1 /* SPDX-License-Identifier: LGPL-2.1 OR MIT */
3 * Syscall definitions for NOLIBC (those in man(2))
4 * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu>
13 #include <asm/unistd.h>
14 #include <asm/signal.h> /* for SIGCHLD */
15 #include <asm/ioctls.h>
18 #include <linux/loop.h>
19 #include <linux/time.h>
20 #include <linux/auxvec.h>
21 #include <linux/fcntl.h> /* for O_* and AT_* */
22 #include <linux/stat.h> /* for statx() */
23 #include <linux/prctl.h>
24 #include <linux/resource.h>
25 #include <linux/utsname.h>
33 /* Syscall return helper: takes the syscall value in argument and checks for an
34 * error in it. This may only be used with signed returns (int or long), but
35 * not with pointers. An error is any value < 0. When an error is encountered,
36 * -ret is set into errno and -1 is returned. Otherwise the returned value is
37 * passed as-is with its type preserved.
40 #define __sysret(arg) \
42 __typeof__(arg) __sysret_arg = (arg); \
43 (__sysret_arg < 0) /* error ? */ \
44 ? (({ SET_ERRNO(-__sysret_arg); }), -1) /* ret -1 with errno = -arg */ \
45 : __sysret_arg; /* return original value */ \
48 /* Syscall ENOSYS helper: Avoids unused-parameter warnings and provides a
52 static __inline__
int __nolibc_enosys(const char *syscall
, ...)
59 /* Functions in this file only describe syscalls. They're declared static so
60 * that the compiler usually decides to inline them while still being allowed
61 * to pass a pointer to one of their instances. Each syscall exists in two
63 * - the "internal" ones, which matches the raw syscall interface at the
64 * kernel level, which may sometimes slightly differ from the documented
65 * libc-level ones. For example most of them return either a valid value
66 * or -errno. All of these are prefixed with "sys_". They may be called
67 * by non-portable applications if desired.
69 * - the "exported" ones, whose interface must closely match the one
70 * documented in man(2), that applications are supposed to expect. These
71 * ones rely on the internal ones, and set errno.
73 * Each syscall will be defined with the two functions, sorted in alphabetical
74 * order applied to the exported names.
76 * In case of doubt about the relevance of a function here, only those which
77 * set errno should be defined here. Wrappers like those appearing in man(3)
78 * should not be placed here.
83 * int brk(void *addr);
84 * void *sbrk(intptr_t inc)
87 static __attribute__((unused
))
88 void *sys_brk(void *addr
)
90 return (void *)my_syscall1(__NR_brk
, addr
);
93 static __attribute__((unused
))
96 void *ret
= sys_brk(addr
);
105 static __attribute__((unused
))
106 void *sbrk(intptr_t inc
)
108 /* first call to find current end */
109 void *ret
= sys_brk(0);
111 if (ret
&& sys_brk(ret
+ inc
) == ret
+ inc
)
120 * int chdir(const char *path);
123 static __attribute__((unused
))
124 int sys_chdir(const char *path
)
126 return my_syscall1(__NR_chdir
, path
);
129 static __attribute__((unused
))
130 int chdir(const char *path
)
132 return __sysret(sys_chdir(path
));
137 * int chmod(const char *path, mode_t mode);
140 static __attribute__((unused
))
141 int sys_chmod(const char *path
, mode_t mode
)
144 return my_syscall4(__NR_fchmodat
, AT_FDCWD
, path
, mode
, 0);
145 #elif defined(__NR_chmod)
146 return my_syscall2(__NR_chmod
, path
, mode
);
148 return __nolibc_enosys(__func__
, path
, mode
);
152 static __attribute__((unused
))
153 int chmod(const char *path
, mode_t mode
)
155 return __sysret(sys_chmod(path
, mode
));
160 * int chown(const char *path, uid_t owner, gid_t group);
163 static __attribute__((unused
))
164 int sys_chown(const char *path
, uid_t owner
, gid_t group
)
167 return my_syscall5(__NR_fchownat
, AT_FDCWD
, path
, owner
, group
, 0);
168 #elif defined(__NR_chown)
169 return my_syscall3(__NR_chown
, path
, owner
, group
);
171 return __nolibc_enosys(__func__
, path
, owner
, group
);
175 static __attribute__((unused
))
176 int chown(const char *path
, uid_t owner
, gid_t group
)
178 return __sysret(sys_chown(path
, owner
, group
));
183 * int chroot(const char *path);
186 static __attribute__((unused
))
187 int sys_chroot(const char *path
)
189 return my_syscall1(__NR_chroot
, path
);
192 static __attribute__((unused
))
193 int chroot(const char *path
)
195 return __sysret(sys_chroot(path
));
203 static __attribute__((unused
))
204 int sys_close(int fd
)
206 return my_syscall1(__NR_close
, fd
);
209 static __attribute__((unused
))
212 return __sysret(sys_close(fd
));
220 static __attribute__((unused
))
223 return my_syscall1(__NR_dup
, fd
);
226 static __attribute__((unused
))
229 return __sysret(sys_dup(fd
));
234 * int dup2(int old, int new);
237 static __attribute__((unused
))
238 int sys_dup2(int old
, int new)
241 return my_syscall3(__NR_dup3
, old
, new, 0);
242 #elif defined(__NR_dup2)
243 return my_syscall2(__NR_dup2
, old
, new);
245 return __nolibc_enosys(__func__
, old
, new);
249 static __attribute__((unused
))
250 int dup2(int old
, int new)
252 return __sysret(sys_dup2(old
, new));
257 * int dup3(int old, int new, int flags);
261 static __attribute__((unused
))
262 int sys_dup3(int old
, int new, int flags
)
264 return my_syscall3(__NR_dup3
, old
, new, flags
);
267 static __attribute__((unused
))
268 int dup3(int old
, int new, int flags
)
270 return __sysret(sys_dup3(old
, new, flags
));
276 * int execve(const char *filename, char *const argv[], char *const envp[]);
279 static __attribute__((unused
))
280 int sys_execve(const char *filename
, char *const argv
[], char *const envp
[])
282 return my_syscall3(__NR_execve
, filename
, argv
, envp
);
285 static __attribute__((unused
))
286 int execve(const char *filename
, char *const argv
[], char *const envp
[])
288 return __sysret(sys_execve(filename
, argv
, envp
));
293 * void exit(int status);
296 static __attribute__((noreturn
,unused
))
297 void sys_exit(int status
)
299 my_syscall1(__NR_exit
, status
& 255);
300 while(1); /* shut the "noreturn" warnings. */
303 static __attribute__((noreturn
,unused
))
304 void exit(int status
)
315 static __attribute__((unused
))
319 /* note: some archs only have clone() and not fork(). Different archs
320 * have a different API, but most archs have the flags on first arg and
321 * will not use the rest with no other flag.
323 return my_syscall5(__NR_clone
, SIGCHLD
, 0, 0, 0, 0);
324 #elif defined(__NR_fork)
325 return my_syscall0(__NR_fork
);
327 return __nolibc_enosys(__func__
);
332 static __attribute__((unused
))
335 return __sysret(sys_fork());
343 static __attribute__((unused
))
344 int sys_fsync(int fd
)
346 return my_syscall1(__NR_fsync
, fd
);
349 static __attribute__((unused
))
352 return __sysret(sys_fsync(fd
));
357 * int getdents64(int fd, struct linux_dirent64 *dirp, int count);
360 static __attribute__((unused
))
361 int sys_getdents64(int fd
, struct linux_dirent64
*dirp
, int count
)
363 return my_syscall3(__NR_getdents64
, fd
, dirp
, count
);
366 static __attribute__((unused
))
367 int getdents64(int fd
, struct linux_dirent64
*dirp
, int count
)
369 return __sysret(sys_getdents64(fd
, dirp
, count
));
374 * uid_t geteuid(void);
377 static __attribute__((unused
))
378 uid_t
sys_geteuid(void)
380 #ifdef __NR_geteuid32
381 return my_syscall0(__NR_geteuid32
);
383 return my_syscall0(__NR_geteuid
);
387 static __attribute__((unused
))
390 return sys_geteuid();
395 * pid_t getpgid(pid_t pid);
398 static __attribute__((unused
))
399 pid_t
sys_getpgid(pid_t pid
)
401 return my_syscall1(__NR_getpgid
, pid
);
404 static __attribute__((unused
))
405 pid_t
getpgid(pid_t pid
)
407 return __sysret(sys_getpgid(pid
));
412 * pid_t getpgrp(void);
415 static __attribute__((unused
))
416 pid_t
sys_getpgrp(void)
418 return sys_getpgid(0);
421 static __attribute__((unused
))
424 return sys_getpgrp();
429 * pid_t getpid(void);
432 static __attribute__((unused
))
433 pid_t
sys_getpid(void)
435 return my_syscall0(__NR_getpid
);
438 static __attribute__((unused
))
446 * pid_t getppid(void);
449 static __attribute__((unused
))
450 pid_t
sys_getppid(void)
452 return my_syscall0(__NR_getppid
);
455 static __attribute__((unused
))
458 return sys_getppid();
463 * pid_t gettid(void);
466 static __attribute__((unused
))
467 pid_t
sys_gettid(void)
469 return my_syscall0(__NR_gettid
);
472 static __attribute__((unused
))
478 static unsigned long getauxval(unsigned long key
);
481 * int getpagesize(void);
484 static __attribute__((unused
))
485 int getpagesize(void)
487 return __sysret((int)getauxval(AT_PAGESZ
) ?: -ENOENT
);
492 * int gettimeofday(struct timeval *tv, struct timezone *tz);
495 static __attribute__((unused
))
496 int sys_gettimeofday(struct timeval
*tv
, struct timezone
*tz
)
498 #ifdef __NR_gettimeofday
499 return my_syscall2(__NR_gettimeofday
, tv
, tz
);
501 return __nolibc_enosys(__func__
, tv
, tz
);
505 static __attribute__((unused
))
506 int gettimeofday(struct timeval
*tv
, struct timezone
*tz
)
508 return __sysret(sys_gettimeofday(tv
, tz
));
513 * uid_t getuid(void);
516 static __attribute__((unused
))
517 uid_t
sys_getuid(void)
520 return my_syscall0(__NR_getuid32
);
522 return my_syscall0(__NR_getuid
);
526 static __attribute__((unused
))
534 * int ioctl(int fd, unsigned long req, void *value);
537 static __attribute__((unused
))
538 int sys_ioctl(int fd
, unsigned long req
, void *value
)
540 return my_syscall3(__NR_ioctl
, fd
, req
, value
);
543 static __attribute__((unused
))
544 int ioctl(int fd
, unsigned long req
, void *value
)
546 return __sysret(sys_ioctl(fd
, req
, value
));
550 * int kill(pid_t pid, int signal);
553 static __attribute__((unused
))
554 int sys_kill(pid_t pid
, int signal
)
556 return my_syscall2(__NR_kill
, pid
, signal
);
559 static __attribute__((unused
))
560 int kill(pid_t pid
, int signal
)
562 return __sysret(sys_kill(pid
, signal
));
567 * int link(const char *old, const char *new);
570 static __attribute__((unused
))
571 int sys_link(const char *old
, const char *new)
574 return my_syscall5(__NR_linkat
, AT_FDCWD
, old
, AT_FDCWD
, new, 0);
575 #elif defined(__NR_link)
576 return my_syscall2(__NR_link
, old
, new);
578 return __nolibc_enosys(__func__
, old
, new);
582 static __attribute__((unused
))
583 int link(const char *old
, const char *new)
585 return __sysret(sys_link(old
, new));
590 * off_t lseek(int fd, off_t offset, int whence);
593 static __attribute__((unused
))
594 off_t
sys_lseek(int fd
, off_t offset
, int whence
)
597 return my_syscall3(__NR_lseek
, fd
, offset
, whence
);
599 return __nolibc_enosys(__func__
, fd
, offset
, whence
);
603 static __attribute__((unused
))
604 off_t
lseek(int fd
, off_t offset
, int whence
)
606 return __sysret(sys_lseek(fd
, offset
, whence
));
611 * int mkdir(const char *path, mode_t mode);
614 static __attribute__((unused
))
615 int sys_mkdir(const char *path
, mode_t mode
)
618 return my_syscall3(__NR_mkdirat
, AT_FDCWD
, path
, mode
);
619 #elif defined(__NR_mkdir)
620 return my_syscall2(__NR_mkdir
, path
, mode
);
622 return __nolibc_enosys(__func__
, path
, mode
);
626 static __attribute__((unused
))
627 int mkdir(const char *path
, mode_t mode
)
629 return __sysret(sys_mkdir(path
, mode
));
633 * int rmdir(const char *path);
636 static __attribute__((unused
))
637 int sys_rmdir(const char *path
)
640 return my_syscall1(__NR_rmdir
, path
);
641 #elif defined(__NR_unlinkat)
642 return my_syscall3(__NR_unlinkat
, AT_FDCWD
, path
, AT_REMOVEDIR
);
644 return __nolibc_enosys(__func__
, path
);
648 static __attribute__((unused
))
649 int rmdir(const char *path
)
651 return __sysret(sys_rmdir(path
));
656 * int mknod(const char *path, mode_t mode, dev_t dev);
659 static __attribute__((unused
))
660 long sys_mknod(const char *path
, mode_t mode
, dev_t dev
)
663 return my_syscall4(__NR_mknodat
, AT_FDCWD
, path
, mode
, dev
);
664 #elif defined(__NR_mknod)
665 return my_syscall3(__NR_mknod
, path
, mode
, dev
);
667 return __nolibc_enosys(__func__
, path
, mode
, dev
);
671 static __attribute__((unused
))
672 int mknod(const char *path
, mode_t mode
, dev_t dev
)
674 return __sysret(sys_mknod(path
, mode
, dev
));
678 static __attribute__((unused
))
679 void *sys_mmap(void *addr
, size_t length
, int prot
, int flags
, int fd
,
684 #if defined(__NR_mmap2)
691 return (void *)my_syscall6(n
, addr
, length
, prot
, flags
, fd
, offset
);
695 /* Note that on Linux, MAP_FAILED is -1 so we can use the generic __sysret()
696 * which returns -1 upon error and still satisfy user land that checks for
700 static __attribute__((unused
))
701 void *mmap(void *addr
, size_t length
, int prot
, int flags
, int fd
, off_t offset
)
703 void *ret
= sys_mmap(addr
, length
, prot
, flags
, fd
, offset
);
705 if ((unsigned long)ret
>= -4095UL) {
706 SET_ERRNO(-(long)ret
);
712 static __attribute__((unused
))
713 int sys_munmap(void *addr
, size_t length
)
715 return my_syscall2(__NR_munmap
, addr
, length
);
718 static __attribute__((unused
))
719 int munmap(void *addr
, size_t length
)
721 return __sysret(sys_munmap(addr
, length
));
725 * int mount(const char *source, const char *target,
726 * const char *fstype, unsigned long flags,
729 static __attribute__((unused
))
730 int sys_mount(const char *src
, const char *tgt
, const char *fst
,
731 unsigned long flags
, const void *data
)
733 return my_syscall5(__NR_mount
, src
, tgt
, fst
, flags
, data
);
736 static __attribute__((unused
))
737 int mount(const char *src
, const char *tgt
,
738 const char *fst
, unsigned long flags
,
741 return __sysret(sys_mount(src
, tgt
, fst
, flags
, data
));
746 * int open(const char *path, int flags[, mode_t mode]);
749 static __attribute__((unused
))
750 int sys_open(const char *path
, int flags
, mode_t mode
)
753 return my_syscall4(__NR_openat
, AT_FDCWD
, path
, flags
, mode
);
754 #elif defined(__NR_open)
755 return my_syscall3(__NR_open
, path
, flags
, mode
);
757 return __nolibc_enosys(__func__
, path
, flags
, mode
);
761 static __attribute__((unused
))
762 int open(const char *path
, int flags
, ...)
766 if (flags
& O_CREAT
) {
769 va_start(args
, flags
);
770 mode
= va_arg(args
, int);
774 return __sysret(sys_open(path
, flags
, mode
));
779 * int pipe2(int pipefd[2], int flags);
780 * int pipe(int pipefd[2]);
783 static __attribute__((unused
))
784 int sys_pipe2(int pipefd
[2], int flags
)
786 return my_syscall2(__NR_pipe2
, pipefd
, flags
);
789 static __attribute__((unused
))
790 int pipe2(int pipefd
[2], int flags
)
792 return __sysret(sys_pipe2(pipefd
, flags
));
795 static __attribute__((unused
))
796 int pipe(int pipefd
[2])
798 return pipe2(pipefd
, 0);
803 * int prctl(int option, unsigned long arg2, unsigned long arg3,
804 * unsigned long arg4, unsigned long arg5);
807 static __attribute__((unused
))
808 int sys_prctl(int option
, unsigned long arg2
, unsigned long arg3
,
809 unsigned long arg4
, unsigned long arg5
)
811 return my_syscall5(__NR_prctl
, option
, arg2
, arg3
, arg4
, arg5
);
814 static __attribute__((unused
))
815 int prctl(int option
, unsigned long arg2
, unsigned long arg3
,
816 unsigned long arg4
, unsigned long arg5
)
818 return __sysret(sys_prctl(option
, arg2
, arg3
, arg4
, arg5
));
823 * int pivot_root(const char *new, const char *old);
826 static __attribute__((unused
))
827 int sys_pivot_root(const char *new, const char *old
)
829 return my_syscall2(__NR_pivot_root
, new, old
);
832 static __attribute__((unused
))
833 int pivot_root(const char *new, const char *old
)
835 return __sysret(sys_pivot_root(new, old
));
840 * int poll(struct pollfd *fds, int nfds, int timeout);
843 static __attribute__((unused
))
844 int sys_poll(struct pollfd
*fds
, int nfds
, int timeout
)
846 #if defined(__NR_ppoll)
850 t
.tv_sec
= timeout
/ 1000;
851 t
.tv_nsec
= (timeout
% 1000) * 1000000;
853 return my_syscall5(__NR_ppoll
, fds
, nfds
, (timeout
>= 0) ? &t
: NULL
, NULL
, 0);
854 #elif defined(__NR_poll)
855 return my_syscall3(__NR_poll
, fds
, nfds
, timeout
);
857 return __nolibc_enosys(__func__
, fds
, nfds
, timeout
);
861 static __attribute__((unused
))
862 int poll(struct pollfd
*fds
, int nfds
, int timeout
)
864 return __sysret(sys_poll(fds
, nfds
, timeout
));
869 * ssize_t read(int fd, void *buf, size_t count);
872 static __attribute__((unused
))
873 ssize_t
sys_read(int fd
, void *buf
, size_t count
)
875 return my_syscall3(__NR_read
, fd
, buf
, count
);
878 static __attribute__((unused
))
879 ssize_t
read(int fd
, void *buf
, size_t count
)
881 return __sysret(sys_read(fd
, buf
, count
));
886 * int reboot(int cmd);
887 * <cmd> is among LINUX_REBOOT_CMD_*
890 static __attribute__((unused
))
891 ssize_t
sys_reboot(int magic1
, int magic2
, int cmd
, void *arg
)
893 return my_syscall4(__NR_reboot
, magic1
, magic2
, cmd
, arg
);
896 static __attribute__((unused
))
899 return __sysret(sys_reboot(LINUX_REBOOT_MAGIC1
, LINUX_REBOOT_MAGIC2
, cmd
, 0));
904 * int getrlimit(int resource, struct rlimit *rlim);
905 * int setrlimit(int resource, const struct rlimit *rlim);
908 static __attribute__((unused
))
909 int sys_prlimit64(pid_t pid
, int resource
,
910 const struct rlimit64
*new_limit
, struct rlimit64
*old_limit
)
912 return my_syscall4(__NR_prlimit64
, pid
, resource
, new_limit
, old_limit
);
915 static __attribute__((unused
))
916 int getrlimit(int resource
, struct rlimit
*rlim
)
918 struct rlimit64 rlim64
;
921 ret
= __sysret(sys_prlimit64(0, resource
, NULL
, &rlim64
));
922 rlim
->rlim_cur
= rlim64
.rlim_cur
;
923 rlim
->rlim_max
= rlim64
.rlim_max
;
928 static __attribute__((unused
))
929 int setrlimit(int resource
, const struct rlimit
*rlim
)
931 struct rlimit64 rlim64
= {
932 .rlim_cur
= rlim
->rlim_cur
,
933 .rlim_max
= rlim
->rlim_max
,
936 return __sysret(sys_prlimit64(0, resource
, &rlim64
, NULL
));
941 * int sched_yield(void);
944 static __attribute__((unused
))
945 int sys_sched_yield(void)
947 return my_syscall0(__NR_sched_yield
);
950 static __attribute__((unused
))
951 int sched_yield(void)
953 return __sysret(sys_sched_yield());
958 * int select(int nfds, fd_set *read_fds, fd_set *write_fds,
959 * fd_set *except_fds, struct timeval *timeout);
962 static __attribute__((unused
))
963 int sys_select(int nfds
, fd_set
*rfds
, fd_set
*wfds
, fd_set
*efds
, struct timeval
*timeout
)
965 #if defined(__ARCH_WANT_SYS_OLD_SELECT) && !defined(__NR__newselect)
966 struct sel_arg_struct
{
970 } arg
= { .n
= nfds
, .r
= rfds
, .w
= wfds
, .e
= efds
, .t
= timeout
};
971 return my_syscall1(__NR_select
, &arg
);
972 #elif defined(__NR__newselect)
973 return my_syscall5(__NR__newselect
, nfds
, rfds
, wfds
, efds
, timeout
);
974 #elif defined(__NR_select)
975 return my_syscall5(__NR_select
, nfds
, rfds
, wfds
, efds
, timeout
);
976 #elif defined(__NR_pselect6)
980 t
.tv_sec
= timeout
->tv_sec
;
981 t
.tv_nsec
= timeout
->tv_usec
* 1000;
983 return my_syscall6(__NR_pselect6
, nfds
, rfds
, wfds
, efds
, timeout
? &t
: NULL
, NULL
);
985 return __nolibc_enosys(__func__
, nfds
, rfds
, wfds
, efds
, timeout
);
989 static __attribute__((unused
))
990 int select(int nfds
, fd_set
*rfds
, fd_set
*wfds
, fd_set
*efds
, struct timeval
*timeout
)
992 return __sysret(sys_select(nfds
, rfds
, wfds
, efds
, timeout
));
997 * int setpgid(pid_t pid, pid_t pgid);
1000 static __attribute__((unused
))
1001 int sys_setpgid(pid_t pid
, pid_t pgid
)
1003 return my_syscall2(__NR_setpgid
, pid
, pgid
);
1006 static __attribute__((unused
))
1007 int setpgid(pid_t pid
, pid_t pgid
)
1009 return __sysret(sys_setpgid(pid
, pgid
));
1014 * pid_t setsid(void);
1017 static __attribute__((unused
))
1018 pid_t
sys_setsid(void)
1020 return my_syscall0(__NR_setsid
);
1023 static __attribute__((unused
))
1026 return __sysret(sys_setsid());
1030 * int statx(int fd, const char *path, int flags, unsigned int mask, struct statx *buf);
1031 * int stat(const char *path, struct stat *buf);
1034 static __attribute__((unused
))
1035 int sys_statx(int fd
, const char *path
, int flags
, unsigned int mask
, struct statx
*buf
)
1038 return my_syscall5(__NR_statx
, fd
, path
, flags
, mask
, buf
);
1040 return __nolibc_enosys(__func__
, fd
, path
, flags
, mask
, buf
);
1044 static __attribute__((unused
))
1045 int statx(int fd
, const char *path
, int flags
, unsigned int mask
, struct statx
*buf
)
1047 return __sysret(sys_statx(fd
, path
, flags
, mask
, buf
));
1051 static __attribute__((unused
))
1052 int stat(const char *path
, struct stat
*buf
)
1057 ret
= __sysret(sys_statx(AT_FDCWD
, path
, AT_NO_AUTOMOUNT
, STATX_BASIC_STATS
, &statx
));
1061 buf
->st_dev
= ((statx
.stx_dev_minor
& 0xff)
1062 | (statx
.stx_dev_major
<< 8)
1063 | ((statx
.stx_dev_minor
& ~0xff) << 12));
1064 buf
->st_ino
= statx
.stx_ino
;
1065 buf
->st_mode
= statx
.stx_mode
;
1066 buf
->st_nlink
= statx
.stx_nlink
;
1067 buf
->st_uid
= statx
.stx_uid
;
1068 buf
->st_gid
= statx
.stx_gid
;
1069 buf
->st_rdev
= ((statx
.stx_rdev_minor
& 0xff)
1070 | (statx
.stx_rdev_major
<< 8)
1071 | ((statx
.stx_rdev_minor
& ~0xff) << 12));
1072 buf
->st_size
= statx
.stx_size
;
1073 buf
->st_blksize
= statx
.stx_blksize
;
1074 buf
->st_blocks
= statx
.stx_blocks
;
1075 buf
->st_atim
.tv_sec
= statx
.stx_atime
.tv_sec
;
1076 buf
->st_atim
.tv_nsec
= statx
.stx_atime
.tv_nsec
;
1077 buf
->st_mtim
.tv_sec
= statx
.stx_mtime
.tv_sec
;
1078 buf
->st_mtim
.tv_nsec
= statx
.stx_mtime
.tv_nsec
;
1079 buf
->st_ctim
.tv_sec
= statx
.stx_ctime
.tv_sec
;
1080 buf
->st_ctim
.tv_nsec
= statx
.stx_ctime
.tv_nsec
;
1087 * int symlink(const char *old, const char *new);
1090 static __attribute__((unused
))
1091 int sys_symlink(const char *old
, const char *new)
1093 #ifdef __NR_symlinkat
1094 return my_syscall3(__NR_symlinkat
, old
, AT_FDCWD
, new);
1095 #elif defined(__NR_symlink)
1096 return my_syscall2(__NR_symlink
, old
, new);
1098 return __nolibc_enosys(__func__
, old
, new);
1102 static __attribute__((unused
))
1103 int symlink(const char *old
, const char *new)
1105 return __sysret(sys_symlink(old
, new));
1110 * mode_t umask(mode_t mode);
1113 static __attribute__((unused
))
1114 mode_t
sys_umask(mode_t mode
)
1116 return my_syscall1(__NR_umask
, mode
);
1119 static __attribute__((unused
))
1120 mode_t
umask(mode_t mode
)
1122 return sys_umask(mode
);
1127 * int umount2(const char *path, int flags);
1130 static __attribute__((unused
))
1131 int sys_umount2(const char *path
, int flags
)
1133 return my_syscall2(__NR_umount2
, path
, flags
);
1136 static __attribute__((unused
))
1137 int umount2(const char *path
, int flags
)
1139 return __sysret(sys_umount2(path
, flags
));
1144 * int uname(struct utsname *buf);
1153 char domainname
[65];
1156 static __attribute__((unused
))
1157 int sys_uname(struct utsname
*buf
)
1159 return my_syscall1(__NR_uname
, buf
);
1162 static __attribute__((unused
))
1163 int uname(struct utsname
*buf
)
1165 return __sysret(sys_uname(buf
));
1170 * int unlink(const char *path);
1173 static __attribute__((unused
))
1174 int sys_unlink(const char *path
)
1176 #ifdef __NR_unlinkat
1177 return my_syscall3(__NR_unlinkat
, AT_FDCWD
, path
, 0);
1178 #elif defined(__NR_unlink)
1179 return my_syscall1(__NR_unlink
, path
);
1181 return __nolibc_enosys(__func__
, path
);
1185 static __attribute__((unused
))
1186 int unlink(const char *path
)
1188 return __sysret(sys_unlink(path
));
1193 * pid_t wait(int *status);
1194 * pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage);
1195 * pid_t waitpid(pid_t pid, int *status, int options);
1198 static __attribute__((unused
))
1199 pid_t
sys_wait4(pid_t pid
, int *status
, int options
, struct rusage
*rusage
)
1202 return my_syscall4(__NR_wait4
, pid
, status
, options
, rusage
);
1204 return __nolibc_enosys(__func__
, pid
, status
, options
, rusage
);
1208 static __attribute__((unused
))
1209 pid_t
wait(int *status
)
1211 return __sysret(sys_wait4(-1, status
, 0, NULL
));
1214 static __attribute__((unused
))
1215 pid_t
wait4(pid_t pid
, int *status
, int options
, struct rusage
*rusage
)
1217 return __sysret(sys_wait4(pid
, status
, options
, rusage
));
1221 static __attribute__((unused
))
1222 pid_t
waitpid(pid_t pid
, int *status
, int options
)
1224 return __sysret(sys_wait4(pid
, status
, options
, NULL
));
1229 * ssize_t write(int fd, const void *buf, size_t count);
1232 static __attribute__((unused
))
1233 ssize_t
sys_write(int fd
, const void *buf
, size_t count
)
1235 return my_syscall3(__NR_write
, fd
, buf
, count
);
1238 static __attribute__((unused
))
1239 ssize_t
write(int fd
, const void *buf
, size_t count
)
1241 return __sysret(sys_write(fd
, buf
, count
));
1246 * int memfd_create(const char *name, unsigned int flags);
1249 static __attribute__((unused
))
1250 int sys_memfd_create(const char *name
, unsigned int flags
)
1252 return my_syscall2(__NR_memfd_create
, name
, flags
);
1255 static __attribute__((unused
))
1256 int memfd_create(const char *name
, unsigned int flags
)
1258 return __sysret(sys_memfd_create(name
, flags
));
1261 /* make sure to include all global symbols */
1264 #endif /* _NOLIBC_SYS_H */