Nothing to see here, move along
at main 66 lines 2.2 kB view raw
1#[must_use] 2#[non_exhaustive] 3#[derive(Debug, Clone, Copy, PartialEq, Eq)] 4#[repr(i64)] 5pub enum KernelError { 6 SlotOccupied = -1, 7 SlotEmpty = -2, 8 InvalidObject = -3, 9 InsufficientRights = -4, 10 StaleGeneration = -5, 11 PoolExhausted = -6, 12 InvalidType = -7, 13 InvalidSlot = -8, 14 InvalidAddress = -9, 15 WouldBlock = -10, 16 ResourceExhausted = -11, 17 #[allow(dead_code)] 18 NotFound = -12, 19 PermissionDenied = -13, 20 BadState = -14, 21 InvalidParameter = -15, 22 NotInitialized = -16, 23 IommuFault = -17, 24 AlreadyExists = -18, 25 DepthLimit = -19, 26 GuardMismatch = -20, 27} 28 29impl KernelError { 30 pub const fn to_errno(self) -> i64 { 31 self as i64 32 } 33} 34 35impl core::fmt::Display for KernelError { 36 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 37 match self { 38 Self::SlotOccupied => write!(f, "slot occupied"), 39 Self::SlotEmpty => write!(f, "slot empty"), 40 Self::InvalidObject => write!(f, "invalid object"), 41 Self::InsufficientRights => write!(f, "insufficient rights"), 42 Self::StaleGeneration => write!(f, "stale generation"), 43 Self::PoolExhausted => write!(f, "pool exhausted"), 44 Self::InvalidType => write!(f, "invalid type"), 45 Self::InvalidSlot => write!(f, "invalid slot"), 46 Self::InvalidAddress => write!(f, "invalid address"), 47 Self::WouldBlock => write!(f, "would block"), 48 Self::ResourceExhausted => write!(f, "resource exhausted"), 49 Self::NotFound => write!(f, "not found"), 50 Self::PermissionDenied => write!(f, "permission denied"), 51 Self::BadState => write!(f, "bad state"), 52 Self::InvalidParameter => write!(f, "invalid parameter"), 53 Self::NotInitialized => write!(f, "not initialized"), 54 Self::IommuFault => write!(f, "iommu fault"), 55 Self::AlreadyExists => write!(f, "already exists"), 56 Self::DepthLimit => write!(f, "depth limit"), 57 Self::GuardMismatch => write!(f, "guard mismatch"), 58 } 59 } 60} 61 62impl From<KernelError> for i64 { 63 fn from(e: KernelError) -> Self { 64 e.to_errno() 65 } 66}