Skip to content

Commit 50c19e2

Browse files
committed
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()
2 parents f4e0ff7 + 2d965c1 commit 50c19e2

File tree

12 files changed

+68
-115
lines changed

12 files changed

+68
-115
lines changed

tools/include/nolibc/nolibc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
#include "sched.h"
117117
#include "signal.h"
118118
#include "unistd.h"
119+
#include "stdbool.h"
119120
#include "stdio.h"
120121
#include "stdlib.h"
121122
#include "string.h"

tools/include/nolibc/poll.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ int sys_poll(struct pollfd *fds, int nfds, int timeout)
3939
t.tv_nsec = (timeout % 1000) * 1000000;
4040
}
4141
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);
4442
#else
45-
return __nolibc_enosys(__func__, fds, nfds, timeout);
43+
return my_syscall3(__NR_poll, fds, nfds, timeout);
4644
#endif
4745
}
4846

tools/include/nolibc/std.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ typedef unsigned long nlink_t;
2929
typedef signed long off_t;
3030
typedef signed long blksize_t;
3131
typedef signed long blkcnt_t;
32-
typedef __kernel_old_time_t time_t;
32+
typedef __kernel_time_t time_t;
3333

3434
#endif /* _NOLIBC_STD_H */

tools/include/nolibc/sys.h

Lines changed: 39 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,8 @@ int sys_chmod(const char *path, mode_t mode)
142142
{
143143
#if defined(__NR_fchmodat)
144144
return my_syscall4(__NR_fchmodat, AT_FDCWD, path, mode, 0);
145-
#elif defined(__NR_chmod)
146-
return my_syscall2(__NR_chmod, path, mode);
147145
#else
148-
return __nolibc_enosys(__func__, path, mode);
146+
return my_syscall2(__NR_chmod, path, mode);
149147
#endif
150148
}
151149

@@ -165,10 +163,8 @@ int sys_chown(const char *path, uid_t owner, gid_t group)
165163
{
166164
#if defined(__NR_fchownat)
167165
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);
170166
#else
171-
return __nolibc_enosys(__func__, path, owner, group);
167+
return my_syscall3(__NR_chown, path, owner, group);
172168
#endif
173169
}
174170

@@ -238,11 +234,22 @@ static __attribute__((unused))
238234
int sys_dup2(int old, int new)
239235
{
240236
#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+
241250
return my_syscall3(__NR_dup3, old, new, 0);
242-
#elif defined(__NR_dup2)
243-
return my_syscall2(__NR_dup2, old, new);
244251
#else
245-
return __nolibc_enosys(__func__, old, new);
252+
return my_syscall2(__NR_dup2, old, new);
246253
#endif
247254
}
248255

