pub struct MappedPages { /* private fields */ }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.
Implementations§
Source§impl MappedPages
impl MappedPages
Sourcepub unsafe fn new(start_vaddr: VirtAddr, size: usize, owned: bool) -> Self
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
Sourcepub fn start_address(&self) -> VirtAddr
pub fn start_address(&self) -> VirtAddr
Returns the starting virtual address
Sourcepub fn end_address(&self) -> VirtAddr
pub fn end_address(&self) -> VirtAddr
Returns the ending virtual address (exclusive)
Sourcepub fn as_mut_ptr(&mut self) -> *mut u8
pub fn as_mut_ptr(&mut self) -> *mut u8
Returns a mutable pointer to the start of the mapping
Sourcepub unsafe fn read<T>(&self, offset: usize) -> Result<T, MapError>
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
Sourcepub unsafe fn write<T>(
&mut self,
offset: usize,
value: T,
) -> Result<(), MapError>
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
Sourcepub unsafe fn as_slice(&self, len: usize) -> Result<&[u8], MapError>
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
Sourcepub unsafe fn as_mut_slice(&mut self, len: usize) -> Result<&mut [u8], MapError>
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
Sourcepub fn into_allocated_pages(self) -> Result<AllocatedPages, MapError>
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
impl Debug for MappedPages
impl Send for MappedPages
Auto Trait Implementations§
impl Freeze for MappedPages
impl RefUnwindSafe for MappedPages
impl !Sync for MappedPages
impl Unpin for MappedPages
impl UnsafeUnpin for MappedPages
impl UnwindSafe for MappedPages
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
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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