When 0 address protection is enabled,
0-4k memory needs to be preallocated to
prevent UEFI applications from allocating use,
such as grub.

Cc: Ard Biesheuvel <ardb+tianoc...@kernel.org>
Cc: Bibo Mao <maob...@loongson.cn>
Cc: Chao Li <lic...@loongson.cn>
Cc: Leif Lindholm <quic_llind...@quicinc.com>
Cc: Liming Gao <gaolim...@byosoft.com.cn>
Cc: Michael D Kinney <michael.d.kin...@intel.com>
Signed-off-by: xianglai li <lixiang...@loongson.cn>
---
 .../LoongArchQemuPkg/PlatformPei/MemDetect.c        | 13 +++++++++++++
 .../LoongArchQemuPkg/PlatformPei/PlatformPei.inf    |  1 +
 2 files changed, 14 insertions(+)

diff --git a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c 
b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c
index fad4cff8d8..7e6a4a3aa9 100644
--- a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c
+++ b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c
@@ -101,4 +101,17 @@ InitializeRamRegions (
 
     AddMemoryRangeHob ( pEntry->BaseAddr, pEntry->BaseAddr + pEntry->Length);
   }
+
+  //
+  //When 0 address protection is enabled,
+  //0-4k memory needs to be preallocated to prevent UEFI applications from 
allocating use,
+  //such as grub
+  //
+  if (PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT0) {
+    BuildMemoryAllocationHob (
+          0,
+          EFI_PAGE_SIZE,
+          EfiBootServicesData
+          );
+  }
 }
diff --git a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf 
b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf
index 268efac585..6cc3513b63 100644
--- a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf
+++ b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf
@@ -59,6 +59,7 @@
   gLoongArchQemuPkgTokenSpaceGuid.PcdDeviceTreeBase
   gLoongArchQemuPkgTokenSpaceGuid.PcdDeviceTreePadding
   gLoongArchQemuPkgTokenSpaceGuid.PcdRtcBaseAddress
+  gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask
 
 [FixedPcd]
   gLoongArchQemuPkgTokenSpaceGuid.PcdFlashDxeFvBase
-- 
2.39.1




-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#105553): https://edk2.groups.io/g/devel/message/105553
Mute This Topic: https://groups.io/mt/99261444/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to