Struct kernel::utilities::capability_ptr::CapabilityPtr
source · 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.
Because it is register sized, CapabilityPtr
is guaranteed to be
at least the size of a word (usize) 1. Operations on the
pointer may affect permissions, e.g. offsetting the pointer beyond
the bounds of the memory object invalidates it. Like a *const ()
, a CapabilityPtr
may also “hide” information by storing a
word of data with no memory access permissions.
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) -> U
pub fn map_or<U, F>(&self, default: U, f: F) -> 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
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 Default for CapabilityPtr
impl Default for CapabilityPtr
source§impl From<CapabilityPtr> for usize
impl From<CapabilityPtr> for usize
source§fn from(from: CapabilityPtr) -> Self
fn from(from: CapabilityPtr) -> Self
Returns the address of the CapabilityPtr
.
Provenance note: may not expose 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 and no authority
Provenance note: may have null provenance.
source§impl Hash for CapabilityPtr
impl Hash for CapabilityPtr
source§impl LowerHex for CapabilityPtr
impl LowerHex for CapabilityPtr
source§impl Ord for CapabilityPtr
impl Ord for CapabilityPtr
source§fn cmp(&self, other: &CapabilityPtr) -> Ordering
fn cmp(&self, other: &CapabilityPtr) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for CapabilityPtr
impl PartialEq for CapabilityPtr
source§fn eq(&self, other: &CapabilityPtr) -> bool
fn eq(&self, other: &CapabilityPtr) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for CapabilityPtr
impl PartialOrd for CapabilityPtr
source§fn partial_cmp(&self, other: &CapabilityPtr) -> Option<Ordering>
fn partial_cmp(&self, other: &CapabilityPtr) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl UpperHex for CapabilityPtr
impl UpperHex for CapabilityPtr
impl Copy for CapabilityPtr
impl Eq for CapabilityPtr
impl StructuralPartialEq for CapabilityPtr
Auto Trait Implementations§
impl Freeze for CapabilityPtr
impl RefUnwindSafe for CapabilityPtr
impl !Send for CapabilityPtr
impl !Sync for CapabilityPtr
impl Unpin for CapabilityPtr
impl UnwindSafe for CapabilityPtr
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)