ReactOS  0.4.15-dev-2700-g4b4ffa9
fxdriver.hpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxDriver.hpp
8 
9 Abstract:
10 
11  This is the definition of the FxDriver object.
12 
13 Author:
14 
15 
16 
17 Environment:
18 
19  Both kernel and user mode
20 
21 Revision History:
22 
23 --*/
24 
25 #ifndef _FXDRIVER_H_
26 #define _FXDRIVER_H_
27 
28 #include "fxdrivercallbacks.hpp"
29 
30 
31 //
32 // Unique value to retrieve the FxDriver* from the PDEVICE_OBJECT.
33 //
34 #define FX_TRACE_INFO_ID (FxDriver::_GetTraceInfoExtension)
35 
36 //
37 // Structure to hold WMI Callback info
38 //
39 struct FxTraceInfo {
43 };
44 
45 //
46 // Unique value to retrieve the FxDriver* from the MdDriverObject. Use a value
47 // that is not exposed to the driver writer through the dispatch table or WDM.
48 //
49 #define FX_DRIVER_ID ((PVOID)FxDriver::GetFxDriver)
50 
51 //
52 // The following are support classes for FxDriver
53 //
55 {
56 friend class FxDevice;
57 friend class FxPackage;
58 friend class FxWmiIrpHandler;
59 
60 private:
61 
64 
66 
67  //
68  // Callbacks to device driver
69  //
71 
72  //
73  // This represents any constraints on callbacks
74  // to the device driver that may be inherited
75  // by child devices and their objects
76  //
79 
80  //
81  // Frameworks objects that raise event callbacks into the device
82  // driver provide spinlock and mutex based callback locks
83  // to allow proper synchronization between the driver and
84  // these callbacks.
85  //
86  // Some events must be passive level, while others at dispatch
87  // level, thus the need for two locks.
88  //
89  // The objects internal state is protected by the FxNonPagedObject
90  // lock inherited by the object, and is different from the callback
91  // locks.
92  //
94 
95  //
96  // These pointers allow the proper lock to be acquired
97  // based on the configuration with a minimal of runtime
98  // checks. This is configured by ConfigureConstraints()
99  //
102 
103  //
104  // This is the Driver-wide configuration
105  //
107 
108  //
109  // Deferred Disposal List
110  //
112 
113 #if FX_IS_USER_MODE
114  //
115  // A handle to the driver service parameters key.
116  // The framework does not have permission to open it with
117  // write access from user mode, so we keep a pre-opened one.
118  //
119  HKEY m_DriverParametersKey;
120 #endif
121 
122 private:
123 
124  static
126 
127 public:
128 
129  // This is public to allow the C function FxCoreDriverUnload to call it
131 
132  FxDriver(
135  __in PFX_DRIVER_GLOBALS FxDriverGlobals
136  );
137 
138  ~FxDriver();
139 
140  static
141  VOID
145  );
146 
147  static
148  VOID
152  );
153 
154  static
155  FxDriver*
156  GetFxDriver(
158  );
159 
161  NTSTATUS
163  VOID
164  );
165 
166 
167 
168 
169 
170 
171 
172 
173 
174 
175 
176 
177 
178 
179 
180 
181 
182 
183 
184 
185 
186 
187 
188 
189 
190 
191 
192 
193 
194 
195 
196 
197 
198 
199 
200  __inline
201  WDFDRIVER
203  VOID
204  )
205  {
206  return (WDFDRIVER) GetObjectHandle();
207  }
208 
209 #if (FX_CORE_MODE == FX_CORE_KERNEL_MODE)
210 
212  NTSTATUS
213  AddDevice(
215  );
216 
217 #else
218 
220  NTSTATUS
222  _In_ IWudfDeviceStack * DevStack,
223  _In_ LPCWSTR KernelDeviceName,
224  _In_opt_ HKEY PdoKey,
226  _In_ LPCWSTR DevInstanceID,
227  _In_ ULONG DriverID
228  );
229 #endif
230 
231  VOID
233  VOID
234  );
235 
237  FxString *
239  VOID
240  );
241 
244  VOID
245  )
246  {
247  return &m_RegistryPath;
248  }
249 
250  __inline
253  VOID
254  )
255  {
256  return m_DriverObject.GetObject();
257  }
258 
260  NTSTATUS
261  Initialize(
265  );
266 
267  //
268  // The following methods support the callback constraints
269  // and handle locking and deferral
270  //
271  VOID
274  );
275 
276  //
277  // IFxHasCallbacks Support
278  //
279 
280  virtual
281  VOID
283  __out WDF_EXECUTION_LEVEL* ExecutionLevel,
284  __out WDF_SYNCHRONIZATION_SCOPE* SynchronizationScope
285  ) {
286 
287  if (ExecutionLevel != NULL) {
288  *ExecutionLevel = m_ExecutionLevel;
289  }
290 
291  if (SynchronizationScope != NULL) {
292  *SynchronizationScope = m_SynchronizationScope;
293  }
294  }
295 
296  virtual
300  ) {
301 
302  if (LockObject != NULL) {
304  }
305 
306  return m_CallbackLockPtr;
307  }
308 
309  //
310  // IFxAssociation Support
311  //
312  virtual
313  NTSTATUS
316  )
317  {
318  switch (Params->Type) {
319  case FX_TYPE_DRIVER:
320  *Params->Object = (FxDriver*) this;
321  break;
322 
323  default:
324  return FxNonPagedObject::QueryInterface(Params); // __super call
325  }
326 
327  return STATUS_SUCCESS;
328  }
329 
330  virtual
331  VOID
333  VOID
334  )
335  {
336  //
337  // If diposed at > PASSIVE, we will cause a deadlock in FxDriver::Dispose
338  // when we call into the dispose list to wait for empty when we are in
339  // the context of the dispose list's work item.
340  //
342 
343  FxNonPagedObject::DeleteObject(); // __super call
344  }
345 
346  virtual
347  BOOLEAN
348  Dispose(
349  VOID
350  );
351 
352  __inline
355  )
356  {
357  return m_DisposeList;
358  }
359 
360  __inline
363  )
364  {
365  return m_DriverDeviceAdd.Method;
366  }
367 
368  static
370 
371 #if FX_IS_USER_MODE
372 private:
373 
374  //
375  // Open the handle to the driver service parameters key
376  // that we keep opened for use from user mode.
377  //
378  NTSTATUS
379  OpenParametersKey(
380  VOID
381  );
382 
383  VOID
384  ClearDriverObjectFxDriver(
385  VOID
386  );
387 
388 public:
389 
390  __inline
391  HKEY
392  GetDriverParametersKey(
393  VOID
394  )
395  {
396  return m_DriverParametersKey;
397  }
398 #endif
399 
400 #if (FX_CORE_MODE == FX_CORE_USER_MODE)
401 
402  VOID
405  )
406  {
408  }
409 
410  BOOLEAN
413  )
414  {
416  }
417 
418 #endif
419 
420 };
421 
422 #endif // _FXDRIVER_H_
VOID SetDriverObjectFlag(_In_ FxDriverObjectUmFlags Flag)
DRIVER_ADD_DEVICE MdDriverAddDeviceType
virtual VOID DeleteObject(VOID)
_Must_inspect_result_ FxString * GetRegistryPath(VOID)
Definition: fxdriver.cpp:539
static MdDriverUnloadType Unload
Definition: fxdriver.hpp:369
FxDriverObjectUmFlags
Definition: fxldrum.h:125
PFN_WDF_DRIVER_DEVICE_ADD Method
#define _Must_inspect_result_
Definition: no_sal2.h:62
VOID ConfigureConstraints(__in_opt PWDF_OBJECT_ATTRIBUTES DriverAttributes)
Definition: fxdriver.cpp:564
FxCallbackMutexLock m_CallbackMutexLock
Definition: fxdriver.hpp:93
_In_ WDFIOTARGET _In_ PWDF_REQUEST_COMPLETION_PARAMS Params
Definition: wdfrequest.h:306
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define __in_opt
Definition: dbghelp.h:38
FxDisposeList * m_DisposeList
Definition: fxdriver.hpp:111
EVT_WDF_DRIVER_DEVICE_ADD * PFN_WDF_DRIVER_DEVICE_ADD
Definition: wdfdriver.h:78
_Must_inspect_result_ NTSTATUS Initialize(__in PCUNICODE_STRING RegistryPath, __in PWDF_DRIVER_CONFIG Config, __in_opt PWDF_OBJECT_ATTRIBUTES DriverAttributes)
Definition: fxdriver.cpp:334
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:213
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1155
VOID SetDriverObjectFlag(_In_ FxDriverObjectUmFlags Flag)
Definition: fxdriver.hpp:403
#define _In_opt_
Definition: no_sal2.h:212
#define LockObject(Object, Irql)
Definition: titypes.h:34
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
virtual NTSTATUS QueryInterface(__inout FxQueryInterfaceParams *Params)
Definition: fxdriver.hpp:314
FxObject * m_CallbackLockObjectPtr
Definition: fxdriver.hpp:101
PVOID __inline GetObjectHandle(VOID)
Definition: fxobject.hpp:603
#define __out
Definition: dbghelp.h:62
unsigned char BOOLEAN
static FxDriver * GetFxDriver(__in MdDriverObject DriverObject)
Definition: fxdriverkm.cpp:158
static VOID _InitializeTag(__in PFX_DRIVER_GLOBALS Globals, __in PWDF_DRIVER_CONFIG Config)
Definition: fxdriver.cpp:266
_Must_inspect_result_ NTSTATUS AllocateDriverObjectExtensionAndStoreFxDriver(VOID)
Definition: fxdriverkm.cpp:129
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
PUNICODE_STRING GetRegistryPathUnicodeString(VOID)
Definition: fxdriver.hpp:243
enum _WDF_SYNCHRONIZATION_SCOPE WDF_SYNCHRONIZATION_SCOPE
__inline WDFDRIVER GetHandle(VOID)
Definition: fxdriver.hpp:202
FxCallbackLock * m_CallbackLockPtr
Definition: fxdriver.hpp:100
PVOID Context
Definition: fxdriver.hpp:42
LPTSTR ServiceName
Definition: ServiceMain.c:15
#define ASSERT(a)
Definition: mode.c:44
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING _In_opt_ PWDF_OBJECT_ATTRIBUTES DriverAttributes
Definition: wdfdriver.h:213
Definition: xml2sdb.h:79
virtual VOID DeleteObject(VOID)
Definition: fxdriver.hpp:332
static __inline KIRQL MxGetCurrentIrql()
Definition: mxgeneralkm.h:86
WDF_DRIVER_CONFIG m_Config
Definition: fxdriver.hpp:106
static MdDriverAddDeviceType AddDevice
Definition: fxdriver.hpp:125
BOOLEAN IsDriverObjectFlagSet(_In_ FxDriverObjectUmFlags Flag)
MdDriverObject DriverObject
Definition: fxdriver.hpp:40
#define __inout
Definition: dbghelp.h:50
WDF_EXECUTION_LEVEL m_ExecutionLevel
Definition: fxdriver.hpp:77
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_CHILD_LIST_CONFIG Config
Definition: wdfchildlist.h:474
__inline FxDisposeList * GetDisposeList()
Definition: fxdriver.hpp:354
__inline MdDriverObject GetObject(VOID)
VOID InitializeInternal(VOID)
#define _In_
Definition: no_sal2.h:158
PFN_WDF_TRACE_CALLBACK Callback
Definition: fxdriver.hpp:41
__inline MdDriverObject GetDriverObject(VOID)
Definition: fxdriver.hpp:252
FxDriverUnload m_DriverUnload
Definition: fxdriver.hpp:130
WDF_SYNCHRONIZATION_SCOPE m_SynchronizationScope
Definition: fxdriver.hpp:78
UNICODE_STRING m_RegistryPath
Definition: fxdriver.hpp:63
virtual VOID GetConstraints(__out WDF_EXECUTION_LEVEL *ExecutionLevel, __out WDF_SYNCHRONIZATION_SCOPE *SynchronizationScope)
Definition: fxdriver.hpp:282
#define NULL
Definition: types.h:112
BOOLEAN IsDriverObjectFlagSet(_In_ FxDriverObjectUmFlags Flag)
Definition: fxdriver.hpp:411
EVT_WDF_TRACE_CALLBACK * PFN_WDF_TRACE_CALLBACK
Definition: wdfdriver.h:118
~FxDriver()
Definition: fxdriver.cpp:78
virtual FxCallbackLock * GetCallbackLockPtr(__deref_out FxObject **LockObject)
Definition: fxdriver.hpp:298
#define __deref_out
Definition: dbghelp.h:26
unsigned int ULONG
Definition: retypes.h:1
BOOLEAN m_DebuggerConnected
Definition: fxdriver.hpp:65
WDF_EXTERN_C_START enum _WDF_EXECUTION_LEVEL WDF_EXECUTION_LEVEL
virtual _Must_inspect_result_ NTSTATUS QueryInterface(__in FxQueryInterfaceParams *Params)
Definition: fxobject.cpp:255
#define STATUS_SUCCESS
Definition: shellext.h:65
FxDriver(__in MdDriverObject DriverObject, __in PWDF_DRIVER_CONFIG DriverConfig, __in PFX_DRIVER_GLOBALS FxDriverGlobals)
Definition: fxdriver.cpp:33
static VOID _InitializeDriverName(__in PFX_DRIVER_GLOBALS Globals, __in PCUNICODE_STRING RegistryPath)
Definition: fxdriver.cpp:180
#define __in
Definition: dbghelp.h:35
__inline PFN_WDF_DRIVER_DEVICE_ADD GetDriverDeviceAddMethod()
Definition: fxdriver.hpp:362
virtual BOOLEAN Dispose(VOID)
Definition: fxdriver.cpp:128
MxDriverObject m_DriverObject
Definition: fxdriver.hpp:62
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ PWDF_DRIVER_CONFIG DriverConfig
Definition: wdfdriver.h:213
FxDriverDeviceAdd m_DriverDeviceAdd
Definition: fxdriver.hpp:70
DRIVER_UNLOAD MdDriverUnloadType