mirror of
https://github.com/fluencelabs/marine.git
synced 2024-12-12 14:55:32 +00:00
apply new module creation scheme
This commit is contained in:
parent
dd001db7ad
commit
39c9aaa703
@ -28,8 +28,11 @@ use wasmer_runtime::Func;
|
||||
/// 4. read a result from the res by reading 4 bytes as little-endian result_size
|
||||
/// and the read result_size bytes as the final result.
|
||||
/// 5. deallocate(res, strlen(sql)) to clean memory.
|
||||
|
||||
pub(crate) trait ModuleABI<'a> {}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct ModuleABI<'a> {
|
||||
pub(crate) struct ABI<'a> {
|
||||
// It is safe to use unwrap() while calling these functions because Option is used here
|
||||
// just to allow partially initialization. And all Option fields will contain Some if
|
||||
// invoking FCE::new has been succeed.
|
||||
|
@ -17,18 +17,18 @@
|
||||
use crate::vm::config::Config;
|
||||
use crate::vm::errors::FCEError;
|
||||
use crate::vm::module::fce_result::FCEResult;
|
||||
use crate::vm::module::{ModuleABI, ModuleAPI};
|
||||
use crate::vm::module::{ModuleAPI, ABI};
|
||||
|
||||
use sha2::digest::generic_array::GenericArray;
|
||||
use sha2::digest::FixedOutput;
|
||||
use wasmer_runtime::{compile, func, imports, Ctx, Instance};
|
||||
use wasmer_runtime::{compile, func, imports, Ctx, Func, Instance};
|
||||
use wasmer_runtime_core::import::ImportObject;
|
||||
use wasmer_runtime_core::memory::ptr::{Array, WasmPtr};
|
||||
use wasmer_wasi::generate_import_object_for_version;
|
||||
|
||||
pub(crate) struct FCEModule {
|
||||
instance: &'static Instance,
|
||||
abi: ModuleABI<'static>,
|
||||
instance: Instance,
|
||||
abi: ABI<'static>,
|
||||
}
|
||||
|
||||
impl FCEModule {
|
||||
@ -52,19 +52,46 @@ impl FCEModule {
|
||||
import_object.allow_missing_functions = false;
|
||||
|
||||
let instance = compile(&wasm_bytes)?.instantiate(&import_object)?;
|
||||
let instance: &'static mut Instance = Box::leak(Box::new(instance));
|
||||
let abi = ModuleABI {
|
||||
allocate: Some(instance.exports.get(&config.allocate_fn_name)?),
|
||||
deallocate: Some(instance.exports.get(&config.deallocate_fn_name)?),
|
||||
invoke: Some(instance.exports.get(&config.invoke_fn_name)?),
|
||||
store: Some(instance.exports.get(&config.store_fn_name)?),
|
||||
load: Some(instance.exports.get(&config.load_fn_name)?),
|
||||
|
||||
unsafe {
|
||||
#[rustfmt::skip]
|
||||
let allocate = std::mem::transmute::<Func<'_, i32, i32>, Func<'static, i32, i32>>(
|
||||
instance.exports.get(&config.allocate_fn_name)?
|
||||
);
|
||||
|
||||
#[rustfmt::skip]
|
||||
let deallocate = std::mem::transmute::<Func<'_, (i32, i32)>, Func<'static, (i32, i32)>>(
|
||||
instance.exports.get(&config.deallocate_fn_name)?
|
||||
);
|
||||
|
||||
#[rustfmt::skip]
|
||||
let invoke = std::mem::transmute::<Func<'_, (i32, i32), i32>, Func<'static, (i32, i32), i32>, >(
|
||||
instance.exports.get(&config.invoke_fn_name)?
|
||||
);
|
||||
|
||||
#[rustfmt::skip]
|
||||
let store = std::mem::transmute::<Func<'_, (i32, i32)>, Func<'static, _, _>>(
|
||||
instance.exports.get(&config.store_fn_name)?,
|
||||
);
|
||||
|
||||
#[rustfmt::skip]
|
||||
let load = std::mem::transmute::<Func<'_, i32, i32>, Func<'static, _, _>>(
|
||||
instance.exports.get(&config.load_fn_name)?,
|
||||
);
|
||||
|
||||
let abi = ABI {
|
||||
allocate: Some(allocate),
|
||||
deallocate: Some(deallocate),
|
||||
invoke: Some(invoke),
|
||||
store: Some(store),
|
||||
load: Some(load),
|
||||
};
|
||||
|
||||
Ok(Self { instance, abi })
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_abi(&self) -> &ModuleABI<'static> {
|
||||
pub fn get_abi(&self) -> &ABI<'static> {
|
||||
&self.abi
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,6 @@ mod api;
|
||||
mod fce_module;
|
||||
pub mod fce_result;
|
||||
|
||||
pub(crate) use abi::ModuleABI;
|
||||
pub(crate) use abi::ABI;
|
||||
pub(crate) use api::ModuleAPI;
|
||||
pub(crate) use fce_module::FCEModule;
|
||||
|
Loading…
Reference in New Issue
Block a user