ReactOS  0.4.15-dev-1033-gd7d716a
pnpmgr.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for pnpmgr.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#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;}
 

Functions

VOID IopFixupDeviceId (PWCHAR String)
 
VOID NTAPI IopInstallCriticalDevice (PDEVICE_NODE DeviceNode)
 
NTSTATUS FASTCALL IopInitializeDevice (PDEVICE_NODE DeviceNode, PDRIVER_OBJECT DriverObject)
 
NTSTATUS IopGetSystemPowerDeviceObject (PDEVICE_OBJECT *DeviceObject)
 
USHORT NTAPI IopGetBusTypeGuidIndex (LPGUID BusTypeGuid)
 
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 NTAPI IopCreateDeviceKeyPath (IN PCUNICODE_STRING RegistryPath, IN ULONG CreateOptions, OUT PHANDLE Handle)
 
NTSTATUS IopSetDeviceInstanceData (HANDLE InstanceKey, PDEVICE_NODE DeviceNode)
 
NTSTATUS IopGetParentIdPrefix (PDEVICE_NODE DeviceNode, PUNICODE_STRING ParentIdPrefix)
 
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)
 
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)
 
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

NTSTATUS NTAPI IoOpenDeviceRegistryKey (IN PDEVICE_OBJECT DeviceObject, IN ULONG DevInstKeyType, IN ACCESS_MASK DesiredAccess, OUT PHANDLE DevInstRegKey)
 
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

ERESOURCE PpRegistryDeviceResource
 
KGUARDED_MUTEX PpDeviceReferenceTableLock
 
RTL_AVL_TABLE PpDeviceReferenceTable
 
BOOLEAN PnPBootDriversLoaded
 
ULONG ExpInitializationPhase
 
PDRIVER_OBJECT IopRootDriverObject
 
PIO_BUS_TYPE_GUID_LIST PnpBusTypeGuidList = NULL
 

Macro Definition Documentation

◆ 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 2080 of file pnpmgr.c.

◆ PIP_RETURN_DATA

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

Definition at line 2079 of file pnpmgr.c.

◆ PIP_UNIMPLEMENTED

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

Definition at line 2081 of file pnpmgr.c.

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 2088 of file pnpmgr.c.

2093 {
2095  DEVICE_CAPABILITIES DeviceCaps;
2096  ULONG ReturnLength = 0, Length = 0, ValueType;
2097  PWCHAR ValueName = NULL, EnumeratorNameEnd, DeviceInstanceName;
2098  PVOID Data = NULL;
2100  GUID BusTypeGuid;
2101  POBJECT_NAME_INFORMATION ObjectNameInfo = NULL;
2102  BOOLEAN NullTerminate = FALSE;
2103  DEVICE_REMOVAL_POLICY Policy;
2104 
2105  DPRINT("IoGetDeviceProperty(0x%p %d)\n", DeviceObject, DeviceProperty);
2106 
2107  /* Assume failure */
2108  *ResultLength = 0;
2109 
2110  /* Only PDOs can call this */
2112 
2113  /* Handle all properties */
2114  switch (DeviceProperty)
2115  {
2117 
2118  /* Get the GUID from the internal cache */
2119  Status = PnpBusTypeGuidGet(DeviceNode->ChildBusTypeIndex, &BusTypeGuid);
2120  if (!NT_SUCCESS(Status)) return Status;
2121 
2122  /* This is the format of the returned data */
2123  PIP_RETURN_DATA(sizeof(GUID), &BusTypeGuid);
2124 
2126 
2127  /* Validate correct interface type */
2128  if (DeviceNode->ChildInterfaceType == InterfaceTypeUndefined)
2130 
2131  /* This is the format of the returned data */
2132  PIP_RETURN_DATA(sizeof(INTERFACE_TYPE), &DeviceNode->ChildInterfaceType);
2133 
2135 
2136  /* Validate correct bus number */
2137  if ((DeviceNode->ChildBusNumber & 0x80000000) == 0x80000000)
2139 
2140  /* This is the format of the returned data */
2141  PIP_RETURN_DATA(sizeof(ULONG), &DeviceNode->ChildBusNumber);
2142 
2144 
2145  /* Get the instance path */
2146  DeviceInstanceName = DeviceNode->InstancePath.Buffer;
2147 
2148  /* Sanity checks */
2149  ASSERT((BufferLength & 1) == 0);
2150  ASSERT(DeviceInstanceName != NULL);
2151 
2152  /* Get the name from the path */
2153  EnumeratorNameEnd = wcschr(DeviceInstanceName, OBJ_NAME_PATH_SEPARATOR);
2154  ASSERT(EnumeratorNameEnd);
2155 
2156  /* This string needs to be NULL-terminated */
2157  NullTerminate = TRUE;
2158 
2159  /* This is the format of the returned data */
2160  PIP_RETURN_DATA((ULONG)(EnumeratorNameEnd - DeviceInstanceName) * sizeof(WCHAR),
2161  DeviceInstanceName);
2162 
2163  case DevicePropertyAddress:
2164 
2165  /* Query the device caps */
2167  if (!NT_SUCCESS(Status) || (DeviceCaps.Address == MAXULONG))
2169 
2170  /* This is the format of the returned data */
2171  PIP_RETURN_DATA(sizeof(ULONG), &DeviceCaps.Address);
2172 
2174 
2175  /* Validate we have resources */
2176  if (!DeviceNode->BootResources)
2177 // if (!DeviceNode->BootResourcesTranslated) // FIXFIX: Need this field
2178  {
2179  /* No resources will still fake success, but with 0 bytes */
2180  *ResultLength = 0;
2181  return STATUS_SUCCESS;
2182  }
2183 
2184  /* This is the format of the returned data */
2185  PIP_RETURN_DATA(PnpDetermineResourceListSize(DeviceNode->BootResources), // FIXFIX: Should use BootResourcesTranslated
2186  DeviceNode->BootResources); // FIXFIX: Should use BootResourcesTranslated
2187 
2189 
2190  /* Sanity check for Unicode-sized string */
2191  ASSERT((BufferLength & 1) == 0);
2192 
2193  /* Allocate name buffer */
2195  ObjectNameInfo = ExAllocatePool(PagedPool, Length);
2196  if (!ObjectNameInfo) return STATUS_INSUFFICIENT_RESOURCES;
2197 
2198  /* Query the PDO name */
2200  ObjectNameInfo,
2201  Length,
2202  ResultLength);
2204  {
2205  /* It's up to the caller to try again */
2207  }
2208 
2209  /* This string needs to be NULL-terminated */
2210  NullTerminate = TRUE;
2211 
2212  /* Return if successful */
2213  if (NT_SUCCESS(Status)) PIP_RETURN_DATA(ObjectNameInfo->Name.Length,
2214  ObjectNameInfo->Name.Buffer);
2215 
2216  /* Let the caller know how big the name is */
2218  break;
2219 
2221 
2222  Policy = DeviceNode->RemovalPolicy;
2223  PIP_RETURN_DATA(sizeof(Policy), &Policy);
2224 
2225  /* Handle the registry-based properties */
2249  //PIP_REGISTRY_DATA(REGSTR_VAL_CONTAINERID, REG_SZ); // Win7
2251  break;
2254  break;
2259  default:
2261  }
2262 
2263  /* Having a registry value name implies registry data */
2264  if (ValueName)
2265  {
2266  /* We know up-front how much data to expect */
2268 
2269  /* Go get the data, use the LogConf subkey if necessary */
2271  ValueType,
2272  ValueName,
2273  (DeviceProperty ==
2275  L"LogConf": NULL,
2276  PropertyBuffer,
2277  ResultLength);
2278  }
2279  else if (NT_SUCCESS(Status))
2280  {
2281  /* We know up-front how much data to expect, check the caller's buffer */
2282  *ResultLength = ReturnLength + (NullTerminate ? sizeof(UNICODE_NULL) : 0);
2283  if (*ResultLength <= BufferLength)
2284  {
2285  /* Buffer is all good, copy the data */
2286  RtlCopyMemory(PropertyBuffer, Data, ReturnLength);
2287 
2288  /* Check if we need to NULL-terminate the string */
2289  if (NullTerminate)
2290  {
2291  /* Terminate the string */
2292  ((PWCHAR)PropertyBuffer)[ReturnLength / sizeof(WCHAR)] = UNICODE_NULL;
2293  }
2294 
2295  /* This is the success path */
2297  }
2298  else
2299  {
2300  /* Failure path */
2302  }
2303  }
2304 
2305  /* Free any allocation we may have made, and return the status code */
2306  if (ObjectNameInfo) ExFreePool(ObjectNameInfo);
2307  return Status;
2308 }
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
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
#define TRUE
Definition: types.h:120
_In_ PCWSTR _In_z_ PCWSTR _In_ ULONG ValueType
Definition: rtlfuncs.h:4154
NTSTATUS NTAPI PnpBusTypeGuidGet(IN USHORT Index, IN LPGUID BusTypeGuid)
Definition: pnpmgr.c:1876
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:932
#define REGSTR_VAL_UI_NUMBER
Definition: regstr.h:426
uint16_t * PWCHAR
Definition: typedefs.h:56
#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:1997
#define REGSTR_VAL_COMPATIBLEIDS
Definition: regstr.h:296
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
#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:476
void DPRINT(...)
Definition: polytest.cpp:61
#define REG_RESOURCE_LIST
Definition: nt_native.h:1502
#define PIP_UNIMPLEMENTED()
Definition: pnpmgr.c:2081
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ UCHAR BufferLength
Definition: scsi.h:4067
#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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
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:2080
ULONG NTAPI PnpDetermineResourceListSize(IN PCM_RESOURCE_LIST ResourceList)
Definition: pnpmgr.c:1943
#define REGSTR_VAL_HARDWAREID
Definition: regstr.h:485
#define REGSTR_VAL_DEVDESC
Definition: regstr.h:292
#define MAXULONG
Definition: typedefs.h:251
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
#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
NTSTATUS NTAPI IopQueryDeviceCapabilities(PDEVICE_NODE DeviceNode, PDEVICE_CAPABILITIES DeviceCaps)
Definition: devaction.c:329
enum _DEVICE_REMOVAL_POLICY DEVICE_REMOVAL_POLICY
#define PIP_RETURN_DATA(x, y)
Definition: pnpmgr.c:2079
unsigned int ULONG
Definition: retypes.h:1
#define REGSTR_VAL_BOOTCONFIG
Definition: regstr.h:293
return STATUS_SUCCESS
Definition: btrfs.c:3014
#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
PDEVICE_NODE FASTCALL IopGetDeviceNode(IN PDEVICE_OBJECT DeviceObject)
#define REG_SZ
Definition: layer.c:22

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

◆ IoInvalidateDeviceRelations()

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

Definition at line 2478 of file pnpmgr.c.

2481 {
2483  {
2484  KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, 0x2, (ULONG_PTR)DeviceObject, 0, 0);
2485  }
2486 
2487  switch (Type)
2488  {
2489  case BusRelations:
2490  /* Enumerate the device */
2492  break;
2493  default:
2494  /* Everything else is not implemented */
2495  break;
2496  }
2497 }
Type
Definition: Type.h:6
VOID PiQueueDeviceAction(_In_ PDEVICE_OBJECT DeviceObject, _In_ DEVICE_ACTION Action, _In_opt_ PKEVENT CompletionEvent, _Out_opt_ NTSTATUS *CompletionStatus)
Queue a device operation to a worker thread.
Definition: devaction.c:2472
uint32_t ULONG_PTR
Definition: typedefs.h:65
smooth NULL
Definition: ftsmooth.c:416
#define IopIsValidPhysicalDeviceObject(PhysicalDeviceObject)
Definition: io.h:238
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG _In_ LONG _In_ LONG x2
Definition: winddi.h:3706
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:108

Referenced by _Function_class_(), add_volume_device(), ClassDeviceControl(), ClassInterpretSenseInfo(), DiskIoctlGetLengthInfo(), FDO_StartDevice(), HalpReportDetectedDevices(), IopStartAndEnumerateDevice(), IsaPdoStartReadPort(), KsCreateBusEnumObject(), KspBusWorkerRoutine(), KspInstallBusEnumInterface(), KsServiceBusEnumCreateRequest(), PipResetDevice(), RamdiskCreateRamdisk(), remove_volume_child(), ReportGreenPdo(), USBH_ProcessPortStateChange(), USBHUB_RootHubCallBack(), and VideoPortEnumerateChildren().

◆ IoOpenDeviceRegistryKey()

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

Definition at line 2327 of file pnpmgr.c.

