mirror of https://github.com/acidanthera/audk.git
Ring3: Fixed line endings.
This commit is contained in:
parent
a615429b73
commit
a52d50a6ec
|
@ -2176,80 +2176,80 @@ Done:
|
|||
return Status;
|
||||
}
|
||||
|
||||
/**
|
||||
Internal function. Used by the pool functions to allocate pages
|
||||
to back pool allocation requests.
|
||||
|
||||
@param PoolType The type of memory for the new pool pages
|
||||
@param NoPages No of pages to allocate
|
||||
@param Granularity Bits to align.
|
||||
@param NeedGuard Flag to indicate Guard page is needed or not
|
||||
|
||||
@return The allocated memory, or NULL
|
||||
|
||||
**/
|
||||
VOID *
|
||||
CoreAllocatePoolPagesI (
|
||||
IN EFI_MEMORY_TYPE PoolType,
|
||||
IN UINTN NoPages,
|
||||
IN UINTN Granularity,
|
||||
IN BOOLEAN NeedGuard
|
||||
)
|
||||
{
|
||||
VOID *Buffer;
|
||||
EFI_STATUS Status;
|
||||
|
||||
Status = EfiAcquireLockOrFail (&gMemoryLock);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Buffer = CoreAllocatePoolPages (PoolType, NoPages, Granularity, NeedGuard);
|
||||
CoreReleaseMemoryLock ();
|
||||
|
||||
if (Buffer != NULL) {
|
||||
if (NeedGuard) {
|
||||
SetGuardForMemory ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, NoPages);
|
||||
}
|
||||
|
||||
ApplyMemoryProtectionPolicy (
|
||||
EfiConventionalMemory,
|
||||
PoolType,
|
||||
(EFI_PHYSICAL_ADDRESS)(UINTN)Buffer,
|
||||
EFI_PAGES_TO_SIZE (NoPages)
|
||||
);
|
||||
}
|
||||
|
||||
return Buffer;
|
||||
}
|
||||
/**
|
||||
Internal function. Used by the pool functions to allocate pages
|
||||
to back pool allocation requests.
|
||||
|
||||
/**
|
||||
Internal function. Frees pool pages allocated via CoreAllocatePoolPagesI().
|
||||
|
||||
@param PoolType The type of memory for the pool pages
|
||||
@param Memory The base address to free
|
||||
@param NoPages The number of pages to free
|
||||
|
||||
**/
|
||||
VOID
|
||||
CoreFreePoolPagesI (
|
||||
IN EFI_MEMORY_TYPE PoolType,
|
||||
IN EFI_PHYSICAL_ADDRESS Memory,
|
||||
IN UINTN NoPages
|
||||
)
|
||||
{
|
||||
CoreAcquireMemoryLock ();
|
||||
CoreFreePoolPages (Memory, NoPages);
|
||||
CoreReleaseMemoryLock ();
|
||||
|
||||
GuardFreedPagesChecked (Memory, NoPages);
|
||||
ApplyMemoryProtectionPolicy (
|
||||
PoolType,
|
||||
EfiConventionalMemory,
|
||||
(EFI_PHYSICAL_ADDRESS)(UINTN)Memory,
|
||||
EFI_PAGES_TO_SIZE (NoPages)
|
||||
);
|
||||
}
|
||||
@param PoolType The type of memory for the new pool pages
|
||||
@param NoPages No of pages to allocate
|
||||
@param Granularity Bits to align.
|
||||
@param NeedGuard Flag to indicate Guard page is needed or not
|
||||
|
||||
@return The allocated memory, or NULL
|
||||
|
||||
**/
|
||||
VOID *
|
||||
CoreAllocatePoolPagesI (
|
||||
IN EFI_MEMORY_TYPE PoolType,
|
||||
IN UINTN NoPages,
|
||||
IN UINTN Granularity,
|
||||
IN BOOLEAN NeedGuard
|
||||
)
|
||||
{
|
||||
VOID *Buffer;
|
||||
EFI_STATUS Status;
|
||||
|
||||
Status = EfiAcquireLockOrFail (&gMemoryLock);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Buffer = CoreAllocatePoolPages (PoolType, NoPages, Granularity, NeedGuard);
|
||||
CoreReleaseMemoryLock ();
|
||||
|
||||
if (Buffer != NULL) {
|
||||
if (NeedGuard) {
|
||||
SetGuardForMemory ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, NoPages);
|
||||
}
|
||||
|
||||
ApplyMemoryProtectionPolicy (
|
||||
EfiConventionalMemory,
|
||||
PoolType,
|
||||
(EFI_PHYSICAL_ADDRESS)(UINTN)Buffer,
|
||||
EFI_PAGES_TO_SIZE (NoPages)
|
||||
);
|
||||
}
|
||||
|
||||
return Buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
Internal function. Frees pool pages allocated via CoreAllocatePoolPagesI().
|
||||
|
||||
@param PoolType The type of memory for the pool pages
|
||||
@param Memory The base address to free
|
||||
@param NoPages The number of pages to free
|
||||
|
||||
**/
|
||||
VOID
|
||||
CoreFreePoolPagesI (
|
||||
IN EFI_MEMORY_TYPE PoolType,
|
||||
IN EFI_PHYSICAL_ADDRESS Memory,
|
||||
IN UINTN NoPages
|
||||
)
|
||||
{
|
||||
CoreAcquireMemoryLock ();
|
||||
CoreFreePoolPages (Memory, NoPages);
|
||||
CoreReleaseMemoryLock ();
|
||||
|
||||
GuardFreedPagesChecked (Memory, NoPages);
|
||||
ApplyMemoryProtectionPolicy (
|
||||
PoolType,
|
||||
EfiConventionalMemory,
|
||||
(EFI_PHYSICAL_ADDRESS)(UINTN)Memory,
|
||||
EFI_PAGES_TO_SIZE (NoPages)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
Internal function. Frees guarded pool pages.
|
||||
|
|
|
@ -1,201 +1,201 @@
|
|||
/** @file
|
||||
UEFI Memory pool management functions.
|
||||
|
||||
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#ifndef _MEMORY_POOL_LIB_H_
|
||||
#define _MEMORY_POOL_LIB_H_
|
||||
|
||||
#include <Library/UefiLib.h>
|
||||
|
||||
//
|
||||
// +---------------------------------------------------+
|
||||
// | 0..(EfiMaxMemoryType - 1) - Normal memory type |
|
||||
// +---------------------------------------------------+
|
||||
// | EfiMaxMemoryType..0x6FFFFFFF - Invalid |
|
||||
// +---------------------------------------------------+
|
||||
// | 0x70000000..0x7FFFFFFF - OEM reserved |
|
||||
// +---------------------------------------------------+
|
||||
// | 0x80000000..0xFFFFFFFF - OS reserved |
|
||||
// +---------------------------------------------------+
|
||||
//
|
||||
#define MEMORY_TYPE_OS_RESERVED_MIN 0x80000000
|
||||
#define MEMORY_TYPE_OS_RESERVED_MAX 0xFFFFFFFF
|
||||
#define MEMORY_TYPE_OEM_RESERVED_MIN 0x70000000
|
||||
#define MEMORY_TYPE_OEM_RESERVED_MAX 0x7FFFFFFF
|
||||
|
||||
//
|
||||
// Memory type to guard (matching the related PCD definition)
|
||||
//
|
||||
#define GUARD_HEAP_TYPE_PAGE BIT0
|
||||
#define GUARD_HEAP_TYPE_POOL BIT1
|
||||
#define GUARD_HEAP_TYPE_FREED BIT4
|
||||
#define GUARD_HEAP_TYPE_ALL \
|
||||
(GUARD_HEAP_TYPE_PAGE|GUARD_HEAP_TYPE_POOL|GUARD_HEAP_TYPE_FREED)
|
||||
|
||||
/**
|
||||
Called to initialize the pool.
|
||||
|
||||
**/
|
||||
VOID
|
||||
CoreInitializePool (
|
||||
VOID
|
||||
);
|
||||
|
||||
/**
|
||||
Allocate pool of a particular type.
|
||||
|
||||
@param PoolType Type of pool to allocate
|
||||
@param Size The amount of pool to allocate
|
||||
@param Buffer The address to return a pointer to the allocated
|
||||
pool
|
||||
|
||||
@retval EFI_INVALID_PARAMETER PoolType not valid or Buffer is NULL
|
||||
@retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
|
||||
@retval EFI_SUCCESS Pool successfully allocated.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
CoreInternalAllocatePool (
|
||||
IN EFI_MEMORY_TYPE PoolType,
|
||||
IN UINTN Size,
|
||||
OUT VOID **Buffer
|
||||
);
|
||||
|
||||
/**
|
||||
Allocate pool of a particular type.
|
||||
|
||||
@param PoolType Type of pool to allocate
|
||||
@param Size The amount of pool to allocate
|
||||
@param Buffer The address to return a pointer to the allocated
|
||||
pool
|
||||
|
||||
@retval EFI_INVALID_PARAMETER PoolType not valid or Buffer is NULL
|
||||
@retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
|
||||
@retval EFI_SUCCESS Pool successfully allocated.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
CoreAllocatePool (
|
||||
IN EFI_MEMORY_TYPE PoolType,
|
||||
IN UINTN Size,
|
||||
OUT VOID **Buffer
|
||||
);
|
||||
|
||||
/**
|
||||
Internal function to allocate pool of a particular type.
|
||||
Caller must have the memory lock held
|
||||
|
||||
@param PoolType Type of pool to allocate
|
||||
@param Size The amount of pool to allocate
|
||||
@param NeedGuard Flag to indicate Guard page is needed or not
|
||||
|
||||
@return The allocate pool, or NULL
|
||||
|
||||
**/
|
||||
VOID *
|
||||
CoreAllocatePoolI (
|
||||
IN EFI_MEMORY_TYPE PoolType,
|
||||
IN UINTN Size,
|
||||
IN BOOLEAN NeedGuard
|
||||
);
|
||||
|
||||
/**
|
||||
Frees pool.
|
||||
|
||||
@param Buffer The allocated pool entry to free
|
||||
@param PoolType Pointer to pool type
|
||||
|
||||
@retval EFI_INVALID_PARAMETER Buffer is not a valid value.
|
||||
@retval EFI_SUCCESS Pool successfully freed.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
CoreInternalFreePool (
|
||||
IN VOID *Buffer,
|
||||
OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Frees pool.
|
||||
|
||||
@param Buffer The allocated pool entry to free
|
||||
|
||||
@retval EFI_INVALID_PARAMETER Buffer is not a valid value.
|
||||
@retval EFI_SUCCESS Pool successfully freed.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
CoreFreePool (
|
||||
IN VOID *Buffer
|
||||
);
|
||||
|
||||
/**
|
||||
Internal function to free a pool entry.
|
||||
Caller must have the memory lock held
|
||||
|
||||
@param Buffer The allocated pool entry to free
|
||||
@param PoolType Pointer to pool type
|
||||
|
||||
@retval EFI_INVALID_PARAMETER Buffer not valid
|
||||
@retval EFI_SUCCESS Buffer successfully freed.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
CoreFreePoolI (
|
||||
IN VOID *Buffer,
|
||||
OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Check to see if the heap guard is enabled for page and/or pool allocation.
|
||||
|
||||
@param[in] GuardType Specify the sub-type(s) of Heap Guard.
|
||||
|
||||
@return TRUE/FALSE.
|
||||
**/
|
||||
BOOLEAN
|
||||
IsHeapGuardEnabled (
|
||||
UINT8 GuardType
|
||||
);
|
||||
|
||||
/**
|
||||
Check to see if the pool at the given address should be guarded or not.
|
||||
|
||||
@param[in] MemoryType Pool type to check.
|
||||
|
||||
|
||||
@return TRUE The given type of pool should be guarded.
|
||||
@return FALSE The given type of pool should not be guarded.
|
||||
**/
|
||||
BOOLEAN
|
||||
IsPoolTypeToGuard (
|
||||
IN EFI_MEMORY_TYPE MemoryType
|
||||
);
|
||||
|
||||
/**
|
||||
Check to see if the memory at the given address should be guarded or not.
|
||||
|
||||
@param[in] MemoryType Memory type to check.
|
||||
@param[in] AllocateType Allocation type to check.
|
||||
@param[in] PageOrPool Indicate a page allocation or pool allocation.
|
||||
|
||||
|
||||
@return TRUE The given type of memory should be guarded.
|
||||
@return FALSE The given type of memory should not be guarded.
|
||||
**/
|
||||
BOOLEAN
|
||||
IsMemoryTypeToGuard (
|
||||
IN EFI_MEMORY_TYPE MemoryType,
|
||||
IN EFI_ALLOCATE_TYPE AllocateType,
|
||||
IN UINT8 PageOrPool
|
||||
);
|
||||
|
||||
#endif
|
||||
/** @file
|
||||
UEFI Memory pool management functions.
|
||||
|
||||
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#ifndef _MEMORY_POOL_LIB_H_
|
||||
#define _MEMORY_POOL_LIB_H_
|
||||
|
||||
#include <Library/UefiLib.h>
|
||||
|
||||
//
|
||||
// +---------------------------------------------------+
|
||||
// | 0..(EfiMaxMemoryType - 1) - Normal memory type |
|
||||
// +---------------------------------------------------+
|
||||
// | EfiMaxMemoryType..0x6FFFFFFF - Invalid |
|
||||
// +---------------------------------------------------+
|
||||
// | 0x70000000..0x7FFFFFFF - OEM reserved |
|
||||
// +---------------------------------------------------+
|
||||
// | 0x80000000..0xFFFFFFFF - OS reserved |
|
||||
// +---------------------------------------------------+
|
||||
//
|
||||
#define MEMORY_TYPE_OS_RESERVED_MIN 0x80000000
|
||||
#define MEMORY_TYPE_OS_RESERVED_MAX 0xFFFFFFFF
|
||||
#define MEMORY_TYPE_OEM_RESERVED_MIN 0x70000000
|
||||
#define MEMORY_TYPE_OEM_RESERVED_MAX 0x7FFFFFFF
|
||||
|
||||
//
|
||||
// Memory type to guard (matching the related PCD definition)
|
||||
//
|
||||
#define GUARD_HEAP_TYPE_PAGE BIT0
|
||||
#define GUARD_HEAP_TYPE_POOL BIT1
|
||||
#define GUARD_HEAP_TYPE_FREED BIT4
|
||||
#define GUARD_HEAP_TYPE_ALL \
|
||||
(GUARD_HEAP_TYPE_PAGE|GUARD_HEAP_TYPE_POOL|GUARD_HEAP_TYPE_FREED)
|
||||
|
||||
/**
|
||||
Called to initialize the pool.
|
||||
|
||||
**/
|
||||
VOID
|
||||
CoreInitializePool (
|
||||
VOID
|
||||
);
|
||||
|
||||
/**
|
||||
Allocate pool of a particular type.
|
||||
|
||||
@param PoolType Type of pool to allocate
|
||||
@param Size The amount of pool to allocate
|
||||
@param Buffer The address to return a pointer to the allocated
|
||||
pool
|
||||
|
||||
@retval EFI_INVALID_PARAMETER PoolType not valid or Buffer is NULL
|
||||
@retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
|
||||
@retval EFI_SUCCESS Pool successfully allocated.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
CoreInternalAllocatePool (
|
||||
IN EFI_MEMORY_TYPE PoolType,
|
||||
IN UINTN Size,
|
||||
OUT VOID **Buffer
|
||||
);
|
||||
|
||||
/**
|
||||
Allocate pool of a particular type.
|
||||
|
||||
@param PoolType Type of pool to allocate
|
||||
@param Size The amount of pool to allocate
|
||||
@param Buffer The address to return a pointer to the allocated
|
||||
pool
|
||||
|
||||
@retval EFI_INVALID_PARAMETER PoolType not valid or Buffer is NULL
|
||||
@retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
|
||||
@retval EFI_SUCCESS Pool successfully allocated.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
CoreAllocatePool (
|
||||
IN EFI_MEMORY_TYPE PoolType,
|
||||
IN UINTN Size,
|
||||
OUT VOID **Buffer
|
||||
);
|
||||
|
||||
/**
|
||||
Internal function to allocate pool of a particular type.
|
||||
Caller must have the memory lock held
|
||||
|
||||
@param PoolType Type of pool to allocate
|
||||
@param Size The amount of pool to allocate
|
||||
@param NeedGuard Flag to indicate Guard page is needed or not
|
||||
|
||||
@return The allocate pool, or NULL
|
||||
|
||||
**/
|
||||
VOID *
|
||||
CoreAllocatePoolI (
|
||||
IN EFI_MEMORY_TYPE PoolType,
|
||||
IN UINTN Size,
|
||||
IN BOOLEAN NeedGuard
|
||||
);
|
||||
|
||||
/**
|
||||
Frees pool.
|
||||
|
||||
@param Buffer The allocated pool entry to free
|
||||
@param PoolType Pointer to pool type
|
||||
|
||||
@retval EFI_INVALID_PARAMETER Buffer is not a valid value.
|
||||
@retval EFI_SUCCESS Pool successfully freed.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
CoreInternalFreePool (
|
||||
IN VOID *Buffer,
|
||||
OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Frees pool.
|
||||
|
||||
@param Buffer The allocated pool entry to free
|
||||
|
||||
@retval EFI_INVALID_PARAMETER Buffer is not a valid value.
|
||||
@retval EFI_SUCCESS Pool successfully freed.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
CoreFreePool (
|
||||
IN VOID *Buffer
|
||||
);
|
||||
|
||||
/**
|
||||
Internal function to free a pool entry.
|
||||
Caller must have the memory lock held
|
||||
|
||||
@param Buffer The allocated pool entry to free
|
||||
@param PoolType Pointer to pool type
|
||||
|
||||
@retval EFI_INVALID_PARAMETER Buffer not valid
|
||||
@retval EFI_SUCCESS Buffer successfully freed.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
CoreFreePoolI (
|
||||
IN VOID *Buffer,
|
||||
OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Check to see if the heap guard is enabled for page and/or pool allocation.
|
||||
|
||||
@param[in] GuardType Specify the sub-type(s) of Heap Guard.
|
||||
|
||||
@return TRUE/FALSE.
|
||||
**/
|
||||
BOOLEAN
|
||||
IsHeapGuardEnabled (
|
||||
UINT8 GuardType
|
||||
);
|
||||
|
||||
/**
|
||||
Check to see if the pool at the given address should be guarded or not.
|
||||
|
||||
@param[in] MemoryType Pool type to check.
|
||||
|
||||
|
||||
@return TRUE The given type of pool should be guarded.
|
||||
@return FALSE The given type of pool should not be guarded.
|
||||
**/
|
||||
BOOLEAN
|
||||
IsPoolTypeToGuard (
|
||||
IN EFI_MEMORY_TYPE MemoryType
|
||||
);
|
||||
|
||||
/**
|
||||
Check to see if the memory at the given address should be guarded or not.
|
||||
|
||||
@param[in] MemoryType Memory type to check.
|
||||
@param[in] AllocateType Allocation type to check.
|
||||
@param[in] PageOrPool Indicate a page allocation or pool allocation.
|
||||
|
||||
|
||||
@return TRUE The given type of memory should be guarded.
|
||||
@return FALSE The given type of memory should not be guarded.
|
||||
**/
|
||||
BOOLEAN
|
||||
IsMemoryTypeToGuard (
|
||||
IN EFI_MEMORY_TYPE MemoryType,
|
||||
IN EFI_ALLOCATE_TYPE AllocateType,
|
||||
IN UINT8 PageOrPool
|
||||
);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,124 +1,124 @@
|
|||
/** @file
|
||||
DXE Core functions necessary for pool management functions.
|
||||
|
||||
Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#ifndef _INTERNAL_POOL_H_
|
||||
#define _INTERNAL_POOL_H_
|
||||
|
||||
extern BOOLEAN mOnGuarding;
|
||||
|
||||
/**
|
||||
Update memory profile information.
|
||||
|
||||
@param CallerAddress Address of caller who call Allocate or Free.
|
||||
@param Action This Allocate or Free action.
|
||||
@param MemoryType Memory type.
|
||||
EfiMaxMemoryType means the MemoryType is unknown.
|
||||
@param Size Buffer size.
|
||||
@param Buffer Buffer address.
|
||||
@param ActionString String for memory profile action.
|
||||
Only needed for user defined allocate action.
|
||||
|
||||
@return EFI_SUCCESS Memory profile is updated.
|
||||
@return EFI_UNSUPPORTED Memory profile is unsupported,
|
||||
or memory profile for the image is not required,
|
||||
or memory profile for the memory type is not required.
|
||||
@return EFI_ACCESS_DENIED It is during memory profile data getting.
|
||||
@return EFI_ABORTED Memory profile recording is not enabled.
|
||||
@return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.
|
||||
@return EFI_NOT_FOUND No matched allocate info found for free action.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
CoreUpdateProfile (
|
||||
IN EFI_PHYSICAL_ADDRESS CallerAddress,
|
||||
IN MEMORY_PROFILE_ACTION Action,
|
||||
IN EFI_MEMORY_TYPE MemoryType,
|
||||
IN UINTN Size, // Valid for AllocatePages/FreePages/AllocatePool
|
||||
IN VOID *Buffer,
|
||||
IN CHAR8 *ActionString OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Install MemoryAttributesTable on memory allocation.
|
||||
|
||||
@param[in] MemoryType EFI memory type.
|
||||
**/
|
||||
VOID
|
||||
InstallMemoryAttributesTableOnMemoryAllocation (
|
||||
IN EFI_MEMORY_TYPE MemoryType
|
||||
);
|
||||
|
||||
/**
|
||||
Internal function. Frees guarded pool pages.
|
||||
|
||||
@param PoolType The type of memory for the pool pages
|
||||
@param Memory The base address to free
|
||||
@param NoPages The number of pages to free
|
||||
|
||||
**/
|
||||
VOID
|
||||
CoreFreePoolPagesWithGuard (
|
||||
IN EFI_MEMORY_TYPE PoolType,
|
||||
IN EFI_PHYSICAL_ADDRESS Memory,
|
||||
IN UINTN NoPages
|
||||
);
|
||||
|
||||
/**
|
||||
Check to see if the page at the given address is guarded or not.
|
||||
|
||||
@param[in] Address The address to check for.
|
||||
|
||||
@return TRUE The page at Address is guarded.
|
||||
@return FALSE The page at Address is not guarded.
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
IsMemoryGuarded (
|
||||
IN EFI_PHYSICAL_ADDRESS Address
|
||||
);
|
||||
|
||||
/**
|
||||
Internal function. Used by the pool functions to allocate pages
|
||||
to back pool allocation requests.
|
||||
|
||||
@param PoolType The type of memory for the new pool pages
|
||||
@param NoPages No of pages to allocate
|
||||
@param Granularity Bits to align.
|
||||
@param NeedGuard Flag to indicate Guard page is needed or not
|
||||
|
||||
@return The allocated memory, or NULL
|
||||
|
||||
**/
|
||||
VOID *
|
||||
CoreAllocatePoolPagesI (
|
||||
IN EFI_MEMORY_TYPE PoolType,
|
||||
IN UINTN NoPages,
|
||||
IN UINTN Granularity,
|
||||
IN BOOLEAN NeedGuard
|
||||
);
|
||||
|
||||
/**
|
||||
Internal function. Frees pool pages allocated via CoreAllocatePoolPagesI().
|
||||
|
||||
@param PoolType The type of memory for the pool pages
|
||||
@param Memory The base address to free
|
||||
@param NoPages The number of pages to free
|
||||
|
||||
**/
|
||||
VOID
|
||||
CoreFreePoolPagesI (
|
||||
IN EFI_MEMORY_TYPE PoolType,
|
||||
IN EFI_PHYSICAL_ADDRESS Memory,
|
||||
IN UINTN NoPages
|
||||
);
|
||||
|
||||
#endif
|
||||
/** @file
|
||||
DXE Core functions necessary for pool management functions.
|
||||
|
||||
Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#ifndef _INTERNAL_POOL_H_
|
||||
#define _INTERNAL_POOL_H_
|
||||
|
||||
extern BOOLEAN mOnGuarding;
|
||||
|
||||
/**
|
||||
Update memory profile information.
|
||||
|
||||
@param CallerAddress Address of caller who call Allocate or Free.
|
||||
@param Action This Allocate or Free action.
|
||||
@param MemoryType Memory type.
|
||||
EfiMaxMemoryType means the MemoryType is unknown.
|
||||
@param Size Buffer size.
|
||||
@param Buffer Buffer address.
|
||||
@param ActionString String for memory profile action.
|
||||
Only needed for user defined allocate action.
|
||||
|
||||
@return EFI_SUCCESS Memory profile is updated.
|
||||
@return EFI_UNSUPPORTED Memory profile is unsupported,
|
||||
or memory profile for the image is not required,
|
||||
or memory profile for the memory type is not required.
|
||||
@return EFI_ACCESS_DENIED It is during memory profile data getting.
|
||||
@return EFI_ABORTED Memory profile recording is not enabled.
|
||||
@return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.
|
||||
@return EFI_NOT_FOUND No matched allocate info found for free action.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
CoreUpdateProfile (
|
||||
IN EFI_PHYSICAL_ADDRESS CallerAddress,
|
||||
IN MEMORY_PROFILE_ACTION Action,
|
||||
IN EFI_MEMORY_TYPE MemoryType,
|
||||
IN UINTN Size, // Valid for AllocatePages/FreePages/AllocatePool
|
||||
IN VOID *Buffer,
|
||||
IN CHAR8 *ActionString OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Install MemoryAttributesTable on memory allocation.
|
||||
|
||||
@param[in] MemoryType EFI memory type.
|
||||
**/
|
||||
VOID
|
||||
InstallMemoryAttributesTableOnMemoryAllocation (
|
||||
IN EFI_MEMORY_TYPE MemoryType
|
||||
);
|
||||
|
||||
/**
|
||||
Internal function. Frees guarded pool pages.
|
||||
|
||||
@param PoolType The type of memory for the pool pages
|
||||
@param Memory The base address to free
|
||||
@param NoPages The number of pages to free
|
||||
|
||||
**/
|
||||
VOID
|
||||
CoreFreePoolPagesWithGuard (
|
||||
IN EFI_MEMORY_TYPE PoolType,
|
||||
IN EFI_PHYSICAL_ADDRESS Memory,
|
||||
IN UINTN NoPages
|
||||
);
|
||||
|
||||
/**
|
||||
Check to see if the page at the given address is guarded or not.
|
||||
|
||||
@param[in] Address The address to check for.
|
||||
|
||||
@return TRUE The page at Address is guarded.
|
||||
@return FALSE The page at Address is not guarded.
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
IsMemoryGuarded (
|
||||
IN EFI_PHYSICAL_ADDRESS Address
|
||||
);
|
||||
|
||||
/**
|
||||
Internal function. Used by the pool functions to allocate pages
|
||||
to back pool allocation requests.
|
||||
|
||||
@param PoolType The type of memory for the new pool pages
|
||||
@param NoPages No of pages to allocate
|
||||
@param Granularity Bits to align.
|
||||
@param NeedGuard Flag to indicate Guard page is needed or not
|
||||
|
||||
@return The allocated memory, or NULL
|
||||
|
||||
**/
|
||||
VOID *
|
||||
CoreAllocatePoolPagesI (
|
||||
IN EFI_MEMORY_TYPE PoolType,
|
||||
IN UINTN NoPages,
|
||||
IN UINTN Granularity,
|
||||
IN BOOLEAN NeedGuard
|
||||
);
|
||||
|
||||
/**
|
||||
Internal function. Frees pool pages allocated via CoreAllocatePoolPagesI().
|
||||
|
||||
@param PoolType The type of memory for the pool pages
|
||||
@param Memory The base address to free
|
||||
@param NoPages The number of pages to free
|
||||
|
||||
**/
|
||||
VOID
|
||||
CoreFreePoolPagesI (
|
||||
IN EFI_MEMORY_TYPE PoolType,
|
||||
IN EFI_PHYSICAL_ADDRESS Memory,
|
||||
IN UINTN NoPages
|
||||
);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,40 +1,40 @@
|
|||
## @file
|
||||
# UEFI Memory pool management functions.
|
||||
#
|
||||
# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
#
|
||||
##
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010005
|
||||
BASE_NAME = MemoryPoolLib
|
||||
FILE_GUID = 084a3534-da19-435e-8eeb-be08237ed403
|
||||
MODULE_TYPE = DXE_DRIVER
|
||||
VERSION_STRING = 1.0
|
||||
LIBRARY_CLASS = MemoryPoolLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER
|
||||
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64 EBC
|
||||
#
|
||||
|
||||
[Sources]
|
||||
InternalPool.h
|
||||
Pool.c
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
BaseLib
|
||||
DebugLib
|
||||
PcdLib
|
||||
UefiBootServicesTableLib
|
||||
UefiLib
|
||||
|
||||
[Pcd]
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPageType ## CONSUMES
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPoolType ## CONSUMES
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPropertyMask ## CONSUMES
|
||||
## @file
|
||||
# UEFI Memory pool management functions.
|
||||
#
|
||||
# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
#
|
||||
##
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010005
|
||||
BASE_NAME = MemoryPoolLib
|
||||
FILE_GUID = 084a3534-da19-435e-8eeb-be08237ed403
|
||||
MODULE_TYPE = DXE_DRIVER
|
||||
VERSION_STRING = 1.0
|
||||
LIBRARY_CLASS = MemoryPoolLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER
|
||||
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64 EBC
|
||||
#
|
||||
|
||||
[Sources]
|
||||
InternalPool.h
|
||||
Pool.c
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
BaseLib
|
||||
DebugLib
|
||||
PcdLib
|
||||
UefiBootServicesTableLib
|
||||
UefiLib
|
||||
|
||||
[Pcd]
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPageType ## CONSUMES
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPoolType ## CONSUMES
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPropertyMask ## CONSUMES
|
||||
|
|
|
@ -841,90 +841,90 @@ CoreFreePoolI (
|
|||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
Check to see if the heap guard is enabled for page and/or pool allocation.
|
||||
|
||||
@param[in] GuardType Specify the sub-type(s) of Heap Guard.
|
||||
|
||||
@return TRUE/FALSE.
|
||||
**/
|
||||
BOOLEAN
|
||||
IsHeapGuardEnabled (
|
||||
UINT8 GuardType
|
||||
)
|
||||
{
|
||||
return IsMemoryTypeToGuard (EfiMaxMemoryType, AllocateAnyPages, GuardType);
|
||||
}
|
||||
|
||||
/**
|
||||
Check to see if the pool at the given address should be guarded or not.
|
||||
|
||||
@param[in] MemoryType Pool type to check.
|
||||
|
||||
|
||||
@return TRUE The given type of pool should be guarded.
|
||||
@return FALSE The given type of pool should not be guarded.
|
||||
**/
|
||||
BOOLEAN
|
||||
IsPoolTypeToGuard (
|
||||
IN EFI_MEMORY_TYPE MemoryType
|
||||
)
|
||||
{
|
||||
return IsMemoryTypeToGuard (
|
||||
MemoryType,
|
||||
AllocateAnyPages,
|
||||
GUARD_HEAP_TYPE_POOL
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
Check to see if the memory at the given address should be guarded or not.
|
||||
|
||||
@param[in] MemoryType Memory type to check.
|
||||
@param[in] AllocateType Allocation type to check.
|
||||
@param[in] PageOrPool Indicate a page allocation or pool allocation.
|
||||
|
||||
|
||||
@return TRUE The given type of memory should be guarded.
|
||||
@return FALSE The given type of memory should not be guarded.
|
||||
**/
|
||||
BOOLEAN
|
||||
IsMemoryTypeToGuard (
|
||||
IN EFI_MEMORY_TYPE MemoryType,
|
||||
IN EFI_ALLOCATE_TYPE AllocateType,
|
||||
IN UINT8 PageOrPool
|
||||
)
|
||||
{
|
||||
UINT64 TestBit;
|
||||
UINT64 ConfigBit;
|
||||
|
||||
if (AllocateType == AllocateAddress) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((PcdGet8 (PcdHeapGuardPropertyMask) & PageOrPool) == 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (PageOrPool == GUARD_HEAP_TYPE_POOL) {
|
||||
ConfigBit = PcdGet64 (PcdHeapGuardPoolType);
|
||||
} else if (PageOrPool == GUARD_HEAP_TYPE_PAGE) {
|
||||
ConfigBit = PcdGet64 (PcdHeapGuardPageType);
|
||||
} else {
|
||||
ConfigBit = (UINT64)-1;
|
||||
}
|
||||
|
||||
if ((UINT32)MemoryType >= MEMORY_TYPE_OS_RESERVED_MIN) {
|
||||
TestBit = BIT63;
|
||||
} else if ((UINT32)MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {
|
||||
TestBit = BIT62;
|
||||
} else if (MemoryType < EfiMaxMemoryType) {
|
||||
TestBit = LShiftU64 (1, MemoryType);
|
||||
} else if (MemoryType == EfiMaxMemoryType) {
|
||||
TestBit = (UINT64)-1;
|
||||
} else {
|
||||
TestBit = 0;
|
||||
}
|
||||
|
||||
return ((ConfigBit & TestBit) != 0);
|
||||
}
|
||||
/**
|
||||
Check to see if the heap guard is enabled for page and/or pool allocation.
|
||||
|
||||
@param[in] GuardType Specify the sub-type(s) of Heap Guard.
|
||||
|
||||
@return TRUE/FALSE.
|
||||
**/
|
||||
BOOLEAN
|
||||
IsHeapGuardEnabled (
|
||||
UINT8 GuardType
|
||||
)
|
||||
{
|
||||
return IsMemoryTypeToGuard (EfiMaxMemoryType, AllocateAnyPages, GuardType);
|
||||
}
|
||||
|
||||
/**
|
||||
Check to see if the pool at the given address should be guarded or not.
|
||||
|
||||
@param[in] MemoryType Pool type to check.
|
||||
|
||||
|
||||
@return TRUE The given type of pool should be guarded.
|
||||
@return FALSE The given type of pool should not be guarded.
|
||||
**/
|
||||
BOOLEAN
|
||||
IsPoolTypeToGuard (
|
||||
IN EFI_MEMORY_TYPE MemoryType
|
||||
)
|
||||
{
|
||||
return IsMemoryTypeToGuard (
|
||||
MemoryType,
|
||||
AllocateAnyPages,
|
||||
GUARD_HEAP_TYPE_POOL
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
Check to see if the memory at the given address should be guarded or not.
|
||||
|
||||
@param[in] MemoryType Memory type to check.
|
||||
@param[in] AllocateType Allocation type to check.
|
||||
@param[in] PageOrPool Indicate a page allocation or pool allocation.
|
||||
|
||||
|
||||
@return TRUE The given type of memory should be guarded.
|
||||
@return FALSE The given type of memory should not be guarded.
|
||||
**/
|
||||
BOOLEAN
|
||||
IsMemoryTypeToGuard (
|
||||
IN EFI_MEMORY_TYPE MemoryType,
|
||||
IN EFI_ALLOCATE_TYPE AllocateType,
|
||||
IN UINT8 PageOrPool
|
||||
)
|
||||
{
|
||||
UINT64 TestBit;
|
||||
UINT64 ConfigBit;
|
||||
|
||||
if (AllocateType == AllocateAddress) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((PcdGet8 (PcdHeapGuardPropertyMask) & PageOrPool) == 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (PageOrPool == GUARD_HEAP_TYPE_POOL) {
|
||||
ConfigBit = PcdGet64 (PcdHeapGuardPoolType);
|
||||
} else if (PageOrPool == GUARD_HEAP_TYPE_PAGE) {
|
||||
ConfigBit = PcdGet64 (PcdHeapGuardPageType);
|
||||
} else {
|
||||
ConfigBit = (UINT64)-1;
|
||||
}
|
||||
|
||||
if ((UINT32)MemoryType >= MEMORY_TYPE_OS_RESERVED_MIN) {
|
||||
TestBit = BIT63;
|
||||
} else if ((UINT32)MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {
|
||||
TestBit = BIT62;
|
||||
} else if (MemoryType < EfiMaxMemoryType) {
|
||||
TestBit = LShiftU64 (1, MemoryType);
|
||||
} else if (MemoryType == EfiMaxMemoryType) {
|
||||
TestBit = (UINT64)-1;
|
||||
} else {
|
||||
TestBit = 0;
|
||||
}
|
||||
|
||||
return ((ConfigBit & TestBit) != 0);
|
||||
}
|
||||
|
|
|
@ -108,10 +108,10 @@ typedef enum {
|
|||
/// by a corresponding call to the underlying isolation architecture.
|
||||
///
|
||||
EfiUnacceptedMemoryType,
|
||||
///
|
||||
/// Memory allocated for (by) Ring3 Images.
|
||||
///
|
||||
EfiRing3MemoryType,
|
||||
///
|
||||
/// Memory allocated for (by) Ring3 Images.
|
||||
///
|
||||
EfiRing3MemoryType,
|
||||
EfiMaxMemoryType
|
||||
} EFI_MEMORY_TYPE;
|
||||
|
||||
|
|
Loading…
Reference in New Issue