]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/DxeIplPeim: reserve page 0 for NULL pointer detection
authorJian J Wang <devel@edk2.groups.io>
Wed, 6 Nov 2019 21:13:32 +0000 (21:13 +0000)
committerJian J Wang <jian.j.wang@intel.com>
Sat, 9 Nov 2019 02:59:56 +0000 (10:59 +0800)
When a boot loader examines the memory map, it can see that location 0
is available memory. If it chooses to use that memory, and
PcdNullPointerDetectionPropertyMask is enabled, use of memory in page 0
will cause an exception. This does occur when running the memtest86
program.

Leaving page 0 available is for legacy support purpose. Since we have
deprecated the support of legacy, the solution is just reserving it so
that it cannot be allocated for other uses.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1885
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c
MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c

index 172d7cd1c60ccfebd3b7c48796078c9be9b94fa4..6e8ca824d469e9db51405fc673c41d539e750436 100644 (file)
@@ -246,8 +246,12 @@ HandOffToDxeCore (
   EFI_PEI_VECTOR_HANDOFF_INFO_PPI *VectorHandoffInfoPpi;\r
   BOOLEAN                   BuildPageTablesIa32Pae;\r
 \r
+  //\r
+  // Clear page 0 and mark it as allocated if NULL pointer detection is enabled.\r
+  //\r
   if (IsNullDetectionEnabled ()) {\r
     ClearFirst4KPage (HobList.Raw);\r
+    BuildMemoryAllocationHob (0, EFI_PAGES_TO_SIZE (1), EfiBootServicesData);\r
   }\r
 \r
   Status = PeiServicesAllocatePages (EfiBootServicesData, EFI_SIZE_TO_PAGES (STACK_SIZE), &BaseOfStack);\r
index 2867610bff4d8bc37211ea4892b716246d77e3a3..f465eb1d8ac4237f1702ee8de4df0fae2d0e1b23 100644 (file)
@@ -36,8 +36,12 @@ HandOffToDxeCore (
   EFI_VECTOR_HANDOFF_INFO         *VectorInfo;\r
   EFI_PEI_VECTOR_HANDOFF_INFO_PPI *VectorHandoffInfoPpi;\r
 \r
+  //\r
+  // Clear page 0 and mark it as allocated if NULL pointer detection is enabled.\r
+  //\r
   if (IsNullDetectionEnabled ()) {\r
     ClearFirst4KPage (HobList.Raw);\r
+    BuildMemoryAllocationHob (0, EFI_PAGES_TO_SIZE (1), EfiBootServicesData);\r
   }\r
 \r
   //\r