ReactOS 0.4.17-dev-116-ga4b6fe9
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 1373 of file pnpmgr.c.

◆ PIP_RETURN_DATA

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

Definition at line 1372 of file pnpmgr.c.

◆ PIP_UNIMPLEMENTED

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

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

1386{
1388 DEVICE_CAPABILITIES DeviceCaps;
1390 PWCHAR ValueName = NULL, EnumeratorNameEnd, DeviceInstanceName;
1391 PVOID Data = NULL;
1393 GUID BusTypeGuid;
1394 POBJECT_NAME_INFORMATION ObjectNameInfo = NULL;
1395 BOOLEAN NullTerminate = FALSE;
1397
1398 DPRINT("IoGetDeviceProperty(0x%p %d)\n", DeviceObject, DeviceProperty);
1399
1400 /* Assume failure */
1401 *ResultLength = 0;
1402
1403 /* Only PDOs can call this */
1405
1406 /* Handle all properties */
1407 switch (DeviceProperty)
1408 {
1410
1411 /* Get the GUID from the internal cache */
1412 Status = PnpBusTypeGuidGet(DeviceNode->ChildBusTypeIndex, &BusTypeGuid);
1413 if (!NT_SUCCESS(Status)) return Status;
1414
1415 /* This is the format of the returned data */
1416 PIP_RETURN_DATA(sizeof(GUID), &BusTypeGuid);
1417
1419
1420 /* Validate correct interface type */
1421 if (DeviceNode->ChildInterfaceType == InterfaceTypeUndefined)
1423
1424 /* This is the format of the returned data */
1425 PIP_RETURN_DATA(sizeof(INTERFACE_TYPE), &DeviceNode->ChildInterfaceType);
1426
1428
1429 /* Validate correct bus number */
1430 if ((DeviceNode->ChildBusNumber & 0x80000000) == 0x80000000)
1432
1433 /* This is the format of the returned data */
1434 PIP_RETURN_DATA(sizeof(ULONG), &DeviceNode->ChildBusNumber);
1435
1437
1438 /* Get the instance path */
1439 DeviceInstanceName = DeviceNode->InstancePath.Buffer;
1440
1441 /* Sanity checks */
1442 ASSERT((BufferLength & 1) == 0);
1443 ASSERT(DeviceInstanceName != NULL);
1444
1445 /* Get the name from the path */
1446 EnumeratorNameEnd = wcschr(DeviceInstanceName, OBJ_NAME_PATH_SEPARATOR);
1447 ASSERT(EnumeratorNameEnd);
1448
1449 /* This string needs to be NULL-terminated */
1450 NullTerminate = TRUE;
1451
1452 /* This is the format of the returned data */
1453 PIP_RETURN_DATA((ULONG)(EnumeratorNameEnd - DeviceInstanceName) * sizeof(WCHAR),
1454 DeviceInstanceName);
1455
1457
1458 /* Query the device caps */
1460 if (!NT_SUCCESS(Status) || (DeviceCaps.Address == MAXULONG))
1462
1463 /* This is the format of the returned data */
1464 PIP_RETURN_DATA(sizeof(ULONG), &DeviceCaps.Address);
1465
1467
1468 /* Validate we have resources */
1469 if (!DeviceNode->BootResources)
1470// if (!DeviceNode->BootResourcesTranslated) // FIXFIX: Need this field
1471 {
1472 /* No resources will still fake success, but with 0 bytes */
1473 *ResultLength = 0;
1474 return STATUS_SUCCESS;
1475 }
1476
1477 /* This is the format of the returned data */
1478 PIP_RETURN_DATA(PnpDetermineResourceListSize(DeviceNode->BootResources), // FIXFIX: Should use BootResourcesTranslated
1479 DeviceNode->BootResources); // FIXFIX: Should use BootResourcesTranslated
1480
1482
1483 /* Sanity check for Unicode-sized string */
1484 ASSERT((BufferLength & 1) == 0);
1485
1486 /* Allocate name buffer */
1488 ObjectNameInfo = ExAllocatePool(PagedPool, Length);
1489 if (!ObjectNameInfo) return STATUS_INSUFFICIENT_RESOURCES;
1490
1491 /* Query the PDO name */
1493 ObjectNameInfo,
1494 Length,
1495 ResultLength);
1497 {
1498 /* It's up to the caller to try again */
1500 }
1501
1502 /* This string needs to be NULL-terminated */
1503 NullTerminate = TRUE;
1504
1505 /* Return if successful */
1506 if (NT_SUCCESS(Status)) PIP_RETURN_DATA(ObjectNameInfo->Name.Length,
1507 ObjectNameInfo->Name.Buffer);
1508
1509 /* Let the caller know how big the name is */
1511 break;
1512
1514
1515 Policy = DeviceNode->RemovalPolicy;
1516 PIP_RETURN_DATA(sizeof(Policy), &Policy);
1517
1518 /* Handle the registry-based properties */
1542 //PIP_REGISTRY_DATA(REGSTR_VAL_CONTAINERID, REG_SZ); // Win7
1544 break;
1547 break;
1552 default:
1554 }
1555
1556 /* Having a registry value name implies registry data */
1557 if (ValueName)
1558 {
1559 /* We know up-front how much data to expect */
1561
1562 /* Go get the data, use the LogConf subkey if necessary */
1564 ValueType,
1565 ValueName,
1566 (DeviceProperty ==
1568 L"LogConf": NULL,
1570 ResultLength);
1571 }
1572 else if (NT_SUCCESS(Status))
1573 {
1574 /* We know up-front how much data to expect, check the caller's buffer */
1575 *ResultLength = ReturnLength + (NullTerminate ? sizeof(UNICODE_NULL) : 0);
1576 if (*ResultLength <= BufferLength)
1577 {
1578 /* Buffer is all good, copy the data */
1580
1581 /* Check if we need to NULL-terminate the string */
1582 if (NullTerminate)
1583 {
1584 /* Terminate the string */
1586 }
1587
1588 /* This is the success path */
1590 }
1591 else
1592 {
1593 /* Failure path */
1595 }
1596 }
1597
1598 /* Free any allocation we may have made, and return the status code */
1599 if (ObjectNameInfo) ExFreePool(ObjectNameInfo);
1600 return Status;
1601}
_In_ PVOID _In_ ULONG _Out_ PVOID _In_ ULONG _Inout_ PULONG ReturnLength
@ DeviceNode
Definition: Node.h:9
unsigned char BOOLEAN
Definition: actypes.h:127
#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
#define L(x)
Definition: resources.c:13
#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
#define REG_SZ
Definition: layer.c:22
#define ASSERT(a)
Definition: mode.c:44
#define REG_RESOURCE_LIST
Definition: nt_native.h:1505
struct _OBJECT_NAME_INFORMATION OBJECT_NAME_INFORMATION
#define REG_MULTI_SZ
Definition: nt_native.h:1504
#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:857
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:570
NTSTATUS NTAPI ObQueryNameString(IN PVOID Object, OUT POBJECT_NAME_INFORMATION ObjectNameInfo, IN ULONG Length, OUT PULONG ReturnLength)
Definition: obname.c:1207
short WCHAR
Definition: pedump.c:58
ULONG NTAPI PnpDetermineResourceListSize(IN PCM_RESOURCE_LIST ResourceList)
Definition: pnpmgr.c:1236
#define PIP_REGISTRY_DATA(x, y)
Definition: pnpmgr.c:1373
#define PIP_UNIMPLEMENTED()
Definition: pnpmgr.c:1374
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:1290
#define PIP_RETURN_DATA(x, y)
Definition: pnpmgr.c:1372
NTSTATUS NTAPI PnpBusTypeGuidGet(IN USHORT Index, IN LPGUID BusTypeGuid)
Definition: pnpmgr.c:1169
#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
@ InterfaceTypeUndefined
Definition: restypes.h:120
enum _INTERFACE_TYPE INTERFACE_TYPE
#define REG_DWORD
Definition: sdbapi.c:615
#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:2061
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3782
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ ULONG _Out_ PVOID PropertyBuffer
Definition: wdfdevice.h:4443
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY DeviceProperty
Definition: wdfdevice.h:3775
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3777
_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

