On FAT16 partitions smaller than 128MB, the cluster size is 2048, which is
[reactos.git] / reactos / ntoskrnl / mm / pagefile.c
index acdc923..91d8beb 100644 (file)
 #define NDEBUG
 #include <internal/debug.h>
 
+#if defined (ALLOC_PRAGMA)
+#pragma alloc_text(INIT, MmInitPagingFile)
+#endif
+
+
 /* TYPES *********************************************************************/
 
 typedef struct _PAGINGFILE
@@ -45,14 +50,14 @@ typedef struct _PAGINGFILE
    PULONG AllocMap;
    KSPIN_LOCK AllocMapLock;
    ULONG AllocMapSize;
-   PGET_RETRIEVAL_DESCRIPTOR RetrievalPointers;
+   PRETRIEVAL_POINTERS_BUFFER RetrievalPointers;
 }
 PAGINGFILE, *PPAGINGFILE;
 
 typedef struct _RETRIEVEL_DESCRIPTOR_LIST
 {
    struct _RETRIEVEL_DESCRIPTOR_LIST* Next;
-   GET_RETRIEVAL_DESCRIPTOR RetrievalPointers;
+   RETRIEVAL_POINTERS_BUFFER RetrievalPointers;
 }
 RETRIEVEL_DESCRIPTOR_LIST, *PRETRIEVEL_DESCRIPTOR_LIST;
 
@@ -78,7 +83,7 @@ ULONG MiFreeSwapPages;
 ULONG MiUsedSwapPages;
 
 /*
- * Number of pages that have been reserved for swapping but not yet allocated 
+ * Number of pages that have been reserved for swapping but not yet allocated
  */
 static ULONG MiReservedSwapPages;
 
@@ -117,7 +122,25 @@ static BOOLEAN MmSwapSpaceMessage = FALSE;
 
 /* FUNCTIONS *****************************************************************/
 
+BOOLEAN
+STDCALL
+MmIsFileAPagingFile(PFILE_OBJECT FileObject)
+{
+    ULONG i;
+
+    /* Loop through all the paging files */
+    for (i = 0; i < MiPagingFileCount; i++)
+    {
+        /* Check if this is one of them */
+        if (PagingFileList[i]->FileObject == FileObject) return TRUE;
+    }
+
+    /* Nothing found */
+    return FALSE;
+}
+
 VOID
+NTAPI
 MmShowOutOfSpaceMessagePagingFile(VOID)
 {
    if (!MmSwapSpaceMessage)
@@ -128,27 +151,27 @@ MmShowOutOfSpaceMessagePagingFile(VOID)
 }
 
 LARGE_INTEGER STATIC
-MmGetOffsetPageFile(PGET_RETRIEVAL_DESCRIPTOR RetrievalPointers, LARGE_INTEGER Offset)
+MmGetOffsetPageFile(PRETRIEVAL_POINTERS_BUFFER RetrievalPointers, LARGE_INTEGER Offset)
 {
    /* Simple binary search */
    ULONG first, last, mid;
    first = 0;
-   last = RetrievalPointers->NumberOfPairs - 1;
+   last = RetrievalPointers->ExtentCount - 1;
    while (first <= last)
    {
       mid = (last - first) / 2 + first;
-      if ((ULONGLONG) Offset.QuadPart < RetrievalPointers->Pair[mid].Vcn)
+      if (Offset.QuadPart < RetrievalPointers->Extents[mid].NextVcn.QuadPart)
       {
          if (mid == 0)
          {
-            Offset.QuadPart += RetrievalPointers->Pair[0].Lcn - RetrievalPointers->StartVcn;
+            Offset.QuadPart += RetrievalPointers->Extents[0].Lcn.QuadPart - RetrievalPointers->StartingVcn.QuadPart;
             return Offset;
          }
          else
          {
-            if ((ULONGLONG) Offset.QuadPart >= RetrievalPointers->Pair[mid-1].Vcn)
+            if (Offset.QuadPart >= RetrievalPointers->Extents[mid-1].NextVcn.QuadPart)
             {
-               Offset.QuadPart += RetrievalPointers->Pair[mid].Lcn  - RetrievalPointers->Pair[mid-1].Vcn;
+               Offset.QuadPart += RetrievalPointers->Extents[mid].Lcn.QuadPart - RetrievalPointers->Extents[mid-1].NextVcn.QuadPart;
                return Offset;
             }
             last = mid - 1;
@@ -156,13 +179,13 @@ MmGetOffsetPageFile(PGET_RETRIEVAL_DESCRIPTOR RetrievalPointers, LARGE_INTEGER O
       }
       else
       {
-         if (mid == RetrievalPointers->NumberOfPairs - 1)
+         if (mid == RetrievalPointers->ExtentCount - 1)
          {
             break;
          }
-         if ((ULONGLONG) Offset.QuadPart < RetrievalPointers->Pair[mid+1].Vcn)
+         if (Offset.QuadPart < RetrievalPointers->Extents[mid+1].NextVcn.QuadPart)
          {
-            Offset.QuadPart += RetrievalPointers->Pair[mid+1].Lcn  - RetrievalPointers->Pair[mid].Vcn;
+            Offset.QuadPart += RetrievalPointers->Extents[mid+1].Lcn.QuadPart  - RetrievalPointers->Extents[mid].NextVcn.QuadPart;
             return Offset;
          }
          first = mid + 1;
@@ -184,7 +207,9 @@ MmGetOffsetPageFile(PGET_RETRIEVAL_DESCRIPTOR RetrievalPointers, LARGE_INTEGER O
 #endif
 }
 
-NTSTATUS MmWriteToSwapPage(SWAPENTRY SwapEntry, PFN_TYPE Page)
+NTSTATUS
+NTAPI
+MmWriteToSwapPage(SWAPENTRY SwapEntry, PFN_TYPE Page)
 {
    ULONG i, offset;
    LARGE_INTEGER file_offset;
@@ -224,21 +249,23 @@ NTSTATUS MmWriteToSwapPage(SWAPENTRY SwapEntry, PFN_TYPE Page)
    file_offset = MmGetOffsetPageFile(PagingFileList[i]->RetrievalPointers, file_offset);
 
    KeInitializeEvent(&Event, NotificationEvent, FALSE);
-   Status = IoPageWrite(PagingFileList[i]->FileObject,
-                        Mdl,
-                        &file_offset,
-                        &Event,
-                        &Iosb);
+   Status = IoSynchronousPageWrite(PagingFileList[i]->FileObject,
+                                   Mdl,
+                                   &file_offset,
+                                   &Event,
+                                   &Iosb);
    if (Status == STATUS_PENDING)
    {
       KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
       Status = Iosb.Status;
    }
-   MmUnmapLockedPages(Mdl->MappedSystemVa, Mdl);            
+   MmUnmapLockedPages(Mdl->MappedSystemVa, Mdl);
    return(Status);
 }
 
-NTSTATUS MmReadFromSwapPage(SWAPENTRY SwapEntry, PFN_TYPE Page)
+NTSTATUS
+NTAPI
+MmReadFromSwapPage(SWAPENTRY SwapEntry, PFN_TYPE Page)
 {
    ULONG i, offset;
    LARGE_INTEGER file_offset;
@@ -288,11 +315,13 @@ NTSTATUS MmReadFromSwapPage(SWAPENTRY SwapEntry, PFN_TYPE Page)
       KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
       Status = Iosb.Status;
    }
-   MmUnmapLockedPages(Mdl->MappedSystemVa, Mdl);            
+   MmUnmapLockedPages(Mdl->MappedSystemVa, Mdl);
    return(Status);
 }
 
-VOID INIT_FUNCTION
+VOID
+INIT_FUNCTION
+NTAPI
 MmInitPagingFile(VOID)
 {
    ULONG i;
@@ -327,6 +356,7 @@ MmInitPagingFile(VOID)
 }
 
 BOOLEAN
+NTAPI
 MmReserveSwapPages(ULONG Nr)
 {
    KIRQL oldIrql;
@@ -346,6 +376,7 @@ MmReserveSwapPages(ULONG Nr)
 }
 
 VOID
+NTAPI
 MmDereserveSwapPages(ULONG Nr)
 {
    KIRQL oldIrql;
@@ -383,6 +414,7 @@ MiAllocPageFromPagingFile(PPAGINGFILE PagingFile)
 }
 
 VOID
+NTAPI
 MmFreeSwapPage(SWAPENTRY Entry)
 {
    ULONG i;
@@ -391,7 +423,7 @@ MmFreeSwapPage(SWAPENTRY Entry)
 
    i = FILE_FROM_ENTRY(Entry);
    off = OFFSET_FROM_ENTRY(Entry);
-   
+
    if (i >= MAX_PAGING_FILES)
    {
        DPRINT1("Bad swap entry 0x%.8X\n", Entry);
@@ -404,9 +436,9 @@ MmFreeSwapPage(SWAPENTRY Entry)
       KEBUGCHECK(0);
    }
    KeAcquireSpinLockAtDpcLevel(&PagingFileList[i]->AllocMapLock);
-   
+
    PagingFileList[i]->AllocMap[off >> 5] &= (~(1 << (off % 32)));
-   
+
    PagingFileList[i]->FreePages++;
    PagingFileList[i]->UsedPages--;
 
@@ -418,12 +450,14 @@ MmFreeSwapPage(SWAPENTRY Entry)
 }
 
 BOOLEAN
+NTAPI
 MmIsAvailableSwapPage(VOID)
 {
    return(MiFreeSwapPages > 0);
 }
 
 SWAPENTRY
+NTAPI
 MmAllocSwapPage(VOID)
 {
    KIRQL oldIrql;
@@ -471,7 +505,7 @@ MmAllocRetrievelDescriptorList(ULONG Pairs)
    ULONG Size;
    PRETRIEVEL_DESCRIPTOR_LIST RetDescList;
 
-   Size = sizeof(RETRIEVEL_DESCRIPTOR_LIST) + Pairs * sizeof(MAPPING_PAIR);
+   Size = sizeof(RETRIEVEL_DESCRIPTOR_LIST) + Pairs * 2 * sizeof(LARGE_INTEGER);
    RetDescList = ExAllocatePool(NonPagedPool, Size);
    if (RetDescList)
    {
@@ -498,7 +532,7 @@ MmDumpToPagingFile(ULONG BugCode,
    PULONG MdlMap;
    LONGLONG NextOffset = 0;
    ULONG i;
-   PGET_RETRIEVAL_DESCRIPTOR RetrievalPointers;
+   PRETRIEVAL_POINTERS_BUFFER RetrievalPointers;
    LARGE_INTEGER DiskOffset;
 
    if (MmCoreDumpPageFile == 0xFFFFFFFF)
@@ -515,7 +549,7 @@ MmDumpToPagingFile(ULONG BugCode,
    Headers->Type = MmCoreDumpType;
    if (TrapFrame != NULL)
    {
-      if (!(TrapFrame->Eflags & (1 << 17)))
+      if (!(TrapFrame->EFlags & (1 << 17)))
       {
          memcpy(&Headers->TrapFrame, TrapFrame,
                 sizeof(KTRAP_FRAME) - (4 * sizeof(DWORD)));
@@ -532,7 +566,7 @@ MmDumpToPagingFile(ULONG BugCode,
    Headers->BugCheckParameters[3] = BugCodeParameter4;
    Headers->FaultingStackBase = (PVOID)Thread->Tcb.StackLimit;
    Headers->FaultingStackSize =
-   StackSize = (ULONG_PTR)(Thread->Tcb.StackBase - Thread->Tcb.StackLimit);
+   StackSize = (ULONG_PTR)Thread->Tcb.StackBase - (ULONG_PTR)Thread->Tcb.StackLimit;
    Headers->PhysicalMemorySize = MmStats.NrTotalPages * PAGE_SIZE;
 
    /* Initialize the dump device. */
@@ -585,7 +619,7 @@ MmDumpToPagingFile(ULONG BugCode,
       for (i = 0; i < MmStats.NrTotalPages; i++)
       {
          MdlMap[0] = i;
-         MmCreateVirtualMappingForKernel(MmCoreDumpPageFrame, 
+         MmCreateVirtualMappingForKernel(MmCoreDumpPageFrame,
                                         PAGE_READWRITE,
                                          MdlMap,
                                         1);
@@ -631,10 +665,10 @@ MmInitializeCrashDump(HANDLE PageFileHandle, ULONG PageFileNum)
    PIRP Irp;
    KEVENT Event;
    IO_STATUS_BLOCK Iosb;
-   UNICODE_STRING DiskDumpName;
+   UNICODE_STRING DiskDumpName = RTL_CONSTANT_STRING(L"DiskDump");
    ANSI_STRING ProcName;
    PIO_STACK_LOCATION StackPtr;
-   PMODULE_OBJECT ModuleObject;
+   PLDR_DATA_TABLE_ENTRY ModuleObject;
 
    Status = ZwFsControlFile(PageFileHandle,
                             0,
@@ -678,7 +712,7 @@ MmInitializeCrashDump(HANDLE PageFileHandle, ULONG PageFileNum)
                                        FALSE,
                                        &Event,
                                        &Iosb);
-   if(Irp == NULL) 
+   if(Irp == NULL)
    {
       ObDereferenceObject(PageFile);
       return(STATUS_NO_MEMORY);// tMk - is this correct return code ???
@@ -707,14 +741,13 @@ MmInitializeCrashDump(HANDLE PageFileHandle, ULONG PageFileNum)
    }
 
    /* Load the diskdump driver. */
-   RtlRosInitUnicodeStringFromLiteral(&DiskDumpName, L"DiskDump");
    ModuleObject = LdrGetModuleObject(&DiskDumpName);
    if (ModuleObject == NULL)
    {
       return(STATUS_OBJECT_NAME_NOT_FOUND);
    }
    RtlInitAnsiString(&ProcName, "DiskDumpFunctions");
-   Status = LdrGetProcedureAddress(ModuleObject->Base,
+   Status = LdrGetProcedureAddress(ModuleObject->DllBase,
                                    &ProcName,
                                    0,
                                    (PVOID*)&MmCoreDumpFunctions);
@@ -759,9 +792,12 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName,
    ULONG BytesPerAllocationUnit;
    LARGE_INTEGER Vcn;
    ULONG ExtentCount;
-   ULONG MaxVcn;
+   LARGE_INTEGER MaxVcn;
    ULONG Count;
    ULONG Size;
+   KPROCESSOR_MODE PreviousMode;
+   UNICODE_STRING CapturedFileName;
+   LARGE_INTEGER SafeInitialSize, SafeMaximumSize;
 
    DPRINT("NtCreatePagingFile(FileName %wZ, InitialSize %I64d)\n",
           FileName, InitialSize->QuadPart);
@@ -771,8 +807,57 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName,
       return(STATUS_TOO_MANY_PAGING_FILES);
    }
 
+   PreviousMode = ExGetPreviousMode();
+
+   if (PreviousMode != KernelMode)
+   {
+      _SEH_TRY
+      {
+         SafeInitialSize = ProbeForReadLargeInteger(InitialSize);
+         SafeMaximumSize = ProbeForReadLargeInteger(MaximumSize);
+      }
+      _SEH_HANDLE
+      {
+         Status = _SEH_GetExceptionCode();
+      }
+      _SEH_END;
+
+      if (!NT_SUCCESS(Status))
+      {
+         return Status;
+      }
+   }
+   else
+   {
+      SafeInitialSize = *InitialSize;
+      SafeMaximumSize = *MaximumSize;
+   }
+
+   /* Pagefiles can't be larger than 4GB and ofcourse the minimum should be
+      smaller than the maximum */
+   if (0 != SafeInitialSize.u.HighPart)
+   {
+      return STATUS_INVALID_PARAMETER_2;
+   }
+   if (0 != SafeMaximumSize.u.HighPart)
+   {
+      return STATUS_INVALID_PARAMETER_3;
+   }
+   if (SafeMaximumSize.u.LowPart < SafeInitialSize.u.LowPart)
+   {
+      return STATUS_INVALID_PARAMETER_MIX;
+   }
+
+   Status = ProbeAndCaptureUnicodeString(&CapturedFileName,
+                                         PreviousMode,
+                                         FileName);
+   if (!NT_SUCCESS(Status))
+   {
+      return(Status);
+   }
+
    InitializeObjectAttributes(&ObjectAttributes,
-                              FileName,
+                              &CapturedFileName,
                               0,
                               NULL,
                               NULL);
@@ -790,50 +875,65 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName,
                          0,
                          CreateFileTypeNone,
                          NULL,
-                         SL_OPEN_PAGING_FILE);
+                         SL_OPEN_PAGING_FILE | IO_NO_PARAMETER_CHECKING);
+
+   ReleaseCapturedUnicodeString(&CapturedFileName,
+                                PreviousMode);
    if (!NT_SUCCESS(Status))
    {
       return(Status);
    }
 
-   Status = NtQueryVolumeInformationFile(FileHandle,
+   Status = ZwQueryVolumeInformationFile(FileHandle,
                                          &IoStatus,
                                          &FsSizeInformation,
                                          sizeof(FILE_FS_SIZE_INFORMATION),
                                          FileFsSizeInformation);
    if (!NT_SUCCESS(Status))
    {
-      NtClose(FileHandle);
+      ZwClose(FileHandle);
       return Status;
    }
 
-   BytesPerAllocationUnit = FsSizeInformation.SectorsPerAllocationUnit * FsSizeInformation.BytesPerSector;
-   if (BytesPerAllocationUnit % PAGE_SIZE)
+   BytesPerAllocationUnit = FsSizeInformation.SectorsPerAllocationUnit *
+                            FsSizeInformation.BytesPerSector;
+
+   /* We have to find a value which is a multiple of both PAGE_SIZE and
+      BytesPerAllocationUnit */
+   SafeInitialSize.u.LowPart = ((SafeInitialSize.u.LowPart + PAGE_SIZE - 1) /
+                                PAGE_SIZE) * PAGE_SIZE;
+   while (0 != (SafeInitialSize.u.LowPart % BytesPerAllocationUnit) &&
+          SafeInitialSize.u.LowPart <= SafeMaximumSize.u.LowPart - PAGE_SIZE)
    {
-      NtClose(FileHandle);
-      return STATUS_UNSUCCESSFUL;
+      SafeInitialSize.u.LowPart += PAGE_SIZE;
+   }
+   if (0 != (SafeInitialSize.u.LowPart % BytesPerAllocationUnit))
+   {
+      ZwClose(FileHandle);
+      return STATUS_ALLOTTED_SPACE_EXCEEDED;
    }
+   ASSERT(0 == (SafeInitialSize.u.LowPart % PAGE_SIZE));
 
-   Status = NtSetInformationFile(FileHandle,
+   Status = ZwSetInformationFile(FileHandle,
                                  &IoStatus,
-                                 InitialSize,
+                                 &SafeInitialSize,
                                  sizeof(LARGE_INTEGER),
                                  FileAllocationInformation);
    if (!NT_SUCCESS(Status))
    {
-      NtClose(FileHandle);
+      ZwClose(FileHandle);
       return(Status);
    }
 
    Status = ObReferenceObjectByHandle(FileHandle,
                                       FILE_ALL_ACCESS,
                                       IoFileObjectType,
-                                      UserMode,
+                                      PreviousMode,
                                       (PVOID*)&FileObject,
                                       NULL);
    if (!NT_SUCCESS(Status))
    {
-      NtClose(FileHandle);
+      ZwClose(FileHandle);
       return(Status);
    }
 
@@ -842,7 +942,7 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName,
    if (CurrentRetDescList == NULL)
    {
       ObDereferenceObject(FileObject);
-      NtClose(FileHandle);
+      ZwClose(FileHandle);
       return(STATUS_NO_MEMORY);
    }
 
@@ -854,10 +954,10 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName,
 #endif
 
    ExtentCount = 0;
-   MaxVcn = (ULONG)((InitialSize->QuadPart + BytesPerAllocationUnit - 1) / BytesPerAllocationUnit);
+   MaxVcn.QuadPart = (SafeInitialSize.QuadPart + BytesPerAllocationUnit - 1) / BytesPerAllocationUnit;
    while(1)
    {
-      Status = NtFsControlFile(FileHandle,
+      Status = ZwFsControlFile(FileHandle,
                                0,
                                NULL,
                                NULL,
@@ -866,7 +966,7 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName,
                                &Vcn,
                                sizeof(LARGE_INTEGER),
                                &CurrentRetDescList->RetrievalPointers,
-                               sizeof(GET_RETRIEVAL_DESCRIPTOR) + PAIRS_PER_RUN * sizeof(MAPPING_PAIR));
+                               sizeof(RETRIEVAL_POINTERS_BUFFER) + PAIRS_PER_RUN * 2 * sizeof(LARGE_INTEGER));
       if (!NT_SUCCESS(Status))
       {
          while (RetDescList)
@@ -876,11 +976,11 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName,
             ExFreePool(CurrentRetDescList);
          }
          ObDereferenceObject(FileObject);
-         NtClose(FileHandle);
+         ZwClose(FileHandle);
          return(Status);
       }
-      ExtentCount += CurrentRetDescList->RetrievalPointers.NumberOfPairs;
-      if ((ULONG)CurrentRetDescList->RetrievalPointers.Pair[CurrentRetDescList->RetrievalPointers.NumberOfPairs-1].Vcn < MaxVcn)
+      ExtentCount += CurrentRetDescList->RetrievalPointers.ExtentCount;
+      if (CurrentRetDescList->RetrievalPointers.Extents[CurrentRetDescList->RetrievalPointers.ExtentCount-1].NextVcn.QuadPart < MaxVcn.QuadPart)
       {
          CurrentRetDescList->Next = MmAllocRetrievelDescriptorList(PAIRS_PER_RUN);
          if (CurrentRetDescList->Next == NULL)
@@ -892,10 +992,10 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName,
                ExFreePool(CurrentRetDescList);
             }
             ObDereferenceObject(FileObject);
-            NtClose(FileHandle);
+            ZwClose(FileHandle);
             return(STATUS_NO_MEMORY);
          }
-         Vcn.QuadPart = CurrentRetDescList->RetrievalPointers.Pair[CurrentRetDescList->RetrievalPointers.NumberOfPairs-1].Vcn;
+         Vcn = CurrentRetDescList->RetrievalPointers.Extents[CurrentRetDescList->RetrievalPointers.ExtentCount-1].NextVcn;
          CurrentRetDescList = CurrentRetDescList->Next;
       }
       else
@@ -914,16 +1014,16 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName,
          ExFreePool(CurrentRetDescList);
       }
       ObDereferenceObject(FileObject);
-      NtClose(FileHandle);
+      ZwClose(FileHandle);
       return(STATUS_NO_MEMORY);
    }
 
    RtlZeroMemory(PagingFile, sizeof(*PagingFile));
 
    PagingFile->FileObject = FileObject;
-   PagingFile->MaximumSize.QuadPart = MaximumSize->QuadPart;
-   PagingFile->CurrentSize.QuadPart = InitialSize->QuadPart;
-   PagingFile->FreePages = (ULONG)(InitialSize->QuadPart / PAGE_SIZE);
+   PagingFile->MaximumSize.QuadPart = SafeMaximumSize.QuadPart;
+   PagingFile->CurrentSize.QuadPart = SafeInitialSize.QuadPart;
+   PagingFile->FreePages = (ULONG)(SafeInitialSize.QuadPart / PAGE_SIZE);
    PagingFile->UsedPages = 0;
    KeInitializeSpinLock(&PagingFile->AllocMapLock);
 
@@ -946,7 +1046,7 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName,
       return(STATUS_NO_MEMORY);
    }
    DPRINT("ExtentCount: %d\n", ExtentCount);
-   Size = sizeof(GET_RETRIEVAL_DESCRIPTOR) + ExtentCount * sizeof(MAPPING_PAIR);
+   Size = sizeof(RETRIEVAL_POINTERS_BUFFER) + ExtentCount * 2 * sizeof(LARGE_INTEGER);
    PagingFile->RetrievalPointers = ExAllocatePool(NonPagedPool, Size);
    if (PagingFile->RetrievalPointers == NULL)
    {
@@ -959,7 +1059,7 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName,
       ExFreePool(PagingFile->AllocMap);
       ExFreePool(PagingFile);
       ObDereferenceObject(FileObject);
-      NtClose(FileHandle);
+      ZwClose(FileHandle);
       return(STATUS_NO_MEMORY);
    }
 
@@ -967,39 +1067,39 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName,
    RtlZeroMemory(PagingFile->RetrievalPointers, Size);
 
    Count = 0;
-   PagingFile->RetrievalPointers->NumberOfPairs = ExtentCount;
-   PagingFile->RetrievalPointers->StartVcn = RetDescList->RetrievalPointers.StartVcn;
+   PagingFile->RetrievalPointers->ExtentCount = ExtentCount;
+   PagingFile->RetrievalPointers->StartingVcn = RetDescList->RetrievalPointers.StartingVcn;
    CurrentRetDescList = RetDescList;
    while (CurrentRetDescList)
    {
-      memcpy(&PagingFile->RetrievalPointers->Pair[Count],
-             CurrentRetDescList->RetrievalPointers.Pair,
-             CurrentRetDescList->RetrievalPointers.NumberOfPairs * sizeof(MAPPING_PAIR));
-      Count += CurrentRetDescList->RetrievalPointers.NumberOfPairs;
+      memcpy(&PagingFile->RetrievalPointers->Extents[Count],
+             CurrentRetDescList->RetrievalPointers.Extents,
+             CurrentRetDescList->RetrievalPointers.ExtentCount * 2 * sizeof(LARGE_INTEGER));
+      Count += CurrentRetDescList->RetrievalPointers.ExtentCount;
       RetDescList = CurrentRetDescList;
       CurrentRetDescList = CurrentRetDescList->Next;
       ExFreePool(RetDescList);
    }
 
-   if (PagingFile->RetrievalPointers->NumberOfPairs != ExtentCount ||
-         (ULONG)PagingFile->RetrievalPointers->Pair[ExtentCount - 1].Vcn != MaxVcn)
+   if (PagingFile->RetrievalPointers->ExtentCount != ExtentCount ||
+         PagingFile->RetrievalPointers->Extents[ExtentCount - 1].NextVcn.QuadPart != MaxVcn.QuadPart)
    {
       ExFreePool(PagingFile->RetrievalPointers);
       ExFreePool(PagingFile->AllocMap);
       ExFreePool(PagingFile);
       ObDereferenceObject(FileObject);
-      NtClose(FileHandle);
+      ZwClose(FileHandle);
       return(STATUS_UNSUCCESSFUL);
    }
 
    /*
     * Change the entries from lcn's to volume offset's.
     */
-   PagingFile->RetrievalPointers->StartVcn *= BytesPerAllocationUnit;
+   PagingFile->RetrievalPointers->StartingVcn.QuadPart *= BytesPerAllocationUnit;
    for (i = 0; i < ExtentCount; i++)
    {
-      PagingFile->RetrievalPointers->Pair[i].Lcn *= BytesPerAllocationUnit;
-      PagingFile->RetrievalPointers->Pair[i].Vcn *= BytesPerAllocationUnit;
+      PagingFile->RetrievalPointers->Extents[i].Lcn.QuadPart *= BytesPerAllocationUnit;
+      PagingFile->RetrievalPointers->Extents[i].NextVcn.QuadPart *= BytesPerAllocationUnit;
    }
 
    KeAcquireSpinLock(&PagingFileListLock, &oldIrql);
@@ -1022,7 +1122,7 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName,
    {
       MmInitializeCrashDump(FileHandle, i);
    }
-   NtClose(FileHandle);
+   ZwClose(FileHandle);
 
    MmSwapSpaceMessage = FALSE;