MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / kernel_fork

Function kernel_fork

src/backend/linux_raw/runtime/syscalls.rs:35–79  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

33
34#[inline]
35pub(crate) unsafe fn kernel_fork() -> io::Result<Fork> {
36 let mut child_pid = MaybeUninit::<RawPid>::uninit();
37
38 // Unix `fork` only returns the child PID in the parent; we'd like it in
39 // the child too, so set `CLONE_CHILD_SETTID` and pass in the address of a
40 // memory location to store it to in the child.
41 //
42 // Architectures differ on the order of the parameters.
43 #[cfg(target_arch = "x86_64")]
44 let pid = ret_c_int(syscall!(
45 __NR_clone,
46 c_int(c::SIGCHLD | c::CLONE_CHILD_SETTID),
47 zero(),
48 zero(),
49 &mut child_pid,
50 zero()
51 ))?;
52 #[cfg(any(
53 target_arch = "aarch64",
54 target_arch = "arm",
55 target_arch = "mips",
56 target_arch = "mips32r6",
57 target_arch = "mips64",
58 target_arch = "mips64r6",
59 target_arch = "powerpc",
60 target_arch = "powerpc64",
61 target_arch = "riscv64",
62 target_arch = "s390x",
63 target_arch = "x86"
64 ))]
65 let pid = ret_c_int(syscall!(
66 __NR_clone,
67 c_int(c::SIGCHLD | c::CLONE_CHILD_SETTID),
68 zero(),
69 zero(),
70 zero(),
71 &mut child_pid
72 ))?;
73
74 Ok(if let Some(pid) = Pid::from_raw(pid) {
75 Fork::ParentOf(pid)
76 } else {
77 Fork::Child(Pid::from_raw_unchecked(child_pid.assume_init()))
78 })
79}
80
81#[cfg(feature = "fs")]
82pub(crate) unsafe fn execveat(

Callers

nothing calls this directly

Calls 2

assume_initMethod · 0.80
ret_c_intFunction · 0.50

Tested by

no test coverage detected