ReactOS 0.4.16-dev-112-g52265ae
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 IopGetSystemPowerDeviceObject (PDEVICE_OBJECT *DeviceObject)
 
USHORT NTAPI IopGetBusTypeGuidIndex (LPGUID BusTypeGuid)
 
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)
 
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)
 
VOID NTAPI IoInvalidateDeviceState (IN PDEVICE_OBJECT DeviceObject)
 

Variables

ERESOURCE PpRegistryDeviceResource
 
KGUARDED_MUTEX PpDeviceReferenceTableLock
 
RTL_AVL_TABLE PpDeviceReferenceTable
 
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 1374 of file pnpmgr.c.

◆ PIP_RETURN_DATA

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

Definition at line 1373 of file pnpmgr.c.

◆ PIP_UNIMPLEMENTED

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

Definition at line 1375 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 1382 of file pnpmgr.c.

1387{
1389 DEVICE_CAPABILITIES DeviceCaps;
1391 PWCHAR ValueName = NULL, EnumeratorNameEnd, DeviceInstanceName;
1392 PVOID Data = NULL;
1394 GUID BusTypeGuid;
1395 POBJECT_NAME_INFORMATION ObjectNameInfo = NULL;
1396 BOOLEAN NullTerminate = FALSE;
1398
1399 DPRINT("IoGetDeviceProperty(0x%p %d)\n", DeviceObject, DeviceProperty);
1400
1401 /* Assume failure */
1402 *ResultLength = 0;
1403
1404 /* Only PDOs can call this */
1406
1407 /* Handle all properties */
1408 switch (DeviceProperty)
1409 {
1411
1412 /* Get the GUID from the internal cache */
1413 Status = PnpBusTypeGuidGet(DeviceNode->ChildBusTypeIndex, &BusTypeGuid);
1414 if (!NT_SUCCESS(Status)) return Status;
1415
1416 /* This is the format of the returned data */
1417 PIP_RETURN_DATA(sizeof(GUID), &BusTypeGuid);
1418
1420
1421 /* Validate correct interface type */
1422 if (DeviceNode->ChildInterfaceType == InterfaceTypeUndefined)
1424
1425 /* This is the format of the returned data */
1426 PIP_RETURN_DATA(sizeof(INTERFACE_TYPE), &DeviceNode->ChildInterfaceType);
1427
1429
1430 /* Validate correct bus number */
1431 if ((DeviceNode->ChildBusNumber & 0x80000000) == 0x80000000)
1433
1434 /* This is the format of the returned data */
1435 PIP_RETURN_DATA(sizeof(ULONG), &DeviceNode->ChildBusNumber);
1436
1438
1439 /* Get the instance path */
1440 DeviceInstanceName = DeviceNode->InstancePath.Buffer;
1441
1442 /* Sanity checks */
1443 ASSERT((BufferLength & 1) == 0);
1444 ASSERT(DeviceInstanceName != NULL);
1445
1446 /* Get the name from the path */
1447 EnumeratorNameEnd = wcschr(DeviceInstanceName, OBJ_NAME_PATH_SEPARATOR);
1448 ASSERT(EnumeratorNameEnd);
1449
1450 /* This string needs to be NULL-terminated */
1451 NullTerminate = TRUE;
1452
1453 /* This is the format of the returned data */
1454 PIP_RETURN_DATA((ULONG)(EnumeratorNameEnd - DeviceInstanceName) * sizeof(WCHAR),
1455 DeviceInstanceName);
1456
1458
1459 /* Query the device caps */
1461 if (!NT_SUCCESS(Status) || (DeviceCaps.Address == MAXULONG))
1463
1464 /* This is the format of the returned data */
1465 PIP_RETURN_DATA(sizeof(ULONG), &DeviceCaps.Address);
1466
1468
1469 /* Validate we have resources */
1470 if (!DeviceNode->BootResources)
1471// if (!DeviceNode->BootResourcesTranslated) // FIXFIX: Need this field
1472 {
1473 /* No resources will still fake success, but with 0 bytes */
1474 *ResultLength = 0;
1475 return STATUS_SUCCESS;
1476 }
1477
1478 /* This is the format of the returned data */
1479 PIP_RETURN_DATA(PnpDetermineResourceListSize(DeviceNode->BootResources), // FIXFIX: Should use BootResourcesTranslated
1480 DeviceNode->BootResources); // FIXFIX: Should use BootResourcesTranslated
1481
1483
1484 /* Sanity check for Unicode-sized string */
1485 ASSERT((BufferLength & 1) == 0);
1486
1487 /* Allocate name buffer */
1489 ObjectNameInfo = ExAllocatePool(PagedPool, Length);
1490 if (!ObjectNameInfo) return STATUS_INSUFFICIENT_RESOURCES;
1491
1492 /* Query the PDO name */
1494 ObjectNameInfo,
1495 Length,
1496 ResultLength);
1498 {
1499 /* It's up to the caller to try again */
1501 }
1502
1503 /* This string needs to be NULL-terminated */
1504 NullTerminate = TRUE;
1505
1506 /* Return if successful */
1507 if (NT_SUCCESS(Status)) PIP_RETURN_DATA(ObjectNameInfo->Name.Length,
1508 ObjectNameInfo->Name.Buffer);
1509
1510 /* Let the caller know how big the name is */
1512 break;
1513
1515
1516 Policy = DeviceNode->RemovalPolicy;
1517 PIP_RETURN_DATA(sizeof(Policy), &Policy);
1518
1519 /* Handle the registry-based properties */
1543 //PIP_REGISTRY_DATA(REGSTR_VAL_CONTAINERID, REG_SZ); // Win7
1545 break;
1548 break;
1553 default:
1555 }
1556
1557 /* Having a registry value name implies registry data */
1558 if (ValueName)
1559 {
1560 /* We know up-front how much data to expect */
1562
1563 /* Go get the data, use the LogConf subkey if necessary */
1565 ValueType,
1566 ValueName,
1567 (DeviceProperty ==
1569 L"LogConf": NULL,
1571 ResultLength);
1572 }
1573 else if (NT_SUCCESS(Status))
1574 {
1575 /* We know up-front how much data to expect, check the caller's buffer */
1576 *ResultLength = ReturnLength + (NullTerminate ? sizeof(UNICODE_NULL) : 0);
1577 if (*ResultLength <= BufferLength)
1578 {
1579 /* Buffer is all good, copy the data */
1581
1582 /* Check if we need to NULL-terminate the string */
1583 if (NullTerminate)
1584 {
1585 /* Terminate the string */
1587 }
1588
1589 /* This is the success path */
1591 }
1592 else
1593 {
1594 /* Failure path */
1596 }
1597 }
1598
1599 /* Free any allocation we may have made, and return the status code */
1600 if (ObjectNameInfo) ExFreePool(ObjectNameInfo);
1601 return Status;
1602}
@ DeviceNode
Definition: Node.h:9
unsigned char BOOLEAN
#define OBJ_NAME_PATH_SEPARATOR
Definition: arcname_tests.c:25
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define wcschr
Definition: compat.h:17
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:43
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define PagedPool
Definition: env_spec_w32.h:308
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
Status
Definition: gdiplustypes.h:25
@ InterfaceTypeUndefined
Definition: hwresource.cpp:136
enum _INTERFACE_TYPE INTERFACE_TYPE
#define REG_SZ
Definition: layer.c:22
#define ASSERT(a)
Definition: mode.c:44
#define REG_RESOURCE_LIST
Definition: nt_native.h:1502
struct _OBJECT_NAME_INFORMATION OBJECT_NAME_INFORMATION
#define REG_MULTI_SZ
Definition: nt_native.h:1501
#define UNICODE_NULL
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
PDEVICE_NODE FASTCALL IopGetDeviceNode(IN PDEVICE_OBJECT DeviceObject)
NTSTATUS NTAPI IopQueryDeviceCapabilities(PDEVICE_NODE DeviceNode, PDEVICE_CAPABILITIES DeviceCaps)
Definition: devaction.c:854
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:476
#define L(x)
Definition: ntvdm.h:50
NTSTATUS NTAPI ObQueryNameString(IN PVOID Object, OUT POBJECT_NAME_INFORMATION ObjectNameInfo, IN ULONG Length, OUT PULONG ReturnLength)
Definition: obname.c:1207
ULONG NTAPI PnpDetermineResourceListSize(IN PCM_RESOURCE_LIST ResourceList)
Definition: pnpmgr.c:1237
#define PIP_REGISTRY_DATA(x, y)
Definition: pnpmgr.c:1374
#define PIP_UNIMPLEMENTED()
Definition: pnpmgr.c:1375
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:1291
#define PIP_RETURN_DATA(x, y)
Definition: pnpmgr.c:1373
NTSTATUS NTAPI PnpBusTypeGuidGet(IN USHORT Index, IN LPGUID BusTypeGuid)
Definition: pnpmgr.c:1170
#define REGSTR_VAL_UI_NUMBER
Definition: regstr.h:426
#define REGSTR_VAL_DEVDESC
Definition: regstr.h:292
#define REGSTR_VAL_CLASSGUID
Definition: regstr.h:422
#define REGSTR_VAL_COMPATIBLEIDS
Definition: regstr.h:296
#define REGSTR_VAL_BOOTCONFIG
Definition: regstr.h:293
#define REGSTR_VAL_DRIVER
Definition: regstr.h:385
#define REGSTR_VAL_FRIENDLYNAME
Definition: regstr.h:465
#define REGSTR_VAL_HARDWAREID
Definition: regstr.h:485
#define REGSTR_VAL_LOCATION_INFORMATION
Definition: regstr.h:423
#define REGSTR_VAL_CONFIGFLAGS
Definition: regstr.h:388
#define REGSTR_VAL_CLASS
Definition: regstr.h:291
#define REGSTR_VAL_MFG
Definition: regstr.h:306
#define REG_DWORD
Definition: sdbapi.c:596
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define DPRINT
Definition: sndvol32.h:73
#define MAXULONG
Definition: typedefs.h:251
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint16_t * PWCHAR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3776
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ ULONG _Out_ PVOID PropertyBuffer
Definition: wdfdevice.h:4437
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY DeviceProperty
Definition: wdfdevice.h:3769
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
_In_ WDFINTERRUPT _In_ WDF_INTERRUPT_POLICY Policy
Definition: wdfinterrupt.h:653
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG _Out_opt_ PULONG _Out_opt_ PULONG ValueType
Definition: wdfregistry.h:282
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
DEVICE_CAPABILITIES
Definition: iotypes.h:965
enum _DEVICE_REMOVAL_POLICY DEVICE_REMOVAL_POLICY
@ DevicePropertyCompatibleIDs
Definition: iotypes.h:1197
@ DevicePropertyAddress
Definition: iotypes.h:1211
@ DevicePropertyEnumeratorName
Definition: iotypes.h:1210
@ DevicePropertyBootConfiguration
Definition: iotypes.h:1198
@ DevicePropertyResourceRequirements
Definition: iotypes.h:1215
@ DevicePropertyDriverKeyName
Definition: iotypes.h:1202
@ DevicePropertyInstallState
Definition: iotypes.h:1213
@ DevicePropertyClassGuid
Definition: iotypes.h:1201
@ DevicePropertyUINumber
Definition: iotypes.h:1212
@ DevicePropertyBusNumber
Definition: iotypes.h:1209
@ DevicePropertyBootConfigurationTranslated
Definition: iotypes.h:1199
@ DevicePropertyRemovalPolicy
Definition: iotypes.h:1214
@ DevicePropertyPhysicalDeviceObjectName
Definition: iotypes.h:1206
@ DevicePropertyLegacyBusType
Definition: iotypes.h:1208
@ DevicePropertyAllocatedResources
Definition: iotypes.h:1216
@ DevicePropertyManufacturer
Definition: iotypes.h:1203
@ DevicePropertyClassName
Definition: iotypes.h:1200
@ DevicePropertyFriendlyName
Definition: iotypes.h:1204
@ DevicePropertyContainerID
Definition: iotypes.h:1217
@ DevicePropertyLocationInformation
Definition: iotypes.h:1205
@ DevicePropertyHardwareID
Definition: iotypes.h:1196
@ DevicePropertyBusTypeGuid
Definition: iotypes.h:1207
@ DevicePropertyDeviceDescription
Definition: iotypes.h:1195
__wchar_t WCHAR
Definition: xmlstorage.h:180

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