2331 {
2332  static WCHAR RootKeyName[] =
2333  L"\\Registry\\Machine\\System\\CurrentControlSet\\";
2334  static WCHAR ProfileKeyName[] =
2335  L"Hardware Profiles\\Current\\System\\CurrentControlSet\\";
2336  static WCHAR ClassKeyName[] = L"Control\\Class\\";
2337  static WCHAR EnumKeyName[] = L"Enum\\";
2338  static WCHAR DeviceParametersKeyName[] = L"Device Parameters";
2340  PWSTR KeyNameBuffer;
2342  ULONG DriverKeyLength;
2345  NTSTATUS Status;
2346 
2347  DPRINT("IoOpenDeviceRegistryKey() called\n");
2348 
2350  {
2351  DPRINT1("IoOpenDeviceRegistryKey(): got wrong params, exiting... \n");
2352  return STATUS_INVALID_PARAMETER;
2353  }
2354 
2358 
2359  /*
2360  * Calculate the length of the base key name. This is the full
2361  * name for driver key or the name excluding "Device Parameters"
2362  * subkey for device key.
2363  */
2364 
2365  KeyNameLength = sizeof(RootKeyName);
2367  KeyNameLength += sizeof(ProfileKeyName) - sizeof(UNICODE_NULL);
2369  {
2370  KeyNameLength += sizeof(ClassKeyName) - sizeof(UNICODE_NULL);
2372  0, NULL, &DriverKeyLength);
2374  return Status;
2375  KeyNameLength += DriverKeyLength;
2376  }
2377  else
2378  {
2379  KeyNameLength += sizeof(EnumKeyName) - sizeof(UNICODE_NULL) +
2380  DeviceNode->InstancePath.Length;
2381  }
2382 
2383  /*
2384  * Now allocate the buffer for the key name...
2385  */
2386 
2387  KeyNameBuffer = ExAllocatePool(PagedPool, KeyNameLength);
2388  if (KeyNameBuffer == NULL)
2390 
2391  KeyName.Length = 0;
2392  KeyName.MaximumLength = (USHORT)KeyNameLength;
2393  KeyName.Buffer = KeyNameBuffer;
2394 
2395  /*
2396  * ...and build the key name.
2397  */
2398 
2399  KeyName.Length += sizeof(RootKeyName) - sizeof(UNICODE_NULL);
2400  RtlCopyMemory(KeyNameBuffer, RootKeyName, KeyName.Length);
2401 
2403  RtlAppendUnicodeToString(&KeyName, ProfileKeyName);
2404 
2406  {
2407  RtlAppendUnicodeToString(&KeyName, ClassKeyName);
2409  DriverKeyLength, KeyNameBuffer +
2410  (KeyName.Length / sizeof(WCHAR)),
2411  &DriverKeyLength);
2412  if (!NT_SUCCESS(Status))
2413  {
2414  DPRINT1("Call to IoGetDeviceProperty() failed with Status 0x%08lx\n", Status);
2415  ExFreePool(KeyNameBuffer);
2416  return Status;
2417  }
2418  KeyName.Length += (USHORT)DriverKeyLength - sizeof(UNICODE_NULL);
2419  }
2420  else
2421  {
2422  RtlAppendUnicodeToString(&KeyName, EnumKeyName);
2424  if (DeviceNode->InstancePath.Length == 0)
2425  {
2426  ExFreePool(KeyNameBuffer);
2427  return Status;
2428  }
2429  }
2430 
2431  /*
2432  * Open the base key.
2433  */
2435  if (!NT_SUCCESS(Status))
2436  {
2437  DPRINT1("IoOpenDeviceRegistryKey(%wZ): Base key doesn't exist, exiting... (Status 0x%08lx)\n", &KeyName, Status);
2438  ExFreePool(KeyNameBuffer);
2439  return Status;
2440  }
2441  ExFreePool(KeyNameBuffer);
2442 
2443  /*
2444  * For driver key we're done now.
2445  */
2446 
2448  return Status;
2449 
2450  /*
2451  * Let's go further. For device key we must open "Device Parameters"
2452  * subkey and create it if it doesn't exist yet.
2453  */
2454 
2455  RtlInitUnicodeString(&KeyName, DeviceParametersKeyName);
2457  &KeyName,
2459  *DevInstRegKey,
2460  NULL);
2461  Status = ZwCreateKey(DevInstRegKey,
2462  DesiredAccess,
2464  0,
2465  NULL,
2467  NULL);
2468  ZwClose(ObjectAttributes.RootDirectory);
2469 
2470  return Status;
2471 }
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 OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define PLUGPLAY_REGKEY_DEVICE
Definition: iofuncs.h:2782
#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:1591
uint16_t * PWSTR
Definition: typedefs.h:56
_In_ ULONG DevInstKeyType
Definition: iofuncs.h:1123
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#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:2088
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
Definition: Node.h:9
Status
Definition: gdiplustypes.h:24
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:208
_In_ ULONG _In_ ACCESS_MASK _Out_ PHANDLE DevInstRegKey
Definition: iofuncs.h:1123
#define IopIsValidPhysicalDeviceObject(PhysicalDeviceObject)
Definition: io.h:238
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
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:4137
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 ExFreePool(addr)
Definition: env_spec_w32.h:352
#define PLUGPLAY_REGKEY_CURRENT_HWPROFILE
Definition: iofuncs.h:2784
PDEVICE_NODE FASTCALL IopGetDeviceNode(IN PDEVICE_OBJECT DeviceObject)

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

◆ IopCreateDeviceKeyPath()

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

Definition at line 666 of file pnpmgr.c.

669 {
671  HANDLE hParent = NULL, hKey;
674  PCWSTR Current, Last;
675  USHORT Length;
677 
678  /* Assume failure */
679  *Handle = NULL;
680 
681  /* Open root key for device instances */
683  if (!NT_SUCCESS(Status))
684  {
685  DPRINT1("ZwOpenKey('%wZ') failed with status 0x%08lx\n", &EnumU, Status);
686  return Status;
687  }
688 
689  Current = KeyName.Buffer = RegistryPath->Buffer;
690  Last = &RegistryPath->Buffer[RegistryPath->Length / sizeof(WCHAR)];
691 
692  /* Go up to the end of the string */
693  while (Current <= Last)
694  {
695  if (Current != Last && *Current != L'\\')
696  {
697  /* Not the end of the string and not a separator */
698  Current++;
699  continue;
700  }
701 
702  /* Prepare relative key name */
703  Length = (USHORT)((ULONG_PTR)Current - (ULONG_PTR)KeyName.Buffer);
704  KeyName.MaximumLength = KeyName.Length = Length;
705  DPRINT("Create '%wZ'\n", &KeyName);
706 
707  /* Open key */
709  &KeyName,
711  hParent,
712  NULL);
713  Status = ZwCreateKey(&hKey,
714  Current == Last ? KEY_ALL_ACCESS : KEY_CREATE_SUB_KEY,
716  0,
717  NULL,
719  NULL);
720 
721  /* Close parent key handle, we don't need it anymore */
722  if (hParent)
723  ZwClose(hParent);
724 
725  /* Key opening/creating failed? */
726  if (!NT_SUCCESS(Status))
727  {
728  DPRINT1("ZwCreateKey('%wZ') failed with status 0x%08lx\n", &KeyName, Status);
729  return Status;
730  }
731 
732  /* Check if it is the end of the string */
733  if (Current == Last)
734  {
735  /* Yes, return success */
736  *Handle = hKey;
737  return STATUS_SUCCESS;
738  }
739 
740  /* Start with this new parent key */
741  hParent = hKey;
742  Current++;
743  KeyName.Buffer = (PWSTR)Current;
744  }
745 
746  return STATUS_UNSUCCESSFUL;
747 }
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:57
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSTATUS NTAPI IopOpenRegistryKeyEx(PHANDLE KeyHandle, HANDLE ParentKey, PUNICODE_STRING Name, ACCESS_MASK DesiredAccess)
Definition: pnpmgr.c:1591
uint16_t * PWSTR
Definition: typedefs.h:56
LONG NTSTATUS
Definition: precomp.h:26
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
uint32_t ULONG_PTR
Definition: typedefs.h:65
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
_In_ HANDLE Handle
Definition: extypes.h:390
_In_z_ PWSTR RegistryPath
Definition: classp.h:1930
__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 STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
const DOCKBAR PVOID HWND hParent
Definition: tooldock.h:22
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
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1018
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

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

◆ 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 1616 of file pnpmgr.c.

1622 {
1624  ULONG KeyDisposition, RootHandleIndex = 0, i = 1, NestedCloseLevel = 0;
1625  USHORT Length;
1626  HANDLE HandleArray[2];
1627  BOOLEAN Recursing = TRUE;
1628  PWCHAR pp, p, p1;
1629  UNICODE_STRING KeyString;
1631  PAGED_CODE();
1632 
1633  /* P1 is start, pp is end */
1634  p1 = KeyName->Buffer;
1635  pp = (PVOID)((ULONG_PTR)p1 + KeyName->Length);
1636 
1637  /* Create the target key */
1639  KeyName,
1641  RootHandle,
1642  NULL);
1643  Status = ZwCreateKey(&HandleArray[i],
1644  DesiredAccess,
1646  0,
1647  NULL,
1648  CreateOptions,
1649  &KeyDisposition);
1650 
1651  /* Now we check if this failed */
1652  if ((Status == STATUS_OBJECT_NAME_NOT_FOUND) && (RootHandle))
1653  {
1654  /* Target key failed, so we'll need to create its parent. Setup array */
1655  HandleArray[0] = NULL;
1656  HandleArray[1] = RootHandle;
1657 
1658  /* Keep recursing for each missing parent */
1659  while (Recursing)
1660  {
1661  /* And if we're deep enough, close the last handle */
1662  if (NestedCloseLevel > 1) ZwClose(HandleArray[RootHandleIndex]);
1663 
1664  /* We're setup to ping-pong between the two handle array entries */
1665  RootHandleIndex = i;
1666  i = (i + 1) & 1;
1667 
1668  /* Clear the one we're attempting to open now */
1669  HandleArray[i] = NULL;
1670 
1671  /* Process the parent key name */
1672  for (p = p1; ((p < pp) && (*p != OBJ_NAME_PATH_SEPARATOR)); p++);
1673  Length = (USHORT)(p - p1) * sizeof(WCHAR);
1674 
1675  /* Is there a parent name? */
1676  if (Length)
1677  {
1678  /* Build the unicode string for it */
1679  KeyString.Buffer = p1;
1680  KeyString.Length = KeyString.MaximumLength = Length;
1681 
1682  /* Now try opening the parent */
1684  &KeyString,
1686  HandleArray[RootHandleIndex],
1687  NULL);
1688  Status = ZwCreateKey(&HandleArray[i],
1689  DesiredAccess,
1691  0,
1692  NULL,
1693  CreateOptions,
1694  &KeyDisposition);
1695  if (NT_SUCCESS(Status))
1696  {
1697  /* It worked, we have one more handle */
1698  NestedCloseLevel++;
1699  }
1700  else
1701  {
1702  /* Parent key creation failed, abandon loop */
1703  Recursing = FALSE;
1704  continue;
1705  }
1706  }
1707  else
1708  {
1709  /* We don't have a parent name, probably corrupted key name */
1711  Recursing = FALSE;
1712  continue;
1713  }
1714 
1715  /* Now see if there's more parents to create */
1716  p1 = p + 1;
1717  if ((p == pp) || (p1 == pp))
1718  {
1719  /* We're done, hopefully successfully, so stop */
1720  Recursing = FALSE;
1721  }
1722  }
1723 
1724  /* Outer loop check for handle nesting that requires closing the top handle */
1725  if (NestedCloseLevel > 1) ZwClose(HandleArray[RootHandleIndex]);
1726  }
1727 
1728  /* Check if we broke out of the loop due to success */
1729  if (NT_SUCCESS(Status))
1730  {
1731  /* Return the target handle (we closed all the parent ones) and disposition */
1732  *Handle = HandleArray[i];
1733  if (Disposition) *Disposition = KeyDisposition;
1734  }
1735 
1736  /* Return the success state */
1737  return Status;
1738 }
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 OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define TRUE
Definition: types.h:120
#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:56
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:50
uint32_t ULONG_PTR
Definition: typedefs.h:65
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 FALSE
Definition: types.h:117
#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
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:4137
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:3014
#define PAGED_CODE()

◆ 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 1030 of file pnpmgr.c.

