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 <sean@xobs.io>
This commit is contained in:
Sean Cross 2021-08-18 18:21:19 +08:00
parent f5de6551bc
commit 7dee05082c

View file

@ -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 {