MdeModulePkg/Core: fix guard page missing issue

This issue is a regression one caused by a patch at

    425d25699b

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>
This commit is contained in:
Jian J Wang 2018-01-26 19:47:14 +08:00 committed by Star Zeng
parent 821807bcef
commit 1263ecf2ff
2 changed files with 11 additions and 12 deletions

View File

@ -1135,10 +1135,6 @@ CoreConvertPagesWithGuard (
OldPages = NumberOfPages; OldPages = NumberOfPages;
AdjustMemoryF (&Start, &NumberOfPages); AdjustMemoryF (&Start, &NumberOfPages);
if (NumberOfPages == 0) {
return EFI_SUCCESS;
}
// //
// It's safe to unset Guard page inside memory lock because there should // It's safe to unset Guard page inside memory lock because there should
// be no memory allocation occurred in updating memory page attribute at // be no memory allocation occurred in updating memory page attribute at
@ -1147,6 +1143,9 @@ CoreConvertPagesWithGuard (
// marking it usable (from non-present to present). // marking it usable (from non-present to present).
// //
UnsetGuardForMemory (OldStart, OldPages); UnsetGuardForMemory (OldStart, OldPages);
if (NumberOfPages == 0) {
return EFI_SUCCESS;
}
} else { } else {
AdjustMemoryA (&Start, &NumberOfPages); AdjustMemoryA (&Start, &NumberOfPages);
} }

View File

@ -642,7 +642,6 @@ CoreFreePoolPagesWithGuard (
NoPagesGuarded = NoPages; NoPagesGuarded = NoPages;
AdjustMemoryF (&Memory, &NoPages); AdjustMemoryF (&Memory, &NoPages);
if (NoPages > 0) {
// //
// It's safe to unset Guard page inside memory lock because there should // It's safe to unset Guard page inside memory lock because there should
// be no memory allocation occurred in updating memory page attribute at // be no memory allocation occurred in updating memory page attribute at
@ -651,6 +650,7 @@ CoreFreePoolPagesWithGuard (
// marking it usable (from non-present to present). // marking it usable (from non-present to present).
// //
UnsetGuardForMemory (MemoryGuarded, NoPagesGuarded); UnsetGuardForMemory (MemoryGuarded, NoPagesGuarded);
if (NoPages > 0) {
CoreFreePoolPagesI (PoolType, Memory, NoPages); CoreFreePoolPagesI (PoolType, Memory, NoPages);
} }
} }