[NTOS:MM] Properly initialize initial process address space on amd64

By applying the same kludge on the relevant MMPFNs than on x86
This commit is contained in:
Jérôme Gardou 2021-05-25 10:44:11 +02:00 committed by Jérôme Gardou
parent f9ea58dc97
commit ed1038ff9c
2 changed files with 23 additions and 8 deletions

View file

@ -943,10 +943,6 @@ MmInitializeProcessAddressSpace(IN PEPROCESS Process,
ASSERT(Process->VadRoot.NumberGenericTableElements == 0); ASSERT(Process->VadRoot.NumberGenericTableElements == 0);
Process->VadRoot.BalancedRoot.u1.Parent = &Process->VadRoot.BalancedRoot; Process->VadRoot.BalancedRoot.u1.Parent = &Process->VadRoot.BalancedRoot;
#ifdef _M_AMD64
/* On x64 the PFNs for the initial process are already set up */
if (Process != &KiInitialProcess) {
#endif
/* Lock our working set */ /* Lock our working set */
MiLockProcessWorkingSet(Process, PsGetCurrentThread()); MiLockProcessWorkingSet(Process, PsGetCurrentThread());
@ -1014,9 +1010,6 @@ MmInitializeProcessAddressSpace(IN PEPROCESS Process,
/* Release the process working set */ /* Release the process working set */
MiUnlockProcessWorkingSet(Process, PsGetCurrentThread()); MiUnlockProcessWorkingSet(Process, PsGetCurrentThread());
#ifdef _M_AMD64
} /* On x64 the PFNs for the initial process are already set up */
#endif
#ifdef _M_AMD64 #ifdef _M_AMD64
/* On x64 we need a VAD for the shared user page */ /* On x64 we need a VAD for the shared user page */

View file

@ -252,6 +252,8 @@ MiInitializePageTable(VOID)
RtlZeroMemory(MiPteToAddress(PointerPxe), PAGE_SIZE); RtlZeroMemory(MiPteToAddress(PointerPxe), PAGE_SIZE);
} }
} }
PxePfn = PFN_FROM_PXE(MiAddressToPxe((PVOID)HYPER_SPACE));
PsGetCurrentProcess()->Pcb.DirectoryTableBase[1] = PxePfn << PAGE_SHIFT;
/* Map PPEs for paged pool */ /* Map PPEs for paged pool */
MiMapPPEs(MmPagedPoolStart, MmPagedPoolEnd); MiMapPPEs(MmPagedPoolStart, MmPagedPoolEnd);
@ -713,7 +715,6 @@ MiInitMachineDependent(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
// PrototypePte.u.ProtoAddress // PrototypePte.u.ProtoAddress
PrototypePte.u.Soft.PageFileHigh = MI_PTE_LOOKUP_NEEDED; PrototypePte.u.Soft.PageFileHigh = MI_PTE_LOOKUP_NEEDED;
MiInitializePageTable(); MiInitializePageTable();
MiBuildNonPagedPool(); MiBuildNonPagedPool();
@ -723,6 +724,27 @@ MiInitMachineDependent(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
/* Map the PFN database pages */ /* Map the PFN database pages */
MiBuildPfnDatabase(LoaderBlock); MiBuildPfnDatabase(LoaderBlock);
/* Reset the ref/share count so that MmInitializeProcessAddressSpace works */
PMMPFN Pfn = MiGetPfnEntry(PFN_FROM_PTE((PMMPTE)PXE_SELFMAP));
Pfn->u2.ShareCount = 0;
Pfn->u3.e2.ReferenceCount = 0;
Pfn = MiGetPfnEntry(PFN_FROM_PDE(MiAddressToPde((PVOID)HYPER_SPACE)));
Pfn->u2.ShareCount = 0;
Pfn->u3.e2.ReferenceCount = 0;
Pfn = MiGetPfnEntry(PFN_FROM_PPE(MiAddressToPpe((PVOID)HYPER_SPACE)));
Pfn->u2.ShareCount = 0;
Pfn->u3.e2.ReferenceCount = 0;
Pfn = MiGetPfnEntry(PFN_FROM_PXE(MiAddressToPxe((PVOID)HYPER_SPACE)));
Pfn->u2.ShareCount = 0;
Pfn->u3.e2.ReferenceCount = 0;
Pfn = MiGetPfnEntry(PFN_FROM_PTE(MiAddressToPte(MmWorkingSetList)));
Pfn->u2.ShareCount = 0;
Pfn->u3.e2.ReferenceCount = 0;
/* Initialize the nonpaged pool */ /* Initialize the nonpaged pool */
InitializePool(NonPagedPool, 0); InitializePool(NonPagedPool, 0);