xref: /src/sys/contrib/edk2/Include/Library/MemoryAllocationLib.h (revision 580fcf642ea2d5a1e60f24947d1c2e97007e44e9)
10499b37cSWarner Losh /** @file
20499b37cSWarner Losh   Provides services to allocate and free memory buffers of various memory types and alignments.
30499b37cSWarner Losh 
40499b37cSWarner Losh   The Memory Allocation Library abstracts various common memory allocation operations. This library
50499b37cSWarner Losh   allows code to be written in a phase-independent manner because the allocation of memory in PEI, DXE,
60499b37cSWarner Losh   and SMM (for example) is done via a different mechanism. Using a common library interface makes it
70499b37cSWarner Losh   much easier to port algorithms from phase to phase.
80499b37cSWarner Losh 
94a14dfccSMitchell Horne Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
104a14dfccSMitchell Horne SPDX-License-Identifier: BSD-2-Clause-Patent
110499b37cSWarner Losh 
120499b37cSWarner Losh **/
130499b37cSWarner Losh 
140499b37cSWarner Losh #ifndef __MEMORY_ALLOCATION_LIB_H__
150499b37cSWarner Losh #define __MEMORY_ALLOCATION_LIB_H__
160499b37cSWarner Losh 
170499b37cSWarner Losh /**
180499b37cSWarner Losh   Allocates one or more 4KB pages of type EfiBootServicesData.
190499b37cSWarner Losh 
200499b37cSWarner Losh   Allocates the number of 4KB pages of type EfiBootServicesData and returns a pointer to the
210499b37cSWarner Losh   allocated buffer.  The buffer returned is aligned on a 4KB boundary.  If Pages is 0, then NULL
220499b37cSWarner Losh   is returned.  If there is not enough memory remaining to satisfy the request, then NULL is
230499b37cSWarner Losh   returned.
240499b37cSWarner Losh 
250499b37cSWarner Losh   @param  Pages                 The number of 4 KB pages to allocate.
260499b37cSWarner Losh 
270499b37cSWarner Losh   @return A pointer to the allocated buffer or NULL if allocation fails.
280499b37cSWarner Losh 
290499b37cSWarner Losh **/
300499b37cSWarner Losh VOID *
310499b37cSWarner Losh EFIAPI
320499b37cSWarner Losh AllocatePages (
330499b37cSWarner Losh   IN UINTN  Pages
340499b37cSWarner Losh   );
350499b37cSWarner Losh 
360499b37cSWarner Losh /**
370499b37cSWarner Losh   Allocates one or more 4KB pages of type EfiRuntimeServicesData.
380499b37cSWarner Losh 
390499b37cSWarner Losh   Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
400499b37cSWarner Losh   allocated buffer.  The buffer returned is aligned on a 4KB boundary.  If Pages is 0, then NULL
410499b37cSWarner Losh   is returned.  If there is not enough memory remaining to satisfy the request, then NULL is
420499b37cSWarner Losh   returned.
430499b37cSWarner Losh 
440499b37cSWarner Losh   @param  Pages                 The number of 4 KB pages to allocate.
450499b37cSWarner Losh 
460499b37cSWarner Losh   @return A pointer to the allocated buffer or NULL if allocation fails.
470499b37cSWarner Losh 
480499b37cSWarner Losh **/
490499b37cSWarner Losh VOID *
500499b37cSWarner Losh EFIAPI
510499b37cSWarner Losh AllocateRuntimePages (
520499b37cSWarner Losh   IN UINTN  Pages
530499b37cSWarner Losh   );
540499b37cSWarner Losh 
550499b37cSWarner Losh /**
560499b37cSWarner Losh   Allocates one or more 4KB pages of type EfiReservedMemoryType.
570499b37cSWarner Losh 
580499b37cSWarner Losh   Allocates the number of 4KB pages of type EfiReservedMemoryType and returns a pointer to the
590499b37cSWarner Losh   allocated buffer.  The buffer returned is aligned on a 4KB boundary.  If Pages is 0, then NULL
600499b37cSWarner Losh   is returned.  If there is not enough memory remaining to satisfy the request, then NULL is
610499b37cSWarner Losh   returned.
620499b37cSWarner Losh 
630499b37cSWarner Losh   @param  Pages                 The number of 4 KB pages to allocate.
640499b37cSWarner Losh 
650499b37cSWarner Losh   @return A pointer to the allocated buffer or NULL if allocation fails.
660499b37cSWarner Losh 
670499b37cSWarner Losh **/
680499b37cSWarner Losh VOID *
690499b37cSWarner Losh EFIAPI
700499b37cSWarner Losh AllocateReservedPages (
710499b37cSWarner Losh   IN UINTN  Pages
720499b37cSWarner Losh   );
730499b37cSWarner Losh 
740499b37cSWarner Losh /**
750499b37cSWarner Losh   Frees one or more 4KB pages that were previously allocated with one of the page allocation
760499b37cSWarner Losh   functions in the Memory Allocation Library.
770499b37cSWarner Losh 
780499b37cSWarner Losh   Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer.  Buffer
790499b37cSWarner Losh   must have been allocated on a previous call to the page allocation services of the Memory
800499b37cSWarner Losh   Allocation Library.  If it is not possible to free allocated pages, then this function will
810499b37cSWarner Losh   perform no actions.
820499b37cSWarner Losh 
830499b37cSWarner Losh   If Buffer was not allocated with a page allocation function in the Memory Allocation Library,
840499b37cSWarner Losh   then ASSERT().
850499b37cSWarner Losh   If Pages is zero, then ASSERT().
860499b37cSWarner Losh 
870499b37cSWarner Losh   @param  Buffer                Pointer to the buffer of pages to free.
880499b37cSWarner Losh   @param  Pages                 The number of 4 KB pages to free.
890499b37cSWarner Losh 
900499b37cSWarner Losh **/
910499b37cSWarner Losh VOID
920499b37cSWarner Losh EFIAPI
930499b37cSWarner Losh FreePages (
940499b37cSWarner Losh   IN VOID   *Buffer,
950499b37cSWarner Losh   IN UINTN  Pages
960499b37cSWarner Losh   );
970499b37cSWarner Losh 
980499b37cSWarner Losh /**
990499b37cSWarner Losh   Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.
1000499b37cSWarner Losh 
1010499b37cSWarner Losh   Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an
1020499b37cSWarner Losh   alignment specified by Alignment.  The allocated buffer is returned.  If Pages is 0, then NULL is
1030499b37cSWarner Losh   returned.  If there is not enough memory at the specified alignment remaining to satisfy the
1040499b37cSWarner Losh   request, then NULL is returned.
1050499b37cSWarner Losh 
1060499b37cSWarner Losh   If Alignment is not a power of two and Alignment is not zero, then ASSERT().
1070499b37cSWarner Losh   If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().
1080499b37cSWarner Losh 
1090499b37cSWarner Losh   @param  Pages                 The number of 4 KB pages to allocate.
1100499b37cSWarner Losh   @param  Alignment             The requested alignment of the allocation.  Must be a power of two.
1110499b37cSWarner Losh                                 If Alignment is zero, then byte alignment is used.
1120499b37cSWarner Losh 
1130499b37cSWarner Losh   @return A pointer to the allocated buffer or NULL if allocation fails.
1140499b37cSWarner Losh 
1150499b37cSWarner Losh **/
1160499b37cSWarner Losh VOID *
1170499b37cSWarner Losh EFIAPI
1180499b37cSWarner Losh AllocateAlignedPages (
1190499b37cSWarner Losh   IN UINTN  Pages,
1200499b37cSWarner Losh   IN UINTN  Alignment
1210499b37cSWarner Losh   );
1220499b37cSWarner Losh 
1230499b37cSWarner Losh /**
1240499b37cSWarner Losh   Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment.
1250499b37cSWarner Losh 
1260499b37cSWarner Losh   Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an
1270499b37cSWarner Losh   alignment specified by Alignment.  The allocated buffer is returned.  If Pages is 0, then NULL is
1280499b37cSWarner Losh   returned.  If there is not enough memory at the specified alignment remaining to satisfy the
1290499b37cSWarner Losh   request, then NULL is returned.
1300499b37cSWarner Losh 
1310499b37cSWarner Losh   If Alignment is not a power of two and Alignment is not zero, then ASSERT().
1320499b37cSWarner Losh   If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().
1330499b37cSWarner Losh 
1340499b37cSWarner Losh   @param  Pages                 The number of 4 KB pages to allocate.
1350499b37cSWarner Losh   @param  Alignment             The requested alignment of the allocation.  Must be a power of two.
1360499b37cSWarner Losh                                 If Alignment is zero, then byte alignment is used.
1370499b37cSWarner Losh 
1380499b37cSWarner Losh   @return A pointer to the allocated buffer or NULL if allocation fails.
1390499b37cSWarner Losh 
1400499b37cSWarner Losh **/
1410499b37cSWarner Losh VOID *
1420499b37cSWarner Losh EFIAPI
1430499b37cSWarner Losh AllocateAlignedRuntimePages (
1440499b37cSWarner Losh   IN UINTN  Pages,
1450499b37cSWarner Losh   IN UINTN  Alignment
1460499b37cSWarner Losh   );
1470499b37cSWarner Losh 
1480499b37cSWarner Losh /**
1490499b37cSWarner Losh   Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment.
1500499b37cSWarner Losh 
1510499b37cSWarner Losh   Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an
1520499b37cSWarner Losh   alignment specified by Alignment.  The allocated buffer is returned.  If Pages is 0, then NULL is
1530499b37cSWarner Losh   returned.  If there is not enough memory at the specified alignment remaining to satisfy the
1540499b37cSWarner Losh   request, then NULL is returned.
1550499b37cSWarner Losh 
1560499b37cSWarner Losh   If Alignment is not a power of two and Alignment is not zero, then ASSERT().
1570499b37cSWarner Losh   If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().
1580499b37cSWarner Losh 
1590499b37cSWarner Losh   @param  Pages                 The number of 4 KB pages to allocate.
1600499b37cSWarner Losh   @param  Alignment             The requested alignment of the allocation.  Must be a power of two.
1610499b37cSWarner Losh                                 If Alignment is zero, then byte alignment is used.
1620499b37cSWarner Losh 
1630499b37cSWarner Losh   @return A pointer to the allocated buffer or NULL if allocation fails.
1640499b37cSWarner Losh 
1650499b37cSWarner Losh **/
1660499b37cSWarner Losh VOID *
1670499b37cSWarner Losh EFIAPI
1680499b37cSWarner Losh AllocateAlignedReservedPages (
1690499b37cSWarner Losh   IN UINTN  Pages,
1700499b37cSWarner Losh   IN UINTN  Alignment
1710499b37cSWarner Losh   );
1720499b37cSWarner Losh 
1730499b37cSWarner Losh /**
1740499b37cSWarner Losh   Frees one or more 4KB pages that were previously allocated with one of the aligned page
1750499b37cSWarner Losh   allocation functions in the Memory Allocation Library.
1760499b37cSWarner Losh 
1770499b37cSWarner Losh   Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer.  Buffer
1780499b37cSWarner Losh   must have been allocated on a previous call to the aligned page allocation services of the Memory
1790499b37cSWarner Losh   Allocation Library.  If it is not possible to free allocated pages, then this function will
1800499b37cSWarner Losh   perform no actions.
1810499b37cSWarner Losh 
1820499b37cSWarner Losh   If Buffer was not allocated with an aligned page allocation function in the Memory Allocation
1830499b37cSWarner Losh   Library, then ASSERT().
1840499b37cSWarner Losh   If Pages is zero, then ASSERT().
1850499b37cSWarner Losh 
1860499b37cSWarner Losh   @param  Buffer                Pointer to the buffer of pages to free.
1870499b37cSWarner Losh   @param  Pages                 The number of 4 KB pages to free.
1880499b37cSWarner Losh 
1890499b37cSWarner Losh **/
1900499b37cSWarner Losh VOID
1910499b37cSWarner Losh EFIAPI
1920499b37cSWarner Losh FreeAlignedPages (
1930499b37cSWarner Losh   IN VOID   *Buffer,
1940499b37cSWarner Losh   IN UINTN  Pages
1950499b37cSWarner Losh   );
1960499b37cSWarner Losh 
1970499b37cSWarner Losh /**
1980499b37cSWarner Losh   Allocates a buffer of type EfiBootServicesData.
1990499b37cSWarner Losh 
2000499b37cSWarner Losh   Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a
2010499b37cSWarner Losh   pointer to the allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is
2020499b37cSWarner Losh   returned.  If there is not enough memory remaining to satisfy the request, then NULL is returned.
2030499b37cSWarner Losh 
2040499b37cSWarner Losh   @param  AllocationSize        The number of bytes to allocate.
2050499b37cSWarner Losh 
2060499b37cSWarner Losh   @return A pointer to the allocated buffer or NULL if allocation fails.
2070499b37cSWarner Losh 
2080499b37cSWarner Losh **/
2090499b37cSWarner Losh VOID *
2100499b37cSWarner Losh EFIAPI
2110499b37cSWarner Losh AllocatePool (
2120499b37cSWarner Losh   IN UINTN  AllocationSize
2130499b37cSWarner Losh   );
2140499b37cSWarner Losh 
2150499b37cSWarner Losh /**
2160499b37cSWarner Losh   Allocates a buffer of type EfiRuntimeServicesData.
2170499b37cSWarner Losh 
2180499b37cSWarner Losh   Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns
2190499b37cSWarner Losh   a pointer to the allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is
2200499b37cSWarner Losh   returned.  If there is not enough memory remaining to satisfy the request, then NULL is returned.
2210499b37cSWarner Losh 
2220499b37cSWarner Losh   @param  AllocationSize        The number of bytes to allocate.
2230499b37cSWarner Losh 
2240499b37cSWarner Losh   @return A pointer to the allocated buffer or NULL if allocation fails.
2250499b37cSWarner Losh 
2260499b37cSWarner Losh **/
2270499b37cSWarner Losh VOID *
2280499b37cSWarner Losh EFIAPI
2290499b37cSWarner Losh AllocateRuntimePool (
2300499b37cSWarner Losh   IN UINTN  AllocationSize
2310499b37cSWarner Losh   );
2320499b37cSWarner Losh 
2330499b37cSWarner Losh /**
2340499b37cSWarner Losh   Allocates a buffer of type EfiReservedMemoryType.
2350499b37cSWarner Losh 
2360499b37cSWarner Losh   Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType and returns
2370499b37cSWarner Losh   a pointer to the allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is
2380499b37cSWarner Losh   returned.  If there is not enough memory remaining to satisfy the request, then NULL is returned.
2390499b37cSWarner Losh 
2400499b37cSWarner Losh   @param  AllocationSize        The number of bytes to allocate.
2410499b37cSWarner Losh 
2420499b37cSWarner Losh   @return A pointer to the allocated buffer or NULL if allocation fails.
2430499b37cSWarner Losh 
2440499b37cSWarner Losh **/
2450499b37cSWarner Losh VOID *
2460499b37cSWarner Losh EFIAPI
2470499b37cSWarner Losh AllocateReservedPool (
2480499b37cSWarner Losh   IN UINTN  AllocationSize
2490499b37cSWarner Losh   );
2500499b37cSWarner Losh 
2510499b37cSWarner Losh /**
2520499b37cSWarner Losh   Allocates and zeros a buffer of type EfiBootServicesData.
2530499b37cSWarner Losh 
2540499b37cSWarner Losh   Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the
2550499b37cSWarner Losh   buffer with zeros, and returns a pointer to the allocated buffer.  If AllocationSize is 0, then a
2560499b37cSWarner Losh   valid buffer of 0 size is returned.  If there is not enough memory remaining to satisfy the
2570499b37cSWarner Losh   request, then NULL is returned.
2580499b37cSWarner Losh 
2590499b37cSWarner Losh   @param  AllocationSize        The number of bytes to allocate and zero.
2600499b37cSWarner Losh 
2610499b37cSWarner Losh   @return A pointer to the allocated buffer or NULL if allocation fails.
2620499b37cSWarner Losh 
2630499b37cSWarner Losh **/
2640499b37cSWarner Losh VOID *
2650499b37cSWarner Losh EFIAPI
2660499b37cSWarner Losh AllocateZeroPool (
2670499b37cSWarner Losh   IN UINTN  AllocationSize
2680499b37cSWarner Losh   );
2690499b37cSWarner Losh 
2700499b37cSWarner Losh /**
2710499b37cSWarner Losh   Allocates and zeros a buffer of type EfiRuntimeServicesData.
2720499b37cSWarner Losh 
2730499b37cSWarner Losh   Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the
2740499b37cSWarner Losh   buffer with zeros, and returns a pointer to the allocated buffer.  If AllocationSize is 0, then a
2750499b37cSWarner Losh   valid buffer of 0 size is returned.  If there is not enough memory remaining to satisfy the
2760499b37cSWarner Losh   request, then NULL is returned.
2770499b37cSWarner Losh 
2780499b37cSWarner Losh   @param  AllocationSize        The number of bytes to allocate and zero.
2790499b37cSWarner Losh 
2800499b37cSWarner Losh   @return A pointer to the allocated buffer or NULL if allocation fails.
2810499b37cSWarner Losh 
2820499b37cSWarner Losh **/
2830499b37cSWarner Losh VOID *
2840499b37cSWarner Losh EFIAPI
2850499b37cSWarner Losh AllocateRuntimeZeroPool (
2860499b37cSWarner Losh   IN UINTN  AllocationSize
2870499b37cSWarner Losh   );
2880499b37cSWarner Losh 
2890499b37cSWarner Losh /**
2900499b37cSWarner Losh   Allocates and zeros a buffer of type EfiReservedMemoryType.
2910499b37cSWarner Losh 
2920499b37cSWarner Losh   Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the
2930499b37cSWarner Losh   buffer with zeros, and returns a pointer to the allocated buffer.  If AllocationSize is 0, then a
2940499b37cSWarner Losh   valid buffer of 0 size is returned.  If there is not enough memory remaining to satisfy the
2950499b37cSWarner Losh   request, then NULL is returned.
2960499b37cSWarner Losh 
2970499b37cSWarner Losh   @param  AllocationSize        The number of bytes to allocate and zero.
2980499b37cSWarner Losh 
2990499b37cSWarner Losh   @return A pointer to the allocated buffer or NULL if allocation fails.
3000499b37cSWarner Losh 
3010499b37cSWarner Losh **/
3020499b37cSWarner Losh VOID *
3030499b37cSWarner Losh EFIAPI
3040499b37cSWarner Losh AllocateReservedZeroPool (
3050499b37cSWarner Losh   IN UINTN  AllocationSize
3060499b37cSWarner Losh   );
3070499b37cSWarner Losh 
3080499b37cSWarner Losh /**
3090499b37cSWarner Losh   Copies a buffer to an allocated buffer of type EfiBootServicesData.
3100499b37cSWarner Losh 
3110499b37cSWarner Losh   Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies
3120499b37cSWarner Losh   AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
3130499b37cSWarner Losh   allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there
3140499b37cSWarner Losh   is not enough memory remaining to satisfy the request, then NULL is returned.
3150499b37cSWarner Losh 
3160499b37cSWarner Losh   If Buffer is NULL, then ASSERT().
3170499b37cSWarner Losh   If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3180499b37cSWarner Losh 
3190499b37cSWarner Losh   @param  AllocationSize        The number of bytes to allocate and zero.
3200499b37cSWarner Losh   @param  Buffer                The buffer to copy to the allocated buffer.
3210499b37cSWarner Losh 
3220499b37cSWarner Losh   @return A pointer to the allocated buffer or NULL if allocation fails.
3230499b37cSWarner Losh 
3240499b37cSWarner Losh **/
3250499b37cSWarner Losh VOID *
3260499b37cSWarner Losh EFIAPI
3270499b37cSWarner Losh AllocateCopyPool (
3280499b37cSWarner Losh   IN UINTN       AllocationSize,
3290499b37cSWarner Losh   IN CONST VOID  *Buffer
3300499b37cSWarner Losh   );
3310499b37cSWarner Losh 
3320499b37cSWarner Losh /**
3330499b37cSWarner Losh   Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.
3340499b37cSWarner Losh 
3350499b37cSWarner Losh   Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies
3360499b37cSWarner Losh   AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
3370499b37cSWarner Losh   allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there
3380499b37cSWarner Losh   is not enough memory remaining to satisfy the request, then NULL is returned.
3390499b37cSWarner Losh 
3400499b37cSWarner Losh   If Buffer is NULL, then ASSERT().
3410499b37cSWarner Losh   If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3420499b37cSWarner Losh 
3430499b37cSWarner Losh   @param  AllocationSize        The number of bytes to allocate and zero.
3440499b37cSWarner Losh   @param  Buffer                The buffer to copy to the allocated buffer.
3450499b37cSWarner Losh 
3460499b37cSWarner Losh   @return A pointer to the allocated buffer or NULL if allocation fails.
3470499b37cSWarner Losh 
3480499b37cSWarner Losh **/
3490499b37cSWarner Losh VOID *
3500499b37cSWarner Losh EFIAPI
3510499b37cSWarner Losh AllocateRuntimeCopyPool (
3520499b37cSWarner Losh   IN UINTN       AllocationSize,
3530499b37cSWarner Losh   IN CONST VOID  *Buffer
3540499b37cSWarner Losh   );
3550499b37cSWarner Losh 
3560499b37cSWarner Losh /**
3570499b37cSWarner Losh   Copies a buffer to an allocated buffer of type EfiReservedMemoryType.
3580499b37cSWarner Losh 
3590499b37cSWarner Losh   Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies
3600499b37cSWarner Losh   AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
3610499b37cSWarner Losh   allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there
3620499b37cSWarner Losh   is not enough memory remaining to satisfy the request, then NULL is returned.
3630499b37cSWarner Losh 
3640499b37cSWarner Losh   If Buffer is NULL, then ASSERT().
3650499b37cSWarner Losh   If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3660499b37cSWarner Losh 
3670499b37cSWarner Losh   @param  AllocationSize        The number of bytes to allocate and zero.
3680499b37cSWarner Losh   @param  Buffer                The buffer to copy to the allocated buffer.
3690499b37cSWarner Losh 
3700499b37cSWarner Losh   @return A pointer to the allocated buffer or NULL if allocation fails.
3710499b37cSWarner Losh 
3720499b37cSWarner Losh **/
3730499b37cSWarner Losh VOID *
3740499b37cSWarner Losh EFIAPI
3750499b37cSWarner Losh AllocateReservedCopyPool (
3760499b37cSWarner Losh   IN UINTN       AllocationSize,
3770499b37cSWarner Losh   IN CONST VOID  *Buffer
3780499b37cSWarner Losh   );
3790499b37cSWarner Losh 
3800499b37cSWarner Losh /**
3810499b37cSWarner Losh   Reallocates a buffer of type EfiBootServicesData.
3820499b37cSWarner Losh 
3830499b37cSWarner Losh   Allocates and zeros the number bytes specified by NewSize from memory of type
3840499b37cSWarner Losh   EfiBootServicesData.  If OldBuffer is not NULL, then the smaller of OldSize and
3850499b37cSWarner Losh   NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
3860499b37cSWarner Losh   OldBuffer is freed.  A pointer to the newly allocated buffer is returned.
3870499b37cSWarner Losh   If NewSize is 0, then a valid buffer of 0 size is  returned.  If there is not
3880499b37cSWarner Losh   enough memory remaining to satisfy the request, then NULL is returned.
3890499b37cSWarner Losh 
3900499b37cSWarner Losh   If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
3910499b37cSWarner Losh   is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
3920499b37cSWarner Losh 
3930499b37cSWarner Losh   @param  OldSize        The size, in bytes, of OldBuffer.
3940499b37cSWarner Losh   @param  NewSize        The size, in bytes, of the buffer to reallocate.
3950499b37cSWarner Losh   @param  OldBuffer      The buffer to copy to the allocated buffer.  This is an optional
3960499b37cSWarner Losh                          parameter that may be NULL.
3970499b37cSWarner Losh 
3980499b37cSWarner Losh   @return A pointer to the allocated buffer or NULL if allocation fails.
3990499b37cSWarner Losh 
4000499b37cSWarner Losh **/
4010499b37cSWarner Losh VOID *
4020499b37cSWarner Losh EFIAPI
4030499b37cSWarner Losh ReallocatePool (
4040499b37cSWarner Losh   IN UINTN  OldSize,
4050499b37cSWarner Losh   IN UINTN  NewSize,
4060499b37cSWarner Losh   IN VOID   *OldBuffer  OPTIONAL
4070499b37cSWarner Losh   );
4080499b37cSWarner Losh 
4090499b37cSWarner Losh /**
4100499b37cSWarner Losh   Reallocates a buffer of type EfiRuntimeServicesData.
4110499b37cSWarner Losh 
4120499b37cSWarner Losh   Allocates and zeros the number bytes specified by NewSize from memory of type
4130499b37cSWarner Losh   EfiRuntimeServicesData.  If OldBuffer is not NULL, then the smaller of OldSize and
4140499b37cSWarner Losh   NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
4150499b37cSWarner Losh   OldBuffer is freed.  A pointer to the newly allocated buffer is returned.
4160499b37cSWarner Losh   If NewSize is 0, then a valid buffer of 0 size is  returned.  If there is not
4170499b37cSWarner Losh   enough memory remaining to satisfy the request, then NULL is returned.
4180499b37cSWarner Losh 
4190499b37cSWarner Losh   If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
4200499b37cSWarner Losh   is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
4210499b37cSWarner Losh 
4220499b37cSWarner Losh   @param  OldSize        The size, in bytes, of OldBuffer.
4230499b37cSWarner Losh   @param  NewSize        The size, in bytes, of the buffer to reallocate.
4240499b37cSWarner Losh   @param  OldBuffer      The buffer to copy to the allocated buffer.  This is an optional
4250499b37cSWarner Losh                          parameter that may be NULL.
4260499b37cSWarner Losh 
4270499b37cSWarner Losh   @return A pointer to the allocated buffer or NULL if allocation fails.
4280499b37cSWarner Losh 
4290499b37cSWarner Losh **/
4300499b37cSWarner Losh VOID *
4310499b37cSWarner Losh EFIAPI
4320499b37cSWarner Losh ReallocateRuntimePool (
4330499b37cSWarner Losh   IN UINTN  OldSize,
4340499b37cSWarner Losh   IN UINTN  NewSize,
4350499b37cSWarner Losh   IN VOID   *OldBuffer  OPTIONAL
4360499b37cSWarner Losh   );
4370499b37cSWarner Losh 
4380499b37cSWarner Losh /**
4390499b37cSWarner Losh   Reallocates a buffer of type EfiReservedMemoryType.
4400499b37cSWarner Losh 
4410499b37cSWarner Losh   Allocates and zeros the number bytes specified by NewSize from memory of type
4420499b37cSWarner Losh   EfiReservedMemoryType.  If OldBuffer is not NULL, then the smaller of OldSize and
4430499b37cSWarner Losh   NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
4440499b37cSWarner Losh   OldBuffer is freed.  A pointer to the newly allocated buffer is returned.
4450499b37cSWarner Losh   If NewSize is 0, then a valid buffer of 0 size is  returned.  If there is not
4460499b37cSWarner Losh   enough memory remaining to satisfy the request, then NULL is returned.
4470499b37cSWarner Losh 
4480499b37cSWarner Losh   If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
4490499b37cSWarner Losh   is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
4500499b37cSWarner Losh 
4510499b37cSWarner Losh   @param  OldSize        The size, in bytes, of OldBuffer.
4520499b37cSWarner Losh   @param  NewSize        The size, in bytes, of the buffer to reallocate.
4530499b37cSWarner Losh   @param  OldBuffer      The buffer to copy to the allocated buffer.  This is an optional
4540499b37cSWarner Losh                          parameter that may be NULL.
4550499b37cSWarner Losh 
4560499b37cSWarner Losh   @return A pointer to the allocated buffer or NULL if allocation fails.
4570499b37cSWarner Losh 
4580499b37cSWarner Losh **/
4590499b37cSWarner Losh VOID *
4600499b37cSWarner Losh EFIAPI
4610499b37cSWarner Losh ReallocateReservedPool (
4620499b37cSWarner Losh   IN UINTN  OldSize,
4630499b37cSWarner Losh   IN UINTN  NewSize,
4640499b37cSWarner Losh   IN VOID   *OldBuffer  OPTIONAL
4650499b37cSWarner Losh   );
4660499b37cSWarner Losh 
4670499b37cSWarner Losh /**
4680499b37cSWarner Losh   Frees a buffer that was previously allocated with one of the pool allocation functions in the
4690499b37cSWarner Losh   Memory Allocation Library.
4700499b37cSWarner Losh 
4710499b37cSWarner Losh   Frees the buffer specified by Buffer.  Buffer must have been allocated on a previous call to the
4720499b37cSWarner Losh   pool allocation services of the Memory Allocation Library.  If it is not possible to free pool
4730499b37cSWarner Losh   resources, then this function will perform no actions.
4740499b37cSWarner Losh 
4750499b37cSWarner Losh   If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,
4760499b37cSWarner Losh   then ASSERT().
4770499b37cSWarner Losh 
4780499b37cSWarner Losh   @param  Buffer                Pointer to the buffer to free.
4790499b37cSWarner Losh 
4800499b37cSWarner Losh **/
4810499b37cSWarner Losh VOID
4820499b37cSWarner Losh EFIAPI
4830499b37cSWarner Losh FreePool (
4840499b37cSWarner Losh   IN VOID  *Buffer
4850499b37cSWarner Losh   );
4860499b37cSWarner Losh 
4870499b37cSWarner Losh #endif
488