ReactOS 0.4.15-dev-7958-gcd0bb1a
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
39__inline
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
65WDFEXPORT(WdfCxDeviceInitAssignWdmIrpPreprocessCallback)(
66 __in
68 __in
70 __in
72 __in
77 __in
79 )
80{
81 DDI_ENTRY();
82
86
90
91 //
92 // Caller must be a class extension driver.
93 //
96 goto Done;
97 }
98
100
103 }
104
105 //
106 // ARRAY_SIZE(CxDeviceInit->PreprocessInfo->Dispatch) just returns a
107 // constant size, it does not actually deref PreprocessInfo (which could
108 // be NULL)
109 //
113 "MajorFunction %x is invalid, %!STATUS!",
115
116 goto Done;
117 }
118
119 //
120 // CX must call this API multiple times if it wants to register preprocess callbacks for
121 // multiple IRP major codes.
122 //
128 "Couldn't create object PreprocessInfo, "
129 "%!STATUS!", status);
130
131 goto Done;
132 }
134 }
135
137
138 if (NumMinorFunctions > 0) {
142 "Already assigned Minorfunctions, %!STATUS!",
143 status);
144 goto Done;
145 }
146
148 (PUCHAR) FxPoolAllocate(fxDriverGlobals,
150 sizeof(UCHAR) * NumMinorFunctions);
151
155 "Couldn't create object MinorFunctions, "
156 "%!STATUS!", status);
157 goto Done;
158 }
159
162 &MinorFunctions[0],
164 );
165
168 }
169
172
174
175Done:
176 return status;
177}
178
180VOID
181WDFEXPORT(WdfCxDeviceInitSetIoInCallerContextCallback)(
182 __in
184 __in
186 __in
188 )
189
190/*++
191
192Routine Description:
193
194 Registers an I/O pre-processing callback for the class extension device.
195
196 If registered, any I/O for the device is first presented to this
197 callback function before being placed in any I/O Queue's.
198
199 The callback is invoked in the thread and/or DPC context of the
200 original WDM caller as presented to the I/O package. No framework
201 threading, locking, synchronization, or queuing occurs, and
202 responsibility for synchronization is up to the device driver.
203
204 This API is intended to support METHOD_NEITHER IRP_MJ_DEVICE_CONTROL's
205 which must access the user buffer in the original callers context. The
206 driver would probe and lock the buffer pages from within this event
207 handler using the functions supplied on the WDFREQUEST object, storing
208 any required mapped buffers and/or pointers on the WDFREQUEST context
209 whose size is set by the RequestContextSize of the WDF_DRIVER_CONFIG structure.
210
211 It is the responsibility of this routine to either complete the request, or
212 pass it on to the I/O package through WdfDeviceEnqueueRequest(Device, Request).
213
214Arguments:
215
216 CxDeviceInit - Class Extension Device initialization structure
217
218 EvtIoInCallerContext - Pointer to driver supplied callback function
219
220Return Value:
221
222 None
223
224--*/
225{
226 DDI_ENTRY();
227
231
235
236 //
237 // Caller must be a class extension driver.
238 //
240 if (!NT_SUCCESS(status)) {
241 goto Done;
242 }
243
245
247
248Done:
249 return;
250}
251
253VOID
254WDFEXPORT(WdfCxDeviceInitSetRequestAttributes)(
255 __in
257 __in
259 __in
261 )
262{
263 DDI_ENTRY();
264
268
272
273 //
274 // Caller must be a class extension driver.
275 //
277 if (!NT_SUCCESS(status)) {
278 goto Done;
279 }
280
282
283 //
284 // Parent of all requests created from WDFDEVICE are parented by the WDFDEVICE.
285 //
289
290 if (!NT_SUCCESS(status)) {
292 return;
293 }
294
297 sizeof(WDF_OBJECT_ATTRIBUTES));
298
299Done:
300 return;
301}
302
304VOID
305WDFEXPORT(WdfCxDeviceInitSetFileObjectConfig)(
306 __in
308 __in
310 __in
314 )
315
316/*++
317
318Routine Description:
319
320 Registers file object callbacks for class extensions.
321
322 Defaults to WdfFileObjectNotRequired if no file obj config set.
323
324Arguments:
325
326Returns:
327
328--*/
329
330{
331 DDI_ENTRY();
332
337
341
342 //
343 // Caller must be a class extension driver.
344 //
346 if (!NT_SUCCESS(status)) {
347 goto Done;
348 }
349
351
355 "Invalid CxFileObjectConfig Size %d, expected %d",
357
359 goto Done;
360 }
361
368 );
369
370 if (!NT_SUCCESS(status)) {
372 goto Done;
373 }
374
375 //
376 // Validate AutoForwardCleanupClose.
377 //
378 switch (CxFileObjectConfig->AutoForwardCleanupClose) {
379 case WdfTrue:
380 case WdfFalse:
381 case WdfUseDefault:
382 break;
383
384 default:
387 "Invalid CxFileObjectConfig->AutoForwardCleanupClose value 0x%x, "
388 "expected WDF_TRI_STATE value",
389 CxFileObjectConfig->AutoForwardCleanupClose);
390
392 goto Done;
393 }
394
396
398 CxFileObjectConfig->AutoForwardCleanupClose;
399
400 //
401 // Remove bit flags and validate file object class value.
402 //
404 CxFileObjectConfig->FileObjectClass);
405
410 "Out of range CxFileObjectConfig->FileObjectClass %d",
411 CxFileObjectConfig->FileObjectClass);
413 goto Done;
414 }
415
416 //
417 // The optional flag can only be combined with a subset of values.
418 //
420 switch(normalizedFileClass) {
424 break;
425
426 default:
429 "Invalid CxFileObjectConfig->FileObjectClass %d",
430 CxFileObjectConfig->FileObjectClass);
432 goto Done;
433 break; // just in case static verification tools complain.
434 }
435 }
436
438
442
447 }
448
449Done:
450 return;
451}
452
456WDFEXPORT(WdfCxDeviceInitAllocate)(
457 __in
459 __in
461 )
462{
463 DDI_ENTRY();
464
469
472 fxDriverGlobals = DeviceInit->DriverGlobals;
474
475 //
476 // Caller must be a class extension driver.
477 //
479 if (!NT_SUCCESS(status)) {
480 goto Done;
481 }
482
484 if (!NT_SUCCESS(status)) {
485 goto Done;
486 }
487
490 goto Done;
491 }
492
495
496Done:
497 return cxDeviceInit;
498}
499
500} // extern "C"
501
LONG NTSTATUS
Definition: precomp.h:26
#define ARRAY_SIZE(A)
Definition: main.h:33
#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:32
#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)
DriverGlobals
_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: ms_sal.h:558
#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 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(STDCALL * PFN_WDFCXDEVICE_WDM_IRP_PREPROCESS)(_In_ WDFDEVICE Device, _Inout_ PIRP Irp, _In_ PVOID DispatchContext)
Definition: wdfcx.h:63
_In_ PWDFDEVICE_INIT _In_ PWDF_FILEOBJECT_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES FileObjectAttributes
Definition: wdfdevice.h:3400
_In_ PWDFDEVICE_INIT _In_ PFN_WDF_IO_IN_CALLER_CONTEXT EvtIoInCallerContext
Definition: wdfdevice.h:3505
_In_ PWDFDEVICE_INIT _In_ PWDF_OBJECT_ATTRIBUTES RequestAttributes
Definition: wdfdevice.h:3431
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:3468
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ PFN_WDFDEVICE_WDM_IRP_PREPROCESS _In_ UCHAR _In_opt_ PUCHAR MinorFunctions
Definition: wdfdevice.h:3465
EVT_WDF_IO_IN_CALLER_CONTEXT * PFN_WDF_IO_IN_CALLER_CONTEXT
Definition: wdfdevice.h:1728
_In_ UCHAR MajorFunction
Definition: wdfdevice.h:1697
@ 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