From cecb7faea23bd055ca4a2bc08b313f5dbaadde31 Mon Sep 17 00:00:00 2001 From: Kuba Brecka Date: Thu, 7 Apr 2016 11:38:53 +0000 Subject: [tsan] Add support for dispatch event sources GCD has APIs for event sources, we need some more release-acquire pairs to avoid false positives in TSan. Differential Revision: http://reviews.llvm.org/D18515 llvm-svn: 265660 --- compiler-rt/lib/tsan/rtl/tsan_libdispatch_mac.cc | 72 ++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'compiler-rt/lib/tsan') diff --git a/compiler-rt/lib/tsan/rtl/tsan_libdispatch_mac.cc b/compiler-rt/lib/tsan/rtl/tsan_libdispatch_mac.cc index 2b4dc3413aa..abfc82fc358 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_libdispatch_mac.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_libdispatch_mac.cc @@ -317,6 +317,78 @@ TSAN_INTERCEPTOR(void, dispatch_group_notify_f, dispatch_group_t group, dispatch_callback_wrap); } +TSAN_INTERCEPTOR(void, dispatch_source_set_event_handler, + dispatch_source_t source, dispatch_block_t handler) { + SCOPED_TSAN_INTERCEPTOR(dispatch_source_set_event_handler, source, handler); + dispatch_block_t new_handler = ^(void) { + { + SCOPED_INTERCEPTOR_RAW(dispatch_source_set_event_handler_callback); + Acquire(thr, pc, (uptr)source); + } + handler(); + }; + Release(thr, pc, (uptr)source); + REAL(dispatch_source_set_event_handler)(source, new_handler); +} + +TSAN_INTERCEPTOR(void, dispatch_source_set_event_handler_f, + dispatch_source_t source, dispatch_function_t handler) { + SCOPED_TSAN_INTERCEPTOR(dispatch_source_set_event_handler_f, source, handler); + dispatch_block_t block = ^(void) { + handler(dispatch_get_context(source)); + }; + WRAP(dispatch_source_set_event_handler)(source, block); +} + +TSAN_INTERCEPTOR(void, dispatch_source_set_cancel_handler, + dispatch_source_t source, dispatch_block_t handler) { + SCOPED_TSAN_INTERCEPTOR(dispatch_source_set_cancel_handler, source, handler); + dispatch_block_t new_handler = ^(void) { + { + SCOPED_INTERCEPTOR_RAW(dispatch_source_set_cancel_handler_callback); + Acquire(thr, pc, (uptr)source); + } + handler(); + }; + Release(thr, pc, (uptr)source); + REAL(dispatch_source_set_cancel_handler)(source, new_handler); +} + +TSAN_INTERCEPTOR(void, dispatch_source_set_cancel_handler_f, + dispatch_source_t source, dispatch_function_t handler) { + SCOPED_TSAN_INTERCEPTOR(dispatch_source_set_cancel_handler_f, source, + handler); + dispatch_block_t block = ^(void) { + handler(dispatch_get_context(source)); + }; + WRAP(dispatch_source_set_cancel_handler)(source, block); +} + +TSAN_INTERCEPTOR(void, dispatch_source_set_registration_handler, + dispatch_source_t source, dispatch_block_t handler) { + SCOPED_TSAN_INTERCEPTOR(dispatch_source_set_registration_handler, source, + handler); + dispatch_block_t new_handler = ^(void) { + { + SCOPED_INTERCEPTOR_RAW(dispatch_source_set_registration_handler_callback); + Acquire(thr, pc, (uptr)source); + } + handler(); + }; + Release(thr, pc, (uptr)source); + REAL(dispatch_source_set_registration_handler)(source, new_handler); +} + +TSAN_INTERCEPTOR(void, dispatch_source_set_registration_handler_f, + dispatch_source_t source, dispatch_function_t handler) { + SCOPED_TSAN_INTERCEPTOR(dispatch_source_set_registration_handler_f, source, + handler); + dispatch_block_t block = ^(void) { + handler(dispatch_get_context(source)); + }; + WRAP(dispatch_source_set_registration_handler)(source, block); +} + } // namespace __tsan #endif // SANITIZER_MAC -- cgit v1.2.3