2006-09-17 05:20:24 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2005-01-26 13:58:37 +00:00
|
|
|
* FILE: ntoskrnl/ps/psmgr.c
|
2006-09-17 05:20:24 +00:00
|
|
|
* PURPOSE: Process Manager: Initialization Code
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
1998-08-25 04:27:26 +00:00
|
|
|
*/
|
|
|
|
|
2006-09-17 05:20:24 +00:00
|
|
|
/* INCLUDES ******************************************************************/
|
1998-08-25 04:27:26 +00:00
|
|
|
|
2004-08-15 16:39:12 +00:00
|
|
|
#include <ntoskrnl.h>
|
2001-05-01 23:08:21 +00:00
|
|
|
#define NDEBUG
|
2008-08-30 16:31:06 +00:00
|
|
|
#include <debug.h>
|
1999-11-24 11:51:55 +00:00
|
|
|
|
2006-10-08 02:10:34 +00:00
|
|
|
extern ULONG ExpInitializationPhase;
|
|
|
|
|
2010-09-24 17:02:13 +00:00
|
|
|
PVOID KeUserPopEntrySListEnd;
|
|
|
|
PVOID KeUserPopEntrySListFault;
|
|
|
|
PVOID KeUserPopEntrySListResume;
|
|
|
|
|
2006-09-16 20:37:49 +00:00
|
|
|
GENERIC_MAPPING PspProcessMapping =
|
|
|
|
{
|
2005-04-18 02:12:30 +00:00
|
|
|
STANDARD_RIGHTS_READ | PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
|
|
|
|
STANDARD_RIGHTS_WRITE | PROCESS_CREATE_PROCESS | PROCESS_CREATE_THREAD |
|
|
|
|
PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_DUP_HANDLE |
|
2005-05-09 01:38:29 +00:00
|
|
|
PROCESS_TERMINATE | PROCESS_SET_QUOTA | PROCESS_SET_INFORMATION |
|
2005-04-29 16:41:52 +00:00
|
|
|
PROCESS_SUSPEND_RESUME,
|
2005-04-18 02:12:30 +00:00
|
|
|
STANDARD_RIGHTS_EXECUTE | SYNCHRONIZE,
|
2006-09-16 20:37:49 +00:00
|
|
|
PROCESS_ALL_ACCESS
|
|
|
|
};
|
2005-04-18 02:12:30 +00:00
|
|
|
|
2006-09-16 20:37:49 +00:00
|
|
|
GENERIC_MAPPING PspThreadMapping =
|
|
|
|
{
|
2005-04-18 04:46:06 +00:00
|
|
|
STANDARD_RIGHTS_READ | THREAD_GET_CONTEXT | THREAD_QUERY_INFORMATION,
|
|
|
|
STANDARD_RIGHTS_WRITE | THREAD_TERMINATE | THREAD_SUSPEND_RESUME |
|
|
|
|
THREAD_ALERT | THREAD_SET_INFORMATION | THREAD_SET_CONTEXT,
|
|
|
|
STANDARD_RIGHTS_EXECUTE | SYNCHRONIZE,
|
2006-09-16 20:37:49 +00:00
|
|
|
THREAD_ALL_ACCESS
|
|
|
|
};
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-09-16 20:37:49 +00:00
|
|
|
PVOID PspSystemDllBase;
|
|
|
|
PVOID PspSystemDllSection;
|
|
|
|
PVOID PspSystemDllEntryPoint;
|
2005-04-22 12:52:25 +00:00
|
|
|
|
2006-11-12 22:36:21 +00:00
|
|
|
UNICODE_STRING PsNtDllPathName =
|
2015-03-16 03:14:16 +00:00
|
|
|
RTL_CONSTANT_STRING(L"\\SystemRoot\\System32\\ntdll.dll");
|
2006-11-12 22:36:21 +00:00
|
|
|
|
2006-09-16 20:37:49 +00:00
|
|
|
PHANDLE_TABLE PspCidTable;
|
1998-08-25 04:27:26 +00:00
|
|
|
|
2006-09-16 20:37:49 +00:00
|
|
|
PEPROCESS PsInitialSystemProcess = NULL;
|
|
|
|
PEPROCESS PsIdleProcess = NULL;
|
2015-02-26 01:59:05 +00:00
|
|
|
HANDLE PspInitialSystemProcessHandle = NULL;
|
2006-09-12 13:54:52 +00:00
|
|
|
|
2006-09-16 20:37:49 +00:00
|
|
|
ULONG PsMinimumWorkingSet, PsMaximumWorkingSet;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
LIST_ENTRY List;
|
|
|
|
KGUARDED_MUTEX Lock;
|
|
|
|
} PspWorkingSetChangeHead;
|
|
|
|
ULONG PspDefaultPagedLimit, PspDefaultNonPagedLimit, PspDefaultPagefileLimit;
|
|
|
|
BOOLEAN PspDoingGiveBacks;
|
|
|
|
|
2006-09-17 05:20:24 +00:00
|
|
|
/* PRIVATE FUNCTIONS *********************************************************/
|
2006-09-16 20:37:49 +00:00
|
|
|
|
2022-11-28 23:49:33 +00:00
|
|
|
static CODE_SEG("INIT")
|
2006-09-17 05:20:24 +00:00
|
|
|
NTSTATUS
|
2022-11-28 23:49:33 +00:00
|
|
|
PspLookupSystemDllEntryPoint(
|
|
|
|
_In_ PCSTR Name,
|
|
|
|
_Out_ PVOID* EntryPoint)
|
2006-09-17 05:20:24 +00:00
|
|
|
{
|
2022-11-28 23:49:33 +00:00
|
|
|
/* Call the internal API */
|
|
|
|
return RtlpFindExportedRoutineByName(PspSystemDllBase,
|
|
|
|
Name,
|
|
|
|
EntryPoint,
|
|
|
|
NULL,
|
|
|
|
STATUS_PROCEDURE_NOT_FOUND);
|
2006-09-17 05:20:24 +00:00
|
|
|
}
|
2006-09-12 13:54:52 +00:00
|
|
|
|
2022-11-28 23:49:33 +00:00
|
|
|
static CODE_SEG("INIT")
|
2006-09-17 05:20:24 +00:00
|
|
|
NTSTATUS
|
|
|
|
PspLookupKernelUserEntryPoints(VOID)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
2006-09-12 13:54:52 +00:00
|
|
|
|
2006-09-17 05:20:24 +00:00
|
|
|
/* Get user-mode APC trampoline */
|
2007-02-23 07:56:01 +00:00
|
|
|
Status = PspLookupSystemDllEntryPoint("KiUserApcDispatcher",
|
2006-09-17 05:20:24 +00:00
|
|
|
&KeUserApcDispatcher);
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
|
|
|
|
/* Get user-mode exception dispatcher */
|
2007-02-23 07:56:01 +00:00
|
|
|
Status = PspLookupSystemDllEntryPoint("KiUserExceptionDispatcher",
|
2006-09-17 05:20:24 +00:00
|
|
|
&KeUserExceptionDispatcher);
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
|
|
|
|
/* Get user-mode callback dispatcher */
|
2007-02-23 07:56:01 +00:00
|
|
|
Status = PspLookupSystemDllEntryPoint("KiUserCallbackDispatcher",
|
2006-09-17 05:20:24 +00:00
|
|
|
&KeUserCallbackDispatcher);
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
|
|
|
|
/* Get user-mode exception raise trampoline */
|
2007-02-23 07:56:01 +00:00
|
|
|
Status = PspLookupSystemDllEntryPoint("KiRaiseUserExceptionDispatcher",
|
2006-09-17 05:20:24 +00:00
|
|
|
&KeRaiseUserExceptionDispatcher);
|
2006-10-04 16:00:36 +00:00
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
|
2010-09-24 17:02:13 +00:00
|
|
|
/* Get user-mode SLIST exception functions for page fault rollback race hack */
|
|
|
|
Status = PspLookupSystemDllEntryPoint("ExpInterlockedPopEntrySListEnd",
|
|
|
|
&KeUserPopEntrySListEnd);
|
|
|
|
if (!NT_SUCCESS(Status)) { DPRINT1("this not found\n"); return Status; }
|
|
|
|
Status = PspLookupSystemDllEntryPoint("ExpInterlockedPopEntrySListFault",
|
|
|
|
&KeUserPopEntrySListFault);
|
|
|
|
if (!NT_SUCCESS(Status)) { DPRINT1("this not found\n"); return Status; }
|
|
|
|
Status = PspLookupSystemDllEntryPoint("ExpInterlockedPopEntrySListResume",
|
|
|
|
&KeUserPopEntrySListResume);
|
|
|
|
if (!NT_SUCCESS(Status)) { DPRINT1("this not found\n"); return Status; }
|
|
|
|
|
|
|
|
/* On x86, there are multiple ways to do a system call, find the right stubs */
|
|
|
|
#if defined(_X86_)
|
2006-10-04 16:00:36 +00:00
|
|
|
/* Check if this is a machine that supports SYSENTER */
|
|
|
|
if (KeFeatureBits & KF_FAST_SYSCALL)
|
|
|
|
{
|
|
|
|
/* Get user-mode sysenter stub */
|
2011-01-12 13:40:34 +00:00
|
|
|
SharedUserData->SystemCall = (PsNtosImageBase >> (PAGE_SHIFT + 1));
|
2007-02-23 07:56:01 +00:00
|
|
|
Status = PspLookupSystemDllEntryPoint("KiFastSystemCall",
|
2006-10-04 16:00:36 +00:00
|
|
|
(PVOID)&SharedUserData->
|
|
|
|
SystemCall);
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
|
|
|
|
/* Get user-mode sysenter return stub */
|
2007-02-23 07:56:01 +00:00
|
|
|
Status = PspLookupSystemDllEntryPoint("KiFastSystemCallRet",
|
2006-10-04 16:00:36 +00:00
|
|
|
(PVOID)&SharedUserData->
|
|
|
|
SystemCallReturn);
|
2010-09-10 21:01:59 +00:00
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
2006-10-04 16:00:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Get the user-mode interrupt stub */
|
2007-02-23 07:56:01 +00:00
|
|
|
Status = PspLookupSystemDllEntryPoint("KiIntSystemCall",
|
2006-10-04 16:00:36 +00:00
|
|
|
(PVOID)&SharedUserData->
|
|
|
|
SystemCall);
|
2010-09-10 21:01:59 +00:00
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
2006-10-04 16:00:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the test instruction */
|
2010-09-10 21:01:59 +00:00
|
|
|
SharedUserData->TestRetInstruction = 0xC3;
|
2010-09-24 17:02:13 +00:00
|
|
|
#endif
|
2006-10-04 16:00:36 +00:00
|
|
|
|
|
|
|
/* Return the status */
|
2006-09-17 05:20:24 +00:00
|
|
|
return Status;
|
|
|
|
}
|
2006-09-16 20:37:49 +00:00
|
|
|
|
|
|
|
NTSTATUS
|
2005-09-13 23:28:21 +00:00
|
|
|
NTAPI
|
2006-09-17 05:20:24 +00:00
|
|
|
PspMapSystemDll(IN PEPROCESS Process,
|
2007-09-26 16:41:35 +00:00
|
|
|
IN PVOID *DllBase,
|
|
|
|
IN BOOLEAN UseLargePages)
|
2006-09-17 05:20:24 +00:00
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
2008-12-03 17:28:59 +00:00
|
|
|
LARGE_INTEGER Offset = {{0, 0}};
|
2006-09-17 05:20:24 +00:00
|
|
|
SIZE_T ViewSize = 0;
|
|
|
|
PVOID ImageBase = 0;
|
2015-09-05 11:49:54 +00:00
|
|
|
|
2006-09-17 05:20:24 +00:00
|
|
|
/* Map the System DLL */
|
|
|
|
Status = MmMapViewOfSection(PspSystemDllSection,
|
|
|
|
Process,
|
|
|
|
(PVOID*)&ImageBase,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
&Offset,
|
|
|
|
&ViewSize,
|
|
|
|
ViewShare,
|
|
|
|
0,
|
|
|
|
PAGE_READWRITE);
|
2007-09-26 16:41:35 +00:00
|
|
|
if (Status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
/* Normalize status code */
|
|
|
|
Status = STATUS_CONFLICTING_ADDRESSES;
|
|
|
|
}
|
2015-09-05 11:49:54 +00:00
|
|
|
|
2006-09-17 05:20:24 +00:00
|
|
|
/* Write the image base and return status */
|
|
|
|
if (DllBase) *DllBase = ImageBase;
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2020-10-06 19:44:01 +00:00
|
|
|
CODE_SEG("INIT")
|
2006-09-17 05:20:24 +00:00
|
|
|
NTSTATUS
|
2005-09-13 23:28:21 +00:00
|
|
|
NTAPI
|
2006-09-17 05:20:24 +00:00
|
|
|
PsLocateSystemDll(VOID)
|
|
|
|
{
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
IO_STATUS_BLOCK IoStatusBlock;
|
|
|
|
HANDLE FileHandle, SectionHandle;
|
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG_PTR HardErrorParameters;
|
|
|
|
ULONG HardErrorResponse;
|
|
|
|
|
|
|
|
/* Locate and open NTDLL to determine ImageBase and LdrStartup */
|
2006-11-12 22:36:21 +00:00
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&PsNtDllPathName,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2006-09-17 05:20:24 +00:00
|
|
|
Status = ZwOpenFile(&FileHandle,
|
|
|
|
FILE_READ_ACCESS,
|
|
|
|
&ObjectAttributes,
|
|
|
|
&IoStatusBlock,
|
|
|
|
FILE_SHARE_READ,
|
|
|
|
0);
|
2006-10-08 02:10:34 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Failed, bugcheck */
|
|
|
|
KeBugCheckEx(PROCESS1_INITIALIZATION_FAILED, Status, 2, 0, 0);
|
|
|
|
}
|
2006-09-17 05:20:24 +00:00
|
|
|
|
2008-07-20 04:38:26 +00:00
|
|
|
/* Check if the image is valid */
|
2006-10-08 02:10:34 +00:00
|
|
|
Status = MmCheckSystemImage(FileHandle, TRUE);
|
2006-09-17 05:20:24 +00:00
|
|
|
if (Status == STATUS_IMAGE_CHECKSUM_MISMATCH)
|
|
|
|
{
|
|
|
|
/* Raise a hard error */
|
2006-11-12 22:36:21 +00:00
|
|
|
HardErrorParameters = (ULONG_PTR)&PsNtDllPathName;
|
2006-09-17 05:20:24 +00:00
|
|
|
NtRaiseHardError(Status,
|
|
|
|
1,
|
|
|
|
1,
|
|
|
|
&HardErrorParameters,
|
|
|
|
OptionOk,
|
|
|
|
&HardErrorResponse);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a section for NTDLL */
|
|
|
|
Status = ZwCreateSection(&SectionHandle,
|
|
|
|
SECTION_ALL_ACCESS,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
PAGE_EXECUTE,
|
|
|
|
SEC_IMAGE,
|
|
|
|
FileHandle);
|
|
|
|
ZwClose(FileHandle);
|
2006-10-08 02:10:34 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Failed, bugcheck */
|
|
|
|
KeBugCheckEx(PROCESS1_INITIALIZATION_FAILED, Status, 3, 0, 0);
|
|
|
|
}
|
2006-09-17 05:20:24 +00:00
|
|
|
|
|
|
|
/* Reference the Section */
|
|
|
|
Status = ObReferenceObjectByHandle(SectionHandle,
|
|
|
|
SECTION_ALL_ACCESS,
|
|
|
|
MmSectionObjectType,
|
|
|
|
KernelMode,
|
|
|
|
(PVOID*)&PspSystemDllSection,
|
|
|
|
NULL);
|
|
|
|
ZwClose(SectionHandle);
|
2006-10-08 02:10:34 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Failed, bugcheck */
|
|
|
|
KeBugCheckEx(PROCESS1_INITIALIZATION_FAILED, Status, 4, 0, 0);
|
|
|
|
}
|
|
|
|
|
2006-09-17 05:20:24 +00:00
|
|
|
/* Map it */
|
2007-09-26 16:41:35 +00:00
|
|
|
Status = PspMapSystemDll(PsGetCurrentProcess(), &PspSystemDllBase, FALSE);
|
2006-10-08 02:10:34 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Failed, bugcheck */
|
|
|
|
KeBugCheckEx(PROCESS1_INITIALIZATION_FAILED, Status, 5, 0, 0);
|
|
|
|
}
|
2006-09-17 05:20:24 +00:00
|
|
|
|
2006-10-08 02:10:34 +00:00
|
|
|
/* Return status */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2020-10-06 19:44:01 +00:00
|
|
|
CODE_SEG("INIT")
|
2006-10-08 02:10:34 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
PspInitializeSystemDll(VOID)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
/* Get user-mode startup thunk */
|
2007-02-23 07:56:01 +00:00
|
|
|
Status = PspLookupSystemDllEntryPoint("LdrInitializeThunk",
|
|
|
|
&PspSystemDllEntryPoint);
|
2006-10-08 02:10:34 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Failed, bugcheck */
|
|
|
|
KeBugCheckEx(PROCESS1_INITIALIZATION_FAILED, Status, 7, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get all the other entrypoints */
|
|
|
|
Status = PspLookupKernelUserEntryPoints();
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Failed, bugcheck */
|
|
|
|
KeBugCheckEx(PROCESS1_INITIALIZATION_FAILED, Status, 8, 0, 0);
|
|
|
|
}
|
|
|
|
|
2009-10-04 16:53:15 +00:00
|
|
|
/* Let KD know we are done */
|
|
|
|
KdUpdateDataBlock();
|
|
|
|
|
2006-10-08 02:10:34 +00:00
|
|
|
/* Return status */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2020-10-06 19:44:01 +00:00
|
|
|
CODE_SEG("INIT")
|
2006-10-08 02:10:34 +00:00
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
2015-09-03 23:57:39 +00:00
|
|
|
PspInitPhase1(VOID)
|
2006-10-08 02:10:34 +00:00
|
|
|
{
|
|
|
|
/* Initialize the System DLL and return status of operation */
|
|
|
|
if (!NT_SUCCESS(PspInitializeSystemDll())) return FALSE;
|
|
|
|
return TRUE;
|
2006-09-17 05:20:24 +00:00
|
|
|
}
|
2005-08-07 22:48:07 +00:00
|
|
|
|
2020-10-06 19:44:01 +00:00
|
|
|
CODE_SEG("INIT")
|
2006-09-16 20:37:49 +00:00
|
|
|
BOOLEAN
|
2005-09-13 23:28:21 +00:00
|
|
|
NTAPI
|
2007-01-25 01:13:09 +00:00
|
|
|
PspInitPhase0(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
|
2005-04-18 04:46:06 +00:00
|
|
|
{
|
2006-09-16 20:37:49 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
HANDLE SysThreadHandle;
|
|
|
|
PETHREAD SysThread;
|
|
|
|
MM_SYSTEMSIZE SystemSize;
|
|
|
|
UNICODE_STRING Name;
|
|
|
|
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
|
2007-01-18 09:44:49 +00:00
|
|
|
ULONG i;
|
2006-09-16 20:37:49 +00:00
|
|
|
|
|
|
|
/* Get the system size */
|
|
|
|
SystemSize = MmQuerySystemSize();
|
|
|
|
|
|
|
|
/* Setup some memory options */
|
|
|
|
PspDefaultPagefileLimit = -1;
|
|
|
|
switch (SystemSize)
|
|
|
|
{
|
|
|
|
/* Medimum systems */
|
|
|
|
case MmMediumSystem:
|
2005-04-18 04:46:06 +00:00
|
|
|
|
2006-09-16 20:37:49 +00:00
|
|
|
/* Increase the WS sizes a bit */
|
|
|
|
PsMinimumWorkingSet += 10;
|
|
|
|
PsMaximumWorkingSet += 100;
|
2005-04-18 04:46:06 +00:00
|
|
|
|
2006-09-16 20:37:49 +00:00
|
|
|
/* Large systems */
|
|
|
|
case MmLargeSystem:
|
2005-04-18 04:46:06 +00:00
|
|
|
|
2006-09-16 20:37:49 +00:00
|
|
|
/* Increase the WS sizes a bit more */
|
|
|
|
PsMinimumWorkingSet += 30;
|
|
|
|
PsMaximumWorkingSet += 300;
|
2005-04-18 04:46:06 +00:00
|
|
|
|
2006-09-16 20:37:49 +00:00
|
|
|
/* Small and other systems */
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-01-18 09:44:49 +00:00
|
|
|
/* Setup callbacks */
|
|
|
|
for (i = 0; i < PSP_MAX_CREATE_THREAD_NOTIFY; i++)
|
|
|
|
{
|
|
|
|
ExInitializeCallBack(&PspThreadNotifyRoutine[i]);
|
|
|
|
}
|
|
|
|
for (i = 0; i < PSP_MAX_CREATE_PROCESS_NOTIFY; i++)
|
|
|
|
{
|
|
|
|
ExInitializeCallBack(&PspProcessNotifyRoutine[i]);
|
|
|
|
}
|
|
|
|
for (i = 0; i < PSP_MAX_LOAD_IMAGE_NOTIFY; i++)
|
|
|
|
{
|
|
|
|
ExInitializeCallBack(&PspLoadImageNotifyRoutine[i]);
|
|
|
|
}
|
|
|
|
|
2006-09-16 20:37:49 +00:00
|
|
|
/* Setup the quantum table */
|
|
|
|
PsChangeQuantumTable(FALSE, PsRawPrioritySeparation);
|
|
|
|
|
|
|
|
/* Set quota settings */
|
|
|
|
if (!PspDefaultPagedLimit) PspDefaultPagedLimit = 0;
|
|
|
|
if (!PspDefaultNonPagedLimit) PspDefaultNonPagedLimit = 0;
|
|
|
|
if (!(PspDefaultNonPagedLimit) && !(PspDefaultPagedLimit))
|
2005-06-21 23:42:58 +00:00
|
|
|
{
|
2006-09-16 20:37:49 +00:00
|
|
|
/* Enable give-backs */
|
|
|
|
PspDoingGiveBacks = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Disable them */
|
|
|
|
PspDoingGiveBacks = FALSE;
|
|
|
|
}
|
2005-04-18 02:12:30 +00:00
|
|
|
|
2006-09-16 20:37:49 +00:00
|
|
|
/* Now multiply limits by 1MB */
|
|
|
|
PspDefaultPagedLimit <<= 20;
|
|
|
|
PspDefaultNonPagedLimit <<= 20;
|
2009-09-27 20:07:43 +00:00
|
|
|
if (PspDefaultPagefileLimit != MAXULONG) PspDefaultPagefileLimit <<= 20;
|
2006-09-16 20:37:49 +00:00
|
|
|
|
|
|
|
/* Initialize the Active Process List */
|
|
|
|
InitializeListHead(&PsActiveProcessHead);
|
|
|
|
KeInitializeGuardedMutex(&PspActiveProcessMutex);
|
|
|
|
|
|
|
|
/* Get the idle process */
|
|
|
|
PsIdleProcess = PsGetCurrentProcess();
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-09-16 20:37:49 +00:00
|
|
|
/* Setup the locks */
|
|
|
|
PsIdleProcess->ProcessLock.Value = 0;
|
|
|
|
ExInitializeRundownProtection(&PsIdleProcess->RundownProtect);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-09-16 20:37:49 +00:00
|
|
|
/* Initialize the thread list */
|
|
|
|
InitializeListHead(&PsIdleProcess->ThreadListHead);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-09-16 20:37:49 +00:00
|
|
|
/* Clear kernel time */
|
|
|
|
PsIdleProcess->Pcb.KernelTime = 0;
|
2005-08-07 22:48:07 +00:00
|
|
|
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-10 18:40:30 +00:00
|
|
|
/* Initialize Object Initializer */
|
2006-09-16 20:37:49 +00:00
|
|
|
RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
|
|
|
|
ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
|
2012-09-02 22:06:42 +00:00
|
|
|
ObjectTypeInitializer.InvalidAttributes = OBJ_PERMANENT |
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-10 18:40:30 +00:00
|
|
|
OBJ_EXCLUSIVE |
|
|
|
|
OBJ_OPENIF;
|
|
|
|
ObjectTypeInitializer.PoolType = NonPagedPool;
|
|
|
|
ObjectTypeInitializer.SecurityRequired = TRUE;
|
|
|
|
|
|
|
|
/* Initialize the Process type */
|
|
|
|
RtlInitUnicodeString(&Name, L"Process");
|
2006-09-16 20:37:49 +00:00
|
|
|
ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(EPROCESS);
|
|
|
|
ObjectTypeInitializer.GenericMapping = PspProcessMapping;
|
|
|
|
ObjectTypeInitializer.ValidAccessMask = PROCESS_ALL_ACCESS;
|
|
|
|
ObjectTypeInitializer.DeleteProcedure = PspDeleteProcess;
|
|
|
|
ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &PsProcessType);
|
|
|
|
|
|
|
|
/* Initialize the Thread type */
|
|
|
|
RtlInitUnicodeString(&Name, L"Thread");
|
|
|
|
ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
|
|
|
|
ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(ETHREAD);
|
|
|
|
ObjectTypeInitializer.GenericMapping = PspThreadMapping;
|
|
|
|
ObjectTypeInitializer.ValidAccessMask = THREAD_ALL_ACCESS;
|
|
|
|
ObjectTypeInitializer.DeleteProcedure = PspDeleteThread;
|
|
|
|
ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &PsThreadType);
|
|
|
|
|
|
|
|
/* Initialize the Job type */
|
|
|
|
RtlInitUnicodeString(&Name, L"Job");
|
|
|
|
ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
|
|
|
|
ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(EJOB);
|
|
|
|
ObjectTypeInitializer.GenericMapping = PspJobMapping;
|
2012-09-02 22:06:42 +00:00
|
|
|
ObjectTypeInitializer.InvalidAttributes = 0;
|
2006-09-16 20:37:49 +00:00
|
|
|
ObjectTypeInitializer.ValidAccessMask = JOB_OBJECT_ALL_ACCESS;
|
|
|
|
ObjectTypeInitializer.DeleteProcedure = PspDeleteJob;
|
|
|
|
ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &PsJobType);
|
|
|
|
|
|
|
|
/* Initialize job structures external to this file */
|
|
|
|
PspInitializeJobStructures();
|
|
|
|
|
|
|
|
/* Initialize the Working Set data */
|
|
|
|
InitializeListHead(&PspWorkingSetChangeHead.List);
|
|
|
|
KeInitializeGuardedMutex(&PspWorkingSetChangeHead.Lock);
|
|
|
|
|
|
|
|
/* Create the CID Handle table */
|
|
|
|
PspCidTable = ExCreateHandleTable(NULL);
|
2007-01-18 09:44:49 +00:00
|
|
|
if (!PspCidTable) return FALSE;
|
2006-09-16 20:37:49 +00:00
|
|
|
|
|
|
|
/* FIXME: Initialize LDT/VDM support */
|
|
|
|
|
|
|
|
/* Setup the reaper */
|
|
|
|
ExInitializeWorkItem(&PspReaperWorkItem, PspReapRoutine, NULL);
|
|
|
|
|
|
|
|
/* Set the boot access token */
|
|
|
|
PspBootAccessToken = (PTOKEN)(PsIdleProcess->Token.Value & ~MAX_FAST_REFS);
|
|
|
|
|
|
|
|
/* Setup default object attributes */
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* Create the Initial System Process */
|
|
|
|
Status = PspCreateProcess(&PspInitialSystemProcessHandle,
|
|
|
|
PROCESS_ALL_ACCESS,
|
|
|
|
&ObjectAttributes,
|
|
|
|
0,
|
|
|
|
FALSE,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
FALSE);
|
|
|
|
if (!NT_SUCCESS(Status)) return FALSE;
|
|
|
|
|
|
|
|
/* Get a reference to it */
|
|
|
|
ObReferenceObjectByHandle(PspInitialSystemProcessHandle,
|
|
|
|
0,
|
|
|
|
PsProcessType,
|
|
|
|
KernelMode,
|
|
|
|
(PVOID*)&PsInitialSystemProcess,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* Copy the process names */
|
|
|
|
strcpy(PsIdleProcess->ImageFileName, "Idle");
|
|
|
|
strcpy(PsInitialSystemProcess->ImageFileName, "System");
|
|
|
|
|
|
|
|
/* Allocate a structure for the audit name */
|
2007-01-18 09:44:49 +00:00
|
|
|
PsInitialSystemProcess->SeAuditProcessCreationInfo.ImageFileName =
|
|
|
|
ExAllocatePoolWithTag(PagedPool,
|
|
|
|
sizeof(OBJECT_NAME_INFORMATION),
|
|
|
|
TAG_SEPA);
|
|
|
|
if (!PsInitialSystemProcess->SeAuditProcessCreationInfo.ImageFileName)
|
|
|
|
{
|
|
|
|
/* Allocation failed */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Zero it */
|
|
|
|
RtlZeroMemory(PsInitialSystemProcess->
|
|
|
|
SeAuditProcessCreationInfo.ImageFileName,
|
|
|
|
sizeof(OBJECT_NAME_INFORMATION));
|
2006-09-16 20:37:49 +00:00
|
|
|
|
2007-01-18 09:44:49 +00:00
|
|
|
/* Setup the system initialization thread */
|
2006-09-16 20:37:49 +00:00
|
|
|
Status = PsCreateSystemThread(&SysThreadHandle,
|
|
|
|
THREAD_ALL_ACCESS,
|
|
|
|
&ObjectAttributes,
|
|
|
|
0,
|
|
|
|
NULL,
|
2007-01-25 01:13:09 +00:00
|
|
|
Phase1Initialization,
|
|
|
|
LoaderBlock);
|
2006-09-16 20:37:49 +00:00
|
|
|
if (!NT_SUCCESS(Status)) return FALSE;
|
|
|
|
|
|
|
|
/* Create a handle to it */
|
|
|
|
ObReferenceObjectByHandle(SysThreadHandle,
|
|
|
|
0,
|
|
|
|
PsThreadType,
|
|
|
|
KernelMode,
|
|
|
|
(PVOID*)&SysThread,
|
|
|
|
NULL);
|
2010-01-23 21:27:26 +00:00
|
|
|
ObCloseHandle(SysThreadHandle, KernelMode);
|
2006-09-16 20:37:49 +00:00
|
|
|
|
|
|
|
/* Return success */
|
|
|
|
return TRUE;
|
2005-04-18 02:12:30 +00:00
|
|
|
}
|
2005-08-05 03:44:24 +00:00
|
|
|
|
2020-10-06 19:44:01 +00:00
|
|
|
CODE_SEG("INIT")
|
2006-10-02 15:52:58 +00:00
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
2007-01-25 01:13:09 +00:00
|
|
|
PsInitSystem(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
|
2006-10-02 15:52:58 +00:00
|
|
|
{
|
2006-10-08 02:10:34 +00:00
|
|
|
/* Check the initialization phase */
|
|
|
|
switch (ExpInitializationPhase)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
|
|
|
|
/* Do Phase 0 */
|
2007-01-25 01:13:09 +00:00
|
|
|
return PspInitPhase0(LoaderBlock);
|
2006-10-08 02:10:34 +00:00
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
/* Do Phase 1 */
|
|
|
|
return PspInitPhase1();
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
/* Don't know any other phase! Bugcheck! */
|
2007-01-25 01:13:09 +00:00
|
|
|
KeBugCheckEx(UNEXPECTED_INITIALIZATION_CALL,
|
|
|
|
1,
|
|
|
|
ExpInitializationPhase,
|
|
|
|
0,
|
|
|
|
0);
|
2006-10-08 02:10:34 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2006-10-02 15:52:58 +00:00
|
|
|
}
|
|
|
|
|
2006-09-17 05:20:24 +00:00
|
|
|
/* PUBLIC FUNCTIONS **********************************************************/
|
2005-08-05 03:44:24 +00:00
|
|
|
|
2006-09-17 05:20:24 +00:00
|
|
|
/*
|
2005-04-18 05:47:13 +00:00
|
|
|
* @implemented
|
2000-06-03 21:36:32 +00:00
|
|
|
*/
|
|
|
|
BOOLEAN
|
2006-09-17 05:20:24 +00:00
|
|
|
NTAPI
|
2015-03-16 03:14:16 +00:00
|
|
|
PsGetVersion(OUT PULONG MajorVersion OPTIONAL,
|
|
|
|
OUT PULONG MinorVersion OPTIONAL,
|
|
|
|
OUT PULONG BuildNumber OPTIONAL,
|
|
|
|
OUT PUNICODE_STRING CSDVersion OPTIONAL)
|
2000-06-03 21:36:32 +00:00
|
|
|
{
|
2006-09-17 05:20:24 +00:00
|
|
|
if (MajorVersion) *MajorVersion = NtMajorVersion;
|
|
|
|
if (MinorVersion) *MinorVersion = NtMinorVersion;
|
2015-03-16 03:14:16 +00:00
|
|
|
if (BuildNumber ) *BuildNumber = NtBuildNumber & 0x3FFF;
|
2000-06-03 21:36:32 +00:00
|
|
|
|
2005-04-18 05:47:13 +00:00
|
|
|
if (CSDVersion)
|
|
|
|
{
|
|
|
|
CSDVersion->Length = CmCSDVersionString.Length;
|
2015-03-16 03:14:16 +00:00
|
|
|
CSDVersion->MaximumLength = CmCSDVersionString.MaximumLength;
|
2005-04-18 05:47:13 +00:00
|
|
|
CSDVersion->Buffer = CmCSDVersionString.Buffer;
|
|
|
|
}
|
2000-06-03 21:36:32 +00:00
|
|
|
|
2015-03-16 03:14:16 +00:00
|
|
|
/* Return TRUE if this is a Checked Build */
|
2005-04-18 05:47:13 +00:00
|
|
|
return (NtBuildNumber >> 28) == 0xC;
|
2000-06-03 21:36:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|