Struct memory::AllocatedPages
pub struct AllocatedPages<P = Page4K>where
P: PageSize,{ /* private fields */ }
Expand description
Represents a range of allocated VirtualAddress
es, specified in Page
s.
These pages are not initially mapped to any physical memory frames, you must do that separately
in order to actually use their memory; see the MappedPages
type for more.
This object represents ownership of the allocated virtual pages; if this object falls out of scope, its allocated pages will be auto-deallocated upon drop.
Implementations§
§impl<P> AllocatedPages<P>where
P: PageSize,
impl<P> AllocatedPages<P>where P: PageSize,
pub const fn empty() -> AllocatedPages<P>
pub const fn empty() -> AllocatedPages<P>
Returns an empty AllocatedPages object that performs no page allocation. Can be used as a placeholder, but will not permit any real usage.
pub const fn start_address(&self) -> VirtualAddress
pub const fn start_address(&self) -> VirtualAddress
Returns the starting VirtualAddress
in this range of pages.
pub const fn size_in_bytes(&self) -> usize
pub const fn size_in_bytes(&self) -> usize
Returns the size in bytes of this range of pages.
pub const fn size_in_pages(&self) -> usize
pub const fn size_in_pages(&self) -> usize
Returns the size in number of pages of this range of pages.
pub const fn range(&self) -> &PageRange<P>
pub const fn range(&self) -> &PageRange<P>
Returns a reference to the inner PageRange
, which is cloneable/iterable.
pub const fn offset_of_address(&self, addr: VirtualAddress) -> Option<usize>
pub const fn offset_of_address(&self, addr: VirtualAddress) -> Option<usize>
Returns the offset of the given VirtualAddress
within this range of pages,
i.e., addr - self.start_address()
.
If the given addr
is not covered by this range of pages, this returns None
.
Examples
If the range covers addresses 0x2000
to 0x4000
,
then offset_of_address(0x3500)
would return Some(0x1500)
.
pub const fn address_at_offset(&self, offset: usize) -> Option<VirtualAddress>
pub const fn address_at_offset(&self, offset: usize) -> Option<VirtualAddress>
Returns the VirtualAddress
at the given offset into this range of pages,
i.e., self.start_address() + offset
.
If the given offset
is not within this range of pages, this returns None
.
Examples
If the range covers addresses 0x2000
through 0x3FFF
,
then address_at_offset(0x1500)
would return Some(0x3500)
,
and address_at_offset(0x2000)
would return None
.
pub fn merge(&mut self, ap: AllocatedPages<P>) -> Result<(), AllocatedPages<P>>
pub fn merge(&mut self, ap: AllocatedPages<P>) -> Result<(), AllocatedPages<P>>
Merges the given AllocatedPages
object ap
into this AllocatedPages
object (self
).
This is just for convenience and usability purposes, it performs no allocation or remapping.
The ap
must be virtually contiguous and come immediately after self
,
that is, self.end
must equal ap.start
.
If this condition is met, self
is modified and Ok(())
is returned,
otherwise Err(ap)
is returned.
pub fn split(
self,
at_page: Page<P>
) -> Result<(AllocatedPages<P>, AllocatedPages<P>), AllocatedPages<P>>
pub fn split( self, at_page: Page<P> ) -> Result<(AllocatedPages<P>, AllocatedPages<P>), AllocatedPages<P>>
Splits this AllocatedPages
into two separate AllocatedPages
objects:
[beginning : at_page - 1]
[at_page : end]
This function follows the behavior of core::slice::split_at()
,
thus, either one of the returned AllocatedPages
objects may be empty.
- If
at_page == self.start
, the first returnedAllocatedPages
object will be empty. - If
at_page == self.end + 1
, the second returnedAllocatedPages
object will be empty.
Returns an Err
containing this AllocatedPages
if at_page
is otherwise out of bounds.