diff options
-rw-r--r-- | MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c | 27 | ||||
-rw-r--r-- | MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 21 | ||||
-rw-r--r-- | UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 5 |
3 files changed, 27 insertions, 26 deletions
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;
}
}
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c index b19906b610..7bc68087ad 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -1868,6 +1868,10 @@ InitializeMpSyncData ( UINTN CpuIndex;
if (mSmmMpSyncData != NULL) {
+ if (mSmmMpSyncData->SyncContext != NULL) {
+ SmmCpuSyncContextDeinit (mSmmMpSyncData->SyncContext);
+ }
+
//
// mSmmMpSyncDataSize includes one structure of SMM_DISPATCHER_MP_SYNC_DATA, one
// CpuData array of SMM_CPU_DATA_BLOCK and one CandidateBsp array of BOOLEAN.
@@ -1968,6 +1972,7 @@ InitializeMpServiceData ( mSmmMpSyncData = (SMM_DISPATCHER_MP_SYNC_DATA *)AllocatePages (EFI_SIZE_TO_PAGES (mSmmMpSyncDataSize));
ASSERT (mSmmMpSyncData != NULL);
+ ZeroMem (mSmmMpSyncData, mSmmMpSyncDataSize);
RelaxedMode = FALSE;
GetSmmCpuSyncConfigData (&RelaxedMode, NULL, NULL);
mCpuSmmSyncMode = RelaxedMode ? MmCpuSyncModeRelaxedAp : MmCpuSyncModeTradition;
|