xous: hosted: read back memory for TrySendMessage

Like SendMessage, the TrySendMessage requires us to read back memory.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2020-08-30 17:38:24 +08:00
parent 7a2e5fbde8
commit 1a0bb99890

View file

@ -520,49 +520,54 @@ fn _xous_syscall_result(
// println!(" Waiting again");
continue;
}
if let crate::SysCall::SendMessage(_, ref msg) = call {
match msg {
crate::Message::MutableBorrow(crate::MemoryMessage {
id: _id,
buf,
offset: _offset,
valid: _valid,
}) => {
// Read the buffer back from the remote host.
use core::slice;
let mut data =
unsafe { slice::from_raw_parts_mut(buf.addr.get() as _, buf.size.get()) };
stream.read_exact(&mut data).expect("Server shut down");
// pkt.extend_from_slice(data);
match &call {
crate::SysCall::SendMessage(_, msg) | crate::SysCall::TrySendMessage(_, msg) => {
match msg {
crate::Message::MutableBorrow(crate::MemoryMessage {
id: _id,
buf,
offset: _offset,
valid: _valid,
}) => {
// Read the buffer back from the remote host.
use core::slice;
let mut data = unsafe {
slice::from_raw_parts_mut(buf.addr.get() as _, buf.size.get())
};
stream.read_exact(&mut data).expect("Server shut down");
// pkt.extend_from_slice(data);
}
crate::Message::Borrow(crate::MemoryMessage {
id: _id,
buf,
offset: _offset,
valid: _valid,
}) => {
// Read the buffer back from the remote host and ensure it's the same
use core::slice;
let mut check_data = Vec::new();
check_data.resize(buf.len(), 0);
let data =
unsafe { slice::from_raw_parts_mut(buf.as_mut_ptr(), buf.len()) };
stream
.read_exact(&mut check_data)
.expect("Server shut down");
assert_eq!(data, check_data.as_slice());
}
crate::Message::Move(crate::MemoryMessage {
id: _id,
buf: _buf,
offset: _offset,
valid: _valid,
}) => (),
// Nothing to do for Immutable borrow, since the memory can't change
crate::Message::Scalar(_) => (),
}
crate::Message::Borrow(crate::MemoryMessage {
id: _id,
buf,
offset: _offset,
valid: _valid,
}) => {
// Read the buffer back from the remote host and ensure it's the same
use core::slice;
let mut check_data = Vec::new();
check_data.resize(buf.len(), 0);
let data = unsafe { slice::from_raw_parts_mut(buf.as_mut_ptr(), buf.len()) };
stream
.read_exact(&mut check_data)
.expect("Server shut down");
assert_eq!(data, check_data.as_slice());
}
crate::Message::Move(crate::MemoryMessage {
id: _id,
buf: _buf,
offset: _offset,
valid: _valid,
}) => (),
// Nothing to do for Immutable borrow, since the memory can't change
crate::Message::Scalar(_) => (),
}
_ => (),
}
// Now that we have the Stream mutex, temporarily take the Mailbox mutex to see if