From 614f732ab398154ab9548f2dadde35c0f4a812f4 Mon Sep 17 00:00:00 2001 From: Mitchell Merry Date: Fri, 26 Dec 2025 20:24:28 +1100 Subject: [PATCH 1/2] Add functions to get the process name and main module range. --- src/runtime/process.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/runtime/process.rs b/src/runtime/process.rs index ccbfb313..ee07ea89 100644 --- a/src/runtime/process.rs +++ b/src/runtime/process.rs @@ -161,6 +161,14 @@ impl Process { } } + /// Gets the name of the process. + #[cfg(feature = "alloc")] + #[inline] + pub fn get_name(&self) -> Result { + let path = self.get_path()?; + Ok(path.split("/").last().ok_or(Error {})?.into()) + } + /// Gets the address of a module in the process. #[inline] pub fn get_module_address(&self, name: &str) -> Result { @@ -247,6 +255,14 @@ impl Process { }) } + /// Get the address and size of the main module in the process. + #[cfg(feature = "alloc")] + #[inline] + pub fn get_main_module_range(&self) -> Result<(Address, u64), Error> { + let main_module_name = self.get_name()?; + self.get_module_range(&main_module_name) + } + /// Reads a value of the type specified from the process at the address /// given. #[inline] From e11a927183f80c744ae8d777d59f43f22f7b63e5 Mon Sep 17 00:00:00 2001 From: Mitchell Merry Date: Sat, 27 Dec 2025 09:46:14 +1100 Subject: [PATCH 2/2] remove an unnecessary allocation --- src/runtime/process.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/runtime/process.rs b/src/runtime/process.rs index ee07ea89..da7c856e 100644 --- a/src/runtime/process.rs +++ b/src/runtime/process.rs @@ -165,8 +165,14 @@ impl Process { #[cfg(feature = "alloc")] #[inline] pub fn get_name(&self) -> Result { - let path = self.get_path()?; - Ok(path.split("/").last().ok_or(Error {})?.into()) + let mut path = self.get_path()?; + + // remove everything before the / on path to avoid an allocation + let (before, _) = path.rsplit_once('/').ok_or(Error {})?; + let index = before.len() + 1; + path.drain(..index); + + Ok(path) } /// Gets the address of a module in the process.