4 #include <sys/syscall.h>
6 #define SYSCALL_LL(x) \
7 ((union { long long ll; long l[2]; }){ .ll = x }).l[0], \
8 ((union { long long ll; long l[2]; }){ .ll = x }).l[1]
10 #define SYSCALL_SIGSET_SIZE 8
12 #if defined(SYSCALL_NORETURN)
13 static inline long __syscall_ret(unsigned long r)
18 #elif defined(SYSCALL_RETURN_ERRNO)
19 static inline long __syscall_ret(unsigned long r)
24 extern long __syscall_ret(unsigned long);
27 static inline long syscall0(long n)
30 __asm__ __volatile__ ("int $128" : "=a"(ret) : "a"(n) : "memory");
31 return __syscall_ret(ret);
36 static inline long syscall1(long n, long a1)
39 __asm__ __volatile__ ("int $128" : "=a"(ret) : "a"(n), "b"(a1) : "memory");
40 return __syscall_ret(ret);
43 static inline long syscall2(long n, long a1, long a2)
46 __asm__ __volatile__ ("int $128" : "=a"(ret) : "a"(n), "b"(a1), "c"(a2) : "memory");
47 return __syscall_ret(ret);
50 static inline long syscall3(long n, long a1, long a2, long a3)
53 __asm__ __volatile__ ("int $128" : "=a"(ret) : "a"(n), "b"(a1), "c"(a2), "d"(a3) : "memory");
54 return __syscall_ret(ret);
57 static inline long syscall4(long n, long a1, long a2, long a3, long a4)
60 __asm__ __volatile__ ("int $128" : "=a"(ret) : "a"(n), "b"(a1), "c"(a2), "d"(a3), "S"(a4) : "memory");
61 return __syscall_ret(ret);
64 static inline long syscall5(long n, long a1, long a2, long a3, long a4, long a5)
67 __asm__ __volatile__ ("int $128" : "=a"(ret) : "a"(n), "b"(a1), "c"(a2), "d"(a3), "S"(a4), "D"(a5) : "memory");
68 return __syscall_ret(ret);
71 static inline long syscall6(long n, long a1, long a2, long a3, long a4, long a5, long a6)
74 __asm__ __volatile__ ("pushl %%ebp ; mov %%eax,%%ebp ; movl %1,%%eax ; int $128 ; popl %%ebp"
75 : "=a"(ret) : "i"(n), "b"(a1), "c"(a2), "d"(a3), "S"(a4), "D"(a5), "a"(a6) : "memory");
76 return __syscall_ret(ret);
81 static inline long syscall1(long n, long a1)
84 __asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx"
85 : "=a"(ret) : "a"(n), "r"(a1) : "memory");
86 return __syscall_ret(ret);
89 static inline long syscall2(long n, long a1, long a2)
92 __asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx"
93 : "=a"(ret) : "a"(n), "r"(a1), "c"(a2) : "memory");
94 return __syscall_ret(ret);
97 static inline long syscall3(long n, long a1, long a2, long a3)
100 __asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx"
101 : "=a"(ret) : "a"(n), "r"(a1), "c"(a2), "d"(a3) : "memory");
102 return __syscall_ret(ret);
105 static inline long syscall4(long n, long a1, long a2, long a3, long a4)
108 __asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx"
109 : "=a"(ret) : "a"(n), "r"(a1), "c"(a2), "d"(a3), "S"(a4) : "memory");
110 return __syscall_ret(ret);
113 static inline long syscall5(long n, long a1, long a2, long a3, long a4, long a5)
116 __asm__ __volatile__ ("pushl %%ebx ; mov %%eax,%%ebx ; movl %1,%%eax ; int $128 ; popl %%ebx"
117 : "=a"(ret) : "i"(n), "a"(a1), "c"(a2), "d"(a3), "S"(a4), "D"(a5) : "memory");
118 return __syscall_ret(ret);
121 #define syscall6(n,a1,a2,a3,a4,a5,a6) __syscall((n),(a1),(a2),(a3),(a4),(a5),(a6))
125 #define __SC_socket 1
127 #define __SC_connect 3
128 #define __SC_listen 4
129 #define __SC_accept 5
130 #define __SC_getsockname 6
131 #define __SC_getpeername 7
132 #define __SC_socketpair 8
135 #define __SC_sendto 11
136 #define __SC_recvfrom 12
137 #define __SC_shutdown 13
138 #define __SC_setsockopt 14
139 #define __SC_getsockopt 15
140 #define __SC_sendmsg 16
141 #define __SC_recvmsg 17
144 #define socketcall(nm, a, b, c, d, e, f) syscall2(__NR_socketcall, __SC_##nm, \
145 (long)(long [6]){ (long)a, (long)b, (long)c, (long)d, (long)e, (long)f })
149 #define O_LARGEFILE 0100000
151 /* the following are needed for iso c functions to use */
152 #define __syscall_open(filename, flags, mode) syscall3(__NR_open, (long)(filename), (flags)|O_LARGEFILE, (mode))
153 #define __syscall_read(fd, buf, len) syscall3(__NR_read, (fd), (long)(buf), (len))
154 #define __syscall_write(fd, buf, len) syscall3(__NR_write, (fd), (long)(buf), (len))
155 #define __syscall_close(fd) syscall1(__NR_close, (fd))
156 #define __syscall_fcntl(fd, cmd, arg) syscall3(__NR_fcntl64, (fd), (cmd), (long)(arg))
157 #define __syscall_dup2(old, new) syscall2(__NR_dup2, (old), (new))
158 #define __syscall_unlink(path) syscall1(__NR_unlink, (long)(path))
159 #define __syscall_getpid() syscall0(__NR_getpid)
160 #define __syscall_kill(pid,sig) syscall2(__NR_kill, (pid), (sig))
161 #define __syscall_sigaction(sig,new,old) syscall4(__NR_rt_sigaction, (sig), (long)(new), (long)(old), SYSCALL_SIGSET_SIZE)
162 #define __syscall_ioctl(fd,ioc,arg) syscall3(__NR_ioctl, (fd), (ioc), (long)(arg))
163 #define __syscall_exit(code) syscall1(__NR_exit, code)
165 long __syscall(long, ...);