https://git.reactos.org/?p=reactos.git;a=commitdiff;h=9095dbf5a5e877fae5a62…
commit 9095dbf5a5e877fae5a62554d6a774adf35cb672
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Sat Feb 10 22:45:45 2018 +0100
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Sun Nov 1 09:32:27 2020 +0100
[NTOS:MM:X64] Implement MmCreatePageFileMapping and MmDeletePageFileMapping
---
ntoskrnl/mm/amd64/page.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 47 insertions(+), 2 deletions(-)
diff --git a/ntoskrnl/mm/amd64/page.c b/ntoskrnl/mm/amd64/page.c
index 0559de76b88..6b311fb34da 100644
--- a/ntoskrnl/mm/amd64/page.c
+++ b/ntoskrnl/mm/amd64/page.c
@@ -462,7 +462,23 @@ NTAPI
MmDeletePageFileMapping(PEPROCESS Process, PVOID Address,
SWAPENTRY* SwapEntry)
{
- UNIMPLEMENTED;
+ PMMPTE Pte;
+
+ Pte = MiGetPteForProcess(Process, Address, FALSE);
+ if (Pte == NULL)
+ {
+ *SwapEntry = 0;
+ return;
+ }
+
+ if (Pte->u.Trans.Valid || !Pte->u.Trans.Transition)
+ {
+ DPRINT1("Pte %x (want not 1 and 0x800)\n", Pte);
+ KeBugCheck(MEMORY_MANAGEMENT);
+ }
+
+ *SwapEntry = Pte->u.Long >> 1;
+ MI_ERASE_PTE(Pte);
}
NTSTATUS
@@ -471,7 +487,36 @@ MmCreatePageFileMapping(PEPROCESS Process,
PVOID Address,
SWAPENTRY SwapEntry)
{
- UNIMPLEMENTED;
+ PMMPTE Pte;
+ MMPTE PteValue;
+
+ if (Process == NULL && Address < MmSystemRangeStart)
+ {
+ DPRINT1("No process\n");
+ KeBugCheck(MEMORY_MANAGEMENT);
+ }
+ if (Process != NULL && Address >= MmSystemRangeStart)
+ {
+ DPRINT1("Setting kernel address with process context\n");
+ KeBugCheck(MEMORY_MANAGEMENT);
+ }
+
+ if (SwapEntry & (1ull << 63))
+ {
+ KeBugCheck(MEMORY_MANAGEMENT);
+ }
+
+ /* Allocate a PTE */
+ Pte = MiGetPteForProcess(Process, Address, TRUE);
+ if (Pte == NULL)
+ {
+ return STATUS_UNSUCCESSFUL;
+ }
+
+ NT_ASSERT(Pte->u.Long == 0);
+ PteValue.u.Long = SwapEntry << 1;
+ MI_WRITE_INVALID_PTE(Pte, PteValue);
+
return STATUS_UNSUCCESSFUL;
}