ReactOS  0.4.15-dev-3177-gd6a0299
fxtimerapi.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxTimerApi.cpp
8 
9 Abstract:
10 
11  This implements the WDFTIMER API's
12 
13 Author:
14 
15 
16 
17 Environment:
18 
19  Both kernel and user mode
20 
21 Revision History:
22 
23 
24 --*/
25 
26 #include "coreprivshared.hpp"
27 
28 #include "fxtimer.hpp"
29 
30 extern "C" {
31 // #include "FxTimerApi.tmh"
32 }
33 
34 //
35 // extern "C" the entire file
36 //
37 extern "C" {
38 
42 STDCALL
43 WDFEXPORT(WdfTimerCreate)(
44  __in
46  __in
48  __in
50  __out
51  WDFTIMER * Timer
52  )
53 
54 /*++
55 
56 Routine Description:
57 
58  Create a TIMER object that will call the supplied function
59  when it fires. It returns a handle to the WDFTIMER object.
60 
61 Arguments:
62 
63  Config - WDF_TIMER_CONFIG structure.
64 
65  Attributes - WDF_OBJECT_ATTRIBUTES to set the parent object, to request
66  a context memory allocation and a DestroyCallback.
67 
68  Timer - Pointer to location to return the resulting WDFTIMER handle.
69 
70 Returns:
71 
72  STATUS_SUCCESS - A WDFTIMER handle has been created.
73 
74 Notes:
75 
76  The WDFTIMER object is deleted either when the DEVICE or QUEUE it is
77  associated with is deleted, or WdfObjectDelete is called.
78 
79 --*/
80 
81 {
82  DDI_ENTRY();
83 
87 
89 
91  Attributes,
93  if (!NT_SUCCESS(status)) {
94  return status;
95  }
96 
98  Attributes->ParentObject,
100  (PVOID*)&pParent,
102 
105 
106  if (Config->Size != sizeof(WDF_TIMER_CONFIG) &&
107  Config->Size != sizeof(WDF_TIMER_CONFIG_V1_7) &&
108  Config->Size != sizeof(WDF_TIMER_CONFIG_V1_11)) {
110 
113  "PWDF_TIMER_CONFIG Size %d, expected %d, %!STATUS!",
114  Config->Size, sizeof(WDF_TIMER_CONFIG), status);
115 
116  return status;
117  }
118 
119  if (Config->Period > MAXLONG) {
121 
124  "Period value %u for a periodic timer cannot be greater than "
125  "MAXLONG, %!STATUS!", Config->Period, status);
126 
127  return status;
128  }
129 
130  //
131  // For version 1.13 and higher, the tolerable delay could
132  // go upto MAXULONG
133  //
134  if (Config->Size > sizeof(WDF_TIMER_CONFIG_V1_7) &&
136  if (Config->TolerableDelay > MAXLONG) {
137 
139 
142  "TolerableDelay value %u cannot be greater than MAXLONG, "
143  "%!STATUS!", Config->TolerableDelay, status);
144 
145  return status;
146  }
147  }
148 
149  if (Config->Size > sizeof(WDF_TIMER_CONFIG_V1_11)) {
150 
151 #if (FX_CORE_MODE == FX_CORE_USER_MODE)
152  if (Config->UseHighResolutionTimer) {
153 
157  "UseHighResolutionTimer option is not supported for UMDF "
158  "%!STATUS!", status);
159  return status;
160  }
161 #endif
162 
163  if ((Config->TolerableDelay > 0) &&
164  (Config->UseHighResolutionTimer)) {
165 
167 
170  "UseHighResolutionTimer option sepcified with non zero tolerable delay %u "
171  "%!STATUS!", Config->TolerableDelay, status);
172 
173  return status;
174  }
175  }
176 
178  Attributes,
180  if (!NT_SUCCESS(status)) {
181  return status;
182  }
183 
184  if (Config->Period > 0 &&
185  Attributes->ExecutionLevel == WdfExecutionLevelPassive) {
187 
190  "Passive level periodic timer is not supported. "
191  "Use one shot timer and queue the next timer from the callback "
192  "or use a dedicated thread, %!STATUS!",
193  status);
194 
195  return status;
196  }
197 
199 }
200 
202 BOOLEAN
203 STDCALL
204 WDFEXPORT(WdfTimerStart)(
205  __in
207  __in
208  WDFTIMER Timer,
209  __in
211  )
212 
213 /*++
214 
215 Routine Description:
216 
217  Enqueue the TIMER to run at the specified time.
218 
219 Arguments:
220 
221  WDFTIMER - Handle to WDFTIMER object created with WdfTimerCreate.
222 
223  DueTime - Time to execute
224 
225 Returns:
226 
227  TRUE if the timer object was in the system's timer queue
228 
229 --*/
230 
231 {
232  DDI_ENTRY();
233 
236 
238  Timer,
240  (PVOID*)&pFxTimer);
241 
243 
244  return pFxTimer->Start(li);
245 }
246 
249 BOOLEAN
250 STDCALL
251 WDFEXPORT(WdfTimerStop)(
252  __in
254  __in
255  WDFTIMER Timer,
256  __in
257  BOOLEAN Wait
258  )
259 
260 /*++
261 
262 Routine Description:
263 
264  Stop the TIMER
265 
266 Arguments:
267 
268  WDFTIMER - Handle to WDFTIMER object created with WdfTimerCreate.
269 
270 Returns:
271 
272  TRUE if the timer object was in the system's timer queue
273 
274 --*/
275 
276 {
277  DDI_ENTRY();
278 
280  FxTimer* pFxTimer;
282 
284  Timer,
286  (PVOID*)&pFxTimer,
288 
289  if (Wait) {
291  if (!NT_SUCCESS(status)) {
292  return FALSE;
293  }
294  }
295 
296  return pFxTimer->Stop(Wait);
297 }
298 
300 WDFOBJECT
301 STDCALL
302 WDFEXPORT(WdfTimerGetParentObject)(
303  __in
305  __in
306  WDFTIMER Timer
307  )
308 
309 /*++
310 
311 Routine Description:
312 
313  Return the Parent Object handle supplied to WdfTimerCreate
314 
315 Arguments:
316 
317  WDFTIMER - Handle to WDFTIMER object created with WdfTimerCreate.
318 
319 Returns:
320 
321  Handle to the framework object that is the specified timer object's
322  parent object
323 
324 --*/
325 
326 {
327  DDI_ENTRY();
328 
329  FxTimer* pFxTimer;
330 
332  Timer,
334  (PVOID*)&pFxTimer);
335 
336  return pFxTimer->GetObject();
337 }
338 
339 } // extern "C"
#define DDI_ENTRY()
Definition: fxglobalskm.h:56
FxObjectHandleGetPtrAndGlobals(pFxDriverGlobals, Attributes->ParentObject, FX_TYPE_OBJECT,(PVOID *)&pParent, &pFxDriverGlobals)
return STATUS_NOT_SUPPORTED
static _Must_inspect_result_ NTSTATUS _Create(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_TIMER_CONFIG Config, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in FxObject *ParentObject, __out WDFTIMER *Timer)
Definition: fxtimer.cpp:87
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
#define MAXLONG
Definition: umtypes.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:167
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ __in PWDF_TIMER_CONFIG __in PWDF_OBJECT_ATTRIBUTES __out WDFTIMER * Timer
Definition: fxtimerapi.cpp:81
BOOLEAN Stop(__in BOOLEAN Wait)
Definition: fxtimer.cpp:633
DriverGlobals
_Must_inspect_result_ __in PWDF_TIMER_CONFIG __in PWDF_OBJECT_ATTRIBUTES Attributes
Definition: fxtimerapi.cpp:47
return STATUS_NOT_IMPLEMENTED
#define FALSE
Definition: types.h:117
BOOLEAN Start(__in LARGE_INTEGER DueTime)
Definition: fxtimer.cpp:537
#define WDFEXPORT(a)
Definition: fxmacros.hpp:157
_Must_inspect_result_ NTSTATUS __inline FxValidateObjectAttributesForParentHandle(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
#define __out
Definition: dbghelp.h:62
unsigned char BOOLEAN
_Must_inspect_result_ BOOLEAN IsVersionGreaterThanOrEqualTo(__in ULONG Major, __in ULONG Minor)
Definition: globalskm.cpp:92
FxPointerNotNull(pFxDriverGlobals, Config)
NTSTATUS status
Definition: fxtimerapi.cpp:86
FxTimer * pFxTimer
Definition: fxtimerapi.cpp:234
__in WDFTIMER __in LONGLONG DueTime
Definition: fxtimerapi.cpp:231
int64_t LONGLONG
Definition: typedefs.h:68
__inline NTSTATUS FxVerifierCheckIrqlLevel(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in KIRQL Irql)
Definition: fxverifier.h:158
#define TRACINGDEVICE
Definition: dbgtrace.h:58
#define STDCALL
Definition: wdf.h:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
__drv_when(Wait==__true, __drv_maxIRQL(PASSIVE_LEVEL)) __drv_when(Wait
__in WDFTIMER __in BOOLEAN Wait
Definition: fxtimerapi.cpp:276
WDFOBJECT GetObject(VOID)
Definition: fxtimer.hpp:176
_Must_inspect_result_ NTSTATUS FxValidateObjectAttributes(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
_Must_inspect_result_ __in PWDF_TIMER_CONFIG Config
Definition: fxtimerapi.cpp:47
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define _Must_inspect_result_
Definition: ms_sal.h:558
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_CHILD_LIST_CONFIG Config
Definition: wdfchildlist.h:474
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
PFX_DRIVER_GLOBALS pFxDriverGlobals
Definition: fxtimerapi.cpp:84
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
_Must_inspect_result_ __drv_maxIRQL(DISPATCH_LEVEL) NTSTATUS STDCALL WDFEXPORT(WdfTimerCreate)(__in PWDF_DRIVER_GLOBALS DriverGlobals
FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals), Timer, FX_TYPE_TIMER,(PVOID *)&pFxTimer)
FxObject * pParent
Definition: fxtimerapi.cpp:85
__inline PFX_DRIVER_GLOBALS GetFxDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: fxglobals.h:597
#define __in
Definition: dbghelp.h:35
LARGE_INTEGER li
Definition: fxtimerapi.cpp:235
LONGLONG QuadPart
Definition: typedefs.h:114
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
Definition: ps.c:97