◆ IoInvalidateDeviceRelations()

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

Definition at line 1772 of file pnpmgr.c.

1775{
1777 {
1778 KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, 0x2, (ULONG_PTR)DeviceObject, 0, 0);
1779 }
1780
1781 switch (Type)
1782 {
1783 case BusRelations:
1784 /* Enumerate the device */
1786 break;
1787 default:
1788 /* Everything else is not implemented */
1789 break;
1790 }
1791}
Type
Definition: Type.h:7
#define IopIsValidPhysicalDeviceObject(PhysicalDeviceObject)
Definition: io.h:242
@ PiActionEnumDeviceTree
Definition: io.h:526
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:2659
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
uint32_t ULONG_PTR
Definition: typedefs.h:65
@ BusRelations
Definition: iotypes.h:2152

Referenced by _Function_class_(), add_volume_device(), ClassDeviceControl(), ClassInterpretSenseInfo(), DiskIoctlGetLengthInfo(), FxChildList::EndScan(), FDO_StartDevice(), FdoIoctlDiskCreateDisk(), FdoIoctlDiskDeleteDriveLayout(), FdoIoctlDiskSetDriveLayout(), FdoIoctlDiskSetDriveLayoutEx(), FdoIoctlDiskUpdateProperties(), MxDeviceObject::InvalidateDeviceRelations(), IsaFdoRemoveDevice(), IsaPdoStartReadPort(), IsaReadPortRemoveDevice(), KsCreateBusEnumObject(), KspBusWorkerRoutine(), KspInstallBusEnumInterface(), KsServiceBusEnumCreateRequest(), PartitionHandleDeviceControl(), FxChildList::ProcessBusRelations(), FxChildList::ProcessModificationsLocked(), RamdiskCreateRamdisk(), remove_volume_child(), ReportGreenPdo(), RequestDispatchToSequentialQueue(), SenseInfoInterpretByAdditionalSenseCode(), USBH_FdoQueryBusRelations(), USBH_ProcessPortStateChange(), USBHUB_RootHubCallBack(), and VideoPortEnumerateChildren().

◆ IoInvalidateDeviceState()

VOID NTAPI IoInvalidateDeviceState ( IN PDEVICE_OBJECT  DeviceObject)

◆ IoOpenDeviceRegistryKey()

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

Definition at line 1621 of file pnpmgr.c.

