2 * PROJECT: ReactOS Win32K
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: subsystems/win32/win32k/eng/engevent.c
5 * PURPOSE: Event Support Routines
6 * PROGRAMMERS: Aleksey Bragin <aleksey@reactos.org>
7 * ReactOS Portable Systems Group
10 /* INCLUDES *******************************************************************/
19 /* PUBLIC FUNCTIONS ***********************************************************/
22 _Success_(return != FALSE
)
26 _Outptr_ PEVENT
*ppEvent
)
28 BOOLEAN Result
= TRUE
;
31 /* Allocate memory for the event structure */
32 EngEvent
= ExAllocatePoolWithTag(NonPagedPool
,
33 sizeof(ENG_EVENT
) + sizeof(KEVENT
),
37 /* Set KEVENT pointer */
39 EngEvent
->pKEvent
= EngEvent
+ 1;
41 /* Initialize the kernel event */
42 KeInitializeEvent(EngEvent
->pKEvent
,
46 /* Pass pointer to our structure to the caller */
48 DPRINT("EngCreateEvent() created %p\n", EngEvent
);
53 DPRINT("EngCreateEvent() failed\n");
64 _In_ _Post_ptr_invalid_ PEVENT Event
)
66 DPRINT("EngDeleteEvent(%p)\n", Event
);
68 /* Check if it's a usermapped event */
69 if (Event
->fFlags
& ENG_EVENT_USERMAPPED
)
71 /* Disallow deletion of usermapped events */
72 DPRINT1("Driver attempted to delete a usermapped event!\n");
76 /* Free the allocated memory */
77 ExFreePoolWithTag(Event
, GDITAG_ENG_EVENT
);
89 KeClearEvent(Event
->pKEvent
);
98 return KeSetEvent(Event
->pKEvent
,
108 /* Read the event state */
109 return KeReadStateEvent(Event
->pKEvent
);
116 _In_ HANDLE hUserObject
,
117 _Reserved_ PVOID Reserved1
,
118 _Reserved_ PVOID Reserved2
,
119 _Reserved_ PVOID Reserved3
)
124 /* Allocate memory for the event structure */
125 EngEvent
= ExAllocatePoolWithTag(NonPagedPool
,
128 if (!EngEvent
) return NULL
;
131 EngEvent
->fFlags
= 0;
132 EngEvent
->pKEvent
= NULL
;
134 /* Create a handle, and have Ob fill out the pKEvent field */
135 Status
= ObReferenceObjectByHandle(EngEvent
,
141 if (NT_SUCCESS(Status
))
143 /* Pulse the event and set that it's mapped by user */
144 KePulseEvent(EngEvent
->pKEvent
, EVENT_INCREMENT
, FALSE
);
145 EngEvent
->fFlags
|= ENG_EVENT_USERMAPPED
;
149 /* Free the allocation */
150 ExFreePoolWithTag(EngEvent
, GDITAG_ENG_EVENT
);
154 /* Support legacy interface */
155 if (Reserved1
) *(PVOID
*)Reserved1
= EngEvent
;
164 /* Must be a usermapped event */
165 if (!(Event
->fFlags
& ENG_EVENT_USERMAPPED
)) return FALSE
;
167 /* Dereference the object, destroying it */
168 ObDereferenceObject(Event
->pKEvent
);
170 /* Free the Eng object */
171 ExFreePoolWithTag(Event
, GDITAG_ENG_EVENT
);
177 EngWaitForSingleObject(
179 _In_opt_ PLARGE_INTEGER TimeOut
)
182 DPRINT("EngWaitForSingleObject(%p %I64d)\n", Event
, TimeOut
->QuadPart
);
184 /* Validate parameters */
185 if (!Event
) return FALSE
;
187 /* Check if it's a usermapped event and fail in that case */
188 if (Event
->fFlags
& ENG_EVENT_USERMAPPED
)
190 /* Disallow deletion of usermapped events */
191 DPRINT1("Driver attempted to wait on a usermapped event!\n");
195 /* Wait for the event */
196 Status
= KeWaitForSingleObject(Event
->pKEvent
,
202 /* Check if there is a failure or a timeout */
203 return NT_SUCCESS(Status
);