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>
32 /* Syscall return helper: takes the syscall value in argument and checks for an
33 * error in it. This may only be used with signed returns (int or long), but
34 * not with pointers. An error is any value < 0. When an error is encountered,
35 * -ret is set into errno and -1 is returned. Otherwise the returned value is
36 * passed as-is with its type preserved.
39 #define __sysret(arg) \
41 __typeof__(arg) __sysret_arg = (arg); \
42 (__sysret_arg < 0) /* error ? */ \
43 ? (({ SET_ERRNO(-__sysret_arg); }), -1) /* ret -1 with errno = -arg */ \
44 : __sysret_arg; /* return original value */ \
47 /* Syscall ENOSYS helper: Avoids unused-parameter warnings and provides a
51 static __inline__ int __nolibc_enosys(const char *syscall, ...)
58 /* Functions in this file only describe syscalls. They're declared static so
59 * that the compiler usually decides to inline them while still being allowed
60 * to pass a pointer to one of their instances. Each syscall exists in two
62 * - the "internal" ones, which matches the raw syscall interface at the
63 * kernel level, which may sometimes slightly differ from the documented
64 * libc-level ones. For example most of them return either a valid value
65 * or -errno. All of these are prefixed with "sys_". They may be called
66 * by non-portable applications if desired.
68 * - the "exported" ones, whose interface must closely match the one
69 * documented in man(2), that applications are supposed to expect. These
70 * ones rely on the internal ones, and set errno.
72 * Each syscall will be defined with the two functions, sorted in alphabetical
73 * order applied to the exported names.
75 * In case of doubt about the relevance of a function here, only those which
76 * set errno should be defined here. Wrappers like those appearing in man(3)
77 * should not be placed here.
82 * int brk(void *addr);
83 * void *sbrk(intptr_t inc)
86 static __attribute__((unused))
87 void *sys_brk(void *addr)
89 return (void *)my_syscall1(__NR_brk, addr);
92 static __attribute__((unused))
95 void *ret = sys_brk(addr);
104 static __attribute__((unused))
105 void *sbrk(intptr_t inc)
107 /* first call to find current end */
108 void *ret = sys_brk(0);
110 if (ret && sys_brk(ret + inc) == ret + inc)
119 * int chdir(const char *path);
122 static __attribute__((unused))
123 int sys_chdir(const char *path)
125 return my_syscall1(__NR_chdir, path);
128 static __attribute__((unused))
129 int chdir(const char *path)
131 return __sysret(sys_chdir(path));
136 * int chmod(const char *path, mode_t mode);
139 static __attribute__((unused))
140 int sys_chmod(const char *path, mode_t mode)
143 return my_syscall4(__NR_fchmodat, AT_FDCWD, path, mode, 0);
144 #elif defined(__NR_chmod)
145 return my_syscall2(__NR_chmod, path, mode);
147 return __nolibc_enosys(__func__, path, mode);
151 static __attribute__((unused))
152 int chmod(const char *path, mode_t mode)
154 return __sysret(sys_chmod(path, mode));
159 * int chown(const char *path, uid_t owner, gid_t group);
162 static __attribute__((unused))
163 int sys_chown(const char *path, uid_t owner, gid_t group)
166 return my_syscall5(__NR_fchownat, AT_FDCWD, path, owner, group, 0);
167 #elif defined(__NR_chown)
168 return my_syscall3(__NR_chown, path, owner, group);
170 return __nolibc_enosys(__func__, path, owner, group);
174 static __attribute__((unused))
175 int chown(const char *path, uid_t owner, gid_t group)
177 return __sysret(sys_chown(path, owner, group));
182 * int chroot(const char *path);
185 static __attribute__((unused))
186 int sys_chroot(const char *path)
188 return my_syscall1(__NR_chroot, path);
191 static __attribute__((unused))
192 int chroot(const char *path)
194 return __sysret(sys_chroot(path));
202 static __attribute__((unused))
203 int sys_close(int fd)
205 return my_syscall1(__NR_close, fd);
208 static __attribute__((unused))
211 return __sysret(sys_close(fd));
219 static __attribute__((unused))
222 return my_syscall1(__NR_dup, fd);
225 static __attribute__((unused))
228 return __sysret(sys_dup(fd));
233 * int dup2(int old, int new);
236 static __attribute__((unused))
237 int sys_dup2(int old, int new)
240 return my_syscall3(__NR_dup3, old, new, 0);
241 #elif defined(__NR_dup2)
242 return my_syscall2(__NR_dup2, old, new);
244 return __nolibc_enosys(__func__, old, new);
248 static __attribute__((unused))
249 int dup2(int old, int new)
251 return __sysret(sys_dup2(old, new));
256 * int dup3(int old, int new, int flags);
260 static __attribute__((unused))
261 int sys_dup3(int old, int new, int flags)
263 return my_syscall3(__NR_dup3, old, new, flags);
266 static __attribute__((unused))
267 int dup3(int old, int new, int flags)
269 return __sysret(sys_dup3(old, new, flags));
275 * int execve(const char *filename, char *const argv[], char *const envp[]);
278 static __attribute__((unused))
279 int sys_execve(const char *filename, char *const argv[], char *const envp[])
281 return my_syscall3(__NR_execve, filename, argv, envp);
284 static __attribute__((unused))
285 int execve(const char *filename, char *const argv[], char *const envp[])
287 return __sysret(sys_execve(filename, argv, envp));
292 * void exit(int status);
295 static __attribute__((noreturn,unused))
296 void sys_exit(int status)
298 my_syscall1(__NR_exit, status & 255);
299 while(1); /* shut the "noreturn" warnings. */
302 static __attribute__((noreturn,unused))
303 void exit(int status)
314 static __attribute__((unused))
318 /* note: some archs only have clone() and not fork(). Different archs
319 * have a different API, but most archs have the flags on first arg and
320 * will not use the rest with no other flag.
322 return my_syscall5(__NR_clone, SIGCHLD, 0, 0, 0, 0);
323 #elif defined(__NR_fork)
324 return my_syscall0(__NR_fork);
326 return __nolibc_enosys(__func__);
331 static __attribute__((unused))
334 return __sysret(sys_fork());
342 static __attribute__((unused))
343 int sys_fsync(int fd)
345 return my_syscall1(__NR_fsync, fd);
348 static __attribute__((unused))
351 return __sysret(sys_fsync(fd));
356 * int getdents64(int fd, struct linux_dirent64 *dirp, int count);
359 static __attribute__((unused))
360 int sys_getdents64(int fd, struct linux_dirent64 *dirp, int count)
362 return my_syscall3(__NR_getdents64, fd, dirp, count);
365 static __attribute__((unused))
366 int getdents64(int fd, struct linux_dirent64 *dirp, int count)
368 return __sysret(sys_getdents64(fd, dirp, count));
373 * uid_t geteuid(void);
376 static __attribute__((unused))
377 uid_t sys_geteuid(void)
379 #ifdef __NR_geteuid32
380 return my_syscall0(__NR_geteuid32);
382 return my_syscall0(__NR_geteuid);
386 static __attribute__((unused))
389 return sys_geteuid();
394 * pid_t getpgid(pid_t pid);
397 static __attribute__((unused))
398 pid_t sys_getpgid(pid_t pid)
400 return my_syscall1(__NR_getpgid, pid);
403 static __attribute__((unused))
404 pid_t getpgid(pid_t pid)
406 return __sysret(sys_getpgid(pid));
411 * pid_t getpgrp(void);
414 static __attribute__((unused))
415 pid_t sys_getpgrp(void)
417 return sys_getpgid(0);
420 static __attribute__((unused))
423 return sys_getpgrp();
428 * pid_t getpid(void);
431 static __attribute__((unused))
432 pid_t sys_getpid(void)
434 return my_syscall0(__NR_getpid);
437 static __attribute__((unused))
445 * pid_t getppid(void);
448 static __attribute__((unused))
449 pid_t sys_getppid(void)
451 return my_syscall0(__NR_getppid);
454 static __attribute__((unused))
457 return sys_getppid();
462 * pid_t gettid(void);
465 static __attribute__((unused))
466 pid_t sys_gettid(void)
468 return my_syscall0(__NR_gettid);
471 static __attribute__((unused))
477 static unsigned long getauxval(unsigned long key);
480 * int getpagesize(void);
483 static __attribute__((unused))
484 int getpagesize(void)
486 return __sysret((int)getauxval(AT_PAGESZ) ?: -ENOENT);
491 * int gettimeofday(struct timeval *tv, struct timezone *tz);
494 static __attribute__((unused))
495 int sys_gettimeofday(struct timeval *tv, struct timezone *tz)
497 #ifdef __NR_gettimeofday
498 return my_syscall2(__NR_gettimeofday, tv, tz);
500 return __nolibc_enosys(__func__, tv, tz);
504 static __attribute__((unused))
505 int gettimeofday(struct timeval *tv, struct timezone *tz)
507 return __sysret(sys_gettimeofday(tv, tz));
512 * uid_t getuid(void);
515 static __attribute__((unused))
516 uid_t sys_getuid(void)
519 return my_syscall0(__NR_getuid32);
521 return my_syscall0(__NR_getuid);
525 static __attribute__((unused))
533 * int ioctl(int fd, unsigned long req, void *value);
536 static __attribute__((unused))
537 int sys_ioctl(int fd, unsigned long req, void *value)
539 return my_syscall3(__NR_ioctl, fd, req, value);
542 static __attribute__((unused))
543 int ioctl(int fd, unsigned long req, void *value)
545 return __sysret(sys_ioctl(fd, req, value));
549 * int kill(pid_t pid, int signal);
552 static __attribute__((unused))
553 int sys_kill(pid_t pid, int signal)
555 return my_syscall2(__NR_kill, pid, signal);
558 static __attribute__((unused))
559 int kill(pid_t pid, int signal)
561 return __sysret(sys_kill(pid, signal));
566 * int link(const char *old, const char *new);
569 static __attribute__((unused))
570 int sys_link(const char *old, const char *new)
573 return my_syscall5(__NR_linkat, AT_FDCWD, old, AT_FDCWD, new, 0);
574 #elif defined(__NR_link)
575 return my_syscall2(__NR_link, old, new);
577 return __nolibc_enosys(__func__, old, new);
581 static __attribute__((unused))
582 int link(const char *old, const char *new)
584 return __sysret(sys_link(old, new));
589 * off_t lseek(int fd, off_t offset, int whence);
592 static __attribute__((unused))
593 off_t sys_lseek(int fd, off_t offset, int whence)
596 return my_syscall3(__NR_lseek, fd, offset, whence);
598 return __nolibc_enosys(__func__, fd, offset, whence);
602 static __attribute__((unused))
603 off_t lseek(int fd, off_t offset, int whence)
605 return __sysret(sys_lseek(fd, offset, whence));
610 * int mkdir(const char *path, mode_t mode);
613 static __attribute__((unused))
614 int sys_mkdir(const char *path, mode_t mode)
617 return my_syscall3(__NR_mkdirat, AT_FDCWD, path, mode);
618 #elif defined(__NR_mkdir)
619 return my_syscall2(__NR_mkdir, path, mode);
621 return __nolibc_enosys(__func__, path, mode);
625 static __attribute__((unused))
626 int mkdir(const char *path, mode_t mode)
628 return __sysret(sys_mkdir(path, mode));
632 * int rmdir(const char *path);
635 static __attribute__((unused))
636 int sys_rmdir(const char *path)
639 return my_syscall1(__NR_rmdir, path);
640 #elif defined(__NR_unlinkat)
641 return my_syscall3(__NR_unlinkat, AT_FDCWD, path, AT_REMOVEDIR);
643 return __nolibc_enosys(__func__, path);
647 static __attribute__((unused))
648 int rmdir(const char *path)
650 return __sysret(sys_rmdir(path));
655 * int mknod(const char *path, mode_t mode, dev_t dev);
658 static __attribute__((unused))
659 long sys_mknod(const char *path, mode_t mode, dev_t dev)
662 return my_syscall4(__NR_mknodat, AT_FDCWD, path, mode, dev);
663 #elif defined(__NR_mknod)
664 return my_syscall3(__NR_mknod, path, mode, dev);
666 return __nolibc_enosys(__func__, path, mode, dev);
670 static __attribute__((unused))
671 int mknod(const char *path, mode_t mode, dev_t dev)
673 return __sysret(sys_mknod(path, mode, dev));
677 static __attribute__((unused))
678 void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd,
683 #if defined(__NR_mmap2)
690 return (void *)my_syscall6(n, addr, length, prot, flags, fd, offset);
694 /* Note that on Linux, MAP_FAILED is -1 so we can use the generic __sysret()
695 * which returns -1 upon error and still satisfy user land that checks for
699 static __attribute__((unused))
700 void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
702 void *ret = sys_mmap(addr, length, prot, flags, fd, offset);
704 if ((unsigned long)ret >= -4095UL) {
705 SET_ERRNO(-(long)ret);
711 static __attribute__((unused))
712 int sys_munmap(void *addr, size_t length)
714 return my_syscall2(__NR_munmap, addr, length);
717 static __attribute__((unused))
718 int munmap(void *addr, size_t length)
720 return __sysret(sys_munmap(addr, length));
724 * int mount(const char *source, const char *target,
725 * const char *fstype, unsigned long flags,
728 static __attribute__((unused))
729 int sys_mount(const char *src, const char *tgt, const char *fst,
730 unsigned long flags, const void *data)
732 return my_syscall5(__NR_mount, src, tgt, fst, flags, data);
735 static __attribute__((unused))
736 int mount(const char *src, const char *tgt,
737 const char *fst, unsigned long flags,
740 return __sysret(sys_mount(src, tgt, fst, flags, data));
745 * int open(const char *path, int flags[, mode_t mode]);
748 static __attribute__((unused))
749 int sys_open(const char *path, int flags, mode_t mode)
752 return my_syscall4(__NR_openat, AT_FDCWD, path, flags, mode);
753 #elif defined(__NR_open)
754 return my_syscall3(__NR_open, path, flags, mode);
756 return __nolibc_enosys(__func__, path, flags, mode);
760 static __attribute__((unused))
761 int open(const char *path, int flags, ...)
765 if (flags & O_CREAT) {
768 va_start(args, flags);
769 mode = va_arg(args, int);
773 return __sysret(sys_open(path, flags, mode));
778 * int pipe2(int pipefd[2], int flags);
779 * int pipe(int pipefd[2]);
782 static __attribute__((unused))
783 int sys_pipe2(int pipefd[2], int flags)
785 return my_syscall2(__NR_pipe2, pipefd, flags);
788 static __attribute__((unused))
789 int pipe2(int pipefd[2], int flags)
791 return __sysret(sys_pipe2(pipefd, flags));
794 static __attribute__((unused))
795 int pipe(int pipefd[2])
797 return pipe2(pipefd, 0);
802 * int prctl(int option, unsigned long arg2, unsigned long arg3,
803 * unsigned long arg4, unsigned long arg5);
806 static __attribute__((unused))
807 int sys_prctl(int option, unsigned long arg2, unsigned long arg3,
808 unsigned long arg4, unsigned long arg5)
810 return my_syscall5(__NR_prctl, option, arg2, arg3, arg4, arg5);
813 static __attribute__((unused))
814 int prctl(int option, unsigned long arg2, unsigned long arg3,
815 unsigned long arg4, unsigned long arg5)
817 return __sysret(sys_prctl(option, arg2, arg3, arg4, arg5));
822 * int pivot_root(const char *new, const char *old);
825 static __attribute__((unused))
826 int sys_pivot_root(const char *new, const char *old)
828 return my_syscall2(__NR_pivot_root, new, old);
831 static __attribute__((unused))
832 int pivot_root(const char *new, const char *old)
834 return __sysret(sys_pivot_root(new, old));
839 * int poll(struct pollfd *fds, int nfds, int timeout);
842 static __attribute__((unused))
843 int sys_poll(struct pollfd *fds, int nfds, int timeout)
845 #if defined(__NR_ppoll)
849 t.tv_sec = timeout / 1000;
850 t.tv_nsec = (timeout % 1000) * 1000000;
852 return my_syscall5(__NR_ppoll, fds, nfds, (timeout >= 0) ? &t : NULL, NULL, 0);
853 #elif defined(__NR_poll)
854 return my_syscall3(__NR_poll, fds, nfds, timeout);
856 return __nolibc_enosys(__func__, fds, nfds, timeout);
860 static __attribute__((unused))
861 int poll(struct pollfd *fds, int nfds, int timeout)
863 return __sysret(sys_poll(fds, nfds, timeout));
868 * ssize_t read(int fd, void *buf, size_t count);
871 static __attribute__((unused))
872 ssize_t sys_read(int fd, void *buf, size_t count)
874 return my_syscall3(__NR_read, fd, buf, count);
877 static __attribute__((unused))
878 ssize_t read(int fd, void *buf, size_t count)
880 return __sysret(sys_read(fd, buf, count));
885 * int reboot(int cmd);
886 * <cmd> is among LINUX_REBOOT_CMD_*
889 static __attribute__((unused))
890 ssize_t sys_reboot(int magic1, int magic2, int cmd, void *arg)
892 return my_syscall4(__NR_reboot, magic1, magic2, cmd, arg);
895 static __attribute__((unused))
898 return __sysret(sys_reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, cmd, 0));
903 * int getrlimit(int resource, struct rlimit *rlim);
904 * int setrlimit(int resource, const struct rlimit *rlim);
907 static __attribute__((unused))
908 int sys_prlimit64(pid_t pid, int resource,
909 const struct rlimit64 *new_limit, struct rlimit64 *old_limit)
911 return my_syscall4(__NR_prlimit64, pid, resource, new_limit, old_limit);
914 static __attribute__((unused))
915 int getrlimit(int resource, struct rlimit *rlim)
917 struct rlimit64 rlim64;
920 ret = __sysret(sys_prlimit64(0, resource, NULL, &rlim64));
921 rlim->rlim_cur = rlim64.rlim_cur;
922 rlim->rlim_max = rlim64.rlim_max;
927 static __attribute__((unused))
928 int setrlimit(int resource, const struct rlimit *rlim)
930 struct rlimit64 rlim64 = {
931 .rlim_cur = rlim->rlim_cur,
932 .rlim_max = rlim->rlim_max,
935 return __sysret(sys_prlimit64(0, resource, &rlim64, NULL));
940 * int sched_yield(void);
943 static __attribute__((unused))
944 int sys_sched_yield(void)
946 return my_syscall0(__NR_sched_yield);
949 static __attribute__((unused))
950 int sched_yield(void)
952 return __sysret(sys_sched_yield());
957 * int select(int nfds, fd_set *read_fds, fd_set *write_fds,
958 * fd_set *except_fds, struct timeval *timeout);
961 static __attribute__((unused))
962 int sys_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *timeout)
964 #if defined(__ARCH_WANT_SYS_OLD_SELECT) && !defined(__NR__newselect)
965 struct sel_arg_struct {
969 } arg = { .n = nfds, .r = rfds, .w = wfds, .e = efds, .t = timeout };
970 return my_syscall1(__NR_select, &arg);
971 #elif defined(__NR__newselect)
972 return my_syscall5(__NR__newselect, nfds, rfds, wfds, efds, timeout);
973 #elif defined(__NR_select)
974 return my_syscall5(__NR_select, nfds, rfds, wfds, efds, timeout);
975 #elif defined(__NR_pselect6)
979 t.tv_sec = timeout->tv_sec;
980 t.tv_nsec = timeout->tv_usec * 1000;
982 return my_syscall6(__NR_pselect6, nfds, rfds, wfds, efds, timeout ? &t : NULL, NULL);
984 return __nolibc_enosys(__func__, nfds, rfds, wfds, efds, timeout);
988 static __attribute__((unused))
989 int select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *timeout)
991 return __sysret(sys_select(nfds, rfds, wfds, efds, timeout));
996 * int setpgid(pid_t pid, pid_t pgid);
999 static __attribute__((unused))
1000 int sys_setpgid(pid_t pid, pid_t pgid)
1002 return my_syscall2(__NR_setpgid, pid, pgid);
1005 static __attribute__((unused))
1006 int setpgid(pid_t pid, pid_t pgid)
1008 return __sysret(sys_setpgid(pid, pgid));
1013 * pid_t setsid(void);
1016 static __attribute__((unused))
1017 pid_t sys_setsid(void)
1019 return my_syscall0(__NR_setsid);
1022 static __attribute__((unused))
1025 return __sysret(sys_setsid());
1029 * int statx(int fd, const char *path, int flags, unsigned int mask, struct statx *buf);
1030 * int stat(const char *path, struct stat *buf);
1033 static __attribute__((unused))
1034 int sys_statx(int fd, const char *path, int flags, unsigned int mask, struct statx *buf)
1037 return my_syscall5(__NR_statx, fd, path, flags, mask, buf);
1039 return __nolibc_enosys(__func__, fd, path, flags, mask, buf);
1043 static __attribute__((unused))
1044 int statx(int fd, const char *path, int flags, unsigned int mask, struct statx *buf)
1046 return __sysret(sys_statx(fd, path, flags, mask, buf));
1050 static __attribute__((unused))
1051 int stat(const char *path, struct stat *buf)
1056 ret = __sysret(sys_statx(AT_FDCWD, path, AT_NO_AUTOMOUNT, STATX_BASIC_STATS, &statx));
1060 buf->st_dev = ((statx.stx_dev_minor & 0xff)
1061 | (statx.stx_dev_major << 8)
1062 | ((statx.stx_dev_minor & ~0xff) << 12));
1063 buf->st_ino = statx.stx_ino;
1064 buf->st_mode = statx.stx_mode;
1065 buf->st_nlink = statx.stx_nlink;
1066 buf->st_uid = statx.stx_uid;
1067 buf->st_gid = statx.stx_gid;
1068 buf->st_rdev = ((statx.stx_rdev_minor & 0xff)
1069 | (statx.stx_rdev_major << 8)
1070 | ((statx.stx_rdev_minor & ~0xff) << 12));
1071 buf->st_size = statx.stx_size;
1072 buf->st_blksize = statx.stx_blksize;
1073 buf->st_blocks = statx.stx_blocks;
1074 buf->st_atim.tv_sec = statx.stx_atime.tv_sec;
1075 buf->st_atim.tv_nsec = statx.stx_atime.tv_nsec;
1076 buf->st_mtim.tv_sec = statx.stx_mtime.tv_sec;
1077 buf->st_mtim.tv_nsec = statx.stx_mtime.tv_nsec;
1078 buf->st_ctim.tv_sec = statx.stx_ctime.tv_sec;
1079 buf->st_ctim.tv_nsec = statx.stx_ctime.tv_nsec;
1086 * int symlink(const char *old, const char *new);
1089 static __attribute__((unused))
1090 int sys_symlink(const char *old, const char *new)
1092 #ifdef __NR_symlinkat
1093 return my_syscall3(__NR_symlinkat, old, AT_FDCWD, new);
1094 #elif defined(__NR_symlink)
1095 return my_syscall2(__NR_symlink, old, new);
1097 return __nolibc_enosys(__func__, old, new);
1101 static __attribute__((unused))
1102 int symlink(const char *old, const char *new)
1104 return __sysret(sys_symlink(old, new));
1109 * mode_t umask(mode_t mode);
1112 static __attribute__((unused))
1113 mode_t sys_umask(mode_t mode)
1115 return my_syscall1(__NR_umask, mode);
1118 static __attribute__((unused))
1119 mode_t umask(mode_t mode)
1121 return sys_umask(mode);
1126 * int umount2(const char *path, int flags);
1129 static __attribute__((unused))
1130 int sys_umount2(const char *path, int flags)
1132 return my_syscall2(__NR_umount2, path, flags);
1135 static __attribute__((unused))
1136 int umount2(const char *path, int flags)
1138 return __sysret(sys_umount2(path, flags));
1143 * int unlink(const char *path);
1146 static __attribute__((unused))
1147 int sys_unlink(const char *path)
1149 #ifdef __NR_unlinkat
1150 return my_syscall3(__NR_unlinkat, AT_FDCWD, path, 0);
1151 #elif defined(__NR_unlink)
1152 return my_syscall1(__NR_unlink, path);
1154 return __nolibc_enosys(__func__, path);
1158 static __attribute__((unused))
1159 int unlink(const char *path)
1161 return __sysret(sys_unlink(path));
1166 * pid_t wait(int *status);
1167 * pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage);
1168 * pid_t waitpid(pid_t pid, int *status, int options);
1171 static __attribute__((unused))
1172 pid_t sys_wait4(pid_t pid, int *status, int options, struct rusage *rusage)
1175 return my_syscall4(__NR_wait4, pid, status, options, rusage);
1177 return __nolibc_enosys(__func__, pid, status, options, rusage);
1181 static __attribute__((unused))
1182 pid_t wait(int *status)
1184 return __sysret(sys_wait4(-1, status, 0, NULL));
1187 static __attribute__((unused))
1188 pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage)
1190 return __sysret(sys_wait4(pid, status, options, rusage));
1194 static __attribute__((unused))
1195 pid_t waitpid(pid_t pid, int *status, int options)
1197 return __sysret(sys_wait4(pid, status, options, NULL));
1202 * ssize_t write(int fd, const void *buf, size_t count);
1205 static __attribute__((unused))
1206 ssize_t sys_write(int fd, const void *buf, size_t count)
1208 return my_syscall3(__NR_write, fd, buf, count);
1211 static __attribute__((unused))
1212 ssize_t write(int fd, const void *buf, size_t count)
1214 return __sysret(sys_write(fd, buf, count));
1219 * int memfd_create(const char *name, unsigned int flags);
1222 static __attribute__((unused))
1223 int sys_memfd_create(const char *name, unsigned int flags)
1225 return my_syscall2(__NR_memfd_create, name, flags);
1228 static __attribute__((unused))
1229 int memfd_create(const char *name, unsigned int flags)
1231 return __sysret(sys_memfd_create(name, flags));
1234 /* make sure to include all global symbols */
1237 #endif /* _NOLIBC_SYS_H */