kernel: allow freeing unbacked virtual memory

Memory is on-demand allocated, meaning it's entirely possible to
allocate and free memory without ever touching physical pages.

Previously, when we attempted to free memory, it would skip over pages
that were never backed by real memory.

With this patch, we continue to free the virtual page even if there is
no associated physical page.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2021-09-27 13:39:10 +08:00 committed by bunnie
parent 6304ba4616
commit fa31e2235c

View file

@ -530,8 +530,14 @@ impl MemoryManager {
/// * MemoryInUse - The specified page is already mapped
pub fn unmap_page(&mut self, virt: *mut usize) -> Result<usize, xous_kernel::Error> {
let pid = crate::arch::process::current_pid();
let phys = crate::arch::mem::virt_to_phys(virt as usize)?;
self.release_page(phys as *mut usize, pid)?;
// If the virtual address has an assigned physical address, release that
// address from this process.
if let Ok(phys) = crate::arch::mem::virt_to_phys(virt as usize) {
self.release_page(phys as *mut usize, pid)?;
};
// Free the virtual address.
crate::arch::mem::unmap_page_inner(self, virt as usize)
}