[ros-diffs] [tkreuzer] 46849: [HAL] Fix a possible overflow of the hal heap in HalpMapPhysicalMemory64 and simplify the code.

tkreuzer at svn.reactos.org tkreuzer at svn.reactos.org
Mon Apr 12 21:40:05 CEST 2010


Author: tkreuzer
Date: Mon Apr 12 21:39:50 2010
New Revision: 46849

URL: http://svn.reactos.org/svn/reactos?rev=46849&view=rev
Log:
[HAL]
Fix a possible overflow of the hal heap in HalpMapPhysicalMemory64 and simplify the code.

Modified:
    trunk/reactos/hal/halx86/generic/halinit.c

Modified: trunk/reactos/hal/halx86/generic/halinit.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halx86/generic/halinit.c?rev=46849&r1=46848&r2=46849&view=diff
==============================================================================
--- trunk/reactos/hal/halx86/generic/halinit.c [iso-8859-1] (original)
+++ trunk/reactos/hal/halx86/generic/halinit.c [iso-8859-1] Mon Apr 12 21:39:50 2010
@@ -145,33 +145,31 @@
 
     /* Start at the current HAL heap base */
     BaseAddress = HalpHeapStart;
+    VirtualAddress = BaseAddress;
 
     /* Loop until we have all the pages required */
     while (UsedPages < PageCount)
     {
-        /* Begin a new loop cycle */
-        UsedPages = 0;
-        VirtualAddress = BaseAddress;
-
         /* If this overflows past the HAL heap, it means there's no space */
-        if (BaseAddress == NULL) return NULL;
-
-        /* Loop until we have all the pages required in a single run */
-        while (UsedPages < PageCount)
-        {
-            /* Get the PTE for this address and check if it's available */
-            PointerPte = HalAddressToPte(VirtualAddress);
-            if (*(PULONG)PointerPte)
-            {
-                /* PTE has data, skip it and start with a new base address */
-                BaseAddress = (PVOID)((ULONG_PTR)VirtualAddress + PAGE_SIZE);
-                break;
-            }
-         
-            /* PTE is available, keep going on this run */
-            VirtualAddress = (PVOID)((ULONG_PTR)VirtualAddress + PAGE_SIZE);
-            UsedPages++;
-        }
+        if (VirtualAddress == NULL) return NULL;
+
+        /* Get the PTE for this address */
+        PointerPte = HalAddressToPte(VirtualAddress);
+
+        /* Go to the next page */
+        VirtualAddress = (PVOID)((ULONG_PTR)VirtualAddress + PAGE_SIZE);
+
+        /* Check if the page is available */
+        if (PointerPte->Valid)
+        {
+            /* PTE has data, skip it and start with a new base address */
+            BaseAddress = VirtualAddress;
+            UsedPages = 0;
+            continue;
+        }
+
+        /* PTE is available, keep going on this run */
+        UsedPages++;
     }
 
     /* Take the base address of the page plus the actual offset in the address */




More information about the Ros-diffs mailing list