[NTOSKRNL]
[reactos.git] / reactos / ntoskrnl / mm / mmfault.c
index 9a3ecf9..2390854 100644 (file)
@@ -9,9 +9,7 @@
 /* INCLUDES *******************************************************************/
 
 #include <ntoskrnl.h>
-#ifdef NEWCC
 #include "../cache/section/newmm.h"
-#endif
 #define NDEBUG
 #include <debug.h>
 
 NTSTATUS
 NTAPI
 MmpAccessFault(KPROCESSOR_MODE Mode,
-                  ULONG_PTR Address,
-                  BOOLEAN FromMdl)
+               ULONG_PTR Address,
+               BOOLEAN FromMdl)
 {
-   PMMSUPPORT AddressSpace;
-   MEMORY_AREA* MemoryArea;
-   NTSTATUS Status;
-   BOOLEAN Locked = FromMdl;
+    PMMSUPPORT AddressSpace;
+    MEMORY_AREA* MemoryArea;
+    NTSTATUS Status;
 
-   DPRINT("MmAccessFault(Mode %d, Address %x)\n", Mode, Address);
+    DPRINT("MmAccessFault(Mode %d, Address %x)\n", Mode, Address);
 
-   if (KeGetCurrentIrql() >= DISPATCH_LEVEL)
-   {
-      DPRINT1("Page fault at high IRQL was %d\n", KeGetCurrentIrql());
-      return(STATUS_UNSUCCESSFUL);
-   }
+    if (KeGetCurrentIrql() >= DISPATCH_LEVEL)
+    {
+        DPRINT1("Page fault at high IRQL was %u\n", KeGetCurrentIrql());
+        return(STATUS_UNSUCCESSFUL);
+    }
 
-   /*
-    * Find the memory area for the faulting address
-    */
-   if (Address >= (ULONG_PTR)MmSystemRangeStart)
-   {
-      /*
-       * Check permissions
-       */
-      if (Mode != KernelMode)
-      {
-         DPRINT1("MmAccessFault(Mode %d, Address %x)\n", Mode, Address);
-         return(STATUS_ACCESS_VIOLATION);
-      }
-      AddressSpace = MmGetKernelAddressSpace();
-   }
-   else
-   {
-      AddressSpace = &PsGetCurrentProcess()->Vm;
-   }
+    /*
+     * Find the memory area for the faulting address
+     */
+    if (Address >= (ULONG_PTR)MmSystemRangeStart)
+    {
+        /*
+         * Check permissions
+         */
+        if (Mode != KernelMode)
+        {
+            DPRINT1("MmAccessFault(Mode %d, Address %x)\n", Mode, Address);
+            return(STATUS_ACCESS_VIOLATION);
+        }
+        AddressSpace = MmGetKernelAddressSpace();
+    }
+    else
+    {
+        AddressSpace = &PsGetCurrentProcess()->Vm;
+    }
 
-   if (!FromMdl)
-   {
-      MmLockAddressSpace(AddressSpace);
-   }
-   do
-   {
-      MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, (PVOID)Address);
-      if (MemoryArea == NULL || MemoryArea->DeleteInProgress)
-      {
-         if (!FromMdl)
-         {
-            MmUnlockAddressSpace(AddressSpace);
-         }
-         return (STATUS_ACCESS_VIOLATION);
-      }
+    if (!FromMdl)
+    {
+        MmLockAddressSpace(AddressSpace);
+    }
+    do
+    {
+        MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, (PVOID)Address);
+        if (MemoryArea == NULL || MemoryArea->DeleteInProgress)
+        {
+            if (!FromMdl)
+            {
+                MmUnlockAddressSpace(AddressSpace);
+            }
+            return (STATUS_ACCESS_VIOLATION);
+        }
 
-      switch (MemoryArea->Type)
-      {
-         case MEMORY_AREA_SECTION_VIEW:
+        switch (MemoryArea->Type)
+        {
+        case MEMORY_AREA_SECTION_VIEW:
             Status = MmAccessFaultSectionView(AddressSpace,
                                               MemoryArea,
-                                              (PVOID)Address,
-                                              Locked);
+                                              (PVOID)Address);
             break;
 
-         case MEMORY_AREA_VIRTUAL_MEMORY:
-            Status = STATUS_ACCESS_VIOLATION;
+        case MEMORY_AREA_CACHE:
+            // This code locks for itself to keep from having to break a lock
+            // passed in.
+            if (!FromMdl)
+                MmUnlockAddressSpace(AddressSpace);
+            Status = MmAccessFaultCacheSection(Mode, Address, FromMdl);
+            if (!FromMdl)
+                MmLockAddressSpace(AddressSpace);
             break;
 
-#ifdef NEWCC
-            case MEMORY_AREA_CACHE:
-                       // This code locks for itself to keep from having to break a lock
-                       // passed in.
-                       if (!FromMdl)
-                               MmUnlockAddressSpace(AddressSpace);
-                   Status = MmAccessFaultCacheSection(Mode, Address, Locked);
-                       if (!FromMdl)
-                               MmLockAddressSpace(AddressSpace);
-                       break;
-#endif
-
-         default:
+        default:
             Status = STATUS_ACCESS_VIOLATION;
             break;
-      }
-   }
-   while (Status == STATUS_MM_RESTART_OPERATION);
+        }
+    }
+    while (Status == STATUS_MM_RESTART_OPERATION);
 
