Path: blob/main/sys/contrib/edk2/Include/Library/MemoryAllocationLib.h
48383 views
/** @file1Provides services to allocate and free memory buffers of various memory types and alignments.23The Memory Allocation Library abstracts various common memory allocation operations. This library4allows code to be written in a phase-independent manner because the allocation of memory in PEI, DXE,5and SMM (for example) is done via a different mechanism. Using a common library interface makes it6much easier to port algorithms from phase to phase.78Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>9SPDX-License-Identifier: BSD-2-Clause-Patent1011**/1213#ifndef __MEMORY_ALLOCATION_LIB_H__14#define __MEMORY_ALLOCATION_LIB_H__1516/**17Allocates one or more 4KB pages of type EfiBootServicesData.1819Allocates the number of 4KB pages of type EfiBootServicesData and returns a pointer to the20allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL21is returned. If there is not enough memory remaining to satisfy the request, then NULL is22returned.2324@param Pages The number of 4 KB pages to allocate.2526@return A pointer to the allocated buffer or NULL if allocation fails.2728**/29VOID *30EFIAPI31AllocatePages (32IN UINTN Pages33);3435/**36Allocates one or more 4KB pages of type EfiRuntimeServicesData.3738Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the39allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL40is returned. If there is not enough memory remaining to satisfy the request, then NULL is41returned.4243@param Pages The number of 4 KB pages to allocate.4445@return A pointer to the allocated buffer or NULL if allocation fails.4647**/48VOID *49EFIAPI50AllocateRuntimePages (51IN UINTN Pages52);5354/**55Allocates one or more 4KB pages of type EfiReservedMemoryType.5657Allocates the number of 4KB pages of type EfiReservedMemoryType and returns a pointer to the58allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL59is returned. If there is not enough memory remaining to satisfy the request, then NULL is60returned.6162@param Pages The number of 4 KB pages to allocate.6364@return A pointer to the allocated buffer or NULL if allocation fails.6566**/67VOID *68EFIAPI69AllocateReservedPages (70IN UINTN Pages71);7273/**74Frees one or more 4KB pages that were previously allocated with one of the page allocation75functions in the Memory Allocation Library.7677Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer78must have been allocated on a previous call to the page allocation services of the Memory79Allocation Library. If it is not possible to free allocated pages, then this function will80perform no actions.8182If Buffer was not allocated with a page allocation function in the Memory Allocation Library,83then ASSERT().84If Pages is zero, then ASSERT().8586@param Buffer Pointer to the buffer of pages to free.87@param Pages The number of 4 KB pages to free.8889**/90VOID91EFIAPI92FreePages (93IN VOID *Buffer,94IN UINTN Pages95);9697/**98Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.99100Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an101alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is102returned. If there is not enough memory at the specified alignment remaining to satisfy the103request, then NULL is returned.104105If Alignment is not a power of two and Alignment is not zero, then ASSERT().106If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().107108@param Pages The number of 4 KB pages to allocate.109@param Alignment The requested alignment of the allocation. Must be a power of two.110If Alignment is zero, then byte alignment is used.111112@return A pointer to the allocated buffer or NULL if allocation fails.113114**/115VOID *116EFIAPI117AllocateAlignedPages (118IN UINTN Pages,119IN UINTN Alignment120);121122/**123Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment.124125Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an126alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is127returned. If there is not enough memory at the specified alignment remaining to satisfy the128request, then NULL is returned.129130If Alignment is not a power of two and Alignment is not zero, then ASSERT().131If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().132133@param Pages The number of 4 KB pages to allocate.134@param Alignment The requested alignment of the allocation. Must be a power of two.135If Alignment is zero, then byte alignment is used.136137@return A pointer to the allocated buffer or NULL if allocation fails.138139**/140VOID *141EFIAPI142AllocateAlignedRuntimePages (143IN UINTN Pages,144IN UINTN Alignment145);146147/**148Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment.149150Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an151alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is152returned. If there is not enough memory at the specified alignment remaining to satisfy the153request, then NULL is returned.154155If Alignment is not a power of two and Alignment is not zero, then ASSERT().156If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().157158@param Pages The number of 4 KB pages to allocate.159@param Alignment The requested alignment of the allocation. Must be a power of two.160If Alignment is zero, then byte alignment is used.161162@return A pointer to the allocated buffer or NULL if allocation fails.163164**/165VOID *166EFIAPI167AllocateAlignedReservedPages (168IN UINTN Pages,169IN UINTN Alignment170);171172/**173Frees one or more 4KB pages that were previously allocated with one of the aligned page174allocation functions in the Memory Allocation Library.175176Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer177must have been allocated on a previous call to the aligned page allocation services of the Memory178Allocation Library. If it is not possible to free allocated pages, then this function will179perform no actions.180181If Buffer was not allocated with an aligned page allocation function in the Memory Allocation182Library, then ASSERT().183If Pages is zero, then ASSERT().184185@param Buffer Pointer to the buffer of pages to free.186@param Pages The number of 4 KB pages to free.187188**/189VOID190EFIAPI191FreeAlignedPages (192IN VOID *Buffer,193IN UINTN Pages194);195196/**197Allocates a buffer of type EfiBootServicesData.198199Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a200pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is201returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.202203@param AllocationSize The number of bytes to allocate.204205@return A pointer to the allocated buffer or NULL if allocation fails.206207**/208VOID *209EFIAPI210AllocatePool (211IN UINTN AllocationSize212);213214/**215Allocates a buffer of type EfiRuntimeServicesData.216217Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns218a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is219returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.220221@param AllocationSize The number of bytes to allocate.222223@return A pointer to the allocated buffer or NULL if allocation fails.224225**/226VOID *227EFIAPI228AllocateRuntimePool (229IN UINTN AllocationSize230);231232/**233Allocates a buffer of type EfiReservedMemoryType.234235Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType and returns236a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is237returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.238239@param AllocationSize The number of bytes to allocate.240241@return A pointer to the allocated buffer or NULL if allocation fails.242243**/244VOID *245EFIAPI246AllocateReservedPool (247IN UINTN AllocationSize248);249250/**251Allocates and zeros a buffer of type EfiBootServicesData.252253Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the254buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a255valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the256request, then NULL is returned.257258@param AllocationSize The number of bytes to allocate and zero.259260@return A pointer to the allocated buffer or NULL if allocation fails.261262**/263VOID *264EFIAPI265AllocateZeroPool (266IN UINTN AllocationSize267);268269/**270Allocates and zeros a buffer of type EfiRuntimeServicesData.271272Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the273buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a274valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the275request, then NULL is returned.276277@param AllocationSize The number of bytes to allocate and zero.278279@return A pointer to the allocated buffer or NULL if allocation fails.280281**/282VOID *283EFIAPI284AllocateRuntimeZeroPool (285IN UINTN AllocationSize286);287288/**289Allocates and zeros a buffer of type EfiReservedMemoryType.290291Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the292buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a293valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the294request, then NULL is returned.295296@param AllocationSize The number of bytes to allocate and zero.297298@return A pointer to the allocated buffer or NULL if allocation fails.299300**/301VOID *302EFIAPI303AllocateReservedZeroPool (304IN UINTN AllocationSize305);306307/**308Copies a buffer to an allocated buffer of type EfiBootServicesData.309310Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies311AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the312allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there313is not enough memory remaining to satisfy the request, then NULL is returned.314315If Buffer is NULL, then ASSERT().316If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().317318@param AllocationSize The number of bytes to allocate and zero.319@param Buffer The buffer to copy to the allocated buffer.320321@return A pointer to the allocated buffer or NULL if allocation fails.322323**/324VOID *325EFIAPI326AllocateCopyPool (327IN UINTN AllocationSize,328IN CONST VOID *Buffer329);330331/**332Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.333334Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies335AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the336allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there337is not enough memory remaining to satisfy the request, then NULL is returned.338339If Buffer is NULL, then ASSERT().340If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().341342@param AllocationSize The number of bytes to allocate and zero.343@param Buffer The buffer to copy to the allocated buffer.344345@return A pointer to the allocated buffer or NULL if allocation fails.346347**/348VOID *349EFIAPI350AllocateRuntimeCopyPool (351IN UINTN AllocationSize,352IN CONST VOID *Buffer353);354355/**356Copies a buffer to an allocated buffer of type EfiReservedMemoryType.357358Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies359AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the360allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there361is not enough memory remaining to satisfy the request, then NULL is returned.362363If Buffer is NULL, then ASSERT().364If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().365366@param AllocationSize The number of bytes to allocate and zero.367@param Buffer The buffer to copy to the allocated buffer.368369@return A pointer to the allocated buffer or NULL if allocation fails.370371**/372VOID *373EFIAPI374AllocateReservedCopyPool (375IN UINTN AllocationSize,376IN CONST VOID *Buffer377);378379/**380Reallocates a buffer of type EfiBootServicesData.381382Allocates and zeros the number bytes specified by NewSize from memory of type383EfiBootServicesData. If OldBuffer is not NULL, then the smaller of OldSize and384NewSize bytes are copied from OldBuffer to the newly allocated buffer, and385OldBuffer is freed. A pointer to the newly allocated buffer is returned.386If NewSize is 0, then a valid buffer of 0 size is returned. If there is not387enough memory remaining to satisfy the request, then NULL is returned.388389If the allocation of the new buffer is successful and the smaller of NewSize and OldSize390is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().391392@param OldSize The size, in bytes, of OldBuffer.393@param NewSize The size, in bytes, of the buffer to reallocate.394@param OldBuffer The buffer to copy to the allocated buffer. This is an optional395parameter that may be NULL.396397@return A pointer to the allocated buffer or NULL if allocation fails.398399**/400VOID *401EFIAPI402ReallocatePool (403IN UINTN OldSize,404IN UINTN NewSize,405IN VOID *OldBuffer OPTIONAL406);407408/**409Reallocates a buffer of type EfiRuntimeServicesData.410411Allocates and zeros the number bytes specified by NewSize from memory of type412EfiRuntimeServicesData. If OldBuffer is not NULL, then the smaller of OldSize and413NewSize bytes are copied from OldBuffer to the newly allocated buffer, and414OldBuffer is freed. A pointer to the newly allocated buffer is returned.415If NewSize is 0, then a valid buffer of 0 size is returned. If there is not416enough memory remaining to satisfy the request, then NULL is returned.417418If the allocation of the new buffer is successful and the smaller of NewSize and OldSize419is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().420421@param OldSize The size, in bytes, of OldBuffer.422@param NewSize The size, in bytes, of the buffer to reallocate.423@param OldBuffer The buffer to copy to the allocated buffer. This is an optional424parameter that may be NULL.425426@return A pointer to the allocated buffer or NULL if allocation fails.427428**/429VOID *430EFIAPI431ReallocateRuntimePool (432IN UINTN OldSize,433IN UINTN NewSize,434IN VOID *OldBuffer OPTIONAL435);436437/**438Reallocates a buffer of type EfiReservedMemoryType.439440Allocates and zeros the number bytes specified by NewSize from memory of type441EfiReservedMemoryType. If OldBuffer is not NULL, then the smaller of OldSize and442NewSize bytes are copied from OldBuffer to the newly allocated buffer, and443OldBuffer is freed. A pointer to the newly allocated buffer is returned.444If NewSize is 0, then a valid buffer of 0 size is returned. If there is not445enough memory remaining to satisfy the request, then NULL is returned.446447If the allocation of the new buffer is successful and the smaller of NewSize and OldSize448is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().449450@param OldSize The size, in bytes, of OldBuffer.451@param NewSize The size, in bytes, of the buffer to reallocate.452@param OldBuffer The buffer to copy to the allocated buffer. This is an optional453parameter that may be NULL.454455@return A pointer to the allocated buffer or NULL if allocation fails.456457**/458VOID *459EFIAPI460ReallocateReservedPool (461IN UINTN OldSize,462IN UINTN NewSize,463IN VOID *OldBuffer OPTIONAL464);465466/**467Frees a buffer that was previously allocated with one of the pool allocation functions in the468Memory Allocation Library.469470Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the471pool allocation services of the Memory Allocation Library. If it is not possible to free pool472resources, then this function will perform no actions.473474If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,475then ASSERT().476477@param Buffer Pointer to the buffer to free.478479**/480VOID481EFIAPI482FreePool (483IN VOID *Buffer484);485486#endif487488489