1037 {
1038  UNICODE_STRING IdentifierU = RTL_CONSTANT_STRING(L"Identifier");
1039  UNICODE_STRING HardwareIDU = RTL_CONSTANT_STRING(L"HardwareID");
1040  UNICODE_STRING ConfigurationDataU = RTL_CONSTANT_STRING(L"Configuration Data");
1041  UNICODE_STRING BootConfigU = RTL_CONSTANT_STRING(L"BootConfig");
1042  UNICODE_STRING LogConfU = RTL_CONSTANT_STRING(L"LogConf");
1044  HANDLE hDevicesKey = NULL;
1045  HANDLE hDeviceKey = NULL;
1046  HANDLE hLevel1Key, hLevel2Key = NULL, hLogConf;
1047  UNICODE_STRING Level2NameU;
1048  WCHAR Level2Name[5];
1049  ULONG IndexDevice = 0;
1050  ULONG IndexSubKey;
1051  PKEY_BASIC_INFORMATION pDeviceInformation = NULL;
1052  ULONG DeviceInfoLength = sizeof(KEY_BASIC_INFORMATION) + 50 * sizeof(WCHAR);
1053  PKEY_VALUE_PARTIAL_INFORMATION pValueInformation = NULL;
1054  ULONG ValueInfoLength = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 50 * sizeof(WCHAR);
1057  PCM_FULL_RESOURCE_DESCRIPTOR BootResources = NULL;
1058  ULONG BootResourcesLength;
1059  NTSTATUS Status;
1060 
1061  const UNICODE_STRING IdentifierSerial = RTL_CONSTANT_STRING(L"SerialController");
1062  UNICODE_STRING HardwareIdSerial = RTL_CONSTANT_STRING(L"*PNP0501\0");
1063  static ULONG DeviceIndexSerial = 0;
1064  const UNICODE_STRING IdentifierKeyboard = RTL_CONSTANT_STRING(L"KeyboardController");
1065  UNICODE_STRING HardwareIdKeyboard = RTL_CONSTANT_STRING(L"*PNP0303\0");
1066  static ULONG DeviceIndexKeyboard = 0;
1067  const UNICODE_STRING IdentifierMouse = RTL_CONSTANT_STRING(L"PointerController");
1068  UNICODE_STRING HardwareIdMouse = RTL_CONSTANT_STRING(L"*PNP0F13\0");
1069  static ULONG DeviceIndexMouse = 0;
1070  const UNICODE_STRING IdentifierParallel = RTL_CONSTANT_STRING(L"ParallelController");
1071  UNICODE_STRING HardwareIdParallel = RTL_CONSTANT_STRING(L"*PNP0400\0");
1072  static ULONG DeviceIndexParallel = 0;
1073  const UNICODE_STRING IdentifierFloppy = RTL_CONSTANT_STRING(L"FloppyDiskPeripheral");
1074  UNICODE_STRING HardwareIdFloppy = RTL_CONSTANT_STRING(L"*PNP0700\0");
1075  static ULONG DeviceIndexFloppy = 0;
1076  UNICODE_STRING HardwareIdKey;
1077  PUNICODE_STRING pHardwareId;
1078  ULONG DeviceIndex = 0;
1079  PUCHAR CmResourceList;
1080  ULONG ListCount;
1081 
1082  if (RelativePath)
1083  {
1084  Status = IopOpenRegistryKeyEx(&hDevicesKey, hBaseKey, RelativePath, KEY_ENUMERATE_SUB_KEYS);
1085  if (!NT_SUCCESS(Status))
1086  {
1087  DPRINT("ZwOpenKey() failed with status 0x%08lx\n", Status);
1088  goto cleanup;
1089  }
1090  }
1091  else
1092  hDevicesKey = hBaseKey;
1093 
1094  pDeviceInformation = ExAllocatePool(PagedPool, DeviceInfoLength);
1095  if (!pDeviceInformation)
1096  {
1097  DPRINT("ExAllocatePool() failed\n");
1099  goto cleanup;
1100  }
1101 
1102  pValueInformation = ExAllocatePool(PagedPool, ValueInfoLength);
1103  if (!pValueInformation)
1104  {
1105  DPRINT("ExAllocatePool() failed\n");
1107  goto cleanup;
1108  }
1109 
1110  while (TRUE)
1111  {
1112  Status = ZwEnumerateKey(hDevicesKey, IndexDevice, KeyBasicInformation, pDeviceInformation, DeviceInfoLength, &RequiredSize);
1114  break;
1116  {
1117  ExFreePool(pDeviceInformation);
1118  DeviceInfoLength = RequiredSize;
1119  pDeviceInformation = ExAllocatePool(PagedPool, DeviceInfoLength);
1120  if (!pDeviceInformation)
1121  {
1122  DPRINT("ExAllocatePool() failed\n");
1124  goto cleanup;
1125  }
1126  Status = ZwEnumerateKey(hDevicesKey, IndexDevice, KeyBasicInformation, pDeviceInformation, DeviceInfoLength, &RequiredSize);
1127  }
1128  if (!NT_SUCCESS(Status))
1129  {
1130  DPRINT("ZwEnumerateKey() failed with status 0x%08lx\n", Status);
1131  goto cleanup;
1132  }
1133  IndexDevice++;
1134 
1135  /* Open device key */
1136  DeviceName.Length = DeviceName.MaximumLength = (USHORT)pDeviceInformation->NameLength;
1137  DeviceName.Buffer = pDeviceInformation->Name;
1138 
1139  Status = IopOpenRegistryKeyEx(&hDeviceKey, hDevicesKey, &DeviceName,
1140  KEY_QUERY_VALUE + (EnumerateSubKeys ? KEY_ENUMERATE_SUB_KEYS : 0));
1141  if (!NT_SUCCESS(Status))
1142  {
1143  DPRINT("ZwOpenKey() failed with status 0x%08lx\n", Status);
1144  goto cleanup;
1145  }
1146 
1147  /* Read boot resources, and add then to parent ones */
1148  Status = ZwQueryValueKey(hDeviceKey, &ConfigurationDataU, KeyValuePartialInformation, pValueInformation, ValueInfoLength, &RequiredSize);
1150  {
1151  ExFreePool(pValueInformation);
1152  ValueInfoLength = RequiredSize;
1153  pValueInformation = ExAllocatePool(PagedPool, ValueInfoLength);
1154  if (!pValueInformation)
1155  {
1156  DPRINT("ExAllocatePool() failed\n");
1157  ZwDeleteKey(hLevel2Key);
1159  goto cleanup;
1160  }
1161  Status = ZwQueryValueKey(hDeviceKey, &ConfigurationDataU, KeyValuePartialInformation, pValueInformation, ValueInfoLength, &RequiredSize);
1162  }
1164  {
1165  BootResources = ParentBootResources;
1166  BootResourcesLength = ParentBootResourcesLength;
1167  }
1168  else if (!NT_SUCCESS(Status))
1169  {
1170  DPRINT("ZwQueryValueKey() failed with status 0x%08lx\n", Status);
1171  goto nextdevice;
1172  }
1173  else if (pValueInformation->Type != REG_FULL_RESOURCE_DESCRIPTOR)
1174  {
1175  DPRINT("Wrong registry type: got 0x%lx, expected 0x%lx\n", pValueInformation->Type, REG_FULL_RESOURCE_DESCRIPTOR);
1176  goto nextdevice;
1177  }
1178  else
1179  {
1180  static const ULONG Header = FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList.PartialDescriptors);
1181 
1182  /* Concatenate current resources and parent ones */
1183  if (ParentBootResourcesLength == 0)
1184  BootResourcesLength = pValueInformation->DataLength;
1185  else
1186  BootResourcesLength = ParentBootResourcesLength
1187  + pValueInformation->DataLength
1188  - Header;
1189  BootResources = ExAllocatePool(PagedPool, BootResourcesLength);
1190  if (!BootResources)
1191  {
1192  DPRINT("ExAllocatePool() failed\n");
1193  goto nextdevice;
1194  }
1195  if (ParentBootResourcesLength < sizeof(CM_FULL_RESOURCE_DESCRIPTOR))
1196  {
1197  RtlCopyMemory(BootResources, pValueInformation->Data, pValueInformation->DataLength);
1198  }
1199  else if (ParentBootResources->PartialResourceList.PartialDescriptors[ParentBootResources->PartialResourceList.Count - 1].Type == CmResourceTypeDeviceSpecific)
1200  {
1201  RtlCopyMemory(BootResources, pValueInformation->Data, pValueInformation->DataLength);
1202  RtlCopyMemory(
1203  (PVOID)((ULONG_PTR)BootResources + pValueInformation->DataLength),
1204  (PVOID)((ULONG_PTR)ParentBootResources + Header),
1205  ParentBootResourcesLength - Header);
1206  BootResources->PartialResourceList.Count += ParentBootResources->PartialResourceList.Count;
1207  }
1208  else
1209  {
1210  RtlCopyMemory(BootResources, pValueInformation->Data, Header);
1211  RtlCopyMemory(
1212  (PVOID)((ULONG_PTR)BootResources + Header),
1213  (PVOID)((ULONG_PTR)ParentBootResources + Header),
1214  ParentBootResourcesLength - Header);
1215  RtlCopyMemory(
1216  (PVOID)((ULONG_PTR)BootResources + ParentBootResourcesLength),
1217  pValueInformation->Data + Header,
1218  pValueInformation->DataLength - Header);
1219  BootResources->PartialResourceList.Count += ParentBootResources->PartialResourceList.Count;
1220  }
1221  }
1222 
1223  if (EnumerateSubKeys)
1224  {
1225  IndexSubKey = 0;
1226  while (TRUE)
1227  {
1228  Status = ZwEnumerateKey(hDeviceKey, IndexSubKey, KeyBasicInformation, pDeviceInformation, DeviceInfoLength, &RequiredSize);
1230  break;
1232  {
1233  ExFreePool(pDeviceInformation);
1234  DeviceInfoLength = RequiredSize;
1235  pDeviceInformation = ExAllocatePool(PagedPool, DeviceInfoLength);
1236  if (!pDeviceInformation)
1237  {
1238  DPRINT("ExAllocatePool() failed\n");
1240  goto cleanup;
1241  }
1242  Status = ZwEnumerateKey(hDeviceKey, IndexSubKey, KeyBasicInformation, pDeviceInformation, DeviceInfoLength, &RequiredSize);
1243  }
1244  if (!NT_SUCCESS(Status))
1245  {
1246  DPRINT("ZwEnumerateKey() failed with status 0x%08lx\n", Status);
1247  goto cleanup;
1248  }
1249  IndexSubKey++;
1250  DeviceName.Length = DeviceName.MaximumLength = (USHORT)pDeviceInformation->NameLength;
1251  DeviceName.Buffer = pDeviceInformation->Name;
1252 
1254  hDeviceKey,
1255  &DeviceName,
1256  hRootKey,
1257  TRUE,
1258  BootResources,
1259  BootResourcesLength);
1260  if (!NT_SUCCESS(Status))
1261  goto cleanup;
1262  }
1263  }
1264 
1265  /* Read identifier */
1266  Status = ZwQueryValueKey(hDeviceKey, &IdentifierU, KeyValuePartialInformation, pValueInformation, ValueInfoLength, &RequiredSize);
1268  {
1269  ExFreePool(pValueInformation);
1270  ValueInfoLength = RequiredSize;
1271  pValueInformation = ExAllocatePool(PagedPool, ValueInfoLength);
1272  if (!pValueInformation)
1273  {
1274  DPRINT("ExAllocatePool() failed\n");
1276  goto cleanup;
1277  }
1278  Status = ZwQueryValueKey(hDeviceKey, &IdentifierU, KeyValuePartialInformation, pValueInformation, ValueInfoLength, &RequiredSize);
1279  }
1280  if (!NT_SUCCESS(Status))
1281  {
1283  {
1284  DPRINT("ZwQueryValueKey() failed with status 0x%08lx\n", Status);
1285  goto nextdevice;
1286  }
1288  }
1289  else if (pValueInformation->Type != REG_SZ)
1290  {
1291  DPRINT("Wrong registry type: got 0x%lx, expected 0x%lx\n", pValueInformation->Type, REG_SZ);
1292  goto nextdevice;
1293  }
1294  else
1295  {
1296  /* Assign hardware id to this device */
1297  ValueName.Length = ValueName.MaximumLength = (USHORT)pValueInformation->DataLength;
1298  ValueName.Buffer = (PWCHAR)pValueInformation->Data;
1299  if (ValueName.Length >= sizeof(WCHAR) && ValueName.Buffer[ValueName.Length / sizeof(WCHAR) - 1] == UNICODE_NULL)
1300  ValueName.Length -= sizeof(WCHAR);
1301  }
1302 
1303  if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierSerial, FALSE) == 0)
1304  {
1305  pHardwareId = &HardwareIdSerial;
1306  DeviceIndex = DeviceIndexSerial++;
1307  }
1308  else if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierKeyboard, FALSE) == 0)
1309  {
1310  pHardwareId = &HardwareIdKeyboard;
1311  DeviceIndex = DeviceIndexKeyboard++;
1312  }
1313  else if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierMouse, FALSE) == 0)
1314  {
1315  pHardwareId = &HardwareIdMouse;
1316  DeviceIndex = DeviceIndexMouse++;
1317  }
1318  else if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierParallel, FALSE) == 0)
1319  {
1320  pHardwareId = &HardwareIdParallel;
1321  DeviceIndex = DeviceIndexParallel++;
1322  }
1323  else if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierFloppy, FALSE) == 0)
1324  {
1325  pHardwareId = &HardwareIdFloppy;
1326  DeviceIndex = DeviceIndexFloppy++;
1327  }
1328  else
1329  {
1330  /* Unknown key path */
1331  DPRINT("Unknown key path '%wZ'\n", RelativePath);
1332  goto nextdevice;
1333  }
1334 
1335  /* Prepare hardware id key (hardware id value without final \0) */
1336  HardwareIdKey = *pHardwareId;
1337  HardwareIdKey.Length -= sizeof(UNICODE_NULL);
1338 
1339  /* Add the detected device to Root key */
1340  InitializeObjectAttributes(&ObjectAttributes, &HardwareIdKey, OBJ_KERNEL_HANDLE, hRootKey, NULL);
1341  Status = ZwCreateKey(
1342  &hLevel1Key,
1345  0,
1346  NULL,
1348  NULL);
1349  if (!NT_SUCCESS(Status))
1350  {
1351  DPRINT("ZwCreateKey() failed with status 0x%08lx\n", Status);
1352  goto nextdevice;
1353  }
1354  swprintf(Level2Name, L"%04lu", DeviceIndex);
1355  RtlInitUnicodeString(&Level2NameU, Level2Name);
1356  InitializeObjectAttributes(&ObjectAttributes, &Level2NameU, OBJ_KERNEL_HANDLE, hLevel1Key, NULL);
1357  Status = ZwCreateKey(
1358  &hLevel2Key,
1361  0,
1362  NULL,
1364  NULL);
1365  ZwClose(hLevel1Key);
1366  if (!NT_SUCCESS(Status))
1367  {
1368  DPRINT("ZwCreateKey() failed with status 0x%08lx\n", Status);
1369  goto nextdevice;
1370  }
1371  DPRINT("Found %wZ #%lu (%wZ)\n", &ValueName, DeviceIndex, &HardwareIdKey);
1372  Status = ZwSetValueKey(hLevel2Key, &HardwareIDU, 0, REG_MULTI_SZ, pHardwareId->Buffer, pHardwareId->MaximumLength);
1373  if (!NT_SUCCESS(Status))
1374  {
1375  DPRINT("ZwSetValueKey() failed with status 0x%08lx\n", Status);
1376  ZwDeleteKey(hLevel2Key);
1377  goto nextdevice;
1378  }
1379  /* Create 'LogConf' subkey */
1381  Status = ZwCreateKey(
1382  &hLogConf,
1383  KEY_SET_VALUE,
1385  0,
1386  NULL,
1388  NULL);
1389  if (!NT_SUCCESS(Status))
1390  {
1391  DPRINT("ZwCreateKey() failed with status 0x%08lx\n", Status);
1392  ZwDeleteKey(hLevel2Key);
1393  goto nextdevice;
1394  }
1395  if (BootResourcesLength >= sizeof(CM_FULL_RESOURCE_DESCRIPTOR))
1396  {
1397  CmResourceList = ExAllocatePool(PagedPool, BootResourcesLength + sizeof(ULONG));
1398  if (!CmResourceList)
1399  {
1400  ZwClose(hLogConf);
1401  ZwDeleteKey(hLevel2Key);
1402  goto nextdevice;
1403  }
1404 
1405  /* Add the list count (1st member of CM_RESOURCE_LIST) */
1406  ListCount = 1;
1407  RtlCopyMemory(CmResourceList,
1408  &ListCount,
1409  sizeof(ULONG));
1410 
1411  /* Now add the actual list (2nd member of CM_RESOURCE_LIST) */
1412  RtlCopyMemory(CmResourceList + sizeof(ULONG),
1413  BootResources,
1414  BootResourcesLength);
1415 
1416  /* Save boot resources to 'LogConf\BootConfig' */
1417  Status = ZwSetValueKey(hLogConf, &BootConfigU, 0, REG_RESOURCE_LIST, CmResourceList, BootResourcesLength + sizeof(ULONG));
1418  if (!NT_SUCCESS(Status))
1419  {
1420  DPRINT("ZwSetValueKey() failed with status 0x%08lx\n", Status);
1421  ZwClose(hLogConf);
1422  ZwDeleteKey(hLevel2Key);
1423  goto nextdevice;
1424  }
1425  }
1426  ZwClose(hLogConf);
1427 
1428 nextdevice:
1429  if (BootResources && BootResources != ParentBootResources)
1430  {
1431  ExFreePool(BootResources);
1432  BootResources = NULL;
1433  }
1434  if (hLevel2Key)
1435  {
1436  ZwClose(hLevel2Key);
1437  hLevel2Key = NULL;
1438  }
1439  if (hDeviceKey)
1440  {
1441  ZwClose(hDeviceKey);
1442  hDeviceKey = NULL;
1443  }
1444  }
1445 
1447 
1448 cleanup:
1449  if (hDevicesKey && hDevicesKey != hBaseKey)
1450  ZwClose(hDevicesKey);
1451  if (hDeviceKey)
1452  ZwClose(hDeviceKey);
1453  if (pDeviceInformation)
1454  ExFreePool(pDeviceInformation);
1455  if (pValueInformation)
1456  ExFreePool(pValueInformation);
1457  return Status;
1458 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define CmResourceTypeDeviceSpecific
Definition: hwresource.cpp:127
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:205
#define KEY_SET_VALUE
Definition: nt_native.h:1017
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSTATUS NTAPI IopOpenRegistryKeyEx(PHANDLE KeyHandle, HANDLE ParentKey, PUNICODE_STRING Name, ACCESS_MASK DesiredAccess)
Definition: pnpmgr.c:1591
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
struct _KEY_BASIC_INFORMATION KEY_BASIC_INFORMATION
_Inout_ PRTL_BUFFER _In_ SIZE_T RequiredSize
uint16_t * PWCHAR
Definition: typedefs.h:56
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
uint32_t ULONG_PTR
Definition: typedefs.h:65
CM_PARTIAL_RESOURCE_LIST PartialResourceList
Definition: hwresource.cpp:160
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
#define FALSE
Definition: types.h:117
#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
#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
Status
Definition: gdiplustypes.h:24
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
#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:260
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
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:1030
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1018
#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().

