-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[compiler-rt][rtsan] pthread_detach/pthread_kill interception. #126765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@llvm/pr-subscribers-compiler-rt-sanitizer Author: David CARLIER (devnexen) ChangesFull diff: https://github.com/llvm/llvm-project/pull/126765.diff 2 Files Affected:
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 {
|
|
@devnexen thanks for the suggestion - how confident are you that both |
|
Ah I did not look at linux/glibc, maybe we should add it only for freebsd later down the line. |
Sorry - please could you clarify what you're proposing here? Do you mean introduce it for FreeBSD now and Linux later, or Linux now and FreeBSD later? |
|
I would say not Linux but FreeBSD later. |
|
@devnexen OK - are you happy if we close this PR for now? |
|
Sure I mean either that or rebasing later whatever you all prefer. |
No description provided.