MdeModulePkg/SmmCore: add sanity check for SetMemoryAttributes

Heap Guard feature needs enough memory and paging to work. Otherwise
calling SetMemoryAttributes to change page attribute will fail. This
patch add necessary check of result of calling SetMemoryAttributes.
This can help users to debug their problem in enabling this feature.

Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@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 2018-04-11 16:35:32 +08:00 committed by Star Zeng
parent a5cd613cdb
commit 5fef2c7069
1 changed files with 18 additions and 12 deletions

View File

@ -592,14 +592,17 @@ SetGuardPage (
IN EFI_PHYSICAL_ADDRESS BaseAddress IN EFI_PHYSICAL_ADDRESS BaseAddress
) )
{ {
EFI_STATUS Status;
if (mSmmMemoryAttribute != NULL) { if (mSmmMemoryAttribute != NULL) {
mOnGuarding = TRUE; mOnGuarding = TRUE;
mSmmMemoryAttribute->SetMemoryAttributes ( Status = mSmmMemoryAttribute->SetMemoryAttributes (
mSmmMemoryAttribute, mSmmMemoryAttribute,
BaseAddress, BaseAddress,
EFI_PAGE_SIZE, EFI_PAGE_SIZE,
EFI_MEMORY_RP EFI_MEMORY_RP
); );
ASSERT_EFI_ERROR (Status);
mOnGuarding = FALSE; mOnGuarding = FALSE;
} }
} }
@ -619,14 +622,17 @@ UnsetGuardPage (
IN EFI_PHYSICAL_ADDRESS BaseAddress IN EFI_PHYSICAL_ADDRESS BaseAddress
) )
{ {
EFI_STATUS Status;
if (mSmmMemoryAttribute != NULL) { if (mSmmMemoryAttribute != NULL) {
mOnGuarding = TRUE; mOnGuarding = TRUE;
mSmmMemoryAttribute->ClearMemoryAttributes ( Status = mSmmMemoryAttribute->ClearMemoryAttributes (
mSmmMemoryAttribute, mSmmMemoryAttribute,
BaseAddress, BaseAddress,
EFI_PAGE_SIZE, EFI_PAGE_SIZE,
EFI_MEMORY_RP EFI_MEMORY_RP
); );
ASSERT_EFI_ERROR (Status);
mOnGuarding = FALSE; mOnGuarding = FALSE;
} }
} }