From: Brendan Shanks bshanks@codeweavers.com
--- dlls/ntdll/unix/thread.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
diff --git a/dlls/ntdll/unix/thread.c b/dlls/ntdll/unix/thread.c index 43de6cefad3..711cb4cb13c 100644 --- a/dlls/ntdll/unix/thread.c +++ b/dlls/ntdll/unix/thread.c @@ -59,6 +59,10 @@ #include <libprocstat.h> #endif
+#ifdef __APPLE__ +#include <mach/mach.h> +#endif + #define NONAMELESSUNION #define NONAMELESSSTRUCT #include "ntstatus.h" @@ -1876,6 +1880,40 @@ static void set_native_thread_name( HANDLE handle, const UNICODE_STRING *name ) write( fd, nameA, len ); close( fd ); } +#elif defined(__APPLE__) + /* pthread_setname_np() silently fails if the name is longer than 63 characters + null terminator */ + char nameA[64]; + NTSTATUS status; + int unix_pid, unix_tid, len, current_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; + + current_tid = mach_thread_self(); + mach_port_deallocate(mach_task_self(), current_tid); + + if (unix_tid != current_tid) + { + static int once; + if (!once++) FIXME("setting other thread name not supported\n"); + return; + } + + len = ntdll_wcstoumbs( name->Buffer, name->Length / sizeof(WCHAR), nameA, sizeof(nameA) - 1, FALSE ); + nameA[len] = '\0'; + pthread_setname_np(nameA); #else static int once; if (!once++) FIXME("not implemented on this platform\n");