Enabled via the `--enable-valgrind` configure switch.
--- /dev/null
+AC_DEFUN([PDNS_ENABLE_VALGRIND],[
+ AC_MSG_CHECKING([whether to enable Valgrind support])
+ AC_ARG_ENABLE([valgrind],
+ AS_HELP_STRING([--enable-valgrind],[enable Valgrind support @<:@default=no@:>@]),
+ [enable_valgrind=$enableval],
+ [enable_valgrind=no],
+ )
+ AC_MSG_RESULT([$enable_valgrind])
+
+ AS_IF([test "x$enable_valgrind" != "xno"], [
+ AS_IF([test "x$enable_valgrind" = "xyes" -o "x$enable_valgrind" = "xauto"], [
+ AC_CHECK_HEADERS([valgrind/valgrind.h], valgrind_headers=yes, valgrind_headers=no)
+ ])
+ ])
+ AS_IF([test "x$enable_valgrind" = "xyes"], [
+ AS_IF([test x"$valgrind_headers" = "no"], [
+ AC_MSG_ERROR([Valgrind support requested but required Valgrind headers were not found])
+ ])
+ ])
+ AM_CONDITIONAL([PDNS_USE_VALGRIND], [test x"$valgrind_headers" = "xyes" ])
+ AS_IF([test x"$valgrind_headers" = "xyes" ],
+ [ AC_DEFINE([PDNS_USE_VALGRIND], [1], [Define if using Valgrind.]) ],
+ )
+])
#include <stdio.h>
#include <iostream>
+#ifdef PDNS_USE_VALGRIND
+#include <valgrind/valgrind.h>
+#endif /* PDNS_USE_VALGRIND */
/** \page MTasker
Simple system for implementing cooperative multitasking of functions, with
uc->uc_link = &d_kernel; // come back to kernel after dying
uc->uc_stack.resize (d_stacksize);
+#ifdef PDNS_USE_VALGRIND
+ uc->valgrind_id = VALGRIND_STACK_REGISTER(&uc->uc_stack[0],
+ &uc->uc_stack[uc->uc_stack.size()]);
+#endif /* PDNS_USE_VALGRIND */
auto& thread = d_threads[d_maxtid];
auto mt = this;
pdns_ucontext_t* uc_link;
std::vector<char, lazy_allocator<char>> uc_stack;
std::exception_ptr exception;
+#ifdef PDNS_USE_VALGRIND
+ int valgrind_id;
+#endif /* PDNS_USE_VALGRIND */
};
void
using boost::context::detail::make_fcontext;
#endif /* BOOST_VERSION < 106100 */
+#ifdef PDNS_USE_VALGRIND
+#include <valgrind/valgrind.h>
+#endif /* PDNS_USE_VALGRIND */
#if BOOST_VERSION < 105600
/* Note: This typedef means functions taking fcontext_t*, like jump_fcontext(),
pdns_ucontext_t::pdns_ucontext_t
(): uc_mcontext(nullptr), uc_link(nullptr) {
+#ifdef PDNS_USE_VALGRIND
+ valgrind_id = 0;
+#endif /* PDNS_USE_VALGRIND */
}
pdns_ucontext_t::~pdns_ucontext_t
/* There's nothing to delete here since fcontext doesn't require anything
* to be heap allocated.
*/
+#ifdef PDNS_USE_VALGRIND
+ if (valgrind_id != 0) {
+ VALGRIND_STACK_DEREGISTER(valgrind_id);
+ }
+#endif /* PDNS_USE_VALGRIND */
}
void
#include <signal.h>
#include <ucontext.h>
+#ifdef PDNS_USE_VALGRIND
+#include <valgrind/valgrind.h>
+#endif /* PDNS_USE_VALGRIND */
+
template <typename Message> static __attribute__((noinline, cold, noreturn))
void
throw_errno (Message&& msg) {
pdns_ucontext_t::pdns_ucontext_t() {
uc_mcontext = new ::ucontext_t();
uc_link = nullptr;
+#ifdef PDNS_USE_VALGRIND
+ valgrind_id = 0;
+#endif /* PDNS_USE_VALGRIND */
}
pdns_ucontext_t::~pdns_ucontext_t() {
delete static_cast<ucontext_t*>(uc_mcontext);
+#ifdef PDNS_USE_VALGRIND
+ if (valgrind_id != 0) {
+ VALGRIND_STACK_DEREGISTER(valgrind_id);
+ }
+#endif /* PDNS_USE_VALGRIND */
}
void
PDNS_ENABLE_SANITIZERS
PDNS_ENABLE_MALLOC_TRACE
+PDNS_ENABLE_VALGRIND
AX_AVAILABLE_SYSTEMD
AM_CONDITIONAL([HAVE_SYSTEMD], [ test x"$systemd" = "xy" ])
PDNS_CHECK_PANDOC
--- /dev/null
+../../../m4//pdns_enable_valgrind.m4
\ No newline at end of file