19 #define IORSRCTRACE(...) DbgPrint(__VA_ARGS__)
22 #define IORSRCTRACE __noop
24 #define IORSRCTRACE(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
31_SystemConfigurationInformation = { 0, 0, 0, 0, 0, 0, 0,
FALSE,
FALSE, 0, 0 };
51 L"FloatingPointProcessor",
61 L"MultifunctionAdapter",
69 L"ParallelController",
71 L"KeyboardController",
75 L"FloppyDiskPeripheral",
81 L"KeyboardPeripheral",
82 L"TerminalPeripheral",
87 L"DockingInformation",
88 L"RealModeIrqRoutingTable",
89 L"RealModePCIEnumeration",
97 L"Configuration Data",
98 L"Component Information"
139 HANDLE ControllerKeyHandle;
143 ULONG ControllerNumber;
144 ULONG ControllerLoop;
145 ULONG MaximumControllerNumber;
149 HANDLE PeripheralKeyHandle;
153 ULONG PeripheralNumber;
154 ULONG PeripheralLoop;
155 ULONG MaximumPeripheralNumber;
159 ULONG LenFullInformation;
160 ULONG LenKeyFullInformation;
162 WCHAR TempBuffer[14];
164 IORSRCTRACE(
"\nIopQueryDeviceDescription(Query: 0x%p)\n"
166 " RootKeyHandle: 0x%p\n"
173 RtlInitEmptyUnicodeString(&TempString, TempBuffer,
sizeof(TempBuffer));
180 if (
Query->ControllerNumber)
182 ControllerNumber = *(
Query->ControllerNumber);
183 MaximumControllerNumber = ControllerNumber + 1;
184 IORSRCTRACE(
" Getting controller #%lu\n", ControllerNumber);
188 IORSRCTRACE(
" Enumerating controllers in '%wZ'...\n", &ControllerRootRegName);
192 &ControllerRootRegName,
202 ZwQueryKey(ControllerKeyHandle,
205 &LenFullInformation);
209 if (!ControllerFullInformation)
216 Status = ZwQueryKey(ControllerKeyHandle,
218 ControllerFullInformation,
220 &LenFullInformation);
222 ControllerKeyHandle =
NULL;
228 if (ControllerFullInformation)
234 ControllerNumber = 0;
235 MaximumControllerNumber = ControllerFullInformation->
SubKeys;
239 ControllerFullInformation =
NULL;
243 ControllerRegName = ControllerRootRegName;
246 for (; ControllerNumber < MaximumControllerNumber; ControllerNumber++)
249 ControllerRootRegName = ControllerRegName;
262 IORSRCTRACE(
" Retrieving controller '%wZ'\n", &ControllerRootRegName);
266 &ControllerRootRegName,
282 Status = ZwQueryValueKey(ControllerKeyHandle,
286 &LenKeyFullInformation);
292 ControllerInformation[ControllerLoop] =
NULL;
298 if (!ControllerInformation[ControllerLoop])
305 Status = ZwQueryValueKey(ControllerKeyHandle,
308 ControllerInformation[ControllerLoop],
309 LenKeyFullInformation,
310 &LenKeyFullInformation);
315 ControllerKeyHandle =
NULL;
323 if (!
Query->PeripheralType || !(*
Query->PeripheralType))
325 IORSRCTRACE(
" --> Bus #%lu Controller #%lu Callout: '%wZ'\n",
326 Bus, ControllerNumber, &ControllerRootRegName);
329 &ControllerRootRegName,
333 *
Query->ControllerType,
335 ControllerInformation,
351 if (
Query->PeripheralNumber)
353 PeripheralNumber = *(
Query->PeripheralNumber);
354 MaximumPeripheralNumber = PeripheralNumber + 1;
355 IORSRCTRACE(
" Getting peripheral #%lu\n", PeripheralNumber);
359 IORSRCTRACE(
" Enumerating peripherals in '%wZ'...\n", &ControllerRootRegName);
363 &ControllerRootRegName,
373 ZwQueryKey(PeripheralKeyHandle,
376 &LenFullInformation);
380 if (!PeripheralFullInformation)
388 Status = ZwQueryKey(PeripheralKeyHandle,
390 PeripheralFullInformation,
392 &LenFullInformation);
394 PeripheralKeyHandle =
NULL;
405 PeripheralNumber = 0;
406 MaximumPeripheralNumber = PeripheralFullInformation->
SubKeys;
410 PeripheralFullInformation =
NULL;
414 ControllerRegName = ControllerRootRegName;
417 for (; PeripheralNumber < MaximumPeripheralNumber; PeripheralNumber++)
420 ControllerRootRegName = ControllerRegName;
433 IORSRCTRACE(
" Retrieving peripheral '%wZ'\n", &ControllerRootRegName);
437 &ControllerRootRegName,
452 Status = ZwQueryValueKey(PeripheralKeyHandle,
456 &LenKeyFullInformation);
462 PeripheralInformation[PeripheralLoop] =
NULL;
468 if (!PeripheralInformation[PeripheralLoop])
475 Status = ZwQueryValueKey(PeripheralKeyHandle,
478 PeripheralInformation[PeripheralLoop],
479 LenKeyFullInformation,
480 &LenKeyFullInformation);
485 PeripheralKeyHandle =
NULL;
490 IORSRCTRACE(
" --> Bus #%lu Controller #%lu Peripheral #%lu Callout: '%wZ'\n",
491 Bus, ControllerNumber, PeripheralNumber, &ControllerRootRegName);
494 &ControllerRootRegName,
498 *
Query->ControllerType,
500 ControllerInformation,
501 *
Query->PeripheralType,
503 PeripheralInformation);
509 if (PeripheralInformation[PeripheralLoop])
512 PeripheralInformation[PeripheralLoop] =
NULL;
526 if (ControllerInformation[ControllerLoop])
529 ControllerInformation[ControllerLoop] =
NULL;
578 ULONG LenBasicInformation = 0;
579 ULONG LenFullInformation;
580 ULONG LenKeyFullInformation;
589 IORSRCTRACE(
"\nIopQueryBusDescription(Query: 0x%p)\n"
591 " RootKeyHandle: 0x%p\n"
593 " Bus: 0x%p (%lu)\n",
596 KeyIsRoot ?
"TRUE" :
"FALSE",
597 Bus, Bus ? *Bus : -1);
600 Status = ZwQueryKey(RootKeyHandle,
603 &LenFullInformation);
614 if (!FullInformation)
618 Status = ZwQueryKey(RootKeyHandle,
622 &LenFullInformation);
630 if (!BasicInformation)
644 if (
Query->BusNumber && (*(
Query->BusNumber) == *Bus))
648 Status = ZwEnumerateKey(RootKeyHandle,
696 IORSRCTRACE(
" SubRootRegName: '%wZ'\n", &SubRootRegName);
707 IORSRCTRACE(
" Getting bus value: '%wZ'\n", &SubBusString);
710 ZwQueryValueKey(SubRootKeyHandle,
714 &LenKeyFullInformation);
725 Status = ZwQueryValueKey(SubRootKeyHandle,
729 LenKeyFullInformation,
730 &LenKeyFullInformation);
739 if (BusConfigData !=
NULL &&
753 IORSRCTRACE(
" --> Bus #%lu Callout: '%wZ'\n", *Bus, &SubRootRegName);
770 IORSRCTRACE(
" --> Getting device on Bus #%lu : '%wZ'\n", *Bus, &SubRootRegName);
794 if (
Query->BusNumber && (*(
Query->BusNumber) == *Bus))
797 SubRootKeyHandle =
NULL;
810 SubRootKeyHandle =
NULL;
814 if (BasicInformation)
828 ULONG interfaces = 0;
829 PWSTR symbolicLinkList;
848 symbolicLinkList += (
wcslen(symbolicLinkList) + 1);
854 *Interfaces = interfaces;
868 WCHAR LinkTargetBuffer[256];
871 ASSERT(NtSystemPartitionDeviceName->MaximumLength >= NtSystemPartitionDeviceName->Length +
sizeof(
WCHAR));
872 ASSERT(NtSystemPartitionDeviceName->Buffer[NtSystemPartitionDeviceName->Length /
sizeof(
WCHAR)] ==
UNICODE_NULL);
873 ASSERT(OsLoaderPathName->MaximumLength >= OsLoaderPathName->Length +
sizeof(
WCHAR));
878 NtSystemPartitionDeviceName,
889 DPRINT(
"Failed to open symlink %wZ, Status=%lx\n", NtSystemPartitionDeviceName,
Status);
895 RtlInitEmptyUnicodeString(&
LinkTarget, LinkTargetBuffer,
906 DPRINT(
"Failed querying symlink %wZ, Status=%lx\n", NtSystemPartitionDeviceName,
Status);
916 &CmRegistryMachineSystemName,
920 DPRINT(
"Failed to open HKLM\\SYSTEM, Status=%lx\n",
Status);
939 DPRINT(
"Failed opening/creating Setup key, Status=%lx\n",
Status);
955 DPRINT(
"Failed writing SystemPartition value, Status=%lx\n",
Status);
962 if (OsLoaderPathName->Length >
sizeof(
WCHAR) &&
965 OsLoaderPathName->Length -=
sizeof(
WCHAR);
966 OsLoaderPathName->Buffer[OsLoaderPathName->Length /
sizeof(
WCHAR)] =
UNICODE_NULL;
974 OsLoaderPathName->Buffer,
978 DPRINT(
"Failed writing OsLoaderPath value, Status=%lx\n",
Status);
1055 DPRINT1(
"IoReportResourceUsage is halfplemented!\n");
1068 *ConflictDetected =
TRUE;
1070 if (!OverrideConflict)
1072 DPRINT1(
"Denying an attempt to claim resources currently in use by another device!\n");
1077 DPRINT1(
"Proceeding with conflicting resources\n");
1087 *ConflictDetected =
FALSE;
1102 DPRINT1(
"IopLegacyResourceAllocation is halfplemented!\n");
1119 DPRINT1(
"Denying an attempt to claim resources currently in use by another device!\n");
1164 if (RequestedResources)
1167 if (!(RequestedResources->AlternativeLists) || !(RequestedResources->List[0].Count))
1170 RequestedResources =
NULL;
1224 ULONG BusLoopNumber = -1;
1231 " BusType: 0x%p (%lu)\n"
1232 " BusNumber: 0x%p (%lu)\n"
1233 " ControllerType: 0x%p (%lu)\n"
1234 " ControllerNumber: 0x%p (%lu)\n"
1235 " PeripheralType: 0x%p (%lu)\n"
1236 " PeripheralNumber: 0x%p (%lu)\n"
1237 " CalloutRoutine: 0x%p\n"
1239 "--> Query: 0x%p\n",
1242 ControllerType, ControllerType ? *ControllerType : -1,
1243 ControllerNumber, ControllerNumber ? *ControllerNumber : -1,
1244 PeripheralType, PeripheralType ? *PeripheralType : -1,
1245 PeripheralNumber, PeripheralNumber ? *PeripheralNumber : -1,
1275 Query.ControllerType = ControllerType;
1276 Query.ControllerNumber = ControllerNumber;
1277 Query.PeripheralType = PeripheralType;
1278 Query.PeripheralNumber = PeripheralNumber;
1279 Query.CalloutRoutine = CalloutRoutine;
1342 Status = ZwCreateKey(&ResourceMapKey,
1359 Status = ZwCreateKey(&HalKey,
1407 TranslatedResourceList,
#define OBJ_NAME_PATH_SEPARATOR
BOOL Query(LPCTSTR *ServiceArgs, DWORD ArgCount, BOOL bExtended)
static const CLASS_AND_INTERFACES ExpectedInterfaces[]
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
#define NT_SUCCESS(StatCode)
static const WCHAR DescriptionKey[]
#define ExAllocatePoolWithTag(hernya, size, tag)
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
enum _INTERFACE_TYPE * PINTERFACE_TYPE
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define OBJ_KERNEL_HANDLE
#define OBJ_CASE_INSENSITIVE
static NTSTATUS IopQueryBusDescription(_In_ PIO_QUERY Query, _In_ UNICODE_STRING RootKey, _In_ HANDLE RootKeyHandle, _Inout_ PULONG Bus, _In_ BOOLEAN KeyIsRoot)
Reads and returns Hardware information from the appropriate hardware registry key....
PCWSTR ArcTypes[MaximumType+1]
NTSTATUS NTAPI IoReportResourceUsage(_In_opt_ PUNICODE_STRING DriverClassName, _In_ PDRIVER_OBJECT DriverObject, _In_reads_bytes_opt_(DriverListSize) PCM_RESOURCE_LIST DriverList, _In_opt_ ULONG DriverListSize, _In_opt_ PDEVICE_OBJECT DeviceObject, _In_reads_bytes_opt_(DeviceListSize) PCM_RESOURCE_LIST DeviceList, _In_opt_ ULONG DeviceListSize, _In_ BOOLEAN OverrideConflict, _Out_ PBOOLEAN ConflictDetected)
Reports hardware resources in the \Registry\Machine\Hardware\ResourceMap tree, so that a subsequently...
NTSTATUS IopFetchConfigurationInformation(_Out_ PWSTR *SymbolicLinkList, _In_ GUID Guid, _In_ ULONG ExpectedInterfaces, _Out_ PULONG Interfaces)
NTSTATUS NTAPI IoAssignResources(_In_ PUNICODE_STRING RegistryPath, _In_opt_ PUNICODE_STRING DriverClassName, _In_ PDRIVER_OBJECT DriverObject, _In_opt_ PDEVICE_OBJECT DeviceObject, _In_opt_ PIO_RESOURCE_REQUIREMENTS_LIST RequestedResources, _Inout_ PCM_RESOURCE_LIST *AllocatedResources)
VOID IopStoreSystemPartitionInformation(_In_ PUNICODE_STRING NtSystemPartitionDeviceName, _In_ PUNICODE_STRING OsLoaderPathName)
struct _IO_QUERY IO_QUERY
PCWSTR IoDeviceInfoNames[IoQueryDeviceMaxData]
static NTSTATUS IopQueryDeviceDescription(_In_ PIO_QUERY Query, _In_ UNICODE_STRING RootKey, _In_ HANDLE RootKeyHandle, _In_ ULONG Bus, _In_ PKEY_VALUE_FULL_INFORMATION *BusInformation)
Reads and returns Hardware information from the appropriate hardware registry key....
struct _IO_QUERY * PIO_QUERY
NTSTATUS NTAPI IoReportHalResourceUsage(_In_ PUNICODE_STRING HalName, _In_ PCM_RESOURCE_LIST RawResourceList, _In_ PCM_RESOURCE_LIST TranslatedResourceList, _In_ ULONG ResourceListSize)
Reports hardware resources of the HAL in the \Registry\Machine\Hardware\ResourceMap tree.
static NTSTATUS IopLegacyResourceAllocation(_In_ ARBITER_REQUEST_SOURCE AllocationType, _In_ PDRIVER_OBJECT DriverObject, _In_opt_ PDEVICE_OBJECT DeviceObject, _In_opt_ PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements, _Inout_ PCM_RESOURCE_LIST *AllocatedResources)
static CONFIGURATION_INFORMATION _SystemConfigurationInformation
PCONFIGURATION_INFORMATION NTAPI IoGetConfigurationInformation(VOID)
Returns a pointer to the I/O manager's global configuration information structure.
NTSTATUS NTAPI IoQueryDeviceDescription(_In_opt_ PINTERFACE_TYPE BusType, _In_opt_ PULONG BusNumber, _In_opt_ PCONFIGURATION_TYPE ControllerType, _In_opt_ PULONG ControllerNumber, _In_opt_ PCONFIGURATION_TYPE PeripheralType, _In_opt_ PULONG PeripheralNumber, _In_ PIO_QUERY_DEVICE_ROUTINE CalloutRoutine, _In_opt_ PVOID Context)
Reads and returns Hardware information from the appropriate hardware registry key.
#define ExFreePoolWithTag(_P, _T)
#define InitializeObjectAttributes(p, n, a, r, s)
#define _In_reads_bytes_opt_(size)
_Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PCM_RESOURCE_LIST * AllocatedResources
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
#define DNF_LEGACY_RESOURCE_DEVICENODE
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T _In_ SECTION_INHERIT _In_ ULONG AllocationType
NTSYSAPI NTSTATUS NTAPI ZwOpenSymbolicLinkObject(_Out_ PHANDLE SymbolicLinkHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define SYMBOLIC_LINK_QUERY
@ KeyValueFullInformation
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
struct _KEY_BASIC_INFORMATION KEY_BASIC_INFORMATION
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define REG_OPTION_NON_VOLATILE
#define REG_RESOURCE_LIST
NTSYSAPI NTSTATUS NTAPI RtlIntegerToUnicodeString(ULONG Value, ULONG Base, PUNICODE_STRING String)
#define REG_OPTION_VOLATILE
#define UNREFERENCED_PARAMETER(P)
NTSTATUS NTAPI IopOpenRegistryKeyEx(PHANDLE KeyHandle, HANDLE ParentKey, PUNICODE_STRING Name, ACCESS_MASK DesiredAccess)
PDEVICE_NODE FASTCALL IopGetDeviceNode(IN PDEVICE_OBJECT DeviceObject)
NTSTATUS NTAPI IopFixupResourceListWithRequirements(IN PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList, OUT PCM_RESOURCE_LIST *ResourceList)
NTSTATUS NTAPI IopCreateRegistryKeyEx(OUT PHANDLE Handle, IN HANDLE BaseHandle OPTIONAL, IN PUNICODE_STRING KeyName, IN ACCESS_MASK DesiredAccess, IN ULONG CreateOptions, OUT PULONG Disposition OPTIONAL)
NTSTATUS NTAPI IopDetectResourceConflict(IN PCM_RESOURCE_LIST ResourceList, IN BOOLEAN Silent, OUT OPTIONAL PCM_PARTIAL_RESOURCE_DESCRIPTOR ConflictingDescriptor)
NTSTATUS NTAPI IoGetDeviceInterfaces(IN CONST GUID *InterfaceClassGuid, IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL, IN ULONG Flags, OUT PWSTR *SymbolicLinkList)
#define STATUS_NO_MORE_ENTRIES
#define STATUS_NOT_IMPLEMENTED
#define STATUS_CONFLICTING_ADDRESSES
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
_Check_return_ _CRTIMP int __cdecl wcsncmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
enum _CONFIGURATION_TYPE * PCONFIGURATION_TYPE
#define STATUS_BUFFER_TOO_SMALL
#define STATUS_BUFFER_OVERFLOW
PIO_QUERY_DEVICE_ROUTINE CalloutRoutine
PCONFIGURATION_TYPE ControllerType
PCONFIGURATION_TYPE PeripheralType
#define RTL_CONSTANT_STRING(s)
#define STATUS_INVALID_PARAMETER
#define STATUS_UNSUCCESSFUL
#define STATUS_INSUFFICIENT_RESOURCES
_In_ PDEVICE_OBJECT DeviceObject
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
_In_ WDFDEVICE _In_ PPNP_BUS_INFORMATION BusInformation
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
_Must_inspect_result_ _In_ WDFOBJECT _In_ CONST GUID * Guid
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
_In_opt_ PUNICODE_STRING DriverClassName
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE BusType
_In_opt_ PDEVICE_OBJECT _In_ ULONG _Outptr_result_nullonfailure_ _At_ * SymbolicLinkList(return==0, __drv_allocatesMem(Mem))) PZZWSTR *SymbolicLinkList
_In_ INTERFACE_TYPE _In_ ULONG _In_ ULONG _In_opt_ PCM_RESOURCE_LIST _In_opt_ PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements
enum _ARBITER_REQUEST_SOURCE ARBITER_REQUEST_SOURCE
@ IoQueryDeviceConfigurationData
@ ArbiterRequestLegacyAssigned
NTSTATUS(NTAPI * PIO_QUERY_DEVICE_ROUTINE)(_In_ PVOID Context, _In_ PUNICODE_STRING PathName, _In_ INTERFACE_TYPE BusType, _In_ ULONG BusNumber, _In_ PKEY_VALUE_FULL_INFORMATION *BusInformation, _In_ CONFIGURATION_TYPE ControllerType, _In_ ULONG ControllerNumber, _In_ PKEY_VALUE_FULL_INFORMATION *ControllerInformation, _In_ CONFIGURATION_TYPE PeripheralType, _In_ ULONG PeripheralNumber, _In_ PKEY_VALUE_FULL_INFORMATION *PeripheralInformation)
_Inout_ PUNICODE_STRING LinkTarget