strat9_kernel/ipc/
message.rs1pub use strat9_abi::data::IpcMessage;
2use strat9_abi::data::{IPC_MESSAGE_ALIGN, IPC_MESSAGE_SIZE};
3
4use zerocopy::FromBytes;
5
6#[repr(C)]
7#[derive(Debug, Clone, Copy, PartialEq, Eq, FromBytes)]
8pub struct IpcLabel {
9 pub tier: u8,
10 pub family: u8,
11 pub compartment: u16,
12}
13
14pub fn ipc_message_from_raw(buf: &[u8; IPC_MESSAGE_SIZE]) -> IpcMessage {
16 unsafe { core::ptr::read_unaligned(buf.as_ptr() as *const IpcMessage) }
18}
19
20pub fn ipc_message_to_raw(msg: &IpcMessage, out: &mut [u8; IPC_MESSAGE_SIZE]) {
22 unsafe {
24 core::ptr::copy_nonoverlapping(
25 msg as *const _ as *const u8,
26 out.as_mut_ptr(),
27 IPC_MESSAGE_SIZE,
28 );
29 }
30}
31
32static_assertions::assert_eq_size!(IpcMessage, [u8; IPC_MESSAGE_SIZE]);
33static_assertions::const_assert_eq!(core::mem::align_of::<IpcMessage>(), IPC_MESSAGE_ALIGN);