sel4/arch/riscv/
fault.rs

1//
2// Copyright 2023, Colias Group, LLC
3//
4// SPDX-License-Identifier: MIT
5//
6
7use 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_enum]
21#[derive(Debug, Clone, PartialEq, Eq)]
22pub enum Fault {
23    NullFault(NullFault),
24    CapFault(CapFault),
25    UnknownSyscall(UnknownSyscall),
26    UserException(UserException),
27    VmFault(VmFault),
28    #[sel4_cfg(KERNEL_MCS)]
29    Timeout(Timeout),
30}
31
32impl Fault {
33    pub fn from_sys(raw: sys::seL4_Fault) -> Self {
34        sel4_cfg_wrap_match! {
35            match raw.splay() {
36                sys::seL4_Fault_Splayed::NullFault(inner) => {
37                    Self::NullFault(NullFault::from_inner(inner))
38                }
39                sys::seL4_Fault_Splayed::CapFault(inner) => Self::CapFault(CapFault::from_inner(inner)),
40                sys::seL4_Fault_Splayed::UnknownSyscall(inner) => {
41                    Self::UnknownSyscall(UnknownSyscall::from_inner(inner))
42                }
43                sys::seL4_Fault_Splayed::UserException(inner) => {
44                    Self::UserException(UserException::from_inner(inner))
45                }
46                sys::seL4_Fault_Splayed::VMFault(inner) => Self::VmFault(VmFault::from_inner(inner)),
47                #[sel4_cfg(KERNEL_MCS)]
48                sys::seL4_Fault_Splayed::Timeout(inner) => Self::Timeout(Timeout::from_inner(inner)),
49            }
50        }
51    }
52}