⚠️ VeridianOS Kernel Documentation - This is low-level kernel code. All functions are unsafe unless explicitly marked otherwise. no_std

veridian_kernel/ipc/
error.rs

1//! IPC error types and result definitions
2
3use core::fmt;
4
5/// IPC operation result type
6pub type Result<T> = core::result::Result<T, IpcError>;
7
8/// IPC error types
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10#[allow(dead_code)] // Public error enum -- variants used across IPC subsystem
11pub enum IpcError {
12    /// Invalid or revoked capability
13    InvalidCapability,
14    /// Target process not found
15    ProcessNotFound,
16    /// Target endpoint does not exist
17    EndpointNotFound,
18    /// Message size exceeds maximum allowed
19    MessageTooLarge,
20    /// No memory available for operation
21    OutOfMemory,
22    /// Operation would block but non-blocking mode requested
23    WouldBlock,
24    /// Rate limit exceeded for this endpoint
25    RateLimitExceeded,
26    /// Operation timed out
27    Timeout,
28    /// Permission denied for the requested operation
29    PermissionDenied,
30    /// Invalid message format or parameters
31    InvalidMessage,
32    /// Channel is full (for async channels)
33    ChannelFull,
34    /// Channel is empty (for async channels)
35    ChannelEmpty,
36    /// Endpoint is already bound to another process
37    EndpointBusy,
38    /// Invalid memory region specified
39    InvalidMemoryRegion,
40    /// Resource temporarily unavailable
41    ResourceBusy,
42    /// IPC system not initialized
43    NotInitialized,
44}
45
46impl IpcError {
47    /// Get a static string description of the error
48    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    /// Convert error to a numeric code for system calls
70    #[allow(dead_code)] // Syscall interface API
71    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}