Asynchronous I/O Responses
A driver should return STATUS_PENDING from a dispatch routine when it cannot complete an I/O request synchronously in a timely manner. Understanding when to return STATUS_PENDING is a problem for many driver writers.
A driver must return STATUS_PENDING if:
· Its dispatch routine for an IRP might return before the IRP is completed.
· It completes the IRP on another thread.
· The dispatch routine cannot determine the IRP’s completion status before it returns.
The driver must call the IoMarkIrpPending macro before it releases control of the IRP and before it returns STATUS_PENDING. IoMarkIrpPending sets the SL_PENDING_RETURNED bit in the Control field of the current I/O stack location. Each time an I/O stack location is completed, the I/O Manager copies the value of this bit to the Irp->PendingReturned field in the IRP header, as Figure 5 shows.
Figure 5. Propagating the pending bit
In Figure 5, Driver C’s call to the IoMarkIrpPending macro sets the SL_PENDING_RETURNED bit in the Control field of Driver C’s I/O stack location. When Driver C completes the IRP, the I/O Manager changes the IRP stack pointer to point to driver B and propagates the value of the SL_PENDING_RETURNED bit to the PendingReturned field in the IRP header.