@@ -480,8 +480,12 @@ static int setup_at_exit_wrapper(ThreadState *thr, uptr pc, void(*f)(),
480480 // due to atexit_mu held on exit from the calloc interceptor.
481481 ScopedIgnoreInterceptors ignore;
482482
483+ #if !SANITIZER_NETBSD
483484 res = REAL (__cxa_atexit)((void (*)(void *a))at_exit_callback_installed_at,
484485 0 , 0 );
486+ #else
487+ res = REAL (atexit)((void (*)())at_exit_callback_installed_at);
488+ #endif
485489 // Push AtExitCtx on the top of the stack of callback functions
486490 if (!res) {
487491 interceptor_ctx ()->AtExitStack .PushBack (ctx);
@@ -2828,7 +2832,7 @@ static void finalize(void *arg) {
28282832 Die ();
28292833}
28302834
2831- #if !SANITIZER_APPLE && !SANITIZER_ANDROID
2835+ #if !SANITIZER_APPLE && !SANITIZER_ANDROID && !SANITIZER_NETBSD
28322836static void unreachable () {
28332837 Report (" FATAL: ThreadSanitizer: unreachable called\n " );
28342838 Die ();
@@ -2990,6 +2994,9 @@ void InitializeInterceptors() {
29902994 TSAN_MAYBE_INTERCEPT_ON_EXIT;
29912995 TSAN_INTERCEPT (__cxa_atexit);
29922996 TSAN_INTERCEPT (_exit);
2997+ #ifdef SANITIZER_NETBSD
2998+ TSAN_INTERCEPT (atexit);
2999+ #endif
29933000
29943001#ifdef NEED_TLS_GET_ADDR
29953002#if !SANITIZER_S390
@@ -3003,13 +3010,18 @@ void InitializeInterceptors() {
30033010 TSAN_MAYBE_INTERCEPT__LWP_EXIT;
30043011 TSAN_MAYBE_INTERCEPT_THR_EXIT;
30053012
3006- #if !SANITIZER_APPLE && !SANITIZER_ANDROID
3013+ #if !SANITIZER_APPLE && !SANITIZER_ANDROID && !SANITIZER_NETBSD
30073014 // Need to setup it, because interceptors check that the function is resolved.
30083015 // But atexit is emitted directly into the module, so can't be resolved.
30093016 REAL (atexit) = (int (*)(void (*)()))unreachable;
30103017#endif
30113018
3012- if (REAL (__cxa_atexit)(&finalize, 0 , 0 )) {
3019+ #if !SANITIZER_NETBSD
3020+ if (REAL (__cxa_atexit)(&finalize, 0 , 0 ))
3021+ #else
3022+ if (REAL (atexit)((void (*)())&finalize))
3023+ #endif
3024+ {
30133025 Printf (" ThreadSanitizer: failed to setup atexit callback\n " );
30143026 Die ();
30153027 }
0 commit comments