diff --git a/kernel/src/fs/procfs/pid/status.rs b/kernel/src/fs/procfs/pid/status.rs index 12ca3fcd0..9dc0cd38d 100644 --- a/kernel/src/fs/procfs/pid/status.rs +++ b/kernel/src/fs/procfs/pid/status.rs @@ -99,10 +99,9 @@ impl FileOps for StatusFileOps { ) .unwrap(); - { - let vmar = process.lock_root_vmar(); - let anon = vmar.unwrap().get_rss_counter(RssType::RSS_ANONPAGES) * (PAGE_SIZE / 1024); - let file = vmar.unwrap().get_rss_counter(RssType::RSS_FILEPAGES) * (PAGE_SIZE / 1024); + if let Some(vmar_ref) = process.lock_root_vmar().as_ref() { + let anon = vmar_ref.get_rss_counter(RssType::RSS_ANONPAGES) * (PAGE_SIZE / 1024); + let file = vmar_ref.get_rss_counter(RssType::RSS_FILEPAGES) * (PAGE_SIZE / 1024); let rss = anon + file; writeln!( status_output, diff --git a/kernel/src/process/process_vm/mod.rs b/kernel/src/process/process_vm/mod.rs index 600e442ae..3ee73aa4b 100644 --- a/kernel/src/process/process_vm/mod.rs +++ b/kernel/src/process/process_vm/mod.rs @@ -87,6 +87,13 @@ impl ProcessVmarGuard<'_> { self.inner.as_ref().unwrap() } + /// Returns a reference to the process VMAR if it exists. + /// + /// Returns `None` if the process has exited and its VMAR has been dropped. + pub fn as_ref(&self) -> Option<&Vmar> { + self.inner.as_ref() + } + /// Sets a new VMAR for the binding process. /// /// If the `new_vmar` is `None`, this method will remove the