◆ IopFixupDeviceId()

VOID IopFixupDeviceId ( PWCHAR  String)

Definition at line 33 of file pnpmgr.c.

34 {
36 
37  for (i = 0; i < Length; i++)
38  {
39  if (String[i] == L'\\')
40  String[i] = L'#';
41  }
42 }
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:80
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by IopInstallCriticalDevice().

◆ IopGetBusTypeGuidIndex()

USHORT NTAPI IopGetBusTypeGuidIndex ( LPGUID  BusTypeGuid)

Definition at line 481 of file pnpmgr.c.

482 {
483  USHORT i = 0, FoundIndex = 0xFFFF;
484  ULONG NewSize;
485  PVOID NewList;
486 
487  /* Acquire the lock */
489 
490  /* Loop all entries */
491  while (i < PnpBusTypeGuidList->GuidCount)
492  {
493  /* Try to find a match */
494  if (RtlCompareMemory(BusTypeGuid,
496  sizeof(GUID)) == sizeof(GUID))
497  {
498  /* Found it */
499  FoundIndex = i;
500  goto Quickie;
501  }
502  i++;
503  }
504 
505  /* Check if we have to grow the list */
507  {
508  /* Calculate the new size */
509  NewSize = sizeof(IO_BUS_TYPE_GUID_LIST) +
510  (sizeof(GUID) * PnpBusTypeGuidList->GuidCount);
511 
512  /* Allocate the new copy */
513  NewList = ExAllocatePool(PagedPool, NewSize);
514 
515  if (!NewList)
516  {
517  /* Fail */
519  goto Quickie;
520  }
521 
522  /* Now copy them, decrease the size too */
523  NewSize -= sizeof(GUID);
525 
526  /* Free the old list */
528 
529  /* Use the new buffer */
530  PnpBusTypeGuidList = NewList;
531  }
532 
533  /* Copy the new GUID */
535  BusTypeGuid,
536  sizeof(GUID));
537 
538  /* The new entry is the index */
539  FoundIndex = (USHORT)PnpBusTypeGuidList->GuidCount;
541 
542 Quickie:
544  return FoundIndex;
545 }
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:28
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().

◆ IopGetParentIdPrefix()

NTSTATUS IopGetParentIdPrefix ( PDEVICE_NODE  DeviceNode,
PUNICODE_STRING  ParentIdPrefix 
)

Definition at line 904 of file pnpmgr.c.

906 {
907  const UNICODE_STRING EnumKeyPath = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum\\");
908  ULONG KeyNameBufferLength;
909  PKEY_VALUE_PARTIAL_INFORMATION ParentIdPrefixInformation = NULL;
910  UNICODE_STRING KeyName = {0, 0, NULL};
911  UNICODE_STRING KeyValue;
913  HANDLE hKey = NULL;
914  ULONG crc32;
916 
917  /* HACK: As long as some devices have a NULL device
918  * instance path, the following test is required :(
919  */
920  if (DeviceNode->Parent->InstancePath.Length == 0)
921  {
922  DPRINT1("Parent of %wZ has NULL Instance path, please report!\n",
923  &DeviceNode->InstancePath);
924  return STATUS_UNSUCCESSFUL;
925  }
926 
927  /* 1. Try to retrieve ParentIdPrefix from registry */
928  KeyNameBufferLength = FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data) + sizeof(L"12345678&12345678");
929  ParentIdPrefixInformation = ExAllocatePoolWithTag(PagedPool,
930  KeyNameBufferLength + sizeof(UNICODE_NULL),
931  TAG_IO);
932  if (!ParentIdPrefixInformation)
933  {
935  }
936 
937  KeyName.Length = 0;
938  KeyName.MaximumLength = EnumKeyPath.Length +
939  DeviceNode->Parent->InstancePath.Length +
940  sizeof(UNICODE_NULL);
942  KeyName.MaximumLength,
943  TAG_IO);
944  if (!KeyName.Buffer)
945  {
947  goto cleanup;
948  }
949 
950  RtlCopyUnicodeString(&KeyName, &EnumKeyPath);
951  RtlAppendUnicodeStringToString(&KeyName, &DeviceNode->Parent->InstancePath);
952 
954  if (!NT_SUCCESS(Status))
955  {
956  goto cleanup;
957  }
958  RtlInitUnicodeString(&ValueName, L"ParentIdPrefix");
959  Status = ZwQueryValueKey(hKey,
960  &ValueName,
962  ParentIdPrefixInformation,
963  KeyNameBufferLength,
964  &KeyNameBufferLength);
965  if (NT_SUCCESS(Status))
966  {
967  if (ParentIdPrefixInformation->Type != REG_SZ)
968  {
970  }
971  else
972  {
973  KeyValue.MaximumLength = (USHORT)ParentIdPrefixInformation->DataLength;
974  KeyValue.Length = KeyValue.MaximumLength - sizeof(UNICODE_NULL);
975  KeyValue.Buffer = (PWSTR)ParentIdPrefixInformation->Data;
976  ASSERT(KeyValue.Buffer[KeyValue.Length / sizeof(WCHAR)] == UNICODE_NULL);
977  }
978  goto cleanup;
979  }
981  {
982  /* FIXME how do we get here and why is ParentIdPrefixInformation valid? */
983  KeyValue.MaximumLength = (USHORT)ParentIdPrefixInformation->DataLength;
984  KeyValue.Length = KeyValue.MaximumLength - sizeof(UNICODE_NULL);
985  KeyValue.Buffer = (PWSTR)ParentIdPrefixInformation->Data;
986  ASSERT(KeyValue.Buffer[KeyValue.Length / sizeof(WCHAR)] == UNICODE_NULL);
987  goto cleanup;
988  }
989 
990  /* 2. Create the ParentIdPrefix value */
992  (PUCHAR)DeviceNode->Parent->InstancePath.Buffer,
993  DeviceNode->Parent->InstancePath.Length);
994 
995  RtlStringCbPrintfW((PWSTR)ParentIdPrefixInformation,
996  KeyNameBufferLength,
997  L"%lx&%lx",
998  DeviceNode->Parent->Level,
999  crc32);
1000  RtlInitUnicodeString(&KeyValue, (PWSTR)ParentIdPrefixInformation);
1001 
1002  /* 3. Try to write the ParentIdPrefix to registry */
1003  Status = ZwSetValueKey(hKey,
1004  &ValueName,
1005  0,
1006  REG_SZ,
1007  KeyValue.Buffer,
1008  ((ULONG)wcslen(KeyValue.Buffer) + 1) * sizeof(WCHAR));
1009 
1010 cleanup:
1011  if (NT_SUCCESS(Status))
1012  {
1013  /* Duplicate the string to return it */
1015  &KeyValue,
1016  ParentIdPrefix);
1017  }
1018  ExFreePoolWithTag(ParentIdPrefixInformation, TAG_IO);
1020  if (hKey != NULL)
1021  {
1022  ZwClose(hKey);
1023  }
1024  return Status;
1025 }
_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:1591
uint16_t * PWSTR
Definition: typedefs.h:56
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
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
#define RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
Definition: isapnp.h:82
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSYSAPI NTSTATUS WINAPI RtlDuplicateUnicodeString(int, const UNICODE_STRING *, UNICODE_STRING *)
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)
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
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
#define RtlComputeCrc32
Definition: compat.h:558
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
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:255
#define DPRINT1
Definition: precomp.h:8
#define crc32(crc, buf, len)
Definition: inflate.c:1081
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 1742 of file pnpmgr.c.

