Pull nolibc updates from Thomas Weißschuh: "Only small bugfixes and cleanups" * tag 'nolibc-20250928-for-6.18-1' of git://git.kernel.org/pub/scm/linux/kernel/git/nolibc/linux-nolibc: tools/nolibc: add stdbool.h to nolibc includes tools/nolibc: make time_t robust if __kernel_old_time_t is missing in host headers selftests/nolibc: remove outdated comment about construct order selftests/nolibc: fix EXPECT_NZ macro tools/nolibc: drop wait4() support kselftest/arm64: tpidr2: Switch to waitpid() over wait4() tools/nolibc: fold llseek fallback into lseek() tools/nolibc: remove __nolibc_enosys() fallback from fork functions tools/nolibc: remove __nolibc_enosys() fallback from dup2() tools/nolibc: remove __nolibc_enosys() fallback from *at() functions tools/nolibc: remove __nolibc_enosys() fallback from time64-related functions tools/nolibc: use tabs instead of spaces for indentation tools/nolibc: avoid error in dup2() if old fd equals new fd selftests/nolibc: always compile the kernel with GCC selftests/nolibc: don't pass CC to toplevel Makefile selftests/nolibc: deduplicate invocations of toplevel Makefile selftests/nolibc: be more specific about variables affecting nolibc-test tools/nolibc: fix error return value of clock_nanosleep()
Showing the changes to tools/include (9 of 12 files). Show all
Unified · Split
| @@ -116,6 +116,7 @@ · 115 unmodified lines | ||
| 116 | 116 | #include "sched.h" |
| 117 | 117 | #include "signal.h" |
| 118 | 118 | #include "unistd.h" |
| 119 | +#include "stdbool.h" | |
| 119 | 120 | #include "stdio.h" |
| 120 | 121 | #include "stdlib.h" |
| 121 | 122 | #include "string.h" |
| @@ -39,10 +39,8 @@ int sys_poll(struct pollfd *fds, int nfds, int timeout) · 38 unmodified lines | ||
| 39 | 39 | t.tv_nsec = (timeout % 1000) * 1000000; |
| 40 | 40 | } |
| 41 | 41 | return my_syscall5(__NR_ppoll_time64, fds, nfds, (timeout >= 0) ? &t : NULL, NULL, 0); |
| 42 | −#elif defined(__NR_poll) | |
| 43 | − return my_syscall3(__NR_poll, fds, nfds, timeout); | |
| 44 | 42 | #else |
| 45 | − return __nolibc_enosys(__func__, fds, nfds, timeout); | |
| 43 | + return my_syscall3(__NR_poll, fds, nfds, timeout); | |
| 46 | 44 | #endif |
| 47 | 45 | } |
| 48 | 46 | |
| @@ -29,6 +29,6 @@ typedef unsigned long nlink_t; · 28 unmodified lines | ||
| 29 | 29 | typedef signed long off_t; |
| 30 | 30 | typedef signed long blksize_t; |
| 31 | 31 | typedef signed long blkcnt_t; |
| 32 | −typedef __kernel_old_time_t time_t; | |
| 32 | +typedef __kernel_time_t time_t; | |
| 33 | 33 | |
| 34 | 34 | #endif /* _NOLIBC_STD_H */ |
| @@ -142,10 +142,8 @@ int sys_chmod(const char *path, mode_t mode) · 141 unmodified lines | ||
| 142 | 142 | { |
| 143 | 143 | #if defined(__NR_fchmodat) |
| 144 | 144 | return my_syscall4(__NR_fchmodat, AT_FDCWD, path, mode, 0); |
| 145 | −#elif defined(__NR_chmod) | |
| 146 | − return my_syscall2(__NR_chmod, path, mode); | |
| 147 | 145 | #else |
| 148 | − return __nolibc_enosys(__func__, path, mode); | |
| 146 | + return my_syscall2(__NR_chmod, path, mode); | |
| 149 | 147 | #endif |
| 150 | 148 | } |
| 151 | 149 | |
| @@ -165,10 +163,8 @@ int sys_chown(const char *path, uid_t owner, gid_t group) · 13 unmodified lines | ||
| 165 | 163 | { |
| 166 | 164 | #if defined(__NR_fchownat) |
| 167 | 165 | 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); | |
| 170 | 166 | #else |
| 171 | − return __nolibc_enosys(__func__, path, owner, group); | |
| 167 | + return my_syscall3(__NR_chown, path, owner, group); | |
| 172 | 168 | #endif |
| 173 | 169 | } |
| 174 | 170 | |
| @@ -238,11 +234,22 @@ static __attribute__((unused)) · 63 unmodified lines | ||
| 238 | 234 | int sys_dup2(int old, int new) |
| 239 | 235 | { |
| 240 | 236 | #if defined(__NR_dup3) |
| 237 | + int ret, nr_fcntl; | |
| 238 | + | |
| 239 | +#ifdef __NR_fcntl64 | |
| 240 | + nr_fcntl = __NR_fcntl64; | |
| 241 | +#else | |
| 242 | + nr_fcntl = __NR_fcntl; | |
| 243 | +#endif | |
| 244 | + | |
| 245 | + if (old == new) { | |
| 246 | + ret = my_syscall2(nr_fcntl, old, F_GETFD); | |
| 247 | + return ret < 0 ? ret : old; | |
| 248 | + } | |
| 249 | + | |
| 241 | 250 | return my_syscall3(__NR_dup3, old, new, 0); |
| 242 | −#elif defined(__NR_dup2) | |
| 243 | − return my_syscall2(__NR_dup2, old, new); | |
| 244 | 251 | #else |
| 245 | − return __nolibc_enosys(__func__, old, new); | |
| 252 | + return my_syscall2(__NR_dup2, old, new); | |
| 246 | 253 | #endif |
| 247 | 254 | } |
| 248 | 255 | |
| @@ -327,10 +334,8 @@ pid_t sys_fork(void) · 78 unmodified lines | ||
| 327 | 334 | * will not use the rest with no other flag. |
| 328 | 335 | */ |
| 329 | 336 | return my_syscall5(__NR_clone, SIGCHLD, 0, 0, 0, 0); |
| 330 | −#elif defined(__NR_fork) | |
| 331 | − return my_syscall0(__NR_fork); | |
| 332 | 337 | #else |
| 333 | − return __nolibc_enosys(__func__); | |
| 338 | + return my_syscall0(__NR_fork); | |
| 334 | 339 | #endif |
| 335 | 340 | } |
| 336 | 341 | #endif |
| @@ -347,7 +352,7 @@ pid_t sys_vfork(void) · 10 unmodified lines | ||
| 347 | 352 | { |
| 348 | 353 | #if defined(__NR_vfork) |
| 349 | 354 | return my_syscall0(__NR_vfork); |
| 350 | −#elif defined(__NR_clone3) | |
| 355 | +#else | |
| 351 | 356 | /* |
| 352 | 357 | * clone() could be used but has different argument orders per |
| 353 | 358 | * architecture. |
| @@ -358,8 +363,6 @@ pid_t sys_vfork(void) · 4 unmodified lines | ||
| 358 | 363 | }; |
| 359 | 364 | |
| 360 | 365 | return my_syscall2(__NR_clone3, &args, sizeof(args)); |
| 361 | −#else | |
| 362 | − return __nolibc_enosys(__func__); | |
| 363 | 366 | #endif |
| 364 | 367 | } |
| 365 | 368 | #endif |
| @@ -569,10 +572,8 @@ int sys_link(const char *old, const char *new) · 203 unmodified lines | ||
| 569 | 572 | { |
| 570 | 573 | #if defined(__NR_linkat) |
| 571 | 574 | return my_syscall5(__NR_linkat, AT_FDCWD, old, AT_FDCWD, new, 0); |
| 572 | −#elif defined(__NR_link) | |
| 573 | − return my_syscall2(__NR_link, old, new); | |
| 574 | 575 | #else |
| 575 | − return __nolibc_enosys(__func__, old, new); | |
| 576 | + return my_syscall2(__NR_link, old, new); | |
| 576 | 577 | #endif |
| 577 | 578 | } |
| 578 | 579 | |
| @@ -593,41 +594,27 @@ off_t sys_lseek(int fd, off_t offset, int whence) · 14 unmodified lines | ||
| 593 | 594 | #if defined(__NR_lseek) |
| 594 | 595 | return my_syscall3(__NR_lseek, fd, offset, whence); |
| 595 | 596 | #else |
| 596 | − return __nolibc_enosys(__func__, fd, offset, whence); | |
| 597 | −#endif | |
| 598 | −} | |
| 597 | + __kernel_loff_t loff = 0; | |
| 598 | + off_t result; | |
| 599 | + int ret; | |
| 599 | 600 | |
| 600 | −static __attribute__((unused)) | |
| 601 | −int sys_llseek(int fd, unsigned long offset_high, unsigned long offset_low, | |
| 602 | − __kernel_loff_t *result, int whence) | |
| 603 | −{ | |
| 604 | −#if defined(__NR_llseek) | |
| 605 | − return my_syscall5(__NR_llseek, fd, offset_high, offset_low, result, whence); | |
| 606 | −#else | |
| 607 | − return __nolibc_enosys(__func__, fd, offset_high, offset_low, result, whence); | |
| 601 | + /* Only exists on 32bit where nolibc off_t is also 32bit */ | |
| 602 | + ret = my_syscall5(__NR_llseek, fd, 0, offset, &loff, whence); | |
| 603 | + if (ret < 0) | |
| 604 | + result = ret; | |
| 605 | + else if (loff != (off_t)loff) | |
| 606 | + result = -EOVERFLOW; | |
| 607 | + else | |
| 608 | + result = loff; | |
| 609 | + | |
| 610 | + return result; | |
| 608 | 611 | #endif |
| 609 | 612 | } |
| 610 | 613 | |
| 611 | 614 | static __attribute__((unused)) |
| 612 | 615 | off_t lseek(int fd, off_t offset, int whence) |
| 613 | 616 | { |
| 614 | − __kernel_loff_t loff = 0; | |
| 615 | − off_t result; | |
| 616 | − int ret; | |
| 617 | − | |
| 618 | − result = sys_lseek(fd, offset, whence); | |
| 619 | − if (result == -ENOSYS) { | |
| 620 | − /* Only exists on 32bit where nolibc off_t is also 32bit */ | |
| 621 | − ret = sys_llseek(fd, 0, offset, &loff, whence); | |
| 622 | − if (ret < 0) | |
| 623 | − result = ret; | |
| 624 | − else if (loff != (off_t)loff) | |
| 625 | − result = -EOVERFLOW; | |
| 626 | − else | |
| 627 | − result = loff; | |
| 628 | − } | |
| 629 | − | |
| 630 | − return __sysret(result); | |
| 617 | + return __sysret(sys_lseek(fd, offset, whence)); | |
| 631 | 618 | } |
| 632 | 619 | |
| 633 | 620 | |
| @@ -640,10 +627,8 @@ int sys_mkdir(const char *path, mode_t mode) · 6 unmodified lines | ||
| 640 | 627 | { |
| 641 | 628 | #if defined(__NR_mkdirat) |
| 642 | 629 | return my_syscall3(__NR_mkdirat, AT_FDCWD, path, mode); |
| 643 | −#elif defined(__NR_mkdir) | |
| 644 | − return my_syscall2(__NR_mkdir, path, mode); | |
| 645 | 630 | #else |
| 646 | − return __nolibc_enosys(__func__, path, mode); | |
| 631 | + return my_syscall2(__NR_mkdir, path, mode); | |
| 647 | 632 | #endif |
| 648 | 633 | } |
| 649 | 634 | |
| @@ -662,10 +647,8 @@ int sys_rmdir(const char *path) · 12 unmodified lines | ||
| 662 | 647 | { |
| 663 | 648 | #if defined(__NR_rmdir) |
| 664 | 649 | return my_syscall1(__NR_rmdir, path); |
| 665 | −#elif defined(__NR_unlinkat) | |
| 666 | − return my_syscall3(__NR_unlinkat, AT_FDCWD, path, AT_REMOVEDIR); | |
| 667 | 650 | #else |
| 668 | − return __nolibc_enosys(__func__, path); | |
| 651 | + return my_syscall3(__NR_unlinkat, AT_FDCWD, path, AT_REMOVEDIR); | |
| 669 | 652 | #endif |
| 670 | 653 | } |
| 671 | 654 | |
| @@ -685,10 +668,8 @@ long sys_mknod(const char *path, mode_t mode, dev_t dev) · 13 unmodified lines | ||
| 685 | 668 | { |
| 686 | 669 | #if defined(__NR_mknodat) |
| 687 | 670 | return my_syscall4(__NR_mknodat, AT_FDCWD, path, mode, dev); |
| 688 | −#elif defined(__NR_mknod) | |
| 689 | − return my_syscall3(__NR_mknod, path, mode, dev); | |
| 690 | 671 | #else |
| 691 | − return __nolibc_enosys(__func__, path, mode, dev); | |
| 672 | + return my_syscall3(__NR_mknod, path, mode, dev); | |
| 692 | 673 | #endif |
| 693 | 674 | } |
| 694 | 675 | |
| @@ -801,7 +782,7 @@ int sys_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeva · 106 unmodified lines | ||
| 801 | 782 | t.tv_nsec = timeout->tv_usec * 1000; |
| 802 | 783 | } |
| 803 | 784 | return my_syscall6(__NR_pselect6, nfds, rfds, wfds, efds, timeout ? &t : NULL, NULL); |
| 804 | −#elif defined(__NR_pselect6_time64) | |
| 785 | +#else | |
| 805 | 786 | struct __kernel_timespec t; |
| 806 | 787 | |
| 807 | 788 | if (timeout) { |
| @@ -809,8 +790,6 @@ int sys_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeva · 1 unmodified line | ||
| 809 | 790 | t.tv_nsec = timeout->tv_usec * 1000; |
| 810 | 791 | } |
| 811 | 792 | return my_syscall6(__NR_pselect6_time64, nfds, rfds, wfds, efds, timeout ? &t : NULL, NULL); |
| 812 | −#else | |
| 813 | − return __nolibc_enosys(__func__, nfds, rfds, wfds, efds, timeout); | |
| 814 | 793 | #endif |
| 815 | 794 | } |
| 816 | 795 | |
| @@ -874,10 +853,8 @@ int sys_symlink(const char *old, const char *new) · 57 unmodified lines | ||
| 874 | 853 | { |
| 875 | 854 | #if defined(__NR_symlinkat) |
| 876 | 855 | return my_syscall3(__NR_symlinkat, old, AT_FDCWD, new); |
| 877 | −#elif defined(__NR_symlink) | |
| 878 | − return my_syscall2(__NR_symlink, old, new); | |
| 879 | 856 | #else |
| 880 | − return __nolibc_enosys(__func__, old, new); | |
| 857 | + return my_syscall2(__NR_symlink, old, new); | |
| 881 | 858 | #endif |
| 882 | 859 | } |
| 883 | 860 | |
| @@ -931,10 +908,8 @@ int sys_unlink(const char *path) · 47 unmodified lines | ||
| 931 | 908 | { |
| 932 | 909 | #if defined(__NR_unlinkat) |
| 933 | 910 | return my_syscall3(__NR_unlinkat, AT_FDCWD, path, 0); |
| 934 | −#elif defined(__NR_unlink) | |
| 935 | − return my_syscall1(__NR_unlink, path); | |
| 936 | 911 | #else |
| 937 | − return __nolibc_enosys(__func__, path); | |
| 912 | + return my_syscall1(__NR_unlink, path); | |
| 938 | 913 | #endif |
| 939 | 914 | } |
| 940 | 915 | |
| @@ -22,13 +22,13 @@ · 21 unmodified lines | ||
| 22 | 22 | static __attribute__((unused)) |
| 23 | 23 | ssize_t sys_getrandom(void *buf, size_t buflen, unsigned int flags) |
| 24 | 24 | { |
| 25 | − return my_syscall3(__NR_getrandom, buf, buflen, flags); | |
| 25 | + return my_syscall3(__NR_getrandom, buf, buflen, flags); | |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | static __attribute__((unused)) |
| 29 | 29 | ssize_t getrandom(void *buf, size_t buflen, unsigned int flags) |
| 30 | 30 | { |
| 31 | − return __sysret(sys_getrandom(buf, buflen, flags)); | |
| 31 | + return __sysret(sys_getrandom(buf, buflen, flags)); | |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | #endif /* _NOLIBC_SYS_RANDOM_H */ |
| @@ -34,7 +34,7 @@ int sys_timerfd_gettime(int fd, struct itimerspec *curr_value) · 33 unmodified lines | ||
| 34 | 34 | { |
| 35 | 35 | #if defined(__NR_timerfd_gettime) |
| 36 | 36 | return my_syscall2(__NR_timerfd_gettime, fd, curr_value); |
| 37 | −#elif defined(__NR_timerfd_gettime64) | |
| 37 | +#else | |
| 38 | 38 | struct __kernel_itimerspec kcurr_value; |
| 39 | 39 | int ret; |
| 40 | 40 | |
| @@ -42,8 +42,6 @@ int sys_timerfd_gettime(int fd, struct itimerspec *curr_value) · 1 unmodified line | ||
| 42 | 42 | __nolibc_timespec_kernel_to_user(&kcurr_value.it_interval, &curr_value->it_interval); |
| 43 | 43 | __nolibc_timespec_kernel_to_user(&kcurr_value.it_value, &curr_value->it_value); |
| 44 | 44 | return ret; |
| 45 | −#else | |
| 46 | − return __nolibc_enosys(__func__, fd, curr_value); | |
| 47 | 45 | #endif |
| 48 | 46 | } |
| 49 | 47 | |
| @@ -60,7 +58,7 @@ int sys_timerfd_settime(int fd, int flags, · 10 unmodified lines | ||
| 60 | 58 | { |
| 61 | 59 | #if defined(__NR_timerfd_settime) |
| 62 | 60 | return my_syscall4(__NR_timerfd_settime, fd, flags, new_value, old_value); |
| 63 | −#elif defined(__NR_timerfd_settime64) | |
| 61 | +#else | |
| 64 | 62 | struct __kernel_itimerspec knew_value, kold_value; |
| 65 | 63 | int ret; |
| 66 | 64 | |
| @@ -72,8 +70,6 @@ int sys_timerfd_settime(int fd, int flags, · 5 unmodified lines | ||
| 72 | 70 | __nolibc_timespec_kernel_to_user(&kold_value.it_value, &old_value->it_value); |
| 73 | 71 | } |
| 74 | 72 | return ret; |
| 75 | −#else | |
| 76 | − return __nolibc_enosys(__func__, fd, flags, new_value, old_value); | |
| 77 | 73 | #endif |
| 78 | 74 | } |
| 79 | 75 | |
| @@ -16,27 +16,10 @@ · 15 unmodified lines | ||
| 16 | 16 | |
| 17 | 17 | /* |
| 18 | 18 | * pid_t wait(int *status); |
| 19 | − * pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage); | |
| 20 | 19 | * pid_t waitpid(pid_t pid, int *status, int options); |
| 21 | 20 | * int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options); |
| 22 | 21 | */ |
| 23 | 22 | |
| 24 | −static __attribute__((unused)) | |
| 25 | −pid_t sys_wait4(pid_t pid, int *status, int options, struct rusage *rusage) | |
| 26 | −{ | |
| 27 | −#ifdef __NR_wait4 | |
| 28 | − return my_syscall4(__NR_wait4, pid, status, options, rusage); | |
| 29 | −#else | |
| 30 | − return __nolibc_enosys(__func__, pid, status, options, rusage); | |
| 31 | −#endif | |
| 32 | −} | |
| 33 | − | |
| 34 | −static __attribute__((unused)) | |
| 35 | −pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage) | |
| 36 | −{ | |
| 37 | − return __sysret(sys_wait4(pid, status, options, rusage)); | |
| 38 | −} | |
| 39 | − | |
| 40 | 23 | static __attribute__((unused)) |
| 41 | 24 | int sys_waitid(int which, pid_t pid, siginfo_t *infop, int options, struct rusage *rusage) |
| 42 | 25 | { |
| @@ -45,7 +45,7 @@ int sys_clock_getres(clockid_t clockid, struct timespec *res) · 44 unmodified lines | ||
| 45 | 45 | { |
| 46 | 46 | #if defined(__NR_clock_getres) |
| 47 | 47 | return my_syscall2(__NR_clock_getres, clockid, res); |
| 48 | −#elif defined(__NR_clock_getres_time64) | |
| 48 | +#else | |
| 49 | 49 | struct __kernel_timespec kres; |
| 50 | 50 | int ret; |
| 51 | 51 | |
| @@ -53,8 +53,6 @@ int sys_clock_getres(clockid_t clockid, struct timespec *res) · 1 unmodified line | ||
| 53 | 53 | if (res) |
| 54 | 54 | __nolibc_timespec_kernel_to_user(&kres, res); |
| 55 | 55 | return ret; |
| 56 | −#else | |
| 57 | − return __nolibc_enosys(__func__, clockid, res); | |
| 58 | 56 | #endif |
| 59 | 57 | } |
| 60 | 58 | |
| @@ -69,7 +67,7 @@ int sys_clock_gettime(clockid_t clockid, struct timespec *tp) · 8 unmodified lines | ||
| 69 | 67 | { |
| 70 | 68 | #if defined(__NR_clock_gettime) |
| 71 | 69 | return my_syscall2(__NR_clock_gettime, clockid, tp); |
| 72 | −#elif defined(__NR_clock_gettime64) | |
| 70 | +#else | |
| 73 | 71 | struct __kernel_timespec ktp; |
| 74 | 72 | int ret; |
| 75 | 73 | |
| @@ -77,8 +75,6 @@ int sys_clock_gettime(clockid_t clockid, struct timespec *tp) · 1 unmodified line | ||
| 77 | 75 | if (tp) |
| 78 | 76 | __nolibc_timespec_kernel_to_user(&ktp, tp); |
| 79 | 77 | return ret; |
| 80 | −#else | |
| 81 | − return __nolibc_enosys(__func__, clockid, tp); | |
| 82 | 78 | #endif |
| 83 | 79 | } |
| 84 | 80 | |
| @@ -133,7 +129,8 @@ static __attribute__((unused)) · 48 unmodified lines | ||
| 133 | 129 | int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp, |
| 134 | 130 | struct timespec *rmtp) |
| 135 | 131 | { |
| 136 | − return __sysret(sys_clock_nanosleep(clockid, flags, rqtp, rmtp)); | |
| 132 | + /* Directly return a positive error number */ | |
| 133 | + return -sys_clock_nanosleep(clockid, flags, rqtp, rmtp); | |
| 137 | 134 | } |
| 138 | 135 | |
| 139 | 136 | static __inline__ |
| @@ -145,7 +142,7 @@ double difftime(time_t time1, time_t time2) · 5 unmodified lines | ||
| 145 | 142 | static __inline__ |
| 146 | 143 | int nanosleep(const struct timespec *rqtp, struct timespec *rmtp) |
| 147 | 144 | { |
| 148 | − return clock_nanosleep(CLOCK_REALTIME, 0, rqtp, rmtp); | |
| 145 | + return __sysret(sys_clock_nanosleep(CLOCK_REALTIME, 0, rqtp, rmtp)); | |
| 149 | 146 | } |
| 150 | 147 | |
| 151 | 148 | |
| @@ -33,7 +33,7 @@ · 32 unmodified lines | ||
| 33 | 33 | static __attribute__((unused)) |
| 34 | 34 | int sys_faccessat(int fd, const char *path, int amode, int flag) |
| 35 | 35 | { |
| 36 | − return my_syscall4(__NR_faccessat, fd, path, amode, flag); | |
| 36 | + return my_syscall4(__NR_faccessat, fd, path, amode, flag); | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | static __attribute__((unused)) |