Struct frame_allocator::PhysicalMemoryRegion
source · 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 PhysicalMemoryRegion
s 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 PhysicalMemoryRegion
s 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§
source§impl PhysicalMemoryRegion
impl PhysicalMemoryRegion
pub fn new(frames: FrameRange, typ: MemoryRegionType) -> PhysicalMemoryRegion
Methods from Deref<Target = FrameRange>§
pub fn start(&self) -> &Frame<P>
pub fn start(&self) -> &Frame<P>
Returns the starting [Frame
] in this FrameRange
.
pub fn end(&self) -> &Frame<P>
pub fn end(&self) -> &Frame<P>
Returns the ending [Frame
] in this FrameRange
.
pub fn start_address(&self) -> PhysicalAddress
pub fn start_address(&self) -> PhysicalAddress
Returns the [PhysicalAddress
] of the starting [Frame
] in this FrameRange
.
pub fn size_in_frames(&self) -> usize
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
pub fn size_in_bytes(&self) -> usize
Returns the size of this range in bytes.
pub fn contains_address(&self, addr: PhysicalAddress) -> bool
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>
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>
pub fn address_at_offset(&self, offset: usize) -> Option<PhysicalAddress>
Returns the [PhysicalAddress
] at the given offset
into this FrameRange
within 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>
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
pub fn contains_range(&self, other: &FrameRange<P>) -> bool
Returns true
if the other
FrameRange
is fully contained within this FrameRange
.
Methods from Deref<Target = RangeInclusive<Frame<P>>>§
sourcepub fn iter(&self) -> RangeInclusiveIterator<Idx>
pub fn iter(&self) -> RangeInclusiveIterator<Idx>
Returns an iterator with the same start
and end
values as the range.
sourcepub fn contains<U>(&self, item: &U) -> boolwhere
Idx: PartialOrd<U>,
U: PartialOrd<Idx> + ?Sized,
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
impl Borrow<Frame<Page4K>> for &PhysicalMemoryRegion
source§impl Clone for PhysicalMemoryRegion
impl Clone for PhysicalMemoryRegion
source§fn clone(&self) -> PhysicalMemoryRegion
fn clone(&self) -> PhysicalMemoryRegion
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for PhysicalMemoryRegion
impl Debug for PhysicalMemoryRegion
source§impl Deref for PhysicalMemoryRegion
impl Deref for PhysicalMemoryRegion
source§impl Ord for PhysicalMemoryRegion
impl Ord for PhysicalMemoryRegion
source§impl PartialEq<PhysicalMemoryRegion> for PhysicalMemoryRegion
impl PartialEq<PhysicalMemoryRegion> for PhysicalMemoryRegion
source§impl PartialOrd<PhysicalMemoryRegion> for PhysicalMemoryRegion
impl PartialOrd<PhysicalMemoryRegion> for PhysicalMemoryRegion
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more