[PATCH v2 02/10] win32u: Use NT interface for MsgWaitForMultipleObjectsEx user driver entry point.

Jacek Caban wine at gitlab.winehq.org
Tue May 3 09:21:44 CDT 2022


From: Jacek Caban <jacek at codeweavers.com>

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
---
 dlls/win32u/dce.c              |  3 ++-
 dlls/win32u/driver.c           | 28 ++++++----------------------
 dlls/win32u/input.c            |  3 ++-
 dlls/win32u/message.c          | 20 ++++++++++++++++++--
 dlls/wineandroid.drv/android.h |  5 +++--
 dlls/wineandroid.drv/window.c  |  9 +++++----
 dlls/winemac.drv/event.c       | 18 +++++++++---------
 dlls/winemac.drv/macdrv.h      |  5 +++--
 dlls/winex11.drv/event.c       | 18 +++++++++---------
 dlls/winex11.drv/x11drv.h      |  5 +++--
 include/wine/gdi_driver.h      |  4 ++--
 11 files changed, 62 insertions(+), 56 deletions(-)

diff --git a/dlls/win32u/dce.c b/dlls/win32u/dce.c
index 80f630b5614..c41067af464 100644
--- a/dlls/win32u/dce.c
+++ b/dlls/win32u/dce.c
@@ -1432,6 +1432,7 @@ static void update_now( HWND hwnd, UINT rdw_flags )
  */
 BOOL WINAPI NtUserRedrawWindow( HWND hwnd, const RECT *rect, HRGN hrgn, UINT flags )
 {
+    LARGE_INTEGER zero = { .QuadPart = 0 };
     static const RECT empty;
     BOOL ret;
 
@@ -1452,7 +1453,7 @@ BOOL WINAPI NtUserRedrawWindow( HWND hwnd, const RECT *rect, HRGN hrgn, UINT fla
     }
 
     /* process pending expose events before painting */
-    if (flags & RDW_UPDATENOW) user_driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_PAINT, 0 );
+    if (flags & RDW_UPDATENOW) user_driver->pMsgWaitForMultipleObjectsEx( 0, NULL, &zero, QS_PAINT, 0 );
 
     if (rect && !hrgn)
     {
diff --git a/dlls/win32u/driver.c b/dlls/win32u/driver.c
index ebc512bb4ee..f3c1d419b1d 100644
--- a/dlls/win32u/driver.c
+++ b/dlls/win32u/driver.c
@@ -784,30 +784,14 @@ static void nulldrv_GetDC( HDC hdc, HWND hwnd, HWND top_win, const RECT *win_rec
 {
 }
 
-/* helper for kernel32->ntdll timeout format conversion */
-static inline LARGE_INTEGER *get_nt_timeout( LARGE_INTEGER *time, DWORD timeout )
+static NTSTATUS nulldrv_MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *handles,
+                                                     const LARGE_INTEGER *timeout,
+                                                     DWORD mask, DWORD flags )
 {
-    if (timeout == INFINITE) return NULL;
-    time->QuadPart = (ULONGLONG)timeout * -10000;
-    return time;
-}
-
-static DWORD nulldrv_MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *handles, DWORD timeout,
-                                                  DWORD mask, DWORD flags )
-{
-    NTSTATUS status;
-    LARGE_INTEGER time;
+    if (!count && timeout && !timeout->QuadPart) return WAIT_TIMEOUT;
 
-    if (!count && !timeout) return WAIT_TIMEOUT;
-
-    status = NtWaitForMultipleObjects( count, handles, !(flags & MWMO_WAITALL), !!(flags & MWMO_ALERTABLE),
-                                       get_nt_timeout( &time, timeout ) );
-    if (HIWORD(status))  /* is it an error code? */
-    {
-        SetLastError( RtlNtStatusToDosError(status) );
-        status = WAIT_FAILED;
-    }
-    return status;
+    return NtWaitForMultipleObjects( count, handles, !(flags & MWMO_WAITALL),
+                                     !!(flags & MWMO_ALERTABLE), timeout );
 }
 
 static void nulldrv_ReleaseDC( HWND hwnd, HDC hdc )
diff --git a/dlls/win32u/input.c b/dlls/win32u/input.c
index 28fc5a918c8..877e3f1a064 100644
--- a/dlls/win32u/input.c
+++ b/dlls/win32u/input.c
@@ -268,7 +268,8 @@ BOOL WINAPI NtUserGetCursorInfo( CURSORINFO *info )
 
 static void check_for_events( UINT flags )
 {
-    if (user_driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, flags, 0 ) == WAIT_TIMEOUT)
+    LARGE_INTEGER zero = { .QuadPart = 0 };
+    if (user_driver->pMsgWaitForMultipleObjectsEx( 0, NULL, &zero, flags, 0 ) == WAIT_TIMEOUT)
         flush_window_surfaces( TRUE );
 }
 
