2005-10-07 21:09:23 +08:00
|
|
|
/*
|
2008-08-18 21:30:17 +08:00
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
* COPYRIGHT: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: ntoskrnl/io/pnpmgr/pnproot.c
|
2005-01-26 21:58:37 +08:00
|
|
|
* PURPOSE: PnP manager root device
|
|
|
|
* PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
|
2008-11-27 02:56:41 +08:00
|
|
|
* Copyright 2007 Herv? Poussineau (hpoussin@reactos.org)
|
2003-09-26 02:29:45 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
2004-08-16 00:39:12 +08:00
|
|
|
#include <ntoskrnl.h>
|
2003-09-26 02:29:45 +08:00
|
|
|
#define NDEBUG
|
2008-08-31 00:31:06 +08:00
|
|
|
#include <debug.h>
|
2003-09-26 02:29:45 +08:00
|
|
|
|
|
|
|
/* GLOBALS *******************************************************************/
|
|
|
|
|
|
|
|
#define ENUM_NAME_ROOT L"Root"
|
|
|
|
|
|
|
|
/* DATA **********************************************************************/
|
|
|
|
|
2005-02-07 18:33:44 +08:00
|
|
|
typedef struct _PNPROOT_DEVICE
|
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
// Entry on device list
|
|
|
|
LIST_ENTRY ListEntry;
|
|
|
|
// Physical Device Object of device
|
|
|
|
PDEVICE_OBJECT Pdo;
|
|
|
|
// Device ID
|
|
|
|
UNICODE_STRING DeviceID;
|
|
|
|
// Instance ID
|
|
|
|
UNICODE_STRING InstanceID;
|
|
|
|
// Device description
|
|
|
|
UNICODE_STRING DeviceDescription;
|
|
|
|
// Resource requirement list
|
|
|
|
PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirementsList;
|
|
|
|
// Associated resource list
|
|
|
|
PCM_RESOURCE_LIST ResourceList;
|
|
|
|
ULONG ResourceListSize;
|
2003-09-26 02:29:45 +08:00
|
|
|
} PNPROOT_DEVICE, *PPNPROOT_DEVICE;
|
|
|
|
|
2005-02-07 18:33:44 +08:00
|
|
|
typedef enum
|
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
dsStopped,
|
|
|
|
dsStarted,
|
|
|
|
dsPaused,
|
|
|
|
dsRemoved,
|
|
|
|
dsSurpriseRemoved
|
2003-09-26 02:29:45 +08:00
|
|
|
} PNPROOT_DEVICE_STATE;
|
|
|
|
|
2003-12-31 02:52:06 +08:00
|
|
|
typedef struct _PNPROOT_COMMON_DEVICE_EXTENSION
|
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
// Wether this device extension is for an FDO or PDO
|
|
|
|
BOOLEAN IsFDO;
|
2003-12-31 02:52:06 +08:00
|
|
|
} PNPROOT_COMMON_DEVICE_EXTENSION, *PPNPROOT_COMMON_DEVICE_EXTENSION;
|
|
|
|
|
2003-09-26 02:29:45 +08:00
|
|
|
/* Physical Device Object device extension for a child device */
|
|
|
|
typedef struct _PNPROOT_PDO_DEVICE_EXTENSION
|
2003-12-31 02:52:06 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
// Common device data
|
|
|
|
PNPROOT_COMMON_DEVICE_EXTENSION Common;
|
|
|
|
// Informations about the device
|
|
|
|
PPNPROOT_DEVICE DeviceInfo;
|
2003-12-31 02:52:06 +08:00
|
|
|
} PNPROOT_PDO_DEVICE_EXTENSION, *PPNPROOT_PDO_DEVICE_EXTENSION;
|
|
|
|
|
2007-06-04 17:15:04 +08:00
|
|
|
/* Physical Device Object device extension for the Root bus device object */
|
2003-09-26 02:29:45 +08:00
|
|
|
typedef struct _PNPROOT_FDO_DEVICE_EXTENSION
|
2003-12-31 02:52:06 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
// Common device data
|
|
|
|
PNPROOT_COMMON_DEVICE_EXTENSION Common;
|
|
|
|
// Lower device object
|
|
|
|
PDEVICE_OBJECT Ldo;
|
|
|
|
// Current state of the driver
|
|
|
|
PNPROOT_DEVICE_STATE State;
|
|
|
|
// Namespace device list
|
|
|
|
LIST_ENTRY DeviceListHead;
|
|
|
|
// Number of (not removed) devices in device list
|
|
|
|
ULONG DeviceListCount;
|
|
|
|
// Lock for namespace device list
|
|
|
|
KGUARDED_MUTEX DeviceListLock;
|
2003-12-31 02:52:06 +08:00
|
|
|
} PNPROOT_FDO_DEVICE_EXTENSION, *PPNPROOT_FDO_DEVICE_EXTENSION;
|
|
|
|
|
2007-06-04 17:15:04 +08:00
|
|
|
typedef struct _BUFFER
|
|
|
|
{
|
2007-12-21 17:40:32 +08:00
|
|
|
PVOID *Data;
|
2007-12-03 16:25:54 +08:00
|
|
|
PULONG Length;
|
2007-06-04 17:15:04 +08:00
|
|
|
} BUFFER, *PBUFFER;
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-06-04 17:15:04 +08:00
|
|
|
static PDEVICE_OBJECT PnpRootDeviceObject = NULL;
|
2003-09-26 02:29:45 +08:00
|
|
|
|
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
2007-06-04 17:15:04 +08:00
|
|
|
static NTSTATUS
|
|
|
|
LocateChildDevice(
|
2007-12-03 16:25:54 +08:00
|
|
|
IN PPNPROOT_FDO_DEVICE_EXTENSION DeviceExtension,
|
2020-05-02 23:57:46 +08:00
|
|
|
IN PCUNICODE_STRING DeviceId,
|
2007-12-03 16:25:54 +08:00
|
|
|
IN PCWSTR InstanceId,
|
2021-12-14 06:27:01 +08:00
|
|
|
OUT PPNPROOT_DEVICE* ChildDevice OPTIONAL)
|
2007-06-04 17:15:04 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
PPNPROOT_DEVICE Device;
|
2020-05-02 23:57:46 +08:00
|
|
|
UNICODE_STRING InstanceIdU;
|
2008-08-26 02:21:19 +08:00
|
|
|
PLIST_ENTRY NextEntry;
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2020-05-02 23:57:46 +08:00
|
|
|
/* Initialize the string to compare */
|
2007-12-03 16:25:54 +08:00
|
|
|
RtlInitUnicodeString(&InstanceIdU, InstanceId);
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2008-08-25 04:40:27 +08:00
|
|
|
/* Start looping */
|
2008-08-26 02:21:19 +08:00
|
|
|
for (NextEntry = DeviceExtension->DeviceListHead.Flink;
|
|
|
|
NextEntry != &DeviceExtension->DeviceListHead;
|
|
|
|
NextEntry = NextEntry->Flink)
|
2007-12-03 16:25:54 +08:00
|
|
|
{
|
2008-08-26 02:21:19 +08:00
|
|
|
/* Get the entry */
|
|
|
|
Device = CONTAINING_RECORD(NextEntry, PNPROOT_DEVICE, ListEntry);
|
|
|
|
|
2008-08-25 04:40:27 +08:00
|
|
|
/* See if the strings match */
|
2020-05-02 23:57:46 +08:00
|
|
|
if (RtlEqualUnicodeString(DeviceId, &Device->DeviceID, TRUE) &&
|
2008-08-25 04:40:27 +08:00
|
|
|
RtlEqualUnicodeString(&InstanceIdU, &Device->InstanceID, TRUE))
|
2007-12-03 16:25:54 +08:00
|
|
|
{
|
2008-08-25 04:40:27 +08:00
|
|
|
/* They do, so set the pointer and return success */
|
2021-12-14 06:27:01 +08:00
|
|
|
if (ChildDevice)
|
|
|
|
*ChildDevice = Device;
|
2007-12-03 16:25:54 +08:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2008-08-25 04:40:27 +08:00
|
|
|
/* No device found */
|
2007-12-03 16:25:54 +08:00
|
|
|
return STATUS_NO_SUCH_DEVICE;
|
2007-06-04 17:15:04 +08:00
|
|
|
}
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2012-03-21 15:15:55 +08:00
|
|
|
NTSTATUS
|
|
|
|
PnpRootRegisterDevice(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject)
|
|
|
|
{
|
|
|
|
PPNPROOT_FDO_DEVICE_EXTENSION DeviceExtension = PnpRootDeviceObject->DeviceExtension;
|
|
|
|
PPNPROOT_DEVICE Device;
|
|
|
|
PDEVICE_NODE DeviceNode;
|
|
|
|
PWSTR InstancePath;
|
|
|
|
UNICODE_STRING InstancePathCopy;
|
|
|
|
|
|
|
|
Device = ExAllocatePoolWithTag(PagedPool, sizeof(PNPROOT_DEVICE), TAG_PNP_ROOT);
|
|
|
|
if (!Device) return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
DeviceNode = IopGetDeviceNode(DeviceObject);
|
|
|
|
if (!RtlCreateUnicodeString(&InstancePathCopy, DeviceNode->InstancePath.Buffer))
|
|
|
|
{
|
|
|
|
ExFreePoolWithTag(Device, TAG_PNP_ROOT);
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
InstancePath = wcsrchr(InstancePathCopy.Buffer, L'\\');
|
|
|
|
ASSERT(InstancePath);
|
|
|
|
|
|
|
|
if (!RtlCreateUnicodeString(&Device->InstanceID, InstancePath + 1))
|
|
|
|
{
|
|
|
|
RtlFreeUnicodeString(&InstancePathCopy);
|
|
|
|
ExFreePoolWithTag(Device, TAG_PNP_ROOT);
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
InstancePath[0] = UNICODE_NULL;
|
|
|
|
|
|
|
|
if (!RtlCreateUnicodeString(&Device->DeviceID, InstancePathCopy.Buffer))
|
|
|
|
{
|
|
|
|
RtlFreeUnicodeString(&InstancePathCopy);
|
|
|
|
RtlFreeUnicodeString(&Device->InstanceID);
|
|
|
|
ExFreePoolWithTag(Device, TAG_PNP_ROOT);
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
InstancePath[0] = L'\\';
|
|
|
|
|
|
|
|
Device->Pdo = DeviceObject;
|
|
|
|
|
|
|
|
KeAcquireGuardedMutex(&DeviceExtension->DeviceListLock);
|
|
|
|
InsertTailList(&DeviceExtension->DeviceListHead,
|
|
|
|
&Device->ListEntry);
|
|
|
|
DeviceExtension->DeviceListCount++;
|
|
|
|
KeReleaseGuardedMutex(&DeviceExtension->DeviceListLock);
|
|
|
|
|
|
|
|
RtlFreeUnicodeString(&InstancePathCopy);
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-06-04 17:15:04 +08:00
|
|
|
/* Creates a new PnP device for a legacy driver */
|
2003-09-26 02:29:45 +08:00
|
|
|
NTSTATUS
|
|
|
|
PnpRootCreateDevice(
|
2007-12-03 16:25:54 +08:00
|
|
|
IN PUNICODE_STRING ServiceName,
|
2011-08-23 11:57:24 +08:00
|
|
|
IN OPTIONAL PDRIVER_OBJECT DriverObject,
|
2010-04-02 11:47:14 +08:00
|
|
|
OUT PDEVICE_OBJECT *PhysicalDeviceObject,
|
|
|
|
OUT OPTIONAL PUNICODE_STRING FullInstancePath)
|
2003-09-26 02:29:45 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
PPNPROOT_FDO_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
PPNPROOT_PDO_DEVICE_EXTENSION PdoDeviceExtension;
|
2020-05-02 23:42:40 +08:00
|
|
|
UNICODE_STRING DevicePath;
|
2007-12-03 16:25:54 +08:00
|
|
|
WCHAR InstancePath[5];
|
|
|
|
PPNPROOT_DEVICE Device = NULL;
|
|
|
|
NTSTATUS Status;
|
2010-04-02 11:47:14 +08:00
|
|
|
UNICODE_STRING PathSep = RTL_CONSTANT_STRING(L"\\");
|
2010-04-10 12:11:45 +08:00
|
|
|
ULONG NextInstance;
|
|
|
|
UNICODE_STRING EnumKeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\" REGSTR_PATH_SYSTEMENUM);
|
2016-03-31 15:51:08 +08:00
|
|
|
HANDLE EnumHandle, DeviceKeyHandle = NULL, InstanceKeyHandle;
|
2010-04-10 12:11:45 +08:00
|
|
|
RTL_QUERY_REGISTRY_TABLE QueryTable[2];
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
2007-12-03 16:25:54 +08:00
|
|
|
|
|
|
|
DeviceExtension = PnpRootDeviceObject->DeviceExtension;
|
|
|
|
KeAcquireGuardedMutex(&DeviceExtension->DeviceListLock);
|
|
|
|
|
2010-04-02 11:47:14 +08:00
|
|
|
DPRINT("Creating a PnP root device for service '%wZ'\n", ServiceName);
|
2007-12-03 16:25:54 +08:00
|
|
|
|
2020-05-02 23:42:40 +08:00
|
|
|
DevicePath.Length = 0;
|
|
|
|
DevicePath.MaximumLength = sizeof(REGSTR_KEY_ROOTENUM) + sizeof(L'\\') + ServiceName->Length;
|
|
|
|
DevicePath.Buffer = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
DevicePath.MaximumLength,
|
|
|
|
TAG_PNP_ROOT);
|
|
|
|
if (DevicePath.Buffer == NULL)
|
|
|
|
{
|
|
|
|
DPRINT1("ExAllocatePoolWithTag() failed\n");
|
|
|
|
Status = STATUS_NO_MEMORY;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
RtlAppendUnicodeToString(&DevicePath, REGSTR_KEY_ROOTENUM L"\\");
|
|
|
|
RtlAppendUnicodeStringToString(&DevicePath, ServiceName);
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
/* Initialize a PNPROOT_DEVICE structure */
|
|
|
|
Device = ExAllocatePoolWithTag(PagedPool, sizeof(PNPROOT_DEVICE), TAG_PNP_ROOT);
|
|
|
|
if (!Device)
|
|
|
|
{
|
|
|
|
DPRINT("ExAllocatePoolWithTag() failed\n");
|
|
|
|
Status = STATUS_NO_MEMORY;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
RtlZeroMemory(Device, sizeof(PNPROOT_DEVICE));
|
2020-05-02 23:42:40 +08:00
|
|
|
Device->DeviceID = DevicePath;
|
|
|
|
RtlInitEmptyUnicodeString(&DevicePath, NULL, 0);
|
2010-04-10 12:11:45 +08:00
|
|
|
|
|
|
|
Status = IopOpenRegistryKeyEx(&EnumHandle, NULL, &EnumKeyName, KEY_READ);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
2013-11-17 02:27:26 +08:00
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&Device->DeviceID,
|
|
|
|
OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE,
|
|
|
|
EnumHandle,
|
|
|
|
NULL);
|
2021-11-01 06:24:32 +08:00
|
|
|
Status = ZwCreateKey(&DeviceKeyHandle, KEY_SET_VALUE, &ObjectAttributes, 0, NULL, REG_OPTION_NON_VOLATILE, NULL);
|
2013-11-17 02:27:26 +08:00
|
|
|
ObCloseHandle(EnumHandle, KernelMode);
|
2010-04-10 12:11:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to open registry key\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
tryagain:
|
|
|
|
RtlZeroMemory(QueryTable, sizeof(QueryTable));
|
|
|
|
QueryTable[0].Name = L"NextInstance";
|
|
|
|
QueryTable[0].EntryContext = &NextInstance;
|
|
|
|
QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED;
|
|
|
|
|
|
|
|
Status = RtlQueryRegistryValues(RTL_REGISTRY_HANDLE,
|
|
|
|
(PWSTR)DeviceKeyHandle,
|
|
|
|
QueryTable,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2021-12-14 06:27:01 +08:00
|
|
|
for (NextInstance = 0; NextInstance <= 9999; NextInstance++)
|
2010-04-10 12:11:45 +08:00
|
|
|
{
|
2021-12-14 06:27:01 +08:00
|
|
|
_snwprintf(InstancePath, sizeof(InstancePath) / sizeof(WCHAR), L"%04lu", NextInstance);
|
|
|
|
Status = LocateChildDevice(DeviceExtension, &Device->DeviceID, InstancePath, NULL);
|
|
|
|
if (Status == STATUS_NO_SUCH_DEVICE)
|
|
|
|
break;
|
|
|
|
}
|
2010-04-10 12:11:45 +08:00
|
|
|
|
2021-12-14 06:27:01 +08:00
|
|
|
if (NextInstance > 9999)
|
|
|
|
{
|
|
|
|
DPRINT1("Too many legacy devices reported for service '%wZ'\n", ServiceName);
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
goto cleanup;
|
2010-04-10 12:11:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_snwprintf(InstancePath, sizeof(InstancePath) / sizeof(WCHAR), L"%04lu", NextInstance);
|
2021-12-14 06:27:01 +08:00
|
|
|
Status = LocateChildDevice(DeviceExtension, &Device->DeviceID, InstancePath, NULL);
|
2010-04-10 12:11:45 +08:00
|
|
|
if (Status != STATUS_NO_SUCH_DEVICE || NextInstance > 9999)
|
|
|
|
{
|
2013-09-01 00:02:13 +08:00
|
|
|
DPRINT1("NextInstance value is corrupt! (%lu)\n", NextInstance);
|
2010-04-10 12:11:45 +08:00
|
|
|
RtlDeleteRegistryValue(RTL_REGISTRY_HANDLE,
|
|
|
|
(PWSTR)DeviceKeyHandle,
|
|
|
|
L"NextInstance");
|
|
|
|
goto tryagain;
|
|
|
|
}
|
|
|
|
|
|
|
|
NextInstance++;
|
|
|
|
Status = RtlWriteRegistryValue(RTL_REGISTRY_HANDLE,
|
|
|
|
(PWSTR)DeviceKeyHandle,
|
|
|
|
L"NextInstance",
|
|
|
|
REG_DWORD,
|
|
|
|
&NextInstance,
|
|
|
|
sizeof(NextInstance));
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to write new NextInstance value! (0x%x)\n", Status);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
if (!RtlCreateUnicodeString(&Device->InstanceID, InstancePath))
|
|
|
|
{
|
|
|
|
Status = STATUS_NO_MEMORY;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2011-08-15 13:03:53 +08:00
|
|
|
/* Finish creating the instance path in the registry */
|
2013-11-17 02:27:26 +08:00
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&Device->InstanceID,
|
|
|
|
OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE,
|
|
|
|
DeviceKeyHandle,
|
|
|
|
NULL);
|
2021-11-01 06:24:32 +08:00
|
|
|
Status = ZwCreateKey(&InstanceKeyHandle, KEY_QUERY_VALUE, &ObjectAttributes, 0, NULL, REG_OPTION_NON_VOLATILE, NULL);
|
2013-11-17 02:27:26 +08:00
|
|
|
if (!NT_SUCCESS(Status))
|
2011-08-15 13:03:53 +08:00
|
|
|
{
|
|
|
|
DPRINT1("Failed to create instance path (0x%x)\n", Status);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Just close the handle */
|
2013-11-17 02:27:26 +08:00
|
|
|
ObCloseHandle(InstanceKeyHandle, KernelMode);
|
2011-08-15 13:03:53 +08:00
|
|
|
|
2010-04-02 11:47:14 +08:00
|
|
|
if (FullInstancePath)
|
|
|
|
{
|
|
|
|
FullInstancePath->MaximumLength = Device->DeviceID.Length + PathSep.Length + Device->InstanceID.Length;
|
|
|
|
FullInstancePath->Length = 0;
|
|
|
|
FullInstancePath->Buffer = ExAllocatePool(PagedPool, FullInstancePath->MaximumLength);
|
|
|
|
if (!FullInstancePath->Buffer)
|
|
|
|
{
|
|
|
|
Status = STATUS_NO_MEMORY;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlAppendUnicodeStringToString(FullInstancePath, &Device->DeviceID);
|
|
|
|
RtlAppendUnicodeStringToString(FullInstancePath, &PathSep);
|
|
|
|
RtlAppendUnicodeStringToString(FullInstancePath, &Device->InstanceID);
|
|
|
|
}
|
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
/* Initialize a device object */
|
|
|
|
Status = IoCreateDevice(
|
2011-08-23 11:57:24 +08:00
|
|
|
DriverObject ? DriverObject : PnpRootDeviceObject->DriverObject,
|
2007-12-03 16:25:54 +08:00
|
|
|
sizeof(PNPROOT_PDO_DEVICE_EXTENSION),
|
|
|
|
NULL,
|
|
|
|
FILE_DEVICE_CONTROLLER,
|
|
|
|
FILE_AUTOGENERATED_DEVICE_NAME,
|
|
|
|
FALSE,
|
|
|
|
&Device->Pdo);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT("IoCreateDevice() failed with status 0x%08lx\n", Status);
|
|
|
|
Status = STATUS_NO_MEMORY;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
PdoDeviceExtension = (PPNPROOT_PDO_DEVICE_EXTENSION)Device->Pdo->DeviceExtension;
|
|
|
|
RtlZeroMemory(PdoDeviceExtension, sizeof(PNPROOT_PDO_DEVICE_EXTENSION));
|
|
|
|
PdoDeviceExtension->Common.IsFDO = FALSE;
|
|
|
|
PdoDeviceExtension->DeviceInfo = Device;
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
Device->Pdo->Flags |= DO_BUS_ENUMERATED_DEVICE;
|
|
|
|
Device->Pdo->Flags &= ~DO_DEVICE_INITIALIZING;
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
InsertTailList(
|
|
|
|
&DeviceExtension->DeviceListHead,
|
|
|
|
&Device->ListEntry);
|
|
|
|
DeviceExtension->DeviceListCount++;
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
*PhysicalDeviceObject = Device->Pdo;
|
|
|
|
DPRINT("Created PDO %p (%wZ\\%wZ)\n", *PhysicalDeviceObject, &Device->DeviceID, &Device->InstanceID);
|
|
|
|
Device = NULL;
|
|
|
|
Status = STATUS_SUCCESS;
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-06-04 17:15:04 +08:00
|
|
|
cleanup:
|
2007-12-03 16:25:54 +08:00
|
|
|
KeReleaseGuardedMutex(&DeviceExtension->DeviceListLock);
|
|
|
|
if (Device)
|
|
|
|
{
|
|
|
|
if (Device->Pdo)
|
|
|
|
IoDeleteDevice(Device->Pdo);
|
|
|
|
RtlFreeUnicodeString(&Device->DeviceID);
|
|
|
|
RtlFreeUnicodeString(&Device->InstanceID);
|
|
|
|
ExFreePoolWithTag(Device, TAG_PNP_ROOT);
|
|
|
|
}
|
2020-05-02 23:42:40 +08:00
|
|
|
RtlFreeUnicodeString(&DevicePath);
|
2016-03-31 15:51:08 +08:00
|
|
|
if (DeviceKeyHandle != NULL)
|
2013-11-17 02:27:26 +08:00
|
|
|
ObCloseHandle(DeviceKeyHandle, KernelMode);
|
2007-12-03 16:25:54 +08:00
|
|
|
return Status;
|
2004-06-11 17:33:42 +08:00
|
|
|
}
|
|
|
|
|
2007-06-04 17:15:04 +08:00
|
|
|
static NTSTATUS NTAPI
|
|
|
|
QueryStringCallback(
|
2007-12-03 16:25:54 +08:00
|
|
|
IN PWSTR ValueName,
|
|
|
|
IN ULONG ValueType,
|
|
|
|
IN PVOID ValueData,
|
|
|
|
IN ULONG ValueLength,
|
|
|
|
IN PVOID Context,
|
|
|
|
IN PVOID EntryContext)
|
2005-05-31 07:01:37 +08:00
|
|
|
{
|
2007-12-21 17:40:32 +08:00
|
|
|
PUNICODE_STRING Destination = (PUNICODE_STRING)EntryContext;
|
|
|
|
UNICODE_STRING Source;
|
2007-12-03 16:25:54 +08:00
|
|
|
|
|
|
|
if (ValueType != REG_SZ || ValueLength == 0 || ValueLength % sizeof(WCHAR) != 0)
|
2011-08-21 08:27:58 +08:00
|
|
|
{
|
|
|
|
Destination->Length = 0;
|
|
|
|
Destination->MaximumLength = 0;
|
|
|
|
Destination->Buffer = NULL;
|
2007-12-03 16:25:54 +08:00
|
|
|
return STATUS_SUCCESS;
|
2011-08-21 08:27:58 +08:00
|
|
|
}
|
2007-12-03 16:25:54 +08:00
|
|
|
|
[HAL/NDK]
- Make Vector parameter in HalEnableSystemInterrupt, HalDisableSystemInterrupt and HalBeginSystemInterrupt an ULONG, not an UCHAR
[NDK]
- 64bit fixes for HANDLE_TABLE, KPROCESS, SECTION_IMAGE_INFORMATION, MMADDRESS_LIST, MMVAD_FLAGS, MMVAD, MMVAD_LONG, MMVAD_SHORT, MEMORY_DESCRIPTOR, MEMORY_ALLOCATION_DESCRIPTOR, LdrVerifyMappedImageMatchesChecksum
- KDPC_DATA::DpcQueueDepth is signed on amd64, unsigned on x86
[NTOSKRNL]
- Fix hundreds of MSVC and amd64 warnings
- add a pragma message to FstubFixupEfiPartition, since it looks broken
- Move portable Ke constants from <arch>/cpu.c to krnlinit.c
- Fixed a bug in amd64 KiGeneralProtectionFaultHandler
svn path=/trunk/; revision=53734
2011-09-18 21:11:45 +08:00
|
|
|
Source.MaximumLength = Source.Length = (USHORT)ValueLength;
|
2007-12-21 17:40:32 +08:00
|
|
|
Source.Buffer = ValueData;
|
2011-08-21 08:27:58 +08:00
|
|
|
|
2007-12-21 17:40:32 +08:00
|
|
|
return RtlDuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, &Source, Destination);
|
2005-05-31 07:01:37 +08:00
|
|
|
}
|
|
|
|
|
2007-06-04 17:15:04 +08:00
|
|
|
static NTSTATUS NTAPI
|
|
|
|
QueryBinaryValueCallback(
|
2007-12-03 16:25:54 +08:00
|
|
|
IN PWSTR ValueName,
|
|
|
|
IN ULONG ValueType,
|
|
|
|
IN PVOID ValueData,
|
|
|
|
IN ULONG ValueLength,
|
|
|
|
IN PVOID Context,
|
|
|
|
IN PVOID EntryContext)
|
2003-09-26 02:29:45 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
PBUFFER Buffer = (PBUFFER)EntryContext;
|
|
|
|
PVOID BinaryValue;
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
if (ValueLength == 0)
|
|
|
|
{
|
2007-12-21 17:40:32 +08:00
|
|
|
*Buffer->Data = NULL;
|
2007-12-03 16:25:54 +08:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
BinaryValue = ExAllocatePoolWithTag(PagedPool, ValueLength, TAG_PNP_ROOT);
|
|
|
|
if (BinaryValue == NULL)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
RtlCopyMemory(BinaryValue, ValueData, ValueLength);
|
2007-12-21 17:40:32 +08:00
|
|
|
*Buffer->Data = BinaryValue;
|
2007-12-03 16:25:54 +08:00
|
|
|
if (Buffer->Length) *Buffer->Length = ValueLength;
|
|
|
|
return STATUS_SUCCESS;
|
2003-09-26 02:29:45 +08:00
|
|
|
}
|
|
|
|
|
2020-05-02 23:08:12 +08:00
|
|
|
static
|
|
|
|
NTSTATUS
|
|
|
|
CreateDeviceFromRegistry(
|
|
|
|
_Inout_ PPNPROOT_FDO_DEVICE_EXTENSION DeviceExtension,
|
2020-05-02 23:33:24 +08:00
|
|
|
_Inout_ PUNICODE_STRING DevicePath,
|
2020-05-02 23:08:12 +08:00
|
|
|
_In_ PCWSTR InstanceId,
|
|
|
|
_In_ HANDLE SubKeyHandle)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
PPNPROOT_DEVICE Device;
|
|
|
|
HANDLE DeviceKeyHandle = NULL;
|
|
|
|
RTL_QUERY_REGISTRY_TABLE QueryTable[4];
|
|
|
|
BUFFER Buffer1, Buffer2;
|
|
|
|
|
|
|
|
/* If the device already exists, there's nothing to do */
|
2020-05-02 23:57:46 +08:00
|
|
|
Status = LocateChildDevice(DeviceExtension, DevicePath, InstanceId, &Device);
|
2020-05-02 23:08:12 +08:00
|
|
|
if (Status != STATUS_NO_SUCH_DEVICE)
|
|
|
|
{
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a PPNPROOT_DEVICE object, and add it to the list of known devices */
|
|
|
|
Device = ExAllocatePoolWithTag(PagedPool, sizeof(PNPROOT_DEVICE), TAG_PNP_ROOT);
|
|
|
|
if (!Device)
|
|
|
|
{
|
|
|
|
DPRINT("ExAllocatePoolWithTag() failed\n");
|
|
|
|
Status = STATUS_NO_MEMORY;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
RtlZeroMemory(Device, sizeof(PNPROOT_DEVICE));
|
|
|
|
|
|
|
|
/* Fill device ID and instance ID */
|
2020-05-02 23:33:24 +08:00
|
|
|
Device->DeviceID = *DevicePath;
|
|
|
|
RtlInitEmptyUnicodeString(DevicePath, NULL, 0);
|
2020-05-02 23:08:12 +08:00
|
|
|
if (!RtlCreateUnicodeString(&Device->InstanceID, InstanceId))
|
|
|
|
{
|
|
|
|
DPRINT1("RtlCreateUnicodeString() failed\n");
|
|
|
|
Status = STATUS_NO_MEMORY;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Open registry key to fill other informations */
|
|
|
|
Status = IopOpenRegistryKeyEx(&DeviceKeyHandle, SubKeyHandle, &Device->InstanceID, KEY_READ);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* If our key disappeared, let the caller go on */
|
|
|
|
DPRINT1("IopOpenRegistryKeyEx() failed for '%wZ' with status 0x%lx\n",
|
|
|
|
&Device->InstanceID, Status);
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill information from the device instance key */
|
|
|
|
RtlZeroMemory(QueryTable, sizeof(QueryTable));
|
|
|
|
QueryTable[0].QueryRoutine = QueryStringCallback;
|
|
|
|
QueryTable[0].Name = L"DeviceDesc";
|
|
|
|
QueryTable[0].EntryContext = &Device->DeviceDescription;
|
|
|
|
|
|
|
|
RtlQueryRegistryValues(RTL_REGISTRY_HANDLE,
|
|
|
|
(PCWSTR)DeviceKeyHandle,
|
|
|
|
QueryTable,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* Fill information from the LogConf subkey */
|
|
|
|
Buffer1.Data = (PVOID *)&Device->ResourceRequirementsList;
|
|
|
|
Buffer1.Length = NULL;
|
|
|
|
Buffer2.Data = (PVOID *)&Device->ResourceList;
|
|
|
|
Buffer2.Length = &Device->ResourceListSize;
|
|
|
|
RtlZeroMemory(QueryTable, sizeof(QueryTable));
|
|
|
|
QueryTable[0].Flags = RTL_QUERY_REGISTRY_SUBKEY;
|
|
|
|
QueryTable[0].Name = L"LogConf";
|
|
|
|
QueryTable[1].QueryRoutine = QueryBinaryValueCallback;
|
|
|
|
QueryTable[1].Name = L"BasicConfigVector";
|
|
|
|
QueryTable[1].EntryContext = &Buffer1;
|
|
|
|
QueryTable[2].QueryRoutine = QueryBinaryValueCallback;
|
|
|
|
QueryTable[2].Name = L"BootConfig";
|
|
|
|
QueryTable[2].EntryContext = &Buffer2;
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(RtlQueryRegistryValues(RTL_REGISTRY_HANDLE,
|
|
|
|
(PCWSTR)DeviceKeyHandle,
|
|
|
|
QueryTable,
|
|
|
|
NULL,
|
|
|
|
NULL)))
|
|
|
|
{
|
|
|
|
/* Non-fatal error */
|
2020-05-02 23:33:24 +08:00
|
|
|
DPRINT1("Failed to read the LogConf key for %wZ\\%S\n", &Device->DeviceID, InstanceId);
|
2020-05-02 23:08:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Insert the newly created device into the list */
|
|
|
|
InsertTailList(&DeviceExtension->DeviceListHead,
|
|
|
|
&Device->ListEntry);
|
|
|
|
DeviceExtension->DeviceListCount++;
|
|
|
|
Device = NULL;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (DeviceKeyHandle != NULL)
|
|
|
|
{
|
|
|
|
ZwClose(DeviceKeyHandle);
|
|
|
|
}
|
|
|
|
if (Device != NULL)
|
|
|
|
{
|
|
|
|
/* We have a device that has not been added to device list. We need to clean it up */
|
|
|
|
RtlFreeUnicodeString(&Device->DeviceID);
|
|
|
|
RtlFreeUnicodeString(&Device->InstanceID);
|
|
|
|
ExFreePoolWithTag(Device, TAG_PNP_ROOT);
|
|
|
|
}
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2021-12-14 06:27:01 +08:00
|
|
|
static NTSTATUS
|
|
|
|
IopShouldProcessDevice(
|
|
|
|
IN HANDLE SubKey,
|
|
|
|
IN PCWSTR InstanceID)
|
|
|
|
{
|
|
|
|
UNICODE_STRING DeviceReportedValue = RTL_CONSTANT_STRING(L"DeviceReported");
|
|
|
|
UNICODE_STRING Control = RTL_CONSTANT_STRING(L"Control");
|
|
|
|
UNICODE_STRING InstanceIDU;
|
|
|
|
PKEY_VALUE_FULL_INFORMATION pKeyValueFullInformation;
|
|
|
|
HANDLE InstanceKey, ControlKey;
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
ULONG Size, DeviceReported, ResultLength;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
Size = 128;
|
|
|
|
pKeyValueFullInformation = ExAllocatePool(PagedPool, Size);
|
|
|
|
if (!pKeyValueFullInformation)
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
|
|
|
/* Open Instance key */
|
|
|
|
RtlInitUnicodeString(&InstanceIDU, InstanceID);
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&InstanceIDU,
|
|
|
|
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
|
|
|
|
SubKey,
|
|
|
|
NULL);
|
|
|
|
Status = ZwOpenKey(&InstanceKey,
|
|
|
|
KEY_QUERY_VALUE,
|
|
|
|
&ObjectAttributes);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
ExFreePool(pKeyValueFullInformation);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read 'DeviceReported' Key */
|
|
|
|
Status = ZwQueryValueKey(InstanceKey, &DeviceReportedValue, KeyValueFullInformation, pKeyValueFullInformation, Size, &ResultLength);
|
|
|
|
if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
|
|
|
|
{
|
|
|
|
ZwClose(InstanceKey);
|
|
|
|
ExFreePool(pKeyValueFullInformation);
|
|
|
|
DPRINT("No 'DeviceReported' value\n");
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
else if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
ZwClose(InstanceKey);
|
|
|
|
ExFreePool(pKeyValueFullInformation);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
if (pKeyValueFullInformation->Type != REG_DWORD || pKeyValueFullInformation->DataLength != sizeof(DeviceReported))
|
|
|
|
{
|
|
|
|
ZwClose(InstanceKey);
|
|
|
|
ExFreePool(pKeyValueFullInformation);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
RtlCopyMemory(&DeviceReported, (PVOID)((ULONG_PTR)pKeyValueFullInformation + pKeyValueFullInformation->DataOffset), sizeof(DeviceReported));
|
|
|
|
/* FIXME: Check DeviceReported value? */
|
|
|
|
ASSERT(DeviceReported == 1);
|
|
|
|
|
|
|
|
/* Open Control key */
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&Control,
|
|
|
|
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
|
|
|
|
InstanceKey,
|
|
|
|
NULL);
|
|
|
|
Status = ZwOpenKey(&ControlKey,
|
|
|
|
KEY_QUERY_VALUE,
|
|
|
|
&ObjectAttributes);
|
|
|
|
ZwClose(InstanceKey);
|
|
|
|
if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
|
|
|
|
{
|
|
|
|
DPRINT("No 'Control' key\n");
|
|
|
|
return STATUS_NO_SUCH_DEVICE;
|
|
|
|
}
|
|
|
|
else if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
ExFreePool(pKeyValueFullInformation);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read 'DeviceReported' Key */
|
|
|
|
Status = ZwQueryValueKey(ControlKey, &DeviceReportedValue, KeyValueFullInformation, pKeyValueFullInformation, Size, &ResultLength);
|
|
|
|
ZwClose(ControlKey);
|
|
|
|
if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
|
|
|
|
{
|
|
|
|
ExFreePool(pKeyValueFullInformation);
|
|
|
|
DPRINT("No 'DeviceReported' value\n");
|
|
|
|
return STATUS_NO_SUCH_DEVICE;
|
|
|
|
}
|
|
|
|
else if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
ExFreePool(pKeyValueFullInformation);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
if (pKeyValueFullInformation->Type != REG_DWORD || pKeyValueFullInformation->DataLength != sizeof(DeviceReported))
|
|
|
|
{
|
|
|
|
ExFreePool(pKeyValueFullInformation);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
RtlCopyMemory(&DeviceReported, (PVOID)((ULONG_PTR)pKeyValueFullInformation + pKeyValueFullInformation->DataOffset), sizeof(DeviceReported));
|
|
|
|
/* FIXME: Check DeviceReported value? */
|
|
|
|
ASSERT(DeviceReported == 1);
|
|
|
|
|
|
|
|
ExFreePool(pKeyValueFullInformation);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-06-04 17:15:04 +08:00
|
|
|
static NTSTATUS
|
|
|
|
EnumerateDevices(
|
2007-12-03 16:25:54 +08:00
|
|
|
IN PDEVICE_OBJECT DeviceObject)
|
2003-09-26 02:29:45 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
PPNPROOT_FDO_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
PKEY_BASIC_INFORMATION KeyInfo = NULL, SubKeyInfo = NULL;
|
|
|
|
UNICODE_STRING LegacyU = RTL_CONSTANT_STRING(L"LEGACY_");
|
|
|
|
UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\" REGSTR_PATH_SYSTEMENUM L"\\" REGSTR_KEY_ROOTENUM);
|
|
|
|
UNICODE_STRING SubKeyName;
|
2020-05-02 23:33:24 +08:00
|
|
|
UNICODE_STRING DevicePath;
|
2016-03-31 15:51:08 +08:00
|
|
|
HANDLE KeyHandle = NULL;
|
|
|
|
HANDLE SubKeyHandle = NULL;
|
2019-04-20 16:48:43 +08:00
|
|
|
ULONG KeyInfoSize, SubKeyInfoSize;
|
2007-12-03 16:25:54 +08:00
|
|
|
ULONG ResultSize;
|
|
|
|
ULONG Index1, Index2;
|
|
|
|
NTSTATUS Status = STATUS_UNSUCCESSFUL;
|
|
|
|
|
|
|
|
DPRINT("EnumerateDevices(FDO %p)\n", DeviceObject);
|
|
|
|
|
|
|
|
DeviceExtension = (PPNPROOT_FDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
|
|
|
KeAcquireGuardedMutex(&DeviceExtension->DeviceListLock);
|
|
|
|
|
2019-04-20 16:49:13 +08:00
|
|
|
/* Should hold most key names, but we reallocate below if it's too small */
|
|
|
|
KeyInfoSize = FIELD_OFFSET(KEY_BASIC_INFORMATION, Name) + 64 * sizeof(WCHAR);
|
2019-04-20 16:48:43 +08:00
|
|
|
KeyInfo = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
KeyInfoSize + sizeof(UNICODE_NULL),
|
|
|
|
TAG_PNP_ROOT);
|
2007-12-03 16:25:54 +08:00
|
|
|
if (!KeyInfo)
|
2003-09-26 02:29:45 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
DPRINT("ExAllocatePoolWithTag() failed\n");
|
|
|
|
Status = STATUS_NO_MEMORY;
|
|
|
|
goto cleanup;
|
2003-09-26 02:29:45 +08:00
|
|
|
}
|
2019-04-20 16:48:43 +08:00
|
|
|
SubKeyInfoSize = KeyInfoSize;
|
|
|
|
SubKeyInfo = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
SubKeyInfoSize + sizeof(UNICODE_NULL),
|
|
|
|
TAG_PNP_ROOT);
|
2007-12-03 16:25:54 +08:00
|
|
|
if (!SubKeyInfo)
|
2007-06-04 17:15:04 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
DPRINT("ExAllocatePoolWithTag() failed\n");
|
|
|
|
Status = STATUS_NO_MEMORY;
|
|
|
|
goto cleanup;
|
2007-06-04 17:15:04 +08:00
|
|
|
}
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2008-01-02 21:33:40 +08:00
|
|
|
Status = IopOpenRegistryKeyEx(&KeyHandle, NULL, &KeyName, KEY_ENUMERATE_SUB_KEYS);
|
2005-05-30 03:48:43 +08:00
|
|
|
if (!NT_SUCCESS(Status))
|
2003-09-26 02:29:45 +08:00
|
|
|
{
|
2008-01-02 21:33:40 +08:00
|
|
|
DPRINT("IopOpenRegistryKeyEx(%wZ) failed with status 0x%08lx\n", &KeyName, Status);
|
2007-12-03 16:25:54 +08:00
|
|
|
goto cleanup;
|
2003-09-26 02:29:45 +08:00
|
|
|
}
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
/* Devices are sub-sub-keys of 'KeyName'. KeyName is already opened as
|
|
|
|
* KeyHandle. We'll first do a first enumeration to have first level keys,
|
|
|
|
* and an inner one to have the real devices list.
|
|
|
|
*/
|
|
|
|
Index1 = 0;
|
2005-05-30 03:48:43 +08:00
|
|
|
while (TRUE)
|
2003-09-26 02:29:45 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
Status = ZwEnumerateKey(
|
|
|
|
KeyHandle,
|
|
|
|
Index1,
|
|
|
|
KeyBasicInformation,
|
|
|
|
KeyInfo,
|
2019-04-20 16:48:43 +08:00
|
|
|
KeyInfoSize,
|
2007-12-03 16:25:54 +08:00
|
|
|
&ResultSize);
|
|
|
|
if (Status == STATUS_NO_MORE_ENTRIES)
|
2007-06-04 17:15:04 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
break;
|
2007-06-04 17:15:04 +08:00
|
|
|
}
|
2019-04-20 16:48:43 +08:00
|
|
|
else if (Status == STATUS_BUFFER_OVERFLOW ||
|
|
|
|
Status == STATUS_BUFFER_TOO_SMALL)
|
|
|
|
{
|
|
|
|
ASSERT(KeyInfoSize < ResultSize);
|
|
|
|
KeyInfoSize = ResultSize;
|
|
|
|
ExFreePoolWithTag(KeyInfo, TAG_PNP_ROOT);
|
|
|
|
KeyInfo = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
KeyInfoSize + sizeof(UNICODE_NULL),
|
|
|
|
TAG_PNP_ROOT);
|
|
|
|
if (!KeyInfo)
|
|
|
|
{
|
|
|
|
DPRINT1("ExAllocatePoolWithTag(%lu) failed\n", KeyInfoSize);
|
|
|
|
Status = STATUS_NO_MEMORY;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2007-12-03 16:25:54 +08:00
|
|
|
else if (!NT_SUCCESS(Status))
|
2007-06-04 17:15:04 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
DPRINT("ZwEnumerateKey() failed with status 0x%08lx\n", Status);
|
|
|
|
goto cleanup;
|
2007-06-04 17:15:04 +08:00
|
|
|
}
|
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
/* Terminate the string */
|
|
|
|
KeyInfo->Name[KeyInfo->NameLength / sizeof(WCHAR)] = 0;
|
|
|
|
|
|
|
|
/* Check if it is a legacy driver */
|
|
|
|
RtlInitUnicodeString(&SubKeyName, KeyInfo->Name);
|
|
|
|
if (RtlPrefixUnicodeString(&LegacyU, &SubKeyName, FALSE))
|
2007-06-04 17:15:04 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
DPRINT("Ignoring legacy driver '%wZ'\n", &SubKeyName);
|
|
|
|
Index1++;
|
|
|
|
continue;
|
2007-06-04 17:15:04 +08:00
|
|
|
}
|
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
/* Open the key */
|
2008-01-02 21:33:40 +08:00
|
|
|
Status = IopOpenRegistryKeyEx(&SubKeyHandle, KeyHandle, &SubKeyName, KEY_ENUMERATE_SUB_KEYS);
|
2007-06-04 17:15:04 +08:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2017-04-08 17:26:42 +08:00
|
|
|
DPRINT("IopOpenRegistryKeyEx() failed for '%wZ' with status 0x%lx\n",
|
|
|
|
&SubKeyName, Status);
|
2007-12-03 16:25:54 +08:00
|
|
|
break;
|
2007-06-04 17:15:04 +08:00
|
|
|
}
|
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
/* Enumerate the sub-keys */
|
|
|
|
Index2 = 0;
|
|
|
|
while (TRUE)
|
2007-06-04 17:15:04 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
Status = ZwEnumerateKey(
|
|
|
|
SubKeyHandle,
|
|
|
|
Index2,
|
|
|
|
KeyBasicInformation,
|
|
|
|
SubKeyInfo,
|
2019-04-20 16:48:43 +08:00
|
|
|
SubKeyInfoSize,
|
2007-12-03 16:25:54 +08:00
|
|
|
&ResultSize);
|
|
|
|
if (Status == STATUS_NO_MORE_ENTRIES)
|
2019-04-20 16:48:43 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
break;
|
2019-04-20 16:48:43 +08:00
|
|
|
}
|
|
|
|
else if (Status == STATUS_BUFFER_OVERFLOW ||
|
|
|
|
Status == STATUS_BUFFER_TOO_SMALL)
|
|
|
|
{
|
|
|
|
ASSERT(SubKeyInfoSize < ResultSize);
|
|
|
|
SubKeyInfoSize = ResultSize;
|
|
|
|
ExFreePoolWithTag(SubKeyInfo, TAG_PNP_ROOT);
|
|
|
|
SubKeyInfo = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
SubKeyInfoSize + sizeof(UNICODE_NULL),
|
|
|
|
TAG_PNP_ROOT);
|
|
|
|
if (!SubKeyInfo)
|
|
|
|
{
|
|
|
|
DPRINT1("ExAllocatePoolWithTag(%lu) failed\n", SubKeyInfoSize);
|
|
|
|
Status = STATUS_NO_MEMORY;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2007-12-03 16:25:54 +08:00
|
|
|
else if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT("ZwEnumerateKey() failed with status 0x%08lx\n", Status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Terminate the string */
|
|
|
|
SubKeyInfo->Name[SubKeyInfo->NameLength / sizeof(WCHAR)] = 0;
|
|
|
|
|
2020-05-02 23:33:24 +08:00
|
|
|
/* Compute device ID */
|
|
|
|
DevicePath.Length = 0;
|
|
|
|
DevicePath.MaximumLength = sizeof(REGSTR_KEY_ROOTENUM) + sizeof(L'\\') + SubKeyName.Length;
|
|
|
|
DevicePath.Buffer = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
DevicePath.MaximumLength,
|
|
|
|
TAG_PNP_ROOT);
|
|
|
|
if (DevicePath.Buffer == NULL)
|
|
|
|
{
|
|
|
|
DPRINT1("ExAllocatePoolWithTag() failed\n");
|
|
|
|
Status = STATUS_NO_MEMORY;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2021-06-11 20:29:21 +08:00
|
|
|
|
2020-05-02 23:33:24 +08:00
|
|
|
RtlAppendUnicodeToString(&DevicePath, REGSTR_KEY_ROOTENUM L"\\");
|
|
|
|
RtlAppendUnicodeStringToString(&DevicePath, &SubKeyName);
|
|
|
|
DPRINT("Found device %wZ\\%S!\n", &DevicePath, SubKeyInfo->Name);
|
|
|
|
|
2021-12-14 06:27:01 +08:00
|
|
|
Status = IopShouldProcessDevice(SubKeyHandle, SubKeyInfo->Name);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
Status = CreateDeviceFromRegistry(DeviceExtension,
|
|
|
|
&DevicePath,
|
|
|
|
SubKeyInfo->Name,
|
|
|
|
SubKeyHandle);
|
|
|
|
|
|
|
|
/* If CreateDeviceFromRegistry didn't take ownership and zero this,
|
|
|
|
* we need to free it
|
|
|
|
*/
|
|
|
|
RtlFreeUnicodeString(&DevicePath);
|
2020-05-02 23:33:24 +08:00
|
|
|
|
2021-12-14 06:27:01 +08:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (Status == STATUS_NO_SUCH_DEVICE)
|
|
|
|
{
|
|
|
|
DPRINT("Skipping device %wZ\\%S (not reported yet)\n", &DevicePath, SubKeyInfo->Name);
|
|
|
|
}
|
|
|
|
else
|
2007-12-03 16:25:54 +08:00
|
|
|
{
|
2020-05-02 23:08:12 +08:00
|
|
|
goto cleanup;
|
2007-12-03 16:25:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Index2++;
|
2007-06-04 17:15:04 +08:00
|
|
|
}
|
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
ZwClose(SubKeyHandle);
|
2016-03-31 15:51:08 +08:00
|
|
|
SubKeyHandle = NULL;
|
2007-12-03 16:25:54 +08:00
|
|
|
Index1++;
|
2005-05-30 03:48:43 +08:00
|
|
|
}
|
2007-06-04 17:15:04 +08:00
|
|
|
|
|
|
|
cleanup:
|
2016-03-31 15:51:08 +08:00
|
|
|
if (SubKeyHandle != NULL)
|
2007-12-03 16:25:54 +08:00
|
|
|
ZwClose(SubKeyHandle);
|
2016-03-31 15:51:08 +08:00
|
|
|
if (KeyHandle != NULL)
|
2007-12-03 16:25:54 +08:00
|
|
|
ZwClose(KeyHandle);
|
2008-11-27 02:56:41 +08:00
|
|
|
if (KeyInfo)
|
|
|
|
ExFreePoolWithTag(KeyInfo, TAG_PNP_ROOT);
|
|
|
|
if (SubKeyInfo)
|
|
|
|
ExFreePoolWithTag(SubKeyInfo, TAG_PNP_ROOT);
|
2007-12-03 16:25:54 +08:00
|
|
|
KeReleaseGuardedMutex(&DeviceExtension->DeviceListLock);
|
|
|
|
return Status;
|
2003-09-26 02:29:45 +08:00
|
|
|
}
|
|
|
|
|
2007-06-04 17:15:04 +08:00
|
|
|
/* FUNCTION: Handle IRP_MN_QUERY_DEVICE_RELATIONS IRPs for the root bus device object
|
|
|
|
* ARGUMENTS:
|
|
|
|
* DeviceObject = Pointer to functional device object of the root bus driver
|
|
|
|
* Irp = Pointer to IRP that should be handled
|
|
|
|
* RETURNS:
|
|
|
|
* Status
|
|
|
|
*/
|
|
|
|
static NTSTATUS
|
|
|
|
PnpRootQueryDeviceRelations(
|
2007-12-03 16:25:54 +08:00
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
2003-09-26 02:29:45 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
PPNPROOT_PDO_DEVICE_EXTENSION PdoDeviceExtension;
|
|
|
|
PPNPROOT_FDO_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
PDEVICE_RELATIONS Relations = NULL, OtherRelations = (PDEVICE_RELATIONS)Irp->IoStatus.Information;
|
|
|
|
PPNPROOT_DEVICE Device = NULL;
|
|
|
|
ULONG Size;
|
|
|
|
NTSTATUS Status;
|
2008-08-26 02:21:19 +08:00
|
|
|
PLIST_ENTRY NextEntry;
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
DPRINT("PnpRootQueryDeviceRelations(FDO %p, Irp %p)\n", DeviceObject, Irp);
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
Status = EnumerateDevices(DeviceObject);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT("EnumerateDevices() failed with status 0x%08lx\n", Status);
|
|
|
|
return Status;
|
|
|
|
}
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
DeviceExtension = (PPNPROOT_FDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
Size = FIELD_OFFSET(DEVICE_RELATIONS, Objects) + sizeof(PDEVICE_OBJECT) * DeviceExtension->DeviceListCount;
|
|
|
|
if (OtherRelations)
|
2003-09-26 02:29:45 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
/* Another bus driver has already created a DEVICE_RELATIONS
|
|
|
|
* structure so we must merge this structure with our own */
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
Size += sizeof(PDEVICE_OBJECT) * OtherRelations->Count;
|
|
|
|
}
|
|
|
|
Relations = (PDEVICE_RELATIONS)ExAllocatePool(PagedPool, Size);
|
|
|
|
if (!Relations)
|
|
|
|
{
|
|
|
|
DPRINT("ExAllocatePoolWithTag() failed\n");
|
|
|
|
Status = STATUS_NO_MEMORY;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
RtlZeroMemory(Relations, Size);
|
|
|
|
if (OtherRelations)
|
|
|
|
{
|
|
|
|
Relations->Count = OtherRelations->Count;
|
|
|
|
RtlCopyMemory(Relations->Objects, OtherRelations->Objects, sizeof(PDEVICE_OBJECT) * OtherRelations->Count);
|
2003-09-26 02:29:45 +08:00
|
|
|
}
|
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
KeAcquireGuardedMutex(&DeviceExtension->DeviceListLock);
|
2008-08-26 02:21:19 +08:00
|
|
|
|
|
|
|
/* Start looping */
|
|
|
|
for (NextEntry = DeviceExtension->DeviceListHead.Flink;
|
|
|
|
NextEntry != &DeviceExtension->DeviceListHead;
|
|
|
|
NextEntry = NextEntry->Flink)
|
2007-12-03 16:25:54 +08:00
|
|
|
{
|
2008-08-26 02:21:19 +08:00
|
|
|
/* Get the entry */
|
|
|
|
Device = CONTAINING_RECORD(NextEntry, PNPROOT_DEVICE, ListEntry);
|
[HAL/NDK]
- Make Vector parameter in HalEnableSystemInterrupt, HalDisableSystemInterrupt and HalBeginSystemInterrupt an ULONG, not an UCHAR
[NDK]
- 64bit fixes for HANDLE_TABLE, KPROCESS, SECTION_IMAGE_INFORMATION, MMADDRESS_LIST, MMVAD_FLAGS, MMVAD, MMVAD_LONG, MMVAD_SHORT, MEMORY_DESCRIPTOR, MEMORY_ALLOCATION_DESCRIPTOR, LdrVerifyMappedImageMatchesChecksum
- KDPC_DATA::DpcQueueDepth is signed on amd64, unsigned on x86
[NTOSKRNL]
- Fix hundreds of MSVC and amd64 warnings
- add a pragma message to FstubFixupEfiPartition, since it looks broken
- Move portable Ke constants from <arch>/cpu.c to krnlinit.c
- Fixed a bug in amd64 KiGeneralProtectionFaultHandler
svn path=/trunk/; revision=53734
2011-09-18 21:11:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
if (!Device->Pdo)
|
|
|
|
{
|
|
|
|
/* Create a physical device object for the
|
|
|
|
* device as it does not already have one */
|
|
|
|
Status = IoCreateDevice(
|
|
|
|
DeviceObject->DriverObject,
|
|
|
|
sizeof(PNPROOT_PDO_DEVICE_EXTENSION),
|
|
|
|
NULL,
|
|
|
|
FILE_DEVICE_CONTROLLER,
|
|
|
|
FILE_AUTOGENERATED_DEVICE_NAME,
|
|
|
|
FALSE,
|
|
|
|
&Device->Pdo);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT("IoCreateDevice() failed with status 0x%08lx\n", Status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
PdoDeviceExtension = (PPNPROOT_PDO_DEVICE_EXTENSION)Device->Pdo->DeviceExtension;
|
|
|
|
RtlZeroMemory(PdoDeviceExtension, sizeof(PNPROOT_PDO_DEVICE_EXTENSION));
|
|
|
|
PdoDeviceExtension->Common.IsFDO = FALSE;
|
|
|
|
PdoDeviceExtension->DeviceInfo = Device;
|
|
|
|
|
|
|
|
Device->Pdo->Flags |= DO_BUS_ENUMERATED_DEVICE;
|
|
|
|
Device->Pdo->Flags &= ~DO_DEVICE_INITIALIZING;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reference the physical device object. The PnP manager
|
|
|
|
will dereference it again when it is no longer needed */
|
|
|
|
ObReferenceObject(Device->Pdo);
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
Relations->Objects[Relations->Count++] = Device->Pdo;
|
|
|
|
}
|
|
|
|
KeReleaseGuardedMutex(&DeviceExtension->DeviceListLock);
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)Relations;
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-06-04 17:15:04 +08:00
|
|
|
cleanup:
|
2007-12-03 16:25:54 +08:00
|
|
|
if (!NT_SUCCESS(Status))
|
2007-06-04 17:15:04 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
if (OtherRelations)
|
|
|
|
ExFreePool(OtherRelations);
|
|
|
|
if (Relations)
|
|
|
|
ExFreePool(Relations);
|
|
|
|
if (Device && Device->Pdo)
|
|
|
|
{
|
|
|
|
IoDeleteDevice(Device->Pdo);
|
|
|
|
Device->Pdo = NULL;
|
|
|
|
}
|
2007-06-04 17:15:04 +08:00
|
|
|
}
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
return Status;
|
2003-09-26 02:29:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: Handle Plug and Play IRPs for the root bus device object
|
|
|
|
* ARGUMENTS:
|
|
|
|
* DeviceObject = Pointer to functional device object of the root bus driver
|
|
|
|
* Irp = Pointer to IRP that should be handled
|
|
|
|
* RETURNS:
|
|
|
|
* Status
|
|
|
|
*/
|
2007-06-04 17:15:04 +08:00
|
|
|
static NTSTATUS
|
2005-02-07 18:33:44 +08:00
|
|
|
PnpRootFdoPnpControl(
|
2007-12-03 16:25:54 +08:00
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
2003-09-26 02:29:45 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
PPNPROOT_FDO_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
PIO_STACK_LOCATION IrpSp;
|
|
|
|
NTSTATUS Status;
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
DeviceExtension = (PPNPROOT_FDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
|
|
|
Status = Irp->IoStatus.Status;
|
|
|
|
IrpSp = IoGetCurrentIrpStackLocation(Irp);
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
switch (IrpSp->MinorFunction)
|
|
|
|
{
|
|
|
|
case IRP_MN_QUERY_DEVICE_RELATIONS:
|
|
|
|
DPRINT("IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS\n");
|
|
|
|
Status = PnpRootQueryDeviceRelations(DeviceObject, Irp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_START_DEVICE:
|
|
|
|
DPRINT("IRP_MJ_PNP / IRP_MN_START_DEVICE\n");
|
2007-12-03 17:03:38 +08:00
|
|
|
if (!IoForwardIrpSynchronously(DeviceExtension->Ldo, Irp))
|
|
|
|
Status = STATUS_UNSUCCESSFUL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Status = Irp->IoStatus.Status;
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
DeviceExtension->State = dsStarted;
|
|
|
|
}
|
2010-04-04 08:33:19 +08:00
|
|
|
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return Status;
|
2007-12-03 16:25:54 +08:00
|
|
|
|
|
|
|
case IRP_MN_STOP_DEVICE:
|
|
|
|
DPRINT("IRP_MJ_PNP / IRP_MN_STOP_DEVICE\n");
|
|
|
|
/* Root device cannot be stopped */
|
2010-04-04 08:33:19 +08:00
|
|
|
Irp->IoStatus.Status = Status = STATUS_INVALID_DEVICE_REQUEST;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return Status;
|
2007-12-03 16:25:54 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
DPRINT("IRP_MJ_PNP / Unknown minor function 0x%lx\n", IrpSp->MinorFunction);
|
|
|
|
break;
|
|
|
|
}
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2010-04-04 09:18:41 +08:00
|
|
|
if (Status != STATUS_PENDING)
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
2003-09-26 02:29:45 +08:00
|
|
|
}
|
|
|
|
|
2007-06-04 17:15:04 +08:00
|
|
|
static NTSTATUS
|
|
|
|
PdoQueryDeviceRelations(
|
2007-12-03 16:25:54 +08:00
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp,
|
|
|
|
IN PIO_STACK_LOCATION IrpSp)
|
2007-06-04 17:15:04 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
PDEVICE_RELATIONS Relations;
|
|
|
|
NTSTATUS Status = Irp->IoStatus.Status;
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2010-04-04 08:33:19 +08:00
|
|
|
if (IrpSp->Parameters.QueryDeviceRelations.Type != TargetDeviceRelation)
|
|
|
|
return Status;
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2010-04-04 08:33:19 +08:00
|
|
|
DPRINT("IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / TargetDeviceRelation\n");
|
|
|
|
Relations = (PDEVICE_RELATIONS)ExAllocatePool(PagedPool, sizeof(DEVICE_RELATIONS));
|
|
|
|
if (!Relations)
|
2007-12-03 16:25:54 +08:00
|
|
|
{
|
2010-04-04 08:33:19 +08:00
|
|
|
DPRINT("ExAllocatePoolWithTag() failed\n");
|
|
|
|
Status = STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ObReferenceObject(DeviceObject);
|
|
|
|
Relations->Count = 1;
|
|
|
|
Relations->Objects[0] = DeviceObject;
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)Relations;
|
2007-12-03 16:25:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
2007-06-04 17:15:04 +08:00
|
|
|
}
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-06-04 17:15:04 +08:00
|
|
|
static NTSTATUS
|
|
|
|
PdoQueryCapabilities(
|
2007-12-03 16:25:54 +08:00
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp,
|
|
|
|
IN PIO_STACK_LOCATION IrpSp)
|
2003-09-26 02:29:45 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
PDEVICE_CAPABILITIES DeviceCapabilities;
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
DeviceCapabilities = IrpSp->Parameters.DeviceCapabilities.Capabilities;
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
if (DeviceCapabilities->Version != 1)
|
|
|
|
return STATUS_REVISION_MISMATCH;
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
DeviceCapabilities->UniqueID = TRUE;
|
|
|
|
/* FIXME: Fill other fields */
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
return STATUS_SUCCESS;
|
2007-06-04 17:15:04 +08:00
|
|
|
}
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-06-04 17:15:04 +08:00
|
|
|
static NTSTATUS
|
|
|
|
PdoQueryResources(
|
2007-12-03 16:25:54 +08:00
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp,
|
|
|
|
IN PIO_STACK_LOCATION IrpSp)
|
2007-06-04 17:15:04 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
PPNPROOT_PDO_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
PCM_RESOURCE_LIST ResourceList;
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
DeviceExtension = (PPNPROOT_PDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2010-04-04 10:59:31 +08:00
|
|
|
if (DeviceExtension->DeviceInfo->ResourceList)
|
2007-12-03 16:25:54 +08:00
|
|
|
{
|
|
|
|
/* Copy existing resource requirement list */
|
|
|
|
ResourceList = ExAllocatePool(
|
|
|
|
PagedPool,
|
2010-04-04 09:18:41 +08:00
|
|
|
DeviceExtension->DeviceInfo->ResourceListSize);
|
2007-12-03 16:25:54 +08:00
|
|
|
if (!ResourceList)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
RtlCopyMemory(
|
2010-04-04 09:18:41 +08:00
|
|
|
ResourceList,
|
2007-12-03 16:25:54 +08:00
|
|
|
DeviceExtension->DeviceInfo->ResourceList,
|
|
|
|
DeviceExtension->DeviceInfo->ResourceListSize);
|
2010-04-04 09:18:41 +08:00
|
|
|
|
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)ResourceList;
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2010-04-04 10:59:31 +08:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* No resources so just return without changing the status */
|
|
|
|
return Irp->IoStatus.Status;
|
|
|
|
}
|
2007-06-04 17:15:04 +08:00
|
|
|
}
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-06-04 17:15:04 +08:00
|
|
|
static NTSTATUS
|
|
|
|
PdoQueryResourceRequirements(
|
2007-12-03 16:25:54 +08:00
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp,
|
|
|
|
IN PIO_STACK_LOCATION IrpSp)
|
2007-06-04 17:15:04 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
PPNPROOT_PDO_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
PIO_RESOURCE_REQUIREMENTS_LIST ResourceList;
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
DeviceExtension = (PPNPROOT_PDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2010-04-04 10:59:31 +08:00
|
|
|
if (DeviceExtension->DeviceInfo->ResourceRequirementsList)
|
2007-12-03 16:25:54 +08:00
|
|
|
{
|
|
|
|
/* Copy existing resource requirement list */
|
|
|
|
ResourceList = ExAllocatePool(PagedPool, DeviceExtension->DeviceInfo->ResourceRequirementsList->ListSize);
|
|
|
|
if (!ResourceList)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
RtlCopyMemory(
|
|
|
|
ResourceList,
|
|
|
|
DeviceExtension->DeviceInfo->ResourceRequirementsList,
|
|
|
|
DeviceExtension->DeviceInfo->ResourceRequirementsList->ListSize);
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2010-04-04 10:59:31 +08:00
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)ResourceList;
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* No resource requirements so just return without changing the status */
|
|
|
|
return Irp->IoStatus.Status;
|
|
|
|
}
|
2003-09-26 02:29:45 +08:00
|
|
|
}
|
|
|
|
|
2007-06-04 17:15:04 +08:00
|
|
|
static NTSTATUS
|
|
|
|
PdoQueryDeviceText(
|
2007-12-03 16:25:54 +08:00
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp,
|
|
|
|
IN PIO_STACK_LOCATION IrpSp)
|
2007-06-04 17:15:04 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
PPNPROOT_PDO_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
DEVICE_TEXT_TYPE DeviceTextType;
|
|
|
|
NTSTATUS Status = Irp->IoStatus.Status;
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
DeviceExtension = (PPNPROOT_PDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
|
|
|
DeviceTextType = IrpSp->Parameters.QueryDeviceText.DeviceTextType;
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
switch (DeviceTextType)
|
|
|
|
{
|
|
|
|
case DeviceTextDescription:
|
|
|
|
{
|
|
|
|
UNICODE_STRING String;
|
|
|
|
DPRINT("IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_TEXT / DeviceTextDescription\n");
|
|
|
|
|
2011-08-21 08:27:58 +08:00
|
|
|
if (DeviceExtension->DeviceInfo->DeviceDescription.Buffer != NULL)
|
|
|
|
{
|
|
|
|
Status = RtlDuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE,
|
|
|
|
&DeviceExtension->DeviceInfo->DeviceDescription,
|
|
|
|
&String);
|
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)String.Buffer;
|
|
|
|
}
|
2007-12-03 16:25:54 +08:00
|
|
|
break;
|
|
|
|
}
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
case DeviceTextLocationInformation:
|
|
|
|
{
|
|
|
|
DPRINT("IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_TEXT / DeviceTextLocationInformation\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
DPRINT1("IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_TEXT / unknown query id type 0x%lx\n", DeviceTextType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
2007-06-04 17:15:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS
|
|
|
|
PdoQueryId(
|
2007-12-03 16:25:54 +08:00
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp,
|
|
|
|
IN PIO_STACK_LOCATION IrpSp)
|
2007-06-04 17:15:04 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
PPNPROOT_PDO_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
BUS_QUERY_ID_TYPE IdType;
|
|
|
|
NTSTATUS Status = Irp->IoStatus.Status;
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
DeviceExtension = (PPNPROOT_PDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
|
|
|
IdType = IrpSp->Parameters.QueryId.IdType;
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
switch (IdType)
|
|
|
|
{
|
|
|
|
case BusQueryDeviceID:
|
|
|
|
{
|
|
|
|
UNICODE_STRING String;
|
|
|
|
DPRINT("IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryDeviceID\n");
|
|
|
|
|
|
|
|
Status = RtlDuplicateUnicodeString(
|
|
|
|
RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE,
|
|
|
|
&DeviceExtension->DeviceInfo->DeviceID,
|
|
|
|
&String);
|
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)String.Buffer;
|
|
|
|
break;
|
|
|
|
}
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
case BusQueryHardwareIDs:
|
|
|
|
case BusQueryCompatibleIDs:
|
|
|
|
{
|
|
|
|
/* Optional, do nothing */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BusQueryInstanceID:
|
|
|
|
{
|
|
|
|
UNICODE_STRING String;
|
|
|
|
DPRINT("IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryInstanceID\n");
|
|
|
|
|
|
|
|
Status = RtlDuplicateUnicodeString(
|
|
|
|
RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE,
|
|
|
|
&DeviceExtension->DeviceInfo->InstanceID,
|
|
|
|
&String);
|
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)String.Buffer;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
DPRINT1("IRP_MJ_PNP / IRP_MN_QUERY_ID / unknown query id type 0x%lx\n", IdType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
2007-06-04 17:15:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS
|
|
|
|
PdoQueryBusInformation(
|
2007-12-03 16:25:54 +08:00
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp,
|
|
|
|
IN PIO_STACK_LOCATION IrpSp)
|
2007-06-04 17:15:04 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
PPNP_BUS_INFORMATION BusInfo;
|
|
|
|
NTSTATUS Status;
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
BusInfo = (PPNP_BUS_INFORMATION)ExAllocatePoolWithTag(PagedPool, sizeof(PNP_BUS_INFORMATION), TAG_PNP_ROOT);
|
|
|
|
if (!BusInfo)
|
|
|
|
Status = STATUS_NO_MEMORY;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RtlCopyMemory(
|
|
|
|
&BusInfo->BusTypeGuid,
|
|
|
|
&GUID_BUS_TYPE_INTERNAL,
|
|
|
|
sizeof(BusInfo->BusTypeGuid));
|
|
|
|
BusInfo->LegacyBusType = PNPBus;
|
|
|
|
/* We're the only root bus enumerator on the computer */
|
|
|
|
BusInfo->BusNumber = 0;
|
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)BusInfo;
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
}
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
return Status;
|
2007-06-04 17:15:04 +08:00
|
|
|
}
|
2003-09-26 02:29:45 +08:00
|
|
|
|
|
|
|
/*
|
2007-06-04 17:15:04 +08:00
|
|
|
* FUNCTION: Handle Plug and Play IRPs for the child device
|
2003-09-26 02:29:45 +08:00
|
|
|
* ARGUMENTS:
|
2007-06-04 17:15:04 +08:00
|
|
|
* DeviceObject = Pointer to physical device object of the child device
|
2003-09-26 02:29:45 +08:00
|
|
|
* Irp = Pointer to IRP that should be handled
|
|
|
|
* RETURNS:
|
|
|
|
* Status
|
|
|
|
*/
|
2007-06-04 17:15:04 +08:00
|
|
|
static NTSTATUS
|
|
|
|
PnpRootPdoPnpControl(
|
2005-02-07 18:33:44 +08:00
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
2003-09-26 02:29:45 +08:00
|
|
|
{
|
2016-03-31 15:54:52 +08:00
|
|
|
PPNPROOT_PDO_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
PPNPROOT_FDO_DEVICE_EXTENSION FdoDeviceExtension;
|
|
|
|
PIO_STACK_LOCATION IrpSp;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
DeviceExtension = DeviceObject->DeviceExtension;
|
|
|
|
FdoDeviceExtension = PnpRootDeviceObject->DeviceExtension;
|
|
|
|
Status = Irp->IoStatus.Status;
|
|
|
|
IrpSp = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
|
|
|
|
switch (IrpSp->MinorFunction)
|
|
|
|
{
|
|
|
|
case IRP_MN_START_DEVICE: /* 0x00 */
|
|
|
|
DPRINT("IRP_MJ_PNP / IRP_MN_START_DEVICE\n");
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_QUERY_DEVICE_RELATIONS: /* 0x07 */
|
|
|
|
Status = PdoQueryDeviceRelations(DeviceObject, Irp, IrpSp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_QUERY_CAPABILITIES: /* 0x09 */
|
|
|
|
DPRINT("IRP_MJ_PNP / IRP_MN_QUERY_CAPABILITIES\n");
|
|
|
|
Status = PdoQueryCapabilities(DeviceObject, Irp, IrpSp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_QUERY_RESOURCES: /* 0x0a */
|
|
|
|
DPRINT("IRP_MJ_PNP / IRP_MN_QUERY_RESOURCES\n");
|
|
|
|
Status = PdoQueryResources(DeviceObject, Irp, IrpSp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_QUERY_RESOURCE_REQUIREMENTS: /* 0x0b */
|
|
|
|
DPRINT("IRP_MJ_PNP / IRP_MN_QUERY_RESOURCE_REQUIREMENTS\n");
|
|
|
|
Status = PdoQueryResourceRequirements(DeviceObject, Irp, IrpSp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_QUERY_DEVICE_TEXT: /* 0x0c */
|
|
|
|
DPRINT("IRP_MJ_PNP / IRP_MN_QUERY_RESOURCE_REQUIREMENTS\n");
|
|
|
|
Status = PdoQueryDeviceText(DeviceObject, Irp, IrpSp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_FILTER_RESOURCE_REQUIREMENTS: /* 0x0d */
|
|
|
|
DPRINT("IRP_MJ_PNP / IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_REMOVE_DEVICE:
|
|
|
|
/* Remove the device from the device list and decrement the device count*/
|
|
|
|
KeAcquireGuardedMutex(&FdoDeviceExtension->DeviceListLock);
|
|
|
|
RemoveEntryList(&DeviceExtension->DeviceInfo->ListEntry);
|
|
|
|
FdoDeviceExtension->DeviceListCount--;
|
|
|
|
KeReleaseGuardedMutex(&FdoDeviceExtension->DeviceListLock);
|
|
|
|
|
|
|
|
/* Free some strings we created */
|
|
|
|
RtlFreeUnicodeString(&DeviceExtension->DeviceInfo->DeviceDescription);
|
|
|
|
RtlFreeUnicodeString(&DeviceExtension->DeviceInfo->DeviceID);
|
|
|
|
RtlFreeUnicodeString(&DeviceExtension->DeviceInfo->InstanceID);
|
|
|
|
|
|
|
|
/* Free the resource requirements list */
|
|
|
|
if (DeviceExtension->DeviceInfo->ResourceRequirementsList != NULL)
|
2010-06-10 04:04:39 +08:00
|
|
|
ExFreePool(DeviceExtension->DeviceInfo->ResourceRequirementsList);
|
|
|
|
|
2016-03-31 15:54:52 +08:00
|
|
|
/* Free the boot resources list */
|
|
|
|
if (DeviceExtension->DeviceInfo->ResourceList != NULL)
|
2010-06-10 04:04:39 +08:00
|
|
|
ExFreePool(DeviceExtension->DeviceInfo->ResourceList);
|
|
|
|
|
2016-03-31 15:54:52 +08:00
|
|
|
/* Free the device info */
|
|
|
|
ExFreePool(DeviceExtension->DeviceInfo);
|
2010-06-10 04:04:39 +08:00
|
|
|
|
2016-03-31 15:54:52 +08:00
|
|
|
/* Finally, delete the device object */
|
|
|
|
IoDeleteDevice(DeviceObject);
|
2010-06-10 04:04:39 +08:00
|
|
|
|
2016-03-31 15:54:52 +08:00
|
|
|
/* Return success */
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
break;
|
2010-04-23 05:07:46 +08:00
|
|
|
|
2016-03-31 15:54:52 +08:00
|
|
|
case IRP_MN_QUERY_ID: /* 0x13 */
|
|
|
|
Status = PdoQueryId(DeviceObject, Irp, IrpSp);
|
|
|
|
break;
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2017-04-02 22:24:11 +08:00
|
|
|
case IRP_MN_QUERY_PNP_DEVICE_STATE: /* 0x14 */
|
|
|
|
DPRINT("IRP_MJ_PNP / IRP_MN_QUERY_PNP_DEVICE_STATE\n");
|
|
|
|
break;
|
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
case IRP_MN_QUERY_BUS_INFORMATION: /* 0x15 */
|
|
|
|
DPRINT("IRP_MJ_PNP / IRP_MN_QUERY_BUS_INFORMATION\n");
|
|
|
|
Status = PdoQueryBusInformation(DeviceObject, Irp, IrpSp);
|
|
|
|
break;
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
default:
|
|
|
|
DPRINT1("IRP_MJ_PNP / Unknown minor function 0x%lx\n", IrpSp->MinorFunction);
|
|
|
|
break;
|
|
|
|
}
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
if (Status != STATUS_PENDING)
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
}
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
return Status;
|
2003-09-26 02:29:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-06-04 17:15:04 +08:00
|
|
|
* FUNCTION: Handle Plug and Play IRPs
|
2003-09-26 02:29:45 +08:00
|
|
|
* ARGUMENTS:
|
|
|
|
* DeviceObject = Pointer to PDO or FDO
|
|
|
|
* Irp = Pointer to IRP that should be handled
|
|
|
|
* RETURNS:
|
|
|
|
* Status
|
|
|
|
*/
|
2007-06-04 17:15:04 +08:00
|
|
|
static NTSTATUS NTAPI
|
|
|
|
PnpRootPnpControl(
|
2007-12-03 16:25:54 +08:00
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
2003-09-26 02:29:45 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
PPNPROOT_COMMON_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
NTSTATUS Status;
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
DeviceExtension = (PPNPROOT_COMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
if (DeviceExtension->IsFDO)
|
|
|
|
Status = PnpRootFdoPnpControl(DeviceObject, Irp);
|
|
|
|
else
|
|
|
|
Status = PnpRootPdoPnpControl(DeviceObject, Irp);
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
return Status;
|
2003-09-26 02:29:45 +08:00
|
|
|
}
|
|
|
|
|
2015-09-07 01:13:48 +08:00
|
|
|
/*
|
|
|
|
* FUNCTION: Handle Power IRPs
|
|
|
|
* ARGUMENTS:
|
|
|
|
* DeviceObject = Pointer to PDO or FDO
|
|
|
|
* Irp = Pointer to IRP that should be handled
|
|
|
|
* RETURNS:
|
|
|
|
* Status
|
|
|
|
*/
|
|
|
|
static NTSTATUS NTAPI
|
|
|
|
PnpRootPowerControl(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
|
|
|
PPNPROOT_FDO_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
PIO_STACK_LOCATION IrpSp;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
DeviceExtension = DeviceObject->DeviceExtension;
|
|
|
|
Status = Irp->IoStatus.Status;
|
|
|
|
IrpSp = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
|
|
|
|
if (DeviceExtension->Common.IsFDO)
|
|
|
|
{
|
|
|
|
ASSERT(!DeviceExtension->Common.IsFDO);
|
|
|
|
PoStartNextPowerIrp(Irp);
|
|
|
|
IoCopyCurrentIrpStackLocationToNext(Irp);
|
|
|
|
Status = PoCallDriver(DeviceExtension->Ldo, Irp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (IrpSp->MinorFunction)
|
|
|
|
{
|
|
|
|
case IRP_MN_QUERY_POWER:
|
|
|
|
case IRP_MN_SET_POWER:
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
PoStartNextPowerIrp(Irp);
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2003-09-26 02:29:45 +08:00
|
|
|
NTSTATUS
|
2008-08-18 21:35:52 +08:00
|
|
|
NTAPI
|
2003-09-26 02:29:45 +08:00
|
|
|
PnpRootAddDevice(
|
2007-12-03 16:25:54 +08:00
|
|
|
IN PDRIVER_OBJECT DriverObject,
|
|
|
|
IN PDEVICE_OBJECT PhysicalDeviceObject)
|
2003-09-26 02:29:45 +08:00
|
|
|
{
|
2007-12-03 16:25:54 +08:00
|
|
|
PPNPROOT_FDO_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
NTSTATUS Status;
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
DPRINT("PnpRootAddDevice(DriverObject %p, Pdo %p)\n", DriverObject, PhysicalDeviceObject);
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
if (!PhysicalDeviceObject)
|
|
|
|
{
|
|
|
|
DPRINT("PhysicalDeviceObject 0x%p\n", PhysicalDeviceObject);
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
2008-08-24 23:48:05 +08:00
|
|
|
KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0);
|
2007-12-03 16:25:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Status = IoCreateDevice(
|
|
|
|
DriverObject,
|
|
|
|
sizeof(PNPROOT_FDO_DEVICE_EXTENSION),
|
|
|
|
NULL,
|
|
|
|
FILE_DEVICE_BUS_EXTENDER,
|
|
|
|
FILE_DEVICE_SECURE_OPEN,
|
|
|
|
TRUE,
|
|
|
|
&PnpRootDeviceObject);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT("IoCreateDevice() failed with status 0x%08lx\n", Status);
|
2008-08-24 23:48:05 +08:00
|
|
|
KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0);
|
2007-12-03 16:25:54 +08:00
|
|
|
}
|
|
|
|
DPRINT("Created FDO %p\n", PnpRootDeviceObject);
|
|
|
|
|
|
|
|
DeviceExtension = (PPNPROOT_FDO_DEVICE_EXTENSION)PnpRootDeviceObject->DeviceExtension;
|
|
|
|
RtlZeroMemory(DeviceExtension, sizeof(PNPROOT_FDO_DEVICE_EXTENSION));
|
|
|
|
|
|
|
|
DeviceExtension->Common.IsFDO = TRUE;
|
|
|
|
DeviceExtension->State = dsStopped;
|
|
|
|
InitializeListHead(&DeviceExtension->DeviceListHead);
|
|
|
|
DeviceExtension->DeviceListCount = 0;
|
|
|
|
KeInitializeGuardedMutex(&DeviceExtension->DeviceListLock);
|
|
|
|
|
|
|
|
Status = IoAttachDeviceToDeviceStackSafe(
|
|
|
|
PnpRootDeviceObject,
|
|
|
|
PhysicalDeviceObject,
|
|
|
|
&DeviceExtension->Ldo);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT("IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n", Status);
|
2008-08-24 23:48:05 +08:00
|
|
|
KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0);
|
2007-12-03 16:25:54 +08:00
|
|
|
}
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
PnpRootDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
DPRINT("Done AddDevice()\n");
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
return STATUS_SUCCESS;
|
2003-09-26 02:29:45 +08:00
|
|
|
}
|
|
|
|
|
2017-06-19 03:48:45 +08:00
|
|
|
#if MI_TRACE_PFNS
|
|
|
|
PDEVICE_OBJECT IopPfnDumpDeviceObject;
|
|
|
|
|
|
|
|
NTSTATUS NTAPI
|
|
|
|
PnpRootCreateClose(
|
|
|
|
_In_ PDEVICE_OBJECT DeviceObject,
|
|
|
|
_In_ PIRP Irp)
|
|
|
|
{
|
|
|
|
PIO_STACK_LOCATION IoStack;
|
|
|
|
|
|
|
|
if (DeviceObject != IopPfnDumpDeviceObject)
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_INVALID_DEVICE_REQUEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
if (IoStack->MajorFunction == IRP_MJ_CREATE)
|
|
|
|
{
|
|
|
|
MmDumpArmPfnDatabase(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-06-04 17:15:04 +08:00
|
|
|
NTSTATUS NTAPI
|
2003-09-26 02:29:45 +08:00
|
|
|
PnpRootDriverEntry(
|
2007-12-03 16:25:54 +08:00
|
|
|
IN PDRIVER_OBJECT DriverObject,
|
|
|
|
IN PUNICODE_STRING RegistryPath)
|
2003-09-26 02:29:45 +08:00
|
|
|
{
|
2017-06-19 03:48:45 +08:00
|
|
|
#if MI_TRACE_PFNS
|
|
|
|
NTSTATUS Status;
|
|
|
|
UNICODE_STRING PfnDumpDeviceName = RTL_CONSTANT_STRING(L"\\Device\\PfnDump");
|
|
|
|
#endif
|
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
DPRINT("PnpRootDriverEntry(%p %wZ)\n", DriverObject, RegistryPath);
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2010-04-12 05:25:50 +08:00
|
|
|
IopRootDriverObject = DriverObject;
|
[HAL/NDK]
- Make Vector parameter in HalEnableSystemInterrupt, HalDisableSystemInterrupt and HalBeginSystemInterrupt an ULONG, not an UCHAR
[NDK]
- 64bit fixes for HANDLE_TABLE, KPROCESS, SECTION_IMAGE_INFORMATION, MMADDRESS_LIST, MMVAD_FLAGS, MMVAD, MMVAD_LONG, MMVAD_SHORT, MEMORY_DESCRIPTOR, MEMORY_ALLOCATION_DESCRIPTOR, LdrVerifyMappedImageMatchesChecksum
- KDPC_DATA::DpcQueueDepth is signed on amd64, unsigned on x86
[NTOSKRNL]
- Fix hundreds of MSVC and amd64 warnings
- add a pragma message to FstubFixupEfiPartition, since it looks broken
- Move portable Ke constants from <arch>/cpu.c to krnlinit.c
- Fixed a bug in amd64 KiGeneralProtectionFaultHandler
svn path=/trunk/; revision=53734
2011-09-18 21:11:45 +08:00
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
DriverObject->DriverExtension->AddDevice = PnpRootAddDevice;
|
2003-09-26 02:29:45 +08:00
|
|
|
|
2017-06-19 03:48:45 +08:00
|
|
|
#if MI_TRACE_PFNS
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_CREATE] = PnpRootCreateClose;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_CLOSE] = PnpRootCreateClose;
|
|
|
|
#endif
|
2007-12-03 16:25:54 +08:00
|
|
|
DriverObject->MajorFunction[IRP_MJ_PNP] = PnpRootPnpControl;
|
2015-09-07 01:13:48 +08:00
|
|
|
DriverObject->MajorFunction[IRP_MJ_POWER] = PnpRootPowerControl;
|
2007-06-04 17:15:04 +08:00
|
|
|
|
2017-06-19 03:48:45 +08:00
|
|
|
#if MI_TRACE_PFNS
|
|
|
|
Status = IoCreateDevice(DriverObject,
|
|
|
|
0,
|
|
|
|
&PfnDumpDeviceName,
|
|
|
|
FILE_DEVICE_UNKNOWN,
|
|
|
|
0,
|
|
|
|
FALSE,
|
|
|
|
&IopPfnDumpDeviceObject);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Creating PFN Dump device failed with %lx\n", Status);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IopPfnDumpDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-12-03 16:25:54 +08:00
|
|
|
return STATUS_SUCCESS;
|
2003-09-26 02:29:45 +08:00
|
|
|
}
|