VOID
CancelRoutine(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp)
{
// Release the system-wide cancel spinlock ASAP
IoReleaseCancelSpinLock(Irp->CancelIrql);
// Dequeue the IRP from my CUSTOM queue (if it's still in the queue)
// ...
// Cancel the IRP
if (IrpWasInQueue)
{
IoSetCancelRoutine(Irp, NULL);
Irp->IoStatus.Status = STATUS_CANCELLED;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
}
}
By the way, I think there may be a typo in the docs for
IoSetCancelRoutine(), which mention the a IoSetCancelSpinLock() routine that
doesn't seem to exist.
As an aside you don't need to remove your cancel routine below in
cancelation as that should be done for you by the i/o manager before it
calls your routine. In fact this is a basic mechanism we use for
cancelation. We do atomic swaps on the cancel routine field of the IRP to
get the routine to call.
Neill.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Nate Bushman" <nate.bushman@NO_SPAAAMpowerquest.com> wrote in message
news:uKw0gz4UCHA.2716@tkmsftngp12...
Also, what is the proper behavior of the Cancel Routine if it doesn't find
the IRP in a queue (ie the IRP has been dequeued and may be in the process
of being dispatched). Should the Cancel Routine do nothing in this case,
and simply let the dispatching code complete the IRP?
"Neill Clift [MS]" <nei...@microsoft.com> wrote in message
news:3d753c8f$1...@news.microsoft.com...
Yes, that's what he meant. IoCancelIrp has already done this.
> Also, what is the proper behavior of the Cancel Routine if it doesn't find
> the IRP in a queue (ie the IRP has been dequeued and may be in the process
> of being dispatched). Should the Cancel Routine do nothing in this case,
> and simply let the dispatching code complete the IRP?
It's best to arrange matters so that the cancel routine always removes
the IRP from some queue and completes it. The DEVQUEUE code in my WDM
book (as modified by a long-ago service pack) appears to be bulletproof,
and I know that much of the same logic was incorporated (coincidentally
or not--and it doesn't matter) into the cancel-safe queue that's in the
XP DDK.
--
Walter Oney
Consulting and Training
http://www.oneysoft.com
Also, does this mean that in order to have a cancel safe queue, my code that
accesses the queue needs to use the system-wide cancel spinlock for
synchronization (acquiring/releasing the cancel spinlock when accessing the
queue), rather than just some spinlock that I've created?
"Walter Oney" <walt...@oneysoft.com> wrote in message
news:3D7637F8...@oneysoft.com...
Nate
"Nate Bushman" <nate.bushman@NO_SPAAAMpowerquest.com> wrote in message
news:uN5qMLQVCHA.3556@tkmsftngp08...
You're welcome, and thanks for the pat on the back. With the 9/11
anniversary coming up, I've been feeling pretty low...