ReactOS 0.4.16-dev-1946-g52006dd
fxcxdeviceinitapi.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxCxDeviceInitApi.cpp
8
9Abstract:
10
11 This module exposes the "C" interface to the FxDevice object
12 for the class extensions.
13
14Author:
15
16
17
18Environment:
19
20 Both kernel and user mode
21
22Revision History:
23
24
25
26--*/
27
28#include "coreprivshared.hpp"
29
30extern "C" {
31// #include "FxCxDeviceInitApi.tmh"
32}
33
34//
35// Extern "C" the entire file
36//
37extern "C" {
38
40static
43 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
45 )
46{
48
49 if (FxIsClassExtension(FxDriverGlobals, CxDriverGlobals) == FALSE) {
52 "This function can only be called by a WDF "
53 "extension driver, Driver 0x%p, %!STATUS!",
54 CxDriverGlobals->Public.Driver, status);
55 FxVerifierDbgBreakPoint(FxDriverGlobals);
56 }
57
58 return status;
59}
60
66WDFEXPORT(WdfCxDeviceInitAssignWdmIrpPreprocessCallback)(
67 __in
68 PWDF_DRIVER_GLOBALS DriverGlobals,
69 __in
71 __in
73 __in
78 __in
80 )
81{
82 DDI_ENTRY();
83
87
88 cxDriverGlobals = GetFxDriverGlobals(DriverGlobals);
91
92 //
93 // Caller must be a class extension driver.
94 //
97 goto Done;
98 }
99
101
104 }
105
106 //
107 // ARRAY_SIZE(CxDeviceInit->PreprocessInfo->Dispatch) just returns a
108 // constant size, it does not actually deref PreprocessInfo (which could
109 // be NULL)
110 //
114 "MajorFunction %x is invalid, %!STATUS!",
116
117 goto Done;
118 }
119
120 //
121 // CX must call this API multiple times if it wants to register preprocess callbacks for
122 // multiple IRP major codes.
123 //
129 "Couldn't create object PreprocessInfo, "
130 "%!STATUS!", status);
131
132 goto Done;
133 }
135 }
136
138
139 if (NumMinorFunctions > 0) {
143 "Already assigned Minorfunctions, %!STATUS!",
144 status);
145 goto Done;
146 }
147
149 (PUCHAR) FxPoolAllocate(fxDriverGlobals,
151 sizeof(UCHAR) * NumMinorFunctions);
152
156 "Couldn't create object MinorFunctions, "
157 "%!STATUS!", status);
158 goto Done;
159 }
160
163 &MinorFunctions[0],
165 );
166
169 }
170
173
175
176Done:
177 return status;
178}
179
181VOID
182NTAPI
183WDFEXPORT(WdfCxDeviceInitSetIoInCallerContextCallback)(
184 __in
185 PWDF_DRIVER_GLOBALS DriverGlobals,
186 __in
188 __in
190 )
191
192/*++
193
194Routine Description:
195
196 Registers an I/O pre-processing callback for the class extension device.
197
198 If registered, any I/O for the device is first presented to this
199 callback function before being placed in any I/O Queue's.
200
201 The callback is invoked in the thread and/or DPC context of the
202 original WDM caller as presented to the I/O package. No framework
203 threading, locking, synchronization, or queuing occurs, and
204 responsibility for synchronization is up to the device driver.
205
206 This API is intended to support METHOD_NEITHER IRP_MJ_DEVICE_CONTROL's
207 which must access the user buffer in the original callers context. The
208 driver would probe and lock the buffer pages from within this event
209 handler using the functions supplied on the WDFREQUEST object, storing
210 any required mapped buffers and/or pointers on the WDFREQUEST context
211 whose size is set by the RequestContextSize of the WDF_DRIVER_CONFIG structure.
212
213 It is the responsibility of this routine to either complete the request, or
214 pass it on to the I/O package through WdfDeviceEnqueueRequest(Device, Request).
215
216Arguments:
217
218 CxDeviceInit - Class Extension Device initialization structure
219
220 EvtIoInCallerContext - Pointer to driver supplied callback function
221
222Return Value:
223
224 None
225
226--*/
227{
228 DDI_ENTRY();
229
233
234 cxDriverGlobals = GetFxDriverGlobals(DriverGlobals);
237
238 //
239 // Caller must be a class extension driver.
240 //
242 if (!NT_SUCCESS(status)) {
243 goto Done;
244 }
245
247
249
250Done:
251 return;
252}
253
255VOID
256NTAPI
257WDFEXPORT(WdfCxDeviceInitSetRequestAttributes)(
258 __in
259 PWDF_DRIVER_GLOBALS DriverGlobals,
260 __in
262 __in
264 )
265{
266 DDI_ENTRY();
267
271
272 cxDriverGlobals = GetFxDriverGlobals(DriverGlobals);
275
276 //
277 // Caller must be a class extension driver.
278 //
280 if (!NT_SUCCESS(status)) {
281 goto Done;
282 }
283
285
286 //
287 // Parent of all requests created from WDFDEVICE are parented by the WDFDEVICE.
288 //
292
293 if (!NT_SUCCESS(status)) {
295 return;
296 }
297
300 sizeof(WDF_OBJECT_ATTRIBUTES));
301
302Done:
303 return;
304}
305
307VOID
308NTAPI
309WDFEXPORT(WdfCxDeviceInitSetFileObjectConfig)(
310 __in
311 PWDF_DRIVER_GLOBALS DriverGlobals,
312 __in
314 __in
318 )
319
320/*++
321
322Routine Description:
323
324 Registers file object callbacks for class extensions.
325
326 Defaults to WdfFileObjectNotRequired if no file obj config set.
327
328Arguments:
329
330Returns:
331
332--*/
333
334{
335 DDI_ENTRY();
336
341
342 cxDriverGlobals = GetFxDriverGlobals(DriverGlobals);
345
346 //
347 // Caller must be a class extension driver.
348 //
350 if (!NT_SUCCESS(status)) {
351 goto Done;
352 }
353
355
359 "Invalid CxFileObjectConfig Size %d, expected %d",
361
363 goto Done;
364 }
365
372 );
373
374 if (!NT_SUCCESS(status)) {
376 goto Done;
377 }
378
379 //
380 // Validate AutoForwardCleanupClose.
381 //
382 switch (CxFileObjectConfig->AutoForwardCleanupClose) {
383 case WdfTrue:
384 case WdfFalse:
385 case WdfUseDefault:
386 break;
387
388 default:
391 "Invalid CxFileObjectConfig->AutoForwardCleanupClose value 0x%x, "
392 "expected WDF_TRI_STATE value",
393 CxFileObjectConfig->AutoForwardCleanupClose);
394
396 goto Done;
397 }
398
400
402 CxFileObjectConfig->AutoForwardCleanupClose;
403
404 //
405 // Remove bit flags and validate file object class value.
406 //
408 CxFileObjectConfig->FileObjectClass);
409
414 "Out of range CxFileObjectConfig->FileObjectClass %d",
415 CxFileObjectConfig->FileObjectClass);
417 goto Done;
418 }
419
420 //
421 // The optional flag can only be combined with a subset of values.
422 //
424 switch(normalizedFileClass) {
428 break;
429
430 default:
433 "Invalid CxFileObjectConfig->FileObjectClass %d",
434 CxFileObjectConfig->FileObjectClass);
436 goto Done;
437 break; // just in case static verification tools complain.
438 }
439 }
440
442
446
451 }
452
453Done:
454 return;
455}
456
460NTAPI
461WDFEXPORT(WdfCxDeviceInitAllocate)(
462 __in
463 PWDF_DRIVER_GLOBALS DriverGlobals,
464 __in
466 )
467{
468 DDI_ENTRY();
469
474
475 cxDriverGlobals = GetFxDriverGlobals(DriverGlobals);
477 fxDriverGlobals = DeviceInit->DriverGlobals;
479
480 //
481 // Caller must be a class extension driver.
482 //
484 if (!NT_SUCCESS(status)) {
485 goto Done;
486 }
487
489 if (!NT_SUCCESS(status)) {
490 goto Done;
491 }
492
495 goto Done;
496 }
497
500
501Done:
502 return cxDeviceInit;
503}
504
505} // extern "C"
506
#define __inline
Definition: _wctype.cpp:15
LONG NTSTATUS
Definition: precomp.h:26
#define ARRAY_SIZE(A)
Definition: main.h:20
#define __in
Definition: dbghelp.h:35
#define __in_bcount(x)
Definition: dbghelp.h:41
#define __in_opt
Definition: dbghelp.h:38
#define TRACINGDEVICE
Definition: dbgtrace.h:58
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define __drv_when(cond, annotes)
Definition: driverspecs.h:335
#define __drv_maxIRQL(irql)
Definition: driverspecs.h:291
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define NonPagedPool
Definition: env_spec_w32.h:307
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
NTSTATUS status
_Must_inspect_result_ __in PWDFCXDEVICE_INIT CxDeviceInit
_Must_inspect_result_ __in PWDFCXDEVICE_INIT __in PFN_WDFCXDEVICE_WDM_IRP_PREPROCESS __in UCHAR __in_opt PUCHAR __in ULONG NumMinorFunctions
static __inline NTSTATUS FxValiateCx(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PFX_DRIVER_GLOBALS CxDriverGlobals)
__in PWDFCXDEVICE_INIT __in PFN_WDF_IO_IN_CALLER_CONTEXT EvtIoInCallerContext
__in PWDFCXDEVICE_INIT __in PWDFCX_FILEOBJECT_CONFIG __in_opt PWDF_OBJECT_ATTRIBUTES FileObjectAttributes
PWDFCXDEVICE_INIT cxDeviceInit
_Must_inspect_result_ __in PWDFCXDEVICE_INIT __in PFN_WDFCXDEVICE_WDM_IRP_PREPROCESS __in UCHAR MajorFunction
__in PWDFCXDEVICE_INIT __in PWDFCX_FILEOBJECT_CONFIG CxFileObjectConfig
_Must_inspect_result_ __in PWDFCXDEVICE_INIT __in PFN_WDFCXDEVICE_WDM_IRP_PREPROCESS EvtCxDeviceWdmIrpPreprocess
PFX_DRIVER_GLOBALS fxDriverGlobals
WDF_FILEOBJECT_CLASS normalizedFileClass
__in PWDFCXDEVICE_INIT __in PWDF_OBJECT_ATTRIBUTES RequestAttributes
cxDeviceInit CxDriverGlobals
PFX_DRIVER_GLOBALS cxDriverGlobals
_Must_inspect_result_ __in PWDFDEVICE_INIT DeviceInit
BOOLEAN __inline FxIsFileObjectOptional(__in WDF_FILEOBJECT_CLASS FileObjectClass)
Definition: fxdevice.hpp:112
WDF_FILEOBJECT_CLASS __inline FxFileObjectClassNormalize(__in WDF_FILEOBJECT_CLASS FileObjectClass)
Definition: fxdevice.hpp:103
FxVerifierDbgBreakPoint(pFxDriverGlobals)
_Must_inspect_result_ __inline BOOLEAN FxIsClassExtension(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PFX_DRIVER_GLOBALS ExtDriverGlobals)
Definition: fxglobals.h:965
__inline PFX_DRIVER_GLOBALS GetFxDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: fxglobals.h:597
#define DDI_ENTRY()
Definition: fxglobalskm.h:56
#define WDFEXPORT(a)
Definition: fxmacros.hpp:157
#define FxPointerNotNull(FxDriverGlobals, Ptr)
Definition: fxmacros.hpp:253
@ FX_VALIDATE_OPTION_SYNCHRONIZATION_SCOPE_ALLOWED
@ FX_VALIDATE_OPTION_EXECUTION_LEVEL_ALLOWED
@ FX_VALIDATE_OPTION_PARENT_NOT_ALLOWED
_Must_inspect_result_ NTSTATUS FxValidateObjectAttributes(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
__inline NTSTATUS FxVerifierCheckIrqlLevel(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in KIRQL Irql)
Definition: fxverifier.h:158
#define ASSERT(a)
Definition: mode.c:44
#define _Must_inspect_result_
Definition: no_sal2.h:62
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
WDFCX_FILEOBJECT_CONFIG Callbacks
WDF_TRI_STATE AutoForwardCleanupClose
WDF_FILEOBJECT_CLASS Class
WDF_OBJECT_ATTRIBUTES Attributes
PFN_WDFCXDEVICE_WDM_IRP_PREPROCESS EvtCxDevicePreprocess
Info Dispatch[IRP_MJ_MAXIMUM_FUNCTION+1]
PFN_WDF_IO_IN_CALLER_CONTEXT IoInCallerContextCallback
static _Must_inspect_result_ PWDFCXDEVICE_INIT _AllocateCxDeviceInit(__in PWDFDEVICE_INIT DeviceInit)
PFX_DRIVER_GLOBALS ClientDriverGlobals
CxFileObjectInit FileObject
WDF_OBJECT_ATTRIBUTES RequestAttributes
FxIrpPreprocessInfo * PreprocessInfo
PFX_DRIVER_GLOBALS CxDriverGlobals
Definition: ps.c:97
#define NTAPI
Definition: typedefs.h:36
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PWDFDEVICE_INIT DeviceInit
Definition: wdfcontrol.h:113
NTSTATUS(NTAPI * PFN_WDFCXDEVICE_WDM_IRP_PREPROCESS)(_In_ WDFDEVICE Device, _Inout_ PIRP Irp, _In_ PVOID DispatchContext)
Definition: wdfcx.h:65
_In_ PWDFDEVICE_INIT _In_ PWDF_FILEOBJECT_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES FileObjectAttributes
Definition: wdfdevice.h:3406
_In_ PWDFDEVICE_INIT _In_ PFN_WDF_IO_IN_CALLER_CONTEXT EvtIoInCallerContext
Definition: wdfdevice.h:3511
_In_ PWDFDEVICE_INIT _In_ PWDF_OBJECT_ATTRIBUTES RequestAttributes
Definition: wdfdevice.h:3437
enum _WDF_FILEOBJECT_CLASS WDF_FILEOBJECT_CLASS
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ PFN_WDFDEVICE_WDM_IRP_PREPROCESS _In_ UCHAR _In_opt_ PUCHAR _In_ ULONG NumMinorFunctions
Definition: wdfdevice.h:3474
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ PFN_WDFDEVICE_WDM_IRP_PREPROCESS _In_ UCHAR _In_opt_ PUCHAR MinorFunctions
Definition: wdfdevice.h:3471
EVT_WDF_IO_IN_CALLER_CONTEXT * PFN_WDF_IO_IN_CALLER_CONTEXT
Definition: wdfdevice.h:1734
_In_ UCHAR MajorFunction
Definition: wdfdevice.h:1703
@ WdfFileObjectWdfCanUseFsContext
Definition: wdfdevice.h:461
@ WdfFileObjectInvalid
Definition: wdfdevice.h:459
@ WdfFileObjectWdfCanUseFsContext2
Definition: wdfdevice.h:462
@ WdfFileObjectWdfCannotUseFsContexts
Definition: wdfdevice.h:463
@ WdfTrue
Definition: wdftypes.h:88
@ WdfUseDefault
Definition: wdftypes.h:89
@ WdfFalse
Definition: wdftypes.h:87
#define WDFAPI
Definition: wdftypes.h:53
unsigned char UCHAR
Definition: xmlstorage.h:181