[PATCH 09/11] winemac: Move driver implementation to unixlib.

Jacek Caban wine at gitlab.winehq.org
Thu Jun 2 19:51:24 CDT 2022


From: Jacek Caban <jacek at codeweavers.com>

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
---
 dlls/winemac.drv/Makefile.in   |  3 ++-
 dlls/winemac.drv/clipboard.c   |  4 ++++
 dlls/winemac.drv/display.c     |  6 +++++-
 dlls/winemac.drv/dllmain.c     | 10 +++++++++-
 dlls/winemac.drv/event.c       | 12 ++++++++----
 dlls/winemac.drv/gdi.c         |  4 ++++
 dlls/winemac.drv/image.c       |  4 ++++
 dlls/winemac.drv/keyboard.c    |  4 ++++
 dlls/winemac.drv/macdrv.h      |  9 ++-------
 dlls/winemac.drv/macdrv_main.c | 30 +++++++++++++++++++++---------
 dlls/winemac.drv/mouse.c       |  4 ++++
 dlls/winemac.drv/opengl.c      |  4 ++++
 dlls/winemac.drv/surface.c     |  4 ++++
 dlls/winemac.drv/systray.c     |  4 ++++
 dlls/winemac.drv/unixlib.h     |  6 ++++--
 dlls/winemac.drv/vulkan.c      |  4 ++++
 dlls/winemac.drv/window.c      |  4 ++++
 tools/makedep.c                |  2 ++
 18 files changed, 93 insertions(+), 25 deletions(-)

diff --git a/dlls/winemac.drv/Makefile.in b/dlls/winemac.drv/Makefile.in
index 06c654344d1..e3d3180b2d1 100644
--- a/dlls/winemac.drv/Makefile.in
+++ b/dlls/winemac.drv/Makefile.in
@@ -1,8 +1,9 @@
 EXTRADEFS = -DWINE_NO_LONG_TYPES
 MODULE    = winemac.drv
+UNIXLIB   = winemac.so
 IMPORTS   = uuid rpcrt4 user32 gdi32 win32u
 DELAYIMPORTS = ole32 shell32 imm32
-EXTRALIBS = -framework AppKit -framework Carbon -framework Security -framework OpenGL -framework IOKit -framework CoreVideo -framework QuartzCore $(METAL_LIBS)
+EXTRALIBS = -lwin32u -framework AppKit -framework Carbon -framework Security -framework OpenGL -framework IOKit -framework CoreVideo -framework QuartzCore $(METAL_LIBS)
 
 EXTRADLLFLAGS = -mcygwin
 
diff --git a/dlls/winemac.drv/clipboard.c b/dlls/winemac.drv/clipboard.c
index 8a795e61724..0f7bace1050 100644
--- a/dlls/winemac.drv/clipboard.c
+++ b/dlls/winemac.drv/clipboard.c
@@ -22,6 +22,10 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#if 0
+#pragma makedep unix
+#endif
+
 #include "config.h"
 
 #include "ntstatus.h"
diff --git a/dlls/winemac.drv/display.c b/dlls/winemac.drv/display.c
index 5dbfe9338ce..2e126b384d1 100644
--- a/dlls/winemac.drv/display.c
+++ b/dlls/winemac.drv/display.c
@@ -19,6 +19,10 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#if 0
+#pragma makedep unix
+#endif
+
 #include "config.h"
 
 #include "macdrv.h"
@@ -992,7 +996,7 @@ better:
         }
         else if (flags & (CDS_TEST | CDS_NORESET))
             ret = DISP_CHANGE_SUCCESSFUL;
-        else if (lstrcmpiW(primary_adapter, devname))
+        else if (wcsicmp(primary_adapter, devname))
         {
             FIXME("Changing non-primary adapter settings is currently unsupported.\n");
             ret = DISP_CHANGE_SUCCESSFUL;
diff --git a/dlls/winemac.drv/dllmain.c b/dlls/winemac.drv/dllmain.c
index e281a473e07..2ffbc12083d 100644
--- a/dlls/winemac.drv/dllmain.c
+++ b/dlls/winemac.drv/dllmain.c
@@ -28,6 +28,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(macdrv);
 
 
 HMODULE macdrv_module = 0;
+static unixlib_handle_t macdrv_handle;
+NTSTATUS (CDECL *macdrv_unix_call)(enum macdrv_funcs code, void *params);
 
 struct quit_info {
     HWND               *wins;
@@ -405,15 +407,21 @@ static BOOL process_attach(void)
         { .id = 0 }
     };
 
+    if (NtQueryVirtualMemory(GetCurrentProcess(), macdrv_module, MemoryWineUnixFuncs,
+                             &macdrv_handle, sizeof(macdrv_handle), NULL))
+        return FALSE;
+
     for (str = strings; str->id; str++)
         str->len = LoadStringW(macdrv_module, str->id, (WCHAR *)&str->str, 0);
     params.strings = strings;
 
-    if (MACDRV_CALL(init, &params)) return FALSE;
+    params.pNtWaitForMultipleObjects = NtWaitForMultipleObjects;
+    if (__wine_unix_call(macdrv_handle, unix_init, &params)) return FALSE;
 
     callback_table = NtCurrentTeb()->Peb->KernelCallbackTable;
     memcpy( callback_table + NtUserDriverCallbackFirst, kernel_callbacks, sizeof(kernel_callbacks) );
 
+    macdrv_unix_call = params.unix_call;
     return TRUE;
 }
 
