]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/mtasker_context.hh
rec: Don't account chained queries more than once
[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 #ifndef MTASKER_CONTEXT_HH
23 #define MTASKER_CONTEXT_HH
24
25 #include "lazy_allocator.hh"
26 #include <boost/function.hpp>
27 #include <vector>
28 #include <exception>
29
30 struct 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;
40 #ifdef PDNS_USE_VALGRIND
41 int valgrind_id;
42 #endif /* PDNS_USE_VALGRIND */
43 };
44
45 void
46 pdns_swapcontext
47 (pdns_ucontext_t& __restrict octx, pdns_ucontext_t const& __restrict ctx);
48
49 void
50 pdns_makecontext
51 (pdns_ucontext_t& ctx, boost::function<void(void)>& start);
52
53 #ifdef HAVE_FIBER_SANITIZER
54 #include <sanitizer/common_interface_defs.h>
55 #endif /* HAVE_FIBER_SANITIZER */
56
57 #ifdef HAVE_FIBER_SANITIZER
58 extern __thread void* t_mainStack;
59 extern __thread size_t t_mainStackSize;
60 #endif /* HAVE_FIBER_SANITIZER */
61
62 static 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
69 static inline void notifyStackSwitchToKernel()
70 {
71 #ifdef HAVE_FIBER_SANITIZER
72 notifyStackSwitch(t_mainStack, t_mainStackSize);
73 #endif /* HAVE_FIBER_SANITIZER */
74 }
75
76 static inline void notifyStackSwitchDone()
77 {
78 #ifdef HAVE_FIBER_SANITIZER
79 #ifdef HAVE_SANITIZER_FINISH_SWITCH_FIBER_SINGLE_PTR
80 __sanitizer_finish_switch_fiber(nullptr);
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 */
86 #endif /* HAVE_FIBER_SANITIZER */
87 }
88
89
90 #endif // MTASKER_CONTEXT_HH