Skip to content

Commit a5e2cbc

Browse files
committed
ZJIT: Prepare frame state before getivar calls
rb_ivar_get can raise Ractor::IsolationError for class/module ivars from non-main Ractors. Without gen_prepare_non_leaf_call, the frame state is not properly set up when the exception is raised, which can lead to crashes or incorrect behavior during exception handling.
1 parent 8b9635e commit a5e2cbc

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

zjit/src/codegen.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ fn gen_insn(cb: &mut CodeBlock, jit: &mut JITState, asm: &mut Assembler, functio
630630
Insn::CCallVariadic { cfunc, recv, name, args, cme, state, blockiseq, return_type: _, elidable: _ } => {
631631
gen_ccall_variadic(jit, asm, *cfunc, *name, opnd!(recv), opnds!(args), *cme, *blockiseq, &function.frame_state(*state))
632632
}
633-
Insn::GetIvar { self_val, id, ic, state: _ } => gen_getivar(jit, asm, opnd!(self_val), *id, *ic),
633+
Insn::GetIvar { self_val, id, ic, state } => gen_getivar(jit, asm, opnd!(self_val), *id, *ic, &function.frame_state(*state)),
634634
Insn::SetGlobal { id, val, state } => no_output!(gen_setglobal(jit, asm, *id, opnd!(val), &function.frame_state(*state))),
635635
Insn::GetGlobal { id, state } => gen_getglobal(jit, asm, *id, &function.frame_state(*state)),
636636
&Insn::IsBlockParamModified { ep } => gen_is_block_param_modified(asm, opnd!(ep)),
@@ -1107,7 +1107,9 @@ fn gen_ccall_variadic(
11071107
}
11081108

11091109
/// Emit an uncached instance variable lookup
1110-
fn gen_getivar(jit: &mut JITState, asm: &mut Assembler, recv: Opnd, id: ID, ic: *const iseq_inline_iv_cache_entry) -> Opnd {
1110+
fn gen_getivar(jit: &mut JITState, asm: &mut Assembler, recv: Opnd, id: ID, ic: *const iseq_inline_iv_cache_entry, state: &FrameState) -> Opnd {
1111+
// rb_ivar_get can raise Ractor::IsolationError for class/module ivars from non-main Ractors
1112+
gen_prepare_non_leaf_call(jit, asm, state);
11111113
if ic.is_null() {
11121114
asm_ccall!(asm, rb_ivar_get, recv, id.0.into())
11131115
} else {

0 commit comments

Comments
 (0)