Hi,
I’m attempting to create a filter driver for a serial port. I can
successfully attach the driver and intercept serial calls. However,
when the driver is unloaded I get a 0x9F bug check
(DRIVER_POWER_STATE_FAILURE) with parameter 1 = 1. The DDK docs
say this means “The device object being freed still has an
outstanding power request which it has not completed”.
My desire was to have a filter driver that could run on NT4 as
well as the later version of NT so I initially simply passed
all IRPs down to the next layer like so:
NTSTATUS JCSerialFilterDispatch(PDEVICE_OBJECT pDeviceObject, PIRP pIrp)
{
PIO_STACK_LOCATION pIrpStkCur;
PIO_STACK_LOCATION pIrpStkNext;
PJCSERIAL_EXTENSION pDevExt =
(PJCSERIAL_EXTENSION)pDeviceObject->DeviceExtension;
pIrpStkCur = IoGetCurrentIrpStackLocation(pIrp);
pIrpStkNext = IoGetNextIrpStackLocation(pIrp);
*pIrpStkNext = *pIrpStkCur;
IoSetCompletionRoutine(pIrp, NULL, NULL, FALSE, FALSE, FALSE);
return IoCallDriver(pDevExt->pSerialDevice, pIrp);
}
Looking around on the net I found that IRPs for the function
IRP_MJ_POWER should use PoCallDriver() rather than IoCallDriver.
Of course this call isn’t in NT4 but I can live with that
(create two versions) if necessary. So I changed my dispatch
routine to look like:
NTSTATUS JCSerialFilterDispatch(PDEVICE_OBJECT pDeviceObject, PIRP pIrp)
{
PIO_STACK_LOCATION pIrpStkCur;
PIO_STACK_LOCATION pIrpStkNext;
PJCSERIAL_EXTENSION pDevExt =
(PJCSERIAL_EXTENSION)pDeviceObject->DeviceExtension;
USHORT nMajorFunction;
pIrpStkCur = IoGetCurrentIrpStackLocation(pIrp);
nMajorFunction = pIrpStkCur->MajorFunction;
#if WINVER >= 0x0500
if (nMajorFunction == IRP_MJ_POWER)
{
// Need to handle power IRPs in a special manner.
IoSkipCurrentIrpStackLocation(pIrp);
return PoCallDriver(pDevExt->pSerialDevice, pIrp);
}
#endif
/* @@ Eventually do other stuff here @@ */
pIrpStkNext = IoGetNextIrpStackLocation(pIrp);
*pIrpStkNext = *pIrpStkCur;
IoSetCompletionRoutine(pIrp, NULL, NULL, FALSE, FALSE, FALSE);
return IoCallDriver(pDevExt->pSerialDevice, pIrp);
}
Unfortunately this fails in the same manner. I set a
breakpoint on the IRP_MJ_POWER handler and it is called.
How should this situation be properly handled? I would
think that all legacy filter drivers would have this
problem but I can’t find a solution to this in DejaNews.
Dale