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; }