Index: lib/asan/asan_posix.cc =================================================================== --- lib/asan/asan_posix.cc +++ lib/asan/asan_posix.cc @@ -40,29 +40,50 @@ // ---------------------- TSD ---------------- {{{1 +#if SANITIZER_FREEBSD +static __thread void *_tsd_data; +#else static pthread_key_t tsd_key; static bool tsd_key_inited = false; +#endif void AsanTSDInit(void (*destructor)(void *tsd)) { +#if SANITIZER_FREEBSD + DCHECK(destructor == &PlatformTSDDtor); + _tsd_data = nullptr; +#else CHECK(!tsd_key_inited); tsd_key_inited = true; CHECK_EQ(0, pthread_key_create(&tsd_key, destructor)); +#endif } void *AsanTSDGet() { +#if SANITIZER_FREEBSD + return _tsd_data; +#else CHECK(tsd_key_inited); return pthread_getspecific(tsd_key); +#endif } void AsanTSDSet(void *tsd) { +#if SANITIZER_FREEBSD + _tsd_data = tsd; +#else CHECK(tsd_key_inited); pthread_setspecific(tsd_key, tsd); +#endif } void PlatformTSDDtor(void *tsd) { AsanThreadContext *context = (AsanThreadContext*)tsd; if (context->destructor_iterations > 1) { context->destructor_iterations--; +#if SANITIZER_FREEBSD + _tsd_data = tsd; +#else CHECK_EQ(0, pthread_setspecific(tsd_key, tsd)); +#endif return; } AsanThread::TSDDtor(tsd);