diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp index 410da0748b433..af074d119e86a 100644 --- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp +++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp @@ -749,6 +749,16 @@ INTERCEPTOR(int, pthread_rwlock_wrlock, pthread_rwlock_t *lock) { return REAL(pthread_rwlock_wrlock)(lock); } +INTERCEPTOR(int, pthread_detach, pthread_t thread) { + __rtsan_notify_intercepted_call("pthread_detach"); + return REAL(pthread_detach)(thread); +} + +INTERCEPTOR(int, pthread_kill, pthread_t thread, int signal) { + __rtsan_notify_intercepted_call("pthread_kill"); + return REAL(pthread_kill)(thread, signal); +} + // Sleeping INTERCEPTOR(unsigned int, sleep, unsigned int s) { @@ -1498,6 +1508,8 @@ void __rtsan::InitializeInterceptors() { INTERCEPT_FUNCTION(pthread_rwlock_rdlock); INTERCEPT_FUNCTION(pthread_rwlock_unlock); INTERCEPT_FUNCTION(pthread_rwlock_wrlock); + INTERCEPT_FUNCTION(pthread_detach); + INTERCEPT_FUNCTION(pthread_kill); INTERCEPT_FUNCTION(sleep); INTERCEPT_FUNCTION(usleep); diff --git a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp index 98d27caae94b8..994aeff6a1c8c 100644 --- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp +++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp @@ -1148,6 +1148,28 @@ TEST(TestRtsanInterceptors, PthreadCondWaitDiesWhenRealtime) { pthread_mutex_destroy(&mutex); } +TEST(TestRtsanInterceptors, PthreadDetachDiesWhenRealtime) { + pthread_t thread{}; + ASSERT_EQ(0, + pthread_create(&thread, nullptr, &FakeThreadEntryPoint, nullptr)); + + auto Func = [&thread]() { pthread_detach(thread); }; + + ExpectRealtimeDeath(Func, "pthread_detach"); + ExpectNonRealtimeSurvival(Func); +} + +TEST(TestRtsanInterceptors, PthreadKillDiesWhenRealtime) { + pthread_t thread{}; + ASSERT_EQ(0, + pthread_create(&thread, nullptr, &FakeThreadEntryPoint, nullptr)); + + auto Func = [&thread]() { pthread_kill(thread, -1); }; + + ExpectRealtimeDeath(Func, "pthread_kill"); + ExpectNonRealtimeSurvival(Func); +} + class PthreadRwlockTest : public ::testing::Test { protected: void SetUp() override {