summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Core/Dxe/Mem
diff options
context:
space:
mode:
Diffstat (limited to 'MdeModulePkg/Core/Dxe/Mem')
-rw-r--r--MdeModulePkg/Core/Dxe/Mem/HeapGuard.c621
-rw-r--r--MdeModulePkg/Core/Dxe/Mem/HeapGuard.h76
-rw-r--r--MdeModulePkg/Core/Dxe/Mem/Imem.h66
-rw-r--r--MdeModulePkg/Core/Dxe/Mem/MemData.c5
-rw-r--r--MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c611
-rw-r--r--MdeModulePkg/Core/Dxe/Mem/Page.c687
-rw-r--r--MdeModulePkg/Core/Dxe/Mem/Pool.c368
7 files changed, 1256 insertions, 1178 deletions
diff --git a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c
index b4cb488..9377f62 100644
--- a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c
+++ b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c
@@ -14,34 +14,34 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// Global to avoid infinite reentrance of memory allocation when updating
// page table attributes, which may need allocate pages for new PDE/PTE.
//
-GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mOnGuarding = FALSE;
+GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mOnGuarding = FALSE;
//
// Pointer to table tracking the Guarded memory with bitmap, in which '1'
// is used to indicate memory guarded. '0' might be free memory or Guard
// page itself, depending on status of memory adjacent to it.
//
-GLOBAL_REMOVE_IF_UNREFERENCED UINT64 mGuardedMemoryMap = 0;
+GLOBAL_REMOVE_IF_UNREFERENCED UINT64 mGuardedMemoryMap = 0;
//
// Current depth level of map table pointed by mGuardedMemoryMap.
// mMapLevel must be initialized at least by 1. It will be automatically
// updated according to the address of memory just tracked.
//
-GLOBAL_REMOVE_IF_UNREFERENCED UINTN mMapLevel = 1;
+GLOBAL_REMOVE_IF_UNREFERENCED UINTN mMapLevel = 1;
//
// Shift and mask for each level of map table
//
-GLOBAL_REMOVE_IF_UNREFERENCED UINTN mLevelShift[GUARDED_HEAP_MAP_TABLE_DEPTH]
- = GUARDED_HEAP_MAP_TABLE_DEPTH_SHIFTS;
-GLOBAL_REMOVE_IF_UNREFERENCED UINTN mLevelMask[GUARDED_HEAP_MAP_TABLE_DEPTH]
- = GUARDED_HEAP_MAP_TABLE_DEPTH_MASKS;
+GLOBAL_REMOVE_IF_UNREFERENCED UINTN mLevelShift[GUARDED_HEAP_MAP_TABLE_DEPTH]
+ = GUARDED_HEAP_MAP_TABLE_DEPTH_SHIFTS;
+GLOBAL_REMOVE_IF_UNREFERENCED UINTN mLevelMask[GUARDED_HEAP_MAP_TABLE_DEPTH]
+ = GUARDED_HEAP_MAP_TABLE_DEPTH_MASKS;
//
// Used for promoting freed but not used pages.
//
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_PHYSICAL_ADDRESS mLastPromotedPage = BASE_4GB;
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_PHYSICAL_ADDRESS mLastPromotedPage = BASE_4GB;
/**
Set corresponding bits in bitmap table to 1 according to the address.
@@ -55,29 +55,29 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_PHYSICAL_ADDRESS mLastPromotedPage = BASE_4GB;
STATIC
VOID
SetBits (
- IN EFI_PHYSICAL_ADDRESS Address,
- IN UINTN BitNumber,
- IN UINT64 *BitMap
+ IN EFI_PHYSICAL_ADDRESS Address,
+ IN UINTN BitNumber,
+ IN UINT64 *BitMap
)
{
- UINTN Lsbs;
- UINTN Qwords;
- UINTN Msbs;
- UINTN StartBit;
- UINTN EndBit;
+ UINTN Lsbs;
+ UINTN Qwords;
+ UINTN Msbs;
+ UINTN StartBit;
+ UINTN EndBit;
- StartBit = (UINTN)GUARDED_HEAP_MAP_ENTRY_BIT_INDEX (Address);
- EndBit = (StartBit + BitNumber - 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
+ StartBit = (UINTN)GUARDED_HEAP_MAP_ENTRY_BIT_INDEX (Address);
+ EndBit = (StartBit + BitNumber - 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
if ((StartBit + BitNumber) >= GUARDED_HEAP_MAP_ENTRY_BITS) {
- Msbs = (GUARDED_HEAP_MAP_ENTRY_BITS - StartBit) %
- GUARDED_HEAP_MAP_ENTRY_BITS;
- Lsbs = (EndBit + 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
- Qwords = (BitNumber - Msbs) / GUARDED_HEAP_MAP_ENTRY_BITS;
+ Msbs = (GUARDED_HEAP_MAP_ENTRY_BITS - StartBit) %
+ GUARDED_HEAP_MAP_ENTRY_BITS;
+ Lsbs = (EndBit + 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
+ Qwords = (BitNumber - Msbs) / GUARDED_HEAP_MAP_ENTRY_BITS;
} else {
- Msbs = BitNumber;
- Lsbs = 0;
- Qwords = 0;
+ Msbs = BitNumber;
+ Lsbs = 0;
+ Qwords = 0;
}
if (Msbs > 0) {
@@ -86,8 +86,11 @@ SetBits (
}
if (Qwords > 0) {
- SetMem64 ((VOID *)BitMap, Qwords * GUARDED_HEAP_MAP_ENTRY_BYTES,
- (UINT64)-1);
+ SetMem64 (
+ (VOID *)BitMap,
+ Qwords * GUARDED_HEAP_MAP_ENTRY_BYTES,
+ (UINT64)-1
+ );
BitMap += Qwords;
}
@@ -108,29 +111,29 @@ SetBits (
STATIC
VOID
ClearBits (
- IN EFI_PHYSICAL_ADDRESS Address,
- IN UINTN BitNumber,
- IN UINT64 *BitMap
+ IN EFI_PHYSICAL_ADDRESS Address,
+ IN UINTN BitNumber,
+ IN UINT64 *BitMap
)
{
- UINTN Lsbs;
- UINTN Qwords;
- UINTN Msbs;
- UINTN StartBit;
- UINTN EndBit;
+ UINTN Lsbs;
+ UINTN Qwords;
+ UINTN Msbs;
+ UINTN StartBit;
+ UINTN EndBit;
- StartBit = (UINTN)GUARDED_HEAP_MAP_ENTRY_BIT_INDEX (Address);
- EndBit = (StartBit + BitNumber - 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
+ StartBit = (UINTN)GUARDED_HEAP_MAP_ENTRY_BIT_INDEX (Address);
+ EndBit = (StartBit + BitNumber - 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
if ((StartBit + BitNumber) >= GUARDED_HEAP_MAP_ENTRY_BITS) {
- Msbs = (GUARDED_HEAP_MAP_ENTRY_BITS - StartBit) %
- GUARDED_HEAP_MAP_ENTRY_BITS;
- Lsbs = (EndBit + 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
- Qwords = (BitNumber - Msbs) / GUARDED_HEAP_MAP_ENTRY_BITS;
+ Msbs = (GUARDED_HEAP_MAP_ENTRY_BITS - StartBit) %
+ GUARDED_HEAP_MAP_ENTRY_BITS;
+ Lsbs = (EndBit + 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
+ Qwords = (BitNumber - Msbs) / GUARDED_HEAP_MAP_ENTRY_BITS;
} else {
- Msbs = BitNumber;
- Lsbs = 0;
- Qwords = 0;
+ Msbs = BitNumber;
+ Lsbs = 0;
+ Qwords = 0;
}
if (Msbs > 0) {
@@ -163,21 +166,21 @@ ClearBits (
STATIC
UINT64
GetBits (
- IN EFI_PHYSICAL_ADDRESS Address,
- IN UINTN BitNumber,
- IN UINT64 *BitMap
+ IN EFI_PHYSICAL_ADDRESS Address,
+ IN UINTN BitNumber,
+ IN UINT64 *BitMap
)
{
- UINTN StartBit;
- UINTN EndBit;
- UINTN Lsbs;
- UINTN Msbs;
- UINT64 Result;
+ UINTN StartBit;
+ UINTN EndBit;
+ UINTN Lsbs;
+ UINTN Msbs;
+ UINT64 Result;
ASSERT (BitNumber <= GUARDED_HEAP_MAP_ENTRY_BITS);
- StartBit = (UINTN)GUARDED_HEAP_MAP_ENTRY_BIT_INDEX (Address);
- EndBit = (StartBit + BitNumber - 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
+ StartBit = (UINTN)GUARDED_HEAP_MAP_ENTRY_BIT_INDEX (Address);
+ EndBit = (StartBit + BitNumber - 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
if ((StartBit + BitNumber) > GUARDED_HEAP_MAP_ENTRY_BITS) {
Msbs = GUARDED_HEAP_MAP_ENTRY_BITS - StartBit;
@@ -187,13 +190,13 @@ GetBits (
Lsbs = 0;
}
- if (StartBit == 0 && BitNumber == GUARDED_HEAP_MAP_ENTRY_BITS) {
+ if ((StartBit == 0) && (BitNumber == GUARDED_HEAP_MAP_ENTRY_BITS)) {
Result = *BitMap;
} else {
- Result = RShiftU64((*BitMap), StartBit) & (LShiftU64(1, Msbs) - 1);
+ Result = RShiftU64 ((*BitMap), StartBit) & (LShiftU64 (1, Msbs) - 1);
if (Lsbs > 0) {
- BitMap += 1;
- Result |= LShiftU64 ((*BitMap) & (LShiftU64 (1, Lsbs) - 1), Msbs);
+ BitMap += 1;
+ Result |= LShiftU64 ((*BitMap) & (LShiftU64 (1, Lsbs) - 1), Msbs);
}
}
@@ -212,18 +215,18 @@ GetBits (
**/
UINTN
FindGuardedMemoryMap (
- IN EFI_PHYSICAL_ADDRESS Address,
- IN BOOLEAN AllocMapUnit,
- OUT UINT64 **BitMap
+ IN EFI_PHYSICAL_ADDRESS Address,
+ IN BOOLEAN AllocMapUnit,
+ OUT UINT64 **BitMap
)
{
- UINTN Level;
- UINT64 *GuardMap;
- UINT64 MapMemory;
- UINTN Index;
- UINTN Size;
- UINTN BitsToUnitEnd;
- EFI_STATUS Status;
+ UINTN Level;
+ UINT64 *GuardMap;
+ UINT64 MapMemory;
+ UINTN Index;
+ UINTN Size;
+ UINTN BitsToUnitEnd;
+ EFI_STATUS Status;
MapMemory = 0;
@@ -235,50 +238,49 @@ FindGuardedMemoryMap (
RShiftU64 (
Address,
mLevelShift[GUARDED_HEAP_MAP_TABLE_DEPTH - mMapLevel - 1]
- ) != 0) {
-
+ ) != 0)
+ {
if (mGuardedMemoryMap != 0) {
Size = (mLevelMask[GUARDED_HEAP_MAP_TABLE_DEPTH - mMapLevel - 1] + 1)
* GUARDED_HEAP_MAP_ENTRY_BYTES;
Status = CoreInternalAllocatePages (
- AllocateAnyPages,
- EfiBootServicesData,
- EFI_SIZE_TO_PAGES (Size),
- &MapMemory,
- FALSE
- );
+ AllocateAnyPages,
+ EfiBootServicesData,
+ EFI_SIZE_TO_PAGES (Size),
+ &MapMemory,
+ FALSE
+ );
ASSERT_EFI_ERROR (Status);
ASSERT (MapMemory != 0);
SetMem ((VOID *)(UINTN)MapMemory, Size, 0);
*(UINT64 *)(UINTN)MapMemory = mGuardedMemoryMap;
- mGuardedMemoryMap = MapMemory;
+ mGuardedMemoryMap = MapMemory;
}
mMapLevel++;
-
}
GuardMap = &mGuardedMemoryMap;
for (Level = GUARDED_HEAP_MAP_TABLE_DEPTH - mMapLevel;
Level < GUARDED_HEAP_MAP_TABLE_DEPTH;
- ++Level) {
-
+ ++Level)
+ {
if (*GuardMap == 0) {
if (!AllocMapUnit) {
GuardMap = NULL;
break;
}
- Size = (mLevelMask[Level] + 1) * GUARDED_HEAP_MAP_ENTRY_BYTES;
+ Size = (mLevelMask[Level] + 1) * GUARDED_HEAP_MAP_ENTRY_BYTES;
Status = CoreInternalAllocatePages (
- AllocateAnyPages,
- EfiBootServicesData,
- EFI_SIZE_TO_PAGES (Size),
- &MapMemory,
- FALSE
- );
+ AllocateAnyPages,
+ EfiBootServicesData,
+ EFI_SIZE_TO_PAGES (Size),
+ &MapMemory,
+ FALSE
+ );
ASSERT_EFI_ERROR (Status);
ASSERT (MapMemory != 0);
@@ -286,10 +288,9 @@ FindGuardedMemoryMap (
*GuardMap = MapMemory;
}
- Index = (UINTN)RShiftU64 (Address, mLevelShift[Level]);
- Index &= mLevelMask[Level];
- GuardMap = (UINT64 *)(UINTN)((*GuardMap) + Index * sizeof (UINT64));
-
+ Index = (UINTN)RShiftU64 (Address, mLevelShift[Level]);
+ Index &= mLevelMask[Level];
+ GuardMap = (UINT64 *)(UINTN)((*GuardMap) + Index * sizeof (UINT64));
}
BitsToUnitEnd = GUARDED_HEAP_MAP_BITS - GUARDED_HEAP_MAP_BIT_INDEX (Address);
@@ -309,13 +310,13 @@ FindGuardedMemoryMap (
VOID
EFIAPI
SetGuardedMemoryBits (
- IN EFI_PHYSICAL_ADDRESS Address,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS Address,
+ IN UINTN NumberOfPages
)
{
- UINT64 *BitMap;
- UINTN Bits;
- UINTN BitsToUnitEnd;
+ UINT64 *BitMap;
+ UINTN Bits;
+ UINTN BitsToUnitEnd;
while (NumberOfPages > 0) {
BitsToUnitEnd = FindGuardedMemoryMap (Address, TRUE, &BitMap);
@@ -325,7 +326,7 @@ SetGuardedMemoryBits (
// Cross map unit
Bits = BitsToUnitEnd;
} else {
- Bits = NumberOfPages;
+ Bits = NumberOfPages;
}
SetBits (Address, Bits, BitMap);
@@ -346,13 +347,13 @@ SetGuardedMemoryBits (
VOID
EFIAPI
ClearGuardedMemoryBits (
- IN EFI_PHYSICAL_ADDRESS Address,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS Address,
+ IN UINTN NumberOfPages
)
{
- UINT64 *BitMap;
- UINTN Bits;
- UINTN BitsToUnitEnd;
+ UINT64 *BitMap;
+ UINTN Bits;
+ UINTN BitsToUnitEnd;
while (NumberOfPages > 0) {
BitsToUnitEnd = FindGuardedMemoryMap (Address, TRUE, &BitMap);
@@ -362,7 +363,7 @@ ClearGuardedMemoryBits (
// Cross map unit
Bits = BitsToUnitEnd;
} else {
- Bits = NumberOfPages;
+ Bits = NumberOfPages;
}
ClearBits (Address, Bits, BitMap);
@@ -382,15 +383,15 @@ ClearGuardedMemoryBits (
**/
UINT64
GetGuardedMemoryBits (
- IN EFI_PHYSICAL_ADDRESS Address,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS Address,
+ IN UINTN NumberOfPages
)
{
- UINT64 *BitMap;
- UINTN Bits;
- UINT64 Result;
- UINTN Shift;
- UINTN BitsToUnitEnd;
+ UINT64 *BitMap;
+ UINTN Bits;
+ UINT64 Result;
+ UINTN Shift;
+ UINTN BitsToUnitEnd;
ASSERT (NumberOfPages <= GUARDED_HEAP_MAP_ENTRY_BITS);
@@ -401,9 +402,9 @@ GetGuardedMemoryBits (
if (NumberOfPages > BitsToUnitEnd) {
// Cross map unit
- Bits = BitsToUnitEnd;
+ Bits = BitsToUnitEnd;
} else {
- Bits = NumberOfPages;
+ Bits = NumberOfPages;
}
if (BitMap != NULL) {
@@ -428,15 +429,18 @@ GetGuardedMemoryBits (
UINTN
EFIAPI
GetGuardMapBit (
- IN EFI_PHYSICAL_ADDRESS Address
+ IN EFI_PHYSICAL_ADDRESS Address
)
{
- UINT64 *GuardMap;
+ UINT64 *GuardMap;
FindGuardedMemoryMap (Address, FALSE, &GuardMap);
if (GuardMap != NULL) {
- if (RShiftU64 (*GuardMap,
- GUARDED_HEAP_MAP_ENTRY_BIT_INDEX (Address)) & 1) {
+ if (RShiftU64 (
+ *GuardMap,
+ GUARDED_HEAP_MAP_ENTRY_BIT_INDEX (Address)
+ ) & 1)
+ {
return 1;
}
}
@@ -444,7 +448,6 @@ GetGuardMapBit (
return 0;
}
-
/**
Check to see if the page at the given address is a Guard page or not.
@@ -456,10 +459,10 @@ GetGuardMapBit (
BOOLEAN
EFIAPI
IsGuardPage (
- IN EFI_PHYSICAL_ADDRESS Address
+ IN EFI_PHYSICAL_ADDRESS Address
)
{
- UINT64 BitMap;
+ UINT64 BitMap;
//
// There must be at least one guarded page before and/or after given
@@ -470,7 +473,6 @@ IsGuardPage (
return ((BitMap == BIT0) || (BitMap == BIT2) || (BitMap == (BIT2 | BIT0)));
}
-
/**
Check to see if the page at the given address is guarded or not.
@@ -482,7 +484,7 @@ IsGuardPage (
BOOLEAN
EFIAPI
IsMemoryGuarded (
- IN EFI_PHYSICAL_ADDRESS Address
+ IN EFI_PHYSICAL_ADDRESS Address
)
{
return (GetGuardMapBit (Address) == 1);
@@ -500,10 +502,10 @@ IsMemoryGuarded (
VOID
EFIAPI
SetGuardPage (
- IN EFI_PHYSICAL_ADDRESS BaseAddress
+ IN EFI_PHYSICAL_ADDRESS BaseAddress
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
if (gCpu == NULL) {
return;
@@ -535,11 +537,11 @@ SetGuardPage (
VOID
EFIAPI
UnsetGuardPage (
- IN EFI_PHYSICAL_ADDRESS BaseAddress
+ IN EFI_PHYSICAL_ADDRESS BaseAddress
)
{
- UINT64 Attributes;
- EFI_STATUS Status;
+ UINT64 Attributes;
+ EFI_STATUS Status;
if (gCpu == NULL) {
return;
@@ -583,13 +585,13 @@ UnsetGuardPage (
**/
BOOLEAN
IsMemoryTypeToGuard (
- IN EFI_MEMORY_TYPE MemoryType,
- IN EFI_ALLOCATE_TYPE AllocateType,
- IN UINT8 PageOrPool
+ IN EFI_MEMORY_TYPE MemoryType,
+ IN EFI_ALLOCATE_TYPE AllocateType,
+ IN UINT8 PageOrPool
)
{
- UINT64 TestBit;
- UINT64 ConfigBit;
+ UINT64 TestBit;
+ UINT64 ConfigBit;
if (AllocateType == AllocateAddress) {
return FALSE;
@@ -609,7 +611,7 @@ IsMemoryTypeToGuard (
if ((UINT32)MemoryType >= MEMORY_TYPE_OS_RESERVED_MIN) {
TestBit = BIT63;
- } else if ((UINT32) MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {
+ } else if ((UINT32)MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {
TestBit = BIT62;
} else if (MemoryType < EfiMaxMemoryType) {
TestBit = LShiftU64 (1, MemoryType);
@@ -633,11 +635,14 @@ IsMemoryTypeToGuard (
**/
BOOLEAN
IsPoolTypeToGuard (
- IN EFI_MEMORY_TYPE MemoryType
+ IN EFI_MEMORY_TYPE MemoryType
)
{
- return IsMemoryTypeToGuard (MemoryType, AllocateAnyPages,
- GUARD_HEAP_TYPE_POOL);
+ return IsMemoryTypeToGuard (
+ MemoryType,
+ AllocateAnyPages,
+ GUARD_HEAP_TYPE_POOL
+ );
}
/**
@@ -651,8 +656,8 @@ IsPoolTypeToGuard (
**/
BOOLEAN
IsPageTypeToGuard (
- IN EFI_MEMORY_TYPE MemoryType,
- IN EFI_ALLOCATE_TYPE AllocateType
+ IN EFI_MEMORY_TYPE MemoryType,
+ IN EFI_ALLOCATE_TYPE AllocateType
)
{
return IsMemoryTypeToGuard (MemoryType, AllocateType, GUARD_HEAP_TYPE_PAGE);
@@ -667,7 +672,7 @@ IsPageTypeToGuard (
**/
BOOLEAN
IsHeapGuardEnabled (
- UINT8 GuardType
+ UINT8 GuardType
)
{
return IsMemoryTypeToGuard (EfiMaxMemoryType, AllocateAnyPages, GuardType);
@@ -683,11 +688,11 @@ IsHeapGuardEnabled (
**/
VOID
SetGuardForMemory (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NumberOfPages
)
{
- EFI_PHYSICAL_ADDRESS GuardPage;
+ EFI_PHYSICAL_ADDRESS GuardPage;
//
// Set tail Guard
@@ -719,8 +724,8 @@ SetGuardForMemory (
**/
VOID
UnsetGuardForMemory (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NumberOfPages
)
{
EFI_PHYSICAL_ADDRESS GuardPage;
@@ -742,7 +747,7 @@ UnsetGuardForMemory (
// -------------------
// Start -> -1 -2
//
- GuardPage = Memory - EFI_PAGES_TO_SIZE (1);
+ GuardPage = Memory - EFI_PAGES_TO_SIZE (1);
GuardBitmap = GetGuardedMemoryBits (Memory - EFI_PAGES_TO_SIZE (2), 2);
if ((GuardBitmap & BIT1) == 0) {
//
@@ -775,7 +780,7 @@ UnsetGuardForMemory (
// --------------------
// +1 +0 <- End
//
- GuardPage = Memory + EFI_PAGES_TO_SIZE (NumberOfPages);
+ GuardPage = Memory + EFI_PAGES_TO_SIZE (NumberOfPages);
GuardBitmap = GetGuardedMemoryBits (GuardPage, 2);
if ((GuardBitmap & BIT0) == 0) {
//
@@ -799,7 +804,7 @@ UnsetGuardForMemory (
//
// No matter what, we just clear the mark of the Guarded memory.
//
- ClearGuardedMemoryBits(Memory, NumberOfPages);
+ ClearGuardedMemoryBits (Memory, NumberOfPages);
}
/**
@@ -818,9 +823,9 @@ UnsetGuardForMemory (
**/
UINT64
AdjustMemoryS (
- IN UINT64 Start,
- IN UINT64 Size,
- IN UINT64 SizeRequested
+ IN UINT64 Start,
+ IN UINT64 Size,
+ IN UINT64 SizeRequested
)
{
UINT64 Target;
@@ -831,7 +836,7 @@ AdjustMemoryS (
// make sure alignment of the returned pool address.
//
if ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) == 0) {
- SizeRequested = ALIGN_VALUE(SizeRequested, 8);
+ SizeRequested = ALIGN_VALUE (SizeRequested, 8);
}
Target = Start + Size - SizeRequested;
@@ -877,8 +882,8 @@ AdjustMemoryS (
**/
VOID
AdjustMemoryF (
- IN OUT EFI_PHYSICAL_ADDRESS *Memory,
- IN OUT UINTN *NumberOfPages
+ IN OUT EFI_PHYSICAL_ADDRESS *Memory,
+ IN OUT UINTN *NumberOfPages
)
{
EFI_PHYSICAL_ADDRESS Start;
@@ -886,11 +891,11 @@ AdjustMemoryF (
UINTN PagesToFree;
UINT64 GuardBitmap;
- if (Memory == NULL || NumberOfPages == NULL || *NumberOfPages == 0) {
+ if ((Memory == NULL) || (NumberOfPages == NULL) || (*NumberOfPages == 0)) {
return;
}
- Start = *Memory;
+ Start = *Memory;
PagesToFree = *NumberOfPages;
//
@@ -906,7 +911,7 @@ AdjustMemoryF (
// Start -> -1 -2
//
MemoryToTest = Start - EFI_PAGES_TO_SIZE (2);
- GuardBitmap = GetGuardedMemoryBits (MemoryToTest, 2);
+ GuardBitmap = GetGuardedMemoryBits (MemoryToTest, 2);
if ((GuardBitmap & BIT1) == 0) {
//
// Head Guard exists.
@@ -941,7 +946,7 @@ AdjustMemoryF (
// +1 +0 <- End
//
MemoryToTest = Start + EFI_PAGES_TO_SIZE (PagesToFree);
- GuardBitmap = GetGuardedMemoryBits (MemoryToTest, 2);
+ GuardBitmap = GetGuardedMemoryBits (MemoryToTest, 2);
if ((GuardBitmap & BIT0) == 0) {
//
// Tail Guard exists.
@@ -961,8 +966,8 @@ AdjustMemoryF (
PagesToFree -= 1;
}
- *Memory = Start;
- *NumberOfPages = PagesToFree;
+ *Memory = Start;
+ *NumberOfPages = PagesToFree;
}
/**
@@ -975,8 +980,8 @@ AdjustMemoryF (
**/
VOID
AdjustMemoryA (
- IN OUT EFI_PHYSICAL_ADDRESS *Memory,
- IN OUT UINTN *NumberOfPages
+ IN OUT EFI_PHYSICAL_ADDRESS *Memory,
+ IN OUT UINTN *NumberOfPages
)
{
//
@@ -1009,12 +1014,12 @@ AdjustMemoryA (
**/
VOID *
AdjustPoolHeadA (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NoPages,
- IN UINTN Size
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NoPages,
+ IN UINTN Size
)
{
- if (Memory == 0 || (PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) != 0) {
+ if ((Memory == 0) || ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) != 0)) {
//
// Pool head is put near the head Guard
//
@@ -1037,10 +1042,10 @@ AdjustPoolHeadA (
**/
VOID *
AdjustPoolHeadF (
- IN EFI_PHYSICAL_ADDRESS Memory
+ IN EFI_PHYSICAL_ADDRESS Memory
)
{
- if (Memory == 0 || (PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) != 0) {
+ if ((Memory == 0) || ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) != 0)) {
//
// Pool head is put near the head Guard
//
@@ -1103,30 +1108,31 @@ SetAllGuardPages (
VOID
)
{
- UINTN Entries[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINTN Shifts[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINTN Indices[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINT64 Tables[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINT64 Addresses[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINT64 TableEntry;
- UINT64 Address;
- UINT64 GuardPage;
- INTN Level;
- UINTN Index;
- BOOLEAN OnGuarding;
-
- if (mGuardedMemoryMap == 0 ||
- mMapLevel == 0 ||
- mMapLevel > GUARDED_HEAP_MAP_TABLE_DEPTH) {
+ UINTN Entries[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINTN Shifts[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINTN Indices[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINT64 Tables[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINT64 Addresses[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINT64 TableEntry;
+ UINT64 Address;
+ UINT64 GuardPage;
+ INTN Level;
+ UINTN Index;
+ BOOLEAN OnGuarding;
+
+ if ((mGuardedMemoryMap == 0) ||
+ (mMapLevel == 0) ||
+ (mMapLevel > GUARDED_HEAP_MAP_TABLE_DEPTH))
+ {
return;
}
CopyMem (Entries, mLevelMask, sizeof (Entries));
CopyMem (Shifts, mLevelShift, sizeof (Shifts));
- SetMem (Tables, sizeof(Tables), 0);
- SetMem (Addresses, sizeof(Addresses), 0);
- SetMem (Indices, sizeof(Indices), 0);
+ SetMem (Tables, sizeof (Tables), 0);
+ SetMem (Addresses, sizeof (Addresses), 0);
+ SetMem (Indices, sizeof (Indices), 0);
Level = GUARDED_HEAP_MAP_TABLE_DEPTH - mMapLevel;
Tables[Level] = mGuardedMemoryMap;
@@ -1135,32 +1141,26 @@ SetAllGuardPages (
DEBUG_CODE (
DumpGuardedMemoryBitmap ();
- );
+ );
while (TRUE) {
if (Indices[Level] > Entries[Level]) {
Tables[Level] = 0;
Level -= 1;
} else {
-
- TableEntry = ((UINT64 *)(UINTN)(Tables[Level]))[Indices[Level]];
- Address = Addresses[Level];
+ TableEntry = ((UINT64 *)(UINTN)(Tables[Level]))[Indices[Level]];
+ Address = Addresses[Level];
if (TableEntry == 0) {
-
OnGuarding = FALSE;
-
} else if (Level < GUARDED_HEAP_MAP_TABLE_DEPTH - 1) {
-
- Level += 1;
- Tables[Level] = TableEntry;
- Addresses[Level] = Address;
- Indices[Level] = 0;
+ Level += 1;
+ Tables[Level] = TableEntry;
+ Addresses[Level] = Address;
+ Indices[Level] = 0;
continue;
-
} else {
-
Index = 0;
while (Index < GUARDED_HEAP_MAP_ENTRY_BITS) {
if ((TableEntry & 1) == 1) {
@@ -1169,6 +1169,7 @@ SetAllGuardPages (
} else {
GuardPage = Address - EFI_PAGE_SIZE;
}
+
OnGuarding = TRUE;
} else {
if (OnGuarding) {
@@ -1176,6 +1177,7 @@ SetAllGuardPages (
} else {
GuardPage = 0;
}
+
OnGuarding = FALSE;
}
@@ -1198,10 +1200,9 @@ SetAllGuardPages (
break;
}
- Indices[Level] += 1;
- Address = (Level == 0) ? 0 : Addresses[Level - 1];
- Addresses[Level] = Address | LShiftU64(Indices[Level], Shifts[Level]);
-
+ Indices[Level] += 1;
+ Address = (Level == 0) ? 0 : Addresses[Level - 1];
+ Addresses[Level] = Address | LShiftU64 (Indices[Level], Shifts[Level]);
}
}
@@ -1214,31 +1215,32 @@ SetAllGuardPages (
**/
VOID
GetLastGuardedFreePageAddress (
- OUT EFI_PHYSICAL_ADDRESS *Address
+ OUT EFI_PHYSICAL_ADDRESS *Address
)
{
- EFI_PHYSICAL_ADDRESS AddressGranularity;
- EFI_PHYSICAL_ADDRESS BaseAddress;
- UINTN Level;
- UINT64 Map;
- INTN Index;
+ EFI_PHYSICAL_ADDRESS AddressGranularity;
+ EFI_PHYSICAL_ADDRESS BaseAddress;
+ UINTN Level;
+ UINT64 Map;
+ INTN Index;
ASSERT (mMapLevel >= 1);
BaseAddress = 0;
- Map = mGuardedMemoryMap;
+ Map = mGuardedMemoryMap;
for (Level = GUARDED_HEAP_MAP_TABLE_DEPTH - mMapLevel;
Level < GUARDED_HEAP_MAP_TABLE_DEPTH;
- ++Level) {
+ ++Level)
+ {
AddressGranularity = LShiftU64 (1, mLevelShift[Level]);
//
// Find the non-NULL entry at largest index.
//
- for (Index = (INTN)mLevelMask[Level]; Index >= 0 ; --Index) {
+ for (Index = (INTN)mLevelMask[Level]; Index >= 0; --Index) {
if (((UINT64 *)(UINTN)Map)[Index] != 0) {
BaseAddress += MultU64x32 (AddressGranularity, (UINT32)Index);
- Map = ((UINT64 *)(UINTN)Map)[Index];
+ Map = ((UINT64 *)(UINTN)Map)[Index];
break;
}
}
@@ -1248,7 +1250,7 @@ GetLastGuardedFreePageAddress (
// Find the non-zero MSB then get the page address.
//
while (Map != 0) {
- Map = RShiftU64 (Map, 1);
+ Map = RShiftU64 (Map, 1);
BaseAddress += EFI_PAGES_TO_SIZE (1);
}
@@ -1265,8 +1267,8 @@ GetLastGuardedFreePageAddress (
**/
VOID
MarkFreedPages (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINTN Pages
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINTN Pages
)
{
SetGuardedMemoryBits (BaseAddress, Pages);
@@ -1283,11 +1285,11 @@ MarkFreedPages (
VOID
EFIAPI
GuardFreedPages (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINTN Pages
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINTN Pages
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
//
// Legacy memory lower than 1MB might be accessed with no allocation. Leave
@@ -1322,6 +1324,7 @@ GuardFreedPages (
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "Failed to guard freed pages: %p (%lu)\n", BaseAddress, (UINT64)Pages));
}
+
mOnGuarding = FALSE;
}
}
@@ -1337,8 +1340,8 @@ GuardFreedPages (
VOID
EFIAPI
GuardFreedPagesChecked (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINTN Pages
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINTN Pages
)
{
if (IsHeapGuardEnabled (GUARD_HEAP_TYPE_FREED)) {
@@ -1355,30 +1358,31 @@ GuardAllFreedPages (
VOID
)
{
- UINTN Entries[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINTN Shifts[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINTN Indices[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINT64 Tables[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINT64 Addresses[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINT64 TableEntry;
- UINT64 Address;
- UINT64 GuardPage;
- INTN Level;
- UINT64 BitIndex;
- UINTN GuardPageNumber;
-
- if (mGuardedMemoryMap == 0 ||
- mMapLevel == 0 ||
- mMapLevel > GUARDED_HEAP_MAP_TABLE_DEPTH) {
+ UINTN Entries[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINTN Shifts[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINTN Indices[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINT64 Tables[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINT64 Addresses[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINT64 TableEntry;
+ UINT64 Address;
+ UINT64 GuardPage;
+ INTN Level;
+ UINT64 BitIndex;
+ UINTN GuardPageNumber;
+
+ if ((mGuardedMemoryMap == 0) ||
+ (mMapLevel == 0) ||
+ (mMapLevel > GUARDED_HEAP_MAP_TABLE_DEPTH))
+ {
return;
}
CopyMem (Entries, mLevelMask, sizeof (Entries));
CopyMem (Shifts, mLevelShift, sizeof (Shifts));
- SetMem (Tables, sizeof(Tables), 0);
- SetMem (Addresses, sizeof(Addresses), 0);
- SetMem (Indices, sizeof(Indices), 0);
+ SetMem (Tables, sizeof (Tables), 0);
+ SetMem (Addresses, sizeof (Addresses), 0);
+ SetMem (Indices, sizeof (Indices), 0);
Level = GUARDED_HEAP_MAP_TABLE_DEPTH - mMapLevel;
Tables[Level] = mGuardedMemoryMap;
@@ -1391,14 +1395,14 @@ GuardAllFreedPages (
Tables[Level] = 0;
Level -= 1;
} else {
- TableEntry = ((UINT64 *)(UINTN)(Tables[Level]))[Indices[Level]];
- Address = Addresses[Level];
+ TableEntry = ((UINT64 *)(UINTN)(Tables[Level]))[Indices[Level]];
+ Address = Addresses[Level];
if (Level < GUARDED_HEAP_MAP_TABLE_DEPTH - 1) {
- Level += 1;
- Tables[Level] = TableEntry;
- Addresses[Level] = Address;
- Indices[Level] = 0;
+ Level += 1;
+ Tables[Level] = TableEntry;
+ Addresses[Level] = Address;
+ Indices[Level] = 0;
continue;
} else {
@@ -1408,6 +1412,7 @@ GuardAllFreedPages (
if (GuardPage == (UINT64)-1) {
GuardPage = Address;
}
+
++GuardPageNumber;
} else if (GuardPageNumber > 0) {
GuardFreedPages (GuardPage, GuardPageNumber);
@@ -1429,10 +1434,9 @@ GuardAllFreedPages (
break;
}
- Indices[Level] += 1;
- Address = (Level == 0) ? 0 : Addresses[Level - 1];
+ Indices[Level] += 1;
+ Address = (Level == 0) ? 0 : Addresses[Level - 1];
Addresses[Level] = Address | LShiftU64 (Indices[Level], Shifts[Level]);
-
}
//
@@ -1457,16 +1461,17 @@ GuardAllFreedPages (
**/
VOID
MergeGuardPages (
- IN EFI_MEMORY_DESCRIPTOR *MemoryMapEntry,
- IN EFI_PHYSICAL_ADDRESS MaxAddress
+ IN EFI_MEMORY_DESCRIPTOR *MemoryMapEntry,
+ IN EFI_PHYSICAL_ADDRESS MaxAddress
)
{
- EFI_PHYSICAL_ADDRESS EndAddress;
- UINT64 Bitmap;
- INTN Pages;
+ EFI_PHYSICAL_ADDRESS EndAddress;
+ UINT64 Bitmap;
+ INTN Pages;
if (!IsHeapGuardEnabled (GUARD_HEAP_TYPE_FREED) ||
- MemoryMapEntry->Type >= EfiMemoryMappedIO) {
+ (MemoryMapEntry->Type >= EfiMemoryMappedIO))
+ {
return;
}
@@ -1511,14 +1516,14 @@ MergeGuardPages (
**/
BOOLEAN
PromoteGuardedFreePages (
- OUT EFI_PHYSICAL_ADDRESS *StartAddress,
- OUT EFI_PHYSICAL_ADDRESS *EndAddress
+ OUT EFI_PHYSICAL_ADDRESS *StartAddress,
+ OUT EFI_PHYSICAL_ADDRESS *EndAddress
)
{
- EFI_STATUS Status;
- UINTN AvailablePages;
- UINT64 Bitmap;
- EFI_PHYSICAL_ADDRESS Start;
+ EFI_STATUS Status;
+ UINTN AvailablePages;
+ UINT64 Bitmap;
+ EFI_PHYSICAL_ADDRESS Start;
if (!IsHeapGuardEnabled (GUARD_HEAP_TYPE_FREED)) {
return FALSE;
@@ -1528,8 +1533,8 @@ PromoteGuardedFreePages (
// Similar to memory allocation service, always search the freed pages in
// descending direction.
//
- Start = mLastPromotedPage;
- AvailablePages = 0;
+ Start = mLastPromotedPage;
+ AvailablePages = 0;
while (AvailablePages == 0) {
Start -= EFI_PAGES_TO_SIZE (GUARDED_HEAP_MAP_ENTRY_BITS);
//
@@ -1565,7 +1570,7 @@ PromoteGuardedFreePages (
// operation; otherwise infinite loops could be caused.
//
mOnGuarding = TRUE;
- Status = gCpu->SetMemoryAttributes (gCpu, Start, EFI_PAGES_TO_SIZE(AvailablePages), 0);
+ Status = gCpu->SetMemoryAttributes (gCpu, Start, EFI_PAGES_TO_SIZE (AvailablePages), 0);
ASSERT_EFI_ERROR (Status);
mOnGuarding = FALSE;
}
@@ -1590,7 +1595,8 @@ HeapGuardCpuArchProtocolNotify (
ASSERT (gCpu != NULL);
if (IsHeapGuardEnabled (GUARD_HEAP_TYPE_PAGE|GUARD_HEAP_TYPE_POOL) &&
- IsHeapGuardEnabled (GUARD_HEAP_TYPE_FREED)) {
+ IsHeapGuardEnabled (GUARD_HEAP_TYPE_FREED))
+ {
DEBUG ((DEBUG_ERROR, "Heap guard and freed memory guard cannot be enabled at the same time.\n"));
CpuDeadLoop ();
}
@@ -1614,11 +1620,11 @@ HeapGuardCpuArchProtocolNotify (
**/
VOID
Uint64ToBinString (
- IN UINT64 Value,
- OUT CHAR8 *BinString
+ IN UINT64 Value,
+ OUT CHAR8 *BinString
)
{
- UINTN Index;
+ UINTN Index;
if (BinString == NULL) {
return;
@@ -1626,8 +1632,9 @@ Uint64ToBinString (
for (Index = 64; Index > 0; --Index) {
BinString[Index - 1] = '0' + (Value & 1);
- Value = RShiftU64 (Value, 1);
+ Value = RShiftU64 (Value, 1);
}
+
BinString[64] = '\0';
}
@@ -1640,44 +1647,48 @@ DumpGuardedMemoryBitmap (
VOID
)
{
- UINTN Entries[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINTN Shifts[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINTN Indices[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINT64 Tables[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINT64 Addresses[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINT64 TableEntry;
- UINT64 Address;
- INTN Level;
- UINTN RepeatZero;
- CHAR8 String[GUARDED_HEAP_MAP_ENTRY_BITS + 1];
- CHAR8 *Ruler1;
- CHAR8 *Ruler2;
+ UINTN Entries[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINTN Shifts[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINTN Indices[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINT64 Tables[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINT64 Addresses[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINT64 TableEntry;
+ UINT64 Address;
+ INTN Level;
+ UINTN RepeatZero;
+ CHAR8 String[GUARDED_HEAP_MAP_ENTRY_BITS + 1];
+ CHAR8 *Ruler1;
+ CHAR8 *Ruler2;
if (!IsHeapGuardEnabled (GUARD_HEAP_TYPE_ALL)) {
return;
}
- if (mGuardedMemoryMap == 0 ||
- mMapLevel == 0 ||
- mMapLevel > GUARDED_HEAP_MAP_TABLE_DEPTH) {
+ if ((mGuardedMemoryMap == 0) ||
+ (mMapLevel == 0) ||
+ (mMapLevel > GUARDED_HEAP_MAP_TABLE_DEPTH))
+ {
return;
}
Ruler1 = " 3 2 1 0";
Ruler2 = "FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210";
- DEBUG ((HEAP_GUARD_DEBUG_LEVEL, "============================="
- " Guarded Memory Bitmap "
- "==============================\r\n"));
+ DEBUG ((
+ HEAP_GUARD_DEBUG_LEVEL,
+ "============================="
+ " Guarded Memory Bitmap "
+ "==============================\r\n"
+ ));
DEBUG ((HEAP_GUARD_DEBUG_LEVEL, " %a\r\n", Ruler1));
DEBUG ((HEAP_GUARD_DEBUG_LEVEL, " %a\r\n", Ruler2));
CopyMem (Entries, mLevelMask, sizeof (Entries));
CopyMem (Shifts, mLevelShift, sizeof (Shifts));
- SetMem (Indices, sizeof(Indices), 0);
- SetMem (Tables, sizeof(Tables), 0);
- SetMem (Addresses, sizeof(Addresses), 0);
+ SetMem (Indices, sizeof (Indices), 0);
+ SetMem (Tables, sizeof (Tables), 0);
+ SetMem (Addresses, sizeof (Addresses), 0);
Level = GUARDED_HEAP_MAP_TABLE_DEPTH - mMapLevel;
Tables[Level] = mGuardedMemoryMap;
@@ -1686,7 +1697,6 @@ DumpGuardedMemoryBitmap (
while (TRUE) {
if (Indices[Level] > Entries[Level]) {
-
Tables[Level] = 0;
Level -= 1;
RepeatZero = 0;
@@ -1696,40 +1706,33 @@ DumpGuardedMemoryBitmap (
"========================================="
"=========================================\r\n"
));
-
} else {
-
- TableEntry = ((UINT64 *)(UINTN)Tables[Level])[Indices[Level]];
- Address = Addresses[Level];
+ TableEntry = ((UINT64 *)(UINTN)Tables[Level])[Indices[Level]];
+ Address = Addresses[Level];
if (TableEntry == 0) {
-
if (Level == GUARDED_HEAP_MAP_TABLE_DEPTH - 1) {
if (RepeatZero == 0) {
- Uint64ToBinString(TableEntry, String);
+ Uint64ToBinString (TableEntry, String);
DEBUG ((HEAP_GUARD_DEBUG_LEVEL, "%016lx: %a\r\n", Address, String));
} else if (RepeatZero == 1) {
DEBUG ((HEAP_GUARD_DEBUG_LEVEL, "... : ...\r\n"));
}
+
RepeatZero += 1;
}
-
} else if (Level < GUARDED_HEAP_MAP_TABLE_DEPTH - 1) {
-
- Level += 1;
- Tables[Level] = TableEntry;
- Addresses[Level] = Address;
- Indices[Level] = 0;
- RepeatZero = 0;
+ Level += 1;
+ Tables[Level] = TableEntry;
+ Addresses[Level] = Address;
+ Indices[Level] = 0;
+ RepeatZero = 0;
continue;
-
} else {
-
RepeatZero = 0;
- Uint64ToBinString(TableEntry, String);
+ Uint64ToBinString (TableEntry, String);
DEBUG ((HEAP_GUARD_DEBUG_LEVEL, "%016lx: %a\r\n", Address, String));
-
}
}
@@ -1737,10 +1740,8 @@ DumpGuardedMemoryBitmap (
break;
}
- Indices[Level] += 1;
- Address = (Level == 0) ? 0 : Addresses[Level - 1];
- Addresses[Level] = Address | LShiftU64(Indices[Level], Shifts[Level]);
-
+ Indices[Level] += 1;
+ Address = (Level == 0) ? 0 : Addresses[Level - 1];
+ Addresses[Level] = Address | LShiftU64 (Indices[Level], Shifts[Level]);
}
}
-
diff --git a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.h b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.h
index d6e4ed3..9a32b4d 100644
--- a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.h
+++ b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.h
@@ -51,15 +51,15 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// Each entry occupies 8B/64b. 1-page can hold 512 entries, which spans 9
// bits in address. (512 = 1 << 9)
//
-#define BYTE_LENGTH_SHIFT 3 // (8 = 1 << 3)
+#define BYTE_LENGTH_SHIFT 3 // (8 = 1 << 3)
#define GUARDED_HEAP_MAP_TABLE_ENTRY_SHIFT \
(EFI_PAGE_SHIFT - BYTE_LENGTH_SHIFT)
-#define GUARDED_HEAP_MAP_TABLE_DEPTH 5
+#define GUARDED_HEAP_MAP_TABLE_DEPTH 5
// Use UINT64_index + bit_index_of_UINT64 to locate the bit in may
-#define GUARDED_HEAP_MAP_ENTRY_BIT_SHIFT 6 // (64 = 1 << 6)
+#define GUARDED_HEAP_MAP_ENTRY_BIT_SHIFT 6 // (64 = 1 << 6)
#define GUARDED_HEAP_MAP_ENTRY_BITS \
(1 << GUARDED_HEAP_MAP_ENTRY_BIT_SHIFT)
@@ -152,9 +152,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// 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_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)
@@ -164,10 +164,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#define HEAP_GUARD_DEBUG_LEVEL (DEBUG_POOL|DEBUG_PAGE)
typedef struct {
- UINT32 TailMark;
- UINT32 HeadMark;
- EFI_PHYSICAL_ADDRESS Address;
- LIST_ENTRY Link;
+ UINT32 TailMark;
+ UINT32 HeadMark;
+ EFI_PHYSICAL_ADDRESS Address;
+ LIST_ENTRY Link;
} HEAP_GUARD_NODE;
/**
@@ -219,8 +219,8 @@ CoreConvertPagesWithGuard (
**/
VOID
SetGuardForMemory (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NumberOfPages
);
/**
@@ -233,8 +233,8 @@ SetGuardForMemory (
**/
VOID
UnsetGuardForMemory (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NumberOfPages
);
/**
@@ -247,8 +247,8 @@ UnsetGuardForMemory (
**/
VOID
AdjustMemoryA (
- IN OUT EFI_PHYSICAL_ADDRESS *Memory,
- IN OUT UINTN *NumberOfPages
+ IN OUT EFI_PHYSICAL_ADDRESS *Memory,
+ IN OUT UINTN *NumberOfPages
);
/**
@@ -265,8 +265,8 @@ AdjustMemoryA (
**/
VOID
AdjustMemoryF (
- IN OUT EFI_PHYSICAL_ADDRESS *Memory,
- IN OUT UINTN *NumberOfPages
+ IN OUT EFI_PHYSICAL_ADDRESS *Memory,
+ IN OUT UINTN *NumberOfPages
);
/**
@@ -285,9 +285,9 @@ AdjustMemoryF (
**/
UINT64
AdjustMemoryS (
- IN UINT64 Start,
- IN UINT64 Size,
- IN UINT64 SizeRequested
+ IN UINT64 Start,
+ IN UINT64 Size,
+ IN UINT64 SizeRequested
);
/**
@@ -301,7 +301,7 @@ AdjustMemoryS (
**/
BOOLEAN
IsPoolTypeToGuard (
- IN EFI_MEMORY_TYPE MemoryType
+ IN EFI_MEMORY_TYPE MemoryType
);
/**
@@ -315,8 +315,8 @@ IsPoolTypeToGuard (
**/
BOOLEAN
IsPageTypeToGuard (
- IN EFI_MEMORY_TYPE MemoryType,
- IN EFI_ALLOCATE_TYPE AllocateType
+ IN EFI_MEMORY_TYPE MemoryType,
+ IN EFI_ALLOCATE_TYPE AllocateType
);
/**
@@ -330,7 +330,7 @@ IsPageTypeToGuard (
BOOLEAN
EFIAPI
IsMemoryGuarded (
- IN EFI_PHYSICAL_ADDRESS Address
+ IN EFI_PHYSICAL_ADDRESS Address
);
/**
@@ -344,7 +344,7 @@ IsMemoryGuarded (
BOOLEAN
EFIAPI
IsGuardPage (
- IN EFI_PHYSICAL_ADDRESS Address
+ IN EFI_PHYSICAL_ADDRESS Address
);
/**
@@ -369,9 +369,9 @@ DumpGuardedMemoryBitmap (
**/
VOID *
AdjustPoolHeadA (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NoPages,
- IN UINTN Size
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NoPages,
+ IN UINTN Size
);
/**
@@ -383,7 +383,7 @@ AdjustPoolHeadA (
**/
VOID *
AdjustPoolHeadF (
- IN EFI_PHYSICAL_ADDRESS Memory
+ IN EFI_PHYSICAL_ADDRESS Memory
);
/**
@@ -395,7 +395,7 @@ AdjustPoolHeadF (
**/
BOOLEAN
IsHeapGuardEnabled (
- UINT8 GuardType
+ UINT8 GuardType
);
/**
@@ -418,8 +418,8 @@ HeapGuardCpuArchProtocolNotify (
**/
VOID
MergeGuardPages (
- IN EFI_MEMORY_DESCRIPTOR *MemoryMapEntry,
- IN EFI_PHYSICAL_ADDRESS MaxAddress
+ IN EFI_MEMORY_DESCRIPTOR *MemoryMapEntry,
+ IN EFI_PHYSICAL_ADDRESS MaxAddress
);
/**
@@ -433,8 +433,8 @@ MergeGuardPages (
VOID
EFIAPI
GuardFreedPagesChecked (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINTN Pages
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINTN Pages
);
/**
@@ -458,10 +458,10 @@ GuardFreedPagesChecked (
**/
BOOLEAN
PromoteGuardedFreePages (
- OUT EFI_PHYSICAL_ADDRESS *StartAddress,
- OUT EFI_PHYSICAL_ADDRESS *EndAddress
+ OUT EFI_PHYSICAL_ADDRESS *StartAddress,
+ OUT EFI_PHYSICAL_ADDRESS *EndAddress
);
-extern BOOLEAN mOnGuarding;
+extern BOOLEAN mOnGuarding;
#endif
diff --git a/MdeModulePkg/Core/Dxe/Mem/Imem.h b/MdeModulePkg/Core/Dxe/Mem/Imem.h
index 090f3f0..2f0bf2b 100644
--- a/MdeModulePkg/Core/Dxe/Mem/Imem.h
+++ b/MdeModulePkg/Core/Dxe/Mem/Imem.h
@@ -20,34 +20,33 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// | 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
+#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_MAP_ENTRY
//
-#define MEMORY_MAP_SIGNATURE SIGNATURE_32('m','m','a','p')
+#define MEMORY_MAP_SIGNATURE SIGNATURE_32('m','m','a','p')
typedef struct {
- UINTN Signature;
- LIST_ENTRY Link;
- BOOLEAN FromPages;
+ UINTN Signature;
+ LIST_ENTRY Link;
+ BOOLEAN FromPages;
- EFI_MEMORY_TYPE Type;
- UINT64 Start;
- UINT64 End;
+ EFI_MEMORY_TYPE Type;
+ UINT64 Start;
+ UINT64 End;
- UINT64 VirtualStart;
- UINT64 Attribute;
+ UINT64 VirtualStart;
+ UINT64 Attribute;
} MEMORY_MAP;
//
// Internal prototypes
//
-
/**
Internal function. Used by the pool functions to allocate pages
to back pool allocation requests.
@@ -62,14 +61,12 @@ typedef struct {
**/
VOID *
CoreAllocatePoolPages (
- IN EFI_MEMORY_TYPE PoolType,
- IN UINTN NumberOfPages,
- IN UINTN Alignment,
- IN BOOLEAN NeedGuard
+ IN EFI_MEMORY_TYPE PoolType,
+ IN UINTN NumberOfPages,
+ IN UINTN Alignment,
+ IN BOOLEAN NeedGuard
);
-
-
/**
Internal function. Frees pool pages allocated via AllocatePoolPages ()
@@ -79,12 +76,10 @@ CoreAllocatePoolPages (
**/
VOID
CoreFreePoolPages (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NumberOfPages
);
-
-
/**
Internal function to allocate pool of a particular type.
Caller must have the memory lock held
@@ -103,8 +98,6 @@ CoreAllocatePoolI (
IN BOOLEAN NeedGuard
);
-
-
/**
Internal function to free a pool entry.
Caller must have the memory lock held
@@ -118,12 +111,10 @@ CoreAllocatePoolI (
**/
EFI_STATUS
CoreFreePoolI (
- IN VOID *Buffer,
- OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
+ IN VOID *Buffer,
+ OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
);
-
-
/**
Enter critical section by gaining lock on gMemoryLock.
@@ -133,7 +124,6 @@ CoreAcquireMemoryLock (
VOID
);
-
/**
Exit critical section by releasing lock on gMemoryLock.
@@ -165,18 +155,18 @@ CoreReleaseMemoryLock (
EFI_STATUS
EFIAPI
CoreInternalAllocatePages (
- IN EFI_ALLOCATE_TYPE Type,
- IN EFI_MEMORY_TYPE MemoryType,
- IN UINTN NumberOfPages,
+ IN EFI_ALLOCATE_TYPE Type,
+ IN EFI_MEMORY_TYPE MemoryType,
+ IN UINTN NumberOfPages,
IN OUT EFI_PHYSICAL_ADDRESS *Memory,
- IN BOOLEAN NeedGuard
+ IN BOOLEAN NeedGuard
);
//
// Internal Global data
//
-extern EFI_LOCK gMemoryLock;
-extern LIST_ENTRY gMemoryMap;
-extern LIST_ENTRY mGcdMemorySpaceMap;
+extern EFI_LOCK gMemoryLock;
+extern LIST_ENTRY gMemoryMap;
+extern LIST_ENTRY mGcdMemorySpaceMap;
#endif
diff --git a/MdeModulePkg/Core/Dxe/Mem/MemData.c b/MdeModulePkg/Core/Dxe/Mem/MemData.c
index 67d8868..8f138b7 100644
--- a/MdeModulePkg/Core/Dxe/Mem/MemData.c
+++ b/MdeModulePkg/Core/Dxe/Mem/MemData.c
@@ -8,13 +8,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "DxeMain.h"
-
//
// MemoryLock - synchronizes access to the memory map and pool lists
//
-EFI_LOCK gMemoryLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
+EFI_LOCK gMemoryLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
//
// MemoryMap - the current memory map
//
-LIST_ENTRY gMemoryMap = INITIALIZE_LIST_HEAD_VARIABLE (gMemoryMap);
+LIST_ENTRY gMemoryMap = INITIALIZE_LIST_HEAD_VARIABLE (gMemoryMap);
diff --git a/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c b/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c
index 62bbe3c..00e33b7 100644
--- a/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c
+++ b/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c
@@ -9,15 +9,15 @@
#include "DxeMain.h"
#include "Imem.h"
-#define IS_UEFI_MEMORY_PROFILE_ENABLED ((PcdGet8 (PcdMemoryProfilePropertyMask) & BIT0) != 0)
+#define IS_UEFI_MEMORY_PROFILE_ENABLED ((PcdGet8 (PcdMemoryProfilePropertyMask) & BIT0) != 0)
#define GET_OCCUPIED_SIZE(ActualSize, Alignment) \
((ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1)))
typedef struct {
- UINT32 Signature;
- MEMORY_PROFILE_CONTEXT Context;
- LIST_ENTRY *DriverInfoList;
+ UINT32 Signature;
+ MEMORY_PROFILE_CONTEXT Context;
+ LIST_ENTRY *DriverInfoList;
} MEMORY_PROFILE_CONTEXT_DATA;
typedef struct {
@@ -29,15 +29,14 @@ typedef struct {
} MEMORY_PROFILE_DRIVER_INFO_DATA;
typedef struct {
- UINT32 Signature;
- MEMORY_PROFILE_ALLOC_INFO AllocInfo;
- CHAR8 *ActionString;
- LIST_ENTRY Link;
+ UINT32 Signature;
+ MEMORY_PROFILE_ALLOC_INFO AllocInfo;
+ CHAR8 *ActionString;
+ LIST_ENTRY Link;
} MEMORY_PROFILE_ALLOC_INFO_DATA;
-
-GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY mImageQueue = INITIALIZE_LIST_HEAD_VARIABLE (mImageQueue);
-GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA mMemoryProfileContext = {
+GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY mImageQueue = INITIALIZE_LIST_HEAD_VARIABLE (mImageQueue);
+GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA mMemoryProfileContext = {
MEMORY_PROFILE_CONTEXT_SIGNATURE,
{
{
@@ -47,21 +46,21 @@ GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA mMemoryProfileContext
},
0,
0,
- {0},
- {0},
+ { 0 },
+ { 0 },
0,
0,
0
},
&mImageQueue,
};
-GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA *mMemoryProfileContextPtr = NULL;
+GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA *mMemoryProfileContextPtr = NULL;
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_LOCK mMemoryProfileLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
-GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mMemoryProfileGettingStatus = FALSE;
-GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mMemoryProfileRecordingEnable = MEMORY_PROFILE_RECORDING_DISABLE;
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_PROTOCOL *mMemoryProfileDriverPath;
-GLOBAL_REMOVE_IF_UNREFERENCED UINTN mMemoryProfileDriverPathSize;
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_LOCK mMemoryProfileLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
+GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mMemoryProfileGettingStatus = FALSE;
+GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mMemoryProfileRecordingEnable = MEMORY_PROFILE_RECORDING_DISABLE;
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_PROTOCOL *mMemoryProfileDriverPath;
+GLOBAL_REMOVE_IF_UNREFERENCED UINTN mMemoryProfileDriverPathSize;
/**
Get memory profile data.
@@ -82,7 +81,7 @@ EFIAPI
ProfileProtocolGetData (
IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
IN OUT UINT64 *ProfileSize,
- OUT VOID *ProfileBuffer
+ OUT VOID *ProfileBuffer
);
/**
@@ -103,11 +102,11 @@ ProfileProtocolGetData (
EFI_STATUS
EFIAPI
ProfileProtocolRegisterImage (
- IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
- IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
- IN PHYSICAL_ADDRESS ImageBase,
- IN UINT64 ImageSize,
- IN EFI_FV_FILETYPE FileType
+ IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
+ IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
+ IN PHYSICAL_ADDRESS ImageBase,
+ IN UINT64 ImageSize,
+ IN EFI_FV_FILETYPE FileType
);
/**
@@ -127,10 +126,10 @@ ProfileProtocolRegisterImage (
EFI_STATUS
EFIAPI
ProfileProtocolUnregisterImage (
- IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
- IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
- IN PHYSICAL_ADDRESS ImageBase,
- IN UINT64 ImageSize
+ IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
+ IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
+ IN PHYSICAL_ADDRESS ImageBase,
+ IN UINT64 ImageSize
);
/**
@@ -147,8 +146,8 @@ ProfileProtocolUnregisterImage (
EFI_STATUS
EFIAPI
ProfileProtocolGetRecordingState (
- IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
- OUT BOOLEAN *RecordingState
+ IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
+ OUT BOOLEAN *RecordingState
);
/**
@@ -164,8 +163,8 @@ ProfileProtocolGetRecordingState (
EFI_STATUS
EFIAPI
ProfileProtocolSetRecordingState (
- IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
- IN BOOLEAN RecordingState
+ IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
+ IN BOOLEAN RecordingState
);
/**
@@ -194,16 +193,16 @@ ProfileProtocolSetRecordingState (
EFI_STATUS
EFIAPI
ProfileProtocolRecord (
- IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
- IN PHYSICAL_ADDRESS CallerAddress,
- IN MEMORY_PROFILE_ACTION Action,
- IN EFI_MEMORY_TYPE MemoryType,
- IN VOID *Buffer,
- IN UINTN Size,
- IN CHAR8 *ActionString OPTIONAL
+ IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
+ IN PHYSICAL_ADDRESS CallerAddress,
+ IN MEMORY_PROFILE_ACTION Action,
+ IN EFI_MEMORY_TYPE MemoryType,
+ IN VOID *Buffer,
+ IN UINTN Size,
+ IN CHAR8 *ActionString OPTIONAL
);
-GLOBAL_REMOVE_IF_UNREFERENCED EDKII_MEMORY_PROFILE_PROTOCOL mProfileProtocol = {
+GLOBAL_REMOVE_IF_UNREFERENCED EDKII_MEMORY_PROFILE_PROTOCOL mProfileProtocol = {
ProfileProtocolGetData,
ProfileProtocolRegisterImage,
ProfileProtocolUnregisterImage,
@@ -268,22 +267,22 @@ InternalPeCoffGetSubsystem (
ASSERT (Pe32Data != NULL);
- DosHdr = (EFI_IMAGE_DOS_HEADER *) Pe32Data;
+ DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;
if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
//
// DOS image header is present, so read the PE header after the DOS image header.
//
- Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *) ((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data + (UINTN)((DosHdr->e_lfanew) & 0x0ffff));
} else {
//
// DOS image header is not present, so PE header is at the image base.
//
- Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *) Pe32Data;
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;
}
if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {
return Hdr.Te->Subsystem;
- } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
+ } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
Magic = Hdr.Pe32->OptionalHeader.Magic;
if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
return Hdr.Pe32->OptionalHeader.Subsystem;
@@ -318,23 +317,23 @@ InternalPeCoffGetEntryPoint (
OUT VOID **EntryPoint
)
{
- EFI_IMAGE_DOS_HEADER *DosHdr;
- EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
+ EFI_IMAGE_DOS_HEADER *DosHdr;
+ EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
ASSERT (Pe32Data != NULL);
ASSERT (EntryPoint != NULL);
- DosHdr = (EFI_IMAGE_DOS_HEADER *) Pe32Data;
+ DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;
if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
//
// DOS image header is present, so read the PE header after the DOS image header.
//
- Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *) ((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data + (UINTN)((DosHdr->e_lfanew) & 0x0ffff));
} else {
//
// DOS image header is not present, so PE header is at the image base.
//
- Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *) Pe32Data;
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;
}
//
@@ -342,10 +341,10 @@ InternalPeCoffGetEntryPoint (
// AddressOfEntryPoint is common for PE32 & PE32+
//
if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {
- *EntryPoint = (VOID *) ((UINTN) Pe32Data + (UINTN) (Hdr.Te->AddressOfEntryPoint & 0x0ffffffff) + sizeof (EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize);
+ *EntryPoint = (VOID *)((UINTN)Pe32Data + (UINTN)(Hdr.Te->AddressOfEntryPoint & 0x0ffffffff) + sizeof (EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize);
return RETURN_SUCCESS;
} else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
- *EntryPoint = (VOID *) ((UINTN) Pe32Data + (UINTN) (Hdr.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff));
+ *EntryPoint = (VOID *)((UINTN)Pe32Data + (UINTN)(Hdr.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff));
return RETURN_SUCCESS;
}
@@ -368,30 +367,30 @@ InternalPeCoffGetEntryPoint (
**/
MEMORY_PROFILE_DRIVER_INFO_DATA *
BuildDriverInfo (
- IN MEMORY_PROFILE_CONTEXT_DATA *ContextData,
- IN EFI_GUID *FileName,
- IN PHYSICAL_ADDRESS ImageBase,
- IN UINT64 ImageSize,
- IN PHYSICAL_ADDRESS EntryPoint,
- IN UINT16 ImageSubsystem,
- IN EFI_FV_FILETYPE FileType
+ IN MEMORY_PROFILE_CONTEXT_DATA *ContextData,
+ IN EFI_GUID *FileName,
+ IN PHYSICAL_ADDRESS ImageBase,
+ IN UINT64 ImageSize,
+ IN PHYSICAL_ADDRESS EntryPoint,
+ IN UINT16 ImageSubsystem,
+ IN EFI_FV_FILETYPE FileType
)
{
- EFI_STATUS Status;
- MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- VOID *EntryPointInImage;
- CHAR8 *PdbString;
- UINTN PdbSize;
- UINTN PdbOccupiedSize;
-
- PdbSize = 0;
+ EFI_STATUS Status;
+ MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ VOID *EntryPointInImage;
+ CHAR8 *PdbString;
+ UINTN PdbSize;
+ UINTN PdbOccupiedSize;
+
+ PdbSize = 0;
PdbOccupiedSize = 0;
- PdbString = NULL;
+ PdbString = NULL;
if (ImageBase != 0) {
- PdbString = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageBase);
+ PdbString = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageBase);
if (PdbString != NULL) {
- PdbSize = AsciiStrSize (PdbString);
+ PdbSize = AsciiStrSize (PdbString);
PdbOccupiedSize = GET_OCCUPIED_SIZE (PdbSize, sizeof (UINT64));
}
}
@@ -402,53 +401,56 @@ BuildDriverInfo (
Status = CoreInternalAllocatePool (
EfiBootServicesData,
sizeof (*DriverInfoData) + sizeof (LIST_ENTRY) + PdbSize,
- (VOID **) &DriverInfoData
+ (VOID **)&DriverInfoData
);
if (EFI_ERROR (Status)) {
return NULL;
}
+
ASSERT (DriverInfoData != NULL);
ZeroMem (DriverInfoData, sizeof (*DriverInfoData));
- DriverInfo = &DriverInfoData->DriverInfo;
- DriverInfoData->Signature = MEMORY_PROFILE_DRIVER_INFO_SIGNATURE;
+ DriverInfo = &DriverInfoData->DriverInfo;
+ DriverInfoData->Signature = MEMORY_PROFILE_DRIVER_INFO_SIGNATURE;
DriverInfo->Header.Signature = MEMORY_PROFILE_DRIVER_INFO_SIGNATURE;
- DriverInfo->Header.Length = (UINT16) (sizeof (MEMORY_PROFILE_DRIVER_INFO) + PdbOccupiedSize);
- DriverInfo->Header.Revision = MEMORY_PROFILE_DRIVER_INFO_REVISION;
+ DriverInfo->Header.Length = (UINT16)(sizeof (MEMORY_PROFILE_DRIVER_INFO) + PdbOccupiedSize);
+ DriverInfo->Header.Revision = MEMORY_PROFILE_DRIVER_INFO_REVISION;
if (FileName != NULL) {
CopyMem (&DriverInfo->FileName, FileName, sizeof (EFI_GUID));
}
- DriverInfo->ImageBase = ImageBase;
- DriverInfo->ImageSize = ImageSize;
- DriverInfo->EntryPoint = EntryPoint;
+
+ DriverInfo->ImageBase = ImageBase;
+ DriverInfo->ImageSize = ImageSize;
+ DriverInfo->EntryPoint = EntryPoint;
DriverInfo->ImageSubsystem = ImageSubsystem;
if ((EntryPoint != 0) && ((EntryPoint < ImageBase) || (EntryPoint >= (ImageBase + ImageSize)))) {
//
// If the EntryPoint is not in the range of image buffer, it should come from emulation environment.
// So patch ImageBuffer here to align the EntryPoint.
//
- Status = InternalPeCoffGetEntryPoint ((VOID *) (UINTN) ImageBase, &EntryPointInImage);
+ Status = InternalPeCoffGetEntryPoint ((VOID *)(UINTN)ImageBase, &EntryPointInImage);
ASSERT_EFI_ERROR (Status);
- DriverInfo->ImageBase = ImageBase + EntryPoint - (PHYSICAL_ADDRESS) (UINTN) EntryPointInImage;
+ DriverInfo->ImageBase = ImageBase + EntryPoint - (PHYSICAL_ADDRESS)(UINTN)EntryPointInImage;
}
- DriverInfo->FileType = FileType;
- DriverInfoData->AllocInfoList = (LIST_ENTRY *) (DriverInfoData + 1);
+
+ DriverInfo->FileType = FileType;
+ DriverInfoData->AllocInfoList = (LIST_ENTRY *)(DriverInfoData + 1);
InitializeListHead (DriverInfoData->AllocInfoList);
- DriverInfo->CurrentUsage = 0;
- DriverInfo->PeakUsage = 0;
+ DriverInfo->CurrentUsage = 0;
+ DriverInfo->PeakUsage = 0;
DriverInfo->AllocRecordCount = 0;
if (PdbSize != 0) {
- DriverInfo->PdbStringOffset = (UINT16) sizeof (MEMORY_PROFILE_DRIVER_INFO);
- DriverInfoData->PdbString = (CHAR8 *) (DriverInfoData->AllocInfoList + 1);
+ DriverInfo->PdbStringOffset = (UINT16)sizeof (MEMORY_PROFILE_DRIVER_INFO);
+ DriverInfoData->PdbString = (CHAR8 *)(DriverInfoData->AllocInfoList + 1);
CopyMem (DriverInfoData->PdbString, PdbString, PdbSize);
} else {
DriverInfo->PdbStringOffset = 0;
- DriverInfoData->PdbString = NULL;
+ DriverInfoData->PdbString = NULL;
}
InsertTailList (ContextData->DriverInfoList, &DriverInfoData->Link);
- ContextData->Context.ImageCount ++;
+ ContextData->Context.ImageCount++;
ContextData->Context.TotalImageSize += DriverInfo->ImageSize;
return DriverInfoData;
@@ -465,13 +467,13 @@ BuildDriverInfo (
**/
BOOLEAN
NeedRecordThisDriver (
- IN EFI_DEVICE_PATH_PROTOCOL *DriverFilePath
+ IN EFI_DEVICE_PATH_PROTOCOL *DriverFilePath
)
{
- EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath;
- EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance;
- UINTN DevicePathSize;
- UINTN FilePathSize;
+ EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance;
+ UINTN DevicePathSize;
+ UINTN FilePathSize;
if (!IsDevicePathValid (mMemoryProfileDriverPath, mMemoryProfileDriverPathSize)) {
//
@@ -483,7 +485,7 @@ NeedRecordThisDriver (
//
// Record FilePath without END node.
//
- FilePathSize = GetDevicePathSize (DriverFilePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL);
+ FilePathSize = GetDevicePathSize (DriverFilePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL);
DevicePathInstance = mMemoryProfileDriverPath;
do {
@@ -500,14 +502,15 @@ NeedRecordThisDriver (
//
DevicePathSize = (UINTN)TmpDevicePath - (UINTN)DevicePathInstance;
if ((FilePathSize == DevicePathSize) &&
- (CompareMem (DriverFilePath, DevicePathInstance, DevicePathSize) == 0)) {
+ (CompareMem (DriverFilePath, DevicePathInstance, DevicePathSize) == 0))
+ {
return TRUE;
}
//
// Get next instance.
//
- DevicePathInstance = (EFI_DEVICE_PATH_PROTOCOL *)((UINTN)DevicePathInstance + DevicePathSize + DevicePathNodeLength(TmpDevicePath));
+ DevicePathInstance = (EFI_DEVICE_PATH_PROTOCOL *)((UINTN)DevicePathInstance + DevicePathSize + DevicePathNodeLength (TmpDevicePath));
} while (DevicePathSubType (TmpDevicePath) != END_ENTIRE_DEVICE_PATH_SUBTYPE);
return FALSE;
@@ -525,22 +528,22 @@ NeedRecordThisDriver (
**/
BOOLEAN
RegisterDxeCore (
- IN VOID *HobStart,
- IN MEMORY_PROFILE_CONTEXT_DATA *ContextData
+ IN VOID *HobStart,
+ IN MEMORY_PROFILE_CONTEXT_DATA *ContextData
)
{
- EFI_PEI_HOB_POINTERS DxeCoreHob;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- PHYSICAL_ADDRESS ImageBase;
- UINT8 TempBuffer[sizeof(MEDIA_FW_VOL_FILEPATH_DEVICE_PATH) + sizeof(EFI_DEVICE_PATH_PROTOCOL)];
- MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FilePath;
+ EFI_PEI_HOB_POINTERS DxeCoreHob;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ PHYSICAL_ADDRESS ImageBase;
+ UINT8 TempBuffer[sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH) + sizeof (EFI_DEVICE_PATH_PROTOCOL)];
+ MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FilePath;
ASSERT (ContextData != NULL);
//
// Searching for image hob
//
- DxeCoreHob.Raw = HobStart;
+ DxeCoreHob.Raw = HobStart;
while ((DxeCoreHob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, DxeCoreHob.Raw)) != NULL) {
if (CompareGuid (&DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.Name, &gEfiHobMemoryAllocModuleGuid)) {
//
@@ -548,26 +551,28 @@ RegisterDxeCore (
//
break;
}
+
DxeCoreHob.Raw = GET_NEXT_HOB (DxeCoreHob);
}
+
ASSERT (DxeCoreHob.Raw != NULL);
- FilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) TempBuffer;
+ FilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)TempBuffer;
EfiInitializeFwVolDevicepathNode (FilePath, &DxeCoreHob.MemoryAllocationModule->ModuleName);
SetDevicePathEndNode (FilePath + 1);
- if (!NeedRecordThisDriver ((EFI_DEVICE_PATH_PROTOCOL *) FilePath)) {
+ if (!NeedRecordThisDriver ((EFI_DEVICE_PATH_PROTOCOL *)FilePath)) {
return FALSE;
}
- ImageBase = DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.MemoryBaseAddress;
+ ImageBase = DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.MemoryBaseAddress;
DriverInfoData = BuildDriverInfo (
ContextData,
&DxeCoreHob.MemoryAllocationModule->ModuleName,
ImageBase,
DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.MemoryLength,
DxeCoreHob.MemoryAllocationModule->EntryPoint,
- InternalPeCoffGetSubsystem ((VOID *) (UINTN) ImageBase),
+ InternalPeCoffGetSubsystem ((VOID *)(UINTN)ImageBase),
EFI_FV_FILETYPE_DXE_CORE
);
if (DriverInfoData == NULL) {
@@ -585,10 +590,10 @@ RegisterDxeCore (
**/
VOID
MemoryProfileInit (
- IN VOID *HobStart
+ IN VOID *HobStart
)
{
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
if (!IS_UEFI_MEMORY_PROFILE_ENABLED) {
return;
@@ -605,9 +610,10 @@ MemoryProfileInit (
} else {
mMemoryProfileRecordingEnable = MEMORY_PROFILE_RECORDING_ENABLE;
}
+
mMemoryProfileDriverPathSize = PcdGetSize (PcdMemoryProfileDriverPath);
- mMemoryProfileDriverPath = AllocateCopyPool (mMemoryProfileDriverPathSize, PcdGetPtr (PcdMemoryProfileDriverPath));
- mMemoryProfileContextPtr = &mMemoryProfileContext;
+ mMemoryProfileDriverPath = AllocateCopyPool (mMemoryProfileDriverPathSize, PcdGetPtr (PcdMemoryProfileDriverPath));
+ mMemoryProfileContextPtr = &mMemoryProfileContext;
RegisterDxeCore (HobStart, &mMemoryProfileContext);
@@ -623,8 +629,8 @@ MemoryProfileInstallProtocol (
VOID
)
{
- EFI_HANDLE Handle;
- EFI_STATUS Status;
+ EFI_HANDLE Handle;
+ EFI_STATUS Status;
if (!IS_UEFI_MEMORY_PROFILE_ENABLED) {
return;
@@ -650,21 +656,22 @@ MemoryProfileInstallProtocol (
**/
EFI_GUID *
GetFileNameFromFilePath (
- IN EFI_DEVICE_PATH_PROTOCOL *FilePath
+ IN EFI_DEVICE_PATH_PROTOCOL *FilePath
)
{
- MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *ThisFilePath;
- EFI_GUID *FileName;
+ MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *ThisFilePath;
+ EFI_GUID *FileName;
FileName = NULL;
if (FilePath != NULL) {
- ThisFilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) FilePath;
+ ThisFilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)FilePath;
while (!IsDevicePathEnd (ThisFilePath)) {
FileName = EfiGetNameGuidFromFwVolDevicePathNode (ThisFilePath);
if (FileName != NULL) {
break;
}
- ThisFilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) NextDevicePathNode (ThisFilePath);
+
+ ThisFilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)NextDevicePathNode (ThisFilePath);
}
}
@@ -689,8 +696,8 @@ RegisterMemoryProfileImage (
IN EFI_FV_FILETYPE FileType
)
{
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
if (!IS_UEFI_MEMORY_PROFILE_ENABLED) {
return EFI_UNSUPPORTED;
@@ -733,21 +740,22 @@ RegisterMemoryProfileImage (
**/
MEMORY_PROFILE_DRIVER_INFO_DATA *
GetMemoryProfileDriverInfoByFileNameAndAddress (
- IN MEMORY_PROFILE_CONTEXT_DATA *ContextData,
- IN EFI_GUID *FileName,
- IN PHYSICAL_ADDRESS Address
+ IN MEMORY_PROFILE_CONTEXT_DATA *ContextData,
+ IN EFI_GUID *FileName,
+ IN PHYSICAL_ADDRESS Address
)
{
- MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- LIST_ENTRY *DriverLink;
- LIST_ENTRY *DriverInfoList;
+ MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ LIST_ENTRY *DriverLink;
+ LIST_ENTRY *DriverInfoList;
DriverInfoList = ContextData->DriverInfoList;
for (DriverLink = DriverInfoList->ForwardLink;
DriverLink != DriverInfoList;
- DriverLink = DriverLink->ForwardLink) {
+ DriverLink = DriverLink->ForwardLink)
+ {
DriverInfoData = CR (
DriverLink,
MEMORY_PROFILE_DRIVER_INFO_DATA,
@@ -757,7 +765,8 @@ GetMemoryProfileDriverInfoByFileNameAndAddress (
DriverInfo = &DriverInfoData->DriverInfo;
if ((CompareGuid (&DriverInfo->FileName, FileName)) &&
(Address >= DriverInfo->ImageBase) &&
- (Address < (DriverInfo->ImageBase + DriverInfo->ImageSize))) {
+ (Address < (DriverInfo->ImageBase + DriverInfo->ImageSize)))
+ {
return DriverInfoData;
}
}
@@ -777,20 +786,21 @@ GetMemoryProfileDriverInfoByFileNameAndAddress (
**/
MEMORY_PROFILE_DRIVER_INFO_DATA *
GetMemoryProfileDriverInfoFromAddress (
- IN MEMORY_PROFILE_CONTEXT_DATA *ContextData,
- IN PHYSICAL_ADDRESS Address
+ IN MEMORY_PROFILE_CONTEXT_DATA *ContextData,
+ IN PHYSICAL_ADDRESS Address
)
{
- MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- LIST_ENTRY *DriverLink;
- LIST_ENTRY *DriverInfoList;
+ MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ LIST_ENTRY *DriverLink;
+ LIST_ENTRY *DriverInfoList;
DriverInfoList = ContextData->DriverInfoList;
for (DriverLink = DriverInfoList->ForwardLink;
DriverLink != DriverInfoList;
- DriverLink = DriverLink->ForwardLink) {
+ DriverLink = DriverLink->ForwardLink)
+ {
DriverInfoData = CR (
DriverLink,
MEMORY_PROFILE_DRIVER_INFO_DATA,
@@ -799,7 +809,8 @@ GetMemoryProfileDriverInfoFromAddress (
);
DriverInfo = &DriverInfoData->DriverInfo;
if ((Address >= DriverInfo->ImageBase) &&
- (Address < (DriverInfo->ImageBase + DriverInfo->ImageSize))) {
+ (Address < (DriverInfo->ImageBase + DriverInfo->ImageSize)))
+ {
return DriverInfoData;
}
}
@@ -820,15 +831,15 @@ GetMemoryProfileDriverInfoFromAddress (
**/
EFI_STATUS
UnregisterMemoryProfileImage (
- IN LOADED_IMAGE_PRIVATE_DATA *DriverEntry
+ IN LOADED_IMAGE_PRIVATE_DATA *DriverEntry
)
{
- EFI_STATUS Status;
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- EFI_GUID *FileName;
- PHYSICAL_ADDRESS ImageAddress;
- VOID *EntryPointInImage;
+ EFI_STATUS Status;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ EFI_GUID *FileName;
+ PHYSICAL_ADDRESS ImageAddress;
+ VOID *EntryPointInImage;
if (!IS_UEFI_MEMORY_PROFILE_ENABLED) {
return EFI_UNSUPPORTED;
@@ -844,23 +855,26 @@ UnregisterMemoryProfileImage (
}
DriverInfoData = NULL;
- FileName = GetFileNameFromFilePath (DriverEntry->Info.FilePath);
- ImageAddress = DriverEntry->ImageContext.ImageAddress;
+ FileName = GetFileNameFromFilePath (DriverEntry->Info.FilePath);
+ ImageAddress = DriverEntry->ImageContext.ImageAddress;
if ((DriverEntry->ImageContext.EntryPoint < ImageAddress) || (DriverEntry->ImageContext.EntryPoint >= (ImageAddress + DriverEntry->ImageContext.ImageSize))) {
//
// If the EntryPoint is not in the range of image buffer, it should come from emulation environment.
// So patch ImageAddress here to align the EntryPoint.
//
- Status = InternalPeCoffGetEntryPoint ((VOID *) (UINTN) ImageAddress, &EntryPointInImage);
+ Status = InternalPeCoffGetEntryPoint ((VOID *)(UINTN)ImageAddress, &EntryPointInImage);
ASSERT_EFI_ERROR (Status);
- ImageAddress = ImageAddress + (UINTN) DriverEntry->ImageContext.EntryPoint - (UINTN) EntryPointInImage;
+ ImageAddress = ImageAddress + (UINTN)DriverEntry->ImageContext.EntryPoint - (UINTN)EntryPointInImage;
}
+
if (FileName != NULL) {
DriverInfoData = GetMemoryProfileDriverInfoByFileNameAndAddress (ContextData, FileName, ImageAddress);
}
+
if (DriverInfoData == NULL) {
DriverInfoData = GetMemoryProfileDriverInfoFromAddress (ContextData, ImageAddress);
}
+
if (DriverInfoData == NULL) {
return EFI_NOT_FOUND;
}
@@ -868,11 +882,11 @@ UnregisterMemoryProfileImage (
ContextData->Context.TotalImageSize -= DriverInfoData->DriverInfo.ImageSize;
// Keep the ImageBase for RVA calculation in Application.
- //DriverInfoData->DriverInfo.ImageBase = 0;
+ // DriverInfoData->DriverInfo.ImageBase = 0;
DriverInfoData->DriverInfo.ImageSize = 0;
if (DriverInfoData->DriverInfo.PeakUsage == 0) {
- ContextData->Context.ImageCount --;
+ ContextData->Context.ImageCount--;
RemoveEntryList (&DriverInfoData->Link);
//
// Use CoreInternalFreePool() that will not update profile for this FreePool action.
@@ -897,14 +911,14 @@ UnregisterMemoryProfileImage (
**/
BOOLEAN
CoreNeedRecordProfile (
- IN EFI_MEMORY_TYPE MemoryType
+ IN EFI_MEMORY_TYPE MemoryType
)
{
- UINT64 TestBit;
+ UINT64 TestBit;
- if ((UINT32) MemoryType >= MEMORY_TYPE_OS_RESERVED_MIN) {
+ if ((UINT32)MemoryType >= MEMORY_TYPE_OS_RESERVED_MIN) {
TestBit = BIT63;
- } else if ((UINT32) MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {
+ } else if ((UINT32)MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {
TestBit = BIT62;
} else {
TestBit = LShiftU64 (1, MemoryType);
@@ -930,12 +944,12 @@ CoreNeedRecordProfile (
**/
UINTN
GetProfileMemoryIndex (
- IN EFI_MEMORY_TYPE MemoryType
+ IN EFI_MEMORY_TYPE MemoryType
)
{
- if ((UINT32) MemoryType >= MEMORY_TYPE_OS_RESERVED_MIN) {
+ if ((UINT32)MemoryType >= MEMORY_TYPE_OS_RESERVED_MIN) {
return EfiMaxMemoryType;
- } else if ((UINT32) MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {
+ } else if ((UINT32)MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {
return EfiMaxMemoryType + 1;
} else {
return MemoryType;
@@ -968,17 +982,17 @@ CoreUpdateProfileAllocate (
IN CHAR8 *ActionString OPTIONAL
)
{
- EFI_STATUS Status;
- MEMORY_PROFILE_CONTEXT *Context;
- MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
- MEMORY_PROFILE_ALLOC_INFO *AllocInfo;
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- MEMORY_PROFILE_ALLOC_INFO_DATA *AllocInfoData;
- UINTN ProfileMemoryIndex;
- MEMORY_PROFILE_ACTION BasicAction;
- UINTN ActionStringSize;
- UINTN ActionStringOccupiedSize;
+ EFI_STATUS Status;
+ MEMORY_PROFILE_CONTEXT *Context;
+ MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
+ MEMORY_PROFILE_ALLOC_INFO *AllocInfo;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ MEMORY_PROFILE_ALLOC_INFO_DATA *AllocInfoData;
+ UINTN ProfileMemoryIndex;
+ MEMORY_PROFILE_ACTION BasicAction;
+ UINTN ActionStringSize;
+ UINTN ActionStringOccupiedSize;
BasicAction = Action & MEMORY_PROFILE_ACTION_BASIC_MASK;
@@ -992,10 +1006,10 @@ CoreUpdateProfileAllocate (
return EFI_UNSUPPORTED;
}
- ActionStringSize = 0;
+ ActionStringSize = 0;
ActionStringOccupiedSize = 0;
if (ActionString != NULL) {
- ActionStringSize = AsciiStrSize (ActionString);
+ ActionStringSize = AsciiStrSize (ActionString);
ActionStringOccupiedSize = GET_OCCUPIED_SIZE (ActionStringSize, sizeof (UINT64));
}
@@ -1003,48 +1017,49 @@ CoreUpdateProfileAllocate (
// Use CoreInternalAllocatePool() that will not update profile for this AllocatePool action.
//
AllocInfoData = NULL;
- Status = CoreInternalAllocatePool (
- EfiBootServicesData,
- sizeof (*AllocInfoData) + ActionStringSize,
- (VOID **) &AllocInfoData
- );
+ Status = CoreInternalAllocatePool (
+ EfiBootServicesData,
+ sizeof (*AllocInfoData) + ActionStringSize,
+ (VOID **)&AllocInfoData
+ );
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
+
ASSERT (AllocInfoData != NULL);
//
// Only update SequenceCount if and only if it is basic action.
//
if (Action == BasicAction) {
- ContextData->Context.SequenceCount ++;
+ ContextData->Context.SequenceCount++;
}
- AllocInfo = &AllocInfoData->AllocInfo;
- AllocInfoData->Signature = MEMORY_PROFILE_ALLOC_INFO_SIGNATURE;
- AllocInfo->Header.Signature = MEMORY_PROFILE_ALLOC_INFO_SIGNATURE;
- AllocInfo->Header.Length = (UINT16) (sizeof (MEMORY_PROFILE_ALLOC_INFO) + ActionStringOccupiedSize);
- AllocInfo->Header.Revision = MEMORY_PROFILE_ALLOC_INFO_REVISION;
- AllocInfo->CallerAddress = CallerAddress;
- AllocInfo->SequenceId = ContextData->Context.SequenceCount;
- AllocInfo->Action = Action;
- AllocInfo->MemoryType = MemoryType;
- AllocInfo->Buffer = (PHYSICAL_ADDRESS) (UINTN) Buffer;
- AllocInfo->Size = Size;
+ AllocInfo = &AllocInfoData->AllocInfo;
+ AllocInfoData->Signature = MEMORY_PROFILE_ALLOC_INFO_SIGNATURE;
+ AllocInfo->Header.Signature = MEMORY_PROFILE_ALLOC_INFO_SIGNATURE;
+ AllocInfo->Header.Length = (UINT16)(sizeof (MEMORY_PROFILE_ALLOC_INFO) + ActionStringOccupiedSize);
+ AllocInfo->Header.Revision = MEMORY_PROFILE_ALLOC_INFO_REVISION;
+ AllocInfo->CallerAddress = CallerAddress;
+ AllocInfo->SequenceId = ContextData->Context.SequenceCount;
+ AllocInfo->Action = Action;
+ AllocInfo->MemoryType = MemoryType;
+ AllocInfo->Buffer = (PHYSICAL_ADDRESS)(UINTN)Buffer;
+ AllocInfo->Size = Size;
if (ActionString != NULL) {
- AllocInfo->ActionStringOffset = (UINT16) sizeof (MEMORY_PROFILE_ALLOC_INFO);
- AllocInfoData->ActionString = (CHAR8 *) (AllocInfoData + 1);
+ AllocInfo->ActionStringOffset = (UINT16)sizeof (MEMORY_PROFILE_ALLOC_INFO);
+ AllocInfoData->ActionString = (CHAR8 *)(AllocInfoData + 1);
CopyMem (AllocInfoData->ActionString, ActionString, ActionStringSize);
} else {
AllocInfo->ActionStringOffset = 0;
- AllocInfoData->ActionString = NULL;
+ AllocInfoData->ActionString = NULL;
}
InsertTailList (DriverInfoData->AllocInfoList, &AllocInfoData->Link);
- Context = &ContextData->Context;
+ Context = &ContextData->Context;
DriverInfo = &DriverInfoData->DriverInfo;
- DriverInfo->AllocRecordCount ++;
+ DriverInfo->AllocRecordCount++;
//
// Update summary if and only if it is basic action.
@@ -1056,6 +1071,7 @@ CoreUpdateProfileAllocate (
if (DriverInfo->PeakUsage < DriverInfo->CurrentUsage) {
DriverInfo->PeakUsage = DriverInfo->CurrentUsage;
}
+
DriverInfo->CurrentUsageByType[ProfileMemoryIndex] += Size;
if (DriverInfo->PeakUsageByType[ProfileMemoryIndex] < DriverInfo->CurrentUsageByType[ProfileMemoryIndex]) {
DriverInfo->PeakUsageByType[ProfileMemoryIndex] = DriverInfo->CurrentUsageByType[ProfileMemoryIndex];
@@ -1065,6 +1081,7 @@ CoreUpdateProfileAllocate (
if (Context->PeakTotalUsage < Context->CurrentTotalUsage) {
Context->PeakTotalUsage = Context->CurrentTotalUsage;
}
+
Context->CurrentTotalUsageByType[ProfileMemoryIndex] += Size;
if (Context->PeakTotalUsageByType[ProfileMemoryIndex] < Context->CurrentTotalUsageByType[ProfileMemoryIndex]) {
Context->PeakTotalUsageByType[ProfileMemoryIndex] = Context->CurrentTotalUsageByType[ProfileMemoryIndex];
@@ -1087,22 +1104,23 @@ CoreUpdateProfileAllocate (
**/
MEMORY_PROFILE_ALLOC_INFO_DATA *
GetMemoryProfileAllocInfoFromAddress (
- IN MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData,
- IN MEMORY_PROFILE_ACTION BasicAction,
- IN UINTN Size,
- IN VOID *Buffer
+ IN MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData,
+ IN MEMORY_PROFILE_ACTION BasicAction,
+ IN UINTN Size,
+ IN VOID *Buffer
)
{
- LIST_ENTRY *AllocInfoList;
- LIST_ENTRY *AllocLink;
- MEMORY_PROFILE_ALLOC_INFO *AllocInfo;
- MEMORY_PROFILE_ALLOC_INFO_DATA *AllocInfoData;
+ LIST_ENTRY *AllocInfoList;
+ LIST_ENTRY *AllocLink;
+ MEMORY_PROFILE_ALLOC_INFO *AllocInfo;
+ MEMORY_PROFILE_ALLOC_INFO_DATA *AllocInfoData;
AllocInfoList = DriverInfoData->AllocInfoList;
for (AllocLink = AllocInfoList->ForwardLink;
AllocLink != AllocInfoList;
- AllocLink = AllocLink->ForwardLink) {
+ AllocLink = AllocLink->ForwardLink)
+ {
AllocInfoData = CR (
AllocLink,
MEMORY_PROFILE_ALLOC_INFO_DATA,
@@ -1113,17 +1131,21 @@ GetMemoryProfileAllocInfoFromAddress (
if ((AllocInfo->Action & MEMORY_PROFILE_ACTION_BASIC_MASK) != BasicAction) {
continue;
}
+
switch (BasicAction) {
case MemoryProfileActionAllocatePages:
- if ((AllocInfo->Buffer <= (PHYSICAL_ADDRESS) (UINTN) Buffer) &&
- ((AllocInfo->Buffer + AllocInfo->Size) >= ((PHYSICAL_ADDRESS) (UINTN) Buffer + Size))) {
+ if ((AllocInfo->Buffer <= (PHYSICAL_ADDRESS)(UINTN)Buffer) &&
+ ((AllocInfo->Buffer + AllocInfo->Size) >= ((PHYSICAL_ADDRESS)(UINTN)Buffer + Size)))
+ {
return AllocInfoData;
}
+
break;
case MemoryProfileActionAllocatePool:
- if (AllocInfo->Buffer == (PHYSICAL_ADDRESS) (UINTN) Buffer) {
+ if (AllocInfo->Buffer == (PHYSICAL_ADDRESS)(UINTN)Buffer) {
return AllocInfoData;
}
+
break;
default:
ASSERT (FALSE);
@@ -1186,7 +1208,7 @@ CoreUpdateProfileFree (
// Need use do-while loop to find all possible records,
// because one address might be recorded multiple times.
//
- Found = FALSE;
+ Found = FALSE;
AllocInfoData = NULL;
do {
if (DriverInfoData != NULL) {
@@ -1203,6 +1225,7 @@ CoreUpdateProfileFree (
break;
}
}
+
if (AllocInfoData == NULL) {
//
// Legal case, because driver A might free memory allocated by driver B, by some protocol.
@@ -1211,7 +1234,8 @@ CoreUpdateProfileFree (
for (DriverLink = DriverInfoList->ForwardLink;
DriverLink != DriverInfoList;
- DriverLink = DriverLink->ForwardLink) {
+ DriverLink = DriverLink->ForwardLink)
+ {
ThisDriverInfoData = CR (
DriverLink,
MEMORY_PROFILE_DRIVER_INFO_DATA,
@@ -1230,6 +1254,7 @@ CoreUpdateProfileFree (
AllocInfoData = NULL;
break;
}
+
if (AllocInfoData != NULL) {
DriverInfoData = ThisDriverInfoData;
break;
@@ -1254,44 +1279,45 @@ CoreUpdateProfileFree (
Found = TRUE;
- Context = &ContextData->Context;
+ Context = &ContextData->Context;
DriverInfo = &DriverInfoData->DriverInfo;
- AllocInfo = &AllocInfoData->AllocInfo;
+ AllocInfo = &AllocInfoData->AllocInfo;
- DriverInfo->AllocRecordCount --;
+ DriverInfo->AllocRecordCount--;
//
// Update summary if and only if it is basic action.
//
if (AllocInfo->Action == (AllocInfo->Action & MEMORY_PROFILE_ACTION_BASIC_MASK)) {
ProfileMemoryIndex = GetProfileMemoryIndex (AllocInfo->MemoryType);
- Context->CurrentTotalUsage -= AllocInfo->Size;
+ Context->CurrentTotalUsage -= AllocInfo->Size;
Context->CurrentTotalUsageByType[ProfileMemoryIndex] -= AllocInfo->Size;
- DriverInfo->CurrentUsage -= AllocInfo->Size;
+ DriverInfo->CurrentUsage -= AllocInfo->Size;
DriverInfo->CurrentUsageByType[ProfileMemoryIndex] -= AllocInfo->Size;
}
RemoveEntryList (&AllocInfoData->Link);
if (BasicAction == MemoryProfileActionFreePages) {
- if (AllocInfo->Buffer != (PHYSICAL_ADDRESS) (UINTN) Buffer) {
+ if (AllocInfo->Buffer != (PHYSICAL_ADDRESS)(UINTN)Buffer) {
CoreUpdateProfileAllocate (
AllocInfo->CallerAddress,
AllocInfo->Action,
AllocInfo->MemoryType,
- (UINTN) ((PHYSICAL_ADDRESS) (UINTN) Buffer - AllocInfo->Buffer),
- (VOID *) (UINTN) AllocInfo->Buffer,
+ (UINTN)((PHYSICAL_ADDRESS)(UINTN)Buffer - AllocInfo->Buffer),
+ (VOID *)(UINTN)AllocInfo->Buffer,
AllocInfoData->ActionString
);
}
- if (AllocInfo->Buffer + AllocInfo->Size != ((PHYSICAL_ADDRESS) (UINTN) Buffer + Size)) {
+
+ if (AllocInfo->Buffer + AllocInfo->Size != ((PHYSICAL_ADDRESS)(UINTN)Buffer + Size)) {
CoreUpdateProfileAllocate (
AllocInfo->CallerAddress,
AllocInfo->Action,
AllocInfo->MemoryType,
- (UINTN) ((AllocInfo->Buffer + AllocInfo->Size) - ((PHYSICAL_ADDRESS) (UINTN) Buffer + Size)),
- (VOID *) ((UINTN) Buffer + Size),
+ (UINTN)((AllocInfo->Buffer + AllocInfo->Size) - ((PHYSICAL_ADDRESS)(UINTN)Buffer + Size)),
+ (VOID *)((UINTN)Buffer + Size),
AllocInfoData->ActionString
);
}
@@ -1337,9 +1363,9 @@ CoreUpdateProfile (
IN CHAR8 *ActionString OPTIONAL
)
{
- EFI_STATUS Status;
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- MEMORY_PROFILE_ACTION BasicAction;
+ EFI_STATUS Status;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_ACTION BasicAction;
if (!IS_UEFI_MEMORY_PROFILE_ENABLED) {
return EFI_UNSUPPORTED;
@@ -1394,6 +1420,7 @@ CoreUpdateProfile (
Status = EFI_UNSUPPORTED;
break;
}
+
CoreReleaseMemoryProfileLock ();
return Status;
@@ -1412,15 +1439,14 @@ MemoryProfileGetDataSize (
VOID
)
{
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- MEMORY_PROFILE_ALLOC_INFO_DATA *AllocInfoData;
- LIST_ENTRY *DriverInfoList;
- LIST_ENTRY *DriverLink;
- LIST_ENTRY *AllocInfoList;
- LIST_ENTRY *AllocLink;
- UINTN TotalSize;
-
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ MEMORY_PROFILE_ALLOC_INFO_DATA *AllocInfoData;
+ LIST_ENTRY *DriverInfoList;
+ LIST_ENTRY *DriverLink;
+ LIST_ENTRY *AllocInfoList;
+ LIST_ENTRY *AllocLink;
+ UINTN TotalSize;
ContextData = GetMemoryProfileContext ();
if (ContextData == NULL) {
@@ -1432,7 +1458,8 @@ MemoryProfileGetDataSize (
DriverInfoList = ContextData->DriverInfoList;
for (DriverLink = DriverInfoList->ForwardLink;
DriverLink != DriverInfoList;
- DriverLink = DriverLink->ForwardLink) {
+ DriverLink = DriverLink->ForwardLink)
+ {
DriverInfoData = CR (
DriverLink,
MEMORY_PROFILE_DRIVER_INFO_DATA,
@@ -1444,7 +1471,8 @@ MemoryProfileGetDataSize (
AllocInfoList = DriverInfoData->AllocInfoList;
for (AllocLink = AllocInfoList->ForwardLink;
AllocLink != AllocInfoList;
- AllocLink = AllocLink->ForwardLink) {
+ AllocLink = AllocLink->ForwardLink)
+ {
AllocInfoData = CR (
AllocLink,
MEMORY_PROFILE_ALLOC_INFO_DATA,
@@ -1466,35 +1494,36 @@ MemoryProfileGetDataSize (
**/
VOID
MemoryProfileCopyData (
- IN VOID *ProfileBuffer
+ IN VOID *ProfileBuffer
)
{
- MEMORY_PROFILE_CONTEXT *Context;
- MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
- MEMORY_PROFILE_ALLOC_INFO *AllocInfo;
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- MEMORY_PROFILE_ALLOC_INFO_DATA *AllocInfoData;
- LIST_ENTRY *DriverInfoList;
- LIST_ENTRY *DriverLink;
- LIST_ENTRY *AllocInfoList;
- LIST_ENTRY *AllocLink;
- UINTN PdbSize;
- UINTN ActionStringSize;
+ MEMORY_PROFILE_CONTEXT *Context;
+ MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
+ MEMORY_PROFILE_ALLOC_INFO *AllocInfo;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ MEMORY_PROFILE_ALLOC_INFO_DATA *AllocInfoData;
+ LIST_ENTRY *DriverInfoList;
+ LIST_ENTRY *DriverLink;
+ LIST_ENTRY *AllocInfoList;
+ LIST_ENTRY *AllocLink;
+ UINTN PdbSize;
+ UINTN ActionStringSize;
ContextData = GetMemoryProfileContext ();
if (ContextData == NULL) {
- return ;
+ return;
}
Context = ProfileBuffer;
CopyMem (Context, &ContextData->Context, sizeof (MEMORY_PROFILE_CONTEXT));
- DriverInfo = (MEMORY_PROFILE_DRIVER_INFO *) (Context + 1);
+ DriverInfo = (MEMORY_PROFILE_DRIVER_INFO *)(Context + 1);
DriverInfoList = ContextData->DriverInfoList;
for (DriverLink = DriverInfoList->ForwardLink;
DriverLink != DriverInfoList;
- DriverLink = DriverLink->ForwardLink) {
+ DriverLink = DriverLink->ForwardLink)
+ {
DriverInfoData = CR (
DriverLink,
MEMORY_PROFILE_DRIVER_INFO_DATA,
@@ -1504,14 +1533,16 @@ MemoryProfileCopyData (
CopyMem (DriverInfo, &DriverInfoData->DriverInfo, sizeof (MEMORY_PROFILE_DRIVER_INFO));
if (DriverInfo->PdbStringOffset != 0) {
PdbSize = AsciiStrSize (DriverInfoData->PdbString);
- CopyMem ((VOID *) ((UINTN) DriverInfo + DriverInfo->PdbStringOffset), DriverInfoData->PdbString, PdbSize);
+ CopyMem ((VOID *)((UINTN)DriverInfo + DriverInfo->PdbStringOffset), DriverInfoData->PdbString, PdbSize);
}
- AllocInfo = (MEMORY_PROFILE_ALLOC_INFO *) ((UINTN) DriverInfo + DriverInfo->Header.Length);
+
+ AllocInfo = (MEMORY_PROFILE_ALLOC_INFO *)((UINTN)DriverInfo + DriverInfo->Header.Length);
AllocInfoList = DriverInfoData->AllocInfoList;
for (AllocLink = AllocInfoList->ForwardLink;
AllocLink != AllocInfoList;
- AllocLink = AllocLink->ForwardLink) {
+ AllocLink = AllocLink->ForwardLink)
+ {
AllocInfoData = CR (
AllocLink,
MEMORY_PROFILE_ALLOC_INFO_DATA,
@@ -1521,12 +1552,13 @@ MemoryProfileCopyData (
CopyMem (AllocInfo, &AllocInfoData->AllocInfo, sizeof (MEMORY_PROFILE_ALLOC_INFO));
if (AllocInfo->ActionStringOffset != 0) {
ActionStringSize = AsciiStrSize (AllocInfoData->ActionString);
- CopyMem ((VOID *) ((UINTN) AllocInfo + AllocInfo->ActionStringOffset), AllocInfoData->ActionString, ActionStringSize);
+ CopyMem ((VOID *)((UINTN)AllocInfo + AllocInfo->ActionStringOffset), AllocInfoData->ActionString, ActionStringSize);
}
- AllocInfo = (MEMORY_PROFILE_ALLOC_INFO *) ((UINTN) AllocInfo + AllocInfo->Header.Length);
+
+ AllocInfo = (MEMORY_PROFILE_ALLOC_INFO *)((UINTN)AllocInfo + AllocInfo->Header.Length);
}
- DriverInfo = (MEMORY_PROFILE_DRIVER_INFO *) AllocInfo;
+ DriverInfo = (MEMORY_PROFILE_DRIVER_INFO *)AllocInfo;
}
}
@@ -1549,25 +1581,25 @@ EFIAPI
ProfileProtocolGetData (
IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
IN OUT UINT64 *ProfileSize,
- OUT VOID *ProfileBuffer
+ OUT VOID *ProfileBuffer
)
{
- UINTN Size;
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- BOOLEAN MemoryProfileGettingStatus;
+ UINTN Size;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ BOOLEAN MemoryProfileGettingStatus;
ContextData = GetMemoryProfileContext ();
if (ContextData == NULL) {
return EFI_UNSUPPORTED;
}
- MemoryProfileGettingStatus = mMemoryProfileGettingStatus;
+ MemoryProfileGettingStatus = mMemoryProfileGettingStatus;
mMemoryProfileGettingStatus = TRUE;
Size = MemoryProfileGetDataSize ();
if (*ProfileSize < Size) {
- *ProfileSize = Size;
+ *ProfileSize = Size;
mMemoryProfileGettingStatus = MemoryProfileGettingStatus;
return EFI_BUFFER_TOO_SMALL;
}
@@ -1604,18 +1636,18 @@ ProfileProtocolRegisterImage (
IN EFI_FV_FILETYPE FileType
)
{
- EFI_STATUS Status;
- LOADED_IMAGE_PRIVATE_DATA DriverEntry;
- VOID *EntryPointInImage;
+ EFI_STATUS Status;
+ LOADED_IMAGE_PRIVATE_DATA DriverEntry;
+ VOID *EntryPointInImage;
ZeroMem (&DriverEntry, sizeof (DriverEntry));
- DriverEntry.Info.FilePath = FilePath;
+ DriverEntry.Info.FilePath = FilePath;
DriverEntry.ImageContext.ImageAddress = ImageBase;
- DriverEntry.ImageContext.ImageSize = ImageSize;
- Status = InternalPeCoffGetEntryPoint ((VOID *) (UINTN) ImageBase, &EntryPointInImage);
+ DriverEntry.ImageContext.ImageSize = ImageSize;
+ Status = InternalPeCoffGetEntryPoint ((VOID *)(UINTN)ImageBase, &EntryPointInImage);
ASSERT_EFI_ERROR (Status);
- DriverEntry.ImageContext.EntryPoint = (PHYSICAL_ADDRESS) (UINTN) EntryPointInImage;
- DriverEntry.ImageContext.ImageType = InternalPeCoffGetSubsystem ((VOID *) (UINTN) ImageBase);
+ DriverEntry.ImageContext.EntryPoint = (PHYSICAL_ADDRESS)(UINTN)EntryPointInImage;
+ DriverEntry.ImageContext.ImageType = InternalPeCoffGetSubsystem ((VOID *)(UINTN)ImageBase);
return RegisterMemoryProfileImage (&DriverEntry, FileType);
}
@@ -1643,17 +1675,17 @@ ProfileProtocolUnregisterImage (
IN UINT64 ImageSize
)
{
- EFI_STATUS Status;
- LOADED_IMAGE_PRIVATE_DATA DriverEntry;
- VOID *EntryPointInImage;
+ EFI_STATUS Status;
+ LOADED_IMAGE_PRIVATE_DATA DriverEntry;
+ VOID *EntryPointInImage;
ZeroMem (&DriverEntry, sizeof (DriverEntry));
- DriverEntry.Info.FilePath = FilePath;
+ DriverEntry.Info.FilePath = FilePath;
DriverEntry.ImageContext.ImageAddress = ImageBase;
- DriverEntry.ImageContext.ImageSize = ImageSize;
- Status = InternalPeCoffGetEntryPoint ((VOID *) (UINTN) ImageBase, &EntryPointInImage);
+ DriverEntry.ImageContext.ImageSize = ImageSize;
+ Status = InternalPeCoffGetEntryPoint ((VOID *)(UINTN)ImageBase, &EntryPointInImage);
ASSERT_EFI_ERROR (Status);
- DriverEntry.ImageContext.EntryPoint = (PHYSICAL_ADDRESS) (UINTN) EntryPointInImage;
+ DriverEntry.ImageContext.EntryPoint = (PHYSICAL_ADDRESS)(UINTN)EntryPointInImage;
return UnregisterMemoryProfileImage (&DriverEntry);
}
@@ -1672,11 +1704,11 @@ ProfileProtocolUnregisterImage (
EFI_STATUS
EFIAPI
ProfileProtocolGetRecordingState (
- IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
- OUT BOOLEAN *RecordingState
+ IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
+ OUT BOOLEAN *RecordingState
)
{
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
ContextData = GetMemoryProfileContext ();
if (ContextData == NULL) {
@@ -1686,6 +1718,7 @@ ProfileProtocolGetRecordingState (
if (RecordingState == NULL) {
return EFI_INVALID_PARAMETER;
}
+
*RecordingState = mMemoryProfileRecordingEnable;
return EFI_SUCCESS;
}
@@ -1703,11 +1736,11 @@ ProfileProtocolGetRecordingState (
EFI_STATUS
EFIAPI
ProfileProtocolSetRecordingState (
- IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
- IN BOOLEAN RecordingState
+ IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
+ IN BOOLEAN RecordingState
)
{
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
ContextData = GetMemoryProfileContext ();
if (ContextData == NULL) {
@@ -1744,13 +1777,13 @@ ProfileProtocolSetRecordingState (
EFI_STATUS
EFIAPI
ProfileProtocolRecord (
- IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
- IN PHYSICAL_ADDRESS CallerAddress,
- IN MEMORY_PROFILE_ACTION Action,
- IN EFI_MEMORY_TYPE MemoryType,
- IN VOID *Buffer,
- IN UINTN Size,
- IN CHAR8 *ActionString OPTIONAL
+ IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
+ IN PHYSICAL_ADDRESS CallerAddress,
+ IN MEMORY_PROFILE_ACTION Action,
+ IN EFI_MEMORY_TYPE MemoryType,
+ IN VOID *Buffer,
+ IN UINTN Size,
+ IN CHAR8 *ActionString OPTIONAL
)
{
return CoreUpdateProfile (CallerAddress, Action, MemoryType, Size, Buffer, ActionString);
diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c
index 731bf08..47d4c5d 100644
--- a/MdeModulePkg/Core/Dxe/Mem/Page.c
+++ b/MdeModulePkg/Core/Dxe/Mem/Page.c
@@ -14,38 +14,38 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// Entry for tracking the memory regions for each memory type to coalesce similar memory types
//
typedef struct {
- EFI_PHYSICAL_ADDRESS BaseAddress;
- EFI_PHYSICAL_ADDRESS MaximumAddress;
- UINT64 CurrentNumberOfPages;
- UINT64 NumberOfPages;
- UINTN InformationIndex;
- BOOLEAN Special;
- BOOLEAN Runtime;
+ EFI_PHYSICAL_ADDRESS BaseAddress;
+ EFI_PHYSICAL_ADDRESS MaximumAddress;
+ UINT64 CurrentNumberOfPages;
+ UINT64 NumberOfPages;
+ UINTN InformationIndex;
+ BOOLEAN Special;
+ BOOLEAN Runtime;
} EFI_MEMORY_TYPE_STATISTICS;
//
// MemoryMap - The current memory map
//
-UINTN mMemoryMapKey = 0;
+UINTN mMemoryMapKey = 0;
-#define MAX_MAP_DEPTH 6
+#define MAX_MAP_DEPTH 6
///
/// mMapDepth - depth of new descriptor stack
///
-UINTN mMapDepth = 0;
+UINTN mMapDepth = 0;
///
/// mMapStack - space to use as temp storage to build new map descriptors
///
-MEMORY_MAP mMapStack[MAX_MAP_DEPTH];
-UINTN mFreeMapStack = 0;
+MEMORY_MAP mMapStack[MAX_MAP_DEPTH];
+UINTN mFreeMapStack = 0;
///
/// This list maintain the free memory map list
///
-LIST_ENTRY mFreeMemoryMapEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mFreeMemoryMapEntryList);
-BOOLEAN mMemoryTypeInformationInitialized = FALSE;
+LIST_ENTRY mFreeMemoryMapEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mFreeMemoryMapEntryList);
+BOOLEAN mMemoryTypeInformationInitialized = FALSE;
-EFI_MEMORY_TYPE_STATISTICS mMemoryTypeStatistics[EfiMaxMemoryType + 1] = {
+EFI_MEMORY_TYPE_STATISTICS mMemoryTypeStatistics[EfiMaxMemoryType + 1] = {
{ 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, FALSE }, // EfiReservedMemoryType
{ 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiLoaderCode
{ 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiLoaderData
@@ -64,10 +64,10 @@ EFI_MEMORY_TYPE_STATISTICS mMemoryTypeStatistics[EfiMaxMemoryType + 1] = {
{ 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE } // EfiMaxMemoryType
};
-EFI_PHYSICAL_ADDRESS mDefaultMaximumAddress = MAX_ALLOC_ADDRESS;
-EFI_PHYSICAL_ADDRESS mDefaultBaseAddress = MAX_ALLOC_ADDRESS;
+EFI_PHYSICAL_ADDRESS mDefaultMaximumAddress = MAX_ALLOC_ADDRESS;
+EFI_PHYSICAL_ADDRESS mDefaultBaseAddress = MAX_ALLOC_ADDRESS;
-EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1] = {
+EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1] = {
{ EfiReservedMemoryType, 0 },
{ EfiLoaderCode, 0 },
{ EfiLoaderData, 0 },
@@ -90,7 +90,7 @@ EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1] = {
// and ready to load the module in to specified address.or else, the memory is not ready and module will be loaded at a
// address assigned by DXE core.
//
-GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN gLoadFixedAddressCodeMemoryReady = FALSE;
+GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN gLoadFixedAddressCodeMemoryReady = FALSE;
/**
Enter critical section by gaining lock on gMemoryLock.
@@ -104,8 +104,6 @@ CoreAcquireMemoryLock (
CoreAcquireLock (&gMemoryLock);
}
-
-
/**
Exit critical section by releasing lock on gMemoryLock.
@@ -118,9 +116,6 @@ CoreReleaseMemoryLock (
CoreReleaseLock (&gMemoryLock);
}
-
-
-
/**
Internal function. Removes a descriptor entry.
@@ -129,7 +124,7 @@ CoreReleaseMemoryLock (
**/
VOID
RemoveMemoryMapEntry (
- IN OUT MEMORY_MAP *Entry
+ IN OUT MEMORY_MAP *Entry
)
{
RemoveEntryList (&Entry->Link);
@@ -157,17 +152,17 @@ RemoveMemoryMapEntry (
**/
VOID
CoreAddRange (
- IN EFI_MEMORY_TYPE Type,
- IN EFI_PHYSICAL_ADDRESS Start,
- IN EFI_PHYSICAL_ADDRESS End,
- IN UINT64 Attribute
+ IN EFI_MEMORY_TYPE Type,
+ IN EFI_PHYSICAL_ADDRESS Start,
+ IN EFI_PHYSICAL_ADDRESS End,
+ IN UINT64 Attribute
)
{
- LIST_ENTRY *Link;
- MEMORY_MAP *Entry;
+ LIST_ENTRY *Link;
+ MEMORY_MAP *Entry;
ASSERT ((Start & EFI_PAGE_MASK) == 0);
- ASSERT (End > Start) ;
+ ASSERT (End > Start);
ASSERT_LOCKED (&gMemoryLock);
@@ -182,7 +177,7 @@ CoreAddRange (
// at address 0, then do not zero the page at address 0 because the page is being
// used for other purposes.
//
- if (Type == EfiConventionalMemory && Start == 0 && (End >= EFI_PAGE_SIZE - 1)) {
+ if ((Type == EfiConventionalMemory) && (Start == 0) && (End >= EFI_PAGE_SIZE - 1)) {
if ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT0) == 0) {
SetMem ((VOID *)(UINTN)Start, EFI_PAGE_SIZE, 0);
}
@@ -226,12 +221,9 @@ CoreAddRange (
}
if (Entry->End + 1 == Start) {
-
Start = Entry->Start;
RemoveMemoryMapEntry (Entry);
-
} else if (Entry->Start == End + 1) {
-
End = Entry->End;
RemoveMemoryMapEntry (Entry);
}
@@ -241,19 +233,19 @@ CoreAddRange (
// Add descriptor
//
- mMapStack[mMapDepth].Signature = MEMORY_MAP_SIGNATURE;
- mMapStack[mMapDepth].FromPages = FALSE;
- mMapStack[mMapDepth].Type = Type;
- mMapStack[mMapDepth].Start = Start;
- mMapStack[mMapDepth].End = End;
- mMapStack[mMapDepth].VirtualStart = 0;
- mMapStack[mMapDepth].Attribute = Attribute;
+ mMapStack[mMapDepth].Signature = MEMORY_MAP_SIGNATURE;
+ mMapStack[mMapDepth].FromPages = FALSE;
+ mMapStack[mMapDepth].Type = Type;
+ mMapStack[mMapDepth].Start = Start;
+ mMapStack[mMapDepth].End = End;
+ mMapStack[mMapDepth].VirtualStart = 0;
+ mMapStack[mMapDepth].Attribute = Attribute;
InsertTailList (&gMemoryMap, &mMapStack[mMapDepth].Link);
mMapDepth += 1;
ASSERT (mMapDepth < MAX_MAP_DEPTH);
- return ;
+ return;
}
/**
@@ -274,9 +266,9 @@ AllocateMemoryMapEntry (
VOID
)
{
- MEMORY_MAP* FreeDescriptorEntries;
- MEMORY_MAP* Entry;
- UINTN Index;
+ MEMORY_MAP *FreeDescriptorEntries;
+ MEMORY_MAP *Entry;
+ UINTN Index;
if (IsListEmpty (&mFreeMemoryMapEntryList)) {
//
@@ -292,7 +284,7 @@ AllocateMemoryMapEntry (
//
// Enque the free memmory map entries into the list
//
- for (Index = 0; Index < DEFAULT_PAGE_ALLOCATION_GRANULARITY / sizeof(MEMORY_MAP); Index++) {
+ for (Index = 0; Index < DEFAULT_PAGE_ALLOCATION_GRANULARITY / sizeof (MEMORY_MAP); Index++) {
FreeDescriptorEntries[Index].Signature = MEMORY_MAP_SIGNATURE;
InsertTailList (&mFreeMemoryMapEntryList, &FreeDescriptorEntries[Index].Link);
}
@@ -300,6 +292,7 @@ AllocateMemoryMapEntry (
return NULL;
}
}
+
//
// dequeue the first descriptor from the list
//
@@ -309,7 +302,6 @@ AllocateMemoryMapEntry (
return Entry;
}
-
/**
Internal function. Moves any memory descriptors that are on the
temporary descriptor stack to heap.
@@ -320,9 +312,9 @@ CoreFreeMemoryMapStack (
VOID
)
{
- MEMORY_MAP *Entry;
- MEMORY_MAP *Entry2;
- LIST_ENTRY *Link2;
+ MEMORY_MAP *Entry;
+ MEMORY_MAP *Entry2;
+ LIST_ENTRY *Link2;
ASSERT_LOCKED (&gMemoryLock);
@@ -330,7 +322,7 @@ CoreFreeMemoryMapStack (
// If already freeing the map stack, then return
//
if (mFreeMapStack != 0) {
- return ;
+ return;
}
//
@@ -352,14 +344,13 @@ CoreFreeMemoryMapStack (
mMapDepth -= 1;
if (mMapStack[mMapDepth].Link.ForwardLink != NULL) {
-
//
// Move this entry to general memory
//
RemoveEntryList (&mMapStack[mMapDepth].Link);
mMapStack[mMapDepth].Link.ForwardLink = NULL;
- CopyMem (Entry , &mMapStack[mMapDepth], sizeof (MEMORY_MAP));
+ CopyMem (Entry, &mMapStack[mMapDepth], sizeof (MEMORY_MAP));
Entry->FromPages = TRUE;
//
@@ -367,13 +358,12 @@ CoreFreeMemoryMapStack (
//
for (Link2 = gMemoryMap.ForwardLink; Link2 != &gMemoryMap; Link2 = Link2->ForwardLink) {
Entry2 = CR (Link2, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
- if (Entry2->FromPages && Entry2->Start > Entry->Start) {
+ if (Entry2->FromPages && (Entry2->Start > Entry->Start)) {
break;
}
}
InsertTailList (Link2, &Entry->Link);
-
} else {
//
// This item of mMapStack[mMapDepth] has already been dequeued from gMemoryMap list,
@@ -395,27 +385,27 @@ PromoteMemoryResource (
VOID
)
{
- LIST_ENTRY *Link;
- EFI_GCD_MAP_ENTRY *Entry;
- BOOLEAN Promoted;
- EFI_PHYSICAL_ADDRESS StartAddress;
- EFI_PHYSICAL_ADDRESS EndAddress;
- EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
+ LIST_ENTRY *Link;
+ EFI_GCD_MAP_ENTRY *Entry;
+ BOOLEAN Promoted;
+ EFI_PHYSICAL_ADDRESS StartAddress;
+ EFI_PHYSICAL_ADDRESS EndAddress;
+ EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
DEBUG ((DEBUG_PAGE, "Promote the memory resource\n"));
CoreAcquireGcdMemoryLock ();
Promoted = FALSE;
- Link = mGcdMemorySpaceMap.ForwardLink;
+ Link = mGcdMemorySpaceMap.ForwardLink;
while (Link != &mGcdMemorySpaceMap) {
-
Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
- if (Entry->GcdMemoryType == EfiGcdMemoryTypeReserved &&
- Entry->EndAddress < MAX_ALLOC_ADDRESS &&
- (Entry->Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
- (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED)) {
+ if ((Entry->GcdMemoryType == EfiGcdMemoryTypeReserved) &&
+ (Entry->EndAddress < MAX_ALLOC_ADDRESS) &&
+ ((Entry->Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
+ (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED)))
+ {
//
// Update the GCD map
//
@@ -424,9 +414,10 @@ PromoteMemoryResource (
} else {
Entry->GcdMemoryType = EfiGcdMemoryTypeSystemMemory;
}
+
Entry->Capabilities |= EFI_MEMORY_TESTED;
- Entry->ImageHandle = gDxeCoreImageHandle;
- Entry->DeviceHandle = NULL;
+ Entry->ImageHandle = gDxeCoreImageHandle;
+ Entry->DeviceHandle = NULL;
//
// Add to allocable system memory resource
@@ -468,6 +459,7 @@ PromoteMemoryResource (
return Promoted;
}
+
/**
This function try to allocate Runtime code & Boot time code memory range. If LMFA enabled, 2 patchable PCD
PcdLoadFixAddressRuntimeCodePageNumber & PcdLoadFixAddressBootTimeCodePageNumber which are set by tools will record the
@@ -479,58 +471,61 @@ CoreLoadingFixedAddressHook (
VOID
)
{
- UINT32 RuntimeCodePageNumber;
- UINT32 BootTimeCodePageNumber;
- EFI_PHYSICAL_ADDRESS RuntimeCodeBase;
- EFI_PHYSICAL_ADDRESS BootTimeCodeBase;
- EFI_STATUS Status;
-
- //
- // Make sure these 2 areas are not initialzied.
- //
- if (!gLoadFixedAddressCodeMemoryReady) {
- RuntimeCodePageNumber = PcdGet32(PcdLoadFixAddressRuntimeCodePageNumber);
- BootTimeCodePageNumber= PcdGet32(PcdLoadFixAddressBootTimeCodePageNumber);
- RuntimeCodeBase = (EFI_PHYSICAL_ADDRESS)(gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress - EFI_PAGES_TO_SIZE (RuntimeCodePageNumber));
- BootTimeCodeBase = (EFI_PHYSICAL_ADDRESS)(RuntimeCodeBase - EFI_PAGES_TO_SIZE (BootTimeCodePageNumber));
- //
- // Try to allocate runtime memory.
- //
- Status = CoreAllocatePages (
- AllocateAddress,
- EfiRuntimeServicesCode,
- RuntimeCodePageNumber,
- &RuntimeCodeBase
- );
- if (EFI_ERROR(Status)) {
- //
- // Runtime memory allocation failed
- //
- return;
- }
- //
- // Try to allocate boot memory.
- //
- Status = CoreAllocatePages (
- AllocateAddress,
- EfiBootServicesCode,
- BootTimeCodePageNumber,
- &BootTimeCodeBase
- );
- if (EFI_ERROR(Status)) {
- //
- // boot memory allocation failed. Free Runtime code range and will try the allocation again when
- // new memory range is installed.
- //
- CoreFreePages (
- RuntimeCodeBase,
- RuntimeCodePageNumber
- );
- return;
- }
- gLoadFixedAddressCodeMemoryReady = TRUE;
- }
- return;
+ UINT32 RuntimeCodePageNumber;
+ UINT32 BootTimeCodePageNumber;
+ EFI_PHYSICAL_ADDRESS RuntimeCodeBase;
+ EFI_PHYSICAL_ADDRESS BootTimeCodeBase;
+ EFI_STATUS Status;
+
+ //
+ // Make sure these 2 areas are not initialzied.
+ //
+ if (!gLoadFixedAddressCodeMemoryReady) {
+ RuntimeCodePageNumber = PcdGet32 (PcdLoadFixAddressRuntimeCodePageNumber);
+ BootTimeCodePageNumber = PcdGet32 (PcdLoadFixAddressBootTimeCodePageNumber);
+ RuntimeCodeBase = (EFI_PHYSICAL_ADDRESS)(gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress - EFI_PAGES_TO_SIZE (RuntimeCodePageNumber));
+ BootTimeCodeBase = (EFI_PHYSICAL_ADDRESS)(RuntimeCodeBase - EFI_PAGES_TO_SIZE (BootTimeCodePageNumber));
+ //
+ // Try to allocate runtime memory.
+ //
+ Status = CoreAllocatePages (
+ AllocateAddress,
+ EfiRuntimeServicesCode,
+ RuntimeCodePageNumber,
+ &RuntimeCodeBase
+ );
+ if (EFI_ERROR (Status)) {
+ //
+ // Runtime memory allocation failed
+ //
+ return;
+ }
+
+ //
+ // Try to allocate boot memory.
+ //
+ Status = CoreAllocatePages (
+ AllocateAddress,
+ EfiBootServicesCode,
+ BootTimeCodePageNumber,
+ &BootTimeCodeBase
+ );
+ if (EFI_ERROR (Status)) {
+ //
+ // boot memory allocation failed. Free Runtime code range and will try the allocation again when
+ // new memory range is installed.
+ //
+ CoreFreePages (
+ RuntimeCodeBase,
+ RuntimeCodePageNumber
+ );
+ return;
+ }
+
+ gLoadFixedAddressCodeMemoryReady = TRUE;
+ }
+
+ return;
}
/**
@@ -556,32 +551,37 @@ CoreAddMemoryDescriptor (
IN UINT64 Attribute
)
{
- EFI_PHYSICAL_ADDRESS End;
- EFI_STATUS Status;
- UINTN Index;
- UINTN FreeIndex;
+ EFI_PHYSICAL_ADDRESS End;
+ EFI_STATUS Status;
+ UINTN Index;
+ UINTN FreeIndex;
if ((Start & EFI_PAGE_MASK) != 0) {
return;
}
- if (Type >= EfiMaxMemoryType && Type < MEMORY_TYPE_OEM_RESERVED_MIN) {
+ if ((Type >= EfiMaxMemoryType) && (Type < MEMORY_TYPE_OEM_RESERVED_MIN)) {
return;
}
+
CoreAcquireMemoryLock ();
End = Start + LShiftU64 (NumberOfPages, EFI_PAGE_SHIFT) - 1;
CoreAddRange (Type, Start, End, Attribute);
CoreFreeMemoryMapStack ();
CoreReleaseMemoryLock ();
- ApplyMemoryProtectionPolicy (EfiMaxMemoryType, Type, Start,
- LShiftU64 (NumberOfPages, EFI_PAGE_SHIFT));
+ ApplyMemoryProtectionPolicy (
+ EfiMaxMemoryType,
+ Type,
+ Start,
+ LShiftU64 (NumberOfPages, EFI_PAGE_SHIFT)
+ );
//
// If Loading Module At Fixed Address feature is enabled. try to allocate memory with Runtime code & Boot time code type
//
- if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {
- CoreLoadingFixedAddressHook();
+ if (PcdGet64 (PcdLoadModuleAtFixAddressEnable) != 0) {
+ CoreLoadingFixedAddressHook ();
}
//
@@ -591,7 +591,6 @@ CoreAddMemoryDescriptor (
return;
}
-
//
// Loop through each memory type in the order specified by the gMemoryTypeInformation[] array
//
@@ -599,10 +598,11 @@ CoreAddMemoryDescriptor (
//
// Make sure the memory type in the gMemoryTypeInformation[] array is valid
//
- Type = (EFI_MEMORY_TYPE) (gMemoryTypeInformation[Index].Type);
+ Type = (EFI_MEMORY_TYPE)(gMemoryTypeInformation[Index].Type);
if ((UINT32)Type > EfiMaxMemoryType) {
continue;
}
+
if (gMemoryTypeInformation[Index].NumberOfPages != 0) {
//
// Allocate pages for the current memory type from the top of available memory
@@ -623,7 +623,7 @@ CoreAddMemoryDescriptor (
//
// Make sure the memory type in the gMemoryTypeInformation[] array is valid
//
- Type = (EFI_MEMORY_TYPE) (gMemoryTypeInformation[FreeIndex].Type);
+ Type = (EFI_MEMORY_TYPE)(gMemoryTypeInformation[FreeIndex].Type);
if ((UINT32)Type > EfiMaxMemoryType) {
continue;
}
@@ -637,6 +637,7 @@ CoreAddMemoryDescriptor (
mMemoryTypeStatistics[Type].MaximumAddress = MAX_ALLOC_ADDRESS;
}
}
+
return;
}
@@ -666,10 +667,11 @@ CoreAddMemoryDescriptor (
//
// Make sure the memory type in the gMemoryTypeInformation[] array is valid
//
- Type = (EFI_MEMORY_TYPE) (gMemoryTypeInformation[Index].Type);
+ Type = (EFI_MEMORY_TYPE)(gMemoryTypeInformation[Index].Type);
if ((UINT32)Type > EfiMaxMemoryType) {
continue;
}
+
if (gMemoryTypeInformation[Index].NumberOfPages != 0) {
CoreFreePages (
mMemoryTypeStatistics[Type].BaseAddress,
@@ -684,12 +686,13 @@ CoreAddMemoryDescriptor (
// If the number of pages reserved for a memory type is 0, then all allocations for that type
// should be in the default range.
//
- for (Type = (EFI_MEMORY_TYPE) 0; Type < EfiMaxMemoryType; Type++) {
+ for (Type = (EFI_MEMORY_TYPE)0; Type < EfiMaxMemoryType; Type++) {
for (Index = 0; gMemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) {
if (Type == (EFI_MEMORY_TYPE)gMemoryTypeInformation[Index].Type) {
mMemoryTypeStatistics[Type].InformationIndex = Index;
}
}
+
mMemoryTypeStatistics[Type].CurrentNumberOfPages = 0;
if (mMemoryTypeStatistics[Type].MaximumAddress == MAX_ALLOC_ADDRESS) {
mMemoryTypeStatistics[Type].MaximumAddress = mDefaultMaximumAddress;
@@ -699,7 +702,6 @@ CoreAddMemoryDescriptor (
mMemoryTypeInformationInitialized = TRUE;
}
-
/**
Internal function. Converts a memory range to the specified type or attributes.
The range must exist in the memory map. Either ChangingType or
@@ -730,26 +732,25 @@ CoreConvertPagesEx (
IN UINT64 NewAttributes
)
{
+ UINT64 NumberOfBytes;
+ UINT64 End;
+ UINT64 RangeEnd;
+ UINT64 Attribute;
+ EFI_MEMORY_TYPE MemType;
+ LIST_ENTRY *Link;
+ MEMORY_MAP *Entry;
- UINT64 NumberOfBytes;
- UINT64 End;
- UINT64 RangeEnd;
- UINT64 Attribute;
- EFI_MEMORY_TYPE MemType;
- LIST_ENTRY *Link;
- MEMORY_MAP *Entry;
-
- Entry = NULL;
+ Entry = NULL;
NumberOfBytes = LShiftU64 (NumberOfPages, EFI_PAGE_SHIFT);
- End = Start + NumberOfBytes - 1;
+ End = Start + NumberOfBytes - 1;
ASSERT (NumberOfPages);
ASSERT ((Start & EFI_PAGE_MASK) == 0);
- ASSERT (End > Start) ;
+ ASSERT (End > Start);
ASSERT_LOCKED (&gMemoryLock);
- ASSERT ( (ChangingType == FALSE) || (ChangingAttributes == FALSE) );
+ ASSERT ((ChangingType == FALSE) || (ChangingAttributes == FALSE));
- if (NumberOfPages == 0 || ((Start & EFI_PAGE_MASK) != 0) || (Start >= End)) {
+ if ((NumberOfPages == 0) || ((Start & EFI_PAGE_MASK) != 0) || (Start >= End)) {
return EFI_INVALID_PARAMETER;
}
@@ -758,14 +759,13 @@ CoreConvertPagesEx (
//
while (Start < End) {
-
//
// Find the entry that the covers the range
//
for (Link = gMemoryMap.ForwardLink; Link != &gMemoryMap; Link = Link->ForwardLink) {
Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
- if (Entry->Start <= Start && Entry->End > Start) {
+ if ((Entry->Start <= Start) && (Entry->End > Start)) {
break;
}
}
@@ -786,6 +786,7 @@ CoreConvertPagesEx (
return EFI_NOT_FOUND;
}
}
+
//
// Convert range to the end, or to the end of the descriptor
// if that's all we've got
@@ -800,6 +801,7 @@ CoreConvertPagesEx (
if (ChangingType) {
DEBUG ((DEBUG_PAGE, "ConvertRange: %lx-%lx to type %d\n", Start, RangeEnd, NewType));
}
+
if (ChangingAttributes) {
DEBUG ((DEBUG_PAGE, "ConvertRange: %lx-%lx to attr %lx\n", Start, RangeEnd, NewAttributes));
}
@@ -808,13 +810,14 @@ CoreConvertPagesEx (
//
// Debug code - verify conversion is allowed
//
- if (!(NewType == EfiConventionalMemory ? 1 : 0) ^ (Entry->Type == EfiConventionalMemory ? 1 : 0)) {
+ if (!((NewType == EfiConventionalMemory) ? 1 : 0) ^ ((Entry->Type == EfiConventionalMemory) ? 1 : 0)) {
DEBUG ((DEBUG_ERROR | DEBUG_PAGE, "ConvertPages: Incompatible memory types, "));
if (Entry->Type == EfiConventionalMemory) {
DEBUG ((DEBUG_ERROR | DEBUG_PAGE, "the pages to free have been freed\n"));
} else {
DEBUG ((DEBUG_ERROR | DEBUG_PAGE, "the pages to allocate have been allocated\n"));
}
+
return EFI_NOT_FOUND;
}
@@ -822,8 +825,9 @@ CoreConvertPagesEx (
// Update counters for the number of pages allocated to each memory type
//
if ((UINT32)Entry->Type < EfiMaxMemoryType) {
- if ((Start >= mMemoryTypeStatistics[Entry->Type].BaseAddress && Start <= mMemoryTypeStatistics[Entry->Type].MaximumAddress) ||
- (Start >= mDefaultBaseAddress && Start <= mDefaultMaximumAddress) ) {
+ if (((Start >= mMemoryTypeStatistics[Entry->Type].BaseAddress) && (Start <= mMemoryTypeStatistics[Entry->Type].MaximumAddress)) ||
+ ((Start >= mDefaultBaseAddress) && (Start <= mDefaultMaximumAddress)))
+ {
if (NumberOfPages > mMemoryTypeStatistics[Entry->Type].CurrentNumberOfPages) {
mMemoryTypeStatistics[Entry->Type].CurrentNumberOfPages = 0;
} else {
@@ -833,8 +837,9 @@ CoreConvertPagesEx (
}
if ((UINT32)NewType < EfiMaxMemoryType) {
- if ((Start >= mMemoryTypeStatistics[NewType].BaseAddress && Start <= mMemoryTypeStatistics[NewType].MaximumAddress) ||
- (Start >= mDefaultBaseAddress && Start <= mDefaultMaximumAddress) ) {
+ if (((Start >= mMemoryTypeStatistics[NewType].BaseAddress) && (Start <= mMemoryTypeStatistics[NewType].MaximumAddress)) ||
+ ((Start >= mDefaultBaseAddress) && (Start <= mDefaultMaximumAddress)))
+ {
mMemoryTypeStatistics[NewType].CurrentNumberOfPages += NumberOfPages;
if (mMemoryTypeStatistics[NewType].CurrentNumberOfPages > gMemoryTypeInformation[mMemoryTypeStatistics[NewType].InformationIndex].NumberOfPages) {
gMemoryTypeInformation[mMemoryTypeStatistics[NewType].InformationIndex].NumberOfPages = (UINT32)mMemoryTypeStatistics[NewType].CurrentNumberOfPages;
@@ -847,21 +852,16 @@ CoreConvertPagesEx (
// Pull range out of descriptor
//
if (Entry->Start == Start) {
-
//
// Clip start
//
Entry->Start = RangeEnd + 1;
-
} else if (Entry->End == RangeEnd) {
-
//
// Clip end
//
Entry->End = Start - 1;
-
} else {
-
//
// Pull it out of the center, clip current
//
@@ -870,7 +870,7 @@ CoreConvertPagesEx (
// Add a new one
//
mMapStack[mMapDepth].Signature = MEMORY_MAP_SIGNATURE;
- mMapStack[mMapDepth].FromPages = FALSE;
+ mMapStack[mMapDepth].FromPages = FALSE;
mMapStack[mMapDepth].Type = Entry->Type;
mMapStack[mMapDepth].Start = RangeEnd+1;
mMapStack[mMapDepth].End = Entry->End;
@@ -896,10 +896,10 @@ CoreConvertPagesEx (
//
if (ChangingType) {
Attribute = Entry->Attribute;
- MemType = NewType;
+ MemType = NewType;
} else {
Attribute = NewAttributes;
- MemType = Entry->Type;
+ MemType = Entry->Type;
}
//
@@ -916,7 +916,8 @@ CoreConvertPagesEx (
//
if (!IsHeapGuardEnabled (GUARD_HEAP_TYPE_FREED) ||
!ChangingType ||
- MemType != EfiConventionalMemory) {
+ (MemType != EfiConventionalMemory))
+ {
CoreAddRange (MemType, Start, RangeEnd, Attribute);
}
@@ -928,10 +929,10 @@ CoreConvertPagesEx (
//
if (Start == 0) {
if (RangeEnd > EFI_PAGE_SIZE) {
- DEBUG_CLEAR_MEMORY ((VOID *)(UINTN) EFI_PAGE_SIZE, (UINTN) (RangeEnd - EFI_PAGE_SIZE + 1));
+ DEBUG_CLEAR_MEMORY ((VOID *)(UINTN)EFI_PAGE_SIZE, (UINTN)(RangeEnd - EFI_PAGE_SIZE + 1));
}
} else {
- DEBUG_CLEAR_MEMORY ((VOID *)(UINTN) Start, (UINTN) (RangeEnd - Start + 1));
+ DEBUG_CLEAR_MEMORY ((VOID *)(UINTN)Start, (UINTN)(RangeEnd - Start + 1));
}
}
@@ -953,7 +954,6 @@ CoreConvertPagesEx (
return EFI_SUCCESS;
}
-
/**
Internal function. Converts a memory range to the specified type.
The range must exist in the memory map.
@@ -977,10 +977,9 @@ CoreConvertPages (
IN EFI_MEMORY_TYPE NewType
)
{
- return CoreConvertPagesEx(Start, NumberOfPages, TRUE, NewType, FALSE, 0);
+ return CoreConvertPagesEx (Start, NumberOfPages, TRUE, NewType, FALSE, 0);
}
-
/**
Internal function. Converts a memory range to use new attributes.
@@ -1002,12 +1001,11 @@ CoreUpdateMemoryAttributes (
//
// Update the attributes to the new value
//
- CoreConvertPagesEx(Start, NumberOfPages, FALSE, (EFI_MEMORY_TYPE)0, TRUE, NewAttributes);
+ CoreConvertPagesEx (Start, NumberOfPages, FALSE, (EFI_MEMORY_TYPE)0, TRUE, NewAttributes);
CoreReleaseMemoryLock ();
}
-
/**
Internal function. Finds a consecutive free page range below
the requested address.
@@ -1033,20 +1031,19 @@ CoreFindFreePagesI (
IN BOOLEAN NeedGuard
)
{
- UINT64 NumberOfBytes;
- UINT64 Target;
- UINT64 DescStart;
- UINT64 DescEnd;
- UINT64 DescNumberOfBytes;
- LIST_ENTRY *Link;
- MEMORY_MAP *Entry;
-
- if ((MaxAddress < EFI_PAGE_MASK) ||(NumberOfPages == 0)) {
+ UINT64 NumberOfBytes;
+ UINT64 Target;
+ UINT64 DescStart;
+ UINT64 DescEnd;
+ UINT64 DescNumberOfBytes;
+ LIST_ENTRY *Link;
+ MEMORY_MAP *Entry;
+
+ if ((MaxAddress < EFI_PAGE_MASK) || (NumberOfPages == 0)) {
return 0;
}
if ((MaxAddress & EFI_PAGE_MASK) != EFI_PAGE_MASK) {
-
//
// If MaxAddress is not aligned to the end of a page
//
@@ -1068,7 +1065,7 @@ CoreFindFreePagesI (
}
NumberOfBytes = LShiftU64 (NumberOfPages, EFI_PAGE_SHIFT);
- Target = 0;
+ Target = 0;
for (Link = gMemoryMap.ForwardLink; Link != &gMemoryMap; Link = Link->ForwardLink) {
Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
@@ -1081,7 +1078,7 @@ CoreFindFreePagesI (
}
DescStart = Entry->Start;
- DescEnd = Entry->End;
+ DescEnd = Entry->End;
//
// If desc is past max allowed address or below min allowed address, skip it
@@ -1153,7 +1150,6 @@ CoreFindFreePagesI (
return Target;
}
-
/**
Internal function. Finds a consecutive free page range below
the requested address
@@ -1170,19 +1166,19 @@ CoreFindFreePagesI (
**/
UINT64
FindFreePages (
- IN UINT64 MaxAddress,
- IN UINT64 NoPages,
- IN EFI_MEMORY_TYPE NewType,
- IN UINTN Alignment,
- IN BOOLEAN NeedGuard
- )
+ IN UINT64 MaxAddress,
+ IN UINT64 NoPages,
+ IN EFI_MEMORY_TYPE NewType,
+ IN UINTN Alignment,
+ IN BOOLEAN NeedGuard
+ )
{
- UINT64 Start;
+ UINT64 Start;
//
// Attempt to find free pages in the preferred bin based on the requested memory type
//
- if ((UINT32)NewType < EfiMaxMemoryType && MaxAddress >= mMemoryTypeStatistics[NewType].MaximumAddress) {
+ if (((UINT32)NewType < EfiMaxMemoryType) && (MaxAddress >= mMemoryTypeStatistics[NewType].MaximumAddress)) {
Start = CoreFindFreePagesI (
mMemoryTypeStatistics[NewType].MaximumAddress,
mMemoryTypeStatistics[NewType].BaseAddress,
@@ -1200,12 +1196,19 @@ FindFreePages (
// Attempt to find free pages in the default allocation bin
//
if (MaxAddress >= mDefaultMaximumAddress) {
- Start = CoreFindFreePagesI (mDefaultMaximumAddress, 0, NoPages, NewType,
- Alignment, NeedGuard);
+ Start = CoreFindFreePagesI (
+ mDefaultMaximumAddress,
+ 0,
+ NoPages,
+ NewType,
+ Alignment,
+ NeedGuard
+ );
if (Start != 0) {
if (Start < mDefaultBaseAddress) {
mDefaultBaseAddress = Start;
}
+
return Start;
}
}
@@ -1216,8 +1219,14 @@ FindFreePages (
// address range. If this allocation fails, then there are not enough
// resources anywhere to satisfy the request.
//
- Start = CoreFindFreePagesI (MaxAddress, 0, NoPages, NewType, Alignment,
- NeedGuard);
+ Start = CoreFindFreePagesI (
+ MaxAddress,
+ 0,
+ NoPages,
+ NewType,
+ Alignment,
+ NeedGuard
+ );
if (Start != 0) {
return Start;
}
@@ -1235,7 +1244,6 @@ FindFreePages (
return FindFreePages (MaxAddress, NoPages, NewType, Alignment, NeedGuard);
}
-
/**
Allocates pages from the memory map.
@@ -1258,11 +1266,11 @@ FindFreePages (
EFI_STATUS
EFIAPI
CoreInternalAllocatePages (
- IN EFI_ALLOCATE_TYPE Type,
- IN EFI_MEMORY_TYPE MemoryType,
- IN UINTN NumberOfPages,
+ IN EFI_ALLOCATE_TYPE Type,
+ IN EFI_MEMORY_TYPE MemoryType,
+ IN UINTN NumberOfPages,
IN OUT EFI_PHYSICAL_ADDRESS *Memory,
- IN BOOLEAN NeedGuard
+ IN BOOLEAN NeedGuard
)
{
EFI_STATUS Status;
@@ -1277,8 +1285,9 @@ CoreInternalAllocatePages (
return EFI_INVALID_PARAMETER;
}
- if ((MemoryType >= EfiMaxMemoryType && MemoryType < MEMORY_TYPE_OEM_RESERVED_MIN) ||
- (MemoryType == EfiConventionalMemory) || (MemoryType == EfiPersistentMemory)) {
+ if (((MemoryType >= EfiMaxMemoryType) && (MemoryType < MEMORY_TYPE_OEM_RESERVED_MIN)) ||
+ (MemoryType == EfiConventionalMemory) || (MemoryType == EfiPersistentMemory))
+ {
return EFI_INVALID_PARAMETER;
}
@@ -1288,11 +1297,11 @@ CoreInternalAllocatePages (
Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
- if (MemoryType == EfiACPIReclaimMemory ||
- MemoryType == EfiACPIMemoryNVS ||
- MemoryType == EfiRuntimeServicesCode ||
- MemoryType == EfiRuntimeServicesData) {
-
+ if ((MemoryType == EfiACPIReclaimMemory) ||
+ (MemoryType == EfiACPIMemoryNVS) ||
+ (MemoryType == EfiRuntimeServicesCode) ||
+ (MemoryType == EfiRuntimeServicesData))
+ {
Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
}
@@ -1327,15 +1336,18 @@ CoreInternalAllocatePages (
//
if (Type == AllocateAddress) {
if ((NumberOfPages == 0) ||
- (NumberOfPages > RShiftU64 (MaxAddress, EFI_PAGE_SHIFT))) {
+ (NumberOfPages > RShiftU64 (MaxAddress, EFI_PAGE_SHIFT)))
+ {
return EFI_NOT_FOUND;
}
+
NumberOfBytes = LShiftU64 (NumberOfPages, EFI_PAGE_SHIFT);
- End = Start + NumberOfBytes - 1;
+ End = Start + NumberOfBytes - 1;
if ((Start >= End) ||
(Start > MaxAddress) ||
- (End > MaxAddress)) {
+ (End > MaxAddress))
+ {
return EFI_NOT_FOUND;
}
@@ -1347,20 +1359,26 @@ CoreInternalAllocatePages (
// fragmented.
//
- for (CheckType = (EFI_MEMORY_TYPE) 0; CheckType < EfiMaxMemoryType; CheckType++) {
- if (MemoryType != CheckType &&
+ for (CheckType = (EFI_MEMORY_TYPE)0; CheckType < EfiMaxMemoryType; CheckType++) {
+ if ((MemoryType != CheckType) &&
mMemoryTypeStatistics[CheckType].Special &&
- mMemoryTypeStatistics[CheckType].NumberOfPages > 0) {
- if (Start >= mMemoryTypeStatistics[CheckType].BaseAddress &&
- Start <= mMemoryTypeStatistics[CheckType].MaximumAddress) {
+ (mMemoryTypeStatistics[CheckType].NumberOfPages > 0))
+ {
+ if ((Start >= mMemoryTypeStatistics[CheckType].BaseAddress) &&
+ (Start <= mMemoryTypeStatistics[CheckType].MaximumAddress))
+ {
return EFI_NOT_FOUND;
}
- if (End >= mMemoryTypeStatistics[CheckType].BaseAddress &&
- End <= mMemoryTypeStatistics[CheckType].MaximumAddress) {
+
+ if ((End >= mMemoryTypeStatistics[CheckType].BaseAddress) &&
+ (End <= mMemoryTypeStatistics[CheckType].MaximumAddress))
+ {
return EFI_NOT_FOUND;
}
- if (Start < mMemoryTypeStatistics[CheckType].BaseAddress &&
- End > mMemoryTypeStatistics[CheckType].MaximumAddress) {
+
+ if ((Start < mMemoryTypeStatistics[CheckType].BaseAddress) &&
+ (End > mMemoryTypeStatistics[CheckType].MaximumAddress))
+ {
return EFI_NOT_FOUND;
}
}
@@ -1377,8 +1395,13 @@ CoreInternalAllocatePages (
// If not a specific address, then find an address to allocate
//
if (Type != AllocateAddress) {
- Start = FindFreePages (MaxAddress, NumberOfPages, MemoryType, Alignment,
- NeedGuard);
+ Start = FindFreePages (
+ MaxAddress,
+ NumberOfPages,
+ MemoryType,
+ Alignment,
+ NeedGuard
+ );
if (Start == 0) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
@@ -1389,9 +1412,9 @@ CoreInternalAllocatePages (
// Convert pages from FreeMemory to the requested type
//
if (NeedGuard) {
- Status = CoreConvertPagesWithGuard(Start, NumberOfPages, MemoryType);
+ Status = CoreConvertPagesWithGuard (Start, NumberOfPages, MemoryType);
} else {
- Status = CoreConvertPages(Start, NumberOfPages, MemoryType);
+ Status = CoreConvertPages (Start, NumberOfPages, MemoryType);
}
Done:
@@ -1401,6 +1424,7 @@ Done:
if (NeedGuard) {
SetGuardForMemory (Start, NumberOfPages);
}
+
*Memory = Start;
}
@@ -1438,21 +1462,31 @@ CoreAllocatePages (
BOOLEAN NeedGuard;
NeedGuard = IsPageTypeToGuard (MemoryType, Type) && !mOnGuarding;
- Status = CoreInternalAllocatePages (Type, MemoryType, NumberOfPages, Memory,
- NeedGuard);
+ Status = CoreInternalAllocatePages (
+ Type,
+ MemoryType,
+ NumberOfPages,
+ Memory,
+ NeedGuard
+ );
if (!EFI_ERROR (Status)) {
CoreUpdateProfile (
- (EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),
+ (EFI_PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),
MemoryProfileActionAllocatePages,
MemoryType,
EFI_PAGES_TO_SIZE (NumberOfPages),
- (VOID *) (UINTN) *Memory,
+ (VOID *)(UINTN)*Memory,
NULL
);
InstallMemoryAttributesTableOnMemoryAllocation (MemoryType);
- ApplyMemoryProtectionPolicy (EfiConventionalMemory, MemoryType, *Memory,
- EFI_PAGES_TO_SIZE (NumberOfPages));
+ ApplyMemoryProtectionPolicy (
+ EfiConventionalMemory,
+ MemoryType,
+ *Memory,
+ EFI_PAGES_TO_SIZE (NumberOfPages)
+ );
}
+
return Status;
}
@@ -1471,16 +1505,16 @@ CoreAllocatePages (
EFI_STATUS
EFIAPI
CoreInternalFreePages (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NumberOfPages,
- OUT EFI_MEMORY_TYPE *MemoryType OPTIONAL
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NumberOfPages,
+ OUT EFI_MEMORY_TYPE *MemoryType OPTIONAL
)
{
- EFI_STATUS Status;
- LIST_ENTRY *Link;
- MEMORY_MAP *Entry;
- UINTN Alignment;
- BOOLEAN IsGuarded;
+ EFI_STATUS Status;
+ LIST_ENTRY *Link;
+ MEMORY_MAP *Entry;
+ UINTN Alignment;
+ BOOLEAN IsGuarded;
//
// Free the range
@@ -1491,13 +1525,14 @@ CoreInternalFreePages (
// Find the entry that the covers the range
//
IsGuarded = FALSE;
- Entry = NULL;
+ Entry = NULL;
for (Link = gMemoryMap.ForwardLink; Link != &gMemoryMap; Link = Link->ForwardLink) {
- Entry = CR(Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
- if (Entry->Start <= Memory && Entry->End > Memory) {
- break;
+ Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
+ if ((Entry->Start <= Memory) && (Entry->End > Memory)) {
+ break;
}
}
+
if (Link == &gMemoryMap) {
Status = EFI_NOT_FOUND;
goto Done;
@@ -1506,13 +1541,12 @@ CoreInternalFreePages (
Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
ASSERT (Entry != NULL);
- if (Entry->Type == EfiACPIReclaimMemory ||
- Entry->Type == EfiACPIMemoryNVS ||
- Entry->Type == EfiRuntimeServicesCode ||
- Entry->Type == EfiRuntimeServicesData) {
-
+ if ((Entry->Type == EfiACPIReclaimMemory) ||
+ (Entry->Type == EfiACPIMemoryNVS) ||
+ (Entry->Type == EfiRuntimeServicesCode) ||
+ (Entry->Type == EfiRuntimeServicesData))
+ {
Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
-
}
if ((Memory & (Alignment - 1)) != 0) {
@@ -1530,8 +1564,11 @@ CoreInternalFreePages (
IsGuarded = IsPageTypeToGuard (Entry->Type, AllocateAnyPages) &&
IsMemoryGuarded (Memory);
if (IsGuarded) {
- Status = CoreConvertPagesWithGuard (Memory, NumberOfPages,
- EfiConventionalMemory);
+ Status = CoreConvertPagesWithGuard (
+ Memory,
+ NumberOfPages,
+ EfiConventionalMemory
+ );
} else {
Status = CoreConvertPages (Memory, NumberOfPages, EfiConventionalMemory);
}
@@ -1559,24 +1596,29 @@ CoreFreePages (
IN UINTN NumberOfPages
)
{
- EFI_STATUS Status;
- EFI_MEMORY_TYPE MemoryType;
+ EFI_STATUS Status;
+ EFI_MEMORY_TYPE MemoryType;
Status = CoreInternalFreePages (Memory, NumberOfPages, &MemoryType);
if (!EFI_ERROR (Status)) {
GuardFreedPagesChecked (Memory, NumberOfPages);
CoreUpdateProfile (
- (EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),
+ (EFI_PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),
MemoryProfileActionFreePages,
MemoryType,
EFI_PAGES_TO_SIZE (NumberOfPages),
- (VOID *) (UINTN) Memory,
+ (VOID *)(UINTN)Memory,
NULL
);
InstallMemoryAttributesTableOnMemoryAllocation (MemoryType);
- ApplyMemoryProtectionPolicy (MemoryType, EfiConventionalMemory, Memory,
- EFI_PAGES_TO_SIZE (NumberOfPages));
+ ApplyMemoryProtectionPolicy (
+ MemoryType,
+ EfiConventionalMemory,
+ Memory,
+ EFI_PAGES_TO_SIZE (NumberOfPages)
+ );
}
+
return Status;
}
@@ -1604,7 +1646,7 @@ MergeMemoryMapDescriptor (
//
// Traverse the array of descriptors in MemoryMap
//
- for (; MemoryMap != MemoryMapDescriptor; MemoryMap = NEXT_MEMORY_DESCRIPTOR (MemoryMap, DescriptorSize)) {
+ for ( ; MemoryMap != MemoryMapDescriptor; MemoryMap = NEXT_MEMORY_DESCRIPTOR (MemoryMap, DescriptorSize)) {
//
// Check to see if the Type fields are identical.
//
@@ -1701,17 +1743,17 @@ CoreGetMemoryMap (
OUT UINT32 *DescriptorVersion
)
{
- EFI_STATUS Status;
- UINTN Size;
- UINTN BufferSize;
- UINTN NumberOfEntries;
- LIST_ENTRY *Link;
- MEMORY_MAP *Entry;
- EFI_GCD_MAP_ENTRY *GcdMapEntry;
- EFI_GCD_MAP_ENTRY MergeGcdMapEntry;
- EFI_MEMORY_TYPE Type;
- EFI_MEMORY_DESCRIPTOR *MemoryMapStart;
- EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
+ EFI_STATUS Status;
+ UINTN Size;
+ UINTN BufferSize;
+ UINTN NumberOfEntries;
+ LIST_ENTRY *Link;
+ MEMORY_MAP *Entry;
+ EFI_GCD_MAP_ENTRY *GcdMapEntry;
+ EFI_GCD_MAP_ENTRY MergeGcdMapEntry;
+ EFI_MEMORY_TYPE Type;
+ EFI_MEMORY_DESCRIPTOR *MemoryMapStart;
+ EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
//
// Make sure the parameters are valid
@@ -1732,8 +1774,9 @@ CoreGetMemoryMap (
if ((GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypePersistent) ||
(GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeReserved) ||
((GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) &&
- ((GcdMapEntry->Attributes & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME))) {
- NumberOfEntries ++;
+ ((GcdMapEntry->Attributes & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME)))
+ {
+ NumberOfEntries++;
}
}
@@ -1744,7 +1787,7 @@ CoreGetMemoryMap (
// prevent people from having pointer math bugs in their code.
// now you have to use *DescriptorSize to make things work.
//
- Size += sizeof(UINT64) - (Size % sizeof (UINT64));
+ Size += sizeof (UINT64) - (Size % sizeof (UINT64));
if (DescriptorSize != NULL) {
*DescriptorSize = Size;
@@ -1786,10 +1829,10 @@ CoreGetMemoryMap (
//
// Convert internal map into an EFI_MEMORY_DESCRIPTOR
//
- MemoryMap->Type = Entry->Type;
- MemoryMap->PhysicalStart = Entry->Start;
- MemoryMap->VirtualStart = Entry->VirtualStart;
- MemoryMap->NumberOfPages = RShiftU64 (Entry->End - Entry->Start + 1, EFI_PAGE_SHIFT);
+ MemoryMap->Type = Entry->Type;
+ MemoryMap->PhysicalStart = Entry->Start;
+ MemoryMap->VirtualStart = Entry->VirtualStart;
+ MemoryMap->NumberOfPages = RShiftU64 (Entry->End - Entry->Start + 1, EFI_PAGE_SHIFT);
//
// If the memory type is EfiConventionalMemory, then determine if the range is part of a
// memory type bin and needs to be converted to the same memory type as the rest of the
@@ -1798,15 +1841,17 @@ CoreGetMemoryMap (
// differences across reboots.
//
if (MemoryMap->Type == EfiConventionalMemory) {
- for (Type = (EFI_MEMORY_TYPE) 0; Type < EfiMaxMemoryType; Type++) {
+ for (Type = (EFI_MEMORY_TYPE)0; Type < EfiMaxMemoryType; Type++) {
if (mMemoryTypeStatistics[Type].Special &&
- mMemoryTypeStatistics[Type].NumberOfPages > 0 &&
- Entry->Start >= mMemoryTypeStatistics[Type].BaseAddress &&
- Entry->End <= mMemoryTypeStatistics[Type].MaximumAddress) {
+ (mMemoryTypeStatistics[Type].NumberOfPages > 0) &&
+ (Entry->Start >= mMemoryTypeStatistics[Type].BaseAddress) &&
+ (Entry->End <= mMemoryTypeStatistics[Type].MaximumAddress))
+ {
MemoryMap->Type = Type;
}
}
}
+
MemoryMap->Attribute = Entry->Attribute;
if (MemoryMap->Type < EfiMaxMemoryType) {
if (mMemoryTypeStatistics[MemoryMap->Type].Runtime) {
@@ -1821,7 +1866,6 @@ CoreGetMemoryMap (
MemoryMap = MergeMemoryMapDescriptor (MemoryMapStart, MemoryMap, Size);
}
-
ZeroMem (&MergeGcdMapEntry, sizeof (MergeGcdMapEntry));
GcdMapEntry = NULL;
for (Link = mGcdMemorySpaceMap.ForwardLink; ; Link = Link->ForwardLink) {
@@ -1834,15 +1878,17 @@ CoreGetMemoryMap (
if ((MergeGcdMapEntry.Capabilities == GcdMapEntry->Capabilities) &&
(MergeGcdMapEntry.Attributes == GcdMapEntry->Attributes) &&
(MergeGcdMapEntry.GcdMemoryType == GcdMapEntry->GcdMemoryType) &&
- (MergeGcdMapEntry.GcdIoType == GcdMapEntry->GcdIoType)) {
- MergeGcdMapEntry.EndAddress = GcdMapEntry->EndAddress;
+ (MergeGcdMapEntry.GcdIoType == GcdMapEntry->GcdIoType))
+ {
+ MergeGcdMapEntry.EndAddress = GcdMapEntry->EndAddress;
continue;
}
}
if ((MergeGcdMapEntry.GcdMemoryType == EfiGcdMemoryTypeReserved) ||
((MergeGcdMapEntry.GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) &&
- ((MergeGcdMapEntry.Attributes & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME))) {
+ ((MergeGcdMapEntry.Attributes & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME)))
+ {
//
// Page Align GCD range is required. When it is converted to EFI_MEMORY_DESCRIPTOR,
// it will be recorded as page PhysicalStart and NumberOfPages.
@@ -1857,7 +1903,7 @@ CoreGetMemoryMap (
MemoryMap->VirtualStart = 0;
MemoryMap->NumberOfPages = RShiftU64 ((MergeGcdMapEntry.EndAddress - MergeGcdMapEntry.BaseAddress + 1), EFI_PAGE_SHIFT);
MemoryMap->Attribute = (MergeGcdMapEntry.Attributes & ~EFI_MEMORY_PORT_IO) |
- (MergeGcdMapEntry.Capabilities & (EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK));
+ (MergeGcdMapEntry.Capabilities & (EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK));
if (MergeGcdMapEntry.GcdMemoryType == EfiGcdMemoryTypeReserved) {
MemoryMap->Type = EfiReservedMemoryType;
@@ -1891,8 +1937,8 @@ CoreGetMemoryMap (
MemoryMap->VirtualStart = 0;
MemoryMap->NumberOfPages = RShiftU64 ((MergeGcdMapEntry.EndAddress - MergeGcdMapEntry.BaseAddress + 1), EFI_PAGE_SHIFT);
MemoryMap->Attribute = MergeGcdMapEntry.Attributes | EFI_MEMORY_NV |
- (MergeGcdMapEntry.Capabilities & (EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK));
- MemoryMap->Type = EfiPersistentMemory;
+ (MergeGcdMapEntry.Capabilities & (EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK));
+ MemoryMap->Type = EfiPersistentMemory;
//
// Check to see if the new Memory Map Descriptor can be merged with an
@@ -1900,12 +1946,14 @@ CoreGetMemoryMap (
//
MemoryMap = MergeMemoryMapDescriptor (MemoryMapStart, MemoryMap, Size);
}
+
if (Link == &mGcdMemorySpaceMap) {
//
// break loop when arrive at head.
//
break;
}
+
if (GcdMapEntry != NULL) {
//
// Copy new GCD map entry for the following GCD range merge
@@ -1931,11 +1979,12 @@ CoreGetMemoryMap (
// all supported OSs.
//
MemoryMapEnd = MemoryMap;
- MemoryMap = MemoryMapStart;
+ MemoryMap = MemoryMapStart;
while (MemoryMap < MemoryMapEnd) {
MemoryMap->Attribute &= ~(UINT64)EFI_MEMORY_ACCESS_MASK;
- MemoryMap = NEXT_MEMORY_DESCRIPTOR (MemoryMap, Size);
+ MemoryMap = NEXT_MEMORY_DESCRIPTOR (MemoryMap, Size);
}
+
MergeMemoryMap (MemoryMapStart, &BufferSize, Size);
MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMapStart + BufferSize);
@@ -1957,12 +2006,11 @@ Done:
DEBUG_CODE (
DumpGuardedMemoryBitmap ();
- );
+ );
return Status;
}
-
/**
Internal function. Used by the pool functions to allocate pages
to back pool allocation requests.
@@ -1977,19 +2025,24 @@ Done:
**/
VOID *
CoreAllocatePoolPages (
- IN EFI_MEMORY_TYPE PoolType,
- IN UINTN NumberOfPages,
- IN UINTN Alignment,
- IN BOOLEAN NeedGuard
+ IN EFI_MEMORY_TYPE PoolType,
+ IN UINTN NumberOfPages,
+ IN UINTN Alignment,
+ IN BOOLEAN NeedGuard
)
{
- UINT64 Start;
+ UINT64 Start;
//
// Find the pages to convert
//
- Start = FindFreePages (MAX_ALLOC_ADDRESS, NumberOfPages, PoolType, Alignment,
- NeedGuard);
+ Start = FindFreePages (
+ MAX_ALLOC_ADDRESS,
+ NumberOfPages,
+ PoolType,
+ Alignment,
+ NeedGuard
+ );
//
// Convert it to boot services data
@@ -2004,10 +2057,9 @@ CoreAllocatePoolPages (
}
}
- return (VOID *)(UINTN) Start;
+ return (VOID *)(UINTN)Start;
}
-
/**
Internal function. Frees pool pages allocated via AllocatePoolPages ()
@@ -2017,15 +2069,13 @@ CoreAllocatePoolPages (
**/
VOID
CoreFreePoolPages (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NumberOfPages
)
{
CoreConvertPages (Memory, NumberOfPages, EfiConventionalMemory);
}
-
-
/**
Make sure the memory map is following all the construction rules,
it is the last time to check memory map error before exit boot services.
@@ -2039,19 +2089,18 @@ CoreFreePoolPages (
**/
EFI_STATUS
CoreTerminateMemoryMap (
- IN UINTN MapKey
+ IN UINTN MapKey
)
{
- EFI_STATUS Status;
- LIST_ENTRY *Link;
- MEMORY_MAP *Entry;
+ EFI_STATUS Status;
+ LIST_ENTRY *Link;
+ MEMORY_MAP *Entry;
Status = EFI_SUCCESS;
CoreAcquireMemoryLock ();
if (MapKey == mMemoryMapKey) {
-
//
// Make sure the memory map is following all the construction rules
// This is the last chance we will be able to display any messages on
@@ -2059,18 +2108,19 @@ CoreTerminateMemoryMap (
//
for (Link = gMemoryMap.ForwardLink; Link != &gMemoryMap; Link = Link->ForwardLink) {
- Entry = CR(Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
+ Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
if (Entry->Type < EfiMaxMemoryType) {
if (mMemoryTypeStatistics[Entry->Type].Runtime) {
ASSERT (Entry->Type != EfiACPIReclaimMemory);
ASSERT (Entry->Type != EfiACPIMemoryNVS);
if ((Entry->Start & (RUNTIME_PAGE_ALLOCATION_GRANULARITY - 1)) != 0) {
- DEBUG((DEBUG_ERROR | DEBUG_PAGE, "ExitBootServices: A RUNTIME memory entry is not on a proper alignment.\n"));
+ DEBUG ((DEBUG_ERROR | DEBUG_PAGE, "ExitBootServices: A RUNTIME memory entry is not on a proper alignment.\n"));
Status = EFI_INVALID_PARAMETER;
goto Done;
}
+
if (((Entry->End + 1) & (RUNTIME_PAGE_ALLOCATION_GRANULARITY - 1)) != 0) {
- DEBUG((DEBUG_ERROR | DEBUG_PAGE, "ExitBootServices: A RUNTIME memory entry is not on a proper alignment.\n"));
+ DEBUG ((DEBUG_ERROR | DEBUG_PAGE, "ExitBootServices: A RUNTIME memory entry is not on a proper alignment.\n"));
Status = EFI_INVALID_PARAMETER;
goto Done;
}
@@ -2094,12 +2144,3 @@ Done:
return Status;
}
-
-
-
-
-
-
-
-
-
diff --git a/MdeModulePkg/Core/Dxe/Mem/Pool.c b/MdeModulePkg/Core/Dxe/Mem/Pool.c
index 734fc94..7aaf501 100644
--- a/MdeModulePkg/Core/Dxe/Mem/Pool.c
+++ b/MdeModulePkg/Core/Dxe/Mem/Pool.c
@@ -10,36 +10,35 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "Imem.h"
#include "HeapGuard.h"
-STATIC EFI_LOCK mPoolMemoryLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
+STATIC EFI_LOCK mPoolMemoryLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
-#define POOL_FREE_SIGNATURE SIGNATURE_32('p','f','r','0')
+#define POOL_FREE_SIGNATURE SIGNATURE_32('p','f','r','0')
typedef struct {
- UINT32 Signature;
- UINT32 Index;
- LIST_ENTRY Link;
+ UINT32 Signature;
+ UINT32 Index;
+ LIST_ENTRY Link;
} POOL_FREE;
-
-#define POOL_HEAD_SIGNATURE SIGNATURE_32('p','h','d','0')
-#define POOLPAGE_HEAD_SIGNATURE SIGNATURE_32('p','h','d','1')
+#define POOL_HEAD_SIGNATURE SIGNATURE_32('p','h','d','0')
+#define POOLPAGE_HEAD_SIGNATURE SIGNATURE_32('p','h','d','1')
typedef struct {
- UINT32 Signature;
- UINT32 Reserved;
- EFI_MEMORY_TYPE Type;
- UINTN Size;
- CHAR8 Data[1];
+ UINT32 Signature;
+ UINT32 Reserved;
+ EFI_MEMORY_TYPE Type;
+ UINTN Size;
+ CHAR8 Data[1];
} POOL_HEAD;
-#define SIZE_OF_POOL_HEAD OFFSET_OF(POOL_HEAD,Data)
+#define SIZE_OF_POOL_HEAD OFFSET_OF(POOL_HEAD,Data)
-#define POOL_TAIL_SIGNATURE SIGNATURE_32('p','t','a','l')
+#define POOL_TAIL_SIGNATURE SIGNATURE_32('p','t','a','l')
typedef struct {
- UINT32 Signature;
- UINT32 Reserved;
- UINTN Size;
+ UINT32 Signature;
+ UINT32 Reserved;
+ UINTN Size;
} POOL_TAIL;
-#define POOL_OVERHEAD (SIZE_OF_POOL_HEAD + sizeof(POOL_TAIL))
+#define POOL_OVERHEAD (SIZE_OF_POOL_HEAD + sizeof(POOL_TAIL))
#define HEAD_TO_TAIL(a) \
((POOL_TAIL *) (((CHAR8 *) (a)) + (a)->Size - sizeof(POOL_TAIL)));
@@ -49,16 +48,16 @@ typedef struct {
// blocks between bins by splitting them up, while not wasting too much memory
// as we would in a strict power-of-2 sequence
//
-STATIC CONST UINT16 mPoolSizeTable[] = {
+STATIC CONST UINT16 mPoolSizeTable[] = {
128, 256, 384, 640, 1024, 1664, 2688, 4352, 7040, 11392, 18432, 29824
};
-#define SIZE_TO_LIST(a) (GetPoolIndexFromSize (a))
-#define LIST_TO_SIZE(a) (mPoolSizeTable [a])
+#define SIZE_TO_LIST(a) (GetPoolIndexFromSize (a))
+#define LIST_TO_SIZE(a) (mPoolSizeTable [a])
-#define MAX_POOL_LIST (ARRAY_SIZE (mPoolSizeTable))
+#define MAX_POOL_LIST (ARRAY_SIZE (mPoolSizeTable))
-#define MAX_POOL_SIZE (MAX_ADDRESS - POOL_OVERHEAD)
+#define MAX_POOL_SIZE (MAX_ADDRESS - POOL_OVERHEAD)
//
// Globals
@@ -66,22 +65,22 @@ STATIC CONST UINT16 mPoolSizeTable[] = {
#define POOL_SIGNATURE SIGNATURE_32('p','l','s','t')
typedef struct {
- INTN Signature;
- UINTN Used;
- EFI_MEMORY_TYPE MemoryType;
- LIST_ENTRY FreeList[MAX_POOL_LIST];
- LIST_ENTRY Link;
+ INTN Signature;
+ UINTN Used;
+ EFI_MEMORY_TYPE MemoryType;
+ LIST_ENTRY FreeList[MAX_POOL_LIST];
+ LIST_ENTRY Link;
} POOL;
//
// Pool header for each memory type.
//
-POOL mPoolHead[EfiMaxMemoryType];
+POOL mPoolHead[EfiMaxMemoryType];
//
// List of pool header to search for the appropriate memory type.
//
-LIST_ENTRY mPoolHeadList = INITIALIZE_LIST_HEAD_VARIABLE (mPoolHeadList);
+LIST_ENTRY mPoolHeadList = INITIALIZE_LIST_HEAD_VARIABLE (mPoolHeadList);
/**
Get pool size table index from the specified size.
@@ -94,16 +93,17 @@ LIST_ENTRY mPoolHeadList = INITIALIZE_LIST_HEAD_VARIABLE (mPoolHeadList);
STATIC
UINTN
GetPoolIndexFromSize (
- UINTN Size
+ UINTN Size
)
{
- UINTN Index;
+ UINTN Index;
for (Index = 0; Index < MAX_POOL_LIST; Index++) {
- if (mPoolSizeTable [Index] >= Size) {
+ if (mPoolSizeTable[Index] >= Size) {
return Index;
}
}
+
return MAX_POOL_LIST;
}
@@ -119,17 +119,16 @@ CoreInitializePool (
UINTN Type;
UINTN Index;
- for (Type=0; Type < EfiMaxMemoryType; Type++) {
+ for (Type = 0; Type < EfiMaxMemoryType; Type++) {
mPoolHead[Type].Signature = 0;
mPoolHead[Type].Used = 0;
- mPoolHead[Type].MemoryType = (EFI_MEMORY_TYPE) Type;
- for (Index=0; Index < MAX_POOL_LIST; Index++) {
+ mPoolHead[Type].MemoryType = (EFI_MEMORY_TYPE)Type;
+ for (Index = 0; Index < MAX_POOL_LIST; Index++) {
InitializeListHead (&mPoolHead[Type].FreeList[Index]);
}
}
}
-
/**
Look up pool head for specified memory type.
@@ -143,9 +142,9 @@ LookupPoolHead (
IN EFI_MEMORY_TYPE MemoryType
)
{
- LIST_ENTRY *Link;
- POOL *Pool;
- UINTN Index;
+ LIST_ENTRY *Link;
+ POOL *Pool;
+ UINTN Index;
if ((UINT32)MemoryType < EfiMaxMemoryType) {
return &mPoolHead[MemoryType];
@@ -156,10 +155,9 @@ LookupPoolHead (
// OS loaders that are provided by operating system vendors.
// MemoryType values in the range 0x70000000..0x7FFFFFFF are reserved for OEM use.
//
- if ((UINT32) MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {
-
+ if ((UINT32)MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {
for (Link = mPoolHeadList.ForwardLink; Link != &mPoolHeadList; Link = Link->ForwardLink) {
- Pool = CR(Link, POOL, Link, POOL_SIGNATURE);
+ Pool = CR (Link, POOL, Link, POOL_SIGNATURE);
if (Pool->MemoryType == MemoryType) {
return Pool;
}
@@ -170,10 +168,10 @@ LookupPoolHead (
return NULL;
}
- Pool->Signature = POOL_SIGNATURE;
- Pool->Used = 0;
+ Pool->Signature = POOL_SIGNATURE;
+ Pool->Used = 0;
Pool->MemoryType = MemoryType;
- for (Index=0; Index < MAX_POOL_LIST; Index++) {
+ for (Index = 0; Index < MAX_POOL_LIST; Index++) {
InitializeListHead (&Pool->FreeList[Index]);
}
@@ -185,8 +183,6 @@ LookupPoolHead (
return NULL;
}
-
-
/**
Allocate pool of a particular type.
@@ -210,14 +206,15 @@ CoreInternalAllocatePool (
OUT VOID **Buffer
)
{
- EFI_STATUS Status;
- BOOLEAN NeedGuard;
+ EFI_STATUS Status;
+ BOOLEAN NeedGuard;
//
// If it's not a valid type, fail it
//
- if ((PoolType >= EfiMaxMemoryType && PoolType < MEMORY_TYPE_OEM_RESERVED_MIN) ||
- (PoolType == EfiConventionalMemory) || (PoolType == EfiPersistentMemory)) {
+ if (((PoolType >= EfiMaxMemoryType) && (PoolType < MEMORY_TYPE_OEM_RESERVED_MIN)) ||
+ (PoolType == EfiConventionalMemory) || (PoolType == EfiPersistentMemory))
+ {
return EFI_INVALID_PARAMETER;
}
@@ -278,7 +275,7 @@ CoreAllocatePool (
Status = CoreInternalAllocatePool (PoolType, Size, Buffer);
if (!EFI_ERROR (Status)) {
CoreUpdateProfile (
- (EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),
+ (EFI_PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),
MemoryProfileActionAllocatePool,
PoolType,
Size,
@@ -287,6 +284,7 @@ CoreAllocatePool (
);
InstallMemoryAttributesTableOnMemoryAllocation (PoolType);
}
+
return Status;
}
@@ -305,10 +303,10 @@ CoreAllocatePool (
STATIC
VOID *
CoreAllocatePoolPagesI (
- IN EFI_MEMORY_TYPE PoolType,
- IN UINTN NoPages,
- IN UINTN Granularity,
- IN BOOLEAN NeedGuard
+ IN EFI_MEMORY_TYPE PoolType,
+ IN UINTN NoPages,
+ IN UINTN Granularity,
+ IN BOOLEAN NeedGuard
)
{
VOID *Buffer;
@@ -326,9 +324,15 @@ CoreAllocatePoolPagesI (
if (NeedGuard) {
SetGuardForMemory ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, NoPages);
}
- ApplyMemoryProtectionPolicy(EfiConventionalMemory, PoolType,
- (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, EFI_PAGES_TO_SIZE (NoPages));
+
+ ApplyMemoryProtectionPolicy (
+ EfiConventionalMemory,
+ PoolType,
+ (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer,
+ EFI_PAGES_TO_SIZE (NoPages)
+ );
}
+
return Buffer;
}
@@ -350,27 +354,27 @@ CoreAllocatePoolI (
IN BOOLEAN NeedGuard
)
{
- POOL *Pool;
- POOL_FREE *Free;
- POOL_HEAD *Head;
- POOL_TAIL *Tail;
- CHAR8 *NewPage;
- VOID *Buffer;
- UINTN Index;
- UINTN FSize;
- UINTN Offset, MaxOffset;
- UINTN NoPages;
- UINTN Granularity;
- BOOLEAN HasPoolTail;
- BOOLEAN PageAsPool;
+ POOL *Pool;
+ POOL_FREE *Free;
+ POOL_HEAD *Head;
+ POOL_TAIL *Tail;
+ CHAR8 *NewPage;
+ VOID *Buffer;
+ UINTN Index;
+ UINTN FSize;
+ UINTN Offset, MaxOffset;
+ UINTN NoPages;
+ UINTN Granularity;
+ BOOLEAN HasPoolTail;
+ BOOLEAN PageAsPool;
ASSERT_LOCKED (&mPoolMemoryLock);
- if (PoolType == EfiACPIReclaimMemory ||
- PoolType == EfiACPIMemoryNVS ||
- PoolType == EfiRuntimeServicesCode ||
- PoolType == EfiRuntimeServicesData) {
-
+ if ((PoolType == EfiACPIReclaimMemory) ||
+ (PoolType == EfiACPIMemoryNVS) ||
+ (PoolType == EfiRuntimeServicesCode) ||
+ (PoolType == EfiRuntimeServicesData))
+ {
Granularity = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
} else {
Granularity = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
@@ -380,8 +384,8 @@ CoreAllocatePoolI (
// Adjust the size by the pool header & tail overhead
//
- HasPoolTail = !(NeedGuard &&
- ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) == 0));
+ HasPoolTail = !(NeedGuard &&
+ ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) == 0));
PageAsPool = (IsHeapGuardEnabled (GUARD_HEAP_TYPE_FREED) && !mOnGuarding);
//
@@ -392,27 +396,30 @@ CoreAllocatePoolI (
Size = ALIGN_VARIABLE (Size);
Size += POOL_OVERHEAD;
- Index = SIZE_TO_LIST(Size);
- Pool = LookupPoolHead (PoolType);
- if (Pool== NULL) {
+ Index = SIZE_TO_LIST (Size);
+ Pool = LookupPoolHead (PoolType);
+ if (Pool == NULL) {
return NULL;
}
+
Head = NULL;
//
// If allocation is over max size, just allocate pages for the request
// (slow)
//
- if (Index >= SIZE_TO_LIST (Granularity) || NeedGuard || PageAsPool) {
+ if ((Index >= SIZE_TO_LIST (Granularity)) || NeedGuard || PageAsPool) {
if (!HasPoolTail) {
Size -= sizeof (POOL_TAIL);
}
- NoPages = EFI_SIZE_TO_PAGES (Size) + EFI_SIZE_TO_PAGES (Granularity) - 1;
+
+ NoPages = EFI_SIZE_TO_PAGES (Size) + EFI_SIZE_TO_PAGES (Granularity) - 1;
NoPages &= ~(UINTN)(EFI_SIZE_TO_PAGES (Granularity) - 1);
- Head = CoreAllocatePoolPagesI (PoolType, NoPages, Granularity, NeedGuard);
+ Head = CoreAllocatePoolPagesI (PoolType, NoPages, Granularity, NeedGuard);
if (NeedGuard) {
Head = AdjustPoolHeadA ((EFI_PHYSICAL_ADDRESS)(UINTN)Head, NoPages, Size);
}
+
goto Done;
}
@@ -420,8 +427,7 @@ CoreAllocatePoolI (
// If there's no free pool in the proper list size, go get some more pages
//
if (IsListEmpty (&Pool->FreeList[Index])) {
-
- Offset = LIST_TO_SIZE (Index);
+ Offset = LIST_TO_SIZE (Index);
MaxOffset = Granularity;
//
@@ -431,7 +437,7 @@ CoreAllocatePoolI (
if (!IsListEmpty (&Pool->FreeList[Index])) {
Free = CR (Pool->FreeList[Index].ForwardLink, POOL_FREE, Link, POOL_FREE_SIGNATURE);
RemoveEntryList (&Free->Link);
- NewPage = (VOID *) Free;
+ NewPage = (VOID *)Free;
MaxOffset = LIST_TO_SIZE (Index);
goto Carve;
}
@@ -440,8 +446,12 @@ CoreAllocatePoolI (
//
// Get another page
//
- NewPage = CoreAllocatePoolPagesI (PoolType, EFI_SIZE_TO_PAGES (Granularity),
- Granularity, NeedGuard);
+ NewPage = CoreAllocatePoolPagesI (
+ PoolType,
+ EFI_SIZE_TO_PAGES (Granularity),
+ Granularity,
+ NeedGuard
+ );
if (NewPage == NULL) {
goto Done;
}
@@ -450,7 +460,7 @@ CoreAllocatePoolI (
// Serve the allocation request from the head of the allocated block
//
Carve:
- Head = (POOL_HEAD *) NewPage;
+ Head = (POOL_HEAD *)NewPage;
//
// Carve up remaining space into free pool blocks
@@ -458,15 +468,16 @@ Carve:
Index--;
while (Offset < MaxOffset) {
ASSERT (Index < MAX_POOL_LIST);
- FSize = LIST_TO_SIZE(Index);
+ FSize = LIST_TO_SIZE (Index);
while (Offset + FSize <= MaxOffset) {
- Free = (POOL_FREE *) &NewPage[Offset];
+ Free = (POOL_FREE *)&NewPage[Offset];
Free->Signature = POOL_FREE_SIGNATURE;
Free->Index = (UINT32)Index;
InsertHeadList (&Pool->FreeList[Index], &Free->Link);
Offset += FSize;
}
+
Index -= 1;
}
@@ -480,13 +491,12 @@ Carve:
Free = CR (Pool->FreeList[Index].ForwardLink, POOL_FREE, Link, POOL_FREE_SIGNATURE);
RemoveEntryList (&Free->Link);
- Head = (POOL_HEAD *) Free;
+ Head = (POOL_HEAD *)Free;
Done:
Buffer = NULL;
if (Head != NULL) {
-
//
// Account the allocation
//
@@ -497,7 +507,7 @@ Done:
//
Head->Signature = (PageAsPool) ? POOLPAGE_HEAD_SIGNATURE : POOL_HEAD_SIGNATURE;
Head->Size = Size;
- Head->Type = (EFI_MEMORY_TYPE) PoolType;
+ Head->Type = (EFI_MEMORY_TYPE)PoolType;
Buffer = Head->Data;
if (HasPoolTail) {
@@ -514,22 +524,19 @@ Done:
DEBUG ((
DEBUG_POOL,
- "AllocatePoolI: Type %x, Addr %p (len %lx) %,ld\n", PoolType,
+ "AllocatePoolI: Type %x, Addr %p (len %lx) %,ld\n",
+ PoolType,
Buffer,
(UINT64)Size,
- (UINT64) Pool->Used
+ (UINT64)Pool->Used
));
-
-
} else {
- DEBUG ((DEBUG_ERROR | DEBUG_POOL, "AllocatePool: failed to allocate %ld bytes\n", (UINT64) Size));
+ DEBUG ((DEBUG_ERROR | DEBUG_POOL, "AllocatePool: failed to allocate %ld bytes\n", (UINT64)Size));
}
return Buffer;
}
-
-
/**
Frees pool.
@@ -543,11 +550,11 @@ Done:
EFI_STATUS
EFIAPI
CoreInternalFreePool (
- IN VOID *Buffer,
- OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
+ IN VOID *Buffer,
+ OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
if (Buffer == NULL) {
return EFI_INVALID_PARAMETER;
@@ -574,13 +581,13 @@ CoreFreePool (
IN VOID *Buffer
)
{
- EFI_STATUS Status;
- EFI_MEMORY_TYPE PoolType;
+ EFI_STATUS Status;
+ EFI_MEMORY_TYPE PoolType;
Status = CoreInternalFreePool (Buffer, &PoolType);
if (!EFI_ERROR (Status)) {
CoreUpdateProfile (
- (EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),
+ (EFI_PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),
MemoryProfileActionFreePool,
PoolType,
0,
@@ -589,6 +596,7 @@ CoreFreePool (
);
InstallMemoryAttributesTableOnMemoryAllocation (PoolType);
}
+
return Status;
}
@@ -603,9 +611,9 @@ CoreFreePool (
STATIC
VOID
CoreFreePoolPagesI (
- IN EFI_MEMORY_TYPE PoolType,
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NoPages
+ IN EFI_MEMORY_TYPE PoolType,
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NoPages
)
{
CoreAcquireMemoryLock ();
@@ -613,8 +621,12 @@ CoreFreePoolPagesI (
CoreReleaseMemoryLock ();
GuardFreedPagesChecked (Memory, NoPages);
- ApplyMemoryProtectionPolicy (PoolType, EfiConventionalMemory,
- (EFI_PHYSICAL_ADDRESS)(UINTN)Memory, EFI_PAGES_TO_SIZE (NoPages));
+ ApplyMemoryProtectionPolicy (
+ PoolType,
+ EfiConventionalMemory,
+ (EFI_PHYSICAL_ADDRESS)(UINTN)Memory,
+ EFI_PAGES_TO_SIZE (NoPages)
+ );
}
/**
@@ -628,13 +640,13 @@ CoreFreePoolPagesI (
STATIC
VOID
CoreFreePoolPagesWithGuard (
- IN EFI_MEMORY_TYPE PoolType,
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NoPages
+ IN EFI_MEMORY_TYPE PoolType,
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NoPages
)
{
- EFI_PHYSICAL_ADDRESS MemoryGuarded;
- UINTN NoPagesGuarded;
+ EFI_PHYSICAL_ADDRESS MemoryGuarded;
+ UINTN NoPagesGuarded;
MemoryGuarded = Memory;
NoPagesGuarded = NoPages;
@@ -666,41 +678,44 @@ CoreFreePoolPagesWithGuard (
**/
EFI_STATUS
CoreFreePoolI (
- IN VOID *Buffer,
- OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
+ IN VOID *Buffer,
+ OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
)
{
- POOL *Pool;
- POOL_HEAD *Head;
- POOL_TAIL *Tail;
- POOL_FREE *Free;
- UINTN Index;
- UINTN NoPages;
- UINTN Size;
- CHAR8 *NewPage;
- UINTN Offset;
- BOOLEAN AllFree;
- UINTN Granularity;
- BOOLEAN IsGuarded;
- BOOLEAN HasPoolTail;
- BOOLEAN PageAsPool;
-
- ASSERT(Buffer != NULL);
+ POOL *Pool;
+ POOL_HEAD *Head;
+ POOL_TAIL *Tail;
+ POOL_FREE *Free;
+ UINTN Index;
+ UINTN NoPages;
+ UINTN Size;
+ CHAR8 *NewPage;
+ UINTN Offset;
+ BOOLEAN AllFree;
+ UINTN Granularity;
+ BOOLEAN IsGuarded;
+ BOOLEAN HasPoolTail;
+ BOOLEAN PageAsPool;
+
+ ASSERT (Buffer != NULL);
//
// Get the head & tail of the pool entry
//
Head = BASE_CR (Buffer, POOL_HEAD, Data);
- ASSERT(Head != NULL);
-
- if (Head->Signature != POOL_HEAD_SIGNATURE &&
- Head->Signature != POOLPAGE_HEAD_SIGNATURE) {
- ASSERT (Head->Signature == POOL_HEAD_SIGNATURE ||
- Head->Signature == POOLPAGE_HEAD_SIGNATURE);
+ ASSERT (Head != NULL);
+
+ if ((Head->Signature != POOL_HEAD_SIGNATURE) &&
+ (Head->Signature != POOLPAGE_HEAD_SIGNATURE))
+ {
+ ASSERT (
+ Head->Signature == POOL_HEAD_SIGNATURE ||
+ Head->Signature == POOLPAGE_HEAD_SIGNATURE
+ );
return EFI_INVALID_PARAMETER;
}
- IsGuarded = IsPoolTypeToGuard (Head->Type) &&
- IsMemoryGuarded ((EFI_PHYSICAL_ADDRESS)(UINTN)Head);
+ IsGuarded = IsPoolTypeToGuard (Head->Type) &&
+ IsMemoryGuarded ((EFI_PHYSICAL_ADDRESS)(UINTN)Head);
HasPoolTail = !(IsGuarded &&
((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) == 0));
PageAsPool = (Head->Signature == POOLPAGE_HEAD_SIGNATURE);
@@ -734,14 +749,15 @@ CoreFreePoolI (
if (Pool == NULL) {
return EFI_INVALID_PARAMETER;
}
- Pool->Used -= Size;
- DEBUG ((DEBUG_POOL, "FreePool: %p (len %lx) %,ld\n", Head->Data, (UINT64)(Head->Size - POOL_OVERHEAD), (UINT64) Pool->Used));
- if (Head->Type == EfiACPIReclaimMemory ||
- Head->Type == EfiACPIMemoryNVS ||
- Head->Type == EfiRuntimeServicesCode ||
- Head->Type == EfiRuntimeServicesData) {
+ Pool->Used -= Size;
+ DEBUG ((DEBUG_POOL, "FreePool: %p (len %lx) %,ld\n", Head->Data, (UINT64)(Head->Size - POOL_OVERHEAD), (UINT64)Pool->Used));
+ if ((Head->Type == EfiACPIReclaimMemory) ||
+ (Head->Type == EfiACPIMemoryNVS) ||
+ (Head->Type == EfiRuntimeServicesCode) ||
+ (Head->Type == EfiRuntimeServicesData))
+ {
Granularity = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
} else {
Granularity = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
@@ -754,18 +770,17 @@ CoreFreePoolI (
//
// Determine the pool list
//
- Index = SIZE_TO_LIST(Size);
+ Index = SIZE_TO_LIST (Size);
DEBUG_CLEAR_MEMORY (Head, Size);
//
// If it's not on the list, it must be pool pages
//
- if (Index >= SIZE_TO_LIST (Granularity) || IsGuarded || PageAsPool) {
-
+ if ((Index >= SIZE_TO_LIST (Granularity)) || IsGuarded || PageAsPool) {
//
// Return the memory pages back to free memory
//
- NoPages = EFI_SIZE_TO_PAGES (Size) + EFI_SIZE_TO_PAGES (Granularity) - 1;
+ NoPages = EFI_SIZE_TO_PAGES (Size) + EFI_SIZE_TO_PAGES (Granularity) - 1;
NoPages &= ~(UINTN)(EFI_SIZE_TO_PAGES (Granularity) - 1);
if (IsGuarded) {
Head = AdjustPoolHeadF ((EFI_PHYSICAL_ADDRESS)(UINTN)Head);
@@ -781,14 +796,12 @@ CoreFreePoolI (
NoPages
);
}
-
} else {
-
//
// Put the pool entry onto the free pool list
//
- Free = (POOL_FREE *) Head;
- ASSERT(Free != NULL);
+ Free = (POOL_FREE *)Head;
+ ASSERT (Free != NULL);
Free->Signature = POOL_FREE_SIGNATURE;
Free->Index = (UINT32)Index;
InsertHeadList (&Pool->FreeList[Index], &Free->Link);
@@ -798,46 +811,48 @@ CoreFreePoolI (
// entries
//
NewPage = (CHAR8 *)((UINTN)Free & ~(Granularity - 1));
- Free = (POOL_FREE *) &NewPage[0];
- ASSERT(Free != NULL);
+ Free = (POOL_FREE *)&NewPage[0];
+ ASSERT (Free != NULL);
if (Free->Signature == POOL_FREE_SIGNATURE) {
-
AllFree = TRUE;
- Offset = 0;
+ Offset = 0;
while ((Offset < Granularity) && (AllFree)) {
- Free = (POOL_FREE *) &NewPage[Offset];
- ASSERT(Free != NULL);
+ Free = (POOL_FREE *)&NewPage[Offset];
+ ASSERT (Free != NULL);
if (Free->Signature != POOL_FREE_SIGNATURE) {
AllFree = FALSE;
}
- Offset += LIST_TO_SIZE(Free->Index);
+
+ Offset += LIST_TO_SIZE (Free->Index);
}
if (AllFree) {
-
//
// All of the pool entries in the same page as Free are free pool
// entries
// Remove all of these pool entries from the free loop lists.
//
- Free = (POOL_FREE *) &NewPage[0];
- ASSERT(Free != NULL);
+ Free = (POOL_FREE *)&NewPage[0];
+ ASSERT (Free != NULL);
Offset = 0;
while (Offset < Granularity) {
- Free = (POOL_FREE *) &NewPage[Offset];
- ASSERT(Free != NULL);
+ Free = (POOL_FREE *)&NewPage[Offset];
+ ASSERT (Free != NULL);
RemoveEntryList (&Free->Link);
- Offset += LIST_TO_SIZE(Free->Index);
+ Offset += LIST_TO_SIZE (Free->Index);
}
//
// Free the page
//
- CoreFreePoolPagesI (Pool->MemoryType, (EFI_PHYSICAL_ADDRESS) (UINTN)NewPage,
- EFI_SIZE_TO_PAGES (Granularity));
+ CoreFreePoolPagesI (
+ Pool->MemoryType,
+ (EFI_PHYSICAL_ADDRESS)(UINTN)NewPage,
+ EFI_SIZE_TO_PAGES (Granularity)
+ );
}
}
}
@@ -847,11 +862,10 @@ CoreFreePoolI (
// portion of that memory type has been freed. If it has, then free the
// list entry for that memory type
//
- if (((UINT32) Pool->MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) && Pool->Used == 0) {
+ if (((UINT32)Pool->MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) && (Pool->Used == 0)) {
RemoveEntryList (&Pool->Link);
CoreFreePoolI (Pool, NULL);
}
return EFI_SUCCESS;
}
-