pub struct CapabilityPtr { /* private fields */ }
Expand description
A pointer to userspace memory with implied authority.
A CapabilityPtr
points to memory a userspace process may be permitted to
read, write, or execute. It is sized exactly to a CPU register that can pass
values between userspace and the kernel 1. Operations on the pointer
may affect permissions, e.g. offsetting the pointer beyond the bounds of the
memory object may invalidate it.
CapabilityPtr
should be used to store or pass a value between the
kernel and userspace that may represent a valid userspace reference,
when one party intends the other to access it.
Depending on the architecture, the size of a
CapabilityPtr
may be a word size or larger, e.g., if registers can store metadata such as access permissions. ↩
Implementations§
Source§impl CapabilityPtr
impl CapabilityPtr
Sourcepub fn as_ptr<T>(&self) -> *const T
pub fn as_ptr<T>(&self) -> *const T
Returns the pointer component of a CapabilityPtr
but without any of the authority.
Construct a CapabilityPtr
from a raw pointer, with authority ranging over
[base
, base + length
) and permissions perms
.
Provenance note: may derive from a pointer other than the input to provide something with valid provenance to justify the other arguments.
§Safety
Constructing a CapabilityPtr
with metadata may convey authority to
dereference this pointer, such as in userspace. When these pointers
serve as the only memory isolation primitive in the system, this method
can thus break Tock’s isolation model. As semi-trusted kernel code can
name this type and method, it is thus marked as unsafe
.
Sourcepub fn map_or<U, F>(&self, default: U, f: F) -> Uwhere
F: FnOnce(&Self) -> U,
pub fn map_or<U, F>(&self, default: U, f: F) -> Uwhere
F: FnOnce(&Self) -> U,
If the CapabilityPtr
is null returns default
, otherwise applies f
to self
.
Sourcepub fn map_or_else<U, D, F>(&self, default: D, f: F) -> U
pub fn map_or_else<U, D, F>(&self, default: D, f: F) -> U
If the CapabilityPtr
is null returns default
, otherwise applies f
to self
.
default is only evaluated if self
is not null.
Trait Implementations§
Source§impl AddAssign<usize> for CapabilityPtr
impl AddAssign<usize> for CapabilityPtr
Source§fn add_assign(&mut self, rhs: usize)
fn add_assign(&mut self, rhs: usize)
Increments the address of a CapabilityPtr
. If the pointer is offset
past its bounds, its authority may be invalidated.
Source§impl Clone for CapabilityPtr
impl Clone for CapabilityPtr
Source§fn clone(&self) -> CapabilityPtr
fn clone(&self) -> CapabilityPtr
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for CapabilityPtr
impl Debug for CapabilityPtr
Source§impl From<CapabilityPtr> for MachineRegister
impl From<CapabilityPtr> for MachineRegister
Source§fn from(from: CapabilityPtr) -> Self
fn from(from: CapabilityPtr) -> Self
Creates a MachineRegister
containing this CapabilityPtr
,
including its provenance.
Source§impl From<usize> for CapabilityPtr
impl From<usize> for CapabilityPtr
Source§fn from(from: usize) -> Self
fn from(from: usize) -> Self
Constructs a CapabilityPtr
with a given address but no authority or
provenance.