Skip to content

Commit c3c954d

Browse files
committed
ZJIT: More recognizable JIT return poison, assert only when RUBY_DEBUG
A good poison value gives a recognizable fault address if someone erroneously dereferences. Asserting the pointer is not poison shouldn't be necessary, so move it to RUBY_DEBUG builds.
1 parent c919778 commit c3c954d

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

zjit.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,8 @@ static inline void rb_zjit_jit_frame_update_references(zjit_jit_frame_t *jit_fra
6666

6767
#define rb_zjit_enabled_p (rb_zjit_entry != 0)
6868

69-
enum zjit_poison_values {
70-
// Poison value used on frame push when runtime checks are enabled
71-
ZJIT_JIT_RETURN_POISON = 2,
72-
};
69+
// BADFrame. The high bit is set, so likely SEGV on linux and darwin if dereferenced.
70+
#define ZJIT_JIT_RETURN_POISON 0xbadfbadfbadfbadfULL
7371

7472
// Return the JITFrame pointer from cfp->jit_return, or NULL if not present.
7573
// YJIT also uses jit_return (as a return address), so this must only return
@@ -79,7 +77,7 @@ CFP_ZJIT_FRAME(const rb_control_frame_t *cfp)
7977
{
8078
if (!rb_zjit_enabled_p) return NULL;
8179
#if USE_ZJIT
82-
RUBY_ASSERT_ALWAYS(cfp->jit_return != (void *)ZJIT_JIT_RETURN_POISON);
80+
RUBY_ASSERT((unsigned long long)cfp->jit_return != ZJIT_JIT_RETURN_POISON);
8381
#endif
8482
return cfp->jit_return;
8583
}

zjit/bindgen/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ fn main() {
313313
.allowlist_function("rb_zjit_insn_leaf")
314314
.allowlist_type("jit_bindgen_constants")
315315
.allowlist_type("zjit_struct_offsets")
316-
.allowlist_type("zjit_poison_values")
316+
.allowlist_var("ZJIT_JIT_RETURN_POISON")
317317
.allowlist_function("rb_assert_holding_vm_lock")
318318
.allowlist_function("rb_jit_shape_too_complex_p")
319319
.allowlist_function("rb_jit_multi_ractor_p")

zjit/src/cruby_bindings.inc.rs

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)