CHERIoT RTOS
A compartmentalised RTOS for CHERIoT hardware
Toggle main menu visibility
Loading...
Searching...
No Matches
sdk
include
compartment.h
1
// Copyright Microsoft and CHERIoT Contributors.
2
// SPDX-License-Identifier: MIT
3
4
#pragma once
5
#include <cdefs.h>
6
#include <
compartment-macros.h
>
7
#include <stddef.h>
8
#include <stdint.h>
9
10
#ifdef __cplusplus
11
# include <
cheri.hh
>
12
#endif
13
14
/**
15
* State for error handlers to use.
16
*
17
* Note: This structure should have the same layout as the register-save area
18
* (that is, the initial sequence of a TrustedStack, up through ca5, inclusive).
19
*/
20
struct
ErrorState
21
{
22
/**
23
* The faulting program counter. Error handlers may modify this but the
24
* result *must* point into the compartment's program counter capability.
25
* If it does not then the trusted stack will be unwound forcibly to the
26
* caller's compartment.
27
*
28
* Note: This is passed as an *untagged* capability. This allows error
29
* handlers to inspect the bounds and permissions, but does not convey the
30
* rights.
31
*/
32
void
*
pcc
;
33
34
/**
35
* The register state where the fault occurred. These may be modified by
36
* an error handler.
37
*/
38
void
*
registers
[15];
39
#ifdef __cplusplus
40
/**
41
* Templated method to get a reference to value of given
42
* CHERI::RegisterNumber.
43
*
44
* Static asserts that the register is one of the general purpose ones
45
* excluding CZR. This doesn't support getting PCC because in that case
46
* you can Use ErrorState.pcc directly.
47
*/
48
template
<CHERI::RegisterNumber ARegisterNumber>
49
[[nodiscard]]
void
*&
get_register_value
()
50
{
51
static_assert
(ARegisterNumber >
CHERI::RegisterNumber::CZR
&&
52
ARegisterNumber <=
CHERI::RegisterNumber::CA5
,
53
"get_register_value: invalid RegisterNumber"
);
54
return
this->registers[
static_cast<
size_t
>
(ARegisterNumber) - 1];
55
}
56
57
/**
58
* Returns a pointer to the value of the given CHERI::RegisterNumber from
59
* this ErrorState.
60
*
61
* Will either select the appropriate index into ErrorState.registers
62
* accounting for the missing CZR, ErrorState.PCC, or if registerNumber is
63
* invalid or not contained in ErrorState then nullptr is returned.
64
*/
65
[[nodiscard]]
void
**
66
get_register_value
(
CHERI::RegisterNumber
registerNumber)
67
{
68
if
(registerNumber >
CHERI::RegisterNumber::CZR
&&
69
registerNumber <=
CHERI::RegisterNumber::CA5
)
70
{
71
return
&this->registers[
static_cast<
size_t
>
(registerNumber) - 1];
72
}
73
if
(registerNumber ==
CHERI::RegisterNumber::PCC
)
74
{
75
return
&this->pcc;
76
}
77
return
nullptr
;
78
}
79
#endif
80
};
81
82
/**
83
* Valid return values from an error handler.
84
*/
85
enum
ErrorRecoveryBehaviour
86
{
87
/// Install the modified context.
88
InstallContext,
89
/// Unwind the trusted stack to the caller.
90
ForceUnwind
91
};
92
93
__BEGIN_DECLS
94
/**
95
* The error handler for the current compartment. A compartment may choose to
96
* implement this. If not implemented then compartment faults will unwind the
97
* trusted stack.
98
*/
99
__attribute__((
100
section(
".compartment_error_handler"
))) enum ErrorRecoveryBehaviour
101
compartment_error_handler(struct
ErrorState
*frame,
102
size_t
mcause,
103
size_t
mtval);
104
__END_DECLS
cheri.hh
C++ helpers for operating on capabilities.
CHERI::RegisterNumber
RegisterNumber
Register numbers as reported in thee cap idx field of mtval CSR when a CHERI exception is taken.
Definition
cheri.hh:1441
CHERI::RegisterNumber::CA5
@ CA5
$c15 / $ca5 used by the ABI as an argument register.
Definition
cheri.hh:1523
CHERI::RegisterNumber::CZR
@ CZR
The zero register, which always contains the NULL capability.
Definition
cheri.hh:1445
CHERI::RegisterNumber::PCC
@ PCC
The Program Counter Capability.
Definition
cheri.hh:1531
compartment-macros.h
Macros for interacting with the compartmentalisation model in CHERIoT.
ErrorState
State for error handlers to use.
Definition
compartment.h:21
ErrorState::get_register_value
void ** get_register_value(CHERI::RegisterNumber registerNumber)
Returns a pointer to the value of the given CHERI::RegisterNumber from this ErrorState.
Definition
compartment.h:66
ErrorState::get_register_value
void *& get_register_value()
Templated method to get a reference to value of given CHERI::RegisterNumber.
Definition
compartment.h:49
ErrorState::registers
void * registers[15]
The register state where the fault occurred.
Definition
compartment.h:38
ErrorState::pcc
void * pcc
The faulting program counter.
Definition
compartment.h:32
Generated by
1.18.0