diff options
author | Alan Wu <XrXr@users.noreply.github.com> | 2023-03-21 14:24:17 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-21 14:24:17 -0400 |
commit | aa54082d70d06bf2dd0d535bb06287b80bb2727f (patch) | |
tree | 3f26870fb0a29b5fa7e31b15fb1206c1db8ef26c /yjit/src/invariants.rs | |
parent | 5de26bc0319d8b0de315cb90e68345a816673fa6 (diff) | |
download | ruby-aa54082d70d06bf2dd0d535bb06287b80bb2727f.tar.gz |
YJIT: Fix large ISeq rejection (#7576)
We crashed in some edge cases due to the recent change to not compile
encoded iseqs that are larger than `u16::MAX`.
- Match the C signature of rb_yjit_constant_ic_update() and clamp down
to `IseqIdx` size
- Return failure instead of panicking with `unwrap()` in codegen when
the iseq is too large
Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
Co-authored-by: Noah Gibbs <noah.gibbs@shopify.com>
Diffstat (limited to 'yjit/src/invariants.rs')
-rw-r--r-- | yjit/src/invariants.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/yjit/src/invariants.rs b/yjit/src/invariants.rs index 5156ca6a26..c93213b484 100644 --- a/yjit/src/invariants.rs +++ b/yjit/src/invariants.rs @@ -389,12 +389,21 @@ pub fn block_assumptions_free(blockref: BlockRef) { /// Invalidate the block for the matching opt_getinlinecache so it could regenerate code /// using the new value in the constant cache. #[no_mangle] -pub extern "C" fn rb_yjit_constant_ic_update(iseq: *const rb_iseq_t, ic: IC, insn_idx: u16) { +pub extern "C" fn rb_yjit_constant_ic_update(iseq: *const rb_iseq_t, ic: IC, insn_idx: std::os::raw::c_uint) { // If YJIT isn't enabled, do nothing if !yjit_enabled_p() { return; } + // Try to downcast the iseq index + let insn_idx: IseqIdx = if let Ok(idx) = insn_idx.try_into() { + idx + } else { + // The index is too large, YJIT can't possibily have code for it, + // so there is nothing to invalidate. + return; + }; + if !unsafe { (*(*ic).entry).ic_cref }.is_null() || unsafe { rb_yjit_multi_ractor_p() } { // We can't generate code in these situations, so no need to invalidate. // See gen_opt_getinlinecache. |