diff options
author | mdkinney <mdkinney@6f19259b-4bc3-4df7-8a09-765794883524> | 2013-03-22 21:20:07 +0000 |
---|---|---|
committer | mdkinney <mdkinney@6f19259b-4bc3-4df7-8a09-765794883524> | 2013-03-22 21:20:07 +0000 |
commit | d436d5ca0936b1be59bd60087cd0b6e0d2e08d76 (patch) | |
tree | 8c04dcdc442b7881f835327d7d558223d39def74 /MdeModulePkg/Core | |
parent | 9a34087280a857eb0b80ff27d0efabc540b36f99 (diff) | |
download | edk2-d436d5ca0936b1be59bd60087cd0b6e0d2e08d76.zip edk2-d436d5ca0936b1be59bd60087cd0b6e0d2e08d76.tar.gz edk2-d436d5ca0936b1be59bd60087cd0b6e0d2e08d76.tar.bz2 |
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 <michael.d.kinney@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14218 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdeModulePkg/Core')
-rw-r--r-- | MdeModulePkg/Core/Dxe/Mem/Page.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c index 8a6d35d..90976a1 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -177,7 +177,20 @@ CoreAddRange ( 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
//
|