mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-08 04:56:43 +00:00
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:
parent
9a10f50ce1
commit
77c07f0d79
1 changed files with 24 additions and 0 deletions
|
|
@ -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.
|
||||
///
|
||||
|
|
|
|||
Loading…
Reference in a new issue