2 Support routines for memory allocation routines
3 based on PeiService for PEI phase drivers.
5 Copyright (c) 2006 - 2017, 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
;
53 Status
= PeiServicesAllocatePages (MemoryType
, Pages
, &Memory
);
54 if (EFI_ERROR (Status
)) {
58 return (VOID
*) (UINTN
) Memory
;
62 Allocates one or more 4KB pages of type EfiBootServicesData.
64 Allocates the number of 4KB pages of type EfiBootServicesData and returns a pointer to the
65 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
66 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
69 @param Pages The number of 4 KB pages to allocate.
71 @return A pointer to the allocated buffer or NULL if allocation fails.
80 return InternalAllocatePages (EfiBootServicesData
, Pages
);
84 Allocates one or more 4KB pages of type EfiRuntimeServicesData.
86 Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
87 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
88 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
91 @param Pages The number of 4 KB pages to allocate.
93 @return A pointer to the allocated buffer or NULL if allocation fails.
98 AllocateRuntimePages (
102 return InternalAllocatePages (EfiRuntimeServicesData
, Pages
);
106 Allocates one or more 4KB pages of type EfiReservedMemoryType.
108 Allocates the number of 4KB pages of type EfiReservedMemoryType and returns a pointer to the
109 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
110 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
113 @param Pages The number of 4 KB pages to allocate.
115 @return A pointer to the allocated buffer or NULL if allocation fails.
120 AllocateReservedPages (
124 return InternalAllocatePages (EfiReservedMemoryType
, Pages
);
128 Frees one or more 4KB pages that were previously allocated with one of the page allocation
129 functions in the Memory Allocation Library.
131 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
132 must have been allocated on a previous call to the page allocation services of the Memory
133 Allocation Library. If it is not possible to free allocated pages, then this function will
136 If Buffer was not allocated with a page allocation function in the Memory Allocation Library,
138 If Pages is zero, then ASSERT().
140 @param Buffer The pointer to the buffer of pages to free.
141 @param Pages The number of 4 KB pages to free.
154 Status
= PeiServicesFreePages ((EFI_PHYSICAL_ADDRESS
) (UINTN
) Buffer
, Pages
);
155 ASSERT_EFI_ERROR (Status
);
159 Allocates one or more 4KB pages of a certain memory type at a specified alignment.
161 Allocates the number of 4KB pages specified by Pages of a certain memory type with an alignment
162 specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is returned.
163 If there is not enough memory at the specified alignment remaining to satisfy the request, then
165 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
166 If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, 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.
171 Must be a power of two.
172 If Alignment is zero, then byte alignment is used.
174 @return A pointer to the allocated buffer or NULL if allocation fails.
178 InternalAllocateAlignedPages (
179 IN EFI_MEMORY_TYPE MemoryType
,
185 EFI_PHYSICAL_ADDRESS Memory
;
188 UINTN UnalignedPages
;
192 // Alignment must be a power of two or zero.
194 ASSERT ((Alignment
& (Alignment
- 1)) == 0);
199 if (Alignment
> EFI_PAGE_SIZE
) {
201 // Calculate the total number of pages since alignment is larger than page size.
203 AlignmentMask
= Alignment
- 1;
204 RealPages
= Pages
+ EFI_SIZE_TO_PAGES (Alignment
);
206 // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.
208 ASSERT (RealPages
> Pages
);
210 Status
= PeiServicesAllocatePages (MemoryType
, RealPages
, &Memory
);
211 if (EFI_ERROR (Status
)) {
214 AlignedMemory
= ((UINTN
) Memory
+ AlignmentMask
) & ~AlignmentMask
;
215 UnalignedPages
= EFI_SIZE_TO_PAGES (AlignedMemory
- (UINTN
) Memory
);
216 if (UnalignedPages
> 0) {
218 // Free first unaligned page(s).
220 Status
= PeiServicesFreePages (Memory
, UnalignedPages
);
221 ASSERT_EFI_ERROR (Status
);
223 Memory
= AlignedMemory
+ EFI_PAGES_TO_SIZE (Pages
);
224 UnalignedPages
= RealPages
- Pages
- UnalignedPages
;
225 if (UnalignedPages
> 0) {
227 // Free last unaligned page(s).
229 Status
= PeiServicesFreePages (Memory
, UnalignedPages
);
230 ASSERT_EFI_ERROR (Status
);
234 // Do not over-allocate pages in this case.
236 Status
= PeiServicesAllocatePages (MemoryType
, Pages
, &Memory
);
237 if (EFI_ERROR (Status
)) {
240 AlignedMemory
= (UINTN
) Memory
;
242 return (VOID
*) AlignedMemory
;
246 Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.
248 Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an
249 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
250 returned. If there is not enough memory at the specified alignment remaining to satisfy the
251 request, then NULL is returned.
253 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
254 If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().
256 @param Pages The number of 4 KB pages to allocate.
257 @param Alignment The requested alignment of the allocation.
258 Must be a power of two.
259 If Alignment is zero, then byte alignment is used.
261 @return A pointer to the allocated buffer or NULL if allocation fails.
266 AllocateAlignedPages (
271 return InternalAllocateAlignedPages (EfiBootServicesData
, Pages
, Alignment
);
275 Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment.
277 Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an
278 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
279 returned. If there is not enough memory at the specified alignment remaining to satisfy the
280 request, then NULL is returned.
282 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
283 If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().
285 @param Pages The number of 4 KB pages to allocate.
286 @param Alignment The requested alignment of the allocation.
287 Must be a power of two.
288 If Alignment is zero, then byte alignment is used.
290 @return A pointer to the allocated buffer or NULL if allocation fails.
295 AllocateAlignedRuntimePages (
300 return InternalAllocateAlignedPages (EfiRuntimeServicesData
, Pages
, Alignment
);
304 Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment.
306 Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an
307 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
308 returned. If there is not enough memory at the specified alignment remaining to satisfy the
309 request, then NULL is returned.
311 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
312 If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().
314 @param Pages The number of 4 KB pages to allocate.
315 @param Alignment The requested alignment of the allocation.
316 Must be a power of two.
317 If Alignment is zero, then byte alignment is used.
319 @return A pointer to the allocated buffer or NULL if allocation fails.
324 AllocateAlignedReservedPages (
329 return InternalAllocateAlignedPages (EfiReservedMemoryType
, Pages
, Alignment
);
333 Frees one or more 4KB pages that were previously allocated with one of the aligned page
334 allocation functions in the Memory Allocation Library.
336 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
337 must have been allocated on a previous call to the aligned page allocation services of the Memory
338 Allocation Library. If it is not possible to free allocated pages, then this function will
341 If Buffer was not allocated with an aligned page allocation function in the Memory Allocation
342 Library, then ASSERT().
343 If Pages is zero, then ASSERT().
345 @param Buffer The pointer to the buffer of pages to free.
346 @param Pages The number of 4 KB pages to free.
359 Status
= PeiServicesFreePages ((EFI_PHYSICAL_ADDRESS
) (UINTN
) Buffer
, Pages
);
360 ASSERT_EFI_ERROR (Status
);
364 Allocates a buffer of a certain pool type.
366 Allocates the number bytes specified by AllocationSize of a certain pool type and returns a
367 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
368 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
370 @param MemoryType The type of memory to allocate.
371 @param AllocationSize The number of bytes to allocate.
373 @return A pointer to the allocated buffer or NULL if allocation fails.
377 InternalAllocatePool (
378 IN EFI_MEMORY_TYPE MemoryType
,
379 IN UINTN AllocationSize
383 // If we need lots of small runtime/reserved memory type from PEI in the future,
384 // we can consider providing a more complex algorithm that allocates runtime pages and
385 // provide pool allocations from those pages.
387 return InternalAllocatePages (MemoryType
, EFI_SIZE_TO_PAGES (AllocationSize
));
391 Allocates a buffer of type EfiBootServicesData.
393 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a
394 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
395 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
397 @param AllocationSize The number of bytes to allocate.
399 @return A pointer to the allocated buffer or NULL if allocation fails.
405 IN UINTN AllocationSize
411 Status
= PeiServicesAllocatePool (AllocationSize
, &Buffer
);
412 if (EFI_ERROR (Status
)) {
419 Allocates a buffer of type EfiRuntimeServicesData.
421 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns
422 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
423 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
425 @param AllocationSize The number of bytes to allocate.
427 @return A pointer to the allocated buffer or NULL if allocation fails.
432 AllocateRuntimePool (
433 IN UINTN AllocationSize
436 return InternalAllocatePool (EfiRuntimeServicesData
, AllocationSize
);
440 Allocates a buffer of type EfiReservedMemoryType.
442 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType and returns
443 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
444 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
446 @param AllocationSize The number of bytes to allocate.
448 @return A pointer to the allocated buffer or NULL if allocation fails.
453 AllocateReservedPool (
454 IN UINTN AllocationSize
457 return InternalAllocatePool (EfiReservedMemoryType
, AllocationSize
);
461 Allocates and zeros a buffer of a certain pool type.
463 Allocates the number bytes specified by AllocationSize of a certain pool type, clears the buffer
464 with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a valid
465 buffer of 0 size is returned. If there is not enough memory remaining to satisfy the request,
466 then NULL is returned.
468 @param PoolType The type of memory to allocate.
469 @param AllocationSize The number of bytes to allocate and zero.
471 @return A pointer to the allocated buffer or NULL if allocation fails.
475 InternalAllocateZeroPool (
476 IN EFI_MEMORY_TYPE PoolType
,
477 IN UINTN AllocationSize
482 Memory
= InternalAllocatePool (PoolType
, AllocationSize
);
483 if (Memory
!= NULL
) {
484 Memory
= ZeroMem (Memory
, AllocationSize
);
490 Allocates and zeros a buffer of type EfiBootServicesData.
492 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the
493 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
494 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
495 request, then NULL is returned.
497 @param AllocationSize The number of bytes to allocate and zero.
499 @return A pointer to the allocated buffer or NULL if allocation fails.
505 IN UINTN AllocationSize
510 Memory
= AllocatePool (AllocationSize
);
511 if (Memory
!= NULL
) {
512 Memory
= ZeroMem (Memory
, AllocationSize
);
518 Allocates and zeros a buffer of type EfiRuntimeServicesData.
520 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the
521 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
522 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
523 request, then NULL is returned.
525 @param AllocationSize The number of bytes to allocate and zero.
527 @return A pointer to the allocated buffer or NULL if allocation fails.
532 AllocateRuntimeZeroPool (
533 IN UINTN AllocationSize
536 return InternalAllocateZeroPool (EfiRuntimeServicesData
, AllocationSize
);
540 Allocates and zeros a buffer of type EfiReservedMemoryType.
542 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the
543 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
544 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
545 request, then NULL is returned.
547 @param AllocationSize The number of bytes to allocate and zero.
549 @return A pointer to the allocated buffer or NULL if allocation fails.
554 AllocateReservedZeroPool (
555 IN UINTN AllocationSize
558 return InternalAllocateZeroPool (EfiReservedMemoryType
, AllocationSize
);
562 Copies a buffer to an allocated buffer of a certain pool type.
564 Allocates the number bytes specified by AllocationSize of a certain pool type, copies
565 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
566 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
567 is not enough memory remaining to satisfy the request, then NULL is returned.
568 If Buffer is NULL, then ASSERT().
569 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
571 @param PoolType The type of pool to allocate.
572 @param AllocationSize The number of bytes to allocate and zero.
573 @param Buffer The buffer to copy to the allocated buffer.
575 @return A pointer to the allocated buffer or NULL if allocation fails.
579 InternalAllocateCopyPool (
580 IN EFI_MEMORY_TYPE PoolType
,
581 IN UINTN AllocationSize
,
582 IN CONST VOID
*Buffer
587 ASSERT (Buffer
!= NULL
);
588 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
590 Memory
= InternalAllocatePool (PoolType
, AllocationSize
);
591 if (Memory
!= NULL
) {
592 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
598 Copies a buffer to an allocated buffer of type EfiBootServicesData.
600 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies
601 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
602 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
603 is not enough memory remaining to satisfy the request, then NULL is returned.
605 If Buffer is NULL, then ASSERT().
606 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
608 @param AllocationSize The number of bytes to allocate and zero.
609 @param Buffer The buffer to copy to the allocated buffer.
611 @return A pointer to the allocated buffer or NULL if allocation fails.
617 IN UINTN AllocationSize
,
618 IN CONST VOID
*Buffer
623 ASSERT (Buffer
!= NULL
);
624 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
626 Memory
= AllocatePool (AllocationSize
);
627 if (Memory
!= NULL
) {
628 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
634 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.
636 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies
637 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
638 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
639 is not enough memory remaining to satisfy the request, then NULL is returned.
641 If Buffer is NULL, then ASSERT().
642 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
644 @param AllocationSize The number of bytes to allocate and zero.
645 @param Buffer The buffer to copy to the allocated buffer.
647 @return A pointer to the allocated buffer or NULL if allocation fails.
652 AllocateRuntimeCopyPool (
653 IN UINTN AllocationSize
,
654 IN CONST VOID
*Buffer
657 return InternalAllocateCopyPool (EfiRuntimeServicesData
, AllocationSize
, Buffer
);
661 Copies a buffer to an allocated buffer of type EfiReservedMemoryType.
663 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies
664 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
665 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
666 is not enough memory remaining to satisfy the request, then NULL is returned.
668 If Buffer is NULL, then ASSERT().
669 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
671 @param AllocationSize The number of bytes to allocate and zero.
672 @param Buffer The buffer to copy to the allocated buffer.
674 @return A pointer to the allocated buffer or NULL if allocation fails.
679 AllocateReservedCopyPool (
680 IN UINTN AllocationSize
,
681 IN CONST VOID
*Buffer
684 return InternalAllocateCopyPool (EfiReservedMemoryType
, AllocationSize
, Buffer
);
688 Reallocates a buffer of a specified memory type.
690 Allocates and zeros the number bytes specified by NewSize from memory of the type
691 specified by PoolType. 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 PoolType The type of pool to allocate.
701 @param OldSize The size, in bytes, of OldBuffer.
702 @param NewSize The size, in bytes, of the buffer to reallocate.
703 @param OldBuffer The buffer to copy to the allocated buffer. This is an
704 optional parameter that may be NULL.
706 @return A pointer to the allocated buffer or NULL if allocation fails.
710 InternalReallocatePool (
711 IN EFI_MEMORY_TYPE PoolType
,
714 IN VOID
*OldBuffer OPTIONAL
719 NewBuffer
= InternalAllocateZeroPool (PoolType
, NewSize
);
720 if (NewBuffer
!= NULL
&& OldBuffer
!= NULL
) {
721 CopyMem (NewBuffer
, OldBuffer
, MIN (OldSize
, NewSize
));
722 FreePool (OldBuffer
);
728 Reallocates a buffer of type EfiBootServicesData.
730 Allocates and zeros the number bytes specified by NewSize from memory of type
731 EfiBootServicesData. If OldBuffer is not NULL, then the smaller of OldSize and
732 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
733 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
734 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
735 enough memory remaining to satisfy the request, then NULL is returned.
737 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
738 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
740 @param OldSize The size, in bytes, of OldBuffer.
741 @param NewSize The size, in bytes, of the buffer to reallocate.
742 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
743 parameter that may be NULL.
745 @return A pointer to the allocated buffer or NULL if allocation fails.
753 IN VOID
*OldBuffer OPTIONAL
756 return InternalReallocatePool (EfiBootServicesData
, OldSize
, NewSize
, OldBuffer
);
760 Reallocates a buffer of type EfiRuntimeServicesData.
762 Allocates and zeros the number bytes specified by NewSize from memory of type
763 EfiRuntimeServicesData. If OldBuffer is not NULL, then the smaller of OldSize and
764 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
765 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
766 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
767 enough memory remaining to satisfy the request, then NULL is returned.
769 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
770 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
772 @param OldSize The size, in bytes, of OldBuffer.
773 @param NewSize The size, in bytes, of the buffer to reallocate.
774 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
775 parameter that may be NULL.
777 @return A pointer to the allocated buffer or NULL if allocation fails.
782 ReallocateRuntimePool (
785 IN VOID
*OldBuffer OPTIONAL
788 return InternalReallocatePool (EfiRuntimeServicesData
, OldSize
, NewSize
, OldBuffer
);
792 Reallocates a buffer of type EfiReservedMemoryType.
794 Allocates and zeros the number bytes specified by NewSize from memory of type
795 EfiReservedMemoryType. If OldBuffer is not NULL, then the smaller of OldSize and
796 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
797 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
798 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
799 enough memory remaining to satisfy the request, then NULL is returned.
801 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
802 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
804 @param OldSize The size, in bytes, of OldBuffer.
805 @param NewSize The size, in bytes, of the buffer to reallocate.
806 @param OldBuffer The buffer to copy to the allocated buffer. This is an
807 optional parameter that may be NULL.
809 @return A pointer to the allocated buffer or NULL if allocation fails.
814 ReallocateReservedPool (
817 IN VOID
*OldBuffer OPTIONAL
820 return InternalReallocatePool (EfiReservedMemoryType
, OldSize
, NewSize
, OldBuffer
);
824 Frees a buffer that was previously allocated with one of the pool allocation functions in the
825 Memory Allocation Library.
827 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
828 pool allocation services of the Memory Allocation Library. If it is not possible to free pool
829 resources, then this function will perform no actions.
831 If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,
834 @param Buffer The pointer to the buffer to free.
844 // PEI phase does not support to free pool, so leave it as NOP.