Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move ASan related instructions around context swapping into SwappedContext.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 16 Jan 2020 15:31:32 +0000 (16:31 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 16 Jan 2020 22:10:31 +0000 (23:10 +0100)
* make ASan related fields private
* kill now unused src/kernel/contexts/context_private.h

MANIFEST.in
src/kernel/context/ContextBoost.cpp
src/kernel/context/ContextBoost.hpp
src/kernel/context/ContextRaw.cpp
src/kernel/context/ContextRaw.hpp
src/kernel/context/ContextSwapped.cpp
src/kernel/context/ContextSwapped.hpp
src/kernel/context/ContextUnix.cpp
src/kernel/context/ContextUnix.hpp
src/kernel/context/context_private.hpp [deleted file]
tools/cmake/DefinePackages.cmake

index 3816a7f..013c512 100644 (file)
@@ -2185,7 +2185,6 @@ include src/kernel/context/ContextThread.cpp
 include src/kernel/context/ContextThread.hpp
 include src/kernel/context/ContextUnix.cpp
 include src/kernel/context/ContextUnix.hpp
 include src/kernel/context/ContextThread.hpp
 include src/kernel/context/ContextUnix.cpp
 include src/kernel/context/ContextUnix.hpp
-include src/kernel/context/context_private.hpp
 include src/kernel/future.cpp
 include src/kernel/lmm/fair_bottleneck.cpp
 include src/kernel/lmm/maxmin.cpp
 include src/kernel/future.cpp
 include src/kernel/lmm/fair_bottleneck.cpp
 include src/kernel/lmm/maxmin.cpp
index 9e5e486..9d275c2 100644 (file)
@@ -4,7 +4,6 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "ContextBoost.hpp"
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "ContextBoost.hpp"
-#include "context_private.hpp"
 #include "simgrid/Exception.hpp"
 #include "src/simix/smx_private.hpp"
 
 #include "simgrid/Exception.hpp"
 #include "src/simix/smx_private.hpp"
 
@@ -49,19 +48,15 @@ void BoostContext::wrapper(BoostContext::arg_type arg)
   smx_ctx_wrapper(context);
 }
 
   smx_ctx_wrapper(context);
 }
 
-void BoostContext::swap_into(SwappedContext* to_)
+void BoostContext::swap_into_for_real(SwappedContext* to_)
 {
   BoostContext* to = static_cast<BoostContext*>(to_);
 #if BOOST_VERSION < 106100
   boost::context::jump_fcontext(&this->fc_, to->fc_, reinterpret_cast<intptr_t>(to));
 #else
   BoostContext* ctx[2] = {this, to};
 {
   BoostContext* to = static_cast<BoostContext*>(to_);
 #if BOOST_VERSION < 106100
   boost::context::jump_fcontext(&this->fc_, to->fc_, reinterpret_cast<intptr_t>(to));
 #else
   BoostContext* ctx[2] = {this, to};
-  ASAN_ONLY(void* fake_stack = nullptr);
-  ASAN_ONLY(to->asan_ctx_ = this);
-  ASAN_START_SWITCH(this->asan_stop_ ? nullptr : &fake_stack, to->asan_stack_, to->asan_stack_size_);
   boost::context::detail::transfer_t arg = boost::context::detail::jump_fcontext(to->fc_, ctx);
   this->verify_previous_context(static_cast<BoostContext**>(arg.data)[0]);
   boost::context::detail::transfer_t arg = boost::context::detail::jump_fcontext(to->fc_, ctx);
   this->verify_previous_context(static_cast<BoostContext**>(arg.data)[0]);
-  ASAN_FINISH_SWITCH(fake_stack, &this->asan_ctx_->asan_stack_, &this->asan_ctx_->asan_stack_size_);
   static_cast<BoostContext**>(arg.data)[0]->fc_ = arg.fctx;
 #endif
 }
   static_cast<BoostContext**>(arg.data)[0]->fc_ = arg.fctx;
 #endif
 }