Referenced by Bus_AddDevice(), ClasspInitializeHotplugInfo(), DcInitializeAdapterLocation(), GetBusInterface(), InPortAddDevice(), IntVideoPortCreateAdapterDeviceObject(), IoGetDmaAdapter(), IoOpenDeviceRegistryKey(), IopGetDeviceProperty(), IopUpdateResourceMap(), IsaFdoQueryInterface(), KspStartBusDevice(), NdisIAddDevice(), NdisIPnPStartDevice(), PcGetDeviceProperty(), PciDetermineSlotNumber(), PciGetDeviceProperty(), PciIdexGetBusLocation(), 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 1771 of file pnpmgr.c.

1774{
1776 {
1777 KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, 0x2, (ULONG_PTR)DeviceObject, 0, 0);
1778 }
1779
1780 switch (Type)
1781 {
1782 case BusRelations:
1783 /* Enumerate the device */
1785 break;
1786 default:
1787 /* Everything else is not implemented */
1788 break;
1789 }
1790}
Type
Definition: Type.h:7
DECLSPEC_NORETURN VOID NTAPI KeBugCheckEx(IN ULONG BugCheckCode, IN ULONG_PTR BugCheckParameter1, IN ULONG_PTR BugCheckParameter2, IN ULONG_PTR BugCheckParameter3, IN ULONG_PTR BugCheckParameter4)
Definition: debug.c:485
#define IopIsValidPhysicalDeviceObject(PhysicalDeviceObject)
Definition: io.h:241
@ PiActionEnumDeviceTree
Definition: io.h:525
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:2668
uint32_t ULONG_PTR
Definition: typedefs.h:65
@ BusRelations
Definition: iotypes.h:2154

Referenced by _Function_class_(), add_volume_device(), AtaFdoDeviceControl(), AtaPortExitStateMachine(), 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()

◆ IoOpenDeviceRegistryKey()

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

Definition at line 1620 of file pnpmgr.c.

1624{
1625 static WCHAR RootKeyName[] =
1626 L"\\Registry\\Machine\\System\\CurrentControlSet\\";
1627 static WCHAR ProfileKeyName[] =
1628 L"Hardware Profiles\\Current\\System\\CurrentControlSet\\";
1629 static WCHAR ClassKeyName[] = L"Control\\Class\\";
1630 static WCHAR EnumKeyName[] = L"Enum\\";
1631 static WCHAR DeviceParametersKeyName[] = L"Device Parameters";
1633 PWSTR KeyNameBuffer;
1635 ULONG DriverKeyLength;
1639
1640 DPRINT("IoOpenDeviceRegistryKey() called\n");
1641
1643 {
1644 DPRINT1("IoOpenDeviceRegistryKey(): got wrong params, exiting...\n");
1646 }
1647
1651
1652 /*
1653 * Calculate the length of the base key name. This is the full
1654 * name for driver key or the name excluding "Device Parameters"
1655 * subkey for device key.
1656 */
1657
1658 KeyNameLength = sizeof(RootKeyName);
1660 KeyNameLength += sizeof(ProfileKeyName) - sizeof(UNICODE_NULL);
1662 {
1663 KeyNameLength += sizeof(ClassKeyName) - sizeof(UNICODE_NULL);
1665 0, NULL, &DriverKeyLength);
1667 return Status;
1668 KeyNameLength += DriverKeyLength;
1669 }
1670 else
1671 {
1672 KeyNameLength += sizeof(EnumKeyName) - sizeof(UNICODE_NULL) +
1673 DeviceNode->InstancePath.Length;
1674 }
1675
1676 /*
1677 * Now allocate the buffer for the key name...
1678 */
1679
1680 KeyNameBuffer = ExAllocatePool(PagedPool, KeyNameLength);
1681 if (KeyNameBuffer == NULL)
1683
1684 KeyName.Length = 0;
1685 KeyName.MaximumLength = (USHORT)KeyNameLength;
1686 KeyName.Buffer = KeyNameBuffer;
1687
1688 /*
1689 * ...and build the key name.
1690 */
1691
1692 KeyName.Length += sizeof(RootKeyName) - sizeof(UNICODE_NULL);
1693 RtlCopyMemory(KeyNameBuffer, RootKeyName, KeyName.Length);
1694
1696 RtlAppendUnicodeToString(&KeyName, ProfileKeyName);
1697
1699 {
1700 RtlAppendUnicodeToString(&KeyName, ClassKeyName);
1702 DriverKeyLength, KeyNameBuffer +
1703 (KeyName.Length / sizeof(WCHAR)),
1704 &DriverKeyLength);
1705 if (!NT_SUCCESS(Status))
1706 {
1707 DPRINT1("Call to IoGetDeviceProperty() failed with Status 0x%08lx\n", Status);
1708 ExFreePool(KeyNameBuffer);
1709 return Status;
1710 }
1711 KeyName.Length += (USHORT)DriverKeyLength - sizeof(UNICODE_NULL);
1712 }
1713 else
1714 {
1715 RtlAppendUnicodeToString(&KeyName, EnumKeyName);
1717 if (DeviceNode->InstancePath.Length == 0)
1718 {
1719 ExFreePool(KeyNameBuffer);
1720 return Status;
1721 }
1722 }
1723
1724 /*
1725 * Open the base key.
1726 */
1728 if (!NT_SUCCESS(Status))
1729 {
1730 DPRINT1("IoOpenDeviceRegistryKey(%wZ): Base key doesn't exist, exiting... (Status 0x%08lx)\n", &KeyName, Status);
1731 ExFreePool(KeyNameBuffer);
1732 return Status;
1733 }
1734 ExFreePool(KeyNameBuffer);
1735
1736 /*
1737 * For driver key we're done now.
1738 */
1739
1741 return Status;
1742
1743 /*
1744 * Let's go further. For device key we must open "Device Parameters"
1745 * subkey and create it if it doesn't exist yet.
1746 */
1747
1748 RtlInitUnicodeString(&KeyName, DeviceParametersKeyName);
1750 &KeyName,
1753 NULL);
1754 Status = ZwCreateKey(DevInstRegKey,
1757 0,
1758 NULL,
1760 NULL);
1761 ZwClose(ObjectAttributes.RootDirectory);
1762
1763 return Status;
1764}
#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 InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:115
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:1060
unsigned short USHORT
Definition: pedump.c:61
NTSTATUS NTAPI IopOpenRegistryKeyEx(PHANDLE KeyHandle, HANDLE ParentKey, PUNICODE_STRING Name, ACCESS_MASK DesiredAccess)
Definition: pnpmgr.c:884
NTSTATUS NTAPI IoGetDeviceProperty(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_REGISTRY_PROPERTY DeviceProperty, IN ULONG BufferLength, OUT PVOID PropertyBuffer, OUT PULONG ResultLength)
Definition: pnpmgr.c:1381
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
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:2664
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2705
#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_(), AtaGetRegistryKey(), AtaSetPortRegistryKey(), AtaSetRegistryKey(), ClasspMediaChangeDeviceInstanceOverride(), ClasspScanForSpecialInRegistry(), CmBattAddDevice(), CmBattCreateFdo(), DiskAddDevice(), EngpUpdateMonitorDevices(), IntCreateNewRegistryPath(), IntSetupDeviceSettingsKey(), IntVideoPortChildQueryId(), 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 521 of file pnpmgr.c.

