Avoid crashing at a random ISEQ access

[Feature #19420]
This commit is contained in:
Takashi Kokubun 2023-03-05 22:09:57 -08:00
Родитель d6814fa24f
Коммит 22d944c8b7
2 изменённых файлов: 6 добавлений и 1 удалений

Просмотреть файл

@ -83,7 +83,7 @@ module RubyVM::MJIT
def compile_branch_stub(ctx, asm, branch_stub, target0_p)
# Call rb_mjit_branch_stub_hit
iseq = branch_stub.iseq
if C.imemo_type(iseq) != C.imemo_iseq # Guard against ISEQ GC at random moments
if C.mjit_opts.dump_disasm && C.imemo_type(iseq) == C.imemo_iseq # Guard against ISEQ GC at random moments
asm.comment("branch stub hit: #{iseq.body.location.label}@#{C.rb_iseq_path(iseq)}:#{iseq_lineno(iseq, target0_p ? branch_stub.target0.pc : branch_stub.target1.pc)}")
end
asm.mov(:rdi, to_value(branch_stub))

5
mjit.c
Просмотреть файл

@ -310,7 +310,11 @@ rb_mjit_collect_vm_usage_insn(int insn)
#endif // YJIT_STATS
extern VALUE rb_gc_enable(void);
extern VALUE rb_gc_disable(void);
#define WITH_MJIT_ISOLATED(stmt) do { \
VALUE was_disabled = rb_gc_disable(); \
rb_hook_list_t *global_hooks = rb_ec_ractor_hooks(GET_EC()); \
rb_mjit_global_events = global_hooks->events; \
global_hooks->events = 0; \
@ -321,6 +325,7 @@ rb_mjit_collect_vm_usage_insn(int insn)
mjit_call_p = (mjit_cancel_p ? false : original_call_p); \
mjit_stats_p = mjit_opts.stats; \
global_hooks->events = rb_mjit_global_events; \
if (!was_disabled) rb_gc_enable(); \
} while (0);
void