Writing an Unload Routine
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 Context
The 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 Does
Although the exact details vary from driver to driver, in general the following steps are performed in an Unload routine.
Get Windows® 2000 Device Driver Book: A Guide for Programmers, Second Edition, The now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.