pub struct PhysicalMemoryRegion {
    pub frames: FrameRange<Page4K>,
    pub typ: MemoryRegionType,
}
Expand description

PhysicalMemoryRegion represents a range of contiguous frames in physical memory for bookkeeping purposes. It does not give access to the underlying frames.

Ordering and Equality

PhysicalMemoryRegion implements the Ord trait, and its total ordering is ONLY based on its starting Frame. This is useful so we can store PhysicalMemoryRegions in a sorted collection.

Similarly, PhysicalMemoryRegion implements equality traits, Eq and PartialEq, both of which are also based ONLY on the starting Frame of the PhysicalMemoryRegion. Thus, comparing two PhysicalMemoryRegions with the == or != operators may not work as expected. since it ignores their actual range of frames.

Fields§

§frames: FrameRange<Page4K>

The Frames covered by this region, an inclusive range.

§typ: MemoryRegionType

The type of this memory region, e.g., whether it’s in a free or reserved region.

Implementations§

Methods from Deref<Target = FrameRange>§

pub fn start(&self) -> &Frame<P>

Returns the starting [Frame] in this FrameRange.

pub fn end(&self) -> &Frame<P>

Returns the ending [Frame] in this FrameRange.

pub fn start_address(&self) -> PhysicalAddress

Returns the [PhysicalAddress] of the starting [Frame] in this FrameRange.

pub fn size_in_frames(&self) -> usize

Returns the number of [Frame]s covered by this iterator.

Use this instead of Iterator::count() method. This is instant, because it doesn’t need to iterate over each entry, unlike normal iterators.

pub fn size_in_bytes(&self) -> usize

Returns the size of this range in bytes.

pub fn contains_address(&self, addr: PhysicalAddress) -> bool

Returns true if this FrameRange contains the given [PhysicalAddress].

pub fn offset_of_address(&self, addr: PhysicalAddress) -> Option<usize>

Returns the offset of the given [PhysicalAddress] within this FrameRange, i.e., addr - self.start_address().

If the given addr is not covered by this range of [Frame]s, this returns None.

Examples

If the range covers addresses 0x2000 to 0x4000, then offset_of_address(0x3500) would return Some(0x1500).

pub fn address_at_offset(&self, offset: usize) -> Option<PhysicalAddress>

Returns the [PhysicalAddress] at the given offset into this FrameRangewithin this FrameRange, i.e., self.start_address() + offset.

If the given offset is not within this range of [Frame]s, 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 to_extended(&self, to_include: Frame<P>) -> FrameRange<P>

Returns a new separate FrameRange that is extended to include the given [Frame].

pub fn contains_range(&self, other: &FrameRange<P>) -> bool

Returns true if the other FrameRange is fully contained within this FrameRange.

pub fn overlap(&self, other: &FrameRange<P>) -> Option<FrameRange<P>>

Returns an inclusive FrameRange representing the [Frame]s that overlap across this FrameRange and the given other FrameRange.

If there is no overlap between the two ranges, None is returned.

Methods from Deref<Target = RangeInclusive<Frame<P>>>§

source

pub fn start(&self) -> &Idx

Returns the lower bound of the range (inclusive).

source

pub fn end(&self) -> &Idx

Returns the upper bound of the range (inclusive).

source

pub fn is_empty(&self) -> bool

Returns true if the range contains no items.

source

pub fn iter(&self) -> RangeInclusiveIterator<Idx>

Returns an iterator with the same start and end values as the range.

source

pub fn contains<U>(&self, item: &U) -> boolwhere Idx: PartialOrd<U>, U: PartialOrd<Idx> + ?Sized,

Returns true if item is contained in the range.

Trait Implementations§

source§

impl Borrow<Frame<Page4K>> for &PhysicalMemoryRegion

source§

fn borrow(&self) -> &Frame

Immutably borrows from an owned value. Read more
source§

impl Clone for PhysicalMemoryRegion

source§

fn clone(&self) -> PhysicalMemoryRegion

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for PhysicalMemoryRegion

source§

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

Formats the value using the given formatter. Read more
source§

impl Deref for PhysicalMemoryRegion

§

type Target = FrameRange<Page4K>

The resulting type after dereferencing.
source§

fn deref(&self) -> &FrameRange

Dereferences the value.
source§

impl Ord for PhysicalMemoryRegion

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<PhysicalMemoryRegion> for PhysicalMemoryRegion

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<PhysicalMemoryRegion> for PhysicalMemoryRegion

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Eq for PhysicalMemoryRegion

source§

impl StructuralEq for PhysicalMemoryRegion

Auto Trait Implementations§

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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.