audk/MdeModulePkg/Core/Dxe/Misc
Jian J Wang 7fef06af4e MdeModulePkg/Core: allow HeapGuard even before CpuArchProtocol installed
Due to the fact that HeapGuard needs CpuArchProtocol to update page
attributes, the feature is normally enabled after CpuArchProtocol is
installed. Since there're some drivers are loaded before CpuArchProtocl,
they cannot make use HeapGuard feature to detect potential issues.

This patch fixes above situation by updating the DXE core to skip the
NULL check against global gCpu in the IsMemoryTypeToGuard(), and adding
NULL check against gCpu in SetGuardPage() and UnsetGuardPage() to make
sure that they can be called but do nothing. This will allow HeapGuard to
record all guarded memory without setting the related Guard pages to not-
present.

Once the CpuArchProtocol is installed, a protocol notify will be called
to complete the work of setting Guard pages to not-present.

Please note that above changes will cause a #PF in GCD code during cleanup
of map entries, which is initiated by CpuDxe driver to update real mtrr
and paging attributes back to GCD. During that time, CpuDxe doesn't allow
GCD to update memory attributes and then any Guard page cannot be unset.
As a result, this will prevent Guarded memory from freeing during memory
map cleanup.

The solution is to avoid allocating guarded memory as memory map entries
in GCD code. It's done by setting global mOnGuarding to TRUE before memory
allocation and setting it back to FALSE afterwards in GCD function
CoreAllocateGcdMapEntry().

Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Jiewen Yao <jiewen.yao@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>
2018-03-16 15:01:11 +08:00
..
DebugImageInfo.c MdeModulePkg: Refine casting expression result to bigger size 2017-03-06 14:33:20 +08:00
InstallConfigurationTable.c MdeModulePkg: Fix use-after-free error in InstallConfigurationTable() 2017-06-20 16:55:10 +08:00
MemoryAttributesTable.c MdeModulePkg/DxeCore: switch to MdePkg allocation granularity macros 2017-03-06 11:29:20 +01:00
MemoryProtection.c MdeModulePkg/Core: allow HeapGuard even before CpuArchProtocol installed 2018-03-16 15:01:11 +08:00
PropertiesTable.c MdeModulePkg/Core: Fix incorrect memory map generated in a rare case 2017-12-19 15:19:46 +08:00
SetWatchdogTimer.c Update the copyright notice format 2010-04-24 09:49:11 +00:00
Stall.c MdeModulePkg/Stall: Refine to compare 2 values with the same type 2017-01-12 21:26:27 +08:00