By default, once the driver is loaded, it remains in the system until a reboot occurs. To make a driver unloadable, an Unload routine is necessary. The Unload routine is announced during DriverEntry. The I/O Manager then calls this routine whenever the driver is manually or automatically unloaded. Execution ContextThe I/O Manager calls a driver's Unload routine just before removing the driver from memory. Table 6.4 shows that the Unload routine runs at PASSIVE_LEVEL IRQL, which means it has access to paged system resources. What an Unload Routine DoesAlthough the exact details vary from driver to driver, in general the following steps are performed in an Unload routine.
It is important to note that for WDM drivers, the responsibilities of Unload are performed in the RemoveDevice routine. One final note: A driver's Unload routine is not called at system shutdown time. Any special work required during system shutdown must be performed inside of a separate shutdown routine.
|