From fe0260400eebb613338a720c9568c10ab4f17225 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 8 Sep 2012 22:23:03 -0400 Subject: [PATCH 01/16] add acct syscall source file, omitted in last syscalls commit --- src/unistd/acct.c | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/unistd/acct.c diff --git a/src/unistd/acct.c b/src/unistd/acct.c new file mode 100644 index 00000000..93847127 --- /dev/null +++ b/src/unistd/acct.c @@ -0,0 +1,9 @@ +#define _GNU_SOURCE +#include +#include "syscall.h" +#include "libc.h" + +int acct(const char *filename) +{ + return syscall(SYS_acct, filename); +} -- 2.20.1 From 208eb584efbf995e0c5d92f76d5f4c08ae0054b4 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 8 Sep 2012 22:43:14 -0400 Subject: [PATCH 02/16] 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. --- arch/arm/bits/syscall.h | 191 ------------------------- arch/arm/syscall_arch.h | 41 ++++++ arch/i386/bits/syscall.h | 286 ------------------------------------- arch/i386/syscall_arch.h | 136 ++++++++++++++++++ arch/mips/bits/syscall.h | 87 ----------- arch/mips/syscall_arch.h | 41 ++++++ arch/x86_64/bits/syscall.h | 68 --------- arch/x86_64/syscall_arch.h | 64 +++++++++ include/sys/syscall.h | 18 --- src/internal/syscall.h | 143 ++++++++++++++++++- 10 files changed, 420 insertions(+), 655 deletions(-) create mode 100644 arch/arm/syscall_arch.h create mode 100644 arch/i386/syscall_arch.h create mode 100644 arch/mips/syscall_arch.h create mode 100644 arch/x86_64/syscall_arch.h 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 -- 2.20.1 From 41c5ee50eee769f85253946e4c4b5706de37e9e9 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 8 Sep 2012 22:48:22 -0400 Subject: [PATCH 03/16] disable sync_file_range for now something is wrong with the logic for the argument layout, resulting in compile errors on mips due to too many args to syscall... further information on how it's supposed to work will be needed before it can be reactivated. --- src/linux/sync_file_range.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/linux/sync_file_range.c b/src/linux/sync_file_range.c index 739e602a..a47dc386 100644 --- a/src/linux/sync_file_range.c +++ b/src/linux/sync_file_range.c @@ -1,13 +1,14 @@ #define _GNU_SOURCE #include +#include #include "syscall.h" int sync_file_range(int fd, off_t pos, off_t len, unsigned flags) { -#if defined(SYS_sync_file_range2) +#if 0 && defined(SYS_sync_file_range2) return syscall(SYS_sync_file_range2, fd, flags, __SYSCALL_LL_E(pos), __SYSCALL_LL_E(len)); -#elif defined(SYS_sync_file_range) +#elif 0 && defined(SYS_sync_file_range) return syscall(SYS_sync_file_range, fd, __SYSCALL_LL_O(pos), __SYSCALL_LL_E(len), flags); #else -- 2.20.1 From 21419914c530c505cb450733b724257be703d9db Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 9 Sep 2012 00:55:31 -0400 Subject: [PATCH 04/16] fix broken mips syscall asm this code was using $10 to save the syscall number, but $10 is not necessarily preserved by the kernel across syscalls. only mattered for syscalls that got interrupted by a signal and restarted. as far as i can tell, $25 is preserved by the kernel across syscalls. --- src/internal/mips/syscall.s | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/internal/mips/syscall.s b/src/internal/mips/syscall.s index 01a5917b..28575408 100644 --- a/src/internal/mips/syscall.s +++ b/src/internal/mips/syscall.s @@ -3,7 +3,7 @@ .global __syscall .type __syscall,@function __syscall: - move $10, $4 + move $25, $4 move $4, $5 move $5, $6 move $6, $7 @@ -13,7 +13,7 @@ __syscall: subu $sp, $sp, 32 sw $8, 16($sp) sw $9, 20($sp) - move $2, $10 + move $2, $25 syscall beq $7, $0, 1f addu $sp, $sp, 32 -- 2.20.1 From be48e22b424b6f858da0151a0b3b68bdb96b41ca Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 9 Sep 2012 00:59:30 -0400 Subject: [PATCH 05/16] fix mips syscall_cp_asm code (saved register usage) --- src/thread/mips/syscall_cp.s | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/thread/mips/syscall_cp.s b/src/thread/mips/syscall_cp.s index 9a796bd6..8dd4c442 100644 --- a/src/thread/mips/syscall_cp.s +++ b/src/thread/mips/syscall_cp.s @@ -7,7 +7,7 @@ __syscall_cp_asm: __cp_begin: lw $4, 0($4) bne $4, $0, 2f - move $10, $5 + move $25, $5 move $4, $6 move $5, $7 lw $6, 16($sp) @@ -17,7 +17,7 @@ __cp_begin: subu $sp, $sp, 32 sw $8, 16($sp) sw $9, 20($sp) - move $2, $10 + move $2, $25 syscall .global __cp_end __cp_end: -- 2.20.1 From 328810d32524e4928fec50b57e37e1bf330b2e40 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 9 Sep 2012 01:01:19 -0400 Subject: [PATCH 06/16] inline syscall support for mips this drastically reduces the size of some functions which are purely syscall wrappers. disabled for clang due to known bugs satisfying register constraints. --- arch/mips/syscall_arch.h | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/arch/mips/syscall_arch.h b/arch/mips/syscall_arch.h index 68e8dce3..f3df2dcd 100644 --- a/arch/mips/syscall_arch.h +++ b/arch/mips/syscall_arch.h @@ -5,6 +5,61 @@ #define __SYSCALL_SSLEN 16 +#ifndef __clang__ + +#define __asm_syscall(...) do { \ + register long r2 __asm__("$2"); \ + register long r7 __asm__("$7"); \ + __asm__ __volatile__ ( \ + "move $2,%2 ; syscall" \ + : "=&r"(r2), "=r"(r7) : __VA_ARGS__ \ + : "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13", \ + "$14", "$15", "$24", "hi", "lo", "memory"); \ + return r7 ? -r2 : r2; \ + } while (0) + +static inline long __syscall0(long n) +{ + register long r25 __asm__("$25") = n; + __asm_syscall("r"(r25)); +} + +static inline long __syscall1(long n, long a) +{ + register long r25 __asm__("$25") = n; + register long r4 __asm__("$4") = a; + __asm_syscall("r"(r25), "r"(r4)); +} + +static inline long __syscall2(long n, long a, long b) +{ + register long r25 __asm__("$25") = n; + register long r4 __asm__("$4") = a; + register long r5 __asm__("$5") = b; + __asm_syscall("r"(r25), "r"(r4), "r"(r5)); +} + +static inline long __syscall3(long n, long a, long b, long c) +{ + register long r25 __asm__("$25") = n; + register long r4 __asm__("$4") = a; + register long r5 __asm__("$5") = b; + register long r6 __asm__("$6") = c; + __asm_syscall("r"(r25), "r"(r4), "r"(r5), "r"(r6)); +} + +static inline long __syscall4(long n, long a, long b, long c, long d) +{ + register long r25 __asm__("$25") = n; + register long r4 __asm__("$4") = a; + register long r5 __asm__("$5") = b; + register long r6 __asm__("$6") = c; + register long r7 __asm__("$7") = d; + __asm_syscall("r"(r25), "r"(r4), "r"(r5), "r"(r6), "r"(r7)); +} + +#else + static inline long __syscall0(long n) { return (__syscall)(n); @@ -30,6 +85,8 @@ static inline long __syscall4(long n, long a, long b, long c, long d) return (__syscall)(n, a, b, c, d); } +#endif + static inline long __syscall5(long n, long a, long b, long c, long d, long e) { return (__syscall)(n, a, b, c, d, e); -- 2.20.1 From 5e3c243d8df6b1504db9c1e6442d47ed38937e02 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 9 Sep 2012 01:29:19 -0400 Subject: [PATCH 07/16] inline syscall support for arm most pure-syscall-wrapper functions compile to the smallest/simplest code possible (save r7 ; load syscall # ; svc 0 ; restore r7 ; tail call to __syscall_ret). --- arch/arm/syscall_arch.h | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/arch/arm/syscall_arch.h b/arch/arm/syscall_arch.h index 48b0e36b..14ca8525 100644 --- a/arch/arm/syscall_arch.h +++ b/arch/arm/syscall_arch.h @@ -5,6 +5,57 @@ #define __SYSCALL_SSLEN 8 +#ifndef __clang__ + +#define __asm_syscall(...) do { \ + __asm__ __volatile__ ( "svc 0" \ + : "=r"(r0) : __VA_ARGS__ : "memory"); \ + return r0; \ + } while (0) + +static inline long __syscall0(long n) +{ + register long r7 __asm__("r7") = n; + register long r0 __asm__("r0"); + __asm_syscall("r"(r7)); +} + +static inline long __syscall1(long n, long a) +{ + register long r7 __asm__("r7") = n; + register long r0 __asm__("r0") = a; + __asm_syscall("r"(r7), "r"(r0)); +} + +static inline long __syscall2(long n, long a, long b) +{ + register long r7 __asm__("r7") = n; + register long r0 __asm__("r0") = a; + register long r1 __asm__("r1") = b; + __asm_syscall("r"(r7), "r"(r0), "r"(r1)); +} + +static inline long __syscall3(long n, long a, long b, long c) +{ + register long r7 __asm__("r7") = n; + register long r0 __asm__("r0") = a; + register long r1 __asm__("r1") = b; + register long r2 __asm__("r2") = c; + __asm_syscall("r"(r7), "r"(r0), "r"(r1), "r"(r2)); +} + +static inline long __syscall4(long n, long a, long b, long c, long d) +{ + register long r7 __asm__("r7") = n; + register long r0 __asm__("r0") = a; + register long r1 __asm__("r1") = b; + register long r2 __asm__("r2") = c; + register long r3 __asm__("r3") = d; + __asm_syscall("r"(r7), "r"(r0), "r"(r1), "r"(r2), "r"(r3)); +} + +#else + static inline long __syscall0(long n) { return (__syscall)(n); @@ -30,6 +81,8 @@ static inline long __syscall4(long n, long a, long b, long c, long d) return (__syscall)(n, a, b, c, d); } +#endif + static inline long __syscall5(long n, long a, long b, long c, long d, long e) { return (__syscall)(n, a, b, c, d, e); -- 2.20.1 From 9a3bbce447403d735282586786dc436ec1ffbad4 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 9 Sep 2012 14:53:06 -0400 Subject: [PATCH 08/16] add 7-arg syscall support for mips no syscalls actually use that many arguments; the issue is that some syscalls with 64-bit arguments have them ordered badly so that breaking them into aligned 32-bit half-arguments wastes slots with padding, and a 7th slot is needed for the last argument. --- src/internal/mips/syscall.s | 7 +++++-- src/internal/syscall.h | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/internal/mips/syscall.s b/src/internal/mips/syscall.s index 28575408..e18a382e 100644 --- a/src/internal/mips/syscall.s +++ b/src/internal/mips/syscall.s @@ -3,17 +3,20 @@ .global __syscall .type __syscall,@function __syscall: - move $25, $4 + move $2, $4 move $4, $5 move $5, $6 move $6, $7 lw $7, 16($sp) lw $8, 20($sp) lw $9, 24($sp) + lw $10,28($sp) subu $sp, $sp, 32 sw $8, 16($sp) sw $9, 20($sp) - move $2, $25 + sw $10,24($sp) + sw $2 ,28($sp) + lw $2, 28($sp) syscall beq $7, $0, 1f addu $sp, $sp, 32 diff --git a/src/internal/syscall.h b/src/internal/syscall.h index ffaf640a..50409ef8 100644 --- a/src/internal/syscall.h +++ b/src/internal/syscall.h @@ -14,9 +14,10 @@ long __syscall_cp(long, long, long, long, long, long, long); #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 __syscall7(n,a,b,c,d,e,f,g) (__syscall)(n,(long)(a),(long)(b),(long)(c),(long)(d),(long)(e),(long)(f),(long)g) -#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_NARGS_X(a,b,c,d,e,f,g,h,n,...) n +#define __SYSCALL_NARGS(...) __SYSCALL_NARGS_X(__VA_ARGS__,7,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__) -- 2.20.1 From 3d939be2e3bcd4bfaf5cba27c9122a77a9c67021 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 9 Sep 2012 14:58:55 -0400 Subject: [PATCH 09/16] reenable sync_file_range; should no longer break on mips --- src/linux/sync_file_range.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/linux/sync_file_range.c b/src/linux/sync_file_range.c index a47dc386..6859abc0 100644 --- a/src/linux/sync_file_range.c +++ b/src/linux/sync_file_range.c @@ -5,10 +5,10 @@ int sync_file_range(int fd, off_t pos, off_t len, unsigned flags) { -#if 0 && defined(SYS_sync_file_range2) +#if defined(SYS_sync_file_range2) return syscall(SYS_sync_file_range2, fd, flags, __SYSCALL_LL_E(pos), __SYSCALL_LL_E(len)); -#elif 0 && defined(SYS_sync_file_range) +#elif defined(SYS_sync_file_range) return syscall(SYS_sync_file_range, fd, __SYSCALL_LL_O(pos), __SYSCALL_LL_E(len), flags); #else -- 2.20.1 From 141138c41b5b1cbb74c61690c9b6dbacce4e1983 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 9 Sep 2012 16:09:29 -0400 Subject: [PATCH 10/16] add linux ppoll syscall wrapper --- include/poll.h | 10 ++++++++++ src/linux/ppoll.c | 9 +++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/linux/ppoll.c diff --git a/include/poll.h b/include/poll.h index 36ef7fee..ace3f3aa 100644 --- a/include/poll.h +++ b/include/poll.h @@ -5,6 +5,8 @@ extern "C" { #endif +#incluce + #define POLLIN 0x001 #define POLLPRI 0x002 #define POLLOUT 0x004 @@ -28,6 +30,14 @@ struct pollfd int poll (struct pollfd *, nfds_t, int); +#ifdef _GNU_SOURCE +#define __NEED_time_t +#define __NEED_struct_timespec +#define __NEED_sigset_t +#include +int ppoll(struct pollfd *, nfds_t, const struct timespec *, const sigset_t *); +#endif + #ifdef __cplusplus } #endif diff --git a/src/linux/ppoll.c b/src/linux/ppoll.c new file mode 100644 index 00000000..8f4aab9b --- /dev/null +++ b/src/linux/ppoll.c @@ -0,0 +1,9 @@ +#define _GNU_SOURCE +#include +#include "syscall.h" + +int ppoll(struct pollfd *fds, nfds_t n, const struct timespec *to, const sigset_t *mask) +{ + struct timespec tmp = *to; + return syscall_cp(SYS_ppoll, fds, n, &tmp, mask); +} -- 2.20.1 From 743546a9339d3da4304fd63f74872e90ac792f63 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 9 Sep 2012 16:27:26 -0400 Subject: [PATCH 11/16] fix typo introduced in poll.h --- include/poll.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/poll.h b/include/poll.h index ace3f3aa..f0e68b2f 100644 --- a/include/poll.h +++ b/include/poll.h @@ -5,7 +5,7 @@ extern "C" { #endif -#incluce +#include #define POLLIN 0x001 #define POLLPRI 0x002 -- 2.20.1 From ea544bfe808ef74c6d1727312069c12dd1c5c150 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 9 Sep 2012 16:29:33 -0400 Subject: [PATCH 12/16] add preadv/pwritev syscall wrappers --- include/sys/uio.h | 9 +++++++++ src/unistd/preadv.c | 13 +++++++++++++ src/unistd/pwritev.c | 13 +++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 src/unistd/preadv.c create mode 100644 src/unistd/pwritev.c diff --git a/include/sys/uio.h b/include/sys/uio.h index 624ff422..60c5c2fe 100644 --- a/include/sys/uio.h +++ b/include/sys/uio.h @@ -11,6 +11,10 @@ extern "C" { #define __NEED_ssize_t #define __NEED_struct_iovec +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) +#define __NEED_off_t +#endif + #ifdef _GNU_SOURCE #define __NEED_pid_t #endif @@ -20,6 +24,11 @@ extern "C" { ssize_t readv (int, const struct iovec *, int); ssize_t writev (int, const struct iovec *, int); +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) +ssize_t preadv (int, const struct iovec *, int, off_t); +ssize_t pwritev (int, const struct iovec *, int, off_t); +#endif + #ifdef _GNU_SOURCE ssize_t process_vm_writev(pid_t, const struct iovec *, unsigned long, const struct iovec *, unsigned long, unsigned long); ssize_t process_vm_readv(pid_t, const struct iovec *, unsigned long, const struct iovec *, unsigned long, unsigned long); diff --git a/src/unistd/preadv.c b/src/unistd/preadv.c new file mode 100644 index 00000000..371e46f8 --- /dev/null +++ b/src/unistd/preadv.c @@ -0,0 +1,13 @@ +#define _GNU_SOURCE +#include +#include +#include "syscall.h" +#include "libc.h" + +ssize_t preadv(int fd, const struct iovec *iov, int count, off_t ofs) +{ + return syscall_cp(SYS_preadv, fd, iov, count, + (long)(ofs), (long)(ofs>>32)); +} + +LFS64(preadv); diff --git a/src/unistd/pwritev.c b/src/unistd/pwritev.c new file mode 100644 index 00000000..1df268d5 --- /dev/null +++ b/src/unistd/pwritev.c @@ -0,0 +1,13 @@ +#define _GNU_SOURCE +#include +#include +#include "syscall.h" +#include "libc.h" + +ssize_t pwritev(int fd, const struct iovec *iov, int count, off_t ofs) +{ + return syscall_cp(SYS_pwritev, fd, iov, count, + (long)(ofs), (long)(ofs>>32)); +} + +LFS64(pwritev); -- 2.20.1 From 2416c63b81f7f79ea781725cf1117c191775c699 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 9 Sep 2012 16:33:47 -0400 Subject: [PATCH 13/16] fix up lfs64 junk for preadv/pwritev --- include/sys/uio.h | 5 +++++ src/unistd/preadv.c | 2 +- src/unistd/pwritev.c | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/sys/uio.h b/include/sys/uio.h index 60c5c2fe..09b6ab9e 100644 --- a/include/sys/uio.h +++ b/include/sys/uio.h @@ -27,6 +27,11 @@ ssize_t writev (int, const struct iovec *, int); #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) ssize_t preadv (int, const struct iovec *, int, off_t); ssize_t pwritev (int, const struct iovec *, int, off_t); +#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) +#define preadv64 preadv +#define pwritev64 pwritev +#define off64_t off_t +#endif #endif #ifdef _GNU_SOURCE diff --git a/src/unistd/preadv.c b/src/unistd/preadv.c index 371e46f8..46d9ece7 100644 --- a/src/unistd/preadv.c +++ b/src/unistd/preadv.c @@ -1,4 +1,4 @@ -#define _GNU_SOURCE +#define _BSD_SOURCE #include #include #include "syscall.h" diff --git a/src/unistd/pwritev.c b/src/unistd/pwritev.c index 1df268d5..aec5d323 100644 --- a/src/unistd/pwritev.c +++ b/src/unistd/pwritev.c @@ -1,4 +1,4 @@ -#define _GNU_SOURCE +#define _BSD_SOURCE #include #include #include "syscall.h" -- 2.20.1 From a660180c6a93681c6efb54fb5826c08d4df60208 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 9 Sep 2012 16:37:19 -0400 Subject: [PATCH 14/16] mincore syscall wrapper --- include/sys/mman.h | 1 + src/mman/mincore.c | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 src/mman/mincore.c diff --git a/include/sys/mman.h b/include/sys/mman.h index 0fa32e6a..136b45b3 100644 --- a/include/sys/mman.h +++ b/include/sys/mman.h @@ -33,6 +33,7 @@ void *mremap (void *, size_t, size_t, int, ...); #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) int madvise (void *, size_t, int); +int mincore (void *, size_t, unsigned char *); #endif int shm_open (const char *, int, mode_t); diff --git a/src/mman/mincore.c b/src/mman/mincore.c new file mode 100644 index 00000000..4bb19f85 --- /dev/null +++ b/src/mman/mincore.c @@ -0,0 +1,8 @@ +#define _GNU_SOURCE +#include +#include "syscall.h" + +int mincore (void *addr, size_t len, unsigned char *vec) +{ + return syscall(SYS_mincore, addr, len, vec); +} -- 2.20.1 From c87584a3e962dabd7b97733bfc3700e003d87d28 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 9 Sep 2012 16:50:20 -0400 Subject: [PATCH 15/16] add setdomainname syscall, fix getdomainname (previously a stub) --- include/unistd.h | 1 + src/misc/getdomainname.c | 10 +++++++++- src/misc/setdomainname.c | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/misc/setdomainname.c diff --git a/include/unistd.h b/include/unistd.h index 4f6953c4..d3bb781a 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -165,6 +165,7 @@ int getpagesize(void); int getdtablesize(void); int sethostname(const char *, size_t); int getdomainname(char *, size_t); +int setdomainname(const char *, size_t); int setgroups(size_t, const gid_t []); char *getpass(const char *); int daemon(int, int); diff --git a/src/misc/getdomainname.c b/src/misc/getdomainname.c index 7eb113d7..59df566d 100644 --- a/src/misc/getdomainname.c +++ b/src/misc/getdomainname.c @@ -1,9 +1,17 @@ +#define _GNU_SOURCE #include #include #include +#include int getdomainname(char *name, size_t len) { - *name = 0; + struct utsname temp; + uname(&temp); + if (!len || strlen(temp.domainname) >= len) { + errno = EINVAL; + return -1; + } + strcpy(name, temp.domainname); return 0; } diff --git a/src/misc/setdomainname.c b/src/misc/setdomainname.c new file mode 100644 index 00000000..22d3f746 --- /dev/null +++ b/src/misc/setdomainname.c @@ -0,0 +1,8 @@ +#define _GNU_SOURCE +#include +#include "syscall.h" + +int setdomainname(const char *name, size_t len) +{ + return syscall(SYS_setdomainname, name, len); +} -- 2.20.1 From 2c1cd2399a237db968a521cdaef3d47a3fb2c2e9 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 10 Sep 2012 15:30:52 -0400 Subject: [PATCH 16/16] add LIBCC (compiler runtime) logic and override to configure this should both fix the issue with ARM needing -lgcc_eh (although that's really a bug in the libgcc build process that's causing considerable bloat, which should be fixed) and make it easier to build musl using clang/llvm in place of gcc. unfortunately I don't know a good way to detect and support pcc's -lpcc since it's not in pcc's default library search path... --- configure | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/configure b/configure index 4e3931c1..93518a7d 100755 --- a/configure +++ b/configure @@ -34,6 +34,7 @@ Some influential environment variables: CC C compiler command [detected] CFLAGS C compiler flags [-Os -pipe ...] CROSS_COMPILE prefix for cross compiler and tools [none] + LIBCC compiler runtime library [detected] Use these variables to override the choices made by configure. @@ -128,6 +129,7 @@ CFLAGS=*) CFLAGS=${arg#*=} ;; CPPFLAGS=*) CPPFLAGS=${arg#*=} ;; LDFLAGS=*) LDFLAGS=${arg#*=} ;; CROSS_COMPILE=*) CROSS_COMPILE=${arg#*=} ;; +LIBCC=*) LIBCC=${arg#*=} ;; *=*) ;; *) target=$arg ;; esac @@ -286,6 +288,10 @@ printf "warning: disabling dynamic linking support\n" shared=no } +# Find compiler runtime library +test -z "$LIBCC" && tryldflag LIBCC -lgcc && tryldflag LIBCC -lgcc_eh +test -z "$LIBCC" && tryldflag LIBCC -lcompiler_rt +printf "using compiler runtime libraries: %s\n" "$LIBCC" printf "creating config.mak... " @@ -309,6 +315,7 @@ CFLAGS_C99FSE = $CFLAGS_C99FSE CPPFLAGS = $CPPFLAGS LDFLAGS = $LDFLAGS_AUTO $LDFLAGS CROSS_COMPILE = $CROSS_COMPILE +LIBCC = $LIBCC EOF test "x$static" = xno && echo "STATIC_LIBS =" test "x$shared" = xno && echo "SHARED_LIBS =" -- 2.20.1