index 6445635..8284fc9 100644 (file)
@@ -34,8 +34,6 @@ class BoostContext : public SwappedContext {
 public:
   BoostContext(std::function<void()>&& code, actor::ActorImpl* actor, SwappedContextFactory* factory);
 
 public:
   BoostContext(std::function<void()>&& code, actor::ActorImpl* actor, SwappedContextFactory* factory);
 
-  void swap_into(SwappedContext* to) override;
-
 private:
 #if BOOST_VERSION < 106100
   boost::context::fcontext_t fc_;
 private:
 #if BOOST_VERSION < 106100
   boost::context::fcontext_t fc_;
@@ -46,6 +44,8 @@ private:
 #endif
 
   XBT_ATTRIB_NORETURN static void wrapper(arg_type arg);
 #endif
 
   XBT_ATTRIB_NORETURN static void wrapper(arg_type arg);
+
+  void swap_into_for_real(SwappedContext* to) override;
 };
 
 class BoostContextFactory : public SwappedContextFactory {
 };
 
 class BoostContextFactory : public SwappedContextFactory {
index 4ac3c90..47fe3f0 100644 (file)
@@ -4,7 +4,6 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "ContextRaw.hpp"
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "ContextRaw.hpp"
-#include "context_private.hpp"
 #include "mc/mc.h"
 #include "simgrid/Exception.hpp"
 #include "src/simix/smx_private.hpp"
 #include "mc/mc.h"
 #include "simgrid/Exception.hpp"
 #include "src/simix/smx_private.hpp"
@@ -206,14 +205,10 @@ RawContext::RawContext(std::function<void()>&& code, actor::ActorImpl* actor, Sw
    }
 }
 
    }
 }
 
-void RawContext::swap_into(SwappedContext* to_)
+void RawContext::swap_into_for_real(SwappedContext* to_)
 {
   const RawContext* to = static_cast<RawContext*>(to_);
 {
   const RawContext* to = static_cast<RawContext*>(to_);
-  ASAN_ONLY(void* fake_stack = nullptr);
-  ASAN_ONLY(to_->asan_ctx_ = this);
-  ASAN_START_SWITCH(this->asan_stop_ ? nullptr : &fake_stack, to_->asan_stack_, to_->asan_stack_size_);
   raw_swapcontext(&this->stack_top_, to->stack_top_);
   raw_swapcontext(&this->stack_top_, to->stack_top_);
-  ASAN_FINISH_SWITCH(fake_stack, &this->asan_ctx_->asan_stack_, &this->asan_ctx_->asan_stack_size_);
 }
 
 ContextFactory* raw_factory()
 }
 
 ContextFactory* raw_factory()
index 7e36473..f9b30e0 100644 (file)
@@ -28,11 +28,11 @@ class RawContext : public SwappedContext {
 public:
   RawContext(std::function<void()>&& code, actor::ActorImpl* actor, SwappedContextFactory* factory);
 
 public:
   RawContext(std::function<void()>&& code, actor::ActorImpl* actor, SwappedContextFactory* factory);
 
-  void swap_into(SwappedContext* to) override;
-
 private:
   /** pointer to top the stack stack */
   void* stack_top_ = nullptr;
 private:
   /** pointer to top the stack stack */
   void* stack_top_ = nullptr;
+
+  void swap_into_for_real(SwappedContext* to) override;
 };
 
 class RawContextFactory : public SwappedContextFactory {
 };
 
 class RawContextFactory : public SwappedContextFactory {
index 8d7e071..e6e6a7b 100644 (file)
@@ -7,7 +7,6 @@
 #include "simgrid/modelchecker.h"
 #include "src/internal_config.h"
 #include "src/kernel/actor/ActorImpl.hpp"
 #include "simgrid/modelchecker.h"
 #include "src/internal_config.h"
 #include "src/kernel/actor/ActorImpl.hpp"
-#include "src/kernel/context/context_private.hpp"
 #include "src/simix/smx_private.hpp"
 #include "xbt/parmap.hpp"
 
 #include "src/simix/smx_private.hpp"
 #include "xbt/parmap.hpp"
 
@@ -28,6 +27,9 @@
 #if HAVE_VALGRIND_H
 #include <valgrind/valgrind.h>
 #endif
 #if HAVE_VALGRIND_H
 #include <valgrind/valgrind.h>
 #endif
+#if HAVE_SANITIZER_ADDRESS_FIBER_SUPPORT
+#include <sanitizer/asan_interface.h>
+#endif
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
 
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
 
@@ -158,6 +160,21 @@ void SwappedContext::stop()
   throw ForcefulKillException();
 }
 
   throw ForcefulKillException();
 }
 
