Sync with trunk (48237)
[reactos.git] / ntoskrnl / mm / mmfault.c
index 1549987..308686d 100644 (file)
@@ -105,10 +105,6 @@ MmpAccessFault(KPROCESSOR_MODE Mode,
 
       switch (MemoryArea->Type)
       {
-         case MEMORY_AREA_SYSTEM:
-            Status = STATUS_ACCESS_VIOLATION;
-            break;
-
          case MEMORY_AREA_PAGED_POOL:
             Status = STATUS_SUCCESS;
             break;
@@ -124,10 +120,6 @@ MmpAccessFault(KPROCESSOR_MODE Mode,
             Status = STATUS_ACCESS_VIOLATION;
             break;
 
-         case MEMORY_AREA_SHARED_DATA:
-            Status = STATUS_ACCESS_VIOLATION;
-            break;
-
          default:
             Status = STATUS_ACCESS_VIOLATION;
             break;
@@ -153,7 +145,6 @@ MmNotPresentFault(KPROCESSOR_MODE Mode,
    MEMORY_AREA* MemoryArea;
    NTSTATUS Status;
    BOOLEAN Locked = FromMdl;
-   extern PMMPTE MmSharedUserDataPte;
 
    DPRINT("MmNotPresentFault(Mode %d, Address %x)\n", Mode, Address);
 
@@ -211,10 +202,6 @@ MmNotPresentFault(KPROCESSOR_MODE Mode,
                break;
             }
 
-         case MEMORY_AREA_SYSTEM:
-            Status = STATUS_ACCESS_VIOLATION;
-            break;
-
          case MEMORY_AREA_SECTION_VIEW:
             Status = MmNotPresentFaultSectionView(AddressSpace,
                                                   MemoryArea,
@@ -223,18 +210,12 @@ MmNotPresentFault(KPROCESSOR_MODE Mode,
             break;
 
          case MEMORY_AREA_VIRTUAL_MEMORY:
-         case MEMORY_AREA_PEB_OR_TEB:
             Status = MmNotPresentFaultVirtualMemory(AddressSpace,
                                                     MemoryArea,
                                                     (PVOID)Address,
                                                     Locked);
             break;
 
-         case MEMORY_AREA_SHARED_DATA:
-              *MiAddressToPte(USER_SHARED_DATA) = *MmSharedUserDataPte;
-              Status = STATUS_SUCCESS;
-            break;
-
          default:
             Status = STATUS_ACCESS_VIOLATION;
             break;
@@ -274,17 +255,30 @@ MmAccessFault(IN BOOLEAN StoreInstruction,
 #endif
     }
     
-    //
-    // Check if this is an ARM3 memory area
-    //
+    /* 
+     * Check if this is an ARM3 memory area or if there's no memory area at all.
+     * The latter can happen early in the boot cycle when ARM3 paged pool is in
+     * use before having defined the memory areas proper.
+     * A proper fix would be to define memory areas in the ARM3 code, but we want
+     * to avoid adding this ReactOS-specific construct to ARM3 code.
+     * Either way, in the future, as ReactOS-paged pool is eliminated, this hack
+     * can go away.
+     */
     MemoryArea = MmLocateMemoryAreaByAddress(MmGetKernelAddressSpace(), Address);
-    if ((MemoryArea) && (MemoryArea->Type == MEMORY_AREA_OWNED_BY_ARM3))
+    if (!(MemoryArea) && (Address <= MM_HIGHEST_USER_ADDRESS))
+    {
+        /* Could this be a VAD fault from user-mode? */
+        MemoryArea = MmLocateMemoryAreaByAddress(MmGetCurrentAddressSpace(), Address);
+    }
+    if ((!(MemoryArea) && ((ULONG_PTR)Address >= (ULONG_PTR)MmPagedPoolStart)) ||
+        ((MemoryArea) && (MemoryArea->Type == MEMORY_AREA_OWNED_BY_ARM3)))
     {
         //
         // Hand it off to more competent hands...
         //
+        DPRINT("ARM3 fault %p\n", MemoryArea);
         return MmArmAccessFault(StoreInstruction, Address, Mode, TrapInformation);
-    }   
+    }
 
     /* Keep same old ReactOS Behaviour */
     if (StoreInstruction)
@@ -304,8 +298,7 @@ NTAPI
 MmCommitPagedPoolAddress(PVOID Address, BOOLEAN Locked)
 {
    NTSTATUS Status;
-   PFN_TYPE AllocatedPage;
-   KIRQL OldIrql;
+   PFN_NUMBER AllocatedPage;
 
    Status = MmRequestPageMemoryConsumer(MC_PPOOL, FALSE, &AllocatedPage);
    if (!NT_SUCCESS(Status))
@@ -320,11 +313,5 @@ MmCommitPagedPoolAddress(PVOID Address, BOOLEAN Locked)
                              PAGE_READWRITE,
                              &AllocatedPage,
                              1);
-   if (Locked)
-   {
-      OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
-      MmLockPage(AllocatedPage);
-      KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
-   }
    return(Status);
 }