@@ -327,10 +334,8 @@ pid_t sys_fork(void)
327334
* will not use the rest with no other flag.
328335
*/
329336
return my_syscall5(__NR_clone, SIGCHLD, 0, 0, 0, 0);
330-
#elif defined(__NR_fork)
331-
return my_syscall0(__NR_fork);
332337
#else
333-
return __nolibc_enosys(__func__);
338+
return my_syscall0(__NR_fork);
334339
#endif
335340
}
336341
#endif
@@ -347,7 +352,7 @@ pid_t sys_vfork(void)
347352
{
348353
#if defined(__NR_vfork)
349354
return my_syscall0(__NR_vfork);
350-
#elif defined(__NR_clone3)
355+
#else
351356
/*
352357
* clone() could be used but has different argument orders per
353358
* architecture.
@@ -358,8 +363,6 @@ pid_t sys_vfork(void)
358363
};
359364

360365
return my_syscall2(__NR_clone3, &args, sizeof(args));
361-
#else
362-
return __nolibc_enosys(__func__);
363366
#endif
364367
}
365368
#endif
@@ -569,10 +572,8 @@ int sys_link(const char *old, const char *new)
569572
{
570573
#if defined(__NR_linkat)
571574
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);
574575
#else
575-
return __nolibc_enosys(__func__, old, new);
576+
return my_syscall2(__NR_link, old, new);
576577
#endif
577578
}
578579

@@ -593,41 +594,27 @@ off_t sys_lseek(int fd, off_t offset, int whence)
593594
#if defined(__NR_lseek)
594595
return my_syscall3(__NR_lseek, fd, offset, whence);
595596
#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;
599600

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;
608611
#endif
609612
}
610613

611614
static __attribute__((unused))
612615
off_t lseek(int fd, off_t offset, int whence)
613616
{
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));
631618
}
632619

633620

@@ -640,10 +627,8 @@ int sys_mkdir(const char *path, mode_t mode)
640627
{
641628
#if defined(__NR_mkdirat)
642629
return my_syscall3(__NR_mkdirat, AT_FDCWD, path, mode);
643-
#elif defined(__NR_mkdir)
644-
return my_syscall2(__NR_mkdir, path, mode);
645630
#else
646-
return __nolibc_enosys(__func__, path, mode);
631+
return my_syscall2(__NR_mkdir, path, mode);
647632
#endif
648633
}
649634

@@ -662,10 +647,8 @@ int sys_rmdir(const char *path)
662647
{
663648
#if defined(__NR_rmdir)
664649
return my_syscall1(__NR_rmdir, path);
665-
#elif defined(__NR_unlinkat)
666-
return my_syscall3(__NR_unlinkat, AT_FDCWD, path, AT_REMOVEDIR);
667650
#else
668-
return __nolibc_enosys(__func__, path);
651+
return my_syscall3(__NR_unlinkat, AT_FDCWD, path, AT_REMOVEDIR);
669652
#endif
670653
}
671654

@@ -685,10 +668,8 @@ long sys_mknod(const char *path, mode_t mode, dev_t dev)
685668
{
686669
#if defined(__NR_mknodat)
687670
return my_syscall4(__NR_mknodat, AT_FDCWD, path, mode, dev);
688-
#elif defined(__NR_mknod)
689-
return my_syscall3(__NR_mknod, path, mode, dev);
690671
#else
691-
return __nolibc_enosys(__func__, path, mode, dev);
672+
return my_syscall3(__NR_mknod, path, mode, dev);
692673
#endif
693674
}
694675

@@ -801,16 +782,14 @@ int sys_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeva
801782
t.tv_nsec = timeout->tv_usec * 1000;
802783
}
803784
return my_syscall6(__NR_pselect6, nfds, rfds, wfds, efds, timeout ? &t : NULL, NULL);
804-
#elif defined(__NR_pselect6_time64)
785+
#else
805786
struct __kernel_timespec t;
806787

807788
if (timeout) {
808789
t.tv_sec = timeout->tv_sec;
809790
t.tv_nsec = timeout->tv_usec * 1000;
810791
}
811792
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);
814793
#endif
815794
}
816795

@@ -874,10 +853,8 @@ int sys_symlink(const char *old, const char *new)
874853
{
875854
#if defined(__NR_symlinkat)
876855
return my_syscall3(__NR_symlinkat, old, AT_FDCWD, new);
877-
#elif defined(__NR_symlink)
878-
return my_syscall2(__NR_symlink, old, new);
879856
#else
880-
return __nolibc_enosys(__func__, old, new);
857+
return my_syscall2(__NR_symlink, old, new);
881858
#endif
882859
}
883860

@@ -931,10 +908,8 @@ int sys_unlink(const char *path)
931908
{
932909
#if defined(__NR_unlinkat)
933910
return my_syscall3(__NR_unlinkat, AT_FDCWD, path, 0);
934-
#elif defined(__NR_unlink)
935-
return my_syscall1(__NR_unlink, path);
936911
#else
937-
return __nolibc_enosys(__func__, path);
912+
return my_syscall1(__NR_unlink, path);
938913
#endif
939914
}
940915

tools/include/nolibc/sys/random.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
static __attribute__((unused))
2323
ssize_t sys_getrandom(void *buf, size_t buflen, unsigned int flags)
2424
{
25-
return my_syscall3(__NR_getrandom, buf, buflen, flags);
25+
return my_syscall3(__NR_getrandom, buf, buflen, flags);
2626
}
2727

2828
static __attribute__((unused))
2929
ssize_t getrandom(void *buf, size_t buflen, unsigned int flags)
3030
{
31-
return __sysret(sys_getrandom(buf, buflen, flags));
31+
return __sysret(sys_getrandom(buf, buflen, flags));
3232
}
3333

3434
#endif /* _NOLIBC_SYS_RANDOM_H */

tools/include/nolibc/sys/timerfd.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,14 @@ int sys_timerfd_gettime(int fd, struct itimerspec *curr_value)
3434
{
3535
#if defined(__NR_timerfd_gettime)
3636
return my_syscall2(__NR_timerfd_gettime, fd, curr_value);
37-
#elif defined(__NR_timerfd_gettime64)
37+
#else
3838
struct __kernel_itimerspec kcurr_value;
3939
int ret;
4040

4141
ret = my_syscall2(__NR_timerfd_gettime64, fd, &kcurr_value);
4242
__nolibc_timespec_kernel_to_user(&kcurr_value.it_interval, &curr_value->it_interval);
4343
__nolibc_timespec_kernel_to_user(&kcurr_value.it_value, &curr_value->it_value);
4444
return ret;
45-
#else
46-
return __nolibc_enosys(__func__, fd, curr_value);
4745
#endif
4846
}
4947

@@ -60,7 +58,7 @@ int sys_timerfd_settime(int fd, int flags,
6058
{
6159
#if defined(__NR_timerfd_settime)
6260
return my_syscall4(__NR_timerfd_settime, fd, flags, new_value, old_value);
63-
#elif defined(__NR_timerfd_settime64)
61+
#else
6462
struct __kernel_itimerspec knew_value, kold_value;
6563
int ret;
6664

@@ -72,8 +70,6 @@ int sys_timerfd_settime(int fd, int flags,
7270
__nolibc_timespec_kernel_to_user(&kold_value.it_value, &old_value->it_value);
7371
}
7472
return ret;
75-
#else
76-
return __nolibc_enosys(__func__, fd, flags, new_value, old_value);
7773
#endif
7874
}
7975

tools/include/nolibc/sys/wait.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,10 @@
1616

1717
/*
1818
* pid_t wait(int *status);
19-
* pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage);
2019
* pid_t waitpid(pid_t pid, int *status, int options);
2120
* int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);
2221
*/
2322

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-
4023
static __attribute__((unused))
4124
int sys_waitid(int which, pid_t pid, siginfo_t *infop, int options, struct rusage *rusage)
4225
{

tools/include/nolibc/time.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,14 @@ int sys_clock_getres(clockid_t clockid, struct timespec *res)
4545
{
4646
#if defined(__NR_clock_getres)
4747
return my_syscall2(__NR_clock_getres, clockid, res);
48-
#elif defined(__NR_clock_getres_time64)
48+
#else
4949
struct __kernel_timespec kres;
5050
int ret;
5151

5252
ret = my_syscall2(__NR_clock_getres_time64, clockid, &kres);
5353
if (res)
5454
__nolibc_timespec_kernel_to_user(&kres, res);
5555
return ret;
56-
#else
57-
return __nolibc_enosys(__func__, clockid, res);
5856
#endif
5957
}
6058

@@ -69,16 +67,14 @@ int sys_clock_gettime(clockid_t clockid, struct timespec *tp)
6967
{
7068
#if defined(__NR_clock_gettime)
7169
return my_syscall2(__NR_clock_gettime, clockid, tp);
72-
#elif defined(__NR_clock_gettime64)
70+
#else
7371
struct __kernel_timespec ktp;
7472
int ret;
7573

7674
ret = my_syscall2(__NR_clock_gettime64, clockid, &ktp);
7775
if (tp)
7876
__nolibc_timespec_kernel_to_user(&ktp, tp);
7977
return ret;
80-
#else
81-
return __nolibc_enosys(__func__, clockid, tp);
8278
#endif
8379
}
8480

@@ -133,7 +129,8 @@ static __attribute__((unused))
133129
int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp,
134130
struct timespec *rmtp)
135131
{
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);
137134
}
138135

139136
static __inline__
@@ -145,7 +142,7 @@ double difftime(time_t time1, time_t time2)
145142
static __inline__
146143
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
147144
{
148-
return clock_nanosleep(CLOCK_REALTIME, 0, rqtp, rmtp);
145+
return __sysret(sys_clock_nanosleep(CLOCK_REALTIME, 0, rqtp, rmtp));
149146
}
150147

151148

tools/include/nolibc/unistd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
static __attribute__((unused))
3434
int sys_faccessat(int fd, const char *path, int amode, int flag)
3535
{
36-
return my_syscall4(__NR_faccessat, fd, path, amode, flag);
36+
return my_syscall4(__NR_faccessat, fd, path, amode, flag);
3737
}
3838

3939
static __attribute__((unused))

0 commit comments

Comments
 (0)