[PATCH] tools/nolibc: align sys_vfork() with sys_fork()

Thomas Weißschuh posted 1 patch 1 day, 22 hours ago
tools/include/nolibc/arch-s390.h |  8 ++++++++
tools/include/nolibc/sys.h       | 18 +++++-------------
2 files changed, 13 insertions(+), 13 deletions(-)
[PATCH] tools/nolibc: align sys_vfork() with sys_fork()
Posted by Thomas Weißschuh 1 day, 22 hours ago
Currently the generic variants of sys_fork() and sys_vfork() differ in
both they precedence of used system calls and the usage of sys_clone()
vs sys_clone3(). While the interface of clone3() in sys_vfork() is more
consistent over different architectures, qemu-user does not support it,
making testing harder. We already handle the different clone()
interfaces for sys_fork() in the architecture-specific headers, and can
do so also for sys_vfork(). In fact SPARC already has such handling and
only s390 is currently missing.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 tools/include/nolibc/arch-s390.h |  8 ++++++++
 tools/include/nolibc/sys.h       | 18 +++++-------------
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/tools/include/nolibc/arch-s390.h b/tools/include/nolibc/arch-s390.h
index 5bee6ecbde0a..904281e95f99 100644
--- a/tools/include/nolibc/arch-s390.h
+++ b/tools/include/nolibc/arch-s390.h
@@ -8,6 +8,7 @@
 
 #include "types.h"
 
+#include <linux/sched.h>
 #include <linux/signal.h>
 #include <linux/unistd.h>
 
@@ -189,4 +190,11 @@ pid_t sys_fork(void)
 }
 #define sys_fork sys_fork
 
+static __attribute__((unused))
+pid_t sys_vfork(void)
+{
+	return my_syscall5(__NR_clone, 0, CLONE_VM | CLONE_VFORK | SIGCHLD, 0, 0, 0);
+}
+#define sys_vfork sys_vfork
+
 #endif /* _NOLIBC_ARCH_S390_H */
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index 847af1ccbdc9..403ee9ce8389 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -22,7 +22,7 @@
 #include <linux/time.h>
 #include <linux/auxvec.h>
 #include <linux/fcntl.h> /* for O_* and AT_* */
-#include <linux/sched.h> /* for clone_args */
+#include <linux/sched.h> /* for CLONE_* */
 #include <linux/stat.h>  /* for statx() */
 
 #include "errno.h"
@@ -363,19 +363,11 @@ pid_t fork(void)
 static __attribute__((unused))
 pid_t sys_vfork(void)
 {
-#if defined(__NR_vfork)
+#if defined(__NR_clone)
+	/* See the note in sys_fork(). */
+	return my_syscall5(__NR_clone, CLONE_VM | CLONE_VFORK | SIGCHLD, 0, 0, 0, 0);
+#elif defined(__NR_vfork)
 	return my_syscall0(__NR_vfork);
-#else
-	/*
-	 * clone() could be used but has different argument orders per
-	 * architecture.
-	 */
-	struct clone_args args = {
-		.flags		= CLONE_VM | CLONE_VFORK,
-		.exit_signal	= SIGCHLD,
-	};
-
-	return my_syscall2(__NR_clone3, &args, sizeof(args));
 #endif
 }
 #endif

---
base-commit: 6f882963bd535af05fbed02a299d5d40d15f80a5
change-id: 20260104-nolibc-vfork-eae89ef0685e

Best regards,
-- 
Thomas Weißschuh <linux@weissschuh.net>

Re: [PATCH] tools/nolibc: align sys_vfork() with sys_fork()
Posted by Willy Tarreau 1 day, 13 hours ago
On Sun, Jan 04, 2026 at 11:43:13PM +0100, Thomas Weißschuh wrote:
> Currently the generic variants of sys_fork() and sys_vfork() differ in
> both they precedence of used system calls and the usage of sys_clone()
> vs sys_clone3(). While the interface of clone3() in sys_vfork() is more
> consistent over different architectures, qemu-user does not support it,
> making testing harder. We already handle the different clone()
> interfaces for sys_fork() in the architecture-specific headers, and can
> do so also for sys_vfork(). In fact SPARC already has such handling and
> only s390 is currently missing.
> 
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>

LGTM.

Acked-by: Willy Tarreau <w@1wt.eu>

thanks,
Willy