|
From: Stephan M. <ste...@we...> - 2007-06-14 17:41:37
|
Hi Dan, thanks a lot for your patch. I applied it as follows: * I added a 'file_object' parameter to the claim/release functions and moved your code to these functions * I removed the redundant 'interface.claimed' struct member * I also removed the 'dev.ref_count' member since it's not needed any more You'll find my changes in the SVN: http://libusb-win32.svn.sourceforge.net/viewvc/libusb-win32/trunk/libusb/ The code still passes all of my unit-test so I'm quite confident that my modifications didn't break anything. Please let me know is anything doesn't work as expected. Stephan > > This is the patch we've come up with to handle multiple interfaces from > different processes properly, and the releasing thereof if a dying > process fails to call release_interface (svn revisions our from our own > tree): > > Index: C:/Projects/software/libusb/win32/src/driver/dispatch.c > =================================================================== > --- C:/Projects/software/libusb/win32/src/driver/dispatch.c (revision > 6445) > +++ C:/Projects/software/libusb/win32/src/driver/dispatch.c (revision > 6446) > @@ -71,13 +71,28 @@ > } > > case IRP_MJ_CLOSE: > + { > + int i; > > - if(!InterlockedDecrement(&dev->ref_count)) > - { > - /* release all interfaces when the last handle is closed */ > - release_all_interfaces(dev); > - } > - return complete_irp(irp, STATUS_SUCCESS, 0); > + if(!InterlockedDecrement(&dev->ref_count)) > + { > + /* release all interfaces when the last handle is closed */ > + release_all_interfaces(dev); > + } > + else > + { > + /* release all interfaces that were connected with the > handle */ > + for(i = 0; i < LIBUSB_MAX_NUMBER_OF_INTERFACES; i++) > + { > + > if((ULONG_PTR)IoGetCurrentIrpStackLocation(irp)->FileObject == > + dev->config.interfaces[i].file_object) > + { > + release_interface(dev, i); > + } > + } > + } > + return complete_irp(irp, STATUS_SUCCESS, 0); > + } > > case IRP_MJ_CLEANUP: > > Index: C:/Projects/software/libusb/win32/src/driver/release_interface.c > =================================================================== > --- C:/Projects/software/libusb/win32/src/driver/release_interface.c > (revision 6445) > +++ C:/Projects/software/libusb/win32/src/driver/release_interface.c > (revision 6446) > @@ -52,6 +52,7 @@ > } > > dev->config.interfaces[interface].claimed = FALSE; > + dev->config.interfaces[interface].file_object = (ULONG_PTR)NULL; > > return STATUS_SUCCESS; > } > @@ -63,6 +64,7 @@ > for(i = 0; i < LIBUSB_MAX_NUMBER_OF_INTERFACES; i++) > { > dev->config.interfaces[i].claimed = FALSE; > + dev->config.interfaces[i].file_object = (ULONG_PTR)NULL; > } > > return STATUS_SUCCESS; > Index: C:/Projects/software/libusb/win32/src/driver/libusb_driver.h > =================================================================== > --- C:/Projects/software/libusb/win32/src/driver/libusb_driver.h > (revision 6445) > +++ C:/Projects/software/libusb/win32/src/driver/libusb_driver.h > (revision 6446) > @@ -116,6 +116,7 @@ > { > int valid; > int claimed; > + ULONG_PTR file_object; > libusb_endpoint_t endpoints[LIBUSB_MAX_NUMBER_OF_ENDPOINTS]; > } libusb_interface_t; > > Index: C:/Projects/software/libusb/win32/src/driver/ioctl.c > =================================================================== > --- C:/Projects/software/libusb/win32/src/driver/ioctl.c (revision 6445) > +++ C:/Projects/software/libusb/win32/src/driver/ioctl.c (revision 6446) > @@ -285,6 +285,18 @@ > > case LIBUSB_IOCTL_CLAIM_INTERFACE: > status = claim_interface(dev, request->interface.interface); > + > + /* add FileObject tracing to release the interface in the future, */ > + /* when its handle will be closed */ > + if (NT_SUCCESS(status)) > + { > + > dev->config.interfaces[request->interface.interface].file_object = > + (ULONG_PTR)stack_location->FileObject; > + } > + else > + { > + > dev->config.interfaces[request->interface.interface].file_object = > (ULONG_PTR)NULL; > + } > break; > > case LIBUSB_IOCTL_RELEASE_INTERFACE: > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Libusb-win32-devel mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel > _____________________________________________________________________ Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! http://smartsurfer.web.de/?mc=100071&distributionid=000000000066 |