ReactOS  0.4.14-dev-606-g14ebc0b
pnpmgr.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for pnpmgr.c:

Go to the source code of this file.

Classes

struct  _DEVICE_ACTION_DATA
 

Macros

#define NDEBUG
 
#define MAX_DEVICE_ID_LEN   200
 
#define MAX_SEPARATORS_INSTANCEID   0
 
#define MAX_SEPARATORS_DEVICEID   1
 
#define PIP_RETURN_DATA(x, y)   {ReturnLength = x; Data = y; Status = STATUS_SUCCESS; break;}
 
#define PIP_REGISTRY_DATA(x, y)   {ValueName = x; ValueType = y; break;}
 
#define PIP_UNIMPLEMENTED()   {UNIMPLEMENTED_DBGBREAK(); break;}
 

Typedefs

typedef struct _DEVICE_ACTION_DATA DEVICE_ACTION_DATA
 
typedef struct _DEVICE_ACTION_DATAPDEVICE_ACTION_DATA
 

Functions

NTSTATUS NTAPI IopCreateDeviceKeyPath (IN PCUNICODE_STRING RegistryPath, IN ULONG CreateOptions, OUT PHANDLE Handle)
 
NTSTATUS IopPrepareDeviceForRemoval (PDEVICE_OBJECT DeviceObject, BOOLEAN Force)
 
PDEVICE_OBJECT IopGetDeviceObjectFromDeviceInstance (PUNICODE_STRING DeviceInstance)
 
PDEVICE_NODE FASTCALL IopGetDeviceNode (PDEVICE_OBJECT DeviceObject)
 
VOID IopFixupDeviceId (PWCHAR String)
 
VOID NTAPI IopInstallCriticalDevice (PDEVICE_NODE DeviceNode)
 
NTSTATUS FASTCALL IopInitializeDevice (PDEVICE_NODE DeviceNode, PDRIVER_OBJECT DriverObject)
 
static NTSTATUS NTAPI IopSendEject (IN PDEVICE_OBJECT DeviceObject)
 
static VOID NTAPI IopSendSurpriseRemoval (IN PDEVICE_OBJECT DeviceObject)
 
static NTSTATUS NTAPI IopQueryRemoveDevice (IN PDEVICE_OBJECT DeviceObject)
 
static NTSTATUS NTAPI IopQueryStopDevice (IN PDEVICE_OBJECT DeviceObject)
 
static VOID NTAPI IopSendRemoveDevice (IN PDEVICE_OBJECT DeviceObject)
 
static VOID NTAPI IopCancelRemoveDevice (IN PDEVICE_OBJECT DeviceObject)
 
static VOID NTAPI IopSendStopDevice (IN PDEVICE_OBJECT DeviceObject)
 
static NTSTATUS IopSetServiceEnumData (PDEVICE_NODE DeviceNode)
 
VOID NTAPI IopStartDevice2 (IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS NTAPI IopStartAndEnumerateDevice (IN PDEVICE_NODE DeviceNode)
 
NTSTATUS IopStopDevice (PDEVICE_NODE DeviceNode)
 
NTSTATUS IopStartDevice (PDEVICE_NODE DeviceNode)
 
NTSTATUS NTAPI IopQueryDeviceCapabilities (PDEVICE_NODE DeviceNode, PDEVICE_CAPABILITIES DeviceCaps)
 
static VOID NTAPI IopDeviceActionWorker (_In_ PVOID Context)
 
NTSTATUS IopGetSystemPowerDeviceObject (PDEVICE_OBJECT *DeviceObject)
 
USHORT NTAPI IopGetBusTypeGuidIndex (LPGUID BusTypeGuid)
 
NTSTATUS IopCreateDeviceNode (PDEVICE_NODE ParentNode, PDEVICE_OBJECT PhysicalDeviceObject, PUNICODE_STRING ServiceName, PDEVICE_NODE *DeviceNode)
 
NTSTATUS IopFreeDeviceNode (PDEVICE_NODE DeviceNode)
 
NTSTATUS NTAPI IopSynchronousCall (IN PDEVICE_OBJECT DeviceObject, IN PIO_STACK_LOCATION IoStackLocation, OUT PVOID *Information)
 
NTSTATUS NTAPI IopInitiatePnpIrp (IN PDEVICE_OBJECT DeviceObject, IN OUT PIO_STATUS_BLOCK IoStatusBlock, IN UCHAR MinorFunction, IN PIO_STACK_LOCATION Stack OPTIONAL)
 
NTSTATUS IopTraverseDeviceTreeNode (PDEVICETREE_TRAVERSE_CONTEXT Context)
 
NTSTATUS IopTraverseDeviceTree (PDEVICETREE_TRAVERSE_CONTEXT Context)
 
NTSTATUS IopSetDeviceInstanceData (HANDLE InstanceKey, PDEVICE_NODE DeviceNode)
 
NTSTATUS IopGetParentIdPrefix (PDEVICE_NODE DeviceNode, PUNICODE_STRING ParentIdPrefix)
 
static BOOLEAN IopValidateID (_In_ PWCHAR Id, _In_ BUS_QUERY_ID_TYPE QueryType)
 
NTSTATUS IopQueryHardwareIds (PDEVICE_NODE DeviceNode, HANDLE InstanceKey)
 
NTSTATUS IopQueryCompatibleIds (PDEVICE_NODE DeviceNode, HANDLE InstanceKey)
 
NTSTATUS IopCreateDeviceInstancePath (_In_ PDEVICE_NODE DeviceNode, _Out_ PUNICODE_STRING InstancePath)
 
NTSTATUS IopActionInterrogateDeviceStack (PDEVICE_NODE DeviceNode, PVOID Context)
 
static VOID IopHandleDeviceRemoval (IN PDEVICE_NODE DeviceNode, IN PDEVICE_RELATIONS DeviceRelations)
 
NTSTATUS IopEnumerateDevice (IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS IopActionConfigureChildServices (PDEVICE_NODE DeviceNode, PVOID Context)
 
NTSTATUS IopActionInitChildServices (PDEVICE_NODE DeviceNode, PVOID Context)
 
NTSTATUS IopInitializePnpServices (IN PDEVICE_NODE DeviceNode)
 
static INIT_FUNCTION NTSTATUS IopEnumerateDetectedDevices (IN HANDLE hBaseKey, IN PUNICODE_STRING RelativePath OPTIONAL, IN HANDLE hRootKey, IN BOOLEAN EnumerateSubKeys, IN PCM_FULL_RESOURCE_DESCRIPTOR ParentBootResources, IN ULONG ParentBootResourcesLength)
 
static INIT_FUNCTION BOOLEAN IopIsFirmwareMapperDisabled (VOID)
 
INIT_FUNCTION NTSTATUS NTAPI IopUpdateRootKey (VOID)
 
NTSTATUS NTAPI IopOpenRegistryKeyEx (PHANDLE KeyHandle, HANDLE ParentKey, PUNICODE_STRING Name, ACCESS_MASK DesiredAccess)
 
NTSTATUS NTAPI IopCreateRegistryKeyEx (OUT PHANDLE Handle, IN HANDLE RootHandle OPTIONAL, IN PUNICODE_STRING KeyName, IN ACCESS_MASK DesiredAccess, IN ULONG CreateOptions, OUT PULONG Disposition OPTIONAL)
 
NTSTATUS NTAPI IopGetRegistryValue (IN HANDLE Handle, IN PWSTR ValueName, OUT PKEY_VALUE_FULL_INFORMATION *Information)
 
RTL_GENERIC_COMPARE_RESULTS NTAPI PiCompareInstancePath (IN PRTL_AVL_TABLE Table, IN PVOID FirstStruct, IN PVOID SecondStruct)
 
PVOID NTAPI PiAllocateGenericTableEntry (IN PRTL_AVL_TABLE Table, IN CLONG ByteSize)
 
VOID NTAPI PiFreeGenericTableEntry (IN PRTL_AVL_TABLE Table, IN PVOID Buffer)
 
VOID NTAPI PpInitializeDeviceReferenceTable (VOID)
 
BOOLEAN NTAPI PiInitPhase0 (VOID)
 
BOOLEAN NTAPI PpInitSystem (VOID)
 
PDEVICE_NODE NTAPI PipAllocateDeviceNode (IN PDEVICE_OBJECT PhysicalDeviceObject)
 
NTSTATUS NTAPI PnpBusTypeGuidGet (IN USHORT Index, IN LPGUID BusTypeGuid)
 
NTSTATUS NTAPI PnpDeviceObjectToDeviceInstance (IN PDEVICE_OBJECT DeviceObject, IN PHANDLE DeviceInstanceHandle, IN ACCESS_MASK DesiredAccess)
 
ULONG NTAPI PnpDetermineResourceListSize (IN PCM_RESOURCE_LIST ResourceList)
 
NTSTATUS NTAPI PiGetDeviceRegistryProperty (IN PDEVICE_OBJECT DeviceObject, IN ULONG ValueType, IN PWSTR ValueName, IN PWSTR KeyName, OUT PVOID Buffer, IN PULONG BufferLength)
 
NTSTATUS NTAPI IoGetDeviceProperty (IN PDEVICE_OBJECT DeviceObject, IN DEVICE_REGISTRY_PROPERTY DeviceProperty, IN ULONG BufferLength, OUT PVOID PropertyBuffer, OUT PULONG ResultLength)
 
VOID NTAPI IoInvalidateDeviceState (IN PDEVICE_OBJECT PhysicalDeviceObject)
 
IoOpenDeviceRegistryKey

Open a registry key unique for a specified driver or device instance.

Parameters
DeviceObjectDevice to get the registry key for.
DevInstKeyTypeType of the key to return.
DesiredAccessAccess mask (eg. KEY_READ | KEY_WRITE).
DevInstRegKeyHandle to the opened registry key on successful return.
Returns
Status.

@implemented

VOID IopCancelPrepareDeviceForRemoval (PDEVICE_OBJECT DeviceObject)
 
NTSTATUS NTAPI IoOpenDeviceRegistryKey (IN PDEVICE_OBJECT DeviceObject, IN ULONG DevInstKeyType, IN ACCESS_MASK DesiredAccess, OUT PHANDLE DevInstRegKey)
 
static NTSTATUS IopQueryRemoveChildDevices (PDEVICE_NODE ParentDeviceNode, BOOLEAN Force)
 
static VOID IopSendRemoveChildDevices (PDEVICE_NODE ParentDeviceNode)
 
static VOID IopCancelRemoveChildDevices (PDEVICE_NODE ParentDeviceNode)
 
static NTSTATUS IopQueryRemoveDeviceRelations (PDEVICE_RELATIONS DeviceRelations, BOOLEAN Force)
 
static VOID IopSendRemoveDeviceRelations (PDEVICE_RELATIONS DeviceRelations)
 
static VOID IopCancelRemoveDeviceRelations (PDEVICE_RELATIONS DeviceRelations)
 
NTSTATUS IopPrepareDeviceForRemoval (IN PDEVICE_OBJECT DeviceObject, BOOLEAN Force)
 
NTSTATUS IopRemoveDevice (PDEVICE_NODE DeviceNode)
 
VOID NTAPI IoRequestDeviceEject (IN PDEVICE_OBJECT PhysicalDeviceObject)
 
VOID NTAPI IoInvalidateDeviceRelations (IN PDEVICE_OBJECT DeviceObject, IN DEVICE_RELATION_TYPE Type)
 
NTSTATUS NTAPI IoSynchronousInvalidateDeviceRelations (IN PDEVICE_OBJECT DeviceObject, IN DEVICE_RELATION_TYPE Type)
 
BOOLEAN NTAPI IoTranslateBusAddress (IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber, IN PHYSICAL_ADDRESS BusAddress, IN OUT PULONG AddressSpace, OUT PPHYSICAL_ADDRESS TranslatedAddress)
 

Variables

PDEVICE_NODE IopRootDeviceNode
 
KSPIN_LOCK IopDeviceTreeLock
 
ERESOURCE PpRegistryDeviceResource
 
KGUARDED_MUTEX PpDeviceReferenceTableLock
 
RTL_AVL_TABLE PpDeviceReferenceTable
 
ERESOURCE IopDriverLoadResource
 
ULONG ExpInitializationPhase
 
BOOLEAN PnpSystemInit
 
PDRIVER_OBJECT IopRootDriverObject
 
PIO_BUS_TYPE_GUID_LIST PnpBusTypeGuidList = NULL
 
LIST_ENTRY IopDeviceActionRequestList
 
WORK_QUEUE_ITEM IopDeviceActionWorkItem
 
BOOLEAN IopDeviceActionInProgress
 
KSPIN_LOCK IopDeviceActionLock
 
LONG IopNumberDeviceNodes
 

Macro Definition Documentation

◆ MAX_DEVICE_ID_LEN

#define MAX_DEVICE_ID_LEN   200

Definition at line 28 of file pnpmgr.c.

◆ MAX_SEPARATORS_DEVICEID

#define MAX_SEPARATORS_DEVICEID   1

Definition at line 30 of file pnpmgr.c.

◆ MAX_SEPARATORS_INSTANCEID

#define MAX_SEPARATORS_INSTANCEID   0

Definition at line 29 of file pnpmgr.c.

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file pnpmgr.c.

◆ PIP_REGISTRY_DATA

#define PIP_REGISTRY_DATA (   x,
  y 
)    {ValueName = x; ValueType = y; break;}

Definition at line 4220 of file pnpmgr.c.

◆ PIP_RETURN_DATA

#define PIP_RETURN_DATA (   x,
  y 
)    {ReturnLength = x; Data = y; Status = STATUS_SUCCESS; break;}

Definition at line 4219 of file pnpmgr.c.

◆ PIP_UNIMPLEMENTED

#define PIP_UNIMPLEMENTED ( )    {UNIMPLEMENTED_DBGBREAK(); break;}

Definition at line 4221 of file pnpmgr.c.

Typedef Documentation

◆ DEVICE_ACTION_DATA

◆ PDEVICE_ACTION_DATA

Function Documentation

◆ IoGetDeviceProperty()

NTSTATUS NTAPI IoGetDeviceProperty ( IN PDEVICE_OBJECT  DeviceObject,
IN DEVICE_REGISTRY_PROPERTY  DeviceProperty,
IN ULONG  BufferLength,
OUT PVOID  PropertyBuffer,
OUT PULONG  ResultLength 
)

Definition at line 4228 of file pnpmgr.c.

