1use sel4_config::{sel4_cfg, sel4_cfg_enum, sel4_cfg_wrap_match};
8
9use crate::{declare_fault_newtype, sys};
10
11declare_fault_newtype!(NullFault, seL4_Fault_NullFault);
12declare_fault_newtype!(CapFault, seL4_Fault_CapFault);
13declare_fault_newtype!(UnknownSyscall, seL4_Fault_UnknownSyscall);
14declare_fault_newtype!(UserException, seL4_Fault_UserException);
15declare_fault_newtype!(VmFault, seL4_Fault_VMFault);
16
17#[sel4_cfg(KERNEL_MCS)]
18declare_fault_newtype!(Timeout, seL4_Fault_Timeout);
19
20#[sel4_cfg(HARDWARE_DEBUG_API)]
21declare_fault_newtype!(DebugException, seL4_Fault_DebugException);
22
23#[sel4_cfg_enum]
24#[derive(Debug, Clone, PartialEq, Eq)]
25pub enum Fault {
26 NullFault(NullFault),
27 CapFault(CapFault),
28 UnknownSyscall(UnknownSyscall),
29 UserException(UserException),
30 VmFault(VmFault),
31 #[sel4_cfg(KERNEL_MCS)]
32 Timeout(Timeout),
33 #[sel4_cfg(HARDWARE_DEBUG_API)]
34 DebugException(DebugException),
35}
36
37impl Fault {
38 pub fn from_sys(raw: sys::seL4_Fault) -> Self {
39 sel4_cfg_wrap_match! {
40 match raw.splay() {
41 sys::seL4_Fault_Splayed::NullFault(inner) => {
42 Self::NullFault(NullFault::from_inner(inner))
43 }
44 sys::seL4_Fault_Splayed::CapFault(inner) => Self::CapFault(CapFault::from_inner(inner)),
45 sys::seL4_Fault_Splayed::UnknownSyscall(inner) => {
46 Self::UnknownSyscall(UnknownSyscall::from_inner(inner))
47 }
48 sys::seL4_Fault_Splayed::UserException(inner) => {
49 Self::UserException(UserException::from_inner(inner))
50 }
51 sys::seL4_Fault_Splayed::VMFault(inner) => Self::VmFault(VmFault::from_inner(inner)),
52 #[sel4_cfg(KERNEL_MCS)]
53 sys::seL4_Fault_Splayed::Timeout(inner) => Self::Timeout(Timeout::from_inner(inner)),
54 #[sel4_cfg(HARDWARE_DEBUG_API)]
55 sys::seL4_Fault_Splayed::DebugException(inner) => Self::DebugException(DebugException::from_inner(inner)),
56 }
57 }
58 }
59}