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
CapabilityPtrmay 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.
CapabilityPtrs can be the sole memory isolation primitive in the
system, thus great care must be taken with this method, as errors can
break Tock’s isolation model.
Provenance note: may derive from a pointer other than the input to provide something with valid provenance to justify the other arguments.
§Safety
NOTE: Hardware capability support is experimental in Tock. The intent of this type is to capture semantics general to any hardware capability implementation, however, there is no upstream support for any such hardware today. As such, the exact safety conditions may change in the future.
Callers are responsible for ensuring that the authority conveyed by this pointer does not violate Tock’s isolation model, under an assumption that hardware capabilities are the sole memory isolation mechanism.
Authority is conveyed solely by the base, length, and perms.
The value in ptr may be freely changed by untrusted code. When
executing on a platform with hardware capability enforcement, callers
may assume that on any attempt to use ptr, hardware will verify that:
ptris within the bounds [base,base + length).- The access type is allowed by
perms.
Callers are responsible for restricting access to this pointer, i.e., ensuring that a pointer which allows access to process memory is only given to the correct process.
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 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for CapabilityPtr
Source§impl Debug for CapabilityPtr
impl Debug for CapabilityPtr
impl Eq 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.