4233 {
4235  DEVICE_CAPABILITIES DeviceCaps;
4236  ULONG ReturnLength = 0, Length = 0, ValueType;
4237  PWCHAR ValueName = NULL, EnumeratorNameEnd, DeviceInstanceName;
4238  PVOID Data = NULL;
4240  GUID BusTypeGuid;
4241  POBJECT_NAME_INFORMATION ObjectNameInfo = NULL;
4242  BOOLEAN NullTerminate = FALSE;
4243  DEVICE_REMOVAL_POLICY Policy;
4244 
4245  DPRINT("IoGetDeviceProperty(0x%p %d)\n", DeviceObject, DeviceProperty);
4246 
4247  /* Assume failure */
4248  *ResultLength = 0;
4249 
4250  /* Only PDOs can call this */
4252 
4253  /* Handle all properties */
4254  switch (DeviceProperty)
4255  {
4257 
4258  /* Get the GUID from the internal cache */
4259  Status = PnpBusTypeGuidGet(DeviceNode->ChildBusTypeIndex, &BusTypeGuid);
4260  if (!NT_SUCCESS(Status)) return Status;
4261 
4262  /* This is the format of the returned data */
4263  PIP_RETURN_DATA(sizeof(GUID), &BusTypeGuid);
4264 
4266 
4267  /* Validate correct interface type */
4268  if (DeviceNode->ChildInterfaceType == InterfaceTypeUndefined)
4270 
4271  /* This is the format of the returned data */
4272  PIP_RETURN_DATA(sizeof(INTERFACE_TYPE), &DeviceNode->ChildInterfaceType);
4273 
4275 
4276  /* Validate correct bus number */
4277  if ((DeviceNode->ChildBusNumber & 0x80000000) == 0x80000000)
4279 
4280  /* This is the format of the returned data */
4281  PIP_RETURN_DATA(sizeof(ULONG), &DeviceNode->ChildBusNumber);
4282 
4284 
4285  /* Get the instance path */
4286  DeviceInstanceName = DeviceNode->InstancePath.Buffer;
4287 
4288  /* Sanity checks */
4289  ASSERT((BufferLength & 1) == 0);
4290  ASSERT(DeviceInstanceName != NULL);
4291 
4292  /* Get the name from the path */
4293  EnumeratorNameEnd = wcschr(DeviceInstanceName, OBJ_NAME_PATH_SEPARATOR);
4294  ASSERT(EnumeratorNameEnd);
4295 
4296  /* This string needs to be NULL-terminated */
4297  NullTerminate = TRUE;
4298 
4299  /* This is the format of the returned data */
4300  PIP_RETURN_DATA((ULONG)(EnumeratorNameEnd - DeviceInstanceName) * sizeof(WCHAR),
4301  DeviceInstanceName);
4302 
4303  case DevicePropertyAddress:
4304 
4305  /* Query the device caps */
4307  if (!NT_SUCCESS(Status) || (DeviceCaps.Address == MAXULONG))
4309 
4310  /* This is the format of the returned data */
4311  PIP_RETURN_DATA(sizeof(ULONG), &DeviceCaps.Address);
4312 
4314 
4315  /* Validate we have resources */
4316  if (!DeviceNode->BootResources)
4317 // if (!DeviceNode->BootResourcesTranslated) // FIXFIX: Need this field
4318  {
4319  /* No resources will still fake success, but with 0 bytes */
4320  *ResultLength = 0;
4321  return STATUS_SUCCESS;
4322  }
4323 
4324  /* This is the format of the returned data */
4325  PIP_RETURN_DATA(PnpDetermineResourceListSize(DeviceNode->BootResources), // FIXFIX: Should use BootResourcesTranslated
4326  DeviceNode->BootResources); // FIXFIX: Should use BootResourcesTranslated
4327 
4329 
4330  /* Sanity check for Unicode-sized string */
4331  ASSERT((BufferLength & 1) == 0);
4332 
4333  /* Allocate name buffer */
4335  ObjectNameInfo = ExAllocatePool(PagedPool, Length);
4336  if (!ObjectNameInfo) return STATUS_INSUFFICIENT_RESOURCES;
4337 
4338  /* Query the PDO name */
4340  ObjectNameInfo,
4341  Length,
4342  ResultLength);
4344  {
4345  /* It's up to the caller to try again */
4347  }
4348 
4349  /* This string needs to be NULL-terminated */
4350  NullTerminate = TRUE;
4351 
4352  /* Return if successful */
4353  if (NT_SUCCESS(Status)) PIP_RETURN_DATA(ObjectNameInfo->Name.Length,
4354  ObjectNameInfo->Name.Buffer);
4355 
4356  /* Let the caller know how big the name is */
4358  break;
4359 
4361 
4362  Policy = DeviceNode->RemovalPolicy;
4363  PIP_RETURN_DATA(sizeof(Policy), &Policy);
4364 
4365  /* Handle the registry-based properties */
4389  //PIP_REGISTRY_DATA(REGSTR_VAL_CONTAINERID, REG_SZ); // Win7
4391  break;
4394  break;
4399  default:
4401  }
4402 
4403  /* Having a registry value name implies registry data */
4404  if (ValueName)
4405  {
4406  /* We know up-front how much data to expect */
4408 
4409  /* Go get the data, use the LogConf subkey if necessary */
4411  ValueType,
4412  ValueName,
4413  (DeviceProperty ==
4415  L"LogConf": NULL,
4416  PropertyBuffer,
4417  ResultLength);
4418  }
4419  else if (NT_SUCCESS(Status))
4420  {
4421  /* We know up-front how much data to expect, check the caller's buffer */
4422  *ResultLength = ReturnLength + (NullTerminate ? sizeof(UNICODE_NULL) : 0);
4423  if (*ResultLength <= BufferLength)
4424  {
4425  /* Buffer is all good, copy the data */
4426  RtlCopyMemory(PropertyBuffer, Data, ReturnLength);
4427 
4428  /* Check if we need to NULL-terminate the string */
4429  if (NullTerminate)
4430  {
4431  /* Terminate the string */
4432  ((PWCHAR)PropertyBuffer)[ReturnLength / sizeof(WCHAR)] = UNICODE_NULL;
4433  }
4434 
4435  /* This is the success path */
4437  }
4438  else
4439  {
4440  /* Failure path */
4442  }
4443  }
4444 
4445  /* Free any allocation we may have made, and return the status code */
4446  if (ObjectNameInfo) ExFreePool(ObjectNameInfo);
4447  return Status;
4448 }
IN CINT OUT PVOID IN ULONG OUT PULONG ResultLength
Definition: conport.c:47
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:39
#define REGSTR_VAL_CLASS
Definition: regstr.h:291
#define REGSTR_VAL_DRIVER
Definition: regstr.h:385
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
enum _INTERFACE_TYPE INTERFACE_TYPE
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
_In_ PCWSTR _In_z_ PCWSTR _In_ ULONG ValueType
Definition: rtlfuncs.h:4016
NTSTATUS NTAPI PnpBusTypeGuidGet(IN USHORT Index, IN LPGUID BusTypeGuid)
Definition: pnpmgr.c:4016
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
NTSTATUS NTAPI ObQueryNameString(IN PVOID Object, OUT POBJECT_NAME_INFORMATION ObjectNameInfo, IN ULONG Length, OUT PULONG ReturnLength)
Definition: obname.c:1209
#define REGSTR_VAL_CONFIGFLAGS
Definition: regstr.h:388
DEVICE_CAPABILITIES
Definition: iotypes.h:928
#define REGSTR_VAL_UI_NUMBER
Definition: regstr.h:426
uint16_t * PWCHAR
Definition: typedefs.h:54
#define REGSTR_VAL_FRIENDLYNAME
Definition: regstr.h:465
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
NTSTATUS NTAPI PiGetDeviceRegistryProperty(IN PDEVICE_OBJECT DeviceObject, IN ULONG ValueType, IN PWSTR ValueName, IN PWSTR KeyName, OUT PVOID Buffer, IN PULONG BufferLength)
Definition: pnpmgr.c:4137
#define REGSTR_VAL_COMPATIBLEIDS
Definition: regstr.h:296
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
#define UNICODE_NULL
_In_ ULONG BufferLength
Definition: usbdlib.h:225
#define OBJ_NAME_PATH_SEPARATOR
Definition: arcname_tests.c:25
#define REG_MULTI_SZ
Definition: nt_native.h:1501
unsigned char BOOLEAN
struct _OBJECT_NAME_INFORMATION OBJECT_NAME_INFORMATION
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:462
void DPRINT(...)
Definition: polytest.cpp:61
#define REG_RESOURCE_LIST
Definition: nt_native.h:1502
#define PIP_UNIMPLEMENTED()
Definition: pnpmgr.c:4221
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define REGSTR_VAL_CLASSGUID
Definition: regstr.h:422
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
Definition: Node.h:9
PDEVICE_NODE FASTCALL IopGetDeviceNode(PDEVICE_OBJECT DeviceObject)
Definition: pnpmgr.c:66
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static const WCHAR L[]
Definition: oid.c:1250
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define PIP_REGISTRY_DATA(x, y)
Definition: pnpmgr.c:4220
ULONG NTAPI PnpDetermineResourceListSize(IN PCM_RESOURCE_LIST ResourceList)
Definition: pnpmgr.c:4083
#define REGSTR_VAL_HARDWAREID
Definition: regstr.h:485
#define REGSTR_VAL_DEVDESC
Definition: regstr.h:292
Status
Definition: gdiplustypes.h:24
#define MAXULONG
Definition: typedefs.h:250
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define REGSTR_VAL_MFG
Definition: regstr.h:306
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
_In_ DEVICE_REGISTRY_PROPERTY DeviceProperty
Definition: iofuncs.h:1003
enum _DEVICE_REMOVAL_POLICY DEVICE_REMOVAL_POLICY
#define PIP_RETURN_DATA(x, y)
Definition: pnpmgr.c:4219
NTSTATUS NTAPI IopQueryDeviceCapabilities(PDEVICE_NODE DeviceNode, PDEVICE_CAPABILITIES DeviceCaps)
Definition: pnpmgr.c:986
unsigned int ULONG
Definition: retypes.h:1
#define REGSTR_VAL_BOOTCONFIG
Definition: regstr.h:293
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define REG_DWORD
Definition: sdbapi.c:596
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define REGSTR_VAL_LOCATION_INFORMATION
Definition: regstr.h:423
#define REG_SZ
Definition: layer.c:22

Referenced by Bus_AddDevice(), ClasspInitializeHotplugInfo(), GetBusInterface(), CHCDController::HandleDeviceControl(), IntVideoPortCreateAdapterDeviceObject(), IoGetDmaAdapter(), IoOpenDeviceRegistryKey(), IopGetDeviceProperty(), IopUpdateResourceMap(), KspStartBusDevice(), NdisIAddDevice(), NdisIPnPStartDevice(), PcGetDeviceProperty(), PciDetermineSlotNumber(), PciGetDeviceProperty(), RamdiskPnp(), StreamClassStartDevice(), USBH_IoctlGetNodeConnectionDriverKeyName(), USBHUB_FdoHandleDeviceControl(), USBPORT_StartDevice(), and USBPORT_UserGetHcName().

◆ IoInvalidateDeviceRelations()

VOID NTAPI IoInvalidateDeviceRelations ( IN PDEVICE_OBJECT  DeviceObject,
IN DEVICE_RELATION_TYPE  Type 
)

Definition at line 5111 of file pnpmgr.c.

5114 {
5116  KIRQL OldIrql;
5117 
5119  sizeof(DEVICE_ACTION_DATA),
5120  TAG_IO);
5121  if (!Data)
5122  return;
5123 
5125  Data->DeviceObject = DeviceObject;
5126  Data->Type = Type;
5127 
5129  InsertTailList(&IopDeviceActionRequestList, &Data->RequestListEntry);
5131  {
5133  return;
5134  }
5137 
5140  NULL);
5143 }
#define TRUE
Definition: types.h:120
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:717
#define TAG_IO
Definition: tag.h:69
Type
Definition: Type.h:6
KSPIN_LOCK IopDeviceActionLock
Definition: pnpmgr.c:39
#define InsertTailList(ListHead, Entry)
BOOLEAN IopDeviceActionInProgress
Definition: pnpmgr.c:38
UCHAR KIRQL
Definition: env_spec_w32.h:591
smooth NULL
Definition: ftsmooth.c:416
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
LIST_ENTRY IopDeviceActionRequestList
Definition: pnpmgr.c:36
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
static VOID NTAPI IopDeviceActionWorker(_In_ PVOID Context)
Definition: pnpmgr.c:1060
#define ObReferenceObject
Definition: obfuncs.h:204
WORK_QUEUE_ITEM IopDeviceActionWorkItem
Definition: pnpmgr.c:37

Referenced by _Function_class_(), add_volume_device(), ClassDeviceControl(), ClassInvalidateBusRelations(), ClassRemoveDevice(), CreateUsbChildDeviceObject(), DestroyUsbChildDeviceObject(), DiskDeviceControl(), DiskFdoProcessError(), DiskIoctlGetLengthInfo(), DiskIoctlGetPartitionInfo(), DiskIoctlGetPartitionInfoEx(), FDO_StartDevice(), KsCreateBusEnumObject(), KspBusWorkerRoutine(), KspInstallBusEnumInterface(), KsServiceBusEnumCreateRequest(), RamdiskCreateRamdisk(), remove_volume_child(), ReportGreenPdo(), USBH_ProcessPortStateChange(), USBHUB_RootHubCallBack(), and VideoPortEnumerateChildren().

◆ IoInvalidateDeviceState()

VOID NTAPI IoInvalidateDeviceState ( IN PDEVICE_OBJECT  PhysicalDeviceObject)

Definition at line 4455 of file pnpmgr.c.

4456 {
4458  IO_STACK_LOCATION Stack;
4459  ULONG PnPFlags;
4460  NTSTATUS Status;
4462 
4463  RtlZeroMemory(&Stack, sizeof(IO_STACK_LOCATION));
4464  Stack.MajorFunction = IRP_MJ_PNP;
4466 
4467  Status = IopSynchronousCall(PhysicalDeviceObject, &Stack, (PVOID*)&PnPFlags);
4468  if (!NT_SUCCESS(Status))
4469  {
4471  {
4472  DPRINT1("IRP_MN_QUERY_PNP_DEVICE_STATE failed with status 0x%lx\n", Status);
4473  }
4474  return;
4475  }
4476 
4477  if (PnPFlags & PNP_DEVICE_NOT_DISABLEABLE)
4478  DeviceNode->UserFlags |= DNUF_NOT_DISABLEABLE;
4479  else
4480  DeviceNode->UserFlags &= ~DNUF_NOT_DISABLEABLE;
4481 
4482  if (PnPFlags & PNP_DEVICE_DONT_DISPLAY_IN_UI)
4483  DeviceNode->UserFlags |= DNUF_DONT_SHOW_IN_UI;
4484  else
4485  DeviceNode->UserFlags &= ~DNUF_DONT_SHOW_IN_UI;
4486 
4487  if ((PnPFlags & PNP_DEVICE_REMOVED) ||
4488  ((PnPFlags & PNP_DEVICE_FAILED) && !(PnPFlags & PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED)))
4489  {
4490  /* Flag it if it's failed */
4491  if (PnPFlags & PNP_DEVICE_FAILED) DeviceNode->Problem = CM_PROB_FAILED_POST_START;
4492 
4493  /* Send removal IRPs to all of its children */
4495 
4496  /* Send surprise removal */
4498 
4499  /* Tell the user-mode PnP manager that a device was removed */
4500  IopQueueTargetDeviceEvent(&GUID_DEVICE_SURPRISE_REMOVAL,
4501  &DeviceNode->InstancePath);
4502 
4504  }
4505  else if ((PnPFlags & PNP_DEVICE_FAILED) && (PnPFlags & PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED))
4506  {
4507  /* Stop for resource rebalance */
4509  if (!NT_SUCCESS(Status))
4510  {
4511  DPRINT1("Failed to stop device for rebalancing\n");
4512 
4513  /* Stop failed so don't rebalance */
4515  }
4516  }
4517 
4518  /* Resource rebalance */
4520  {
4521  DPRINT("Sending IRP_MN_QUERY_RESOURCES to device stack\n");
4522 
4524  &IoStatusBlock,
4526  NULL);
4528  {
4529  DeviceNode->BootResources =
4532  }
4533  else
4534  {
4535  DPRINT("IopInitiatePnpIrp() failed (Status %x) or IoStatusBlock.Information=NULL\n", Status);
4536  DeviceNode->BootResources = NULL;
4537  }
4538 
4539  DPRINT("Sending IRP_MN_QUERY_RESOURCE_REQUIREMENTS to device stack\n");
4540 
4542  &IoStatusBlock,
4544  NULL);
4545  if (NT_SUCCESS(Status))
4546  {
4547  DeviceNode->ResourceRequirements =
4549  }
4550  else
4551  {
4552  DPRINT("IopInitiatePnpIrp() failed (Status %08lx)\n", Status);
4553  DeviceNode->ResourceRequirements = NULL;
4554  }
4555 
4556  /* IRP_MN_FILTER_RESOURCE_REQUIREMENTS is called indirectly by IopStartDevice */
4558  {
4559  DPRINT1("Restart after resource rebalance failed\n");
4560 
4562  DeviceNode->Flags |= DNF_START_FAILED;
4563 
4565  }
4566  }
4567 }
struct _CM_RESOURCE_LIST * PCM_RESOURCE_LIST
#define TRUE
Definition: types.h:120
#define IRP_MN_QUERY_RESOURCES
NTSTATUS NTAPI IopSynchronousCall(IN PDEVICE_OBJECT DeviceObject, IN PIO_STACK_LOCATION IoStackLocation, OUT PVOID *Information)
Definition: pnpmgr.c:1420
#define PNP_DEVICE_REMOVED
Definition: iotypes.h:967
#define DNUF_NOT_DISABLEABLE
Definition: iotypes.h:204
#define IRP_MN_QUERY_RESOURCE_REQUIREMENTS
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
#define DNF_HAS_BOOT_CONFIG
Definition: iotypes.h:196
#define CM_PROB_FAILED_POST_START
Definition: cfg.h:73
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1122
static VOID NTAPI IopSendSurpriseRemoval(IN PDEVICE_OBJECT DeviceObject)
Definition: pnpmgr.c:519
#define PNP_DEVICE_DONT_DISPLAY_IN_UI
Definition: iotypes.h:965
#define DNF_START_FAILED
Definition: iotypes.h:169
#define DNUF_DONT_SHOW_IN_UI
Definition: iotypes.h:203
#define IopDeviceNodeSetFlag(DeviceNode, Flag)
Definition: io.h:142
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define DNF_STARTED
Definition: iotypes.h:168
NTSTATUS IopQueueTargetDeviceEvent(const GUID *Guid, PUNICODE_STRING DeviceIds)
Definition: plugplay.c:46
#define PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED
Definition: iotypes.h:968
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define PNP_DEVICE_NOT_DISABLEABLE
Definition: iotypes.h:969
Definition: Node.h:9
PDEVICE_NODE FASTCALL IopGetDeviceNode(PDEVICE_OBJECT DeviceObject)
Definition: pnpmgr.c:66
NTSTATUS IopStartDevice(PDEVICE_NODE DeviceNode)
Definition: pnpmgr.c:926
NTSTATUS IopRemoveDevice(PDEVICE_NODE DeviceNode)
Definition: pnpmgr.c:5000
NTSTATUS IopPrepareDeviceForRemoval(PDEVICE_OBJECT DeviceObject, BOOLEAN Force)
#define PNP_DEVICE_FAILED
Definition: iotypes.h:966
NTSTATUS NTAPI IopInitiatePnpIrp(IN PDEVICE_OBJECT DeviceObject, IN OUT PIO_STATUS_BLOCK IoStatusBlock, IN UCHAR MinorFunction, IN PIO_STACK_LOCATION Stack OPTIONAL)
Definition: pnpmgr.c:1490
Status
Definition: gdiplustypes.h:24
struct _IO_RESOURCE_REQUIREMENTS_LIST * PIO_RESOURCE_REQUIREMENTS_LIST
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSTATUS IopStopDevice(PDEVICE_NODE DeviceNode)
Definition: pnpmgr.c:904
static VOID NTAPI IopSendRemoveDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: pnpmgr.c:587
#define DPRINT1
Definition: precomp.h:8
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define IRP_MN_QUERY_PNP_DEVICE_STATE
#define DNF_START_REQUEST_PENDING
Definition: iotypes.h:173

Referenced by HidUsb_ResetWorkerRoutine(), and IopStartDevice2().

◆ IoOpenDeviceRegistryKey()

NTSTATUS NTAPI IoOpenDeviceRegistryKey ( IN PDEVICE_OBJECT  DeviceObject,
IN ULONG  DevInstKeyType,
IN ACCESS_MASK  DesiredAccess,
OUT PHANDLE  DevInstRegKey 
)

Definition at line 4586 of file pnpmgr.c.

