diff options
author | edef <edef@unfathomable.blue> | 2022-02-08 01:46:16 +0000 |
---|---|---|
committer | edef <edef@unfathomable.blue> | 2022-02-08 02:32:05 +0000 |
commit | 0c1fa0017ab4eb5f1a547e42347bb376868b60df (patch) | |
tree | c467dee866dfc18ca230124d948d3a1259df6f44 /ripple/minitrace/src | |
parent | f7422d4616a8a1deb4516ca5022f4df4bc58a017 (diff) | |
download | unf-legacy-0c1fa0017ab4eb5f1a547e42347bb376868b60df.tar.zst |
ripple/minitrace: log openat paths
Co-authored-by: V <v@unfathomable.blue> Change-Id: Idcb3c29c4761158be788511f5f4bdb3003edf909
Diffstat (limited to 'ripple/minitrace/src')
-rw-r--r-- | ripple/minitrace/src/main.rs | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/ripple/minitrace/src/main.rs b/ripple/minitrace/src/main.rs index 5fa35da..6b7c044 100644 --- a/ripple/minitrace/src/main.rs +++ b/ripple/minitrace/src/main.rs @@ -14,7 +14,15 @@ use { }, unistd::Pid, }, - std::{convert::TryInto, env, os::unix::process::CommandExt, process::Command}, + std::{ + convert::TryInto, + env, + ffi::CString, + fs::File, + io::{self, BufRead, Seek, SeekFrom}, + os::unix::process::CommandExt, + process::Command, + }, }; // TODO(edef): consider implementing this in terms of TID? @@ -40,6 +48,7 @@ impl Tid { #[derive(Debug)] struct Process { tgid: Tgid, + mem: File, } impl Process { @@ -66,7 +75,25 @@ impl Process { status => bail!("unexpected child state: {:?}", status), } - Ok(Process { tgid }) + Ok(Process { + tgid, + mem: File::open(format!("/proc/{}/mem", tgid.0)) + .context("Couldn't open child memory")?, + }) + } + + fn read_mem_cstr(&self, ptr: u64) -> Result<CString> { + let mut mem = io::BufReader::new(&self.mem); + mem.seek(SeekFrom::Start(ptr))?; + let mut buf = vec![]; + mem.read_until(0, &mut buf)?; + + // TODO(V): replace with CString::from_vec_with_nul when we update to Rust 1.58 + if buf.pop() != Some(0) { + bail!("Couldn't find null terminator"); + } + + Ok(CString::new(buf).expect("logic error")) } } @@ -139,7 +166,7 @@ fn main() -> Result<()> { syscall_state = Some(EntryExit::Entry(entry)); - if !check_syscall(entry) { + if !check_syscall(&process, entry) { ptrace::kill(event_tid.as_pid())?; panic!("unsupported syscall {:?}", entry); } @@ -169,7 +196,7 @@ fn main() -> Result<()> { Ok(()) } -fn check_syscall(entry: SyscallEntry) -> bool { +fn check_syscall(process: &Process, entry: SyscallEntry) -> bool { match entry.number { // read 0 => {} @@ -236,12 +263,17 @@ fn check_syscall(entry: SyscallEntry) -> bool { // openat 257 => { - let [dirfd, _pathname, _flags, _mode, _, _] = entry.args; + let [dirfd, pathname, _flags, _mode, _, _] = entry.args; const AT_FDCWD: i32 = -100; if dirfd.try_into() == Ok(AT_FDCWD) { return false; } + + println!( + "openat(AT_FDCWD, {:?}, ..)", + process.read_mem_cstr(pathname).unwrap() + ); } // newfstatat |