xous: hosted: free MemoryMessage::Move after send

This ensures that these messages aren't leaked. In a native system, this
memory would be "freed" by the kernel as it is attached to the new
memory space.

Signed-off-by: Sean <xobs@ci.betrusted.io>
This commit is contained in:
Sean 2020-09-03 13:22:13 +08:00
parent 5b45382489
commit f1353e8ff0

View file

@ -559,10 +559,15 @@ fn _xous_syscall_result(
crate::Message::Move(crate::MemoryMessage { crate::Message::Move(crate::MemoryMessage {
id: _id, id: _id,
buf: _buf, buf,
offset: _offset, offset: _offset,
valid: _valid, valid: _valid,
}) => (), }) => {
// In a hosted environment, the message contents are leaked when
// it gets converted into a MemoryMessage. Now that the call is
// complete, free the memory.
mem::unmap_memory_post(*buf).unwrap();
},
// Nothing to do for Immutable borrow, since the memory can't change // Nothing to do for Immutable borrow, since the memory can't change
crate::Message::Scalar(_) => (), crate::Message::Scalar(_) => (),
} }
@ -612,33 +617,36 @@ fn _xous_syscall_to(
for word in &[nr, a1, a2, a3, a4, a5, a6, a7] { for word in &[nr, a1, a2, a3, a4, a5, a6, a7] {
pkt.extend_from_slice(&word.to_le_bytes()); pkt.extend_from_slice(&word.to_le_bytes());
} }
if let crate::SysCall::SendMessage(_, ref msg) = call { match call {
match msg { crate::SysCall::SendMessage(_, ref msg) | crate::SysCall::TrySendMessage(_, ref msg) => {
crate::Message::MutableBorrow(crate::MemoryMessage { match msg {
id: _id, crate::Message::MutableBorrow(crate::MemoryMessage {
buf, id: _id,
offset: _offset, buf,
valid: _valid, offset: _offset,
}) valid: _valid,
| crate::Message::Borrow(crate::MemoryMessage { })
id: _id, | crate::Message::Borrow(crate::MemoryMessage {
buf, id: _id,
offset: _offset, buf,
valid: _valid, offset: _offset,
}) valid: _valid,
| crate::Message::Move(crate::MemoryMessage { })
id: _id, | crate::Message::Move(crate::MemoryMessage {
buf, id: _id,
offset: _offset, buf,
valid: _valid, offset: _offset,
}) => { valid: _valid,
use core::slice; }) => {
let data: &[u8] = use core::slice;
unsafe { slice::from_raw_parts(buf.addr.get() as _, buf.size.get()) }; let data: &[u8] =
pkt.extend_from_slice(data); unsafe { slice::from_raw_parts(buf.addr.get() as _, buf.size.get()) };
pkt.extend_from_slice(data);
}
crate::Message::Scalar(_) => (),
} }
crate::Message::Scalar(_) => (),
} }
_ => (),
} }
xsc.write_all(&pkt).expect("Server shut down"); xsc.write_all(&pkt).expect("Server shut down");