Merge 36852, 37322, 37333, 37334, 43428, 43451, 44259, 46404 from amd64 branch.
[reactos.git] / reactos / ntoskrnl / mm / section.c
index e741a43..8761620 100644 (file)
@@ -71,6 +71,10 @@ MM_SECTION_PAGEOUT_CONTEXT;
 
 POBJECT_TYPE MmSectionObjectType = NULL;
 
+BOOLEAN MmAllocationFragment;
+
+ULONG_PTR MmSubsectionBase;
+
 static GENERIC_MAPPING MmpSectionMapping = {
          STANDARD_RIGHTS_READ | SECTION_MAP_READ | SECTION_QUERY,
          STANDARD_RIGHTS_WRITE | SECTION_MAP_WRITE,
@@ -461,7 +465,7 @@ MmUnsharePageEntrySectionSegment(PROS_SECTION_OBJECT Section,
       PFILE_OBJECT FileObject;
       PBCB Bcb;
       SWAPENTRY SavedSwapEntry;
-      PFN_TYPE Page;
+      PFN_NUMBER Page;
       BOOLEAN IsImageSection;
       ULONG FileOffset;
 
@@ -576,7 +580,7 @@ BOOLEAN MiIsPageFromCache(PMEMORY_AREA MemoryArea,
 
 NTSTATUS
 NTAPI
-MiCopyFromUserPage(PFN_TYPE DestPage, PVOID SourceAddress)
+MiCopyFromUserPage(PFN_NUMBER DestPage, PVOID SourceAddress)
 {
     PEPROCESS Process;
     KIRQL Irql;
@@ -597,7 +601,7 @@ NTSTATUS
 NTAPI
 MiReadPage(PMEMORY_AREA MemoryArea,
            ULONG SegOffset,
-           PPFN_TYPE Page)
+           PPFN_NUMBER Page)
 /*
  * FUNCTION: Read a page for a section backed memory area.
  * PARAMETERS:
@@ -778,7 +782,7 @@ MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace,
                              BOOLEAN Locked)
 {
    ULONG Offset;
-   PFN_TYPE Page;
+   PFN_NUMBER Page;
    NTSTATUS Status;
    PVOID PAddress;
    PROS_SECTION_OBJECT Section;
@@ -790,7 +794,6 @@ MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace,
    PMM_REGION Region;
    BOOLEAN HasSwapEntry;
    PEPROCESS Process = MmGetAddressSpaceOwner(AddressSpace);
-   KIRQL OldIrql;
     
    /*
     * There is a window between taking the page fault and locking the
@@ -799,12 +802,6 @@ MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace,
     */
    if (MmIsPagePresent(Process, Address))
    {
-      if (Locked)
-      {
-         OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
-         MmLockPage(MmGetPfnForProcess(Process, Address));
-         KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
-      }
       return(STATUS_SUCCESS);
    }
 
@@ -928,12 +925,6 @@ MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace,
          }
          MmInsertRmap(Page, Process, (PVOID)PAddress);
       }
-      if (Locked)
-      {
-         OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
-         MmLockPage(Page);
-         KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
-      }
       MmUnlockSectionSegment(Segment);
       PageOp->Status = STATUS_SUCCESS;
       MmspCompleteAndReleasePageOp(PageOp);
@@ -1000,12 +991,6 @@ MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace,
       /*
        * Finish the operation
        */
-      if (Locked)
-      {
-         OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
-         MmLockPage(Page);
-         KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
-      }
       PageOp->Status = STATUS_SUCCESS;
       MmspCompleteAndReleasePageOp(PageOp);
       DPRINT("Address 0x%.8X\n", Address);
@@ -1033,16 +1018,6 @@ MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace,
           KeBugCheck(MEMORY_MANAGEMENT);
          return(Status);
       }
