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-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_X86_64_SYSCALL_H
10#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_X86_64_SYSCALL_H
11
12#include "src/__support/common.h"
13
14#define SYSCALL_CLOBBER_LIST "rcx", "r11", "memory"
15
16namespace LIBC_NAMESPACE {
17
18LIBC_INLINE long syscall_impl(long __number) {
19 long retcode;
20 LIBC_INLINE_ASM("syscall"
21 : "=a"(retcode)
22 : "a"(__number)
23 : SYSCALL_CLOBBER_LIST);
24 return retcode;
25}
26
27LIBC_INLINE long syscall_impl(long __number, long __arg1) {
28 long retcode;
29 LIBC_INLINE_ASM("syscall"
30 : "=a"(retcode)
31 : "a"(__number), "D"(__arg1)
32 : SYSCALL_CLOBBER_LIST);
33 return retcode;
34}
35
36LIBC_INLINE long syscall_impl(long __number, long __arg1, long __arg2) {
37 long retcode;
38 LIBC_INLINE_ASM("syscall"
39 : "=a"(retcode)
40 : "a"(__number), "D"(__arg1), "S"(__arg2)
41 : SYSCALL_CLOBBER_LIST);
42 return retcode;
43}
44
45LIBC_INLINE long syscall_impl(long __number, long __arg1, long __arg2,
46 long __arg3) {
47 long retcode;
48 LIBC_INLINE_ASM("syscall"
49 : "=a"(retcode)
50 : "a"(__number), "D"(__arg1), "S"(__arg2), "d"(__arg3)
51 : SYSCALL_CLOBBER_LIST);
52 return retcode;
53}
54
55LIBC_INLINE long syscall_impl(long __number, long __arg1, long __arg2,
56 long __arg3, long __arg4) {
57 long retcode;
58 register long r10 __asm__("r10") = __arg4;
59 LIBC_INLINE_ASM("syscall"
60 : "=a"(retcode)
61 : "a"(__number), "D"(__arg1), "S"(__arg2), "d"(__arg3),
62 "r"(r10)
63 : SYSCALL_CLOBBER_LIST);
64 return retcode;
65}
66
67LIBC_INLINE long syscall_impl(long __number, long __arg1, long __arg2,
68 long __arg3, long __arg4, long __arg5) {
69 long retcode;
70 register long r10 __asm__("r10") = __arg4;
71 register long r8 __asm__("r8") = __arg5;
72 LIBC_INLINE_ASM("syscall"
73 : "=a"(retcode)
74 : "a"(__number), "D"(__arg1), "S"(__arg2), "d"(__arg3),
75 "r"(r10), "r"(r8)
76 : SYSCALL_CLOBBER_LIST);
77 return retcode;
78}
79
80LIBC_INLINE long syscall_impl(long __number, long __arg1, long __arg2,
81 long __arg3, long __arg4, long __arg5,
82 long __arg6) {
83 long retcode;
84 register long r10 __asm__("r10") = __arg4;
85 register long r8 __asm__("r8") = __arg5;
86 register long r9 __asm__("r9") = __arg6;
87 LIBC_INLINE_ASM("syscall"
88 : "=a"(retcode)
89 : "a"(__number), "D"(__arg1), "S"(__arg2), "d"(__arg3),
90 "r"(r10), "r"(r8), "r"(r9)
91 : SYSCALL_CLOBBER_LIST);
92 return retcode;
93}
94
95#undef SYSCALL_CLOBBER_LIST
96} // namespace LIBC_NAMESPACE
97
98#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_X86_64_SYSCALL_H
99

source code of libc/src/__support/OSUtil/linux/x86_64/syscall.h