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 *******************************************************************/
16 /* PUBLIC FUNCTIONS ***********************************************************/
19 _Success_(return != FALSE
)
23 _Outptr_ PEVENT
*ppEvent
)
25 BOOLEAN Result
= TRUE
;
28 /* Allocate memory for the event structure */
29 EngEvent
= ExAllocatePoolWithTag(NonPagedPool
,
30 sizeof(ENG_EVENT
) + sizeof(KEVENT
),
34 /* Set KEVENT pointer */
36 EngEvent
->pKEvent
= EngEvent
+ 1;
38 /* Initialize the kernel event */
39 KeInitializeEvent(EngEvent
->pKEvent
,
43 /* Pass pointer to our structure to the caller */
45 DPRINT("EngCreateEvent() created %p\n", EngEvent
);
50 DPRINT("EngCreateEvent() failed\n");
61 _In_ _Post_ptr_invalid_ PEVENT Event
)
63 DPRINT("EngDeleteEvent(%p)\n", Event
);
65 /* Check if it's a usermapped event */
66 if (Event
->fFlags
& ENG_EVENT_USERMAPPED
)
68 /* Disallow deletion of usermapped events */
69 DPRINT1("Driver attempted to delete a usermapped event!\n");
73 /* Free the allocated memory */
74 ExFreePoolWithTag(Event
, GDITAG_ENG_EVENT
);
86 KeClearEvent(Event
->pKEvent
);
95 return KeSetEvent(Event
->pKEvent
,
105 /* Read the event state */
106 return KeReadStateEvent(Event
->pKEvent
);
113 _In_ HANDLE hUserObject
,
114 _Reserved_ PVOID Reserved1
,
115 _Reserved_ PVOID Reserved2
,
116 _Reserved_ PVOID Reserved3
)
121 /* Allocate memory for the event structure */
122 EngEvent
= ExAllocatePoolWithTag(NonPagedPool
,
125 if (!EngEvent
) return NULL
;
128 EngEvent
->fFlags
= 0;
129 EngEvent
->pKEvent
= NULL
;
131 /* Create a handle, and have Ob fill out the pKEvent field */
132 Status
= ObReferenceObjectByHandle(EngEvent
,
138 if (NT_SUCCESS(Status
))
140 /* Pulse the event and set that it's mapped by user */
141 KePulseEvent(EngEvent
->pKEvent
, EVENT_INCREMENT
, FALSE
);
142 EngEvent
->fFlags
|= ENG_EVENT_USERMAPPED
;
146 /* Free the allocation */
147 ExFreePoolWithTag(EngEvent
, GDITAG_ENG_EVENT
);
151 /* Support legacy interface */
152 if (Reserved1
) *(PVOID
*)Reserved1
= EngEvent
;
161 /* Must be a usermapped event */
162 if (!(Event
->fFlags
& ENG_EVENT_USERMAPPED
)) return FALSE
;
164 /* Dereference the object, destroying it */
165 ObDereferenceObject(Event
->pKEvent
);
167 /* Free the Eng object */
168 ExFreePoolWithTag(Event
, GDITAG_ENG_EVENT
);
174 EngWaitForSingleObject(
176 _In_opt_ PLARGE_INTEGER TimeOut
)
179 DPRINT("EngWaitForSingleObject(%p %I64d)\n", Event
, TimeOut
->QuadPart
);
181 /* Validate parameters */
182 if (!Event
) return FALSE
;
184 /* Check if it's a usermapped event and fail in that case */
185 if (Event
->fFlags
& ENG_EVENT_USERMAPPED
)
187 /* Disallow deletion of usermapped events */
188 DPRINT1("Driver attempted to wait on a usermapped event!\n");
192 /* Wait for the event */
193 Status
= KeWaitForSingleObject(Event
->pKEvent
,
199 /* Check if there is a failure or a timeout */
200 return NT_SUCCESS(Status
);