-      /*
-       * Don't add an rmap entry since the page mapped could be for
-       * anything.
-       */
-      if (Locked)
-      {
-         OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
-         MmLockPage(Page);
-         KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
-      }
 
       /*
        * Cleanup and release locks
@@ -1082,12 +1057,6 @@ MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace,
          return(Status);
       }
       MmInsertRmap(Page, Process, (PVOID)PAddress);
-      if (Locked)
-      {
-         OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
-         MmLockPage(Page);
-         KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
-      }
 
       /*
        * Cleanup and release locks
@@ -1184,12 +1153,6 @@ MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace,
       }
       MmInsertRmap(Page, Process, (PVOID)PAddress);
 
-      if (Locked)
-      {
-         OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
-         MmLockPage(Page);
-         KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
-      }
       PageOp->Status = STATUS_SUCCESS;
       MmspCompleteAndReleasePageOp(PageOp);
       DPRINT("Address 0x%.8X\n", Address);
@@ -1260,12 +1223,6 @@ MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace,
           KeBugCheck(MEMORY_MANAGEMENT);
       }
       MmInsertRmap(Page, Process, (PVOID)PAddress);
-      if (Locked)
-      {
-         OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
-         MmLockPage(Page);
-         KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
-      }
       PageOp->Status = STATUS_SUCCESS;
       MmspCompleteAndReleasePageOp(PageOp);
       DPRINT("Address 0x%.8X\n", Address);
@@ -1294,12 +1251,6 @@ MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace,
           KeBugCheck(MEMORY_MANAGEMENT);
       }
       MmInsertRmap(Page, Process, (PVOID)PAddress);
-      if (Locked)
-      {
-         OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
-         MmLockPage(Page);
-         KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
-      }
       PageOp->Status = STATUS_SUCCESS;
       MmspCompleteAndReleasePageOp(PageOp);
       DPRINT("Address 0x%.8X\n", Address);
@@ -1316,8 +1267,8 @@ MmAccessFaultSectionView(PMMSUPPORT AddressSpace,
 {
    PMM_SECTION_SEGMENT Segment;
    PROS_SECTION_OBJECT Section;
-   PFN_TYPE OldPage;
-   PFN_TYPE NewPage;
+   PFN_NUMBER OldPage;
+   PFN_NUMBER NewPage;
    NTSTATUS Status;
    PVOID PAddress;
    ULONG Offset;
@@ -1325,7 +1276,6 @@ MmAccessFaultSectionView(PMMSUPPORT AddressSpace,
    PMM_REGION Region;
    ULONG Entry;
    PEPROCESS Process = MmGetAddressSpaceOwner(AddressSpace);
-   KIRQL OldIrql;
     
    DPRINT("MmAccessFaultSectionView(%x, %x, %x, %x)\n", AddressSpace, MemoryArea, Address, Locked);
 
@@ -1464,13 +1414,6 @@ MmAccessFaultSectionView(PMMSUPPORT AddressSpace,
       DPRINT1("Unable to create virtual mapping\n");
        KeBugCheck(MEMORY_MANAGEMENT);
    }
-   if (Locked)
-   {
-      OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
-      MmLockPage(NewPage);
-      MmUnlockPage(OldPage);
-      KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
-   }
 
    /*
     * Unshare the old page.
@@ -1492,7 +1435,7 @@ MmPageOutDeleteMapping(PVOID Context, PEPROCESS Process, PVOID Address)
 {
    MM_SECTION_PAGEOUT_CONTEXT* PageOutContext;
    BOOLEAN WasDirty;
-   PFN_TYPE Page;
+   PFN_NUMBER Page;
 
    PageOutContext = (MM_SECTION_PAGEOUT_CONTEXT*)Context;
    if (Process)
@@ -1539,7 +1482,7 @@ MmPageOutSectionView(PMMSUPPORT AddressSpace,
                      PVOID Address,
                      PMM_PAGEOP PageOp)
 {
-   PFN_TYPE Page;
+   PFN_NUMBER Page;
    MM_SECTION_PAGEOUT_CONTEXT Context;
    SWAPENTRY SwapEntry;
    ULONG Entry;
@@ -1899,7 +1842,7 @@ MmWritePageSectionView(PMMSUPPORT AddressSpace,
    ULONG Offset;
    PROS_SECTION_OBJECT Section;
    PMM_SECTION_SEGMENT Segment;
-   PFN_TYPE Page;
+   PFN_NUMBER Page;
    SWAPENTRY SwapEntry;
    ULONG Entry;
    BOOLEAN Private;
@@ -2076,7 +2019,7 @@ MmAlterViewAttributes(PMMSUPPORT AddressSpace,
          {
             ULONG Offset;
             ULONG Entry;
-            PFN_TYPE Page;
+            PFN_NUMBER Page;
 
             Offset = (ULONG_PTR)Address - (ULONG_PTR)MemoryArea->StartingAddress
                      + MemoryArea->Data.SectionData.ViewOffset;
@@ -2185,7 +2128,7 @@ MmpFreePageFileSegment(PMM_SECTION_SEGMENT Segment)
    ULONG Offset;
    ULONG Entry;
    ULONG SavedSwapEntry;
-   PFN_TYPE Page;
+   PFN_NUMBER Page;
 
    Page = 0;
 
@@ -3934,7 +3877,7 @@ NtMapViewOfSection(IN HANDLE SectionHandle,
 
 static VOID
 MmFreeSectionPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
-                  PFN_TYPE Page, SWAPENTRY SwapEntry, BOOLEAN Dirty)
+                  PFN_NUMBER Page, SWAPENTRY SwapEntry, BOOLEAN Dirty)
 {
    ULONG Entry;
    PFILE_OBJECT FileObject;
@@ -4479,63 +4422,6 @@ NtExtendSection(IN HANDLE SectionHandle,
    return STATUS_NOT_IMPLEMENTED;
 }
 
-
-/**********************************************************************
- * NAME       INTERNAL
- *  MmAllocateSection@4
- *
- * DESCRIPTION
- *
- * ARGUMENTS
- *  Length
- *
- * RETURN VALUE
- *
- * NOTE
- *  Code taken from ntoskrnl/mm/special.c.
- *
- * REVISIONS
- */
-PVOID NTAPI
-MmAllocateSection (IN ULONG Length, PVOID BaseAddress)
-{
-   PVOID Result;
-   MEMORY_AREA* marea;
-   NTSTATUS Status;
-   PMMSUPPORT AddressSpace;
-   PHYSICAL_ADDRESS BoundaryAddressMultiple;
-
-   DPRINT("MmAllocateSection(Length %x)\n",Length);
-
-   BoundaryAddressMultiple.QuadPart = 0;
-
-   AddressSpace = MmGetKernelAddressSpace();
-   Result = BaseAddress;
-   MmLockAddressSpace(AddressSpace);
-   Status = MmCreateMemoryArea (AddressSpace,
-                                MEMORY_AREA_SYSTEM,
-                                &Result,
-                                Length,
-                                0,
-                                &marea,
-                                FALSE,
-                                0,
-                                BoundaryAddressMultiple);
-   MmUnlockAddressSpace(AddressSpace);
-
-   if (!NT_SUCCESS(Status))
-   {
-      return (NULL);
-   }
-   DPRINT("Result %p\n",Result);
-
-   /* Create a virtual mapping for this memory area */
-   MmMapMemoryArea(Result, Length, MC_NPPOOL, PAGE_READWRITE);
-
-   return ((PVOID)Result);
-}
-
-
 /**********************************************************************
  * NAME       EXPORTED
  * MmMapViewOfSection