pub struct BuddyFrameAllocator;Expand description
Wrapper around the buddy allocator implementing the x86_64 crate’s FrameAllocator trait.
Used by OffsetPageTable when it needs a new intermediate page-table node
(PML4 / PDPT / PD / PT).
§Safety invariant: page-table frames MUST be zeroed
The x86_64 CPU page-table walker reads all 512 entries of every intermediate node it traverses, regardless of which entries are “in use”. If a newly allocated page-table frame contains stale bytes (left behind by the slab allocator or a previous allocation), any non-zero entry is decoded as a valid PTE pointing to an arbitrary physical address. The first fetch from such an address becomes the new RIP after the Ring 3 transition : explaining why RIP is non-deterministic across boots.
BuddyFrameAllocator enforces zeroing via FrameAllocOptions::new() .purpose(FramePurpose::PageTable) which:
- Calls the buddy allocator for a raw order-0 frame.
- CAS-claims the frame via the
MetaSlotrefcount field (REFCOUNT_UNUSED→1). - Zeros the 4 KiB with a single
ptr::write_bytesthrough the HHDM. - Sets purpose flags on the
MetaSlotwithReleaseordering. - Stores
refcount = 1withReleaseordering so any future reader that loads the refcount withAcquireobserves a fully-initialised frame.
This matches the Asterinas OSTD pattern (FrameAllocOptions + per-frame
MetaSlot with refcount CAS). Metadata lives in
dedicated slots (not in mapped page bytes); see get_meta_slot.
Trait Implementations§
Source§impl FrameAllocator<Size4KiB> for BuddyFrameAllocator
impl FrameAllocator<Size4KiB> for BuddyFrameAllocator
Source§fn allocate_frame(&mut self) -> Option<X86PhysFrame<Size4KiB>>
fn allocate_frame(&mut self) -> Option<X86PhysFrame<Size4KiB>>
Auto Trait Implementations§
impl Freeze for BuddyFrameAllocator
impl RefUnwindSafe for BuddyFrameAllocator
impl Send for BuddyFrameAllocator
impl Sync for BuddyFrameAllocator
impl Unpin for BuddyFrameAllocator
impl UnsafeUnpin for BuddyFrameAllocator
impl UnwindSafe for BuddyFrameAllocator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more