ReactOS 0.4.15-dev-6068-g8061a6f
iorsrce.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for iorsrce.c:

Go to the source code of this file.

Classes

struct  _IO_QUERY
 

Macros

#define NDEBUG
 
#define IORSRCTRACE(...)   do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
 

Typedefs

typedef struct _IO_QUERY IO_QUERY
 
typedef struct _IO_QUERYPIO_QUERY
 

Functions

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. Helper stub of IopQueryBusDescription().
 
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. Helper stub of IoQueryDeviceDescription(). Has two modes of operation, either looking for root bus types or for sub-bus information.
 
NTSTATUS IopFetchConfigurationInformation (_Out_ PWSTR *SymbolicLinkList, _In_ GUID Guid, _In_ ULONG ExpectedInterfaces, _Out_ PULONG Interfaces)
 
VOID IopStoreSystemPartitionInformation (_In_ PUNICODE_STRING NtSystemPartitionDeviceName, _In_ PUNICODE_STRING OsLoaderPathName)
 
PCONFIGURATION_INFORMATION NTAPI IoGetConfigurationInformation (VOID)
 Returns a pointer to the I/O manager's global configuration information structure.
 
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 loaded driver cannot attempt to use the same resources.
 
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)
 
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)
 
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.
 
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.
 

Variables

static CONFIGURATION_INFORMATION _SystemConfigurationInformation = { 0, 0, 0, 0, 0, 0, 0, FALSE, FALSE, 0, 0 }
 
PCWSTR ArcTypes [MaximumType+1]
 
PCWSTR IoDeviceInfoNames [IoQueryDeviceMaxData]
 

Macro Definition Documentation

◆ IORSRCTRACE

#define IORSRCTRACE (   ...)    do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)

Definition at line 24 of file iorsrce.c.

◆ NDEBUG

#define NDEBUG

Definition at line 15 of file iorsrce.c.

Typedef Documentation

◆ IO_QUERY

◆ PIO_QUERY

Function Documentation

◆ IoAssignResources()

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 
)

Definition at line 1105 of file iorsrce.c.

1112{
1114
1117
1118 /* Do we have a DO? */
1119 if (DeviceObject)
1120 {
1121 /* Get its device node */
1124 {
1125 /* New drivers should not call this API */
1126 KeBugCheckEx(PNP_DETECTED_FATAL_ERROR,
1127 0,
1128 0,
1131 }
1132 }
1133
1134 /* Did the driver supply resources? */
1135 if (RequestedResources)
1136 {
1137 /* Make sure there's actually something useful in them */
1138 if (!(RequestedResources->AlternativeLists) || !(RequestedResources->List[0].Count))
1139 {
1140 /* Empty resources are no resources */
1141 RequestedResources = NULL;
1142 }
1143 }
1144
1145 /* Initialize output if given */
1148
1149 /* Call internal helper function */
1153 RequestedResources,
1155}
@ DeviceNode
Definition: Node.h:9
#define NULL
Definition: types.h:112
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)
Definition: iorsrce.c:1064
_Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PCM_RESOURCE_LIST * AllocatedResources
Definition: ndis.h:4643
#define DNF_LEGACY_RESOURCE_DEVICENODE
Definition: iotypes.h:187
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
PDEVICE_NODE FASTCALL IopGetDeviceNode(IN PDEVICE_OBJECT DeviceObject)
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
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_In_opt_ PUNICODE_STRING DriverClassName
Definition: halfuncs.h:156
@ ArbiterRequestLegacyAssigned
Definition: iotypes.h:4616

Referenced by PciAssignSlotResources(), and VideoPortGetAccessRanges().

◆ IoGetConfigurationInformation()

PCONFIGURATION_INFORMATION NTAPI IoGetConfigurationInformation ( VOID  )

Returns a pointer to the I/O manager's global configuration information structure.

This structure contains the current values for how many physical storage media, SCSI HBA, serial, and parallel devices have device objects created to represent them by drivers as they are loaded.

Definition at line 969 of file iorsrce.c.

970{
972}
static CONFIGURATION_INFORMATION _SystemConfigurationInformation
Definition: iorsrce.c:31

Referenced by AddControllers(), AddDeviceInternal(), DeviceEvtSelfManagedIoCleanup(), DeviceEvtSelfManagedIoInit(), DiskAddDevice(), DiskRemoveDevice(), DriverEntry(), FdoRemoveAdapter(), FdoStartAdapter(), GetCurrentResources(), InitializeConfiguration(), IoGetBootDiskInformation(), IopCreateArcNamesCd(), IopCreateArcNamesDisk(), QSI_DEF(), ScsiFlopAddDevice(), ScsiFlopRemoveDevice(), ScsiPortInitialize(), SerialAddDeviceInternal(), SpiConfigToResource(), SpiCreatePortConfig(), UniataFindBusMasterController(), VfdCreateDevice(), VfdDeleteDevice(), and xHalIoAssignDriveLetters().

◆ IopFetchConfigurationInformation()

NTSTATUS IopFetchConfigurationInformation ( _Out_ PWSTR SymbolicLinkList,
_In_ GUID  Guid,
_In_ ULONG  ExpectedInterfaces,
_Out_ PULONG  Interfaces 
)

Definition at line 791 of file iorsrce.c.

