a question about driver completion routine

Discussion in 'Windows Vista Drivers' started by robert, Apr 27, 2005.

  1. robert

    robert Guest


    If an IRP is canceled, does the I/O manager call the driver supplied IRP
    completion Routine besides the driver supplied cancellation routine?

    robert, Apr 27, 2005
    1. Advertisements

  2. robert

    Calvin Guan Guest

    Yes if INVOKE_ON_CANCEL is specified and the cancelroutine called
    Calvin Guan, Apr 28, 2005
    1. Advertisements

  3. robert

    robert Guest

    Hi Calvin,
    Thanks, how/where is the INVOKE_ON_CANCEL flag used? I cannot find any
    information about this.
    On XP DDK, we can implement driver Cancel-Safe IRP Queues using
    IoCspxxx routines. These functions ensure that IRP cancellation is
    implemented correctly. However, driver doesn't implement cancellation
    routines. in this case, if my driver has implemented a completion routine for
    an IRP before inserted into the queue and this IRP gets canceled, does my
    driver's completion routine get called?

    robert, Apr 28, 2005
  4. It works ilke that:

    1. The IoCancelIrp function does InterlockedExchange of the cancel routine
    address (replaces it with NULL), acquires the cancel spinlock, mark the IRP
    cancelled, and if cancel routine was non-NULL, calls the cancel routine.
    2. The cancel routine is supposed to stop any I/O in progress and eventually
    call IoCompleteRequest with STATUS_CANCELLED status. All registered
    completion routines will get called, if they are set with CallOnCancel flag.

    If there is no cancel routine set, the IRP will only be marked as cancelled,
    but it's a driver responsibility to eventually call IoCompleteRequest on it.
    Alexander Grigoriev, Apr 28, 2005
  5. completion routines and cancel routines are mutually exclusive. if you have
    set a cancel routine, you own the irp because you pended it. A completion
    routine runs only when you send the irp to another device object and the
    device which received the irp completed the IRP. It is illegal to send an
    irp with a cancel routine set (the machine will bugcheck). So, when your
    cancel routine gets called, you complete the request at the appropriate

    Doron Holan [MS], Apr 28, 2005
  6. robert

    Calvin Guan Guest

    The upper drivers or the irp initiator can specify InvokeOnCancel flag when
    setting up a completion routine. As Doron pointed out, the driver sets the
    CancelRoutine can not set a completion routine for the same IRP. Completion
    routine (set by caller) is meant to notify the caller that and IRP on the
    target device has been complete.
    Calvin Guan, Apr 28, 2005
  7. The cancel routine usually calls IoCompleteRequest, which in turn fires the
    completion routine of the _next upper_ driver.

    Also look at InvokeOnCancel flag of IoSetCompletionRoutine.
    Maxim S. Shatskih, Apr 28, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.