From 4be5f4031b01f72a2ddb4f7c09928318a8339b01 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Tue, 31 Mar 2020 18:36:53 +0800 Subject: [PATCH] xous: add UnmapMemory syscall Signed-off-by: Sean Cross --- xous-rs/src/syscall.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/xous-rs/src/syscall.rs b/xous-rs/src/syscall.rs index f0e758f82..4d59dbe43 100644 --- a/xous-rs/src/syscall.rs +++ b/xous-rs/src/syscall.rs @@ -79,6 +79,12 @@ pub enum SysCall { MemoryFlags, /* flags */ ), + /// Release the memory back to the operating system. + /// + /// # Errors + /// + UnmapMemory(*mut usize /* virt */, usize /* region size */), + /// Sets the offset and size of a given memory region. This call may only /// be made by processes that have not yet started, or processes that have a /// PPID of 1. Care must be taken to ensure this region doesn't run into @@ -306,6 +312,7 @@ enum SysCallNumber { SendMessage = 16, Connect = 17, SpawnThread = 18, + UnmapMemory = 19, Invalid, } @@ -330,6 +337,16 @@ impl SysCall { 0, 0, ], + SysCall::UnmapMemory(a1, a2) => [ + SysCallNumber::UnmapMemory as usize, + a1 as usize, + a2, + 0, + 0, + 0, + 0, + 0, + ], SysCall::Yield => [SysCallNumber::Yield as usize, 0, 0, 0, 0, 0, 0, 0], SysCall::WaitEvent => [SysCallNumber::WaitEvent as usize, 0, 0, 0, 0, 0, 0, 0], SysCall::ReceiveMessage(sid) => [ @@ -513,6 +530,7 @@ impl SysCall { a3, MemoryFlags::from_bits(a4).ok_or(InvalidSyscall {})?, ), + Some(SysCallNumber::UnmapMemory) => SysCall::UnmapMemory(a1 as *mut usize, a2), Some(SysCallNumber::Yield) => SysCall::Yield, Some(SysCallNumber::WaitEvent) => SysCall::WaitEvent, Some(SysCallNumber::ReceiveMessage) => SysCall::ReceiveMessage((a1, a2, a3, a4)), @@ -676,6 +694,19 @@ pub fn map_memory( } } +/// Map the given physical address to the given virtual address. +/// The `size` field must be page-aligned. +pub fn unmap_memory(virt: MemoryAddress, size: usize) -> core::result::Result<(), Error> { + let result = rsyscall(SysCall::UnmapMemory(virt.get() as *mut usize, size))?; + if let Result::Ok = result { + Ok(()) + } else if let Result::Error(e) = result { + Err(e) + } else { + Err(Error::InternalError) + } +} + /// Claim a hardware interrupt for this process. pub fn claim_interrupt( irq_no: usize,