796{
798 ULONG interfaces = 0;
799 PWSTR symbolicLinkList;
800
801 /* Get the associated enabled interfaces with the given GUID */
803 if (!NT_SUCCESS(Status))
804 {
805 /* Zero output and leave */
808
809 return STATUS_UNSUCCESSFUL;
810 }
811
812 symbolicLinkList = *SymbolicLinkList;
813
814 /* Count the number of enabled interfaces by counting the number of symbolic links */
815 while (*symbolicLinkList != UNICODE_NULL)
816 {
817 interfaces++;
818 symbolicLinkList += (wcslen(symbolicLinkList) + 1);
819 }
820
821 /* Matching result will define the result */
823 /* Finally, give back to the caller the number of found interfaces */
824 *Interfaces = interfaces;
825
826 return Status;
827}
LONG NTSTATUS
Definition: precomp.h:26
static const CLASS_AND_INTERFACES ExpectedInterfaces[]
Definition: browseui.c:13
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:25
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define UNICODE_NULL
NTSTATUS NTAPI IoGetDeviceInterfaces(IN CONST GUID *InterfaceClassGuid, IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL, IN ULONG Flags, OUT PWSTR *SymbolicLinkList)
Definition: deviface.c:454
#define STATUS_SUCCESS
Definition: shellext.h:65
uint16_t * PWSTR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Must_inspect_result_ _In_ WDFOBJECT _In_ CONST GUID * Guid
Definition: wdfobject.h:762
_In_opt_ PDEVICE_OBJECT _In_ ULONG _Outptr_result_nullonfailure_ _At_ * SymbolicLinkList(return==0, __drv_allocatesMem(Mem))) PZZWSTR *SymbolicLinkList

Referenced by IopCreateArcNamesCd(), and IopCreateArcNamesDisk().

◆ IopLegacyResourceAllocation()

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

Definition at line 1064 of file iorsrce.c.

1070{
1072
1073 DPRINT1("IopLegacyResourceAllocation is halfplemented!\n");
1074
1076 {
1077 /* We can get there by calling IoAssignResources() with RequestedResources = NULL.
1078 * TODO: not sure what we should do, but we shouldn't crash.
1079 */
1082 }
1083
1086 if (!NT_SUCCESS(Status))
1087 {
1089 {
1090 DPRINT1("Denying an attempt to claim resources currently in use by another device!\n");
1091 }
1092
1093 return Status;
1094 }
1095
1096 /* TODO: Claim resources in registry */
1097 return STATUS_SUCCESS;
1098}
#define DPRINT1
Definition: precomp.h:8
#define UNIMPLEMENTED
Definition: debug.h:115
NTSTATUS NTAPI IopFixupResourceListWithRequirements(IN PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList, OUT PCM_RESOURCE_LIST *ResourceList)
Definition: pnpres.c:219
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
#define STATUS_CONFLICTING_ADDRESSES
Definition: ntstatus.h:261
_In_ INTERFACE_TYPE _In_ ULONG _In_ ULONG _In_opt_ PCM_RESOURCE_LIST _In_opt_ PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements
Definition: iofuncs.h:1551

Referenced by IoAssignResources().

◆ IopQueryBusDescription()

static NTSTATUS IopQueryBusDescription ( _In_ PIO_QUERY  Query,
_In_ UNICODE_STRING  RootKey,
_In_ HANDLE  RootKeyHandle,
_Inout_ PULONG  Bus,
_In_ BOOLEAN  KeyIsRoot 
)
static

Reads and returns Hardware information from the appropriate hardware registry key. Helper stub of IoQueryDeviceDescription(). Has two modes of operation, either looking for root bus types or for sub-bus information.

Parameters
[in]QueryWhat the parent function wants.
[in]RootKeyWhich key to look in.
[in]RootKeyHandleHandle to the key.
[in,out]BusPointer to the current bus number.
[in]KeyIsRootWhether we are looking for root bus types or information under them.
Returns
A status code.

Definition at line 546 of file iorsrce.c.