-   DPRINT("Completed page fault handling\n");
-   if (!FromMdl)
-   {
-      MmUnlockAddressSpace(AddressSpace);
-   }
-   return(Status);
+    DPRINT("Completed page fault handling\n");
+    if (!FromMdl)
+    {
+        MmUnlockAddressSpace(AddressSpace);
+    }
+    return(Status);
 }
 
 NTSTATUS
 NTAPI
 MmNotPresentFault(KPROCESSOR_MODE Mode,
-                           ULONG_PTR Address,
-                           BOOLEAN FromMdl)
+                  ULONG_PTR Address,
+                  BOOLEAN FromMdl)
 {
-   PMMSUPPORT AddressSpace;
-   MEMORY_AREA* MemoryArea;
-   NTSTATUS Status;
-   BOOLEAN Locked = FromMdl;
+    PMMSUPPORT AddressSpace;
+    MEMORY_AREA* MemoryArea;
+    NTSTATUS Status;
 
-   DPRINT("MmNotPresentFault(Mode %d, Address %x)\n", Mode, Address);
+    DPRINT("MmNotPresentFault(Mode %d, Address %x)\n", Mode, Address);
 
-   if (KeGetCurrentIrql() >= DISPATCH_LEVEL)
-   {
-      DPRINT1("Page fault at high IRQL was %d, address %x\n", KeGetCurrentIrql(), Address);
-      return(STATUS_UNSUCCESSFUL);
-   }
+    if (KeGetCurrentIrql() >= DISPATCH_LEVEL)
+    {
+        DPRINT1("Page fault at high IRQL was %u, address %x\n", KeGetCurrentIrql(), Address);
+        return(STATUS_UNSUCCESSFUL);
+    }
 
-   /*
-    * Find the memory area for the faulting address
-    */
-   if (Address >= (ULONG_PTR)MmSystemRangeStart)
-   {
-      /*
-       * Check permissions
-       */
-      if (Mode != KernelMode)
-      {
-        DPRINT1("Address: %x\n", Address);
-         return(STATUS_ACCESS_VIOLATION);
-      }
-      AddressSpace = MmGetKernelAddressSpace();
-   }
-   else
-   {
-      AddressSpace = &PsGetCurrentProcess()->Vm;
-   }
+    /*
+     * Find the memory area for the faulting address
+     */
+    if (Address >= (ULONG_PTR)MmSystemRangeStart)
+    {
+        /*
+         * Check permissions
+         */
+        if (Mode != KernelMode)
+        {
+            DPRINT1("Address: %x\n", Address);
+            return(STATUS_ACCESS_VIOLATION);
+        }
+        AddressSpace = MmGetKernelAddressSpace();
+    }
+    else
+    {
+        AddressSpace = &PsGetCurrentProcess()->Vm;
+    }
 
-   if (!FromMdl)
-   {
-      MmLockAddressSpace(AddressSpace);
-   }
+    if (!FromMdl)
+    {
+        MmLockAddressSpace(AddressSpace);
+    }
 
-   /*
-    * Call the memory area specific fault handler
-    */
-   do
-   {
-      MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, (PVOID)Address);
-      if (MemoryArea == NULL || MemoryArea->DeleteInProgress)
-      {
-         if (!FromMdl)
-         {
-            MmUnlockAddressSpace(AddressSpace);
-         }
-         return (STATUS_ACCESS_VIOLATION);
-      }
+    /*
+     * Call the memory area specific fault handler
+     */
+    do
+    {
+        MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, (PVOID)Address);
+        if (MemoryArea == NULL || MemoryArea->DeleteInProgress)
+        {
+            if (!FromMdl)
+            {
+                MmUnlockAddressSpace(AddressSpace);
+            }
+            return (STATUS_ACCESS_VIOLATION);
+        }
 
-      switch (MemoryArea->Type)
-      {
-         case MEMORY_AREA_SECTION_VIEW:
+        switch (MemoryArea->Type)
+        {
+        case MEMORY_AREA_SECTION_VIEW:
             Status = MmNotPresentFaultSectionView(AddressSpace,
                                                   MemoryArea,
                                                   (PVOID)Address,
-                                                  Locked);
+                                                  FromMdl);
             break;
 
-         case MEMORY_AREA_VIRTUAL_MEMORY:
-            Status = MmNotPresentFaultVirtualMemory(AddressSpace,
-                                                    MemoryArea,
-                                                    (PVOID)Address,
-                                                    Locked);
+        case MEMORY_AREA_CACHE:
+            // This code locks for itself to keep from having to break a lock
+            // passed in.
+            if (!FromMdl)
+                MmUnlockAddressSpace(AddressSpace);
+            Status = MmNotPresentFaultCacheSection(Mode, Address, FromMdl);
+            if (!FromMdl)
+                MmLockAddressSpace(AddressSpace);
             break;
 
-#ifdef  NEWCC
-           case MEMORY_AREA_CACHE:
-                       // This code locks for itself to keep from having to break a lock
-                       // passed in.
-                       if (!FromMdl)
-                               MmUnlockAddressSpace(AddressSpace);
-                   Status = MmNotPresentFaultCacheSection(Mode, Address, Locked);
-                       if (!FromMdl)
-                               MmLockAddressSpace(AddressSpace);
-                       break;
-#endif
-
-         default:
+        default:
             Status = STATUS_ACCESS_VIOLATION;
             break;
-      }
-   }
-   while (Status == STATUS_MM_RESTART_OPERATION);
+        }
+    }
+    while (Status == STATUS_MM_RESTART_OPERATION);
 
