diff options
author | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2022-05-15 16:07:12 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-15 16:07:12 +1200 |
commit | 32de6097b2b5d8394b3a1399e13d309444697954 (patch) | |
tree | bfcad8e159c733e0ed6ae0b6e72743cd2eb0e3c7 /vm_core.h | |
parent | 48002ff1877e2fedb5d3893eec4ea633b87ea22f (diff) | |
download | ruby-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.h | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -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 |