sel4_sys/fault/arch/
riscv.rs

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
//
// Copyright 2023, Colias Group, LLC
//
// SPDX-License-Identifier: BSD-2-Clause
//

use crate::bf::*;
use crate::c::*;

use sel4_config::sel4_cfg_wrap_match;

impl seL4_Fault {
    pub(crate) fn arch_get_with(
        label: seL4_Word,
        length: seL4_Word,
        f: impl Fn(core::ffi::c_ulong) -> seL4_Word,
    ) -> Option<Self> {
        let f = |i: core::ffi::c_uint| f(i.into());
        let length: core::ffi::c_uint = length.try_into().unwrap();
        Some(sel4_cfg_wrap_match! {
            match label {
                seL4_Fault_tag::seL4_Fault_UnknownSyscall => {
                    assert!(length == seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_Length);
                    seL4_Fault_UnknownSyscall_Unpacked {
                        FaultIP: f(seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_FaultIP),
                        SP: f(seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_SP),
                        RA: f(seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_RA),
                        A0: f(seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_A0),
                        A1: f(seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_A1),
                        A2: f(seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_A2),
                        A3: f(seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_A3),
                        A4: f(seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_A4),
                        A5: f(seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_A5),
                        A6: f(seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_A6),
                        Syscall: f(seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_Syscall),
                    }
                    .unsplay()
                }
                seL4_Fault_tag::seL4_Fault_UserException => {
                    assert!(length == seL4_UserException_Msg::seL4_UserException_Length);
                    seL4_Fault_UserException_Unpacked {
                        FaultIP: f(seL4_UserException_Msg::seL4_UserException_FaultIP),
                        SP: f(seL4_UserException_Msg::seL4_UserException_SP),
                        Number: f(seL4_UserException_Msg::seL4_UserException_Number),
                        Code: f(seL4_UserException_Msg::seL4_UserException_Code),
                    }
                    .unsplay()
                }
                seL4_Fault_tag::seL4_Fault_VMFault => {
                    assert!(length == seL4_VMFault_Msg::seL4_VMFault_Length);
                    seL4_Fault_VMFault_Unpacked {
                        IP: f(seL4_VMFault_Msg::seL4_VMFault_IP),
                        Addr: f(seL4_VMFault_Msg::seL4_VMFault_Addr),
                        PrefetchFault: f(seL4_VMFault_Msg::seL4_VMFault_PrefetchFault),
                        FSR: f(seL4_VMFault_Msg::seL4_VMFault_FSR),
                    }
                    .unsplay()
                }
                _ => return None,
            }
        })
    }
}