Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add fiber annotations for TSan.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 9 Jan 2020 21:52:54 +0000 (22:52 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 16 Jan 2020 22:22:31 +0000 (23:22 +0100)
Close simgrid/simgrid#42.

ChangeLog
src/kernel/context/ContextSwapped.cpp
src/kernel/context/ContextSwapped.hpp

index 052e93c..feceb39 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -53,6 +53,7 @@ SMPI:
 
 Fixed bugs (FG#.. -> framagit bugs; FG!.. -> framagit merge requests):
  - FG#39: Missing s4u::Comm::wait_any_for example
+ - FG#42: Add support for ThreadSanitizer (TSan)
  - FG!19: Removing RngStream
  - FG!20: A module for RNG calls
  - FG!21: Choice between ad-hoc and standard distributions implementations
index e6e6a7b..afbaa91 100644 (file)
@@ -30,6 +30,9 @@
 #if HAVE_SANITIZER_ADDRESS_FIBER_SUPPORT
 #include <sanitizer/asan_interface.h>
 #endif
+#if HAVE_SANITIZER_THREAD_FIBER_SUPPORT
+#include <sanitizer/tsan_interface.h>
+#endif
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
 
@@ -122,6 +125,14 @@ SwappedContext::SwappedContext(std::function<void()>&& code, smx_actor_t actor,
 #endif
 #if HAVE_SANITIZER_ADDRESS_FIBER_SUPPORT
     this->asan_stack_ = get_stack_bottom();
+#endif
+#if HAVE_SANITIZER_THREAD_FIBER_SUPPORT
+    this->tsan_fiber_ = __tsan_create_fiber(0);
+#endif
+  } else {
+    // not has_code(): in maestro context
+#if HAVE_SANITIZER_THREAD_FIBER_SUPPORT
+    this->tsan_fiber_ = __tsan_get_current_fiber();
 #endif
   }
 }
@@ -131,6 +142,9 @@ SwappedContext::~SwappedContext()
   if (stack_ == nullptr) // maestro has no extra stack
     return;
 
+#if HAVE_SANITIZER_THREAD_FIBER_SUPPORT
+  __tsan_destroy_fiber(tsan_fiber_);
+#endif
 #if HAVE_VALGRIND_H
   if (RUNNING_ON_VALGRIND)
     VALGRIND_STACK_DEREGISTER(valgrind_stack_id_);
@@ -167,6 +181,9 @@ void SwappedContext::swap_into(SwappedContext* to)
   to->asan_ctx_    = this;
   __sanitizer_start_switch_fiber(this->asan_stop_ ? nullptr : &fake_stack, to->asan_stack_, to->asan_stack_size_);
 #endif
+#if HAVE_SANITIZER_THREAD_FIBER_SUPPORT
+  __tsan_switch_to_fiber(to->tsan_fiber_, 0);
+#endif
 
   swap_into_for_real(to);
 
index aac9841..1b815aa 100644 (file)
@@ -82,6 +82,9 @@ private:
   SwappedContext* asan_ctx_ = nullptr;
   bool asan_stop_           = false;
 #endif
+#if HAVE_SANITIZER_THREAD_FIBER_SUPPORT
+  void* tsan_fiber_;
+#endif
 
   virtual void swap_into_for_real(SwappedContext* to) = 0; // Defined in Raw, Boost and UContext subclasses
 };