1745 {
1746  UNICODE_STRING ValueString;
1747  NTSTATUS Status;
1748  PKEY_VALUE_FULL_INFORMATION FullInformation;
1749  ULONG Size;
1750  PAGED_CODE();
1751 
1752  RtlInitUnicodeString(&ValueString, ValueName);
1753 
1754  Status = ZwQueryValueKey(Handle,
1755  &ValueString,
1757  NULL,
1758  0,
1759  &Size);
1760  if ((Status != STATUS_BUFFER_OVERFLOW) &&
1762  {
1763  return Status;
1764  }
1765 
1766  FullInformation = ExAllocatePool(NonPagedPool, Size);
1767  if (!FullInformation) return STATUS_INSUFFICIENT_RESOURCES;
1768 
1769  Status = ZwQueryValueKey(Handle,
1770  &ValueString,
1772  FullInformation,
1773  Size,
1774  &Size);
1775  if (!NT_SUCCESS(Status))
1776  {
1777  ExFreePool(FullInformation);
1778  return Status;
1779  }
1780 
1781  *Information = FullInformation;
1782  return STATUS_SUCCESS;
1783 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG NTSTATUS
Definition: precomp.h:26
Iosb Information
Definition: create.c:4353
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
smooth NULL
Definition: ftsmooth.c:416
_In_ HANDLE Handle
Definition: extypes.h:390
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define PAGED_CODE()

Referenced by IopSetServiceEnumData(), PiGetDeviceRegistryProperty(), PiInitCacheGroupInformation(), PipCallDriverAddDevice(), PipGetDriverTagPriority(), and PpInitGetGroupOrderIndex().

◆ IopGetSystemPowerDeviceObject()

NTSTATUS IopGetSystemPowerDeviceObject ( PDEVICE_OBJECT DeviceObject)

Definition at line 463 of file pnpmgr.c.

464 {
465  KIRQL OldIrql;
466 
468  {
472 
473  return STATUS_SUCCESS;
474  }
475 
476  return STATUS_UNSUCCESSFUL;
477 }
PDEVICE_OBJECT PhysicalDeviceObject
Definition: iotypes.h:839
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
PDEVICE_NODE PopSystemPowerDeviceNode
Definition: power.c:25
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
KSPIN_LOCK IopDeviceTreeLock
Definition: devnode.c:19
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ IopInitializeDevice()

NTSTATUS FASTCALL IopInitializeDevice ( PDEVICE_NODE  DeviceNode,
PDRIVER_OBJECT  DriverObject 
)

Definition at line 395 of file pnpmgr.c.

397 {
398  PDEVICE_OBJECT Fdo;
400 
401  if (!DriverObject)
402  {
403  /* Special case for bus driven devices */
404  DeviceNode->Flags |= DNF_ADDED;
405  return STATUS_SUCCESS;
406  }
407 
409  {
410  DeviceNode->Flags |= DNF_LEGACY_DRIVER;
411  }
412 
413  if (DeviceNode->Flags & DNF_LEGACY_DRIVER)
414  {
415  DeviceNode->Flags |= (DNF_ADDED | DNF_STARTED);
416  return STATUS_SUCCESS;
417  }
418 
419  /* This is a Plug and Play driver */
420  DPRINT("Plug and Play driver found\n");
421  ASSERT(DeviceNode->PhysicalDeviceObject);
422 
423  DPRINT("Calling %wZ->AddDevice(%wZ)\n",
425  &DeviceNode->InstancePath);
427  DeviceNode->PhysicalDeviceObject);
428  if (!NT_SUCCESS(Status))
429  {
430  DPRINT1("%wZ->AddDevice(%wZ) failed with status 0x%x\n",
432  &DeviceNode->InstancePath,
433  Status);
435  DeviceNode->Problem = CM_PROB_FAILED_ADD;
436  return Status;
437  }
438 
439  Fdo = IoGetAttachedDeviceReference(DeviceNode->PhysicalDeviceObject);
440 
441  /* Check if we have a ACPI device (needed for power management) */
442  if (Fdo->DeviceType == FILE_DEVICE_ACPI)
443  {
444  static BOOLEAN SystemPowerDeviceNodeCreated = FALSE;
445 
446  /* There can be only one system power device */
447  if (!SystemPowerDeviceNodeCreated)
448  {
451  SystemPowerDeviceNodeCreated = TRUE;
452  }
453  }
454 
455  ObDereferenceObject(Fdo);
456 
458 
459  return STATUS_SUCCESS;
460 }
PDEVICE_OBJECT PhysicalDeviceObject
Definition: iotypes.h:839
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define FALSE
Definition: types.h:117
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2181
#define IopDeviceNodeSetFlag(DeviceNode, Flag)
Definition: io.h:142
unsigned char BOOLEAN
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
void DPRINT(...)
Definition: polytest.cpp:61
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
#define DNF_STARTED
Definition: iotypes.h:168
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PDEVICE_NODE PopSystemPowerDeviceNode
Definition: power.c:25
Definition: Node.h:9
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
#define DNF_LEGACY_DRIVER
Definition: iotypes.h:181
#define DNF_DISABLED
Definition: iotypes.h:188
PDRIVER_ADD_DEVICE AddDevice
Definition: iotypes.h:2119
#define DPRINT1
Definition: precomp.h:8
#define ObReferenceObject
Definition: obfuncs.h:204
#define FILE_DEVICE_ACPI
Definition: winioctl.h:155
#define CM_PROB_FAILED_ADD
Definition: cfg.h:61
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define DNF_ADDED
Definition: iotypes.h:179
UNICODE_STRING DriverName
Definition: iotypes.h:2182

◆ IopInitiatePnpIrp()

NTSTATUS NTAPI IopInitiatePnpIrp ( IN PDEVICE_OBJECT  DeviceObject,
IN OUT PIO_STATUS_BLOCK  IoStatusBlock,
IN UCHAR  MinorFunction,
IN PIO_STACK_LOCATION Stack  OPTIONAL 
)

Definition at line 623 of file pnpmgr.c.

627 {
628  IO_STACK_LOCATION IoStackLocation;
629 
630  /* Fill out the stack information */
631  RtlZeroMemory(&IoStackLocation, sizeof(IO_STACK_LOCATION));
632  IoStackLocation.MajorFunction = IRP_MJ_PNP;
633  IoStackLocation.MinorFunction = MinorFunction;
634  if (Stack)
635  {
636  /* Copy the rest */
637  RtlCopyMemory(&IoStackLocation.Parameters,
638  &Stack->Parameters,
639  sizeof(Stack->Parameters));
640  }
641 
642  /* Do the PnP call */
644  &IoStackLocation,
646  return IoStatusBlock->Status;
647 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
NTSTATUS NTAPI IopSynchronousCall(IN PDEVICE_OBJECT DeviceObject, IN PIO_STACK_LOCATION IoStackLocation, OUT PVOID *Information)
Definition: pnpmgr.c:549
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
_In_ UCHAR MinorFunction
Definition: pofuncs.h:42
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2779

◆ IopInstallCriticalDevice()

VOID NTAPI IopInstallCriticalDevice ( PDEVICE_NODE  DeviceNode)

Definition at line 46 of file pnpmgr.c.

47 {
49  HANDLE CriticalDeviceKey, InstanceKey;
51  UNICODE_STRING CriticalDeviceKeyU = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\CriticalDeviceDatabase");
52  UNICODE_STRING CompatibleIdU = RTL_CONSTANT_STRING(L"CompatibleIDs");
53  UNICODE_STRING HardwareIdU = RTL_CONSTANT_STRING(L"HardwareID");
54  UNICODE_STRING ServiceU = RTL_CONSTANT_STRING(L"Service");
55  UNICODE_STRING ClassGuidU = RTL_CONSTANT_STRING(L"ClassGUID");
57  ULONG HidLength = 0, CidLength = 0, BufferLength;
58  PWCHAR IdBuffer, OriginalIdBuffer;
59 
60  /* Open the device instance key */
61  Status = IopCreateDeviceKeyPath(&DeviceNode->InstancePath, REG_OPTION_NON_VOLATILE, &InstanceKey);
62  if (Status != STATUS_SUCCESS)
63  return;
64 
65  Status = ZwQueryValueKey(InstanceKey,
66  &HardwareIdU,
68  NULL,
69  0,
70  &HidLength);
72  {
73  ZwClose(InstanceKey);
74  return;
75  }
76 
77  Status = ZwQueryValueKey(InstanceKey,
78  &CompatibleIdU,
80  NULL,
81  0,
82  &CidLength);
84  {
85  CidLength = 0;
86  }
87 
88  BufferLength = HidLength + CidLength;
89  BufferLength -= (((CidLength != 0) ? 2 : 1) * FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data));
90 
91  /* Allocate a buffer to hold data from both */
92  OriginalIdBuffer = IdBuffer = ExAllocatePool(PagedPool, BufferLength);
93  if (!IdBuffer)
94  {
95  ZwClose(InstanceKey);
96  return;
97  }
98 
99  /* Compute the buffer size */
100  if (HidLength > CidLength)
101  BufferLength = HidLength;
102  else
103  BufferLength = CidLength;
104 
105  PartialInfo = ExAllocatePool(PagedPool, BufferLength);
106  if (!PartialInfo)
107  {
108  ZwClose(InstanceKey);
109  ExFreePool(OriginalIdBuffer);
110  return;
111  }
112 
113  Status = ZwQueryValueKey(InstanceKey,
114  &HardwareIdU,
116  PartialInfo,
117  HidLength,
118  &HidLength);
119  if (Status != STATUS_SUCCESS)
120  {
121  ExFreePool(PartialInfo);
122  ExFreePool(OriginalIdBuffer);
123  ZwClose(InstanceKey);
124  return;
125  }
126 
127  /* Copy in HID info first (without 2nd terminating NULL if CID is present) */
128  HidLength = PartialInfo->DataLength - ((CidLength != 0) ? sizeof(WCHAR) : 0);
129  RtlCopyMemory(IdBuffer, PartialInfo->Data, HidLength);
130 
131  if (CidLength != 0)
132  {
133  Status = ZwQueryValueKey(InstanceKey,
134  &CompatibleIdU,
136  PartialInfo,
137  CidLength,
138  &CidLength);
139  if (Status != STATUS_SUCCESS)
140  {
141  ExFreePool(PartialInfo);
142  ExFreePool(OriginalIdBuffer);
143  ZwClose(InstanceKey);
144  return;
145  }
146 
147  /* Copy CID next */
148  CidLength = PartialInfo->DataLength;
149  RtlCopyMemory(((PUCHAR)IdBuffer) + HidLength, PartialInfo->Data, CidLength);
150  }
151 
152  /* Free our temp buffer */
153  ExFreePool(PartialInfo);
154 
156  &CriticalDeviceKeyU,
158  NULL,
159  NULL);
160  Status = ZwOpenKey(&CriticalDeviceKey,
163  if (!NT_SUCCESS(Status))
164  {
165  /* The critical device database doesn't exist because
166  * we're probably in 1st stage setup, but it's ok */
167  ExFreePool(OriginalIdBuffer);
168  ZwClose(InstanceKey);
169  return;
170  }
171 
172  while (*IdBuffer)
173  {
174  USHORT StringLength = (USHORT)wcslen(IdBuffer) + 1, Index;
175 
176  IopFixupDeviceId(IdBuffer);
177 
178  /* Look through all subkeys for a match */
179  for (Index = 0; TRUE; Index++)
180  {
181  ULONG NeededLength;
182  PKEY_BASIC_INFORMATION BasicInfo;
183 
184  Status = ZwEnumerateKey(CriticalDeviceKey,
185  Index,
187  NULL,
188  0,
189  &NeededLength);
191  break;
193  {
194  UNICODE_STRING ChildIdNameU, RegKeyNameU;
195 
196  BasicInfo = ExAllocatePool(PagedPool, NeededLength);
197  if (!BasicInfo)
198  {
199  /* No memory */
200  ExFreePool(OriginalIdBuffer);
201  ZwClose(CriticalDeviceKey);
202  ZwClose(InstanceKey);
203  return;
204  }
205 
206  Status = ZwEnumerateKey(CriticalDeviceKey,
207  Index,
209  BasicInfo,
210  NeededLength,
211  &NeededLength);
212  if (Status != STATUS_SUCCESS)
213  {
214  /* This shouldn't happen */
215  ExFreePool(BasicInfo);
216  continue;
217  }
218 
219  ChildIdNameU.Buffer = IdBuffer;
220  ChildIdNameU.MaximumLength = ChildIdNameU.Length = (StringLength - 1) * sizeof(WCHAR);
221  RegKeyNameU.Buffer = BasicInfo->Name;
222  RegKeyNameU.MaximumLength = RegKeyNameU.Length = (USHORT)BasicInfo->NameLength;
223 
224  if (RtlEqualUnicodeString(&ChildIdNameU, &RegKeyNameU, TRUE))
225  {
226  HANDLE ChildKeyHandle;
227 
229  &ChildIdNameU,
231  CriticalDeviceKey,
232  NULL);
233 
234  Status = ZwOpenKey(&ChildKeyHandle,
237  if (Status != STATUS_SUCCESS)
238  {
239  ExFreePool(BasicInfo);
240  continue;
241  }
242 
243  /* Check if there's already a driver installed */
244  Status = ZwQueryValueKey(InstanceKey,
245  &ClassGuidU,
247  NULL,
248  0,
249  &NeededLength);
251  {
252  ExFreePool(BasicInfo);
253  continue;
254  }
255 
256  Status = ZwQueryValueKey(ChildKeyHandle,
257  &ClassGuidU,
259  NULL,
260  0,
261  &NeededLength);
263  {
264  ExFreePool(BasicInfo);
265  continue;
266  }
267 
268  PartialInfo = ExAllocatePool(PagedPool, NeededLength);
269  if (!PartialInfo)
270  {
271  ExFreePool(OriginalIdBuffer);
272  ExFreePool(BasicInfo);
273  ZwClose(InstanceKey);
274  ZwClose(ChildKeyHandle);
275  ZwClose(CriticalDeviceKey);
276  return;
277  }
278 
279  /* Read ClassGUID entry in the CDDB */
280  Status = ZwQueryValueKey(ChildKeyHandle,
281  &ClassGuidU,
283  PartialInfo,
284  NeededLength,
285  &NeededLength);
286  if (Status != STATUS_SUCCESS)
287  {
288  ExFreePool(BasicInfo);
289  continue;
290  }
291 
292  /* Write it to the ENUM key */
293  Status = ZwSetValueKey(InstanceKey,
294  &ClassGuidU,
295  0,
296  REG_SZ,
297  PartialInfo->Data,
298  PartialInfo->DataLength);
299  if (Status != STATUS_SUCCESS)
300  {
301  ExFreePool(BasicInfo);
302  ExFreePool(PartialInfo);
303  ZwClose(ChildKeyHandle);
304  continue;
305  }
306 
307  Status = ZwQueryValueKey(ChildKeyHandle,
308  &ServiceU,
310  NULL,
311  0,
312  &NeededLength);
314  {
315  ExFreePool(PartialInfo);
316  PartialInfo = ExAllocatePool(PagedPool, NeededLength);
317  if (!PartialInfo)
318  {
319  ExFreePool(OriginalIdBuffer);
320  ExFreePool(BasicInfo);
321  ZwClose(InstanceKey);
322  ZwClose(ChildKeyHandle);
323  ZwClose(CriticalDeviceKey);
324  return;
325  }
326 
327  /* Read the service entry from the CDDB */
328  Status = ZwQueryValueKey(ChildKeyHandle,
329  &ServiceU,
331  PartialInfo,
332  NeededLength,
333  &NeededLength);
334  if (Status != STATUS_SUCCESS)
335  {
336  ExFreePool(BasicInfo);
337  ExFreePool(PartialInfo);
338  ZwClose(ChildKeyHandle);
339  continue;
340  }
341 
342  /* Write it to the ENUM key */
343  Status = ZwSetValueKey(InstanceKey,
344  &ServiceU,
345  0,
346  REG_SZ,
347  PartialInfo->Data,
348  PartialInfo->DataLength);
349  if (Status != STATUS_SUCCESS)
350  {
351  ExFreePool(BasicInfo);
352  ExFreePool(PartialInfo);
353  ZwClose(ChildKeyHandle);
354  continue;
355  }
356 
357  DPRINT("Installed service '%S' for critical device '%wZ'\n", PartialInfo->Data, &ChildIdNameU);
358  }
359  else
360  {
361  DPRINT1("Installed NULL service for critical device '%wZ'\n", &ChildIdNameU);
362  }
363 
364  ExFreePool(OriginalIdBuffer);
365  ExFreePool(PartialInfo);
366  ExFreePool(BasicInfo);
367  ZwClose(InstanceKey);
368  ZwClose(ChildKeyHandle);
369  ZwClose(CriticalDeviceKey);
370 
371  /* That's it */
372  return;
373  }
374 
375  ExFreePool(BasicInfo);
376  }
377  else
378  {
379  /* Umm, not sure what happened here */
380  continue;
381  }
382  }
383 
384  /* Advance to the next ID */
385  IdBuffer += StringLength;
386  }
387 
388  ExFreePool(OriginalIdBuffer);
389  ZwClose(InstanceKey);
390  ZwClose(CriticalDeviceKey);
391 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:205
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
unsigned char * PUCHAR
Definition: retypes.h:3
NTSTATUS NTAPI IopCreateDeviceKeyPath(IN PCUNICODE_STRING RegistryPath, IN ULONG CreateOptions, OUT PHANDLE Handle)
Definition: pnpmgr.c:666
LONG NTSTATUS
Definition: precomp.h:26
uint16_t * PWCHAR
Definition: typedefs.h:56
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
if(!(yy_init))
Definition: macro.lex.yy.c:714
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ UCHAR BufferLength
Definition: scsi.h:4067
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const UCHAR Index[8]
Definition: usbohci.c:18
Definition: Node.h:9
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
VOID IopFixupDeviceId(PWCHAR String)
Definition: pnpmgr.c:33
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
unsigned short USHORT
Definition: pedump.c:61
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
return STATUS_SUCCESS
Definition: btrfs.c:3014
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#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 IopActionConfigureChildServices().

◆ IopIsFirmwareMapperDisabled()

static INIT_FUNCTION BOOLEAN IopIsFirmwareMapperDisabled ( VOID  )
static

Definition at line 1463 of file pnpmgr.c.

1464 {
1465  UNICODE_STRING KeyPathU = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM\\CURRENTCONTROLSET\\Control\\Pnp");
1466  UNICODE_STRING KeyNameU = RTL_CONSTANT_STRING(L"DisableFirmwareMapper");
1468  HANDLE hPnpKey;
1469  PKEY_VALUE_PARTIAL_INFORMATION KeyInformation;
1470  ULONG DesiredLength, Length;
1471  ULONG KeyValue = 0;
1472  NTSTATUS Status;
1473 
1475  Status = ZwOpenKey(&hPnpKey, KEY_QUERY_VALUE, &ObjectAttributes);
1476  if (NT_SUCCESS(Status))
1477  {
1478  Status = ZwQueryValueKey(hPnpKey,
1479  &KeyNameU,
1481  NULL,
1482  0,
1483  &DesiredLength);
1484  if ((Status == STATUS_BUFFER_TOO_SMALL) ||
1486  {
1487  Length = DesiredLength;
1488  KeyInformation = ExAllocatePool(PagedPool, Length);
1489  if (KeyInformation)
1490  {
1491  Status = ZwQueryValueKey(hPnpKey,
1492  &KeyNameU,
1494  KeyInformation,
1495  Length,
1496  &DesiredLength);
1497  if (NT_SUCCESS(Status) && KeyInformation->DataLength == sizeof(ULONG))
1498  {
1499  KeyValue = (ULONG)(*KeyInformation->Data);
1500  }
1501  else
1502  {
1503  DPRINT1("ZwQueryValueKey(%wZ%wZ) failed\n", &KeyPathU, &KeyNameU);
1504  }
1505 
1506  ExFreePool(KeyInformation);
1507  }
1508  else
1509  {
1510  DPRINT1("Failed to allocate memory for registry query\n");
1511  }
1512  }
1513  else
1514  {
1515  DPRINT1("ZwQueryValueKey(%wZ%wZ) failed with status 0x%08lx\n", &KeyPathU, &KeyNameU, Status);
1516  }
1517 
1518  ZwClose(hPnpKey);
1519  }
1520  else
1521  {
1522  DPRINT1("ZwOpenKey(%wZ) failed with status 0x%08lx\n", &KeyPathU, Status);
1523  }
1524 
1525  DPRINT("Firmware mapper is %s\n", KeyValue != 0 ? "disabled" : "enabled");
1526 
1527  return (KeyValue != 0) ? TRUE : FALSE;
1528 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by IopUpdateRootKey().

◆ IopOpenRegistryKeyEx()

NTSTATUS NTAPI IopOpenRegistryKeyEx ( PHANDLE  KeyHandle,
HANDLE  ParentKey,
PUNICODE_STRING  Name,
ACCESS_MASK  DesiredAccess 
)

Definition at line 1591 of file pnpmgr.c.

1595 {
1597  NTSTATUS Status;
1598 
1599  PAGED_CODE();
1600 
1601  *KeyHandle = NULL;
1602 
1604  Name,
1606  ParentKey,
1607  NULL);
1608 
1610 
1611  return Status;
1612 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
LONG NTSTATUS
Definition: precomp.h:26
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
smooth NULL
Definition: ftsmooth.c:416
Status
Definition: gdiplustypes.h:24
_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:4137
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define PAGED_CODE()

Referenced by CreateDeviceFromRegistry(), EnumerateDevices(), IoOpenDeviceRegistryKey(), IopCreateDeviceKeyPath(), IopEnumerateDetectedDevices(), IopGetParentIdPrefix(), IopInitializeBootDrivers(), IopInitializePlugPlayServices(), IopLoadServiceModule(), IopSetServiceEnumData(), IopStoreSystemPartitionInformation(), IopUpdateControlKeyWithResources(), IopUpdateRootKey(), IoSetSystemPartition(), PiGetDeviceRegistryProperty(), PiInitCacheGroupInformation(), PipCallDriverAddDevice(), PipGetDriverTagPriority(), PnpDeviceObjectToDeviceInstance(), and PnpRootCreateDevice().

◆ IopSetDeviceInstanceData()

NTSTATUS IopSetDeviceInstanceData ( HANDLE  InstanceKey,
PDEVICE_NODE  DeviceNode 
)

Definition at line 750 of file pnpmgr.c.

752 {
755  HANDLE LogConfKey, ControlKey, DeviceParamsKey;
756  ULONG ResCount;
759 
760  DPRINT("IopSetDeviceInstanceData() called\n");
761 
762  /* Create the 'LogConf' key */
763  RtlInitUnicodeString(&KeyName, L"LogConf");
765  &KeyName,
767  InstanceKey,
768  NULL);
769  Status = ZwCreateKey(&LogConfKey,
772  0,
773  NULL,
774  // FIXME? In r53694 it was silently turned from non-volatile into this,
775  // without any extra warning. Is this still needed??
777  NULL);
778  if (NT_SUCCESS(Status))
779  {
780  /* Set 'BootConfig' value */
781  if (DeviceNode->BootResources != NULL)
782  {
783  ResCount = DeviceNode->BootResources->Count;
784  if (ResCount != 0)
785  {
786  RtlInitUnicodeString(&KeyName, L"BootConfig");
787  Status = ZwSetValueKey(LogConfKey,
788  &KeyName,
789  0,
791  DeviceNode->BootResources,
792  PnpDetermineResourceListSize(DeviceNode->BootResources));
793  }
794  }
795 
796  /* Set 'BasicConfigVector' value */
797  if (DeviceNode->ResourceRequirements != NULL &&
798  DeviceNode->ResourceRequirements->ListSize != 0)
799  {
800  RtlInitUnicodeString(&KeyName, L"BasicConfigVector");
801  Status = ZwSetValueKey(LogConfKey,
802  &KeyName,
803  0,
805  DeviceNode->ResourceRequirements,
806  DeviceNode->ResourceRequirements->ListSize);
807  }
808 
809  ZwClose(LogConfKey);
810  }
811 
812  /* Set the 'ConfigFlags' value */
813  RtlInitUnicodeString(&KeyName, L"ConfigFlags");
814  Status = ZwQueryValueKey(InstanceKey,
815  &KeyName,
817  NULL,
818  0,
819  &ResultLength);
821  {
822  /* Write the default value */
823  ULONG DefaultConfigFlags = 0;
824  Status = ZwSetValueKey(InstanceKey,
825  &KeyName,
826  0,
827  REG_DWORD,
828  &DefaultConfigFlags,
829  sizeof(DefaultConfigFlags));
830  }
831 
832  /* Create the 'Control' key */
833  RtlInitUnicodeString(&KeyName, L"Control");
835  &KeyName,
837  InstanceKey,
838  NULL);
839  Status = ZwCreateKey(&ControlKey,
840  0,
842  0,
843  NULL,
845  NULL);
846  if (NT_SUCCESS(Status))
847  ZwClose(ControlKey);
848 
849  /* Create the 'Device Parameters' key and set the 'FirmwareIdentified' value for all ACPI-enumerated devices */
850  if (_wcsnicmp(DeviceNode->InstancePath.Buffer, L"ACPI\\", 5) == 0)
851  {
852  RtlInitUnicodeString(&KeyName, L"Device Parameters");
854  &KeyName,
856  InstanceKey,
857  NULL);
858  Status = ZwCreateKey(&DeviceParamsKey,
859  0,
861  0,
862  NULL,
864  NULL);
865  if (NT_SUCCESS(Status))
866  {
867  ULONG FirmwareIdentified = 1;
868  RtlInitUnicodeString(&KeyName, L"FirmwareIdentified");
869  Status = ZwSetValueKey(DeviceParamsKey,
870  &KeyName,
871  0,
872  REG_DWORD,
873  &FirmwareIdentified,
874  sizeof(FirmwareIdentified));
875 
876  ZwClose(DeviceParamsKey);
877  }
878  }
879 
880  DPRINT("IopSetDeviceInstanceData() done\n");
881 
882  return Status;
883 }
IN CINT OUT PVOID IN ULONG OUT PULONG ResultLength
Definition: conport.c:47
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 OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define REG_RESOURCE_REQUIREMENTS_LIST
Definition: nt_native.h:1504
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define REG_RESOURCE_LIST
Definition: nt_native.h:1502
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Definition: Node.h:9
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
ULONG NTAPI PnpDetermineResourceListSize(IN PCM_RESOURCE_LIST ResourceList)
Definition: pnpmgr.c:1943
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
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 REG_OPTION_VOLATILE
Definition: nt_native.h:1060
#define REG_DWORD
Definition: sdbapi.c:596

Referenced by IopActionInterrogateDeviceStack(), and IoReportDetectedDevice().

◆ IopSynchronousCall()

NTSTATUS NTAPI IopSynchronousCall ( IN PDEVICE_OBJECT  DeviceObject,
IN PIO_STACK_LOCATION  IoStackLocation,
OUT PVOID Information 
)

Definition at line 549 of file pnpmgr.c.

552 {
553  PIRP Irp;
554  PIO_STACK_LOCATION IrpStack;
556  KEVENT Event;
558  PDEVICE_OBJECT TopDeviceObject;
559  PAGED_CODE();
560 
561  /* Call the top of the device stack */
562  TopDeviceObject = IoGetAttachedDeviceReference(DeviceObject);
563 
564  /* Allocate an IRP */
565  Irp = IoAllocateIrp(TopDeviceObject->StackSize, FALSE);
566  if (!Irp)
567  {
568  ObDereferenceObject(TopDeviceObject);
570  }
571 
572  /* Initialize to failure */
573  Irp->IoStatus.Status = IoStatusBlock.Status = STATUS_NOT_SUPPORTED;
574  Irp->IoStatus.Information = IoStatusBlock.Information = 0;
575 
576  /* Special case for IRP_MN_FILTER_RESOURCE_REQUIREMENTS */
577  if ((IoStackLocation->MajorFunction == IRP_MJ_PNP) &&
578  (IoStackLocation->MinorFunction == IRP_MN_FILTER_RESOURCE_REQUIREMENTS))
579  {
580  /* Copy the resource requirements list into the IOSB */
581  Irp->IoStatus.Information =
582  IoStatusBlock.Information = (ULONG_PTR)IoStackLocation->Parameters.FilterResourceRequirements.IoResourceRequirementList;
583  }
584 
585  /* Initialize the event */
587 
588  /* Set them up */
589  Irp->UserIosb = &IoStatusBlock;
590  Irp->UserEvent = &Event;
591 
592  /* Queue the IRP */
593  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
595 
596  /* Copy-in the stack */
597  IrpStack = IoGetNextIrpStackLocation(Irp);
598  *IrpStack = *IoStackLocation;
599 
600  /* Call the driver */
601  Status = IoCallDriver(TopDeviceObject, Irp);
602  if (Status == STATUS_PENDING)
603  {
604  /* Wait for it */
606  Executive,
607  KernelMode,
608  FALSE,
609  NULL);
611  }
612 
613  /* Remove the reference */
614  ObDereferenceObject(TopDeviceObject);
615 
616  /* Return the information */
618  return Status;
619 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_MN_FILTER_RESOURCE_REQUIREMENTS
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
VOID NTAPI IoQueueThreadIrp(IN PIRP Irp)
Definition: irp.c:1954
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
Iosb Information
Definition: create.c:4353
#define FALSE
Definition: types.h:117
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:439
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
#define STATUS_PENDING
Definition: ntstatus.h:82
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2691
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define ULONG_PTR
Definition: config.h:101
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
#define PAGED_CODE()

Referenced by IoInvalidateDeviceState(), IopCancelRemoveDevice(), IopGetRelatedTargetDevice(), IopInitiatePnpIrp(), IopQueryRemoveDevice(), IopQueryStopDevice(), IopSendEject(), IopSendRemoveDevice(), IopSendStopDevice(), IopSendSurpriseRemoval(), and IopStartDevice2().

◆ IopUpdateRootKey()

INIT_FUNCTION NTSTATUS NTAPI IopUpdateRootKey ( VOID  )

Definition at line 1533 of file pnpmgr.c.

1534 {
1535  UNICODE_STRING EnumU = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Enum");
1536  UNICODE_STRING RootPathU = RTL_CONSTANT_STRING(L"Root");
1537  UNICODE_STRING MultiKeyPathU = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System\\MultifunctionAdapter");
1539  HANDLE hEnum, hRoot;
1540  NTSTATUS Status;
1541 
1544  if (!NT_SUCCESS(Status))
1545  {
1546  DPRINT1("ZwCreateKey() failed with status 0x%08lx\n", Status);
1547  return Status;
1548  }
1549 
1552  ZwClose(hEnum);
1553  if (!NT_SUCCESS(Status))
1554  {
1555  DPRINT1("ZwOpenKey() failed with status 0x%08lx\n", Status);
1556  return Status;
1557  }
1558 
1560  {
1561  Status = IopOpenRegistryKeyEx(&hEnum, NULL, &MultiKeyPathU, KEY_ENUMERATE_SUB_KEYS);
1562  if (!NT_SUCCESS(Status))
1563  {
1564  /* Nothing to do, don't return with an error status */
1565  DPRINT("ZwOpenKey() failed with status 0x%08lx\n", Status);
1566  ZwClose(hRoot);
1567  return STATUS_SUCCESS;
1568  }
1570  hEnum,
1571  NULL,
1572  hRoot,
1573  TRUE,
1574  NULL,
1575  0);
1576  ZwClose(hEnum);
1577  }
1578  else
1579  {
1580  /* Enumeration is disabled */
1582  }
1583 
1584  ZwClose(hRoot);
1585 
1586  return Status;
1587 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
static INIT_FUNCTION BOOLEAN IopIsFirmwareMapperDisabled(VOID)
Definition: pnpmgr.c:1463
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSTATUS NTAPI IopOpenRegistryKeyEx(PHANDLE KeyHandle, HANDLE ParentKey, PUNICODE_STRING Name, ACCESS_MASK DesiredAccess)
Definition: pnpmgr.c:1591
LONG NTSTATUS
Definition: precomp.h:26
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
static HTREEITEM hRoot
Definition: treeview.c:381
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
#define DPRINT1
Definition: precomp.h:8
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
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:1030
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1018
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by IopInitializePlugPlayServices().

◆ IoSynchronousInvalidateDeviceRelations()

NTSTATUS NTAPI IoSynchronousInvalidateDeviceRelations ( IN PDEVICE_OBJECT  DeviceObject,
IN DEVICE_RELATION_TYPE  Type 
)

Definition at line 2504 of file pnpmgr.c.

2507 {
2508  PAGED_CODE();
2509 
2511  {
2512  KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, 0x2, (ULONG_PTR)DeviceObject, 0, 0);
2513  }
2514 
2515  switch (Type)
2516  {
2517  case BusRelations:
2518  /* Enumerate the device */
2520  case PowerRelations:
2521  /* Not handled yet */
2522  return STATUS_NOT_IMPLEMENTED;
2523  case TargetDeviceRelation:
2524  /* Nothing to do */
2525  return STATUS_SUCCESS;
2526  default:
2527  /* Ejection relations are not supported */
2528  return STATUS_NOT_SUPPORTED;
2529  }
2530 }
Type
Definition: Type.h:6
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IopIsValidPhysicalDeviceObject(PhysicalDeviceObject)
Definition: io.h:238
NTSTATUS PiPerformSyncDeviceAction(_In_ PDEVICE_OBJECT DeviceObject, _In_ DEVICE_ACTION Action)
Perfom a device operation synchronously via PiQueueDeviceAction.
Definition: devaction.c:2531
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG _In_ LONG _In_ LONG x2
Definition: winddi.h:3706
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
return STATUS_SUCCESS
Definition: btrfs.c:3014
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:108
#define PAGED_CODE()

