Allocator

Struct Allocator 

Source
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

Source

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.

Source

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

Source

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.

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, 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.