Skip to content

Commit d254526

Browse files
authored
Revert "[rtsan] Support legacy pthread_cond variables (#152947)" (#155963)
This reverts commit aa4bc2e. As discussed on #155181 , this introduced some unneeded code. Reverting and applying the smaller version of the fix
1 parent 43c85af commit d254526

File tree

2 files changed

+4
-87
lines changed

2 files changed

+4
-87
lines changed

compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp

Lines changed: 4 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include "interception/interception.h"
1717
#include "sanitizer_common/sanitizer_allocator_dlsym.h"
18-
#include "sanitizer_common/sanitizer_glibc_version.h"
1918
#include "sanitizer_common/sanitizer_platform_interceptors.h"
2019

2120
#include "interception/interception.h"
@@ -47,41 +46,12 @@
4746

4847
using namespace __sanitizer;
4948

50-
DECLARE_REAL_AND_INTERCEPTOR(void *, malloc, usize size)
51-
DECLARE_REAL_AND_INTERCEPTOR(void, free, void *ptr)
52-
5349
namespace {
5450
struct DlsymAlloc : public DlSymAllocator<DlsymAlloc> {
5551
static bool UseImpl() { return !__rtsan_is_initialized(); }
5652
};
5753
} // namespace
5854

59-
// See note in tsan as to why this is necessary
60-
static pthread_cond_t *init_cond(pthread_cond_t *c, bool force = false) {
61-
if (!common_flags()->legacy_pthread_cond)
62-
return c;
63-
64-
atomic_uintptr_t *p = (atomic_uintptr_t *)c;
65-
uptr cond = atomic_load(p, memory_order_acquire);
66-
if (!force && cond != 0)
67-
return (pthread_cond_t *)cond;
68-
void *newcond = WRAP(malloc)(sizeof(pthread_cond_t));
69-
internal_memset(newcond, 0, sizeof(pthread_cond_t));
70-
if (atomic_compare_exchange_strong(p, &cond, (uptr)newcond,
71-
memory_order_acq_rel))
72-
return (pthread_cond_t *)newcond;
73-
WRAP(free)(newcond);
74-
return (pthread_cond_t *)cond;
75-
}
76-
77-
static void destroy_cond(pthread_cond_t *cond) {
78-
if (common_flags()->legacy_pthread_cond) {
79-
// Free our aux cond and zero the pointer to not leave dangling pointers.
80-
WRAP(free)(cond);
81-
atomic_store((atomic_uintptr_t *)cond, 0, memory_order_relaxed);
82-
}
83-
}
84-
8555
// Filesystem
8656

8757
INTERCEPTOR(int, open, const char *path, int oflag, ...) {
@@ -796,45 +766,26 @@ INTERCEPTOR(int, pthread_join, pthread_t thread, void **value_ptr) {
796766
return REAL(pthread_join)(thread, value_ptr);
797767
}
798768

799-
INTERCEPTOR(int, pthread_cond_init, pthread_cond_t *cond,
800-
const pthread_condattr_t *a) {
801-
__rtsan_notify_intercepted_call("pthread_cond_init");
802-
pthread_cond_t *c = init_cond(cond, true);
803-
return REAL(pthread_cond_init)(c, a);
804-
}
805-
806769
INTERCEPTOR(int, pthread_cond_signal, pthread_cond_t *cond) {
807770
__rtsan_notify_intercepted_call("pthread_cond_signal");
808-
pthread_cond_t *c = init_cond(cond);
809-
return REAL(pthread_cond_signal)(c);
771+
return REAL(pthread_cond_signal)(cond);
810772
}
811773

812774
INTERCEPTOR(int, pthread_cond_broadcast, pthread_cond_t *cond) {
813775
__rtsan_notify_intercepted_call("pthread_cond_broadcast");
814-
pthread_cond_t *c = init_cond(cond);
815-
return REAL(pthread_cond_broadcast)(c);
776+
return REAL(pthread_cond_broadcast)(cond);
816777
}
817778

818779
INTERCEPTOR(int, pthread_cond_wait, pthread_cond_t *cond,
819780
pthread_mutex_t *mutex) {
820781
__rtsan_notify_intercepted_call("pthread_cond_wait");
821-
pthread_cond_t *c = init_cond(cond);
822-
return REAL(pthread_cond_wait)(c, mutex);
782+
return REAL(pthread_cond_wait)(cond, mutex);
823783
}
824784

825785
INTERCEPTOR(int, pthread_cond_timedwait, pthread_cond_t *cond,
826786
pthread_mutex_t *mutex, const timespec *ts) {
827787
__rtsan_notify_intercepted_call("pthread_cond_timedwait");
828-
pthread_cond_t *c = init_cond(cond);
829-
return REAL(pthread_cond_timedwait)(c, mutex, ts);
830-
}
831-
832-
INTERCEPTOR(int, pthread_cond_destroy, pthread_cond_t *cond) {
833-
__rtsan_notify_intercepted_call("pthread_cond_destroy");
834-
pthread_cond_t *c = init_cond(cond);
835-
int res = REAL(pthread_cond_destroy)(c);
836-
destroy_cond(c);
837-
return res;
788+
return REAL(pthread_cond_timedwait)(cond, mutex, ts);
838789
}
839790

840791
INTERCEPTOR(int, pthread_rwlock_rdlock, pthread_rwlock_t *lock) {
@@ -1690,26 +1641,10 @@ void __rtsan::InitializeInterceptors() {
16901641
INTERCEPT_FUNCTION(pthread_mutex_lock);
16911642
INTERCEPT_FUNCTION(pthread_mutex_unlock);
16921643
INTERCEPT_FUNCTION(pthread_join);
1693-
1694-
// See the comment in tsan_interceptors_posix.cpp.
1695-
#if SANITIZER_GLIBC && !__GLIBC_PREREQ(2, 36) && \
1696-
(defined(__x86_64__) || defined(__mips__) || SANITIZER_PPC64V1 || \
1697-
defined(__s390x__))
1698-
INTERCEPT_FUNCTION_VER(pthread_cond_init, "GLIBC_2.3.2");
1699-
INTERCEPT_FUNCTION_VER(pthread_cond_signal, "GLIBC_2.3.2");
1700-
INTERCEPT_FUNCTION_VER(pthread_cond_broadcast, "GLIBC_2.3.2");
1701-
INTERCEPT_FUNCTION_VER(pthread_cond_wait, "GLIBC_2.3.2");
1702-
INTERCEPT_FUNCTION_VER(pthread_cond_timedwait, "GLIBC_2.3.2");
1703-
INTERCEPT_FUNCTION_VER(pthread_cond_destroy, "GLIBC_2.3.2");
1704-
#else
1705-
INTERCEPT_FUNCTION(pthread_cond_init);
17061644
INTERCEPT_FUNCTION(pthread_cond_signal);
17071645
INTERCEPT_FUNCTION(pthread_cond_broadcast);
17081646
INTERCEPT_FUNCTION(pthread_cond_wait);
17091647
INTERCEPT_FUNCTION(pthread_cond_timedwait);
1710-
INTERCEPT_FUNCTION(pthread_cond_destroy);
1711-
#endif
1712-
17131648
INTERCEPT_FUNCTION(pthread_rwlock_rdlock);
17141649
INTERCEPT_FUNCTION(pthread_rwlock_unlock);
17151650
INTERCEPT_FUNCTION(pthread_rwlock_wrlock);

compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,24 +1241,6 @@ TEST(TestRtsanInterceptors, SpinLockLockDiesWhenRealtime) {
12411241
}
12421242
#endif
12431243

1244-
TEST(TestRtsanInterceptors, PthreadCondInitDiesWhenRealtime) {
1245-
pthread_cond_t cond{};
1246-
auto Func = [&cond]() { pthread_cond_init(&cond, nullptr); };
1247-
ExpectRealtimeDeath(Func, "pthread_cond_init");
1248-
ExpectNonRealtimeSurvival(Func);
1249-
}
1250-
1251-
TEST(TestRtsanInterceptors, PthreadCondDestroyDiesWhenRealtime) {
1252-
pthread_cond_t cond{};
1253-
ASSERT_EQ(0, pthread_cond_init(&cond, nullptr));
1254-
1255-
auto Func = [&cond]() { pthread_cond_destroy(&cond); };
1256-
ExpectRealtimeDeath(Func, "pthread_cond_destroy");
1257-
ExpectNonRealtimeSurvival(Func);
1258-
1259-
pthread_cond_destroy(&cond);
1260-
}
1261-
12621244
TEST(TestRtsanInterceptors, PthreadCondSignalDiesWhenRealtime) {
12631245
pthread_cond_t cond{};
12641246
ASSERT_EQ(0, pthread_cond_init(&cond, nullptr));

0 commit comments

Comments
 (0)