diff --git a/dlls/winemac.drv/event.c b/dlls/winemac.drv/event.c
index ce7f06b07dd..d76c6ee8edb 100644
--- a/dlls/winemac.drv/event.c
+++ b/dlls/winemac.drv/event.c
@@ -20,6 +20,10 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#if 0
+#pragma makedep unix
+#endif
+
 #include "config.h"
 
 #include "macdrv.h"
@@ -521,8 +525,8 @@ NTSTATUS macdrv_MsgWaitForMultipleObjectsEx(DWORD count, const HANDLE *handles,
     if (!data)
     {
         if (!count && timeout && !timeout->QuadPart) return WAIT_TIMEOUT;
-        return NtWaitForMultipleObjects( count, handles, !(flags & MWMO_WAITALL),
-                                         !!(flags & MWMO_ALERTABLE), timeout );
+        return pNtWaitForMultipleObjects( count, handles, !(flags & MWMO_WAITALL),
+                                          !!(flags & MWMO_ALERTABLE), timeout );
     }
 
     if (data->current_event && data->current_event->type != QUERY_EVENT &&
@@ -534,8 +538,8 @@ NTSTATUS macdrv_MsgWaitForMultipleObjectsEx(DWORD count, const HANDLE *handles,
     if (process_events(data->queue, event_mask)) ret = count - 1;
     else if (count || !timeout || timeout->QuadPart)
     {
-        ret = NtWaitForMultipleObjects( count, handles, !(flags & MWMO_WAITALL),
-                                        !!(flags & MWMO_ALERTABLE), timeout );
+        ret = pNtWaitForMultipleObjects( count, handles, !(flags & MWMO_WAITALL),
+                                         !!(flags & MWMO_ALERTABLE), timeout );
         if (ret == count - 1) process_events(data->queue, event_mask);
     }
     else ret = WAIT_TIMEOUT;
diff --git a/dlls/winemac.drv/gdi.c b/dlls/winemac.drv/gdi.c
index 3f83436d97a..7114835677b 100644
--- a/dlls/winemac.drv/gdi.c
+++ b/dlls/winemac.drv/gdi.c
@@ -19,6 +19,10 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#if 0
+#pragma makedep unix
+#endif
+
 #include "config.h"
 
 #include "macdrv.h"
diff --git a/dlls/winemac.drv/image.c b/dlls/winemac.drv/image.c
index f6423858136..a0ee8b04aa9 100644
--- a/dlls/winemac.drv/image.c
+++ b/dlls/winemac.drv/image.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 "macdrv.h"
diff --git a/dlls/winemac.drv/keyboard.c b/dlls/winemac.drv/keyboard.c
index 181e86afd4a..102f945e79c 100644
--- a/dlls/winemac.drv/keyboard.c
+++ b/dlls/winemac.drv/keyboard.c
@@ -24,6 +24,10 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#if 0
+#pragma makedep unix
+#endif
+
 #include "config.h"
 
 #include "macdrv.h"
diff --git a/dlls/winemac.drv/macdrv.h b/dlls/winemac.drv/macdrv.h
index a841465486e..735cfc84d87 100644
--- a/dlls/winemac.drv/macdrv.h
+++ b/dlls/winemac.drv/macdrv.h
@@ -43,6 +43,8 @@ extern BOOL allow_software_rendering DECLSPEC_HIDDEN;
 extern BOOL disable_window_decorations DECLSPEC_HIDDEN;
 extern HMODULE macdrv_module DECLSPEC_HIDDEN;
 
+extern NTSTATUS (WINAPI *pNtWaitForMultipleObjects)(ULONG,const HANDLE*,BOOLEAN,
+                                                    BOOLEAN,const LARGE_INTEGER*) DECLSPEC_HIDDEN;
 
 extern const char* debugstr_cf(CFTypeRef t) DECLSPEC_HIDDEN;
 
@@ -273,7 +275,6 @@ extern void macdrv_status_item_mouse_move(const macdrv_event *event) DECLSPEC_HI
 extern void check_retina_status(void) DECLSPEC_HIDDEN;
 extern void macdrv_init_display_devices(BOOL force) DECLSPEC_HIDDEN;
 extern void init_user_driver(void) DECLSPEC_HIDDEN;
-extern NTSTATUS macdrv_init(void *arg) DECLSPEC_HIDDEN;
 
 /**************************************************************************
  * Mac IME driver
@@ -372,10 +373,4 @@ static inline UINT asciiz_to_unicode(WCHAR *dst, const char *src)
     return (p - dst) * sizeof(WCHAR);
 }
 
-/* FIXME: remove once we use unixlib */
-#define wcsicmp strcmpiW
-#define wcsnicmp strncmpiW
-#define wcsrchr strrchrW
-#define wcstol strtolW
-
 #endif  /* __WINE_MACDRV_H */
diff --git a/dlls/winemac.drv/macdrv_main.c b/dlls/winemac.drv/macdrv_main.c
index ddd4f03fd31..6ed0fdb7730 100644
--- a/dlls/winemac.drv/macdrv_main.c
+++ b/dlls/winemac.drv/macdrv_main.c
@@ -19,6 +19,11 @@
  * 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 "config.h"
 
 #include <Security/AuthSession.h>
@@ -67,6 +72,8 @@ int enable_app_nap = FALSE;
 
 CFDictionaryRef localized_strings;
 
+NTSTATUS (WINAPI *pNtWaitForMultipleObjects)(ULONG,const HANDLE*,BOOLEAN,
+                                             BOOLEAN,const LARGE_INTEGER*);
 
 /**************************************************************************
  *              debugstr_cf
@@ -313,9 +320,9 @@ static void setup_options(void)
     {
         static const WCHAR noneW[] = {'n','o','n','e',0};
         static const WCHAR allW[] = {'a','l','l',0};
-        if (!lstrcmpW(buffer, noneW))
+        if (!wcscmp(buffer, noneW))
             topmost_float_inactive = TOPMOST_FLOAT_INACTIVE_NONE;
-        else if (!lstrcmpW(buffer, allW))
+        else if (!wcscmp(buffer, allW))
             topmost_float_inactive = TOPMOST_FLOAT_INACTIVE_ALL;
         else
             topmost_float_inactive = TOPMOST_FLOAT_INACTIVE_NONFULLSCREEN;
@@ -371,9 +378,9 @@ static void setup_options(void)
     {
         static const WCHAR transparentW[] = {'t','r','a','n','s','p','a','r','e','n','t',0};
         static const WCHAR behindW[] = {'b','e','h','i','n','d',0};
-        if (!lstrcmpW(buffer, transparentW))
+        if (!wcscmp(buffer, transparentW))
             gl_surface_mode = GL_SURFACE_IN_FRONT_TRANSPARENT;
-        else if (!lstrcmpW(buffer, behindW))
+        else if (!wcscmp(buffer, behindW))
             gl_surface_mode = GL_SURFACE_BEHIND;
         else
             gl_surface_mode = GL_SURFACE_IN_FRONT_OPAQUE;
@@ -427,10 +434,13 @@ static void load_strings(struct localized_string *str)
 }
 
 
+static NTSTATUS CDECL unix_call( enum macdrv_funcs code, void *params );
+
+
 /***********************************************************************
  *              macdrv_init
  */
-NTSTATUS macdrv_init(void *arg)
+static NTSTATUS macdrv_init(void *arg)
 {
     struct init_params *params = arg;
     SessionAttributeBits attributes;
@@ -454,6 +464,8 @@ NTSTATUS macdrv_init(void *arg)
     init_user_driver();
     macdrv_init_display_devices(FALSE);
 
+    pNtWaitForMultipleObjects = params->pNtWaitForMultipleObjects;
+    params->unix_call = unix_call;
     return STATUS_SUCCESS;
 }
 
@@ -609,9 +621,9 @@ BOOL macdrv_SystemParametersInfo( UINT action, UINT int_param, void *ptr_param,
 
 NTSTATUS macdrv_client_func(enum macdrv_client_funcs id, const void *params, ULONG size)
 {
-    /* FIXME: use KeUserModeCallback instead */
-    NTSTATUS (WINAPI *func)(const void *, ULONG) = ((void **)NtCurrentTeb()->Peb->KernelCallbackTable)[id];
-    return func(params, size);
+    void *ret_ptr;
+    ULONG ret_len;
+    return KeUserModeCallback(id, params, size, &ret_ptr, &ret_len);
 }
 
 
@@ -655,7 +667,7 @@ C_ASSERT( ARRAYSIZE(__wine_unix_call_funcs) == unix_funcs_count );
 
 
 /* FIXME: Use __wine_unix_call instead */
-NTSTATUS unix_call(enum macdrv_funcs code, void *params)
+static NTSTATUS CDECL unix_call(enum macdrv_funcs code, void *params)
 {
     return __wine_unix_call_funcs[code]( params );
 }
diff --git a/dlls/winemac.drv/mouse.c b/dlls/winemac.drv/mouse.c
index 18a98296a76..fcdd1d1be1a 100644
--- a/dlls/winemac.drv/mouse.c
+++ b/dlls/winemac.drv/mouse.c
@@ -20,6 +20,10 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#if 0
+#pragma makedep unix
+#endif
+
 #include "config.h"
 
 #define OEMRESOURCE
diff --git a/dlls/winemac.drv/opengl.c b/dlls/winemac.drv/opengl.c
index cf58588981f..63b24ee991d 100644
--- a/dlls/winemac.drv/opengl.c
+++ b/dlls/winemac.drv/opengl.c
@@ -19,6 +19,10 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#if 0
+#pragma makedep unix
+#endif
+
 #include "config.h"
 
 #include "macdrv.h"
diff --git a/dlls/winemac.drv/surface.c b/dlls/winemac.drv/surface.c
index e8039b3b3aa..5306e3b619f 100644
--- a/dlls/winemac.drv/surface.c
+++ b/dlls/winemac.drv/surface.c
@@ -20,6 +20,10 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#if 0
+#pragma makedep unix
+#endif
+
 #include "config.h"
 
 #include "macdrv.h"
diff --git a/dlls/winemac.drv/systray.c b/dlls/winemac.drv/systray.c
index c1901ae0036..9d660d0287e 100644
--- a/dlls/winemac.drv/systray.c
+++ b/dlls/winemac.drv/systray.c
@@ -21,6 +21,10 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#if 0
+#pragma makedep unix
+#endif
+
 #include "config.h"
 
 #include "macdrv.h"
diff --git a/dlls/winemac.drv/unixlib.h b/dlls/winemac.drv/unixlib.h
index fea59564b92..284a3e26db9 100644
--- a/dlls/winemac.drv/unixlib.h
+++ b/dlls/winemac.drv/unixlib.h
@@ -36,8 +36,8 @@ enum macdrv_funcs
 };
 
 /* FIXME: Use __wine_unix_call when the rest of the stack is ready */
-extern NTSTATUS unix_call(enum macdrv_funcs code, void *params) DECLSPEC_HIDDEN;
-#define MACDRV_CALL(func, params) unix_call( unix_ ## func, params )
+extern NTSTATUS (CDECL *macdrv_unix_call)(enum macdrv_funcs code, void *params) DECLSPEC_HIDDEN;
+#define MACDRV_CALL(func, params) macdrv_unix_call(unix_ ## func, params)
 
 /* macdrv_dnd_get_data params */
 struct dnd_get_data_params
@@ -83,7 +83,9 @@ struct localized_string
 
 struct init_params
 {
+    NTSTATUS (WINAPI *pNtWaitForMultipleObjects)(ULONG,const HANDLE*,BOOLEAN,BOOLEAN,const LARGE_INTEGER*);
     struct localized_string *strings;
+    NTSTATUS (CDECL *unix_call)(enum macdrv_funcs code, void *params);
 };
 
 /* macdrv_notify_icon params */
diff --git a/dlls/winemac.drv/vulkan.c b/dlls/winemac.drv/vulkan.c
index ddef551c3d7..00f5e8465ab 100644
--- a/dlls/winemac.drv/vulkan.c
+++ b/dlls/winemac.drv/vulkan.c
@@ -21,6 +21,10 @@
 /* NOTE: If making changes here, consider whether they should be reflected in
  * the other drivers. */
 
+#if 0
+#pragma makedep unix
+#endif
+
 #include "config.h"
 
 #include <stdarg.h>
diff --git a/dlls/winemac.drv/window.c b/dlls/winemac.drv/window.c
index 072bdf606d4..f533f1d6310 100644
--- a/dlls/winemac.drv/window.c
+++ b/dlls/winemac.drv/window.c
@@ -21,6 +21,10 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#if 0
+#pragma makedep unix
+#endif
+
 #include "config.h"
 
 #include <IOKit/pwr_mgt/IOPMLib.h>
diff --git a/tools/makedep.c b/tools/makedep.c
index eaf7366da1a..83e4844050a 100644
--- a/tools/makedep.c
+++ b/tools/makedep.c
@@ -1506,6 +1506,8 @@ static void parse_file( struct makefile *make, struct incl_file *source, int src
     source->files_count = 0;
     source->files_size = file->deps_count;
     source->files = xmalloc( source->files_size * sizeof(*source->files) );
+
+    if (strendswith( file->name, ".m" )) file->flags |= FLAG_C_UNIX;
     if (file->flags & FLAG_C_UNIX) source->use_msvcrt = 0;
     else if (file->flags & FLAG_C_IMPLIB) source->use_msvcrt = 1;
 
-- 
GitLab


https://gitlab.winehq.org/wine/wine/-/merge_requests/177



More information about the wine-devel mailing list