diff mbox series

[1/6] tools/nolibc: add support for waitid()

Message ID 20241221-nolibc-rv32-v1-1-d9ef6dab7c63@weissschuh.net (mailing list archive)
State New
Headers show
Series selftests/nolibc: wire up riscv32 | expand

Commit Message

Thomas Weißschuh Dec. 21, 2024, 2:44 p.m. UTC
waitid() is the modern variant of the family of wait-like syscalls.
Some architectures have dropped support for wait(), wait4() and waitpid()
but all of them support waitid().
It is more flexible and easier to use than the older ones.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 tools/include/nolibc/sys.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Comments

Willy Tarreau Dec. 21, 2024, 4:35 p.m. UTC | #1
Hi Thomas!

On Sat, Dec 21, 2024 at 03:44:28PM +0100, Thomas Weißschuh wrote:
> waitid() is the modern variant of the family of wait-like syscalls.
> Some architectures have dropped support for wait(), wait4() and waitpid()
> but all of them support waitid().
> It is more flexible and easier to use than the older ones.

I'm generally fine with the series, but I'm starting to get concerned
that some simple applications that used to rely on wait() or waitpid()
will not work on this architecture. Just like we did for some early
syscalls that got replaced (e.g. open->openat etc), I think we'll have
to implement a default wrapper relying on waitid() for all these calls
in this case, and maybe as well for lseek->llseek() btw, what do you
think ?

The single fact that you've had to modify some of the nolibc-test code
(which is supposed to be the application here) indicates that we're
progressively going away from what applications need on certain archs.
Ideally an application relying on long-established calls should continue
to work unmodified.

Maybe it will be time for us to run an overall audit of arch-dependent
syscalls we currently have, to make sure that the common ones continue
to work fine there (and waitpid() definitely is as common a syscall as
open() since it's the good old and portable one).

Cheers,
Willy
diff mbox series

Patch

diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index 7b82bc3cf107439a3f09f98b99d4d540ffb9ba2a..d4a5c2399a66b200ebf7ab249569cce2285481a5 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -23,6 +23,7 @@ 
 #include <linux/prctl.h>
 #include <linux/resource.h>
 #include <linux/utsname.h>
+#include <linux/signal.h>
 
 #include "arch.h"
 #include "errno.h"
@@ -1225,6 +1226,23 @@  pid_t waitpid(pid_t pid, int *status, int options)
 }
 
 
+/*
+ * 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);
  */