- Revert 49927 "Update to trunk" as it breaks KsStudio (again)
[reactos.git] / ntoskrnl / mm / i386 / page.c
index a7dbce4..9ce0ef5 100644 (file)
@@ -223,10 +223,7 @@ MmGetPageTableForProcess(PEPROCESS Process, PVOID Address, BOOLEAN Create)
                 MmDeleteHyperspaceMapping(PageDir);
                 return NULL;
             }
-            MI_SET_USAGE(MI_USAGE_LEGACY_PAGE_DIRECTORY);
-            if (Process) MI_SET_PROCESS2(Process->ImageFileName);
-            if (!Process) MI_SET_PROCESS2("Kernel Legacy");
-            Status = MmRequestPageMemoryConsumer(MC_SYSTEM, FALSE, &Pfn);
+            Status = MmRequestPageMemoryConsumer(MC_NPPOOL, FALSE, &Pfn);
             if (!NT_SUCCESS(Status) || Pfn == 0)
             {
                 KeBugCheck(MEMORY_MANAGEMENT);
@@ -234,7 +231,7 @@ MmGetPageTableForProcess(PEPROCESS Process, PVOID Address, BOOLEAN Create)
             Entry = InterlockedCompareExchangePte(&PageDir[PdeOffset], PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE | PA_USER, 0);
             if (Entry != 0)
             {
-                MmReleasePageMemoryConsumer(MC_SYSTEM, Pfn);
+                MmReleasePageMemoryConsumer(MC_NPPOOL, Pfn);
                 Pfn = PTE_TO_PFN(Entry);
             }
         }
@@ -261,9 +258,6 @@ MmGetPageTableForProcess(PEPROCESS Process, PVOID Address, BOOLEAN Create)
                 {
                     return NULL;
                 }
-                MI_SET_USAGE(MI_USAGE_LEGACY_PAGE_DIRECTORY);
-                if (Process) MI_SET_PROCESS2(Process->ImageFileName);
-                if (!Process) MI_SET_PROCESS2("Kernel Legacy");
                 Status = MmRequestPageMemoryConsumer(MC_SYSTEM, FALSE, &Pfn);
                 if (!NT_SUCCESS(Status) || Pfn == 0)
                 {
@@ -286,10 +280,7 @@ MmGetPageTableForProcess(PEPROCESS Process, PVOID Address, BOOLEAN Create)
             {
                 return NULL;
             }
-            MI_SET_USAGE(MI_USAGE_LEGACY_PAGE_DIRECTORY);
-            if (Process) MI_SET_PROCESS2(Process->ImageFileName);
-            if (!Process) MI_SET_PROCESS2("Kernel Legacy");
-            Status = MmRequestPageMemoryConsumer(MC_SYSTEM, FALSE, &Pfn);
+            Status = MmRequestPageMemoryConsumer(MC_NPPOOL, FALSE, &Pfn);
             if (!NT_SUCCESS(Status) || Pfn == 0)
             {
                 KeBugCheck(MEMORY_MANAGEMENT);
@@ -297,7 +288,7 @@ MmGetPageTableForProcess(PEPROCESS Process, PVOID Address, BOOLEAN Create)
             Entry = InterlockedCompareExchangePte(PageDir, PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE | PA_USER, 0);
             if (Entry != 0)
             {
-                MmReleasePageMemoryConsumer(MC_SYSTEM, Pfn);
+                MmReleasePageMemoryConsumer(MC_NPPOOL, Pfn);
             }
         }
     }
@@ -458,7 +449,7 @@ MmDeleteVirtualMapping(PEPROCESS Process, PVOID Address, BOOLEAN FreePage,
     
     if (FreePage && WasValid)
     {
-        MmReleasePageMemoryConsumer(MC_SYSTEM, Pfn);
+        MmReleasePageMemoryConsumer(MC_NPPOOL, Pfn);
     }
     
     /*
@@ -474,18 +465,6 @@ MmDeleteVirtualMapping(PEPROCESS Process, PVOID Address, BOOLEAN FreePage,
     }
 }
 
-VOID
-NTAPI
-MmGetPageFileMapping(PEPROCESS Process, PVOID Address,
-                                        SWAPENTRY* SwapEntry)
-/*
- * FUNCTION: Get a page file mapping
- */
-{
-       ULONG Entry = MmGetPageEntryForProcess(Process, Address);
-       *SwapEntry = Entry >> 1;
-}
-
 VOID
 NTAPI
 MmDeletePageFileMapping(PEPROCESS Process, PVOID Address,
@@ -930,6 +909,54 @@ MmGetPhysicalAddress(PVOID vaddr)
     return p;
 }
 
+VOID
+NTAPI
+MmUpdatePageDir(PEPROCESS Process, PVOID Address, ULONG Size)
+{
+    ULONG StartOffset, EndOffset, Offset;
+    PULONG Pde;
+    
+    //
+    // Check if the process isn't there anymore
+    // This is probably a bad sign, since it means the caller is setting cr3 to
+    // 0 or something...
+    //
+    if ((PTE_TO_PFN(Process->Pcb.DirectoryTableBase[0]) == 0) && (Process != PsGetCurrentProcess()))
+    {
+        DPRINT1("Process: %16s is dead: %p\n", Process->ImageFileName, Process->Pcb.DirectoryTableBase[0]);
+        ASSERT(FALSE);
+        return;
+    }
+
+    if (Address < MmSystemRangeStart)
+    {
+        KeBugCheck(MEMORY_MANAGEMENT);
+    }
+
+    StartOffset = ADDR_TO_PDE_OFFSET(Address);
+    EndOffset = ADDR_TO_PDE_OFFSET((PVOID)((ULONG_PTR)Address + Size));
+
+    if (Process != NULL && Process != PsGetCurrentProcess())
+    {
+        Pde = MmCreateHyperspaceMapping(PTE_TO_PFN(Process->Pcb.DirectoryTableBase[0]));
+    }
+    else
+    {
+        Pde = (PULONG)PAGEDIRECTORY_MAP;
+    }
+    for (Offset = StartOffset; Offset <= EndOffset; Offset++)
+    {
+        if (Offset != ADDR_TO_PDE_OFFSET(PAGETABLE_MAP))
+        {
+            InterlockedCompareExchangePte(&Pde[Offset], MmGlobalKernelPageDirectory[Offset], 0);
+        }
+    }
+    if (Pde != (PULONG)PAGEDIRECTORY_MAP)
+    {
+        MmDeleteHyperspaceMapping(Pde);
+    }
+}
+
 VOID
 INIT_FUNCTION
 NTAPI