2 Support routines for memory allocation routines based
3 on boot services for Dxe phase drivers using OS malloc.
5 OS malloc is used so OS based malloc debugging tools can be used.
6 If a single driver links against this lib protocols from other
7 drivers, or EFI boot services can return a buffer that needs to
8 freed using the EFI scheme. This is why the gEmuThunk->Free ()
9 can detect if the memory rang is for EFI so the right free can be
12 Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
13 Portions copyright (c) 2011, Apple Inc. All rights reserved.
14 This program and the accompanying materials
15 are licensed and made available under the terms and conditions of the BSD License
16 which accompanies this distribution. The full text of the license may be found at
17 http://opensource.org/licenses/bsd-license.php.
19 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
20 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
28 #include <Library/MemoryAllocationLib.h>
29 #include <Library/UefiBootServicesTableLib.h>
30 #include <Library/BaseMemoryLib.h>
31 #include <Library/DebugLib.h>
32 #include <Library/EmuThunkLib.h>
35 Allocates one or more 4KB pages of a certain memory type.
37 Allocates the number of 4KB pages of a certain memory type and returns a pointer to the allocated
38 buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL is returned.
39 If there is not enough memory remaining to satisfy the request, then NULL is returned.
41 @param MemoryType The type of memory to allocate.
42 @param Pages The number of 4 KB pages to allocate.
44 @return A pointer to the allocated buffer or NULL if allocation fails.
48 InternalAllocatePages (
49 IN EFI_MEMORY_TYPE MemoryType
,
54 EFI_PHYSICAL_ADDRESS Memory
;
60 return gEmuThunk
->Valloc (Pages
* EFI_PAGE_SIZE
);
64 Allocates one or more 4KB pages of type EfiBootServicesData.
66 Allocates the number of 4KB pages of type EfiBootServicesData and returns a pointer to the
67 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
68 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
71 @param Pages The number of 4 KB pages to allocate.
73 @return A pointer to the allocated buffer or NULL if allocation fails.
82 return InternalAllocatePages (EfiBootServicesData
, Pages
);
86 Allocates one or more 4KB pages of type EfiRuntimeServicesData.
88 Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
89 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
90 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
93 @param Pages The number of 4 KB pages to allocate.
95 @return A pointer to the allocated buffer or NULL if allocation fails.
100 AllocateRuntimePages (
104 return InternalAllocatePages (EfiRuntimeServicesData
, Pages
);
108 Allocates one or more 4KB pages of type EfiReservedMemoryType.
110 Allocates the number of 4KB pages of type EfiReservedMemoryType and returns a pointer to the
111 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
112 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
115 @param Pages The number of 4 KB pages to allocate.
117 @return A pointer to the allocated buffer or NULL if allocation fails.
122 AllocateReservedPages (
126 return InternalAllocatePages (EfiReservedMemoryType
, Pages
);
130 Frees one or more 4KB pages that were previously allocated with one of the page allocation
131 functions in the Memory Allocation Library.
133 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
134 must have been allocated on a previous call to the page allocation services of the Memory
135 Allocation Library. If it is not possible to free allocated pages, then this function will
138 If Buffer was not allocated with a page allocation function in the Memory Allocation Library,
140 If Pages is zero, then ASSERT().
142 @param Buffer The pointer to the buffer of pages to free.
143 @param Pages The number of 4 KB pages to free.
156 if (!gEmuThunk
->Free (Buffer
)) {
157 // The Free thunk will not free memory allocated in emulated EFI memory.
158 // The assmuption is this was allocated directly by EFI. We need this as some
159 // times protocols or EFI BootServices can return dynamically allocated buffers.
160 Status
= gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
) (UINTN
) Buffer
, Pages
);
161 ASSERT_EFI_ERROR (Status
);
166 Allocates one or more 4KB pages of a certain memory type at a specified alignment.
168 Allocates the number of 4KB pages specified by Pages of a certain memory type with an alignment
169 specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is returned.
170 If there is not enough memory at the specified alignment remaining to satisfy the request, then
172 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
174 @param MemoryType The type of memory to allocate.
175 @param Pages The number of 4 KB pages to allocate.
176 @param Alignment The requested alignment of the allocation. Must be a power of two.
177 If Alignment is zero, then byte alignment is used.
179 @return A pointer to the allocated buffer or NULL if allocation fails.
183 InternalAllocateAlignedPages (
184 IN EFI_MEMORY_TYPE MemoryType
,
193 UINTN UnalignedPages
;
197 // Alignment must be a power of two or zero.
199 ASSERT ((Alignment
& (Alignment
- 1)) == 0);
204 if (Alignment
> EFI_PAGE_SIZE
) {
206 // Caculate the total number of pages since alignment is larger than page size.
208 AlignmentMask
= Alignment
- 1;
209 RealPages
= Pages
+ EFI_SIZE_TO_PAGES (Alignment
);
211 // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.
213 ASSERT (RealPages
> Pages
);
215 Memory
= gEmuThunk
->Valloc (Pages
* EFI_PAGE_SIZE
);
216 if (Memory
!= NULL
) {
219 AlignedMemory
= ((UINTN
) Memory
+ AlignmentMask
) & ~AlignmentMask
;
220 UnalignedPages
= EFI_SIZE_TO_PAGES (AlignedMemory
- (UINTN
) Memory
);
221 if (UnalignedPages
> 0) {
223 // Free first unaligned page(s).
225 FreePages (Memory
, UnalignedPages
);
227 Memory
= (VOID
*) (AlignedMemory
+ EFI_PAGES_TO_SIZE (Pages
));
228 UnalignedPages
= RealPages
- Pages
- UnalignedPages
;
229 if (UnalignedPages
> 0) {
231 // Free last unaligned page(s).
233 FreePages (Memory
, UnalignedPages
);
237 // Do not over-allocate pages in this case.
239 Memory
= gEmuThunk
->Valloc (Pages
* EFI_PAGE_SIZE
);
240 if (Memory
!= NULL
) {
243 AlignedMemory
= (UINTN
) Memory
;
245 return (VOID
*) AlignedMemory
;
249 Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.
251 Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an
252 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
253 returned. If there is not enough memory at the specified alignment remaining to satisfy the
254 request, then NULL is returned.
256 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
258 @param Pages The number of 4 KB pages to allocate.
259 @param Alignment The requested alignment of the allocation. Must be a power of two.
260 If Alignment is zero, then byte alignment is used.
262 @return A pointer to the allocated buffer or NULL if allocation fails.
267 AllocateAlignedPages (
272 return InternalAllocateAlignedPages (EfiBootServicesData
, Pages
, Alignment
);
276 Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment.
278 Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an
279 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
280 returned. If there is not enough memory at the specified alignment remaining to satisfy the
281 request, then NULL is returned.
283 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
285 @param Pages The number of 4 KB pages to allocate.
286 @param Alignment The requested alignment of the allocation. Must be a power of two.
287 If Alignment is zero, then byte alignment is used.
289 @return A pointer to the allocated buffer or NULL if allocation fails.
294 AllocateAlignedRuntimePages (
299 return InternalAllocateAlignedPages (EfiRuntimeServicesData
, Pages
, Alignment
);
303 Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment.
305 Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an
306 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
307 returned. If there is not enough memory at the specified alignment remaining to satisfy the
308 request, then NULL is returned.
310 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
312 @param Pages The number of 4 KB pages to allocate.
313 @param Alignment The requested alignment of the allocation. Must be a power of two.
314 If Alignment is zero, then byte alignment is used.
316 @return A pointer to the allocated buffer or NULL if allocation fails.
321 AllocateAlignedReservedPages (
326 return InternalAllocateAlignedPages (EfiReservedMemoryType
, Pages
, Alignment
);
330 Frees one or more 4KB pages that were previously allocated with one of the aligned page
331 allocation functions in the Memory Allocation Library.
333 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
334 must have been allocated on a previous call to the aligned page allocation services of the Memory
335 Allocation Library. If it is not possible to free allocated pages, then this function will
338 If Buffer was not allocated with an aligned page allocation function in the Memory Allocation
339 Library, then ASSERT().
340 If Pages is zero, then ASSERT().
342 @param Buffer The pointer to the buffer of pages to free.
343 @param Pages The number of 4 KB pages to free.
353 FreePages (Buffer
, Pages
);
357 Allocates a buffer of a certain pool type.
359 Allocates the number bytes specified by AllocationSize of a certain pool type and returns a
360 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
361 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
363 @param MemoryType The type of memory to allocate.
364 @param AllocationSize The number of bytes to allocate.
366 @return A pointer to the allocated buffer or NULL if allocation fails.
370 InternalAllocatePool (
371 IN EFI_MEMORY_TYPE MemoryType
,
372 IN UINTN AllocationSize
375 return gEmuThunk
->Malloc (AllocationSize
);
379 Allocates a buffer of type EfiBootServicesData.
381 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a
382 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
383 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
385 @param AllocationSize The number of bytes to allocate.
387 @return A pointer to the allocated buffer or NULL if allocation fails.
393 IN UINTN AllocationSize
396 return InternalAllocatePool (EfiBootServicesData
, AllocationSize
);
400 Allocates a buffer of type EfiRuntimeServicesData.
402 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns
403 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
404 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
406 @param AllocationSize The number of bytes to allocate.
408 @return A pointer to the allocated buffer or NULL if allocation fails.
413 AllocateRuntimePool (
414 IN UINTN AllocationSize
417 return InternalAllocatePool (EfiRuntimeServicesData
, AllocationSize
);
421 Allocates a buffer of type EfiReservedMemoryType.
423 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType and returns
424 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
425 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
427 @param AllocationSize The number of bytes to allocate.
429 @return A pointer to the allocated buffer or NULL if allocation fails.
434 AllocateReservedPool (
435 IN UINTN AllocationSize
438 return InternalAllocatePool (EfiReservedMemoryType
, AllocationSize
);
442 Allocates and zeros a buffer of a certain pool type.
444 Allocates the number bytes specified by AllocationSize of a certain pool type, clears the buffer
445 with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a valid
446 buffer of 0 size is returned. If there is not enough memory remaining to satisfy the request,
447 then NULL is returned.
449 @param PoolType The type of memory to allocate.
450 @param AllocationSize The number of bytes to allocate and zero.
452 @return A pointer to the allocated buffer or NULL if allocation fails.
456 InternalAllocateZeroPool (
457 IN EFI_MEMORY_TYPE PoolType
,
458 IN UINTN AllocationSize
463 Memory
= InternalAllocatePool (PoolType
, AllocationSize
);
464 if (Memory
!= NULL
) {
465 Memory
= ZeroMem (Memory
, AllocationSize
);
471 Allocates and zeros a buffer of type EfiBootServicesData.
473 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the
474 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
475 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
476 request, then NULL is returned.
478 @param AllocationSize The number of bytes to allocate and zero.
480 @return A pointer to the allocated buffer or NULL if allocation fails.
486 IN UINTN AllocationSize
489 return InternalAllocateZeroPool (EfiBootServicesData
, AllocationSize
);
493 Allocates and zeros a buffer of type EfiRuntimeServicesData.
495 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the
496 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
497 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
498 request, then NULL is returned.
500 @param AllocationSize The number of bytes to allocate and zero.
502 @return A pointer to the allocated buffer or NULL if allocation fails.
507 AllocateRuntimeZeroPool (
508 IN UINTN AllocationSize
511 return InternalAllocateZeroPool (EfiRuntimeServicesData
, AllocationSize
);
515 Allocates and zeros a buffer of type EfiReservedMemoryType.
517 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the
518 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
519 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
520 request, then NULL is returned.
522 @param AllocationSize The number of bytes to allocate and zero.
524 @return A pointer to the allocated buffer or NULL if allocation fails.
529 AllocateReservedZeroPool (
530 IN UINTN AllocationSize
533 return InternalAllocateZeroPool (EfiReservedMemoryType
, AllocationSize
);
537 Copies a buffer to an allocated buffer of a certain pool type.
539 Allocates the number bytes specified by AllocationSize of a certain pool type, copies
540 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
541 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
542 is not enough memory remaining to satisfy the request, then NULL is returned.
543 If Buffer is NULL, then ASSERT().
544 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
546 @param PoolType The type of pool to allocate.
547 @param AllocationSize The number of bytes to allocate and zero.
548 @param Buffer The buffer to copy to the allocated buffer.
550 @return A pointer to the allocated buffer or NULL if allocation fails.
554 InternalAllocateCopyPool (
555 IN EFI_MEMORY_TYPE PoolType
,
556 IN UINTN AllocationSize
,
557 IN CONST VOID
*Buffer
562 ASSERT (Buffer
!= NULL
);
563 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
565 Memory
= InternalAllocatePool (PoolType
, AllocationSize
);
566 if (Memory
!= NULL
) {
567 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
573 Copies a buffer to an allocated buffer of type EfiBootServicesData.
575 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies
576 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
577 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
578 is not enough memory remaining to satisfy the request, then NULL is returned.
580 If Buffer is NULL, then ASSERT().
581 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
583 @param AllocationSize The number of bytes to allocate and zero.
584 @param Buffer The buffer to copy to the allocated buffer.
586 @return A pointer to the allocated buffer or NULL if allocation fails.
592 IN UINTN AllocationSize
,
593 IN CONST VOID
*Buffer
596 return InternalAllocateCopyPool (EfiBootServicesData
, AllocationSize
, Buffer
);
600 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.
602 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies
603 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
604 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
605 is not enough memory remaining to satisfy the request, then NULL is returned.
607 If Buffer is NULL, then ASSERT().
608 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
610 @param AllocationSize The number of bytes to allocate and zero.
611 @param Buffer The buffer to copy to the allocated buffer.
613 @return A pointer to the allocated buffer or NULL if allocation fails.
618 AllocateRuntimeCopyPool (
619 IN UINTN AllocationSize
,
620 IN CONST VOID
*Buffer
623 return InternalAllocateCopyPool (EfiRuntimeServicesData
, AllocationSize
, Buffer
);
627 Copies a buffer to an allocated buffer of type EfiReservedMemoryType.
629 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies
630 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
631 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
632 is not enough memory remaining to satisfy the request, then NULL is returned.
634 If Buffer is NULL, then ASSERT().
635 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
637 @param AllocationSize The number of bytes to allocate and zero.
638 @param Buffer The buffer to copy to the allocated buffer.
640 @return A pointer to the allocated buffer or NULL if allocation fails.
645 AllocateReservedCopyPool (
646 IN UINTN AllocationSize
,
647 IN CONST VOID
*Buffer
650 return InternalAllocateCopyPool (EfiReservedMemoryType
, AllocationSize
, Buffer
);
654 Reallocates a buffer of a specified memory type.
656 Allocates and zeros the number bytes specified by NewSize from memory of the type
657 specified by PoolType. If OldBuffer is not NULL, then the smaller of OldSize and
658 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
659 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
660 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
661 enough memory remaining to satisfy the request, then NULL is returned.
663 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
664 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
666 @param PoolType The type of pool to allocate.
667 @param OldSize The size, in bytes, of OldBuffer.
668 @param NewSize The size, in bytes, of the buffer to reallocate.
669 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
670 parameter that may be NULL.
672 @return A pointer to the allocated buffer or NULL if allocation fails.
676 InternalReallocatePool (
677 IN EFI_MEMORY_TYPE PoolType
,
680 IN VOID
*OldBuffer OPTIONAL
685 NewBuffer
= InternalAllocateZeroPool (PoolType
, NewSize
);
686 if (NewBuffer
!= NULL
&& OldBuffer
!= NULL
) {
687 CopyMem (NewBuffer
, OldBuffer
, MIN (OldSize
, NewSize
));
688 FreePool (OldBuffer
);
694 Reallocates a buffer of type EfiBootServicesData.
696 Allocates and zeros the number bytes specified by NewSize from memory of type
697 EfiBootServicesData. If OldBuffer is not NULL, then the smaller of OldSize and
698 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
699 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
700 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
701 enough memory remaining to satisfy the request, then NULL is returned.
703 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
704 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
706 @param OldSize The size, in bytes, of OldBuffer.
707 @param NewSize The size, in bytes, of the buffer to reallocate.
708 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
709 parameter that may be NULL.
711 @return A pointer to the allocated buffer or NULL if allocation fails.
719 IN VOID
*OldBuffer OPTIONAL
722 return InternalReallocatePool (EfiBootServicesData
, OldSize
, NewSize
, OldBuffer
);
726 Reallocates a buffer of type EfiRuntimeServicesData.
728 Allocates and zeros the number bytes specified by NewSize from memory of type
729 EfiRuntimeServicesData. If OldBuffer is not NULL, then the smaller of OldSize and
730 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
731 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
732 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
733 enough memory remaining to satisfy the request, then NULL is returned.
735 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
736 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
738 @param OldSize The size, in bytes, of OldBuffer.
739 @param NewSize The size, in bytes, of the buffer to reallocate.
740 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
741 parameter that may be NULL.
743 @return A pointer to the allocated buffer or NULL if allocation fails.
748 ReallocateRuntimePool (
751 IN VOID
*OldBuffer OPTIONAL
754 return InternalReallocatePool (EfiRuntimeServicesData
, OldSize
, NewSize
, OldBuffer
);
758 Reallocates a buffer of type EfiReservedMemoryType.
760 Allocates and zeros the number bytes specified by NewSize from memory of type
761 EfiReservedMemoryType. If OldBuffer is not NULL, then the smaller of OldSize and
762 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
763 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
764 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
765 enough memory remaining to satisfy the request, then NULL is returned.
767 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
768 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
770 @param OldSize The size, in bytes, of OldBuffer.
771 @param NewSize The size, in bytes, of the buffer to reallocate.
772 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
773 parameter that may be NULL.
775 @return A pointer to the allocated buffer or NULL if allocation fails.
780 ReallocateReservedPool (
783 IN VOID
*OldBuffer OPTIONAL
786 return InternalReallocatePool (EfiReservedMemoryType
, OldSize
, NewSize
, OldBuffer
);
790 Frees a buffer that was previously allocated with one of the pool allocation functions in the
791 Memory Allocation Library.
793 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
794 pool allocation services of the Memory Allocation Library. If it is not possible to free pool
795 resources, then this function will perform no actions.
797 If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,
800 @param Buffer The pointer to the buffer to free.
811 if (!gEmuThunk
->Free (Buffer
)) {
812 // The Free thunk will not free memory allocated in emulated EFI memory.
813 // The assmuption is this was allocated directly by EFI. We need this as some
814 // times protocols or EFI BootServices can return dynamically allocated buffers.
815 Status
= gBS
->FreePool (Buffer
);
816 ASSERT_EFI_ERROR (Status
);