win32u: Send the total number of registered devices to the server.

Instead of device_count which is the number of registration updates,
and execute the request within the rawinput_mutex to ensure atomicity
of the update and consistency between the client and the server state.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=53468
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=53487
This commit is contained in:
Rémi Bernon 2022-08-05 11:25:49 +02:00 committed by Alexandre Julliard
parent b5ed538993
commit 17bdb5060a

View file

@ -866,8 +866,15 @@ BOOL WINAPI NtUserRegisterRawInputDevices( const RAWINPUTDEVICE *devices, UINT d
registered_devices = realloc( registered_devices, size );
if (registered_devices) for (i = 0; i < device_count; ++i) register_rawinput_device( devices + i );
server_devices = malloc( registered_device_count * sizeof(*server_devices) );
if (server_devices) for (i = 0; i < registered_device_count; ++i)
if (!(device_count = registered_device_count)) server_devices = NULL;
else if (!(server_devices = malloc( device_count * sizeof(*server_devices) )))
{
pthread_mutex_unlock( &rawinput_mutex );
SetLastError( ERROR_OUTOFMEMORY );
return FALSE;
}
for (i = 0; i < device_count; ++i)
{
server_devices[i].usage_page = registered_devices[i].usUsagePage;
server_devices[i].usage = registered_devices[i].usUsage;
@ -875,14 +882,6 @@ BOOL WINAPI NtUserRegisterRawInputDevices( const RAWINPUTDEVICE *devices, UINT d
server_devices[i].target = wine_server_user_handle( registered_devices[i].hwndTarget );
}
pthread_mutex_unlock( &rawinput_mutex );
if (!registered_devices || !server_devices)
{
SetLastError( ERROR_OUTOFMEMORY );
return FALSE;
}
SERVER_START_REQ( update_rawinput_devices )
{
wine_server_add_data( req, server_devices, device_count * sizeof(*server_devices) );
@ -892,6 +891,14 @@ BOOL WINAPI NtUserRegisterRawInputDevices( const RAWINPUTDEVICE *devices, UINT d
free( server_devices );
pthread_mutex_unlock( &rawinput_mutex );
if (!registered_devices)
{
SetLastError( ERROR_OUTOFMEMORY );
return FALSE;
}
return ret;
}