4590 {
4591  static WCHAR RootKeyName[] =
4592  L"\\Registry\\Machine\\System\\CurrentControlSet\\";
4593  static WCHAR ProfileKeyName[] =
4594  L"Hardware Profiles\\Current\\System\\CurrentControlSet\\";
4595  static WCHAR ClassKeyName[] = L"Control\\Class\\";
4596  static WCHAR EnumKeyName[] = L"Enum\\";
4597  static WCHAR DeviceParametersKeyName[] = L"Device Parameters";
4599  PWSTR KeyNameBuffer;
4601  ULONG DriverKeyLength;
4604  NTSTATUS Status;
4605 
4606  DPRINT("IoOpenDeviceRegistryKey() called\n");
4607 
4609  {
4610  DPRINT1("IoOpenDeviceRegistryKey(): got wrong params, exiting... \n");
4611  return STATUS_INVALID_PARAMETER;
4612  }
4613 
4617 
4618  /*
4619  * Calculate the length of the base key name. This is the full
4620  * name for driver key or the name excluding "Device Parameters"
4621  * subkey for device key.
4622  */
4623 
4624  KeyNameLength = sizeof(RootKeyName);
4626  KeyNameLength += sizeof(ProfileKeyName) - sizeof(UNICODE_NULL);
4628  {
4629  KeyNameLength += sizeof(ClassKeyName) - sizeof(UNICODE_NULL);
4631  0, NULL, &DriverKeyLength);
4633  return Status;
4634  KeyNameLength += DriverKeyLength;
4635  }
4636  else
4637  {
4638  KeyNameLength += sizeof(EnumKeyName) - sizeof(UNICODE_NULL) +
4639  DeviceNode->InstancePath.Length;
4640  }
4641 
4642  /*
4643  * Now allocate the buffer for the key name...
4644  */
4645 
4646  KeyNameBuffer = ExAllocatePool(PagedPool, KeyNameLength);
4647  if (KeyNameBuffer == NULL)
4649 
4650  KeyName.Length = 0;
4651  KeyName.MaximumLength = (USHORT)KeyNameLength;
4652  KeyName.Buffer = KeyNameBuffer;
4653 
4654  /*
4655  * ...and build the key name.
4656  */
4657 
4658  KeyName.Length += sizeof(RootKeyName) - sizeof(UNICODE_NULL);
4659  RtlCopyMemory(KeyNameBuffer, RootKeyName, KeyName.Length);
4660 
4662  RtlAppendUnicodeToString(&KeyName, ProfileKeyName);
4663 
4665  {
4666  RtlAppendUnicodeToString(&KeyName, ClassKeyName);
4668  DriverKeyLength, KeyNameBuffer +
4669  (KeyName.Length / sizeof(WCHAR)),
4670  &DriverKeyLength);
4671  if (!NT_SUCCESS(Status))
4672  {
4673  DPRINT1("Call to IoGetDeviceProperty() failed with Status 0x%08lx\n", Status);
4674  ExFreePool(KeyNameBuffer);
4675  return Status;
4676  }
4677  KeyName.Length += (USHORT)DriverKeyLength - sizeof(UNICODE_NULL);
4678  }
4679  else
4680  {
4681  RtlAppendUnicodeToString(&KeyName, EnumKeyName);
4683  if (DeviceNode->InstancePath.Length == 0)
4684  {
4685  ExFreePool(KeyNameBuffer);
4686  return Status;
4687  }
4688  }
4689 
4690  /*
4691  * Open the base key.
4692  */
4694  if (!NT_SUCCESS(Status))
4695  {
4696  DPRINT1("IoOpenDeviceRegistryKey(%wZ): Base key doesn't exist, exiting... (Status 0x%08lx)\n", &KeyName, Status);
4697  ExFreePool(KeyNameBuffer);
4698  return Status;
4699  }
4700  ExFreePool(KeyNameBuffer);
4701 
4702  /*
4703  * For driver key we're done now.
4704  */
4705 
4707  return Status;
4708 
4709  /*
4710  * Let's go further. For device key we must open "Device Parameters"
4711  * subkey and create it if it doesn't exist yet.
4712  */
4713 
4714  RtlInitUnicodeString(&KeyName, DeviceParametersKeyName);
4716  &KeyName,
4718  *DevInstRegKey,
4719  NULL);
4720  Status = ZwCreateKey(DevInstRegKey,
4721  DesiredAccess,
4723  0,
4724  NULL,
4726  NULL);
4727  ZwClose(ObjectAttributes.RootDirectory);
4728 
4729  return Status;
4730 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define PLUGPLAY_REGKEY_DEVICE
Definition: iofuncs.h:2738
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSTATUS NTAPI IopOpenRegistryKeyEx(PHANDLE KeyHandle, HANDLE ParentKey, PUNICODE_STRING Name, ACCESS_MASK DesiredAccess)
Definition: pnpmgr.c:3688
uint16_t * PWSTR
Definition: typedefs.h:54
_In_ ULONG DevInstKeyType
Definition: iofuncs.h:1123
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define UNICODE_NULL
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI IoGetDeviceProperty(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_REGISTRY_PROPERTY DeviceProperty, IN ULONG BufferLength, OUT PVOID PropertyBuffer, OUT PULONG ResultLength)
Definition: pnpmgr.c:4228
void DPRINT(...)
Definition: polytest.cpp:61
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
Definition: Node.h:9
PDEVICE_NODE FASTCALL IopGetDeviceNode(PDEVICE_OBJECT DeviceObject)
Definition: pnpmgr.c:66
static const WCHAR L[]
Definition: oid.c:1250
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define PLUGPLAY_REGKEY_DRIVER
Definition: usbd.c:42
_In_ ULONG _In_ ULONG KeyNameLength
Definition: usbdlib.h:195
_In_ ULONG _In_ ACCESS_MASK _Out_ PHANDLE DevInstRegKey
Definition: iofuncs.h:1123
#define IopIsValidPhysicalDeviceObject(PhysicalDeviceObject)
Definition: io.h:238
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
unsigned short USHORT
Definition: pedump.c:61
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define PLUGPLAY_REGKEY_CURRENT_HWPROFILE
Definition: iofuncs.h:2740

Referenced by CdRomGetDeviceParameter(), CdRomSetDeviceParameter(), ClassGetDeviceParameter(), ClasspMediaChangeDeviceInstanceOverride(), ClasspScanForSpecialInRegistry(), ClassSetDeviceParameter(), CmBattAddDevice(), CmBattCreateFdo(), DiskAddDevice(), IntCreateNewRegistryPath(), IntSetupDeviceSettingsKey(), KsMapModuleName(), NdisIPnPStartDevice(), PciAddDevice(), PciGetBiosConfig(), PciSaveBiosConfig(), PcNewRegistryKey(), USBD_GetPdoRegistryParameter(), USBH_SetPdoRegistryParameter(), USBH_WriteFailReasonID(), USBPORT_GetRegistryKeyValueFullInfo(), and USBPORT_SetRegistryKeyValue().

◆ IopActionConfigureChildServices()

NTSTATUS IopActionConfigureChildServices ( PDEVICE_NODE  DeviceNode,
PVOID  Context 
)

Definition at line 2832 of file pnpmgr.c.

2834 {
2836  PDEVICE_NODE ParentDeviceNode;
2839  NTSTATUS Status;
2840  DEVICE_CAPABILITIES DeviceCaps;
2841 
2842  DPRINT("IopActionConfigureChildServices(%p, %p)\n", DeviceNode, Context);
2843 
2844  ParentDeviceNode = (PDEVICE_NODE)Context;
2845 
2846  /*
2847  * We are called for the parent too, but we don't need to do special
2848  * handling for this node
2849  */
2850  if (DeviceNode == ParentDeviceNode)
2851  {
2852  DPRINT("Success\n");
2853  return STATUS_SUCCESS;
2854  }
2855 
2856  /*
2857  * Make sure this device node is a direct child of the parent device node
2858  * that is given as an argument
2859  */
2860 
2861  if (DeviceNode->Parent != ParentDeviceNode)
2862  {
2863  DPRINT("Skipping 2+ level child\n");
2864  return STATUS_SUCCESS;
2865  }
2866 
2867  if (!(DeviceNode->Flags & DNF_PROCESSED))
2868  {
2869  DPRINT1("Child not ready to be configured\n");
2870  return STATUS_SUCCESS;
2871  }
2872 
2873  if (!(DeviceNode->Flags & (DNF_DISABLED | DNF_STARTED | DNF_ADDED)))
2874  {
2875  UNICODE_STRING RegKey;
2876 
2877  /* Install the service for this if it's in the CDDB */
2879 
2880  /*
2881  * Retrieve configuration from Enum key
2882  */
2883 
2884  Service = &DeviceNode->ServiceName;
2885 
2889 
2890  QueryTable[0].Name = L"Service";
2893 
2894  QueryTable[1].Name = L"ClassGUID";
2898  QueryTable[1].DefaultData = L"";
2899  QueryTable[1].DefaultLength = 0;
2900 
2901  RegKey.Length = 0;
2902  RegKey.MaximumLength = sizeof(ENUM_ROOT) + sizeof(WCHAR) + DeviceNode->InstancePath.Length;
2904  RegKey.MaximumLength,
2905  TAG_IO);
2906  if (RegKey.Buffer == NULL)
2907  {
2910  }
2911 
2913  RtlAppendUnicodeToString(&RegKey, L"\\");
2914  RtlAppendUnicodeStringToString(&RegKey, &DeviceNode->InstancePath);
2915 
2917  RegKey.Buffer, QueryTable, NULL, NULL);
2918  ExFreePoolWithTag(RegKey.Buffer, TAG_IO);
2919 
2920  if (!NT_SUCCESS(Status))
2921  {
2922  /* FIXME: Log the error */
2923  DPRINT("Could not retrieve configuration for device %wZ (Status 0x%08x)\n",
2924  &DeviceNode->InstancePath, Status);
2926  return STATUS_SUCCESS;
2927  }
2928 
2929  if (Service->Buffer == NULL)
2930  {
2931  if (NT_SUCCESS(IopQueryDeviceCapabilities(DeviceNode, &DeviceCaps)) &&
2932  DeviceCaps.RawDeviceOK)
2933  {
2934  DPRINT("%wZ is using parent bus driver (%wZ)\n", &DeviceNode->InstancePath, &ParentDeviceNode->ServiceName);
2935  RtlInitEmptyUnicodeString(&DeviceNode->ServiceName, NULL, 0);
2936  }
2937  else if (ClassGUID.Length != 0)
2938  {
2939  /* Device has a ClassGUID value, but no Service value.
2940  * Suppose it is using the NULL driver, so state the
2941  * device is started */
2942  DPRINT("%wZ is using NULL driver\n", &DeviceNode->InstancePath);
2944  }
2945  else
2946  {
2949  }
2950  return STATUS_SUCCESS;
2951  }
2952 
2953  DPRINT("Got Service %S\n", Service->Buffer);
2954  }
2955 
2956  return STATUS_SUCCESS;
2957 }
_In_ PCWSTR _Inout_ _At_ QueryTable _Pre_unknown_ PRTL_QUERY_REGISTRY_TABLE QueryTable
Definition: rtlfuncs.h:4004
#define DNF_PROCESSED
Definition: iotypes.h:167
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define TAG_IO
Definition: tag.h:69
USHORT MaximumLength
Definition: env_spec_w32.h:370
VOID NTAPI IopInstallCriticalDevice(PDEVICE_NODE DeviceNode)
Definition: pnpmgr.c:85
LONG NTSTATUS
Definition: precomp.h:26
DEVICE_CAPABILITIES
Definition: iotypes.h:928
struct _DEVICE_NODE * PDEVICE_NODE
#define IopDeviceNodeSetFlag(DeviceNode, Flag)
Definition: io.h:142
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
static const WCHAR ClassGUID[]
Definition: devclass.c:30
#define DNF_STARTED
Definition: iotypes.h:168
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ENUM_ROOT
Definition: io.h:53
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
Definition: Node.h:9
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static const WCHAR L[]
Definition: oid.c:1250
#define DNF_DISABLED
Definition: iotypes.h:188
#define RTL_REGISTRY_ABSOLUTE
Definition: nt_native.h:161
Status
Definition: gdiplustypes.h:24
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
UNICODE_STRING ServiceName
Definition: iotypes.h:843
#define CM_PROB_FAILED_INSTALL
Definition: cfg.h:58
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI IopQueryDeviceCapabilities(PDEVICE_NODE DeviceNode, PDEVICE_CAPABILITIES DeviceCaps)
Definition: pnpmgr.c:986
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define DNF_ADDED
Definition: iotypes.h:179
#define RTL_QUERY_REGISTRY_DIRECT
Definition: nt_native.h:144
#define REG_SZ
Definition: layer.c:22

Referenced by IopEnumerateDevice().

◆ IopActionInitChildServices()

NTSTATUS IopActionInitChildServices ( PDEVICE_NODE  DeviceNode,
PVOID  Context 
)

Definition at line 2977 of file pnpmgr.c.

2979 {
2980  PDEVICE_NODE ParentDeviceNode;
2981  NTSTATUS Status;
2982  BOOLEAN BootDrivers = !PnpSystemInit;
2983 
2984  DPRINT("IopActionInitChildServices(%p, %p)\n", DeviceNode, Context);
2985 
2986  ParentDeviceNode = Context;
2987 
2988  /*
2989  * We are called for the parent too, but we don't need to do special
2990  * handling for this node
2991  */
2992  if (DeviceNode == ParentDeviceNode)
2993  {
2994  DPRINT("Success\n");
2995  return STATUS_SUCCESS;
2996  }
2997 
2998  /*
2999  * We don't want to check for a direct child because
3000  * this function is called during boot to reinitialize
3001  * devices with drivers that couldn't load yet due to
3002  * stage 0 limitations (ie can't load from disk yet).
3003  */
3004 
3005  if (!(DeviceNode->Flags & DNF_PROCESSED))
3006  {
3007  DPRINT1("Child not ready to be added\n");
3008  return STATUS_SUCCESS;
3009  }
3010 
3014  return STATUS_SUCCESS;
3015 
3016  if (DeviceNode->ServiceName.Buffer == NULL)
3017  {
3018  /* We don't need to worry about loading the driver because we're
3019  * being driven in raw mode so our parent must be loaded to get here */
3021  if (NT_SUCCESS(Status))
3022  {
3024  if (!NT_SUCCESS(Status))
3025  {
3026  DPRINT1("IopStartDevice(%wZ) failed with status 0x%08x\n",
3027  &DeviceNode->InstancePath, Status);
3028  }
3029  }
3030  }
3031  else
3032  {
3033  PLDR_DATA_TABLE_ENTRY ModuleObject;
3035 
3038  /* Get existing DriverObject pointer (in case the driver has
3039  already been loaded and initialized) */
3041  &DriverObject,
3042  &DeviceNode->ServiceName,
3043  FALSE);
3044 
3045  if (!NT_SUCCESS(Status))
3046  {
3047  /* Driver is not initialized, try to load it */
3048  Status = IopLoadServiceModule(&DeviceNode->ServiceName, &ModuleObject);
3049 
3051  {
3052  /* Initialize the driver */
3054  &DeviceNode->ServiceName, FALSE, &DriverObject);
3056  }
3058  {
3059  DPRINT1("Service '%wZ' is disabled\n", &DeviceNode->ServiceName);
3061  }
3062  else
3063  {
3064  DPRINT("IopLoadServiceModule(%wZ) failed with status 0x%08x\n",
3065  &DeviceNode->ServiceName, Status);
3066  if (!BootDrivers) DeviceNode->Problem = CM_PROB_DRIVER_FAILED_LOAD;
3067  }
3068  }
3071 
3072  /* Driver is loaded and initialized at this point */
3073  if (NT_SUCCESS(Status))
3074  {
3075  /* Initialize the device, including all filters */
3077 
3078  /* Remove the extra reference */
3080  }
3081  else
3082  {
3083  /*
3084  * Don't disable when trying to load only boot drivers
3085  */
3086  if (!BootDrivers)
3087  {
3089  }
3090  }
3091  }
3092 
3093  return STATUS_SUCCESS;
3094 }
NTSTATUS NTAPI PipCallDriverAddDevice(IN PDEVICE_NODE DeviceNode, IN BOOLEAN LoadDriver, IN PDRIVER_OBJECT DriverObject)
Definition: pnpinit.c:240
#define TRUE
Definition: types.h:120
#define DNF_PROCESSED
Definition: iotypes.h:167
BOOLEAN PnpSystemInit
Definition: iomgr.c:17
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS FASTCALL IopLoadServiceModule(IN PUNICODE_STRING ServiceName, OUT PLDR_DATA_TABLE_ENTRY *ModuleObject)
Definition: driver.c:314
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define CM_PROB_FAILED_DRIVER_ENTRY
Definition: cfg.h:67
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define STATUS_DRIVER_UNABLE_TO_LOAD
Definition: ntstatus.h:731
NTSTATUS FASTCALL IopInitializeDevice(PDEVICE_NODE DeviceNode, PDRIVER_OBJECT DriverObject)
Definition: pnpmgr.c:434
#define IopDeviceNodeSetFlag(DeviceNode, Flag)
Definition: io.h:142
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
void DPRINT(...)
Definition: polytest.cpp:61
#define DNF_STARTED
Definition: iotypes.h:168
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define CM_PROB_DISABLED_SERVICE
Definition: cfg.h:62
NTSTATUS FASTCALL IopGetDriverObject(OUT PDRIVER_OBJECT *DriverObject, IN PUNICODE_STRING ServiceName, IN BOOLEAN FileSystem)
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
Definition: Node.h:9
NTSTATUS IopStartDevice(PDEVICE_NODE DeviceNode)
Definition: pnpmgr.c:926
#define CM_PROB_DRIVER_FAILED_LOAD
Definition: cfg.h:69
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
Definition: btrfs_drv.h:1853
#define DNF_DISABLED
Definition: iotypes.h:188
#define IopDeviceNodeHasFlag(DeviceNode, Flag)
Definition: io.h:160
Status
Definition: gdiplustypes.h:24
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
NTSTATUS FASTCALL IopInitializeDriverModule(IN PDEVICE_NODE DeviceNode, IN PLDR_DATA_TABLE_ENTRY ModuleObject, IN PUNICODE_STRING ServiceName, IN BOOLEAN FileSystemDriver, OUT PDRIVER_OBJECT *DriverObject)
Definition: driver.c:467
#define DPRINT1
Definition: precomp.h:8
struct tagContext Context
Definition: acpixf.h:1030
ERESOURCE IopDriverLoadResource
Definition: driver.c:19
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define DNF_ADDED
Definition: iotypes.h:179
#define STATUS_IMAGE_ALREADY_LOADED
Definition: ntstatus.h:492

