Skip to main content

kernel_api/syscall/
result.rs

1use crate::allocator::AllocError;
2use crate::ptr::PointerError;
3
4pub type Result<T> = core::result::Result<T, Error>;
5
6macro_rules! define_error {
7    ($(#[$attr:meta])* pub enum Error {
8	    $($name:ident = $val:literal),*
9	    $(,)?
10    }) => {
11	    $(#[$attr])* pub enum Error {
12	        $($name = $val),*
13        }
14
15	    impl From<u128> for Error {
16			fn from(value: u128) -> Error {
17				match value {
18					$($val => Error::$name),*,
19					_ => Self::Invalid,
20				}
21			}
22		}
23    };
24}
25
26define_error! {
27	#[derive(Debug, Copy, Clone, Eq, PartialEq)]
28	#[repr(u16)]
29	pub enum Error {
30		InvalidPointer = 0,
31		InvalidUtf8 = 1,
32		UnsupportedProtocol = 2,
33		UnknownProtocol = 3,
34		EndpointNotFound = 4,
35		NameInUse = 5,
36		InvalidHandle = 6,
37		Overflow = 7,
38		InvalidName = 8,
39		DeadServer = 9,
40		InvalidReturn = 10,
41		Invalid = 11,
42		AllocationFailure = 12,
43		InvalidArg = 13,
44		AsyncUnsupported = 14,
45		FutureCompat = 15,
46		// Object is not long enough for passed arguments
47		EndOfData = 16,
48		ProtocolOverlap = 17,
49	}
50}
51
52impl From<PointerError> for Error {
53	fn from(_: PointerError) -> Self {
54		Self::InvalidPointer
55	}
56}
57
58impl From<AllocError> for Error {
59	fn from(_: AllocError) -> Self {
60		Self::AllocationFailure
61	}
62}