diff --git a/lib/kwasm-loader/src/lib.rs b/lib/kwasm-loader/src/lib.rs index cce0a9954..3e98175db 100644 --- a/lib/kwasm-loader/src/lib.rs +++ b/lib/kwasm-loader/src/lib.rs @@ -74,6 +74,9 @@ impl Loader for KernelLoader { ::std::slice::from_raw_parts(ctx.dynamic_sigindices, full_ctx.dynamic_sigindice_count()) ) }; + let local_param_counts: Vec = (module.imported_functions.len()..module.func_assoc.len()) + .map(|x| module.signatures.get(*module.func_assoc.get(FuncIndex::new(x)).unwrap()).unwrap().params().len()) + .collect(); let profile = LoadProfile { code: code, memory: memory, @@ -87,6 +90,7 @@ impl Loader for KernelLoader { Ok(KernelInstance { context: sc, offsets: rm.get_offsets().unwrap(), + param_counts: local_param_counts, }) } } @@ -94,11 +98,15 @@ impl Loader for KernelLoader { pub struct KernelInstance { context: ServiceContext, offsets: Vec, + param_counts: Vec, // FIXME: Full signature check } impl Instance for KernelInstance { type Error = String; fn call(&mut self, id: usize, args: &[Value]) -> Result { + if args.len() != self.param_counts[id] { + return Err("param count mismatch".into()); + } let args: Vec = args.iter().map(|x| x.to_u64()).collect(); let ret = self.context.run_code(RunProfile {