2005-07-31 12:11:56 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
2008-05-22 13:40:42 +00:00
|
|
|
* FILE: ntoskrnl/mm/procsup.c
|
2005-07-31 12:11:56 +00:00
|
|
|
* PURPOSE: Memory functions related to Processes
|
|
|
|
*
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
|
|
|
#include <ntoskrnl.h>
|
|
|
|
#define NDEBUG
|
2008-08-30 16:31:06 +00:00
|
|
|
#include <debug.h>
|
2005-07-31 12:11:56 +00:00
|
|
|
|
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
|
|
|
PVOID
|
2008-11-29 20:47:48 +00:00
|
|
|
NTAPI
|
2006-05-18 20:32:17 +00:00
|
|
|
MiCreatePebOrTeb(PEPROCESS Process,
|
2005-07-31 12:11:56 +00:00
|
|
|
PVOID BaseAddress)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
2009-04-27 10:12:57 +00:00
|
|
|
PMMSUPPORT ProcessAddressSpace = &Process->Vm;
|
2005-07-31 12:11:56 +00:00
|
|
|
PMEMORY_AREA MemoryArea;
|
|
|
|
PHYSICAL_ADDRESS BoundaryAddressMultiple;
|
|
|
|
PVOID AllocatedBase = BaseAddress;
|
|
|
|
BoundaryAddressMultiple.QuadPart = 0;
|
|
|
|
|
|
|
|
/* Acquire the Lock */
|
|
|
|
MmLockAddressSpace(ProcessAddressSpace);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a Peb or Teb.
|
|
|
|
* Loop until it works, decreasing by PAGE_SIZE each time. The logic here
|
|
|
|
* is that a PEB allocation should never fail since the address is free,
|
|
|
|
* while TEB allocation can fail, and we should simply try the address
|
|
|
|
* below. Is there a nicer way of doing this automagically? (ie: findning)
|
|
|
|
* a gap region? -- Alex
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
DPRINT("Trying to allocate: %x\n", AllocatedBase);
|
2005-11-13 17:28:24 +00:00
|
|
|
Status = MmCreateMemoryArea(ProcessAddressSpace,
|
2005-07-31 12:11:56 +00:00
|
|
|
MEMORY_AREA_PEB_OR_TEB,
|
|
|
|
&AllocatedBase,
|
|
|
|
PAGE_SIZE,
|
|
|
|
PAGE_READWRITE,
|
|
|
|
&MemoryArea,
|
|
|
|
TRUE,
|
2005-11-13 17:28:24 +00:00
|
|
|
0,
|
2005-07-31 12:11:56 +00:00
|
|
|
BoundaryAddressMultiple);
|
|
|
|
AllocatedBase = RVA(AllocatedBase, -PAGE_SIZE);
|
|
|
|
} while (Status != STATUS_SUCCESS);
|
|
|
|
|
|
|
|
/* Initialize the Region */
|
2005-11-28 23:43:40 +00:00
|
|
|
MmInitializeRegion(&MemoryArea->Data.VirtualMemoryData.RegionListHead,
|
2005-07-31 12:11:56 +00:00
|
|
|
PAGE_SIZE,
|
|
|
|
MEM_COMMIT,
|
|
|
|
PAGE_READWRITE);
|
|
|
|
|
|
|
|
/* Reserve the pages */
|
|
|
|
MmReserveSwapPages(PAGE_SIZE);
|
|
|
|
|
|
|
|
/* Unlock Address Space */
|
|
|
|
DPRINT("Returning\n");
|
|
|
|
MmUnlockAddressSpace(ProcessAddressSpace);
|
|
|
|
return RVA(AllocatedBase, PAGE_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
2008-11-29 20:47:48 +00:00
|
|
|
NTAPI
|
2006-05-18 20:32:17 +00:00
|
|
|
MmDeleteTeb(PEPROCESS Process,
|
2005-07-31 12:11:56 +00:00
|
|
|
PTEB Teb)
|
|
|
|
{
|
2009-04-27 10:12:57 +00:00
|
|
|
PMMSUPPORT ProcessAddressSpace = &Process->Vm;
|
2005-08-01 00:06:18 +00:00
|
|
|
PMEMORY_AREA MemoryArea;
|
2005-07-31 12:11:56 +00:00
|
|
|
|
|
|
|
/* Lock the Address Space */
|
|
|
|
MmLockAddressSpace(ProcessAddressSpace);
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-08-01 00:06:18 +00:00
|
|
|
MemoryArea = MmLocateMemoryAreaByAddress(ProcessAddressSpace, (PVOID)Teb);
|
|
|
|
if (MemoryArea)
|
|
|
|
{
|
|
|
|
/* Delete the Teb */
|
|
|
|
MmFreeVirtualMemory(Process, MemoryArea);
|
|
|
|
}
|
2005-07-31 12:11:56 +00:00
|
|
|
|
|
|
|
/* Unlock the Address Space */
|
|
|
|
MmUnlockAddressSpace(ProcessAddressSpace);
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
- PS_UNKNOWN_VALUE determines if the process should be created with large pages: rename to PS_LARGE_PAGES
- Do Address Space initialization as per "Windows Internals II" slides, either for the Boot, System, Cloned User or New User Process cases.
- Rename MmCreateProcessAddressSpace to MmInitializeProcessAddressSpace, and MmCopyMmInfo to MmCreateProcessAddressSpace. What ReactOS did is correct as per "Windows Internals II", but the names were inverted.
- Clone the Object Table if we are the boot process, and only initialize part of the address space (since we don't need things like guard page, TEB, etc), however, do initialize and map the shared user data section.
- Make the initial system process and idle process share the same page directory instead of creating a new one.
- Use the same priority class as the parent process, if the process was in the idle or below-normal priority class.
- Only duplicate handles if the caller requested it, instead of always duplicating the process's handles!
- Generate a null image file name for system processes.
- Rename ObpCreateHandleTable to ObInitProcess and better handle race and out-of-memory conditions. Detect if auditing required, but don't do anything about it.
- Initialize the Idle/System process address space much earlier in the boot process, in MmInitSystem.
Thanks to Alex for providing various information, and answering all my questions.
svn path=/trunk/; revision=29223
2007-09-26 20:55:26 +00:00
|
|
|
NTAPI
|
|
|
|
MmInitializeHandBuiltProcess2(IN PEPROCESS Process)
|
|
|
|
{
|
|
|
|
PVOID BaseAddress;
|
|
|
|
PMEMORY_AREA MemoryArea;
|
|
|
|
PHYSICAL_ADDRESS BoundaryAddressMultiple;
|
|
|
|
NTSTATUS Status;
|
2009-04-27 10:12:57 +00:00
|
|
|
PMMSUPPORT ProcessAddressSpace = &Process->Vm;
|
2007-11-25 17:52:02 +00:00
|
|
|
BoundaryAddressMultiple.QuadPart = 0;
|
2007-10-19 23:21:45 +00:00
|
|
|
|
- PS_UNKNOWN_VALUE determines if the process should be created with large pages: rename to PS_LARGE_PAGES
- Do Address Space initialization as per "Windows Internals II" slides, either for the Boot, System, Cloned User or New User Process cases.
- Rename MmCreateProcessAddressSpace to MmInitializeProcessAddressSpace, and MmCopyMmInfo to MmCreateProcessAddressSpace. What ReactOS did is correct as per "Windows Internals II", but the names were inverted.
- Clone the Object Table if we are the boot process, and only initialize part of the address space (since we don't need things like guard page, TEB, etc), however, do initialize and map the shared user data section.
- Make the initial system process and idle process share the same page directory instead of creating a new one.
- Use the same priority class as the parent process, if the process was in the idle or below-normal priority class.
- Only duplicate handles if the caller requested it, instead of always duplicating the process's handles!
- Generate a null image file name for system processes.
- Rename ObpCreateHandleTable to ObInitProcess and better handle race and out-of-memory conditions. Detect if auditing required, but don't do anything about it.
- Initialize the Idle/System process address space much earlier in the boot process, in MmInitSystem.
Thanks to Alex for providing various information, and answering all my questions.
svn path=/trunk/; revision=29223
2007-09-26 20:55:26 +00:00
|
|
|
/* Create the shared data page */
|
|
|
|
BaseAddress = (PVOID)USER_SHARED_DATA;
|
|
|
|
Status = MmCreateMemoryArea(ProcessAddressSpace,
|
|
|
|
MEMORY_AREA_SHARED_DATA,
|
|
|
|
&BaseAddress,
|
|
|
|
PAGE_SIZE,
|
|
|
|
PAGE_EXECUTE_READ,
|
|
|
|
&MemoryArea,
|
|
|
|
FALSE,
|
|
|
|
0,
|
|
|
|
BoundaryAddressMultiple);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
MmInitializeProcessAddressSpace(IN PEPROCESS Process,
|
2007-09-27 18:07:44 +00:00
|
|
|
IN PEPROCESS ProcessClone OPTIONAL,
|
- PS_UNKNOWN_VALUE determines if the process should be created with large pages: rename to PS_LARGE_PAGES
- Do Address Space initialization as per "Windows Internals II" slides, either for the Boot, System, Cloned User or New User Process cases.
- Rename MmCreateProcessAddressSpace to MmInitializeProcessAddressSpace, and MmCopyMmInfo to MmCreateProcessAddressSpace. What ReactOS did is correct as per "Windows Internals II", but the names were inverted.
- Clone the Object Table if we are the boot process, and only initialize part of the address space (since we don't need things like guard page, TEB, etc), however, do initialize and map the shared user data section.
- Make the initial system process and idle process share the same page directory instead of creating a new one.
- Use the same priority class as the parent process, if the process was in the idle or below-normal priority class.
- Only duplicate handles if the caller requested it, instead of always duplicating the process's handles!
- Generate a null image file name for system processes.
- Rename ObpCreateHandleTable to ObInitProcess and better handle race and out-of-memory conditions. Detect if auditing required, but don't do anything about it.
- Initialize the Idle/System process address space much earlier in the boot process, in MmInitSystem.
Thanks to Alex for providing various information, and answering all my questions.
svn path=/trunk/; revision=29223
2007-09-26 20:55:26 +00:00
|
|
|
IN PVOID Section OPTIONAL,
|
2007-09-27 18:07:44 +00:00
|
|
|
IN OUT PULONG Flags,
|
- PS_UNKNOWN_VALUE determines if the process should be created with large pages: rename to PS_LARGE_PAGES
- Do Address Space initialization as per "Windows Internals II" slides, either for the Boot, System, Cloned User or New User Process cases.
- Rename MmCreateProcessAddressSpace to MmInitializeProcessAddressSpace, and MmCopyMmInfo to MmCreateProcessAddressSpace. What ReactOS did is correct as per "Windows Internals II", but the names were inverted.
- Clone the Object Table if we are the boot process, and only initialize part of the address space (since we don't need things like guard page, TEB, etc), however, do initialize and map the shared user data section.
- Make the initial system process and idle process share the same page directory instead of creating a new one.
- Use the same priority class as the parent process, if the process was in the idle or below-normal priority class.
- Only duplicate handles if the caller requested it, instead of always duplicating the process's handles!
- Generate a null image file name for system processes.
- Rename ObpCreateHandleTable to ObInitProcess and better handle race and out-of-memory conditions. Detect if auditing required, but don't do anything about it.
- Initialize the Idle/System process address space much earlier in the boot process, in MmInitSystem.
Thanks to Alex for providing various information, and answering all my questions.
svn path=/trunk/; revision=29223
2007-09-26 20:55:26 +00:00
|
|
|
IN POBJECT_NAME_INFORMATION *AuditName OPTIONAL)
|
2005-07-31 12:11:56 +00:00
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
2009-04-27 10:12:57 +00:00
|
|
|
PMMSUPPORT ProcessAddressSpace = &Process->Vm;
|
2005-07-31 12:11:56 +00:00
|
|
|
PVOID BaseAddress;
|
|
|
|
PMEMORY_AREA MemoryArea;
|
|
|
|
PHYSICAL_ADDRESS BoundaryAddressMultiple;
|
2005-11-28 23:43:40 +00:00
|
|
|
SIZE_T ViewSize = 0;
|
2005-07-31 12:11:56 +00:00
|
|
|
PVOID ImageBase = 0;
|
- PS_UNKNOWN_VALUE determines if the process should be created with large pages: rename to PS_LARGE_PAGES
- Do Address Space initialization as per "Windows Internals II" slides, either for the Boot, System, Cloned User or New User Process cases.
- Rename MmCreateProcessAddressSpace to MmInitializeProcessAddressSpace, and MmCopyMmInfo to MmCreateProcessAddressSpace. What ReactOS did is correct as per "Windows Internals II", but the names were inverted.
- Clone the Object Table if we are the boot process, and only initialize part of the address space (since we don't need things like guard page, TEB, etc), however, do initialize and map the shared user data section.
- Make the initial system process and idle process share the same page directory instead of creating a new one.
- Use the same priority class as the parent process, if the process was in the idle or below-normal priority class.
- Only duplicate handles if the caller requested it, instead of always duplicating the process's handles!
- Generate a null image file name for system processes.
- Rename ObpCreateHandleTable to ObInitProcess and better handle race and out-of-memory conditions. Detect if auditing required, but don't do anything about it.
- Initialize the Idle/System process address space much earlier in the boot process, in MmInitSystem.
Thanks to Alex for providing various information, and answering all my questions.
svn path=/trunk/; revision=29223
2007-09-26 20:55:26 +00:00
|
|
|
PROS_SECTION_OBJECT SectionObject = Section;
|
2005-07-31 12:11:56 +00:00
|
|
|
BoundaryAddressMultiple.QuadPart = 0;
|
|
|
|
|
2008-07-28 01:49:23 +00:00
|
|
|
/* Initialize the Addresss Space lock */
|
2008-07-28 01:11:19 +00:00
|
|
|
KeInitializeGuardedMutex(&Process->AddressCreationLock);
|
2009-04-27 10:12:57 +00:00
|
|
|
Process->Vm.WorkingSetExpansionLinks.Flink = NULL;
|
2005-07-31 12:11:56 +00:00
|
|
|
|
2009-05-28 18:59:26 +00:00
|
|
|
/* Initialize AVL tree */
|
|
|
|
ASSERT(Process->VadRoot.NumberGenericTableElements == 0);
|
|
|
|
Process->VadRoot.BalancedRoot.u1.Parent = &Process->VadRoot.BalancedRoot;
|
|
|
|
|
2005-07-31 12:11:56 +00:00
|
|
|
/* Acquire the Lock */
|
|
|
|
MmLockAddressSpace(ProcessAddressSpace);
|
|
|
|
|
|
|
|
/* Protect the highest 64KB of the process address space */
|
|
|
|
BaseAddress = (PVOID)MmUserProbeAddress;
|
2005-11-13 17:28:24 +00:00
|
|
|
Status = MmCreateMemoryArea(ProcessAddressSpace,
|
2005-07-31 12:11:56 +00:00
|
|
|
MEMORY_AREA_NO_ACCESS,
|
|
|
|
&BaseAddress,
|
|
|
|
0x10000,
|
|
|
|
PAGE_NOACCESS,
|
|
|
|
&MemoryArea,
|
|
|
|
FALSE,
|
2005-11-13 17:28:24 +00:00
|
|
|
0,
|
2005-07-31 12:11:56 +00:00
|
|
|
BoundaryAddressMultiple);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to protect last 64KB\n");
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Protect the 60KB above the shared user page */
|
|
|
|
BaseAddress = (char*)USER_SHARED_DATA + PAGE_SIZE;
|
2005-11-13 17:28:24 +00:00
|
|
|
Status = MmCreateMemoryArea(ProcessAddressSpace,
|
2005-07-31 12:11:56 +00:00
|
|
|
MEMORY_AREA_NO_ACCESS,
|
|
|
|
&BaseAddress,
|
|
|
|
0x10000 - PAGE_SIZE,
|
|
|
|
PAGE_NOACCESS,
|
|
|
|
&MemoryArea,
|
|
|
|
FALSE,
|
2005-11-13 17:28:24 +00:00
|
|
|
0,
|
2005-07-31 12:11:56 +00:00
|
|
|
BoundaryAddressMultiple);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to protect the memory above the shared user page\n");
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create the shared data page */
|
|
|
|
BaseAddress = (PVOID)USER_SHARED_DATA;
|
2005-11-13 17:28:24 +00:00
|
|
|
Status = MmCreateMemoryArea(ProcessAddressSpace,
|
2005-07-31 12:11:56 +00:00
|
|
|
MEMORY_AREA_SHARED_DATA,
|
|
|
|
&BaseAddress,
|
|
|
|
PAGE_SIZE,
|
2005-11-13 17:28:24 +00:00
|
|
|
PAGE_EXECUTE_READ,
|
2005-07-31 12:11:56 +00:00
|
|
|
&MemoryArea,
|
|
|
|
FALSE,
|
2005-11-13 17:28:24 +00:00
|
|
|
0,
|
2005-07-31 12:11:56 +00:00
|
|
|
BoundaryAddressMultiple);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to create Shared User Data\n");
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* The process now has an address space */
|
|
|
|
Process->HasAddressSpace = TRUE;
|
|
|
|
|
2005-07-31 12:11:56 +00:00
|
|
|
/* Check if there's a Section Object */
|
- PS_UNKNOWN_VALUE determines if the process should be created with large pages: rename to PS_LARGE_PAGES
- Do Address Space initialization as per "Windows Internals II" slides, either for the Boot, System, Cloned User or New User Process cases.
- Rename MmCreateProcessAddressSpace to MmInitializeProcessAddressSpace, and MmCopyMmInfo to MmCreateProcessAddressSpace. What ReactOS did is correct as per "Windows Internals II", but the names were inverted.
- Clone the Object Table if we are the boot process, and only initialize part of the address space (since we don't need things like guard page, TEB, etc), however, do initialize and map the shared user data section.
- Make the initial system process and idle process share the same page directory instead of creating a new one.
- Use the same priority class as the parent process, if the process was in the idle or below-normal priority class.
- Only duplicate handles if the caller requested it, instead of always duplicating the process's handles!
- Generate a null image file name for system processes.
- Rename ObpCreateHandleTable to ObInitProcess and better handle race and out-of-memory conditions. Detect if auditing required, but don't do anything about it.
- Initialize the Idle/System process address space much earlier in the boot process, in MmInitSystem.
Thanks to Alex for providing various information, and answering all my questions.
svn path=/trunk/; revision=29223
2007-09-26 20:55:26 +00:00
|
|
|
if (SectionObject)
|
2005-07-31 12:11:56 +00:00
|
|
|
{
|
|
|
|
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",
|
- PS_UNKNOWN_VALUE determines if the process should be created with large pages: rename to PS_LARGE_PAGES
- Do Address Space initialization as per "Windows Internals II" slides, either for the Boot, System, Cloned User or New User Process cases.
- Rename MmCreateProcessAddressSpace to MmInitializeProcessAddressSpace, and MmCopyMmInfo to MmCreateProcessAddressSpace. What ReactOS did is correct as per "Windows Internals II", but the names were inverted.
- Clone the Object Table if we are the boot process, and only initialize part of the address space (since we don't need things like guard page, TEB, etc), however, do initialize and map the shared user data section.
- Make the initial system process and idle process share the same page directory instead of creating a new one.
- Use the same priority class as the parent process, if the process was in the idle or below-normal priority class.
- Only duplicate handles if the caller requested it, instead of always duplicating the process's handles!
- Generate a null image file name for system processes.
- Rename ObpCreateHandleTable to ObInitProcess and better handle race and out-of-memory conditions. Detect if auditing required, but don't do anything about it.
- Initialize the Idle/System process address space much earlier in the boot process, in MmInitSystem.
Thanks to Alex for providing various information, and answering all my questions.
svn path=/trunk/; revision=29223
2007-09-26 20:55:26 +00:00
|
|
|
SectionObject, Process, &ImageBase);
|
2005-07-31 12:11:56 +00:00
|
|
|
Status = MmMapViewOfSection(Section,
|
2006-05-10 17:47:44 +00:00
|
|
|
(PEPROCESS)Process,
|
2005-07-31 12:11:56 +00:00
|
|
|
(PVOID*)&ImageBase,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
&ViewSize,
|
|
|
|
0,
|
|
|
|
MEM_COMMIT,
|
|
|
|
PAGE_READWRITE);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to map process Image\n");
|
2005-11-13 17:28:24 +00:00
|
|
|
return Status;
|
2005-07-31 12:11:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Save the pointer */
|
|
|
|
Process->SectionBaseAddress = ImageBase;
|
|
|
|
|
|
|
|
/* Determine the image file name and save it to EPROCESS */
|
|
|
|
DPRINT("Getting Image name\n");
|
- PS_UNKNOWN_VALUE determines if the process should be created with large pages: rename to PS_LARGE_PAGES
- Do Address Space initialization as per "Windows Internals II" slides, either for the Boot, System, Cloned User or New User Process cases.
- Rename MmCreateProcessAddressSpace to MmInitializeProcessAddressSpace, and MmCopyMmInfo to MmCreateProcessAddressSpace. What ReactOS did is correct as per "Windows Internals II", but the names were inverted.
- Clone the Object Table if we are the boot process, and only initialize part of the address space (since we don't need things like guard page, TEB, etc), however, do initialize and map the shared user data section.
- Make the initial system process and idle process share the same page directory instead of creating a new one.
- Use the same priority class as the parent process, if the process was in the idle or below-normal priority class.
- Only duplicate handles if the caller requested it, instead of always duplicating the process's handles!
- Generate a null image file name for system processes.
- Rename ObpCreateHandleTable to ObInitProcess and better handle race and out-of-memory conditions. Detect if auditing required, but don't do anything about it.
- Initialize the Idle/System process address space much earlier in the boot process, in MmInitSystem.
Thanks to Alex for providing various information, and answering all my questions.
svn path=/trunk/; revision=29223
2007-09-26 20:55:26 +00:00
|
|
|
FileName = SectionObject->FileObject->FileName;
|
2008-05-22 13:40:42 +00:00
|
|
|
szSrc = (PWCHAR)((PCHAR)FileName.Buffer + FileName.Length);
|
|
|
|
if (FileName.Buffer)
|
2005-07-31 12:11:56 +00:00
|
|
|
{
|
2008-05-22 13:40:42 +00:00
|
|
|
/* Loop the file name*/
|
|
|
|
while (szSrc > FileName.Buffer)
|
2005-07-31 12:11:56 +00:00
|
|
|
{
|
2008-05-22 13:40:42 +00:00
|
|
|
/* 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++;
|
|
|
|
}
|
2005-07-31 12:11:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy the to the process and truncate it to 15 characters if necessary */
|
|
|
|
szDest = Process->ImageFileName;
|
|
|
|
lnFName = min(lnFName, sizeof(Process->ImageFileName) - 1);
|
2006-07-27 00:22:36 +00:00
|
|
|
while (lnFName--) *szDest++ = (UCHAR)*szSrc++;
|
2008-02-11 17:45:56 +00:00
|
|
|
*szDest = ANSI_NULL;
|
2006-07-27 00:22:36 +00:00
|
|
|
|
|
|
|
/* Check if caller wants an audit name */
|
|
|
|
if (AuditName)
|
|
|
|
{
|
|
|
|
/* Setup the audit name */
|
- PS_UNKNOWN_VALUE determines if the process should be created with large pages: rename to PS_LARGE_PAGES
- Do Address Space initialization as per "Windows Internals II" slides, either for the Boot, System, Cloned User or New User Process cases.
- Rename MmCreateProcessAddressSpace to MmInitializeProcessAddressSpace, and MmCopyMmInfo to MmCreateProcessAddressSpace. What ReactOS did is correct as per "Windows Internals II", but the names were inverted.
- Clone the Object Table if we are the boot process, and only initialize part of the address space (since we don't need things like guard page, TEB, etc), however, do initialize and map the shared user data section.
- Make the initial system process and idle process share the same page directory instead of creating a new one.
- Use the same priority class as the parent process, if the process was in the idle or below-normal priority class.
- Only duplicate handles if the caller requested it, instead of always duplicating the process's handles!
- Generate a null image file name for system processes.
- Rename ObpCreateHandleTable to ObInitProcess and better handle race and out-of-memory conditions. Detect if auditing required, but don't do anything about it.
- Initialize the Idle/System process address space much earlier in the boot process, in MmInitSystem.
Thanks to Alex for providing various information, and answering all my questions.
svn path=/trunk/; revision=29223
2007-09-26 20:55:26 +00:00
|
|
|
SeInitializeProcessAuditName(SectionObject->FileObject,
|
2006-07-27 00:22:36 +00:00
|
|
|
FALSE,
|
|
|
|
AuditName);
|
|
|
|
}
|
2005-07-31 12:11:56 +00:00
|
|
|
|
|
|
|
/* Return status to caller */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
|
|
|
/* Unlock the Address Space */
|
|
|
|
DPRINT("Unlocking\n");
|
|
|
|
MmUnlockAddressSpace(ProcessAddressSpace);
|
|
|
|
|
|
|
|
/* Return status to caller */
|
|
|
|
return Status;
|
|
|
|
}
|
2006-07-09 18:54:13 +00:00
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
MmCleanProcessAddressSpace(IN PEPROCESS Process)
|
|
|
|
{
|
|
|
|
/* FIXME: Add part of MmDeleteProcessAddressSpace here */
|
|
|
|
}
|
|
|
|
|
2007-10-19 23:21:45 +00:00
|
|
|
NTSTATUS
|
2006-07-09 18:54:13 +00:00
|
|
|
NTAPI
|
|
|
|
MmDeleteProcessAddressSpace(PEPROCESS Process)
|
|
|
|
{
|
|
|
|
PVOID Address;
|
|
|
|
PMEMORY_AREA MemoryArea;
|
|
|
|
|
|
|
|
DPRINT("MmDeleteProcessAddressSpace(Process %x (%s))\n", Process,
|
|
|
|
Process->ImageFileName);
|
|
|
|
|
2009-04-27 10:12:57 +00:00
|
|
|
MmLockAddressSpace(&Process->Vm);
|
2006-07-09 18:54:13 +00:00
|
|
|
|
2009-04-27 10:12:57 +00:00
|
|
|
while ((MemoryArea = (PMEMORY_AREA)Process->Vm.WorkingSetExpansionLinks.Flink) != NULL)
|
2006-07-09 18:54:13 +00:00
|
|
|
{
|
|
|
|
switch (MemoryArea->Type)
|
|
|
|
{
|
|
|
|
case MEMORY_AREA_SECTION_VIEW:
|
|
|
|
Address = (PVOID)MemoryArea->StartingAddress;
|
2009-04-27 10:12:57 +00:00
|
|
|
MmUnlockAddressSpace(&Process->Vm);
|
2006-07-09 18:54:13 +00:00
|
|
|
MmUnmapViewOfSection(Process, Address);
|
2009-04-27 10:12:57 +00:00
|
|
|
MmLockAddressSpace(&Process->Vm);
|
2006-07-09 18:54:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MEMORY_AREA_VIRTUAL_MEMORY:
|
|
|
|
case MEMORY_AREA_PEB_OR_TEB:
|
|
|
|
MmFreeVirtualMemory(Process, MemoryArea);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MEMORY_AREA_SHARED_DATA:
|
|
|
|
case MEMORY_AREA_NO_ACCESS:
|
2009-04-27 10:12:57 +00:00
|
|
|
MmFreeMemoryArea(&Process->Vm,
|
2006-07-09 18:54:13 +00:00
|
|
|
MemoryArea,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MEMORY_AREA_MDL_MAPPING:
|
2008-08-24 15:48:05 +00:00
|
|
|
KeBugCheck(PROCESS_HAS_LOCKED_PAGES);
|
2006-07-09 18:54:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2008-12-07 18:05:28 +00:00
|
|
|
KeBugCheck(MEMORY_MANAGEMENT);
|
2006-07-09 18:54:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Mmi386ReleaseMmInfo(Process);
|
|
|
|
|
2009-04-27 10:12:57 +00:00
|
|
|
MmUnlockAddressSpace(&Process->Vm);
|
2006-07-09 18:54:13 +00:00
|
|
|
|
|
|
|
DPRINT("Finished MmReleaseMmInfo()\n");
|
|
|
|
return(STATUS_SUCCESS);
|
|
|
|
}
|
2008-05-22 13:40:42 +00:00
|
|
|
|