xref: /llvm-project/libc/src/__support/OSUtil/linux/i386/syscall.h (revision 8413599b59b209312f9662dcad3e7bb4e9d4a4d4)
1 //===---------- inline implementation of i386 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_I386_SYSCALL_H
10 #define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_I386_SYSCALL_H
11 
12 #include "src/__support/common.h"
13 #include "src/__support/macros/config.h"
14 
15 namespace LIBC_NAMESPACE_DECL {
16 
17 LIBC_INLINE long syscall_impl(long num) {
18   long ret;
19   LIBC_INLINE_ASM("int $128" : "=a"(ret) : "a"(num) : "memory");
20   return ret;
21 }
22 
23 LIBC_INLINE long syscall_impl(long num, long arg1) {
24   long ret;
25   LIBC_INLINE_ASM("int $128" : "=a"(ret) : "a"(num), "b"(arg1) : "memory");
26   return ret;
27 }
28 
29 LIBC_INLINE long syscall_impl(long num, long arg1, long arg2) {
30   long ret;
31   LIBC_INLINE_ASM("int $128"
32                   : "=a"(ret)
33                   : "a"(num), "b"(arg1), "c"(arg2)
34                   : "memory");
35   return ret;
36 }
37 
38 LIBC_INLINE long syscall_impl(long num, long arg1, long arg2, long arg3) {
39   long ret;
40   LIBC_INLINE_ASM("int $128"
41                   : "=a"(ret)
42                   : "a"(num), "b"(arg1), "c"(arg2), "d"(arg3)
43                   : "memory");
44   return ret;
45 }
46 
47 LIBC_INLINE long syscall_impl(long num, long arg1, long arg2, long arg3,
48                               long arg4) {
49   long ret;
50   LIBC_INLINE_ASM("int $128"
51                   : "=a"(ret)
52                   : "a"(num), "b"(arg1), "c"(arg2), "d"(arg3), "S"(arg4)
53                   : "memory");
54   return ret;
55 }
56 
57 LIBC_INLINE long syscall_impl(long num, long arg1, long arg2, long arg3,
58                               long arg4, long arg5) {
59   long ret;
60   LIBC_INLINE_ASM("int $128"
61                   : "=a"(ret)
62                   : "a"(num), "b"(arg1), "c"(arg2), "d"(arg3), "S"(arg4),
63                     "D"(arg5)
64                   : "memory");
65   return ret;
66 }
67 
68 LIBC_INLINE long syscall_impl(long num, long arg1, long arg2, long arg3,
69                               long arg4, long arg5, long arg6) {
70   long ret;
71   LIBC_INLINE_ASM(R"(
72     push %[arg6]
73     push %%ebp
74     mov 4(%%esp), %%ebp
75     int $128
76     pop %%ebp
77     add $4, %%esp
78   )"
79                   : "=a"(ret)
80                   : "a"(num), "b"(arg1), "c"(arg2), "d"(arg3), "S"(arg4),
81                     "D"(arg5), [arg6] "m"(arg6)
82                   : "memory");
83   return ret;
84 }
85 
86 } // namespace LIBC_NAMESPACE_DECL
87 
88 #endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_I386_SYSCALL_H
89