diff --git a/src/child.rs b/src/child.rs deleted file mode 100644 index 6413521..0000000 --- a/src/child.rs +++ /dev/null @@ -1,15 +0,0 @@ -use nix::libc; -use nix::sys::ptrace::traceme; -use nix::unistd::execv; -use std::ffi::CString; - -pub fn starti(child_exec_path: CString) -> ! { - // ⚠️ There is a limited amount of things that can be done here, see fork's safety - match traceme() { - Ok(_) => { - execv(&child_exec_path, &[&child_exec_path]).unwrap(); - unreachable!(); - } - Err(errno) => unsafe { libc::exit(errno as i32) }, - } -} diff --git a/src/main.rs b/src/main.rs index 0eba599..e2daf01 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,9 @@ -mod child; mod debug_target; mod syscall_info; use crate::debug_target::{ExitedTarget, StoppedTarget}; use color_eyre::eyre::eyre; use either::Either; -use nix::sys::ptrace::*; -use nix::sys::signal::Signal::*; use nix::unistd::{fork, ForkResult}; use std::ffi::CString; @@ -48,7 +45,12 @@ fn main() -> color_eyre::Result<()> { let child_exec_path = CString::new(env!("ASM_PROG_PATH"))?; match unsafe { fork() } { - Ok(ForkResult::Child) => child::starti(child_exec_path), + Ok(ForkResult::Child) => { + // ⚠️ There is a limited amount of things that can be done here, see fork's safety + nix::sys::ptrace::traceme()?; + nix::unistd::execv(&child_exec_path, &[&child_exec_path])?; + unreachable!(); + } Ok(ForkResult::Parent { child: child_pid }) => { println!("✔️ Created child {child_pid}");