- Revert 49927 "Update to trunk" as it breaks KsStudio (again)
[reactos.git] / ntoskrnl / mm / rmap.c
index 8d6867e..8d6b7a6 100644 (file)
@@ -10,9 +10,6 @@
 /* INCLUDES *****************************************************************/
 
 #include <ntoskrnl.h>
-#ifdef NEWCC
-#include "../cache/section/newmm.h"
-#endif
 #define NDEBUG
 #include <debug.h>
 
 
 /* TYPES ********************************************************************/
 
+typedef struct _MM_RMAP_ENTRY
+{
+   struct _MM_RMAP_ENTRY* Next;
+   PEPROCESS Process;
+   PVOID Address;
+#if DBG
+   PVOID Caller;
+#endif
+}
+MM_RMAP_ENTRY, *PMM_RMAP_ENTRY;
+
 /* GLOBALS ******************************************************************/
 
+static FAST_MUTEX RmapListLock;
 static NPAGED_LOOKASIDE_LIST RmapLookasideList;
-FAST_MUTEX RmapListLock;
 
 /* FUNCTIONS ****************************************************************/
 
@@ -68,7 +76,6 @@ MmPageOutPhysicalAddress(PFN_NUMBER Page)
    Process = entry->Process;
 
    Address = entry->Address;
-
    if ((((ULONG_PTR)Address) & 0xFFF) != 0)
    {
       KeBugCheck(MEMORY_MANAGEMENT);
@@ -197,11 +204,8 @@ MmSetCleanAllRmaps(PFN_NUMBER Page)
    }
    while (current_entry != NULL)
    {
-#ifdef NEWCC
-         if (!RMAP_IS_SEGMENT(current_entry->Address))
-#endif
-                 MmSetCleanPage(current_entry->Process, current_entry->Address);
-         current_entry = current_entry->Next;
+      MmSetCleanPage(current_entry->Process, current_entry->Address);
+      current_entry = current_entry->Next;
    }
    ExReleaseFastMutex(&RmapListLock);
 }
@@ -221,10 +225,7 @@ MmSetDirtyAllRmaps(PFN_NUMBER Page)
    }
    while (current_entry != NULL)
    {
-#ifdef NEWCC
-         if (!RMAP_IS_SEGMENT(current_entry->Address))
-#endif
-                 MmSetDirtyPage(current_entry->Process, current_entry->Address);
+      MmSetDirtyPage(current_entry->Process, current_entry->Address);
       current_entry = current_entry->Next;
    }
    ExReleaseFastMutex(&RmapListLock);
