From 179cd78f828c67a113e5f0ad85952cfb99c0a281 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Tue, 26 Nov 2019 09:48:11 +0300 Subject: [PATCH] kernel32: Implement higher level API to access thread description. Signed-off-by: Nikolay Sivov Signed-off-by: Alexandre Julliard --- ...api-ms-win-core-processthreads-l1-1-3.spec | 2 +- dlls/kernel32/kernel32.spec | 1 + dlls/kernel32/tests/thread.c | 2 +- dlls/kernelbase/kernelbase.spec | 2 +- dlls/kernelbase/thread.c | 60 ++++++++++++++++++- 5 files changed, 61 insertions(+), 6 deletions(-) diff --git a/dlls/api-ms-win-core-processthreads-l1-1-3/api-ms-win-core-processthreads-l1-1-3.spec b/dlls/api-ms-win-core-processthreads-l1-1-3/api-ms-win-core-processthreads-l1-1-3.spec index 6f0c4fa7529..9cc853d2884 100644 --- a/dlls/api-ms-win-core-processthreads-l1-1-3/api-ms-win-core-processthreads-l1-1-3.spec +++ b/dlls/api-ms-win-core-processthreads-l1-1-3/api-ms-win-core-processthreads-l1-1-3.spec @@ -1,7 +1,7 @@ @ stub GetProcessDefaultCpuSets @ stub GetProcessInformation @ stub GetSystemCpuSetInformation -@ stub GetThreadDescription +@ stdcall GetThreadDescription(long ptr) kernel32.GetThreadDescription @ stub GetThreadSelectedCpuSets @ stub SetProcessDefaultCpuSets @ stub SetProcessInformation diff --git a/dlls/kernel32/kernel32.spec b/dlls/kernel32/kernel32.spec index 367f5d23739..984422d2b47 100644 --- a/dlls/kernel32/kernel32.spec +++ b/dlls/kernel32/kernel32.spec @@ -847,6 +847,7 @@ @ stdcall -import GetTempPathA(long ptr) @ stdcall -import GetTempPathW(long ptr) @ stdcall -import GetThreadContext(long ptr) +@ stdcall -import GetThreadDescription(long ptr) @ stdcall -import GetThreadErrorMode() @ stdcall -import GetThreadGroupAffinity(long ptr) @ stdcall -import GetThreadIOPendingFlag(long ptr) diff --git a/dlls/kernel32/tests/thread.c b/dlls/kernel32/tests/thread.c index 180eed82419..8ff34ba5f36 100644 --- a/dlls/kernel32/tests/thread.c +++ b/dlls/kernel32/tests/thread.c @@ -2125,7 +2125,7 @@ static void test_thread_description(void) if (!pGetThreadDescription) { - skip("Thread description API is not supported.\n"); + win_skip("Thread description API is not supported.\n"); return; } diff --git a/dlls/kernelbase/kernelbase.spec b/dlls/kernelbase/kernelbase.spec index 7d20d3b1124..6022d4ea373 100644 --- a/dlls/kernelbase/kernelbase.spec +++ b/dlls/kernelbase/kernelbase.spec @@ -711,7 +711,7 @@ @ stdcall GetTempPathA(long ptr) @ stdcall GetTempPathW(long ptr) @ stdcall GetThreadContext(long ptr) -# @ stub GetThreadDescription +@ stdcall GetThreadDescription(long ptr) @ stdcall GetThreadErrorMode() @ stdcall GetThreadGroupAffinity(long ptr) @ stdcall GetThreadIOPendingFlag(long ptr) diff --git a/dlls/kernelbase/thread.c b/dlls/kernelbase/thread.c index 345f44dff7f..521d3be0798 100644 --- a/dlls/kernelbase/thread.c +++ b/dlls/kernelbase/thread.c @@ -20,6 +20,7 @@ #include #include +#include #include "ntstatus.h" #define WIN32_NO_STATUS @@ -33,6 +34,7 @@ #include "wine/exception.h" #include "wine/asm.h" #include "wine/debug.h" +#include "wine/heap.h" WINE_DEFAULT_DEBUG_CHANNEL(thread); @@ -390,12 +392,64 @@ BOOL WINAPI DECLSPEC_HOTPATCH SetThreadContext( HANDLE thread, const CONTEXT *co /*********************************************************************** * SetThreadDescription (kernelbase.@) */ -HRESULT WINAPI /* DECLSPEC_HOTPATCH */ SetThreadDescription( HANDLE thread, PCWSTR description ) +HRESULT WINAPI DECLSPEC_HOTPATCH SetThreadDescription( HANDLE thread, PCWSTR description ) { - FIXME( "(%p %s): stub\n", thread, debugstr_w( description )); - return E_NOTIMPL; + THREAD_DESCRIPTION_INFORMATION info; + int length; + + TRACE( "(%p, %s)\n", thread, debugstr_w( description )); + + length = description ? lstrlenW( description ) * sizeof(WCHAR) : 0; + + if (length > USHRT_MAX) + return HRESULT_FROM_NT(STATUS_INVALID_PARAMETER); + + info.Length = length << 16 | length; + info.Description = (WCHAR *)description; + + return HRESULT_FROM_NT(NtSetInformationThread( thread, ThreadDescription, &info, sizeof(info) )); } +/*********************************************************************** + * GetThreadDescription (kernelbase.@) + */ +HRESULT WINAPI DECLSPEC_HOTPATCH GetThreadDescription( HANDLE thread, WCHAR **description ) +{ + THREAD_DESCRIPTION_INFORMATION *info; + NTSTATUS status; + ULONG length; + + TRACE( "(%p, %p)\n", thread, description ); + + *description = NULL; + + length = 0; + status = NtQueryInformationThread( thread, ThreadDescription, NULL, 0, &length ); + if (status != STATUS_BUFFER_TOO_SMALL) + return HRESULT_FROM_NT(status); + + if (!(info = heap_alloc( length ))) + return HRESULT_FROM_NT(STATUS_NO_MEMORY); + + status = NtQueryInformationThread( thread, ThreadDescription, info, length, &length ); + if (!status) + { + length = info->Length & 0xffff; + + if (!(*description = LocalAlloc( 0, length + sizeof(WCHAR)))) + status = STATUS_NO_MEMORY; + else + { + if (length) + memcpy(*description, info->Description, length); + (*description)[length / sizeof(WCHAR)] = 0; + } + } + + heap_free(info); + + return HRESULT_FROM_NT(status); +} /*********************************************************************** * SetThreadErrorMode (kernelbase.@)