4 #include <sys/syscall.h>
6 #define SYSCALL_LL(x) x, 0
7 #define SYSCALL_SIGSET_SIZE 8
9 #if defined(SYSCALL_NORETURN)
10 static inline long __syscall_ret(unsigned long r)
15 #elif defined(SYSCALL_RETURN_ERRNO)
16 static inline long __syscall_ret(unsigned long r)
21 extern long __syscall_ret(unsigned long);
24 // 64: di, si, dx, r10, r8, r9
25 // 32: ebx, ecx, edx, esi, edi, ebp
27 #define SYSCALL "syscall"
29 static inline long syscall0(long n)
32 __asm__ __volatile__ (SYSCALL : "=a"(ret) : "a"(n) : "rcx", "r11", "memory");
33 return __syscall_ret(ret);
36 static inline long syscall1(long n, long a1)
39 __asm__ __volatile__ (SYSCALL : "=a"(ret) : "a"(n), "D"(a1) : "rcx", "r11", "memory");
40 return __syscall_ret(ret);
43 static inline long syscall2(long n, long a1, long a2)
46 __asm__ __volatile__ (SYSCALL : "=a"(ret) : "a"(n), "D"(a1), "S"(a2)
47 : "rcx", "r11", "memory");
48 return __syscall_ret(ret);
51 static inline long syscall3(long n, long a1, long a2, long a3)
54 __asm__ __volatile__ (SYSCALL : "=a"(ret) : "a"(n), "D"(a1), "S"(a2),
55 "d"(a3) : "rcx", "r11", "memory");
56 return __syscall_ret(ret);
59 static inline long syscall4(long n, long a1, long a2, long a3, long a4)
62 register long r10 __asm__("r10") = a4;
63 __asm__ __volatile__ (SYSCALL : "=a"(ret) : "a"(n), "D"(a1), "S"(a2),
64 "d"(a3), "r"(r10): "rcx", "r11", "memory");
65 return __syscall_ret(ret);
68 static inline long syscall5(long n, long a1, long a2, long a3, long a4,
72 register long r10 __asm__("r10") = a4;
73 register long r8 __asm__("r8") = a5;
74 __asm__ __volatile__ (SYSCALL : "=a"(ret) : "a"(n), "D"(a1), "S"(a2),
75 "d"(a3), "r"(r10), "r"(r8) : "rcx", "r11", "memory");
76 return __syscall_ret(ret);
79 static inline long syscall6(long n, long a1, long a2, long a3, long a4,
83 register long r10 __asm__("r10") = a4;
84 register long r8 __asm__("r8") = a5;
85 register long r9 __asm__("r9") = a6;
86 __asm__ __volatile__ (SYSCALL : "=a"(ret) : "a"(n), "D"(a1), "S"(a2),
87 "d"(a3), "r"(r10), "r"(r8), "r"(r9) : "rcx", "r11", "memory");
88 return __syscall_ret(ret);
92 #define O_LARGEFILE 0100000
94 #define socketcall(nm, a, b, c, d, e, f) syscall6(__NR_##nm, \
95 (long)a, (long)b, (long)c, (long)d, (long)e, (long)f)
97 /* the following are needed for iso c functions to use */
98 #define __syscall_open(filename, flags, mode) syscall3(__NR_open, (long)(filename), (flags)|O_LARGEFILE, (mode))
99 #define __syscall_read(fd, buf, len) syscall3(__NR_read, (fd), (long)(buf), (len))
100 #define __syscall_write(fd, buf, len) syscall3(__NR_write, (fd), (long)(buf), (len))
101 #define __syscall_close(fd) syscall1(__NR_close, (fd))
102 #define __syscall_fcntl(fd, cmd, arg) syscall3(__NR_fcntl, (fd), (cmd), (long)(arg))
103 #define __syscall_dup2(old, new) syscall2(__NR_dup2, (old), (new))
104 #define __syscall_unlink(path) syscall1(__NR_unlink, (long)(path))
105 #define __syscall_getpid() syscall0(__NR_getpid)
106 #define __syscall_kill(pid,sig) syscall2(__NR_kill, (pid), (sig))
107 #define __syscall_sigaction(sig,new,old) syscall4(__NR_rt_sigaction, (sig), (long)(new), (long)(old), SYSCALL_SIGSET_SIZE)
108 #define __syscall_ioctl(fd,ioc,arg) syscall3(__NR_ioctl, (fd), (ioc), (long)(arg))
109 #define __syscall_exit(code) syscall1(__NR_exit, code)
111 long __syscall(long, ...);