* [PATCH 01/10] tools/nolibc: prepare for headers in subdirectories
2025-04-16 12:06 [PATCH 00/10] tools/nolibc: split out functionality into new headers Thomas Weißschuh
@ 2025-04-16 12:06 ` Thomas Weißschuh
2025-04-16 12:06 ` [PATCH 02/10] tools/nolibc: add elf.h Thomas Weißschuh
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Thomas Weißschuh @ 2025-04-16 12:06 UTC (permalink / raw)
To: Willy Tarreau, Thomas Weißschuh; +Cc: linux-kernel, Thomas Weißschuh
To support headers in subdirectories (like sys/), their subdirectory needs
to be preserved during installation into the sysroot.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
tools/include/nolibc/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile
index f9702877ac21ab5ad30df1740e40e67f477f3824..f562cb53be10efc4e0758b8836cf3ace5b3c151f 100644
--- a/tools/include/nolibc/Makefile
+++ b/tools/include/nolibc/Makefile
@@ -72,7 +72,7 @@ help:
headers:
$(Q)mkdir -p $(OUTPUT)sysroot
$(Q)mkdir -p $(OUTPUT)sysroot/include
- $(Q)cp $(all_files) $(OUTPUT)sysroot/include/
+ $(Q)cp --parents $(all_files) $(OUTPUT)sysroot/include/
$(Q)if [ "$(ARCH)" = "x86" ]; then \
sed -e \
's,^#ifndef _NOLIBC_ARCH_X86_64_H,#if !defined(_NOLIBC_ARCH_X86_64_H) \&\& defined(__x86_64__),' \
--
2.49.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 02/10] tools/nolibc: add elf.h
2025-04-16 12:06 [PATCH 00/10] tools/nolibc: split out functionality into new headers Thomas Weißschuh
2025-04-16 12:06 ` [PATCH 01/10] tools/nolibc: prepare for headers in subdirectories Thomas Weißschuh
@ 2025-04-16 12:06 ` Thomas Weißschuh
2025-04-16 12:06 ` [PATCH 03/10] tools/nolibc: move open() and friends to fcntl.h Thomas Weißschuh
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Thomas Weißschuh @ 2025-04-16 12:06 UTC (permalink / raw)
To: Willy Tarreau, Thomas Weißschuh; +Cc: linux-kernel, Thomas Weißschuh
The UAPI header do already provide an elf.h implementation.
Reexport it under its libc name.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
tools/include/nolibc/Makefile | 1 +
tools/include/nolibc/elf.h | 15 +++++++++++++++
tools/include/nolibc/nolibc.h | 1 +
3 files changed, 17 insertions(+)
diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile
index f562cb53be10efc4e0758b8836cf3ace5b3c151f..fd76d267d79a8533b7e78375c30324c962b01973 100644
--- a/tools/include/nolibc/Makefile
+++ b/tools/include/nolibc/Makefile
@@ -30,6 +30,7 @@ all_files := \
crt.h \
ctype.h \
dirent.h \
+ elf.h \
errno.h \
limits.h \
nolibc.h \
diff --git a/tools/include/nolibc/elf.h b/tools/include/nolibc/elf.h
new file mode 100644
index 0000000000000000000000000000000000000000..beb0b3a87569a3037055c8fe7e9b086a26ca7d13
--- /dev/null
+++ b/tools/include/nolibc/elf.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
+/*
+ * Shim elf.h header for NOLIBC.
+ * Copyright (C) 2025 Thomas Weißschuh <thomas.weissschuh@linutronix.de>
+ */
+
+#ifndef _NOLIBC_SYS_ELF_H
+#define _NOLIBC_SYS_ELF_H
+
+#include <linux/elf.h>
+
+/* make sure to include all global symbols */
+#include "nolibc.h"
+
+#endif /* _NOLIBC_SYS_ELF_H */
diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h
index 70872401aca8d5aa37b12ee585193353f692576d..127f0d9068c6508bd45acfe0ebf2ce15acc422b0 100644
--- a/tools/include/nolibc/nolibc.h
+++ b/tools/include/nolibc/nolibc.h
@@ -97,6 +97,7 @@
#include "types.h"
#include "sys.h"
#include "ctype.h"
+#include "elf.h"
#include "signal.h"
#include "unistd.h"
#include "stdio.h"
--
2.49.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 03/10] tools/nolibc: move open() and friends to fcntl.h
2025-04-16 12:06 [PATCH 00/10] tools/nolibc: split out functionality into new headers Thomas Weißschuh
2025-04-16 12:06 ` [PATCH 01/10] tools/nolibc: prepare for headers in subdirectories Thomas Weißschuh
2025-04-16 12:06 ` [PATCH 02/10] tools/nolibc: add elf.h Thomas Weißschuh
@ 2025-04-16 12:06 ` Thomas Weißschuh
2025-04-16 12:06 ` [PATCH 04/10] tools/nolibc: move getauxval() to sys/auxv.h Thomas Weißschuh
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Thomas Weißschuh @ 2025-04-16 12:06 UTC (permalink / raw)
To: Willy Tarreau, Thomas Weißschuh; +Cc: linux-kernel, Thomas Weißschuh
This is the location regular userspace expects these definitions.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
tools/include/nolibc/Makefile | 1 +
tools/include/nolibc/dirent.h | 1 +
tools/include/nolibc/fcntl.h | 69 +++++++++++++++++++++++++++++++++++++++++++
tools/include/nolibc/nolibc.h | 1 +
tools/include/nolibc/sys.h | 52 --------------------------------
5 files changed, 72 insertions(+), 52 deletions(-)
diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile
index fd76d267d79a8533b7e78375c30324c962b01973..2132e4f4d2165729ec6d10860d0586f1b71ee0fb 100644
--- a/tools/include/nolibc/Makefile
+++ b/tools/include/nolibc/Makefile
@@ -32,6 +32,7 @@ all_files := \
dirent.h \
elf.h \
errno.h \
+ fcntl.h \
limits.h \
nolibc.h \
signal.h \
diff --git a/tools/include/nolibc/dirent.h b/tools/include/nolibc/dirent.h
index c5c30d0dd6806b1bec2fa8120a3df29aaa201393..d3fb9500c60a31bc1b75601d78871df82ca75f7d 100644
--- a/tools/include/nolibc/dirent.h
+++ b/tools/include/nolibc/dirent.h
@@ -9,6 +9,7 @@
#include "stdint.h"
#include "types.h"
+#include "fcntl.h"
#include <linux/limits.h>
diff --git a/tools/include/nolibc/fcntl.h b/tools/include/nolibc/fcntl.h
new file mode 100644
index 0000000000000000000000000000000000000000..5feb08ad54a7d943b8100eac21f4058310efea91
--- /dev/null
+++ b/tools/include/nolibc/fcntl.h
@@ -0,0 +1,69 @@
+/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
+/*
+ * fcntl definition for NOLIBC
+ * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu>
+ */
+
+#ifndef _NOLIBC_FCNTL_H
+#define _NOLIBC_FCNTL_H
+
+#include "arch.h"
+#include "types.h"
+#include "sys.h"
+
+/*
+ * int openat(int dirfd, const char *path, int flags[, mode_t mode]);
+ */
+
+static __attribute__((unused))
+int sys_openat(int dirfd, const char *path, int flags, mode_t mode)
+{
+ return my_syscall4(__NR_openat, dirfd, path, flags, mode);
+}
+
+static __attribute__((unused))
+int openat(int dirfd, const char *path, int flags, ...)
+{
+ mode_t mode = 0;
+
+ if (flags & O_CREAT) {
+ va_list args;
+
+ va_start(args, flags);
+ mode = va_arg(args, mode_t);
+ va_end(args);
+ }
+
+ return __sysret(sys_openat(dirfd, path, flags, mode));
+}
+
+/*
+ * int open(const char *path, int flags[, mode_t mode]);
+ */
+
+static __attribute__((unused))
+int sys_open(const char *path, int flags, mode_t mode)
+{
+ return my_syscall4(__NR_openat, AT_FDCWD, path, flags, mode);
+}
+
+static __attribute__((unused))
+int open(const char *path, int flags, ...)
+{
+ mode_t mode = 0;
+
+ if (flags & O_CREAT) {
+ va_list args;
+
+ va_start(args, flags);
+ mode = va_arg(args, mode_t);
+ va_end(args);
+ }
+
+ return __sysret(sys_open(path, flags, mode));
+}
+
+/* make sure to include all global symbols */
+#include "nolibc.h"
+
+#endif /* _NOLIBC_FCNTL_H */
diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h
index 127f0d9068c6508bd45acfe0ebf2ce15acc422b0..bb4183a8fdc41023d9b8b37fe35ec37ca408b4c6 100644
--- a/tools/include/nolibc/nolibc.h
+++ b/tools/include/nolibc/nolibc.h
@@ -106,6 +106,7 @@
#include "time.h"
#include "stackprotector.h"
#include "dirent.h"
+#include "fcntl.h"
/* Used by programs to avoid std includes */
#define NOLIBC
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index 08c1c074bec89a27e53e5d461a3ebbf71ec323d1..5fa351e6a3512a3d0c609867244ac91e8563ab2a 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -764,58 +764,6 @@ int mount(const char *src, const char *tgt,
return __sysret(sys_mount(src, tgt, fst, flags, data));
}
-/*
- * int openat(int dirfd, const char *path, int flags[, mode_t mode]);
- */
-
-static __attribute__((unused))
-int sys_openat(int dirfd, const char *path, int flags, mode_t mode)
-{
- return my_syscall4(__NR_openat, dirfd, path, flags, mode);
-}
-
-static __attribute__((unused))
-int openat(int dirfd, const char *path, int flags, ...)
-{
- mode_t mode = 0;
-
- if (flags & O_CREAT) {
- va_list args;
-
- va_start(args, flags);
- mode = va_arg(args, mode_t);
- va_end(args);
- }
-
- return __sysret(sys_openat(dirfd, path, flags, mode));
-}
-
-/*
- * int open(const char *path, int flags[, mode_t mode]);
- */
-
-static __attribute__((unused))
-int sys_open(const char *path, int flags, mode_t mode)
-{
- return my_syscall4(__NR_openat, AT_FDCWD, path, flags, mode);
-}
-
-static __attribute__((unused))
-int open(const char *path, int flags, ...)
-{
- mode_t mode = 0;
-
- if (flags & O_CREAT) {
- va_list args;
-
- va_start(args, flags);
- mode = va_arg(args, mode_t);
- va_end(args);
- }
-
- return __sysret(sys_open(path, flags, mode));
-}
-
/*
* int pipe2(int pipefd[2], int flags);
--
2.49.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 04/10] tools/nolibc: move getauxval() to sys/auxv.h
2025-04-16 12:06 [PATCH 00/10] tools/nolibc: split out functionality into new headers Thomas Weißschuh
` (2 preceding siblings ...)
2025-04-16 12:06 ` [PATCH 03/10] tools/nolibc: move open() and friends to fcntl.h Thomas Weißschuh
@ 2025-04-16 12:06 ` Thomas Weißschuh
2025-04-16 12:06 ` [PATCH 05/10] tools/nolibc: move mmap() and friends to sys/mman.h Thomas Weißschuh
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Thomas Weißschuh @ 2025-04-16 12:06 UTC (permalink / raw)
To: Willy Tarreau, Thomas Weißschuh; +Cc: linux-kernel, Thomas Weißschuh
This is the location regular userspace expects the definition.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
tools/include/nolibc/Makefile | 1 +
tools/include/nolibc/nolibc.h | 1 +
tools/include/nolibc/stdlib.h | 26 --------------------------
tools/include/nolibc/sys/auxv.h | 41 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 43 insertions(+), 26 deletions(-)
diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile
index 2132e4f4d2165729ec6d10860d0586f1b71ee0fb..a3781f39692532fb75c7aaf70f65b2d5bf7c7abd 100644
--- a/tools/include/nolibc/Makefile
+++ b/tools/include/nolibc/Makefile
@@ -44,6 +44,7 @@ all_files := \
stdlib.h \
string.h \
sys.h \
+ sys/auxv.h \
time.h \
types.h \
unistd.h \
diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h
index bb4183a8fdc41023d9b8b37fe35ec37ca408b4c6..0d8c49e0dddc595c2f029788ecb5b51231e2695a 100644
--- a/tools/include/nolibc/nolibc.h
+++ b/tools/include/nolibc/nolibc.h
@@ -96,6 +96,7 @@
#include "arch.h"
#include "types.h"
#include "sys.h"
+#include "sys/auxv.h"
#include "ctype.h"
#include "elf.h"
#include "signal.h"
diff --git a/tools/include/nolibc/stdlib.h b/tools/include/nolibc/stdlib.h
index 86ad378ab1ea220559d5ab1adc4bb9972977ba9e..ba8a1427121fc543fc83646e5108c645cbdd62a2 100644
--- a/tools/include/nolibc/stdlib.h
+++ b/tools/include/nolibc/stdlib.h
@@ -102,32 +102,6 @@ char *getenv(const char *name)
return NULL;
}
-static __attribute__((unused))
-unsigned long getauxval(unsigned long type)
-{
- const unsigned long *auxv = _auxv;
- unsigned long ret;
-
- if (!auxv)
- return 0;
-
- while (1) {
- if (!auxv[0] && !auxv[1]) {
- ret = 0;
- break;
- }
-
- if (auxv[0] == type) {
- ret = auxv[1];
- break;
- }
-
- auxv += 2;
- }
-
- return ret;
-}
-
static __attribute__((unused))
void *malloc(size_t len)
{
diff --git a/tools/include/nolibc/sys/auxv.h b/tools/include/nolibc/sys/auxv.h
new file mode 100644
index 0000000000000000000000000000000000000000..04c2b9cbe51a262025bbbc7c74a0640c71529eab
--- /dev/null
+++ b/tools/include/nolibc/sys/auxv.h
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
+/*
+ * auxv definitions for NOLIBC
+ * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu>
+ */
+
+#ifndef _NOLIBC_SYS_AUXV_H
+#define _NOLIBC_SYS_AUXV_H
+
+#include "../crt.h"
+
+static __attribute__((unused))
+unsigned long getauxval(unsigned long type)
+{
+ const unsigned long *auxv = _auxv;
+ unsigned long ret;
+
+ if (!auxv)
+ return 0;
+
+ while (1) {
+ if (!auxv[0] && !auxv[1]) {
+ ret = 0;
+ break;
+ }
+
+ if (auxv[0] == type) {
+ ret = auxv[1];
+ break;
+ }
+
+ auxv += 2;
+ }
+
+ return ret;
+}
+
+/* make sure to include all global symbols */
+#include "../nolibc.h"
+
+#endif /* _NOLIBC_SYS_AUXV_H */
--
2.49.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 05/10] tools/nolibc: move mmap() and friends to sys/mman.h
2025-04-16 12:06 [PATCH 00/10] tools/nolibc: split out functionality into new headers Thomas Weißschuh
` (3 preceding siblings ...)
2025-04-16 12:06 ` [PATCH 04/10] tools/nolibc: move getauxval() to sys/auxv.h Thomas Weißschuh
@ 2025-04-16 12:06 ` Thomas Weißschuh
2025-04-16 12:06 ` [PATCH 06/10] tools/nolibc: move stat() and friends to sys/stat.h Thomas Weißschuh
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Thomas Weißschuh @ 2025-04-16 12:06 UTC (permalink / raw)
To: Willy Tarreau, Thomas Weißschuh; +Cc: linux-kernel, Thomas Weißschuh
This is the location regular userspace expects these definitions.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
tools/include/nolibc/Makefile | 1 +
tools/include/nolibc/nolibc.h | 1 +
tools/include/nolibc/sys.h | 48 -------------------------------
tools/include/nolibc/sys/mman.h | 63 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 65 insertions(+), 48 deletions(-)
diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile
index a3781f39692532fb75c7aaf70f65b2d5bf7c7abd..ca8817e84c3a5b4df3d373e60a956945d2665b94 100644
--- a/tools/include/nolibc/Makefile
+++ b/tools/include/nolibc/Makefile
@@ -45,6 +45,7 @@ all_files := \
string.h \
sys.h \
sys/auxv.h \
+ sys/mman.h \
time.h \
types.h \
unistd.h \
diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h
index 0d8c49e0dddc595c2f029788ecb5b51231e2695a..ffdf501db1b6faebe2f0d5f56bd3c31c1a8ec164 100644
--- a/tools/include/nolibc/nolibc.h
+++ b/tools/include/nolibc/nolibc.h
@@ -97,6 +97,7 @@
#include "types.h"
#include "sys.h"
#include "sys/auxv.h"
+#include "sys/mman.h"
#include "ctype.h"
#include "elf.h"
#include "signal.h"
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index 5fa351e6a3512a3d0c609867244ac91e8563ab2a..13e6b2479fbf8bcb36843072665e50046c5f41eb 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -24,7 +24,6 @@
#include <linux/resource.h>
#include <linux/utsname.h>
-#include "arch.h"
#include "errno.h"
#include "stdarg.h"
#include "types.h"
@@ -697,53 +696,6 @@ int mknod(const char *path, mode_t mode, dev_t dev)
return __sysret(sys_mknod(path, mode, dev));
}
-#ifndef sys_mmap
-static __attribute__((unused))
-void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd,
- off_t offset)
-{
- int n;
-
-#if defined(__NR_mmap2)
- n = __NR_mmap2;
- offset >>= 12;
-#else
- n = __NR_mmap;
-#endif
-
- return (void *)my_syscall6(n, addr, length, prot, flags, fd, offset);
-}
-#endif
-
-/* Note that on Linux, MAP_FAILED is -1 so we can use the generic __sysret()
- * which returns -1 upon error and still satisfy user land that checks for
- * MAP_FAILED.
- */
-
-static __attribute__((unused))
-void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
-{
- void *ret = sys_mmap(addr, length, prot, flags, fd, offset);
-
- if ((unsigned long)ret >= -4095UL) {
- SET_ERRNO(-(long)ret);
- ret = MAP_FAILED;
- }
- return ret;
-}
-
-static __attribute__((unused))
-int sys_munmap(void *addr, size_t length)
-{
- return my_syscall2(__NR_munmap, addr, length);
-}
-
-static __attribute__((unused))
-int munmap(void *addr, size_t length)
-{
- return __sysret(sys_munmap(addr, length));
-}
-
/*
* int mount(const char *source, const char *target,
* const char *fstype, unsigned long flags,
diff --git a/tools/include/nolibc/sys/mman.h b/tools/include/nolibc/sys/mman.h
new file mode 100644
index 0000000000000000000000000000000000000000..ad9d06b6b7919ec76a0652266158366cf639a77a
--- /dev/null
+++ b/tools/include/nolibc/sys/mman.h
@@ -0,0 +1,63 @@
+/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
+/*
+ * mm definition for NOLIBC
+ * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu>
+ */
+
+#ifndef _NOLIBC_SYS_MMAN_H
+#define _NOLIBC_SYS_MMAN_H
+
+#include "../arch.h"
+#include "../sys.h"
+
+#ifndef sys_mmap
+static __attribute__((unused))
+void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd,
+ off_t offset)
+{
+ int n;
+
+#if defined(__NR_mmap2)
+ n = __NR_mmap2;
+ offset >>= 12;
+#else
+ n = __NR_mmap;
+#endif
+
+ return (void *)my_syscall6(n, addr, length, prot, flags, fd, offset);
+}
+#endif
+
+/* Note that on Linux, MAP_FAILED is -1 so we can use the generic __sysret()
+ * which returns -1 upon error and still satisfy user land that checks for
+ * MAP_FAILED.
+ */
+
+static __attribute__((unused))
+void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
+{
+ void *ret = sys_mmap(addr, length, prot, flags, fd, offset);
+
+ if ((unsigned long)ret >= -4095UL) {
+ SET_ERRNO(-(long)ret);
+ ret = MAP_FAILED;
+ }
+ return ret;
+}
+
+static __attribute__((unused))
+int sys_munmap(void *addr, size_t length)
+{
+ return my_syscall2(__NR_munmap, addr, length);
+}
+
+static __attribute__((unused))
+int munmap(void *addr, size_t length)
+{
+ return __sysret(sys_munmap(addr, length));
+}
+
+/* make sure to include all global symbols */
+#include "../nolibc.h"
+
+#endif /* _NOLIBC_SYS_MMAN_H */
--
2.49.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 06/10] tools/nolibc: move stat() and friends to sys/stat.h
2025-04-16 12:06 [PATCH 00/10] tools/nolibc: split out functionality into new headers Thomas Weißschuh
` (4 preceding siblings ...)
2025-04-16 12:06 ` [PATCH 05/10] tools/nolibc: move mmap() and friends to sys/mman.h Thomas Weißschuh
@ 2025-04-16 12:06 ` Thomas Weißschuh
2025-04-16 12:06 ` [PATCH 07/10] tools/nolibc: move syscall() to sys/syscall.h Thomas Weißschuh
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Thomas Weißschuh @ 2025-04-16 12:06 UTC (permalink / raw)
To: Willy Tarreau, Thomas Weißschuh; +Cc: linux-kernel, Thomas Weißschuh
This is the location regular userspace expects these definitions.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
tools/include/nolibc/Makefile | 1 +
tools/include/nolibc/nolibc.h | 1 +
tools/include/nolibc/sys.h | 56 -------------------------------
tools/include/nolibc/sys/stat.h | 74 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 76 insertions(+), 56 deletions(-)
diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile
index ca8817e84c3a5b4df3d373e60a956945d2665b94..747d73b453680a32d1b8748640f2ebd1ae9b1fb4 100644
--- a/tools/include/nolibc/Makefile
+++ b/tools/include/nolibc/Makefile
@@ -46,6 +46,7 @@ all_files := \
sys.h \
sys/auxv.h \
sys/mman.h \
+ sys/stat.h \
time.h \
types.h \
unistd.h \
diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h
index ffdf501db1b6faebe2f0d5f56bd3c31c1a8ec164..8296cbbeebe994aa335b561a2d9986e529e001a6 100644
--- a/tools/include/nolibc/nolibc.h
+++ b/tools/include/nolibc/nolibc.h
@@ -98,6 +98,7 @@
#include "sys.h"
#include "sys/auxv.h"
#include "sys/mman.h"
+#include "sys/stat.h"
#include "ctype.h"
#include "elf.h"
#include "signal.h"
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index 13e6b2479fbf8bcb36843072665e50046c5f41eb..c76dc80147281041afa1cb443d01897d186f7168 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -968,62 +968,6 @@ pid_t setsid(void)
return __sysret(sys_setsid());
}
-/*
- * int statx(int fd, const char *path, int flags, unsigned int mask, struct statx *buf);
- * int stat(const char *path, struct stat *buf);
- */
-
-static __attribute__((unused))
-int sys_statx(int fd, const char *path, int flags, unsigned int mask, struct statx *buf)
-{
-#ifdef __NR_statx
- return my_syscall5(__NR_statx, fd, path, flags, mask, buf);
-#else
- return __nolibc_enosys(__func__, fd, path, flags, mask, buf);
-#endif
-}
-
-static __attribute__((unused))
-int statx(int fd, const char *path, int flags, unsigned int mask, struct statx *buf)
-{
- return __sysret(sys_statx(fd, path, flags, mask, buf));
-}
-
-
-static __attribute__((unused))
-int stat(const char *path, struct stat *buf)
-{
- struct statx statx;
- long ret;
-
- ret = __sysret(sys_statx(AT_FDCWD, path, AT_NO_AUTOMOUNT, STATX_BASIC_STATS, &statx));
- if (ret == -1)
- return ret;
-
- buf->st_dev = ((statx.stx_dev_minor & 0xff)
- | (statx.stx_dev_major << 8)
- | ((statx.stx_dev_minor & ~0xff) << 12));
- buf->st_ino = statx.stx_ino;
- buf->st_mode = statx.stx_mode;
- buf->st_nlink = statx.stx_nlink;
- buf->st_uid = statx.stx_uid;
- buf->st_gid = statx.stx_gid;
- buf->st_rdev = ((statx.stx_rdev_minor & 0xff)
- | (statx.stx_rdev_major << 8)
- | ((statx.stx_rdev_minor & ~0xff) << 12));
- buf->st_size = statx.stx_size;
- buf->st_blksize = statx.stx_blksize;
- buf->st_blocks = statx.stx_blocks;
- buf->st_atim.tv_sec = statx.stx_atime.tv_sec;
- buf->st_atim.tv_nsec = statx.stx_atime.tv_nsec;
- buf->st_mtim.tv_sec = statx.stx_mtime.tv_sec;
- buf->st_mtim.tv_nsec = statx.stx_mtime.tv_nsec;
- buf->st_ctim.tv_sec = statx.stx_ctime.tv_sec;
- buf->st_ctim.tv_nsec = statx.stx_ctime.tv_nsec;
-
- return 0;
-}
-
/*
* int symlink(const char *old, const char *new);
diff --git a/tools/include/nolibc/sys/stat.h b/tools/include/nolibc/sys/stat.h
new file mode 100644
index 0000000000000000000000000000000000000000..0eaf5496ce233a4d8b5a239eef5ecefe05a39dd6
--- /dev/null
+++ b/tools/include/nolibc/sys/stat.h
@@ -0,0 +1,74 @@
+/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
+/*
+ * stat definition for NOLIBC
+ * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu>
+ */
+
+#ifndef _NOLIBC_SYS_STAT_H
+#define _NOLIBC_SYS_STAT_H
+
+#include "../arch.h"
+#include "../types.h"
+#include "../sys.h"
+
+/*
+ * int statx(int fd, const char *path, int flags, unsigned int mask, struct statx *buf);
+ * int stat(const char *path, struct stat *buf);
+ */
+
+static __attribute__((unused))
+int sys_statx(int fd, const char *path, int flags, unsigned int mask, struct statx *buf)
+{
+#ifdef __NR_statx
+ return my_syscall5(__NR_statx, fd, path, flags, mask, buf);
+#else
+ return __nolibc_enosys(__func__, fd, path, flags, mask, buf);
+#endif
+}
+
+static __attribute__((unused))
+int statx(int fd, const char *path, int flags, unsigned int mask, struct statx *buf)
+{
+ return __sysret(sys_statx(fd, path, flags, mask, buf));
+}
+
+
+static __attribute__((unused))
+int stat(const char *path, struct stat *buf)
+{
+ struct statx statx;
+ long ret;
+
+ ret = __sysret(sys_statx(AT_FDCWD, path, AT_NO_AUTOMOUNT, STATX_BASIC_STATS, &statx));
+ if (ret == -1)
+ return ret;
+
+ buf->st_dev = ((statx.stx_dev_minor & 0xff)
+ | (statx.stx_dev_major << 8)
+ | ((statx.stx_dev_minor & ~0xff) << 12));
+ buf->st_ino = statx.stx_ino;
+ buf->st_mode = statx.stx_mode;
+ buf->st_nlink = statx.stx_nlink;
+ buf->st_uid = statx.stx_uid;
+ buf->st_gid = statx.stx_gid;
+ buf->st_rdev = ((statx.stx_rdev_minor & 0xff)
+ | (statx.stx_rdev_major << 8)
+ | ((statx.stx_rdev_minor & ~0xff) << 12));
+ buf->st_size = statx.stx_size;
+ buf->st_blksize = statx.stx_blksize;
+ buf->st_blocks = statx.stx_blocks;
+ buf->st_atim.tv_sec = statx.stx_atime.tv_sec;
+ buf->st_atim.tv_nsec = statx.stx_atime.tv_nsec;
+ buf->st_mtim.tv_sec = statx.stx_mtime.tv_sec;
+ buf->st_mtim.tv_nsec = statx.stx_mtime.tv_nsec;
+ buf->st_ctim.tv_sec = statx.stx_ctime.tv_sec;
+ buf->st_ctim.tv_nsec = statx.stx_ctime.tv_nsec;
+
+ return 0;
+}
+
+
+/* make sure to include all global symbols */
+#include "../nolibc.h"
+
+#endif /* _NOLIBC_SYS_STAT_H */
--
2.49.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 07/10] tools/nolibc: move syscall() to sys/syscall.h
2025-04-16 12:06 [PATCH 00/10] tools/nolibc: split out functionality into new headers Thomas Weißschuh
` (5 preceding siblings ...)
2025-04-16 12:06 ` [PATCH 06/10] tools/nolibc: move stat() and friends to sys/stat.h Thomas Weißschuh
@ 2025-04-16 12:06 ` Thomas Weißschuh
2025-04-16 12:06 ` [PATCH 08/10] tools/nolibc: move gettimeofday() to sys/time.h Thomas Weißschuh
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Thomas Weißschuh @ 2025-04-16 12:06 UTC (permalink / raw)
To: Willy Tarreau, Thomas Weißschuh; +Cc: linux-kernel, Thomas Weißschuh
This is the location regular userspace expects the definition.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
tools/include/nolibc/Makefile | 1 +
tools/include/nolibc/nolibc.h | 1 +
tools/include/nolibc/sys/syscall.h | 19 +++++++++++++++++++
tools/include/nolibc/unistd.h | 6 ------
4 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile
index 747d73b453680a32d1b8748640f2ebd1ae9b1fb4..65c3b90f8ba9213401900a8568469bb2c5770dd6 100644
--- a/tools/include/nolibc/Makefile
+++ b/tools/include/nolibc/Makefile
@@ -47,6 +47,7 @@ all_files := \
sys/auxv.h \
sys/mman.h \
sys/stat.h \
+ sys/syscall.h \
time.h \
types.h \
unistd.h \
diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h
index 8296cbbeebe994aa335b561a2d9986e529e001a6..cb5705d55d80862b0c942bffb6c38db7626aac86 100644
--- a/tools/include/nolibc/nolibc.h
+++ b/tools/include/nolibc/nolibc.h
@@ -99,6 +99,7 @@
#include "sys/auxv.h"
#include "sys/mman.h"
#include "sys/stat.h"
+#include "sys/syscall.h"
#include "ctype.h"
#include "elf.h"
#include "signal.h"
diff --git a/tools/include/nolibc/sys/syscall.h b/tools/include/nolibc/sys/syscall.h
new file mode 100644
index 0000000000000000000000000000000000000000..59efdec8fd1c8cd9f282d1e9ea52431003342a7f
--- /dev/null
+++ b/tools/include/nolibc/sys/syscall.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
+/*
+ * syscall() definition for NOLIBC
+ * Copyright (C) 2024 Thomas Weißschuh <linux@weissschuh.net>
+ */
+
+#ifndef _NOLIBC_SYS_SYSCALL_H
+#define _NOLIBC_SYS_SYSCALL_H
+
+#define __syscall_narg(_0, _1, _2, _3, _4, _5, _6, N, ...) N
+#define _syscall_narg(...) __syscall_narg(__VA_ARGS__, 6, 5, 4, 3, 2, 1, 0)
+#define _syscall(N, ...) __sysret(my_syscall##N(__VA_ARGS__))
+#define _syscall_n(N, ...) _syscall(N, __VA_ARGS__)
+#define syscall(...) _syscall_n(_syscall_narg(__VA_ARGS__), ##__VA_ARGS__)
+
+/* make sure to include all global symbols */
+#include "../nolibc.h"
+
+#endif /* _NOLIBC_SYS_SYSCALL_H */
diff --git a/tools/include/nolibc/unistd.h b/tools/include/nolibc/unistd.h
index e38f3660c0517d757de1ae497b61c4f61b9f1cdc..ac7d53d986cd11ac84dd0a17e5a7055c779b2b10 100644
--- a/tools/include/nolibc/unistd.h
+++ b/tools/include/nolibc/unistd.h
@@ -56,12 +56,6 @@ int tcsetpgrp(int fd, pid_t pid)
return ioctl(fd, TIOCSPGRP, &pid);
}
-#define __syscall_narg(_0, _1, _2, _3, _4, _5, _6, N, ...) N
-#define _syscall_narg(...) __syscall_narg(__VA_ARGS__, 6, 5, 4, 3, 2, 1, 0)
-#define _syscall(N, ...) __sysret(my_syscall##N(__VA_ARGS__))
-#define _syscall_n(N, ...) _syscall(N, __VA_ARGS__)
-#define syscall(...) _syscall_n(_syscall_narg(__VA_ARGS__), ##__VA_ARGS__)
-
/* make sure to include all global symbols */
#include "nolibc.h"
--
2.49.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 08/10] tools/nolibc: move gettimeofday() to sys/time.h
2025-04-16 12:06 [PATCH 00/10] tools/nolibc: split out functionality into new headers Thomas Weißschuh
` (6 preceding siblings ...)
2025-04-16 12:06 ` [PATCH 07/10] tools/nolibc: move syscall() to sys/syscall.h Thomas Weißschuh
@ 2025-04-16 12:06 ` Thomas Weißschuh
2025-04-16 12:06 ` [PATCH 09/10] tools/nolibc: add sys/types.h shim Thomas Weißschuh
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Thomas Weißschuh @ 2025-04-16 12:06 UTC (permalink / raw)
To: Willy Tarreau, Thomas Weißschuh; +Cc: linux-kernel, Thomas Weißschuh
This is the location regular userspace expects this definition.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
tools/include/nolibc/Makefile | 1 +
tools/include/nolibc/nolibc.h | 1 +
tools/include/nolibc/sys.h | 21 ---------------------
tools/include/nolibc/sys/time.h | 36 ++++++++++++++++++++++++++++++++++++
4 files changed, 38 insertions(+), 21 deletions(-)
diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile
index 65c3b90f8ba9213401900a8568469bb2c5770dd6..fd1fc769cbbea7c6af998630020d6d621505f2a1 100644
--- a/tools/include/nolibc/Makefile
+++ b/tools/include/nolibc/Makefile
@@ -48,6 +48,7 @@ all_files := \
sys/mman.h \
sys/stat.h \
sys/syscall.h \
+ sys/time.h \
time.h \
types.h \
unistd.h \
diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h
index cb5705d55d80862b0c942bffb6c38db7626aac86..d84e8610bf1081bc92d969ab760d8277e25a5174 100644
--- a/tools/include/nolibc/nolibc.h
+++ b/tools/include/nolibc/nolibc.h
@@ -100,6 +100,7 @@
#include "sys/mman.h"
#include "sys/stat.h"
#include "sys/syscall.h"
+#include "sys/time.h"
#include "ctype.h"
#include "elf.h"
#include "signal.h"
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index c76dc80147281041afa1cb443d01897d186f7168..aab0685af84f46298aae37e5a1bfecb07861db33 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -487,27 +487,6 @@ int getpagesize(void)
}
-/*
- * int gettimeofday(struct timeval *tv, struct timezone *tz);
- */
-
-static __attribute__((unused))
-int sys_gettimeofday(struct timeval *tv, struct timezone *tz)
-{
-#ifdef __NR_gettimeofday
- return my_syscall2(__NR_gettimeofday, tv, tz);
-#else
- return __nolibc_enosys(__func__, tv, tz);
-#endif
-}
-
-static __attribute__((unused))
-int gettimeofday(struct timeval *tv, struct timezone *tz)
-{
- return __sysret(sys_gettimeofday(tv, tz));
-}
-
-
/*
* uid_t getuid(void);
*/
diff --git a/tools/include/nolibc/sys/time.h b/tools/include/nolibc/sys/time.h
new file mode 100644
index 0000000000000000000000000000000000000000..1d326c05ee627b6bdb7d2777cbb11eea385f2407
--- /dev/null
+++ b/tools/include/nolibc/sys/time.h
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
+/*
+ * time definitions for NOLIBC
+ * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu>
+ */
+
+#ifndef _NOLIBC_SYS_TIME_H
+#define _NOLIBC_SYS_TIME_H
+
+#include "../arch.h"
+#include "../sys.h"
+
+/*
+ * int gettimeofday(struct timeval *tv, struct timezone *tz);
+ */
+
+static __attribute__((unused))
+int sys_gettimeofday(struct timeval *tv, struct timezone *tz)
+{
+#ifdef __NR_gettimeofday
+ return my_syscall2(__NR_gettimeofday, tv, tz);
+#else
+ return __nolibc_enosys(__func__, tv, tz);
+#endif
+}
+
+static __attribute__((unused))
+int gettimeofday(struct timeval *tv, struct timezone *tz)
+{
+ return __sysret(sys_gettimeofday(tv, tz));
+}
+
+/* make sure to include all global symbols */
+#include "../nolibc.h"
+
+#endif /* _NOLIBC_SYS_TIME_H */
--
2.49.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 09/10] tools/nolibc: add sys/types.h shim
2025-04-16 12:06 [PATCH 00/10] tools/nolibc: split out functionality into new headers Thomas Weißschuh
` (7 preceding siblings ...)
2025-04-16 12:06 ` [PATCH 08/10] tools/nolibc: move gettimeofday() to sys/time.h Thomas Weißschuh
@ 2025-04-16 12:06 ` Thomas Weißschuh
2025-04-16 12:06 ` [PATCH 10/10] tools/nolibc: move wait() and friends to sys/wait.h Thomas Weißschuh
2025-04-19 9:02 ` [PATCH 00/10] tools/nolibc: split out functionality into new headers Willy Tarreau
10 siblings, 0 replies; 12+ messages in thread
From: Thomas Weißschuh @ 2025-04-16 12:06 UTC (permalink / raw)
To: Willy Tarreau, Thomas Weißschuh; +Cc: linux-kernel, Thomas Weißschuh
This is the location regular userspace expects the header.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
tools/include/nolibc/Makefile | 1 +
tools/include/nolibc/sys/types.h | 7 +++++++
2 files changed, 8 insertions(+)
diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile
index fd1fc769cbbea7c6af998630020d6d621505f2a1..fec0d4eb2119c8ad2bf65d386b8b5799adf0be5c 100644
--- a/tools/include/nolibc/Makefile
+++ b/tools/include/nolibc/Makefile
@@ -49,6 +49,7 @@ all_files := \
sys/stat.h \
sys/syscall.h \
sys/time.h \
+ sys/types.h \
time.h \
types.h \
unistd.h \
diff --git a/tools/include/nolibc/sys/types.h b/tools/include/nolibc/sys/types.h
new file mode 100644
index 0000000000000000000000000000000000000000..8a264a13275c4ad72cd0345368dc00a731f88cc0
--- /dev/null
+++ b/tools/include/nolibc/sys/types.h
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
+/*
+ * sys/types.h shim for NOLIBC
+ * Copyright (C) 2025 Thomas Weißschuh <thomas.weissschuh@linutronix.de>
+ */
+
+#include "../types.h"
--
2.49.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 10/10] tools/nolibc: move wait() and friends to sys/wait.h
2025-04-16 12:06 [PATCH 00/10] tools/nolibc: split out functionality into new headers Thomas Weißschuh
` (8 preceding siblings ...)
2025-04-16 12:06 ` [PATCH 09/10] tools/nolibc: add sys/types.h shim Thomas Weißschuh
@ 2025-04-16 12:06 ` Thomas Weißschuh
2025-04-19 9:02 ` [PATCH 00/10] tools/nolibc: split out functionality into new headers Willy Tarreau
10 siblings, 0 replies; 12+ messages in thread
From: Thomas Weißschuh @ 2025-04-16 12:06 UTC (permalink / raw)
To: Willy Tarreau, Thomas Weißschuh; +Cc: linux-kernel, Thomas Weißschuh
This is the location regular userspace expects these definitions.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
tools/include/nolibc/Makefile | 1 +
tools/include/nolibc/nolibc.h | 1 +
tools/include/nolibc/sys.h | 53 ------------------------------
tools/include/nolibc/sys/wait.h | 71 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 73 insertions(+), 53 deletions(-)
diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile
index fec0d4eb2119c8ad2bf65d386b8b5799adf0be5c..b5d4479abc3b727b6260b9c6ecd34d2b25906c2b 100644
--- a/tools/include/nolibc/Makefile
+++ b/tools/include/nolibc/Makefile
@@ -50,6 +50,7 @@ all_files := \
sys/syscall.h \
sys/time.h \
sys/types.h \
+ sys/wait.h \
time.h \
types.h \
unistd.h \
diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h
index d84e8610bf1081bc92d969ab760d8277e25a5174..e8843880e4dfca54dcd3f2aec33dab83cb25c17c 100644
--- a/tools/include/nolibc/nolibc.h
+++ b/tools/include/nolibc/nolibc.h
@@ -101,6 +101,7 @@
#include "sys/stat.h"
#include "sys/syscall.h"
#include "sys/time.h"
+#include "sys/wait.h"
#include "ctype.h"
#include "elf.h"
#include "signal.h"
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index aab0685af84f46298aae37e5a1bfecb07861db33..d07456d6e5727cdcb2d4f49c0de73568207a6331 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -1054,59 +1054,6 @@ int unlink(const char *path)
}
-/*
- * pid_t wait(int *status);
- * pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage);
- * pid_t waitpid(pid_t pid, int *status, int options);
- */
-
-static __attribute__((unused))
-pid_t sys_wait4(pid_t pid, int *status, int options, struct rusage *rusage)
-{
-#ifdef __NR_wait4
- return my_syscall4(__NR_wait4, pid, status, options, rusage);
-#else
- return __nolibc_enosys(__func__, pid, status, options, rusage);
-#endif
-}
-
-static __attribute__((unused))
-pid_t wait(int *status)
-{
- return __sysret(sys_wait4(-1, status, 0, NULL));
-}
-
-static __attribute__((unused))
-pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage)
-{
- return __sysret(sys_wait4(pid, status, options, rusage));
-}
-
-
-static __attribute__((unused))
-pid_t waitpid(pid_t pid, int *status, int options)
-{
- return __sysret(sys_wait4(pid, status, options, NULL));
-}
-
-
-/*
- * int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);
- */
-
-static __attribute__((unused))
-int sys_waitid(int which, pid_t pid, siginfo_t *infop, int options, struct rusage *rusage)
-{
- return my_syscall5(__NR_waitid, which, pid, infop, options, rusage);
-}
-
-static __attribute__((unused))
-int waitid(int which, pid_t pid, siginfo_t *infop, int options)
-{
- return __sysret(sys_waitid(which, pid, infop, options, NULL));
-}
-
-
/*
* ssize_t write(int fd, const void *buf, size_t count);
*/
diff --git a/tools/include/nolibc/sys/wait.h b/tools/include/nolibc/sys/wait.h
new file mode 100644
index 0000000000000000000000000000000000000000..1af366a63f2079af587d74389530dbcc9cfb588a
--- /dev/null
+++ b/tools/include/nolibc/sys/wait.h
@@ -0,0 +1,71 @@
+/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
+/*
+ * wait definitions for NOLIBC
+ * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu>
+ */
+
+#ifndef _NOLIBC_SYS_WAIT_H
+#define _NOLIBC_SYS_WAIT_H
+
+#include "../arch.h"
+#include "../std.h"
+#include "../types.h"
+
+/*
+ * pid_t wait(int *status);
+ * pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage);
+ * pid_t waitpid(pid_t pid, int *status, int options);
+ */
+
+static __attribute__((unused))
+pid_t sys_wait4(pid_t pid, int *status, int options, struct rusage *rusage)
+{
+#ifdef __NR_wait4
+ return my_syscall4(__NR_wait4, pid, status, options, rusage);
+#else
+ return __nolibc_enosys(__func__, pid, status, options, rusage);
+#endif
+}
+
+static __attribute__((unused))
+pid_t wait(int *status)
+{
+ return __sysret(sys_wait4(-1, status, 0, NULL));
+}
+
+static __attribute__((unused))
+pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage)
+{
+ return __sysret(sys_wait4(pid, status, options, rusage));
+}
+
+
+static __attribute__((unused))
+pid_t waitpid(pid_t pid, int *status, int options)
+{
+ return __sysret(sys_wait4(pid, status, options, NULL));
+}
+
+
+/*
+ * int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);
+ */
+
+static __attribute__((unused))
+int sys_waitid(int which, pid_t pid, siginfo_t *infop, int options, struct rusage *rusage)
+{
+ return my_syscall5(__NR_waitid, which, pid, infop, options, rusage);
+}
+
+static __attribute__((unused))
+int waitid(int which, pid_t pid, siginfo_t *infop, int options)
+{
+ return __sysret(sys_waitid(which, pid, infop, options, NULL));
+}
+
+
+
+/* make sure to include all global symbols */
+#include "../nolibc.h"
+
+#endif /* _NOLIBC_SYS_WAIT_H */
--
2.49.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 00/10] tools/nolibc: split out functionality into new headers
2025-04-16 12:06 [PATCH 00/10] tools/nolibc: split out functionality into new headers Thomas Weißschuh
` (9 preceding siblings ...)
2025-04-16 12:06 ` [PATCH 10/10] tools/nolibc: move wait() and friends to sys/wait.h Thomas Weißschuh
@ 2025-04-19 9:02 ` Willy Tarreau
10 siblings, 0 replies; 12+ messages in thread
From: Willy Tarreau @ 2025-04-19 9:02 UTC (permalink / raw)
To: Thomas Weißschuh; +Cc: Thomas Weißschuh, linux-kernel
Hi Thomas!
On Wed, Apr 16, 2025 at 02:06:15PM +0200, Thomas Weißschuh wrote:
> Porting applications to nolibc is made harder by the lack of standard
> header names. Split out the existing functionality from the big catch-all
> headers into new dedicated ones.
>
> This series does not introduce any new logic.
>
> The last patch for sys/wait.h will conflict with
> "tools/nolibc: implement waitpid() in terms of waitid()" [0].
> But as both patches will go through the nolibc tree anyways we can take
> care of the conflict there.
>
> Based on linux-nolibc.git/next
>
> [0] https://lore.kernel.org/lkml/20250411-nolibc-kselftest-harness-v3-21-4d9c0295893f@linutronix.de/
>
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Nice work! Now we'll have sys/types.h, which will simplify the port to
many trivial programs that had to use it (as well as the few others of
course, but that one really stands out during tests). And I do appreciate
that we can continue to include everything at once using -include nolibc.h
without having to care for such details.
For the whole series: Acked-by: Willy Tarreau <w@1wt.eu>
Thanks!
Willy
^ permalink raw reply [flat|nested] 12+ messages in thread