Skip to content

ZJIT: Mark the code region executable on partial failures #13937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions zjit/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,29 @@ pub extern "C" fn rb_zjit_iseq_gen_entry_point(iseq: IseqPtr, _ec: EcPtr) -> *co
code_ptr
}

/// Compile an entry point for a given ISEQ
/// See [gen_iseq_entry_point_body]. This wrapper is to make sure cb.mark_all_executable()
/// is called even if gen_iseq_entry_point_body() partially fails and returns a null pointer.
fn gen_iseq_entry_point(iseq: IseqPtr) -> *const u8 {
let cb = ZJITState::get_code_block();
let code_ptr = gen_iseq_entry_point_body(cb, iseq);

// Always mark the code region executable if asm.compile() has been used.
// We need to do this even if code_ptr is null because, even if gen_entry()
// or gen_iseq() fails, gen_function() has used asm.compile().
cb.mark_all_executable();

code_ptr
}

/// Compile an entry point for a given ISEQ
fn gen_iseq_entry_point_body(cb: &mut CodeBlock, iseq: IseqPtr) -> *const u8 {
// Compile ISEQ into High-level IR
let function = match compile_iseq(iseq) {
Some(function) => function,
None => return std::ptr::null(),
};

// Compile the High-level IR
let cb = ZJITState::get_code_block();
let (start_ptr, mut branch_iseqs) = match gen_function(cb, iseq, &function) {
Some((start_ptr, gc_offsets, jit)) => {
// Remember the block address to reuse it later
Expand Down Expand Up @@ -137,9 +150,6 @@ fn gen_iseq_entry_point(iseq: IseqPtr) -> *const u8 {
}
}

// Always mark the code region executable if asm.compile() has been used
cb.mark_all_executable();

// Return a JIT code address or a null pointer
start_ptr.map(|start_ptr| start_ptr.raw_ptr(cb)).unwrap_or(std::ptr::null())
}
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy