What status should I return in my dispatch routine when completing an IRP?

Discussion in 'Windows Vista Drivers' started by Borislav Marinov, May 22, 2007.

  1. What status should I return in my dispatch routine when completing an
    IRP (in my LOWEST LAYER DRIVER)?
    The documentation is unclear on that but I have 2 choices (let say
    ntStat is my completion status):
    1. mark the IRP as pending (IoMarkIrpPending), set my completion
    status (ntStat) in Irp->IoStatus.Status, complete the IRP
    (IoCompleteRequest) and return status PENDING.
    2. set my completion status (ntStat) in Irp->IoStatus.Status, complete
    the IRP (IoCompleteRequest) and return ntStat.
    In both cases the upper layer completion routine will get invoked but
    in case #2, the upper driver will get status different than pending
    which will indicate that access to the IRP is allowed (the
    documentation only states that access is not allowed if pending is
    returned so any other status implies that I am allowed to access the
    IRP, correct?). wouldn't that cause a crash?
    Most of the upper layer drivers check for status pending and than they
    wait on the async. event, which is signaled by the IoCompletion
    routine, and they do not do that if the status is not pending. This
    somehow implies that the IoCompletion routine is not called (the event
    is not signaled), correct?
    I am currently voting for #1 any other thoughts?
    Thanks a lot,
    Bobby Marinov
     
    Borislav Marinov, May 22, 2007
    #1
    1. Advertisements

  2. The rule is:

    If you complete an IRP in your dispatch routine, you should return the same
    status as you put into Irp->IoStatus->Status.

    BUT, if you queue your IRP for later completion, you MUST call
    IoMarkIrpPending, AND return STATUS_PENDING. Even though the IRP can be
    completed in the meantime.
     
    Alexander Grigoriev, May 22, 2007
    #2
    1. Advertisements

  3. Borislav Marinov

    Tim Roberts Guest

    It depends on whether you are done with the IRP or not. If you are really
    done with the IRP, then you do #2 -- you set the status, complete the IRP,
    and return the status.

    If you aren't done with the request, then you follow the pending path.
     
    Tim Roberts, May 22, 2007
    #3
  4. What status should I return in my dispatch routine when completing an
    If you have already called IoCompleteRequest for the IRP - then return the same
    value as was set in Irp->IoStatus.Status.

    Note that you cannot touch Irp->IoStatus.Status after IoCompleteRequest, so, do
    something like:

    Irp->IoStatus.Status = Status = STATUS_SOME_ERROR;
    IoCompleteRequest(Irp, ...);
    return Status;
     
    Maxim S. Shatskih, May 22, 2007
    #4
  5. Thanks for the reply.
    I know all that and my sample indicates (not touching of the IRP.
    My problem is with the upper layer driver which is going to receive
    status SUCCESS and a callback.
    The question is where should I process the IRP when a non-pending
    status is returned?
    The answer is simple for the pending status - in the IoCompletion
    routine. But for status success(or failure) It gets more complicated.
    I can always ignore the IoCompletion or I can always use the callback:
    if I supply it, I should always be called, correct?
     
    Borislav Marinov, May 22, 2007
    #5
  6. The question is where should I process the IRP when a non-pending
    You must process it in the dispatch routine or its callees, then fill
    Irp->IoStatus, then call IoCompleteRequest - all from this path.
     
    Maxim S. Shatskih, May 22, 2007
    #6
    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.