Skip to main content

MappedPages

Struct MappedPages 

Source
pub struct MappedPages {
    start_vaddr: VirtAddr,
    size: usize,
    owned: bool,
    _marker: PhantomData<*mut ()>,
}
Expand description

A safely mapped memory region

MappedPages represents a contiguous virtual memory mapping to physical frames. The mapping is automatically unmapped when the MappedPages is dropped.

This is inspired by Theseus’s MappedPages abstraction.

Fields§

§start_vaddr: VirtAddr

Starting virtual address

§size: usize

Size in bytes

§owned: bool

Whether this mapping owns the underlying frames

§_marker: PhantomData<*mut ()>

Marker to prevent Send/Sync (mapping is CPU-local)

Implementations§

Source§

impl MappedPages

Source

pub unsafe fn new(start_vaddr: VirtAddr, size: usize, owned: bool) -> Self

Creates a new MappedPages from an existing mapping

§Safety
  • The virtual address range must be a valid mapping
  • The caller must ensure the mapping remains valid for the lifetime
  • The size must match the actual mapping size
Source

pub fn start_address(&self) -> VirtAddr

Returns the starting virtual address

Source

pub fn size(&self) -> usize

Returns the size in bytes

Source

pub fn end_address(&self) -> VirtAddr

Returns the ending virtual address (exclusive)

Source

pub fn range(&self) -> Range<VirtAddr>

Returns the virtual address range

Source

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

Returns a pointer to the start of the mapping

Source

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

Returns a mutable pointer to the start of the mapping

Source

pub unsafe fn read<T>(&self, offset: usize) -> Result<T, MapError>

Reads a value from the mapped memory at the given offset

§Safety
  • The offset + size_of::() must be within the mapping
  • The memory must be properly initialized for type T
  • Proper alignment must be ensured
Source

pub unsafe fn write<T>( &mut self, offset: usize, value: T, ) -> Result<(), MapError>

Writes a value to the mapped memory at the given offset

§Safety
  • The offset + size_of::() must be within the mapping
  • The memory must be writable (not read-only)
  • Proper alignment must be ensured
Source

pub unsafe fn as_slice(&self, len: usize) -> Result<&[u8], MapError>

Returns a slice reference to the mapped memory

§Safety
  • The mapping must contain initialized data
  • No other mutable references to this memory can exist
Source

pub unsafe fn as_mut_slice(&mut self, len: usize) -> Result<&mut [u8], MapError>

Returns a mutable slice reference to the mapped memory

§Safety
  • The mapping must be writable
  • No other references to this memory can exist
Source

pub fn into_allocated_pages(self) -> Result<AllocatedPages, MapError>

Converts this MappedPages into an AllocatedPages, consuming the mapping

This transfers ownership of the underlying frames.

Trait Implementations§

Source§

impl Debug for MappedPages

Source§

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

Performs the fmt operation.

Source§

impl Drop for MappedPages

Source§

fn drop(&mut self)

Performs the drop operation.

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 MappedPages

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.