diff --git a/dlls/win32u/message.c b/dlls/win32u/message.c
index 67990e7b1f4..e67f9adcbe7 100644
--- a/dlls/win32u/message.c
+++ b/dlls/win32u/message.c
@@ -1897,8 +1897,9 @@ static inline void check_for_driver_events( UINT msg )
 {
     if (get_user_thread_info()->message_count > 200)
     {
+        LARGE_INTEGER zero = { .QuadPart = 0 };
         flush_window_surfaces( FALSE );
-        user_driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
+        user_driver->pMsgWaitForMultipleObjectsEx( 0, NULL, &zero, QS_ALLINPUT, 0 );
     }
     else if (msg == WM_TIMER || msg == WM_SYSTIMER)
     {
@@ -1908,9 +1909,18 @@ static inline void check_for_driver_events( UINT msg )
     else get_user_thread_info()->message_count++;
 }
 
+/* helper for kernel32->ntdll timeout format conversion */
+static inline LARGE_INTEGER *get_nt_timeout( LARGE_INTEGER *time, DWORD timeout )
+{
+    if (timeout == INFINITE) return NULL;
+    time->QuadPart = (ULONGLONG)timeout * -10000;
+    return time;
+}
+
 /* wait for message or signaled handle */
 static DWORD wait_message( DWORD count, const HANDLE *handles, DWORD timeout, DWORD mask, DWORD flags )
 {
+    LARGE_INTEGER time;
     DWORD ret, lock;
     void *ret_ptr;
     ULONG ret_len;
@@ -1918,7 +1928,13 @@ static DWORD wait_message( DWORD count, const HANDLE *handles, DWORD timeout, DW
     if (enable_thunk_lock)
         lock = KeUserModeCallback( NtUserThunkLock, NULL, 0, &ret_ptr, &ret_len );
 
-    ret = user_driver->pMsgWaitForMultipleObjectsEx( count, handles, timeout, mask, flags );
+    ret = user_driver->pMsgWaitForMultipleObjectsEx( count, handles, get_nt_timeout( &time, timeout ),
+                                                     mask, flags );
+    if (HIWORD(ret))  /* is it an error code? */
+    {
+        SetLastError( RtlNtStatusToDosError(ret) );
+        ret = WAIT_FAILED;
+    }
     if (ret == WAIT_TIMEOUT && !count && !timeout) NtYieldExecution();
     if ((mask & QS_INPUT) == QS_INPUT) get_user_thread_info()->message_count = 0;
 
diff --git a/dlls/wineandroid.drv/android.h b/dlls/wineandroid.drv/android.h
index 34f7ef877dc..93e3c2201bf 100644
--- a/dlls/wineandroid.drv/android.h
+++ b/dlls/wineandroid.drv/android.h
@@ -86,8 +86,9 @@ extern SHORT ANDROID_VkKeyScanEx( WCHAR ch, HKL hkl ) DECLSPEC_HIDDEN;
 extern void ANDROID_SetCursor( HCURSOR handle ) DECLSPEC_HIDDEN;
 extern BOOL ANDROID_CreateWindow( HWND hwnd ) DECLSPEC_HIDDEN;
 extern void ANDROID_DestroyWindow( HWND hwnd ) DECLSPEC_HIDDEN;
-extern DWORD ANDROID_MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *handles, DWORD timeout,
-                                                  DWORD mask, DWORD flags ) DECLSPEC_HIDDEN;
+extern NTSTATUS ANDROID_MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *handles,
+                                                     const LARGE_INTEGER *timeout,
+                                                     DWORD mask, DWORD flags ) DECLSPEC_HIDDEN;
 extern void ANDROID_SetCursor( HCURSOR handle ) DECLSPEC_HIDDEN;
 extern void ANDROID_SetLayeredWindowAttributes( HWND hwnd, COLORREF key, BYTE alpha,
                                                 DWORD flags ) DECLSPEC_HIDDEN;
diff --git a/dlls/wineandroid.drv/window.c b/dlls/wineandroid.drv/window.c
index 81466259fc5..5143990836f 100644
--- a/dlls/wineandroid.drv/window.c
+++ b/dlls/wineandroid.drv/window.c
@@ -1201,8 +1201,9 @@ static LRESULT CALLBACK desktop_wndproc_wrapper( HWND hwnd, UINT msg, WPARAM wp,
 /***********************************************************************
  *           ANDROID_MsgWaitForMultipleObjectsEx
  */
-DWORD ANDROID_MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *handles,
-                                           DWORD timeout, DWORD mask, DWORD flags )
+NTSTATUS ANDROID_MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *handles,
+                                              const LARGE_INTEGER *timeout,
+                                              DWORD mask, DWORD flags )
 {
     if (GetCurrentThreadId() == desktop_tid)
     {
@@ -1210,8 +1211,8 @@ DWORD ANDROID_MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *handles,
         if (current_event) mask = 0;
         if (process_events( mask )) return count - 1;
     }
-    return WaitForMultipleObjectsEx( count, handles, flags & MWMO_WAITALL,
-                                     timeout, flags & MWMO_ALERTABLE );
+    return NtWaitForMultipleObjects( count, handles, !(flags & MWMO_WAITALL),
+                                     !!(flags & MWMO_ALERTABLE), timeout );
 }
 
 /**********************************************************************
diff --git a/dlls/winemac.drv/event.c b/dlls/winemac.drv/event.c
index a3135f9d2ca..45ceb09c094 100644
--- a/dlls/winemac.drv/event.c
+++ b/dlls/winemac.drv/event.c
@@ -339,21 +339,21 @@ static int process_events(macdrv_event_queue queue, macdrv_event_mask mask)
 /***********************************************************************
  *              MsgWaitForMultipleObjectsEx   (MACDRV.@)
  */
