Skip to content

Commit

Permalink
Removed dup code from jailer/env/clone()
Browse files Browse the repository at this point in the history
There were no differences between the x86_64 and the aarch64 versions
of the clone sys call.

Signed-off-by: seafoodfry <[email protected]>
  • Loading branch information
seafoodfry authored and roypat committed Jul 22, 2024
1 parent f91b800 commit b041106
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions src/jailer/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ fn dup2(old_fd: libc::c_int, new_fd: libc::c_int) -> Result<(), JailerError> {
// manner to the fork syscall. The libc wrapper prevents use of a NULL stack pointer, so we will
// call the syscall directly.
fn clone(child_stack: *mut libc::c_void, flags: libc::c_int) -> Result<libc::c_int, JailerError> {
// Clone parameters order is different between x86_64 and aarch64.
#[cfg(target_arch = "x86_64")]
return SyscallReturnCode(
SyscallReturnCode(
// SAFETY: This is safe because we are using a library function with valid parameters.
libc::c_int::try_from(unsafe {
libc::syscall(libc::SYS_clone, flags, child_stack, 0, 0, 0)
Expand All @@ -91,18 +89,7 @@ fn clone(child_stack: *mut libc::c_void, flags: libc::c_int) -> Result<libc::c_i
.unwrap(),
)
.into_result()
.map_err(JailerError::Clone);
#[cfg(target_arch = "aarch64")]
return SyscallReturnCode(
// SAFETY: This is safe because we are using a library function with valid parameters.
libc::c_int::try_from(unsafe {
libc::syscall(libc::SYS_clone, flags, child_stack, 0, 0, 0)
})
// Unwrap is needed because PIDs are 32-bit.
.unwrap(),
)
.into_result()
.map_err(JailerError::Clone);
.map_err(JailerError::Clone)
}

#[derive(Debug, thiserror::Error)]
Expand Down

0 comments on commit b041106

Please sign in to comment.