aboutsummaryrefslogtreecommitdiffstats
path: root/vm_core.h
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2022-05-15 16:07:12 +1200
committerGitHub <noreply@github.com>2022-05-15 16:07:12 +1200
commit32de6097b2b5d8394b3a1399e13d309444697954 (patch)
treebfcad8e159c733e0ed6ae0b6e72743cd2eb0e3c7 /vm_core.h
parent48002ff1877e2fedb5d3893eec4ea633b87ea22f (diff)
downloadruby-32de6097b2b5d8394b3a1399e13d309444697954.tar.gz
Fix various autoload race conditions. (#5898)
* Add RUBY_VM_CRITICAL_SECTION for detecting unexpected context switch. * Prevent race between GC mark and autoload setup. * Protect race on autoload state. * Avoid potential race condition when allocating `autoload_featuremap`. * Add NEWS entry for autoload fixes.
Diffstat (limited to 'vm_core.h')
-rw-r--r--vm_core.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/vm_core.h b/vm_core.h
index 196b564383..cd48a3e5c5 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -56,12 +56,21 @@
#if VM_CHECK_MODE > 0
#define VM_ASSERT(expr) RUBY_ASSERT_MESG_WHEN(VM_CHECK_MODE > 0, expr, #expr)
#define VM_UNREACHABLE(func) rb_bug(#func ": unreachable")
-
+#define RUBY_VM_CRITICAL_SECTION
#else
#define VM_ASSERT(expr) ((void)0)
#define VM_UNREACHABLE(func) UNREACHABLE
#endif
+#if defined(RUBY_VM_CRITICAL_SECTION)
+extern int rb_vm_critical_section_entered;
+#define RUBY_VM_CRITICAL_SECTION_ENTER rb_vm_critical_section_entered += 1;
+#define RUBY_VM_CRITICAL_SECTION_EXIT rb_vm_critical_section_entered -= 1;
+#else
+#define RUBY_VM_CRITICAL_SECTION_ENTER
+#define RUBY_VM_CRITICAL_SECTION_EXIT
+#endif
+
#if defined(__wasm__) && !defined(__EMSCRIPTEN__)
# include "wasm/setjmp.h"
#else