Iterating over WDM device stack

Discussion in 'Windows Vista Drivers' started by Ilya Konstantinov, Feb 23, 2011.

  1. [cross-posted to StackOverflow - http://stackoverflow.com/questions/5095406/iterating-over-wdm-device-stack]

    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 one 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?

    Thanks!
     
    Ilya Konstantinov, Feb 23, 2011
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.