100 lines · c
1//===---------- inline implementation of x86_64 syscalls ----------* C++ *-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_X86_64_SYSCALL_H10#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_X86_64_SYSCALL_H11 12#include "src/__support/common.h"13#include "src/__support/macros/config.h"14 15#define SYSCALL_CLOBBER_LIST "rcx", "r11", "memory"16 17namespace LIBC_NAMESPACE_DECL {18 19LIBC_INLINE long syscall_impl(long __number) {20 long retcode;21 LIBC_INLINE_ASM("syscall"22 : "=a"(retcode)23 : "a"(__number)24 : SYSCALL_CLOBBER_LIST);25 return retcode;26}27 28LIBC_INLINE long syscall_impl(long __number, long __arg1) {29 long retcode;30 LIBC_INLINE_ASM("syscall"31 : "=a"(retcode)32 : "a"(__number), "D"(__arg1)33 : SYSCALL_CLOBBER_LIST);34 return retcode;35}36 37LIBC_INLINE long syscall_impl(long __number, long __arg1, long __arg2) {38 long retcode;39 LIBC_INLINE_ASM("syscall"40 : "=a"(retcode)41 : "a"(__number), "D"(__arg1), "S"(__arg2)42 : SYSCALL_CLOBBER_LIST);43 return retcode;44}45 46LIBC_INLINE long syscall_impl(long __number, long __arg1, long __arg2,47 long __arg3) {48 long retcode;49 LIBC_INLINE_ASM("syscall"50 : "=a"(retcode)51 : "a"(__number), "D"(__arg1), "S"(__arg2), "d"(__arg3)52 : SYSCALL_CLOBBER_LIST);53 return retcode;54}55 56LIBC_INLINE long syscall_impl(long __number, long __arg1, long __arg2,57 long __arg3, long __arg4) {58 long retcode;59 register long r10 __asm__("r10") = __arg4;60 LIBC_INLINE_ASM("syscall"61 : "=a"(retcode)62 : "a"(__number), "D"(__arg1), "S"(__arg2), "d"(__arg3),63 "r"(r10)64 : SYSCALL_CLOBBER_LIST);65 return retcode;66}67 68LIBC_INLINE long syscall_impl(long __number, long __arg1, long __arg2,69 long __arg3, long __arg4, long __arg5) {70 long retcode;71 register long r10 __asm__("r10") = __arg4;72 register long r8 __asm__("r8") = __arg5;73 LIBC_INLINE_ASM("syscall"74 : "=a"(retcode)75 : "a"(__number), "D"(__arg1), "S"(__arg2), "d"(__arg3),76 "r"(r10), "r"(r8)77 : SYSCALL_CLOBBER_LIST);78 return retcode;79}80 81LIBC_INLINE long syscall_impl(long __number, long __arg1, long __arg2,82 long __arg3, long __arg4, long __arg5,83 long __arg6) {84 long retcode;85 register long r10 __asm__("r10") = __arg4;86 register long r8 __asm__("r8") = __arg5;87 register long r9 __asm__("r9") = __arg6;88 LIBC_INLINE_ASM("syscall"89 : "=a"(retcode)90 : "a"(__number), "D"(__arg1), "S"(__arg2), "d"(__arg3),91 "r"(r10), "r"(r8), "r"(r9)92 : SYSCALL_CLOBBER_LIST);93 return retcode;94}95 96#undef SYSCALL_CLOBBER_LIST97} // namespace LIBC_NAMESPACE_DECL98 99#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_X86_64_SYSCALL_H100