CHERIoT RTOS
A compartmentalised RTOS for CHERIoT hardware
Loading...
Searching...
No Matches
switcher.h
Go to the documentation of this file.
1#pragma once
2#include <cdefs.h>
3#include <stddef.h>
4#include <stdint.h>
5
6/**
7 * \file
8 *
9 * APIs for interacting with the switcher.
10 */
11
12/**
13 * Returns true if the trusted stack contains at least `requiredFrames` frames
14 * past the current one, false otherwise.
15 *
16 * Note: This is faster than calling either `trusted_stack_index` or
17 * `trusted_stack_size` and so should be preferred in guards.
18 */
19__cheri_libcall _Bool trusted_stack_has_space(int requiredFrames);
20
21/**
22 * Recover the stack value that was passed into a compartment on
23 * cross-compartment call. This allows sub-compartment compartmentalization
24 * (e.g. running another OS in a compartment) where the monitor in the
25 * compartment uses heap-allocated stacks for the nested compartments, while
26 * providing a mechanism for the monitor to recover the stack.
27 */
28__cheri_libcall void *switcher_recover_stack(void);
29
30/**
31 * Returns a store-only capability to two hazard pointer slots for the current
32 * thread. Objects stored here will not be deallocated until (at least) the
33 * next cross-compartment call or until they are explicitly overwritten.
34 */
35__cheri_libcall void **switcher_thread_hazard_slots(void);
36
37/**
38 * Returns the lowest address that has been stored to on the stack in this
39 * compartment invocation.
40 */
41__cheri_libcall ptraddr_t stack_lowest_used_address(void);
42
43/**
44 * Resets the switcher's count of invocations.
45 *
46 * Switcher place a limit on the number of times a compartment invocation may
47 * fault (default 512). This prevents a compartment from getting stuck
48 * partially recovering from errors. This function resets the count to zero.
49 * It should be called from outer compartments' run loops and from places where
50 * the caller is certain that error handling is making forward progress.
51 *
52 * Note: If this is called from an error handler that subsequently returns with
53 * with install-context, the switcher will subtract one from this and set the
54 * switcher error count to -1. Because this is odd, the switcher will detect
55 * the next invocation of the error handler as a double fault and will force
56 * unwind. Do not call this if you are currently in an error handler unless
57 * you are jumping out via some mechanism that does *not* involve returning to
58 * the switcher.
59 *
60 * Returns the previous value of the invocation count. The low bit is set if
61 * an error handler is currently running, the remaining bits are the count.
62 */
63__cheri_libcall uint16_t switcher_handler_invocation_count_reset(void);
__cheri_libcall _Bool trusted_stack_has_space(int requiredFrames)
Returns true if the trusted stack contains at least requiredFrames frames past the current one,...
__cheri_libcall void ** switcher_thread_hazard_slots(void)
Returns a store-only capability to two hazard pointer slots for the current thread.
__cheri_libcall uint16_t switcher_handler_invocation_count_reset(void)
Resets the switcher's count of invocations.
__cheri_libcall ptraddr_t stack_lowest_used_address(void)
Returns the lowest address that has been stored to on the stack in this compartment invocation.
__cheri_libcall void * switcher_recover_stack(void)
Recover the stack value that was passed into a compartment on cross-compartment call.