2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/ps/notify.c
5 * PURPOSE: Notifications
7 * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
10 /* INCLUDES ****************************************************************/
14 #include <internal/debug.h>
16 /* GLOBAL *******************************************************************/
18 #define MAX_THREAD_NOTIFY_ROUTINE_COUNT 8
20 static ULONG PspThreadNotifyRoutineCount
= 0;
21 static PCREATE_THREAD_NOTIFY_ROUTINE
22 PspThreadNotifyRoutine
[MAX_THREAD_NOTIFY_ROUTINE_COUNT
];
24 static PCREATE_PROCESS_NOTIFY_ROUTINE
25 PspProcessNotifyRoutine
[MAX_PROCESS_NOTIFY_ROUTINE_COUNT
];
27 static PLOAD_IMAGE_NOTIFY_ROUTINE
28 PspLoadImageNotifyRoutine
[MAX_LOAD_IMAGE_NOTIFY_ROUTINE_COUNT
];
30 typedef VOID (STDCALL
*PLEGO_NOTIFY_ROUTINE
)(IN PKTHREAD Thread
);
31 static PLEGO_NOTIFY_ROUTINE PspLegoNotifyRoutine
;
33 /* FUNCTIONS ***************************************************************/
40 PsSetCreateProcessNotifyRoutine(IN PCREATE_PROCESS_NOTIFY_ROUTINE NotifyRoutine
,
45 /* Check if it's a removal or addition */
48 /* Loop the routines */
49 for(i
=0;i
<MAX_PROCESS_NOTIFY_ROUTINE_COUNT
;i
++)
51 /* Check for a match */
52 if ((PVOID
)PspProcessNotifyRoutine
[i
] == (PVOID
)NotifyRoutine
)
54 /* Remove and return */
55 PspProcessNotifyRoutine
[i
] = NULL
;
56 return(STATUS_SUCCESS
);
62 /* Loop the routines */
63 for(i
=0;i
<MAX_PROCESS_NOTIFY_ROUTINE_COUNT
;i
++)
65 /* Find an empty one */
66 if (PspProcessNotifyRoutine
[i
] == NULL
)
69 PspProcessNotifyRoutine
[i
] = NotifyRoutine
;
70 return STATUS_SUCCESS
;
76 return STATUS_INVALID_PARAMETER
;
84 PsSetLegoNotifyRoutine(PVOID LegoNotifyRoutine
)
86 /* Set the System-Wide Lego Routine */
87 PspLegoNotifyRoutine
= LegoNotifyRoutine
;
89 /* Return the location to the Lego Data */
90 return FIELD_OFFSET(KTHREAD
, LegoData
);
98 PsRemoveLoadImageNotifyRoutine(IN PLOAD_IMAGE_NOTIFY_ROUTINE NotifyRoutine
)
102 /* Loop the routines */
103 for(i
=0;i
<MAX_LOAD_IMAGE_NOTIFY_ROUTINE_COUNT
;i
++)
105 /* Check for a match */
106 if ((PVOID
)PspLoadImageNotifyRoutine
[i
] == (PVOID
)NotifyRoutine
)
108 /* Remove and return */
109 PspLoadImageNotifyRoutine
[i
] = NULL
;
110 return(STATUS_SUCCESS
);
115 return STATUS_INVALID_PARAMETER
;
123 PsSetLoadImageNotifyRoutine(IN PLOAD_IMAGE_NOTIFY_ROUTINE NotifyRoutine
)
127 /* Loop the routines */
128 for (i
= 0; i
< MAX_LOAD_IMAGE_NOTIFY_ROUTINE_COUNT
; i
++)
130 /* Find an empty one */
131 if (PspLoadImageNotifyRoutine
[i
] == NULL
)
134 PspLoadImageNotifyRoutine
[i
] = NotifyRoutine
;
135 return STATUS_SUCCESS
;
140 return STATUS_INVALID_PARAMETER
;
148 PsRemoveCreateThreadNotifyRoutine(IN PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine
)
152 /* Loop the routines */
153 for(i
=0;i
<MAX_THREAD_NOTIFY_ROUTINE_COUNT
;i
++)
155 /* Check for a match */
156 if ((PVOID
)PspThreadNotifyRoutine
[i
] == (PVOID
)NotifyRoutine
)
158 /* Remove and return */
159 PspThreadNotifyRoutine
[i
] = NULL
;
160 return(STATUS_SUCCESS
);
165 return STATUS_INVALID_PARAMETER
;
173 PsSetCreateThreadNotifyRoutine(IN PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine
)
175 if (PspThreadNotifyRoutineCount
>= MAX_THREAD_NOTIFY_ROUTINE_COUNT
)
177 return(STATUS_INSUFFICIENT_RESOURCES
);
180 PspThreadNotifyRoutine
[PspThreadNotifyRoutineCount
] = NotifyRoutine
;
181 PspThreadNotifyRoutineCount
++;
183 return(STATUS_SUCCESS
);
188 PspRunCreateThreadNotifyRoutines(PETHREAD CurrentThread
,
192 CLIENT_ID Cid
= CurrentThread
->Cid
;
194 for (i
= 0; i
< PspThreadNotifyRoutineCount
; i
++)
196 PspThreadNotifyRoutine
[i
](Cid
.UniqueProcess
, Cid
.UniqueThread
, Create
);
202 PspRunCreateProcessNotifyRoutines(PEPROCESS CurrentProcess
,
206 HANDLE ProcessId
= (HANDLE
)CurrentProcess
->UniqueProcessId
;
207 HANDLE ParentId
= CurrentProcess
->InheritedFromUniqueProcessId
;
209 for(i
= 0; i
< MAX_PROCESS_NOTIFY_ROUTINE_COUNT
; ++i
)
211 if(PspProcessNotifyRoutine
[i
])
213 PspProcessNotifyRoutine
[i
](ParentId
, ProcessId
, Create
);
220 PspRunLoadImageNotifyRoutines(PUNICODE_STRING FullImageName
,
222 PIMAGE_INFO ImageInfo
)
226 for (i
= 0; i
< MAX_PROCESS_NOTIFY_ROUTINE_COUNT
; ++ i
)
228 if (PspLoadImageNotifyRoutine
[i
])
230 PspLoadImageNotifyRoutine
[i
](FullImageName
, ProcessId
, ImageInfo
);
237 PspRunLegoRoutine(IN PKTHREAD Thread
)
240 if (PspLegoNotifyRoutine
) (PspLegoNotifyRoutine
)(Thread
);