History

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

Linus Torvalds committed 1 year ago

Commit 50c19e22 parents f4e0ff7 2d965c112 files · +68 −115Browse files

Showing the changes to tools/include (9 of 12 files). Show all

Unified · Split

9 files
  1. tools/include/nolibc/nolibc.h +1 −0
  2. tools/include/nolibc/poll.h +1 −3
  3. tools/include/nolibc/std.h +1 −1
  4. tools/include/nolibc/sys.h +39 −64
  5. tools/include/nolibc/sys/random.h +2 −2
  6. tools/include/nolibc/sys/timerfd.h +2 −6
  7. tools/include/nolibc/sys/wait.h +0 −17
  8. tools/include/nolibc/time.h +5 −8
  9. tools/include/nolibc/unistd.h +1 −1
tools/include/nolibc/nolibc.h+1−0
@@ -116,6 +116,7 @@ · 115 unmodified lines
116#include "sched.h"116#include "sched.h"
117#include "signal.h"117#include "signal.h"
118#include "unistd.h"118#include "unistd.h"
119#include "stdbool.h"
119#include "stdio.h"120#include "stdio.h"
120#include "stdlib.h"121#include "stdlib.h"
121#include "string.h"122#include "string.h"
tools/include/nolibc/poll.h+1−3
@@ -39,10 +39,8 @@ int sys_poll(struct pollfd *fds, int nfds, int timeout) · 38 unmodified lines
39 t.tv_nsec = (timeout % 1000) * 1000000;39 t.tv_nsec = (timeout % 1000) * 1000000;
40 }40 }
41 return my_syscall5(__NR_ppoll_time64, fds, nfds, (timeout >= 0) ? &t : NULL, NULL, 0);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#else42#else
45 return __nolibc_enosys(__func__, fds, nfds, timeout);43 return my_syscall3(__NR_poll, fds, nfds, timeout);
46#endif44#endif
47}45}
48 46
tools/include/nolibc/std.h+1−1
@@ -29,6 +29,6 @@ typedef unsigned long nlink_t; · 28 unmodified lines
29typedef signed long off_t;29typedef signed long off_t;
30typedef signed long blksize_t;30typedef signed long blksize_t;
31typedef signed long blkcnt_t;31typedef signed long blkcnt_t;
32typedef __kernel_old_time_t time_t;32typedef __kernel_time_t time_t;
33 33
34#endif /* _NOLIBC_STD_H */34#endif /* _NOLIBC_STD_H */
tools/include/nolibc/sys.h+39−64
@@ -142,10 +142,8 @@ int sys_chmod(const char *path, mode_t mode) · 141 unmodified lines
142{142{
143#if defined(__NR_fchmodat)143#if defined(__NR_fchmodat)
144 return my_syscall4(__NR_fchmodat, AT_FDCWD, path, mode, 0);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#else145#else
148 return __nolibc_enosys(__func__, path, mode);146 return my_syscall2(__NR_chmod, path, mode);
149#endif147#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#if defined(__NR_fchownat)164#if defined(__NR_fchownat)
167 return my_syscall5(__NR_fchownat, AT_FDCWD, path, owner, group, 0);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#else166#else
171 return __nolibc_enosys(__func__, path, owner, group);167 return my_syscall3(__NR_chown, path, owner, group);
172#endif168#endif
173}169}
174 170
@@ -238,11 +234,22 @@ static __attribute__((unused)) · 63 unmodified lines
238int sys_dup2(int old, int new)234int sys_dup2(int old, int new)
239{235{
240#if defined(__NR_dup3)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 return my_syscall3(__NR_dup3, old, new, 0);250 return my_syscall3(__NR_dup3, old, new, 0);
242#elif defined(__NR_dup2)
243 return my_syscall2(__NR_dup2, old, new);
244#else251#else
245 return __nolibc_enosys(__func__, old, new);252 return my_syscall2(__NR_dup2, old, new);
246#endif253#endif
247}254}
248 255
@@ -327,10 +334,8 @@ pid_t sys_fork(void) · 78 unmodified lines
327 * will not use the rest with no other flag.334 * will not use the rest with no other flag.
328 */335 */
329 return my_syscall5(__NR_clone, SIGCHLD, 0, 0, 0, 0);336 return my_syscall5(__NR_clone, SIGCHLD, 0, 0, 0, 0);
330#elif defined(__NR_fork)
331 return my_syscall0(__NR_fork);
332#else337#else
333 return __nolibc_enosys(__func__);338 return my_syscall0(__NR_fork);
334#endif339#endif
335}340}
336#endif341#endif
@@ -347,7 +352,7 @@ pid_t sys_vfork(void) · 10 unmodified lines
347{352{
348#if defined(__NR_vfork)353#if defined(__NR_vfork)
349 return my_syscall0(__NR_vfork);354 return my_syscall0(__NR_vfork);
350#elif defined(__NR_clone3)355#else
351 /*356 /*
352 * clone() could be used but has different argument orders per357 * clone() could be used but has different argument orders per
353 * architecture.358 * architecture.
@@ -358,8 +363,6 @@ pid_t sys_vfork(void) · 4 unmodified lines
358 };363 };
359 364
360 return my_syscall2(__NR_clone3, &args, sizeof(args));365 return my_syscall2(__NR_clone3, &args, sizeof(args));
361#else
362 return __nolibc_enosys(__func__);
363#endif366#endif
364}367}
365#endif368#endif
@@ -569,10 +572,8 @@ int sys_link(const char *old, const char *new) · 203 unmodified lines
569{572{
570#if defined(__NR_linkat)573#if defined(__NR_linkat)
571 return my_syscall5(__NR_linkat, AT_FDCWD, old, AT_FDCWD, new, 0);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#else575#else
575 return __nolibc_enosys(__func__, old, new);576 return my_syscall2(__NR_link, old, new);
576#endif577#endif
577}578}
578 579
@@ -593,41 +594,27 @@ off_t sys_lseek(int fd, off_t offset, int whence) · 14 unmodified lines
593#if defined(__NR_lseek)594#if defined(__NR_lseek)
594 return my_syscall3(__NR_lseek, fd, offset, whence);595 return my_syscall3(__NR_lseek, fd, offset, whence);
595#else596#else
596 return __nolibc_enosys(__func__, fd, offset, whence);597 __kernel_loff_t loff = 0;
597#endif598 off_t result;
598}599 int ret;
599 600
600static __attribute__((unused))601 /* Only exists on 32bit where nolibc off_t is also 32bit */
601int sys_llseek(int fd, unsigned long offset_high, unsigned long offset_low,602 ret = my_syscall5(__NR_llseek, fd, 0, offset, &loff, whence);
602 __kernel_loff_t *result, int whence)603 if (ret < 0)
603{604 result = ret;
604#if defined(__NR_llseek)605 else if (loff != (off_t)loff)
605 return my_syscall5(__NR_llseek, fd, offset_high, offset_low, result, whence);606 result = -EOVERFLOW;
606#else607 else
607 return __nolibc_enosys(__func__, fd, offset_high, offset_low, result, whence);608 result = loff;
609
610 return result;
608#endif611#endif
609}612}
610 613
611static __attribute__((unused))614static __attribute__((unused))
612off_t lseek(int fd, off_t offset, int whence)615off_t lseek(int fd, off_t offset, int whence)
613{616{
614 __kernel_loff_t loff = 0;617 return __sysret(sys_lseek(fd, offset, whence));
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);
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#if defined(__NR_mkdirat)628#if defined(__NR_mkdirat)
642 return my_syscall3(__NR_mkdirat, AT_FDCWD, path, mode);629 return my_syscall3(__NR_mkdirat, AT_FDCWD, path, mode);
643#elif defined(__NR_mkdir)
644 return my_syscall2(__NR_mkdir, path, mode);
645#else630#else
646 return __nolibc_enosys(__func__, path, mode);631 return my_syscall2(__NR_mkdir, path, mode);
647#endif632#endif
648}633}
649 634
@@ -662,10 +647,8 @@ int sys_rmdir(const char *path) · 12 unmodified lines
662{647{
663#if defined(__NR_rmdir)648#if defined(__NR_rmdir)
664 return my_syscall1(__NR_rmdir, path);649 return my_syscall1(__NR_rmdir, path);
665#elif defined(__NR_unlinkat)
666 return my_syscall3(__NR_unlinkat, AT_FDCWD, path, AT_REMOVEDIR);
667#else650#else
668 return __nolibc_enosys(__func__, path);651 return my_syscall3(__NR_unlinkat, AT_FDCWD, path, AT_REMOVEDIR);
669#endif652#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#if defined(__NR_mknodat)669#if defined(__NR_mknodat)
687 return my_syscall4(__NR_mknodat, AT_FDCWD, path, mode, dev);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#else671#else
691 return __nolibc_enosys(__func__, path, mode, dev);672 return my_syscall3(__NR_mknod, path, mode, dev);
692#endif673#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 t.tv_nsec = timeout->tv_usec * 1000;782 t.tv_nsec = timeout->tv_usec * 1000;
802 }783 }
803 return my_syscall6(__NR_pselect6, nfds, rfds, wfds, efds, timeout ? &t : NULL, NULL);784 return my_syscall6(__NR_pselect6, nfds, rfds, wfds, efds, timeout ? &t : NULL, NULL);
804#elif defined(__NR_pselect6_time64)785#else
805 struct __kernel_timespec t;786 struct __kernel_timespec t;
806 787
807 if (timeout) {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 t.tv_nsec = timeout->tv_usec * 1000;790 t.tv_nsec = timeout->tv_usec * 1000;
810 }791 }
811 return my_syscall6(__NR_pselect6_time64, nfds, rfds, wfds, efds, timeout ? &t : NULL, NULL);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#endif793#endif
815}794}
816 795
@@ -874,10 +853,8 @@ int sys_symlink(const char *old, const char *new) · 57 unmodified lines
874{853{
875#if defined(__NR_symlinkat)854#if defined(__NR_symlinkat)
876 return my_syscall3(__NR_symlinkat, old, AT_FDCWD, new);855 return my_syscall3(__NR_symlinkat, old, AT_FDCWD, new);
877#elif defined(__NR_symlink)
878 return my_syscall2(__NR_symlink, old, new);
879#else856#else
880 return __nolibc_enosys(__func__, old, new);857 return my_syscall2(__NR_symlink, old, new);
881#endif858#endif
882}859}
883 860
@@ -931,10 +908,8 @@ int sys_unlink(const char *path) · 47 unmodified lines
931{908{
932#if defined(__NR_unlinkat)909#if defined(__NR_unlinkat)
933 return my_syscall3(__NR_unlinkat, AT_FDCWD, path, 0);910 return my_syscall3(__NR_unlinkat, AT_FDCWD, path, 0);
934#elif defined(__NR_unlink)
935 return my_syscall1(__NR_unlink, path);
936#else911#else
937 return __nolibc_enosys(__func__, path);912 return my_syscall1(__NR_unlink, path);
938#endif913#endif
939}914}
940 915
tools/include/nolibc/sys/random.h+2−2
@@ -22,13 +22,13 @@ · 21 unmodified lines
22static __attribute__((unused))22static __attribute__((unused))
23ssize_t sys_getrandom(void *buf, size_t buflen, unsigned int flags)23ssize_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
28static __attribute__((unused))28static __attribute__((unused))
29ssize_t getrandom(void *buf, size_t buflen, unsigned int flags)29ssize_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#endif /* _NOLIBC_SYS_RANDOM_H */34#endif /* _NOLIBC_SYS_RANDOM_H */
tools/include/nolibc/sys/timerfd.h+2−6
@@ -34,7 +34,7 @@ int sys_timerfd_gettime(int fd, struct itimerspec *curr_value) · 33 unmodified lines
34{34{
35#if defined(__NR_timerfd_gettime)35#if defined(__NR_timerfd_gettime)
36 return my_syscall2(__NR_timerfd_gettime, fd, curr_value);36 return my_syscall2(__NR_timerfd_gettime, fd, curr_value);
37#elif defined(__NR_timerfd_gettime64)37#else
38 struct __kernel_itimerspec kcurr_value;38 struct __kernel_itimerspec kcurr_value;
39 int ret;39 int ret;
40 40
@@ -42,8 +42,6 @@ int sys_timerfd_gettime(int fd, struct itimerspec *curr_value) · 1 unmodified line
42 __nolibc_timespec_kernel_to_user(&kcurr_value.it_interval, &curr_value->it_interval);42 __nolibc_timespec_kernel_to_user(&kcurr_value.it_interval, &curr_value->it_interval);
43 __nolibc_timespec_kernel_to_user(&kcurr_value.it_value, &curr_value->it_value);43 __nolibc_timespec_kernel_to_user(&kcurr_value.it_value, &curr_value->it_value);
44 return ret;44 return ret;
45#else
46 return __nolibc_enosys(__func__, fd, curr_value);
47#endif45#endif
48}46}
49 47
@@ -60,7 +58,7 @@ int sys_timerfd_settime(int fd, int flags, · 10 unmodified lines
60{58{
61#if defined(__NR_timerfd_settime)59#if defined(__NR_timerfd_settime)
62 return my_syscall4(__NR_timerfd_settime, fd, flags, new_value, old_value);60 return my_syscall4(__NR_timerfd_settime, fd, flags, new_value, old_value);
63#elif defined(__NR_timerfd_settime64)61#else
64 struct __kernel_itimerspec knew_value, kold_value;62 struct __kernel_itimerspec knew_value, kold_value;
65 int ret;63 int ret;
66 64
@@ -72,8 +70,6 @@ int sys_timerfd_settime(int fd, int flags, · 5 unmodified lines
72 __nolibc_timespec_kernel_to_user(&kold_value.it_value, &old_value->it_value);70 __nolibc_timespec_kernel_to_user(&kold_value.it_value, &old_value->it_value);
73 }71 }
74 return ret;72 return ret;
75#else
76 return __nolibc_enosys(__func__, fd, flags, new_value, old_value);
77#endif73#endif
78}74}
79 75
tools/include/nolibc/sys/wait.h+0−17
@@ -16,27 +16,10 @@ · 15 unmodified lines
16 16
17/*17/*
18 * pid_t wait(int *status);18 * pid_t wait(int *status);
19 * pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage);
20 * pid_t waitpid(pid_t pid, int *status, int options);19 * pid_t waitpid(pid_t pid, int *status, int options);
21 * int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);20 * int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);
22 */21 */
23 22
24static __attribute__((unused))
25pid_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
34static __attribute__((unused))
35pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage)
36{
37 return __sysret(sys_wait4(pid, status, options, rusage));
38}
39
40static __attribute__((unused))23static __attribute__((unused))
41int sys_waitid(int which, pid_t pid, siginfo_t *infop, int options, struct rusage *rusage)24int sys_waitid(int which, pid_t pid, siginfo_t *infop, int options, struct rusage *rusage)
42{25{
tools/include/nolibc/time.h+5−8
@@ -45,7 +45,7 @@ int sys_clock_getres(clockid_t clockid, struct timespec *res) · 44 unmodified lines
45{45{
46#if defined(__NR_clock_getres)46#if defined(__NR_clock_getres)
47 return my_syscall2(__NR_clock_getres, clockid, res);47 return my_syscall2(__NR_clock_getres, clockid, res);
48#elif defined(__NR_clock_getres_time64)48#else
49 struct __kernel_timespec kres;49 struct __kernel_timespec kres;
50 int ret;50 int ret;
51 51
@@ -53,8 +53,6 @@ int sys_clock_getres(clockid_t clockid, struct timespec *res) · 1 unmodified line
53 if (res)53 if (res)
54 __nolibc_timespec_kernel_to_user(&kres, res);54 __nolibc_timespec_kernel_to_user(&kres, res);
55 return ret;55 return ret;
56#else
57 return __nolibc_enosys(__func__, clockid, res);
58#endif56#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#if defined(__NR_clock_gettime)68#if defined(__NR_clock_gettime)
71 return my_syscall2(__NR_clock_gettime, clockid, tp);69 return my_syscall2(__NR_clock_gettime, clockid, tp);
72#elif defined(__NR_clock_gettime64)70#else
73 struct __kernel_timespec ktp;71 struct __kernel_timespec ktp;
74 int ret;72 int ret;
75 73
@@ -77,8 +75,6 @@ int sys_clock_gettime(clockid_t clockid, struct timespec *tp) · 1 unmodified line
77 if (tp)75 if (tp)
78 __nolibc_timespec_kernel_to_user(&ktp, tp);76 __nolibc_timespec_kernel_to_user(&ktp, tp);
79 return ret;77 return ret;
80#else
81 return __nolibc_enosys(__func__, clockid, tp);
82#endif78#endif
83}79}
84 80
@@ -133,7 +129,8 @@ static __attribute__((unused)) · 48 unmodified lines
133int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp,129int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp,
134 struct timespec *rmtp)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
139static __inline__136static __inline__
@@ -145,7 +142,7 @@ double difftime(time_t time1, time_t time2) · 5 unmodified lines
145static __inline__142static __inline__
146int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)143int 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
tools/include/nolibc/unistd.h+1−1
@@ -33,7 +33,7 @@ · 32 unmodified lines
33static __attribute__((unused))33static __attribute__((unused))
34int sys_faccessat(int fd, const char *path, int amode, int flag)34int 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
39static __attribute__((unused))39static __attribute__((unused))

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t