524{
526 HANDLE hParent = NULL, hKey;
529 PCWSTR Current, Last;
532
533 /* Assume failure */
534 *Handle = NULL;
535
536 /* Open root key for device instances */
538 if (!NT_SUCCESS(Status))
539 {
540 DPRINT1("ZwOpenKey('%wZ') failed with status 0x%08lx\n", &EnumU, Status);
541 return Status;
542 }
543
544 Current = KeyName.Buffer = RegistryPath->Buffer;
545 Last = &RegistryPath->Buffer[RegistryPath->Length / sizeof(WCHAR)];
546
547 /* Go up to the end of the string */
548 while (Current <= Last)
549 {
550 if (Current != Last && *Current != L'\\')
551 {
552 /* Not the end of the string and not a separator */
553 Current++;
554 continue;
555 }
556
557 /* Prepare relative key name */
558 Length = (USHORT)((ULONG_PTR)Current - (ULONG_PTR)KeyName.Buffer);
559 KeyName.MaximumLength = KeyName.Length = Length;
560 DPRINT("Create '%wZ'\n", &KeyName);
561
562 /* Open key */
564 &KeyName,
566 hParent,
567 NULL);
568 Status = ZwCreateKey(&hKey,
569 Current == Last ? KEY_ALL_ACCESS : KEY_CREATE_SUB_KEY,
571 0,
572 NULL,
574 NULL);
575
576 /* Close parent key handle, we don't need it anymore */
577 if (hParent)
578 ZwClose(hParent);
579
580 /* Key opening/creating failed? */
581 if (!NT_SUCCESS(Status))
582 {
583 DPRINT1("ZwCreateKey('%wZ') failed with status 0x%08lx\n", &KeyName, Status);
584 return Status;
585 }
586
587 /* Check if it is the end of the string */
588 if (Current == Last)
589 {
590 /* Yes, return success */
591 *Handle = hKey;
592 return STATUS_SUCCESS;
593 }
594
595 /* Start with this new parent key */
596 hParent = hKey;
597 Current++;
598 KeyName.Buffer = (PWSTR)Current;
599 }
600
601 return STATUS_UNSUCCESSFUL;
602}
#define RTL_CONSTANT_STRING(s)
Definition: combase.c:35
#define ULONG_PTR
Definition: config.h:101
FxAutoRegKey hKey
ULONG Handle
Definition: gdb_input.c:15
#define KEY_ALL_ACCESS
Definition: nt_native.h:1044
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1021
#define ENUM_ROOT
Definition: io.h:53
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 909 of file pnpmgr.c.

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

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 */
448 goto Quickie;
449 }
450
451 /* Now copy them, decrease the size too */
452 NewSize -= sizeof(GUID);
454
455 /* Free the old list */
457
458 /* Use the new buffer */
459 PnpBusTypeGuidList = NewList;
460 }
461
462 /* Copy the new GUID */
464 BusTypeGuid,
465 sizeof(GUID));
466
467 /* The new entry is the index */
468 FoundIndex = (USHORT)PnpBusTypeGuidList->GuidCount;
470
471Quickie:
473 return FoundIndex;
474}
#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:419
FAST_MUTEX Lock
Definition: io.h:418

