ReactOS 0.4.16-dev-1946-g52006dd
fxqueryinterfaceapi.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxQueryInterfaceAPI.cpp
8
9Abstract:
10
11 This module implements the device interface object.
12
13Author:
14
15
16
17
18Environment:
19
20 Kernel mode only
21
22Revision History:
23
24--*/
25#include "fxsupportpch.hpp"
26
27extern "C" {
28// #include "FxQueryInterfaceAPI.tmh"
29#define RtlSizeTToULong RtlULongPtrToULong
30}
31
32//
33// Extern "C" the entire file
34//
35extern "C" {
40WDFEXPORT(WdfDeviceAddQueryInterface)(
41 __in
42 PWDF_DRIVER_GLOBALS DriverGlobals,
43 __in
44 WDFDEVICE Device,
45 __in
47 )
48{
54
56 Device,
58 (PVOID*) &pDevice,
60
62
66
69 return status;
70 }
71
72 pInterface = InterfaceConfig->Interface;
73
76
79 "WDFDEVICE %p, WDF_QUERY_INTERFACE_CONFIG Size %d, expected %d, "
80 "%!STATUS!", Device, InterfaceConfig->Size,
82
83 goto Done;
84 }
85
86 //
87 // A pass through interface is only associated with PDOs
88 //
89 if (InterfaceConfig->SendQueryToParentStack && pDevice->IsPdo() == FALSE) {
91
94 "SendQueryToParentStack TRUE, but WDFDEVICE %p not a PDO, %!STATUS!",
95 Device, status);
96
97 goto Done;
98 }
99
100 //
101 // The only time we can have a NULL Interface is if the interface is
102 // passthrough or it is an import interface (since on import interfaces
103 // the callback must do the copying).
104 //
105 if (pInterface == NULL) {
106 if (InterfaceConfig->SendQueryToParentStack || InterfaceConfig->ImportInterface) {
107 //
108 // A NULL interface is valid for this config
109 //
110 DO_NOTHING();
111 }
112 else {
114
117 "WDFDEVICE %p, SendQueryToParentStack is FALSE and "
118 "InterfaceConfig->ImportInterface is FALSE, %!STATUS!",
119 Device, status);
120
121 goto Done;
122 }
123 }
124
125 //
126 // If it is an import interface, we need a callback so that the driver can
127 // modify the interface being returned.
128 //
129 if (InterfaceConfig->ImportInterface &&
130 InterfaceConfig->EvtDeviceProcessQueryInterfaceRequest == NULL) {
132
135 "WDFDEVICE %p, ImportInterface is TRUE and "
136 "EvtDeviceProcessQueryInterfaceRequest is NULL, %!STATUS!",
137 Device, status);
138
139 goto Done;
140 }
141
142 if (pInterface != NULL) {
143 //
144 // Make sure we are exposing the minimum size
145 //
146 if (pInterface->Size < sizeof(INTERFACE)) {
148
151 "WDFDEVICE %p, Interface size %d < sizeof(INTERFACE) (%d), "
152 "%!STATUS!", Device, pInterface->Size, sizeof(INTERFACE), status);
153
154 goto Done;
155 }
156 }
157
158 //
159 // Since the QI irp is only allowed to be sent at passive level and
160 // the list of FxQueryInterface's is locked by a lock which does not
161 // raise IRQL, we can allocate the structure out paged pool.
162 //
165
168
171 "WDFDEVICE %p, object creation failed, %!STATUS!", Device, status);
172
173 goto Done;
174 }
175
176 if (pInterface != NULL) {
177 //
178 // Try to allocate memory for the interface.
179 //
181 FxPoolAllocate(pFxDriverGlobals, PagedPool, pInterface->Size);
182
185
188 "WDFDEVICE %p, interface allocation failed, %!STATUS!",
189 Device, status);
190
191 goto Done;
192 }
193
197
201 }
205 }
206 }
207
209
211
212Done:
213 //
214 // Delete the query interface structure if there is an error.
215 //
217 delete pQueryInterface;
219 }
220
221 return status;
222}
223
224} // extern "C"
LONG NTSTATUS
Definition: precomp.h:26
static VOID NTAPI _InterfaceReferenceNoOp(__in_opt PVOID Context)
Definition: fxdevice.hpp:1767
static VOID NTAPI _InterfaceDereferenceNoOp(__in_opt PVOID Context)
Definition: fxdevice.hpp:1778
FxPkgPnp * m_PkgPnp
Definition: fxdevice.hpp:670
__inline BOOLEAN IsPdo(VOID)
Definition: fxdevice.hpp:1245
VOID AddQueryInterface(__in FxQueryInterface *QI, __in BOOLEAN Lock)
Definition: fxpkgpnp.cpp:5017
#define __in
Definition: dbghelp.h:35
#define TRACINGERROR
Definition: dbgtrace.h:63
#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_maxIRQL(irql)
Definition: driverspecs.h:291
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define PagedPool
Definition: env_spec_w32.h:308
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
PFX_DRIVER_GLOBALS pFxDriverGlobals
__inline PFX_DRIVER_GLOBALS GetFxDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: fxglobals.h:597
#define WDFEXPORT(a)
Definition: fxmacros.hpp:157
#define FxPointerNotNull(FxDriverGlobals, Ptr)
Definition: fxmacros.hpp:253
FxQueryInterface * pQueryInterface
_Must_inspect_result_ __in WDFDEVICE __in PWDF_QUERY_INTERFACE_CONFIG InterfaceConfig
FxDevice * pDevice
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), Device, FX_TYPE_DEVICE,(PVOID *) &pDevice, &pFxDriverGlobals)
_Must_inspect_result_ __in WDFDEVICE Device
NTSTATUS status
PINTERFACE pInterface
@ FX_TYPE_DEVICE
Definition: fxtypes.h:47
__inline NTSTATUS FxVerifierCheckIrqlLevel(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in KIRQL Irql)
Definition: fxverifier.h:158
#define DO_NOTHING()
Definition: mxgeneral.h:32
#define _Must_inspect_result_
Definition: no_sal2.h:62
struct _INTERFACE * PINTERFACE
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
USHORT Size
Definition: miniport.h:121
PINTERFACE_REFERENCE InterfaceReference
Definition: miniport.h:124
PINTERFACE_DEREFERENCE InterfaceDereference
Definition: miniport.h:125
Definition: ps.c:97
#define NTAPI
Definition: typedefs.h:36
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_QUERY_INTERFACE_CONFIG InterfaceConfig