Struct memory::AllocatedPages

pub struct AllocatedPages<P = Page4K>where
    P: PageSize,{ /* private fields */ }
Expand description

Represents a range of allocated VirtualAddresses, specified in Pages.

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,

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

Returns the starting VirtualAddress in this range of pages.

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

Returns the size in number of pages of this range of pages.

pub const fn start(&self) -> &Page<P>

Returns the starting Page in this range of pages.

pub const fn end(&self) -> &Page<P>

Returns the ending Page (inclusive) in this range of pages.

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>

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>

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>>

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>>

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 returned AllocatedPages object will be empty.
  • If at_page == self.end + 1, the second returned AllocatedPages object will be empty.

Returns an Err containing this AllocatedPages if at_page is otherwise out of bounds.

Trait Implementations§

§

impl<P> Debug for AllocatedPages<P>where P: PageSize,

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<P> Default for AllocatedPages<P>where P: PageSize,

§

fn default() -> AllocatedPages<P>

Returns the “default value” for a type. Read more
§

impl<P> Drop for AllocatedPages<P>where P: PageSize,

§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<P> RefUnwindSafe for AllocatedPages<P>where P: RefUnwindSafe,

§

impl<P> Send for AllocatedPages<P>where P: Send,

§

impl<P> Sync for AllocatedPages<P>where P: Sync,

§

impl<P> Unpin for AllocatedPages<P>where P: Unpin,

§

impl<P> UnwindSafe for AllocatedPages<P>where P: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.