Referenced by PiInitializeDevNode().

◆ IopGetParentIdPrefix()

NTSTATUS IopGetParentIdPrefix ( PDEVICE_NODE  DeviceNode,
PUNICODE_STRING  ParentIdPrefix 
)

Definition at line 759 of file pnpmgr.c.

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

Referenced by IopCreateDeviceInstancePath().

◆ IopGetRegistryValue()

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

Definition at line 1035 of file pnpmgr.c.

1038{
1039 UNICODE_STRING ValueString;
1041 PKEY_VALUE_FULL_INFORMATION FullInformation;
1042 ULONG Size;
1043 PAGED_CODE();
1044
1045 RtlInitUnicodeString(&ValueString, ValueName);
1046
1047 Status = ZwQueryValueKey(Handle,
1048 &ValueString,
1050 NULL,
1051 0,
1052 &Size);
1053 if ((Status != STATUS_BUFFER_OVERFLOW) &&
1055 {
1056 return Status;
1057 }
1058
1059 FullInformation = ExAllocatePool(NonPagedPool, Size);
1060 if (!FullInformation) return STATUS_INSUFFICIENT_RESOURCES;
1061
1062 Status = ZwQueryValueKey(Handle,
1063 &ValueString,
1065 FullInformation,
1066 Size,
1067 &Size);
1068 if (!NT_SUCCESS(Status))
1069 {
1070 ExFreePool(FullInformation);
1071 return Status;
1072 }
1073
1074 *Information = FullInformation;
1075 return STATUS_SUCCESS;
1076}
#define NonPagedPool
Definition: env_spec_w32.h:307
@ KeyValueFullInformation
Definition: nt_native.h:1184
#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:4539
_In_ WDFREQUEST _In_ NTSTATUS _In_ ULONG_PTR Information
Definition: wdfrequest.h:1049

Referenced by IoGetDeviceInterfaceAlias(), 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:1011
_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 478 of file pnpmgr.c.

482{
484
485 /* Fill out the stack information */
489 if (Stack)
490 {
491 /* Copy the rest */
494 sizeof(Stack->Parameters));
495 }
496
497 /* Do the PnP call */
501 return IoStatusBlock->Status;
502}
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:100
NTSTATUS IopSynchronousCall(IN PDEVICE_OBJECT DeviceObject, IN PIO_STACK_LOCATION IoStackLocation, OUT PVOID *Information)
union _IO_STACK_LOCATION::@1696 Parameters
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_In_ PIO_STACK_LOCATION IoStackLocation
Definition: usbdlib.h:265
_In_ UCHAR _In_ UCHAR MinorFunction
Definition: wdfdevice.h:1705
_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:1134
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1022
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:285
NTSTATUS NTAPI IopCreateDeviceKeyPath(IN PCUNICODE_STRING RegistryPath, IN ULONG CreateOptions, OUT PHANDLE Handle)
Definition: pnpmgr.c:521
VOID IopFixupDeviceId(PWCHAR String)
Definition: pnpmgr.c:32
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by PiInitializeDevNode().

◆ IopOpenRegistryKeyEx()

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

◆ IopSetDeviceInstanceData()

