From d3c57dec71e714d4922daa45fee019fbc7dc7180 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Sat, 9 Jul 2022 15:13:42 +0200 Subject: [PATCH] win32u: Use KeUserModeCallback interface for DDE message callbacks. --- dlls/user32/message.c | 14 +++++++------- dlls/user32/user_main.c | 20 ++++++++++++++++++-- dlls/user32/user_private.h | 2 +- dlls/win32u/message.c | 36 +++++++++++++++++++++++++++++++----- dlls/win32u/ntuser_private.h | 4 ---- include/ntuser.h | 30 ++++++++++++++++++++++++++++++ 6 files changed, 87 insertions(+), 19 deletions(-) diff --git a/dlls/user32/message.c b/dlls/user32/message.c index eff0c4efbcf..f4e9b5b404e 100644 --- a/dlls/user32/message.c +++ b/dlls/user32/message.c @@ -477,7 +477,7 @@ BOOL post_dde_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam, DWORD * Unpack a posted DDE message received from another process. */ BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam, - void **buffer, size_t size ) + const void *buffer, size_t size ) { UINT_PTR uiLo, uiHi; HGLOBAL hMem = 0; @@ -491,9 +491,9 @@ BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam ULONGLONG hpack; /* hMem is being passed */ if (size != sizeof(hpack)) return FALSE; - if (!buffer || !*buffer) return FALSE; + if (!size) return FALSE; uiLo = *lparam; - memcpy( &hpack, *buffer, size ); + memcpy( &hpack, buffer, size ); hMem = unpack_ptr( hpack ); uiHi = (UINT_PTR)hMem; TRACE("recv dde-ack %Ix mem=%Ix[%Ix]\n", uiLo, uiHi, GlobalSize( hMem )); @@ -509,7 +509,7 @@ BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam case WM_DDE_ADVISE: case WM_DDE_DATA: case WM_DDE_POKE: - if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE; + if (!size && message != WM_DDE_DATA) return FALSE; uiHi = *lparam; if (size) { @@ -517,7 +517,7 @@ BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam return FALSE; if ((ptr = GlobalLock( hMem ))) { - memcpy( ptr, *buffer, size ); + memcpy( ptr, buffer, size ); GlobalUnlock( hMem ); } else @@ -533,11 +533,11 @@ BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam case WM_DDE_EXECUTE: if (size) { - if (!buffer || !*buffer) return FALSE; + if (!size) return FALSE; if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size ))) return FALSE; if ((ptr = GlobalLock( hMem ))) { - memcpy( ptr, *buffer, size ); + memcpy( ptr, buffer, size ); GlobalUnlock( hMem ); TRACE( "exec: pairing c=%08Ix s=%p\n", *lparam, hMem ); if (!dde_add_pair( (HGLOBAL)*lparam, hMem )) diff --git a/dlls/user32/user_main.c b/dlls/user32/user_main.c index f9bc4985368..16ce5c6a854 100644 --- a/dlls/user32/user_main.c +++ b/dlls/user32/user_main.c @@ -134,8 +134,6 @@ static NTSTATUS try_finally( NTSTATUS (CDECL *func)( void *), void *arg, static const struct user_callbacks user_funcs = { NtWaitForMultipleObjects, - post_dde_message, - unpack_dde_message, try_finally, }; @@ -192,6 +190,12 @@ static NTSTATUS WINAPI User32FreeCachedClipboardData( const struct free_cached_d return 0; } +static NTSTATUS WINAPI User32PostDDEMessage( const struct post_dde_message_params *params, ULONG size ) +{ + return post_dde_message( params->hwnd, params->msg, params->wparam, params->lparam, + params->dest_tid, params->type ); +} + static NTSTATUS WINAPI User32RenderSsynthesizedFormat( const struct render_synthesized_format_params *params, ULONG size ) { @@ -204,6 +208,16 @@ static BOOL WINAPI User32LoadDriver( const WCHAR *path, ULONG size ) return LoadLibraryW( path ) != NULL; } +static NTSTATUS WINAPI User32UnpackDDEMessage( const struct unpack_dde_message_params *params, ULONG size ) +{ + struct unpack_dde_message_result *result = params->result; + result->wparam = params->wparam; + result->lparam = params->lparam; + size -= FIELD_OFFSET( struct unpack_dde_message_params, data ); + return unpack_dde_message( params->hwnd, params->message, &result->wparam, &result->lparam, + params->data, size ); +} + static const void *kernel_callback_table[NtUserCallCount] = { User32CallEnumDisplayMonitor, @@ -220,8 +234,10 @@ static const void *kernel_callback_table[NtUserCallCount] = User32LoadDriver, User32LoadImage, User32LoadSysMenu, + User32PostDDEMessage, User32RegisterBuiltinClasses, User32RenderSsynthesizedFormat, + User32UnpackDDEMessage, }; diff --git a/dlls/user32/user_private.h b/dlls/user32/user_private.h index e637bf01f5e..2e09605cc03 100644 --- a/dlls/user32/user_private.h +++ b/dlls/user32/user_private.h @@ -60,7 +60,7 @@ struct tagWND; extern BOOL post_dde_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam, DWORD dest_tid, DWORD type ) DECLSPEC_HIDDEN; extern BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam, - void **buffer, size_t size ) DECLSPEC_HIDDEN; + const void *buffer, size_t size ) DECLSPEC_HIDDEN; extern void free_cached_data( UINT format, HANDLE handle ) DECLSPEC_HIDDEN; extern HANDLE render_synthesized_format( UINT format, UINT from ) DECLSPEC_HIDDEN; diff --git a/dlls/win32u/message.c b/dlls/win32u/message.c index b8ea7cdce9f..0045c8a54c0 100644 --- a/dlls/win32u/message.c +++ b/dlls/win32u/message.c @@ -1827,9 +1827,26 @@ static int peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags, } if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST) { - if (!user_callbacks->unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam, - &info.msg.lParam, &buffer, size )) - continue; /* ignore it */ + struct unpack_dde_message_result result; + struct unpack_dde_message_params *params; + void *ret_ptr; + ULONG len; + BOOL ret; + + len = FIELD_OFFSET( struct unpack_dde_message_params, data[size] ); + if (!(params = malloc( len ))) + continue; + params->result = &result; + params->hwnd = info.msg.hwnd; + params->message = info.msg.message; + params->wparam = info.msg.wParam; + params->lparam = info.msg.lParam; + if (size) memcpy( params->data, buffer, size ); + ret = KeUserModeCallback( NtUserUnpackDDEMessage, params, len, &ret_ptr, &len ); + free( params ); + if (!ret) continue; /* ignore it */ + info.msg.wParam = result.wparam; + info.msg.lParam = result.lparam; } *msg = info.msg; msg->pt = point_phys_to_win_dpi( info.msg.hwnd, info.msg.pt ); @@ -2185,8 +2202,17 @@ static BOOL put_message_in_queue( const struct send_message_info *info, size_t * } else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST) { - return user_callbacks && user_callbacks->post_dde_message( info->hwnd, info->msg, - info->wparam, info->lparam, info->dest_tid, info->type ); + struct post_dde_message_params params; + void *ret_ptr; + ULONG ret_len; + + params.hwnd = info->hwnd; + params.msg = info->msg; + params.wparam = info->wparam; + params.lparam = info->lparam; + params.dest_tid = info->dest_tid; + params.type = info->type; + return KeUserModeCallback( NtUserPostDDEMessage, ¶ms, sizeof(params), &ret_ptr, &ret_len ); } SERVER_START_REQ( send_message ) diff --git a/dlls/win32u/ntuser_private.h b/dlls/win32u/ntuser_private.h index 55f2a449be4..9c23799c6bb 100644 --- a/dlls/win32u/ntuser_private.h +++ b/dlls/win32u/ntuser_private.h @@ -33,10 +33,6 @@ struct hardware_msg_data; struct user_callbacks { NTSTATUS (WINAPI *pNtWaitForMultipleObjects)(ULONG,const HANDLE*,BOOLEAN,BOOLEAN,const LARGE_INTEGER*); - BOOL (CDECL *post_dde_message)( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam, DWORD dest_tid, - DWORD type ); - BOOL (CDECL *unpack_dde_message)( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam, - void **buffer, size_t size ); NTSTATUS (CDECL *try_finally)( NTSTATUS (CDECL *func)( void *), void *arg, void (CALLBACK *finally_func)( BOOL )); }; diff --git a/include/ntuser.h b/include/ntuser.h index d22799ebe01..8cd7833717f 100644 --- a/include/ntuser.h +++ b/include/ntuser.h @@ -42,8 +42,10 @@ enum NtUserLoadDriver, NtUserLoadImage, NtUserLoadSysMenu, + NtUserPostDDEMessage, NtUserRegisterBuiltinClasses, NtUserRenderSynthesizedFormat, + NtUserUnpackDDEMessage, /* win16 hooks */ NtUserCallFreeIcon, NtUserThunkLock, @@ -218,6 +220,17 @@ struct load_sys_menu_params BOOL mdi; }; +/* NtUserPostDDEMessage params */ +struct post_dde_message_params +{ + HWND hwnd; + UINT msg; + WPARAM wparam; + LPARAM lparam; + DWORD dest_tid; + DWORD type; +}; + /* NtUserRenderSynthesizedFormat params */ struct render_synthesized_format_params { @@ -225,6 +238,23 @@ struct render_synthesized_format_params UINT from; }; +/* NtUserUnpackDDEMessage params */ +struct unpack_dde_message_result +{ + WPARAM wparam; + LPARAM lparam; +}; + +struct unpack_dde_message_params +{ + struct unpack_dde_message_result *result; /* FIXME: Use NtCallbackReturn instead */ + HWND hwnd; + UINT message; + WPARAM wparam; + LPARAM lparam; + char data[1]; +}; + /* process DPI awareness contexts */ #define NTUSER_DPI_UNAWARE 0x00006010 #define NTUSER_DPI_SYSTEM_AWARE 0x00006011