Skip to content

Commit

Permalink
[ASAN][LSAN] Ignore main or uninitialized thead in pthread_exit
Browse files Browse the repository at this point in the history
Fix crash on CHECK in ThreadArgRetval::Finish().
  • Loading branch information
vitalybuka committed May 12, 2023
1 parent 3826a74 commit 2394f09
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion compiler-rt/lib/asan/asan_interceptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "asan_suppressions.h"
#include "asan_thread.h"
#include "lsan/lsan_common.h"
#include "sanitizer_common/sanitizer_internal_defs.h"
#include "sanitizer_common/sanitizer_libc.h"

// There is no general interception at all on Fuchsia.
Expand Down Expand Up @@ -263,7 +264,9 @@ INTERCEPTOR(int, pthread_detach, void *thread) {
}

INTERCEPTOR(int, pthread_exit, void *retval) {
asanThreadArgRetval().Finish(GetThreadSelf(), retval);
AsanThread *t = GetCurrentThread();
if (t && t->tid() != kMainTid)
asanThreadArgRetval().Finish(GetThreadSelf(), retval);
return REAL(pthread_exit)(retval);
}

Expand Down
4 changes: 3 additions & 1 deletion compiler-rt/lib/lsan/lsan_interceptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,9 @@ INTERCEPTOR(int, pthread_detach, void *thread) {
}

INTERCEPTOR(int, pthread_exit, void *retval) {
GetThreadArgRetval().Finish(GetThreadSelf(), retval);
ThreadContextLsanBase *t = GetCurrentThread();
if (t && t->tid != kMainTid)
GetThreadArgRetval().Finish(GetThreadSelf(), retval);
return REAL(pthread_exit)(retval);
}

Expand Down

0 comments on commit 2394f09

Please sign in to comment.