diff options
Diffstat (limited to 'ripple/minitrace')
-rw-r--r-- | ripple/minitrace/src/main.rs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/ripple/minitrace/src/main.rs b/ripple/minitrace/src/main.rs index eaabad0..09b694c 100644 --- a/ripple/minitrace/src/main.rs +++ b/ripple/minitrace/src/main.rs @@ -108,11 +108,11 @@ macro_rules! define_syscalls { } impl $SyscallEntry { - fn from_regs(regs: libc::user_regs_struct) -> Result<$SyscallEntry> { + fn from_regs(process: &Process, regs: libc::user_regs_struct) -> Result<$SyscallEntry> { Ok(match (regs.orig_rax, [regs.rdi, regs.rsi, regs.rdx, regs.r10, regs.r8, regs.r9]) { $( ($nr, [$($arg),*, ..]) => $SyscallEntry::$syscall { - $($arg: match SyscallArg::try_from_reg($arg) { + $($arg: match ProcessSyscallArg::try_from_process_reg(process, $arg) { Some(x) => x, None => bail!("couldn't parse {}(2) {}: 0x{:08x}", stringify!($syscall), stringify!($arg), $arg) }),* @@ -178,6 +178,22 @@ macro_rules! syscall_bitflags { }; } +trait ProcessSyscallArg: Sized { + fn try_from_process_reg(process: &Process, reg: u64) -> Option<Self>; +} + +impl ProcessSyscallArg for CString { + fn try_from_process_reg(process: &Process, reg: u64) -> Option<Self> { + process.read_mem_cstr(reg).ok() + } +} + +impl<T: SyscallArg> ProcessSyscallArg for T { + fn try_from_process_reg(_process: &Process, reg: u64) -> Option<Self> { + SyscallArg::try_from_reg(reg) + } +} + trait SyscallArg: Sized { fn try_from_reg(reg: u64) -> Option<Self>; } @@ -328,7 +344,7 @@ fn main() -> Result<()> { assert_eq!(tid, event_tid); let regs = ptrace::getregs(event_tid.as_pid())?; - let entry = match SyscallEntry::from_regs(regs) { + let entry = match SyscallEntry::from_regs(&process, regs) { Ok(entry) => entry, Err(err) => { ptrace::kill(event_tid.as_pid())?; |