summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg/Core/PiSmmCore/HeapGuard.c
diff options
context:
space:
mode:
Diffstat (limited to 'MdeModulePkg/Core/PiSmmCore/HeapGuard.c')
-rw-r--r--MdeModulePkg/Core/PiSmmCore/HeapGuard.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/MdeModulePkg/Core/PiSmmCore/HeapGuard.c b/MdeModulePkg/Core/PiSmmCore/HeapGuard.c
index f9657f9baa..d5556eb79c 100644
--- a/MdeModulePkg/Core/PiSmmCore/HeapGuard.c
+++ b/MdeModulePkg/Core/PiSmmCore/HeapGuard.c
@@ -941,6 +941,7 @@ AdjustMemoryF (
EFI_PHYSICAL_ADDRESS MemoryToTest;
UINTN PagesToFree;
UINT64 GuardBitmap;
+ UINT64 Attributes;
if (Memory == NULL || NumberOfPages == NULL || *NumberOfPages == 0) {
return;
@@ -950,6 +951,27 @@ AdjustMemoryF (
PagesToFree = *NumberOfPages;
//
+ // In case the memory to free is marked as read-only (e.g. EfiRuntimeServicesCode).
+ //
+ if (mSmmMemoryAttribute != NULL) {
+ Attributes = 0;
+ mSmmMemoryAttribute->GetMemoryAttributes (
+ mSmmMemoryAttribute,
+ Start,
+ EFI_PAGES_TO_SIZE (PagesToFree),
+ &Attributes
+ );
+ if ((Attributes & EFI_MEMORY_RO) != 0) {
+ mSmmMemoryAttribute->ClearMemoryAttributes (
+ mSmmMemoryAttribute,
+ Start,
+ EFI_PAGES_TO_SIZE (PagesToFree),
+ EFI_MEMORY_RO
+ );
+ }
+ }
+
+ //
// Head Guard must be one page before, if any.
//
// MSB-> 1 0 <-LSB