X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=EmulatorPkg%2FLibrary%2FGuardUefiMemoryAllocationLib%2FMemoryAllocationLib.c;h=d6e20d6f74e6afea884dd86f5c322411f5fe5a6c;hp=c457e7c213134df49e7041877c3569af3521682e;hb=d18d8a1d0e370f8ce6ccc2725f4170586d457e53;hpb=bb89ec1a7ec2f8d35033df9e47b3604925da3bd3 diff --git a/EmulatorPkg/Library/GuardUefiMemoryAllocationLib/MemoryAllocationLib.c b/EmulatorPkg/Library/GuardUefiMemoryAllocationLib/MemoryAllocationLib.c index c457e7c213..d6e20d6f74 100644 --- a/EmulatorPkg/Library/GuardUefiMemoryAllocationLib/MemoryAllocationLib.c +++ b/EmulatorPkg/Library/GuardUefiMemoryAllocationLib/MemoryAllocationLib.c @@ -1,23 +1,23 @@ /** @file - Support routines for memory allocation routines based + Support routines for memory allocation routines based on boot services for Dxe phase drivers using OS malloc. - - OS malloc is used so OS based malloc debugging tools can be used. - If a single driver links against this lib protocols from other - drivers, or EFI boot services can return a buffer that needs to - freed using the EFI scheme. This is why the gEmuThunk->Free () + + OS malloc is used so OS based malloc debugging tools can be used. + If a single driver links against this lib protocols from other + drivers, or EFI boot services can return a buffer that needs to + freed using the EFI scheme. This is why the gEmuThunk->Free () can detect if the memory rang is for EFI so the right free can be called. Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.
- Portions copyright (c) 2011, Apple Inc. 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. + Portions copyright (c) 2011, Apple Inc. 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. - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ @@ -46,12 +46,12 @@ **/ VOID * InternalAllocatePages ( - IN EFI_MEMORY_TYPE MemoryType, + IN EFI_MEMORY_TYPE MemoryType, IN UINTN Pages ) { EFI_STATUS Status; - EFI_PHYSICAL_ADDRESS Memory; + EFI_PHYSICAL_ADDRESS Memory; if (Pages == 0) { return NULL; @@ -134,11 +134,11 @@ AllocateReservedPages ( must have been allocated on a previous call to the page allocation services of the Memory 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 The pointer to the buffer of pages to free. @param Pages The number of 4 KB pages to free. @@ -155,7 +155,7 @@ FreePages ( ASSERT (Pages != 0); if (!gEmuThunk->Free (Buffer)) { // The Free thunk will not free memory allocated in emulated EFI memory. - // The assmuption is this was allocated directly by EFI. We need this as some + // The assmuption is this was allocated directly by EFI. We need this as some // times protocols or EFI BootServices can return dynamically allocated buffers. Status = gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages); ASSERT_EFI_ERROR (Status); @@ -181,7 +181,7 @@ FreePages ( **/ VOID * InternalAllocateAlignedPages ( - IN EFI_MEMORY_TYPE MemoryType, + IN EFI_MEMORY_TYPE MemoryType, IN UINTN Pages, IN UINTN Alignment ) @@ -197,7 +197,7 @@ InternalAllocateAlignedPages ( // Alignment must be a power of two or zero. // ASSERT ((Alignment & (Alignment - 1)) == 0); - + if (Pages == 0) { return NULL; } @@ -211,7 +211,7 @@ InternalAllocateAlignedPages ( // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow. // ASSERT (RealPages > Pages); - + Memory = gEmuThunk->Valloc (Pages * EFI_PAGE_SIZE); if (Memory != NULL) { return NULL; @@ -252,7 +252,7 @@ InternalAllocateAlignedPages ( alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is returned. If there is not enough memory at the specified alignment remaining to satisfy the request, then NULL is returned. - + If Alignment is not a power of two and Alignment is not zero, then ASSERT(). @param Pages The number of 4 KB pages to allocate. @@ -279,7 +279,7 @@ AllocateAlignedPages ( alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is returned. If there is not enough memory at the specified alignment remaining to satisfy the request, then NULL is returned. - + If Alignment is not a power of two and Alignment is not zero, then ASSERT(). @param Pages The number of 4 KB pages to allocate. @@ -306,7 +306,7 @@ AllocateAlignedRuntimePages ( alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is returned. If there is not enough memory at the specified alignment remaining to satisfy the request, then NULL is returned. - + If Alignment is not a power of two and Alignment is not zero, then ASSERT(). @param Pages The number of 4 KB pages to allocate. @@ -332,13 +332,13 @@ 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. If it is not possible to free allocated pages, then this function will + 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 The pointer to the buffer of pages to free. @param Pages The number of 4 KB pages to free. @@ -368,7 +368,7 @@ FreeAlignedPages ( **/ VOID * InternalAllocatePool ( - IN EFI_MEMORY_TYPE MemoryType, + IN EFI_MEMORY_TYPE MemoryType, IN UINTN AllocationSize ) { @@ -454,9 +454,9 @@ AllocateReservedPool ( **/ VOID * InternalAllocateZeroPool ( - IN EFI_MEMORY_TYPE PoolType, + IN EFI_MEMORY_TYPE PoolType, IN UINTN AllocationSize - ) + ) { VOID *Memory; @@ -541,7 +541,7 @@ AllocateReservedZeroPool ( 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. If Buffer is NULL, then ASSERT(). - If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). @param PoolType The type of pool to allocate. @param AllocationSize The number of bytes to allocate and zero. @@ -552,10 +552,10 @@ AllocateReservedZeroPool ( **/ VOID * InternalAllocateCopyPool ( - IN EFI_MEMORY_TYPE PoolType, + IN EFI_MEMORY_TYPE PoolType, IN UINTN AllocationSize, IN CONST VOID *Buffer - ) + ) { VOID *Memory; @@ -567,7 +567,7 @@ InternalAllocateCopyPool ( Memory = CopyMem (Memory, Buffer, AllocationSize); } return Memory; -} +} /** Copies a buffer to an allocated buffer of type EfiBootServicesData. @@ -576,9 +576,9 @@ InternalAllocateCopyPool ( 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. - + If Buffer is NULL, then ASSERT(). - If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). @param AllocationSize The number of bytes to allocate and zero. @param Buffer The buffer to copy to the allocated buffer. @@ -603,9 +603,9 @@ AllocateCopyPool ( 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. - + If Buffer is NULL, then ASSERT(). - If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). @param AllocationSize The number of bytes to allocate and zero. @param Buffer The buffer to copy to the allocated buffer. @@ -630,9 +630,9 @@ AllocateRuntimeCopyPool ( 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. - + If Buffer is NULL, then ASSERT(). - If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). @param AllocationSize The number of bytes to allocate and zero. @param Buffer The buffer to copy to the allocated buffer. @@ -654,19 +654,19 @@ AllocateReservedCopyPool ( Reallocates a buffer of a specified memory type. Allocates and zeros the number bytes specified by NewSize from memory of the type - specified by PoolType. If OldBuffer is not NULL, then the smaller of OldSize and - NewSize bytes are copied from OldBuffer to the newly allocated buffer, and - 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 + specified by PoolType. If OldBuffer is not NULL, then the smaller of OldSize and + NewSize bytes are copied from OldBuffer to the newly allocated buffer, and + 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 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. @param NewSize The size, in bytes, of the buffer to reallocate. - @param OldBuffer The buffer to copy to the allocated buffer. This is an optional + @param OldBuffer The buffer to copy to the allocated buffer. This is an optional parameter that may be NULL. @return A pointer to the allocated buffer or NULL if allocation fails. @@ -674,7 +674,7 @@ AllocateReservedCopyPool ( **/ VOID * InternalReallocatePool ( - IN EFI_MEMORY_TYPE PoolType, + IN EFI_MEMORY_TYPE PoolType, IN UINTN OldSize, IN UINTN NewSize, IN VOID *OldBuffer OPTIONAL @@ -694,18 +694,18 @@ InternalReallocatePool ( Reallocates a buffer of type EfiBootServicesData. Allocates and zeros the number bytes specified by NewSize from memory of type - EfiBootServicesData. If OldBuffer is not NULL, then the smaller of OldSize and - NewSize bytes are copied from OldBuffer to the newly allocated buffer, and - 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 + EfiBootServicesData. If OldBuffer is not NULL, then the smaller of OldSize and + NewSize bytes are copied from OldBuffer to the newly allocated buffer, and + 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 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. - @param OldBuffer The buffer to copy to the allocated buffer. This is an optional + @param OldBuffer The buffer to copy to the allocated buffer. This is an optional parameter that may be NULL. @return A pointer to the allocated buffer or NULL if allocation fails. @@ -726,10 +726,10 @@ ReallocatePool ( Reallocates a buffer of type EfiRuntimeServicesData. Allocates and zeros the number bytes specified by NewSize from memory of type - EfiRuntimeServicesData. If OldBuffer is not NULL, then the smaller of OldSize and - NewSize bytes are copied from OldBuffer to the newly allocated buffer, and - 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 + EfiRuntimeServicesData. If OldBuffer is not NULL, then the smaller of OldSize and + NewSize bytes are copied from OldBuffer to the newly allocated buffer, and + 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 the allocation of the new buffer is successful and the smaller of NewSize and OldSize @@ -737,7 +737,7 @@ ReallocatePool ( @param OldSize The size, in bytes, of OldBuffer. @param NewSize The size, in bytes, of the buffer to reallocate. - @param OldBuffer The buffer to copy to the allocated buffer. This is an optional + @param OldBuffer The buffer to copy to the allocated buffer. This is an optional parameter that may be NULL. @return A pointer to the allocated buffer or NULL if allocation fails. @@ -758,10 +758,10 @@ ReallocateRuntimePool ( Reallocates a buffer of type EfiReservedMemoryType. Allocates and zeros the number bytes specified by NewSize from memory of type - EfiReservedMemoryType. If OldBuffer is not NULL, then the smaller of OldSize and - NewSize bytes are copied from OldBuffer to the newly allocated buffer, and - 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 + EfiReservedMemoryType. If OldBuffer is not NULL, then the smaller of OldSize and + NewSize bytes are copied from OldBuffer to the newly allocated buffer, and + 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 the allocation of the new buffer is successful and the smaller of NewSize and OldSize @@ -769,7 +769,7 @@ ReallocateRuntimePool ( @param OldSize The size, in bytes, of OldBuffer. @param NewSize The size, in bytes, of the buffer to reallocate. - @param OldBuffer The buffer to copy to the allocated buffer. This is an optional + @param OldBuffer The buffer to copy to the allocated buffer. This is an optional parameter that may be NULL. @return A pointer to the allocated buffer or NULL if allocation fails. @@ -793,7 +793,7 @@ ReallocateReservedPool ( 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. 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(). @@ -810,7 +810,7 @@ FreePool ( if (!gEmuThunk->Free (Buffer)) { // The Free thunk will not free memory allocated in emulated EFI memory. - // The assmuption is this was allocated directly by EFI. We need this as some + // The assmuption is this was allocated directly by EFI. We need this as some // times protocols or EFI BootServices can return dynamically allocated buffers. Status = gBS->FreePool (Buffer); ASSERT_EFI_ERROR (Status);