veridian_kernel/ipc/
error.rs1use core::fmt;
4
5pub type Result<T> = core::result::Result<T, IpcError>;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10#[allow(dead_code)] pub enum IpcError {
12 InvalidCapability,
14 ProcessNotFound,
16 EndpointNotFound,
18 MessageTooLarge,
20 OutOfMemory,
22 WouldBlock,
24 RateLimitExceeded,
26 Timeout,
28 PermissionDenied,
30 InvalidMessage,
32 ChannelFull,
34 ChannelEmpty,
36 EndpointBusy,
38 InvalidMemoryRegion,
40 ResourceBusy,
42 NotInitialized,
44}
45
46impl IpcError {
47 pub fn as_str(&self) -> &'static str {
49 match self {
50 Self::InvalidCapability => "Invalid or revoked capability",
51 Self::ProcessNotFound => "Target process not found",
52 Self::EndpointNotFound => "Endpoint not found",
53 Self::MessageTooLarge => "Message too large",
54 Self::OutOfMemory => "Out of memory",
55 Self::WouldBlock => "Operation would block",
56 Self::RateLimitExceeded => "Rate limit exceeded",
57 Self::Timeout => "Operation timed out",
58 Self::PermissionDenied => "Permission denied",
59 Self::InvalidMessage => "Invalid message format",
60 Self::ChannelFull => "Channel is full",
61 Self::ChannelEmpty => "Channel is empty",
62 Self::EndpointBusy => "Endpoint is busy",
63 Self::InvalidMemoryRegion => "Invalid memory region",
64 Self::ResourceBusy => "Resource temporarily unavailable",
65 Self::NotInitialized => "IPC system not initialized",
66 }
67 }
68
69 #[allow(dead_code)] pub fn to_errno(self) -> i32 {
72 match self {
73 Self::InvalidCapability => -1,
74 Self::ProcessNotFound => -2,
75 Self::EndpointNotFound => -3,
76 Self::MessageTooLarge => -4,
77 Self::OutOfMemory => -5,
78 Self::WouldBlock => -6,
79 Self::RateLimitExceeded => -7,
80 Self::Timeout => -8,
81 Self::PermissionDenied => -9,
82 Self::InvalidMessage => -10,
83 Self::ChannelFull => -11,
84 Self::ChannelEmpty => -12,
85 Self::EndpointBusy => -13,
86 Self::InvalidMemoryRegion => -14,
87 Self::ResourceBusy => -15,
88 Self::NotInitialized => -16,
89 }
90 }
91}
92
93impl fmt::Display for IpcError {
94 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
95 write!(f, "{}", self.as_str())
96 }
97}