[NTOS]: Take over MmInitializeProcessAddressSpace, MmInitializeHandBuiltProcess,...
authorSir Richard <sir_richard@svn.reactos.org>
Sat, 24 Jul 2010 15:01:05 +0000 (15:01 +0000)
committerSir Richard <sir_richard@svn.reactos.org>
Sat, 24 Jul 2010 15:01:05 +0000 (15:01 +0000)
[NTOS]: Prepare to take over MmCreateProcessAddressSpace.

svn path=/trunk/; revision=48231

reactos/ntoskrnl/mm/ARM3/pfnlist.c
reactos/ntoskrnl/mm/ARM3/procsup.c
reactos/ntoskrnl/mm/i386/page.c
reactos/ntoskrnl/mm/procsup.c

index fb24d9f..294f656 100644 (file)
@@ -700,8 +700,8 @@ MiInitializePfn(IN PFN_NUMBER PageFrameIndex,
     /* 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 */
index 00020a4..b4fa2de 100644 (file)
@@ -832,6 +832,165 @@ MmCreateTeb(IN PEPROCESS Process,
     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
index a675924..ac05ecc 100644 (file)
@@ -122,7 +122,7 @@ Mmi386ReleaseMmInfo(PEPROCESS Process)
     ULONG i;
     
     DPRINT("Mmi386ReleaseMmInfo(Process %x)\n",Process);
-    
+
     LdtDescriptor = (PUSHORT) &Process->Pcb.LdtDescriptor;
     LdtBase = LdtDescriptor[1] |
     ((LdtDescriptor[2] & 0xff) << 16) |
@@ -155,26 +155,6 @@ Mmi386ReleaseMmInfo(PEPROCESS Process)
     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
 NTAPI
 MmCreateProcessAddressSpace(IN ULONG MinWs,
index 8694acf..5867d29 100644 (file)
 #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
 MmCleanProcessAddressSpace(IN PEPROCESS Process)