From: Otto Moerbeek Date: Thu, 18 Dec 2025 14:33:02 +0000 (+0100) Subject: wip for acquire/release in broadcast pipes X-Git-Tag: rec-5.4.0-beta1~53^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa0f02bbdb0a7d1c0d9dbbe9cb43e5991bed6f59;p=thirdparty%2Fpdns.git wip for acquire/release in broadcast pipes Signed-off-by: Otto Moerbeek --- diff --git a/pdns/recursordist/rec-main.cc b/pdns/recursordist/rec-main.cc index 3811b9ebd9..749078e467 100644 --- a/pdns/recursordist/rec-main.cc +++ b/pdns/recursordist/rec-main.cc @@ -81,6 +81,24 @@ thread_local FrameStreamServersInfo t_nodFrameStreamServersInfo; #endif #endif +#if __SANITIZE_THREAD__ +#if defined __has_include +#if __has_include() +#include +#else /* __has_include() */ +extern "C" void __tsan_acquire(void* addr); +extern "C" void __tsan_release(void* addr); +#endif /* __has_include() */ +#else /* defined __has_include */ +extern "C" void __tsan_acquire(void* addr); +extern "C" void __tsan_release(void* addr); +#endif /* defined __has_include */ +#else +#error XXXX +#define __tsan_acquire(x) +#define __tsan_release(x) +#endif /* __SANITIZE_THREAD__ */ + string g_programname = "pdns_recursor"; string g_pidfname; RecursorControlChannel g_rcc; // only active in the handler thread @@ -1507,7 +1525,13 @@ void broadcastFunction(const pipefunc_t& func) ThreadMSG* tmsg = new ThreadMSG(); // NOLINT: manual ownership handling tmsg->func = func; tmsg->wantAnswer = true; + + __tsan_release(tmsg); + if (write(threadInfo.getPipes().writeToThread, &tmsg, sizeof(tmsg)) != sizeof(tmsg)) { // NOLINT: sizeof correct + + __tsan_acquire(tmsg); + delete tmsg; // NOLINT: manual ownership handling unixDie("write to thread pipe returned wrong size or error"); @@ -1518,6 +1542,8 @@ void broadcastFunction(const pipefunc_t& func) unixDie("read from thread pipe returned wrong size or error"); } + __tsan_acquire(resp); + if (resp != nullptr) { delete resp; // NOLINT: manual ownership handling resp = nullptr; @@ -1588,7 +1614,12 @@ T broadcastAccFunction(const std::function& func) tmsg->func = [func] { return voider(func); }; tmsg->wantAnswer = true; + __tsan_release(tmsg); + if (write(tps.writeToThread, &tmsg, sizeof(tmsg)) != sizeof(tmsg)) { // NOLINT:: sizeof correct + + __tsan_acquire(tmsg); + delete tmsg; // NOLINT: manual ownership handling unixDie("write to thread pipe returned wrong size or error"); } @@ -1597,6 +1628,8 @@ T broadcastAccFunction(const std::function& func) if (read(tps.readFromThread, &resp, sizeof(resp)) != sizeof(resp)) // NOLINT: sizeof correct unixDie("read from thread pipe returned wrong size or error"); + __tsan_acquire(resp); + if (resp) { ret += *resp; delete resp; // NOLINT: manual ownership handling @@ -2353,6 +2386,8 @@ static void handlePipeRequest(int fileDesc, FDMultiplexer::funcparam_t& /* var * unixDie("read from thread pipe returned wrong size or error"); } + __tsan_acquire(tmsg); + void* resp = nullptr; try { resp = tmsg->func(); @@ -2372,6 +2407,9 @@ static void handlePipeRequest(int fileDesc, FDMultiplexer::funcparam_t& /* var * g_rateLimitedLogger.log(g_slog->withName("runtime"), "PIPE function"); } if (tmsg->wantAnswer) { + + __tsan_release(resp); + if (write(RecThreadInfo::self().getPipes().writeFromThread, &resp, sizeof(resp)) != sizeof(resp)) { delete tmsg; // NOLINT: manual ownership handling unixDie("write to thread pipe returned wrong size or error"); diff --git a/regression-tests.api/runtests.py b/regression-tests.api/runtests.py index cb9bcdea15..8fd736450c 100755 --- a/regression-tests.api/runtests.py +++ b/regression-tests.api/runtests.py @@ -161,7 +161,7 @@ if daemon not in ('authoritative', 'recursor') or backend not in ('gmysql', 'gpg daemon = sys.argv[1] pdns_server = os.environ.get("PDNSSERVER", "../pdns/pdns_server") -pdns_recursor = os.environ.get("PDNSRECURSOR", "../pdns/recursordist/pdns_recursor") +pdns_recursor = os.environ.get("PDNSRECURSOR", "../pdns/recursordist/build/pdns_recursor") common_args = [ "--daemon=no", "--socket-dir=.", "--config-dir=.", "--local-address=127.0.0.1", "--local-port="+str(DNSPORT),