ReactOS  0.4.15-dev-1632-g4e289ce
fxdpcapi.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxDpcApi.cpp
8 
9 Abstract:
10 
11  This implements the WDFDPC API's
12 
13 Author:
14 
15 
16 
17 Environment:
18 
19  Kernel mode only
20 
21 Revision History:
22 
23 
24 --*/
25 
26 #include "fxcorepch.hpp"
27 
28 #include "fxdpc.hpp"
29 
30 extern "C" {
31 // #include "FxDpcApi.tmh"
32 }
33 
34 //
35 // extern "C" the entire file
36 //
37 extern "C" {
38 
42 STDCALL
43 WDFEXPORT(WdfDpcCreate)(
44  __in
46  __in
48  __in
50  __out
51  WDFDPC * Dpc
52  )
53 
54 /*++
55 
56 Routine Description:
57 
58  Create a DPC object that will call the supplied function with
59  context when it fires. It returns a handle to the WDFDPC object.
60 
61 Arguments:
62 
63  Config - WDF_DPC_CONFIG structure.
64 
65  Attributes - WDF_OBJECT_ATTRIBUTES to set the parent object and to request
66  a context memory allocation, and a DestroyCallback.
67 
68  Dpc - Pointer to location to returnt he resulting WDFDPC handle.
69 
70 Returns:
71 
72  STATUS_SUCCESS - A WDFDPC handle has been created.
73 
74 Notes:
75 
76  The WDFDPC object is deleted either when the DEVICE or QUEUE it is
77  associated as its parent with is deleted, or WdfObjectDelete is called.
78 
79  If the DPC is used to access WDM objects, a Cleanup callback should
80  be registered to allow references to be released.
81 
82 --*/
83 
84 {
88 
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_DPC_CONFIG)) {
108 
110  "WDF_DPC_CONFIG got Size %d, expected %d, %!STATUS!",
111  Config->Size, sizeof(WDF_DPC_CONFIG), status);
112 
113  return status;
114  }
115 
118  Attributes
119  );
120 
121  if (!NT_SUCCESS(status)) {
122  return status;
123  }
124 
126 
127  return status;
128 }
129 
130 
132 KDPC*
133 STDCALL
134 WDFEXPORT(WdfDpcWdmGetDpc)(
135  __in
137  __in
138  WDFDPC Dpc
139  )
140 /*++
141 
142 Routine Description:
143 
144  Return the KDPC* object pointer so that it may be linked into
145  a DPC list.
146 
147 Arguments:
148 
149  WDFDPC - Handle to WDFDPC object created with WdfDpcCreate.
150 
151 Returns:
152 
153  KDPC*
154 
155 --*/
156 
157 {
158  FxDpc* pFxDpc;
159 
161  Dpc,
162  FX_TYPE_DPC,
163  (PVOID*)&pFxDpc);
164 
165  return pFxDpc->GetDpcPtr();
166 }
167 
168 
170 BOOLEAN
171 STDCALL
172 WDFEXPORT(WdfDpcEnqueue)(
173  __in
175  __in
176  WDFDPC Dpc
177  )
178 
179 /*++
180 
181 Routine Description:
182 
183  Enqueue the DPC to run at a system determined time
184 
185 Arguments:
186 
187  WDFDPC - Handle to WDFDPC object created with WdfDpcCreate.
188 
189 Returns:
190 
191 --*/
192 
193 {
194  FxDpc* pFxDpc;
195 
197  Dpc,
198  FX_TYPE_DPC,
199  (PVOID*)&pFxDpc);
200 
202 }
203 
204 
207 BOOLEAN
208 STDCALL
209 WDFEXPORT(WdfDpcCancel)(
210  __in
212  __in
213  WDFDPC Dpc,
214  __in
215  BOOLEAN Wait
216  )
217 
218 /*++
219 
220 Routine Description:
221 
222  Attempt to cancel the DPC and returns status
223 
224 Arguments:
225 
226  WDFDPC - Handle to WDFDPC object created with WdfDpcCreate.
227 
228 Returns:
229 
230  TRUE - DPC was cancelled, and was not run
231 
232  FALSE - DPC was not cancelled, has run, is running, or will run
233 
234 --*/
235 
236 {
240 
242  Dpc,
243  FX_TYPE_DPC,
244  (PVOID*)&pFxDpc,
246 
247  if (Wait) {
249  if (!NT_SUCCESS(status)) {
250  return FALSE;
251  }
252  }
253 
254  return pFxDpc->Cancel(Wait);
255 }
256 
257 
258 
260 WDFOBJECT
261 STDCALL
262 WDFEXPORT(WdfDpcGetParentObject)(
263  __in
265  __in
266  WDFDPC Dpc
267  )
268 
269 /*++
270 
271 Routine Description:
272 
273  Return the parent parent object supplied to WdfDpcCreate.
274 
275 Arguments:
276 
277  WDFDPC - Handle to WDFDPC object created with WdfDpcCreate.
278 
279 Returns:
280 
281 --*/
282 
283 {
284  FxDpc* pFxDpc;
285 
287  Dpc,
288  FX_TYPE_DPC,
289  (PVOID*)&pFxDpc);
290 
291  return pFxDpc->GetObject();
292 }
293 
294 } // extern "C"
FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals), Dpc, FX_TYPE_DPC,(PVOID *)&pFxDpc)
#define _Must_inspect_result_
Definition: no_sal2.h:62
_Must_inspect_result_ _In_ PWDF_DPC_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFDPC * Dpc
Definition: wdfdpc.h:107
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
Definition: fxdpc.hpp:63
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:167
KDPC * GetDpcPtr(VOID)
Definition: fxdpc.hpp:117
LONG NTSTATUS
Definition: precomp.h:26
DriverGlobals
_Must_inspect_result_ __in PWDF_DPC_CONFIG __in PWDF_OBJECT_ATTRIBUTES __out WDFDPC * Dpc
Definition: fxdpcapi.cpp:84
_Must_inspect_result_ __in PWDF_DPC_CONFIG __in PWDF_OBJECT_ATTRIBUTES Attributes
Definition: fxdpcapi.cpp:47
NTSTATUS status
Definition: fxdpcapi.cpp:87
__in WDFDPC __in BOOLEAN Wait
Definition: fxdpcapi.cpp:236
#define FALSE
Definition: types.h:117
#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_ __drv_maxIRQL(DISPATCH_LEVEL) NTSTATUS STDCALL WDFEXPORT(WdfDpcCreate)(__in PWDF_DRIVER_GLOBALS DriverGlobals
__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
BOOLEAN Cancel(__in BOOLEAN Wait)
Definition: fxdpc.cpp:261
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
FxDpc * pFxDpc
Definition: fxdpcapi.cpp:238
static _Must_inspect_result_ NTSTATUS _Create(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_DPC_CONFIG Config, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in FxObject *ParentObject, __out WDFDPC *Dpc)
Definition: fxdpc.cpp:79
_Must_inspect_result_ NTSTATUS FxValidateObjectAttributes(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
Definition: ketypes.h:687
FxPointerNotNull(pFxDriverGlobals, Config)
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_CHILD_LIST_CONFIG Config
Definition: wdfchildlist.h:474
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
return KeInsertQueueDpc(pFxDpc->GetDpcPtr(), NULL, NULL)
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define HIGH_LEVEL
Definition: env_spec_w32.h:703
FxObjectHandleGetPtrAndGlobals(pFxDriverGlobals, Attributes->ParentObject, FX_TYPE_OBJECT,(PVOID *)&pParent, &pFxDriverGlobals)
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
__drv_when(Wait==__true, __drv_maxIRQL(PASSIVE_LEVEL)) __drv_when(Wait
FxObject * pParent
Definition: fxdpcapi.cpp:86
WDFOBJECT GetObject(VOID)
Definition: fxdpc.hpp:125
__inline PFX_DRIVER_GLOBALS GetFxDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: fxglobals.h:597
_Must_inspect_result_ __in PWDF_DPC_CONFIG Config
Definition: fxdpcapi.cpp:47
#define __in
Definition: dbghelp.h:35
pFxDriverGlobals
Definition: fxdpcapi.cpp:89
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
Definition: ps.c:97