[NTOS]: Take over MmInitializeProcessAddressSpace, MmInitializeHandBuiltProcess, MmInitializeHandBuiltProcess2 into ARM3, and cleanup the code.

[NTOS]: Prepare to take over MmCreateProcessAddressSpace.

svn path=/trunk/; revision=48231
This commit is contained in:
Sir Richard 2010-07-24 15:01:05 +00:00
parent 3bb2ea0d09
commit 7ea7b76e51
4 changed files with 162 additions and 149 deletions

View 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 */

View 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

View 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,

View file

@ -13,134 +13,8 @@
#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)