Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
22 changes: 22 additions & 0 deletions compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down