+void SwappedContext::swap_into(SwappedContext* to)
+{
+#if HAVE_SANITIZER_ADDRESS_FIBER_SUPPORT
+  void* fake_stack = nullptr;
+  to->asan_ctx_    = this;
+  __sanitizer_start_switch_fiber(this->asan_stop_ ? nullptr : &fake_stack, to->asan_stack_, to->asan_stack_size_);
+#endif
+
+  swap_into_for_real(to);
+
+#if HAVE_SANITIZER_ADDRESS_FIBER_SUPPORT
+  __sanitizer_finish_switch_fiber(fake_stack, &this->asan_ctx_->asan_stack_, &this->asan_ctx_->asan_stack_size_);
+#endif
+}
+
 /** Maestro wants to run all ready actors */
 void SwappedContextFactory::run_all()
 {
 /** Maestro wants to run all ready actors */
 void SwappedContextFactory::run_all()
 {
index b83ae9f..aac9841 100644 (file)
@@ -6,6 +6,7 @@
 #ifndef SIMGRID_KERNEL_CONTEXT_SWAPPED_CONTEXT_HPP
 #define SIMGRID_KERNEL_CONTEXT_SWAPPED_CONTEXT_HPP
 
 #ifndef SIMGRID_KERNEL_CONTEXT_SWAPPED_CONTEXT_HPP
 #define SIMGRID_KERNEL_CONTEXT_SWAPPED_CONTEXT_HPP
 
+#include "src/internal_config.h" // HAVE_SANITIZER_*
 #include "src/kernel/context/Context.hpp"
 
 #include <memory>
 #include "src/kernel/context/Context.hpp"
 
 #include <memory>
@@ -55,20 +56,13 @@ public:
   virtual void resume();
   XBT_ATTRIB_NORETURN void stop() override;
 
   virtual void resume();
   XBT_ATTRIB_NORETURN void stop() override;
 
-  virtual void swap_into(SwappedContext* to) = 0; // Defined in Raw, Boost and UContext subclasses
+  void swap_into(SwappedContext* to);
 
   unsigned char* get_stack() const { return stack_; }
   // Return the address for the bottom of the stack.  Depending on the stack direction it may be the lower or higher
   // address
   unsigned char* get_stack_bottom() const { return PTH_STACKGROWTH == -1 ? stack_ + smx_context_stack_size : stack_; }
 
 
   unsigned char* get_stack() const { return stack_; }
   // Return the address for the bottom of the stack.  Depending on the stack direction it may be the lower or higher
   // address
   unsigned char* get_stack_bottom() const { return PTH_STACKGROWTH == -1 ? stack_ + smx_context_stack_size : stack_; }
 
-#if HAVE_SANITIZER_ADDRESS_FIBER_SUPPORT
-  const void* asan_stack_   = nullptr;
-  size_t asan_stack_size_   = 0;
-  SwappedContext* asan_ctx_ = nullptr;
-  bool asan_stop_           = false;
-#endif
-
 protected:
   // With ASan, after a context switch, check that the originating context is the expected one (see BoostContext)
   void verify_previous_context(const SwappedContext* context) const;
 protected:
   // With ASan, after a context switch, check that the originating context is the expected one (see BoostContext)
   void verify_previous_context(const SwappedContext* context) const;
@@ -82,6 +76,14 @@ private:
 #if HAVE_VALGRIND_H
   unsigned int valgrind_stack_id_;
 #endif
 #if HAVE_VALGRIND_H
   unsigned int valgrind_stack_id_;
 #endif
+#if HAVE_SANITIZER_ADDRESS_FIBER_SUPPORT
+  const void* asan_stack_   = nullptr;
+  size_t asan_stack_size_   = 0;
+  SwappedContext* asan_ctx_ = nullptr;
+  bool asan_stop_           = false;
+#endif
+
+  virtual void swap_into_for_real(SwappedContext* to) = 0; // Defined in Raw, Boost and UContext subclasses
 };
 
 inline void SwappedContext::verify_previous_context(XBT_ATTRIB_UNUSED const SwappedContext* context) const
 };
 
 inline void SwappedContext::verify_previous_context(XBT_ATTRIB_UNUSED const SwappedContext* context) const
