Skip to main content

WritableCapability

Struct WritableCapability 

Source
pub struct WritableCapability<T> { /* private fields */ }
Expand description

Read+Write bounds-checked capability. NOT Copy/Clone so the borrow checker prevents aliasing the unique-writer status.

Constructed from &mut [T] or an owned Box<T> (via OwnedWritableCapability::from_box). The &mut borrow IS the unique-writer guarantee; without it, multiple WritableCapability instances could simultaneously write the same region.

Implementations§

Source§

impl<T> WritableCapability<T>

Source

pub const SIGNATURE: AxisMask

Direction signature of WritableCapability<T>. Engages the K_bounds axis (runtime base / length / permissions stored at slot for CHERI-style bounds enforcement on every deref).

Source

pub unsafe fn new( ptr: *mut T, base: usize, length: u32, perms: u32, ) -> Result<Self, CapabilityError>

§Safety

Caller guarantees [base, base + length) is valid memory and no other writer accesses the region while this capability is alive.

Source

pub fn from_slice_mut(slice: &mut [T]) -> (WritableCapability<T>, &mut [T])

Safe constructor: build a writable capability over a mutable slice borrow. Grants Read + Write permissions.

Source

pub fn has_permission(&self, p: CapabilityPermission) -> bool

Source

pub fn is_sealed(&self) -> bool

Source

pub fn sealed(self) -> Self

Source

pub fn unsealed(self) -> Self

Source

pub fn read(&self) -> Result<T, CapabilityError>
where T: Copy,

Read through the capability.

Source

pub fn write(&mut self, value: T) -> Result<(), CapabilityError>

Write through the capability. The &mut self receiver + the constructor’s &mut [T] / Box-consuming nature provide the unique-writer guarantee.

Source

pub fn narrow( &self, sub_base: usize, sub_length: u32, sub_perms: u32, ) -> Result<Self, CapabilityError>

Narrow to a sub-range, returning a new WritableCapability. To narrow to a read-only view, use narrow_readable.

Source

pub fn narrow_readable( &self, sub_base: usize, sub_length: u32, sub_perms: u32, ) -> Result<ReadableCapability<T>, CapabilityError>

Narrow to a read-only view. Returned ReadableCapability does NOT have Write perm regardless of what sub_perms contains.

Source

pub fn as_readable(&self) -> ReadableCapability<T>

Borrow this WritableCapability as a ReadableCapability view (no Write perm, no transfer of ownership). The borrow checker prevents the writable cap from being used while the readable view is alive.

Trait Implementations§

Source§

impl<T: Debug> Debug for WritableCapability<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.