Skip to main content

strat9_kernel/ipc/
message.rs

1pub use strat9_abi::data::IpcMessage;
2
3use zerocopy::FromBytes;
4
5#[repr(C)]
6#[derive(Debug, Clone, Copy, PartialEq, Eq, FromBytes)]
7pub struct IpcLabel {
8    pub tier: u8,
9    pub family: u8,
10    pub compartment: u16,
11}
12
13/// Performs the ipc message from raw operation.
14pub fn ipc_message_from_raw(buf: &[u8; 64]) -> IpcMessage {
15    // SAFETY: `buf` has exactly 64 bytes, matching `IpcMessage` size.
16    unsafe { core::ptr::read_unaligned(buf.as_ptr() as *const IpcMessage) }
17}
18
19/// Performs the ipc message to raw operation.
20pub fn ipc_message_to_raw(msg: &IpcMessage, out: &mut [u8; 64]) {
21    // SAFETY: `out` has exactly 64 bytes, matching `IpcMessage` size.
22    unsafe {
23        core::ptr::copy_nonoverlapping(msg as *const _ as *const u8, out.as_mut_ptr(), 64);
24    }
25}
26
27static_assertions::assert_eq_size!(IpcMessage, [u8; 64]);
28static_assertions::const_assert_eq!(core::mem::align_of::<IpcMessage>(), 64);