Author: ion
Date: Thu Jan 26 21:16:59 2012
New Revision: 55227
URL:
http://svn.reactos.org/svn/reactos?rev=55227&view=rev
Log:
Laa-a-a-a-dies and gentlemen.....
For your unique, viewing and executing pleasure..
For one time only....by popular demand....
The one...
The only...
The unforgettable, unforgivable...
Meanest, baddest, piece of code around...
He's back..... with a vengeance...
The ultimate...
Mega...
Uber..
Amazing...
HACK
OF
DOOOOOOOOOOOOOOOOOOOOOOOOOOOOOM
</applause>
Modified:
trunk/reactos/ntoskrnl/include/internal/mm.h
trunk/reactos/ntoskrnl/ke/i386/thrdini.c
trunk/reactos/ntoskrnl/ke/procobj.c
trunk/reactos/ntoskrnl/ke/thrdobj.c
trunk/reactos/ntoskrnl/ke/thrdschd.c
trunk/reactos/ntoskrnl/mm/i386/page.c
trunk/reactos/ntoskrnl/mm/mmfault.c
Modified: trunk/reactos/ntoskrnl/include/internal/mm.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] Thu Jan 26 21:16:59 2012
@@ -5,6 +5,20 @@
/* TYPES *********************************************************************/
struct _EPROCESS;
+
+/* ReactOS Mm Hacks */
+VOID
+FASTCALL
+MiSyncForProcessAttach(
+ IN PKTHREAD NextThread,
+ IN PEPROCESS Process
+);
+
+VOID
+FASTCALL
+MiSyncForContextSwitch(
+ IN PKTHREAD Thread
+);
extern PMMSUPPORT MmKernelAddressSpace;
extern PFN_COUNT MiFreeSwapPages;
Modified: trunk/reactos/ntoskrnl/ke/i386/thrdini.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/thrdini.c…
==============================================================================
--- trunk/reactos/ntoskrnl/ke/i386/thrdini.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ke/i386/thrdini.c [iso-8859-1] Thu Jan 26 21:16:59 2012
@@ -433,6 +433,9 @@
/* Get thread pointers */
OldThread = (PKTHREAD)(OldThreadAndApcFlag & ~3);
NewThread = Pcr->PrcbData.CurrentThread;
+
+ /* ReactOS Mm Hack */
+ MiSyncForContextSwitch(NewThread);
/* Get the old thread and set its kernel stack */
OldThread->KernelStack = SwitchFrame;
Modified: trunk/reactos/ntoskrnl/ke/procobj.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/procobj.c?rev=…
==============================================================================
--- trunk/reactos/ntoskrnl/ke/procobj.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ke/procobj.c [iso-8859-1] Thu Jan 26 21:16:59 2012
@@ -97,6 +97,9 @@
/* Release lock */
KiReleaseApcLockFromDpcLevel(ApcLock);
+ /* Make sure that we are in the right page directory (ReactOS Mm Hack) */
+ MiSyncForProcessAttach(Thread, (PEPROCESS)Process);
+
/* Swap Processes */
KiSwapProcess(Process, SavedApcState->Process);
@@ -615,6 +618,9 @@
/* Release lock */
KiReleaseApcLockFromDpcLevel(&ApcLock);
+ /* Make sure that we are in the right page directory (ReactOS Mm Hack) */
+ MiSyncForProcessAttach(Thread, (PEPROCESS)Process);
+
/* Swap Processes */
KiSwapProcess(Thread->ApcState.Process, Process);
@@ -782,6 +788,9 @@
/* Release lock */
KiReleaseApcLockFromDpcLevel(&ApcLock);
+ /* Make sure that we are in the right page directory (ReactOS Mm Hack) */
+ MiSyncForProcessAttach(Thread, (PEPROCESS)Process);
+
/* Swap Processes */
KiSwapProcess(Thread->ApcState.Process, Process);
Modified: trunk/reactos/ntoskrnl/ke/thrdobj.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/thrdobj.c?rev=…
==============================================================================
--- trunk/reactos/ntoskrnl/ke/thrdobj.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ke/thrdobj.c [iso-8859-1] Thu Jan 26 21:16:59 2012
@@ -856,6 +856,9 @@
Thread->StackBase = KernelStack;
Thread->StackLimit = (ULONG_PTR)KernelStack - KERNEL_STACK_SIZE;
Thread->KernelStackResident = TRUE;
+
+ /* Make sure that we are in the right page directory (ReactOS Mm Hack) */
+ MiSyncForProcessAttach(Thread, (PEPROCESS)Process);
/* Enter SEH to avoid crashes due to user mode */
Status = STATUS_SUCCESS;
Modified: trunk/reactos/ntoskrnl/ke/thrdschd.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/thrdschd.c?rev…
==============================================================================
--- trunk/reactos/ntoskrnl/ke/thrdschd.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ke/thrdschd.c [iso-8859-1] Thu Jan 26 21:16:59 2012
@@ -394,6 +394,9 @@
/* Save the wait IRQL */
WaitIrql = CurrentThread->WaitIrql;
+ /* REACTOS Mm Hack of Doom */
+ MiSyncForContextSwitch(NextThread);
+
/* Swap contexts */
ApcState = KiSwapContext(WaitIrql, CurrentThread);
@@ -790,6 +793,9 @@
/* Sanity check */
ASSERT(OldIrql <= DISPATCH_LEVEL);
+ /* REACTOS Mm Hack of Doom */
+ MiSyncForContextSwitch(NextThread);
+
/* Swap to new thread */
KiSwapContext(APC_LEVEL, Thread);
Status = STATUS_SUCCESS;
Modified: trunk/reactos/ntoskrnl/mm/i386/page.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/i386/page.c?re…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/i386/page.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/i386/page.c [iso-8859-1] Thu Jan 26 21:16:59 2012
@@ -1029,6 +1029,54 @@
}
VOID
+NTAPI
+MmUpdatePageDir(PEPROCESS Process, PVOID Address, ULONG Size)
+{
+ ULONG StartOffset, EndOffset, Offset;
+ PULONG Pde;
+
+ //
+ // Check if the process isn't there anymore
+ // This is probably a bad sign, since it means the caller is setting cr3 to
+ // 0 or something...
+ //
+ if ((PTE_TO_PFN(Process->Pcb.DirectoryTableBase[0]) == 0) && (Process !=
PsGetCurrentProcess()))
+ {
+ DPRINT1("Process: %16s is dead: %p\n", Process->ImageFileName,
Process->Pcb.DirectoryTableBase[0]);
+ ASSERT(FALSE);
+ return;
+ }
+
+ if (Address < MmSystemRangeStart)
+ {
+ KeBugCheck(MEMORY_MANAGEMENT);
+ }
+
+ StartOffset = ADDR_TO_PDE_OFFSET(Address);
+ EndOffset = ADDR_TO_PDE_OFFSET((PVOID)((ULONG_PTR)Address + Size));
+
+ if (Process != NULL && Process != PsGetCurrentProcess())
+ {
+ Pde =
MmCreateHyperspaceMapping(PTE_TO_PFN(Process->Pcb.DirectoryTableBase[0]));
+ }
+ else
+ {
+ Pde = (PULONG)PAGEDIRECTORY_MAP;
+ }
+ for (Offset = StartOffset; Offset <= EndOffset; Offset++)
+ {
+ if (Offset != ADDR_TO_PDE_OFFSET(PAGETABLE_MAP))
+ {
+ InterlockedCompareExchangePte(&Pde[Offset],
MmGlobalKernelPageDirectory[Offset], 0);
+ }
+ }
+ if (Pde != (PULONG)PAGEDIRECTORY_MAP)
+ {
+ MmDeleteHyperspaceMapping(Pde);
+ }
+}
+
+VOID
INIT_FUNCTION
NTAPI
MmInitGlobalKernelPageDirectory(VOID)
Modified: trunk/reactos/ntoskrnl/mm/mmfault.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/mmfault.c?rev=…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/mmfault.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/mmfault.c [iso-8859-1] Thu Jan 26 21:16:59 2012
@@ -19,6 +19,41 @@
#include "ARM3/miarm.h"
/* PRIVATE FUNCTIONS **********************************************************/
+
+VOID
+FASTCALL
+MiSyncForProcessAttach(IN PKTHREAD Thread,
+ IN PEPROCESS Process)
+{
+ PETHREAD Ethread = CONTAINING_RECORD(Thread, ETHREAD, Tcb);
+ //DPRINT1("Hack sync for process: %p and thread: %p\n", Process, Thread);
+ //DPRINT1("Thread stack hack: %p %d\n", Thread->StackLimit,
Thread->LargeStack);
+
+ /* Hack Sync because Mm is broken */
+ MmUpdatePageDir(Process, Ethread, sizeof(ETHREAD));
+ MmUpdatePageDir(Process, Ethread->ThreadsProcess, sizeof(EPROCESS));
+ MmUpdatePageDir(Process,
+ (PVOID)Thread->StackLimit,
+ Thread->LargeStack ?
+ KERNEL_LARGE_STACK_SIZE : KERNEL_STACK_SIZE);
+}
+
+VOID
+FASTCALL
+MiSyncForContextSwitch(IN PKTHREAD Thread)
+{
+ PVOID Process = PsGetCurrentProcess();
+ PETHREAD Ethread = CONTAINING_RECORD(Thread, ETHREAD, Tcb);
+ //DPRINT1("Hack sync for thread: %p and process: %p\n", Thread, Process);
+ //DPRINT1("Thread stack hack: %p %d\n", Thread->StackLimit,
Thread->LargeStack);
+
+ /* Hack Sync because Mm is broken */
+ MmUpdatePageDir(Process, Ethread->ThreadsProcess, sizeof(EPROCESS));
+ MmUpdatePageDir(Process,
+ (PVOID)Thread->StackLimit,
+ Thread->LargeStack ?
+ KERNEL_LARGE_STACK_SIZE : KERNEL_STACK_SIZE);
+}
NTSTATUS
NTAPI