2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
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.
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.
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.
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.
23 #include "lazy_allocator.hh"
24 #include <boost/function.hpp>
28 struct pdns_ucontext_t {
30 pdns_ucontext_t (pdns_ucontext_t const&) = delete;
31 pdns_ucontext_t& operator= (pdns_ucontext_t const&) = delete;
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
40 #endif /* PDNS_USE_VALGRIND */
45 (pdns_ucontext_t& __restrict octx, pdns_ucontext_t const& __restrict ctx);
49 (pdns_ucontext_t& ctx, boost::function<void(void)>& start);
51 #ifdef HAVE_FIBER_SANITIZER
52 #include <sanitizer/common_interface_defs.h>
53 #endif /* HAVE_FIBER_SANITIZER */
55 #ifdef HAVE_FIBER_SANITIZER
56 extern __thread void* t_mainStack;
57 extern __thread size_t t_mainStackSize;
58 #endif /* HAVE_FIBER_SANITIZER */
60 static inline void notifyStackSwitch(void* startOfStack, size_t stackSize)
62 #ifdef HAVE_FIBER_SANITIZER
63 __sanitizer_start_switch_fiber(nullptr, startOfStack, stackSize);
64 #endif /* HAVE_FIBER_SANITIZER */
67 static inline void notifyStackSwitchToKernel()
69 #ifdef HAVE_FIBER_SANITIZER
70 notifyStackSwitch(t_mainStack, t_mainStackSize);
71 #endif /* HAVE_FIBER_SANITIZER */
74 static inline void notifyStackSwitchDone()
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 */