NTSTATUS IopSetDeviceInstanceData ( HANDLE  InstanceKey,
PDEVICE_NODE  DeviceNode 
)

Definition at line 605 of file pnpmgr.c.

607{
610 HANDLE LogConfKey, ControlKey, DeviceParamsKey;
611 ULONG ResCount;
614
615 DPRINT("IopSetDeviceInstanceData() called\n");
616
617 /* Create the 'LogConf' key */
618 RtlInitUnicodeString(&KeyName, L"LogConf");
620 &KeyName,
622 InstanceKey,
623 NULL);
624 Status = ZwCreateKey(&LogConfKey,
627 0,
628 NULL,
629 // FIXME? In r53694 it was silently turned from non-volatile into this,
630 // without any extra warning. Is this still needed??
632 NULL);
633 if (NT_SUCCESS(Status))
634 {
635 /* Set 'BootConfig' value */
636 if (DeviceNode->BootResources != NULL)
637 {
638 ResCount = DeviceNode->BootResources->Count;
639 if (ResCount != 0)
640 {
641 RtlInitUnicodeString(&KeyName, L"BootConfig");
642 Status = ZwSetValueKey(LogConfKey,
643 &KeyName,
644 0,
646 DeviceNode->BootResources,
648 }
649 }
650
651 /* Set 'BasicConfigVector' value */
652 if (DeviceNode->ResourceRequirements != NULL &&
653 DeviceNode->ResourceRequirements->ListSize != 0)
654 {
655 RtlInitUnicodeString(&KeyName, L"BasicConfigVector");
656 Status = ZwSetValueKey(LogConfKey,
657 &KeyName,
658 0,
660 DeviceNode->ResourceRequirements,
661 DeviceNode->ResourceRequirements->ListSize);
662 }
663
664 ZwClose(LogConfKey);
665 }
666
667 /* Set the 'ConfigFlags' value */
668 RtlInitUnicodeString(&KeyName, L"ConfigFlags");
669 Status = ZwQueryValueKey(InstanceKey,
670 &KeyName,
672 NULL,
673 0,
674 &ResultLength);
676 {
677 /* Write the default value */
678 ULONG DefaultConfigFlags = 0;
679 Status = ZwSetValueKey(InstanceKey,
680 &KeyName,
681 0,
682 REG_DWORD,
683 &DefaultConfigFlags,
684 sizeof(DefaultConfigFlags));
685 }
686
687 /* Create the 'Control' key */
688 RtlInitUnicodeString(&KeyName, L"Control");
690 &KeyName,
692 InstanceKey,
693 NULL);
694 Status = ZwCreateKey(&ControlKey,
695 0,
697 0,
698 NULL,
700 NULL);
701 if (NT_SUCCESS(Status))
702 ZwClose(ControlKey);
703
704 /* Create the 'Device Parameters' key and set the 'FirmwareIdentified' value for all ACPI-enumerated devices */
705 if (_wcsnicmp(DeviceNode->InstancePath.Buffer, L"ACPI\\", 5) == 0)
706 {
707 RtlInitUnicodeString(&KeyName, L"Device Parameters");
709 &KeyName,
711 InstanceKey,
712 NULL);
713 Status = ZwCreateKey(&DeviceParamsKey,
714 0,
716 0,
717 NULL,
719 NULL);
720 if (NT_SUCCESS(Status))
721 {
722 ULONG FirmwareIdentified = 1;
723 RtlInitUnicodeString(&KeyName, L"FirmwareIdentified");
724 Status = ZwSetValueKey(DeviceParamsKey,
725 &KeyName,
726 0,
727 REG_DWORD,
728 &FirmwareIdentified,
729 sizeof(FirmwareIdentified));
730
731 ZwClose(DeviceParamsKey);
732 }
733 }
734
735 DPRINT("IopSetDeviceInstanceData() done\n");
736
737 return Status;
738}
_ACRTIMP int __cdecl _wcsnicmp(const wchar_t *, const wchar_t *, size_t)
Definition: wcs.c:195
@ KeyValueBasicInformation
Definition: nt_native.h:1183
#define REG_RESOURCE_REQUIREMENTS_LIST
Definition: nt_native.h:1507
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1063

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

◆ IoSynchronousInvalidateDeviceRelations()

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

Definition at line 1797 of file pnpmgr.c.

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

Referenced by EngpUpdateMonitorDevices().

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