Referenced by IopInitializePnpServices().

◆ IopActionInterrogateDeviceStack()

NTSTATUS IopActionInterrogateDeviceStack ( PDEVICE_NODE  DeviceNode,
PVOID  Context 
)

Definition at line 2355 of file pnpmgr.c.

2357 {
2360  PWSTR LocationInformation;
2361  PDEVICE_NODE ParentDeviceNode;
2362  IO_STACK_LOCATION Stack;
2363  NTSTATUS Status;
2365  LCID LocaleId;
2366  HANDLE InstanceKey = NULL;
2368  UNICODE_STRING InstancePathU;
2369  PDEVICE_OBJECT OldDeviceObject;
2370 
2371  DPRINT("IopActionInterrogateDeviceStack(%p, %p)\n", DeviceNode, Context);
2372  DPRINT("PDO 0x%p\n", DeviceNode->PhysicalDeviceObject);
2373 
2374  ParentDeviceNode = (PDEVICE_NODE)Context;
2375 
2376  /*
2377  * We are called for the parent too, but we don't need to do special
2378  * handling for this node
2379  */
2380  if (DeviceNode == ParentDeviceNode)
2381  {
2382  DPRINT("Success\n");
2383  return STATUS_SUCCESS;
2384  }
2385 
2386  /*
2387  * Make sure this device node is a direct child of the parent device node
2388  * that is given as an argument
2389  */
2390  if (DeviceNode->Parent != ParentDeviceNode)
2391  {
2392  DPRINT("Skipping 2+ level child\n");
2393  return STATUS_SUCCESS;
2394  }
2395 
2396  /* Skip processing if it was already completed before */
2397  if (DeviceNode->Flags & DNF_PROCESSED)
2398  {
2399  /* Nothing to do */
2400  return STATUS_SUCCESS;
2401  }
2402 
2403  /* Get Locale ID */
2404  Status = ZwQueryDefaultLocale(FALSE, &LocaleId);
2405  if (!NT_SUCCESS(Status))
2406  {
2407  DPRINT1("ZwQueryDefaultLocale() failed with status 0x%lx\n", Status);
2408  return Status;
2409  }
2410 
2411  /*
2412  * FIXME: For critical errors, cleanup and disable device, but always
2413  * return STATUS_SUCCESS.
2414  */
2415 
2416  Status = IopCreateDeviceInstancePath(DeviceNode, &InstancePathU);
2417  if (!NT_SUCCESS(Status))
2418  {
2420  {
2421  DPRINT1("IopCreateDeviceInstancePath() failed with status 0x%lx\n", Status);
2422  }
2423 
2424  /* We have to return success otherwise we abort the traverse operation */
2425  return STATUS_SUCCESS;
2426  }
2427 
2428  /* Verify that this is not a duplicate */
2429  OldDeviceObject = IopGetDeviceObjectFromDeviceInstance(&InstancePathU);
2430  if (OldDeviceObject != NULL)
2431  {
2432  PDEVICE_NODE OldDeviceNode = IopGetDeviceNode(OldDeviceObject);
2433 
2434  DPRINT1("Duplicate device instance '%wZ'\n", &InstancePathU);
2435  DPRINT1("Current instance parent: '%wZ'\n", &DeviceNode->Parent->InstancePath);
2436  DPRINT1("Old instance parent: '%wZ'\n", &OldDeviceNode->Parent->InstancePath);
2437 
2438  KeBugCheckEx(PNP_DETECTED_FATAL_ERROR,
2439  0x01,
2440  (ULONG_PTR)DeviceNode->PhysicalDeviceObject,
2441  (ULONG_PTR)OldDeviceObject,
2442  0);
2443  }
2444 
2445  DeviceNode->InstancePath = InstancePathU;
2446 
2447  DPRINT("InstancePath is %S\n", DeviceNode->InstancePath.Buffer);
2448 
2449  /*
2450  * Create registry key for the instance id, if it doesn't exist yet
2451  */
2452  Status = IopCreateDeviceKeyPath(&DeviceNode->InstancePath, REG_OPTION_NON_VOLATILE, &InstanceKey);
2453  if (!NT_SUCCESS(Status))
2454  {
2455  DPRINT1("Failed to create the instance key! (Status %lx)\n", Status);
2456 
2457  /* We have to return success otherwise we abort the traverse operation */
2458  return STATUS_SUCCESS;
2459  }
2460 
2461  IopQueryHardwareIds(DeviceNode, InstanceKey);
2462 
2463  IopQueryCompatibleIds(DeviceNode, InstanceKey);
2464 
2465  DPRINT("Sending IRP_MN_QUERY_DEVICE_TEXT.DeviceTextDescription to device stack\n");
2466 
2467  Stack.Parameters.QueryDeviceText.DeviceTextType = DeviceTextDescription;
2468  Stack.Parameters.QueryDeviceText.LocaleId = LocaleId;
2469  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
2470  &IoStatusBlock,
2472  &Stack);
2474  : NULL;
2475  /* This key is mandatory, so even if the Irp fails, we still write it */
2476  RtlInitUnicodeString(&ValueName, L"DeviceDesc");
2477  if (ZwQueryValueKey(InstanceKey, &ValueName, KeyValueBasicInformation, NULL, 0, &RequiredLength) == STATUS_OBJECT_NAME_NOT_FOUND)
2478  {
2479  if (DeviceDescription &&
2481  {
2482  /* This key is overriden when a driver is installed. Don't write the
2483  * new description if another one already exists */
2484  Status = ZwSetValueKey(InstanceKey,
2485  &ValueName,
2486  0,
2487  REG_SZ,
2489  ((ULONG)wcslen(DeviceDescription) + 1) * sizeof(WCHAR));
2490  }
2491  else
2492  {
2493  UNICODE_STRING DeviceDesc = RTL_CONSTANT_STRING(L"Unknown device");
2494  DPRINT("Driver didn't return DeviceDesc (Status 0x%08lx), so place unknown device there\n", Status);
2495 
2496  Status = ZwSetValueKey(InstanceKey,
2497  &ValueName,
2498  0,
2499  REG_SZ,
2500  DeviceDesc.Buffer,
2501  DeviceDesc.MaximumLength);
2502  if (!NT_SUCCESS(Status))
2503  {
2504  DPRINT1("ZwSetValueKey() failed (Status 0x%lx)\n", Status);
2505  }
2506 
2507  }
2508  }
2509 
2510  if (DeviceDescription)
2511  {
2513  }
2514 
2515  DPRINT("Sending IRP_MN_QUERY_DEVICE_TEXT.DeviceTextLocation to device stack\n");
2516 
2517  Stack.Parameters.QueryDeviceText.DeviceTextType = DeviceTextLocationInformation;
2518  Stack.Parameters.QueryDeviceText.LocaleId = LocaleId;
2519  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
2520  &IoStatusBlock,
2522  &Stack);
2524  {
2525  LocationInformation = (PWSTR)IoStatusBlock.Information;
2526  DPRINT("LocationInformation: %S\n", LocationInformation);
2527  RtlInitUnicodeString(&ValueName, L"LocationInformation");
2528  Status = ZwSetValueKey(InstanceKey,
2529  &ValueName,
2530  0,
2531  REG_SZ,
2532  LocationInformation,
2533  ((ULONG)wcslen(LocationInformation) + 1) * sizeof(WCHAR));
2534  if (!NT_SUCCESS(Status))
2535  {
2536  DPRINT1("ZwSetValueKey() failed (Status %lx)\n", Status);
2537  }
2538 
2539  ExFreePoolWithTag(LocationInformation, 0);
2540  }
2541  else
2542  {
2543  DPRINT("IopInitiatePnpIrp() failed (Status %x) or IoStatusBlock.Information=NULL\n", Status);
2544  }
2545 
2546  DPRINT("Sending IRP_MN_QUERY_BUS_INFORMATION to device stack\n");
2547 
2548  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
2549  &IoStatusBlock,
2551  NULL);
2553  {
2555 
2556  DeviceNode->ChildBusNumber = BusInformation->BusNumber;
2557  DeviceNode->ChildInterfaceType = BusInformation->LegacyBusType;
2558  DeviceNode->ChildBusTypeIndex = IopGetBusTypeGuidIndex(&BusInformation->BusTypeGuid);
2559  ExFreePoolWithTag(BusInformation, 0);
2560  }
2561  else
2562  {
2563  DPRINT("IopInitiatePnpIrp() failed (Status %x) or IoStatusBlock.Information=NULL\n", Status);
2564 
2565  DeviceNode->ChildBusNumber = 0xFFFFFFF0;
2566  DeviceNode->ChildInterfaceType = InterfaceTypeUndefined;
2567  DeviceNode->ChildBusTypeIndex = -1;
2568  }
2569 
2570  DPRINT("Sending IRP_MN_QUERY_RESOURCES to device stack\n");
2571 
2572  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
2573  &IoStatusBlock,
2575  NULL);
2577  {
2580  }
2581  else
2582  {
2583  DPRINT("IopInitiatePnpIrp() failed (Status %x) or IoStatusBlock.Information=NULL\n", Status);
2584  DeviceNode->BootResources = NULL;
2585  }
2586 
2587  DPRINT("Sending IRP_MN_QUERY_RESOURCE_REQUIREMENTS to device stack\n");
2588 
2589  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
2590  &IoStatusBlock,
2592  NULL);
2593  if (NT_SUCCESS(Status))
2594  {
2596  }
2597  else
2598  {
2599  DPRINT("IopInitiatePnpIrp() failed (Status %08lx)\n", Status);
2600  DeviceNode->ResourceRequirements = NULL;
2601  }
2602 
2603  if (InstanceKey != NULL)
2604  {
2605  IopSetDeviceInstanceData(InstanceKey, DeviceNode);
2606  }
2607 
2608  ZwClose(InstanceKey);
2609 
2611 
2613  {
2614  /* Report the device to the user-mode pnp manager */
2615  IopQueueTargetDeviceEvent(&GUID_DEVICE_ENUMERATED,
2616  &DeviceNode->InstancePath);
2617  }
2618 
2619  return STATUS_SUCCESS;
2620 }
struct _CM_RESOURCE_LIST * PCM_RESOURCE_LIST
#define STATUS_PLUGPLAY_NO_DEVICE
Definition: ntstatus.h:717
#define IRP_MN_QUERY_RESOURCES
#define DNF_PROCESSED
Definition: iotypes.h:167
USHORT MaximumLength
Definition: env_spec_w32.h:370
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
uint16_t * PWSTR
Definition: typedefs.h:54
#define IRP_MN_QUERY_RESOURCE_REQUIREMENTS
NTSTATUS NTAPI IopCreateDeviceKeyPath(IN PCUNICODE_STRING RegistryPath, IN ULONG CreateOptions, OUT PHANDLE Handle)
Definition: pnpmgr.c:1612
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI NTSTATUS NTAPI ZwQueryDefaultLocale(_In_ BOOLEAN UserProfile, _Out_ PLCID DefaultLocaleId)
#define DNF_HAS_BOOT_CONFIG
Definition: iotypes.h:196
PDEVICE_OBJECT IopGetDeviceObjectFromDeviceInstance(PUNICODE_STRING DeviceInstance)
Definition: plugplay.c:148
DWORD LCID
Definition: nls.h:13
struct _DEVICE_NODE * Parent
Definition: iotypes.h:825
uint32_t ULONG_PTR
Definition: typedefs.h:63
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
struct _DEVICE_NODE * PDEVICE_NODE
#define UNICODE_NULL
NTSTATUS IopCreateDeviceInstancePath(_In_ PDEVICE_NODE DeviceNode, _Out_ PUNICODE_STRING InstancePath)
Definition: pnpmgr.c:2193
#define IopDeviceNodeSetFlag(DeviceNode, Flag)
Definition: io.h:142
smooth NULL
Definition: ftsmooth.c:416
struct _PNP_BUS_INFORMATION * PPNP_BUS_INFORMATION
void DPRINT(...)
Definition: polytest.cpp:61
USHORT NTAPI IopGetBusTypeGuidIndex(LPGUID BusTypeGuid)
Definition: pnpmgr.c:1106
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
_Must_inspect_result_ _In_ PDEVICE_DESCRIPTION DeviceDescription
Definition: iofuncs.h:1015
NTSTATUS IopQueueTargetDeviceEvent(const GUID *Guid, PUNICODE_STRING DeviceIds)
Definition: plugplay.c:46
NTSTATUS IopSetDeviceInstanceData(HANDLE InstanceKey, PDEVICE_NODE DeviceNode)
Definition: pnpmgr.c:1696
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IRP_MN_QUERY_DEVICE_TEXT
Definition: Node.h:9
PDEVICE_NODE FASTCALL IopGetDeviceNode(PDEVICE_OBJECT DeviceObject)
Definition: pnpmgr.c:66
#define IRP_MN_QUERY_BUS_INFORMATION
static const WCHAR L[]
Definition: oid.c:1250
#define DNF_LEGACY_DRIVER
Definition: iotypes.h:181
NTSTATUS NTAPI IopInitiatePnpIrp(IN PDEVICE_OBJECT DeviceObject, IN OUT PIO_STATUS_BLOCK IoStatusBlock, IN UCHAR MinorFunction, IN PIO_STACK_LOCATION Stack OPTIONAL)
Definition: pnpmgr.c:1490
#define IopDeviceNodeHasFlag(DeviceNode, Flag)
Definition: io.h:160
Status
Definition: gdiplustypes.h:24
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
struct _IO_RESOURCE_REQUIREMENTS_LIST * PIO_RESOURCE_REQUIREMENTS_LIST
_In_ ULONG _Out_opt_ PULONG RequiredLength
Definition: wmifuncs.h:29
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSTATUS IopQueryCompatibleIds(PDEVICE_NODE DeviceNode, HANDLE InstanceKey)
Definition: pnpmgr.c:2129
#define DPRINT1
Definition: precomp.h:8
NTSTATUS IopQueryHardwareIds(PDEVICE_NODE DeviceNode, HANDLE InstanceKey)
Definition: pnpmgr.c:2065
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
INTERFACE_TYPE LegacyBusType
Definition: cmtypes.h:363
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:107
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define REG_SZ
Definition: layer.c:22

Referenced by IopEnumerateDevice(), and IoReportDetectedDevice().

◆ IopCancelPrepareDeviceForRemoval()

VOID IopCancelPrepareDeviceForRemoval ( PDEVICE_OBJECT  DeviceObject)

Definition at line 4908 of file pnpmgr.c.

4909 {
4910  IO_STACK_LOCATION Stack;
4912  PDEVICE_RELATIONS DeviceRelations;
4913  NTSTATUS Status;
4914 
4916 
4917  Stack.Parameters.QueryDeviceRelations.Type = RemovalRelations;
4918 
4920  &IoStatusBlock,
4922  &Stack);
4923  if (!NT_SUCCESS(Status))
4924  {
4925  DPRINT("IopInitiatePnpIrp() failed with status 0x%08lx\n", Status);
4926  DeviceRelations = NULL;
4927  }
4928  else
4929  {
4930  DeviceRelations = (PDEVICE_RELATIONS)IoStatusBlock.Information;
4931  }
4932 
4933  if (DeviceRelations)
4934  IopCancelRemoveDeviceRelations(DeviceRelations);
4935 }
LONG NTSTATUS
Definition: precomp.h:26
static VOID NTAPI IopCancelRemoveDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: pnpmgr.c:614
struct _DEVICE_RELATIONS * PDEVICE_RELATIONS
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static VOID IopCancelRemoveDeviceRelations(PDEVICE_RELATIONS DeviceRelations)
Definition: pnpmgr.c:4891
NTSTATUS NTAPI IopInitiatePnpIrp(IN PDEVICE_OBJECT DeviceObject, IN OUT PIO_STATUS_BLOCK IoStatusBlock, IN UCHAR MinorFunction, IN PIO_STACK_LOCATION Stack OPTIONAL)
Definition: pnpmgr.c:1490
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define IRP_MN_QUERY_DEVICE_RELATIONS
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772

Referenced by IopCancelRemoveChildDevices(), IopCancelRemoveDeviceRelations(), IopQueryRemoveChildDevices(), and IopQueryRemoveDeviceRelations().

◆ IopCancelRemoveChildDevices()

static VOID IopCancelRemoveChildDevices ( PDEVICE_NODE  ParentDeviceNode)
static

Definition at line 4810 of file pnpmgr.c.

4811 {
4812  PDEVICE_NODE ChildDeviceNode, NextDeviceNode;
4813  KIRQL OldIrql;
4814 
4816  ChildDeviceNode = ParentDeviceNode->Child;
4817  while (ChildDeviceNode != NULL)
4818  {
4819  NextDeviceNode = ChildDeviceNode->Sibling;
4821 
4823 
4824  ChildDeviceNode = NextDeviceNode;
4825 
4827  }
4829 }
PDEVICE_OBJECT PhysicalDeviceObject
Definition: iotypes.h:839
UCHAR KIRQL
Definition: env_spec_w32.h:591
struct _DEVICE_NODE * Child
Definition: iotypes.h:824
smooth NULL
Definition: ftsmooth.c:416
VOID IopCancelPrepareDeviceForRemoval(PDEVICE_OBJECT DeviceObject)
Definition: pnpmgr.c:4908
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
struct _DEVICE_NODE * Sibling
Definition: iotypes.h:823
KSPIN_LOCK IopDeviceTreeLock
Definition: pnpmgr.c:19

Referenced by IoRequestDeviceEject().

◆ IopCancelRemoveDevice()

