From: Rich Felker Date: Fri, 22 Jan 2016 03:39:07 +0000 (+0000) Subject: move x32 sysinfo impl and syscall fixup code out of arch/x32/src X-Git-Tag: v1.1.13~76 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=66215afc2e09f0153a63d58d3baec25cf0122b7b;p=oweals%2Fmusl.git move x32 sysinfo impl and syscall fixup code out of arch/x32/src all such arch-specific translation units are being moved to appropriate arch dirs under the main src tree. --- diff --git a/arch/x32/src/syscall_cp_fixup.c b/arch/x32/src/syscall_cp_fixup.c deleted file mode 100644 index b1f3a382..00000000 --- a/arch/x32/src/syscall_cp_fixup.c +++ /dev/null @@ -1,38 +0,0 @@ -#include - -__attribute__((__visibility__("hidden"))) -long __syscall_cp_internal(volatile void*, long long, long long, long long, long long, - long long, long long, long long); - -struct __timespec { long long tv_sec; long tv_nsec; }; -struct __timespec_kernel { long long tv_sec; long long tv_nsec; }; -#define __tsc(X) ((struct __timespec*)(unsigned long)(X)) -#define __fixup(X) do { if(X) { \ - ts->tv_sec = __tsc(X)->tv_sec; \ - ts->tv_nsec = __tsc(X)->tv_nsec; \ - (X) = (unsigned long)ts; } } while(0) - -__attribute__((__visibility__("hidden"))) -long __syscall_cp_asm (volatile void * foo, long long n, long long a1, long long a2, long long a3, - long long a4, long long a5, long long a6) -{ - struct __timespec_kernel ts[1]; - switch (n) { - case SYS_mq_timedsend: case SYS_mq_timedreceive: case SYS_pselect6: - __fixup(a5); - break; - case SYS_futex: - if((a2 & (~128 /* FUTEX_PRIVATE_FLAG */)) == 0 /* FUTEX_WAIT */) - __fixup(a4); - break; - case SYS_clock_nanosleep: - case SYS_rt_sigtimedwait: case SYS_ppoll: - __fixup(a3); - break; - case SYS_nanosleep: - __fixup(a1); - break; - } - return __syscall_cp_internal(foo, n, a1, a2, a3, a4, a5, a6); -} - diff --git a/arch/x32/src/sysinfo.c b/arch/x32/src/sysinfo.c deleted file mode 100644 index d1c1b148..00000000 --- a/arch/x32/src/sysinfo.c +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -#define klong long long -#define kulong unsigned long long - -struct kernel_sysinfo { - klong uptime; - kulong loads[3]; - kulong totalram; - kulong freeram; - kulong sharedram; - kulong bufferram; - kulong totalswap; - kulong freeswap; - short procs; - short pad; - kulong totalhigh; - kulong freehigh; - unsigned mem_unit; -}; - -int __lsysinfo(struct sysinfo *info) -{ - struct kernel_sysinfo tmp; - int ret = syscall(SYS_sysinfo, &tmp); - if(ret == -1) return ret; - info->uptime = tmp.uptime; - info->loads[0] = tmp.loads[0]; - info->loads[1] = tmp.loads[1]; - info->loads[2] = tmp.loads[2]; - kulong shifts; - kulong max = tmp.totalram | tmp.totalswap; - __asm__("bsr %1,%0" : "=r"(shifts) : "r"(max)); - shifts = shifts >= 32 ? shifts - 31 : 0; - info->totalram = tmp.totalram >> shifts; - info->freeram = tmp.freeram >> shifts; - info->sharedram = tmp.sharedram >> shifts; - info->bufferram = tmp.bufferram >> shifts; - info->totalswap = tmp.totalswap >> shifts; - info->freeswap = tmp.freeswap >> shifts; - info->procs = tmp.procs ; - info->totalhigh = tmp.totalhigh >> shifts; - info->freehigh = tmp.freehigh >> shifts; - info->mem_unit = (tmp.mem_unit ? tmp.mem_unit : 1) << shifts; - return ret; -} - -weak_alias(__lsysinfo, sysinfo); diff --git a/src/linux/x32/sysinfo.c b/src/linux/x32/sysinfo.c new file mode 100644 index 00000000..d1c1b148 --- /dev/null +++ b/src/linux/x32/sysinfo.c @@ -0,0 +1,50 @@ +#include +#include "syscall.h" +#include "libc.h" + +#define klong long long +#define kulong unsigned long long + +struct kernel_sysinfo { + klong uptime; + kulong loads[3]; + kulong totalram; + kulong freeram; + kulong sharedram; + kulong bufferram; + kulong totalswap; + kulong freeswap; + short procs; + short pad; + kulong totalhigh; + kulong freehigh; + unsigned mem_unit; +}; + +int __lsysinfo(struct sysinfo *info) +{ + struct kernel_sysinfo tmp; + int ret = syscall(SYS_sysinfo, &tmp); + if(ret == -1) return ret; + info->uptime = tmp.uptime; + info->loads[0] = tmp.loads[0]; + info->loads[1] = tmp.loads[1]; + info->loads[2] = tmp.loads[2]; + kulong shifts; + kulong max = tmp.totalram | tmp.totalswap; + __asm__("bsr %1,%0" : "=r"(shifts) : "r"(max)); + shifts = shifts >= 32 ? shifts - 31 : 0; + info->totalram = tmp.totalram >> shifts; + info->freeram = tmp.freeram >> shifts; + info->sharedram = tmp.sharedram >> shifts; + info->bufferram = tmp.bufferram >> shifts; + info->totalswap = tmp.totalswap >> shifts; + info->freeswap = tmp.freeswap >> shifts; + info->procs = tmp.procs ; + info->totalhigh = tmp.totalhigh >> shifts; + info->freehigh = tmp.freehigh >> shifts; + info->mem_unit = (tmp.mem_unit ? tmp.mem_unit : 1) << shifts; + return ret; +} + +weak_alias(__lsysinfo, sysinfo); diff --git a/src/linux/x32/sysinfo.s b/src/linux/x32/sysinfo.s deleted file mode 100644 index 53d79db2..00000000 --- a/src/linux/x32/sysinfo.s +++ /dev/null @@ -1 +0,0 @@ -# see arch/x32/src/sysinfo.c diff --git a/src/thread/x32/syscall_cp_fixup.c b/src/thread/x32/syscall_cp_fixup.c new file mode 100644 index 00000000..b1f3a382 --- /dev/null +++ b/src/thread/x32/syscall_cp_fixup.c @@ -0,0 +1,38 @@ +#include + +__attribute__((__visibility__("hidden"))) +long __syscall_cp_internal(volatile void*, long long, long long, long long, long long, + long long, long long, long long); + +struct __timespec { long long tv_sec; long tv_nsec; }; +struct __timespec_kernel { long long tv_sec; long long tv_nsec; }; +#define __tsc(X) ((struct __timespec*)(unsigned long)(X)) +#define __fixup(X) do { if(X) { \ + ts->tv_sec = __tsc(X)->tv_sec; \ + ts->tv_nsec = __tsc(X)->tv_nsec; \ + (X) = (unsigned long)ts; } } while(0) + +__attribute__((__visibility__("hidden"))) +long __syscall_cp_asm (volatile void * foo, long long n, long long a1, long long a2, long long a3, + long long a4, long long a5, long long a6) +{ + struct __timespec_kernel ts[1]; + switch (n) { + case SYS_mq_timedsend: case SYS_mq_timedreceive: case SYS_pselect6: + __fixup(a5); + break; + case SYS_futex: + if((a2 & (~128 /* FUTEX_PRIVATE_FLAG */)) == 0 /* FUTEX_WAIT */) + __fixup(a4); + break; + case SYS_clock_nanosleep: + case SYS_rt_sigtimedwait: case SYS_ppoll: + __fixup(a3); + break; + case SYS_nanosleep: + __fixup(a1); + break; + } + return __syscall_cp_internal(foo, n, a1, a2, a3, a4, a5, a6); +} +