|
CHERIoT RTOS
A compartmentalised RTOS for CHERIoT hardware
|
Helper for a value that encodes either a pointer or an error value in a pointer-sized value, discriminated by the tag bit. More...
#include <cheri.hh>
Public Member Functions | |
| ErrorOr (T *pointer) | |
| Construct from a pointer. | |
| ErrorOr (Capability< T, IsSealed > pointer) | |
| Construct from a CHERI::Capability. | |
| ErrorOr (int error) | |
| Initialise the value with an error value. | |
| bool | is_error () |
| Returns true if this holds an error value, false otherwise. | |
| auto | either (auto &&onT, auto &&onE) |
| Generic eliminator for ErrorOr<T> values. | |
| int | as_error () |
| If this holds an error value, return it, otherwise return 0. | |
| T * | as_pointer () |
| If this holds a pointer, return it, otherwise return nullptr. | |
| T * | as_raw () |
| Returns the underlying pointer, which may be an untagged capability with integer error value. | |
| auto | as_raw_capability () |
| Returns the underlying pointer, which may be an untagged capability with integer error value, in its CHERI::Capability<> wrapper, which includes the IsSealed flag. | |
| auto | and_then (auto &&function) |
| Monadic helper modelled on std::optional. | |
| auto | and_then (auto &&function) |
| int | and_then (auto &&function) |
| Variant on and_then that returns an int: either the value returned by the callback, or the error value held by *this. | |
| auto | or_else (auto &&function) |
| Monadic helper modelled on std::optional. | |
| auto | or_else (auto &&function) |
Helper for a value that encodes either a pointer or an error value in a pointer-sized value, discriminated by the tag bit.
This is a non-owning pointer type.
|
inline |
|
inline |
Construct from a CHERI::Capability.
This may be a C API that uses the convention of holding a pointer or an error value. You may call this constructor with an invalid pointer.
|
inline |
|
inline |
Variant on and_then that returns an int: either the value returned by the callback, or the error value held by *this.
This is useful for propagating error values in functions that return an int (e.g. where negative values indicate errors and zero or positive values indicate success).
Definition at line 1775 of file cheri.hh.
References either().
|
inline |
|
inline |
Monadic helper modelled on std::optional.
Takes a reference to a callable object that accepts a T* or something that can be implicitly cast to a T*. The return value for the argument should be either void (in which case and_then returns *this) or an ErrorOr<U>
The callback is invoked if and only if this holds a valid pointer.
Definition at line 1740 of file cheri.hh.
References either().
|
inline |
|
inline |
|
inline |
Returns the underlying pointer, which may be an untagged capability with integer error value.
For type safety, prefer as_pointer or as_error.
|
inlinenodiscard |
Returns the underlying pointer, which may be an untagged capability with integer error value, in its CHERI::Capability<> wrapper, which includes the IsSealed flag.
For type safety, prefer as_pointer or as_error.
|
inline |
Generic eliminator for ErrorOr<T> values.
Read x.either(t, e) as "either calls t with x's value or e with x's error". That is, either takes two callbacks, the first of which is called with non-error T * values, and the second of which is called with int error values. The return type of the latter (the error handler) must be convertable to the return type of the former (the T * handler).
Definition at line 1645 of file cheri.hh.
References is_error().
Referenced by and_then(), as_error(), and or_else().
|
inline |
|
inline |
|
inline |
Monadic helper modelled on std::optional.
Takes a reference to a callable object that accepts an int. The return value for the argument should be either void (in which case or_else returns *this) or something that can implicitly cast to an ErrorOr<T>.
The callback is invoked if and only if this holds an error value.
Definition at line 1792 of file cheri.hh.
References either().