static VOID NTAPI IopCancelRemoveDevice ( IN PDEVICE_OBJECT  DeviceObject)
static

Definition at line 614 of file pnpmgr.c.

615 {
616  IO_STACK_LOCATION Stack;
617  PVOID Dummy;
618 
619  RtlZeroMemory(&Stack, sizeof(IO_STACK_LOCATION));
620  Stack.MajorFunction = IRP_MJ_PNP;
622 
623  /* Drivers should never fail a IRP_MN_CANCEL_REMOVE_DEVICE request */
624  IopSynchronousCall(DeviceObject, &Stack, &Dummy);
625 
628  &GUID_TARGET_DEVICE_REMOVE_CANCELLED,
629  NULL,
630  NULL);
631 }
#define IRP_MN_CANCEL_REMOVE_DEVICE
NTSTATUS NTAPI IopSynchronousCall(IN PDEVICE_OBJECT DeviceObject, IN PIO_STACK_LOCATION IoStackLocation, OUT PVOID *Information)
Definition: pnpmgr.c:1420
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
smooth NULL
Definition: ftsmooth.c:416
VOID IopNotifyPlugPlayNotification(IN PDEVICE_OBJECT DeviceObject, IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory, IN LPCGUID Event, IN PVOID EventCategoryData1, IN PVOID EventCategoryData2)
Definition: pnpnotify.c:36
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261

Referenced by IopCancelPrepareDeviceForRemoval(), and IopPrepareDeviceForRemoval().

◆ IopCancelRemoveDeviceRelations()

static VOID IopCancelRemoveDeviceRelations ( PDEVICE_RELATIONS  DeviceRelations)
static

Definition at line 4891 of file pnpmgr.c.

4892 {
4893  /* This function DOES dereference the device objects in all cases */
4894 
4895  ULONG i;
4896 
4897  for (i = 0; i < DeviceRelations->Count; i++)
4898  {
4899  IopCancelPrepareDeviceForRemoval(DeviceRelations->Objects[i]);
4900  ObDereferenceObject(DeviceRelations->Objects[i]);
4901  DeviceRelations->Objects[i] = NULL;
4902  }
4903 
4904  ExFreePool(DeviceRelations);
4905 }
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2055
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
VOID IopCancelPrepareDeviceForRemoval(PDEVICE_OBJECT DeviceObject)
Definition: pnpmgr.c:4908
unsigned int ULONG
Definition: retypes.h:1
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by IopCancelPrepareDeviceForRemoval(), IopPrepareDeviceForRemoval(), and IoRequestDeviceEject().

◆ IopCreateDeviceInstancePath()

NTSTATUS IopCreateDeviceInstancePath ( _In_ PDEVICE_NODE  DeviceNode,
_Out_ PUNICODE_STRING  InstancePath 
)

Definition at line 2193 of file pnpmgr.c.

2196 {
2198  UNICODE_STRING DeviceId;
2200  IO_STACK_LOCATION Stack;
2201  NTSTATUS Status;
2202  UNICODE_STRING ParentIdPrefix = { 0, 0, NULL };
2204  BOOLEAN IsValidID;
2205 
2206  DPRINT("Sending IRP_MN_QUERY_ID.BusQueryDeviceID to device stack\n");
2207 
2208  Stack.Parameters.QueryId.IdType = BusQueryDeviceID;
2209  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
2210  &IoStatusBlock,
2212  &Stack);
2213  if (!NT_SUCCESS(Status))
2214  {
2215  DPRINT1("IopInitiatePnpIrp(BusQueryDeviceID) failed (Status %x)\n", Status);
2216  return Status;
2217  }
2218 
2220 
2221  if (!IsValidID)
2222  {
2223  DPRINT1("Invalid DeviceID. DeviceNode - %p\n", DeviceNode);
2224  }
2225 
2226  /* Save the device id string */
2228 
2229  DPRINT("Sending IRP_MN_QUERY_CAPABILITIES to device stack (after enumeration)\n");
2230 
2232  if (!NT_SUCCESS(Status))
2233  {
2234  DPRINT1("IopQueryDeviceCapabilities() failed (Status 0x%08lx)\n", Status);
2235  RtlFreeUnicodeString(&DeviceId);
2236  return Status;
2237  }
2238 
2239  /* This bit is only check after enumeration */
2240  if (DeviceCapabilities.HardwareDisabled)
2241  {
2242  /* FIXME: Cleanup device */
2243  DeviceNode->Flags |= DNF_DISABLED;
2244  RtlFreeUnicodeString(&DeviceId);
2246  }
2247  else
2248  {
2249  DeviceNode->Flags &= ~DNF_DISABLED;
2250  }
2251 
2252  if (!DeviceCapabilities.UniqueID)
2253  {
2254  /* Device has not a unique ID. We need to prepend parent bus unique identifier */
2255  DPRINT("Instance ID is not unique\n");
2256  Status = IopGetParentIdPrefix(DeviceNode, &ParentIdPrefix);
2257  if (!NT_SUCCESS(Status))
2258  {
2259  DPRINT1("IopGetParentIdPrefix() failed (Status 0x%08lx)\n", Status);
2260  RtlFreeUnicodeString(&DeviceId);
2261  return Status;
2262  }
2263  }
2264 
2265  DPRINT("Sending IRP_MN_QUERY_ID.BusQueryInstanceID to device stack\n");
2266 
2267  Stack.Parameters.QueryId.IdType = BusQueryInstanceID;
2268  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
2269  &IoStatusBlock,
2271  &Stack);
2272  if (!NT_SUCCESS(Status))
2273  {
2274  DPRINT("IopInitiatePnpIrp(BusQueryInstanceID) failed (Status %lx)\n", Status);
2276  }
2277 
2279  {
2281 
2282  if (!IsValidID)
2283  {
2284  DPRINT1("Invalid InstanceID. DeviceNode - %p\n", DeviceNode);
2285  }
2286  }
2287 
2290 
2291  InstancePath->Length = 0;
2292  InstancePath->MaximumLength = DeviceId.Length + sizeof(WCHAR) +
2293  ParentIdPrefix.Length +
2294  InstanceId.Length +
2295  sizeof(UNICODE_NULL);
2296  if (ParentIdPrefix.Length && InstanceId.Length)
2297  {
2298  InstancePath->MaximumLength += sizeof(WCHAR);
2299  }
2300 
2301  InstancePath->Buffer = ExAllocatePoolWithTag(PagedPool,
2302  InstancePath->MaximumLength,
2303  TAG_IO);
2304  if (!InstancePath->Buffer)
2305  {
2307  RtlFreeUnicodeString(&ParentIdPrefix);
2308  RtlFreeUnicodeString(&DeviceId);
2310  }
2311 
2312  /* Start with the device id */
2313  RtlCopyUnicodeString(InstancePath, &DeviceId);
2314  RtlAppendUnicodeToString(InstancePath, L"\\");
2315 
2316  /* Add information from parent bus device to InstancePath */
2317  RtlAppendUnicodeStringToString(InstancePath, &ParentIdPrefix);
2318  if (ParentIdPrefix.Length && InstanceId.Length)
2319  {
2320  RtlAppendUnicodeToString(InstancePath, L"&");
2321  }
2322 
2323  /* Finally, add the id returned by the driver stack */
2325 
2326  /*
2327  * FIXME: Check for valid characters, if there is invalid characters
2328  * then bugcheck
2329  */
2330 
2332  RtlFreeUnicodeString(&DeviceId);
2333  RtlFreeUnicodeString(&ParentIdPrefix);
2334 
2335  return STATUS_SUCCESS;
2336 }
#define STATUS_PLUGPLAY_NO_DEVICE
Definition: ntstatus.h:717
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define IRP_MN_QUERY_ID
#define TAG_IO
Definition: tag.h:69
uint16_t * PWSTR
Definition: typedefs.h:54
LONG NTSTATUS
Definition: precomp.h:26
DEVICE_CAPABILITIES
Definition: iotypes.h:928
uint16_t * PWCHAR
Definition: typedefs.h:54
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
#define UNICODE_NULL
_Must_inspect_result_ _In_opt_ PVOID _In_opt_ PVOID InstanceId
Definition: fsrtlfuncs.h:907
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define DeviceCapabilities
Definition: wingdi.h:4448
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS IopGetParentIdPrefix(PDEVICE_NODE DeviceNode, PUNICODE_STRING ParentIdPrefix)
Definition: pnpmgr.c:1850
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
Definition: Node.h:9
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static BOOLEAN IopValidateID(_In_ PWCHAR Id, _In_ BUS_QUERY_ID_TYPE QueryType)
Definition: pnpmgr.c:1975
static const WCHAR L[]
Definition: oid.c:1250
#define DNF_DISABLED
Definition: iotypes.h:188
NTSTATUS NTAPI IopInitiatePnpIrp(IN PDEVICE_OBJECT DeviceObject, IN OUT PIO_STATUS_BLOCK IoStatusBlock, IN UCHAR MinorFunction, IN PIO_STACK_LOCATION Stack OPTIONAL)
Definition: pnpmgr.c:1490
Status
Definition: gdiplustypes.h:24
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI IopQueryDeviceCapabilities(PDEVICE_NODE DeviceNode, PDEVICE_CAPABILITIES DeviceCaps)
Definition: pnpmgr.c:986
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by IopActionInterrogateDeviceStack().

◆ IopCreateDeviceKeyPath()

NTSTATUS NTAPI IopCreateDeviceKeyPath ( IN PCUNICODE_STRING  RegistryPath,
IN ULONG  CreateOptions,
OUT PHANDLE  Handle 
)

Definition at line 1612 of file pnpmgr.c.

1615 {
1617  HANDLE hParent = NULL, hKey;
1620  PCWSTR Current, Last;
1621  USHORT Length;
1622  NTSTATUS Status;
1623 
1624  /* Assume failure */
1625  *Handle = NULL;
1626 
1627  /* Open root key for device instances */
1629  if (!NT_SUCCESS(Status))
1630  {
1631  DPRINT1("ZwOpenKey('%wZ') failed with status 0x%08lx\n", &EnumU, Status);
1632  return Status;
1633  }
1634 
1635  Current = KeyName.Buffer = RegistryPath->Buffer;
1636  Last = &RegistryPath->Buffer[RegistryPath->Length / sizeof(WCHAR)];
1637 
1638  /* Go up to the end of the string */
1639  while (Current <= Last)
1640  {
1641  if (Current != Last && *Current != L'\\')
1642  {
1643  /* Not the end of the string and not a separator */
1644  Current++;
1645  continue;
1646  }
1647 
1648  /* Prepare relative key name */
1649  Length = (USHORT)((ULONG_PTR)Current - (ULONG_PTR)KeyName.Buffer);
1650  KeyName.MaximumLength = KeyName.Length = Length;
1651  DPRINT("Create '%wZ'\n", &KeyName);
1652 
1653  /* Open key */
1655  &KeyName,
1657  hParent,
1658  NULL);
1659  Status = ZwCreateKey(&hKey,
1660  Current == Last ? KEY_ALL_ACCESS : KEY_CREATE_SUB_KEY,
1662  0,
1663  NULL,
1664  CreateOptions,
1665  NULL);
1666 
1667  /* Close parent key handle, we don't need it anymore */
1668  if (hParent)
1669  ZwClose(hParent);
1670 
1671  /* Key opening/creating failed? */
1672  if (!NT_SUCCESS(Status))
1673  {
1674  DPRINT1("ZwCreateKey('%wZ') failed with status 0x%08lx\n", &KeyName, Status);
1675  return Status;
1676  }
1677 
1678  /* Check if it is the end of the string */
1679  if (Current == Last)
1680  {
1681  /* Yes, return success */
1682  *Handle = hKey;
1683  return STATUS_SUCCESS;
1684  }
1685 
1686  /* Start with this new parent key */
1687  hParent = hKey;
1688  Current++;
1689  KeyName.Buffer = (PWSTR)Current;
1690  }
1691 
1692  return STATUS_UNSUCCESSFUL;
1693 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
const uint16_t * PCWSTR
Definition: typedefs.h:55
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSTATUS NTAPI IopOpenRegistryKeyEx(PHANDLE KeyHandle, HANDLE ParentKey, PUNICODE_STRING Name, ACCESS_MASK DesiredAccess)
Definition: pnpmgr.c:3688
uint16_t * PWSTR
Definition: typedefs.h:54
LONG NTSTATUS
Definition: precomp.h:26
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
_In_ HANDLE Handle
Definition: extypes.h:390
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ENUM_ROOT
Definition: io.h:53
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE _In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG CreateOptions
Definition: fltkernel.h:1230
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
static const WCHAR L[]
Definition: oid.c:1250
const DOCKBAR PVOID HWND hParent
Definition: tooldock.h:22
Status
Definition: gdiplustypes.h:24
unsigned short USHORT
Definition: pedump.c:61
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define DPRINT1
Definition: precomp.h:8
#define ULONG_PTR
Definition: config.h:101
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1018
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by IopActionInterrogateDeviceStack(), IopCreateDeviceNode(), IopInstallCriticalDevice(), IopQueryDeviceCapabilities(), IopStartDevice(), and IoReportDetectedDevice().

◆ IopCreateDeviceNode()

NTSTATUS IopCreateDeviceNode ( PDEVICE_NODE  ParentNode,
PDEVICE_OBJECT  PhysicalDeviceObject,
PUNICODE_STRING  ServiceName,
PDEVICE_NODE DeviceNode 
)

Definition at line 1187 of file pnpmgr.c.