◆ IoTranslateBusAddress()

BOOLEAN NTAPI IoTranslateBusAddress ( IN INTERFACE_TYPE  InterfaceType,
IN ULONG  BusNumber,
IN PHYSICAL_ADDRESS  BusAddress,
IN OUT PULONG  AddressSpace,
OUT PPHYSICAL_ADDRESS  TranslatedAddress 
)

Definition at line 2537 of file pnpmgr.c.

2542 {
2543  /* FIXME: Notify the resource arbiter */
2544 
2545  return HalTranslateBusAddress(InterfaceType,
2546  BusNumber,
2547  BusAddress,
2548  AddressSpace,
2550 }
_In_ ULONG _In_ PHYSICAL_ADDRESS BusAddress
Definition: iofuncs.h:2268
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG _Out_ PPHYSICAL_ADDRESS TranslatedAddress
Definition: iofuncs.h:2268
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:156
BOOLEAN NTAPI HalTranslateBusAddress(IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber, IN PHYSICAL_ADDRESS BusAddress, IN OUT PULONG AddressSpace, OUT PPHYSICAL_ADDRESS TranslatedAddress)
Definition: bus.c:140

◆ PiAllocateGenericTableEntry()

PVOID NTAPI PiAllocateGenericTableEntry ( IN PRTL_AVL_TABLE  Table,
IN CLONG  ByteSize 
)

Definition at line 1803 of file pnpmgr.c.

1805 {
1806  /* FIXME: TODO */
1807  ASSERT(FALSE);
1808  return NULL;
1809 }
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)

