From 7dee05082c242813ee58fea2c93b0bcca813ccc8 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Wed, 18 Aug 2021 18:21:19 +0800 Subject: [PATCH] xous: syscall: add function to modify memory ptr Add a function to modify the pointer of a MemoryRange. This is used by `hosted` mode in order to modify memory pointers when we receive them from the remote client. Signed-off-by: Sean Cross --- xous-rs/src/syscall.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/xous-rs/src/syscall.rs b/xous-rs/src/syscall.rs index df717e5d8..5650b29e6 100644 --- a/xous-rs/src/syscall.rs +++ b/xous-rs/src/syscall.rs @@ -985,6 +985,25 @@ impl SysCall { } } + /// If the syscall has memory attached to it, return the memory, mutably + /// + /// # Safety + /// + /// This function is only safe to call to fixup the pointer. It should + /// not be used for any other purpose. + pub unsafe fn memory_mut(&mut self) -> Option<&mut MemoryRange> { + match self { + SysCall::TrySendMessage(_, msg) | SysCall::SendMessage(_, msg) => match msg { + Message::Move(memory_message) + | Message::Borrow(memory_message) + | Message::MutableBorrow(memory_message) => Some(&mut memory_message.buf), + _ => None, + }, + SysCall::ReturnMemory(_, range, _, _) => Some(range), + _ => None, + } + } + /// Returns `true` if the given syscall may be called from an IRQ context pub fn can_call_from_interrupt(&self) -> bool { if let SysCall::TrySendMessage(_cid, msg) = self {