Commit 09c14c63 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

winebus.sys: Allocate private device data separately.

And use an opaque struct unix_device as private data. Signed-off-by: 's avatarRémi Bernon <rbernon@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 7e1d1fac
...@@ -40,12 +40,12 @@ typedef struct ...@@ -40,12 +40,12 @@ typedef struct
void (*set_feature_report)(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io); void (*set_feature_report)(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io);
} platform_vtbl; } 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 */ /* HID Plug and Play Bus */
DEVICE_OBJECT *bus_create_hid_device(const WCHAR *busidW, WORD vid, WORD pid, DEVICE_OBJECT *bus_create_hid_device(const WCHAR *busidW, WORD vid, WORD pid, WORD input,
WORD input, DWORD version, DWORD uid, const WCHAR *serialW, BOOL is_gamepad, DWORD version, DWORD uid, const WCHAR *serialW, BOOL is_gamepad,
const platform_vtbl *vtbl, DWORD platform_data_size) DECLSPEC_HIDDEN; 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; 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 bus_unlink_hid_device(DEVICE_OBJECT *device) DECLSPEC_HIDDEN;
void process_hid_report(DEVICE_OBJECT *device, BYTE *report, DWORD length) DECLSPEC_HIDDEN; void process_hid_report(DEVICE_OBJECT *device, BYTE *report, DWORD length) DECLSPEC_HIDDEN;
......
...@@ -103,13 +103,19 @@ static struct iohid_bus_options options; ...@@ -103,13 +103,19 @@ static struct iohid_bus_options options;
struct platform_private struct platform_private
{ {
struct unix_device unix_device;
IOHIDDeviceRef device; IOHIDDeviceRef device;
uint8_t *buffer; 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) 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) static void CFStringToWSTR(CFStringRef cstr, LPWSTR wstr, int length)
...@@ -137,6 +143,8 @@ static void handle_IOHIDDeviceIOHIDReportCallback(void *context, ...@@ -137,6 +143,8 @@ static void handle_IOHIDDeviceIOHIDReportCallback(void *context,
static void free_device(DEVICE_OBJECT *device) 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) static int compare_platform_device(DEVICE_OBJECT *device, void *platform_dev)
...@@ -285,6 +293,7 @@ static const platform_vtbl iohid_vtbl = ...@@ -285,6 +293,7 @@ static const platform_vtbl iohid_vtbl =
static void handle_DeviceMatchingCallback(void *context, IOReturn result, void *sender, IOHIDDeviceRef IOHIDDevice) static void handle_DeviceMatchingCallback(void *context, IOReturn result, void *sender, IOHIDDeviceRef IOHIDDevice)
{ {
struct platform_private *private;
DEVICE_OBJECT *device; DEVICE_OBJECT *device;
DWORD vid, pid, version, uid; DWORD vid, pid, version, uid;
CFStringRef str = NULL; CFStringRef str = NULL;
...@@ -355,14 +364,14 @@ static void handle_DeviceMatchingCallback(void *context, IOReturn result, void * ...@@ -355,14 +364,14 @@ static void handle_DeviceMatchingCallback(void *context, IOReturn result, void *
if (is_gamepad) if (is_gamepad)
input = 0; input = 0;
device = bus_create_hid_device(busidW, vid, pid, input, if (!(private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct platform_private))))
version, uid, str ? serial_string : NULL, is_gamepad, return;
&iohid_vtbl, sizeof(struct platform_private));
if (!device) device = bus_create_hid_device(busidW, vid, pid, input, version, uid, str ? serial_string : NULL,
ERR("Failed to create device\n"); is_gamepad, &iohid_vtbl, &private->unix_device);
if (!device) HeapFree(GetProcessHeap(), 0, private);
else else
{ {
struct platform_private *private = impl_from_DEVICE_OBJECT(device);
private->device = IOHIDDevice; private->device = IOHIDDevice;
private->buffer = NULL; private->buffer = NULL;
IoInvalidateDeviceRelations(bus_pdo, BusRelations); IoInvalidateDeviceRelations(bus_pdo, BusRelations);
......
...@@ -110,6 +110,8 @@ static Uint16 (*pSDL_JoystickGetVendor)(SDL_Joystick * joystick); ...@@ -110,6 +110,8 @@ static Uint16 (*pSDL_JoystickGetVendor)(SDL_Joystick * joystick);
struct platform_private struct platform_private
{ {
struct unix_device unix_device;
SDL_Joystick *sdl_joystick; SDL_Joystick *sdl_joystick;
SDL_GameController *sdl_controller; SDL_GameController *sdl_controller;
SDL_JoystickID id; SDL_JoystickID id;
...@@ -128,9 +130,14 @@ struct platform_private ...@@ -128,9 +130,14 @@ struct platform_private
int haptic_effect_id; 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) 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 #define CONTROLLER_NUM_BUTTONS 11
...@@ -479,6 +486,8 @@ static void free_device(DEVICE_OBJECT *device) ...@@ -479,6 +486,8 @@ static void free_device(DEVICE_OBJECT *device)
pSDL_GameControllerClose(ext->sdl_controller); pSDL_GameControllerClose(ext->sdl_controller);
if (ext->sdl_haptic) if (ext->sdl_haptic)
pSDL_HapticClose(ext->sdl_haptic); pSDL_HapticClose(ext->sdl_haptic);
HeapFree(GetProcessHeap(), 0, ext);
} }
static int compare_platform_device(DEVICE_OBJECT *device, void *context) static int compare_platform_device(DEVICE_OBJECT *device, void *context)
...@@ -730,6 +739,7 @@ static void try_remove_device(DEVICE_OBJECT *device) ...@@ -730,6 +739,7 @@ static void try_remove_device(DEVICE_OBJECT *device)
static void try_add_device(unsigned int index) static void try_add_device(unsigned int index)
{ {
DWORD vid = 0, pid = 0, version = 0; DWORD vid = 0, pid = 0, version = 0;
struct platform_private *private;
DEVICE_OBJECT *device = NULL; DEVICE_OBJECT *device = NULL;
WCHAR serial[34] = {0}; WCHAR serial[34] = {0};
char guid_str[34]; char guid_str[34];
...@@ -788,21 +798,18 @@ static void try_add_device(unsigned int index) ...@@ -788,21 +798,18 @@ static void try_add_device(unsigned int index)
if (is_xbox_gamepad) if (is_xbox_gamepad)
input = 0; input = 0;
device = bus_create_hid_device(sdl_busidW, vid, pid, input, version, index, if (!(private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*private)))) return;
serial, is_xbox_gamepad, &sdl_vtbl, sizeof(struct platform_private));
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_joystick = joystick;
private->sdl_controller = controller; private->sdl_controller = controller;
private->id = id; private->id = id;
IoInvalidateDeviceRelations(bus_pdo, BusRelations); IoInvalidateDeviceRelations(bus_pdo, BusRelations);
} }
else
{
WARN("Ignoring device %i\n", id);
}
} }
static void process_device_event(SDL_Event *event) static void process_device_event(SDL_Event *event)
......
...@@ -99,6 +99,8 @@ static struct udev_bus_options options; ...@@ -99,6 +99,8 @@ static struct udev_bus_options options;
struct platform_private struct platform_private
{ {
struct unix_device unix_device;
struct udev_device *udev_device; struct udev_device *udev_device;
int device_fd; int device_fd;
...@@ -106,9 +108,14 @@ struct platform_private ...@@ -106,9 +108,14 @@ struct platform_private
int control_pipe[2]; 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) 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 #ifdef HAS_PROPER_INPUT_HEADER
...@@ -550,6 +557,8 @@ static void hidraw_free_device(DEVICE_OBJECT *device) ...@@ -550,6 +557,8 @@ static void hidraw_free_device(DEVICE_OBJECT *device)
close(private->device_fd); close(private->device_fd);
udev_device_unref(private->udev_device); udev_device_unref(private->udev_device);
HeapFree(GetProcessHeap(), 0, private);
} }
static int compare_platform_device(DEVICE_OBJECT *device, void *platform_dev) static int compare_platform_device(DEVICE_OBJECT *device, void *platform_dev)
...@@ -833,7 +842,7 @@ static const platform_vtbl hidraw_vtbl = ...@@ -833,7 +842,7 @@ static const platform_vtbl hidraw_vtbl =
static inline struct wine_input_private *input_impl_from_DEVICE_OBJECT(DEVICE_OBJECT *device) 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) static void lnxev_free_device(DEVICE_OBJECT *device)
...@@ -855,6 +864,8 @@ static void lnxev_free_device(DEVICE_OBJECT *device) ...@@ -855,6 +864,8 @@ static void lnxev_free_device(DEVICE_OBJECT *device)
close(ext->base.device_fd); close(ext->base.device_fd);
udev_device_unref(ext->base.udev_device); udev_device_unref(ext->base.udev_device);
HeapFree(GetProcessHeap(), 0, ext);
} }
static DWORD CALLBACK lnxev_device_report_thread(void *args); static DWORD CALLBACK lnxev_device_report_thread(void *args);
...@@ -1050,6 +1061,7 @@ static void get_device_subsystem_info(struct udev_device *dev, char const *subsy ...@@ -1050,6 +1061,7 @@ static void get_device_subsystem_info(struct udev_device *dev, char const *subsy
static void try_add_device(struct udev_device *dev) static void try_add_device(struct udev_device *dev)
{ {
DWORD vid = 0, pid = 0, version = 0, input = -1; DWORD vid = 0, pid = 0, version = 0, input = -1;
struct platform_private *private;
DEVICE_OBJECT *device = NULL; DEVICE_OBJECT *device = NULL;
const char *subsystem; const char *subsystem;
const char *devnode; const char *devnode;
...@@ -1127,20 +1139,25 @@ static void try_add_device(struct udev_device *dev) ...@@ -1127,20 +1139,25 @@ static void try_add_device(struct udev_device *dev)
if (strcmp(subsystem, "hidraw") == 0) if (strcmp(subsystem, "hidraw") == 0)
{ {
device = bus_create_hid_device(hidraw_busidW, vid, pid, input, version, 0, serial, is_gamepad, if (!(private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct platform_private))))
&hidraw_vtbl, 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 #ifdef HAS_PROPER_INPUT_HEADER
else if (strcmp(subsystem, "input") == 0) else if (strcmp(subsystem, "input") == 0)
{ {
device = bus_create_hid_device(lnxev_busidW, vid, pid, input, version, 0, serial, is_gamepad, if (!(private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct wine_input_private))))
&lnxev_vtbl, 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 #endif
if (device) if (device)
{ {
struct platform_private *private = impl_from_DEVICE_OBJECT(device);
private->udev_device = udev_device_ref(dev); private->udev_device = udev_device_ref(dev);
private->device_fd = fd; private->device_fd = fd;
IoInvalidateDeviceRelations(bus_pdo, BusRelations); IoInvalidateDeviceRelations(bus_pdo, BusRelations);
......
...@@ -139,7 +139,7 @@ struct device_extension ...@@ -139,7 +139,7 @@ struct device_extension
DWORD buffer_size; DWORD buffer_size;
LIST_ENTRY irp_queue; LIST_ENTRY irp_queue;
BYTE platform_private[1]; struct unix_device *unix_device;
}; };
static CRITICAL_SECTION device_list_cs; static CRITICAL_SECTION device_list_cs;
...@@ -171,10 +171,10 @@ static inline WCHAR *strdupW(const WCHAR *src) ...@@ -171,10 +171,10 @@ static inline WCHAR *strdupW(const WCHAR *src)
return dst; 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; 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) static DWORD get_device_index(WORD vid, WORD pid, WORD input)
...@@ -260,9 +260,9 @@ static void remove_pending_irps(DEVICE_OBJECT *device) ...@@ -260,9 +260,9 @@ static void remove_pending_irps(DEVICE_OBJECT *device)
} }
} }
DEVICE_OBJECT *bus_create_hid_device(const WCHAR *busidW, WORD vid, WORD pid, DEVICE_OBJECT *bus_create_hid_device(const WCHAR *busidW, WORD vid, WORD pid, WORD input,
WORD input, DWORD version, DWORD uid, const WCHAR *serialW, BOOL is_gamepad, DWORD version, DWORD uid, const WCHAR *serialW, BOOL is_gamepad,
const platform_vtbl *vtbl, DWORD platform_data_size) const platform_vtbl *vtbl, struct unix_device *unix_device)
{ {
static const WCHAR device_name_fmtW[] = {'\\','D','e','v','i','c','e','\\','%','s','#','%','p',0}; static const WCHAR device_name_fmtW[] = {'\\','D','e','v','i','c','e','\\','%','s','#','%','p',0};
struct device_extension *ext; struct device_extension *ext;
...@@ -271,19 +271,17 @@ DEVICE_OBJECT *bus_create_hid_device(const WCHAR *busidW, WORD vid, WORD pid, ...@@ -271,19 +271,17 @@ DEVICE_OBJECT *bus_create_hid_device(const WCHAR *busidW, WORD vid, WORD pid,
UNICODE_STRING nameW; UNICODE_STRING nameW;
WCHAR dev_name[256]; WCHAR dev_name[256];
NTSTATUS status; NTSTATUS status;
DWORD length;
TRACE("(%s, %04x, %04x, %04x, %u, %u, %s, %u, %p, %u)\n", TRACE("bus_id %s, vid %04x, pid %04x, input %04x, version %u, uid %u, serial %s, "
debugstr_w(busidW), vid, pid, input, version, uid, debugstr_w(serialW), "is_gamepad %u, vtbl %p, unix_device %p\n", debugstr_w(busidW), vid, pid, input,
is_gamepad, vtbl, platform_data_size); version, uid, debugstr_w(serialW), is_gamepad, vtbl, unix_device);
if (!(pnp_dev = HeapAlloc(GetProcessHeap(), 0, sizeof(*pnp_dev)))) if (!(pnp_dev = HeapAlloc(GetProcessHeap(), 0, sizeof(*pnp_dev))))
return NULL; return NULL;
sprintfW(dev_name, device_name_fmtW, busidW, pnp_dev); sprintfW(dev_name, device_name_fmtW, busidW, pnp_dev);
RtlInitUnicodeString(&nameW, dev_name); RtlInitUnicodeString(&nameW, dev_name);
length = FIELD_OFFSET(struct device_extension, platform_private[platform_data_size]); status = IoCreateDevice(driver_obj, sizeof(struct device_extension), &nameW, 0, 0, FALSE, &device);
status = IoCreateDevice(driver_obj, length, &nameW, 0, 0, FALSE, &device);
if (status) if (status)
{ {
FIXME("failed to create device error %x\n", status); FIXME("failed to create device error %x\n", status);
...@@ -310,8 +308,7 @@ DEVICE_OBJECT *bus_create_hid_device(const WCHAR *busidW, WORD vid, WORD pid, ...@@ -310,8 +308,7 @@ DEVICE_OBJECT *bus_create_hid_device(const WCHAR *busidW, WORD vid, WORD pid,
ext->last_report_size = 0; ext->last_report_size = 0;
ext->last_report_read = TRUE; ext->last_report_read = TRUE;
ext->buffer_size = 0; ext->buffer_size = 0;
ext->unix_device = unix_device;
memset(ext->platform_private, 0, platform_data_size);
InitializeListHead(&ext->irp_queue); InitializeListHead(&ext->irp_queue);
InitializeCriticalSection(&ext->cs); InitializeCriticalSection(&ext->cs);
......
...@@ -27,6 +27,10 @@ ...@@ -27,6 +27,10 @@
#include "unixlib.h" #include "unixlib.h"
struct unix_device
{
};
extern NTSTATUS sdl_bus_init(void *) DECLSPEC_HIDDEN; extern NTSTATUS sdl_bus_init(void *) DECLSPEC_HIDDEN;
extern NTSTATUS sdl_bus_wait(void *) DECLSPEC_HIDDEN; extern NTSTATUS sdl_bus_wait(void *) DECLSPEC_HIDDEN;
extern NTSTATUS sdl_bus_stop(void *) DECLSPEC_HIDDEN; extern NTSTATUS sdl_bus_stop(void *) DECLSPEC_HIDDEN;
......
...@@ -44,6 +44,8 @@ struct iohid_bus_options ...@@ -44,6 +44,8 @@ struct iohid_bus_options
{ {
}; };
struct unix_device;
enum unix_funcs enum unix_funcs
{ {
sdl_init, sdl_init,
......
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