mem: add map_page()

This shortcut function ensures a page is mapped.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2020-03-14 22:06:00 +08:00
parent 9a10f50ce1
commit 77c07f0d79

View file

@ -343,6 +343,30 @@ impl MemoryManager {
}))
}
/// Attempt to allocate a single page from the default section.
/// Note that this will be backed by a real page.
pub fn map_page(&mut self, pid: PID) -> Result<*mut usize, xous::Error> {
let virt =
self.find_virtual_address(0 as *mut usize, PAGE_SIZE, xous::MemoryType::Default)?;
// Grab the next available page. This claims it for this process.
let phys = self.alloc_page(pid)?;
// Actually perform the map. At this stage, every physical page should be owned by us.
if let Err(e) = crate::arch::mem::map_page_inner(
self,
pid,
phys as usize,
virt as usize,
xous::MemoryFlags::R | xous::MemoryFlags::W,
) {
self.release_page(phys as *mut usize, pid).ok();
return Err(e);
}
Ok(virt as *mut usize)
}
/// Attempt to map the given physical address into the virtual address space
/// of this process.
///