1835{
1836 /* FIXME: Notify the resource arbiter */
1837
1839 BusNumber,
1840 BusAddress,
1843}
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
_In_ ULONG BusNumber
Definition: pciidex.h:65
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID InterfaceType
Definition: wdffdo.h:463
_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 1096 of file pnpmgr.c.

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

Referenced by PpInitializeDeviceReferenceTable().

◆ PiCompareInstancePath()

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

Definition at line 1080 of file pnpmgr.c.

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

Referenced by PpInitializeDeviceReferenceTable().

◆ PiFreeGenericTableEntry()

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

Definition at line 1106 of file pnpmgr.c.

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

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

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

Referenced by IoGetDeviceProperty().

◆ PiInitPhase0()

BOOLEAN NTAPI PiInitPhase0 ( VOID  )

Definition at line 1129 of file pnpmgr.c.

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

Referenced by PpInitSystem().

◆ PnpBusTypeGuidGet()

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

Definition at line 1169 of file pnpmgr.c.

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

Referenced by IoGetDeviceProperty().

◆ PnpDetermineResourceListSize()

ULONG NTAPI PnpDetermineResourceListSize ( IN PCM_RESOURCE_LIST  ResourceList)

Definition at line 1236 of file pnpmgr.c.

1237{
1238 ULONG FinalSize, PartialSize, EntrySize, i, j;
1239 PCM_FULL_RESOURCE_DESCRIPTOR FullDescriptor;
1240 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
1241
1242 /* If we don't have one, that's easy */
1243 if (!ResourceList) return 0;
1244
1245 /* Start with the minimum size possible */
1246 FinalSize = FIELD_OFFSET(CM_RESOURCE_LIST, List);
1247
1248 /* Loop each full descriptor */
1249 FullDescriptor = ResourceList->List;
1250 for (i = 0; i < ResourceList->Count; i++)
1251 {
1252 /* Start with the minimum size possible */
1253 PartialSize = FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList) +
1254 FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors);
1255
1256 /* Loop each partial descriptor */
1257 PartialDescriptor = FullDescriptor->PartialResourceList.PartialDescriptors;
1258 for (j = 0; j < FullDescriptor->PartialResourceList.Count; j++)
1259 {
1260 /* Start with the minimum size possible */
1262
1263 /* Check if there is extra data */
1264 if (PartialDescriptor->Type == CmResourceTypeDeviceSpecific)
1265 {
1266 /* Add that data */
1267 EntrySize += PartialDescriptor->u.DeviceSpecificData.DataSize;
1268 }
1269
1270 /* The size of partial descriptors is bigger */
1271 PartialSize += EntrySize;
1272
1273 /* Go to the next partial descriptor */
1274 PartialDescriptor = (PVOID)((ULONG_PTR)PartialDescriptor + EntrySize);
1275 }
1276
1277 /* The size of full descriptors is bigger */
1278 FinalSize += PartialSize;
1279
1280 /* Go to the next full descriptor */
1281 FullDescriptor = (PVOID)((ULONG_PTR)FullDescriptor + PartialSize);
1282 }
1283
1284 /* Return the final size */
1285 return FinalSize;
1286}
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: restypes.h:108
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR CM_PARTIAL_RESOURCE_DESCRIPTOR
CM_PARTIAL_RESOURCE_LIST PartialResourceList
Definition: restypes.h:144
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@384 u
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@384::@393 DeviceSpecificData
CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1]
Definition: restypes.h:100
_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 1196 of file pnpmgr.c.

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

Referenced by PiGetDeviceRegistryProperty().

◆ PpInitializeDeviceReferenceTable()

VOID NTAPI PpInitializeDeviceReferenceTable ( VOID  )

Definition at line 1115 of file pnpmgr.c.

1116{
1117 /* Setup the guarded mutex and AVL table */
1124 NULL);
1125}
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:1106
RTL_AVL_TABLE PpDeviceReferenceTable
Definition: pnpmgr.c:20
PVOID NTAPI PiAllocateGenericTableEntry(IN PRTL_AVL_TABLE Table, IN CLONG ByteSize)
Definition: pnpmgr.c:1096
RTL_GENERIC_COMPARE_RESULTS NTAPI PiCompareInstancePath(IN PRTL_AVL_TABLE Table, IN PVOID FirstStruct, IN PVOID SecondStruct)
Definition: pnpmgr.c:1080
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 1141 of file pnpmgr.c.

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

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