add separate handling for unmap syscall

The unmap syscall is a little bit tricky, because it can de-allocate
several pages at once, which can trigger an advisory de-allocate
message to the swapper in the middle of the loop. The entire structure
has to be re-written to handle this case, so we patch this right at
the top level syscall point and handle it entirely with custom
logic in the swapper.
This commit is contained in:
bunnie 2024-04-01 14:03:43 +08:00
parent 5f1e8618f0
commit 46525eff04

View file

@ -731,22 +731,32 @@ pub fn handle_inner(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallR
Ok(xous_kernel::Result::MemoryRange(range))
})
}
SysCall::UnmapMemory(range) => MemoryManager::with_mut(|mm| {
let mut result = Ok(xous_kernel::Result::Ok);
let virt = range.as_ptr() as usize;
let size = range.len();
if cfg!(baremetal) && virt & 0xfff != 0 {
return Err(xous_kernel::Error::BadAlignment);
}
for addr in (virt..(virt + size)).step_by(PAGE_SIZE) {
if let Err(e) = mm.unmap_page(addr as *mut usize) {
if result.is_ok() {
result = Err(e);
SysCall::UnmapMemory(range) => {
println!("UnmapMemory: {:x?}", range);
#[cfg(feature = "swap")]
// this call may diverge if it generates an advisory to the swapper
let result = crate::swap::Swap::with_mut(|s| s.unmap(range));
#[cfg(not(feature = "swap"))]
let result = {
MemoryManager::with_mut(|mm| {
let mut result = Ok(xous_kernel::Result::Ok);
let virt = range.as_ptr() as usize;
let size = range.len();
if cfg!(baremetal) && virt & 0xfff != 0 {
return Err(xous_kernel::Error::BadAlignment);
}
}
}
for addr in (virt..(virt + size)).step_by(PAGE_SIZE) {
if let Err(e) = mm.unmap_page(addr as *mut usize) {
if result.is_ok() {
result = Err(e);
}
}
}
result
})
};
result
}),
}
SysCall::IncreaseHeap(delta, flags) => {
if delta & 0xfff != 0 {
return Err(xous_kernel::Error::BadAlignment);