Hi All,
I have a test application for interaction with usb device using kmdf driver.
However when the application is running and if I remove the device, application crashes.
Error code receive at the application level says: event type: clr20r3, error is system.objectdisposedexception
I have observed the different behaviors at driver level, if Wait request is processed as given below:
If I complete the wait requests in evtiostop, application crashes (i.e. using WdfRequestComplete as show below code)
And, if I process this request in a regular way, stop and no re-queue (using wdfRequestStopAcknoweledge(Request, False)) application never crashes.
Below is evtiostop callback code, please advise any corrections required to avoid application crashing as well as wait event completion.
VOID vEvtIoStop( IN WDFQUEUE Queue, IN WDFREQUEST Request, IN ULONG ActionFlags )
{
PREQUEST_CONTEXT reqContext;
PDEVICE_EXTENSION deviceExtension = NULL;
//UNREFERENCED_PARAMETER(Queue);
deviceExtension = UsbGetDeviceExtension(WdfIoQueueGetDevice(Queue));
reqContext = UsbGetRequestContext(Request);
//clear the cancel routine
if ((ActionFlags & WdfRequestStopRequestCancelable) ) {
PFN_WDF_REQUEST_CANCEL cancelRoutine;
cancelRoutine = reqContext->CancelRoutine;
UsbClearCancelRoutine(Request, TRUE);
reqContext->CancelRoutine = cancelRoutine;
reqContext->MarkCancelableOnResume = TRUE;
ActionFlags &= ~WdfRequestStopRequestCancelable;
}
//complete the request if it is a wait request
if(deviceExtension->CurrentWaitRequest == Request) {
reqContext->MarkCancelableOnResume = FALSE;
reqContext->CancelRoutine = NULL;
reqContext = UsbGetRequestContext(deviceExtension->CurrentWaitRequest);
//reqContext->Information = sizeof(ULONG);
WdfRequestComplete(deviceExtension->CurrentWaitRequest, STATUS_SUCCESS);
deviceExtension->CurrentWaitRequest = NULL;
return;
}
//dont requeue
WdfRequestStopAcknowledge(Request, FALSE);
ActionFlags &= ~WdfRequestStopActionSuspend;
}
Thanks in Advance.