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 ac6f821a8f..f8c814c22c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1440,6 +1440,7 @@ AC_CHECK_HEADERS(utime.h)
AC_CHECK_HEADERS(sys/epoll.h)
AC_CHECK_HEADERS(sys/event.h)
AC_CHECK_HEADERS(stdckdint.h)
+AC_CHECK_HEADERS(stdatomic.h)
AS_CASE("$target_cpu", [x64|x86_64|i[3-6]86*], [
AC_CHECK_HEADERS(x86intrin.h)
@@ -2121,6 +2122,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 85eb8920b5..c496da20a2 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"
@@ -415,6 +419,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) {