1191 {
1193  NTSTATUS Status;
1194  KIRQL OldIrql;
1195  UNICODE_STRING FullServiceName;
1196  UNICODE_STRING LegacyPrefix = RTL_CONSTANT_STRING(L"LEGACY_");
1197  UNICODE_STRING UnknownDeviceName = RTL_CONSTANT_STRING(L"UNKNOWN");
1198  UNICODE_STRING KeyName, ClassName;
1199  PUNICODE_STRING ServiceName1;
1200  ULONG LegacyValue;
1202  HANDLE InstanceHandle;
1203 
1204  DPRINT("ParentNode 0x%p PhysicalDeviceObject 0x%p ServiceName %wZ\n",
1205  ParentNode, PhysicalDeviceObject, ServiceName);
1206 
1208  if (!Node)
1209  {
1211  }
1212 
1213  RtlZeroMemory(Node, sizeof(DEVICE_NODE));
1214 
1215  if (!ServiceName)
1216  ServiceName1 = &UnknownDeviceName;
1217  else
1218  ServiceName1 = ServiceName;
1219 
1220  if (!PhysicalDeviceObject)
1221  {
1222  FullServiceName.MaximumLength = LegacyPrefix.Length + ServiceName1->Length + sizeof(UNICODE_NULL);
1223  FullServiceName.Length = 0;
1224  FullServiceName.Buffer = ExAllocatePool(PagedPool, FullServiceName.MaximumLength);
1225  if (!FullServiceName.Buffer)
1226  {
1229  }
1230 
1231  RtlAppendUnicodeStringToString(&FullServiceName, &LegacyPrefix);
1232  RtlAppendUnicodeStringToString(&FullServiceName, ServiceName1);
1233  RtlUpcaseUnicodeString(&FullServiceName, &FullServiceName, FALSE);
1234 
1235  Status = PnpRootCreateDevice(&FullServiceName, NULL, &PhysicalDeviceObject, &Node->InstancePath);
1236  if (!NT_SUCCESS(Status))
1237  {
1238  DPRINT1("PnpRootCreateDevice() failed with status 0x%08X\n", Status);
1239  ExFreePool(FullServiceName.Buffer);
1241  return Status;
1242  }
1243 
1244  /* Create the device key for legacy drivers */
1245  Status = IopCreateDeviceKeyPath(&Node->InstancePath, REG_OPTION_VOLATILE, &InstanceHandle);
1246  if (!NT_SUCCESS(Status))
1247  {
1248  ExFreePool(FullServiceName.Buffer);
1250  return Status;
1251  }
1252 
1253  Node->ServiceName.MaximumLength = ServiceName1->Length + sizeof(UNICODE_NULL);
1254  Node->ServiceName.Length = 0;
1255  Node->ServiceName.Buffer = ExAllocatePool(PagedPool, Node->ServiceName.MaximumLength);
1256  if (!Node->ServiceName.Buffer)
1257  {
1258  ZwClose(InstanceHandle);
1259  ExFreePool(FullServiceName.Buffer);
1261  return Status;
1262  }
1263 
1264  RtlCopyUnicodeString(&Node->ServiceName, ServiceName1);
1265 
1266  if (ServiceName)
1267  {
1268  RtlInitUnicodeString(&KeyName, L"Service");
1269  Status = ZwSetValueKey(InstanceHandle, &KeyName, 0, REG_SZ, ServiceName->Buffer, ServiceName->Length + sizeof(UNICODE_NULL));
1270  }
1271 
1272  if (NT_SUCCESS(Status))
1273  {
1274  RtlInitUnicodeString(&KeyName, L"Legacy");
1275  LegacyValue = 1;
1276  Status = ZwSetValueKey(InstanceHandle, &KeyName, 0, REG_DWORD, &LegacyValue, sizeof(LegacyValue));
1277 
1278  RtlInitUnicodeString(&KeyName, L"ConfigFlags");
1279  LegacyValue = 0;
1280  ZwSetValueKey(InstanceHandle, &KeyName, 0, REG_DWORD, &LegacyValue, sizeof(LegacyValue));
1281 
1282  if (NT_SUCCESS(Status))
1283  {
1284  RtlInitUnicodeString(&KeyName, L"Class");
1285  RtlInitUnicodeString(&ClassName, L"LegacyDriver");
1286  Status = ZwSetValueKey(InstanceHandle, &KeyName, 0, REG_SZ, ClassName.Buffer, ClassName.Length + sizeof(UNICODE_NULL));
1287  if (NT_SUCCESS(Status))
1288  {
1289  RtlInitUnicodeString(&KeyName, L"ClassGUID");
1290  RtlInitUnicodeString(&ClassGUID, L"{8ECC055D-047F-11D1-A537-0000F8753ED1}");
1291  Status = ZwSetValueKey(InstanceHandle, &KeyName, 0, REG_SZ, ClassGUID.Buffer, ClassGUID.Length + sizeof(UNICODE_NULL));
1292  if (NT_SUCCESS(Status))
1293  {
1294  // FIXME: Retrieve the real "description" by looking at the "DisplayName" string
1295  // of the corresponding CurrentControlSet\Services\xxx entry for this driver.
1296  RtlInitUnicodeString(&KeyName, L"DeviceDesc");
1297  Status = ZwSetValueKey(InstanceHandle, &KeyName, 0, REG_SZ, ServiceName1->Buffer, ServiceName1->Length + sizeof(UNICODE_NULL));
1298  }
1299  }
1300  }
1301  }
1302 
1303  ZwClose(InstanceHandle);
1304  ExFreePool(FullServiceName.Buffer);
1305 
1306  if (!NT_SUCCESS(Status))
1307  {
1308  ExFreePool(Node->ServiceName.Buffer);
1310  return Status;
1311  }
1312 
1317  }
1318 
1319  Node->PhysicalDeviceObject = PhysicalDeviceObject;
1320 
1321  ((PEXTENDED_DEVOBJ_EXTENSION)PhysicalDeviceObject->DeviceObjectExtension)->DeviceNode = Node;
1322 
1323  if (ParentNode)
1324  {
1326  Node->Parent = ParentNode;
1327  Node->Sibling = NULL;
1328  if (ParentNode->LastChild == NULL)
1329  {
1330  ParentNode->Child = Node;
1331  ParentNode->LastChild = Node;
1332  }
1333  else
1334  {
1335  ParentNode->LastChild->Sibling = Node;
1336  ParentNode->LastChild = Node;
1337  }
1339  Node->Level = ParentNode->Level + 1;
1340  }
1341 
1343 
1344  *DeviceNode = Node;
1345 
1346  return STATUS_SUCCESS;
1347 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
#define DNF_PROCESSED
Definition: iotypes.h:167
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
NTSTATUS RtlUpcaseUnicodeString(PUNICODE_STRING dst, PUNICODE_STRING src, BOOLEAN Alloc)
Definition: string_lib.cpp:46
#define TAG_IO_DEVNODE
Definition: tag.h:89
USHORT MaximumLength
Definition: env_spec_w32.h:370
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSTATUS NTAPI IopCreateDeviceKeyPath(IN PCUNICODE_STRING RegistryPath, IN ULONG CreateOptions, OUT PHANDLE Handle)
Definition: pnpmgr.c:1612
LONG NTSTATUS
Definition: precomp.h:26
struct _EXTENDED_DEVOBJ_EXTENSION * PEXTENDED_DEVOBJ_EXTENSION
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1122
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
UCHAR KIRQL
Definition: env_spec_w32.h:591
struct _DEVICE_NODE * Child
Definition: iotypes.h:824
#define UNICODE_NULL
union node Node
Definition: types.h:1255
#define IopDeviceNodeSetFlag(DeviceNode, Flag)
Definition: io.h:142
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
static const WCHAR ClassGUID[]
Definition: devclass.c:30
#define DNF_STARTED
Definition: iotypes.h:168
LPTSTR ServiceName
Definition: ServiceMain.c:15
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
Definition: Node.h:9
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static const WCHAR L[]
Definition: oid.c:1250
struct _DEVICE_NODE * LastChild
Definition: iotypes.h:826
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define DNF_LEGACY_DRIVER
Definition: iotypes.h:181
Status
Definition: gdiplustypes.h:24
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define DPRINT1
Definition: precomp.h:8
ULONG Level
Definition: iotypes.h:827
KSPIN_LOCK IopDeviceTreeLock
Definition: pnpmgr.c:19
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define DNF_ADDED
Definition: iotypes.h:179
#define REG_DWORD
Definition: sdbapi.c:596
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
NTSTATUS PnpRootCreateDevice(IN PUNICODE_STRING ServiceName, IN OPTIONAL PDRIVER_OBJECT DriverObject, OUT PDEVICE_OBJECT *PhysicalDeviceObject, OUT OPTIONAL PUNICODE_STRING FullInstancePath)
Definition: pnproot.c:186
Definition: dlist.c:348
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define REG_SZ
Definition: layer.c:22

Referenced by IopEnumerateDevice().

◆ IopCreateRegistryKeyEx()

NTSTATUS NTAPI IopCreateRegistryKeyEx ( OUT PHANDLE  Handle,
IN HANDLE RootHandle  OPTIONAL,
IN PUNICODE_STRING  KeyName,
IN ACCESS_MASK  DesiredAccess,
IN ULONG  CreateOptions,
OUT PULONG Disposition  OPTIONAL 
)

Definition at line 3713 of file pnpmgr.c.

3719 {
3721  ULONG KeyDisposition, RootHandleIndex = 0, i = 1, NestedCloseLevel = 0;
3722  USHORT Length;
3723  HANDLE HandleArray[2];
3724  BOOLEAN Recursing = TRUE;
3725  PWCHAR pp, p, p1;
3726  UNICODE_STRING KeyString;
3728  PAGED_CODE();
3729 
3730  /* P1 is start, pp is end */
3731  p1 = KeyName->Buffer;
3732  pp = (PVOID)((ULONG_PTR)p1 + KeyName->Length);
3733 
3734  /* Create the target key */
3736  KeyName,
3738  RootHandle,
3739  NULL);
3740  Status = ZwCreateKey(&HandleArray[i],
3741  DesiredAccess,
3743  0,
3744  NULL,
3745  CreateOptions,
3746  &KeyDisposition);
3747 
3748  /* Now we check if this failed */
3749  if ((Status == STATUS_OBJECT_NAME_NOT_FOUND) && (RootHandle))
3750  {
3751  /* Target key failed, so we'll need to create its parent. Setup array */
3752  HandleArray[0] = NULL;
3753  HandleArray[1] = RootHandle;
3754 
3755  /* Keep recursing for each missing parent */
3756  while (Recursing)
3757  {
3758  /* And if we're deep enough, close the last handle */
3759  if (NestedCloseLevel > 1) ZwClose(HandleArray[RootHandleIndex]);
3760 
3761  /* We're setup to ping-pong between the two handle array entries */
3762  RootHandleIndex = i;
3763  i = (i + 1) & 1;
3764 
3765  /* Clear the one we're attempting to open now */
3766  HandleArray[i] = NULL;
3767 
3768  /* Process the parent key name */
3769  for (p = p1; ((p < pp) && (*p != OBJ_NAME_PATH_SEPARATOR)); p++);
3770  Length = (USHORT)(p - p1) * sizeof(WCHAR);
3771 
3772  /* Is there a parent name? */
3773  if (Length)
3774  {
3775  /* Build the unicode string for it */
3776  KeyString.Buffer = p1;
3777  KeyString.Length = KeyString.MaximumLength = Length;
3778 
3779  /* Now try opening the parent */
3781  &KeyString,
3783  HandleArray[RootHandleIndex],
3784  NULL);
3785  Status = ZwCreateKey(&HandleArray[i],
3786  DesiredAccess,
3788  0,
3789  NULL,
3790  CreateOptions,
3791  &KeyDisposition);
3792  if (NT_SUCCESS(Status))
3793  {
3794  /* It worked, we have one more handle */
3795  NestedCloseLevel++;
3796  }
3797  else
3798  {
3799  /* Parent key creation failed, abandon loop */
3800  Recursing = FALSE;
3801  continue;
3802  }
3803  }
3804  else
3805  {
3806  /* We don't have a parent name, probably corrupted key name */
3808  Recursing = FALSE;
3809  continue;
3810  }
3811 
3812  /* Now see if there's more parents to create */
3813  p1 = p + 1;
3814  if ((p == pp) || (p1 == pp))
3815  {
3816  /* We're done, hopefully successfully, so stop */
3817  Recursing = FALSE;
3818  }
3819  }
3820 
3821  /* Outer loop check for handle nesting that requires closing the top handle */
3822  if (NestedCloseLevel > 1) ZwClose(HandleArray[RootHandleIndex]);
3823  }
3824 
3825  /* Check if we broke out of the loop due to success */
3826  if (NT_SUCCESS(Status))
3827  {
3828  /* Return the target handle (we closed all the parent ones) and disposition */
3829  *Handle = HandleArray[i];
3830  if (Disposition) *Disposition = KeyDisposition;
3831  }
3832 
3833  /* Return the success state */
3834  return Status;
3835 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
#define TRUE
Definition: types.h:120
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
uint16_t * PWCHAR
Definition: typedefs.h:54
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:50
#define PAGED_CODE()
Definition: video.h:57
uint32_t ULONG_PTR
Definition: typedefs.h:63
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define OBJ_NAME_PATH_SEPARATOR
Definition: arcname_tests.c:25
#define pp
Definition: hlsl.yy.c:1208
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
_In_ HANDLE Handle
Definition: extypes.h:390
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE _In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG CreateOptions
Definition: fltkernel.h:1230
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
Status
Definition: gdiplustypes.h:24
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
unsigned short USHORT
Definition: pedump.c:61
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
unsigned int ULONG
Definition: retypes.h:1
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
GLfloat GLfloat p
Definition: glext.h:8902
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231

Referenced by IopSetServiceEnumData().

◆ IopDeviceActionWorker()

static VOID NTAPI IopDeviceActionWorker ( _In_ PVOID  Context)
static

Definition at line 1060 of file pnpmgr.c.

1062 {
1063  PLIST_ENTRY ListEntry;
1065  KIRQL OldIrql;
1066 
1069  {
1072  Data = CONTAINING_RECORD(ListEntry,
1074  RequestListEntry);
1075 
1077  Data->Type);
1078 
1079  ObDereferenceObject(Data->DeviceObject);
1082  }
1085 }
NTSTATUS NTAPI IoSynchronousInvalidateDeviceRelations(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_RELATION_TYPE Type)
Definition: pnpmgr.c:5150
#define TAG_IO
Definition: tag.h:69
KSPIN_LOCK IopDeviceActionLock
Definition: pnpmgr.c:39
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
BOOLEAN IopDeviceActionInProgress
Definition: pnpmgr.c:38
UCHAR KIRQL
Definition: env_spec_w32.h:591
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
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
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: typedefs.h:117
LIST_ENTRY IopDeviceActionRequestList
Definition: pnpmgr.c:36
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by IoInvalidateDeviceRelations().

◆ IopEnumerateDetectedDevices()

static INIT_FUNCTION NTSTATUS IopEnumerateDetectedDevices ( IN HANDLE  hBaseKey,
IN PUNICODE_STRING RelativePath  OPTIONAL,
IN HANDLE  hRootKey,
IN BOOLEAN  EnumerateSubKeys,
IN PCM_FULL_RESOURCE_DESCRIPTOR  ParentBootResources,
IN ULONG  ParentBootResourcesLength 
)
static

Definition at line 3127 of file pnpmgr.c.

