A couple of suggestions
-
do not keep ANY globals at all. Get rid of every last one. This will force you to keep state per device object and to maintain that state in the right spot.
-
read the wdk rules about pnp irps proactively and apply to them to your driver. Do not randomly change behavior in the driver and hope that it sticks (And is correct)
…and of course, I would suggest you strongly consider KMDF for your driver instead of WDM. KMDF takes care of all of these details for you and lets you focus in on what you want the driver to do instead of all the rules it must follow
d
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Thursday, January 22, 2009 6:31 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] USB device surprise removal issue
Thanks to everyone for your responses.
I am in a situation where I do not control the application code. In any case I would like the driver to be robust irrespective of what the application does.
As Doron said, In case of application not releasing handle and still attempting IO after removal,It is made to fail by the driver in this case, not the OS.
My problem is not that about the IO’s but with a REMOVE_DEVICE IRP that comes out of turn due to app not releasing handle. This caused the device to get logically removed during cleanup.
Earlier I had fixed this by identifying the problem REMOVE_DEVICE IRP by tracking the states. In normal course it should follow either surprise remove or query removal. If not, i used to simply complete the IRP without doing any processing. This caused driver verifier to Bugcheck
DRIVER_VERIFIER_IOMANAGER_VIOLATION (c9)
The IO manager has caught a misbehaving driver.
Arguments:
Arg1: 0000021d, (Fatal error) An IRP dispatch handler has not properly detached from the stack below it upon receiving a remove IRP. (DeviceObject, Dispatch Routine, and IRP specified.)
Today, I came up with a new solution. After analyzing the device objects from succesive insertions, I found that the only common thing that I am cleaning up is the symbolic link. I crated a global pointer to hold the symbolic link and deffered setting it to false, to the driver unload function. With this, the problematic REMOVE_DEVICE IRP handler will only do cleanup on what the old device object refers to. The new device object is not affected and hence device does not get logically removed.
What do you think about this solution. Is this an acceptable way to deal with this?
Regards,
Venkateswaran C G
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer