[NTOSKRNL/FORMATTING]

- Trim trailing whitespace and get rid of tabs in Mm

svn path=/trunk/; revision=54755
This commit is contained in:
Thomas Faber 2011-12-25 18:21:05 +00:00
parent 846be7ac13
commit 89857ef31c
20 changed files with 920 additions and 920 deletions

View file

@ -70,8 +70,8 @@ ULONG
NTAPI NTAPI
MmTrimAllSystemPageableMemory(IN ULONG PurgeTransitionList) MmTrimAllSystemPageableMemory(IN ULONG PurgeTransitionList)
{ {
UNIMPLEMENTED; UNIMPLEMENTED;
return 0; return 0;
} }
/* /*

View file

@ -820,8 +820,8 @@ ExFreePoolWithTag(IN PVOID P,
// //
if (TagToFree && TagToFree != Entry->PoolTag) if (TagToFree && TagToFree != Entry->PoolTag)
{ {
DPRINT1("Freeing pool - invalid tag specified: %.4s != %.4s\n", (char*)&TagToFree, (char*)&Entry->PoolTag); DPRINT1("Freeing pool - invalid tag specified: %.4s != %.4s\n", (char*)&TagToFree, (char*)&Entry->PoolTag);
KeBugCheckEx(BAD_POOL_CALLER, 0x0A, (ULONG_PTR)P, Entry->PoolTag, TagToFree); KeBugCheckEx(BAD_POOL_CALLER, 0x0A, (ULONG_PTR)P, Entry->PoolTag, TagToFree);
} }
// //

View file

@ -18,12 +18,12 @@
#if DBG #if DBG
#define ASSERT_LIST_INVARIANT(x) \ #define ASSERT_LIST_INVARIANT(x) \
do { \ do { \
ASSERT(((x)->Total == 0 && \ ASSERT(((x)->Total == 0 && \
(x)->Flink == LIST_HEAD && \ (x)->Flink == LIST_HEAD && \
(x)->Blink == LIST_HEAD) || \ (x)->Blink == LIST_HEAD) || \
((x)->Total != 0 && \ ((x)->Total != 0 && \
(x)->Flink != LIST_HEAD && \ (x)->Flink != LIST_HEAD && \
(x)->Blink != LIST_HEAD)); \ (x)->Blink != LIST_HEAD)); \
} while (0) } while (0)
#else #else
#define ASSERT_LIST_INVARIANT(x) #define ASSERT_LIST_INVARIANT(x)
@ -285,7 +285,7 @@ MiRemovePageByColor(IN PFN_NUMBER PageIndex,
} }
/* We are not on a list anymore */ /* We are not on a list anymore */
ASSERT_LIST_INVARIANT(ListHead); ASSERT_LIST_INVARIANT(ListHead);
Pfn1->u1.Flink = Pfn1->u2.Blink = 0; Pfn1->u1.Flink = Pfn1->u2.Blink = 0;
/* Zero flags but restore color and cache */ /* Zero flags but restore color and cache */

View file