3134 {
3135  UNICODE_STRING IdentifierU = RTL_CONSTANT_STRING(L"Identifier");
3136  UNICODE_STRING HardwareIDU = RTL_CONSTANT_STRING(L"HardwareID");
3137  UNICODE_STRING ConfigurationDataU = RTL_CONSTANT_STRING(L"Configuration Data");
3138  UNICODE_STRING BootConfigU = RTL_CONSTANT_STRING(L"BootConfig");
3139  UNICODE_STRING LogConfU = RTL_CONSTANT_STRING(L"LogConf");
3141  HANDLE hDevicesKey = NULL;
3142  HANDLE hDeviceKey = NULL;
3143  HANDLE hLevel1Key, hLevel2Key = NULL, hLogConf;
3144  UNICODE_STRING Level2NameU;
3145  WCHAR Level2Name[5];
3146  ULONG IndexDevice = 0;
3147  ULONG IndexSubKey;
3148  PKEY_BASIC_INFORMATION pDeviceInformation = NULL;
3149  ULONG DeviceInfoLength = sizeof(KEY_BASIC_INFORMATION) + 50 * sizeof(WCHAR);
3150  PKEY_VALUE_PARTIAL_INFORMATION pValueInformation = NULL;
3151  ULONG ValueInfoLength = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 50 * sizeof(WCHAR);
3154  PCM_FULL_RESOURCE_DESCRIPTOR BootResources = NULL;
3155  ULONG BootResourcesLength;
3156  NTSTATUS Status;
3157 
3158  const UNICODE_STRING IdentifierSerial = RTL_CONSTANT_STRING(L"SerialController");
3159  UNICODE_STRING HardwareIdSerial = RTL_CONSTANT_STRING(L"*PNP0501\0");
3160  static ULONG DeviceIndexSerial = 0;
3161  const UNICODE_STRING IdentifierKeyboard = RTL_CONSTANT_STRING(L"KeyboardController");
3162  UNICODE_STRING HardwareIdKeyboard = RTL_CONSTANT_STRING(L"*PNP0303\0");
3163  static ULONG DeviceIndexKeyboard = 0;
3164  const UNICODE_STRING IdentifierMouse = RTL_CONSTANT_STRING(L"PointerController");
3165  UNICODE_STRING HardwareIdMouse = RTL_CONSTANT_STRING(L"*PNP0F13\0");
3166  static ULONG DeviceIndexMouse = 0;
3167  const UNICODE_STRING IdentifierParallel = RTL_CONSTANT_STRING(L"ParallelController");
3168  UNICODE_STRING HardwareIdParallel = RTL_CONSTANT_STRING(L"*PNP0400\0");
3169  static ULONG DeviceIndexParallel = 0;
3170  const UNICODE_STRING IdentifierFloppy = RTL_CONSTANT_STRING(L"FloppyDiskPeripheral");
3171  UNICODE_STRING HardwareIdFloppy = RTL_CONSTANT_STRING(L"*PNP0700\0");
3172  static ULONG DeviceIndexFloppy = 0;
3173  UNICODE_STRING HardwareIdKey;
3174  PUNICODE_STRING pHardwareId;
3175  ULONG DeviceIndex = 0;
3176  PUCHAR CmResourceList;
3177  ULONG ListCount;
3178 
3179  if (RelativePath)
3180  {
3181  Status = IopOpenRegistryKeyEx(&hDevicesKey, hBaseKey, RelativePath, KEY_ENUMERATE_SUB_KEYS);
3182  if (!NT_SUCCESS(Status))
3183  {
3184  DPRINT("ZwOpenKey() failed with status 0x%08lx\n", Status);
3185  goto cleanup;
3186  }
3187  }
3188  else
3189  hDevicesKey = hBaseKey;
3190 
3191  pDeviceInformation = ExAllocatePool(PagedPool, DeviceInfoLength);
3192  if (!pDeviceInformation)
3193  {
3194  DPRINT("ExAllocatePool() failed\n");
3196  goto cleanup;
3197  }
3198 
3199  pValueInformation = ExAllocatePool(PagedPool, ValueInfoLength);
3200  if (!pValueInformation)
3201  {
3202  DPRINT("ExAllocatePool() failed\n");
3204  goto cleanup;
3205  }
3206 
3207  while (TRUE)
3208  {
3209  Status = ZwEnumerateKey(hDevicesKey, IndexDevice, KeyBasicInformation, pDeviceInformation, DeviceInfoLength, &RequiredSize);
3211  break;
3213  {
3214  ExFreePool(pDeviceInformation);
3215  DeviceInfoLength = RequiredSize;
3216  pDeviceInformation = ExAllocatePool(PagedPool, DeviceInfoLength);
3217  if (!pDeviceInformation)
3218  {
3219  DPRINT("ExAllocatePool() failed\n");
3221  goto cleanup;
3222  }
3223  Status = ZwEnumerateKey(hDevicesKey, IndexDevice, KeyBasicInformation, pDeviceInformation, DeviceInfoLength, &RequiredSize);
3224  }
3225  if (!NT_SUCCESS(Status))
3226  {
3227  DPRINT("ZwEnumerateKey() failed with status 0x%08lx\n", Status);
3228  goto cleanup;
3229  }
3230  IndexDevice++;
3231 
3232  /* Open device key */
3233  DeviceName.Length = DeviceName.MaximumLength = (USHORT)pDeviceInformation->NameLength;
3234  DeviceName.Buffer = pDeviceInformation->Name;
3235 
3236  Status = IopOpenRegistryKeyEx(&hDeviceKey, hDevicesKey, &DeviceName,
3237  KEY_QUERY_VALUE + (EnumerateSubKeys ? KEY_ENUMERATE_SUB_KEYS : 0));
3238  if (!NT_SUCCESS(Status))
3239  {
3240  DPRINT("ZwOpenKey() failed with status 0x%08lx\n", Status);
3241  goto cleanup;
3242  }
3243 
3244  /* Read boot resources, and add then to parent ones */
3245  Status = ZwQueryValueKey(hDeviceKey, &ConfigurationDataU, KeyValuePartialInformation, pValueInformation, ValueInfoLength, &RequiredSize);
3247  {
3248  ExFreePool(pValueInformation);
3249  ValueInfoLength = RequiredSize;
3250  pValueInformation = ExAllocatePool(PagedPool, ValueInfoLength);
3251  if (!pValueInformation)
3252  {
3253  DPRINT("ExAllocatePool() failed\n");
3254  ZwDeleteKey(hLevel2Key);
3256  goto cleanup;
3257  }
3258  Status = ZwQueryValueKey(hDeviceKey, &ConfigurationDataU, KeyValuePartialInformation, pValueInformation, ValueInfoLength, &RequiredSize);
3259  }
3261  {
3262  BootResources = ParentBootResources;
3263  BootResourcesLength = ParentBootResourcesLength;
3264  }
3265  else if (!NT_SUCCESS(Status))
3266  {
3267  DPRINT("ZwQueryValueKey() failed with status 0x%08lx\n", Status);
3268  goto nextdevice;
3269  }
3270  else if (pValueInformation->Type != REG_FULL_RESOURCE_DESCRIPTOR)
3271  {
3272  DPRINT("Wrong registry type: got 0x%lx, expected 0x%lx\n", pValueInformation->Type, REG_FULL_RESOURCE_DESCRIPTOR);
3273  goto nextdevice;
3274  }
3275  else
3276  {
3277  static const ULONG Header = FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList.PartialDescriptors);
3278 
3279  /* Concatenate current resources and parent ones */
3280  if (ParentBootResourcesLength == 0)
3281  BootResourcesLength = pValueInformation->DataLength;
3282  else
3283  BootResourcesLength = ParentBootResourcesLength
3284  + pValueInformation->DataLength
3285  - Header;
3286  BootResources = ExAllocatePool(PagedPool, BootResourcesLength);
3287  if (!BootResources)
3288  {
3289  DPRINT("ExAllocatePool() failed\n");
3290  goto nextdevice;
3291  }
3292  if (ParentBootResourcesLength < sizeof(CM_FULL_RESOURCE_DESCRIPTOR))
3293  {
3294  RtlCopyMemory(BootResources, pValueInformation->Data, pValueInformation->DataLength);
3295  }
3296  else if (ParentBootResources->PartialResourceList.PartialDescriptors[ParentBootResources->PartialResourceList.Count - 1].Type == CmResourceTypeDeviceSpecific)
3297  {
3298  RtlCopyMemory(BootResources, pValueInformation->Data, pValueInformation->DataLength);
3299  RtlCopyMemory(
3300  (PVOID)((ULONG_PTR)BootResources + pValueInformation->DataLength),
3301  (PVOID)((ULONG_PTR)ParentBootResources + Header),
3302  ParentBootResourcesLength - Header);
3303  BootResources->PartialResourceList.Count += ParentBootResources->PartialResourceList.Count;
3304  }
3305  else
3306  {
3307  RtlCopyMemory(BootResources, pValueInformation->Data, Header);
3308  RtlCopyMemory(
3309  (PVOID)((ULONG_PTR)BootResources + Header),
3310  (PVOID)((ULONG_PTR)ParentBootResources + Header),
3311  ParentBootResourcesLength - Header);
3312  RtlCopyMemory(
3313  (PVOID)((ULONG_PTR)BootResources + ParentBootResourcesLength),
3314  pValueInformation->Data + Header,
3315  pValueInformation->DataLength - Header);
3316  BootResources->PartialResourceList.Count += ParentBootResources->PartialResourceList.Count;
3317  }
3318  }
3319 
3320  if (EnumerateSubKeys)
3321  {
3322  IndexSubKey = 0;
3323  while (TRUE)
3324  {
3325  Status = ZwEnumerateKey(hDeviceKey, IndexSubKey, KeyBasicInformation, pDeviceInformation, DeviceInfoLength, &RequiredSize);
3327  break;
3329  {
3330  ExFreePool(pDeviceInformation);
3331  DeviceInfoLength = RequiredSize;
3332  pDeviceInformation = ExAllocatePool(PagedPool, DeviceInfoLength);
3333  if (!pDeviceInformation)
3334  {
3335  DPRINT("ExAllocatePool() failed\n");
3337  goto cleanup;
3338  }
3339  Status = ZwEnumerateKey(hDeviceKey, IndexSubKey, KeyBasicInformation, pDeviceInformation, DeviceInfoLength, &RequiredSize);
3340  }
3341  if (!NT_SUCCESS(Status))
3342  {
3343  DPRINT("ZwEnumerateKey() failed with status 0x%08lx\n", Status);
3344  goto cleanup;
3345  }
3346  IndexSubKey++;
3347  DeviceName.Length = DeviceName.MaximumLength = (USHORT)pDeviceInformation->NameLength;
3348  DeviceName.Buffer = pDeviceInformation->Name;
3349 
3351  hDeviceKey,
3352  &DeviceName,
3353  hRootKey,
3354  TRUE,
3355  BootResources,
3356  BootResourcesLength);
3357  if (!NT_SUCCESS(Status))
3358  goto cleanup;
3359  }
3360  }
3361 
3362  /* Read identifier */
3363  Status = ZwQueryValueKey(hDeviceKey, &IdentifierU, KeyValuePartialInformation, pValueInformation, ValueInfoLength, &RequiredSize);
3365  {
3366  ExFreePool(pValueInformation);
3367  ValueInfoLength = RequiredSize;
3368  pValueInformation = ExAllocatePool(PagedPool, ValueInfoLength);
3369  if (!pValueInformation)
3370  {
3371  DPRINT("ExAllocatePool() failed\n");
3373  goto cleanup;
3374  }
3375  Status = ZwQueryValueKey(hDeviceKey, &IdentifierU, KeyValuePartialInformation, pValueInformation, ValueInfoLength, &RequiredSize);
3376  }
3377  if (!NT_SUCCESS(Status))
3378  {
3380  {
3381  DPRINT("ZwQueryValueKey() failed with status 0x%08lx\n", Status);
3382  goto nextdevice;
3383  }
3385  }
3386  else if (pValueInformation->Type != REG_SZ)
3387  {
3388  DPRINT("Wrong registry type: got 0x%lx, expected 0x%lx\n", pValueInformation->Type, REG_SZ);
3389  goto nextdevice;
3390  }
3391  else
3392  {
3393  /* Assign hardware id to this device */
3394  ValueName.Length = ValueName.MaximumLength = (USHORT)pValueInformation->DataLength;
3395  ValueName.Buffer = (PWCHAR)pValueInformation->Data;
3396  if (ValueName.Length >= sizeof(WCHAR) && ValueName.Buffer[ValueName.Length / sizeof(WCHAR) - 1] == UNICODE_NULL)
3397  ValueName.Length -= sizeof(WCHAR);
3398  }
3399 
3400  if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierSerial, FALSE) == 0)
3401  {
3402  pHardwareId = &HardwareIdSerial;
3403  DeviceIndex = DeviceIndexSerial++;
3404  }
3405  else if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierKeyboard, FALSE) == 0)
3406  {
3407  pHardwareId = &HardwareIdKeyboard;
3408  DeviceIndex = DeviceIndexKeyboard++;
3409  }
3410  else if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierMouse, FALSE) == 0)
3411  {
3412  pHardwareId = &HardwareIdMouse;
3413  DeviceIndex = DeviceIndexMouse++;
3414  }
3415  else if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierParallel, FALSE) == 0)
3416  {
3417  pHardwareId = &HardwareIdParallel;
3418  DeviceIndex = DeviceIndexParallel++;
3419  }
3420  else if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierFloppy, FALSE) == 0)
3421  {
3422  pHardwareId = &HardwareIdFloppy;
3423  DeviceIndex = DeviceIndexFloppy++;
3424  }
3425  else
3426  {
3427  /* Unknown key path */
3428  DPRINT("Unknown key path '%wZ'\n", RelativePath);
3429  goto nextdevice;
3430  }
3431 
3432  /* Prepare hardware id key (hardware id value without final \0) */
3433  HardwareIdKey = *pHardwareId;
3434  HardwareIdKey.Length -= sizeof(UNICODE_NULL);
3435 
3436  /* Add the detected device to Root key */
3437  InitializeObjectAttributes(&ObjectAttributes, &HardwareIdKey, OBJ_KERNEL_HANDLE, hRootKey, NULL);
3438  Status = ZwCreateKey(
3439  &hLevel1Key,
3442  0,
3443  NULL,
3445  NULL);
3446  if (!NT_SUCCESS(Status))
3447  {
3448  DPRINT("ZwCreateKey() failed with status 0x%08lx\n", Status);
3449  goto nextdevice;
3450  }
3451  swprintf(Level2Name, L"%04lu", DeviceIndex);
3452  RtlInitUnicodeString(&Level2NameU, Level2Name);
3453  InitializeObjectAttributes(&ObjectAttributes, &Level2NameU, OBJ_KERNEL_HANDLE, hLevel1Key, NULL);
3454  Status = ZwCreateKey(
3455  &hLevel2Key,
3458  0,
3459  NULL,
3461  NULL);
3462  ZwClose(hLevel1Key);
3463  if (!NT_SUCCESS(Status))
3464  {
3465  DPRINT("ZwCreateKey() failed with status 0x%08lx\n", Status);
3466  goto nextdevice;
3467  }
3468  DPRINT("Found %wZ #%lu (%wZ)\n", &ValueName, DeviceIndex, &HardwareIdKey);
3469  Status = ZwSetValueKey(hLevel2Key, &HardwareIDU, 0, REG_MULTI_SZ, pHardwareId->Buffer, pHardwareId->MaximumLength);
3470  if (!NT_SUCCESS(Status))
3471  {
3472  DPRINT("ZwSetValueKey() failed with status 0x%08lx\n", Status);
3473  ZwDeleteKey(hLevel2Key);
3474  goto nextdevice;
3475  }
3476  /* Create 'LogConf' subkey */
3478  Status = ZwCreateKey(
3479  &hLogConf,
3480  KEY_SET_VALUE,
3482  0,
3483  NULL,
3485  NULL);
3486  if (!NT_SUCCESS(Status))
3487  {
3488  DPRINT("ZwCreateKey() failed with status 0x%08lx\n", Status);
3489  ZwDeleteKey(hLevel2Key);
3490  goto nextdevice;
3491  }
3492  if (BootResourcesLength >= sizeof(CM_FULL_RESOURCE_DESCRIPTOR))
3493  {
3494  CmResourceList = ExAllocatePool(PagedPool, BootResourcesLength + sizeof(ULONG));
3495  if (!CmResourceList)
3496  {
3497  ZwClose(hLogConf);
3498  ZwDeleteKey(hLevel2Key);
3499  goto nextdevice;
3500  }
3501 
3502  /* Add the list count (1st member of CM_RESOURCE_LIST) */
3503  ListCount = 1;
3504  RtlCopyMemory(CmResourceList,
3505  &ListCount,
3506  sizeof(ULONG));
3507 
3508  /* Now add the actual list (2nd member of CM_RESOURCE_LIST) */
3509  RtlCopyMemory(CmResourceList + sizeof(ULONG),
3510  BootResources,
3511  BootResourcesLength);
3512 
3513  /* Save boot resources to 'LogConf\BootConfig' */
3514  Status = ZwSetValueKey(hLogConf, &BootConfigU, 0, REG_RESOURCE_LIST, CmResourceList, BootResourcesLength + sizeof(ULONG));
3515  if (!NT_SUCCESS(Status))
3516  {
3517  DPRINT("ZwSetValueKey() failed with status 0x%08lx\n", Status);
3518  ZwClose(hLogConf);
3519  ZwDeleteKey(hLevel2Key);
3520  goto nextdevice;
3521  }
3522  }
3523  ZwClose(hLogConf);
3524 
3525 nextdevice:
3526  if (BootResources && BootResources != ParentBootResources)
3527  {
3528  ExFreePool(BootResources);
3529  BootResources = NULL;
3530  }
3531  if (hLevel2Key)
3532  {
3533  ZwClose(hLevel2Key);
3534  hLevel2Key = NULL;
3535  }
3536  if (hDeviceKey)
3537  {
3538  ZwClose(hDeviceKey);
3539  hDeviceKey = NULL;
3540  }
3541  }
3542 
3544 
3545 cleanup:
3546  if (hDevicesKey && hDevicesKey != hBaseKey)
3547  ZwClose(hDevicesKey);
3548  if (hDeviceKey)
3549  ZwClose(hDeviceKey);
3550  if (pDeviceInformation)
3551  ExFreePool(pDeviceInformation);
3552  if (pValueInformation)
3553  ExFreePool(pValueInformation);
3554  return Status;
3555 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define CmResourceTypeDeviceSpecific
Definition: hwresource.cpp:127
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:193
#define KEY_SET_VALUE
Definition: nt_native.h:1017
USHORT MaximumLength
Definition: env_spec_w32.h:370
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSTATUS NTAPI IopOpenRegistryKeyEx(PHANDLE KeyHandle, HANDLE ParentKey, PUNICODE_STRING Name, ACCESS_MASK DesiredAccess)
Definition: pnpmgr.c:3688
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
struct _KEY_BASIC_INFORMATION KEY_BASIC_INFORMATION
uint16_t * PWCHAR
Definition: typedefs.h:54
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
uint32_t ULONG_PTR
Definition: typedefs.h:63
CM_PARTIAL_RESOURCE_LIST PartialResourceList
Definition: hwresource.cpp:160
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
#define UNICODE_NULL
Definition: Header.h:8
#define REG_MULTI_SZ
Definition: nt_native.h:1501
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define REG_RESOURCE_LIST
Definition: nt_native.h:1502
#define REG_FULL_RESOURCE_DESCRIPTOR
Definition: nt_native.h:1503
_Inout_ PRTL_BUFFER _In_ SIZE_T RequiredSize
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define swprintf(buf, format,...)
Definition: sprintf.c:56
static const WCHAR L[]
Definition: oid.c:1250
ULONG RtlCompareUnicodeString(PUNICODE_STRING s1, PUNICODE_STRING s2, BOOLEAN UpCase)
Definition: string_lib.cpp:31
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
Status
Definition: gdiplustypes.h:24
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
unsigned short USHORT
Definition: pedump.c:61
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
struct _KEY_VALUE_PARTIAL_INFORMATION KEY_VALUE_PARTIAL_INFORMATION
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
char * cleanup(char *str)
Definition: wpickclick.c:99
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
static INIT_FUNCTION NTSTATUS IopEnumerateDetectedDevices(IN HANDLE hBaseKey, IN PUNICODE_STRING RelativePath OPTIONAL, IN HANDLE hRootKey, IN BOOLEAN EnumerateSubKeys, IN PCM_FULL_RESOURCE_DESCRIPTOR ParentBootResources, IN ULONG ParentBootResourcesLength)
Definition: pnpmgr.c:3127
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1018
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define REG_SZ
Definition: layer.c:22

Referenced by IopUpdateRootKey().

◆ IopEnumerateDevice()

NTSTATUS IopEnumerateDevice ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 2670 of file pnpmgr.c.

2672 {
2675  PDEVICE_RELATIONS DeviceRelations;
2676  PDEVICE_OBJECT ChildDeviceObject;
2678  PDEVICE_NODE ChildDeviceNode;
2679  IO_STACK_LOCATION Stack;
2680  NTSTATUS Status;
2681  ULONG i;
2682 
2683  DPRINT("DeviceObject 0x%p\n", DeviceObject);
2684 
2686  {
2688 
2689  DPRINT("Sending GUID_DEVICE_ARRIVAL\n");
2690  IopQueueTargetDeviceEvent(&GUID_DEVICE_ARRIVAL,
2691  &DeviceNode->InstancePath);
2692  }
2693 
2694  DPRINT("Sending IRP_MN_QUERY_DEVICE_RELATIONS to device stack\n");
2695 
2696  Stack.Parameters.QueryDeviceRelations.Type = BusRelations;
2697 
2699  DeviceObject,
2700  &IoStatusBlock,
2702  &Stack);
2703  if (!NT_SUCCESS(Status) || Status == STATUS_PENDING)
2704  {
2705  DPRINT("IopInitiatePnpIrp() failed with status 0x%08lx\n", Status);
2706  return Status;
2707  }
2708 
2709  DeviceRelations = (PDEVICE_RELATIONS)IoStatusBlock.Information;
2710 
2711  /*
2712  * Send removal IRPs for devices that have disappeared
2713  * NOTE: This code handles the case where no relations are specified
2714  */
2715  IopHandleDeviceRemoval(DeviceNode, DeviceRelations);
2716 
2717  /* Now we bail if nothing was returned */
2718  if (!DeviceRelations)
2719  {
2720  /* We're all done */
2721  DPRINT("No PDOs\n");
2722  return STATUS_SUCCESS;
2723  }
2724 
2725  DPRINT("Got %u PDOs\n", DeviceRelations->Count);
2726 
2727  /*
2728  * Create device nodes for all discovered devices
2729  */
2730  for (i = 0; i < DeviceRelations->Count; i++)
2731  {
2732  ChildDeviceObject = DeviceRelations->Objects[i];
2733  ASSERT((ChildDeviceObject->Flags & DO_DEVICE_INITIALIZING) == 0);
2734 
2735  ChildDeviceNode = IopGetDeviceNode(ChildDeviceObject);
2736  if (!ChildDeviceNode)
2737  {
2738  /* One doesn't exist, create it */
2740  DeviceNode,
2741  ChildDeviceObject,
2742  NULL,
2743  &ChildDeviceNode);
2744  if (NT_SUCCESS(Status))
2745  {
2746  /* Mark the node as enumerated */
2747  ChildDeviceNode->Flags |= DNF_ENUMERATED;
2748 
2749  /* Mark the DO as bus enumerated */
2750  ChildDeviceObject->Flags |= DO_BUS_ENUMERATED_DEVICE;
2751  }
2752  else
2753  {
2754  /* Ignore this DO */
2755  DPRINT1("IopCreateDeviceNode() failed with status 0x%08x. Skipping PDO %u\n", Status, i);
2756  ObDereferenceObject(ChildDeviceObject);
2757  }
2758  }
2759  else
2760  {
2761  /* Mark it as enumerated */
2762  ChildDeviceNode->Flags |= DNF_ENUMERATED;
2763  ObDereferenceObject(ChildDeviceObject);
2764  }
2765  }
2766  ExFreePool(DeviceRelations);
2767 
2768  /*
2769  * Retrieve information about all discovered children from the bus driver
2770  */
2772  &Context,
2773  DeviceNode,
2775  DeviceNode);
2776 
2778  if (!NT_SUCCESS(Status))
2779  {
2780  DPRINT("IopTraverseDeviceTree() failed with status 0x%08lx\n", Status);
2781  return Status;
2782  }
2783 
2784  /*
2785  * Retrieve configuration from the registry for discovered children
2786  */
2788  &Context,
2789  DeviceNode,
2791  DeviceNode);
2792 
2794  if (!NT_SUCCESS(Status))
2795  {
2796  DPRINT("IopTraverseDeviceTree() failed with status 0x%08lx\n", Status);
2797  return Status;
2798  }
2799 
2800  /*
2801  * Initialize services for discovered children.
2802  */
2804  if (!NT_SUCCESS(Status))
2805  {
2806  DPRINT("IopInitializePnpServices() failed with status 0x%08lx\n", Status);
2807  return Status;
2808  }
2809 
2810  DPRINT("IopEnumerateDevice() finished\n");
2811  return STATUS_SUCCESS;
2812 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
ULONG Flags
Definition: iotypes.h:836
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2055
LONG NTSTATUS
Definition: precomp.h:26
static VOID IopHandleDeviceRemoval(IN PDEVICE_NODE DeviceNode, IN PDEVICE_RELATIONS DeviceRelations)
Definition: pnpmgr.c:2624
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
NTSTATUS IopCreateDeviceNode(PDEVICE_NODE ParentNode, PDEVICE_OBJECT PhysicalDeviceObject, PUNICODE_STRING ServiceName, PDEVICE_NODE *DeviceNode)
Definition: pnpmgr.c:1187
NTSTATUS IopActionConfigureChildServices(PDEVICE_NODE DeviceNode, PVOID Context)
Definition: pnpmgr.c:2832
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
NTSTATUS IopActionInterrogateDeviceStack(PDEVICE_NODE DeviceNode, PVOID Context)
Definition: pnpmgr.c:2355
struct _DEVICE_RELATIONS * PDEVICE_RELATIONS
smooth NULL
Definition: ftsmooth.c:416
#define DO_BUS_ENUMERATED_DEVICE
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS IopQueueTargetDeviceEvent(const GUID *Guid, PUNICODE_STRING DeviceIds)
Definition: plugplay.c:46
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define DNF_NEED_ENUMERATION_ONLY
Definition: iotypes.h:194
Definition: Node.h:9
PDEVICE_NODE FASTCALL IopGetDeviceNode(PDEVICE_OBJECT DeviceObject)
Definition: pnpmgr.c:66
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
NTSTATUS NTAPI IopInitiatePnpIrp(IN PDEVICE_OBJECT DeviceObject, IN OUT PIO_STATUS_BLOCK IoStatusBlock, IN UCHAR MinorFunction, IN PIO_STACK_LOCATION Stack OPTIONAL)
Definition: pnpmgr.c:1490
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define DPRINT1
Definition: precomp.h:8
#define IopInitDeviceTreeTraverseContext( _DeviceTreeTraverseContext, _DeviceNode, _Action, _Context)
Definition: io.h:225
struct tagContext Context
Definition: acpixf.h:1030
unsigned int ULONG
Definition: retypes.h:1
#define DNF_ENUMERATED
Definition: iotypes.h:170
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938
NTSTATUS IopInitializePnpServices(IN PDEVICE_NODE DeviceNode)
Definition: pnpmgr.c:3109
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
NTSTATUS IopTraverseDeviceTree(PDEVICETREE_TRAVERSE_CONTEXT Context)
Definition: pnpmgr.c:1570

