From d457dd7314835ba43845462c6d81c5985b89f891 Mon Sep 17 00:00:00 2001 From: edef Date: Wed, 27 Jul 2022 23:23:39 +0000 Subject: ripple/minitrace: better errors for invalid syscall args Change-Id: I26356c9b88c838e3c87e4083ac17f958c7c57bb7 --- ripple/minitrace/src/main.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'ripple') diff --git a/ripple/minitrace/src/main.rs b/ripple/minitrace/src/main.rs index 4e2368a..3d94288 100644 --- a/ripple/minitrace/src/main.rs +++ b/ripple/minitrace/src/main.rs @@ -108,14 +108,17 @@ macro_rules! define_syscalls { } impl $enum { - fn from_regs(regs: libc::user_regs_struct) -> Option<$enum> { - Some(match (regs.orig_rax, [regs.rdi, regs.rsi, regs.rdx, regs.r10, regs.r8, regs.r9]) { + fn from_regs(regs: libc::user_regs_struct) -> Result<$enum> { + Ok(match (regs.orig_rax, [regs.rdi, regs.rsi, regs.rdx, regs.r10, regs.r8, regs.r9]) { $( ($nr, [$($arg_id),*, ..]) => $enum::$id { - $($arg_id: SyscallArg::try_from_reg($arg_id)?),* + $($arg_id: match SyscallArg::try_from_reg($arg_id) { + Some(x) => x, + None => bail!("couldn't parse {}(2) {}: 0x{:08x}", stringify!($id), stringify!($arg_id), $arg_id) + }),* }, )* - _ => return None + (n, _) => bail!("unknown syscall number {n}") }) } } @@ -303,10 +306,10 @@ fn main() -> Result<()> { let regs = ptrace::getregs(event_tid.as_pid())?; let entry = match SyscallEntry::from_regs(regs) { - Some(entry) => entry, - None => { + Ok(entry) => entry, + Err(err) => { ptrace::kill(event_tid.as_pid())?; - panic!("unsupported syscall {:?}", regs.orig_rax); + panic!("{err}"); } }; -- cgit 1.4.1