2006-05-08 16:48:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Boiler plate for irp cancelation, for irp queues you manage yourself
|
|
|
|
-Gunnar
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CancelRoutine(
|
|
|
|
DEV_OBJ Dev,
|
|
|
|
Irp
|
|
|
|
)
|
|
|
|
{
|
|
|
|
//don't need this since we have our own sync. protecting irp cancellation
|
2021-09-13 01:33:14 +00:00
|
|
|
IoReleaseCancelSpinLock(Irp->CancelIrql);
|
|
|
|
|
2006-05-08 16:48:10 +00:00
|
|
|
theLock = Irp->Tail.Overlay.DriverContext[3];
|
2021-09-13 01:33:14 +00:00
|
|
|
|
|
|
|
Lock(theLock);
|
2006-05-08 16:48:10 +00:00
|
|
|
RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
|
|
|
|
Unlock(theLock);
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2006-05-08 16:48:10 +00:00
|
|
|
Irp->IoStatus.Status = STATUS_CANCELLED;
|
|
|
|
Irp->IoStatus.Information = 0;
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2006-05-08 16:48:10 +00:00
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2006-05-08 16:48:10 +00:00
|
|
|
}
|
2021-09-13 01:33:14 +00:00
|
|
|
|
|
|
|
|
2006-05-08 16:48:10 +00:00
|
|
|
QUEUE_BOLIERPLATE
|
|
|
|
{
|
|
|
|
Lock(theLock);
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2006-05-08 16:48:10 +00:00
|
|
|
Irp->Tail.Overlay.DriverContext[3] = &theLock;
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2006-05-08 16:48:10 +00:00
|
|
|
IoSetCancelRoutine(Irp, CancelRoutine);
|
|
|
|
if (Irp->Cancel && IoSetCancelRoutine(Irp, NULL))
|
2021-09-13 01:33:14 +00:00
|
|
|
{
|
2006-05-08 16:48:10 +00:00
|
|
|
/*
|
|
|
|
Irp has already been cancelled (before we got to queue it),
|
2021-09-13 01:33:14 +00:00
|
|
|
and we got to remove the cancel routine before the canceler could,
|
2006-05-08 16:48:10 +00:00
|
|
|
so we cancel/complete the irp ourself.
|
|
|
|
*/
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2006-05-08 16:48:10 +00:00
|
|
|
Unlock(theLock);
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2006-05-08 16:48:10 +00:00
|
|
|
Irp->IoStatus.Status = STATUS_CANCELLED;
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2006-05-08 16:48:10 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2021-09-13 01:33:14 +00:00
|
|
|
|
|
|
|
//else were ok
|
|
|
|
|
|
|
|
|
2006-05-08 16:48:10 +00:00
|
|
|
Irp->IoStatus.Status = STATUS_PENDING;
|
|
|
|
IoMarkIrpPending(Irp);
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2006-05-08 16:48:10 +00:00
|
|
|
InsertTailList(Queue);
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2006-05-08 16:48:10 +00:00
|
|
|
Unlock(theLock);
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2006-05-08 16:48:10 +00:00
|
|
|
}
|
2021-09-13 01:33:14 +00:00
|
|
|
|
|
|
|
|
2006-05-08 16:48:10 +00:00
|
|
|
DEQUEUE_BOILERPLATE
|
|
|
|
{
|
|
|
|
Lock(theLock);
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2006-05-08 16:48:10 +00:00
|
|
|
Irp = RemoveHeadList(Queue);
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2006-05-08 16:48:10 +00:00
|
|
|
if (!IoSetCancelRoutine(Irp, NULL))
|
|
|
|
{
|
|
|
|
/*
|
2021-09-13 01:33:14 +00:00
|
|
|
Cancel routine WILL be called after we release the spinlock. It will try to remove
|
|
|
|
the irp from the list and cancel/complete this irp. Since we allready removed it,
|
2006-05-08 16:48:10 +00:00
|
|
|
make its ListEntry point to itself.
|
|
|
|
*/
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2006-05-08 16:48:10 +00:00
|
|
|
InitializeListHead(&Irp->Tail.Overlay.ListEntry);
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2006-05-08 16:48:10 +00:00
|
|
|
Unlock(theLock);
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2006-05-08 16:48:10 +00:00
|
|
|
return;
|
2021-09-13 01:33:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-08 16:48:10 +00:00
|
|
|
/*
|
|
|
|
Cancel routine will NOT be called, canceled or not.
|
|
|
|
The Irp might have been canceled (Irp->Cancel flag set) but we don't care,
|
|
|
|
since we are to complete this Irp now anyways.
|
|
|
|
*/
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2006-05-08 16:48:10 +00:00
|
|
|
Unlock(theLock);
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2006-05-08 16:48:10 +00:00
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2006-05-08 16:48:10 +00:00
|
|
|
}
|