Fix unwrap panic of dropped VMAR in PID status

This commit is contained in:
Marsman1996
2025-06-22 17:20:59 +08:00
committed by Ruihan Li
parent a1accf4304
commit 1c56fbc871
2 changed files with 10 additions and 4 deletions

View File

@ -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,

View File

@ -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<Full>> {
self.inner.as_ref()
}
/// Sets a new VMAR for the binding process.
///
/// If the `new_vmar` is `None`, this method will remove the