Struct PagedMemory

Source
pub struct PagedMemory<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> PagedMemory<'a>

Source

pub unsafe fn from_raw<S: PageStore + Send + 'static>( base: *mut u8, length: usize, store: S, page_size: Option<usize>, ) -> Result<PagedMemory<'static>, Error>

Make the memory paged in userspace with raw base pointer and length. Note that the range of addresses should be valid throughout the lifetime of PagedMemory and no access should be made to the memory unless it is wrapped in [PagedMemory::run].

Source

pub fn new<S: PageStore + Send + 'static>( length: usize, store: S, page_size: Option<usize>, ) -> Result<PagedMemory<'static>, Error>

Create a slice of memory that is pagged.

Source

pub fn as_slice_mut(&mut self) -> &mut [u8]

Because an access to the memory could wait upon the PageStore to load the page in case of a page fault, to avoid dead-lock, make sure the resources the store will acquire will not be held by this code before accessing the paged memory. For example, using println!("{}", mem.as_slice()[0]) could dead-lock the system if the read() implementation of PageStore also uses println: the I/O is first locked before the dereference of mem[0] which could possibly induces a page fault that invokes read() to bring in the page content, then when the page store tries to invoke println, it gets stuck (the dereference is imcomplete). As a good practice, always make sure PageStore grabs the least resources that do not overlap with the code here.

Source

pub fn as_slice(&self) -> &[u8]

Source

pub fn as_raw_parts(&self) -> (*mut u8, usize)

Source

pub fn page_size(&self) -> usize

Return the configured page size.

Source

pub fn release_page(&self, page_offset: usize)

Release the page content loaded from PageStore. The next access to an address within this page will trigger a page fault. page_offset must be one of the offset passed in by page fault handler.

Source

pub fn release_all_pages(&self)

Trait Implementations§

Source§

impl<'a> Drop for PagedMemory<'a>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for PagedMemory<'a>

§

impl<'a> RefUnwindSafe for PagedMemory<'a>

§

impl<'a> Send for PagedMemory<'a>

§

impl<'a> Sync for PagedMemory<'a>

§

impl<'a> Unpin for PagedMemory<'a>

§

impl<'a> UnwindSafe for PagedMemory<'a>

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.