-   DPRINT("Completed page fault handling\n");
-   if (!FromMdl)
-   {
-      MmUnlockAddressSpace(AddressSpace);
-   }
-   return(Status);
+    DPRINT("Completed page fault handling\n");
+    if (!FromMdl)
+    {
+        MmUnlockAddressSpace(AddressSpace);
+    }
+    return(Status);
 }
 
 extern BOOLEAN Mmi386MakeKernelPageTableGlobal(PVOID Address);
@@ -240,7 +220,7 @@ MmAccessFault(IN BOOLEAN StoreInstruction,
         }
 #endif
     }
-    
+
     /* Is there a ReactOS address space yet? */
     if (MmGetKernelAddressSpace())
     {
@@ -252,11 +232,11 @@ MmAccessFault(IN BOOLEAN StoreInstruction,
             MemoryArea = MmLocateMemoryAreaByAddress(MmGetCurrentAddressSpace(), Address);
         }
     }
-    
+
     /* Is this an ARM3 memory area, or is there no address space yet? */
     if (((MemoryArea) && (MemoryArea->Type == MEMORY_AREA_OWNED_BY_ARM3)) ||
-        (!(MemoryArea) && ((ULONG_PTR)Address >= (ULONG_PTR)MmPagedPoolStart)) ||
-        (!MmGetKernelAddressSpace()))
+            (!(MemoryArea) && ((ULONG_PTR)Address >= (ULONG_PTR)MmPagedPoolStart)) ||
+            (!MmGetKernelAddressSpace()))
     {
         /* This is an ARM3 fault */
         DPRINT("ARM3 fault %p\n", MemoryArea);