ReactOS  0.4.15-dev-3316-g067ca88
fxdeviceinit.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxDeviceInit.cpp
8 
9 Abstract:
10  Internals for WDFDEVICE_INIT
11 
12 Author:
13 
14 
15 
16 Environment:
17 
18  Both kernel and user mode
19 
20 Revision History:
21 
22 --*/
23 
24 #include "coreprivshared.hpp"
25 
26 extern "C" {
27 // #include "FxDeviceInit.tmh"
28 }
29 
32  ) :
33  Driver(Driver)
34 {
35  DriverGlobals = Driver->GetDriverGlobals();
36 
39  Inrush = FALSE;
42 
44  FileObject.AutoForwardCleanupClose = WdfUseDefault;
45 
46  DeviceName = NULL;
48 
50  Exclusive = FALSE;
51 
53 
55 
61 
63 
65 
66  RtlZeroMemory(&Fdo.EventCallbacks, sizeof(Fdo.EventCallbacks));
67  RtlZeroMemory(&Fdo.ListConfig, sizeof(Fdo.ListConfig));
68  RtlZeroMemory(&Fdo.ListConfigAttributes, sizeof(Fdo.ListConfigAttributes));
69  Fdo.Filter = FALSE;
70 
72  Pdo.Raw = FALSE;
73  Pdo.Static = FALSE;
74  Pdo.DeviceID = NULL;
77  Pdo.DefaultLocale = 0x0;
80 
81  RtlZeroMemory(&Security, sizeof(Security));
82 
84 
86 
88 
90 
92 
93 #if (FX_CORE_MODE == FX_CORE_USER_MODE)
94 
97 
98  DevStack = NULL;
99 
101 
102  PdoKey = NULL;
103 
105 
106  DriverID = 0;
107 #endif
108 }
109 
111 {
113 
116  }
117 
120  }
121 
124  }
125 
126  if (DeviceName != NULL) {
127  DeviceName->DeleteObject();
128  }
129  if (Pdo.DeviceID != NULL) {
131  }
132  if (Pdo.InstanceID != NULL) {
134  }
135  if (Pdo.ContainerID != NULL) {
137  }
138 
140 
141  if (Security.Sddl != NULL) {
143  }
144  if (PreprocessInfo != NULL) {
145  delete PreprocessInfo;
146  }
147 
150  PWDFCXDEVICE_INIT cxInit;
151  cxInit = CONTAINING_RECORD(next, WDFCXDEVICE_INIT, ListEntry);
153  delete cxInit;
154  }
155 
156 #if (FX_CORE_MODE == FX_CORE_USER_MODE)
157  delete [] KernelDeviceName;
158  delete [] ConfigRegistryPath;
159  delete [] DevInstanceID;
160 
161  if (PdoKey != NULL) {
163  PdoKey = NULL;
164  }
165 #endif
166 
167 }
168 
170 NTSTATUS
172  __in PFX_DRIVER_GLOBALS FxDriverGlobals,
173  __in const UNICODE_STRING* Name
174  )
175 {
176  if (DeviceName == NULL) {
177  DeviceName = new(FxDriverGlobals, WDF_NO_OBJECT_ATTRIBUTES)
178  FxString(FxDriverGlobals);
179 
180  if (DeviceName == NULL) {
182 
184 
186  "DeviceName is NULL, %!STATUS!", status);
187 
188  return status;
189  }
190 
191  //
192  // Clear out the autogenerate flag since we have a specific name
193  //
195  }
196 
197  return DeviceName->Assign(Name);
198 }
199 
205  )
206 {
210 
211  pFxDriverGlobals = Driver->GetDriverGlobals();
212 
214 
215  if (pInit == NULL) {
217  "WDFDRIVER 0x%p couldn't allocate WDFDEVICE_INIT",
218  Driver);
219  return NULL;
220  }
221 
223 
224  //
225  // Since we require and SDLL string, initialize to autogenerated device
226  // name so the driver doesn't have to worry about creating a name if they
227  // don't want it (useful if creating a DO for WMI tracing for instance).
228  //
230 
233 
234  if (pInit->Security.Sddl != NULL) {
236  }
237  else {
241  "WDFDRIVER 0x%p couldn't create Security String object %!STATUS!",
242  Driver, status);
243  }
244 
245  if (!NT_SUCCESS(status)) {
246  delete pInit;
247  pInit = NULL;
248  }
249 
250  return pInit;
251 }
252 
253 BOOLEAN
255  VOID
256  )
257 {
258  //
259  // Driver explicitly set a class or SDDL, we have to create a secure
260  // device. This will be true for all control devices (SDDL required)
261  // and raw PDOs (class required), could be true for FDOs or filters as
262  // well.
263  //
265  return TRUE;
266  }
267 
268  //
269  // See if there is a name for the device
270  //
271  if (HasName()) {
272  if (IsPdoInit()) {
273 
274 
275 
276 
277 
278 
279 
280 
281 
282 
283 
284 
285 
286  ASSERT(Pdo.Raw == FALSE);
287 
292  "WDFDRIVER 0x%p asked for a named device object, but the PDO "
293  "will be created without a name because an SDDL string has not "
294  "been specified for the PDO.",
295  Driver
296  );
297  return FALSE;
298  }
299  else {
300  //
301  // We are creating a named FDO or filter
302  //
303  ASSERT(IsFdoInit());
304  return TRUE;
305  }
306  }
307 
308  //
309  // No name involved (FDO or filter)
310  //
311  ASSERT(IsFdoInit());
312 
313  return FALSE;
314 }
315 
316 VOID
319  )
320 {
322 }
323 
virtual VOID DeleteObject(VOID)
SecurityInit Security
SINGLE_LIST_ENTRY DeviceText
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
BOOLEAN ShouldCreateSecure(VOID)
BOOLEAN DeviceClassSet
#define TRUE
Definition: types.h:120
LIST_ENTRY ListEntry
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
LONG NTSTATUS
Definition: precomp.h:26
_In_ PWDFDEVICE_INIT _In_ WDF_RELEASE_HARDWARE_ORDER_ON_FAILURE ReleaseHardwareOrderOnFailure
Definition: wdfdevice.h:4362
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FxPowerPolicyStateCallback * PowerPolicyStateCallbacks
BOOLEAN HasName(VOID)
FxDevice * CreatedDevice
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3272
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define FALSE
Definition: types.h:117
BOOLEAN RequiresSelfIoTarget
FxDeviceInitType InitType
_In_ PWDFDEVICE_INIT _In_ PWDF_OBJECT_ATTRIBUTES RequestAttributes
Definition: wdfdevice.h:3428
unsigned char BOOLEAN
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
DeviceType
Definition: mmdrv.h:41
#define FILE_AUTOGENERATED_DEVICE_NAME
Definition: iotypes.h:138
FxString * Sddl
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
FxIrpPreprocessInfo * PreprocessInfo
ULONG DirectTransferThreshold
#define TRACINGDEVICE
Definition: dbgtrace.h:58
PFX_DRIVER_GLOBALS pFxDriverGlobals
#define ASSERT(a)
Definition: mode.c:44
static _Must_inspect_result_ PWDFDEVICE_INIT _AllocateControlDeviceInit(__in FxDriver *Driver, __in const UNICODE_STRING *SDDLString)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_Must_inspect_result_ NTSTATUS Assign(__in PCWSTR SourceString)
Definition: fxstring.cpp:57
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461
PFX_DRIVER_GLOBALS DriverGlobals
WDF_POWER_POLICY_EVENT_CALLBACKS PolicyEventCallbacks
FxString * InstanceID
static void _CleanupList(__inout PSINGLE_LIST_ENTRY Head)
BOOLEAN CreatedOnStack
WDFDEVICE_INIT(__in FxDriver *Driver)
WDF_PNPPOWER_EVENT_CALLBACKS PnpPowerEventCallbacks
FxString * DeviceID
Definition: typedefs.h:119
#define _Must_inspect_result_
Definition: ms_sal.h:558
LIST_ENTRY CxDeviceInitListHead
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
#define TRACE_LEVEL_WARNING
Definition: storswtr.h:28
BOOLEAN IsFdoInit(VOID)
PWDFDEVICE_INIT pInit
FxDeviceDescriptionEntry * DescriptionEntry
static unsigned __int64 next
Definition: rand_nt.c:6
PFN_WDF_IO_IN_CALLER_CONTEXT IoInCallerContextCallback
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
PWSTR ConfigRegistryPath
WDF_PDO_EVENT_CALLBACKS EventCallbacks
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
PnpPowerInit PnpPower
#define NULL
Definition: types.h:112
#define FILE_DEVICE_UNKNOWN
Definition: winioctl.h:140
FxPowerStateCallback * PowerStateCallbacks
FxPnpStateCallback * PnpStateCallbacks
_Must_inspect_result_ _In_ WDFDRIVER _In_ CONST UNICODE_STRING * SDDLString
Definition: wdfcontrol.h:83
#define WDF_NO_OBJECT_ATTRIBUTES
Definition: wdftypes.h:105
WDF_TRI_STATE PowerPolicyOwner
WDF_DEVICE_IO_TYPE DeviceControlIoType
_Must_inspect_result_ _In_ PWDFCXDEVICE_INIT CxDeviceInit
Definition: fxdynamics.h:1012
BOOLEAN PowerPageable
VOID AddCxDeviceInit(__in PWDFCXDEVICE_INIT CxDeviceInit)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_Must_inspect_result_ NTSTATUS AssignName(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in const UNICODE_STRING *Name)
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
BOOLEAN ForwardRequestToParent
FxString * ContainerID
IWudfDeviceStack * DevStack
#define __in
Definition: dbghelp.h:35
_Must_inspect_result_ _In_ WDFDRIVER Driver
Definition: wdfcontrol.h:83
static SERVICE_STATUS status
Definition: service.c:31
ULONG RemoveLockOptionFlags
BOOLEAN IsPdoInit(VOID)
WDF_DEVICE_IO_TYPE ReadWriteIoType
Definition: ps.c:97