1bd8c8fbbSWilly Tarreau /* SPDX-License-Identifier: LGPL-2.1 OR MIT */ 2bd8c8fbbSWilly Tarreau /* 3bd8c8fbbSWilly Tarreau * Syscall definitions for NOLIBC (those in man(2)) 4bd8c8fbbSWilly Tarreau * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu> 5bd8c8fbbSWilly Tarreau */ 6bd8c8fbbSWilly Tarreau 7bd8c8fbbSWilly Tarreau #ifndef _NOLIBC_SYS_H 8bd8c8fbbSWilly Tarreau #define _NOLIBC_SYS_H 9bd8c8fbbSWilly Tarreau 10a7604ba1SWilly Tarreau #include <stdarg.h> 11bd8c8fbbSWilly Tarreau #include "std.h" 12bd8c8fbbSWilly Tarreau 13bd8c8fbbSWilly Tarreau /* system includes */ 14bd8c8fbbSWilly Tarreau #include <asm/unistd.h> 15fddc8f81SThomas Weißschuh #include <asm/signal.h> /* for SIGCHLD */ 16bd8c8fbbSWilly Tarreau #include <asm/ioctls.h> 17544fa1a2SAmmar Faizi #include <asm/mman.h> 18bd8c8fbbSWilly Tarreau #include <linux/fs.h> 19bd8c8fbbSWilly Tarreau #include <linux/loop.h> 20bd8c8fbbSWilly Tarreau #include <linux/time.h> 217efd762eSAmmar Faizi #include <linux/auxvec.h> 22fddc8f81SThomas Weißschuh #include <linux/fcntl.h> /* for O_* and AT_* */ 23fddc8f81SThomas Weißschuh #include <linux/stat.h> /* for statx() */ 2472ffbc67SThomas Weißschuh #include <linux/reboot.h> /* for LINUX_REBOOT_* */ 25208aa9d9SThomas Weißschuh #include <linux/prctl.h> 26bd8c8fbbSWilly Tarreau 27bd8c8fbbSWilly Tarreau #include "arch.h" 2845a794bfSWilly Tarreau #include "errno.h" 29bd8c8fbbSWilly Tarreau #include "types.h" 30bd8c8fbbSWilly Tarreau 316591be4aSZhangjin Wu 326591be4aSZhangjin Wu /* Syscall return helper for library routines, set errno as -ret when ret is in 336591be4aSZhangjin Wu * range of [-MAX_ERRNO, -1] 346591be4aSZhangjin Wu * 356591be4aSZhangjin Wu * Note, No official reference states the errno range here aligns with musl 366591be4aSZhangjin Wu * (src/internal/syscall_ret.c) and glibc (sysdeps/unix/sysv/linux/sysdep.h) 376591be4aSZhangjin Wu */ 386591be4aSZhangjin Wu 39428905daSZhangjin Wu static __inline__ __attribute__((unused, always_inline)) 406591be4aSZhangjin Wu long __sysret(unsigned long ret) 41428905daSZhangjin Wu { 426591be4aSZhangjin Wu if (ret >= (unsigned long)-MAX_ERRNO) { 436591be4aSZhangjin Wu SET_ERRNO(-(long)ret); 446591be4aSZhangjin Wu return -1; 45428905daSZhangjin Wu } 46428905daSZhangjin Wu return ret; 47428905daSZhangjin Wu } 48bd8c8fbbSWilly Tarreau 49bd8c8fbbSWilly Tarreau /* Functions in this file only describe syscalls. They're declared static so 50bd8c8fbbSWilly Tarreau * that the compiler usually decides to inline them while still being allowed 51bd8c8fbbSWilly Tarreau * to pass a pointer to one of their instances. Each syscall exists in two 52bd8c8fbbSWilly Tarreau * versions: 53bd8c8fbbSWilly Tarreau * - the "internal" ones, which matches the raw syscall interface at the 54bd8c8fbbSWilly Tarreau * kernel level, which may sometimes slightly differ from the documented 55bd8c8fbbSWilly Tarreau * libc-level ones. For example most of them return either a valid value 56bd8c8fbbSWilly Tarreau * or -errno. All of these are prefixed with "sys_". They may be called 57bd8c8fbbSWilly Tarreau * by non-portable applications if desired. 58bd8c8fbbSWilly Tarreau * 59bd8c8fbbSWilly Tarreau * - the "exported" ones, whose interface must closely match the one 60bd8c8fbbSWilly Tarreau * documented in man(2), that applications are supposed to expect. These 61bd8c8fbbSWilly Tarreau * ones rely on the internal ones, and set errno. 62bd8c8fbbSWilly Tarreau * 63bd8c8fbbSWilly Tarreau * Each syscall will be defined with the two functions, sorted in alphabetical 64bd8c8fbbSWilly Tarreau * order applied to the exported names. 65bd8c8fbbSWilly Tarreau * 66bd8c8fbbSWilly Tarreau * In case of doubt about the relevance of a function here, only those which 67bd8c8fbbSWilly Tarreau * set errno should be defined here. Wrappers like those appearing in man(3) 68bd8c8fbbSWilly Tarreau * should not be placed here. 69bd8c8fbbSWilly Tarreau */ 70bd8c8fbbSWilly Tarreau 71bd8c8fbbSWilly Tarreau 72bd8c8fbbSWilly Tarreau /* 73bd8c8fbbSWilly Tarreau * int brk(void *addr); 74bd8c8fbbSWilly Tarreau * void *sbrk(intptr_t inc) 75bd8c8fbbSWilly Tarreau */ 76bd8c8fbbSWilly Tarreau 77bd8c8fbbSWilly Tarreau static __attribute__((unused)) 78bd8c8fbbSWilly Tarreau void *sys_brk(void *addr) 79bd8c8fbbSWilly Tarreau { 80bd8c8fbbSWilly Tarreau return (void *)my_syscall1(__NR_brk, addr); 81bd8c8fbbSWilly Tarreau } 82bd8c8fbbSWilly Tarreau 83bd8c8fbbSWilly Tarreau static __attribute__((unused)) 84bd8c8fbbSWilly Tarreau int brk(void *addr) 85bd8c8fbbSWilly Tarreau { 86d27447bcSZhangjin Wu return __sysret(sys_brk(addr) ? 0 : -ENOMEM); 87bd8c8fbbSWilly Tarreau } 88bd8c8fbbSWilly Tarreau 89bd8c8fbbSWilly Tarreau static __attribute__((unused)) 90bd8c8fbbSWilly Tarreau void *sbrk(intptr_t inc) 91bd8c8fbbSWilly Tarreau { 92bd8c8fbbSWilly Tarreau /* first call to find current end */ 93*4201cfceSZhangjin Wu void *ret = sys_brk(0); 94*4201cfceSZhangjin Wu 95*4201cfceSZhangjin Wu if (ret && sys_brk(ret + inc) == ret + inc) 96bd8c8fbbSWilly Tarreau return ret + inc; 97bd8c8fbbSWilly Tarreau 98*4201cfceSZhangjin Wu return (void *)__sysret(-ENOMEM); 99bd8c8fbbSWilly Tarreau } 100bd8c8fbbSWilly Tarreau 101bd8c8fbbSWilly Tarreau 102bd8c8fbbSWilly Tarreau /* 103bd8c8fbbSWilly Tarreau * int chdir(const char *path); 104bd8c8fbbSWilly Tarreau */ 105bd8c8fbbSWilly Tarreau 106bd8c8fbbSWilly Tarreau static __attribute__((unused)) 107bd8c8fbbSWilly Tarreau int sys_chdir(const char *path) 108bd8c8fbbSWilly Tarreau { 109bd8c8fbbSWilly Tarreau return my_syscall1(__NR_chdir, path); 110bd8c8fbbSWilly Tarreau } 111bd8c8fbbSWilly Tarreau 112bd8c8fbbSWilly Tarreau static __attribute__((unused)) 113bd8c8fbbSWilly Tarreau int chdir(const char *path) 114bd8c8fbbSWilly Tarreau { 115d27447bcSZhangjin Wu return __sysret(sys_chdir(path)); 116bd8c8fbbSWilly Tarreau } 117bd8c8fbbSWilly Tarreau 118bd8c8fbbSWilly Tarreau 119bd8c8fbbSWilly Tarreau /* 120bd8c8fbbSWilly Tarreau * int chmod(const char *path, mode_t mode); 121bd8c8fbbSWilly Tarreau */ 122bd8c8fbbSWilly Tarreau 123bd8c8fbbSWilly Tarreau static __attribute__((unused)) 124bd8c8fbbSWilly Tarreau int sys_chmod(const char *path, mode_t mode) 125bd8c8fbbSWilly Tarreau { 126bd8c8fbbSWilly Tarreau #ifdef __NR_fchmodat 127bd8c8fbbSWilly Tarreau return my_syscall4(__NR_fchmodat, AT_FDCWD, path, mode, 0); 128bd8c8fbbSWilly Tarreau #elif defined(__NR_chmod) 129bd8c8fbbSWilly Tarreau return my_syscall2(__NR_chmod, path, mode); 130bd8c8fbbSWilly Tarreau #else 131ca50df30SZhangjin Wu return -ENOSYS; 132bd8c8fbbSWilly Tarreau #endif 133bd8c8fbbSWilly Tarreau } 134bd8c8fbbSWilly Tarreau 135bd8c8fbbSWilly Tarreau static __attribute__((unused)) 136bd8c8fbbSWilly Tarreau int chmod(const char *path, mode_t mode) 137bd8c8fbbSWilly Tarreau { 138d27447bcSZhangjin Wu return __sysret(sys_chmod(path, mode)); 139bd8c8fbbSWilly Tarreau } 140bd8c8fbbSWilly Tarreau 141bd8c8fbbSWilly Tarreau 142bd8c8fbbSWilly Tarreau /* 143bd8c8fbbSWilly Tarreau * int chown(const char *path, uid_t owner, gid_t group); 144bd8c8fbbSWilly Tarreau */ 145bd8c8fbbSWilly Tarreau 146bd8c8fbbSWilly Tarreau static __attribute__((unused)) 147bd8c8fbbSWilly Tarreau int sys_chown(const char *path, uid_t owner, gid_t group) 148bd8c8fbbSWilly Tarreau { 149bd8c8fbbSWilly Tarreau #ifdef __NR_fchownat 150bd8c8fbbSWilly Tarreau return my_syscall5(__NR_fchownat, AT_FDCWD, path, owner, group, 0); 151bd8c8fbbSWilly Tarreau #elif defined(__NR_chown) 152bd8c8fbbSWilly Tarreau return my_syscall3(__NR_chown, path, owner, group); 153bd8c8fbbSWilly Tarreau #else 154ca50df30SZhangjin Wu return -ENOSYS; 155bd8c8fbbSWilly Tarreau #endif 156bd8c8fbbSWilly Tarreau } 157bd8c8fbbSWilly Tarreau 158bd8c8fbbSWilly Tarreau static __attribute__((unused)) 159bd8c8fbbSWilly Tarreau int chown(const char *path, uid_t owner, gid_t group) 160bd8c8fbbSWilly Tarreau { 161d27447bcSZhangjin Wu return __sysret(sys_chown(path, owner, group)); 162bd8c8fbbSWilly Tarreau } 163bd8c8fbbSWilly Tarreau 164bd8c8fbbSWilly Tarreau 165bd8c8fbbSWilly Tarreau /* 166bd8c8fbbSWilly Tarreau * int chroot(const char *path); 167bd8c8fbbSWilly Tarreau */ 168bd8c8fbbSWilly Tarreau 169bd8c8fbbSWilly Tarreau static __attribute__((unused)) 170bd8c8fbbSWilly Tarreau int sys_chroot(const char *path) 171bd8c8fbbSWilly Tarreau { 172bd8c8fbbSWilly Tarreau return my_syscall1(__NR_chroot, path); 173bd8c8fbbSWilly Tarreau } 174bd8c8fbbSWilly Tarreau 175bd8c8fbbSWilly Tarreau static __attribute__((unused)) 176bd8c8fbbSWilly Tarreau int chroot(const char *path) 177bd8c8fbbSWilly Tarreau { 178d27447bcSZhangjin Wu return __sysret(sys_chroot(path)); 179bd8c8fbbSWilly Tarreau } 180bd8c8fbbSWilly Tarreau 181bd8c8fbbSWilly Tarreau 182bd8c8fbbSWilly Tarreau /* 183bd8c8fbbSWilly Tarreau * int close(int fd); 184bd8c8fbbSWilly Tarreau */ 185bd8c8fbbSWilly Tarreau 186bd8c8fbbSWilly Tarreau static __attribute__((unused)) 187bd8c8fbbSWilly Tarreau int sys_close(int fd) 188bd8c8fbbSWilly Tarreau { 189bd8c8fbbSWilly Tarreau return my_syscall1(__NR_close, fd); 190bd8c8fbbSWilly Tarreau } 191bd8c8fbbSWilly Tarreau 192bd8c8fbbSWilly Tarreau static __attribute__((unused)) 193bd8c8fbbSWilly Tarreau int close(int fd) 194bd8c8fbbSWilly Tarreau { 195d27447bcSZhangjin Wu return __sysret(sys_close(fd)); 196bd8c8fbbSWilly Tarreau } 197bd8c8fbbSWilly Tarreau 198bd8c8fbbSWilly Tarreau 199bd8c8fbbSWilly Tarreau /* 200bd8c8fbbSWilly Tarreau * int dup(int fd); 201bd8c8fbbSWilly Tarreau */ 202bd8c8fbbSWilly Tarreau 203bd8c8fbbSWilly Tarreau static __attribute__((unused)) 204bd8c8fbbSWilly Tarreau int sys_dup(int fd) 205bd8c8fbbSWilly Tarreau { 206bd8c8fbbSWilly Tarreau return my_syscall1(__NR_dup, fd); 207bd8c8fbbSWilly Tarreau } 208bd8c8fbbSWilly Tarreau 209bd8c8fbbSWilly Tarreau static __attribute__((unused)) 210bd8c8fbbSWilly Tarreau int dup(int fd) 211bd8c8fbbSWilly Tarreau { 212d27447bcSZhangjin Wu return __sysret(sys_dup(fd)); 213bd8c8fbbSWilly Tarreau } 214bd8c8fbbSWilly Tarreau 215bd8c8fbbSWilly Tarreau 216bd8c8fbbSWilly Tarreau /* 217bd8c8fbbSWilly Tarreau * int dup2(int old, int new); 218bd8c8fbbSWilly Tarreau */ 219bd8c8fbbSWilly Tarreau 220bd8c8fbbSWilly Tarreau static __attribute__((unused)) 221bd8c8fbbSWilly Tarreau int sys_dup2(int old, int new) 222bd8c8fbbSWilly Tarreau { 223bd8c8fbbSWilly Tarreau #ifdef __NR_dup3 224bd8c8fbbSWilly Tarreau return my_syscall3(__NR_dup3, old, new, 0); 225bd8c8fbbSWilly Tarreau #elif defined(__NR_dup2) 226bd8c8fbbSWilly Tarreau return my_syscall2(__NR_dup2, old, new); 227bd8c8fbbSWilly Tarreau #else 228ca50df30SZhangjin Wu return -ENOSYS; 229bd8c8fbbSWilly Tarreau #endif 230bd8c8fbbSWilly Tarreau } 231bd8c8fbbSWilly Tarreau 232bd8c8fbbSWilly Tarreau static __attribute__((unused)) 233bd8c8fbbSWilly Tarreau int dup2(int old, int new) 234bd8c8fbbSWilly Tarreau { 235d27447bcSZhangjin Wu return __sysret(sys_dup2(old, new)); 236bd8c8fbbSWilly Tarreau } 237bd8c8fbbSWilly Tarreau 238bd8c8fbbSWilly Tarreau 239bd8c8fbbSWilly Tarreau /* 240bd8c8fbbSWilly Tarreau * int dup3(int old, int new, int flags); 241bd8c8fbbSWilly Tarreau */ 242bd8c8fbbSWilly Tarreau 243bd8c8fbbSWilly Tarreau #ifdef __NR_dup3 244bd8c8fbbSWilly Tarreau static __attribute__((unused)) 245bd8c8fbbSWilly Tarreau int sys_dup3(int old, int new, int flags) 246bd8c8fbbSWilly Tarreau { 247bd8c8fbbSWilly Tarreau return my_syscall3(__NR_dup3, old, new, flags); 248bd8c8fbbSWilly Tarreau } 249bd8c8fbbSWilly Tarreau 250bd8c8fbbSWilly Tarreau static __attribute__((unused)) 251bd8c8fbbSWilly Tarreau int dup3(int old, int new, int flags) 252bd8c8fbbSWilly Tarreau { 253d27447bcSZhangjin Wu return __sysret(sys_dup3(old, new, flags)); 254bd8c8fbbSWilly Tarreau } 255bd8c8fbbSWilly Tarreau #endif 256bd8c8fbbSWilly Tarreau 257bd8c8fbbSWilly Tarreau 258bd8c8fbbSWilly Tarreau /* 259bd8c8fbbSWilly Tarreau * int execve(const char *filename, char *const argv[], char *const envp[]); 260bd8c8fbbSWilly Tarreau */ 261bd8c8fbbSWilly Tarreau 262bd8c8fbbSWilly Tarreau static __attribute__((unused)) 263bd8c8fbbSWilly Tarreau int sys_execve(const char *filename, char *const argv[], char *const envp[]) 264bd8c8fbbSWilly Tarreau { 265bd8c8fbbSWilly Tarreau return my_syscall3(__NR_execve, filename, argv, envp); 266bd8c8fbbSWilly Tarreau } 267bd8c8fbbSWilly Tarreau 268bd8c8fbbSWilly Tarreau static __attribute__((unused)) 269bd8c8fbbSWilly Tarreau int execve(const char *filename, char *const argv[], char *const envp[]) 270bd8c8fbbSWilly Tarreau { 271d27447bcSZhangjin Wu return __sysret(sys_execve(filename, argv, envp)); 272bd8c8fbbSWilly Tarreau } 273bd8c8fbbSWilly Tarreau 274bd8c8fbbSWilly Tarreau 275bd8c8fbbSWilly Tarreau /* 276bd8c8fbbSWilly Tarreau * void exit(int status); 277bd8c8fbbSWilly Tarreau */ 278bd8c8fbbSWilly Tarreau 279bd8c8fbbSWilly Tarreau static __attribute__((noreturn,unused)) 280bd8c8fbbSWilly Tarreau void sys_exit(int status) 281bd8c8fbbSWilly Tarreau { 282bd8c8fbbSWilly Tarreau my_syscall1(__NR_exit, status & 255); 283fddc8f81SThomas Weißschuh while(1); /* shut the "noreturn" warnings. */ 284bd8c8fbbSWilly Tarreau } 285bd8c8fbbSWilly Tarreau 286bd8c8fbbSWilly Tarreau static __attribute__((noreturn,unused)) 287bd8c8fbbSWilly Tarreau void exit(int status) 288bd8c8fbbSWilly Tarreau { 289bd8c8fbbSWilly Tarreau sys_exit(status); 290bd8c8fbbSWilly Tarreau } 291bd8c8fbbSWilly Tarreau 292bd8c8fbbSWilly Tarreau 293bd8c8fbbSWilly Tarreau /* 294bd8c8fbbSWilly Tarreau * pid_t fork(void); 295bd8c8fbbSWilly Tarreau */ 296bd8c8fbbSWilly Tarreau 297404fa87cSThomas Weißschuh #ifndef sys_fork 298bd8c8fbbSWilly Tarreau static __attribute__((unused)) 299bd8c8fbbSWilly Tarreau pid_t sys_fork(void) 300bd8c8fbbSWilly Tarreau { 301bd8c8fbbSWilly Tarreau #ifdef __NR_clone 302bd8c8fbbSWilly Tarreau /* note: some archs only have clone() and not fork(). Different archs 303bd8c8fbbSWilly Tarreau * have a different API, but most archs have the flags on first arg and 304bd8c8fbbSWilly Tarreau * will not use the rest with no other flag. 305bd8c8fbbSWilly Tarreau */ 306bd8c8fbbSWilly Tarreau return my_syscall5(__NR_clone, SIGCHLD, 0, 0, 0, 0); 307bd8c8fbbSWilly Tarreau #elif defined(__NR_fork) 308bd8c8fbbSWilly Tarreau return my_syscall0(__NR_fork); 309bd8c8fbbSWilly Tarreau #else 310ca50df30SZhangjin Wu return -ENOSYS; 311bd8c8fbbSWilly Tarreau #endif 312bd8c8fbbSWilly Tarreau } 313404fa87cSThomas Weißschuh #endif 314bd8c8fbbSWilly Tarreau 315bd8c8fbbSWilly Tarreau static __attribute__((unused)) 316bd8c8fbbSWilly Tarreau pid_t fork(void) 317bd8c8fbbSWilly Tarreau { 318d27447bcSZhangjin Wu return __sysret(sys_fork()); 319bd8c8fbbSWilly Tarreau } 320bd8c8fbbSWilly Tarreau 321bd8c8fbbSWilly Tarreau 322bd8c8fbbSWilly Tarreau /* 323bd8c8fbbSWilly Tarreau * int fsync(int fd); 324bd8c8fbbSWilly Tarreau */ 325bd8c8fbbSWilly Tarreau 326bd8c8fbbSWilly Tarreau static __attribute__((unused)) 327bd8c8fbbSWilly Tarreau int sys_fsync(int fd) 328bd8c8fbbSWilly Tarreau { 329bd8c8fbbSWilly Tarreau return my_syscall1(__NR_fsync, fd); 330bd8c8fbbSWilly Tarreau } 331bd8c8fbbSWilly Tarreau 332bd8c8fbbSWilly Tarreau static __attribute__((unused)) 333bd8c8fbbSWilly Tarreau int fsync(int fd) 334bd8c8fbbSWilly Tarreau { 335d27447bcSZhangjin Wu return __sysret(sys_fsync(fd)); 336bd8c8fbbSWilly Tarreau } 337bd8c8fbbSWilly Tarreau 338bd8c8fbbSWilly Tarreau 339bd8c8fbbSWilly Tarreau /* 340bd8c8fbbSWilly Tarreau * int getdents64(int fd, struct linux_dirent64 *dirp, int count); 341bd8c8fbbSWilly Tarreau */ 342bd8c8fbbSWilly Tarreau 343bd8c8fbbSWilly Tarreau static __attribute__((unused)) 344bd8c8fbbSWilly Tarreau int sys_getdents64(int fd, struct linux_dirent64 *dirp, int count) 345bd8c8fbbSWilly Tarreau { 346bd8c8fbbSWilly Tarreau return my_syscall3(__NR_getdents64, fd, dirp, count); 347bd8c8fbbSWilly Tarreau } 348bd8c8fbbSWilly Tarreau 349bd8c8fbbSWilly Tarreau static __attribute__((unused)) 350bd8c8fbbSWilly Tarreau int getdents64(int fd, struct linux_dirent64 *dirp, int count) 351bd8c8fbbSWilly Tarreau { 352d27447bcSZhangjin Wu return __sysret(sys_getdents64(fd, dirp, count)); 353bd8c8fbbSWilly Tarreau } 354bd8c8fbbSWilly Tarreau 355bd8c8fbbSWilly Tarreau 356bd8c8fbbSWilly Tarreau /* 357919d0532SWilly Tarreau * uid_t geteuid(void); 358919d0532SWilly Tarreau */ 359919d0532SWilly Tarreau 360919d0532SWilly Tarreau static __attribute__((unused)) 361919d0532SWilly Tarreau uid_t sys_geteuid(void) 362919d0532SWilly Tarreau { 363919d0532SWilly Tarreau #ifdef __NR_geteuid32 364919d0532SWilly Tarreau return my_syscall0(__NR_geteuid32); 365919d0532SWilly Tarreau #else 366919d0532SWilly Tarreau return my_syscall0(__NR_geteuid); 367919d0532SWilly Tarreau #endif 368919d0532SWilly Tarreau } 369919d0532SWilly Tarreau 370919d0532SWilly Tarreau static __attribute__((unused)) 371919d0532SWilly Tarreau uid_t geteuid(void) 372919d0532SWilly Tarreau { 373919d0532SWilly Tarreau return sys_geteuid(); 374919d0532SWilly Tarreau } 375919d0532SWilly Tarreau 376919d0532SWilly Tarreau 377919d0532SWilly Tarreau /* 378bd8c8fbbSWilly Tarreau * pid_t getpgid(pid_t pid); 379bd8c8fbbSWilly Tarreau */ 380bd8c8fbbSWilly Tarreau 381bd8c8fbbSWilly Tarreau static __attribute__((unused)) 382bd8c8fbbSWilly Tarreau pid_t sys_getpgid(pid_t pid) 383bd8c8fbbSWilly Tarreau { 384bd8c8fbbSWilly Tarreau return my_syscall1(__NR_getpgid, pid); 385bd8c8fbbSWilly Tarreau } 386bd8c8fbbSWilly Tarreau 387bd8c8fbbSWilly Tarreau static __attribute__((unused)) 388bd8c8fbbSWilly Tarreau pid_t getpgid(pid_t pid) 389bd8c8fbbSWilly Tarreau { 390d27447bcSZhangjin Wu return __sysret(sys_getpgid(pid)); 391bd8c8fbbSWilly Tarreau } 392bd8c8fbbSWilly Tarreau 393bd8c8fbbSWilly Tarreau 394bd8c8fbbSWilly Tarreau /* 395bd8c8fbbSWilly Tarreau * pid_t getpgrp(void); 396bd8c8fbbSWilly Tarreau */ 397bd8c8fbbSWilly Tarreau 398bd8c8fbbSWilly Tarreau static __attribute__((unused)) 399bd8c8fbbSWilly Tarreau pid_t sys_getpgrp(void) 400bd8c8fbbSWilly Tarreau { 401bd8c8fbbSWilly Tarreau return sys_getpgid(0); 402bd8c8fbbSWilly Tarreau } 403bd8c8fbbSWilly Tarreau 404bd8c8fbbSWilly Tarreau static __attribute__((unused)) 405bd8c8fbbSWilly Tarreau pid_t getpgrp(void) 406bd8c8fbbSWilly Tarreau { 407830acd08SWilly Tarreau return sys_getpgrp(); 408bd8c8fbbSWilly Tarreau } 409bd8c8fbbSWilly Tarreau 410bd8c8fbbSWilly Tarreau 411bd8c8fbbSWilly Tarreau /* 412bd8c8fbbSWilly Tarreau * pid_t getpid(void); 413bd8c8fbbSWilly Tarreau */ 414bd8c8fbbSWilly Tarreau 415bd8c8fbbSWilly Tarreau static __attribute__((unused)) 416bd8c8fbbSWilly Tarreau pid_t sys_getpid(void) 417bd8c8fbbSWilly Tarreau { 418bd8c8fbbSWilly Tarreau return my_syscall0(__NR_getpid); 419bd8c8fbbSWilly Tarreau } 420bd8c8fbbSWilly Tarreau 421bd8c8fbbSWilly Tarreau static __attribute__((unused)) 422bd8c8fbbSWilly Tarreau pid_t getpid(void) 423bd8c8fbbSWilly Tarreau { 424830acd08SWilly Tarreau return sys_getpid(); 425bd8c8fbbSWilly Tarreau } 426bd8c8fbbSWilly Tarreau 427bd8c8fbbSWilly Tarreau 428bd8c8fbbSWilly Tarreau /* 42954abe359SWilly Tarreau * pid_t getppid(void); 43054abe359SWilly Tarreau */ 43154abe359SWilly Tarreau 43254abe359SWilly Tarreau static __attribute__((unused)) 43354abe359SWilly Tarreau pid_t sys_getppid(void) 43454abe359SWilly Tarreau { 43554abe359SWilly Tarreau return my_syscall0(__NR_getppid); 43654abe359SWilly Tarreau } 43754abe359SWilly Tarreau 43854abe359SWilly Tarreau static __attribute__((unused)) 43954abe359SWilly Tarreau pid_t getppid(void) 44054abe359SWilly Tarreau { 44154abe359SWilly Tarreau return sys_getppid(); 44254abe359SWilly Tarreau } 44354abe359SWilly Tarreau 44454abe359SWilly Tarreau 44554abe359SWilly Tarreau /* 446bd8c8fbbSWilly Tarreau * pid_t gettid(void); 447bd8c8fbbSWilly Tarreau */ 448bd8c8fbbSWilly Tarreau 449bd8c8fbbSWilly Tarreau static __attribute__((unused)) 450bd8c8fbbSWilly Tarreau pid_t sys_gettid(void) 451bd8c8fbbSWilly Tarreau { 452bd8c8fbbSWilly Tarreau return my_syscall0(__NR_gettid); 453bd8c8fbbSWilly Tarreau } 454bd8c8fbbSWilly Tarreau 455bd8c8fbbSWilly Tarreau static __attribute__((unused)) 456bd8c8fbbSWilly Tarreau pid_t gettid(void) 457bd8c8fbbSWilly Tarreau { 458830acd08SWilly Tarreau return sys_gettid(); 459bd8c8fbbSWilly Tarreau } 460bd8c8fbbSWilly Tarreau 4617efd762eSAmmar Faizi static unsigned long getauxval(unsigned long key); 4627efd762eSAmmar Faizi 4637efd762eSAmmar Faizi /* 4647efd762eSAmmar Faizi * long getpagesize(void); 4657efd762eSAmmar Faizi */ 4667efd762eSAmmar Faizi 4677efd762eSAmmar Faizi static __attribute__((unused)) 4687efd762eSAmmar Faizi long getpagesize(void) 4697efd762eSAmmar Faizi { 470d27447bcSZhangjin Wu return __sysret(getauxval(AT_PAGESZ) ?: -ENOENT); 4717efd762eSAmmar Faizi } 4727efd762eSAmmar Faizi 473bd8c8fbbSWilly Tarreau 474bd8c8fbbSWilly Tarreau /* 475bd8c8fbbSWilly Tarreau * int gettimeofday(struct timeval *tv, struct timezone *tz); 476bd8c8fbbSWilly Tarreau */ 477bd8c8fbbSWilly Tarreau 478bd8c8fbbSWilly Tarreau static __attribute__((unused)) 479bd8c8fbbSWilly Tarreau int sys_gettimeofday(struct timeval *tv, struct timezone *tz) 480bd8c8fbbSWilly Tarreau { 4812f98aca8SZhangjin Wu #ifdef __NR_gettimeofday 482bd8c8fbbSWilly Tarreau return my_syscall2(__NR_gettimeofday, tv, tz); 4832f98aca8SZhangjin Wu #else 4842f98aca8SZhangjin Wu return -ENOSYS; 4852f98aca8SZhangjin Wu #endif 486bd8c8fbbSWilly Tarreau } 487bd8c8fbbSWilly Tarreau 488bd8c8fbbSWilly Tarreau static __attribute__((unused)) 489bd8c8fbbSWilly Tarreau int gettimeofday(struct timeval *tv, struct timezone *tz) 490bd8c8fbbSWilly Tarreau { 491d27447bcSZhangjin Wu return __sysret(sys_gettimeofday(tv, tz)); 492bd8c8fbbSWilly Tarreau } 493bd8c8fbbSWilly Tarreau 494bd8c8fbbSWilly Tarreau 495bd8c8fbbSWilly Tarreau /* 496919d0532SWilly Tarreau * uid_t getuid(void); 497919d0532SWilly Tarreau */ 498919d0532SWilly Tarreau 499919d0532SWilly Tarreau static __attribute__((unused)) 500919d0532SWilly Tarreau uid_t sys_getuid(void) 501919d0532SWilly Tarreau { 502919d0532SWilly Tarreau #ifdef __NR_getuid32 503919d0532SWilly Tarreau return my_syscall0(__NR_getuid32); 504919d0532SWilly Tarreau #else 505919d0532SWilly Tarreau return my_syscall0(__NR_getuid); 506919d0532SWilly Tarreau #endif 507919d0532SWilly Tarreau } 508919d0532SWilly Tarreau 509919d0532SWilly Tarreau static __attribute__((unused)) 510919d0532SWilly Tarreau uid_t getuid(void) 511919d0532SWilly Tarreau { 512919d0532SWilly Tarreau return sys_getuid(); 513919d0532SWilly Tarreau } 514919d0532SWilly Tarreau 515919d0532SWilly Tarreau 516919d0532SWilly Tarreau /* 517bd8c8fbbSWilly Tarreau * int ioctl(int fd, unsigned long req, void *value); 518bd8c8fbbSWilly Tarreau */ 519bd8c8fbbSWilly Tarreau 520bd8c8fbbSWilly Tarreau static __attribute__((unused)) 521bd8c8fbbSWilly Tarreau int sys_ioctl(int fd, unsigned long req, void *value) 522bd8c8fbbSWilly Tarreau { 523bd8c8fbbSWilly Tarreau return my_syscall3(__NR_ioctl, fd, req, value); 524bd8c8fbbSWilly Tarreau } 525bd8c8fbbSWilly Tarreau 526bd8c8fbbSWilly Tarreau static __attribute__((unused)) 527bd8c8fbbSWilly Tarreau int ioctl(int fd, unsigned long req, void *value) 528bd8c8fbbSWilly Tarreau { 529d27447bcSZhangjin Wu return __sysret(sys_ioctl(fd, req, value)); 530bd8c8fbbSWilly Tarreau } 531bd8c8fbbSWilly Tarreau 532bd8c8fbbSWilly Tarreau /* 533bd8c8fbbSWilly Tarreau * int kill(pid_t pid, int signal); 534bd8c8fbbSWilly Tarreau */ 535bd8c8fbbSWilly Tarreau 536bd8c8fbbSWilly Tarreau static __attribute__((unused)) 537bd8c8fbbSWilly Tarreau int sys_kill(pid_t pid, int signal) 538bd8c8fbbSWilly Tarreau { 539bd8c8fbbSWilly Tarreau return my_syscall2(__NR_kill, pid, signal); 540bd8c8fbbSWilly Tarreau } 541bd8c8fbbSWilly Tarreau 542bd8c8fbbSWilly Tarreau static __attribute__((unused)) 543bd8c8fbbSWilly Tarreau int kill(pid_t pid, int signal) 544bd8c8fbbSWilly Tarreau { 545d27447bcSZhangjin Wu return __sysret(sys_kill(pid, signal)); 546bd8c8fbbSWilly Tarreau } 547bd8c8fbbSWilly Tarreau 548bd8c8fbbSWilly Tarreau 549bd8c8fbbSWilly Tarreau /* 550bd8c8fbbSWilly Tarreau * int link(const char *old, const char *new); 551bd8c8fbbSWilly Tarreau */ 552bd8c8fbbSWilly Tarreau 553bd8c8fbbSWilly Tarreau static __attribute__((unused)) 554bd8c8fbbSWilly Tarreau int sys_link(const char *old, const char *new) 555bd8c8fbbSWilly Tarreau { 556bd8c8fbbSWilly Tarreau #ifdef __NR_linkat 557bd8c8fbbSWilly Tarreau return my_syscall5(__NR_linkat, AT_FDCWD, old, AT_FDCWD, new, 0); 558bd8c8fbbSWilly Tarreau #elif defined(__NR_link) 559bd8c8fbbSWilly Tarreau return my_syscall2(__NR_link, old, new); 560bd8c8fbbSWilly Tarreau #else 561ca50df30SZhangjin Wu return -ENOSYS; 562bd8c8fbbSWilly Tarreau #endif 563bd8c8fbbSWilly Tarreau } 564bd8c8fbbSWilly Tarreau 565bd8c8fbbSWilly Tarreau static __attribute__((unused)) 566bd8c8fbbSWilly Tarreau int link(const char *old, const char *new) 567bd8c8fbbSWilly Tarreau { 568d27447bcSZhangjin Wu return __sysret(sys_link(old, new)); 569bd8c8fbbSWilly Tarreau } 570bd8c8fbbSWilly Tarreau 571bd8c8fbbSWilly Tarreau 572bd8c8fbbSWilly Tarreau /* 573bd8c8fbbSWilly Tarreau * off_t lseek(int fd, off_t offset, int whence); 574bd8c8fbbSWilly Tarreau */ 575bd8c8fbbSWilly Tarreau 576bd8c8fbbSWilly Tarreau static __attribute__((unused)) 577bd8c8fbbSWilly Tarreau off_t sys_lseek(int fd, off_t offset, int whence) 578bd8c8fbbSWilly Tarreau { 5792f98aca8SZhangjin Wu #ifdef __NR_lseek 580bd8c8fbbSWilly Tarreau return my_syscall3(__NR_lseek, fd, offset, whence); 5812f98aca8SZhangjin Wu #else 5822f98aca8SZhangjin Wu return -ENOSYS; 5832f98aca8SZhangjin Wu #endif 584bd8c8fbbSWilly Tarreau } 585bd8c8fbbSWilly Tarreau 586bd8c8fbbSWilly Tarreau static __attribute__((unused)) 587bd8c8fbbSWilly Tarreau off_t lseek(int fd, off_t offset, int whence) 588bd8c8fbbSWilly Tarreau { 589d27447bcSZhangjin Wu return __sysret(sys_lseek(fd, offset, whence)); 590bd8c8fbbSWilly Tarreau } 591bd8c8fbbSWilly Tarreau 592bd8c8fbbSWilly Tarreau 593bd8c8fbbSWilly Tarreau /* 594bd8c8fbbSWilly Tarreau * int mkdir(const char *path, mode_t mode); 595bd8c8fbbSWilly Tarreau */ 596bd8c8fbbSWilly Tarreau 597bd8c8fbbSWilly Tarreau static __attribute__((unused)) 598bd8c8fbbSWilly Tarreau int sys_mkdir(const char *path, mode_t mode) 599bd8c8fbbSWilly Tarreau { 600bd8c8fbbSWilly Tarreau #ifdef __NR_mkdirat 601bd8c8fbbSWilly Tarreau return my_syscall3(__NR_mkdirat, AT_FDCWD, path, mode); 602bd8c8fbbSWilly Tarreau #elif defined(__NR_mkdir) 603bd8c8fbbSWilly Tarreau return my_syscall2(__NR_mkdir, path, mode); 604bd8c8fbbSWilly Tarreau #else 605ca50df30SZhangjin Wu return -ENOSYS; 606bd8c8fbbSWilly Tarreau #endif 607bd8c8fbbSWilly Tarreau } 608bd8c8fbbSWilly Tarreau 609bd8c8fbbSWilly Tarreau static __attribute__((unused)) 610bd8c8fbbSWilly Tarreau int mkdir(const char *path, mode_t mode) 611bd8c8fbbSWilly Tarreau { 612d27447bcSZhangjin Wu return __sysret(sys_mkdir(path, mode)); 613bd8c8fbbSWilly Tarreau } 614bd8c8fbbSWilly Tarreau 615bd8c8fbbSWilly Tarreau 616bd8c8fbbSWilly Tarreau /* 617bd8c8fbbSWilly Tarreau * int mknod(const char *path, mode_t mode, dev_t dev); 618bd8c8fbbSWilly Tarreau */ 619bd8c8fbbSWilly Tarreau 620bd8c8fbbSWilly Tarreau static __attribute__((unused)) 621bd8c8fbbSWilly Tarreau long sys_mknod(const char *path, mode_t mode, dev_t dev) 622bd8c8fbbSWilly Tarreau { 623bd8c8fbbSWilly Tarreau #ifdef __NR_mknodat 624bd8c8fbbSWilly Tarreau return my_syscall4(__NR_mknodat, AT_FDCWD, path, mode, dev); 625bd8c8fbbSWilly Tarreau #elif defined(__NR_mknod) 626bd8c8fbbSWilly Tarreau return my_syscall3(__NR_mknod, path, mode, dev); 627bd8c8fbbSWilly Tarreau #else 628ca50df30SZhangjin Wu return -ENOSYS; 629bd8c8fbbSWilly Tarreau #endif 630bd8c8fbbSWilly Tarreau } 631bd8c8fbbSWilly Tarreau 632bd8c8fbbSWilly Tarreau static __attribute__((unused)) 633bd8c8fbbSWilly Tarreau int mknod(const char *path, mode_t mode, dev_t dev) 634bd8c8fbbSWilly Tarreau { 635d27447bcSZhangjin Wu return __sysret(sys_mknod(path, mode, dev)); 636bd8c8fbbSWilly Tarreau } 637bd8c8fbbSWilly Tarreau 63818a5a09dSSven Schnelle #ifndef sys_mmap 639544fa1a2SAmmar Faizi static __attribute__((unused)) 640544fa1a2SAmmar Faizi void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd, 641544fa1a2SAmmar Faizi off_t offset) 642544fa1a2SAmmar Faizi { 643544fa1a2SAmmar Faizi int n; 644544fa1a2SAmmar Faizi 645364702f7SWilly Tarreau #if defined(__NR_mmap2) 646544fa1a2SAmmar Faizi n = __NR_mmap2; 647544fa1a2SAmmar Faizi offset >>= 12; 648544fa1a2SAmmar Faizi #else 649544fa1a2SAmmar Faizi n = __NR_mmap; 650544fa1a2SAmmar Faizi #endif 651544fa1a2SAmmar Faizi 652544fa1a2SAmmar Faizi return (void *)my_syscall6(n, addr, length, prot, flags, fd, offset); 653544fa1a2SAmmar Faizi } 65418a5a09dSSven Schnelle #endif 655544fa1a2SAmmar Faizi 656924e9539SZhangjin Wu /* Note that on Linux, MAP_FAILED is -1 so we can use the generic __sysret() 657924e9539SZhangjin Wu * which returns -1 upon error and still satisfy user land that checks for 658924e9539SZhangjin Wu * MAP_FAILED. 659924e9539SZhangjin Wu */ 660924e9539SZhangjin Wu 661544fa1a2SAmmar Faizi static __attribute__((unused)) 662544fa1a2SAmmar Faizi void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) 663544fa1a2SAmmar Faizi { 664924e9539SZhangjin Wu return (void *)__sysret((unsigned long)sys_mmap(addr, length, prot, flags, fd, offset)); 665544fa1a2SAmmar Faizi } 666544fa1a2SAmmar Faizi 667544fa1a2SAmmar Faizi static __attribute__((unused)) 668544fa1a2SAmmar Faizi int sys_munmap(void *addr, size_t length) 669544fa1a2SAmmar Faizi { 670544fa1a2SAmmar Faizi return my_syscall2(__NR_munmap, addr, length); 671544fa1a2SAmmar Faizi } 672544fa1a2SAmmar Faizi 673544fa1a2SAmmar Faizi static __attribute__((unused)) 674544fa1a2SAmmar Faizi int munmap(void *addr, size_t length) 675544fa1a2SAmmar Faizi { 676d27447bcSZhangjin Wu return __sysret(sys_munmap(addr, length)); 677544fa1a2SAmmar Faizi } 678bd8c8fbbSWilly Tarreau 679bd8c8fbbSWilly Tarreau /* 680bd8c8fbbSWilly Tarreau * int mount(const char *source, const char *target, 681bd8c8fbbSWilly Tarreau * const char *fstype, unsigned long flags, 682bd8c8fbbSWilly Tarreau * const void *data); 683bd8c8fbbSWilly Tarreau */ 684bd8c8fbbSWilly Tarreau static __attribute__((unused)) 685bd8c8fbbSWilly Tarreau int sys_mount(const char *src, const char *tgt, const char *fst, 686bd8c8fbbSWilly Tarreau unsigned long flags, const void *data) 687bd8c8fbbSWilly Tarreau { 688bd8c8fbbSWilly Tarreau return my_syscall5(__NR_mount, src, tgt, fst, flags, data); 689bd8c8fbbSWilly Tarreau } 690bd8c8fbbSWilly Tarreau 691bd8c8fbbSWilly Tarreau static __attribute__((unused)) 692bd8c8fbbSWilly Tarreau int mount(const char *src, const char *tgt, 693bd8c8fbbSWilly Tarreau const char *fst, unsigned long flags, 694bd8c8fbbSWilly Tarreau const void *data) 695bd8c8fbbSWilly Tarreau { 696d27447bcSZhangjin Wu return __sysret(sys_mount(src, tgt, fst, flags, data)); 697bd8c8fbbSWilly Tarreau } 698bd8c8fbbSWilly Tarreau 699bd8c8fbbSWilly Tarreau 700bd8c8fbbSWilly Tarreau /* 701a7604ba1SWilly Tarreau * int open(const char *path, int flags[, mode_t mode]); 702bd8c8fbbSWilly Tarreau */ 703bd8c8fbbSWilly Tarreau 704bd8c8fbbSWilly Tarreau static __attribute__((unused)) 705bd8c8fbbSWilly Tarreau int sys_open(const char *path, int flags, mode_t mode) 706bd8c8fbbSWilly Tarreau { 707bd8c8fbbSWilly Tarreau #ifdef __NR_openat 708bd8c8fbbSWilly Tarreau return my_syscall4(__NR_openat, AT_FDCWD, path, flags, mode); 709bd8c8fbbSWilly Tarreau #elif defined(__NR_open) 710bd8c8fbbSWilly Tarreau return my_syscall3(__NR_open, path, flags, mode); 711bd8c8fbbSWilly Tarreau #else 712ca50df30SZhangjin Wu return -ENOSYS; 713bd8c8fbbSWilly Tarreau #endif 714bd8c8fbbSWilly Tarreau } 715bd8c8fbbSWilly Tarreau 716bd8c8fbbSWilly Tarreau static __attribute__((unused)) 717a7604ba1SWilly Tarreau int open(const char *path, int flags, ...) 718bd8c8fbbSWilly Tarreau { 719a7604ba1SWilly Tarreau mode_t mode = 0; 720a7604ba1SWilly Tarreau int ret; 721a7604ba1SWilly Tarreau 722a7604ba1SWilly Tarreau if (flags & O_CREAT) { 723a7604ba1SWilly Tarreau va_list args; 724a7604ba1SWilly Tarreau 725a7604ba1SWilly Tarreau va_start(args, flags); 726f62ec079SZhangjin Wu mode = va_arg(args, int); 727a7604ba1SWilly Tarreau va_end(args); 728a7604ba1SWilly Tarreau } 729a7604ba1SWilly Tarreau 730d27447bcSZhangjin Wu return __sysret(sys_open(path, flags, mode)); 731bd8c8fbbSWilly Tarreau } 732bd8c8fbbSWilly Tarreau 733bd8c8fbbSWilly Tarreau 734bd8c8fbbSWilly Tarreau /* 735208aa9d9SThomas Weißschuh * int prctl(int option, unsigned long arg2, unsigned long arg3, 736208aa9d9SThomas Weißschuh * unsigned long arg4, unsigned long arg5); 737208aa9d9SThomas Weißschuh */ 738208aa9d9SThomas Weißschuh 739208aa9d9SThomas Weißschuh static __attribute__((unused)) 740208aa9d9SThomas Weißschuh int sys_prctl(int option, unsigned long arg2, unsigned long arg3, 741208aa9d9SThomas Weißschuh unsigned long arg4, unsigned long arg5) 742208aa9d9SThomas Weißschuh { 743208aa9d9SThomas Weißschuh return my_syscall5(__NR_prctl, option, arg2, arg3, arg4, arg5); 744208aa9d9SThomas Weißschuh } 745208aa9d9SThomas Weißschuh 746208aa9d9SThomas Weißschuh static __attribute__((unused)) 747208aa9d9SThomas Weißschuh int prctl(int option, unsigned long arg2, unsigned long arg3, 748208aa9d9SThomas Weißschuh unsigned long arg4, unsigned long arg5) 749208aa9d9SThomas Weißschuh { 750d27447bcSZhangjin Wu return __sysret(sys_prctl(option, arg2, arg3, arg4, arg5)); 751208aa9d9SThomas Weißschuh } 752208aa9d9SThomas Weißschuh 753208aa9d9SThomas Weißschuh 754208aa9d9SThomas Weißschuh /* 755bd8c8fbbSWilly Tarreau * int pivot_root(const char *new, const char *old); 756bd8c8fbbSWilly Tarreau */ 757bd8c8fbbSWilly Tarreau 758bd8c8fbbSWilly Tarreau static __attribute__((unused)) 759bd8c8fbbSWilly Tarreau int sys_pivot_root(const char *new, const char *old) 760bd8c8fbbSWilly Tarreau { 761bd8c8fbbSWilly Tarreau return my_syscall2(__NR_pivot_root, new, old); 762bd8c8fbbSWilly Tarreau } 763bd8c8fbbSWilly Tarreau 764bd8c8fbbSWilly Tarreau static __attribute__((unused)) 765bd8c8fbbSWilly Tarreau int pivot_root(const char *new, const char *old) 766bd8c8fbbSWilly Tarreau { 767d27447bcSZhangjin Wu return __sysret(sys_pivot_root(new, old)); 768bd8c8fbbSWilly Tarreau } 769bd8c8fbbSWilly Tarreau 770bd8c8fbbSWilly Tarreau 771bd8c8fbbSWilly Tarreau /* 772bd8c8fbbSWilly Tarreau * int poll(struct pollfd *fds, int nfds, int timeout); 773bd8c8fbbSWilly Tarreau */ 774bd8c8fbbSWilly Tarreau 775bd8c8fbbSWilly Tarreau static __attribute__((unused)) 776bd8c8fbbSWilly Tarreau int sys_poll(struct pollfd *fds, int nfds, int timeout) 777bd8c8fbbSWilly Tarreau { 778bd8c8fbbSWilly Tarreau #if defined(__NR_ppoll) 779bd8c8fbbSWilly Tarreau struct timespec t; 780bd8c8fbbSWilly Tarreau 781bd8c8fbbSWilly Tarreau if (timeout >= 0) { 782bd8c8fbbSWilly Tarreau t.tv_sec = timeout / 1000; 783bd8c8fbbSWilly Tarreau t.tv_nsec = (timeout % 1000) * 1000000; 784bd8c8fbbSWilly Tarreau } 7850dd2fdbfSZhangjin Wu return my_syscall5(__NR_ppoll, fds, nfds, (timeout >= 0) ? &t : NULL, NULL, 0); 786bd8c8fbbSWilly Tarreau #elif defined(__NR_poll) 787bd8c8fbbSWilly Tarreau return my_syscall3(__NR_poll, fds, nfds, timeout); 788bd8c8fbbSWilly Tarreau #else 789ca50df30SZhangjin Wu return -ENOSYS; 790bd8c8fbbSWilly Tarreau #endif 791bd8c8fbbSWilly Tarreau } 792bd8c8fbbSWilly Tarreau 793bd8c8fbbSWilly Tarreau static __attribute__((unused)) 794bd8c8fbbSWilly Tarreau int poll(struct pollfd *fds, int nfds, int timeout) 795bd8c8fbbSWilly Tarreau { 796d27447bcSZhangjin Wu return __sysret(sys_poll(fds, nfds, timeout)); 797bd8c8fbbSWilly Tarreau } 798bd8c8fbbSWilly Tarreau 799bd8c8fbbSWilly Tarreau 800bd8c8fbbSWilly Tarreau /* 801bd8c8fbbSWilly Tarreau * ssize_t read(int fd, void *buf, size_t count); 802bd8c8fbbSWilly Tarreau */ 803bd8c8fbbSWilly Tarreau 804bd8c8fbbSWilly Tarreau static __attribute__((unused)) 805bd8c8fbbSWilly Tarreau ssize_t sys_read(int fd, void *buf, size_t count) 806bd8c8fbbSWilly Tarreau { 807bd8c8fbbSWilly Tarreau return my_syscall3(__NR_read, fd, buf, count); 808bd8c8fbbSWilly Tarreau } 809bd8c8fbbSWilly Tarreau 810bd8c8fbbSWilly Tarreau static __attribute__((unused)) 811bd8c8fbbSWilly Tarreau ssize_t read(int fd, void *buf, size_t count) 812bd8c8fbbSWilly Tarreau { 813d27447bcSZhangjin Wu return __sysret(sys_read(fd, buf, count)); 814bd8c8fbbSWilly Tarreau } 815bd8c8fbbSWilly Tarreau 816bd8c8fbbSWilly Tarreau 817bd8c8fbbSWilly Tarreau /* 818bd8c8fbbSWilly Tarreau * int reboot(int cmd); 819bd8c8fbbSWilly Tarreau * <cmd> is among LINUX_REBOOT_CMD_* 820bd8c8fbbSWilly Tarreau */ 821bd8c8fbbSWilly Tarreau 822bd8c8fbbSWilly Tarreau static __attribute__((unused)) 823bd8c8fbbSWilly Tarreau ssize_t sys_reboot(int magic1, int magic2, int cmd, void *arg) 824bd8c8fbbSWilly Tarreau { 825bd8c8fbbSWilly Tarreau return my_syscall4(__NR_reboot, magic1, magic2, cmd, arg); 826bd8c8fbbSWilly Tarreau } 827bd8c8fbbSWilly Tarreau 828bd8c8fbbSWilly Tarreau static __attribute__((unused)) 829bd8c8fbbSWilly Tarreau int reboot(int cmd) 830bd8c8fbbSWilly Tarreau { 831d27447bcSZhangjin Wu return __sysret(sys_reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, cmd, 0)); 832bd8c8fbbSWilly Tarreau } 833bd8c8fbbSWilly Tarreau 834bd8c8fbbSWilly Tarreau 835bd8c8fbbSWilly Tarreau /* 836bd8c8fbbSWilly Tarreau * int sched_yield(void); 837bd8c8fbbSWilly Tarreau */ 838bd8c8fbbSWilly Tarreau 839bd8c8fbbSWilly Tarreau static __attribute__((unused)) 840bd8c8fbbSWilly Tarreau int sys_sched_yield(void) 841bd8c8fbbSWilly Tarreau { 842bd8c8fbbSWilly Tarreau return my_syscall0(__NR_sched_yield); 843bd8c8fbbSWilly Tarreau } 844bd8c8fbbSWilly Tarreau 845bd8c8fbbSWilly Tarreau static __attribute__((unused)) 846bd8c8fbbSWilly Tarreau int sched_yield(void) 847bd8c8fbbSWilly Tarreau { 848d27447bcSZhangjin Wu return __sysret(sys_sched_yield()); 849bd8c8fbbSWilly Tarreau } 850bd8c8fbbSWilly Tarreau 851bd8c8fbbSWilly Tarreau 852bd8c8fbbSWilly Tarreau /* 853bd8c8fbbSWilly Tarreau * int select(int nfds, fd_set *read_fds, fd_set *write_fds, 854bd8c8fbbSWilly Tarreau * fd_set *except_fds, struct timeval *timeout); 855bd8c8fbbSWilly Tarreau */ 856bd8c8fbbSWilly Tarreau 857bd8c8fbbSWilly Tarreau static __attribute__((unused)) 858bd8c8fbbSWilly Tarreau int sys_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *timeout) 859bd8c8fbbSWilly Tarreau { 860bd8c8fbbSWilly Tarreau #if defined(__ARCH_WANT_SYS_OLD_SELECT) && !defined(__NR__newselect) 861bd8c8fbbSWilly Tarreau struct sel_arg_struct { 862bd8c8fbbSWilly Tarreau unsigned long n; 863bd8c8fbbSWilly Tarreau fd_set *r, *w, *e; 864bd8c8fbbSWilly Tarreau struct timeval *t; 865bd8c8fbbSWilly Tarreau } arg = { .n = nfds, .r = rfds, .w = wfds, .e = efds, .t = timeout }; 866bd8c8fbbSWilly Tarreau return my_syscall1(__NR_select, &arg); 867bd8c8fbbSWilly Tarreau #elif defined(__ARCH_WANT_SYS_PSELECT6) && defined(__NR_pselect6) 868bd8c8fbbSWilly Tarreau struct timespec t; 869bd8c8fbbSWilly Tarreau 870bd8c8fbbSWilly Tarreau if (timeout) { 871bd8c8fbbSWilly Tarreau t.tv_sec = timeout->tv_sec; 872bd8c8fbbSWilly Tarreau t.tv_nsec = timeout->tv_usec * 1000; 873bd8c8fbbSWilly Tarreau } 874bd8c8fbbSWilly Tarreau return my_syscall6(__NR_pselect6, nfds, rfds, wfds, efds, timeout ? &t : NULL, NULL); 875bd8c8fbbSWilly Tarreau #elif defined(__NR__newselect) || defined(__NR_select) 876bd8c8fbbSWilly Tarreau #ifndef __NR__newselect 877bd8c8fbbSWilly Tarreau #define __NR__newselect __NR_select 878bd8c8fbbSWilly Tarreau #endif 879bd8c8fbbSWilly Tarreau return my_syscall5(__NR__newselect, nfds, rfds, wfds, efds, timeout); 880bd8c8fbbSWilly Tarreau #else 881ca50df30SZhangjin Wu return -ENOSYS; 882bd8c8fbbSWilly Tarreau #endif 883bd8c8fbbSWilly Tarreau } 884bd8c8fbbSWilly Tarreau 885bd8c8fbbSWilly Tarreau static __attribute__((unused)) 886bd8c8fbbSWilly Tarreau int select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *timeout) 887bd8c8fbbSWilly Tarreau { 888d27447bcSZhangjin Wu return __sysret(sys_select(nfds, rfds, wfds, efds, timeout)); 889bd8c8fbbSWilly Tarreau } 890bd8c8fbbSWilly Tarreau 891bd8c8fbbSWilly Tarreau 892bd8c8fbbSWilly Tarreau /* 893bd8c8fbbSWilly Tarreau * int setpgid(pid_t pid, pid_t pgid); 894bd8c8fbbSWilly Tarreau */ 895bd8c8fbbSWilly Tarreau 896bd8c8fbbSWilly Tarreau static __attribute__((unused)) 897bd8c8fbbSWilly Tarreau int sys_setpgid(pid_t pid, pid_t pgid) 898bd8c8fbbSWilly Tarreau { 899bd8c8fbbSWilly Tarreau return my_syscall2(__NR_setpgid, pid, pgid); 900bd8c8fbbSWilly Tarreau } 901bd8c8fbbSWilly Tarreau 902bd8c8fbbSWilly Tarreau static __attribute__((unused)) 903bd8c8fbbSWilly Tarreau int setpgid(pid_t pid, pid_t pgid) 904bd8c8fbbSWilly Tarreau { 905d27447bcSZhangjin Wu return __sysret(sys_setpgid(pid, pgid)); 906bd8c8fbbSWilly Tarreau } 907bd8c8fbbSWilly Tarreau 908bd8c8fbbSWilly Tarreau 909bd8c8fbbSWilly Tarreau /* 910bd8c8fbbSWilly Tarreau * pid_t setsid(void); 911bd8c8fbbSWilly Tarreau */ 912bd8c8fbbSWilly Tarreau 913bd8c8fbbSWilly Tarreau static __attribute__((unused)) 914bd8c8fbbSWilly Tarreau pid_t sys_setsid(void) 915bd8c8fbbSWilly Tarreau { 916bd8c8fbbSWilly Tarreau return my_syscall0(__NR_setsid); 917bd8c8fbbSWilly Tarreau } 918bd8c8fbbSWilly Tarreau 919bd8c8fbbSWilly Tarreau static __attribute__((unused)) 920bd8c8fbbSWilly Tarreau pid_t setsid(void) 921bd8c8fbbSWilly Tarreau { 922d27447bcSZhangjin Wu return __sysret(sys_setsid()); 923bd8c8fbbSWilly Tarreau } 924bd8c8fbbSWilly Tarreau 925b551cb7dSFeiyang Chen #if defined(__NR_statx) 926b551cb7dSFeiyang Chen /* 927b551cb7dSFeiyang Chen * int statx(int fd, const char *path, int flags, unsigned int mask, struct statx *buf); 928b551cb7dSFeiyang Chen */ 929b551cb7dSFeiyang Chen 930b551cb7dSFeiyang Chen static __attribute__((unused)) 931b551cb7dSFeiyang Chen int sys_statx(int fd, const char *path, int flags, unsigned int mask, struct statx *buf) 932b551cb7dSFeiyang Chen { 933b551cb7dSFeiyang Chen return my_syscall5(__NR_statx, fd, path, flags, mask, buf); 934b551cb7dSFeiyang Chen } 935b551cb7dSFeiyang Chen 936b551cb7dSFeiyang Chen static __attribute__((unused)) 937b551cb7dSFeiyang Chen int statx(int fd, const char *path, int flags, unsigned int mask, struct statx *buf) 938b551cb7dSFeiyang Chen { 939d27447bcSZhangjin Wu return __sysret(sys_statx(fd, path, flags, mask, buf)); 940b551cb7dSFeiyang Chen } 941b551cb7dSFeiyang Chen #endif 942bd8c8fbbSWilly Tarreau 943bd8c8fbbSWilly Tarreau /* 944bd8c8fbbSWilly Tarreau * int stat(const char *path, struct stat *buf); 945bd8c8fbbSWilly Tarreau * Warning: the struct stat's layout is arch-dependent. 946bd8c8fbbSWilly Tarreau */ 947bd8c8fbbSWilly Tarreau 948b551cb7dSFeiyang Chen #if defined(__NR_statx) && !defined(__NR_newfstatat) && !defined(__NR_stat) 949b551cb7dSFeiyang Chen /* 950b551cb7dSFeiyang Chen * Maybe we can just use statx() when available for all architectures? 951b551cb7dSFeiyang Chen */ 952b551cb7dSFeiyang Chen static __attribute__((unused)) 953b551cb7dSFeiyang Chen int sys_stat(const char *path, struct stat *buf) 954b551cb7dSFeiyang Chen { 955b551cb7dSFeiyang Chen struct statx statx; 956b551cb7dSFeiyang Chen long ret; 957b551cb7dSFeiyang Chen 958b551cb7dSFeiyang Chen ret = sys_statx(AT_FDCWD, path, AT_NO_AUTOMOUNT, STATX_BASIC_STATS, &statx); 959b551cb7dSFeiyang Chen buf->st_dev = ((statx.stx_dev_minor & 0xff) 960b551cb7dSFeiyang Chen | (statx.stx_dev_major << 8) 961b551cb7dSFeiyang Chen | ((statx.stx_dev_minor & ~0xff) << 12)); 962b551cb7dSFeiyang Chen buf->st_ino = statx.stx_ino; 963b551cb7dSFeiyang Chen buf->st_mode = statx.stx_mode; 964b551cb7dSFeiyang Chen buf->st_nlink = statx.stx_nlink; 965b551cb7dSFeiyang Chen buf->st_uid = statx.stx_uid; 966b551cb7dSFeiyang Chen buf->st_gid = statx.stx_gid; 967b551cb7dSFeiyang Chen buf->st_rdev = ((statx.stx_rdev_minor & 0xff) 968b551cb7dSFeiyang Chen | (statx.stx_rdev_major << 8) 969b551cb7dSFeiyang Chen | ((statx.stx_rdev_minor & ~0xff) << 12)); 970b551cb7dSFeiyang Chen buf->st_size = statx.stx_size; 971b551cb7dSFeiyang Chen buf->st_blksize = statx.stx_blksize; 972b551cb7dSFeiyang Chen buf->st_blocks = statx.stx_blocks; 97387b9fa66SThomas Weißschuh buf->st_atim.tv_sec = statx.stx_atime.tv_sec; 97487b9fa66SThomas Weißschuh buf->st_atim.tv_nsec = statx.stx_atime.tv_nsec; 97587b9fa66SThomas Weißschuh buf->st_mtim.tv_sec = statx.stx_mtime.tv_sec; 97687b9fa66SThomas Weißschuh buf->st_mtim.tv_nsec = statx.stx_mtime.tv_nsec; 97787b9fa66SThomas Weißschuh buf->st_ctim.tv_sec = statx.stx_ctime.tv_sec; 97887b9fa66SThomas Weißschuh buf->st_ctim.tv_nsec = statx.stx_ctime.tv_nsec; 979b551cb7dSFeiyang Chen return ret; 980b551cb7dSFeiyang Chen } 981b551cb7dSFeiyang Chen #else 982bd8c8fbbSWilly Tarreau static __attribute__((unused)) 983bd8c8fbbSWilly Tarreau int sys_stat(const char *path, struct stat *buf) 984bd8c8fbbSWilly Tarreau { 985bd8c8fbbSWilly Tarreau struct sys_stat_struct stat; 986bd8c8fbbSWilly Tarreau long ret; 987bd8c8fbbSWilly Tarreau 988bd8c8fbbSWilly Tarreau #ifdef __NR_newfstatat 989bd8c8fbbSWilly Tarreau /* only solution for arm64 */ 990bd8c8fbbSWilly Tarreau ret = my_syscall4(__NR_newfstatat, AT_FDCWD, path, &stat, 0); 991bd8c8fbbSWilly Tarreau #elif defined(__NR_stat) 992bd8c8fbbSWilly Tarreau ret = my_syscall2(__NR_stat, path, &stat); 993bd8c8fbbSWilly Tarreau #else 994ca50df30SZhangjin Wu return -ENOSYS; 995bd8c8fbbSWilly Tarreau #endif 996bd8c8fbbSWilly Tarreau buf->st_dev = stat.st_dev; 997bd8c8fbbSWilly Tarreau buf->st_ino = stat.st_ino; 998bd8c8fbbSWilly Tarreau buf->st_mode = stat.st_mode; 999bd8c8fbbSWilly Tarreau buf->st_nlink = stat.st_nlink; 1000bd8c8fbbSWilly Tarreau buf->st_uid = stat.st_uid; 1001bd8c8fbbSWilly Tarreau buf->st_gid = stat.st_gid; 1002bd8c8fbbSWilly Tarreau buf->st_rdev = stat.st_rdev; 1003bd8c8fbbSWilly Tarreau buf->st_size = stat.st_size; 1004bd8c8fbbSWilly Tarreau buf->st_blksize = stat.st_blksize; 1005bd8c8fbbSWilly Tarreau buf->st_blocks = stat.st_blocks; 100687b9fa66SThomas Weißschuh buf->st_atim.tv_sec = stat.st_atime; 100787b9fa66SThomas Weißschuh buf->st_atim.tv_nsec = stat.st_atime_nsec; 100887b9fa66SThomas Weißschuh buf->st_mtim.tv_sec = stat.st_mtime; 100987b9fa66SThomas Weißschuh buf->st_mtim.tv_nsec = stat.st_mtime_nsec; 101087b9fa66SThomas Weißschuh buf->st_ctim.tv_sec = stat.st_ctime; 101187b9fa66SThomas Weißschuh buf->st_ctim.tv_nsec = stat.st_ctime_nsec; 1012bd8c8fbbSWilly Tarreau return ret; 1013bd8c8fbbSWilly Tarreau } 1014b551cb7dSFeiyang Chen #endif 1015bd8c8fbbSWilly Tarreau 1016bd8c8fbbSWilly Tarreau static __attribute__((unused)) 1017bd8c8fbbSWilly Tarreau int stat(const char *path, struct stat *buf) 1018bd8c8fbbSWilly Tarreau { 1019d27447bcSZhangjin Wu return __sysret(sys_stat(path, buf)); 1020bd8c8fbbSWilly Tarreau } 1021bd8c8fbbSWilly Tarreau 1022bd8c8fbbSWilly Tarreau 1023bd8c8fbbSWilly Tarreau /* 1024bd8c8fbbSWilly Tarreau * int symlink(const char *old, const char *new); 1025bd8c8fbbSWilly Tarreau */ 1026bd8c8fbbSWilly Tarreau 1027bd8c8fbbSWilly Tarreau static __attribute__((unused)) 1028bd8c8fbbSWilly Tarreau int sys_symlink(const char *old, const char *new) 1029bd8c8fbbSWilly Tarreau { 1030bd8c8fbbSWilly Tarreau #ifdef __NR_symlinkat 1031bd8c8fbbSWilly Tarreau return my_syscall3(__NR_symlinkat, old, AT_FDCWD, new); 1032bd8c8fbbSWilly Tarreau #elif defined(__NR_symlink) 1033bd8c8fbbSWilly Tarreau return my_syscall2(__NR_symlink, old, new); 1034bd8c8fbbSWilly Tarreau #else 1035ca50df30SZhangjin Wu return -ENOSYS; 1036bd8c8fbbSWilly Tarreau #endif 1037bd8c8fbbSWilly Tarreau } 1038bd8c8fbbSWilly Tarreau 1039bd8c8fbbSWilly Tarreau static __attribute__((unused)) 1040bd8c8fbbSWilly Tarreau int symlink(const char *old, const char *new) 1041bd8c8fbbSWilly Tarreau { 1042d27447bcSZhangjin Wu return __sysret(sys_symlink(old, new)); 1043bd8c8fbbSWilly Tarreau } 1044bd8c8fbbSWilly Tarreau 1045bd8c8fbbSWilly Tarreau 1046bd8c8fbbSWilly Tarreau /* 1047bd8c8fbbSWilly Tarreau * mode_t umask(mode_t mode); 1048bd8c8fbbSWilly Tarreau */ 1049bd8c8fbbSWilly Tarreau 1050bd8c8fbbSWilly Tarreau static __attribute__((unused)) 1051bd8c8fbbSWilly Tarreau mode_t sys_umask(mode_t mode) 1052bd8c8fbbSWilly Tarreau { 1053bd8c8fbbSWilly Tarreau return my_syscall1(__NR_umask, mode); 1054bd8c8fbbSWilly Tarreau } 1055bd8c8fbbSWilly Tarreau 1056bd8c8fbbSWilly Tarreau static __attribute__((unused)) 1057bd8c8fbbSWilly Tarreau mode_t umask(mode_t mode) 1058bd8c8fbbSWilly Tarreau { 1059bd8c8fbbSWilly Tarreau return sys_umask(mode); 1060bd8c8fbbSWilly Tarreau } 1061bd8c8fbbSWilly Tarreau 1062bd8c8fbbSWilly Tarreau 1063bd8c8fbbSWilly Tarreau /* 1064bd8c8fbbSWilly Tarreau * int umount2(const char *path, int flags); 1065bd8c8fbbSWilly Tarreau */ 1066bd8c8fbbSWilly Tarreau 1067bd8c8fbbSWilly Tarreau static __attribute__((unused)) 1068bd8c8fbbSWilly Tarreau int sys_umount2(const char *path, int flags) 1069bd8c8fbbSWilly Tarreau { 1070bd8c8fbbSWilly Tarreau return my_syscall2(__NR_umount2, path, flags); 1071bd8c8fbbSWilly Tarreau } 1072bd8c8fbbSWilly Tarreau 1073bd8c8fbbSWilly Tarreau static __attribute__((unused)) 1074bd8c8fbbSWilly Tarreau int umount2(const char *path, int flags) 1075bd8c8fbbSWilly Tarreau { 1076d27447bcSZhangjin Wu return __sysret(sys_umount2(path, flags)); 1077bd8c8fbbSWilly Tarreau } 1078bd8c8fbbSWilly Tarreau 1079bd8c8fbbSWilly Tarreau 1080bd8c8fbbSWilly Tarreau /* 1081bd8c8fbbSWilly Tarreau * int unlink(const char *path); 1082bd8c8fbbSWilly Tarreau */ 1083bd8c8fbbSWilly Tarreau 1084bd8c8fbbSWilly Tarreau static __attribute__((unused)) 1085bd8c8fbbSWilly Tarreau int sys_unlink(const char *path) 1086bd8c8fbbSWilly Tarreau { 1087bd8c8fbbSWilly Tarreau #ifdef __NR_unlinkat 1088bd8c8fbbSWilly Tarreau return my_syscall3(__NR_unlinkat, AT_FDCWD, path, 0); 1089bd8c8fbbSWilly Tarreau #elif defined(__NR_unlink) 1090bd8c8fbbSWilly Tarreau return my_syscall1(__NR_unlink, path); 1091bd8c8fbbSWilly Tarreau #else 1092ca50df30SZhangjin Wu return -ENOSYS; 1093bd8c8fbbSWilly Tarreau #endif 1094bd8c8fbbSWilly Tarreau } 1095bd8c8fbbSWilly Tarreau 1096bd8c8fbbSWilly Tarreau static __attribute__((unused)) 1097bd8c8fbbSWilly Tarreau int unlink(const char *path) 1098bd8c8fbbSWilly Tarreau { 1099d27447bcSZhangjin Wu return __sysret(sys_unlink(path)); 1100bd8c8fbbSWilly Tarreau } 1101bd8c8fbbSWilly Tarreau 1102bd8c8fbbSWilly Tarreau 1103bd8c8fbbSWilly Tarreau /* 1104bd8c8fbbSWilly Tarreau * pid_t wait(int *status); 1105bd8c8fbbSWilly Tarreau * pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage); 1106bd8c8fbbSWilly Tarreau * pid_t waitpid(pid_t pid, int *status, int options); 1107bd8c8fbbSWilly Tarreau */ 1108bd8c8fbbSWilly Tarreau 1109bd8c8fbbSWilly Tarreau static __attribute__((unused)) 1110bd8c8fbbSWilly Tarreau pid_t sys_wait4(pid_t pid, int *status, int options, struct rusage *rusage) 1111bd8c8fbbSWilly Tarreau { 11122f98aca8SZhangjin Wu #ifdef __NR_wait4 1113bd8c8fbbSWilly Tarreau return my_syscall4(__NR_wait4, pid, status, options, rusage); 11142f98aca8SZhangjin Wu #else 11152f98aca8SZhangjin Wu return -ENOSYS; 11162f98aca8SZhangjin Wu #endif 1117bd8c8fbbSWilly Tarreau } 1118bd8c8fbbSWilly Tarreau 1119bd8c8fbbSWilly Tarreau static __attribute__((unused)) 1120bd8c8fbbSWilly Tarreau pid_t wait(int *status) 1121bd8c8fbbSWilly Tarreau { 1122d27447bcSZhangjin Wu return __sysret(sys_wait4(-1, status, 0, NULL)); 1123bd8c8fbbSWilly Tarreau } 1124bd8c8fbbSWilly Tarreau 1125bd8c8fbbSWilly Tarreau static __attribute__((unused)) 1126bd8c8fbbSWilly Tarreau pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage) 1127bd8c8fbbSWilly Tarreau { 1128d27447bcSZhangjin Wu return __sysret(sys_wait4(pid, status, options, rusage)); 1129bd8c8fbbSWilly Tarreau } 1130bd8c8fbbSWilly Tarreau 1131bd8c8fbbSWilly Tarreau 1132bd8c8fbbSWilly Tarreau static __attribute__((unused)) 1133bd8c8fbbSWilly Tarreau pid_t waitpid(pid_t pid, int *status, int options) 1134bd8c8fbbSWilly Tarreau { 1135d27447bcSZhangjin Wu return __sysret(sys_wait4(pid, status, options, NULL)); 1136bd8c8fbbSWilly Tarreau } 1137bd8c8fbbSWilly Tarreau 1138bd8c8fbbSWilly Tarreau 1139bd8c8fbbSWilly Tarreau /* 1140bd8c8fbbSWilly Tarreau * ssize_t write(int fd, const void *buf, size_t count); 1141bd8c8fbbSWilly Tarreau */ 1142bd8c8fbbSWilly Tarreau 1143bd8c8fbbSWilly Tarreau static __attribute__((unused)) 1144bd8c8fbbSWilly Tarreau ssize_t sys_write(int fd, const void *buf, size_t count) 1145bd8c8fbbSWilly Tarreau { 1146bd8c8fbbSWilly Tarreau return my_syscall3(__NR_write, fd, buf, count); 1147bd8c8fbbSWilly Tarreau } 1148bd8c8fbbSWilly Tarreau 1149bd8c8fbbSWilly Tarreau static __attribute__((unused)) 1150bd8c8fbbSWilly Tarreau ssize_t write(int fd, const void *buf, size_t count) 1151bd8c8fbbSWilly Tarreau { 1152d27447bcSZhangjin Wu return __sysret(sys_write(fd, buf, count)); 1153bd8c8fbbSWilly Tarreau } 1154bd8c8fbbSWilly Tarreau 1155e8842cf0SThomas Weißschuh 1156e8842cf0SThomas Weißschuh /* 1157e8842cf0SThomas Weißschuh * int memfd_create(const char *name, unsigned int flags); 1158e8842cf0SThomas Weißschuh */ 1159e8842cf0SThomas Weißschuh 1160e8842cf0SThomas Weißschuh static __attribute__((unused)) 1161e8842cf0SThomas Weißschuh int sys_memfd_create(const char *name, unsigned int flags) 1162e8842cf0SThomas Weißschuh { 1163e8842cf0SThomas Weißschuh return my_syscall2(__NR_memfd_create, name, flags); 1164e8842cf0SThomas Weißschuh } 1165e8842cf0SThomas Weißschuh 1166e8842cf0SThomas Weißschuh static __attribute__((unused)) 1167e8842cf0SThomas Weißschuh int memfd_create(const char *name, unsigned int flags) 1168e8842cf0SThomas Weißschuh { 1169d27447bcSZhangjin Wu return __sysret(sys_memfd_create(name, flags)); 1170e8842cf0SThomas Weißschuh } 1171e8842cf0SThomas Weißschuh 117255abdd1fSWilly Tarreau /* make sure to include all global symbols */ 117355abdd1fSWilly Tarreau #include "nolibc.h" 1174bd8c8fbbSWilly Tarreau 1175bd8c8fbbSWilly Tarreau #endif /* _NOLIBC_SYS_H */ 1176