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§

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.

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_pool of the boot-services. A caller must not assume this when forwarding the pointer to other allocation services outside of this module.

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.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.