ReactOS  0.4.15-dev-3294-ge98684e
mxtimerkm.h
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 ModuleName:
6 
7  MxTimerKm.h
8 
9 Abstract:
10 
11  Kernel mode implementation of timer defined in
12  MxTimer.h
13 
14 Author:
15 
16 
17 Revision History:
18 
19 
20 
21 --*/
22 
23 #pragma once
24 
25 #define TolerableDelayUnlimited ((ULONG)-1)
26 
27 typedef
28 BOOLEAN
35  );
36 
37 typedef struct _MdTimer {
38 
39 
40  //
41  // The timer period
42  //
44 
45  //
46  // Tracks whether the ex timer is being used
47  //
49 
50 // #pragma warning(push)
51 // #pragma warning( disable: 4201 ) // nonstandard extension used : nameless struct/union
52 
53  union {
54  struct {
55  //
56  // Callback function to be invoked upon timer expiration
57  //
61  };
62 
63  struct {
64  //
65  // Callback function to be invoked upon timer expiration
66  //
69  };
70  };
71 
72 // #pragma warning(pop)
73 
74  //
75  // Context to be passed in to the callback function
76  //
78 
79 } MdTimer;
80 
81 #include "mxtimer.h"
82 
84  VOID
85  )
86 {
89  m_Timer.m_Period = 0;
91 }
92 
94  VOID
95  )
96 {
97  // __REACTOS__ Ex timers are not supported
98  // BOOLEAN wasCancelled;
99 
100  // if (m_Timer.m_IsExtTimer &&
101  // m_Timer.m_KernelExTimer) {
102  // wasCancelled = ExDeleteTimer(m_Timer.m_KernelExTimer,
103  // TRUE, // Cancel if pending. We don't expect
104  // // it to be pending though
105  // FALSE,// Wait
106  // NULL);
107  // //
108  // // Timer should not have been pending
109  // //
110  // ASSERT(wasCancelled == FALSE);
111  // m_Timer.m_KernelExTimer = NULL;
112  // }
113 }
114 
115 NTSTATUS
116 #ifdef _MSC_VER
117 #pragma prefast(suppress:__WARNING_UNMATCHED_DECL_ANNO, "_Must_inspect_result_ not needed in kernel mode as the function always succeeds");
118 #endif
121  __in MdDeferredRoutine TimerCallback,
123  )
124 {
126  m_Timer.m_TimerCallback = TimerCallback;
128 
130  KeInitializeDpc(&(m_Timer.TimerDpc), // Timer DPC
131  m_Timer.m_TimerCallback, // DeferredRoutine
132  m_Timer.m_TimerContext); // DeferredContext
133 
135 
136  return STATUS_SUCCESS;
137 }
138 
140 NTSTATUS
143  __in MdExtCallback TimerCallback,
144  __in LONG Period,
146  __in BOOLEAN UseHighResolutionTimer
147  )
148 /*++
149 
150 Routine Description:
151 
152  Initializes an Ex timer. By invoking this routine instead of
153  Initialize, the client is implicitly declaring that it wants
154  to use the new timers
155 
156 Arguments:
157 
158  TimerContext - Context to be passed back with the cllback
159  TimerCallback - Callback to be invoked when the timer fires
160  Period - Period in ms
161  TolerableDelay - Tolerable delay in ms
162  UseHighResolutionTimer- Indicates whether to use the high
163  resolution timers
164 
165 Returns:
166 
167  Status
168 
169 --*/
170 
171 {
172  // NTSTATUS status;
173  // ULONG attributes = 0;
174 
175  // m_Timer.m_TimerContext = TimerContext;
176  // m_Timer.m_ExTimerCallback = TimerCallback;
177  // m_Timer.m_Period = Period;
178 
179  // if (TolerableDelay != 0) {
180 
181  // attributes |= EX_TIMER_NO_WAKE;
182 
183  // } else if (UseHighResolutionTimer) {
184 
185  // attributes |= EX_TIMER_HIGH_RESOLUTION;
186  // }
187 
188  // m_Timer.m_KernelExTimer = ExAllocateTimer(m_Timer.m_ExTimerCallback,
189  // TimerContext,
190  // attributes);
191  // if (m_Timer.m_KernelExTimer) {
192 
193  // status = STATUS_SUCCESS;
194 
195  // } else {
196 
197  // status = STATUS_INSUFFICIENT_RESOURCES;
198  // }
199 
200  // m_Timer.m_IsExtTimer = TRUE;
201 
202  // return status;
203  return STATUS_NOT_IMPLEMENTED; // __REACTOS__ Ex timers are not supported
204 }
205 
206 
207 __inline
208 BOOLEAN
212  )
213 {
214  if (m_Timer.m_IsExtTimer) {
215  // __REACTOS__ Ex timers are not supported
216  // EXT_SET_PARAMETERS parameters;
217 
218  // ExInitializeSetTimerParameters(&parameters);
219 
220  // //
221  // // We get the delay in ms but the underlying API needs it in 100 ns
222  // // units. Convert tolerable delay from ms to 100 ns. However,
223  // // MAXULONG (TolerableDelayUnlimited) has a special meaning that the
224  // // system should never be woken up, so we assign the corresponding
225  // // special value for Ex timers
226  // //
227  // if (TolerableDelay == TolerableDelayUnlimited) {
228  // parameters.NoWakeTolerance = EX_TIMER_UNLIMITED_TOLERANCE;
229  // } else {
230  // parameters.NoWakeTolerance = ((LONGLONG) TolerableDelay) * 10 * 1000;
231  // }
232 
233  // return ExSetTimer(m_Timer.m_KernelExTimer,
234  // DueTime.QuadPart,
235  // (((LONGLONG) m_Timer.m_Period) * 10 * 1000),
236  // &parameters);
237  return FALSE;
238  } else {
239 
240  return KeSetCoalescableTimer(&(m_Timer.KernelTimer),
241  DueTime,
244  &(m_Timer.TimerDpc));
245  }
246 
247 }
248 
249 
250 VOID
254  )
255 {
256  if (m_Timer.m_IsExtTimer) {
257 
259 
260  } else {
261  KeSetCoalescableTimer(&(m_Timer.KernelTimer),
262  DueTime,
265  &(m_Timer.TimerDpc));
266  }
267 
268  return;
269 }
270 
272 BOOLEAN
274  VOID
275  )
276 {
277  BOOLEAN bRetVal;
278 
279  if (m_Timer.m_IsExtTimer) {
280  bRetVal = FALSE;
281  // bRetVal = ExCancelTimer(m_Timer.m_KernelExTimer, NULL); // __REACTOS__ Ex timers are not supported
282 
283  } else {
284  bRetVal = KeCancelTimer(&(m_Timer.KernelTimer));
285  }
286 
287  return bRetVal;
288 }
289 
290 VOID
292  VOID
293  )
294 {
296 }
EXT_CALLBACK * MdExtCallback
Definition: mxkm.h:36
_In_ LARGE_INTEGER _In_ ULONG _In_ ULONG TolerableDelay
Definition: kefuncs.h:1324
PVOID m_TimerContext
Definition: mxtimerkm.h:77
CHECK_RETURN_IF_USER_MODE __inline NTSTATUS Initialize(__in_opt PVOID TimerContext, __in MdDeferredRoutine TimerCallback, __in LONG Period)
Definition: mxtimerkm.h:119
__inline VOID FlushQueuedDpcs(VOID)
Definition: mxtimerkm.h:291
_Must_inspect_result_ _In_ PWDF_DPC_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFDPC * Dpc
Definition: wdfdpc.h:107
PEX_TIMER m_KernelExTimer
Definition: mxtimerkm.h:68
#define __in_opt
Definition: dbghelp.h:38
LONG NTSTATUS
Definition: precomp.h:26
_In_ LARGE_INTEGER _In_ ULONG Period
Definition: kefuncs.h:1324
__inline ~MxTimer(VOID)
Definition: mxtimerkm.h:93
MdDeferredRoutine m_TimerCallback
Definition: mxtimerkm.h:58
KDEFERRED_ROUTINE * MdDeferredRoutine
Definition: mxkm.h:35
__inline MxTimer(VOID)
Definition: mxtimerkm.h:83
return STATUS_NOT_IMPLEMENTED
#define FALSE
Definition: types.h:117
MdExtCallback m_ExTimerCallback
Definition: mxtimerkm.h:67
long LONG
Definition: pedump.c:60
struct _EX_TIMER * PEX_TIMER
Definition: extypes.h:291
unsigned char BOOLEAN
KTIMER KernelTimer
Definition: mxtimerkm.h:59
__inline VOID Start(__in LARGE_INTEGER DueTime, __in ULONG TolerableDelay=0)
Definition: mxtimerkm.h:251
BOOLEAN NTAPI KeCancelTimer(IN OUT PKTIMER Timer)
Definition: timerobj.c:206
#define STDCALL
Definition: wdf.h:45
KDPC TimerDpc
Definition: mxtimerkm.h:60
__inline BOOLEAN StartWithReturn(__in LARGE_INTEGER DueTime, __in ULONG TolerableDelay=0)
Definition: mxtimerkm.h:209
Definition: ketypes.h:687
#define __inout
Definition: dbghelp.h:50
#define _Must_inspect_result_
Definition: ms_sal.h:558
CHECK_RETURN_IF_USER_MODE __inline NTSTATUS InitializeEx(__in_opt PVOID TimerContext, __in MdExtCallbackType TimerCallback, __in LONG Period, __in ULONG TolerableDelay, __in BOOLEAN UseHighResolutionTimer)
Definition: mxtimerkm.h:141
LONG m_Period
Definition: mxtimerkm.h:43
_Must_inspect_result_ _In_ PWDF_TIMER_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFTIMER * Timer
Definition: wdftimer.h:153
static __inline VOID MxFlushQueuedDpcs()
Definition: mxgeneralkm.h:589
#define NULL
Definition: types.h:112
BOOLEAN(STDCALL * PFN_KE_SET_COALESCABLE_TIMER)(__inout PKTIMER Timer, __in LARGE_INTEGER DueTime, __in ULONG Period, __in ULONG TolerableDelay, __in_opt PKDPC Dpc)
Definition: mxtimerkm.h:29
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:187
BOOLEAN m_IsExtTimer
Definition: mxtimerkm.h:48
MdTimer m_Timer
Definition: mxtimer.h:33
#define BOOLEAN
Definition: pedump.c:73
struct _MdTimer MdTimer
unsigned int ULONG
Definition: retypes.h:1
_In_ PLARGE_INTEGER _In_opt_ PTIMER_APC_ROUTINE _In_opt_ PVOID TimerContext
Definition: zwfuncs.h:428
#define STATUS_SUCCESS
Definition: shellext.h:65
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
#define __in
Definition: dbghelp.h:35
VOID NTAPI KeInitializeTimerEx(OUT PKTIMER Timer, IN TIMER_TYPE Type)
Definition: timerobj.c:244
_Must_inspect_result_ __inline BOOLEAN Stop(VOID)
Definition: mxtimerkm.h:273