非分页内存指针
Nonpaged memory pointer
>我声明了 2 个结构:
struct irp_list {
IRP *irp;
LIST_ENTRY lh;
};
和
struct dev_info {
...
LIST_ENTRY lh;
...
};
在驱动程序写入函数(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,就好像插入失败一样?
这可能不是一个正确的答案,但对于评论来说有点太复杂了,所以我把它写成一个答案,为了正确的格式,等等:
阅读文档InsertTailList
:
VOID InsertTailList( _Inout_ PLIST_ENTRY ListHead, _Inout_ PLIST_ENTRY Entry );
InsertTailList
更新ListHead->Blink
指向Entry
。它 更新Entry->Blink
以指向列表中旧的最后一个条目,以及 将Entry->Flink
设置为ListHead
。上一个的Flink
条目也会更新为指向Entry
。
IsListEmpty
在哪里 说:
现在,我如果当前没有条目,则
IsListEmpty
返回TRUE
列表,否则为 FALSE。言论
IsListEmpty
如果引用回TRUE
ListHead->Flink
则返回ListHead
.
不确定我是否理解所有这些,但对我来说,ListHead->Flink
似乎没有被InsertListTail
更新(这似乎很奇怪(。虽然这句话
上一个最后一个条目的
Flink
也更新为指向Entry
。
可能表明它确实会更新头部,如果它是列表中的唯一内容。
(嘎嘎,刚刚发现评论说你已经解决了(。