Commit db6c5b59 authored by Aric Stewart's avatar Aric Stewart Committed by Alexandre Julliard

winebus.sys: Improve unloading the winebus driver.

parent bfe48889
...@@ -22,6 +22,9 @@ typedef int(*enum_func)(DEVICE_OBJECT *device, void *context); ...@@ -22,6 +22,9 @@ typedef int(*enum_func)(DEVICE_OBJECT *device, void *context);
NTSTATUS WINAPI udev_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry_path) DECLSPEC_HIDDEN; NTSTATUS WINAPI udev_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry_path) DECLSPEC_HIDDEN;
NTSTATUS WINAPI iohid_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry_path) DECLSPEC_HIDDEN; NTSTATUS WINAPI iohid_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry_path) DECLSPEC_HIDDEN;
NTSTATUS WINAPI sdl_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry_path) DECLSPEC_HIDDEN; NTSTATUS WINAPI sdl_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry_path) DECLSPEC_HIDDEN;
void udev_driver_unload( void ) DECLSPEC_HIDDEN;
void iohid_driver_unload( void ) DECLSPEC_HIDDEN;
void sdl_driver_unload( void ) DECLSPEC_HIDDEN;
/* Native device function table */ /* Native device function table */
typedef struct typedef struct
......
...@@ -98,6 +98,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(plugplay); ...@@ -98,6 +98,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(plugplay);
static DRIVER_OBJECT *iohid_driver_obj = NULL; static DRIVER_OBJECT *iohid_driver_obj = NULL;
static IOHIDManagerRef hid_manager; static IOHIDManagerRef hid_manager;
static CFRunLoopRef run_loop;
static HANDLE run_loop_handle;
static const WCHAR busidW[] = {'I','O','H','I','D',0}; static const WCHAR busidW[] = {'I','O','H','I','D',0};
...@@ -372,7 +374,7 @@ static void handle_RemovalCallback(void *context, IOReturn result, void *sender, ...@@ -372,7 +374,7 @@ static void handle_RemovalCallback(void *context, IOReturn result, void *sender,
/* This puts the relevant run loop for event handling into a WINE thread */ /* This puts the relevant run loop for event handling into a WINE thread */
static DWORD CALLBACK runloop_thread(void *args) static DWORD CALLBACK runloop_thread(void *args)
{ {
CFRunLoopRef run_loop = CFRunLoopGetCurrent(); run_loop = CFRunLoopGetCurrent();
IOHIDManagerSetDeviceMatching(hid_manager, NULL); IOHIDManagerSetDeviceMatching(hid_manager, NULL);
IOHIDManagerRegisterDeviceMatchingCallback(hid_manager, handle_DeviceMatchingCallback, NULL); IOHIDManagerRegisterDeviceMatchingCallback(hid_manager, handle_DeviceMatchingCallback, NULL);
...@@ -388,18 +390,12 @@ static DWORD CALLBACK runloop_thread(void *args) ...@@ -388,18 +390,12 @@ static DWORD CALLBACK runloop_thread(void *args)
CFRunLoopRun(); CFRunLoopRun();
TRACE("Run Loop exiting\n"); TRACE("Run Loop exiting\n");
IOHIDManagerRegisterDeviceMatchingCallback(hid_manager, NULL, NULL);
IOHIDManagerRegisterDeviceRemovalCallback(hid_manager, NULL, NULL);
IOHIDManagerUnscheduleFromRunLoop(hid_manager, run_loop, kCFRunLoopDefaultMode);
CFRelease(hid_manager);
return 1; return 1;
} }
NTSTATUS WINAPI iohid_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry_path) NTSTATUS WINAPI iohid_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry_path)
{ {
HANDLE run_loop_handle;
TRACE("(%p, %s)\n", driver, debugstr_w(registry_path->Buffer)); TRACE("(%p, %s)\n", driver, debugstr_w(registry_path->Buffer));
iohid_driver_obj = driver; iohid_driver_obj = driver;
...@@ -414,10 +410,25 @@ NTSTATUS WINAPI iohid_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registr ...@@ -414,10 +410,25 @@ NTSTATUS WINAPI iohid_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registr
return STATUS_UNSUCCESSFUL; return STATUS_UNSUCCESSFUL;
} }
CloseHandle(run_loop_handle);
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
void iohid_driver_unload( void )
{
TRACE("Unloading Driver\n");
if (iohid_driver_obj != NULL)
{
IOHIDManagerUnscheduleFromRunLoop(hid_manager, run_loop, kCFRunLoopDefaultMode);
CFRunLoopStop(run_loop);
WaitForSingleObject(run_loop_handle, INFINITE);
CloseHandle(run_loop_handle);
IOHIDManagerRegisterDeviceMatchingCallback(hid_manager, NULL, NULL);
IOHIDManagerRegisterDeviceRemovalCallback(hid_manager, NULL, NULL);
CFRelease(hid_manager);
}
TRACE("Driver Unloaded\n");
}
#else #else
NTSTATUS WINAPI iohid_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry_path) NTSTATUS WINAPI iohid_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry_path)
...@@ -426,4 +437,9 @@ NTSTATUS WINAPI iohid_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registr ...@@ -426,4 +437,9 @@ NTSTATUS WINAPI iohid_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registr
return STATUS_NOT_IMPLEMENTED; return STATUS_NOT_IMPLEMENTED;
} }
void iohid_driver_unload( void )
{
TRACE("Stub: Unload Driver\n");
}
#endif /* HAVE_IOHIDMANAGERCREATE */ #endif /* HAVE_IOHIDMANAGERCREATE */
...@@ -927,6 +927,11 @@ static DWORD CALLBACK deviceloop_thread(void *args) ...@@ -927,6 +927,11 @@ static DWORD CALLBACK deviceloop_thread(void *args)
return 0; return 0;
} }
void sdl_driver_unload( void )
{
TRACE("Unload Driver\n");
}
NTSTATUS WINAPI sdl_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry_path) NTSTATUS WINAPI sdl_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry_path)
{ {
static const WCHAR controller_modeW[] = {'M','a','p',' ','C','o','n','t','r','o','l','l','e','r','s',0}; static const WCHAR controller_modeW[] = {'M','a','p',' ','C','o','n','t','r','o','l','l','e','r','s',0};
...@@ -1023,4 +1028,9 @@ NTSTATUS WINAPI sdl_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry_ ...@@ -1023,4 +1028,9 @@ NTSTATUS WINAPI sdl_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry_
return STATUS_NOT_IMPLEMENTED; return STATUS_NOT_IMPLEMENTED;
} }
void sdl_driver_unload( void )
{
TRACE("Stub: Unload Driver\n");
}
#endif /* SONAME_LIBSDL2 */ #endif /* SONAME_LIBSDL2 */
...@@ -1418,6 +1418,11 @@ static DWORD CALLBACK deviceloop_thread(void *args) ...@@ -1418,6 +1418,11 @@ static DWORD CALLBACK deviceloop_thread(void *args)
return 0; return 0;
} }
void udev_driver_unload( void )
{
TRACE("Unload Driver\n");
}
NTSTATUS WINAPI udev_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry_path) NTSTATUS WINAPI udev_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry_path)
{ {
HANDLE events[2]; HANDLE events[2];
...@@ -1482,4 +1487,9 @@ NTSTATUS WINAPI udev_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry ...@@ -1482,4 +1487,9 @@ NTSTATUS WINAPI udev_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry
return STATUS_NOT_IMPLEMENTED; return STATUS_NOT_IMPLEMENTED;
} }
void udev_driver_unload( void )
{
TRACE("Stub: Unload Driver\n");
}
#endif /* HAVE_UDEV */ #endif /* HAVE_UDEV */
...@@ -699,6 +699,13 @@ BOOL is_xbox_gamepad(WORD vid, WORD pid) ...@@ -699,6 +699,13 @@ BOOL is_xbox_gamepad(WORD vid, WORD pid)
return FALSE; return FALSE;
} }
static void WINAPI driver_unload(DRIVER_OBJECT *driver)
{
udev_driver_unload();
iohid_driver_unload();
sdl_driver_unload();
}
NTSTATUS WINAPI DriverEntry( DRIVER_OBJECT *driver, UNICODE_STRING *path ) NTSTATUS WINAPI DriverEntry( DRIVER_OBJECT *driver, UNICODE_STRING *path )
{ {
static const WCHAR udevW[] = {'\\','D','r','i','v','e','r','\\','U','D','E','V',0}; static const WCHAR udevW[] = {'\\','D','r','i','v','e','r','\\','U','D','E','V',0};
...@@ -720,5 +727,7 @@ NTSTATUS WINAPI DriverEntry( DRIVER_OBJECT *driver, UNICODE_STRING *path ) ...@@ -720,5 +727,7 @@ NTSTATUS WINAPI DriverEntry( DRIVER_OBJECT *driver, UNICODE_STRING *path )
IoCreateDriver(&udev, udev_driver_init); IoCreateDriver(&udev, udev_driver_init);
IoCreateDriver(&iohid, iohid_driver_init); IoCreateDriver(&iohid, iohid_driver_init);
driver->DriverUnload = driver_unload;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment