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.


svn path=/trunk/; revision=34876
This commit is contained in:
ReactOS Portable Systems Group 2008-07-28 00:43:57 +00:00
parent 487609a995
commit 71f2416876
3 changed files with 9 additions and 33 deletions

View file

@ -1569,7 +1569,7 @@ MiSyncThreadProcessViews(IN PVOID Process,
}
extern MADDRESS_SPACE MmKernelAddressSpace;
extern PMADDRESS_SPACE MmKernelAddressSpace;
FORCEINLINE
VOID
@ -1591,7 +1591,7 @@ FORCEINLINE
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 @@ FORCEINLINE
PMADDRESS_SPACE
MmGetKernelAddressSpace(VOID)
{
return &MmKernelAddressSpace;
return MmKernelAddressSpace;
}
#endif

View file

@ -19,39 +19,21 @@
/* GLOBALS ******************************************************************/
MADDRESS_SPACE MmKernelAddressSpace;
PMADDRESS_SPACE MmKernelAddressSpace;
ULONGLONG Cycles;
ULONG TimeDelta;
/* FUNCTIONS *****************************************************************/
VOID
INIT_FUNCTION
NTAPI
MmInitializeKernelAddressSpace(VOID)
{
MmInitializeAddressSpace(NULL, &MmKernelAddressSpace);
}
NTSTATUS
NTAPI
MmInitializeAddressSpace(PEPROCESS Process,
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;
}

View file

@ -368,6 +368,7 @@ NTAPI
MmInit1(VOID)
{
PLDR_DATA_TABLE_ENTRY LdrEntry;
LARGE_INTEGER Dummy;
/* Dump memory descriptors */
if (MiDbgEnableMdDump) MiDbgDumpMemoryDescriptors();
@ -395,7 +396,8 @@ MmInit1(VOID)
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 @@ NTAPI
MmInitSystem(IN ULONG Phase,
IN PLOADER_PARAMETER_BLOCK LoaderBlock)
{
ULONG Flags = 0;
if (Phase == 0)
{
/* Initialize Mm bootstrap */
@ -465,13 +466,6 @@ MmInitSystem(IN ULONG Phase,
/* 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);