https://git.reactos.org/?p=reactos.git;a=commitdiff;h=ed1038ff9c41e640a04ad…
commit ed1038ff9c41e640a04ad63b7c98f726b3f0ecad
Author: Jérôme Gardou <jerome.gardou(a)reactos.org>
AuthorDate: Tue May 25 10:44:11 2021 +0200
Commit: Jérôme Gardou <zefklop(a)users.noreply.github.com>
CommitDate: Wed Jun 9 11:27:18 2021 +0200
[NTOS:MM] Properly initialize initial process address space on amd64
By applying the same kludge on the relevant MMPFNs than on x86
---
ntoskrnl/mm/ARM3/procsup.c | 7 -------
ntoskrnl/mm/amd64/init.c | 24 +++++++++++++++++++++++-
2 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/ntoskrnl/mm/ARM3/procsup.c b/ntoskrnl/mm/ARM3/procsup.c
index 2fc8dccae54..0d46aa9c05f 100644
--- a/ntoskrnl/mm/ARM3/procsup.c
+++ b/ntoskrnl/mm/ARM3/procsup.c
@@ -943,10 +943,6 @@ MmInitializeProcessAddressSpace(IN PEPROCESS Process,
ASSERT(Process->VadRoot.NumberGenericTableElements == 0);
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 */
MiLockProcessWorkingSet(Process, PsGetCurrentThread());
@@ -1014,9 +1010,6 @@ MmInitializeProcessAddressSpace(IN PEPROCESS Process,
/* Release the process working set */
MiUnlockProcessWorkingSet(Process, PsGetCurrentThread());
-#ifdef _M_AMD64
- } /* On x64 the PFNs for the initial process are already set up */
-#endif
#ifdef _M_AMD64
/* On x64 we need a VAD for the shared user page */
diff --git a/ntoskrnl/mm/amd64/init.c b/ntoskrnl/mm/amd64/init.c
index eea9cc2c1bb..0c6a868b144 100644
--- a/ntoskrnl/mm/amd64/init.c
+++ b/ntoskrnl/mm/amd64/init.c
@@ -252,6 +252,8 @@ MiInitializePageTable(VOID)
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 */
MiMapPPEs(MmPagedPoolStart, MmPagedPoolEnd);
@@ -713,7 +715,6 @@ MiInitMachineDependent(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
// PrototypePte.u.ProtoAddress
PrototypePte.u.Soft.PageFileHigh = MI_PTE_LOOKUP_NEEDED;
-
MiInitializePageTable();
MiBuildNonPagedPool();
@@ -723,6 +724,27 @@ MiInitMachineDependent(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
/* Map the PFN database pages */
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 */
InitializePool(NonPagedPool, 0);