From b9332ac8e7126066ac4238443d63eaa4c06789f9 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Sat, 24 Dec 2022 01:13:40 -0800 Subject: MJIT: Cancel all on disastrous situations (#7019) I noticed this while running test_yjit with --mjit-call-threshold=1, which redefines `Integer#<`. When Ruby is monkey-patched, MJIT itself could be broken. Similarly, Ruby scripts could break MJIT in many different ways. I prepared the same set of hooks as YJIT so that we could possibly override it and disable it on those moments. Every constant under RubyVM::MJIT is private and thus it's an unsupported behavior though. --- mjit_c.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'mjit_c.rb') diff --git a/mjit_c.rb b/mjit_c.rb index d0d4ef168c..905de6139a 100644 --- a/mjit_c.rb +++ b/mjit_c.rb @@ -109,6 +109,13 @@ module RubyVM::MJIT # :nodoc: all } end + def mjit_cancel_all(reason) + Primitive.cstmt! %{ + mjit_cancel_all(RSTRING_PTR(reason)); + return Qnil; + } + end + # Convert encoded VM pointers to insn BINs. def rb_vm_insn_decode(encoded) Primitive.cexpr! 'INT2NUM(rb_vm_insn_decode(NUM2PTR(encoded)))' @@ -170,6 +177,10 @@ module RubyVM::MJIT # :nodoc: all Primitive.cexpr! %q{ INT2NUM(VM_METHOD_TYPE_ISEQ) } end + def C.RUBY_EVENT_CLASS + Primitive.cexpr! %q{ UINT2NUM(RUBY_EVENT_CLASS) } + end + def C.SHAPE_CAPACITY_CHANGE Primitive.cexpr! %q{ UINT2NUM(SHAPE_CAPACITY_CHANGE) } end -- cgit v1.2.3