@ -33,7 +33,7 @@ BOOLEAN MmProtectFreedNonPagedPool;
VOID VOID
NTAPI NTAPI
MiProtectFreeNonPagedPool(IN PVOID VirtualAddress, MiProtectFreeNonPagedPool(IN PVOID VirtualAddress,
IN ULONG PageCount) IN ULONG PageCount)
{ {
PMMPTE PointerPte, LastPte; PMMPTE PointerPte, LastPte;
MMPTE TempPte; MMPTE TempPte;
@ -62,7 +62,7 @@ MiProtectFreeNonPagedPool(IN PVOID VirtualAddress,
BOOLEAN BOOLEAN
NTAPI NTAPI
MiUnProtectFreeNonPagedPool(IN PVOID VirtualAddress, MiUnProtectFreeNonPagedPool(IN PVOID VirtualAddress,
IN ULONG PageCount) IN ULONG PageCount)
{ {
PMMPTE PointerPte; PMMPTE PointerPte;
MMPTE TempPte; MMPTE TempPte;
@ -1184,8 +1184,8 @@ NTAPI
MmAllocateMappingAddress(IN SIZE_T NumberOfBytes, MmAllocateMappingAddress(IN SIZE_T NumberOfBytes,
IN ULONG PoolTag) IN ULONG PoolTag)
{ {
UNIMPLEMENTED; UNIMPLEMENTED;
return NULL; return NULL;
} }
/* /*
@ -1196,7 +1196,7 @@ NTAPI
MmFreeMappingAddress(IN PVOID BaseAddress, MmFreeMappingAddress(IN PVOID BaseAddress,
IN ULONG PoolTag) IN ULONG PoolTag)
{ {
UNIMPLEMENTED; UNIMPLEMENTED;
} }
/* EOF */ /* EOF */

View file

@ -718,7 +718,7 @@ MiSnapThunk(IN PVOID DllBase,
/* Copy the procedure name */ /* Copy the procedure name */
RtlStringCbCopyA(*MissingApi, RtlStringCbCopyA(*MissingApi,
MAXIMUM_FILENAME_LENGTH, MAXIMUM_FILENAME_LENGTH,
(PCHAR)&NameImport->Name[0]); (PCHAR)&NameImport->Name[0]);
/* Setup name tables */ /* Setup name tables */
DPRINT("Import name: %s\n", NameImport->Name); DPRINT("Import name: %s\n", NameImport->Name);

View file

@ -394,10 +394,10 @@ MiFindEmptyAddressRangeDownTree(IN SIZE_T Length,
HighVpn = BoundaryAddress >> PAGE_SHIFT; HighVpn = BoundaryAddress >> PAGE_SHIFT;
/* Starting from the root, go down until the right-most child /* Starting from the root, go down until the right-most child
* which is just behind the boundary*/ * which is just behind the boundary*/
LowestNode = Node = RtlRightChildAvl(&Table->BalancedRoot); LowestNode = Node = RtlRightChildAvl(&Table->BalancedRoot);
while (((Child = RtlRightChildAvl(Node)) != 0 ) while (((Child = RtlRightChildAvl(Node)) != 0 )
&& (Node->EndingVpn < HighVpn )) Node = Child; && (Node->EndingVpn < HighVpn )) Node = Child;
/* Now loop the Vad nodes */ /* Now loop the Vad nodes */
while (Node) while (Node)

View file

@ -29,7 +29,7 @@
#define PA_BIT_CD (4) #define PA_BIT_CD (4)
#define PA_BIT_ACCESSED (5) #define PA_BIT_ACCESSED (5)
#define PA_BIT_DIRTY (6) #define PA_BIT_DIRTY (6)
#define PA_BIT_GLOBAL (8) #define PA_BIT_GLOBAL (8)
#define PA_PRESENT (1 << PA_BIT_PRESENT) #define PA_PRESENT (1 << PA_BIT_PRESENT)
#define PA_READWRITE (1 << PA_BIT_READWRITE) #define PA_READWRITE (1 << PA_BIT_READWRITE)
@ -40,8 +40,8 @@
#define PA_ACCESSED (1 << PA_BIT_ACCESSED) #define PA_ACCESSED (1 << PA_BIT_ACCESSED)
#define PA_GLOBAL (1 << PA_BIT_GLOBAL) #define PA_GLOBAL (1 << PA_BIT_GLOBAL)
#define HYPERSPACE (0xc0400000) #define HYPERSPACE (0xc0400000)
#define IS_HYPERSPACE(v) (((ULONG)(v) >= HYPERSPACE && (ULONG)(v) < HYPERSPACE + 0x400000)) #define IS_HYPERSPACE(v) (((ULONG)(v) >= HYPERSPACE && (ULONG)(v) < HYPERSPACE + 0x400000))
ULONG MmGlobalKernelPageDirectory[1024]; ULONG MmGlobalKernelPageDirectory[1024];
@ -491,13 +491,13 @@ MmDeleteVirtualMapping(PEPROCESS Process, PVOID Address, BOOLEAN FreePage,
VOID VOID
NTAPI NTAPI
MmGetPageFileMapping(PEPROCESS Process, PVOID Address, MmGetPageFileMapping(PEPROCESS Process, PVOID Address,
SWAPENTRY* SwapEntry) SWAPENTRY* SwapEntry)
/* /*
* FUNCTION: Get a page file mapping * FUNCTION: Get a page file mapping
*/ */
{ {
ULONG Entry = MmGetPageEntryForProcess(Process, Address); ULONG Entry = MmGetPageEntryForProcess(Process, Address);
*SwapEntry = Entry >> 1; *SwapEntry = Entry >> 1;
} }
VOID VOID

View file

@ -28,7 +28,7 @@
#define PA_BIT_CD (4) #define PA_BIT_CD (4)
#define PA_BIT_ACCESSED (5) #define PA_BIT_ACCESSED (5)
#define PA_BIT_DIRTY (6) #define PA_BIT_DIRTY (6)
#define PA_BIT_GLOBAL (8) #define PA_BIT_GLOBAL (8)
#define PA_PRESENT (1 << PA_BIT_PRESENT) #define PA_PRESENT (1 << PA_BIT_PRESENT)
#define PA_READWRITE (1 << PA_BIT_READWRITE) #define PA_READWRITE (1 << PA_BIT_READWRITE)
@ -39,13 +39,13 @@
#define PA_ACCESSED (1 << PA_BIT_ACCESSED) #define PA_ACCESSED (1 << PA_BIT_ACCESSED)
#define PA_GLOBAL (1 << PA_BIT_GLOBAL) #define PA_GLOBAL (1 << PA_BIT_GLOBAL)
#define PAGETABLE_MAP (0xc0000000) #define PAGETABLE_MAP (0xc0000000)
#define PAGEDIRECTORY_MAP (0xc0000000 + (PAGETABLE_MAP / (1024))) #define PAGEDIRECTORY_MAP (0xc0000000 + (PAGETABLE_MAP / (1024)))
#define PAE_PAGEDIRECTORY_MAP (0xc0000000 + (PAGETABLE_MAP / (512))) #define PAE_PAGEDIRECTORY_MAP (0xc0000000 + (PAGETABLE_MAP / (512)))
#define HYPERSPACE (Ke386Pae ? 0xc0800000 : 0xc0400000) #define HYPERSPACE (Ke386Pae ? 0xc0800000 : 0xc0400000)
#define IS_HYPERSPACE(v) (((ULONG)(v) >= HYPERSPACE && (ULONG)(v) < HYPERSPACE + 0x400000)) #define IS_HYPERSPACE(v) (((ULONG)(v) >= HYPERSPACE && (ULONG)(v) < HYPERSPACE + 0x400000))
ULONG MmGlobalKernelPageDirectory[1024]; ULONG MmGlobalKernelPageDirectory[1024];
ULONGLONG MmGlobalKernelPageDirectoryForPAE[2048]; ULONGLONG MmGlobalKernelPageDirectoryForPAE[2048];
@ -184,9 +184,9 @@ ProtectToPTE(ULONG flProtect)
#define PAE_ADDR_TO_PAGE_TABLE(v) (((ULONG)(v)) / (512 * PAGE_SIZE)) #define PAE_ADDR_TO_PAGE_TABLE(v) (((ULONG)(v)) / (512 * PAGE_SIZE))
#define PAE_ADDR_TO_PDE(v) (PULONGLONG) (PAE_PAGEDIRECTORY_MAP + \ #define PAE_ADDR_TO_PDE(v) (PULONGLONG) (PAE_PAGEDIRECTORY_MAP + \
((((ULONG_PTR)(v)) / (512 * 512))&(~0x7))) ((((ULONG_PTR)(v)) / (512 * 512))&(~0x7)))
#define PAE_ADDR_TO_PTE(v) (PULONGLONG) (PAGETABLE_MAP + ((((ULONG_PTR)(v) / 512))&(~0x7))) #define PAE_ADDR_TO_PTE(v) (PULONGLONG) (PAGETABLE_MAP + ((((ULONG_PTR)(v) / 512))&(~0x7)))
#define PAE_ADDR_TO_PDTE_OFFSET(v) (((ULONG_PTR)(v)) / (512 * 512 * PAGE_SIZE)) #define PAE_ADDR_TO_PDTE_OFFSET(v) (((ULONG_PTR)(v)) / (512 * 512 * PAGE_SIZE))
@ -232,43 +232,43 @@ Mmi386ReleaseMmInfo(PEPROCESS Process)
{ {
PageDir = (PULONGLONG)MmCreateHyperspaceMapping(PAE_PTE_TO_PFN(PageDirTable[i])); PageDir = (PULONGLONG)MmCreateHyperspaceMapping(PAE_PTE_TO_PFN(PageDirTable[i]));
if (i < PAE_ADDR_TO_PDTE_OFFSET(MmSystemRangeStart)) if (i < PAE_ADDR_TO_PDTE_OFFSET(MmSystemRangeStart))
{ {
for (j = 0; j < 512; j++) for (j = 0; j < 512; j++)
{ {
if (PageDir[j] != 0LL) if (PageDir[j] != 0LL)
{ {
DPRINT1("ProcessId %d, Pde for %08x - %08x is not freed, RefCount %d\n", DPRINT1("ProcessId %d, Pde for %08x - %08x is not freed, RefCount %d\n",
Process->UniqueProcessId, Process->UniqueProcessId,
(i * 512 + j) * 512 * PAGE_SIZE, (i * 512 + j + 1) * 512 * PAGE_SIZE - 1, (i * 512 + j) * 512 * PAGE_SIZE, (i * 512 + j + 1) * 512 * PAGE_SIZE - 1,
((PMADDRESS_SPACE)&Process->VadRoot)->PageTableRefCountTable[i*512 + j]); ((PMADDRESS_SPACE)&Process->VadRoot)->PageTableRefCountTable[i*512 + j]);
Pde = MmCreateHyperspaceMapping(PAE_PTE_TO_PFN(PageDir[j])); Pde = MmCreateHyperspaceMapping(PAE_PTE_TO_PFN(PageDir[j]));
for (k = 0; k < 512; k++) for (k = 0; k < 512; k++)
{ {
if(Pde[k] != 0) if(Pde[k] != 0)
{ {
if (Pde[k] & PA_PRESENT) if (Pde[k] & PA_PRESENT)
{ {
DPRINT1("Page at %08x is not freed\n", DPRINT1("Page at %08x is not freed\n",
(i * 512 + j) * 512 * PAGE_SIZE + k * PAGE_SIZE); (i * 512 + j) * 512 * PAGE_SIZE + k * PAGE_SIZE);
} }
else else
{ {
DPRINT1("Swapentry %x at %x is not freed\n", DPRINT1("Swapentry %x at %x is not freed\n",
(i * 512 + j) * 512 * PAGE_SIZE + k * PAGE_SIZE); (i * 512 + j) * 512 * PAGE_SIZE + k * PAGE_SIZE);
} }
} }
} }
MmDeleteHyperspaceMapping(Pde); MmDeleteHyperspaceMapping(Pde);
MmReleasePageMemoryConsumer(MC_NPPOOL, PAE_PTE_TO_PFN(PageDir[j])); MmReleasePageMemoryConsumer(MC_NPPOOL, PAE_PTE_TO_PFN(PageDir[j]));
} }
} }
} }
if (i == PAE_ADDR_TO_PDTE_OFFSET(HYPERSPACE)) if (i == PAE_ADDR_TO_PDTE_OFFSET(HYPERSPACE))
{ {
MmReleasePageMemoryConsumer(MC_NPPOOL, PAE_PTE_TO_PFN(PageDir[PAE_ADDR_TO_PDE_PAGE_OFFSET(HYPERSPACE)])); MmReleasePageMemoryConsumer(MC_NPPOOL, PAE_PTE_TO_PFN(PageDir[PAE_ADDR_TO_PDE_PAGE_OFFSET(HYPERSPACE)]));
MmReleasePageMemoryConsumer(MC_NPPOOL, PAE_PTE_TO_PFN(PageDir[PAE_ADDR_TO_PDE_PAGE_OFFSET(HYPERSPACE)+1])); MmReleasePageMemoryConsumer(MC_NPPOOL, PAE_PTE_TO_PFN(PageDir[PAE_ADDR_TO_PDE_PAGE_OFFSET(HYPERSPACE)+1]));
} }
MmDeleteHyperspaceMapping(PageDir); MmDeleteHyperspaceMapping(PageDir);
MmReleasePageMemoryConsumer(MC_NPPOOL, PAE_PTE_TO_PFN(PageDirTable[i])); MmReleasePageMemoryConsumer(MC_NPPOOL, PAE_PTE_TO_PFN(PageDirTable[i]));
} }
MmDeleteHyperspaceMapping((PVOID)PageDirTable); MmDeleteHyperspaceMapping((PVOID)PageDirTable);
@ -284,28 +284,28 @@ Mmi386ReleaseMmInfo(PEPROCESS Process)
if (PageDir[i] != 0) if (PageDir[i] != 0)
{ {
DPRINT1("Pde for %08x - %08x is not freed, RefCount %d\n", DPRINT1("Pde for %08x - %08x is not freed, RefCount %d\n",
i * 4 * 1024 * 1024, (i + 1) * 4 * 1024 * 1024 - 1, i * 4 * 1024 * 1024, (i + 1) * 4 * 1024 * 1024 - 1,
((PMADDRESS_SPACE)&Process->VadRoot)->PageTableRefCountTable[i]); ((PMADDRESS_SPACE)&Process->VadRoot)->PageTableRefCountTable[i]);
Pde = MmCreateHyperspaceMapping(PTE_TO_PFN(PageDir[i])); Pde = MmCreateHyperspaceMapping(PTE_TO_PFN(PageDir[i]));
for (j = 0; j < 1024; j++) for (j = 0; j < 1024; j++)
{ {
if(Pde[j] != 0) if(Pde[j] != 0)
{ {
if (Pde[j] & PA_PRESENT) if (Pde[j] & PA_PRESENT)
{ {
DPRINT1("Page at %08x is not freed\n", DPRINT1("Page at %08x is not freed\n",
i * 4 * 1024 * 1024 + j * PAGE_SIZE); i * 4 * 1024 * 1024 + j * PAGE_SIZE);
} }
else else
{ {
DPRINT1("Swapentry %x at %x is not freed\n", DPRINT1("Swapentry %x at %x is not freed\n",
Pde[j], i * 4 * 1024 * 1024 + j * PAGE_SIZE); Pde[j], i * 4 * 1024 * 1024 + j * PAGE_SIZE);
} }
} }
} }
MmDeleteHyperspaceMapping(Pde); MmDeleteHyperspaceMapping(Pde);
MmReleasePageMemoryConsumer(MC_NPPOOL, PTE_TO_PFN(PageDir[i])); MmReleasePageMemoryConsumer(MC_NPPOOL, PTE_TO_PFN(PageDir[i]));
} }
} }
MmReleasePageMemoryConsumer(MC_NPPOOL, PTE_TO_PFN(PageDir[ADDR_TO_PDE_OFFSET(HYPERSPACE)])); MmReleasePageMemoryConsumer(MC_NPPOOL, PTE_TO_PFN(PageDir[ADDR_TO_PDE_OFFSET(HYPERSPACE)]));
MmDeleteHyperspaceMapping(PageDir); MmDeleteHyperspaceMapping(PageDir);
@ -377,25 +377,25 @@ MmCreateProcessAddressSpace(IN ULONG MinWs,
PageDirTable = MmCreateHyperspaceMapping(Pfn[0]); PageDirTable = MmCreateHyperspaceMapping(Pfn[0]);
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
PageDirTable[i] = PAE_PFN_TO_PTE(Pfn[1+i]) | PA_PRESENT; PageDirTable[i] = PAE_PFN_TO_PTE(Pfn[1+i]) | PA_PRESENT;
} }
MmDeleteHyperspaceMapping(PageDirTable); MmDeleteHyperspaceMapping(PageDirTable);
for (i = PAE_ADDR_TO_PDTE_OFFSET(MmSystemRangeStart); i < 4; i++) for (i = PAE_ADDR_TO_PDTE_OFFSET(MmSystemRangeStart); i < 4; i++)
{ {
PageDir = (PULONGLONG)MmCreateHyperspaceMapping(Pfn[i+1]); PageDir = (PULONGLONG)MmCreateHyperspaceMapping(Pfn[i+1]);
memcpy(PageDir, &MmGlobalKernelPageDirectoryForPAE[i * 512], 512 * sizeof(ULONGLONG)); memcpy(PageDir, &MmGlobalKernelPageDirectoryForPAE[i * 512], 512 * sizeof(ULONGLONG));
if (PAE_ADDR_TO_PDTE_OFFSET(PAGETABLE_MAP) == i) if (PAE_ADDR_TO_PDTE_OFFSET(PAGETABLE_MAP) == i)
{ {
for (j = 0; j < 4; j++) for (j = 0; j < 4; j++)
{ {
PageDir[PAE_ADDR_TO_PDE_PAGE_OFFSET(PAGETABLE_MAP) + j] = PAE_PFN_TO_PTE(Pfn[1+j]) | PA_PRESENT | PA_READWRITE; PageDir[PAE_ADDR_TO_PDE_PAGE_OFFSET(PAGETABLE_MAP) + j] = PAE_PFN_TO_PTE(Pfn[1+j]) | PA_PRESENT | PA_READWRITE;
} }
} }
if (PAE_ADDR_TO_PDTE_OFFSET(HYPERSPACE) == i) if (PAE_ADDR_TO_PDTE_OFFSET(HYPERSPACE) == i)
{ {
PageDir[PAE_ADDR_TO_PDE_PAGE_OFFSET(HYPERSPACE)] = PAE_PFN_TO_PTE(Pfn[5]) | PA_PRESENT | PA_READWRITE; PageDir[PAE_ADDR_TO_PDE_PAGE_OFFSET(HYPERSPACE)] = PAE_PFN_TO_PTE(Pfn[5]) | PA_PRESENT | PA_READWRITE;
PageDir[PAE_ADDR_TO_PDE_PAGE_OFFSET(HYPERSPACE)+1] = PAE_PFN_TO_PTE(Pfn[6]) | PA_PRESENT | PA_READWRITE; PageDir[PAE_ADDR_TO_PDE_PAGE_OFFSET(HYPERSPACE)+1] = PAE_PFN_TO_PTE(Pfn[6]) | PA_PRESENT | PA_READWRITE;
} }
MmDeleteHyperspaceMapping(PageDir); MmDeleteHyperspaceMapping(PageDir);
} }
} }
@ -552,22 +552,22 @@ MmGetPageTableForProcessForPAE(PEPROCESS Process, PVOID Address, BOOLEAN Create)
if (Entry == 0LL) if (Entry == 0LL)
{ {
if (Create == FALSE) if (Create == FALSE)
{ {
MmDeleteHyperspaceMapping(PageDir); MmDeleteHyperspaceMapping(PageDir);
return NULL; return NULL;
} }
Status = MmRequestPageMemoryConsumer(MC_NPPOOL, FALSE, &Pfn); Status = MmRequestPageMemoryConsumer(MC_NPPOOL, FALSE, &Pfn);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
ASSERT(FALSE); ASSERT(FALSE);
} }
Entry = PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE | PA_USER; Entry = PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE | PA_USER;
Entry = ExfInterlockedCompareExchange64UL(PageDir, &Entry, &ZeroEntry); Entry = ExfInterlockedCompareExchange64UL(PageDir, &Entry, &ZeroEntry);
if (Entry != 0LL) if (Entry != 0LL)
{ {
MmReleasePageMemoryConsumer(MC_NPPOOL, Pfn); MmReleasePageMemoryConsumer(MC_NPPOOL, Pfn);
Pfn = PAE_PTE_TO_PFN(Entry); Pfn = PAE_PTE_TO_PFN(Entry);
} }
} }
else else
{ {
@ -586,46 +586,46 @@ MmGetPageTableForProcessForPAE(PEPROCESS Process, PVOID Address, BOOLEAN Create)
{ {
if (Address >= MmSystemRangeStart) if (Address >= MmSystemRangeStart)
{ {
if (MmGlobalKernelPageDirectoryForPAE[PAE_ADDR_TO_PDE_OFFSET(Address)] == 0LL) if (MmGlobalKernelPageDirectoryForPAE[PAE_ADDR_TO_PDE_OFFSET(Address)] == 0LL)
{ {
if (Create == FALSE) if (Create == FALSE)
{ {
return NULL; return NULL;
} }
Status = MmRequestPageMemoryConsumer(MC_NPPOOL, FALSE, &Pfn); Status = MmRequestPageMemoryConsumer(MC_NPPOOL, FALSE, &Pfn);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
ASSERT(FALSE); ASSERT(FALSE);
} }
Entry = PAE_PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE; Entry = PAE_PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE;
if (Ke386GlobalPagesEnabled) if (Ke386GlobalPagesEnabled)
{ {
Entry |= PA_GLOBAL; Entry |= PA_GLOBAL;
} }
if (0LL != ExfInterlockedCompareExchange64UL(&MmGlobalKernelPageDirectoryForPAE[PAE_ADDR_TO_PDE_OFFSET(Address)], &Entry, &ZeroEntry)) if (0LL != ExfInterlockedCompareExchange64UL(&MmGlobalKernelPageDirectoryForPAE[PAE_ADDR_TO_PDE_OFFSET(Address)], &Entry, &ZeroEntry))
{ {
MmReleasePageMemoryConsumer(MC_NPPOOL, Pfn); MmReleasePageMemoryConsumer(MC_NPPOOL, Pfn);
} }
} }
(void)ExfInterlockedCompareExchange64UL(PageDir, &MmGlobalKernelPageDirectoryForPAE[PAE_ADDR_TO_PDE_OFFSET(Address)], &ZeroEntry); (void)ExfInterlockedCompareExchange64UL(PageDir, &MmGlobalKernelPageDirectoryForPAE[PAE_ADDR_TO_PDE_OFFSET(Address)], &ZeroEntry);
} }
else else
{ {
if (Create == FALSE) if (Create == FALSE)
{ {
return NULL; return NULL;
} }
Status = MmRequestPageMemoryConsumer(MC_NPPOOL, FALSE, &Pfn); Status = MmRequestPageMemoryConsumer(MC_NPPOOL, FALSE, &Pfn);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
ASSERT(FALSE); ASSERT(FALSE);
} }
Entry = PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE | PA_USER; Entry = PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE | PA_USER;
Entry = ExfInterlockedCompareExchange64UL(PageDir, &Entry, &ZeroEntry); Entry = ExfInterlockedCompareExchange64UL(PageDir, &Entry, &ZeroEntry);
if (Entry != 0LL) if (Entry != 0LL)
{ {
MmReleasePageMemoryConsumer(MC_NPPOOL, Pfn); MmReleasePageMemoryConsumer(MC_NPPOOL, Pfn);
} }
} }
} }
return (PULONGLONG)PAE_ADDR_TO_PTE(Address); return (PULONGLONG)PAE_ADDR_TO_PTE(Address);
@ -650,21 +650,21 @@ MmGetPageTableForProcess(PEPROCESS Process, PVOID Address, BOOLEAN Create)
if (0 == InterlockedCompareExchangeUL(&PageDir[PdeOffset], 0, 0)) if (0 == InterlockedCompareExchangeUL(&PageDir[PdeOffset], 0, 0))
{ {
if (Create == FALSE) if (Create == FALSE)
{ {
MmDeleteHyperspaceMapping(PageDir); MmDeleteHyperspaceMapping(PageDir);
return NULL; return NULL;
} }
Status = MmRequestPageMemoryConsumer(MC_NPPOOL, FALSE, &Pfn); Status = MmRequestPageMemoryConsumer(MC_NPPOOL, FALSE, &Pfn);
if (!NT_SUCCESS(Status) || Pfn == 0) if (!NT_SUCCESS(Status) || Pfn == 0)
{ {
ASSERT(FALSE); ASSERT(FALSE);
} }
Entry = InterlockedCompareExchangeUL(&PageDir[PdeOffset], PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE | PA_USER, 0); Entry = InterlockedCompareExchangeUL(&PageDir[PdeOffset], PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE | PA_USER, 0);
if (Entry != 0) if (Entry != 0)
{ {
MmReleasePageMemoryConsumer(MC_NPPOOL, Pfn); MmReleasePageMemoryConsumer(MC_NPPOOL, Pfn);
Pfn = PTE_TO_PFN(Entry); Pfn = PTE_TO_PFN(Entry);
} }
} }
else else
{ {
@ -684,44 +684,44 @@ MmGetPageTableForProcess(PEPROCESS Process, PVOID Address, BOOLEAN Create)
if (Address >= MmSystemRangeStart) if (Address >= MmSystemRangeStart)
{ {
if (0 == InterlockedCompareExchangeUL(&MmGlobalKernelPageDirectory[PdeOffset], 0, 0)) if (0 == InterlockedCompareExchangeUL(&MmGlobalKernelPageDirectory[PdeOffset], 0, 0))
{ {
if (Create == FALSE) if (Create == FALSE)
{ {
return NULL; return NULL;
} }
Status = MmRequestPageMemoryConsumer(MC_NPPOOL, FALSE, &Pfn); Status = MmRequestPageMemoryConsumer(MC_NPPOOL, FALSE, &Pfn);
if (!NT_SUCCESS(Status) || Pfn == 0) if (!NT_SUCCESS(Status) || Pfn == 0)
{ {
ASSERT(FALSE); ASSERT(FALSE);
} }
Entry = PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE; Entry = PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE;
if (Ke386GlobalPagesEnabled) if (Ke386GlobalPagesEnabled)
{ {
Entry |= PA_GLOBAL; Entry |= PA_GLOBAL;
} }
if(0 != InterlockedCompareExchangeUL(&MmGlobalKernelPageDirectory[PdeOffset], Entry, 0)) if(0 != InterlockedCompareExchangeUL(&MmGlobalKernelPageDirectory[PdeOffset], Entry, 0))
{ {
MmReleasePageMemoryConsumer(MC_NPPOOL, Pfn); MmReleasePageMemoryConsumer(MC_NPPOOL, Pfn);
} }
} }
(void)InterlockedExchangeUL(PageDir, MmGlobalKernelPageDirectory[PdeOffset]); (void)InterlockedExchangeUL(PageDir, MmGlobalKernelPageDirectory[PdeOffset]);
} }
else else
{ {
if (Create == FALSE) if (Create == FALSE)
{ {
return NULL; return NULL;
} }
Status = MmRequestPageMemoryConsumer(MC_NPPOOL, FALSE, &Pfn); Status = MmRequestPageMemoryConsumer(MC_NPPOOL, FALSE, &Pfn);
if (!NT_SUCCESS(Status) || Pfn == 0) if (!NT_SUCCESS(Status) || Pfn == 0)
{ {
ASSERT(FALSE); ASSERT(FALSE);
} }
Entry = InterlockedCompareExchangeUL(PageDir, PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE | PA_USER, 0); Entry = InterlockedCompareExchangeUL(PageDir, PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE | PA_USER, 0);
if (Entry != 0) if (Entry != 0)
{ {
MmReleasePageMemoryConsumer(MC_NPPOOL, Pfn); MmReleasePageMemoryConsumer(MC_NPPOOL, Pfn);
} }
} }
} }
return (PULONG)ADDR_TO_PTE(Address); return (PULONG)ADDR_TO_PTE(Address);
@ -832,8 +832,8 @@ MmDisableVirtualMapping(PEPROCESS Process, PVOID Address, BOOLEAN* WasDirty, PPF
*/ */
do do
{ {
Pte = *Pt; Pte = *Pt;
tmpPte = Pte & ~PA_PRESENT; tmpPte = Pte & ~PA_PRESENT;
} while (Pte != ExfInterlockedCompareExchange64UL(Pt, &tmpPte, &Pte)); } while (Pte != ExfInterlockedCompareExchange64UL(Pt, &tmpPte, &Pte));
MiFlushTlb((PULONG)Pt, Address); MiFlushTlb((PULONG)Pt, Address);
@ -848,7 +848,7 @@ MmDisableVirtualMapping(PEPROCESS Process, PVOID Address, BOOLEAN* WasDirty, PPF
*/ */
if (WasDirty != NULL) if (WasDirty != NULL)
{ {
*WasDirty = Pte & PA_DIRTY ? TRUE : FALSE; *WasDirty = Pte & PA_DIRTY ? TRUE : FALSE;
} }
if (Page != NULL) if (Page != NULL)
{ {
@ -908,7 +908,7 @@ MmRawDeleteVirtualMapping(PVOID Address)
/* /*
* Set the entry to zero * Set the entry to zero
*/ */
(void)ExfpInterlockedExchange64UL(Pt, &ZeroPte); (void)ExfpInterlockedExchange64UL(Pt, &ZeroPte);
MiFlushTlb((PULONG)Pt, Address); MiFlushTlb((PULONG)Pt, Address);
} }
} }
@ -1249,7 +1249,7 @@ MmIsAccessedAndResetAccessPage(PEPROCESS Process, PVOID Address)
do do
{ {
Pte = *Pt; Pte = *Pt;
tmpPte = Pte & ~PA_ACCESSED; tmpPte = Pte & ~PA_ACCESSED;
} while (Pte != ExfInterlockedCompareExchange64UL(Pt, &tmpPte, &Pte)); } while (Pte != ExfInterlockedCompareExchange64UL(Pt, &tmpPte, &Pte));
if (Pte & PA_ACCESSED) if (Pte & PA_ACCESSED)
@ -1317,7 +1317,7 @@ MmSetCleanPage(PEPROCESS Process, PVOID Address)
do do
{ {
Pte = *Pt; Pte = *Pt;
tmpPte = Pte & ~PA_DIRTY; tmpPte = Pte & ~PA_DIRTY;
} while (Pte != ExfInterlockedCompareExchange64UL(Pt, &tmpPte, &Pte)); } while (Pte != ExfInterlockedCompareExchange64UL(Pt, &tmpPte, &Pte));
if (Pte & PA_DIRTY) if (Pte & PA_DIRTY)
@ -1381,7 +1381,7 @@ MmSetDirtyPage(PEPROCESS Process, PVOID Address)
do do
{ {
Pte = *Pt; Pte = *Pt;
tmpPte = Pte | PA_DIRTY; tmpPte = Pte | PA_DIRTY;
} while (Pte != ExfInterlockedCompareExchange64UL(Pt, &tmpPte, &Pte)); } while (Pte != ExfInterlockedCompareExchange64UL(Pt, &tmpPte, &Pte));
if (!(Pte & PA_DIRTY)) if (!(Pte & PA_DIRTY))
{ {
@ -1437,7 +1437,7 @@ MmEnableVirtualMapping(PEPROCESS Process, PVOID Address)
do do
{ {
Pte = *Pt; Pte = *Pt;
tmpPte = Pte | PA_PRESENT; tmpPte = Pte | PA_PRESENT;
} while (Pte != ExfInterlockedCompareExchange64UL(Pt, &tmpPte, &Pte)); } while (Pte != ExfInterlockedCompareExchange64UL(Pt, &tmpPte, &Pte));
if (!(Pte & PA_PRESENT)) if (!(Pte & PA_PRESENT))
{ {
@ -1511,7 +1511,7 @@ NTAPI
MmCreateVirtualMappingForKernel(PVOID Address, MmCreateVirtualMappingForKernel(PVOID Address,
ULONG flProtect, ULONG flProtect,
PPFN_NUMBER Pages, PPFN_NUMBER Pages,
ULONG PageCount) ULONG PageCount)
{ {
ULONG Attributes; ULONG Attributes;
ULONG i; ULONG i;
@ -1561,10 +1561,10 @@ MmCreateVirtualMappingForKernel(PVOID Address,
if (oldPdeOffset != PdeOffset) if (oldPdeOffset != PdeOffset)
{ {
Pt = MmGetPageTableForProcessForPAE(NULL, Addr, TRUE); Pt = MmGetPageTableForProcessForPAE(NULL, Addr, TRUE);
if (Pt == NULL) if (Pt == NULL)
{ {
ASSERT(FALSE); ASSERT(FALSE);
} }
} }
else else
{ {
@ -1572,11 +1572,11 @@ MmCreateVirtualMappingForKernel(PVOID Address,
} }
oldPdeOffset = PdeOffset; oldPdeOffset = PdeOffset;
Pte = PFN_TO_PTE(Pages[i]) | Attributes; Pte = PFN_TO_PTE(Pages[i]) | Attributes;
if (NoExecute) if (NoExecute)
{ {
Pte |= 0x8000000000000000LL; Pte |= 0x8000000000000000LL;
} }
Pte = ExfpInterlockedExchange64UL(Pt, &Pte); Pte = ExfpInterlockedExchange64UL(Pt, &Pte);
if (Pte != 0LL) if (Pte != 0LL)
{ {
@ -1611,10 +1611,10 @@ MmCreateVirtualMappingForKernel(PVOID Address,
if (oldPdeOffset != PdeOffset) if (oldPdeOffset != PdeOffset)
{ {
Pt = MmGetPageTableForProcess(NULL, Addr, TRUE); Pt = MmGetPageTableForProcess(NULL, Addr, TRUE);
if (Pt == NULL) if (Pt == NULL)
{ {
ASSERT(FALSE); ASSERT(FALSE);
} }
} }
else else
{ {
@ -1747,10 +1747,10 @@ MmCreateVirtualMappingUnsafe(PEPROCESS Process,
ASSERT(FALSE); ASSERT(FALSE);
} }
if (PageCount > 0x10000 || if (PageCount > 0x10000 ||
(ULONG_PTR) Address / PAGE_SIZE + PageCount > 0x100000) (ULONG_PTR) Address / PAGE_SIZE + PageCount > 0x100000)
{ {
DPRINT1("Page count to large\n"); DPRINT1("Page count to large\n");
ASSERT(FALSE); ASSERT(FALSE);
} }
} }
else else
@ -1761,11 +1761,11 @@ MmCreateVirtualMappingUnsafe(PEPROCESS Process,
ASSERT(FALSE); ASSERT(FALSE);
} }
if (PageCount > (ULONG_PTR)MmSystemRangeStart / PAGE_SIZE || if (PageCount > (ULONG_PTR)MmSystemRangeStart / PAGE_SIZE ||
(ULONG_PTR) Address / PAGE_SIZE + PageCount > (ULONG_PTR) Address / PAGE_SIZE + PageCount >
(ULONG_PTR)MmSystemRangeStart / PAGE_SIZE) (ULONG_PTR)MmSystemRangeStart / PAGE_SIZE)
{ {
DPRINT1("Page Count to large\n"); DPRINT1("Page Count to large\n");
ASSERT(FALSE); ASSERT(FALSE);
} }
} }
@ -1780,7 +1780,7 @@ MmCreateVirtualMappingUnsafe(PEPROCESS Process,
Attributes &= ~PA_USER; Attributes &= ~PA_USER;
if (Ke386GlobalPagesEnabled) if (Ke386GlobalPagesEnabled)
{ {
Attributes |= PA_GLOBAL; Attributes |= PA_GLOBAL;
} }
} }
else else
@ -1809,11 +1809,11 @@ MmCreateVirtualMappingUnsafe(PEPROCESS Process,
if (oldPdeOffset != PdeOffset) if (oldPdeOffset != PdeOffset)
{ {
MmUnmapPageTable((PULONG)Pt); MmUnmapPageTable((PULONG)Pt);
Pt = MmGetPageTableForProcessForPAE(Process, Addr, TRUE); Pt = MmGetPageTableForProcessForPAE(Process, Addr, TRUE);
if (Pt == NULL) if (Pt == NULL)
{ {
ASSERT(FALSE); ASSERT(FALSE);
} }
} }
else else
{ {
@ -1822,11 +1822,11 @@ MmCreateVirtualMappingUnsafe(PEPROCESS Process,
oldPdeOffset = PdeOffset; oldPdeOffset = PdeOffset;
MmMarkPageMapped(Pages[i]); MmMarkPageMapped(Pages[i]);
tmpPte = PAE_PFN_TO_PTE(Pages[i]) | Attributes; tmpPte = PAE_PFN_TO_PTE(Pages[i]) | Attributes;
if (NoExecute) if (NoExecute)
{ {
tmpPte |= 0x8000000000000000LL; tmpPte |= 0x8000000000000000LL;
} }
Pte = ExfpInterlockedExchange64UL(Pt, &tmpPte); Pte = ExfpInterlockedExchange64UL(Pt, &tmpPte);
if (PAE_PAGE_MASK((Pte)) != 0LL && !((Pte) & PA_PRESENT)) if (PAE_PAGE_MASK((Pte)) != 0LL && !((Pte) & PA_PRESENT))
{ {
@ -1837,7 +1837,7 @@ MmCreateVirtualMappingUnsafe(PEPROCESS Process,
MmMarkPageUnmapped(PAE_PTE_TO_PFN((Pte))); MmMarkPageUnmapped(PAE_PTE_TO_PFN((Pte)));
} }
if (Address < MmSystemRangeStart && if (Address < MmSystemRangeStart &&
((PMADDRESS_SPACE)&Process->VadRoot)->PageTableRefCountTable != NULL && ((PMADDRESS_SPACE)&Process->VadRoot)->PageTableRefCountTable != NULL &&
Attributes & PA_PRESENT) Attributes & PA_PRESENT)
{ {
PUSHORT Ptrc; PUSHORT Ptrc;
@ -1878,11 +1878,11 @@ MmCreateVirtualMappingUnsafe(PEPROCESS Process,
if (oldPdeOffset != PdeOffset) if (oldPdeOffset != PdeOffset)
{ {
MmUnmapPageTable(Pt); MmUnmapPageTable(Pt);
Pt = MmGetPageTableForProcess(Process, Addr, TRUE); Pt = MmGetPageTableForProcess(Process, Addr, TRUE);
if (Pt == NULL) if (Pt == NULL)
{ {
ASSERT(FALSE); ASSERT(FALSE);
} }
} }
else else
{ {
@ -1900,9 +1900,9 @@ MmCreateVirtualMappingUnsafe(PEPROCESS Process,
{ {
MmMarkPageUnmapped(PTE_TO_PFN((Pte))); MmMarkPageUnmapped(PTE_TO_PFN((Pte)));
} }
(void)InterlockedExchangeUL(Pt, PFN_TO_PTE(Pages[i]) | Attributes); (void)InterlockedExchangeUL(Pt, PFN_TO_PTE(Pages[i]) | Attributes);
if (Address < MmSystemRangeStart && if (Address < MmSystemRangeStart &&
((PMADDRESS_SPACE)&Process->VadRoot)->PageTableRefCountTable != NULL && ((PMADDRESS_SPACE)&Process->VadRoot)->PageTableRefCountTable != NULL &&
Attributes & PA_PRESENT) Attributes & PA_PRESENT)
{ {
PUSHORT Ptrc; PUSHORT Ptrc;
@ -2021,7 +2021,7 @@ MmSetPageProtect(PEPROCESS Process, PVOID Address, ULONG flProtect)
Attributes &= ~PA_USER; Attributes &= ~PA_USER;
if (Ke386GlobalPagesEnabled) if (Ke386GlobalPagesEnabled)
{ {
Attributes |= PA_GLOBAL; Attributes |= PA_GLOBAL;
} }
} }
else else
@ -2042,15 +2042,15 @@ MmSetPageProtect(PEPROCESS Process, PVOID Address, ULONG flProtect)
do do
{ {
Pte = *Pt; Pte = *Pt;
tmpPte = PAE_PAGE_MASK(Pte) | Attributes | (Pte & (PA_ACCESSED|PA_DIRTY)); tmpPte = PAE_PAGE_MASK(Pte) | Attributes | (Pte & (PA_ACCESSED|PA_DIRTY));
if (NoExecute) if (NoExecute)
{ {
tmpPte |= 0x8000000000000000LL; tmpPte |= 0x8000000000000000LL;
} }
else else
{ {
tmpPte &= ~0x8000000000000000LL; tmpPte &= ~0x8000000000000000LL;
} }
} while (Pte != ExfInterlockedCompareExchange64UL(Pt, &tmpPte, &Pte)); } while (Pte != ExfInterlockedCompareExchange64UL(Pt, &tmpPte, &Pte));
MiFlushTlb((PULONG)Pt, Address); MiFlushTlb((PULONG)Pt, Address);
@ -2133,24 +2133,24 @@ MmCreateHyperspaceMapping(PFN_NUMBER Page)
for (i = Page %1024; i < 1024; i++, Pte++) for (i = Page %1024; i < 1024; i++, Pte++)
{ {
if (0LL == ExfInterlockedCompareExchange64UL(Pte, &Entry, &ZeroEntry)) if (0LL == ExfInterlockedCompareExchange64UL(Pte, &Entry, &ZeroEntry))
{ {
break; break;
} }
} }
if (i >= 1024) if (i >= 1024)
{ {
Pte = PAE_ADDR_TO_PTE(HYPERSPACE); Pte = PAE_ADDR_TO_PTE(HYPERSPACE);
for (i = 0; i < Page % 1024; i++, Pte++) for (i = 0; i < Page % 1024; i++, Pte++)
{ {
if (0LL == ExfInterlockedCompareExchange64UL(Pte, &Entry, &ZeroEntry)) if (0LL == ExfInterlockedCompareExchange64UL(Pte, &Entry, &ZeroEntry))
{ {
break; break;
} }
} }
if (i >= Page % 1024) if (i >= Page % 1024)
{ {
ASSERT(FALSE); ASSERT(FALSE);
} }
} }
} }
else else
@ -2158,24 +2158,24 @@ MmCreateHyperspaceMapping(PFN_NUMBER Page)
for (i = Page %1024; (LONG)i >= 0; i--, Pte--) for (i = Page %1024; (LONG)i >= 0; i--, Pte--)
{ {
if (0LL == ExfInterlockedCompareExchange64UL(Pte, &Entry, &ZeroEntry)) if (0LL == ExfInterlockedCompareExchange64UL(Pte, &Entry, &ZeroEntry))
{ {
break; break;
} }
} }
if ((LONG)i < 0) if ((LONG)i < 0)
{ {
Pte = PAE_ADDR_TO_PTE(HYPERSPACE) + 1023; Pte = PAE_ADDR_TO_PTE(HYPERSPACE) + 1023;
for (i = 1023; i > Page % 1024; i--, Pte--) for (i = 1023; i > Page % 1024; i--, Pte--)
{ {
if (0LL == ExfInterlockedCompareExchange64UL(Pte, &Entry, &ZeroEntry)) if (0LL == ExfInterlockedCompareExchange64UL(Pte, &Entry, &ZeroEntry))
{ {
break; break;
} }
} }
if (i <= Page % 1024) if (i <= Page % 1024)
{ {
ASSERT(FALSE); ASSERT(FALSE);
} }
} }
} }
} }
@ -2305,27 +2305,27 @@ MmUpdatePageDir(PEPROCESS Process, PVOID Address, ULONG Size)
for (i = PAE_ADDR_TO_PDTE_OFFSET(Address); i <= PAE_ADDR_TO_PDTE_OFFSET((PVOID)((ULONG_PTR)Address + Size)); i++) for (i = PAE_ADDR_TO_PDTE_OFFSET(Address); i <= PAE_ADDR_TO_PDTE_OFFSET((PVOID)((ULONG_PTR)Address + Size)); i++)
{ {
if (i == PAE_ADDR_TO_PDTE_OFFSET(Address)) if (i == PAE_ADDR_TO_PDTE_OFFSET(Address))
{ {
StartOffset = PAE_ADDR_TO_PDE_PAGE_OFFSET(Address); StartOffset = PAE_ADDR_TO_PDE_PAGE_OFFSET(Address);
} }
else else
{ {
StartOffset = 0; StartOffset = 0;
} }
if (i == PAE_ADDR_TO_PDTE_OFFSET((PVOID)((ULONG_PTR)Address + Size))) if (i == PAE_ADDR_TO_PDTE_OFFSET((PVOID)((ULONG_PTR)Address + Size)))
{ {
EndOffset = PAE_ADDR_TO_PDE_PAGE_OFFSET((PVOID)((ULONG_PTR)Address + Size)); EndOffset = PAE_ADDR_TO_PDE_PAGE_OFFSET((PVOID)((ULONG_PTR)Address + Size));
} }
else else
{ {
EndOffset = 511; EndOffset = 511;
} }
if (Process != NULL && Process != PsGetCurrentProcess()) if (Process != NULL && Process != PsGetCurrentProcess())
{ {
PageDirTable = MmCreateHyperspaceMapping(PAE_PTE_TO_PFN(Process->Pcb.DirectoryTableBase.QuadPart)); PageDirTable = MmCreateHyperspaceMapping(PAE_PTE_TO_PFN(Process->Pcb.DirectoryTableBase.QuadPart));
Pde = (PULONGLONG)MmCreateHyperspaceMapping(PTE_TO_PFN(PageDirTable[i])); Pde = (PULONGLONG)MmCreateHyperspaceMapping(PTE_TO_PFN(PageDirTable[i]));
MmDeleteHyperspaceMapping(PageDirTable); MmDeleteHyperspaceMapping(PageDirTable);
} }
else else
{ {
@ -2385,16 +2385,16 @@ MmInitGlobalKernelPageDirectory(VOID)
for (i = PAE_ADDR_TO_PDE_OFFSET(MmSystemRangeStart); i < 4 * 512; i++) for (i = PAE_ADDR_TO_PDE_OFFSET(MmSystemRangeStart); i < 4 * 512; i++)
{ {
if (!(i >= PAE_ADDR_TO_PDE_OFFSET(PAGETABLE_MAP) && i < PAE_ADDR_TO_PDE_OFFSET(PAGETABLE_MAP) + 4) && if (!(i >= PAE_ADDR_TO_PDE_OFFSET(PAGETABLE_MAP) && i < PAE_ADDR_TO_PDE_OFFSET(PAGETABLE_MAP) + 4) &&
!(i >= PAE_ADDR_TO_PDE_OFFSET(HYPERSPACE) && i < PAE_ADDR_TO_PDE_OFFSET(HYPERSPACE) + 2) && !(i >= PAE_ADDR_TO_PDE_OFFSET(HYPERSPACE) && i < PAE_ADDR_TO_PDE_OFFSET(HYPERSPACE) + 2) &&
0LL == MmGlobalKernelPageDirectoryForPAE[i] && 0LL != CurrentPageDirectory[i]) 0LL == MmGlobalKernelPageDirectoryForPAE[i] && 0LL != CurrentPageDirectory[i])
{ {
(void)ExfpInterlockedExchange64UL(&MmGlobalKernelPageDirectoryForPAE[i], &CurrentPageDirectory[i]); (void)ExfpInterlockedExchange64UL(&MmGlobalKernelPageDirectoryForPAE[i], &CurrentPageDirectory[i]);
if (Ke386GlobalPagesEnabled) if (Ke386GlobalPagesEnabled)
{ {
MmGlobalKernelPageDirectoryForPAE[i] |= PA_GLOBAL; MmGlobalKernelPageDirectoryForPAE[i] |= PA_GLOBAL;
CurrentPageDirectory[i] |= PA_GLOBAL; CurrentPageDirectory[i] |= PA_GLOBAL;
} }
} }
} }
} }
else else
@ -2403,15 +2403,15 @@ MmInitGlobalKernelPageDirectory(VOID)
for (i = ADDR_TO_PDE_OFFSET(MmSystemRangeStart); i < 1024; i++) for (i = ADDR_TO_PDE_OFFSET(MmSystemRangeStart); i < 1024; i++)
{ {
if (i != ADDR_TO_PDE_OFFSET(PAGETABLE_MAP) && if (i != ADDR_TO_PDE_OFFSET(PAGETABLE_MAP) &&
i != ADDR_TO_PDE_OFFSET(HYPERSPACE) && i != ADDR_TO_PDE_OFFSET(HYPERSPACE) &&
0 == MmGlobalKernelPageDirectory[i] && 0 != CurrentPageDirectory[i]) 0 == MmGlobalKernelPageDirectory[i] && 0 != CurrentPageDirectory[i])
{ {
MmGlobalKernelPageDirectory[i] = CurrentPageDirectory[i]; MmGlobalKernelPageDirectory[i] = CurrentPageDirectory[i];
if (Ke386GlobalPagesEnabled) if (Ke386GlobalPagesEnabled)
{ {
MmGlobalKernelPageDirectory[i] |= PA_GLOBAL; MmGlobalKernelPageDirectory[i] |= PA_GLOBAL;
CurrentPageDirectory[i] |= PA_GLOBAL; CurrentPageDirectory[i] |= PA_GLOBAL;
} }
} }
} }
} }
@ -2442,7 +2442,7 @@ MiInitPageDirectoryMap(VOID)
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(), Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM, MEMORY_AREA_SYSTEM,
&BaseAddress, &BaseAddress,
Ke386Pae ? 0x800000 : 0x400000, Ke386Pae ? 0x800000 : 0x400000,
PAGE_READWRITE, PAGE_READWRITE,
&kernel_map_desc, &kernel_map_desc,
TRUE, TRUE,
@ -2456,7 +2456,7 @@ MiInitPageDirectoryMap(VOID)
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(), Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM, MEMORY_AREA_SYSTEM,
&BaseAddress, &BaseAddress,
0x400000, 0x400000,
PAGE_READWRITE, PAGE_READWRITE,
&hyperspace_desc, &hyperspace_desc,
TRUE, TRUE,

View file

@ -87,15 +87,15 @@ MmpAccessFault(KPROCESSOR_MODE Mode,
break; break;
#ifdef NEWCC #ifdef NEWCC
case MEMORY_AREA_CACHE: case MEMORY_AREA_CACHE:
// This code locks for itself to keep from having to break a lock // This code locks for itself to keep from having to break a lock
// passed in. // passed in.
if (!FromMdl) if (!FromMdl)
MmUnlockAddressSpace(AddressSpace); MmUnlockAddressSpace(AddressSpace);
Status = MmAccessFaultCacheSection(Mode, Address, Locked); Status = MmAccessFaultCacheSection(Mode, Address, Locked);
if (!FromMdl) if (!FromMdl)
MmLockAddressSpace(AddressSpace); MmLockAddressSpace(AddressSpace);
break; break;
#endif #endif
default: default:
@ -141,7 +141,7 @@ MmNotPresentFault(KPROCESSOR_MODE Mode,
*/ */
if (Mode != KernelMode) if (Mode != KernelMode)
{ {
DPRINT1("Address: %x\n", Address); DPRINT1("Address: %x\n", Address);
return(STATUS_ACCESS_VIOLATION); return(STATUS_ACCESS_VIOLATION);
} }
AddressSpace = MmGetKernelAddressSpace(); AddressSpace = MmGetKernelAddressSpace();
@ -186,15 +186,15 @@ MmNotPresentFault(KPROCESSOR_MODE Mode,
break; break;
#ifdef NEWCC #ifdef NEWCC
case MEMORY_AREA_CACHE: case MEMORY_AREA_CACHE:
// This code locks for itself to keep from having to break a lock // This code locks for itself to keep from having to break a lock
// passed in. // passed in.
if (!FromMdl) if (!FromMdl)
MmUnlockAddressSpace(AddressSpace); MmUnlockAddressSpace(AddressSpace);
Status = MmNotPresentFaultCacheSection(Mode, Address, Locked); Status = MmNotPresentFaultCacheSection(Mode, Address, Locked);
if (!FromMdl) if (!FromMdl)
MmLockAddressSpace(AddressSpace); MmLockAddressSpace(AddressSpace);
break; break;
#endif #endif
default: default:

View file

@ -304,8 +304,8 @@ MmMpwThreadMain(PVOID Ignored)
PagesWritten = 0; PagesWritten = 0;
#ifndef NEWCC #ifndef NEWCC
// XXX arty -- we flush when evicting pages or destorying cache // XXX arty -- we flush when evicting pages or destorying cache
// sections. // sections.
CcRosFlushDirtyPages(128, &PagesWritten, FALSE); CcRosFlushDirtyPages(128, &PagesWritten, FALSE);
#endif #endif
} }

View file

@ -429,8 +429,8 @@ MmFreeSwapPage(SWAPENTRY Entry)
if (i >= MAX_PAGING_FILES) if (i >= MAX_PAGING_FILES)
{ {
DPRINT1("Bad swap entry 0x%.8X\n", Entry); DPRINT1("Bad swap entry 0x%.8X\n", Entry);
KeBugCheck(MEMORY_MANAGEMENT); KeBugCheck(MEMORY_MANAGEMENT);
} }
KeAcquireSpinLock(&PagingFileListLock, &oldIrql); KeAcquireSpinLock(&PagingFileListLock, &oldIrql);

View file

@ -32,8 +32,8 @@
#define PA_CD 0x10 #define PA_CD 0x10
#define PA_READWRITE 3 #define PA_READWRITE 3
#define HYPERSPACE (0xc0400000) #define HYPERSPACE (0xc0400000)
#define IS_HYPERSPACE(v) (((ULONG)(v) >= HYPERSPACE && (ULONG)(v) < HYPERSPACE + 0x400000)) #define IS_HYPERSPACE(v) (((ULONG)(v) >= HYPERSPACE && (ULONG)(v) < HYPERSPACE + 0x400000))
#define PTE_TO_PFN(X) ((X) >> PAGE_SHIFT) #define PTE_TO_PFN(X) ((X) >> PAGE_SHIFT)
#define PFN_TO_PTE(X) ((X) << PAGE_SHIFT) #define PFN_TO_PTE(X) ((X) << PAGE_SHIFT)
@ -229,7 +229,7 @@ MmDeleteVirtualMapping(PEPROCESS Process, PVOID Address, BOOLEAN FreePage,
ppc_map_info_t info = { 0 }; ppc_map_info_t info = { 0 };
DPRINT("MmDeleteVirtualMapping(%x, %x, %d, %x, %x)\n", DPRINT("MmDeleteVirtualMapping(%x, %x, %d, %x, %x)\n",
Process, Address, FreePage, WasDirty, Page); Process, Address, FreePage, WasDirty, Page);
info.proc = Process ? (int)Process->UniqueProcessId : 0; info.proc = Process ? (int)Process->UniqueProcessId : 0;
info.addr = (vaddr_t)Address; info.addr = (vaddr_t)Address;
@ -237,7 +237,7 @@ MmDeleteVirtualMapping(PEPROCESS Process, PVOID Address, BOOLEAN FreePage,
if (FreePage && info.phys) if (FreePage && info.phys)
{ {
MmReleasePageMemoryConsumer(MC_NPPOOL, info.phys >> PAGE_SHIFT); MmReleasePageMemoryConsumer(MC_NPPOOL, info.phys >> PAGE_SHIFT);
} }
/* /*
@ -245,11 +245,11 @@ MmDeleteVirtualMapping(PEPROCESS Process, PVOID Address, BOOLEAN FreePage,
*/ */
if (WasDirty != NULL) if (WasDirty != NULL)
{ {
*WasDirty = !!(info.flags & MMU_PAGE_DIRTY); *WasDirty = !!(info.flags & MMU_PAGE_DIRTY);
} }
if (Page != NULL) if (Page != NULL)
{ {
*Page = info.phys >> PAGE_SHIFT; *Page = info.phys >> PAGE_SHIFT;
} }
} }
@ -266,13 +266,13 @@ MmDeletePageFileMapping(PEPROCESS Process, PVOID Address,
* Decrement the reference count for this page table. * Decrement the reference count for this page table.
*/ */
if (Process != NULL && if (Process != NULL &&
((PMADDRESS_SPACE)&Process->VadRoot)->PageTableRefCountTable != NULL && ((PMADDRESS_SPACE)&Process->VadRoot)->PageTableRefCountTable != NULL &&
Address < MmSystemRangeStart) Address < MmSystemRangeStart)
{ {
PUSHORT Ptrc; PUSHORT Ptrc;
Ptrc = ((PMADDRESS_SPACE)&Process->VadRoot)->PageTableRefCountTable; Ptrc = ((PMADDRESS_SPACE)&Process->VadRoot)->PageTableRefCountTable;
MmFreePageTable(Process, Address); MmFreePageTable(Process, Address);
} }
/* /*
@ -301,8 +301,8 @@ MmIsAccessedAndResetAccessPage(PEPROCESS Process, PVOID Address)
if (Address < MmSystemRangeStart && Process == NULL) if (Address < MmSystemRangeStart && Process == NULL)
{ {
DPRINT1("MmIsAccessedAndResetAccessPage is called for user space without a process.\n"); DPRINT1("MmIsAccessedAndResetAccessPage is called for user space without a process.\n");
ASSERT(FALSE); ASSERT(FALSE);
} }
info.proc = Process ? (int)Process->UniqueProcessId : 0; info.proc = Process ? (int)Process->UniqueProcessId : 0;
@ -359,7 +359,7 @@ NTAPI
MmCreateVirtualMappingForKernel(PVOID Address, MmCreateVirtualMappingForKernel(PVOID Address,
ULONG flProtect, ULONG flProtect,
PPFN_NUMBER Pages, PPFN_NUMBER Pages,
ULONG PageCount) ULONG PageCount)
{ {
ULONG i; ULONG i;
PVOID Addr; PVOID Addr;
@ -369,8 +369,8 @@ MmCreateVirtualMappingForKernel(PVOID Address,
if (Address < MmSystemRangeStart) if (Address < MmSystemRangeStart)
{ {
DPRINT1("MmCreateVirtualMappingForKernel is called for user space\n"); DPRINT1("MmCreateVirtualMappingForKernel is called for user space\n");
ASSERT(FALSE); ASSERT(FALSE);
} }
Addr = Address; Addr = Address;
@ -378,14 +378,14 @@ MmCreateVirtualMappingForKernel(PVOID Address,
for (i = 0; i < PageCount; i++, Addr = (PVOID)((ULONG_PTR)Addr + PAGE_SIZE)) for (i = 0; i < PageCount; i++, Addr = (PVOID)((ULONG_PTR)Addr + PAGE_SIZE))
{ {
#if 0 #if 0
if (!(Attributes & PA_PRESENT) && Pages[i] != 0) if (!(Attributes & PA_PRESENT) && Pages[i] != 0)
{ {
DPRINT1("Setting physical address but not allowing access at address " DPRINT1("Setting physical address but not allowing access at address "
"0x%.8X with attributes %x/%x.\n", "0x%.8X with attributes %x/%x.\n",
Addr, Attributes, flProtect); Addr, Attributes, flProtect);
ASSERT(FALSE); ASSERT(FALSE);
} }
(void)InterlockedExchangeUL(Pt, PFN_TO_PTE(Pages[i]) | Attributes); (void)InterlockedExchangeUL(Pt, PFN_TO_PTE(Pages[i]) | Attributes);
#endif #endif
} }
@ -400,17 +400,17 @@ MmCreatePageFileMapping(PEPROCESS Process,
{ {
if (Process == NULL && Address < MmSystemRangeStart) if (Process == NULL && Address < MmSystemRangeStart)
{ {
DPRINT1("No process\n"); DPRINT1("No process\n");
ASSERT(FALSE); ASSERT(FALSE);
} }
if (Process != NULL && Address >= MmSystemRangeStart) if (Process != NULL && Address >= MmSystemRangeStart)
{ {
DPRINT1("Setting kernel address with process context\n"); DPRINT1("Setting kernel address with process context\n");
ASSERT(FALSE); ASSERT(FALSE);
} }
if (SwapEntry & (1 << 31)) if (SwapEntry & (1 << 31))
{ {
ASSERT(FALSE); ASSERT(FALSE);
} }
// XXX arty // XXX arty
@ -433,36 +433,36 @@ MmCreateVirtualMappingUnsafe(PEPROCESS Process,
ppc_map_info_t info = { 0 }; ppc_map_info_t info = { 0 };
DPRINT("MmCreateVirtualMappingUnsafe(%x, %x, %x, %x (%x), %d)\n", DPRINT("MmCreateVirtualMappingUnsafe(%x, %x, %x, %x (%x), %d)\n",
Process, Address, flProtect, Pages, *Pages, PageCount); Process, Address, flProtect, Pages, *Pages, PageCount);
if (Process == NULL) if (Process == NULL)
{ {
if (Address < MmSystemRangeStart) if (Address < MmSystemRangeStart)
{ {
DPRINT1("No process\n"); DPRINT1("No process\n");
ASSERT(FALSE); ASSERT(FALSE);
} }
if (PageCount > 0x10000 || if (PageCount > 0x10000 ||
(ULONG_PTR) Address / PAGE_SIZE + PageCount > 0x100000) (ULONG_PTR) Address / PAGE_SIZE + PageCount > 0x100000)
{ {
DPRINT1("Page count to large\n"); DPRINT1("Page count to large\n");
ASSERT(FALSE); ASSERT(FALSE);
} }
} }
else else
{ {
if (Address >= MmSystemRangeStart) if (Address >= MmSystemRangeStart)
{ {
DPRINT1("Setting kernel address with process context\n"); DPRINT1("Setting kernel address with process context\n");
ASSERT(FALSE); ASSERT(FALSE);
} }
if (PageCount > (ULONG_PTR)MmSystemRangeStart / PAGE_SIZE || if (PageCount > (ULONG_PTR)MmSystemRangeStart / PAGE_SIZE ||
(ULONG_PTR) Address / PAGE_SIZE + PageCount > (ULONG_PTR) Address / PAGE_SIZE + PageCount >
(ULONG_PTR)MmSystemRangeStart / PAGE_SIZE) (ULONG_PTR)MmSystemRangeStart / PAGE_SIZE)
{ {
DPRINT1("Page Count to large\n"); DPRINT1("Page Count to large\n");
ASSERT(FALSE); ASSERT(FALSE);
} }
} }
Attributes = ProtectToFlags(flProtect); Attributes = ProtectToFlags(flProtect);
@ -470,17 +470,17 @@ MmCreateVirtualMappingUnsafe(PEPROCESS Process,
for (i = 0; i < PageCount; i++, Addr = (PVOID)((ULONG_PTR)Addr + PAGE_SIZE)) for (i = 0; i < PageCount; i++, Addr = (PVOID)((ULONG_PTR)Addr + PAGE_SIZE))
{ {
Process = PsGetCurrentProcess(); Process = PsGetCurrentProcess();
info.proc = ((Addr < MmSystemRangeStart) && Process) ? info.proc = ((Addr < MmSystemRangeStart) && Process) ?
(int)Process->UniqueProcessId : 0; (int)Process->UniqueProcessId : 0;
info.addr = (vaddr_t)Addr; info.addr = (vaddr_t)Addr;
info.flags = Attributes; info.flags = Attributes;
MmuMapPage(&info, 1); MmuMapPage(&info, 1);
//(void)InterlockedExchangeUL(Pt, PFN_TO_PTE(Pages[i]) | Attributes); //(void)InterlockedExchangeUL(Pt, PFN_TO_PTE(Pages[i]) | Attributes);
if (Address < MmSystemRangeStart && if (Address < MmSystemRangeStart &&
((PMADDRESS_SPACE)&Process->VadRoot)->PageTableRefCountTable != NULL && ((PMADDRESS_SPACE)&Process->VadRoot)->PageTableRefCountTable != NULL &&
Attributes & PA_PRESENT) Attributes & PA_PRESENT)
{ {
#if 0 #if 0
PUSHORT Ptrc; PUSHORT Ptrc;
@ -488,7 +488,7 @@ MmCreateVirtualMappingUnsafe(PEPROCESS Process,
Ptrc[ADDR_TO_PAGE_TABLE(Addr)]++; Ptrc[ADDR_TO_PAGE_TABLE(Addr)]++;
#endif #endif
} }
} }
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
@ -533,18 +533,18 @@ MmGetPageProtect(PEPROCESS Process, PVOID Address)
if (!info.phys) { return PAGE_NOACCESS; } if (!info.phys) { return PAGE_NOACCESS; }
if (!(info.flags & MMU_KMASK)) if (!(info.flags & MMU_KMASK))
{ {
Protect |= PAGE_SYSTEM; Protect |= PAGE_SYSTEM;
if ((info.flags & MMU_KR) && (info.flags & MMU_KW)) if ((info.flags & MMU_KR) && (info.flags & MMU_KW))
Protect = PAGE_READWRITE; Protect = PAGE_READWRITE;
else if (info.flags & MMU_KR) else if (info.flags & MMU_KR)
Protect = PAGE_EXECUTE_READ; Protect = PAGE_EXECUTE_READ;
} }
else else
{ {
if ((info.flags & MMU_UR) && (info.flags & MMU_UW)) if ((info.flags & MMU_UR) && (info.flags & MMU_UW))
Protect = PAGE_READWRITE; Protect = PAGE_READWRITE;
else else
Protect = PAGE_EXECUTE_READ; Protect = PAGE_EXECUTE_READ;
} }
return(Protect); return(Protect);
} }

View file

@ -60,9 +60,9 @@ void KiPageFaultHandler(int trap, ppc_trap_frame_t *frame)
/* get the faulting address */ /* get the faulting address */
if (trap == 4) /* Instruction miss */ if (trap == 4) /* Instruction miss */
VirtualAddr = frame->srr0; VirtualAddr = frame->srr0;
else /* Data miss */ else /* Data miss */
VirtualAddr = frame->dar; VirtualAddr = frame->dar;
/* MSR_PR */ /* MSR_PR */
Mode = frame->srr1 & 0x4000 ? UserMode : KernelMode; Mode = frame->srr1 & 0x4000 ? UserMode : KernelMode;
@ -71,11 +71,11 @@ void KiPageFaultHandler(int trap, ppc_trap_frame_t *frame)
/* handle the fault */ /* handle the fault */
if (AccessFault) if (AccessFault)
{ {
Status = MmAccessFault(Mode, (PVOID)VirtualAddr, FALSE, TrapInfo); Status = MmAccessFault(Mode, (PVOID)VirtualAddr, FALSE, TrapInfo);
} }
else else
{ {
Status = MmNotPresentFault(Mode, VirtualAddr, FALSE); Status = MmNotPresentFault(Mode, VirtualAddr, FALSE);
} }
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))

View file

@ -198,10 +198,10 @@ MmSetCleanAllRmaps(PFN_NUMBER Page)
while (current_entry != NULL) while (current_entry != NULL)
{ {
#ifdef NEWCC #ifdef NEWCC
if (!RMAP_IS_SEGMENT(current_entry->Address)) if (!RMAP_IS_SEGMENT(current_entry->Address))
#endif #endif
MmSetCleanPage(current_entry->Process, current_entry->Address); MmSetCleanPage(current_entry->Process, current_entry->Address);
current_entry = current_entry->Next; current_entry = current_entry->Next;
} }
ExReleaseFastMutex(&RmapListLock); ExReleaseFastMutex(&RmapListLock);
} }
@ -222,9 +222,9 @@ MmSetDirtyAllRmaps(PFN_NUMBER Page)
while (current_entry != NULL) while (current_entry != NULL)
{ {
#ifdef NEWCC #ifdef NEWCC
if (!RMAP_IS_SEGMENT(current_entry->Address)) if (!RMAP_IS_SEGMENT(current_entry->Address))
#endif #endif
MmSetDirtyPage(current_entry->Process, current_entry->Address); MmSetDirtyPage(current_entry->Process, current_entry->Address);
current_entry = current_entry->Next; current_entry = current_entry->Next;
} }
ExReleaseFastMutex(&RmapListLock); ExReleaseFastMutex(&RmapListLock);
@ -245,11 +245,11 @@ MmIsDirtyPageRmap(PFN_NUMBER Page)
} }
while (current_entry != NULL) while (current_entry != NULL)
{ {
if ( if (
#ifdef NEWCC #ifdef NEWCC
!RMAP_IS_SEGMENT(current_entry->Address) && !RMAP_IS_SEGMENT(current_entry->Address) &&
#endif #endif
MmIsDirtyPage(current_entry->Process, current_entry->Address)) MmIsDirtyPage(current_entry->Process, current_entry->Address))
{ {
ExReleaseFastMutex(&RmapListLock); ExReleaseFastMutex(&RmapListLock);
return(TRUE); return(TRUE);
@ -271,7 +271,7 @@ MmInsertRmap(PFN_NUMBER Page, PEPROCESS Process,
#ifdef NEWCC #ifdef NEWCC
if (!RMAP_IS_SEGMENT(Address)) if (!RMAP_IS_SEGMENT(Address))
#endif #endif
Address = (PVOID)PAGE_ROUND_DOWN(Address); Address = (PVOID)PAGE_ROUND_DOWN(Address);
new_entry = ExAllocateFromNPagedLookasideList(&RmapLookasideList); new_entry = ExAllocateFromNPagedLookasideList(&RmapLookasideList);
if (new_entry == NULL) if (new_entry == NULL)
@ -292,7 +292,7 @@ MmInsertRmap(PFN_NUMBER Page, PEPROCESS Process,
#ifdef NEWCC #ifdef NEWCC
!RMAP_IS_SEGMENT(Address) && !RMAP_IS_SEGMENT(Address) &&
#endif #endif
MmGetPfnForProcess(Process, Address) != Page) MmGetPfnForProcess(Process, Address) != Page)
{ {
DPRINT1("Insert rmap (%d, 0x%.8X) 0x%.8X which doesn't match physical " DPRINT1("Insert rmap (%d, 0x%.8X) 0x%.8X which doesn't match physical "
"address 0x%.8X\n", Process->UniqueProcessId, Address, "address 0x%.8X\n", Process->UniqueProcessId, Address,
@ -326,18 +326,18 @@ MmInsertRmap(PFN_NUMBER Page, PEPROCESS Process,
if (!RMAP_IS_SEGMENT(Address)) if (!RMAP_IS_SEGMENT(Address))
#endif #endif
{ {
if (Process == NULL) if (Process == NULL)
{ {
Process = PsInitialSystemProcess; Process = PsInitialSystemProcess;
} }
if (Process) if (Process)
{ {
PrevSize = InterlockedExchangeAddUL(&Process->Vm.WorkingSetSize, PAGE_SIZE); PrevSize = InterlockedExchangeAddUL(&Process->Vm.WorkingSetSize, PAGE_SIZE);
if (PrevSize >= Process->Vm.PeakWorkingSetSize) if (PrevSize >= Process->Vm.PeakWorkingSetSize)
{ {
Process->Vm.PeakWorkingSetSize = PrevSize + PAGE_SIZE; Process->Vm.PeakWorkingSetSize = PrevSize + PAGE_SIZE;
} }
} }
} }
} }
@ -365,30 +365,30 @@ MmDeleteAllRmaps(PFN_NUMBER Page, PVOID Context,
previous_entry = current_entry; previous_entry = current_entry;
current_entry = current_entry->Next; current_entry = current_entry->Next;
#ifdef NEWCC #ifdef NEWCC
if (!RMAP_IS_SEGMENT(previous_entry->Address)) if (!RMAP_IS_SEGMENT(previous_entry->Address))
#endif #endif
{ {
if (DeleteMapping) if (DeleteMapping)
{ {
DeleteMapping(Context, previous_entry->Process, DeleteMapping(Context, previous_entry->Process,
previous_entry->Address); previous_entry->Address);
} }
Process = previous_entry->Process; Process = previous_entry->Process;
ExFreeToNPagedLookasideList(&RmapLookasideList, previous_entry); ExFreeToNPagedLookasideList(&RmapLookasideList, previous_entry);
if (Process == NULL) if (Process == NULL)
{ {
Process = PsInitialSystemProcess; Process = PsInitialSystemProcess;
} }
if (Process) if (Process)
{ {
(void)InterlockedExchangeAddUL(&Process->Vm.WorkingSetSize, -PAGE_SIZE); (void)InterlockedExchangeAddUL(&Process->Vm.WorkingSetSize, -PAGE_SIZE);
} }
} }
#ifdef NEWCC #ifdef NEWCC
else else
{ {
ExFreeToNPagedLookasideList(&RmapLookasideList, previous_entry); ExFreeToNPagedLookasideList(&RmapLookasideList, previous_entry);
} }
#endif #endif
} }
} }
@ -420,18 +420,18 @@ MmDeleteRmap(PFN_NUMBER Page, PEPROCESS Process,
ExReleaseFastMutex(&RmapListLock); ExReleaseFastMutex(&RmapListLock);
ExFreeToNPagedLookasideList(&RmapLookasideList, current_entry); ExFreeToNPagedLookasideList(&RmapLookasideList, current_entry);
#ifdef NEWCC #ifdef NEWCC
if (!RMAP_IS_SEGMENT(Address)) if (!RMAP_IS_SEGMENT(Address))
#endif #endif
{ {
if (Process == NULL) if (Process == NULL)
{ {
Process = PsInitialSystemProcess; Process = PsInitialSystemProcess;
} }
if (Process) if (Process)
{ {
(void)InterlockedExchangeAddUL(&Process->Vm.WorkingSetSize, -PAGE_SIZE); (void)InterlockedExchangeAddUL(&Process->Vm.WorkingSetSize, -PAGE_SIZE);
} }
} }
return; return;
} }
previous_entry = current_entry; previous_entry = current_entry;
@ -453,13 +453,13 @@ MmGetSegmentRmap(PFN_NUMBER Page, PULONG RawOffset)
current_entry = MmGetRmapListHeadPage(Page); current_entry = MmGetRmapListHeadPage(Page);
while (current_entry != NULL) while (current_entry != NULL)
{ {
if (RMAP_IS_SEGMENT(current_entry->Address)) if (RMAP_IS_SEGMENT(current_entry->Address))
{ {
Result = (PCACHE_SECTION_PAGE_TABLE)current_entry->Process; Result = (PCACHE_SECTION_PAGE_TABLE)current_entry->Process;
*RawOffset = (ULONG_PTR)current_entry->Address & ~RMAP_SEGMENT_MASK; *RawOffset = (ULONG_PTR)current_entry->Address & ~RMAP_SEGMENT_MASK;
InterlockedIncrementUL(&Result->Segment->ReferenceCount); InterlockedIncrementUL(&Result->Segment->ReferenceCount);
ExReleaseFastMutex(&RmapListLock); ExReleaseFastMutex(&RmapListLock);
return Result; return Result;
} }
previous_entry = current_entry; previous_entry = current_entry;
current_entry = current_entry->Next; current_entry = current_entry->Next;
@ -479,7 +479,7 @@ MmDeleteSectionAssociation(PFN_NUMBER Page)
current_entry = MmGetRmapListHeadPage(Page); current_entry = MmGetRmapListHeadPage(Page);
while (current_entry != NULL) while (current_entry != NULL)
{ {
if (RMAP_IS_SEGMENT(current_entry->Address)) if (RMAP_IS_SEGMENT(current_entry->Address))
{ {
if (previous_entry == NULL) if (previous_entry == NULL)
{ {

View file

@ -180,12 +180,12 @@ static const INFORMATION_CLASS_INFO ExSectionInfoClass[] =
File Format Specification", revision 6.0 (February 1999) File Format Specification", revision 6.0 (February 1999)
*/ */
NTSTATUS NTAPI PeFmtCreateSection(IN CONST VOID * FileHeader, NTSTATUS NTAPI PeFmtCreateSection(IN CONST VOID * FileHeader,
IN SIZE_T FileHeaderSize, IN SIZE_T FileHeaderSize,
IN PVOID File, IN PVOID File,
OUT PMM_IMAGE_SECTION_OBJECT ImageSectionObject, OUT PMM_IMAGE_SECTION_OBJECT ImageSectionObject,
OUT PULONG Flags, OUT PULONG Flags,
IN PEXEFMT_CB_READ_FILE ReadFileCb, IN PEXEFMT_CB_READ_FILE ReadFileCb,
IN PEXEFMT_CB_ALLOCATE_SEGMENTS AllocateSegmentsCb) IN PEXEFMT_CB_ALLOCATE_SEGMENTS AllocateSegmentsCb)
{ {
NTSTATUS nStatus; NTSTATUS nStatus;
ULONG cbFileHeaderOffsetSize = 0; ULONG cbFileHeaderOffsetSize = 0;
@ -228,32 +228,32 @@ NTSTATUS NTAPI PeFmtCreateSection(IN CONST VOID * FileHeader,
/* image too small to be an MZ executable */ /* image too small to be an MZ executable */
if(FileHeaderSize < sizeof(IMAGE_DOS_HEADER)) if(FileHeaderSize < sizeof(IMAGE_DOS_HEADER))
DIE(("Too small to be an MZ executable, size is %lu\n", FileHeaderSize)); DIE(("Too small to be an MZ executable, size is %lu\n", FileHeaderSize));
/* no MZ signature */ /* no MZ signature */
if(pidhDosHeader->e_magic != IMAGE_DOS_SIGNATURE) if(pidhDosHeader->e_magic != IMAGE_DOS_SIGNATURE)
DIE(("No MZ signature found, e_magic is %hX\n", pidhDosHeader->e_magic)); DIE(("No MZ signature found, e_magic is %hX\n", pidhDosHeader->e_magic));
/* not a Windows executable */ /* not a Windows executable */
if(pidhDosHeader->e_lfanew <= 0) if(pidhDosHeader->e_lfanew <= 0)
DIE(("Not a Windows executable, e_lfanew is %d\n", pidhDosHeader->e_lfanew)); DIE(("Not a Windows executable, e_lfanew is %d\n", pidhDosHeader->e_lfanew));
/* NT HEADER */ /* NT HEADER */
nStatus = STATUS_INVALID_IMAGE_FORMAT; nStatus = STATUS_INVALID_IMAGE_FORMAT;
if(!Intsafe_AddULong32(&cbFileHeaderOffsetSize, pidhDosHeader->e_lfanew, RTL_SIZEOF_THROUGH_FIELD(IMAGE_NT_HEADERS32, FileHeader))) if(!Intsafe_AddULong32(&cbFileHeaderOffsetSize, pidhDosHeader->e_lfanew, RTL_SIZEOF_THROUGH_FIELD(IMAGE_NT_HEADERS32, FileHeader)))
DIE(("The DOS stub is too large, e_lfanew is %X\n", pidhDosHeader->e_lfanew)); DIE(("The DOS stub is too large, e_lfanew is %X\n", pidhDosHeader->e_lfanew));
if(FileHeaderSize < cbFileHeaderOffsetSize) if(FileHeaderSize < cbFileHeaderOffsetSize)
pinhNtHeader = NULL; pinhNtHeader = NULL;
else else
{ {
/* /*
* we already know that Intsafe_CanOffsetPointer(FileHeader, FileHeaderSize), * we already know that Intsafe_CanOffsetPointer(FileHeader, FileHeaderSize),
* and FileHeaderSize >= cbFileHeaderOffsetSize, so this holds true too * and FileHeaderSize >= cbFileHeaderOffsetSize, so this holds true too
*/ */
ASSERT(Intsafe_CanOffsetPointer(FileHeader, pidhDosHeader->e_lfanew)); ASSERT(Intsafe_CanOffsetPointer(FileHeader, pidhDosHeader->e_lfanew));
pinhNtHeader = (PVOID)((UINT_PTR)FileHeader + pidhDosHeader->e_lfanew); pinhNtHeader = (PVOID)((UINT_PTR)FileHeader + pidhDosHeader->e_lfanew);
} }
/* /*
@ -263,74 +263,74 @@ NTSTATUS NTAPI PeFmtCreateSection(IN CONST VOID * FileHeader,
if(FileHeaderSize < cbFileHeaderOffsetSize || if(FileHeaderSize < cbFileHeaderOffsetSize ||
(UINT_PTR)pinhNtHeader % TYPE_ALIGNMENT(IMAGE_NT_HEADERS32) != 0) (UINT_PTR)pinhNtHeader % TYPE_ALIGNMENT(IMAGE_NT_HEADERS32) != 0)
{ {
ULONG cbNtHeaderSize; ULONG cbNtHeaderSize;
ULONG cbReadSize; ULONG cbReadSize;
PVOID pData; PVOID pData;
l_ReadHeaderFromFile: l_ReadHeaderFromFile:
cbNtHeaderSize = 0; cbNtHeaderSize = 0;
lnOffset.QuadPart = pidhDosHeader->e_lfanew; lnOffset.QuadPart = pidhDosHeader->e_lfanew;
/* read the header from the file */ /* read the header from the file */
nStatus = ReadFileCb(File, &lnOffset, sizeof(IMAGE_NT_HEADERS64), &pData, &pBuffer, &cbReadSize); nStatus = ReadFileCb(File, &lnOffset, sizeof(IMAGE_NT_HEADERS64), &pData, &pBuffer, &cbReadSize);
if(!NT_SUCCESS(nStatus)) if(!NT_SUCCESS(nStatus))
DIE(("ReadFile failed, status %08X\n", nStatus)); DIE(("ReadFile failed, status %08X\n", nStatus));
ASSERT(pData); ASSERT(pData);
ASSERT(pBuffer); ASSERT(pBuffer);
ASSERT(cbReadSize > 0); ASSERT(cbReadSize > 0);
nStatus = STATUS_INVALID_IMAGE_FORMAT; nStatus = STATUS_INVALID_IMAGE_FORMAT;
/* the buffer doesn't contain the file header */ /* the buffer doesn't contain the file header */
if(cbReadSize < RTL_SIZEOF_THROUGH_FIELD(IMAGE_NT_HEADERS32, FileHeader)) if(cbReadSize < RTL_SIZEOF_THROUGH_FIELD(IMAGE_NT_HEADERS32, FileHeader))
DIE(("The file doesn't contain the PE file header\n")); DIE(("The file doesn't contain the PE file header\n"));
pinhNtHeader = pData; pinhNtHeader = pData;
/* object still not aligned: copy it to the beginning of the buffer */ /* object still not aligned: copy it to the beginning of the buffer */
if((UINT_PTR)pinhNtHeader % TYPE_ALIGNMENT(IMAGE_NT_HEADERS32) != 0) if((UINT_PTR)pinhNtHeader % TYPE_ALIGNMENT(IMAGE_NT_HEADERS32) != 0)
{ {
ASSERT((UINT_PTR)pBuffer % TYPE_ALIGNMENT(IMAGE_NT_HEADERS32) == 0); ASSERT((UINT_PTR)pBuffer % TYPE_ALIGNMENT(IMAGE_NT_HEADERS32) == 0);
RtlMoveMemory(pBuffer, pData, cbReadSize); RtlMoveMemory(pBuffer, pData, cbReadSize);
pinhNtHeader = pBuffer; pinhNtHeader = pBuffer;
} }
/* invalid NT header */ /* invalid NT header */
nStatus = STATUS_INVALID_IMAGE_PROTECT; nStatus = STATUS_INVALID_IMAGE_PROTECT;
if(pinhNtHeader->Signature != IMAGE_NT_SIGNATURE) if(pinhNtHeader->Signature != IMAGE_NT_SIGNATURE)
DIE(("The file isn't a PE executable, Signature is %X\n", pinhNtHeader->Signature)); DIE(("The file isn't a PE executable, Signature is %X\n", pinhNtHeader->Signature));
nStatus = STATUS_INVALID_IMAGE_FORMAT; nStatus = STATUS_INVALID_IMAGE_FORMAT;
if(!Intsafe_AddULong32(&cbNtHeaderSize, pinhNtHeader->FileHeader.SizeOfOptionalHeader, FIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader))) if(!Intsafe_AddULong32(&cbNtHeaderSize, pinhNtHeader->FileHeader.SizeOfOptionalHeader, FIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader)))
DIE(("The full NT header is too large\n")); DIE(("The full NT header is too large\n"));
/* the buffer doesn't contain the whole NT header */ /* the buffer doesn't contain the whole NT header */
if(cbReadSize < cbNtHeaderSize) if(cbReadSize < cbNtHeaderSize)
DIE(("The file doesn't contain the full NT header\n")); DIE(("The file doesn't contain the full NT header\n"));
} }
else else
{ {
ULONG cbOptHeaderOffsetSize = 0; ULONG cbOptHeaderOffsetSize = 0;
nStatus = STATUS_INVALID_IMAGE_FORMAT; nStatus = STATUS_INVALID_IMAGE_FORMAT;
/* don't trust an invalid NT header */ /* don't trust an invalid NT header */
if(pinhNtHeader->Signature != IMAGE_NT_SIGNATURE) if(pinhNtHeader->Signature != IMAGE_NT_SIGNATURE)
DIE(("The file isn't a PE executable, Signature is %X\n", pinhNtHeader->Signature)); DIE(("The file isn't a PE executable, Signature is %X\n", pinhNtHeader->Signature));
if(!Intsafe_AddULong32(&cbOptHeaderOffsetSize, pidhDosHeader->e_lfanew, FIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader))) if(!Intsafe_AddULong32(&cbOptHeaderOffsetSize, pidhDosHeader->e_lfanew, FIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader)))
DIE(("The DOS stub is too large, e_lfanew is %X\n", pidhDosHeader->e_lfanew)); DIE(("The DOS stub is too large, e_lfanew is %X\n", pidhDosHeader->e_lfanew));
if(!Intsafe_AddULong32(&cbOptHeaderOffsetSize, cbOptHeaderOffsetSize, pinhNtHeader->FileHeader.SizeOfOptionalHeader)) if(!Intsafe_AddULong32(&cbOptHeaderOffsetSize, cbOptHeaderOffsetSize, pinhNtHeader->FileHeader.SizeOfOptionalHeader))
DIE(("The NT header is too large, SizeOfOptionalHeader is %X\n", pinhNtHeader->FileHeader.SizeOfOptionalHeader)); DIE(("The NT header is too large, SizeOfOptionalHeader is %X\n", pinhNtHeader->FileHeader.SizeOfOptionalHeader));
/* the buffer doesn't contain the whole NT header: read it from the file */ /* the buffer doesn't contain the whole NT header: read it from the file */
if(cbOptHeaderOffsetSize > FileHeaderSize) if(cbOptHeaderOffsetSize > FileHeaderSize)
goto l_ReadHeaderFromFile; goto l_ReadHeaderFromFile;
} }
/* read information from the NT header */ /* read information from the NT header */
@ -340,42 +340,42 @@ l_ReadHeaderFromFile:
nStatus = STATUS_INVALID_IMAGE_FORMAT; nStatus = STATUS_INVALID_IMAGE_FORMAT;
if(!RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, Magic)) if(!RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, Magic))
DIE(("The optional header doesn't contain the Magic field, SizeOfOptionalHeader is %X\n", cbOptHeaderSize)); DIE(("The optional header doesn't contain the Magic field, SizeOfOptionalHeader is %X\n", cbOptHeaderSize));
/* ASSUME: RtlZeroMemory(ImageSectionObject, sizeof(*ImageSectionObject)); */ /* ASSUME: RtlZeroMemory(ImageSectionObject, sizeof(*ImageSectionObject)); */
switch(piohOptHeader->Magic) switch(piohOptHeader->Magic)
{ {
case IMAGE_NT_OPTIONAL_HDR32_MAGIC: case IMAGE_NT_OPTIONAL_HDR32_MAGIC:
case IMAGE_NT_OPTIONAL_HDR64_MAGIC: case IMAGE_NT_OPTIONAL_HDR64_MAGIC:
break; break;
default: default:
DIE(("Unrecognized optional header, Magic is %X\n", piohOptHeader->Magic)); DIE(("Unrecognized optional header, Magic is %X\n", piohOptHeader->Magic));
} }
if (RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, SectionAlignment) && if (RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, SectionAlignment) &&
RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, FileAlignment)) RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, FileAlignment))
{ {
/* See [1], section 3.4.2 */ /* See [1], section 3.4.2 */
if(piohOptHeader->SectionAlignment < PAGE_SIZE) if(piohOptHeader->SectionAlignment < PAGE_SIZE)
{ {
if(piohOptHeader->FileAlignment != piohOptHeader->SectionAlignment) if(piohOptHeader->FileAlignment != piohOptHeader->SectionAlignment)
DIE(("Sections aren't page-aligned and the file alignment isn't the same\n")); DIE(("Sections aren't page-aligned and the file alignment isn't the same\n"));
} }
else if(piohOptHeader->SectionAlignment < piohOptHeader->FileAlignment) else if(piohOptHeader->SectionAlignment < piohOptHeader->FileAlignment)
DIE(("The section alignment is smaller than the file alignment\n")); DIE(("The section alignment is smaller than the file alignment\n"));
nSectionAlignment = piohOptHeader->SectionAlignment; nSectionAlignment = piohOptHeader->SectionAlignment;
nFileAlignment = piohOptHeader->FileAlignment; nFileAlignment = piohOptHeader->FileAlignment;
if(!IsPowerOf2(nSectionAlignment) || !IsPowerOf2(nFileAlignment)) if(!IsPowerOf2(nSectionAlignment) || !IsPowerOf2(nFileAlignment))
DIE(("The section alignment (%u) and file alignment (%u) aren't both powers of 2\n", nSectionAlignment, nFileAlignment)); DIE(("The section alignment (%u) and file alignment (%u) aren't both powers of 2\n", nSectionAlignment, nFileAlignment));
} }
else else
{ {
nSectionAlignment = PAGE_SIZE; nSectionAlignment = PAGE_SIZE;
nFileAlignment = PAGE_SIZE; nFileAlignment = PAGE_SIZE;
} }
ASSERT(IsPowerOf2(nSectionAlignment)); ASSERT(IsPowerOf2(nSectionAlignment));
@ -383,93 +383,93 @@ l_ReadHeaderFromFile:
switch(piohOptHeader->Magic) switch(piohOptHeader->Magic)
{ {
/* PE32 */ /* PE32 */
case IMAGE_NT_OPTIONAL_HDR32_MAGIC: case IMAGE_NT_OPTIONAL_HDR32_MAGIC:
{ {
if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, ImageBase)) if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, ImageBase))
ImageSectionObject->ImageBase = piohOptHeader->ImageBase; ImageSectionObject->ImageBase = piohOptHeader->ImageBase;
if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, SizeOfImage)) if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, SizeOfImage))
ImageSectionObject->ImageSize = piohOptHeader->SizeOfImage; ImageSectionObject->ImageSize = piohOptHeader->SizeOfImage;
if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, SizeOfStackReserve)) if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, SizeOfStackReserve))
ImageSectionObject->StackReserve = piohOptHeader->SizeOfStackReserve; ImageSectionObject->StackReserve = piohOptHeader->SizeOfStackReserve;
if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, SizeOfStackCommit)) if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, SizeOfStackCommit))
ImageSectionObject->StackCommit = piohOptHeader->SizeOfStackCommit; ImageSectionObject->StackCommit = piohOptHeader->SizeOfStackCommit;
break; break;
} }
/* PE32+ */ /* PE32+ */
case IMAGE_NT_OPTIONAL_HDR64_MAGIC: case IMAGE_NT_OPTIONAL_HDR64_MAGIC:
{ {
const IMAGE_OPTIONAL_HEADER64 * pioh64OptHeader; const IMAGE_OPTIONAL_HEADER64 * pioh64OptHeader;
pioh64OptHeader = (const IMAGE_OPTIONAL_HEADER64 *)piohOptHeader; pioh64OptHeader = (const IMAGE_OPTIONAL_HEADER64 *)piohOptHeader;
if(RTL_CONTAINS_FIELD(pioh64OptHeader, cbOptHeaderSize, ImageBase)) if(RTL_CONTAINS_FIELD(pioh64OptHeader, cbOptHeaderSize, ImageBase))
{ {
if(pioh64OptHeader->ImageBase > MAXULONG_PTR) if(pioh64OptHeader->ImageBase > MAXULONG_PTR)
DIE(("ImageBase exceeds the address space\n")); DIE(("ImageBase exceeds the address space\n"));
ImageSectionObject->ImageBase = (ULONG_PTR)pioh64OptHeader->ImageBase; ImageSectionObject->ImageBase = (ULONG_PTR)pioh64OptHeader->ImageBase;
} }
if(RTL_CONTAINS_FIELD(pioh64OptHeader, cbOptHeaderSize, SizeOfImage)) if(RTL_CONTAINS_FIELD(pioh64OptHeader, cbOptHeaderSize, SizeOfImage))
{ {
if(pioh64OptHeader->SizeOfImage > MAXULONG_PTR) if(pioh64OptHeader->SizeOfImage > MAXULONG_PTR)
DIE(("SizeOfImage exceeds the address space\n")); DIE(("SizeOfImage exceeds the address space\n"));
ImageSectionObject->ImageSize = pioh64OptHeader->SizeOfImage; ImageSectionObject->ImageSize = pioh64OptHeader->SizeOfImage;
} }
if(RTL_CONTAINS_FIELD(pioh64OptHeader, cbOptHeaderSize, SizeOfStackReserve)) if(RTL_CONTAINS_FIELD(pioh64OptHeader, cbOptHeaderSize, SizeOfStackReserve))
{ {
if(pioh64OptHeader->SizeOfStackReserve > MAXULONG_PTR) if(pioh64OptHeader->SizeOfStackReserve > MAXULONG_PTR)
DIE(("SizeOfStackReserve exceeds the address space\n")); DIE(("SizeOfStackReserve exceeds the address space\n"));
ImageSectionObject->StackReserve = (ULONG_PTR)pioh64OptHeader->SizeOfStackReserve; ImageSectionObject->StackReserve = (ULONG_PTR)pioh64OptHeader->SizeOfStackReserve;
} }
if(RTL_CONTAINS_FIELD(pioh64OptHeader, cbOptHeaderSize, SizeOfStackCommit)) if(RTL_CONTAINS_FIELD(pioh64OptHeader, cbOptHeaderSize, SizeOfStackCommit))
{ {
if(pioh64OptHeader->SizeOfStackCommit > MAXULONG_PTR) if(pioh64OptHeader->SizeOfStackCommit > MAXULONG_PTR)
DIE(("SizeOfStackCommit exceeds the address space\n")); DIE(("SizeOfStackCommit exceeds the address space\n"));
ImageSectionObject->StackCommit = (ULONG_PTR)pioh64OptHeader->SizeOfStackCommit; ImageSectionObject->StackCommit = (ULONG_PTR)pioh64OptHeader->SizeOfStackCommit;
} }
break; break;
} }
} }
/* [1], section 3.4.2 */ /* [1], section 3.4.2 */
if((ULONG_PTR)ImageSectionObject->ImageBase % 0x10000) if((ULONG_PTR)ImageSectionObject->ImageBase % 0x10000)
DIE(("ImageBase is not aligned on a 64KB boundary")); DIE(("ImageBase is not aligned on a 64KB boundary"));
if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, Subsystem)) if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, Subsystem))
{ {
ImageSectionObject->Subsystem = piohOptHeader->Subsystem; ImageSectionObject->Subsystem = piohOptHeader->Subsystem;
if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, MinorSubsystemVersion) && if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, MinorSubsystemVersion) &&
RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, MajorSubsystemVersion)) RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, MajorSubsystemVersion))
{ {
ImageSectionObject->MinorSubsystemVersion = piohOptHeader->MinorSubsystemVersion; ImageSectionObject->MinorSubsystemVersion = piohOptHeader->MinorSubsystemVersion;
ImageSectionObject->MajorSubsystemVersion = piohOptHeader->MajorSubsystemVersion; ImageSectionObject->MajorSubsystemVersion = piohOptHeader->MajorSubsystemVersion;
} }
} }
if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, AddressOfEntryPoint)) if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, AddressOfEntryPoint))
{ {
ImageSectionObject->EntryPoint = piohOptHeader->ImageBase + ImageSectionObject->EntryPoint = piohOptHeader->ImageBase +
piohOptHeader->AddressOfEntryPoint; piohOptHeader->AddressOfEntryPoint;
} }
if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, SizeOfCode)) if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, SizeOfCode))
ImageSectionObject->Executable = piohOptHeader->SizeOfCode != 0; ImageSectionObject->Executable = piohOptHeader->SizeOfCode != 0;
else else
ImageSectionObject->Executable = TRUE; ImageSectionObject->Executable = TRUE;
ImageSectionObject->ImageCharacteristics = pinhNtHeader->FileHeader.Characteristics; ImageSectionObject->ImageCharacteristics = pinhNtHeader->FileHeader.Characteristics;
ImageSectionObject->Machine = pinhNtHeader->FileHeader.Machine; ImageSectionObject->Machine = pinhNtHeader->FileHeader.Machine;
@ -479,7 +479,7 @@ l_ReadHeaderFromFile:
/* see [1], section 3.3 */ /* see [1], section 3.3 */
if(pinhNtHeader->FileHeader.NumberOfSections > 96) if(pinhNtHeader->FileHeader.NumberOfSections > 96)
DIE(("Too many sections, NumberOfSections is %u\n", pinhNtHeader->FileHeader.NumberOfSections)); DIE(("Too many sections, NumberOfSections is %u\n", pinhNtHeader->FileHeader.NumberOfSections));
/* /*
* the additional segment is for the file's headers. They need to be present for * the additional segment is for the file's headers. They need to be present for
@ -490,51 +490,51 @@ l_ReadHeaderFromFile:
/* file offset for the section headers */ /* file offset for the section headers */
if(!Intsafe_AddULong32(&cbSectionHeadersOffset, pidhDosHeader->e_lfanew, FIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader))) if(!Intsafe_AddULong32(&cbSectionHeadersOffset, pidhDosHeader->e_lfanew, FIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader)))
DIE(("Offset overflow\n")); DIE(("Offset overflow\n"));
if(!Intsafe_AddULong32(&cbSectionHeadersOffset, cbSectionHeadersOffset, pinhNtHeader->FileHeader.SizeOfOptionalHeader)) if(!Intsafe_AddULong32(&cbSectionHeadersOffset, cbSectionHeadersOffset, pinhNtHeader->FileHeader.SizeOfOptionalHeader))
DIE(("Offset overflow\n")); DIE(("Offset overflow\n"));
/* size of the section headers */ /* size of the section headers */
ASSERT(Intsafe_CanMulULong32(pinhNtHeader->FileHeader.NumberOfSections, sizeof(IMAGE_SECTION_HEADER))); ASSERT(Intsafe_CanMulULong32(pinhNtHeader->FileHeader.NumberOfSections, sizeof(IMAGE_SECTION_HEADER)));
cbSectionHeadersSize = pinhNtHeader->FileHeader.NumberOfSections * sizeof(IMAGE_SECTION_HEADER); cbSectionHeadersSize = pinhNtHeader->FileHeader.NumberOfSections * sizeof(IMAGE_SECTION_HEADER);
if(!Intsafe_AddULong32(&cbSectionHeadersOffsetSize, cbSectionHeadersOffset, cbSectionHeadersSize)) if(!Intsafe_AddULong32(&cbSectionHeadersOffsetSize, cbSectionHeadersOffset, cbSectionHeadersSize))
DIE(("Section headers too large\n")); DIE(("Section headers too large\n"));
/* size of the executable's headers */ /* size of the executable's headers */
if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, SizeOfHeaders)) if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, SizeOfHeaders))
{ {
// if(!IsAligned(piohOptHeader->SizeOfHeaders, nFileAlignment)) // if(!IsAligned(piohOptHeader->SizeOfHeaders, nFileAlignment))
// DIE(("SizeOfHeaders is not aligned\n")); // DIE(("SizeOfHeaders is not aligned\n"));
if(cbSectionHeadersSize > piohOptHeader->SizeOfHeaders) if(cbSectionHeadersSize > piohOptHeader->SizeOfHeaders)
DIE(("The section headers overflow SizeOfHeaders\n")); DIE(("The section headers overflow SizeOfHeaders\n"));
cbHeadersSize = piohOptHeader->SizeOfHeaders; cbHeadersSize = piohOptHeader->SizeOfHeaders;
} }
else if(!AlignUp(&cbHeadersSize, cbSectionHeadersOffsetSize, nFileAlignment)) else if(!AlignUp(&cbHeadersSize, cbSectionHeadersOffsetSize, nFileAlignment))
DIE(("Overflow aligning the size of headers\n")); DIE(("Overflow aligning the size of headers\n"));
if(pBuffer) if(pBuffer)
{ {
ExFreePool(pBuffer); ExFreePool(pBuffer);
pBuffer = NULL; pBuffer = NULL;
} }
/* WARNING: pinhNtHeader IS NO LONGER USABLE */ /* WARNING: pinhNtHeader IS NO LONGER USABLE */
/* WARNING: piohOptHeader IS NO LONGER USABLE */ /* WARNING: piohOptHeader IS NO LONGER USABLE */
/* WARNING: pioh64OptHeader IS NO LONGER USABLE */ /* WARNING: pioh64OptHeader IS NO LONGER USABLE */
if(FileHeaderSize < cbSectionHeadersOffsetSize) if(FileHeaderSize < cbSectionHeadersOffsetSize)
pishSectionHeaders = NULL; pishSectionHeaders = NULL;
else else
{ {
/* /*
* we already know that Intsafe_CanOffsetPointer(FileHeader, FileHeaderSize), * we already know that Intsafe_CanOffsetPointer(FileHeader, FileHeaderSize),
* and FileHeaderSize >= cbSectionHeadersOffsetSize, so this holds true too * and FileHeaderSize >= cbSectionHeadersOffsetSize, so this holds true too
*/ */
ASSERT(Intsafe_CanOffsetPointer(FileHeader, cbSectionHeadersOffset)); ASSERT(Intsafe_CanOffsetPointer(FileHeader, cbSectionHeadersOffset));
pishSectionHeaders = (PVOID)((UINT_PTR)FileHeader + cbSectionHeadersOffset); pishSectionHeaders = (PVOID)((UINT_PTR)FileHeader + cbSectionHeadersOffset);
} }
/* /*
@ -544,36 +544,36 @@ l_ReadHeaderFromFile:
if(FileHeaderSize < cbSectionHeadersOffsetSize || if(FileHeaderSize < cbSectionHeadersOffsetSize ||
(UINT_PTR)pishSectionHeaders % TYPE_ALIGNMENT(IMAGE_SECTION_HEADER) != 0) (UINT_PTR)pishSectionHeaders % TYPE_ALIGNMENT(IMAGE_SECTION_HEADER) != 0)
{ {
PVOID pData; PVOID pData;
ULONG cbReadSize; ULONG cbReadSize;
lnOffset.QuadPart = cbSectionHeadersOffset; lnOffset.QuadPart = cbSectionHeadersOffset;
/* read the header from the file */ /* read the header from the file */
nStatus = ReadFileCb(File, &lnOffset, cbSectionHeadersSize, &pData, &pBuffer, &cbReadSize); nStatus = ReadFileCb(File, &lnOffset, cbSectionHeadersSize, &pData, &pBuffer, &cbReadSize);
if(!NT_SUCCESS(nStatus)) if(!NT_SUCCESS(nStatus))
DIE(("ReadFile failed with status %08X\n", nStatus)); DIE(("ReadFile failed with status %08X\n", nStatus));
ASSERT(pData); ASSERT(pData);
ASSERT(pBuffer); ASSERT(pBuffer);
ASSERT(cbReadSize > 0); ASSERT(cbReadSize > 0);
nStatus = STATUS_INVALID_IMAGE_FORMAT; nStatus = STATUS_INVALID_IMAGE_FORMAT;
/* the buffer doesn't contain all the section headers */ /* the buffer doesn't contain all the section headers */
if(cbReadSize < cbSectionHeadersSize) if(cbReadSize < cbSectionHeadersSize)
DIE(("The file doesn't contain all of the section headers\n")); DIE(("The file doesn't contain all of the section headers\n"));
pishSectionHeaders = pData; pishSectionHeaders = pData;
/* object still not aligned: copy it to the beginning of the buffer */ /* object still not aligned: copy it to the beginning of the buffer */
if((UINT_PTR)pishSectionHeaders % TYPE_ALIGNMENT(IMAGE_SECTION_HEADER) != 0) if((UINT_PTR)pishSectionHeaders % TYPE_ALIGNMENT(IMAGE_SECTION_HEADER) != 0)
{ {
ASSERT((UINT_PTR)pBuffer % TYPE_ALIGNMENT(IMAGE_SECTION_HEADER) == 0); ASSERT((UINT_PTR)pBuffer % TYPE_ALIGNMENT(IMAGE_SECTION_HEADER) == 0);
RtlMoveMemory(pBuffer, pData, cbReadSize); RtlMoveMemory(pBuffer, pData, cbReadSize);
pishSectionHeaders = pBuffer; pishSectionHeaders = pBuffer;
} }
} }
/* SEGMENTS */ /* SEGMENTS */
@ -585,7 +585,7 @@ l_ReadHeaderFromFile:
DIE(("AllocateSegments failed\n")); DIE(("AllocateSegments failed\n"));
/* initialize the headers segment */ /* initialize the headers segment */
pssSegments = ImageSectionObject->Segments; pssSegments = ImageSectionObject->Segments;
// ASSERT(IsAligned(cbHeadersSize, nFileAlignment)); // ASSERT(IsAligned(cbHeadersSize, nFileAlignment));
@ -612,92 +612,92 @@ l_ReadHeaderFromFile:
/* convert the executable sections into segments. See also [1], section 4 */ /* convert the executable sections into segments. See also [1], section 4 */
for(i = 0; i < ImageSectionObject->NrSegments - 1; ++ i) for(i = 0; i < ImageSectionObject->NrSegments - 1; ++ i)
{ {
ULONG nCharacteristics; ULONG nCharacteristics;
/* validate the alignment */ /* validate the alignment */
if(!IsAligned(pishSectionHeaders[i].VirtualAddress, nSectionAlignment)) if(!IsAligned(pishSectionHeaders[i].VirtualAddress, nSectionAlignment))
DIE(("VirtualAddress[%u] is not aligned\n", i)); DIE(("VirtualAddress[%u] is not aligned\n", i));
/* sections must be contiguous, ordered by base address and non-overlapping */ /* sections must be contiguous, ordered by base address and non-overlapping */
if(pishSectionHeaders[i].VirtualAddress != nPrevVirtualEndOfSegment) if(pishSectionHeaders[i].VirtualAddress != nPrevVirtualEndOfSegment)
DIE(("Memory gap between section %u and the previous\n", i)); DIE(("Memory gap between section %u and the previous\n", i));
/* ignore explicit BSS sections */ /* ignore explicit BSS sections */
if(pishSectionHeaders[i].SizeOfRawData != 0) if(pishSectionHeaders[i].SizeOfRawData != 0)
{ {
/* validate the alignment */ /* validate the alignment */
#if 0 #if 0
/* Yes, this should be a multiple of FileAlignment, but there's /* Yes, this should be a multiple of FileAlignment, but there's
* stuff out there that isn't. We can cope with that * stuff out there that isn't. We can cope with that
*/ */
if(!IsAligned(pishSectionHeaders[i].SizeOfRawData, nFileAlignment)) if(!IsAligned(pishSectionHeaders[i].SizeOfRawData, nFileAlignment))
DIE(("SizeOfRawData[%u] is not aligned\n", i)); DIE(("SizeOfRawData[%u] is not aligned\n", i));
#endif #endif
// if(!IsAligned(pishSectionHeaders[i].PointerToRawData, nFileAlignment)) // if(!IsAligned(pishSectionHeaders[i].PointerToRawData, nFileAlignment))
// DIE(("PointerToRawData[%u] is not aligned\n", i)); // DIE(("PointerToRawData[%u] is not aligned\n", i));
/* conversion */ /* conversion */
pssSegments[i].FileOffset = pishSectionHeaders[i].PointerToRawData; pssSegments[i].FileOffset = pishSectionHeaders[i].PointerToRawData;
pssSegments[i].RawLength = pishSectionHeaders[i].SizeOfRawData; pssSegments[i].RawLength = pishSectionHeaders[i].SizeOfRawData;
} }
else else
{ {
ASSERT(pssSegments[i].FileOffset == 0); ASSERT(pssSegments[i].FileOffset == 0);
ASSERT(pssSegments[i].RawLength == 0); ASSERT(pssSegments[i].RawLength == 0);
} }
ASSERT(Intsafe_CanAddLong64(pssSegments[i].FileOffset, pssSegments[i].RawLength)); ASSERT(Intsafe_CanAddLong64(pssSegments[i].FileOffset, pssSegments[i].RawLength));
nCharacteristics = pishSectionHeaders[i].Characteristics; nCharacteristics = pishSectionHeaders[i].Characteristics;
/* no explicit protection */ /* no explicit protection */
if((nCharacteristics & (IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE)) == 0) if((nCharacteristics & (IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE)) == 0)
{ {
if(nCharacteristics & IMAGE_SCN_CNT_CODE) if(nCharacteristics & IMAGE_SCN_CNT_CODE)
nCharacteristics |= IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ; nCharacteristics |= IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ;
if(nCharacteristics & IMAGE_SCN_CNT_INITIALIZED_DATA) if(nCharacteristics & IMAGE_SCN_CNT_INITIALIZED_DATA)
nCharacteristics |= IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE; nCharacteristics |= IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE;
if(nCharacteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA) if(nCharacteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA)
nCharacteristics |= IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE; nCharacteristics |= IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE;
} }
/* see table above */ /* see table above */
pssSegments[i].Protection = SectionCharacteristicsToProtect[nCharacteristics >> 28]; pssSegments[i].Protection = SectionCharacteristicsToProtect[nCharacteristics >> 28];
pssSegments[i].WriteCopy = !(nCharacteristics & IMAGE_SCN_MEM_SHARED); pssSegments[i].WriteCopy = !(nCharacteristics & IMAGE_SCN_MEM_SHARED);
if(pishSectionHeaders[i].Misc.VirtualSize == 0 || pishSectionHeaders[i].Misc.VirtualSize < pishSectionHeaders[i].SizeOfRawData) if(pishSectionHeaders[i].Misc.VirtualSize == 0 || pishSectionHeaders[i].Misc.VirtualSize < pishSectionHeaders[i].SizeOfRawData)
pssSegments[i].Length = pishSectionHeaders[i].SizeOfRawData; pssSegments[i].Length = pishSectionHeaders[i].SizeOfRawData;
else else
pssSegments[i].Length = pishSectionHeaders[i].Misc.VirtualSize; pssSegments[i].Length = pishSectionHeaders[i].Misc.VirtualSize;
pssSegments[i].Length = ALIGN_UP_BY(pssSegments[i].Length, nSectionAlignment); pssSegments[i].Length = ALIGN_UP_BY(pssSegments[i].Length, nSectionAlignment);
if (pssSegments[i].Length < pssSegments[i].Length) if (pssSegments[i].Length < pssSegments[i].Length)
DIE(("Cannot align the virtual size of section %u\n", i)); DIE(("Cannot align the virtual size of section %u\n", i));
if(pssSegments[i].Length == 0) if(pssSegments[i].Length == 0)
DIE(("Virtual size of section %u is null\n", i)); DIE(("Virtual size of section %u is null\n", i));
pssSegments[i].VirtualAddress = pishSectionHeaders[i].VirtualAddress; pssSegments[i].VirtualAddress = pishSectionHeaders[i].VirtualAddress;
pssSegments[i].Characteristics = pishSectionHeaders[i].Characteristics; pssSegments[i].Characteristics = pishSectionHeaders[i].Characteristics;
/* ensure the memory image is no larger than 4GB */ /* ensure the memory image is no larger than 4GB */
nPrevVirtualEndOfSegment = pssSegments[i].VirtualAddress + pssSegments[i].Length; nPrevVirtualEndOfSegment = pssSegments[i].VirtualAddress + pssSegments[i].Length;
if (nPrevVirtualEndOfSegment < pssSegments[i].VirtualAddress) if (nPrevVirtualEndOfSegment < pssSegments[i].VirtualAddress)
DIE(("The image is too large\n")); DIE(("The image is too large\n"));
} }
if(nSectionAlignment >= PAGE_SIZE) if(nSectionAlignment >= PAGE_SIZE)
*Flags |= EXEFMT_LOAD_ASSUME_SEGMENTS_PAGE_ALIGNED; *Flags |= EXEFMT_LOAD_ASSUME_SEGMENTS_PAGE_ALIGNED;
/* Success */ /* Success */
nStatus = STATUS_ROS_EXEFMT_LOADED_FORMAT | EXEFMT_LOADED_PE32; nStatus = STATUS_ROS_EXEFMT_LOADED_FORMAT | EXEFMT_LOADED_PE32;
l_Return: l_Return:
if(pBuffer) if(pBuffer)
ExFreePool(pBuffer); ExFreePool(pBuffer);
return nStatus; return nStatus;
} }
@ -981,7 +981,7 @@ MmUnsharePageEntrySectionSegment(PROS_SECTION_OBJECT Section,
#ifndef NEWCC #ifndef NEWCC
Status = CcRosUnmapCacheSegment(Bcb, FileOffset, Dirty); Status = CcRosUnmapCacheSegment(Bcb, FileOffset, Dirty);
#else #else
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
#endif #endif
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
@ -1293,7 +1293,7 @@ MiReadPage(PMEMORY_AREA MemoryArea,
Resources.Context = MemoryArea->Data.SectionData.Section->FileObject; Resources.Context = MemoryArea->Data.SectionData.Section->FileObject;
Resources.FileOffset.QuadPart = SegOffset + Resources.FileOffset.QuadPart = SegOffset +
MemoryArea->Data.SectionData.Segment->FileOffset; MemoryArea->Data.SectionData.Segment->FileOffset;
Resources.Consumer = MC_USER; Resources.Consumer = MC_USER;
Resources.Amount = PAGE_SIZE; Resources.Amount = PAGE_SIZE;
@ -1676,7 +1676,7 @@ MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace,
if (Entry != Entry1) if (Entry != Entry1)
{ {
DPRINT1("Someone changed ppte entry while we slept\n"); DPRINT1("Someone changed ppte entry while we slept\n");
KeBugCheck(MEMORY_MANAGEMENT); KeBugCheck(MEMORY_MANAGEMENT);
} }
/* /*
@ -2224,7 +2224,7 @@ MmPageOutSectionView(PMMSUPPORT AddressSpace,
#ifndef NEWCC #ifndef NEWCC
Status = CcRosUnmapCacheSegment(Bcb, FileOffset, FALSE); Status = CcRosUnmapCacheSegment(Bcb, FileOffset, FALSE);
#else #else
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
#endif #endif
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {