Fix function offset.

This commit is contained in:
Heyang Zhou
2019-05-07 08:25:46 -07:00
parent 0895dc60c2
commit 0bbd6e6970
3 changed files with 5 additions and 11 deletions

View File

@ -74,7 +74,7 @@ impl Loader for KernelLoader {
::std::slice::from_raw_parts(ctx.dynamic_sigindices, full_ctx.dynamic_sigindice_count()) ::std::slice::from_raw_parts(ctx.dynamic_sigindices, full_ctx.dynamic_sigindice_count())
) )
}; };
let local_param_counts: Vec<usize> = (module.imported_functions.len()..module.func_assoc.len()) let param_counts: Vec<usize> = (0..module.func_assoc.len())
.map(|x| module.signatures.get(*module.func_assoc.get(FuncIndex::new(x)).unwrap()).unwrap().params().len()) .map(|x| module.signatures.get(*module.func_assoc.get(FuncIndex::new(x)).unwrap()).unwrap().params().len())
.collect(); .collect();
let profile = LoadProfile { let profile = LoadProfile {
@ -90,7 +90,7 @@ impl Loader for KernelLoader {
Ok(KernelInstance { Ok(KernelInstance {
context: sc, context: sc,
offsets: rm.get_offsets().unwrap(), offsets: rm.get_offsets().unwrap(),
param_counts: local_param_counts, param_counts: param_counts,
}) })
} }
} }

View File

@ -220,7 +220,7 @@ impl Instance {
} }
} }
pub fn resolve_local_func(&self, name: &str) -> ResolveResult<usize> { pub fn resolve_func(&self, name: &str) -> ResolveResult<usize> {
let export_index = let export_index =
self.module self.module
.info .info
@ -231,13 +231,7 @@ impl Instance {
})?; })?;
if let ExportIndex::Func(func_index) = export_index { if let ExportIndex::Func(func_index) = export_index {
match func_index.local_or_import(&self.module.info) { Ok(func_index.index())
LocalOrImport::Local(x) => Ok(x.index()),
LocalOrImport::Import(x) => Err(ResolveError::ExportWrongType {
name: name.to_string(),
}
.into())
}
} else { } else {
Err(ResolveError::ExportWrongType { Err(ResolveError::ExportWrongType {
name: name.to_string(), name: name.to_string(),

View File

@ -84,7 +84,7 @@ fn handle_client(mut stream: UnixStream) {
args.push(Value::I64(stream.read_u64::<LittleEndian>().unwrap() as _)); args.push(Value::I64(stream.read_u64::<LittleEndian>().unwrap() as _));
} }
let index = instance.resolve_local_func(func_name).unwrap(); let index = instance.resolve_func(func_name).unwrap();
let ret = ins.call(index, &args); let ret = ins.call(index, &args);
match ret { match ret {
Ok(x) => { Ok(x) => {