From 1e9390e558d02652d245353b9e4e3037451c6c30 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Sat, 30 Jul 2022 03:09:47 +0200 Subject: [PATCH] win32u: Use platform-independent layout for ntuser_thread_info. --- dlls/imm32/imm.c | 8 ++++---- dlls/user32/message.c | 15 ++++++++++----- dlls/user32/user_main.c | 2 +- dlls/user32/win.c | 8 ++++---- dlls/win32u/driver.c | 2 +- dlls/win32u/imm.c | 7 ++++--- dlls/win32u/window.c | 17 ++++++++++------- dlls/win32u/winstation.c | 15 ++++++++------- dlls/wineandroid.drv/device.c | 4 ++-- dlls/winemac.drv/macdrv.h | 2 +- dlls/winemac.drv/macdrv_main.c | 2 +- dlls/winex11.drv/x11drv.h | 2 +- dlls/winex11.drv/x11drv_main.c | 4 ++-- include/ntuser.h | 14 +++++++------- 14 files changed, 56 insertions(+), 46 deletions(-) diff --git a/dlls/imm32/imm.c b/dlls/imm32/imm.c index bfbf3b2ad78..780d544c0e9 100644 --- a/dlls/imm32/imm.c +++ b/dlls/imm32/imm.c @@ -235,7 +235,7 @@ static DWORD convert_candidatelist_AtoW( static struct coinit_spy *get_thread_coinit_spy(void) { - return NtUserGetThreadInfo()->client_imm; + return (struct coinit_spy *)(UINT_PTR)NtUserGetThreadInfo()->client_imm; } static void imm_couninit_thread(BOOL cleanup) @@ -299,7 +299,7 @@ static ULONG WINAPI InitializeSpy_Release(IInitializeSpy *iface) if (!ref) { HeapFree(GetProcessHeap(), 0, spy); - NtUserGetThreadInfo()->client_imm = NULL; + NtUserGetThreadInfo()->client_imm = 0; } return ref; } @@ -373,7 +373,7 @@ static void imm_coinit_thread(void) spy->ref = 1; spy->cookie.QuadPart = 0; spy->apt_flags = 0; - NtUserGetThreadInfo()->client_imm = spy; + NtUserGetThreadInfo()->client_imm = (UINT_PTR)spy; } @@ -440,7 +440,7 @@ static void IMM_FreeThreadData(void) { struct coinit_spy *spy; - free_input_context_data(NtUserGetThreadInfo()->default_imc); + free_input_context_data(UlongToHandle(NtUserGetThreadInfo()->default_imc)); if ((spy = get_thread_coinit_spy())) IInitializeSpy_Release(&spy->IInitializeSpy_iface); } diff --git a/dlls/user32/message.c b/dlls/user32/message.c index 097e8fd4391..2cbdd761fe9 100644 --- a/dlls/user32/message.c +++ b/dlls/user32/message.c @@ -60,10 +60,15 @@ static inline void *unpack_ptr( ULONGLONG ptr64 ) return (void *)(ULONG_PTR)ptr64; } +static struct wm_char_mapping_data *get_wmchar_data(void) +{ + return (struct wm_char_mapping_data *)(UINT_PTR)NtUserGetThreadInfo()->wmchar_data; +} + /* check for pending WM_CHAR message with DBCS trailing byte */ static inline BOOL get_pending_wmchar( MSG *msg, UINT first, UINT last, BOOL remove ) { - struct wm_char_mapping_data *data = NtUserGetThreadInfo()->wmchar_data; + struct wm_char_mapping_data *data = get_wmchar_data(); if (!data || !data->get_msg.message) return FALSE; if ((first || last) && (first > WM_CHAR || last < WM_CHAR)) return FALSE; @@ -119,7 +124,7 @@ BOOL map_wparam_AtoW( UINT message, WPARAM *wparam, enum wm_char_mapping mapping */ if (mapping != WMCHAR_MAP_NOMAPPING) { - struct wm_char_mapping_data *data = NtUserGetThreadInfo()->wmchar_data; + struct wm_char_mapping_data *data = get_wmchar_data(); BYTE low = LOBYTE(*wparam); cp = get_input_codepage(); @@ -152,7 +157,7 @@ BOOL map_wparam_AtoW( UINT message, WPARAM *wparam, enum wm_char_mapping mapping { if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) ))) return FALSE; - NtUserGetThreadInfo()->wmchar_data = data; + NtUserGetThreadInfo()->wmchar_data = (UINT_PTR)data; } TRACE( "storing lead byte %02x mapping %u\n", low, mapping ); data->lead_byte[mapping] = low; @@ -210,11 +215,11 @@ static void map_wparam_WtoA( MSG *msg, BOOL remove ) len = WideCharToMultiByte( cp, 0, wch, 1, (LPSTR)ch, 2, NULL, NULL ); if (len == 2) /* DBCS char */ { - struct wm_char_mapping_data *data = NtUserGetThreadInfo()->wmchar_data; + struct wm_char_mapping_data *data = get_wmchar_data(); if (!data) { if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) ))) return; - NtUserGetThreadInfo()->wmchar_data = data; + NtUserGetThreadInfo()->wmchar_data = (UINT_PTR)data; } if (remove) { diff --git a/dlls/user32/user_main.c b/dlls/user32/user_main.c index 139d9b5f46e..df3e6b27b81 100644 --- a/dlls/user32/user_main.c +++ b/dlls/user32/user_main.c @@ -240,7 +240,7 @@ static void thread_detach(void) WDML_NotifyThreadDetach(); NtUserCallNoParam( NtUserThreadDetach ); - HeapFree( GetProcessHeap(), 0, thread_info->wmchar_data ); + HeapFree( GetProcessHeap(), 0, (void *)(UINT_PTR)thread_info->wmchar_data ); } diff --git a/dlls/user32/win.c b/dlls/user32/win.c index fa2ae2e9da4..e246d112383 100644 --- a/dlls/user32/win.c +++ b/dlls/user32/win.c @@ -95,7 +95,7 @@ HWND get_hwnd_message_parent(void) struct ntuser_thread_info *thread_info = NtUserGetThreadInfo(); if (!thread_info->msg_window) GetDesktopWindow(); /* trigger creation */ - return thread_info->msg_window; + return UlongToHandle( thread_info->msg_window ); } @@ -109,8 +109,8 @@ BOOL is_desktop_window( HWND hwnd ) struct ntuser_thread_info *thread_info = NtUserGetThreadInfo(); if (!hwnd) return FALSE; - if (hwnd == thread_info->top_window) return TRUE; - if (hwnd == thread_info->msg_window) return TRUE; + if (hwnd == UlongToHandle( thread_info->top_window )) return TRUE; + if (hwnd == UlongToHandle( thread_info->msg_window )) return TRUE; if (!HIWORD(hwnd) || HIWORD(hwnd) == 0xffff) { @@ -582,7 +582,7 @@ HWND WINAPI GetDesktopWindow(void) { struct ntuser_thread_info *thread_info = NtUserGetThreadInfo(); - if (thread_info->top_window) return thread_info->top_window; + if (thread_info->top_window) return UlongToHandle( thread_info->top_window ); return NtUserGetDesktopWindow(); } diff --git a/dlls/win32u/driver.c b/dlls/win32u/driver.c index e8f410b7f4c..f70d4a7b455 100644 --- a/dlls/win32u/driver.c +++ b/dlls/win32u/driver.c @@ -785,7 +785,7 @@ static BOOL nodrv_CreateWindow( HWND hwnd ) HWND parent = NtUserGetAncestor( hwnd, GA_PARENT ); /* HWND_MESSAGE windows don't need a graphics driver */ - if (!parent || parent == NtUserGetThreadInfo()->msg_window) return TRUE; + if (!parent || parent == UlongToHandle( NtUserGetThreadInfo()->msg_window )) return TRUE; if (warned++) return FALSE; ERR_(winediag)( "Application tried to create a window, but no driver could be loaded.\n" ); diff --git a/dlls/win32u/imm.c b/dlls/win32u/imm.c index 5adfe3704aa..1b78a12a803 100644 --- a/dlls/win32u/imm.c +++ b/dlls/win32u/imm.c @@ -212,8 +212,9 @@ UINT WINAPI NtUserAssociateInputContext( HWND hwnd, HIMC ctx, ULONG flags ) HIMC get_default_input_context(void) { struct ntuser_thread_info *thread_info = NtUserGetThreadInfo(); - if (!thread_info->default_imc) thread_info->default_imc = NtUserCreateInputContext( 0 ); - return thread_info->default_imc; + if (!thread_info->default_imc) + thread_info->default_imc = HandleToUlong( NtUserCreateInputContext( 0 )); + return UlongToHandle( thread_info->default_imc ); } HIMC get_window_input_context( HWND hwnd ) @@ -390,7 +391,7 @@ void cleanup_imm_thread(void) thread_info->imm_thread_data = NULL; } - NtUserDestroyInputContext( thread_info->client_info.default_imc ); + NtUserDestroyInputContext( UlongToHandle( thread_info->client_info.default_imc )); } BOOL WINAPI ImmProcessKey( HWND hwnd, HKL hkl, UINT vkey, LPARAM key_data, DWORD unknown ) diff --git a/dlls/win32u/window.c b/dlls/win32u/window.c index 61de6ad1c33..c4e14381cf5 100644 --- a/dlls/win32u/window.c +++ b/dlls/win32u/window.c @@ -173,7 +173,7 @@ HWND get_hwnd_message_parent(void) struct ntuser_thread_info *thread_info = NtUserGetThreadInfo(); if (!thread_info->msg_window) get_desktop_window(); /* trigger creation */ - return thread_info->msg_window; + return UlongToHandle( thread_info->msg_window ); } /*********************************************************************** @@ -225,8 +225,8 @@ BOOL is_desktop_window( HWND hwnd ) struct ntuser_thread_info *thread_info = NtUserGetThreadInfo(); if (!hwnd) return FALSE; - if (hwnd == thread_info->top_window) return TRUE; - if (hwnd == thread_info->msg_window) return TRUE; + if (hwnd == UlongToHandle( thread_info->top_window )) return TRUE; + if (hwnd == UlongToHandle( thread_info->msg_window )) return TRUE; if (!HIWORD(hwnd) || HIWORD(hwnd) == 0xffff) { @@ -4930,15 +4930,18 @@ static WND *create_window_handle( HWND parent, HWND owner, UNICODE_STRING *name, if (name->Buffer == (const WCHAR *)DESKTOP_CLASS_ATOM) { - if (!thread_info->top_window) thread_info->top_window = full_parent ? full_parent : handle; - else assert( full_parent == thread_info->top_window ); - if (full_parent && !user_driver->pCreateDesktopWindow( thread_info->top_window )) + if (!thread_info->top_window) + thread_info->top_window = HandleToUlong( full_parent ? full_parent : handle ); + else assert( full_parent == UlongToHandle( thread_info->top_window )); + if (full_parent && + !user_driver->pCreateDesktopWindow( UlongToHandle( thread_info->top_window ))) ERR( "failed to create desktop window\n" ); register_builtin_classes(); } else /* HWND_MESSAGE parent */ { - if (!thread_info->msg_window && !full_parent) thread_info->msg_window = handle; + if (!thread_info->msg_window && !full_parent) + thread_info->msg_window = HandleToUlong( handle ); } } diff --git a/dlls/win32u/winstation.c b/dlls/win32u/winstation.c index 0f6fb66a2b2..d3eb145b7c5 100644 --- a/dlls/win32u/winstation.c +++ b/dlls/win32u/winstation.c @@ -399,7 +399,7 @@ HWND get_desktop_window(void) { struct ntuser_thread_info *thread_info = NtUserGetThreadInfo(); - if (thread_info->top_window) return thread_info->top_window; + if (thread_info->top_window) return UlongToHandle( thread_info->top_window ); SERVER_START_REQ( get_desktop_window ) @@ -407,8 +407,8 @@ HWND get_desktop_window(void) req->force = 0; if (!wine_server_call( req )) { - thread_info->top_window = wine_server_ptr_handle( reply->top_window ); - thread_info->msg_window = wine_server_ptr_handle( reply->msg_window ); + thread_info->top_window = reply->top_window; + thread_info->msg_window = reply->msg_window; } } SERVER_END_REQ; @@ -489,18 +489,19 @@ HWND get_desktop_window(void) req->force = 1; if (!wine_server_call( req )) { - thread_info->top_window = wine_server_ptr_handle( reply->top_window ); - thread_info->msg_window = wine_server_ptr_handle( reply->msg_window ); + thread_info->top_window = reply->top_window; + thread_info->msg_window = reply->msg_window; } } SERVER_END_REQ; } - if (!thread_info->top_window || !user_driver->pCreateDesktopWindow( thread_info->top_window )) + if (!thread_info->top_window || + !user_driver->pCreateDesktopWindow( UlongToHandle( thread_info->top_window ))) ERR_(win)( "failed to create desktop window\n" ); register_builtin_classes(); - return thread_info->top_window; + return UlongToHandle( thread_info->top_window ); } static HANDLE get_winstations_dir_handle(void) diff --git a/dlls/wineandroid.drv/device.c b/dlls/wineandroid.drv/device.c index 62bcbae72f3..b7292b5faf1 100644 --- a/dlls/wineandroid.drv/device.c +++ b/dlls/wineandroid.drv/device.c @@ -245,7 +245,7 @@ static inline BOOL is_in_desktop_process(void) static inline DWORD current_client_id(void) { - DWORD client_id = PtrToUlong( NtUserGetThreadInfo()->driver_data ); + DWORD client_id = NtUserGetThreadInfo()->driver_data; return client_id ? client_id : GetCurrentProcessId(); } @@ -1137,7 +1137,7 @@ NTSTATUS android_dispatch_ioctl( void *arg ) if (in_size >= sizeof(*header)) { irp->IoStatus.Information = 0; - NtUserGetThreadInfo()->driver_data = UlongToHandle( params->client_id ); + NtUserGetThreadInfo()->driver_data = params->client_id; irp->IoStatus.u.Status = func( irp->AssociatedIrp.SystemBuffer, in_size, irpsp->Parameters.DeviceIoControl.OutputBufferLength, &irp->IoStatus.Information ); diff --git a/dlls/winemac.drv/macdrv.h b/dlls/winemac.drv/macdrv.h index 2e44206dc92..b5524517a7e 100644 --- a/dlls/winemac.drv/macdrv.h +++ b/dlls/winemac.drv/macdrv.h @@ -117,7 +117,7 @@ static inline RECT rect_from_cgrect(CGRect cgrect) static inline struct macdrv_thread_data *macdrv_thread_data(void) { - return NtUserGetThreadInfo()->driver_data; + return (struct macdrv_thread_data *)(UINT_PTR)NtUserGetThreadInfo()->driver_data; } diff --git a/dlls/winemac.drv/macdrv_main.c b/dlls/winemac.drv/macdrv_main.c index 7cca25cf302..1f8ea268f45 100644 --- a/dlls/winemac.drv/macdrv_main.c +++ b/dlls/winemac.drv/macdrv_main.c @@ -536,7 +536,7 @@ struct macdrv_thread_data *macdrv_init_thread_data(void) macdrv_compute_keyboard_layout(data); set_queue_display_fd(macdrv_get_event_queue_fd(data->queue)); - NtUserGetThreadInfo()->driver_data = data; + NtUserGetThreadInfo()->driver_data = (UINT_PTR)data; NtUserActivateKeyboardLayout(data->active_keyboard_layout, 0); return data; diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h index 31a94d1632a..ad4a520af13 100644 --- a/dlls/winex11.drv/x11drv.h +++ b/dlls/winex11.drv/x11drv.h @@ -393,7 +393,7 @@ extern struct x11drv_thread_data *x11drv_init_thread_data(void) DECLSPEC_HIDDEN; static inline struct x11drv_thread_data *x11drv_thread_data(void) { - return NtUserGetThreadInfo()->driver_data; + return (struct x11drv_thread_data *)(UINT_PTR)NtUserGetThreadInfo()->driver_data; } /* retrieve the thread display, or NULL if not created yet */ diff --git a/dlls/winex11.drv/x11drv_main.c b/dlls/winex11.drv/x11drv_main.c index 20e07679635..e94977f8caf 100644 --- a/dlls/winex11.drv/x11drv_main.c +++ b/dlls/winex11.drv/x11drv_main.c @@ -734,7 +734,7 @@ void X11DRV_ThreadDetach(void) XCloseDisplay( data->display ); free( data ); /* clear data in case we get re-entered from user32 before the thread is truly dead */ - NtUserGetThreadInfo()->driver_data = NULL; + NtUserGetThreadInfo()->driver_data = 0; } } @@ -795,7 +795,7 @@ struct x11drv_thread_data *x11drv_init_thread_data(void) if (TRACE_ON(synchronous)) XSynchronize( data->display, True ); set_queue_display_fd( data->display ); - NtUserGetThreadInfo()->driver_data = data; + NtUserGetThreadInfo()->driver_data = (UINT_PTR)data; if (use_xim) X11DRV_SetupXIM(); diff --git a/include/ntuser.h b/include/ntuser.h index e3694bde779..84cb7fdb9b8 100644 --- a/include/ntuser.h +++ b/include/ntuser.h @@ -61,19 +61,19 @@ enum /* TEB thread info, not compatible with Windows */ struct ntuser_thread_info { - void *driver_data; /* driver-specific data */ + UINT64 driver_data; /* driver-specific data */ DWORD message_time; /* value for GetMessageTime */ DWORD message_pos; /* value for GetMessagePos */ - ULONG_PTR message_extra; /* value for GetMessageExtraInfo */ + UINT64 message_extra; /* value for GetMessageExtraInfo */ INPUT_MESSAGE_SOURCE msg_source; /* Message source for current message */ WORD recursion_count; /* SendMessage recursion counter */ UINT receive_flags; /* currently received message flags */ - HWND top_window; /* desktop window */ - HWND msg_window; /* HWND_MESSAGE parent window */ + UINT top_window; /* desktop window */ + UINT msg_window; /* HWND_MESSAGE parent window */ DPI_AWARENESS dpi_awareness; /* DPI awareness */ - HIMC default_imc; /* default input context */ - void *client_imm; /* client IMM thread info */ - struct wm_char_mapping_data *wmchar_data; /* Data for WM_CHAR mappings */ + UINT default_imc; /* default input context */ + UINT64 client_imm; /* client IMM thread info */ + UINT64 wmchar_data; /* client data for WM_CHAR mappings */ }; static inline struct ntuser_thread_info *NtUserGetThreadInfo(void)