kernel: hosted: handle TrySendMessage the same as SendMessage

With the introduction of TrySendMessage, the kernel needs to know that
this data structure should be transmitted over the wire in the same
manner as SendMessage. Previously it was not special-casing this, which
resulted in memory errors.

Signed-off-by: Sean <xobs@ci.betrusted.io>
This commit is contained in:
Sean 2020-09-03 13:17:01 +08:00
parent 2dc0545eaa
commit 3e6d3904fb

View file

@ -101,7 +101,8 @@ fn handle_connection(
*word = usize::from_le_bytes(bytes.try_into().unwrap()); *word = usize::from_le_bytes(bytes.try_into().unwrap());
} }
if packet_data[1] == 16 if (packet_data[1] == xous_kernel::syscall::SysCallNumber::SendMessage as _
|| packet_data[1] == xous_kernel::syscall::SysCallNumber::TrySendMessage as _)
&& (packet_data[3] == 1 || packet_data[3] == 2 || packet_data[3] == 3) && (packet_data[3] == 1 || packet_data[3] == 2 || packet_data[3] == 3)
{ {
let mut v = vec![0; packet_data[6]]; let mut v = vec![0; packet_data[6]];
@ -180,39 +181,41 @@ fn handle_connection(
// "Received packet: {:08x} {} {} {} {} {} {} {}: {:?}", // "Received packet: {:08x} {} {} {} {} {} {} {}: {:?}",
// pkt[0], pkt[1], pkt[2], pkt[3], pkt[4], pkt[5], pkt[6], pkt[7], call // pkt[0], pkt[1], pkt[2], pkt[3], pkt[4], pkt[5], pkt[6], pkt[7], call
// ); // );
if let SysCall::SendMessage(ref _cid, ref mut envelope) = call { match call {
match envelope { SysCall::SendMessage(ref _cid, ref mut envelope)
xous_kernel::Message::MutableBorrow(msg) | SysCall::TrySendMessage(ref _cid, ref mut envelope) => {
| xous_kernel::Message::Borrow(msg) match envelope {
| xous_kernel::Message::Move(msg) => { xous_kernel::Message::MutableBorrow(msg)
// Update the address pointer. This will get turned back into a | xous_kernel::Message::Borrow(msg)
// usable pointer by casting it back into a &[T] on the other | xous_kernel::Message::Move(msg) => {
// side. This is just a pointer to the start of data // Update the address pointer. This will get turned back into a
// as well as the index into the data it points at. The lengths // usable pointer by casting it back into a &[T] on the other
// should still be equal once we reconstitute the data in the // side. This is just a pointer to the start of data
// other process. // as well as the index into the data it points at. The lengths
// ::debug_here::debug_here!(); // should still be equal once we reconstitute the data in the
let sliced_data = data.into_boxed_slice(); // other process.
assert_eq!( // ::debug_here::debug_here!();
sliced_data.len(), let sliced_data = data.into_boxed_slice();
msg.buf.len(), assert_eq!(
"deconstructed data {} != message buf length {}", sliced_data.len(),
sliced_data.len(), msg.buf.len(),
msg.buf.len() "deconstructed data {} != message buf length {}",
); sliced_data.len(),
msg.buf.addr = msg.buf.len()
match MemoryAddress::new(Box::into_raw(sliced_data) );
as *mut u8 msg.buf.addr =
as usize) match MemoryAddress::new(Box::into_raw(sliced_data)
{ as *mut u8
Some(a) => a, as usize)
_ => unreachable!(), {
}; Some(a) => a,
_ => unreachable!(),
};
}
xous_kernel::Message::Scalar(_) => (),
} }
xous_kernel::Message::Scalar(_) => (),
} }
} else { _ => panic!("unsupported message type"),
panic!("unsupported message type");
} }
chn.send(ThreadMessage::SysCall(pid, thread_id, call)) chn.send(ThreadMessage::SysCall(pid, thread_id, call))
.expect("couldn't make syscall"); .expect("couldn't make syscall");