pub struct PagedRange<'a> { /* private fields */ }Expand description
A single logically-contiguous byte range spread across guest pages.
PagedRange is defined by a GPN (guest page number) slice, a byte
offset into that slice’s implied flat address space, and a length.
§Interior-page constraint
The first page may start at an arbitrary byte offset and the last page may end before the page boundary, but all interior pages are fully covered. There is no way to skip bytes within an interior page.
VALID: ░░████ ██████ ██████ ███░░░
INVALID: ░░████ ░░████ ██████ ███░░░
▲ interior page cannot start at non-zero offsetThis means two guest memory regions starting at arbitrary GPAs cannot
always be represented by a single PagedRange. Use PagedRanges
when you need to concatenate multiple independent regions.
§Construction
Use PagedRange::new(offset, len, gpns) where
offset is the byte offset into the page list and len is the total
byte length. The GPN slice must be large enough to cover
offset + len bytes.
Implementations§
Source§impl<'a> PagedRange<'a>
impl<'a> PagedRange<'a>
Sourcepub const fn new(offset: usize, len: usize, gpns: &'a [u64]) -> Option<Self>
pub const fn new(offset: usize, len: usize, gpns: &'a [u64]) -> Option<Self>
Creates a new range over gpns, starting at offset bytes into the page list, extending for len bytes.
Returns None if offset or len are out of bounds.
Sourcepub fn try_subrange(&self, offset: usize, len: usize) -> Option<Self>
pub fn try_subrange(&self, offset: usize, len: usize) -> Option<Self>
Returns a subrange of this range, or None if the subrange is outside this range.
Sourcepub fn subrange(&self, offset: usize, len: usize) -> Self
pub fn subrange(&self, offset: usize, len: usize) -> Self
Returns a subrange of this range.
Panics if the subrange is outside this range.
Sourcepub fn offset(&self) -> usize
pub fn offset(&self) -> usize
Returns the byte offset into the first page of the range.
Only the first page can have a non-zero offset; all subsequent pages covered by the range are implicitly page-aligned.
Sourcepub fn skip(&mut self, len: usize)
pub fn skip(&mut self, len: usize)
Skips the first len bytes of the range.
Panics if len is larger than the range’s length.
Sourcepub fn truncate(&mut self, len: usize)
pub fn truncate(&mut self, len: usize)
Truncates the range to len bytes.
Panics if len is larger than the range’s length.
Sourcepub fn split(self, offset: usize) -> (Self, Self)
pub fn split(self, offset: usize) -> (Self, Self)
Splits the range at offset.
Panics if offset is outside the range.
Sourcepub fn try_split(self, offset: usize) -> Option<(Self, Self)>
pub fn try_split(self, offset: usize) -> Option<(Self, Self)>
Splits the range at offset, returning None if offset is outside
the range.
Sourcepub fn pop_front_range(&mut self) -> Option<Result<AddressRange, InvalidGpn>>
pub fn pop_front_range(&mut self) -> Option<Result<AddressRange, InvalidGpn>>
Removes and returns the first contiguous range.
Sourcepub fn reader(self, mem: &'a GuestMemory) -> PagedRangeReader<'a>
pub fn reader(self, mem: &'a GuestMemory) -> PagedRangeReader<'a>
Returns a MemoryRead implementation.
Sourcepub fn writer(self, mem: &'a GuestMemory) -> PagedRangeWriter<'a>
pub fn writer(self, mem: &'a GuestMemory) -> PagedRangeWriter<'a>
Returns a MemoryWrite implementation.
Sourcepub fn ranges(self) -> PagedRangeRangeIter<'a> ⓘ
pub fn ranges(self) -> PagedRangeRangeIter<'a> ⓘ
Returns an iterator over the AddressRanges represented by this
range.
Trait Implementations§
Source§impl<'a> Clone for PagedRange<'a>
impl<'a> Clone for PagedRange<'a>
Source§fn clone(&self) -> PagedRange<'a>
fn clone(&self) -> PagedRange<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more