552{
554 ULONG BusLoop;
555 UNICODE_STRING SubRootRegName;
556 UNICODE_STRING BusString;
557 UNICODE_STRING SubBusString;
558 ULONG LenBasicInformation = 0;
559 ULONG LenFullInformation;
560 ULONG LenKeyFullInformation;
561 ULONG LenKey;
562 HANDLE SubRootKeyHandle;
563 PKEY_FULL_INFORMATION FullInformation;
564 PKEY_BASIC_INFORMATION BasicInformation = NULL;
567 {NULL, NULL, NULL};
568
569 IORSRCTRACE("\nIopQueryBusDescription(Query: 0x%p)\n"
570 " RootKey: '%wZ'\n"
571 " RootKeyHandle: 0x%p\n"
572 " KeyIsRoot: %s\n"
573 " Bus: 0x%p (%lu)\n",
574 Query,
575 &RootKey, RootKeyHandle,
576 KeyIsRoot ? "TRUE" : "FALSE",
577 Bus, Bus ? *Bus : -1);
578
579 /* Retrieve the necessary buffer space */
580 Status = ZwQueryKey(RootKeyHandle,
582 NULL, 0,
583 &LenFullInformation);
584
585 if (!NT_SUCCESS(Status) &&
588 {
589 return Status;
590 }
591
592 /* Allocate it */
593 FullInformation = ExAllocatePoolWithTag(PagedPool, LenFullInformation, TAG_IO_RESOURCE);
594
595 if (!FullInformation)
596 return STATUS_NO_MEMORY;
597
598 /* Get the information */
599 Status = ZwQueryKey(RootKeyHandle,
601 FullInformation,
602 LenFullInformation,
603 &LenFullInformation);
604 if (NT_SUCCESS(Status))
605 {
606 /* Buffer needed for all the keys under this one */
607 LenBasicInformation = FullInformation->MaxNameLen + sizeof(KEY_BASIC_INFORMATION);
608
609 /* Allocate it */
610 BasicInformation = ExAllocatePoolWithTag(PagedPool, LenBasicInformation, TAG_IO_RESOURCE);
611 }
612
613 /* Deallocate the old buffer */
614 ExFreePoolWithTag(FullInformation, TAG_IO_RESOURCE);
615
616 /* Try to find a bus */
617 for (BusLoop = 0; NT_SUCCESS(Status); BusLoop++)
618 {
619 /* Bus parameter was passed and number was matched */
620 if (Query->BusNumber && (*(Query->BusNumber) == *Bus))
621 break;
622
623 /* Enumerate the Key */
624 Status = ZwEnumerateKey(RootKeyHandle,
625 BusLoop,
627 BasicInformation,
628 LenBasicInformation,
629 &LenKey);
630
631 /* Stop if everything was enumerated */
632 if (!NT_SUCCESS(Status))
633 break;
634
635 IORSRCTRACE(" Seen: '%.*ws'\n", BasicInformation->NameLength/sizeof(WCHAR), BasicInformation->Name);
636
637 /* What bus are we going to go down? (only check if this is a root key) */
638 if (KeyIsRoot)
639 {
640 if (wcsncmp(BasicInformation->Name, L"MultifunctionAdapter", BasicInformation->NameLength / sizeof(WCHAR)) &&
641 wcsncmp(BasicInformation->Name, L"EisaAdapter", BasicInformation->NameLength / sizeof(WCHAR)) &&
642 wcsncmp(BasicInformation->Name, L"TcAdapter", BasicInformation->NameLength / sizeof(WCHAR)))
643 {
644 /* Nothing found, check next */
645 continue;
646 }
647 }
648
649 /* Enumerate the bus */
650 BusString.Buffer = BasicInformation->Name;
651 BusString.Length = (USHORT)BasicInformation->NameLength;
652 BusString.MaximumLength = (USHORT)BasicInformation->NameLength;
653
654 /* Open a handle to the root registry key */
656 &BusString,
658 RootKeyHandle,
659 NULL);
660
661 Status = ZwOpenKey(&SubRootKeyHandle, KEY_READ, &ObjectAttributes);
662
663 /* Go on if we failed */
664 if (!NT_SUCCESS(Status))
665 continue;
666
667 /* Key opened, create the path */
668 SubRootRegName = RootKey;
669 RtlAppendUnicodeToString(&SubRootRegName, L"\\");
670 RtlAppendUnicodeStringToString(&SubRootRegName, &BusString);
671
672 IORSRCTRACE(" SubRootRegName: '%wZ'\n", &SubRootRegName);
673
674 if (!KeyIsRoot)
675 {
676 /* Parsing a sub-bus key */
677 ULONG SubBusLoop;
678 for (SubBusLoop = 0; SubBusLoop < RTL_NUMBER_OF(IoDeviceInfoNames); SubBusLoop++)
679 {
680 /* Identifier string first */
681 RtlInitUnicodeString(&SubBusString, IoDeviceInfoNames[SubBusLoop]);
682
683 IORSRCTRACE(" Getting bus value: '%wZ'\n", &SubBusString);
684
685 /* Retrieve the necessary buffer space */
686 ZwQueryValueKey(SubRootKeyHandle,
687 &SubBusString,
689 NULL, 0,
690 &LenKeyFullInformation);
691
692 /* Allocate it */
693 BusInformation[SubBusLoop] = ExAllocatePoolWithTag(PagedPool, LenKeyFullInformation, TAG_IO_RESOURCE);
694
695 /* Get the information */
696 Status = ZwQueryValueKey(SubRootKeyHandle,
697 &SubBusString,
699 BusInformation[SubBusLoop],
700 LenKeyFullInformation,
701 &LenKeyFullInformation);
702 }
703
704 if (NT_SUCCESS(Status))
705 {
706 PKEY_VALUE_FULL_INFORMATION BusConfigData =
708
709 /* Do we have something? */
710 if (BusConfigData != NULL &&
711 BusConfigData->DataLength != 0 &&
712 /* Does it match what we want? */
713 (((PCM_FULL_RESOURCE_DESCRIPTOR)((ULONG_PTR)BusConfigData +
714 BusConfigData->DataOffset))->InterfaceType == *(Query->BusType)))
715 {
716 /* Found a bus */
717 (*Bus)++;
718
719 /* Is it the bus we wanted? */
720 if (Query->BusNumber == NULL || *(Query->BusNumber) == *Bus)
721 {
722 if (Query->ControllerType == NULL)
723 {
724 IORSRCTRACE(" --> Bus #%lu Callout: '%wZ'\n", *Bus, &SubRootRegName);
725
726 /* We don't want controller information: call the callback */
727 Status = Query->CalloutRoutine(Query->Context,
728 &SubRootRegName,
729 *(Query->BusType),
730 *Bus,
732 0,
733 0,
734 NULL,
735 0,
736 0,
737 NULL);
738 }
739 else
740 {
741 IORSRCTRACE(" --> Getting device on Bus #%lu : '%wZ'\n", *Bus, &SubRootRegName);
742
743 /* We want controller information: get it */
745 SubRootRegName,
746 RootKeyHandle,
747 *Bus,
749 }
750 }
751 }
752 }
753
754 /* Free the allocated memory */
755 for (SubBusLoop = 0; SubBusLoop < RTL_NUMBER_OF(IoDeviceInfoNames); SubBusLoop++)
756 {
757 if (BusInformation[SubBusLoop])
758 {
760 BusInformation[SubBusLoop] = NULL;
761 }
762 }
763
764 /* Exit the loop if we found the bus */
765 if (Query->BusNumber && (*(Query->BusNumber) == *Bus))
766 {
767 ZwClose(SubRootKeyHandle);
768 SubRootKeyHandle = NULL;
769 continue;
770 }
771 }
772
773 /* Enumerate the buses below us recursively if we haven't found the bus yet */
774 Status = IopQueryBusDescription(Query, SubRootRegName, SubRootKeyHandle, Bus, !KeyIsRoot);
775
776 /* Everything enumerated */
778
779 ZwClose(SubRootKeyHandle);
780 SubRootKeyHandle = NULL;
781 }
782
783 /* Free the last remaining allocated memory */
784 if (BasicInformation)
785 ExFreePoolWithTag(BasicInformation, TAG_IO_RESOURCE);
786
787 return Status;
788}
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
BOOL Query(LPCTSTR *ServiceArgs, DWORD ArgCount, BOOL bExtended)
Definition: query.c:292
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
#define PagedPool
Definition: env_spec_w32.h:308
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
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....
Definition: iorsrce.c:546
#define IORSRCTRACE(...)
Definition: iorsrce.c:24
PCWSTR IoDeviceInfoNames[IoQueryDeviceMaxData]
Definition: iorsrce.c:94
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....
Definition: iorsrce.c:126
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
@ KeyBasicInformation
Definition: nt_native.h:1131
@ KeyFullInformation
Definition: nt_native.h:1133
@ KeyValueFullInformation
Definition: nt_native.h:1181
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
#define KEY_READ
Definition: nt_native.h:1023
struct _KEY_BASIC_INFORMATION KEY_BASIC_INFORMATION
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:205
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define L(x)
Definition: ntvdm.h:50
unsigned short USHORT
Definition: pedump.c:61
_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)
static PMEMKEY RootKey
Definition: registry.c:55
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define TAG_IO_RESOURCE
Definition: tag.h:93
_In_ WDFDEVICE _In_ PPNP_BUS_INFORMATION BusInformation
Definition: wdfdevice.h:3915
@ IoQueryDeviceMaxData
Definition: iotypes.h:4451
@ IoQueryDeviceConfigurationData
Definition: iotypes.h:4449
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by IopQueryBusDescription(), and IoQueryDeviceDescription().

