From: Zebediah Figura Subject: [PATCH 1/4] wineusb.sys: Move the libusb_cancel_transfer() call to a new Unix library. Message-Id: Date: Fri, 01 Jul 2022 05:55:01 +0000 In-Reply-To: References: From: Zebediah Figura --- dlls/wineusb.sys/Makefile.in | 2 ++ dlls/wineusb.sys/unixlib.c | 50 ++++++++++++++++++++++++++++++++++++ dlls/wineusb.sys/unixlib.h | 38 +++++++++++++++++++++++++++ dlls/wineusb.sys/wineusb.c | 21 +++++++++++++-- 4 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 dlls/wineusb.sys/unixlib.c create mode 100644 dlls/wineusb.sys/unixlib.h diff --git a/dlls/wineusb.sys/Makefile.in b/dlls/wineusb.sys/Makefile.in index 8145213fbef..ee3bfffdbeb 100644 --- a/dlls/wineusb.sys/Makefile.in +++ b/dlls/wineusb.sys/Makefile.in @@ -1,5 +1,6 @@ EXTRADEFS = -DWINE_NO_LONG_TYPES MODULE = wineusb.sys +UNIXLIB = wineusb.so IMPORTS = ntoskrnl UNIX_LIBS = $(USB_LIBS) UNIX_CFLAGS = $(USB_CFLAGS) @@ -7,6 +8,7 @@ UNIX_CFLAGS = $(USB_CFLAGS) EXTRADLLFLAGS = -Wl,--subsystem,native -mcygwin C_SRCS = \ + unixlib.c \ wineusb.c RC_SRCS = wineusb.rc diff --git a/dlls/wineusb.sys/unixlib.c b/dlls/wineusb.sys/unixlib.c new file mode 100644 index 00000000000..cdc84d98ede --- /dev/null +++ b/dlls/wineusb.sys/unixlib.c @@ -0,0 +1,50 @@ +/* + * libusb backend + * + * Copyright 2020 Zebediah Figura + * + * 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 + */ + +#if 0 +#pragma makedep unix +#endif + +#include +#include "ntstatus.h" +#define WIN32_NO_STATUS +#include "wine/debug.h" +#include "wine/list.h" + +#include "unixlib.h" + +WINE_DEFAULT_DEBUG_CHANNEL(wineusb); + +static NTSTATUS usb_cancel_transfer(void *args) +{ + const struct usb_cancel_transfer_params *params = args; + int ret; + + if ((ret = libusb_cancel_transfer(params->transfer)) < 0) + ERR("Failed to cancel transfer: %s\n", libusb_strerror(ret)); + + return STATUS_SUCCESS; +} + +const unixlib_entry_t __wine_unix_call_funcs[] = +{ +#define X(name) [unix_ ## name] = name + X(usb_cancel_transfer), +}; diff --git a/dlls/wineusb.sys/unixlib.h b/dlls/wineusb.sys/unixlib.h new file mode 100644 index 00000000000..d046062cd5f --- /dev/null +++ b/dlls/wineusb.sys/unixlib.h @@ -0,0 +1,38 @@ +/* + * wineusb Unix library interface + * + * Copyright 2022 Zebediah Figura 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 __WINE_WINEUSB_UNIXLIB_H +#define __WINE_WINEUSB_UNIXLIB_H + +#include "windef.h" +#include "winternl.h" +#include "wine/unixlib.h" + +struct usb_cancel_transfer_params +{ + void *transfer; +}; + +enum unix_funcs +{ + unix_usb_cancel_transfer, +}; + +#endif diff --git a/dlls/wineusb.sys/wineusb.c b/dlls/wineusb.sys/wineusb.c index 87669b5c65d..1f3435b67a4 100644 --- a/dlls/wineusb.sys/wineusb.c +++ b/dlls/wineusb.sys/wineusb.c @@ -36,6 +36,8 @@ #include "wine/list.h" #include "wine/unicode.h" +#include "unixlib.h" + WINE_DEFAULT_DEBUG_CHANNEL(wineusb); #ifdef __ASM_USE_FASTCALL_WRAPPER @@ -64,6 +66,8 @@ __ASM_STDCALL_FUNC( wrap_fastcall_func1, 8, DECLARE_CRITICAL_SECTION(wineusb_cs); +static unixlib_handle_t unix_handle; + static struct list device_list = LIST_INIT(device_list); struct usb_device @@ -712,9 +716,12 @@ static NTSTATUS usb_submit_urb(struct usb_device *device, IRP *irp) for (entry = mark->Flink; entry != mark; entry = entry->Flink) { IRP *queued_irp = CONTAINING_RECORD(entry, IRP, Tail.Overlay.ListEntry); + struct usb_cancel_transfer_params params = + { + .transfer = queued_irp->Tail.Overlay.DriverContext[0], + }; - if ((ret = libusb_cancel_transfer(queued_irp->Tail.Overlay.DriverContext[0])) < 0) - ERR("Failed to cancel transfer: %s\n", libusb_strerror(ret)); + __wine_unix_call(unix_handle, unix_usb_cancel_transfer, ¶ms); } LeaveCriticalSection(&wineusb_cs); @@ -930,10 +937,20 @@ static void WINAPI driver_unload(DRIVER_OBJECT *driver) NTSTATUS WINAPI DriverEntry(DRIVER_OBJECT *driver, UNICODE_STRING *path) { + NTSTATUS status; + void *instance; int err; TRACE("driver %p, path %s.\n", driver, debugstr_w(path->Buffer)); + RtlPcToFileHeader(DriverEntry, &instance); + if ((status = NtQueryVirtualMemory(GetCurrentProcess(), instance, + MemoryWineUnixFuncs, &unix_handle, sizeof(unix_handle), NULL))) + { + ERR("Failed to initialize Unix library, status %#x.\n", status); + return status; + } + driver_obj = driver; if ((err = libusb_init(NULL))) -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/356