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 SPDX-License-Identifier: BSD-2-Clause-Patent
22 #include <Library/MemoryAllocationLib.h>
23 #include <Library/UefiBootServicesTableLib.h>
24 #include <Library/BaseMemoryLib.h>
25 #include <Library/DebugLib.h>
26 #include <Library/EmuThunkLib.h>
29 Allocates one or more 4KB pages of a certain memory type.
31 Allocates the number of 4KB pages of a certain memory type and returns a pointer to the allocated
32 buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL is returned.
33 If there is not enough memory remaining to satisfy the request, then NULL is returned.
35 @param MemoryType The type of memory to allocate.
36 @param Pages The number of 4 KB pages to allocate.
38 @return A pointer to the allocated buffer or NULL if allocation fails.
42 InternalAllocatePages (
43 IN EFI_MEMORY_TYPE MemoryType
,
48 EFI_PHYSICAL_ADDRESS Memory
;
54 return gEmuThunk
->Valloc (Pages
* EFI_PAGE_SIZE
);
58 Allocates one or more 4KB pages of type EfiBootServicesData.
60 Allocates the number of 4KB pages of type EfiBootServicesData and returns a pointer to the
61 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
62 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
65 @param Pages The number of 4 KB pages to allocate.
67 @return A pointer to the allocated buffer or NULL if allocation fails.
76 return InternalAllocatePages (EfiBootServicesData
, Pages
);
80 Allocates one or more 4KB pages of type EfiRuntimeServicesData.
82 Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
83 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
84 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
87 @param Pages The number of 4 KB pages to allocate.
89 @return A pointer to the allocated buffer or NULL if allocation fails.
94 AllocateRuntimePages (
98 return InternalAllocatePages (EfiRuntimeServicesData
, Pages
);
102 Allocates one or more 4KB pages of type EfiReservedMemoryType.
104 Allocates the number of 4KB pages of type EfiReservedMemoryType and returns a pointer to the
105 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
106 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
109 @param Pages The number of 4 KB pages to allocate.
111 @return A pointer to the allocated buffer or NULL if allocation fails.
116 AllocateReservedPages (
120 return InternalAllocatePages (EfiReservedMemoryType
, Pages
);
124 Frees one or more 4KB pages that were previously allocated with one of the page allocation
125 functions in the Memory Allocation Library.
127 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
128 must have been allocated on a previous call to the page allocation services of the Memory
129 Allocation Library. If it is not possible to free allocated pages, then this function will
132 If Buffer was not allocated with a page allocation function in the Memory Allocation Library,
134 If Pages is zero, then ASSERT().
136 @param Buffer The pointer to the buffer of pages to free.
137 @param Pages The number of 4 KB pages to free.
150 if (!gEmuThunk
->Free (Buffer
)) {
151 // The Free thunk will not free memory allocated in emulated EFI memory.
152 // The assmuption is this was allocated directly by EFI. We need this as some
153 // times protocols or EFI BootServices can return dynamically allocated buffers.
154 Status
= gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
) (UINTN
) Buffer
, Pages
);
155 ASSERT_EFI_ERROR (Status
);
160 Allocates one or more 4KB pages of a certain memory type at a specified alignment.
162 Allocates the number of 4KB pages specified by Pages of a certain memory type with an alignment
163 specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is returned.
164 If there is not enough memory at the specified alignment remaining to satisfy the request, then
166 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
168 @param MemoryType The type of memory to allocate.
169 @param Pages The number of 4 KB pages to allocate.
170 @param Alignment The requested alignment of the allocation. Must be a power of two.
171 If Alignment is zero, then byte alignment is used.
173 @return A pointer to the allocated buffer or NULL if allocation fails.
177 InternalAllocateAlignedPages (
178 IN EFI_MEMORY_TYPE MemoryType
,
187 UINTN UnalignedPages
;
191 // Alignment must be a power of two or zero.
193 ASSERT ((Alignment
& (Alignment
- 1)) == 0);
198 if (Alignment
> EFI_PAGE_SIZE
) {
200 // Caculate the total number of pages since alignment is larger than page size.
202 AlignmentMask
= Alignment
- 1;
203 RealPages
= Pages
+ EFI_SIZE_TO_PAGES (Alignment
);
205 // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.
207 ASSERT (RealPages
> Pages
);
209 Memory
= gEmuThunk
->Valloc (Pages
* EFI_PAGE_SIZE
);
210 if (Memory
!= NULL
) {
213 AlignedMemory
= ((UINTN
) Memory
+ AlignmentMask
) & ~AlignmentMask
;
214 UnalignedPages
= EFI_SIZE_TO_PAGES (AlignedMemory
- (UINTN
) Memory
);
215 if (UnalignedPages
> 0) {
217 // Free first unaligned page(s).
219 FreePages (Memory
, UnalignedPages
);
221 Memory
= (VOID
*) (AlignedMemory
+ EFI_PAGES_TO_SIZE (Pages
));
222 UnalignedPages
= RealPages
- Pages
- UnalignedPages
;
223 if (UnalignedPages
> 0) {
225 // Free last unaligned page(s).
227 FreePages (Memory
, UnalignedPages
);
231 // Do not over-allocate pages in this case.
233 Memory
= gEmuThunk
->Valloc (Pages
* EFI_PAGE_SIZE
);
234 if (Memory
!= NULL
) {
237 AlignedMemory
= (UINTN
) Memory
;
239 return (VOID
*) AlignedMemory
;
243 Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.
245 Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an
246 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
247 returned. If there is not enough memory at the specified alignment remaining to satisfy the
248 request, then NULL is returned.
250 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
252 @param Pages The number of 4 KB pages to allocate.
253 @param Alignment The requested alignment of the allocation. Must be a power of two.
254 If Alignment is zero, then byte alignment is used.
256 @return A pointer to the allocated buffer or NULL if allocation fails.
261 AllocateAlignedPages (
266 return InternalAllocateAlignedPages (EfiBootServicesData
, Pages
, Alignment
);
270 Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment.
272 Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an
273 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
274 returned. If there is not enough memory at the specified alignment remaining to satisfy the
275 request, then NULL is returned.
277 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
279 @param Pages The number of 4 KB pages to allocate.
280 @param Alignment The requested alignment of the allocation. Must be a power of two.
281 If Alignment is zero, then byte alignment is used.
283 @return A pointer to the allocated buffer or NULL if allocation fails.
288 AllocateAlignedRuntimePages (
293 return InternalAllocateAlignedPages (EfiRuntimeServicesData
, Pages
, Alignment
);
297 Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment.
299 Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an
300 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
301 returned. If there is not enough memory at the specified alignment remaining to satisfy the
302 request, then NULL is returned.
304 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
306 @param Pages The number of 4 KB pages to allocate.
307 @param Alignment The requested alignment of the allocation. Must be a power of two.
308 If Alignment is zero, then byte alignment is used.
310 @return A pointer to the allocated buffer or NULL if allocation fails.
315 AllocateAlignedReservedPages (
320 return InternalAllocateAlignedPages (EfiReservedMemoryType
, Pages
, Alignment
);
324 Frees one or more 4KB pages that were previously allocated with one of the aligned page
325 allocation functions in the Memory Allocation Library.
327 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
328 must have been allocated on a previous call to the aligned page allocation services of the Memory
329 Allocation Library. If it is not possible to free allocated pages, then this function will
332 If Buffer was not allocated with an aligned page allocation function in the Memory Allocation
333 Library, then ASSERT().
334 If Pages is zero, then ASSERT().
336 @param Buffer The pointer to the buffer of pages to free.
337 @param Pages The number of 4 KB pages to free.
347 FreePages (Buffer
, Pages
);
351 Allocates a buffer of a certain pool type.
353 Allocates the number bytes specified by AllocationSize of a certain pool type and returns a
354 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
355 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
357 @param MemoryType The type of memory to allocate.
358 @param AllocationSize The number of bytes to allocate.
360 @return A pointer to the allocated buffer or NULL if allocation fails.
364 InternalAllocatePool (
365 IN EFI_MEMORY_TYPE MemoryType
,
366 IN UINTN AllocationSize
369 return gEmuThunk
->Malloc (AllocationSize
);
373 Allocates a buffer of type EfiBootServicesData.
375 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a
376 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
377 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
379 @param AllocationSize The number of bytes to allocate.
381 @return A pointer to the allocated buffer or NULL if allocation fails.
387 IN UINTN AllocationSize
390 return InternalAllocatePool (EfiBootServicesData
, AllocationSize
);
394 Allocates a buffer of type EfiRuntimeServicesData.
396 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns
397 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
398 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
400 @param AllocationSize The number of bytes to allocate.
402 @return A pointer to the allocated buffer or NULL if allocation fails.
407 AllocateRuntimePool (
408 IN UINTN AllocationSize
411 return InternalAllocatePool (EfiRuntimeServicesData
, AllocationSize
);
415 Allocates a buffer of type EfiReservedMemoryType.
417 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType and returns
418 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
419 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
421 @param AllocationSize The number of bytes to allocate.
423 @return A pointer to the allocated buffer or NULL if allocation fails.
428 AllocateReservedPool (
429 IN UINTN AllocationSize
432 return InternalAllocatePool (EfiReservedMemoryType
, AllocationSize
);
436 Allocates and zeros a buffer of a certain pool type.
438 Allocates the number bytes specified by AllocationSize of a certain pool type, clears the buffer
439 with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a valid
440 buffer of 0 size is returned. If there is not enough memory remaining to satisfy the request,
441 then NULL is returned.
443 @param PoolType The type of memory to allocate.
444 @param AllocationSize The number of bytes to allocate and zero.
446 @return A pointer to the allocated buffer or NULL if allocation fails.
450 InternalAllocateZeroPool (
451 IN EFI_MEMORY_TYPE PoolType
,
452 IN UINTN AllocationSize
457 Memory
= InternalAllocatePool (PoolType
, AllocationSize
);
458 if (Memory
!= NULL
) {
459 Memory
= ZeroMem (Memory
, AllocationSize
);
465 Allocates and zeros a buffer of type EfiBootServicesData.
467 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the
468 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
469 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
470 request, then NULL is returned.
472 @param AllocationSize The number of bytes to allocate and zero.
474 @return A pointer to the allocated buffer or NULL if allocation fails.
480 IN UINTN AllocationSize
483 return InternalAllocateZeroPool (EfiBootServicesData
, AllocationSize
);
487 Allocates and zeros a buffer of type EfiRuntimeServicesData.
489 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the
490 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
491 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
492 request, then NULL is returned.
494 @param AllocationSize The number of bytes to allocate and zero.
496 @return A pointer to the allocated buffer or NULL if allocation fails.
501 AllocateRuntimeZeroPool (
502 IN UINTN AllocationSize
505 return InternalAllocateZeroPool (EfiRuntimeServicesData
, AllocationSize
);
509 Allocates and zeros a buffer of type EfiReservedMemoryType.
511 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the
512 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
513 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
514 request, then NULL is returned.
516 @param AllocationSize The number of bytes to allocate and zero.
518 @return A pointer to the allocated buffer or NULL if allocation fails.
523 AllocateReservedZeroPool (
524 IN UINTN AllocationSize
527 return InternalAllocateZeroPool (EfiReservedMemoryType
, AllocationSize
);
531 Copies a buffer to an allocated buffer of a certain pool type.
533 Allocates the number bytes specified by AllocationSize of a certain pool type, copies
534 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
535 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
536 is not enough memory remaining to satisfy the request, then NULL is returned.
537 If Buffer is NULL, then ASSERT().
538 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
540 @param PoolType The type of pool to allocate.
541 @param AllocationSize The number of bytes to allocate and zero.
542 @param Buffer The buffer to copy to the allocated buffer.
544 @return A pointer to the allocated buffer or NULL if allocation fails.
548 InternalAllocateCopyPool (
549 IN EFI_MEMORY_TYPE PoolType
,
550 IN UINTN AllocationSize
,
551 IN CONST VOID
*Buffer
556 ASSERT (Buffer
!= NULL
);
557 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
559 Memory
= InternalAllocatePool (PoolType
, AllocationSize
);
560 if (Memory
!= NULL
) {
561 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
567 Copies a buffer to an allocated buffer of type EfiBootServicesData.
569 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies
570 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
571 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
572 is not enough memory remaining to satisfy the request, then NULL is returned.
574 If Buffer is NULL, then ASSERT().
575 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
577 @param AllocationSize The number of bytes to allocate and zero.
578 @param Buffer The buffer to copy to the allocated buffer.
580 @return A pointer to the allocated buffer or NULL if allocation fails.
586 IN UINTN AllocationSize
,
587 IN CONST VOID
*Buffer
590 return InternalAllocateCopyPool (EfiBootServicesData
, AllocationSize
, Buffer
);
594 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.
596 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies
597 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
598 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
599 is not enough memory remaining to satisfy the request, then NULL is returned.
601 If Buffer is NULL, then ASSERT().
602 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
604 @param AllocationSize The number of bytes to allocate and zero.
605 @param Buffer The buffer to copy to the allocated buffer.
607 @return A pointer to the allocated buffer or NULL if allocation fails.
612 AllocateRuntimeCopyPool (
613 IN UINTN AllocationSize
,
614 IN CONST VOID
*Buffer
617 return InternalAllocateCopyPool (EfiRuntimeServicesData
, AllocationSize
, Buffer
);
621 Copies a buffer to an allocated buffer of type EfiReservedMemoryType.
623 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies
624 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
625 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
626 is not enough memory remaining to satisfy the request, then NULL is returned.
628 If Buffer is NULL, then ASSERT().
629 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
631 @param AllocationSize The number of bytes to allocate and zero.
632 @param Buffer The buffer to copy to the allocated buffer.
634 @return A pointer to the allocated buffer or NULL if allocation fails.
639 AllocateReservedCopyPool (
640 IN UINTN AllocationSize
,
641 IN CONST VOID
*Buffer
644 return InternalAllocateCopyPool (EfiReservedMemoryType
, AllocationSize
, Buffer
);
648 Reallocates a buffer of a specified memory type.
650 Allocates and zeros the number bytes specified by NewSize from memory of the type
651 specified by PoolType. If OldBuffer is not NULL, then the smaller of OldSize and
652 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
653 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
654 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
655 enough memory remaining to satisfy the request, then NULL is returned.
657 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
658 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
660 @param PoolType The type of pool to allocate.
661 @param OldSize The size, in bytes, of OldBuffer.
662 @param NewSize The size, in bytes, of the buffer to reallocate.
663 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
664 parameter that may be NULL.
666 @return A pointer to the allocated buffer or NULL if allocation fails.
670 InternalReallocatePool (
671 IN EFI_MEMORY_TYPE PoolType
,
674 IN VOID
*OldBuffer OPTIONAL
679 NewBuffer
= InternalAllocateZeroPool (PoolType
, NewSize
);
680 if (NewBuffer
!= NULL
&& OldBuffer
!= NULL
) {
681 CopyMem (NewBuffer
, OldBuffer
, MIN (OldSize
, NewSize
));
682 FreePool (OldBuffer
);
688 Reallocates a buffer of type EfiBootServicesData.
690 Allocates and zeros the number bytes specified by NewSize from memory of type
691 EfiBootServicesData. If OldBuffer is not NULL, then the smaller of OldSize and
692 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
693 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
694 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
695 enough memory remaining to satisfy the request, then NULL is returned.
697 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
698 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
700 @param OldSize The size, in bytes, of OldBuffer.
701 @param NewSize The size, in bytes, of the buffer to reallocate.
702 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
703 parameter that may be NULL.
705 @return A pointer to the allocated buffer or NULL if allocation fails.
713 IN VOID
*OldBuffer OPTIONAL
716 return InternalReallocatePool (EfiBootServicesData
, OldSize
, NewSize
, OldBuffer
);
720 Reallocates a buffer of type EfiRuntimeServicesData.
722 Allocates and zeros the number bytes specified by NewSize from memory of type
723 EfiRuntimeServicesData. If OldBuffer is not NULL, then the smaller of OldSize and
724 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
725 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
726 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
727 enough memory remaining to satisfy the request, then NULL is returned.
729 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
730 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
732 @param OldSize The size, in bytes, of OldBuffer.
733 @param NewSize The size, in bytes, of the buffer to reallocate.
734 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
735 parameter that may be NULL.
737 @return A pointer to the allocated buffer or NULL if allocation fails.
742 ReallocateRuntimePool (
745 IN VOID
*OldBuffer OPTIONAL
748 return InternalReallocatePool (EfiRuntimeServicesData
, OldSize
, NewSize
, OldBuffer
);
752 Reallocates a buffer of type EfiReservedMemoryType.
754 Allocates and zeros the number bytes specified by NewSize from memory of type
755 EfiReservedMemoryType. If OldBuffer is not NULL, then the smaller of OldSize and
756 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
757 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
758 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
759 enough memory remaining to satisfy the request, then NULL is returned.
761 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
762 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
764 @param OldSize The size, in bytes, of OldBuffer.
765 @param NewSize The size, in bytes, of the buffer to reallocate.
766 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
767 parameter that may be NULL.
769 @return A pointer to the allocated buffer or NULL if allocation fails.
774 ReallocateReservedPool (
777 IN VOID
*OldBuffer OPTIONAL
780 return InternalReallocatePool (EfiReservedMemoryType
, OldSize
, NewSize
, OldBuffer
);
784 Frees a buffer that was previously allocated with one of the pool allocation functions in the
785 Memory Allocation Library.
787 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
788 pool allocation services of the Memory Allocation Library. If it is not possible to free pool
789 resources, then this function will perform no actions.
791 If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,
794 @param Buffer The pointer to the buffer to free.
805 if (!gEmuThunk
->Free (Buffer
)) {
806 // The Free thunk will not free memory allocated in emulated EFI memory.
807 // The assmuption is this was allocated directly by EFI. We need this as some
808 // times protocols or EFI BootServices can return dynamically allocated buffers.
809 Status
= gBS
->FreePool (Buffer
);
810 ASSERT_EFI_ERROR (Status
);