◆ IopQueryDeviceDescription()

static NTSTATUS IopQueryDeviceDescription ( _In_ PIO_QUERY  Query,
_In_ UNICODE_STRING  RootKey,
_In_ HANDLE  RootKeyHandle,
_In_ ULONG  Bus,
_In_ PKEY_VALUE_FULL_INFORMATION BusInformation 
)
static

Reads and returns Hardware information from the appropriate hardware registry key. Helper stub of IopQueryBusDescription().

Parameters
[in]QueryWhat the parent function wants.
[in]RootKeyWhich key to look in.
[in]RootKeyHandleHandle to the key.
[in]BusThe bus number.
[in]BusInformationThe configuration information being sent.
Returns
A status code.

Definition at line 126 of file iorsrce.c.

132{
134
135 /* Controller data */
136 UNICODE_STRING ControllerString;
137 UNICODE_STRING ControllerRootRegName = RootKey;
138 UNICODE_STRING ControllerRegName;
139 HANDLE ControllerKeyHandle;
140 PKEY_FULL_INFORMATION ControllerFullInformation = NULL;
142 {NULL, NULL, NULL};
143 ULONG ControllerNumber;
144 ULONG ControllerLoop;
145 ULONG MaximumControllerNumber;
146
147 /* Peripheral data */
148 UNICODE_STRING PeripheralString;
149 HANDLE PeripheralKeyHandle;
150 PKEY_FULL_INFORMATION PeripheralFullInformation;
152 {NULL, NULL, NULL};
153 ULONG PeripheralNumber;
154 ULONG PeripheralLoop;
155 ULONG MaximumPeripheralNumber;
156
157 /* Global Registry data */
159 ULONG LenFullInformation;
160 ULONG LenKeyFullInformation;
161 UNICODE_STRING TempString;
162 WCHAR TempBuffer[14];
163
164 IORSRCTRACE("\nIopQueryDeviceDescription(Query: 0x%p)\n"
165 " RootKey: '%wZ'\n"
166 " RootKeyHandle: 0x%p\n"
167 " Bus: %lu\n",
168 Query,
169 &RootKey, RootKeyHandle,
170 Bus);
171
172 /* Temporary string */
173 TempString.MaximumLength = sizeof(TempBuffer);
174 TempString.Length = 0;
175 TempString.Buffer = TempBuffer;
176
177 /* Append controller name to string */
178 RtlAppendUnicodeToString(&ControllerRootRegName, L"\\");
179 RtlAppendUnicodeToString(&ControllerRootRegName, ArcTypes[*Query->ControllerType]);
180
181 /* Set the controller number if specified */
182 if (Query->ControllerNumber && *(Query->ControllerNumber))
183 {
184 ControllerNumber = *Query->ControllerNumber;
185 MaximumControllerNumber = ControllerNumber + 1;
186 IORSRCTRACE(" Getting controller #%lu\n", ControllerNumber);
187 }
188 else
189 {
190 IORSRCTRACE(" Enumerating controllers in '%wZ'...\n", &ControllerRootRegName);
191
192 /* Find out how many controllers there are */
194 &ControllerRootRegName,
196 NULL,
197 NULL);
198
199 Status = ZwOpenKey(&ControllerKeyHandle, KEY_READ, &ObjectAttributes);
200
201 if (NT_SUCCESS(Status))
202 {
203 /* Retrieve the necessary buffer space */
204 ZwQueryKey(ControllerKeyHandle,
206 NULL, 0,
207 &LenFullInformation);
208
209 /* Allocate it */
210 ControllerFullInformation = ExAllocatePoolWithTag(PagedPool, LenFullInformation, TAG_IO_RESOURCE);
211
212 /* Get the information */
213 Status = ZwQueryKey(ControllerKeyHandle,
215 ControllerFullInformation,
216 LenFullInformation,
217 &LenFullInformation);
218 ZwClose(ControllerKeyHandle);
219 ControllerKeyHandle = NULL;
220 }
221
222 /* No controller was found, bail out */
223 if (!NT_SUCCESS(Status))
224 {
225 if (ControllerFullInformation != NULL)
226 ExFreePoolWithTag(ControllerFullInformation, TAG_IO_RESOURCE);
227 return Status;
228 }
229
230 /* Find out the controllers */
231 ControllerNumber = 0;
232 MaximumControllerNumber = ControllerFullInformation->SubKeys;
233
234 /* Cleanup */
235 ExFreePoolWithTag(ControllerFullInformation, TAG_IO_RESOURCE);
236 ControllerFullInformation = NULL;
237 }
238
239 /* Save string */
240 ControllerRegName = ControllerRootRegName;
241
242 /* Loop through controllers */
243 for (; ControllerNumber < MaximumControllerNumber; ControllerNumber++)
244 {
245 /* Load string */
246 ControllerRootRegName = ControllerRegName;
247
248 /* Convert controller number to registry string */
249 Status = RtlIntegerToUnicodeString(ControllerNumber, 10, &TempString);
250
251 /* Create string */
252 Status |= RtlAppendUnicodeToString(&ControllerRootRegName, L"\\");
253 Status |= RtlAppendUnicodeStringToString(&ControllerRootRegName, &TempString);
254
255 /* Something messed up */
256 if (!NT_SUCCESS(Status))
257 break;
258
259 IORSRCTRACE(" Retrieving controller '%wZ'\n", &ControllerRootRegName);
260
261 /* Open the registry key */
263 &ControllerRootRegName,
265 NULL,
266 NULL);
267
268 Status = ZwOpenKey(&ControllerKeyHandle, KEY_READ, &ObjectAttributes);
269
270 /* Read the configuration data */
271 if (NT_SUCCESS(Status))
272 {
273 for (ControllerLoop = 0; ControllerLoop < RTL_NUMBER_OF(IoDeviceInfoNames); ControllerLoop++)
274 {
275 /* Identifier string first */
276 RtlInitUnicodeString(&ControllerString, IoDeviceInfoNames[ControllerLoop]);
277
278 /* Retrieve the necessary buffer space */
279 Status = ZwQueryValueKey(ControllerKeyHandle,
280 &ControllerString,
282 NULL, 0,
283 &LenKeyFullInformation);
284
285 if (!NT_SUCCESS(Status) &&
288 {
289 continue;
290 }
291
292 /* Allocate it */
293 ControllerInformation[ControllerLoop] = ExAllocatePoolWithTag(PagedPool, LenKeyFullInformation, TAG_IO_RESOURCE);
294
295 /* Get the information */
296 Status = ZwQueryValueKey(ControllerKeyHandle,
297 &ControllerString,
299 ControllerInformation[ControllerLoop],
300 LenKeyFullInformation,
301 &LenKeyFullInformation);
302 }
303
304 /* Cleanup */
305 ZwClose(ControllerKeyHandle);
306 ControllerKeyHandle = NULL;
307 }
308
309 /* Something messed up */
310 if (!NT_SUCCESS(Status))
311 goto EndLoop;
312
313 /* We now have bus *AND* controller information, is it enough? */
314 if (!Query->PeripheralType || !(*Query->PeripheralType))
315 {
316 IORSRCTRACE(" --> Bus #%lu Controller #%lu Callout: '%wZ'\n",
317 Bus, ControllerNumber, &ControllerRootRegName);
318
319 Status = Query->CalloutRoutine(Query->Context,
320 &ControllerRootRegName,
321 *Query->BusType,
322 Bus,
324 *Query->ControllerType,
325 ControllerNumber,
326 ControllerInformation,
327 0,
328 0,
329 NULL);
330 goto EndLoop;
331 }
332
333 /* Not enough: the caller also wants peripheral name */
334 Status = RtlAppendUnicodeToString(&ControllerRootRegName, L"\\");
335 Status |= RtlAppendUnicodeToString(&ControllerRootRegName, ArcTypes[*Query->PeripheralType]);
336
337 /* Something messed up */
338 if (!NT_SUCCESS(Status))
339 goto EndLoop;
340
341 /* Set the peripheral number if specified */
342 if (Query->PeripheralNumber && *Query->PeripheralNumber)
343 {
344 PeripheralNumber = *Query->PeripheralNumber;
345 MaximumPeripheralNumber = PeripheralNumber + 1;
346 IORSRCTRACE(" Getting peripheral #%lu\n", PeripheralNumber);
347 }
348 else
349 {
350 IORSRCTRACE(" Enumerating peripherals in '%wZ'...\n", &ControllerRootRegName);
351
352 /* Find out how many peripherals there are */
354 &ControllerRootRegName,
356 NULL,
357 NULL);
358
359 Status = ZwOpenKey(&PeripheralKeyHandle, KEY_READ, &ObjectAttributes);
360
361 if (NT_SUCCESS(Status))
362 {
363 /* Retrieve the necessary buffer space */
364 ZwQueryKey(PeripheralKeyHandle,
366 NULL, 0,
367 &LenFullInformation);
368
369 /* Allocate it */
370 PeripheralFullInformation = ExAllocatePoolWithTag(PagedPool, LenFullInformation, TAG_IO_RESOURCE);
371
372 /* Get the information */
373 Status = ZwQueryKey(PeripheralKeyHandle,
375 PeripheralFullInformation,
376 LenFullInformation,
377 &LenFullInformation);
378 ZwClose(PeripheralKeyHandle);
379 PeripheralKeyHandle = NULL;
380 }
381
382 /* No controller was found, cleanup and bail out */
383 if (!NT_SUCCESS(Status))
384 {
386 goto EndLoop;
387 }
388
389 /* Find out peripheral number */
390 PeripheralNumber = 0;
391 MaximumPeripheralNumber = PeripheralFullInformation->SubKeys;
392
393 /* Cleanup */
394 ExFreePoolWithTag(PeripheralFullInformation, TAG_IO_RESOURCE);
395 PeripheralFullInformation = NULL;
396 }
397
398 /* Save name */
399 ControllerRegName = ControllerRootRegName;
400
401 /* Loop through peripherals */
402 for (; PeripheralNumber < MaximumPeripheralNumber; PeripheralNumber++)
403 {
404 /* Restore name */
405 ControllerRootRegName = ControllerRegName;
406
407 /* Convert peripheral number to registry string */
408 Status = RtlIntegerToUnicodeString(PeripheralNumber, 10, &TempString);
409
410 /* Create string */
411 Status |= RtlAppendUnicodeToString(&ControllerRootRegName, L"\\");
412 Status |= RtlAppendUnicodeStringToString(&ControllerRootRegName, &TempString);
413
414 /* Something messed up */
415 if (!NT_SUCCESS(Status))
416 break;
417
418 IORSRCTRACE(" Retrieving peripheral '%wZ'\n", &ControllerRootRegName);
419
420 /* Open the registry key */
422 &ControllerRootRegName,
424 NULL,
425 NULL);
426
427 Status = ZwOpenKey(&PeripheralKeyHandle, KEY_READ, &ObjectAttributes);
428
429 if (NT_SUCCESS(Status))
430 {
431 for (PeripheralLoop = 0; PeripheralLoop < RTL_NUMBER_OF(IoDeviceInfoNames); PeripheralLoop++)
432 {
433 /* Identifier string first */
434 RtlInitUnicodeString(&PeripheralString, IoDeviceInfoNames[PeripheralLoop]);
435
436 /* Retrieve the necessary buffer space */
437 Status = ZwQueryValueKey(PeripheralKeyHandle,
438 &PeripheralString,
440 NULL, 0,
441 &LenKeyFullInformation);
442
443 if (!NT_SUCCESS(Status) &&
446 {
447 PeripheralInformation[PeripheralLoop] = NULL;
448 continue;
449 }
450
451 /* Allocate it */
452 PeripheralInformation[PeripheralLoop] = ExAllocatePoolWithTag(PagedPool, LenKeyFullInformation, TAG_IO_RESOURCE);
453
454 /* Get the information */
455 Status = ZwQueryValueKey(PeripheralKeyHandle,
456 &PeripheralString,
458 PeripheralInformation[PeripheralLoop],
459 LenKeyFullInformation,
460 &LenKeyFullInformation);
461 }
462
463 /* Cleanup */
464 ZwClose(PeripheralKeyHandle);
465 PeripheralKeyHandle = NULL;
466
467 /* We now have everything the caller could possibly want */
468 if (NT_SUCCESS(Status))
469 {
470 IORSRCTRACE(" --> Bus #%lu Controller #%lu Peripheral #%lu Callout: '%wZ'\n",
471 Bus, ControllerNumber, PeripheralNumber, &ControllerRootRegName);
472
473 Status = Query->CalloutRoutine(Query->Context,
474 &ControllerRootRegName,
475 *Query->BusType,
476 Bus,
478 *Query->ControllerType,
479 ControllerNumber,
480 ControllerInformation,
481 *Query->PeripheralType,
482 PeripheralNumber,
483 PeripheralInformation);
484 }
485
486 /* Free the allocated memory */
487 for (PeripheralLoop = 0; PeripheralLoop < RTL_NUMBER_OF(IoDeviceInfoNames); PeripheralLoop++)
488 {
489 if (PeripheralInformation[PeripheralLoop])
490 {
491 ExFreePoolWithTag(PeripheralInformation[PeripheralLoop], TAG_IO_RESOURCE);
492 PeripheralInformation[PeripheralLoop] = NULL;
493 }
494 }
495
496 /* Something messed up */
497 if (!NT_SUCCESS(Status))
498 break;
499 }
500 }
501
502EndLoop:
503 /* Free the allocated memory */
504 for (ControllerLoop = 0; ControllerLoop < RTL_NUMBER_OF(IoDeviceInfoNames); ControllerLoop++)
505 {
506 if (ControllerInformation[ControllerLoop])
507 {
508 ExFreePoolWithTag(ControllerInformation[ControllerLoop], TAG_IO_RESOURCE);
509 ControllerInformation[ControllerLoop] = NULL;
510 }
511 }
512
513 /* Something messed up */
514 if (!NT_SUCCESS(Status))
515 break;
516 }
517
518 return Status;
519}
PCWSTR ArcTypes[MaximumType+1]
Definition: iorsrce.c:47
NTSYSAPI NTSTATUS NTAPI RtlIntegerToUnicodeString(ULONG Value, ULONG Base, PUNICODE_STRING String)

