From 9300a465016c7474ee61d6cefa97c662c190aeff Mon Sep 17 00:00:00 2001 From: edef Date: Sat, 30 Jul 2022 02:07:13 +0000 Subject: ripple/minitrace: dump early memory mappings These are from right after exec(2), so they are all done by the kernel. Change-Id: Ic76aa9c40acac64462fa6ab5c33cabcee3e096e5 --- ripple/minitrace/src/main.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'ripple/minitrace/src/main.rs') diff --git a/ripple/minitrace/src/main.rs b/ripple/minitrace/src/main.rs index cf23034..0f9cb0d 100644 --- a/ripple/minitrace/src/main.rs +++ b/ripple/minitrace/src/main.rs @@ -27,6 +27,8 @@ use { }, }; +mod maps_file; + // TODO(edef): consider implementing this in terms of TID? // tgids are a strict subset of tids #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] @@ -92,6 +94,19 @@ impl Process { Ok(CString::from_vec_with_nul(buf).expect("logic error")) } + + fn read_mappings(&self) -> Result> { + let contents = std::fs::read_to_string(format!("/proc/{}/maps", self.tgid.0))?; + + // TODO(edef): consult /proc/$pid/map_files/* for pathnames, since /proc/$pid/maps is unreliable with odd paths + // we'll want to verify the two against each other, just to be sure they're congruent + + let mappings = contents + .lines() + .map(maps_file::parse_mapping_line) + .collect::>()?; + Ok(mappings) + } } macro_rules! define_syscalls { @@ -384,6 +399,8 @@ fn main() -> Result<()> { cmd })?; + println!("{:#?}", process.read_mappings()?); + let options = ptrace::Options::PTRACE_O_TRACESYSGOOD | ptrace::Options::PTRACE_O_TRACECLONE | ptrace::Options::PTRACE_O_EXITKILL; -- cgit 1.4.1