[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Libjit-developers] Crashing when using jit_insn_call_indirect_vtable wi
From: |
Alexander Kellett |
Subject: |
[Libjit-developers] Crashing when using jit_insn_call_indirect_vtable with JIT_TAIL_CALL |
Date: |
Sun, 31 Oct 2004 17:39:16 +0100 |
User-agent: |
Mutt/1.5.6i |
Hey all,
Calling jit_insn_call_indirect_vtable with JIT_CALL_TAIL
(with similar signatures and params) results in a really
lovely crash.
The attached testcase crashes with --enable-interpreter
at the very least and i've been unable to find the time
to look into getting the x86 backend to work for my
current codebase.
Alex
#include <stdio.h>
#include <jit/jit.h>
#define INCREF 1
static jit_context_t *s_ctx = 0;
static void* build_function_callback_inner(jit_int value)
{
printf("build_function_callback_inner called with param %i\n", value);
jit_context_build_start(*s_ctx);
// create method signature
jit_type_t params[1];
params[0] = jit_type_int;
jit_type_t signature;
signature = jit_type_create_signature
(jit_abi_cdecl, jit_type_int, params, 1, INCREF);
// generate the function
jit_function_t function = jit_function_create(*s_ctx, signature);
// get the first param and return to the caller (runtime)
jit_value_t param = jit_value_get_param(function, 0);
jit_insn_return(function, param);
jit_dump_function(stderr, function, "build_function_callback_inner");
// compile and return pointer to function
jit_function_compile(function);
jit_context_build_end(*s_ctx);
void *func_ptr = jit_function_to_vtable_pointer(function);
printf("FUNC PTR -- %p\n", func_ptr);
return func_ptr;
}
static void* build_function_callback(jit_int value)
{
printf("build_function_callback called with param %i\n", value);
jit_context_build_start(*s_ctx);
// create method signature
jit_type_t params[1];
params[0] = jit_type_int;
jit_type_t signature;
signature = jit_type_create_signature
(jit_abi_cdecl, jit_type_int, params, 1, INCREF);
// generate the function
jit_function_t function = jit_function_create(*s_ctx, signature);
// get the first param and return to the caller (runtime)
jit_value_t param = jit_value_get_param(function, 0);
jit_value_t constant = jit_value_create_nint_constant(function,
jit_type_int, 9000);
jit_dump_function(stderr, function, "build_function_callback_inner");
// generate instructions to call the build function inner callback
// here we recieve back a jit value that during runtime will contain the
actual built function pointer to be called
jit_value_t func_ptr;
func_ptr = call_builtin(function, "build_function_callback_inner", (void
*)build_function_callback_inner,
jit_type_int, param, 0, 0, jit_type_void_ptr);
// generated the return int, pass in int signature that the method has
jit_type_t sig_gen_func;
jit_type_t sig_gen_params[1];
sig_gen_params[0] = jit_type_int;
sig_gen_func = jit_type_create_signature(jit_abi_cdecl, jit_type_int,
sig_gen_params, 1, INCREF);
// fill in the passed in values array
jit_value_t sig_gen_param_values[1];
sig_gen_param_values[0] = param;
jit_value_t return_value = jit_insn_call_indirect_vtable(function, func_ptr,
sig_gen_func, sig_gen_param_values, 1, JIT_CALL_TAIL);
// compile and return pointer to function
jit_function_compile(function);
jit_context_build_end(*s_ctx);
void *func_ptr_ptr = jit_function_to_vtable_pointer(function);
printf("FUNC PTR -- %p\n", func_ptr_ptr);
return func_ptr_ptr;
}
static jit_value_t call_builtin
(jit_function_t func, const char *name, void *native_func,
jit_type_t arg1_type, jit_value_t value1,
jit_type_t arg2_type, jit_value_t value2,
jit_type_t return_type)
{
jit_type_t signature;
jit_type_t arg_types[2];
jit_value_t args[2];
int num_args = 0;
if(arg1_type)
{
args[num_args] = jit_insn_convert(func, value1, arg1_type, 0);
if(!(args[num_args]))
{
printf("oom!");
}
arg_types[num_args] = arg1_type;
++num_args;
}
if(arg2_type)
{
args[num_args] = jit_insn_convert(func, value2, arg2_type, 0);
if(!(args[num_args]))
{
printf("oom!");
}
arg_types[num_args] = arg2_type;
++num_args;
}
signature = jit_type_create_signature
(jit_abi_cdecl, return_type, arg_types, num_args, 1);
if(!signature)
{
printf("oom!");
}
value1 = jit_insn_call_native(func, name, native_func, signature,
args, num_args, JIT_CALL_NOTHROW);
if(!value1)
{
printf("oom!");
}
jit_type_free(signature);
return value1;
}
int main() {
jit_context_t context = jit_context_create();
s_ctx = &context;
jit_context_build_start(context);
// build signature for main function returns an int, takes no params
jit_type_t params[0];
jit_type_t signature;
signature = jit_type_create_signature
(jit_abi_cdecl, jit_type_int, params, 0, INCREF);
jit_function_t function = jit_function_create(context, signature);
// build the passed in integer that will eventually be returned back to us
jit_value_t id = jit_value_create_nint_constant(function, jit_type_int,
5000);
// generate instructions to call the build function callback
// here we recieve back a jit value that during runtime will contain the
actual built function pointer to be called
jit_value_t func_ptr;
func_ptr = call_builtin(function, "build_function_callback", (void
*)build_function_callback,
jit_type_int, id, 0, 0, jit_type_void_ptr);
// generated the return int, pass in int signature that the method has
jit_type_t sig_gen_func;
jit_type_t sig_gen_params[1];
sig_gen_params[0] = jit_type_int;
sig_gen_func = jit_type_create_signature(jit_abi_cdecl, jit_type_int,
sig_gen_params, 1, INCREF);
// fill in the passed in values array
jit_value_t sig_gen_param_values[1];
sig_gen_param_values[0] = id;
jit_value_t return_value = jit_insn_call_indirect_vtable(function, func_ptr,
sig_gen_func, sig_gen_param_values, 1, 0);
// generate the code to return the given value back to the calling method
jit_insn_return(function, return_value);
// dump and compile the code
jit_dump_function(stderr, function, "main");
jit_function_compile(function);
jit_context_build_end(context);
jit_int ret;
printf("running!!!!\n");
jit_function_apply(function, 0, &ret);
printf("result :: %d!!!!\n", ret);
printf("done!!!\n");
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Libjit-developers] Crashing when using jit_insn_call_indirect_vtable with JIT_TAIL_CALL,
Alexander Kellett <=