Pass caller names to __pthread_internal_find for better errors.
On http://b/122082295 we had this abort:
12-27 15:29:31.237 10222 10814 10848 F libc : invalid pthread_t 0xb1907960 passed to libc
This wasn't super helpful. We can do better. Now you get something like
this instead:
03-27 02:34:58.754 25329 25329 W libc : invalid pthread_t (0) passed to pthread_join
Test: adb shell crasher
Bug: http://b/123255692
Change-Id: I1d545665a233308480cc3747ec3120e2b6de0453
diff --git a/libc/bionic/pthread_setname_np.cpp b/libc/bionic/pthread_setname_np.cpp
index f582d53..f673983 100644
--- a/libc/bionic/pthread_setname_np.cpp
+++ b/libc/bionic/pthread_setname_np.cpp
@@ -42,9 +42,10 @@
// This value is not exported by kernel headers.
#define MAX_TASK_COMM_LEN 16
-static int __open_task_comm_fd(pthread_t t, int flags) {
+static int __open_task_comm_fd(pthread_t t, int flags, const char* caller) {
char comm_name[64];
- snprintf(comm_name, sizeof(comm_name), "/proc/self/task/%d/comm", pthread_gettid_np(t));
+ snprintf(comm_name, sizeof(comm_name), "/proc/self/task/%d/comm",
+ __pthread_internal_gettid(t, caller));
return open(comm_name, O_CLOEXEC | flags);
}
@@ -59,7 +60,7 @@
}
// We have to get another thread's name.
- int fd = __open_task_comm_fd(t, O_RDONLY);
+ int fd = __open_task_comm_fd(t, O_RDONLY, "pthread_getname_np");
if (fd == -1) return errno;
ssize_t n = TEMP_FAILURE_RETRY(read(fd, buf, buf_size));
@@ -91,7 +92,7 @@
}
// We have to set another thread's name.
- int fd = __open_task_comm_fd(t, O_WRONLY);
+ int fd = __open_task_comm_fd(t, O_WRONLY, "pthread_setname_np");
if (fd == -1) return errno;
ssize_t n = TEMP_FAILURE_RETRY(write(fd, thread_name, thread_name_len));