]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/mtasker_context.hh
auth 4.1 build: Switch to devtoolset 7 for el6
[thirdparty/pdns.git] / pdns / mtasker_context.hh
CommitLineData
12471842
PL
1/*
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
5cf909f3
AN
22#ifndef MTASKER_CONTEXT_HH
23#define MTASKER_CONTEXT_HH
24
25#include "lazy_allocator.hh"
abc75058 26#include <boost/function.hpp>
5cf909f3
AN
27#include <vector>
28#include <exception>
29
30struct pdns_ucontext_t {
31 pdns_ucontext_t ();
32 pdns_ucontext_t (pdns_ucontext_t const&) = delete;
33 pdns_ucontext_t& operator= (pdns_ucontext_t const&) = delete;
34 ~pdns_ucontext_t ();
35
36 void* uc_mcontext;
37 pdns_ucontext_t* uc_link;
38 std::vector<char, lazy_allocator<char>> uc_stack;
39 std::exception_ptr exception;
ec7fcc43
RG
40#ifdef PDNS_USE_VALGRIND
41 int valgrind_id;
42#endif /* PDNS_USE_VALGRIND */
5cf909f3
AN
43};
44
45void
46pdns_swapcontext
47(pdns_ucontext_t& __restrict octx, pdns_ucontext_t const& __restrict ctx);
48
49void
50pdns_makecontext
abc75058 51(pdns_ucontext_t& ctx, boost::function<void(void)>& start);
5cf909f3 52
9c811931
RG
53#ifdef HAVE_FIBER_SANITIZER
54#include <sanitizer/common_interface_defs.h>
55#endif /* HAVE_FIBER_SANITIZER */
56
57#ifdef HAVE_FIBER_SANITIZER
58extern __thread void* t_mainStack;
59extern __thread size_t t_mainStackSize;
60#endif /* HAVE_FIBER_SANITIZER */
61
62static inline void notifyStackSwitch(void* startOfStack, size_t stackSize)
63{
64#ifdef HAVE_FIBER_SANITIZER
65 __sanitizer_start_switch_fiber(nullptr, startOfStack, stackSize);
66#endif /* HAVE_FIBER_SANITIZER */
67}
68
69static inline void notifyStackSwitchToKernel()
70{
71#ifdef HAVE_FIBER_SANITIZER
72 notifyStackSwitch(t_mainStack, t_mainStackSize);
73#endif /* HAVE_FIBER_SANITIZER */
74}
75
76static inline void notifyStackSwitchDone()
77{
78#ifdef HAVE_FIBER_SANITIZER
3144c8f7 79#ifdef HAVE_SANITIZER_FINISH_SWITCH_FIBER_SINGLE_PTR
9c811931 80 __sanitizer_finish_switch_fiber(nullptr);
3144c8f7
RG
81#else /* HAVE_SANITIZER_FINISH_SWITCH_FIBER_SINGLE_PTR */
82#ifdef HAVE_SANITIZER_FINISH_SWITCH_FIBER_THREE_PTRS
83 __sanitizer_finish_switch_fiber(nullptr, nullptr, nullptr);
84#endif /* HAVE_SANITIZER_FINISH_SWITCH_FIBER_THREE_PTRS */
85#endif /* HAVE_SANITIZER_FINISH_SWITCH_FIBER_SINGLE_PTR */
9c811931
RG
86#endif /* HAVE_FIBER_SANITIZER */
87}
88
89
5cf909f3 90#endif // MTASKER_CONTEXT_HH