非分页内存指针

时间:2013-08-25 17:22:52

标签: c++ windows driver wdk

我声明了2个结构:

struct irp_list {
   IRP *irp;
   LIST_ENTRY lh;
};

struct dev_info {
...
   LIST_ENTRY lh;
...
};

Inside 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,好像插入失败一样?

1 个答案:

答案 0 :(得分:1)

这可能不是一个正确的答案,但它对于评论来说有点过于复杂,所以我将其作为答案,正确的格式化等来写:

阅读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

如果它是列表中唯一的东西,

可能表示它确实更新了头部。

(Gah,刚发现评论说你已经解决了它)。

相关问题