1625{
1626 static WCHAR RootKeyName[] =
1627 L"\\Registry\\Machine\\System\\CurrentControlSet\\";
1628 static WCHAR ProfileKeyName[] =
1629 L"Hardware Profiles\\Current\\System\\CurrentControlSet\\";
1630 static WCHAR ClassKeyName[] = L"Control\\Class\\";
1631 static WCHAR EnumKeyName[] = L"Enum\\";
1632 static WCHAR DeviceParametersKeyName[] = L"Device Parameters";
1634 PWSTR KeyNameBuffer;
1636 ULONG DriverKeyLength;
1640
1641 DPRINT("IoOpenDeviceRegistryKey() called\n");
1642
1644 {
1645 DPRINT1("IoOpenDeviceRegistryKey(): got wrong params, exiting...\n");
1647 }
1648
1652
1653 /*
1654 * Calculate the length of the base key name. This is the full
1655 * name for driver key or the name excluding "Device Parameters"
1656 * subkey for device key.
1657 */
1658
1659 KeyNameLength = sizeof(RootKeyName);
1661 KeyNameLength += sizeof(ProfileKeyName) - sizeof(UNICODE_NULL);
1663 {
1664 KeyNameLength += sizeof(ClassKeyName) - sizeof(UNICODE_NULL);
1666 0, NULL, &DriverKeyLength);
1668 return Status;
1669 KeyNameLength += DriverKeyLength;
1670 }
1671 else
1672 {
1673 KeyNameLength += sizeof(EnumKeyName) - sizeof(UNICODE_NULL) +
1674 DeviceNode->InstancePath.Length;
1675 }
1676
1677 /*
1678 * Now allocate the buffer for the key name...
1679 */
1680
1681 KeyNameBuffer = ExAllocatePool(PagedPool, KeyNameLength);
1682 if (KeyNameBuffer == NULL)
1684
1685 KeyName.Length = 0;
1686 KeyName.MaximumLength = (USHORT)KeyNameLength;
1687 KeyName.Buffer = KeyNameBuffer;
1688
1689 /*
1690 * ...and build the key name.
1691 */
1692
1693 KeyName.Length += sizeof(RootKeyName) - sizeof(UNICODE_NULL);
1694 RtlCopyMemory(KeyNameBuffer, RootKeyName, KeyName.Length);
1695
1697 RtlAppendUnicodeToString(&KeyName, ProfileKeyName);
1698
1700 {
1701 RtlAppendUnicodeToString(&KeyName, ClassKeyName);
1703 DriverKeyLength, KeyNameBuffer +
1704 (KeyName.Length / sizeof(WCHAR)),
1705 &DriverKeyLength);
1706 if (!NT_SUCCESS(Status))
1707 {
1708 DPRINT1("Call to IoGetDeviceProperty() failed with Status 0x%08lx\n", Status);
1709 ExFreePool(KeyNameBuffer);
1710 return Status;
1711 }
1712 KeyName.Length += (USHORT)DriverKeyLength - sizeof(UNICODE_NULL);
1713 }
1714 else
1715 {
1716 RtlAppendUnicodeToString(&KeyName, EnumKeyName);
1718 if (DeviceNode->InstancePath.Length == 0)
1719 {
1720 ExFreePool(KeyNameBuffer);
1721 return Status;
1722 }
1723 }
1724
1725 /*
1726 * Open the base key.
1727 */
1729 if (!NT_SUCCESS(Status))
1730 {
1731 DPRINT1("IoOpenDeviceRegistryKey(%wZ): Base key doesn't exist, exiting... (Status 0x%08lx)\n", &KeyName, Status);
1732 ExFreePool(KeyNameBuffer);
1733 return Status;
1734 }
1735 ExFreePool(KeyNameBuffer);
1736
1737 /*
1738 * For driver key we're done now.
1739 */
1740
1742 return Status;
1743
1744 /*
1745 * Let's go further. For device key we must open "Device Parameters"
1746 * subkey and create it if it doesn't exist yet.
1747 */
1748
1749 RtlInitUnicodeString(&KeyName, DeviceParametersKeyName);
1751 &KeyName,
1754 NULL);
1755 Status = ZwCreateKey(DevInstRegKey,
1758 0,
1759 NULL,
1761 NULL);
1762 ZwClose(ObjectAttributes.RootDirectory);
1763
1764 return Status;
1765}
#define DPRINT1
Definition: precomp.h:8
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
unsigned short USHORT
Definition: pedump.c:61
NTSTATUS NTAPI IopOpenRegistryKeyEx(PHANDLE KeyHandle, HANDLE ParentKey, PUNICODE_STRING Name, ACCESS_MASK DesiredAccess)
Definition: pnpmgr.c:885
NTSTATUS NTAPI IoGetDeviceProperty(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_REGISTRY_PROPERTY DeviceProperty, IN ULONG BufferLength, OUT PVOID PropertyBuffer, OUT PULONG ResultLength)
Definition: pnpmgr.c:1382
uint16_t * PWSTR
Definition: typedefs.h:56
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define PLUGPLAY_REGKEY_DRIVER
Definition: usbd.c:42
_In_ ULONG _In_ ULONG KeyNameLength
Definition: usbdlib.h:208
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2658
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699
#define PLUGPLAY_REGKEY_CURRENT_HWPROFILE
Definition: iofuncs.h:2788
_In_ ULONG _In_ ACCESS_MASK _Out_ PHANDLE DevInstRegKey
Definition: iofuncs.h:1127
_In_ ULONG DevInstKeyType
Definition: iofuncs.h:1125
#define PLUGPLAY_REGKEY_DEVICE
Definition: iofuncs.h:2786

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

525{
527 HANDLE hParent = NULL, hKey;
530 PCWSTR Current, Last;
533
534 /* Assume failure */
535 *Handle = NULL;
536
537 /* Open root key for device instances */
539 if (!NT_SUCCESS(Status))
540 {
541 DPRINT1("ZwOpenKey('%wZ') failed with status 0x%08lx\n", &EnumU, Status);
542 return Status;
543 }
544
545 Current = KeyName.Buffer = RegistryPath->Buffer;
546 Last = &RegistryPath->Buffer[RegistryPath->Length / sizeof(WCHAR)];
547
548 /* Go up to the end of the string */
549 while (Current <= Last)
550 {
551 if (Current != Last && *Current != L'\\')
552 {
553 /* Not the end of the string and not a separator */
554 Current++;
555 continue;
556 }
557
558 /* Prepare relative key name */
559 Length = (USHORT)((ULONG_PTR)Current - (ULONG_PTR)KeyName.Buffer);
560 KeyName.MaximumLength = KeyName.Length = Length;
561 DPRINT("Create '%wZ'\n", &KeyName);
562
563 /* Open key */
565 &KeyName,
567 hParent,
568 NULL);
569 Status = ZwCreateKey(&hKey,
570 Current == Last ? KEY_ALL_ACCESS : KEY_CREATE_SUB_KEY,
572 0,
573 NULL,
575 NULL);
576
577 /* Close parent key handle, we don't need it anymore */
578 if (hParent)
579 ZwClose(hParent);
580
581 /* Key opening/creating failed? */
582 if (!NT_SUCCESS(Status))
583 {
584 DPRINT1("ZwCreateKey('%wZ') failed with status 0x%08lx\n", &KeyName, Status);
585 return Status;
586 }
587
588 /* Check if it is the end of the string */
589 if (Current == Last)
590 {
591 /* Yes, return success */
592 *Handle = hKey;
593 return STATUS_SUCCESS;
594 }
595
596 /* Start with this new parent key */
597 hParent = hKey;
598 Current++;
599 KeyName.Buffer = (PWSTR)Current;
600 }
601
602 return STATUS_UNSUCCESSFUL;
603}
#define ULONG_PTR
Definition: config.h:101
FxAutoRegKey hKey
ULONG Handle
Definition: gdb_input.c:15
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1018
#define ENUM_ROOT
Definition: io.h:53
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_opt_ WDFKEY _In_ PCUNICODE_STRING _In_ ACCESS_MASK _In_ ULONG CreateOptions
Definition: wdfregistry.h:118

Referenced by IopInstallCriticalDevice(), IopQueryDeviceCapabilities(), IoReportDetectedDevice(), PiControlInitializeDevice(), and PiInitializeDevNode().

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

