mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-13 22:25:40 +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,
|
backend::RunnableModule,
|
||||||
vm::{Ctx, LocalGlobal, SigId, Anyfunc},
|
vm::{Ctx, LocalGlobal, SigId, Anyfunc},
|
||||||
module::ModuleInfo,
|
module::ModuleInfo,
|
||||||
types::{Value, LocalMemoryIndex, LocalTableIndex, ImportedMemoryIndex, ImportedTableIndex},
|
types::{Value, LocalMemoryIndex, LocalTableIndex, ImportedMemoryIndex, ImportedTableIndex, FuncIndex},
|
||||||
structures::TypedIndex,
|
structures::TypedIndex,
|
||||||
};
|
};
|
||||||
use service::{ServiceContext, LoadProfile, RunProfile, TableEntryRequest};
|
use service::{ServiceContext, LoadProfile, RunProfile, TableEntryRequest, ImportInfo};
|
||||||
|
|
||||||
pub struct KernelLoader;
|
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());
|
let globals: &[*mut LocalGlobal] = ::std::slice::from_raw_parts(ctx.globals, module.globals.len());
|
||||||
globals.iter().map(|x| (**x).data).collect()
|
globals.iter().map(|x| (**x).data).collect()
|
||||||
};
|
};
|
||||||
let mut import_names: Vec<String> = vec![];
|
let mut import_names: Vec<ImportInfo> = vec![];
|
||||||
for (_, import) in &module.imported_functions {
|
for (idx, import) in &module.imported_functions {
|
||||||
let name = format!("{}##{}", module.namespace_table.get(import.namespace_index), module.name_table.get(import.name_index));
|
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 {
|
let dynamic_sigindices: &[u32] = unsafe {
|
||||||
::std::mem::transmute::<&[SigId], &[u32]>(
|
::std::mem::transmute::<&[SigId], &[u32]>(
|
||||||
|
@ -95,6 +95,7 @@ struct WriteMemoryRequest {
|
|||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
struct ImportRequest {
|
struct ImportRequest {
|
||||||
name: [u8; 64],
|
name: [u8; 64],
|
||||||
|
param_count: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
@ -108,11 +109,16 @@ pub struct LoadProfile<'a> {
|
|||||||
pub memory: Option<&'a [u8]>,
|
pub memory: Option<&'a [u8]>,
|
||||||
pub memory_max: usize,
|
pub memory_max: usize,
|
||||||
pub globals: &'a [u64],
|
pub globals: &'a [u64],
|
||||||
pub imports: &'a [String],
|
pub imports: &'a [ImportInfo],
|
||||||
pub dynamic_sigindices: &'a [u32],
|
pub dynamic_sigindices: &'a [u32],
|
||||||
pub table: Option<&'a [TableEntryRequest]>,
|
pub table: Option<&'a [TableEntryRequest]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct ImportInfo {
|
||||||
|
pub name: String,
|
||||||
|
pub param_count: usize,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct RunProfile<'a> {
|
pub struct RunProfile<'a> {
|
||||||
pub entry_offset: u32,
|
pub entry_offset: u32,
|
||||||
pub params: &'a [u64],
|
pub params: &'a [u64],
|
||||||
@ -126,13 +132,16 @@ impl ServiceContext {
|
|||||||
pub fn new(load: LoadProfile) -> ServiceResult<ServiceContext> {
|
pub fn new(load: LoadProfile) -> ServiceResult<ServiceContext> {
|
||||||
let dev = File::open("/dev/wasmctl")?;
|
let dev = File::open("/dev/wasmctl")?;
|
||||||
let imports: Vec<ImportRequest> = load.imports.iter().map(|x| {
|
let imports: Vec<ImportRequest> = load.imports.iter().map(|x| {
|
||||||
let mut req: ImportRequest = unsafe { ::std::mem::zeroed() };
|
let mut req = ImportRequest {
|
||||||
let x = x.as_bytes();
|
name: [0u8; 64],
|
||||||
|
param_count: x.param_count as u32,
|
||||||
|
};
|
||||||
|
let name = x.name.as_bytes();
|
||||||
let mut count = req.name.len() - 1;
|
let mut count = req.name.len() - 1;
|
||||||
if x.len() < count {
|
if name.len() < count {
|
||||||
count = x.len();
|
count = name.len();
|
||||||
}
|
}
|
||||||
req.name[..count].copy_from_slice(&x[..count]);
|
req.name[..count].copy_from_slice(&name[..count]);
|
||||||
req
|
req
|
||||||
}).collect();
|
}).collect();
|
||||||
let req = LoadCodeRequest {
|
let req = LoadCodeRequest {
|
||||||
|
Loading…
Reference in New Issue
Block a user