Skip to content

Commit

Permalink
Add support for Ruby 3.2.2
Browse files Browse the repository at this point in the history
Signed-off-by: Francisco Javier Honduvilla Coto <javierhonduco@gmail.com>
  • Loading branch information
javierhonduco committed Aug 20, 2023
1 parent 704f7cc commit fc31fb4
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ruby_versions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ pub const ruby_version_configs_yaml: &[&str] = &[
include_str!("ruby_3_1_3.yaml"),
include_str!("ruby_3_2_0.yaml"),
include_str!("ruby_3_2_1.yaml"),
include_str!("ruby_3_2_2.yaml"),
];
14 changes: 14 additions & 0 deletions src/ruby_versions/ruby_3_2_2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
major_version: 3
minor_version: 2
patch_version: 2
vm_offset: 0
vm_size_offset: 8
control_frame_t_sizeof: 64
cfp_offset: 16
label_offset: 16
path_flavour: 1
line_info_size_offset: 128
line_info_table_offset: 112
lineno_offset: 0
main_thread_offset: 32
ec_offset: 520
77 changes: 77 additions & 0 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,82 @@ fn dump_ruby_structs_ruby_3_2_1() {
.unwrap();
}

fn dump_ruby_structs_ruby_3_2_2() {
let vm_offset: i32 = offset_of!(
rbspy_ruby_structs::ruby_3_2_0::rb_execution_context_struct,
vm_stack
) as i32;

let vm_size_offset: i32 = offset_of!(
rbspy_ruby_structs::ruby_3_2_0::rb_execution_context_struct,
vm_stack_size
) as i32;

let control_frame_t_sizeof: i32 =
size_of::<rbspy_ruby_structs::ruby_3_2_0::rb_control_frame_struct>() as i32;

let cfp_offset: i32 = offset_of!(
rbspy_ruby_structs::ruby_3_2_0::rb_execution_context_struct,
cfp
) as i32;

let label_offset: i32 = offset_of!(
rbspy_ruby_structs::ruby_3_2_0::rb_iseq_location_struct,
label
) as i32;

let line_info_table_offset: i32 = offset_of!(
rbspy_ruby_structs::ruby_3_2_0::rb_iseq_constant_body,
insns_info
) as i32;

let line_info_size_offset: i32 = line_info_table_offset
+ (offset_of!(
rbspy_ruby_structs::ruby_3_2_0::rb_iseq_constant_body_iseq_insn_info,
size
) as i32);

let main_thread_offset: i32 = offset_of!(
rbspy_ruby_structs::ruby_3_2_0::rb_vm_struct__bindgen_ty_1,
main_thread
) as i32;

let ruby_3_2_2_offsets = RubyVersionOffsets {
major_version: 3,
minor_version: 2,
patch_version: 2,
vm_offset,
vm_size_offset,
control_frame_t_sizeof,
cfp_offset,
label_offset,
path_flavour: 1,
line_info_size_offset,
line_info_table_offset,
lineno_offset: 0,
main_thread_offset,
// we want: ruby_current_vm_ptr->ractor->main_thread->ractor(->threads)->running_ec
// we have: ruby_current_vm_ptr->ractor->main_thread

// .ractor
// (gdb) p/d offsetof(struct rb_thread_struct, ractor)
// $15 = 24

// .running_ec
// /* hole */ /* hole */
// (gdb) p/d sizeof(struct rb_ractor_pub) + sizeof(struct rb_ractor_sync) + sizeof(VALUE) + sizeof(_Bool) + 7 + sizeof(rb_nativethread_cond_t) + sizeof(struct list_head) + sizeof(unsigned int) *3 + 4 + sizeof(rb_global_vm_lock_t)
// $16 = 520
ec_offset: 520,
};

let yaml = serde_yaml::to_string(&ruby_3_2_2_offsets).unwrap();

File::create("src/ruby_versions/ruby_3_2_2.yaml")
.unwrap()
.write_all(yaml.as_bytes())
.unwrap();
}

fn main() {
dump_ruby_structs_ruby_2_6_0();
dump_ruby_structs_ruby_2_6_3();
Expand All @@ -844,4 +920,5 @@ fn main() {
dump_ruby_structs_ruby_3_1_3();
dump_ruby_structs_ruby_3_2_0();
dump_ruby_structs_ruby_3_2_1();
dump_ruby_structs_ruby_3_2_2();
}

0 comments on commit fc31fb4

Please sign in to comment.