1 /* Copyright (c) 2009-2018. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef SIMGRID_SIMIX_UNIX_CONTEXT_HPP
7 #define SIMGRID_SIMIX_UNIX_CONTEXT_HPP
9 #include <ucontext.h> /* context relative declarations */
16 #include <simgrid/simix.hpp>
17 #include <xbt/parmap.hpp>
18 #include <xbt/xbt_os_thread.h>
20 #include "src/internal_config.h"
21 #include "src/kernel/context/ContextSwapped.hpp"
27 class UContext : public SwappedContext {
29 UContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process,
30 SwappedContextFactory* factory);
33 void swap_into(SwappedContext* to) override;
36 ucontext_t uc_; /* the ucontext that executes the code */
38 #if HAVE_SANITIZER_ADDRESS_FIBER_SUPPORT
39 const void* asan_stack_ = nullptr;
40 size_t asan_stack_size_ = 0;
41 UContext* asan_ctx_ = nullptr;
42 bool asan_stop_ = false;
45 static void smx_ctx_sysv_wrapper(int, int);
46 static void make_ctx(ucontext_t* ucp, void (*func)(int, int), UContext* arg);
49 class UContextFactory : public SwappedContextFactory {
51 UContextFactory() : SwappedContextFactory("UContextFactory") {}
53 Context* create_context(std::function<void()> code, void_pfn_smxprocess_t cleanup, smx_actor_t process) override;