[RSHELL]
[reactos.git] / ntoskrnl / mm / pagefile.c
index a9c1c6a..06563d9 100644 (file)
@@ -81,17 +81,17 @@ static ULONG MiPagingFileCount;
 ULONG MmNumberOfPagingFiles;
 
 /* Number of pages that are available for swapping */
-PFN_NUMBER MiFreeSwapPages;
+PFN_COUNT MiFreeSwapPages;
 
 /* Number of pages that have been allocated for swapping */
-PFN_NUMBER MiUsedSwapPages;
+PFN_COUNT MiUsedSwapPages;
 
 BOOLEAN MmZeroPageFile;
 
 /*
  * Number of pages that have been reserved for swapping but not yet allocated
  */
-static PFN_NUMBER MiReservedSwapPages;
+static PFN_COUNT MiReservedSwapPages;
 
 /*
  * Ratio between reserved and available swap pages, e.g. setting this to five
@@ -113,7 +113,10 @@ static PFN_NUMBER MiReservedSwapPages;
  */
 #define FILE_FROM_ENTRY(i) ((i) & 0x0f)
 #define OFFSET_FROM_ENTRY(i) ((i) >> 11)
-#define ENTRY_FROM_FILE_OFFSET(i, j) ((i) | (j) << 11 | 0x400)
+#define ENTRY_FROM_FILE_OFFSET(i, j) ((i) | ((j) << 11) | 0x400)
+
+/* Make sure there can be only 16 paging files */
+C_ASSERT(FILE_FROM_ENTRY(0xffffffff) < MAX_PAGING_FILES);
 
 static BOOLEAN MmSwapSpaceMessage = FALSE;
 
@@ -124,7 +127,7 @@ NTAPI
 MmBuildMdlFromPages(PMDL Mdl, PPFN_NUMBER Pages)
 {
     memcpy(Mdl + 1, Pages, sizeof(PFN_NUMBER) * (PAGE_ROUND_UP(Mdl->ByteOffset+Mdl->ByteCount)/PAGE_SIZE));
-    
+
     /* FIXME: this flag should be set by the caller perhaps? */
     Mdl->MdlFlags |= MDL_IO_PAGE_READ;
 }
@@ -132,7 +135,7 @@ MmBuildMdlFromPages(PMDL Mdl, PPFN_NUMBER Pages)
 
 BOOLEAN
 NTAPI
-MmIsFileAPagingFile(PFILE_OBJECT FileObject)
+MmIsFileObjectAPagingFile(PFILE_OBJECT FileObject)
 {
     ULONG i;
 
@@ -219,7 +222,8 @@ NTSTATUS
 NTAPI
 MmWriteToSwapPage(SWAPENTRY SwapEntry, PFN_NUMBER Page)
 {
-   ULONG i, offset;
+   ULONG i;
+   ULONG_PTR offset;
    LARGE_INTEGER file_offset;
    IO_STATUS_BLOCK Iosb;
    NTSTATUS Status;
@@ -238,11 +242,6 @@ MmWriteToSwapPage(SWAPENTRY SwapEntry, PFN_NUMBER Page)
    i = FILE_FROM_ENTRY(SwapEntry);
    offset = OFFSET_FROM_ENTRY(SwapEntry);
 
-   if (i >= MAX_PAGING_FILES)
-   {
-      DPRINT1("Bad swap entry 0x%.8X\n", SwapEntry);
-      KeBugCheck(MEMORY_MANAGEMENT);
-   }
    if (PagingFileList[i]->FileObject == NULL ||
          PagingFileList[i]->FileObject->DeviceObject == NULL)
    {
@@ -268,7 +267,7 @@ MmWriteToSwapPage(SWAPENTRY SwapEntry, PFN_NUMBER Page)
       KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
       Status = Iosb.Status;
    }
-    
+
    if (Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA)
    {
       MmUnmapLockedPages (Mdl->MappedSystemVa, Mdl);
@@ -280,7 +279,8 @@ NTSTATUS
 NTAPI
 MmReadFromSwapPage(SWAPENTRY SwapEntry, PFN_NUMBER Page)
 {
-   ULONG i, offset;
+   ULONG i;
+   ULONG_PTR offset;
    LARGE_INTEGER file_offset;
    IO_STATUS_BLOCK Iosb;
    NTSTATUS Status;
@@ -299,11 +299,6 @@ MmReadFromSwapPage(SWAPENTRY SwapEntry, PFN_NUMBER Page)
    i = FILE_FROM_ENTRY(SwapEntry);
    offset = OFFSET_FROM_ENTRY(SwapEntry);
 
-   if (i >= MAX_PAGING_FILES)
-   {
-      DPRINT1("Bad swap entry 0x%.8X\n", SwapEntry);
-      KeBugCheck(MEMORY_MANAGEMENT);
-   }
    if (PagingFileList[i]->FileObject == NULL ||
          PagingFileList[i]->FileObject->DeviceObject == NULL)
    {
@@ -419,18 +414,12 @@ NTAPI
 MmFreeSwapPage(SWAPENTRY Entry)
 {
    ULONG i;
-   ULONG off;
+   ULONG_PTR off;
    KIRQL oldIrql;
 
    i = FILE_FROM_ENTRY(Entry);
    off = OFFSET_FROM_ENTRY(Entry);
 
-   if (i >= MAX_PAGING_FILES)
-   {
-       DPRINT1("Bad swap entry 0x%.8X\n", Entry);
-       KeBugCheck(MEMORY_MANAGEMENT);
-   }
-
    KeAcquireSpinLock(&PagingFileListLock, &oldIrql);
    if (PagingFileList[i] == NULL)
    {
@@ -645,7 +634,7 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName,
     * bytes) to the physical location of cluster 3042 then. */
    if (BytesPerAllocationUnit % PAGE_SIZE)
    {
-      DPRINT1("BytesPerAllocationUnit %d is not a multiple of PAGE_SIZE %d\n",
+      DPRINT1("BytesPerAllocationUnit %lu is not a multiple of PAGE_SIZE %d\n",
               BytesPerAllocationUnit, PAGE_SIZE);
       ZwClose(FileHandle);
       return STATUS_UNSUCCESSFUL;
@@ -782,7 +771,7 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName,
       ZwClose(FileHandle);
       return(STATUS_NO_MEMORY);
    }
-   DPRINT("ExtentCount: %d\n", ExtentCount);
+   DPRINT("ExtentCount: %lu\n", ExtentCount);
    Size = sizeof(RETRIEVAL_POINTERS_BUFFER) + ExtentCount * 2 * sizeof(LARGE_INTEGER);
    PagingFile->RetrievalPointers = ExAllocatePool(NonPagedPool, Size);
    if (PagingFile->RetrievalPointers == NULL)