Skip to content

Commit

Permalink
YJIT: Call mprotect after entry stub failure
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Oct 3, 2023
1 parent 492e943 commit 71ac83a
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions yjit/src/core.rs
Expand Up @@ -2283,7 +2283,7 @@ fn entry_stub_hit_body(entry_ptr: *const c_void, ec: EcPtr) -> Option<*const u8>
let pending_entry = gen_entry_chain_guard(&mut asm, ocb, iseq, insn_idx)?;
asm.compile(cb, Some(ocb));

// Try to find an existing compiled version of this block
// Find or compile a block version
let blockid = BlockId { iseq, idx: insn_idx };
let mut ctx = Context::default();
ctx.stack_size = stack_size;
Expand All @@ -2293,33 +2293,31 @@ fn entry_stub_hit_body(entry_ptr: *const c_void, ec: EcPtr) -> Option<*const u8>
let mut asm = Assembler::new();
asm.jmp(unsafe { blockref.as_ref() }.start_addr.into());
asm.compile(cb, Some(ocb));
blockref
Some(blockref)
}
// If this block hasn't yet been compiled, generate blocks after the entry guard.
None => match gen_block_series(blockid, &ctx, ec, cb, ocb) {
Some(blockref) => blockref,
None => { // No space
// Trigger code GC. This entry point will be recompiled later.
cb.code_gc(ocb);
return None;
}
}
None => gen_block_series(blockid, &ctx, ec, cb, ocb),
};

// Regenerate the previous entry
assert!(!entry_ptr.is_null());
let entryref = NonNull::<Entry>::new(entry_ptr as *mut Entry).expect("Entry should not be null");
regenerate_entry(cb, &entryref, next_entry);
if blockref.is_some() {
// Regenerate the previous entry
assert!(!entry_ptr.is_null());
let entryref = NonNull::<Entry>::new(entry_ptr as *mut Entry).expect("Entry should not be null");
regenerate_entry(cb, &entryref, next_entry);

// Write an entry to the heap and push it to the ISEQ
let pending_entry = Rc::try_unwrap(pending_entry).ok().expect("PendingEntry should be unique");
get_or_create_iseq_payload(iseq).entries.push(pending_entry.into_entry());
// Write an entry to the heap and push it to the ISEQ
let pending_entry = Rc::try_unwrap(pending_entry).ok().expect("PendingEntry should be unique");
get_or_create_iseq_payload(iseq).entries.push(pending_entry.into_entry());
} else {
// Trigger code GC. This entry point will be recompiled later.
cb.code_gc(ocb);
}

cb.mark_all_executable();
ocb.unwrap().mark_all_executable();

// Let the stub jump to the block
Some(unsafe { blockref.as_ref() }.start_addr.raw_ptr())
blockref.map(|block| unsafe { block.as_ref() }.start_addr.raw_ptr())
}

/// Generate a stub that calls entry_stub_hit
Expand Down

0 comments on commit 71ac83a

Please sign in to comment.