Author: ros-arm-bringup
Date: Sun Jul 27 20:11:19 2008
New Revision: 34879
URL: http://svn.reactos.org/svn/reactos?rev=34879&view=rev
Log:
The address space creation lock is a guarded mutex, not a pushlock, in NT 5.2. While it is commendable to attempt using Vista optimizations (it is a push lock on Vista) in order to speed up
the kernel, it is entirely stupid to do so by completing ignoring the ramifications of this change, and furthermore, to pollute the kernel with typecasts, as well as to introduce non-standard
behavior. Ironically it is ion himself who made this change.
Modified:
trunk/reactos/ntoskrnl/include/internal/mm.h
trunk/reactos/ntoskrnl/mm/i386/page.c
trunk/reactos/ntoskrnl/mm/procsup.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] Sun Jul 27 20:11:19 2008
@@ -1574,16 +1574,14 @@
VOID
MmLockAddressSpace(PMADDRESS_SPACE AddressSpace)
{
- KeEnterCriticalRegion();
- ExAcquirePushLockExclusive((PEX_PUSH_LOCK)&CONTAINING_RECORD(AddressSpace, EPROCESS, VadRoot)->AddressCreationLock);
+ KeAcquireGuardedMutex(&CONTAINING_RECORD(AddressSpace, EPROCESS, VadRoot)->AddressCreationLock);
}
FORCEINLINE
VOID
MmUnlockAddressSpace(PMADDRESS_SPACE AddressSpace)
{
- ExReleasePushLock((PEX_PUSH_LOCK)&CONTAINING_RECORD(AddressSpace, EPROCESS, VadRoot)->AddressCreationLock);
- KeLeaveCriticalRegion();
+ KeReleaseGuardedMutex(&CONTAINING_RECORD(AddressSpace, EPROCESS, VadRoot)->AddressCreationLock);
}
FORCEINLINE
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] Sun Jul 27 20:11:19 2008
@@ -196,6 +196,7 @@
*DirectoryTableBase = PsGetCurrentProcess()->Pcb.DirectoryTableBase;
/* Initialize the Addresss Space */
+ KeInitializeGuardedMutex(&Process->AddressCreationLock);
MmInitializeAddressSpace(Process, (PMADDRESS_SPACE)&Process->VadRoot);
/* The process now has an address space */
Modified: trunk/reactos/ntoskrnl/mm/procsup.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/procsup.c?rev=…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/procsup.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/procsup.c [iso-8859-1] Sun Jul 27 20:11:19 2008
@@ -520,6 +520,7 @@
BoundaryAddressMultiple.QuadPart = 0;
/* Initialize the Addresss Space */
+ KeInitializeGuardedMutex(&Process->AddressCreationLock);
MmInitializeAddressSpace(Process, ProcessAddressSpace);
/* Acquire the Lock */
Author: ros-arm-bringup
Date: Sun Jul 27 19:43:57 2008
New Revision: 34876
URL: http://svn.reactos.org/svn/reactos?rev=34876&view=rev
Log:
Looks like this address space nonsense made even less sense than originally understood. The kernel address space was something created very early-on, and associated with a global variable
that actually contained the address space itself (so it wasn't part of any process). Its locks however, were associated to the "current process", which, when this function is called, is the
idle process (which later is cloned into the initial system process). Shortly thereafter, the address space of the "current process" (still, at this point, the idle process) was initialized
with the function reserved for real processes (MmInitializeProcessAddressSpace), which among other things, performed a couple of user-mode mappings (which are irrelevant and should not be
part of the system process address space). This created a weird schism: the kernel address space was actually a global variable associated with no process at all, while the kernel process
had its own address space as well (which was not the kernel address space). It's a miracle this didn't screw anything up especially since whether or not the address space has an owner
determined the lowest address (which means that if the kernel process allocated a memory with its *own* address space, the code would think it was a user-mode process).
This patch gets rid of the kernel address space as a static structure, and instead makes it a pointer into the idle/system process' address space. It also gets rid of MmInitializeKernelAddresSpace
and instead makes use of the existing MmInitializeHandBuiltProcess, cleaning up the user-mode allocations previously made. Even though all address spaces now have an owner and are part of a
process, MmGetAddressSpaceOwner will still return NULL for now, to remain backwards compatible with legacy code.
Modified:
trunk/reactos/ntoskrnl/include/internal/mm.h
trunk/reactos/ntoskrnl/mm/aspace.c
trunk/reactos/ntoskrnl/mm/mminit.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] Sun Jul 27 19:43:57 2008
@@ -1569,7 +1569,7 @@
}
-extern MADDRESS_SPACE MmKernelAddressSpace;
+extern PMADDRESS_SPACE MmKernelAddressSpace;
FORCEINLINE
VOID
@@ -1591,7 +1591,7 @@
PEPROCESS
MmGetAddressSpaceOwner(IN PMADDRESS_SPACE AddressSpace)
{
- if (AddressSpace == &MmKernelAddressSpace) return NULL;
+ if (AddressSpace == MmKernelAddressSpace) return NULL;
return CONTAINING_RECORD(AddressSpace, EPROCESS, VadRoot);
}
@@ -1606,7 +1606,7 @@
PMADDRESS_SPACE
MmGetKernelAddressSpace(VOID)
{
- return &MmKernelAddressSpace;
+ return MmKernelAddressSpace;
}
#endif
Modified: trunk/reactos/ntoskrnl/mm/aspace.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/aspace.c?rev=3…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/aspace.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/aspace.c [iso-8859-1] Sun Jul 27 19:43:57 2008
@@ -19,20 +19,12 @@
/* GLOBALS ******************************************************************/
-MADDRESS_SPACE MmKernelAddressSpace;
+PMADDRESS_SPACE MmKernelAddressSpace;
ULONGLONG Cycles;
ULONG TimeDelta;
/* FUNCTIONS *****************************************************************/
-
-VOID
-INIT_FUNCTION
-NTAPI
-MmInitializeKernelAddressSpace(VOID)
-{
- MmInitializeAddressSpace(NULL, &MmKernelAddressSpace);
-}
NTSTATUS
NTAPI
@@ -40,18 +32,8 @@
PMADDRESS_SPACE AddressSpace)
{
AddressSpace->MemoryAreaRoot = NULL;
-
- if (Process != NULL)
- {
- AddressSpace->Lock = (PEX_PUSH_LOCK)&Process->AddressCreationLock;
- ExInitializePushLock((PULONG_PTR)AddressSpace->Lock);
- }
- else
- {
- AddressSpace->Lock = (PEX_PUSH_LOCK)&PsGetCurrentProcess()->AddressCreationLock;
- ExInitializePushLock((PULONG_PTR)AddressSpace->Lock);
- }
-
+ AddressSpace->Lock = (PEX_PUSH_LOCK)&Process->AddressCreationLock;
+ ExInitializePushLock((PULONG_PTR)AddressSpace->Lock);
return STATUS_SUCCESS;
}
Modified: trunk/reactos/ntoskrnl/mm/mminit.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/mminit.c?rev=3…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/mminit.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/mminit.c [iso-8859-1] Sun Jul 27 19:43:57 2008
@@ -368,6 +368,7 @@
MmInit1(VOID)
{
PLDR_DATA_TABLE_ENTRY LdrEntry;
+ LARGE_INTEGER Dummy;
/* Dump memory descriptors */
if (MiDbgEnableMdDump) MiDbgDumpMemoryDescriptors();
@@ -395,7 +396,8 @@
DbgPrint("Used memory %dKb\n", (MmNumberOfPhysicalPages * PAGE_SIZE) / 1024);
/* Initialize the kernel address space */
- MmInitializeKernelAddressSpace();
+ MmInitializeHandBuiltProcess(PsGetCurrentProcess(), &Dummy);
+ MmKernelAddressSpace = MmGetCurrentAddressSpace();
MmInitGlobalKernelPageDirectory();
/* Get kernel address boundaries */
@@ -456,7 +458,6 @@
MmInitSystem(IN ULONG Phase,
IN PLOADER_PARAMETER_BLOCK LoaderBlock)
{
- ULONG Flags = 0;
if (Phase == 0)
{
/* Initialize Mm bootstrap */
@@ -464,13 +465,6 @@
/* Initialize the Loader Lock */
KeInitializeMutant(&MmSystemLoadLock, FALSE);
-
- /* Initialize the address space for the system process */
- MmInitializeProcessAddressSpace(PsGetCurrentProcess(),
- NULL,
- NULL,
- &Flags,
- NULL);
/* Reload boot drivers */
MiReloadBootLoadedDrivers(LoaderBlock);