kernel32: Implement higher level API to access thread description.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
stable
Nikolay Sivov 2019-11-26 09:48:11 +03:00 committed by Alexandre Julliard
parent b934f6626e
commit 179cd78f82
5 changed files with 61 additions and 6 deletions

View File

@ -1,7 +1,7 @@
@ stub GetProcessDefaultCpuSets @ stub GetProcessDefaultCpuSets
@ stub GetProcessInformation @ stub GetProcessInformation
@ stub GetSystemCpuSetInformation @ stub GetSystemCpuSetInformation
@ stub GetThreadDescription @ stdcall GetThreadDescription(long ptr) kernel32.GetThreadDescription
@ stub GetThreadSelectedCpuSets @ stub GetThreadSelectedCpuSets
@ stub SetProcessDefaultCpuSets @ stub SetProcessDefaultCpuSets
@ stub SetProcessInformation @ stub SetProcessInformation

View File

@ -847,6 +847,7 @@
@ stdcall -import GetTempPathA(long ptr) @ stdcall -import GetTempPathA(long ptr)
@ stdcall -import GetTempPathW(long ptr) @ stdcall -import GetTempPathW(long ptr)
@ stdcall -import GetThreadContext(long ptr) @ stdcall -import GetThreadContext(long ptr)
@ stdcall -import GetThreadDescription(long ptr)
@ stdcall -import GetThreadErrorMode() @ stdcall -import GetThreadErrorMode()
@ stdcall -import GetThreadGroupAffinity(long ptr) @ stdcall -import GetThreadGroupAffinity(long ptr)
@ stdcall -import GetThreadIOPendingFlag(long ptr) @ stdcall -import GetThreadIOPendingFlag(long ptr)

View File

@ -2125,7 +2125,7 @@ static void test_thread_description(void)
if (!pGetThreadDescription) if (!pGetThreadDescription)
{ {
skip("Thread description API is not supported.\n"); win_skip("Thread description API is not supported.\n");
return; return;
} }

View File

@ -711,7 +711,7 @@
@ stdcall GetTempPathA(long ptr) @ stdcall GetTempPathA(long ptr)
@ stdcall GetTempPathW(long ptr) @ stdcall GetTempPathW(long ptr)
@ stdcall GetThreadContext(long ptr) @ stdcall GetThreadContext(long ptr)
# @ stub GetThreadDescription @ stdcall GetThreadDescription(long ptr)
@ stdcall GetThreadErrorMode() @ stdcall GetThreadErrorMode()
@ stdcall GetThreadGroupAffinity(long ptr) @ stdcall GetThreadGroupAffinity(long ptr)
@ stdcall GetThreadIOPendingFlag(long ptr) @ stdcall GetThreadIOPendingFlag(long ptr)

View File

@ -20,6 +20,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <limits.h>
#include "ntstatus.h" #include "ntstatus.h"
#define WIN32_NO_STATUS #define WIN32_NO_STATUS
@ -33,6 +34,7 @@
#include "wine/exception.h" #include "wine/exception.h"
#include "wine/asm.h" #include "wine/asm.h"
#include "wine/debug.h" #include "wine/debug.h"
#include "wine/heap.h"
WINE_DEFAULT_DEBUG_CHANNEL(thread); WINE_DEFAULT_DEBUG_CHANNEL(thread);
@ -390,12 +392,64 @@ BOOL WINAPI DECLSPEC_HOTPATCH SetThreadContext( HANDLE thread, const CONTEXT *co
/*********************************************************************** /***********************************************************************
* SetThreadDescription (kernelbase.@) * 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 )); THREAD_DESCRIPTION_INFORMATION info;
return E_NOTIMPL; 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.@) * SetThreadErrorMode (kernelbase.@)