Moved child process code into main

This commit is contained in:
Elnath 2025-05-18 17:58:35 +02:00
parent 14e8d0b386
commit 00a94cc0d4
2 changed files with 6 additions and 19 deletions

View File

@ -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) },
}
}

View File

@ -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}");