ReactOS 0.4.15-dev-8102-g108db8f
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/* GLOBALS *******************************************************************/
17
19
21{
26};
27
29{
30 /* EventBasicInformation */
32};
33
34/* FUNCTIONS *****************************************************************/
35
36CODE_SEG("INIT")
40{
41 OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
44 DPRINT("Creating Event Object Type\n");
45
46 /* Create the Event Object Type */
47 RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
48 RtlInitUnicodeString(&Name, L"Event");
49 ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
50 ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(KEVENT);
51 ObjectTypeInitializer.GenericMapping = ExpEventMapping;
52 ObjectTypeInitializer.PoolType = NonPagedPool;
53 ObjectTypeInitializer.ValidAccessMask = EVENT_ALL_ACCESS;
54 ObjectTypeInitializer.InvalidAttributes = OBJ_OPENLINK;
55 Status = ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &ExEventObjectType);
56 if (!NT_SUCCESS(Status)) return FALSE;
57 return TRUE;
58}
59
60/*
61 * @implemented
62 */
66{
69 PAGED_CODE();
70
71 /* Reference the Object */
76 (PVOID*)&Event,
77 NULL);
78
79 /* Check for Success */
81 {
82 /* Clear the Event and Dereference */
85 }
86
87 /* Return Status */
88 return Status;
89}
90
91/*
92 * @implemented
93 */
101{
106 PAGED_CODE();
107 DPRINT("NtCreateEvent(0x%p, 0x%x, 0x%p)\n",
109
110 /* Check if we were called from user-mode */
112 {
113 /* Enter SEH Block */
115 {
116 /* Check handle pointer */
118 }
120 {
121 /* Return the exception code */
123 }
124 _SEH2_END;
125 }
126
127 /* Create the Object */
132 NULL,
133 sizeof(KEVENT),
134 0,
135 0,
136 (PVOID*)&Event);
137
138 /* Check for Success */
139 if (NT_SUCCESS(Status))
140 {
141 /* Initialize the Event */
143 EventType,
145
146 /* Insert it */
148 NULL,
150 0,
151 NULL,
152 &hEvent);
153
154 /* Check for success */
155 if (NT_SUCCESS(Status))
156 {
157 /* Enter SEH for return */
159 {
160 /* Return the handle to the caller */
162 }
164 {
165 /* Get the exception code */
167 }
168 _SEH2_END;
169 }
170 }
171
172 /* Return Status */
173 return Status;
174}
175
176/*
177 * @implemented
178 */
180NTAPI
184{
188 PAGED_CODE();
189 DPRINT("NtOpenEvent(0x%p, 0x%x, 0x%p)\n",
191
192 /* Check if we were called from user-mode */
194 {
195 /* Enter SEH Block */
197 {
198 /* Check handle pointer */
200 }
202 {
203 /* Return the exception code */
205 }
206 _SEH2_END;
207 }
208
209 /* Open the Object */
213 NULL,
215 NULL,
216 &hEvent);
217
218 /* Check for success */
219 if (NT_SUCCESS(Status))
220 {
221 /* Enter SEH for return */
223 {
224 /* Return the handle to the caller */
226 }
228 {
229 /* Get the exception code */
231 }
232 _SEH2_END;
233 }
234
235 /* Return status */
236 return Status;
237}
238
239/*
240 * @implemented
241 */
243NTAPI
246{
250 PAGED_CODE();
251 DPRINT("NtPulseEvent(EventHandle 0%p PreviousState 0%p)\n",
253
254 /* Check if we were called from user-mode */
256 {
257 /* Entry SEH Block */
259 {
260 /* Make sure the state pointer is valid */
262 }
264 {
265 /* Return the exception code */
267 }
268 _SEH2_END;
269 }
270
271 /* Open the Object */
276 (PVOID*)&Event,
277 NULL);
278
279 /* Check for success */
280 if(NT_SUCCESS(Status))
281 {
282 /* Pulse the Event */
285
286 /* Check if caller wants the old state back */
287 if(PreviousState)
288 {
289 /* Entry SEH Block for return */
291 {
292 /* Return previous state */
293 *PreviousState = Prev;
294 }
296 {
297 /* Get the exception code */
299 }
300 _SEH2_END;
301 }
302 }
303
304 /* Return Status */
305 return Status;
306}
307
308/*
309 * @implemented
310 */
312NTAPI
314 IN EVENT_INFORMATION_CLASS EventInformationClass,
315 OUT PVOID EventInformation,
316 IN ULONG EventInformationLength,
318{
322 PEVENT_BASIC_INFORMATION BasicInfo =
323 (PEVENT_BASIC_INFORMATION)EventInformation;
324 PAGED_CODE();
325 DPRINT("NtQueryEvent(0x%p, 0x%x)\n", EventHandle, EventInformationClass);
326
327 /* Check buffers and class validity */
328 Status = DefaultQueryInfoBufferCheck(EventInformationClass,
330 sizeof(ExEventInfoClass) /
331 sizeof(ExEventInfoClass[0]),
333 EventInformation,
334 EventInformationLength,
336 NULL,
338 if(!NT_SUCCESS(Status))
339 {
340 /* Invalid buffers */
341 DPRINT("NtQuerySemaphore() failed, Status: 0x%x\n", Status);
342 return Status;
343 }
344
345 /* Get the Object */
350 (PVOID*)&Event,
351 NULL);
352
353 /* Check for success */
354 if(NT_SUCCESS(Status))
355 {
356 /* Entry SEH Block */
358 {
359 /* Return Event Type and State */
360 BasicInfo->EventType = Event->Header.Type;
361 BasicInfo->EventState = KeReadStateEvent(Event);
362
363 /* Return length */
365 }
367 {
368 /* Get the exception code */
370 }
371 _SEH2_END;
372
373 /* Dereference the Object */
375 }
376
377 /* Return status */
378 return Status;
379}
380
381/*
382 * @implemented
383 */
385NTAPI
388{
392 PAGED_CODE();
393 DPRINT("NtResetEvent(EventHandle 0%p PreviousState 0%p)\n",
395
396 /* Check if we were called from user-mode */
398 {
399 /* Entry SEH Block */
401 {
402 /* Make sure the state pointer is valid */
404 }
406 {
407 /* Return the exception code */
409 }
410 _SEH2_END;
411 }
412
413 /* Open the Object */
418 (PVOID*)&Event,
419 NULL);
420
421 /* Check for success */
422 if(NT_SUCCESS(Status))
423 {
424 /* Reset the Event */
425 LONG Prev = KeResetEvent(Event);
427
428 /* Check if caller wants the old state back */
429 if(PreviousState)
430 {
431 /* Entry SEH Block for return */
433 {
434 /* Return previous state */
435 *PreviousState = Prev;
436 }
438 {
439 /* Get the exception code */
441 }
442 _SEH2_END;
443 }
444 }
445
446 /* Return Status */
447 return Status;
448}
449
450/*
451 * @implemented
452 */
454NTAPI
457{
461 PAGED_CODE();
462 DPRINT("NtSetEvent(EventHandle 0%p PreviousState 0%p)\n",
464
465 /* Check if we were called from user-mode */
467 {
468 /* Entry SEH Block */
470 {
471 /* Make sure the state pointer is valid */
473 }
475 {
476 /* Return the exception code */
478 }
479 _SEH2_END;
480 }
481
482 /* Open the Object */
487 (PVOID*)&Event,
488 NULL);
489 if (NT_SUCCESS(Status))
490 {
491 /* Set the Event */
494
495 /* Check if caller wants the old state back */
496 if (PreviousState)
497 {
498 /* Entry SEH Block for return */
500 {
501 /* Return previous state */
502 *PreviousState = Prev;
503 }
505 {
507 }
508 _SEH2_END;
509 }
510 }
511
512 /* Return Status */
513 return Status;
514}
515
516/*
517 * @implemented
518 */
520NTAPI
522{
525 PAGED_CODE();
526
527 /* Open the Object */
532 (PVOID*)&Event,
533 NULL);
534 if (NT_SUCCESS(Status))
535 {
536 /* Set the Event */
539 }
540
541 /* Return Status */
542 return Status;
543}
544
545/* EOF */
#define PAGED_CODE()
#define CODE_SEG(...)
unsigned char BOOLEAN
struct NameRec_ * Name
Definition: cdprocs.h:460
LONG NTSTATUS
Definition: precomp.h:26
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:43
#define KEVENT
Definition: env_spec_w32.h:69
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define NonPagedPool
Definition: env_spec_w32.h:307
LONG NTAPI KePulseEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:68
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
VOID NTAPI KeSetEventBoostPriority(IN PKEVENT Event, IN PKTHREAD *WaitingThread OPTIONAL)
Definition: eventobj.c:229
LONG NTAPI KeReadStateEvent(IN PKEVENT Event)
Definition: eventobj.c:120
LONG NTAPI KeResetEvent(IN PKEVENT Event)
Definition: eventobj.c:133
#define ExGetPreviousMode
Definition: ex.h:140
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
Status
Definition: gdiplustypes.h:25
LONG NTAPI ExSystemExceptionFilter(VOID)
Definition: harderr.c:349
#define ICIF_QUERY
Definition: icif.h:18
#define IQS_SAME(Type, Alignment, Flags)
Definition: icif.h:37
#define ICIF_PROBE_READ_WRITE
Definition: icif.h:24
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define OBJ_OPENLINK
Definition: winternl.h:230
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
#define EVENT_QUERY_STATE
Definition: security.c:53
static HANDLE hEvent
Definition: comm.c:54
#define KernelMode
Definition: asm.h:34
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_ EVENT_TYPE EventType
Definition: exfuncs.h:167
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_ EVENT_TYPE _In_ BOOLEAN InitialState
Definition: exfuncs.h:169
enum _EVENT_INFORMATION_CLASS EVENT_INFORMATION_CLASS
struct _EVENT_BASIC_INFORMATION EVENT_BASIC_INFORMATION
struct _EVENT_BASIC_INFORMATION * PEVENT_BASIC_INFORMATION
#define SYNCHRONIZE
Definition: nt_native.h:61
ULONG ACCESS_MASK
Definition: nt_native.h:40
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define STANDARD_RIGHTS_READ
Definition: nt_native.h:65
#define STANDARD_RIGHTS_WRITE
Definition: nt_native.h:66
#define STANDARD_RIGHTS_EXECUTE
Definition: nt_native.h:67
enum _EVENT_TYPE EVENT_TYPE
NTSTATUS NTAPI NtSetEventBoostPriority(IN HANDLE EventHandle)
Definition: event.c:521
NTSTATUS NTAPI NtPulseEvent(IN HANDLE EventHandle, OUT PLONG PreviousState OPTIONAL)
Definition: event.c:244
NTSTATUS NTAPI NtSetEvent(IN HANDLE EventHandle, OUT PLONG PreviousState OPTIONAL)
Definition: event.c:455
NTSTATUS NTAPI NtOpenEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: event.c:181
NTSTATUS NTAPI NtResetEvent(IN HANDLE EventHandle, OUT PLONG PreviousState OPTIONAL)
Definition: event.c:386
BOOLEAN NTAPI ExpInitializeEventImplementation(VOID)
Definition: event.c:39
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:96
NTSTATUS NTAPI NtQueryEvent(IN HANDLE EventHandle, IN EVENT_INFORMATION_CLASS EventInformationClass, OUT PVOID EventInformation, IN ULONG EventInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: event.c:313
NTSTATUS NTAPI NtClearEvent(IN HANDLE EventHandle)
Definition: event.c:65
GENERIC_MAPPING ExpEventMapping
Definition: event.c:20
POBJECT_TYPE ExEventObjectType
Definition: event.c:18
static const INFORMATION_CLASS_INFO ExEventInfoClass[]
Definition: event.c:28
static __inline NTSTATUS DefaultQueryInfoBufferCheck(_In_ ULONG Class, _In_ const INFORMATION_CLASS_INFO *ClassList, _In_ ULONG ClassListEntries, _In_ ULONG Flags, _In_opt_ PVOID Buffer, _In_ ULONG BufferLength, _In_opt_ PULONG ReturnLength, _In_opt_ PULONG_PTR ReturnLengthPtr, _In_ KPROCESSOR_MODE PreviousMode)
Probe helper that validates the provided parameters whenever a NtQuery*** system call is invoked from...
Definition: probe.h:219
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
#define L(x)
Definition: ntvdm.h:50
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:2935
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:2532
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:1039
NTSTATUS NTAPI ObCreateObjectType(IN PUNICODE_STRING TypeName, IN POBJECT_TYPE_INITIALIZER ObjectTypeInitializer, IN PVOID Reserved, OUT POBJECT_TYPE *ObjectType)
Definition: oblife.c:1136
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:494
long LONG
Definition: pedump.c:60
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define ProbeForWriteLong(Ptr)
Definition: probe.h:37
#define ProbeForWriteHandle(Ptr)
Definition: probe.h:43
#define DPRINT
Definition: sndvol32.h:73
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
EVENT_TYPE EventType
Definition: extypes.h:731
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
ULONG DefaultNonPagedPoolCharge
Definition: obtypes.h:365
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IN
Definition: typedefs.h:39
int32_t * PLONG
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_In_ WDF_POWER_DEVICE_STATE PreviousState
Definition: wdfdevice.h:829
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2658
#define EVENT_MODIFY_STATE
Definition: winbase.h:163
_Out_ PHANDLE EventHandle
Definition: iofuncs.h:857
#define EVENT_INCREMENT
Definition: iotypes.h:597
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define ObDereferenceObject
Definition: obfuncs.h:203
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103