迭代 WDM 设备堆栈

发布于 2024-10-18 14:04:00 字数 439 浏览 7 评论 0原文

据我了解,只能从下往上迭代 WDM 设备的设备堆栈,因为 DEVICE_OBJECT 有 AttachedDevice 成员(但不是 LowerDevice 成员)。幸运的是,AddDevice 回调接收 PhysicalDeviceObject,因此您可以迭代整个堆栈。

在我的过滤器驱动程序中,我试图确定我是否已经在过滤某个设备对象。 (假设我这样做有正当理由。请耐心等待。)我的想法是检查堆栈中的每个 DEVICE_OBJECT 并将其 DriverObject 成员与我的进行比较。

从 IoGetAttachedDeviceReference 的存在来看,我认为仅仅访问 AttachedDevice 并不是一件安全的事情,因为存在设备突然消失的风险。然而,IoGetAttachedDeviceReference 将我直接带到堆栈的顶部,这对我来说没有好处。

那么,有没有一种安全的方法来迭代设备堆栈呢?

As I understand, one can iterate the device stack of WDM devices only from the bottoms up, because DEVICE_OBJECT has an AttachedDevice member (but not a LowerDevice member). Luckily, the AddDevice callback receives the PhysicalDeviceObject so you can iterate over the entire stack.

From within my filter driver I'm trying to determine whether I'm already filtering a certain device object. (Let's say I have a legit reason for this. Bear with me.) My idea was to go over every DEVICE_OBJECT in the stack and compare its DriverObject member to mine.

Judging from the existence of IoGetAttachedDeviceReference, I assume just accessing AttachedDevice isn't a safe thing to do, for the risk of the device suddenly going away. However, IoGetAttachedDeviceReference brings me straight to the top of the stack, which is no good for me.

So, is there a safe way to iterate over a device stack?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

も让我眼熟你 2024-10-25 14:04:00

正确的,你不能安全地遍历 AttachedDevice 链,除非你能以某种方式保证堆栈不会被拆除(例如,如果你有一个引用堆栈的活动文件对象)。在 Win2K 上,这几乎是您唯一的选择。

在 XP 及更高版本上,首选方法实际上是从堆栈顶部向下遍历。您可以通过调用 IoGetAttachedDeviceReference 然后调用 IoGetLowerDeviceObject 来完成此操作。

-斯科特

Correct, you can't safely walk the AttachedDevice chain unless you can somehow guarantee that the stack will not be torn down (e.g. if you have an active file object referencing the stack). On Win2K this is pretty much your only option.

On XP and later, the preferred method is actually to walk from the top of the stack down. You can do this by calling IoGetAttachedDeviceReference and then calling IoGetLowerDeviceObject.

-scott

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文