xref: /reactos/ntoskrnl/io/iomgr/ioevent.c (revision 40462c92)
1 /*
2  * PROJECT:         ReactOS Kernel
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * FILE:            ntoskrnl/io/iomgr/ioevent.c
5  * PURPOSE:         I/O Wrappers for the Executive Event Functions
6  * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)
7  *                  Eric Kohl
8  */
9 
10 /* INCLUDES *****************************************************************/
11 
12 #include <ntoskrnl.h>
13 #include <debug.h>
14 
15 /* PRIVATE FUNCTIONS *********************************************************/
16 
17 PKEVENT
18 NTAPI
19 IopCreateEvent(IN PUNICODE_STRING EventName,
20                IN PHANDLE EventHandle,
21                IN EVENT_TYPE Type)
22 {
23     OBJECT_ATTRIBUTES ObjectAttributes;
24     PKEVENT Event;
25     HANDLE Handle;
26     NTSTATUS Status;
27     PAGED_CODE();
28 
29     /* Initialize the object attributes */
30     InitializeObjectAttributes(&ObjectAttributes,
31                                EventName,
32                                OBJ_OPENIF | OBJ_KERNEL_HANDLE,
33                                NULL,
34                                NULL);
35 
36     /* Create the event */
37     Status = ZwCreateEvent(&Handle,
38                            EVENT_ALL_ACCESS,
39                            &ObjectAttributes,
40                            Type,
41                            TRUE);
42     if (!NT_SUCCESS(Status)) return NULL;
43 
44     /* Get a handle to it */
45     Status = ObReferenceObjectByHandle(Handle,
46                                        0,
47                                        ExEventObjectType,
48                                        KernelMode,
49                                        (PVOID*)&Event,
50                                        NULL);
51     if (!NT_SUCCESS(Status))
52     {
53         ZwClose(Handle);
54         return NULL;
55     }
56 
57     /* Dereference the extra count, and return the handle */
58     ObDereferenceObject(Event);
59     *EventHandle = Handle;
60     return Event;
61 }
62 
63 /* PUBLIC FUNCTIONS **********************************************************/
64 
65 /*
66  * @implemented
67  */
68 PKEVENT
69 NTAPI
70 IoCreateNotificationEvent(IN PUNICODE_STRING EventName,
71                           IN PHANDLE EventHandle)
72 {
73     /* Call the internal API */
74     return IopCreateEvent(EventName, EventHandle, NotificationEvent);
75 }
76 
77 /*
78  * @implemented
79  */
80 PKEVENT
81 NTAPI
82 IoCreateSynchronizationEvent(IN PUNICODE_STRING EventName,
83                              IN PHANDLE EventHandle)
84 {
85     /* Call the internal API */
86     return IopCreateEvent(EventName, EventHandle, SynchronizationEvent);
87 }
88 
89 /* EOF */
90