Set the native thread name on Linux when set with SetThreadDescription(). I'm also working on support for macOS and exception-based thread naming.
This uses the `get_thread_times` server call to get the PID/TID, is this ok or should I make a new server call for this?
`/proc/%u/task/%u/comm` is documented in the proc(5) man page, strings written to it are silently truncated at `TASK_COMM_LEN` (16) characters.
From: Brendan Shanks bshanks@codeweavers.com
--- dlls/ntdll/unix/thread.c | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+)
diff --git a/dlls/ntdll/unix/thread.c b/dlls/ntdll/unix/thread.c index bb8c1c2936b..06d1de53a56 100644 --- a/dlls/ntdll/unix/thread.c +++ b/dlls/ntdll/unix/thread.c @@ -1828,6 +1828,63 @@ BOOL get_thread_times(int unix_pid, int unix_tid, LARGE_INTEGER *kernel_time, LA #endif }
+static void set_native_thread_name( HANDLE handle, const UNICODE_STRING *name ) +{ + char nameA[64]; + NTSTATUS status; + int unix_pid, unix_tid; + + SERVER_START_REQ( get_thread_times ) + { + req->handle = wine_server_obj_handle( handle ); + status = wine_server_call( req ); + if (status == STATUS_SUCCESS) + { + unix_pid = reply->unix_pid; + unix_tid = reply->unix_tid; + } + } + SERVER_END_REQ; + + if (status != STATUS_SUCCESS || unix_pid == -1 || unix_tid == -1) + return; + + if (unix_pid != getpid()) + { + static int once; + if (!once++) FIXME("cross-process native thread naming not supported\n"); + return; + } + + nameA[0] = '\0'; + if (name->Length) + { + size_t len = name->Length / sizeof(WCHAR); + int ret = ntdll_wcstoumbs(name->Buffer, len, nameA, sizeof(nameA) - 1, FALSE); + if (ret >= 0) + nameA[ret] = '\0'; + } + +#ifdef linux + { + char path[64]; + FILE *f; + + sprintf(path, "/proc/%u/task/%u/comm", unix_pid, unix_tid); + + f = fopen(path, "w"); + if (!f) + return; + fwrite(nameA, strlen(nameA), 1, f); + fclose(f); + } +#else + static int once; + if (!once++) FIXME("not implemented on this platform\n"); + return; +#endif +} + #ifndef _WIN64 static BOOL is_process_wow64( const CLIENT_ID *id ) { @@ -2254,6 +2311,9 @@ NTSTATUS WINAPI NtSetInformationThread( HANDLE handle, THREADINFOCLASS class, status = wine_server_call( req ); } SERVER_END_REQ; + + set_native_thread_name( handle, &info->ThreadName ); + return status; }
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The tests also ran into some preexisting test failures. If you know how to fix them that would be helpful. See the TestBot job for the details:
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=125107
Your paranoid android.
=== debian11 (32 bit report) ===
ddraw: ddraw7.c:15663: Test failed: Expected unsynchronised map for flags 0x1000. ddraw7.c:15663: Test failed: Expected unsynchronised map for flags 0x3000.
=== debian11 (build log) ===
Use of uninitialized value $Flaky in addition (+) at /home/testbot/lib/WineTestBot/LogUtils.pm line 720, <$LogFile> line 24735. Use of uninitialized value $Flaky in addition (+) at /home/testbot/lib/WineTestBot/LogUtils.pm line 720, <$LogFile> line 24735. Use of uninitialized value $Flaky in addition (+) at /home/testbot/lib/WineTestBot/LogUtils.pm line 720, <$LogFile> line 24735.