mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 10:04:49 +00:00
use tags for pool allocations, and reformat code
svn path=/trunk/; revision=14546
This commit is contained in:
parent
dac8f53fe5
commit
18cff7ccc9
1 changed files with 452 additions and 432 deletions
|
@ -27,6 +27,7 @@
|
||||||
/* GLOBAL *******************************************************************/
|
/* GLOBAL *******************************************************************/
|
||||||
|
|
||||||
#define MAX_THREAD_NOTIFY_ROUTINE_COUNT 8
|
#define MAX_THREAD_NOTIFY_ROUTINE_COUNT 8
|
||||||
|
#define TAG_KAPC TAG('k','p','a','p') /* kpap - kernel ps apc */
|
||||||
|
|
||||||
static ULONG PiThreadNotifyRoutineCount = 0;
|
static ULONG PiThreadNotifyRoutineCount = 0;
|
||||||
static PCREATE_THREAD_NOTIFY_ROUTINE
|
static PCREATE_THREAD_NOTIFY_ROUTINE
|
||||||
|
@ -44,11 +45,12 @@ PiBeforeBeginThread(CONTEXT c)
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
PsInitializeThread(PEPROCESS Process,
|
PsInitializeThread (
|
||||||
|
PEPROCESS Process,
|
||||||
PETHREAD* ThreadPtr,
|
PETHREAD* ThreadPtr,
|
||||||
POBJECT_ATTRIBUTES ObjectAttributes,
|
POBJECT_ATTRIBUTES ObjectAttributes,
|
||||||
KPROCESSOR_MODE AccessMode,
|
KPROCESSOR_MODE AccessMode,
|
||||||
BOOLEAN First)
|
BOOLEAN First )
|
||||||
{
|
{
|
||||||
PETHREAD Thread;
|
PETHREAD Thread;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
@ -127,10 +129,11 @@ PsInitializeThread(PEPROCESS Process,
|
||||||
|
|
||||||
|
|
||||||
static NTSTATUS
|
static NTSTATUS
|
||||||
PsCreateTeb(HANDLE ProcessHandle,
|
PsCreateTeb (
|
||||||
|
HANDLE ProcessHandle,
|
||||||
PTEB *TebPtr,
|
PTEB *TebPtr,
|
||||||
PETHREAD Thread,
|
PETHREAD Thread,
|
||||||
PINITIAL_TEB InitialTeb)
|
PINITIAL_TEB InitialTeb )
|
||||||
{
|
{
|
||||||
PEPROCESS Process;
|
PEPROCESS Process;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
@ -276,14 +279,15 @@ PsCreateTeb(HANDLE ProcessHandle,
|
||||||
|
|
||||||
|
|
||||||
VOID STDCALL
|
VOID STDCALL
|
||||||
LdrInitApcRundownRoutine(PKAPC Apc)
|
LdrInitApcRundownRoutine ( PKAPC Apc )
|
||||||
{
|
{
|
||||||
ExFreePool(Apc);
|
ExFreePool(Apc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VOID STDCALL
|
VOID STDCALL
|
||||||
LdrInitApcKernelRoutine(PKAPC Apc,
|
LdrInitApcKernelRoutine (
|
||||||
|
PKAPC Apc,
|
||||||
PKNORMAL_ROUTINE* NormalRoutine,
|
PKNORMAL_ROUTINE* NormalRoutine,
|
||||||
PVOID* NormalContext,
|
PVOID* NormalContext,
|
||||||
PVOID* SystemArgument1,
|
PVOID* SystemArgument1,
|
||||||
|
@ -294,14 +298,15 @@ LdrInitApcKernelRoutine(PKAPC Apc,
|
||||||
|
|
||||||
|
|
||||||
NTSTATUS STDCALL
|
NTSTATUS STDCALL
|
||||||
NtCreateThread(OUT PHANDLE ThreadHandle,
|
NtCreateThread (
|
||||||
|
OUT PHANDLE ThreadHandle,
|
||||||
IN ACCESS_MASK DesiredAccess,
|
IN ACCESS_MASK DesiredAccess,
|
||||||
IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
|
IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
|
||||||
IN HANDLE ProcessHandle,
|
IN HANDLE ProcessHandle,
|
||||||
OUT PCLIENT_ID ClientId,
|
OUT PCLIENT_ID ClientId,
|
||||||
IN PCONTEXT ThreadContext,
|
IN PCONTEXT ThreadContext,
|
||||||
IN PINITIAL_TEB InitialTeb,
|
IN PINITIAL_TEB InitialTeb,
|
||||||
IN BOOLEAN CreateSuspended)
|
IN BOOLEAN CreateSuspended )
|
||||||
{
|
{
|
||||||
HANDLE hThread;
|
HANDLE hThread;
|
||||||
CONTEXT SafeContext;
|
CONTEXT SafeContext;
|
||||||
|
@ -362,7 +367,8 @@ NtCreateThread(OUT PHANDLE ThreadHandle,
|
||||||
DPRINT("NtCreateThread(ThreadHandle %x, PCONTEXT %x)\n",
|
DPRINT("NtCreateThread(ThreadHandle %x, PCONTEXT %x)\n",
|
||||||
ThreadHandle,ThreadContext);
|
ThreadHandle,ThreadContext);
|
||||||
|
|
||||||
Status = ObReferenceObjectByHandle(ProcessHandle,
|
Status = ObReferenceObjectByHandle(
|
||||||
|
ProcessHandle,
|
||||||
PROCESS_CREATE_THREAD,
|
PROCESS_CREATE_THREAD,
|
||||||
PsProcessType,
|
PsProcessType,
|
||||||
PreviousMode,
|
PreviousMode,
|
||||||
|
@ -402,7 +408,8 @@ NtCreateThread(OUT PHANDLE ThreadHandle,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create a client id handle */
|
/* create a client id handle */
|
||||||
Status = PsCreateCidHandle(Thread, PsThreadType, &Thread->Cid.UniqueThread);
|
Status = PsCreateCidHandle (
|
||||||
|
Thread, PsThreadType, &Thread->Cid.UniqueThread);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
ObDereferenceObject(Thread);
|
ObDereferenceObject(Thread);
|
||||||
|
@ -454,10 +461,17 @@ NtCreateThread(OUT PHANDLE ThreadHandle,
|
||||||
* Queue an APC to the thread that will execute the ntdll startup
|
* Queue an APC to the thread that will execute the ntdll startup
|
||||||
* routine.
|
* routine.
|
||||||
*/
|
*/
|
||||||
LdrInitApc = ExAllocatePool(NonPagedPool, sizeof(KAPC));
|
LdrInitApc = ExAllocatePoolWithTag (
|
||||||
KeInitializeApc(LdrInitApc, &Thread->Tcb, OriginalApcEnvironment, LdrInitApcKernelRoutine,
|
NonPagedPool, sizeof(KAPC), TAG_KAPC );
|
||||||
LdrInitApcRundownRoutine, LdrpGetSystemDllEntryPoint(),
|
KeInitializeApc (
|
||||||
UserMode, NULL);
|
LdrInitApc,
|
||||||
|
&Thread->Tcb,
|
||||||
|
OriginalApcEnvironment,
|
||||||
|
LdrInitApcKernelRoutine,
|
||||||
|
LdrInitApcRundownRoutine,
|
||||||
|
LdrpGetSystemDllEntryPoint(),
|
||||||
|
UserMode,
|
||||||
|
NULL );
|
||||||
KeInsertQueueApc(LdrInitApc, NULL, NULL, IO_NO_INCREMENT);
|
KeInsertQueueApc(LdrInitApc, NULL, NULL, IO_NO_INCREMENT);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -503,13 +517,14 @@ NtCreateThread(OUT PHANDLE ThreadHandle,
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
NTSTATUS STDCALL
|
NTSTATUS STDCALL
|
||||||
PsCreateSystemThread(PHANDLE ThreadHandle,
|
PsCreateSystemThread (
|
||||||
|
PHANDLE ThreadHandle,
|
||||||
ACCESS_MASK DesiredAccess,
|
ACCESS_MASK DesiredAccess,
|
||||||
POBJECT_ATTRIBUTES ObjectAttributes,
|
POBJECT_ATTRIBUTES ObjectAttributes,
|
||||||
HANDLE ProcessHandle,
|
HANDLE ProcessHandle,
|
||||||
PCLIENT_ID ClientId,
|
PCLIENT_ID ClientId,
|
||||||
PKSTART_ROUTINE StartRoutine,
|
PKSTART_ROUTINE StartRoutine,
|
||||||
PVOID StartContext)
|
PVOID StartContext )
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Creates a thread which executes in kernel mode
|
* FUNCTION: Creates a thread which executes in kernel mode
|
||||||
* ARGUMENTS:
|
* ARGUMENTS:
|
||||||
|
@ -536,7 +551,8 @@ PsCreateSystemThread(PHANDLE ThreadHandle,
|
||||||
DPRINT("PsCreateSystemThread(ThreadHandle %x, ProcessHandle %x)\n",
|
DPRINT("PsCreateSystemThread(ThreadHandle %x, ProcessHandle %x)\n",
|
||||||
ThreadHandle,ProcessHandle);
|
ThreadHandle,ProcessHandle);
|
||||||
|
|
||||||
Status = PsInitializeThread(NULL,
|
Status = PsInitializeThread(
|
||||||
|
NULL,
|
||||||
&Thread,
|
&Thread,
|
||||||
ObjectAttributes,
|
ObjectAttributes,
|
||||||
KernelMode,
|
KernelMode,
|
||||||
|
@ -559,7 +575,8 @@ PsCreateSystemThread(PHANDLE ThreadHandle,
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread->StartAddress = StartRoutine;
|
Thread->StartAddress = StartRoutine;
|
||||||
Status = KiArchInitThread(&Thread->Tcb, StartRoutine, StartContext);
|
Status = KiArchInitThread (
|
||||||
|
&Thread->Tcb, StartRoutine, StartContext);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
ObDereferenceObject(Thread);
|
ObDereferenceObject(Thread);
|
||||||
|
@ -575,7 +592,8 @@ PsCreateSystemThread(PHANDLE ThreadHandle,
|
||||||
KiUnblockThread(&Thread->Tcb, NULL, 0);
|
KiUnblockThread(&Thread->Tcb, NULL, 0);
|
||||||
KeReleaseDispatcherDatabaseLock(oldIrql);
|
KeReleaseDispatcherDatabaseLock(oldIrql);
|
||||||
|
|
||||||
Status = ObInsertObject((PVOID)Thread,
|
Status = ObInsertObject(
|
||||||
|
(PVOID)Thread,
|
||||||
NULL,
|
NULL,
|
||||||
DesiredAccess,
|
DesiredAccess,
|
||||||
0,
|
0,
|
||||||
|
@ -590,8 +608,9 @@ PsCreateSystemThread(PHANDLE ThreadHandle,
|
||||||
|
|
||||||
|
|
||||||
VOID STDCALL
|
VOID STDCALL
|
||||||
PspRunCreateThreadNotifyRoutines(PETHREAD CurrentThread,
|
PspRunCreateThreadNotifyRoutines (
|
||||||
BOOLEAN Create)
|
PETHREAD CurrentThread,
|
||||||
|
BOOLEAN Create )
|
||||||
{
|
{
|
||||||
ULONG i;
|
ULONG i;
|
||||||
CLIENT_ID Cid = CurrentThread->Cid;
|
CLIENT_ID Cid = CurrentThread->Cid;
|
||||||
|
@ -607,7 +626,8 @@ PspRunCreateThreadNotifyRoutines(PETHREAD CurrentThread,
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
NTSTATUS STDCALL
|
NTSTATUS STDCALL
|
||||||
PsSetCreateThreadNotifyRoutine(IN PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine)
|
PsSetCreateThreadNotifyRoutine (
|
||||||
|
IN PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine )
|
||||||
{
|
{
|
||||||
if (PiThreadNotifyRoutineCount >= MAX_THREAD_NOTIFY_ROUTINE_COUNT)
|
if (PiThreadNotifyRoutineCount >= MAX_THREAD_NOTIFY_ROUTINE_COUNT)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue