diff options
| author | Alan Wu <XrXr@users.noreply.github.com> | 2025-12-03 16:03:23 -0500 |
|---|---|---|
| committer | Alan Wu <XrXr@users.noreply.github.com> | 2025-12-05 15:49:25 -0500 |
| commit | 109ddd291ebc4f07f786e7b4ed277b20e3faaa8a (patch) | |
| tree | aa297a3db3f224aefc302a21c0da3e5ab5b089ad | |
| parent | 8132b3d1d8abbe38810a1e268c59b6d49e46d9a1 (diff) | |
ZJIT: Avoid binding to `rb_iseq_constant_body`
Its definition changes depending on e.g. whether there is YJIT in the
build.
| -rw-r--r-- | zjit.c | 4 | ||||
| -rw-r--r-- | zjit/bindgen/src/main.rs | 2 | ||||
| -rw-r--r-- | zjit/src/cruby.rs | 13 | ||||
| -rw-r--r-- | zjit/src/cruby_bindings.inc.rs | 36 |
4 files changed, 20 insertions, 35 deletions
@@ -31,6 +31,10 @@ #include <errno.h> +enum zjit_struct_offsets { + ISEQ_BODY_OFFSET_PARAM = offsetof(struct rb_iseq_constant_body, param) +}; + #define PTR2NUM(x) (rb_int2inum((intptr_t)(void *)(x))) // For a given raw_sample (frame), set the hash with the caller's diff --git a/zjit/bindgen/src/main.rs b/zjit/bindgen/src/main.rs index e07953ffd5..30e8514974 100644 --- a/zjit/bindgen/src/main.rs +++ b/zjit/bindgen/src/main.rs @@ -301,6 +301,7 @@ fn main() { .allowlist_function("rb_zjit_defined_ivar") .allowlist_function("rb_zjit_insn_leaf") .allowlist_type("jit_bindgen_constants") + .allowlist_type("zjit_struct_offsets") .allowlist_function("rb_assert_holding_vm_lock") .allowlist_function("rb_jit_shape_too_complex_p") .allowlist_function("rb_jit_multi_ractor_p") @@ -428,6 +429,7 @@ fn main() { // We define these manually, don't import them .blocklist_type("VALUE") .blocklist_type("ID") + .blocklist_type("rb_iseq_constant_body") // Avoid binding to stuff we don't use .blocklist_item("rb_thread_struct.*") diff --git a/zjit/src/cruby.rs b/zjit/src/cruby.rs index b255c28e52..e653602874 100644 --- a/zjit/src/cruby.rs +++ b/zjit/src/cruby.rs @@ -231,6 +231,16 @@ pub fn insn_len(opcode: usize) -> u32 { } } +/// We avoid using bindgen for `rb_iseq_constant_body` since its definition changes depending +/// on build configuration while we need one bindgen file that works for all configurations. +/// Use an opaque type for it instead. +/// See: <https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs> +#[repr(C)] +pub struct rb_iseq_constant_body { + _data: [u8; 0], + _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>, +} + /// An object handle similar to VALUE in the C code. Our methods assume /// that this is a handle. Sometimes the C code briefly uses VALUE as /// an unsigned integer type and don't necessarily store valid handles but @@ -683,7 +693,8 @@ pub trait IseqAccess { impl IseqAccess for IseqPtr { /// Get a description of the ISEQ's signature. Analogous to `ISEQ_BODY(iseq)->param` in C. unsafe fn params<'a>(self) -> &'a IseqParameters { - unsafe { &(*(*self).body).param } + use crate::cast::IntoUsize; + unsafe { &*((*self).body.byte_add(ISEQ_BODY_OFFSET_PARAM.to_usize()) as *const IseqParameters) } } } diff --git a/zjit/src/cruby_bindings.inc.rs b/zjit/src/cruby_bindings.inc.rs index a80f3d83c5..aed35c3c63 100644 --- a/zjit/src/cruby_bindings.inc.rs +++ b/zjit/src/cruby_bindings.inc.rs @@ -595,40 +595,6 @@ pub type rb_jit_func_t = ::std::option::Option< ) -> VALUE, >; #[repr(C)] -pub struct rb_iseq_constant_body { - pub type_: rb_iseq_type, - pub iseq_size: ::std::os::raw::c_uint, - pub iseq_encoded: *mut VALUE, - pub param: rb_iseq_constant_body_rb_iseq_parameters, - pub location: rb_iseq_location_t, - pub insns_info: rb_iseq_constant_body_iseq_insn_info, - pub local_table: *const ID, - pub lvar_states: *mut rb_iseq_constant_body_lvar_state, - pub catch_table: *mut iseq_catch_table, - pub parent_iseq: *const rb_iseq_struct, - pub local_iseq: *mut rb_iseq_struct, - pub is_entries: *mut iseq_inline_storage_entry, - pub call_data: *mut rb_call_data, - pub variable: rb_iseq_constant_body__bindgen_ty_1, - pub local_table_size: ::std::os::raw::c_uint, - pub ic_size: ::std::os::raw::c_uint, - pub ise_size: ::std::os::raw::c_uint, - pub ivc_size: ::std::os::raw::c_uint, - pub icvarc_size: ::std::os::raw::c_uint, - pub ci_size: ::std::os::raw::c_uint, - pub stack_max: ::std::os::raw::c_uint, - pub builtin_attrs: ::std::os::raw::c_uint, - pub prism: bool, - pub mark_bits: rb_iseq_constant_body__bindgen_ty_2, - pub outer_variables: *mut rb_id_table, - pub mandatory_only_iseq: *const rb_iseq_t, - pub jit_entry: rb_jit_func_t, - pub jit_entry_calls: ::std::os::raw::c_ulong, - pub jit_exception: rb_jit_func_t, - pub jit_exception_calls: ::std::os::raw::c_ulong, - pub zjit_payload: *mut ::std::os::raw::c_void, -} -#[repr(C)] #[derive(Debug, Copy, Clone)] pub struct rb_iseq_constant_body_rb_iseq_parameters { pub flags: rb_iseq_constant_body_rb_iseq_parameters__bindgen_ty_1, @@ -1866,6 +1832,8 @@ pub const DEFINED_REF: defined_type = 15; pub const DEFINED_FUNC: defined_type = 16; pub const DEFINED_CONST_FROM: defined_type = 17; pub type defined_type = u32; +pub const ISEQ_BODY_OFFSET_PARAM: zjit_struct_offsets = 16; +pub type zjit_struct_offsets = u32; pub const ROBJECT_OFFSET_AS_HEAP_FIELDS: jit_bindgen_constants = 16; pub const ROBJECT_OFFSET_AS_ARY: jit_bindgen_constants = 16; pub const RUBY_OFFSET_RSTRING_LEN: jit_bindgen_constants = 16; |
