none
if current irp->CurrentLocation = 1,still Call IoSetCompletionRoutine RRS feed

  • Question

  • if current irp->CurrentLocation == 1 still Call IoSetCompletionRoutine to set CompletionFun at next Layer IoStack in,it would be ?

    Thanks.

    Thursday, September 12, 2013 9:21 AM

Answers

  • You can't call IoSkipCurrentIrpStackLocation and then set a completion routine, that will stomp on the completion routine of the previous driver in the stack or corrupt memory. you should always receive an irp with enough stack locations. what device stack are you in? are you attaching to the stack outside of AddDevice?

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    • Marked as answer by Jiang Kai Wednesday, October 9, 2013 1:14 AM
    Friday, September 13, 2013 4:10 AM
  • You should not even be looking at irp-CUrrentLocation for questions like this.  In fact in 20 years of Windows driver writing I've never looked at the value directly, I only used it to get a pointer to the IRP stack location.

    The rule is if you have an IRP that was either recieved or created by your driver, you can call IoSetCompletionRoutine to get a completion callback if you are passing the IRP to another driver.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    • Proposed as answer by Pavel A Thursday, September 12, 2013 12:11 PM
    • Marked as answer by Doron Holan [MSFT] Thursday, September 12, 2013 2:08 PM
    Thursday, September 12, 2013 10:57 AM

All replies

  • You should not even be looking at irp-CUrrentLocation for questions like this.  In fact in 20 years of Windows driver writing I've never looked at the value directly, I only used it to get a pointer to the IRP stack location.

    The rule is if you have an IRP that was either recieved or created by your driver, you can call IoSetCompletionRoutine to get a completion callback if you are passing the IRP to another driver.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    • Proposed as answer by Pavel A Thursday, September 12, 2013 12:11 PM
    • Marked as answer by Doron Holan [MSFT] Thursday, September 12, 2013 2:08 PM
    Thursday, September 12, 2013 10:57 AM
  • I want to say that if current irp->CurrentLocation == 1, and then current irp->CurrentLocation == 2 by IoSkipCurrentIrpStackLocation(irp).finally Call IoCallDriver ,stay on this location after IoCallDriver .

    CODE:to avoid NO_MORE_STACK_LOCATIONS

    if (cr == NULL || irp->CurrentLocation <= 1) // WINDBG:irp->CurrentLocation = 2  FilterDev & OriginalDev
      {
       
       
       IoSkipCurrentIrpStackLocation(irp);
      
       if (cr != NULL)
       {
        
        //set completion routine (this way is slow)
        // save old completion routine and context
        TDI_SKIP_CTX *ctx = (TDI_SKIP_CTX *)ExAllocatePoolWithTag(NonPagedPool, sizeof(*ctx), POOL_TAG);
        if (ctx == NULL) {

         FilterDebugPrint(("%s: ExAllocatePoolWithTag error\n", __FUNCTION__));
         
         status = irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
         IoCompleteRequest(irp, IO_NO_INCREMENT);

         return status;
        }

        ctx->old_cr = irps->CompletionRoutine;
        ctx->old_context = irps->Context;
        ctx->new_cr = cr;
        ctx->new_context = context;
        ctx->fileobj = irps->FileObject;
        ctx->new_devobj = devobj;

        ctx->old_control = irps->Control;

        IoSetCompletionRoutine(irp, tdi_skip_complete, ctx, TRUE, TRUE, TRUE);
        DbgPrint("in tdi_dispatch_complete,abnormal status irp->CurrentLocation <= 1:irp:0X%X.\n",irp);
       }
       else
       {
        DbgPrint("in tdi_dispatch_complete,abnormal status,irp:0X%X.\n",irp);
       }

      }
      else
      {
       
       IoCopyCurrentIrpStackLocationToNext(irp);
       
       if (cr != NULL)
       {
        /*
         * this way for completion is more quicker than used above
         */
        DbgPrint("in tdi_dispatch_complete,normal status,irp:0X%X.\n",irp);
        IoSetCompletionRoutine(irp, cr, context, TRUE, TRUE, TRUE);
       }
       else
       {
        DbgPrint("in tdi_dispatch_complete,normal status,cr == NULL, irp:0X%X.\n",irp);
        IoSetCompletionRoutine(irp, tdi_generic_complete, NULL, TRUE, TRUE, TRUE);
       }
      }

      /* call original driver */
      status = IoCallDriver(old_devobj, irp);
     }
     return status;

    Other:
    Really want to know you of Email, because I also want to study 20 years driven development......

    I'm anystayisjk@hotmail.com

    Friday, September 13, 2013 2:37 AM
  • You can't call IoSkipCurrentIrpStackLocation and then set a completion routine, that will stomp on the completion routine of the previous driver in the stack or corrupt memory. you should always receive an irp with enough stack locations. what device stack are you in? are you attaching to the stack outside of AddDevice?

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    • Marked as answer by Jiang Kai Wednesday, October 9, 2013 1:14 AM
    Friday, September 13, 2013 4:10 AM
  • This is TdiFilter's DeviceStack. attaching by IoAttachDeviceToDeviceStackSafe.

    Thanks

    Friday, September 13, 2013 6:08 AM