Detachuing a specific DeviceObject from a Device stack

Someday I’ll publish my bus filter driver on github so this doesn’t have to
be such torture.

Mark Roddy

On Wed, Nov 23, 2016 at 2:05 PM, wrote:

> IoAttachDeviceToDeviceStack() attaches a device object to any stack,
> whether it’s managed to PNP or not. It doesn’t care whether the stack
> starts on a PDO or on a custom device object.
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at: http:> showlists.cfm?list=ntdev>
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and
> software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at <
> http://www.osronline.com/page.cfm?name=ListServer&gt;
></http:></http:>

That would be an *amazing* gift to the community. I’m not sure a lot of people can appreciate just how cool that would be.

Peter
OSR
@OSRDrivers

> @Alex, I am going to move the IoAttachToDeviceStack() to the return from IRP_MN_QUERY_RESOURCE_REQUIREMENTS just in case this is an issue.

I wonder how you recieve an IRP_MN_QUERY_RESOURCE_REQUIREMENTS IRP without being attached. Please tell us how you do this “legally”.

@Abdel Read what I copied from the WDK documentation “The driver can safely assume that the PDO’s devnode has been created when it receives an IRP_MN_QUERY_RESOURCE_REQUIREMENTS request.”

When IT, the PDO, has received IRP_MN_QUERY_RESOURCE_REQUIREMENTS , not the filter.

@Mark Nothing tortuous about filter drivers Mark, its about when to use the list of PDOs returned from a bus FDO in response to a IRP_MN_QUERY_DEVICE_RELATIONS. Perhaps you should read the entire thread before making comments.

By the time the stack receives IRP_MN_QUERY_RESOURCE_REQUIREMENTS, it’s fully built with all lower and upper filters and FDO.

@Alex, yes, its clear that that’s what happens. The documentation isn’t clear on this though: Trying to use the child PDO when the bus is back from query relations doesn’t always cause an error. Using it in IoAttachDeviceToDeciveStack() is OK, but using it in IoGetDeviceObjectProperty() isn’t for example.

>Using it in IoAttachDeviceToDeciveStack() is OK, but using it in IoGetDeviceObjectProperty()
isn’t for example.

It’s because IoAttachDeviceToDeviceStack() is not a PNP function, and IoGetDeviceObjectProperty() is a PNP function.

@Alex, you will have to explain what you mean there, how does one function be non ‘PnP’ while another is?

By reading the docs and seeing if the passed in device object is required to be a pdo or can be any random device

Get Outlook for Android


From: xxxxx@lists.osr.com on behalf of xxxxx@hotmail.com
Sent: Friday, November 25, 2016 6:39:59 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Detachuing a specific DeviceObject from a Device stack

@Alex, you will have to explain what you mean there, how does one function be non ‘PnP’ while another is?


NTDEV is sponsored by OSR

Visit the list online at: http:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at http:

To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:>

Hm. I see, for IoGetDeviceProperty() it states it has to be a PDO device, but for IoAttachDeviceToDeviceStack() it doesn’t.

20 years writing windows drivers and I have never heard of this distinction before. The documentation on query resources doesn’t go into this detail. Shame, it would make life easier.

Anyway, thanks Doron

>Warning A device object cannot be passed to any routine that takes a PDO as an
argument

A PDO is a PNP concept. It becomes a PDO when PNP subsystem knows about it.

From IoAttachDeviceToDeviceStack documentation:

The IoAttachDeviceToDeviceStack routine attaches the caller’s device object to the highest device object in the chain and returns a pointer to the previously highest device object.

Nowhere does it say the target device object or any device object in the chain has to be a PDO. In fact, such a requirement cannot exist, because the function already existed when Windows didn’t even have a concept of PDO.

I know, but it IS a PDO in this case.

So “A device object cannot be passed to any routine that takes a PDO as an argument”
should read “A device object cannot be passed to any routine that REQUIRES a PDO as an argument”

Yes. That would be a good and valuable clarification. Please click “Send comments on this topic to Microsoft” and recommend the change, point to this thread if you like.

Peter
OSR
@OSRDrivers