Jacek Caban : win32u: Move NtUserSetWinEventHook implementation from user32.

Alexandre Julliard julliard at winehq.org
Wed Feb 16 15:30:25 CST 2022


Module: wine
Branch: master
Commit: d76b38ffb640885c6d798d8f3a2558907694dcf2
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=d76b38ffb640885c6d798d8f3a2558907694dcf2

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed Feb 16 12:29:56 2022 +0100

win32u: Move NtUserSetWinEventHook implementation from user32.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/user32/hook.c      | 54 +++++++-----------------------------------------
 dlls/win32u/hook.c      | 55 +++++++++++++++++++++++++++++++++++++++++++++++++
 dlls/win32u/syscall.c   |  1 +
 dlls/win32u/win32u.spec |  2 +-
 dlls/wow64win/syscall.h |  1 +
 dlls/wow64win/user.c    | 19 +++++++++++++++++
 include/ntuser.h        |  3 +++
 7 files changed, 87 insertions(+), 48 deletions(-)

diff --git a/dlls/user32/hook.c b/dlls/user32/hook.c
index 26bde944175..edcc3143ab4 100644
--- a/dlls/user32/hook.c
+++ b/dlls/user32/hook.c
@@ -709,61 +709,21 @@ HWINEVENTHOOK WINAPI SetWinEventHook(DWORD event_min, DWORD event_max,
                                      HMODULE inst, WINEVENTPROC proc,
                                      DWORD pid, DWORD tid, DWORD flags)
 {
-    HWINEVENTHOOK handle = 0;
     WCHAR module[MAX_PATH];
-    DWORD len;
+    UNICODE_STRING str;
+    DWORD len = 0;
 
     TRACE("%d,%d,%p,%p,%08x,%04x,%08x\n", event_min, event_max, inst,
           proc, pid, tid, flags);
 
-    if (inst)
-    {
-        if (!(len = GetModuleFileNameW(inst, module, MAX_PATH)) || len >= MAX_PATH)
-            inst = 0;
-    }
-
-    if ((flags & WINEVENT_INCONTEXT) && !inst)
-    {
-        SetLastError(ERROR_HOOK_NEEDS_HMOD);
-        return 0;
-    }
-
-    if (event_min > event_max)
+    if (inst && (!(len = GetModuleFileNameW( inst, module, MAX_PATH )) || len >= MAX_PATH))
     {
-        SetLastError(ERROR_INVALID_HOOK_FILTER);
-        return 0;
-    }
-
-    /* FIXME: what if the tid or pid belongs to another process? */
-    if (tid)  /* thread-local hook */
         inst = 0;
-
-    SERVER_START_REQ( set_hook )
-    {
-        req->id        = WH_WINEVENT;
-        req->pid       = pid;
-        req->tid       = tid;
-        req->event_min = event_min;
-        req->event_max = event_max;
-        req->flags     = flags;
-        req->unicode   = 1;
-        if (inst) /* make proc relative to the module base */
-        {
-            req->proc = wine_server_client_ptr( (void *)((char *)proc - (char *)inst) );
-            wine_server_add_data( req, module, lstrlenW(module) * sizeof(WCHAR) );
-        }
-        else req->proc = wine_server_client_ptr( proc );
-
-        if (!wine_server_call_err( req ))
-        {
-            handle = wine_server_ptr_handle( reply->handle );
-            get_user_thread_info()->active_hooks = reply->active_hooks;
-        }
+        len = 0;
     }
-    SERVER_END_REQ;
-
-    TRACE("-> %p\n", handle);
-    return handle;
+    str.Buffer = module;
+    str.Length = str.MaximumLength = len * sizeof(WCHAR);
+    return NtUserSetWinEventHook( event_min, event_max, inst, &str, proc, pid, tid, flags );
 }
 
 static inline BOOL find_first_hook(DWORD id, DWORD event, HWND hwnd, LONG object_id,
diff --git a/dlls/win32u/hook.c b/dlls/win32u/hook.c
index 02520a025f8..46f6efe1b1b 100644
--- a/dlls/win32u/hook.c
+++ b/dlls/win32u/hook.c
@@ -26,10 +26,65 @@
 #include "win32u_private.h"
 #include "ntuser_private.h"
 #include "wine/server.h"
+#include "wine/debug.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(hook);
 
 #define WH_WINEVENT (WH_MAXHOOK+1)
 
 
+/***********************************************************************
+ *           NtUserSetWinEventHook   (win32u.@)
+ */
+HWINEVENTHOOK WINAPI NtUserSetWinEventHook( DWORD event_min, DWORD event_max, HMODULE inst,
+                                            UNICODE_STRING *module, WINEVENTPROC proc,
+                                            DWORD pid, DWORD tid, DWORD flags )
+{
+    HWINEVENTHOOK handle = 0;
+
+    if ((flags & WINEVENT_INCONTEXT) && !inst)
+    {
+        SetLastError(ERROR_HOOK_NEEDS_HMOD);
+        return 0;
+    }
+
+    if (event_min > event_max)
+    {
+        SetLastError(ERROR_INVALID_HOOK_FILTER);
+        return 0;
+    }
+
+    /* FIXME: what if the tid or pid belongs to another process? */
+    if (tid) inst = 0; /* thread-local hook */
+
+    SERVER_START_REQ( set_hook )
+    {
+        req->id        = WH_WINEVENT;
+        req->pid       = pid;
+        req->tid       = tid;
+        req->event_min = event_min;
+        req->event_max = event_max;
+        req->flags     = flags;
+        req->unicode   = 1;
+        if (inst) /* make proc relative to the module base */
+        {
+            req->proc = wine_server_client_ptr( (void *)((char *)proc - (char *)inst) );
+            wine_server_add_data( req, module->Buffer, module->Length );
+        }
+        else req->proc = wine_server_client_ptr( proc );
+
+        if (!wine_server_call_err( req ))
+        {
+            handle = wine_server_ptr_handle( reply->handle );
+            get_user_thread_info()->active_hooks = reply->active_hooks;
+        }
+    }
+    SERVER_END_REQ;
+
+    TRACE("-> %p\n", handle);
+    return handle;
+}
+
 /***********************************************************************
  *           NtUserUnhookWinEvent   (win32u.@)
  */
diff --git a/dlls/win32u/syscall.c b/dlls/win32u/syscall.c
index d698dc31743..e2b88dcc62e 100644
--- a/dlls/win32u/syscall.c
+++ b/dlls/win32u/syscall.c
@@ -139,6 +139,7 @@ static void * const syscalls[] =
     NtUserSetProcessWindowStation,
     NtUserSetProp,
     NtUserSetThreadDesktop,
+    NtUserSetWinEventHook,
     NtUserUnhookWinEvent,
 };
 
