diff --git a/kernel/src/arch/riscv/mem.rs b/kernel/src/arch/riscv/mem.rs index f840c1d90..f09b1410d 100644 --- a/kernel/src/arch/riscv/mem.rs +++ b/kernel/src/arch/riscv/mem.rs @@ -1182,7 +1182,7 @@ pub fn evict_page_inner(target_pid: PID, vaddr: usize) -> Result { + // release the page from the swapper's address space + MemoryManager::with_mut(|mm| { + let paddr = crate::arch::mem::virt_to_phys(swap_vaddr).unwrap() as usize; + #[cfg(feature = "debug-swap-verbose")] + println!("Release flash backing page - paddr {:x}", paddr); + // this call unmaps the virtual page from the page table + crate::arch::mem::unmap_page_inner(mm, swap_vaddr).expect("couldn't unmap page"); + // This call releases the physical page from the RPT - the pid has to match that + // of the original owner. This is the "pointy end" of + // the stick; after this call, the memory is now back + // into the free pool. + mm.release_page_swap(paddr as *mut usize, src_pid) + .expect("couldn't free page that was swapped out"); + }); + } + Err(xous_kernel::Error::BadAddress) => { + #[cfg(feature = "debug-swap")] + println!("Written page wasn't mapped {:x}", flash_vaddr); + // in this case, it wasn't mapped into memory. We have been returned to the + // swapper's memory space, and we can just move to + // checking the next page + } + _ => { + panic!("Unexpected error in WriteToFlash page free") + } + } // Unhalt IRQs self.swap_restore_irq();