Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
350a87cd0368eb3766811bc338e6ce2387ed92c1
[simgrid.git] / src / kernel / context / ContextUnix.hpp
1 /* Copyright (c) 2009-2019. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SIMGRID_SIMIX_UNIX_CONTEXT_HPP
7 #define SIMGRID_SIMIX_UNIX_CONTEXT_HPP
8
9 #include <ucontext.h> /* context relative declarations */
10
11 #include <atomic>
12 #include <cstdint>
13 #include <functional>
14 #include <vector>
15
16 #include <simgrid/simix.hpp>
17 #include <xbt/parmap.hpp>
18 #include <xbt/xbt_os_thread.h>
19
20 #include "src/internal_config.h"
21 #include "src/kernel/context/ContextSwapped.hpp"
22
23 namespace simgrid {
24 namespace kernel {
25 namespace context {
26
27 class UContext : public SwappedContext {
28 public:
29   UContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process,
30            SwappedContextFactory* factory);
31
32   void swap_into(SwappedContext* to) override;
33
34 private:
35   ucontext_t uc_;         /* the ucontext that executes the code */
36
37 #if HAVE_SANITIZER_ADDRESS_FIBER_SUPPORT
38   const void* asan_stack_ = nullptr;
39   size_t asan_stack_size_ = 0;
40   UContext* asan_ctx_     = nullptr;
41   bool asan_stop_         = false;
42 #endif
43
44   static void smx_ctx_sysv_wrapper(int, int);
45   static void make_ctx(ucontext_t* ucp, void (*func)(int, int), UContext* arg);
46 };
47
48 class UContextFactory : public SwappedContextFactory {
49 public:
50   UContextFactory() : SwappedContextFactory("UContextFactory") {}
51
52   Context* create_context(std::function<void()> code, void_pfn_smxprocess_t cleanup, smx_actor_t process) override;
53 };
54 }}} // namespace
55
56 #endif