From f990e317cf3fb0f2db57687fa5e66aad46b1b93a Mon Sep 17 00:00:00 2001 From: localcc Date: Sun, 22 Jun 2025 17:50:43 +0200 Subject: [PATCH 1/3] chore: formatting pass --- abis/linux/ipc.h | 4 +- abis/linux/shm.h | 7 +- abis/linux/signal.h | 157 +- abis/linux/stat.h | 20 +- options/ansi/include/bits/ansi/fenv.h | 23 +- .../ansi/musl-generic-math/__fpclassifyl.c | 13 +- options/ansi/musl-generic-math/exp10l.c | 27 +- options/ansi/musl-generic-math/expl.c | 37 +- options/ansi/musl-generic-math/fabsl.c | 8 +- options/ansi/musl-generic-math/ilogbl.c | 30 +- options/ansi/musl-generic-math/lgammal.c | 292 +- options/ansi/musl-generic-math/libm.h | 186 +- options/ansi/musl-generic-math/nextafterl.c | 15 +- options/ansi/musl-generic-math/remquol.c | 42 +- options/ansi/musl-generic-math/rintl.c | 14 +- options/ansi/musl-generic-math/roundl.c | 16 +- options/ansi/musl-generic-math/scalbnl.c | 8 +- options/elf/include/elf.h | 374 ++- options/elf/include/link.h | 18 +- options/internal/include/bits/machine.h | 15 +- options/internal/include/bits/types.h | 123 +- options/internal/include/mlibc/tcb.hpp | 79 +- options/rtld/generic/linker.cpp | 1838 ++++++------ options/rtld/generic/main.cpp | 662 +++-- options/rtld/include/mlibc/rtld-abi.hpp | 3 +- sysdeps/linux/generic/sysdeps.cpp | 569 ++-- sysdeps/linux/include/bits/syscall_aliases.h | 2468 ++++++++--------- tests/posix/pthread_attr.c | 61 +- tests/posix/sigaltstack.c | 34 +- 29 files changed, 3665 insertions(+), 3478 deletions(-) diff --git a/abis/linux/ipc.h b/abis/linux/ipc.h index b5f9f110e0..63b950c483 100644 --- a/abis/linux/ipc.h +++ b/abis/linux/ipc.h @@ -1,9 +1,9 @@ #ifndef _ABIBITS_IPC_H #define _ABIBITS_IPC_H -#include #include #include +#include #ifdef __cplusplus extern "C" { @@ -18,7 +18,7 @@ extern "C" { #define IPC_STAT 2 #define IPC_INFO 3 -#define IPC_PRIVATE ((key_t) 0) +#define IPC_PRIVATE ((key_t)0) #if defined(__aarch64__) || defined(__i386__) || defined(__m68k__) #define IPC_64 0x100 diff --git a/abis/linux/shm.h b/abis/linux/shm.h index ad137bccce..ec1ae06b8f 100644 --- a/abis/linux/shm.h +++ b/abis/linux/shm.h @@ -5,11 +5,11 @@ extern "C" { #endif -#include #include +#include -#include #include +#include #define SHM_R 0400 #define SHM_W 0200 @@ -64,7 +64,8 @@ struct shmid_ds { time_t shm_dtime; time_t shm_ctime; }; -#elif defined(__x86_64__) || defined(__aarch64__) || (defined(__riscv) && __riscv_xlen == 64) || defined(__loongarch64) +#elif defined(__x86_64__) || defined(__aarch64__) || (defined(__riscv) && __riscv_xlen == 64) \ + || defined(__loongarch64) struct shmid_ds { struct ipc_perm shm_perm; size_t shm_segsz; diff --git a/abis/linux/signal.h b/abis/linux/signal.h index a8dc59f66f..1377b90946 100644 --- a/abis/linux/signal.h +++ b/abis/linux/signal.h @@ -1,12 +1,12 @@ #ifndef _ABIBITS_SIGNAL_H #define _ABIBITS_SIGNAL_H -#include -#include -#include #include +#include #include #include +#include +#include #define POLL_IN 1 #define POLL_OUT 2 @@ -20,7 +20,7 @@ typedef struct { int si_signo, si_errno, si_code; union { - char __pad[128 - 2*sizeof(int) - sizeof(long)]; + char __pad[128 - 2 * sizeof(int) - sizeof(long)]; struct { union { struct { @@ -62,26 +62,26 @@ typedef struct { } __sigsys; } __si_fields; } siginfo_t; -#define si_pid __si_fields.__si_common.__first.__piduid.si_pid -#define si_uid __si_fields.__si_common.__first.__piduid.si_uid -#define si_status __si_fields.__si_common.__second.__sigchld.si_status -#define si_utime __si_fields.__si_common.__second.__sigchld.si_utime -#define si_stime __si_fields.__si_common.__second.__sigchld.si_stime -#define si_value __si_fields.__si_common.__second.si_value -#define si_addr __si_fields.__sigfault.si_addr +#define si_pid __si_fields.__si_common.__first.__piduid.si_pid +#define si_uid __si_fields.__si_common.__first.__piduid.si_uid +#define si_status __si_fields.__si_common.__second.__sigchld.si_status +#define si_utime __si_fields.__si_common.__second.__sigchld.si_utime +#define si_stime __si_fields.__si_common.__second.__sigchld.si_stime +#define si_value __si_fields.__si_common.__second.si_value +#define si_addr __si_fields.__sigfault.si_addr #define si_addr_lsb __si_fields.__sigfault.si_addr_lsb -#define si_lower __si_fields.__sigfault.__first.__addr_bnd.si_lower -#define si_upper __si_fields.__sigfault.__first.__addr_bnd.si_upper -#define si_pkey __si_fields.__sigfault.__first.si_pkey -#define si_band __si_fields.__sigpoll.si_band -#define si_fd __si_fields.__sigpoll.si_fd +#define si_lower __si_fields.__sigfault.__first.__addr_bnd.si_lower +#define si_upper __si_fields.__sigfault.__first.__addr_bnd.si_upper +#define si_pkey __si_fields.__sigfault.__first.si_pkey +#define si_band __si_fields.__sigpoll.si_band +#define si_fd __si_fields.__sigpoll.si_fd #define si_timerid __si_fields.__si_common.__first.__timer.si_timerid #define si_overrun __si_fields.__si_common.__first.__timer.si_overrun -#define si_ptr si_value.sival_ptr -#define si_int si_value.sival_int +#define si_ptr si_value.sival_ptr +#define si_int si_value.sival_int #define si_call_addr __si_fields.__sigsys.si_call_addr #define si_syscall __si_fields.__sigsys.si_syscall -#define si_arch __si_fields.__sigsys.si_arch +#define si_arch __si_fields.__sigsys.si_arch /* Required for sys_sigaction sysdep. */ #define SA_NOCLDSTOP 1 @@ -98,7 +98,7 @@ extern "C" { #endif /* Argument for signal() */ -typedef void (*__sighandler) (int); +typedef void (*__sighandler)(int); #define SIG_ERR ((__sighandler)(void *)(-1)) #define SIG_DFL ((__sighandler)(void *)(0)) @@ -125,30 +125,30 @@ typedef struct { #define SIG_UNBLOCK 1 #define SIG_SETMASK 2 -#define SIGHUP 1 -#define SIGQUIT 3 -#define SIGTRAP 5 -#define SIGIOT SIGABRT -#define SIGBUS 7 -#define SIGKILL 9 -#define SIGUSR1 10 -#define SIGUSR2 12 -#define SIGPIPE 13 -#define SIGALRM 14 +#define SIGHUP 1 +#define SIGQUIT 3 +#define SIGTRAP 5 +#define SIGIOT SIGABRT +#define SIGBUS 7 +#define SIGKILL 9 +#define SIGUSR1 10 +#define SIGUSR2 12 +#define SIGPIPE 13 +#define SIGALRM 14 #define SIGSTKFLT 16 -#define SIGCHLD 17 -#define SIGCONT 18 -#define SIGSTOP 19 -#define SIGTSTP 20 -#define SIGTTIN 21 -#define SIGTTOU 22 -#define SIGURG 23 -#define SIGXCPU 24 -#define SIGXFSZ 25 +#define SIGCHLD 17 +#define SIGCONT 18 +#define SIGSTOP 19 +#define SIGTSTP 20 +#define SIGTTIN 21 +#define SIGTTOU 22 +#define SIGURG 23 +#define SIGXCPU 24 +#define SIGXFSZ 25 #define SIGVTALRM 26 -#define SIGWINCH 28 -#define SIGPOLL 29 -#define SIGSYS 31 +#define SIGWINCH 28 +#define SIGPOLL 29 +#define SIGSYS 31 #define SIGUNUSED SIGSYS #define SIGCANCEL 32 @@ -359,17 +359,17 @@ typedef struct __ucontext { #define NGREG 32 enum { - REG_PC = 0, + REG_PC = 0, #define REG_PC REG_PC - REG_RA = 1, + REG_RA = 1, #define REG_RA REG_RA - REG_SP = 2, + REG_SP = 2, #define REG_SP REG_SP - REG_TP = 4, + REG_TP = 4, #define REG_TP REG_TP - REG_S0 = 8, + REG_S0 = 8, #define REG_S0 REG_S0 - REG_A0 = 10 + REG_A0 = 10 #define REG_A0 REG_A0 }; @@ -404,7 +404,7 @@ typedef struct sigcontext { typedef struct __ucontext { unsigned long uc_flags; - struct ucontext *uc_link; + struct ucontext *uc_link; stack_t uc_stack; sigset_t uc_sigmask; #pragma GCC diagnostic push @@ -414,7 +414,7 @@ typedef struct __ucontext { mcontext_t uc_mcontext; } ucontext_t; -#elif defined (__aarch64__) +#elif defined(__aarch64__) #define NGREG 34 @@ -456,38 +456,29 @@ struct sve_context { uint16_t vl; uint16_t __reserved[3]; }; -#define SVE_VQ_BYTES 16 -#define SVE_VQ_MIN 1 -#define SVE_VQ_MAX 512 -#define SVE_VL_MIN (SVE_VQ_MIN * SVE_VQ_BYTES) -#define SVE_VL_MAX (SVE_VQ_MAX * SVE_VQ_BYTES) -#define SVE_NUM_ZREGS 32 -#define SVE_NUM_PREGS 16 -#define sve_vl_valid(vl) \ - ((vl) % SVE_VQ_BYTES == 0 && (vl) >= SVE_VL_MIN && (vl) <= SVE_VL_MAX) -#define sve_vq_from_vl(vl) ((vl) / SVE_VQ_BYTES) -#define sve_vl_from_vq(vq) ((vq) * SVE_VQ_BYTES) -#define SVE_SIG_ZREG_SIZE(vq) ((unsigned)(vq) * SVE_VQ_BYTES) -#define SVE_SIG_PREG_SIZE(vq) ((unsigned)(vq) * (SVE_VQ_BYTES / 8)) -#define SVE_SIG_FFR_SIZE(vq) SVE_SIG_PREG_SIZE(vq) -#define SVE_SIG_REGS_OFFSET \ - ((sizeof(struct sve_context) + (SVE_VQ_BYTES - 1)) \ - / SVE_VQ_BYTES * SVE_VQ_BYTES) -#define SVE_SIG_ZREGS_OFFSET SVE_SIG_REGS_OFFSET -#define SVE_SIG_ZREG_OFFSET(vq, n) \ - (SVE_SIG_ZREGS_OFFSET + SVE_SIG_ZREG_SIZE(vq) * (n)) -#define SVE_SIG_ZREGS_SIZE(vq) \ - (SVE_SIG_ZREG_OFFSET(vq, SVE_NUM_ZREGS) - SVE_SIG_ZREGS_OFFSET) -#define SVE_SIG_PREGS_OFFSET(vq) \ - (SVE_SIG_ZREGS_OFFSET + SVE_SIG_ZREGS_SIZE(vq)) -#define SVE_SIG_PREG_OFFSET(vq, n) \ - (SVE_SIG_PREGS_OFFSET(vq) + SVE_SIG_PREG_SIZE(vq) * (n)) -#define SVE_SIG_PREGS_SIZE(vq) \ - (SVE_SIG_PREG_OFFSET(vq, SVE_NUM_PREGS) - SVE_SIG_PREGS_OFFSET(vq)) -#define SVE_SIG_FFR_OFFSET(vq) \ - (SVE_SIG_PREGS_OFFSET(vq) + SVE_SIG_PREGS_SIZE(vq)) -#define SVE_SIG_REGS_SIZE(vq) \ - (SVE_SIG_FFR_OFFSET(vq) + SVE_SIG_FFR_SIZE(vq) - SVE_SIG_REGS_OFFSET) +#define SVE_VQ_BYTES 16 +#define SVE_VQ_MIN 1 +#define SVE_VQ_MAX 512 +#define SVE_VL_MIN (SVE_VQ_MIN * SVE_VQ_BYTES) +#define SVE_VL_MAX (SVE_VQ_MAX * SVE_VQ_BYTES) +#define SVE_NUM_ZREGS 32 +#define SVE_NUM_PREGS 16 +#define sve_vl_valid(vl) ((vl) % SVE_VQ_BYTES == 0 && (vl) >= SVE_VL_MIN && (vl) <= SVE_VL_MAX) +#define sve_vq_from_vl(vl) ((vl) / SVE_VQ_BYTES) +#define sve_vl_from_vq(vq) ((vq) * SVE_VQ_BYTES) +#define SVE_SIG_ZREG_SIZE(vq) ((unsigned)(vq) * SVE_VQ_BYTES) +#define SVE_SIG_PREG_SIZE(vq) ((unsigned)(vq) * (SVE_VQ_BYTES / 8)) +#define SVE_SIG_FFR_SIZE(vq) SVE_SIG_PREG_SIZE(vq) +#define SVE_SIG_REGS_OFFSET \ + ((sizeof(struct sve_context) + (SVE_VQ_BYTES - 1)) / SVE_VQ_BYTES * SVE_VQ_BYTES) +#define SVE_SIG_ZREGS_OFFSET SVE_SIG_REGS_OFFSET +#define SVE_SIG_ZREG_OFFSET(vq, n) (SVE_SIG_ZREGS_OFFSET + SVE_SIG_ZREG_SIZE(vq) * (n)) +#define SVE_SIG_ZREGS_SIZE(vq) (SVE_SIG_ZREG_OFFSET(vq, SVE_NUM_ZREGS) - SVE_SIG_ZREGS_OFFSET) +#define SVE_SIG_PREGS_OFFSET(vq) (SVE_SIG_ZREGS_OFFSET + SVE_SIG_ZREGS_SIZE(vq)) +#define SVE_SIG_PREG_OFFSET(vq, n) (SVE_SIG_PREGS_OFFSET(vq) + SVE_SIG_PREG_SIZE(vq) * (n)) +#define SVE_SIG_PREGS_SIZE(vq) (SVE_SIG_PREG_OFFSET(vq, SVE_NUM_PREGS) - SVE_SIG_PREGS_OFFSET(vq)) +#define SVE_SIG_FFR_OFFSET(vq) (SVE_SIG_PREGS_OFFSET(vq) + SVE_SIG_PREGS_SIZE(vq)) +#define SVE_SIG_REGS_SIZE(vq) (SVE_SIG_FFR_OFFSET(vq) + SVE_SIG_FFR_SIZE(vq) - SVE_SIG_REGS_OFFSET) #define SVE_SIG_CONTEXT_SIZE(vq) (SVE_SIG_REGS_OFFSET + SVE_SIG_REGS_SIZE(vq)) typedef struct __ucontext { @@ -498,7 +489,7 @@ typedef struct __ucontext { mcontext_t uc_mcontext; } ucontext_t; -#elif defined (__m68k__) +#elif defined(__m68k__) /* taken from musl */ diff --git a/abis/linux/stat.h b/abis/linux/stat.h index 57992c5d76..3231e71e76 100644 --- a/abis/linux/stat.h +++ b/abis/linux/stat.h @@ -1,17 +1,17 @@ #ifndef _ABIBITS_STAT_H #define _ABIBITS_STAT_H -#include -#include -#include -#include +#include +#include #include +#include #include -#include -#include +#include #include +#include #include #include +#include #define S_IFMT 0x0F000 #define S_IFBLK 0x06000 @@ -38,9 +38,9 @@ #define S_ISGID 02000 #define S_ISVTX 01000 -#define S_IREAD S_IRUSR +#define S_IREAD S_IRUSR #define S_IWRITE S_IWUSR -#define S_IEXEC S_IXUSR +#define S_IEXEC S_IXUSR #ifdef __cplusplus extern "C" { @@ -66,7 +66,7 @@ struct stat { long __unused[3]; }; -#elif (defined(__riscv) && __riscv_xlen == 64) || defined (__aarch64__) || defined(__loongarch64) +#elif (defined(__riscv) && __riscv_xlen == 64) || defined(__aarch64__) || defined(__loongarch64) struct stat { dev_t st_dev; @@ -116,7 +116,7 @@ struct stat { struct timespec st_mtim; struct timespec st_ctim; }; -#elif defined (__m68k__) +#elif defined(__m68k__) struct stat { dev_t st_dev; diff --git a/options/ansi/include/bits/ansi/fenv.h b/options/ansi/include/bits/ansi/fenv.h index 326f8c0f1e..74b58f666a 100644 --- a/options/ansi/include/bits/ansi/fenv.h +++ b/options/ansi/include/bits/ansi/fenv.h @@ -10,7 +10,8 @@ #define FE_OVERFLOW 8 #define FE_UNDERFLOW 16 -#define FE_ALL_EXCEPT (FE_DENORMAL | FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) +#define FE_ALL_EXCEPT \ + (FE_DENORMAL | FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) #define FE_TONEAREST 0 #define FE_DOWNWARD 0x400 @@ -47,27 +48,27 @@ #define FE_DOWNWARD 2 #define FE_UPWARD 3 -#elif defined (__m68k__) +#elif defined(__m68k__) #if __HAVE_68881__ || __mcffpu__ || __HAVE_FPU_ -#define FE_INEXACT 8 -#define FE_DIVBYZERO 16 -#define FE_UNDERFLOW 32 -#define FE_OVERFLOW 64 -#define FE_INVALID 128 +#define FE_INEXACT 8 +#define FE_DIVBYZERO 16 +#define FE_UNDERFLOW 32 +#define FE_OVERFLOW 64 +#define FE_INVALID 128 #define FE_ALL_EXCEPT 0xf8 -#define FE_TONEAREST 0 +#define FE_TONEAREST 0 #define FE_TOWARDZERO 16 -#define FE_DOWNWARD 32 -#define FE_UPWARD 48 +#define FE_DOWNWARD 32 +#define FE_UPWARD 48 #else #define FE_ALL_EXCEPT 0 -#define FE_TONEAREST 0 +#define FE_TONEAREST 0 #endif diff --git a/options/ansi/musl-generic-math/__fpclassifyl.c b/options/ansi/musl-generic-math/__fpclassifyl.c index fb62dd9fc4..663100a973 100644 --- a/options/ansi/musl-generic-math/__fpclassifyl.c +++ b/options/ansi/musl-generic-math/__fpclassifyl.c @@ -1,16 +1,12 @@ #include "libm.h" #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -int __fpclassifyl(long double x) -{ - return __fpclassify(x); -} +int __fpclassifyl(long double x) { return __fpclassify(x); } #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -int __fpclassifyl(long double x) -{ +int __fpclassifyl(long double x) { union ldshape u = {x}; int e = u.i.se & 0x7fff; - int msb = u.i.m>>63; + int msb = u.i.m >> 63; if (!e && !msb) return u.i.m ? FP_SUBNORMAL : FP_ZERO; if (e == 0x7fff) { @@ -28,8 +24,7 @@ int __fpclassifyl(long double x) return FP_NORMAL; } #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -int __fpclassifyl(long double x) -{ +int __fpclassifyl(long double x) { union ldshape u = {x}; int e = u.i.se & 0x7fff; u.i.se = 0; diff --git a/options/ansi/musl-generic-math/exp10l.c b/options/ansi/musl-generic-math/exp10l.c index f18e554d76..96d1796570 100644 --- a/options/ansi/musl-generic-math/exp10l.c +++ b/options/ansi/musl-generic-math/exp10l.c @@ -1,31 +1,26 @@ #define _GNU_SOURCE #include #include -//#include "libc.h" +// #include "libc.h" #include "libm.h" #include "weak_alias.h" #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double exp10l(long double x) -{ - return exp10(x); -} +long double exp10l(long double x) { return exp10(x); } #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -long double exp10l(long double x) -{ - static const long double p10[] = { - 1e-15L, 1e-14L, 1e-13L, 1e-12L, 1e-11L, 1e-10L, - 1e-9L, 1e-8L, 1e-7L, 1e-6L, 1e-5L, 1e-4L, 1e-3L, 1e-2L, 1e-1L, - 1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, - 1e10, 1e11, 1e12, 1e13, 1e14, 1e15 - }; +long double exp10l(long double x) { + static const long double p10[] = {1e-15L, 1e-14L, 1e-13L, 1e-12L, 1e-11L, 1e-10L, 1e-9L, 1e-8L, + 1e-7L, 1e-6L, 1e-5L, 1e-4L, 1e-3L, 1e-2L, 1e-1L, 1, + 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, + 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15}; long double n, y = modfl(x, &n); union ldshape u = {n}; /* fabsl(n) < 16 without raising invalid on nan */ - if ((u.i.se & 0x7fff) < 0x3fff+4) { - if (!y) return p10[(int)n+15]; + if ((u.i.se & 0x7fff) < 0x3fff + 4) { + if (!y) + return p10[(int)n + 15]; y = exp2l(3.32192809488736234787031942948939L * y); - return y * p10[(int)n+15]; + return y * p10[(int)n + 15]; } return powl(10.0, x); } diff --git a/options/ansi/musl-generic-math/expl.c b/options/ansi/musl-generic-math/expl.c index 0a7f44f685..69cd97fca2 100644 --- a/options/ansi/musl-generic-math/expl.c +++ b/options/ansi/musl-generic-math/expl.c @@ -68,30 +68,24 @@ #include "libm.h" #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double expl(long double x) -{ - return exp(x); -} +long double expl(long double x) { return exp(x); } #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 static const long double P[3] = { - 1.2617719307481059087798E-4L, - 3.0299440770744196129956E-2L, - 9.9999999999999999991025E-1L, + 1.2617719307481059087798E-4L, + 3.0299440770744196129956E-2L, + 9.9999999999999999991025E-1L, }; static const long double Q[4] = { - 3.0019850513866445504159E-6L, - 2.5244834034968410419224E-3L, - 2.2726554820815502876593E-1L, - 2.0000000000000000000897E0L, + 3.0019850513866445504159E-6L, + 2.5244834034968410419224E-3L, + 2.2726554820815502876593E-1L, + 2.0000000000000000000897E0L, }; -static const long double -LN2HI = 6.9314575195312500000000E-1L, -LN2LO = 1.4286068203094172321215E-6L, -LOG2E = 1.4426950408889634073599E0L; +static const long double LN2HI = 6.9314575195312500000000E-1L, LN2LO = 1.4286068203094172321215E-6L, + LOG2E = 1.4426950408889634073599E0L; -long double expl(long double x) -{ +long double expl(long double x) { long double px, xx; int k; @@ -100,7 +94,7 @@ long double expl(long double x) if (x > 11356.5234062941439488L) /* x > ln(2^16384 - 0.5) */ return x * 0x1p16383L; if (x < -11399.4985314888605581L) /* x < ln(2^-16446) */ - return -0x1p-16445L/x; + return -0x1p-16445L / x; /* Express e**x = e**f 2**k * = e**(f + k ln(2)) @@ -115,14 +109,11 @@ long double expl(long double x) */ xx = x * x; px = x * __polevll(xx, P, 2); - x = px/(__polevll(xx, Q, 3) - px); + x = px / (__polevll(xx, Q, 3) - px); x = 1.0 + 2.0 * x; return scalbnl(x, k); } #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 // TODO: broken implementation to make things compile -long double expl(long double x) -{ - return exp(x); -} +long double expl(long double x) { return exp(x); } #endif diff --git a/options/ansi/musl-generic-math/fabsl.c b/options/ansi/musl-generic-math/fabsl.c index c4f36ec281..74c8a4a844 100644 --- a/options/ansi/musl-generic-math/fabsl.c +++ b/options/ansi/musl-generic-math/fabsl.c @@ -1,12 +1,8 @@ #include "libm.h" #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double fabsl(long double x) -{ - return fabs(x); -} +long double fabsl(long double x) { return fabs(x); } #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -long double fabsl(long double x) -{ +long double fabsl(long double x) { union ldshape u = {x}; u.i.se &= 0x7fff; diff --git a/options/ansi/musl-generic-math/ilogbl.c b/options/ansi/musl-generic-math/ilogbl.c index 7b1a9cf8d0..84f6b551ba 100644 --- a/options/ansi/musl-generic-math/ilogbl.c +++ b/options/ansi/musl-generic-math/ilogbl.c @@ -1,44 +1,40 @@ -#include #include "libm.h" +#include #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -int ilogbl(long double x) -{ - return ilogb(x); -} +int ilogbl(long double x) { return ilogb(x); } #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -int ilogbl(long double x) -{ - #pragma STDC FENV_ACCESS ON +int ilogbl(long double x) { +#pragma STDC FENV_ACCESS ON union ldshape u = {x}; uint64_t m = u.i.m; int e = u.i.se & 0x7fff; if (!e) { if (m == 0) { - FORCE_EVAL(0/0.0f); + FORCE_EVAL(0 / 0.0f); return FP_ILOGB0; } /* subnormal x */ - for (e = -0x3fff+1; m>>63 == 0; e--, m<<=1); + for (e = -0x3fff + 1; m >> 63 == 0; e--, m <<= 1) + ; return e; } if (e == 0x7fff) { - FORCE_EVAL(0/0.0f); - return m<<1 ? FP_ILOGBNAN : INT_MAX; + FORCE_EVAL(0 / 0.0f); + return m << 1 ? FP_ILOGBNAN : INT_MAX; } return e - 0x3fff; } #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -int ilogbl(long double x) -{ - #pragma STDC FENV_ACCESS ON +int ilogbl(long double x) { +#pragma STDC FENV_ACCESS ON union ldshape u = {x}; int e = u.i.se & 0x7fff; if (!e) { if (x == 0) { - FORCE_EVAL(0/0.0f); + FORCE_EVAL(0 / 0.0f); return FP_ILOGB0; } /* subnormal x */ @@ -46,7 +42,7 @@ int ilogbl(long double x) return ilogbl(x) - 120; } if (e == 0x7fff) { - FORCE_EVAL(0/0.0f); + FORCE_EVAL(0 / 0.0f); u.i.se = 0; return u.f ? FP_ILOGBNAN : INT_MAX; } diff --git a/options/ansi/musl-generic-math/lgammal.c b/options/ansi/musl-generic-math/lgammal.c index f0bea364e5..ceaa653f04 100644 --- a/options/ansi/musl-generic-math/lgammal.c +++ b/options/ansi/musl-generic-math/lgammal.c @@ -88,146 +88,138 @@ #define _GNU_SOURCE #include "libm.h" #include "weak_alias.h" -//#include "libc.h" +// #include "libc.h" #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 double __lgamma_r(double x, int *sg); -long double __lgammal_r(long double x, int *sg) -{ - return __lgamma_r(x, sg); -} +long double __lgammal_r(long double x, int *sg) { return __lgamma_r(x, sg); } #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 static const long double -pi = 3.14159265358979323846264L, - -/* lgam(1+x) = 0.5 x + x a(x)/b(x) - -0.268402099609375 <= x <= 0 - peak relative error 6.6e-22 */ -a0 = -6.343246574721079391729402781192128239938E2L, -a1 = 1.856560238672465796768677717168371401378E3L, -a2 = 2.404733102163746263689288466865843408429E3L, -a3 = 8.804188795790383497379532868917517596322E2L, -a4 = 1.135361354097447729740103745999661157426E2L, -a5 = 3.766956539107615557608581581190400021285E0L, - -b0 = 8.214973713960928795704317259806842490498E3L, -b1 = 1.026343508841367384879065363925870888012E4L, -b2 = 4.553337477045763320522762343132210919277E3L, -b3 = 8.506975785032585797446253359230031874803E2L, -b4 = 6.042447899703295436820744186992189445813E1L, -/* b5 = 1.000000000000000000000000000000000000000E0 */ - + pi = 3.14159265358979323846264L, -tc = 1.4616321449683623412626595423257213284682E0L, -tf = -1.2148629053584961146050602565082954242826E-1, /* double precision */ -/* tt = (tail of tf), i.e. tf + tt has extended precision. */ -tt = 3.3649914684731379602768989080467587736363E-18L, -/* lgam ( 1.4616321449683623412626595423257213284682E0 ) = --1.2148629053584960809551455717769158215135617312999903886372437313313530E-1 */ + /* lgam(1+x) = 0.5 x + x a(x)/b(x) + -0.268402099609375 <= x <= 0 + peak relative error 6.6e-22 */ + a0 = -6.343246574721079391729402781192128239938E2L, + a1 = 1.856560238672465796768677717168371401378E3L, + a2 = 2.404733102163746263689288466865843408429E3L, + a3 = 8.804188795790383497379532868917517596322E2L, + a4 = 1.135361354097447729740103745999661157426E2L, + a5 = 3.766956539107615557608581581190400021285E0L, -/* lgam (x + tc) = tf + tt + x g(x)/h(x) - -0.230003726999612341262659542325721328468 <= x - <= 0.2699962730003876587373404576742786715318 - peak relative error 2.1e-21 */ -g0 = 3.645529916721223331888305293534095553827E-18L, -g1 = 5.126654642791082497002594216163574795690E3L, -g2 = 8.828603575854624811911631336122070070327E3L, -g3 = 5.464186426932117031234820886525701595203E3L, -g4 = 1.455427403530884193180776558102868592293E3L, -g5 = 1.541735456969245924860307497029155838446E2L, -g6 = 4.335498275274822298341872707453445815118E0L, + b0 = 8.214973713960928795704317259806842490498E3L, + b1 = 1.026343508841367384879065363925870888012E4L, + b2 = 4.553337477045763320522762343132210919277E3L, + b3 = 8.506975785032585797446253359230031874803E2L, + b4 = 6.042447899703295436820744186992189445813E1L, + /* b5 = 1.000000000000000000000000000000000000000E0 */ -h0 = 1.059584930106085509696730443974495979641E4L, -h1 = 2.147921653490043010629481226937850618860E4L, -h2 = 1.643014770044524804175197151958100656728E4L, -h3 = 5.869021995186925517228323497501767586078E3L, -h4 = 9.764244777714344488787381271643502742293E2L, -h5 = 6.442485441570592541741092969581997002349E1L, -/* h6 = 1.000000000000000000000000000000000000000E0 */ + tc = 1.4616321449683623412626595423257213284682E0L, + tf = -1.2148629053584961146050602565082954242826E-1, /* double precision */ + /* tt = (tail of tf), i.e. tf + tt has extended precision. */ + tt = 3.3649914684731379602768989080467587736363E-18L, + /* lgam ( 1.4616321449683623412626595423257213284682E0 ) = + -1.2148629053584960809551455717769158215135617312999903886372437313313530E-1 */ + /* lgam (x + tc) = tf + tt + x g(x)/h(x) + -0.230003726999612341262659542325721328468 <= x + <= 0.2699962730003876587373404576742786715318 + peak relative error 2.1e-21 */ + g0 = 3.645529916721223331888305293534095553827E-18L, + g1 = 5.126654642791082497002594216163574795690E3L, + g2 = 8.828603575854624811911631336122070070327E3L, + g3 = 5.464186426932117031234820886525701595203E3L, + g4 = 1.455427403530884193180776558102868592293E3L, + g5 = 1.541735456969245924860307497029155838446E2L, + g6 = 4.335498275274822298341872707453445815118E0L, -/* lgam (x+1) = -0.5 x + x u(x)/v(x) - -0.100006103515625 <= x <= 0.231639862060546875 - peak relative error 1.3e-21 */ -u0 = -8.886217500092090678492242071879342025627E1L, -u1 = 6.840109978129177639438792958320783599310E2L, -u2 = 2.042626104514127267855588786511809932433E3L, -u3 = 1.911723903442667422201651063009856064275E3L, -u4 = 7.447065275665887457628865263491667767695E2L, -u5 = 1.132256494121790736268471016493103952637E2L, -u6 = 4.484398885516614191003094714505960972894E0L, + h0 = 1.059584930106085509696730443974495979641E4L, + h1 = 2.147921653490043010629481226937850618860E4L, + h2 = 1.643014770044524804175197151958100656728E4L, + h3 = 5.869021995186925517228323497501767586078E3L, + h4 = 9.764244777714344488787381271643502742293E2L, + h5 = 6.442485441570592541741092969581997002349E1L, + /* h6 = 1.000000000000000000000000000000000000000E0 */ -v0 = 1.150830924194461522996462401210374632929E3L, -v1 = 3.399692260848747447377972081399737098610E3L, -v2 = 3.786631705644460255229513563657226008015E3L, -v3 = 1.966450123004478374557778781564114347876E3L, -v4 = 4.741359068914069299837355438370682773122E2L, -v5 = 4.508989649747184050907206782117647852364E1L, -/* v6 = 1.000000000000000000000000000000000000000E0 */ + /* lgam (x+1) = -0.5 x + x u(x)/v(x) + -0.100006103515625 <= x <= 0.231639862060546875 + peak relative error 1.3e-21 */ + u0 = -8.886217500092090678492242071879342025627E1L, + u1 = 6.840109978129177639438792958320783599310E2L, + u2 = 2.042626104514127267855588786511809932433E3L, + u3 = 1.911723903442667422201651063009856064275E3L, + u4 = 7.447065275665887457628865263491667767695E2L, + u5 = 1.132256494121790736268471016493103952637E2L, + u6 = 4.484398885516614191003094714505960972894E0L, + v0 = 1.150830924194461522996462401210374632929E3L, + v1 = 3.399692260848747447377972081399737098610E3L, + v2 = 3.786631705644460255229513563657226008015E3L, + v3 = 1.966450123004478374557778781564114347876E3L, + v4 = 4.741359068914069299837355438370682773122E2L, + v5 = 4.508989649747184050907206782117647852364E1L, + /* v6 = 1.000000000000000000000000000000000000000E0 */ -/* lgam (x+2) = .5 x + x s(x)/r(x) - 0 <= x <= 1 - peak relative error 7.2e-22 */ -s0 = 1.454726263410661942989109455292824853344E6L, -s1 = -3.901428390086348447890408306153378922752E6L, -s2 = -6.573568698209374121847873064292963089438E6L, -s3 = -3.319055881485044417245964508099095984643E6L, -s4 = -7.094891568758439227560184618114707107977E5L, -s5 = -6.263426646464505837422314539808112478303E4L, -s6 = -1.684926520999477529949915657519454051529E3L, + /* lgam (x+2) = .5 x + x s(x)/r(x) + 0 <= x <= 1 + peak relative error 7.2e-22 */ + s0 = 1.454726263410661942989109455292824853344E6L, + s1 = -3.901428390086348447890408306153378922752E6L, + s2 = -6.573568698209374121847873064292963089438E6L, + s3 = -3.319055881485044417245964508099095984643E6L, + s4 = -7.094891568758439227560184618114707107977E5L, + s5 = -6.263426646464505837422314539808112478303E4L, + s6 = -1.684926520999477529949915657519454051529E3L, -r0 = -1.883978160734303518163008696712983134698E7L, -r1 = -2.815206082812062064902202753264922306830E7L, -r2 = -1.600245495251915899081846093343626358398E7L, -r3 = -4.310526301881305003489257052083370058799E6L, -r4 = -5.563807682263923279438235987186184968542E5L, -r5 = -3.027734654434169996032905158145259713083E4L, -r6 = -4.501995652861105629217250715790764371267E2L, -/* r6 = 1.000000000000000000000000000000000000000E0 */ + r0 = -1.883978160734303518163008696712983134698E7L, + r1 = -2.815206082812062064902202753264922306830E7L, + r2 = -1.600245495251915899081846093343626358398E7L, + r3 = -4.310526301881305003489257052083370058799E6L, + r4 = -5.563807682263923279438235987186184968542E5L, + r5 = -3.027734654434169996032905158145259713083E4L, + r6 = -4.501995652861105629217250715790764371267E2L, + /* r6 = 1.000000000000000000000000000000000000000E0 */ - -/* lgam(x) = ( x - 0.5 ) * log(x) - x + LS2PI + 1/x w(1/x^2) - x >= 8 - Peak relative error 1.51e-21 -w0 = LS2PI - 0.5 */ -w0 = 4.189385332046727417803e-1L, -w1 = 8.333333333333331447505E-2L, -w2 = -2.777777777750349603440E-3L, -w3 = 7.936507795855070755671E-4L, -w4 = -5.952345851765688514613E-4L, -w5 = 8.412723297322498080632E-4L, -w6 = -1.880801938119376907179E-3L, -w7 = 4.885026142432270781165E-3L; + /* lgam(x) = ( x - 0.5 ) * log(x) - x + LS2PI + 1/x w(1/x^2) + x >= 8 + Peak relative error 1.51e-21 + w0 = LS2PI - 0.5 */ + w0 = 4.189385332046727417803e-1L, w1 = 8.333333333333331447505E-2L, + w2 = -2.777777777750349603440E-3L, w3 = 7.936507795855070755671E-4L, + w4 = -5.952345851765688514613E-4L, w5 = 8.412723297322498080632E-4L, + w6 = -1.880801938119376907179E-3L, w7 = 4.885026142432270781165E-3L; /* sin(pi*x) assuming x > 2^-1000, if sin(pi*x)==0 the sign is arbitrary */ -static long double sin_pi(long double x) -{ +static long double sin_pi(long double x) { int n; /* spurious inexact if odd int */ x *= 0.5; - x = 2.0*(x - floorl(x)); /* x mod 2.0 */ + x = 2.0 * (x - floorl(x)); /* x mod 2.0 */ - n = (int)(x*4.0); - n = (n+1)/2; - x -= n*0.5f; + n = (int)(x * 4.0); + n = (n + 1) / 2; + x -= n * 0.5f; x *= pi; switch (n) { - default: /* case 4: */ - case 0: return __sinl(x, 0.0, 0); - case 1: return __cosl(x, 0.0); - case 2: return __sinl(-x, 0.0, 0); - case 3: return -__cosl(x, 0.0); + default: /* case 4: */ + case 0: + return __sinl(x, 0.0, 0); + case 1: + return __cosl(x, 0.0); + case 2: + return __sinl(-x, 0.0, 0); + case 3: + return -__cosl(x, 0.0); } } long double __lgammal_r(long double x, int *sg) { long double t, y, z, nadj, p, p1, p2, q, r, w; union ldshape u = {x}; - uint32_t ix = (u.i.se & 0x7fffU)<<16 | u.i.m>>48; + uint32_t ix = (u.i.se & 0x7fffU) << 16 | u.i.m >> 48; int sign = u.i.se >> 15; int i; @@ -236,7 +228,7 @@ long double __lgammal_r(long double x, int *sg) { /* purge off +-inf, NaN, +-0, tiny and negative arguments */ if (ix >= 0x7fff0000) return x * x; - if (ix < 0x3fc08000) { /* |x|<2**-63, return -log(|x|) */ + if (ix < 0x3fc08000) { /* |x|<2**-63, return -log(|x|) */ if (sign) { *sg = -1; x = -x; @@ -247,7 +239,7 @@ long double __lgammal_r(long double x, int *sg) { x = -x; t = sin_pi(x); if (t == 0.0) - return 1.0 / (x-x); /* -integer */ + return 1.0 / (x - x); /* -integer */ if (t > 0.0) *sg = -1; else @@ -258,14 +250,14 @@ long double __lgammal_r(long double x, int *sg) { /* purge off 1 and 2 (so the sign is ok with downward rounding) */ if ((ix == 0x3fff8000 || ix == 0x40008000) && u.i.m == 0) { r = 0; - } else if (ix < 0x40008000) { /* x < 2.0 */ - if (ix <= 0x3ffee666) { /* 8.99993896484375e-1 */ + } else if (ix < 0x40008000) { /* x < 2.0 */ + if (ix <= 0x3ffee666) { /* 8.99993896484375e-1 */ /* lgamma(x) = lgamma(x+1) - log(x) */ r = -logl(x); - if (ix >= 0x3ffebb4a) { /* 7.31597900390625e-1 */ + if (ix >= 0x3ffebb4a) { /* 7.31597900390625e-1 */ y = x - 1.0; i = 0; - } else if (ix >= 0x3ffced33) { /* 2.31639862060546875e-1 */ + } else if (ix >= 0x3ffced33) { /* 2.31639862060546875e-1 */ y = x - (tc - 1.0); i = 1; } else { /* x < 0.23 */ @@ -274,11 +266,11 @@ long double __lgammal_r(long double x, int *sg) { } } else { r = 0.0; - if (ix >= 0x3fffdda6) { /* 1.73162841796875 */ + if (ix >= 0x3fffdda6) { /* 1.73162841796875 */ /* [1.7316,2] */ y = x - 2.0; i = 0; - } else if (ix >= 0x3fff9da6) { /* 1.23162841796875 */ + } else if (ix >= 0x3fff9da6) { /* 1.23162841796875 */ /* [1.23,1.73] */ y = x - tc; i = 1; @@ -289,23 +281,23 @@ long double __lgammal_r(long double x, int *sg) { } } switch (i) { - case 0: - p1 = a0 + y * (a1 + y * (a2 + y * (a3 + y * (a4 + y * a5)))); - p2 = b0 + y * (b1 + y * (b2 + y * (b3 + y * (b4 + y)))); - r += 0.5 * y + y * p1/p2; - break; - case 1: - p1 = g0 + y * (g1 + y * (g2 + y * (g3 + y * (g4 + y * (g5 + y * g6))))); - p2 = h0 + y * (h1 + y * (h2 + y * (h3 + y * (h4 + y * (h5 + y))))); - p = tt + y * p1/p2; - r += (tf + p); - break; - case 2: - p1 = y * (u0 + y * (u1 + y * (u2 + y * (u3 + y * (u4 + y * (u5 + y * u6)))))); - p2 = v0 + y * (v1 + y * (v2 + y * (v3 + y * (v4 + y * (v5 + y))))); - r += (-0.5 * y + p1 / p2); + case 0: + p1 = a0 + y * (a1 + y * (a2 + y * (a3 + y * (a4 + y * a5)))); + p2 = b0 + y * (b1 + y * (b2 + y * (b3 + y * (b4 + y)))); + r += 0.5 * y + y * p1 / p2; + break; + case 1: + p1 = g0 + y * (g1 + y * (g2 + y * (g3 + y * (g4 + y * (g5 + y * g6))))); + p2 = h0 + y * (h1 + y * (h2 + y * (h3 + y * (h4 + y * (h5 + y))))); + p = tt + y * p1 / p2; + r += (tf + p); + break; + case 2: + p1 = y * (u0 + y * (u1 + y * (u2 + y * (u3 + y * (u4 + y * (u5 + y * u6)))))); + p2 = v0 + y * (v1 + y * (v2 + y * (v3 + y * (v4 + y * (v5 + y))))); + r += (-0.5 * y + p1 / p2); } - } else if (ix < 0x40028000) { /* 8.0 */ + } else if (ix < 0x40028000) { /* 8.0 */ /* x < 8.0 */ i = (int)x; y = x - (double)i; @@ -315,20 +307,20 @@ long double __lgammal_r(long double x, int *sg) { z = 1.0; /* lgamma(1+s) = log(s) + lgamma(s) */ switch (i) { - case 7: - z *= (y + 6.0); /* FALLTHRU */ - case 6: - z *= (y + 5.0); /* FALLTHRU */ - case 5: - z *= (y + 4.0); /* FALLTHRU */ - case 4: - z *= (y + 3.0); /* FALLTHRU */ - case 3: - z *= (y + 2.0); /* FALLTHRU */ - r += logl(z); - break; + case 7: + z *= (y + 6.0); /* FALLTHRU */ + case 6: + z *= (y + 5.0); /* FALLTHRU */ + case 5: + z *= (y + 4.0); /* FALLTHRU */ + case 4: + z *= (y + 3.0); /* FALLTHRU */ + case 3: + z *= (y + 2.0); /* FALLTHRU */ + r += logl(z); + break; } - } else if (ix < 0x40418000) { /* 2^66 */ + } else if (ix < 0x40418000) { /* 2^66 */ /* 8.0 <= x < 2**66 */ t = logl(x); z = 1.0 / x; @@ -345,17 +337,11 @@ long double __lgammal_r(long double x, int *sg) { // TODO: broken implementation to make things compile double __lgamma_r(double x, int *sg); -long double __lgammal_r(long double x, int *sg) -{ - return __lgamma_r(x, sg); -} +long double __lgammal_r(long double x, int *sg) { return __lgamma_r(x, sg); } #endif extern int __signgam; -long double lgammal(long double x) -{ - return __lgammal_r(x, &__signgam); -} +long double lgammal(long double x) { return __lgammal_r(x, &__signgam); } weak_alias(__lgammal_r, lgammal_r); diff --git a/options/ansi/musl-generic-math/libm.h b/options/ansi/musl-generic-math/libm.h index 21ebd4589e..68e3612ef0 100644 --- a/options/ansi/musl-generic-math/libm.h +++ b/options/ansi/musl-generic-math/libm.h @@ -13,9 +13,9 @@ #ifndef _LIBM_H #define _LIBM_H -#include #include #include +#include #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ @@ -69,95 +69,125 @@ union ldshape { #error Unsupported long double representation #endif -#define FORCE_EVAL(x) do { \ - if (sizeof(x) == sizeof(float)) { \ - volatile float __x; \ - __x = (x); \ - } else if (sizeof(x) == sizeof(double)) { \ - volatile double __x; \ - __x = (x); \ - } else { \ - volatile long double __x; \ - __x = (x); \ - } \ -} while(0) +#define FORCE_EVAL(x) \ + do { \ + if (sizeof(x) == sizeof(float)) { \ + volatile float __x; \ + __x = (x); \ + } else if (sizeof(x) == sizeof(double)) { \ + volatile double __x; \ + __x = (x); \ + } else { \ + volatile long double __x; \ + __x = (x); \ + } \ + } while (0) /* Get two 32 bit ints from a double. */ -#define EXTRACT_WORDS(hi,lo,d) \ -do { \ - union {double f; uint64_t i;} __u; \ - __u.f = (d); \ - (hi) = __u.i >> 32; \ - (lo) = (uint32_t)__u.i; \ -} while (0) +#define EXTRACT_WORDS(hi, lo, d) \ + do { \ + union { \ + double f; \ + uint64_t i; \ + } __u; \ + __u.f = (d); \ + (hi) = __u.i >> 32; \ + (lo) = (uint32_t)__u.i; \ + } while (0) /* Get the more significant 32 bit int from a double. */ -#define GET_HIGH_WORD(hi,d) \ -do { \ - union {double f; uint64_t i;} __u; \ - __u.f = (d); \ - (hi) = __u.i >> 32; \ -} while (0) +#define GET_HIGH_WORD(hi, d) \ + do { \ + union { \ + double f; \ + uint64_t i; \ + } __u; \ + __u.f = (d); \ + (hi) = __u.i >> 32; \ + } while (0) /* Get the less significant 32 bit int from a double. */ -#define GET_LOW_WORD(lo,d) \ -do { \ - union {double f; uint64_t i;} __u; \ - __u.f = (d); \ - (lo) = (uint32_t)__u.i; \ -} while (0) +#define GET_LOW_WORD(lo, d) \ + do { \ + union { \ + double f; \ + uint64_t i; \ + } __u; \ + __u.f = (d); \ + (lo) = (uint32_t)__u.i; \ + } while (0) /* Set a double from two 32 bit ints. */ -#define INSERT_WORDS(d,hi,lo) \ -do { \ - union {double f; uint64_t i;} __u; \ - __u.i = ((uint64_t)(hi)<<32) | (uint32_t)(lo); \ - (d) = __u.f; \ -} while (0) +#define INSERT_WORDS(d, hi, lo) \ + do { \ + union { \ + double f; \ + uint64_t i; \ + } __u; \ + __u.i = ((uint64_t)(hi) << 32) | (uint32_t)(lo); \ + (d) = __u.f; \ + } while (0) /* Set the more significant 32 bits of a double from an int. */ -#define SET_HIGH_WORD(d,hi) \ -do { \ - union {double f; uint64_t i;} __u; \ - __u.f = (d); \ - __u.i &= 0xffffffff; \ - __u.i |= (uint64_t)(hi) << 32; \ - (d) = __u.f; \ -} while (0) +#define SET_HIGH_WORD(d, hi) \ + do { \ + union { \ + double f; \ + uint64_t i; \ + } __u; \ + __u.f = (d); \ + __u.i &= 0xffffffff; \ + __u.i |= (uint64_t)(hi) << 32; \ + (d) = __u.f; \ + } while (0) /* Set the less significant 32 bits of a double from an int. */ -#define SET_LOW_WORD(d,lo) \ -do { \ - union {double f; uint64_t i;} __u; \ - __u.f = (d); \ - __u.i &= 0xffffffff00000000ull; \ - __u.i |= (uint32_t)(lo); \ - (d) = __u.f; \ -} while (0) +#define SET_LOW_WORD(d, lo) \ + do { \ + union { \ + double f; \ + uint64_t i; \ + } __u; \ + __u.f = (d); \ + __u.i &= 0xffffffff00000000ull; \ + __u.i |= (uint32_t)(lo); \ + (d) = __u.f; \ + } while (0) /* Get a 32 bit int from a float. */ -#define GET_FLOAT_WORD(w,d) \ -do { \ - union {float f; uint32_t i;} __u; \ - __u.f = (d); \ - (w) = __u.i; \ -} while (0) +#define GET_FLOAT_WORD(w, d) \ + do { \ + union { \ + float f; \ + uint32_t i; \ + } __u; \ + __u.f = (d); \ + (w) = __u.i; \ + } while (0) /* Set a float from a 32 bit int. */ -#define SET_FLOAT_WORD(d,w) \ -do { \ - union {float f; uint32_t i;} __u; \ - __u.i = (w); \ - (d) = __u.f; \ -} while (0) +#define SET_FLOAT_WORD(d, w) \ + do { \ + union { \ + float f; \ + uint32_t i; \ + } __u; \ + __u.i = (w); \ + (d) = __u.f; \ + } while (0) #undef __CMPLX #undef CMPLX #undef CMPLXF #undef CMPLXL -#define __CMPLX(x, y, t) \ - ((union { _Complex t __z; t __xy[2]; }){.__xy = {(x),(y)}}.__z) +#define __CMPLX(x, y, t) \ + ((union { \ + _Complex t __z; \ + t __xy[2]; \ + }){ \ + .__xy = {(x), (y)} \ + }.__z) #define CMPLX(x, y) __CMPLX(x, y, double) #define CMPLXF(x, y) __CMPLX(x, y, float) @@ -167,20 +197,20 @@ do { \ /* fdlibm kernel functions */ -int __rem_pio2_large(double*,double*,int,int,int); +int __rem_pio2_large(double *, double *, int, int, int); -int __rem_pio2(double,double*); -double __sin(double,double,int); -double __cos(double,double); -double __tan(double,double,int); +int __rem_pio2(double, double *); +double __sin(double, double, int); +double __cos(double, double); +double __tan(double, double, int); double __expo2(double); /*double complex __ldexp_cexp(double complex,int); */ -int __rem_pio2f(float,double*); -float __sindf(double); -float __cosdf(double); -float __tandf(double,int); -float __expo2f(float); +int __rem_pio2f(float, double *); +float __sindf(double); +float __cosdf(double); +float __tandf(double, int); +float __expo2f(float); /*float complex __ldexp_cexpf(float complex,int); */ int __rem_pio2l(long double, long double *); diff --git a/options/ansi/musl-generic-math/nextafterl.c b/options/ansi/musl-generic-math/nextafterl.c index 37e858fb49..df83289fa0 100644 --- a/options/ansi/musl-generic-math/nextafterl.c +++ b/options/ansi/musl-generic-math/nextafterl.c @@ -1,13 +1,9 @@ #include "libm.h" #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double nextafterl(long double x, long double y) -{ - return nextafter(x, y); -} +long double nextafterl(long double x, long double y) { return nextafter(x, y); } #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -long double nextafterl(long double x, long double y) -{ +long double nextafterl(long double x, long double y) { union ldshape ux, uy; if (isnan(x) || isnan(y)) @@ -38,12 +34,11 @@ long double nextafterl(long double x, long double y) return x + x; /* raise underflow if ux is subnormal or zero */ if ((ux.i.se & 0x7fff) == 0) - FORCE_EVAL(x*x + ux.f*ux.f); + FORCE_EVAL(x * x + ux.f * ux.f); return ux.f; } #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -long double nextafterl(long double x, long double y) -{ +long double nextafterl(long double x, long double y) { union ldshape ux, uy; if (isnan(x) || isnan(y)) @@ -69,7 +64,7 @@ long double nextafterl(long double x, long double y) return x + x; /* raise underflow if ux is subnormal or zero */ if ((ux.i.se & 0x7fff) == 0) - FORCE_EVAL(x*x + ux.f*ux.f); + FORCE_EVAL(x * x + ux.f * ux.f); return ux.f; } #endif diff --git a/options/ansi/musl-generic-math/remquol.c b/options/ansi/musl-generic-math/remquol.c index 9b065c007f..e1acfb6b67 100644 --- a/options/ansi/musl-generic-math/remquol.c +++ b/options/ansi/musl-generic-math/remquol.c @@ -1,13 +1,9 @@ #include "libm.h" #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double remquol(long double x, long double y, int *quo) -{ - return remquo(x, y, quo); -} +long double remquol(long double x, long double y, int *quo) { return remquo(x, y, quo); } #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -long double remquol(long double x, long double y, int *quo) -{ +long double remquol(long double x, long double y, int *quo) { union ldshape ux = {x}, uy = {y}; int ex = ux.i.se & 0x7fff; int ey = uy.i.se & 0x7fff; @@ -17,7 +13,7 @@ long double remquol(long double x, long double y, int *quo) *quo = 0; if (y == 0 || isnan(y) || ex == 0x7fff) - return (x*y)/(x*y); + return (x * y) / (x * y); if (x == 0) return x; @@ -43,15 +39,15 @@ long double remquol(long double x, long double y, int *quo) for (; ex > ey; ex--) { i = mx - my; if (mx >= my) { - mx = 2*i; + mx = 2 * i; q++; q <<= 1; - } else if (2*mx < mx) { - mx = 2*mx - my; + } else if (2 * mx < mx) { + mx = 2 * mx - my; q <<= 1; q++; } else { - mx = 2*mx; + mx = 2 * mx; q <<= 1; } } @@ -63,12 +59,13 @@ long double remquol(long double x, long double y, int *quo) if (mx == 0) ex = -120; else - for (; mx >> 63 == 0; mx *= 2, ex--); + for (; mx >> 63 == 0; mx *= 2, ex--) + ; ux.i.m = mx; #elif LDBL_MANT_DIG == 113 uint64_t hi, lo, xhi, xlo, yhi, ylo; - xhi = (ux.i2.hi & -1ULL>>16) | 1ULL<<48; - yhi = (uy.i2.hi & -1ULL>>16) | 1ULL<<48; + xhi = (ux.i2.hi & -1ULL >> 16) | 1ULL << 48; + yhi = (uy.i2.hi & -1ULL >> 16) | 1ULL << 48; xlo = ux.i2.lo; ylo = ux.i2.lo; for (; ex > ey; ex--) { @@ -77,12 +74,12 @@ long double remquol(long double x, long double y, int *quo) if (xlo < ylo) hi -= 1; if (hi >> 63 == 0) { - xhi = 2*hi + (lo>>63); - xlo = 2*lo; + xhi = 2 * hi + (lo >> 63); + xlo = 2 * lo; q++; } else { - xhi = 2*xhi + (xlo>>63); - xlo = 2*xlo; + xhi = 2 * xhi + (xlo >> 63); + xlo = 2 * xlo; } q <<= 1; } @@ -95,10 +92,11 @@ long double remquol(long double x, long double y, int *quo) xlo = lo; q++; } - if ((xhi|xlo) == 0) + if ((xhi | xlo) == 0) ex = -120; else - for (; xhi >> 48 == 0; xhi = 2*xhi + (xlo>>63), xlo = 2*xlo, ex--); + for (; xhi >> 48 == 0; xhi = 2 * xhi + (xlo >> 63), xlo = 2 * xlo, ex--) + ; ux.i2.hi = xhi; ux.i2.lo = xlo; #endif @@ -113,12 +111,12 @@ long double remquol(long double x, long double y, int *quo) x = ux.f; if (sy) y = -y; - if (ex == ey || (ex+1 == ey && (2*x > y || (2*x == y && q%2)))) { + if (ex == ey || (ex + 1 == ey && (2 * x > y || (2 * x == y && q % 2)))) { x -= y; q++; } q &= 0x7fffffff; - *quo = sx^sy ? -(int)q : (int)q; + *quo = sx ^ sy ? -(int)q : (int)q; return sx ? -x : x; } #endif diff --git a/options/ansi/musl-generic-math/rintl.c b/options/ansi/musl-generic-math/rintl.c index 374327db22..c294b1733f 100644 --- a/options/ansi/musl-generic-math/rintl.c +++ b/options/ansi/musl-generic-math/rintl.c @@ -1,29 +1,25 @@ #include "libm.h" #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double rintl(long double x) -{ - return rint(x); -} +long double rintl(long double x) { return rint(x); } #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -static const long double toint = 1/LDBL_EPSILON; +static const long double toint = 1 / LDBL_EPSILON; -long double rintl(long double x) -{ +long double rintl(long double x) { union ldshape u = {x}; int e = u.i.se & 0x7fff; int s = u.i.se >> 15; long double y; - if (e >= 0x3fff+LDBL_MANT_DIG-1) + if (e >= 0x3fff + LDBL_MANT_DIG - 1) return x; if (s) y = x - toint + toint; else y = x + toint - toint; if (y == 0) - return 0*x; + return 0 * x; return y; } #endif diff --git a/options/ansi/musl-generic-math/roundl.c b/options/ansi/musl-generic-math/roundl.c index f4ff6820a9..c6aa3cc6bf 100644 --- a/options/ansi/musl-generic-math/roundl.c +++ b/options/ansi/musl-generic-math/roundl.c @@ -1,27 +1,23 @@ #include "libm.h" #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double roundl(long double x) -{ - return round(x); -} +long double roundl(long double x) { return round(x); } #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -static const long double toint = 1/LDBL_EPSILON; +static const long double toint = 1 / LDBL_EPSILON; -long double roundl(long double x) -{ +long double roundl(long double x) { union ldshape u = {x}; int e = u.i.se & 0x7fff; long double y; - if (e >= 0x3fff+LDBL_MANT_DIG-1) + if (e >= 0x3fff + LDBL_MANT_DIG - 1) return x; if (u.i.se >> 15) x = -x; - if (e < 0x3fff-1) { + if (e < 0x3fff - 1) { FORCE_EVAL(x + toint); - return 0*u.f; + return 0 * u.f; } y = x + toint - toint - x; if (y > 0.5) diff --git a/options/ansi/musl-generic-math/scalbnl.c b/options/ansi/musl-generic-math/scalbnl.c index db44dab064..42205c4a49 100644 --- a/options/ansi/musl-generic-math/scalbnl.c +++ b/options/ansi/musl-generic-math/scalbnl.c @@ -1,13 +1,9 @@ #include "libm.h" #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double scalbnl(long double x, int n) -{ - return scalbn(x, n); -} +long double scalbnl(long double x, int n) { return scalbn(x, n); } #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -long double scalbnl(long double x, int n) -{ +long double scalbnl(long double x, int n) { union ldshape u; if (n > 16383) { diff --git a/options/elf/include/elf.h b/options/elf/include/elf.h index 9eabfc60a3..041839e6ed 100644 --- a/options/elf/include/elf.h +++ b/options/elf/include/elf.h @@ -1,9 +1,9 @@ #ifndef _ELF_H #define _ELF_H -#include -#include #include +#include +#include #ifdef __cplusplus extern "C" { @@ -49,56 +49,56 @@ typedef Elf32_Half Elf32_Versym; typedef struct { unsigned char e_ident[EI_NIDENT]; /* ELF identification */ - Elf32_Half e_type; /* Object file type */ - Elf32_Half e_machine; /* Machine type */ - Elf32_Word e_version; /* Object file version */ - Elf32_Addr e_entry; /* Entry point address */ - Elf32_Off e_phoff; /* Program header offset */ - Elf32_Off e_shoff; /* Section header offset */ - Elf32_Word e_flags; /* Processor-specific flags */ - Elf32_Half e_ehsize; /* ELF header size */ - Elf32_Half e_phentsize; /* Size of program header entry */ - Elf32_Half e_phnum; /* Number of program header entries */ - Elf32_Half e_shentsize; /* Size of section header entry */ - Elf32_Half e_shnum; /* Number of section header entries */ - Elf32_Half e_shstrndx; /* Section name string table index */ + Elf32_Half e_type; /* Object file type */ + Elf32_Half e_machine; /* Machine type */ + Elf32_Word e_version; /* Object file version */ + Elf32_Addr e_entry; /* Entry point address */ + Elf32_Off e_phoff; /* Program header offset */ + Elf32_Off e_shoff; /* Section header offset */ + Elf32_Word e_flags; /* Processor-specific flags */ + Elf32_Half e_ehsize; /* ELF header size */ + Elf32_Half e_phentsize; /* Size of program header entry */ + Elf32_Half e_phnum; /* Number of program header entries */ + Elf32_Half e_shentsize; /* Size of section header entry */ + Elf32_Half e_shnum; /* Number of section header entries */ + Elf32_Half e_shstrndx; /* Section name string table index */ } Elf32_Ehdr; typedef struct { unsigned char e_ident[EI_NIDENT]; /* ELF identification */ - Elf64_Half e_type; /* Object file type */ - Elf64_Half e_machine; /* Machine type */ - Elf64_Word e_version; /* Object file version */ - Elf64_Addr e_entry; /* Entry point address */ - Elf64_Off e_phoff; /* Program header offset */ - Elf64_Off e_shoff; /* Section header offset */ - Elf64_Word e_flags; /* Processor-specific flags */ - Elf64_Half e_ehsize; /* ELF header size */ - Elf64_Half e_phentsize; /* Size of program header entry */ - Elf64_Half e_phnum; /* Number of program header entries */ - Elf64_Half e_shentsize; /* Size of section header entry */ - Elf64_Half e_shnum; /* Number of section header entries */ - Elf64_Half e_shstrndx; /* Section name string table index */ + Elf64_Half e_type; /* Object file type */ + Elf64_Half e_machine; /* Machine type */ + Elf64_Word e_version; /* Object file version */ + Elf64_Addr e_entry; /* Entry point address */ + Elf64_Off e_phoff; /* Program header offset */ + Elf64_Off e_shoff; /* Section header offset */ + Elf64_Word e_flags; /* Processor-specific flags */ + Elf64_Half e_ehsize; /* ELF header size */ + Elf64_Half e_phentsize; /* Size of program header entry */ + Elf64_Half e_phnum; /* Number of program header entries */ + Elf64_Half e_shentsize; /* Size of section header entry */ + Elf64_Half e_shnum; /* Number of section header entries */ + Elf64_Half e_shstrndx; /* Section name string table index */ } Elf64_Ehdr; typedef struct { Elf32_Half vd_version; /* Version revision */ - Elf32_Half vd_flags; /* Version information */ - Elf32_Half vd_ndx; /* Version Index */ - Elf32_Half vd_cnt; /* Number of associated aux entries */ - Elf32_Word vd_hash; /* Version name hash value */ - Elf32_Word vd_aux; /* Offset in bytes to verdaux array */ - Elf32_Word vd_next; /* Offset in bytes to next verdef entry */ + Elf32_Half vd_flags; /* Version information */ + Elf32_Half vd_ndx; /* Version Index */ + Elf32_Half vd_cnt; /* Number of associated aux entries */ + Elf32_Word vd_hash; /* Version name hash value */ + Elf32_Word vd_aux; /* Offset in bytes to verdaux array */ + Elf32_Word vd_next; /* Offset in bytes to next verdef entry */ } Elf32_Verdef; typedef struct { Elf64_Half vd_version; /* Version revision */ - Elf64_Half vd_flags; /* Version information */ - Elf64_Half vd_ndx; /* Version Index */ - Elf64_Half vd_cnt; /* Number of associated aux entries */ - Elf64_Word vd_hash; /* Version name hash value */ - Elf64_Word vd_aux; /* Offset in bytes to verdaux array */ - Elf64_Word vd_next; /* Offset in bytes to next verdef entry */ + Elf64_Half vd_flags; /* Version information */ + Elf64_Half vd_ndx; /* Version Index */ + Elf64_Half vd_cnt; /* Number of associated aux entries */ + Elf64_Word vd_hash; /* Version name hash value */ + Elf64_Word vd_aux; /* Offset in bytes to verdaux array */ + Elf64_Word vd_next; /* Offset in bytes to next verdef entry */ } Elf64_Verdef; typedef struct { @@ -159,22 +159,11 @@ typedef struct { Elf64_Word l_flags; } Elf64_Lib; -enum { - ET_NONE = 0, - ET_REL = 1, - ET_EXEC = 2, - ET_DYN = 3, - ET_CORE = 4 -}; +enum { ET_NONE = 0, ET_REL = 1, ET_EXEC = 2, ET_DYN = 3, ET_CORE = 4 }; -enum { - SHN_UNDEF = 0, - SHN_ABS = 0xFFF1 -}; +enum { SHN_UNDEF = 0, SHN_ABS = 0xFFF1 }; -enum { - STN_UNDEF = 0 -}; +enum { STN_UNDEF = 0 }; typedef struct { Elf32_Word st_name; @@ -194,12 +183,8 @@ typedef struct { Elf64_Xword st_size; } Elf64_Sym; -__MLIBC_INLINE_DEFINITION unsigned char ELF64_ST_BIND(unsigned char info) { - return info >> 4; -} -__MLIBC_INLINE_DEFINITION unsigned char ELF64_ST_TYPE(unsigned char info) { - return info & 0x0F; -} +__MLIBC_INLINE_DEFINITION unsigned char ELF64_ST_BIND(unsigned char info) { return info >> 4; } +__MLIBC_INLINE_DEFINITION unsigned char ELF64_ST_TYPE(unsigned char info) { return info & 0x0F; } __MLIBC_INLINE_DEFINITION unsigned char ELF64_ST_INFO(unsigned char bind, unsigned char type) { return (bind << 4) | type; } @@ -209,31 +194,15 @@ typedef struct { Elf64_Half si_flags; } Elf64_Syminfo; -__MLIBC_INLINE_DEFINITION unsigned char ELF32_ST_BIND(unsigned char info) { - return info >> 4; -} -__MLIBC_INLINE_DEFINITION unsigned char ELF32_ST_TYPE(unsigned char info) { - return info & 0xF; -} +__MLIBC_INLINE_DEFINITION unsigned char ELF32_ST_BIND(unsigned char info) { return info >> 4; } +__MLIBC_INLINE_DEFINITION unsigned char ELF32_ST_TYPE(unsigned char info) { return info & 0xF; } __MLIBC_INLINE_DEFINITION unsigned char ELF32_ST_INFO(unsigned char bind, unsigned char type) { return (bind << 4) | (type & 0xF); } -enum { - STB_GLOBAL = 1, - STB_WEAK = 2, - STB_GNU_UNIQUE = 10, - STB_LOPROC = 13, - STB_HIPROC = 15 -}; +enum { STB_GLOBAL = 1, STB_WEAK = 2, STB_GNU_UNIQUE = 10, STB_LOPROC = 13, STB_HIPROC = 15 }; -enum { - STT_OBJECT = 1, - STT_FUNC = 2, - STT_TLS = 6, - STT_LOPROC = 13, - STT_HIPROC = 15 -}; +enum { STT_OBJECT = 1, STT_FUNC = 2, STT_TLS = 6, STT_LOPROC = 13, STT_HIPROC = 15 }; enum { R_X86_64_NONE = 0, @@ -318,8 +287,8 @@ enum { R_68K_RELATIVE = 22, R_68K_TLS_DTPMOD32 = 40, - R_68K_TLS_DTPREL32= 41, - R_68K_TLS_TPREL32= 42 + R_68K_TLS_DTPREL32 = 41, + R_68K_TLS_TPREL32 = 42 }; enum { @@ -345,7 +314,7 @@ typedef struct { typedef struct { Elf64_Addr r_offset; - uint64_t r_info; + uint64_t r_info; } Elf64_Rel; typedef struct { @@ -363,22 +332,14 @@ typedef struct { typedef Elf32_Word Elf32_Relr; typedef Elf64_Xword Elf64_Relr; -__MLIBC_INLINE_DEFINITION Elf64_Xword ELF64_R_SYM(Elf64_Xword info) { - return info >> 32; -} -__MLIBC_INLINE_DEFINITION Elf64_Xword ELF64_R_TYPE(Elf64_Xword info) { - return info & 0xFFFFFFFF; -} +__MLIBC_INLINE_DEFINITION Elf64_Xword ELF64_R_SYM(Elf64_Xword info) { return info >> 32; } +__MLIBC_INLINE_DEFINITION Elf64_Xword ELF64_R_TYPE(Elf64_Xword info) { return info & 0xFFFFFFFF; } __MLIBC_INLINE_DEFINITION Elf64_Xword ELF64_R_INFO(Elf64_Xword sym, Elf64_Xword type) { return ((((Elf64_Xword)(sym)) << 32) + (type)); } -__MLIBC_INLINE_DEFINITION Elf32_Word ELF32_R_SYM(Elf32_Word info) { - return info >> 8; -} -__MLIBC_INLINE_DEFINITION Elf32_Word ELF32_R_TYPE(Elf32_Word info) { - return info & 0xFF; -} +__MLIBC_INLINE_DEFINITION Elf32_Word ELF32_R_SYM(Elf32_Word info) { return info >> 8; } +__MLIBC_INLINE_DEFINITION Elf32_Word ELF32_R_TYPE(Elf32_Word info) { return info & 0xFF; } enum { PT_NULL = 0, @@ -405,32 +366,28 @@ enum { PT_HIPROC = 0x7fffffff }; -enum { - PF_X = 1, - PF_W = 2, - PF_R = 4 -}; +enum { PF_X = 1, PF_W = 2, PF_R = 4 }; typedef struct { - Elf32_Word p_type; /* Type of segment */ - Elf32_Off p_offset; /* Offset in file */ - Elf32_Addr p_vaddr; /* Virtual address in memory */ - Elf32_Addr p_paddr; /* Reserved */ + Elf32_Word p_type; /* Type of segment */ + Elf32_Off p_offset; /* Offset in file */ + Elf32_Addr p_vaddr; /* Virtual address in memory */ + Elf32_Addr p_paddr; /* Reserved */ Elf32_Word p_filesz; /* Size of segment in file */ - Elf32_Word p_memsz; /* Size of segment in memory */ - Elf32_Word p_flags; /* Segment attributes */ - Elf32_Word p_align; /* Alignment of segment */ + Elf32_Word p_memsz; /* Size of segment in memory */ + Elf32_Word p_flags; /* Segment attributes */ + Elf32_Word p_align; /* Alignment of segment */ } Elf32_Phdr; typedef struct { - Elf64_Word p_type; /* Type of segment */ - Elf64_Word p_flags; /* Segment attributes */ - Elf64_Off p_offset; /* Offset in file */ - Elf64_Addr p_vaddr; /* Virtual address in memory */ - Elf64_Addr p_paddr; /* Reserved */ + Elf64_Word p_type; /* Type of segment */ + Elf64_Word p_flags; /* Segment attributes */ + Elf64_Off p_offset; /* Offset in file */ + Elf64_Addr p_vaddr; /* Virtual address in memory */ + Elf64_Addr p_paddr; /* Reserved */ Elf64_Xword p_filesz; /* Size of segment in file */ - Elf64_Xword p_memsz; /* Size of segment in memory */ - Elf64_Xword p_align; /* Alignment of segment */ + Elf64_Xword p_memsz; /* Size of segment in memory */ + Elf64_Xword p_align; /* Alignment of segment */ } Elf64_Phdr; enum { @@ -499,8 +456,8 @@ enum { }; /* Valid values for note segment descriptor files for core files */ -#define NT_PRSTATUS 1 -#define NT_FPREGSET 2 +#define NT_PRSTATUS 1 +#define NT_FPREGSET 2 #define NT_PRPSINFO 3 /* Build ID bits as generated by ld --build-id */ @@ -549,10 +506,10 @@ typedef struct { } Elf64_Shdr; typedef struct { - uint64_t a_type; - union { - uint64_t a_val; - } a_un; + uint64_t a_type; + union { + uint64_t a_val; + } a_un; } Elf64_auxv_t; typedef struct { @@ -563,123 +520,124 @@ typedef struct { } Elf32_auxv_t; typedef struct { - Elf32_Word n_namesz; - Elf32_Word n_descsz; - Elf32_Word n_type; + Elf32_Word n_namesz; + Elf32_Word n_descsz; + Elf32_Word n_type; } Elf32_Nhdr; typedef struct { - Elf64_Word n_namesz; - Elf64_Word n_descsz; - Elf64_Word n_type; + Elf64_Word n_namesz; + Elf64_Word n_descsz; + Elf64_Word n_type; } Elf64_Nhdr; /* ST_TYPE (subfield of st_info) values (symbol type) */ -#define STT_NOTYPE 0 -#define STT_OBJECT 1 -#define STT_FUNC 2 -#define STT_SECTION 3 -#define STT_FILE 4 +#define STT_NOTYPE 0 +#define STT_OBJECT 1 +#define STT_FUNC 2 +#define STT_SECTION 3 +#define STT_FILE 4 /* ST_BIND (subfield of st_info) values (symbol binding) */ -#define STB_LOCAL 0 -#define STB_GLOBAL 1 -#define STB_WEAK 2 +#define STB_LOCAL 0 +#define STB_GLOBAL 1 +#define STB_WEAK 2 /* sh_type (section type) values */ -#define SHT_NULL 0 -#define SHT_PROGBITS 1 -#define SHT_SYMTAB 2 -#define SHT_STRTAB 3 -#define SHT_RELA 4 -#define SHT_HASH 5 +#define SHT_NULL 0 +#define SHT_PROGBITS 1 +#define SHT_SYMTAB 2 +#define SHT_STRTAB 3 +#define SHT_RELA 4 +#define SHT_HASH 5 #define SHT_DYNAMIC 6 -#define SHT_NOTE 7 -#define SHT_NOBITS 8 -#define SHT_REL 9 -#define SHT_DYNSYM 11 -#define SHT_INIT_ARRAY 14 -#define SHT_FINI_ARRAY 15 -#define SHT_SYMTAB_SHNDX 18 +#define SHT_NOTE 7 +#define SHT_NOBITS 8 +#define SHT_REL 9 +#define SHT_DYNSYM 11 +#define SHT_INIT_ARRAY 14 +#define SHT_FINI_ARRAY 15 +#define SHT_SYMTAB_SHNDX 18 /* special section indices */ -#define SHN_UNDEF 0 -#define SHN_LORESERVE 0xff00 -#define SHN_COMMON 0xfff2 -#define SHN_XINDEX 0xffff -#define SHN_HIRESERVE 0xff00 +#define SHN_UNDEF 0 +#define SHN_LORESERVE 0xff00 +#define SHN_COMMON 0xfff2 +#define SHN_XINDEX 0xffff +#define SHN_HIRESERVE 0xff00 /* values for e_machine */ -#define EM_NONE 0 -#define EM_M32 1 -#define EM_SPARC 2 -#define EM_386 3 -#define EM_68K 4 -#define EM_MIPS 8 -#define EM_PARISC 15 -#define EM_PPC 20 -#define EM_PPC64 21 -#define EM_S390 22 -#define EM_ARM 40 -#define EM_SH 42 -#define EM_SPARCV9 43 -#define EM_IA_64 50 -#define EM_X86_64 62 -#define EM_BLACKFIN 106 -#define EM_AARCH64 183 -#define EM_RISCV 243 -#define EM_LOONGARCH 258 - -/* Linux notes this value as being interim; however applications are using this (Qt6), so we define it here. */ -#define EM_ALPHA 0x9026 +#define EM_NONE 0 +#define EM_M32 1 +#define EM_SPARC 2 +#define EM_386 3 +#define EM_68K 4 +#define EM_MIPS 8 +#define EM_PARISC 15 +#define EM_PPC 20 +#define EM_PPC64 21 +#define EM_S390 22 +#define EM_ARM 40 +#define EM_SH 42 +#define EM_SPARCV9 43 +#define EM_IA_64 50 +#define EM_X86_64 62 +#define EM_BLACKFIN 106 +#define EM_AARCH64 183 +#define EM_RISCV 243 +#define EM_LOONGARCH 258 + +/* Linux notes this value as being interim; however applications are using this (Qt6), so we define + * it here. */ +#define EM_ALPHA 0x9026 /* values for e_version */ -#define EV_NONE 0 -#define EV_CURRENT 1 -#define EV_NUM 2 +#define EV_NONE 0 +#define EV_CURRENT 1 +#define EV_NUM 2 /* e_indent constants */ -#define EI_MAG0 0 -#define ELFMAG0 0x7f +#define EI_MAG0 0 +#define ELFMAG0 0x7f -#define EI_MAG1 1 -#define ELFMAG1 'E' +#define EI_MAG1 1 +#define ELFMAG1 'E' -#define EI_MAG2 2 -#define ELFMAG2 'L' +#define EI_MAG2 2 +#define ELFMAG2 'L' -#define EI_MAG3 3 -#define ELFMAG3 'F' +#define EI_MAG3 3 +#define ELFMAG3 'F' -#define ELFMAG "\177ELF" -#define SELFMAG 4 +#define ELFMAG "\177ELF" +#define SELFMAG 4 -#define EI_CLASS 4 -#define ELFCLASSNONE 0 -#define ELFCLASS32 1 -#define ELFCLASS64 2 -#define ELFCLASSNUM 3 +#define EI_CLASS 4 +#define ELFCLASSNONE 0 +#define ELFCLASS32 1 +#define ELFCLASS64 2 +#define ELFCLASSNUM 3 -#define EI_DATA 5 -#define ELFDATANONE 0 -#define ELFDATA2LSB 1 -#define ELFDATA2MSB 2 -#define ELFDATANUM 3 +#define EI_DATA 5 +#define ELFDATANONE 0 +#define ELFDATA2LSB 1 +#define ELFDATA2MSB 2 +#define ELFDATANUM 3 -#define EI_VERSION 6 +#define EI_VERSION 6 -#define EI_OSABI 7 -#define ELFOSABI_HPUX 1 -#define ELFOSABI_NETBSD 2 -#define ELFOSABI_GNU 3 +#define EI_OSABI 7 +#define ELFOSABI_HPUX 1 +#define ELFOSABI_NETBSD 2 +#define ELFOSABI_GNU 3 #define ELFOSABI_LINUX ELFOSABI_GNU -#define ELFOSABI_SOLARIS 6 -#define ELFOSABI_AIX 7 -#define ELFOSABI_IRIX 8 -#define ELFOSABI_FREEBSD 9 -#define ELFOSABI_OPENBSD 12 +#define ELFOSABI_SOLARIS 6 +#define ELFOSABI_AIX 7 +#define ELFOSABI_IRIX 8 +#define ELFOSABI_FREEBSD 9 +#define ELFOSABI_OPENBSD 12 -#define EI_ABIVERSION 8 +#define EI_ABIVERSION 8 #define ELF_NOTE_GNU "GNU" diff --git a/options/elf/include/link.h b/options/elf/include/link.h index 91a5fb6b8f..bb1bd9d93e 100644 --- a/options/elf/include/link.h +++ b/options/elf/include/link.h @@ -8,19 +8,19 @@ extern "C" { #include #include -#if defined(__x86_64__) || defined(__aarch64__) \ - || (defined(__riscv) && __riscv_xlen == 64) || defined(__loongarch64) -# define ElfW(type) Elf64_ ## type +#if defined(__x86_64__) || defined(__aarch64__) || (defined(__riscv) && __riscv_xlen == 64) \ + || defined(__loongarch64) +#define ElfW(type) Elf64_##type #elif defined(__i386__) || defined(__m68k__) -# define ElfW(type) Elf32_ ## type +#define ElfW(type) Elf32_##type #else -# error Unknown architecture +#error Unknown architecture #endif struct dl_phdr_info { ElfW(Addr) dlpi_addr; const char *dlpi_name; - const ElfW(Phdr) *dlpi_phdr; + const ElfW(Phdr) * dlpi_phdr; ElfW(Half) dlpi_phnum; unsigned long long int dlpi_adds; unsigned long long int dlpi_subs; @@ -31,7 +31,7 @@ struct dl_phdr_info { struct link_map { Elf64_Addr l_addr; char *l_name; - ElfW(Dyn) *l_ld; + ElfW(Dyn) * l_ld; struct link_map *l_next, *l_prev; }; @@ -45,7 +45,9 @@ struct r_debug { #ifndef __MLIBC_ABI_ONLY -int dl_iterate_phdr(int (*__callback)(struct dl_phdr_info* __info, size_t __size, void* __data), void* __data); +int dl_iterate_phdr( + int (*__callback)(struct dl_phdr_info *__info, size_t __size, void *__data), void *__data +); extern ElfW(Dyn) _DYNAMIC[]; diff --git a/options/internal/include/bits/machine.h b/options/internal/include/bits/machine.h index ad000f60ce..1f475e7eb6 100644 --- a/options/internal/include/bits/machine.h +++ b/options/internal/include/bits/machine.h @@ -4,7 +4,7 @@ #include -#if defined (__i386__) +#if defined(__i386__) struct __mlibc_jmpbuf_register_state { uint32_t ebx; uint32_t ebp; @@ -13,7 +13,7 @@ struct __mlibc_jmpbuf_register_state { uint32_t esp; uint32_t eip; }; -#elif defined (__x86_64__) +#elif defined(__x86_64__) struct __mlibc_jmpbuf_register_state { uint64_t rbx; uint64_t rbp; @@ -24,7 +24,7 @@ struct __mlibc_jmpbuf_register_state { uint64_t rsp; uint64_t rip; }; -#elif defined (__aarch64__) +#elif defined(__aarch64__) struct __mlibc_jmpbuf_register_state { uint64_t x19; uint64_t x20; @@ -49,7 +49,7 @@ struct __mlibc_jmpbuf_register_state { uint64_t d14; uint64_t d15; }; -#elif defined (__riscv) && __riscv_xlen == 64 +#elif defined(__riscv) && __riscv_xlen == 64 struct __mlibc_jmpbuf_register_state { uint64_t ra; uint64_t s0; @@ -78,7 +78,7 @@ struct __mlibc_jmpbuf_register_state { double fs10; double fs11; }; -#elif defined (__m68k__) +#elif defined(__m68k__) struct __mlibc_jmpbuf_register_state { uint32_t d2; uint32_t d3; @@ -95,7 +95,7 @@ struct __mlibc_jmpbuf_register_state { uint32_t sp; uint32_t pc; }; -#elif defined (__loongarch64) +#elif defined(__loongarch64) struct __mlibc_jmpbuf_register_state { uint64_t ra; uint64_t sp; @@ -119,8 +119,7 @@ struct __mlibc_jmpbuf_register_state { double fs7; }; #else -# error "Missing architecture specific code" +#error "Missing architecture specific code" #endif #endif /* MLIBC_MACHINE_H */ - diff --git a/options/internal/include/bits/types.h b/options/internal/include/bits/types.h index ee8b2eeff5..55079ea329 100644 --- a/options/internal/include/bits/types.h +++ b/options/internal/include/bits/types.h @@ -1,66 +1,66 @@ #ifndef _MLIBC_INTERNAL_TYPES_H #define _MLIBC_INTERNAL_TYPES_H -typedef __UINT8_TYPE__ __mlibc_uint8; +typedef __UINT8_TYPE__ __mlibc_uint8; typedef __UINT16_TYPE__ __mlibc_uint16; typedef __UINT32_TYPE__ __mlibc_uint32; typedef __UINT64_TYPE__ __mlibc_uint64; -typedef __INT8_TYPE__ __mlibc_int8; +typedef __INT8_TYPE__ __mlibc_int8; typedef __INT16_TYPE__ __mlibc_int16; typedef __INT32_TYPE__ __mlibc_int32; typedef __INT64_TYPE__ __mlibc_int64; /* Clang and GCC have different mechanisms for INT32_C and friends. */ #ifdef __clang__ -# define __MLIBC_C_EXPAND_JOIN(x, suffix) x ## suffix -# define __MLIBC_C_JOIN(x, suffix) __MLIBC_C_EXPAND_JOIN(x, suffix) +#define __MLIBC_C_EXPAND_JOIN(x, suffix) x##suffix +#define __MLIBC_C_JOIN(x, suffix) __MLIBC_C_EXPAND_JOIN(x, suffix) -# define __MLIBC_INT8_C(x) __MLIBC_C_JOIN(x, __INT8_C_SUFFIX__) -# define __MLIBC_INT16_C(x) __MLIBC_C_JOIN(x, __INT16_C_SUFFIX__) -# define __MLIBC_INT32_C(x) __MLIBC_C_JOIN(x, __INT32_C_SUFFIX__) -# define __MLIBC_INT64_C(x) __MLIBC_C_JOIN(x, __INT64_C_SUFFIX__) +#define __MLIBC_INT8_C(x) __MLIBC_C_JOIN(x, __INT8_C_SUFFIX__) +#define __MLIBC_INT16_C(x) __MLIBC_C_JOIN(x, __INT16_C_SUFFIX__) +#define __MLIBC_INT32_C(x) __MLIBC_C_JOIN(x, __INT32_C_SUFFIX__) +#define __MLIBC_INT64_C(x) __MLIBC_C_JOIN(x, __INT64_C_SUFFIX__) -# define __MLIBC_UINT8_C(x) __MLIBC_C_JOIN(x, __UINT8_C_SUFFIX__) -# define __MLIBC_UINT16_C(x) __MLIBC_C_JOIN(x, __UINT16_C_SUFFIX__) -# define __MLIBC_UINT32_C(x) __MLIBC_C_JOIN(x, __UINT32_C_SUFFIX__) -# define __MLIBC_UINT64_C(x) __MLIBC_C_JOIN(x, __UINT64_C_SUFFIX__) +#define __MLIBC_UINT8_C(x) __MLIBC_C_JOIN(x, __UINT8_C_SUFFIX__) +#define __MLIBC_UINT16_C(x) __MLIBC_C_JOIN(x, __UINT16_C_SUFFIX__) +#define __MLIBC_UINT32_C(x) __MLIBC_C_JOIN(x, __UINT32_C_SUFFIX__) +#define __MLIBC_UINT64_C(x) __MLIBC_C_JOIN(x, __UINT64_C_SUFFIX__) -# define __MLIBC_INTMAX_C(x) __MLIBC_C_JOIN(x, __INTMAX_C_SUFFIX__) -# define __MLIBC_UINTMAX_C(x) __MLIBC_C_JOIN(x, __UINTMAX_C_SUFFIX__) +#define __MLIBC_INTMAX_C(x) __MLIBC_C_JOIN(x, __INTMAX_C_SUFFIX__) +#define __MLIBC_UINTMAX_C(x) __MLIBC_C_JOIN(x, __UINTMAX_C_SUFFIX__) #else -# define __MLIBC_INT8_C(x) __INT8_C(x) -# define __MLIBC_INT16_C(x) __INT16_C(x) -# define __MLIBC_INT32_C(x) __INT32_C(x) -# define __MLIBC_INT64_C(x) __INT64_C(x) - -# define __MLIBC_UINT8_C(x) __UINT8_C(x) -# define __MLIBC_UINT16_C(x) __UINT16_C(x) -# define __MLIBC_UINT32_C(x) __UINT32_C(x) -# define __MLIBC_UINT64_C(x) __UINT64_C(x) - -# define __MLIBC_INTMAX_C(x) __INTMAX_C(x) -# define __MLIBC_UINTMAX_C(x) __UINTMAX_C(x) +#define __MLIBC_INT8_C(x) __INT8_C(x) +#define __MLIBC_INT16_C(x) __INT16_C(x) +#define __MLIBC_INT32_C(x) __INT32_C(x) +#define __MLIBC_INT64_C(x) __INT64_C(x) + +#define __MLIBC_UINT8_C(x) __UINT8_C(x) +#define __MLIBC_UINT16_C(x) __UINT16_C(x) +#define __MLIBC_UINT32_C(x) __UINT32_C(x) +#define __MLIBC_UINT64_C(x) __UINT64_C(x) + +#define __MLIBC_INTMAX_C(x) __INTMAX_C(x) +#define __MLIBC_UINTMAX_C(x) __UINTMAX_C(x) #endif -#define __MLIBC_INT8_MAX __INT8_MAX__ +#define __MLIBC_INT8_MAX __INT8_MAX__ #define __MLIBC_INT16_MAX __INT16_MAX__ #define __MLIBC_INT32_MAX __INT32_MAX__ #define __MLIBC_INT64_MAX __INT64_MAX__ -#define __MLIBC_INT8_MIN (-__MLIBC_INT8_MAX - 1) +#define __MLIBC_INT8_MIN (-__MLIBC_INT8_MAX - 1) #define __MLIBC_INT16_MIN (-__MLIBC_INT16_MAX - 1) #define __MLIBC_INT32_MIN (-__MLIBC_INT32_MAX - 1) #define __MLIBC_INT64_MIN (-__MLIBC_INT64_MAX - 1) -#define __MLIBC_UINT8_MAX __UINT8_MAX__ +#define __MLIBC_UINT8_MAX __UINT8_MAX__ #define __MLIBC_UINT16_MAX __UINT16_MAX__ #define __MLIBC_UINT32_MAX __UINT32_MAX__ #define __MLIBC_UINT64_MAX __UINT64_MAX__ /* Fast types (signed). */ -#if defined (__i386__) +#if defined(__i386__) typedef __mlibc_int8 __mlibc_int_fast8; #define __MLIBC_INT_FAST8_C(x) __MLIBC_INT8_C(x) @@ -82,7 +82,7 @@ typedef __mlibc_int64 __mlibc_int_fast64; #define __MLIBC_INT_FAST64_MAX __MLIBC_INT64_MAX #define __MLIBC_INT_FAST64_MIN __MLIBC_INT64_MIN -#elif defined (__x86_64__) +#elif defined(__x86_64__) typedef __mlibc_int8 __mlibc_int_fast8; #define __MLIBC_INT_FAST8_C(x) __MLIBC_INT8_C(x) @@ -104,7 +104,7 @@ typedef __mlibc_int64 __mlibc_int_fast64; #define __MLIBC_INT_FAST64_MAX __MLIBC_INT64_MAX #define __MLIBC_INT_FAST64_MIN __MLIBC_INT64_MIN -#elif defined (__aarch64__) +#elif defined(__aarch64__) typedef __mlibc_int8 __mlibc_int_fast8; #define __MLIBC_INT_FAST8_C(x) __MLIBC_INT8_C(x) @@ -126,7 +126,7 @@ typedef __mlibc_int64 __mlibc_int_fast64; #define __MLIBC_INT_FAST64_MAX __MLIBC_INT64_MAX #define __MLIBC_INT_FAST64_MIN __MLIBC_INT64_MIN -#elif defined (__riscv) && __riscv_xlen == 64 +#elif defined(__riscv) && __riscv_xlen == 64 typedef __mlibc_int8 __mlibc_int_fast8; #define __MLIBC_INT_FAST8_C(x) __MLIBC_INT8_C(x) @@ -148,7 +148,7 @@ typedef __mlibc_int64 __mlibc_int_fast64; #define __MLIBC_INT_FAST64_MAX __MLIBC_INT64_MAX #define __MLIBC_INT_FAST64_MIN __MLIBC_INT64_MIN -#elif defined (__m68k__) +#elif defined(__m68k__) typedef __mlibc_int8 __mlibc_int_fast8; #define __MLIBC_INT_FAST8_C(x) __MLIBC_INT8_C(x) @@ -170,7 +170,7 @@ typedef __mlibc_int64 __mlibc_int_fast64; #define __MLIBC_INT_FAST64_MAX __MLIBC_INT64_MAX #define __MLIBC_INT_FAST64_MIN __MLIBC_INT64_MIN -#elif defined (__loongarch64) +#elif defined(__loongarch64) typedef __mlibc_int8 __mlibc_int_fast8; #define __MLIBC_INT_FAST8_C(x) __MLIBC_INT8_C(x) @@ -193,12 +193,12 @@ typedef __mlibc_int64 __mlibc_int_fast64; #define __MLIBC_INT_FAST64_MIN __MLIBC_INT64_MIN #else -# error "Missing architecture specific code" +#error "Missing architecture specific code" #endif /* Fast types (unsigned). */ -#if defined (__i386__) +#if defined(__i386__) typedef __mlibc_uint8 __mlibc_uint_fast8; #define __MLIBC_UINT_FAST8_C(x) __MLIBC_UINT8_C(x) @@ -220,7 +220,7 @@ typedef __mlibc_uint64 __mlibc_uint_fast64; #define __MLIBC_UINT_FAST64_MAX __MLIBC_UINT64_MAX #define __MLIBC_UINT_FAST64_MIN __MLIBC_UINT64_MIN -#elif defined (__x86_64__) +#elif defined(__x86_64__) typedef __mlibc_uint8 __mlibc_uint_fast8; #define __MLIBC_UINT_FAST8_C(x) __MLIBC_UINT8_C(x) @@ -242,7 +242,7 @@ typedef __mlibc_uint64 __mlibc_uint_fast64; #define __MLIBC_UINT_FAST64_MAX __MLIBC_UINT64_MAX #define __MLIBC_UINT_FAST64_MIN __MLIBC_UINT64_MIN -#elif defined (__aarch64__) +#elif defined(__aarch64__) typedef __mlibc_uint8 __mlibc_uint_fast8; #define __MLIBC_UINT_FAST8_C(x) __MLIBC_UINT8_C(x) @@ -264,7 +264,7 @@ typedef __mlibc_uint64 __mlibc_uint_fast64; #define __MLIBC_UINT_FAST64_MAX __MLIBC_UINT64_MAX #define __MLIBC_UINT_FAST64_MIN __MLIBC_UINT64_MIN -#elif defined (__riscv) && __riscv_xlen == 64 +#elif defined(__riscv) && __riscv_xlen == 64 typedef __mlibc_uint8 __mlibc_uint_fast8; #define __MLIBC_UINT_FAST8_C(x) __MLIBC_UINT8_C(x) @@ -286,7 +286,7 @@ typedef __mlibc_uint64 __mlibc_uint_fast64; #define __MLIBC_UINT_FAST64_MAX __MLIBC_UINT64_MAX #define __MLIBC_UINT_FAST64_MIN __MLIBC_UINT64_MIN -#elif defined (__m68k__) +#elif defined(__m68k__) typedef __mlibc_uint8 __mlibc_uint_fast8; #define __MLIBC_UINT_FAST8_C(x) __MLIBC_UINT8_C(x) @@ -308,7 +308,7 @@ typedef __mlibc_uint64 __mlibc_uint_fast64; #define __MLIBC_UINT_FAST64_MAX __MLIBC_UINT64_MAX #define __MLIBC_UINT_FAST64_MIN __MLIBC_UINT64_MIN -#elif defined (__loongarch64) +#elif defined(__loongarch64) typedef __mlibc_uint8 __mlibc_uint_fast8; #define __MLIBC_UINT_FAST8_C(x) __MLIBC_UINT8_C(x) @@ -331,13 +331,13 @@ typedef __mlibc_uint64 __mlibc_uint_fast64; #define __MLIBC_UINT_FAST64_MIN __MLIBC_UINT64_MIN #else -# error "Missing architecture specific code" +#error "Missing architecture specific code" #endif /* Special types. */ -typedef __INTMAX_TYPE__ __mlibc_intmax; -typedef __INTPTR_TYPE__ __mlibc_intptr; +typedef __INTMAX_TYPE__ __mlibc_intmax; +typedef __INTPTR_TYPE__ __mlibc_intptr; typedef __PTRDIFF_TYPE__ __mlibc_ptrdiff; #define __MLIBC_INTMAX_MAX __INTMAX_MAX__ #define __MLIBC_INTMAX_MIN (-__INTMAX_MAX__ - 1) @@ -348,7 +348,7 @@ typedef __PTRDIFF_TYPE__ __mlibc_ptrdiff; typedef __UINTMAX_TYPE__ __mlibc_uintmax; typedef __UINTPTR_TYPE__ __mlibc_uintptr; -typedef __SIZE_TYPE__ __mlibc_size; +typedef __SIZE_TYPE__ __mlibc_size; #define __MLIBC_UINTMAX_MAX __UINTMAX_MAX__ #define __MLIBC_UINTPTR_MAX __UINTPTR_MAX__ #define __MLIBC_SIZE_MAX __SIZE_MAX__ @@ -369,24 +369,23 @@ typedef __SIZE_TYPE__ __mlibc_size; /* ---------------------------------------------------------------------------- */ #if defined(__cplusplus) && defined(__cpp_static_assert) && __cpp_static_assert >= 200410L -# define __MLIBC_STATIC_ASSERT(c, text) static_assert(c, text) +#define __MLIBC_STATIC_ASSERT(c, text) static_assert(c, text) #elif !defined(__cplusplus) /* _Static_assert is an extension in C89/C99. */ -# define __MLIBC_STATIC_ASSERT(c, text) __extension__ _Static_assert(c, text) +#define __MLIBC_STATIC_ASSERT(c, text) __extension__ _Static_assert(c, text) #else -# define __MLIBC_STATIC_ASSERT(c, text) extern int __static_assert_unavailable +#define __MLIBC_STATIC_ASSERT(c, text) extern int __static_assert_unavailable #endif -#define __MLIBC_CHECK_TYPE(T1, T2) __MLIBC_STATIC_ASSERT(sizeof(T1) == sizeof(T2),\ - #T1 " != " #T2) +#define __MLIBC_CHECK_TYPE(T1, T2) __MLIBC_STATIC_ASSERT(sizeof(T1) == sizeof(T2), #T1 " != " #T2) /* Least-width. */ -__MLIBC_CHECK_TYPE(__mlibc_int8, __INT_LEAST8_TYPE__); +__MLIBC_CHECK_TYPE(__mlibc_int8, __INT_LEAST8_TYPE__); __MLIBC_CHECK_TYPE(__mlibc_int16, __INT_LEAST16_TYPE__); __MLIBC_CHECK_TYPE(__mlibc_int32, __INT_LEAST32_TYPE__); __MLIBC_CHECK_TYPE(__mlibc_int64, __INT_LEAST64_TYPE__); -__MLIBC_CHECK_TYPE(__mlibc_uint8, __UINT_LEAST8_TYPE__); +__MLIBC_CHECK_TYPE(__mlibc_uint8, __UINT_LEAST8_TYPE__); __MLIBC_CHECK_TYPE(__mlibc_uint16, __UINT_LEAST16_TYPE__); __MLIBC_CHECK_TYPE(__mlibc_uint32, __UINT_LEAST32_TYPE__); __MLIBC_CHECK_TYPE(__mlibc_uint64, __UINT_LEAST64_TYPE__); @@ -394,15 +393,15 @@ __MLIBC_CHECK_TYPE(__mlibc_uint64, __UINT_LEAST64_TYPE__); /* Fast-width. */ /* Unfortunately, GCC and Clang disagree about fast types. */ #ifndef __clang__ - __MLIBC_CHECK_TYPE(__mlibc_int_fast8, __INT_FAST8_TYPE__); - __MLIBC_CHECK_TYPE(__mlibc_int_fast16, __INT_FAST16_TYPE__); - __MLIBC_CHECK_TYPE(__mlibc_int_fast32, __INT_FAST32_TYPE__); - __MLIBC_CHECK_TYPE(__mlibc_int_fast64, __INT_FAST64_TYPE__); - - __MLIBC_CHECK_TYPE(__mlibc_uint_fast8, __UINT_FAST8_TYPE__); - __MLIBC_CHECK_TYPE(__mlibc_uint_fast16, __UINT_FAST16_TYPE__); - __MLIBC_CHECK_TYPE(__mlibc_uint_fast32, __UINT_FAST32_TYPE__); - __MLIBC_CHECK_TYPE(__mlibc_uint_fast64, __UINT_FAST64_TYPE__); +__MLIBC_CHECK_TYPE(__mlibc_int_fast8, __INT_FAST8_TYPE__); +__MLIBC_CHECK_TYPE(__mlibc_int_fast16, __INT_FAST16_TYPE__); +__MLIBC_CHECK_TYPE(__mlibc_int_fast32, __INT_FAST32_TYPE__); +__MLIBC_CHECK_TYPE(__mlibc_int_fast64, __INT_FAST64_TYPE__); + +__MLIBC_CHECK_TYPE(__mlibc_uint_fast8, __UINT_FAST8_TYPE__); +__MLIBC_CHECK_TYPE(__mlibc_uint_fast16, __UINT_FAST16_TYPE__); +__MLIBC_CHECK_TYPE(__mlibc_uint_fast32, __UINT_FAST32_TYPE__); +__MLIBC_CHECK_TYPE(__mlibc_uint_fast64, __UINT_FAST64_TYPE__); #endif #endif /* _MLIBC_INTERNAL_TYPES_H */ diff --git a/options/internal/include/mlibc/tcb.hpp b/options/internal/include/mlibc/tcb.hpp index 90cfab6779..25ba7615c4 100644 --- a/options/internal/include/mlibc/tcb.hpp +++ b/options/internal/include/mlibc/tcb.hpp @@ -1,9 +1,9 @@ #pragma once -#include -#include #include #include +#include +#include #include "elf.hpp" @@ -34,52 +34,49 @@ */ namespace { - // Set when the cancellation is enabled - constexpr unsigned int tcbCancelEnableBit = 1 << 0; - // 1 - cancellation is asynchronous, 0 - cancellation is deferred - constexpr unsigned int tcbCancelAsyncBit = 1 << 1; - // Set when the thread has been cancelled - constexpr unsigned int tcbCancelTriggerBit = 1 << 2; - // Set when the thread is in the process of being cancelled. - constexpr unsigned int tcbCancelingBit = 1 << 3; - // Set when the thread is exiting. - constexpr unsigned int tcbExitingBit = 1 << 4; -} +// Set when the cancellation is enabled +constexpr unsigned int tcbCancelEnableBit = 1 << 0; +// 1 - cancellation is asynchronous, 0 - cancellation is deferred +constexpr unsigned int tcbCancelAsyncBit = 1 << 1; +// Set when the thread has been cancelled +constexpr unsigned int tcbCancelTriggerBit = 1 << 2; +// Set when the thread is in the process of being cancelled. +constexpr unsigned int tcbCancelingBit = 1 << 3; +// Set when the thread is exiting. +constexpr unsigned int tcbExitingBit = 1 << 4; +} // namespace namespace mlibc { - // Returns true when bitmask indicates thread has been asynchronously - // cancelled. - static constexpr bool tcb_async_cancelled(int value) { - return (value & (tcbCancelEnableBit | tcbCancelAsyncBit - | tcbCancelTriggerBit)) == (tcbCancelEnableBit - | tcbCancelAsyncBit | tcbCancelTriggerBit); - } +// Returns true when bitmask indicates thread has been asynchronously +// cancelled. +static constexpr bool tcb_async_cancelled(int value) { + return (value & (tcbCancelEnableBit | tcbCancelAsyncBit | tcbCancelTriggerBit)) + == (tcbCancelEnableBit | tcbCancelAsyncBit | tcbCancelTriggerBit); +} - // Returns true when bitmask indicates async cancellation is enabled. - static constexpr bool tcb_async_cancel(int value) { - return (value & (tcbCancelEnableBit | tcbCancelAsyncBit)) - == (tcbCancelEnableBit | tcbCancelAsyncBit); - } +// Returns true when bitmask indicates async cancellation is enabled. +static constexpr bool tcb_async_cancel(int value) { + return (value & (tcbCancelEnableBit | tcbCancelAsyncBit)) + == (tcbCancelEnableBit | tcbCancelAsyncBit); +} - // Returns true when bitmask indicates cancellation is enabled. - static constexpr bool tcb_cancel_enabled(int value) { - return (value & tcbCancelEnableBit); - } +// Returns true when bitmask indicates cancellation is enabled. +static constexpr bool tcb_cancel_enabled(int value) { return (value & tcbCancelEnableBit); } - // Returns true when bitmask indicates threas has been cancelled. - static constexpr bool tcb_cancelled(int value) { - return (value & (tcbCancelEnableBit | tcbCancelTriggerBit)) - == (tcbCancelEnableBit | tcbCancelTriggerBit); - } +// Returns true when bitmask indicates threas has been cancelled. +static constexpr bool tcb_cancelled(int value) { + return (value & (tcbCancelEnableBit | tcbCancelTriggerBit)) + == (tcbCancelEnableBit | tcbCancelTriggerBit); +} #if !MLIBC_STATIC_BUILD && !MLIBC_BUILDING_RTLD - // In non-static builds, libc.so always has a TCB available. - constexpr bool tcb_available_flag = true; +// In non-static builds, libc.so always has a TCB available. +constexpr bool tcb_available_flag = true; #else - // Otherwise this will be set to true after RTLD has initialized the TCB. - extern bool tcb_available_flag; +// Otherwise this will be set to true after RTLD has initialized the TCB. +extern bool tcb_available_flag; #endif -} +} // namespace mlibc enum class TcbThreadReturnValue { Pointer, @@ -139,7 +136,7 @@ struct Tcb { size_t guardSize; inline void invokeThreadFunc(void *entry, void *user_arg) { - if(returnValueType == TcbThreadReturnValue::Pointer) { + if (returnValueType == TcbThreadReturnValue::Pointer) { auto func = reinterpret_cast(entry); returnValue.voidPtr = func(user_arg); } else { @@ -177,7 +174,7 @@ static_assert(sizeof(Tcb) - offsetof(Tcb, cancelBits) - TP_TCB_OFFSET == 80); // sysdeps/linux/riscv64/cp_syscall.S needs to be updated whenever // the struct is expanded. static_assert(sizeof(Tcb) - offsetof(Tcb, cancelBits) == 96); -#elif defined (__m68k__) +#elif defined(__m68k__) // The thread pointer on m68k points to 0x7000 bytes *after* the end of the // TCB, so similarly to as on RISC-V, we need to keep the value in // sysdeps/linux/m68k/cp_syscall.S up-to-date. diff --git a/options/rtld/generic/linker.cpp b/options/rtld/generic/linker.cpp index 33cd1b93c8..ef17a731cf 100644 --- a/options/rtld/generic/linker.cpp +++ b/options/rtld/generic/linker.cpp @@ -4,19 +4,18 @@ // keep a list of optional generic relocation types enum { - R_OFFSET = (uintptr_t) -1, + R_OFFSET = (uintptr_t)-1, }; - +#include #include #include +#include #include #include -#include #include +#include #include -#include -#include #include "elf.hpp" #include "linker.hpp" @@ -49,13 +48,15 @@ constexpr inline ptrdiff_t tlsOffsetFromTp = -0x7000; constexpr inline bool tlsAboveTp = true; constexpr inline uintptr_t tlsOffsetFromTp = 0; #else -# error Unknown architecture +#error Unknown architecture #endif extern DebugInterface globalDebugInterface; extern uintptr_t __stack_chk_guard; -extern frg::manual_box> libraryPaths; +extern frg::manual_box< + frg::small_vector> + libraryPaths; extern frg::manual_box> preloads; #if MLIBC_STATIC_BUILD @@ -84,10 +85,9 @@ bool trySeek(int fd, int64_t offset) { bool tryReadExactly(int fd, void *data, size_t length) { size_t offset = 0; - while(offset < length) { + while (offset < length) { ssize_t chunk; - if(mlibc::sys_read(fd, reinterpret_cast(data) + offset, - length - offset, &chunk)) + if (mlibc::sys_read(fd, reinterpret_cast(data) + offset, length - offset, &chunk)) return false; __ensure(chunk > 0); offset += chunk; @@ -97,13 +97,11 @@ bool tryReadExactly(int fd, void *data, size_t length) { } void closeOrDie(int fd) { - if(mlibc::sys_close(fd)) + if (mlibc::sys_close(fd)) __ensure(!"sys_close() failed"); } -uintptr_t alignUp(uintptr_t address, size_t align) { - return (address + align - 1) & ~(align - 1); -} +uintptr_t alignUp(uintptr_t address, size_t align) { return (address + align - 1) & ~(align - 1); } // -------------------------------------------------------- // ObjectRepository @@ -111,17 +109,22 @@ uintptr_t alignUp(uintptr_t address, size_t align) { ObjectRepository::ObjectRepository() : loadedObjects{getAllocator()}, - dependencyQueue{getAllocator()}, - _nameMap{frg::hash{}, getAllocator()}, - _destructQueue{getAllocator()} {} - -SharedObject *ObjectRepository::injectObjectFromDts(frg::string_view name, - frg::string path, uintptr_t base_address, - elf_dyn *dynamic, uint64_t rts) { + dependencyQueue{getAllocator()}, + _nameMap{frg::hash{}, getAllocator()}, + _destructQueue{getAllocator()} {} + +SharedObject *ObjectRepository::injectObjectFromDts( + frg::string_view name, + frg::string path, + uintptr_t base_address, + elf_dyn *dynamic, + uint64_t rts +) { __ensure(!findLoadedObject(name)); - auto object = frg::construct(getAllocator(), - name.data(), std::move(path), false, globalScope.get(), rts); + auto object = frg::construct( + getAllocator(), name.data(), std::move(path), false, globalScope.get(), rts + ); object->baseAddress = base_address; object->dynamic = dynamic; _parseDynamic(object); @@ -134,14 +137,20 @@ SharedObject *ObjectRepository::injectObjectFromDts(frg::string_view name, return object; } -SharedObject *ObjectRepository::injectObjectFromPhdrs(frg::string_view name, - frg::string path, void *phdr_pointer, - size_t phdr_entry_size, size_t num_phdrs, void *entry_pointer, - uint64_t rts) { +SharedObject *ObjectRepository::injectObjectFromPhdrs( + frg::string_view name, + frg::string path, + void *phdr_pointer, + size_t phdr_entry_size, + size_t num_phdrs, + void *entry_pointer, + uint64_t rts +) { __ensure(!findLoadedObject(name)); - auto object = frg::construct(getAllocator(), - name.data(), std::move(path), true, globalScope.get(), rts); + auto object = frg::construct( + getAllocator(), name.data(), std::move(path), true, globalScope.get(), rts + ); _fetchFromPhdrs(object, phdr_pointer, phdr_entry_size, num_phdrs, entry_pointer); _parseDynamic(object); _parseVerdef(object); @@ -153,25 +162,31 @@ SharedObject *ObjectRepository::injectObjectFromPhdrs(frg::string_view name, return object; } -SharedObject *ObjectRepository::injectStaticObject(frg::string_view name, - frg::string path, void *phdr_pointer, - size_t phdr_entry_size, size_t num_phdrs, void *entry_pointer, - uint64_t rts) { +SharedObject *ObjectRepository::injectStaticObject( + frg::string_view name, + frg::string path, + void *phdr_pointer, + size_t phdr_entry_size, + size_t num_phdrs, + void *entry_pointer, + uint64_t rts +) { __ensure(!findLoadedObject(name)); - auto object = frg::construct(getAllocator(), - name.data(), std::move(path), true, globalScope.get(), rts); + auto object = frg::construct( + getAllocator(), name.data(), std::move(path), true, globalScope.get(), rts + ); _fetchFromPhdrs(object, phdr_pointer, phdr_entry_size, num_phdrs, entry_pointer); #if MLIBC_STATIC_BUILD - object->initArray = reinterpret_cast(__init_array_start); - object->initArraySize = static_cast((uintptr_t)__init_array_end - - (uintptr_t)__init_array_start); - object->finiArray = reinterpret_cast(__fini_array_start); - object->finiArraySize = static_cast((uintptr_t)__fini_array_end - - (uintptr_t)__fini_array_start); - object->preInitArray = reinterpret_cast(__preinit_array_start); - object->preInitArraySize = static_cast((uintptr_t)__preinit_array_end - - (uintptr_t)__preinit_array_start); + object->initArray = reinterpret_cast(__init_array_start); + object->initArraySize = + static_cast((uintptr_t)__init_array_end - (uintptr_t)__init_array_start); + object->finiArray = reinterpret_cast(__fini_array_start); + object->finiArraySize = + static_cast((uintptr_t)__fini_array_end - (uintptr_t)__fini_array_start); + object->preInitArray = reinterpret_cast(__preinit_array_start); + object->preInitArraySize = + static_cast((uintptr_t)__preinit_array_end - (uintptr_t)__preinit_array_start); #endif _addLoadedObject(object); @@ -179,14 +194,15 @@ SharedObject *ObjectRepository::injectStaticObject(frg::string_view name, return object; } -frg::expected ObjectRepository::requestObjectWithName(frg::string_view name, - SharedObject *origin, Scope *localScope, bool createScope, uint64_t rts) { +frg::expected ObjectRepository::requestObjectWithName( + frg::string_view name, SharedObject *origin, Scope *localScope, bool createScope, uint64_t rts +) { if (auto obj = findLoadedObject(name)) return obj; - auto tryToOpen = [&] (const char *path) { + auto tryToOpen = [&](const char *path) { int fd; - if(auto x = mlibc::sys_open(path, O_RDONLY, 0, &fd); x) { + if (auto x = mlibc::sys_open(path, O_RDONLY, 0, &fd); x) { return -1; } return fd; @@ -194,8 +210,8 @@ frg::expected ObjectRepository::requestObjectWithNa // TODO(arsen): this process can probably undergo heavy optimization, by // preprocessing the rpath only once on parse - auto processRpath = [&] (frg::string_view path) { - frg::string sPath { getAllocator() }; + auto processRpath = [&](frg::string_view path) { + frg::string sPath{getAllocator()}; if (path.starts_with("$ORIGIN")) { frg::string_view dirname = origin->path; auto lastsl = dirname.find_last('/'); @@ -204,10 +220,10 @@ frg::expected ObjectRepository::requestObjectWithNa } else { dirname = "."; } - sPath = frg::string{ getAllocator(), dirname }; + sPath = frg::string{getAllocator(), dirname}; sPath += path.sub_string(7, path.size() - 7); } else { - sPath = frg::string{ getAllocator(), path }; + sPath = frg::string{getAllocator(), path}; } if (sPath[sPath.size() - 1] != '/') { sPath += '/'; @@ -218,16 +234,16 @@ frg::expected ObjectRepository::requestObjectWithNa int fd = tryToOpen(sPath.data()); if (logRpath && fd >= 0) mlibc::infoLogger() << "rtld: found in rpath" << frg::endlog; - return frg::tuple { fd, std::move(sPath) }; + return frg::tuple{fd, std::move(sPath)}; }; - frg::string chosenPath { getAllocator() }; + frg::string chosenPath{getAllocator()}; int fd = -1; if (origin && origin->runPath) { size_t start = 0; size_t idx = 0; - frg::string_view rpath { origin->runPath }; - auto next = [&] () { + frg::string_view rpath{origin->runPath}; + auto next = [&]() { idx = rpath.find_first(':', start); if (idx == (size_t)-1) idx = rpath.size(); @@ -254,18 +270,19 @@ frg::expected ObjectRepository::requestObjectWithNa mlibc::infoLogger() << "rtld: no rpath set for object" << frg::endlog; } - for(size_t i = 0; i < libraryPaths->size() && fd == -1; i++) { + for (size_t i = 0; i < libraryPaths->size() && fd == -1; i++) { auto ldPath = (*libraryPaths)[i]; auto path = frg::string{getAllocator(), ldPath} + '/' + name; - if(logLdPath) - mlibc::infoLogger() << "rtld: Trying to load " << name << " from ldpath " << ldPath << "/" << frg::endlog; + if (logLdPath) + mlibc::infoLogger() << "rtld: Trying to load " << name << " from ldpath " << ldPath + << "/" << frg::endlog; fd = tryToOpen(path.data()); - if(fd >= 0) { + if (fd >= 0) { chosenPath = std::move(path); break; } } - if(fd == -1) + if (fd == -1) return LinkerError::notFound; if (createScope) { @@ -277,12 +294,13 @@ frg::expected ObjectRepository::requestObjectWithNa __ensure(localScope != nullptr); - auto object = frg::construct(getAllocator(), - name.data(), std::move(chosenPath), false, localScope, rts); + auto object = frg::construct( + getAllocator(), name.data(), std::move(chosenPath), false, localScope, rts + ); auto result = _fetchFromFile(object, fd); closeOrDie(fd); - if(!result) { + if (!result) { frg::destruct(getAllocator(), object); return result.error(); } @@ -294,8 +312,9 @@ frg::expected ObjectRepository::requestObjectWithNa return object; } -frg::expected ObjectRepository::requestObjectAtPath(frg::string_view path, - Scope *localScope, bool createScope, uint64_t rts) { +frg::expected ObjectRepository::requestObjectAtPath( + frg::string_view path, Scope *localScope, bool createScope, uint64_t rts +) { // TODO: Support SONAME correctly. auto lastSlash = path.find_last('/') + 1; auto name = path; @@ -314,19 +333,20 @@ frg::expected ObjectRepository::requestObjectAtPath __ensure(localScope != nullptr); - auto object = frg::construct(getAllocator(), - name.data(), path.data(), false, localScope, rts); + auto object = frg::construct( + getAllocator(), name.data(), path.data(), false, localScope, rts + ); frg::string no_prefix(getAllocator(), path); int fd; - if(mlibc::sys_open((no_prefix + '\0').data(), O_RDONLY, 0, &fd)) { + if (mlibc::sys_open((no_prefix + '\0').data(), O_RDONLY, 0, &fd)) { frg::destruct(getAllocator(), object); return LinkerError::notFound; } auto result = _fetchFromFile(object, fd); closeOrDie(fd); - if(!result) { + if (!result) { frg::destruct(getAllocator(), object); return result.error(); } @@ -348,7 +368,7 @@ SharedObject *ObjectRepository::findCaller(void *addr) { for (auto [name, object] : _nameMap) { // Search all PT_LOAD segments for the specified address. - for(size_t j = 0; j < object->phdrCount; j++) { + for (size_t j = 0; j < object->phdrCount; j++) { auto phdr = (elf_phdr *)((uintptr_t)object->phdrPointer + j * object->phdrEntrySize); if (phdr->p_type == PT_LOAD) { uintptr_t start = object->baseAddress + phdr->p_vaddr; @@ -395,13 +415,18 @@ void ObjectRepository::destructObjects() { // ObjectRepository: Fetching methods. // -------------------------------------------------------- -void ObjectRepository::_fetchFromPhdrs(SharedObject *object, void *phdr_pointer, - size_t phdr_entry_size, size_t phdr_count, void *entry_pointer) { +void ObjectRepository::_fetchFromPhdrs( + SharedObject *object, + void *phdr_pointer, + size_t phdr_entry_size, + size_t phdr_count, + void *entry_pointer +) { __ensure(object->isMainObject); object->phdrPointer = phdr_pointer; object->phdrEntrySize = phdr_entry_size; object->phdrCount = phdr_count; - if(verbose) + if (verbose) mlibc::infoLogger() << "rtld: Loading " << object->name << frg::endlog; // Note: the entry pointer is absolute and not relative to the base address. @@ -411,74 +436,69 @@ void ObjectRepository::_fetchFromPhdrs(SharedObject *object, void *phdr_pointer, frg::optional tls_offset; // segments are already mapped, so we just have to find the dynamic section - for(size_t i = 0; i < phdr_count; i++) { + for (size_t i = 0; i < phdr_count; i++) { auto phdr = (elf_phdr *)((uintptr_t)phdr_pointer + i * phdr_entry_size); - switch(phdr->p_type) { - case PT_PHDR: - // Determine the executable's base address (in the PIE case) by comparing - // the PHDR segment's load address against it's address in the ELF file. - object->baseAddress = reinterpret_cast(phdr_pointer) - phdr->p_vaddr; - if(verbose) - mlibc::infoLogger() << "rtld: Executable is loaded at " - << (void *)object->baseAddress << frg::endlog; - break; - case PT_DYNAMIC: - dynamic_offset = phdr->p_vaddr; - break; - case PT_TLS: { - object->tlsSegmentSize = phdr->p_memsz; - object->tlsAlignment = phdr->p_align; - object->tlsImageSize = phdr->p_filesz; - tls_offset = phdr->p_vaddr; - break; - case PT_INTERP: - object->interpreterPath = frg::string{ - (char*)(object->baseAddress + phdr->p_vaddr), - getAllocator() - }; - } break; - default: - //FIXME warn about unknown phdrs - break; + switch (phdr->p_type) { + case PT_PHDR: + // Determine the executable's base address (in the PIE case) by comparing + // the PHDR segment's load address against it's address in the ELF file. + object->baseAddress = reinterpret_cast(phdr_pointer) - phdr->p_vaddr; + if (verbose) + mlibc::infoLogger() << "rtld: Executable is loaded at " + << (void *)object->baseAddress << frg::endlog; + break; + case PT_DYNAMIC: + dynamic_offset = phdr->p_vaddr; + break; + case PT_TLS: { + object->tlsSegmentSize = phdr->p_memsz; + object->tlsAlignment = phdr->p_align; + object->tlsImageSize = phdr->p_filesz; + tls_offset = phdr->p_vaddr; + break; + case PT_INTERP: + object->interpreterPath = frg::string{ + (char *)(object->baseAddress + phdr->p_vaddr), getAllocator() + }; + } break; + default: + // FIXME warn about unknown phdrs + break; } } - if(dynamic_offset) + if (dynamic_offset) object->dynamic = (elf_dyn *)(object->baseAddress + *dynamic_offset); - if(tls_offset) + if (tls_offset) object->tlsImagePtr = (void *)(object->baseAddress + *tls_offset); } - frg::expected ObjectRepository::_fetchFromFile(SharedObject *object, int fd) { __ensure(!object->isMainObject); // read the elf file header elf_ehdr ehdr; - if(!tryReadExactly(fd, &ehdr, sizeof(elf_ehdr))) + if (!tryReadExactly(fd, &ehdr, sizeof(elf_ehdr))) return LinkerError::fileTooShort; - if(ehdr.e_ident[0] != 0x7F - || ehdr.e_ident[1] != 'E' - || ehdr.e_ident[2] != 'L' - || ehdr.e_ident[3] != 'F') + if (ehdr.e_ident[0] != 0x7F || ehdr.e_ident[1] != 'E' || ehdr.e_ident[2] != 'L' + || ehdr.e_ident[3] != 'F') return LinkerError::notElf; - if((ehdr.e_type != ET_EXEC && ehdr.e_type != ET_DYN) - || ehdr.e_machine != ELF_MACHINE - || ehdr.e_ident[EI_CLASS] != ELF_CLASS) + if ((ehdr.e_type != ET_EXEC && ehdr.e_type != ET_DYN) || ehdr.e_machine != ELF_MACHINE + || ehdr.e_ident[EI_CLASS] != ELF_CLASS) return LinkerError::wrongElfType; // read the elf program headers auto phdr_buffer = (char *)getAllocator().allocate(ehdr.e_phnum * ehdr.e_phentsize); - if(!phdr_buffer) + if (!phdr_buffer) return LinkerError::outOfMemory; - if(!trySeek(fd, ehdr.e_phoff)) { + if (!trySeek(fd, ehdr.e_phoff)) { getAllocator().deallocate(phdr_buffer, ehdr.e_phnum * ehdr.e_phentsize); return LinkerError::invalidProgramHeader; } - if(!tryReadExactly(fd, phdr_buffer, ehdr.e_phnum * ehdr.e_phentsize)) { + if (!tryReadExactly(fd, phdr_buffer, ehdr.e_phnum * ehdr.e_phentsize)) { getAllocator().deallocate(phdr_buffer, ehdr.e_phnum * ehdr.e_phentsize); return LinkerError::invalidProgramHeader; } @@ -491,14 +511,14 @@ frg::expected ObjectRepository::_fetchFromFile(SharedObject * constexpr size_t hugeSize = 0x200000; uintptr_t highest_address = 0; - for(int i = 0; i < ehdr.e_phnum; i++) { + for (int i = 0; i < ehdr.e_phnum; i++) { auto phdr = (elf_phdr *)(phdr_buffer + i * ehdr.e_phentsize); - if(phdr->p_type != PT_LOAD) + if (phdr->p_type != PT_LOAD) continue; auto limit = phdr->p_vaddr + phdr->p_memsz; - if(limit > highest_address) + if (limit > highest_address) highest_address = limit; } @@ -509,14 +529,19 @@ frg::expected ObjectRepository::_fetchFromFile(SharedObject * #if MLIBC_MMAP_ALLOCATE_DSO void *mappedAddr = nullptr; - if (mlibc::sys_vm_map(nullptr, - highest_address - object->baseAddress, PROT_NONE, - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0, &mappedAddr)) { + if (mlibc::sys_vm_map( + nullptr, + highest_address - object->baseAddress, + PROT_NONE, + MAP_PRIVATE | MAP_ANONYMOUS, + -1, + 0, + &mappedAddr + )) { mlibc::infoLogger() << "sys_vm_map failed when allocating address space for DSO \"" - << object->name << "\"" - << ", base " << (void *)object->baseAddress - << ", requested " << (highest_address - object->baseAddress) << " bytes" - << frg::endlog; + << object->name << "\"" + << ", base " << (void *)object->baseAddress << ", requested " + << (highest_address - object->baseAddress) << " bytes" << frg::endlog; getAllocator().deallocate(phdr_buffer, ehdr.e_phnum * ehdr.e_phentsize); return LinkerError::outOfMemory; } @@ -527,18 +552,18 @@ frg::expected ObjectRepository::_fetchFromFile(SharedObject * libraryBase += (highest_address + (hugeSize - 1)) & ~(hugeSize - 1); #endif - if(verbose || logBaseAddresses) - mlibc::infoLogger() << "rtld: Loading " << object->name - << " at " << (void *)object->baseAddress << frg::endlog; + if (verbose || logBaseAddresses) + mlibc::infoLogger() << "rtld: Loading " << object->name << " at " + << (void *)object->baseAddress << frg::endlog; // Load all segments. constexpr size_t pageSize = 0x1000; - for(int i = 0; i < ehdr.e_phnum; i++) { + for (int i = 0; i < ehdr.e_phnum; i++) { auto phdr = (elf_phdr *)(phdr_buffer + i * ehdr.e_phentsize); - if(phdr->p_type == PT_LOAD) { + if (phdr->p_type == PT_LOAD) { size_t misalign = phdr->p_vaddr & (pageSize - 1); - if(!phdr->p_memsz) + if (!phdr->p_memsz) continue; __ensure(phdr->p_memsz >= phdr->p_filesz); @@ -552,78 +577,97 @@ frg::expected ObjectRepository::_fetchFromFile(SharedObject * auto initial_prot = PROT_READ | PROT_WRITE; int prot = 0; - if(phdr->p_flags & PF_R) + if (phdr->p_flags & PF_R) prot |= PROT_READ; - if(phdr->p_flags & PF_W) + if (phdr->p_flags & PF_W) prot |= PROT_WRITE; - if(phdr->p_flags & PF_X) + if (phdr->p_flags & PF_X) prot |= PROT_EXEC; - #if MLIBC_MAP_DSO_SEGMENTS +#if MLIBC_MAP_DSO_SEGMENTS // we can avoid the vm_protect call if we don't have to write to the segment - if(phdr->p_memsz == phdr->p_filesz) + if (phdr->p_memsz == phdr->p_filesz) initial_prot = prot; void *map_pointer; - if(mlibc::sys_vm_map(reinterpret_cast(map_address), - backed_map_size, initial_prot, - MAP_PRIVATE | MAP_FIXED, fd, phdr->p_offset - misalign, &map_pointer)) + if (mlibc::sys_vm_map( + reinterpret_cast(map_address), + backed_map_size, + initial_prot, + MAP_PRIVATE | MAP_FIXED, + fd, + phdr->p_offset - misalign, + &map_pointer + )) __ensure(!"sys_vm_map failed"); - if(total_map_size > backed_map_size) - if(mlibc::sys_vm_map(reinterpret_cast(map_address + backed_map_size), - total_map_size - backed_map_size, initial_prot, - MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, -1, 0, &map_pointer)) + if (total_map_size > backed_map_size) + if (mlibc::sys_vm_map( + reinterpret_cast(map_address + backed_map_size), + total_map_size - backed_map_size, + initial_prot, + MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, + -1, + 0, + &map_pointer + )) __ensure(!"sys_vm_map failed"); - if(mlibc::sys_vm_readahead) - if(mlibc::sys_vm_readahead(reinterpret_cast(map_address), - backed_map_size)) - mlibc::infoLogger() << "mlibc: sys_vm_readahead() failed in ld.so" - << frg::endlog; + if (mlibc::sys_vm_readahead) + if (mlibc::sys_vm_readahead(reinterpret_cast(map_address), backed_map_size)) + mlibc::infoLogger() + << "mlibc: sys_vm_readahead() failed in ld.so" << frg::endlog; // Clear the trailing area at the end of the backed mapping. // We do not clear the leading area; programs are not supposed to access it. - memset(reinterpret_cast(map_address + misalign + phdr->p_filesz), - 0, phdr->p_memsz - phdr->p_filesz); - #else + memset( + reinterpret_cast(map_address + misalign + phdr->p_filesz), + 0, + phdr->p_memsz - phdr->p_filesz + ); +#else (void)backed_map_size; void *map_pointer; - if(mlibc::sys_vm_map(reinterpret_cast(map_address), - total_map_size, initial_prot, - MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, -1, 0, &map_pointer)) + if (mlibc::sys_vm_map( + reinterpret_cast(map_address), + total_map_size, + initial_prot, + MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, + -1, + 0, + &map_pointer + )) __ensure(!"sys_vm_map failed"); __ensure(trySeek(fd, phdr->p_offset)); - __ensure(tryReadExactly(fd, reinterpret_cast(map_address) + misalign, - phdr->p_filesz)); - #endif - if(initial_prot != prot) { + __ensure( + tryReadExactly(fd, reinterpret_cast(map_address) + misalign, phdr->p_filesz) + ); +#endif + if (initial_prot != prot) { if (!mlibc::sys_vm_protect) __ensure(!"sys_vm_protect not provided"); - if (mlibc::sys_vm_protect(reinterpret_cast(map_address), total_map_size, prot)) + if (mlibc::sys_vm_protect( + reinterpret_cast(map_address), total_map_size, prot + )) __ensure(!"sys_vm_protect failed"); } - }else if(phdr->p_type == PT_TLS) { + } else if (phdr->p_type == PT_TLS) { object->tlsSegmentSize = phdr->p_memsz; object->tlsAlignment = phdr->p_align; object->tlsImageSize = phdr->p_filesz; object->tlsImagePtr = (void *)(object->baseAddress + phdr->p_vaddr); - }else if(phdr->p_type == PT_DYNAMIC) { + } else if (phdr->p_type == PT_DYNAMIC) { object->dynamic = (elf_dyn *)(object->baseAddress + phdr->p_vaddr); - }else if(phdr->p_type == PT_INTERP - || phdr->p_type == PT_PHDR - || phdr->p_type == PT_NOTE - || phdr->p_type == PT_RISCV_ATTRIBUTES - || phdr->p_type == PT_GNU_EH_FRAME - || phdr->p_type == PT_GNU_RELRO - || phdr->p_type == PT_GNU_STACK - || phdr->p_type == PT_GNU_PROPERTY) { + } else if (phdr->p_type == PT_INTERP || phdr->p_type == PT_PHDR || phdr->p_type == PT_NOTE + || phdr->p_type == PT_RISCV_ATTRIBUTES || phdr->p_type == PT_GNU_EH_FRAME + || phdr->p_type == PT_GNU_RELRO || phdr->p_type == PT_GNU_STACK + || phdr->p_type == PT_GNU_PROPERTY) { // ignore the phdr - }else{ - mlibc::panicLogger() << "Unexpected PHDR type 0x" - << frg::hex_fmt(phdr->p_type) << " in DSO " << object->name << frg::endlog; + } else { + mlibc::panicLogger() << "Unexpected PHDR type 0x" << frg::hex_fmt(phdr->p_type) + << " in DSO " << object->name << frg::endlog; } } @@ -635,9 +679,9 @@ frg::expected ObjectRepository::_fetchFromFile(SharedObject * // -------------------------------------------------------- void ObjectRepository::_parseDynamic(SharedObject *object) { - if(!object->dynamic) + if (!object->dynamic) mlibc::infoLogger() << "ldso: Object '" << object->name - << "' does not have a dynamic section" << frg::endlog; + << "' does not have a dynamic section" << frg::endlog; __ensure(object->dynamic); // Fix up these offsets to addresses after the loop, since the @@ -647,207 +691,214 @@ void ObjectRepository::_parseDynamic(SharedObject *object) { bool runpath_found = false; frg::optional soname_offset; - for(size_t i = 0; object->dynamic[i].d_tag != DT_NULL; i++) { + for (size_t i = 0; object->dynamic[i].d_tag != DT_NULL; i++) { elf_dyn *dynamic = &object->dynamic[i]; - switch(dynamic->d_tag) { - // handle hash table, symbol table and string table - case DT_HASH: - object->hashStyle = HashStyle::systemV; - object->hashTableOffset = dynamic->d_un.d_ptr; - break; - case DT_GNU_HASH: - object->hashStyle = HashStyle::gnu; - object->hashTableOffset = dynamic->d_un.d_ptr; - break; - case DT_STRTAB: - object->stringTableOffset = dynamic->d_un.d_ptr; - break; - case DT_STRSZ: - break; // we don't need the size of the string table - case DT_SYMTAB: - object->symbolTableOffset = dynamic->d_un.d_ptr; - break; - case DT_SYMENT: - __ensure(dynamic->d_un.d_val == sizeof(elf_sym)); - break; - // handle lazy relocation table - case DT_PLTGOT: - object->globalOffsetTable = (void **)(object->baseAddress - + dynamic->d_un.d_ptr); - break; - case DT_JMPREL: - object->lazyRelocTableOffset = dynamic->d_un.d_ptr; - break; - case DT_PLTRELSZ: - object->lazyTableSize = dynamic->d_un.d_val; - break; - case DT_PLTREL: - if(dynamic->d_un.d_val == DT_RELA) { - object->lazyExplicitAddend = true; - }else{ - __ensure(dynamic->d_un.d_val == DT_REL); - object->lazyExplicitAddend = false; - } - break; - // TODO: Implement this correctly! - case DT_SYMBOLIC: - object->symbolicResolution = true; - break; - case DT_BIND_NOW: - object->eagerBinding = true; - break; - case DT_FLAGS: { - if(dynamic->d_un.d_val & DF_SYMBOLIC) + switch (dynamic->d_tag) { + // handle hash table, symbol table and string table + case DT_HASH: + object->hashStyle = HashStyle::systemV; + object->hashTableOffset = dynamic->d_un.d_ptr; + break; + case DT_GNU_HASH: + object->hashStyle = HashStyle::gnu; + object->hashTableOffset = dynamic->d_un.d_ptr; + break; + case DT_STRTAB: + object->stringTableOffset = dynamic->d_un.d_ptr; + break; + case DT_STRSZ: + break; // we don't need the size of the string table + case DT_SYMTAB: + object->symbolTableOffset = dynamic->d_un.d_ptr; + break; + case DT_SYMENT: + __ensure(dynamic->d_un.d_val == sizeof(elf_sym)); + break; + // handle lazy relocation table + case DT_PLTGOT: + object->globalOffsetTable = (void **)(object->baseAddress + dynamic->d_un.d_ptr); + break; + case DT_JMPREL: + object->lazyRelocTableOffset = dynamic->d_un.d_ptr; + break; + case DT_PLTRELSZ: + object->lazyTableSize = dynamic->d_un.d_val; + break; + case DT_PLTREL: + if (dynamic->d_un.d_val == DT_RELA) { + object->lazyExplicitAddend = true; + } else { + __ensure(dynamic->d_un.d_val == DT_REL); + object->lazyExplicitAddend = false; + } + break; + // TODO: Implement this correctly! + case DT_SYMBOLIC: object->symbolicResolution = true; - if(dynamic->d_un.d_val & DF_STATIC_TLS) - object->haveStaticTls = true; - if(dynamic->d_un.d_val & DF_BIND_NOW) + break; + case DT_BIND_NOW: object->eagerBinding = true; - - auto ignored = DF_BIND_NOW | DF_SYMBOLIC | DF_STATIC_TLS; + break; + case DT_FLAGS: { + if (dynamic->d_un.d_val & DF_SYMBOLIC) + object->symbolicResolution = true; + if (dynamic->d_un.d_val & DF_STATIC_TLS) + object->haveStaticTls = true; + if (dynamic->d_un.d_val & DF_BIND_NOW) + object->eagerBinding = true; + + auto ignored = DF_BIND_NOW | DF_SYMBOLIC | DF_STATIC_TLS; #ifdef __riscv - // Work around https://sourceware.org/bugzilla/show_bug.cgi?id=24673. - ignored |= DF_TEXTREL; + // Work around https://sourceware.org/bugzilla/show_bug.cgi?id=24673. + ignored |= DF_TEXTREL; #else - if(dynamic->d_un.d_val & DF_TEXTREL) - mlibc::panicLogger() << "\e[31mrtld: DF_TEXTREL is unimplemented" << frg::endlog; + if (dynamic->d_un.d_val & DF_TEXTREL) + mlibc::panicLogger() + << "\e[31mrtld: DF_TEXTREL is unimplemented" << frg::endlog; #endif - if(dynamic->d_un.d_val & ~ignored) - mlibc::infoLogger() << "\e[31mrtld: DT_FLAGS(" << frg::hex_fmt{dynamic->d_un.d_val & ~ignored} - << ") is not implemented correctly!\e[39m" - << frg::endlog; - } break; - case DT_FLAGS_1: - if(dynamic->d_un.d_val & DF_1_NOW) - object->eagerBinding = true; - // The DF_1_PIE flag is informational only. It is used by e.g file(1). - // The DF_1_NODELETE flag has a similar effect to RTLD_NODELETE, both of which we - // ignore because we don't implement dlclose(). - if(dynamic->d_un.d_val & ~(DF_1_NOW | DF_1_PIE | DF_1_NODELETE)) - mlibc::infoLogger() << "\e[31mrtld: DT_FLAGS_1(" << frg::hex_fmt{dynamic->d_un.d_val} - << ") is not implemented correctly!\e[39m" - << frg::endlog; - break; - case DT_RPATH: - if (runpath_found) { - /* Ignore RPATH if RUNPATH was present. */ + if (dynamic->d_un.d_val & ~ignored) + mlibc::infoLogger() + << "\e[31mrtld: DT_FLAGS(" << frg::hex_fmt{dynamic->d_un.d_val & ~ignored} + << ") is not implemented correctly!\e[39m" << frg::endlog; + } break; + case DT_FLAGS_1: + if (dynamic->d_un.d_val & DF_1_NOW) + object->eagerBinding = true; + // The DF_1_PIE flag is informational only. It is used by e.g file(1). + // The DF_1_NODELETE flag has a similar effect to RTLD_NODELETE, both of which we + // ignore because we don't implement dlclose(). + if (dynamic->d_un.d_val & ~(DF_1_NOW | DF_1_PIE | DF_1_NODELETE)) + mlibc::infoLogger() + << "\e[31mrtld: DT_FLAGS_1(" << frg::hex_fmt{dynamic->d_un.d_val} + << ") is not implemented correctly!\e[39m" << frg::endlog; break; - } - [[fallthrough]]; - case DT_RUNPATH: - runpath_found = dynamic->d_tag == DT_RUNPATH; - runpath_offset = dynamic->d_un.d_val; - break; - case DT_INIT: - if(dynamic->d_un.d_ptr != 0) - object->initPtr = (InitFuncPtr)(object->baseAddress + dynamic->d_un.d_ptr); - break; - case DT_FINI: - if(dynamic->d_un.d_ptr != 0) - object->finiPtr = (InitFuncPtr)(object->baseAddress + dynamic->d_un.d_ptr); - break; - case DT_INIT_ARRAY: - if(dynamic->d_un.d_ptr != 0) - object->initArray = (InitFuncPtr *)(object->baseAddress + dynamic->d_un.d_ptr); - break; - case DT_FINI_ARRAY: - if(dynamic->d_un.d_ptr != 0) - object->finiArray = (InitFuncPtr *)(object->baseAddress + dynamic->d_un.d_ptr); - break; - case DT_INIT_ARRAYSZ: - object->initArraySize = dynamic->d_un.d_val; - break; - case DT_FINI_ARRAYSZ: - object->finiArraySize = dynamic->d_un.d_val; - break; - case DT_PREINIT_ARRAY: - if(dynamic->d_un.d_ptr != 0) { + case DT_RPATH: + if (runpath_found) { + /* Ignore RPATH if RUNPATH was present. */ + break; + } + [[fallthrough]]; + case DT_RUNPATH: + runpath_found = dynamic->d_tag == DT_RUNPATH; + runpath_offset = dynamic->d_un.d_val; + break; + case DT_INIT: + if (dynamic->d_un.d_ptr != 0) + object->initPtr = (InitFuncPtr)(object->baseAddress + dynamic->d_un.d_ptr); + break; + case DT_FINI: + if (dynamic->d_un.d_ptr != 0) + object->finiPtr = (InitFuncPtr)(object->baseAddress + dynamic->d_un.d_ptr); + break; + case DT_INIT_ARRAY: + if (dynamic->d_un.d_ptr != 0) + object->initArray = (InitFuncPtr *)(object->baseAddress + dynamic->d_un.d_ptr); + break; + case DT_FINI_ARRAY: + if (dynamic->d_un.d_ptr != 0) + object->finiArray = (InitFuncPtr *)(object->baseAddress + dynamic->d_un.d_ptr); + break; + case DT_INIT_ARRAYSZ: + object->initArraySize = dynamic->d_un.d_val; + break; + case DT_FINI_ARRAYSZ: + object->finiArraySize = dynamic->d_un.d_val; + break; + case DT_PREINIT_ARRAY: + if (dynamic->d_un.d_ptr != 0) { + // Only the main object is allowed pre-initializers. + __ensure(object->isMainObject); + object->preInitArray = + (InitFuncPtr *)(object->baseAddress + dynamic->d_un.d_ptr); + } + break; + case DT_PREINIT_ARRAYSZ: // Only the main object is allowed pre-initializers. __ensure(object->isMainObject); - object->preInitArray = (InitFuncPtr *)(object->baseAddress + dynamic->d_un.d_ptr); - } - break; - case DT_PREINIT_ARRAYSZ: - // Only the main object is allowed pre-initializers. - __ensure(object->isMainObject); - object->preInitArraySize = dynamic->d_un.d_val; - break; - case DT_DEBUG: + object->preInitArraySize = dynamic->d_un.d_val; + break; + case DT_DEBUG: #if ELF_CLASS == ELFCLASS32 - dynamic->d_un.d_val = reinterpret_cast(&globalDebugInterface); + dynamic->d_un.d_val = reinterpret_cast(&globalDebugInterface); #elif ELF_CLASS == ELFCLASS64 - dynamic->d_un.d_val = reinterpret_cast(&globalDebugInterface); + dynamic->d_un.d_val = reinterpret_cast(&globalDebugInterface); #endif - break; - case DT_SONAME: - soname_offset = dynamic->d_un.d_val; - break; - // handle version information - case DT_VERSYM: - object->versionTableOffset = dynamic->d_un.d_ptr; - break; - case DT_VERDEF: - object->versionDefinitionTableOffset = dynamic->d_un.d_ptr; - break; - case DT_VERDEFNUM: - object->versionDefinitionCount = dynamic->d_un.d_val; - break; - case DT_VERNEED: - object->versionRequirementTableOffset = dynamic->d_un.d_ptr; - break; - case DT_VERNEEDNUM: - object->versionRequirementCount = dynamic->d_un.d_val; - break; - // ignore unimportant tags - case DT_NEEDED: // we handle this later - case DT_RELA: case DT_RELASZ: case DT_RELAENT: case DT_RELACOUNT: - case DT_REL: case DT_RELSZ: case DT_RELENT: case DT_RELCOUNT: - case DT_RELR: case DT_RELRSZ: case DT_RELRENT: + break; + case DT_SONAME: + soname_offset = dynamic->d_un.d_val; + break; + // handle version information + case DT_VERSYM: + object->versionTableOffset = dynamic->d_un.d_ptr; + break; + case DT_VERDEF: + object->versionDefinitionTableOffset = dynamic->d_un.d_ptr; + break; + case DT_VERDEFNUM: + object->versionDefinitionCount = dynamic->d_un.d_val; + break; + case DT_VERNEED: + object->versionRequirementTableOffset = dynamic->d_un.d_ptr; + break; + case DT_VERNEEDNUM: + object->versionRequirementCount = dynamic->d_un.d_val; + break; + // ignore unimportant tags + case DT_NEEDED: // we handle this later + case DT_RELA: + case DT_RELASZ: + case DT_RELAENT: + case DT_RELACOUNT: + case DT_REL: + case DT_RELSZ: + case DT_RELENT: + case DT_RELCOUNT: + case DT_RELR: + case DT_RELRSZ: + case DT_RELRENT: #ifdef __riscv - case DT_TEXTREL: // Work around https://sourceware.org/bugzilla/show_bug.cgi?id=24673. + case DT_TEXTREL: // Work around https://sourceware.org/bugzilla/show_bug.cgi?id=24673. #endif - break; - case DT_TLSDESC_PLT: case DT_TLSDESC_GOT: - break; - default: - // Ignore unknown entries in the os-specific area as we don't use them. - if(dynamic->d_tag < DT_LOOS || dynamic->d_tag > DT_HIOS) { - mlibc::panicLogger() << "Unexpected dynamic entry " - << (void *)dynamic->d_tag << " in object" << frg::endlog; - } + break; + case DT_TLSDESC_PLT: + case DT_TLSDESC_GOT: + break; + default: + // Ignore unknown entries in the os-specific area as we don't use them. + if (dynamic->d_tag < DT_LOOS || dynamic->d_tag > DT_HIOS) { + mlibc::panicLogger() << "Unexpected dynamic entry " << (void *)dynamic->d_tag + << " in object" << frg::endlog; + } } } - if(runpath_offset) { - object->runPath = reinterpret_cast(object->baseAddress - + object->stringTableOffset + *runpath_offset); + if (runpath_offset) { + object->runPath = reinterpret_cast( + object->baseAddress + object->stringTableOffset + *runpath_offset + ); } - if(soname_offset) { - object->soName = reinterpret_cast(object->baseAddress - + object->stringTableOffset + *soname_offset); + if (soname_offset) { + object->soName = reinterpret_cast( + object->baseAddress + object->stringTableOffset + *soname_offset + ); } } void ObjectRepository::_parseVerdef(SharedObject *object) { - if(!object->versionDefinitionTableOffset) { - if(verbose) - mlibc::infoLogger() - << "mlibc: Object " << object->name - << " defines no versions" << frg::endlog; + if (!object->versionDefinitionTableOffset) { + if (verbose) + mlibc::infoLogger() << "mlibc: Object " << object->name << " defines no versions" + << frg::endlog; return; } - if(verbose) - mlibc::infoLogger() - << "mlibc: Object " << object->name - << " defines " << object->versionDefinitionCount - << " version(s)" << frg::endlog; + if (verbose) + mlibc::infoLogger() << "mlibc: Object " << object->name << " defines " + << object->versionDefinitionCount << " version(s)" << frg::endlog; - uintptr_t address = - object->baseAddress - + object->versionDefinitionTableOffset; + uintptr_t address = object->baseAddress + object->versionDefinitionTableOffset; - for(size_t i = 0; i < object->versionDefinitionCount; i++) { + for (size_t i = 0; i < object->versionDefinitionCount; i++) { elf_verdef def; memcpy(&def, reinterpret_cast(address), sizeof(elf_verdef)); @@ -861,19 +912,15 @@ void ObjectRepository::_parseVerdef(SharedObject *object) { elf_verdaux aux; memcpy(&aux, reinterpret_cast(address + def.vd_aux), sizeof(elf_verdaux)); - const char *name = - reinterpret_cast( - object->baseAddress - + object->stringTableOffset + aux.vda_name); + const char *name = reinterpret_cast( + object->baseAddress + object->stringTableOffset + aux.vda_name + ); - if(verbose) - mlibc::infoLogger() - << "mlibc: Object " << object->name - << " defines version " << name - << " (index " << def.vd_ndx << ")" - << frg::endlog; + if (verbose) + mlibc::infoLogger() << "mlibc: Object " << object->name << " defines version " << name + << " (index " << def.vd_ndx << ")" << frg::endlog; - if(!(def.vd_flags & VER_FLG_BASE)) { + if (!(def.vd_flags & VER_FLG_BASE)) { SymbolVersion ver{name, def.vd_hash}; object->definedVersions.push(ver); object->knownVersions.insert(def.vd_ndx, ver); @@ -884,100 +931,87 @@ void ObjectRepository::_parseVerdef(SharedObject *object) { } void ObjectRepository::_parseVerneed(SharedObject *object) { - if(!object->versionRequirementTableOffset) { - if(verbose) - mlibc::infoLogger() << "mlibc: Object " << object->name << " requires no versions" << frg::endlog; + if (!object->versionRequirementTableOffset) { + if (verbose) + mlibc::infoLogger() << "mlibc: Object " << object->name << " requires no versions" + << frg::endlog; return; } - if(verbose) - mlibc::infoLogger() - << "mlibc: Object " << object->name - << " requires " << object->versionRequirementCount - << " version(s)" << frg::endlog; + if (verbose) + mlibc::infoLogger() << "mlibc: Object " << object->name << " requires " + << object->versionRequirementCount << " version(s)" << frg::endlog; - uintptr_t address = - object->baseAddress - + object->versionRequirementTableOffset; + uintptr_t address = object->baseAddress + object->versionRequirementTableOffset; - for(size_t i = 0; i < object->versionRequirementCount; i++) { + for (size_t i = 0; i < object->versionRequirementCount; i++) { elf_verneed need; memcpy(&need, reinterpret_cast(address), sizeof(elf_verneed)); // Required by spec. __ensure(need.vn_version == 1); - frg::string_view file = - reinterpret_cast( - object->baseAddress - + object->stringTableOffset + need.vn_file); + frg::string_view file = reinterpret_cast( + object->baseAddress + object->stringTableOffset + need.vn_file + ); // Figure out the target object from file SharedObject *target = nullptr; - for(auto dep : object->dependencies) { - if(verbose) - mlibc::infoLogger() - << "mlibc: Trying " << dep->name << " (SONAME: " - << dep->soName << ") to satisfy " << file << frg::endlog; - if(dep->name == file || (dep->soName && dep->soName == file)) { + for (auto dep : object->dependencies) { + if (verbose) + mlibc::infoLogger() << "mlibc: Trying " << dep->name << " (SONAME: " << dep->soName + << ") to satisfy " << file << frg::endlog; + if (dep->name == file || (dep->soName && dep->soName == file)) { target = dep; break; } } - if(!target) - mlibc::panicLogger() - << "mlibc: No object named \"" - << file - << "\" found for VERNEED entry of object " - << object->name << frg::endlog; - - if(verbose) - mlibc::infoLogger() - << "mlibc: Object " << object->name - << " requires " << need.vn_cnt - << " version(s) from DSO " - << file << frg::endlog; + if (!target) + mlibc::panicLogger() << "mlibc: No object named \"" << file + << "\" found for VERNEED entry of object " << object->name + << frg::endlog; + + if (verbose) + mlibc::infoLogger() << "mlibc: Object " << object->name << " requires " << need.vn_cnt + << " version(s) from DSO " << file << frg::endlog; uintptr_t auxAddr = address + need.vn_aux; - for(size_t j = 0; j < need.vn_cnt; j++) { + for (size_t j = 0; j < need.vn_cnt; j++) { elf_vernaux aux; memcpy(&aux, reinterpret_cast(auxAddr), sizeof(elf_vernaux)); // TODO(qookie): Handle weak versions. __ensure(!aux.vna_flags); - const char *name = - reinterpret_cast( - object->baseAddress - + object->stringTableOffset + aux.vna_name); + const char *name = reinterpret_cast( + object->baseAddress + object->stringTableOffset + aux.vna_name + ); - if(verbose) + if (verbose) mlibc::infoLogger() - << "mlibc: Object " << object->name - << " requires version " << name - << " (index " << aux.vna_other - << ") from DSO " << file - << frg::endlog; + << "mlibc: Object " << object->name << " requires version " << name + << " (index " << aux.vna_other << ") from DSO " << file << frg::endlog; frg::optional ver; - for(auto &def : target->definedVersions) { - if(def.hash() != aux.vna_hash) continue; - if(def.name() == name) { + for (auto &def : target->definedVersions) { + if (def.hash() != aux.vna_hash) + continue; + if (def.name() == name) { ver = def; break; } } - if(!ver) + if (!ver) mlibc::panicLogger() - << "mlibc: Object " << target->name - << " does not define version \"" - << name << "\" needed by object " - << object->name << frg::endlog; + << "mlibc: Object " << target->name << " does not define version \"" << name + << "\" needed by object " << object->name << frg::endlog; bool isDefault = !(aux.vna_other & 0x8000); // Bit 15 indicates whether the static linker should ignore this version. - object->knownVersions.insert(aux.vna_other & 0x7FFF, isDefault ? ver->makeDefault() : *ver); + object->knownVersions.insert( + aux.vna_other & 0x7FFF, isDefault ? ver->makeDefault() : *ver + ); auxAddr += aux.vna_next; } @@ -985,20 +1019,20 @@ void ObjectRepository::_parseVerneed(SharedObject *object) { } } -void ObjectRepository::_discoverDependencies(SharedObject *object, - Scope *localScope, uint64_t rts) { - if(object->isMainObject) { - for(auto preload : *preloads) { +void +ObjectRepository::_discoverDependencies(SharedObject *object, Scope *localScope, uint64_t rts) { + if (object->isMainObject) { + for (auto preload : *preloads) { frg::expected libraryResult; if (preload.find_first('/') == size_t(-1)) { libraryResult = requestObjectWithName(preload, object, globalScope.get(), false, 1); } else { libraryResult = requestObjectAtPath(preload, globalScope.get(), false, 1); } - if(!libraryResult) + if (!libraryResult) mlibc::panicLogger() << "rtld: Could not load preload " << preload << frg::endlog; - if(verbose) + if (verbose) mlibc::infoLogger() << "rtld: Preloading " << preload << frg::endlog; auto library = libraryResult.value(); @@ -1011,17 +1045,17 @@ void ObjectRepository::_discoverDependencies(SharedObject *object, } // Load required dynamic libraries. - for(size_t i = 0; object->dynamic[i].d_tag != DT_NULL; i++) { + for (size_t i = 0; object->dynamic[i].d_tag != DT_NULL; i++) { elf_dyn *dynamic = &object->dynamic[i]; - if(dynamic->d_tag != DT_NEEDED) + if (dynamic->d_tag != DT_NEEDED) continue; - const char *library_str = (const char *)(object->baseAddress - + object->stringTableOffset + dynamic->d_un.d_val); + const char *library_str = + (const char *)(object->baseAddress + object->stringTableOffset + dynamic->d_un.d_val); - auto libraryResult = requestObjectWithName(frg::string_view{library_str}, - object, localScope, false, rts); - if(!libraryResult) + auto libraryResult = + requestObjectWithName(frg::string_view{library_str}, object, localScope, false, rts); + if (!libraryResult) mlibc::panicLogger() << "Could not satisfy dependency " << library_str << frg::endlog; auto library = libraryResult.value(); @@ -1042,50 +1076,76 @@ void ObjectRepository::_addLoadedObject(SharedObject *object) { // SharedObject // -------------------------------------------------------- -SharedObject::SharedObject(const char *name, frg::string path, - bool is_main_object, Scope *local_scope, uint64_t object_rts) - : name(name, getAllocator()), path(std::move(path)), - interpreterPath(getAllocator()), soName(nullptr), - isMainObject(is_main_object), objectRts(object_rts), inLinkMap(false), - baseAddress(0), localScope(local_scope), dynamic(nullptr), - globalOffsetTable(nullptr), entry(nullptr), tlsSegmentSize(0), - tlsAlignment(0), tlsImageSize(0), tlsImagePtr(nullptr), - tlsInitialized(false), hashTableOffset(0), symbolTableOffset(0), - stringTableOffset(0), - knownVersions({}, getAllocator()), definedVersions(getAllocator()), - lazyRelocTableOffset(0), lazyTableSize(0), - lazyExplicitAddend(false), symbolicResolution(false), - eagerBinding(false), haveStaticTls(false), - dependencies(getAllocator()), tlsModel(TlsModel::null), - tlsOffset(0), globalRts(0), wasLinked(false), - scheduledForInit(false), onInitStack(false), - wasInitialized(false) { } - -SharedObject::SharedObject(const char *name, const char *path, - bool is_main_object, Scope *localScope, uint64_t object_rts) - : SharedObject(name, - frg::string { path, getAllocator() }, - is_main_object, localScope, object_rts) {} +SharedObject::SharedObject( + const char *name, + frg::string path, + bool is_main_object, + Scope *local_scope, + uint64_t object_rts +) +: name(name, getAllocator()), + path(std::move(path)), + interpreterPath(getAllocator()), + soName(nullptr), + isMainObject(is_main_object), + objectRts(object_rts), + inLinkMap(false), + baseAddress(0), + localScope(local_scope), + dynamic(nullptr), + globalOffsetTable(nullptr), + entry(nullptr), + tlsSegmentSize(0), + tlsAlignment(0), + tlsImageSize(0), + tlsImagePtr(nullptr), + tlsInitialized(false), + hashTableOffset(0), + symbolTableOffset(0), + stringTableOffset(0), + knownVersions({}, getAllocator()), + definedVersions(getAllocator()), + lazyRelocTableOffset(0), + lazyTableSize(0), + lazyExplicitAddend(false), + symbolicResolution(false), + eagerBinding(false), + haveStaticTls(false), + dependencies(getAllocator()), + tlsModel(TlsModel::null), + tlsOffset(0), + globalRts(0), + wasLinked(false), + scheduledForInit(false), + onInitStack(false), + wasInitialized(false) {} + +SharedObject::SharedObject( + const char *name, const char *path, bool is_main_object, Scope *localScope, uint64_t object_rts +) +: SharedObject( + name, + frg::string{path, getAllocator()}, + is_main_object, + localScope, + object_rts + ) {} frg::tuple SharedObject::getSymbolByIndex(size_t index) { SymbolVersion ver{1}; // If we don't have any version information, treat all symbols as global. ObjectSymbol sym{ - this, - reinterpret_cast( - baseAddress - + symbolTableOffset - + index * sizeof(elf_sym))}; + this, reinterpret_cast(baseAddress + symbolTableOffset + index * sizeof(elf_sym)) + }; - if(versionTableOffset) { + if (versionTableOffset) { // Pull out the VERSYM entry for this symbol elf_version verIdx; memcpy( - &verIdx, - reinterpret_cast( - baseAddress - + versionTableOffset - + index * sizeof(elf_version)), - sizeof(elf_version) + &verIdx, + reinterpret_cast( + baseAddress + versionTableOffset + index * sizeof(elf_version) + ), + sizeof(elf_version) ); // Bit 15 indicates that this version is not the default one. @@ -1093,31 +1153,25 @@ frg::tuple SharedObject::getSymbolByIndex(size_t in verIdx &= 0x7FFF; // 0 and 1 are special, 0 is local, 1 is global (not in VERDEF/VERNEED) - if(verIdx != 0 && verIdx != 1) { + if (verIdx != 0 && verIdx != 1) { auto maybeVer = knownVersions.find(verIdx); - if(maybeVer == knownVersions.end()) - mlibc::panicLogger() - << "mlibc: Symbol " << sym.getString() - << " of object " << name - << " has invalid version index " << verIdx - << frg::endlog; + if (maybeVer == knownVersions.end()) + mlibc::panicLogger() << "mlibc: Symbol " << sym.getString() << " of object " << name + << " has invalid version index " << verIdx << frg::endlog; ver = maybeVer->get<1>(); } else { ver = SymbolVersion{verIdx}; } - if(isDefault) + if (isDefault) ver = ver.makeDefault(); - if(logSymbolVersions) - mlibc::infoLogger() - << "mlibc: Symbol " << sym.getString() - << " of object " << name - << " has version " << ver.name() - << " and " << (ver.isDefault() ? "is" : "isn't") - << " the default version" - << frg::endlog; + if (logSymbolVersions) + mlibc::infoLogger() << "mlibc: Symbol " << sym.getString() << " of object " << name + << " has version " << ver.name() << " and " + << (ver.isDefault() ? "is" : "isn't") << " the default version" + << frg::endlog; } else { // If we have no version information, the only symbol we've got is the default. ver = ver.makeDefault(); @@ -1129,37 +1183,44 @@ frg::tuple SharedObject::getSymbolByIndex(size_t in void processLateRelocation(Relocation rel) { // resolve the symbol if there is a symbol frg::optional p; - if(rel.symbol_index()) { + if (rel.symbol_index()) { auto [sym, ver] = rel.object()->getSymbolByIndex(rel.symbol_index()); - p = Scope::resolveGlobalOrLocal(*globalScope, rel.object()->localScope, - sym.getString(), rel.object()->objectRts, Scope::resolveCopy, ver); + p = Scope::resolveGlobalOrLocal( + *globalScope, + rel.object()->localScope, + sym.getString(), + rel.object()->objectRts, + Scope::resolveCopy, + ver + ); } - switch(rel.type()) { - case R_COPY: - __ensure(p); - memcpy(rel.destination(), (void *)p->virtualAddress(), p->symbol()->st_size); - break; + switch (rel.type()) { + case R_COPY: + __ensure(p); + memcpy(rel.destination(), (void *)p->virtualAddress(), p->symbol()->st_size); + break; -// TODO: R_IRELATIVE also exists on other architectures but will likely need a different implementation. +// TODO: R_IRELATIVE also exists on other architectures but will likely need a different +// implementation. #if defined(__x86_64__) || defined(__i386__) - case R_IRELATIVE: { - uintptr_t addr = rel.object()->baseAddress + rel.addend_rel(); - auto* fn = reinterpret_cast(addr); - rel.relocate(fn()); - } break; + case R_IRELATIVE: { + uintptr_t addr = rel.object()->baseAddress + rel.addend_rel(); + auto *fn = reinterpret_cast(addr); + rel.relocate(fn()); + } break; #elif defined(__aarch64__) - case R_IRELATIVE: { - uintptr_t addr = rel.object()->baseAddress + rel.addend_rel(); - auto* fn = reinterpret_cast(addr); - // TODO: the function should get passed AT_HWCAP value. - rel.relocate(fn(0)); - } break; + case R_IRELATIVE: { + uintptr_t addr = rel.object()->baseAddress + rel.addend_rel(); + auto *fn = reinterpret_cast(addr); + // TODO: the function should get passed AT_HWCAP value. + rel.relocate(fn(0)); + } break; #endif - default: - break; + default: + break; } } @@ -1170,44 +1231,44 @@ void processLateRelocations(SharedObject *object) { frg::optional rela_offset; frg::optional rela_length; - for(size_t i = 0; object->dynamic[i].d_tag != DT_NULL; i++) { + for (size_t i = 0; object->dynamic[i].d_tag != DT_NULL; i++) { elf_dyn *dynamic = &object->dynamic[i]; - switch(dynamic->d_tag) { - case DT_REL: - rel_offset = dynamic->d_un.d_ptr; - break; - case DT_RELSZ: - rel_length = dynamic->d_un.d_val; - break; - case DT_RELENT: - __ensure(dynamic->d_un.d_val == sizeof(elf_rel)); - break; - case DT_RELA: - rela_offset = dynamic->d_un.d_ptr; - break; - case DT_RELASZ: - rela_length = dynamic->d_un.d_val; - break; - case DT_RELAENT: - __ensure(dynamic->d_un.d_val == sizeof(elf_rela)); - break; + switch (dynamic->d_tag) { + case DT_REL: + rel_offset = dynamic->d_un.d_ptr; + break; + case DT_RELSZ: + rel_length = dynamic->d_un.d_val; + break; + case DT_RELENT: + __ensure(dynamic->d_un.d_val == sizeof(elf_rel)); + break; + case DT_RELA: + rela_offset = dynamic->d_un.d_ptr; + break; + case DT_RELASZ: + rela_length = dynamic->d_un.d_val; + break; + case DT_RELAENT: + __ensure(dynamic->d_un.d_val == sizeof(elf_rela)); + break; } } - if(rela_offset && rela_length) { - for(size_t offset = 0; offset < *rela_length; offset += sizeof(elf_rela)) { + if (rela_offset && rela_length) { + for (size_t offset = 0; offset < *rela_length; offset += sizeof(elf_rela)) { auto reloc = (elf_rela *)(object->baseAddress + *rela_offset + offset); auto r = Relocation(object, reloc); processLateRelocation(r); } - } else if(rel_offset && rel_length) { - for(size_t offset = 0; offset < *rel_length; offset += sizeof(elf_rel)) { + } else if (rel_offset && rel_length) { + for (size_t offset = 0; offset < *rel_length; offset += sizeof(elf_rel)) { auto reloc = (elf_rel *)(object->baseAddress + *rel_offset + offset); auto r = Relocation(object, reloc); processLateRelocation(r); } - }else{ + } else { __ensure(!rela_offset && !rela_length); __ensure(!rel_offset && !rel_length); } @@ -1217,44 +1278,44 @@ void doInitialize(SharedObject *object) { __ensure(object->wasLinked); __ensure(!object->wasInitialized); - if(verbose) + if (verbose) mlibc::infoLogger() << "rtld: Initialize " << object->name << frg::endlog; - if(verbose) + if (verbose) mlibc::infoLogger() << "rtld: Running DT_INIT function" << frg::endlog; - if(object->initPtr != nullptr) + if (object->initPtr != nullptr) object->initPtr(); - if(verbose) + if (verbose) mlibc::infoLogger() << "rtld: Running DT_INIT_ARRAY functions" << frg::endlog; __ensure((object->initArraySize % sizeof(InitFuncPtr)) == 0); - for(size_t i = 0; i < object->initArraySize / sizeof(InitFuncPtr); i++) + for (size_t i = 0; i < object->initArraySize / sizeof(InitFuncPtr); i++) object->initArray[i](); - if(verbose) + if (verbose) mlibc::infoLogger() << "rtld: Object initialization complete" << frg::endlog; object->wasInitialized = true; } void doDestruct(SharedObject *object) { - if(!object->wasInitialized || object->wasDestroyed) + if (!object->wasInitialized || object->wasDestroyed) return; - if(verbose) + if (verbose) mlibc::infoLogger() << "rtld: Destruct " << object->name << frg::endlog; - if(verbose) + if (verbose) mlibc::infoLogger() << "rtld: Running DT_FINI_ARRAY functions" << frg::endlog; __ensure((object->finiArraySize % sizeof(InitFuncPtr)) == 0); - for(size_t i = object->finiArraySize / sizeof(InitFuncPtr); i > 0; i--) + for (size_t i = object->finiArraySize / sizeof(InitFuncPtr); i > 0; i--) object->finiArray[i - 1](); - if(verbose) + if (verbose) mlibc::infoLogger() << "rtld: Running DT_FINI function" << frg::endlog; - if(object->finiPtr != nullptr) + if (object->finiPtr != nullptr) object->finiPtr(); - if(verbose) + if (verbose) mlibc::infoLogger() << "rtld: Object destruction complete" << frg::endlog; object->wasDestroyed = true; } @@ -1263,14 +1324,15 @@ void doDestruct(SharedObject *object) { // RuntimeTlsMap // -------------------------------------------------------- -RuntimeTlsMap::RuntimeTlsMap() -: initialPtr{0}, initialLimit{0}, indices{getAllocator()} { } +RuntimeTlsMap::RuntimeTlsMap() : initialPtr{0}, initialLimit{0}, indices{getAllocator()} {} -void initTlsObjects(Tcb *tcb, const frg::vector &objects, bool checkInitialized) { +void initTlsObjects( + Tcb *tcb, const frg::vector &objects, bool checkInitialized +) { // Initialize TLS segments that follow the static model. - for(auto object : objects) { - if(object->tlsModel == TlsModel::initial) { - if(checkInitialized && object->tlsInitialized) + for (auto object : objects) { + if (object->tlsModel == TlsModel::initial) { + if (checkInitialized && object->tlsInitialized) continue; char *tcb_ptr = reinterpret_cast(tcb); @@ -1284,8 +1346,9 @@ void initTlsObjects(Tcb *tcb, const frg::vector memcpy(tls_ptr, object->tlsImagePtr, object->tlsImageSize); if (verbose) { - mlibc::infoLogger() << "rtld: wrote tls image at " << (void *)tls_ptr - << ", size = 0x" << frg::hex_fmt{object->tlsSegmentSize} << frg::endlog; + mlibc::infoLogger() + << "rtld: wrote tls image at " << (void *)tls_ptr << ", size = 0x" + << frg::hex_fmt{object->tlsSegmentSize} << frg::endlog; } if (checkInitialized) @@ -1329,10 +1392,10 @@ Tcb *allocateTcb() { __ensure((tcbAddress & (alignof(Tcb) - 1)) == 0); if (verbose) { - mlibc::infoLogger() << "rtld: tcb allocated at " << (void *)tcbAddress - << ", size = 0x" << frg::hex_fmt{sizeof(Tcb)} << frg::endlog; - mlibc::infoLogger() << "rtld: tls allocated at " << (void *)tlsAddress - << ", size = 0x" << frg::hex_fmt{tlsInitialSize} << frg::endlog; + mlibc::infoLogger() << "rtld: tcb allocated at " << (void *)tcbAddress << ", size = 0x" + << frg::hex_fmt{sizeof(Tcb)} << frg::endlog; + mlibc::infoLogger() << "rtld: tls allocated at " << (void *)tlsAddress << ", size = 0x" + << frg::hex_fmt{tlsInitialSize} << frg::endlog; } Tcb *tcb_ptr = new ((char *)tcbAddress) Tcb; @@ -1343,17 +1406,19 @@ Tcb *allocateTcb() { tcb_ptr->didExit = 0; tcb_ptr->isJoinable = 1; memset(&tcb_ptr->returnValue, 0, sizeof(tcb_ptr->returnValue)); - tcb_ptr->localKeys = frg::construct>(getAllocator()); + tcb_ptr->localKeys = + frg::construct>(getAllocator()); tcb_ptr->dtvSize = runtimeTlsMap->indices.size(); tcb_ptr->dtvPointers = frg::construct_n(getAllocator(), runtimeTlsMap->indices.size()); memset(tcb_ptr->dtvPointers, 0, sizeof(void *) * runtimeTlsMap->indices.size()); - for(size_t i = 0; i < runtimeTlsMap->indices.size(); ++i) { + for (size_t i = 0; i < runtimeTlsMap->indices.size(); ++i) { auto object = runtimeTlsMap->indices[i]; - if(object->tlsModel != TlsModel::initial) + if (object->tlsModel != TlsModel::initial) continue; if constexpr (tlsAboveTp) { - tcb_ptr->dtvPointers[i] = reinterpret_cast(tcb_ptr) + sizeof(Tcb) + object->tlsOffset; + tcb_ptr->dtvPointers[i] = + reinterpret_cast(tcb_ptr) + sizeof(Tcb) + object->tlsOffset; } else { tcb_ptr->dtvPointers[i] = reinterpret_cast(tcb_ptr) + object->tlsOffset; } @@ -1366,7 +1431,7 @@ void *accessDtv(SharedObject *object) { Tcb *tcb_ptr = mlibc::get_current_tcb(); // We might need to reallocate the DTV. - if(object->tlsIndex >= tcb_ptr->dtvSize) { + if (object->tlsIndex >= tcb_ptr->dtvSize) { // TODO: need to protect runtimeTlsMap against concurrent access. auto ndtv = frg::construct_n(getAllocator(), runtimeTlsMap->indices.size()); memset(ndtv, 0, sizeof(void *) * runtimeTlsMap->indices.size()); @@ -1377,7 +1442,7 @@ void *accessDtv(SharedObject *object) { } // We might need to fill in a new DTV entry. - if(!tcb_ptr->dtvPointers[object->tlsIndex]) { + if (!tcb_ptr->dtvPointers[object->tlsIndex]) { __ensure(object->tlsModel == TlsModel::dynamic); auto buffer = getAllocator().allocate(object->tlsSegmentSize); @@ -1387,8 +1452,8 @@ void *accessDtv(SharedObject *object) { tcb_ptr->dtvPointers[object->tlsIndex] = buffer; if (verbose) { - mlibc::infoLogger() << "rtld: accessDtv wrote tls image at " << buffer - << ", size = 0x" << frg::hex_fmt{object->tlsSegmentSize} << frg::endlog; + mlibc::infoLogger() << "rtld: accessDtv wrote tls image at " << buffer << ", size = 0x" + << frg::hex_fmt{object->tlsSegmentSize} << frg::endlog; } } @@ -1411,12 +1476,12 @@ void *tryAccessDtv(SharedObject *object) { // -------------------------------------------------------- ObjectSymbol::ObjectSymbol(SharedObject *object, const elf_sym *symbol) -: _object(object), _symbol(symbol) { } +: _object(object), + _symbol(symbol) {} const char *ObjectSymbol::getString() { __ensure(_symbol->st_name != 0); - return (const char *)(_object->baseAddress - + _object->stringTableOffset + _symbol->st_name); + return (const char *)(_object->baseAddress + _object->stringTableOffset + _symbol->st_name); } uintptr_t ObjectSymbol::virtualAddress() { @@ -1433,10 +1498,10 @@ uintptr_t ObjectSymbol::virtualAddress() { uint32_t elf64Hash(frg::string_view string) { uint32_t h = 0, g; - for(size_t i = 0; i < string.size(); ++i) { + for (size_t i = 0; i < string.size(); ++i) { h = (h << 4) + (uint32_t)string[i]; g = h & 0xF0000000; - if(g) + if (g) h ^= g >> 24; h &= 0x0FFFFFFF; } @@ -1445,38 +1510,41 @@ uint32_t elf64Hash(frg::string_view string) { } uint32_t gnuHash(frg::string_view string) { - uint32_t h = 5381; - for(size_t i = 0; i < string.size(); ++i) - h = (h << 5) + h + string[i]; - return h; + uint32_t h = 5381; + for (size_t i = 0; i < string.size(); ++i) + h = (h << 5) + h + string[i]; + return h; } // TODO: move this to some namespace or class? -frg::optional resolveInObject(SharedObject *object, frg::string_view string, - frg::optional version) { +frg::optional resolveInObject( + SharedObject *object, frg::string_view string, frg::optional version +) { // Checks if the symbol can be used to satisfy the dependency. - auto eligible = [&] (ObjectSymbol cand) { - if(cand.symbol()->st_shndx == SHN_UNDEF) + auto eligible = [&](ObjectSymbol cand) { + if (cand.symbol()->st_shndx == SHN_UNDEF) return false; auto bind = ELF_ST_BIND(cand.symbol()->st_info); - if(bind != STB_GLOBAL && bind != STB_WEAK && bind != STB_GNU_UNIQUE) + if (bind != STB_GLOBAL && bind != STB_WEAK && bind != STB_GNU_UNIQUE) return false; return true; }; // Checks if the symbol's version matches the desired version. - auto correctVersion = [&] (SymbolVersion candVersion) { + auto correctVersion = [&](SymbolVersion candVersion) { // TODO(qookie): Not sure if local symbols should participate in dynamic symbol resolution - if(!version && (candVersion.isDefault() || candVersion.isLocal() || candVersion.isGlobal())) + if (!version + && (candVersion.isDefault() || candVersion.isLocal() || candVersion.isGlobal())) return true; // Caller requested default version, but this isn't it. - if(!version) + if (!version) return false; // If the requested version is global (caller has VERNEED but not for this symbol), // use the default one. - if(version->isGlobal() && !candVersion.isGlobal() && !candVersion.isLocal() && candVersion.isDefault()) + if (version->isGlobal() && !candVersion.isGlobal() && !candVersion.isLocal() + && candVersion.isDefault()) return true; return *version == candVersion; }; @@ -1487,16 +1555,17 @@ frg::optional resolveInObject(SharedObject *object, frg::string_vi auto bucket = elf64Hash(string) % num_buckets; auto index = hash_table[2 + bucket]; - while(index != 0) { + while (index != 0) { auto [cand, ver] = object->getSymbolByIndex(index); - if(eligible(cand) && frg::string_view{cand.getString()} == string && correctVersion(ver)) + if (eligible(cand) && frg::string_view{cand.getString()} == string + && correctVersion(ver)) return cand; index = hash_table[2 + num_buckets + index]; } return frg::optional{}; - }else{ + } else { __ensure(object->hashStyle == HashStyle::gnu); struct GnuTable { @@ -1506,15 +1575,16 @@ frg::optional resolveInObject(SharedObject *object, frg::string_vi uint32_t bloomShift; }; - auto hash_table = reinterpret_cast(object->baseAddress - + object->hashTableOffset); - auto buckets = reinterpret_cast(object->baseAddress - + object->hashTableOffset + sizeof(GnuTable) - + hash_table->bloomSize * sizeof(elf_addr)); - auto chains = reinterpret_cast(object->baseAddress - + object->hashTableOffset + sizeof(GnuTable) - + hash_table->bloomSize * sizeof(elf_addr) - + hash_table->nBuckets * sizeof(uint32_t)); + auto hash_table = + reinterpret_cast(object->baseAddress + object->hashTableOffset); + auto buckets = reinterpret_cast( + object->baseAddress + object->hashTableOffset + sizeof(GnuTable) + + hash_table->bloomSize * sizeof(elf_addr) + ); + auto chains = reinterpret_cast( + object->baseAddress + object->hashTableOffset + sizeof(GnuTable) + + hash_table->bloomSize * sizeof(elf_addr) + hash_table->nBuckets * sizeof(uint32_t) + ); // TODO: Use the bloom filter. @@ -1522,28 +1592,30 @@ frg::optional resolveInObject(SharedObject *object, frg::string_vi auto hash = gnuHash(string); auto index = buckets[hash % hash_table->nBuckets]; - if(!index) + if (!index) return frg::optional{}; - while(true) { + while (true) { // chains[] contains an array of hashes, parallel to the symbol table. auto chash = chains[index - hash_table->symbolOffset]; if ((chash & ~1) == (hash & ~1)) { auto [cand, ver] = object->getSymbolByIndex(index); - if(eligible(cand) && frg::string_view{cand.getString()} == string && correctVersion(ver)) + if (eligible(cand) && frg::string_view{cand.getString()} == string + && correctVersion(ver)) return cand; } // If we hit the end of the chain, the symbol is not present. - if(chash & 1) + if (chash & 1) return frg::optional{}; index++; } } } -frg::optional Scope::_resolveNext(frg::string_view string, - SharedObject *target, frg::optional version) { +frg::optional Scope::_resolveNext( + frg::string_view string, SharedObject *target, frg::optional version +) { // Skip objects until we find the target, and only look for symbols after that. size_t i; for (i = 0; i < _objects.size(); i++) { @@ -1552,24 +1624,24 @@ frg::optional Scope::_resolveNext(frg::string_view string, } if (i == _objects.size()) { - mlibc::infoLogger() << "rtld: object passed to Scope::resolveAfter was not found" << frg::endlog; + mlibc::infoLogger() << "rtld: object passed to Scope::resolveAfter was not found" + << frg::endlog; return frg::optional(); } for (i = i + 1; i < _objects.size(); i++) { - if(_objects[i]->isMainObject) + if (_objects[i]->isMainObject) continue; frg::optional p = resolveInObject(_objects[i], string, version); - if(p) + if (p) return p; } return frg::optional(); } -Scope::Scope(bool isGlobal) -: isGlobal{isGlobal}, _objects(getAllocator()) { } +Scope::Scope(bool isGlobal) : isGlobal{isGlobal}, _objects(getAllocator()) {} void Scope::appendObject(SharedObject *object) { // Don't insert duplicates. @@ -1581,44 +1653,56 @@ void Scope::appendObject(SharedObject *object) { _objects.push(object); } -frg::optional Scope::resolveGlobalOrLocal(Scope &globalScope, - Scope *localScope, frg::string_view string, uint64_t skipRts, ResolveFlags flags, - frg::optional version) { +frg::optional Scope::resolveGlobalOrLocal( + Scope &globalScope, + Scope *localScope, + frg::string_view string, + uint64_t skipRts, + ResolveFlags flags, + frg::optional version +) { auto sym = globalScope.resolveSymbol(string, skipRts, flags | skipGlobalAfterRts, version); - if(!sym && localScope) + if (!sym && localScope) sym = localScope->resolveSymbol(string, skipRts, flags | skipGlobalAfterRts, version); return sym; } -frg::optional Scope::resolveGlobalOrLocalNext(Scope &globalScope, - Scope *localScope, frg::string_view string, SharedObject *origin, - frg::optional version) { +frg::optional Scope::resolveGlobalOrLocalNext( + Scope &globalScope, + Scope *localScope, + frg::string_view string, + SharedObject *origin, + frg::optional version +) { auto sym = globalScope._resolveNext(string, origin, version); - if(!sym && localScope) { + if (!sym && localScope) { sym = localScope->_resolveNext(string, origin, version); } return sym; } // TODO: let this return uintptr_t -frg::optional Scope::resolveSymbol(frg::string_view string, - uint64_t skipRts, ResolveFlags flags, - frg::optional version) { +frg::optional Scope::resolveSymbol( + frg::string_view string, + uint64_t skipRts, + ResolveFlags flags, + frg::optional version +) { for (auto object : _objects) { - if((flags & resolveCopy) && object->isMainObject) + if ((flags & resolveCopy) && object->isMainObject) continue; - if((flags & skipGlobalAfterRts) && object->globalRts > skipRts) { + if ((flags & skipGlobalAfterRts) && object->globalRts > skipRts) { // globalRts should be monotone increasing for objects in the global scope, // so as an optimization we can break early here. // TODO: If we implement DT_SYMBOLIC, this assumption fails. - if(isGlobal) + if (isGlobal) break; else continue; } frg::optional p = resolveInObject(object, string, version); - if(p) + if (p) return p; } @@ -1630,20 +1714,23 @@ frg::optional Scope::resolveSymbol(frg::string_view string, // -------------------------------------------------------- Loader::Loader(Scope *scope, SharedObject *mainExecutable, bool is_initial_link, uint64_t rts) -: _mainExecutable{mainExecutable}, _loadScope{scope}, _isInitialLink{is_initial_link}, - _linkRts{rts}, _linkBfs{getAllocator()}, _initQueue{getAllocator()} { } +: _mainExecutable{mainExecutable}, + _loadScope{scope}, + _isInitialLink{is_initial_link}, + _linkRts{rts}, + _linkBfs{getAllocator()}, + _initQueue{getAllocator()} {} void Loader::_buildLinkBfs(SharedObject *root) { __ensure(_linkBfs.size() == 0); struct Token {}; - using Set = frg::hash_map, MemoryAllocator>; + using Set = frg::hash_map, MemoryAllocator>; Set set{frg::hash{}, getAllocator()}; _linkBfs.push(root); // Loop over indices (not iterators) here: We are adding elements in the loop! - for(size_t i = 0; i < _linkBfs.size(); i++) { + for (size_t i = 0; i < _linkBfs.size(); i++) { auto current = _linkBfs[i]; // At this point the object is loaded and we can fill in its debug struct, @@ -1672,7 +1759,7 @@ void Loader::linkObjects(SharedObject *root) { _buildTlsMaps(); // Promote objects to the desired scope. - for(auto object : _linkBfs) { + for (auto object : _linkBfs) { if (object->globalRts == 0 && _loadScope->isGlobal) object->globalRts = _linkRts; @@ -1680,54 +1767,54 @@ void Loader::linkObjects(SharedObject *root) { } // Process regular relocations. - for(auto object : _linkBfs) { + for (auto object : _linkBfs) { // Some objects have already been linked before. - if(object->objectRts < _linkRts) + if (object->objectRts < _linkRts) continue; - if(object->dynamic == nullptr) + if (object->dynamic == nullptr) continue; - if(verbose) + if (verbose) mlibc::infoLogger() << "rtld: Linking " << object->name << frg::endlog; __ensure(!object->wasLinked); // TODO: Support this. - if(object->symbolicResolution) + if (object->symbolicResolution) mlibc::infoLogger() << "\e[31mrtld: DT_SYMBOLIC is not implemented correctly!\e[39m" - << frg::endlog; + << frg::endlog; _processStaticRelocations(object); _processLazyRelocations(object); } // Process copy relocations. - for(auto object : _linkBfs) { - if(!object->isMainObject) + for (auto object : _linkBfs) { + if (!object->isMainObject) continue; // Some objects have already been linked before. - if(object->objectRts < _linkRts) + if (object->objectRts < _linkRts) continue; - if(object->dynamic == nullptr) + if (object->dynamic == nullptr) continue; processLateRelocations(object); } - for(auto object : _linkBfs) { + for (auto object : _linkBfs) { object->wasLinked = true; - if(object->inLinkMap) + if (object->inLinkMap) continue; - auto linkMap = reinterpret_cast(globalDebugInterface.head); + auto linkMap = reinterpret_cast(globalDebugInterface.head); object->linkMap.prev = linkMap; object->linkMap.next = linkMap->next; - if(linkMap->next) + if (linkMap->next) linkMap->next->prev = &(object->linkMap); linkMap->next = &(object->linkMap); object->inLinkMap = true; @@ -1735,17 +1822,17 @@ void Loader::linkObjects(SharedObject *root) { } void Loader::_buildTlsMaps() { - if(_isInitialLink) { + if (_isInitialLink) { __ensure(runtimeTlsMap->initialPtr == 0); __ensure(runtimeTlsMap->initialLimit == 0); __ensure(!_linkBfs.empty()); __ensure(_linkBfs.front()->isMainObject); - for(auto object : _linkBfs) { + for (auto object : _linkBfs) { __ensure(object->tlsModel == TlsModel::null); - if(object->tlsSegmentSize == 0) + if (object->tlsSegmentSize == 0) continue; // Allocate an index for the object. @@ -1756,7 +1843,7 @@ void Loader::_buildTlsMaps() { if constexpr (tlsAboveTp) { size_t misalign = runtimeTlsMap->initialPtr & (object->tlsAlignment - 1); - if(misalign) + if (misalign) runtimeTlsMap->initialPtr += object->tlsAlignment - misalign; object->tlsOffset = runtimeTlsMap->initialPtr; @@ -1765,26 +1852,26 @@ void Loader::_buildTlsMaps() { runtimeTlsMap->initialPtr += object->tlsSegmentSize; size_t misalign = runtimeTlsMap->initialPtr & (object->tlsAlignment - 1); - if(misalign) + if (misalign) runtimeTlsMap->initialPtr += object->tlsAlignment - misalign; object->tlsOffset = -runtimeTlsMap->initialPtr; } - if(verbose) - mlibc::infoLogger() << "rtld: TLS of " << object->name - << " mapped to 0x" << frg::hex_fmt{object->tlsOffset} - << ", size: " << object->tlsSegmentSize - << ", alignment: " << object->tlsAlignment << frg::endlog; + if (verbose) + mlibc::infoLogger() + << "rtld: TLS of " << object->name << " mapped to 0x" + << frg::hex_fmt{object->tlsOffset} << ", size: " << object->tlsSegmentSize + << ", alignment: " << object->tlsAlignment << frg::endlog; } // Reserve some additional space for future libraries. runtimeTlsMap->initialLimit = runtimeTlsMap->initialPtr + 64; - }else{ - for(auto object : _linkBfs) { - if(object->tlsModel != TlsModel::null) + } else { + for (auto object : _linkBfs) { + if (object->tlsModel != TlsModel::null) continue; - if(object->tlsSegmentSize == 0) + if (object->tlsSegmentSize == 0) continue; // Allocate an index for the object. @@ -1793,12 +1880,12 @@ void Loader::_buildTlsMaps() { // There are some libraries (e.g. Mesa) that require static TLS even though // they expect to be dynamically loaded. - if(object->haveStaticTls) { + if (object->haveStaticTls) { object->tlsModel = TlsModel::initial; if constexpr (tlsAboveTp) { size_t misalign = runtimeTlsMap->initialPtr & (object->tlsAlignment - 1); - if(misalign) + if (misalign) runtimeTlsMap->initialPtr += object->tlsAlignment - misalign; object->tlsOffset = runtimeTlsMap->initialPtr; @@ -1807,22 +1894,23 @@ void Loader::_buildTlsMaps() { runtimeTlsMap->initialPtr += object->tlsSegmentSize; size_t misalign = runtimeTlsMap->initialPtr & (object->tlsAlignment - 1); - if(misalign) + if (misalign) runtimeTlsMap->initialPtr += object->tlsAlignment - misalign; object->tlsOffset = -runtimeTlsMap->initialPtr; } - if(runtimeTlsMap->initialPtr > runtimeTlsMap->initialLimit) - mlibc::panicLogger() << "rtld: Static TLS space exhausted while while" - " allocating TLS for " << object->name << frg::endlog; + if (runtimeTlsMap->initialPtr > runtimeTlsMap->initialLimit) + mlibc::panicLogger() << "rtld: Static TLS space exhausted while while" + " allocating TLS for " + << object->name << frg::endlog; - if(verbose) - mlibc::infoLogger() << "rtld: TLS of " << object->name - << " mapped to 0x" << frg::hex_fmt{object->tlsOffset} - << ", size: " << object->tlsSegmentSize - << ", alignment: " << object->tlsAlignment << frg::endlog; - }else{ + if (verbose) + mlibc::infoLogger() + << "rtld: TLS of " << object->name << " mapped to 0x" + << frg::hex_fmt{object->tlsOffset} << ", size: " << object->tlsSegmentSize + << ", alignment: " << object->tlsAlignment << frg::endlog; + } else { object->tlsModel = TlsModel::dynamic; } } @@ -1839,19 +1927,19 @@ void Loader::initObjects(ObjectRepository *repository) { __ensure(_mainExecutable->isMainObject); __ensure(!_mainExecutable->wasInitialized); __ensure((_mainExecutable->preInitArraySize % sizeof(InitFuncPtr)) == 0); - for(size_t i = 0; i < _mainExecutable->preInitArraySize / sizeof(InitFuncPtr); i++) + for (size_t i = 0; i < _mainExecutable->preInitArraySize / sizeof(InitFuncPtr); i++) _mainExecutable->preInitArray[i](); } // Convert the breadth-first representation to a depth-first post-order representation, // so that every object is initialized *after* its dependencies. - for(auto object : _linkBfs) { - if(!object->scheduledForInit) + for (auto object : _linkBfs) { + if (!object->scheduledForInit) _scheduleInit(object); } - for(auto object : _initQueue) { - if(!object->wasInitialized) { + for (auto object : _initQueue) { + if (!object->wasInitialized) { doInitialize(object); repository->addObjectToDestructQueue(object); } @@ -1867,8 +1955,8 @@ void Loader::_scheduleInit(SharedObject *object) { __ensure(!object->scheduledForInit); object->scheduledForInit = true; - for(size_t i = 0; i < object->dependencies.size(); i++) { - if(!object->dependencies[i]->scheduledForInit) + for (size_t i = 0; i < object->dependencies.size(); i++) { + if (!object->dependencies[i]->scheduledForInit) _scheduleInit(object->dependencies[i]); } @@ -1878,108 +1966,110 @@ void Loader::_scheduleInit(SharedObject *object) { void Loader::_processRelocations(Relocation &rel) { // copy and irelative relocations have to be performed after all other relocations - if(rel.type() == R_COPY || rel.type() == R_IRELATIVE) + if (rel.type() == R_COPY || rel.type() == R_IRELATIVE) return; // resolve the symbol if there is a symbol frg::optional p; - if(rel.symbol_index()) { + if (rel.symbol_index()) { auto [sym, ver] = rel.object()->getSymbolByIndex(rel.symbol_index()); - p = Scope::resolveGlobalOrLocal(*globalScope, rel.object()->localScope, - sym.getString(), rel.object()->objectRts, 0, ver); - if(!p) { - if(ELF_ST_BIND(sym.symbol()->st_info) != STB_WEAK) - mlibc::panicLogger() << "Unresolved load-time symbol " - << sym.getString() << " in object " << rel.object()->name << frg::endlog; - - if(verbose) - mlibc::infoLogger() << "rtld: Unresolved weak load-time symbol " - << sym.getString() << " in object " << rel.object()->name << frg::endlog; + p = Scope::resolveGlobalOrLocal( + *globalScope, rel.object()->localScope, sym.getString(), rel.object()->objectRts, 0, ver + ); + if (!p) { + if (ELF_ST_BIND(sym.symbol()->st_info) != STB_WEAK) + mlibc::panicLogger() << "Unresolved load-time symbol " << sym.getString() + << " in object " << rel.object()->name << frg::endlog; + + if (verbose) + mlibc::infoLogger() << "rtld: Unresolved weak load-time symbol " << sym.getString() + << " in object " << rel.object()->name << frg::endlog; } } - switch(rel.type()) { - case R_NONE: - break; + switch (rel.type()) { + case R_NONE: + break; - case R_JUMP_SLOT: { - __ensure(!rel.addend_norel()); - uintptr_t symbol_addr = p ? p->virtualAddress() : 0; - rel.relocate(symbol_addr); - } break; + case R_JUMP_SLOT: { + __ensure(!rel.addend_norel()); + uintptr_t symbol_addr = p ? p->virtualAddress() : 0; + rel.relocate(symbol_addr); + } break; #if !defined(__riscv) && !defined(__loongarch64) - // on some architectures, R_GLOB_DAT can be defined to other relocations - case R_GLOB_DAT: { - __ensure(rel.symbol_index()); - uintptr_t symbol_addr = p ? p->virtualAddress() : 0; - rel.relocate(symbol_addr + rel.addend_norel()); - } break; + // on some architectures, R_GLOB_DAT can be defined to other relocations + case R_GLOB_DAT: { + __ensure(rel.symbol_index()); + uintptr_t symbol_addr = p ? p->virtualAddress() : 0; + rel.relocate(symbol_addr + rel.addend_norel()); + } break; #endif - case R_ABSOLUTE: { - __ensure(rel.symbol_index()); - uintptr_t symbol_addr = p ? p->virtualAddress() : 0; - rel.relocate(symbol_addr + rel.addend_rel()); - } break; - - case R_RELATIVE: { - __ensure(!rel.symbol_index()); - rel.relocate(rel.object()->baseAddress + rel.addend_rel()); - } break; - - // DTPMOD and DTPREL are dynamic TLS relocations (for __tls_get_addr()). - // TPOFF is a relocation to the initial TLS model. - case R_TLS_DTPMOD: { - // sets the first `sizeof(uintptr_t)` bytes of `struct __abi_tls_entry` - // this means that we can just use the `SharedObject *` to resolve whatever we need - __ensure(!rel.addend_rel()); - if(rel.symbol_index()) { - __ensure(p); - rel.relocate(elf_addr(p->object())); - }else{ - if(stillSlightlyVerbose) - mlibc::infoLogger() << "rtld: Warning: TLS_DTPMOD64 with no symbol in object " - << rel.object()->name << frg::endlog; - rel.relocate(elf_addr(rel.object())); - } - } break; - case R_TLS_DTPREL: { - __ensure(rel.symbol_index()); - __ensure(p); - rel.relocate(p->symbol()->st_value + rel.addend_rel() - TLS_DTV_OFFSET); - } break; - case R_TLS_TPREL: { - uintptr_t off = rel.addend_rel(); - ssize_t tls_offset = 0; - - if(rel.symbol_index()) { + case R_ABSOLUTE: { + __ensure(rel.symbol_index()); + uintptr_t symbol_addr = p ? p->virtualAddress() : 0; + rel.relocate(symbol_addr + rel.addend_rel()); + } break; + + case R_RELATIVE: { + __ensure(!rel.symbol_index()); + rel.relocate(rel.object()->baseAddress + rel.addend_rel()); + } break; + + // DTPMOD and DTPREL are dynamic TLS relocations (for __tls_get_addr()). + // TPOFF is a relocation to the initial TLS model. + case R_TLS_DTPMOD: { + // sets the first `sizeof(uintptr_t)` bytes of `struct __abi_tls_entry` + // this means that we can just use the `SharedObject *` to resolve whatever we need + __ensure(!rel.addend_rel()); + if (rel.symbol_index()) { + __ensure(p); + rel.relocate(elf_addr(p->object())); + } else { + if (stillSlightlyVerbose) + mlibc::infoLogger() << "rtld: Warning: TLS_DTPMOD64 with no symbol in object " + << rel.object()->name << frg::endlog; + rel.relocate(elf_addr(rel.object())); + } + } break; + case R_TLS_DTPREL: { + __ensure(rel.symbol_index()); __ensure(p); - if(p->object()->tlsModel != TlsModel::initial) - mlibc::panicLogger() << "rtld: In object " << rel.object()->name - << ": Static TLS relocation to symbol " << p->getString() - << " in dynamically loaded object " - << p->object()->name << frg::endlog; - off += p->symbol()->st_value; - tls_offset = p->object()->tlsOffset; - }else{ - if(stillSlightlyVerbose) - mlibc::infoLogger() << "rtld: Warning: TPOFF64 with no symbol" - " in object " << rel.object()->name << frg::endlog; - if(rel.object()->tlsModel != TlsModel::initial) - mlibc::panicLogger() << "rtld: In object " << rel.object()->name - << ": Static TLS relocation to dynamically loaded object " - << rel.object()->name << frg::endlog; - tls_offset = rel.object()->tlsOffset; - } + rel.relocate(p->symbol()->st_value + rel.addend_rel() - TLS_DTV_OFFSET); + } break; + case R_TLS_TPREL: { + uintptr_t off = rel.addend_rel(); + ssize_t tls_offset = 0; + + if (rel.symbol_index()) { + __ensure(p); + if (p->object()->tlsModel != TlsModel::initial) + mlibc::panicLogger() + << "rtld: In object " << rel.object()->name + << ": Static TLS relocation to symbol " << p->getString() + << " in dynamically loaded object " << p->object()->name << frg::endlog; + off += p->symbol()->st_value; + tls_offset = p->object()->tlsOffset; + } else { + if (stillSlightlyVerbose) + mlibc::infoLogger() << "rtld: Warning: TPOFF64 with no symbol" + " in object " + << rel.object()->name << frg::endlog; + if (rel.object()->tlsModel != TlsModel::initial) + mlibc::panicLogger() << "rtld: In object " << rel.object()->name + << ": Static TLS relocation to dynamically loaded object " + << rel.object()->name << frg::endlog; + tls_offset = rel.object()->tlsOffset; + } - off += tls_offset + tlsOffsetFromTp; - rel.relocate(off); - } break; - default: - mlibc::panicLogger() << "Unexpected relocation type " - << (void *) rel.type() << frg::endlog; + off += tls_offset + tlsOffsetFromTp; + rel.relocate(off); + } break; + default: + mlibc::panicLogger() << "Unexpected relocation type " << (void *)rel.type() + << frg::endlog; } } @@ -1993,53 +2083,53 @@ void Loader::_processStaticRelocations(SharedObject *object) { frg::optional relr_offset; frg::optional relr_length; - for(size_t i = 0; object->dynamic[i].d_tag != DT_NULL; i++) { + for (size_t i = 0; object->dynamic[i].d_tag != DT_NULL; i++) { elf_dyn *dynamic = &object->dynamic[i]; - switch(dynamic->d_tag) { - case DT_RELA: - rela_offset = dynamic->d_un.d_ptr; - break; - case DT_RELASZ: - rela_length = dynamic->d_un.d_val; - break; - case DT_RELAENT: - __ensure(dynamic->d_un.d_val == sizeof(elf_rela)); - break; - case DT_REL: - rel_offset = dynamic->d_un.d_ptr; - break; - case DT_RELSZ: - rel_length = dynamic->d_un.d_val; - break; - case DT_RELENT: - __ensure(dynamic->d_un.d_val == sizeof(elf_rel)); - break; - case DT_RELR: - relr_offset = dynamic->d_un.d_ptr; - break; - case DT_RELRSZ: - relr_length = dynamic->d_un.d_val; - break; - case DT_RELRENT: - __ensure(dynamic->d_un.d_val == sizeof(elf_relr)); - break; + switch (dynamic->d_tag) { + case DT_RELA: + rela_offset = dynamic->d_un.d_ptr; + break; + case DT_RELASZ: + rela_length = dynamic->d_un.d_val; + break; + case DT_RELAENT: + __ensure(dynamic->d_un.d_val == sizeof(elf_rela)); + break; + case DT_REL: + rel_offset = dynamic->d_un.d_ptr; + break; + case DT_RELSZ: + rel_length = dynamic->d_un.d_val; + break; + case DT_RELENT: + __ensure(dynamic->d_un.d_val == sizeof(elf_rel)); + break; + case DT_RELR: + relr_offset = dynamic->d_un.d_ptr; + break; + case DT_RELRSZ: + relr_length = dynamic->d_un.d_val; + break; + case DT_RELRENT: + __ensure(dynamic->d_un.d_val == sizeof(elf_relr)); + break; } } - if(rela_offset && rela_length) { + if (rela_offset && rela_length) { __ensure(!rel_offset && !rel_length); - for(size_t offset = 0; offset < *rela_length; offset += sizeof(elf_rela)) { + for (size_t offset = 0; offset < *rela_length; offset += sizeof(elf_rela)) { auto reloc = (elf_rela *)(object->baseAddress + *rela_offset + offset); auto r = Relocation(object, reloc); _processRelocations(r); } - }else if(rel_offset && rel_length) { + } else if (rel_offset && rel_length) { __ensure(!rela_offset && !rela_length); - for(size_t offset = 0; offset < *rel_length; offset += sizeof(elf_rel)) { + for (size_t offset = 0; offset < *rel_length; offset += sizeof(elf_rel)) { auto reloc = (elf_rel *)(object->baseAddress + *rel_offset + offset); auto r = Relocation(object, reloc); @@ -2047,26 +2137,27 @@ void Loader::_processStaticRelocations(SharedObject *object) { } } - if(relr_offset && relr_length) { + if (relr_offset && relr_length) { elf_addr *addr = nullptr; - for(size_t offset = 0; offset < *relr_length; offset += sizeof(elf_relr)) { + for (size_t offset = 0; offset < *relr_length; offset += sizeof(elf_relr)) { auto entry = *(elf_relr *)(object->baseAddress + *relr_offset + offset); // Even entry indicates the beginning address. - if(!(entry & 1)) { + if (!(entry & 1)) { addr = (elf_addr *)(object->baseAddress + entry); __ensure(addr); *addr++ += object->baseAddress; - }else { - // Odd entry indicates entry is a bitmap of the subsequent locations to be relocated. + } else { + // Odd entry indicates entry is a bitmap of the subsequent locations to be + // relocated. - // The first bit of an entry is always a marker about whether the entry is an address or a bitmap, - // discard it. + // The first bit of an entry is always a marker about whether the entry is an + // address or a bitmap, discard it. entry >>= 1; - for(int i = 0; entry; ++i) { - if(entry & 1) { + for (int i = 0; entry; ++i) { + if (entry & 1) { addr[i] += object->baseAddress; } entry >>= 1; @@ -2086,28 +2177,28 @@ extern "C" void *__mlibcTlsdescDynamic(void *); #endif void Loader::_processLazyRelocations(SharedObject *object) { - if(object->globalOffsetTable == nullptr) { + if (object->globalOffsetTable == nullptr) { __ensure(object->lazyRelocTableOffset == 0); return; } object->globalOffsetTable[1] = object; object->globalOffsetTable[2] = (void *)&pltRelocateStub; - if(!object->lazyTableSize) + if (!object->lazyTableSize) return; // adjust the addresses of JUMP_SLOT relocations __ensure(object->lazyExplicitAddend.has_value()); size_t rel_size = (*object->lazyExplicitAddend) ? sizeof(elf_rela) : sizeof(elf_rel); - for(size_t offset = 0; offset < object->lazyTableSize; offset += rel_size) { + for (size_t offset = 0; offset < object->lazyTableSize; offset += rel_size) { elf_info type; elf_info symbol_index; uintptr_t rel_addr; uintptr_t addend [[maybe_unused]] = 0; - if(*object->lazyExplicitAddend) { + if (*object->lazyExplicitAddend) { auto reloc = (elf_rela *)(object->baseAddress + object->lazyRelocTableOffset + offset); type = ELF_R_TYPE(reloc->r_info); symbol_index = ELF_R_SYM(reloc->r_info); @@ -2121,89 +2212,96 @@ void Loader::_processLazyRelocations(SharedObject *object) { } switch (type) { - case R_JUMP_SLOT: - if(eagerBinding) { - auto [sym, ver] = object->getSymbolByIndex(symbol_index); - auto p = Scope::resolveGlobalOrLocal(*globalScope, object->localScope, sym.getString(), object->objectRts, 0, ver); - - if(!p) { - if(ELF_ST_BIND(sym.symbol()->st_info) != STB_WEAK) - mlibc::panicLogger() << "rtld: Unresolved JUMP_SLOT symbol " - << sym.getString() << " in object " << object->name << frg::endlog; - - if(verbose) - mlibc::infoLogger() << "rtld: Unresolved weak JUMP_SLOT symbol " - << sym.getString() << " in object " << object->name << frg::endlog; - *((uintptr_t *)rel_addr) = 0; - }else{ - *((uintptr_t *)rel_addr) = p->virtualAddress(); + case R_JUMP_SLOT: + if (eagerBinding) { + auto [sym, ver] = object->getSymbolByIndex(symbol_index); + auto p = Scope::resolveGlobalOrLocal( + *globalScope, object->localScope, sym.getString(), object->objectRts, 0, ver + ); + + if (!p) { + if (ELF_ST_BIND(sym.symbol()->st_info) != STB_WEAK) + mlibc::panicLogger() + << "rtld: Unresolved JUMP_SLOT symbol " << sym.getString() + << " in object " << object->name << frg::endlog; + + if (verbose) + mlibc::infoLogger() + << "rtld: Unresolved weak JUMP_SLOT symbol " << sym.getString() + << " in object " << object->name << frg::endlog; + *((uintptr_t *)rel_addr) = 0; + } else { + *((uintptr_t *)rel_addr) = p->virtualAddress(); + } + } else { + *((uintptr_t *)rel_addr) += object->baseAddress; } - }else{ - *((uintptr_t *)rel_addr) += object->baseAddress; - } - break; + break; #if defined(__x86_64__) - case R_X86_64_IRELATIVE: { - auto ptr = object->baseAddress + addend; - auto target = reinterpret_cast(ptr)(); - *((uintptr_t *)rel_addr) = target; - break; - } + case R_X86_64_IRELATIVE: { + auto ptr = object->baseAddress + addend; + auto target = reinterpret_cast(ptr)(); + *((uintptr_t *)rel_addr) = target; + break; + } #endif // TODO: TLSDESC relocations aren't aarch64/x86_64 specific #if defined(__aarch64__) || defined(__x86_64__) - case R_TLSDESC: { - size_t symValue = 0; - SharedObject *target = nullptr; - - if (symbol_index) { - auto [sym, ver] = object->getSymbolByIndex(symbol_index); - auto p = Scope::resolveGlobalOrLocal(*globalScope, object->localScope, sym.getString(), object->objectRts, 0, ver); - - if (!p) { - __ensure(ELF_ST_BIND(sym.symbol()->st_info) != STB_WEAK); - mlibc::panicLogger() << "rtld: Unresolved TLSDESC for symbol " - << sym.getString() << " in object " << object->name << frg::endlog; + case R_TLSDESC: { + size_t symValue = 0; + SharedObject *target = nullptr; + + if (symbol_index) { + auto [sym, ver] = object->getSymbolByIndex(symbol_index); + auto p = Scope::resolveGlobalOrLocal( + *globalScope, object->localScope, sym.getString(), object->objectRts, 0, ver + ); + + if (!p) { + __ensure(ELF_ST_BIND(sym.symbol()->st_info) != STB_WEAK); + mlibc::panicLogger() + << "rtld: Unresolved TLSDESC for symbol " << sym.getString() + << " in object " << object->name << frg::endlog; + } else { + target = p->object(); + if (p->symbol()) + symValue = p->symbol()->st_value; + } } else { - target = p->object(); - if (p->symbol()) - symValue = p->symbol()->st_value; + target = object; } - } else { - target = object; - } - __ensure(target); + __ensure(target); - if (target->tlsModel == TlsModel::initial) { - ((uint64_t *)rel_addr)[0] = reinterpret_cast(&__mlibcTlsdescStatic); - uint64_t value = symValue + target->tlsOffset + tlsOffsetFromTp + addend; - ((uint64_t *)rel_addr)[1] = value; - } else { - struct TlsdescData { - uintptr_t tlsIndex; - uintptr_t addend; - }; + if (target->tlsModel == TlsModel::initial) { + ((uint64_t *)rel_addr)[0] = reinterpret_cast(&__mlibcTlsdescStatic); + uint64_t value = symValue + target->tlsOffset + tlsOffsetFromTp + addend; + ((uint64_t *)rel_addr)[1] = value; + } else { + struct TlsdescData { + uintptr_t tlsIndex; + uintptr_t addend; + }; - // Access DTV for object to force the entry to be allocated and initialized - accessDtv(target); + // Access DTV for object to force the entry to be allocated and initialized + accessDtv(target); - __ensure(target->tlsIndex < mlibc::get_current_tcb()->dtvSize); + __ensure(target->tlsIndex < mlibc::get_current_tcb()->dtvSize); - // TODO: We should free this when the DSO gets destroyed - auto data = frg::construct(getAllocator()); - data->tlsIndex = target->tlsIndex; - data->addend = symValue + addend; + // TODO: We should free this when the DSO gets destroyed + auto data = frg::construct(getAllocator()); + data->tlsIndex = target->tlsIndex; + data->addend = symValue + addend; - ((uint64_t *)rel_addr)[0] = reinterpret_cast(&__mlibcTlsdescDynamic); - ((uint64_t *)rel_addr)[1] = reinterpret_cast(data); - } - } break; + ((uint64_t *)rel_addr)[0] = reinterpret_cast(&__mlibcTlsdescDynamic); + ((uint64_t *)rel_addr)[1] = reinterpret_cast(data); + } + } break; #endif - default: - mlibc::panicLogger() << "unimplemented lazy relocation type " << type << frg::endlog; - break; + default: + mlibc::panicLogger() + << "unimplemented lazy relocation type " << type << frg::endlog; + break; } } } - diff --git a/options/rtld/generic/main.cpp b/options/rtld/generic/main.cpp index e96df46341..d61c554fae 100644 --- a/options/rtld/generic/main.cpp +++ b/options/rtld/generic/main.cpp @@ -6,13 +6,12 @@ #include #include +#include #include -#include -#include #include +#include +#include #include -#include -#include #include "elf.hpp" #include "linker.hpp" @@ -21,8 +20,8 @@ #include #endif -#define HIDDEN __attribute__((__visibility__("hidden"))) -#define EXPORT __attribute__((__visibility__("default"))) +#define HIDDEN __attribute__((__visibility__("hidden"))) +#define EXPORT __attribute__((__visibility__("default"))) static constexpr bool logEntryExit = false; static constexpr bool logStartup = false; @@ -34,9 +33,9 @@ extern HIDDEN elf_dyn _DYNAMIC[]; #endif namespace mlibc { - // Declared in options/internal/mlibc/tcb.hpp. - bool tcb_available_flag = false; -} +// Declared in options/internal/mlibc/tcb.hpp. +bool tcb_available_flag = false; +} // namespace mlibc mlibc::RtldConfig rtldConfig; @@ -50,7 +49,9 @@ frg::manual_box globalScope; frg::manual_box runtimeTlsMap; // We use a small vector to avoid memory allocation for the default library paths -frg::manual_box> libraryPaths; +frg::manual_box< + frg::small_vector> + libraryPaths; frg::manual_box> preloads; @@ -64,7 +65,8 @@ DebugInterface globalDebugInterface; // Use a PC-relative instruction sequence to find our runtime load address. uintptr_t getLdsoBase() { -#if defined(__x86_64__) || defined(__i386__) || defined(__aarch64__) || defined(__m68k__) || defined(__loongarch64) +#if defined(__x86_64__) || defined(__i386__) || defined(__aarch64__) || defined(__m68k__) \ + || defined(__loongarch64) // On x86_64, the first GOT entry holds the link-time address of _DYNAMIC. // TODO: This isn't guaranteed on AArch64, so this might fail with some linkers. auto linktime_dynamic = reinterpret_cast(_GLOBAL_OFFSET_TABLE_[0]); @@ -73,7 +75,7 @@ uintptr_t getLdsoBase() { #elif defined(__riscv) return reinterpret_cast(&__ehdr_start); #else - #error Unknown architecture! +#error Unknown architecture! #endif } @@ -90,72 +92,84 @@ extern "C" void relocateSelf() { size_t rel_size = 0; size_t relr_offset = 0; size_t relr_size = 0; - for(size_t i = 0; _DYNAMIC[i].d_tag != DT_NULL; i++) { + for (size_t i = 0; _DYNAMIC[i].d_tag != DT_NULL; i++) { auto ent = &_DYNAMIC[i]; - switch(ent->d_tag) { - case DT_REL: rel_offset = ent->d_un.d_ptr; break; - case DT_RELSZ: rel_size = ent->d_un.d_val; break; - case DT_RELA: rela_offset = ent->d_un.d_ptr; break; - case DT_RELASZ: rela_size = ent->d_un.d_val; break; - case DT_RELR: relr_offset = ent->d_un.d_ptr; break; - case DT_RELRSZ: relr_size = ent->d_un.d_val; break; + switch (ent->d_tag) { + case DT_REL: + rel_offset = ent->d_un.d_ptr; + break; + case DT_RELSZ: + rel_size = ent->d_un.d_val; + break; + case DT_RELA: + rela_offset = ent->d_un.d_ptr; + break; + case DT_RELASZ: + rela_size = ent->d_un.d_val; + break; + case DT_RELR: + relr_offset = ent->d_un.d_ptr; + break; + case DT_RELRSZ: + relr_size = ent->d_un.d_val; + break; } } auto ldso_base = getLdsoBase(); - for(size_t disp = 0; disp < rela_size; disp += sizeof(elf_rela)) { + for (size_t disp = 0; disp < rela_size; disp += sizeof(elf_rela)) { auto reloc = reinterpret_cast(ldso_base + rela_offset + disp); auto type = ELF_R_TYPE(reloc->r_info); - if(ELF_R_SYM(reloc->r_info)) + if (ELF_R_SYM(reloc->r_info)) __builtin_trap(); auto p = reinterpret_cast(ldso_base + reloc->r_offset); - switch(type) { - case R_RELATIVE: - *p = ldso_base + reloc->r_addend; - break; - default: - __builtin_trap(); + switch (type) { + case R_RELATIVE: + *p = ldso_base + reloc->r_addend; + break; + default: + __builtin_trap(); } } - for(size_t disp = 0; disp < rel_size; disp += sizeof(elf_rel)) { + for (size_t disp = 0; disp < rel_size; disp += sizeof(elf_rel)) { auto reloc = reinterpret_cast(ldso_base + rel_offset + disp); auto type = ELF_R_TYPE(reloc->r_info); - if(ELF_R_SYM(reloc->r_info)) + if (ELF_R_SYM(reloc->r_info)) __builtin_trap(); auto p = reinterpret_cast(ldso_base + reloc->r_offset); - switch(type) { - case R_RELATIVE: - *p += ldso_base; - break; - default: - __builtin_trap(); + switch (type) { + case R_RELATIVE: + *p += ldso_base; + break; + default: + __builtin_trap(); } } elf_addr *addr = nullptr; - for(size_t disp = 0; disp < relr_size; disp += sizeof(elf_relr)) { + for (size_t disp = 0; disp < relr_size; disp += sizeof(elf_relr)) { auto entry = *(elf_relr *)(ldso_base + relr_offset + disp); // Even entry indicates the beginning address. - if(!(entry & 1)) { + if (!(entry & 1)) { addr = (elf_addr *)(ldso_base + entry); __ensure(addr); *addr++ += ldso_base; - }else { + } else { // Odd entry indicates entry is a bitmap of the subsequent locations to be relocated. - // The first bit of an entry is always a marker about whether the entry is an address or a bitmap, - // discard it. + // The first bit of an entry is always a marker about whether the entry is an address or + // a bitmap, discard it. entry >>= 1; - for(int i = 0; entry; ++i) { - if(entry & 1) { + for (int i = 0; entry; ++i) { + if (entry & 1) { addr[i] += ldso_base; } entry >>= 1; @@ -171,29 +185,33 @@ extern "C" void relocateSelf() { extern "C" void relocateSelf68k(elf_dyn *dynamic, uintptr_t ldso_base) { size_t rela_offset = 0; size_t rela_size = 0; - for(size_t i = 0; dynamic[i].d_tag != DT_NULL; i++) { + for (size_t i = 0; dynamic[i].d_tag != DT_NULL; i++) { auto ent = &dynamic[i]; - switch(ent->d_tag) { - case DT_RELA: rela_offset = ent->d_un.d_ptr; break; - case DT_RELASZ: rela_size = ent->d_un.d_val; break; + switch (ent->d_tag) { + case DT_RELA: + rela_offset = ent->d_un.d_ptr; + break; + case DT_RELASZ: + rela_size = ent->d_un.d_val; + break; } } - for(size_t disp = 0; disp < rela_size; disp += sizeof(elf_rela)) { + for (size_t disp = 0; disp < rela_size; disp += sizeof(elf_rela)) { auto reloc = reinterpret_cast(ldso_base + rela_offset + disp); auto type = ELF_R_TYPE(reloc->r_info); auto p = reinterpret_cast(ldso_base + reloc->r_offset); - switch(type) { - case R_NONE: - break; + switch (type) { + case R_NONE: + break; - case R_RELATIVE: - *p = ldso_base + reloc->r_addend; - break; - default: { - __builtin_trap(); - } + case R_RELATIVE: + *p = ldso_base + reloc->r_addend; + break; + default: { + __builtin_trap(); + } } } } @@ -203,7 +221,7 @@ extern "C" void relocateSelf68k(elf_dyn *dynamic, uintptr_t ldso_base) { extern "C" void *lazyRelocate(SharedObject *object, unsigned int rel_index) { __ensure(object->lazyExplicitAddend); auto reloc = (elf_rela *)(object->baseAddress + object->lazyRelocTableOffset - + rel_index * sizeof(elf_rela)); + + rel_index * sizeof(elf_rela)); auto type = ELF_R_TYPE(reloc->r_info); auto symbol_index = ELF_R_SYM(reloc->r_info); @@ -211,63 +229,67 @@ extern "C" void *lazyRelocate(SharedObject *object, unsigned int rel_index) { __ensure(ELF_CLASS == ELFCLASS64); auto [sym, ver] = object->getSymbolByIndex(symbol_index); - auto p = Scope::resolveGlobalOrLocal(*globalScope, object->localScope, sym.getString(), object->objectRts, 0, ver); - if(!p) + auto p = Scope::resolveGlobalOrLocal( + *globalScope, object->localScope, sym.getString(), object->objectRts, 0, ver + ); + if (!p) mlibc::panicLogger() << "Unresolved JUMP_SLOT symbol" << frg::endlog; - //mlibc::infoLogger() << "Lazy relocation to " << symbol_str + // mlibc::infoLogger() << "Lazy relocation to " << symbol_str // << " resolved to " << pointer << frg::endlog; *(uint64_t *)(object->baseAddress + reloc->r_offset) = p->virtualAddress(); return (void *)p->virtualAddress(); } -extern "C" [[ gnu::visibility("default") ]] void *__rtld_allocateTcb() { +extern "C" [[gnu::visibility("default")]] void *__rtld_allocateTcb() { auto tcb = allocateTcb(); initTlsObjects(tcb, globalScope->_objects, false); return tcb; } extern "C" { - [[ gnu::visibility("hidden") ]] void dl_debug_state() { - // This function is used to signal changes in the debugging link map, - // GDB just sets a breakpoint on this function and we can call it - // everytime we update the link map. We don't need to implement - // anything besides defining and calling it. - } +[[gnu::visibility("hidden")]] void dl_debug_state() { + // This function is used to signal changes in the debugging link map, + // GDB just sets a breakpoint on this function and we can call it + // everytime we update the link map. We don't need to implement + // anything besides defining and calling it. +} } -extern "C" [[gnu::alias("dl_debug_state"), gnu::visibility("default")]] void _dl_debug_state() noexcept; +extern "C" [[gnu::alias("dl_debug_state"), gnu::visibility("default")]] void +_dl_debug_state() noexcept; // This symbol can be used by GDB to find the global interface structure -[[ gnu::visibility("default") ]] DebugInterface *_dl_debug_addr = &globalDebugInterface; +[[gnu::visibility("default")]] DebugInterface *_dl_debug_addr = &globalDebugInterface; -static frg::vector parseList(frg::string_view paths, frg::string_view separators) { +static frg::vector +parseList(frg::string_view paths, frg::string_view separators) { frg::vector list{getAllocator()}; size_t p = 0; - while(p < paths.size()) { + while (p < paths.size()) { size_t s; // Offset of next colon or end of string. - if(size_t cs = paths.find_first_of(separators, p); cs != size_t(-1)) { + if (size_t cs = paths.find_first_of(separators, p); cs != size_t(-1)) { s = cs; - }else{ + } else { s = paths.size(); } auto path = paths.sub_string(p, s - p); p = s + 1; - if(path.size() == 0) + if (path.size() == 0) continue; - if(path.ends_with("/")) { + if (path.ends_with("/")) { size_t i = path.size() - 1; - while(i > 0 && path[i] == '/') + while (i > 0 && path[i] == '/') i--; path = path.sub_string(0, i + 1); } - if(path == "/") + if (path == "/") path = ""; list.push_back(path); @@ -282,7 +304,7 @@ static constexpr uint64_t supportedDtFlags1 = DF_1_NOW; #endif extern "C" void *interpreterMain(uintptr_t *entry_stack) { - if(logEntryExit) + if (logEntryExit) mlibc::infoLogger() << "Entering ld.so" << frg::endlog; entryStack = entry_stack; @@ -290,7 +312,7 @@ extern "C" void *interpreterMain(uintptr_t *entry_stack) { // The TID is needed to use futexes, so this caching saves a lot of syscalls. earlyTcb.selfPointer = &earlyTcb; earlyTcb.tid = mlibc::this_tid(); - if(mlibc::sys_tcb_set(&earlyTcb)) + if (mlibc::sys_tcb_set(&earlyTcb)) __ensure(!"sys_tcb_set() failed"); mlibc::tcb_available_flag = true; @@ -307,15 +329,15 @@ extern "C" void *interpreterMain(uintptr_t *entry_stack) { const char *execfn = "(executable)"; #ifndef MLIBC_STATIC_BUILD - using ctor_fn = void(*)(void); + using ctor_fn = void (*)(void); ctor_fn *ldso_ctors = nullptr; size_t num_ldso_ctors = 0; auto ldso_base = getLdsoBase(); - if(logStartup) { - mlibc::infoLogger() << "ldso: Own base address is: 0x" - << frg::hex_fmt(ldso_base) << frg::endlog; + if (logStartup) { + mlibc::infoLogger() << "ldso: Own base address is: 0x" << frg::hex_fmt(ldso_base) + << frg::endlog; mlibc::infoLogger() << "ldso: Own dynamic section is at: " << _DYNAMIC << frg::endlog; } @@ -330,49 +352,62 @@ extern "C" void *interpreterMain(uintptr_t *entry_stack) { // Here, we make sure that the dynamic linker does not need relocations itself. uintptr_t strtab_offset = 0; uintptr_t soname_str = 0; - for(size_t i = 0; _DYNAMIC[i].d_tag != DT_NULL; i++) { + for (size_t i = 0; _DYNAMIC[i].d_tag != DT_NULL; i++) { auto ent = &_DYNAMIC[i]; - switch(ent->d_tag) { - case DT_STRTAB: strtab_offset = ent->d_un.d_ptr; break; - case DT_SONAME: soname_str = ent->d_un.d_val; break; - case DT_INIT_ARRAY: ldso_ctors = reinterpret_cast(ent->d_un.d_ptr + ldso_base); break; - case DT_INIT_ARRAYSZ: num_ldso_ctors = ent->d_un.d_val / sizeof(ctor_fn); break; - case DT_HASH: - case DT_GNU_HASH: - case DT_STRSZ: - case DT_SYMTAB: - case DT_SYMENT: - case DT_RELA: - case DT_RELASZ: - case DT_RELAENT: - case DT_RELACOUNT: - case DT_DEBUG: - case DT_REL: - case DT_RELSZ: - case DT_RELENT: - case DT_RELCOUNT: - case DT_RELR: - case DT_RELRSZ: - case DT_RELRENT: - case DT_PLTGOT: - case DT_BIND_NOW: - continue; - case DT_FLAGS: { - if((ent->d_un.d_val & ~supportedDtFlags) == 0) { + switch (ent->d_tag) { + case DT_STRTAB: + strtab_offset = ent->d_un.d_ptr; + break; + case DT_SONAME: + soname_str = ent->d_un.d_val; + break; + case DT_INIT_ARRAY: + ldso_ctors = reinterpret_cast(ent->d_un.d_ptr + ldso_base); + break; + case DT_INIT_ARRAYSZ: + num_ldso_ctors = ent->d_un.d_val / sizeof(ctor_fn); + break; + case DT_HASH: + case DT_GNU_HASH: + case DT_STRSZ: + case DT_SYMTAB: + case DT_SYMENT: + case DT_RELA: + case DT_RELASZ: + case DT_RELAENT: + case DT_RELACOUNT: + case DT_DEBUG: + case DT_REL: + case DT_RELSZ: + case DT_RELENT: + case DT_RELCOUNT: + case DT_RELR: + case DT_RELRSZ: + case DT_RELRENT: + case DT_PLTGOT: + case DT_BIND_NOW: continue; + case DT_FLAGS: { + if ((ent->d_un.d_val & ~supportedDtFlags) == 0) { + continue; + } + mlibc::panicLogger() + << "rtld: unexpected DT_FLAGS value of " << frg::hex_fmt(ent->d_un.d_val) + << " in program interpreter" << frg::endlog; + break; } - mlibc::panicLogger() << "rtld: unexpected DT_FLAGS value of " << frg::hex_fmt(ent->d_un.d_val) << " in program interpreter" << frg::endlog; - break; - } - case DT_FLAGS_1: { - if((ent->d_un.d_val & ~supportedDtFlags1) == 0) { - continue; + case DT_FLAGS_1: { + if ((ent->d_un.d_val & ~supportedDtFlags1) == 0) { + continue; + } + mlibc::panicLogger() + << "rtld: unexpected DT_FLAGS_1 value of " << frg::hex_fmt(ent->d_un.d_val) + << " in program interpreter" << frg::endlog; + break; } - mlibc::panicLogger() << "rtld: unexpected DT_FLAGS_1 value of " << frg::hex_fmt(ent->d_un.d_val) << " in program interpreter" << frg::endlog; - break; - } - default: - mlibc::panicLogger() << "rtld: unexpected dynamic entry " << ent->d_tag << " in program interpreter" << frg::endlog; + default: + mlibc::panicLogger() << "rtld: unexpected dynamic entry " << ent->d_tag + << " in program interpreter" << frg::endlog; } } __ensure(strtab_offset); @@ -383,23 +418,24 @@ extern "C" void *interpreterMain(uintptr_t *entry_stack) { aux += *aux + 1; // First, we skip argc and all args. __ensure(!*aux); aux++; - while(*aux) { // Loop through the environment. + while (*aux) { // Loop through the environment. auto env = reinterpret_cast(*aux); frg::string_view view{env}; size_t s = view.find_first('='); - if(s == size_t(-1)) - mlibc::panicLogger() << "rtld: environment '" << env << "' is missing a '='" << frg::endlog; + if (s == size_t(-1)) + mlibc::panicLogger() << "rtld: environment '" << env << "' is missing a '='" + << frg::endlog; auto name = view.sub_string(0, s); auto value = const_cast(view.data() + s + 1); - if(name == "LD_SHOW_AUXV" && *value && *value != '0') { + if (name == "LD_SHOW_AUXV" && *value && *value != '0') { ldShowAuxv = true; - }else if(name == "LD_LIBRARY_PATH" && *value) { - for(auto path : parseList(value, ":;")) + } else if (name == "LD_LIBRARY_PATH" && *value) { + for (auto path : parseList(value, ":;")) libraryPaths->push_back(path); - }else if(name == "LD_PRELOAD" && *value) { + } else if (name == "LD_PRELOAD" && *value) { *preloads = parseList(value, " :"); } @@ -412,66 +448,123 @@ extern "C" void *interpreterMain(uintptr_t *entry_stack) { } // Parse the actual vector. - while(true) { + while (true) { auto value = aux + 1; - if(!(*aux)) + if (!(*aux)) break; - if(ldShowAuxv) { - switch(*aux) { - case AT_PHDR: mlibc::infoLogger() << "AT_PHDR: 0x" << frg::hex_fmt{*value} << frg::endlog; break; - case AT_PHENT: mlibc::infoLogger() << "AT_PHENT: " << *value << frg::endlog; break; - case AT_PHNUM: mlibc::infoLogger() << "AT_PHNUM: " << *value << frg::endlog; break; - case AT_ENTRY: mlibc::infoLogger() << "AT_ENTRY: 0x" << frg::hex_fmt{*value} << frg::endlog; break; - case AT_PAGESZ: mlibc::infoLogger() << "AT_PAGESZ: " << *value << frg::endlog; break; - case AT_BASE: mlibc::infoLogger() << "AT_BASE: 0x" << frg::hex_fmt{*value} << frg::endlog; break; - case AT_FLAGS: mlibc::infoLogger() << "AT_FLAGS: 0x" << frg::hex_fmt{*value} << frg::endlog; break; - case AT_NOTELF: mlibc::infoLogger() << "AT_NOTELF: " << frg::hex_fmt{*value} << frg::endlog; break; - case AT_UID: mlibc::infoLogger() << "AT_UID: " << *value << frg::endlog; break; - case AT_EUID: mlibc::infoLogger() << "AT_EUID: " << *value << frg::endlog; break; - case AT_GID: mlibc::infoLogger() << "AT_GID: " << *value << frg::endlog; break; - case AT_EGID: mlibc::infoLogger() << "AT_EGID: " << *value << frg::endlog; break; + if (ldShowAuxv) { + switch (*aux) { + case AT_PHDR: + mlibc::infoLogger() << "AT_PHDR: 0x" << frg::hex_fmt{*value} << frg::endlog; + break; + case AT_PHENT: + mlibc::infoLogger() << "AT_PHENT: " << *value << frg::endlog; + break; + case AT_PHNUM: + mlibc::infoLogger() << "AT_PHNUM: " << *value << frg::endlog; + break; + case AT_ENTRY: + mlibc::infoLogger() << "AT_ENTRY: 0x" << frg::hex_fmt{*value} << frg::endlog; + break; + case AT_PAGESZ: + mlibc::infoLogger() << "AT_PAGESZ: " << *value << frg::endlog; + break; + case AT_BASE: + mlibc::infoLogger() << "AT_BASE: 0x" << frg::hex_fmt{*value} << frg::endlog; + break; + case AT_FLAGS: + mlibc::infoLogger() << "AT_FLAGS: 0x" << frg::hex_fmt{*value} << frg::endlog; + break; + case AT_NOTELF: + mlibc::infoLogger() << "AT_NOTELF: " << frg::hex_fmt{*value} << frg::endlog; + break; + case AT_UID: + mlibc::infoLogger() << "AT_UID: " << *value << frg::endlog; + break; + case AT_EUID: + mlibc::infoLogger() << "AT_EUID: " << *value << frg::endlog; + break; + case AT_GID: + mlibc::infoLogger() << "AT_GID: " << *value << frg::endlog; + break; + case AT_EGID: + mlibc::infoLogger() << "AT_EGID: " << *value << frg::endlog; + break; #ifdef AT_PLATFORM - case AT_PLATFORM: mlibc::infoLogger() << "AT_PLATFORM: " << reinterpret_cast(*value) << frg::endlog; break; + case AT_PLATFORM: + mlibc::infoLogger() + << "AT_PLATFORM: " << reinterpret_cast(*value) << frg::endlog; + break; #endif #ifdef AT_HWCAP - case AT_HWCAP: mlibc::infoLogger() << "AT_HWCAP: " << frg::hex_fmt{*value} << frg::endlog; break; + case AT_HWCAP: + mlibc::infoLogger() << "AT_HWCAP: " << frg::hex_fmt{*value} << frg::endlog; + break; #endif #ifdef AT_CLKTCK - case AT_CLKTCK: mlibc::infoLogger() << "AT_CLKTCK: " << *value << frg::endlog; break; + case AT_CLKTCK: + mlibc::infoLogger() << "AT_CLKTCK: " << *value << frg::endlog; + break; #endif #ifdef AT_FPUCW - case AT_FPUCW: mlibc::infoLogger() << "AT_FPUCW: " << frg::hex_fmt{*value} << frg::endlog; break; + case AT_FPUCW: + mlibc::infoLogger() << "AT_FPUCW: " << frg::hex_fmt{*value} << frg::endlog; + break; #endif #ifdef AT_SECURE - case AT_SECURE: mlibc::infoLogger() << "AT_SECURE: " << *value << frg::endlog; break; + case AT_SECURE: + mlibc::infoLogger() << "AT_SECURE: " << *value << frg::endlog; + break; #endif #ifdef AT_RANDOM - case AT_RANDOM: mlibc::infoLogger() << "AT_RANDOM: 0x" << frg::hex_fmt{*value} << frg::endlog; break; + case AT_RANDOM: + mlibc::infoLogger() << "AT_RANDOM: 0x" << frg::hex_fmt{*value} << frg::endlog; + break; #endif #ifdef AT_EXECFN - case AT_EXECFN: mlibc::infoLogger() << "AT_EXECFN: " << reinterpret_cast(*value) << frg::endlog; break; + case AT_EXECFN: + mlibc::infoLogger() + << "AT_EXECFN: " << reinterpret_cast(*value) << frg::endlog; + break; #endif #ifdef AT_SYSINFO_EHDR - case AT_SYSINFO_EHDR: mlibc::infoLogger() << "AT_SYSINFO_EHDR: 0x" << frg::hex_fmt{*value} << frg::endlog; break; + case AT_SYSINFO_EHDR: + mlibc::infoLogger() + << "AT_SYSINFO_EHDR: 0x" << frg::hex_fmt{*value} << frg::endlog; + break; #endif } } // TODO: Whitelist auxiliary vector entries here? - switch(*aux) { - case AT_PHDR: phdr_pointer = reinterpret_cast(*value); break; - case AT_PHENT: phdr_entry_size = *value; break; - case AT_PHNUM: phdr_count = *value; break; - case AT_ENTRY: entry_pointer = reinterpret_cast(*value); break; - case AT_EXECFN: execfn = reinterpret_cast(*value); break; - case AT_RANDOM: stack_entropy = reinterpret_cast(*value); break; - case AT_SECURE: rtldConfig.secureRequired = reinterpret_cast(*value); break; + switch (*aux) { + case AT_PHDR: + phdr_pointer = reinterpret_cast(*value); + break; + case AT_PHENT: + phdr_entry_size = *value; + break; + case AT_PHNUM: + phdr_count = *value; + break; + case AT_ENTRY: + entry_pointer = reinterpret_cast(*value); + break; + case AT_EXECFN: + execfn = reinterpret_cast(*value); + break; + case AT_RANDOM: + stack_entropy = reinterpret_cast(*value); + break; + case AT_SECURE: + rtldConfig.secureRequired = reinterpret_cast(*value); + break; } aux += 2; } - globalDebugInterface.base = reinterpret_cast(ldso_base); + globalDebugInterface.base = reinterpret_cast(ldso_base); // This is here because libgcc will add a global constructor on glibc Linux // (which is what it believes we are due to the aarch64-linux-gnu toolchain) @@ -481,33 +574,31 @@ extern "C" void *interpreterMain(uintptr_t *entry_stack) { // using the host toolchain. #if defined(__aarch64__) && defined(__gnu_linux__) for (size_t i = 0; i < num_ldso_ctors; i++) { - if(logStartup) + if (logStartup) mlibc::infoLogger() << "ldso: Running own constructor at " - << reinterpret_cast(ldso_ctors[i]) - << frg::endlog; + << reinterpret_cast(ldso_ctors[i]) << frg::endlog; ldso_ctors[i](); } #else if (num_ldso_ctors > 0) { - mlibc::panicLogger() << "ldso: Found unexpected own global constructor(s), init_array starts at: " - << ldso_ctors - << frg::endlog; + mlibc::panicLogger() + << "ldso: Found unexpected own global constructor(s), init_array starts at: " + << ldso_ctors << frg::endlog; } #endif #else - auto ehdr = reinterpret_cast(__ehdr_start); - phdr_pointer = reinterpret_cast((uintptr_t)ehdr->e_phoff + (uintptr_t)ehdr); + auto ehdr = reinterpret_cast(__ehdr_start); + phdr_pointer = reinterpret_cast((uintptr_t)ehdr->e_phoff + (uintptr_t)ehdr); phdr_entry_size = ehdr->e_phentsize; phdr_count = ehdr->e_phnum; - entry_pointer = reinterpret_cast(ehdr->e_entry); + entry_pointer = reinterpret_cast(ehdr->e_entry); #endif __ensure(phdr_pointer); __ensure(entry_pointer); - if(logStartup) - mlibc::infoLogger() << "ldso: Executable PHDRs are at " << phdr_pointer - << frg::endlog; + if (logStartup) + mlibc::infoLogger() << "ldso: Executable PHDRs are at " << phdr_pointer << frg::endlog; // perform the initial dynamic linking initialRepository.initialize(); @@ -517,9 +608,9 @@ extern "C" void *interpreterMain(uintptr_t *entry_stack) { // Add the dynamic linker, as well as the exectuable to the repository. #ifndef MLIBC_STATIC_BUILD auto ldso_soname = reinterpret_cast(ldso_base + strtab_offset + soname_str); - auto ldso = initialRepository->injectObjectFromDts(ldso_soname, - frg::string { getAllocator() }, - ldso_base, _DYNAMIC, 1); + auto ldso = initialRepository->injectObjectFromDts( + ldso_soname, frg::string{getAllocator()}, ldso_base, _DYNAMIC, 1 + ); auto ldso_ehdr = reinterpret_cast(__ehdr_start); auto ldso_phdr = reinterpret_cast(ldso_base + ldso_ehdr->e_phoff); @@ -529,9 +620,15 @@ extern "C" void *interpreterMain(uintptr_t *entry_stack) { ldso->phdrEntrySize = ldso_ehdr->e_phentsize; // TODO: support non-zero base addresses? - executableSO = initialRepository->injectObjectFromPhdrs(execfn, - frg::string { execfn, getAllocator() }, - phdr_pointer, phdr_entry_size, phdr_count, entry_pointer, 1); + executableSO = initialRepository->injectObjectFromPhdrs( + execfn, + frg::string{execfn, getAllocator()}, + phdr_pointer, + phdr_entry_size, + phdr_count, + entry_pointer, + 1 + ); // We can't initialise the ldso object after the executable SO, // so we have to set the ldso path after loading both. @@ -544,10 +641,16 @@ extern "C" void *interpreterMain(uintptr_t *entry_stack) { current->dependenciesDiscovered = true; } #else - executableSO = initialRepository->injectStaticObject(execfn, - frg::string{ execfn, getAllocator() }, - phdr_pointer, phdr_entry_size, phdr_count, entry_pointer, 1); - globalDebugInterface.base = (void*)executableSO->baseAddress; + executableSO = initialRepository->injectStaticObject( + execfn, + frg::string{execfn, getAllocator()}, + phdr_pointer, + phdr_entry_size, + phdr_count, + entry_pointer, + 1 + ); + globalDebugInterface.base = (void *)executableSO->baseAddress; #endif globalDebugInterface.head = &executableSO->linkMap; @@ -559,7 +662,7 @@ extern "C" void *interpreterMain(uintptr_t *entry_stack) { auto tcb = allocateTcb(); tcb->tid = earlyTcb.tid; - if(mlibc::sys_tcb_set(tcb)) + if (mlibc::sys_tcb_set(tcb)) __ensure(!"sys_tcb_set() failed"); globalDebugInterface.ver = 1; @@ -569,50 +672,49 @@ extern "C" void *interpreterMain(uintptr_t *entry_stack) { linker.initObjects(initialRepository.get()); - if(logEntryExit) - mlibc::infoLogger() << "Leaving ld.so, jump to " - << (void *)executableSO->entry << frg::endlog; + if (logEntryExit) + mlibc::infoLogger() << "Leaving ld.so, jump to " << (void *)executableSO->entry + << frg::endlog; return executableSO->entry; } const char *lastError; -extern "C" [[ gnu::visibility("default") ]] uintptr_t *__dlapi_entrystack() { - return entryStack; -} +extern "C" [[gnu::visibility("default")]] uintptr_t *__dlapi_entrystack() { return entryStack; } -extern "C" [[ gnu::visibility("default") ]] +extern "C" [[gnu::visibility("default")]] const char *__dlapi_error() { auto error = lastError; lastError = nullptr; return error; } -extern "C" [[ gnu::visibility("default") ]] +extern "C" [[gnu::visibility("default")]] void *__dlapi_get_tls(struct __abi_tls_entry *entry) { return reinterpret_cast(accessDtv(entry->object)) + entry->offset; } -extern "C" [[ gnu::visibility("default") ]] +extern "C" [[gnu::visibility("default")]] const mlibc::RtldConfig &__dlapi_get_config() { return rtldConfig; } -extern "C" [[ gnu::visibility("default") ]] void __dlapi_exit() { +extern "C" [[gnu::visibility("default")]] void __dlapi_exit() { initialRepository->destructObjects(); } #if __MLIBC_POSIX_OPTION -extern "C" [[ gnu::visibility("default") ]] +extern "C" [[gnu::visibility("default")]] void *__dlapi_open(const char *file, int flags, void *returnAddress) { if (logDlCalls) - mlibc::infoLogger() << "rtld: __dlapi_open(" << (file ? file : "nullptr") << ")" << frg::endlog; + mlibc::infoLogger() << "rtld: __dlapi_open(" << (file ? file : "nullptr") << ")" + << frg::endlog; if (flags & RTLD_DEEPBIND) mlibc::infoLogger() << "rtld: dlopen(RTLD_DEEPBIND) is unsupported" << frg::endlog; - if(!file) + if (!file) return executableSO; // TODO: Thread-safety! @@ -622,8 +724,8 @@ void *__dlapi_open(const char *file, int flags, void *returnAddress) { if (flags & RTLD_NOLOAD) { object = initialRepository->findLoadedObject(file); if (object && object->globalRts == 0 && (flags & RTLD_GLOBAL)) { - // The object was opened with RTLD_LOCAL, but we are called with RTLD_NOLOAD | RTLD_GLOBAL. - // According to the man page, we should promote to the global scope here. + // The object was opened with RTLD_LOCAL, but we are called with RTLD_NOLOAD | + // RTLD_GLOBAL. According to the man page, we should promote to the global scope here. object->globalRts = rts; globalScope->appendObject(object); } @@ -637,36 +739,37 @@ void *__dlapi_open(const char *file, int flags, void *returnAddress) { SharedObject *origin = initialRepository->findCaller(returnAddress); if (!origin) { mlibc::panicLogger() << "rtld: unable to determine calling object of dlopen " - << "(ra = " << returnAddress << ")" << frg::endlog; + << "(ra = " << returnAddress << ")" << frg::endlog; } - objectResult = initialRepository->requestObjectWithName(file, origin, newScope, !isGlobal, rts); + objectResult = + initialRepository->requestObjectWithName(file, origin, newScope, !isGlobal, rts); } else { objectResult = initialRepository->requestObjectAtPath(file, newScope, !isGlobal, rts); } - if(!objectResult) { + if (!objectResult) { switch (objectResult.error()) { - case LinkerError::success: - __builtin_unreachable(); - case LinkerError::notFound: - lastError = "Cannot locate requested DSO"; - break; - case LinkerError::fileTooShort: - lastError = "File too short"; - break; - case LinkerError::notElf: - lastError = "File is not an ELF file"; - break; - case LinkerError::wrongElfType: - lastError = "File has wrong ELF type"; - break; - case LinkerError::outOfMemory: - lastError = "Out of memory"; - break; - case LinkerError::invalidProgramHeader: - lastError = "File has invalid program header"; - break; + case LinkerError::success: + __builtin_unreachable(); + case LinkerError::notFound: + lastError = "Cannot locate requested DSO"; + break; + case LinkerError::fileTooShort: + lastError = "File too short"; + break; + case LinkerError::notElf: + lastError = "File is not an ELF file"; + break; + case LinkerError::wrongElfType: + lastError = "File has wrong ELF type"; + break; + case LinkerError::outOfMemory: + lastError = "Out of memory"; + break; + case LinkerError::invalidProgramHeader: + lastError = "File has invalid program header"; + break; } return nullptr; } @@ -675,7 +778,7 @@ void *__dlapi_open(const char *file, int flags, void *returnAddress) { initialRepository->discoverDependenciesFromLoadedObject(object); for (size_t i = 0; i < initialRepository->dependencyQueue.size(); i++) { auto current = initialRepository->dependencyQueue[i]; - if(!current->dependenciesDiscovered) { + if (!current->dependenciesDiscovered) { initialRepository->discoverDependenciesFromLoadedObject(current); current->dependenciesDiscovered = true; } @@ -691,7 +794,7 @@ void *__dlapi_open(const char *file, int flags, void *returnAddress) { return object; } -extern "C" [[ gnu::visibility("default") ]] +extern "C" [[gnu::visibility("default")]] void *__dlapi_resolve(void *handle, const char *string, void *returnAddress, const char *version) { if (logDlCalls) { const char *name; @@ -706,13 +809,13 @@ void *__dlapi_resolve(void *handle, const char *string, void *returnAddress, con } mlibc::infoLogger() << "rtld: __dlapi_resolve(" << (quote ? "\"" : "") << name - << (quote ? "\"" : "") << ", \"" << string << "\")" << frg::endlog; + << (quote ? "\"" : "") << ", \"" << string << "\")" << frg::endlog; } frg::optional target; frg::optional targetVersion = frg::null_opt; - if(version) + if (version) targetVersion = SymbolVersion{version}; if (handle == RTLD_DEFAULT) { @@ -721,10 +824,12 @@ void *__dlapi_resolve(void *handle, const char *string, void *returnAddress, con SharedObject *origin = initialRepository->findCaller(returnAddress); if (!origin) { mlibc::panicLogger() << "rtld: unable to determine calling object of dlsym " - << "(ra = " << returnAddress << ")" << frg::endlog; + << "(ra = " << returnAddress << ")" << frg::endlog; } - target = Scope::resolveGlobalOrLocalNext(*globalScope, origin->localScope, string, origin, targetVersion); + target = Scope::resolveGlobalOrLocalNext( + *globalScope, origin->localScope, string, origin, targetVersion + ); } else { // POSIX does not unambiguously state how dlsym() is supposed to work; it just // states that "The symbol resolution algorithm used shall be dependency order @@ -741,25 +846,24 @@ void *__dlapi_resolve(void *handle, const char *string, void *returnAddress, con frg::vector queue{getAllocator()}; - struct Token { }; - frg::hash_map< - SharedObject *, Token, - frg::hash, MemoryAllocator - > visited{frg::hash{}, getAllocator()}; + struct Token {}; + frg::hash_map, MemoryAllocator> visited{ + frg::hash{}, getAllocator() + }; auto root = reinterpret_cast(handle); visited.insert(root, Token{}); queue.push_back(root); - for(size_t i = 0; i < queue.size(); i++) { + for (size_t i = 0; i < queue.size(); i++) { auto current = queue[i]; target = resolveInObject(current, string, targetVersion); - if(target) + if (target) break; - for(auto dep : current->dependencies) { - if(visited.get(dep)) + for (auto dep : current->dependencies) { + if (visited.get(dep)) continue; visited.insert(dep, Token{}); queue.push_back(dep); @@ -786,20 +890,20 @@ struct __dlapi_symbol { void *link_map; }; -extern "C" [[ gnu::visibility("default") ]] +extern "C" [[gnu::visibility("default")]] int __dlapi_reverse(const void *ptr, __dlapi_symbol *info) { if (logDlCalls) mlibc::infoLogger() << "rtld: __dlapi_reverse(" << ptr << ")" << frg::endlog; - for(size_t i = 0; i < initialRepository->loadedObjects.size(); i++) { + for (size_t i = 0; i < initialRepository->loadedObjects.size(); i++) { auto object = initialRepository->loadedObjects[i]; - auto eligible = [&] (ObjectSymbol cand) { - if(cand.symbol()->st_shndx == SHN_UNDEF) + auto eligible = [&](ObjectSymbol cand) { + if (cand.symbol()->st_shndx == SHN_UNDEF) return false; auto bind = ELF_ST_BIND(cand.symbol()->st_info); - if(bind != STB_GLOBAL && bind != STB_WEAK) + if (bind != STB_GLOBAL && bind != STB_WEAK) return false; return true; @@ -807,13 +911,15 @@ int __dlapi_reverse(const void *ptr, __dlapi_symbol *info) { auto hash_table = (Elf64_Word *)(object->baseAddress + object->hashTableOffset); auto num_symbols = hash_table[1]; - for(size_t i = 0; i < num_symbols; i++) { - ObjectSymbol cand{object, (elf_sym *)(object->baseAddress - + object->symbolTableOffset + i * sizeof(elf_sym))}; - if(eligible(cand) && cand.virtualAddress() == reinterpret_cast(ptr)) { + for (size_t i = 0; i < num_symbols; i++) { + ObjectSymbol cand{ + object, + (elf_sym *)(object->baseAddress + object->symbolTableOffset + i * sizeof(elf_sym)) + }; + if (eligible(cand) && cand.virtualAddress() == reinterpret_cast(ptr)) { if (logDlCalls) - mlibc::infoLogger() << "rtld: Found symbol " << cand.getString() << " in object " - << object->path << frg::endlog; + mlibc::infoLogger() << "rtld: Found symbol " << cand.getString() + << " in object " << object->path << frg::endlog; info->file = object->path.data(); info->base = reinterpret_cast(object->baseAddress); @@ -827,17 +933,18 @@ int __dlapi_reverse(const void *ptr, __dlapi_symbol *info) { } // Not found, find the DSO it should be in. - for(size_t i = 0; i < initialRepository->loadedObjects.size(); i++) { + for (size_t i = 0; i < initialRepository->loadedObjects.size(); i++) { auto object = initialRepository->loadedObjects[i]; - for(size_t j = 0; j < object->phdrCount; j++) { + for (size_t j = 0; j < object->phdrCount; j++) { auto phdr = (elf_phdr *)((uintptr_t)object->phdrPointer + j * object->phdrEntrySize); - if(phdr->p_type != PT_LOAD) { + if (phdr->p_type != PT_LOAD) { continue; } uintptr_t start = object->baseAddress + phdr->p_vaddr; uintptr_t end = start + phdr->p_memsz; - if(reinterpret_cast(ptr) >= start && reinterpret_cast(ptr) < end) { + if (reinterpret_cast(ptr) >= start + && reinterpret_cast(ptr) < end) { mlibc::infoLogger() << "rtld: Found DSO " << object->path << frg::endlog; info->file = object->path.data(); info->base = reinterpret_cast(object->baseAddress); @@ -856,7 +963,7 @@ int __dlapi_reverse(const void *ptr, __dlapi_symbol *info) { return -1; } -extern "C" [[ gnu::visibility("default") ]] +extern "C" [[gnu::visibility("default")]] int __dlapi_close(void *) { if (logDlCalls) mlibc::infoLogger() << "mlibc: dlclose() is a no-op" << frg::endlog; @@ -865,20 +972,20 @@ int __dlapi_close(void *) { #endif -extern "C" [[ gnu::visibility("default") ]] -int __dlapi_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void*), void *data) { +extern "C" [[gnu::visibility("default")]] +int __dlapi_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *), void *data) { int last_return = 0; for (auto object : initialRepository->loadedObjects) { struct dl_phdr_info info; info.dlpi_addr = object->baseAddress; info.dlpi_name = object->name.data(); - if(object->isMainObject) { + if (object->isMainObject) { info.dlpi_name = ""; } else { info.dlpi_name = object->name.data(); } - info.dlpi_phdr = static_cast(object->phdrPointer); + info.dlpi_phdr = static_cast(object->phdrPointer); info.dlpi_phnum = object->phdrCount; info.dlpi_adds = rtsCounter; info.dlpi_subs = 0; // TODO(geert): implement dlclose(). @@ -889,14 +996,14 @@ int __dlapi_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void*), info.dlpi_tls_data = tryAccessDtv(object); last_return = callback(&info, sizeof(struct dl_phdr_info), data); - if(last_return) + if (last_return) return last_return; } return last_return; } -extern "C" [[ gnu::visibility("default") ]] +extern "C" [[gnu::visibility("default")]] void __dlapi_enter(uintptr_t *entry_stack) { #if MLIBC_STATIC_BUILD interpreterMain(entry_stack); @@ -907,30 +1014,31 @@ void __dlapi_enter(uintptr_t *entry_stack) { #if __MLIBC_GLIBC_OPTION -extern "C" [[gnu::visibility("default")]] int _dl_find_object(void *address, dl_find_object *result) { - for(const SharedObject *object : initialRepository->loadedObjects) { - if(object->baseAddress > reinterpret_cast(address)) +extern "C" [[gnu::visibility("default")]] int +_dl_find_object(void *address, dl_find_object *result) { + for (const SharedObject *object : initialRepository->loadedObjects) { + if (object->baseAddress > reinterpret_cast(address)) continue; - if(object->inLinkMap) + if (object->inLinkMap) result->dlfo_link_map = (link_map *)&object->linkMap; else result->dlfo_link_map = nullptr; uintptr_t end_addr = 0; - for(size_t j = 0; j < object->phdrCount; j++) { + for (size_t j = 0; j < object->phdrCount; j++) { auto phdr = (elf_phdr *)((uintptr_t)object->phdrPointer + j * object->phdrEntrySize); - if(phdr->p_type == DLFO_EH_SEGMENT_TYPE) { + if (phdr->p_type == DLFO_EH_SEGMENT_TYPE) { result->dlfo_eh_frame = (void *)(object->baseAddress + phdr->p_vaddr); continue; } - if(phdr->p_type != PT_LOAD) { + if (phdr->p_type != PT_LOAD) { continue; } end_addr = frg::max(end_addr, phdr->p_vaddr + phdr->p_memsz); } - if(reinterpret_cast(address) > object->baseAddress + end_addr) + if (reinterpret_cast(address) > object->baseAddress + end_addr) continue; result->dlfo_flags = 0; @@ -939,11 +1047,15 @@ extern "C" [[gnu::visibility("default")]] int _dl_find_object(void *address, dl_ // TODO: fill these fields with proper values #if DLFO_STRUCT_HAS_EH_DBASE - mlibc::infoLogger() << "mlibc: _dl_find_object dlfo_eh_dbase is not implemented and always returns NULL" << frg::endlog; + mlibc::infoLogger() + << "mlibc: _dl_find_object dlfo_eh_dbase is not implemented and always returns NULL" + << frg::endlog; result->dlfo_eh_dbase = nullptr; #endif // DLFO_STRUCT_HAS_EH_DBASE #if DLFO_STRUCT_HAS_EH_COUNT - mlibc::infoLogger() << "mlibc: _dl_find_object dlfo_eh_count is not implemented and always returns 0" << frg::endlog; + mlibc::infoLogger() + << "mlibc: _dl_find_object dlfo_eh_count is not implemented and always returns 0" + << frg::endlog; result->dlfo_eh_count = 0; #endif // DLFO_STRUCT_HAS_EH_COUNT @@ -972,16 +1084,16 @@ extern "C" unsigned long __getauxval(unsigned long type) { aux += *aux + 1; // Skip argc and all arguments __ensure(!*aux); aux++; - while(*aux) // Now, we skip the environment. + while (*aux) // Now, we skip the environment. aux++; aux++; // Parse the auxiliary vector. - while(true) { + while (true) { auto value = aux + 1; - if(*aux == AT_NULL) { + if (*aux == AT_NULL) { return 0; - }else if(*aux == type) { + } else if (*aux == type) { return *value; } aux += 2; diff --git a/options/rtld/include/mlibc/rtld-abi.hpp b/options/rtld/include/mlibc/rtld-abi.hpp index 9ab707ef34..39806eee55 100644 --- a/options/rtld/include/mlibc/rtld-abi.hpp +++ b/options/rtld/include/mlibc/rtld-abi.hpp @@ -3,7 +3,8 @@ #include -#if defined(__x86_64__) || defined(__aarch64__) || defined(__i386__) || defined(__riscv) || defined (__m68k__) || defined(__loongarch64) +#if defined(__x86_64__) || defined(__aarch64__) || defined(__i386__) || defined(__riscv) \ + || defined(__m68k__) || defined(__loongarch64) struct __abi_tls_entry { struct SharedObject *object; diff --git a/sysdeps/linux/generic/sysdeps.cpp b/sysdeps/linux/generic/sysdeps.cpp index c3ae67ba7c..8a4fbacaca 100644 --- a/sysdeps/linux/generic/sysdeps.cpp +++ b/sysdeps/linux/generic/sysdeps.cpp @@ -5,20 +5,20 @@ #include -#include -#include #include #include +#include +#include #if __MLIBC_LINUX_OPTION -# include +#include #endif +#include "cxx-syscall.hpp" +#include +#include #include #include -#include #include -#include #include -#include "cxx-syscall.hpp" #if __MLIBC_LINUX_OPTION && !defined(MLIBC_BUILDING_RTLD) @@ -26,12 +26,16 @@ #endif -#define STUB_ONLY { __ensure(!"STUB_ONLY function was called"); __builtin_unreachable(); } +#define STUB_ONLY \ + { \ + __ensure(!"STUB_ONLY function was called"); \ + __builtin_unreachable(); \ + } #define UNUSED(x) (void)(x); #ifndef MLIBC_BUILDING_RTLD extern "C" long __do_syscall_ret(unsigned long ret) { - if(ret > -4096UL) { + if (ret > -4096UL) { errno = -ret; return -1; } @@ -43,16 +47,14 @@ namespace mlibc { void sys_libc_log(const char *message) { size_t n = 0; - while(message[n]) + while (message[n]) n++; do_syscall(SYS_write, 2, message, n); char lf = '\n'; do_syscall(SYS_write, 2, &lf, 1); } -void sys_libc_panic() { - __builtin_trap(); -} +void sys_libc_panic() { __builtin_trap(); } #if defined(__i386__) @@ -60,12 +62,12 @@ struct user_desc { unsigned int entry_number; unsigned long base_addr; unsigned int limit; - unsigned int seg_32bit: 1; - unsigned int contents: 2; - unsigned int read_exec_only: 1; - unsigned int limit_in_pages: 1; - unsigned int seg_not_present: 1; - unsigned int useable: 1; + unsigned int seg_32bit : 1; + unsigned int contents : 2; + unsigned int read_exec_only : 1; + unsigned int limit_in_pages : 1; + unsigned int seg_not_present : 1; + unsigned int useable : 1; }; #endif @@ -80,36 +82,36 @@ extern "C" void *__m68k_read_tp() { int sys_tcb_set(void *pointer) { #if defined(__x86_64__) auto ret = do_syscall(SYS_arch_prctl, 0x1002 /* ARCH_SET_FS */, pointer); - if(int e = sc_error(ret); e) + if (int e = sc_error(ret); e) return e; #elif defined(__i386__) struct user_desc desc = { - .entry_number = static_cast(-1), - .base_addr = uintptr_t(pointer), - .limit = 0xfffff, - .seg_32bit = 1, - .contents = 0, - .read_exec_only = 0, - .limit_in_pages = 1, - .seg_not_present = 0, - .useable = 1, + .entry_number = static_cast(-1), + .base_addr = uintptr_t(pointer), + .limit = 0xfffff, + .seg_32bit = 1, + .contents = 0, + .read_exec_only = 0, + .limit_in_pages = 1, + .seg_not_present = 0, + .useable = 1, }; auto ret = do_syscall(SYS_set_thread_area, &desc); __ensure(!sc_error(ret)); - asm volatile ("movw %w0, %%gs" : : "q"(desc.entry_number * 8 + 3) :); + asm volatile("movw %w0, %%gs" : : "q"(desc.entry_number * 8 + 3) :); #elif defined(__riscv) uintptr_t thread_data = reinterpret_cast(pointer) + sizeof(Tcb); - asm volatile ("mv tp, %0" :: "r"(thread_data)); -#elif defined (__aarch64__) + asm volatile("mv tp, %0" ::"r"(thread_data)); +#elif defined(__aarch64__) uintptr_t thread_data = reinterpret_cast(pointer) + sizeof(Tcb) - 0x10; - asm volatile ("msr tpidr_el0, %0" :: "r"(thread_data)); -#elif defined (__m68k__) + asm volatile("msr tpidr_el0, %0" ::"r"(thread_data)); +#elif defined(__m68k__) auto ret = do_syscall(__NR_set_thread_area, (uintptr_t)pointer + 0x7000 + sizeof(Tcb)); - if(int e = sc_error(ret); e) + if (int e = sc_error(ret); e) return e; #elif defined(__loongarch64) uintptr_t thread_data = reinterpret_cast(pointer) + sizeof(Tcb); - asm volatile ("move $tp, %0" :: "r"(thread_data)); + asm volatile("move $tp, %0" ::"r"(thread_data)); #else #error "Missing architecture specific code." #endif @@ -117,23 +119,22 @@ int sys_tcb_set(void *pointer) { } int sys_anon_allocate(size_t size, void **pointer) { - return sys_vm_map(nullptr, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, - -1, 0, pointer); -} -int sys_anon_free(void *pointer, size_t size) { - return sys_vm_unmap(pointer, size); + return sys_vm_map( + nullptr, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0, pointer + ); } +int sys_anon_free(void *pointer, size_t size) { return sys_vm_unmap(pointer, size); } int sys_fadvise(int fd, off_t offset, off_t length, int advice) { auto ret = do_syscall(SYS_fadvise64, fd, offset, length, advice); - if(int e = sc_error(ret); e) + if (int e = sc_error(ret); e) return e; return 0; } int sys_open(const char *path, int flags, mode_t mode, int *fd) { auto ret = do_cp_syscall(SYS_openat, AT_FDCWD, path, flags, mode); - if(int e = sc_error(ret); e) + if (int e = sc_error(ret); e) return e; *fd = sc_int_result(ret); return 0; @@ -149,21 +150,21 @@ int sys_openat(int dirfd, const char *path, int flags, mode_t mode, int *fd) { int sys_close(int fd) { auto ret = do_cp_syscall(SYS_close, fd); - if(int e = sc_error(ret); e) + if (int e = sc_error(ret); e) return e; return 0; } int sys_dup2(int fd, int flags, int newfd) { auto ret = do_cp_syscall(SYS_dup3, fd, newfd, flags); - if(int e = sc_error(ret); e) + if (int e = sc_error(ret); e) return e; return 0; } int sys_read(int fd, void *buffer, size_t size, ssize_t *bytes_read) { auto ret = do_cp_syscall(SYS_read, fd, buffer, size); - if(int e = sc_error(ret); e) + if (int e = sc_error(ret); e) return e; *bytes_read = sc_int_result(ret); return 0; @@ -171,7 +172,7 @@ int sys_read(int fd, void *buffer, size_t size, ssize_t *bytes_read) { int sys_readv(int fd, const struct iovec *iovs, int iovc, ssize_t *bytes_read) { auto ret = do_cp_syscall(SYS_readv, fd, iovs, iovc); - if(int e = sc_error(ret); e) + if (int e = sc_error(ret); e) return e; *bytes_read = sc_int_result(ret); return 0; @@ -179,16 +180,16 @@ int sys_readv(int fd, const struct iovec *iovs, int iovc, ssize_t *bytes_read) { int sys_write(int fd, const void *buffer, size_t size, ssize_t *bytes_written) { auto ret = do_cp_syscall(SYS_write, fd, buffer, size); - if(int e = sc_error(ret); e) + if (int e = sc_error(ret); e) return e; - if(bytes_written) + if (bytes_written) *bytes_written = sc_int_result(ret); return 0; } int sys_seek(int fd, off_t offset, int whence, off_t *new_offset) { auto ret = do_syscall(SYS_lseek, fd, offset, whence); - if(int e = sc_error(ret); e) + if (int e = sc_error(ret); e) return e; *new_offset = sc_int_result(ret); return 0; @@ -196,28 +197,28 @@ int sys_seek(int fd, off_t offset, int whence, off_t *new_offset) { int sys_chmod(const char *pathname, mode_t mode) { auto ret = do_cp_syscall(SYS_fchmodat, AT_FDCWD, pathname, mode); - if(int e = sc_error(ret); e) + if (int e = sc_error(ret); e) return e; return 0; } int sys_fchmod(int fd, mode_t mode) { auto ret = do_cp_syscall(SYS_fchmod, fd, mode); - if(int e = sc_error(ret); e) + if (int e = sc_error(ret); e) return e; return 0; } int sys_fchmodat(int fd, const char *pathname, mode_t mode, int flags) { auto ret = do_cp_syscall(SYS_fchmodat, fd, pathname, mode, flags); - if(int e = sc_error(ret); e) + if (int e = sc_error(ret); e) return e; return 0; } int sys_fchownat(int dirfd, const char *pathname, uid_t owner, gid_t group, int flags) { auto ret = do_cp_syscall(SYS_fchownat, dirfd, pathname, owner, group, flags); - if(int e = sc_error(ret); e) + if (int e = sc_error(ret); e) return e; return 0; } @@ -229,19 +230,18 @@ int sys_utimensat(int dirfd, const char *pathname, const struct timespec times[2 return 0; } -int sys_vm_map(void *hint, size_t size, int prot, int flags, - int fd, off_t offset, void **window) { - if(offset % 4096) +int sys_vm_map(void *hint, size_t size, int prot, int flags, int fd, off_t offset, void **window) { + if (offset % 4096) return EINVAL; - if(size >= PTRDIFF_MAX) + if (size >= PTRDIFF_MAX) return ENOMEM; #if defined(SYS_mmap2) - auto ret = do_syscall(SYS_mmap2, hint, size, prot, flags, fd, offset/4096); + auto ret = do_syscall(SYS_mmap2, hint, size, prot, flags, fd, offset / 4096); #else auto ret = do_syscall(SYS_mmap, hint, size, prot, flags, fd, offset); #endif // TODO: musl fixes up EPERM errors from the kernel. - if(int e = sc_error(ret); e) + if (int e = sc_error(ret); e) return e; *window = sc_ptr_result(ret); return 0; @@ -249,7 +249,7 @@ int sys_vm_map(void *hint, size_t size, int prot, int flags, int sys_vm_unmap(void *pointer, size_t size) { auto ret = do_syscall(SYS_munmap, pointer, size); - if(int e = sc_error(ret); e) + if (int e = sc_error(ret); e) return e; return 0; } @@ -341,8 +341,7 @@ int sys_fstatfs(int fd, struct statfs *buf) { extern "C" void __mlibc_signal_restore(void); extern "C" void __mlibc_signal_restore_rt(void); -int sys_sigaction(int signum, const struct sigaction *act, - struct sigaction *oldact) { +int sys_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) { struct ksigaction { void (*handler)(int); unsigned long flags; @@ -354,15 +353,20 @@ int sys_sigaction(int signum, const struct sigaction *act, if (act) { kernel_act.handler = act->sa_handler; kernel_act.flags = act->sa_flags | SA_RESTORER; - kernel_act.restorer = (act->sa_flags & SA_SIGINFO) ? __mlibc_signal_restore_rt : __mlibc_signal_restore; + kernel_act.restorer = + (act->sa_flags & SA_SIGINFO) ? __mlibc_signal_restore_rt : __mlibc_signal_restore; memcpy(&kernel_act.mask, &act->sa_mask, sizeof(kernel_act.mask)); } static_assert(sizeof(kernel_act.mask) == 8); - auto ret = do_syscall(SYS_rt_sigaction, signum, act ? - &kernel_act : NULL, oldact ? - &kernel_oldact : NULL, sizeof(kernel_act.mask)); + auto ret = do_syscall( + SYS_rt_sigaction, + signum, + act ? &kernel_act : NULL, + oldact ? &kernel_oldact : NULL, + sizeof(kernel_act.mask) + ); if (int e = sc_error(ret); e) return e; @@ -376,33 +380,49 @@ int sys_sigaction(int signum, const struct sigaction *act, } int sys_socket(int domain, int type, int protocol, int *fd) { - auto ret = do_syscall(SYS_socket, domain, type, protocol); - if (int e = sc_error(ret); e) - return e; - *fd = sc_int_result(ret); - return 0; + auto ret = do_syscall(SYS_socket, domain, type, protocol); + if (int e = sc_error(ret); e) + return e; + *fd = sc_int_result(ret); + return 0; } int sys_msg_send(int sockfd, const struct msghdr *msg, int flags, ssize_t *length) { - auto ret = do_cp_syscall(SYS_sendmsg, sockfd, msg, flags); - if (int e = sc_error(ret); e) - return e; - *length = sc_int_result(ret); - return 0; + auto ret = do_cp_syscall(SYS_sendmsg, sockfd, msg, flags); + if (int e = sc_error(ret); e) + return e; + *length = sc_int_result(ret); + return 0; } -ssize_t sys_sendto(int fd, const void *buffer, size_t size, int flags, const struct sockaddr *sock_addr, socklen_t addr_length, ssize_t *length) { +ssize_t sys_sendto( + int fd, + const void *buffer, + size_t size, + int flags, + const struct sockaddr *sock_addr, + socklen_t addr_length, + ssize_t *length +) { auto ret = do_cp_syscall(SYS_sendto, fd, buffer, size, flags, sock_addr, addr_length); - if(int e = sc_error(ret); e) { + if (int e = sc_error(ret); e) { return e; } *length = sc_int_result(ret); return 0; } -ssize_t sys_recvfrom(int fd, void *buffer, size_t size, int flags, struct sockaddr *sock_addr, socklen_t *addr_length, ssize_t *length) { +ssize_t sys_recvfrom( + int fd, + void *buffer, + size_t size, + int flags, + struct sockaddr *sock_addr, + socklen_t *addr_length, + ssize_t *length +) { auto ret = do_cp_syscall(SYS_recvfrom, fd, buffer, size, flags, sock_addr, addr_length); - if(int e = sc_error(ret); e) { + if (int e = sc_error(ret); e) { return e; } *length = sc_int_result(ret); @@ -410,24 +430,24 @@ ssize_t sys_recvfrom(int fd, void *buffer, size_t size, int flags, struct sockad } int sys_msg_recv(int sockfd, struct msghdr *msg, int flags, ssize_t *length) { - auto ret = do_cp_syscall(SYS_recvmsg, sockfd, msg, flags); - if (int e = sc_error(ret); e) - return e; - *length = sc_int_result(ret); - return 0; + auto ret = do_cp_syscall(SYS_recvmsg, sockfd, msg, flags); + if (int e = sc_error(ret); e) + return e; + *length = sc_int_result(ret); + return 0; } int sys_fcntl(int fd, int cmd, va_list args, int *result) { - auto arg = va_arg(args, unsigned long); - // TODO: the api for linux differs for each command so fcntl()s might fail with -EINVAL - // we should implement all the different fcntl()s + auto arg = va_arg(args, unsigned long); + // TODO: the api for linux differs for each command so fcntl()s might fail with -EINVAL + // we should implement all the different fcntl()s // TODO(geert): only some fcntl()s can fail with -EINTR, making do_cp_syscall useless // on most fcntls(). Another reason to handle different fcntl()s seperately. - auto ret = do_cp_syscall(SYS_fcntl, fd, cmd, arg); - if (int e = sc_error(ret); e) - return e; - *result = sc_int_result(ret); - return 0; + auto ret = do_cp_syscall(SYS_fcntl, fd, cmd, arg); + if (int e = sc_error(ret); e) + return e; + *result = sc_int_result(ret); + return 0; } int sys_getcwd(char *buf, size_t size) { @@ -446,15 +466,12 @@ int sys_unlinkat(int dfd, const char *path, int flags) { } int sys_sleep(time_t *secs, long *nanos) { - struct timespec req = { - .tv_sec = *secs, - .tv_nsec = *nanos - }; + struct timespec req = {.tv_sec = *secs, .tv_nsec = *nanos}; struct timespec rem = {}; auto ret = do_cp_syscall(SYS_nanosleep, &req, &rem); - if (int e = sc_error(ret); e) - return e; + if (int e = sc_error(ret); e) + return e; *secs = rem.tv_sec; *nanos = rem.tv_nsec; @@ -467,25 +484,26 @@ int sys_isatty(int fd) { if (int e = sc_error(ret); e) return e; auto res = sc_int_result(ret); - if(!res) return 0; + if (!res) + return 0; return 1; } #if __MLIBC_POSIX_OPTION +#include #include +#include +#include +#include +#include #include #include -#include -#include #include #include +#include +#include #include -#include -#include -#include -#include -#include int sys_ioctl(int fd, unsigned long request, void *arg, int *result) { auto ret = do_syscall(SYS_ioctl, fd, request, arg); @@ -497,17 +515,24 @@ int sys_ioctl(int fd, unsigned long request, void *arg, int *result) { } int sys_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { - auto ret = do_cp_syscall(SYS_connect, sockfd, addr, addrlen); - if (int e = sc_error(ret); e) - return e; - return 0; + auto ret = do_cp_syscall(SYS_connect, sockfd, addr, addrlen); + if (int e = sc_error(ret); e) + return e; + return 0; } -int sys_pselect(int nfds, fd_set *readfds, fd_set *writefds, - fd_set *exceptfds, const struct timespec *timeout, const sigset_t *sigmask, int *num_events) { +int sys_pselect( + int nfds, + fd_set *readfds, + fd_set *writefds, + fd_set *exceptfds, + const struct timespec *timeout, + const sigset_t *sigmask, + int *num_events +) { // The Linux kernel sometimes modifies the timeout argument. struct timespec local_timeout; - if(timeout) + if (timeout) local_timeout = *timeout; // The Linux kernel really wants 7 arguments, even tho this is not supported @@ -520,8 +545,9 @@ int sys_pselect(int nfds, fd_set *readfds, fd_set *writefds, data.sigmask = sigmask; data.ss_len = NSIG / 8; - auto ret = do_cp_syscall(SYS_pselect6, nfds, readfds, writefds, - exceptfds, timeout ? &local_timeout : nullptr, &data); + auto ret = do_cp_syscall( + SYS_pselect6, nfds, readfds, writefds, exceptfds, timeout ? &local_timeout : nullptr, &data + ); if (int e = sc_error(ret); e) return e; *num_events = sc_int_result(ret); @@ -529,23 +555,23 @@ int sys_pselect(int nfds, fd_set *readfds, fd_set *writefds, } int sys_pipe(int *fds, int flags) { - if(flags) { - auto ret = do_syscall(SYS_pipe2, fds, flags); - if (int e = sc_error(ret); e) - return e; - return 0; - } else { - auto ret = do_syscall(SYS_pipe2, fds, 0); - if (int e = sc_error(ret); e) - return e; - return 0; - } + if (flags) { + auto ret = do_syscall(SYS_pipe2, fds, flags); + if (int e = sc_error(ret); e) + return e; + return 0; + } else { + auto ret = do_syscall(SYS_pipe2, fds, 0); + if (int e = sc_error(ret); e) + return e; + return 0; + } } int sys_fork(pid_t *child) { auto ret = do_syscall(SYS_clone, SIGCHLD, 0); if (int e = sc_error(ret); e) - return e; + return e; *child = sc_int_result(ret); return 0; } @@ -553,50 +579,50 @@ int sys_fork(pid_t *child) { int sys_waitpid(pid_t pid, int *status, int flags, struct rusage *ru, pid_t *ret_pid) { auto ret = do_syscall(SYS_wait4, pid, status, flags, ru); if (int e = sc_error(ret); e) - return e; + return e; *ret_pid = sc_int_result(ret); return 0; } int sys_execve(const char *path, char *const argv[], char *const envp[]) { - auto ret = do_syscall(SYS_execve, path, argv, envp); - if (int e = sc_error(ret); e) - return e; - return 0; + auto ret = do_syscall(SYS_execve, path, argv, envp); + if (int e = sc_error(ret); e) + return e; + return 0; } int sys_sigprocmask(int how, const sigset_t *set, sigset_t *old) { - auto ret = do_syscall(SYS_rt_sigprocmask, how, set, old, NSIG / 8); - if (int e = sc_error(ret); e) - return e; + auto ret = do_syscall(SYS_rt_sigprocmask, how, set, old, NSIG / 8); + if (int e = sc_error(ret); e) + return e; return 0; } int sys_setresuid(uid_t ruid, uid_t euid, uid_t suid) { auto ret = do_syscall(SYS_setresuid, ruid, euid, suid); - if (int e = sc_error(ret); e) - return e; + if (int e = sc_error(ret); e) + return e; return 0; } int sys_setresgid(gid_t rgid, gid_t egid, gid_t sgid) { auto ret = do_syscall(SYS_setresgid, rgid, egid, sgid); - if (int e = sc_error(ret); e) - return e; + if (int e = sc_error(ret); e) + return e; return 0; } int sys_getresuid(uid_t *ruid, uid_t *euid, uid_t *suid) { auto ret = do_syscall(SYS_getresuid, ruid, euid, suid); - if (int e = sc_error(ret); e) - return e; + if (int e = sc_error(ret); e) + return e; return 0; } int sys_getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid) { auto ret = do_syscall(SYS_getresgid, rgid, egid, sgid); - if (int e = sc_error(ret); e) - return e; + if (int e = sc_error(ret); e) + return e; return 0; } @@ -616,19 +642,16 @@ int sys_setregid(gid_t rgid, gid_t egid) { int sys_sysinfo(struct sysinfo *info) { auto ret = do_syscall(SYS_sysinfo, info); - if (int e = sc_error(ret); e) - return e; + if (int e = sc_error(ret); e) + return e; return 0; } -void sys_yield() { - do_syscall(SYS_sched_yield); -} +void sys_yield() { do_syscall(SYS_sched_yield); } int sys_clone(void *tcb, pid_t *pid_out, void *stack) { - unsigned long flags = CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND - | CLONE_THREAD | CLONE_SYSVSEM | CLONE_SETTLS - | CLONE_PARENT_SETTID; + unsigned long flags = CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | CLONE_THREAD + | CLONE_SYSVSEM | CLONE_SETTLS | CLONE_PARENT_SETTID; #if defined(__riscv) || defined(__loongarch64) // TP should point to the address immediately after the TCB. @@ -645,7 +668,8 @@ int sys_clone(void *tcb, pid_t *pid_out, void *stack) { uint32_t gs; asm volatile("movw %%gs, %w0" : "=q"(gs)); - auto user_desc = reinterpret_cast(getAllocator().allocate(sizeof(struct user_desc))); + auto user_desc = + reinterpret_cast(getAllocator().allocate(sizeof(struct user_desc))); user_desc->entry_number = (gs & 0xffff) >> 3; user_desc->base_addr = uintptr_t(tcb); @@ -677,17 +701,17 @@ extern "C" const char __mlibc_syscall_end[1]; #endif int sys_before_cancellable_syscall(ucontext_t *uct) { #if defined(__x86_64__) - auto pc = reinterpret_cast(uct->uc_mcontext.gregs[REG_RIP]); + auto pc = reinterpret_cast(uct->uc_mcontext.gregs[REG_RIP]); #elif defined(__i386__) - auto pc = reinterpret_cast(uct->uc_mcontext.gregs[REG_EIP]); + auto pc = reinterpret_cast(uct->uc_mcontext.gregs[REG_EIP]); #elif defined(__riscv) - auto pc = reinterpret_cast(uct->uc_mcontext.gregs[REG_PC]); + auto pc = reinterpret_cast(uct->uc_mcontext.gregs[REG_PC]); #elif defined(__aarch64__) - auto pc = reinterpret_cast(uct->uc_mcontext.pc); + auto pc = reinterpret_cast(uct->uc_mcontext.pc); #elif defined(__m68k__) - auto pc = reinterpret_cast(uct->uc_mcontext.gregs[R_PC]); + auto pc = reinterpret_cast(uct->uc_mcontext.gregs[R_PC]); #elif defined(__loongarch64) - auto pc = reinterpret_cast(uct->uc_mcontext.pc); + auto pc = reinterpret_cast(uct->uc_mcontext.pc); #else #error "Missing architecture specific code." #endif @@ -714,10 +738,17 @@ int sys_tcsetattr(int fd, int optional_action, const struct termios *attr) { int req; switch (optional_action) { - case TCSANOW: req = TCSETS; break; - case TCSADRAIN: req = TCSETSW; break; - case TCSAFLUSH: req = TCSETSF; break; - default: return EINVAL; + case TCSANOW: + req = TCSETS; + break; + case TCSADRAIN: + req = TCSETSW; + break; + case TCSAFLUSH: + req = TCSETSF; + break; + default: + return EINVAL; } auto ret = do_syscall(SYS_ioctl, fd, req, attr); @@ -783,8 +814,9 @@ int sys_setsockopt(int fd, int layer, int number, const void *buffer, socklen_t return 0; } -int sys_sockname(int fd, struct sockaddr *addr_ptr, socklen_t max_addr_length, - socklen_t *actual_length) { +int sys_sockname( + int fd, struct sockaddr *addr_ptr, socklen_t max_addr_length, socklen_t *actual_length +) { auto ret = do_syscall(SYS_getsockname, fd, addr_ptr, &max_addr_length); if (int e = sc_error(ret); e) return e; @@ -792,8 +824,9 @@ int sys_sockname(int fd, struct sockaddr *addr_ptr, socklen_t max_addr_length, return 0; } -int sys_peername(int fd, struct sockaddr *addr_ptr, socklen_t max_addr_length, - socklen_t *actual_length) { +int sys_peername( + int fd, struct sockaddr *addr_ptr, socklen_t max_addr_length, socklen_t *actual_length +) { auto ret = do_syscall(SYS_getpeername, fd, addr_ptr, &max_addr_length); if (int e = sc_error(ret); e) return e; @@ -852,10 +885,10 @@ int sys_timer_create(clockid_t clk, struct sigevent *__restrict evp, timer_t *__ struct linux_uapi_sigevent *ksevp = 0; int timer_id; - switch(evp ? evp->sigev_notify : SIGEV_SIGNAL) { + switch (evp ? evp->sigev_notify : SIGEV_SIGNAL) { case SIGEV_NONE: case SIGEV_SIGNAL: { - if(evp) { + if (evp) { ksev.sigev_value = evp->sigev_value; ksev.sigev_signo = evp->sigev_signo; ksev.sigev_notify = evp->sigev_notify; @@ -867,7 +900,7 @@ int sys_timer_create(clockid_t clk, struct sigevent *__restrict evp, timer_t *__ if (int e = sc_error(ret); e) { return e; } - *res = (void *) (intptr_t) timer_id; + *res = (void *)(intptr_t)timer_id; break; } case SIGEV_THREAD: @@ -880,7 +913,9 @@ int sys_timer_create(clockid_t clk, struct sigevent *__restrict evp, timer_t *__ return 0; } -int sys_timer_settime(timer_t t, int flags, const struct itimerspec *__restrict val, struct itimerspec *__restrict old) { +int sys_timer_settime( + timer_t t, int flags, const struct itimerspec *__restrict val, struct itimerspec *__restrict old +) { auto ret = do_syscall(SYS_timer_settime, t, flags, val, old); if (int e = sc_error(ret); e) { return e; @@ -889,7 +924,7 @@ int sys_timer_settime(timer_t t, int flags, const struct itimerspec *__restrict } int sys_timer_delete(timer_t t) { - __ensure((intptr_t) t >= 0); + __ensure((intptr_t)t >= 0); auto ret = do_syscall(SYS_timer_delete, t); if (int e = sc_error(ret); e) { return e; @@ -905,13 +940,11 @@ int sys_ptrace(long req, pid_t pid, void *addr, void *data, long *out) { return 0; } -int sys_open_dir(const char *path, int *fd) { - return sys_open(path, O_DIRECTORY, 0, fd); -} +int sys_open_dir(const char *path, int *fd) { return sys_open(path, O_DIRECTORY, 0, fd); } int sys_read_entries(int handle, void *buffer, size_t max_size, size_t *bytes_read) { auto ret = do_syscall(SYS_getdents64, handle, buffer, max_size); - if(int e = sc_error(ret); e) + if (int e = sc_error(ret); e) return e; *bytes_read = sc_int_result(ret); return 0; @@ -919,7 +952,7 @@ int sys_read_entries(int handle, void *buffer, size_t max_size, size_t *bytes_re int sys_prctl(int op, va_list ap, int *out) { unsigned long x[4]; - for(int i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) x[i] = va_arg(ap, unsigned long); auto ret = do_syscall(SYS_prctl, op, x[0], x[1], x[2], x[3]); @@ -1043,8 +1076,13 @@ int sys_getaffinity(pid_t pid, size_t cpusetsize, cpu_set_t *mask) { return 0; } -int sys_mount(const char *source, const char *target, - const char *fstype, unsigned long flags, const void *data) { +int sys_mount( + const char *source, + const char *target, + const char *fstype, + unsigned long flags, + const void *data +) { auto ret = do_syscall(SYS_mount, source, target, fstype, flags, data); if (int e = sc_error(ret); e) return e; @@ -1080,7 +1118,9 @@ int sys_epoll_ctl(int epfd, int mode, int fd, struct epoll_event *ev) { return 0; } -int sys_epoll_pwait(int epfd, struct epoll_event *ev, int n, int timeout, const sigset_t *sigmask, int *raised) { +int sys_epoll_pwait( + int epfd, struct epoll_event *ev, int n, int timeout, const sigset_t *sigmask, int *raised +) { auto ret = do_syscall(SYS_epoll_pwait, epfd, ev, n, timeout, sigmask, NSIG / 8); if (int e = sc_error(ret); e) return e; @@ -1112,7 +1152,9 @@ int sys_timerfd_create(int clockid, int flags, int *fd) { return 0; } -int sys_timerfd_settime(int fd, int flags, const struct itimerspec *value, struct itimerspec *oldvalue) { +int sys_timerfd_settime( + int fd, int flags, const struct itimerspec *value, struct itimerspec *oldvalue +) { auto ret = do_syscall(SYS_timerfd_settime, fd, flags, value, oldvalue); if (int e = sc_error(ret); e) return e; @@ -1170,7 +1212,8 @@ int sys_socketpair(int domain, int type_and_flags, int proto, int *fds) { return 0; } -int sys_getsockopt(int fd, int layer, int number, void *__restrict buffer, socklen_t *__restrict size) { +int +sys_getsockopt(int fd, int layer, int number, void *__restrict buffer, socklen_t *__restrict size) { auto ret = do_syscall(SYS_getsockopt, fd, layer, number, buffer, size, 0); if (int e = sc_error(ret); e) return e; @@ -1197,7 +1240,7 @@ int sys_ttyname(int fd, char *buf, size_t size) { return errno; char *procname; - if(int e = asprintf(&procname, "/proc/self/fd/%i", fd); e) + if (int e = asprintf(&procname, "/proc/self/fd/%i", fd); e) return ENOMEM; __ensure(procname); @@ -1251,7 +1294,7 @@ int sys_get_min_priority(int policy, int *out) { int sys_getschedparam(void *tcb, int *policy, struct sched_param *param) { auto t = reinterpret_cast(tcb); - if(!t->tid) { + if (!t->tid) { return ESRCH; } @@ -1270,7 +1313,7 @@ int sys_getschedparam(void *tcb, int *policy, struct sched_param *param) { int sys_setschedparam(void *tcb, int policy, const struct sched_param *param) { auto t = reinterpret_cast(tcb); - if(!t->tid) { + if (!t->tid) { return ESRCH; } @@ -1298,7 +1341,7 @@ int sys_if_indextoname(unsigned int index, char *name) { int fd = 0; int r = sys_socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, AF_UNSPEC, &fd); - if(r) + if (r) return r; struct ifreq ifr; @@ -1307,8 +1350,8 @@ int sys_if_indextoname(unsigned int index, char *name) { int ret = sys_ioctl(fd, SIOCGIFNAME, &ifr, NULL); close(fd); - if(ret) { - if(ret == ENODEV) + if (ret) { + if (ret == ENODEV) return ENXIO; return ret; } @@ -1322,7 +1365,7 @@ int sys_if_nametoindex(const char *name, unsigned int *ret) { int fd = 0; int r = sys_socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, AF_UNSPEC, &fd); - if(r) + if (r) return r; struct ifreq ifr; @@ -1331,7 +1374,7 @@ int sys_if_nametoindex(const char *name, unsigned int *ret) { r = sys_ioctl(fd, SIOCGIFINDEX, &ifr, NULL); close(fd); - if(r) { + if (r) { return r; } @@ -1342,9 +1385,9 @@ int sys_if_nametoindex(const char *name, unsigned int *ret) { int sys_ptsname(int fd, char *buffer, size_t length) { int index; - if(int e = sys_ioctl(fd, TIOCGPTN, &index, NULL); e) + if (int e = sys_ioctl(fd, TIOCGPTN, &index, NULL); e) return e; - if((size_t)snprintf(buffer, length, "/dev/pts/%d", index) >= length) { + if ((size_t)snprintf(buffer, length, "/dev/pts/%d", index) >= length) { return ERANGE; } return 0; @@ -1353,14 +1396,14 @@ int sys_ptsname(int fd, char *buffer, size_t length) { int sys_unlockpt(int fd) { int unlock = 0; - if(int e = sys_ioctl(fd, TIOCSPTLCK, &unlock, NULL); e) + if (int e = sys_ioctl(fd, TIOCSPTLCK, &unlock, NULL); e) return e; return 0; } int sys_thread_setname(void *tcb, const char *name) { - if(strlen(name) > 15) { + if (strlen(name) > 15) { return ERANGE; } @@ -1368,18 +1411,18 @@ int sys_thread_setname(void *tcb, const char *name) { char *path; int cs = 0; - if(asprintf(&path, "/proc/self/task/%d/comm", t->tid) < 0) { + if (asprintf(&path, "/proc/self/task/%d/comm", t->tid) < 0) { return ENOMEM; } pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); int fd; - if(int e = sys_open(path, O_WRONLY, 0, &fd); e) { + if (int e = sys_open(path, O_WRONLY, 0, &fd); e) { return e; } - if(int e = sys_write(fd, name, strlen(name) + 1, NULL)) { + if (int e = sys_write(fd, name, strlen(name) + 1, NULL)) { return e; } @@ -1396,18 +1439,18 @@ int sys_thread_getname(void *tcb, char *name, size_t size) { int cs = 0; ssize_t real_size = 0; - if(asprintf(&path, "/proc/self/task/%d/comm", t->tid) < 0) { + if (asprintf(&path, "/proc/self/task/%d/comm", t->tid) < 0) { return ENOMEM; } pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); int fd; - if(int e = sys_open(path, O_RDONLY | O_CLOEXEC, 0, &fd); e) { + if (int e = sys_open(path, O_RDONLY | O_CLOEXEC, 0, &fd); e) { return e; } - if(int e = sys_read(fd, name, size, &real_size)) { + if (int e = sys_read(fd, name, size, &real_size)) { return e; } @@ -1416,7 +1459,7 @@ int sys_thread_getname(void *tcb, char *name, size_t size) { pthread_setcancelstate(cs, 0); - if(static_cast(size) <= real_size) { + if (static_cast(size) <= real_size) { return ERANGE; } @@ -1473,14 +1516,12 @@ int sys_flock(int fd, int options) { return 0; } -int sys_seteuid(uid_t euid) { - return sys_setresuid(-1, euid, -1); -} +int sys_seteuid(uid_t euid) { return sys_setresuid(-1, euid, -1); } int sys_vm_remap(void *pointer, size_t size, size_t new_size, void **window) { auto ret = do_syscall(SYS_mremap, pointer, size, new_size, MREMAP_MAYMOVE); // TODO: musl fixes up EPERM errors from the kernel. - if(int e = sc_error(ret); e) + if (int e = sc_error(ret); e) return e; *window = sc_ptr_result(ret); return 0; @@ -1507,23 +1548,23 @@ int sys_linkat(int olddirfd, const char *old_path, int newdirfd, const char *new // Inspired by musl (src/stat/statvfs.c:28 fixup function) static void statfs_to_statvfs(struct statfs *from, struct statvfs *to) { *to = { - .f_bsize = from->f_bsize, - .f_frsize = from->f_frsize ? from->f_frsize : from->f_bsize, - .f_blocks = from->f_blocks, - .f_bfree = from->f_bfree, - .f_bavail = from->f_bavail, - .f_files = from->f_files, - .f_ffree = from->f_ffree, - .f_favail = from->f_ffree, - .f_fsid = (unsigned long) from->f_fsid.__val[0], - .f_flag = from->f_flags, - .f_namemax = from->f_namelen, + .f_bsize = from->f_bsize, + .f_frsize = from->f_frsize ? from->f_frsize : from->f_bsize, + .f_blocks = from->f_blocks, + .f_bfree = from->f_bfree, + .f_bavail = from->f_bavail, + .f_files = from->f_files, + .f_ffree = from->f_ffree, + .f_favail = from->f_ffree, + .f_fsid = (unsigned long)from->f_fsid.__val[0], + .f_flag = from->f_flags, + .f_namemax = from->f_namelen, }; } int sys_statvfs(const char *path, struct statvfs *out) { struct statfs buf; - if(auto ret = sys_statfs(path, &buf); ret != 0) { + if (auto ret = sys_statfs(path, &buf); ret != 0) { return ret; } statfs_to_statvfs(&buf, out); @@ -1532,7 +1573,7 @@ int sys_statvfs(const char *path, struct statvfs *out) { int sys_fstatvfs(int fd, struct statvfs *out) { struct statfs buf; - if(auto ret = sys_fstatfs(fd, &buf); ret != 0) { + if (auto ret = sys_fstatfs(fd, &buf); ret != 0) { return ret; } statfs_to_statvfs(&buf, out); @@ -1540,10 +1581,10 @@ int sys_fstatvfs(int fd, struct statvfs *out) { } int sys_sysconf(int num, long *ret) { - switch(num) { + switch (num) { case _SC_OPEN_MAX: { struct rlimit ru; - if(int e = sys_getrlimit(RLIMIT_NOFILE, &ru); e) { + if (int e = sys_getrlimit(RLIMIT_NOFILE, &ru); e) { return e; } *ret = (ru.rlim_cur == RLIM_INFINITY) ? -1 : ru.rlim_cur; @@ -1552,7 +1593,7 @@ int sys_sysconf(int num, long *ret) { case _SC_NPROCESSORS_ONLN: { cpu_set_t set; CPU_ZERO(&set); - if(int e = sys_getaffinity(0, sizeof(set), &set); e) { + if (int e = sys_getaffinity(0, sizeof(set), &set); e) { return e; } *ret = CPU_COUNT(&set); @@ -1560,7 +1601,7 @@ int sys_sysconf(int num, long *ret) { } case _SC_PHYS_PAGES: { struct sysinfo info; - if(int e = sys_sysinfo(&info); e) { + if (int e = sys_sysinfo(&info); e) { return e; } unsigned unit = (info.mem_unit) ? info.mem_unit : 1; @@ -1569,7 +1610,7 @@ int sys_sysconf(int num, long *ret) { } case _SC_CHILD_MAX: { struct rlimit ru; - if(int e = sys_getrlimit(RLIMIT_NPROC, &ru); e) { + if (int e = sys_getrlimit(RLIMIT_NPROC, &ru); e) { return e; } *ret = (ru.rlim_cur == RLIM_INFINITY) ? -1 : ru.rlim_cur; @@ -1589,7 +1630,7 @@ int sys_sysconf(int num, long *ret) { int sys_semget(key_t key, int n, int fl, int *id) { auto ret = do_syscall(SYS_semget, key, n, fl); - if(int e = sc_error(ret); e) + if (int e = sc_error(ret); e) return e; *id = sc_int_result(ret); return 0; @@ -1597,7 +1638,7 @@ int sys_semget(key_t key, int n, int fl, int *id) { int sys_semctl(int semid, int semnum, int cmd, void *semun, int *out) { auto ret = do_syscall(SYS_semctl, semid, semnum, cmd | IPC_64, semun); - if(int e = sc_error(ret); e) + if (int e = sc_error(ret); e) return e; *out = sc_int_result(ret); return 0; @@ -1605,7 +1646,7 @@ int sys_semctl(int semid, int semnum, int cmd, void *semun, int *out) { int sys_waitid(idtype_t idtype, id_t id, siginfo_t *info, int options) { auto ret = do_syscall(SYS_waitid, idtype, id, info, options, 0); - if(int e = sc_error(ret); e) + if (int e = sc_error(ret); e) return e; return sc_int_result(ret); } @@ -1672,7 +1713,7 @@ int sys_pidfd_getpid(int fd, pid_t *outpid) { pid_t pid; int ret = sscanf(pidfdGetPidLine, "Pid: %d\n", &pid); - if(ret != 1) + if (ret != 1) continue; if (pid == 0) @@ -1828,7 +1869,6 @@ int sys_mkdir(const char *path, mode_t mode) { return 0; } - int sys_mkdirat(int dirfd, const char *path, mode_t mode) { auto ret = do_syscall(SYS_mkdirat, dirfd, path, mode); if (int e = sc_error(ret); e) @@ -2014,9 +2054,7 @@ int sys_dup(int fd, int flags, int *newfd) { return 0; } -void sys_sync() { - do_syscall(SYS_sync); -} +void sys_sync() { do_syscall(SYS_sync); } int sys_fsync(int fd) { auto ret = do_syscall(SYS_fsync, fd); @@ -2045,26 +2083,22 @@ int sys_getentropy(void *buffer, size_t length) { return sys_getrandom(buffer, length, 0, &written); } -int sys_setxattr(const char *path, const char *name, const void *val, - size_t size, int flags) { +int sys_setxattr(const char *path, const char *name, const void *val, size_t size, int flags) { auto ret = do_syscall(SYS_setxattr, path, name, val, size, flags); return sc_error(ret); } -int sys_lsetxattr(const char *path, const char *name, const void *val, - size_t size, int flags) { +int sys_lsetxattr(const char *path, const char *name, const void *val, size_t size, int flags) { auto ret = do_syscall(SYS_lsetxattr, path, name, val, size, flags); return sc_error(ret); } -int sys_fsetxattr(int fd, const char *name, const void *val, - size_t size, int flags) { +int sys_fsetxattr(int fd, const char *name, const void *val, size_t size, int flags) { auto ret = do_syscall(SYS_fsetxattr, fd, name, val, size, flags); return sc_error(ret); } -int sys_getxattr(const char *path, const char *name, void *val, size_t size, - ssize_t *nread) { +int sys_getxattr(const char *path, const char *name, void *val, size_t size, ssize_t *nread) { auto ret = do_syscall(SYS_getxattr, path, name, val, size); if (int e = sc_error(ret); e) { return e; @@ -2074,8 +2108,7 @@ int sys_getxattr(const char *path, const char *name, void *val, size_t size, return 0; } -int sys_lgetxattr(const char *path, const char *name, void *val, size_t size, - ssize_t *nread) { +int sys_lgetxattr(const char *path, const char *name, void *val, size_t size, ssize_t *nread) { auto ret = do_syscall(SYS_lgetxattr, path, name, val, size); if (int e = sc_error(ret); e) { return e; @@ -2085,8 +2118,7 @@ int sys_lgetxattr(const char *path, const char *name, void *val, size_t size, return 0; } -int sys_fgetxattr(int fd, const char *name, void *val, size_t size, - ssize_t *nread) { +int sys_fgetxattr(int fd, const char *name, void *val, size_t size, ssize_t *nread) { auto ret = do_syscall(SYS_fgetxattr, fd, name, val, size); if (int e = sc_error(ret); e) { return e; @@ -2141,7 +2173,12 @@ int sys_flistxattr(int fd, char *list, size_t size, ssize_t *nread) { return 0; } -int sys_sigtimedwait(const sigset_t *__restrict set, siginfo_t *__restrict info, const struct timespec *__restrict timeout, int *out_signal) { +int sys_sigtimedwait( + const sigset_t *__restrict set, + siginfo_t *__restrict info, + const struct timespec *__restrict timeout, + int *out_signal +) { auto ret = do_syscall(SYS_rt_sigtimedwait, set, info, timeout, NSIG / 8); if (int e = sc_error(ret); e) @@ -2154,7 +2191,7 @@ int sys_sigtimedwait(const sigset_t *__restrict set, siginfo_t *__restrict info, int sys_sendfile(int outfd, int infd, off_t *offset, size_t count, ssize_t *out) { auto ret = do_syscall(SYS_sendfile, outfd, infd, offset, count); - if(int e = sc_error(ret); e) { + if (int e = sc_error(ret); e) { return e; } *out = sc_int_result(ret); @@ -2163,22 +2200,32 @@ int sys_sendfile(int outfd, int infd, off_t *offset, size_t count, ssize_t *out) int sys_syncfs(int fd) { auto ret = do_syscall(SYS_syncfs, fd); - if(int e = sc_error(ret); e) { + if (int e = sc_error(ret); e) { return e; } return 0; } -int sys_name_to_handle_at(int dirfd, const char *pathname, struct file_handle *handle, int *mount_id, int flags) { +int sys_name_to_handle_at( + int dirfd, const char *pathname, struct file_handle *handle, int *mount_id, int flags +) { auto ret = do_syscall(SYS_name_to_handle_at, dirfd, pathname, handle, mount_id, flags); if (int e = sc_error(ret); e) return e; return sc_int_result(ret); } -int sys_splice(int in_fd, off_t *in_off, int out_fd, off_t *out_off, size_t size, unsigned int flags, ssize_t *out) { +int sys_splice( + int in_fd, + off_t *in_off, + int out_fd, + off_t *out_off, + size_t size, + unsigned int flags, + ssize_t *out +) { auto ret = do_syscall(SYS_copy_file_range, in_fd, in_off, out_fd, out_off, size, flags); - if(int e = sc_error(ret); e) { + if (int e = sc_error(ret); e) { return e; } *out = sc_int_result(ret); @@ -2187,7 +2234,7 @@ int sys_splice(int in_fd, off_t *in_off, int out_fd, off_t *out_off, size_t size int sys_unshare(int flags) { auto ret = do_syscall(SYS_unshare, flags); - if(int e = sc_error(ret); e) { + if (int e = sc_error(ret); e) { return e; } return 0; @@ -2195,7 +2242,7 @@ int sys_unshare(int flags) { int sys_setns(int fd, int nstype) { auto ret = do_syscall(SYS_setns, fd, nstype); - if(int e = sc_error(ret); e) { + if (int e = sc_error(ret); e) { return e; } return 0; @@ -2203,7 +2250,7 @@ int sys_setns(int fd, int nstype) { int sys_setgroups(size_t size, const gid_t *list) { auto ret = do_syscall(SYS_setgroups, size, list); - if(int e = sc_error(ret); e) { + if (int e = sc_error(ret); e) { return e; } return 0; @@ -2212,11 +2259,11 @@ int sys_setgroups(size_t size, const gid_t *list) { #if __MLIBC_BSD_OPTION int sys_brk(void **out) { auto ret = do_syscall(SYS_brk, 0); - if(int e = sc_error(ret); e) { + if (int e = sc_error(ret); e) { return e; } - *out = (void *) sc_int_result(ret); + *out = (void *)sc_int_result(ret); return 0; } #endif // __MLIBC_BSD_OPTION @@ -2226,7 +2273,7 @@ int sys_brk(void **out) { int sys_personality(unsigned long persona, int *out) { auto ret = do_syscall(SYS_personality, persona); - if(int e = sc_error(ret); e) { + if (int e = sc_error(ret); e) { return e; } @@ -2238,15 +2285,15 @@ int sys_ioperm(unsigned long int from, unsigned long int num, int turn_on) { #if defined(SYS_ioperm) auto ret = do_syscall(SYS_ioperm, from, num, turn_on); - if(int e = sc_error(ret); e) { + if (int e = sc_error(ret); e) { return e; } return 0; #else - (void) from; - (void) num; - (void) turn_on; + (void)from; + (void)num; + (void)turn_on; return ENOSYS; #endif } @@ -2255,13 +2302,13 @@ int sys_iopl(int level) { #if defined(SYS_iopl) auto ret = do_syscall(SYS_iopl, level); - if(int e = sc_error(ret); e) { + if (int e = sc_error(ret); e) { return e; } return 0; #else - (void) level; + (void)level; return ENOSYS; #endif } diff --git a/sysdeps/linux/include/bits/syscall_aliases.h b/sysdeps/linux/include/bits/syscall_aliases.h index 236a0e24c5..5976f28e78 100644 --- a/sysdeps/linux/include/bits/syscall_aliases.h +++ b/sysdeps/linux/include/bits/syscall_aliases.h @@ -2,1855 +2,1855 @@ #define __MLIBC_SYSCALL_ALIAS_BIT /* This file is autogenerated. Don't bother. */ /* Generator script: sysdeps/linux/update-syscall-list.py. */ -#ifdef __NR__llseek -# define SYS__llseek __NR__llseek +#ifdef __NR__llseek +#define SYS__llseek __NR__llseek #endif -#ifdef __NR__newselect -# define SYS__newselect __NR__newselect +#ifdef __NR__newselect +#define SYS__newselect __NR__newselect #endif -#ifdef __NR__sysctl -# define SYS__sysctl __NR__sysctl +#ifdef __NR__sysctl +#define SYS__sysctl __NR__sysctl #endif -#ifdef __NR_accept -# define SYS_accept __NR_accept +#ifdef __NR_accept +#define SYS_accept __NR_accept #endif -#ifdef __NR_accept4 -# define SYS_accept4 __NR_accept4 +#ifdef __NR_accept4 +#define SYS_accept4 __NR_accept4 #endif -#ifdef __NR_access -# define SYS_access __NR_access +#ifdef __NR_access +#define SYS_access __NR_access #endif -#ifdef __NR_acct -# define SYS_acct __NR_acct +#ifdef __NR_acct +#define SYS_acct __NR_acct #endif -#ifdef __NR_add_key -# define SYS_add_key __NR_add_key +#ifdef __NR_add_key +#define SYS_add_key __NR_add_key #endif -#ifdef __NR_adjtimex -# define SYS_adjtimex __NR_adjtimex +#ifdef __NR_adjtimex +#define SYS_adjtimex __NR_adjtimex #endif -#ifdef __NR_alarm -# define SYS_alarm __NR_alarm +#ifdef __NR_alarm +#define SYS_alarm __NR_alarm #endif -#ifdef __NR_arc_gettls -# define SYS_arc_gettls __NR_arc_gettls +#ifdef __NR_arc_gettls +#define SYS_arc_gettls __NR_arc_gettls #endif -#ifdef __NR_arc_settls -# define SYS_arc_settls __NR_arc_settls +#ifdef __NR_arc_settls +#define SYS_arc_settls __NR_arc_settls #endif -#ifdef __NR_arc_usr_cmpxchg -# define SYS_arc_usr_cmpxchg __NR_arc_usr_cmpxchg +#ifdef __NR_arc_usr_cmpxchg +#define SYS_arc_usr_cmpxchg __NR_arc_usr_cmpxchg #endif -#ifdef __NR_arch_prctl -# define SYS_arch_prctl __NR_arch_prctl +#ifdef __NR_arch_prctl +#define SYS_arch_prctl __NR_arch_prctl #endif -#ifdef __NR_arm_fadvise64_64 -# define SYS_arm_fadvise64_64 __NR_arm_fadvise64_64 +#ifdef __NR_arm_fadvise64_64 +#define SYS_arm_fadvise64_64 __NR_arm_fadvise64_64 #endif -#ifdef __NR_atomic_barrier -# define SYS_atomic_barrier __NR_atomic_barrier +#ifdef __NR_atomic_barrier +#define SYS_atomic_barrier __NR_atomic_barrier #endif -#ifdef __NR_atomic_cmpxchg_32 -# define SYS_atomic_cmpxchg_32 __NR_atomic_cmpxchg_32 +#ifdef __NR_atomic_cmpxchg_32 +#define SYS_atomic_cmpxchg_32 __NR_atomic_cmpxchg_32 #endif -#ifdef __NR_bdflush -# define SYS_bdflush __NR_bdflush +#ifdef __NR_bdflush +#define SYS_bdflush __NR_bdflush #endif -#ifdef __NR_bind -# define SYS_bind __NR_bind +#ifdef __NR_bind +#define SYS_bind __NR_bind #endif -#ifdef __NR_bpf -# define SYS_bpf __NR_bpf +#ifdef __NR_bpf +#define SYS_bpf __NR_bpf #endif -#ifdef __NR_brk -# define SYS_brk __NR_brk +#ifdef __NR_brk +#define SYS_brk __NR_brk #endif -#ifdef __NR_cachectl -# define SYS_cachectl __NR_cachectl +#ifdef __NR_cachectl +#define SYS_cachectl __NR_cachectl #endif -#ifdef __NR_cacheflush -# define SYS_cacheflush __NR_cacheflush +#ifdef __NR_cacheflush +#define SYS_cacheflush __NR_cacheflush #endif -#ifdef __NR_cachestat -# define SYS_cachestat __NR_cachestat +#ifdef __NR_cachestat +#define SYS_cachestat __NR_cachestat #endif -#ifdef __NR_capget -# define SYS_capget __NR_capget +#ifdef __NR_capget +#define SYS_capget __NR_capget #endif -#ifdef __NR_capset -# define SYS_capset __NR_capset +#ifdef __NR_capset +#define SYS_capset __NR_capset #endif -#ifdef __NR_chdir -# define SYS_chdir __NR_chdir +#ifdef __NR_chdir +#define SYS_chdir __NR_chdir #endif -#ifdef __NR_chmod -# define SYS_chmod __NR_chmod +#ifdef __NR_chmod +#define SYS_chmod __NR_chmod #endif -#ifdef __NR_chown -# define SYS_chown __NR_chown +#ifdef __NR_chown +#define SYS_chown __NR_chown #endif -#ifdef __NR_chown32 -# define SYS_chown32 __NR_chown32 +#ifdef __NR_chown32 +#define SYS_chown32 __NR_chown32 #endif -#ifdef __NR_chroot -# define SYS_chroot __NR_chroot +#ifdef __NR_chroot +#define SYS_chroot __NR_chroot #endif -#ifdef __NR_clock_adjtime -# define SYS_clock_adjtime __NR_clock_adjtime +#ifdef __NR_clock_adjtime +#define SYS_clock_adjtime __NR_clock_adjtime #endif -#ifdef __NR_clock_adjtime64 -# define SYS_clock_adjtime64 __NR_clock_adjtime64 +#ifdef __NR_clock_adjtime64 +#define SYS_clock_adjtime64 __NR_clock_adjtime64 #endif -#ifdef __NR_clock_getres -# define SYS_clock_getres __NR_clock_getres +#ifdef __NR_clock_getres +#define SYS_clock_getres __NR_clock_getres #endif -#ifdef __NR_clock_getres_time64 -# define SYS_clock_getres_time64 __NR_clock_getres_time64 +#ifdef __NR_clock_getres_time64 +#define SYS_clock_getres_time64 __NR_clock_getres_time64 #endif -#ifdef __NR_clock_gettime -# define SYS_clock_gettime __NR_clock_gettime +#ifdef __NR_clock_gettime +#define SYS_clock_gettime __NR_clock_gettime #endif -#ifdef __NR_clock_gettime64 -# define SYS_clock_gettime64 __NR_clock_gettime64 +#ifdef __NR_clock_gettime64 +#define SYS_clock_gettime64 __NR_clock_gettime64 #endif -#ifdef __NR_clock_nanosleep -# define SYS_clock_nanosleep __NR_clock_nanosleep +#ifdef __NR_clock_nanosleep +#define SYS_clock_nanosleep __NR_clock_nanosleep #endif -#ifdef __NR_clock_nanosleep_time64 -# define SYS_clock_nanosleep_time64 __NR_clock_nanosleep_time64 +#ifdef __NR_clock_nanosleep_time64 +#define SYS_clock_nanosleep_time64 __NR_clock_nanosleep_time64 #endif -#ifdef __NR_clock_settime -# define SYS_clock_settime __NR_clock_settime +#ifdef __NR_clock_settime +#define SYS_clock_settime __NR_clock_settime #endif -#ifdef __NR_clock_settime64 -# define SYS_clock_settime64 __NR_clock_settime64 +#ifdef __NR_clock_settime64 +#define SYS_clock_settime64 __NR_clock_settime64 #endif -#ifdef __NR_clone -# define SYS_clone __NR_clone +#ifdef __NR_clone +#define SYS_clone __NR_clone #endif -#ifdef __NR_clone3 -# define SYS_clone3 __NR_clone3 +#ifdef __NR_clone3 +#define SYS_clone3 __NR_clone3 #endif -#ifdef __NR_close -# define SYS_close __NR_close +#ifdef __NR_close +#define SYS_close __NR_close #endif -#ifdef __NR_close_range -# define SYS_close_range __NR_close_range +#ifdef __NR_close_range +#define SYS_close_range __NR_close_range #endif -#ifdef __NR_connect -# define SYS_connect __NR_connect +#ifdef __NR_connect +#define SYS_connect __NR_connect #endif -#ifdef __NR_copy_file_range -# define SYS_copy_file_range __NR_copy_file_range +#ifdef __NR_copy_file_range +#define SYS_copy_file_range __NR_copy_file_range #endif -#ifdef __NR_creat -# define SYS_creat __NR_creat +#ifdef __NR_creat +#define SYS_creat __NR_creat #endif -#ifdef __NR_create_module -# define SYS_create_module __NR_create_module +#ifdef __NR_create_module +#define SYS_create_module __NR_create_module #endif -#ifdef __NR_delete_module -# define SYS_delete_module __NR_delete_module +#ifdef __NR_delete_module +#define SYS_delete_module __NR_delete_module #endif -#ifdef __NR_dipc -# define SYS_dipc __NR_dipc +#ifdef __NR_dipc +#define SYS_dipc __NR_dipc #endif -#ifdef __NR_dup -# define SYS_dup __NR_dup +#ifdef __NR_dup +#define SYS_dup __NR_dup #endif -#ifdef __NR_dup2 -# define SYS_dup2 __NR_dup2 +#ifdef __NR_dup2 +#define SYS_dup2 __NR_dup2 #endif -#ifdef __NR_dup3 -# define SYS_dup3 __NR_dup3 +#ifdef __NR_dup3 +#define SYS_dup3 __NR_dup3 #endif -#ifdef __NR_epoll_create -# define SYS_epoll_create __NR_epoll_create +#ifdef __NR_epoll_create +#define SYS_epoll_create __NR_epoll_create #endif -#ifdef __NR_epoll_create1 -# define SYS_epoll_create1 __NR_epoll_create1 +#ifdef __NR_epoll_create1 +#define SYS_epoll_create1 __NR_epoll_create1 #endif -#ifdef __NR_epoll_ctl -# define SYS_epoll_ctl __NR_epoll_ctl +#ifdef __NR_epoll_ctl +#define SYS_epoll_ctl __NR_epoll_ctl #endif -#ifdef __NR_epoll_ctl_old -# define SYS_epoll_ctl_old __NR_epoll_ctl_old +#ifdef __NR_epoll_ctl_old +#define SYS_epoll_ctl_old __NR_epoll_ctl_old #endif -#ifdef __NR_epoll_pwait -# define SYS_epoll_pwait __NR_epoll_pwait +#ifdef __NR_epoll_pwait +#define SYS_epoll_pwait __NR_epoll_pwait #endif -#ifdef __NR_epoll_pwait2 -# define SYS_epoll_pwait2 __NR_epoll_pwait2 +#ifdef __NR_epoll_pwait2 +#define SYS_epoll_pwait2 __NR_epoll_pwait2 #endif -#ifdef __NR_epoll_wait -# define SYS_epoll_wait __NR_epoll_wait +#ifdef __NR_epoll_wait +#define SYS_epoll_wait __NR_epoll_wait #endif -#ifdef __NR_epoll_wait_old -# define SYS_epoll_wait_old __NR_epoll_wait_old +#ifdef __NR_epoll_wait_old +#define SYS_epoll_wait_old __NR_epoll_wait_old #endif -#ifdef __NR_eventfd -# define SYS_eventfd __NR_eventfd +#ifdef __NR_eventfd +#define SYS_eventfd __NR_eventfd #endif -#ifdef __NR_eventfd2 -# define SYS_eventfd2 __NR_eventfd2 +#ifdef __NR_eventfd2 +#define SYS_eventfd2 __NR_eventfd2 #endif -#ifdef __NR_exec_with_loader -# define SYS_exec_with_loader __NR_exec_with_loader +#ifdef __NR_exec_with_loader +#define SYS_exec_with_loader __NR_exec_with_loader #endif -#ifdef __NR_execv -# define SYS_execv __NR_execv +#ifdef __NR_execv +#define SYS_execv __NR_execv #endif -#ifdef __NR_execve -# define SYS_execve __NR_execve +#ifdef __NR_execve +#define SYS_execve __NR_execve #endif -#ifdef __NR_execveat -# define SYS_execveat __NR_execveat +#ifdef __NR_execveat +#define SYS_execveat __NR_execveat #endif -#ifdef __NR_exit -# define SYS_exit __NR_exit +#ifdef __NR_exit +#define SYS_exit __NR_exit #endif -#ifdef __NR_exit_group -# define SYS_exit_group __NR_exit_group +#ifdef __NR_exit_group +#define SYS_exit_group __NR_exit_group #endif -#ifdef __NR_faccessat -# define SYS_faccessat __NR_faccessat +#ifdef __NR_faccessat +#define SYS_faccessat __NR_faccessat #endif -#ifdef __NR_faccessat2 -# define SYS_faccessat2 __NR_faccessat2 +#ifdef __NR_faccessat2 +#define SYS_faccessat2 __NR_faccessat2 #endif -#ifdef __NR_fadvise64 -# define SYS_fadvise64 __NR_fadvise64 +#ifdef __NR_fadvise64 +#define SYS_fadvise64 __NR_fadvise64 #endif -#ifdef __NR_fadvise64_64 -# define SYS_fadvise64_64 __NR_fadvise64_64 +#ifdef __NR_fadvise64_64 +#define SYS_fadvise64_64 __NR_fadvise64_64 #endif -#ifdef __NR_fallocate -# define SYS_fallocate __NR_fallocate +#ifdef __NR_fallocate +#define SYS_fallocate __NR_fallocate #endif -#ifdef __NR_fanotify_init -# define SYS_fanotify_init __NR_fanotify_init +#ifdef __NR_fanotify_init +#define SYS_fanotify_init __NR_fanotify_init #endif -#ifdef __NR_fanotify_mark -# define SYS_fanotify_mark __NR_fanotify_mark +#ifdef __NR_fanotify_mark +#define SYS_fanotify_mark __NR_fanotify_mark #endif -#ifdef __NR_fchdir -# define SYS_fchdir __NR_fchdir +#ifdef __NR_fchdir +#define SYS_fchdir __NR_fchdir #endif -#ifdef __NR_fchmod -# define SYS_fchmod __NR_fchmod +#ifdef __NR_fchmod +#define SYS_fchmod __NR_fchmod #endif -#ifdef __NR_fchmodat -# define SYS_fchmodat __NR_fchmodat +#ifdef __NR_fchmodat +#define SYS_fchmodat __NR_fchmodat #endif -#ifdef __NR_fchmodat2 -# define SYS_fchmodat2 __NR_fchmodat2 +#ifdef __NR_fchmodat2 +#define SYS_fchmodat2 __NR_fchmodat2 #endif -#ifdef __NR_fchown -# define SYS_fchown __NR_fchown +#ifdef __NR_fchown +#define SYS_fchown __NR_fchown #endif -#ifdef __NR_fchown32 -# define SYS_fchown32 __NR_fchown32 +#ifdef __NR_fchown32 +#define SYS_fchown32 __NR_fchown32 #endif -#ifdef __NR_fchownat -# define SYS_fchownat __NR_fchownat +#ifdef __NR_fchownat +#define SYS_fchownat __NR_fchownat #endif -#ifdef __NR_fcntl -# define SYS_fcntl __NR_fcntl +#ifdef __NR_fcntl +#define SYS_fcntl __NR_fcntl #endif -#ifdef __NR_fcntl64 -# define SYS_fcntl64 __NR_fcntl64 +#ifdef __NR_fcntl64 +#define SYS_fcntl64 __NR_fcntl64 #endif -#ifdef __NR_fdatasync -# define SYS_fdatasync __NR_fdatasync +#ifdef __NR_fdatasync +#define SYS_fdatasync __NR_fdatasync #endif -#ifdef __NR_fgetxattr -# define SYS_fgetxattr __NR_fgetxattr +#ifdef __NR_fgetxattr +#define SYS_fgetxattr __NR_fgetxattr #endif -#ifdef __NR_finit_module -# define SYS_finit_module __NR_finit_module +#ifdef __NR_finit_module +#define SYS_finit_module __NR_finit_module #endif -#ifdef __NR_flistxattr -# define SYS_flistxattr __NR_flistxattr +#ifdef __NR_flistxattr +#define SYS_flistxattr __NR_flistxattr #endif -#ifdef __NR_flock -# define SYS_flock __NR_flock +#ifdef __NR_flock +#define SYS_flock __NR_flock #endif -#ifdef __NR_fork -# define SYS_fork __NR_fork +#ifdef __NR_fork +#define SYS_fork __NR_fork #endif -#ifdef __NR_fremovexattr -# define SYS_fremovexattr __NR_fremovexattr +#ifdef __NR_fremovexattr +#define SYS_fremovexattr __NR_fremovexattr #endif -#ifdef __NR_fsconfig -# define SYS_fsconfig __NR_fsconfig +#ifdef __NR_fsconfig +#define SYS_fsconfig __NR_fsconfig #endif -#ifdef __NR_fsetxattr -# define SYS_fsetxattr __NR_fsetxattr +#ifdef __NR_fsetxattr +#define SYS_fsetxattr __NR_fsetxattr #endif -#ifdef __NR_fsmount -# define SYS_fsmount __NR_fsmount +#ifdef __NR_fsmount +#define SYS_fsmount __NR_fsmount #endif -#ifdef __NR_fsopen -# define SYS_fsopen __NR_fsopen +#ifdef __NR_fsopen +#define SYS_fsopen __NR_fsopen #endif -#ifdef __NR_fspick -# define SYS_fspick __NR_fspick +#ifdef __NR_fspick +#define SYS_fspick __NR_fspick #endif -#ifdef __NR_fstat -# define SYS_fstat __NR_fstat +#ifdef __NR_fstat +#define SYS_fstat __NR_fstat #endif -#ifdef __NR_fstat64 -# define SYS_fstat64 __NR_fstat64 +#ifdef __NR_fstat64 +#define SYS_fstat64 __NR_fstat64 #endif -#ifdef __NR_fstatat64 -# define SYS_fstatat64 __NR_fstatat64 +#ifdef __NR_fstatat64 +#define SYS_fstatat64 __NR_fstatat64 #endif -#ifdef __NR_fstatfs -# define SYS_fstatfs __NR_fstatfs +#ifdef __NR_fstatfs +#define SYS_fstatfs __NR_fstatfs #endif -#ifdef __NR_fstatfs64 -# define SYS_fstatfs64 __NR_fstatfs64 +#ifdef __NR_fstatfs64 +#define SYS_fstatfs64 __NR_fstatfs64 #endif -#ifdef __NR_fsync -# define SYS_fsync __NR_fsync +#ifdef __NR_fsync +#define SYS_fsync __NR_fsync #endif -#ifdef __NR_ftruncate -# define SYS_ftruncate __NR_ftruncate +#ifdef __NR_ftruncate +#define SYS_ftruncate __NR_ftruncate #endif -#ifdef __NR_ftruncate64 -# define SYS_ftruncate64 __NR_ftruncate64 +#ifdef __NR_ftruncate64 +#define SYS_ftruncate64 __NR_ftruncate64 #endif -#ifdef __NR_futex -# define SYS_futex __NR_futex +#ifdef __NR_futex +#define SYS_futex __NR_futex #endif -#ifdef __NR_futex_requeue -# define SYS_futex_requeue __NR_futex_requeue +#ifdef __NR_futex_requeue +#define SYS_futex_requeue __NR_futex_requeue #endif -#ifdef __NR_futex_time64 -# define SYS_futex_time64 __NR_futex_time64 +#ifdef __NR_futex_time64 +#define SYS_futex_time64 __NR_futex_time64 #endif -#ifdef __NR_futex_wait -# define SYS_futex_wait __NR_futex_wait +#ifdef __NR_futex_wait +#define SYS_futex_wait __NR_futex_wait #endif -#ifdef __NR_futex_waitv -# define SYS_futex_waitv __NR_futex_waitv +#ifdef __NR_futex_waitv +#define SYS_futex_waitv __NR_futex_waitv #endif -#ifdef __NR_futex_wake -# define SYS_futex_wake __NR_futex_wake +#ifdef __NR_futex_wake +#define SYS_futex_wake __NR_futex_wake #endif -#ifdef __NR_futimesat -# define SYS_futimesat __NR_futimesat +#ifdef __NR_futimesat +#define SYS_futimesat __NR_futimesat #endif -#ifdef __NR_get_kernel_syms -# define SYS_get_kernel_syms __NR_get_kernel_syms +#ifdef __NR_get_kernel_syms +#define SYS_get_kernel_syms __NR_get_kernel_syms #endif -#ifdef __NR_get_mempolicy -# define SYS_get_mempolicy __NR_get_mempolicy +#ifdef __NR_get_mempolicy +#define SYS_get_mempolicy __NR_get_mempolicy #endif -#ifdef __NR_get_robust_list -# define SYS_get_robust_list __NR_get_robust_list +#ifdef __NR_get_robust_list +#define SYS_get_robust_list __NR_get_robust_list #endif -#ifdef __NR_get_thread_area -# define SYS_get_thread_area __NR_get_thread_area +#ifdef __NR_get_thread_area +#define SYS_get_thread_area __NR_get_thread_area #endif -#ifdef __NR_getcpu -# define SYS_getcpu __NR_getcpu +#ifdef __NR_getcpu +#define SYS_getcpu __NR_getcpu #endif -#ifdef __NR_getcwd -# define SYS_getcwd __NR_getcwd +#ifdef __NR_getcwd +#define SYS_getcwd __NR_getcwd #endif -#ifdef __NR_getdents -# define SYS_getdents __NR_getdents +#ifdef __NR_getdents +#define SYS_getdents __NR_getdents #endif -#ifdef __NR_getdents64 -# define SYS_getdents64 __NR_getdents64 +#ifdef __NR_getdents64 +#define SYS_getdents64 __NR_getdents64 #endif -#ifdef __NR_getdomainname -# define SYS_getdomainname __NR_getdomainname +#ifdef __NR_getdomainname +#define SYS_getdomainname __NR_getdomainname #endif -#ifdef __NR_getdtablesize -# define SYS_getdtablesize __NR_getdtablesize +#ifdef __NR_getdtablesize +#define SYS_getdtablesize __NR_getdtablesize #endif -#ifdef __NR_getegid -# define SYS_getegid __NR_getegid +#ifdef __NR_getegid +#define SYS_getegid __NR_getegid #endif -#ifdef __NR_getegid32 -# define SYS_getegid32 __NR_getegid32 +#ifdef __NR_getegid32 +#define SYS_getegid32 __NR_getegid32 #endif -#ifdef __NR_geteuid -# define SYS_geteuid __NR_geteuid +#ifdef __NR_geteuid +#define SYS_geteuid __NR_geteuid #endif -#ifdef __NR_geteuid32 -# define SYS_geteuid32 __NR_geteuid32 +#ifdef __NR_geteuid32 +#define SYS_geteuid32 __NR_geteuid32 #endif -#ifdef __NR_getgid -# define SYS_getgid __NR_getgid +#ifdef __NR_getgid +#define SYS_getgid __NR_getgid #endif -#ifdef __NR_getgid32 -# define SYS_getgid32 __NR_getgid32 +#ifdef __NR_getgid32 +#define SYS_getgid32 __NR_getgid32 #endif -#ifdef __NR_getgroups -# define SYS_getgroups __NR_getgroups +#ifdef __NR_getgroups +#define SYS_getgroups __NR_getgroups #endif -#ifdef __NR_getgroups32 -# define SYS_getgroups32 __NR_getgroups32 +#ifdef __NR_getgroups32 +#define SYS_getgroups32 __NR_getgroups32 #endif -#ifdef __NR_gethostname -# define SYS_gethostname __NR_gethostname +#ifdef __NR_gethostname +#define SYS_gethostname __NR_gethostname #endif -#ifdef __NR_getitimer -# define SYS_getitimer __NR_getitimer +#ifdef __NR_getitimer +#define SYS_getitimer __NR_getitimer #endif -#ifdef __NR_getpagesize -# define SYS_getpagesize __NR_getpagesize +#ifdef __NR_getpagesize +#define SYS_getpagesize __NR_getpagesize #endif -#ifdef __NR_getpeername -# define SYS_getpeername __NR_getpeername +#ifdef __NR_getpeername +#define SYS_getpeername __NR_getpeername #endif -#ifdef __NR_getpgid -# define SYS_getpgid __NR_getpgid +#ifdef __NR_getpgid +#define SYS_getpgid __NR_getpgid #endif -#ifdef __NR_getpgrp -# define SYS_getpgrp __NR_getpgrp +#ifdef __NR_getpgrp +#define SYS_getpgrp __NR_getpgrp #endif -#ifdef __NR_getpid -# define SYS_getpid __NR_getpid +#ifdef __NR_getpid +#define SYS_getpid __NR_getpid #endif -#ifdef __NR_getpmsg -# define SYS_getpmsg __NR_getpmsg +#ifdef __NR_getpmsg +#define SYS_getpmsg __NR_getpmsg #endif -#ifdef __NR_getppid -# define SYS_getppid __NR_getppid +#ifdef __NR_getppid +#define SYS_getppid __NR_getppid #endif -#ifdef __NR_getpriority -# define SYS_getpriority __NR_getpriority +#ifdef __NR_getpriority +#define SYS_getpriority __NR_getpriority #endif -#ifdef __NR_getrandom -# define SYS_getrandom __NR_getrandom +#ifdef __NR_getrandom +#define SYS_getrandom __NR_getrandom #endif -#ifdef __NR_getresgid -# define SYS_getresgid __NR_getresgid +#ifdef __NR_getresgid +#define SYS_getresgid __NR_getresgid #endif -#ifdef __NR_getresgid32 -# define SYS_getresgid32 __NR_getresgid32 +#ifdef __NR_getresgid32 +#define SYS_getresgid32 __NR_getresgid32 #endif -#ifdef __NR_getresuid -# define SYS_getresuid __NR_getresuid +#ifdef __NR_getresuid +#define SYS_getresuid __NR_getresuid #endif -#ifdef __NR_getresuid32 -# define SYS_getresuid32 __NR_getresuid32 +#ifdef __NR_getresuid32 +#define SYS_getresuid32 __NR_getresuid32 #endif -#ifdef __NR_getrlimit -# define SYS_getrlimit __NR_getrlimit +#ifdef __NR_getrlimit +#define SYS_getrlimit __NR_getrlimit #endif -#ifdef __NR_getrusage -# define SYS_getrusage __NR_getrusage +#ifdef __NR_getrusage +#define SYS_getrusage __NR_getrusage #endif -#ifdef __NR_getsid -# define SYS_getsid __NR_getsid +#ifdef __NR_getsid +#define SYS_getsid __NR_getsid #endif -#ifdef __NR_getsockname -# define SYS_getsockname __NR_getsockname +#ifdef __NR_getsockname +#define SYS_getsockname __NR_getsockname #endif -#ifdef __NR_getsockopt -# define SYS_getsockopt __NR_getsockopt +#ifdef __NR_getsockopt +#define SYS_getsockopt __NR_getsockopt #endif -#ifdef __NR_gettid -# define SYS_gettid __NR_gettid +#ifdef __NR_gettid +#define SYS_gettid __NR_gettid #endif -#ifdef __NR_gettimeofday -# define SYS_gettimeofday __NR_gettimeofday +#ifdef __NR_gettimeofday +#define SYS_gettimeofday __NR_gettimeofday #endif -#ifdef __NR_getuid -# define SYS_getuid __NR_getuid +#ifdef __NR_getuid +#define SYS_getuid __NR_getuid #endif -#ifdef __NR_getuid32 -# define SYS_getuid32 __NR_getuid32 +#ifdef __NR_getuid32 +#define SYS_getuid32 __NR_getuid32 #endif -#ifdef __NR_getxattr -# define SYS_getxattr __NR_getxattr +#ifdef __NR_getxattr +#define SYS_getxattr __NR_getxattr #endif -#ifdef __NR_getxattrat -# define SYS_getxattrat __NR_getxattrat +#ifdef __NR_getxattrat +#define SYS_getxattrat __NR_getxattrat #endif -#ifdef __NR_getxgid -# define SYS_getxgid __NR_getxgid +#ifdef __NR_getxgid +#define SYS_getxgid __NR_getxgid #endif -#ifdef __NR_getxpid -# define SYS_getxpid __NR_getxpid +#ifdef __NR_getxpid +#define SYS_getxpid __NR_getxpid #endif -#ifdef __NR_getxuid -# define SYS_getxuid __NR_getxuid +#ifdef __NR_getxuid +#define SYS_getxuid __NR_getxuid #endif -#ifdef __NR_idle -# define SYS_idle __NR_idle +#ifdef __NR_idle +#define SYS_idle __NR_idle #endif -#ifdef __NR_init_module -# define SYS_init_module __NR_init_module +#ifdef __NR_init_module +#define SYS_init_module __NR_init_module #endif -#ifdef __NR_inotify_add_watch -# define SYS_inotify_add_watch __NR_inotify_add_watch +#ifdef __NR_inotify_add_watch +#define SYS_inotify_add_watch __NR_inotify_add_watch #endif -#ifdef __NR_inotify_init -# define SYS_inotify_init __NR_inotify_init +#ifdef __NR_inotify_init +#define SYS_inotify_init __NR_inotify_init #endif -#ifdef __NR_inotify_init1 -# define SYS_inotify_init1 __NR_inotify_init1 +#ifdef __NR_inotify_init1 +#define SYS_inotify_init1 __NR_inotify_init1 #endif -#ifdef __NR_inotify_rm_watch -# define SYS_inotify_rm_watch __NR_inotify_rm_watch +#ifdef __NR_inotify_rm_watch +#define SYS_inotify_rm_watch __NR_inotify_rm_watch #endif -#ifdef __NR_io_cancel -# define SYS_io_cancel __NR_io_cancel +#ifdef __NR_io_cancel +#define SYS_io_cancel __NR_io_cancel #endif -#ifdef __NR_io_destroy -# define SYS_io_destroy __NR_io_destroy +#ifdef __NR_io_destroy +#define SYS_io_destroy __NR_io_destroy #endif -#ifdef __NR_io_getevents -# define SYS_io_getevents __NR_io_getevents +#ifdef __NR_io_getevents +#define SYS_io_getevents __NR_io_getevents #endif -#ifdef __NR_io_pgetevents -# define SYS_io_pgetevents __NR_io_pgetevents +#ifdef __NR_io_pgetevents +#define SYS_io_pgetevents __NR_io_pgetevents #endif -#ifdef __NR_io_pgetevents_time64 -# define SYS_io_pgetevents_time64 __NR_io_pgetevents_time64 +#ifdef __NR_io_pgetevents_time64 +#define SYS_io_pgetevents_time64 __NR_io_pgetevents_time64 #endif -#ifdef __NR_io_setup -# define SYS_io_setup __NR_io_setup +#ifdef __NR_io_setup +#define SYS_io_setup __NR_io_setup #endif -#ifdef __NR_io_submit -# define SYS_io_submit __NR_io_submit +#ifdef __NR_io_submit +#define SYS_io_submit __NR_io_submit #endif -#ifdef __NR_io_uring_enter -# define SYS_io_uring_enter __NR_io_uring_enter +#ifdef __NR_io_uring_enter +#define SYS_io_uring_enter __NR_io_uring_enter #endif -#ifdef __NR_io_uring_register -# define SYS_io_uring_register __NR_io_uring_register +#ifdef __NR_io_uring_register +#define SYS_io_uring_register __NR_io_uring_register #endif -#ifdef __NR_io_uring_setup -# define SYS_io_uring_setup __NR_io_uring_setup +#ifdef __NR_io_uring_setup +#define SYS_io_uring_setup __NR_io_uring_setup #endif -#ifdef __NR_ioctl -# define SYS_ioctl __NR_ioctl +#ifdef __NR_ioctl +#define SYS_ioctl __NR_ioctl #endif -#ifdef __NR_ioperm -# define SYS_ioperm __NR_ioperm +#ifdef __NR_ioperm +#define SYS_ioperm __NR_ioperm #endif -#ifdef __NR_iopl -# define SYS_iopl __NR_iopl +#ifdef __NR_iopl +#define SYS_iopl __NR_iopl #endif -#ifdef __NR_ioprio_get -# define SYS_ioprio_get __NR_ioprio_get +#ifdef __NR_ioprio_get +#define SYS_ioprio_get __NR_ioprio_get #endif -#ifdef __NR_ioprio_set -# define SYS_ioprio_set __NR_ioprio_set +#ifdef __NR_ioprio_set +#define SYS_ioprio_set __NR_ioprio_set #endif -#ifdef __NR_ipc -# define SYS_ipc __NR_ipc +#ifdef __NR_ipc +#define SYS_ipc __NR_ipc #endif -#ifdef __NR_kcmp -# define SYS_kcmp __NR_kcmp +#ifdef __NR_kcmp +#define SYS_kcmp __NR_kcmp #endif -#ifdef __NR_kern_features -# define SYS_kern_features __NR_kern_features +#ifdef __NR_kern_features +#define SYS_kern_features __NR_kern_features #endif -#ifdef __NR_kexec_file_load -# define SYS_kexec_file_load __NR_kexec_file_load +#ifdef __NR_kexec_file_load +#define SYS_kexec_file_load __NR_kexec_file_load #endif -#ifdef __NR_kexec_load -# define SYS_kexec_load __NR_kexec_load +#ifdef __NR_kexec_load +#define SYS_kexec_load __NR_kexec_load #endif -#ifdef __NR_keyctl -# define SYS_keyctl __NR_keyctl +#ifdef __NR_keyctl +#define SYS_keyctl __NR_keyctl #endif -#ifdef __NR_kill -# define SYS_kill __NR_kill +#ifdef __NR_kill +#define SYS_kill __NR_kill #endif -#ifdef __NR_landlock_add_rule -# define SYS_landlock_add_rule __NR_landlock_add_rule +#ifdef __NR_landlock_add_rule +#define SYS_landlock_add_rule __NR_landlock_add_rule #endif -#ifdef __NR_landlock_create_ruleset -# define SYS_landlock_create_ruleset __NR_landlock_create_ruleset +#ifdef __NR_landlock_create_ruleset +#define SYS_landlock_create_ruleset __NR_landlock_create_ruleset #endif -#ifdef __NR_landlock_restrict_self -# define SYS_landlock_restrict_self __NR_landlock_restrict_self +#ifdef __NR_landlock_restrict_self +#define SYS_landlock_restrict_self __NR_landlock_restrict_self #endif -#ifdef __NR_lchown -# define SYS_lchown __NR_lchown +#ifdef __NR_lchown +#define SYS_lchown __NR_lchown #endif -#ifdef __NR_lchown32 -# define SYS_lchown32 __NR_lchown32 +#ifdef __NR_lchown32 +#define SYS_lchown32 __NR_lchown32 #endif -#ifdef __NR_lgetxattr -# define SYS_lgetxattr __NR_lgetxattr +#ifdef __NR_lgetxattr +#define SYS_lgetxattr __NR_lgetxattr #endif -#ifdef __NR_link -# define SYS_link __NR_link +#ifdef __NR_link +#define SYS_link __NR_link #endif -#ifdef __NR_linkat -# define SYS_linkat __NR_linkat +#ifdef __NR_linkat +#define SYS_linkat __NR_linkat #endif -#ifdef __NR_listen -# define SYS_listen __NR_listen +#ifdef __NR_listen +#define SYS_listen __NR_listen #endif -#ifdef __NR_listmount -# define SYS_listmount __NR_listmount +#ifdef __NR_listmount +#define SYS_listmount __NR_listmount #endif -#ifdef __NR_listxattr -# define SYS_listxattr __NR_listxattr +#ifdef __NR_listxattr +#define SYS_listxattr __NR_listxattr #endif -#ifdef __NR_listxattrat -# define SYS_listxattrat __NR_listxattrat +#ifdef __NR_listxattrat +#define SYS_listxattrat __NR_listxattrat #endif -#ifdef __NR_llistxattr -# define SYS_llistxattr __NR_llistxattr +#ifdef __NR_llistxattr +#define SYS_llistxattr __NR_llistxattr #endif -#ifdef __NR_llseek -# define SYS_llseek __NR_llseek +#ifdef __NR_llseek +#define SYS_llseek __NR_llseek #endif -#ifdef __NR_lookup_dcookie -# define SYS_lookup_dcookie __NR_lookup_dcookie +#ifdef __NR_lookup_dcookie +#define SYS_lookup_dcookie __NR_lookup_dcookie #endif -#ifdef __NR_lremovexattr -# define SYS_lremovexattr __NR_lremovexattr +#ifdef __NR_lremovexattr +#define SYS_lremovexattr __NR_lremovexattr #endif -#ifdef __NR_lseek -# define SYS_lseek __NR_lseek +#ifdef __NR_lseek +#define SYS_lseek __NR_lseek #endif -#ifdef __NR_lsetxattr -# define SYS_lsetxattr __NR_lsetxattr +#ifdef __NR_lsetxattr +#define SYS_lsetxattr __NR_lsetxattr #endif -#ifdef __NR_lsm_get_self_attr -# define SYS_lsm_get_self_attr __NR_lsm_get_self_attr +#ifdef __NR_lsm_get_self_attr +#define SYS_lsm_get_self_attr __NR_lsm_get_self_attr #endif -#ifdef __NR_lsm_list_modules -# define SYS_lsm_list_modules __NR_lsm_list_modules +#ifdef __NR_lsm_list_modules +#define SYS_lsm_list_modules __NR_lsm_list_modules #endif -#ifdef __NR_lsm_set_self_attr -# define SYS_lsm_set_self_attr __NR_lsm_set_self_attr +#ifdef __NR_lsm_set_self_attr +#define SYS_lsm_set_self_attr __NR_lsm_set_self_attr #endif -#ifdef __NR_lstat -# define SYS_lstat __NR_lstat +#ifdef __NR_lstat +#define SYS_lstat __NR_lstat #endif -#ifdef __NR_lstat64 -# define SYS_lstat64 __NR_lstat64 +#ifdef __NR_lstat64 +#define SYS_lstat64 __NR_lstat64 #endif -#ifdef __NR_madvise -# define SYS_madvise __NR_madvise +#ifdef __NR_madvise +#define SYS_madvise __NR_madvise #endif -#ifdef __NR_map_shadow_stack -# define SYS_map_shadow_stack __NR_map_shadow_stack +#ifdef __NR_map_shadow_stack +#define SYS_map_shadow_stack __NR_map_shadow_stack #endif -#ifdef __NR_mbind -# define SYS_mbind __NR_mbind +#ifdef __NR_mbind +#define SYS_mbind __NR_mbind #endif -#ifdef __NR_membarrier -# define SYS_membarrier __NR_membarrier +#ifdef __NR_membarrier +#define SYS_membarrier __NR_membarrier #endif -#ifdef __NR_memfd_create -# define SYS_memfd_create __NR_memfd_create +#ifdef __NR_memfd_create +#define SYS_memfd_create __NR_memfd_create #endif -#ifdef __NR_memfd_secret -# define SYS_memfd_secret __NR_memfd_secret +#ifdef __NR_memfd_secret +#define SYS_memfd_secret __NR_memfd_secret #endif -#ifdef __NR_memory_ordering -# define SYS_memory_ordering __NR_memory_ordering +#ifdef __NR_memory_ordering +#define SYS_memory_ordering __NR_memory_ordering #endif -#ifdef __NR_migrate_pages -# define SYS_migrate_pages __NR_migrate_pages +#ifdef __NR_migrate_pages +#define SYS_migrate_pages __NR_migrate_pages #endif -#ifdef __NR_mincore -# define SYS_mincore __NR_mincore +#ifdef __NR_mincore +#define SYS_mincore __NR_mincore #endif -#ifdef __NR_mkdir -# define SYS_mkdir __NR_mkdir +#ifdef __NR_mkdir +#define SYS_mkdir __NR_mkdir #endif -#ifdef __NR_mkdirat -# define SYS_mkdirat __NR_mkdirat +#ifdef __NR_mkdirat +#define SYS_mkdirat __NR_mkdirat #endif -#ifdef __NR_mknod -# define SYS_mknod __NR_mknod +#ifdef __NR_mknod +#define SYS_mknod __NR_mknod #endif -#ifdef __NR_mknodat -# define SYS_mknodat __NR_mknodat +#ifdef __NR_mknodat +#define SYS_mknodat __NR_mknodat #endif -#ifdef __NR_mlock -# define SYS_mlock __NR_mlock +#ifdef __NR_mlock +#define SYS_mlock __NR_mlock #endif -#ifdef __NR_mlock2 -# define SYS_mlock2 __NR_mlock2 +#ifdef __NR_mlock2 +#define SYS_mlock2 __NR_mlock2 #endif -#ifdef __NR_mlockall -# define SYS_mlockall __NR_mlockall +#ifdef __NR_mlockall +#define SYS_mlockall __NR_mlockall #endif -#ifdef __NR_mmap -# define SYS_mmap __NR_mmap +#ifdef __NR_mmap +#define SYS_mmap __NR_mmap #endif -#ifdef __NR_mmap2 -# define SYS_mmap2 __NR_mmap2 +#ifdef __NR_mmap2 +#define SYS_mmap2 __NR_mmap2 #endif -#ifdef __NR_modify_ldt -# define SYS_modify_ldt __NR_modify_ldt +#ifdef __NR_modify_ldt +#define SYS_modify_ldt __NR_modify_ldt #endif -#ifdef __NR_mount -# define SYS_mount __NR_mount +#ifdef __NR_mount +#define SYS_mount __NR_mount #endif -#ifdef __NR_mount_setattr -# define SYS_mount_setattr __NR_mount_setattr +#ifdef __NR_mount_setattr +#define SYS_mount_setattr __NR_mount_setattr #endif -#ifdef __NR_move_mount -# define SYS_move_mount __NR_move_mount +#ifdef __NR_move_mount +#define SYS_move_mount __NR_move_mount #endif -#ifdef __NR_move_pages -# define SYS_move_pages __NR_move_pages +#ifdef __NR_move_pages +#define SYS_move_pages __NR_move_pages #endif -#ifdef __NR_mprotect -# define SYS_mprotect __NR_mprotect +#ifdef __NR_mprotect +#define SYS_mprotect __NR_mprotect #endif -#ifdef __NR_mq_getsetattr -# define SYS_mq_getsetattr __NR_mq_getsetattr +#ifdef __NR_mq_getsetattr +#define SYS_mq_getsetattr __NR_mq_getsetattr #endif -#ifdef __NR_mq_notify -# define SYS_mq_notify __NR_mq_notify +#ifdef __NR_mq_notify +#define SYS_mq_notify __NR_mq_notify #endif -#ifdef __NR_mq_open -# define SYS_mq_open __NR_mq_open +#ifdef __NR_mq_open +#define SYS_mq_open __NR_mq_open #endif -#ifdef __NR_mq_timedreceive -# define SYS_mq_timedreceive __NR_mq_timedreceive +#ifdef __NR_mq_timedreceive +#define SYS_mq_timedreceive __NR_mq_timedreceive #endif -#ifdef __NR_mq_timedreceive_time64 -# define SYS_mq_timedreceive_time64 __NR_mq_timedreceive_time64 +#ifdef __NR_mq_timedreceive_time64 +#define SYS_mq_timedreceive_time64 __NR_mq_timedreceive_time64 #endif -#ifdef __NR_mq_timedsend -# define SYS_mq_timedsend __NR_mq_timedsend +#ifdef __NR_mq_timedsend +#define SYS_mq_timedsend __NR_mq_timedsend #endif -#ifdef __NR_mq_timedsend_time64 -# define SYS_mq_timedsend_time64 __NR_mq_timedsend_time64 +#ifdef __NR_mq_timedsend_time64 +#define SYS_mq_timedsend_time64 __NR_mq_timedsend_time64 #endif -#ifdef __NR_mq_unlink -# define SYS_mq_unlink __NR_mq_unlink +#ifdef __NR_mq_unlink +#define SYS_mq_unlink __NR_mq_unlink #endif -#ifdef __NR_mremap -# define SYS_mremap __NR_mremap +#ifdef __NR_mremap +#define SYS_mremap __NR_mremap #endif -#ifdef __NR_mseal -# define SYS_mseal __NR_mseal +#ifdef __NR_mseal +#define SYS_mseal __NR_mseal #endif -#ifdef __NR_msgctl -# define SYS_msgctl __NR_msgctl +#ifdef __NR_msgctl +#define SYS_msgctl __NR_msgctl #endif -#ifdef __NR_msgget -# define SYS_msgget __NR_msgget +#ifdef __NR_msgget +#define SYS_msgget __NR_msgget #endif -#ifdef __NR_msgrcv -# define SYS_msgrcv __NR_msgrcv +#ifdef __NR_msgrcv +#define SYS_msgrcv __NR_msgrcv #endif -#ifdef __NR_msgsnd -# define SYS_msgsnd __NR_msgsnd +#ifdef __NR_msgsnd +#define SYS_msgsnd __NR_msgsnd #endif -#ifdef __NR_msync -# define SYS_msync __NR_msync +#ifdef __NR_msync +#define SYS_msync __NR_msync #endif -#ifdef __NR_multiplexer -# define SYS_multiplexer __NR_multiplexer +#ifdef __NR_multiplexer +#define SYS_multiplexer __NR_multiplexer #endif -#ifdef __NR_munlock -# define SYS_munlock __NR_munlock +#ifdef __NR_munlock +#define SYS_munlock __NR_munlock #endif -#ifdef __NR_munlockall -# define SYS_munlockall __NR_munlockall +#ifdef __NR_munlockall +#define SYS_munlockall __NR_munlockall #endif -#ifdef __NR_munmap -# define SYS_munmap __NR_munmap +#ifdef __NR_munmap +#define SYS_munmap __NR_munmap #endif -#ifdef __NR_name_to_handle_at -# define SYS_name_to_handle_at __NR_name_to_handle_at +#ifdef __NR_name_to_handle_at +#define SYS_name_to_handle_at __NR_name_to_handle_at #endif -#ifdef __NR_nanosleep -# define SYS_nanosleep __NR_nanosleep +#ifdef __NR_nanosleep +#define SYS_nanosleep __NR_nanosleep #endif -#ifdef __NR_newfstatat -# define SYS_newfstatat __NR_newfstatat +#ifdef __NR_newfstatat +#define SYS_newfstatat __NR_newfstatat #endif -#ifdef __NR_nfsservctl -# define SYS_nfsservctl __NR_nfsservctl +#ifdef __NR_nfsservctl +#define SYS_nfsservctl __NR_nfsservctl #endif -#ifdef __NR_nice -# define SYS_nice __NR_nice +#ifdef __NR_nice +#define SYS_nice __NR_nice #endif -#ifdef __NR_old_adjtimex -# define SYS_old_adjtimex __NR_old_adjtimex +#ifdef __NR_old_adjtimex +#define SYS_old_adjtimex __NR_old_adjtimex #endif -#ifdef __NR_oldfstat -# define SYS_oldfstat __NR_oldfstat +#ifdef __NR_oldfstat +#define SYS_oldfstat __NR_oldfstat #endif -#ifdef __NR_oldlstat -# define SYS_oldlstat __NR_oldlstat +#ifdef __NR_oldlstat +#define SYS_oldlstat __NR_oldlstat #endif -#ifdef __NR_oldolduname -# define SYS_oldolduname __NR_oldolduname +#ifdef __NR_oldolduname +#define SYS_oldolduname __NR_oldolduname #endif -#ifdef __NR_oldstat -# define SYS_oldstat __NR_oldstat +#ifdef __NR_oldstat +#define SYS_oldstat __NR_oldstat #endif -#ifdef __NR_oldumount -# define SYS_oldumount __NR_oldumount +#ifdef __NR_oldumount +#define SYS_oldumount __NR_oldumount #endif -#ifdef __NR_olduname -# define SYS_olduname __NR_olduname +#ifdef __NR_olduname +#define SYS_olduname __NR_olduname #endif -#ifdef __NR_open -# define SYS_open __NR_open +#ifdef __NR_open +#define SYS_open __NR_open #endif -#ifdef __NR_open_by_handle_at -# define SYS_open_by_handle_at __NR_open_by_handle_at +#ifdef __NR_open_by_handle_at +#define SYS_open_by_handle_at __NR_open_by_handle_at #endif -#ifdef __NR_open_tree -# define SYS_open_tree __NR_open_tree +#ifdef __NR_open_tree +#define SYS_open_tree __NR_open_tree #endif -#ifdef __NR_openat -# define SYS_openat __NR_openat +#ifdef __NR_openat +#define SYS_openat __NR_openat #endif -#ifdef __NR_openat2 -# define SYS_openat2 __NR_openat2 +#ifdef __NR_openat2 +#define SYS_openat2 __NR_openat2 #endif -#ifdef __NR_or1k_atomic -# define SYS_or1k_atomic __NR_or1k_atomic +#ifdef __NR_or1k_atomic +#define SYS_or1k_atomic __NR_or1k_atomic #endif -#ifdef __NR_osf_adjtime -# define SYS_osf_adjtime __NR_osf_adjtime +#ifdef __NR_osf_adjtime +#define SYS_osf_adjtime __NR_osf_adjtime #endif -#ifdef __NR_osf_afs_syscall -# define SYS_osf_afs_syscall __NR_osf_afs_syscall +#ifdef __NR_osf_afs_syscall +#define SYS_osf_afs_syscall __NR_osf_afs_syscall #endif -#ifdef __NR_osf_alt_plock -# define SYS_osf_alt_plock __NR_osf_alt_plock +#ifdef __NR_osf_alt_plock +#define SYS_osf_alt_plock __NR_osf_alt_plock #endif -#ifdef __NR_osf_alt_setsid -# define SYS_osf_alt_setsid __NR_osf_alt_setsid +#ifdef __NR_osf_alt_setsid +#define SYS_osf_alt_setsid __NR_osf_alt_setsid #endif -#ifdef __NR_osf_alt_sigpending -# define SYS_osf_alt_sigpending __NR_osf_alt_sigpending +#ifdef __NR_osf_alt_sigpending +#define SYS_osf_alt_sigpending __NR_osf_alt_sigpending #endif -#ifdef __NR_osf_asynch_daemon -# define SYS_osf_asynch_daemon __NR_osf_asynch_daemon +#ifdef __NR_osf_asynch_daemon +#define SYS_osf_asynch_daemon __NR_osf_asynch_daemon #endif -#ifdef __NR_osf_audcntl -# define SYS_osf_audcntl __NR_osf_audcntl +#ifdef __NR_osf_audcntl +#define SYS_osf_audcntl __NR_osf_audcntl #endif -#ifdef __NR_osf_audgen -# define SYS_osf_audgen __NR_osf_audgen +#ifdef __NR_osf_audgen +#define SYS_osf_audgen __NR_osf_audgen #endif -#ifdef __NR_osf_chflags -# define SYS_osf_chflags __NR_osf_chflags +#ifdef __NR_osf_chflags +#define SYS_osf_chflags __NR_osf_chflags #endif -#ifdef __NR_osf_execve -# define SYS_osf_execve __NR_osf_execve +#ifdef __NR_osf_execve +#define SYS_osf_execve __NR_osf_execve #endif -#ifdef __NR_osf_exportfs -# define SYS_osf_exportfs __NR_osf_exportfs +#ifdef __NR_osf_exportfs +#define SYS_osf_exportfs __NR_osf_exportfs #endif -#ifdef __NR_osf_fchflags -# define SYS_osf_fchflags __NR_osf_fchflags +#ifdef __NR_osf_fchflags +#define SYS_osf_fchflags __NR_osf_fchflags #endif -#ifdef __NR_osf_fdatasync -# define SYS_osf_fdatasync __NR_osf_fdatasync +#ifdef __NR_osf_fdatasync +#define SYS_osf_fdatasync __NR_osf_fdatasync #endif -#ifdef __NR_osf_fpathconf -# define SYS_osf_fpathconf __NR_osf_fpathconf +#ifdef __NR_osf_fpathconf +#define SYS_osf_fpathconf __NR_osf_fpathconf #endif -#ifdef __NR_osf_fstat -# define SYS_osf_fstat __NR_osf_fstat +#ifdef __NR_osf_fstat +#define SYS_osf_fstat __NR_osf_fstat #endif -#ifdef __NR_osf_fstatfs -# define SYS_osf_fstatfs __NR_osf_fstatfs +#ifdef __NR_osf_fstatfs +#define SYS_osf_fstatfs __NR_osf_fstatfs #endif -#ifdef __NR_osf_fstatfs64 -# define SYS_osf_fstatfs64 __NR_osf_fstatfs64 +#ifdef __NR_osf_fstatfs64 +#define SYS_osf_fstatfs64 __NR_osf_fstatfs64 #endif -#ifdef __NR_osf_fuser -# define SYS_osf_fuser __NR_osf_fuser +#ifdef __NR_osf_fuser +#define SYS_osf_fuser __NR_osf_fuser #endif -#ifdef __NR_osf_getaddressconf -# define SYS_osf_getaddressconf __NR_osf_getaddressconf +#ifdef __NR_osf_getaddressconf +#define SYS_osf_getaddressconf __NR_osf_getaddressconf #endif -#ifdef __NR_osf_getdirentries -# define SYS_osf_getdirentries __NR_osf_getdirentries +#ifdef __NR_osf_getdirentries +#define SYS_osf_getdirentries __NR_osf_getdirentries #endif -#ifdef __NR_osf_getdomainname -# define SYS_osf_getdomainname __NR_osf_getdomainname +#ifdef __NR_osf_getdomainname +#define SYS_osf_getdomainname __NR_osf_getdomainname #endif -#ifdef __NR_osf_getfh -# define SYS_osf_getfh __NR_osf_getfh +#ifdef __NR_osf_getfh +#define SYS_osf_getfh __NR_osf_getfh #endif -#ifdef __NR_osf_getfsstat -# define SYS_osf_getfsstat __NR_osf_getfsstat +#ifdef __NR_osf_getfsstat +#define SYS_osf_getfsstat __NR_osf_getfsstat #endif -#ifdef __NR_osf_gethostid -# define SYS_osf_gethostid __NR_osf_gethostid +#ifdef __NR_osf_gethostid +#define SYS_osf_gethostid __NR_osf_gethostid #endif -#ifdef __NR_osf_getitimer -# define SYS_osf_getitimer __NR_osf_getitimer +#ifdef __NR_osf_getitimer +#define SYS_osf_getitimer __NR_osf_getitimer #endif -#ifdef __NR_osf_getlogin -# define SYS_osf_getlogin __NR_osf_getlogin +#ifdef __NR_osf_getlogin +#define SYS_osf_getlogin __NR_osf_getlogin #endif -#ifdef __NR_osf_getmnt -# define SYS_osf_getmnt __NR_osf_getmnt +#ifdef __NR_osf_getmnt +#define SYS_osf_getmnt __NR_osf_getmnt #endif -#ifdef __NR_osf_getrusage -# define SYS_osf_getrusage __NR_osf_getrusage +#ifdef __NR_osf_getrusage +#define SYS_osf_getrusage __NR_osf_getrusage #endif -#ifdef __NR_osf_getsysinfo -# define SYS_osf_getsysinfo __NR_osf_getsysinfo +#ifdef __NR_osf_getsysinfo +#define SYS_osf_getsysinfo __NR_osf_getsysinfo #endif -#ifdef __NR_osf_gettimeofday -# define SYS_osf_gettimeofday __NR_osf_gettimeofday +#ifdef __NR_osf_gettimeofday +#define SYS_osf_gettimeofday __NR_osf_gettimeofday #endif -#ifdef __NR_osf_kloadcall -# define SYS_osf_kloadcall __NR_osf_kloadcall +#ifdef __NR_osf_kloadcall +#define SYS_osf_kloadcall __NR_osf_kloadcall #endif -#ifdef __NR_osf_kmodcall -# define SYS_osf_kmodcall __NR_osf_kmodcall +#ifdef __NR_osf_kmodcall +#define SYS_osf_kmodcall __NR_osf_kmodcall #endif -#ifdef __NR_osf_lstat -# define SYS_osf_lstat __NR_osf_lstat +#ifdef __NR_osf_lstat +#define SYS_osf_lstat __NR_osf_lstat #endif -#ifdef __NR_osf_memcntl -# define SYS_osf_memcntl __NR_osf_memcntl +#ifdef __NR_osf_memcntl +#define SYS_osf_memcntl __NR_osf_memcntl #endif -#ifdef __NR_osf_mincore -# define SYS_osf_mincore __NR_osf_mincore +#ifdef __NR_osf_mincore +#define SYS_osf_mincore __NR_osf_mincore #endif -#ifdef __NR_osf_mount -# define SYS_osf_mount __NR_osf_mount +#ifdef __NR_osf_mount +#define SYS_osf_mount __NR_osf_mount #endif -#ifdef __NR_osf_mremap -# define SYS_osf_mremap __NR_osf_mremap +#ifdef __NR_osf_mremap +#define SYS_osf_mremap __NR_osf_mremap #endif -#ifdef __NR_osf_msfs_syscall -# define SYS_osf_msfs_syscall __NR_osf_msfs_syscall +#ifdef __NR_osf_msfs_syscall +#define SYS_osf_msfs_syscall __NR_osf_msfs_syscall #endif -#ifdef __NR_osf_msleep -# define SYS_osf_msleep __NR_osf_msleep +#ifdef __NR_osf_msleep +#define SYS_osf_msleep __NR_osf_msleep #endif -#ifdef __NR_osf_mvalid -# define SYS_osf_mvalid __NR_osf_mvalid +#ifdef __NR_osf_mvalid +#define SYS_osf_mvalid __NR_osf_mvalid #endif -#ifdef __NR_osf_mwakeup -# define SYS_osf_mwakeup __NR_osf_mwakeup +#ifdef __NR_osf_mwakeup +#define SYS_osf_mwakeup __NR_osf_mwakeup #endif -#ifdef __NR_osf_naccept -# define SYS_osf_naccept __NR_osf_naccept +#ifdef __NR_osf_naccept +#define SYS_osf_naccept __NR_osf_naccept #endif -#ifdef __NR_osf_nfssvc -# define SYS_osf_nfssvc __NR_osf_nfssvc +#ifdef __NR_osf_nfssvc +#define SYS_osf_nfssvc __NR_osf_nfssvc #endif -#ifdef __NR_osf_ngetpeername -# define SYS_osf_ngetpeername __NR_osf_ngetpeername +#ifdef __NR_osf_ngetpeername +#define SYS_osf_ngetpeername __NR_osf_ngetpeername #endif -#ifdef __NR_osf_ngetsockname -# define SYS_osf_ngetsockname __NR_osf_ngetsockname +#ifdef __NR_osf_ngetsockname +#define SYS_osf_ngetsockname __NR_osf_ngetsockname #endif -#ifdef __NR_osf_nrecvfrom -# define SYS_osf_nrecvfrom __NR_osf_nrecvfrom +#ifdef __NR_osf_nrecvfrom +#define SYS_osf_nrecvfrom __NR_osf_nrecvfrom #endif -#ifdef __NR_osf_nrecvmsg -# define SYS_osf_nrecvmsg __NR_osf_nrecvmsg +#ifdef __NR_osf_nrecvmsg +#define SYS_osf_nrecvmsg __NR_osf_nrecvmsg #endif -#ifdef __NR_osf_nsendmsg -# define SYS_osf_nsendmsg __NR_osf_nsendmsg +#ifdef __NR_osf_nsendmsg +#define SYS_osf_nsendmsg __NR_osf_nsendmsg #endif -#ifdef __NR_osf_ntp_adjtime -# define SYS_osf_ntp_adjtime __NR_osf_ntp_adjtime +#ifdef __NR_osf_ntp_adjtime +#define SYS_osf_ntp_adjtime __NR_osf_ntp_adjtime #endif -#ifdef __NR_osf_ntp_gettime -# define SYS_osf_ntp_gettime __NR_osf_ntp_gettime +#ifdef __NR_osf_ntp_gettime +#define SYS_osf_ntp_gettime __NR_osf_ntp_gettime #endif -#ifdef __NR_osf_old_creat -# define SYS_osf_old_creat __NR_osf_old_creat +#ifdef __NR_osf_old_creat +#define SYS_osf_old_creat __NR_osf_old_creat #endif -#ifdef __NR_osf_old_fstat -# define SYS_osf_old_fstat __NR_osf_old_fstat +#ifdef __NR_osf_old_fstat +#define SYS_osf_old_fstat __NR_osf_old_fstat #endif -#ifdef __NR_osf_old_getpgrp -# define SYS_osf_old_getpgrp __NR_osf_old_getpgrp +#ifdef __NR_osf_old_getpgrp +#define SYS_osf_old_getpgrp __NR_osf_old_getpgrp #endif -#ifdef __NR_osf_old_killpg -# define SYS_osf_old_killpg __NR_osf_old_killpg +#ifdef __NR_osf_old_killpg +#define SYS_osf_old_killpg __NR_osf_old_killpg #endif -#ifdef __NR_osf_old_lstat -# define SYS_osf_old_lstat __NR_osf_old_lstat +#ifdef __NR_osf_old_lstat +#define SYS_osf_old_lstat __NR_osf_old_lstat #endif -#ifdef __NR_osf_old_open -# define SYS_osf_old_open __NR_osf_old_open +#ifdef __NR_osf_old_open +#define SYS_osf_old_open __NR_osf_old_open #endif -#ifdef __NR_osf_old_sigaction -# define SYS_osf_old_sigaction __NR_osf_old_sigaction +#ifdef __NR_osf_old_sigaction +#define SYS_osf_old_sigaction __NR_osf_old_sigaction #endif -#ifdef __NR_osf_old_sigblock -# define SYS_osf_old_sigblock __NR_osf_old_sigblock +#ifdef __NR_osf_old_sigblock +#define SYS_osf_old_sigblock __NR_osf_old_sigblock #endif -#ifdef __NR_osf_old_sigreturn -# define SYS_osf_old_sigreturn __NR_osf_old_sigreturn +#ifdef __NR_osf_old_sigreturn +#define SYS_osf_old_sigreturn __NR_osf_old_sigreturn #endif -#ifdef __NR_osf_old_sigsetmask -# define SYS_osf_old_sigsetmask __NR_osf_old_sigsetmask +#ifdef __NR_osf_old_sigsetmask +#define SYS_osf_old_sigsetmask __NR_osf_old_sigsetmask #endif -#ifdef __NR_osf_old_sigvec -# define SYS_osf_old_sigvec __NR_osf_old_sigvec +#ifdef __NR_osf_old_sigvec +#define SYS_osf_old_sigvec __NR_osf_old_sigvec #endif -#ifdef __NR_osf_old_stat -# define SYS_osf_old_stat __NR_osf_old_stat +#ifdef __NR_osf_old_stat +#define SYS_osf_old_stat __NR_osf_old_stat #endif -#ifdef __NR_osf_old_vadvise -# define SYS_osf_old_vadvise __NR_osf_old_vadvise +#ifdef __NR_osf_old_vadvise +#define SYS_osf_old_vadvise __NR_osf_old_vadvise #endif -#ifdef __NR_osf_old_vtrace -# define SYS_osf_old_vtrace __NR_osf_old_vtrace +#ifdef __NR_osf_old_vtrace +#define SYS_osf_old_vtrace __NR_osf_old_vtrace #endif -#ifdef __NR_osf_old_wait -# define SYS_osf_old_wait __NR_osf_old_wait +#ifdef __NR_osf_old_wait +#define SYS_osf_old_wait __NR_osf_old_wait #endif -#ifdef __NR_osf_oldquota -# define SYS_osf_oldquota __NR_osf_oldquota +#ifdef __NR_osf_oldquota +#define SYS_osf_oldquota __NR_osf_oldquota #endif -#ifdef __NR_osf_pathconf -# define SYS_osf_pathconf __NR_osf_pathconf +#ifdef __NR_osf_pathconf +#define SYS_osf_pathconf __NR_osf_pathconf #endif -#ifdef __NR_osf_pid_block -# define SYS_osf_pid_block __NR_osf_pid_block +#ifdef __NR_osf_pid_block +#define SYS_osf_pid_block __NR_osf_pid_block #endif -#ifdef __NR_osf_pid_unblock -# define SYS_osf_pid_unblock __NR_osf_pid_unblock +#ifdef __NR_osf_pid_unblock +#define SYS_osf_pid_unblock __NR_osf_pid_unblock #endif -#ifdef __NR_osf_plock -# define SYS_osf_plock __NR_osf_plock +#ifdef __NR_osf_plock +#define SYS_osf_plock __NR_osf_plock #endif -#ifdef __NR_osf_priocntlset -# define SYS_osf_priocntlset __NR_osf_priocntlset +#ifdef __NR_osf_priocntlset +#define SYS_osf_priocntlset __NR_osf_priocntlset #endif -#ifdef __NR_osf_profil -# define SYS_osf_profil __NR_osf_profil +#ifdef __NR_osf_profil +#define SYS_osf_profil __NR_osf_profil #endif -#ifdef __NR_osf_proplist_syscall -# define SYS_osf_proplist_syscall __NR_osf_proplist_syscall +#ifdef __NR_osf_proplist_syscall +#define SYS_osf_proplist_syscall __NR_osf_proplist_syscall #endif -#ifdef __NR_osf_reboot -# define SYS_osf_reboot __NR_osf_reboot +#ifdef __NR_osf_reboot +#define SYS_osf_reboot __NR_osf_reboot #endif -#ifdef __NR_osf_revoke -# define SYS_osf_revoke __NR_osf_revoke +#ifdef __NR_osf_revoke +#define SYS_osf_revoke __NR_osf_revoke #endif -#ifdef __NR_osf_sbrk -# define SYS_osf_sbrk __NR_osf_sbrk +#ifdef __NR_osf_sbrk +#define SYS_osf_sbrk __NR_osf_sbrk #endif -#ifdef __NR_osf_security -# define SYS_osf_security __NR_osf_security +#ifdef __NR_osf_security +#define SYS_osf_security __NR_osf_security #endif -#ifdef __NR_osf_select -# define SYS_osf_select __NR_osf_select +#ifdef __NR_osf_select +#define SYS_osf_select __NR_osf_select #endif -#ifdef __NR_osf_set_program_attributes -# define SYS_osf_set_program_attributes __NR_osf_set_program_attributes +#ifdef __NR_osf_set_program_attributes +#define SYS_osf_set_program_attributes __NR_osf_set_program_attributes #endif -#ifdef __NR_osf_set_speculative -# define SYS_osf_set_speculative __NR_osf_set_speculative +#ifdef __NR_osf_set_speculative +#define SYS_osf_set_speculative __NR_osf_set_speculative #endif -#ifdef __NR_osf_sethostid -# define SYS_osf_sethostid __NR_osf_sethostid +#ifdef __NR_osf_sethostid +#define SYS_osf_sethostid __NR_osf_sethostid #endif -#ifdef __NR_osf_setitimer -# define SYS_osf_setitimer __NR_osf_setitimer +#ifdef __NR_osf_setitimer +#define SYS_osf_setitimer __NR_osf_setitimer #endif -#ifdef __NR_osf_setlogin -# define SYS_osf_setlogin __NR_osf_setlogin +#ifdef __NR_osf_setlogin +#define SYS_osf_setlogin __NR_osf_setlogin #endif -#ifdef __NR_osf_setsysinfo -# define SYS_osf_setsysinfo __NR_osf_setsysinfo +#ifdef __NR_osf_setsysinfo +#define SYS_osf_setsysinfo __NR_osf_setsysinfo #endif -#ifdef __NR_osf_settimeofday -# define SYS_osf_settimeofday __NR_osf_settimeofday +#ifdef __NR_osf_settimeofday +#define SYS_osf_settimeofday __NR_osf_settimeofday #endif -#ifdef __NR_osf_shmat -# define SYS_osf_shmat __NR_osf_shmat +#ifdef __NR_osf_shmat +#define SYS_osf_shmat __NR_osf_shmat #endif -#ifdef __NR_osf_signal -# define SYS_osf_signal __NR_osf_signal +#ifdef __NR_osf_signal +#define SYS_osf_signal __NR_osf_signal #endif -#ifdef __NR_osf_sigprocmask -# define SYS_osf_sigprocmask __NR_osf_sigprocmask +#ifdef __NR_osf_sigprocmask +#define SYS_osf_sigprocmask __NR_osf_sigprocmask #endif -#ifdef __NR_osf_sigsendset -# define SYS_osf_sigsendset __NR_osf_sigsendset +#ifdef __NR_osf_sigsendset +#define SYS_osf_sigsendset __NR_osf_sigsendset #endif -#ifdef __NR_osf_sigstack -# define SYS_osf_sigstack __NR_osf_sigstack +#ifdef __NR_osf_sigstack +#define SYS_osf_sigstack __NR_osf_sigstack #endif -#ifdef __NR_osf_sigwaitprim -# define SYS_osf_sigwaitprim __NR_osf_sigwaitprim +#ifdef __NR_osf_sigwaitprim +#define SYS_osf_sigwaitprim __NR_osf_sigwaitprim #endif -#ifdef __NR_osf_sstk -# define SYS_osf_sstk __NR_osf_sstk +#ifdef __NR_osf_sstk +#define SYS_osf_sstk __NR_osf_sstk #endif -#ifdef __NR_osf_stat -# define SYS_osf_stat __NR_osf_stat +#ifdef __NR_osf_stat +#define SYS_osf_stat __NR_osf_stat #endif -#ifdef __NR_osf_statfs -# define SYS_osf_statfs __NR_osf_statfs +#ifdef __NR_osf_statfs +#define SYS_osf_statfs __NR_osf_statfs #endif -#ifdef __NR_osf_statfs64 -# define SYS_osf_statfs64 __NR_osf_statfs64 +#ifdef __NR_osf_statfs64 +#define SYS_osf_statfs64 __NR_osf_statfs64 #endif -#ifdef __NR_osf_subsys_info -# define SYS_osf_subsys_info __NR_osf_subsys_info +#ifdef __NR_osf_subsys_info +#define SYS_osf_subsys_info __NR_osf_subsys_info #endif -#ifdef __NR_osf_swapctl -# define SYS_osf_swapctl __NR_osf_swapctl +#ifdef __NR_osf_swapctl +#define SYS_osf_swapctl __NR_osf_swapctl #endif -#ifdef __NR_osf_swapon -# define SYS_osf_swapon __NR_osf_swapon +#ifdef __NR_osf_swapon +#define SYS_osf_swapon __NR_osf_swapon #endif -#ifdef __NR_osf_syscall -# define SYS_osf_syscall __NR_osf_syscall +#ifdef __NR_osf_syscall +#define SYS_osf_syscall __NR_osf_syscall #endif -#ifdef __NR_osf_sysinfo -# define SYS_osf_sysinfo __NR_osf_sysinfo +#ifdef __NR_osf_sysinfo +#define SYS_osf_sysinfo __NR_osf_sysinfo #endif -#ifdef __NR_osf_table -# define SYS_osf_table __NR_osf_table +#ifdef __NR_osf_table +#define SYS_osf_table __NR_osf_table #endif -#ifdef __NR_osf_uadmin -# define SYS_osf_uadmin __NR_osf_uadmin +#ifdef __NR_osf_uadmin +#define SYS_osf_uadmin __NR_osf_uadmin #endif -#ifdef __NR_osf_usleep_thread -# define SYS_osf_usleep_thread __NR_osf_usleep_thread +#ifdef __NR_osf_usleep_thread +#define SYS_osf_usleep_thread __NR_osf_usleep_thread #endif -#ifdef __NR_osf_uswitch -# define SYS_osf_uswitch __NR_osf_uswitch +#ifdef __NR_osf_uswitch +#define SYS_osf_uswitch __NR_osf_uswitch #endif -#ifdef __NR_osf_utc_adjtime -# define SYS_osf_utc_adjtime __NR_osf_utc_adjtime +#ifdef __NR_osf_utc_adjtime +#define SYS_osf_utc_adjtime __NR_osf_utc_adjtime #endif -#ifdef __NR_osf_utc_gettime -# define SYS_osf_utc_gettime __NR_osf_utc_gettime +#ifdef __NR_osf_utc_gettime +#define SYS_osf_utc_gettime __NR_osf_utc_gettime #endif -#ifdef __NR_osf_utimes -# define SYS_osf_utimes __NR_osf_utimes +#ifdef __NR_osf_utimes +#define SYS_osf_utimes __NR_osf_utimes #endif -#ifdef __NR_osf_utsname -# define SYS_osf_utsname __NR_osf_utsname +#ifdef __NR_osf_utsname +#define SYS_osf_utsname __NR_osf_utsname #endif -#ifdef __NR_osf_wait4 -# define SYS_osf_wait4 __NR_osf_wait4 +#ifdef __NR_osf_wait4 +#define SYS_osf_wait4 __NR_osf_wait4 #endif -#ifdef __NR_osf_waitid -# define SYS_osf_waitid __NR_osf_waitid +#ifdef __NR_osf_waitid +#define SYS_osf_waitid __NR_osf_waitid #endif -#ifdef __NR_pause -# define SYS_pause __NR_pause +#ifdef __NR_pause +#define SYS_pause __NR_pause #endif -#ifdef __NR_pciconfig_iobase -# define SYS_pciconfig_iobase __NR_pciconfig_iobase +#ifdef __NR_pciconfig_iobase +#define SYS_pciconfig_iobase __NR_pciconfig_iobase #endif -#ifdef __NR_pciconfig_read -# define SYS_pciconfig_read __NR_pciconfig_read +#ifdef __NR_pciconfig_read +#define SYS_pciconfig_read __NR_pciconfig_read #endif -#ifdef __NR_pciconfig_write -# define SYS_pciconfig_write __NR_pciconfig_write +#ifdef __NR_pciconfig_write +#define SYS_pciconfig_write __NR_pciconfig_write #endif -#ifdef __NR_perf_event_open -# define SYS_perf_event_open __NR_perf_event_open +#ifdef __NR_perf_event_open +#define SYS_perf_event_open __NR_perf_event_open #endif -#ifdef __NR_perfctr -# define SYS_perfctr __NR_perfctr +#ifdef __NR_perfctr +#define SYS_perfctr __NR_perfctr #endif -#ifdef __NR_personality -# define SYS_personality __NR_personality +#ifdef __NR_personality +#define SYS_personality __NR_personality #endif -#ifdef __NR_pidfd_getfd -# define SYS_pidfd_getfd __NR_pidfd_getfd +#ifdef __NR_pidfd_getfd +#define SYS_pidfd_getfd __NR_pidfd_getfd #endif -#ifdef __NR_pidfd_open -# define SYS_pidfd_open __NR_pidfd_open +#ifdef __NR_pidfd_open +#define SYS_pidfd_open __NR_pidfd_open #endif -#ifdef __NR_pidfd_send_signal -# define SYS_pidfd_send_signal __NR_pidfd_send_signal +#ifdef __NR_pidfd_send_signal +#define SYS_pidfd_send_signal __NR_pidfd_send_signal #endif -#ifdef __NR_pipe -# define SYS_pipe __NR_pipe +#ifdef __NR_pipe +#define SYS_pipe __NR_pipe #endif -#ifdef __NR_pipe2 -# define SYS_pipe2 __NR_pipe2 +#ifdef __NR_pipe2 +#define SYS_pipe2 __NR_pipe2 #endif -#ifdef __NR_pivot_root -# define SYS_pivot_root __NR_pivot_root +#ifdef __NR_pivot_root +#define SYS_pivot_root __NR_pivot_root #endif -#ifdef __NR_pkey_alloc -# define SYS_pkey_alloc __NR_pkey_alloc +#ifdef __NR_pkey_alloc +#define SYS_pkey_alloc __NR_pkey_alloc #endif -#ifdef __NR_pkey_free -# define SYS_pkey_free __NR_pkey_free +#ifdef __NR_pkey_free +#define SYS_pkey_free __NR_pkey_free #endif -#ifdef __NR_pkey_mprotect -# define SYS_pkey_mprotect __NR_pkey_mprotect +#ifdef __NR_pkey_mprotect +#define SYS_pkey_mprotect __NR_pkey_mprotect #endif -#ifdef __NR_poll -# define SYS_poll __NR_poll +#ifdef __NR_poll +#define SYS_poll __NR_poll #endif -#ifdef __NR_ppoll -# define SYS_ppoll __NR_ppoll +#ifdef __NR_ppoll +#define SYS_ppoll __NR_ppoll #endif -#ifdef __NR_ppoll_time64 -# define SYS_ppoll_time64 __NR_ppoll_time64 +#ifdef __NR_ppoll_time64 +#define SYS_ppoll_time64 __NR_ppoll_time64 #endif -#ifdef __NR_prctl -# define SYS_prctl __NR_prctl +#ifdef __NR_prctl +#define SYS_prctl __NR_prctl #endif -#ifdef __NR_pread64 -# define SYS_pread64 __NR_pread64 +#ifdef __NR_pread64 +#define SYS_pread64 __NR_pread64 #endif -#ifdef __NR_preadv -# define SYS_preadv __NR_preadv +#ifdef __NR_preadv +#define SYS_preadv __NR_preadv #endif -#ifdef __NR_preadv2 -# define SYS_preadv2 __NR_preadv2 +#ifdef __NR_preadv2 +#define SYS_preadv2 __NR_preadv2 #endif -#ifdef __NR_prlimit64 -# define SYS_prlimit64 __NR_prlimit64 +#ifdef __NR_prlimit64 +#define SYS_prlimit64 __NR_prlimit64 #endif -#ifdef __NR_process_madvise -# define SYS_process_madvise __NR_process_madvise +#ifdef __NR_process_madvise +#define SYS_process_madvise __NR_process_madvise #endif -#ifdef __NR_process_mrelease -# define SYS_process_mrelease __NR_process_mrelease +#ifdef __NR_process_mrelease +#define SYS_process_mrelease __NR_process_mrelease #endif -#ifdef __NR_process_vm_readv -# define SYS_process_vm_readv __NR_process_vm_readv +#ifdef __NR_process_vm_readv +#define SYS_process_vm_readv __NR_process_vm_readv #endif -#ifdef __NR_process_vm_writev -# define SYS_process_vm_writev __NR_process_vm_writev +#ifdef __NR_process_vm_writev +#define SYS_process_vm_writev __NR_process_vm_writev #endif -#ifdef __NR_pselect6 -# define SYS_pselect6 __NR_pselect6 +#ifdef __NR_pselect6 +#define SYS_pselect6 __NR_pselect6 #endif -#ifdef __NR_pselect6_time64 -# define SYS_pselect6_time64 __NR_pselect6_time64 +#ifdef __NR_pselect6_time64 +#define SYS_pselect6_time64 __NR_pselect6_time64 #endif -#ifdef __NR_ptrace -# define SYS_ptrace __NR_ptrace +#ifdef __NR_ptrace +#define SYS_ptrace __NR_ptrace #endif -#ifdef __NR_pwrite64 -# define SYS_pwrite64 __NR_pwrite64 +#ifdef __NR_pwrite64 +#define SYS_pwrite64 __NR_pwrite64 #endif -#ifdef __NR_pwritev -# define SYS_pwritev __NR_pwritev +#ifdef __NR_pwritev +#define SYS_pwritev __NR_pwritev #endif -#ifdef __NR_pwritev2 -# define SYS_pwritev2 __NR_pwritev2 +#ifdef __NR_pwritev2 +#define SYS_pwritev2 __NR_pwritev2 #endif -#ifdef __NR_query_module -# define SYS_query_module __NR_query_module +#ifdef __NR_query_module +#define SYS_query_module __NR_query_module #endif -#ifdef __NR_quotactl -# define SYS_quotactl __NR_quotactl +#ifdef __NR_quotactl +#define SYS_quotactl __NR_quotactl #endif -#ifdef __NR_quotactl_fd -# define SYS_quotactl_fd __NR_quotactl_fd +#ifdef __NR_quotactl_fd +#define SYS_quotactl_fd __NR_quotactl_fd #endif -#ifdef __NR_read -# define SYS_read __NR_read +#ifdef __NR_read +#define SYS_read __NR_read #endif -#ifdef __NR_readahead -# define SYS_readahead __NR_readahead +#ifdef __NR_readahead +#define SYS_readahead __NR_readahead #endif -#ifdef __NR_readdir -# define SYS_readdir __NR_readdir +#ifdef __NR_readdir +#define SYS_readdir __NR_readdir #endif -#ifdef __NR_readlink -# define SYS_readlink __NR_readlink +#ifdef __NR_readlink +#define SYS_readlink __NR_readlink #endif -#ifdef __NR_readlinkat -# define SYS_readlinkat __NR_readlinkat +#ifdef __NR_readlinkat +#define SYS_readlinkat __NR_readlinkat #endif -#ifdef __NR_readv -# define SYS_readv __NR_readv +#ifdef __NR_readv +#define SYS_readv __NR_readv #endif -#ifdef __NR_reboot -# define SYS_reboot __NR_reboot +#ifdef __NR_reboot +#define SYS_reboot __NR_reboot #endif -#ifdef __NR_recv -# define SYS_recv __NR_recv +#ifdef __NR_recv +#define SYS_recv __NR_recv #endif -#ifdef __NR_recvfrom -# define SYS_recvfrom __NR_recvfrom +#ifdef __NR_recvfrom +#define SYS_recvfrom __NR_recvfrom #endif -#ifdef __NR_recvmmsg -# define SYS_recvmmsg __NR_recvmmsg +#ifdef __NR_recvmmsg +#define SYS_recvmmsg __NR_recvmmsg #endif -#ifdef __NR_recvmmsg_time64 -# define SYS_recvmmsg_time64 __NR_recvmmsg_time64 +#ifdef __NR_recvmmsg_time64 +#define SYS_recvmmsg_time64 __NR_recvmmsg_time64 #endif -#ifdef __NR_recvmsg -# define SYS_recvmsg __NR_recvmsg +#ifdef __NR_recvmsg +#define SYS_recvmsg __NR_recvmsg #endif -#ifdef __NR_remap_file_pages -# define SYS_remap_file_pages __NR_remap_file_pages +#ifdef __NR_remap_file_pages +#define SYS_remap_file_pages __NR_remap_file_pages #endif -#ifdef __NR_removexattr -# define SYS_removexattr __NR_removexattr +#ifdef __NR_removexattr +#define SYS_removexattr __NR_removexattr #endif -#ifdef __NR_removexattrat -# define SYS_removexattrat __NR_removexattrat +#ifdef __NR_removexattrat +#define SYS_removexattrat __NR_removexattrat #endif -#ifdef __NR_rename -# define SYS_rename __NR_rename +#ifdef __NR_rename +#define SYS_rename __NR_rename #endif -#ifdef __NR_renameat -# define SYS_renameat __NR_renameat +#ifdef __NR_renameat +#define SYS_renameat __NR_renameat #endif -#ifdef __NR_renameat2 -# define SYS_renameat2 __NR_renameat2 +#ifdef __NR_renameat2 +#define SYS_renameat2 __NR_renameat2 #endif -#ifdef __NR_request_key -# define SYS_request_key __NR_request_key +#ifdef __NR_request_key +#define SYS_request_key __NR_request_key #endif -#ifdef __NR_restart_syscall -# define SYS_restart_syscall __NR_restart_syscall +#ifdef __NR_restart_syscall +#define SYS_restart_syscall __NR_restart_syscall #endif -#ifdef __NR_riscv_flush_icache -# define SYS_riscv_flush_icache __NR_riscv_flush_icache +#ifdef __NR_riscv_flush_icache +#define SYS_riscv_flush_icache __NR_riscv_flush_icache #endif -#ifdef __NR_riscv_hwprobe -# define SYS_riscv_hwprobe __NR_riscv_hwprobe +#ifdef __NR_riscv_hwprobe +#define SYS_riscv_hwprobe __NR_riscv_hwprobe #endif -#ifdef __NR_rmdir -# define SYS_rmdir __NR_rmdir +#ifdef __NR_rmdir +#define SYS_rmdir __NR_rmdir #endif -#ifdef __NR_rseq -# define SYS_rseq __NR_rseq +#ifdef __NR_rseq +#define SYS_rseq __NR_rseq #endif -#ifdef __NR_rt_sigaction -# define SYS_rt_sigaction __NR_rt_sigaction +#ifdef __NR_rt_sigaction +#define SYS_rt_sigaction __NR_rt_sigaction #endif -#ifdef __NR_rt_sigpending -# define SYS_rt_sigpending __NR_rt_sigpending +#ifdef __NR_rt_sigpending +#define SYS_rt_sigpending __NR_rt_sigpending #endif -#ifdef __NR_rt_sigprocmask -# define SYS_rt_sigprocmask __NR_rt_sigprocmask +#ifdef __NR_rt_sigprocmask +#define SYS_rt_sigprocmask __NR_rt_sigprocmask #endif -#ifdef __NR_rt_sigqueueinfo -# define SYS_rt_sigqueueinfo __NR_rt_sigqueueinfo +#ifdef __NR_rt_sigqueueinfo +#define SYS_rt_sigqueueinfo __NR_rt_sigqueueinfo #endif -#ifdef __NR_rt_sigreturn -# define SYS_rt_sigreturn __NR_rt_sigreturn +#ifdef __NR_rt_sigreturn +#define SYS_rt_sigreturn __NR_rt_sigreturn #endif -#ifdef __NR_rt_sigsuspend -# define SYS_rt_sigsuspend __NR_rt_sigsuspend +#ifdef __NR_rt_sigsuspend +#define SYS_rt_sigsuspend __NR_rt_sigsuspend #endif -#ifdef __NR_rt_sigtimedwait -# define SYS_rt_sigtimedwait __NR_rt_sigtimedwait +#ifdef __NR_rt_sigtimedwait +#define SYS_rt_sigtimedwait __NR_rt_sigtimedwait #endif -#ifdef __NR_rt_sigtimedwait_time64 -# define SYS_rt_sigtimedwait_time64 __NR_rt_sigtimedwait_time64 +#ifdef __NR_rt_sigtimedwait_time64 +#define SYS_rt_sigtimedwait_time64 __NR_rt_sigtimedwait_time64 #endif -#ifdef __NR_rt_tgsigqueueinfo -# define SYS_rt_tgsigqueueinfo __NR_rt_tgsigqueueinfo +#ifdef __NR_rt_tgsigqueueinfo +#define SYS_rt_tgsigqueueinfo __NR_rt_tgsigqueueinfo #endif -#ifdef __NR_rtas -# define SYS_rtas __NR_rtas +#ifdef __NR_rtas +#define SYS_rtas __NR_rtas #endif -#ifdef __NR_s390_guarded_storage -# define SYS_s390_guarded_storage __NR_s390_guarded_storage +#ifdef __NR_s390_guarded_storage +#define SYS_s390_guarded_storage __NR_s390_guarded_storage #endif -#ifdef __NR_s390_pci_mmio_read -# define SYS_s390_pci_mmio_read __NR_s390_pci_mmio_read +#ifdef __NR_s390_pci_mmio_read +#define SYS_s390_pci_mmio_read __NR_s390_pci_mmio_read #endif -#ifdef __NR_s390_pci_mmio_write -# define SYS_s390_pci_mmio_write __NR_s390_pci_mmio_write +#ifdef __NR_s390_pci_mmio_write +#define SYS_s390_pci_mmio_write __NR_s390_pci_mmio_write #endif -#ifdef __NR_s390_runtime_instr -# define SYS_s390_runtime_instr __NR_s390_runtime_instr +#ifdef __NR_s390_runtime_instr +#define SYS_s390_runtime_instr __NR_s390_runtime_instr #endif -#ifdef __NR_s390_sthyi -# define SYS_s390_sthyi __NR_s390_sthyi +#ifdef __NR_s390_sthyi +#define SYS_s390_sthyi __NR_s390_sthyi #endif -#ifdef __NR_sched_get_affinity -# define SYS_sched_get_affinity __NR_sched_get_affinity +#ifdef __NR_sched_get_affinity +#define SYS_sched_get_affinity __NR_sched_get_affinity #endif -#ifdef __NR_sched_get_priority_max -# define SYS_sched_get_priority_max __NR_sched_get_priority_max +#ifdef __NR_sched_get_priority_max +#define SYS_sched_get_priority_max __NR_sched_get_priority_max #endif -#ifdef __NR_sched_get_priority_min -# define SYS_sched_get_priority_min __NR_sched_get_priority_min +#ifdef __NR_sched_get_priority_min +#define SYS_sched_get_priority_min __NR_sched_get_priority_min #endif -#ifdef __NR_sched_getaffinity -# define SYS_sched_getaffinity __NR_sched_getaffinity +#ifdef __NR_sched_getaffinity +#define SYS_sched_getaffinity __NR_sched_getaffinity #endif -#ifdef __NR_sched_getattr -# define SYS_sched_getattr __NR_sched_getattr +#ifdef __NR_sched_getattr +#define SYS_sched_getattr __NR_sched_getattr #endif -#ifdef __NR_sched_getparam -# define SYS_sched_getparam __NR_sched_getparam +#ifdef __NR_sched_getparam +#define SYS_sched_getparam __NR_sched_getparam #endif -#ifdef __NR_sched_getscheduler -# define SYS_sched_getscheduler __NR_sched_getscheduler +#ifdef __NR_sched_getscheduler +#define SYS_sched_getscheduler __NR_sched_getscheduler #endif -#ifdef __NR_sched_rr_get_interval -# define SYS_sched_rr_get_interval __NR_sched_rr_get_interval +#ifdef __NR_sched_rr_get_interval +#define SYS_sched_rr_get_interval __NR_sched_rr_get_interval #endif -#ifdef __NR_sched_rr_get_interval_time64 -# define SYS_sched_rr_get_interval_time64 __NR_sched_rr_get_interval_time64 +#ifdef __NR_sched_rr_get_interval_time64 +#define SYS_sched_rr_get_interval_time64 __NR_sched_rr_get_interval_time64 #endif -#ifdef __NR_sched_set_affinity -# define SYS_sched_set_affinity __NR_sched_set_affinity +#ifdef __NR_sched_set_affinity +#define SYS_sched_set_affinity __NR_sched_set_affinity #endif -#ifdef __NR_sched_setaffinity -# define SYS_sched_setaffinity __NR_sched_setaffinity +#ifdef __NR_sched_setaffinity +#define SYS_sched_setaffinity __NR_sched_setaffinity #endif -#ifdef __NR_sched_setattr -# define SYS_sched_setattr __NR_sched_setattr +#ifdef __NR_sched_setattr +#define SYS_sched_setattr __NR_sched_setattr #endif -#ifdef __NR_sched_setparam -# define SYS_sched_setparam __NR_sched_setparam +#ifdef __NR_sched_setparam +#define SYS_sched_setparam __NR_sched_setparam #endif -#ifdef __NR_sched_setscheduler -# define SYS_sched_setscheduler __NR_sched_setscheduler +#ifdef __NR_sched_setscheduler +#define SYS_sched_setscheduler __NR_sched_setscheduler #endif -#ifdef __NR_sched_yield -# define SYS_sched_yield __NR_sched_yield +#ifdef __NR_sched_yield +#define SYS_sched_yield __NR_sched_yield #endif -#ifdef __NR_seccomp -# define SYS_seccomp __NR_seccomp +#ifdef __NR_seccomp +#define SYS_seccomp __NR_seccomp #endif -#ifdef __NR_select -# define SYS_select __NR_select +#ifdef __NR_select +#define SYS_select __NR_select #endif -#ifdef __NR_semctl -# define SYS_semctl __NR_semctl +#ifdef __NR_semctl +#define SYS_semctl __NR_semctl #endif -#ifdef __NR_semget -# define SYS_semget __NR_semget +#ifdef __NR_semget +#define SYS_semget __NR_semget #endif -#ifdef __NR_semop -# define SYS_semop __NR_semop +#ifdef __NR_semop +#define SYS_semop __NR_semop #endif -#ifdef __NR_semtimedop -# define SYS_semtimedop __NR_semtimedop +#ifdef __NR_semtimedop +#define SYS_semtimedop __NR_semtimedop #endif -#ifdef __NR_semtimedop_time64 -# define SYS_semtimedop_time64 __NR_semtimedop_time64 +#ifdef __NR_semtimedop_time64 +#define SYS_semtimedop_time64 __NR_semtimedop_time64 #endif -#ifdef __NR_send -# define SYS_send __NR_send +#ifdef __NR_send +#define SYS_send __NR_send #endif -#ifdef __NR_sendfile -# define SYS_sendfile __NR_sendfile +#ifdef __NR_sendfile +#define SYS_sendfile __NR_sendfile #endif -#ifdef __NR_sendfile64 -# define SYS_sendfile64 __NR_sendfile64 +#ifdef __NR_sendfile64 +#define SYS_sendfile64 __NR_sendfile64 #endif -#ifdef __NR_sendmmsg -# define SYS_sendmmsg __NR_sendmmsg +#ifdef __NR_sendmmsg +#define SYS_sendmmsg __NR_sendmmsg #endif -#ifdef __NR_sendmsg -# define SYS_sendmsg __NR_sendmsg +#ifdef __NR_sendmsg +#define SYS_sendmsg __NR_sendmsg #endif -#ifdef __NR_sendto -# define SYS_sendto __NR_sendto +#ifdef __NR_sendto +#define SYS_sendto __NR_sendto #endif -#ifdef __NR_set_mempolicy -# define SYS_set_mempolicy __NR_set_mempolicy +#ifdef __NR_set_mempolicy +#define SYS_set_mempolicy __NR_set_mempolicy #endif -#ifdef __NR_set_mempolicy_home_node -# define SYS_set_mempolicy_home_node __NR_set_mempolicy_home_node +#ifdef __NR_set_mempolicy_home_node +#define SYS_set_mempolicy_home_node __NR_set_mempolicy_home_node #endif -#ifdef __NR_set_robust_list -# define SYS_set_robust_list __NR_set_robust_list +#ifdef __NR_set_robust_list +#define SYS_set_robust_list __NR_set_robust_list #endif -#ifdef __NR_set_thread_area -# define SYS_set_thread_area __NR_set_thread_area +#ifdef __NR_set_thread_area +#define SYS_set_thread_area __NR_set_thread_area #endif -#ifdef __NR_set_tid_address -# define SYS_set_tid_address __NR_set_tid_address +#ifdef __NR_set_tid_address +#define SYS_set_tid_address __NR_set_tid_address #endif -#ifdef __NR_setdomainname -# define SYS_setdomainname __NR_setdomainname +#ifdef __NR_setdomainname +#define SYS_setdomainname __NR_setdomainname #endif -#ifdef __NR_setfsgid -# define SYS_setfsgid __NR_setfsgid +#ifdef __NR_setfsgid +#define SYS_setfsgid __NR_setfsgid #endif -#ifdef __NR_setfsgid32 -# define SYS_setfsgid32 __NR_setfsgid32 +#ifdef __NR_setfsgid32 +#define SYS_setfsgid32 __NR_setfsgid32 #endif -#ifdef __NR_setfsuid -# define SYS_setfsuid __NR_setfsuid +#ifdef __NR_setfsuid +#define SYS_setfsuid __NR_setfsuid #endif -#ifdef __NR_setfsuid32 -# define SYS_setfsuid32 __NR_setfsuid32 +#ifdef __NR_setfsuid32 +#define SYS_setfsuid32 __NR_setfsuid32 #endif -#ifdef __NR_setgid -# define SYS_setgid __NR_setgid +#ifdef __NR_setgid +#define SYS_setgid __NR_setgid #endif -#ifdef __NR_setgid32 -# define SYS_setgid32 __NR_setgid32 +#ifdef __NR_setgid32 +#define SYS_setgid32 __NR_setgid32 #endif -#ifdef __NR_setgroups -# define SYS_setgroups __NR_setgroups +#ifdef __NR_setgroups +#define SYS_setgroups __NR_setgroups #endif -#ifdef __NR_setgroups32 -# define SYS_setgroups32 __NR_setgroups32 +#ifdef __NR_setgroups32 +#define SYS_setgroups32 __NR_setgroups32 #endif -#ifdef __NR_sethae -# define SYS_sethae __NR_sethae +#ifdef __NR_sethae +#define SYS_sethae __NR_sethae #endif -#ifdef __NR_sethostname -# define SYS_sethostname __NR_sethostname +#ifdef __NR_sethostname +#define SYS_sethostname __NR_sethostname #endif -#ifdef __NR_setitimer -# define SYS_setitimer __NR_setitimer +#ifdef __NR_setitimer +#define SYS_setitimer __NR_setitimer #endif -#ifdef __NR_setns -# define SYS_setns __NR_setns +#ifdef __NR_setns +#define SYS_setns __NR_setns #endif -#ifdef __NR_setpgid -# define SYS_setpgid __NR_setpgid +#ifdef __NR_setpgid +#define SYS_setpgid __NR_setpgid #endif -#ifdef __NR_setpgrp -# define SYS_setpgrp __NR_setpgrp +#ifdef __NR_setpgrp +#define SYS_setpgrp __NR_setpgrp #endif -#ifdef __NR_setpriority -# define SYS_setpriority __NR_setpriority +#ifdef __NR_setpriority +#define SYS_setpriority __NR_setpriority #endif -#ifdef __NR_setregid -# define SYS_setregid __NR_setregid +#ifdef __NR_setregid +#define SYS_setregid __NR_setregid #endif -#ifdef __NR_setregid32 -# define SYS_setregid32 __NR_setregid32 +#ifdef __NR_setregid32 +#define SYS_setregid32 __NR_setregid32 #endif -#ifdef __NR_setresgid -# define SYS_setresgid __NR_setresgid +#ifdef __NR_setresgid +#define SYS_setresgid __NR_setresgid #endif -#ifdef __NR_setresgid32 -# define SYS_setresgid32 __NR_setresgid32 +#ifdef __NR_setresgid32 +#define SYS_setresgid32 __NR_setresgid32 #endif -#ifdef __NR_setresuid -# define SYS_setresuid __NR_setresuid +#ifdef __NR_setresuid +#define SYS_setresuid __NR_setresuid #endif -#ifdef __NR_setresuid32 -# define SYS_setresuid32 __NR_setresuid32 +#ifdef __NR_setresuid32 +#define SYS_setresuid32 __NR_setresuid32 #endif -#ifdef __NR_setreuid -# define SYS_setreuid __NR_setreuid +#ifdef __NR_setreuid +#define SYS_setreuid __NR_setreuid #endif -#ifdef __NR_setreuid32 -# define SYS_setreuid32 __NR_setreuid32 +#ifdef __NR_setreuid32 +#define SYS_setreuid32 __NR_setreuid32 #endif -#ifdef __NR_setrlimit -# define SYS_setrlimit __NR_setrlimit +#ifdef __NR_setrlimit +#define SYS_setrlimit __NR_setrlimit #endif -#ifdef __NR_setsid -# define SYS_setsid __NR_setsid +#ifdef __NR_setsid +#define SYS_setsid __NR_setsid #endif -#ifdef __NR_setsockopt -# define SYS_setsockopt __NR_setsockopt +#ifdef __NR_setsockopt +#define SYS_setsockopt __NR_setsockopt #endif -#ifdef __NR_settimeofday -# define SYS_settimeofday __NR_settimeofday +#ifdef __NR_settimeofday +#define SYS_settimeofday __NR_settimeofday #endif -#ifdef __NR_setuid -# define SYS_setuid __NR_setuid +#ifdef __NR_setuid +#define SYS_setuid __NR_setuid #endif -#ifdef __NR_setuid32 -# define SYS_setuid32 __NR_setuid32 +#ifdef __NR_setuid32 +#define SYS_setuid32 __NR_setuid32 #endif -#ifdef __NR_setxattr -# define SYS_setxattr __NR_setxattr +#ifdef __NR_setxattr +#define SYS_setxattr __NR_setxattr #endif -#ifdef __NR_setxattrat -# define SYS_setxattrat __NR_setxattrat +#ifdef __NR_setxattrat +#define SYS_setxattrat __NR_setxattrat #endif -#ifdef __NR_sgetmask -# define SYS_sgetmask __NR_sgetmask +#ifdef __NR_sgetmask +#define SYS_sgetmask __NR_sgetmask #endif -#ifdef __NR_shmat -# define SYS_shmat __NR_shmat +#ifdef __NR_shmat +#define SYS_shmat __NR_shmat #endif -#ifdef __NR_shmctl -# define SYS_shmctl __NR_shmctl +#ifdef __NR_shmctl +#define SYS_shmctl __NR_shmctl #endif -#ifdef __NR_shmdt -# define SYS_shmdt __NR_shmdt +#ifdef __NR_shmdt +#define SYS_shmdt __NR_shmdt #endif -#ifdef __NR_shmget -# define SYS_shmget __NR_shmget +#ifdef __NR_shmget +#define SYS_shmget __NR_shmget #endif -#ifdef __NR_shutdown -# define SYS_shutdown __NR_shutdown +#ifdef __NR_shutdown +#define SYS_shutdown __NR_shutdown #endif -#ifdef __NR_sigaction -# define SYS_sigaction __NR_sigaction +#ifdef __NR_sigaction +#define SYS_sigaction __NR_sigaction #endif -#ifdef __NR_sigaltstack -# define SYS_sigaltstack __NR_sigaltstack +#ifdef __NR_sigaltstack +#define SYS_sigaltstack __NR_sigaltstack #endif -#ifdef __NR_signal -# define SYS_signal __NR_signal +#ifdef __NR_signal +#define SYS_signal __NR_signal #endif -#ifdef __NR_signalfd -# define SYS_signalfd __NR_signalfd +#ifdef __NR_signalfd +#define SYS_signalfd __NR_signalfd #endif -#ifdef __NR_signalfd4 -# define SYS_signalfd4 __NR_signalfd4 +#ifdef __NR_signalfd4 +#define SYS_signalfd4 __NR_signalfd4 #endif -#ifdef __NR_sigpending -# define SYS_sigpending __NR_sigpending +#ifdef __NR_sigpending +#define SYS_sigpending __NR_sigpending #endif -#ifdef __NR_sigprocmask -# define SYS_sigprocmask __NR_sigprocmask +#ifdef __NR_sigprocmask +#define SYS_sigprocmask __NR_sigprocmask #endif -#ifdef __NR_sigreturn -# define SYS_sigreturn __NR_sigreturn +#ifdef __NR_sigreturn +#define SYS_sigreturn __NR_sigreturn #endif -#ifdef __NR_sigsuspend -# define SYS_sigsuspend __NR_sigsuspend +#ifdef __NR_sigsuspend +#define SYS_sigsuspend __NR_sigsuspend #endif -#ifdef __NR_socket -# define SYS_socket __NR_socket +#ifdef __NR_socket +#define SYS_socket __NR_socket #endif -#ifdef __NR_socketcall -# define SYS_socketcall __NR_socketcall +#ifdef __NR_socketcall +#define SYS_socketcall __NR_socketcall #endif -#ifdef __NR_socketpair -# define SYS_socketpair __NR_socketpair +#ifdef __NR_socketpair +#define SYS_socketpair __NR_socketpair #endif -#ifdef __NR_spill -# define SYS_spill __NR_spill +#ifdef __NR_spill +#define SYS_spill __NR_spill #endif -#ifdef __NR_splice -# define SYS_splice __NR_splice +#ifdef __NR_splice +#define SYS_splice __NR_splice #endif -#ifdef __NR_spu_create -# define SYS_spu_create __NR_spu_create +#ifdef __NR_spu_create +#define SYS_spu_create __NR_spu_create #endif -#ifdef __NR_spu_run -# define SYS_spu_run __NR_spu_run +#ifdef __NR_spu_run +#define SYS_spu_run __NR_spu_run #endif -#ifdef __NR_ssetmask -# define SYS_ssetmask __NR_ssetmask +#ifdef __NR_ssetmask +#define SYS_ssetmask __NR_ssetmask #endif -#ifdef __NR_stat -# define SYS_stat __NR_stat +#ifdef __NR_stat +#define SYS_stat __NR_stat #endif -#ifdef __NR_stat64 -# define SYS_stat64 __NR_stat64 +#ifdef __NR_stat64 +#define SYS_stat64 __NR_stat64 #endif -#ifdef __NR_statfs -# define SYS_statfs __NR_statfs +#ifdef __NR_statfs +#define SYS_statfs __NR_statfs #endif -#ifdef __NR_statfs64 -# define SYS_statfs64 __NR_statfs64 +#ifdef __NR_statfs64 +#define SYS_statfs64 __NR_statfs64 #endif -#ifdef __NR_statmount -# define SYS_statmount __NR_statmount +#ifdef __NR_statmount +#define SYS_statmount __NR_statmount #endif -#ifdef __NR_statx -# define SYS_statx __NR_statx +#ifdef __NR_statx +#define SYS_statx __NR_statx #endif -#ifdef __NR_stime -# define SYS_stime __NR_stime +#ifdef __NR_stime +#define SYS_stime __NR_stime #endif -#ifdef __NR_subpage_prot -# define SYS_subpage_prot __NR_subpage_prot +#ifdef __NR_subpage_prot +#define SYS_subpage_prot __NR_subpage_prot #endif -#ifdef __NR_swapcontext -# define SYS_swapcontext __NR_swapcontext +#ifdef __NR_swapcontext +#define SYS_swapcontext __NR_swapcontext #endif -#ifdef __NR_swapoff -# define SYS_swapoff __NR_swapoff +#ifdef __NR_swapoff +#define SYS_swapoff __NR_swapoff #endif -#ifdef __NR_swapon -# define SYS_swapon __NR_swapon +#ifdef __NR_swapon +#define SYS_swapon __NR_swapon #endif -#ifdef __NR_switch_endian -# define SYS_switch_endian __NR_switch_endian +#ifdef __NR_switch_endian +#define SYS_switch_endian __NR_switch_endian #endif -#ifdef __NR_symlink -# define SYS_symlink __NR_symlink +#ifdef __NR_symlink +#define SYS_symlink __NR_symlink #endif -#ifdef __NR_symlinkat -# define SYS_symlinkat __NR_symlinkat +#ifdef __NR_symlinkat +#define SYS_symlinkat __NR_symlinkat #endif -#ifdef __NR_sync -# define SYS_sync __NR_sync +#ifdef __NR_sync +#define SYS_sync __NR_sync #endif -#ifdef __NR_sync_file_range -# define SYS_sync_file_range __NR_sync_file_range +#ifdef __NR_sync_file_range +#define SYS_sync_file_range __NR_sync_file_range #endif -#ifdef __NR_sync_file_range2 -# define SYS_sync_file_range2 __NR_sync_file_range2 +#ifdef __NR_sync_file_range2 +#define SYS_sync_file_range2 __NR_sync_file_range2 #endif -#ifdef __NR_syncfs -# define SYS_syncfs __NR_syncfs +#ifdef __NR_syncfs +#define SYS_syncfs __NR_syncfs #endif -#ifdef __NR_sys_debug_setcontext -# define SYS_sys_debug_setcontext __NR_sys_debug_setcontext +#ifdef __NR_sys_debug_setcontext +#define SYS_sys_debug_setcontext __NR_sys_debug_setcontext #endif -#ifdef __NR_syscall -# define SYS_syscall __NR_syscall +#ifdef __NR_syscall +#define SYS_syscall __NR_syscall #endif -#ifdef __NR_sysfs -# define SYS_sysfs __NR_sysfs +#ifdef __NR_sysfs +#define SYS_sysfs __NR_sysfs #endif -#ifdef __NR_sysinfo -# define SYS_sysinfo __NR_sysinfo +#ifdef __NR_sysinfo +#define SYS_sysinfo __NR_sysinfo #endif -#ifdef __NR_syslog -# define SYS_syslog __NR_syslog +#ifdef __NR_syslog +#define SYS_syslog __NR_syslog #endif -#ifdef __NR_sysmips -# define SYS_sysmips __NR_sysmips +#ifdef __NR_sysmips +#define SYS_sysmips __NR_sysmips #endif -#ifdef __NR_tee -# define SYS_tee __NR_tee +#ifdef __NR_tee +#define SYS_tee __NR_tee #endif -#ifdef __NR_tgkill -# define SYS_tgkill __NR_tgkill +#ifdef __NR_tgkill +#define SYS_tgkill __NR_tgkill #endif -#ifdef __NR_time -# define SYS_time __NR_time +#ifdef __NR_time +#define SYS_time __NR_time #endif -#ifdef __NR_timer_create -# define SYS_timer_create __NR_timer_create +#ifdef __NR_timer_create +#define SYS_timer_create __NR_timer_create #endif -#ifdef __NR_timer_delete -# define SYS_timer_delete __NR_timer_delete +#ifdef __NR_timer_delete +#define SYS_timer_delete __NR_timer_delete #endif -#ifdef __NR_timer_getoverrun -# define SYS_timer_getoverrun __NR_timer_getoverrun +#ifdef __NR_timer_getoverrun +#define SYS_timer_getoverrun __NR_timer_getoverrun #endif -#ifdef __NR_timer_gettime -# define SYS_timer_gettime __NR_timer_gettime +#ifdef __NR_timer_gettime +#define SYS_timer_gettime __NR_timer_gettime #endif -#ifdef __NR_timer_gettime64 -# define SYS_timer_gettime64 __NR_timer_gettime64 +#ifdef __NR_timer_gettime64 +#define SYS_timer_gettime64 __NR_timer_gettime64 #endif -#ifdef __NR_timer_settime -# define SYS_timer_settime __NR_timer_settime +#ifdef __NR_timer_settime +#define SYS_timer_settime __NR_timer_settime #endif -#ifdef __NR_timer_settime64 -# define SYS_timer_settime64 __NR_timer_settime64 +#ifdef __NR_timer_settime64 +#define SYS_timer_settime64 __NR_timer_settime64 #endif -#ifdef __NR_timerfd -# define SYS_timerfd __NR_timerfd +#ifdef __NR_timerfd +#define SYS_timerfd __NR_timerfd #endif -#ifdef __NR_timerfd_create -# define SYS_timerfd_create __NR_timerfd_create +#ifdef __NR_timerfd_create +#define SYS_timerfd_create __NR_timerfd_create #endif -#ifdef __NR_timerfd_gettime -# define SYS_timerfd_gettime __NR_timerfd_gettime +#ifdef __NR_timerfd_gettime +#define SYS_timerfd_gettime __NR_timerfd_gettime #endif -#ifdef __NR_timerfd_gettime64 -# define SYS_timerfd_gettime64 __NR_timerfd_gettime64 +#ifdef __NR_timerfd_gettime64 +#define SYS_timerfd_gettime64 __NR_timerfd_gettime64 #endif -#ifdef __NR_timerfd_settime -# define SYS_timerfd_settime __NR_timerfd_settime +#ifdef __NR_timerfd_settime +#define SYS_timerfd_settime __NR_timerfd_settime #endif -#ifdef __NR_timerfd_settime64 -# define SYS_timerfd_settime64 __NR_timerfd_settime64 +#ifdef __NR_timerfd_settime64 +#define SYS_timerfd_settime64 __NR_timerfd_settime64 #endif -#ifdef __NR_times -# define SYS_times __NR_times +#ifdef __NR_times +#define SYS_times __NR_times #endif -#ifdef __NR_tkill -# define SYS_tkill __NR_tkill +#ifdef __NR_tkill +#define SYS_tkill __NR_tkill #endif -#ifdef __NR_truncate -# define SYS_truncate __NR_truncate +#ifdef __NR_truncate +#define SYS_truncate __NR_truncate #endif -#ifdef __NR_truncate64 -# define SYS_truncate64 __NR_truncate64 +#ifdef __NR_truncate64 +#define SYS_truncate64 __NR_truncate64 #endif -#ifdef __NR_ugetrlimit -# define SYS_ugetrlimit __NR_ugetrlimit +#ifdef __NR_ugetrlimit +#define SYS_ugetrlimit __NR_ugetrlimit #endif -#ifdef __NR_umask -# define SYS_umask __NR_umask +#ifdef __NR_umask +#define SYS_umask __NR_umask #endif -#ifdef __NR_umount -# define SYS_umount __NR_umount +#ifdef __NR_umount +#define SYS_umount __NR_umount #endif -#ifdef __NR_umount2 -# define SYS_umount2 __NR_umount2 +#ifdef __NR_umount2 +#define SYS_umount2 __NR_umount2 #endif -#ifdef __NR_uname -# define SYS_uname __NR_uname +#ifdef __NR_uname +#define SYS_uname __NR_uname #endif -#ifdef __NR_unlink -# define SYS_unlink __NR_unlink +#ifdef __NR_unlink +#define SYS_unlink __NR_unlink #endif -#ifdef __NR_unlinkat -# define SYS_unlinkat __NR_unlinkat +#ifdef __NR_unlinkat +#define SYS_unlinkat __NR_unlinkat #endif -#ifdef __NR_unshare -# define SYS_unshare __NR_unshare +#ifdef __NR_unshare +#define SYS_unshare __NR_unshare #endif -#ifdef __NR_uretprobe -# define SYS_uretprobe __NR_uretprobe +#ifdef __NR_uretprobe +#define SYS_uretprobe __NR_uretprobe #endif -#ifdef __NR_uselib -# define SYS_uselib __NR_uselib +#ifdef __NR_uselib +#define SYS_uselib __NR_uselib #endif -#ifdef __NR_userfaultfd -# define SYS_userfaultfd __NR_userfaultfd +#ifdef __NR_userfaultfd +#define SYS_userfaultfd __NR_userfaultfd #endif -#ifdef __NR_ustat -# define SYS_ustat __NR_ustat +#ifdef __NR_ustat +#define SYS_ustat __NR_ustat #endif -#ifdef __NR_utime -# define SYS_utime __NR_utime +#ifdef __NR_utime +#define SYS_utime __NR_utime #endif -#ifdef __NR_utimensat -# define SYS_utimensat __NR_utimensat +#ifdef __NR_utimensat +#define SYS_utimensat __NR_utimensat #endif -#ifdef __NR_utimensat_time64 -# define SYS_utimensat_time64 __NR_utimensat_time64 +#ifdef __NR_utimensat_time64 +#define SYS_utimensat_time64 __NR_utimensat_time64 #endif -#ifdef __NR_utimes -# define SYS_utimes __NR_utimes +#ifdef __NR_utimes +#define SYS_utimes __NR_utimes #endif -#ifdef __NR_utrap_install -# define SYS_utrap_install __NR_utrap_install +#ifdef __NR_utrap_install +#define SYS_utrap_install __NR_utrap_install #endif -#ifdef __NR_vfork -# define SYS_vfork __NR_vfork +#ifdef __NR_vfork +#define SYS_vfork __NR_vfork #endif -#ifdef __NR_vhangup -# define SYS_vhangup __NR_vhangup +#ifdef __NR_vhangup +#define SYS_vhangup __NR_vhangup #endif -#ifdef __NR_vm86 -# define SYS_vm86 __NR_vm86 +#ifdef __NR_vm86 +#define SYS_vm86 __NR_vm86 #endif -#ifdef __NR_vm86old -# define SYS_vm86old __NR_vm86old +#ifdef __NR_vm86old +#define SYS_vm86old __NR_vm86old #endif -#ifdef __NR_vmsplice -# define SYS_vmsplice __NR_vmsplice +#ifdef __NR_vmsplice +#define SYS_vmsplice __NR_vmsplice #endif -#ifdef __NR_wait4 -# define SYS_wait4 __NR_wait4 +#ifdef __NR_wait4 +#define SYS_wait4 __NR_wait4 #endif -#ifdef __NR_waitid -# define SYS_waitid __NR_waitid +#ifdef __NR_waitid +#define SYS_waitid __NR_waitid #endif -#ifdef __NR_waitpid -# define SYS_waitpid __NR_waitpid +#ifdef __NR_waitpid +#define SYS_waitpid __NR_waitpid #endif -#ifdef __NR_write -# define SYS_write __NR_write +#ifdef __NR_write +#define SYS_write __NR_write #endif -#ifdef __NR_writev -# define SYS_writev __NR_writev +#ifdef __NR_writev +#define SYS_writev __NR_writev #endif #endif /* __MLIBC_SYSCALL_ALIAS_BIT */ diff --git a/tests/posix/pthread_attr.c b/tests/posix/pthread_attr.c index e523c0d08d..b8e1198861 100644 --- a/tests/posix/pthread_attr.c +++ b/tests/posix/pthread_attr.c @@ -1,10 +1,10 @@ -#include +#include #include #include -#include +#include +#include #include #include -#include static void test_detachstate() { pthread_attr_t attr; @@ -12,19 +12,21 @@ static void test_detachstate() { int detachstate; assert(!pthread_attr_getdetachstate(&attr, &detachstate)); assert(detachstate == PTHREAD_CREATE_DETACHED); - assert(pthread_attr_setdetachstate(&attr, 2* (PTHREAD_CREATE_DETACHED + - PTHREAD_CREATE_JOINABLE)) == EINVAL); + assert( + pthread_attr_setdetachstate(&attr, 2 * (PTHREAD_CREATE_DETACHED + PTHREAD_CREATE_JOINABLE)) + == EINVAL + ); } static void *stacksize_worker(void *arg) { - size_t default_stacksize = (*(size_t*)arg); - size_t alloc_size = default_stacksize + default_stacksize/2; + size_t default_stacksize = (*(size_t *)arg); + size_t alloc_size = default_stacksize + default_stacksize / 2; void *area = alloca(alloc_size); // If the allocated stack was not enough this will crash. // Trample both the start and end of the area so it works on both upwards- // and downwards-growing stacks. - *(volatile char*)area = 1; - *(volatile char*)(area + alloc_size - 1) = 1; + *(volatile char *)area = 1; + *(volatile char *)(area + alloc_size - 1) = 1; return NULL; } @@ -54,8 +56,9 @@ static void test_scope() { int scope; assert(!pthread_attr_getscope(&attr, &scope)); assert(scope == PTHREAD_SCOPE_SYSTEM); - assert(pthread_attr_setscope(&attr, 2* (PTHREAD_SCOPE_SYSTEM + - PTHREAD_SCOPE_PROCESS)) == EINVAL); + assert( + pthread_attr_setscope(&attr, 2 * (PTHREAD_SCOPE_SYSTEM + PTHREAD_SCOPE_PROCESS)) == EINVAL + ); } static void test_inheritsched() { @@ -64,8 +67,10 @@ static void test_inheritsched() { int inheritsched; assert(!pthread_attr_getinheritsched(&attr, &inheritsched)); assert(inheritsched == PTHREAD_INHERIT_SCHED); - assert(pthread_attr_setinheritsched(&attr, 2* (PTHREAD_INHERIT_SCHED + - PTHREAD_EXPLICIT_SCHED)) == EINVAL); + assert( + pthread_attr_setinheritsched(&attr, 2 * (PTHREAD_INHERIT_SCHED + PTHREAD_EXPLICIT_SCHED)) + == EINVAL + ); } static void test_schedparam() { @@ -83,28 +88,29 @@ static void test_schedpolicy() { int policy; assert(!pthread_attr_getschedpolicy(&attr, &policy)); assert(policy == SCHED_FIFO); - assert(pthread_attr_setinheritsched(&attr, 2* (SCHED_FIFO + SCHED_RR + - SCHED_OTHER)) == EINVAL); + assert( + pthread_attr_setinheritsched(&attr, 2 * (SCHED_FIFO + SCHED_RR + SCHED_OTHER)) == EINVAL + ); } static void *stackaddr_worker(void *arg) { - void *addr = *(void**)arg; + void *addr = *(void **)arg; void *sp; #if defined(__x86_64__) - asm volatile ("mov %%rsp, %0" : "=r"(sp)); + asm volatile("mov %%rsp, %0" : "=r"(sp)); #elif defined(__i386__) - asm volatile ("mov %%esp, %0" : "=r"(sp)); + asm volatile("mov %%esp, %0" : "=r"(sp)); #elif defined(__aarch64__) - asm volatile ("mov %0, sp" : "=r"(sp)); -#elif defined (__riscv) - asm volatile ("mv %0, sp" : "=r"(sp)); + asm volatile("mov %0, sp" : "=r"(sp)); +#elif defined(__riscv) + asm volatile("mv %0, sp" : "=r"(sp)); #elif defined(__m68k__) - asm volatile ("move.l %%sp, %0" : "=r"(sp)); -#elif defined (__loongarch64) - asm volatile ("move %0, $sp" : "=r"(sp)); + asm volatile("move.l %%sp, %0" : "=r"(sp)); +#elif defined(__loongarch64) + asm volatile("move %0, $sp" : "=r"(sp)); #else -# error Unknown architecture +#error Unknown architecture #endif // Check if our stack pointer is in a sane range. @@ -118,8 +124,7 @@ static void test_stackaddr() { assert(!pthread_attr_init(&attr)); size_t size; assert(!pthread_attr_getstacksize(&attr, &size)); - void *addr = mmap(NULL, size, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + void *addr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); assert(!pthread_attr_setstack(&attr, addr, size)); assert(!pthread_attr_setguardsize(&attr, 0)); void *new_addr; @@ -137,7 +142,7 @@ static void test_stackaddr() { #if !defined(USE_HOST_LIBC) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 32) static void test_stack() { pthread_attr_t attr; - void *stackaddr = (void*)1; + void *stackaddr = (void *)1; size_t stacksize = PTHREAD_STACK_MIN; assert(!pthread_attr_setstack(&attr, stackaddr, stacksize)); diff --git a/tests/posix/sigaltstack.c b/tests/posix/sigaltstack.c index a3636a0074..623dfffd2b 100644 --- a/tests/posix/sigaltstack.c +++ b/tests/posix/sigaltstack.c @@ -38,25 +38,31 @@ int main() { // This is used to trash the stack to ensure sigaltstack actually switched stacks. #if defined(__x86_64__) - asm volatile ("mov $0, %rsp\n" - "\t" "push $0"); + asm volatile("mov $0, %rsp\n" + "\t" + "push $0"); #elif defined(__i386__) - asm volatile ("mov $0, %esp\n" - "\t" "push $0"); + asm volatile("mov $0, %esp\n" + "\t" + "push $0"); #elif defined(__aarch64__) - asm volatile ("mov sp, %0\n" - "\t" "stp x0, x1, [sp, #-16]!" :: "r"((uint64_t)0)); + asm volatile("mov sp, %0\n" + "\t" + "stp x0, x1, [sp, #-16]!" ::"r"((uint64_t)0)); #elif defined(__riscv) && __riscv_xlen == 64 - asm volatile ("li sp, 0\n" - "\t" "sd zero, 0(sp)"); -#elif defined (__m68k__) - asm volatile ("move.l #0, %sp\n" - "\t" "move.l #0, -(%sp)"); + asm volatile("li sp, 0\n" + "\t" + "sd zero, 0(sp)"); +#elif defined(__m68k__) + asm volatile("move.l #0, %sp\n" + "\t" + "move.l #0, -(%sp)"); #elif defined(__loongarch64) - asm volatile ("addi.d $sp, $r0, 0\n" - "\t" "st.d $r0, $sp, 0"); + asm volatile("addi.d $sp, $r0, 0\n" + "\t" + "st.d $r0, $sp, 0"); #else -# error Unknown architecture +#error Unknown architecture #endif return 0; From 6008a373c7e743a0ab8d99b90876b5ae2c5eefd8 Mon Sep 17 00:00:00 2001 From: localcc Date: Sun, 22 Jun 2025 17:49:51 +0200 Subject: [PATCH 2/3] feat: (almost) complete ppc64 support --- abis/linux/auxv.h | 3 + abis/linux/ipc.h | 3 +- abis/linux/shm.h | 12 + abis/linux/signal.h | 47 ++ abis/linux/stat.h | 21 + meson.build | 1 + options/ansi/include/bits/ansi/fenv.h | 15 + .../ansi/musl-generic-math/__fpclassifyl.c | 18 + options/ansi/musl-generic-math/exp10l.c | 22 + options/ansi/musl-generic-math/expl.c | 3 +- options/ansi/musl-generic-math/fabsl.c | 9 + options/ansi/musl-generic-math/ilogbl.c | 29 ++ options/ansi/musl-generic-math/lgammal.c | 3 +- options/ansi/musl-generic-math/libm.h | 12 + options/ansi/musl-generic-math/nextafterl.c | 3 + options/ansi/musl-generic-math/remquol.c | 3 + options/ansi/musl-generic-math/rintl.c | 3 + options/ansi/musl-generic-math/roundl.c | 3 + options/ansi/musl-generic-math/scalbnl.c | 5 +- options/elf/include/elf.h | 30 +- options/elf/include/link.h | 2 +- options/internal/include/bits/machine.h | 10 + options/internal/include/bits/types.h | 44 ++ options/internal/include/mlibc/tcb.hpp | 2 + .../powerpc64-include/mlibc/arch-defs.hpp | 12 + .../powerpc64-include/mlibc/thread.hpp | 22 + options/internal/powerpc64/fenv.S | 166 +++++++ options/internal/powerpc64/setjmp.S | 170 +++++++ options/rtld/generic/linker.cpp | 7 + options/rtld/generic/main.cpp | 179 ++++++- options/rtld/generic/relocation.hpp | 1 + options/rtld/include/mlibc/rtld-abi.hpp | 4 +- options/rtld/powerpc64/elf.hpp | 41 ++ options/rtld/powerpc64/entry.S | 49 ++ options/rtld/powerpc64/runtime.S | 9 + scripts/get-linux-headers.sh | 2 +- sysdeps/linux/aarch64/syscallnos.h | 1 + sysdeps/linux/generic/sysdeps.cpp | 38 ++ sysdeps/linux/include/bits/syscall_aliases.h | 3 + sysdeps/linux/loongarch64/syscallnos.h | 1 + sysdeps/linux/m68k/syscallnos.h | 1 + sysdeps/linux/powerpc64/arch-syscall.cpp | 115 +++++ sysdeps/linux/powerpc64/cp_syscall.S | 48 ++ sysdeps/linux/powerpc64/crt-src/Scrt1.S | 20 + sysdeps/linux/powerpc64/crt-src/crt1.S | 16 + sysdeps/linux/powerpc64/crt-src/crti.S | 13 + sysdeps/linux/powerpc64/crt-src/crtn.S | 9 + sysdeps/linux/powerpc64/signals.S | 23 + sysdeps/linux/powerpc64/syscallnos.h | 441 ++++++++++++++++++ sysdeps/linux/powerpc64/thread_entry.S | 52 +++ sysdeps/linux/riscv64/syscallnos.h | 1 + sysdeps/linux/x86/syscallnos.h | 1 + sysdeps/linux/x86_64/syscallnos.h | 1 + tests/posix/pthread_attr.c | 2 + tests/posix/sigaltstack.c | 4 + 55 files changed, 1736 insertions(+), 19 deletions(-) create mode 100644 options/internal/powerpc64-include/mlibc/arch-defs.hpp create mode 100644 options/internal/powerpc64-include/mlibc/thread.hpp create mode 100644 options/internal/powerpc64/fenv.S create mode 100644 options/internal/powerpc64/setjmp.S create mode 100644 options/rtld/generic/relocation.hpp create mode 100644 options/rtld/powerpc64/elf.hpp create mode 100644 options/rtld/powerpc64/entry.S create mode 100644 options/rtld/powerpc64/runtime.S create mode 100644 sysdeps/linux/powerpc64/arch-syscall.cpp create mode 100644 sysdeps/linux/powerpc64/cp_syscall.S create mode 100644 sysdeps/linux/powerpc64/crt-src/Scrt1.S create mode 100644 sysdeps/linux/powerpc64/crt-src/crt1.S create mode 100644 sysdeps/linux/powerpc64/crt-src/crti.S create mode 100644 sysdeps/linux/powerpc64/crt-src/crtn.S create mode 100644 sysdeps/linux/powerpc64/signals.S create mode 100644 sysdeps/linux/powerpc64/syscallnos.h create mode 100644 sysdeps/linux/powerpc64/thread_entry.S diff --git a/abis/linux/auxv.h b/abis/linux/auxv.h index 0206fd1111..b86f199593 100644 --- a/abis/linux/auxv.h +++ b/abis/linux/auxv.h @@ -7,6 +7,9 @@ #define AT_FPUCW 18 #define AT_SECURE 23 #define AT_RANDOM 25 +#define AT_HWCAP2 26 +#define AT_HWCAP3 29 +#define AT_HWCAP4 30 #define AT_EXECFN 31 #define AT_SYSINFO_EHDR 33 diff --git a/abis/linux/ipc.h b/abis/linux/ipc.h index 63b950c483..c5fe76f6e5 100644 --- a/abis/linux/ipc.h +++ b/abis/linux/ipc.h @@ -22,7 +22,8 @@ extern "C" { #if defined(__aarch64__) || defined(__i386__) || defined(__m68k__) #define IPC_64 0x100 -#elif defined(__x86_64__) || (defined(__riscv) && __riscv_xlen == 64) || defined(__loongarch64) +#elif defined(__x86_64__) || (defined(__riscv) && __riscv_xlen == 64) || defined(__loongarch64) \ + || defined(__powerpc64__) #define IPC_64 0 #else #error "Unsupported arch!" diff --git a/abis/linux/shm.h b/abis/linux/shm.h index ec1ae06b8f..df65380de5 100644 --- a/abis/linux/shm.h +++ b/abis/linux/shm.h @@ -77,6 +77,18 @@ struct shmid_ds { unsigned long shm_nattch; unsigned long __unused[2]; }; +#elif defined(__powerpc64__) +struct shmid_ds { + struct ipc_perm shm_perm; + time_t shm_atime; + time_t shm_dtime; + time_t shm_ctime; + size_t shm_segsz; + pid_t shm_cpid; + pid_t shm_lpid; + unsigned long shm_nattch; + unsigned long __unused[2]; +}; #else #error "Missing architecture specific code." #endif diff --git a/abis/linux/signal.h b/abis/linux/signal.h index 1377b90946..44244e8f80 100644 --- a/abis/linux/signal.h +++ b/abis/linux/signal.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -152,8 +153,14 @@ typedef struct { #define SIGUNUSED SIGSYS #define SIGCANCEL 32 +#if defined(__powerpc64__) +#define MINSIGSTKSZ 8192 +#define SIGSTKSZ 32768 +#else #define MINSIGSTKSZ 2048 #define SIGSTKSZ 8192 +#endif + #define SS_ONSTACK 1 #define SS_DISABLE 2 @@ -621,6 +628,46 @@ typedef struct __ucontext { mcontext_t uc_mcontext; } ucontext_t; +#elif defined(__powerpc64__) + +struct sigaltstack { + void *ss_sp; + int ss_flags; + size_t ss_size; +}; + +typedef unsigned long greg_t, gregset_t[48]; +typedef double fpreg_t, fpregset_t[33]; + +typedef __vector128 vrreg_t; +typedef vrreg_t vrregset_t[34]; + +struct pt_regs { + greg_t gpr[32]; + greg_t pc; +}; + +struct sigcontext { + unsigned long _unused[4]; + int signal; + int _pad0; + unsigned long handler; + unsigned long oldmask; + struct pt_regs *regs; + gregset_t gp_regs; + fpregset_t fp_regs; + vrreg_t *v_regs; + long vmx_reserve[101]; +}; + +typedef struct __ucontext { + unsigned long uc_flags; + struct ucontext *uc_link; + stack_t uc_stack; + sigset_t uc_sigmask; + struct sigcontext uc_mcontext; +} ucontext_t; + #else #error "Missing architecture specific code." #endif diff --git a/abis/linux/stat.h b/abis/linux/stat.h index 3231e71e76..f6c5ffba38 100644 --- a/abis/linux/stat.h +++ b/abis/linux/stat.h @@ -137,6 +137,27 @@ struct stat { ino_t st_ino; }; +#elif defined(__powerpc64__) + +struct stat { + unsigned long st_dev; + unsigned long st_ino; + unsigned long st_nlink; + mode_t st_mode; + uid_t st_uid; + gid_t st_gid; + unsigned long st_rdev; + long st_size; + unsigned long st_blksize; + unsigned long st_blocks; + struct timespec st_atim; + struct timespec st_mtim; + struct timespec st_ctim; + unsigned long __unused4; + unsigned long __unused5; + unsigned long __unused6; +}; + #endif #define stat64 stat diff --git a/meson.build b/meson.build index a1e526bc21..364abd490d 100644 --- a/meson.build +++ b/meson.build @@ -176,6 +176,7 @@ if default_library_paths.length() == 0 'arm': 32, 'm68k': 32, 'loongarch64': 64, + 'powerpc64': 64 } if target_word_size.get(target_machine.cpu_family()) == 64 default_library_paths = ['/lib', '/lib64', '/usr/lib', '/usr/lib64'] diff --git a/options/ansi/include/bits/ansi/fenv.h b/options/ansi/include/bits/ansi/fenv.h index 74b58f666a..e3861a2a2d 100644 --- a/options/ansi/include/bits/ansi/fenv.h +++ b/options/ansi/include/bits/ansi/fenv.h @@ -87,6 +87,21 @@ #define FE_UPWARD 0x200 #define FE_DOWNWARD 0x300 +#elif defined(__powerpc64__) + +#define FE_DIVBYZERO 0x4000000 +#define FE_INEXACT 0x2000000 +#define FE_INVALID 0x20000000 +#define FE_OVERFLOW 0x10000000 +#define FE_UNDERFLOW 0x8000000 + +#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) + +#define FE_TONEAREST 0 +#define FE_DOWNWARD 0b11 +#define FE_TOWARDZERO 0b01 +#define FE_UPWARD 0b10 + #else #error Unknown architecture #endif diff --git a/options/ansi/musl-generic-math/__fpclassifyl.c b/options/ansi/musl-generic-math/__fpclassifyl.c index 663100a973..1f3b143c8d 100644 --- a/options/ansi/musl-generic-math/__fpclassifyl.c +++ b/options/ansi/musl-generic-math/__fpclassifyl.c @@ -34,4 +34,22 @@ int __fpclassifyl(long double x) { return u.i2.lo | u.i2.hi ? FP_NAN : FP_INFINITE; return FP_NORMAL; } +#elif LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024 +int __fpclassifyl(long double x) { + union ldshape u = {x}; + + if (isnan(u.i.hi)) + return FP_NAN; + if (isinf(u.i.hi)) + return FP_INFINITE; + + if (u.i.hi == 0.0) { + if (u.i.lo == 0.0) + return FP_ZERO; + else + return fpclassify(u.i.lo); + } + + return fpclassify(u.i.hi); +} #endif diff --git a/options/ansi/musl-generic-math/exp10l.c b/options/ansi/musl-generic-math/exp10l.c index 96d1796570..5f9a646a4a 100644 --- a/options/ansi/musl-generic-math/exp10l.c +++ b/options/ansi/musl-generic-math/exp10l.c @@ -24,6 +24,28 @@ long double exp10l(long double x) { } return powl(10.0, x); } +#elif LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024 + +#define M_LN10l 2.302585092994045684017991454684364208L + +static const long double log10_high = 0x2.4d763776aaap+0L; +static const long double log10_low = 0x2.b05ba95b58ae0b4c28a38a3fb4p-48L; + +long double exp10l(long double x) { + if (!isfinite(x)) + return expl(x); + if (x < LDBL_MIN_10_EXP - LDBL_DIG - 10) + return LDBL_MIN * LDBL_MIN; + else if (x > LDBL_MAX_10_EXP + 1) + return LDBL_MAX * LDBL_MAX; + else if (fabsl(x) < 0x1p-109L) + return 1.0L; + + union ldshape u = {x}; + long double exp_hi = u.i.hi * log10_high; + long double exp_lo = u.i.hi * log10_low + u.i.lo * M_LN10l; + return expl(exp_hi) * expl(exp_lo); +} #endif weak_alias(exp10l, pow10l); diff --git a/options/ansi/musl-generic-math/expl.c b/options/ansi/musl-generic-math/expl.c index 69cd97fca2..4d42ba577f 100644 --- a/options/ansi/musl-generic-math/expl.c +++ b/options/ansi/musl-generic-math/expl.c @@ -113,7 +113,8 @@ long double expl(long double x) { x = 1.0 + 2.0 * x; return scalbnl(x, k); } -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 +#elif (LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384) \ + || (LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024) // TODO: broken implementation to make things compile long double expl(long double x) { return exp(x); } #endif diff --git a/options/ansi/musl-generic-math/fabsl.c b/options/ansi/musl-generic-math/fabsl.c index 74c8a4a844..3170615cca 100644 --- a/options/ansi/musl-generic-math/fabsl.c +++ b/options/ansi/musl-generic-math/fabsl.c @@ -8,4 +8,13 @@ long double fabsl(long double x) { u.i.se &= 0x7fff; return u.f; } +#elif LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024 +long double fabsl(long double x) { + union ldshape u = {x}; + + u.i1.lo = u.i1.lo ^ (u.i1.hi & 0x8000000000000000LL); + u.i1.hi = u.i1.hi & 0x7fffffffffffffffLL; + + return u.f; +} #endif diff --git a/options/ansi/musl-generic-math/ilogbl.c b/options/ansi/musl-generic-math/ilogbl.c index 84f6b551ba..ca338d1cee 100644 --- a/options/ansi/musl-generic-math/ilogbl.c +++ b/options/ansi/musl-generic-math/ilogbl.c @@ -48,4 +48,33 @@ int ilogbl(long double x) { } return e - 0x3fff; } +#elif LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024 +int ilogbl(long double x) { + union ldshape u = {x}; + + uint64_t hx = u.i1.hi & 0x7fffffffffffffffLL; + if (hx <= 0x0010000000000000LL) { + if (hx == 0) { + return FP_ILOGB0; + } else { + hx <<= 11; + int ix = 0; + for (ix = -1022; hx > 0; hx <<= 1) + ix -= 1; + return ix; + } + } else if (hx < 0x7ff0000000000000LL) { + int hexp = (hx >> 52) - 0x3ff; + if ((hx & 0x000fffffffffffffLL) == 0) { + if ((u.i1.hi ^ u.i1.lo) < 0 && (u.i1.lo & 0x7fffffffffffffffLL) != 0) + hexp--; + } + return hexp; + } else if (FP_ILOGBNAN != INT_MAX) { + if (hx == 0x7ff0000000000000LL) + return INT_MAX; + } + + return FP_ILOGBNAN; +} #endif diff --git a/options/ansi/musl-generic-math/lgammal.c b/options/ansi/musl-generic-math/lgammal.c index ceaa653f04..bcf9176578 100644 --- a/options/ansi/musl-generic-math/lgammal.c +++ b/options/ansi/musl-generic-math/lgammal.c @@ -333,7 +333,8 @@ long double __lgammal_r(long double x, int *sg) { r = nadj - r; return r; } -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 +#elif (LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384) \ + || (LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024) // TODO: broken implementation to make things compile double __lgamma_r(double x, int *sg); diff --git a/options/ansi/musl-generic-math/libm.h b/options/ansi/musl-generic-math/libm.h index 68e3612ef0..bcc4e77be6 100644 --- a/options/ansi/musl-generic-math/libm.h +++ b/options/ansi/musl-generic-math/libm.h @@ -65,6 +65,18 @@ union ldshape { uint64_t lo; } i2; }; +#elif LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024 && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +union ldshape { + long double f; + struct { + double hi; + double lo; + } i; + struct { + uint64_t hi; + uint64_t lo; + } i1; +}; #else #error Unsupported long double representation #endif diff --git a/options/ansi/musl-generic-math/nextafterl.c b/options/ansi/musl-generic-math/nextafterl.c index df83289fa0..3862476a84 100644 --- a/options/ansi/musl-generic-math/nextafterl.c +++ b/options/ansi/musl-generic-math/nextafterl.c @@ -67,4 +67,7 @@ long double nextafterl(long double x, long double y) { FORCE_EVAL(x * x + ux.f * ux.f); return ux.f; } +#elif LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024 +// todo(localcc): broken implementation to make things compile +long double nextafterl(long double x, long double y) { return 0; } #endif diff --git a/options/ansi/musl-generic-math/remquol.c b/options/ansi/musl-generic-math/remquol.c index e1acfb6b67..4095663224 100644 --- a/options/ansi/musl-generic-math/remquol.c +++ b/options/ansi/musl-generic-math/remquol.c @@ -119,4 +119,7 @@ long double remquol(long double x, long double y, int *quo) { *quo = sx ^ sy ? -(int)q : (int)q; return sx ? -x : x; } +#elif LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024 +// todo(localcc): broken implementation to make things compile +long double remquol(long double x, long double y, int *quo) { return 0; } #endif diff --git a/options/ansi/musl-generic-math/rintl.c b/options/ansi/musl-generic-math/rintl.c index c294b1733f..fa456fd1b6 100644 --- a/options/ansi/musl-generic-math/rintl.c +++ b/options/ansi/musl-generic-math/rintl.c @@ -22,4 +22,7 @@ long double rintl(long double x) { return 0 * x; return y; } +#elif LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024 +// todo(localcc): broken implementation to make things compile +long double rintl(long double x) { return 0; } #endif diff --git a/options/ansi/musl-generic-math/roundl.c b/options/ansi/musl-generic-math/roundl.c index c6aa3cc6bf..0f9e4be23e 100644 --- a/options/ansi/musl-generic-math/roundl.c +++ b/options/ansi/musl-generic-math/roundl.c @@ -30,4 +30,7 @@ long double roundl(long double x) { y = -y; return y; } +#elif LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024 +// todo(localcc): broken implementation to make things compile +long double roundl(long double x) { return 0; } #endif diff --git a/options/ansi/musl-generic-math/scalbnl.c b/options/ansi/musl-generic-math/scalbnl.c index 42205c4a49..4bb9d803d1 100644 --- a/options/ansi/musl-generic-math/scalbnl.c +++ b/options/ansi/musl-generic-math/scalbnl.c @@ -26,7 +26,10 @@ long double scalbnl(long double x, int n) { } } u.f = 1.0; - u.i.se = 0x3fff + n; + u.i.se = exp_bias + n; return x * u.f; } +#elif LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024 +// todo(localcc): broken implementation to make things compile +long double scalbnl(long double x, int n) { return 0; } #endif diff --git a/options/elf/include/elf.h b/options/elf/include/elf.h index 041839e6ed..3bf8fe8d25 100644 --- a/options/elf/include/elf.h +++ b/options/elf/include/elf.h @@ -307,6 +307,20 @@ enum { R_LARCH_IRELATIVE = 12 }; +enum { + R_PPC64_NONE = 0, + R_PPC64_JMP_SLOT = 21, + R_PPC64_ADDR64 = 38, + R_PPC64_GLOB_DAT = 20, + R_PPC64_RELATIVE = 22, + R_PPC64_IRELATIVE = 248, + R_PPC64_COPY = 19, + R_PPC64_DTPMOD64 = 68, + R_PPC64_DTPREL64 = 78, + R_PPC64_TPREL64 = 73, + R_PPC64_TLS = 67 +}; + typedef struct { Elf32_Addr r_offset; Elf32_Word r_info; @@ -332,14 +346,11 @@ typedef struct { typedef Elf32_Word Elf32_Relr; typedef Elf64_Xword Elf64_Relr; -__MLIBC_INLINE_DEFINITION Elf64_Xword ELF64_R_SYM(Elf64_Xword info) { return info >> 32; } -__MLIBC_INLINE_DEFINITION Elf64_Xword ELF64_R_TYPE(Elf64_Xword info) { return info & 0xFFFFFFFF; } -__MLIBC_INLINE_DEFINITION Elf64_Xword ELF64_R_INFO(Elf64_Xword sym, Elf64_Xword type) { - return ((((Elf64_Xword)(sym)) << 32) + (type)); -} - -__MLIBC_INLINE_DEFINITION Elf32_Word ELF32_R_SYM(Elf32_Word info) { return info >> 8; } -__MLIBC_INLINE_DEFINITION Elf32_Word ELF32_R_TYPE(Elf32_Word info) { return info & 0xFF; } +#define ELF64_R_SYM(info) (info >> 32) +#define ELF64_R_TYPE(info) (info & 0xFFFFFFFF) +#define ELF64_R_INFO(sym, type) ((((Elf64_Xword)(sym)) << 32) + (type)) +#define ELF32_R_SYM(info) (info >> 8) +#define ELF32_R_TYPE(info) (info & 0xff) enum { PT_NULL = 0, @@ -439,7 +450,8 @@ enum { DT_VERDEF = 0x6ffffffc, DT_VERDEFNUM = 0x6ffffffd, DT_VERNEED = 0x6ffffffe, - DT_VERNEEDNUM = 0x6fffffff + DT_VERNEEDNUM = 0x6fffffff, + DT_LOPROC = 0x70000000, }; enum { diff --git a/options/elf/include/link.h b/options/elf/include/link.h index bb1bd9d93e..cc56ee2f8c 100644 --- a/options/elf/include/link.h +++ b/options/elf/include/link.h @@ -9,7 +9,7 @@ extern "C" { #include #if defined(__x86_64__) || defined(__aarch64__) || (defined(__riscv) && __riscv_xlen == 64) \ - || defined(__loongarch64) + || defined(__loongarch64) || defined(__powerpc64__) #define ElfW(type) Elf64_##type #elif defined(__i386__) || defined(__m68k__) #define ElfW(type) Elf32_##type diff --git a/options/internal/include/bits/machine.h b/options/internal/include/bits/machine.h index 1f475e7eb6..f883ffdae6 100644 --- a/options/internal/include/bits/machine.h +++ b/options/internal/include/bits/machine.h @@ -118,6 +118,16 @@ struct __mlibc_jmpbuf_register_state { double fs6; double fs7; }; +#elif defined(__powerpc64__) +struct __mlibc_jmpbuf_register_state { + uint64_t gprs[17]; + uint64_t fprs[17]; + uint64_t lr; + uint64_t sp; + uint64_t toc; + uint32_t cr_fields; + // todo(localcc): VMX support +}; #else #error "Missing architecture specific code" #endif diff --git a/options/internal/include/bits/types.h b/options/internal/include/bits/types.h index 55079ea329..432668f1f1 100644 --- a/options/internal/include/bits/types.h +++ b/options/internal/include/bits/types.h @@ -192,6 +192,28 @@ typedef __mlibc_int64 __mlibc_int_fast64; #define __MLIBC_INT_FAST64_MAX __MLIBC_INT64_MAX #define __MLIBC_INT_FAST64_MIN __MLIBC_INT64_MIN +#elif defined(__powerpc64__) + +typedef __mlibc_int8 __mlibc_int_fast8; +#define __MLIBC_INT_FAST8_C(x) __MLIBC_INT8_C(x) +#define __MLIBC_INT_FAST8_MAX __MLIBC_INT8_MAX +#define __MLIBC_INT_FAST8_MIN __MLIBC_INT8_MIN + +typedef __mlibc_int64 __mlibc_int_fast16; +#define __MLIBC_INT_FAST16_C(x) __MLIBC_INT64_C(x) +#define __MLIBC_INT_FAST16_MAX __MLIBC_INT64_MAX +#define __MLIBC_INT_FAST16_MIN __MLIBC_INT64_MIN + +typedef __mlibc_int64 __mlibc_int_fast32; +#define __MLIBC_INT_FAST32_C(x) __MLIBC_INT64_C(x) +#define __MLIBC_INT_FAST32_MAX __MLIBC_INT64_MAX +#define __MLIBC_INT_FAST32_MIN __MLIBC_INT64_MIN + +typedef __mlibc_int64 __mlibc_int_fast64; +#define __MLIBC_INT_FAST64_C(x) __MLIBC_INT64_C(x) +#define __MLIBC_INT_FAST64_MAX __MLIBC_INT64_MAX +#define __MLIBC_INT_FAST64_MIN __MLIBC_INT64_MIN + #else #error "Missing architecture specific code" #endif @@ -330,6 +352,28 @@ typedef __mlibc_uint64 __mlibc_uint_fast64; #define __MLIBC_UINT_FAST64_MAX __MLIBC_UINT64_MAX #define __MLIBC_UINT_FAST64_MIN __MLIBC_UINT64_MIN +#elif defined(__powerpc64__) + +typedef __mlibc_uint8 __mlibc_uint_fast8; +#define __MLIBC_UINT_FAST8_C(x) __MLIBC_UINT8_C(x) +#define __MLIBC_UINT_FAST8_MAX __MLIBC_UINT8_MAX +#define __MLIBC_UINT_FAST8_MIN __MLIBC_UINT8_MIN + +typedef __mlibc_uint64 __mlibc_uint_fast16; +#define __MLIBC_UINT_FAST16_C(x) __MLIBC_UINT64_C(x) +#define __MLIBC_UINT_FAST16_MAX __MLIBC_UINT64_MAX +#define __MLIBC_UINT_FAST16_MIN __MLIBC_UINT64_MIN + +typedef __mlibc_uint64 __mlibc_uint_fast32; +#define __MLIBC_UINT_FAST32_C(x) __MLIBC_UINT64_C(x) +#define __MLIBC_UINT_FAST32_MAX __MLIBC_UINT64_MAX +#define __MLIBC_UINT_FAST32_MIN __MLIBC_UINT64_MIN + +typedef __mlibc_uint64 __mlibc_uint_fast64; +#define __MLIBC_UINT_FAST64_C(x) __MLIBC_UINT64_C(x) +#define __MLIBC_UINT_FAST64_MAX __MLIBC_UINT64_MAX +#define __MLIBC_UINT_FAST64_MIN __MLIBC_UINT64_MIN + #else #error "Missing architecture specific code" #endif diff --git a/options/internal/include/mlibc/tcb.hpp b/options/internal/include/mlibc/tcb.hpp index 25ba7615c4..3388ffe282 100644 --- a/options/internal/include/mlibc/tcb.hpp +++ b/options/internal/include/mlibc/tcb.hpp @@ -181,6 +181,8 @@ static_assert(sizeof(Tcb) - offsetof(Tcb, cancelBits) == 96); static_assert(sizeof(Tcb) - offsetof(Tcb, cancelBits) == 0x30); #elif defined(__loongarch64) static_assert(sizeof(Tcb) - offsetof(Tcb, cancelBits) == 96); +#elif defined(__powerpc64__) +static_assert(sizeof(Tcb) - offsetof(Tcb, cancelBits) == 96); #else #error "Missing architecture specific code." #endif diff --git a/options/internal/powerpc64-include/mlibc/arch-defs.hpp b/options/internal/powerpc64-include/mlibc/arch-defs.hpp new file mode 100644 index 0000000000..0a4789f539 --- /dev/null +++ b/options/internal/powerpc64-include/mlibc/arch-defs.hpp @@ -0,0 +1,12 @@ +#ifndef MLIBC_ARCH_DEFS_HPP +#define MLIBC_ARCH_DEFS_HPP + +#include + +namespace mlibc { + +inline constexpr size_t page_size = 0x1000; + +} // namespace mlibc + +#endif // MLIBC_ARCH_DEFS_HPP diff --git a/options/internal/powerpc64-include/mlibc/thread.hpp b/options/internal/powerpc64-include/mlibc/thread.hpp new file mode 100644 index 0000000000..2f9e42ef77 --- /dev/null +++ b/options/internal/powerpc64-include/mlibc/thread.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include + +namespace mlibc { + +inline Tcb *get_current_tcb() { + // inverse of sys_tcb_set from linux sysdeps.cpp + uintptr_t thread_ptr; + asm volatile("mr %0, 13" : "=r"(thread_ptr)); + return reinterpret_cast(thread_ptr - 0x7000 - sizeof(Tcb)); +} + +inline uintptr_t get_sp() { + uintptr_t sp; + asm volatile("mr %0, 1" : "=r"(sp)); + return sp; +} + +} // namespace mlibc diff --git a/options/internal/powerpc64/fenv.S b/options/internal/powerpc64/fenv.S new file mode 100644 index 0000000000..b6985f66a8 --- /dev/null +++ b/options/internal/powerpc64/fenv.S @@ -0,0 +1,166 @@ +.abiversion 1 +.section ".opd", "aw" +.align 8 + +.global feclearexcept +.type feclearexcept,@function +feclearexcept: + .quad .L.feclearexcept + .quad .TOC. + .quad 0 + +.global feraiseexcept +.type feraiseexcept,@function +feraiseexcept: + .quad .L.feraiseexcept + .quad .TOC. + .quad 0 + +.global __fesetround +.hidden __fesetround +.type __fesetround,@function +__fesetround: + .quad .L.__fesetround + .quad .TOC. + .quad 0 + +.global fegetround +.type fegetround,@function +fegetround: + .quad .L.fegetround + .quad .TOC. + .quad 0 + +.global fegetenv +.type fegetenv,@function +fegetenv: + .quad .L.fegetenv + .quad .TOC. + .quad 0 + +.global fesetenv +.type fesetenv,@function +fesetenv: + .quad .L.fesetenv + .quad .TOC. + .quad 0 + +.global fetestexcept +.type fetestexcept,@function +fetestexcept: + .quad .L.fetestexcept + .quad .TOC. + .quad 0 + +.text + +.L.feclearexcept: + addi 1, 1, -8 + + mffs 4 + stfd 4, 0(1) + + ld 4, 0(1) + + nor 3, 3, 3 + and 4, 3, 4 + + std 4, 0(1) + lfd 4, 0(1) + mtfsf 0xff, 4 + + addi 1, 1, 8 + blr + +.L.feraiseexcept: + addi 1, 1, -8 + + mffs 4 + stfd 4, 0(1) + + ld 4, 0(1) + + or 4, 3, 4 + + std 4, 0(1) + lfd 4, 0(1) + mtfsf 0xff, 4 + + li 3, 0 + + addi 1, 1, 8 + blr + +.L.__fesetround: + addi 1, 1, -8 + + mffs 4 + stfd 4, 0(1) + ld 4, 0(1) + + rlwinm 4, 4, 0, 0, 29 + or 4, 3, 4 + + std 4, 0(1) + lfd 4, 0(1) + mtfsf 0xff, 4 + + addi 1, 1, 8 + blr + +.L.fegetround: + addi 1, 1, -8 + + mffs 4 + stfd 4, 0(1) + ld 4, 0(1) + + andi. 3, 4, 0b11 + + addi 1, 1, 8 + blr + +.L.fegetenv: + addi 1, 1, -8 + + mffs 4 + stfd 4, 0(1) + ld 4, 0(1) + + rldicr 4, 4, 32, 31 + std 4, 0(3) + + li 3, 0 + + addi 1, 1, 8 + blr + +.L.fesetenv: + addi 1, 1, -8 + + ld 4, 0(3) + srdi 4, 4, 32 + + std 4, 0(1) + lfd 4, 0(1) + mtfsf 0xff, 4 + + li 3, 0 + + addi 1, 1, 8 + blr + +.L.fetestexcept: + addi 1, 1, -8 + + mffs 4 + stfd 4, 0(1) + ld 4, 0(1) + + and 3, 4, 3 + + addi 1, 1, 8 + blr + +.section .note.GNU-stack,"",%progbits + diff --git a/options/internal/powerpc64/setjmp.S b/options/internal/powerpc64/setjmp.S new file mode 100644 index 0000000000..56ebafae48 --- /dev/null +++ b/options/internal/powerpc64/setjmp.S @@ -0,0 +1,170 @@ +.abiversion 1 +.section ".opd", "aw" +.align 8 + +.global setjmp +.type setjmp, "function" +.global _setjmp +.type _setjmp, "function" +setjmp: +_setjmp: + .quad .L._setjmp + .quad .TOC. + .quad 0 + +.global sigsetjmp +.type sigsetjmp, "function" +sigsetjmp: + .quad .L.sigsetjmp + .quad .TOC. + .quad 0 + +.global longjmp +.type longjmp, "function" +.global _longjmp +.type _longjmp, "function" +longjmp: +_longjmp: + .quad .L._longjmp + .quad .TOC. + .quad 0 + +.text + +.L.__setjmp: + // saving gprs + std 14, 0(3) + std 15, 8(3) + std 16, 16(3) + std 17, 24(3) + std 18, 32(3) + std 19, 40(3) + std 20, 48(3) + std 21, 56(3) + std 22, 64(3) + std 23, 72(3) + std 24, 80(3) + std 25, 88(3) + std 26, 96(3) + std 27, 104(3) + std 28, 112(3) + std 29, 120(3) + std 30, 128(3) + std 31, 136(3) + + // saving fprs + stfd 14, 144(3) + stfd 15, 152(3) + stfd 16, 160(3) + stfd 17, 168(3) + stfd 18, 176(3) + stfd 19, 184(3) + stfd 20, 192(3) + stfd 21, 200(3) + stfd 22, 208(3) + stfd 23, 216(3) + stfd 24, 224(3) + stfd 25, 232(3) + stfd 26, 240(3) + stfd 27, 248(3) + stfd 28, 256(3) + stfd 29, 264(3) + stfd 30, 272(3) + stfd 31, 280(3) + + // saving lr + mflr 14 + std 14, 288(3) + + // saving sp + std 1, 296(3) + + // saving toc + std 2, 304(3) + + // saving cr + mfcr 14 + std 14, 312(3) + + cmpwi 5, 0 + bne 1f + + li 3, 0 + blr +1: + b __sigsetjmp + nop + +.L._setjmp: + li 5, 0 + b .L.__setjmp + +.L.sigsetjmp: + li 5, 1 + b .L.__setjmp + +.L._longjmp: + // todo(localcc): implement VMX + // loading gprs + ld 14, 0(3) + ld 15, 8(3) + ld 16, 16(3) + ld 17, 24(3) + ld 18, 32(3) + ld 19, 40(3) + ld 20, 48(3) + ld 21, 56(3) + ld 22, 64(3) + ld 23, 72(3) + ld 24, 80(3) + ld 25, 88(3) + ld 26, 96(3) + ld 27, 104(3) + ld 28, 112(3) + ld 29, 120(3) + ld 30, 128(3) + ld 31, 136(3) + + // loading fprs + lfd 14, 144(3) + lfd 15, 152(3) + lfd 16, 160(3) + lfd 17, 168(3) + lfd 18, 176(3) + lfd 19, 184(3) + lfd 20, 192(3) + lfd 21, 200(3) + lfd 22, 208(3) + lfd 23, 216(3) + lfd 24, 224(3) + lfd 25, 232(3) + lfd 26, 240(3) + lfd 27, 248(3) + lfd 28, 256(3) + lfd 29, 264(3) + lfd 30, 272(3) + lfd 31, 280(3) + + // loading lr + ld 14, 288(3) + mtlr 14 + + // loading sp + ld 1, 296(3) + + // loading toc + ld 2, 304(3) + + // loading cr + ld 14, 312(3) + mtcr 14 + + mr 3, 4 + cmpwi 3, 0 + bne 1f + addi 3, 3, 1 +1: + blr + +.section .note.GNU-stack,"",%progbits + diff --git a/options/rtld/generic/linker.cpp b/options/rtld/generic/linker.cpp index ef17a731cf..961005bfbc 100644 --- a/options/rtld/generic/linker.cpp +++ b/options/rtld/generic/linker.cpp @@ -47,6 +47,9 @@ constexpr inline ptrdiff_t tlsOffsetFromTp = -0x7000; #elif defined(__loongarch64) constexpr inline bool tlsAboveTp = true; constexpr inline uintptr_t tlsOffsetFromTp = 0; +#elif defined(__powerpc64__) +constexpr inline bool tlsAboveTp = true; +constexpr inline uintptr_t tlsOffsetFromTp = -0x7000; #else #error Unknown architecture #endif @@ -858,6 +861,10 @@ void ObjectRepository::_parseDynamic(SharedObject *object) { case DT_RELRENT: #ifdef __riscv case DT_TEXTREL: // Work around https://sourceware.org/bugzilla/show_bug.cgi?id=24673. +#endif +#if defined(__powerpc64__) + case DT_LOPROC: + case 0x70000003: // unknown #endif break; case DT_TLSDESC_PLT: diff --git a/options/rtld/generic/main.cpp b/options/rtld/generic/main.cpp index d61c554fae..38f70b0f08 100644 --- a/options/rtld/generic/main.cpp +++ b/options/rtld/generic/main.cpp @@ -17,7 +17,9 @@ #include "linker.hpp" #if __MLIBC_POSIX_OPTION + #include + #endif #define HIDDEN __attribute__((__visibility__("hidden"))) @@ -58,6 +60,10 @@ frg::manual_box> preloads; static SharedObject *executableSO; extern HIDDEN char __ehdr_start[]; +#if defined(__powerpc64__) +uintptr_t ldsoBase; +#endif + // Global debug interface variable DebugInterface globalDebugInterface; @@ -74,12 +80,15 @@ uintptr_t getLdsoBase() { return runtime_dynamic - linktime_dynamic; #elif defined(__riscv) return reinterpret_cast(&__ehdr_start); +#elif defined(__powerpc64__) + return ldsoBase; #else #error Unknown architecture! #endif } -#if !defined(__m68k__) +#if defined(__x86_64__) || defined(__aarch64__) || defined(__riscv) || defined(__i386__) \ + || defined(__loongarch64) // Relocates the dynamic linker (i.e. this DSO) itself. // Assumptions: // - There are no references to external symbols. @@ -180,7 +189,159 @@ extern "C" void relocateSelf() { } } } -#else +#elif defined(__powerpc64__) +// ppc64 elfv1 can't rely on the OPD before relocations, therefore calling the getLdsoBase function +// will fail +extern "C" void relocateSelfPPC64(uintptr_t ldso_base) { + size_t rela_offset = 0; + size_t rela_size = 0; + size_t rel_offset = 0; + size_t rel_size = 0; + size_t relr_offset = 0; + size_t relr_size = 0; + + size_t symtab_offset = 0; + size_t relplt_offset = 0; + size_t relplt_size = 0; + uint64_t relplt_type = 0; + for (size_t i = 0; _DYNAMIC[i].d_tag != DT_NULL; i++) { + auto ent = &_DYNAMIC[i]; + switch (ent->d_tag) { + case DT_REL: + rel_offset = ent->d_un.d_ptr; + break; + case DT_RELSZ: + rel_size = ent->d_un.d_val; + break; + case DT_RELA: + rela_offset = ent->d_un.d_ptr; + break; + case DT_RELASZ: + rela_size = ent->d_un.d_val; + break; + case DT_RELR: + relr_offset = ent->d_un.d_ptr; + break; + case DT_RELRSZ: + relr_size = ent->d_un.d_val; + break; + case DT_JMPREL: + relplt_offset = ent->d_un.d_ptr; + break; + case DT_PLTRELSZ: + relplt_size = ent->d_un.d_val; + break; + case DT_PLTREL: + relplt_type = ent->d_un.d_val; + break; + case DT_SYMTAB: + symtab_offset = ent->d_un.d_ptr; + break; + } + } + + for (size_t disp = 0; disp < rela_size; disp += sizeof(elf_rela)) { + auto reloc = reinterpret_cast(ldso_base + rela_offset + disp); + + auto type = ELF_R_TYPE(reloc->r_info); + if (ELF_R_SYM(reloc->r_info)) + __builtin_trap(); + + auto p = reinterpret_cast(ldso_base + reloc->r_offset); + switch (type) { + case R_RELATIVE: + *p = ldso_base + reloc->r_addend; + break; + default: + __builtin_trap(); + } + } + + for (size_t disp = 0; disp < rel_size; disp += sizeof(elf_rel)) { + auto reloc = reinterpret_cast(ldso_base + rel_offset + disp); + + auto type = ELF_R_TYPE(reloc->r_info); + if (ELF_R_SYM(reloc->r_info)) + __builtin_trap(); + + auto p = reinterpret_cast(ldso_base + reloc->r_offset); + switch (type) { + case R_RELATIVE: + *p += ldso_base; + break; + default: + __builtin_trap(); + } + } + + elf_addr *addr = nullptr; + for (size_t disp = 0; disp < relr_size; disp += sizeof(elf_relr)) { + auto entry = *(elf_relr *)(ldso_base + relr_offset + disp); + + // Even entry indicates the beginning address. + if (!(entry & 1)) { + addr = (elf_addr *)(ldso_base + entry); + __ensure(addr); + *addr++ += ldso_base; + } else { + // Odd entry indicates entry is a bitmap of the subsequent locations to be relocated. + + // The first bit of an entry is always a marker about whether the entry is an address or + // a bitmap, discard it. + entry >>= 1; + + for (int i = 0; entry; ++i) { + if (entry & 1) { + addr[i] += ldso_base; + } + entry >>= 1; + } + + // Each entry describes at max 63 (on 64bit) or 31 (on 32bit) subsequent locations. + addr += CHAR_BIT * sizeof(elf_relr) - 1; + } + } + + // this is mostly copied from linker.cpp, but we need plt relocations here already + bool is_rela = relplt_type == DT_RELA; + size_t plt_rel_size = is_rela ? sizeof(elf_rela) : sizeof(elf_rel); + for (size_t disp = 0; disp < relplt_size; disp += plt_rel_size) { + elf_info type; + elf_info symbol_index; + + uintptr_t rel_addr; + uintptr_t addend [[maybe_unused]] = 0; + + if (is_rela) { + auto reloc = reinterpret_cast(ldso_base + relplt_offset + disp); + type = ELF_R_TYPE(reloc->r_info); + symbol_index = ELF_R_SYM(reloc->r_info); + rel_addr = ldso_base + reloc->r_offset; + addend = reloc->r_addend; + } else { + auto reloc = reinterpret_cast(ldso_base + relplt_offset + disp); + type = ELF_R_TYPE(reloc->r_info); + symbol_index = ELF_R_SYM(reloc->r_info); + rel_addr = ldso_base + reloc->r_offset; + } + + elf_sym *symbol = + reinterpret_cast(ldso_base + symtab_offset + symbol_index * sizeof(elf_sym)); + + // this only resolves jump slots in the current ldso, others will get + // resolved incorrectly but ld.so should not rely on external deps either way + switch (type) { + case R_JUMP_SLOT: + *reinterpret_cast(rel_addr) = ldso_base + symbol->st_value; + break; + default: + __builtin_trap(); + } + } + + ldsoBase = ldso_base; +} +#elif defined(__m68k__) // m68k needs a tighter relocation function to avoid itself relying on the GOT. extern "C" void relocateSelf68k(elf_dyn *dynamic, uintptr_t ldso_base) { size_t rela_offset = 0; @@ -215,7 +376,9 @@ extern "C" void relocateSelf68k(elf_dyn *dynamic, uintptr_t ldso_base) { } } } -#endif // !defined(__m68k__) +#else +#error Unknown architecture +#endif #endif extern "C" void *lazyRelocate(SharedObject *object, unsigned int rel_index) { @@ -405,6 +568,16 @@ extern "C" void *interpreterMain(uintptr_t *entry_stack) { << " in program interpreter" << frg::endlog; break; } +#if defined(__powerpc64__) + case DT_LOPROC: + case 0x70000003: // unknown + // we handle those on powerpc + case DT_JMPREL: + case DT_PLTRELSZ: + case DT_PLTREL: + continue; +#endif + default: mlibc::panicLogger() << "rtld: unexpected dynamic entry " << ent->d_tag << " in program interpreter" << frg::endlog; diff --git a/options/rtld/generic/relocation.hpp b/options/rtld/generic/relocation.hpp new file mode 100644 index 0000000000..6f70f09bee --- /dev/null +++ b/options/rtld/generic/relocation.hpp @@ -0,0 +1 @@ +#pragma once diff --git a/options/rtld/include/mlibc/rtld-abi.hpp b/options/rtld/include/mlibc/rtld-abi.hpp index 39806eee55..a99681970d 100644 --- a/options/rtld/include/mlibc/rtld-abi.hpp +++ b/options/rtld/include/mlibc/rtld-abi.hpp @@ -4,7 +4,7 @@ #include #if defined(__x86_64__) || defined(__aarch64__) || defined(__i386__) || defined(__riscv) \ - || defined(__m68k__) || defined(__loongarch64) + || defined(__m68k__) || defined(__loongarch64) || defined(__powerpc64__) struct __abi_tls_entry { struct SharedObject *object; @@ -24,6 +24,8 @@ constexpr inline unsigned long TLS_DTV_OFFSET = 0x800; constexpr inline unsigned long TLS_DTV_OFFSET = 0; #elif defined(__m68k__) constexpr inline unsigned long TLS_DTV_OFFSET = 0x8000; +#elif defined(__powerpc64__) +constexpr inline unsigned long TLS_DTV_OFFSET = 0x8000; #else #error "Missing architecture specific code." #endif diff --git a/options/rtld/powerpc64/elf.hpp b/options/rtld/powerpc64/elf.hpp new file mode 100644 index 0000000000..66f1e45739 --- /dev/null +++ b/options/rtld/powerpc64/elf.hpp @@ -0,0 +1,41 @@ +#pragma once + +#include + +#define ELF_CLASS ELFCLASS64 +#define ELF_MACHINE EM_PPC64 + +using elf_ehdr = Elf64_Ehdr; +using elf_phdr = Elf64_Phdr; +using elf_dyn = Elf64_Dyn; +using elf_rel = Elf64_Rel; +using elf_rela = Elf64_Rela; +using elf_relr = Elf64_Relr; +using elf_sym = Elf64_Sym; +using elf_addr = Elf64_Addr; + +using elf_info = Elf64_Xword; +using elf_addend = Elf64_Sxword; + +using elf_version = Elf64_Half; +using elf_verdef = Elf64_Verdef; +using elf_verdaux = Elf64_Verdaux; +using elf_verneed = Elf64_Verneed; +using elf_vernaux = Elf64_Vernaux; + +#define ELF_R_SYM ELF64_R_SYM +#define ELF_R_TYPE ELF64_R_TYPE +#define ELF_ST_BIND ELF64_ST_BIND + +#define R_NONE R_PPC64_NONE +#define R_JUMP_SLOT R_PPC64_JMP_SLOT +#define R_ABSOLUTE R_PPC64_ADDR64 +#define R_GLOB_DAT R_PPC64_GLOB_DAT +#define R_RELATIVE R_PPC64_RELATIVE +#define R_IRELATIVE R_PPC64_IRELATIVE +// #define R_OFFSET +#define R_COPY R_PPC64_COPY +#define R_TLS_DTPMOD R_PPC64_DTPMOD64 +#define R_TLS_DTPREL R_PPC64_DTPREL64 +#define R_TLS_TPREL R_PPC64_TPREL64 +#define R_TLSDESC R_PPC64_TLS diff --git a/options/rtld/powerpc64/entry.S b/options/rtld/powerpc64/entry.S new file mode 100644 index 0000000000..dfe4fad62f --- /dev/null +++ b/options/rtld/powerpc64/entry.S @@ -0,0 +1,49 @@ +.text +.global _start +.section ".opd", "aw" +.align 8 +_start: + .quad _realstart + .quad .TOC. + .quad 0 +.text +.global _realstart +.hidden _realstart +_realstart: + mflr 0 + bl pc +pc: + mr 14, 1 // store entry stack + addi 1, 1, -288 // allocate redzone + std 2, 40(1) // store .TOC. + + mflr 3 // current instruction pointer + 8 because of mflr+bl before it + addi 3, 3, -8 + + addis 4, 2, _start@toc@ha + ld 4, _start@toc@l(4) + // lis 4, _realstart@ha + // addi 4, 4, _realstart@l // r4 = known address at link time + subf 3, 4, 3 // r3 = _realstart - ip = base load address + + // relocations are not applied yet, the .opd table is not correct + // so the stubs for calling the .opd entries are not going to work either + // calling the function manually + // lis 4, relocateSelfPPC64@ha + // addi 4, 4, relocateSelfPPC64@l + addis 4, 2, relocateSelfPPC64@toc@ha + ld 4, relocateSelfPPC64@toc@l(4) + add 4, 3, 4 + mtctr 4 + bctrl + + mr 3, 14 + bl interpreterMain + nop + + ld 2, 8(3) // loading toc and jumping to Scrt1.S entry + ld 3, 0(3) + mtctr 3 + bctr + +.section .note.GNU-stack,"",%progbits \ No newline at end of file diff --git a/options/rtld/powerpc64/runtime.S b/options/rtld/powerpc64/runtime.S new file mode 100644 index 0000000000..448ad65024 --- /dev/null +++ b/options/rtld/powerpc64/runtime.S @@ -0,0 +1,9 @@ +.abiversion 1 +.global pltRelocateStub +pltRelocateStub: + # we need to save / restore all registers than can hold function arguments + # we do not need to save callee-saved registers as they will not be trashed by lazyRelocate + # TODO: save floating point argument registers + // todo(localcc): implement + trap +.section .note.GNU-stack,"",%progbits \ No newline at end of file diff --git a/scripts/get-linux-headers.sh b/scripts/get-linux-headers.sh index 00d7d2d856..8e4993a71e 100755 --- a/scripts/get-linux-headers.sh +++ b/scripts/get-linux-headers.sh @@ -4,7 +4,7 @@ set -ex LINUX_MAJOR=v6.x LINUX_VERSION=6.13.8 -: "${ARCH:=$(uname -m)}" +: "${ARCH:=powerpc}" curl -Lo linux-$LINUX_VERSION.tar.xz https://cdn.kernel.org/pub/linux/kernel/$LINUX_MAJOR/linux-$LINUX_VERSION.tar.xz tar -xf linux-$LINUX_VERSION.tar.xz diff --git a/sysdeps/linux/aarch64/syscallnos.h b/sysdeps/linux/aarch64/syscallnos.h index d1a7161723..4e82ab5fd3 100644 --- a/sysdeps/linux/aarch64/syscallnos.h +++ b/sysdeps/linux/aarch64/syscallnos.h @@ -324,4 +324,5 @@ #define __NR_getxattrat 464 #define __NR_listxattrat 465 #define __NR_removexattrat 466 +#define __NR_open_tree_attr 467 #endif /* __MLIBC_SYSCALLNOS_h */ diff --git a/sysdeps/linux/generic/sysdeps.cpp b/sysdeps/linux/generic/sysdeps.cpp index 8a4fbacaca..e03ecc3f5c 100644 --- a/sysdeps/linux/generic/sysdeps.cpp +++ b/sysdeps/linux/generic/sysdeps.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -79,6 +80,26 @@ extern "C" void *__m68k_read_tp() { } #endif +#if defined(__powerpc64__) +typedef struct { + uint64_t hwcap_extn; + uint64_t hwcap; + uint32_t __unused; + uint32_t at_platform; + uintptr_t dso_slot2; + uintptr_t dso_slot1; + uintptr_t tar_save; + void *__private_ss; + uintptr_t ebb_handler; + uintptr_t ebb_ctx_pointer; + uintptr_t ebb_reserved1; + uintptr_t ebb_reserved2; + uintptr_t pointer_guard; + uintptr_t stack_guard; + void *dtv; +} tcbhead_t; +#endif + int sys_tcb_set(void *pointer) { #if defined(__x86_64__) auto ret = do_syscall(SYS_arch_prctl, 0x1002 /* ARCH_SET_FS */, pointer); @@ -112,6 +133,16 @@ int sys_tcb_set(void *pointer) { #elif defined(__loongarch64) uintptr_t thread_data = reinterpret_cast(pointer) + sizeof(Tcb); asm volatile("move $tp, %0" ::"r"(thread_data)); +#elif defined(__powerpc64__) + // todo(localcc): fix this? + // tcbhead_t* tcbhead = reinterpret_cast(reinterpret_cast(pointer) - + // sizeof(tcbhead_t)); const auto& aux_vec = get_aux_vec(); + // tcbhead->hwcap = (static_cast(aux_vec.at_hwcap) << 32) | aux_vec.at_hwcap2; + // tcbhead->hwcap_extn = (static_cast(aux_vec.at_hwcap3) << 32) | + // aux_vec.at_hwcap4; tcbhead->at_platform = aux_vec.at_platform; + + uintptr_t thread_data = reinterpret_cast(pointer) + 0x7000 + sizeof(Tcb); + asm volatile("mr 13, %0" ::"r"(thread_data)); #else #error "Missing architecture specific code." #endif @@ -663,6 +694,11 @@ int sys_clone(void *tcb, pid_t *pid_out, void *stack) { // TODO: We should change the sysdep so that we don't need to do this. auto tp = reinterpret_cast(tcb) + sizeof(Tcb) - 0x10; tcb = reinterpret_cast(tp); +#elif defined(__powerpc64__) + // TP should point to the address 0x7000 bytes after the TCB. + // TODO: We should change the sysdep so that we don't need to do this. + auto tp = reinterpret_cast(tcb) + sizeof(Tcb) + 0x7000; + tcb = reinterpret_cast(tp); #elif defined(__i386__) /* get the entry number, as we don't request a new one here */ uint32_t gs; @@ -712,6 +748,8 @@ int sys_before_cancellable_syscall(ucontext_t *uct) { auto pc = reinterpret_cast(uct->uc_mcontext.gregs[R_PC]); #elif defined(__loongarch64) auto pc = reinterpret_cast(uct->uc_mcontext.pc); +#elif defined(__powerpc64__) + auto pc = reinterpret_cast(uct->uc_mcontext.regs->pc); #else #error "Missing architecture specific code." #endif diff --git a/sysdeps/linux/include/bits/syscall_aliases.h b/sysdeps/linux/include/bits/syscall_aliases.h index 5976f28e78..cf2d3cfea2 100644 --- a/sysdeps/linux/include/bits/syscall_aliases.h +++ b/sysdeps/linux/include/bits/syscall_aliases.h @@ -809,6 +809,9 @@ #ifdef __NR_open_tree #define SYS_open_tree __NR_open_tree #endif +#ifdef __NR_open_tree_attr +#define SYS_open_tree_attr __NR_open_tree_attr +#endif #ifdef __NR_openat #define SYS_openat __NR_openat #endif diff --git a/sysdeps/linux/loongarch64/syscallnos.h b/sysdeps/linux/loongarch64/syscallnos.h index 271a79c450..152775697d 100644 --- a/sysdeps/linux/loongarch64/syscallnos.h +++ b/sysdeps/linux/loongarch64/syscallnos.h @@ -320,4 +320,5 @@ #define __NR_getxattrat 464 #define __NR_listxattrat 465 #define __NR_removexattrat 466 +#define __NR_open_tree_attr 467 #endif /* __MLIBC_SYSCALLNOS_h */ diff --git a/sysdeps/linux/m68k/syscallnos.h b/sysdeps/linux/m68k/syscallnos.h index 5dc7dcd745..6a77501b6b 100644 --- a/sysdeps/linux/m68k/syscallnos.h +++ b/sysdeps/linux/m68k/syscallnos.h @@ -439,4 +439,5 @@ #define __NR_getxattrat 464 #define __NR_listxattrat 465 #define __NR_removexattrat 466 +#define __NR_open_tree_attr 467 #endif /* __MLIBC_SYSCALLNOS_h */ diff --git a/sysdeps/linux/powerpc64/arch-syscall.cpp b/sysdeps/linux/powerpc64/arch-syscall.cpp new file mode 100644 index 0000000000..f03f9f01cf --- /dev/null +++ b/sysdeps/linux/powerpc64/arch-syscall.cpp @@ -0,0 +1,115 @@ +#include +#include + +using sc_word_t = __sc_word_t; + +sc_word_t transform_ret(sc_word_t ret) { + // reading cr0.SO + sc_word_t is_err; + asm volatile("mfcr %0" : "=r"(is_err)); + is_err = (is_err >> 28) & 0b1; + + // branchless negation + ret = (ret ^ -is_err) + is_err; + return ret; +} + +sc_word_t __do_syscall0(long sc) { + register int sc_reg asm("r0") = sc; + register sc_word_t ret asm("r3"); + asm volatile("sc" : "=r"(ret) : "r"(sc_reg) : "memory"); + return transform_ret(ret); +} + +sc_word_t __do_syscall1(long sc, sc_word_t arg1) { + register int sc_reg asm("r0") = sc; + register sc_word_t arg1_reg asm("r3") = arg1; + register sc_word_t ret asm("r3"); + asm volatile("sc" : "=r"(ret) : "r"(sc_reg), "r"(arg1_reg) : "memory"); + return transform_ret(ret); +} + +sc_word_t __do_syscall2(long sc, sc_word_t arg1, sc_word_t arg2) { + register int sc_reg asm("r0") = sc; + register sc_word_t arg1_reg asm("r3") = arg1; + register sc_word_t arg2_reg asm("r4") = arg2; + register sc_word_t ret asm("r3"); + asm volatile("sc" : "=r"(ret) : "r"(sc_reg), "r"(arg1_reg), "r"(arg2_reg) : "memory"); + return transform_ret(ret); +} + +sc_word_t __do_syscall3(long sc, sc_word_t arg1, sc_word_t arg2, sc_word_t arg3) { + register int sc_reg asm("r0") = sc; + register sc_word_t arg1_reg asm("r3") = arg1; + register sc_word_t arg2_reg asm("r4") = arg2; + register sc_word_t arg3_reg asm("r5") = arg3; + register sc_word_t ret asm("r3"); + asm volatile("sc" + : "=r"(ret) + : "r"(sc_reg), "r"(arg1_reg), "r"(arg2_reg), "r"(arg3_reg) + : "memory"); + return transform_ret(ret); +} + +sc_word_t __do_syscall4(long sc, sc_word_t arg1, sc_word_t arg2, sc_word_t arg3, sc_word_t arg4) { + register int sc_reg asm("r0") = sc; + register sc_word_t arg1_reg asm("r3") = arg1; + register sc_word_t arg2_reg asm("r4") = arg2; + register sc_word_t arg3_reg asm("r5") = arg3; + register sc_word_t arg4_reg asm("r6") = arg4; + register sc_word_t ret asm("r3"); + asm volatile("sc" + : "=r"(ret) + : "r"(sc_reg), "r"(arg1_reg), "r"(arg2_reg), "r"(arg3_reg), "r"(arg4_reg) + : "memory"); + return transform_ret(ret); +} + +sc_word_t __do_syscall5( + long sc, sc_word_t arg1, sc_word_t arg2, sc_word_t arg3, sc_word_t arg4, sc_word_t arg5 +) { + register int sc_reg asm("r0") = sc; + register sc_word_t arg1_reg asm("r3") = arg1; + register sc_word_t arg2_reg asm("r4") = arg2; + register sc_word_t arg3_reg asm("r5") = arg3; + register sc_word_t arg4_reg asm("r6") = arg4; + register sc_word_t arg5_reg asm("r7") = arg5; + register sc_word_t ret asm("r3"); + asm volatile( + "sc" + : "=r"(ret) + : "r"(sc_reg), "r"(arg1_reg), "r"(arg2_reg), "r"(arg3_reg), "r"(arg4_reg), "r"(arg5_reg) + : "memory" + ); + return transform_ret(ret); +} + +sc_word_t __do_syscall6( + long sc, + sc_word_t arg1, + sc_word_t arg2, + sc_word_t arg3, + sc_word_t arg4, + sc_word_t arg5, + sc_word_t arg6 +) { + register int sc_reg asm("r0") = sc; + register sc_word_t arg1_reg asm("r3") = arg1; + register sc_word_t arg2_reg asm("r4") = arg2; + register sc_word_t arg3_reg asm("r5") = arg3; + register sc_word_t arg4_reg asm("r6") = arg4; + register sc_word_t arg5_reg asm("r7") = arg5; + register sc_word_t arg6_reg asm("r8") = arg6; + register sc_word_t ret asm("r3"); + asm volatile("sc" + : "=r"(ret) + : "r"(sc_reg), + "r"(arg1_reg), + "r"(arg2_reg), + "r"(arg3_reg), + "r"(arg4_reg), + "r"(arg5_reg), + "r"(arg6_reg) + : "memory"); + return transform_ret(ret); +} diff --git a/sysdeps/linux/powerpc64/cp_syscall.S b/sysdeps/linux/powerpc64/cp_syscall.S new file mode 100644 index 0000000000..13e4fd8d08 --- /dev/null +++ b/sysdeps/linux/powerpc64/cp_syscall.S @@ -0,0 +1,48 @@ +.abiversion 1 +.section ".opd", "aw" +.align 8 +.global __mlibc_do_asm_cp_syscall +.type __mlibc_do_asm_cp_syscall, "function" +__mlibc_do_asm_cp_syscall: + .quad .L.__mlibc_do_asm_cp_syscall + .quad .TOC. + .quad 0 +.global __mlibc_syscall_begin +.global __mlibc_syscall_end + +.text +.L.__mlibc_do_asm_cp_syscall: + mr 0, 3 + mr 3, 4 + mr 4, 5 + mr 5, 6 + mr 6, 7 + mr 7, 8 + mr 8, 9 + + lwz 9, -0x7060(13) // Tcb::cancelBits +__mlibc_syscall_begin: + li 10, ((1 << 0) | (1 << 2)) + and 9, 9, 10 + cmpd 9, 10 + beq cancel + sc + + // linux sets cr0.SO on ppc64 if a syscall failed + // but the rest of the library expects a negated result code in case of a failure + // adjusting the return value + mfcr 4 + rlwinm 4, 4, 4, 31, 31 + neg 5, 4 + xor 3, 3, 5 + add 3, 3, 4 +__mlibc_syscall_end: + blr + +cancel: + b __mlibc_do_cancel + nop + trap + +.section .note.GNU-stack,"",%progbits + diff --git a/sysdeps/linux/powerpc64/crt-src/Scrt1.S b/sysdeps/linux/powerpc64/crt-src/Scrt1.S new file mode 100644 index 0000000000..25d16b5637 --- /dev/null +++ b/sysdeps/linux/powerpc64/crt-src/Scrt1.S @@ -0,0 +1,20 @@ +.section ".opd", "aw" +.align 8 +.global _start +_start: + .quad _realstart + .quad .TOC. + .quad 0 + +.text +_realstart: + std 2, 40(1) // store .TOC. on the stack + + mr 3, 1 + addis 4, 2, main@toc@ha + addi 4, 4, main@toc@l + b __mlibc_entry + nop + +.section .note.GNU-stack,"",%progbits + diff --git a/sysdeps/linux/powerpc64/crt-src/crt1.S b/sysdeps/linux/powerpc64/crt-src/crt1.S new file mode 100644 index 0000000000..1bd38e052f --- /dev/null +++ b/sysdeps/linux/powerpc64/crt-src/crt1.S @@ -0,0 +1,16 @@ +.section ".opd", "aw" +.align 8 +.global _start +_start: + .quad _realstart + .quad .TOC. + .quad 0 + +.text +_realstart: + // todo(localcc): implement + trap + nop + trap +.section .note.GNU-stack,"",%progbits + diff --git a/sysdeps/linux/powerpc64/crt-src/crti.S b/sysdeps/linux/powerpc64/crt-src/crti.S new file mode 100644 index 0000000000..78424379b1 --- /dev/null +++ b/sysdeps/linux/powerpc64/crt-src/crti.S @@ -0,0 +1,13 @@ +.section .init +.global _init +_init: + // todo(localcc): implement + trap + +.section .fini +.global _fini +_fini: + // todo(localcc): implement + trap +.section .note.GNU-stack,"",%progbits + diff --git a/sysdeps/linux/powerpc64/crt-src/crtn.S b/sysdeps/linux/powerpc64/crt-src/crtn.S new file mode 100644 index 0000000000..d415f1e10b --- /dev/null +++ b/sysdeps/linux/powerpc64/crt-src/crtn.S @@ -0,0 +1,9 @@ +.section .init + // todo(localcc): implement + trap + +.section .fini + // todo(localcc): implement + trap +.section .note.GNU-stack,"",%progbits + diff --git a/sysdeps/linux/powerpc64/signals.S b/sysdeps/linux/powerpc64/signals.S new file mode 100644 index 0000000000..02330c8bbf --- /dev/null +++ b/sysdeps/linux/powerpc64/signals.S @@ -0,0 +1,23 @@ +.abiversion 1 +.section ".opd", "aw" +.align 8 +.global __mlibc_signal_restore +.type __mlibc_signal_restore, @function +__mlibc_signal_restore: + .quad .L.__mlibc_signal_restore + .quad .TOC. + .quad 0 +.global __mlibc_signal_restore_rt +.type __mlibc_signal_restore_rt, @function +__mlibc_signal_restore_rt: + .quad .L.__mlibc_signal_restore_rt + .quad .TOC. + .quad 0 + +.text +.L.__mlibc_signal_restore: +.L.__mlibc_signal_restore_rt: + li 0, 172 // __NR_rt_sigreturn + sc + +.section .note.GNU-stack,"",%progbits \ No newline at end of file diff --git a/sysdeps/linux/powerpc64/syscallnos.h b/sysdeps/linux/powerpc64/syscallnos.h new file mode 100644 index 0000000000..4b24c1bcb9 --- /dev/null +++ b/sysdeps/linux/powerpc64/syscallnos.h @@ -0,0 +1,441 @@ +#ifndef __MLIBC_SYSCALLNOS_h +#define __MLIBC_SYSCALLNOS_h +/* This file is autogenerated. Don't bother. */ +/* Generator script: sysdeps/linux/update-syscall-list.py. */ +#define __NR_restart_syscall 0 +#define __NR_exit 1 +#define __NR_fork 2 +#define __NR_read 3 +#define __NR_write 4 +#define __NR_open 5 +#define __NR_close 6 +#define __NR_waitpid 7 +#define __NR_creat 8 +#define __NR_link 9 +#define __NR_unlink 10 +#define __NR_execve 11 +#define __NR_chdir 12 +#define __NR_time 13 +#define __NR_mknod 14 +#define __NR_chmod 15 +#define __NR_lchown 16 +#define __NR_oldstat 18 +#define __NR_lseek 19 +#define __NR_getpid 20 +#define __NR_mount 21 +#define __NR_umount 22 +#define __NR_setuid 23 +#define __NR_getuid 24 +#define __NR_stime 25 +#define __NR_ptrace 26 +#define __NR_alarm 27 +#define __NR_oldfstat 28 +#define __NR_pause 29 +#define __NR_utime 30 +#define __NR_access 33 +#define __NR_nice 34 +#define __NR_sync 36 +#define __NR_kill 37 +#define __NR_rename 38 +#define __NR_mkdir 39 +#define __NR_rmdir 40 +#define __NR_dup 41 +#define __NR_pipe 42 +#define __NR_times 43 +#define __NR_brk 45 +#define __NR_setgid 46 +#define __NR_getgid 47 +#define __NR_signal 48 +#define __NR_geteuid 49 +#define __NR_getegid 50 +#define __NR_acct 51 +#define __NR_umount2 52 +#define __NR_ioctl 54 +#define __NR_fcntl 55 +#define __NR_setpgid 57 +#define __NR_oldolduname 59 +#define __NR_umask 60 +#define __NR_chroot 61 +#define __NR_ustat 62 +#define __NR_dup2 63 +#define __NR_getppid 64 +#define __NR_getpgrp 65 +#define __NR_setsid 66 +#define __NR_sigaction 67 +#define __NR_sgetmask 68 +#define __NR_ssetmask 69 +#define __NR_setreuid 70 +#define __NR_setregid 71 +#define __NR_sigsuspend 72 +#define __NR_sigpending 73 +#define __NR_sethostname 74 +#define __NR_setrlimit 75 +#define __NR_getrlimit 76 +#define __NR_getrusage 77 +#define __NR_gettimeofday 78 +#define __NR_settimeofday 79 +#define __NR_getgroups 80 +#define __NR_setgroups 81 +#define __NR_select 82 +#define __NR_symlink 83 +#define __NR_oldlstat 84 +#define __NR_readlink 85 +#define __NR_uselib 86 +#define __NR_swapon 87 +#define __NR_reboot 88 +#define __NR_readdir 89 +#define __NR_mmap 90 +#define __NR_munmap 91 +#define __NR_truncate 92 +#define __NR_ftruncate 93 +#define __NR_fchmod 94 +#define __NR_fchown 95 +#define __NR_getpriority 96 +#define __NR_setpriority 97 +#define __NR_statfs 99 +#define __NR_fstatfs 100 +#define __NR_ioperm 101 +#define __NR_socketcall 102 +#define __NR_syslog 103 +#define __NR_setitimer 104 +#define __NR_getitimer 105 +#define __NR_stat 106 +#define __NR_lstat 107 +#define __NR_fstat 108 +#define __NR_olduname 109 +#define __NR_iopl 110 +#define __NR_vhangup 111 +#define __NR_idle 112 +#define __NR_vm86 113 +#define __NR_wait4 114 +#define __NR_swapoff 115 +#define __NR_sysinfo 116 +#define __NR_ipc 117 +#define __NR_fsync 118 +#define __NR_sigreturn 119 +#define __NR_clone 120 +#define __NR_setdomainname 121 +#define __NR_uname 122 +#define __NR_modify_ldt 123 +#define __NR_adjtimex 124 +#define __NR_mprotect 125 +#define __NR_sigprocmask 126 +#define __NR_create_module 127 +#define __NR_init_module 128 +#define __NR_delete_module 129 +#define __NR_get_kernel_syms 130 +#define __NR_quotactl 131 +#define __NR_getpgid 132 +#define __NR_fchdir 133 +#define __NR_bdflush 134 +#define __NR_sysfs 135 +#define __NR_personality 136 +#define __NR_setfsuid 138 +#define __NR_setfsgid 139 +#define __NR__llseek 140 +#define __NR_getdents 141 +#define __NR__newselect 142 +#define __NR_flock 143 +#define __NR_msync 144 +#define __NR_readv 145 +#define __NR_writev 146 +#define __NR_getsid 147 +#define __NR_fdatasync 148 +#define __NR__sysctl 149 +#define __NR_mlock 150 +#define __NR_munlock 151 +#define __NR_mlockall 152 +#define __NR_munlockall 153 +#define __NR_sched_setparam 154 +#define __NR_sched_getparam 155 +#define __NR_sched_setscheduler 156 +#define __NR_sched_getscheduler 157 +#define __NR_sched_yield 158 +#define __NR_sched_get_priority_max 159 +#define __NR_sched_get_priority_min 160 +#define __NR_sched_rr_get_interval 161 +#define __NR_nanosleep 162 +#define __NR_mremap 163 +#define __NR_setresuid 164 +#define __NR_getresuid 165 +#define __NR_query_module 166 +#define __NR_poll 167 +#define __NR_nfsservctl 168 +#define __NR_setresgid 169 +#define __NR_getresgid 170 +#define __NR_prctl 171 +#define __NR_rt_sigreturn 172 +#define __NR_rt_sigaction 173 +#define __NR_rt_sigprocmask 174 +#define __NR_rt_sigpending 175 +#define __NR_rt_sigtimedwait 176 +#define __NR_rt_sigqueueinfo 177 +#define __NR_rt_sigsuspend 178 +#define __NR_pread64 179 +#define __NR_pwrite64 180 +#define __NR_chown 181 +#define __NR_getcwd 182 +#define __NR_capget 183 +#define __NR_capset 184 +#define __NR_sigaltstack 185 +#define __NR_sendfile 186 +#define __NR_getpmsg 187 +#define __NR_vfork 189 +#define __NR_ugetrlimit 190 +#define __NR_readahead 191 +#define __NR_mmap2 192 +#define __NR_truncate64 193 +#define __NR_ftruncate64 194 +#define __NR_stat64 195 +#define __NR_lstat64 196 +#define __NR_fstat64 197 +#define __NR_pciconfig_read 198 +#define __NR_pciconfig_write 199 +#define __NR_pciconfig_iobase 200 +#define __NR_multiplexer 201 +#define __NR_getdents64 202 +#define __NR_pivot_root 203 +#define __NR_fcntl64 204 +#define __NR_madvise 205 +#define __NR_mincore 206 +#define __NR_gettid 207 +#define __NR_tkill 208 +#define __NR_setxattr 209 +#define __NR_lsetxattr 210 +#define __NR_fsetxattr 211 +#define __NR_getxattr 212 +#define __NR_lgetxattr 213 +#define __NR_fgetxattr 214 +#define __NR_listxattr 215 +#define __NR_llistxattr 216 +#define __NR_flistxattr 217 +#define __NR_removexattr 218 +#define __NR_lremovexattr 219 +#define __NR_fremovexattr 220 +#define __NR_futex 221 +#define __NR_sched_setaffinity 222 +#define __NR_sched_getaffinity 223 +#define __NR_sendfile64 226 +#define __NR_io_setup 227 +#define __NR_io_destroy 228 +#define __NR_io_getevents 229 +#define __NR_io_submit 230 +#define __NR_io_cancel 231 +#define __NR_set_tid_address 232 +#define __NR_fadvise64 233 +#define __NR_exit_group 234 +#define __NR_lookup_dcookie 235 +#define __NR_epoll_create 236 +#define __NR_epoll_ctl 237 +#define __NR_epoll_wait 238 +#define __NR_remap_file_pages 239 +#define __NR_timer_create 240 +#define __NR_timer_settime 241 +#define __NR_timer_gettime 242 +#define __NR_timer_getoverrun 243 +#define __NR_timer_delete 244 +#define __NR_clock_settime 245 +#define __NR_clock_gettime 246 +#define __NR_clock_getres 247 +#define __NR_clock_nanosleep 248 +#define __NR_swapcontext 249 +#define __NR_tgkill 250 +#define __NR_utimes 251 +#define __NR_statfs64 252 +#define __NR_fstatfs64 253 +#define __NR_fadvise64_64 254 +#define __NR_rtas 255 +#define __NR_sys_debug_setcontext 256 +#define __NR_migrate_pages 258 +#define __NR_mbind 259 +#define __NR_get_mempolicy 260 +#define __NR_set_mempolicy 261 +#define __NR_mq_open 262 +#define __NR_mq_unlink 263 +#define __NR_mq_timedsend 264 +#define __NR_mq_timedreceive 265 +#define __NR_mq_notify 266 +#define __NR_mq_getsetattr 267 +#define __NR_kexec_load 268 +#define __NR_add_key 269 +#define __NR_request_key 270 +#define __NR_keyctl 271 +#define __NR_waitid 272 +#define __NR_ioprio_set 273 +#define __NR_ioprio_get 274 +#define __NR_inotify_init 275 +#define __NR_inotify_add_watch 276 +#define __NR_inotify_rm_watch 277 +#define __NR_spu_run 278 +#define __NR_spu_create 279 +#define __NR_pselect6 280 +#define __NR_ppoll 281 +#define __NR_unshare 282 +#define __NR_splice 283 +#define __NR_tee 284 +#define __NR_vmsplice 285 +#define __NR_openat 286 +#define __NR_mkdirat 287 +#define __NR_mknodat 288 +#define __NR_fchownat 289 +#define __NR_futimesat 290 +#define __NR_fstatat64 291 +#define __NR_unlinkat 292 +#define __NR_renameat 293 +#define __NR_linkat 294 +#define __NR_symlinkat 295 +#define __NR_readlinkat 296 +#define __NR_fchmodat 297 +#define __NR_faccessat 298 +#define __NR_get_robust_list 299 +#define __NR_set_robust_list 300 +#define __NR_move_pages 301 +#define __NR_getcpu 302 +#define __NR_epoll_pwait 303 +#define __NR_utimensat 304 +#define __NR_signalfd 305 +#define __NR_timerfd_create 306 +#define __NR_eventfd 307 +#define __NR_sync_file_range2 308 +#define __NR_fallocate 309 +#define __NR_subpage_prot 310 +#define __NR_timerfd_settime 311 +#define __NR_timerfd_gettime 312 +#define __NR_signalfd4 313 +#define __NR_eventfd2 314 +#define __NR_epoll_create1 315 +#define __NR_dup3 316 +#define __NR_pipe2 317 +#define __NR_inotify_init1 318 +#define __NR_perf_event_open 319 +#define __NR_preadv 320 +#define __NR_pwritev 321 +#define __NR_rt_tgsigqueueinfo 322 +#define __NR_fanotify_init 323 +#define __NR_fanotify_mark 324 +#define __NR_prlimit64 325 +#define __NR_socket 326 +#define __NR_bind 327 +#define __NR_connect 328 +#define __NR_listen 329 +#define __NR_accept 330 +#define __NR_getsockname 331 +#define __NR_getpeername 332 +#define __NR_socketpair 333 +#define __NR_send 334 +#define __NR_sendto 335 +#define __NR_recv 336 +#define __NR_recvfrom 337 +#define __NR_shutdown 338 +#define __NR_setsockopt 339 +#define __NR_getsockopt 340 +#define __NR_sendmsg 341 +#define __NR_recvmsg 342 +#define __NR_recvmmsg 343 +#define __NR_accept4 344 +#define __NR_name_to_handle_at 345 +#define __NR_open_by_handle_at 346 +#define __NR_clock_adjtime 347 +#define __NR_syncfs 348 +#define __NR_sendmmsg 349 +#define __NR_setns 350 +#define __NR_process_vm_readv 351 +#define __NR_process_vm_writev 352 +#define __NR_finit_module 353 +#define __NR_kcmp 354 +#define __NR_sched_setattr 355 +#define __NR_sched_getattr 356 +#define __NR_renameat2 357 +#define __NR_seccomp 358 +#define __NR_getrandom 359 +#define __NR_memfd_create 360 +#define __NR_bpf 361 +#define __NR_execveat 362 +#define __NR_switch_endian 363 +#define __NR_userfaultfd 364 +#define __NR_membarrier 365 +#define __NR_mlock2 378 +#define __NR_copy_file_range 379 +#define __NR_preadv2 380 +#define __NR_pwritev2 381 +#define __NR_kexec_file_load 382 +#define __NR_statx 383 +#define __NR_pkey_alloc 384 +#define __NR_pkey_free 385 +#define __NR_pkey_mprotect 386 +#define __NR_rseq 387 +#define __NR_io_pgetevents 388 +#define __NR_semget 393 +#define __NR_semctl 394 +#define __NR_shmget 395 +#define __NR_shmctl 396 +#define __NR_shmat 397 +#define __NR_shmdt 398 +#define __NR_msgget 399 +#define __NR_msgsnd 400 +#define __NR_msgrcv 401 +#define __NR_msgctl 402 +#define __NR_clock_gettime64 403 +#define __NR_clock_settime64 404 +#define __NR_clock_adjtime64 405 +#define __NR_clock_getres_time64 406 +#define __NR_clock_nanosleep_time64 407 +#define __NR_timer_gettime64 408 +#define __NR_timer_settime64 409 +#define __NR_timerfd_gettime64 410 +#define __NR_timerfd_settime64 411 +#define __NR_utimensat_time64 412 +#define __NR_pselect6_time64 413 +#define __NR_ppoll_time64 414 +#define __NR_io_pgetevents_time64 416 +#define __NR_recvmmsg_time64 417 +#define __NR_mq_timedsend_time64 418 +#define __NR_mq_timedreceive_time64 419 +#define __NR_semtimedop_time64 420 +#define __NR_rt_sigtimedwait_time64 421 +#define __NR_futex_time64 422 +#define __NR_sched_rr_get_interval_time64 423 +#define __NR_pidfd_send_signal 424 +#define __NR_io_uring_setup 425 +#define __NR_io_uring_enter 426 +#define __NR_io_uring_register 427 +#define __NR_open_tree 428 +#define __NR_move_mount 429 +#define __NR_fsopen 430 +#define __NR_fsconfig 431 +#define __NR_fsmount 432 +#define __NR_fspick 433 +#define __NR_pidfd_open 434 +#define __NR_clone3 435 +#define __NR_close_range 436 +#define __NR_openat2 437 +#define __NR_pidfd_getfd 438 +#define __NR_faccessat2 439 +#define __NR_process_madvise 440 +#define __NR_epoll_pwait2 441 +#define __NR_mount_setattr 442 +#define __NR_quotactl_fd 443 +#define __NR_landlock_create_ruleset 444 +#define __NR_landlock_add_rule 445 +#define __NR_landlock_restrict_self 446 +#define __NR_process_mrelease 448 +#define __NR_futex_waitv 449 +#define __NR_set_mempolicy_home_node 450 +#define __NR_cachestat 451 +#define __NR_fchmodat2 452 +#define __NR_map_shadow_stack 453 +#define __NR_futex_wake 454 +#define __NR_futex_wait 455 +#define __NR_futex_requeue 456 +#define __NR_statmount 457 +#define __NR_listmount 458 +#define __NR_lsm_get_self_attr 459 +#define __NR_lsm_set_self_attr 460 +#define __NR_lsm_list_modules 461 +#define __NR_mseal 462 +#define __NR_setxattrat 463 +#define __NR_getxattrat 464 +#define __NR_listxattrat 465 +#define __NR_removexattrat 466 +#define __NR_open_tree_attr 467 +#endif /* __MLIBC_SYSCALLNOS_h */ diff --git a/sysdeps/linux/powerpc64/thread_entry.S b/sysdeps/linux/powerpc64/thread_entry.S new file mode 100644 index 0000000000..15e2f19e19 --- /dev/null +++ b/sysdeps/linux/powerpc64/thread_entry.S @@ -0,0 +1,52 @@ +.abiversion 1 +.section ".opd","aw" +.align 8 +.global __mlibc_spawn_thread +.type __mlibc_spawn_thread, "function" +__mlibc_spawn_thread: + .quad .L.__mlibc_spawn_thread + .quad .TOC. + .quad 0 + +.text +.L.__mlibc_spawn_thread: + // __mlibc_spawn_thread(flags, stack, pid_out, child_tid, tls) + // x3, x4, x5, x6, x7 + // syscall(NR_clone, flags, stack, ptid, tls, ctid) + // x0, x3, x4, x5, x6, x7 + + // Swap x6<->x7 + mr 8, 7 + mr 7, 6 + mr 6, 8 + + li 0, 120 // NR_clone + sc + nop + + cmpwi 3, 0 + bne .parent + + // load user_arg/entry from the stack + // sysdeps/linux/generic/thread.cpp:sys_prepare_stack:55 + ld 3, 0(1) + ld 4, 8(1) + mr 8, 1 + addi 1, 1, 16 + + // allocate a new stack frame for toc saving stubs + stdu 1, -112(1) + std 2, 40(1) + + bl __mlibc_enter_thread + nop + + addi 1, 1, 112 + + trap + +.parent: + blr + +.section .note.GNU-stack,"",%progbits + diff --git a/sysdeps/linux/riscv64/syscallnos.h b/sysdeps/linux/riscv64/syscallnos.h index 49f5db442b..0fe528d9be 100644 --- a/sysdeps/linux/riscv64/syscallnos.h +++ b/sysdeps/linux/riscv64/syscallnos.h @@ -325,4 +325,5 @@ #define __NR_getxattrat 464 #define __NR_listxattrat 465 #define __NR_removexattrat 466 +#define __NR_open_tree_attr 467 #endif /* __MLIBC_SYSCALLNOS_h */ diff --git a/sysdeps/linux/x86/syscallnos.h b/sysdeps/linux/x86/syscallnos.h index e4376c458f..d36795fc82 100644 --- a/sysdeps/linux/x86/syscallnos.h +++ b/sysdeps/linux/x86/syscallnos.h @@ -446,4 +446,5 @@ #define __NR_getxattrat 464 #define __NR_listxattrat 465 #define __NR_removexattrat 466 +#define __NR_open_tree_attr 467 #endif /* __MLIBC_SYSCALLNOS_h */ diff --git a/sysdeps/linux/x86_64/syscallnos.h b/sysdeps/linux/x86_64/syscallnos.h index 641aa67e84..80df81f719 100644 --- a/sysdeps/linux/x86_64/syscallnos.h +++ b/sysdeps/linux/x86_64/syscallnos.h @@ -376,4 +376,5 @@ #define __NR_getxattrat 464 #define __NR_listxattrat 465 #define __NR_removexattrat 466 +#define __NR_open_tree_attr 467 #endif /* __MLIBC_SYSCALLNOS_h */ diff --git a/tests/posix/pthread_attr.c b/tests/posix/pthread_attr.c index b8e1198861..08348e414b 100644 --- a/tests/posix/pthread_attr.c +++ b/tests/posix/pthread_attr.c @@ -109,6 +109,8 @@ static void *stackaddr_worker(void *arg) { asm volatile("move.l %%sp, %0" : "=r"(sp)); #elif defined(__loongarch64) asm volatile("move %0, $sp" : "=r"(sp)); +#elif defined(__powerpc64__) + asm volatile("mflr %0" : "=r"(sp)); #else #error Unknown architecture #endif diff --git a/tests/posix/sigaltstack.c b/tests/posix/sigaltstack.c index 623dfffd2b..91661c4f3d 100644 --- a/tests/posix/sigaltstack.c +++ b/tests/posix/sigaltstack.c @@ -61,6 +61,10 @@ int main() { asm volatile("addi.d $sp, $r0, 0\n" "\t" "st.d $r0, $sp, 0"); +#elif defined(__powerpc64__) + asm volatile("li 1, 0\n" + "\t" + "std 3, 0(1)"); #else #error Unknown architecture #endif From b274ce5e525cfcb366912aca6ff3b78e9d5089a6 Mon Sep 17 00:00:00 2001 From: localcc Date: Tue, 24 Jun 2025 20:23:58 +0200 Subject: [PATCH 3/3] fix: implement pltRelocateSelf and crt1.s This also removes .init/.fini constructors as they're not needed --- options/rtld/powerpc64/entry.S | 6 ++++++ options/rtld/powerpc64/runtime.S | 28 ++++++++++++++++++++++---- sysdeps/linux/powerpc64/crt-src/crt1.S | 10 ++++++--- sysdeps/linux/powerpc64/crt-src/crti.S | 11 ---------- sysdeps/linux/powerpc64/crt-src/crtn.S | 7 ------- 5 files changed, 37 insertions(+), 25 deletions(-) diff --git a/options/rtld/powerpc64/entry.S b/options/rtld/powerpc64/entry.S index dfe4fad62f..c4684c4223 100644 --- a/options/rtld/powerpc64/entry.S +++ b/options/rtld/powerpc64/entry.S @@ -41,9 +41,15 @@ pc: bl interpreterMain nop + stdu 1, -112(1) + std 2, 40(1) + ld 2, 8(3) // loading toc and jumping to Scrt1.S entry ld 3, 0(3) mtctr 3 bctr + addi 1, 1, 112 + trap + .section .note.GNU-stack,"",%progbits \ No newline at end of file diff --git a/options/rtld/powerpc64/runtime.S b/options/rtld/powerpc64/runtime.S index 448ad65024..26310731bf 100644 --- a/options/rtld/powerpc64/runtime.S +++ b/options/rtld/powerpc64/runtime.S @@ -1,9 +1,29 @@ .abiversion 1 .global pltRelocateStub pltRelocateStub: - # we need to save / restore all registers than can hold function arguments - # we do not need to save callee-saved registers as they will not be trashed by lazyRelocate - # TODO: save floating point argument registers + // we need to save / restore all registers than can hold function arguments + // we do not need to save callee-saved registers as they will not be trashed by lazyRelocate + // TODO: save floating point argument registers // todo(localcc): implement - trap + + stdu 1, -112(1) + std 2, 40(1) + + std 3, 48(1) + std 4, 56(1) + + ld 3, 112(1) + ld 4, 120(1) + + bl lazyRelocate + nop + mtctr 3 + + ld 3, 48(1) + ld 4, 56(1) + + addi 1, 1, 112 + + bctr + .section .note.GNU-stack,"",%progbits \ No newline at end of file diff --git a/sysdeps/linux/powerpc64/crt-src/crt1.S b/sysdeps/linux/powerpc64/crt-src/crt1.S index 1bd38e052f..a3457272d4 100644 --- a/sysdeps/linux/powerpc64/crt-src/crt1.S +++ b/sysdeps/linux/powerpc64/crt-src/crt1.S @@ -8,9 +8,13 @@ _start: .text _realstart: - // todo(localcc): implement - trap + mr 3, 1 + + addis 4, 2, main@toc@ha + addi 4, 4, main@toc@l + + bl __mlibc_entry nop - trap + .section .note.GNU-stack,"",%progbits diff --git a/sysdeps/linux/powerpc64/crt-src/crti.S b/sysdeps/linux/powerpc64/crt-src/crti.S index 78424379b1..5b663018e5 100644 --- a/sysdeps/linux/powerpc64/crt-src/crti.S +++ b/sysdeps/linux/powerpc64/crt-src/crti.S @@ -1,13 +1,2 @@ -.section .init -.global _init -_init: - // todo(localcc): implement - trap - -.section .fini -.global _fini -_fini: - // todo(localcc): implement - trap .section .note.GNU-stack,"",%progbits diff --git a/sysdeps/linux/powerpc64/crt-src/crtn.S b/sysdeps/linux/powerpc64/crt-src/crtn.S index d415f1e10b..5b663018e5 100644 --- a/sysdeps/linux/powerpc64/crt-src/crtn.S +++ b/sysdeps/linux/powerpc64/crt-src/crtn.S @@ -1,9 +1,2 @@ -.section .init - // todo(localcc): implement - trap - -.section .fini - // todo(localcc): implement - trap .section .note.GNU-stack,"",%progbits