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
countcontiguous frames of sizeps; - 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§
Sourcefn allocate_physical(
&self,
ps: PageSize,
count: NonZeroUsize,
) -> Result<usize, AllocError>
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.
Sourceunsafe fn deallocate_physical(
&self,
ps: PageSize,
count: NonZeroUsize,
phys: usize,
)
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".