916{
918 ULONG KeyDisposition, RootHandleIndex = 0, i = 1, NestedCloseLevel = 0;
920 HANDLE HandleArray[2];
921 BOOLEAN Recursing = TRUE;
922 PWCHAR pp, p, p1;
923 UNICODE_STRING KeyString;
925 PAGED_CODE();
926
927 /* P1 is start, pp is end */
928 p1 = KeyName->Buffer;
929 pp = (PVOID)((ULONG_PTR)p1 + KeyName->Length);
930
931 /* Create the target key */
933 KeyName,
935 RootHandle,
936 NULL);
937 Status = ZwCreateKey(&HandleArray[i],
940 0,
941 NULL,
943 &KeyDisposition);
944
945 /* Now we check if this failed */
946 if ((Status == STATUS_OBJECT_NAME_NOT_FOUND) && (RootHandle))
947 {
948 /* Target key failed, so we'll need to create its parent. Setup array */
949 HandleArray[0] = NULL;
950 HandleArray[1] = RootHandle;
951
952 /* Keep recursing for each missing parent */
953 while (Recursing)
954 {
955 /* And if we're deep enough, close the last handle */
956 if (NestedCloseLevel > 1) ZwClose(HandleArray[RootHandleIndex]);
957
958 /* We're setup to ping-pong between the two handle array entries */
959 RootHandleIndex = i;
960 i = (i + 1) & 1;
961
962 /* Clear the one we're attempting to open now */
963 HandleArray[i] = NULL;
964
965 /* Process the parent key name */
966 for (p = p1; ((p < pp) && (*p != OBJ_NAME_PATH_SEPARATOR)); p++);
967 Length = (USHORT)(p - p1) * sizeof(WCHAR);
968
969 /* Is there a parent name? */
970 if (Length)
971 {
972 /* Build the unicode string for it */
973 KeyString.Buffer = p1;
974 KeyString.Length = KeyString.MaximumLength = Length;
975
976 /* Now try opening the parent */
978 &KeyString,
980 HandleArray[RootHandleIndex],
981 NULL);
982 Status = ZwCreateKey(&HandleArray[i],
985 0,
986 NULL,
988 &KeyDisposition);
989 if (NT_SUCCESS(Status))
990 {
991 /* It worked, we have one more handle */
992 NestedCloseLevel++;
993 }
994 else
995 {
996 /* Parent key creation failed, abandon loop */
997 Recursing = FALSE;
998 continue;
999 }
1000 }
1001 else
1002 {
1003 /* We don't have a parent name, probably corrupted key name */
1005 Recursing = FALSE;
1006 continue;
1007 }
1008
1009 /* Now see if there's more parents to create */
1010 p1 = p + 1;
1011 if ((p == pp) || (p1 == pp))
1012 {
1013 /* We're done, hopefully successfully, so stop */
1014 Recursing = FALSE;
1015 }
1016 }
1017
1018 /* Outer loop check for handle nesting that requires closing the top handle */
1019 if (NestedCloseLevel > 1) ZwClose(HandleArray[RootHandleIndex]);
1020 }
1021
1022 /* Check if we broke out of the loop due to success */
1023 if (NT_SUCCESS(Status))
1024 {
1025 /* Return the target handle (we closed all the parent ones) and disposition */
1026 *Handle = HandleArray[i];
1027 if (Disposition) *Disposition = KeyDisposition;
1028 }
1029
1030 /* Return the success state */
1031 return Status;
1032}
#define PAGED_CODE()
GLfloat GLfloat p
Definition: glext.h:8902
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_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:56
USHORT MaximumLength
Definition: env_spec_w32.h:370
void * PVOID
Definition: typedefs.h:50

◆ IopFixupDeviceId()

VOID IopFixupDeviceId ( PWCHAR  String)

Definition at line 32 of file pnpmgr.c.

33{
35
36 for (i = 0; i < Length; i++)
37 {
38 if (String[i] == L'\\')
39 String[i] = L'#';
40 }
41}
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
ULONG_PTR SIZE_T
Definition: typedefs.h:80
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433

Referenced by IopInstallCriticalDevice().

◆ IopGetBusTypeGuidIndex()

USHORT NTAPI IopGetBusTypeGuidIndex ( LPGUID  BusTypeGuid)

Definition at line 411 of file pnpmgr.c.

412{
413 USHORT i = 0, FoundIndex = 0xFFFF;
415 PVOID NewList;
416
417 /* Acquire the lock */
419
420 /* Loop all entries */
421 while (i < PnpBusTypeGuidList->GuidCount)
422 {
423 /* Try to find a match */
424 if (RtlCompareMemory(BusTypeGuid,
426 sizeof(GUID)) == sizeof(GUID))
427 {
428 /* Found it */
429 FoundIndex = i;
430 goto Quickie;
431 }
432 i++;
433 }
434
435 /* Check if we have to grow the list */
437 {
438 /* Calculate the new size */
440 (sizeof(GUID) * PnpBusTypeGuidList->GuidCount);
441
442 /* Allocate the new copy */
443 NewList = ExAllocatePool(PagedPool, NewSize);
444
445 if (!NewList)
446 {
447 /* Fail */
449 goto Quickie;
450 }
451
452 /* Now copy them, decrease the size too */
453 NewSize -= sizeof(GUID);
455
456 /* Free the old list */
458
459 /* Use the new buffer */
460 PnpBusTypeGuidList = NewList;
461 }
462
463 /* Copy the new GUID */
465 BusTypeGuid,
466 sizeof(GUID));
467
468 /* The new entry is the index */
469 FoundIndex = (USHORT)PnpBusTypeGuidList->GuidCount;
471
472Quickie:
474 return FoundIndex;
475}
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
_Must_inspect_result_ _In_ USHORT NewSize
Definition: fltkernel.h:975
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
struct _IO_BUS_TYPE_GUID_LIST IO_BUS_TYPE_GUID_LIST
PIO_BUS_TYPE_GUID_LIST PnpBusTypeGuidList
Definition: pnpmgr.c:27
GUID Guids[1]
Definition: io.h:420
FAST_MUTEX Lock
Definition: io.h:419

Referenced by PiInitializeDevNode().

◆ IopGetParentIdPrefix()

NTSTATUS IopGetParentIdPrefix ( PDEVICE_NODE  DeviceNode,
PUNICODE_STRING  ParentIdPrefix 
)

Definition at line 760 of file pnpmgr.c.

762{
763 const UNICODE_STRING EnumKeyPath = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum\\");
764 ULONG KeyNameBufferLength;
765 PKEY_VALUE_PARTIAL_INFORMATION ParentIdPrefixInformation = NULL;
766 UNICODE_STRING KeyName = {0, 0, NULL};
767 UNICODE_STRING KeyValue;
769 HANDLE hKey = NULL;
770 ULONG crc32;
772
773 /* HACK: As long as some devices have a NULL device
774 * instance path, the following test is required :(
775 */
776 if (DeviceNode->Parent->InstancePath.Length == 0)
777 {
778 DPRINT1("Parent of %wZ has NULL Instance path, please report!\n",
779 &DeviceNode->InstancePath);
780 return STATUS_UNSUCCESSFUL;
781 }
782
783 /* 1. Try to retrieve ParentIdPrefix from registry */
784 KeyNameBufferLength = FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data) + sizeof(L"12345678&12345678");
785 ParentIdPrefixInformation = ExAllocatePoolWithTag(PagedPool,
786 KeyNameBufferLength + sizeof(UNICODE_NULL),
787 TAG_IO);
788 if (!ParentIdPrefixInformation)
789 {
791 }
792
793 KeyName.Length = 0;
794 KeyName.MaximumLength = EnumKeyPath.Length +
795 DeviceNode->Parent->InstancePath.Length +
796 sizeof(UNICODE_NULL);
798 KeyName.MaximumLength,
799 TAG_IO);
800 if (!KeyName.Buffer)
801 {
803 goto cleanup;
804 }
805
806 RtlCopyUnicodeString(&KeyName, &EnumKeyPath);
807 RtlAppendUnicodeStringToString(&KeyName, &DeviceNode->Parent->InstancePath);
808
810 if (!NT_SUCCESS(Status))
811 {
812 goto cleanup;
813 }
814 RtlInitUnicodeString(&ValueName, L"ParentIdPrefix");
815 Status = ZwQueryValueKey(hKey,
816 &ValueName,
818 ParentIdPrefixInformation,
819 KeyNameBufferLength,
820 &KeyNameBufferLength);
821 if (NT_SUCCESS(Status))
822 {
823 if (ParentIdPrefixInformation->Type != REG_SZ)
824 {
826 }
827 else
828 {
829 KeyValue.MaximumLength = (USHORT)ParentIdPrefixInformation->DataLength;
830 KeyValue.Length = KeyValue.MaximumLength - sizeof(UNICODE_NULL);
831 KeyValue.Buffer = (PWSTR)ParentIdPrefixInformation->Data;
832 ASSERT(KeyValue.Buffer[KeyValue.Length / sizeof(WCHAR)] == UNICODE_NULL);
833 }
834 goto cleanup;
835 }
837 {
838 /* FIXME how do we get here and why is ParentIdPrefixInformation valid? */
839 KeyValue.MaximumLength = (USHORT)ParentIdPrefixInformation->DataLength;
840 KeyValue.Length = KeyValue.MaximumLength - sizeof(UNICODE_NULL);
841 KeyValue.Buffer = (PWSTR)ParentIdPrefixInformation->Data;
842 ASSERT(KeyValue.Buffer[KeyValue.Length / sizeof(WCHAR)] == UNICODE_NULL);
843 goto cleanup;
844 }
845
846 /* 2. Create the ParentIdPrefix value */
848 (PUCHAR)DeviceNode->Parent->InstancePath.Buffer,
849 DeviceNode->Parent->InstancePath.Length);
850
851 RtlStringCbPrintfW((PWSTR)ParentIdPrefixInformation,
852 KeyNameBufferLength,
853 L"%lx&%lx",
854 DeviceNode->Parent->Level,
855 crc32);
856 RtlInitUnicodeString(&KeyValue, (PWSTR)ParentIdPrefixInformation);
857
858 /* 3. Try to write the ParentIdPrefix to registry */
859 Status = ZwSetValueKey(hKey,
860 &ValueName,
861 0,
862 REG_SZ,
863 KeyValue.Buffer,
864 ((ULONG)wcslen(KeyValue.Buffer) + 1) * sizeof(WCHAR));
865
866cleanup:
867 if (NT_SUCCESS(Status))
868 {
869 /* Duplicate the string to return it */
871 &KeyValue,
872 ParentIdPrefix);
873 }
874 ExFreePoolWithTag(ParentIdPrefixInformation, TAG_IO);
876 if (hKey != NULL)
877 {
878 ZwClose(hKey);
879 }
880 return Status;
881}
#define RtlComputeCrc32
Definition: compat.h:810
#define crc32(crc, buf, len)
Definition: inflate.c:1081
static void cleanup(void)
Definition: main.c:1335
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
Definition: green.h:15
NTSYSAPI NTSTATUS WINAPI RtlDuplicateUnicodeString(int, const UNICODE_STRING *, UNICODE_STRING *)
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
@ KeyValuePartialInformation
Definition: nt_native.h:1182
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define KEY_SET_VALUE
Definition: nt_native.h:1017
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
#define TAG_IO
Definition: tag.h:80
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
unsigned char * PUCHAR
Definition: typedefs.h:53

