diff options
Diffstat (limited to 'MdeModulePkg/Core/Dxe')
-rw-r--r-- | MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 14 | ||||
-rw-r--r-- | MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c | 27 | ||||
-rw-r--r-- | MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 21 |
3 files changed, 36 insertions, 26 deletions
diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c index 467d5e4813..f5cac1874a 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -153,6 +153,13 @@ CoreDumpGcdMemorySpaceMap ( EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;
UINTN Index;
+ // The compiler is not smart enough to compile out the whole function if DEBUG_GCD is not enabled, so we end up
+ // looping through the GCD every time it gets updated, which wastes a lot of needless cycles if we aren't going to
+ // print it. So shortcircuit and jump out if we don't need to print it.
+ if (!DebugPrintLevelEnabled (DEBUG_GCD)) {
+ return;
+ }
+
Status = CoreGetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);
ASSERT (Status == EFI_SUCCESS && MemorySpaceMap != NULL);
@@ -199,6 +206,13 @@ CoreDumpGcdIoSpaceMap ( EFI_GCD_IO_SPACE_DESCRIPTOR *IoSpaceMap;
UINTN Index;
+ // The compiler is not smart enough to compile out the whole function if DEBUG_GCD is not enabled, so we end up
+ // looping through the GCD every time it gets updated, which wastes a lot of needless cycles if we aren't going to
+ // print it. So shortcircuit and jump out if we don't need to print it.
+ if (!DebugPrintLevelEnabled (DEBUG_GCD)) {
+ return;
+ }
+
Status = CoreGetIoSpaceMap (&NumberOfDescriptors, &IoSpaceMap);
ASSERT (Status == EFI_SUCCESS && IoSpaceMap != NULL);
diff --git a/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c b/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c index eeb18f6e47..54061bf1f8 100644 --- a/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c +++ b/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c @@ -177,20 +177,7 @@ CoreNewDebugImageInfoEntry ( Table = mDebugInfoTableHeader.EfiDebugImageInfoTable;
- if (mDebugInfoTableHeader.TableSize < mMaxTableEntries) {
- //
- // We still have empty entires in the Table, find the first empty entry.
- //
- Index = 0;
- while (Table[Index].NormalImage != NULL) {
- Index++;
- }
-
- //
- // There must be an empty entry in the in the table.
- //
- ASSERT (Index < mMaxTableEntries);
- } else {
+ if (mDebugInfoTableHeader.TableSize >= mMaxTableEntries) {
//
// Table is full, so re-allocate another page for a larger table...
//
@@ -218,10 +205,12 @@ CoreNewDebugImageInfoEntry ( // Enlarge the max table entries and set the first empty entry index to
// be the original max table entries.
//
- Index = mMaxTableEntries;
mMaxTableEntries += EFI_PAGE_SIZE / EFI_DEBUG_TABLE_ENTRY_SIZE;
}
+ // We always put the next entry at the end of the currently consumed table (i.e. first free entry)
+ Index = mDebugInfoTableHeader.TableSize;
+
//
// Allocate data for new entry
//
@@ -264,11 +253,13 @@ CoreRemoveDebugImageInfoEntry ( for (Index = 0; Index < mMaxTableEntries; Index++) {
if ((Table[Index].NormalImage != NULL) && (Table[Index].NormalImage->ImageHandle == ImageHandle)) {
//
- // Found a match. Free up the record, then NULL the pointer to indicate the slot
- // is free.
+ // Found a match. Free up the record, then move the final entry down to this slot; we don't care about the
+ // order of the array
//
CoreFreePool (Table[Index].NormalImage);
- Table[Index].NormalImage = NULL;
+ Table[Index].NormalImage = Table[mDebugInfoTableHeader.TableSize - 1].NormalImage;
+ Table[mDebugInfoTableHeader.TableSize - 1].NormalImage = NULL;
+
//
// Decrease the number of EFI_DEBUG_IMAGE_INFO elements and set the mDebugInfoTable in modified status.
//
diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c index 72d72f9d93..33357eb124 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c @@ -196,8 +196,11 @@ SetUefiImageMemoryAttributes ( UINT64 FinalAttributes;
UINT64 CurrentAddress;
UINT64 CurrentLength;
+ UINT64 ImageEnd;
+ UINT64 DescEnd;
CurrentAddress = BaseAddress;
+ ImageEnd = BaseAddress + Length;
// we loop here because we may have multiple memory space descriptors that overlap the requested range
// this will definitely be the case for unprotecting an image, because that calls this function for the entire image,
@@ -216,11 +219,14 @@ SetUefiImageMemoryAttributes ( return;
}
- // ensure that we only change the attributes for the range that we are interested in, not the entire descriptor
- if (BaseAddress + Length > CurrentAddress + Descriptor.Length) {
- CurrentLength = Descriptor.Length;
+ DescEnd = Descriptor.BaseAddress + Descriptor.Length;
+
+ // ensure that we only change the attributes for the range that we are interested in, not the entire descriptor, we
+ // may also be in the middle of a descriptor, so ensure our length is not larger than the descriptor length
+ if (ImageEnd > DescEnd) {
+ CurrentLength = DescEnd - CurrentAddress;
} else {
- CurrentLength = BaseAddress + Length - CurrentAddress;
+ CurrentLength = ImageEnd - CurrentAddress;
}
// Preserve the existing caching and virtual attributes, but remove the hardware access bits
@@ -291,10 +297,9 @@ SetUefiImageMemoryAttributes ( }
}
- // we have CurrentLength, also, but that is just to handle the final descriptor case where we might take only
- // part of a descriptor, so we can use Descriptor.Length here to move to the next descriptor, which for the final
- // descriptor will exit the loop, regardless of whether we truncated or not
- CurrentAddress += Descriptor.Length;
+ // we may have started in the middle of a descriptor, so we need to move to the beginning of the next descriptor,
+ // or the end of the image, whichever is smaller
+ CurrentAddress += CurrentLength;
}
}
|