@@ -245,11 +246,7 @@ MmIsDirtyPageRmap(PFN_NUMBER Page)
    }
    while (current_entry != NULL)
    {
-         if (
-#ifdef NEWCC
-             !RMAP_IS_SEGMENT(current_entry->Address) && 
-#endif
-                 MmIsDirtyPage(current_entry->Process, current_entry->Address))
+      if (MmIsDirtyPage(current_entry->Process, current_entry->Address))
       {
          ExReleaseFastMutex(&RmapListLock);
          return(TRUE);
@@ -268,10 +265,8 @@ MmInsertRmap(PFN_NUMBER Page, PEPROCESS Process,
    PMM_RMAP_ENTRY current_entry;
    PMM_RMAP_ENTRY new_entry;
    ULONG PrevSize;
-#ifdef NEWCC
-   if (!RMAP_IS_SEGMENT(Address))
-#endif
-          Address = (PVOID)PAGE_ROUND_DOWN(Address);
+
+   Address = (PVOID)PAGE_ROUND_DOWN(Address);
 
    new_entry = ExAllocateFromNPagedLookasideList(&RmapLookasideList);
    if (new_entry == NULL)
@@ -288,11 +283,7 @@ MmInsertRmap(PFN_NUMBER Page, PEPROCESS Process,
 #endif
 #endif
 
-   if (
-#ifdef NEWCC
-       !RMAP_IS_SEGMENT(Address) && 
-#endif
-          MmGetPfnForProcess(Process, Address) != Page)
+   if (MmGetPfnForProcess(Process, Address) != Page)
    {
       DPRINT1("Insert rmap (%d, 0x%.8X) 0x%.8X which doesn't match physical "
               "address 0x%.8X\n", Process->UniqueProcessId, Address,
@@ -322,22 +313,17 @@ MmInsertRmap(PFN_NUMBER Page, PEPROCESS Process,
 #endif
    MmSetRmapListHeadPage(Page, new_entry);
    ExReleaseFastMutex(&RmapListLock);
-#ifdef NEWCC
-   if (!RMAP_IS_SEGMENT(Address)) 
-#endif
+   if (Process == NULL)
+   {
+      Process = PsInitialSystemProcess;
+   }
+   if (Process)
    {
-          if (Process == NULL)
-          {
-                  Process = PsInitialSystemProcess;
-          }
-          if (Process)
-          {
-                  PrevSize = InterlockedExchangeAddUL(&Process->Vm.WorkingSetSize, PAGE_SIZE);
-                  if (PrevSize >= Process->Vm.PeakWorkingSetSize)
-                  {
-                          Process->Vm.PeakWorkingSetSize = PrevSize + PAGE_SIZE;
-                  }
-          }
+      PrevSize = InterlockedExchangeAddUL(&Process->Vm.WorkingSetSize, PAGE_SIZE);
+      if (PrevSize >= Process->Vm.PeakWorkingSetSize)
+      {
+         Process->Vm.PeakWorkingSetSize = PrevSize + PAGE_SIZE;
+      }
    }
 }
 
@@ -364,32 +350,21 @@ MmDeleteAllRmaps(PFN_NUMBER Page, PVOID Context,
    {
       previous_entry = current_entry;
       current_entry = current_entry->Next;
-#ifdef NEWCC
-         if (!RMAP_IS_SEGMENT(current_entry->Address)) 
-#endif
-         {
-                 if (DeleteMapping)
-                 {
-                         DeleteMapping(Context, previous_entry->Process,
-                                                       previous_entry->Address);
-                 }
-                 Process = previous_entry->Process;
-                 ExFreeToNPagedLookasideList(&RmapLookasideList, previous_entry);
-                 if (Process == NULL)
-                 {
-                         Process = PsInitialSystemProcess;
-                 }
-                 if (Process)
-                 {
-                         (void)InterlockedExchangeAddUL(&Process->Vm.WorkingSetSize, -PAGE_SIZE);
-                 }
-         } 
-#ifdef NEWCC
-         else 
-         {
-                 ExFreeToNPagedLookasideList(&RmapLookasideList, previous_entry);
-         }
-#endif
+      if (DeleteMapping)
+      {
+         DeleteMapping(Context, previous_entry->Process,
+                       previous_entry->Address);
+      }
+      Process = previous_entry->Process;
+      ExFreeToNPagedLookasideList(&RmapLookasideList, previous_entry);
+      if (Process == NULL)
+      {
+         Process = PsInitialSystemProcess;
+      }
+      if (Process)
+      {
+         (void)InterlockedExchangeAddUL(&Process->Vm.WorkingSetSize, -PAGE_SIZE);
+      }
    }
 }
 
@@ -419,83 +394,18 @@ MmDeleteRmap(PFN_NUMBER Page, PEPROCESS Process,
          }
          ExReleaseFastMutex(&RmapListLock);
          ExFreeToNPagedLookasideList(&RmapLookasideList, current_entry);
-#ifdef NEWCC
-                if (!RMAP_IS_SEGMENT(Address))
-#endif
-                {
-                        if (Process == NULL)
-                        {
-                                Process = PsInitialSystemProcess;
-                        }
-                        if (Process)
-                        {
-                                (void)InterlockedExchangeAddUL(&Process->Vm.WorkingSetSize, -PAGE_SIZE);
-                        }
-                }
-         return;
-      }
-      previous_entry = current_entry;
-      current_entry = current_entry->Next;
-   }
-   KeBugCheck(MEMORY_MANAGEMENT);
-}
-
-#ifdef NEWCC
-PVOID
-NTAPI
-MmGetSegmentRmap(PFN_NUMBER Page, PULONG RawOffset)
-{
-   PCACHE_SECTION_PAGE_TABLE Result = NULL;
-   PMM_RMAP_ENTRY current_entry, previous_entry;
-
-   ExAcquireFastMutex(&RmapListLock);
-   previous_entry = NULL;
-   current_entry = MmGetRmapListHeadPage(Page);
-   while (current_entry != NULL)
-   {
-         if (RMAP_IS_SEGMENT(current_entry->Address))
-      {
-                Result = (PCACHE_SECTION_PAGE_TABLE)current_entry->Process;
-                *RawOffset = (ULONG_PTR)current_entry->Address & ~RMAP_SEGMENT_MASK;
-                InterlockedIncrementUL(&Result->Segment->ReferenceCount);
-         ExReleaseFastMutex(&RmapListLock);
-                return Result;
-      }
-      previous_entry = current_entry;
-      current_entry = current_entry->Next;
-   }
-   ExReleaseFastMutex(&RmapListLock);
-   return NULL;
-}
-
-VOID
-NTAPI
-MmDeleteSectionAssociation(PFN_NUMBER Page)
-{
-   PMM_RMAP_ENTRY current_entry, previous_entry;
-
-   ExAcquireFastMutex(&RmapListLock);
-   previous_entry = NULL;
-   current_entry = MmGetRmapListHeadPage(Page);
-   while (current_entry != NULL)
-   {
-         if (RMAP_IS_SEGMENT(current_entry->Address))
-      {
-         if (previous_entry == NULL)
+         if (Process == NULL)
          {
-            MmSetRmapListHeadPage(Page, current_entry->Next);
+            Process = PsInitialSystemProcess;
          }
-         else
+         if (Process)
          {
-            previous_entry->Next = current_entry->Next;
+            (void)InterlockedExchangeAddUL(&Process->Vm.WorkingSetSize, -PAGE_SIZE);
          }
-         ExReleaseFastMutex(&RmapListLock);
-         ExFreeToNPagedLookasideList(&RmapLookasideList, current_entry);
          return;
       }
       previous_entry = current_entry;
       current_entry = current_entry->Next;
    }
-   ExReleaseFastMutex(&RmapListLock);
+   KeBugCheck(MEMORY_MANAGEMENT);
 }
-#endif