1 //=-- lsan_interceptors.cpp -----------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file is a part of LeakSanitizer. 10 // Interceptors for standalone LSan. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "interception/interception.h" 15 #include "sanitizer_common/sanitizer_allocator.h" 16 #include "sanitizer_common/sanitizer_allocator_dlsym.h" 17 #include "sanitizer_common/sanitizer_allocator_report.h" 18 #include "sanitizer_common/sanitizer_atomic.h" 19 #include "sanitizer_common/sanitizer_common.h" 20 #include "sanitizer_common/sanitizer_flags.h" 21 #include "sanitizer_common/sanitizer_internal_defs.h" 22 #include "sanitizer_common/sanitizer_linux.h" 23 #include "sanitizer_common/sanitizer_platform_interceptors.h" 24 #include "sanitizer_common/sanitizer_platform_limits_netbsd.h" 25 #include "sanitizer_common/sanitizer_platform_limits_posix.h" 26 #if SANITIZER_POSIX 27 #include "sanitizer_common/sanitizer_posix.h" 28 #endif 29 #include "sanitizer_common/sanitizer_tls_get_addr.h" 30 #include "lsan.h" 31 #include "lsan_allocator.h" 32 #include "lsan_common.h" 33 #include "lsan_thread.h" 34 35 #include <stddef.h> 36 37 using namespace __lsan; 38 39 extern "C" { 40 int pthread_attr_init(void *attr); 41 int pthread_attr_destroy(void *attr); 42 int pthread_attr_getdetachstate(void *attr, int *v); 43 int pthread_key_create(unsigned *key, void (*destructor)(void* v)); 44 int pthread_setspecific(unsigned key, const void *v); 45 } 46 47 struct DlsymAlloc : DlSymAllocator<DlsymAlloc> { 48 static bool UseImpl() { return lsan_init_is_running; } 49 static void OnAllocate(const void *ptr, uptr size) { 50 #if CAN_SANITIZE_LEAKS 51 // Suppress leaks from dlerror(). Previously dlsym hack on global array was 52 // used by leak sanitizer as a root region. 53 __lsan_register_root_region(ptr, size); 54 #endif 55 } 56 static void OnFree(const void *ptr, uptr size) { 57 #if CAN_SANITIZE_LEAKS 58 __lsan_unregister_root_region(ptr, size); 59 #endif 60 } 61 }; 62 63 ///// Malloc/free interceptors. ///// 64 65 namespace std { 66 struct nothrow_t; 67 enum class align_val_t: size_t; 68 } 69 70 #if !SANITIZER_APPLE 71 INTERCEPTOR(void*, malloc, uptr size) { 72 if (DlsymAlloc::Use()) 73 return DlsymAlloc::Allocate(size); 74 ENSURE_LSAN_INITED; 75 GET_STACK_TRACE_MALLOC; 76 return lsan_malloc(size, stack); 77 } 78 79 INTERCEPTOR(void, free, void *p) { 80 if (DlsymAlloc::PointerIsMine(p)) 81 return DlsymAlloc::Free(p); 82 ENSURE_LSAN_INITED; 83 lsan_free(p); 84 } 85 86 INTERCEPTOR(void*, calloc, uptr nmemb, uptr size) { 87 if (DlsymAlloc::Use()) 88 return DlsymAlloc::Callocate(nmemb, size); 89 ENSURE_LSAN_INITED; 90 GET_STACK_TRACE_MALLOC; 91 return lsan_calloc(nmemb, size, stack); 92 } 93 94 INTERCEPTOR(void *, realloc, void *ptr, uptr size) { 95 if (DlsymAlloc::Use() || DlsymAlloc::PointerIsMine(ptr)) 96 return DlsymAlloc::Realloc(ptr, size); 97 ENSURE_LSAN_INITED; 98 GET_STACK_TRACE_MALLOC; 99 return lsan_realloc(ptr, size, stack); 100 } 101 102 INTERCEPTOR(void*, reallocarray, void *q, uptr nmemb, uptr size) { 103 ENSURE_LSAN_INITED; 104 GET_STACK_TRACE_MALLOC; 105 return lsan_reallocarray(q, nmemb, size, stack); 106 } 107 108 INTERCEPTOR(int, posix_memalign, void **memptr, uptr alignment, uptr size) { 109 ENSURE_LSAN_INITED; 110 GET_STACK_TRACE_MALLOC; 111 return lsan_posix_memalign(memptr, alignment, size, stack); 112 } 113 114 INTERCEPTOR(void*, valloc, uptr size) { 115 ENSURE_LSAN_INITED; 116 GET_STACK_TRACE_MALLOC; 117 return lsan_valloc(size, stack); 118 } 119 #endif // !SANITIZER_APPLE 120 121 #if SANITIZER_INTERCEPT_MEMALIGN 122 INTERCEPTOR(void*, memalign, uptr alignment, uptr size) { 123 ENSURE_LSAN_INITED; 124 GET_STACK_TRACE_MALLOC; 125 return lsan_memalign(alignment, size, stack); 126 } 127 #define LSAN_MAYBE_INTERCEPT_MEMALIGN INTERCEPT_FUNCTION(memalign) 128 #else 129 #define LSAN_MAYBE_INTERCEPT_MEMALIGN 130 #endif // SANITIZER_INTERCEPT_MEMALIGN 131 132 #if SANITIZER_INTERCEPT___LIBC_MEMALIGN 133 INTERCEPTOR(void *, __libc_memalign, uptr alignment, uptr size) { 134 ENSURE_LSAN_INITED; 135 GET_STACK_TRACE_MALLOC; 136 void *res = lsan_memalign(alignment, size, stack); 137 DTLS_on_libc_memalign(res, size); 138 return res; 139 } 140 #define LSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN INTERCEPT_FUNCTION(__libc_memalign) 141 #else 142 #define LSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN 143 #endif // SANITIZER_INTERCEPT___LIBC_MEMALIGN 144 145 #if SANITIZER_INTERCEPT_ALIGNED_ALLOC 146 INTERCEPTOR(void*, aligned_alloc, uptr alignment, uptr size) { 147 ENSURE_LSAN_INITED; 148 GET_STACK_TRACE_MALLOC; 149 return lsan_aligned_alloc(alignment, size, stack); 150 } 151 #define LSAN_MAYBE_INTERCEPT_ALIGNED_ALLOC INTERCEPT_FUNCTION(aligned_alloc) 152 #else 153 #define LSAN_MAYBE_INTERCEPT_ALIGNED_ALLOC 154 #endif 155 156 #if SANITIZER_INTERCEPT_MALLOC_USABLE_SIZE 157 INTERCEPTOR(uptr, malloc_usable_size, void *ptr) { 158 ENSURE_LSAN_INITED; 159 return GetMallocUsableSize(ptr); 160 } 161 #define LSAN_MAYBE_INTERCEPT_MALLOC_USABLE_SIZE \ 162 INTERCEPT_FUNCTION(malloc_usable_size) 163 #else 164 #define LSAN_MAYBE_INTERCEPT_MALLOC_USABLE_SIZE 165 #endif 166 167 #if SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO 168 struct fake_mallinfo { 169 int x[10]; 170 }; 171 172 INTERCEPTOR(struct fake_mallinfo, mallinfo, void) { 173 struct fake_mallinfo res; 174 internal_memset(&res, 0, sizeof(res)); 175 return res; 176 } 177 #define LSAN_MAYBE_INTERCEPT_MALLINFO INTERCEPT_FUNCTION(mallinfo) 178 179 INTERCEPTOR(int, mallopt, int cmd, int value) { 180 return 0; 181 } 182 #define LSAN_MAYBE_INTERCEPT_MALLOPT INTERCEPT_FUNCTION(mallopt) 183 #else 184 #define LSAN_MAYBE_INTERCEPT_MALLINFO 185 #define LSAN_MAYBE_INTERCEPT_MALLOPT 186 #endif // SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO 187 188 #if SANITIZER_INTERCEPT_PVALLOC 189 INTERCEPTOR(void*, pvalloc, uptr size) { 190 ENSURE_LSAN_INITED; 191 GET_STACK_TRACE_MALLOC; 192 return lsan_pvalloc(size, stack); 193 } 194 #define LSAN_MAYBE_INTERCEPT_PVALLOC INTERCEPT_FUNCTION(pvalloc) 195 #else 196 #define LSAN_MAYBE_INTERCEPT_PVALLOC 197 #endif // SANITIZER_INTERCEPT_PVALLOC 198 199 #if SANITIZER_INTERCEPT_CFREE 200 INTERCEPTOR(void, cfree, void *p) ALIAS(WRAPPER_NAME(free)); 201 #define LSAN_MAYBE_INTERCEPT_CFREE INTERCEPT_FUNCTION(cfree) 202 #else 203 #define LSAN_MAYBE_INTERCEPT_CFREE 204 #endif // SANITIZER_INTERCEPT_CFREE 205 206 #if SANITIZER_INTERCEPT_MCHECK_MPROBE 207 INTERCEPTOR(int, mcheck, void (*abortfunc)(int mstatus)) { 208 return 0; 209 } 210 211 INTERCEPTOR(int, mcheck_pedantic, void (*abortfunc)(int mstatus)) { 212 return 0; 213 } 214 215 INTERCEPTOR(int, mprobe, void *ptr) { 216 return 0; 217 } 218 #endif // SANITIZER_INTERCEPT_MCHECK_MPROBE 219 220 221 // TODO(alekseys): throw std::bad_alloc instead of dying on OOM. 222 #define OPERATOR_NEW_BODY(nothrow)\ 223 ENSURE_LSAN_INITED;\ 224 GET_STACK_TRACE_MALLOC;\ 225 void *res = lsan_malloc(size, stack);\ 226 if (!nothrow && UNLIKELY(!res)) ReportOutOfMemory(size, &stack);\ 227 return res; 228 #define OPERATOR_NEW_BODY_ALIGN(nothrow)\ 229 ENSURE_LSAN_INITED;\ 230 GET_STACK_TRACE_MALLOC;\ 231 void *res = lsan_memalign((uptr)align, size, stack);\ 232 if (!nothrow && UNLIKELY(!res)) ReportOutOfMemory(size, &stack);\ 233 return res; 234 235 #define OPERATOR_DELETE_BODY\ 236 ENSURE_LSAN_INITED;\ 237 lsan_free(ptr); 238 239 // On OS X it's not enough to just provide our own 'operator new' and 240 // 'operator delete' implementations, because they're going to be in the runtime 241 // dylib, and the main executable will depend on both the runtime dylib and 242 // libstdc++, each of has its implementation of new and delete. 243 // To make sure that C++ allocation/deallocation operators are overridden on 244 // OS X we need to intercept them using their mangled names. 245 #if !SANITIZER_APPLE 246 247 INTERCEPTOR_ATTRIBUTE 248 void *operator new(size_t size) { OPERATOR_NEW_BODY(false /*nothrow*/); } 249 INTERCEPTOR_ATTRIBUTE 250 void *operator new[](size_t size) { OPERATOR_NEW_BODY(false /*nothrow*/); } 251 INTERCEPTOR_ATTRIBUTE 252 void *operator new(size_t size, std::nothrow_t const&) 253 { OPERATOR_NEW_BODY(true /*nothrow*/); } 254 INTERCEPTOR_ATTRIBUTE 255 void *operator new[](size_t size, std::nothrow_t const&) 256 { OPERATOR_NEW_BODY(true /*nothrow*/); } 257 INTERCEPTOR_ATTRIBUTE 258 void *operator new(size_t size, std::align_val_t align) 259 { OPERATOR_NEW_BODY_ALIGN(false /*nothrow*/); } 260 INTERCEPTOR_ATTRIBUTE 261 void *operator new[](size_t size, std::align_val_t align) 262 { OPERATOR_NEW_BODY_ALIGN(false /*nothrow*/); } 263 INTERCEPTOR_ATTRIBUTE 264 void *operator new(size_t size, std::align_val_t align, std::nothrow_t const&) 265 { OPERATOR_NEW_BODY_ALIGN(true /*nothrow*/); } 266 INTERCEPTOR_ATTRIBUTE 267 void *operator new[](size_t size, std::align_val_t align, std::nothrow_t const&) 268 { OPERATOR_NEW_BODY_ALIGN(true /*nothrow*/); } 269 270 INTERCEPTOR_ATTRIBUTE 271 void operator delete(void *ptr) NOEXCEPT { OPERATOR_DELETE_BODY; } 272 INTERCEPTOR_ATTRIBUTE 273 void operator delete[](void *ptr) NOEXCEPT { OPERATOR_DELETE_BODY; } 274 INTERCEPTOR_ATTRIBUTE 275 void operator delete(void *ptr, std::nothrow_t const&) { OPERATOR_DELETE_BODY; } 276 INTERCEPTOR_ATTRIBUTE 277 void operator delete[](void *ptr, std::nothrow_t const &) 278 { OPERATOR_DELETE_BODY; } 279 INTERCEPTOR_ATTRIBUTE 280 void operator delete(void *ptr, size_t size) NOEXCEPT 281 { OPERATOR_DELETE_BODY; } 282 INTERCEPTOR_ATTRIBUTE 283 void operator delete[](void *ptr, size_t size) NOEXCEPT 284 { OPERATOR_DELETE_BODY; } 285 INTERCEPTOR_ATTRIBUTE 286 void operator delete(void *ptr, std::align_val_t) NOEXCEPT 287 { OPERATOR_DELETE_BODY; } 288 INTERCEPTOR_ATTRIBUTE 289 void operator delete[](void *ptr, std::align_val_t) NOEXCEPT 290 { OPERATOR_DELETE_BODY; } 291 INTERCEPTOR_ATTRIBUTE 292 void operator delete(void *ptr, std::align_val_t, std::nothrow_t const&) 293 { OPERATOR_DELETE_BODY; } 294 INTERCEPTOR_ATTRIBUTE 295 void operator delete[](void *ptr, std::align_val_t, std::nothrow_t const&) 296 { OPERATOR_DELETE_BODY; } 297 INTERCEPTOR_ATTRIBUTE 298 void operator delete(void *ptr, size_t size, std::align_val_t) NOEXCEPT 299 { OPERATOR_DELETE_BODY; } 300 INTERCEPTOR_ATTRIBUTE 301 void operator delete[](void *ptr, size_t size, std::align_val_t) NOEXCEPT 302 { OPERATOR_DELETE_BODY; } 303 304 #else // SANITIZER_APPLE 305 306 INTERCEPTOR(void *, _Znwm, size_t size) 307 { OPERATOR_NEW_BODY(false /*nothrow*/); } 308 INTERCEPTOR(void *, _Znam, size_t size) 309 { OPERATOR_NEW_BODY(false /*nothrow*/); } 310 INTERCEPTOR(void *, _ZnwmRKSt9nothrow_t, size_t size, std::nothrow_t const&) 311 { OPERATOR_NEW_BODY(true /*nothrow*/); } 312 INTERCEPTOR(void *, _ZnamRKSt9nothrow_t, size_t size, std::nothrow_t const&) 313 { OPERATOR_NEW_BODY(true /*nothrow*/); } 314 315 INTERCEPTOR(void, _ZdlPv, void *ptr) 316 { OPERATOR_DELETE_BODY; } 317 INTERCEPTOR(void, _ZdaPv, void *ptr) 318 { OPERATOR_DELETE_BODY; } 319 INTERCEPTOR(void, _ZdlPvRKSt9nothrow_t, void *ptr, std::nothrow_t const&) 320 { OPERATOR_DELETE_BODY; } 321 INTERCEPTOR(void, _ZdaPvRKSt9nothrow_t, void *ptr, std::nothrow_t const&) 322 { OPERATOR_DELETE_BODY; } 323 324 #endif // !SANITIZER_APPLE 325 326 327 ///// Thread initialization and finalization. ///// 328 329 #if !SANITIZER_NETBSD && !SANITIZER_FREEBSD && !SANITIZER_FUCHSIA 330 static unsigned g_thread_finalize_key; 331 332 static void thread_finalize(void *v) { 333 uptr iter = (uptr)v; 334 if (iter > 1) { 335 if (pthread_setspecific(g_thread_finalize_key, (void*)(iter - 1))) { 336 Report("LeakSanitizer: failed to set thread key.\n"); 337 Die(); 338 } 339 return; 340 } 341 ThreadFinish(); 342 } 343 #endif 344 345 #if SANITIZER_NETBSD 346 INTERCEPTOR(void, _lwp_exit) { 347 ENSURE_LSAN_INITED; 348 ThreadFinish(); 349 REAL(_lwp_exit)(); 350 } 351 #define LSAN_MAYBE_INTERCEPT__LWP_EXIT INTERCEPT_FUNCTION(_lwp_exit) 352 #else 353 #define LSAN_MAYBE_INTERCEPT__LWP_EXIT 354 #endif 355 356 #if SANITIZER_INTERCEPT_THR_EXIT 357 INTERCEPTOR(void, thr_exit, tid_t *state) { 358 ENSURE_LSAN_INITED; 359 ThreadFinish(); 360 REAL(thr_exit)(state); 361 } 362 #define LSAN_MAYBE_INTERCEPT_THR_EXIT INTERCEPT_FUNCTION(thr_exit) 363 #else 364 #define LSAN_MAYBE_INTERCEPT_THR_EXIT 365 #endif 366 367 #if SANITIZER_INTERCEPT___CXA_ATEXIT 368 INTERCEPTOR(int, __cxa_atexit, void (*func)(void *), void *arg, 369 void *dso_handle) { 370 __lsan::ScopedInterceptorDisabler disabler; 371 return REAL(__cxa_atexit)(func, arg, dso_handle); 372 } 373 #define LSAN_MAYBE_INTERCEPT___CXA_ATEXIT INTERCEPT_FUNCTION(__cxa_atexit) 374 #else 375 #define LSAN_MAYBE_INTERCEPT___CXA_ATEXIT 376 #endif 377 378 #if SANITIZER_INTERCEPT_ATEXIT 379 INTERCEPTOR(int, atexit, void (*f)()) { 380 __lsan::ScopedInterceptorDisabler disabler; 381 return REAL(__cxa_atexit)((void (*)(void *a))f, 0, 0); 382 } 383 #define LSAN_MAYBE_INTERCEPT_ATEXIT INTERCEPT_FUNCTION(atexit) 384 #else 385 #define LSAN_MAYBE_INTERCEPT_ATEXIT 386 #endif 387 388 #if SANITIZER_INTERCEPT_PTHREAD_ATFORK 389 extern "C" { 390 extern int _pthread_atfork(void (*prepare)(), void (*parent)(), 391 void (*child)()); 392 }; 393 394 INTERCEPTOR(int, pthread_atfork, void (*prepare)(), void (*parent)(), 395 void (*child)()) { 396 __lsan::ScopedInterceptorDisabler disabler; 397 // REAL(pthread_atfork) cannot be called due to symbol indirections at least 398 // on NetBSD 399 return _pthread_atfork(prepare, parent, child); 400 } 401 #define LSAN_MAYBE_INTERCEPT_PTHREAD_ATFORK INTERCEPT_FUNCTION(pthread_atfork) 402 #else 403 #define LSAN_MAYBE_INTERCEPT_PTHREAD_ATFORK 404 #endif 405 406 #if SANITIZER_INTERCEPT_STRERROR 407 INTERCEPTOR(char *, strerror, int errnum) { 408 __lsan::ScopedInterceptorDisabler disabler; 409 return REAL(strerror)(errnum); 410 } 411 #define LSAN_MAYBE_INTERCEPT_STRERROR INTERCEPT_FUNCTION(strerror) 412 #else 413 #define LSAN_MAYBE_INTERCEPT_STRERROR 414 #endif 415 416 #if SANITIZER_POSIX 417 418 struct ThreadParam { 419 void *(*callback)(void *arg); 420 void *param; 421 atomic_uintptr_t tid; 422 }; 423 424 extern "C" void *__lsan_thread_start_func(void *arg) { 425 ThreadParam *p = (ThreadParam*)arg; 426 void* (*callback)(void *arg) = p->callback; 427 void *param = p->param; 428 // Wait until the last iteration to maximize the chance that we are the last 429 // destructor to run. 430 #if !SANITIZER_NETBSD && !SANITIZER_FREEBSD 431 if (pthread_setspecific(g_thread_finalize_key, 432 (void*)GetPthreadDestructorIterations())) { 433 Report("LeakSanitizer: failed to set thread key.\n"); 434 Die(); 435 } 436 #endif 437 int tid = 0; 438 while ((tid = atomic_load(&p->tid, memory_order_acquire)) == 0) 439 internal_sched_yield(); 440 ThreadStart(tid, GetTid()); 441 atomic_store(&p->tid, 0, memory_order_release); 442 return callback(param); 443 } 444 445 INTERCEPTOR(int, pthread_create, void *th, void *attr, 446 void *(*callback)(void *), void *param) { 447 ENSURE_LSAN_INITED; 448 EnsureMainThreadIDIsCorrect(); 449 __sanitizer_pthread_attr_t myattr; 450 if (!attr) { 451 pthread_attr_init(&myattr); 452 attr = &myattr; 453 } 454 AdjustStackSize(attr); 455 int detached = 0; 456 pthread_attr_getdetachstate(attr, &detached); 457 ThreadParam p; 458 p.callback = callback; 459 p.param = param; 460 atomic_store(&p.tid, 0, memory_order_relaxed); 461 int res; 462 { 463 // Ignore all allocations made by pthread_create: thread stack/TLS may be 464 // stored by pthread for future reuse even after thread destruction, and 465 // the linked list it's stored in doesn't even hold valid pointers to the 466 // objects, the latter are calculated by obscure pointer arithmetic. 467 ScopedInterceptorDisabler disabler; 468 res = REAL(pthread_create)(th, attr, __lsan_thread_start_func, &p); 469 } 470 if (res == 0) { 471 int tid = ThreadCreate(GetCurrentThread(), IsStateDetached(detached)); 472 CHECK_NE(tid, kMainTid); 473 atomic_store(&p.tid, tid, memory_order_release); 474 while (atomic_load(&p.tid, memory_order_acquire) != 0) 475 internal_sched_yield(); 476 } 477 if (attr == &myattr) 478 pthread_attr_destroy(&myattr); 479 return res; 480 } 481 482 INTERCEPTOR(int, pthread_join, void *t, void **arg) { 483 return REAL(pthread_join)(t, arg); 484 } 485 486 DEFINE_REAL_PTHREAD_FUNCTIONS 487 488 INTERCEPTOR(void, _exit, int status) { 489 if (status == 0 && HasReportedLeaks()) status = common_flags()->exitcode; 490 REAL(_exit)(status); 491 } 492 493 #define COMMON_INTERCEPT_FUNCTION(name) INTERCEPT_FUNCTION(name) 494 #include "sanitizer_common/sanitizer_signal_interceptors.inc" 495 496 #endif // SANITIZER_POSIX 497 498 namespace __lsan { 499 500 void InitializeInterceptors() { 501 // Fuchsia doesn't use interceptors that require any setup. 502 #if !SANITIZER_FUCHSIA 503 InitializeSignalInterceptors(); 504 505 INTERCEPT_FUNCTION(malloc); 506 INTERCEPT_FUNCTION(free); 507 LSAN_MAYBE_INTERCEPT_CFREE; 508 INTERCEPT_FUNCTION(calloc); 509 INTERCEPT_FUNCTION(realloc); 510 LSAN_MAYBE_INTERCEPT_MEMALIGN; 511 LSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN; 512 LSAN_MAYBE_INTERCEPT_ALIGNED_ALLOC; 513 INTERCEPT_FUNCTION(posix_memalign); 514 INTERCEPT_FUNCTION(valloc); 515 LSAN_MAYBE_INTERCEPT_PVALLOC; 516 LSAN_MAYBE_INTERCEPT_MALLOC_USABLE_SIZE; 517 LSAN_MAYBE_INTERCEPT_MALLINFO; 518 LSAN_MAYBE_INTERCEPT_MALLOPT; 519 INTERCEPT_FUNCTION(pthread_create); 520 INTERCEPT_FUNCTION(pthread_join); 521 INTERCEPT_FUNCTION(_exit); 522 523 LSAN_MAYBE_INTERCEPT__LWP_EXIT; 524 LSAN_MAYBE_INTERCEPT_THR_EXIT; 525 526 LSAN_MAYBE_INTERCEPT___CXA_ATEXIT; 527 LSAN_MAYBE_INTERCEPT_ATEXIT; 528 LSAN_MAYBE_INTERCEPT_PTHREAD_ATFORK; 529 530 LSAN_MAYBE_INTERCEPT_STRERROR; 531 532 #if !SANITIZER_NETBSD && !SANITIZER_FREEBSD 533 if (pthread_key_create(&g_thread_finalize_key, &thread_finalize)) { 534 Report("LeakSanitizer: failed to create thread key.\n"); 535 Die(); 536 } 537 #endif 538 539 #endif // !SANITIZER_FUCHSIA 540 } 541 542 } // namespace __lsan 543