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.
158 Allocates one or more 4KB pages of a certain memory type at a specified alignment.
160 Allocates the number of 4KB pages specified by Pages of a certain memory type with an alignment
161 specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is returned.
162 If there is not enough memory at the specified alignment remaining to satisfy the request, then
164 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
166 @param MemoryType The type of memory to allocate.
167 @param Pages The number of 4 KB pages to allocate.
168 @param Alignment The requested alignment of the allocation. Must be a power of two.
169 If Alignment is zero, then byte alignment is used.
171 @return A pointer to the allocated buffer or NULL if allocation fails.
175 InternalAllocateAlignedPages (
176 IN EFI_MEMORY_TYPE MemoryType
,
184 UINTN UnalignedPages
;
188 // Alignment must be a power of two or zero.
190 ASSERT ((Alignment
& (Alignment
- 1)) == 0);
195 if (Alignment
> EFI_PAGE_SIZE
) {
197 // Caculate the total number of pages since alignment is larger than page size.
199 AlignmentMask
= Alignment
- 1;
200 RealPages
= Pages
+ EFI_SIZE_TO_PAGES (Alignment
);
202 // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.
204 ASSERT (RealPages
> Pages
);
206 Memory
= gEmuThunk
->Valloc (Pages
* EFI_PAGE_SIZE
);
207 if (Memory
!= NULL
) {
210 AlignedMemory
= ((UINTN
) Memory
+ AlignmentMask
) & ~AlignmentMask
;
211 UnalignedPages
= EFI_SIZE_TO_PAGES (AlignedMemory
- (UINTN
) Memory
);
212 if (UnalignedPages
> 0) {
214 // Free first unaligned page(s).
218 Memory
= (VOID
*) (AlignedMemory
+ EFI_PAGES_TO_SIZE (Pages
));
219 UnalignedPages
= RealPages
- Pages
- UnalignedPages
;
220 if (UnalignedPages
> 0) {
222 // Free last unaligned page(s).
228 // Do not over-allocate pages in this case.
230 Memory
= gEmuThunk
->Valloc (Pages
* EFI_PAGE_SIZE
);
231 if (Memory
!= NULL
) {
234 AlignedMemory
= (UINTN
) Memory
;
236 return (VOID
*) AlignedMemory
;
240 Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.
242 Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an
243 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
244 returned. If there is not enough memory at the specified alignment remaining to satisfy the
245 request, then NULL is returned.
247 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
249 @param Pages The number of 4 KB pages to allocate.
250 @param Alignment The requested alignment of the allocation. Must be a power of two.
251 If Alignment is zero, then byte alignment is used.
253 @return A pointer to the allocated buffer or NULL if allocation fails.
258 AllocateAlignedPages (
263 return InternalAllocateAlignedPages (EfiBootServicesData
, Pages
, Alignment
);
267 Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment.
269 Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an
270 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
271 returned. If there is not enough memory at the specified alignment remaining to satisfy the
272 request, then NULL is returned.
274 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
276 @param Pages The number of 4 KB pages to allocate.
277 @param Alignment The requested alignment of the allocation. Must be a power of two.
278 If Alignment is zero, then byte alignment is used.
280 @return A pointer to the allocated buffer or NULL if allocation fails.
285 AllocateAlignedRuntimePages (
290 return InternalAllocateAlignedPages (EfiRuntimeServicesData
, Pages
, Alignment
);
294 Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment.
296 Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an
297 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
298 returned. If there is not enough memory at the specified alignment remaining to satisfy the
299 request, then NULL is returned.
301 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
303 @param Pages The number of 4 KB pages to allocate.
304 @param Alignment The requested alignment of the allocation. Must be a power of two.
305 If Alignment is zero, then byte alignment is used.
307 @return A pointer to the allocated buffer or NULL if allocation fails.
312 AllocateAlignedReservedPages (
317 return InternalAllocateAlignedPages (EfiReservedMemoryType
, Pages
, Alignment
);
321 Frees one or more 4KB pages that were previously allocated with one of the aligned page
322 allocation functions in the Memory Allocation Library.
324 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
325 must have been allocated on a previous call to the aligned page allocation services of the Memory
326 Allocation Library. If it is not possible to free allocated pages, then this function will
329 If Buffer was not allocated with an aligned page allocation function in the Memory Allocation
330 Library, then ASSERT().
331 If Pages is zero, then ASSERT().
333 @param Buffer The pointer to the buffer of pages to free.
334 @param Pages The number of 4 KB pages to free.
350 Allocates a buffer of a certain pool type.
352 Allocates the number bytes specified by AllocationSize of a certain pool type and returns a
353 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
354 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
356 @param MemoryType The type of memory to allocate.
357 @param AllocationSize The number of bytes to allocate.
359 @return A pointer to the allocated buffer or NULL if allocation fails.
363 InternalAllocatePool (
364 IN EFI_MEMORY_TYPE MemoryType
,
365 IN UINTN AllocationSize
368 return gEmuThunk
->Malloc (AllocationSize
);
372 Allocates a buffer of type EfiBootServicesData.
374 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a
375 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
376 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
378 @param AllocationSize The number of bytes to allocate.
380 @return A pointer to the allocated buffer or NULL if allocation fails.
386 IN UINTN AllocationSize
389 return InternalAllocatePool (EfiBootServicesData
, AllocationSize
);
393 Allocates a buffer of type EfiRuntimeServicesData.
395 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns
396 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
397 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
399 @param AllocationSize The number of bytes to allocate.
401 @return A pointer to the allocated buffer or NULL if allocation fails.
406 AllocateRuntimePool (
407 IN UINTN AllocationSize
410 return InternalAllocatePool (EfiRuntimeServicesData
, AllocationSize
);
414 Allocates a buffer of type EfiReservedMemoryType.
416 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType and returns
417 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
418 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
420 @param AllocationSize The number of bytes to allocate.
422 @return A pointer to the allocated buffer or NULL if allocation fails.
427 AllocateReservedPool (
428 IN UINTN AllocationSize
431 return InternalAllocatePool (EfiReservedMemoryType
, AllocationSize
);
435 Allocates and zeros a buffer of a certain pool type.
437 Allocates the number bytes specified by AllocationSize of a certain pool type, clears the buffer
438 with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a valid
439 buffer of 0 size is returned. If there is not enough memory remaining to satisfy the request,
440 then NULL is returned.
442 @param PoolType The type of memory to allocate.
443 @param AllocationSize The number of bytes to allocate and zero.
445 @return A pointer to the allocated buffer or NULL if allocation fails.
449 InternalAllocateZeroPool (
450 IN EFI_MEMORY_TYPE PoolType
,
451 IN UINTN AllocationSize
456 Memory
= InternalAllocatePool (PoolType
, AllocationSize
);
457 if (Memory
!= NULL
) {
458 Memory
= ZeroMem (Memory
, AllocationSize
);
464 Allocates and zeros a buffer of type EfiBootServicesData.
466 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the
467 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
468 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
469 request, then NULL is returned.
471 @param AllocationSize The number of bytes to allocate and zero.
473 @return A pointer to the allocated buffer or NULL if allocation fails.
479 IN UINTN AllocationSize
482 return InternalAllocateZeroPool (EfiBootServicesData
, AllocationSize
);
486 Allocates and zeros a buffer of type EfiRuntimeServicesData.
488 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the
489 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
490 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
491 request, then NULL is returned.
493 @param AllocationSize The number of bytes to allocate and zero.
495 @return A pointer to the allocated buffer or NULL if allocation fails.
500 AllocateRuntimeZeroPool (
501 IN UINTN AllocationSize
504 return InternalAllocateZeroPool (EfiRuntimeServicesData
, AllocationSize
);
508 Allocates and zeros a buffer of type EfiReservedMemoryType.
510 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the
511 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
512 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
513 request, then NULL is returned.
515 @param AllocationSize The number of bytes to allocate and zero.
517 @return A pointer to the allocated buffer or NULL if allocation fails.
522 AllocateReservedZeroPool (
523 IN UINTN AllocationSize
526 return InternalAllocateZeroPool (EfiReservedMemoryType
, AllocationSize
);
530 Copies a buffer to an allocated buffer of a certain pool type.
532 Allocates the number bytes specified by AllocationSize of a certain pool type, copies
533 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
534 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
535 is not enough memory remaining to satisfy the request, then NULL is returned.
536 If Buffer is NULL, then ASSERT().
537 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
539 @param PoolType The type of pool to allocate.
540 @param AllocationSize The number of bytes to allocate and zero.
541 @param Buffer The buffer to copy to the allocated buffer.
543 @return A pointer to the allocated buffer or NULL if allocation fails.
547 InternalAllocateCopyPool (
548 IN EFI_MEMORY_TYPE PoolType
,
549 IN UINTN AllocationSize
,
550 IN CONST VOID
*Buffer
555 ASSERT (Buffer
!= NULL
);
556 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
558 Memory
= InternalAllocatePool (PoolType
, AllocationSize
);
559 if (Memory
!= NULL
) {
560 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
566 Copies a buffer to an allocated buffer of type EfiBootServicesData.
568 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies
569 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
570 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
571 is not enough memory remaining to satisfy the request, then NULL is returned.
573 If Buffer is NULL, then ASSERT().
574 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
576 @param AllocationSize The number of bytes to allocate and zero.
577 @param Buffer The buffer to copy to the allocated buffer.
579 @return A pointer to the allocated buffer or NULL if allocation fails.
585 IN UINTN AllocationSize
,
586 IN CONST VOID
*Buffer
589 return InternalAllocateCopyPool (EfiBootServicesData
, AllocationSize
, Buffer
);
593 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.
595 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies
596 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
597 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
598 is not enough memory remaining to satisfy the request, then NULL is returned.
600 If Buffer is NULL, then ASSERT().
601 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
603 @param AllocationSize The number of bytes to allocate and zero.
604 @param Buffer The buffer to copy to the allocated buffer.
606 @return A pointer to the allocated buffer or NULL if allocation fails.
611 AllocateRuntimeCopyPool (
612 IN UINTN AllocationSize
,
613 IN CONST VOID
*Buffer
616 return InternalAllocateCopyPool (EfiRuntimeServicesData
, AllocationSize
, Buffer
);
620 Copies a buffer to an allocated buffer of type EfiReservedMemoryType.
622 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies
623 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
624 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
625 is not enough memory remaining to satisfy the request, then NULL is returned.
627 If Buffer is NULL, then ASSERT().
628 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
630 @param AllocationSize The number of bytes to allocate and zero.
631 @param Buffer The buffer to copy to the allocated buffer.
633 @return A pointer to the allocated buffer or NULL if allocation fails.
638 AllocateReservedCopyPool (
639 IN UINTN AllocationSize
,
640 IN CONST VOID
*Buffer
643 return InternalAllocateCopyPool (EfiReservedMemoryType
, AllocationSize
, Buffer
);
647 Reallocates a buffer of a specified memory type.
649 Allocates and zeros the number bytes specified by NewSize from memory of the type
650 specified by PoolType. If OldBuffer is not NULL, then the smaller of OldSize and
651 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
652 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
653 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
654 enough memory remaining to satisfy the request, then NULL is returned.
656 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
657 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
659 @param PoolType The type of pool to allocate.
660 @param OldSize The size, in bytes, of OldBuffer.
661 @param NewSize The size, in bytes, of the buffer to reallocate.
662 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
663 parameter that may be NULL.
665 @return A pointer to the allocated buffer or NULL if allocation fails.
669 InternalReallocatePool (
670 IN EFI_MEMORY_TYPE PoolType
,
673 IN VOID
*OldBuffer OPTIONAL
678 NewBuffer
= InternalAllocateZeroPool (PoolType
, NewSize
);
679 if (NewBuffer
!= NULL
&& OldBuffer
!= NULL
) {
680 CopyMem (NewBuffer
, OldBuffer
, MIN (OldSize
, NewSize
));
681 FreePool (OldBuffer
);
687 Reallocates a buffer of type EfiBootServicesData.
689 Allocates and zeros the number bytes specified by NewSize from memory of type
690 EfiBootServicesData. If OldBuffer is not NULL, then the smaller of OldSize and
691 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
692 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
693 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
694 enough memory remaining to satisfy the request, then NULL is returned.
696 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
697 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
699 @param OldSize The size, in bytes, of OldBuffer.
700 @param NewSize The size, in bytes, of the buffer to reallocate.
701 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
702 parameter that may be NULL.
704 @return A pointer to the allocated buffer or NULL if allocation fails.
712 IN VOID
*OldBuffer OPTIONAL
715 return InternalReallocatePool (EfiBootServicesData
, OldSize
, NewSize
, OldBuffer
);
719 Reallocates a buffer of type EfiRuntimeServicesData.
721 Allocates and zeros the number bytes specified by NewSize from memory of type
722 EfiRuntimeServicesData. If OldBuffer is not NULL, then the smaller of OldSize and
723 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
724 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
725 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
726 enough memory remaining to satisfy the request, then NULL is returned.
728 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
729 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
731 @param OldSize The size, in bytes, of OldBuffer.
732 @param NewSize The size, in bytes, of the buffer to reallocate.
733 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
734 parameter that may be NULL.
736 @return A pointer to the allocated buffer or NULL if allocation fails.
741 ReallocateRuntimePool (
744 IN VOID
*OldBuffer OPTIONAL
747 return InternalReallocatePool (EfiRuntimeServicesData
, OldSize
, NewSize
, OldBuffer
);
751 Reallocates a buffer of type EfiReservedMemoryType.
753 Allocates and zeros the number bytes specified by NewSize from memory of type
754 EfiReservedMemoryType. If OldBuffer is not NULL, then the smaller of OldSize and
755 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
756 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
757 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
758 enough memory remaining to satisfy the request, then NULL is returned.
760 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
761 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
763 @param OldSize The size, in bytes, of OldBuffer.
764 @param NewSize The size, in bytes, of the buffer to reallocate.
765 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
766 parameter that may be NULL.
768 @return A pointer to the allocated buffer or NULL if allocation fails.
773 ReallocateReservedPool (
776 IN VOID
*OldBuffer OPTIONAL
779 return InternalReallocatePool (EfiReservedMemoryType
, OldSize
, NewSize
, OldBuffer
);
783 Frees a buffer that was previously allocated with one of the pool allocation functions in the
784 Memory Allocation Library.
786 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
787 pool allocation services of the Memory Allocation Library. If it is not possible to free pool
788 resources, then this function will perform no actions.
790 If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,
793 @param Buffer The pointer to the buffer to free.
804 if (!gEmuThunk
->Free (Buffer
)) {
805 // The Free thunk will not free memory allocated in emulated EFI memory.
806 // The assmuption is this was allocated directly by EFI. We need this as some
807 // times protocols or EFI BootServices can return dynamically allocated buffers.
808 gBS
->FreePool (Buffer
);