summary refs log tree commit diff
path: root/ripple/minitrace/src/main.rs
diff options
context:
space:
mode:
authoredef <edef@unfathomable.blue>2022-07-30 02:07:13 +0000
committeredef <edef@unfathomable.blue>2022-07-30 02:23:50 +0000
commit9300a465016c7474ee61d6cefa97c662c190aeff (patch)
tree065a35b888364d2607fd3a7afc49f700baf5327e /ripple/minitrace/src/main.rs
parentdb58b80ac7d1cc4f16ef1bc21146de9ab6e90302 (diff)
ripple/minitrace: dump early memory mappings
These are from right after exec(2), so they are all done by the kernel.

Change-Id: Ic76aa9c40acac64462fa6ab5c33cabcee3e096e5
Diffstat (limited to 'ripple/minitrace/src/main.rs')
-rw-r--r--ripple/minitrace/src/main.rs17
1 files changed, 17 insertions, 0 deletions
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<Vec<maps_file::Mapping>> {
+		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::<Result<_, _>>()?;
+		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;