none
DispatchPower Function RRS feed

  • Question

  • The driver has Always worked well with XP, Vista, Seven.
    I started the test with "Windows Hardware Certification Kit" on a PCwithSeven32bit(x86).
    The PC crashes always in elc_DispatchPowerfunction() during the callPoCallDriver().

    Bug Check 0xC9, 0x24D:

    Fatal error

    A driver has passed an invalid device object to a function that requires a PDO. (Device object specified.)

    The USB 2.0deviceis powered from the network, not the PC, does not affectset the device to energy saving as it is self-powered.


    ------------------------------------------------------------------------------
    NTSTATUS DriverEntry(  IN PDRIVER_OBJECT DriverObject,
     IN PUNICODE_STRING RegistryPath  )
    {
    ....
    DriverObject->MajorFunction[IRP_MJ_POWER] = elc_DispatchPower;
    ...
    }

    ------------------------------------------------------------------------------

    NTSTATUS elc_DispatchPower( IN PDEVICE_OBJECT fdo, IN PIRP Irp )
    {
       PIO_STACK_LOCATION irpStack, nextStack;
       PDEVICE_EXTENSION pdx = fdo->DeviceExtension;
       NTSTATUS ntStatus;

       Irp->IoStatus.Status = STATUS_SUCCESS;
       Irp->IoStatus.Information = 0;

       irpStack = IoGetCurrentIrpStackLocation (Irp);

       nextStack = IoGetNextIrpStackLocation(Irp);
       RtlCopyMemory(nextStack, irpStack, sizeof(IO_STACK_LOCATION));

       PoStartNextPowerIrp(Irp);
       ntStatus = PoCallDriver(pdx->StackDeviceObject,Irp);

       if (ntStatus == STATUS_PENDING)
       {
       IoMarkIrpPending(Irp);
       }
       else
       {
       } // if ntStatus is PENDING

    return ntStatus;

    }

    ------------------------------------------------------------------------------

    Thank you

    Wednesday, June 5, 2013 10:06 AM

Answers

  • There are actually several issues in the code mentioned above. For instance:

    • Use IoCopyCurrentIrpStackLocationToNext instead of manually copying the stack locations
    • Do not touch IRP after you called PoCallDriver/IoCallDriver
    • Use I/O remove lock to track the number of outstanding I/O operations and to determine when it is safe to detach and delete a driver's device object.

    Please see the following white paper on proper way to handle IRPs:

    http://msdn.microsoft.com/en-us/windows/hardware/gg487398

    Please see the following MSDN link on using remove locks:

    http://msdn.microsoft.com/en-us/library/windows/hardware/ff565504(v=vs.85).aspx

    Please take a look at serenum sample in your latest driver kit.

    Thanks,
    Rudy, Microsoft Driver Quality Tools team

    Thursday, June 13, 2013 5:01 PM
  • There are actually several issues in the code mentioned above. For instance:

    • Use IoCopyCurrentIrpStackLocationToNext instead of manually copying the stack locations
    • Do not touch IRP after you called PoCallDriver/IoCallDriver
    • Use I/O remove lock to track the number of outstanding I/O operations and to determine when it is safe to detach and delete a driver's device object.

    Please see the following white paper on proper way to handle IRPs:

    http://msdn.microsoft.com/en-us/windows/hardware/gg487398

    Please see the following MSDN link on using remove locks:

    http://msdn.microsoft.com/en-us/library/windows/hardware/ff565504(v=vs.85).aspx

    Please take a look at serenum sample in your latest driver kit.

    Thanks Microsoft Driver Quality Tools Team.

    Thursday, June 13, 2013 5:07 PM

All replies

  • Can you provide the full !analyze -v output?  The 0xC9 bugcheck is generated by Driver Verifier.  I may be able to provide more detail with the full output as to what Verifier is seeing there.

    Driver Verifier is designed to enforce rules as written on MSDN, and I'm fairly certain that DV is enforcing this excerpt from the PoCallDriver routine page on MSDN:

    "Beginning with Windows Vista, drivers should call IoCallDriver, not PoCallDriver to pass a power IRP to the next-lower driver. "

    If you're looking to use this driver on Win8 or Win8.1 (and really, Win7 and Vista for that matter), it should be updated to use IoCallDriver when passing the IRP down to the next device. 

    Thanks,

    Michael

    Thursday, June 13, 2013 3:49 AM
  • There are actually several issues in the code mentioned above. For instance:

    • Use IoCopyCurrentIrpStackLocationToNext instead of manually copying the stack locations
    • Do not touch IRP after you called PoCallDriver/IoCallDriver
    • Use I/O remove lock to track the number of outstanding I/O operations and to determine when it is safe to detach and delete a driver's device object.

    Please see the following white paper on proper way to handle IRPs:

    http://msdn.microsoft.com/en-us/windows/hardware/gg487398

    Please see the following MSDN link on using remove locks:

    http://msdn.microsoft.com/en-us/library/windows/hardware/ff565504(v=vs.85).aspx

    Please take a look at serenum sample in your latest driver kit.

    Thanks,
    Rudy, Microsoft Driver Quality Tools team

    Thursday, June 13, 2013 5:01 PM
  • There are actually several issues in the code mentioned above. For instance:

    • Use IoCopyCurrentIrpStackLocationToNext instead of manually copying the stack locations
    • Do not touch IRP after you called PoCallDriver/IoCallDriver
    • Use I/O remove lock to track the number of outstanding I/O operations and to determine when it is safe to detach and delete a driver's device object.

    Please see the following white paper on proper way to handle IRPs:

    http://msdn.microsoft.com/en-us/windows/hardware/gg487398

    Please see the following MSDN link on using remove locks:

    http://msdn.microsoft.com/en-us/library/windows/hardware/ff565504(v=vs.85).aspx

    Please take a look at serenum sample in your latest driver kit.

    Thanks Microsoft Driver Quality Tools Team.

    Thursday, June 13, 2013 5:07 PM