mirror of
https://github.com/reactos/reactos.git
synced 2025-07-29 09:12:20 +00:00
Implemented process and thread notification routines.
svn path=/trunk/; revision=2479
This commit is contained in:
parent
041c7d16a5
commit
059a7a0f64
6 changed files with 125 additions and 35 deletions
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: psfuncs.h,v 1.17 2002/01/03 14:01:16 ekohl Exp $
|
/* $Id: psfuncs.h,v 1.18 2002/01/03 17:58:44 ekohl Exp $
|
||||||
*/
|
*/
|
||||||
#ifndef _INCLUDE_DDK_PSFUNCS_H
|
#ifndef _INCLUDE_DDK_PSFUNCS_H
|
||||||
#define _INCLUDE_DDK_PSFUNCS_H
|
#define _INCLUDE_DDK_PSFUNCS_H
|
||||||
|
@ -87,6 +87,13 @@ NTSTATUS STDCALL PsLookupThreadByThreadId(IN PVOID ThreadId,
|
||||||
OUT struct _ETHREAD **Thread);
|
OUT struct _ETHREAD **Thread);
|
||||||
// OUT PETHREAD *Thread);
|
// OUT PETHREAD *Thread);
|
||||||
|
|
||||||
|
NTSTATUS STDCALL
|
||||||
|
PsSetCreateProcessNotifyRoutine(IN PCREATE_PROCESS_NOTIFY_ROUTINE NotifyRoutine,
|
||||||
|
IN BOOLEAN Remove);
|
||||||
|
|
||||||
|
NTSTATUS STDCALL
|
||||||
|
PsSetCreateThreadNotifyRoutine(IN PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
|
@ -20,6 +20,14 @@ struct _KTHREAD;
|
||||||
|
|
||||||
typedef NTSTATUS STDCALL (*PKSTART_ROUTINE)(PVOID StartContext);
|
typedef NTSTATUS STDCALL (*PKSTART_ROUTINE)(PVOID StartContext);
|
||||||
|
|
||||||
|
typedef VOID STDCALL (*PCREATE_PROCESS_NOTIFY_ROUTINE)(HANDLE ParentId,
|
||||||
|
HANDLE ProcessId,
|
||||||
|
BOOLEAN Create);
|
||||||
|
|
||||||
|
typedef VOID STDCALL (*PCREATE_THREAD_NOTIFY_ROUTINE)(HANDLE ProcessId,
|
||||||
|
HANDLE ThreadId,
|
||||||
|
BOOLEAN Create);
|
||||||
|
|
||||||
typedef struct _STACK_INFORMATION
|
typedef struct _STACK_INFORMATION
|
||||||
{
|
{
|
||||||
PVOID BaseAddress;
|
PVOID BaseAddress;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
; $Id: ntoskrnl.def,v 1.121 2002/01/03 14:02:04 ekohl Exp $
|
; $Id: ntoskrnl.def,v 1.122 2002/01/03 18:02:34 ekohl Exp $
|
||||||
;
|
;
|
||||||
; reactos/ntoskrnl/ntoskrnl.def
|
; reactos/ntoskrnl/ntoskrnl.def
|
||||||
;
|
;
|
||||||
|
@ -609,8 +609,8 @@ PsReferenceImpersonationToken@16
|
||||||
PsReferencePrimaryToken@4
|
PsReferencePrimaryToken@4
|
||||||
;PsReturnPoolQuota@12
|
;PsReturnPoolQuota@12
|
||||||
PsRevertToSelf@0
|
PsRevertToSelf@0
|
||||||
;PsSetCreateProcessNotifyRoutine@8
|
PsSetCreateProcessNotifyRoutine@8
|
||||||
;PsSetCreateThreadNotifyRoutine@4
|
PsSetCreateThreadNotifyRoutine@4
|
||||||
;PsSetLegoNotifyRoutine@4
|
;PsSetLegoNotifyRoutine@4
|
||||||
;PsSetProcessPriorityByClass@8
|
;PsSetProcessPriorityByClass@8
|
||||||
PsTerminateSystemThread@4
|
PsTerminateSystemThread@4
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
; $Id: ntoskrnl.edf,v 1.107 2002/01/03 14:02:04 ekohl Exp $
|
; $Id: ntoskrnl.edf,v 1.108 2002/01/03 18:02:34 ekohl Exp $
|
||||||
;
|
;
|
||||||
; reactos/ntoskrnl/ntoskrnl.def
|
; reactos/ntoskrnl/ntoskrnl.def
|
||||||
;
|
;
|
||||||
|
@ -609,8 +609,8 @@ PsReferenceImpersonationToken=PsReferenceImpersonationToken@16
|
||||||
PsReferencePrimaryToken=PsReferencePrimaryToken@4
|
PsReferencePrimaryToken=PsReferencePrimaryToken@4
|
||||||
;PsReturnPoolQuota
|
;PsReturnPoolQuota
|
||||||
PsRevertToSelf=PsRevertToSelf@0
|
PsRevertToSelf=PsRevertToSelf@0
|
||||||
;PsSetCreateProcessNotifyRoutine
|
PsSetCreateProcessNotifyRoutine=PsSetCreateProcessNotifyRoutine@8
|
||||||
;PsSetCreateThreadNotifyRoutine
|
PsSetCreateThreadNotifyRoutine=PsSetCreateThreadNotifyRoutine@4
|
||||||
;PsSetLegoNotifyRoutine
|
;PsSetLegoNotifyRoutine
|
||||||
;PsSetProcessPriorityByClass
|
;PsSetProcessPriorityByClass
|
||||||
PsTerminateSystemThread=PsTerminateSystemThread@4
|
PsTerminateSystemThread=PsTerminateSystemThread@4
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: create.c,v 1.41 2001/11/21 18:44:25 ekohl Exp $
|
/* $Id: create.c,v 1.42 2002/01/03 17:59:09 ekohl Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
|
@ -40,6 +40,12 @@ extern ULONG PiNrThreads;
|
||||||
|
|
||||||
extern LIST_ENTRY PiThreadListHead;
|
extern LIST_ENTRY PiThreadListHead;
|
||||||
|
|
||||||
|
#define MAX_THREAD_NOTIFY_ROUTINE_COUNT 8
|
||||||
|
|
||||||
|
static ULONG PiThreadNotifyRoutineCount = 0;
|
||||||
|
static PCREATE_THREAD_NOTIFY_ROUTINE
|
||||||
|
PiThreadNotifyRoutine[MAX_THREAD_NOTIFY_ROUTINE_COUNT];
|
||||||
|
|
||||||
/* FUNCTIONS ***************************************************************/
|
/* FUNCTIONS ***************************************************************/
|
||||||
|
|
||||||
NTSTATUS STDCALL
|
NTSTATUS STDCALL
|
||||||
|
@ -299,20 +305,32 @@ PsBeginThread(PKSTART_ROUTINE StartRoutine, PVOID StartContext)
|
||||||
VOID STDCALL
|
VOID STDCALL
|
||||||
PiDeleteThread(PVOID ObjectBody)
|
PiDeleteThread(PVOID ObjectBody)
|
||||||
{
|
{
|
||||||
KIRQL oldIrql;
|
KIRQL oldIrql;
|
||||||
|
PETHREAD Thread;
|
||||||
DPRINT("PiDeleteThread(ObjectBody %x)\n",ObjectBody);
|
ULONG i;
|
||||||
|
|
||||||
KeAcquireSpinLock(&PiThreadListLock, &oldIrql);
|
DPRINT("PiDeleteThread(ObjectBody %x)\n",ObjectBody);
|
||||||
DPRINT("Process %x(%d)\n", ((PETHREAD)ObjectBody)->ThreadsProcess,
|
|
||||||
ObGetReferenceCount(((PETHREAD)ObjectBody)->ThreadsProcess));
|
KeAcquireSpinLock(&PiThreadListLock, &oldIrql);
|
||||||
ObDereferenceObject(((PETHREAD)ObjectBody)->ThreadsProcess);
|
Thread = (PETHREAD)ObjectBody;
|
||||||
((PETHREAD)ObjectBody)->ThreadsProcess = NULL;
|
|
||||||
PiNrThreads--;
|
for (i = 0; i < PiThreadNotifyRoutineCount; i++)
|
||||||
RemoveEntryList(&((PETHREAD)ObjectBody)->Tcb.ThreadListEntry);
|
{
|
||||||
HalReleaseTask((PETHREAD)ObjectBody);
|
PiThreadNotifyRoutine[i](Thread->Cid.UniqueProcess,
|
||||||
KeReleaseSpinLock(&PiThreadListLock, oldIrql);
|
Thread->Cid.UniqueThread,
|
||||||
DPRINT("PiDeleteThread() finished\n");
|
FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
DPRINT("Process %x(%d)\n",
|
||||||
|
Thread->ThreadsProcess,
|
||||||
|
ObGetReferenceCount(Thread->ThreadsProcess));
|
||||||
|
ObDereferenceObject(Thread->ThreadsProcess);
|
||||||
|
Thread->ThreadsProcess = NULL;
|
||||||
|
PiNrThreads--;
|
||||||
|
RemoveEntryList(&Thread->Tcb.ThreadListEntry);
|
||||||
|
HalReleaseTask(Thread);
|
||||||
|
KeReleaseSpinLock(&PiThreadListLock, oldIrql);
|
||||||
|
DPRINT("PiDeleteThread() finished\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID STDCALL
|
VOID STDCALL
|
||||||
|
@ -338,6 +356,7 @@ PsInitializeThread(HANDLE ProcessHandle,
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
KIRQL oldIrql;
|
KIRQL oldIrql;
|
||||||
PEPROCESS Process;
|
PEPROCESS Process;
|
||||||
|
ULONG i;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reference process
|
* Reference process
|
||||||
|
@ -408,8 +427,15 @@ PsInitializeThread(HANDLE ProcessHandle,
|
||||||
|
|
||||||
Thread->Tcb.BasePriority = Thread->ThreadsProcess->Pcb.BasePriority;
|
Thread->Tcb.BasePriority = Thread->ThreadsProcess->Pcb.BasePriority;
|
||||||
Thread->Tcb.Priority = Thread->Tcb.BasePriority;
|
Thread->Tcb.Priority = Thread->Tcb.BasePriority;
|
||||||
|
|
||||||
return(STATUS_SUCCESS);
|
for (i = 0; i < PiThreadNotifyRoutineCount; i++)
|
||||||
|
{
|
||||||
|
PiThreadNotifyRoutine[i](Thread->Cid.UniqueProcess,
|
||||||
|
Thread->Cid.UniqueThread,
|
||||||
|
TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -656,4 +682,17 @@ PsCreateSystemThread(PHANDLE ThreadHandle,
|
||||||
return(STATUS_SUCCESS);
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NTSTATUS STDCALL
|
||||||
|
PsSetCreateThreadNotifyRoutine(IN PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine)
|
||||||
|
{
|
||||||
|
if (PiThreadNotifyRoutineCount >= MAX_THREAD_NOTIFY_ROUTINE_COUNT)
|
||||||
|
return(STATUS_INSUFFICIENT_RESOURCES);
|
||||||
|
|
||||||
|
PiThreadNotifyRoutine[PiThreadNotifyRoutineCount] = NotifyRoutine;
|
||||||
|
PiThreadNotifyRoutineCount++;
|
||||||
|
|
||||||
|
return(STATUS_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: process.c,v 1.74 2002/01/03 14:03:05 ekohl Exp $
|
/* $Id: process.c,v 1.75 2002/01/03 17:59:09 ekohl Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
|
@ -46,6 +46,12 @@ static GENERIC_MAPPING PiProcessMapping = {PROCESS_READ,
|
||||||
PROCESS_EXECUTE,
|
PROCESS_EXECUTE,
|
||||||
PROCESS_ALL_ACCESS};
|
PROCESS_ALL_ACCESS};
|
||||||
|
|
||||||
|
#define MAX_PROCESS_NOTIFY_ROUTINE_COUNT 8
|
||||||
|
|
||||||
|
static ULONG PiProcessNotifyRoutineCount = 0;
|
||||||
|
static PCREATE_PROCESS_NOTIFY_ROUTINE
|
||||||
|
PiProcessNotifyRoutine[MAX_PROCESS_NOTIFY_ROUTINE_COUNT];
|
||||||
|
|
||||||
/* FUNCTIONS *****************************************************************/
|
/* FUNCTIONS *****************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
@ -300,20 +306,29 @@ PiFreeSymbols(PPEB Peb)
|
||||||
VOID STDCALL
|
VOID STDCALL
|
||||||
PiDeleteProcess(PVOID ObjectBody)
|
PiDeleteProcess(PVOID ObjectBody)
|
||||||
{
|
{
|
||||||
KIRQL oldIrql;
|
KIRQL oldIrql;
|
||||||
|
PEPROCESS Process;
|
||||||
DPRINT("PiDeleteProcess(ObjectBody %x)\n",ObjectBody);
|
ULONG i;
|
||||||
|
|
||||||
KeAcquireSpinLock(&PsProcessListLock, &oldIrql);
|
DPRINT("PiDeleteProcess(ObjectBody %x)\n",ObjectBody);
|
||||||
RemoveEntryList(&((PEPROCESS)ObjectBody)->ProcessListEntry);
|
|
||||||
|
Process = (PEPROCESS)Process;
|
||||||
|
KeAcquireSpinLock(&PsProcessListLock, &oldIrql);
|
||||||
|
for (i = 0; i < PiProcessNotifyRoutineCount; i++)
|
||||||
|
{
|
||||||
|
PiProcessNotifyRoutine[i](Process->InheritedFromUniqueProcessId,
|
||||||
|
(HANDLE)Process->UniqueProcessId,
|
||||||
|
FALSE);
|
||||||
|
}
|
||||||
|
RemoveEntryList(&Process->ProcessListEntry);
|
||||||
KeReleaseSpinLock(&PsProcessListLock, oldIrql);
|
KeReleaseSpinLock(&PsProcessListLock, oldIrql);
|
||||||
|
|
||||||
#ifdef KDBG
|
#ifdef KDBG
|
||||||
PiFreeSymbols(((PEPROCESS)ObjectBody)->Peb);
|
PiFreeSymbols(Process->Peb);
|
||||||
#endif /* KDBG */
|
#endif /* KDBG */
|
||||||
|
|
||||||
(VOID)MmReleaseMmInfo((PEPROCESS)ObjectBody);
|
(VOID)MmReleaseMmInfo(Process);
|
||||||
ObDeleteHandleTable((PEPROCESS)ObjectBody);
|
ObDeleteHandleTable(Process);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -393,7 +408,7 @@ PsGetCurrentProcess(VOID)
|
||||||
PEPROCESS STDCALL
|
PEPROCESS STDCALL
|
||||||
IoGetCurrentProcess(VOID)
|
IoGetCurrentProcess(VOID)
|
||||||
{
|
{
|
||||||
return(PsGetCurrentProcess());
|
return(PsGetCurrentProcess());
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS STDCALL
|
NTSTATUS STDCALL
|
||||||
|
@ -454,6 +469,7 @@ NtCreateProcess(OUT PHANDLE ProcessHandle,
|
||||||
PEPORT ExceptionPort;
|
PEPORT ExceptionPort;
|
||||||
PVOID BaseAddress;
|
PVOID BaseAddress;
|
||||||
PMEMORY_AREA MemoryArea;
|
PMEMORY_AREA MemoryArea;
|
||||||
|
ULONG i;
|
||||||
|
|
||||||
DPRINT("NtCreateProcess(ObjectAttributes %x)\n",ObjectAttributes);
|
DPRINT("NtCreateProcess(ObjectAttributes %x)\n",ObjectAttributes);
|
||||||
|
|
||||||
|
@ -500,6 +516,12 @@ NtCreateProcess(OUT PHANDLE ProcessHandle,
|
||||||
MmCopyMmInfo(ParentProcess, Process);
|
MmCopyMmInfo(ParentProcess, Process);
|
||||||
|
|
||||||
KeAcquireSpinLock(&PsProcessListLock, &oldIrql);
|
KeAcquireSpinLock(&PsProcessListLock, &oldIrql);
|
||||||
|
for (i = 0; i < PiProcessNotifyRoutineCount; i++)
|
||||||
|
{
|
||||||
|
PiProcessNotifyRoutine[i](Process->InheritedFromUniqueProcessId,
|
||||||
|
(HANDLE)Process->UniqueProcessId,
|
||||||
|
TRUE);
|
||||||
|
}
|
||||||
InsertHeadList(&PsProcessListHead, &Process->ProcessListEntry);
|
InsertHeadList(&PsProcessListHead, &Process->ProcessListEntry);
|
||||||
InitializeListHead(&Process->ThreadListHead);
|
InitializeListHead(&Process->ThreadListHead);
|
||||||
KeReleaseSpinLock(&PsProcessListLock, oldIrql);
|
KeReleaseSpinLock(&PsProcessListLock, oldIrql);
|
||||||
|
@ -1183,4 +1205,18 @@ PsLookupProcessByProcessId(IN PVOID ProcessId,
|
||||||
return(STATUS_INVALID_PARAMETER);
|
return(STATUS_INVALID_PARAMETER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NTSTATUS STDCALL
|
||||||
|
PsSetCreateProcessNotifyRoutine(IN PCREATE_PROCESS_NOTIFY_ROUTINE NotifyRoutine,
|
||||||
|
IN BOOLEAN Remove)
|
||||||
|
{
|
||||||
|
if (PiProcessNotifyRoutineCount >= MAX_PROCESS_NOTIFY_ROUTINE_COUNT)
|
||||||
|
return(STATUS_INSUFFICIENT_RESOURCES);
|
||||||
|
|
||||||
|
PiProcessNotifyRoutine[PiProcessNotifyRoutineCount] = NotifyRoutine;
|
||||||
|
PiProcessNotifyRoutineCount++;
|
||||||
|
|
||||||
|
return(STATUS_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue