mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 09:47:56 +00:00
Update wasmtime to (almost) lastest master (#6662)
* update wasmtime to (almost) lastest master * bump lock * bump once more
This commit is contained in:
@@ -308,6 +308,7 @@ impl<'a> Sandbox for HostContext<'a> {
|
||||
.ok_or_else(|| "dispatch_thunk_id is out of bounds")?
|
||||
.funcref()
|
||||
.ok_or_else(|| "dispatch_thunk_idx should be a funcref")?
|
||||
.ok_or_else(|| "dispatch_thunk_idx should point to actual func")?
|
||||
.clone();
|
||||
SupervisorFuncRef(func_ref)
|
||||
};
|
||||
|
||||
@@ -22,7 +22,7 @@ use sp_wasm_interface::{Function, Value, ValueType};
|
||||
use std::any::Any;
|
||||
use wasmtime::{
|
||||
Extern, ExternType, Func, FuncType, ImportType, Limits, Memory, MemoryType, Module,
|
||||
Trap, Val,
|
||||
Trap, Val, Store,
|
||||
};
|
||||
|
||||
pub struct Imports {
|
||||
@@ -35,6 +35,7 @@ pub struct Imports {
|
||||
/// Goes over all imports of a module and prepares a vector of `Extern`s that can be used for
|
||||
/// instantiation of the module. Returns an error if there are imports that cannot be satisfied.
|
||||
pub fn resolve_imports(
|
||||
store: &Store,
|
||||
module: &Module,
|
||||
host_functions: &[&'static dyn Function],
|
||||
heap_pages: u32,
|
||||
@@ -54,10 +55,10 @@ pub fn resolve_imports(
|
||||
let resolved = match import_ty.name() {
|
||||
"memory" => {
|
||||
memory_import_index = Some(externs.len());
|
||||
resolve_memory_import(module, &import_ty, heap_pages)?
|
||||
resolve_memory_import(store, &import_ty, heap_pages)?
|
||||
}
|
||||
_ => resolve_func_import(
|
||||
module,
|
||||
store,
|
||||
&import_ty,
|
||||
host_functions,
|
||||
allow_missing_func_imports,
|
||||
@@ -72,7 +73,7 @@ pub fn resolve_imports(
|
||||
}
|
||||
|
||||
fn resolve_memory_import(
|
||||
module: &Module,
|
||||
store: &Store,
|
||||
import_ty: &ImportType,
|
||||
heap_pages: u32,
|
||||
) -> Result<Extern, WasmError> {
|
||||
@@ -105,12 +106,12 @@ fn resolve_memory_import(
|
||||
}
|
||||
|
||||
let memory_ty = MemoryType::new(Limits::new(initial, requested_memory_ty.limits().max()));
|
||||
let memory = Memory::new(module.store(), memory_ty);
|
||||
let memory = Memory::new(store, memory_ty);
|
||||
Ok(Extern::Memory(memory))
|
||||
}
|
||||
|
||||
fn resolve_func_import(
|
||||
module: &Module,
|
||||
store: &Store,
|
||||
import_ty: &ImportType,
|
||||
host_functions: &[&'static dyn Function],
|
||||
allow_missing_func_imports: bool,
|
||||
@@ -132,7 +133,7 @@ fn resolve_func_import(
|
||||
{
|
||||
Some(host_func) => host_func,
|
||||
None if allow_missing_func_imports => {
|
||||
return Ok(MissingHostFuncHandler::new(import_ty).into_extern(module, &func_ty));
|
||||
return Ok(MissingHostFuncHandler::new(import_ty).into_extern(store, &func_ty));
|
||||
}
|
||||
None => {
|
||||
return Err(WasmError::Other(format!(
|
||||
@@ -150,7 +151,7 @@ fn resolve_func_import(
|
||||
)));
|
||||
}
|
||||
|
||||
Ok(HostFuncHandler::new(*host_func).into_extern(module))
|
||||
Ok(HostFuncHandler::new(*host_func).into_extern(store))
|
||||
}
|
||||
|
||||
/// Returns `true` if `lhs` and `rhs` represent the same signature.
|
||||
@@ -223,10 +224,10 @@ impl HostFuncHandler {
|
||||
}
|
||||
}
|
||||
|
||||
fn into_extern(self, module: &Module) -> Extern {
|
||||
fn into_extern(self, store: &Store) -> Extern {
|
||||
let host_func = self.host_func;
|
||||
let func_ty = wasmtime_func_sig(self.host_func);
|
||||
let func = Func::new(module.store(), func_ty,
|
||||
let func = Func::new(store, func_ty,
|
||||
move |_, params, result| {
|
||||
call_static(host_func, params, result)
|
||||
}
|
||||
@@ -249,9 +250,9 @@ impl MissingHostFuncHandler {
|
||||
}
|
||||
}
|
||||
|
||||
fn into_extern(self, wasmtime_module: &Module, func_ty: &FuncType) -> Extern {
|
||||
fn into_extern(self, store: &Store, func_ty: &FuncType) -> Extern {
|
||||
let Self { module, name } = self;
|
||||
let func = Func::new(wasmtime_module.store(), func_ty.clone(),
|
||||
let func = Func::new(store, func_ty.clone(),
|
||||
move |_, _, _| Err(Trap::new(format!(
|
||||
"call to a missing function {}:{}",
|
||||
module, name
|
||||
|
||||
@@ -28,7 +28,7 @@ use sc_executor_common::{
|
||||
util::{WasmModuleInfo, DataSegmentsSnapshot},
|
||||
};
|
||||
use sp_wasm_interface::{Pointer, WordSize, Value};
|
||||
use wasmtime::{Store, Instance, Module, Memory, Table, Val, Func, Extern, Global};
|
||||
use wasmtime::{Engine, Instance, Module, Memory, Table, Val, Func, Extern, Global, Store};
|
||||
|
||||
mod globals_snapshot;
|
||||
|
||||
@@ -42,8 +42,8 @@ pub struct ModuleWrapper {
|
||||
}
|
||||
|
||||
impl ModuleWrapper {
|
||||
pub fn new(store: &Store, code: &[u8]) -> Result<Self> {
|
||||
let module = Module::new(&store, code)
|
||||
pub fn new(engine: &Engine, code: &[u8]) -> Result<Self> {
|
||||
let module = Module::new(engine, code)
|
||||
.map_err(|e| Error::from(format!("cannot create module: {}", e)))?;
|
||||
|
||||
let module_info = WasmModuleInfo::new(code)
|
||||
@@ -121,8 +121,8 @@ fn extern_func(extern_: &Extern) -> Option<&Func> {
|
||||
|
||||
impl InstanceWrapper {
|
||||
/// Create a new instance wrapper from the given wasm module.
|
||||
pub fn new(module_wrapper: &ModuleWrapper, imports: &Imports, heap_pages: u32) -> Result<Self> {
|
||||
let instance = Instance::new(&module_wrapper.module, &imports.externs)
|
||||
pub fn new(store: &Store, module_wrapper: &ModuleWrapper, imports: &Imports, heap_pages: u32) -> Result<Self> {
|
||||
let instance = Instance::new(store, &module_wrapper.module, &imports.externs)
|
||||
.map_err(|e| Error::from(format!("cannot instantiate: {}", e)))?;
|
||||
|
||||
let memory = match imports.memory_import_index {
|
||||
|
||||
@@ -40,7 +40,7 @@ impl GlobalsSnapshot {
|
||||
pub fn take(instance_wrapper: &InstanceWrapper) -> Result<Self> {
|
||||
// EVIL:
|
||||
// Usage of an undocumented function.
|
||||
let handle = unsafe { instance_wrapper.instance.handle().clone() };
|
||||
let handle = instance_wrapper.instance.handle().clone().handle;
|
||||
|
||||
let mut preserved_mut_globals = vec![];
|
||||
|
||||
@@ -75,7 +75,7 @@ impl GlobalsSnapshot {
|
||||
///
|
||||
/// This instance must be the same that was used for creation of this snapshot.
|
||||
pub fn apply(&self, instance_wrapper: &InstanceWrapper) -> Result<()> {
|
||||
if instance_wrapper.instance.handle() != &self.handle {
|
||||
if instance_wrapper.instance.handle().handle != self.handle {
|
||||
return Err(Error::from("unexpected instance handle".to_string()));
|
||||
}
|
||||
|
||||
|
||||
@@ -39,13 +39,17 @@ pub struct WasmtimeRuntime {
|
||||
heap_pages: u32,
|
||||
allow_missing_func_imports: bool,
|
||||
host_functions: Vec<&'static dyn Function>,
|
||||
engine: Engine,
|
||||
}
|
||||
|
||||
impl WasmModule for WasmtimeRuntime {
|
||||
fn new_instance(&self) -> Result<Box<dyn WasmInstance>> {
|
||||
let store = Store::new(&self.engine);
|
||||
|
||||
// Scan all imports, find the matching host functions, and create stubs that adapt arguments
|
||||
// and results.
|
||||
let imports = resolve_imports(
|
||||
&store,
|
||||
self.module_wrapper.module(),
|
||||
&self.host_functions,
|
||||
self.heap_pages,
|
||||
@@ -53,11 +57,12 @@ impl WasmModule for WasmtimeRuntime {
|
||||
)?;
|
||||
|
||||
let instance_wrapper =
|
||||
InstanceWrapper::new(&self.module_wrapper, &imports, self.heap_pages)?;
|
||||
InstanceWrapper::new(&store, &self.module_wrapper, &imports, self.heap_pages)?;
|
||||
let heap_base = instance_wrapper.extract_heap_base()?;
|
||||
let globals_snapshot = GlobalsSnapshot::take(&instance_wrapper)?;
|
||||
|
||||
Ok(Box::new(WasmtimeInstance {
|
||||
store,
|
||||
instance_wrapper: Rc::new(instance_wrapper),
|
||||
module_wrapper: Arc::clone(&self.module_wrapper),
|
||||
imports,
|
||||
@@ -71,6 +76,7 @@ impl WasmModule for WasmtimeRuntime {
|
||||
/// A `WasmInstance` implementation that reuses compiled module and spawns instances
|
||||
/// to execute the compiled code.
|
||||
pub struct WasmtimeInstance {
|
||||
store: Store,
|
||||
module_wrapper: Arc<ModuleWrapper>,
|
||||
instance_wrapper: Rc<InstanceWrapper>,
|
||||
globals_snapshot: GlobalsSnapshot,
|
||||
@@ -106,7 +112,7 @@ impl WasmInstance for WasmtimeInstance {
|
||||
}
|
||||
|
||||
fn get_global_const(&self, name: &str) -> Result<Option<Value>> {
|
||||
let instance = InstanceWrapper::new(&self.module_wrapper, &self.imports, self.heap_pages)?;
|
||||
let instance = InstanceWrapper::new(&self.store, &self.module_wrapper, &self.imports, self.heap_pages)?;
|
||||
instance.get_global_val(name)
|
||||
}
|
||||
}
|
||||
@@ -124,9 +130,8 @@ pub fn create_runtime(
|
||||
config.cranelift_opt_level(wasmtime::OptLevel::SpeedAndSize);
|
||||
|
||||
let engine = Engine::new(&config);
|
||||
let store = Store::new(&engine);
|
||||
|
||||
let module_wrapper = ModuleWrapper::new(&store, code)
|
||||
let module_wrapper = ModuleWrapper::new(&engine, code)
|
||||
.map_err(|e| WasmError::Other(format!("cannot create module: {}", e)))?;
|
||||
|
||||
Ok(WasmtimeRuntime {
|
||||
@@ -134,6 +139,7 @@ pub fn create_runtime(
|
||||
heap_pages: heap_pages as u32,
|
||||
allow_missing_func_imports,
|
||||
host_functions,
|
||||
engine,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user