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
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
)
125 /* Allocate memory for the event structure */
126 EngEvent
= ExAllocatePoolWithTag(NonPagedPool
,
129 if (!EngEvent
) return NULL
;
132 EngEvent
->fFlags
= 0;
133 EngEvent
->pKEvent
= NULL
;
135 /* Create a handle, and have Ob fill out the pKEvent field */
136 Status
= ObReferenceObjectByHandle(hUserObject
,
142 if (NT_SUCCESS(Status
))
144 /* Pulse the event and set that it's mapped by user */
145 KePulseEvent(pvEvent
, EVENT_INCREMENT
, FALSE
);
146 EngEvent
->pKEvent
= pvEvent
;
147 EngEvent
->fFlags
|= ENG_EVENT_USERMAPPED
;
151 /* Free the allocation */
152 ExFreePoolWithTag(EngEvent
, GDITAG_ENG_EVENT
);
156 /* Support legacy interface */
157 if (Reserved1
) *(PVOID
*)Reserved1
= EngEvent
;
166 /* Must be a usermapped event */
167 if (!(Event
->fFlags
& ENG_EVENT_USERMAPPED
)) return FALSE
;
169 /* Dereference the object, destroying it */
170 ObDereferenceObject(Event
->pKEvent
);
172 /* Free the Eng object */
173 ExFreePoolWithTag(Event
, GDITAG_ENG_EVENT
);
179 EngWaitForSingleObject(
181 _In_opt_ PLARGE_INTEGER TimeOut
)
184 DPRINT("EngWaitForSingleObject(%p %I64d)\n", Event
, TimeOut
->QuadPart
);
186 /* Validate parameters */
187 if (!Event
) return FALSE
;
189 /* Check if it's a usermapped event and fail in that case */
190 if (Event
->fFlags
& ENG_EVENT_USERMAPPED
)
192 /* Disallow deletion of usermapped events */
193 DPRINT1("Driver attempted to wait on a usermapped event!\n");
197 /* Wait for the event */
198 Status
= KeWaitForSingleObject(Event
->pKEvent
,
204 /* Check if there is a failure or a timeout */
205 return NT_SUCCESS(Status
);