1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
use core::fmt;
enum_with_val! {
#[derive(Clone, Copy, PartialEq, Eq)]
#[allow(missing_docs)]
pub struct KernelError(u32) {
InvalidKernelCaps = 14,
NotImplemented = 33,
InvalidSize = 101,
InvalidAddress = 102,
MemoryFull = 104,
HandleTableFull = 105,
InvalidMemState = 106,
InvalidMemPerms = 108,
InvalidMemRange = 110,
InvalidThreadPriority = 112,
InvalidProcessorId = 113,
InvalidHandle = 114,
CopyFromUserFailed = 115,
InvalidCombination = 116,
Timeout = 117,
Canceled = 118,
ExceedingMaximum = 119,
InvalidEnum = 120,
NoSuchEntry = 121,
PortRemoteDead = 123,
InvalidState = 125,
ReservedValue = 126,
}
}
impl KernelError {
pub fn make_ret(self) -> u32 {
(self.0 << 9) | 1
}
pub fn from_syscall_ret(err: u32) -> KernelError {
KernelError(err >> 9)
}
pub fn from_description(err: u32) -> KernelError {
KernelError(err)
}
pub fn description(self) -> u32 {
self.0
}
}
impl fmt::Display for KernelError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
KernelError::InvalidKernelCaps => write!(f, "Invalid kernel capabilities. Check the format."),
KernelError::NotImplemented => write!(f, "Method not implemented. Notify roblabla!"),
KernelError::InvalidSize => write!(f, "Invalid size."),
KernelError::InvalidAddress => write!(f, "Invalid address."),
KernelError::MemoryFull => write!(f, "Memory full. Try to kill some processes and try again."),
KernelError::HandleTableFull => write!(f, "Handle table full. You might want to bump your handle table size in the NPDM."),
KernelError::InvalidMemPerms => write!(f, "Invalid memory permissions."),
KernelError::InvalidHandle => write!(f, "Invalid handle. Either it does not exist, or the Handle is of the wrong type."),
KernelError::CopyFromUserFailed => write!(f, "Copy from user failed. The pointer either does not point in userspace, or points to unmapped memory."),
KernelError::InvalidCombination => write!(f, "Invalid combination."),
KernelError::Timeout => write!(f, "Timeout exceeded."),
KernelError::Canceled => write!(f, "Cancelled."),
KernelError::ExceedingMaximum => write!(f, "Argument exceeded maximum possible value."),
KernelError::NoSuchEntry => write!(f, "The entry does not exist."),
KernelError::PortRemoteDead => write!(f, "Remote handle closed. Usually happens when an IPC got sent in the wrong format."),
KernelError::InvalidState => write!(f, "Handle is in invalid state for this operation."),
KernelError(err) => write!(f, "Unknown error: {}", err)
}
}
}