sel4_sys/fault/
mod.rs

1//
2// Copyright 2023, Colias Group, LLC
3//
4// SPDX-License-Identifier: BSD-2-Clause
5//
6
7use crate::bf::*;
8use crate::c::*;
9
10use sel4_config::sel4_cfg_wrap_match;
11
12mod arch;
13
14impl seL4_Fault {
15    pub fn get_from_ipc_buffer(info: &seL4_MessageInfo, ipcbuf: &seL4_IPCBuffer) -> Self {
16        Self::get_with(info.get_label(), info.get_length(), |i| {
17            ipcbuf.msg[i as usize]
18        })
19    }
20
21    pub fn get_with(
22        label: seL4_Word,
23        length: seL4_Word,
24        f: impl Fn(core::ffi::c_ulong) -> seL4_Word,
25    ) -> Self {
26        sel4_cfg_wrap_match! {
27            match label {
28                seL4_Fault_tag::seL4_Fault_NullFault => {
29                    // TODO
30                    // assert!(length == seL4_NullFault_Msg::seL4_NullFault_Length);
31                    seL4_Fault_NullFault_Unpacked {}.unsplay()
32                }
33                seL4_Fault_tag::seL4_Fault_CapFault => {
34                    // TODO
35                    // assert!(length == seL4_CapFault_Msg::seL4_CapFault_Length);
36                    seL4_Fault_CapFault_Unpacked {
37                        IP: f(seL4_CapFault_Msg::seL4_CapFault_IP),
38                        Addr: f(seL4_CapFault_Msg::seL4_CapFault_Addr),
39                        InRecvPhase: f(seL4_CapFault_Msg::seL4_CapFault_InRecvPhase),
40                        LookupFailureType: f(seL4_CapFault_Msg::seL4_CapFault_LookupFailureType),
41                        MR4: f(seL4_CapFault_Msg::seL4_CapFault_BitsLeft),
42                        MR5: f(seL4_CapFault_Msg::seL4_CapFault_GuardMismatch_GuardFound),
43                        MR6: f(seL4_CapFault_Msg::seL4_CapFault_GuardMismatch_BitsFound),
44                    }
45                    .unsplay()
46                }
47                #[sel4_cfg(KERNEL_MCS)]
48                seL4_Fault_tag::seL4_Fault_Timeout => {
49                    assert!(length == seL4_Timeout_Msg::seL4_Timeout_Length.into());
50                    seL4_Fault_Timeout_Unpacked {
51                        data: f(seL4_Timeout_Msg::seL4_Timeout_Data.into()),
52                        consumed: f(seL4_Timeout_Msg::seL4_Timeout_Consumed.into()),
53                    }
54                    .unsplay()
55                }
56                _ => {
57                    match Self::arch_get_with(label, length, f) {
58                    Some(fault) => fault,
59                    None => panic!("Unparsed fault label: {label}"),
60                }},
61            }
62        }
63    }
64}