以下内容全部来自《Windows驱动开发技术详解》,作者张帆、史彩成等,属摘抄型笔记。
///
上篇笔记中有提到过驱动对象和设备对象,当然他们在内核里形成设备栈,存在水平结构和垂直结构。这里利用之前DriverFrame的框架,在一个驱动对象下,创建两个设备对象,呈水平关系。
之后通过KdPrintf将设备对象编列并展示出来,代码如下:
VOID PrintDevice(IN PDRIVER_OBJECT pDriverObject)
{
int i = 1;
PDEVICE_OBJECT pDevice = pDriverObject->DeviceObject;
KdPrint(("----------------------------------------------\n"));
KdPrint(("Begin Dump...\n"));
KdPrint(("Driver Address:0x%08X\n", pDriverObject));
KdPrint(("Driver Name:%wZ\n", &pDriverObject->DriverName));
KdPrint(("Driver HardwareDatabase:%wZ\n", pDriverObject->HardwareDatabase));
KdPrint(("Driver first device:0x%08X\n", pDriverObject->DeviceObject));
for ( ; pDevice != NULL; pDevice = pDevice->NextDevice)
{
KdPrint(("The %d device\n", i++));
KdPrint(("Device AttachedDevice:0x%08X\n", pDevice->AttachedDevice));
KdPrint(("Device NextDevice:0x%08X\n", pDevice->NextDevice));
KdPrint(("Device StackSize:%d\n", pDevice->StackSize));
KdPrint(("Device's DriverObject:0x%08X\n", pDevice->DriverObject));
}
KdPrint(("Dump over!\n"));
KdPrint(("----------------------------------------------\n"));
}
通过DeviceTree也能查看到更清楚的结构。
后续随着学习的深入,再来补全笔记吧。