Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/Makefile.in | 2 +- dlls/winebus.sys/bus_iohid.c | 16 +++++++----- dlls/winebus.sys/bus_sdl.c | 16 +++++++----- dlls/winebus.sys/bus_udev.c | 16 +++++++----- dlls/winebus.sys/hid.c | 4 +++ dlls/winebus.sys/main.c | 43 ++++++++++++++++++++------------- dlls/winebus.sys/unix_private.h | 18 +++++++------- dlls/winebus.sys/unixlib.c | 29 +++++++++++++++------- dlls/winebus.sys/unixlib.h | 3 +-- 9 files changed, 91 insertions(+), 56 deletions(-)
diff --git a/dlls/winebus.sys/Makefile.in b/dlls/winebus.sys/Makefile.in index 658d27b70fd..1675bf1951c 100644 --- a/dlls/winebus.sys/Makefile.in +++ b/dlls/winebus.sys/Makefile.in @@ -2,7 +2,7 @@ MODULE = winebus.sys IMPORTS = ntoskrnl advapi32 EXTRALIBS = $(IOKIT_LIBS) $(UDEV_LIBS) EXTRAINCL = $(UDEV_CFLAGS) $(SDL2_CFLAGS) -EXTRADLLFLAGS = -Wl,--subsystem,native +EXTRADLLFLAGS = -mno-cygwin -Wl,--subsystem,native
C_SRCS = \ bus_iohid.c \ diff --git a/dlls/winebus.sys/bus_iohid.c b/dlls/winebus.sys/bus_iohid.c index 8e6cb0a5ee9..0e36eac880c 100644 --- a/dlls/winebus.sys/bus_iohid.c +++ b/dlls/winebus.sys/bus_iohid.c @@ -17,6 +17,10 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
+#if 0 +#pragma makedep unix +#endif + #include "config.h" #include "wine/port.h"
@@ -371,7 +375,7 @@ static void handle_RemovalCallback(void *context, IOReturn result, void *sender, else WARN("failed to find device for iohid device %p\n", IOHIDDevice); }
-NTSTATUS iohid_bus_init(void *args) +NTSTATUS WINAPI iohid_bus_init(void *args) { TRACE("args %p\n", args);
@@ -392,7 +396,7 @@ NTSTATUS iohid_bus_init(void *args) return STATUS_SUCCESS; }
-NTSTATUS iohid_bus_wait(void *args) +NTSTATUS WINAPI iohid_bus_wait(void *args) { struct bus_event *result = args; CFRunLoopRunResult ret; @@ -416,7 +420,7 @@ NTSTATUS iohid_bus_wait(void *args) return STATUS_SUCCESS; }
-NTSTATUS iohid_bus_stop(void *args) +NTSTATUS WINAPI iohid_bus_stop(void *args) { if (!run_loop) return STATUS_SUCCESS;
@@ -427,19 +431,19 @@ NTSTATUS iohid_bus_stop(void *args)
#else
-NTSTATUS iohid_bus_init(void *args) +NTSTATUS WINAPI iohid_bus_init(void *args) { WARN("IOHID support not compiled in!\n"); return STATUS_NOT_IMPLEMENTED; }
-NTSTATUS iohid_bus_wait(void *args) +NTSTATUS WINAPI iohid_bus_wait(void *args) { WARN("IOHID support not compiled in!\n"); return STATUS_NOT_IMPLEMENTED; }
-NTSTATUS iohid_bus_stop(void *args) +NTSTATUS WINAPI iohid_bus_stop(void *args) { WARN("IOHID support not compiled in!\n"); return STATUS_NOT_IMPLEMENTED; diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c index 785d1045622..79dff5007c0 100644 --- a/dlls/winebus.sys/bus_sdl.c +++ b/dlls/winebus.sys/bus_sdl.c @@ -18,6 +18,10 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
+#if 0 +#pragma makedep unix +#endif + #include "config.h" #include "wine/port.h" #include <errno.h> @@ -814,7 +818,7 @@ static void process_device_event(SDL_Event *event) RtlLeaveCriticalSection(&sdl_cs); }
-NTSTATUS sdl_bus_init(void *args) +NTSTATUS WINAPI sdl_bus_init(void *args) { const char *mapping; int i; @@ -917,7 +921,7 @@ failed: return STATUS_UNSUCCESSFUL; }
-NTSTATUS sdl_bus_wait(void *args) +NTSTATUS WINAPI sdl_bus_wait(void *args) { struct bus_event *result = args; SDL_Event event; @@ -939,7 +943,7 @@ NTSTATUS sdl_bus_wait(void *args) return STATUS_SUCCESS; }
-NTSTATUS sdl_bus_stop(void *args) +NTSTATUS WINAPI sdl_bus_stop(void *args) { SDL_Event event;
@@ -957,19 +961,19 @@ NTSTATUS sdl_bus_stop(void *args)
#else
-NTSTATUS sdl_bus_init(void *args) +NTSTATUS WINAPI sdl_bus_init(void *args) { WARN("SDL support not compiled in!\n"); return STATUS_NOT_IMPLEMENTED; }
-NTSTATUS sdl_bus_wait(void *args) +NTSTATUS WINAPI sdl_bus_wait(void *args) { WARN("SDL support not compiled in!\n"); return STATUS_NOT_IMPLEMENTED; }
-NTSTATUS sdl_bus_stop(void *args) +NTSTATUS WINAPI sdl_bus_stop(void *args) { WARN("SDL support not compiled in!\n"); return STATUS_NOT_IMPLEMENTED; diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c index 2cb727d8216..c859d5df546 100644 --- a/dlls/winebus.sys/bus_udev.c +++ b/dlls/winebus.sys/bus_udev.c @@ -18,6 +18,10 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
+#if 0 +#pragma makedep unix +#endif + #include "config.h" #include <errno.h> #include <fcntl.h> @@ -1184,7 +1188,7 @@ static void process_monitor_event(struct udev_monitor *monitor) udev_device_unref(dev); }
-NTSTATUS udev_bus_init(void *args) +NTSTATUS WINAPI udev_bus_init(void *args) { int monitor_fd;
@@ -1229,7 +1233,7 @@ error: return STATUS_UNSUCCESSFUL; }
-NTSTATUS udev_bus_wait(void *args) +NTSTATUS WINAPI udev_bus_wait(void *args) { struct platform_private *device; struct bus_event *result = args; @@ -1275,7 +1279,7 @@ NTSTATUS udev_bus_wait(void *args) return STATUS_SUCCESS; }
-NTSTATUS udev_bus_stop(void *args) +NTSTATUS WINAPI udev_bus_stop(void *args) { if (!udev_context) return STATUS_SUCCESS; write(deviceloop_control[1], "q", 1); @@ -1284,19 +1288,19 @@ NTSTATUS udev_bus_stop(void *args)
#else
-NTSTATUS udev_bus_init(void *args) +NTSTATUS WINAPI udev_bus_init(void *args) { WARN("UDEV support not compiled in!\n"); return STATUS_NOT_IMPLEMENTED; }
-NTSTATUS udev_bus_wait(void *args) +NTSTATUS WINAPI udev_bus_wait(void *args) { WARN("UDEV support not compiled in!\n"); return STATUS_NOT_IMPLEMENTED; }
-NTSTATUS udev_bus_stop(void *args) +NTSTATUS WINAPI udev_bus_stop(void *args) { WARN("UDEV support not compiled in!\n"); return STATUS_NOT_IMPLEMENTED; diff --git a/dlls/winebus.sys/hid.c b/dlls/winebus.sys/hid.c index 27c85d4f5a6..959cbf7c428 100644 --- a/dlls/winebus.sys/hid.c +++ b/dlls/winebus.sys/hid.c @@ -18,6 +18,10 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
+#if 0 +#pragma makedep unix +#endif + #include <stdarg.h>
#include "ntstatus.h" diff --git a/dlls/winebus.sys/main.c b/dlls/winebus.sys/main.c index d19a2b7cb6c..5fd7744c259 100644 --- a/dlls/winebus.sys/main.c +++ b/dlls/winebus.sys/main.c @@ -17,11 +17,14 @@ * 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 "winnls.h" #include "winternl.h" #include "winioctl.h" #include "hidusage.h" @@ -30,7 +33,6 @@ #include "ddk/hidtypes.h" #include "wine/asm.h" #include "wine/debug.h" -#include "wine/unicode.h" #include "wine/list.h" #include "wine/unixlib.h"
@@ -109,9 +111,12 @@ static CRITICAL_SECTION device_list_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
static struct list device_list = LIST_INIT(device_list);
+static HMODULE instance; +static const unix_entry_point *unix_funcs; + static NTSTATUS winebus_call(unsigned int code, void *args) { - return __wine_unix_call_funcs[code]( args ); + return unix_funcs[code]( args ); }
static void unix_device_remove(DEVICE_OBJECT *device) @@ -193,11 +198,11 @@ static WCHAR *get_instance_id(DEVICE_OBJECT *device) { static const WCHAR formatW[] = {'%','i','&','%','s','&','%','x','&','%','i',0}; struct device_extension *ext = (struct device_extension *)device->DeviceExtension; - DWORD len = strlenW(ext->serialnumber) + 33; + DWORD len = wcslen(ext->serialnumber) + 33; WCHAR *dst;
if ((dst = ExAllocatePool(PagedPool, len * sizeof(WCHAR)))) - sprintfW(dst, formatW, ext->desc.version, ext->serialnumber, ext->desc.uid, ext->index); + swprintf(dst, len, formatW, ext->desc.version, ext->serialnumber, ext->desc.uid, ext->index);
return dst; } @@ -208,13 +213,13 @@ static WCHAR *get_device_id(DEVICE_OBJECT *device) static const WCHAR formatW[] = {'%','s','\','v','i','d','_','%','0','4','x', '&','p','i','d','_','%','0','4','x',0}; struct device_extension *ext = (struct device_extension *)device->DeviceExtension; - DWORD len = strlenW(ext->desc.busid) + 34; - WCHAR *dst, *tmp; + DWORD pos = 0, len = wcslen(ext->desc.busid) + 34; + WCHAR *dst;
if ((dst = ExAllocatePool(PagedPool, len * sizeof(WCHAR)))) { - tmp = dst + sprintfW(dst, formatW, ext->desc.busid, ext->desc.vid, ext->desc.pid); - if (ext->desc.input != -1) sprintfW(tmp, input_formatW, ext->desc.input); + pos += swprintf(dst + pos, len - pos, formatW, ext->desc.busid, ext->desc.vid, ext->desc.pid); + if (ext->desc.input != -1) pos += swprintf(dst + pos, len - pos, input_formatW, ext->desc.input); }
return dst; @@ -225,10 +230,10 @@ static WCHAR *get_hardware_ids(DEVICE_OBJECT *device) struct device_extension *ext = (struct device_extension *)device->DeviceExtension; WCHAR *dst;
- if ((dst = ExAllocatePool(PagedPool, (strlenW(ext->desc.busid) + 2) * sizeof(WCHAR)))) + if ((dst = ExAllocatePool(PagedPool, (wcslen(ext->desc.busid) + 2) * sizeof(WCHAR)))) { - strcpyW(dst, ext->desc.busid); - dst[strlenW(dst) + 1] = 0; + wcscpy(dst, ext->desc.busid); + dst[wcslen(dst) + 1] = 0; }
return dst; @@ -285,7 +290,7 @@ static DEVICE_OBJECT *bus_create_hid_device(struct device_desc *desc, struct uni
TRACE("desc %s, unix_device %p\n", debugstr_device_desc(desc), unix_device);
- sprintfW(dev_name, device_name_fmtW, desc->busid, unix_device); + swprintf(dev_name, ARRAY_SIZE(dev_name), device_name_fmtW, desc->busid, unix_device); RtlInitUnicodeString(&nameW, dev_name); status = IoCreateDevice(driver_obj, sizeof(struct device_extension), &nameW, 0, 0, FALSE, &device); if (status) @@ -900,17 +905,17 @@ static NTSTATUS hid_get_device_string(DEVICE_OBJECT *device, DWORD index, WCHAR switch (index) { case HID_STRING_ID_IMANUFACTURER: - len = (strlenW(ext->manufacturer) + 1) * sizeof(WCHAR); + len = (wcslen(ext->manufacturer) + 1) * sizeof(WCHAR); if (len > buffer_len) return STATUS_BUFFER_TOO_SMALL; else memcpy(buffer, ext->manufacturer, len); return STATUS_SUCCESS; case HID_STRING_ID_IPRODUCT: - len = (strlenW(ext->product) + 1) * sizeof(WCHAR); + len = (wcslen(ext->product) + 1) * sizeof(WCHAR); if (len > buffer_len) return STATUS_BUFFER_TOO_SMALL; else memcpy(buffer, ext->product, len); return STATUS_SUCCESS; case HID_STRING_ID_ISERIALNUMBER: - len = (strlenW(ext->serialnumber) + 1) * sizeof(WCHAR); + len = (wcslen(ext->serialnumber) + 1) * sizeof(WCHAR); if (len > buffer_len) return STATUS_BUFFER_TOO_SMALL; else memcpy(buffer, ext->serialnumber, len); return STATUS_SUCCESS; @@ -1012,7 +1017,7 @@ static NTSTATUS WINAPI hid_internal_dispatch(DEVICE_OBJECT *device, IRP *irp)
irp->IoStatus.Status = hid_get_device_string(device, index, (WCHAR *)irp->UserBuffer, buffer_len); if (irp->IoStatus.Status == STATUS_SUCCESS) - irp->IoStatus.Information = (strlenW((WCHAR *)irp->UserBuffer) + 1) * sizeof(WCHAR); + irp->IoStatus.Information = (wcslen((WCHAR *)irp->UserBuffer) + 1) * sizeof(WCHAR); break; } case IOCTL_HID_GET_INPUT_REPORT: @@ -1110,6 +1115,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/unix_private.h b/dlls/winebus.sys/unix_private.h index cdc2be9b318..5e30b21955a 100644 --- a/dlls/winebus.sys/unix_private.h +++ b/dlls/winebus.sys/unix_private.h @@ -49,17 +49,17 @@ struct unix_device
extern void *unix_device_create(const struct unix_device_vtbl *vtbl, SIZE_T size) DECLSPEC_HIDDEN;
-extern NTSTATUS sdl_bus_init(void *) DECLSPEC_HIDDEN; -extern NTSTATUS sdl_bus_wait(void *) DECLSPEC_HIDDEN; -extern NTSTATUS sdl_bus_stop(void *) DECLSPEC_HIDDEN; +extern NTSTATUS WINAPI sdl_bus_init(void *) DECLSPEC_HIDDEN; +extern NTSTATUS WINAPI sdl_bus_wait(void *) DECLSPEC_HIDDEN; +extern NTSTATUS WINAPI sdl_bus_stop(void *) DECLSPEC_HIDDEN;
-extern NTSTATUS udev_bus_init(void *) DECLSPEC_HIDDEN; -extern NTSTATUS udev_bus_wait(void *) DECLSPEC_HIDDEN; -extern NTSTATUS udev_bus_stop(void *) DECLSPEC_HIDDEN; +extern NTSTATUS WINAPI udev_bus_init(void *) DECLSPEC_HIDDEN; +extern NTSTATUS WINAPI udev_bus_wait(void *) DECLSPEC_HIDDEN; +extern NTSTATUS WINAPI udev_bus_stop(void *) DECLSPEC_HIDDEN;
-extern NTSTATUS iohid_bus_init(void *) DECLSPEC_HIDDEN; -extern NTSTATUS iohid_bus_wait(void *) DECLSPEC_HIDDEN; -extern NTSTATUS iohid_bus_stop(void *) DECLSPEC_HIDDEN; +extern NTSTATUS WINAPI iohid_bus_init(void *) DECLSPEC_HIDDEN; +extern NTSTATUS WINAPI iohid_bus_wait(void *) DECLSPEC_HIDDEN; +extern NTSTATUS WINAPI iohid_bus_stop(void *) DECLSPEC_HIDDEN;
extern void bus_event_cleanup(struct bus_event *event) DECLSPEC_HIDDEN; extern void bus_event_queue_destroy(struct list *queue) DECLSPEC_HIDDEN; diff --git a/dlls/winebus.sys/unixlib.c b/dlls/winebus.sys/unixlib.c index 651b23aa8f4..f21b5a25b04 100644 --- a/dlls/winebus.sys/unixlib.c +++ b/dlls/winebus.sys/unixlib.c @@ -16,6 +16,10 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
+#if 0 +#pragma makedep unix +#endif + #include "config.h"
#include <stdarg.h> @@ -143,7 +147,7 @@ static const struct device_desc mouse_device_desc = .serialnumber = {"0000"}, };
-static NTSTATUS mouse_device_create(void *args) +static NTSTATUS WINAPI mouse_device_create(void *args) { struct device_create_params *params = args; params->desc = mouse_device_desc; @@ -241,7 +245,7 @@ static const struct device_desc keyboard_device_desc = .serialnumber = {"0000"}, };
-static NTSTATUS keyboard_device_create(void *args) +static NTSTATUS WINAPI keyboard_device_create(void *args) { struct device_create_params *params = args; params->desc = keyboard_device_desc; @@ -274,7 +278,7 @@ static ULONG unix_device_incref(struct unix_device *iface) return InterlockedIncrement(&iface->ref); }
-static NTSTATUS unix_device_remove(void *args) +static NTSTATUS WINAPI unix_device_remove(void *args) { struct unix_device *iface = args; iface->vtbl->stop(iface); @@ -282,20 +286,20 @@ static NTSTATUS unix_device_remove(void *args) return STATUS_SUCCESS; }
-static NTSTATUS unix_device_start(void *args) +static NTSTATUS WINAPI unix_device_start(void *args) { struct unix_device *iface = args; return iface->vtbl->start(iface); }
-static NTSTATUS unix_device_get_report_descriptor(void *args) +static NTSTATUS WINAPI unix_device_get_report_descriptor(void *args) { struct device_descriptor_params *params = args; struct unix_device *iface = params->iface; return iface->vtbl->get_report_descriptor(iface, params->buffer, params->length, params->out_length); }
-static NTSTATUS unix_device_set_output_report(void *args) +static NTSTATUS WINAPI unix_device_set_output_report(void *args) { struct device_report_params *params = args; struct unix_device *iface = params->iface; @@ -303,7 +307,7 @@ static NTSTATUS unix_device_set_output_report(void *args) return STATUS_SUCCESS; }
-static NTSTATUS unix_device_get_feature_report(void *args) +static NTSTATUS WINAPI unix_device_get_feature_report(void *args) { struct device_report_params *params = args; struct unix_device *iface = params->iface; @@ -311,7 +315,7 @@ static NTSTATUS unix_device_get_feature_report(void *args) return STATUS_SUCCESS; }
-static NTSTATUS unix_device_set_feature_report(void *args) +static NTSTATUS WINAPI unix_device_set_feature_report(void *args) { struct device_report_params *params = args; struct unix_device *iface = params->iface; @@ -319,7 +323,7 @@ static NTSTATUS unix_device_set_feature_report(void *args) return STATUS_SUCCESS; }
-const unixlib_entry_t __wine_unix_call_funcs[] = +static const unix_entry_point unix_funcs[] = { sdl_bus_init, sdl_bus_wait, @@ -424,3 +428,10 @@ BOOL bus_event_queue_pop(struct list *queue, struct bus_event *event)
return TRUE; } + +NTSTATUS CDECL __wine_init_unix_lib( HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out ) +{ + if (reason != DLL_PROCESS_ATTACH) return STATUS_SUCCESS; + *(const unix_entry_point **)ptr_out = unix_funcs; + return STATUS_SUCCESS; +} diff --git a/dlls/winebus.sys/unixlib.h b/dlls/winebus.sys/unixlib.h index 55ba42500cf..e5156176c46 100644 --- a/dlls/winebus.sys/unixlib.h +++ b/dlls/winebus.sys/unixlib.h @@ -29,7 +29,6 @@
#include "wine/debug.h" #include "wine/list.h" -#include "wine/unixlib.h"
struct device_desc { @@ -137,7 +136,7 @@ enum unix_funcs device_set_feature_report, };
-extern const unixlib_entry_t __wine_unix_call_funcs[] DECLSPEC_HIDDEN; +typedef NTSTATUS (WINAPI *unix_entry_point)(void *);
static inline const char *debugstr_device_desc(struct device_desc *desc) {
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus_iohid.c | 2 +- dlls/winebus.sys/bus_sdl.c | 10 ++++------ dlls/winebus.sys/bus_udev.c | 14 ++++++-------- dlls/winebus.sys/hid.c | 8 ++++---- dlls/winebus.sys/unixlib.c | 16 +++++++++------- 5 files changed, 24 insertions(+), 26 deletions(-)
diff --git a/dlls/winebus.sys/bus_iohid.c b/dlls/winebus.sys/bus_iohid.c index 0e36eac880c..70a7cd0b005 100644 --- a/dlls/winebus.sys/bus_iohid.c +++ b/dlls/winebus.sys/bus_iohid.c @@ -172,7 +172,7 @@ static NTSTATUS iohid_device_start(struct unix_device *iface)
num = IOHIDDeviceGetProperty(private->device, CFSTR(kIOHIDMaxInputReportSizeKey)); length = CFNumberToDWORD(num); - private->buffer = RtlAllocateHeap(GetProcessHeap(), 0, length); + private->buffer = malloc(length);
IOHIDDeviceRegisterInputReportCallback(private->device, private->buffer, length, handle_IOHIDDeviceIOHIDReportCallback, iface); return STATUS_SUCCESS; diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c index 79dff5007c0..956340faf02 100644 --- a/dlls/winebus.sys/bus_sdl.c +++ b/dlls/winebus.sys/bus_sdl.c @@ -374,8 +374,7 @@ static NTSTATUS build_report_descriptor(struct platform_private *ext) return STATUS_NO_MEMORY;
ext->buffer_length = report_size; - if (!(ext->report_buffer = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, report_size))) - goto failed; + if (!(ext->report_buffer = calloc(1, report_size))) goto failed;
/* Initialize axis in the report */ for (i = 0; i < axis_count; i++) @@ -386,7 +385,7 @@ static NTSTATUS build_report_descriptor(struct platform_private *ext) return STATUS_SUCCESS;
failed: - RtlFreeHeap(GetProcessHeap(), 0, ext->report_buffer); + free(ext->report_buffer); hid_descriptor_free(&ext->desc); return STATUS_NO_MEMORY; } @@ -475,8 +474,7 @@ static NTSTATUS build_mapped_report_descriptor(struct platform_private *ext) if (!hid_descriptor_end(&ext->desc)) return STATUS_NO_MEMORY;
- if (!(ext->report_buffer = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, ext->buffer_length))) - goto failed; + if (!(ext->report_buffer = calloc(1, ext->buffer_length))) goto failed;
/* Initialize axis in the report */ for (i = SDL_CONTROLLER_AXIS_LEFTX; i < SDL_CONTROLLER_AXIS_MAX; i++) @@ -491,7 +489,7 @@ static NTSTATUS build_mapped_report_descriptor(struct platform_private *ext) return STATUS_SUCCESS;
failed: - RtlFreeHeap(GetProcessHeap(), 0, ext->report_buffer); + free(ext->report_buffer); hid_descriptor_free(&ext->desc); return STATUS_NO_MEMORY; } diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c index c859d5df546..928548b8893 100644 --- a/dlls/winebus.sys/bus_udev.c +++ b/dlls/winebus.sys/bus_udev.c @@ -548,10 +548,8 @@ static NTSTATUS build_report_descriptor(struct wine_input_private *ext, struct u TRACE("Report will be %i bytes\n", report_size);
ext->buffer_length = report_size; - if (!(ext->current_report_buffer = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, report_size))) - goto failed; - if (!(ext->last_report_buffer = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, report_size))) - goto failed; + if (!(ext->current_report_buffer = calloc(1, report_size))) goto failed; + if (!(ext->last_report_buffer = calloc(1, report_size))) goto failed; ext->report_state = FIRST;
/* Initialize axis in the report */ @@ -562,8 +560,8 @@ static NTSTATUS build_report_descriptor(struct wine_input_private *ext, struct u return STATUS_SUCCESS;
failed: - RtlFreeHeap(GetProcessHeap(), 0, ext->current_report_buffer); - RtlFreeHeap(GetProcessHeap(), 0, ext->last_report_buffer); + free(ext->current_report_buffer); + free(ext->last_report_buffer); hid_descriptor_free(&ext->desc); return STATUS_NO_MEMORY; } @@ -811,8 +809,8 @@ static void lnxev_device_destroy(struct unix_device *iface) { struct wine_input_private *ext = input_impl_from_unix_device(iface);
- RtlFreeHeap(GetProcessHeap(), 0, ext->current_report_buffer); - RtlFreeHeap(GetProcessHeap(), 0, ext->last_report_buffer); + free(ext->current_report_buffer); + free(ext->last_report_buffer); hid_descriptor_free(&ext->desc);
udev_device_unref(ext->base.udev_device); diff --git a/dlls/winebus.sys/hid.c b/dlls/winebus.sys/hid.c index 959cbf7c428..0ad5efa2775 100644 --- a/dlls/winebus.sys/hid.c +++ b/dlls/winebus.sys/hid.c @@ -23,6 +23,7 @@ #endif
#include <stdarg.h> +#include <stdlib.h>
#include "ntstatus.h" #define WIN32_NO_STATUS @@ -40,13 +41,12 @@ static BOOL hid_descriptor_append(struct hid_descriptor *desc, const BYTE *buffe if (desc->size + size > desc->max_size) { desc->max_size = max(desc->max_size * 3 / 2, desc->size + size); - if (!desc->data) desc->data = RtlAllocateHeap(GetProcessHeap(), 0, desc->max_size); - else desc->data = RtlReAllocateHeap(GetProcessHeap(), 0, tmp, desc->max_size); + desc->data = realloc(tmp, desc->max_size); }
if (!desc->data) { - RtlFreeHeap(GetProcessHeap(), 0, tmp); + free(tmp); return FALSE; }
@@ -93,7 +93,7 @@ BOOL hid_descriptor_end(struct hid_descriptor *desc)
void hid_descriptor_free(struct hid_descriptor *desc) { - RtlFreeHeap(GetProcessHeap(), 0, desc->data); + free(desc->data); }
BOOL hid_descriptor_add_buttons(struct hid_descriptor *desc, USAGE usage_page, diff --git a/dlls/winebus.sys/unixlib.c b/dlls/winebus.sys/unixlib.c index f21b5a25b04..f33b7cacfe3 100644 --- a/dlls/winebus.sys/unixlib.c +++ b/dlls/winebus.sys/unixlib.c @@ -23,6 +23,8 @@ #include "config.h"
#include <stdarg.h> +#include <stdlib.h> + #include "ntstatus.h" #define WIN32_NO_STATUS #include "windef.h" @@ -257,7 +259,7 @@ void *unix_device_create(const struct unix_device_vtbl *vtbl, SIZE_T size) { struct unix_device *iface;
- if (!(iface = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, size))) return NULL; + if (!(iface = calloc(1, size))) return NULL; iface->vtbl = vtbl; iface->ref = 1;
@@ -269,7 +271,7 @@ static void unix_device_decref(struct unix_device *iface) if (!InterlockedDecrement(&iface->ref)) { iface->vtbl->destroy(iface); - RtlFreeHeap(GetProcessHeap(), 0, iface); + free(iface); } }
@@ -357,14 +359,14 @@ void bus_event_queue_destroy(struct list *queue) LIST_FOR_EACH_ENTRY_SAFE(event, next, queue, struct bus_event, entry) { bus_event_cleanup(event); - RtlFreeHeap(GetProcessHeap(), 0, event); + free(event); } }
BOOL bus_event_queue_device_removed(struct list *queue, struct unix_device *device) { ULONG size = sizeof(struct bus_event); - struct bus_event *event = RtlAllocateHeap(GetProcessHeap(), 0, size); + struct bus_event *event = malloc(size); if (!event) return FALSE;
if (unix_device_incref(device) == 1) return FALSE; /* being destroyed */ @@ -379,7 +381,7 @@ BOOL bus_event_queue_device_removed(struct list *queue, struct unix_device *devi BOOL bus_event_queue_device_created(struct list *queue, struct unix_device *device, struct device_desc *desc) { ULONG size = sizeof(struct bus_event); - struct bus_event *event = RtlAllocateHeap(GetProcessHeap(), 0, size); + struct bus_event *event = malloc(size); if (!event) return FALSE;
if (unix_device_incref(device) == 1) return FALSE; /* being destroyed */ @@ -395,7 +397,7 @@ BOOL bus_event_queue_device_created(struct list *queue, struct unix_device *devi BOOL bus_event_queue_input_report(struct list *queue, struct unix_device *device, BYTE *report, USHORT length) { ULONG size = offsetof(struct bus_event, input_report.buffer[length]); - struct bus_event *event = RtlAllocateHeap(GetProcessHeap(), 0, size); + struct bus_event *event = malloc(size); if (!event) return FALSE;
if (unix_device_incref(device) == 1) return FALSE; /* being destroyed */ @@ -424,7 +426,7 @@ BOOL bus_event_queue_pop(struct list *queue, struct bus_event *event) else size = offsetof(struct bus_event, input_report.buffer[event->input_report.length]);
memcpy(event, tmp, size); - RtlFreeHeap(GetProcessHeap(), 0, tmp); + free(tmp);
return TRUE; }
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/Makefile.in | 2 +- dlls/winebus.sys/bus_iohid.c | 19 +++++++------------ dlls/winebus.sys/bus_sdl.c | 20 +++++++------------- dlls/winebus.sys/bus_udev.c | 35 +++++++++++++++-------------------- 4 files changed, 30 insertions(+), 46 deletions(-)
diff --git a/dlls/winebus.sys/Makefile.in b/dlls/winebus.sys/Makefile.in index 1675bf1951c..ec731c2b85c 100644 --- a/dlls/winebus.sys/Makefile.in +++ b/dlls/winebus.sys/Makefile.in @@ -1,6 +1,6 @@ MODULE = winebus.sys IMPORTS = ntoskrnl advapi32 -EXTRALIBS = $(IOKIT_LIBS) $(UDEV_LIBS) +EXTRALIBS = $(IOKIT_LIBS) $(UDEV_LIBS) $(PTHREAD_LIBS) EXTRAINCL = $(UDEV_CFLAGS) $(SDL2_CFLAGS) EXTRADLLFLAGS = -mno-cygwin -Wl,--subsystem,native
diff --git a/dlls/winebus.sys/bus_iohid.c b/dlls/winebus.sys/bus_iohid.c index 70a7cd0b005..8dc9e6c3df1 100644 --- a/dlls/winebus.sys/bus_iohid.c +++ b/dlls/winebus.sys/bus_iohid.c @@ -83,6 +83,8 @@ #undef PAGE_SHIFT #endif /* HAVE_IOKIT_HID_IOHIDLIB_H */
+#include <pthread.h> + #include "ntstatus.h" #define WIN32_NO_STATUS #include "windef.h" @@ -98,14 +100,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(plugplay); #ifdef HAVE_IOHIDMANAGERCREATE
-static CRITICAL_SECTION iohid_cs; -static CRITICAL_SECTION_DEBUG iohid_cs_debug = -{ - 0, 0, &iohid_cs, - { &iohid_cs_debug.ProcessLocksList, &iohid_cs_debug.ProcessLocksList }, - 0, 0, { (DWORD_PTR)(__FILE__ ": iohid_cs") } -}; -static CRITICAL_SECTION iohid_cs = { &iohid_cs_debug, -1, 0, 0, 0, 0 }; +static pthread_mutex_t iohid_cs = PTHREAD_MUTEX_INITIALIZER;
static IOHIDManagerRef hid_manager; static CFRunLoopRef run_loop; @@ -184,9 +179,9 @@ static void iohid_device_stop(struct unix_device *iface)
IOHIDDeviceRegisterInputReportCallback(private->device, NULL, 0, NULL, NULL);
- RtlEnterCriticalSection(&iohid_cs); + pthread_mutex_lock(&iohid_cs); list_remove(&private->unix_device.entry); - RtlLeaveCriticalSection(&iohid_cs); + pthread_mutex_unlock(&iohid_cs); }
static NTSTATUS iohid_device_get_report_descriptor(struct unix_device *iface, BYTE *buffer, @@ -407,9 +402,9 @@ NTSTATUS WINAPI iohid_bus_wait(void *args) do { if (bus_event_queue_pop(&event_queue, result)) return STATUS_PENDING; - RtlEnterCriticalSection(&iohid_cs); + pthread_mutex_lock(&iohid_cs); ret = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 10, TRUE); - RtlLeaveCriticalSection(&iohid_cs); + pthread_mutex_unlock(&iohid_cs); } while (ret != kCFRunLoopRunStopped);
TRACE("IOHID main loop exiting\n"); diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c index 956340faf02..b7c3b28ba4e 100644 --- a/dlls/winebus.sys/bus_sdl.c +++ b/dlls/winebus.sys/bus_sdl.c @@ -35,6 +35,8 @@ # include <SDL.h> #endif
+#include <pthread.h> + #include "ntstatus.h" #define WIN32_NO_STATUS #include "windef.h" @@ -62,15 +64,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(plugplay);
WINE_DECLARE_DEBUG_CHANNEL(hid_report);
-static CRITICAL_SECTION sdl_cs; -static CRITICAL_SECTION_DEBUG sdl_cs_debug = -{ - 0, 0, &sdl_cs, - { &sdl_cs_debug.ProcessLocksList, &sdl_cs_debug.ProcessLocksList }, - 0, 0, { (DWORD_PTR)(__FILE__ ": sdl_cs") } -}; -static CRITICAL_SECTION sdl_cs = { &sdl_cs_debug, -1, 0, 0, 0, 0 }; - +static pthread_mutex_t sdl_cs = PTHREAD_MUTEX_INITIALIZER; static const WCHAR sdl_busidW[] = {'S','D','L','J','O','Y',0}; static struct sdl_bus_options options;
@@ -513,9 +507,9 @@ static void sdl_device_stop(struct unix_device *iface) if (private->sdl_controller) pSDL_GameControllerClose(private->sdl_controller); if (private->sdl_haptic) pSDL_HapticClose(private->sdl_haptic);
- RtlEnterCriticalSection(&sdl_cs); + pthread_mutex_lock(&sdl_cs); list_remove(&private->unix_device.entry); - RtlLeaveCriticalSection(&sdl_cs); + pthread_mutex_unlock(&sdl_cs); }
static NTSTATUS sdl_device_get_reportdescriptor(struct unix_device *iface, BYTE *buffer, @@ -787,7 +781,7 @@ static void process_device_event(SDL_Event *event)
TRACE_(hid_report)("Received action %x\n", event->type);
- RtlEnterCriticalSection(&sdl_cs); + pthread_mutex_lock(&sdl_cs);
if (event->type == SDL_JOYDEVICEADDED) sdl_add_device(((SDL_JoyDeviceEvent *)event)->which); @@ -813,7 +807,7 @@ static void process_device_event(SDL_Event *event) else WARN("failed to find device with id %d\n", id); }
- RtlLeaveCriticalSection(&sdl_cs); + pthread_mutex_unlock(&sdl_cs); }
NTSTATUS WINAPI sdl_bus_init(void *args) diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c index 928548b8893..c73a6dd2259 100644 --- a/dlls/winebus.sys/bus_udev.c +++ b/dlls/winebus.sys/bus_udev.c @@ -58,6 +58,8 @@ # endif #endif
+#include <pthread.h> + #include "ntstatus.h" #define WIN32_NO_STATUS #include "windef.h" @@ -91,14 +93,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(plugplay);
WINE_DECLARE_DEBUG_CHANNEL(hid_report);
-static CRITICAL_SECTION udev_cs; -static CRITICAL_SECTION_DEBUG udev_cs_debug = -{ - 0, 0, &udev_cs, - { &udev_cs_debug.ProcessLocksList, &udev_cs_debug.ProcessLocksList }, - 0, 0, { (DWORD_PTR)(__FILE__ ": udev_cs") } -}; -static CRITICAL_SECTION udev_cs = { &udev_cs_debug, -1, 0, 0, 0, 0 }; +static pthread_mutex_t udev_cs = PTHREAD_MUTEX_INITIALIZER;
static struct udev *udev_context = NULL; static struct udev_monitor *udev_monitor; @@ -622,9 +617,9 @@ static void hidraw_device_destroy(struct unix_device *iface)
static NTSTATUS hidraw_device_start(struct unix_device *iface) { - RtlEnterCriticalSection(&udev_cs); + pthread_mutex_lock(&udev_cs); start_polling_device(iface); - RtlLeaveCriticalSection(&udev_cs); + pthread_mutex_unlock(&udev_cs); return STATUS_SUCCESS; }
@@ -632,10 +627,10 @@ static void hidraw_device_stop(struct unix_device *iface) { struct platform_private *private = impl_from_unix_device(iface);
- RtlEnterCriticalSection(&udev_cs); + pthread_mutex_lock(&udev_cs); stop_polling_device(iface); list_remove(&private->unix_device.entry); - RtlLeaveCriticalSection(&udev_cs); + pthread_mutex_unlock(&udev_cs); }
static NTSTATUS hidraw_device_get_report_descriptor(struct unix_device *iface, BYTE *buffer, @@ -824,9 +819,9 @@ static NTSTATUS lnxev_device_start(struct unix_device *iface) if ((status = build_report_descriptor(ext, ext->base.udev_device))) return status;
- RtlEnterCriticalSection(&udev_cs); + pthread_mutex_lock(&udev_cs); start_polling_device(iface); - RtlLeaveCriticalSection(&udev_cs); + pthread_mutex_unlock(&udev_cs); return STATUS_SUCCESS; }
@@ -834,10 +829,10 @@ static void lnxev_device_stop(struct unix_device *iface) { struct wine_input_private *ext = input_impl_from_unix_device(iface);
- RtlEnterCriticalSection(&udev_cs); + pthread_mutex_lock(&udev_cs); stop_polling_device(iface); list_remove(&ext->base.unix_device.entry); - RtlLeaveCriticalSection(&udev_cs); + pthread_mutex_unlock(&udev_cs); }
static NTSTATUS lnxev_device_get_report_descriptor(struct unix_device *iface, BYTE *buffer, @@ -1246,16 +1241,16 @@ NTSTATUS WINAPI udev_bus_wait(void *args) { if (bus_event_queue_pop(&event_queue, result)) return STATUS_PENDING;
- RtlEnterCriticalSection(&udev_cs); + pthread_mutex_lock(&udev_cs); while (close_count--) close(close_fds[close_count]); memcpy(pfd, poll_fds, poll_count * sizeof(*pfd)); count = poll_count; close_count = 0; - RtlLeaveCriticalSection(&udev_cs); + pthread_mutex_unlock(&udev_cs);
while (poll(pfd, count, -1) <= 0) {}
- RtlEnterCriticalSection(&udev_cs); + pthread_mutex_lock(&udev_cs); if (pfd[0].revents) process_monitor_event(udev_monitor); if (pfd[1].revents) read(deviceloop_control[0], &ctrl, 1); for (i = 2; i < count; ++i) @@ -1264,7 +1259,7 @@ NTSTATUS WINAPI udev_bus_wait(void *args) device = find_device_from_fd(pfd[i].fd); if (device) device->read_report(&device->unix_device); } - RtlLeaveCriticalSection(&udev_cs); + pthread_mutex_unlock(&udev_cs); }
TRACE("UDEV main loop exiting\n");
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/Makefile.in | 2 +- dlls/winebus.sys/bus_iohid.c | 12 ++++++------ dlls/winebus.sys/bus_sdl.c | 12 ++++++------ dlls/winebus.sys/bus_udev.c | 12 ++++++------ dlls/winebus.sys/main.c | 7 ++++--- dlls/winebus.sys/unix_private.h | 18 +++++++++--------- dlls/winebus.sys/unixlib.c | 25 +++++++++---------------- dlls/winebus.sys/unixlib.h | 2 -- 8 files changed, 41 insertions(+), 49 deletions(-)
diff --git a/dlls/winebus.sys/Makefile.in b/dlls/winebus.sys/Makefile.in index ec731c2b85c..d358517000d 100644 --- a/dlls/winebus.sys/Makefile.in +++ b/dlls/winebus.sys/Makefile.in @@ -1,6 +1,6 @@ MODULE = winebus.sys IMPORTS = ntoskrnl advapi32 -EXTRALIBS = $(IOKIT_LIBS) $(UDEV_LIBS) $(PTHREAD_LIBS) +EXTRALIBS = $(IOKIT_LIBS) $(UDEV_LIBS) $(PTHREAD_LIBS) -Wl,--subsystem,unixlib EXTRAINCL = $(UDEV_CFLAGS) $(SDL2_CFLAGS) EXTRADLLFLAGS = -mno-cygwin -Wl,--subsystem,native
diff --git a/dlls/winebus.sys/bus_iohid.c b/dlls/winebus.sys/bus_iohid.c index 8dc9e6c3df1..15f37dd2188 100644 --- a/dlls/winebus.sys/bus_iohid.c +++ b/dlls/winebus.sys/bus_iohid.c @@ -370,7 +370,7 @@ static void handle_RemovalCallback(void *context, IOReturn result, void *sender, else WARN("failed to find device for iohid device %p\n", IOHIDDevice); }
-NTSTATUS WINAPI iohid_bus_init(void *args) +NTSTATUS iohid_bus_init(void *args) { TRACE("args %p\n", args);
@@ -391,7 +391,7 @@ NTSTATUS WINAPI iohid_bus_init(void *args) return STATUS_SUCCESS; }
-NTSTATUS WINAPI iohid_bus_wait(void *args) +NTSTATUS iohid_bus_wait(void *args) { struct bus_event *result = args; CFRunLoopRunResult ret; @@ -415,7 +415,7 @@ NTSTATUS WINAPI iohid_bus_wait(void *args) return STATUS_SUCCESS; }
-NTSTATUS WINAPI iohid_bus_stop(void *args) +NTSTATUS iohid_bus_stop(void *args) { if (!run_loop) return STATUS_SUCCESS;
@@ -426,19 +426,19 @@ NTSTATUS WINAPI iohid_bus_stop(void *args)
#else
-NTSTATUS WINAPI iohid_bus_init(void *args) +NTSTATUS iohid_bus_init(void *args) { WARN("IOHID support not compiled in!\n"); return STATUS_NOT_IMPLEMENTED; }
-NTSTATUS WINAPI iohid_bus_wait(void *args) +NTSTATUS iohid_bus_wait(void *args) { WARN("IOHID support not compiled in!\n"); return STATUS_NOT_IMPLEMENTED; }
-NTSTATUS WINAPI iohid_bus_stop(void *args) +NTSTATUS iohid_bus_stop(void *args) { WARN("IOHID support not compiled in!\n"); return STATUS_NOT_IMPLEMENTED; diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c index b7c3b28ba4e..a446eb77375 100644 --- a/dlls/winebus.sys/bus_sdl.c +++ b/dlls/winebus.sys/bus_sdl.c @@ -810,7 +810,7 @@ static void process_device_event(SDL_Event *event) pthread_mutex_unlock(&sdl_cs); }
-NTSTATUS WINAPI sdl_bus_init(void *args) +NTSTATUS sdl_bus_init(void *args) { const char *mapping; int i; @@ -913,7 +913,7 @@ failed: return STATUS_UNSUCCESSFUL; }
-NTSTATUS WINAPI sdl_bus_wait(void *args) +NTSTATUS sdl_bus_wait(void *args) { struct bus_event *result = args; SDL_Event event; @@ -935,7 +935,7 @@ NTSTATUS WINAPI sdl_bus_wait(void *args) return STATUS_SUCCESS; }
-NTSTATUS WINAPI sdl_bus_stop(void *args) +NTSTATUS sdl_bus_stop(void *args) { SDL_Event event;
@@ -953,19 +953,19 @@ NTSTATUS WINAPI sdl_bus_stop(void *args)
#else
-NTSTATUS WINAPI sdl_bus_init(void *args) +NTSTATUS sdl_bus_init(void *args) { WARN("SDL support not compiled in!\n"); return STATUS_NOT_IMPLEMENTED; }
-NTSTATUS WINAPI sdl_bus_wait(void *args) +NTSTATUS sdl_bus_wait(void *args) { WARN("SDL support not compiled in!\n"); return STATUS_NOT_IMPLEMENTED; }
-NTSTATUS WINAPI sdl_bus_stop(void *args) +NTSTATUS sdl_bus_stop(void *args) { WARN("SDL support not compiled in!\n"); return STATUS_NOT_IMPLEMENTED; diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c index c73a6dd2259..cd9b065e56b 100644 --- a/dlls/winebus.sys/bus_udev.c +++ b/dlls/winebus.sys/bus_udev.c @@ -1181,7 +1181,7 @@ static void process_monitor_event(struct udev_monitor *monitor) udev_device_unref(dev); }
-NTSTATUS WINAPI udev_bus_init(void *args) +NTSTATUS udev_bus_init(void *args) { int monitor_fd;
@@ -1226,7 +1226,7 @@ error: return STATUS_UNSUCCESSFUL; }
-NTSTATUS WINAPI udev_bus_wait(void *args) +NTSTATUS udev_bus_wait(void *args) { struct platform_private *device; struct bus_event *result = args; @@ -1272,7 +1272,7 @@ NTSTATUS WINAPI udev_bus_wait(void *args) return STATUS_SUCCESS; }
-NTSTATUS WINAPI udev_bus_stop(void *args) +NTSTATUS udev_bus_stop(void *args) { if (!udev_context) return STATUS_SUCCESS; write(deviceloop_control[1], "q", 1); @@ -1281,19 +1281,19 @@ NTSTATUS WINAPI udev_bus_stop(void *args)
#else
-NTSTATUS WINAPI udev_bus_init(void *args) +NTSTATUS udev_bus_init(void *args) { WARN("UDEV support not compiled in!\n"); return STATUS_NOT_IMPLEMENTED; }
-NTSTATUS WINAPI udev_bus_wait(void *args) +NTSTATUS udev_bus_wait(void *args) { WARN("UDEV support not compiled in!\n"); return STATUS_NOT_IMPLEMENTED; }
-NTSTATUS WINAPI udev_bus_stop(void *args) +NTSTATUS udev_bus_stop(void *args) { WARN("UDEV support not compiled in!\n"); return STATUS_NOT_IMPLEMENTED; diff --git a/dlls/winebus.sys/main.c b/dlls/winebus.sys/main.c index 5fd7744c259..6ba3e7c73ce 100644 --- a/dlls/winebus.sys/main.c +++ b/dlls/winebus.sys/main.c @@ -112,11 +112,11 @@ static CRITICAL_SECTION device_list_cs = { &critsect_debug, -1, 0, 0, 0, 0 }; static struct list device_list = LIST_INIT(device_list);
static HMODULE instance; -static const unix_entry_point *unix_funcs; +static unixlib_handle_t winebus_handle;
static NTSTATUS winebus_call(unsigned int code, void *args) { - return unix_funcs[code]( args ); + return __wine_unix_call(winebus_handle, code, args); }
static void unix_device_remove(DEVICE_OBJECT *device) @@ -1116,7 +1116,8 @@ 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))) + if ((ret = NtQueryVirtualMemory(GetCurrentProcess(), instance, MemoryWineUnixFuncs, + &winebus_handle, sizeof(winebus_handle), NULL))) return ret;
attr.Length = sizeof(attr); diff --git a/dlls/winebus.sys/unix_private.h b/dlls/winebus.sys/unix_private.h index 5e30b21955a..cdc2be9b318 100644 --- a/dlls/winebus.sys/unix_private.h +++ b/dlls/winebus.sys/unix_private.h @@ -49,17 +49,17 @@ struct unix_device
extern void *unix_device_create(const struct unix_device_vtbl *vtbl, SIZE_T size) DECLSPEC_HIDDEN;
-extern NTSTATUS WINAPI sdl_bus_init(void *) DECLSPEC_HIDDEN; -extern NTSTATUS WINAPI sdl_bus_wait(void *) DECLSPEC_HIDDEN; -extern NTSTATUS WINAPI sdl_bus_stop(void *) DECLSPEC_HIDDEN; +extern NTSTATUS sdl_bus_init(void *) DECLSPEC_HIDDEN; +extern NTSTATUS sdl_bus_wait(void *) DECLSPEC_HIDDEN; +extern NTSTATUS sdl_bus_stop(void *) DECLSPEC_HIDDEN;
-extern NTSTATUS WINAPI udev_bus_init(void *) DECLSPEC_HIDDEN; -extern NTSTATUS WINAPI udev_bus_wait(void *) DECLSPEC_HIDDEN; -extern NTSTATUS WINAPI udev_bus_stop(void *) DECLSPEC_HIDDEN; +extern NTSTATUS udev_bus_init(void *) DECLSPEC_HIDDEN; +extern NTSTATUS udev_bus_wait(void *) DECLSPEC_HIDDEN; +extern NTSTATUS udev_bus_stop(void *) DECLSPEC_HIDDEN;
-extern NTSTATUS WINAPI iohid_bus_init(void *) DECLSPEC_HIDDEN; -extern NTSTATUS WINAPI iohid_bus_wait(void *) DECLSPEC_HIDDEN; -extern NTSTATUS WINAPI iohid_bus_stop(void *) DECLSPEC_HIDDEN; +extern NTSTATUS iohid_bus_init(void *) DECLSPEC_HIDDEN; +extern NTSTATUS iohid_bus_wait(void *) DECLSPEC_HIDDEN; +extern NTSTATUS iohid_bus_stop(void *) DECLSPEC_HIDDEN;
extern void bus_event_cleanup(struct bus_event *event) DECLSPEC_HIDDEN; extern void bus_event_queue_destroy(struct list *queue) DECLSPEC_HIDDEN; diff --git a/dlls/winebus.sys/unixlib.c b/dlls/winebus.sys/unixlib.c index f33b7cacfe3..929997f1aa7 100644 --- a/dlls/winebus.sys/unixlib.c +++ b/dlls/winebus.sys/unixlib.c @@ -149,7 +149,7 @@ static const struct device_desc mouse_device_desc = .serialnumber = {"0000"}, };
-static NTSTATUS WINAPI mouse_device_create(void *args) +static NTSTATUS mouse_device_create(void *args) { struct device_create_params *params = args; params->desc = mouse_device_desc; @@ -247,7 +247,7 @@ static const struct device_desc keyboard_device_desc = .serialnumber = {"0000"}, };
-static NTSTATUS WINAPI keyboard_device_create(void *args) +static NTSTATUS keyboard_device_create(void *args) { struct device_create_params *params = args; params->desc = keyboard_device_desc; @@ -280,7 +280,7 @@ static ULONG unix_device_incref(struct unix_device *iface) return InterlockedIncrement(&iface->ref); }
-static NTSTATUS WINAPI unix_device_remove(void *args) +static NTSTATUS unix_device_remove(void *args) { struct unix_device *iface = args; iface->vtbl->stop(iface); @@ -288,20 +288,20 @@ static NTSTATUS WINAPI unix_device_remove(void *args) return STATUS_SUCCESS; }
-static NTSTATUS WINAPI unix_device_start(void *args) +static NTSTATUS unix_device_start(void *args) { struct unix_device *iface = args; return iface->vtbl->start(iface); }
-static NTSTATUS WINAPI unix_device_get_report_descriptor(void *args) +static NTSTATUS unix_device_get_report_descriptor(void *args) { struct device_descriptor_params *params = args; struct unix_device *iface = params->iface; return iface->vtbl->get_report_descriptor(iface, params->buffer, params->length, params->out_length); }
-static NTSTATUS WINAPI unix_device_set_output_report(void *args) +static NTSTATUS unix_device_set_output_report(void *args) { struct device_report_params *params = args; struct unix_device *iface = params->iface; @@ -309,7 +309,7 @@ static NTSTATUS WINAPI unix_device_set_output_report(void *args) return STATUS_SUCCESS; }
-static NTSTATUS WINAPI unix_device_get_feature_report(void *args) +static NTSTATUS unix_device_get_feature_report(void *args) { struct device_report_params *params = args; struct unix_device *iface = params->iface; @@ -317,7 +317,7 @@ static NTSTATUS WINAPI unix_device_get_feature_report(void *args) return STATUS_SUCCESS; }
-static NTSTATUS WINAPI unix_device_set_feature_report(void *args) +static NTSTATUS unix_device_set_feature_report(void *args) { struct device_report_params *params = args; struct unix_device *iface = params->iface; @@ -325,7 +325,7 @@ static NTSTATUS WINAPI unix_device_set_feature_report(void *args) return STATUS_SUCCESS; }
-static const unix_entry_point unix_funcs[] = +const unixlib_entry_t __wine_unix_call_funcs[] = { sdl_bus_init, sdl_bus_wait, @@ -430,10 +430,3 @@ BOOL bus_event_queue_pop(struct list *queue, struct bus_event *event)
return TRUE; } - -NTSTATUS CDECL __wine_init_unix_lib( HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out ) -{ - if (reason != DLL_PROCESS_ATTACH) return STATUS_SUCCESS; - *(const unix_entry_point **)ptr_out = unix_funcs; - return STATUS_SUCCESS; -} diff --git a/dlls/winebus.sys/unixlib.h b/dlls/winebus.sys/unixlib.h index e5156176c46..a088cb1266b 100644 --- a/dlls/winebus.sys/unixlib.h +++ b/dlls/winebus.sys/unixlib.h @@ -136,8 +136,6 @@ enum unix_funcs device_set_feature_report, };
-typedef NTSTATUS (WINAPI *unix_entry_point)(void *); - static inline const char *debugstr_device_desc(struct device_desc *desc) { if (!desc) return "(null)";
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/main.c | 61 ++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 40 deletions(-)
diff --git a/dlls/winebus.sys/main.c b/dlls/winebus.sys/main.c index 6ba3e7c73ce..d3f40806e73 100644 --- a/dlls/winebus.sys/main.c +++ b/dlls/winebus.sys/main.c @@ -196,30 +196,28 @@ static DWORD get_device_index(struct device_desc *desc)
static WCHAR *get_instance_id(DEVICE_OBJECT *device) { - static const WCHAR formatW[] = {'%','i','&','%','s','&','%','x','&','%','i',0}; struct device_extension *ext = (struct device_extension *)device->DeviceExtension; DWORD len = wcslen(ext->serialnumber) + 33; WCHAR *dst;
if ((dst = ExAllocatePool(PagedPool, len * sizeof(WCHAR)))) - swprintf(dst, len, formatW, ext->desc.version, ext->serialnumber, ext->desc.uid, ext->index); + swprintf(dst, len, L"%i&%s&%x&%i", ext->desc.version, ext->serialnumber, ext->desc.uid, ext->index);
return dst; }
static WCHAR *get_device_id(DEVICE_OBJECT *device) { - static const WCHAR input_formatW[] = {'&','M','I','_','%','0','2','u',0}; - static const WCHAR formatW[] = {'%','s','\','v','i','d','_','%','0','4','x', - '&','p','i','d','_','%','0','4','x',0}; + static const WCHAR input_format[] = L"&MI_%02u"; + static const WCHAR format[] = L"%s\vid_%04x&pid_%04x"; struct device_extension *ext = (struct device_extension *)device->DeviceExtension; DWORD pos = 0, len = wcslen(ext->desc.busid) + 34; WCHAR *dst;
if ((dst = ExAllocatePool(PagedPool, len * sizeof(WCHAR)))) { - pos += swprintf(dst + pos, len - pos, formatW, ext->desc.busid, ext->desc.vid, ext->desc.pid); - if (ext->desc.input != -1) pos += swprintf(dst + pos, len - pos, input_formatW, ext->desc.input); + pos += swprintf(dst + pos, len - pos, format, ext->desc.busid, ext->desc.vid, ext->desc.pid); + if (ext->desc.input != -1) pos += swprintf(dst + pos, len - pos, input_format, ext->desc.input); }
return dst; @@ -241,14 +239,8 @@ static WCHAR *get_hardware_ids(DEVICE_OBJECT *device)
static WCHAR *get_compatible_ids(DEVICE_OBJECT *device) { - static const WCHAR xinput_compat[] = - { - 'W','I','N','E','B','U','S','\','W','I','N','E','_','C','O','M','P','_','X','I','N','P','U','T',0 - }; - static const WCHAR hid_compat[] = - { - 'W','I','N','E','B','U','S','\','W','I','N','E','_','C','O','M','P','_','H','I','D',0 - }; + static const WCHAR xinput_compat[] = L"WINEBUS\WINE_COMP_XINPUT"; + static const WCHAR hid_compat[] = L"WINEBUS\WINE_COMP_HID"; struct device_extension *ext = (struct device_extension *)device->DeviceExtension; DWORD size = sizeof(hid_compat); WCHAR *dst; @@ -281,7 +273,6 @@ static void remove_pending_irps(DEVICE_OBJECT *device)
static DEVICE_OBJECT *bus_create_hid_device(struct device_desc *desc, struct unix_device *unix_device) { - static const WCHAR device_name_fmtW[] = {'\','D','e','v','i','c','e','\','%','s','#','%','p',0}; struct device_extension *ext; DEVICE_OBJECT *device; UNICODE_STRING nameW; @@ -290,7 +281,7 @@ static DEVICE_OBJECT *bus_create_hid_device(struct device_desc *desc, struct uni
TRACE("desc %s, unix_device %p\n", debugstr_device_desc(desc), unix_device);
- swprintf(dev_name, ARRAY_SIZE(dev_name), device_name_fmtW, desc->busid, unix_device); + swprintf(dev_name, ARRAY_SIZE(dev_name), L"\Device\%s#%p", desc->busid, unix_device); RtlInitUnicodeString(&nameW, dev_name); status = IoCreateDevice(driver_obj, sizeof(struct device_extension), &nameW, 0, 0, FALSE, &device); if (status) @@ -381,13 +372,16 @@ static NTSTATUS build_device_relations(DEVICE_RELATIONS **devices) return STATUS_SUCCESS; }
-static DWORD check_bus_option(const UNICODE_STRING *option, DWORD default_value) +static DWORD check_bus_option(const WCHAR *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; + UNICODE_STRING str; DWORD size;
- if (NtQueryValueKey(driver_key, option, KeyValuePartialInformation, info, sizeof(buffer), &size) == STATUS_SUCCESS) + RtlInitUnicodeString(&str, option); + + if (NtQueryValueKey(driver_key, &str, KeyValuePartialInformation, info, sizeof(buffer), &size) == STATUS_SUCCESS) { if (info->Type == REG_DWORD) return *(DWORD *)info->Data; } @@ -645,8 +639,6 @@ static void sdl_bus_free_mappings(struct sdl_bus_options *options)
static void sdl_bus_load_mappings(struct sdl_bus_options *options) { - static const WCHAR szPath[] = {'m','a','p',0}; - ULONG idx = 0, len, count = 0, capacity, info_size, info_max_size; KEY_VALUE_FULL_INFORMATION *info; OBJECT_ATTRIBUTES attr = {0}; @@ -658,7 +650,7 @@ static void sdl_bus_load_mappings(struct sdl_bus_options *options) options->mappings_count = 0; options->mappings = NULL;
- RtlInitUnicodeString(&path, szPath); + RtlInitUnicodeString(&path, L"map"); InitializeObjectAttributes(&attr, &path, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, driver_key, NULL); status = NtOpenKey(&key, KEY_ALL_ACCESS, &attr); if (status) return; @@ -715,20 +707,17 @@ done:
static NTSTATUS sdl_driver_init(void) { - static const WCHAR 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 bus_options; struct bus_main_params bus = { - .name = bus_name, + .name = L"SDL", .init_args = &bus_options, .init_code = sdl_init, .wait_code = sdl_wait, }; NTSTATUS status;
- bus_options.map_controllers = check_bus_option(&controller_mode, 1); + bus_options.map_controllers = check_bus_option(L"Map Controllers", 1); if (!bus_options.map_controllers) TRACE("SDL controller to XInput HID gamepad mapping disabled\n"); sdl_bus_load_mappings(&bus_options);
@@ -739,23 +728,18 @@ static NTSTATUS sdl_driver_init(void)
static NTSTATUS udev_driver_init(void) { - static const WCHAR 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 bus_options; struct bus_main_params bus = { - .name = bus_name, + .name = L"UDEV", .init_args = &bus_options, .init_code = udev_init, .wait_code = udev_wait, };
- bus_options.disable_hidraw = check_bus_option(&hidraw_disabled, 0); + bus_options.disable_hidraw = check_bus_option(L"DisableHidraw", 0); if (bus_options.disable_hidraw) TRACE("UDEV hidraw devices disabled in registry\n"); - bus_options.disable_input = check_bus_option(&input_disabled, 0); + bus_options.disable_input = check_bus_option(L"DisableInput", 0); if (bus_options.disable_input) TRACE("UDEV input devices disabled in registry\n");
return bus_main_thread_start(&bus); @@ -763,11 +747,10 @@ static NTSTATUS udev_driver_init(void)
static NTSTATUS iohid_driver_init(void) { - static const WCHAR bus_name[] = {'I','O','H','I','D'}; struct iohid_bus_options bus_options; struct bus_main_params bus = { - .name = bus_name, + .name = L"IOHID", .init_args = &bus_options, .init_code = iohid_init, .wait_code = iohid_wait, @@ -778,8 +761,6 @@ static NTSTATUS iohid_driver_init(void)
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}; - static const UNICODE_STRING SDL_enabled = {sizeof(SDL_enabledW) - sizeof(WCHAR), sizeof(SDL_enabledW), (WCHAR*)SDL_enabledW}; IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation(irp); NTSTATUS ret;
@@ -792,7 +773,7 @@ static NTSTATUS fdo_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp) mouse_device_create(); keyboard_device_create();
- if (!check_bus_option(&SDL_enabled, 1) || sdl_driver_init()) + if (!check_bus_option(L"Enable SDL", 1) || sdl_driver_init()) { udev_driver_init(); iohid_driver_init();