diff options
author | Aaron Patterson <tenderlove@ruby-lang.org> | 2021-01-22 11:26:20 -0800 |
---|---|---|
committer | Alan Wu <XrXr@users.noreply.github.com> | 2021-10-20 18:19:27 -0400 |
commit | 7efde1bfb486aa7bb57f5f355a13be040a6973ff (patch) | |
tree | 66a89e9a960e3ca22196d7eccfdb744baf6a7c26 | |
parent | e427fdff0af907faec8771b98e9cabeaadd05f12 (diff) |
conditionally add libcapstone
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | ujit.rb | 7 | ||||
-rw-r--r-- | 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 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 @@ -1,14 +1,11 @@ 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 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 @@ #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 = { 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) 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) cs_free(insns, count); return insn_list; } +#endif void rb_ujit_init(void) @@ -429,13 +434,13 @@ rb_ujit_init(void) 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(); |