alloc

Function alloc 

Source
pub unsafe fn alloc(
    system_table: *mut SystemTable,
    layout: Layout,
    memory_type: MemoryType,
) -> *mut u8
Expand description

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 parameter specifies which UEFI allocator to use.

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.

  • It must be safe for this function to call allocate_pool of the boot-services provided via the system-table. It is the responsibility of the caller to retain boot-services until the returned allocation is released via dealloc(), or to account for it 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.