-DWORD macdrv_MsgWaitForMultipleObjectsEx(DWORD count, const HANDLE *handles,
-                                         DWORD timeout, DWORD mask, DWORD flags)
+NTSTATUS macdrv_MsgWaitForMultipleObjectsEx(DWORD count, const HANDLE *handles,
+                                            const LARGE_INTEGER *timeout, DWORD mask, DWORD flags)
 {
     DWORD ret;
     struct macdrv_thread_data *data = macdrv_thread_data();
     macdrv_event_mask event_mask = get_event_mask(mask);
 
-    TRACE("count %d, handles %p, timeout %u, mask %x, flags %x\n", count,
+    TRACE("count %d, handles %p, timeout %p, mask %x, flags %x\n", count,
           handles, timeout, mask, flags);
 
     if (!data)
     {
-        if (!count && !timeout) return WAIT_TIMEOUT;
-        return WaitForMultipleObjectsEx(count, handles, flags & MWMO_WAITALL,
-                                        timeout, flags & MWMO_ALERTABLE);
+        if (!count && timeout && !timeout->QuadPart) return WAIT_TIMEOUT;
+        return NtWaitForMultipleObjects( count, handles, !(flags & MWMO_WAITALL),
+                                         !!(flags & MWMO_ALERTABLE), timeout );
     }
 
     if (data->current_event && data->current_event->type != QUERY_EVENT &&
@@ -363,10 +363,10 @@ DWORD macdrv_MsgWaitForMultipleObjectsEx(DWORD count, const HANDLE *handles,
         event_mask = 0;  /* don't process nested events */
 
     if (process_events(data->queue, event_mask)) ret = count - 1;
-    else if (count || timeout)
+    else if (count || !timeout || timeout->QuadPart)
     {
-        ret = WaitForMultipleObjectsEx(count, handles, flags & MWMO_WAITALL,
-                                       timeout, flags & MWMO_ALERTABLE);
+        ret = NtWaitForMultipleObjects( 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/macdrv.h b/dlls/winemac.drv/macdrv.h
index f7ffe0fa1f6..d13a2277e61 100644
--- a/dlls/winemac.drv/macdrv.h
+++ b/dlls/winemac.drv/macdrv.h
@@ -173,8 +173,9 @@ extern UINT macdrv_GetKeyboardLayoutList(INT size, HKL *list) DECLSPEC_HIDDEN;
 extern INT macdrv_GetKeyNameText(LONG lparam, LPWSTR buffer, INT size) DECLSPEC_HIDDEN;
 extern BOOL macdrv_SystemParametersInfo(UINT action, UINT int_param, void *ptr_param,
                                         UINT flags) DECLSPEC_HIDDEN;
-extern DWORD macdrv_MsgWaitForMultipleObjectsEx(DWORD count, const HANDLE *handles,
-                                                DWORD timeout, DWORD mask, DWORD flags) DECLSPEC_HIDDEN;
+extern NTSTATUS macdrv_MsgWaitForMultipleObjectsEx(DWORD count, const HANDLE *handles,
+                                                   const LARGE_INTEGER *timeout, DWORD mask,
+                                                   DWORD flags) DECLSPEC_HIDDEN;
 extern void macdrv_ThreadDetach(void) DECLSPEC_HIDDEN;
 
 
diff --git a/dlls/winex11.drv/event.c b/dlls/winex11.drv/event.c
index 729a0a7eab6..5a22464d594 100644
--- a/dlls/winex11.drv/event.c
+++ b/dlls/winex11.drv/event.c
@@ -476,26 +476,26 @@ static BOOL process_events( Display *display, Bool (*filter)(Display*, XEvent*,X
 /***********************************************************************
  *           MsgWaitForMultipleObjectsEx   (X11DRV.@)
  */
-DWORD X11DRV_MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *handles,
-                                          DWORD timeout, DWORD mask, DWORD flags )
+NTSTATUS X11DRV_MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *handles,
+                                             const LARGE_INTEGER *timeout, DWORD mask, DWORD flags )
 {
     struct x11drv_thread_data *data = x11drv_thread_data();
-    DWORD ret;
+    NTSTATUS ret;
 
     if (!data)
     {
-        if (!count && !timeout) return WAIT_TIMEOUT;
-        return WaitForMultipleObjectsEx( count, handles, flags & MWMO_WAITALL,
-                                         timeout, flags & MWMO_ALERTABLE );
+        if (!count && timeout && !timeout->QuadPart) return WAIT_TIMEOUT;
+        return NtWaitForMultipleObjects( count, handles, !(flags & MWMO_WAITALL),
+                                         !!(flags & MWMO_ALERTABLE), timeout );
     }
 
     if (data->current_event) mask = 0;  /* don't process nested events */
 
     if (process_events( data->display, filter_event, mask )) ret = count - 1;
-    else if (count || timeout)
+    else if (count || !timeout || timeout->QuadPart)
     {
-        ret = WaitForMultipleObjectsEx( count, handles, flags & MWMO_WAITALL,
-                                        timeout, flags & MWMO_ALERTABLE );
+        ret = NtWaitForMultipleObjects( count, handles, !(flags & MWMO_WAITALL),
+                                        !!(flags & MWMO_ALERTABLE), timeout );
         if (ret == count - 1) process_events( data->display, filter_event, mask );
     }
     else ret = WAIT_TIMEOUT;
diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h
index 4576564fda3..4298ae429ed 100644
--- a/dlls/winex11.drv/x11drv.h
+++ b/dlls/winex11.drv/x11drv.h
@@ -686,8 +686,9 @@ extern void retry_grab_clipping_window(void) DECLSPEC_HIDDEN;
 extern BOOL clip_fullscreen_window( HWND hwnd, BOOL reset ) DECLSPEC_HIDDEN;
 extern void move_resize_window( HWND hwnd, int dir ) DECLSPEC_HIDDEN;
 extern void X11DRV_InitKeyboard( Display *display ) DECLSPEC_HIDDEN;
-extern DWORD X11DRV_MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *handles, DWORD timeout,
-                                                 DWORD mask, DWORD flags ) DECLSPEC_HIDDEN;
+extern NTSTATUS X11DRV_MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *handles,
+                                                    const LARGE_INTEGER *timeout,
+                                                    DWORD mask, DWORD flags ) DECLSPEC_HIDDEN;
 extern HWND *build_hwnd_list(void) DECLSPEC_HIDDEN;
 
 typedef int (*x11drv_error_callback)( Display *display, XErrorEvent *event, void *arg );
diff --git a/include/wine/gdi_driver.h b/include/wine/gdi_driver.h
index a63e2c3ceda..a1fe01d2a43 100644
--- a/include/wine/gdi_driver.h
+++ b/include/wine/gdi_driver.h
@@ -165,7 +165,7 @@ struct gdi_dc_funcs
 };
 
 /* increment this when you change the DC function table */
-#define WINE_GDI_DRIVER_VERSION 77
+#define WINE_GDI_DRIVER_VERSION 78
 
 #define GDI_PRIORITY_NULL_DRV        0  /* null driver */
 #define GDI_PRIORITY_FONT_DRV      100  /* any font driver */
@@ -299,7 +299,7 @@ struct user_driver_funcs
     void    (*pDestroyWindow)(HWND);
     void    (*pFlashWindowEx)(FLASHWINFO*);
     void    (*pGetDC)(HDC,HWND,HWND,const RECT *,const RECT *,DWORD);
-    DWORD   (*pMsgWaitForMultipleObjectsEx)(DWORD,const HANDLE*,DWORD,DWORD,DWORD);
+    NTSTATUS (*pMsgWaitForMultipleObjectsEx)(DWORD,const HANDLE*,const LARGE_INTEGER*,DWORD,DWORD);
     void    (*pReleaseDC)(HWND,HDC);
     BOOL    (*pScrollDC)(HDC,INT,INT,HRGN);
     void    (*pSetCapture)(HWND,UINT);
-- 
GitLab


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



More information about the wine-devel mailing list