Referenced by IopQueryBusDescription().

◆ IopStoreSystemPartitionInformation()

VOID IopStoreSystemPartitionInformation ( _In_ PUNICODE_STRING  NtSystemPartitionDeviceName,
_In_ PUNICODE_STRING  OsLoaderPathName 
)

Definition at line 830 of file iorsrce.c.

833{
837 HANDLE LinkHandle, RegistryHandle, KeyHandle;
838 WCHAR LinkTargetBuffer[256];
839 UNICODE_STRING CmRegistryMachineSystemName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM");
840
841 ASSERT(NtSystemPartitionDeviceName->MaximumLength >= NtSystemPartitionDeviceName->Length + sizeof(WCHAR));
842 ASSERT(NtSystemPartitionDeviceName->Buffer[NtSystemPartitionDeviceName->Length / sizeof(WCHAR)] == UNICODE_NULL);
843 ASSERT(OsLoaderPathName->MaximumLength >= OsLoaderPathName->Length + sizeof(WCHAR));
844 ASSERT(OsLoaderPathName->Buffer[OsLoaderPathName->Length / sizeof(WCHAR)] == UNICODE_NULL);
845
846 /* First define needed stuff to open NtSystemPartitionDeviceName symbolic link */
848 NtSystemPartitionDeviceName,
850 NULL,
851 NULL);
852
853 /* Open NtSystemPartitionDeviceName symbolic link */
854 Status = ZwOpenSymbolicLinkObject(&LinkHandle,
857 if (!NT_SUCCESS(Status))
858 {
859 DPRINT("Failed to open symlink %wZ, Status=%lx\n", NtSystemPartitionDeviceName, Status);
860 return;
861 }
862
863 /* Prepare the string that will receive where symbolic link points to */
864 LinkTarget.Length = 0;
865 /* We will zero the end of the string after having received it */
866 LinkTarget.MaximumLength = sizeof(LinkTargetBuffer) - sizeof(UNICODE_NULL);
867 LinkTarget.Buffer = LinkTargetBuffer;
868
869 /* Query target */
870 Status = ZwQuerySymbolicLinkObject(LinkHandle, &LinkTarget, NULL);
871
872 /* We are done with symbolic link */
873 ObCloseHandle(LinkHandle, KernelMode);
874
875 if (!NT_SUCCESS(Status))
876 {
877 DPRINT("Failed querying symlink %wZ, Status=%lx\n", NtSystemPartitionDeviceName, Status);
878 return;
879 }
880
881 /* As promised, we zero the end */
883
884 /* Open registry to save data (HKLM\SYSTEM) */
885 Status = IopOpenRegistryKeyEx(&RegistryHandle,
886 NULL,
887 &CmRegistryMachineSystemName,
889 if (!NT_SUCCESS(Status))
890 {
891 DPRINT("Failed to open HKLM\\SYSTEM, Status=%lx\n", Status);
892 return;
893 }
894
895 /* Open or create the Setup subkey where we'll store in */
897
899 RegistryHandle,
900 &KeyName,
903 NULL);
904
905 /* We're done with HKLM\SYSTEM */
906 ObCloseHandle(RegistryHandle, KernelMode);
907
908 if (!NT_SUCCESS(Status))
909 {
910 DPRINT("Failed opening/creating Setup key, Status=%lx\n", Status);
911 return;
912 }
913
914 /* Prepare first data writing */
915 RtlInitUnicodeString(&KeyName, L"SystemPartition");
916
917 /* Write SystemPartition value which is the target of the symbolic link */
918 Status = ZwSetValueKey(KeyHandle,
919 &KeyName,
920 0,
921 REG_SZ,
923 LinkTarget.Length + sizeof(WCHAR));
924 if (!NT_SUCCESS(Status))
925 {
926 DPRINT("Failed writing SystemPartition value, Status=%lx\n", Status);
927 }
928
929 /* Prepare for second data writing */
930 RtlInitUnicodeString(&KeyName, L"OsLoaderPath");
931
932 /* Remove trailing slash if any (one slash only excepted) */
933 if (OsLoaderPathName->Length > sizeof(WCHAR) &&
934 OsLoaderPathName->Buffer[(OsLoaderPathName->Length / sizeof(WCHAR)) - 1] == OBJ_NAME_PATH_SEPARATOR)
935 {
936 OsLoaderPathName->Length -= sizeof(WCHAR);
937 OsLoaderPathName->Buffer[OsLoaderPathName->Length / sizeof(WCHAR)] = UNICODE_NULL;
938 }
939
940 /* Then, write down data */
941 Status = ZwSetValueKey(KeyHandle,
942 &KeyName,
943 0,
944 REG_SZ,
945 OsLoaderPathName->Buffer,
946 OsLoaderPathName->Length + sizeof(UNICODE_NULL));
947 if (!NT_SUCCESS(Status))
948 {
949 DPRINT("Failed writing OsLoaderPath value, Status=%lx\n", Status);
950 }
951
952 /* We're finally done! */
954}
#define OBJ_NAME_PATH_SEPARATOR
Definition: arcname_tests.c:25
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define REG_SZ
Definition: layer.c:22
#define ASSERT(a)
Definition: mode.c:44
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
#define KernelMode
Definition: asm.h:34
NTSYSAPI NTSTATUS NTAPI ZwOpenSymbolicLinkObject(_Out_ PHANDLE SymbolicLinkHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
#define SYMBOLIC_LINK_QUERY
Definition: nt_native.h:1265
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
NTSTATUS NTAPI IopOpenRegistryKeyEx(PHANDLE KeyHandle, HANDLE ParentKey, PUNICODE_STRING Name, ACCESS_MASK DesiredAccess)
Definition: pnpmgr.c:885
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 ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3379
#define DPRINT
Definition: sndvol32.h:71
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699
_Inout_ PUNICODE_STRING LinkTarget
Definition: zwfuncs.h:292

Referenced by IopCreateArcNames(), and IopCreateArcNamesDisk().

◆ IoQueryDeviceDescription()

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.

Parameters
[in]BusTypeSpecifies the bus type, for example: MCA, ISA, EISA, etc.
[in]BusNumberThe number of the specified bus type to query.
[in]ControllerTypeSpecifies the controller type
[in]ControllerNumberThe number of the specified controller type to query.
[in]CalloutRoutineA user-provided callback function to call for each valid query.
[in]ContextA callback-specific context value.
Returns
A status code.

Definition at line 1184 of file iorsrce.c.

1193{
1195 ULONG BusLoopNumber = -1; /* Root Bus */
1197 UNICODE_STRING RootRegKey;
1198 HANDLE RootRegHandle;
1200
1201 IORSRCTRACE("\nIoQueryDeviceDescription()\n"
1202 " BusType: 0x%p (%lu)\n"
1203 " BusNumber: 0x%p (%lu)\n"
1204 " ControllerType: 0x%p (%lu)\n"
1205 " ControllerNumber: 0x%p (%lu)\n"
1206 " PeripheralType: 0x%p (%lu)\n"
1207 " PeripheralNumber: 0x%p (%lu)\n"
1208 " CalloutRoutine: 0x%p\n"
1209 " Context: 0x%p\n"
1210 "--> Query: 0x%p\n",
1211 BusType, BusType ? *BusType : -1,
1212 BusNumber, BusNumber ? *BusNumber : -1,
1213 ControllerType, ControllerType ? *ControllerType : -1,
1214 ControllerNumber, ControllerNumber ? *ControllerNumber : -1,
1215 PeripheralType, PeripheralType ? *PeripheralType : -1,
1216 PeripheralNumber, PeripheralNumber ? *PeripheralNumber : -1,
1217 CalloutRoutine, Context,
1218 &Query);
1219
1220 /* Set up the string */
1221 RootRegKey.Length = 0;
1222 RootRegKey.MaximumLength = 2048;
1224 RtlAppendUnicodeToString(&RootRegKey, L"\\REGISTRY\\MACHINE\\HARDWARE\\DESCRIPTION\\SYSTEM");
1225
1226 /* Open a handle to the Root Registry Key */
1228 &RootRegKey,
1230 NULL,
1231 NULL);
1232
1233 Status = ZwOpenKey(&RootRegHandle, KEY_READ, &ObjectAttributes);
1234
1235 if (NT_SUCCESS(Status))
1236 {
1237 /* Use a helper function to loop though this key and get the information */
1238 Query.BusType = BusType;
1239 Query.BusNumber = BusNumber;
1240 Query.ControllerType = ControllerType;
1241 Query.ControllerNumber = ControllerNumber;
1242 Query.PeripheralType = PeripheralType;
1243 Query.PeripheralNumber = PeripheralNumber;
1244 Query.CalloutRoutine = CalloutRoutine;
1245 Query.Context = Context;
1247 RootRegKey,
1248 RootRegHandle,
1249 &BusLoopNumber,
1250 TRUE);
1251
1252 /* Close registry key */
1253 ZwClose(RootRegHandle);
1254 }
1255
1256 /* Cleanup */
1258
1259 return Status;
1260}
#define TRUE
Definition: types.h:120
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:160
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE BusType
Definition: halfuncs.h:159

