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);