Struct frame_allocator::AllocatedFrames
source · pub struct AllocatedFrames { /* private fields */ }
Expand description
Represents a range of allocated physical memory [Frame
]s; derefs to [FrameRange
].
These frames are not immediately accessible because they’re not yet mapped
by any virtual memory pages.
You must do that separately in order to create a MappedPages
type,
which can then be used to access the contents of these frames.
This object represents ownership of the range of allocated physical frames; if this object falls out of scope, its allocated frames will be auto-deallocated upon drop.
Implementations§
source§impl AllocatedFrames
impl AllocatedFrames
sourcepub const fn empty() -> AllocatedFrames
pub const fn empty() -> AllocatedFrames
Returns an empty AllocatedFrames object that performs no frame allocation. Can be used as a placeholder, but will not permit any real usage.
sourcepub fn merge(&mut self, other: AllocatedFrames) -> Result<(), AllocatedFrames>
pub fn merge(&mut self, other: AllocatedFrames) -> Result<(), AllocatedFrames>
Merges the given AllocatedFrames
object other
into this AllocatedFrames
object (self
).
This is just for convenience and usability purposes, it performs no allocation or remapping.
The given other
must be physically contiguous with self
, i.e., come immediately before or after self
.
That is, either self.start == other.end + 1
or self.end + 1 == other.start
must be true.
If either of those conditions are met, self
is modified and Ok(())
is returned,
otherwise Err(other)
is returned.
sourcepub fn split(
self,
at_frame: Frame
) -> Result<(AllocatedFrames, AllocatedFrames), AllocatedFrames>
pub fn split(
self,
at_frame: Frame
) -> Result<(AllocatedFrames, AllocatedFrames), AllocatedFrames>
Splits this AllocatedFrames
into two separate AllocatedFrames
objects:
[beginning : at_frame - 1]
[at_frame : end]
This function follows the behavior of core::slice::split_at()
,
thus, either one of the returned AllocatedFrames
objects may be empty.
- If
at_frame == self.start
, the first returnedAllocatedFrames
object will be empty. - If
at_frame == self.end + 1
, the second returnedAllocatedFrames
object will be empty.
Returns an Err
containing this AllocatedFrames
if at_frame
is otherwise out of bounds.
sourcepub fn as_allocated_frame(&self) -> AllocatedFrame<'_>
pub fn as_allocated_frame(&self) -> AllocatedFrame<'_>
Returns an AllocatedFrame
if this AllocatedFrames
object contains only one frame.
Panic
Panics if this AllocatedFrame
contains multiple frames or zero frames.
Methods from Deref<Target = 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 number of 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., addr - self.start_address()
.
If the given offset
is not within this range of [Frame
]s, this returns None
.
Examples
If the range covers addresses 0x2000
to 0x4000
, then address_at_offset(0x1500)
would return Some(0x3500)
.
pub fn to_extended(&self, to_include: Frame) -> FrameRange
pub fn to_extended(&self, to_include: Frame) -> FrameRange
Returns a new separate FrameRange
that is extended to include the given [Frame
].
Methods from Deref<Target = RangeInclusive<Frame>>§
1.27.0 · sourcepub fn start(&self) -> &Idx
pub fn start(&self) -> &Idx
Returns the lower bound of the range (inclusive).
When using an inclusive range for iteration, the values of start()
and
end()
are unspecified after the iteration ended. To determine
whether the inclusive range is empty, use the is_empty()
method
instead of comparing start() > end()
.
Note: the value returned by this method is unspecified after the range has been iterated to exhaustion.
Examples
assert_eq!((3..=5).start(), &3);
1.27.0 · sourcepub fn end(&self) -> &Idx
pub fn end(&self) -> &Idx
Returns the upper bound of the range (inclusive).
When using an inclusive range for iteration, the values of start()
and end()
are unspecified after the iteration ended. To determine
whether the inclusive range is empty, use the is_empty()
method
instead of comparing start() > end()
.
Note: the value returned by this method is unspecified after the range has been iterated to exhaustion.
Examples
assert_eq!((3..=5).end(), &5);
1.35.0 · 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.
Examples
assert!(!(3..=5).contains(&2));
assert!( (3..=5).contains(&3));
assert!( (3..=5).contains(&4));
assert!( (3..=5).contains(&5));
assert!(!(3..=5).contains(&6));
assert!( (3..=3).contains(&3));
assert!(!(3..=2).contains(&3));
assert!( (0.0..=1.0).contains(&1.0));
assert!(!(0.0..=1.0).contains(&f32::NAN));
assert!(!(0.0..=f32::NAN).contains(&0.0));
assert!(!(f32::NAN..=1.0).contains(&1.0));
This method always returns false
after iteration has finished:
let mut r = 3..=5;
assert!(r.contains(&3) && r.contains(&5));
for _ in r.by_ref() {}
// Precise field values are unspecified here
assert!(!r.contains(&3) && !r.contains(&5));
1.47.0 · sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the range contains no items.
Examples
assert!(!(3..=5).is_empty());
assert!(!(3..=3).is_empty());
assert!( (3..=2).is_empty());
The range is empty if either side is incomparable:
assert!(!(3.0..=5.0).is_empty());
assert!( (3.0..=f32::NAN).is_empty());
assert!( (f32::NAN..=5.0).is_empty());
This method returns true
after iteration has finished:
let mut r = 3..=5;
for _ in r.by_ref() {}
// Precise field values are unspecified here
assert!(r.is_empty());