mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-13 06:15:33 +00:00
Pass in param count for import functions in kernel loader.
This commit is contained in:
parent
61510f8116
commit
b343fd40bc
@ -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<String> = vec![];
|
||||
for (_, import) in &module.imported_functions {
|
||||
let mut import_names: Vec<ImportInfo> = 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]>(
|
||||
|
@ -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<ServiceContext> {
|
||||
let dev = File::open("/dev/wasmctl")?;
|
||||
let imports: Vec<ImportRequest> = 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 {
|
||||
|
Loading…
Reference in New Issue
Block a user