From: Rich Felker Date: Sun, 9 Sep 2012 02:43:14 +0000 (-0400) Subject: syscall organization overhaul X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=commitdiff_plain;h=208eb584efbf995e0c5d92f76d5f4c08ae0054b4 syscall organization overhaul now public syscall.h only exposes __NR_* and SYS_* constants and the variadic syscall function. no macros or inline functions, no __syscall_ret or other internal details, no 16-/32-bit legacy syscall renaming, etc. this logic has all been moved to src/internal/syscall.h with the arch-specific parts in arch/$(ARCH)/syscall_arch.h, and the amount of arch-specific stuff has been reduced to a minimum. changes still need to be reviewed/double-checked. minimal testing on i386 and mips has already been performed. --- diff --git a/arch/arm/bits/syscall.h b/arch/arm/bits/syscall.h index c5e25b76..1be213d0 100644 --- a/arch/arm/bits/syscall.h +++ b/arch/arm/bits/syscall.h @@ -1,50 +1,3 @@ -#define __SYSCALL_LL_E(x) \ -((union { long long ll; long l[2]; }){ .ll = x }).l[0], \ -((union { long long ll; long l[2]; }){ .ll = x }).l[1] -#define __SYSCALL_LL_O(x) 0, __SYSCALL_LL_E((x)) - -#define __SYSCALL_SSLEN 8 - -long (__syscall)(long, ...); - -static __inline long __syscall0(long n) -{ - return (__syscall)(n); -} - -static __inline long __syscall1(long n, long a) -{ - return (__syscall)(n, a); -} - -static __inline long __syscall2(long n, long a, long b) -{ - return (__syscall)(n, a, b); -} - -static __inline long __syscall3(long n, long a, long b, long c) -{ - return (__syscall)(n, a, b, c); -} - -static __inline long __syscall4(long n, long a, long b, long c, long d) -{ - return (__syscall)(n, a, b, c, d); -} - -static __inline long __syscall5(long n, long a, long b, long c, long d, long e) -{ - return (__syscall)(n, a, b, c, d, e); -} - -static __inline long __syscall6(long n, long a, long b, long c, long d, long e, long f) -{ - return (__syscall)(n, a, b, c, d, e, f); -} - -#define __socketcall(nm,a,b,c,d,e,f) syscall(SYS_##nm, a, b, c, d, e, f) -#define __socketcall_cp(nm,a,b,c,d,e,f) syscall_cp(SYS_##nm, a, b, c, d, e, f) - #define __NR_restart_syscall 0 #define __NR_exit 1 #define __NR_fork 2 @@ -379,78 +332,6 @@ static __inline long __syscall6(long n, long a, long b, long c, long d, long e, #define __NR_process_vm_readv 376 #define __NR_process_vm_writev 377 -/* fixup legacy 16-bit junk */ -#undef __NR_lchown -#undef __NR_getuid -#undef __NR_getgid -#undef __NR_geteuid -#undef __NR_getegid -#undef __NR_setreuid -#undef __NR_setregid -#undef __NR_getgroups -#undef __NR_setgroups -#undef __NR_fchown -#undef __NR_setresuid -#undef __NR_getresuid -#undef __NR_setresgid -#undef __NR_getresgid -#undef __NR_chown -#undef __NR_setuid -#undef __NR_setgid -#undef __NR_setfsuid -#undef __NR_setfsgid -#define __NR_lchown __NR_lchown32 -#define __NR_getuid __NR_getuid32 -#define __NR_getgid __NR_getgid32 -#define __NR_geteuid __NR_geteuid32 -#define __NR_getegid __NR_getegid32 -#define __NR_setreuid __NR_setreuid32 -#define __NR_setregid __NR_setregid32 -#define __NR_getgroups __NR_getgroups32 -#define __NR_setgroups __NR_setgroups32 -#define __NR_fchown __NR_fchown32 -#define __NR_setresuid __NR_setresuid32 -#define __NR_getresuid __NR_getresuid32 -#define __NR_setresgid __NR_setresgid32 -#define __NR_getresgid __NR_getresgid32 -#define __NR_chown __NR_chown32 -#define __NR_setuid __NR_setuid32 -#define __NR_setgid __NR_setgid32 -#define __NR_setfsuid __NR_setfsuid32 -#define __NR_setfsgid __NR_setfsgid32 - - -/* fixup legacy 32-bit-vs-lfs64 junk */ -#undef __NR_fcntl -#undef __NR_getdents -#undef __NR_ftruncate -#undef __NR_truncate -#undef __NR_stat -#undef __NR_fstat -#undef __NR_lstat -#undef __NR_statfs -#undef __NR_fstatfs -#define __NR_fcntl __NR_fcntl64 -#define __NR_getdents __NR_getdents64 -#define __NR_ftruncate __NR_ftruncate64 -#define __NR_truncate __NR_truncate64 -#define __NR_stat __NR_stat64 -#define __NR_fstat __NR_fstat64 -#define __NR_lstat __NR_lstat64 -#define __NR_statfs __NR_statfs64 -#define __NR_fstatfs __NR_fstatfs64 -#define __NR_fstatat __NR_fstatat64 -#define __NR_pread __NR_pread64 -#define __NR_pwrite __NR_pwrite64 - -#define __NR_fadvise __NR_fadvise64_64 - -#undef __NR_getrlimit -#define __NR_getrlimit __NR_ugetrlimit - -#undef __NR_select -#define __NR_select __NR__newselect - /* Repeated with SYS_ prefix */ @@ -787,75 +668,3 @@ static __inline long __syscall6(long n, long a, long b, long c, long d, long e, #define SYS_setns 375 #define SYS_process_vm_readv 376 #define SYS_process_vm_writev 377 - -/* fixup legacy 16-bit junk */ -#undef SYS_lchown -#undef SYS_getuid -#undef SYS_getgid -#undef SYS_geteuid -#undef SYS_getegid -#undef SYS_setreuid -#undef SYS_setregid -#undef SYS_getgroups -#undef SYS_setgroups -#undef SYS_fchown -#undef SYS_setresuid -#undef SYS_getresuid -#undef SYS_setresgid -#undef SYS_getresgid -#undef SYS_chown -#undef SYS_setuid -#undef SYS_setgid -#undef SYS_setfsuid -#undef SYS_setfsgid -#define SYS_lchown SYS_lchown32 -#define SYS_getuid SYS_getuid32 -#define SYS_getgid SYS_getgid32 -#define SYS_geteuid SYS_geteuid32 -#define SYS_getegid SYS_getegid32 -#define SYS_setreuid SYS_setreuid32 -#define SYS_setregid SYS_setregid32 -#define SYS_getgroups SYS_getgroups32 -#define SYS_setgroups SYS_setgroups32 -#define SYS_fchown SYS_fchown32 -#define SYS_setresuid SYS_setresuid32 -#define SYS_getresuid SYS_getresuid32 -#define SYS_setresgid SYS_setresgid32 -#define SYS_getresgid SYS_getresgid32 -#define SYS_chown SYS_chown32 -#define SYS_setuid SYS_setuid32 -#define SYS_setgid SYS_setgid32 -#define SYS_setfsuid SYS_setfsuid32 -#define SYS_setfsgid SYS_setfsgid32 - - -/* fixup legacy 32-bit-vs-lfs64 junk */ -#undef SYS_fcntl -#undef SYS_getdents -#undef SYS_ftruncate -#undef SYS_truncate -#undef SYS_stat -#undef SYS_fstat -#undef SYS_lstat -#undef SYS_statfs -#undef SYS_fstatfs -#define SYS_fcntl SYS_fcntl64 -#define SYS_getdents SYS_getdents64 -#define SYS_ftruncate SYS_ftruncate64 -#define SYS_truncate SYS_truncate64 -#define SYS_stat SYS_stat64 -#define SYS_fstat SYS_fstat64 -#define SYS_lstat SYS_lstat64 -#define SYS_statfs SYS_statfs64 -#define SYS_fstatfs SYS_fstatfs64 -#define SYS_fstatat SYS_fstatat64 -#define SYS_pread SYS_pread64 -#define SYS_pwrite SYS_pwrite64 - -#define SYS_fadvise SYS_fadvise64_64 - -#undef SYS_getrlimit -#define SYS_getrlimit SYS_ugetrlimit - -#undef SYS_select -#define SYS_select SYS__newselect diff --git a/arch/arm/syscall_arch.h b/arch/arm/syscall_arch.h new file mode 100644 index 00000000..48b0e36b --- /dev/null +++ b/arch/arm/syscall_arch.h @@ -0,0 +1,41 @@ +#define __SYSCALL_LL_E(x) \ +((union { long long ll; long l[2]; }){ .ll = x }).l[0], \ +((union { long long ll; long l[2]; }){ .ll = x }).l[1] +#define __SYSCALL_LL_O(x) 0, __SYSCALL_LL_E((x)) + +#define __SYSCALL_SSLEN 8 + +static inline long __syscall0(long n) +{ + return (__syscall)(n); +} + +static inline long __syscall1(long n, long a) +{ + return (__syscall)(n, a); +} + +static inline long __syscall2(long n, long a, long b) +{ + return (__syscall)(n, a, b); +} + +static inline long __syscall3(long n, long a, long b, long c) +{ + return (__syscall)(n, a, b, c); +} + +static inline long __syscall4(long n, long a, long b, long c, long d) +{ + return (__syscall)(n, a, b, c, d); +} + +static inline long __syscall5(long n, long a, long b, long c, long d, long e) +{ + return (__syscall)(n, a, b, c, d, e); +} + +static inline long __syscall6(long n, long a, long b, long c, long d, long e, long f) +{ + return (__syscall)(n, a, b, c, d, e, f); +} diff --git a/arch/i386/bits/syscall.h b/arch/i386/bits/syscall.h index c36d81fa..0bedf3f3 100644 --- a/arch/i386/bits/syscall.h +++ b/arch/i386/bits/syscall.h @@ -1,145 +1,3 @@ -#define __SYSCALL_LL_E(x) \ -((union { long long ll; long l[2]; }){ .ll = x }).l[0], \ -((union { long long ll; long l[2]; }){ .ll = x }).l[1] -#define __SYSCALL_LL_O(x) __SYSCALL_LL_E((x)) - -#define __SYSCALL_SSLEN 8 - -static __inline long __syscall0(long __n) -{ - unsigned long __ret; - __asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n) : "memory"); - return __ret; -} - -#ifndef __PIC__ - -static __inline long __syscall1(long __n, long __a1) -{ - unsigned long __ret; - __asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1) : "memory"); - return __ret; -} - -static __inline long __syscall2(long __n, long __a1, long __a2) -{ - unsigned long __ret; - __asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1), "c"(__a2) : "memory"); - return __ret; -} - -static __inline long __syscall3(long __n, long __a1, long __a2, long __a3) -{ - unsigned long __ret; - __asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1), "c"(__a2), "d"(__a3) : "memory"); - return __ret; -} - -static __inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4) -{ - unsigned long __ret; - __asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1), "c"(__a2), "d"(__a3), "S"(__a4) : "memory"); - return __ret; -} - -static __inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5) -{ - unsigned long __ret; - __asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1), "c"(__a2), "d"(__a3), "S"(__a4), "D"(__a5) : "memory"); - return __ret; -} - -static __inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6) -{ - unsigned long __ret; - __asm__ __volatile__ ("pushl %7 ; pushl %%ebp ; mov 4(%%esp),%%ebp ; int $128 ; popl %%ebp ; popl %%ecx" - : "=a"(__ret) : "a"(__n), "b"(__a1), "c"(__a2), "d"(__a3), "S"(__a4), "D"(__a5), "g"(__a6) : "memory"); - return __ret; -} - -#else - -static __inline long __syscall1(long __n, long __a1) -{ - unsigned long __ret; - __asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx" - : "=a"(__ret) : "a"(__n), "d"(__a1) : "memory"); - return __ret; -} - -static __inline long __syscall2(long __n, long __a1, long __a2) -{ - unsigned long __ret; - __asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx" - : "=a"(__ret) : "a"(__n), "d"(__a1), "c"(__a2) : "memory"); - return __ret; -} - -static __inline long __syscall3(long __n, long __a1, long __a2, long __a3) -{ - unsigned long __ret; - __asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx" - : "=a"(__ret) : "a"(__n), "S"(__a1), "c"(__a2), "d"(__a3) : "memory"); - return __ret; -} - -static __inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4) -{ - unsigned long __ret; - __asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx" - : "=a"(__ret) : "a"(__n), "D"(__a1), "c"(__a2), "d"(__a3), "S"(__a4) : "memory"); - return __ret; -} - -#if 0 -static __inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5) -{ - unsigned long __ret; - __asm__ __volatile__ ("pushl %2 ; pushl %%ebx ; mov 4(%%esp),%%ebx ; int $128 ; popl %%ebx ; popl %%ecx" - : "=a"(__ret) : "a"(__n), "g"(__a1), "c"(__a2), "d"(__a3), "S"(__a4), "D"(__a5) : "memory"); - return __ret; -} -#else -static __inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5) -{ - return (__syscall)(__n, __a1, __a2, __a3, __a4, __a5); -} -#endif - -static __inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6) -{ - return (__syscall)(__n, __a1, __a2, __a3, __a4, __a5, __a6); -} - -#endif - - -#define __SC_socket 1 -#define __SC_bind 2 -#define __SC_connect 3 -#define __SC_listen 4 -#define __SC_accept 5 -#define __SC_getsockname 6 -#define __SC_getpeername 7 -#define __SC_socketpair 8 -#define __SC_send 9 -#define __SC_recv 10 -#define __SC_sendto 11 -#define __SC_recvfrom 12 -#define __SC_shutdown 13 -#define __SC_setsockopt 14 -#define __SC_getsockopt 15 -#define __SC_sendmsg 16 -#define __SC_recvmsg 17 -#define __SC_accept4 18 -#define __SC_recvmmsg 19 -#define __SC_sendmmsg 20 - -#define __socketcall(nm,a,b,c,d,e,f) syscall(SYS_socketcall, __SC_##nm, \ - ((long [6]){ (long)a, (long)b, (long)c, (long)d, (long)e, (long)f })) -#define __socketcall_cp(nm,a,b,c,d,e,f) syscall_cp(SYS_socketcall, __SC_##nm, \ - ((long [6]){ (long)a, (long)b, (long)c, (long)d, (long)e, (long)f })) - #define __NR_restart_syscall 0 #define __NR_exit 1 #define __NR_fork 2 @@ -485,78 +343,6 @@ static __inline long __syscall6(long __n, long __a1, long __a2, long __a3, long #define __NR_process_vm_readv 347 #define __NR_process_vm_writev 348 -/* fixup legacy 16-bit junk */ -#undef __NR_lchown -#undef __NR_getuid -#undef __NR_getgid -#undef __NR_geteuid -#undef __NR_getegid -#undef __NR_setreuid -#undef __NR_setregid -#undef __NR_getgroups -#undef __NR_setgroups -#undef __NR_fchown -#undef __NR_setresuid -#undef __NR_getresuid -#undef __NR_setresgid -#undef __NR_getresgid -#undef __NR_chown -#undef __NR_setuid -#undef __NR_setgid -#undef __NR_setfsuid -#undef __NR_setfsgid -#define __NR_lchown __NR_lchown32 -#define __NR_getuid __NR_getuid32 -#define __NR_getgid __NR_getgid32 -#define __NR_geteuid __NR_geteuid32 -#define __NR_getegid __NR_getegid32 -#define __NR_setreuid __NR_setreuid32 -#define __NR_setregid __NR_setregid32 -#define __NR_getgroups __NR_getgroups32 -#define __NR_setgroups __NR_setgroups32 -#define __NR_fchown __NR_fchown32 -#define __NR_setresuid __NR_setresuid32 -#define __NR_getresuid __NR_getresuid32 -#define __NR_setresgid __NR_setresgid32 -#define __NR_getresgid __NR_getresgid32 -#define __NR_chown __NR_chown32 -#define __NR_setuid __NR_setuid32 -#define __NR_setgid __NR_setgid32 -#define __NR_setfsuid __NR_setfsuid32 -#define __NR_setfsgid __NR_setfsgid32 - - -/* fixup legacy 32-bit-vs-lfs64 junk */ -#undef __NR_fcntl -#undef __NR_getdents -#undef __NR_ftruncate -#undef __NR_truncate -#undef __NR_stat -#undef __NR_fstat -#undef __NR_lstat -#undef __NR_statfs -#undef __NR_fstatfs -#define __NR_fcntl __NR_fcntl64 -#define __NR_getdents __NR_getdents64 -#define __NR_ftruncate __NR_ftruncate64 -#define __NR_truncate __NR_truncate64 -#define __NR_stat __NR_stat64 -#define __NR_fstat __NR_fstat64 -#define __NR_lstat __NR_lstat64 -#define __NR_statfs __NR_statfs64 -#define __NR_fstatfs __NR_fstatfs64 -#define __NR_fstatat __NR_fstatat64 -#define __NR_pread __NR_pread64 -#define __NR_pwrite __NR_pwrite64 - -#define __NR_fadvise __NR_fadvise64_64 - -#undef __NR_getrlimit -#define __NR_getrlimit __NR_ugetrlimit - -#undef __NR_select -#define __NR_select __NR__newselect - /* Repeated with SYS_ prefix */ @@ -904,75 +690,3 @@ static __inline long __syscall6(long __n, long __a1, long __a2, long __a3, long #define SYS_setns 346 #define SYS_process_vm_readv 347 #define SYS_process_vm_writev 348 - -/* fixup legacy 16-bit junk */ -#undef SYS_lchown -#undef SYS_getuid -#undef SYS_getgid -#undef SYS_geteuid -#undef SYS_getegid -#undef SYS_setreuid -#undef SYS_setregid -#undef SYS_getgroups -#undef SYS_setgroups -#undef SYS_fchown -#undef SYS_setresuid -#undef SYS_getresuid -#undef SYS_setresgid -#undef SYS_getresgid -#undef SYS_chown -#undef SYS_setuid -#undef SYS_setgid -#undef SYS_setfsuid -#undef SYS_setfsgid -#define SYS_lchown SYS_lchown32 -#define SYS_getuid SYS_getuid32 -#define SYS_getgid SYS_getgid32 -#define SYS_geteuid SYS_geteuid32 -#define SYS_getegid SYS_getegid32 -#define SYS_setreuid SYS_setreuid32 -#define SYS_setregid SYS_setregid32 -#define SYS_getgroups SYS_getgroups32 -#define SYS_setgroups SYS_setgroups32 -#define SYS_fchown SYS_fchown32 -#define SYS_setresuid SYS_setresuid32 -#define SYS_getresuid SYS_getresuid32 -#define SYS_setresgid SYS_setresgid32 -#define SYS_getresgid SYS_getresgid32 -#define SYS_chown SYS_chown32 -#define SYS_setuid SYS_setuid32 -#define SYS_setgid SYS_setgid32 -#define SYS_setfsuid SYS_setfsuid32 -#define SYS_setfsgid SYS_setfsgid32 - - -/* fixup legacy 32-bit-vs-lfs64 junk */ -#undef SYS_fcntl -#undef SYS_getdents -#undef SYS_ftruncate -#undef SYS_truncate -#undef SYS_stat -#undef SYS_fstat -#undef SYS_lstat -#undef SYS_statfs -#undef SYS_fstatfs -#define SYS_fcntl SYS_fcntl64 -#define SYS_getdents SYS_getdents64 -#define SYS_ftruncate SYS_ftruncate64 -#define SYS_truncate SYS_truncate64 -#define SYS_stat SYS_stat64 -#define SYS_fstat SYS_fstat64 -#define SYS_lstat SYS_lstat64 -#define SYS_statfs SYS_statfs64 -#define SYS_fstatfs SYS_fstatfs64 -#define SYS_fstatat SYS_fstatat64 -#define SYS_pread SYS_pread64 -#define SYS_pwrite SYS_pwrite64 - -#define SYS_fadvise SYS_fadvise64_64 - -#undef SYS_getrlimit -#define SYS_getrlimit SYS_ugetrlimit - -#undef SYS_select -#define SYS_select SYS__newselect diff --git a/arch/i386/syscall_arch.h b/arch/i386/syscall_arch.h new file mode 100644 index 00000000..dc9ad147 --- /dev/null +++ b/arch/i386/syscall_arch.h @@ -0,0 +1,136 @@ +#define __SYSCALL_LL_E(x) \ +((union { long long ll; long l[2]; }){ .ll = x }).l[0], \ +((union { long long ll; long l[2]; }){ .ll = x }).l[1] +#define __SYSCALL_LL_O(x) __SYSCALL_LL_E((x)) + +#define __SYSCALL_SSLEN 8 + +static inline long __syscall0(long n) +{ + unsigned long __ret; + __asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(n) : "memory"); + return __ret; +} + +#ifndef __PIC__ + +static inline long __syscall1(long n, long a1) +{ + unsigned long __ret; + __asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(n), "b"(a1) : "memory"); + return __ret; +} + +static inline long __syscall2(long n, long a1, long a2) +{ + unsigned long __ret; + __asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(n), "b"(a1), "c"(a2) : "memory"); + return __ret; +} + +static inline long __syscall3(long n, long a1, long a2, long a3) +{ + unsigned long __ret; + __asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(n), "b"(a1), "c"(a2), "d"(a3) : "memory"); + return __ret; +} + +static inline long __syscall4(long n, long a1, long a2, long a3, long a4) +{ + unsigned long __ret; + __asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(n), "b"(a1), "c"(a2), "d"(a3), "S"(a4) : "memory"); + return __ret; +} + +static inline long __syscall5(long n, long a1, long a2, long a3, long a4, long a5) +{ + unsigned long __ret; + __asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(n), "b"(a1), "c"(a2), "d"(a3), "S"(a4), "D"(a5) : "memory"); + return __ret; +} + +static inline long __syscall6(long n, long a1, long a2, long a3, long a4, long a5, long a6) +{ + unsigned long __ret; + __asm__ __volatile__ ("pushl %7 ; pushl %%ebp ; mov 4(%%esp),%%ebp ; int $128 ; popl %%ebp ; popl %%ecx" + : "=a"(__ret) : "a"(n), "b"(a1), "c"(a2), "d"(a3), "S"(a4), "D"(a5), "g"(a6) : "memory"); + return __ret; +} + +#else + +static inline long __syscall1(long n, long a1) +{ + unsigned long __ret; + __asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx" + : "=a"(__ret) : "a"(n), "d"(a1) : "memory"); + return __ret; +} + +static inline long __syscall2(long n, long a1, long a2) +{ + unsigned long __ret; + __asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx" + : "=a"(__ret) : "a"(n), "d"(a1), "c"(a2) : "memory"); + return __ret; +} + +static inline long __syscall3(long n, long a1, long a2, long a3) +{ + unsigned long __ret; + __asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx" + : "=a"(__ret) : "a"(n), "S"(a1), "c"(a2), "d"(a3) : "memory"); + return __ret; +} + +static inline long __syscall4(long n, long a1, long a2, long a3, long a4) +{ + unsigned long __ret; + __asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx" + : "=a"(__ret) : "a"(n), "D"(a1), "c"(a2), "d"(a3), "S"(a4) : "memory"); + return __ret; +} + +#if 0 +static inline long __syscall5(long n, long a1, long a2, long a3, long a4, long a5) +{ + unsigned long __ret; + __asm__ __volatile__ ("pushl %2 ; pushl %%ebx ; mov 4(%%esp),%%ebx ; int $128 ; popl %%ebx ; popl %%ecx" + : "=a"(__ret) : "a"(n), "g"(a1), "c"(a2), "d"(a3), "S"(a4), "D"(a5) : "memory"); + return __ret; +} +#else +static inline long __syscall5(long n, long a1, long a2, long a3, long a4, long a5) +{ + return (__syscall)(n, a1, a2, a3, a4, a5); +} +#endif + +static inline long __syscall6(long n, long a1, long a2, long a3, long a4, long a5, long a6) +{ + return (__syscall)(n, a1, a2, a3, a4, a5, a6); +} + +#endif + + +#define __SC_socket 1 +#define __SC_bind 2 +#define __SC_connect 3 +#define __SC_listen 4 +#define __SC_accept 5 +#define __SC_getsockname 6 +#define __SC_getpeername 7 +#define __SC_socketpair 8 +#define __SC_send 9 +#define __SC_recv 10 +#define __SC_sendto 11 +#define __SC_recvfrom 12 +#define __SC_shutdown 13 +#define __SC_setsockopt 14 +#define __SC_getsockopt 15 +#define __SC_sendmsg 16 +#define __SC_recvmsg 17 +#define __SC_accept4 18 +#define __SC_recvmmsg 19 +#define __SC_sendmmsg 20 diff --git a/arch/mips/bits/syscall.h b/arch/mips/bits/syscall.h index 9a2de2e3..66af2277 100644 --- a/arch/mips/bits/syscall.h +++ b/arch/mips/bits/syscall.h @@ -1,50 +1,3 @@ -#define __SYSCALL_LL_E(x) \ -((union { long long ll; long l[2]; }){ .ll = x }).l[0], \ -((union { long long ll; long l[2]; }){ .ll = x }).l[1] -#define __SYSCALL_LL_O(x) 0, __SYSCALL_LL_E((x)) - -#define __SYSCALL_SSLEN 16 - -long (__syscall)(long, ...); - -static __inline long __syscall0(long n) -{ - return (__syscall)(n); -} - -static __inline long __syscall1(long n, long a) -{ - return (__syscall)(n, a); -} - -static __inline long __syscall2(long n, long a, long b) -{ - return (__syscall)(n, a, b); -} - -static __inline long __syscall3(long n, long a, long b, long c) -{ - return (__syscall)(n, a, b, c); -} - -static __inline long __syscall4(long n, long a, long b, long c, long d) -{ - return (__syscall)(n, a, b, c, d); -} - -static __inline long __syscall5(long n, long a, long b, long c, long d, long e) -{ - return (__syscall)(n, a, b, c, d, e); -} - -static __inline long __syscall6(long n, long a, long b, long c, long d, long e, long f) -{ - return (__syscall)(n, a, b, c, d, e, f); -} - -#define __socketcall(nm,a,b,c,d,e,f) syscall(SYS_##nm, a, b, c, d, e, f) -#define __socketcall_cp(nm,a,b,c,d,e,f) syscall_cp(SYS_##nm, a, b, c, d, e, f) - #define __NR_syscall 4000 #define __NR_exit 4001 #define __NR_fork 4002 @@ -416,26 +369,6 @@ static __inline long __syscall6(long n, long a, long b, long c, long d, long e, #define __NR_process_vm_readv 4345 #define __NR_process_vm_writev 4346 -/* fixup legacy 32-bit-vs-lfs64 junk */ -#undef __NR_fcntl -#undef __NR_getdents -#undef __NR_ftruncate -#undef __NR_truncate -#undef __NR_stat -#undef __NR_fstat -#undef __NR_lstat -#undef __NR_statfs -#undef __NR_fstatfs -#define __NR_fcntl __NR_fcntl64 -#define __NR_getdents __NR_getdents64 -#define __NR_ftruncate __NR_ftruncate64 -#define __NR_truncate __NR_truncate64 -#define __NR_stat __NR_stat64 -#define __NR_fstat __NR_fstat64 -#define __NR_lstat __NR_lstat64 -#define __NR_statfs __NR_statfs64 -#define __NR_fstatfs __NR_fstatfs64 - /* Repeated with SYS_ prefix */ #define SYS_syscall 4000 @@ -808,23 +741,3 @@ static __inline long __syscall6(long n, long a, long b, long c, long d, long e, #define SYS_setns 4344 #define SYS_process_vm_readv 4345 #define SYS_process_vm_writev 4346 - -/* fixup legacy 32-bit-vs-lfs64 junk */ -#undef SYS_fcntl -#undef SYS_getdents -#undef SYS_ftruncate -#undef SYS_truncate -#undef SYS_stat -#undef SYS_fstat -#undef SYS_lstat -#undef SYS_statfs -#undef SYS_fstatfs -#define SYS_fcntl SYS_fcntl64 -#define SYS_getdents SYS_getdents64 -#define SYS_ftruncate SYS_ftruncate64 -#define SYS_truncate SYS_truncate64 -#define SYS_stat SYS_stat64 -#define SYS_fstat SYS_fstat64 -#define SYS_lstat SYS_lstat64 -#define SYS_statfs SYS_statfs64 -#define SYS_fstatfs SYS_fstatfs64 diff --git a/arch/mips/syscall_arch.h b/arch/mips/syscall_arch.h new file mode 100644 index 00000000..68e8dce3 --- /dev/null +++ b/arch/mips/syscall_arch.h @@ -0,0 +1,41 @@ +#define __SYSCALL_LL_E(x) \ +((union { long long ll; long l[2]; }){ .ll = x }).l[0], \ +((union { long long ll; long l[2]; }){ .ll = x }).l[1] +#define __SYSCALL_LL_O(x) 0, __SYSCALL_LL_E((x)) + +#define __SYSCALL_SSLEN 16 + +static inline long __syscall0(long n) +{ + return (__syscall)(n); +} + +static inline long __syscall1(long n, long a) +{ + return (__syscall)(n, a); +} + +static inline long __syscall2(long n, long a, long b) +{ + return (__syscall)(n, a, b); +} + +static inline long __syscall3(long n, long a, long b, long c) +{ + return (__syscall)(n, a, b, c); +} + +static inline long __syscall4(long n, long a, long b, long c, long d) +{ + return (__syscall)(n, a, b, c, d); +} + +static inline long __syscall5(long n, long a, long b, long c, long d, long e) +{ + return (__syscall)(n, a, b, c, d, e); +} + +static inline long __syscall6(long n, long a, long b, long c, long d, long e, long f) +{ + return (__syscall)(n, a, b, c, d, e, f); +} diff --git a/arch/x86_64/bits/syscall.h b/arch/x86_64/bits/syscall.h index 217515f3..1ca5db27 100644 --- a/arch/x86_64/bits/syscall.h +++ b/arch/x86_64/bits/syscall.h @@ -1,71 +1,3 @@ -#define __SYSCALL_LL_E(x) (x) -#define __SYSCALL_LL_O(x) (x) - -#define __SYSCALL_SSLEN 8 - -static __inline long __syscall0(long __n) -{ - unsigned long __ret; - __asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n) : "rcx", "r11", "memory"); - return __ret; -} - -static __inline long __syscall1(long __n, long __a1) -{ - unsigned long __ret; - __asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n), "D"(__a1) : "rcx", "r11", "memory"); - return __ret; -} - -static __inline long __syscall2(long __n, long __a1, long __a2) -{ - unsigned long __ret; - __asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n), "D"(__a1), "S"(__a2) - : "rcx", "r11", "memory"); - return __ret; -} - -static __inline long __syscall3(long __n, long __a1, long __a2, long __a3) -{ - unsigned long __ret; - __asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n), "D"(__a1), "S"(__a2), - "d"(__a3) : "rcx", "r11", "memory"); - return __ret; -} - -static __inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4) -{ - unsigned long __ret; - register long __r10 __asm__("r10") = __a4; - __asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n), "D"(__a1), "S"(__a2), - "d"(__a3), "r"(__r10): "rcx", "r11", "memory"); - return __ret; -} - -static __inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5) -{ - unsigned long __ret; - register long __r10 __asm__("r10") = __a4; - register long __r8 __asm__("r8") = __a5; - __asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n), "D"(__a1), "S"(__a2), - "d"(__a3), "r"(__r10), "r"(__r8) : "rcx", "r11", "memory"); - return __ret; -} - -static __inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6) -{ - unsigned long __ret; - register long __r10 __asm__("r10") = __a4; - register long __r8 __asm__("r8") = __a5; - register long __r9 __asm__("r9") = __a6; - __asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n), "D"(__a1), "S"(__a2), - "d"(__a3), "r"(__r10), "r"(__r8), "r"(__r9) : "rcx", "r11", "memory"); - return __ret; -} - -#define __socketcall(nm,a,b,c,d,e,f) syscall(__NR_##nm, a, b, c, d, e, f) -#define __socketcall_cp(nm,a,b,c,d,e,f) syscall_cp(__NR_##nm, a, b, c, d, e, f) - #define __NR_read 0 #define __NR_write 1 #define __NR_open 2 diff --git a/arch/x86_64/syscall_arch.h b/arch/x86_64/syscall_arch.h new file mode 100644 index 00000000..1c4b48a2 --- /dev/null +++ b/arch/x86_64/syscall_arch.h @@ -0,0 +1,64 @@ +#define __SYSCALL_LL_E(x) (x) +#define __SYSCALL_LL_O(x) (x) + +#define __SYSCALL_SSLEN 8 + +static __inline long __syscall0(long n) +{ + unsigned long ret; + __asm__ __volatile__ ("syscall" : "=a"(ret) : "a"(n) : "rcx", "r11", "memory"); + return ret; +} + +static __inline long __syscall1(long n, long a1) +{ + unsigned long ret; + __asm__ __volatile__ ("syscall" : "=a"(ret) : "a"(n), "D"(a1) : "rcx", "r11", "memory"); + return ret; +} + +static __inline long __syscall2(long n, long a1, long a2) +{ + unsigned long ret; + __asm__ __volatile__ ("syscall" : "=a"(ret) : "a"(n), "D"(a1), "S"(a2) + : "rcx", "r11", "memory"); + return ret; +} + +static __inline long __syscall3(long n, long a1, long a2, long a3) +{ + unsigned long ret; + __asm__ __volatile__ ("syscall" : "=a"(ret) : "a"(n), "D"(a1), "S"(a2), + "d"(a3) : "rcx", "r11", "memory"); + return ret; +} + +static __inline long __syscall4(long n, long a1, long a2, long a3, long a4) +{ + unsigned long ret; + register long r10 __asm__("r10") = a4; + __asm__ __volatile__ ("syscall" : "=a"(ret) : "a"(n), "D"(a1), "S"(a2), + "d"(a3), "r"(r10): "rcx", "r11", "memory"); + return ret; +} + +static __inline long __syscall5(long n, long a1, long a2, long a3, long a4, long a5) +{ + unsigned long ret; + register long r10 __asm__("r10") = a4; + register long r8 __asm__("r8") = a5; + __asm__ __volatile__ ("syscall" : "=a"(ret) : "a"(n), "D"(a1), "S"(a2), + "d"(a3), "r"(r10), "r"(r8) : "rcx", "r11", "memory"); + return ret; +} + +static __inline long __syscall6(long n, long a1, long a2, long a3, long a4, long a5, long a6) +{ + unsigned long ret; + register long r10 __asm__("r10") = a4; + register long r8 __asm__("r8") = a5; + register long r9 __asm__("r9") = a6; + __asm__ __volatile__ ("syscall" : "=a"(ret) : "a"(n), "D"(a1), "S"(a2), + "d"(a3), "r"(r10), "r"(r8), "r"(r9) : "rcx", "r11", "memory"); + return ret; +} diff --git a/include/sys/syscall.h b/include/sys/syscall.h index 62564d7d..af3ca466 100644 --- a/include/sys/syscall.h +++ b/include/sys/syscall.h @@ -6,28 +6,10 @@ extern "C" { #include -long __syscall_ret(unsigned long); -long __syscall(long, ...); long syscall(long, ...); #include -#define __syscall1(n,a) __syscall1(n,(long)(a)) -#define __syscall2(n,a,b) __syscall2(n,(long)(a),(long)(b)) -#define __syscall3(n,a,b,c) __syscall3(n,(long)(a),(long)(b),(long)(c)) -#define __syscall4(n,a,b,c,d) __syscall4(n,(long)(a),(long)(b),(long)(c),(long)(d)) -#define __syscall5(n,a,b,c,d,e) __syscall5(n,(long)(a),(long)(b),(long)(c),(long)(d),(long)(e)) -#define __syscall6(n,a,b,c,d,e,f) __syscall6(n,(long)(a),(long)(b),(long)(c),(long)(d),(long)(e),(long)(f)) - -#define __SYSCALL_NARGS_X(a,b,c,d,e,f,g,n,...) n -#define __SYSCALL_NARGS(...) __SYSCALL_NARGS_X(__VA_ARGS__,6,5,4,3,2,1,0) -#define __SYSCALL_CONCAT_X(a,b) a##b -#define __SYSCALL_CONCAT(a,b) __SYSCALL_CONCAT_X(a,b) -#define __SYSCALL_DISP(b,...) __SYSCALL_CONCAT(b,__SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__) - -#define __syscall(...) __SYSCALL_DISP(__syscall,__VA_ARGS__) -#define syscall(...) __syscall_ret(__syscall(__VA_ARGS__)) - #ifdef __cplusplus } #endif diff --git a/src/internal/syscall.h b/src/internal/syscall.h index 0d88a0ce..ffaf640a 100644 --- a/src/internal/syscall.h +++ b/src/internal/syscall.h @@ -1,9 +1,28 @@ -#ifndef _SYSCALL_H -#define _SYSCALL_H +#ifndef _INTERNAL_SYSCALL_H +#define _INTERNAL_SYSCALL_H -/* This header is mostly useless leftover wrapper cruft */ +long __syscall_ret(unsigned long); +long __syscall(long, ...); +long __syscall_cp(long, long, long, long, long, long, long); #include +#include "syscall_arch.h" + +#define __syscall1(n,a) __syscall1(n,(long)(a)) +#define __syscall2(n,a,b) __syscall2(n,(long)(a),(long)(b)) +#define __syscall3(n,a,b,c) __syscall3(n,(long)(a),(long)(b),(long)(c)) +#define __syscall4(n,a,b,c,d) __syscall4(n,(long)(a),(long)(b),(long)(c),(long)(d)) +#define __syscall5(n,a,b,c,d,e) __syscall5(n,(long)(a),(long)(b),(long)(c),(long)(d),(long)(e)) +#define __syscall6(n,a,b,c,d,e,f) __syscall6(n,(long)(a),(long)(b),(long)(c),(long)(d),(long)(e),(long)(f)) + +#define __SYSCALL_NARGS_X(a,b,c,d,e,f,g,n,...) n +#define __SYSCALL_NARGS(...) __SYSCALL_NARGS_X(__VA_ARGS__,6,5,4,3,2,1,0) +#define __SYSCALL_CONCAT_X(a,b) a##b +#define __SYSCALL_CONCAT(a,b) __SYSCALL_CONCAT_X(a,b) +#define __SYSCALL_DISP(b,...) __SYSCALL_CONCAT(b,__SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__) + +#define __syscall(...) __SYSCALL_DISP(__syscall,__VA_ARGS__) +#define syscall(...) __syscall_ret(__syscall(__VA_ARGS__)) #define socketcall __socketcall #define socketcall_cp __socketcall_cp @@ -16,9 +35,123 @@ #define __syscall_cp5(n,a,b,c,d,e) (__syscall_cp)(n,(long)(a),(long)(b),(long)(c),(long)(d),(long)(e),0) #define __syscall_cp6(n,a,b,c,d,e,f) (__syscall_cp)(n,(long)(a),(long)(b),(long)(c),(long)(d),(long)(e),(long)(f)) -long (__syscall_cp)(long, long, long, long, long, long, long); - #define __syscall_cp(...) __SYSCALL_DISP(__syscall_cp,__VA_ARGS__) #define syscall_cp(...) __syscall_ret(__syscall_cp(__VA_ARGS__)) +#ifdef SYS_socket +#define __socketcall(nm,a,b,c,d,e,f) syscall(SYS_##nm, a, b, c, d, e, f) +#define __socketcall_cp(nm,a,b,c,d,e,f) syscall_cp(SYS_##nm, a, b, c, d, e, f) +#else +#define __socketcall(nm,a,b,c,d,e,f) syscall(SYS_socketcall, __SC_##nm, \ + ((long [6]){ (long)a, (long)b, (long)c, (long)d, (long)e, (long)f })) +#define __socketcall_cp(nm,a,b,c,d,e,f) syscall_cp(SYS_socketcall, __SC_##nm, \ + ((long [6]){ (long)a, (long)b, (long)c, (long)d, (long)e, (long)f })) +#endif + +/* fixup legacy 16-bit junk */ + +#ifdef SYS_getuid32 +#undef SYS_lchown +#undef SYS_getuid +#undef SYS_getgid +#undef SYS_geteuid +#undef SYS_getegid +#undef SYS_setreuid +#undef SYS_setregid +#undef SYS_getgroups +#undef SYS_setgroups +#undef SYS_fchown +#undef SYS_setresuid +#undef SYS_getresuid +#undef SYS_setresgid +#undef SYS_getresgid +#undef SYS_chown +#undef SYS_setuid +#undef SYS_setgid +#undef SYS_setfsuid +#undef SYS_setfsgid +#define SYS_lchown SYS_lchown32 +#define SYS_getuid SYS_getuid32 +#define SYS_getgid SYS_getgid32 +#define SYS_geteuid SYS_geteuid32 +#define SYS_getegid SYS_getegid32 +#define SYS_setreuid SYS_setreuid32 +#define SYS_setregid SYS_setregid32 +#define SYS_getgroups SYS_getgroups32 +#define SYS_setgroups SYS_setgroups32 +#define SYS_fchown SYS_fchown32 +#define SYS_setresuid SYS_setresuid32 +#define SYS_getresuid SYS_getresuid32 +#define SYS_setresgid SYS_setresgid32 +#define SYS_getresgid SYS_getresgid32 +#define SYS_chown SYS_chown32 +#define SYS_setuid SYS_setuid32 +#define SYS_setgid SYS_setgid32 +#define SYS_setfsuid SYS_setfsuid32 +#define SYS_setfsgid SYS_setfsgid32 +#endif + + +/* fixup legacy 32-bit-vs-lfs64 junk */ + +#ifdef SYS_fcntl64 +#undef SYS_fcntl +#define SYS_fcntl SYS_fcntl64 +#endif + +#ifdef SYS_getdents64 +#undef SYS_getdents +#define SYS_getdents SYS_getdents64 +#endif + +#ifdef SYS_ftruncate64 +#undef SYS_ftruncate +#undef SYS_truncate +#define SYS_ftruncate SYS_ftruncate64 +#define SYS_truncate SYS_truncate64 +#endif + +#ifdef SYS_stat64 +#undef SYS_stat +#undef SYS_fstat +#undef SYS_lstat +#undef SYS_statfs +#undef SYS_fstatfs +#define SYS_stat SYS_stat64 +#define SYS_fstat SYS_fstat64 +#define SYS_lstat SYS_lstat64 +#define SYS_statfs SYS_statfs64 +#define SYS_fstatfs SYS_fstatfs64 +#endif + +#if defined(SYS_newfstatat) +#undef SYS_fstatat +#define SYS_fstatat SYS_newfstatat +#elif defined(SYS_fstatat64) +#undef SYS_fstatat +#define SYS_fstatat SYS_fstatat64 +#endif + +#ifdef SYS_ugetrlimit +#undef SYS_getrlimit +#define SYS_getrlimit SYS_ugetrlimit +#endif + +#ifdef SYS__newselect +#undef SYS_select +#define SYS_select SYS__newselect +#endif + +#ifdef SYS_pread64 +#undef SYS_pread +#undef SYS_pwrite +#define SYS_pread SYS_pread64 +#define SYS_pwrite SYS_pwrite64 +#endif + +#ifdef SYS_fadvise64_64 +#undef SYS_fadvise +#define SYS_fadvise SYS_fadvise64_64 +#endif + #endif