[NTOS]: Implement MiAllocatePfn, it is a simpler wrapper that grabs a page, sets...
authorSir Richard <sir_richard@svn.reactos.org>
Sun, 30 May 2010 03:02:39 +0000 (03:02 +0000)
committerSir Richard <sir_richard@svn.reactos.org>
Sun, 30 May 2010 03:02:39 +0000 (03:02 +0000)
[NTOS]: Use MiAllocatePfn in MiLoadImageSection instead of MmAllocPage. Other than doing a better job at initializing the page, it creates our first caller of this function, great for testing, since this is a rather high-demand function, especially at boot.
Please test.

svn path=/trunk/; revision=47432

reactos/ntoskrnl/mm/ARM3/pfnlist.c
reactos/ntoskrnl/mm/sysldr.c

index b70e191..0a7ea07 100644 (file)
@@ -618,6 +618,44 @@ MiInitializePfn(IN PFN_NUMBER PageFrameIndex,
     Pfn1->u2.ShareCount++;
 }
 
+PFN_NUMBER
+NTAPI
+MiAllocatePfn(IN PMMPTE PointerPte,
+              IN ULONG Protection)
+{
+    KIRQL OldIrql;
+    PFN_NUMBER PageFrameIndex;
+    MMPTE TempPte;
+    
+    /* Make an empty software PTE */
+    MI_MAKE_SOFTWARE_PTE(&TempPte, MM_READWRITE);
+    
+    /* Lock the PFN database */
+    OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
+    
+    /* Check if we're running low on pages */
+    if (MmAvailablePages < 128)
+    {
+        DPRINT1("Warning, running low on memory: %d pages left\n", MmAvailablePages);
+        //MiEnsureAvailablePageOrWait(NULL, OldIrql);
+    }
+    
+    /* Grab a page */
+    PageFrameIndex = MiRemoveAnyPage(0);
+    
+    /* Write the software PTE */
+    ASSERT(PointerPte->u.Hard.Valid == 0);
+    *PointerPte = TempPte;
+    PointerPte->u.Soft.Protection |= Protection;
+    
+    /* Initialize its PFN entry */
+    MiInitializePfn(PageFrameIndex, PointerPte, TRUE);
+    
+    /* Release the PFN lock and return the page */
+    KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
+    return PageFrameIndex;
+}
+
 VOID
 NTAPI
 MiDecrementShareCount(IN PMMPFN Pfn1,
index fcecf3c..a242b4b 100644 (file)
@@ -172,7 +172,7 @@ MiLoadImageSection(IN OUT PVOID *SectionPtr,
     while (PointerPte < LastPte)
     {
         /* Allocate a page */
-        TempPte.u.Hard.PageFrameNumber = MmAllocPage(MC_NPPOOL);
+        TempPte.u.Hard.PageFrameNumber = MiAllocatePfn(PointerPte, MM_EXECUTE);
         
         /* Write it */
         ASSERT(PointerPte->u.Hard.Valid == 0);