Referenced by IoInitSystem(), IopPnpEnumerateDevice(), and IoSynchronousInvalidateDeviceRelations().

◆ IopFixupDeviceId()

VOID IopFixupDeviceId ( PWCHAR  String)

Definition at line 72 of file pnpmgr.c.

73 {
75 
76  for (i = 0; i < Length; i++)
77  {
78  if (String[i] == L'\\')
79  String[i] = L'#';
80  }
81 }
static WCHAR String[]
Definition: stringtable.c:55
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
static const WCHAR L[]
Definition: oid.c:1250
ULONG_PTR SIZE_T
Definition: typedefs.h:78
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by IopInstallCriticalDevice().

◆ IopFreeDeviceNode()

NTSTATUS IopFreeDeviceNode ( PDEVICE_NODE  DeviceNode)

Definition at line 1350 of file pnpmgr.c.

1351 {
1352  KIRQL OldIrql;
1353  PDEVICE_NODE PrevSibling = NULL;
1354 
1355  /* All children must be deleted before a parent is deleted */
1356  ASSERT(!DeviceNode->Child);
1357  ASSERT(DeviceNode->PhysicalDeviceObject);
1358 
1360 
1361  /* Get previous sibling */
1362  if (DeviceNode->Parent && DeviceNode->Parent->Child != DeviceNode)
1363  {
1364  PrevSibling = DeviceNode->Parent->Child;
1365  while (PrevSibling->Sibling != DeviceNode)
1366  PrevSibling = PrevSibling->Sibling;
1367  }
1368 
1369  /* Unlink from parent if it exists */
1370  if (DeviceNode->Parent)
1371  {
1372  if (DeviceNode->Parent->LastChild == DeviceNode)
1373  {
1374  DeviceNode->Parent->LastChild = PrevSibling;
1375  if (PrevSibling)
1376  PrevSibling->Sibling = NULL;
1377  }
1378  if (DeviceNode->Parent->Child == DeviceNode)
1379  DeviceNode->Parent->Child = DeviceNode->Sibling;
1380  }
1381 
1382  /* Unlink from sibling list */
1383  if (PrevSibling)
1384  PrevSibling->Sibling = DeviceNode->Sibling;
1385 
1387 
1388  RtlFreeUnicodeString(&DeviceNode->InstancePath);
1389 
1390  RtlFreeUnicodeString(&DeviceNode->ServiceName);
1391 
1392  if (DeviceNode->ResourceList)
1393  {
1394  ExFreePool(DeviceNode->ResourceList);
1395  }
1396 
1397  if (DeviceNode->ResourceListTranslated)
1398  {
1399  ExFreePool(DeviceNode->ResourceListTranslated);
1400  }
1401 
1402  if (DeviceNode->ResourceRequirements)
1403  {
1404  ExFreePool(DeviceNode->ResourceRequirements);
1405  }
1406 
1407  if (DeviceNode->BootResources)
1408  {
1409  ExFreePool(DeviceNode->BootResources);
1410  }
1411 
1412  ((PEXTENDED_DEVOBJ_EXTENSION)DeviceNode->PhysicalDeviceObject->DeviceObjectExtension)->DeviceNode = NULL;
1414 
1415  return STATUS_SUCCESS;
1416 }
#define TAG_IO_DEVNODE
Definition: tag.h:89
struct _EXTENDED_DEVOBJ_EXTENSION * PEXTENDED_DEVOBJ_EXTENSION
UCHAR KIRQL
Definition: env_spec_w32.h:591
smooth NULL
Definition: ftsmooth.c:416
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
Definition: Node.h:9
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
struct _DEVICE_NODE * Sibling
Definition: iotypes.h:823
KSPIN_LOCK IopDeviceTreeLock
Definition: pnpmgr.c:19
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

◆ IopGetBusTypeGuidIndex()

USHORT NTAPI IopGetBusTypeGuidIndex ( LPGUID  BusTypeGuid)

Definition at line 1106 of file pnpmgr.c.

1107 {
1108  USHORT i = 0, FoundIndex = 0xFFFF;
1109  ULONG NewSize;
1110  PVOID NewList;
1111 
1112  /* Acquire the lock */
1114 
1115  /* Loop all entries */
1116  while (i < PnpBusTypeGuidList->GuidCount)
1117  {
1118  /* Try to find a match */
1119  if (RtlCompareMemory(BusTypeGuid,
1121  sizeof(GUID)) == sizeof(GUID))
1122  {
1123  /* Found it */
1124  FoundIndex = i;
1125  goto Quickie;
1126  }
1127  i++;
1128  }
1129 
1130  /* Check if we have to grow the list */
1132  {
1133  /* Calculate the new size */
1134  NewSize = sizeof(IO_BUS_TYPE_GUID_LIST) +
1135  (sizeof(GUID) * PnpBusTypeGuidList->GuidCount);
1136 
1137  /* Allocate the new copy */
1138  NewList = ExAllocatePool(PagedPool, NewSize);
1139 
1140  if (!NewList)
1141  {
1142  /* Fail */
1144  goto Quickie;
1145  }
1146 
1147  /* Now copy them, decrease the size too */
1148  NewSize -= sizeof(GUID);
1150 
1151  /* Free the old list */
1153 
1154  /* Use the new buffer */
1155  PnpBusTypeGuidList = NewList;
1156  }
1157 
1158  /* Copy the new GUID */
1160  BusTypeGuid,
1161  sizeof(GUID));
1162 
1163  /* The new entry is the index */
1164  FoundIndex = (USHORT)PnpBusTypeGuidList->GuidCount;
1166 
1167 Quickie:
1169  return FoundIndex;
1170 }
GUID Guids[1]
Definition: io.h:440
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
PIO_BUS_TYPE_GUID_LIST PnpBusTypeGuidList
Definition: pnpmgr.c:35
FAST_MUTEX Lock
Definition: io.h:439
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
struct _IO_BUS_TYPE_GUID_LIST IO_BUS_TYPE_GUID_LIST
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
_Must_inspect_result_ _In_ USHORT NewSize
Definition: fltkernel.h:975
struct _GUID GUID
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
unsigned short USHORT
Definition: pedump.c:61
unsigned int ULONG
Definition: retypes.h:1
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465

Referenced by IopActionInterrogateDeviceStack().

◆ IopGetDeviceNode()

◆ IopGetDeviceObjectFromDeviceInstance()

PDEVICE_OBJECT IopGetDeviceObjectFromDeviceInstance ( PUNICODE_STRING  DeviceInstance)

Definition at line 148 of file plugplay.c.

149 {
150  if (IopRootDeviceNode == NULL)
151  return NULL;
152 
153  if (DeviceInstance == NULL ||
154  DeviceInstance->Length == 0)
155  {
157  {
160  }
161  else
162  return NULL;
163  }
164 
166 }
PDEVICE_OBJECT PhysicalDeviceObject
Definition: iotypes.h:839
PDEVICE_NODE IopRootDeviceNode
Definition: pnpmgr.c:18
static PDEVICE_OBJECT IopTraverseDeviceNode(PDEVICE_NODE Node, PUNICODE_STRING DeviceInstance)
Definition: plugplay.c:119
smooth NULL
Definition: ftsmooth.c:416
_In_ PNDIS_STRING DeviceInstance
Definition: ndis.h:5202
#define ObReferenceObject
Definition: obfuncs.h:204

Referenced by IopActionInterrogateDeviceStack(), IopDeviceStatus(), IopGetDeviceDepth(), IopGetDeviceProperty(), IopGetDeviceRelations(), IopGetInterfaceDeviceList(), IopGetRelatedDevice(), IopPnpEnumerateDevice(), and IopResetDevice().

◆ IopGetParentIdPrefix()

NTSTATUS IopGetParentIdPrefix ( PDEVICE_NODE  DeviceNode,
PUNICODE_STRING  ParentIdPrefix 
)

Definition at line 1850 of file pnpmgr.c.

1852 {
1853  const UNICODE_STRING EnumKeyPath = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum\\");
1854  ULONG KeyNameBufferLength;
1855  PKEY_VALUE_PARTIAL_INFORMATION ParentIdPrefixInformation = NULL;
1856  UNICODE_STRING KeyName = {0, 0, NULL};
1857  UNICODE_STRING KeyValue;
1859  HANDLE hKey = NULL;
1860  ULONG crc32;
1861  NTSTATUS Status;
1862 
1863  /* HACK: As long as some devices have a NULL device
1864  * instance path, the following test is required :(
1865  */
1866  if (DeviceNode->Parent->InstancePath.Length == 0)
1867  {
1868  DPRINT1("Parent of %wZ has NULL Instance path, please report!\n",
1869  &DeviceNode->InstancePath);
1870  return STATUS_UNSUCCESSFUL;
1871  }
1872 
1873  /* 1. Try to retrieve ParentIdPrefix from registry */
1874  KeyNameBufferLength = FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data) + sizeof(L"12345678&12345678");
1875  ParentIdPrefixInformation = ExAllocatePoolWithTag(PagedPool,
1876  KeyNameBufferLength + sizeof(UNICODE_NULL),
1877  TAG_IO);
1878  if (!ParentIdPrefixInformation)
1879  {
1881  }
1882 
1883  KeyName.Length = 0;
1884  KeyName.MaximumLength = EnumKeyPath.Length +
1885  DeviceNode->Parent->InstancePath.Length +
1886  sizeof(UNICODE_NULL);
1888  KeyName.MaximumLength,
1889  TAG_IO);
1890  if (!KeyName.Buffer)
1891  {
1893  goto cleanup;
1894  }
1895 
1896  RtlCopyUnicodeString(&KeyName, &EnumKeyPath);
1897  RtlAppendUnicodeStringToString(&KeyName, &DeviceNode->Parent->InstancePath);
1898 
1900  if (!NT_SUCCESS(Status))
1901  {
1902  goto cleanup;
1903  }
1904  RtlInitUnicodeString(&ValueName, L"ParentIdPrefix");
1905  Status = ZwQueryValueKey(hKey,
1906  &ValueName,
1908  ParentIdPrefixInformation,
1909  KeyNameBufferLength,
1910  &KeyNameBufferLength);
1911  if (NT_SUCCESS(Status))
1912  {
1913  if (ParentIdPrefixInformation->Type != REG_SZ)
1914  {
1916  }
1917  else
1918  {
1919  KeyValue.MaximumLength = (USHORT)ParentIdPrefixInformation->DataLength;
1920  KeyValue.Length = KeyValue.MaximumLength - sizeof(UNICODE_NULL);
1921  KeyValue.Buffer = (PWSTR)ParentIdPrefixInformation->Data;
1922  ASSERT(KeyValue.Buffer[KeyValue.Length / sizeof(WCHAR)] == UNICODE_NULL);
1923  }
1924  goto cleanup;
1925  }
1927  {
1928  /* FIXME how do we get here and why is ParentIdPrefixInformation valid? */
1929  KeyValue.MaximumLength = (USHORT)ParentIdPrefixInformation->DataLength;
1930  KeyValue.Length = KeyValue.MaximumLength - sizeof(UNICODE_NULL);
1931  KeyValue.Buffer = (PWSTR)ParentIdPrefixInformation->Data;
1932  ASSERT(KeyValue.Buffer[KeyValue.Length / sizeof(WCHAR)] == UNICODE_NULL);
1933  goto cleanup;
1934  }
1935 
1936  /* 2. Create the ParentIdPrefix value */
1937  crc32 = RtlComputeCrc32(0,
1938  (PUCHAR)DeviceNode->Parent->InstancePath.Buffer,
1939  DeviceNode->Parent->InstancePath.Length);
1940 
1941  RtlStringCbPrintfW((PWSTR)ParentIdPrefixInformation,
1942  KeyNameBufferLength,
1943  L"%lx&%lx",
1944  DeviceNode->Parent->Level,
1945  crc32);
1946  RtlInitUnicodeString(&KeyValue, (PWSTR)ParentIdPrefixInformation);
1947 
1948  /* 3. Try to write the ParentIdPrefix to registry */
1949  Status = ZwSetValueKey(hKey,
1950  &ValueName,
1951  0,
1952  REG_SZ,
1953  KeyValue.Buffer,
1954  ((ULONG)wcslen(KeyValue.Buffer) + 1) * sizeof(WCHAR));
1955 
1956 cleanup:
1957  if (NT_SUCCESS(Status))
1958  {
1959  /* Duplicate the string to return it */
1961  &KeyValue,
1962  ParentIdPrefix);
1963  }
1964  ExFreePoolWithTag(ParentIdPrefixInformation, TAG_IO);
1966  if (hKey != NULL)
1967  {
1968  ZwClose(hKey);
1969  }
1970  return Status;
1971 }
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define TAG_IO
Definition: tag.h:69
#define KEY_SET_VALUE
Definition: nt_native.h:1017
USHORT MaximumLength
Definition: env_spec_w32.h:370
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSTATUS NTAPI IopOpenRegistryKeyEx(PHANDLE KeyHandle, HANDLE ParentKey, PUNICODE_STRING Name, ACCESS_MASK DesiredAccess)
Definition: pnpmgr.c:3688
uint16_t * PWSTR
Definition: typedefs.h:54
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
uint32_t crc32
Definition: btrfs.c:4138
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
#define UNICODE_NULL
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTRSAFEVAPI RtlStringCbPrintfW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1173
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
Definition: green.h:15
Definition: Node.h:9
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSYSAPI NTSTATUS WINAPI RtlDuplicateUnicodeString(int, const UNICODE_STRING *, UNICODE_STRING *)
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
NTSYSAPI ULONG NTAPI RtlComputeCrc32(_In_ ULONG InitialCrc, _In_ PUCHAR Buffer, _In_ ULONG Length)
unsigned short USHORT
Definition: pedump.c:61
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
char * cleanup(char *str)
Definition: wpickclick.c:99
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define REG_SZ
Definition: layer.c:22

Referenced by IopCreateDeviceInstancePath().

◆ IopGetRegistryValue()

NTSTATUS NTAPI IopGetRegistryValue ( IN HANDLE  Handle,
IN PWSTR  ValueName,
OUT PKEY_VALUE_FULL_INFORMATION Information 
)

Definition at line 3839 of file pnpmgr.c.

3842 {
3843  UNICODE_STRING ValueString;
3844  NTSTATUS Status;
3845  PKEY_VALUE_FULL_INFORMATION FullInformation;
3846  ULONG Size;
3847  PAGED_CODE();
3848 
3849  RtlInitUnicodeString(&ValueString, ValueName);
3850 
3851  Status = ZwQueryValueKey(Handle,
3852  &ValueString,
3854  NULL,
3855  0,
3856  &Size);
3857  if ((Status != STATUS_BUFFER_OVERFLOW) &&
3859  {
3860  return Status;
3861  }
3862 
3863  FullInformation = ExAllocatePool(NonPagedPool, Size);