Revision: 14218
          http://edk2.svn.sourceforge.net/edk2/?rev=14218&view=rev
Author:   mdkinney
Date:     2013-03-22 21:20:07 +0000 (Fri, 22 Mar 2013)
Log Message:
-----------
Guarantee that free memory in the 4K page starting at address 0 is always 
cleared to 0.  The algorithm is to clear page zero if it is registered with the 
DXE Core with type EfiConventionalMemory, and to also clear page zero if it is 
freed using the UEFI Boot Service FreePages().  This patch improves OS 
compatibility for OSes that may evaluate page 0 for legacy data structures.  
Before this patch, free memory may contain random values which induces random 
boot failures for some OSes.  This patch may also help find NULL pointer bugs 
sooner because all of the fields in a data structure dereferenced through NULL 
will also be NULL now.

Signed-off-by: Michael Kinney <[email protected]>
Reviewed-by: Laszlo Ersek <[email protected]>
Reviewed-by: Jordan Justen <[email protected]>

Modified Paths:
--------------
    trunk/edk2/MdeModulePkg/Core/Dxe/Mem/Page.c

Modified: trunk/edk2/MdeModulePkg/Core/Dxe/Mem/Page.c
===================================================================
--- trunk/edk2/MdeModulePkg/Core/Dxe/Mem/Page.c 2013-03-22 21:18:02 UTC (rev 
14217)
+++ trunk/edk2/MdeModulePkg/Core/Dxe/Mem/Page.c 2013-03-22 21:20:07 UTC (rev 
14218)
@@ -177,8 +177,21 @@
   ASSERT_LOCKED (&gMemoryLock);
 
   DEBUG ((DEBUG_PAGE, "AddRange: %lx-%lx to %d\n", Start, End, Type));
-
+  
   //
+  // If memory of type EfiConventionalMemory is being added that includes the 
page 
+  // starting at address 0, then zero the page starting at address 0.  This 
has 
+  // two benifits.  It helps find NULL pointer bugs and it also maximizes 
+  // compatibility with operating systems that may evaluate memory in this 
page 
+  // for legacy data structures.  If memory of any other type is added 
starting 
+  // at address 0, then do not zero the page at address 0 because the page is 
being 
+  // used for other purposes.
+  //  
+  if (Type == EfiConventionalMemory && Start == 0 && (End >= EFI_PAGE_SIZE - 
1)) {
+    SetMem ((VOID *)(UINTN)Start, EFI_PAGE_SIZE, 0);
+  }
+  
+  //
   // Memory map being altered so updated key
   //
   mMemoryMapKey += 1;

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to