Index: lib/lsan/lsan_interceptors.cc =================================================================== --- lib/lsan/lsan_interceptors.cc +++ lib/lsan/lsan_interceptors.cc @@ -19,6 +19,7 @@ #include "sanitizer_common/sanitizer_flags.h" #include "sanitizer_common/sanitizer_internal_defs.h" #include "sanitizer_common/sanitizer_linux.h" +#include "sanitizer_common/sanitizer_mac.h" #include "sanitizer_common/sanitizer_platform_interceptors.h" #include "sanitizer_common/sanitizer_platform_limits_posix.h" #include "sanitizer_common/sanitizer_tls_get_addr.h" @@ -265,7 +266,7 @@ attr = &myattr; } AdjustStackSize(attr); - int detached = 0; + int detached = kCreateJoinable; pthread_attr_getdetachstate(attr, &detached); ThreadParam p; p.callback = callback; @@ -281,7 +282,8 @@ res = REAL(pthread_create)(th, attr, __lsan_thread_start_func, &p); } if (res == 0) { - int tid = ThreadCreate(GetCurrentThread(), *(uptr *)th, detached); + int tid = ThreadCreate(GetCurrentThread(), *(uptr *)th, + detached == kCreateDetached); CHECK_NE(tid, 0); atomic_store(&p.tid, tid, memory_order_release); while (atomic_load(&p.tid, memory_order_acquire) != 0) Index: lib/sanitizer_common/sanitizer_linux.h =================================================================== --- lib/sanitizer_common/sanitizer_linux.h +++ lib/sanitizer_common/sanitizer_linux.h @@ -55,6 +55,9 @@ #endif #endif // SANITIZER_LINUX +static const int kCreateJoinable = 0; +static const int kCreateDetached = 1; + // This class reads thread IDs from /proc//task using only syscalls. class ThreadLister { public: Index: lib/sanitizer_common/sanitizer_mac.h =================================================================== --- lib/sanitizer_common/sanitizer_mac.h +++ lib/sanitizer_common/sanitizer_mac.h @@ -38,6 +38,9 @@ } // namespace __sanitizer +static const int kCreateJoinable = 1; +static const int kCreateDetached = 2; + extern "C" { static char __crashreporter_info_buff__[__sanitizer::kErrorMessageBufferSize] = {}; Index: lib/tsan/rtl/tsan_interceptors.cc =================================================================== --- lib/tsan/rtl/tsan_interceptors.cc +++ lib/tsan/rtl/tsan_interceptors.cc @@ -16,6 +16,7 @@ #include "sanitizer_common/sanitizer_atomic.h" #include "sanitizer_common/sanitizer_libc.h" #include "sanitizer_common/sanitizer_linux.h" +#include "sanitizer_common/sanitizer_mac.h" #include "sanitizer_common/sanitizer_platform_limits_posix.h" #include "sanitizer_common/sanitizer_placement_new.h" #include "sanitizer_common/sanitizer_stacktrace.h" @@ -46,13 +47,6 @@ #define mallopt(a, b) #endif -#if SANITIZER_LINUX || SANITIZER_FREEBSD -#define PTHREAD_CREATE_DETACHED 1 -#elif SANITIZER_MAC -#define PTHREAD_CREATE_DETACHED 2 -#endif - - #ifdef __mips__ const int kSigCount = 129; #else @@ -911,7 +905,7 @@ pthread_attr_init(&myattr); attr = &myattr; } - int detached = 0; + int detached = kCreateJoinable; REAL(pthread_attr_getdetachstate)(attr, &detached); AdjustStackSize(attr); @@ -929,7 +923,7 @@ } if (res == 0) { int tid = ThreadCreate(thr, pc, *(uptr*)th, - detached == PTHREAD_CREATE_DETACHED); + detached == kCreateDetached); CHECK_NE(tid, 0); // Synchronization on p.tid serves two purposes: // 1. ThreadCreate must finish before the new thread starts.