Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tools/nolibc: Provide vfork()

To allow testing of vfork() support in the arm64 basic-gcs test provide an
implementation for nolibc, using the vfork() syscall if one is available
and otherwise clone3(). We implement in terms of clone3() since the order
of the arguments for clone() varies between architectures.

As for fork() SPARC returns the parent PID rather than 0 in the child
for vfork() so needs custom handling.

Signed-off-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20250703-arm64-gcs-vfork-exit-v3-2-1e9a9d2ddbbe@kernel.org
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>

authored by

Mark Brown and committed by
Thomas Weißschuh
fb476dfb 8c11625a

+45
+16
tools/include/nolibc/arch-sparc.h
··· 188 188 } 189 189 #define sys_fork sys_fork 190 190 191 + static __attribute__((unused)) 192 + pid_t sys_vfork(void) 193 + { 194 + pid_t parent, ret; 195 + 196 + parent = getpid(); 197 + ret = my_syscall0(__NR_vfork); 198 + 199 + /* The syscall returns the parent pid in the child instead of 0 */ 200 + if (ret == parent) 201 + return 0; 202 + else 203 + return ret; 204 + } 205 + #define sys_vfork sys_vfork 206 + 191 207 #endif /* _NOLIBC_ARCH_SPARC_H */
+29
tools/include/nolibc/sys.h
··· 22 22 #include <linux/time.h> 23 23 #include <linux/auxvec.h> 24 24 #include <linux/fcntl.h> /* for O_* and AT_* */ 25 + #include <linux/sched.h> /* for clone_args */ 25 26 #include <linux/stat.h> /* for statx() */ 26 27 27 28 #include "errno.h" ··· 341 340 return __sysret(sys_fork()); 342 341 } 343 342 343 + #ifndef sys_vfork 344 + static __attribute__((unused)) 345 + pid_t sys_vfork(void) 346 + { 347 + #if defined(__NR_vfork) 348 + return my_syscall0(__NR_vfork); 349 + #elif defined(__NR_clone3) 350 + /* 351 + * clone() could be used but has different argument orders per 352 + * architecture. 353 + */ 354 + struct clone_args args = { 355 + .flags = CLONE_VM | CLONE_VFORK, 356 + .exit_signal = SIGCHLD, 357 + }; 358 + 359 + return my_syscall2(__NR_clone3, &args, sizeof(args)); 360 + #else 361 + return __nolibc_enosys(__func__); 362 + #endif 363 + } 364 + #endif 365 + 366 + static __attribute__((unused)) 367 + pid_t vfork(void) 368 + { 369 + return __sysret(sys_vfork()); 370 + } 344 371 345 372 /* 346 373 * int fsync(int fd);