Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 6. Initialization and Cleanup Ro... > Writing Reinitialize Routines - Pg. 88

Initialization and Cleanup Routines status = IoCreateSymbolicLink( &(UNICODE_STRING)symLinkName, &(UNICODE_STRING)devName ); if (!NT_SUCCESS(status)) { // if it fails now, must delete Device object IoDeleteDevice( pDevObj ); return status; } // Made it return STATUS_SUCCESS; } 88 Writing Reinitialize Routines Intermediate-level drivers loading at system boot time may need to delay their initialization until one or more lower-level drivers have finished loading. If the loading of the drivers is under central control, the load sequence can be fixed by setting various Registry entries at installation. But if the drivers are supplied by different vendors, the load order may be indeterminate. In the latter case, the in- termediate driver must register and implement a Reinitialize routine. Execution Context If the DriverEntry routine discovers that it can't finish its initialization because system bootstrapping hasn't yet gone far enough, it can announce a Reinitialize routine by calling IoRegisterDriverReini- tialization. The I/O Manager calls the Reinitialize routine at some later point during the bootstrap. As described in Table 6.3, the Reinitialize routine runs at PASSIVE_ LEVEL IRQL, which means it has access to paged system resources. Reinitialize routines are useful only for drivers that load automatically at system boot. What a Reinitialize Routine Does The Reinitialize routine can perform any driver initialization that the DriverEntry routine was unable to complete. If the Reinitialize routine discovers that the environment still isn't suitable, it can call IoRegisterDriverReinitialization again to reregister itself. Table 6.3. Function Prototype for Reinitialize Routine VOID Reinitialize Parameter IN PDRIVER_OBJECT pDriverObject IN PVOID Context IN ULONG Count Return value IRQL == PASSIVE_LEVEL Description Pointer to driver object Context block specified at registration Zero-based count of reinitialization calls (void) 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.