Skip to main content

VirtualRange

Struct VirtualRange 

Source
pub struct VirtualRange { /* private fields */ }
Expand description

A reserved range of virtual addresses with nothing behind it yet.

Reserving costs address space, not memory. Blocks are mapped in afterwards with VirtualRange::map, and the range is readable only where something has been mapped — touching an unmapped offset faults rather than reading zeroes, which is deliberate: a silent zero would look like KV that was written but empty.

Implementations§

Source§

impl VirtualRange

Source

pub fn reserve(len: usize) -> Result<Self, VirtualMemoryError>

Reserve len bytes of address space.

len must be a multiple of granularity.

Source

pub fn len(&self) -> usize

Bytes of address space reserved.

Source

pub fn is_empty(&self) -> bool

Whether the reservation covers no bytes.

Always false: a zero-length reservation is refused at construction.

Source

pub fn mapped_bytes(&self) -> usize

Bytes currently backed by a mapped block.

Source

pub fn as_ptr(&self) -> *const u8

The base address. Only offsets that have been mapped may be read.

Source

pub fn as_mut_ptr(&mut self) -> *mut u8

The base address, mutable.

Source

pub fn map( &mut self, offset: usize, len: usize, ) -> Result<(), VirtualMemoryError>

Back offset..offset + len with freshly committed memory.

Both offset and len must be multiples of granularity.

Source

pub fn unmap(&mut self, offset: usize) -> Result<(), VirtualMemoryError>

Release the block backing offset, leaving the address space reserved.

The offset must be one previously passed to Self::map; releasing a sub-range would strand the remainder of the block.

Source

pub unsafe fn slice_unchecked(&self, offset: usize, len: usize) -> &[u8]

A read-only view of a mapped span.

§Safety

The caller must ensure offset..offset + len is entirely mapped. Reading unmapped address space faults.

Source

pub unsafe fn slice_unchecked_mut( &mut self, offset: usize, len: usize, ) -> &mut [u8]

A mutable view of a mapped span.

§Safety

The caller must ensure offset..offset + len is entirely mapped.

Trait Implementations§

Source§

impl Debug for VirtualRange

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for VirtualRange

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for VirtualRange

Source§

impl Sync for VirtualRange

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> BindingResource for T
where T: Send + Sync + Debug,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.