diff options
-rw-r--r-- | src/syscall-alpha.h | 204 | ||||
-rw-r--r-- | src/syscall-arm.h | 90 | ||||
-rw-r--r-- | src/syscall-arm64.h | 83 | ||||
-rw-r--r-- | src/syscall-generic.h | 35 | ||||
-rw-r--r-- | src/syscall-i386.h | 67 | ||||
-rw-r--r-- | src/syscall-ia64.h | 40 | ||||
-rw-r--r-- | src/syscall-ppc.h | 89 | ||||
-rw-r--r-- | src/syscall-s390.h | 126 | ||||
-rw-r--r-- | src/syscall-sparc.h | 98 | ||||
-rw-r--r-- | src/syscall-x86_64.h | 58 | ||||
-rw-r--r-- | src/syscall.h | 36 |
11 files changed, 34 insertions, 892 deletions
diff --git a/src/syscall-alpha.h b/src/syscall-alpha.h index 467b74f..0aa4d3d 100644 --- a/src/syscall-alpha.h +++ b/src/syscall-alpha.h @@ -3,207 +3,3 @@ #define __NR_io_getevents 400 #define __NR_io_submit 401 #define __NR_io_cancel 402 - -#define inline_syscall_r0_asm -#define inline_syscall_r0_out_constraint "=v" - -#define inline_syscall_clobbers \ - "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", \ - "$22", "$23", "$24", "$25", "$27", "$28", "memory" - -#define inline_syscall0(name, args...) \ -{ \ - register long _sc_0 inline_syscall_r0_asm; \ - register long _sc_19 __asm__("$19"); \ - \ - _sc_0 = name; \ - __asm__ __volatile__ \ - ("callsys # %0 %1 <= %2" \ - : inline_syscall_r0_out_constraint (_sc_0), \ - "=r"(_sc_19) \ - : "0"(_sc_0) \ - : inline_syscall_clobbers, \ - "$16", "$17", "$18", "$20", "$21"); \ - _sc_ret = _sc_0, _sc_err = _sc_19; \ -} - -#define inline_syscall1(name,arg1) \ -{ \ - register long _sc_0 inline_syscall_r0_asm; \ - register long _sc_16 __asm__("$16"); \ - register long _sc_19 __asm__("$19"); \ - \ - _sc_0 = name; \ - _sc_16 = (long) (arg1); \ - __asm__ __volatile__ \ - ("callsys # %0 %1 <= %2 %3" \ - : inline_syscall_r0_out_constraint (_sc_0), \ - "=r"(_sc_19), "=r"(_sc_16) \ - : "0"(_sc_0), "2"(_sc_16) \ - : inline_syscall_clobbers, \ - "$17", "$18", "$20", "$21"); \ - _sc_ret = _sc_0, _sc_err = _sc_19; \ -} - -#define inline_syscall2(name,arg1,arg2) \ -{ \ - register long _sc_0 inline_syscall_r0_asm; \ - register long _sc_16 __asm__("$16"); \ - register long _sc_17 __asm__("$17"); \ - register long _sc_19 __asm__("$19"); \ - \ - _sc_0 = name; \ - _sc_16 = (long) (arg1); \ - _sc_17 = (long) (arg2); \ - __asm__ __volatile__ \ - ("callsys # %0 %1 <= %2 %3 %4" \ - : inline_syscall_r0_out_constraint (_sc_0), \ - "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17) \ - : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17) \ - : inline_syscall_clobbers, \ - "$18", "$20", "$21"); \ - _sc_ret = _sc_0, _sc_err = _sc_19; \ -} - -#define inline_syscall3(name,arg1,arg2,arg3) \ -{ \ - register long _sc_0 inline_syscall_r0_asm; \ - register long _sc_16 __asm__("$16"); \ - register long _sc_17 __asm__("$17"); \ - register long _sc_18 __asm__("$18"); \ - register long _sc_19 __asm__("$19"); \ - \ - _sc_0 = name; \ - _sc_16 = (long) (arg1); \ - _sc_17 = (long) (arg2); \ - _sc_18 = (long) (arg3); \ - __asm__ __volatile__ \ - ("callsys # %0 %1 <= %2 %3 %4 %5" \ - : inline_syscall_r0_out_constraint (_sc_0), \ - "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17), \ - "=r"(_sc_18) \ - : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17), \ - "4"(_sc_18) \ - : inline_syscall_clobbers, "$20", "$21"); \ - _sc_ret = _sc_0, _sc_err = _sc_19; \ -} - -#define inline_syscall4(name,arg1,arg2,arg3,arg4) \ -{ \ - register long _sc_0 inline_syscall_r0_asm; \ - register long _sc_16 __asm__("$16"); \ - register long _sc_17 __asm__("$17"); \ - register long _sc_18 __asm__("$18"); \ - register long _sc_19 __asm__("$19"); \ - \ - _sc_0 = name; \ - _sc_16 = (long) (arg1); \ - _sc_17 = (long) (arg2); \ - _sc_18 = (long) (arg3); \ - _sc_19 = (long) (arg4); \ - __asm__ __volatile__ \ - ("callsys # %0 %1 <= %2 %3 %4 %5 %6" \ - : inline_syscall_r0_out_constraint (_sc_0), \ - "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17), \ - "=r"(_sc_18) \ - : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17), \ - "4"(_sc_18), "1"(_sc_19) \ - : inline_syscall_clobbers, "$20", "$21"); \ - _sc_ret = _sc_0, _sc_err = _sc_19; \ -} - -#define inline_syscall5(name,arg1,arg2,arg3,arg4,arg5) \ -{ \ - register long _sc_0 inline_syscall_r0_asm; \ - register long _sc_16 __asm__("$16"); \ - register long _sc_17 __asm__("$17"); \ - register long _sc_18 __asm__("$18"); \ - register long _sc_19 __asm__("$19"); \ - register long _sc_20 __asm__("$20"); \ - \ - _sc_0 = name; \ - _sc_16 = (long) (arg1); \ - _sc_17 = (long) (arg2); \ - _sc_18 = (long) (arg3); \ - _sc_19 = (long) (arg4); \ - _sc_20 = (long) (arg5); \ - __asm__ __volatile__ \ - ("callsys # %0 %1 <= %2 %3 %4 %5 %6 %7" \ - : inline_syscall_r0_out_constraint (_sc_0), \ - "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17), \ - "=r"(_sc_18), "=r"(_sc_20) \ - : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17), \ - "4"(_sc_18), "1"(_sc_19), "5"(_sc_20) \ - : inline_syscall_clobbers, "$21"); \ - _sc_ret = _sc_0, _sc_err = _sc_19; \ -} - -#define inline_syscall6(name,arg1,arg2,arg3,arg4,arg5,arg6) \ -{ \ - register long _sc_0 inline_syscall_r0_asm; \ - register long _sc_16 __asm__("$16"); \ - register long _sc_17 __asm__("$17"); \ - register long _sc_18 __asm__("$18"); \ - register long _sc_19 __asm__("$19"); \ - register long _sc_20 __asm__("$20"); \ - register long _sc_21 __asm__("$21"); \ - \ - _sc_0 = name; \ - _sc_16 = (long) (arg1); \ - _sc_17 = (long) (arg2); \ - _sc_18 = (long) (arg3); \ - _sc_19 = (long) (arg4); \ - _sc_20 = (long) (arg5); \ - _sc_21 = (long) (arg6); \ - __asm__ __volatile__ \ - ("callsys # %0 %1 <= %2 %3 %4 %5 %6 %7 %8" \ - : inline_syscall_r0_out_constraint (_sc_0), \ - "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17), \ - "=r"(_sc_18), "=r"(_sc_20), "=r"(_sc_21) \ - : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17), "4"(_sc_18), \ - "1"(_sc_19), "5"(_sc_20), "6"(_sc_21) \ - : inline_syscall_clobbers); \ - _sc_ret = _sc_0, _sc_err = _sc_19; \ -} - -#define INLINE_SYSCALL1(name, nr, args...) \ -({ \ - long _sc_ret, _sc_err; \ - inline_syscall##nr(__NR_##name, args); \ - if (_sc_err != 0) \ - { \ - _sc_ret = -(_sc_ret); \ - } \ - _sc_ret; \ -}) - -#define io_syscall1(type,fname,sname,type1,arg1) \ -type fname(type1 arg1) \ -{ \ - return (type)INLINE_SYSCALL1(sname, 1, arg1); \ -} - -#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ -type fname(type1 arg1,type2 arg2) \ -{ \ - return (type)INLINE_SYSCALL1(sname, 2, arg1, arg2); \ -} - -#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \ -type fname(type1 arg1,type2 arg2,type3 arg3) \ -{ \ - return (type)INLINE_SYSCALL1(sname, 3, arg1, arg2, arg3); \ -} - -#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ -type fname (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ -{ \ - return (type)INLINE_SYSCALL1(sname, 4, arg1, arg2, arg3, arg4); \ -} - -#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ - type5,arg5) \ -type fname (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ -{ \ - return (type)INLINE_SYSCALL1(sname, 5, arg1, arg2, arg3, arg4, arg5);\ -} diff --git a/src/syscall-arm.h b/src/syscall-arm.h index 4a9b665..556852b 100644 --- a/src/syscall-arm.h +++ b/src/syscall-arm.h @@ -24,93 +24,3 @@ #define __NR_io_getevents (__NR_SYSCALL_BASE+245) #define __NR_io_submit (__NR_SYSCALL_BASE+246) #define __NR_io_cancel (__NR_SYSCALL_BASE+247) - -#define __sys2(x) #x -#define __sys1(x) __sys2(x) - -#if defined(__thumb__) || defined(__ARM_EABI__) -#define __SYS_REG(name) register long __sysreg __asm__("r7") = __NR_##name; -#define __SYS_REG_LIST(regs...) "r" (__sysreg) , ##regs -#define __syscall(name) "swi\t0" -#else -#define __SYS_REG(name) -#define __SYS_REG_LIST(regs...) regs -#define __syscall(name) "swi\t" __sys1(__NR_##name) "" -#endif - -#define io_syscall1(type,fname,sname,type1,arg1) \ -type fname(type1 arg1) { \ - __SYS_REG(sname) \ - register long __r0 __asm__("r0") = (long)arg1; \ - register long __res_r0 __asm__("r0"); \ - __asm__ __volatile__ ( \ - __syscall(sname) \ - : "=r" (__res_r0) \ - : __SYS_REG_LIST( "0" (__r0) ) \ - : "memory" ); \ - return (type) __res_r0; \ -} - -#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ -type fname(type1 arg1,type2 arg2) { \ - __SYS_REG(sname) \ - register long __r0 __asm__("r0") = (long)arg1; \ - register long __r1 __asm__("r1") = (long)arg2; \ - register long __res_r0 __asm__("r0"); \ - __asm__ __volatile__ ( \ - __syscall(sname) \ - : "=r" (__res_r0) \ - : __SYS_REG_LIST( "0" (__r0), "r" (__r1) ) \ - : "memory" ); \ - return (type) __res_r0; \ -} - -#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \ -type fname(type1 arg1,type2 arg2,type3 arg3) { \ - __SYS_REG(sname) \ - register long __r0 __asm__("r0") = (long)arg1; \ - register long __r1 __asm__("r1") = (long)arg2; \ - register long __r2 __asm__("r2") = (long)arg3; \ - register long __res_r0 __asm__("r0"); \ - __asm__ __volatile__ ( \ - __syscall(sname) \ - : "=r" (__res_r0) \ - : __SYS_REG_LIST( "0" (__r0), "r" (__r1), "r" (__r2) ) \ - : "memory" ); \ - return (type) __res_r0; \ -} - -#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4)\ -type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \ - __SYS_REG(sname) \ - register long __r0 __asm__("r0") = (long)arg1; \ - register long __r1 __asm__("r1") = (long)arg2; \ - register long __r2 __asm__("r2") = (long)arg3; \ - register long __r3 __asm__("r3") = (long)arg4; \ - register long __res_r0 __asm__("r0"); \ - __asm__ __volatile__ ( \ - __syscall(sname) \ - : "=r" (__res_r0) \ - : __SYS_REG_LIST( "0" (__r0), "r" (__r1), "r" (__r2), "r" (__r3) ) \ - : "memory" ); \ - return (type) __res_r0; \ -} - -#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \ -type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) {\ - __SYS_REG(sname) \ - register long __r0 __asm__("r0") = (long)arg1; \ - register long __r1 __asm__("r1") = (long)arg2; \ - register long __r2 __asm__("r2") = (long)arg3; \ - register long __r3 __asm__("r3") = (long)arg4; \ - register long __r4 __asm__("r4") = (long)arg5; \ - register long __res_r0 __asm__("r0"); \ - __asm__ __volatile__ ( \ - __syscall(sname) \ - : "=r" (__res_r0) \ - : __SYS_REG_LIST( "0" (__r0), "r" (__r1), "r" (__r2), \ - "r" (__r3), "r" (__r4) ) \ - : "memory" ); \ - return (type) __res_r0; \ -} - diff --git a/src/syscall-arm64.h b/src/syscall-arm64.h index 031c571..c20bb3a 100644 --- a/src/syscall-arm64.h +++ b/src/syscall-arm64.h @@ -16,86 +16,3 @@ #define __NR_io_submit 2 #define __NR_io_cancel 3 #define __NR_io_getevents 4 - -#define __sys2(x) #x -#define __sys1(x) __sys2(x) - -#define __SYS_REG(name) register long __sysreg __asm__("w8") = __NR_##name; -#define __SYS_REG_LIST(regs...) "r" (__sysreg) , ##regs -#define __syscall(name) "svc\t#0" - -#define io_syscall1(type,fname,sname,type1,arg1) \ -type fname(type1 arg1) { \ - __SYS_REG(sname) \ - register long __x0 __asm__("x0") = (long)arg1; \ - register long __res_x0 __asm__("x0"); \ - __asm__ __volatile__ ( \ - __syscall(sname) \ - : "=r" (__res_x0) \ - : __SYS_REG_LIST( "0" (__x0) ) \ - : "memory" ); \ - return (type) __res_x0; \ -} - -#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ -type fname(type1 arg1,type2 arg2) { \ - __SYS_REG(sname) \ - register long __x0 __asm__("x0") = (long)arg1; \ - register long __x1 __asm__("x1") = (long)arg2; \ - register long __res_x0 __asm__("x0"); \ - __asm__ __volatile__ ( \ - __syscall(sname) \ - : "=r" (__res_x0) \ - : __SYS_REG_LIST( "0" (__x0), "r" (__x1) ) \ - : "memory" ); \ - return (type) __res_x0; \ -} - -#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \ -type fname(type1 arg1,type2 arg2,type3 arg3) { \ - __SYS_REG(sname) \ - register long __x0 __asm__("x0") = (long)arg1; \ - register long __x1 __asm__("x1") = (long)arg2; \ - register long __x2 __asm__("x2") = (long)arg3; \ - register long __res_x0 __asm__("x0"); \ - __asm__ __volatile__ ( \ - __syscall(sname) \ - : "=r" (__res_x0) \ - : __SYS_REG_LIST( "0" (__x0), "r" (__x1), "r" (__x2) ) \ - : "memory" ); \ - return (type) __res_x0; \ -} - -#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4)\ -type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \ - __SYS_REG(sname) \ - register long __x0 __asm__("x0") = (long)arg1; \ - register long __x1 __asm__("x1") = (long)arg2; \ - register long __x2 __asm__("x2") = (long)arg3; \ - register long __x3 __asm__("x3") = (long)arg4; \ - register long __res_x0 __asm__("x0"); \ - __asm__ __volatile__ ( \ - __syscall(sname) \ - : "=r" (__res_x0) \ - : __SYS_REG_LIST( "0" (__x0), "r" (__x1), "r" (__x2), "r" (__x3) ) \ - : "memory" ); \ - return (type) __res_x0; \ -} - -#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \ -type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) {\ - __SYS_REG(sname) \ - register long __x0 __asm__("x0") = (long)arg1; \ - register long __x1 __asm__("x1") = (long)arg2; \ - register long __x2 __asm__("x2") = (long)arg3; \ - register long __x3 __asm__("x3") = (long)arg4; \ - register long __x4 __asm__("x4") = (long)arg5; \ - register long __res_x0 __asm__("x0"); \ - __asm__ __volatile__ ( \ - __syscall(sname) \ - : "=r" (__res_x0) \ - : __SYS_REG_LIST( "0" (__x0), "r" (__x1), "r" (__x2), \ - "r" (__x3), "r" (__x4) ) \ - : "memory" ); \ - return (type) __res_x0; \ -} diff --git a/src/syscall-generic.h b/src/syscall-generic.h deleted file mode 100644 index 44d57f3..0000000 --- a/src/syscall-generic.h +++ /dev/null @@ -1,35 +0,0 @@ -#include <errno.h> -#include <unistd.h> -#include <sys/syscall.h> - -#define _body_io_syscall(sname, args...) \ -{ \ - int ret, saved_errno; \ - saved_errno = errno; \ - ret= syscall(__NR_##sname, ## args); \ - if (ret < 0) { \ - ret = -errno; \ - errno = saved_errno; \ - } \ - return ret; \ -} - -#define io_syscall1(type,fname,sname,type1,arg1) \ -type fname(type1 arg1) \ -_body_io_syscall(sname, (long)arg1) - -#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ -type fname(type1 arg1,type2 arg2) \ -_body_io_syscall(sname, (long)arg1, (long)arg2) - -#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \ -type fname(type1 arg1,type2 arg2,type3 arg3) \ -_body_io_syscall(sname, (long)arg1, (long)arg2, (long)arg3) - -#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ -type fname (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ -_body_io_syscall(sname, (long)arg1, (long)arg2, (long)arg3, (long)arg4) - -#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4, type5,arg5) \ -type fname (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ -_body_io_syscall(sname, (long)arg1, (long)arg2, (long)arg3, (long)arg4, (long)arg5) diff --git a/src/syscall-i386.h b/src/syscall-i386.h index 9576975..266ed93 100644 --- a/src/syscall-i386.h +++ b/src/syscall-i386.h @@ -3,70 +3,3 @@ #define __NR_io_getevents 247 #define __NR_io_submit 248 #define __NR_io_cancel 249 - -#define io_syscall1(type,fname,sname,type1,arg1) \ -type fname(type1 arg1) \ -{ \ -long __res; \ -__asm__ volatile ("xchgl %%edi,%%ebx\n" \ - "int $0x80\n" \ - "xchgl %%edi,%%ebx" \ - : "=a" (__res) \ - : "0" (__NR_##sname),"D" ((long)(arg1))); \ -return __res; \ -} - -#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ -type fname(type1 arg1,type2 arg2) \ -{ \ -long __res; \ -__asm__ volatile ("xchgl %%edi,%%ebx\n" \ - "int $0x80\n" \ - "xchgl %%edi,%%ebx" \ - : "=a" (__res) \ - : "0" (__NR_##sname),"D" ((long)(arg1)),"c" ((long)(arg2))); \ -return __res; \ -} - -#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \ -type fname(type1 arg1,type2 arg2,type3 arg3) \ -{ \ -long __res; \ -__asm__ volatile ("xchgl %%edi,%%ebx\n" \ - "int $0x80\n" \ - "xchgl %%edi,%%ebx" \ - : "=a" (__res) \ - : "0" (__NR_##sname),"D" ((long)(arg1)),"c" ((long)(arg2)), \ - "d" ((long)(arg3))); \ -return __res; \ -} - -#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ -type fname (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ -{ \ -long __res; \ -__asm__ volatile ("xchgl %%edi,%%ebx\n" \ - "int $0x80\n" \ - "xchgl %%edi,%%ebx" \ - : "=a" (__res) \ - : "0" (__NR_##sname),"D" ((long)(arg1)),"c" ((long)(arg2)), \ - "d" ((long)(arg3)),"S" ((long)(arg4))); \ -return __res; \ -} - -#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ - type5,arg5) \ -type fname (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ -{ \ -long __res; \ -long tmp; \ -__asm__ volatile ("movl %%ebx,%7\n" \ - "movl %2,%%ebx\n" \ - "int $0x80\n" \ - "movl %7,%%ebx" \ - : "=a" (__res) \ - : "0" (__NR_##sname),"rm" ((long)(arg1)),"c" ((long)(arg2)), \ - "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5)), \ - "m" (tmp)); \ -return __res; \ -} diff --git a/src/syscall-ia64.h b/src/syscall-ia64.h index 52ce9dd..a21e93b 100644 --- a/src/syscall-ia64.h +++ b/src/syscall-ia64.h @@ -3,43 +3,3 @@ #define __NR_io_getevents 1240 #define __NR_io_submit 1241 #define __NR_io_cancel 1242 - -#define __ia64_raw_syscall(fname, sname) \ - __asm__ (".text\n" \ - ".globl " SYMSTR(fname) "\n" \ - ".proc " SYMSTR(fname) "\n" \ - SYMSTR(fname) ":\n" \ - " mov r15=" SYMSTR( __NR_ ## sname ) "\n" \ - " break 0x100000\n" \ - " ;;\n" \ - " cmp.eq p6,p0=-1,r10\n" \ - " ;;\n" \ - " (p6) sub r8=0,r8\n" \ - " br.ret.sptk.few b0\n" \ - ".size " SYMSTR(fname) ", . - " SYMSTR(fname) "\n" \ - ".endp " SYMSTR(fname) "\n" \ - ); - -#define io_syscall0(type, name) \ - extern type name(void); \ - __ia64_raw_syscall(name); - -#define io_syscall1(type, fname, sname, type1, arg1) \ - extern type fname(type1 arg1); \ - __ia64_raw_syscall(fname, sname); - -#define io_syscall2(type, fname, sname, type1, arg1, type2, arg2) \ - extern type fname(type1 arg1, type2 arg2); \ - __ia64_raw_syscall(fname, sname); - -#define io_syscall3(type, fname, sname, type1, arg1, type2, arg2, type3, arg3) \ - extern type fname(type1 arg1, type2 arg2, type3 arg3); \ - __ia64_raw_syscall(fname, sname); - -#define io_syscall4(type, fname, sname, type1, arg1, type2, arg2, type3, arg3, type4, arg4) \ - extern type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4); \ - __ia64_raw_syscall(fname, sname); - -#define io_syscall5(type, fname, sname, type1, arg1, type2, arg2, type3, arg3, type4, arg4, type5, arg5) \ - extern type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5); \ - __ia64_raw_syscall(fname, sname); diff --git a/src/syscall-ppc.h b/src/syscall-ppc.h index ca70dd2..dcfb118 100644 --- a/src/syscall-ppc.h +++ b/src/syscall-ppc.h @@ -3,92 +3,3 @@ #define __NR_io_getevents 229 #define __NR_io_submit 230 #define __NR_io_cancel 231 - -/* On powerpc a system call basically clobbers the same registers like a - * function call, with the exception of LR (which is needed for the - * "sc; bnslr" sequence) and CR (where only CR0.SO is clobbered to signal - * an error return status). - */ - -#define __syscall_nr(nr, type, name, args...) \ - unsigned long __sc_ret, __sc_err; \ - { \ - register unsigned long __sc_0 __asm__ ("r0"); \ - register unsigned long __sc_3 __asm__ ("r3"); \ - register unsigned long __sc_4 __asm__ ("r4"); \ - register unsigned long __sc_5 __asm__ ("r5"); \ - register unsigned long __sc_6 __asm__ ("r6"); \ - register unsigned long __sc_7 __asm__ ("r7"); \ - register unsigned long __sc_8 __asm__ ("r8"); \ - \ - __sc_loadargs_##nr(name, args); \ - __asm__ __volatile__ \ - ("sc \n\t" \ - "mfcr %0 " \ - : "=&r" (__sc_0), \ - "=&r" (__sc_3), "=&r" (__sc_4), \ - "=&r" (__sc_5), "=&r" (__sc_6), \ - "=&r" (__sc_7), "=&r" (__sc_8) \ - : __sc_asm_input_##nr \ - : "cr0", "ctr", "memory", \ - "r9", "r10","r11", "r12"); \ - __sc_ret = __sc_3; \ - __sc_err = __sc_0; \ - } \ - if (__sc_err & 0x10000000) return -((int)__sc_ret); \ - return (type) __sc_ret - -#define __sc_loadargs_0(name, dummy...) \ - __sc_0 = __NR_##name -#define __sc_loadargs_1(name, arg1) \ - __sc_loadargs_0(name); \ - __sc_3 = (unsigned long) (arg1) -#define __sc_loadargs_2(name, arg1, arg2) \ - __sc_loadargs_1(name, arg1); \ - __sc_4 = (unsigned long) (arg2) -#define __sc_loadargs_3(name, arg1, arg2, arg3) \ - __sc_loadargs_2(name, arg1, arg2); \ - __sc_5 = (unsigned long) (arg3) -#define __sc_loadargs_4(name, arg1, arg2, arg3, arg4) \ - __sc_loadargs_3(name, arg1, arg2, arg3); \ - __sc_6 = (unsigned long) (arg4) -#define __sc_loadargs_5(name, arg1, arg2, arg3, arg4, arg5) \ - __sc_loadargs_4(name, arg1, arg2, arg3, arg4); \ - __sc_7 = (unsigned long) (arg5) - -#define __sc_asm_input_0 "0" (__sc_0) -#define __sc_asm_input_1 __sc_asm_input_0, "1" (__sc_3) -#define __sc_asm_input_2 __sc_asm_input_1, "2" (__sc_4) -#define __sc_asm_input_3 __sc_asm_input_2, "3" (__sc_5) -#define __sc_asm_input_4 __sc_asm_input_3, "4" (__sc_6) -#define __sc_asm_input_5 __sc_asm_input_4, "5" (__sc_7) - -#define io_syscall1(type,fname,sname,type1,arg1) \ -type fname(type1 arg1) \ -{ \ - __syscall_nr(1, type, sname, arg1); \ -} - -#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ -type fname(type1 arg1, type2 arg2) \ -{ \ - __syscall_nr(2, type, sname, arg1, arg2); \ -} - -#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \ -type fname(type1 arg1, type2 arg2, type3 arg3) \ -{ \ - __syscall_nr(3, type, sname, arg1, arg2, arg3); \ -} - -#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ -type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ -{ \ - __syscall_nr(4, type, sname, arg1, arg2, arg3, arg4); \ -} - -#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \ -type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) \ -{ \ - __syscall_nr(5, type, sname, arg1, arg2, arg3, arg4, arg5); \ -} diff --git a/src/syscall-s390.h b/src/syscall-s390.h index 3ec5ee3..f0805f5 100644 --- a/src/syscall-s390.h +++ b/src/syscall-s390.h @@ -3,129 +3,3 @@ #define __NR_io_getevents 245 #define __NR_io_submit 246 #define __NR_io_cancel 247 - -#define io_svc_clobber "1", "cc", "memory" - -#define io_syscall1(type,fname,sname,type1,arg1) \ -type fname(type1 arg1) { \ - register type1 __arg1 asm("2") = arg1; \ - register long __svcres asm("2"); \ - long __res; \ - __asm__ __volatile__ ( \ - " .if %1 < 256\n" \ - " svc %b1\n" \ - " .else\n" \ - " la %%r1,%1\n" \ - " .svc 0\n" \ - " .endif" \ - : "=d" (__svcres) \ - : "i" (__NR_##sname), \ - "0" (__arg1) \ - : io_svc_clobber ); \ - __res = __svcres; \ - return (type) __res; \ -} - -#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ -type fname(type1 arg1, type2 arg2) { \ - register type1 __arg1 asm("2") = arg1; \ - register type2 __arg2 asm("3") = arg2; \ - register long __svcres asm("2"); \ - long __res; \ - __asm__ __volatile__ ( \ - " .if %1 < 256\n" \ - " svc %b1\n" \ - " .else\n" \ - " la %%r1,%1\n" \ - " svc 0\n" \ - " .endif" \ - : "=d" (__svcres) \ - : "i" (__NR_##sname), \ - "0" (__arg1), \ - "d" (__arg2) \ - : io_svc_clobber ); \ - __res = __svcres; \ - return (type) __res; \ -} - -#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2, \ - type3,arg3) \ -type fname(type1 arg1, type2 arg2, type3 arg3) { \ - register type1 __arg1 asm("2") = arg1; \ - register type2 __arg2 asm("3") = arg2; \ - register type3 __arg3 asm("4") = arg3; \ - register long __svcres asm("2"); \ - long __res; \ - __asm__ __volatile__ ( \ - " .if %1 < 256\n" \ - " svc %b1\n" \ - " .else\n" \ - " la %%r1,%1\n" \ - " svc 0\n" \ - " .endif" \ - : "=d" (__svcres) \ - : "i" (__NR_##sname), \ - "0" (__arg1), \ - "d" (__arg2), \ - "d" (__arg3) \ - : io_svc_clobber ); \ - __res = __svcres; \ - return (type) __res; \ -} - -#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2, \ - type3,arg3,type4,arg4) \ -type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \ - register type1 __arg1 asm("2") = arg1; \ - register type2 __arg2 asm("3") = arg2; \ - register type3 __arg3 asm("4") = arg3; \ - register type4 __arg4 asm("5") = arg4; \ - register long __svcres asm("2"); \ - long __res; \ - __asm__ __volatile__ ( \ - " .if %1 < 256\n" \ - " svc %b1\n" \ - " .else\n" \ - " la %%r1,%1\n" \ - " svc 0\n" \ - " .endif" \ - : "=d" (__svcres) \ - : "i" (__NR_##sname), \ - "0" (__arg1), \ - "d" (__arg2), \ - "d" (__arg3), \ - "d" (__arg4) \ - : io_svc_clobber ); \ - __res = __svcres; \ - return (type) __res; \ -} - -#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2, \ - type3,arg3,type4,arg4,type5,arg5) \ -type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \ - type5 arg5) { \ - register type1 __arg1 asm("2") = arg1; \ - register type2 __arg2 asm("3") = arg2; \ - register type3 __arg3 asm("4") = arg3; \ - register type4 __arg4 asm("5") = arg4; \ - register type5 __arg5 asm("6") = arg5; \ - register long __svcres asm("2"); \ - long __res; \ - __asm__ __volatile__ ( \ - " .if %1 < 256\n" \ - " svc %b1\n" \ - " .else\n" \ - " la %%r1,%1\n" \ - " svc 0\n" \ - " .endif" \ - : "=d" (__svcres) \ - : "i" (__NR_##sname), \ - "0" (__arg1), \ - "d" (__arg2), \ - "d" (__arg3), \ - "d" (__arg4), \ - "d" (__arg5) \ - : io_svc_clobber ); \ - __res = __svcres; \ - return (type) __res; \ -} diff --git a/src/syscall-sparc.h b/src/syscall-sparc.h index dd8033d..3e63e92 100644 --- a/src/syscall-sparc.h +++ b/src/syscall-sparc.h @@ -1,103 +1,5 @@ -#include <errno.h> - #define __NR_io_setup 268 #define __NR_io_destroy 269 #define __NR_io_submit 270 #define __NR_io_cancel 271 #define __NR_io_getevents 272 - -#define io_syscall1(type,fname,sname,type1,arg1) \ -type fname(type1 arg1) \ -{ \ -long __res; \ -register long __g1 __asm__ ("g1") = __NR_##sname; \ -register long __o0 __asm__ ("o0") = (long)(arg1); \ -__asm__ __volatile__ ("t 0x10\n\t" \ - "bcc 1f\n\t" \ - "mov %%o0, %0\n\t" \ - "sub %%g0, %%o0, %0\n\t" \ - "1:\n\t" \ - : "=r" (__res), "=&r" (__o0) \ - : "1" (__o0), "r" (__g1) \ - : "cc"); \ -return (type) __res; \ -} - -#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ -type fname(type1 arg1,type2 arg2) \ -{ \ -long __res; \ -register long __g1 __asm__ ("g1") = __NR_##sname; \ -register long __o0 __asm__ ("o0") = (long)(arg1); \ -register long __o1 __asm__ ("o1") = (long)(arg2); \ -__asm__ __volatile__ ("t 0x10\n\t" \ - "bcc 1f\n\t" \ - "mov %%o0, %0\n\t" \ - "sub %%g0, %%o0, %0\n\t" \ - "1:\n\t" \ - : "=r" (__res), "=&r" (__o0) \ - : "1" (__o0), "r" (__o1), "r" (__g1) \ - : "cc"); \ -return (type) __res; \ -} - -#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \ -type fname(type1 arg1,type2 arg2,type3 arg3) \ -{ \ -long __res; \ -register long __g1 __asm__ ("g1") = __NR_##sname; \ -register long __o0 __asm__ ("o0") = (long)(arg1); \ -register long __o1 __asm__ ("o1") = (long)(arg2); \ -register long __o2 __asm__ ("o2") = (long)(arg3); \ -__asm__ __volatile__ ("t 0x10\n\t" \ - "bcc 1f\n\t" \ - "mov %%o0, %0\n\t" \ - "sub %%g0, %%o0, %0\n\t" \ - "1:\n\t" \ - : "=r" (__res), "=&r" (__o0) \ - : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__g1) \ - : "cc"); \ -return (type) __res; \ -} - -#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ -type fname (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ -{ \ -long __res; \ -register long __g1 __asm__ ("g1") = __NR_##sname; \ -register long __o0 __asm__ ("o0") = (long)(arg1); \ -register long __o1 __asm__ ("o1") = (long)(arg2); \ -register long __o2 __asm__ ("o2") = (long)(arg3); \ -register long __o3 __asm__ ("o3") = (long)(arg4); \ -__asm__ __volatile__ ("t 0x10\n\t" \ - "bcc 1f\n\t" \ - "mov %%o0, %0\n\t" \ - "sub %%g0, %%o0, %0\n\t" \ - "1:\n\t" \ - : "=r" (__res), "=&r" (__o0) \ - : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__o3), "r" (__g1) \ - : "cc"); \ -return (type) __res; \ -} - -#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ - type5,arg5) \ -type fname (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ -{ \ -long __res; \ -register long __g1 __asm__ ("g1") = __NR_##sname; \ -register long __o0 __asm__ ("o0") = (long)(arg1); \ -register long __o1 __asm__ ("o1") = (long)(arg2); \ -register long __o2 __asm__ ("o2") = (long)(arg3); \ -register long __o3 __asm__ ("o3") = (long)(arg4); \ -register long __o4 __asm__ ("o4") = (long)(arg5); \ -__asm__ __volatile__ ("t 0x10\n\t" \ - "bcc 1f\n\t" \ - "mov %%o0, %0\n\t" \ - "sub %%g0, %%o0, %0\n\t" \ - "1:\n\t" \ - : "=r" (__res), "=&r" (__o0) \ - : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__o3), "r" (__o4), "r" (__g1) \ - : "cc"); \ -return (type) __res; \ -} diff --git a/src/syscall-x86_64.h b/src/syscall-x86_64.h index 9361856..84b2639 100644 --- a/src/syscall-x86_64.h +++ b/src/syscall-x86_64.h @@ -3,61 +3,3 @@ #define __NR_io_getevents 208 #define __NR_io_submit 209 #define __NR_io_cancel 210 - -#define __syscall_clobber "r11","rcx","memory" -#define __syscall "syscall" - -#define io_syscall1(type,fname,sname,type1,arg1) \ -type fname(type1 arg1) \ -{ \ -long __res; \ -__asm__ volatile (__syscall \ - : "=a" (__res) \ - : "0" (__NR_##sname),"D" ((long)(arg1)) : __syscall_clobber ); \ -return __res; \ -} - -#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ -type fname(type1 arg1,type2 arg2) \ -{ \ -long __res; \ -__asm__ volatile (__syscall \ - : "=a" (__res) \ - : "0" (__NR_##sname),"D" ((long)(arg1)),"S" ((long)(arg2)) : __syscall_clobber ); \ -return __res; \ -} - -#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \ -type fname(type1 arg1,type2 arg2,type3 arg3) \ -{ \ -long __res; \ -__asm__ volatile (__syscall \ - : "=a" (__res) \ - : "0" (__NR_##sname),"D" ((long)(arg1)),"S" ((long)(arg2)), \ - "d" ((long)(arg3)) : __syscall_clobber); \ -return __res; \ -} - -#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ -type fname (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ -{ \ -long __res; \ -__asm__ volatile ("movq %5,%%r10 ;" __syscall \ - : "=a" (__res) \ - : "0" (__NR_##sname),"D" ((long)(arg1)),"S" ((long)(arg2)), \ - "d" ((long)(arg3)),"g" ((long)(arg4)) : __syscall_clobber,"r10" ); \ -return __res; \ -} - -#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ - type5,arg5) \ -type fname (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ -{ \ -long __res; \ -__asm__ volatile ("movq %5,%%r10 ; movq %6,%%r8 ; " __syscall \ - : "=a" (__res) \ - : "0" (__NR_##sname),"D" ((long)(arg1)),"S" ((long)(arg2)), \ - "d" ((long)(arg3)),"g" ((long)(arg4)),"g" ((long)(arg5)) : \ - __syscall_clobber,"r8","r10" ); \ -return __res; \ -} diff --git a/src/syscall.h b/src/syscall.h index a2da030..6a0a76c 100644 --- a/src/syscall.h +++ b/src/syscall.h @@ -1,5 +1,6 @@ #include <sys/syscall.h> #include <unistd.h> +#include <errno.h> #define _SYMSTR(str) #str #define SYMSTR(str) _SYMSTR(str) @@ -29,6 +30,37 @@ #elif defined(__aarch64__) #include "syscall-arm64.h" #else -#warning "using generic syscall method" -#include "syscall-generic.h" +#warning "using system call numbers from sys/syscall.h" #endif + +#define _body_io_syscall(sname, args...) \ +{ \ + int ret, saved_errno; \ + saved_errno = errno; \ + ret= syscall(__NR_##sname, ## args); \ + if (ret < 0) { \ + ret = -errno; \ + errno = saved_errno; \ + } \ + return ret; \ +} + +#define io_syscall1(type,fname,sname,type1,arg1) \ +type fname(type1 arg1) \ +_body_io_syscall(sname, (long)arg1) + +#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ +type fname(type1 arg1,type2 arg2) \ +_body_io_syscall(sname, (long)arg1, (long)arg2) + +#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \ +type fname(type1 arg1,type2 arg2,type3 arg3) \ +_body_io_syscall(sname, (long)arg1, (long)arg2, (long)arg3) + +#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ +type fname (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ +_body_io_syscall(sname, (long)arg1, (long)arg2, (long)arg3, (long)arg4) + +#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4, type5,arg5) \ +type fname (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ +_body_io_syscall(sname, (long)arg1, (long)arg2, (long)arg3, (long)arg4, (long)arg5) |