PipProcessDevNodeTree之状态DeviceNodeUninitialized下调用PiProcessNewDeviceNode建立DeviceNode->InstancePath
2026/4/21 19:00:15 网站建设 项目流程

nt!PipProcessDevNodeTree函数分析之状态DeviceNodeUninitialized下调用PiProcessNewDeviceNode建立DeviceNode->InstancePath

然后进入状态DeviceNodeInitialized


PipSetDevNodeState(DeviceNode, DeviceNodeInitialized, NULL);


NTSTATUS
PipProcessDevNodeTree(
IN PDEVICE_NODE SubtreeRootDeviceNode,
IN BOOLEAN LoadDriver,
IN BOOLEAN ReallocateResources,
IN ENUM_TYPE EnumType,
IN BOOLEAN Synchronous,
IN BOOLEAN ProcessOnlyIntermediateStates,
IN PADD_CONTEXT AddContext,
IN PPI_DEVICE_REQUEST Request
)
{


switch (currentNode->State) {

case DeviceNodeUninitialized:

if (!ProcessOnlyIntermediateStates) {

if (currentNode->Parent == enumeratedBus && startRoot == NULL) {

startRoot = currentNode;
}
if((!ReallocateResources && EnumType == EnumTypeNone) || startRoot) {

status = PiProcessNewDeviceNode(currentNode);
if (NT_SUCCESS(status)) {

nextNode = SameNode;
}
}
}
break;


NTSTATUS
PiProcessNewDeviceNode(
IN PDEVICE_NODE DeviceNode
)
{

}
}
//
// Build the device instance path and create the instance key.
//
status = PiBuildDeviceNodeInstancePath(DeviceNode, busID, deviceID, instanceID);


。。。。。。


//
// ISSUE: Should not mark the state if the IDs were invalid.
//
PipSetDevNodeState(DeviceNode, DeviceNodeInitialized, NULL);

NTSTATUS
PiBuildDeviceNodeInstancePath(
IN PDEVICE_NODE DeviceNode,
IN PWCHAR BusID,
IN PWCHAR DeviceID,
IN PWCHAR InstanceID
)

/*++

Routine Description:

This function builds the instance path (BusID\DeviceID\InstanceID). If
successful, it will free the storage for any existing instance path and
replace with the new one.

Arguments:

DeviceNode - DeviceNode for which the instance path will be built.

BusID - Bus ID.

DeviceID - Device ID.

InstanceID - Instance ID.

Return Value:

NTSTATUS.

--*/

{
ULONG length;
PWCHAR instancePath;

PAGED_CODE();

if (BusID == NULL || DeviceID == NULL || InstanceID == NULL) {

ASSERT( PipIsDevNodeProblem(DeviceNode, CM_PROB_INVALID_DATA) ||
PipIsDevNodeProblem(DeviceNode, CM_PROB_OUT_OF_MEMORY) ||
PipIsDevNodeProblem(DeviceNode, CM_PROB_REGISTRY));

return STATUS_UNSUCCESSFUL;
}

length = (ULONG)((wcslen(BusID) + wcslen(DeviceID) + wcslen(InstanceID) + 2) * sizeof(WCHAR) + sizeof(UNICODE_NULL));
instancePath = (PWCHAR)ExAllocatePool(PagedPool | POOL_COLD_ALLOCATION, length);
if (!instancePath) {

return STATUS_INSUFFICIENT_RESOURCES;
}
//
// Construct the instance path as <BUS>\<DEVICE>\<INSTANCE>. This should always be NULL terminated
// since we have precomputed the length that we pass into this counted routine.
//
StringCbPrintfW(instancePath, length, L"%s\\%s\\%s", BusID, DeviceID, InstanceID);
//
// Free old instance path.
//
if (DeviceNode->InstancePath.Buffer != NULL) {

IopCleanupDeviceRegistryValues(&DeviceNode->InstancePath);
ExFreePool(DeviceNode->InstancePath.Buffer);
}

RtlInitUnicodeString(&DeviceNode->InstancePath, instancePath);

return STATUS_SUCCESS;

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询