Registering a Cancel Routine

If a device driver has a StartIo routine, its dispatch routines can register a Cancel routine by supplying its address as input to IoStartPacket.

If a driver does not have a StartIo routine, its dispatch routines must do the following before queuing an IRP for further processing by other driver routines:

  1. Call IoAcquireCancelSpinLock.

  2. Call IoSetCancelRoutine with the input IRP and the entry point for a driver-supplied Cancel routine.

  3. Call IoReleaseCancelSpinLock.

For information about the cancel spin lock, see Using the System's Cancel Spin Lock.

Drivers that manage their own queues of IRPs, rather than using the I/O manager-supplied device queue, do not need to acquire the cancel spin lock when calling IoSetCancelRoutine. However, these drivers should check the Cancel routine pointer that IoSetCancelRoutine returns to determine whether the Cancel routine has already started.