[ros-diffs] [tkreuzer] 55597: [FREELDR] Fix a bug in the new heap code and re-enable it. The previous problems seem to be gone. Thanks to Amine for testing.

tkreuzer at svn.reactos.org tkreuzer at svn.reactos.org
Tue Feb 14 19:48:04 UTC 2012


Author: tkreuzer
Date: Tue Feb 14 19:48:04 2012
New Revision: 55597

URL: http://svn.reactos.org/svn/reactos?rev=55597&view=rev
Log:
[FREELDR]
Fix a bug in the new heap code and re-enable it. The previous problems seem to be gone. Thanks to Amine for testing.

Modified:
    trunk/reactos/boot/freeldr/freeldr/CMakeLists.txt
    trunk/reactos/boot/freeldr/freeldr/freeldr_base.rbuild
    trunk/reactos/boot/freeldr/freeldr/mm/heap_new.c
    trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c

Modified: trunk/reactos/boot/freeldr/freeldr/CMakeLists.txt
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/CMakeLists.txt?rev=55597&r1=55596&r2=55597&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/CMakeLists.txt [iso-8859-1] Tue Feb 14 19:48:04 2012
@@ -54,7 +54,7 @@
     inifile/parse.c
     mm/meminit.c
     mm/mm.c
-    mm/heap.c
+    mm/heap_new.c
     reactos/registry.c
     reactos/arcname.c
     reactos/archwsup.c
@@ -155,7 +155,6 @@
 list(APPEND FREELDR_BASE_SOURCE
     bootmgr.c # This file is compiled with custom definitions
     freeldr.c
-    rtl/bget.c
     rtl/libsupp.c)
 
 if (NOT MSVC)

Modified: trunk/reactos/boot/freeldr/freeldr/freeldr_base.rbuild
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/freeldr_base.rbuild?rev=55597&r1=55596&r2=55597&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/freeldr_base.rbuild [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/freeldr_base.rbuild [iso-8859-1] Tue Feb 14 19:48:04 2012
@@ -40,7 +40,7 @@
 		<file>parse.c</file>
 	</directory>
 	<directory name="mm">
-		<file>heap.c</file>
+		<file>heap_new.c</file>
 		<file>meminit.c</file>
 		<file>mm.c</file>
 	</directory>
@@ -51,7 +51,6 @@
 		<file>binhive.c</file>
 	</directory>
 	<directory name="rtl">
-		<file>bget.c</file>
 		<file>libsupp.c</file>
 	</directory>
 	<directory name="ui">

Modified: trunk/reactos/boot/freeldr/freeldr/mm/heap_new.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/mm/heap_new.c?rev=55597&r1=55596&r2=55597&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/mm/heap_new.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/mm/heap_new.c [iso-8859-1] Tue Feb 14 19:48:04 2012
@@ -168,7 +168,7 @@
         if (Block->Size == 0)
         {
             /* Align the end address up to cover the end of the heap */
-            EndAddress = ALIGN_DOWN_POINTER_BY(Block->Data, PAGE_SIZE);
+            EndAddress = ALIGN_UP_POINTER_BY(Block->Data, PAGE_SIZE);
         }
         else
         {
@@ -176,14 +176,19 @@
             EndAddress = ALIGN_DOWN_POINTER_BY(Block->Data, PAGE_SIZE);
         }
 
-        FreePages = (PFN_COUNT)((EndAddress - StartAddress) / MM_PAGE_SIZE);
-        AllFreePages += FreePages;
-
-        /* Now mark the pages free */
-        MmMarkPagesInLookupTable(PageLookupTableAddress,
-                                 (ULONG_PTR)StartAddress / MM_PAGE_SIZE,
-                                 FreePages,
-                                 LoaderFree);
+        /* Check if we have free pages */
+        if (EndAddress > StartAddress)
+        {
+            /* Calculate the size of the free region in pages */
+            FreePages = (PFN_COUNT)((EndAddress - StartAddress) / MM_PAGE_SIZE);
+            AllFreePages += FreePages;
+
+            /* Now mark the pages free */
+            MmMarkPagesInLookupTable(PageLookupTableAddress,
+                                     (ULONG_PTR)StartAddress / MM_PAGE_SIZE,
+                                     FreePages,
+                                     LoaderFree);
+        }
 
         /* bail out, if it was the last block */
         if (Block->Size == 0) break;
@@ -460,8 +465,6 @@
     HeapFree(FrLdrDefaultHeap, MemoryPointer, 'pHmM');
 }
 
-
-#undef ExAllocatePoolWithTag
 PVOID
 NTAPI
 ExAllocatePoolWithTag(
@@ -481,7 +484,6 @@
     return HeapAllocate(FrLdrDefaultHeap, NumberOfBytes, 0);
 }
 
-#undef ExFreePool
 VOID
 NTAPI
 ExFreePool(
@@ -490,7 +492,6 @@
     HeapFree(FrLdrDefaultHeap, P, 0);
 }
 
-#undef ExFreePoolWithTag
 VOID
 NTAPI
 ExFreePoolWithTag(

Modified: trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c?rev=55597&r1=55596&r2=55597&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c [iso-8859-1] Tue Feb 14 19:48:04 2012
@@ -203,7 +203,7 @@
 	//BOOLEAN Status;
 
 	/* Cleanup heap */
-	//HeapCleanupAll();
+	HeapCleanupAll();
 
 	//
 	// Creating a suitable memory map for Windows can be tricky, so let's




More information about the Ros-diffs mailing list