ReactOS  0.4.15-dev-2704-gd5265b0
mxeventum.h
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 ModuleName:
6 
7  MxEventUm.h
8 
9 Abstract:
10 
11  User mode implementation of event
12  class defined in MxEvent.h
13 
14 Author:
15 
16 
17 
18 Revision History:
19 
20 
21 
22 --*/
23 
24 #pragma once
25 
26 typedef struct {
28 #if DBG
29  EVENT_TYPE Type; //tracked to allow ReadState only for notification events
30 #endif
31 } MdEvent;
32 
33 #include "DbgMacros.h"
34 #include "MxEvent.h"
35 
36 __inline
38 {
40 
41  m_Event.Event = NULL;
42 }
43 
44 __inline
46 {
47  //
48  // PLEASE NOTE: shared code must not rely of d'tor uninitializing the
49  // event. d'tor may not be invoked if the event is used in a structure
50  // which is allocated/deallocated using MxPoolAllocate/Free instead of
51  // new/delete
52  //
53  Uninitialize();
54 }
55 
57 __inline
62  )
63 {
65  HANDLE event;
66  BOOL bManualReset;
67 
68  if (NotificationEvent == Type)
69  {
70  bManualReset = TRUE;
71  }
72  else
73  {
74  bManualReset = FALSE;
75  }
76 
77  event = CreateEvent(
78  NULL,
79  bManualReset,
81  NULL
82  );
83 
84  if (NULL == event) {
87  goto exit;
88  }
89 
91 
92 #if DBG
93  m_Event.Type = Type;
94 #endif
95 
97 
98 exit:
99  return status;
100 }
101 
102 __inline
103 PVOID
105  )
106 {
108 
109  return m_Event.Event;
110 }
111 
112 __inline
113 VOID
115  )
116 {
118 
120 }
121 
122 __inline
123 VOID
126  )
127 {
129 
131 
132  Set();
133 }
134 
135 __inline
136 VOID
138  )
139 {
141 
143 }
144 
146 __inline
147 NTSTATUS
149  __in KWAIT_REASON WaitReason,
150  __in KPROCESSOR_MODE WaitMode,
153  )
154 /*++
155 
156 Routine Description:
157  Waits for the event
158 
159 Arguments:
160  WaitReason - Unused (only there to match km definition)
161 
162  WaitMode - Unuses (only there to match km definition)
163 
164  Altertable - Whether the wait is alertable
165 
166  Timout - Timeout in 100 ns units, MUST BE NEGATIVE
167  (negative implies relative timeout)
168 
169 Return Value:
170  Status corresponding to return value of WaitForSingleObjectEx
171 
172  --*/
173 {
175 
176  DWORD retVal;
177 
178  UNREFERENCED_PARAMETER(WaitReason);
179  UNREFERENCED_PARAMETER(WaitMode);
180 
181  LONGLONG relativeTimeOut = 0;
182  LONGLONG timeoutInMs = 0;
183  DWORD dwTimeout = 0;
184 
185  if (NULL != Timeout)
186  {
187  //
188  // Make sure that timeout is 0 or -ve (which implies relative timeout)
189  //
190  if (Timeout->QuadPart > 0)
191  {
193  "Absolute wait not supported in user mode",
194  FALSE
195  );
196 
198  }
199 
200  //
201  // Remove the -ve sign
202  //
203  if (Timeout->QuadPart < 0)
204  {
205  relativeTimeOut = -1 * Timeout->QuadPart;
206  }
207 
208  //
209  // Convert from 100ns units to milliseconds
210  //
211  timeoutInMs = (relativeTimeOut / (10 * 1000));
212 
213  if (timeoutInMs > ULONG_MAX)
214  {
215  Mx::MxAssertMsg("Timeout too large", FALSE);
216 
218  }
219  else
220  {
221  dwTimeout = (DWORD) timeoutInMs;
222  }
223  }
224 
225  retVal = WaitForSingleObjectEx(
226  m_Event.Event,
227  (NULL == Timeout) ? INFINITE : dwTimeout,
228  Alertable
229  );
230 
231  switch(retVal)
232  {
233  case WAIT_ABANDONED:
234  return STATUS_ABANDONED;
235  case WAIT_OBJECT_0:
236  return STATUS_SUCCESS;
237  case WAIT_TIMEOUT:
238  return STATUS_TIMEOUT;
239  case WAIT_FAILED:
240  {
241  DWORD err = GetLastError();
242  return WinErrorToNtStatus(err);
243  }
244  default:
245  {
246  //
247  // We shoudn't get here
248  //
250  return STATUS_UNSUCCESSFUL;
251  }
252  }
253 }
254 
255 LONG
256 __inline
258  )
259 {
261 
262 #if DBG
264 #endif
265 
267  m_Event.Event,
268  0
269  )) {
270  return 1;
271  }
272  else {
273  return 0;
274  }
275 }
276 
277 
278 __inline
279 VOID
281  )
282 {
283  if (NULL != m_Event.Event) {
285  m_Event.Event = NULL;
286  }
287 
289 }
#define CreateEvent
Definition: winbase.h:3604
__inline VOID Uninitialize()
Definition: mxeventkm.h:146
_In_ PVOID _In_ BOOLEAN Alertable
Definition: exfuncs.h:452
DWORD WINAPI WaitForSingleObjectEx(IN HANDLE hHandle, IN DWORD dwMilliseconds, IN BOOL bAlertable)
Definition: synch.c:94
#define _Must_inspect_result_
Definition: no_sal2.h:62
#define CloseHandle
Definition: compat.h:598
NTSTATUS WinErrorToNtStatus(__in ULONG WinError)
Definition: errtostatus.cpp:60
#define WAIT_ABANDONED
Definition: winbase.h:409
KEVENT MdEvent
Definition: mxeventkm.h:26
#define __in_opt
Definition: dbghelp.h:38
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
__inline VOID Set()
Definition: mxeventkm.h:91
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
static __inline VOID MxAssert(__in BOOLEAN Condition)
Definition: mxgeneralkm.h:165
#define DWORD
Definition: nt_native.h:44
LONG KPRIORITY
Definition: compat.h:662
__inline PVOID GetEvent()
Definition: mxeventkm.h:69
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
CHECK_RETURN_IF_USER_MODE __inline NTSTATUS Initialize(__in EVENT_TYPE Type, __in BOOLEAN InitialState)
Definition: mxeventkm.h:55
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
MdEvent m_Event
Definition: mxevent.h:36
__drv_when(Timeout !=NULL, _Must_inspect_result_) __inline NTSTATUS MxEvent
Definition: mxeventum.h:145
unsigned char BOOLEAN
__inline VOID Clear()
Definition: mxeventkm.h:102
enum _EVENT_TYPE EVENT_TYPE
int64_t LONGLONG
Definition: typedefs.h:68
_Must_inspect_result_ __inline NTSTATUS WaitFor(__in KWAIT_REASON WaitReason, __in KPROCESSOR_MODE WaitMode, __in BOOLEAN Alertable, __in_opt PLARGE_INTEGER Timeout)
Definition: mxeventkm.h:115
#define WAIT_OBJECT_0
Definition: winbase.h:403
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_ EVENT_TYPE _In_ BOOLEAN InitialState
Definition: exfuncs.h:165
#define SET_DBGFLAG_INITIALIZED
Definition: dbgmacros.h:59
Type
Definition: Type.h:6
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WAIT_FAILED
Definition: winbase.h:410
#define CLEAR_DBGFLAG_INITIALIZED
Definition: dbgmacros.h:60
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define WAIT_TIMEOUT
Definition: dderror.h:14
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_In_ WDFINTERRUPT _In_ WDF_INTERRUPT_POLICY _In_ WDF_INTERRUPT_PRIORITY Priority
Definition: wdfinterrupt.h:651
__inline ~MxEvent()
Definition: mxeventkm.h:46
#define err(...)
__inline LONG ReadState()
Definition: mxeventkm.h:135
struct _cl_event * event
Definition: glext.h:7739
static __inline VOID MxAssertMsg(__in LPSTR Message, __in BOOLEAN Condition)
Definition: mxgeneralkm.h:176
_In_ void _In_ PCCERT_CONTEXT _In_opt_ LPFILETIME _In_ DWORD _In_ DWORD dwTimeout
Definition: wincrypt.h:6077
HANDLE Event
Definition: mxeventum.h:27
static ULONG Timeout
Definition: ping.c:61
__inline MxEvent()
Definition: mxeventkm.h:31
#define NULL
Definition: types.h:112
__inline VOID SetWithIncrement(__in KPRIORITY Priority)
Definition: mxeventkm.h:80
BOOL WINAPI DECLSPEC_HOTPATCH ResetEvent(IN HANDLE hEvent)
Definition: synch.c:714
enum _KWAIT_REASON KWAIT_REASON
#define ASSERT_DBGFLAG_INITIALIZED
Definition: dbgmacros.h:58
#define STATUS_SUCCESS
Definition: shellext.h:65
void exit(int exitcode)
Definition: _exit.c:33
#define INFINITE
Definition: serial.h:102
#define __in
Definition: dbghelp.h:35
static SERVICE_STATUS status
Definition: service.c:31
#define STATUS_ABANDONED
Definition: ntstatus.h:75
#define ULONG_MAX
Definition: limits.h:44
Definition: ps.c:97