[v2 PATCH 2/2] kernel32: Implement higher level API to access thread description.

Nikolay Sivov nsivov at codeweavers.com
Tue Nov 26 00:48:11 CST 2019


Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
---
 ...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                      | 58 ++++++++++++++++++-
 5 files changed, 60 insertions(+), 5 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 6f0c4fa752..9cc853d288 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 367f5d2373..984422d2b4 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 180eed8241..8ff34ba5f3 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 7d20d3b112..6022d4ea37 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 345f44dff7..b8ce4bdb48 100644
--- a/dlls/kernelbase/thread.c
+++ b/dlls/kernelbase/thread.c
@@ -20,6 +20,7 @@
 
 #include <stdarg.h>
 #include <string.h>
+#include <limits.h>
 
 #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);
 
@@ -392,10 +394,62 @@ BOOL WINAPI DECLSPEC_HOTPATCH SetThreadContext( HANDLE thread, const CONTEXT *co
  */
 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.@)
-- 
2.24.0




More information about the wine-devel mailing list