Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/Makefile.in | 3 ++- dlls/winebus.sys/main.c | 9 ++++++++ dlls/winebus.sys/unixlib.c | 45 ++++++++++++++++++++++++++++++++++++ dlls/winebus.sys/unixlib.h | 34 +++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 dlls/winebus.sys/unixlib.c create mode 100644 dlls/winebus.sys/unixlib.h
diff --git a/dlls/winebus.sys/Makefile.in b/dlls/winebus.sys/Makefile.in index 8cde3c7b422..658d27b70fd 100644 --- a/dlls/winebus.sys/Makefile.in +++ b/dlls/winebus.sys/Makefile.in @@ -9,6 +9,7 @@ C_SRCS = \ bus_sdl.c \ bus_udev.c \ hid.c \ - main.c + main.c \ + unixlib.c
RC_SRCS = winebus.rc diff --git a/dlls/winebus.sys/main.c b/dlls/winebus.sys/main.c index e372ec6db3f..fe0f6dc60cc 100644 --- a/dlls/winebus.sys/main.c +++ b/dlls/winebus.sys/main.c @@ -34,10 +34,14 @@ #include "wine/list.h"
#include "bus.h" +#include "unixlib.h"
WINE_DEFAULT_DEBUG_CHANNEL(plugplay); WINE_DECLARE_DEBUG_CHANNEL(hid_report);
+static HMODULE instance; +static struct unix_funcs *unix_funcs; + #if defined(__i386__) && !defined(_WIN32)
extern void * WINAPI wrap_fastcall_func1( void *func, const void *a ); @@ -1071,6 +1075,7 @@ static NTSTATUS WINAPI driver_add_device(DRIVER_OBJECT *driver, DEVICE_OBJECT *p
static void WINAPI driver_unload(DRIVER_OBJECT *driver) { + __wine_init_unix_lib(instance, DLL_PROCESS_DETACH, NULL, NULL); NtClose(driver_key); }
@@ -1081,6 +1086,10 @@ NTSTATUS WINAPI DriverEntry( DRIVER_OBJECT *driver, UNICODE_STRING *path )
TRACE( "(%p, %s)\n", driver, debugstr_w(path->Buffer) );
+ RtlPcToFileHeader(&DriverEntry, (void *)&instance); + if ((ret = __wine_init_unix_lib(instance, DLL_PROCESS_ATTACH, NULL, &unix_funcs))) + return ret; + attr.Length = sizeof(attr); attr.ObjectName = path; attr.Attributes = OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE; diff --git a/dlls/winebus.sys/unixlib.c b/dlls/winebus.sys/unixlib.c new file mode 100644 index 00000000000..1be740b34b8 --- /dev/null +++ b/dlls/winebus.sys/unixlib.c @@ -0,0 +1,45 @@ +/* + * Copyright 2021 Rémi Bernon for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "config.h" + +#include <stdarg.h> +#include "ntstatus.h" +#define WIN32_NO_STATUS +#include "windef.h" +#include "winbase.h" +#include "winternl.h" + +#include "wine/debug.h" + +#include "unixlib.h" + +WINE_DEFAULT_DEBUG_CHANNEL(plugplay); + +static const struct unix_funcs unix_funcs = +{ +}; + +NTSTATUS CDECL __wine_init_unix_lib(HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out) +{ + TRACE("module %p, reason %u, ptr_in %p, ptr_out %p\n", module, reason, ptr_in, ptr_out); + + if (reason != DLL_PROCESS_ATTACH) return STATUS_SUCCESS; + *(const struct unix_funcs **)ptr_out = &unix_funcs; + return STATUS_SUCCESS; +} diff --git a/dlls/winebus.sys/unixlib.h b/dlls/winebus.sys/unixlib.h new file mode 100644 index 00000000000..c220629ea87 --- /dev/null +++ b/dlls/winebus.sys/unixlib.h @@ -0,0 +1,34 @@ +/* + * Copyright 2021 Rémi Bernon for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef __WINEBUS_UNIXLIB_H +#define __WINEBUS_UNIXLIB_H + +#include <stdarg.h> + +#include <windef.h> +#include <winbase.h> +#include <winternl.h> +#include <ddk/wdm.h> +#include <hidusage.h> + +struct unix_funcs +{ +}; + +#endif /* __WINEBUS_UNIXLIB_H */
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus.h | 2 - dlls/winebus.sys/bus_sdl.c | 142 +++++++++++++------------------- dlls/winebus.sys/main.c | 115 ++++++++++++++++++++------ dlls/winebus.sys/unix_private.h | 34 ++++++++ dlls/winebus.sys/unixlib.c | 5 +- dlls/winebus.sys/unixlib.h | 8 ++ 6 files changed, 192 insertions(+), 114 deletions(-) create mode 100644 dlls/winebus.sys/unix_private.h
diff --git a/dlls/winebus.sys/bus.h b/dlls/winebus.sys/bus.h index 3e53b9c53f1..2c2d26a1525 100644 --- a/dlls/winebus.sys/bus.h +++ b/dlls/winebus.sys/bus.h @@ -30,10 +30,8 @@ typedef int(*enum_func)(DEVICE_OBJECT *device, void *context); /* Buses */ NTSTATUS udev_driver_init(void) DECLSPEC_HIDDEN; NTSTATUS iohid_driver_init(void) DECLSPEC_HIDDEN; -NTSTATUS sdl_driver_init(void) 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 */ typedef struct diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c index 84e3ef20664..0cec6e4d981 100644 --- a/dlls/winebus.sys/bus_sdl.c +++ b/dlls/winebus.sys/bus_sdl.c @@ -52,18 +52,19 @@
#include "bus.h"
+#include "unix_private.h" + WINE_DEFAULT_DEBUG_CHANNEL(plugplay);
#ifdef SONAME_LIBSDL2
WINE_DECLARE_DEBUG_CHANNEL(hid_report);
-static const WCHAR sdl_busidW[] = {'S','D','L','J','O','Y',0}; +static struct sdl_bus_options options;
-static DWORD map_controllers = 0; +static const WCHAR sdl_busidW[] = {'S','D','L','J','O','Y',0};
static void *sdl_handle = NULL; -static HANDLE deviceloop_handle; static UINT quit_event = -1;
#define MAKE_FUNCPTR(f) static typeof(f) * p##f = NULL @@ -748,7 +749,7 @@ static void try_add_device(unsigned int index) return; }
- if (map_controllers && pSDL_IsGameController(index)) + if (options.map_controllers && pSDL_IsGameController(index)) controller = pSDL_GameControllerOpen(index);
id = pSDL_JoystickInstanceID(joystick); @@ -889,68 +890,32 @@ static void sdl_load_mappings(void) } }
-static DWORD CALLBACK deviceloop_thread(void *args) +NTSTATUS WINAPI sdl_bus_stop(void) { - HANDLE init_done = args; SDL_Event event;
- if (pSDL_Init(SDL_INIT_GAMECONTROLLER|SDL_INIT_HAPTIC) < 0) + if (!sdl_handle) return STATUS_SUCCESS; + + event.type = quit_event; + if (pSDL_PushEvent(&event) != 1) { - ERR("Can't init SDL: %s\n", pSDL_GetError()); + ERR("error pushing quit event\n"); return STATUS_UNSUCCESSFUL; }
- pSDL_JoystickEventState(SDL_ENABLE); - pSDL_GameControllerEventState(SDL_ENABLE); - - /* Process mappings */ - if (pSDL_GameControllerAddMapping != NULL) sdl_load_mappings(); - - SetEvent(init_done); - - while (1) { - while (pSDL_WaitEvent(&event) != 0) { - if (event.type == quit_event) { - TRACE("Device thread exiting\n"); - return 0; - } - process_device_event(&event); - } - } + return STATUS_SUCCESS; }
-void sdl_driver_unload( void ) +NTSTATUS WINAPI sdl_bus_init(void *args) { - SDL_Event event; + TRACE("args %p\n", args);
- TRACE("Unload Driver\n"); + options = *(struct sdl_bus_options *)args;
- if (!deviceloop_handle) - return; - - quit_event = pSDL_RegisterEvents(1); - if (quit_event == -1) { - ERR("error registering quit event\n"); - return; - } - - event.type = quit_event; - if (pSDL_PushEvent(&event) != 1) { - ERR("error pushing quit event\n"); - return; - } - - WaitForSingleObject(deviceloop_handle, INFINITE); - CloseHandle(deviceloop_handle); - dlclose(sdl_handle); -} - -static BOOL sdl_initialize(void) -{ if (!(sdl_handle = dlopen(SONAME_LIBSDL2, RTLD_NOW))) { WARN("could not load %s\n", SONAME_LIBSDL2); - return FALSE; + return STATUS_UNSUCCESSFUL; } #define LOAD_FUNCPTR(f) \ if ((p##f = dlsym(sdl_handle, #f)) == NULL) \ @@ -1000,63 +965,66 @@ static BOOL sdl_initialize(void) pSDL_JoystickGetProduct = dlsym(sdl_handle, "SDL_JoystickGetProduct"); pSDL_JoystickGetProductVersion = dlsym(sdl_handle, "SDL_JoystickGetProductVersion"); pSDL_JoystickGetVendor = dlsym(sdl_handle, "SDL_JoystickGetVendor"); - return TRUE; + + if (pSDL_Init(SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC) < 0) + { + ERR("could not init SDL: %s\n", pSDL_GetError()); + goto failed; + } + + if ((quit_event = pSDL_RegisterEvents(1)) == -1) + { + ERR("error registering quit event\n"); + goto failed; + } + + pSDL_JoystickEventState(SDL_ENABLE); + pSDL_GameControllerEventState(SDL_ENABLE); + + /* Process mappings */ + if (pSDL_GameControllerAddMapping != NULL) sdl_load_mappings(); + return STATUS_SUCCESS;
failed: dlclose(sdl_handle); sdl_handle = NULL; - return FALSE; + return STATUS_UNSUCCESSFUL; }
-NTSTATUS sdl_driver_init(void) +NTSTATUS WINAPI sdl_bus_wait(void) { - static const WCHAR controller_modeW[] = {'M','a','p',' ','C','o','n','t','r','o','l','l','e','r','s',0}; - static const UNICODE_STRING controller_mode = {sizeof(controller_modeW) - sizeof(WCHAR), sizeof(controller_modeW), (WCHAR*)controller_modeW}; - - HANDLE events[2]; - DWORD result; - - if (!sdl_handle && !sdl_initialize()) return STATUS_UNSUCCESSFUL; - - map_controllers = check_bus_option(&controller_mode, 1); - - if (!(events[0] = CreateEventW(NULL, TRUE, FALSE, NULL))) - { - WARN("CreateEvent failed\n"); - return STATUS_UNSUCCESSFUL; - } - if (!(events[1] = CreateThread(NULL, 0, deviceloop_thread, events[0], 0, NULL))) - { - WARN("CreateThread failed\n"); - CloseHandle(events[0]); - return STATUS_UNSUCCESSFUL; - } + SDL_Event event;
- result = WaitForMultipleObjects(2, events, FALSE, INFINITE); - CloseHandle(events[0]); - if (result == WAIT_OBJECT_0) + do { - TRACE("Initialization successful\n"); - deviceloop_handle = events[1]; - return STATUS_SUCCESS; - } - CloseHandle(events[1]); + if (pSDL_WaitEvent(&event) != 0) process_device_event(&event); + else WARN("SDL_WaitEvent failed: %s\n", pSDL_GetError()); + } while (event.type != quit_event);
+ TRACE("SDL main loop exiting\n"); dlclose(sdl_handle); sdl_handle = NULL; - return STATUS_UNSUCCESSFUL; + return STATUS_SUCCESS; }
#else
-NTSTATUS sdl_driver_init(void) +NTSTATUS WINAPI sdl_bus_init(void *args) { + WARN("SDL support not compiled in!\n"); return STATUS_NOT_IMPLEMENTED; }
-void sdl_driver_unload( void ) +NTSTATUS WINAPI sdl_bus_wait(void) { - TRACE("Stub: Unload Driver\n"); + WARN("SDL support not compiled in!\n"); + return STATUS_NOT_IMPLEMENTED; +} + +NTSTATUS WINAPI sdl_bus_stop(void) +{ + WARN("SDL support not compiled in!\n"); + return STATUS_NOT_IMPLEMENTED; }
#endif /* SONAME_LIBSDL2 */ diff --git a/dlls/winebus.sys/main.c b/dlls/winebus.sys/main.c index fe0f6dc60cc..a4b236cecb7 100644 --- a/dlls/winebus.sys/main.c +++ b/dlls/winebus.sys/main.c @@ -408,6 +408,20 @@ static NTSTATUS build_device_relations(DEVICE_RELATIONS **devices) return STATUS_SUCCESS; }
+DWORD check_bus_option(const UNICODE_STRING *option, DWORD default_value) +{ + char buffer[FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data[sizeof(DWORD)])]; + KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer; + DWORD size; + + if (NtQueryValueKey(driver_key, option, KeyValuePartialInformation, info, sizeof(buffer), &size) == STATUS_SUCCESS) + { + if (info->Type == REG_DWORD) return *(DWORD *)info->Data; + } + + return default_value; +} + static NTSTATUS handle_IRP_MN_QUERY_DEVICE_RELATIONS(IRP *irp) { NTSTATUS status = irp->IoStatus.Status; @@ -622,6 +636,75 @@ static void keyboard_device_create(void) IoInvalidateDeviceRelations(bus_pdo, BusRelations); }
+static DWORD bus_count; +static HANDLE bus_thread[16]; + +struct bus_main_params +{ + const WCHAR *name; + HANDLE init; + + NTSTATUS (WINAPI *bus_init)(void *args); + NTSTATUS (WINAPI *bus_wait)(void); + void *bus_params; +}; + +static DWORD CALLBACK bus_main_thread(void *args) +{ + struct bus_main_params bus = *(struct bus_main_params *)args; + NTSTATUS status; + + TRACE("%s main loop starting\n", debugstr_w(bus.name)); + status = bus.bus_init(bus.bus_params); + SetEvent(bus.init); + TRACE("%s main loop started\n", debugstr_w(bus.name)); + + if (status) WARN("%s bus init returned status %#x\n", debugstr_w(bus.name), status); + else while ((status = bus.bus_wait()) == STATUS_PENDING) {} + + if (status) WARN("%s bus wait returned status %#x\n", debugstr_w(bus.name), status); + else TRACE("%s main loop exited\n", debugstr_w(bus.name)); + return status; +} + +static NTSTATUS sdl_driver_init(void) +{ + static const WCHAR sdl_bus_name[] = {'S','D','L',0}; + static const WCHAR controller_modeW[] = {'M','a','p',' ','C','o','n','t','r','o','l','l','e','r','s',0}; + static const UNICODE_STRING controller_mode = {sizeof(controller_modeW) - sizeof(WCHAR), sizeof(controller_modeW), (WCHAR*)controller_modeW}; + struct sdl_bus_options sdl_params; + struct bus_main_params params = + { + .name = sdl_bus_name, + .bus_init = unix_funcs->sdl_bus_init, + .bus_wait = unix_funcs->sdl_bus_wait, + .bus_params = &sdl_params, + }; + DWORD i = bus_count++; + + if (!(params.init = CreateEventW(NULL, FALSE, FALSE, NULL))) + { + ERR("failed to create SDL bus event.\n"); + bus_count--; + return STATUS_UNSUCCESSFUL; + } + + sdl_params.map_controllers = check_bus_option(&controller_mode, 1); + if (!sdl_params.map_controllers) TRACE("SDL controller to XInput HID gamepad mapping disabled\n"); + + if (!(bus_thread[i] = CreateThread(NULL, 0, bus_main_thread, ¶ms, 0, NULL))) + { + ERR("failed to create SDL bus thread.\n"); + CloseHandle(params.init); + bus_count--; + return STATUS_UNSUCCESSFUL; + } + + WaitForSingleObject(params.init, INFINITE); + CloseHandle(params.init); + return STATUS_SUCCESS; +} + static NTSTATUS fdo_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp) { static const WCHAR SDL_enabledW[] = {'E','n','a','b','l','e',' ','S','D','L',0}; @@ -638,16 +721,12 @@ static NTSTATUS fdo_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp) mouse_device_create(); keyboard_device_create();
- if (check_bus_option(&SDL_enabled, 1)) + if (!check_bus_option(&SDL_enabled, 1) || sdl_driver_init()) { - if (sdl_driver_init() == STATUS_SUCCESS) - { - irp->IoStatus.Status = STATUS_SUCCESS; - break; - } + udev_driver_init(); + iohid_driver_init(); } - udev_driver_init(); - iohid_driver_init(); + irp->IoStatus.Status = STATUS_SUCCESS; break; case IRP_MN_SURPRISE_REMOVAL: @@ -656,7 +735,10 @@ static NTSTATUS fdo_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp) case IRP_MN_REMOVE_DEVICE: udev_driver_unload(); iohid_driver_unload(); - sdl_driver_unload(); + unix_funcs->sdl_bus_stop(); + + WaitForMultipleObjects(bus_count, bus_thread, TRUE, INFINITE); + while (bus_count--) CloseHandle(bus_thread[bus_count]);
irp->IoStatus.Status = STATUS_SUCCESS; IoSkipCurrentIrpStackLocation(irp); @@ -1025,21 +1107,6 @@ void process_hid_report(DEVICE_OBJECT *device, BYTE *report, DWORD length) LeaveCriticalSection(&ext->cs); }
-DWORD check_bus_option(const UNICODE_STRING *option, DWORD default_value) -{ - char buffer[FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data[sizeof(DWORD)])]; - KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION*)buffer; - DWORD size; - - if (NtQueryValueKey(driver_key, option, KeyValuePartialInformation, info, sizeof(buffer), &size) == STATUS_SUCCESS) - { - if (info->Type == REG_DWORD) - return *(DWORD*)info->Data; - } - - return default_value; -} - BOOL is_xbox_gamepad(WORD vid, WORD pid) { int i; diff --git a/dlls/winebus.sys/unix_private.h b/dlls/winebus.sys/unix_private.h new file mode 100644 index 00000000000..7ac882a03b2 --- /dev/null +++ b/dlls/winebus.sys/unix_private.h @@ -0,0 +1,34 @@ +/* + * Copyright 2021 Rémi Bernon for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef __WINEBUS_UNIX_PRIVATE_H +#define __WINEBUS_UNIX_PRIVATE_H + +#include <stdarg.h> + +#include <windef.h> +#include <winbase.h> +#include <winternl.h> + +#include "unixlib.h" + +extern NTSTATUS WINAPI sdl_bus_init(void *args) DECLSPEC_HIDDEN; +extern NTSTATUS WINAPI sdl_bus_wait(void) DECLSPEC_HIDDEN; +extern NTSTATUS WINAPI sdl_bus_stop(void) DECLSPEC_HIDDEN; + +#endif /* __WINEBUS_UNIX_PRIVATE_H */ diff --git a/dlls/winebus.sys/unixlib.c b/dlls/winebus.sys/unixlib.c index 1be740b34b8..832a20372d6 100644 --- a/dlls/winebus.sys/unixlib.c +++ b/dlls/winebus.sys/unixlib.c @@ -27,12 +27,15 @@
#include "wine/debug.h"
-#include "unixlib.h" +#include "unix_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(plugplay);
static const struct unix_funcs unix_funcs = { + sdl_bus_init, + sdl_bus_wait, + sdl_bus_stop, };
NTSTATUS CDECL __wine_init_unix_lib(HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out) diff --git a/dlls/winebus.sys/unixlib.h b/dlls/winebus.sys/unixlib.h index c220629ea87..a5cd57867e4 100644 --- a/dlls/winebus.sys/unixlib.h +++ b/dlls/winebus.sys/unixlib.h @@ -27,8 +27,16 @@ #include <ddk/wdm.h> #include <hidusage.h>
+struct sdl_bus_options +{ + BOOL map_controllers; +}; + struct unix_funcs { + NTSTATUS (WINAPI *sdl_bus_init)(void *); + NTSTATUS (WINAPI *sdl_bus_wait)(void); + NTSTATUS (WINAPI *sdl_bus_stop)(void); };
#endif /* __WINEBUS_UNIXLIB_H */
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus.h | 3 - dlls/winebus.sys/bus_udev.c | 158 ++++++++++++++------------------ dlls/winebus.sys/main.c | 46 +++++++++- dlls/winebus.sys/unix_private.h | 4 + dlls/winebus.sys/unixlib.c | 3 + dlls/winebus.sys/unixlib.h | 10 ++ 6 files changed, 128 insertions(+), 96 deletions(-)
diff --git a/dlls/winebus.sys/bus.h b/dlls/winebus.sys/bus.h index 2c2d26a1525..4618dea1396 100644 --- a/dlls/winebus.sys/bus.h +++ b/dlls/winebus.sys/bus.h @@ -28,9 +28,7 @@ typedef int(*enum_func)(DEVICE_OBJECT *device, void *context);
/* Buses */ -NTSTATUS udev_driver_init(void) DECLSPEC_HIDDEN; NTSTATUS iohid_driver_init(void) DECLSPEC_HIDDEN; -void udev_driver_unload( void ) DECLSPEC_HIDDEN; void iohid_driver_unload( void ) DECLSPEC_HIDDEN;
/* Native device function table */ @@ -58,7 +56,6 @@ void process_hid_report(DEVICE_OBJECT *device, BYTE *report, DWORD length) DECLS DEVICE_OBJECT *bus_enumerate_hid_devices(const WCHAR *bus_id, enum_func function, void *context) DECLSPEC_HIDDEN;
/* General Bus Functions */ -DWORD check_bus_option(const UNICODE_STRING *option, DWORD default_value) DECLSPEC_HIDDEN; BOOL is_xbox_gamepad(WORD vid, WORD pid) DECLSPEC_HIDDEN;
extern HANDLE driver_key DECLSPEC_HIDDEN; diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c index 77a242a6087..51d846b3bed 100644 --- a/dlls/winebus.sys/bus_udev.c +++ b/dlls/winebus.sys/bus_udev.c @@ -80,6 +80,7 @@ #endif
#include "bus.h" +#include "unix_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(plugplay);
@@ -87,11 +88,12 @@ WINE_DEFAULT_DEBUG_CHANNEL(plugplay);
WINE_DECLARE_DEBUG_CHANNEL(hid_report);
+static struct udev_bus_options options; + static struct udev *udev_context = NULL; -static DWORD disable_hidraw = 0; -static DWORD disable_input = 0; -static HANDLE deviceloop_handle; +static struct udev_monitor *udev_monitor; static int deviceloop_control[2]; +static int udev_monitor_fd;
static const WCHAR hidraw_busidW[] = {'H','I','D','R','A','W',0}; static const WCHAR lnxev_busidW[] = {'L','N','X','E','V',0}; @@ -1179,11 +1181,11 @@ static void build_initial_deviceset(void) return; }
- if (!disable_hidraw) + if (!options.disable_hidraw) if (udev_enumerate_add_match_subsystem(enumerate, "hidraw") < 0) WARN("Failed to add subsystem 'hidraw' to enumeration\n"); #ifdef HAS_PROPER_INPUT_HEADER - if (!disable_input) + if (!options.disable_input) { if (udev_enumerate_add_match_subsystem(enumerate, "input") < 0) WARN("Failed to add subsystem 'input' to enumeration\n"); @@ -1210,7 +1212,7 @@ static void build_initial_deviceset(void) udev_enumerate_unref(enumerate); }
-static struct udev_monitor *create_monitor(struct pollfd *pfd) +static struct udev_monitor *create_monitor(int *fd) { struct udev_monitor *monitor; int systems = 0; @@ -1222,7 +1224,7 @@ static struct udev_monitor *create_monitor(struct pollfd *pfd) return NULL; }
- if (!disable_hidraw) + if (!options.disable_hidraw) { if (udev_monitor_filter_add_match_subsystem_devtype(monitor, "hidraw", NULL) < 0) WARN("Failed to add 'hidraw' subsystem to monitor\n"); @@ -1230,7 +1232,7 @@ static struct udev_monitor *create_monitor(struct pollfd *pfd) systems++; } #ifdef HAS_PROPER_INPUT_HEADER - if (!disable_input) + if (!options.disable_input) { if (udev_monitor_filter_add_match_subsystem_devtype(monitor, "input", NULL) < 0) WARN("Failed to add 'input' subsystem to monitor\n"); @@ -1247,11 +1249,8 @@ static struct udev_monitor *create_monitor(struct pollfd *pfd) if (udev_monitor_enable_receiving(monitor) < 0) goto error;
- if ((pfd->fd = udev_monitor_get_fd(monitor)) >= 0) - { - pfd->events = POLLIN; + if ((*fd = udev_monitor_get_fd(monitor)) >= 0) return monitor; - }
error: WARN("Failed to start monitoring\n"); @@ -1287,118 +1286,95 @@ static void process_monitor_event(struct udev_monitor *monitor) udev_device_unref(dev); }
-static DWORD CALLBACK deviceloop_thread(void *args) -{ - struct udev_monitor *monitor; - HANDLE init_done = args; - struct pollfd pfd[2]; - - pfd[1].fd = deviceloop_control[0]; - pfd[1].events = POLLIN; - pfd[1].revents = 0; - - monitor = create_monitor(&pfd[0]); - build_initial_deviceset(); - SetEvent(init_done); - - while (monitor) - { - if (poll(pfd, 2, -1) <= 0) continue; - if (pfd[1].revents) break; - process_monitor_event(monitor); - } - - TRACE("Monitor thread exiting\n"); - if (monitor) - udev_monitor_unref(monitor); - return 0; -} - -void udev_driver_unload( void ) +NTSTATUS WINAPI udev_bus_stop(void) { - TRACE("Unload Driver\n"); - - if (!deviceloop_handle) - return; + if (!udev_context) return STATUS_SUCCESS;
write(deviceloop_control[1], "q", 1); - WaitForSingleObject(deviceloop_handle, INFINITE); - close(deviceloop_control[0]); - close(deviceloop_control[1]); - CloseHandle(deviceloop_handle); + return STATUS_SUCCESS; }
-NTSTATUS udev_driver_init(void) +NTSTATUS WINAPI udev_bus_init(void *args) { - HANDLE events[2]; - DWORD result; - static const WCHAR hidraw_disabledW[] = {'D','i','s','a','b','l','e','H','i','d','r','a','w',0}; - static const UNICODE_STRING hidraw_disabled = {sizeof(hidraw_disabledW) - sizeof(WCHAR), sizeof(hidraw_disabledW), (WCHAR*)hidraw_disabledW}; - static const WCHAR input_disabledW[] = {'D','i','s','a','b','l','e','I','n','p','u','t',0}; - static const UNICODE_STRING input_disabled = {sizeof(input_disabledW) - sizeof(WCHAR), sizeof(input_disabledW), (WCHAR*)input_disabledW}; + TRACE("args %p\n", args); + + options = *(struct udev_bus_options *)args;
if (pipe(deviceloop_control) != 0) { - ERR("Control pipe creation failed\n"); + ERR("control pipe creation failed\n"); return STATUS_UNSUCCESSFUL; }
if (!(udev_context = udev_new())) { - ERR("Can't create udev object\n"); - goto error; + ERR("udev object creation failed\n"); + close(deviceloop_control[0]); + close(deviceloop_control[1]); + return STATUS_UNSUCCESSFUL; }
- disable_hidraw = check_bus_option(&hidraw_disabled, 0); - if (disable_hidraw) - TRACE("UDEV hidraw devices disabled in registry\n"); - -#ifdef HAS_PROPER_INPUT_HEADER - disable_input = check_bus_option(&input_disabled, 0); - if (disable_input) - TRACE("UDEV input devices disabled in registry\n"); -#endif - - if (!(events[0] = CreateEventW(NULL, TRUE, FALSE, NULL))) - goto error; - if (!(events[1] = CreateThread(NULL, 0, deviceloop_thread, events[0], 0, NULL))) + if (!(udev_monitor = create_monitor(&udev_monitor_fd))) { - CloseHandle(events[0]); - goto error; + ERR("udev monitor creation failed\n"); + close(deviceloop_control[0]); + close(deviceloop_control[1]); + udev_unref(udev_context); + udev_context = NULL; + return STATUS_UNSUCCESSFUL; }
- result = WaitForMultipleObjects(2, events, FALSE, INFINITE); - CloseHandle(events[0]); - if (result == WAIT_OBJECT_0) + build_initial_deviceset(); + return STATUS_SUCCESS; +} + +NTSTATUS WINAPI udev_bus_wait(void) +{ + struct pollfd pfd[2]; + + pfd[0].fd = udev_monitor_fd; + pfd[0].events = POLLIN; + pfd[0].revents = 0; + pfd[1].fd = deviceloop_control[0]; + pfd[1].events = POLLIN; + pfd[1].revents = 0; + + while (1) { - deviceloop_handle = events[1]; - TRACE("Initialization successful\n"); - return STATUS_SUCCESS; + if (poll(pfd, 2, -1) <= 0) continue; + if (pfd[1].revents) break; + process_monitor_event(udev_monitor); } - CloseHandle(events[1]);
-error: - ERR("Failed to initialize udev device thread\n"); + TRACE("UDEV main loop exiting\n"); + udev_monitor_unref(udev_monitor); + + udev_unref(udev_context); + udev_context = NULL; + close(deviceloop_control[0]); close(deviceloop_control[1]); - if (udev_context) - { - udev_unref(udev_context); - udev_context = NULL; - } - return STATUS_UNSUCCESSFUL; + return STATUS_SUCCESS; }
#else
-NTSTATUS udev_driver_init(void) +NTSTATUS WINAPI udev_bus_init(void *args) +{ + WARN("UDEV support not compiled in!\n"); + return STATUS_NOT_IMPLEMENTED; +} + +NTSTATUS WINAPI udev_bus_wait(void) { + WARN("UDEV support not compiled in!\n"); return STATUS_NOT_IMPLEMENTED; }
-void udev_driver_unload( void ) +NTSTATUS WINAPI udev_bus_stop(void) { - TRACE("Stub: Unload Driver\n"); + WARN("UDEV support not compiled in!\n"); + return STATUS_NOT_IMPLEMENTED; }
#endif /* HAVE_UDEV */ diff --git a/dlls/winebus.sys/main.c b/dlls/winebus.sys/main.c index a4b236cecb7..36a281bec9d 100644 --- a/dlls/winebus.sys/main.c +++ b/dlls/winebus.sys/main.c @@ -408,7 +408,7 @@ static NTSTATUS build_device_relations(DEVICE_RELATIONS **devices) return STATUS_SUCCESS; }
-DWORD check_bus_option(const UNICODE_STRING *option, DWORD default_value) +static DWORD check_bus_option(const UNICODE_STRING *option, DWORD default_value) { char buffer[FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data[sizeof(DWORD)])]; KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer; @@ -705,6 +705,48 @@ static NTSTATUS sdl_driver_init(void) return STATUS_SUCCESS; }
+static NTSTATUS udev_driver_init(void) +{ + static const WCHAR udev_bus_name[] = {'U','D','E','V',0}; + static const WCHAR hidraw_disabledW[] = {'D','i','s','a','b','l','e','H','i','d','r','a','w',0}; + static const UNICODE_STRING hidraw_disabled = {sizeof(hidraw_disabledW) - sizeof(WCHAR), sizeof(hidraw_disabledW), (WCHAR*)hidraw_disabledW}; + static const WCHAR input_disabledW[] = {'D','i','s','a','b','l','e','I','n','p','u','t',0}; + static const UNICODE_STRING input_disabled = {sizeof(input_disabledW) - sizeof(WCHAR), sizeof(input_disabledW), (WCHAR*)input_disabledW}; + struct udev_bus_options udev_params; + struct bus_main_params params = + { + .name = udev_bus_name, + .bus_init = unix_funcs->udev_bus_init, + .bus_wait = unix_funcs->udev_bus_wait, + .bus_params = &udev_params, + }; + DWORD i = bus_count++; + + if (!(params.init = CreateEventW(NULL, FALSE, FALSE, NULL))) + { + ERR("failed to create UDEV bus event.\n"); + bus_count--; + return STATUS_UNSUCCESSFUL; + } + + udev_params.disable_hidraw = check_bus_option(&hidraw_disabled, 0); + if (udev_params.disable_hidraw) TRACE("UDEV hidraw devices disabled in registry\n"); + udev_params.disable_input = check_bus_option(&input_disabled, 0); + if (udev_params.disable_input) TRACE("UDEV input devices disabled in registry\n"); + + if (!(bus_thread[i] = CreateThread(NULL, 0, bus_main_thread, ¶ms, 0, NULL))) + { + ERR("failed to create UDEV bus thread.\n"); + CloseHandle(params.init); + bus_count--; + return STATUS_UNSUCCESSFUL; + } + + WaitForSingleObject(params.init, INFINITE); + CloseHandle(params.init); + return STATUS_SUCCESS; +} + static NTSTATUS fdo_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp) { static const WCHAR SDL_enabledW[] = {'E','n','a','b','l','e',' ','S','D','L',0}; @@ -733,8 +775,8 @@ static NTSTATUS fdo_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp) irp->IoStatus.Status = STATUS_SUCCESS; break; case IRP_MN_REMOVE_DEVICE: - udev_driver_unload(); iohid_driver_unload(); + unix_funcs->udev_bus_stop(); unix_funcs->sdl_bus_stop();
WaitForMultipleObjects(bus_count, bus_thread, TRUE, INFINITE); diff --git a/dlls/winebus.sys/unix_private.h b/dlls/winebus.sys/unix_private.h index 7ac882a03b2..8fb280ac7cd 100644 --- a/dlls/winebus.sys/unix_private.h +++ b/dlls/winebus.sys/unix_private.h @@ -31,4 +31,8 @@ extern NTSTATUS WINAPI sdl_bus_init(void *args) DECLSPEC_HIDDEN; extern NTSTATUS WINAPI sdl_bus_wait(void) DECLSPEC_HIDDEN; extern NTSTATUS WINAPI sdl_bus_stop(void) DECLSPEC_HIDDEN;
+extern NTSTATUS WINAPI udev_bus_init(void *args) DECLSPEC_HIDDEN; +extern NTSTATUS WINAPI udev_bus_wait(void) DECLSPEC_HIDDEN; +extern NTSTATUS WINAPI udev_bus_stop(void) DECLSPEC_HIDDEN; + #endif /* __WINEBUS_UNIX_PRIVATE_H */ diff --git a/dlls/winebus.sys/unixlib.c b/dlls/winebus.sys/unixlib.c index 832a20372d6..cbd29ceecd1 100644 --- a/dlls/winebus.sys/unixlib.c +++ b/dlls/winebus.sys/unixlib.c @@ -36,6 +36,9 @@ static const struct unix_funcs unix_funcs = sdl_bus_init, sdl_bus_wait, sdl_bus_stop, + udev_bus_init, + udev_bus_wait, + udev_bus_stop, };
NTSTATUS CDECL __wine_init_unix_lib(HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out) diff --git a/dlls/winebus.sys/unixlib.h b/dlls/winebus.sys/unixlib.h index a5cd57867e4..cd1bce096c7 100644 --- a/dlls/winebus.sys/unixlib.h +++ b/dlls/winebus.sys/unixlib.h @@ -32,11 +32,21 @@ struct sdl_bus_options BOOL map_controllers; };
+struct udev_bus_options +{ + BOOL disable_hidraw; + BOOL disable_input; +}; + struct unix_funcs { NTSTATUS (WINAPI *sdl_bus_init)(void *); NTSTATUS (WINAPI *sdl_bus_wait)(void); NTSTATUS (WINAPI *sdl_bus_stop)(void); + + NTSTATUS (WINAPI *udev_bus_init)(void *); + NTSTATUS (WINAPI *udev_bus_wait)(void); + NTSTATUS (WINAPI *udev_bus_stop)(void); };
#endif /* __WINEBUS_UNIXLIB_H */
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus.h | 4 --- dlls/winebus.sys/bus_iohid.c | 62 ++++++++++++++++----------------- dlls/winebus.sys/main.c | 35 ++++++++++++++++++- dlls/winebus.sys/unix_private.h | 4 +++ dlls/winebus.sys/unixlib.c | 3 ++ dlls/winebus.sys/unixlib.h | 8 +++++ 6 files changed, 80 insertions(+), 36 deletions(-)
diff --git a/dlls/winebus.sys/bus.h b/dlls/winebus.sys/bus.h index 4618dea1396..1e4f37ae896 100644 --- a/dlls/winebus.sys/bus.h +++ b/dlls/winebus.sys/bus.h @@ -27,10 +27,6 @@
typedef int(*enum_func)(DEVICE_OBJECT *device, void *context);
-/* Buses */ -NTSTATUS iohid_driver_init(void) DECLSPEC_HIDDEN; -void iohid_driver_unload( void ) DECLSPEC_HIDDEN; - /* Native device function table */ typedef struct { diff --git a/dlls/winebus.sys/bus_iohid.c b/dlls/winebus.sys/bus_iohid.c index 4eb0ea0e4b3..e21c58b7c84 100644 --- a/dlls/winebus.sys/bus_iohid.c +++ b/dlls/winebus.sys/bus_iohid.c @@ -90,13 +90,16 @@ #include "wine/debug.h"
#include "bus.h" +#include "unix_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(plugplay); + #ifdef HAVE_IOHIDMANAGERCREATE
+static struct iohid_bus_options options; + static IOHIDManagerRef hid_manager; static CFRunLoopRef run_loop; -static HANDLE run_loop_handle;
static const WCHAR busidW[] = {'I','O','H','I','D',0};
@@ -385,63 +388,60 @@ static void handle_RemovalCallback(void *context, IOReturn result, void *sender, } }
-/* This puts the relevant run loop for event handling into a WINE thread */ -static DWORD CALLBACK runloop_thread(void *args) +NTSTATUS WINAPI iohid_bus_init(void *args) { + TRACE("args %p\n", args); + + options = *(struct iohid_bus_options *)args; + + hid_manager = IOHIDManagerCreate(kCFAllocatorDefault, 0L); run_loop = CFRunLoopGetCurrent();
IOHIDManagerSetDeviceMatching(hid_manager, NULL); IOHIDManagerRegisterDeviceMatchingCallback(hid_manager, handle_DeviceMatchingCallback, NULL); IOHIDManagerRegisterDeviceRemovalCallback(hid_manager, handle_RemovalCallback, NULL); IOHIDManagerScheduleWithRunLoop(hid_manager, run_loop, kCFRunLoopDefaultMode); - - CFRunLoopRun(); - TRACE("Run Loop exiting\n"); - return 1; - + return STATUS_SUCCESS; }
-NTSTATUS iohid_driver_init(void) +NTSTATUS WINAPI iohid_bus_wait(void) { - hid_manager = IOHIDManagerCreate(kCFAllocatorDefault, 0L); - if (!(run_loop_handle = CreateThread(NULL, 0, runloop_thread, NULL, 0, NULL))) - { - ERR("Failed to initialize IOHID Manager thread\n"); - CFRelease(hid_manager); - return STATUS_UNSUCCESSFUL; - } + CFRunLoopRun();
- TRACE("Initialization successful\n"); + TRACE("IOHID main loop exiting\n"); + IOHIDManagerRegisterDeviceMatchingCallback(hid_manager, NULL, NULL); + IOHIDManagerRegisterDeviceRemovalCallback(hid_manager, NULL, NULL); + CFRelease(hid_manager); return STATUS_SUCCESS; }
-void iohid_driver_unload( void ) +NTSTATUS WINAPI iohid_bus_stop(void) { - TRACE("Unloading Driver\n"); - - if (!run_loop_handle) - return; + if (!run_loop) return STATUS_SUCCESS;
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"); + return STATUS_SUCCESS; }
#else
-NTSTATUS iohid_driver_init(void) +NTSTATUS WINAPI iohid_bus_init(void *args) +{ + WARN("IOHID support not compiled in!\n"); + return STATUS_NOT_IMPLEMENTED; +} + +NTSTATUS WINAPI iohid_bus_wait(void) { + WARN("IOHID support not compiled in!\n"); return STATUS_NOT_IMPLEMENTED; }
-void iohid_driver_unload( void ) +NTSTATUS WINAPI iohid_bus_stop(void) { - TRACE("Stub: Unload Driver\n"); + WARN("IOHID support not compiled in!\n"); + return STATUS_NOT_IMPLEMENTED; }
#endif /* HAVE_IOHIDMANAGERCREATE */ diff --git a/dlls/winebus.sys/main.c b/dlls/winebus.sys/main.c index 36a281bec9d..2b7566d25df 100644 --- a/dlls/winebus.sys/main.c +++ b/dlls/winebus.sys/main.c @@ -747,6 +747,39 @@ static NTSTATUS udev_driver_init(void) return STATUS_SUCCESS; }
+static NTSTATUS iohid_driver_init(void) +{ + static const WCHAR iohid_bus_name[] = {'I','O','H','I','D',0}; + struct iohid_bus_options iohid_params; + struct bus_main_params params = + { + .name = iohid_bus_name, + .bus_init = unix_funcs->iohid_bus_init, + .bus_wait = unix_funcs->iohid_bus_wait, + .bus_params = &iohid_params, + }; + DWORD i = bus_count++; + + if (!(params.init = CreateEventW(NULL, FALSE, FALSE, NULL))) + { + ERR("failed to create IOHID bus event.\n"); + bus_count--; + return STATUS_UNSUCCESSFUL; + } + + if (!(bus_thread[i] = CreateThread(NULL, 0, bus_main_thread, ¶ms, 0, NULL))) + { + ERR("failed to create IOHID bus thread.\n"); + CloseHandle(params.init); + bus_count--; + return STATUS_UNSUCCESSFUL; + } + + WaitForSingleObject(params.init, INFINITE); + CloseHandle(params.init); + return STATUS_SUCCESS; +} + static NTSTATUS fdo_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp) { static const WCHAR SDL_enabledW[] = {'E','n','a','b','l','e',' ','S','D','L',0}; @@ -775,7 +808,7 @@ static NTSTATUS fdo_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp) irp->IoStatus.Status = STATUS_SUCCESS; break; case IRP_MN_REMOVE_DEVICE: - iohid_driver_unload(); + unix_funcs->iohid_bus_stop(); unix_funcs->udev_bus_stop(); unix_funcs->sdl_bus_stop();
diff --git a/dlls/winebus.sys/unix_private.h b/dlls/winebus.sys/unix_private.h index 8fb280ac7cd..24e42e78aa6 100644 --- a/dlls/winebus.sys/unix_private.h +++ b/dlls/winebus.sys/unix_private.h @@ -35,4 +35,8 @@ extern NTSTATUS WINAPI udev_bus_init(void *args) DECLSPEC_HIDDEN; extern NTSTATUS WINAPI udev_bus_wait(void) DECLSPEC_HIDDEN; extern NTSTATUS WINAPI udev_bus_stop(void) DECLSPEC_HIDDEN;
+extern NTSTATUS WINAPI iohid_bus_init(void *args) DECLSPEC_HIDDEN; +extern NTSTATUS WINAPI iohid_bus_wait(void) DECLSPEC_HIDDEN; +extern NTSTATUS WINAPI iohid_bus_stop(void) DECLSPEC_HIDDEN; + #endif /* __WINEBUS_UNIX_PRIVATE_H */ diff --git a/dlls/winebus.sys/unixlib.c b/dlls/winebus.sys/unixlib.c index cbd29ceecd1..31919e2a53b 100644 --- a/dlls/winebus.sys/unixlib.c +++ b/dlls/winebus.sys/unixlib.c @@ -39,6 +39,9 @@ static const struct unix_funcs unix_funcs = udev_bus_init, udev_bus_wait, udev_bus_stop, + iohid_bus_init, + iohid_bus_wait, + iohid_bus_stop, };
NTSTATUS CDECL __wine_init_unix_lib(HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out) diff --git a/dlls/winebus.sys/unixlib.h b/dlls/winebus.sys/unixlib.h index cd1bce096c7..df634ad4cc3 100644 --- a/dlls/winebus.sys/unixlib.h +++ b/dlls/winebus.sys/unixlib.h @@ -38,6 +38,10 @@ struct udev_bus_options BOOL disable_input; };
+struct iohid_bus_options +{ +}; + struct unix_funcs { NTSTATUS (WINAPI *sdl_bus_init)(void *); @@ -47,6 +51,10 @@ struct unix_funcs NTSTATUS (WINAPI *udev_bus_init)(void *); NTSTATUS (WINAPI *udev_bus_wait)(void); NTSTATUS (WINAPI *udev_bus_stop)(void); + + NTSTATUS (WINAPI *iohid_bus_init)(void *); + NTSTATUS (WINAPI *iohid_bus_wait)(void); + NTSTATUS (WINAPI *iohid_bus_stop)(void); };
#endif /* __WINEBUS_UNIXLIB_H */
And use an opaque struct unix_device as private data.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus.h | 8 ++++---- dlls/winebus.sys/bus_iohid.c | 23 ++++++++++++++++------- dlls/winebus.sys/bus_sdl.c | 25 ++++++++++++++++--------- dlls/winebus.sys/bus_udev.c | 31 ++++++++++++++++++++++++------- dlls/winebus.sys/main.c | 25 +++++++++++-------------- dlls/winebus.sys/unix_private.h | 4 ++++ dlls/winebus.sys/unixlib.h | 2 ++ 7 files changed, 77 insertions(+), 41 deletions(-)
diff --git a/dlls/winebus.sys/bus.h b/dlls/winebus.sys/bus.h index 1e4f37ae896..803ffaad132 100644 --- a/dlls/winebus.sys/bus.h +++ b/dlls/winebus.sys/bus.h @@ -40,12 +40,12 @@ typedef struct void (*set_feature_report)(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io); } platform_vtbl;
-void *get_platform_private(DEVICE_OBJECT *device) DECLSPEC_HIDDEN; +struct unix_device *get_unix_device(DEVICE_OBJECT *device) DECLSPEC_HIDDEN;
/* HID Plug and Play Bus */ -DEVICE_OBJECT *bus_create_hid_device(const WCHAR *busidW, WORD vid, WORD pid, - WORD input, DWORD version, DWORD uid, const WCHAR *serialW, BOOL is_gamepad, - const platform_vtbl *vtbl, DWORD platform_data_size) DECLSPEC_HIDDEN; +DEVICE_OBJECT *bus_create_hid_device(const WCHAR *busidW, WORD vid, WORD pid, WORD input, + DWORD version, DWORD uid, const WCHAR *serialW, BOOL is_gamepad, + const platform_vtbl *vtbl, struct unix_device *unix_device) DECLSPEC_HIDDEN; DEVICE_OBJECT *bus_find_hid_device(const WCHAR *bus_id, void *platform_dev) DECLSPEC_HIDDEN; void bus_unlink_hid_device(DEVICE_OBJECT *device) DECLSPEC_HIDDEN; void process_hid_report(DEVICE_OBJECT *device, BYTE *report, DWORD length) DECLSPEC_HIDDEN; diff --git a/dlls/winebus.sys/bus_iohid.c b/dlls/winebus.sys/bus_iohid.c index e21c58b7c84..55e4880a88b 100644 --- a/dlls/winebus.sys/bus_iohid.c +++ b/dlls/winebus.sys/bus_iohid.c @@ -105,13 +105,19 @@ static const WCHAR busidW[] = {'I','O','H','I','D',0};
struct platform_private { + struct unix_device unix_device; IOHIDDeviceRef device; uint8_t *buffer; };
+static inline struct platform_private *impl_from_unix_device(struct unix_device *iface) +{ + return CONTAINING_RECORD(iface, struct platform_private, unix_device); +} + static inline struct platform_private *impl_from_DEVICE_OBJECT(DEVICE_OBJECT *device) { - return (struct platform_private *)get_platform_private(device); + return impl_from_unix_device(get_unix_device(device)); }
static void CFStringToWSTR(CFStringRef cstr, LPWSTR wstr, int length) @@ -139,6 +145,8 @@ static void handle_IOHIDDeviceIOHIDReportCallback(void *context,
static void free_device(DEVICE_OBJECT *device) { + struct platform_private *private = impl_from_DEVICE_OBJECT(device); + HeapFree(GetProcessHeap(), 0, private); }
static int compare_platform_device(DEVICE_OBJECT *device, void *platform_dev) @@ -287,6 +295,7 @@ static const platform_vtbl iohid_vtbl =
static void handle_DeviceMatchingCallback(void *context, IOReturn result, void *sender, IOHIDDeviceRef IOHIDDevice) { + struct platform_private *private; DEVICE_OBJECT *device; DWORD vid, pid, version, uid; CFStringRef str = NULL; @@ -357,14 +366,14 @@ static void handle_DeviceMatchingCallback(void *context, IOReturn result, void * if (is_gamepad) input = 0;
- device = bus_create_hid_device(busidW, vid, pid, input, - version, uid, str ? serial_string : NULL, is_gamepad, - &iohid_vtbl, sizeof(struct platform_private)); - if (!device) - ERR("Failed to create device\n"); + if (!(private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct platform_private)))) + return; + + device = bus_create_hid_device(busidW, vid, pid, input, version, uid, str ? serial_string : NULL, + is_gamepad, &iohid_vtbl, &private->unix_device); + if (!device) HeapFree(GetProcessHeap(), 0, private); else { - struct platform_private *private = impl_from_DEVICE_OBJECT(device); private->device = IOHIDDevice; private->buffer = NULL; IoInvalidateDeviceRelations(bus_pdo, BusRelations); diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c index 0cec6e4d981..7f392cd14e4 100644 --- a/dlls/winebus.sys/bus_sdl.c +++ b/dlls/winebus.sys/bus_sdl.c @@ -112,6 +112,8 @@ static Uint16 (*pSDL_JoystickGetVendor)(SDL_Joystick * joystick);
struct platform_private { + struct unix_device unix_device; + SDL_Joystick *sdl_joystick; SDL_GameController *sdl_controller; SDL_JoystickID id; @@ -130,9 +132,14 @@ struct platform_private int haptic_effect_id; };
+static inline struct platform_private *impl_from_unix_device(struct unix_device *iface) +{ + return CONTAINING_RECORD(iface, struct platform_private, unix_device); +} + static inline struct platform_private *impl_from_DEVICE_OBJECT(DEVICE_OBJECT *device) { - return (struct platform_private *)get_platform_private(device); + return impl_from_unix_device(get_unix_device(device)); }
#define CONTROLLER_NUM_BUTTONS 11 @@ -481,6 +488,8 @@ static void free_device(DEVICE_OBJECT *device) pSDL_GameControllerClose(ext->sdl_controller); if (ext->sdl_haptic) pSDL_HapticClose(ext->sdl_haptic); + + HeapFree(GetProcessHeap(), 0, ext); }
static int compare_platform_device(DEVICE_OBJECT *device, void *context) @@ -732,6 +741,7 @@ static void try_remove_device(DEVICE_OBJECT *device) static void try_add_device(unsigned int index) { DWORD vid = 0, pid = 0, version = 0; + struct platform_private *private; DEVICE_OBJECT *device = NULL; WCHAR serial[34] = {0}; char guid_str[34]; @@ -790,21 +800,18 @@ static void try_add_device(unsigned int index) if (is_xbox_gamepad) input = 0;
- device = bus_create_hid_device(sdl_busidW, vid, pid, input, version, index, - serial, is_xbox_gamepad, &sdl_vtbl, sizeof(struct platform_private)); + if (!(private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*private)))) return;
- if (device) + device = bus_create_hid_device(sdl_busidW, vid, pid, input, version, index, serial, is_xbox_gamepad, + &sdl_vtbl, &private->unix_device); + if (!device) HeapFree(GetProcessHeap(), 0, private); + else { - struct platform_private *private = impl_from_DEVICE_OBJECT(device); private->sdl_joystick = joystick; private->sdl_controller = controller; private->id = id; IoInvalidateDeviceRelations(bus_pdo, BusRelations); } - else - { - WARN("Ignoring device %i\n", id); - } }
static void process_device_event(SDL_Event *event) diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c index 51d846b3bed..a0e92bbc692 100644 --- a/dlls/winebus.sys/bus_udev.c +++ b/dlls/winebus.sys/bus_udev.c @@ -100,6 +100,8 @@ static const WCHAR lnxev_busidW[] = {'L','N','X','E','V',0};
struct platform_private { + struct unix_device unix_device; + struct udev_device *udev_device; int device_fd;
@@ -107,9 +109,14 @@ struct platform_private int control_pipe[2]; };
+static inline struct platform_private *impl_from_unix_device(struct unix_device *iface) +{ + return CONTAINING_RECORD(iface, struct platform_private, unix_device); +} + static inline struct platform_private *impl_from_DEVICE_OBJECT(DEVICE_OBJECT *device) { - return (struct platform_private *)get_platform_private(device); + return impl_from_unix_device(get_unix_device(device)); }
#ifdef HAS_PROPER_INPUT_HEADER @@ -551,6 +558,8 @@ static void hidraw_free_device(DEVICE_OBJECT *device)
close(private->device_fd); udev_device_unref(private->udev_device); + + HeapFree(GetProcessHeap(), 0, private); }
static int compare_platform_device(DEVICE_OBJECT *device, void *platform_dev) @@ -834,7 +843,7 @@ static const platform_vtbl hidraw_vtbl =
static inline struct wine_input_private *input_impl_from_DEVICE_OBJECT(DEVICE_OBJECT *device) { - return (struct wine_input_private*)get_platform_private(device); + return CONTAINING_RECORD(impl_from_DEVICE_OBJECT(device), struct wine_input_private, base); }
static void lnxev_free_device(DEVICE_OBJECT *device) @@ -856,6 +865,8 @@ static void lnxev_free_device(DEVICE_OBJECT *device)
close(ext->base.device_fd); udev_device_unref(ext->base.udev_device); + + HeapFree(GetProcessHeap(), 0, ext); }
static DWORD CALLBACK lnxev_device_report_thread(void *args); @@ -1051,6 +1062,7 @@ static void get_device_subsystem_info(struct udev_device *dev, char const *subsy static void try_add_device(struct udev_device *dev) { DWORD vid = 0, pid = 0, version = 0, input = -1; + struct platform_private *private; DEVICE_OBJECT *device = NULL; const char *subsystem; const char *devnode; @@ -1128,20 +1140,25 @@ static void try_add_device(struct udev_device *dev)
if (strcmp(subsystem, "hidraw") == 0) { - device = bus_create_hid_device(hidraw_busidW, vid, pid, input, version, 0, serial, is_gamepad, - &hidraw_vtbl, sizeof(struct platform_private)); + if (!(private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct platform_private)))) + return; + device = bus_create_hid_device(hidraw_busidW, vid, pid, input, version, 0, serial, + is_gamepad, &hidraw_vtbl, &private->unix_device); + if (!device) HeapFree(GetProcessHeap(), 0, private); } #ifdef HAS_PROPER_INPUT_HEADER else if (strcmp(subsystem, "input") == 0) { - device = bus_create_hid_device(lnxev_busidW, vid, pid, input, version, 0, serial, is_gamepad, - &lnxev_vtbl, sizeof(struct wine_input_private)); + if (!(private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct wine_input_private)))) + return; + device = bus_create_hid_device(lnxev_busidW, vid, pid, input, version, 0, serial, + is_gamepad, &lnxev_vtbl, &private->unix_device); + if (!device) HeapFree(GetProcessHeap(), 0, private); } #endif
if (device) { - struct platform_private *private = impl_from_DEVICE_OBJECT(device); private->udev_device = udev_device_ref(dev); private->device_fd = fd; IoInvalidateDeviceRelations(bus_pdo, BusRelations); diff --git a/dlls/winebus.sys/main.c b/dlls/winebus.sys/main.c index 2b7566d25df..bd486e36058 100644 --- a/dlls/winebus.sys/main.c +++ b/dlls/winebus.sys/main.c @@ -141,7 +141,7 @@ struct device_extension DWORD buffer_size; LIST_ENTRY irp_queue;
- BYTE platform_private[1]; + struct unix_device *unix_device; };
static CRITICAL_SECTION device_list_cs; @@ -168,10 +168,10 @@ static inline WCHAR *strdupW(const WCHAR *src) return dst; }
-void *get_platform_private(DEVICE_OBJECT *device) +struct unix_device *get_unix_device(DEVICE_OBJECT *device) { struct device_extension *ext = (struct device_extension *)device->DeviceExtension; - return ext->platform_private; + return ext->unix_device; }
static DWORD get_device_index(WORD vid, WORD pid, WORD input) @@ -257,9 +257,9 @@ static void remove_pending_irps(DEVICE_OBJECT *device) } }
-DEVICE_OBJECT *bus_create_hid_device(const WCHAR *busidW, WORD vid, WORD pid, - WORD input, DWORD version, DWORD uid, const WCHAR *serialW, BOOL is_gamepad, - const platform_vtbl *vtbl, DWORD platform_data_size) +DEVICE_OBJECT *bus_create_hid_device(const WCHAR *busidW, WORD vid, WORD pid, WORD input, + DWORD version, DWORD uid, const WCHAR *serialW, BOOL is_gamepad, + const platform_vtbl *vtbl, struct unix_device *unix_device) { static const WCHAR device_name_fmtW[] = {'\','D','e','v','i','c','e','\','%','s','#','%','p',0}; struct device_extension *ext; @@ -268,19 +268,17 @@ DEVICE_OBJECT *bus_create_hid_device(const WCHAR *busidW, WORD vid, WORD pid, UNICODE_STRING nameW; WCHAR dev_name[256]; NTSTATUS status; - DWORD length;
- TRACE("(%s, %04x, %04x, %04x, %u, %u, %s, %u, %p, %u)\n", - debugstr_w(busidW), vid, pid, input, version, uid, debugstr_w(serialW), - is_gamepad, vtbl, platform_data_size); + TRACE("bus_id %s, vid %04x, pid %04x, input %04x, version %u, uid %u, serial %s, " + "is_gamepad %u, vtbl %p, unix_device %p\n", debugstr_w(busidW), vid, pid, input, + version, uid, debugstr_w(serialW), is_gamepad, vtbl, unix_device);
if (!(pnp_dev = HeapAlloc(GetProcessHeap(), 0, sizeof(*pnp_dev)))) return NULL;
sprintfW(dev_name, device_name_fmtW, busidW, pnp_dev); RtlInitUnicodeString(&nameW, dev_name); - length = FIELD_OFFSET(struct device_extension, platform_private[platform_data_size]); - status = IoCreateDevice(driver_obj, length, &nameW, 0, 0, FALSE, &device); + status = IoCreateDevice(driver_obj, sizeof(struct device_extension), &nameW, 0, 0, FALSE, &device); if (status) { FIXME("failed to create device error %x\n", status); @@ -307,8 +305,7 @@ DEVICE_OBJECT *bus_create_hid_device(const WCHAR *busidW, WORD vid, WORD pid, ext->last_report_size = 0; ext->last_report_read = TRUE; ext->buffer_size = 0; - - memset(ext->platform_private, 0, platform_data_size); + ext->unix_device = unix_device;
InitializeListHead(&ext->irp_queue); InitializeCriticalSection(&ext->cs); diff --git a/dlls/winebus.sys/unix_private.h b/dlls/winebus.sys/unix_private.h index 24e42e78aa6..8adbd819bfe 100644 --- a/dlls/winebus.sys/unix_private.h +++ b/dlls/winebus.sys/unix_private.h @@ -27,6 +27,10 @@
#include "unixlib.h"
+struct unix_device +{ +}; + extern NTSTATUS WINAPI sdl_bus_init(void *args) DECLSPEC_HIDDEN; extern NTSTATUS WINAPI sdl_bus_wait(void) DECLSPEC_HIDDEN; extern NTSTATUS WINAPI sdl_bus_stop(void) DECLSPEC_HIDDEN; diff --git a/dlls/winebus.sys/unixlib.h b/dlls/winebus.sys/unixlib.h index df634ad4cc3..4c66aabff88 100644 --- a/dlls/winebus.sys/unixlib.h +++ b/dlls/winebus.sys/unixlib.h @@ -42,6 +42,8 @@ struct iohid_bus_options { };
+struct unix_device; + struct unix_funcs { NTSTATUS (WINAPI *sdl_bus_init)(void *);
Instead of a separately allocated device list entry pointer. And link the device object into the device list directly.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/main.c | 69 ++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 46 deletions(-)
diff --git a/dlls/winebus.sys/main.c b/dlls/winebus.sys/main.c index bd486e36058..cf606c856e3 100644 --- a/dlls/winebus.sys/main.c +++ b/dlls/winebus.sys/main.c @@ -107,12 +107,6 @@ static DEVICE_OBJECT *bus_fdo;
HANDLE driver_key;
-struct pnp_device -{ - struct list entry; - DEVICE_OBJECT *device; -}; - enum device_state { DEVICE_STATE_STOPPED, @@ -122,11 +116,12 @@ enum device_state
struct device_extension { + struct list entry; + DEVICE_OBJECT *device; + CRITICAL_SECTION cs; enum device_state state;
- struct pnp_device *pnp_device; - WORD vid, pid, input; DWORD uid, version, index; BOOL is_gamepad; @@ -153,7 +148,7 @@ static CRITICAL_SECTION_DEBUG critsect_debug = }; static CRITICAL_SECTION device_list_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
-static struct list pnp_devset = LIST_INIT(pnp_devset); +static struct list device_list = LIST_INIT(device_list);
static const WCHAR zero_serialW[]= {'0','0','0','0',0}; static const WCHAR miW[] = {'M','I',0}; @@ -176,12 +171,11 @@ struct unix_device *get_unix_device(DEVICE_OBJECT *device)
static DWORD get_device_index(WORD vid, WORD pid, WORD input) { - struct pnp_device *ptr; + struct device_extension *ext; DWORD index = 0;
- LIST_FOR_EACH_ENTRY(ptr, &pnp_devset, struct pnp_device, entry) + LIST_FOR_EACH_ENTRY(ext, &device_list, struct device_extension, entry) { - struct device_extension *ext = (struct device_extension *)ptr->device->DeviceExtension; if (ext->vid == vid && ext->pid == pid && ext->input == input) index = max(ext->index + 1, index); } @@ -263,7 +257,6 @@ DEVICE_OBJECT *bus_create_hid_device(const WCHAR *busidW, WORD vid, WORD pid, WO { static const WCHAR device_name_fmtW[] = {'\','D','e','v','i','c','e','\','%','s','#','%','p',0}; struct device_extension *ext; - struct pnp_device *pnp_dev; DEVICE_OBJECT *device; UNICODE_STRING nameW; WCHAR dev_name[256]; @@ -273,16 +266,12 @@ DEVICE_OBJECT *bus_create_hid_device(const WCHAR *busidW, WORD vid, WORD pid, WO "is_gamepad %u, vtbl %p, unix_device %p\n", debugstr_w(busidW), vid, pid, input, version, uid, debugstr_w(serialW), is_gamepad, vtbl, unix_device);
- if (!(pnp_dev = HeapAlloc(GetProcessHeap(), 0, sizeof(*pnp_dev)))) - return NULL; - - sprintfW(dev_name, device_name_fmtW, busidW, pnp_dev); + sprintfW(dev_name, device_name_fmtW, busidW, unix_device); RtlInitUnicodeString(&nameW, dev_name); status = IoCreateDevice(driver_obj, sizeof(struct device_extension), &nameW, 0, 0, FALSE, &device); if (status) { FIXME("failed to create device error %x\n", status); - HeapFree(GetProcessHeap(), 0, pnp_dev); return NULL; }
@@ -290,7 +279,7 @@ DEVICE_OBJECT *bus_create_hid_device(const WCHAR *busidW, WORD vid, WORD pid, WO
/* fill out device_extension struct */ ext = (struct device_extension *)device->DeviceExtension; - ext->pnp_device = pnp_dev; + ext->device = device; ext->vid = vid; ext->pid = pid; ext->input = input; @@ -312,8 +301,7 @@ DEVICE_OBJECT *bus_create_hid_device(const WCHAR *busidW, WORD vid, WORD pid, WO ext->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": cs");
/* add to list of pnp devices */ - pnp_dev->device = device; - list_add_tail(&pnp_devset, &pnp_dev->entry); + list_add_tail(&device_list, &ext->entry);
LeaveCriticalSection(&device_list_cs); return device; @@ -321,19 +309,18 @@ DEVICE_OBJECT *bus_create_hid_device(const WCHAR *busidW, WORD vid, WORD pid, WO
DEVICE_OBJECT *bus_find_hid_device(const WCHAR *bus_id, void *platform_dev) { - struct pnp_device *dev; + struct device_extension *ext; DEVICE_OBJECT *ret = NULL;
TRACE("bus_id %s, platform_dev %p\n", debugstr_w(bus_id), platform_dev);
EnterCriticalSection(&device_list_cs); - LIST_FOR_EACH_ENTRY(dev, &pnp_devset, struct pnp_device, entry) + LIST_FOR_EACH_ENTRY(ext, &device_list, struct device_extension, entry) { - struct device_extension *ext = (struct device_extension *)dev->device->DeviceExtension; if (strcmpW(ext->busid, bus_id)) continue; - if (ext->vtbl->compare_platform_device(dev->device, platform_dev) == 0) + if (ext->vtbl->compare_platform_device(ext->device, platform_dev) == 0) { - ret = dev->device; + ret = ext->device; break; } } @@ -345,23 +332,22 @@ DEVICE_OBJECT *bus_find_hid_device(const WCHAR *bus_id, void *platform_dev)
DEVICE_OBJECT *bus_enumerate_hid_devices(const WCHAR *bus_id, enum_func function, void *context) { - struct pnp_device *dev, *dev_next; + struct device_extension *ext, *next; DEVICE_OBJECT *ret = NULL; int cont;
TRACE("bus_id %p\n", debugstr_w(bus_id));
EnterCriticalSection(&device_list_cs); - LIST_FOR_EACH_ENTRY_SAFE(dev, dev_next, &pnp_devset, struct pnp_device, entry) + LIST_FOR_EACH_ENTRY_SAFE(ext, next, &device_list, struct device_extension, entry) { - struct device_extension *ext = (struct device_extension *)dev->device->DeviceExtension; if (strcmpW(ext->busid, bus_id)) continue; LeaveCriticalSection(&device_list_cs); - cont = function(dev->device, context); + cont = function(ext->device, context); EnterCriticalSection(&device_list_cs); if (!cont) { - ret = dev->device; + ret = ext->device; break; } } @@ -372,20 +358,19 @@ DEVICE_OBJECT *bus_enumerate_hid_devices(const WCHAR *bus_id, enum_func function void bus_unlink_hid_device(DEVICE_OBJECT *device) { struct device_extension *ext = (struct device_extension *)device->DeviceExtension; - struct pnp_device *pnp_device = ext->pnp_device;
EnterCriticalSection(&device_list_cs); - list_remove(&pnp_device->entry); + list_remove(&ext->entry); LeaveCriticalSection(&device_list_cs); }
static NTSTATUS build_device_relations(DEVICE_RELATIONS **devices) { + struct device_extension *ext; int i; - struct pnp_device *ptr;
EnterCriticalSection(&device_list_cs); - *devices = ExAllocatePool(PagedPool, offsetof(DEVICE_RELATIONS, Objects[list_count(&pnp_devset)])); + *devices = ExAllocatePool(PagedPool, offsetof(DEVICE_RELATIONS, Objects[list_count(&device_list)]));
if (!*devices) { @@ -394,10 +379,10 @@ static NTSTATUS build_device_relations(DEVICE_RELATIONS **devices) }
i = 0; - LIST_FOR_EACH_ENTRY(ptr, &pnp_devset, struct pnp_device, entry) + LIST_FOR_EACH_ENTRY(ext, &device_list, struct device_extension, entry) { - (*devices)->Objects[i] = ptr->device; - call_fastcall_func1(ObfReferenceObject, ptr->device); + (*devices)->Objects[i] = ext->device; + call_fastcall_func1(ObfReferenceObject, ext->device); i++; } LeaveCriticalSection(&device_list_cs); @@ -862,9 +847,6 @@ static NTSTATUS pdo_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp) break;
case IRP_MN_REMOVE_DEVICE: - { - struct pnp_device *pnp_device = ext->pnp_device; - remove_pending_irps(device);
bus_unlink_hid_device(device); @@ -880,12 +862,7 @@ static NTSTATUS pdo_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp) IoCompleteRequest(irp, IO_NO_INCREMENT);
IoDeleteDevice(device); - - /* pnp_device must be released after the device is gone */ - HeapFree(GetProcessHeap(), 0, pnp_device); - return STATUS_SUCCESS; - }
default: FIXME("Unhandled function %08x\n", irpsp->MinorFunction);