Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rec: Add endbr64 instructions in the right spots for OpenBSD/amd64 #13430

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions pdns/recursordist/mtasker_fcontext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ using boost::context::make_fcontext;
using boost::context::detail::make_fcontext;
#endif /* BOOST_VERSION < 106100 */

// __CET__ is set by the compiler if relevant, so far only relevant/tested for amd64 on OpenBSD
#if defined(__amd64__)
#if __CET__ & 0x1
#define CET_ENDBR __asm("endbr64")
rgacogne marked this conversation as resolved.
Show resolved Hide resolved
#else
#define CET_ENDBR
#endif
#endif

#ifdef PDNS_USE_VALGRIND
#include <valgrind/valgrind.h>
#endif /* PDNS_USE_VALGRIND */
Expand Down Expand Up @@ -132,6 +141,7 @@ extern "C"
static_cast<fcontext_t>(args->prev_ctx), 0);
#else
transfer_t res = jump_fcontext(t.fctx, 0);
CET_ENDBR;
rgacogne marked this conversation as resolved.
Show resolved Hide resolved
/* we got switched back from pdns_swapcontext() */
if (res.data) {
/* if res.data is not a nullptr, it holds a pointer to the context
Expand Down Expand Up @@ -203,6 +213,7 @@ void pdns_swapcontext(pdns_ucontext_t& __restrict octx, pdns_ucontext_t const& _
std::rethrow_exception(origctx->exception);
#else
transfer_t res = jump_fcontext(static_cast<fcontext_t>(ctx.uc_mcontext), &octx.uc_mcontext);
CET_ENDBR;
if (res.data) {
/* 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
Expand Down Expand Up @@ -235,6 +246,7 @@ void pdns_makecontext(pdns_ucontext_t& ctx, std::function<void(void)>& start)
#else
transfer_t res = jump_fcontext(static_cast<fcontext_t>(ctx.uc_mcontext),
&args);
CET_ENDBR;
/* back from threadwrapper, updating the context */
ctx.uc_mcontext = res.fctx;
#endif
Expand Down