-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UnitTestFrameworkPkg/MemoryAllocationLibPosix: Add allocate below add…
…ress Add HostMemoryAllocationBelowAddressLib class and implementation that uses OS specific services to perform pool and page allocations below a specified address in a host based unit test application execution environment. This library class is only required for mocking buffers that are assumed to be below a specific address by code under test. Signed-off-by: Michael D Kinney <[email protected]>
- Loading branch information
Showing
8 changed files
with
681 additions
and
1 deletion.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
UnitTestFrameworkPkg/Include/Library/HostMemoryAllocationBelowAddressLib.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** @file | ||
HostMemoryAllocationBelowAddressLib class | ||
Copyright (c) 2024, Intel Corporation. All rights reserved.<BR> | ||
SPDX-License-Identifier: BSD-2-Clause-Patent | ||
**/ | ||
|
||
#ifndef HOST_MEMORY_ALLOCATION_BELOW_ADDRESS_LIB_H_ | ||
|
||
/** | ||
Allocate memory below a specifies address. | ||
@param[in] MaximumAddress The address below which the memory allocation must | ||
be performed. | ||
@param[in] Length The size, in bytes, of the memory allocation. | ||
@retval !NULL Pointer to the allocated memory. | ||
@retval NULL The memory allocation failed. | ||
**/ | ||
VOID * | ||
EFIAPI | ||
HostAllocatePoolBelowAddress ( | ||
IN VOID *MaximumAddress, | ||
IN UINTN Length | ||
); | ||
|
||
/** | ||
Free memory allocated with AllocateMemoryHostAllocatePoolBelowAddress(). | ||
@param[in] Address Pointer to buffer previously allocated with | ||
HostAllocatePoolBelowAddress(). | ||
@retval TRUE The buffer was freed. | ||
@retval FALSE The buffer could not be freed.. | ||
**/ | ||
VOID | ||
EFIAPI | ||
HostFreePoolBelowAddress ( | ||
IN VOID *Address | ||
); | ||
|
||
/** | ||
Allocates one or more 4KB pages below a specified address at a specified | ||
alignment. | ||
Allocates the number of 4KB pages specified by Pages below MaximumAddress with | ||
an alignment specified by Alignment. The allocated buffer is returned. If | ||
Pages is 0, then NULL is returned. If there is not enough memory below the | ||
requested address 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(). | ||
If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT(). | ||
@param[in] MaximumAddress The address below which the memory allocation must | ||
@param[in] Pages The number of 4 KB pages to allocate. | ||
@param[in] Alignment The requested alignment of the allocation. Must be | ||
a power of two. If Alignment is zero, then byte | ||
alignment is used. | ||
@return A pointer to the allocated buffer or NULL if allocation fails. | ||
**/ | ||
VOID * | ||
EFIAPI | ||
HostAllocateAlignedPagesBelowAddress ( | ||
IN VOID *MaximumAddress, | ||
IN UINTN Pages, | ||
IN UINTN Alignment | ||
); | ||
|
||
/** | ||
Frees one or more 4KB pages that were previously allocated with | ||
HostAllocateAlignedPagesBelowAddress(). | ||
Frees the number of 4KB pages specified by Pages from the buffer specified by | ||
Buffer. Buffer must have been allocated with HostAllocateAlignedPagesBelowAddress(). | ||
If it is not possible to free allocated pages, then this function will perform | ||
no actions. | ||
If Buffer was not allocated with HostAllocateAlignedPagesBelowAddress(), then | ||
ASSERT(). If Pages is zero, then ASSERT(). | ||
@param[in] Buffer The pointer to the buffer of pages to free. | ||
@param[in] Pages The number of 4 KB pages to free. | ||
**/ | ||
VOID | ||
EFIAPI | ||
HostFreeAlignedPagesBelowAddress ( | ||
IN VOID *Buffer, | ||
IN UINTN Pages | ||
); | ||
|
||
#endif |
Oops, something went wrong.