ruby-changes:68913
From: Aaron <ko1@a...>
Date: Thu, 21 Oct 2021 08:13:09 +0900 (JST)
Subject: [ruby-changes:68913] 7efde1bfb4 (master): conditionally add libcapstone
https://git.ruby-lang.org/ruby.git/commit/?id=7efde1bfb4 From 7efde1bfb486aa7bb57f5f355a13be040a6973ff Mon Sep 17 00:00:00 2001 From: Aaron Patterson <tenderlove@r...> Date: Fri, 22 Jan 2021 11:26:20 -0800 Subject: conditionally add libcapstone --- configure.ac | 2 -- ujit.rb | 7 ++----- ujit_iface.c | 29 +++++++++++++++++------------ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/configure.ac b/configure.ac index b34004da1e..ef0aef7298 100644 --- a/configure.ac +++ b/configure.ac @@ -1234,8 +1234,6 @@ if pkg-config --exists capstone; then https://github.com/ruby/ruby/blob/trunk/configure.ac#L1234 CAPSTONE_LIB_L=`pkg-config --libs-only-L capstone` LDFLAGS="$LDFLAGS $CAPSTONE_LIB_L" CFLAGS="$CFLAGS $CAPSTONE_CFLAGS" -else - AC_MSG_ERROR(Please install capstone and pkg-config) fi AC_CHECK_LIB(capstone, cs_open) # Capstone diff --git a/ujit.rb b/ujit.rb index cdfb886795..43be881c05 100644 --- a/ujit.rb +++ b/ujit.rb @@ -1,14 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ujit.rb#L1 module UJIT - def omg - end - def self.disasm(iseq) blocks = UJIT.blocks_for(iseq) return if blocks.empty? str = "" - cs = UJIT::Disasm.open(UJIT::Disasm::ARCH_X86, UJIT::Disasm::MODE_64) + cs = UJIT::Disasm.new str << iseq.disasm str << "\n" @@ -27,5 +24,5 @@ module UJIT https://github.com/ruby/ruby/blob/trunk/ujit.rb#L24 end end str - end + end if defined?(Disasm) end diff --git a/ujit_iface.c b/ujit_iface.c index 349aa40b1b..91d3621b43 100644 --- a/ujit_iface.c +++ b/ujit_iface.c @@ -14,7 +14,10 @@ https://github.com/ruby/ruby/blob/trunk/ujit_iface.c#L14 #include "ujit_core.h" #include "ujit_hooks.inc" #include "ujit.rbinc" + +#if HAVE_LIBCAPSTONE #include <capstone/capstone.h> +#endif VALUE cUjitBlock; VALUE cUjitDisasm; @@ -29,12 +32,6 @@ static const rb_data_type_t ujit_block_type = { https://github.com/ruby/ruby/blob/trunk/ujit_iface.c#L32 0, 0, RUBY_TYPED_FREE_IMMEDIATELY }; -static const rb_data_type_t ujit_disasm_type = { - "UJIT/Disasm", - {0, (void(*)(void *))cs_close, 0, }, - 0, 0, RUBY_TYPED_FREE_IMMEDIATELY -}; - bool rb_ujit_enabled; // Hash table of encoded instructions @@ -376,12 +373,19 @@ iseq_end_index(VALUE self) https://github.com/ruby/ruby/blob/trunk/ujit_iface.c#L373 return INT2NUM(block->end_idx); } +#if HAVE_LIBCAPSTONE +static const rb_data_type_t ujit_disasm_type = { + "UJIT/Disasm", + {0, (void(*)(void *))cs_close, 0, }, + 0, 0, RUBY_TYPED_FREE_IMMEDIATELY +}; + static VALUE -ujit_disasm_open(VALUE mod, VALUE arch, VALUE mode) +ujit_disasm_init(VALUE klass) { csh * handle; - VALUE disasm = TypedData_Make_Struct(cUjitDisasm, csh, &ujit_disasm_type, handle); - cs_open(NUM2INT(arch), NUM2INT(mode), handle); + VALUE disasm = TypedData_Make_Struct(klass, csh, &ujit_disasm_type, handle); + cs_open(CS_ARCH_X86, CS_MODE_64, handle); return disasm; } @@ -405,6 +409,7 @@ ujit_disasm(VALUE self, VALUE code, VALUE from) https://github.com/ruby/ruby/blob/trunk/ujit_iface.c#L409 cs_free(insns, count); return insn_list; } +#endif void rb_ujit_init(void) @@ -429,13 +434,13 @@ rb_ujit_init(void) https://github.com/ruby/ruby/blob/trunk/ujit_iface.c#L434 rb_define_method(cUjitBlock, "iseq_start_index", iseq_start_index, 0); rb_define_method(cUjitBlock, "iseq_end_index", iseq_end_index, 0); +#if HAVE_LIBCAPSTONE cUjitDisasm = rb_define_class_under(mUjit, "Disasm", rb_cObject); - rb_define_const(cUjitDisasm, "ARCH_X86", INT2NUM(CS_ARCH_X86)); - rb_define_const(cUjitDisasm, "MODE_64", INT2NUM(CS_MODE_64)); - rb_define_module_function(cUjitDisasm, "open", ujit_disasm_open, 2); + rb_define_alloc_func(cUjitDisasm, ujit_disasm_init); rb_define_method(cUjitDisasm, "disasm", ujit_disasm, 2); cUjitDisasmInsn = rb_struct_define_under(cUjitDisasm, "Insn", "address", "mnemonic", "op_str", NULL); +#endif // Initialize the GC hooks method_lookup_dependency = st_init_numtable(); -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/