]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Mem/Page.c
Guarantee that free memory in the 4K page starting at address 0 is always cleared...
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Mem / Page.c
index 8a6d35d6e45dcd0501163d0c62975244968556d2..90976a1f0f33f397455797c75b929679de0eaed4 100644 (file)
@@ -177,7 +177,20 @@ CoreAddRange (
   ASSERT_LOCKED (&gMemoryLock);\r
 \r
   DEBUG ((DEBUG_PAGE, "AddRange: %lx-%lx to %d\n", Start, End, Type));\r
-\r
+  \r
+  //\r
+  // If memory of type EfiConventionalMemory is being added that includes the page \r
+  // starting at address 0, then zero the page starting at address 0.  This has \r
+  // two benifits.  It helps find NULL pointer bugs and it also maximizes \r
+  // compatibility with operating systems that may evaluate memory in this page \r
+  // for legacy data structures.  If memory of any other type is added starting \r
+  // at address 0, then do not zero the page at address 0 because the page is being \r
+  // used for other purposes.\r
+  //  \r
+  if (Type == EfiConventionalMemory && Start == 0 && (End >= EFI_PAGE_SIZE - 1)) {\r
+    SetMem ((VOID *)(UINTN)Start, EFI_PAGE_SIZE, 0);\r
+  }\r
+  \r
   //\r
   // Memory map being altered so updated key\r
   //\r