Convert a Message to values which can be put into registers for a send or send_receive syscall. This should be the inverse of from_values, and consistent with the kernel Message implementation.
(
&mut self
)
| 75 | /// This should be the inverse of from_values, and consistent with |
| 76 | /// the kernel Message implementation. |
| 77 | pub fn to_values( |
| 78 | &mut self |
| 79 | ) -> Result<(u64, u64, u64, u64), SyscallError> { |
| 80 | match self { |
| 81 | Message::Short(data1, data2, data3) => { |
| 82 | Ok((0, *data1, *data2, *data3)) |
| 83 | }, |
| 84 | Message::Long(value1, ref mut data2, ref mut data3) => { |
| 85 | let mut ctrl: u64 = MESSAGE_LONG; |
| 86 | let value2 = match data2 { |
| 87 | MessageData::Value(value) => *value, |
| 88 | MessageData::CommHandle(ref mut handle) => { |
| 89 | ctrl |= MESSAGE_DATA2_RDV; // Rendezvous |
| 90 | unsafe{handle.take() as u64} |
| 91 | } |
| 92 | MessageData::MemoryHandle(ref mut handle) => { |
| 93 | ctrl |= MESSAGE_DATA2_MEM; // Memory |
| 94 | unsafe{handle.take()} |
| 95 | } |
| 96 | MessageData::Error(syserror) => { |
| 97 | ctrl |= MESSAGE_DATA2_ERR; // Error |
| 98 | syserror.as_u64() |
| 99 | } |
| 100 | }; |
| 101 | let value3 = match data3 { |
| 102 | MessageData::Value(value) => *value, |
| 103 | MessageData::CommHandle(ref mut handle) => { |
| 104 | ctrl |= MESSAGE_DATA3_RDV; // Rendezvous |
| 105 | unsafe{handle.take() as u64} |
| 106 | } |
| 107 | MessageData::MemoryHandle(ref mut handle) => { |
| 108 | ctrl |= MESSAGE_DATA3_MEM; // Memory |
| 109 | unsafe{handle.take()} |
| 110 | } |
| 111 | MessageData::Error(syserror) => { |
| 112 | ctrl |= MESSAGE_DATA3_ERR; // Error |
| 113 | syserror.as_u64() |
| 114 | } |
| 115 | }; |
| 116 | Ok((ctrl, *value1, value2, value3)) |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | /// Reconstruct a Message from register values returned by a |
| 122 | /// receive syscall. |
no test coverage detected