diff --git a/dlls/win32u/win32u.spec b/dlls/win32u/win32u.spec
index 42bfc1bb4c4..7de0af5d959 100644
--- a/dlls/win32u/win32u.spec
+++ b/dlls/win32u/win32u.spec
@@ -1237,7 +1237,7 @@
 @ stub NtUserSetThreadLayoutHandles
 @ stub NtUserSetThreadState
 @ stub NtUserSetTimer
-@ stub NtUserSetWinEventHook
+@ stdcall -syscall NtUserSetWinEventHook(long long long ptr ptr long long long)
 @ stub NtUserSetWindowArrangement
 @ stub NtUserSetWindowBand
 @ stub NtUserSetWindowCompositionAttribute
diff --git a/dlls/wow64win/syscall.h b/dlls/wow64win/syscall.h
index 3b852147dc1..a0292bb881f 100644
--- a/dlls/wow64win/syscall.h
+++ b/dlls/wow64win/syscall.h
@@ -126,6 +126,7 @@
     SYSCALL_ENTRY( NtUserSetProcessWindowStation ) \
     SYSCALL_ENTRY( NtUserSetProp ) \
     SYSCALL_ENTRY( NtUserSetThreadDesktop ) \
+    SYSCALL_ENTRY( NtUserSetWinEventHook ) \
     SYSCALL_ENTRY( NtUserUnhookWinEvent )
 
 #endif /* __WOW64WIN_SYSCALL_H */
diff --git a/dlls/wow64win/user.c b/dlls/wow64win/user.c
index c55af5233a8..b610b510ebc 100644
--- a/dlls/wow64win/user.c
+++ b/dlls/wow64win/user.c
@@ -356,6 +356,25 @@ NTSTATUS WINAPI wow64_NtUserGetDoubleClickTime( UINT *args )
     return NtUserGetDoubleClickTime();
 }
 
+NTSTATUS WINAPI wow64_NtUserSetWinEventHook( UINT *args )
+{
+    DWORD event_min = get_ulong( &args );
+    DWORD event_max = get_ulong( &args );
+    HMODULE inst = get_handle( &args );
+    UNICODE_STRING32 *module32 = get_ptr( &args );
+    WINEVENTPROC proc = get_ptr(&args );
+    DWORD pid = get_ulong( &args );
+    DWORD tid = get_ulong( &args );
+    DWORD flags = get_ulong( &args );
+    UNICODE_STRING module;
+    HWINEVENTHOOK ret;
+
+    ret = NtUserSetWinEventHook( event_min, event_max, inst,
+                                 unicode_str_32to64( &module, module32 ),
+                                 proc, pid, tid, flags );
+    return HandleToUlong( ret );
+}
+
 NTSTATUS WINAPI wow64_NtUserUnhookWinEvent( UINT *args )
 {
     HWINEVENTHOOK handle = get_handle( &args );
diff --git a/include/ntuser.h b/include/ntuser.h
index 499c9bf809e..65e9d20d90a 100644
--- a/include/ntuser.h
+++ b/include/ntuser.h
@@ -179,6 +179,9 @@ BOOL    WINAPI NtUserSetProcessWindowStation( HWINSTA handle );
 BOOL    WINAPI NtUserSetProp( HWND hwnd, const WCHAR *str, HANDLE handle );
 BOOL    WINAPI NtUserSetSysColors( INT count, const INT *colors, const COLORREF *values );
 BOOL    WINAPI NtUserSetThreadDesktop( HDESK handle );
+HWINEVENTHOOK WINAPI NtUserSetWinEventHook( DWORD event_min, DWORD event_max, HMODULE inst,
+                                            UNICODE_STRING *module, WINEVENTPROC proc,
+                                            DWORD pid, DWORD tid, DWORD flags );
 INT     WINAPI NtUserShowCursor( BOOL show );
 BOOL    WINAPI NtUserSystemParametersInfo( UINT action, UINT val, void *ptr, UINT winini );
 BOOL    WINAPI NtUserSystemParametersInfoForDpi( UINT action, UINT val, PVOID ptr, UINT winini, UINT dpi );




More information about the wine-cvs mailing list