I have an NDIS IM driver that has an IOControl interface that is called at
least once a second by an application. Whenever the driver is uninstalled
and the application continues to send IRPs, the Dispatch routine of the
driver gets called AFTER the Unload has completed causing a BSOD because the
reference data has been released by the Unload.

How can I prevent this call to Dispatch after the Unload?


Larry C

Re: Dispatch called after Unload by David

David
Tue Mar 22 00:11:44 CST 2005

You CAN NOT!!! unload if any handles are open to your device. If you are
unloading, you have logic bugs in your driver.

"Larry Clawson" <larry.clawson@honeywell.com> wrote in message
news:upi%23NAlLFHA.1308@TK2MSFTNGP15.phx.gbl...
>I have an NDIS IM driver that has an IOControl interface that is called at
>least once a second by an application. Whenever the driver is uninstalled
>and the application continues to send IRPs, the Dispatch routine of the
>driver gets called AFTER the Unload has completed causing a BSOD because
>the reference data has been released by the Unload.
>
> How can I prevent this call to Dispatch after the Unload?
>
>
> Larry C
>



Re: Dispatch called after Unload by Larry

Larry
Tue Mar 22 08:52:53 CST 2005

Ok, how does the driver know if a handle is open?. Does this also mean the
driver should fail the miniport halt and unbinds that proceed the unload?

Larry C

"David J. Craig" <SeniorDriversWriter@shogunyoshimuni.com.net> wrote in
message news:OAttZYqLFHA.3960@TK2MSFTNGP12.phx.gbl...
> You CAN NOT!!! unload if any handles are open to your device. If you are
> unloading, you have logic bugs in your driver.
>
> "Larry Clawson" <larry.clawson@honeywell.com> wrote in message
> news:upi%23NAlLFHA.1308@TK2MSFTNGP15.phx.gbl...
>>I have an NDIS IM driver that has an IOControl interface that is called at
>>least once a second by an application. Whenever the driver is uninstalled
>>and the application continues to send IRPs, the Dispatch routine of the
>>driver gets called AFTER the Unload has completed causing a BSOD because
>>the reference data has been released by the Unload.
>>
>> How can I prevent this call to Dispatch after the Unload?
>>
>>
>> Larry C
>>
>
>



Dispatch called after Unload by Steve

Steve
Tue Mar 22 22:59:47 CST 2005

I'm just guessing here, but I expect your user mode app
opens a handle to your IM driver when it starts and
closes it when it finishes. This is bound to lead to
problems because you'll be left with an invalid handle
when the IM is uninstalled.

There is an easy fix for your problem. Have your user
mode app open and close its handle to the IM driver
everytime you send an IOCTL. This way, if you uninstall
the driver, when the user mode app attemps to open it
again it will/should fail! This is what I do and I have
no problems.

Steve.

>-----Original Message-----
>I have an NDIS IM driver that has an IOControl interface
that is called at
>least once a second by an application. Whenever the
driver is uninstalled
>and the application continues to send IRPs, the Dispatch
routine of the
>driver gets called AFTER the Unload has completed
causing a BSOD because the
>reference data has been released by the Unload.
>
>How can I prevent this call to Dispatch after the Unload?
>
>
>Larry C
>
>
>.
>

Dispatch called after Unload by Steve

Steve
Wed Mar 23 18:20:19 CST 2005

Another easy solution is to close the app before you
uninstall your driver! A more complicated alternative is
that you get the driver to inform user mode apps (via a
notification system) that it is about to unload and that
they should close all handles to the driver.

Look at the ddk help on ProtocolUnload. This is the
callback specified in the protocol characteristics that
you used when you registered the protocol using
NdisRegisterProtocol.
The help says ... ProtocolUnload performs driver-
determined cleanup operations. For example,
ProtocolUnload could request clients to close handles
that they have opened to device objects exported by the
protocol. Until all such handles are closed, the I/O
Manager will not call the DriverUnload function that the
protocol registered in the driver object passed to its
DriverEntry function. After all the handles are closed,
ProtocolUnload could call IoDeleteDevice one or more
times to delete device objects created by the protocol.

In the passthru example, that your driver is probably
based on, the driver's device object is deleted in
PtDeregisterDevice() using NdisMDeregisterDevice().

Good luck.
Steve

>-----Original Message-----
>I'm just guessing here, but I expect your user mode app
>opens a handle to your IM driver when it starts and
>closes it when it finishes. This is bound to lead to
>problems because you'll be left with an invalid handle
>when the IM is uninstalled.
>
>There is an easy fix for your problem. Have your user
>mode app open and close its handle to the IM driver
>everytime you send an IOCTL. This way, if you uninstall
>the driver, when the user mode app attemps to open it
>again it will/should fail! This is what I do and I have
>no problems.
>
>Steve.
>
>>-----Original Message-----
>>I have an NDIS IM driver that has an IOControl
interface
>that is called at
>>least once a second by an application. Whenever the
>driver is uninstalled
>>and the application continues to send IRPs, the
Dispatch
>routine of the
>>driver gets called AFTER the Unload has completed
>causing a BSOD because the
>>reference data has been released by the Unload.
>>
>>How can I prevent this call to Dispatch after the
Unload?
>>
>>
>>Larry C
>>
>>
>>.
>>
>.
>