note a leak that needs fixing eventually
[trinity.git] / syscalls / fork.c
blob2fba90c3af65cca4b72eadcfa841234e5b146023
1 /*
2 int sys_fork(struct pt_regs *regs)
3 */
4 #include <sys/wait.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include "pids.h"
8 #include "sanitise.h"
9 #include "shm.h"
10 #include "trinity.h"
13 * Because we don't want to forkbomb, we don't really do anything in the child process.
14 * We only actually do a fork at all on the off-chance that it might trigger some oddness
15 * in the VMAs we've created when we COW.
17 * TODO: Maybe do some dirty_mapping calls in the child ?
18 * TODO: Maybe we could enforce an upper limit on the child count before we fork,
19 * and keep track of them using handle_child ?
22 static void post_fork(int childno)
24 pid_t pid;
26 pid = shm->syscall[childno].retval;
27 if (pid == 0) {
28 // child
29 sleep(1);
30 _exit(EXIT_SUCCESS);
31 } else {
32 __unused__ int ret;
34 while (pid_alive(pid)) {
35 int status;
36 ret = waitpid(pid, &status, WUNTRACED | WCONTINUED | WNOHANG);
41 struct syscallentry syscall_fork = {
42 .name = "fork",
43 .num_args = 0,
44 .flags = AVOID_SYSCALL, // No args to fuzz, confuses fuzzer
45 .post = post_fork,