Skip to content

Commit 528c47b

Browse files
committed
[compiler-rt][TSan] fix crash caused by intercpting pthread_detach on Android
1 parent e2f8bfc commit 528c47b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,20 @@ TSAN_INTERCEPTOR(int, pthread_create,
11301130

11311131
TSAN_INTERCEPTOR(int, pthread_join, void *th, void **ret) {
11321132
SCOPED_INTERCEPTOR_RAW(pthread_join, th, ret);
1133+
#if SANITIZER_ANDROID
1134+
{
1135+
// In Bionic, pthread_detach calls pthread_join, so the thread has already
1136+
// been consumed by the pthread_detach interceptor.
1137+
Tid tid = ctx->thread_registry.FindThread(
1138+
[](ThreadContextBase* tctx, void* arg) {
1139+
return tctx->user_id == (uptr)arg;
1140+
},
1141+
th);
1142+
if (tid == kInvalidTid) {
1143+
return REAL(pthread_join)(th, ret);
1144+
}
1145+
}
1146+
#endif
11331147
Tid tid = ThreadConsumeTid(thr, pc, (uptr)th);
11341148
ThreadIgnoreBegin(thr, pc);
11351149
int res = BLOCK_REAL(pthread_join)(th, ret);

0 commit comments

Comments
 (0)