I have an FSD (file system driver and not filter driver) that responds to special FSCTL (
IRP_MJ_FILE_SYSTEM_CONTROL) requests. The driver uses a variant of
FsRtlCancellableWaitForSingleObject to perform a cancellable wait on a kernel object and the FSCTL IRP.
I now have a second driver that wishes to send an FSCTL IRP to the FSD and a requirement that this must be done in a manner so that
CancelSynchronousIo is functional. My question is: how should I build the IRP so that it can be cancelled with
At first I built the FSCTL IRP using
IoAllocateIrp. This method does not create a threaded IRP and therefore cannot be canceled with
CancelSynchronousIo. (There is
IoQueueThreadIrp but it is reserved for system use.)
Now I am using
IoBuildDeviceIoControlRequest and patch the returned IRP fields with
IRP_MN_KERNEL_CALL, etc. because
IRP_MJ_DEVICE_CONTROL IRP's. This creates a threaded IRP (confirmed with
CancelSynchronousIo still cannot cancel the IRP.
The problem is that although the internal
IopCancelIrpsInCurrentThreadListSpecialApc finds the IRP in the thread's
IrpList, the IRP is not marked
IRP_SYNCHRONOUS_API and is therefore ignored. My obvious next move is to add that bit to
Irp->Flags, but I am beginning to wonder if I should not be doing what I am doing.
I appreciate any advice you may have on the subject. If your advice is "don't do that" I would love to hear alternatives.
PS: I have wondered in the past how an IRP passed to
FsRtlCancellableWaitForSingleObject can be cancelled if there is no cancellation routine on it. Turns out that
IopCancelIrpsInCurrentThreadListSpecialApc first sets
Irp->Cancel and then alerts the thread with
KeAlertThread. This wakes up the alertable
FsRtlCancellableWaitForSingleObject, which then checks
Irp->Cancel. Mystery solved.
It looks like you're new here. If you want to get involved, click one of these buttons!
|Upcoming OSR Seminars|
|Writing WDF Drivers||21 Oct 2019||OSR Seminar Space & ONLINE|
|Internals & Software Drivers||18 Nov 2019||Dulles, VA|
|Kernel Debugging||30 Mar 2020||OSR Seminar Space|
|Developing Minifilters||27 Apr 2020||OSR Seminar Space & ONLINE|