summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Core/Dxe
diff options
context:
space:
mode:
authorJian J Wang <jian.j.wang@intel.com>2018-01-26 19:47:14 +0800
committerStar Zeng <star.zeng@intel.com>2018-02-02 09:50:15 +0800
commit1263ecf2ffc9302663a304e7a6467c6e00cebf4a (patch)
tree3a8522bd89578dcfc306250a286a0e9cfd320584 /MdeModulePkg/Core/Dxe
parent821807bcefb9a36e598d71a8004fae5aab2052a0 (diff)
downloadedk2-1263ecf2ffc9302663a304e7a6467c6e00cebf4a.zip
edk2-1263ecf2ffc9302663a304e7a6467c6e00cebf4a.tar.gz
edk2-1263ecf2ffc9302663a304e7a6467c6e00cebf4a.tar.bz2
MdeModulePkg/Core: fix guard page missing issue
This issue is a regression one caused by a patch at 425d25699be83c35e12df8470b827d7fbcef3bce That fix didn't take the 0 page to free into account, which still needs to call UnsetGuardPage() even no memory needs to free. The fix is just moving the calling of UnsetGuardPage() to the place right after calling AdjustMemoryF(). Cc: Star Zeng <star.zeng@intel.com> Cc: Eric Dong <eric.dong@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang <jian.j.wang@intel.com> Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
Diffstat (limited to 'MdeModulePkg/Core/Dxe')
-rw-r--r--MdeModulePkg/Core/Dxe/Mem/HeapGuard.c7
-rw-r--r--MdeModulePkg/Core/Dxe/Mem/Pool.c16
2 files changed, 11 insertions, 12 deletions
diff --git a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c
index 92753c7..392aeb8 100644
--- a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c
+++ b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c
@@ -1135,10 +1135,6 @@ CoreConvertPagesWithGuard (
OldPages = NumberOfPages;
AdjustMemoryF (&Start, &NumberOfPages);
- if (NumberOfPages == 0) {
- return EFI_SUCCESS;
- }
-
//
// It's safe to unset Guard page inside memory lock because there should
// be no memory allocation occurred in updating memory page attribute at
@@ -1147,6 +1143,9 @@ CoreConvertPagesWithGuard (
// marking it usable (from non-present to present).
//
UnsetGuardForMemory (OldStart, OldPages);
+ if (NumberOfPages == 0) {
+ return EFI_SUCCESS;
+ }
} else {
AdjustMemoryA (&Start, &NumberOfPages);
}
diff --git a/MdeModulePkg/Core/Dxe/Mem/Pool.c b/MdeModulePkg/Core/Dxe/Mem/Pool.c
index df9a1d2..1ff2061 100644
--- a/MdeModulePkg/Core/Dxe/Mem/Pool.c
+++ b/MdeModulePkg/Core/Dxe/Mem/Pool.c
@@ -642,15 +642,15 @@ CoreFreePoolPagesWithGuard (
NoPagesGuarded = NoPages;
AdjustMemoryF (&Memory, &NoPages);
+ //
+ // It's safe to unset Guard page inside memory lock because there should
+ // be no memory allocation occurred in updating memory page attribute at
+ // this point. And unsetting Guard page before free will prevent Guard
+ // page just freed back to pool from being allocated right away before
+ // marking it usable (from non-present to present).
+ //
+ UnsetGuardForMemory (MemoryGuarded, NoPagesGuarded);
if (NoPages > 0) {
- //
- // It's safe to unset Guard page inside memory lock because there should
- // be no memory allocation occurred in updating memory page attribute at
- // this point. And unsetting Guard page before free will prevent Guard
- // page just freed back to pool from being allocated right away before
- // marking it usable (from non-present to present).
- //
- UnsetGuardForMemory (MemoryGuarded, NoPagesGuarded);
CoreFreePoolPagesI (PoolType, Memory, NoPages);
}
}