Module: wine Branch: master Commit: 271feee4ba1e6ff5f3736bea33403866e3f41d7d URL: https://gitlab.winehq.org/wine/wine/-/commit/271feee4ba1e6ff5f3736bea3340386...
Author: Jacek Caban jacek@codeweavers.com Date: Mon Jul 17 23:27:36 2023 +0200
win32u: Use user message packing for WM_GETTEXT and WM_ASKCBFORMATNAME.
---
dlls/user32/winproc.c | 3 ++- dlls/win32u/message.c | 40 ++++++++++++++++++++++++++++++++++------ dlls/win32u/tests/win32u.c | 7 ------- dlls/wow64win/user.c | 4 ++++ 4 files changed, 40 insertions(+), 14 deletions(-)
diff --git a/dlls/user32/winproc.c b/dlls/user32/winproc.c index 1f9b42d0c06..530f87633d9 100644 --- a/dlls/user32/winproc.c +++ b/dlls/user32/winproc.c @@ -833,7 +833,6 @@ BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam, break; case WM_GETTEXT: case WM_ASKCBFORMATNAME: - if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)), size )) return FALSE; break; case WM_WININICHANGE: if (!*lparam) return TRUE; @@ -1183,6 +1182,8 @@ BOOL WINAPI User32CallWindowProc( struct win_proc_params *params, ULONG size ) case WM_NCCREATE: case WM_CREATE: case WM_NCCALCSIZE: + case WM_GETTEXT: + case WM_ASKCBFORMATNAME: { LRESULT *result_ptr = (LRESULT *)buffer - 1; *result_ptr = result; diff --git a/dlls/win32u/message.c b/dlls/win32u/message.c index 58294f4d385..6cf5d4ea47d 100644 --- a/dlls/win32u/message.c +++ b/dlls/win32u/message.c @@ -308,6 +308,13 @@ static inline void push_string( struct packed_message *data, LPCWSTR str ) push_data( data, str, (lstrlenW(str) + 1) * sizeof(WCHAR) ); }
+/* make sure that there is space for 'size' bytes in buffer, growing it if needed */ +static inline void *get_buffer_space( void **buffer, size_t size, size_t prev_size ) +{ + if (prev_size < size) *buffer = malloc( size ); + return *buffer; +} + /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */ static inline BOOL combobox_has_strings( HWND hwnd ) { @@ -409,6 +416,10 @@ static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lpa *ncp.lppos = wp; } break; + case WM_GETTEXT: + case WM_ASKCBFORMATNAME: + if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)), size )) return FALSE; + break; case WM_WINE_SETWINDOWPOS: { WINDOWPOS wp; @@ -1139,6 +1150,11 @@ static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, } }
+static size_t char_size( BOOL ansi ) +{ + return ansi ? sizeof(char) : sizeof(WCHAR); +} + static size_t string_size( const void *str, BOOL ansi ) { return ansi ? strlen( str ) + 1 : (wcslen( str ) + 1) * sizeof(WCHAR); @@ -1175,6 +1191,10 @@ size_t user_message_size( UINT message, WPARAM wparam, LPARAM lparam, BOOL ansi case WM_NCCALCSIZE: size = wparam ? sizeof(NCCALCSIZE_PARAMS) + sizeof(WINDOWPOS) : sizeof(RECT); break; + case WM_GETTEXT: + case WM_ASKCBFORMATNAME: + size = wparam * char_size( ansi ); + break; }
return size; @@ -1222,6 +1242,10 @@ void pack_user_message( void *buffer, size_t size, UINT message, size = sizeof(*ncp); } break; + case WM_GETTEXT: + case WM_ASKCBFORMATNAME: + if (wparam) memset( buffer, 0, char_size( ansi )); + return; }
if (size) memcpy( buffer, lparam_ptr, size ); @@ -1232,7 +1256,8 @@ void pack_user_message( void *buffer, size_t size, UINT message, * * Copy a message result received from client. */ -static void copy_user_result( void *buffer, size_t size, UINT message, WPARAM wparam, LPARAM lparam ) +static void copy_user_result( void *buffer, size_t size, LRESULT result, UINT message, + WPARAM wparam, LPARAM lparam, BOOL ansi ) { void *lparam_ptr = (void *)lparam; size_t copy_size = 0; @@ -1274,6 +1299,13 @@ static void copy_user_result( void *buffer, size_t size, UINT message, WPARAM wp } copy_size = sizeof(RECT); break; + case WM_GETTEXT: + if (!result) memset( buffer, 0, char_size( ansi )); + copy_size = string_size( buffer, ansi ); + break; + case WM_ASKCBFORMATNAME: + copy_size = string_size( buffer, ansi ); + break; default: return; } @@ -1294,7 +1326,6 @@ static void copy_reply( LRESULT result, HWND hwnd, UINT message, WPARAM wparam,
switch(message) { - case WM_GETTEXT: case CB_GETLBTEXT: case LB_GETTEXT: copy_size = (result + 1) * sizeof(WCHAR); @@ -1355,9 +1386,6 @@ static void copy_reply( LRESULT result, HWND hwnd, UINT message, WPARAM wparam, case WM_MDICREATE: copy_size = sizeof(MDICREATESTRUCTW); break; - case WM_ASKCBFORMATNAME: - copy_size = (lstrlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR); - break; default: return; } @@ -1590,7 +1618,7 @@ static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpar result = dispatch_win_proc_params( params, sizeof(*params) + size, &ret_ptr, &ret_len ); if (params != &p) free( params );
- copy_user_result( ret_ptr, min( ret_len, packed_size ), msg, wparam, lparam ); + copy_user_result( ret_ptr, min( ret_len, packed_size ), result, msg, wparam, lparam, ansi );
/* and finally the WH_CALLWNDPROCRET hook */ cwpret.lResult = result; diff --git a/dlls/win32u/tests/win32u.c b/dlls/win32u/tests/win32u.c index 7ce6e990874..8653049b828 100644 --- a/dlls/win32u/tests/win32u.c +++ b/dlls/win32u/tests/win32u.c @@ -1533,7 +1533,6 @@ static void test_msg_output( const struct lparam_hook_test *test, LRESULT result else expected = test->lparam; if (expected) - todo_wine_if( test->message == WM_GETTEXT && !test->msg_result ) ok( !memcmp( lparam_buffer, expected, test->lparam_size ), "unexpected lparam content\n" );
todo_wine_if(test->todo) @@ -1626,32 +1625,26 @@ static void test_wndproc_hook(void) { "WM_GETTEXT", WM_GETTEXT, .wparam = 8, .lparam_size = sizeof(strbufW), .change_lparam = strbufW, .check_lparam = strbuf2W, - .todo = TRUE }, { "WM_GETTEXT2", WM_GETTEXT, .wparam = 8, .msg_result = 1, .lparam_size = sizeof(strbufW), .change_lparam = strbufW, .check_lparam = strbufW, - .todo = TRUE }, { "WM_GETTEXT3", WM_GETTEXT, .wparam = 8, .msg_result = 9, .lparam_size = sizeof(strbufW), .change_lparam = strbufW, .check_lparam = strbufW, - .todo = TRUE }, { "WM_ASKCBFORMATNAME", WM_ASKCBFORMATNAME, .wparam = 8, .lparam_size = sizeof(strbufW), .change_lparam = strbufW, .check_lparam = strbufW, - .todo = TRUE }, { "WM_ASKCBFORMATNAME2", WM_ASKCBFORMATNAME, .wparam = 8, .msg_result = 1, .lparam_size = sizeof(strbufW), .change_lparam = strbufW, .check_lparam = strbufW, - .todo = TRUE }, { "WM_ASKCBFORMATNAME3", WM_ASKCBFORMATNAME, .wparam = 8, .msg_result = 9, .lparam_size = sizeof(strbufW), .change_lparam = strbufW, .check_lparam = strbufW, - .todo = TRUE }, { "CB_GETLBTEXT", CB_GETLBTEXT, .msg_result = 7, .check_result = 4, .todo_result = TRUE, diff --git a/dlls/wow64win/user.c b/dlls/wow64win/user.c index 7aea543ea6a..79298ae2eed 100644 --- a/dlls/wow64win/user.c +++ b/dlls/wow64win/user.c @@ -695,6 +695,10 @@ static size_t packed_result_32to64( UINT message, WPARAM wparam, const void *par } break;
+ case WM_GETTEXT: + case WM_ASKCBFORMATNAME: + break; + default: return 0; }