https://git.reactos.org/?p=reactos.git;a=commitdiff;h=19318dcc1deb97ea8aa01…
commit 19318dcc1deb97ea8aa017df4a5b0f8ea02a1c0f
Author: Pierre Schweitzer <pierre(a)reactos.org>
AuthorDate: Thu Aug 16 14:04:27 2018 +0200
Commit: Pierre Schweitzer <pierre(a)reactos.org>
CommitDate: Thu Aug 16 14:04:27 2018 +0200
[NTOSKRNL] Start making our MMPAGING_FILE struct look like the real one
---
ntoskrnl/include/internal/mm.h | 8 ++++----
ntoskrnl/mm/pagefile.c | 40 ++++++++++++++++++++++------------------
2 files changed, 26 insertions(+), 22 deletions(-)
diff --git a/ntoskrnl/include/internal/mm.h b/ntoskrnl/include/internal/mm.h
index ca82fd87d9..cf9e5069ac 100644
--- a/ntoskrnl/include/internal/mm.h
+++ b/ntoskrnl/include/internal/mm.h
@@ -426,14 +426,14 @@ extern MM_MEMORY_CONSUMER MiMemoryConsumers[MC_MAXIMUM];
/* Page file information */
typedef struct _MMPAGING_FILE
{
- PFN_NUMBER CurrentSize;
+ PFN_NUMBER Size;
PFN_NUMBER MaximumSize;
PFN_NUMBER MinimumSize;
- PFN_NUMBER FreePages;
- PFN_NUMBER UsedPages;
+ PFN_NUMBER FreeSpace;
+ PFN_NUMBER CurrentUsage;
PFILE_OBJECT FileObject;
UNICODE_STRING PageFileName;
- PRTL_BITMAP AllocMap;
+ PRTL_BITMAP Bitmap;
HANDLE FileHandle;
}
MMPAGING_FILE, *PMMPAGING_FILE;
diff --git a/ntoskrnl/mm/pagefile.c b/ntoskrnl/mm/pagefile.c
index dd24fe7d5b..9019beef90 100644
--- a/ntoskrnl/mm/pagefile.c
+++ b/ntoskrnl/mm/pagefile.c
@@ -290,10 +290,10 @@ MmFreeSwapPage(SWAPENTRY Entry)
KeBugCheck(MEMORY_MANAGEMENT);
}
- RtlClearBit(PagingFile->AllocMap, off >> 5);
+ RtlClearBit(PagingFile->Bitmap, off >> 5);
- PagingFile->FreePages++;
- PagingFile->UsedPages--;
+ PagingFile->FreeSpace++;
+ PagingFile->CurrentUsage--;
MiFreeSwapPages++;
MiUsedSwapPages--;
@@ -320,9 +320,9 @@ MmAllocSwapPage(VOID)
for (i = 0; i < MAX_PAGING_FILES; i++)
{
if (MmPagingFile[i] != NULL &&
- MmPagingFile[i]->FreePages >= 1)
+ MmPagingFile[i]->FreeSpace >= 1)
{
- off = RtlFindClearBitsAndSet(MmPagingFile[i]->AllocMap, 1, 0);
+ off = RtlFindClearBitsAndSet(MmPagingFile[i]->Bitmap, 1, 0);
if (off == 0xFFFFFFFF)
{
KeBugCheck(MEMORY_MANAGEMENT);
@@ -741,17 +741,21 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName,
PagingFile->FileHandle = FileHandle;
PagingFile->FileObject = FileObject;
PagingFile->MaximumSize = (SafeMaximumSize.QuadPart >> PAGE_SHIFT);
- PagingFile->CurrentSize = (SafeMinimumSize.QuadPart >> PAGE_SHIFT);
+ PagingFile->Size = (SafeMinimumSize.QuadPart >> PAGE_SHIFT);
PagingFile->MinimumSize = (SafeMinimumSize.QuadPart >> PAGE_SHIFT);
- PagingFile->FreePages = (ULONG)(SafeMinimumSize.QuadPart / PAGE_SIZE);
- PagingFile->UsedPages = 0;
+ /* First page is never used: it's the header
+ * TODO: write it
+ */
+ PagingFile->FreeSpace = (ULONG)(SafeMinimumSize.QuadPart / PAGE_SIZE) - 1;
+ PagingFile->CurrentUsage = 0;
PagingFile->PageFileName = PageFileName;
+ ASSERT(PagingFile->Size == PagingFile->FreeSpace + PagingFile->CurrentUsage
+ 1);
- AllocMapSize = sizeof(RTL_BITMAP) + (((PagingFile->FreePages + 31) / 32) *
sizeof(ULONG));
- PagingFile->AllocMap = ExAllocatePoolWithTag(NonPagedPool,
- AllocMapSize,
- TAG_MM);
- if (PagingFile->AllocMap == NULL)
+ AllocMapSize = sizeof(RTL_BITMAP) + (((PagingFile->MaximumSize + 31) / 32) *
sizeof(ULONG));
+ PagingFile->Bitmap = ExAllocatePoolWithTag(NonPagedPool,
+ AllocMapSize,
+ TAG_MM);
+ if (PagingFile->Bitmap == NULL)
{
ExFreePoolWithTag(PagingFile, TAG_MM);
ObDereferenceObject(FileObject);
@@ -760,10 +764,10 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName,
return STATUS_INSUFFICIENT_RESOURCES;
}
- RtlInitializeBitMap(PagingFile->AllocMap,
- (PULONG)(PagingFile->AllocMap + 1),
- (ULONG)(PagingFile->FreePages));
- RtlClearAllBits(PagingFile->AllocMap);
+ RtlInitializeBitMap(PagingFile->Bitmap,
+ (PULONG)(PagingFile->Bitmap + 1),
+ (ULONG)(PagingFile->MaximumSize));
+ RtlClearAllBits(PagingFile->Bitmap);
/* FIXME: should be calling unsafe instead,
* we should already be in a guarded region
@@ -772,7 +776,7 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName,
ASSERT(MmPagingFile[MmNumberOfPagingFiles] == NULL);
MmPagingFile[MmNumberOfPagingFiles] = PagingFile;
MmNumberOfPagingFiles++;
- MiFreeSwapPages = MiFreeSwapPages + PagingFile->FreePages;
+ MiFreeSwapPages = MiFreeSwapPages + PagingFile->FreeSpace;
KeReleaseGuardedMutex(&MmPageFileCreationLock);
MmSwapSpaceMessage = FALSE;