CHERIoT RTOS
A compartmentalised RTOS for CHERIoT hardware
Loading...
Searching...
No Matches
cheri.h
Go to the documentation of this file.
1// Copyright CHERIoT Contributors.
2// SPDX-License-Identifier: MIT
3
4/**
5 * \file
6 * \brief C definitions for CHERI specific functionality
7 */
8
9#pragma once
10#include <__cheri_sealed.h>
11#include <compartment-macros.h>
12#include <stddef.h>
13#include <stdint.h>
14
15struct Timeout;
16
17/**
18 * The complete set of architectural permissions.
19 */
21{
22 /**
23 * Capability refers to global memory (this capability may be stored
24 * anywhere).
25 */
27 /**
28 * Global capabilities can be loaded through this capability. Without
29 * this permission, any capability loaded via this capability will
30 * have `Global` and `LoadGlobal` removed.
31 */
33 /**
34 * Capability may be used to store. Any store via a capability without
35 * this permission will trap.
36 */
38 /**
39 * Capabilities with store permission may be loaded through this
40 * capability. Without this, any loaded capability will have
41 * `LoadMutable` and `Store` removed.
42 */
44 /**
45 * This capability may be used to store capabilities that do not have
46 * `Global` permission.
47 */
49 /**
50 * This capability can be used to load.
51 */
53 /**
54 * Any load and store permissions on this capability convey the right to
55 * load or store capabilities in addition to data.
56 */
58 /**
59 * If installed as the program counter capability, running code may
60 * access privileged system registers.
61 */
63 /**
64 * This capability may be used as a jump target and used to execute
65 * instructions.
66 */
68 /**
69 * This capability may be used to unseal other capabilities. The
70 * 'address' range is in the sealing type namespace and not in the
71 * memory namespace.
72 */
74 /**
75 * This capability may be used to seal other capabilities. The
76 * 'address' range is in the sealing type namespace and not in the
77 * memory namespace.
78 */
80 /**
81 * Software defined permission bit, no architectural meaning.
82 */
84};
85
86/**
87 * The codes used in the cause field of the mtval CSR when the processor
88 * takes a CHERI exception.
89 */
91{
92 /**
93 * No exception. This value is passed to the error handler after a
94 * forced unwind in a called compartment.
95 */
97 /**
98 * Attempted to use a capability outside its bounds.
99 */
101 /**
102 * Attempted to use an untagged capability to authorize something.
103 */
105 /**
106 * Attempted to use a sealed capability to authorize something.
107 */
109 /**
110 * Attempted to jump to a capability without `Permission::Execute`.
111 */
113 /**
114 * Attempted to load via a capability without `Permission::Load`.
115 */
117 /**
118 * Attempted to store via a capability without `Permission::Store`.
119 */
121 /**
122 * Attempted to store a tagged capability via a capability without
123 * `Permission::LoadStoreCapability`.
124 */
126 /**
127 * Attempted to store a tagged capability without `Permission::Global`
128 * via capability without `Permission::StoreLocal`.
129 */
131 /**
132 * Attempted to access a restricted CSR or SCR with PCC without
133 * `Permission::AccessSystemRegisters`.
134 */
136 /**
137 * Used to represent a value that has no valid meaning in hardware.
138 */
140};
141
142/**
143 * Register numbers as reported in cap idx field of `mtval` CSR when
144 * a CHERI exception is taken. Values less than 32 refer to general
145 * purpose registers and others to SCRs (of these, only PCC can actually
146 * cause an exception).
147 */
149{
150 /**
151 * The zero register, which always contains the `NULL` capability.
152 */
154 /**
155 * `$c1` / `$cra` used by the ABI as the return address.
156 * Not preserved across calls.
157 */
159 /**
160 * `$c2` / `$csp` used by the ABI as the stack pointer.
161 * Preserved across calls.
162 */
164 /**
165 * `$c3` / `$cgp` used by the ABI as the global pointer.
166 * Not allocatable by the compiler, set by the switcher on compartment
167 * entry.
168 */
170 /**
171 * `$c4` / `$ctp` used by the ABI as the thread pointer.
172 * Currently unused by the compiler.
173 * Not preserved across compartment calls.
174 */
176 /**
177 * `$c5` / `$ct0` used by the ABI as temporary register.
178 * Not preserved across calls.
179 */
181 /**
182 * `$c6` / `$ct1` used by the ABI as temporary register.
183 * Not preserved across calls.
184 */
186 /**
187 * `$c7` / `$ct2` used by the ABI as temporary register.
188 * Not preserved across calls.
189 */
191 /**
192 * `$c8` / `$cs0` used by the ABI as a callee-saved register.
193 * Preserved across calls.
194 */
196 /**
197 * `$c9` / `$cs1` used by the ABI as a callee-saved register.
198 * Preserved across calls.
199 */
201 /**
202 * `$c10` / `$ca0` used by the ABI as an argument register.
203 * Not preserved across calls.
204 */
206 /**
207 * `$c11` / `$ca1` used by the ABI as an argument register.
208 * Not preserved across calls.
209 */
211 /**
212 * `$c12` / `$ca2` used by the ABI as an argument register.
213 * Not preserved across calls.
214 */
216 /**
217 * `$c13` / `$ca3` used by the ABI as an argument register.
218 * Not preserved across calls.
219 */
221 /**
222 * `$c14` / `$ca4` used by the ABI as an argument register.
223 * Not preserved across calls.
224 */
226 /**
227 * `$c15` / `$ca5` used by the ABI as an argument register.
228 * Not preserved across calls.
229 */
231 /**
232 * The Program Counter Capability.
233 *
234 * Special capability register used to authorize instruction fetch. The
235 * address is that of the faulting instruction. Also used for accessing
236 * read-only globals.
237 */
239 /**
240 * Machine-mode Trap Code Capability.
241 *
242 * Special capability register that
243 * is installed in PCC when the CPU takes a trap. The address has the
244 * same semantics as the RISC-V `mtvec` CSR. Only accessible when PCC
245 * has the AccessSystemRegisters permission.
246 */
248 /**
249 * Machine-mode Tusted Data Capability.
250 *
251 * Special capability register that contains the memory root capability
252 * on boot. Only accessible when PCC has the AccessSystemRegisters
253 * permission. Use by the RTOS to store a capability to the trusted
254 * stack.
255 */
257 /**
258 * Machine-mode Scratch Capability. Special capabiltiy register that
259 * contains the sealing root capability on boot. Only accessible when
260 * PCC has the AccessSystemRegisters permission.
261 */
263 /**
264 * Machine-mode Exception Program Counter Capability. Special capability
265 * register that contains the PCC of the faulting instruction on trap.
266 * The address has the same semantics as the RISC-V `mepc` CSR. Only
267 * accessible when PCC has the AccessSystemRegisters permission.
268 */
270 /**
271 * Indicates a value that is not used by the hardware to refer to a
272 * register.
273 */
275};
276
277/**
278 * Sealing types.
279 */
281{
282 /**
283 * 0 represents unsealed.
284 */
286
287 /**
288 * Sentry that inherits interrupt status.
289 */
291
292 /**
293 * Sentry that disables interrupts on calls.
294 */
296
297 /**
298 * Sentry that enables interrupts on calls.
299 */
301
302 /**
303 * Return sentry that disables interrupts on return
304 */
306
307 /**
308 * Return sentry that enables interrupts on return
309 */
311
312 /**
313 * Marker for the first sealing type that's valid for data capabilities.
314 */
316
317 /**
318 * The sealing type used for sealed export table entries.
319 *
320 * This is RTOS- and not CHERIoT-specific.
321 */
323
324 /**
325 * The compartment switcher has a sealing type for the trusted stack.
326 *
327 * This must be the second data sealing type so that we can also permit
328 * the switcher to unseal sentries and export table entries.
329 *
330 * This is RTOS- and not CHERIoT-specific.
331 */
333
334 /**
335 * The allocator has a sealing type for the software sealing mechanism
336 * with dynamically allocated objects.
337 *
338 * This is RTOS- and not CHERIoT-specific.
339 */
341
342 /**
343 * The loader reserves a sealing type for the software sealing
344 * mechanism. The permit-unseal capability for this is destroyed after
345 * the loader has run, which guarantees that anything sealed with this
346 * type was present in the original firmware image. The token library
347 * has the only permit-unseal capability for this type.
348 *
349 * This is RTOS- and not CHERIoT-specific.
350 */
352
353 /**
354 * The first sealing key that is reserved for use by the allocator's
355 * software sealing mechanism and used for static sealing types,
356 *
357 * Architecturally, this is the smallest non-interpreted sealing type.
358 */
360
361 /**
362 * The first sealing key in the space that the allocator will
363 * dynamically allocate for sealing types.
364 *
365 * This is RTOS- and not CHERIoT-specific.
366 */
368};
369
370/**
371 * Checks that `ptr` is valid, unsealed, has at least `rawPermissions`, and has
372 * at least `space` bytes after the current offset.
373 *
374 * If the permissions do not include Global and `checkStackNeeded` is `false`,
375 * then this will also check that the capability does not point to the current
376 * thread's stack.
377 *
378 * To reduce code size, this function is provided as part of the compartment
379 * helper library.
380 */
381bool __cheri_libcall check_pointer(const volatile void *ptr,
382 size_t space,
383 uint32_t rawPermissions,
384 bool checkStackNeeded);
CHERISealingType
Sealing types.
Definition cheri.h:281
@ CheriSealTypeReturnSentryDisabling
Return sentry that disables interrupts on return.
Definition cheri.h:305
@ CheriSealTypeSealedImportTableEntries
The sealing type used for sealed export table entries.
Definition cheri.h:322
@ CheriSealTypeReturnSentryEnabling
Return sentry that enables interrupts on return.
Definition cheri.h:310
@ CheriSealTypeSealedTrustedStacks
The compartment switcher has a sealing type for the trusted stack.
Definition cheri.h:332
@ CheriSealTypeSentryEnabling
Sentry that enables interrupts on calls.
Definition cheri.h:300
@ CheriSealTypeStaticToken
The loader reserves a sealing type for the software sealing mechanism.
Definition cheri.h:351
@ CheriSealTypeSentryInheriting
Sentry that inherits interrupt status.
Definition cheri.h:290
@ CheriSealTypeFirstDataSealingType
Marker for the first sealing type that's valid for data capabilities.
Definition cheri.h:315
@ CheriSealTypeFirstDynamicSoftware
The first sealing key in the space that the allocator will dynamically allocate for sealing types.
Definition cheri.h:367
@ CheriSealTypeAllocator
The allocator has a sealing type for the software sealing mechanism with dynamically allocated object...
Definition cheri.h:340
@ CheriSealTypeFirstStaticSoftware
The first sealing key that is reserved for use by the allocator's software sealing mechanism and used...
Definition cheri.h:359
@ CheriSealTypeSentryDisabling
Sentry that disables interrupts on calls.
Definition cheri.h:295
@ CheriSealTypeUnsealed
0 represents unsealed.
Definition cheri.h:285
CHERIPermission
The complete set of architectural permissions.
Definition cheri.h:21
@ CheriPermissionStore
Capability may be used to store.
Definition cheri.h:37
@ CheriPermissionGlobal
Capability refers to global memory (this capability may be stored anywhere).
Definition cheri.h:26
@ CheriPermissionStoreLocal
This capability may be used to store capabilities that do not have Global permission.
Definition cheri.h:48
@ CheriPermissionLoadStoreCapability
Any load and store permissions on this capability convey the right to load or store capabilities in a...
Definition cheri.h:57
@ CheriPermissionUnseal
This capability may be used to unseal other capabilities.
Definition cheri.h:73
@ CheriPermissionUser0
Software defined permission bit, no architectural meaning.
Definition cheri.h:83
@ CheriPermissionLoadGlobal
Global capabilities can be loaded through this capability.
Definition cheri.h:32
@ CheriPermissionExecute
This capability may be used as a jump target and used to execute instructions.
Definition cheri.h:67
@ CheriPermissionAccessSystemRegisters
If installed as the program counter capability, running code may access privileged system registers.
Definition cheri.h:62
@ CheriPermissionSeal
This capability may be used to seal other capabilities.
Definition cheri.h:79
@ CheriPermissionLoad
This capability can be used to load.
Definition cheri.h:52
@ CheriPermissionLoadMutable
Capabilities with store permission may be loaded through this capability.
Definition cheri.h:43
CHERIRegisterNumber
Register numbers as reported in cap idx field of mtval CSR when a CHERI exception is taken.
Definition cheri.h:149
@ CheriRegisterNumberMepcc
Machine-mode Exception Program Counter Capability.
Definition cheri.h:269
@ CheriRegisterNumberCgp
$c3 / $cgp used by the ABI as the global pointer.
Definition cheri.h:169
@ CheriRegisterNumberCsp
$c2 / $csp used by the ABI as the stack pointer.
Definition cheri.h:163
@ CheriRegisterNumberCT0
$c5 / $ct0 used by the ABI as temporary register.
Definition cheri.h:180
@ CheriRegisterNumberCS0
$c8 / $cs0 used by the ABI as a callee-saved register.
Definition cheri.h:195
@ CheriRegisterNumberCA2
$c12 / $ca2 used by the ABI as an argument register.
Definition cheri.h:215
@ CheriRegisterNumberCT2
$c7 / $ct2 used by the ABI as temporary register.
Definition cheri.h:190
@ CheriRegisterNumberCT1
$c6 / $ct1 used by the ABI as temporary register.
Definition cheri.h:185
@ CheriRegisterNumberCA1
$c11 / $ca1 used by the ABI as an argument register.
Definition cheri.h:210
@ CheriRegisterNumberCA4
$c14 / $ca4 used by the ABI as an argument register.
Definition cheri.h:225
@ CheriRegisterNumberInvalid
Indicates a value that is not used by the hardware to refer to a register.
Definition cheri.h:274
@ CheriRegisterNumberCA3
$c13 / $ca3 used by the ABI as an argument register.
Definition cheri.h:220
@ CheriRegisterNumberMScratchC
Machine-mode Scratch Capability.
Definition cheri.h:262
@ CheriRegisterNumberCtp
$c4 / $ctp used by the ABI as the thread pointer.
Definition cheri.h:175
@ CheriRegisterNumberMtdc
Machine-mode Tusted Data Capability.
Definition cheri.h:256
@ CheriRegisterNumberCS1
$c9 / $cs1 used by the ABI as a callee-saved register.
Definition cheri.h:200
@ CheriRegisterNumberCra
$c1 / $cra used by the ABI as the return address.
Definition cheri.h:158
@ CheriRegisterNumberCA5
$c15 / $ca5 used by the ABI as an argument register.
Definition cheri.h:230
@ CheriRegisterNumberCA0
$c10 / $ca0 used by the ABI as an argument register.
Definition cheri.h:205
@ CheriRegisterNumberCzr
The zero register, which always contains the NULL capability.
Definition cheri.h:153
@ CheriRegisterNumberPcc
The Program Counter Capability.
Definition cheri.h:238
@ CheriRegisterNumberMtcc
Machine-mode Trap Code Capability.
Definition cheri.h:247
bool __cheri_libcall check_pointer(const volatile void *ptr, size_t space, uint32_t rawPermissions, bool checkStackNeeded)
Checks that ptr is valid, unsealed, has at least rawPermissions, and has at least space bytes after t...
CHERICauseCode
The codes used in the cause field of the mtval CSR when the processor takes a CHERI exception.
Definition cheri.h:91
@ CheriCauseCodePermitStoreCapabilityViolation
Attempted to store a tagged capability via a capability without Permission::LoadStoreCapability.
Definition cheri.h:125
@ CheriCauseCodePermitStoreLocalCapabilityViolation
Attempted to store a tagged capability without Permission::Global via capability without Permission::...
Definition cheri.h:130
@ CheriCauseCodePermitExecuteViolation
Attempted to jump to a capability without Permission::Execute.
Definition cheri.h:112
@ CheriCauseCodePermitAccessSystemRegistersViolation
Attempted to access a restricted CSR or SCR with PCC without Permission::AccessSystemRegisters.
Definition cheri.h:135
@ CheriCauseCodeBoundsViolation
Attempted to use a capability outside its bounds.
Definition cheri.h:100
@ CheriCauseCodePermitLoadViolation
Attempted to load via a capability without Permission::Load.
Definition cheri.h:116
@ CheriCauseCodeSealViolation
Attempted to use a sealed capability to authorize something.
Definition cheri.h:108
@ CheriCauseCodeNone
No exception.
Definition cheri.h:96
@ CheriCauseCodeInvalid
Used to represent a value that has no valid meaning in hardware.
Definition cheri.h:139
@ CheriCauseCodeTagViolation
Attempted to use an untagged capability to authorize something.
Definition cheri.h:104
@ CheriCauseCodePermitStoreViolation
Attempted to store via a capability without Permission::Store.
Definition cheri.h:120
Macros for interacting with the compartmentalisation model in CHERIoT.
Structure representing a timeout.
Definition timeout.h:47