Sync to trunk head (r42241)
[reactos.git] / reactos / ntoskrnl / mm / section.c
index 5dec48d..3bc81c7 100644 (file)
@@ -152,7 +152,7 @@ MmGetFileNameForAddress(IN PVOID Address,
 {
    PROS_SECTION_OBJECT Section;
    PMEMORY_AREA MemoryArea;
-   PMM_AVL_TABLE AddressSpace;
+   PMMSUPPORT AddressSpace;
    POBJECT_NAME_INFORMATION ModuleNameInformation;
    NTSTATUS Status = STATUS_ADDRESS_NOT_ASSOCIATED;
 
@@ -163,7 +163,7 @@ MmGetFileNameForAddress(IN PVOID Address,
    }
    else
    {
-      AddressSpace = &PsGetCurrentProcess()->VadRoot;
+      AddressSpace = &PsGetCurrentProcess()->Vm;
    }
 
    /* Lock address space */
@@ -657,8 +657,11 @@ MiReadPage(PMEMORY_AREA MemoryArea,
    }
    else
    {
+      PEPROCESS Process;
+      KIRQL Irql;
       PVOID PageAddr;
       ULONG CacheSegOffset;
+
       /*
        * Allocate a page, this is rather complicated by the possibility
        * we might have to move other things out of memory
@@ -691,7 +694,9 @@ MiReadPage(PMEMORY_AREA MemoryArea,
             return Status;
          }
       }
-      PageAddr = MmCreateHyperspaceMapping(*Page);
+
+      Process = PsGetCurrentProcess();
+      PageAddr = MiMapPageInHyperSpace(Process, *Page, &Irql);
       CacheSegOffset = BaseOffset + CacheSeg->Bcb->CacheSegmentSize - FileOffset;
       Length = RawLength - SegOffset;
       if (Length <= CacheSegOffset && Length <= PAGE_SIZE)
@@ -705,6 +710,7 @@ MiReadPage(PMEMORY_AREA MemoryArea,
       else
       {
          memcpy(PageAddr, (char*)BaseAddress + FileOffset - BaseOffset, CacheSegOffset);
+         MiUnmapPageInHyperSpace(Process, PageAddr, Irql);
          CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE, FALSE, FALSE);
          Status = CcRosGetCacheSegment(Bcb,
                                        FileOffset + CacheSegOffset,
@@ -714,7 +720,6 @@ MiReadPage(PMEMORY_AREA MemoryArea,
                                        &CacheSeg);
          if (!NT_SUCCESS(Status))
          {
-            MmDeleteHyperspaceMapping(PageAddr);
             return(Status);
          }
          if (!UptoDate)
@@ -727,10 +732,10 @@ MiReadPage(PMEMORY_AREA MemoryArea,
             if (!NT_SUCCESS(Status))
             {
                CcRosReleaseCacheSegment(Bcb, CacheSeg, FALSE, FALSE, FALSE);
-               MmDeleteHyperspaceMapping(PageAddr);
                return Status;
             }
          }
+         PageAddr = MiMapPageInHyperSpace(Process, *Page, &Irql);
          if (Length < PAGE_SIZE)
          {
             memcpy((char*)PageAddr + CacheSegOffset, BaseAddress, Length - CacheSegOffset);
@@ -740,15 +745,15 @@ MiReadPage(PMEMORY_AREA MemoryArea,
             memcpy((char*)PageAddr + CacheSegOffset, BaseAddress, PAGE_SIZE - CacheSegOffset);
          }
       }
+      MiUnmapPageInHyperSpace(Process, PageAddr, Irql);
       CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE, FALSE, FALSE);
-      MmDeleteHyperspaceMapping(PageAddr);
    }
    return(STATUS_SUCCESS);
 }
 
 NTSTATUS
 NTAPI
-MmNotPresentFaultSectionView(PMM_AVL_TABLE AddressSpace,
+MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace,
                              MEMORY_AREA* MemoryArea,
                              PVOID Address,
                              BOOLEAN Locked)
@@ -1268,7 +1273,7 @@ MmNotPresentFaultSectionView(PMM_AVL_TABLE AddressSpace,
 
 NTSTATUS
 NTAPI
-MmAccessFaultSectionView(PMM_AVL_TABLE AddressSpace,
+MmAccessFaultSectionView(PMMSUPPORT AddressSpace,
                          MEMORY_AREA* MemoryArea,
                          PVOID Address,
                          BOOLEAN Locked)
@@ -1453,7 +1458,7 @@ MmPageOutDeleteMapping(PVOID Context, PEPROCESS Process, PVOID Address)
    PageOutContext = (MM_SECTION_PAGEOUT_CONTEXT*)Context;
    if (Process)
    {
-      MmLockAddressSpace(&Process->VadRoot);
+      MmLockAddressSpace(&Process->Vm);
    }
 
    MmDeleteVirtualMapping(Process,
@@ -1477,7 +1482,7 @@ MmPageOutDeleteMapping(PVOID Context, PEPROCESS Process, PVOID Address)
    }
    if (Process)
    {
-      MmUnlockAddressSpace(&Process->VadRoot);
+      MmUnlockAddressSpace(&Process->Vm);
    }
 
    if (PageOutContext->Private)
@@ -1490,7 +1495,7 @@ MmPageOutDeleteMapping(PVOID Context, PEPROCESS Process, PVOID Address)
 
 NTSTATUS
 NTAPI
-MmPageOutSectionView(PMM_AVL_TABLE AddressSpace,
+MmPageOutSectionView(PMMSUPPORT AddressSpace,
                      MEMORY_AREA* MemoryArea,
                      PVOID Address,
                      PMM_PAGEOP PageOp)
@@ -1844,7 +1849,7 @@ MmPageOutSectionView(PMM_AVL_TABLE AddressSpace,
 
 NTSTATUS
 NTAPI
-MmWritePageSectionView(PMM_AVL_TABLE AddressSpace,
+MmWritePageSectionView(PMMSUPPORT AddressSpace,
                        PMEMORY_AREA MemoryArea,
                        PVOID Address,
                        PMM_PAGEOP PageOp)
@@ -1990,8 +1995,8 @@ MmWritePageSectionView(PMM_AVL_TABLE AddressSpace,
    return(STATUS_SUCCESS);
 }
 
-VOID static
-MmAlterViewAttributes(PMM_AVL_TABLE AddressSpace,
+static VOID
+MmAlterViewAttributes(PMMSUPPORT AddressSpace,
                       PVOID BaseAddress,
                       ULONG RegionSize,
                       ULONG OldType,
@@ -2056,7 +2061,7 @@ MmAlterViewAttributes(PMM_AVL_TABLE AddressSpace,
 
 NTSTATUS
 NTAPI
-MmProtectSectionView(PMM_AVL_TABLE AddressSpace,
+MmProtectSectionView(PMMSUPPORT AddressSpace,
                      PMEMORY_AREA MemoryArea,
                      PVOID BaseAddress,
                      ULONG Length,
@@ -2089,11 +2094,11 @@ MmProtectSectionView(PMM_AVL_TABLE AddressSpace,
    return(Status);
 }
 
-NTSTATUS STDCALL
+NTSTATUS NTAPI
 MmQuerySectionView(PMEMORY_AREA MemoryArea,
                    PVOID Address,
                    PMEMORY_BASIC_INFORMATION Info,
-                   PULONG ResultLength)
+                   PSIZE_T ResultLength)
 {
    PMM_REGION Region;
    PVOID RegionBaseAddress;
@@ -2168,7 +2173,7 @@ MmpFreePageFileSegment(PMM_SECTION_SEGMENT Segment)
    }
 }
 
-VOID STDCALL
+VOID NTAPI
 MmpDeleteSection(PVOID ObjectBody)
 {
    PROS_SECTION_OBJECT Section = (PROS_SECTION_OBJECT)ObjectBody;
@@ -2239,7 +2244,7 @@ MmpDeleteSection(PVOID ObjectBody)
    }
 }
 
-VOID STDCALL
+VOID NTAPI
 MmpCloseSection(IN PEPROCESS Process OPTIONAL,
                 IN PVOID Object,
                 IN ACCESS_MASK GrantedAccess,
@@ -2370,10 +2375,9 @@ MmCreatePageFileSection(PROS_SECTION_OBJECT *SectionObject,
    /*
     * Initialize it
     */
+   RtlZeroMemory(Section, sizeof(ROS_SECTION_OBJECT));
    Section->SectionPageProtection = SectionPageProtection;
    Section->AllocationAttributes = AllocationAttributes;
-   Section->Segment = NULL;
-   Section->FileObject = NULL;
    Section->MaximumSize = MaximumSize;
    Segment = ExAllocatePoolWithTag(NonPagedPool, sizeof(MM_SECTION_SEGMENT),
                                    TAG_MM_SECTION_SEGMENT);
@@ -2422,6 +2426,7 @@ MmCreateDataFileSection(PROS_SECTION_OBJECT *SectionObject,
    LARGE_INTEGER Offset;
    CHAR Buffer;
    FILE_STANDARD_INFORMATION FileInfo;
+   ULONG Length;
 
    /*
     * Create the section
@@ -2442,9 +2447,9 @@ MmCreateDataFileSection(PROS_SECTION_OBJECT *SectionObject,
    /*
     * Initialize it
     */
+   RtlZeroMemory(Section, sizeof(ROS_SECTION_OBJECT));
    Section->SectionPageProtection = SectionPageProtection;
    Section->AllocationAttributes = AllocationAttributes;
-   Section->Segment = NULL;
 
    /*
     * Check file access required
@@ -2484,7 +2489,8 @@ MmCreateDataFileSection(PROS_SECTION_OBJECT *SectionObject,
                                    FileStandardInformation,
                                    sizeof(FILE_STANDARD_INFORMATION),
                                    &FileInfo,
-                                   &Iosb.Information);
+                                   &Length);
+   Iosb.Information = Length;
    if (!NT_SUCCESS(Status))
    {
       ObDereferenceObject(Section);
@@ -3368,6 +3374,7 @@ MmCreateImageSection(PROS_SECTION_OBJECT *SectionObject,
    /*
     * Initialize it
     */
+   RtlZeroMemory(Section, sizeof(ROS_SECTION_OBJECT));
    Section->SectionPageProtection = SectionPageProtection;
    Section->AllocationAttributes = AllocationAttributes;
 
@@ -3477,7 +3484,7 @@ MmCreateImageSection(PROS_SECTION_OBJECT *SectionObject,
 /*
  * @implemented
  */
-NTSTATUS STDCALL
+NTSTATUS NTAPI
 NtCreateSection (OUT PHANDLE SectionHandle,
                  IN ACCESS_MASK DesiredAccess,
                  IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
@@ -3493,13 +3500,17 @@ NtCreateSection (OUT PHANDLE SectionHandle,
 
    PreviousMode = ExGetPreviousMode();
 
-   if(MaximumSize != NULL && PreviousMode != KernelMode)
+   if(PreviousMode != KernelMode)
    {
      _SEH2_TRY
      {
-       /* make a copy on the stack */
-       SafeMaximumSize = ProbeForReadLargeInteger(MaximumSize);
-       MaximumSize = &SafeMaximumSize;
+       if (MaximumSize != NULL)
+       {
+          /* make a copy on the stack */
+          SafeMaximumSize = ProbeForReadLargeInteger(MaximumSize);
+          MaximumSize = &SafeMaximumSize;
+       }
+       ProbeForWriteHandle(SectionHandle);
      }
      _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
      {
@@ -3552,7 +3563,7 @@ NtCreateSection (OUT PHANDLE SectionHandle,
  *
  * REVISIONS
  */
-NTSTATUS STDCALL
+NTSTATUS NTAPI
 NtOpenSection(PHANDLE   SectionHandle,
               ACCESS_MASK  DesiredAccess,
               POBJECT_ATTRIBUTES ObjectAttributes)
@@ -3605,8 +3616,8 @@ NtOpenSection(PHANDLE   SectionHandle,
    return(Status);
 }
 
-NTSTATUS static
-MmMapViewOfSegment(PMM_AVL_TABLE AddressSpace,
+static NTSTATUS
+MmMapViewOfSegment(PMMSUPPORT AddressSpace,
                    PROS_SECTION_OBJECT Section,
                    PMM_SECTION_SEGMENT Segment,
                    PVOID* BaseAddress,
@@ -3699,7 +3710,7 @@ MmMapViewOfSegment(PMM_AVL_TABLE AddressSpace,
  *
  * @implemented
  */
-NTSTATUS STDCALL
+NTSTATUS NTAPI
 NtMapViewOfSection(IN HANDLE SectionHandle,
                    IN HANDLE ProcessHandle,
                    IN OUT PVOID* BaseAddress  OPTIONAL,
@@ -3717,9 +3728,10 @@ NtMapViewOfSection(IN HANDLE SectionHandle,
    PROS_SECTION_OBJECT Section;
    PEPROCESS Process;
    KPROCESSOR_MODE PreviousMode;
-   PMM_AVL_TABLE AddressSpace;
+   PMMSUPPORT AddressSpace;
    NTSTATUS Status = STATUS_SUCCESS;
    ULONG tmpProtect;
+   ACCESS_MASK DesiredAccess;
 
    /*
     * Check the protection
@@ -3796,10 +3808,29 @@ NtMapViewOfSection(IN HANDLE SectionHandle,
       return(Status);
    }
 
-   AddressSpace = &Process->VadRoot;
+   AddressSpace = &Process->Vm;
+
+   /* Convert NT Protection Attr to Access Mask */
+   if (Protect == PAGE_READONLY)
+   {
+      DesiredAccess = SECTION_MAP_READ;
+   }
+   else if (Protect == PAGE_READWRITE)
+   {
+      DesiredAccess = SECTION_MAP_WRITE;
+   }
+   else if (Protect == PAGE_WRITECOPY)
+   {
+      DesiredAccess = SECTION_QUERY;
+   }
+   /* FIXME: Handle other Protection Attributes. For now keep previous behavior */
+   else
+   {
+      DesiredAccess = SECTION_MAP_READ;
+   }
 
    Status = ObReferenceObjectByHandle(SectionHandle,
-                                      SECTION_MAP_READ,
+                                      DesiredAccess,
                                       MmSectionObjectType,
                                       PreviousMode,
                                       (PVOID*)(PVOID)&Section,
@@ -3865,7 +3896,7 @@ NtMapViewOfSection(IN HANDLE SectionHandle,
    return(Status);
 }
 
-VOID static
+static VOID
 MmFreeSectionPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
                   PFN_TYPE Page, SWAPENTRY SwapEntry, BOOLEAN Dirty)
 {
@@ -3878,10 +3909,10 @@ MmFreeSectionPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
    NTSTATUS Status;
    PROS_SECTION_OBJECT Section;
    PMM_SECTION_SEGMENT Segment;
-   PMM_AVL_TABLE AddressSpace;
+   PMMSUPPORT AddressSpace;
    PEPROCESS Process;
 
-   AddressSpace = (PMM_AVL_TABLE)Context;
+   AddressSpace = (PMMSUPPORT)Context;
    Process = MmGetAddressSpaceOwner(AddressSpace);
 
    Address = (PVOID)PAGE_ROUND_DOWN(Address);
@@ -3975,7 +4006,7 @@ MmFreeSectionPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
 }
 
 static NTSTATUS
-MmUnmapViewOfSegment(PMM_AVL_TABLE AddressSpace,
+MmUnmapViewOfSegment(PMMSUPPORT AddressSpace,
                      PVOID BaseAddress)
 {
    NTSTATUS Status;
@@ -4029,13 +4060,13 @@ MmUnmapViewOfSegment(PMM_AVL_TABLE AddressSpace,
 /*
  * @implemented
  */
-NTSTATUS STDCALL
+NTSTATUS NTAPI
 MmUnmapViewOfSection(PEPROCESS Process,
                      PVOID BaseAddress)
 {
    NTSTATUS Status;
    PMEMORY_AREA MemoryArea;
-   PMM_AVL_TABLE AddressSpace;
+   PMMSUPPORT AddressSpace;
    PROS_SECTION_OBJECT Section;
    PMM_PAGEOP PageOp;
    ULONG_PTR Offset;
@@ -4046,7 +4077,7 @@ MmUnmapViewOfSection(PEPROCESS Process,
 
    ASSERT(Process);
 
-   AddressSpace = &Process->VadRoot;
+   AddressSpace = &Process->Vm;
 
    MmLockAddressSpace(AddressSpace);
    MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace,
@@ -4143,10 +4174,11 @@ MmUnmapViewOfSection(PEPROCESS Process,
       Status = MmUnmapViewOfSegment(AddressSpace, BaseAddress);
    }
 
+   MmUnlockAddressSpace(AddressSpace);
+
    /* Notify debugger */
    if (ImageBaseAddress) DbgkUnMapViewOfSection(ImageBaseAddress);
 
-   MmUnlockAddressSpace(AddressSpace);
    return(STATUS_SUCCESS);
 }
 
@@ -4166,7 +4198,7 @@ MmUnmapViewOfSection(PEPROCESS Process,
  *
  * REVISIONS
  */
-NTSTATUS STDCALL
+NTSTATUS NTAPI
 NtUnmapViewOfSection (HANDLE ProcessHandle,
                       PVOID BaseAddress)
 {
@@ -4222,16 +4254,17 @@ NtUnmapViewOfSection (HANDLE ProcessHandle,
  *
  * @implemented
  */
-NTSTATUS STDCALL
+NTSTATUS NTAPI
 NtQuerySection(IN HANDLE SectionHandle,
                IN SECTION_INFORMATION_CLASS SectionInformationClass,
                OUT PVOID SectionInformation,
-               IN ULONG SectionInformationLength,
-               OUT PULONG ResultLength  OPTIONAL)
+               IN SIZE_T SectionInformationLength,
+               OUT PSIZE_T ResultLength  OPTIONAL)
 {
    PROS_SECTION_OBJECT Section;
    KPROCESSOR_MODE PreviousMode;
    NTSTATUS Status = STATUS_SUCCESS;
+   PAGED_CODE();
 
    PreviousMode = ExGetPreviousMode();
 
@@ -4240,6 +4273,7 @@ NtQuerySection(IN HANDLE SectionHandle,
                                         sizeof(ExSectionInfoClass) / sizeof(ExSectionInfoClass[0]),
                                         SectionInformation,
                                         SectionInformationLength,
+                                        NULL,
                                         ResultLength,
                                         PreviousMode);
 
@@ -4352,7 +4386,7 @@ NtQuerySection(IN HANDLE SectionHandle,
  * @todo Move the actual code to internal function MmExtendSection.
  * @unimplemented
  */
-NTSTATUS STDCALL
+NTSTATUS NTAPI
 NtExtendSection(IN HANDLE SectionHandle,
                 IN PLARGE_INTEGER NewMaximumSize)
 {
@@ -4396,7 +4430,7 @@ NtExtendSection(IN HANDLE SectionHandle,
 
    if (!(Section->AllocationAttributes & SEC_FILE))
    {
-      ObfDereferenceObject(Section);
+      ObDereferenceObject(Section);
       return STATUS_INVALID_PARAMETER;
    }
 
@@ -4430,13 +4464,13 @@ NtExtendSection(IN HANDLE SectionHandle,
  *
  * REVISIONS
  */
-PVOID STDCALL
+PVOID NTAPI
 MmAllocateSection (IN ULONG Length, PVOID BaseAddress)
 {
    PVOID Result;
    MEMORY_AREA* marea;
    NTSTATUS Status;
-   PMM_AVL_TABLE AddressSpace;
+   PMMSUPPORT AddressSpace;
    PHYSICAL_ADDRESS BoundaryAddressMultiple;
 
    DPRINT("MmAllocateSection(Length %x)\n",Length);
@@ -4519,7 +4553,7 @@ MmAllocateSection (IN ULONG Length, PVOID BaseAddress)
  *
  * @implemented
  */
-NTSTATUS STDCALL
+NTSTATUS NTAPI
 MmMapViewOfSection(IN PVOID SectionObject,
                    IN PEPROCESS Process,
                    IN OUT PVOID *BaseAddress,
@@ -4532,26 +4566,20 @@ MmMapViewOfSection(IN PVOID SectionObject,
                    IN ULONG Protect)
 {
    PROS_SECTION_OBJECT Section;
-   PMM_AVL_TABLE AddressSpace;
+   PMMSUPPORT AddressSpace;
    ULONG ViewOffset;
    NTSTATUS Status = STATUS_SUCCESS;
 
    ASSERT(Process);
 
-   if (Protect != PAGE_READONLY &&
-       Protect != PAGE_READWRITE &&
-       Protect != PAGE_WRITECOPY &&
-       Protect != PAGE_EXECUTE &&
-       Protect != PAGE_EXECUTE_READ &&
-       Protect != PAGE_EXECUTE_READWRITE &&
-       Protect != PAGE_EXECUTE_WRITECOPY)
+   if (!Protect || Protect & ~PAGE_FLAGS_VALID_FOR_SECTION)
    {
       return STATUS_INVALID_PAGE_PROTECTION;
    }
 
 
    Section = (PROS_SECTION_OBJECT)SectionObject;
-   AddressSpace = &Process->VadRoot;
+   AddressSpace = &Process->Vm;
 
    AllocationType |= (Section->AllocationAttributes & SEC_NO_CHANGE);
 
@@ -4691,6 +4719,8 @@ MmMapViewOfSection(IN PVOID SectionObject,
          (*ViewSize) = Section->MaximumSize.u.LowPart - ViewOffset;
       }
 
+      *ViewSize = PAGE_ROUND_UP(*ViewSize);
+
       MmLockSectionSegment(Section->Segment);
       Status = MmMapViewOfSegment(AddressSpace,
                                   Section,
@@ -4716,19 +4746,55 @@ MmMapViewOfSection(IN PVOID SectionObject,
 /*
  * @unimplemented
  */
-BOOLEAN STDCALL
+BOOLEAN NTAPI
 MmCanFileBeTruncated (IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
                       IN PLARGE_INTEGER   NewFileSize)
 {
-   UNIMPLEMENTED;
-   return (FALSE);
+   /* Check whether an ImageSectionObject exists */
+   if (SectionObjectPointer->ImageSectionObject != NULL)
+   {
+      DPRINT1("ERROR: File can't be truncated because it has an image section\n");
+      return FALSE;
+   }
+
+   if (SectionObjectPointer->DataSectionObject != NULL)
+   {
+      PMM_SECTION_SEGMENT Segment;
+
+      Segment = (PMM_SECTION_SEGMENT)SectionObjectPointer->
+                DataSectionObject;
+
+      if (Segment->ReferenceCount != 0)
+      {
+          /* Check size of file */
+          if (SectionObjectPointer->SharedCacheMap)
+          {
+             PBCB Bcb = SectionObjectPointer->SharedCacheMap;
+             if (NewFileSize->QuadPart <= Bcb->FileSize.QuadPart)
+             {
+                return FALSE;
+             }
+          }
+      }
+      else
+      {
+         /* Something must gone wrong
+          * how can we have a Section but no 
+          * reference? */
+         DPRINT1("ERROR: DataSectionObject without reference!\n");
+      }
+   }
+
+   DPRINT("FIXME: didn't check for outstanding write probes\n");
+
+   return TRUE;
 }
 
 
 /*
  * @unimplemented
  */
-BOOLEAN STDCALL
+BOOLEAN NTAPI
 MmDisableModifiedWriteOfSection (ULONG Unknown0)
 {
    UNIMPLEMENTED;
@@ -4738,7 +4804,7 @@ MmDisableModifiedWriteOfSection (ULONG Unknown0)
 /*
  * @implemented
  */
-BOOLEAN STDCALL
+BOOLEAN NTAPI
 MmFlushImageSection (IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
                      IN MMFLUSH_TYPE   FlushType)
 {
@@ -4761,7 +4827,7 @@ MmFlushImageSection (IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
 /*
  * @unimplemented
  */
-BOOLEAN STDCALL
+BOOLEAN NTAPI
 MmForceSectionClosed (
     IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
     IN BOOLEAN                  DelayClose)
@@ -4774,13 +4840,13 @@ MmForceSectionClosed (
 /*
  * @implemented
  */
-NTSTATUS STDCALL
+NTSTATUS NTAPI
 MmMapViewInSystemSpace (IN PVOID SectionObject,
                         OUT PVOID * MappedBase,
-                        IN OUT PULONG ViewSize)
+                        IN OUT PSIZE_T ViewSize)
 {
    PROS_SECTION_OBJECT Section;
-   PMM_AVL_TABLE AddressSpace;
+   PMMSUPPORT AddressSpace;
    NTSTATUS Status;
 
    DPRINT("MmMapViewInSystemSpace() called\n");
@@ -4822,7 +4888,7 @@ MmMapViewInSystemSpace (IN PVOID SectionObject,
  * @unimplemented
  */
 NTSTATUS
-STDCALL
+NTAPI
 MmMapViewInSessionSpace (
     IN PVOID Section,
     OUT PVOID *MappedBase,
@@ -4837,10 +4903,10 @@ MmMapViewInSessionSpace (
 /*
  * @implemented
  */
-NTSTATUS STDCALL
+NTSTATUS NTAPI
 MmUnmapViewInSystemSpace (IN PVOID MappedBase)
 {
-   PMM_AVL_TABLE AddressSpace;
+   PMMSUPPORT AddressSpace;
    NTSTATUS Status;
 
    DPRINT("MmUnmapViewInSystemSpace() called\n");
@@ -4856,7 +4922,7 @@ MmUnmapViewInSystemSpace (IN PVOID MappedBase)
  * @unimplemented
  */
 NTSTATUS
-STDCALL
+NTAPI
 MmUnmapViewInSessionSpace (
     IN PVOID MappedBase
     )
@@ -4868,7 +4934,7 @@ MmUnmapViewInSessionSpace (
 /*
  * @unimplemented
  */
-NTSTATUS STDCALL
+NTSTATUS NTAPI
 MmSetBankedSection (ULONG Unknown0,
                     ULONG Unknown1,
                     ULONG Unknown2,
@@ -4936,7 +5002,7 @@ MmSetBankedSection (ULONG Unknown0,
  *
  * @implemented
  */
-NTSTATUS STDCALL
+NTSTATUS NTAPI
 MmCreateSection (OUT PVOID  * Section,
                  IN ACCESS_MASK  DesiredAccess,
                  IN POBJECT_ATTRIBUTES ObjectAttributes     OPTIONAL,
@@ -4953,8 +5019,7 @@ MmCreateSection (OUT PVOID  * Section,
     * Check the protection
     */
    Protection = SectionPageProtection & ~(PAGE_GUARD|PAGE_NOCACHE);
-   if (Protection != PAGE_NOACCESS &&
-       Protection != PAGE_READONLY &&
+   if (Protection != PAGE_READONLY &&
        Protection != PAGE_READWRITE &&
        Protection != PAGE_WRITECOPY &&
        Protection != PAGE_EXECUTE &&