Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'nolibc-20250928-for-6.18-1' of git://git.kernel.org/pub/scm/linux/kernel/git/nolibc/linux-nolibc

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()

+69 -116
+1
tools/include/nolibc/nolibc.h
··· 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"
+1 -3
tools/include/nolibc/poll.h
··· 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
+1 -1
tools/include/nolibc/std.h
··· 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 */
+40 -65
tools/include/nolibc/sys.h
··· 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 ··· 163 165 { 164 166 #if defined(__NR_fchownat) 165 167 return my_syscall5(__NR_fchownat, AT_FDCWD, path, owner, group, 0); 166 - #elif defined(__NR_chown) 167 - return my_syscall3(__NR_chown, path, owner, group); 168 168 #else 169 - return __nolibc_enosys(__func__, path, owner, group); 169 + return my_syscall3(__NR_chown, path, owner, group); 170 170 #endif 171 171 } 172 172 ··· 234 238 int sys_dup2(int old, int new) 235 239 { 236 240 #if defined(__NR_dup3) 237 - return my_syscall3(__NR_dup3, old, new, 0); 238 - #elif defined(__NR_dup2) 239 - return my_syscall2(__NR_dup2, old, new); 241 + int ret, nr_fcntl; 242 + 243 + #ifdef __NR_fcntl64 244 + nr_fcntl = __NR_fcntl64; 240 245 #else 241 - return __nolibc_enosys(__func__, old, new); 246 + nr_fcntl = __NR_fcntl; 247 + #endif 248 + 249 + if (old == new) { 250 + ret = my_syscall2(nr_fcntl, old, F_GETFD); 251 + return ret < 0 ? ret : old; 252 + } 253 + 254 + return my_syscall3(__NR_dup3, old, new, 0); 255 + #else 256 + return my_syscall2(__NR_dup2, old, new); 242 257 #endif 243 258 } 244 259 ··· 334 327 * will not use the rest with no other flag. 335 328 */ 336 329 return my_syscall5(__NR_clone, SIGCHLD, 0, 0, 0, 0); 337 - #elif defined(__NR_fork) 338 - return my_syscall0(__NR_fork); 339 330 #else 340 - return __nolibc_enosys(__func__); 331 + return my_syscall0(__NR_fork); 341 332 #endif 342 333 } 343 334 #endif ··· 352 347 { 353 348 #if defined(__NR_vfork) 354 349 return my_syscall0(__NR_vfork); 355 - #elif defined(__NR_clone3) 350 + #else 356 351 /* 357 352 * clone() could be used but has different argument orders per 358 353 * architecture. ··· 363 358 }; 364 359 365 360 return my_syscall2(__NR_clone3, &args, sizeof(args)); 366 - #else 367 - return __nolibc_enosys(__func__); 368 361 #endif 369 362 } 370 363 #endif ··· 572 569 { 573 570 #if defined(__NR_linkat) 574 571 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); 577 572 #else 578 - return __nolibc_enosys(__func__, old, new); 573 + return my_syscall2(__NR_link, old, new); 579 574 #endif 580 575 } 581 576 ··· 594 593 #if defined(__NR_lseek) 595 594 return my_syscall3(__NR_lseek, fd, offset, whence); 596 595 #else 597 - return __nolibc_enosys(__func__, fd, offset, whence); 598 - #endif 599 - } 596 + __kernel_loff_t loff = 0; 597 + off_t result; 598 + int ret; 600 599 601 - static __attribute__((unused)) 602 - int sys_llseek(int fd, unsigned long offset_high, unsigned long offset_low, 603 - __kernel_loff_t *result, int whence) 604 - { 605 - #if defined(__NR_llseek) 606 - return my_syscall5(__NR_llseek, fd, offset_high, offset_low, result, whence); 607 - #else 608 - return __nolibc_enosys(__func__, fd, offset_high, offset_low, result, whence); 600 + /* Only exists on 32bit where nolibc off_t is also 32bit */ 601 + ret = my_syscall5(__NR_llseek, fd, 0, offset, &loff, whence); 602 + if (ret < 0) 603 + result = ret; 604 + else if (loff != (off_t)loff) 605 + result = -EOVERFLOW; 606 + else 607 + result = loff; 608 + 609 + return result; 609 610 #endif 610 611 } 611 612 612 613 static __attribute__((unused)) 613 614 off_t lseek(int fd, off_t offset, int whence) 614 615 { 615 - __kernel_loff_t loff = 0; 616 - off_t result; 617 - int ret; 618 - 619 - result = sys_lseek(fd, offset, whence); 620 - if (result == -ENOSYS) { 621 - /* Only exists on 32bit where nolibc off_t is also 32bit */ 622 - ret = sys_llseek(fd, 0, offset, &loff, whence); 623 - if (ret < 0) 624 - result = ret; 625 - else if (loff != (off_t)loff) 626 - result = -EOVERFLOW; 627 - else 628 - result = loff; 629 - } 630 - 631 - return __sysret(result); 616 + return __sysret(sys_lseek(fd, offset, whence)); 632 617 } 633 618 634 619 ··· 627 640 { 628 641 #if defined(__NR_mkdirat) 629 642 return my_syscall3(__NR_mkdirat, AT_FDCWD, path, mode); 630 - #elif defined(__NR_mkdir) 631 - return my_syscall2(__NR_mkdir, path, mode); 632 643 #else 633 - return __nolibc_enosys(__func__, path, mode); 644 + return my_syscall2(__NR_mkdir, path, mode); 634 645 #endif 635 646 } 636 647 ··· 647 662 { 648 663 #if defined(__NR_rmdir) 649 664 return my_syscall1(__NR_rmdir, path); 650 - #elif defined(__NR_unlinkat) 651 - return my_syscall3(__NR_unlinkat, AT_FDCWD, path, AT_REMOVEDIR); 652 665 #else 653 - return __nolibc_enosys(__func__, path); 666 + return my_syscall3(__NR_unlinkat, AT_FDCWD, path, AT_REMOVEDIR); 654 667 #endif 655 668 } 656 669 ··· 668 685 { 669 686 #if defined(__NR_mknodat) 670 687 return my_syscall4(__NR_mknodat, AT_FDCWD, path, mode, dev); 671 - #elif defined(__NR_mknod) 672 - return my_syscall3(__NR_mknod, path, mode, dev); 673 688 #else 674 - return __nolibc_enosys(__func__, path, mode, dev); 689 + return my_syscall3(__NR_mknod, path, mode, dev); 675 690 #endif 676 691 } 677 692 ··· 782 801 t.tv_nsec = timeout->tv_usec * 1000; 783 802 } 784 803 return my_syscall6(__NR_pselect6, nfds, rfds, wfds, efds, timeout ? &t : NULL, NULL); 785 - #elif defined(__NR_pselect6_time64) 804 + #else 786 805 struct __kernel_timespec t; 787 806 788 807 if (timeout) { ··· 790 809 t.tv_nsec = timeout->tv_usec * 1000; 791 810 } 792 811 return my_syscall6(__NR_pselect6_time64, nfds, rfds, wfds, efds, timeout ? &t : NULL, NULL); 793 - #else 794 - return __nolibc_enosys(__func__, nfds, rfds, wfds, efds, timeout); 795 812 #endif 796 813 } 797 814 ··· 853 874 { 854 875 #if defined(__NR_symlinkat) 855 876 return my_syscall3(__NR_symlinkat, old, AT_FDCWD, new); 856 - #elif defined(__NR_symlink) 857 - return my_syscall2(__NR_symlink, old, new); 858 877 #else 859 - return __nolibc_enosys(__func__, old, new); 878 + return my_syscall2(__NR_symlink, old, new); 860 879 #endif 861 880 } 862 881 ··· 908 931 { 909 932 #if defined(__NR_unlinkat) 910 933 return my_syscall3(__NR_unlinkat, AT_FDCWD, path, 0); 911 - #elif defined(__NR_unlink) 912 - return my_syscall1(__NR_unlink, path); 913 934 #else 914 - return __nolibc_enosys(__func__, path); 935 + return my_syscall1(__NR_unlink, path); 915 936 #endif 916 937 } 917 938
+2 -2
tools/include/nolibc/sys/random.h
··· 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 */
+2 -6
tools/include/nolibc/sys/timerfd.h
··· 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 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 ··· 58 60 { 59 61 #if defined(__NR_timerfd_settime) 60 62 return my_syscall4(__NR_timerfd_settime, fd, flags, new_value, old_value); 61 - #elif defined(__NR_timerfd_settime64) 63 + #else 62 64 struct __kernel_itimerspec knew_value, kold_value; 63 65 int ret; 64 66 ··· 70 72 __nolibc_timespec_kernel_to_user(&kold_value.it_value, &old_value->it_value); 71 73 } 72 74 return ret; 73 - #else 74 - return __nolibc_enosys(__func__, fd, flags, new_value, old_value); 75 75 #endif 76 76 } 77 77
-17
tools/include/nolibc/sys/wait.h
··· 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 - 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 22 40 23 static __attribute__((unused)) 41 24 int sys_waitid(int which, pid_t pid, siginfo_t *infop, int options, struct rusage *rusage)
+5 -8
tools/include/nolibc/time.h
··· 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 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 ··· 67 69 { 68 70 #if defined(__NR_clock_gettime) 69 71 return my_syscall2(__NR_clock_gettime, clockid, tp); 70 - #elif defined(__NR_clock_gettime64) 72 + #else 71 73 struct __kernel_timespec ktp; 72 74 int ret; 73 75 ··· 75 77 if (tp) 76 78 __nolibc_timespec_kernel_to_user(&ktp, tp); 77 79 return ret; 78 - #else 79 - return __nolibc_enosys(__func__, clockid, tp); 80 80 #endif 81 81 } 82 82 ··· 129 133 int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp, 130 134 struct timespec *rmtp) 131 135 { 132 - return __sysret(sys_clock_nanosleep(clockid, flags, rqtp, rmtp)); 136 + /* Directly return a positive error number */ 137 + return -sys_clock_nanosleep(clockid, flags, rqtp, rmtp); 133 138 } 134 139 135 140 static __inline__ ··· 142 145 static __inline__ 143 146 int nanosleep(const struct timespec *rqtp, struct timespec *rmtp) 144 147 { 145 - return clock_nanosleep(CLOCK_REALTIME, 0, rqtp, rmtp); 148 + return __sysret(sys_clock_nanosleep(CLOCK_REALTIME, 0, rqtp, rmtp)); 146 149 } 147 150 148 151
+1 -1
tools/include/nolibc/unistd.h
··· 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))
+3 -3
tools/testing/selftests/arm64/abi/tpidr2.c
··· 182 182 } 183 183 184 184 for (;;) { 185 - waiting = wait4(ret, &status, __WCLONE, NULL); 185 + waiting = waitpid(ret, &status, __WCLONE); 186 186 187 187 if (waiting < 0) { 188 188 if (errno == EINTR) 189 189 continue; 190 - ksft_print_msg("wait4() failed: %d\n", errno); 190 + ksft_print_msg("waitpid() failed: %d\n", errno); 191 191 return 0; 192 192 } 193 193 if (waiting != ret) { 194 - ksft_print_msg("wait4() returned wrong PID %d\n", 194 + ksft_print_msg("waitpid() returned wrong PID %d\n", 195 195 waiting); 196 196 return 0; 197 197 }
+10 -7
tools/testing/selftests/nolibc/Makefile.nolibc
··· 262 262 if (f || !p || !done) printf("failure\n"); else if (s) printf("warning\n"); else printf("success\n");; \ 263 263 printf("\nSee all results in %s\n", ARGV[1]); }' 264 264 265 + # Execute the toplevel kernel Makefile 266 + KBUILD_MAKE = $(MAKE) -C $(srctree) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) LLVM= 267 + 265 268 help: 266 269 @echo "Supported targets under selftests/nolibc:" 267 270 @echo " all call the \"run\" target below" 268 271 @echo " help this help" 269 272 @echo " sysroot create the nolibc sysroot here (uses \$$ARCH)" 270 - @echo " nolibc-test build the executable (uses \$$CC and \$$CROSS_COMPILE)" 273 + @echo " nolibc-test build the executable (uses \$$CC or \$$CROSS_COMPILE)" 271 274 @echo " libc-test build an executable using the compiler's default libc instead" 272 275 @echo " run-user runs the executable under QEMU (uses \$$XARCH, \$$TEST)" 273 276 @echo " initramfs.cpio prepare the initramfs archive with nolibc-test" 274 277 @echo " initramfs prepare the initramfs tree with nolibc-test" 275 278 @echo " defconfig create a fresh new default config (uses \$$XARCH)" 276 - @echo " kernel (re)build the kernel (uses \$$XARCH)" 277 - @echo " kernel-standalone (re)build the kernel with the initramfs (uses \$$XARCH)" 279 + @echo " kernel (re)build the kernel (uses \$$XARCH, \$$CROSS_COMPILE)" 280 + @echo " kernel-standalone (re)build the kernel with the initramfs (uses \$$XARCH, \$$CROSS_COMPILE)" 278 281 @echo " run runs the kernel in QEMU after building it (uses \$$XARCH, \$$TEST)" 279 282 @echo " rerun runs a previously prebuilt kernel in QEMU (uses \$$XARCH, \$$TEST)" 280 283 @echo " clean clean the sysroot, initramfs, build and output files" ··· 343 340 $(Q)cp nolibc-test initramfs/init 344 341 345 342 defconfig: 346 - $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(DEFCONFIG) 343 + $(Q)$(KBUILD_MAKE) $(DEFCONFIG) 347 344 $(Q)if [ -n "$(EXTRACONFIG)" ]; then \ 348 345 $(srctree)/scripts/config --file $(objtree)/.config $(EXTRACONFIG); \ 349 - $(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) olddefconfig < /dev/null; \ 346 + $(KBUILD_MAKE) olddefconfig < /dev/null; \ 350 347 fi 351 348 352 349 kernel: 353 - $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(IMAGE_NAME) < /dev/null 350 + $(Q)$(KBUILD_MAKE) $(IMAGE_NAME) < /dev/null 354 351 355 352 kernel-standalone: initramfs 356 - $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(IMAGE_NAME) CONFIG_INITRAMFS_SOURCE=$(CURDIR)/initramfs < /dev/null 353 + $(Q)$(KBUILD_MAKE) $(IMAGE_NAME) CONFIG_INITRAMFS_SOURCE=$(CURDIR)/initramfs < /dev/null 357 354 358 355 # run the tests after building the kernel 359 356 run: kernel initramfs.cpio
+3 -3
tools/testing/selftests/nolibc/nolibc-test.c
··· 196 196 } 197 197 198 198 199 - #define EXPECT_NZ(cond, expr, val) \ 200 - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_nz(expr, llen; } while (0) 199 + #define EXPECT_NZ(cond, expr) \ 200 + do { if (!(cond)) result(llen, SKIPPED); else ret += expect_nz(expr, llen); } while (0) 201 201 202 202 static __attribute__((unused)) 203 203 int expect_nz(int expr, int llen) ··· 686 686 #define CASE_TEST(name) \ 687 687 case __LINE__: llen += printf("%d %s", test, #name); 688 688 689 - /* constructors validate that they are executed in definition order */ 690 689 __attribute__((constructor)) 691 690 static void constructor1(void) 692 691 { ··· 1333 1334 CASE_TEST(chroot_root); EXPECT_SYSZR(euid0, chroot("/")); break; 1334 1335 CASE_TEST(chroot_blah); EXPECT_SYSER(1, chroot("/proc/self/blah"), -1, ENOENT); break; 1335 1336 CASE_TEST(chroot_exe); EXPECT_SYSER(1, chroot(argv0), -1, ENOTDIR); break; 1337 + CASE_TEST(clock_nanosleep); ts.tv_nsec = -1; EXPECT_EQ(1, EINVAL, clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL)); break; 1336 1338 CASE_TEST(close_m1); EXPECT_SYSER(1, close(-1), -1, EBADF); break; 1337 1339 CASE_TEST(close_dup); EXPECT_SYSZR(1, close(dup(0))); break; 1338 1340 CASE_TEST(dup_0); tmp = dup(0); EXPECT_SYSNE(1, tmp, -1); close(tmp); break;