more debugging of page table issues

This commit is contained in:
Alex Zenla
2024-01-15 18:50:12 -08:00
parent dfc3dc8e90
commit 3e9470afaa
7 changed files with 223 additions and 14 deletions

View File

@ -1,5 +1,7 @@
use crate::sys::XEN_PAGE_SHIFT;
use crate::XenClientError;
use libc::munmap;
use std::ffi::c_void;
use crate::x86::X86_PAGE_SHIFT;
use xencall::sys::MmapEntry;
@ -104,4 +106,28 @@ impl PhysicalPages<'_> {
self.pages.push(page);
Ok(addr)
}
pub fn unmap(&mut self, pfn: u64) -> Result<(), XenClientError> {
let mut page: Option<&PhysicalPage> = None;
for item in &self.pages {
if pfn >= item.pfn && pfn < (item.pfn + item.count) {
break;
}
page = Some(item);
}
if page.is_none() {
return Err(XenClientError::new("failed to unmap pfn"));
}
let page = page.unwrap();
unsafe {
let err = munmap(
page.ptr as *mut c_void,
(page.count << X86_PAGE_SHIFT) as usize,
);
if err != 0 {
return Err(XenClientError::new("failed to munmap pfn"));
}
}
Ok(())
}
}