Skip to main content

PhysicalAllocator

Trait PhysicalAllocator 

Source
pub unsafe trait PhysicalAllocator {
    // Required methods
    fn allocate_physical(
        &self,
        ps: PageSize,
        count: NonZeroUsize,
    ) -> Result<usize, AllocError>;
    unsafe fn deallocate_physical(
        &self,
        ps: PageSize,
        count: NonZeroUsize,
        phys: usize,
    );
}
Expand description

Trait for physical frame allocators.

§Contract guarantees

allocate_physical is a safe method whose returned address may later be passed to unsafe deallocation paths. Implementors must guarantee that every successful allocation:

  • returns the base of count contiguous frames of size ps;
  • returns a base address aligned to ps.bytes();
  • represents the whole byte range [base, base + count * ps.bytes()) without arithmetic overflow;
  • transfers exclusive ownership of that range to the caller until it is returned with deallocate_physical; and
  • never returns a range that overlaps any still-live allocation.

On Err, the allocator must not transfer ownership of any frame.

§Safety

This is an unsafe trait because safe callers and generic wrappers may rely on successful allocations being real, unique physical frames. Implementors must ensure that every successful allocation is backed by physical memory managed by this allocator and exclusively owned until deallocation.

§Errors

Unsupported page sizes, unrepresentable requests, requests too large for the allocator’s configuration, and exhausted memory must be reported with AllocError rather than by returning an address that violates the contract.

Required Methods§

Source

fn allocate_physical( &self, ps: PageSize, count: NonZeroUsize, ) -> Result<usize, AllocError>

Allocate count contiguous frames of size ps.

Returns the physical base address on success. When called on an uninitialised allocator it returns AllocError::OutOfMemory.

§Errors

See the trait-level # Errors documentation.

Source

unsafe fn deallocate_physical( &self, ps: PageSize, count: NonZeroUsize, phys: usize, )

Return count contiguous frames of size ps starting at phys.

§Safety

phys must be the address previously returned by allocate_physical with the same ps and count, and must not be used after this call.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<A: PhysicalAllocator, S: CpuId, const SLOTS: usize, const CAP: usize, const DEPOT_CAP: usize, I: InterruptControl> PhysicalAllocator for DepotAllocator<A, S, SLOTS, CAP, DEPOT_CAP, I>

Source§

impl<const ORDERS: usize, P: Provenance, G: GateConfig> PhysicalAllocator for SummaryBuddyAllocator<ORDERS, P, G>

Source§

impl<const REGIONS: usize, A, S> PhysicalAllocator for RegionedAllocator<REGIONS, A, S>
where A: PhysicalAllocator, S: CpuId,