ReactOS  0.4.14-dev-606-g14ebc0b
event.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS Kernel
4  * FILE: ntoskrnl/ex/event.c
5  * PURPOSE: Event support
6  * PROGRAMMERS: Alex Ionescu(alex@relsoft.net)
7  * Thomas Weidenmueller
8  */
9 
10 /* INCLUDES *****************************************************************/
11 
12 #include <ntoskrnl.h>
13 #define NDEBUG
14 #include <debug.h>
15 
16 #if defined (ALLOC_PRAGMA)
17 #pragma alloc_text(INIT, ExpInitializeEventImplementation)
18 #endif
19 
20 /* GLOBALS *******************************************************************/
21 
23 
25 {
30 };
31 
32 static const INFORMATION_CLASS_INFO ExEventInfoClass[] =
33 {
34  /* EventBasicInformation */
35  ICI_SQ_SAME( sizeof(EVENT_BASIC_INFORMATION), sizeof(ULONG), ICIF_QUERY),
36 };
37 
38 /* FUNCTIONS *****************************************************************/
39 
40 BOOLEAN
41 INIT_FUNCTION
42 NTAPI
44 {
45  OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
48  DPRINT("Creating Event Object Type\n");
49 
50  /* Create the Event Object Type */
51  RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
52  RtlInitUnicodeString(&Name, L"Event");
53  ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
54  ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(KEVENT);
55  ObjectTypeInitializer.GenericMapping = ExpEventMapping;
56  ObjectTypeInitializer.PoolType = NonPagedPool;
57  ObjectTypeInitializer.ValidAccessMask = EVENT_ALL_ACCESS;
58  ObjectTypeInitializer.InvalidAttributes = OBJ_OPENLINK;
59  Status = ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &ExEventObjectType);
60  if (!NT_SUCCESS(Status)) return FALSE;
61  return TRUE;
62 }
63 
64 /*
65  * @implemented
66  */
68 NTAPI
70 {
71  PKEVENT Event;
73  PAGED_CODE();
74 
75  /* Reference the Object */
80  (PVOID*)&Event,
81  NULL);
82 
83  /* Check for Success */
84  if(NT_SUCCESS(Status))
85  {
86  /* Clear the Event and Dereference */
89  }
90 
91  /* Return Status */
92  return Status;
93 }
94 
95 /*
96  * @implemented
97  */
99 NTAPI
105 {
107  PKEVENT Event;
108  HANDLE hEvent;
110  PAGED_CODE();
111  DPRINT("NtCreateEvent(0x%p, 0x%x, 0x%p)\n",
113 
114  /* Check if we were called from user-mode */
115  if (PreviousMode != KernelMode)
116  {
117  /* Enter SEH Block */
118  _SEH2_TRY
119  {
120  /* Check handle pointer */
122  }
124  {
125  /* Return the exception code */
127  }
128  _SEH2_END;
129  }
130 
131  /* Create the Object */
135  PreviousMode,
136  NULL,
137  sizeof(KEVENT),
138  0,
139  0,
140  (PVOID*)&Event);
141 
142  /* Check for Success */
143  if (NT_SUCCESS(Status))
144  {
145  /* Initialize the Event */
147  EventType,
148  InitialState);
149 
150  /* Insert it */
152  NULL,
154  0,
155  NULL,
156  &hEvent);
157 
158  /* Check for success */
159  if (NT_SUCCESS(Status))
160  {
161  /* Enter SEH for return */
162  _SEH2_TRY
163  {
164  /* Return the handle to the caller */
165  *EventHandle = hEvent;
166  }
168  {
169  /* Get the exception code */
171  }
172  _SEH2_END;
173  }
174  }
175 
176  /* Return Status */
177  return Status;
178 }
179 
180 /*
181  * @implemented
182  */
183 NTSTATUS
184 NTAPI
188 {
189  HANDLE hEvent;
192  PAGED_CODE();
193  DPRINT("NtOpenEvent(0x%p, 0x%x, 0x%p)\n",
195 
196  /* Check if we were called from user-mode */
197  if (PreviousMode != KernelMode)
198  {
199  /* Enter SEH Block */
200  _SEH2_TRY
201  {
202  /* Check handle pointer */
204  }
206  {
207  /* Return the exception code */
209  }
210  _SEH2_END;
211  }
212 
213  /* Open the Object */
216  PreviousMode,
217  NULL,
219  NULL,
220  &hEvent);
221 
222  /* Check for success */
223  if (NT_SUCCESS(Status))
224  {
225  /* Enter SEH for return */
226  _SEH2_TRY
227  {
228  /* Return the handle to the caller */
229  *EventHandle = hEvent;
230  }
232  {
233  /* Get the exception code */
235  }
236  _SEH2_END;
237  }
238 
239  /* Return status */
240  return Status;
241 }
242 
243 /*
244  * @implemented
245  */
246 NTSTATUS
247 NTAPI
250 {
251  PKEVENT Event;
254  PAGED_CODE();
255  DPRINT("NtPulseEvent(EventHandle 0%p PreviousState 0%p)\n",
257 
258  /* Check if we were called from user-mode */
260  {
261  /* Entry SEH Block */
262  _SEH2_TRY
263  {
264  /* Make sure the state pointer is valid */
266  }
268  {
269  /* Return the exception code */
271  }
272  _SEH2_END;
273  }
274 
275  /* Open the Object */
279  PreviousMode,
280  (PVOID*)&Event,
281  NULL);
282 
283  /* Check for success */
284  if(NT_SUCCESS(Status))
285  {
286  /* Pulse the Event */
289 
290  /* Check if caller wants the old state back */
291  if(PreviousState)
292  {
293  /* Entry SEH Block for return */
294  _SEH2_TRY
295  {
296  /* Return previous state */
297  *PreviousState = Prev;
298  }
300  {
301  /* Get the exception code */
303  }
304  _SEH2_END;
305  }
306  }
307 
308  /* Return Status */
309  return Status;
310 }
311 
312 /*
313  * @implemented
314  */
315 NTSTATUS
316 NTAPI
318  IN EVENT_INFORMATION_CLASS EventInformationClass,
319  OUT PVOID EventInformation,
320  IN ULONG EventInformationLength,
322 {
323  PKEVENT Event;
326  PEVENT_BASIC_INFORMATION BasicInfo =
327  (PEVENT_BASIC_INFORMATION)EventInformation;
328  PAGED_CODE();
329  DPRINT("NtQueryEvent(0x%p, 0x%x)\n", EventHandle, EventInformationClass);
330 
331  /* Check buffers and class validity */
332  Status = DefaultQueryInfoBufferCheck(EventInformationClass,
334  sizeof(ExEventInfoClass) /
335  sizeof(ExEventInfoClass[0]),
336  EventInformation,
337  EventInformationLength,
338  ReturnLength,
339  NULL,
340  PreviousMode);
341  if(!NT_SUCCESS(Status))
342  {
343  /* Invalid buffers */
344  DPRINT("NtQuerySemaphore() failed, Status: 0x%x\n", Status);
345  return Status;
346  }
347 
348  /* Get the Object */
352  PreviousMode,
353  (PVOID*)&Event,
354  NULL);
355 
356  /* Check for success */
357  if(NT_SUCCESS(Status))
358  {
359  /* Entry SEH Block */
360  _SEH2_TRY
361  {
362  /* Return Event Type and State */
363  BasicInfo->EventType = Event->Header.Type;
364  BasicInfo->EventState = KeReadStateEvent(Event);
365 
366  /* Return length */
368  }
370  {
371  /* Get the exception code */
373  }
374  _SEH2_END;
375 
376  /* Dereference the Object */
378  }
379 
380  /* Return status */
381  return Status;
382 }
383 
384 /*
385  * @implemented
386  */
387 NTSTATUS
388 NTAPI
391 {
392  PKEVENT Event;
395  PAGED_CODE();
396  DPRINT("NtResetEvent(EventHandle 0%p PreviousState 0%p)\n",
398 
399  /* Check if we were called from user-mode */
400  if ((PreviousState) && (PreviousMode != KernelMode))
401  {
402  /* Entry SEH Block */
403  _SEH2_TRY
404  {
405  /* Make sure the state pointer is valid */
407  }
409  {
410  /* Return the exception code */
412  }
413  _SEH2_END;
414  }
415 
416  /* Open the Object */
420  PreviousMode,
421  (PVOID*)&Event,
422  NULL);
423 
424  /* Check for success */
425  if(NT_SUCCESS(Status))
426  {
427  /* Reset the Event */
428  LONG Prev = KeResetEvent(Event);
430 
431  /* Check if caller wants the old state back */
432  if(PreviousState)
433  {
434  /* Entry SEH Block for return */
435  _SEH2_TRY
436  {
437  /* Return previous state */
438  *PreviousState = Prev;
439  }
441  {
442  /* Get the exception code */
444  }
445  _SEH2_END;
446  }
447  }
448 
449  /* Return Status */
450  return Status;
451 }
452 
453 /*
454  * @implemented
455  */
456 NTSTATUS
457 NTAPI
460 {
461  PKEVENT Event;
464  PAGED_CODE();
465  DPRINT("NtSetEvent(EventHandle 0%p PreviousState 0%p)\n",
467 
468  /* Check if we were called from user-mode */
469  if ((PreviousState) && (PreviousMode != KernelMode))
470  {
471  /* Entry SEH Block */
472  _SEH2_TRY
473  {
474  /* Make sure the state pointer is valid */
476  }
478  {
479  /* Return the exception code */
481  }
482  _SEH2_END;
483  }
484 
485  /* Open the Object */
489  PreviousMode,
490  (PVOID*)&Event,
491  NULL);
492  if (NT_SUCCESS(Status))
493  {
494  /* Set the Event */
497 
498  /* Check if caller wants the old state back */
499  if (PreviousState)
500  {
501  /* Entry SEH Block for return */
502  _SEH2_TRY
503  {
504  /* Return previous state */
505  *PreviousState = Prev;
506  }
508  {
510  }
511  _SEH2_END;
512  }
513  }
514 
515  /* Return Status */
516  return Status;
517 }
518 
519 /*
520  * @implemented
521  */
522 NTSTATUS
523 NTAPI
525 {
526  PKEVENT Event;
528  PAGED_CODE();
529 
530  /* Open the Object */
535  (PVOID*)&Event,
536  NULL);
537  if (NT_SUCCESS(Status))
538  {
539  /* Set the Event */
542  }
543 
544  /* Return Status */
545  return Status;
546 }
547 
548 /* EOF */
NTSTATUS NTAPI ObOpenObjectByName(IN POBJECT_ATTRIBUTES ObjectAttributes, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN OUT PVOID ParseContext, OUT PHANDLE Handle)
Definition: obhandle.c:2529
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:39
#define IN
Definition: typedefs.h:38
NTSTATUS NTAPI ObCreateObjectType(IN PUNICODE_STRING TypeName, IN POBJECT_TYPE_INITIALIZER ObjectTypeInitializer, IN PVOID Reserved, OUT POBJECT_TYPE *ObjectType)
Definition: oblife.c:1048
#define TRUE
Definition: types.h:120
static const INFORMATION_CLASS_INFO ExEventInfoClass[]
Definition: event.c:32
#define STANDARD_RIGHTS_WRITE
Definition: nt_native.h:66
#define ProbeForWriteLong(Ptr)
Definition: probe.h:37
LONG NTSTATUS
Definition: precomp.h:26
#define EVENT_QUERY_STATE
Definition: security.c:53
NTSTATUS NTAPI NtCreateEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN EVENT_TYPE EventType, IN BOOLEAN InitialState)
Definition: event.c:100
#define OBJ_OPENLINK
Definition: winternl.h:230
NTSTATUS NTAPI NtSetEventBoostPriority(IN HANDLE EventHandle)
Definition: event.c:524
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define STANDARD_RIGHTS_EXECUTE
Definition: nt_native.h:67
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI NtResetEvent(IN HANDLE EventHandle, OUT PLONG PreviousState OPTIONAL)
Definition: event.c:389
POBJECT_TYPE ExEventObjectType
Definition: event.c:22
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
static HANDLE hEvent
Definition: comm.c:54
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
GENERIC_MAPPING ExpEventMapping
Definition: event.c:24
long LONG
Definition: pedump.c:60
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
enum _EVENT_INFORMATION_CLASS EVENT_INFORMATION_CLASS
struct NameRec_ * Name
Definition: cdprocs.h:464
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI NtQueryEvent(IN HANDLE EventHandle, IN EVENT_INFORMATION_CLASS EventInformationClass, OUT PVOID EventInformation, IN ULONG EventInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: event.c:317
void DPRINT(...)
Definition: polytest.cpp:61
LONG NTAPI KePulseEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:68
NTSTATUS NTAPI ObCreateObject(IN KPROCESSOR_MODE ProbeMode OPTIONAL, IN POBJECT_TYPE Type, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext OPTIONAL, IN ULONG ObjectSize, IN ULONG PagedPoolCharge OPTIONAL, IN ULONG NonPagedPoolCharge OPTIONAL, OUT PVOID *Object)
Definition: oblife.c:952
enum _EVENT_TYPE EVENT_TYPE
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
NTSTATUS NTAPI NtSetEvent(IN HANDLE EventHandle, OUT PLONG PreviousState OPTIONAL)
Definition: event.c:458
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_ EVENT_TYPE _In_ BOOLEAN InitialState
Definition: exfuncs.h:165
struct _EVENT_BASIC_INFORMATION EVENT_BASIC_INFORMATION
#define ProbeForWriteHandle(Ptr)
Definition: probe.h:43
struct _KEVENT KEVENT
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
static const WCHAR L[]
Definition: oid.c:1250
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:414
static __inline NTSTATUS DefaultQueryInfoBufferCheck(ULONG Class, const INFORMATION_CLASS_INFO *ClassList, ULONG ClassListEntries, PVOID Buffer, ULONG BufferLength, PULONG ReturnLength, PULONG_PTR ReturnLengthPtr, KPROCESSOR_MODE PreviousMode)
Definition: probe.h:59
#define STANDARD_RIGHTS_READ
Definition: nt_native.h:65
#define SYNCHRONIZE
Definition: nt_native.h:61
NTSTATUS NTAPI NtOpenEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: event.c:185
Status
Definition: gdiplustypes.h:24
_In_ PLARGE_INTEGER _In_opt_ PTIMER_APC_ROUTINE _In_opt_ PVOID _In_ BOOLEAN _In_opt_ LONG _Out_opt_ PBOOLEAN PreviousState
Definition: zwfuncs.h:428
_SEH2_END
Definition: create.c:4424
NTSTATUS NTAPI ObInsertObject(IN PVOID Object, IN PACCESS_STATE AccessState OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG ObjectPointerBias, OUT PVOID *NewObject OPTIONAL, OUT PHANDLE Handle)
Definition: obhandle.c:2932
#define EVENT_INCREMENT
Definition: iotypes.h:565
LONG NTAPI ExSystemExceptionFilter(VOID)
Definition: harderr.c:351
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
struct _EVENT_BASIC_INFORMATION * PEVENT_BASIC_INFORMATION
unsigned int * PULONG
Definition: retypes.h:1
#define OUT
Definition: typedefs.h:39
LONG NTAPI KeReadStateEvent(IN PKEVENT Event)
Definition: eventobj.c:120
LONG NTAPI KeResetEvent(IN PKEVENT Event)
Definition: eventobj.c:133
NTSTATUS NTAPI NtClearEvent(IN HANDLE EventHandle)
Definition: event.c:69
unsigned int ULONG
Definition: retypes.h:1
#define EVENT_MODIFY_STATE
Definition: winbase.h:163
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
VOID NTAPI KeSetEventBoostPriority(IN PKEVENT Event, IN PKTHREAD *WaitingThread OPTIONAL)
Definition: eventobj.c:229
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_ EVENT_TYPE EventType
Definition: exfuncs.h:165
BOOLEAN INIT_FUNCTION NTAPI ExpInitializeEventImplementation(VOID)
Definition: event.c:43
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
NTSTATUS NTAPI NtPulseEvent(IN HANDLE EventHandle, OUT PLONG PreviousState OPTIONAL)
Definition: event.c:248
signed int * PLONG
Definition: retypes.h:5
ULONG DefaultNonPagedPoolCharge
Definition: obtypes.h:365
ULONG ACCESS_MASK
Definition: nt_native.h:40
EVENT_TYPE EventType
Definition: extypes.h:731
_Out_ PHANDLE EventHandle
Definition: iofuncs.h:855
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68