ReactOS  0.4.14-dev-297-g23e575c
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)
23 BOOL
25 EngCreateEvent(
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 
61 BOOL
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 
83 VOID
87 {
88  /* Clear the event */
89  KeClearEvent(Event->pKEvent);
90 }
91 
92 LONG
96 {
97  /* Set the event */
98  return KeSetEvent(Event->pKEvent,
100  FALSE);
101 }
102 
103 LONG
104 APIENTRY
106  _In_ PEVENT Event)
107 {
108  /* Read the event state */
109  return KeReadStateEvent(Event->pKEvent);
110 }
111 
112 PEVENT
113 APIENTRY
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 
161 BOOL
162 APIENTRY
164  _In_ PEVENT Event)
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 
177 BOOL
178 APIENTRY
180  _In_ PEVENT Event,
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,
200  KernelMode,
201  FALSE,
202  TimeOut);
203 
204  /* Check if there is a failure or a timeout */
205  return NT_SUCCESS(Status);
206 }
207 
208 /* EOF */
LONG APIENTRY EngReadStateEvent(_In_ PEVENT Event)
Definition: engevent.c:105
#define _Must_inspect_result_
Definition: no_sal2.h:314
#define TRUE
Definition: types.h:120
ULONG fFlags
Definition: ntddvdeo.h:554
BOOL APIENTRY EngWaitForSingleObject(_In_ PEVENT Event, _In_opt_ PLARGE_INTEGER TimeOut)
Definition: engevent.c:179
LONG NTSTATUS
Definition: precomp.h:26
#define _Outptr_
Definition: no_sal2.h:396
BOOL APIENTRY EngDeleteEvent(_In_ _Post_ptr_invalid_ PEVENT Event)
Definition: engevent.c:63
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
POBJECT_TYPE ExEventObjectType
Definition: event.c:22
#define _In_opt_
Definition: no_sal2.h:213
PEVENT APIENTRY EngMapEvent(_In_ HDEV hDev, _In_ HANDLE hUserObject, _Reserved_ PVOID Reserved1, _Reserved_ PVOID Reserved2, _Reserved_ PVOID Reserved3)
Definition: engevent.c:114
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:496
unsigned int BOOL
Definition: ntddk_ex.h:94
VOID APIENTRY EngClearEvent(_In_ PEVENT Event)
Definition: engevent.c:85
long LONG
Definition: pedump.c:60
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
LONG APIENTRY EngSetEvent(_In_ PEVENT Event)
Definition: engevent.c:94
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_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:426
void DPRINT(...)
Definition: polytest.cpp:61
LONG NTAPI KePulseEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:68
Definition: bcd.h:202
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define _Reserved_
Definition: no_sal2.h:573
Status
Definition: gdiplustypes.h:24
#define _In_
Definition: no_sal2.h:204
#define _Post_ptr_invalid_
Definition: no_sal2.h:462
#define EVENT_INCREMENT
Definition: iotypes.h:565
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define GDITAG_ENG_EVENT
Definition: tags.h:58
Definition: bcd.h:201
#define DPRINT1
Definition: precomp.h:8
LONG NTAPI KeReadStateEvent(IN PKEVENT Event)
Definition: eventobj.c:120
_Must_inspect_result_ _Success_(return !=FALSE)
Definition: engevent.c:22
#define IO_NO_INCREMENT
Definition: iotypes.h:566
BOOL APIENTRY EngUnmapEvent(_In_ PEVENT Event)
Definition: engevent.c:163
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
PVOID pKEvent
Definition: ntddvdeo.h:553
#define APIENTRY
Definition: api.h:79