Author: sir_richard Date: Sat Jul 24 15:01:05 2010 New Revision: 48231
URL: http://svn.reactos.org/svn/reactos?rev=48231&view=rev Log: [NTOS]: Take over MmInitializeProcessAddressSpace, MmInitializeHandBuiltProcess, MmInitializeHandBuiltProcess2 into ARM3, and cleanup the code. [NTOS]: Prepare to take over MmCreateProcessAddressSpace.
Modified: trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c trunk/reactos/ntoskrnl/mm/ARM3/procsup.c trunk/reactos/ntoskrnl/mm/i386/page.c trunk/reactos/ntoskrnl/mm/procsup.c
Modified: trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c?... ============================================================================== --- trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c [iso-8859-1] Sat Jul 24 15:01:05 2010 @@ -700,8 +700,8 @@ /* Check if this PFN is part of a valid address space */ if (PointerPte->u.Hard.Valid == 1) { - /* FIXME: TODO */ - ASSERT(FALSE); + /* Only valid from MmCreateProcessAddressSpace path */ + ASSERT(PsGetCurrentProcess()->Vm.WorkingSetSize == 0); }
/* Otherwise this is a fresh page -- set it up */
Modified: trunk/reactos/ntoskrnl/mm/ARM3/procsup.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/procsup.c?... ============================================================================== --- trunk/reactos/ntoskrnl/mm/ARM3/procsup.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/ARM3/procsup.c [iso-8859-1] Sat Jul 24 15:01:05 2010 @@ -832,6 +832,165 @@ return Status; }
+NTSTATUS +NTAPI +MmInitializeProcessAddressSpace(IN PEPROCESS Process, + IN PEPROCESS ProcessClone OPTIONAL, + IN PVOID Section OPTIONAL, + IN OUT PULONG Flags, + IN POBJECT_NAME_INFORMATION *AuditName OPTIONAL) +{ + NTSTATUS Status = STATUS_SUCCESS; + SIZE_T ViewSize = 0; + PVOID ImageBase = 0; + PROS_SECTION_OBJECT SectionObject = Section; + PMMPTE PointerPte; + KIRQL OldIrql; + PMMPDE PointerPde; + PFN_NUMBER PageFrameNumber; + UNICODE_STRING FileName; + PWCHAR Source; + PCHAR Destination; + USHORT Length = 0; + + /* We should have a PDE */ + ASSERT(Process->Pcb.DirectoryTableBase[0] != 0); + ASSERT(Process->PdeUpdateNeeded == FALSE); + + /* Attach to the process */ + KeAttachProcess(&Process->Pcb); + + /* The address space should now been in phase 1 or 0 */ + ASSERT(Process->AddressSpaceInitialized <= 1); + Process->AddressSpaceInitialized = 2; + + /* Initialize the Addresss Space lock */ + KeInitializeGuardedMutex(&Process->AddressCreationLock); + Process->Vm.WorkingSetExpansionLinks.Flink = NULL; + + /* Initialize AVL tree */ + ASSERT(Process->VadRoot.NumberGenericTableElements == 0); + Process->VadRoot.BalancedRoot.u1.Parent = &Process->VadRoot.BalancedRoot; + + /* Lock PFN database */ + OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock); + + /* Setup the PFN for the PDE base of this process */ + PointerPte = MiAddressToPte(PDE_BASE); + PageFrameNumber = PFN_FROM_PTE(PointerPte); + //MiInitializePfn(PageFrameNumber, PointerPte, TRUE); + + /* Do the same for hyperspace */ + PointerPde = MiAddressToPde(HYPER_SPACE); + PageFrameNumber = PFN_FROM_PTE(PointerPde); + //MiInitializePfn(PageFrameNumber, PointerPde, TRUE); + + /* Release PFN lock */ + KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql); + + /* Lock the VAD, ARM3-owned ranges away */ + MiRosTakeOverPebTebRanges(Process); + + /* Check if there's a Section Object */ + if (SectionObject) + { + /* Determine the image file name and save it to EPROCESS */ + FileName = SectionObject->FileObject->FileName; + Source = (PWCHAR)((PCHAR)FileName.Buffer + FileName.Length); + if (FileName.Buffer) + { + /* Loop the file name*/ + while (Source > FileName.Buffer) + { + /* Make sure this isn't a backslash */ + if (*--Source == OBJ_NAME_PATH_SEPARATOR) + { + /* If so, stop it here */ + Source++; + break; + } + else + { + /* Otherwise, keep going */ + Length++; + } + } + } + + /* Copy the to the process and truncate it to 15 characters if necessary */ + Destination = Process->ImageFileName; + Length = min(Length, sizeof(Process->ImageFileName) - 1); + while (Length--) *Destination++ = (UCHAR)*Source++; + *Destination = ANSI_NULL; + + /* Check if caller wants an audit name */ + if (AuditName) + { + /* Setup the audit name */ + Status = SeInitializeProcessAuditName(SectionObject->FileObject, + FALSE, + AuditName); + if (!NT_SUCCESS(Status)) + { + /* Fail */ + KeDetachProcess(); + return Status; + } + } + + /* Map the section */ + Status = MmMapViewOfSection(Section, + Process, + (PVOID*)&ImageBase, + 0, + 0, + NULL, + &ViewSize, + 0, + MEM_COMMIT, + PAGE_READWRITE); + + /* Save the pointer */ + Process->SectionBaseAddress = ImageBase; + } + + /* Be nice and detach */ + KeDetachProcess(); + + /* Return status to caller */ + return Status; +} + +NTSTATUS +NTAPI +MmInitializeHandBuiltProcess(IN PEPROCESS Process, + IN PULONG_PTR DirectoryTableBase) +{ + /* Share the directory base with the idle process */ + DirectoryTableBase[0] = PsGetCurrentProcess()->Pcb.DirectoryTableBase[0]; + DirectoryTableBase[1] = PsGetCurrentProcess()->Pcb.DirectoryTableBase[1]; + + /* Initialize the Addresss Space */ + KeInitializeGuardedMutex(&Process->AddressCreationLock); + KeInitializeSpinLock(&Process->HyperSpaceLock); + Process->Vm.WorkingSetExpansionLinks.Flink = NULL; + ASSERT(Process->VadRoot.NumberGenericTableElements == 0); + Process->VadRoot.BalancedRoot.u1.Parent = &Process->VadRoot.BalancedRoot; + + /* Done */ + Process->HasAddressSpace = TRUE;//?? + return STATUS_SUCCESS; +} + +NTSTATUS +NTAPI +MmInitializeHandBuiltProcess2(IN PEPROCESS Process) +{ + /* Lock the VAD, ARM3-owned ranges away */ + MiRosTakeOverPebTebRanges(Process); + return STATUS_SUCCESS; +} + /* SYSTEM CALLS ***************************************************************/
NTSTATUS
Modified: trunk/reactos/ntoskrnl/mm/i386/page.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/i386/page.c?rev... ============================================================================== --- trunk/reactos/ntoskrnl/mm/i386/page.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/i386/page.c [iso-8859-1] Sat Jul 24 15:01:05 2010 @@ -122,7 +122,7 @@ ULONG i;
DPRINT("Mmi386ReleaseMmInfo(Process %x)\n",Process); - + LdtDescriptor = (PUSHORT) &Process->Pcb.LdtDescriptor; LdtBase = LdtDescriptor[1] | ((LdtDescriptor[2] & 0xff) << 16) | @@ -153,26 +153,6 @@
DPRINT("Finished Mmi386ReleaseMmInfo()\n"); return(STATUS_SUCCESS); -} - -NTSTATUS -NTAPI -MmInitializeHandBuiltProcess(IN PEPROCESS Process, - IN PULONG DirectoryTableBase) -{ - /* Share the directory base with the idle process */ - DirectoryTableBase[0] = PsGetCurrentProcess()->Pcb.DirectoryTableBase[0]; - DirectoryTableBase[1] = PsGetCurrentProcess()->Pcb.DirectoryTableBase[1]; - - /* Initialize the Addresss Space */ - KeInitializeGuardedMutex(&Process->AddressCreationLock); - Process->Vm.WorkingSetExpansionLinks.Flink = NULL; - ASSERT(Process->VadRoot.NumberGenericTableElements == 0); - Process->VadRoot.BalancedRoot.u1.Parent = &Process->VadRoot.BalancedRoot; - - /* The process now has an address space */ - Process->HasAddressSpace = TRUE; - return STATUS_SUCCESS; }
BOOLEAN
Modified: trunk/reactos/ntoskrnl/mm/procsup.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/procsup.c?rev=4... ============================================================================== --- trunk/reactos/ntoskrnl/mm/procsup.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/procsup.c [iso-8859-1] Sat Jul 24 15:01:05 2010 @@ -13,133 +13,7 @@ #define NDEBUG #include <debug.h>
-VOID NTAPI MiRosTakeOverPebTebRanges(IN PEPROCESS Process); - /* FUNCTIONS *****************************************************************/ - -NTSTATUS -NTAPI -MmInitializeHandBuiltProcess2(IN PEPROCESS Process) -{ - /* Lock the VAD, ARM3-owned ranges away */ - MiRosTakeOverPebTebRanges(Process); - return STATUS_SUCCESS; -} - -NTSTATUS -NTAPI -MmInitializeProcessAddressSpace(IN PEPROCESS Process, - IN PEPROCESS ProcessClone OPTIONAL, - IN PVOID Section OPTIONAL, - IN OUT PULONG Flags, - IN POBJECT_NAME_INFORMATION *AuditName OPTIONAL) -{ - NTSTATUS Status = STATUS_SUCCESS; - PMMSUPPORT ProcessAddressSpace = &Process->Vm; - SIZE_T ViewSize = 0; - PVOID ImageBase = 0; - PROS_SECTION_OBJECT SectionObject = Section; - - /* Initialize the Addresss Space lock */ - KeInitializeGuardedMutex(&Process->AddressCreationLock); - Process->Vm.WorkingSetExpansionLinks.Flink = NULL; - - /* Initialize AVL tree */ - ASSERT(Process->VadRoot.NumberGenericTableElements == 0); - Process->VadRoot.BalancedRoot.u1.Parent = &Process->VadRoot.BalancedRoot; - - /* Acquire the Lock */ - MmLockAddressSpace(ProcessAddressSpace); - - /* Lock the VAD, ARM3-owned ranges away */ - MiRosTakeOverPebTebRanges(Process); - - /* The process now has an address space */ - Process->HasAddressSpace = TRUE; - - /* Check if there's a Section Object */ - if (SectionObject) - { - UNICODE_STRING FileName; - PWCHAR szSrc; - PCHAR szDest; - USHORT lnFName = 0; - - /* Unlock the Address Space */ - DPRINT("Unlocking\n"); - MmUnlockAddressSpace(ProcessAddressSpace); - - DPRINT("Mapping process image. Section: %p, Process: %p, ImageBase: %p\n", - SectionObject, Process, &ImageBase); - Status = MmMapViewOfSection(Section, - (PEPROCESS)Process, - (PVOID*)&ImageBase, - 0, - 0, - NULL, - &ViewSize, - 0, - MEM_COMMIT, - PAGE_READWRITE); - if (!NT_SUCCESS(Status)) - { - DPRINT1("Failed to map process Image\n"); - return Status; - } - - /* Save the pointer */ - Process->SectionBaseAddress = ImageBase; - - /* Determine the image file name and save it to EPROCESS */ - DPRINT("Getting Image name\n"); - FileName = SectionObject->FileObject->FileName; - szSrc = (PWCHAR)((PCHAR)FileName.Buffer + FileName.Length); - if (FileName.Buffer) - { - /* Loop the file name*/ - while (szSrc > FileName.Buffer) - { - /* Make sure this isn't a backslash */ - if (*--szSrc == OBJ_NAME_PATH_SEPARATOR) - { - /* If so, stop it here */ - szSrc++; - break; - } - else - { - /* Otherwise, keep going */ - lnFName++; - } - } - } - - /* Copy the to the process and truncate it to 15 characters if necessary */ - szDest = Process->ImageFileName; - lnFName = min(lnFName, sizeof(Process->ImageFileName) - 1); - while (lnFName--) *szDest++ = (UCHAR)*szSrc++; - *szDest = ANSI_NULL; - - /* Check if caller wants an audit name */ - if (AuditName) - { - /* Setup the audit name */ - SeInitializeProcessAuditName(SectionObject->FileObject, - FALSE, - AuditName); - } - - /* Return status to caller */ - return Status; - } - - /* Unlock the Address Space */ - DPRINT("Unlocking\n"); - MmUnlockAddressSpace(ProcessAddressSpace); - - /* Return status to caller */ - return Status; -}
VOID NTAPI