我声明了 2 个结构:
struct irp_list {
IRP *irp;
LIST_ENTRY lh;
};
和
struct dev_info {
...
LIST_ENTRY lh;
...
};
在 DriverWrite 函数 (IRP_MJ_WRITE) 中我这样做:
struct irp_list *il;
struct dev_info *di = (struct dev_info*)device->DeviceExtension;
if (!(il = ExAllocatePool(NonPagedPool, sizeof(*il)))) {
ret = STATUS_NO_MEMORY;
DbgPrint("[uart] UartWrite can't handle irp...\n");
goto error;
}
il->irp = irp; // store DriverWrite irp
InsertTailList(&di->lh, &il->lh); // this insert is not failing...
irp->IoStatus.Information = 0;
IoMarkIrpPending(irp);
return STATUS_PENDING;
在 DPC 函数中,我尝试使用以下命令访问 il 的非分页内存:
struct dev_info* di;
di = (struct dev_info*)device->DeviceExtension;
if(!IsListEmpty(&di->lh))
{
// code never reached
}
我知道 DPC 只能读取非分页内存,但为什么 !IsListEmpty 总是返回 FALSE 就好像插入失败一样?