Referenced by IopCreateDeviceInstancePath().

◆ IopGetRegistryValue()

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

Definition at line 1036 of file pnpmgr.c.

1039{
1040 UNICODE_STRING ValueString;
1042 PKEY_VALUE_FULL_INFORMATION FullInformation;
1043 ULONG Size;
1044 PAGED_CODE();
1045
1046 RtlInitUnicodeString(&ValueString, ValueName);
1047
1048 Status = ZwQueryValueKey(Handle,
1049 &ValueString,
1051 NULL,
1052 0,
1053 &Size);
1054 if ((Status != STATUS_BUFFER_OVERFLOW) &&
1056 {
1057 return Status;
1058 }
1059
1060 FullInformation = ExAllocatePool(NonPagedPool, Size);
1061 if (!FullInformation) return STATUS_INSUFFICIENT_RESOURCES;
1062
1063 Status = ZwQueryValueKey(Handle,
1064 &ValueString,
1066 FullInformation,
1067 Size,
1068 &Size);
1069 if (!NT_SUCCESS(Status))
1070 {
1071 ExFreePool(FullInformation);
1072 return Status;
1073 }
1074
1075 *Information = FullInformation;
1076 return STATUS_SUCCESS;
1077}
#define NonPagedPool
Definition: env_spec_w32.h:307
@ KeyValueFullInformation
Definition: nt_native.h:1181
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_In_ WDFREQUEST _In_ NTSTATUS _In_ ULONG_PTR Information
Definition: wdfrequest.h:1049

Referenced by IopGetDriverNames(), IopInitializeBuiltinDriver(), IopLoadDriver(), IopSetServiceEnumData(), PiAttachFilterDriversCallback(), PiCallDriverAddDevice(), PiGetDeviceRegistryProperty(), PiInitCacheGroupInformation(), PipGetDriverTagPriority(), and PpInitGetGroupOrderIndex().

◆ IopGetSystemPowerDeviceObject()

NTSTATUS IopGetSystemPowerDeviceObject ( PDEVICE_OBJECT DeviceObject)

Definition at line 393 of file pnpmgr.c.

394{
396
398 {
402
403 return STATUS_SUCCESS;
404 }
405
406 return STATUS_UNSUCCESSFUL;
407}
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
KSPIN_LOCK IopDeviceTreeLock
Definition: devnode.c:19
PDEVICE_NODE PopSystemPowerDeviceNode
Definition: power.c:25
PDEVICE_OBJECT PhysicalDeviceObject
Definition: iotypes.h:1005
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

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

483{
484 IO_STACK_LOCATION IoStackLocation;
485
486 /* Fill out the stack information */
487 RtlZeroMemory(&IoStackLocation, sizeof(IO_STACK_LOCATION));
488 IoStackLocation.MajorFunction = IRP_MJ_PNP;
489 IoStackLocation.MinorFunction = MinorFunction;
490 if (Stack)
491 {
492 /* Copy the rest */
493 RtlCopyMemory(&IoStackLocation.Parameters,
495 sizeof(Stack->Parameters));
496 }
497
498 /* Do the PnP call */
500 &IoStackLocation,
502 return IoStatusBlock->Status;
503}
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSTATUS IopSynchronousCall(IN PDEVICE_OBJECT DeviceObject, IN PIO_STACK_LOCATION IoStackLocation, OUT PVOID *Information)
union _IO_STACK_LOCATION::@1575 Parameters
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_In_ UCHAR _In_ UCHAR MinorFunction
Definition: wdfdevice.h:1699
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639

◆ IopInstallCriticalDevice()

VOID NTAPI IopInstallCriticalDevice ( PDEVICE_NODE  DeviceNode)

Definition at line 45 of file pnpmgr.c.

46{
48 HANDLE CriticalDeviceKey, InstanceKey;
50 UNICODE_STRING CriticalDeviceKeyU = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\CriticalDeviceDatabase");
51 UNICODE_STRING CompatibleIdU = RTL_CONSTANT_STRING(L"CompatibleIDs");
52 UNICODE_STRING HardwareIdU = RTL_CONSTANT_STRING(L"HardwareID");
53 UNICODE_STRING ServiceU = RTL_CONSTANT_STRING(L"Service");
54 UNICODE_STRING ClassGuidU = RTL_CONSTANT_STRING(L"ClassGUID");
56 ULONG HidLength = 0, CidLength = 0, BufferLength;
57 PWCHAR IdBuffer, OriginalIdBuffer;
58
59 /* Open the device instance key */
60 Status = IopCreateDeviceKeyPath(&DeviceNode->InstancePath, REG_OPTION_NON_VOLATILE, &InstanceKey);
62 return;
63
64 Status = ZwQueryValueKey(InstanceKey,
65 &HardwareIdU,
67 NULL,
68 0,
69 &HidLength);
71 {
72 ZwClose(InstanceKey);
73 return;
74 }
75
76 Status = ZwQueryValueKey(InstanceKey,
77 &CompatibleIdU,
79 NULL,
80 0,
81 &CidLength);
83 {
84 CidLength = 0;
85 }
86
87 BufferLength = HidLength + CidLength;
88 BufferLength -= (((CidLength != 0) ? 2 : 1) * FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data));
89
90 /* Allocate a buffer to hold data from both */
91 OriginalIdBuffer = IdBuffer = ExAllocatePool(PagedPool, BufferLength);
92 if (!IdBuffer)
93 {
94 ZwClose(InstanceKey);
95 return;
96 }
97
98 /* Compute the buffer size */
99 if (HidLength > CidLength)
100 BufferLength = HidLength;
101 else
102 BufferLength = CidLength;
103
104 PartialInfo = ExAllocatePool(PagedPool, BufferLength);
105 if (!PartialInfo)
106 {
107 ZwClose(InstanceKey);
108 ExFreePool(OriginalIdBuffer);
109 return;
110 }
111
112 Status = ZwQueryValueKey(InstanceKey,
113 &HardwareIdU,
115 PartialInfo,
116 HidLength,
117 &HidLength);
118 if (Status != STATUS_SUCCESS)
119 {
120 ExFreePool(PartialInfo);
121 ExFreePool(OriginalIdBuffer);
122 ZwClose(InstanceKey);
123 return;
124 }
125
126 /* Copy in HID info first (without 2nd terminating NULL if CID is present) */
127 HidLength = PartialInfo->DataLength - ((CidLength != 0) ? sizeof(WCHAR) : 0);
128 RtlCopyMemory(IdBuffer, PartialInfo->Data, HidLength);
129
130 if (CidLength != 0)
131 {
132 Status = ZwQueryValueKey(InstanceKey,
133 &CompatibleIdU,
135 PartialInfo,
136 CidLength,
137 &CidLength);
138 if (Status != STATUS_SUCCESS)
139 {
140 ExFreePool(PartialInfo);
141 ExFreePool(OriginalIdBuffer);
142 ZwClose(InstanceKey);
143 return;
144 }
145
146 /* Copy CID next */
147 CidLength = PartialInfo->DataLength;
148 RtlCopyMemory(((PUCHAR)IdBuffer) + HidLength, PartialInfo->Data, CidLength);
149 }
150
151 /* Free our temp buffer */
152 ExFreePool(PartialInfo);
153
155 &CriticalDeviceKeyU,
157 NULL,
158 NULL);
159 Status = ZwOpenKey(&CriticalDeviceKey,
162 if (!NT_SUCCESS(Status))
163 {
164 /* The critical device database doesn't exist because
165 * we're probably in 1st stage setup, but it's ok */
166 ExFreePool(OriginalIdBuffer);
167 ZwClose(InstanceKey);
168 return;
169 }
170
171 while (*IdBuffer)
172 {
173 USHORT StringLength = (USHORT)wcslen(IdBuffer) + 1, Index;
174
175 IopFixupDeviceId(IdBuffer);
176
177 /* Look through all subkeys for a match */
178 for (Index = 0; TRUE; Index++)
179 {
180 ULONG NeededLength;
181 PKEY_BASIC_INFORMATION BasicInfo;
182
183 Status = ZwEnumerateKey(CriticalDeviceKey,
184 Index,
186 NULL,
187 0,
188 &NeededLength);
190 break;
192 {
193 UNICODE_STRING ChildIdNameU, RegKeyNameU;
194
195 BasicInfo = ExAllocatePool(PagedPool, NeededLength);
196 if (!BasicInfo)
197 {
198 /* No memory */
199 ExFreePool(OriginalIdBuffer);
200 ZwClose(CriticalDeviceKey);
201 ZwClose(InstanceKey);
202 return;
203 }
204
205 Status = ZwEnumerateKey(CriticalDeviceKey,
206 Index,
208 BasicInfo,
209 NeededLength,
210 &NeededLength);
211 if (Status != STATUS_SUCCESS)
212 {
213 /* This shouldn't happen */
214 ExFreePool(BasicInfo);
215 continue;
216 }
217
218 ChildIdNameU.Buffer = IdBuffer;
219 ChildIdNameU.MaximumLength = ChildIdNameU.Length = (StringLength - 1) * sizeof(WCHAR);
220 RegKeyNameU.Buffer = BasicInfo->Name;
221 RegKeyNameU.MaximumLength = RegKeyNameU.Length = (USHORT)BasicInfo->NameLength;
222
223 if (RtlEqualUnicodeString(&ChildIdNameU, &RegKeyNameU, TRUE))
224 {
225 HANDLE ChildKeyHandle;
226
228 &ChildIdNameU,
230 CriticalDeviceKey,
231 NULL);
232
233 Status = ZwOpenKey(&ChildKeyHandle,
236 if (Status != STATUS_SUCCESS)
237 {
238 ExFreePool(BasicInfo);
239 continue;
240 }
241
242 /* Check if there's already a driver installed */
243 Status = ZwQueryValueKey(InstanceKey,
244 &ClassGuidU,
246 NULL,
247 0,
248 &NeededLength);
250 {
251 ExFreePool(BasicInfo);
252 continue;
253 }
254
255 Status = ZwQueryValueKey(ChildKeyHandle,
256 &ClassGuidU,
258 NULL,
259 0,
260 &NeededLength);
262 {
263 ExFreePool(BasicInfo);
264 continue;
265 }
266
267 PartialInfo = ExAllocatePool(PagedPool, NeededLength);
268 if (!PartialInfo)
269 {
270 ExFreePool(OriginalIdBuffer);
271 ExFreePool(BasicInfo);
272 ZwClose(InstanceKey);
273 ZwClose(ChildKeyHandle);
274 ZwClose(CriticalDeviceKey);
275 return;
276 }
277
278 /* Read ClassGUID entry in the CDDB */
279 Status = ZwQueryValueKey(ChildKeyHandle,
280 &ClassGuidU,
282 PartialInfo,
283 NeededLength,
284 &NeededLength);
285 if (Status != STATUS_SUCCESS)
286 {
287 ExFreePool(BasicInfo);
288 continue;
289 }
290
291 /* Write it to the ENUM key */
292 Status = ZwSetValueKey(InstanceKey,
293 &ClassGuidU,
294 0,
295 REG_SZ,
296 PartialInfo->Data,
297 PartialInfo->DataLength);
298 if (Status != STATUS_SUCCESS)
299 {
300 ExFreePool(BasicInfo);
301 ExFreePool(PartialInfo);
302 ZwClose(ChildKeyHandle);
303 continue;
304 }
305
306 Status = ZwQueryValueKey(ChildKeyHandle,
307 &ServiceU,
309 NULL,
310 0,
311 &NeededLength);
313 {
314 ExFreePool(PartialInfo);
315 PartialInfo = ExAllocatePool(PagedPool, NeededLength);
316 if (!PartialInfo)
317 {
318 ExFreePool(OriginalIdBuffer);
319 ExFreePool(BasicInfo);
320 ZwClose(InstanceKey);
321 ZwClose(ChildKeyHandle);
322 ZwClose(CriticalDeviceKey);
323 return;
324 }
325
326 /* Read the service entry from the CDDB */
327 Status = ZwQueryValueKey(ChildKeyHandle,
328 &ServiceU,
330 PartialInfo,
331 NeededLength,
332 &NeededLength);
333 if (Status != STATUS_SUCCESS)
334 {
335 ExFreePool(BasicInfo);
336 ExFreePool(PartialInfo);
337 ZwClose(ChildKeyHandle);
338 continue;
339 }
340
341 /* Write it to the ENUM key */
342 Status = ZwSetValueKey(InstanceKey,
343 &ServiceU,
344 0,
345 REG_SZ,
346 PartialInfo->Data,
347 PartialInfo->DataLength);
348 if (Status != STATUS_SUCCESS)
349 {
350 ExFreePool(BasicInfo);
351 ExFreePool(PartialInfo);
352 ZwClose(ChildKeyHandle);
353 continue;
354 }
355
356 DPRINT("Installed service '%S' for critical device '%wZ'\n", PartialInfo->Data, &ChildIdNameU);
357 }
358 else
359 {
360 DPRINT1("Installed NULL service for critical device '%wZ'\n", &ChildIdNameU);
361 }
362
363 ExFreePool(OriginalIdBuffer);
364 ExFreePool(PartialInfo);
365 ExFreePool(BasicInfo);
366 ZwClose(InstanceKey);
367 ZwClose(ChildKeyHandle);
368 ZwClose(CriticalDeviceKey);
369
370 /* That's it */
371 return;
372 }
373
374 ExFreePool(BasicInfo);
375 }
376 else
377 {
378 /* Umm, not sure what happened here */
379 continue;
380 }
381 }
382
383 /* Advance to the next ID */
384 IdBuffer += StringLength;
385 }
386
387 ExFreePool(OriginalIdBuffer);
388 ZwClose(InstanceKey);
389 ZwClose(CriticalDeviceKey);
390}
if(dx< 0)
Definition: linetemp.h:194
@ KeyBasicInformation
Definition: nt_native.h:1131
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:205
NTSTATUS NTAPI IopCreateDeviceKeyPath(IN PCUNICODE_STRING RegistryPath, IN ULONG CreateOptions, OUT PHANDLE Handle)
Definition: pnpmgr.c:522
VOID IopFixupDeviceId(PWCHAR String)
Definition: pnpmgr.c:32
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by PiInitializeDevNode().

