ReactOS  0.4.15-dev-3745-g356babc
fxqueryinterfaceapi.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxQueryInterfaceAPI.cpp
8 
9 Abstract:
10 
11  This module implements the device interface object.
12 
13 Author:
14 
15 
16 
17 
18 Environment:
19 
20  Kernel mode only
21 
22 Revision History:
23 
24 --*/
25 #include "fxsupportpch.hpp"
26 
27 extern "C" {
28 // #include "FxQueryInterfaceAPI.tmh"
29 }
30 
31 //
32 // Extern "C" the entire file
33 //
34 extern "C" {
38 STDCALL
39 WDFEXPORT(WdfDeviceAddQueryInterface)(
40  __in
42  __in
43  WDFDEVICE Device,
44  __in
46  )
47 {
53 
55  Device,
57  (PVOID*) &pDevice,
59 
61 
65 
67  if (!NT_SUCCESS(status)) {
68  return status;
69  }
70 
71  pInterface = InterfaceConfig->Interface;
72 
75 
78  "WDFDEVICE %p, WDF_QUERY_INTERFACE_CONFIG Size %d, expected %d, "
79  "%!STATUS!", Device, InterfaceConfig->Size,
81 
82  goto Done;
83  }
84 
85  //
86  // A pass through interface is only associated with PDOs
87  //
88  if (InterfaceConfig->SendQueryToParentStack && pDevice->IsPdo() == FALSE) {
90 
93  "SendQueryToParentStack TRUE, but WDFDEVICE %p not a PDO, %!STATUS!",
94  Device, status);
95 
96  goto Done;
97  }
98 
99  //
100  // The only time we can have a NULL Interface is if the interface is
101  // passthrough or it is an import interface (since on import interfaces
102  // the callback must do the copying).
103  //
104  if (pInterface == NULL) {
105  if (InterfaceConfig->SendQueryToParentStack || InterfaceConfig->ImportInterface) {
106  //
107  // A NULL interface is valid for this config
108  //
109  DO_NOTHING();
110  }
111  else {
113 
116  "WDFDEVICE %p, SendQueryToParentStack is FALSE and "
117  "InterfaceConfig->ImportInterface is FALSE, %!STATUS!",
118  Device, status);
119 
120  goto Done;
121  }
122  }
123 
124  //
125  // If it is an import interface, we need a callback so that the driver can
126  // modify the interface being returned.
127  //
128  if (InterfaceConfig->ImportInterface &&
129  InterfaceConfig->EvtDeviceProcessQueryInterfaceRequest == NULL) {
131 
134  "WDFDEVICE %p, ImportInterface is TRUE and "
135  "EvtDeviceProcessQueryInterfaceRequest is NULL, %!STATUS!",
136  Device, status);
137 
138  goto Done;
139  }
140 
141  if (pInterface != NULL) {
142  //
143  // Make sure we are exposing the minimum size
144  //
145  if (pInterface->Size < sizeof(INTERFACE)) {
147 
150  "WDFDEVICE %p, Interface size %d < sizeof(INTERFACE) (%d), "
151  "%!STATUS!", Device, pInterface->Size, sizeof(INTERFACE), status);
152 
153  goto Done;
154  }
155  }
156 
157  //
158  // Since the QI irp is only allowed to be sent at passive level and
159  // the list of FxQueryInterface's is locked by a lock which does not
160  // raise IRQL, we can allocate the structure out paged pool.
161  //
164 
167 
170  "WDFDEVICE %p, object creation failed, %!STATUS!", Device, status);
171 
172  goto Done;
173  }
174 
175  if (pInterface != NULL) {
176  //
177  // Try to allocate memory for the interface.
178  //
180  FxPoolAllocate(pFxDriverGlobals, PagedPool, pInterface->Size);
181 
182  if (pQueryInterface->m_Interface == NULL) {
184 
187  "WDFDEVICE %p, interface allocation failed, %!STATUS!",
188  Device, status);
189 
190  goto Done;
191  }
192 
194  pInterface,
195  pInterface->Size);
196 
200  }
204  }
205  }
206 
208 
210 
211 Done:
212  //
213  // Delete the query interface structure if there is an error.
214  //
215  if (!NT_SUCCESS(status) && pQueryInterface != NULL) {
218  }
219 
220  return status;
221 }
222 
223 } // extern "C"
PINTERFACE_REFERENCE InterfaceReference
Definition: miniport.h:124
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
#define TRUE
Definition: types.h:120
USHORT Size
Definition: miniport.h:121
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_QUERY_INTERFACE_CONFIG InterfaceConfig
DriverGlobals
PINTERFACE pInterface
#define FALSE
Definition: types.h:117
#define WDFEXPORT(a)
Definition: fxmacros.hpp:157
static VOID STDCALL _InterfaceReferenceNoOp(__in_opt PVOID Context)
Definition: fxdevice.hpp:1767
struct _INTERFACE * PINTERFACE
_Must_inspect_result_ __in WDFDEVICE __in PWDF_QUERY_INTERFACE_CONFIG InterfaceConfig
_Must_inspect_result_ __in WDFDEVICE Device
__inline NTSTATUS FxVerifierCheckIrqlLevel(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in KIRQL Irql)
Definition: fxverifier.h:158
PFX_DRIVER_GLOBALS pFxDriverGlobals
#define STDCALL
Definition: wdf.h:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
FxDevice * pDevice
FxPointerNotNull(pFxDriverGlobals, Device)
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), Device, FX_TYPE_DEVICE,(PVOID *) &pDevice, &pFxDriverGlobals)
#define _Must_inspect_result_
Definition: ms_sal.h:558
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
FxPkgPnp * m_PkgPnp
Definition: fxdevice.hpp:670
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
NTSTATUS status
PINTERFACE_DEREFERENCE InterfaceDereference
Definition: miniport.h:125
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
static VOID STDCALL _InterfaceDereferenceNoOp(__in_opt PVOID Context)
Definition: fxdevice.hpp:1778
VOID AddQueryInterface(__in FxQueryInterface *QI, __in BOOLEAN Lock)
Definition: fxpkgpnp.cpp:5017
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
__inline BOOLEAN IsPdo(VOID)
Definition: fxdevice.hpp:1245
#define STATUS_SUCCESS
Definition: shellext.h:65
__inline PFX_DRIVER_GLOBALS GetFxDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: fxglobals.h:597
#define TRACINGERROR
Definition: dbgtrace.h:63
#define __in
Definition: dbghelp.h:35
_Must_inspect_result_ __drv_maxIRQL(PASSIVE_LEVEL) NTSTATUS STDCALL WDFEXPORT(WdfDeviceAddQueryInterface)(__in PWDF_DRIVER_GLOBALS DriverGlobals
FxQueryInterface * pQueryInterface
#define DO_NOTHING()
Definition: mxgeneral.h:32
Definition: ps.c:97