Referenced by AddControllers(), FdcFdoQueryBusRelations(), and SpiCreatePortConfig().

◆ IoReportHalResourceUsage()

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.

Parameters
[in]HalNameDescriptive name of the HAL.
[in]RawResourceListList of raw (bus specific) resources which should be claimed for the HAL.
[in]TranslatedResourceListList of translated (system wide) resources which should be claimed for the HAL.
[in]ResourceListSizeSize in bytes of the raw and translated resource lists. Both lists have the same size.
Returns
A status code.

Definition at line 1286 of file iorsrce.c.

1291{
1296 HANDLE ResourceMapKey;
1297 HANDLE HalKey;
1299
1300 /* Open/Create 'RESOURCEMAP' key */
1301 RtlInitUnicodeString(&Name, L"\\Registry\\Machine\\HARDWARE\\RESOURCEMAP");
1303 &Name,
1305 0,
1306 NULL);
1307 Status = ZwCreateKey(&ResourceMapKey,
1310 0,
1311 NULL,
1313 &Disposition);
1314 if (!NT_SUCCESS(Status))
1315 return Status;
1316
1317 /* Open/Create 'Hardware Abstraction Layer' key */
1318 RtlInitUnicodeString(&Name, L"Hardware Abstraction Layer");
1320 &Name,
1322 ResourceMapKey,
1323 NULL);
1324 Status = ZwCreateKey(&HalKey,
1327 0,
1328 NULL,
1330 &Disposition);
1331 ZwClose(ResourceMapKey);
1332 if (!NT_SUCCESS(Status))
1333 return Status;
1334
1335 /* Create 'HalName' key */
1337 HalName,
1339 HalKey,
1340 NULL);
1341 Status = ZwCreateKey(&DescriptionKey,
1344 0,
1345 NULL,
1347 &Disposition);
1348 ZwClose(HalKey);
1349 if (!NT_SUCCESS(Status))
1350 return Status;
1351
1352 /* Add '.Raw' value */
1353 RtlInitUnicodeString(&Name, L".Raw");
1354 Status = ZwSetValueKey(DescriptionKey,
1355 &Name,
1356 0,
1358 RawResourceList,
1359 ResourceListSize);
1360 if (!NT_SUCCESS(Status))
1361 {
1363 return Status;
1364 }
1365
1366 /* Add '.Translated' value */
1367 RtlInitUnicodeString(&Name, L".Translated");
1368 Status = ZwSetValueKey(DescriptionKey,
1369 &Name,
1370 0,
1372 TranslatedResourceList,
1373 ResourceListSize);
1375
1376 return Status;
1377}
struct NameRec_ * Name
Definition: cdprocs.h:460
static const WCHAR DescriptionKey[]
Definition: install.c:37
PWCHAR HalName
Definition: halacpi.c:45
#define OBJ_OPENIF
Definition: winternl.h:229
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:56
#define REG_RESOURCE_LIST
Definition: nt_native.h:1502
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060