◆ IopOpenRegistryKeyEx()

◆ IopSetDeviceInstanceData()

NTSTATUS IopSetDeviceInstanceData ( HANDLE  InstanceKey,
PDEVICE_NODE  DeviceNode 
)

Definition at line 606 of file pnpmgr.c.

608{
611 HANDLE LogConfKey, ControlKey, DeviceParamsKey;
612 ULONG ResCount;
615
616 DPRINT("IopSetDeviceInstanceData() called\n");
617
618 /* Create the 'LogConf' key */
619 RtlInitUnicodeString(&KeyName, L"LogConf");
621 &KeyName,
623 InstanceKey,
624 NULL);
625 Status = ZwCreateKey(&LogConfKey,
628 0,
629 NULL,
630 // FIXME? In r53694 it was silently turned from non-volatile into this,
631 // without any extra warning. Is this still needed??
633 NULL);
634 if (NT_SUCCESS(Status))
635 {
636 /* Set 'BootConfig' value */
637 if (DeviceNode->BootResources != NULL)
638 {
639 ResCount = DeviceNode->BootResources->Count;
640 if (ResCount != 0)
641 {
642 RtlInitUnicodeString(&KeyName, L"BootConfig");
643 Status = ZwSetValueKey(LogConfKey,
644 &KeyName,
645 0,
647 DeviceNode->BootResources,
649 }
650 }
651
652 /* Set 'BasicConfigVector' value */
653 if (DeviceNode->ResourceRequirements != NULL &&
654 DeviceNode->ResourceRequirements->ListSize != 0)
655 {
656 RtlInitUnicodeString(&KeyName, L"BasicConfigVector");
657 Status = ZwSetValueKey(LogConfKey,
658 &KeyName,
659 0,
661 DeviceNode->ResourceRequirements,
662 DeviceNode->ResourceRequirements->ListSize);
663 }
664
665 ZwClose(LogConfKey);
666 }
667
668 /* Set the 'ConfigFlags' value */
669 RtlInitUnicodeString(&KeyName, L"ConfigFlags");
670 Status = ZwQueryValueKey(InstanceKey,
671 &KeyName,
673 NULL,
674 0,
675 &ResultLength);
677 {
678 /* Write the default value */
679 ULONG DefaultConfigFlags = 0;
680 Status = ZwSetValueKey(InstanceKey,
681 &KeyName,
682 0,
683 REG_DWORD,
684 &DefaultConfigFlags,
685 sizeof(DefaultConfigFlags));
686 }
687
688 /* Create the 'Control' key */
689 RtlInitUnicodeString(&KeyName, L"Control");
691 &KeyName,
693 InstanceKey,
694 NULL);
695 Status = ZwCreateKey(&ControlKey,
696 0,
698 0,
699 NULL,
701 NULL);
702 if (NT_SUCCESS(Status))
703 ZwClose(ControlKey);
704
705 /* Create the 'Device Parameters' key and set the 'FirmwareIdentified' value for all ACPI-enumerated devices */
706 if (_wcsnicmp(DeviceNode->InstancePath.Buffer, L"ACPI\\", 5) == 0)
707 {
708 RtlInitUnicodeString(&KeyName, L"Device Parameters");
710 &KeyName,
712 InstanceKey,
713 NULL);
714 Status = ZwCreateKey(&DeviceParamsKey,
715 0,
717 0,
718 NULL,
720 NULL);
721 if (NT_SUCCESS(Status))
722 {
723 ULONG FirmwareIdentified = 1;
724 RtlInitUnicodeString(&KeyName, L"FirmwareIdentified");
725 Status = ZwSetValueKey(DeviceParamsKey,
726 &KeyName,
727 0,
728 REG_DWORD,
729 &FirmwareIdentified,
730 sizeof(FirmwareIdentified));
731
732 ZwClose(DeviceParamsKey);
733 }
734 }
735
736 DPRINT("IopSetDeviceInstanceData() done\n");
737
738 return Status;
739}
@ KeyValueBasicInformation
Definition: nt_native.h:1180
#define REG_RESOURCE_REQUIREMENTS_LIST
Definition: nt_native.h:1504
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
_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)

