summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac2
-rw-r--r--vm_insnhelper.c12
2 files changed, 14 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index b77cbea545..a9c3796caa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1359,6 +1359,7 @@ AC_CHECK_HEADERS(ucontext.h)
AC_CHECK_HEADERS(utime.h)
AC_CHECK_HEADERS(sys/epoll.h)
AC_CHECK_HEADERS(sys/event.h)
+AC_CHECK_HEADERS(stdatomic.h)
AS_CASE("$target_cpu", [x64|x86_64|i[3-6]86*], [
AC_CHECK_HEADERS(x86intrin.h)
@@ -2039,6 +2040,7 @@ AC_CHECK_FUNCS(_longjmp) # used for AC_ARG_WITH(setjmp-type)
test x$ac_cv_func__longjmp = xno && ac_cv_func__setjmp=no
AC_CHECK_FUNCS(arc4random_buf)
AC_CHECK_FUNCS(atan2l atan2f)
+AC_CHECK_DECLS(atomic_signal_fence, [], [], [#include <stdatomic.h>])
AC_CHECK_FUNCS(chmod)
AC_CHECK_FUNCS(chown)
AC_CHECK_FUNCS(chroot)
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index b72167f75d..913fd86bb1 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -12,6 +12,10 @@
#include <math.h>
+#ifdef HAVE_STDATOMIC_H
+ #include <stdatomic.h>
+#endif
+
#include "constant.h"
#include "debug_counter.h"
#include "internal.h"
@@ -388,6 +392,14 @@ vm_push_frame(rb_execution_context_t *ec,
.jit_return = NULL
};
+ /* Ensure the initialization of `*cfp` above never gets reordered with the update of `ec->cfp` below.
+ This is a no-op in all cases we've looked at (https://godbolt.org/z/3oxd1446K), but should guarantee it for all
+ future/untested compilers/platforms. */
+
+ #ifdef HAVE_DECL_ATOMIC_SIGNAL_FENCE
+ atomic_signal_fence(memory_order_seq_cst);
+ #endif
+
ec->cfp = cfp;
if (VMDEBUG == 2) {