5.1 DriverEntry Routine Requirements
Each NT driver must have a standard initialization routine in order to be loaded. The NT I/O Manager defines the prototype, as shown previously, for driver initialization routines.
Naming an NT Driver’s Initialization Routine
Each NT driver should have an initialization routine named DriverEntry. Otherwise, the driver writer must define the name of an NT driver’s initialization routine for the linker so that the driver’s transfer address is linked into the OS loader.
Explicitly naming an NT driver’s initialization routine DriverEntry creates this linkage automatically.
Linking an NT Driver to Libraries
Never link an NT driver with the C runtime library, thereby bloating the driver’s load image with a set of functions specific to the Win32® programming environment. NT drivers cannot call user-mode C runtime routines from kernel mode.
NT drivers use the system-supplied support routines declared in ntddk.h, which includes the NT RtlXxx (for Runtime library) functions and ntdef.h with the set of kernel-mode C runtime routines that NT drivers can call.
The system-supplied video and SCSI port drivers are implemented as dynamic-link libraries. Kernel-mode SCSI and video miniport drivers link themselves to the NT video or SCSI port driver and call the routines exported by the appropriate port driver. For more information about SCSI and video miniport drivers, see Appendix A and the Graphics Driver Design Guide, respectively.
Discardable and Pageable NT Driver Code
The DriverEntry routine and any other driver routines that run only during initialization should be discarded after initialization to conserve system-space memory.
The following driver code must be resident while an NT driver is processing I/O requests:
·Any code that is run at IRQL >= DISPATCH_LEVEL
For a summary of the default IRQLs at which standard NT driver routines run, see Chapter 16.
·Any code that might be in the system page-fault path, which includes any intermediate or device driver code that handles I/O requests for an underlying mass-storage device
Otherwise, NT driver code can be made pageable to conserve system memory. An NT driver of a device that is not used constantly while the system is running can set up a pageable code section that is locked in system memory only when that driver is called to process I/O requests, as can any NT driver layered over such a device driver. However, a device driver’s pageable code section cannot contain certain standard routines.
For more information about discardable and pageable NT driver code, see the Programmer’s Guide.