From 6afe4f00fae59537c2351658285ad98968f39473 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Tue, 10 Sep 2024 15:21:55 +0200 Subject: [PATCH] Tidy --- pdns/recursordist/mtasker_context.cc | 32 ++++++++++++++++------------ 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/pdns/recursordist/mtasker_context.cc b/pdns/recursordist/mtasker_context.cc index 0699b1f94f..1bd3fd8ae1 100644 --- a/pdns/recursordist/mtasker_context.cc +++ b/pdns/recursordist/mtasker_context.cc @@ -118,7 +118,7 @@ extern "C" threadWrapper(intptr_t const xargs) { #else - threadWrapper(transfer_t const t) + threadWrapper(transfer_t const theThread) { #endif /* Access the args passed from pdns_makecontext, and copy them directly from @@ -132,26 +132,26 @@ extern "C" */ notifyStackSwitchDone(); #if BOOST_VERSION < 106100 - auto args = reinterpret_cast(xargs); + auto* args = reinterpret_cast(xargs); #else - auto args = reinterpret_cast(t.data); + auto* args = static_cast(theThread.data); #endif - auto ctx = args->self; - auto work = args->work; + auto* ctx = args->self; + auto* work = args->work; /* we switch back to pdns_makecontext() */ notifyStackSwitchToKernel(); #if BOOST_VERSION < 106100 jump_fcontext(reinterpret_cast(&ctx->uc_mcontext), static_cast(args->prev_ctx), 0); #else - transfer_t res = jump_fcontext(t.fctx, 0); + transfer_t res = jump_fcontext(theThread.fctx, nullptr); CET_ENDBR; /* we got switched back from pdns_swapcontext() */ - if (res.data) { + if (res.data != nullptr) { /* if res.data is not a nullptr, it holds a pointer to the context we just switched from, and we need to fill it to be able to switch back to it later. */ - fcontext_t* ptr = static_cast(res.data); + auto* ptr = static_cast(res.data); *ptr = res.fctx; } #endif @@ -168,13 +168,13 @@ extern "C" notifyStackSwitchToKernel(); /* Emulate the System V uc_link feature. */ - auto const next_ctx = ctx->uc_link->uc_mcontext; + auto* const next_ctx = ctx->uc_link->uc_mcontext; #if BOOST_VERSION < 106100 jump_fcontext(reinterpret_cast(&ctx->uc_mcontext), static_cast(next_ctx), reinterpret_cast(ctx)); #else - jump_fcontext(static_cast(next_ctx), 0); + jump_fcontext(static_cast(next_ctx), nullptr); #endif #ifdef NDEBUG @@ -191,17 +191,19 @@ pdns_ucontext_t::pdns_ucontext_t() : #endif /* PDNS_USE_VALGRIND */ } +#ifdef 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 */ } +#else +pdns_ucontext_t::~pdns_ucontext_t() = default; +#endif /* PDNS_USE_VALGRIND */ void pdns_swapcontext(pdns_ucontext_t& __restrict octx, pdns_ucontext_t const& __restrict ctx) { @@ -218,11 +220,11 @@ void pdns_swapcontext(pdns_ucontext_t& __restrict octx, pdns_ucontext_t const& _ #else transfer_t res = jump_fcontext(static_cast(ctx.uc_mcontext), &octx.uc_mcontext); CET_ENDBR; - if (res.data) { + if (res.data != nullptr) { /* if res.data is not a nullptr, it holds a pointer to the context we just switched from, and we need to fill it to be able to switch back to it later. */ - fcontext_t* ptr = static_cast(res.data); + auto* ptr = static_cast(res.data); *ptr = res.fctx; } if (ctx.exception) { @@ -233,9 +235,11 @@ void pdns_swapcontext(pdns_ucontext_t& __restrict octx, pdns_ucontext_t const& _ void pdns_makecontext(pdns_ucontext_t& ctx, std::function& start) { + // NOLINTBEGIN(cppcoreguidelines-pro-bounds-array-to-pointer-decay) assert(ctx.uc_link); assert(ctx.uc_stack.size() >= 8192); assert(!ctx.uc_mcontext); + // NOLINTEND(cppcoreguidelines-pro-bounds-array-to-pointer-decay) ctx.uc_mcontext = make_fcontext(&ctx.uc_stack[ctx.uc_stack.size() - 1], ctx.uc_stack.size() - 1, &threadWrapper); args_t args; -- 2.47.2