pub struct PagedMemory<'a> { /* private fields */ }
Implementations§
Source§impl<'a> PagedMemory<'a>
impl<'a> PagedMemory<'a>
Sourcepub unsafe fn from_raw<S: PageStore + Send + 'static>(
base: *mut u8,
length: usize,
store: S,
page_size: Option<usize>,
) -> Result<PagedMemory<'static>, Error>
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].
Sourcepub fn new<S: PageStore + Send + 'static>(
length: usize,
store: S,
page_size: Option<usize>,
) -> Result<PagedMemory<'static>, Error>
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.
Sourcepub fn as_slice_mut(&mut self) -> &mut [u8] ⓘ
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.
pub fn as_slice(&self) -> &[u8] ⓘ
pub fn as_raw_parts(&self) -> (*mut u8, usize)
Sourcepub fn release_page(&self, page_offset: usize)
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.