From: "Rémi Bernon" Subject: [PATCH 1/5] winebus.sys: Build with msvcrt. Message-Id: <20210917065035.3294478-1-rbernon@codeweavers.com> Date: Fri, 17 Sep 2021 08:50:31 +0200 Signed-off-by: Rémi Bernon --- 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 @@ -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 #include @@ -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 #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 #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 @@ -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) { -- 2.33.0