MdeModulePkg/DxeCore: Fix issues in Heap Guard

One issue is that macros defined in HeapGuard.h

    GUARD_HEAP_TYPE_PAGE
    GUARD_HEAP_TYPE_POOL

doesn't match the definition of PCD PcdHeapGuardPropertyMask in
MdeModulePkg.dec. This patch fixed it by exchanging the BIT0 and BIT1
of them.

Another is that method AdjustMemoryF() will return a bigger NumberOfPages than
the value passed in. This is caused by counting twice of a shared Guard page
which can be used for both head and tail Guard of the memory before it and
after it. This happens only when partially freeing just one page in the middle
of a bunch of allocated pages. The freed page should be turned into a new
Guard page.

Cc: Jie Lin <jie.lin@intel.com>
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: Star Zeng <star.zeng@intel.com>
This commit is contained in:
Jian J Wang
2017-12-09 19:15:49 +08:00
committed by Star Zeng
parent 1ea53108f6
commit 6cf0a677a9
4 changed files with 88 additions and 28 deletions

View File

@@ -920,21 +920,22 @@ CoreConvertPagesEx (
UINT64 EndToClear;
StartToClear = Start;
EndToClear = RangeEnd;
EndToClear = RangeEnd + 1;
if (PcdGet8 (PcdHeapGuardPropertyMask) & (BIT1|BIT0)) {
if (IsGuardPage(StartToClear)) {
StartToClear += EFI_PAGE_SIZE;
}
if (IsGuardPage (EndToClear)) {
if (IsGuardPage (EndToClear - 1)) {
EndToClear -= EFI_PAGE_SIZE;
}
ASSERT (EndToClear > StartToClear);
}
DEBUG_CLEAR_MEMORY(
(VOID *)(UINTN)StartToClear,
(UINTN)(EndToClear - StartToClear + 1)
);
if (EndToClear > StartToClear) {
DEBUG_CLEAR_MEMORY(
(VOID *)(UINTN)StartToClear,
(UINTN)(EndToClear - StartToClear)
);
}
}
}