Hi,
On WDM, driver when it is about to complete an IRP, it can clear the cancel routine using:
IoAcquireCancelSpinLock(&CancelIrql);
IoSetCancelRoutine(pIrp, NULL);
IoReleaseCancelSpinLock(CancelIrql);
before calling CompleteRequest and take care of synchronizing cancel/complete operation.
How should this be acheived in KMDF code?
I see the following in WDK:
QUOTE
Windows Driver Kit: Kernel-Mode Driver Framework
Synchronizing Cancel and Completion Code
[This is preliminary documentation and subject to change.]
If your driver and device perform device I/O operations asynchronously by means of EvtInterruptIsr and EvtInterruptDpc callback functions, and if the driver calls WdfRequestMarkCancelable to make an I/O request cancelable, there is potential for a synchronization problem if both the EvtInterruptDpc and EvtRequestCancel callback functions contain calls to WdfRequestComplete.
The driver must call WdfRequestComplete only once, to either complete or cancel the request. But if the EvtInterruptDpc and EvtRequestCancel callback functions are not synchronized with each other, the framework can call one while the other is executing. Avoiding this problem is easy if your driver uses the framework’s automatic synchronization, which ensures that the callback functions will be called one at a time.
If the driver uses framework’s automatic synchronization, its EvtRequestCancel callback function can call WdfRequestComplete to cancel a request. The driver’s EvtInterruptDpc callback function should use the following code:
Status = WdfRequestUnmarkCancelable(Request);
if( Status != STATUS_CANCELLED ) {
WdfRequestComplete(Request, RequestStatus);
This code ensures that the driver does not call WdfRequestComplete to complete the request if the driver has already called it to cancel the request.
If your driver calls WdfRequestMarkCancelable to register an EvtRequestCancel callback function, and if your driver uses the framework’s automatic synchronization,
? 2005 Microsoft Corporation
Send feedback on this topic
Built on September 23, 2005
UNQUOTE
To make use of this automatic synchronization from framework, should I be specifying:
WdfSynchronizationScopeDevice?
Will that take care of resolving possible race condition b/w completion routine and cancel routine both being asynchronous?
At present I am using WdfSynchronizationScopeNone (not using any synchronization scope).
Regds,
-Praveen
Regds,
-Praveen