ReactOS 0.4.16-dev-329-g9223134
engevent.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Win32K
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: win32ss/gdi/eng/engevent.c
5 * PURPOSE: Event Support Routines
6 * PROGRAMMERS: Aleksey Bragin <aleksey@reactos.org>
7 * ReactOS Portable Systems Group
8 */
9
10/* INCLUDES *******************************************************************/
11
12#include <win32k.h>
13
14#include <ntddvdeo.h>
15
16#define NDEBUG
17#include <debug.h>
18
19/* PUBLIC FUNCTIONS ***********************************************************/
20
22_Success_(return != FALSE)
23BOOL
25EngCreateEvent(
26 _Outptr_ PEVENT *ppEvent)
27{
29 PENG_EVENT EngEvent;
30
31 /* Allocate memory for the event structure */
33 sizeof(ENG_EVENT) + sizeof(KEVENT),
35 if (EngEvent)
36 {
37 /* Set KEVENT pointer */
38 EngEvent->fFlags = 0;
39 EngEvent->pKEvent = EngEvent + 1;
40
41 /* Initialize the kernel event */
42 KeInitializeEvent(EngEvent->pKEvent,
44 FALSE);
45
46 /* Pass pointer to our structure to the caller */
47 *ppEvent = EngEvent;
48 DPRINT("EngCreateEvent() created %p\n", EngEvent);
49 }
50 else
51 {
52 /* Out of memory */
53 DPRINT("EngCreateEvent() failed\n");
54 Result = FALSE;
55 }
56
57 /* Return result */
58 return Result;
59}
60
61BOOL
65{
66 DPRINT("EngDeleteEvent(%p)\n", Event);
67
68 /* Check if it's a usermapped event */
69 if (Event->fFlags & ENG_EVENT_USERMAPPED)
70 {
71 /* Disallow deletion of usermapped events */
72 DPRINT1("Driver attempted to delete a usermapped event!\n");
73 return FALSE;
74 }
75
76 /* Free the allocated memory */
78
79 /* Return success */
80 return TRUE;
81}
82
83VOID
87{
88 /* Clear the event */
89 KeClearEvent(Event->pKEvent);
90}
91
92LONG
96{
97 /* Set the event */
98 return KeSetEvent(Event->pKEvent,
100 FALSE);
101}
102
103LONG
107{
108 /* Read the event state */
109 return KeReadStateEvent(Event->pKEvent);
110}
111
112PEVENT
115 _In_ HDEV hDev,
116 _In_ HANDLE hUserObject,
120{
121 PENG_EVENT EngEvent;
122 PVOID pvEvent;
124
125 /* Allocate memory for the event structure */
127 sizeof(ENG_EVENT),
129 if (!EngEvent) return NULL;
130
131 /* Zero it out */
132 EngEvent->fFlags = 0;
133 EngEvent->pKEvent = NULL;
134
135 /* Create a handle, and have Ob fill out the pKEvent field */
136 Status = ObReferenceObjectByHandle(hUserObject,
139 UserMode,
140 &pvEvent,
141 NULL);
142 if (NT_SUCCESS(Status))
143 {
144 /* Pulse the event and set that it's mapped by user */
146 EngEvent->pKEvent = pvEvent;
147 EngEvent->fFlags |= ENG_EVENT_USERMAPPED;
148 }
149 else
150 {
151 /* Free the allocation */
153 EngEvent = NULL;
154 }
155
156 /* Support legacy interface */
157 if (Reserved1) *(PVOID*)Reserved1 = EngEvent;
158 return EngEvent;
159}
160
161BOOL
165{
166 /* Must be a usermapped event */
167 if (!(Event->fFlags & ENG_EVENT_USERMAPPED)) return FALSE;
168
169 /* Dereference the object, destroying it */
170 ObDereferenceObject(Event->pKEvent);
171
172 /* Free the Eng object */
174 return TRUE;
175}
176
177BOOL
181 _In_opt_ PLARGE_INTEGER TimeOut)
182{
184 DPRINT("EngWaitForSingleObject(%p %I64d)\n", Event, TimeOut->QuadPart);
185
186 /* Validate parameters */
187 if (!Event) return FALSE;
188
189 /* Check if it's a usermapped event and fail in that case */
190 if (Event->fFlags & ENG_EVENT_USERMAPPED)
191 {
192 /* Disallow deletion of usermapped events */
193 DPRINT1("Driver attempted to wait on a usermapped event!\n");
194 return FALSE;
195 }
196
197 /* Wait for the event */
199 Executive,
201 FALSE,
202 TimeOut);
203
204 /* Check if there is a failure or a timeout */
205 return NT_SUCCESS(Status);
206}
207
208/* EOF */
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
@ Reserved2
Definition: bcd.h:202
@ Reserved1
Definition: bcd.h:201
#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:33
#define APIENTRY
Definition: api.h:79
VOID APIENTRY EngClearEvent(_In_ PEVENT Event)
Definition: engevent.c:85
LONG APIENTRY EngReadStateEvent(_In_ PEVENT Event)
Definition: engevent.c:105
BOOL APIENTRY EngDeleteEvent(_In_ _Post_ptr_invalid_ PEVENT Event)
Definition: engevent.c:63
BOOL APIENTRY EngUnmapEvent(_In_ PEVENT Event)
Definition: engevent.c:163
BOOL APIENTRY EngWaitForSingleObject(_In_ PEVENT Event, _In_opt_ PLARGE_INTEGER TimeOut)
Definition: engevent.c:179
PEVENT APIENTRY EngMapEvent(_In_ HDEV hDev, _In_ HANDLE hUserObject, _Reserved_ PVOID Reserved1, _Reserved_ PVOID Reserved2, _Reserved_ PVOID Reserved3)
Definition: engevent.c:114
LONG APIENTRY EngSetEvent(_In_ PEVENT Event)
Definition: engevent.c:94
@ ENG_EVENT_USERMAPPED
Definition: engevent.h:8
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#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
LONG NTAPI KeReadStateEvent(IN PKEVENT Event)
Definition: eventobj.c:120
unsigned int BOOL
Definition: ntddk_ex.h:94
Status
Definition: gdiplustypes.h:25
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define KernelMode
Definition: asm.h:34
#define UserMode
Definition: asm.h:35
#define _Post_ptr_invalid_
Definition: no_sal2.h:526
#define _Success_(c)
Definition: no_sal2.h:84
#define _Outptr_
Definition: no_sal2.h:262
#define _Must_inspect_result_
Definition: no_sal2.h:62
#define _In_
Definition: no_sal2.h:158
#define _In_opt_
Definition: no_sal2.h:212
#define _Reserved_
Definition: no_sal2.h:504
@ SynchronizationEvent
POBJECT_TYPE ExEventObjectType
Definition: event.c:18
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
@ Reserved3
Definition: sacdrv.h:1471
#define DPRINT
Definition: sndvol32.h:73
ULONG fFlags
Definition: ntddvdeo.h:624
PVOID pKEvent
Definition: ntddvdeo.h:623
#define GDITAG_ENG_EVENT
Definition: tags.h:58
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
#define EVENT_INCREMENT
Definition: iotypes.h:597
#define IO_NO_INCREMENT
Definition: iotypes.h:598
@ Executive
Definition: ketypes.h:415
#define ObDereferenceObject
Definition: obfuncs.h:203