From: Jacek Caban jacek@codeweavers.com
--- dlls/user32/hook.c | 8 +++---- dlls/user32/user_private.h | 2 +- dlls/user32/winproc.c | 47 +++++++++++--------------------------- dlls/win32u/message.c | 37 ++++++++---------------------- dlls/win32u/tests/win32u.c | 7 ------ dlls/wow64win/user.c | 1 + 6 files changed, 28 insertions(+), 74 deletions(-)
diff --git a/dlls/user32/hook.c b/dlls/user32/hook.c index a21b11735ab..b2e213f42fe 100644 --- a/dlls/user32/hook.c +++ b/dlls/user32/hook.c @@ -478,7 +478,7 @@ BOOL WINAPI User32CallWindowsHook( struct win_hook_params *params, ULONG size ) { cbtc.hwndInsertAfter = HWND_TOP; unpack_message( (HWND)params->wparam, WM_CREATE, NULL, (LPARAM *)&cbtc.lpcs, - &ret_ptr, ret_size, FALSE ); + ret_ptr, ret_size, FALSE ); params->lparam = (LPARAM)&cbtc; ret_size = sizeof(*cbtc.lpcs); } @@ -488,10 +488,9 @@ BOOL WINAPI User32CallWindowsHook( struct win_hook_params *params, ULONG size ) { CWPSTRUCT *cwp = (CWPSTRUCT *)params->lparam; size_t offset = (lparam_offset + sizeof(*cwp) + 15) & ~15; - void *buffer = (char *)params + offset;
unpack_message( cwp->hwnd, cwp->message, &cwp->wParam, &cwp->lParam, - &buffer, size - offset, !params->prev_unicode ); + (char *)params + offset, size - offset, !params->prev_unicode ); ret_size = 0; break; } @@ -500,10 +499,9 @@ BOOL WINAPI User32CallWindowsHook( struct win_hook_params *params, ULONG size ) { CWPRETSTRUCT *cwpret = (CWPRETSTRUCT *)params->lparam; size_t offset = (lparam_offset + sizeof(*cwpret) + 15) & ~15; - void *buffer = (char *)params + offset;
unpack_message( cwpret->hwnd, cwpret->message, &cwpret->wParam, &cwpret->lParam, - &buffer, size - offset, !params->prev_unicode ); + (char *)params + offset, size - offset, !params->prev_unicode ); ret_size = 0; break; } diff --git a/dlls/user32/user_private.h b/dlls/user32/user_private.h index 267c535defe..1a467712f0e 100644 --- a/dlls/user32/user_private.h +++ b/dlls/user32/user_private.h @@ -52,7 +52,7 @@ extern BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM extern void free_cached_data( UINT format, HANDLE handle ) DECLSPEC_HIDDEN; extern HANDLE render_synthesized_format( UINT format, UINT from ) DECLSPEC_HIDDEN; extern BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam, - void **buffer, size_t size, BOOL ansi ); + void *buffer, size_t size, BOOL ansi );
extern void CLIPBOARD_ReleaseOwner( HWND hwnd ) DECLSPEC_HIDDEN; extern HDC get_display_dc(void) DECLSPEC_HIDDEN; diff --git a/dlls/user32/winproc.c b/dlls/user32/winproc.c index 3d8e6833602..3ebe1eb2d8c 100644 --- a/dlls/user32/winproc.c +++ b/dlls/user32/winproc.c @@ -730,14 +730,6 @@ LRESULT dispatch_win_proc_params( struct win_proc_params *params ) return result; }
-/* 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 = HeapAlloc( GetProcessHeap(), 0, size ); - return *buffer; -} - static size_t string_size( const void *str, BOOL ansi ) { return ansi ? strlen( str ) + 1 : (wcslen( str ) + 1) * sizeof(WCHAR); @@ -749,7 +741,7 @@ static size_t string_size( const void *str, BOOL ansi ) * Unpack a message received from another process. */ BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam, - void **buffer, size_t size, BOOL ansi ) + void *buffer, size_t size, BOOL ansi ) { size_t minsize = 0;
@@ -758,7 +750,7 @@ BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam, case WM_NCCREATE: case WM_CREATE: { - CREATESTRUCTA *cs = *buffer; + CREATESTRUCTA *cs = buffer; char *str = (char *)(cs + 1);
if (!IS_INTRESOURCE(cs->lpszName)) @@ -775,13 +767,13 @@ BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam, case WM_NCCALCSIZE: if (*wparam) { - NCCALCSIZE_PARAMS *ncp = *buffer; + NCCALCSIZE_PARAMS *ncp = buffer; ncp->lppos = (WINDOWPOS *)((NCCALCSIZE_PARAMS *)ncp + 1); } break; case WM_COPYDATA: { - COPYDATASTRUCT *cds = *buffer; + COPYDATASTRUCT *cds = buffer; if (cds->lpData) cds->lpData = cds + 1; break; } @@ -789,14 +781,14 @@ BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam, case SBM_GETRANGE: case CB_GETEDITSEL: { - DWORD *ptr = *buffer; + DWORD *ptr = buffer; *wparam = (WPARAM)ptr++; *lparam = (LPARAM)ptr; return TRUE; } case WM_MDICREATE: { - MDICREATESTRUCTA *mcs = *buffer; + MDICREATESTRUCTA *mcs = buffer; char *str = (char *)(mcs + 1);
if (!IS_INTRESOURCE(mcs->szClass)) @@ -858,10 +850,7 @@ BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam, case WM_SIZING: case WM_MOVING: case CB_GETCOMBOBOXINFO: - break; case WM_MDIGETACTIVE: - if (!*lparam) return TRUE; - if (!get_buffer_space( buffer, sizeof(BOOL), size )) return FALSE; break; case WM_DEVICECHANGE: if (!(*wparam & 0x8000)) return TRUE; @@ -916,7 +905,7 @@ BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
/* default exit for most messages: check minsize and store buffer in lparam */ if (size < minsize) return FALSE; - *lparam = (LPARAM)*buffer; + *lparam = (LPARAM)buffer; return TRUE; }
@@ -926,22 +915,13 @@ BOOL WINAPI User32CallWindowProc( struct win_proc_params *params, ULONG size )
if (params->needs_unpack) { - char stack_buffer[128]; - size_t msg_size = size - sizeof(*params); void *buffer;
- if (size > sizeof(*params)) - { - size -= sizeof(*params); - buffer = params + 1; - } - else - { - size = sizeof(stack_buffer); - buffer = stack_buffer; - } + size -= sizeof(*params); + buffer = params + 1; + if (!unpack_message( params->hwnd, params->msg, ¶ms->wparam, - ¶ms->lparam, &buffer, size, params->ansi )) + ¶ms->lparam, buffer, size, params->ansi )) return 0;
result = dispatch_win_proc_params( params ); @@ -1003,17 +983,16 @@ BOOL WINAPI User32CallWindowProc( struct win_proc_params *params, ULONG size ) case WM_MOVING: case WM_MDICREATE: case CB_GETCOMBOBOXINFO: + case WM_MDIGETACTIVE: { LRESULT *result_ptr = (LRESULT *)buffer - 1; *result_ptr = result; - return NtCallbackReturn( result_ptr, sizeof(*result_ptr) + msg_size, TRUE ); + return NtCallbackReturn( result_ptr, sizeof(*result_ptr) + size, TRUE ); } }
NtUserMessageCall( params->hwnd, params->msg, params->wparam, params->lparam, (void *)result, NtUserWinProcResult, FALSE ); - if (buffer != stack_buffer && buffer != params + 1) - HeapFree( GetProcessHeap(), 0, buffer ); } else { diff --git a/dlls/win32u/message.c b/dlls/win32u/message.c index 1dcacf66f38..80802f6425f 100644 --- a/dlls/win32u/message.c +++ b/dlls/win32u/message.c @@ -874,6 +874,10 @@ static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lpa memcpy( ps, &cbi, sizeof(cbi) ); break; } + case WM_MDIGETACTIVE: + if (!*lparam) return TRUE; + if (!get_buffer_space( buffer, sizeof(BOOL), size )) return FALSE; + break; default: return TRUE; /* message doesn't need any unpacking */ } @@ -1699,6 +1703,9 @@ size_t user_message_size( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, case CB_GETCOMBOBOXINFO: size = sizeof(COMBOBOXINFO); break; + case WM_MDIGETACTIVE: + if (lparam) size = sizeof(BOOL); + break; }
return size; @@ -1908,26 +1915,6 @@ static void copy_user_result( void *buffer, size_t size, LRESULT result, UINT me } copy_size = sizeof(COMBOBOXINFO); break; - default: - return; - } - - if (copy_size > size) copy_size = size; - if (copy_size) memcpy( lparam_ptr, buffer, copy_size ); -} - -/*********************************************************************** - * copy_reply - * - * Copy a message reply received from client. - */ -static void copy_reply( LRESULT result, HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, - WPARAM wparam_src, LPARAM lparam_src ) -{ - size_t copy_size = 0; - - switch(message) - { case WM_MDIGETACTIVE: if (lparam) copy_size = sizeof(BOOL); break; @@ -1935,7 +1922,8 @@ static void copy_reply( LRESULT result, HWND hwnd, UINT message, WPARAM wparam, return; }
- if (copy_size) memcpy( (void *)lparam, (void *)lparam_src, copy_size ); + if (copy_size > size) copy_size = size; + if (copy_size) memcpy( lparam_ptr, buffer, copy_size ); }
/*********************************************************************** @@ -2001,12 +1989,7 @@ static BOOL reply_winproc_result( LRESULT result, HWND hwnd, UINT message, WPARA MSG msg;
if (!info) return FALSE; - - if (info->type == MSG_CLIENT_MESSAGE) - { - copy_reply( result, hwnd, message, info->msg.wParam, info->msg.lParam, wparam, lparam ); - return TRUE; - } + if (info->type == MSG_CLIENT_MESSAGE) return TRUE;
msg.hwnd = hwnd; msg.message = message; diff --git a/dlls/win32u/tests/win32u.c b/dlls/win32u/tests/win32u.c index b82e7d80687..beb2050c695 100644 --- a/dlls/win32u/tests/win32u.c +++ b/dlls/win32u/tests/win32u.c @@ -1368,7 +1368,6 @@ struct lparam_hook_test size_t check_size; BOOL poison_lparam; BOOL not_allowed; - BOOL todo; };
static const struct lparam_hook_test *current_hook_test; @@ -1594,7 +1593,6 @@ static void test_msg_output( const struct lparam_hook_test *test, LRESULT result (test->message == LB_GETTEXT && test->msg_result == 7)) ok( !memcmp( lparam_buffer, expected, test->lparam_size ), "unexpected lparam content\n" );
- todo_wine_if(test->todo) ok( wndproc_lparam != orig, "wndproc_lparam unmodified\n" ); if (!hooks_called) return; @@ -1604,13 +1602,9 @@ static void test_msg_output( const struct lparam_hook_test *test, LRESULT result ok( retwnd_hook_lparam, "retwnd_hook_lparam not called\n" ); ok( retwnd_hook_lparam2, "retwnd_hook_lparam2 not called\n" );
- todo_wine_if(test->todo) ok( orig != callwnd_hook_lparam, "callwnd_hook_lparam not modified\n" ); - todo_wine_if(test->todo) ok( orig != callwnd_hook_lparam2, "callwnd_hook_lparam2 not modified\n" ); - todo_wine_if(test->todo) ok( orig != retwnd_hook_lparam, "retwnd_hook_lparam not modified\n" ); - todo_wine_if(test->todo) ok( orig != retwnd_hook_lparam2, "retwnd_hook_lparam2 not modified\n" );
/* @@ -1788,7 +1782,6 @@ static void test_wndproc_hook(void) { "WM_MDIGETACTIVE", WM_MDIGETACTIVE, .no_wparam_check = TRUE, .lparam_size = sizeof(BOOL), .change_lparam = &false_lparam, - .todo = TRUE }, { "WM_GETMINMAXINFO", WM_GETMINMAXINFO, diff --git a/dlls/wow64win/user.c b/dlls/wow64win/user.c index 70f91c8210b..28c6fa9b6d4 100644 --- a/dlls/wow64win/user.c +++ b/dlls/wow64win/user.c @@ -917,6 +917,7 @@ static size_t packed_result_32to64( UINT message, WPARAM wparam, const void *par case LB_GETSELITEMS: case WM_SIZING: case WM_MOVING: + case WM_MDIGETACTIVE: break;
default: