2 Support routines for memory allocation routines
3 based on PeiService for PEI phase drivers.
5 Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #include <Library/MemoryAllocationLib.h>
21 #include <Library/PeiServicesLib.h>
22 #include <Library/BaseMemoryLib.h>
23 #include <Library/DebugLib.h>
24 #include <Library/HobLib.h>
28 Allocates one or more 4KB pages of a certain memory type.
30 Allocates the number of 4KB pages of a certain memory type and returns a pointer to the allocated
31 buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL is returned.
32 If there is not enough memory remaining to satisfy the request, then NULL is returned.
34 @param MemoryType The type of memory to allocate.
35 @param Pages The number of 4 KB pages to allocate.
37 @return A pointer to the allocated buffer or NULL if allocation fails.
41 InternalAllocatePages (
42 IN EFI_MEMORY_TYPE MemoryType
,
47 EFI_PHYSICAL_ADDRESS Memory
;
48 EFI_MEMORY_TYPE RequestType
;
49 EFI_PEI_HOB_POINTERS Hob
;
55 RequestType
= MemoryType
;
56 if (MemoryType
== EfiReservedMemoryType
) {
58 // PEI AllocatePages() doesn't support EfiReservedMemoryType.
59 // Change RequestType to EfiBootServicesData for memory allocation.
61 RequestType
= EfiBootServicesData
;
64 Status
= PeiServicesAllocatePages (RequestType
, Pages
, &Memory
);
65 if (EFI_ERROR (Status
)) {
69 if (MemoryType
== EfiReservedMemoryType
) {
71 // Memory type needs to be updated to EfiReservedMemoryType. Per PI spec Volume 1,
72 // PEI AllocatePages() will automate the creation of the Memory Allocation HOB types.
73 // Search Memory Allocation HOB and find the matched memory region,
74 // then change its memory type to EfiReservedMemoryType.
76 Hob
.Raw
= GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
);
77 while (Hob
.Raw
!= NULL
&& Hob
.MemoryAllocation
->AllocDescriptor
.MemoryBaseAddress
!= Memory
) {
78 Hob
.Raw
= GET_NEXT_HOB (Hob
);
79 Hob
.Raw
= GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, Hob
.Raw
);
81 ASSERT (Hob
.Raw
!= NULL
);
82 Hob
.MemoryAllocation
->AllocDescriptor
.MemoryType
= EfiReservedMemoryType
;
85 return (VOID
*) (UINTN
) Memory
;
89 Allocates one or more 4KB pages of type EfiBootServicesData.
91 Allocates the number of 4KB pages of type EfiBootServicesData and returns a pointer to the
92 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
93 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
96 @param Pages The number of 4 KB pages to allocate.
98 @return A pointer to the allocated buffer or NULL if allocation fails.
107 return InternalAllocatePages (EfiBootServicesData
, Pages
);
111 Allocates one or more 4KB pages of type EfiRuntimeServicesData.
113 Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
114 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
115 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
118 @param Pages The number of 4 KB pages to allocate.
120 @return A pointer to the allocated buffer or NULL if allocation fails.
125 AllocateRuntimePages (
129 return InternalAllocatePages (EfiRuntimeServicesData
, Pages
);
133 Allocates one or more 4KB pages of type EfiReservedMemoryType.
135 Allocates the number of 4KB pages of type EfiReservedMemoryType and returns a pointer to the
136 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
137 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
140 @param Pages The number of 4 KB pages to allocate.
142 @return A pointer to the allocated buffer or NULL if allocation fails.
147 AllocateReservedPages (
151 return InternalAllocatePages (EfiReservedMemoryType
, Pages
);
155 Frees one or more 4KB pages that were previously allocated with one of the page allocation
156 functions in the Memory Allocation Library.
158 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
159 must have been allocated on a previous call to the page allocation services of the Memory
160 Allocation Library. If it is not possible to free allocated pages, then this function will
163 If Buffer was not allocated with a page allocation function in the Memory Allocation Library,
165 If Pages is zero, then ASSERT().
167 @param Buffer The pointer to the buffer of pages to free.
168 @param Pages The number of 4 KB pages to free.
180 // PEI phase does not support to free pages, so leave it as NOP.
185 Allocates one or more 4KB pages of a certain memory type at a specified alignment.
187 Allocates the number of 4KB pages specified by Pages of a certain memory type with an alignment
188 specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is returned.
189 If there is not enough memory at the specified alignment remaining to satisfy the request, then
191 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
192 If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().
194 @param MemoryType The type of memory to allocate.
195 @param Pages The number of 4 KB pages to allocate.
196 @param Alignment The requested alignment of the allocation.
197 Must be a power of two.
198 If Alignment is zero, then byte alignment is used.
200 @return A pointer to the allocated buffer or NULL if allocation fails.
204 InternalAllocateAlignedPages (
205 IN EFI_MEMORY_TYPE MemoryType
,
214 // Alignment must be a power of two or zero.
216 ASSERT ((Alignment
& (Alignment
- 1)) == 0);
222 // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.
224 ASSERT (Pages
<= (MAX_ADDRESS
- EFI_SIZE_TO_PAGES (Alignment
)));
226 // We would rather waste some memory to save PEI code size.
228 Memory
= InternalAllocatePages (MemoryType
, Pages
+ EFI_SIZE_TO_PAGES (Alignment
));
229 if (Alignment
== 0) {
230 AlignmentMask
= Alignment
;
232 AlignmentMask
= Alignment
- 1;
234 return (VOID
*) (UINTN
) (((UINTN
) Memory
+ AlignmentMask
) & ~AlignmentMask
);
238 Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.
240 Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an
241 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
242 returned. If there is not enough memory at the specified alignment remaining to satisfy the
243 request, then NULL is returned.
245 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
246 If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().
248 @param Pages The number of 4 KB pages to allocate.
249 @param Alignment The requested alignment of the allocation.
250 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().
275 If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().
277 @param Pages The number of 4 KB pages to allocate.
278 @param Alignment The requested alignment of the allocation.
279 Must be a power of two.
280 If Alignment is zero, then byte alignment is used.
282 @return A pointer to the allocated buffer or NULL if allocation fails.
287 AllocateAlignedRuntimePages (
292 return InternalAllocateAlignedPages (EfiRuntimeServicesData
, Pages
, Alignment
);
296 Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment.
298 Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an
299 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
300 returned. If there is not enough memory at the specified alignment remaining to satisfy the
301 request, then NULL is returned.
303 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
304 If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().
306 @param Pages The number of 4 KB pages to allocate.
307 @param Alignment The requested alignment of the allocation.
308 Must be a power of two.
309 If Alignment is zero, then byte alignment is used.
311 @return A pointer to the allocated buffer or NULL if allocation fails.
316 AllocateAlignedReservedPages (
321 return InternalAllocateAlignedPages (EfiReservedMemoryType
, Pages
, Alignment
);
325 Frees one or more 4KB pages that were previously allocated with one of the aligned page
326 allocation functions in the Memory Allocation Library.
328 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
329 must have been allocated on a previous call to the aligned page allocation services of the Memory
330 Allocation Library. If it is not possible to free allocated pages, then this function will
333 If Buffer was not allocated with an aligned page allocation function in the Memory Allocation
334 Library, then ASSERT().
335 If Pages is zero, then ASSERT().
337 @param Buffer The pointer to the buffer of pages to free.
338 @param Pages The number of 4 KB pages to free.
350 // PEI phase does not support to free pages, so leave it as NOP.
355 Allocates a buffer of a certain pool type.
357 Allocates the number bytes specified by AllocationSize of a certain pool type and returns a
358 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
359 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
361 @param MemoryType The type of memory to allocate.
362 @param AllocationSize The number of bytes to allocate.
364 @return A pointer to the allocated buffer or NULL if allocation fails.
368 InternalAllocatePool (
369 IN EFI_MEMORY_TYPE MemoryType
,
370 IN UINTN AllocationSize
374 // If we need lots of small runtime/reserved memory type from PEI in the future,
375 // we can consider providing a more complex algorithm that allocates runtime pages and
376 // provide pool allocations from those pages.
378 return InternalAllocatePages (MemoryType
, EFI_SIZE_TO_PAGES (AllocationSize
));
382 Allocates a buffer of type EfiBootServicesData.
384 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a
385 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
386 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
388 @param AllocationSize The number of bytes to allocate.
390 @return A pointer to the allocated buffer or NULL if allocation fails.
396 IN UINTN AllocationSize
402 Status
= PeiServicesAllocatePool (AllocationSize
, &Buffer
);
403 if (EFI_ERROR (Status
)) {
410 Allocates a buffer of type EfiRuntimeServicesData.
412 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns
413 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
414 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
416 @param AllocationSize The number of bytes to allocate.
418 @return A pointer to the allocated buffer or NULL if allocation fails.
423 AllocateRuntimePool (
424 IN UINTN AllocationSize
427 return InternalAllocatePool (EfiRuntimeServicesData
, AllocationSize
);
431 Allocates a buffer of type EfiReservedMemoryType.
433 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType and returns
434 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
435 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
437 @param AllocationSize The number of bytes to allocate.
439 @return A pointer to the allocated buffer or NULL if allocation fails.
444 AllocateReservedPool (
445 IN UINTN AllocationSize
448 return InternalAllocatePool (EfiReservedMemoryType
, AllocationSize
);
452 Allocates and zeros a buffer of a certain pool type.
454 Allocates the number bytes specified by AllocationSize of a certain pool type, clears the buffer
455 with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a valid
456 buffer of 0 size is returned. If there is not enough memory remaining to satisfy the request,
457 then NULL is returned.
459 @param PoolType The type of memory to allocate.
460 @param AllocationSize The number of bytes to allocate and zero.
462 @return A pointer to the allocated buffer or NULL if allocation fails.
466 InternalAllocateZeroPool (
467 IN EFI_MEMORY_TYPE PoolType
,
468 IN UINTN AllocationSize
473 Memory
= InternalAllocatePool (PoolType
, AllocationSize
);
474 if (Memory
!= NULL
) {
475 Memory
= ZeroMem (Memory
, AllocationSize
);
481 Allocates and zeros a buffer of type EfiBootServicesData.
483 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the
484 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
485 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
486 request, then NULL is returned.
488 @param AllocationSize The number of bytes to allocate and zero.
490 @return A pointer to the allocated buffer or NULL if allocation fails.
496 IN UINTN AllocationSize
501 Memory
= AllocatePool (AllocationSize
);
502 if (Memory
!= NULL
) {
503 Memory
= ZeroMem (Memory
, AllocationSize
);
509 Allocates and zeros a buffer of type EfiRuntimeServicesData.
511 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, 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 AllocateRuntimeZeroPool (
524 IN UINTN AllocationSize
527 return InternalAllocateZeroPool (EfiRuntimeServicesData
, AllocationSize
);
531 Allocates and zeros a buffer of type EfiReservedMemoryType.
533 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the
534 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
535 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
536 request, then NULL is returned.
538 @param AllocationSize The number of bytes to allocate and zero.
540 @return A pointer to the allocated buffer or NULL if allocation fails.
545 AllocateReservedZeroPool (
546 IN UINTN AllocationSize
549 return InternalAllocateZeroPool (EfiReservedMemoryType
, AllocationSize
);
553 Copies a buffer to an allocated buffer of a certain pool type.
555 Allocates the number bytes specified by AllocationSize of a certain pool type, copies
556 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
557 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
558 is not enough memory remaining to satisfy the request, then NULL is returned.
559 If Buffer is NULL, then ASSERT().
560 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
562 @param PoolType The type of pool to allocate.
563 @param AllocationSize The number of bytes to allocate and zero.
564 @param Buffer The buffer to copy to the allocated buffer.
566 @return A pointer to the allocated buffer or NULL if allocation fails.
570 InternalAllocateCopyPool (
571 IN EFI_MEMORY_TYPE PoolType
,
572 IN UINTN AllocationSize
,
573 IN CONST VOID
*Buffer
578 ASSERT (Buffer
!= NULL
);
579 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
581 Memory
= InternalAllocatePool (PoolType
, AllocationSize
);
582 if (Memory
!= NULL
) {
583 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
589 Copies a buffer to an allocated buffer of type EfiBootServicesData.
591 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies
592 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
593 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
594 is not enough memory remaining to satisfy the request, then NULL is returned.
596 If Buffer is NULL, then ASSERT().
597 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
599 @param AllocationSize The number of bytes to allocate and zero.
600 @param Buffer The buffer to copy to the allocated buffer.
602 @return A pointer to the allocated buffer or NULL if allocation fails.
608 IN UINTN AllocationSize
,
609 IN CONST VOID
*Buffer
614 ASSERT (Buffer
!= NULL
);
615 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
617 Memory
= AllocatePool (AllocationSize
);
618 if (Memory
!= NULL
) {
619 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
625 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.
627 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies
628 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
629 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
630 is not enough memory remaining to satisfy the request, then NULL is returned.
632 If Buffer is NULL, then ASSERT().
633 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
635 @param AllocationSize The number of bytes to allocate and zero.
636 @param Buffer The buffer to copy to the allocated buffer.
638 @return A pointer to the allocated buffer or NULL if allocation fails.
643 AllocateRuntimeCopyPool (
644 IN UINTN AllocationSize
,
645 IN CONST VOID
*Buffer
648 return InternalAllocateCopyPool (EfiRuntimeServicesData
, AllocationSize
, Buffer
);
652 Copies a buffer to an allocated buffer of type EfiReservedMemoryType.
654 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies
655 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
656 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
657 is not enough memory remaining to satisfy the request, then NULL is returned.
659 If Buffer is NULL, then ASSERT().
660 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
662 @param AllocationSize The number of bytes to allocate and zero.
663 @param Buffer The buffer to copy to the allocated buffer.
665 @return A pointer to the allocated buffer or NULL if allocation fails.
670 AllocateReservedCopyPool (
671 IN UINTN AllocationSize
,
672 IN CONST VOID
*Buffer
675 return InternalAllocateCopyPool (EfiReservedMemoryType
, AllocationSize
, Buffer
);
679 Reallocates a buffer of a specified memory type.
681 Allocates and zeros the number bytes specified by NewSize from memory of the type
682 specified by PoolType. If OldBuffer is not NULL, then the smaller of OldSize and
683 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
684 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
685 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
686 enough memory remaining to satisfy the request, then NULL is returned.
688 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
689 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
691 @param PoolType The type of pool to allocate.
692 @param OldSize The size, in bytes, of OldBuffer.
693 @param NewSize The size, in bytes, of the buffer to reallocate.
694 @param OldBuffer The buffer to copy to the allocated buffer. This is an
695 optional parameter that may be NULL.
697 @return A pointer to the allocated buffer or NULL if allocation fails.
701 InternalReallocatePool (
702 IN EFI_MEMORY_TYPE PoolType
,
705 IN VOID
*OldBuffer OPTIONAL
710 NewBuffer
= InternalAllocateZeroPool (PoolType
, NewSize
);
711 if (NewBuffer
!= NULL
&& OldBuffer
!= NULL
) {
712 CopyMem (NewBuffer
, OldBuffer
, MIN (OldSize
, NewSize
));
713 FreePool (OldBuffer
);
719 Reallocates a buffer of type EfiBootServicesData.
721 Allocates and zeros the number bytes specified by NewSize from memory of type
722 EfiBootServicesData. 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.
744 IN VOID
*OldBuffer OPTIONAL
747 return InternalReallocatePool (EfiBootServicesData
, OldSize
, NewSize
, OldBuffer
);
751 Reallocates a buffer of type EfiRuntimeServicesData.
753 Allocates and zeros the number bytes specified by NewSize from memory of type
754 EfiRuntimeServicesData. 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 ReallocateRuntimePool (
776 IN VOID
*OldBuffer OPTIONAL
779 return InternalReallocatePool (EfiRuntimeServicesData
, OldSize
, NewSize
, OldBuffer
);
783 Reallocates a buffer of type EfiReservedMemoryType.
785 Allocates and zeros the number bytes specified by NewSize from memory of type
786 EfiReservedMemoryType. If OldBuffer is not NULL, then the smaller of OldSize and
787 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
788 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
789 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
790 enough memory remaining to satisfy the request, then NULL is returned.
792 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
793 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
795 @param OldSize The size, in bytes, of OldBuffer.
796 @param NewSize The size, in bytes, of the buffer to reallocate.
797 @param OldBuffer The buffer to copy to the allocated buffer. This is an
798 optional parameter that may be NULL.
800 @return A pointer to the allocated buffer or NULL if allocation fails.
805 ReallocateReservedPool (
808 IN VOID
*OldBuffer OPTIONAL
811 return InternalReallocatePool (EfiReservedMemoryType
, OldSize
, NewSize
, OldBuffer
);
815 Frees a buffer that was previously allocated with one of the pool allocation functions in the
816 Memory Allocation Library.
818 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
819 pool allocation services of the Memory Allocation Library. If it is not possible to free pool
820 resources, then this function will perform no actions.
822 If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,
825 @param Buffer The pointer to the buffer to free.
835 // PEI phase does not support to free pool, so leave it as NOP.