From 11657aab278e73a892843b33e196b8f4375d54f9 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Tue, 26 Jul 2022 16:08:55 +0200 Subject: [PATCH] user32: Avoid using WIN_GetPtr for window handle validation. We will eventually want to make GetWindowThreadProcessId fast (probably based on shared handle table) instead of calling win32u. --- dlls/user32/win.c | 47 +++----------------------------------------- dlls/win32u/window.c | 10 ++++++++++ include/ntuser.h | 4 ++++ 3 files changed, 17 insertions(+), 44 deletions(-) diff --git a/dlls/user32/win.c b/dlls/user32/win.c index 8b5033ad821..b149a202433 100644 --- a/dlls/user32/win.c +++ b/dlls/user32/win.c @@ -153,13 +153,7 @@ void WIN_ReleasePtr( WND *ptr ) */ HWND WIN_IsCurrentProcess( HWND hwnd ) { - WND *ptr; - HWND ret; - - if (!(ptr = WIN_GetPtr( hwnd )) || ptr == WND_OTHER_PROCESS || ptr == WND_DESKTOP) return 0; - ret = ptr->obj.handle; - WIN_ReleasePtr( ptr ); - return ret; + return UlongToHandle( NtUserCallHwnd( hwnd, NtUserIsCurrehtProcessWindow )); } @@ -170,13 +164,7 @@ HWND WIN_IsCurrentProcess( HWND hwnd ) */ HWND WIN_IsCurrentThread( HWND hwnd ) { - WND *ptr; - HWND ret = 0; - - if (!(ptr = WIN_GetPtr( hwnd )) || ptr == WND_OTHER_PROCESS || ptr == WND_DESKTOP) return 0; - if (ptr->tid == GetCurrentThreadId()) ret = ptr->obj.handle; - WIN_ReleasePtr( ptr ); - return ret; + return UlongToHandle( NtUserCallHwnd( hwnd, NtUserIsCurrehtThreadWindow )); } @@ -205,36 +193,7 @@ UINT win_set_flags( HWND hwnd, UINT set_mask, UINT clear_mask ) */ HWND WIN_GetFullHandle( HWND hwnd ) { - WND *ptr; - - if (!hwnd || (ULONG_PTR)hwnd >> 16) return hwnd; - if (LOWORD(hwnd) <= 1 || LOWORD(hwnd) == 0xffff) return hwnd; - /* do sign extension for -2 and -3 */ - if (LOWORD(hwnd) >= (WORD)-3) return (HWND)(LONG_PTR)(INT16)LOWORD(hwnd); - - if (!(ptr = WIN_GetPtr( hwnd ))) return hwnd; - - if (ptr == WND_DESKTOP) - { - if (LOWORD(hwnd) == LOWORD(GetDesktopWindow())) return GetDesktopWindow(); - else return get_hwnd_message_parent(); - } - - if (ptr != WND_OTHER_PROCESS) - { - hwnd = ptr->obj.handle; - WIN_ReleasePtr( ptr ); - } - else /* may belong to another process */ - { - SERVER_START_REQ( get_window_info ) - { - req->handle = wine_server_user_handle( hwnd ); - if (!wine_server_call_err( req )) hwnd = wine_server_ptr_handle( reply->full_handle ); - } - SERVER_END_REQ; - } - return hwnd; + return UlongToHandle( NtUserCallHwnd( hwnd, NtUserGetFullWindowHandle )); } diff --git a/dlls/win32u/window.c b/dlls/win32u/window.c index a2ef9e72a06..1b72635e99c 100644 --- a/dlls/win32u/window.c +++ b/dlls/win32u/window.c @@ -5408,6 +5408,16 @@ ULONG_PTR WINAPI NtUserCallHwnd( HWND hwnd, DWORD code ) case NtUserCallHwnd_SetForegroundWindow: return set_foreground_window( hwnd, FALSE ); + /* temporary exports */ + case NtUserGetFullWindowHandle: + return HandleToUlong( get_full_window_handle( hwnd )); + + case NtUserIsCurrehtProcessWindow: + return HandleToUlong( is_current_process_window( hwnd )); + + case NtUserIsCurrehtThreadWindow: + return HandleToUlong( is_current_thread_window( hwnd )); + default: FIXME( "invalid code %u\n", code ); return 0; diff --git a/include/ntuser.h b/include/ntuser.h index 59916d25d6d..dc5f5ee501a 100644 --- a/include/ntuser.h +++ b/include/ntuser.h @@ -1112,6 +1112,10 @@ enum NtUserCallHwnd_IsWindowUnicode, NtUserCallHwnd_IsWindowVisible, NtUserCallHwnd_SetForegroundWindow, + /* temporary exports */ + NtUserGetFullWindowHandle, + NtUserIsCurrehtProcessWindow, + NtUserIsCurrehtThreadWindow, }; static inline UINT NtUserArrangeIconicWindows( HWND parent )