]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/mtasker_context.hh
Make the constructors taking a pthread_rwlock_t * private.
[thirdparty/pdns.git] / pdns / mtasker_context.hh
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 */
22 #pragma once
23 #include "lazy_allocator.hh"
24 #include <boost/function.hpp>
25 #include <vector>
26 #include <exception>
27
28 struct pdns_ucontext_t {
29 pdns_ucontext_t ();
30 pdns_ucontext_t (pdns_ucontext_t const&) = delete;
31 pdns_ucontext_t& operator= (pdns_ucontext_t const&) = delete;
32 ~pdns_ucontext_t ();
33
34 void* uc_mcontext;
35 pdns_ucontext_t* uc_link;
36 std::vector<char, lazy_allocator<char>> uc_stack;
37 std::exception_ptr exception;
38 #ifdef PDNS_USE_VALGRIND
39 int valgrind_id;
40 #endif /* PDNS_USE_VALGRIND */
41 };
42
43 void
44 pdns_swapcontext
45 (pdns_ucontext_t& __restrict octx, pdns_ucontext_t const& __restrict ctx);
46
47 void
48 pdns_makecontext
49 (pdns_ucontext_t& ctx, boost::function<void(void)>& start);
50
51 #ifdef HAVE_FIBER_SANITIZER
52 #include <sanitizer/common_interface_defs.h>
53 #endif /* HAVE_FIBER_SANITIZER */
54
55 #ifdef HAVE_FIBER_SANITIZER
56 extern __thread void* t_mainStack;
57 extern __thread size_t t_mainStackSize;
58 #endif /* HAVE_FIBER_SANITIZER */
59
60 static inline void notifyStackSwitch(void* startOfStack, size_t stackSize)
61 {
62 #ifdef HAVE_FIBER_SANITIZER
63 __sanitizer_start_switch_fiber(nullptr, startOfStack, stackSize);
64 #endif /* HAVE_FIBER_SANITIZER */
65 }
66
67 static inline void notifyStackSwitchToKernel()
68 {
69 #ifdef HAVE_FIBER_SANITIZER
70 notifyStackSwitch(t_mainStack, t_mainStackSize);
71 #endif /* HAVE_FIBER_SANITIZER */
72 }
73
74 static inline void notifyStackSwitchDone()
75 {
76 #ifdef HAVE_FIBER_SANITIZER
77 #ifdef HAVE_SANITIZER_FINISH_SWITCH_FIBER_SINGLE_PTR
78 __sanitizer_finish_switch_fiber(nullptr);
79 #else /* HAVE_SANITIZER_FINISH_SWITCH_FIBER_SINGLE_PTR */
80 #ifdef HAVE_SANITIZER_FINISH_SWITCH_FIBER_THREE_PTRS
81 __sanitizer_finish_switch_fiber(nullptr, nullptr, nullptr);
82 #endif /* HAVE_SANITIZER_FINISH_SWITCH_FIBER_THREE_PTRS */
83 #endif /* HAVE_SANITIZER_FINISH_SWITCH_FIBER_SINGLE_PTR */
84 #endif /* HAVE_FIBER_SANITIZER */
85 }