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