7.2.1 StartIo Routines in NT Device Drivers

As its name suggests, a StartIo routine in an NT device driver is responsible for starting an I/O operation on the physical device.

When an NT device driver’s StartIo routine is called, it can assume that the target device represented by the input device object is not busy. Either one of that device driver’s Dispatch routines has just called IoStartPacket and the IRP was not inserted into the device queue associated with the target device object, or the driver’s DpcForIsr routine is completing another request and has just called IoStartNextPacket.

Before the StartIo routine in a highest-level NT device driver is called, that driver’s Dispatch routine must have probed and locked down the user buffer, if necessary, to set up valid mapped buffer addresses in the IRP queued to its StartIo routine. Such a highest-level device driver that sets up its device objects for direct I/O (or for neither buffered nor direct I/O) cannot defer locking down a user buffer to the driver’s StartIo routine because every StartIo routine is called in an arbitrary thread context at IRQL DISPATCH_LEVEL.

    In other words, NT driver designers should keep in mind the following fact:

Any buffer memory to be accessed by an NT driver’s StartIo routine must be locked down or allocated from resident, system-space memory and must be accessible in an arbitrary thread context.

NT drivers that set up their device objects for buffered I/O can rely on the I/O Manager to pass valid buffers in all IRPs sent to such a driver. Lower-level NT drivers that set up device objects for direct I/O can rely on the highest-level NT driver in their chain to pass valid buffers in all IRPs sent through any intermediate drivers to the underlying device driver.

In general, any NT device driver’s StartIo routine is responsible for calling IoGetCurrentIrpStackLocation with the input IRP and then doing whatever request-specific processing is necessary to start the I/O operation on its device, which can include the following: