klibc-bot for Ben Hutchings
2024-Oct-07 21:36 UTC
[klibc] [klibc:master] syscalls: Clean up the fork() and clone() definitions
Commit-ID: ccfcaca5bb151e8c2ddc3cd99172dea98429278a Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=ccfcaca5bb151e8c2ddc3cd99172dea98429278a Author: Ben Hutchings <ben at decadent.org.uk> AuthorDate: Tue, 1 Oct 2024 23:04:45 +0200 Committer: Ben Hutchings <ben at decadent.org.uk> CommitDate: Wed, 2 Oct 2024 02:07:27 +0200 [klibc] syscalls: Clean up the fork() and clone() definitions Currently we're defining __clone() on all architectures, but it's only needed where fork() is missing and it's broken on s390 and s390x where the parameter order is incompatible. We're also building a list of new architectures which don't implement fork(), when we could automatically detect that. To fix these problems: - If __NR_fork is defined, generate a fork() system call wrapper, with only sparc and sparc64 as special cases. - Otherwise, generate __clone() as a clone() system call wrapper. Comment why this works despite the architecture differences. Signed-off-by: Ben Hutchings <ben at decadent.org.uk> --- usr/klibc/SYSCALLS.def | 12 ++++++++++-- usr/klibc/fork.c | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/usr/klibc/SYSCALLS.def b/usr/klibc/SYSCALLS.def index 65cf1c2e..e0f8895b 100644 --- a/usr/klibc/SYSCALLS.def +++ b/usr/klibc/SYSCALLS.def @@ -18,9 +18,17 @@ * Process-related syscalls */ void _exit,exit::_exit(int); -<?> pid_t clone::__clone(unsigned long, void *); -<!sparc,sparc64,arm64,riscv64,loongarch64> pid_t fork(); +#ifdef __NR_fork +<!sparc,sparc64> pid_t fork(); <sparc,sparc64> pid_t fork at forkish(); +#else +/* + * The clone() parameter order varies between architectures. However, + * the first 2 are always clone_flags and newsp, except on s390/s390x + * where we have fork() and do not use clone(). + */ +pid_t clone::__clone(unsigned long, void *); +#endif #if _KLIBC_REAL_VFORK /* * A lot of architectures need architecture-specific vfork diff --git a/usr/klibc/fork.c b/usr/klibc/fork.c index f5c5d753..bc0f3755 100644 --- a/usr/klibc/fork.c +++ b/usr/klibc/fork.c @@ -1,8 +1,8 @@ /* * fork.c * - * This is normally just a syscall stub, but at least one system - * doesn't have sys_fork, only sys_clone... + * This is normally just a syscall stub, but new architectures only + * implement clone(). */ #include <sys/syscall.h>