Referenced by PpInitializeDeviceReferenceTable().

◆ PiCompareInstancePath()

RTL_GENERIC_COMPARE_RESULTS NTAPI PiCompareInstancePath ( IN PRTL_AVL_TABLE  Table,
IN PVOID  FirstStruct,
IN PVOID  SecondStruct 
)

Definition at line 1787 of file pnpmgr.c.

1790 {
1791  /* FIXME: TODO */
1792  ASSERT(FALSE);
1793  return 0;
1794 }
#define FALSE
Definition: types.h:117
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)

Referenced by PpInitializeDeviceReferenceTable().

◆ PiFreeGenericTableEntry()

VOID NTAPI PiFreeGenericTableEntry ( IN PRTL_AVL_TABLE  Table,
IN PVOID  Buffer 
)

Definition at line 1813 of file pnpmgr.c.

1815 {
1816  /* FIXME: TODO */
1817  ASSERT(FALSE);
1818 }
#define FALSE
Definition: types.h:117
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)

Referenced by PpInitializeDeviceReferenceTable().

◆ PiGetDeviceRegistryProperty()

NTSTATUS NTAPI PiGetDeviceRegistryProperty ( IN PDEVICE_OBJECT  DeviceObject,
IN ULONG  ValueType,
IN PWSTR  ValueName,
IN PWSTR  KeyName,
OUT PVOID  Buffer,
IN PULONG  BufferLength 
)

Definition at line 1997 of file pnpmgr.c.

