mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-24 06:01:33 +00:00
Fix call_indirect.
This commit is contained in:
@ -4,7 +4,7 @@
|
|||||||
(elem (i32.const 10) $add)
|
(elem (i32.const 10) $add)
|
||||||
|
|
||||||
(func $main (export "main") (result i32)
|
(func $main (export "main") (result i32)
|
||||||
(call_indirect (type $binop) (i32.const 42) (i32.const 1) (i32.const 9))
|
(call_indirect (type $binop) (i32.const 42) (i32.const 1) (i32.const 10))
|
||||||
)
|
)
|
||||||
(func $add (param i32) (param i32) (result i32)
|
(func $add (param i32) (param i32) (result i32)
|
||||||
(i32.add (get_local 0) (get_local 1))
|
(i32.add (get_local 0) (get_local 1))
|
||||||
|
@ -3141,25 +3141,24 @@ unsafe extern "C" fn call_indirect(
|
|||||||
if elem_index >= table.count as usize {
|
if elem_index >= table.count as usize {
|
||||||
panic!("element index out of bounds");
|
panic!("element index out of bounds");
|
||||||
}
|
}
|
||||||
let func_index = *(table.base as *mut u32).offset(elem_index as isize) as usize;
|
let anyfunc = &*(table.base as *mut vm::Anyfunc).offset(elem_index as isize);
|
||||||
let ctx: &X64ExecutionContext =
|
let ctx: &X64ExecutionContext =
|
||||||
&*CURRENT_EXECUTION_CONTEXT.with(|x| *x.borrow().last().unwrap());
|
&*CURRENT_EXECUTION_CONTEXT.with(|x| *x.borrow().last().unwrap());
|
||||||
|
|
||||||
println!(
|
let func_index = anyfunc.func_index.unwrap();
|
||||||
"SIG INDEX = {}, FUNC INDEX = {}, ELEM INDEX = {}",
|
|
||||||
sig_index, func_index, elem_index
|
|
||||||
);
|
|
||||||
|
|
||||||
// TODO: Fix table reading. Hardcoding func index = 1 for debugging here.
|
/*println!(
|
||||||
let func_index = 1usize;
|
"SIG INDEX = {}, FUNC INDEX = {:?}, ELEM INDEX = {}",
|
||||||
|
sig_index, func_index, elem_index
|
||||||
|
);*/
|
||||||
|
|
||||||
if ctx.signatures[SigIndex::new(sig_index)]
|
if ctx.signatures[SigIndex::new(sig_index)]
|
||||||
!= ctx.signatures[ctx.function_signatures[FuncIndex::new(func_index)]]
|
!= ctx.signatures[ctx.function_signatures[func_index]]
|
||||||
{
|
{
|
||||||
panic!("signature mismatch");
|
panic!("signature mismatch");
|
||||||
}
|
}
|
||||||
|
|
||||||
let func = ctx.function_pointers[func_index].0;
|
let func = ctx.function_pointers[func_index.index() as usize].0;
|
||||||
CALL_WASM(
|
CALL_WASM(
|
||||||
stack_top,
|
stack_top,
|
||||||
stack_base as usize - stack_top as usize,
|
stack_base as usize - stack_top as usize,
|
||||||
|
@ -194,7 +194,7 @@ impl LocalBacking {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
elements[init_base + i] = vm::Anyfunc { func, ctx, sig_id };
|
elements[init_base + i] = vm::Anyfunc { func, ctx, sig_id, func_index: Some(func_index) };
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -232,7 +232,12 @@ impl LocalBacking {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
elements[init_base + i] = vm::Anyfunc { func, ctx, sig_id };
|
elements[init_base + i] = vm::Anyfunc {
|
||||||
|
func,
|
||||||
|
ctx,
|
||||||
|
sig_id,
|
||||||
|
func_index: Some(func_index),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -428,7 +428,7 @@ pub struct DynFunc<'a> {
|
|||||||
pub(crate) signature: Arc<FuncSig>,
|
pub(crate) signature: Arc<FuncSig>,
|
||||||
module: &'a ModuleInner,
|
module: &'a ModuleInner,
|
||||||
pub(crate) instance_inner: &'a InstanceInner,
|
pub(crate) instance_inner: &'a InstanceInner,
|
||||||
func_index: FuncIndex,
|
pub func_index: FuncIndex,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> DynFunc<'a> {
|
impl<'a> DynFunc<'a> {
|
||||||
|
@ -110,6 +110,7 @@ impl AnyfuncTable {
|
|||||||
func: ptr,
|
func: ptr,
|
||||||
ctx: ptr::null_mut(),
|
ctx: ptr::null_mut(),
|
||||||
sig_id,
|
sig_id,
|
||||||
|
func_index: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AnyfuncInner::Managed(ref func) => {
|
AnyfuncInner::Managed(ref func) => {
|
||||||
@ -120,6 +121,7 @@ impl AnyfuncTable {
|
|||||||
func: func.raw(),
|
func: func.raw(),
|
||||||
ctx: func.instance_inner.vmctx,
|
ctx: func.instance_inner.vmctx,
|
||||||
sig_id,
|
sig_id,
|
||||||
|
func_index: Some(func.func_index),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -3,7 +3,7 @@ use crate::{
|
|||||||
memory::Memory,
|
memory::Memory,
|
||||||
module::ModuleInner,
|
module::ModuleInner,
|
||||||
structures::TypedIndex,
|
structures::TypedIndex,
|
||||||
types::{LocalOrImport, MemoryIndex},
|
types::{FuncIndex, LocalOrImport, MemoryIndex},
|
||||||
};
|
};
|
||||||
use std::{ffi::c_void, mem, ptr};
|
use std::{ffi::c_void, mem, ptr};
|
||||||
|
|
||||||
@ -283,6 +283,7 @@ pub struct Anyfunc {
|
|||||||
pub func: *const Func,
|
pub func: *const Func,
|
||||||
pub ctx: *mut Ctx,
|
pub ctx: *mut Ctx,
|
||||||
pub sig_id: SigId,
|
pub sig_id: SigId,
|
||||||
|
pub func_index: Option<FuncIndex>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Anyfunc {
|
impl Anyfunc {
|
||||||
@ -291,6 +292,7 @@ impl Anyfunc {
|
|||||||
func: ptr::null(),
|
func: ptr::null(),
|
||||||
ctx: ptr::null_mut(),
|
ctx: ptr::null_mut(),
|
||||||
sig_id: SigId(u32::max_value()),
|
sig_id: SigId(u32::max_value()),
|
||||||
|
func_index: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user