|
15 | 15 |
|
16 | 16 | #include "interception/interception.h" |
17 | 17 | #include "sanitizer_common/sanitizer_allocator_dlsym.h" |
18 | | -#include "sanitizer_common/sanitizer_glibc_version.h" |
19 | 18 | #include "sanitizer_common/sanitizer_platform_interceptors.h" |
20 | 19 |
|
21 | 20 | #include "interception/interception.h" |
|
47 | 46 |
|
48 | 47 | using namespace __sanitizer; |
49 | 48 |
|
50 | | -DECLARE_REAL_AND_INTERCEPTOR(void *, malloc, usize size) |
51 | | -DECLARE_REAL_AND_INTERCEPTOR(void, free, void *ptr) |
52 | | - |
53 | 49 | namespace { |
54 | 50 | struct DlsymAlloc : public DlSymAllocator<DlsymAlloc> { |
55 | 51 | static bool UseImpl() { return !__rtsan_is_initialized(); } |
56 | 52 | }; |
57 | 53 | } // namespace |
58 | 54 |
|
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 | | - |
85 | 55 | // Filesystem |
86 | 56 |
|
87 | 57 | INTERCEPTOR(int, open, const char *path, int oflag, ...) { |
@@ -796,45 +766,26 @@ INTERCEPTOR(int, pthread_join, pthread_t thread, void **value_ptr) { |
796 | 766 | return REAL(pthread_join)(thread, value_ptr); |
797 | 767 | } |
798 | 768 |
|
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 | | - |
806 | 769 | INTERCEPTOR(int, pthread_cond_signal, pthread_cond_t *cond) { |
807 | 770 | __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); |
810 | 772 | } |
811 | 773 |
|
812 | 774 | INTERCEPTOR(int, pthread_cond_broadcast, pthread_cond_t *cond) { |
813 | 775 | __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); |
816 | 777 | } |
817 | 778 |
|
818 | 779 | INTERCEPTOR(int, pthread_cond_wait, pthread_cond_t *cond, |
819 | 780 | pthread_mutex_t *mutex) { |
820 | 781 | __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); |
823 | 783 | } |
824 | 784 |
|
825 | 785 | INTERCEPTOR(int, pthread_cond_timedwait, pthread_cond_t *cond, |
826 | 786 | pthread_mutex_t *mutex, const timespec *ts) { |
827 | 787 | __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); |
838 | 789 | } |
839 | 790 |
|
840 | 791 | INTERCEPTOR(int, pthread_rwlock_rdlock, pthread_rwlock_t *lock) { |
@@ -1690,26 +1641,10 @@ void __rtsan::InitializeInterceptors() { |
1690 | 1641 | INTERCEPT_FUNCTION(pthread_mutex_lock); |
1691 | 1642 | INTERCEPT_FUNCTION(pthread_mutex_unlock); |
1692 | 1643 | 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); |
1706 | 1644 | INTERCEPT_FUNCTION(pthread_cond_signal); |
1707 | 1645 | INTERCEPT_FUNCTION(pthread_cond_broadcast); |
1708 | 1646 | INTERCEPT_FUNCTION(pthread_cond_wait); |
1709 | 1647 | INTERCEPT_FUNCTION(pthread_cond_timedwait); |
1710 | | - INTERCEPT_FUNCTION(pthread_cond_destroy); |
1711 | | -#endif |
1712 | | - |
1713 | 1648 | INTERCEPT_FUNCTION(pthread_rwlock_rdlock); |
1714 | 1649 | INTERCEPT_FUNCTION(pthread_rwlock_unlock); |
1715 | 1650 | INTERCEPT_FUNCTION(pthread_rwlock_wrlock); |
|
0 commit comments