make swapper syscall API re-entrant (map/retrieve page)

we no longer diverge at the swapper call, so execution flows
intuitively here. this feels so much nicer.
This commit is contained in:
bunnie 2024-05-28 02:45:27 +08:00
parent 62eb233db1
commit 8ce2ac566a

View file

@ -10,8 +10,6 @@ use xous_kernel::{MemoryFlags, PID};
use crate::arch::process::InitialProcess; use crate::arch::process::InitialProcess;
use crate::mem::MemoryManager; use crate::mem::MemoryManager;
#[cfg(feature = "swap")]
use crate::swap::Swap;
// pub const DEFAULT_STACK_TOP: usize = 0x8000_0000; // pub const DEFAULT_STACK_TOP: usize = 0x8000_0000;
pub const DEFAULT_HEAP_BASE: usize = 0x2000_0000; pub const DEFAULT_HEAP_BASE: usize = 0x2000_0000;
@ -944,16 +942,21 @@ pub fn ensure_page_exists_inner(address: usize) -> Result<usize, xous_kernel::Er
#[cfg(feature = "swap")] #[cfg(feature = "swap")]
if flags & MMUFlags::P.bits() != 0 { if flags & MMUFlags::P.bits() != 0 {
// page is swapped; fill page, map and return // page is swapped; fill page, map and return
Swap::with_mut(|s| { crate::swap::Swap::with_mut(|s| {
s.retrieve_page( s.swap_reentrant_syscall(xous_kernel::SysCall::SwapOp(
crate::arch::process::current_pid(), crate::swap::SwapAbi::RetrievePage as usize,
crate::arch::process::current_tid(),
virt, virt,
new_page, new_page,
) 0,
}) 0,
0,
// the execution flow diverges from here: it returns via the interrupt context handler. -> ! 0,
))
});
*entry =
(ppn1 << 20) | (ppn0 << 10) | ((flags & !MMUFlags::P.bits()) | crate::arch::mem::FLG_VALID);
flush_mmu();
return Ok(new_page);
} else { } else {
// page is reserved: simply zero it out // page is reserved: simply zero it out
// Map the page to our process // Map the page to our process