Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
use ptrace_test_redox::e;
use std::{
io::{prelude::*, Result},
os::unix::io::{AsRawFd, FromRawFd, RawFd}
use syscall::{
const FLAGS: usize = WUNTRACED;
fn main() -> Result<()> {
let pid = e(unsafe { syscall::clone(0) })?;
if pid == 0 {
e(syscall::kill(e(syscall::getpid())?, SIGSTOP))?;
let file = e(syscall::open("file:/bin/regs", O_RDONLY))?;
e(syscall::fexec(file, &[["regs".as_ptr() as usize, 4]], &[]))?;
// println!("Hello from the child");
// println!("This is a testing test");
// println!("Pretty amazing honsetly");
return Ok(());
let mut status = 0;
println!("Waiting... (Initial)");
e(syscall::waitpid(pid, &mut status, FLAGS))?;
println!("Waited! (Initial)");
let mut trace_file = File::open(format!("proc:{}/trace", pid))?;
let mut regs_file = unsafe {
e(syscall::dup(trace_file.as_raw_fd() as usize, b"regs/int"))? as RawFd
// Won't actually restart the process, because it's stopped by ptrace
e(syscall::kill(pid, SIGCONT))?;
loop {
let mut regs = IntRegisters::default(); regs)?;
println!("SYSCALL: {} ({}, {}, {})", regs.rax, regs.rdi, regs.rsi, regs.rdx);
let mut regs = IntRegisters::default(); regs)?;
println!("SYSCALL RET: {}", regs.rax);
// Ok(())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.