Skip to content

Commit

Permalink
Documented the discrepancy in arguments for the clone sys call
Browse files Browse the repository at this point in the history
  • Loading branch information
seafoodfry authored and roypat committed Jul 22, 2024
1 parent b041106 commit d5d67b5
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/jailer/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ fn clone(child_stack: *mut libc::c_void, flags: libc::c_int) -> Result<libc::c_i
SyscallReturnCode(
// SAFETY: This is safe because we are using a library function with valid parameters.
libc::c_int::try_from(unsafe {
// Note: the order of arguments in the raw syscall differs between platforms.
// On x86-64, for example, the parameters passed are `flags`, `stack`, `parent_tid`,
// `child_tid`, and `tls`. But on On x86-32, and several other common architectures
// (including score, ARM, ARM 64) the order of the last two arguments is reversed,
// and instead we must pass `flags`, `stack`, `parent_tid`, `tls`, and `child_tid`.
// This difference in architecture currently doesn't matter because the last 2
// arguments are all 0 but if this were to change we should add an attribute such as
// #[cfg(target_arch = "x86_64")] or #[cfg(target_arch = "aarch64")] for each different
// call.
libc::syscall(libc::SYS_clone, flags, child_stack, 0, 0, 0)
})
// Unwrap is needed because PIDs are 32-bit.
Expand Down

0 comments on commit d5d67b5

Please sign in to comment.