The Pedigree Project 0.1
clone-routing-regressions.cc
1/*
2 * Copyright (c) 2026, Pedigree Developers
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted.
6 */
7
8#include "pedigree/kernel/Log.h"
9
10#include <sched.h>
11#include <signal.h>
12
13class Process;
14
15extern "C" int posixCloneRouteForTest(unsigned long flags);
16
17bool runHostedCloneRoutingRegressions(Process*) {
18 const unsigned long spawnFlags = CLONE_VM | CLONE_VFORK | SIGCHLD;
19 const unsigned long pthreadFlags = CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND |
20 CLONE_THREAD | CLONE_SYSVSEM | CLONE_SETTLS |
21 CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID | CLONE_DETACHED;
22
23 const bool passed =
24 posixCloneRouteForTest(spawnFlags) == 2 && posixCloneRouteForTest(pthreadFlags) == 1 &&
25 posixCloneRouteForTest(spawnFlags | CLONE_NEWUTS) == 2 &&
26 posixCloneRouteForTest(spawnFlags | CLONE_PARENT_SETTID | CLONE_CHILD_SETTID |
27 CLONE_CHILD_CLEARTID | CLONE_SETTLS) == 2 &&
28 posixCloneRouteForTest(0) == 0 && posixCloneRouteForTest(SIGCHLD) == 0 &&
29 posixCloneRouteForTest(SIGCHLD | CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID) == 0 &&
30 posixCloneRouteForTest(CLONE_NEWUTS | SIGCHLD) == 0 &&
31 posixCloneRouteForTest(CLONE_NEWUTS | CLONE_NEWNS | SIGCHLD) == -1 &&
32 posixCloneRouteForTest(CLONE_NEWUTS | pthreadFlags) == -1 &&
33 posixCloneRouteForTest(CLONE_VM) == -1 && posixCloneRouteForTest(CLONE_THREAD) == -1 &&
34 posixCloneRouteForTest(CLONE_VM | CLONE_THREAD) == -1 &&
35 posixCloneRouteForTest(CLONE_VM | CLONE_SIGHAND | CLONE_THREAD) == -1 &&
36 posixCloneRouteForTest(CLONE_SIGHAND) == -1 &&
37 posixCloneRouteForTest(CLONE_VFORK | SIGCHLD) == -1 &&
38 posixCloneRouteForTest(spawnFlags | CLONE_FILES) == -1 &&
39 posixCloneRouteForTest(CLONE_FILES | SIGCHLD) == -1 &&
40 posixCloneRouteForTest(CLONE_PARENT | SIGCHLD) == -1;
41 if (!passed) {
42 ERROR(
43 "HOSTED-SYSCALL-TEST: FAIL clone-process-routing: "
44 "fork, vfork, and pthread clone no longer take distinct paths");
45 return false;
46 }
47
48 NOTICE("HOSTED-SYSCALL-TEST: PASS clone-process-routing");
49 return true;
50}