diff --git a/lib/kwasm-loader/src/lib.rs b/lib/kwasm-loader/src/lib.rs index 365013f57..cce0a9954 100644 --- a/lib/kwasm-loader/src/lib.rs +++ b/lib/kwasm-loader/src/lib.rs @@ -5,10 +5,10 @@ use wasmer_runtime_core::{ backend::RunnableModule, vm::{Ctx, LocalGlobal, SigId, Anyfunc}, module::ModuleInfo, - types::{Value, LocalMemoryIndex, LocalTableIndex, ImportedMemoryIndex, ImportedTableIndex}, + types::{Value, LocalMemoryIndex, LocalTableIndex, ImportedMemoryIndex, ImportedTableIndex, FuncIndex}, structures::TypedIndex, }; -use service::{ServiceContext, LoadProfile, RunProfile, TableEntryRequest}; +use service::{ServiceContext, LoadProfile, RunProfile, TableEntryRequest, ImportInfo}; pub struct KernelLoader; @@ -58,10 +58,16 @@ impl Loader for KernelLoader { let globals: &[*mut LocalGlobal] = ::std::slice::from_raw_parts(ctx.globals, module.globals.len()); globals.iter().map(|x| (**x).data).collect() }; - let mut import_names: Vec = vec![]; - for (_, import) in &module.imported_functions { + let mut import_names: Vec = vec![]; + for (idx, import) in &module.imported_functions { let name = format!("{}##{}", module.namespace_table.get(import.namespace_index), module.name_table.get(import.name_index)); - import_names.push(name); + let sig = module.signatures.get( + *module.func_assoc.get(FuncIndex::new(idx.index())).unwrap() + ).unwrap(); + import_names.push(ImportInfo { + name: name, + param_count: sig.params().len(), + }); } let dynamic_sigindices: &[u32] = unsafe { ::std::mem::transmute::<&[SigId], &[u32]>( diff --git a/lib/kwasm-loader/src/service.rs b/lib/kwasm-loader/src/service.rs index f169327bf..7be3370b9 100644 --- a/lib/kwasm-loader/src/service.rs +++ b/lib/kwasm-loader/src/service.rs @@ -95,6 +95,7 @@ struct WriteMemoryRequest { #[repr(C)] struct ImportRequest { name: [u8; 64], + param_count: u32, } #[repr(C)] @@ -108,11 +109,16 @@ pub struct LoadProfile<'a> { pub memory: Option<&'a [u8]>, pub memory_max: usize, pub globals: &'a [u64], - pub imports: &'a [String], + pub imports: &'a [ImportInfo], pub dynamic_sigindices: &'a [u32], pub table: Option<&'a [TableEntryRequest]>, } +pub struct ImportInfo { + pub name: String, + pub param_count: usize, +} + pub struct RunProfile<'a> { pub entry_offset: u32, pub params: &'a [u64], @@ -126,13 +132,16 @@ impl ServiceContext { pub fn new(load: LoadProfile) -> ServiceResult { let dev = File::open("/dev/wasmctl")?; let imports: Vec = load.imports.iter().map(|x| { - let mut req: ImportRequest = unsafe { ::std::mem::zeroed() }; - let x = x.as_bytes(); + let mut req = ImportRequest { + name: [0u8; 64], + param_count: x.param_count as u32, + }; + let name = x.name.as_bytes(); let mut count = req.name.len() - 1; - if x.len() < count { - count = x.len(); + if name.len() < count { + count = name.len(); } - req.name[..count].copy_from_slice(&x[..count]); + req.name[..count].copy_from_slice(&name[..count]); req }).collect(); let req = LoadCodeRequest {