Skip to main content

BuddyFrameAllocator

Struct BuddyFrameAllocator 

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

  1. Calls the buddy allocator for a raw order-0 frame.
  2. CAS-claims the frame via the MetaSlot refcount field (REFCOUNT_UNUSED1).
  3. Zeros the 4 KiB with a single ptr::write_bytes through the HHDM.
  4. Sets purpose flags on the MetaSlot with Release ordering.
  5. Stores refcount = 1 with Release ordering so any future reader that loads the refcount with Acquire observes 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

Source§

fn allocate_frame(&mut self) -> Option<X86PhysFrame<Size4KiB>>

Allocate a frame of the appropriate size and return it if possible.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.