Referenced by HalpReportResourceUsage().

◆ IoReportResourceUsage()

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 loaded driver cannot attempt to use the same resources.

@halfplemented

Parameters
[in]DriverClassNameThe driver class under which the resource information should be stored.
[in]DriverObjectThe driver object that was provided to the DriverEntry routine.
[in]DriverListResources claimed for the all the driver's devices, rather than per-device.
[in]DriverListSizeSize in bytes of the DriverList.
[in]DeviceObjectThe device object for which resources should be claimed.
[in]DeviceListList of resources that should be claimed for the device.
[in]DeviceListSizeSize of the per-device resource list in bytes.
[in]OverrideConflictTRUE if the resources should be claimed even if a conflict is found.
[out]ConflictDetectedPoints to a variable that receives TRUE if a conflict is detected with another driver.

Definition at line 1012 of file iorsrce.c.

1022{
1025
1026 DPRINT1("IoReportResourceUsage is halfplemented!\n");
1027
1028 if (!DriverList && !DeviceList)
1030
1031 if (DeviceList)
1033 else
1034 ResourceList = DriverList;
1035
1038 {
1039 *ConflictDetected = TRUE;
1040
1041 if (!OverrideConflict)
1042 {
1043 DPRINT1("Denying an attempt to claim resources currently in use by another device!\n");
1045 }
1046 else
1047 {
1048 DPRINT1("Proceeding with conflicting resources\n");
1049 }
1050 }
1051 else if (!NT_SUCCESS(Status))
1052 {
1053 return Status;
1054 }
1055
1056 /* TODO: Claim resources in registry */
1057
1058 *ConflictDetected = FALSE;
1059
1060 return STATUS_SUCCESS;
1061}
#define FALSE
Definition: types.h:117
PDEVICE_LIST DeviceList
Definition: utils.c:27
NTSTATUS NTAPI IopDetectResourceConflict(IN PCM_RESOURCE_LIST ResourceList, IN BOOLEAN Silent, OUT OPTIONAL PCM_PARTIAL_RESOURCE_DESCRIPTOR ConflictingDescriptor)
Definition: pnpres.c:1255
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:309

Variable Documentation

◆ _SystemConfigurationInformation

CONFIGURATION_INFORMATION _SystemConfigurationInformation = { 0, 0, 0, 0, 0, 0, 0, FALSE, FALSE, 0, 0 }
static

Definition at line 31 of file iorsrce.c.

Referenced by IoGetConfigurationInformation().

◆ ArcTypes

PCWSTR ArcTypes[MaximumType+1]

Definition at line 47 of file iorsrce.c.

Referenced by IopQueryDeviceDescription().

◆ IoDeviceInfoNames

PCWSTR IoDeviceInfoNames[IoQueryDeviceMaxData]
Initial value:
=
{
L"Identifier",
L"Configuration Data",
L"Component Information"
}

Definition at line 94 of file iorsrce.c.

Referenced by IopQueryBusDescription(), and IopQueryDeviceDescription().