gpt4 book ai didi

c++ - 非分页内存指针

转载 作者:可可西里 更新时间:2023-11-01 10:37:16 24 4
gpt4 key购买 nike

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

最佳答案

这可能不是一个正确的答案,但它对于评论来说有点太复杂了,所以我把它写成一个答案,为了正确的格式等:

阅读 InsertTailList 的文档:

VOID InsertTailList(
_Inout_ PLIST_ENTRY ListHead,
_Inout_ PLIST_ENTRY Entry
);

InsertTailList updates ListHead->Blink to point to Entry. It updates Entry->Blink to point to the old last entry in the list, and sets Entry->Flink to ListHead. The Flink of the previous last entry is updated to point to Entry as well.

在哪里IsListEmpty说:

IsListEmpty returns TRUE if there are currently no entries in the list and FALSE otherwise.

Remarks

IsListEmpty returns TRUE if ListHead->Flink refers back to ListHead.

现在,我不确定我是否理解所有这些,但对我来说,ListHead->Flink 似乎没有被 InsertListTail 更新(这似乎比较奇怪)。虽然这句话

The Flink of the previous last entry is updated to point to Entry as well.

可能表示如果它是列表中唯一的东西,它确实会更新头部。

(啊,刚看到评论说你已经解决了)。

关于c++ - 非分页内存指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18431647/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com