Implemented process and thread notification routines.
authorEric Kohl <eric.kohl@reactos.org>
Thu, 3 Jan 2002 18:02:34 +0000 (18:02 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Thu, 3 Jan 2002 18:02:34 +0000 (18:02 +0000)
svn path=/trunk/; revision=2479

reactos/include/ddk/psfuncs.h
reactos/include/ddk/pstypes.h
reactos/ntoskrnl/ntoskrnl.def
reactos/ntoskrnl/ntoskrnl.edf
reactos/ntoskrnl/ps/create.c
reactos/ntoskrnl/ps/process.c

index 8dca7cc..d4a8049 100644 (file)
@@ -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
 #define _INCLUDE_DDK_PSFUNCS_H
@@ -87,6 +87,13 @@ NTSTATUS STDCALL PsLookupThreadByThreadId(IN PVOID ThreadId,
                                          OUT struct _ETHREAD **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
 
 /* EOF */
index 695f00e..9aae408 100644 (file)
@@ -20,6 +20,14 @@ struct _KTHREAD;
 
 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
 {
        PVOID   BaseAddress;
index aff07db..38e7dea 100644 (file)
@@ -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
 ;
@@ -609,8 +609,8 @@ PsReferenceImpersonationToken@16
 PsReferencePrimaryToken@4
 ;PsReturnPoolQuota@12
 PsRevertToSelf@0
-;PsSetCreateProcessNotifyRoutine@8
-;PsSetCreateThreadNotifyRoutine@4
+PsSetCreateProcessNotifyRoutine@8
+PsSetCreateThreadNotifyRoutine@4
 ;PsSetLegoNotifyRoutine@4
 ;PsSetProcessPriorityByClass@8
 PsTerminateSystemThread@4
index 0949157..6d23e62 100644 (file)
@@ -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
 ;
@@ -609,8 +609,8 @@ PsReferenceImpersonationToken=PsReferenceImpersonationToken@16
 PsReferencePrimaryToken=PsReferencePrimaryToken@4
 ;PsReturnPoolQuota
 PsRevertToSelf=PsRevertToSelf@0
-;PsSetCreateProcessNotifyRoutine
-;PsSetCreateThreadNotifyRoutine
+PsSetCreateProcessNotifyRoutine=PsSetCreateProcessNotifyRoutine@8
+PsSetCreateThreadNotifyRoutine=PsSetCreateThreadNotifyRoutine@4
 ;PsSetLegoNotifyRoutine
 ;PsSetProcessPriorityByClass
 PsTerminateSystemThread=PsTerminateSystemThread@4
index 9ca6137..082075d 100644 (file)
@@ -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
  * PROJECT:                ReactOS kernel
@@ -40,6 +40,12 @@ extern ULONG PiNrThreads;
 
 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 ***************************************************************/
 
 NTSTATUS STDCALL
@@ -299,20 +305,32 @@ PsBeginThread(PKSTART_ROUTINE StartRoutine, PVOID StartContext)
 VOID STDCALL
 PiDeleteThread(PVOID ObjectBody)
 {
-   KIRQL oldIrql;
-   
-   DPRINT("PiDeleteThread(ObjectBody %x)\n",ObjectBody);
-   
-   KeAcquireSpinLock(&PiThreadListLock, &oldIrql);
-   DPRINT("Process %x(%d)\n", ((PETHREAD)ObjectBody)->ThreadsProcess,
-          ObGetReferenceCount(((PETHREAD)ObjectBody)->ThreadsProcess));
-   ObDereferenceObject(((PETHREAD)ObjectBody)->ThreadsProcess);
-   ((PETHREAD)ObjectBody)->ThreadsProcess = NULL;
-   PiNrThreads--;
-   RemoveEntryList(&((PETHREAD)ObjectBody)->Tcb.ThreadListEntry);
-   HalReleaseTask((PETHREAD)ObjectBody);
-   KeReleaseSpinLock(&PiThreadListLock, oldIrql);
-   DPRINT("PiDeleteThread() finished\n");
+  KIRQL oldIrql;
+  PETHREAD Thread;
+  ULONG i;
+
+  DPRINT("PiDeleteThread(ObjectBody %x)\n",ObjectBody);
+
+  KeAcquireSpinLock(&PiThreadListLock, &oldIrql);
+  Thread = (PETHREAD)ObjectBody;
+
+  for (i = 0; i < PiThreadNotifyRoutineCount; i++)
+    {
+      PiThreadNotifyRoutine[i](Thread->Cid.UniqueProcess,
+                              Thread->Cid.UniqueThread,
+                              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
@@ -338,6 +356,7 @@ PsInitializeThread(HANDLE ProcessHandle,
    NTSTATUS Status;
    KIRQL oldIrql;
    PEPROCESS Process;
+   ULONG i;
    
    /*
     * Reference process
@@ -408,8 +427,15 @@ PsInitializeThread(HANDLE ProcessHandle,
 
    Thread->Tcb.BasePriority = Thread->ThreadsProcess->Pcb.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);
 }
 
+
+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 */
index 0dd2a45..3cb635a 100644 (file)
@@ -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
  * PROJECT:           ReactOS kernel
@@ -46,6 +46,12 @@ static GENERIC_MAPPING PiProcessMapping = {PROCESS_READ,
                                           PROCESS_EXECUTE,
                                           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 *****************************************************************/
 
 
@@ -300,20 +306,29 @@ PiFreeSymbols(PPEB Peb)
 VOID STDCALL
 PiDeleteProcess(PVOID ObjectBody)
 {
-   KIRQL oldIrql;
-   
-   DPRINT("PiDeleteProcess(ObjectBody %x)\n",ObjectBody);
-   
-   KeAcquireSpinLock(&PsProcessListLock, &oldIrql);
-   RemoveEntryList(&((PEPROCESS)ObjectBody)->ProcessListEntry);
+  KIRQL oldIrql;
+  PEPROCESS Process;
+  ULONG i;
+
+  DPRINT("PiDeleteProcess(ObjectBody %x)\n",ObjectBody);
+
+  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);
 
 #ifdef KDBG
-   PiFreeSymbols(((PEPROCESS)ObjectBody)->Peb);
+   PiFreeSymbols(Process->Peb);
 #endif /* KDBG */
 
-   (VOID)MmReleaseMmInfo((PEPROCESS)ObjectBody);
-   ObDeleteHandleTable((PEPROCESS)ObjectBody);
+   (VOID)MmReleaseMmInfo(Process);
+   ObDeleteHandleTable(Process);
 }
 
 
@@ -393,7 +408,7 @@ PsGetCurrentProcess(VOID)
 PEPROCESS STDCALL
 IoGetCurrentProcess(VOID)
 {
-   return(PsGetCurrentProcess());
+  return(PsGetCurrentProcess());
 }
 
 NTSTATUS STDCALL
@@ -454,6 +469,7 @@ NtCreateProcess(OUT PHANDLE ProcessHandle,
    PEPORT ExceptionPort;
    PVOID BaseAddress;
    PMEMORY_AREA MemoryArea;
+   ULONG i;
    
    DPRINT("NtCreateProcess(ObjectAttributes %x)\n",ObjectAttributes);
 
@@ -500,6 +516,12 @@ NtCreateProcess(OUT PHANDLE ProcessHandle,
    MmCopyMmInfo(ParentProcess, Process);
    
    KeAcquireSpinLock(&PsProcessListLock, &oldIrql);
+  for (i = 0; i < PiProcessNotifyRoutineCount; i++)
+    {
+      PiProcessNotifyRoutine[i](Process->InheritedFromUniqueProcessId,
+                               (HANDLE)Process->UniqueProcessId,
+                               TRUE);
+    }
    InsertHeadList(&PsProcessListHead, &Process->ProcessListEntry);
    InitializeListHead(&Process->ThreadListHead);
    KeReleaseSpinLock(&PsProcessListLock, oldIrql);
@@ -1183,4 +1205,18 @@ PsLookupProcessByProcessId(IN PVOID ProcessId,
   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 */