[PATCH 2/4] win32u: Move raw input thread data allocation from user32.

Zebediah Figura wine at gitlab.winehq.org
Fri Jun 17 20:17:11 CDT 2022


From: Zebediah Figura <zfigura at codeweavers.com>

---
 dlls/user32/rawinput.c       | 11 -----------
 dlls/user32/user_main.c      |  2 --
 dlls/user32/user_private.h   |  1 -
 dlls/win32u/ntuser_private.h |  1 -
 dlls/win32u/rawinput.c       | 15 ++++++++++++---
 dlls/win32u/sysparams.c      |  1 +
 6 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/dlls/user32/rawinput.c b/dlls/user32/rawinput.c
index 9286aceb670..d6290f08d12 100644
--- a/dlls/user32/rawinput.c
+++ b/dlls/user32/rawinput.c
@@ -351,17 +351,6 @@ BOOL rawinput_device_get_usages(HANDLE handle, USAGE *usage_page, USAGE *usage)
 }
 
 
-struct rawinput_thread_data * WINAPI rawinput_thread_data(void)
-{
-    struct user_thread_info *thread_info = get_user_thread_info();
-    struct rawinput_thread_data *data = thread_info->rawinput;
-    if (data) return data;
-    data = thread_info->rawinput = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
-                                              RAWINPUT_BUFFER_SIZE + sizeof(struct user_thread_info) );
-    return data;
-}
-
-
 /***********************************************************************
  *              GetRawInputDeviceList   (USER32.@)
  */
diff --git a/dlls/user32/user_main.c b/dlls/user32/user_main.c
index 72d5f30e536..55e72dcf203 100644
--- a/dlls/user32/user_main.c
+++ b/dlls/user32/user_main.c
@@ -169,7 +169,6 @@ static const struct user_callbacks user_funcs =
     register_imm,
     unregister_imm,
     try_finally,
-    rawinput_thread_data,
 };
 
 static NTSTATUS WINAPI User32CopyImage( const struct copy_image_params *params, ULONG size )
@@ -271,7 +270,6 @@ static void thread_detach(void)
 
     NtUserCallNoParam( NtUserThreadDetach );
     HeapFree( GetProcessHeap(), 0, thread_info->wmchar_data );
-    HeapFree( GetProcessHeap(), 0, thread_info->rawinput );
 
     exiting_thread_id = 0;
 }
diff --git a/dlls/user32/user_private.h b/dlls/user32/user_private.h
index d15a3b6856e..71248e03bb8 100644
--- a/dlls/user32/user_private.h
+++ b/dlls/user32/user_private.h
@@ -62,7 +62,6 @@ struct tagWND;
 
 struct hardware_msg_data;
 extern BOOL rawinput_device_get_usages(HANDLE handle, USAGE *usage_page, USAGE *usage);
-extern struct rawinput_thread_data * WINAPI rawinput_thread_data(void);
 extern void CDECL rawinput_update_device_list(void);
 
 extern BOOL post_dde_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam, DWORD dest_tid,
diff --git a/dlls/win32u/ntuser_private.h b/dlls/win32u/ntuser_private.h
index fd644484e48..eb851f57cdb 100644
--- a/dlls/win32u/ntuser_private.h
+++ b/dlls/win32u/ntuser_private.h
@@ -50,7 +50,6 @@ struct user_callbacks
     void (WINAPI *unregister_imm)( HWND hwnd );
     NTSTATUS (CDECL *try_finally)( NTSTATUS (CDECL *func)( void *), void *arg,
                                    void (CALLBACK *finally_func)( BOOL ));
-    struct rawinput_thread_data *(WINAPI *get_rawinput_thread_data)(void);
 };
 
 #define WM_SYSTIMER         0x0118
diff --git a/dlls/win32u/rawinput.c b/dlls/win32u/rawinput.c
index 046e25ecf6a..d6d4e0c13f7 100644
--- a/dlls/win32u/rawinput.c
+++ b/dlls/win32u/rawinput.c
@@ -58,6 +58,15 @@ typedef struct
 } RAWINPUT64;
 #endif
 
+static struct rawinput_thread_data *get_rawinput_thread_data(void)
+{
+    struct user_thread_info *thread_info = get_user_thread_info();
+    struct rawinput_thread_data *data = thread_info->rawinput;
+    if (data) return data;
+    data = thread_info->rawinput = calloc( 1, RAWINPUT_BUFFER_SIZE + sizeof(struct user_thread_info) );
+    return data;
+}
+
 static bool rawinput_from_hardware_message( RAWINPUT *rawinput, const struct hardware_msg_data *msg_data )
 {
     SIZE_T size;
@@ -223,7 +232,7 @@ UINT WINAPI NtUserGetRawInputBuffer( RAWINPUT *data, UINT *data_size, UINT heade
         return 0;
     }
 
-    if (!user_callbacks || !(thread_data = user_callbacks->get_rawinput_thread_data())) return ~0u;
+    if (!(thread_data = get_rawinput_thread_data())) return ~0u;
     rawinput = thread_data->buffer;
 
     /* first RAWINPUT block in the buffer is used for WM_INPUT message data */
@@ -286,7 +295,7 @@ UINT WINAPI NtUserGetRawInputData( HRAWINPUT rawinput, UINT command, void *data,
     TRACE( "rawinput %p, command %#x, data %p, data_size %p, header_size %u.\n",
            rawinput, command, data, data_size, header_size );
 
-    if (!user_callbacks || !(thread_data = user_callbacks->get_rawinput_thread_data()))
+    if (!(thread_data = get_rawinput_thread_data()))
     {
         SetLastError( ERROR_OUTOFMEMORY );
         return ~0u;
@@ -339,7 +348,7 @@ BOOL process_rawinput_message( MSG *msg, UINT hw_id, const struct hardware_msg_d
 {
     struct rawinput_thread_data *thread_data;
 
-    if (!user_callbacks || !(thread_data = user_callbacks->get_rawinput_thread_data()))
+    if (!(thread_data = get_rawinput_thread_data()))
         return FALSE;
 
     if (msg->message == WM_INPUT_DEVICE_CHANGE)
diff --git a/dlls/win32u/sysparams.c b/dlls/win32u/sysparams.c
index 01469c345c2..26426586fb8 100644
--- a/dlls/win32u/sysparams.c
+++ b/dlls/win32u/sysparams.c
@@ -4689,6 +4689,7 @@ static void thread_detach(void)
 
     free( thread_info->key_state );
     thread_info->key_state = 0;
+    free( thread_info->rawinput );
 
     destroy_thread_windows();
     NtClose( thread_info->server_queue );
-- 
GitLab


https://gitlab.winehq.org/wine/wine/-/merge_requests/271



More information about the wine-devel mailing list