Hello gurus,
hopefully someone can point me in the right direction:
I have a legacy driver, that is loaded/unloaded by a user-mode
application via SCM.
When loaded, the driver creates a Control Device Object to communicate
with the user mode app, as well as a couple of other device objects that
perform the real work. The work is not related to any actual device,
it’s just reading/writing to the disk (think virtual file-based drive,
stuff like that). When the work is done, the application sends a control
code to CDO asking it to shut down, the CDO deletes the child device
objects. Before they are deleted, the values of the ReferenceCounts in
their device objects go to 0, indicating that there are no outstanding
references to them.
Finally, the user mode application tells SCM to stop the driver, which
causes the Unload routine to be called, which destroys the CDO, the
DeviceObject member of DriverObject becomes 0, indicating that there are
no device object remaining, and it quits.
At this point it looks like the driver is unloaded, except that it’s
not. Breaking into WinDbg and issuing “lm t n” shows that the driver’s
module is still loaded, and an attempt to start the driver via SCM this
time results in error 2 “file not found”. The only way to solve the
error is to reboot the computer, and after that SCM again can start the
driver, but only once, the subsequent attempts result in error 2 until
the computer is restarted.
As I mentioned, the state of the DeviceObject’s and DriverObject before
unloading shows no outstanding resources that might prevent the driver
from actually being unloaded.
The tracing in the memory allocation routines shows that all memory the
driver allocates gets deleted properly, so there goes another possible
reason.
The Irp tracking shows no outstanding Irp’s either.
Driver Verifier is enabled for this driver and reports no problems.
It seems like this is happening on Vista (with SP1) only, I was not able
to reproduce this error on XP (the driver gets actually unloaded from
the memory).
Does this ring any bell? What else can I check to see if there is
something that forces Vista to keep the driver in memory after the
Unload routine is called?
Any advice would be greatly appreciated! Thank you in advance.
Andrei Belogortseff