evtiostop crashes application

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.

The bug is in the application code.

Thanks Alex, I know this exception can be handled even at application level.
However, if I perform “WdfRequestStopAcknowledge(Request, FALSE)” on the same wait request (currently I am completing this request using WdfRequestComplete API) this crash is not occurring.

Wondering, what difference it makes to this application? Does WdfRequestStopAcknowledge completes this request as status_cancelled back to the application?

while other application is running, I perform PC stand-by and completing this wait request (using WdfRequestComplete) so as to get wait events again from coming back from PC Standby recovery.

If I dont complete wait request and instead perform WdfRequestStopAcknowledge, then after standby recovery, the resumed application doesn’t work properly, as last wait request it sent is not completed.
How to overcome this situation?

once the request is queued and pending has been returned to the app, evtiostop is transparent to the app. The only thing evtiostop can do that the app sees is to complete the request. The app is dying because it has a bug, mist like a race condition bug around io completion. Also around I am guessing unpinning resources too soon and letting them be disposed before the io actually completes

d

debt from my phone


From: xxxxx@gmail.com
Sent: 11/17/2011 10:54 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] evtiostop crashes application

Thanks Alex, I know this exception can be handled even at application level.
However, if I perform “WdfRequestStopAcknowledge(Request, FALSE)” on the same wait request (currently I am completing this request using WdfRequestComplete API) this crash is not occurring.

Wondering, what difference it makes to this application? Does WdfRequestStopAcknowledge completes this request as status_cancelled back to the application?

while other application is running, I perform PC stand-by and completing this wait request (using WdfRequestComplete) so as to get wait events again from coming back from PC Standby recovery.

If I dont complete wait request and instead perform WdfRequestStopAcknowledge, then after standby recovery, the resumed application doesn’t work properly, as last wait request it sent is not completed.
How to overcome this situation?


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Thanks Doron,

Also around I am guessing unpinning resources too soon and letting them be disposed before the io actually completes

I observed the callback order when device is removed case as below:
1.SurpriseRemoved
2.EvtIoStop
3.D0Exit
4.ReleaseHw
And I was completing this wait in EvtIoStop (2) and application used to crash,
now the same wait if completed in SurpriseRemoved callback (1) application is not crashing!
Not able to find difference it makes to the app, if wait is completed one step above?

One more observation: Using irptracker, I was able to see application never gets any completion status when device is removed for the last wait request (if the wait is processed as WdfRequestStopAcknowledge, false in evtiostop).

Have you spent as much time debugging the app which is where you really need to make the fix?

d

debt from my phone


From: xxxxx@gmail.com
Sent: 11/18/2011 3:33 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] evtiostop crashes application

Thanks Doron,

Also around I am guessing unpinning resources too soon and letting them be disposed before the io actually completes

I observed the callback order when device is removed case as below:
1.SurpriseRemoved
2.EvtIoStop
3.D0Exit
4.ReleaseHw
And I was completing this wait in EvtIoStop (2) and application used to crash,
now the same wait if completed in SurpriseRemoved callback (1) application is not crashing!
Not able to find difference it makes to the app, if wait is completed one step above?

One more observation: Using irptracker, I was able to see application never gets any completion status when device is removed for the last wait request (if the wait is processed as WdfRequestStopAcknowledge, false in evtiostop).


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer