pub struct Allocator { /* private fields */ }Expand description
Memory Allocator
This crate implements a rust memory allocator that forwards requests to the
UEFI pool allocator. It takes a System-Table as input, as well as the
memory type to use as backing, and then forwards all memory allocation
requests to the AllocatePool() UEFI system.
The core::alloc::Allocator trait is implemented for this allocator.
Hence, this allocator can also be used to back the global memory-allocator
of liballoc (or libstd). See the Global type for an implementation of
the global allocator, based on this type.
Implementations§
Source§impl Allocator
impl Allocator
Sourcepub unsafe fn from_system_table(
st: *mut SystemTable,
memtype: MemoryType,
) -> Allocator
pub unsafe fn from_system_table( st: *mut SystemTable, memtype: MemoryType, ) -> Allocator
Create Allocator from UEFI System-Table
This creates a new Allocator object from a UEFI System-Table pointer
and the memory-type to use for allocations. That is, all allocations on
this object will be tunnelled through the AllocatePool API on the
given System-Table. Allocations will always use the memory type given
as memtype.
Note that this interface is unsafe, since the caller must guarantee that the System-Table is valid for as long as the Allocator is. Furthermore, the caller must guarantee validity of the system-table-interface. The latter is usually guaranteed by the provider of the System-Table. The former is usually just a matter of tearing down the allocator before returning from your application entry-point.
Sourcepub unsafe fn alloc(&self, layout: Layout) -> *mut u8
pub unsafe fn alloc(&self, layout: Layout) -> *mut u8
Allocate Memory from UEFI Boot-Services
Use the UEFI allocate_pool boot-services to request a block of memory
satisfying the given memory layout. The memory type tied to this
allocator object is used.
This returns a null-pointer if the allocator could not serve the request (which on UEFI implies out-of-memory). Otherwise, a non-null pointer to the aligned block is returned.
§Safety
To ensure safety of this interface, the caller must guarantee:
-
The allocation size must not be 0. The function will panic otherwise.
-
The returned pointer is not necessarily the same pointer as returned by
allocate_poolof the boot-services. A caller must not assume this when forwarding the pointer to other allocation services outside of this module.
Sourcepub unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout)
pub unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout)
Deallocate Memory from UEFI Boot-Services
Use the UEFI free_pool boot-services to release a block of memory
previously allocated through alloc().
§Safety
To ensure safety of this interface, the caller must guarantee:
-
The memory block must be the same as previously returned by a call to
alloc(). Every memory block must be released exactly once. -
The passed layout must match the layout used to allocate the memory block.