index 882dd74..0b6f7a8 100644 (file)
@@ -5,8 +5,6 @@
 
 /* \file UContext.cpp Context switching with ucontexts from System V        */
 
 
 /* \file UContext.cpp Context switching with ucontexts from System V        */
 
-#include "context_private.hpp"
-
 #include "mc/mc.h"
 #include "simgrid/Exception.hpp"
 #include "src/kernel/actor/ActorImpl.hpp"
 #include "mc/mc.h"
 #include "simgrid/Exception.hpp"
 #include "src/kernel/actor/ActorImpl.hpp"
@@ -73,14 +71,10 @@ UContext::UContext(std::function<void()>&& code, actor::ActorImpl* actor, Swappe
   }
 }
 
   }
 }
 
-void UContext::swap_into(SwappedContext* to_)
+void UContext::swap_into_for_real(SwappedContext* to_)
 {
   const UContext* to = static_cast<UContext*>(to_);
 {
   const UContext* to = static_cast<UContext*>(to_);
-  ASAN_ONLY(void* fake_stack = nullptr);
-  ASAN_ONLY(to_->asan_ctx_ = this);
-  ASAN_START_SWITCH(this->asan_stop_ ? nullptr : &fake_stack, to_->asan_stack_, to_->asan_stack_size_);
   swapcontext(&this->uc_, &to->uc_);
   swapcontext(&this->uc_, &to->uc_);
-  ASAN_FINISH_SWITCH(fake_stack, &this->asan_ctx_->asan_stack_, &this->asan_ctx_->asan_stack_size_);
 }
 
 
 }
 
 
index 8b20842..c8a9ad2 100644 (file)
@@ -27,10 +27,10 @@ class UContext : public SwappedContext {
 public:
   UContext(std::function<void()>&& code, actor::ActorImpl* actor, SwappedContextFactory* factory);
 
 public:
   UContext(std::function<void()>&& code, actor::ActorImpl* actor, SwappedContextFactory* factory);
 
-  void swap_into(SwappedContext* to) override;
-
 private:
   ucontext_t uc_;         /* the ucontext that executes the code */
 private:
   ucontext_t uc_;         /* the ucontext that executes the code */
+
+  void swap_into_for_real(SwappedContext* to) override;
 };
 
 class UContextFactory : public SwappedContextFactory {
 };
 
 class UContextFactory : public SwappedContextFactory {
diff --git a/src/kernel/context/context_private.hpp b/src/kernel/context/context_private.hpp
deleted file mode 100644 (file)
index 93aada6..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Copyright (c) 2017-2020. The SimGrid Team. All rights reserved.          */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#ifndef SIMGRID_KERNEL_CONTEXT_PRIVATE_HPP
-#define SIMGRID_KERNEL_CONTEXT_PRIVATE_HPP
-
-#include "src/internal_config.h"
-
-#if HAVE_SANITIZER_ADDRESS_FIBER_SUPPORT
-#include <sanitizer/asan_interface.h>
-#define ASAN_ONLY(expr) expr
-#define ASAN_START_SWITCH(fake_stack_save, bottom, size) __sanitizer_start_switch_fiber(fake_stack_save, bottom, size)
-#define ASAN_FINISH_SWITCH(fake_stack_save, bottom_old, size_old)                                                      \
-  __sanitizer_finish_switch_fiber(fake_stack_save, bottom_old, size_old)
-#else
-#define ASAN_ONLY(expr) (void)0
-#define ASAN_START_SWITCH(fake_stack_save, bottom, size) (void)0
-#define ASAN_FINISH_SWITCH(fake_stack_save, bottom_old, size_old) (void)0
-#endif
-
-#endif
index 7b373ef..ce4f338 100644 (file)
@@ -389,7 +389,6 @@ set(SIMIX_SRC
   src/kernel/future.cpp
   src/simix/libsmx.cpp
   src/simix/smx_context.cpp
   src/kernel/future.cpp
   src/simix/libsmx.cpp
   src/simix/smx_context.cpp
-  src/kernel/context/context_private.hpp
   src/kernel/context/Context.cpp
   src/kernel/context/Context.hpp
   src/kernel/context/ContextRaw.cpp
   src/kernel/context/Context.cpp
   src/kernel/context/Context.hpp
   src/kernel/context/ContextRaw.cpp