非分页内存指针

Nonpaged memory pointer

本文关键字:指针 内存 分页      更新时间:2023-10-16

>我声明了 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

可能表明它确实会更新头部,如果它是列表中的唯一内容。

(嘎嘎,刚刚发现评论说你已经解决了(。