forked from vmware-archive/node-replicated-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.rs
More file actions
265 lines (248 loc) · 9.63 KB
/
Copy patherror.rs
File metadata and controls
265 lines (248 loc) · 9.63 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
// Copyright © 2021 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT
use alloc::string::FromUtf8Error;
use core::{convert::From, num::TryFromIntError};
use arrayvec::CapacityError;
use kpi::SystemCallError;
use crate::memory::VAddr;
/// Shortcut for a Result that returns an error of type KError.
pub(crate) type KResult<T> = Result<T, KError>;
/// Kernel-wide error type with everything that can potentially go wrong.
#[derive(displaydoc::Display, PartialEq, Clone, Debug)]
pub enum KError {
/// User-space pointer is not valid
BadAddress,
/// Global memory is not yet available
GlobalMemoryNotSet,
/// The requested core is already allocated by another process
CoreAlreadyAllocated,
/// Ran out of memory while performing an allocation
OutOfMemory,
/// Replica is not set-up in the KCB
ReplicaNotSet,
/// The core has no current process set
ProcessNotSet,
/// The requested operation is not supported/does not exist
NotSupported,
/// Can't spawn more processes (not enough PIDs)
OutOfPids,
/// The core we're looking up has no executor allocated to it
NoExecutorForCore,
/// Invalid 1st syscall argument supplied: {a}
InvalidSyscallArgument1 { a: u64 },
/// Invalid VSpace Operation (2nd syscall argument) supplied: {a}
InvalidVSpaceOperation { a: u64 },
/// Invalid Process Operation (2nd syscall argument) supplied: {a}
InvalidProcessOperation { a: u64 },
/// Invalid System Operation (2nd syscall argument) supplied: {a}
InvalidSystemOperation { a: u64 },
/// Invalid File Operation (2nd syscall argument) supplied: {a}
InvalidFileOperation { a: u64 },
/// System call arguments (2) received in the wrong order
InvalidSyscallTestArg2,
/// System call arguments (3) received in the wrong order
InvalidSyscallTestArg3,
/// System call arguments (4) received in the wrong order
InvalidSyscallTestArg4,
/// Invalid layout for allocator provided
InvalidLayout,
/// Couldn't allocate bytes on this cache, need to re-grow first
CacheExhausted,
/// Cache can't hold any more objects
CacheFull,
/// Cache full -- added {count} elements
CantGrowFurther { count: usize },
/// KCB not set, memory allocation won't work at this point
KcbUnavailable,
/// The memory manager was already borrowed (this is a bug)
ManagerAlreadyBorrowed,
/// Specified an invalid NUMA node ID for affinity
InvalidAffinityId,
/// Internal data-structure grew too big
CapacityOverflow,
/// Can't spawn more process
ProcessLoadingFailed,
/// Unable to create process
ProcessCreate,
/// No process was associated with the given PID
NoProcessFoundForPid,
/// Couldn't load process (invalid ELF file?)
UnableToLoad,
/// Couldn't parse ELF file (invalid ELF file?)
UnableToParseElf,
/// We never allocated executors for this affinity region and process (need to fill cache)
NoExecutorAllocated,
/// The executor cache for given affinity is empty (need to refill)
ExecutorCacheExhausted,
/// Specified an invalid core
InvalidGlobalThreadId,
/// The excutor was removed from the current core
ExecutorNoLongerValid,
/// The executor on the core was already borrowed (that's a bug)
ExecutorAlreadyBorrowed,
/// Unable to reserve memory for internal process data-structures
NotEnoughMemory,
/// The provided FrameId is not registered with the process
InvalidFrameId,
/// Not enough space in process table (out of PIDs)
TooManyProcesses,
/// Can't register more frames with the process (out of FIDs)
TooManyRegisteredFrames,
/// Supplied file descriptor was invalid
InvalidFileDescriptor,
/// Can't spawn binary {binary}: Not found
BinaryNotFound { binary: &'static str },
/// Supplied frame was invalid
InvalidFrame,
/// The frame could not be detached from the process -- still mapped in its VSpace.
FrameStillMapped,
/// Address space operation covers existing mapping {base:?}
AlreadyMapped { base: VAddr },
/// Provided virtual base {base:?} is invalid (led to overflow on mappings).
BaseOverflow { base: u64 },
/// The requested mapping is not found
NotMapped,
/// The supplied length is invalid
InvalidLength,
/// The supplied base is invalid (alignment?)
InvalidBase,
/// Supplied file is invalid
InvalidFile,
/// Supplied flags are invalid
InvalidFlags,
/// Supplied offset is invalid
InvalidOffset,
/// File/directory permission mismatch (can't be read or written)
PermissionError,
/// Fd or File already exists
AlreadyPresent,
/// Can't read or write to a directory
DirectoryError,
/// Can't open more files for the process
OpenFileLimit,
/// PID is already stored in scheduler state.
FileDescForPidAlreadyAdded,
/// No file-descriptors found for PID.
NoFileDescForPid,
/// Debugger is already attached
DebuggerAlreadyAttached,
/// Failure while running the GDB state machine
DebuggerStmFailure,
/// Can't read (debug) register
DebuggerUnableToReadRegister,
/// Can't write (debug) register
DebuggerUnableToWriteRegister,
/// Can't find a vmxnet3 device (did you pass `--nic vmxnet3`?)
VMXNet3DeviceNotFound,
/// Unable to initialize Ethernet device for RPC
UnableToInitEthernetRPC,
/// Thread-local storage was already initialized for the core
TLSAlreadyInitialized,
/// Unable to find IVSHMEM device on the PCI bus (did you pass `--qemu-ivshmem` and `--qemu-shmem-path`?)
IvShmemDeviceNotFound,
/// Specified Native mode on the kernel command line but kernel initialized a RPC connection?
InvalidNativeMode,
/// The provided user-space buffer address goes above `KERNEL_BASE`.
InvalidUserBufferArgs,
/// Trying to create a user-space virtual address above `KERNEL_BASE`.
NotAUserVAddr,
/// Kernel tried read user-memory that wasn't mapped readable in process' address space.
UserPtMissingReadAccess,
/// Kernel tried write user-memory that wasn't mapped writeable in process' address space.
UserPtMissingWriteAccess,
/// We tried to read from user-memory but we weren't in the process' address space.
NotInRightAddressSpaceForReading,
/// We tried to write to user-memory but we weren't in the process' address space.
NotInRightAddressSpaceForWriting,
/// The string we tried to create from user-memory was not valid UTF-8
NotAValidUtf8String,
/// The PID in the supplied argument does not match the PID of the UserSlice.
PidMismatchInProcessArgument,
/// The supplied buffers for `SliceWrite` have different lengths.
SliceLengthMismatchForWriting,
/// Tried to create a user-space buffer that's too big (> 2GiB)
UserBufferTooLarge,
/// Trying to cast a integer to another integer failed.
TryFromIntError,
/// The provided file-descriptor value was too big (>= MAX_FILES_PER_PROCESS)
FileDescriptorTooLarge,
/// Unable to convert message ID to valid RPC type (faulty message?)
InvalidRpcType,
/// Unable to perform DCM transaction (faulty message?)
DCMError,
}
impl From<CapacityError<crate::memory::Frame>> for KError {
fn from(_err: CapacityError<crate::memory::Frame>) -> Self {
KError::CacheFull
}
}
impl From<core::cell::BorrowMutError> for KError {
fn from(_e: core::cell::BorrowMutError) -> Self {
KError::ManagerAlreadyBorrowed
}
}
impl From<alloc::collections::TryReserveError> for KError {
fn from(_e: alloc::collections::TryReserveError) -> Self {
KError::OutOfMemory
}
}
impl From<fallible_collections::TryReserveError> for KError {
fn from(_e: fallible_collections::TryReserveError) -> Self {
KError::OutOfMemory
}
}
impl From<hashbrown::TryReserveError> for KError {
fn from(_e: hashbrown::TryReserveError) -> Self {
KError::OutOfMemory
}
}
impl From<elfloader::ElfLoaderErr> for KError {
fn from(_e: elfloader::ElfLoaderErr) -> Self {
KError::ProcessCreate
}
}
impl From<core::alloc::AllocError> for KError {
fn from(_e: core::alloc::AllocError) -> Self {
KError::OutOfMemory
}
}
impl From<FromUtf8Error> for KError {
fn from(_e: FromUtf8Error) -> Self {
KError::NotAValidUtf8String
}
}
impl From<TryFromIntError> for KError {
fn from(_e: TryFromIntError) -> Self {
KError::TryFromIntError
}
}
impl From<slabmalloc::AllocationError> for KError {
fn from(err: slabmalloc::AllocationError) -> KError {
match err {
slabmalloc::AllocationError::InvalidLayout => KError::InvalidLayout,
// slabmalloc OOM just means we have to refill:
slabmalloc::AllocationError::OutOfMemory => KError::CacheExhausted,
}
}
}
impl From<KError> for SystemCallError {
/// Translate KErrors to SystemCallErrors.
///
/// The idea is to reduce a big set of events into a smaller set of less precise errors.
/// We can log the the precise errors before we return in the kernel since the conversion
/// happens at the end of the system call.
fn from(e: KError) -> SystemCallError {
match e {
KError::InvalidSyscallArgument1 { .. } => SystemCallError::NotSupported,
KError::InvalidVSpaceOperation { .. } => SystemCallError::NotSupported,
KError::InvalidProcessOperation { .. } => SystemCallError::NotSupported,
KError::BadAddress { .. } => SystemCallError::BadAddress,
_ => SystemCallError::InternalError,
}
}
}
impl Default for KError {
fn default() -> KError {
KError::NotSupported
}
}