1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

conditionally add libcapstone

This commit is contained in:
Aaron Patterson 2021-01-22 11:26:20 -08:00 committed by Alan Wu
parent e427fdff0a
commit 7efde1bfb4
3 changed files with 19 additions and 19 deletions

View file

@ -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

View file

@ -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

View file

@ -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();