If a driver has special processing to do before the operating system disappears, a driver should supply a Shutdown routine. Execution ContextThe I/O Manager calls a Shutdown routine during a system shutdown. As described in Table 6.5, the Shutdown routine runs at PASSIVE_LEVEL IRQL, which means it has access to paged system resources.
What a Shutdown Routine DoesThe main purpose of the Shutdown routine is to put the device into a quiescent state and perhaps store some device information into the system Registry. Again, saving the current volume settings from a sound card is a good example of something a Shutdown routine might do. Unlike the driver's Unload routine, Shutdown routines don't have to worry about releasing driver resources because the operating system is about to disappear anyway. Enabling Shutdown NotificationThere is no direct field in the Driver object for announcing the Shutdown routine. Instead, the event of system shutdown is sent as a separate I/O request to a driver. It is handled with an entry inside of the driver's MajorFunction code array. Additionally, the I/O Manager must be notified that a driver is interested in receiving shutdown notifications. This is done by making a call to IoRegisterShutdownNotification. The following code fragment shows how to enable shutdown notifications in a driver. NTSTATUS DriverEntry ( IN PDRIVER_OBJECT pDriverObject, IN PUNICODE_STRING pRegistryPath ) { : pDriverObject->MajorFunction[ IRP_MJ_SHUTDOWN ] = Shutdown; IoRegisterShutdownNotification( pDriverObject ); : }
|