X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdePkg%2FLibrary%2FPeiMemoryAllocationLib%2FMemoryAllocationLib.c;h=d4e3c228852344aea4f5003174fbb6bb3c885e27;hp=040e26a292d619b96d67f582ca249602d47119ae;hb=2fc59a003ed9104f9feebe0e418f2a04a50f3284;hpb=9638ba6d3f663ba64cb06193f22bc5c70356da64 diff --git a/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c b/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c index 040e26a292..d4e3c22885 100644 --- a/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c +++ b/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c @@ -2,11 +2,11 @@ Support routines for memory allocation routines based on PeiService for PEI phase drivers. - Copyright (c) 2006 - 2008, Intel Corporation
- All rights reserved. This program and the accompanying materials + Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.
+ This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php + http://opensource.org/licenses/bsd-license.php. THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. @@ -128,13 +128,14 @@ AllocateReservedPages ( Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer must have been allocated on a previous call to the page allocation services of the Memory - Allocation Library. + Allocation Library. If it is not possible to free allocated pages, then this function will + perform no actions. If Buffer was not allocated with a page allocation function in the Memory Allocation Library, then ASSERT(). If Pages is zero, then ASSERT(). - @param Buffer Pointer to the buffer of pages to free. + @param Buffer The pointer to the buffer of pages to free. @param Pages The number of 4 KB pages to free. **/ @@ -145,6 +146,7 @@ FreePages ( IN UINTN Pages ) { + ASSERT (Pages != 0); // // PEI phase does not support to free pages, so leave it as NOP. // @@ -288,13 +290,14 @@ AllocateAlignedReservedPages ( Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer must have been allocated on a previous call to the aligned page allocation services of the Memory - Allocation Library. + Allocation Library. If it is not possible to free allocated pages, then this function will + perform no actions. If Buffer was not allocated with an aligned page allocation function in the Memory Allocation Library, then ASSERT(). If Pages is zero, then ASSERT(). - @param Buffer Pointer to the buffer of pages to free. + @param Buffer The pointer to the buffer of pages to free. @param Pages The number of 4 KB pages to free. **/ @@ -305,6 +308,7 @@ FreeAlignedPages ( IN UINTN Pages ) { + ASSERT (Pages != 0); // // PEI phase does not support to free pages, so leave it as NOP. // @@ -408,9 +412,9 @@ AllocateReservedPool ( } /** - Allocates and zeros a buffer of a certian pool type. + Allocates and zeros a buffer of a certain pool type. - Allocates the number bytes specified by AllocationSize of a certian pool type, clears the buffer + Allocates the number bytes specified by AllocationSize of a certain pool type, clears the buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the request, then NULL is returned. @@ -509,9 +513,9 @@ AllocateReservedZeroPool ( } /** - Copies a buffer to an allocated buffer of a certian pool type. + Copies a buffer to an allocated buffer of a certain pool type. - Allocates the number bytes specified by AllocationSize of a certian pool type, copies + Allocates the number bytes specified by AllocationSize of a certain pool type, copies AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the request, then NULL is returned. @@ -644,9 +648,8 @@ AllocateReservedCopyPool ( If NewSize is 0, then a valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the request, then NULL is returned. - If OldBuffer is NULL, then ASSERT(). - If NewSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). - If OldSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If the allocation of the new buffer is successful and the smaller of NewSize and OldSize + is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT(). @param PoolType The type of pool to allocate. @param OldSize The size, in bytes, of OldBuffer. @@ -658,7 +661,6 @@ AllocateReservedCopyPool ( **/ VOID * -EFIAPI InternalReallocatePool ( IN EFI_MEMORY_TYPE PoolType, IN UINTN OldSize, @@ -668,7 +670,7 @@ InternalReallocatePool ( { VOID *NewBuffer; - NewBuffer = AllocateZeroPool (NewSize); + NewBuffer = InternalAllocateZeroPool (PoolType, NewSize); if (NewBuffer != NULL && OldBuffer != NULL) { CopyMem (NewBuffer, OldBuffer, MIN (OldSize, NewSize)); FreePool (OldBuffer); @@ -686,9 +688,8 @@ InternalReallocatePool ( If NewSize is 0, then a valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the request, then NULL is returned. - If OldBuffer is NULL, then ASSERT(). - If NewSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). - If OldSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If the allocation of the new buffer is successful and the smaller of NewSize and OldSize + is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT(). @param OldSize The size, in bytes, of OldBuffer. @param NewSize The size, in bytes, of the buffer to reallocate. @@ -719,9 +720,8 @@ ReallocatePool ( If NewSize is 0, then a valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the request, then NULL is returned. - If OldBuffer is NULL, then ASSERT(). - If NewSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). - If OldSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If the allocation of the new buffer is successful and the smaller of NewSize and OldSize + is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT(). @param OldSize The size, in bytes, of OldBuffer. @param NewSize The size, in bytes, of the buffer to reallocate. @@ -751,10 +751,9 @@ ReallocateRuntimePool ( OldBuffer is freed. A pointer to the newly allocated buffer is returned. If NewSize is 0, then a valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the request, then NULL is returned. - - If OldBuffer is NULL, then ASSERT(). - If NewSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). - If OldSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + + If the allocation of the new buffer is successful and the smaller of NewSize and OldSize + is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT(). @param OldSize The size, in bytes, of OldBuffer. @param NewSize The size, in bytes, of the buffer to reallocate. @@ -780,12 +779,13 @@ ReallocateReservedPool ( Memory Allocation Library. Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the - pool allocation services of the Memory Allocation Library. + pool allocation services of the Memory Allocation Library. If it is not possible to free pool + resources, then this function will perform no actions. If Buffer was not allocated with a pool allocation function in the Memory Allocation Library, then ASSERT(). - @param Buffer Pointer to the buffer to free. + @param Buffer The pointer to the buffer to free. **/ VOID