MUX Sample Queries

in the MUX sample, Mux.C file, for PtRegisterDevice routine, the Routine
Description says: Do not call this from DriverEntry, it will prevent teh
driver from being unloaded (e.g. on uninstall)

why would that happen? Can some one explain?

Creating an Auxilary device in DriverEntry creates an additional reference
on the DeviceObject which prevents the system (NDIS/PnP) from recognizing
that it should call the driver’s unload routine. As a result, if you create
the (an) Auxilary device during DriverEntry, DriverUnload will never be
called. The solution demonstrated in MUX and PASSTHRU (and other NDIS
Miniport samples) is to tie the lifetime of the Auxilary device to the
combined lifetime of all of the miniports (as long as at least one miniport
exists, the Aux device will exist). The Aux device will be destroyed when
the last Miniport is halted (and be destroyed when MiniportHalt returns)
thus allowing NDIS & the system to recognize that it can unload the driver.

I don’t know that this is exactly the logic but from an external model,
think of it this way: When NDIS finishes halting a miniport, it looks at
the DriverObject and asks “hey, any more DeviceObjects associated with this
DriverObject?” If the answer is no, it asks PnP to unload the driver. If
the answer is yes, it assumes that it will get a chance to ask the question
again when the next Miniport is being halted. The problem with that is if
the DeviceObject is actually the Aux device, nothing will ever give NDIS a
chance to ask the question again unless a miniport is loaded & unloaded
after the Aux device is destroyed.

Good Luck,
Dave Cattley
Consulting Engineer
Systems Software Development


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of A P
Sent: Wednesday, December 20, 2006 3:48 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] MUX Sample Queries

in the MUX sample, Mux.C file, for PtRegisterDevice routine, the Routine
Description says: Do not call this from DriverEntry, it will prevent teh
driver from being unloaded (e.g. on uninstall)

why would that happen? Can some one explain?
— Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit the List
Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

I think this is true for any PnP drivers, not only NDIS ones. Creating a
device object in DriverEntry will prevent unload.


Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

“David R. Cattley” wrote in message news:xxxxx@ntdev…
> Creating an Auxilary device in DriverEntry creates an additional reference
> on the DeviceObject which prevents the system (NDIS/PnP) from recognizing
> that it should call the driver’s unload routine. As a result, if you create
> the (an) Auxilary device during DriverEntry, DriverUnload will never be
> called. The solution demonstrated in MUX and PASSTHRU (and other NDIS
> Miniport samples) is to tie the lifetime of the Auxilary device to the
> combined lifetime of all of the miniports (as long as at least one miniport
> exists, the Aux device will exist). The Aux device will be destroyed when
> the last Miniport is halted (and be destroyed when MiniportHalt returns)
> thus allowing NDIS & the system to recognize that it can unload the driver.
>
> I don’t know that this is exactly the logic but from an external model,
> think of it this way: When NDIS finishes halting a miniport, it looks at
> the DriverObject and asks “hey, any more DeviceObjects associated with this
> DriverObject?” If the answer is no, it asks PnP to unload the driver. If
> the answer is yes, it assumes that it will get a chance to ask the question
> again when the next Miniport is being halted. The problem with that is if
> the DeviceObject is actually the Aux device, nothing will ever give NDIS a
> chance to ask the question again unless a miniport is loaded & unloaded
> after the Aux device is destroyed.
>
> Good Luck,
> Dave Cattley
> Consulting Engineer
> Systems Software Development
>
> _____
>
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of A P
> Sent: Wednesday, December 20, 2006 3:48 AM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] MUX Sample Queries
>
>
> in the MUX sample, Mux.C file, for PtRegisterDevice routine, the Routine
> Description says: Do not call this from DriverEntry, it will prevent teh
> driver from being unloaded (e.g. on uninstall)
>
>
> why would that happen? Can some one explain?
> — Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit the List
> Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>