Referenced by IoReportDetectedDevice(), PiControlInitializeDevice(), and PiInitializeDevNode().

◆ IoSynchronousInvalidateDeviceRelations()

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

Definition at line 1798 of file pnpmgr.c.

1801{
1802 PAGED_CODE();
1803
1805 {
1806 KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, 0x2, (ULONG_PTR)DeviceObject, 0, 0);
1807 }
1808
1809 switch (Type)
1810 {
1811 case BusRelations:
1812 /* Enumerate the device */
1814 case PowerRelations:
1815 /* Not handled yet */
1818 /* Nothing to do */
1819 return STATUS_SUCCESS;
1820 default:
1821 /* Ejection relations are not supported */
1822 return STATUS_NOT_SUPPORTED;
1823 }
1824}
NTSTATUS PiPerformSyncDeviceAction(_In_ PDEVICE_OBJECT DeviceObject, _In_ DEVICE_ACTION Action)
Perfom a device operation synchronously via PiQueueDeviceAction.
Definition: devaction.c:2718
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
@ TargetDeviceRelation
Definition: iotypes.h:2156
@ PowerRelations
Definition: iotypes.h:2154

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

1836{
1837 /* FIXME: Notify the resource arbiter */
1838
1840 BusNumber,
1841 BusAddress,
1844}
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
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID InterfaceType
Definition: wdffdo.h:463
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:160
_In_ ULONG _In_ PHYSICAL_ADDRESS BusAddress
Definition: iofuncs.h:2273
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG _Out_ PPHYSICAL_ADDRESS TranslatedAddress
Definition: iofuncs.h:2275
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2274

◆ PiAllocateGenericTableEntry()

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

Definition at line 1097 of file pnpmgr.c.

1099{
1100 /* FIXME: TODO */
1101 ASSERT(FALSE);
1102 return NULL;
1103}

Referenced by PpInitializeDeviceReferenceTable().

◆ PiCompareInstancePath()

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

Definition at line 1081 of file pnpmgr.c.

1084{
1085 /* FIXME: TODO */
1086 ASSERT(FALSE);
1087 return 0;
1088}

Referenced by PpInitializeDeviceReferenceTable().

◆ PiFreeGenericTableEntry()

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

Definition at line 1107 of file pnpmgr.c.

1109{
1110 /* FIXME: TODO */
1111 ASSERT(FALSE);
1112}

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

1297{
1299 HANDLE KeyHandle, SubHandle;
1300 UNICODE_STRING KeyString;
1301 PKEY_VALUE_FULL_INFORMATION KeyValueInfo = NULL;
1302 ULONG Length;
1303 PAGED_CODE();
1304
1305 /* Find the instance key */
1307 if (NT_SUCCESS(Status))
1308 {
1309 /* Check for name given by caller */
1310 if (KeyName)
1311 {
1312 /* Open this key */
1313 RtlInitUnicodeString(&KeyString, KeyName);
1314 Status = IopOpenRegistryKeyEx(&SubHandle,
1315 KeyHandle,
1316 &KeyString,
1317 KEY_READ);
1318 if (NT_SUCCESS(Status))
1319 {
1320 /* And use this handle instead */
1322 KeyHandle = SubHandle;
1323 }
1324 }
1325
1326 /* Check if sub-key handle succeeded (or no-op if no key name given) */
1327 if (NT_SUCCESS(Status))
1328 {
1329 /* Now get the size of the property */
1331 ValueName,
1332 &KeyValueInfo);
1333 }
1334
1335 /* Close the key */
1337 }
1338
1339 /* Fail if any of the registry operations failed */
1340 if (!NT_SUCCESS(Status)) return Status;
1341
1342 /* Check how much data we have to copy */
1343 Length = KeyValueInfo->DataLength;
1344 if (*BufferLength >= Length)
1345 {
1346 /* Check for a match in the value type */
1347 if (KeyValueInfo->Type == ValueType)
1348 {
1349 /* Copy the data */
1351 (PVOID)((ULONG_PTR)KeyValueInfo +
1352 KeyValueInfo->DataOffset),
1353 Length);
1354 }
1355 else
1356 {
1357 /* Invalid registry property type, fail */
1359 }
1360 }
1361 else
1362 {
1363 /* Buffer is too small to hold data */
1365 }
1366
1367 /* Return the required buffer length, free the buffer, and return status */
1369 ExFreePool(KeyValueInfo);
1370 return Status;
1371}
Definition: bufpool.h:45
#define KEY_READ
Definition: nt_native.h:1023
NTSTATUS NTAPI IopGetRegistryValue(IN HANDLE Handle, IN PWSTR ValueName, OUT PKEY_VALUE_FULL_INFORMATION *Information)
Definition: pnpmgr.c:1036
NTSTATUS NTAPI PnpDeviceObjectToDeviceInstance(IN PDEVICE_OBJECT DeviceObject, IN PHANDLE DeviceInstanceHandle, IN ACCESS_MASK DesiredAccess)
Definition: pnpmgr.c:1197

Referenced by IoGetDeviceProperty().

◆ PiInitPhase0()

BOOLEAN NTAPI PiInitPhase0 ( VOID  )

Definition at line 1130 of file pnpmgr.c.

1131{
1132 /* Initialize the resource when accessing device registry data */
1134
1135 /* Setup the device reference AVL table */
1137 return TRUE;
1138}
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
ERESOURCE PpRegistryDeviceResource
Definition: pnpmgr.c:18
VOID NTAPI PpInitializeDeviceReferenceTable(VOID)
Definition: pnpmgr.c:1116

Referenced by PpInitSystem().

◆ PnpBusTypeGuidGet()

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

Definition at line 1170 of file pnpmgr.c.

1172{
1174
1175 /* Acquire the lock */
1177
1178 /* Validate size */
1179 if (Index < PnpBusTypeGuidList->GuidCount)
1180 {
1181 /* Copy the data */
1182 RtlCopyMemory(BusTypeGuid, &PnpBusTypeGuidList->Guids[Index], sizeof(GUID));
1183 }
1184 else
1185 {
1186 /* Failure path */
1188 }
1189
1190 /* Release lock and return status */
1192 return Status;
1193}

Referenced by IoGetDeviceProperty().

◆ PnpDetermineResourceListSize()

ULONG NTAPI PnpDetermineResourceListSize ( IN PCM_RESOURCE_LIST  ResourceList)

Definition at line 1237 of file pnpmgr.c.

1238{
1239 ULONG FinalSize, PartialSize, EntrySize, i, j;
1240 PCM_FULL_RESOURCE_DESCRIPTOR FullDescriptor;
1241 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
1242
1243 /* If we don't have one, that's easy */
1244 if (!ResourceList) return 0;
1245
1246 /* Start with the minimum size possible */
1247 FinalSize = FIELD_OFFSET(CM_RESOURCE_LIST, List);
1248
1249 /* Loop each full descriptor */
1250 FullDescriptor = ResourceList->List;
1251 for (i = 0; i < ResourceList->Count; i++)
1252 {
1253 /* Start with the minimum size possible */
1254 PartialSize = FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList) +
1255 FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors);
1256
1257 /* Loop each partial descriptor */
1258 PartialDescriptor = FullDescriptor->PartialResourceList.PartialDescriptors;
1259 for (j = 0; j < FullDescriptor->PartialResourceList.Count; j++)
1260 {
1261 /* Start with the minimum size possible */
1263
1264 /* Check if there is extra data */
1265 if (PartialDescriptor->Type == CmResourceTypeDeviceSpecific)
1266 {
1267 /* Add that data */
1268 EntrySize += PartialDescriptor->u.DeviceSpecificData.DataSize;
1269 }
1270
1271 /* The size of partial descriptors is bigger */
1272 PartialSize += EntrySize;
1273
1274 /* Go to the next partial descriptor */
1275 PartialDescriptor = (PVOID)((ULONG_PTR)PartialDescriptor + EntrySize);
1276 }
1277
1278 /* The size of full descriptors is bigger */
1279 FinalSize += PartialSize;
1280
1281 /* Go to the next full descriptor */
1282 FullDescriptor = (PVOID)((ULONG_PTR)FullDescriptor + PartialSize);
1283 }
1284
1285 /* Return the final size */
1286 return FinalSize;
1287}
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
#define CmResourceTypeDeviceSpecific
Definition: hwresource.cpp:127
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR CM_PARTIAL_RESOURCE_DESCRIPTOR
CM_PARTIAL_RESOURCE_LIST PartialResourceList
Definition: hwresource.cpp:160
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@391::@400 DeviceSpecificData
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@391 u
CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1]
Definition: hwresource.cpp:119
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:309
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
_In_ UCHAR EntrySize
Definition: iofuncs.h:642

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

1200{
1204 UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\REGISTRY\\MACHINE\\SYSTEM\\CURRENTCONTROLSET\\ENUM");
1205 PAGED_CODE();
1206
1207 /* Open the enum key */
1209 NULL,
1210 &KeyName,
1211 KEY_READ);
1212 if (!NT_SUCCESS(Status)) return Status;
1213
1214 /* Make sure we have an instance path */
1216 if ((DeviceNode) && (DeviceNode->InstancePath.Length))
1217 {
1218 /* Get the instance key */
1219 Status = IopOpenRegistryKeyEx(DeviceInstanceHandle,
1220 KeyHandle,
1221 &DeviceNode->InstancePath,
1223 }
1224 else
1225 {
1226 /* Fail */
1228 }
1229
1230 /* Close the handle and return status */
1232 return Status;
1233}

Referenced by PiGetDeviceRegistryProperty().

◆ PpInitializeDeviceReferenceTable()

VOID NTAPI PpInitializeDeviceReferenceTable ( VOID  )

Definition at line 1116 of file pnpmgr.c.

1117{
1118 /* Setup the guarded mutex and AVL table */
1125 NULL);
1126}
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
VOID FASTCALL KeInitializeGuardedMutex(OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:31
KGUARDED_MUTEX PpDeviceReferenceTableLock
Definition: pnpmgr.c:19
VOID NTAPI PiFreeGenericTableEntry(IN PRTL_AVL_TABLE Table, IN PVOID Buffer)
Definition: pnpmgr.c:1107
RTL_AVL_TABLE PpDeviceReferenceTable
Definition: pnpmgr.c:20
PVOID NTAPI PiAllocateGenericTableEntry(IN PRTL_AVL_TABLE Table, IN CLONG ByteSize)
Definition: pnpmgr.c:1097
RTL_GENERIC_COMPARE_RESULTS NTAPI PiCompareInstancePath(IN PRTL_AVL_TABLE Table, IN PVOID FirstStruct, IN PVOID SecondStruct)
Definition: pnpmgr.c:1081
RTL_AVL_FREE_ROUTINE * PRTL_AVL_FREE_ROUTINE
Definition: rtltypes.h:421
RTL_AVL_ALLOCATE_ROUTINE * PRTL_AVL_ALLOCATE_ROUTINE
Definition: rtltypes.h:413
RTL_AVL_COMPARE_ROUTINE * PRTL_AVL_COMPARE_ROUTINE
Definition: rtltypes.h:404

Referenced by PiInitPhase0().

◆ PpInitSystem()

BOOLEAN NTAPI PpInitSystem ( VOID  )

Definition at line 1142 of file pnpmgr.c.

1143{
1144 /* Check the initialization phase */
1145 switch (ExpInitializationPhase)
1146 {
1147 case 0:
1148
1149 /* Do Phase 0 */
1150 return PiInitPhase0();
1151
1152 case 1:
1153
1154 /* Do Phase 1 */
1155 return TRUE;
1156 //return PiInitPhase1();
1157
1158 default:
1159
1160 /* Don't know any other phase! Bugcheck! */
1161 KeBugCheck(UNEXPECTED_INITIALIZATION_CALL);
1162 return FALSE;
1163 }
1164}
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1430
ULONG ExpInitializationPhase
Definition: init.c:68
BOOLEAN NTAPI PiInitPhase0(VOID)
Definition: pnpmgr.c:1130

Referenced by ExpInitializeExecutive(), and Phase1InitializationDiscard().

Variable Documentation

◆ ExpInitializationPhase

ULONG ExpInitializationPhase
extern

Definition at line 68 of file init.c.

Referenced by PpInitSystem().

◆ IopRootDriverObject

PDRIVER_OBJECT IopRootDriverObject

◆ 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().