daynix / UsbDk

Usb Drivers Development Kit for Windows
Apache License 2.0
553 stars 142 forks source link

Refcount redirection close #106

Open kvojacheck opened 3 years ago

kvojacheck commented 3 years ago

Proposed reference counting workaround to issue #105 Please kindly review, since I'm quite new to Windows driver developement.

ybendito commented 3 years ago

@kvojacheck What happens in following flow: app1 redirects the device and uses it, app2 opens the device and closes it? as pid == 0 means 'match all' will this stop the redirection?

ybendito commented 3 years ago

Probably the proper thing is to use file context (WDFFILECONTEXT) instead of process identifier

kvojacheck commented 3 years ago

@kvojacheck What happens in following flow: app1 redirects the device and uses it, app2 opens the device and closes it? as pid == 0 means 'match all' will this stop the redirection?

At the time app2 closes the device, the refcount is still 1 (since app1 is still using the device), therefore we would go to the PID-based identification as before: as the returned PID value by PsGetCurrentProcessId is likely corresponds to app2 (and most likely not app1), the closure of app2 wouldn't cause the removal of the redirection.

kvojacheck commented 3 years ago

Probably the proper thing is to use file context (WDFFILECONTEXT) instead of process identifier

Thank you for the tip, I will definitely look into this!