ntdll: Use better type for thread description info structure.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
stable
Nikolay Sivov 2019-12-03 12:05:21 +03:00 committed by Alexandre Julliard
parent b21ec9ffc2
commit 7082ebc608
4 changed files with 26 additions and 31 deletions

View File

@ -2145,14 +2145,15 @@ static void test_thread_description(void)
ok(len == sizeof(*thread_desc), "Unexpected structure length %u.\n", len); ok(len == sizeof(*thread_desc), "Unexpected structure length %u.\n", len);
len2 = 0; len2 = 0;
thread_desc->Length = 1; thread_desc->Description.Length = 1;
thread_desc->Description = (WCHAR *)thread_desc; thread_desc->Description.MaximumLength = 0;
thread_desc->Description.Buffer = (WCHAR *)thread_desc;
status = pNtQueryInformationThread(GetCurrentThread(), ThreadDescription, thread_desc, len, &len2); status = pNtQueryInformationThread(GetCurrentThread(), ThreadDescription, thread_desc, len, &len2);
ok(!status, "Failed to get thread info, status %#x.\n", status); ok(!status, "Failed to get thread info, status %#x.\n", status);
ok(len2 == sizeof(*thread_desc), "Unexpected structure length %u.\n", len); ok(len2 == sizeof(*thread_desc), "Unexpected structure length %u.\n", len);
ok(!thread_desc->Length, "Unexpected description length %#x.\n", thread_desc->Length); ok(!thread_desc->Description.Length, "Unexpected description length %#x.\n", thread_desc->Description.Length);
ok(thread_desc->Description == (WCHAR *)(thread_desc + 1), "Unexpected description string pointer %p, %p.\n", ok(thread_desc->Description.Buffer == (WCHAR *)(thread_desc + 1),
thread_desc->Description, thread_desc); "Unexpected description string pointer %p, %p.\n", thread_desc->Description.Buffer, thread_desc);
hr = pSetThreadDescription(GetCurrentThread(), NULL); hr = pSetThreadDescription(GetCurrentThread(), NULL);
ok(hr == HRESULT_FROM_NT(STATUS_SUCCESS), "Failed to set thread description, hr %#x.\n", hr); ok(hr == HRESULT_FROM_NT(STATUS_SUCCESS), "Failed to set thread description, hr %#x.\n", hr);
@ -2176,11 +2177,11 @@ static void test_thread_description(void)
ok(!status, "Failed to get thread info.\n"); ok(!status, "Failed to get thread info.\n");
ok(len == sizeof(*thread_desc) + desc_len, "Unexpected structure length %u.\n", len); ok(len == sizeof(*thread_desc) + desc_len, "Unexpected structure length %u.\n", len);
ok(thread_desc->Length == (desc_len << 16 | desc_len), "Unexpected description length %#x.\n", ok(thread_desc->Description.Length == desc_len && thread_desc->Description.MaximumLength == desc_len,
thread_desc->Length); "Unexpected description length %u.\n", thread_desc->Description.Length);
ok(thread_desc->Description == (WCHAR *)(thread_desc + 1), "Unexpected description string pointer %p, %p.\n", ok(thread_desc->Description.Buffer == (WCHAR *)(thread_desc + 1),
thread_desc->Description, thread_desc); "Unexpected description string pointer %p, %p.\n", thread_desc->Description.Buffer, thread_desc);
ok(!memcmp(thread_desc->Description, desc, desc_len), "Unexpected description string.\n"); ok(!memcmp(thread_desc->Description.Buffer, desc, desc_len), "Unexpected description string.\n");
/* Partial results. */ /* Partial results. */
len = 0; len = 0;
@ -2193,7 +2194,7 @@ static void test_thread_description(void)
ok(len == sizeof(*thread_desc) + desc_len, "Unexpected structure length %u.\n", len); ok(len == sizeof(*thread_desc) + desc_len, "Unexpected structure length %u.\n", len);
/* Change description. */ /* Change description. */
thread_desc->Length = 8 << 16 | 8; thread_desc->Description.Length = thread_desc->Description.MaximumLength = 8;
lstrcpyW((WCHAR *)(thread_desc + 1), L"desc"); lstrcpyW((WCHAR *)(thread_desc + 1), L"desc");
status = pNtSetInformationThread(GetCurrentThread(), ThreadDescription, thread_desc, sizeof(*thread_desc)); status = pNtSetInformationThread(GetCurrentThread(), ThreadDescription, thread_desc, sizeof(*thread_desc));
@ -2211,7 +2212,7 @@ static void test_thread_description(void)
status = NtSetInformationThread(GetCurrentThread(), ThreadDescription, NULL, sizeof(*thread_desc)); status = NtSetInformationThread(GetCurrentThread(), ThreadDescription, NULL, sizeof(*thread_desc));
ok(status == STATUS_ACCESS_VIOLATION, "Unexpected status %#x.\n", status); ok(status == STATUS_ACCESS_VIOLATION, "Unexpected status %#x.\n", status);
thread_desc->Description = NULL; thread_desc->Description.Buffer = NULL;
status = pNtSetInformationThread(GetCurrentThread(), ThreadDescription, thread_desc, sizeof(*thread_desc)); status = pNtSetInformationThread(GetCurrentThread(), ThreadDescription, thread_desc, sizeof(*thread_desc));
ok(status == STATUS_ACCESS_VIOLATION, "Unexpected status %#x.\n", status); ok(status == STATUS_ACCESS_VIOLATION, "Unexpected status %#x.\n", status);
@ -2228,8 +2229,7 @@ static void test_thread_description(void)
hr = pSetThreadDescription(GetCurrentThread(), L"123"); hr = pSetThreadDescription(GetCurrentThread(), L"123");
ok(hr == HRESULT_FROM_NT(STATUS_SUCCESS), "Failed to set thread description, hr %#x.\n", hr); ok(hr == HRESULT_FROM_NT(STATUS_SUCCESS), "Failed to set thread description, hr %#x.\n", hr);
thread_desc->Length = 0; memset(thread_desc, 0, sizeof(*thread_desc));
thread_desc->Description = NULL;
status = pNtSetInformationThread(GetCurrentThread(), ThreadDescription, thread_desc, sizeof(*thread_desc)); status = pNtSetInformationThread(GetCurrentThread(), ThreadDescription, thread_desc, sizeof(*thread_desc));
ok(!status, "Failed to set thread description, status %#x.\n", status); ok(!status, "Failed to set thread description, status %#x.\n", status);

View File

@ -404,8 +404,8 @@ HRESULT WINAPI DECLSPEC_HOTPATCH SetThreadDescription( HANDLE thread, PCWSTR des
if (length > USHRT_MAX) if (length > USHRT_MAX)
return HRESULT_FROM_NT(STATUS_INVALID_PARAMETER); return HRESULT_FROM_NT(STATUS_INVALID_PARAMETER);
info.Length = length << 16 | length; info.Description.Length = info.Description.MaximumLength = length;
info.Description = (WCHAR *)description; info.Description.Buffer = (WCHAR *)description;
return HRESULT_FROM_NT(NtSetInformationThread( thread, ThreadDescription, &info, sizeof(info) )); return HRESULT_FROM_NT(NtSetInformationThread( thread, ThreadDescription, &info, sizeof(info) ));
} }
@ -434,15 +434,13 @@ HRESULT WINAPI DECLSPEC_HOTPATCH GetThreadDescription( HANDLE thread, WCHAR **de
status = NtQueryInformationThread( thread, ThreadDescription, info, length, &length ); status = NtQueryInformationThread( thread, ThreadDescription, info, length, &length );
if (!status) if (!status)
{ {
length = info->Length & 0xffff; if (!(*description = LocalAlloc( 0, info->Description.Length + sizeof(WCHAR))))
if (!(*description = LocalAlloc( 0, length + sizeof(WCHAR))))
status = STATUS_NO_MEMORY; status = STATUS_NO_MEMORY;
else else
{ {
if (length) if (info->Description.Length)
memcpy(*description, info->Description, length); memcpy(*description, info->Description.Buffer, info->Description.Length);
(*description)[length / sizeof(WCHAR)] = 0; (*description)[info->Description.Length / sizeof(WCHAR)] = 0;
} }
} }

View File

@ -1137,8 +1137,8 @@ NTSTATUS WINAPI NtQueryInformationThread( HANDLE handle, THREADINFOCLASS class,
status = STATUS_BUFFER_TOO_SMALL; status = STATUS_BUFFER_TOO_SMALL;
else if (status == STATUS_SUCCESS) else if (status == STATUS_SUCCESS)
{ {
info->Length = desc_len << 16 | desc_len; info->Description.Length = info->Description.MaximumLength = desc_len;
info->Description = ptr; info->Description.Buffer = ptr;
} }
if (ret_len && (status == STATUS_SUCCESS || status == STATUS_BUFFER_TOO_SMALL)) if (ret_len && (status == STATUS_SUCCESS || status == STATUS_BUFFER_TOO_SMALL))
@ -1303,20 +1303,18 @@ NTSTATUS WINAPI NtSetInformationThread( HANDLE handle, THREADINFOCLASS class,
case ThreadDescription: case ThreadDescription:
{ {
const THREAD_DESCRIPTION_INFORMATION *info = data; const THREAD_DESCRIPTION_INFORMATION *info = data;
data_size_t desc_len;
if (length != sizeof(*info)) return STATUS_INFO_LENGTH_MISMATCH; if (length != sizeof(*info)) return STATUS_INFO_LENGTH_MISMATCH;
if (!info) return STATUS_ACCESS_VIOLATION; if (!info) return STATUS_ACCESS_VIOLATION;
desc_len = info->Length & 0xffff; if (info->Description.Length != info->Description.MaximumLength) return STATUS_INVALID_PARAMETER;
if (info->Length >> 16 != desc_len) return STATUS_INVALID_PARAMETER; if (info->Description.Length && !info->Description.Buffer) return STATUS_ACCESS_VIOLATION;
if (info->Length && !info->Description) return STATUS_ACCESS_VIOLATION;
SERVER_START_REQ( set_thread_info ) SERVER_START_REQ( set_thread_info )
{ {
req->handle = wine_server_obj_handle( handle ); req->handle = wine_server_obj_handle( handle );
req->mask = SET_THREAD_INFO_DESCRIPTION; req->mask = SET_THREAD_INFO_DESCRIPTION;
wine_server_add_data( req, info->Description, desc_len ); wine_server_add_data( req, info->Description.Buffer, info->Description.Length );
status = wine_server_call( req ); status = wine_server_call( req );
} }
SERVER_END_REQ; SERVER_END_REQ;

View File

@ -1030,8 +1030,7 @@ typedef struct _THREAD_DESCRIPTOR_INFORMATION
typedef struct _THREAD_DESCRIPTION_INFORMATION typedef struct _THREAD_DESCRIPTION_INFORMATION
{ {
DWORD Length; UNICODE_STRING Description;
WCHAR *Description;
} THREAD_DESCRIPTION_INFORMATION, *PTHREAD_DESCRIPTION_INFORMATION; } THREAD_DESCRIPTION_INFORMATION, *PTHREAD_DESCRIPTION_INFORMATION;
typedef struct _KERNEL_USER_TIMES { typedef struct _KERNEL_USER_TIMES {