2003 {
2004  NTSTATUS Status;
2005  HANDLE KeyHandle, SubHandle;
2006  UNICODE_STRING KeyString;
2007  PKEY_VALUE_FULL_INFORMATION KeyValueInfo = NULL;
2008  ULONG Length;
2009  PAGED_CODE();
2010 
2011  /* Find the instance key */
2013  if (NT_SUCCESS(Status))
2014  {
2015  /* Check for name given by caller */
2016  if (KeyName)
2017  {
2018  /* Open this key */
2019  RtlInitUnicodeString(&KeyString, KeyName);
2020  Status = IopOpenRegistryKeyEx(&SubHandle,
2021  KeyHandle,
2022  &KeyString,
2023  KEY_READ);
2024  if (NT_SUCCESS(Status))
2025  {
2026  /* And use this handle instead */
2027  ZwClose(KeyHandle);
2028  KeyHandle = SubHandle;
2029  }
2030  }
2031 
2032  /* Check if sub-key handle succeeded (or no-op if no key name given) */
2033  if (NT_SUCCESS(Status))
2034  {
2035  /* Now get the size of the property */
2037  ValueName,
2038  &KeyValueInfo);
2039  }
2040 
2041  /* Close the key */
2042  ZwClose(KeyHandle);
2043  }
2044 
2045  /* Fail if any of the registry operations failed */
2046  if (!NT_SUCCESS(Status)) return Status;
2047 
2048  /* Check how much data we have to copy */
2049  Length = KeyValueInfo->DataLength;
2050  if (*BufferLength >= Length)
2051  {
2052  /* Check for a match in the value type */
2053  if (KeyValueInfo->Type == ValueType)
2054  {
2055  /* Copy the data */
2057  (PVOID)((ULONG_PTR)KeyValueInfo +
2058  KeyValueInfo->DataOffset),
2059  Length);
2060  }
2061  else
2062  {
2063  /* Invalid registry property type, fail */
2065  }
2066  }
2067  else
2068  {
2069  /* Buffer is too small to hold data */
2071  }
2072 
2073  /* Return the required buffer length, free the buffer, and return status */
2074  *BufferLength = Length;
2075  ExFreePool(KeyValueInfo);
2076  return Status;
2077 }
_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)
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
#define KEY_READ
Definition: nt_native.h:1023
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSTATUS NTAPI IopOpenRegistryKeyEx(PHANDLE KeyHandle, HANDLE ParentKey, PUNICODE_STRING Name, ACCESS_MASK DesiredAccess)
Definition: pnpmgr.c:1591
_In_ PCWSTR _In_z_ PCWSTR _In_ ULONG ValueType
Definition: rtlfuncs.h:4154
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI IopGetRegistryValue(IN HANDLE Handle, IN PWSTR ValueName, OUT PKEY_VALUE_FULL_INFORMATION *Information)
Definition: pnpmgr.c:1742
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
uint32_t ULONG_PTR
Definition: typedefs.h:65
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:476
Definition: bufpool.h:45
NTSTATUS NTAPI PnpDeviceObjectToDeviceInstance(IN PDEVICE_OBJECT DeviceObject, IN PHANDLE DeviceInstanceHandle, IN ACCESS_MASK DesiredAccess)
Definition: pnpmgr.c:1903
_In_ UCHAR BufferLength
Definition: scsi.h:4067
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define PAGED_CODE()

Referenced by IoGetDeviceProperty().

◆ PiInitPhase0()

BOOLEAN NTAPI PiInitPhase0 ( VOID  )

Definition at line 1836 of file pnpmgr.c.

1837 {
1838  /* Initialize the resource when accessing device registry data */
1840 
1841  /* Setup the device reference AVL table */
1843  return TRUE;
1844 }
#define TRUE
Definition: types.h:120
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
ERESOURCE PpRegistryDeviceResource
Definition: pnpmgr.c:18
VOID NTAPI PpInitializeDeviceReferenceTable(VOID)
Definition: pnpmgr.c:1822

Referenced by PpInitSystem().

◆ PnpBusTypeGuidGet()

NTSTATUS NTAPI PnpBusTypeGuidGet ( IN USHORT  Index,
IN LPGUID  BusTypeGuid 
)

Definition at line 1876 of file pnpmgr.c.

1878 {
1880 
1881  /* Acquire the lock */
1883 
1884  /* Validate size */
1885  if (Index < PnpBusTypeGuidList->GuidCount)
1886  {
1887  /* Copy the data */
1888  RtlCopyMemory(BusTypeGuid, &PnpBusTypeGuidList->Guids[Index], sizeof(GUID));
1889  }
1890  else
1891  {
1892  /* Failure path */
1894  }
1895 
1896  /* Release lock and return status */
1898  return Status;
1899 }
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:28
LONG NTSTATUS
Definition: precomp.h:26
FAST_MUTEX Lock
Definition: io.h:439
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
static const UCHAR Index[8]
Definition: usbohci.c:18
Status
Definition: gdiplustypes.h:24
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by IoGetDeviceProperty().

◆ PnpDetermineResourceListSize()

ULONG NTAPI PnpDetermineResourceListSize ( IN PCM_RESOURCE_LIST  ResourceList)

Definition at line 1943 of file pnpmgr.c.

1944 {
1945  ULONG FinalSize, PartialSize, EntrySize, i, j;
1946  PCM_FULL_RESOURCE_DESCRIPTOR FullDescriptor;
1947  PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
1948 
1949  /* If we don't have one, that's easy */
1950  if (!ResourceList) return 0;
1951 
1952  /* Start with the minimum size possible */
1953  FinalSize = FIELD_OFFSET(CM_RESOURCE_LIST, List);
1954 
1955  /* Loop each full descriptor */
1956  FullDescriptor = ResourceList->List;
1957  for (i = 0; i < ResourceList->Count; i++)
1958  {
1959  /* Start with the minimum size possible */
1960  PartialSize = FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList) +
1961  FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors);
1962 
1963  /* Loop each partial descriptor */
1964  PartialDescriptor = FullDescriptor->PartialResourceList.PartialDescriptors;
1965  for (j = 0; j < FullDescriptor->PartialResourceList.Count; j++)
1966  {
1967  /* Start with the minimum size possible */
1969 
1970  /* Check if there is extra data */
1971  if (PartialDescriptor->Type == CmResourceTypeDeviceSpecific)
1972  {
1973  /* Add that data */
1974  EntrySize += PartialDescriptor->u.DeviceSpecificData.DataSize;
1975  }
1976 
1977  /* The size of partial descriptors is bigger */
1978  PartialSize += EntrySize;
1979 
1980  /* Go to the next partial descriptor */
1981  PartialDescriptor = (PVOID)((ULONG_PTR)PartialDescriptor + EntrySize);
1982  }
1983 
1984  /* The size of full descriptors is bigger */
1985  FinalSize += PartialSize;
1986 
1987  /* Go to the next full descriptor */
1988  FullDescriptor = (PVOID)((ULONG_PTR)FullDescriptor + PartialSize);
1989  }
1990 
1991  /* Return the final size */
1992  return FinalSize;
1993 }
#define CmResourceTypeDeviceSpecific
Definition: hwresource.cpp:127
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@387::@396 DeviceSpecificData
_In_ UCHAR EntrySize
Definition: iofuncs.h:640
const MUI_LANGUAGE_RESOURCE ResourceList[]
Definition: muilanguages.h:414
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR CM_PARTIAL_RESOURCE_DESCRIPTOR
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@387 u
uint32_t ULONG_PTR
Definition: typedefs.h:65
CM_PARTIAL_RESOURCE_LIST PartialResourceList
Definition: hwresource.cpp:160
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
void * PVOID
Definition: retypes.h:9
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 GLint GLint j
Definition: glfuncs.h:250
LIST_ENTRY List
Definition: psmgr.c:57
CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1]
Definition: hwresource.cpp:119
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
unsigned int ULONG
Definition: retypes.h:1

Referenced by IoGetDeviceProperty(), IopAssignDeviceResources(), IopFixupResourceListWithRequirements(), IopSetDeviceInstanceData(), IopTranslateDeviceResources(), IopUpdateControlKeyWithResources(), and IopUpdateResourceMap().

◆ PnpDeviceObjectToDeviceInstance()

NTSTATUS NTAPI PnpDeviceObjectToDeviceInstance ( IN PDEVICE_OBJECT  DeviceObject,
IN PHANDLE  DeviceInstanceHandle,
IN ACCESS_MASK  DesiredAccess 
)

Definition at line 1903 of file pnpmgr.c.

1906 {
1907  NTSTATUS Status;
1908  HANDLE KeyHandle;
1910  UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\REGISTRY\\MACHINE\\SYSTEM\\CURRENTCONTROLSET\\ENUM");
1911  PAGED_CODE();
1912 
1913  /* Open the enum key */
1915  NULL,
1916  &KeyName,
1917  KEY_READ);
1918  if (!NT_SUCCESS(Status)) return Status;
1919 
1920  /* Make sure we have an instance path */
1922  if ((DeviceNode) && (DeviceNode->InstancePath.Length))
1923  {
1924  /* Get the instance key */
1925  Status = IopOpenRegistryKeyEx(DeviceInstanceHandle,
1926  KeyHandle,
1927  &DeviceNode->InstancePath,
1928  DesiredAccess);
1929  }
1930  else
1931  {
1932  /* Fail */
1934  }
1935 
1936  /* Close the handle and return status */
1937  ZwClose(KeyHandle);
1938  return Status;
1939 }
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
#define KEY_READ
Definition: nt_native.h:1023
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSTATUS NTAPI IopOpenRegistryKeyEx(PHANDLE KeyHandle, HANDLE ParentKey, PUNICODE_STRING Name, ACCESS_MASK DesiredAccess)
Definition: pnpmgr.c:1591
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Definition: Node.h:9
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
_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:4137
PDEVICE_NODE FASTCALL IopGetDeviceNode(IN PDEVICE_OBJECT DeviceObject)
#define PAGED_CODE()
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by PiGetDeviceRegistryProperty().

◆ PpInitializeDeviceReferenceTable()

VOID NTAPI PpInitializeDeviceReferenceTable ( VOID  )

Definition at line 1822 of file pnpmgr.c.

1823 {
1824  /* Setup the guarded mutex and AVL table */
1831  NULL);
1832 }
KGUARDED_MUTEX PpDeviceReferenceTableLock
Definition: pnpmgr.c:19
RTL_AVL_COMPARE_ROUTINE * PRTL_AVL_COMPARE_ROUTINE
Definition: rtltypes.h:385
VOID NTAPI PiFreeGenericTableEntry(IN PRTL_AVL_TABLE Table, IN PVOID Buffer)
Definition: pnpmgr.c:1813
PVOID NTAPI PiAllocateGenericTableEntry(IN PRTL_AVL_TABLE Table, IN CLONG ByteSize)
Definition: pnpmgr.c:1803
smooth NULL
Definition: ftsmooth.c:416
RTL_AVL_TABLE PpDeviceReferenceTable
Definition: pnpmgr.c:20
VOID NTAPI RtlInitializeGenericTableAvl(IN OUT PRTL_AVL_TABLE Table, IN PRTL_AVL_COMPARE_ROUTINE CompareRoutine, IN PRTL_AVL_ALLOCATE_ROUTINE AllocateRoutine, IN PRTL_AVL_FREE_ROUTINE FreeRoutine, IN PVOID TableContext)
Definition: avltable.c:26
RTL_AVL_FREE_ROUTINE * PRTL_AVL_FREE_ROUTINE
Definition: rtltypes.h:402
VOID FASTCALL KeInitializeGuardedMutex(OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:31
RTL_AVL_ALLOCATE_ROUTINE * PRTL_AVL_ALLOCATE_ROUTINE
Definition: rtltypes.h:394
RTL_GENERIC_COMPARE_RESULTS NTAPI PiCompareInstancePath(IN PRTL_AVL_TABLE Table, IN PVOID FirstStruct, IN PVOID SecondStruct)
Definition: pnpmgr.c:1787

Referenced by PiInitPhase0().

◆ PpInitSystem()

BOOLEAN NTAPI PpInitSystem ( VOID  )

Definition at line 1848 of file pnpmgr.c.

1849 {
1850  /* Check the initialization phase */
1851  switch (ExpInitializationPhase)
1852  {
1853  case 0:
1854 
1855  /* Do Phase 0 */
1856  return PiInitPhase0();
1857 
1858  case 1:
1859 
1860  /* Do Phase 1 */
1861  return TRUE;
1862  //return PiInitPhase1();
1863 
1864  default:
1865 
1866  /* Don't know any other phase! Bugcheck! */
1867  KeBugCheck(UNEXPECTED_INITIALIZATION_CALL);
1868  return FALSE;
1869  }
1870 }
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1431
BOOLEAN NTAPI PiInitPhase0(VOID)
Definition: pnpmgr.c:1836
ULONG ExpInitializationPhase
Definition: init.c:66

Referenced by ExpInitializeExecutive(), and Phase1InitializationDiscard().

Variable Documentation

◆ ExpInitializationPhase

ULONG ExpInitializationPhase

Definition at line 66 of file init.c.

Referenced by PpInitSystem().

◆ IopRootDriverObject

PDRIVER_OBJECT IopRootDriverObject

Definition at line 27 of file pnpmgr.c.

Referenced by IopInitializePlugPlayServices(), and PnpRootDriverEntry().

◆ PnPBootDriversLoaded

BOOLEAN PnPBootDriversLoaded

Definition at line 21 of file pnpmgr.c.

Referenced by IopInitializeBootDrivers(), and PiQueueDeviceAction().

◆ PnpBusTypeGuidList

PIO_BUS_TYPE_GUID_LIST PnpBusTypeGuidList = NULL

◆ PpDeviceReferenceTable

RTL_AVL_TABLE PpDeviceReferenceTable

Definition at line 20 of file pnpmgr.c.

Referenced by PpInitializeDeviceReferenceTable().

◆ PpDeviceReferenceTableLock

KGUARDED_MUTEX PpDeviceReferenceTableLock

Definition at line 19 of file pnpmgr.c.

Referenced by PpInitializeDeviceReferenceTable().

◆ PpRegistryDeviceResource

ERESOURCE PpRegistryDeviceResource

Definition at line 18 of file pnpmgr.c.

Referenced by PiInitPhase0().