Merge remote-tracking branch 'origin/master' into middleware

This commit is contained in:
losfair
2020-06-18 00:41:42 +08:00
22 changed files with 797 additions and 763 deletions

View File

@@ -5,6 +5,7 @@ use crate::types::Val;
use crate::FunctionType; use crate::FunctionType;
use crate::NativeFunc; use crate::NativeFunc;
use crate::RuntimeError; use crate::RuntimeError;
use std::cell::RefCell;
use std::cmp::max; use std::cmp::max;
use wasm_common::{HostFunction, WasmTypeList, WithEnv, WithoutEnv}; use wasm_common::{HostFunction, WasmTypeList, WithEnv, WithoutEnv};
use wasmer_runtime::{ use wasmer_runtime::{
@@ -55,7 +56,7 @@ impl Function {
F: HostFunction<Args, Rets, WithoutEnv, Env>, F: HostFunction<Args, Rets, WithoutEnv, Env>,
Args: WasmTypeList, Args: WasmTypeList,
Rets: WasmTypeList, Rets: WasmTypeList,
Env: Sized, Env: Sized + 'static,
{ {
let func: wasm_common::Func<Args, Rets> = wasm_common::Func::new(func); let func: wasm_common::Func<Args, Rets> = wasm_common::Func::new(func);
let address = func.address() as *const VMFunctionBody; let address = func.address() as *const VMFunctionBody;
@@ -102,13 +103,13 @@ impl Function {
} }
#[allow(clippy::cast_ptr_alignment)] #[allow(clippy::cast_ptr_alignment)]
pub fn new_dynamic_env<F, Env>(store: &Store, ty: &FunctionType, env: &mut Env, func: F) -> Self pub fn new_dynamic_env<F, Env>(store: &Store, ty: &FunctionType, env: Env, func: F) -> Self
where where
F: Fn(&mut Env, &[Val]) -> Result<Vec<Val>, RuntimeError> + 'static, F: Fn(&mut Env, &[Val]) -> Result<Vec<Val>, RuntimeError> + 'static,
Env: Sized, Env: Sized + 'static,
{ {
let dynamic_ctx = VMDynamicFunctionContext::from_context(VMDynamicFunctionWithEnv { let dynamic_ctx = VMDynamicFunctionContext::from_context(VMDynamicFunctionWithEnv {
env, env: RefCell::new(env),
func: Box::new(func), func: Box::new(func),
function_type: ty.clone(), function_type: ty.clone(),
}); });
@@ -135,12 +136,12 @@ impl Function {
/// * `store` - a global cache to store information in. /// * `store` - a global cache to store information in.
/// * `env` - the function environment. /// * `env` - the function environment.
/// * `func` - the function. /// * `func` - the function.
pub fn new_env<F, Args, Rets, Env>(store: &Store, env: &mut Env, func: F) -> Self pub fn new_env<F, Args, Rets, Env>(store: &Store, env: Env, func: F) -> Self
where where
F: HostFunction<Args, Rets, WithEnv, Env>, F: HostFunction<Args, Rets, WithEnv, Env>,
Args: WasmTypeList, Args: WasmTypeList,
Rets: WasmTypeList, Rets: WasmTypeList,
Env: Sized, Env: Sized + 'static,
{ {
let func: wasm_common::Func<Args, Rets> = wasm_common::Func::new(func); let func: wasm_common::Func<Args, Rets> = wasm_common::Func::new(func);
let address = func.address() as *const VMFunctionBody; let address = func.address() as *const VMFunctionBody;
@@ -149,7 +150,8 @@ impl Function {
// Wasm-defined functions have a `VMContext`. // Wasm-defined functions have a `VMContext`.
// In the case of Host-defined functions `VMContext` is whatever environment // In the case of Host-defined functions `VMContext` is whatever environment
// the user want to attach to the function. // the user want to attach to the function.
let vmctx = env as *mut _ as *mut VMContext; let box_env = Box::new(env);
let vmctx = Box::into_raw(box_env) as *mut _ as *mut VMContext;
let signature = func.ty(); let signature = func.ty();
Self { Self {
store: store.clone(), store: store.clone(),
@@ -364,20 +366,22 @@ impl VMDynamicFunction for VMDynamicFunctionWithoutEnv {
pub(crate) struct VMDynamicFunctionWithEnv<Env> pub(crate) struct VMDynamicFunctionWithEnv<Env>
where where
Env: Sized, Env: Sized + 'static,
{ {
function_type: FunctionType,
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
func: Box<dyn Fn(&mut Env, &[Val]) -> Result<Vec<Val>, RuntimeError> + 'static>, func: Box<dyn Fn(&mut Env, &[Val]) -> Result<Vec<Val>, RuntimeError> + 'static>,
env: *mut Env, env: RefCell<Env>,
function_type: FunctionType,
} }
impl<Env> VMDynamicFunction for VMDynamicFunctionWithEnv<Env> impl<Env> VMDynamicFunction for VMDynamicFunctionWithEnv<Env>
where where
Env: Sized, Env: Sized + 'static,
{ {
fn call(&self, args: &[Val]) -> Result<Vec<Val>, RuntimeError> { fn call(&self, args: &[Val]) -> Result<Vec<Val>, RuntimeError> {
unsafe { (*self.func)(&mut *self.env, &args) } // TODO: the `&mut *self.env.as_ptr()` is likely invoking some "mild"
// undefined behavior due to how it's used in the static fn call
unsafe { (*self.func)(&mut *self.env.as_ptr(), &args) }
} }
fn function_type(&self) -> &FunctionType { fn function_type(&self) -> &FunctionType {
&self.function_type &self.function_type

View File

@@ -94,7 +94,7 @@ fn table_get() -> Result<()> {
let f = Function::new(&store, |num: i32| num + 1); let f = Function::new(&store, |num: i32| num + 1);
let table = Table::new(&store, table_type, Value::FuncRef(f.clone()))?; let table = Table::new(&store, table_type, Value::FuncRef(f.clone()))?;
assert_eq!(*table.ty(), table_type); assert_eq!(*table.ty(), table_type);
let elem = table.get(0).unwrap(); let _elem = table.get(0).unwrap();
// assert_eq!(elem.funcref().unwrap(), f); // assert_eq!(elem.funcref().unwrap(), f);
Ok(()) Ok(())
} }
@@ -102,7 +102,7 @@ fn table_get() -> Result<()> {
#[test] #[test]
#[ignore] #[ignore]
fn table_set() -> Result<()> { fn table_set() -> Result<()> {
/// Table set not yet tested // Table set not yet tested
Ok(()) Ok(())
} }
@@ -220,32 +220,33 @@ fn function_new() -> Result<()> {
#[test] #[test]
fn function_new_env() -> Result<()> { fn function_new_env() -> Result<()> {
let store = Store::default(); let store = Store::default();
#[derive(Clone)]
struct MyEnv {}; struct MyEnv {};
let mut my_env = MyEnv {}; let my_env = MyEnv {};
let function = Function::new_env(&store, &mut my_env, |_env: &mut MyEnv| {}); let function = Function::new_env(&store, my_env.clone(), |_env: &mut MyEnv| {});
assert_eq!(function.ty().clone(), FunctionType::new(vec![], vec![])); assert_eq!(function.ty().clone(), FunctionType::new(vec![], vec![]));
let function = Function::new_env(&store, &mut my_env, |_env: &mut MyEnv, _a: i32| {}); let function = Function::new_env(&store, my_env.clone(), |_env: &mut MyEnv, _a: i32| {});
assert_eq!( assert_eq!(
function.ty().clone(), function.ty().clone(),
FunctionType::new(vec![Type::I32], vec![]) FunctionType::new(vec![Type::I32], vec![])
); );
let function = Function::new_env( let function = Function::new_env(
&store, &store,
&mut my_env, my_env.clone(),
|_env: &mut MyEnv, _a: i32, _b: i64, _c: f32, _d: f64| {}, |_env: &mut MyEnv, _a: i32, _b: i64, _c: f32, _d: f64| {},
); );
assert_eq!( assert_eq!(
function.ty().clone(), function.ty().clone(),
FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![]) FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![])
); );
let function = Function::new_env(&store, &mut my_env, |_env: &mut MyEnv| -> i32 { 1 }); let function = Function::new_env(&store, my_env.clone(), |_env: &mut MyEnv| -> i32 { 1 });
assert_eq!( assert_eq!(
function.ty().clone(), function.ty().clone(),
FunctionType::new(vec![], vec![Type::I32]) FunctionType::new(vec![], vec![Type::I32])
); );
let function = Function::new_env( let function = Function::new_env(
&store, &store,
&mut my_env, my_env.clone(),
|_env: &mut MyEnv| -> (i32, i64, f32, f64) { (1, 2, 3.0, 4.0) }, |_env: &mut MyEnv| -> (i32, i64, f32, f64) { (1, 2, 3.0, 4.0) },
); );
assert_eq!( assert_eq!(
@@ -260,23 +261,23 @@ fn function_new_dynamic() -> Result<()> {
let store = Store::default(); let store = Store::default();
let function_type = FunctionType::new(vec![], vec![]); let function_type = FunctionType::new(vec![], vec![]);
let function = let function =
Function::new_dynamic(&store, &function_type, |values: &[Value]| unimplemented!()); Function::new_dynamic(&store, &function_type, |_values: &[Value]| unimplemented!());
assert_eq!(function.ty().clone(), function_type); assert_eq!(function.ty().clone(), function_type);
let function_type = FunctionType::new(vec![Type::I32], vec![]); let function_type = FunctionType::new(vec![Type::I32], vec![]);
let function = let function =
Function::new_dynamic(&store, &function_type, |values: &[Value]| unimplemented!()); Function::new_dynamic(&store, &function_type, |_values: &[Value]| unimplemented!());
assert_eq!(function.ty().clone(), function_type); assert_eq!(function.ty().clone(), function_type);
let function_type = FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![]); let function_type = FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![]);
let function = let function =
Function::new_dynamic(&store, &function_type, |values: &[Value]| unimplemented!()); Function::new_dynamic(&store, &function_type, |_values: &[Value]| unimplemented!());
assert_eq!(function.ty().clone(), function_type); assert_eq!(function.ty().clone(), function_type);
let function_type = FunctionType::new(vec![], vec![Type::I32]); let function_type = FunctionType::new(vec![], vec![Type::I32]);
let function = let function =
Function::new_dynamic(&store, &function_type, |values: &[Value]| unimplemented!()); Function::new_dynamic(&store, &function_type, |_values: &[Value]| unimplemented!());
assert_eq!(function.ty().clone(), function_type); assert_eq!(function.ty().clone(), function_type);
let function_type = FunctionType::new(vec![], vec![Type::I32, Type::I64, Type::F32, Type::F64]); let function_type = FunctionType::new(vec![], vec![Type::I32, Type::I64, Type::F32, Type::F64]);
let function = let function =
Function::new_dynamic(&store, &function_type, |values: &[Value]| unimplemented!()); Function::new_dynamic(&store, &function_type, |_values: &[Value]| unimplemented!());
assert_eq!(function.ty().clone(), function_type); assert_eq!(function.ty().clone(), function_type);
Ok(()) Ok(())
} }
@@ -284,47 +285,48 @@ fn function_new_dynamic() -> Result<()> {
#[test] #[test]
fn function_new_dynamic_env() -> Result<()> { fn function_new_dynamic_env() -> Result<()> {
let store = Store::default(); let store = Store::default();
#[derive(Clone)]
struct MyEnv {}; struct MyEnv {};
let mut my_env = MyEnv {}; let my_env = MyEnv {};
let function_type = FunctionType::new(vec![], vec![]); let function_type = FunctionType::new(vec![], vec![]);
let function = Function::new_dynamic_env( let function = Function::new_dynamic_env(
&store, &store,
&function_type, &function_type,
&mut my_env, my_env.clone(),
|_env: &mut MyEnv, values: &[Value]| unimplemented!(), |_env: &mut MyEnv, _values: &[Value]| unimplemented!(),
); );
assert_eq!(function.ty().clone(), function_type); assert_eq!(function.ty().clone(), function_type);
let function_type = FunctionType::new(vec![Type::I32], vec![]); let function_type = FunctionType::new(vec![Type::I32], vec![]);
let function = Function::new_dynamic_env( let function = Function::new_dynamic_env(
&store, &store,
&function_type, &function_type,
&mut my_env, my_env.clone(),
|_env: &mut MyEnv, values: &[Value]| unimplemented!(), |_env: &mut MyEnv, _values: &[Value]| unimplemented!(),
); );
assert_eq!(function.ty().clone(), function_type); assert_eq!(function.ty().clone(), function_type);
let function_type = FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![]); let function_type = FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![]);
let function = Function::new_dynamic_env( let function = Function::new_dynamic_env(
&store, &store,
&function_type, &function_type,
&mut my_env, my_env.clone(),
|_env: &mut MyEnv, values: &[Value]| unimplemented!(), |_env: &mut MyEnv, _values: &[Value]| unimplemented!(),
); );
assert_eq!(function.ty().clone(), function_type); assert_eq!(function.ty().clone(), function_type);
let function_type = FunctionType::new(vec![], vec![Type::I32]); let function_type = FunctionType::new(vec![], vec![Type::I32]);
let function = Function::new_dynamic_env( let function = Function::new_dynamic_env(
&store, &store,
&function_type, &function_type,
&mut my_env, my_env.clone(),
|_env: &mut MyEnv, values: &[Value]| unimplemented!(), |_env: &mut MyEnv, _values: &[Value]| unimplemented!(),
); );
assert_eq!(function.ty().clone(), function_type); assert_eq!(function.ty().clone(), function_type);
let function_type = FunctionType::new(vec![], vec![Type::I32, Type::I64, Type::F32, Type::F64]); let function_type = FunctionType::new(vec![], vec![Type::I32, Type::I64, Type::F32, Type::F64]);
let function = Function::new_dynamic_env( let function = Function::new_dynamic_env(
&store, &store,
&function_type, &function_type,
&mut my_env, my_env.clone(),
|_env: &mut MyEnv, values: &[Value]| unimplemented!(), |_env: &mut MyEnv, _values: &[Value]| unimplemented!(),
); );
assert_eq!(function.ty().clone(), function_type); assert_eq!(function.ty().clone(), function_type);
Ok(()) Ok(())

View File

@@ -1,7 +1,10 @@
use super::*; use super::*;
use crate::get_slice_checked; use crate::get_slice_checked;
use libc::c_uchar; use libc::c_uchar;
use std::{path::PathBuf, ptr, str}; use std::path::PathBuf;
use std::ptr;
use std::str;
use std::sync::Arc;
use wasmer::{Memory, MemoryType, NamedResolver}; use wasmer::{Memory, MemoryType, NamedResolver};
use wasmer_wasi as wasi; use wasmer_wasi as wasi;
@@ -214,10 +217,10 @@ pub unsafe extern "C" fn wasmer_wasi_generate_default_import_object() -> *mut wa
// this API will now leak a `Memory` // this API will now leak a `Memory`
let memory_type = MemoryType::new(0, None, false); let memory_type = MemoryType::new(0, None, false);
let memory = Memory::new(store, memory_type).expect("create memory"); let memory = Memory::new(store, memory_type).expect("create memory");
wasi_env.set_memory(&memory); wasi_env.set_memory(Arc::new(memory));
// TODO(mark): review lifetime of `Memory` here // TODO(mark): review lifetime of `Memory` here
let import_object_inner: Box<dyn NamedResolver> = Box::new( let import_object_inner: Box<dyn NamedResolver> = Box::new(
wasi::generate_import_object_from_env(store, &mut wasi_env, wasi::WasiVersion::Latest), wasi::generate_import_object_from_env(store, wasi_env, wasi::WasiVersion::Latest),
); );
let import_object: Box<CAPIImportObject> = Box::new(CAPIImportObject { let import_object: Box<CAPIImportObject> = Box::new(CAPIImportObject {
import_object: import_object_inner, import_object: import_object_inner,

View File

@@ -737,37 +737,33 @@ pub unsafe extern "C" fn wasm_func_new_with_env(
let store = store_ptr.as_ref(); let store = store_ptr.as_ref();
let func_sig = ft.sig(); let func_sig = ft.sig();
let num_rets = func_sig.results().len(); let num_rets = func_sig.results().len();
let inner_callback = move |env: &mut c_void, args: &[Val]| -> Result<Vec<Val>, RuntimeError> { let inner_callback =
let processed_args = args move |env: &mut *mut c_void, args: &[Val]| -> Result<Vec<Val>, RuntimeError> {
.into_iter() let processed_args = args
.map(TryInto::try_into) .into_iter()
.collect::<Result<Vec<wasm_val_t>, _>>() .map(TryInto::try_into)
.expect("Argument conversion failed"); .collect::<Result<Vec<wasm_val_t>, _>>()
.expect("Argument conversion failed");
let mut results = vec![ let mut results = vec![
wasm_val_t { wasm_val_t {
kind: wasm_valkind_enum::WASM_I64 as _, kind: wasm_valkind_enum::WASM_I64 as _,
of: wasm_val_inner { int64_t: 0 }, of: wasm_val_inner { int64_t: 0 },
}; };
num_rets num_rets
]; ];
let _traps = callback(env, processed_args.as_ptr(), results.as_mut_ptr()); let _traps = callback(*env, processed_args.as_ptr(), results.as_mut_ptr());
// TODO: do something with `traps` // TODO: do something with `traps`
let processed_results = results let processed_results = results
.into_iter() .into_iter()
.map(TryInto::try_into) .map(TryInto::try_into)
.collect::<Result<Vec<Val>, _>>() .collect::<Result<Vec<Val>, _>>()
.expect("Result conversion failed"); .expect("Result conversion failed");
Ok(processed_results) Ok(processed_results)
}; };
let f = Function::new_dynamic_env( let f = Function::new_dynamic_env(store, &func_sig, env, inner_callback);
store,
&func_sig,
mem::transmute::<*mut c_void, &mut c_void>(env),
inner_callback,
);
Some(Box::new(wasm_func_t { Some(Box::new(wasm_func_t {
instance: None, instance: None,
inner: f, inner: f,

View File

@@ -1,3 +1,7 @@
// This file contains code from external sources.
// Attributions: https://github.com/wasmerio/wasmer-reborn/blob/master/ATTRIBUTIONS.md
use cranelift_codegen::machinst::buffer::MachSrcLoc;
use cranelift_codegen::{isa, Context}; use cranelift_codegen::{isa, Context};
use wasmer_compiler::{FunctionAddressMap, FunctionBodyData, InstructionAddressMap, SourceLoc}; use wasmer_compiler::{FunctionAddressMap, FunctionBodyData, InstructionAddressMap, SourceLoc};
@@ -9,20 +13,32 @@ pub fn get_function_address_map<'data>(
) -> FunctionAddressMap { ) -> FunctionAddressMap {
let mut instructions = Vec::new(); let mut instructions = Vec::new();
let func = &context.func; if let Some(ref mcr) = &context.mach_compile_result {
let mut blocks = func.layout.blocks().collect::<Vec<_>>(); // New-style backend: we have a `MachCompileResult` that will give us `MachSrcLoc` mapping
blocks.sort_by_key(|block| func.offsets[*block]); // Ensure inst offsets always increase // tuples.
for &MachSrcLoc { start, end, loc } in mcr.buffer.get_srclocs_sorted() {
let encinfo = isa.encoding_info();
for block in blocks {
for (offset, inst, size) in func.inst_offsets(block, &encinfo) {
let srcloc = func.srclocs[inst];
instructions.push(InstructionAddressMap { instructions.push(InstructionAddressMap {
srcloc: SourceLoc::new(srcloc.bits()), srcloc: SourceLoc::new(loc.bits()),
code_offset: offset as usize, code_offset: start as usize,
code_len: size as usize, code_len: (end - start) as usize,
}); });
} }
} else {
let func = &context.func;
let mut blocks = func.layout.blocks().collect::<Vec<_>>();
blocks.sort_by_key(|block| func.offsets[*block]); // Ensure inst offsets always increase
let encinfo = isa.encoding_info();
for block in blocks {
for (offset, inst, size) in func.inst_offsets(block, &encinfo) {
let srcloc = func.srclocs[inst];
instructions.push(InstructionAddressMap {
srcloc: SourceLoc::new(srcloc.bits()),
code_offset: offset as usize,
code_len: size as usize,
});
}
}
} }
// Generate artificial srcloc for function start/end to identify boundary // Generate artificial srcloc for function start/end to identify boundary

View File

@@ -21,8 +21,7 @@ use gimli::write::{Address, EhFrame, FrameTable};
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator}; use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
use wasm_common::entity::{EntityRef, PrimaryMap}; use wasm_common::entity::{EntityRef, PrimaryMap};
use wasm_common::{ use wasm_common::{
Features, FunctionIndex, FunctionType, LocalFunctionIndex, MemoryIndex, SignatureIndex, Features, FunctionIndex, LocalFunctionIndex, MemoryIndex, SignatureIndex, TableIndex,
TableIndex,
}; };
use wasmer_compiler::CompileError; use wasmer_compiler::CompileError;
use wasmer_compiler::{CallingConvention, CompilerConfig, ModuleTranslationState, Target}; use wasmer_compiler::{CallingConvention, CompilerConfig, ModuleTranslationState, Target};
@@ -228,36 +227,39 @@ impl Compiler for CraneliftCompiler {
#[cfg(not(feature = "unwind"))] #[cfg(not(feature = "unwind"))]
let (custom_sections, dwarf) = (PrimaryMap::new(), None); let (custom_sections, dwarf) = (PrimaryMap::new(), None);
Ok(Compilation::new(functions, custom_sections, dwarf)) // function call trampolines (only for local functions, by signature)
} let function_call_trampolines = module
.signatures
fn compile_function_call_trampolines( .values()
&self, .collect::<Vec<_>>()
signatures: &[FunctionType],
) -> Result<Vec<FunctionBody>, CompileError> {
signatures
.par_iter() .par_iter()
.map_init(FunctionBuilderContext::new, |mut cx, sig| { .map_init(FunctionBuilderContext::new, |mut cx, sig| {
make_trampoline_function_call(&*self.isa, &mut cx, sig) make_trampoline_function_call(&*self.isa, &mut cx, sig)
}) })
.collect::<Result<Vec<_>, CompileError>>() .collect::<Result<Vec<FunctionBody>, CompileError>>()?
} .into_iter()
.collect::<PrimaryMap<SignatureIndex, FunctionBody>>();
fn compile_dynamic_function_trampolines(
&self,
signatures: &[FunctionType],
) -> Result<PrimaryMap<FunctionIndex, FunctionBody>, CompileError> {
use wasmer_runtime::VMOffsets; use wasmer_runtime::VMOffsets;
let isa = self.isa();
let frontend_config = isa.frontend_config();
let offsets = VMOffsets::new_for_trampolines(frontend_config.pointer_bytes()); let offsets = VMOffsets::new_for_trampolines(frontend_config.pointer_bytes());
Ok(signatures // dynamic function trampolines (only for imported functions)
let dynamic_function_trampolines = module
.imported_function_types()
.collect::<Vec<_>>()
.par_iter() .par_iter()
.map_init(FunctionBuilderContext::new, |mut cx, func_type| { .map_init(FunctionBuilderContext::new, |mut cx, func_type| {
make_trampoline_dynamic_function(&*self.isa, &offsets, &mut cx, &func_type) make_trampoline_dynamic_function(&*self.isa, &offsets, &mut cx, &func_type)
}) })
.collect::<Result<Vec<_>, CompileError>>()? .collect::<Result<Vec<_>, CompileError>>()?
.into_iter() .into_iter()
.collect::<PrimaryMap<FunctionIndex, FunctionBody>>()) .collect::<PrimaryMap<FunctionIndex, FunctionBody>>();
Ok(Compilation::new(
functions,
custom_sections,
function_call_trampolines,
dynamic_function_trampolines,
dwarf,
))
} }
} }

View File

@@ -74,7 +74,6 @@ impl CraneliftConfig {
let mut builder = let mut builder =
lookup(target.triple().clone()).expect("construct Cranelift ISA for triple"); lookup(target.triple().clone()).expect("construct Cranelift ISA for triple");
// Cpu Features // Cpu Features
let cpu_features = target.cpu_features(); let cpu_features = target.cpu_features();
if target.triple().architecture == Architecture::X86_64 if target.triple().architecture == Architecture::X86_64
&& !cpu_features.contains(CpuFeature::SSE2) && !cpu_features.contains(CpuFeature::SSE2)

View File

@@ -4,10 +4,10 @@ use crate::translator::FuncTranslator;
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator}; use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
use wasm_common::entity::{EntityRef, PrimaryMap, SecondaryMap}; use wasm_common::entity::{EntityRef, PrimaryMap, SecondaryMap};
use wasm_common::Features; use wasm_common::Features;
use wasm_common::{FunctionIndex, FunctionType, LocalFunctionIndex, MemoryIndex, TableIndex}; use wasm_common::{LocalFunctionIndex, MemoryIndex, TableIndex};
use wasmer_compiler::{ use wasmer_compiler::{
Compilation, CompileError, Compiler, CompilerConfig, FunctionBody, FunctionBodyData, Compilation, CompileError, Compiler, CompilerConfig, FunctionBodyData, ModuleTranslationState,
ModuleTranslationState, RelocationTarget, SectionIndex, Target, RelocationTarget, SectionIndex, Target,
}; };
use wasmer_runtime::{MemoryPlan, ModuleInfo, TablePlan}; use wasmer_runtime::{MemoryPlan, ModuleInfo, TablePlan};
@@ -112,32 +112,35 @@ impl Compiler for LLVMCompiler {
}) })
.collect::<PrimaryMap<LocalFunctionIndex, _>>(); .collect::<PrimaryMap<LocalFunctionIndex, _>>();
Ok(Compilation::new(functions, module_custom_sections, None)) let function_call_trampolines = module
} .signatures
.values()
fn compile_function_call_trampolines( .collect::<Vec<_>>()
&self,
signatures: &[FunctionType],
) -> Result<Vec<FunctionBody>, CompileError> {
signatures
.par_iter() .par_iter()
.map_init(FuncTrampoline::new, |func_trampoline, sig| { .map_init(FuncTrampoline::new, |func_trampoline, sig| {
func_trampoline.trampoline(sig, self.config()) func_trampoline.trampoline(sig, self.config())
}) })
.collect::<Result<Vec<_>, CompileError>>() .collect::<Vec<_>>()
} .into_iter()
.collect::<Result<PrimaryMap<_, _>, CompileError>>()?;
fn compile_dynamic_function_trampolines( let dynamic_function_trampolines = module
&self, .imported_function_types()
signatures: &[FunctionType], .collect::<Vec<_>>()
) -> Result<PrimaryMap<FunctionIndex, FunctionBody>, CompileError> {
Ok(signatures
.par_iter() .par_iter()
.map_init(FuncTrampoline::new, |func_trampoline, func_type| { .map_init(FuncTrampoline::new, |func_trampoline, func_type| {
func_trampoline.dynamic_trampoline(&func_type, self.config()) func_trampoline.dynamic_trampoline(&func_type, self.config())
}) })
.collect::<Result<Vec<_>, CompileError>>()? .collect::<Result<Vec<_>, CompileError>>()?
.into_iter() .into_iter()
.collect::<PrimaryMap<FunctionIndex, FunctionBody>>()) .collect::<PrimaryMap<_, _>>();
Ok(Compilation::new(
functions,
module_custom_sections,
function_call_trampolines,
dynamic_function_trampolines,
None,
))
} }
} }

View File

@@ -8256,7 +8256,7 @@ fn sort_call_movs(movs: &mut [(Location, GPR)]) {
} }
// Standard entry trampoline. // Standard entry trampoline.
pub fn gen_std_trampoline(sig: FunctionType) -> FunctionBody { pub fn gen_std_trampoline(sig: &FunctionType) -> FunctionBody {
let mut a = Assembler::new().unwrap(); let mut a = Assembler::new().unwrap();
// Calculate stack offset. // Calculate stack offset.

View File

@@ -120,31 +120,33 @@ impl Compiler for SinglepassCompiler {
.into_iter() .into_iter()
.collect::<PrimaryMap<LocalFunctionIndex, CompiledFunction>>(); .collect::<PrimaryMap<LocalFunctionIndex, CompiledFunction>>();
Ok(Compilation::new(functions, import_trampolines, None)) let function_call_trampolines = module
} .signatures
.values()
fn compile_function_call_trampolines( .collect::<Vec<_>>()
&self,
signatures: &[FunctionType],
) -> Result<Vec<FunctionBody>, CompileError> {
Ok(signatures
.par_iter() .par_iter()
.cloned() .cloned()
.map(gen_std_trampoline) .map(gen_std_trampoline)
.collect()) .collect::<Vec<_>>()
} .into_iter()
.collect::<PrimaryMap<_, _>>();
fn compile_dynamic_function_trampolines( let dynamic_function_trampolines = module
&self, .imported_function_types()
signatures: &[FunctionType], .collect::<Vec<_>>()
) -> Result<PrimaryMap<FunctionIndex, FunctionBody>, CompileError> {
let vmoffsets = VMOffsets::new_for_trampolines(8);
Ok(signatures
.par_iter() .par_iter()
.map(|func_type| gen_std_dynamic_import_trampoline(&vmoffsets, &func_type)) .map(|func_type| gen_std_dynamic_import_trampoline(&vmoffsets, &func_type))
.collect::<Vec<_>>() .collect::<Vec<_>>()
.into_iter() .into_iter()
.collect::<PrimaryMap<FunctionIndex, FunctionBody>>()) .collect::<PrimaryMap<FunctionIndex, FunctionBody>>();
Ok(Compilation::new(
functions,
import_trampolines,
function_call_trampolines,
dynamic_function_trampolines,
None,
))
} }
} }

View File

@@ -2,18 +2,15 @@
//! compilers will need to implement. //! compilers will need to implement.
use crate::error::CompileError; use crate::error::CompileError;
use crate::function::{Compilation, FunctionBody}; use crate::function::Compilation;
use crate::lib::std::boxed::Box; use crate::lib::std::boxed::Box;
use crate::lib::std::sync::Arc; use crate::lib::std::sync::Arc;
use crate::lib::std::vec::Vec;
use crate::target::Target; use crate::target::Target;
use crate::translator::FunctionMiddlewareGenerator; use crate::translator::FunctionMiddlewareGenerator;
use crate::FunctionBodyData; use crate::FunctionBodyData;
use crate::ModuleTranslationState; use crate::ModuleTranslationState;
use wasm_common::entity::PrimaryMap; use wasm_common::entity::PrimaryMap;
use wasm_common::{ use wasm_common::{Features, LocalFunctionIndex, MemoryIndex, TableIndex};
Features, FunctionIndex, FunctionType, LocalFunctionIndex, MemoryIndex, TableIndex,
};
use wasmer_runtime::ModuleInfo; use wasmer_runtime::ModuleInfo;
use wasmer_runtime::{MemoryPlan, TablePlan}; use wasmer_runtime::{MemoryPlan, TablePlan};
use wasmparser::{validate, OperatorValidatorConfig, ValidatingParserConfig}; use wasmparser::{validate, OperatorValidatorConfig, ValidatingParserConfig};
@@ -72,8 +69,7 @@ pub trait Compiler {
/// Compiles a parsed module. /// Compiles a parsed module.
/// ///
/// It returns the `Compilation` result (with a list of `CompiledFunction`) /// It returns the [`Compilation`] or a [`CompileError`].
/// or a `CompileError`.
fn compile_module<'data, 'module>( fn compile_module<'data, 'module>(
&self, &self,
module: &'module ModuleInfo, module: &'module ModuleInfo,
@@ -85,40 +81,4 @@ pub trait Compiler {
// The plans for the module tables (imported and local) // The plans for the module tables (imported and local)
table_plans: PrimaryMap<TableIndex, TablePlan>, table_plans: PrimaryMap<TableIndex, TablePlan>,
) -> Result<Compilation, CompileError>; ) -> Result<Compilation, CompileError>;
/// Compile the trampolines to call a function defined in
/// a Wasm module.
///
/// This allows us to call easily Wasm functions, such as:
///
/// ```ignore
/// let func = instance.exports.get_function("my_func");
/// func.call(&[Value::I32(1)]);
/// ```
fn compile_function_call_trampolines(
&self,
signatures: &[FunctionType],
) -> Result<Vec<FunctionBody>, CompileError>;
/// Compile the trampolines to call a dynamic function defined in
/// a host, from a Wasm module.
///
/// This allows us to create dynamic Wasm functions, such as:
///
/// ```ignore
/// fn my_func(values: &[Val]) -> Result<Vec<Val>, RuntimeError> {
/// // do something
/// }
///
/// let my_func_type = FunctionType::new(vec![Type::I32], vec![Type::I32]);
/// let imports = imports!{
/// "namespace" => {
/// "my_func" => Function::new_dynamic(my_func_type, my_func),
/// }
/// }
/// ```
fn compile_dynamic_function_trampolines(
&self,
signatures: &[FunctionType],
) -> Result<PrimaryMap<FunctionIndex, FunctionBody>, CompileError>;
} }

View File

@@ -16,7 +16,7 @@ use crate::{CompiledFunctionUnwindInfo, FunctionAddressMap, JumpTableOffsets, Re
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use wasm_common::entity::PrimaryMap; use wasm_common::entity::PrimaryMap;
use wasm_common::LocalFunctionIndex; use wasm_common::{FunctionIndex, LocalFunctionIndex, SignatureIndex};
/// The frame info for a Compiled function. /// The frame info for a Compiled function.
/// ///
@@ -101,10 +101,44 @@ impl Dwarf {
pub struct Compilation { pub struct Compilation {
/// Compiled code for the function bodies. /// Compiled code for the function bodies.
functions: Functions, functions: Functions,
/// Custom sections for the module. /// Custom sections for the module.
/// It will hold the data, for example, for constants used in a /// It will hold the data, for example, for constants used in a
/// function, global variables, rodata_64, hot/cold function partitioning, ... /// function, global variables, rodata_64, hot/cold function partitioning, ...
custom_sections: CustomSections, custom_sections: CustomSections,
/// Trampolines to call a function defined locally in the wasm via a
/// provided `Vec` of values.
///
/// This allows us to call easily Wasm functions, such as:
///
/// ```ignore
/// let func = instance.exports.get_function("my_func");
/// func.call(&[Value::I32(1)]);
/// ```
function_call_trampolines: PrimaryMap<SignatureIndex, FunctionBody>,
/// Trampolines to call a dynamic function defined in
/// a host, from a Wasm module.
///
/// This allows us to create dynamic Wasm functions, such as:
///
/// ```ignore
/// fn my_func(values: &[Val]) -> Result<Vec<Val>, RuntimeError> {
/// // do something
/// }
///
/// let my_func_type = FunctionType::new(vec![Type::I32], vec![Type::I32]);
/// let imports = imports!{
/// "namespace" => {
/// "my_func" => Function::new_dynamic(&store, my_func_type, my_func),
/// }
/// }
/// ```
///
/// Note: Dynamic function trampolines are only compiled for imported function types.
dynamic_function_trampolines: PrimaryMap<FunctionIndex, FunctionBody>,
/// Section ids corresponding to the Dwarf debug info /// Section ids corresponding to the Dwarf debug info
debug: Option<Dwarf>, debug: Option<Dwarf>,
} }
@@ -114,11 +148,15 @@ impl Compilation {
pub fn new( pub fn new(
functions: Functions, functions: Functions,
custom_sections: CustomSections, custom_sections: CustomSections,
function_call_trampolines: PrimaryMap<SignatureIndex, FunctionBody>,
dynamic_function_trampolines: PrimaryMap<FunctionIndex, FunctionBody>,
debug: Option<Dwarf>, debug: Option<Dwarf>,
) -> Self { ) -> Self {
Self { Self {
functions, functions,
custom_sections, custom_sections,
function_call_trampolines,
dynamic_function_trampolines,
debug, debug,
} }
} }
@@ -170,6 +208,16 @@ impl Compilation {
.collect::<PrimaryMap<LocalFunctionIndex, _>>() .collect::<PrimaryMap<LocalFunctionIndex, _>>()
} }
/// Gets function call trampolines.
pub fn get_function_call_trampolines(&self) -> PrimaryMap<SignatureIndex, FunctionBody> {
self.function_call_trampolines.clone()
}
/// Gets function call trampolines.
pub fn get_dynamic_function_trampolines(&self) -> PrimaryMap<FunctionIndex, FunctionBody> {
self.dynamic_function_trampolines.clone()
}
/// Gets custom section data. /// Gets custom section data.
pub fn get_custom_sections(&self) -> PrimaryMap<SectionIndex, CustomSection> { pub fn get_custom_sections(&self) -> PrimaryMap<SectionIndex, CustomSection> {
self.custom_sections.clone() self.custom_sections.clone()

View File

@@ -17,6 +17,7 @@ use lazy_static::lazy_static;
use std::cell::UnsafeCell; use std::cell::UnsafeCell;
use std::collections::HashMap; use std::collections::HashMap;
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::Arc;
use std::{f64, ffi::c_void}; use std::{f64, ffi::c_void};
use wasmer::{ use wasmer::{
imports, namespace, Exports, ExternRef, Function, FunctionType, Global, ImportObject, Instance, imports, namespace, Exports, ExternRef, Function, FunctionType, Global, ImportObject, Instance,
@@ -68,9 +69,10 @@ pub use self::utils::{
get_emscripten_table_size, is_emscripten_module, get_emscripten_table_size, is_emscripten_module,
}; };
#[derive(Clone)]
/// The environment provided to the Emscripten imports. /// The environment provided to the Emscripten imports.
pub struct EmEnv { pub struct EmEnv {
memory: Option<Memory>, memory: Option<Arc<Memory>>,
data: *mut EmscriptenData<'static>, data: *mut EmscriptenData<'static>,
} }
@@ -82,7 +84,7 @@ impl EmEnv {
} }
} }
pub fn set_memory(&mut self, memory: Memory) { pub fn set_memory(&mut self, memory: Arc<Memory>) {
self.memory = Some(memory) self.memory = Some(memory)
} }
@@ -463,7 +465,7 @@ pub fn emscripten_call_main(
} }
/// Top level function to execute emscripten /// Top level function to execute emscripten
pub fn run_emscripten_instance( pub fn run_emscripten_instance<'a>(
instance: &mut Instance, instance: &mut Instance,
env: &mut EmEnv, env: &mut EmEnv,
globals: &mut EmscriptenGlobals, globals: &mut EmscriptenGlobals,
@@ -473,7 +475,7 @@ pub fn run_emscripten_instance(
mapped_dirs: Vec<(String, PathBuf)>, mapped_dirs: Vec<(String, PathBuf)>,
) -> Result<(), RuntimeError> { ) -> Result<(), RuntimeError> {
let mut data = EmscriptenData::new(instance, &globals.data, mapped_dirs.into_iter().collect()); let mut data = EmscriptenData::new(instance, &globals.data, mapped_dirs.into_iter().collect());
env.set_memory(globals.memory.clone()); env.set_memory(Arc::new(globals.memory.clone()));
env.set_data(&mut data as *mut _ as *mut c_void); env.set_data(&mut data as *mut _ as *mut c_void);
set_up_emscripten(instance)?; set_up_emscripten(instance)?;
@@ -646,9 +648,17 @@ pub fn generate_emscripten_env(
env: &mut EmEnv, env: &mut EmEnv,
) -> ImportObject { ) -> ImportObject {
let abort_on_cannot_grow_memory_export = if globals.data.use_old_abort_on_cannot_grow_memory { let abort_on_cannot_grow_memory_export = if globals.data.use_old_abort_on_cannot_grow_memory {
Function::new_env(store, env, crate::memory::abort_on_cannot_grow_memory_old) Function::new_env(
store,
env.clone(),
crate::memory::abort_on_cannot_grow_memory_old,
)
} else { } else {
Function::new_env(store, env, crate::memory::abort_on_cannot_grow_memory) Function::new_env(
store,
env.clone(),
crate::memory::abort_on_cannot_grow_memory,
)
}; };
let mut env_ns: Exports = namespace! { let mut env_ns: Exports = namespace! {
@@ -669,256 +679,256 @@ pub fn generate_emscripten_env(
"tempDoublePtr" => Global::new(store, Val::I32(globals.data.temp_double_ptr as i32)), "tempDoublePtr" => Global::new(store, Val::I32(globals.data.temp_double_ptr as i32)),
// inet // inet
"_inet_addr" => Function::new_env(store, env, crate::inet::addr), "_inet_addr" => Function::new_env(store, env.clone(), crate::inet::addr),
// IO // IO
"printf" => Function::new_env(store, env, crate::io::printf), "printf" => Function::new_env(store, env.clone(), crate::io::printf),
"putchar" => Function::new_env(store, env, crate::io::putchar), "putchar" => Function::new_env(store, env.clone(), crate::io::putchar),
"___lock" => Function::new_env(store, env, crate::lock::___lock), "___lock" => Function::new_env(store, env.clone(), crate::lock::___lock),
"___unlock" => Function::new_env(store, env, crate::lock::___unlock), "___unlock" => Function::new_env(store, env.clone(), crate::lock::___unlock),
"___wait" => Function::new_env(store, env, crate::lock::___wait), "___wait" => Function::new_env(store, env.clone(), crate::lock::___wait),
"_flock" => Function::new_env(store, env, crate::lock::_flock), "_flock" => Function::new_env(store, env.clone(), crate::lock::_flock),
"_chroot" => Function::new_env(store, env, crate::io::chroot), "_chroot" => Function::new_env(store, env.clone(), crate::io::chroot),
"_getprotobyname" => Function::new_env(store, env, crate::io::getprotobyname), "_getprotobyname" => Function::new_env(store, env.clone(), crate::io::getprotobyname),
"_getprotobynumber" => Function::new_env(store, env, crate::io::getprotobynumber), "_getprotobynumber" => Function::new_env(store, env.clone(), crate::io::getprotobynumber),
"_getpwuid" => Function::new_env(store, env, crate::io::getpwuid), "_getpwuid" => Function::new_env(store, env.clone(), crate::io::getpwuid),
"_sigdelset" => Function::new_env(store, env, crate::io::sigdelset), "_sigdelset" => Function::new_env(store, env.clone(), crate::io::sigdelset),
"_sigfillset" => Function::new_env(store, env, crate::io::sigfillset), "_sigfillset" => Function::new_env(store, env.clone(), crate::io::sigfillset),
"_tzset" => Function::new_env(store, env, crate::io::tzset), "_tzset" => Function::new_env(store, env.clone(), crate::io::tzset),
"_strptime" => Function::new_env(store, env, crate::io::strptime), "_strptime" => Function::new_env(store, env.clone(), crate::io::strptime),
// exec // exec
"_execvp" => Function::new_env(store, env, crate::exec::execvp), "_execvp" => Function::new_env(store, env.clone(), crate::exec::execvp),
"_execl" => Function::new_env(store, env, crate::exec::execl), "_execl" => Function::new_env(store, env.clone(), crate::exec::execl),
"_execle" => Function::new_env(store, env, crate::exec::execle), "_execle" => Function::new_env(store, env.clone(), crate::exec::execle),
// exit // exit
"__exit" => Function::new_env(store, env, crate::exit::exit), "__exit" => Function::new_env(store, env.clone(), crate::exit::exit),
// Env // Env
"___assert_fail" => Function::new_env(store, env, crate::env::___assert_fail), "___assert_fail" => Function::new_env(store, env.clone(), crate::env::___assert_fail),
"_getenv" => Function::new_env(store, env, crate::env::_getenv), "_getenv" => Function::new_env(store, env.clone(), crate::env::_getenv),
"_setenv" => Function::new_env(store, env, crate::env::_setenv), "_setenv" => Function::new_env(store, env.clone(), crate::env::_setenv),
"_putenv" => Function::new_env(store, env, crate::env::_putenv), "_putenv" => Function::new_env(store, env.clone(), crate::env::_putenv),
"_unsetenv" => Function::new_env(store, env, crate::env::_unsetenv), "_unsetenv" => Function::new_env(store, env.clone(), crate::env::_unsetenv),
"_getpwnam" => Function::new_env(store, env, crate::env::_getpwnam), "_getpwnam" => Function::new_env(store, env.clone(), crate::env::_getpwnam),
"_getgrnam" => Function::new_env(store, env, crate::env::_getgrnam), "_getgrnam" => Function::new_env(store, env.clone(), crate::env::_getgrnam),
"___buildEnvironment" => Function::new_env(store, env, crate::env::___build_environment), "___buildEnvironment" => Function::new_env(store, env.clone(), crate::env::___build_environment),
"___setErrNo" => Function::new_env(store, env, crate::errno::___seterrno), "___setErrNo" => Function::new_env(store, env.clone(), crate::errno::___seterrno),
"_getpagesize" => Function::new_env(store, env, crate::env::_getpagesize), "_getpagesize" => Function::new_env(store, env.clone(), crate::env::_getpagesize),
"_sysconf" => Function::new_env(store, env, crate::env::_sysconf), "_sysconf" => Function::new_env(store, env.clone(), crate::env::_sysconf),
"_getaddrinfo" => Function::new_env(store, env, crate::env::_getaddrinfo), "_getaddrinfo" => Function::new_env(store, env.clone(), crate::env::_getaddrinfo),
"_times" => Function::new_env(store, env, crate::env::_times), "_times" => Function::new_env(store, env.clone(), crate::env::_times),
"_pathconf" => Function::new_env(store, env, crate::env::_pathconf), "_pathconf" => Function::new_env(store, env.clone(), crate::env::_pathconf),
"_fpathconf" => Function::new_env(store, env, crate::env::_fpathconf), "_fpathconf" => Function::new_env(store, env.clone(), crate::env::_fpathconf),
// Syscalls // Syscalls
"___syscall1" => Function::new_env(store, env, crate::syscalls::___syscall1), "___syscall1" => Function::new_env(store, env.clone(), crate::syscalls::___syscall1),
"___syscall3" => Function::new_env(store, env, crate::syscalls::___syscall3), "___syscall3" => Function::new_env(store, env.clone(), crate::syscalls::___syscall3),
"___syscall4" => Function::new_env(store, env, crate::syscalls::___syscall4), "___syscall4" => Function::new_env(store, env.clone(), crate::syscalls::___syscall4),
"___syscall5" => Function::new_env(store, env, crate::syscalls::___syscall5), "___syscall5" => Function::new_env(store, env.clone(), crate::syscalls::___syscall5),
"___syscall6" => Function::new_env(store, env, crate::syscalls::___syscall6), "___syscall6" => Function::new_env(store, env.clone(), crate::syscalls::___syscall6),
"___syscall9" => Function::new_env(store, env, crate::syscalls::___syscall9), "___syscall9" => Function::new_env(store, env.clone(), crate::syscalls::___syscall9),
"___syscall10" => Function::new_env(store, env, crate::syscalls::___syscall10), "___syscall10" => Function::new_env(store, env.clone(), crate::syscalls::___syscall10),
"___syscall12" => Function::new_env(store, env, crate::syscalls::___syscall12), "___syscall12" => Function::new_env(store, env.clone(), crate::syscalls::___syscall12),
"___syscall14" => Function::new_env(store, env, crate::syscalls::___syscall14), "___syscall14" => Function::new_env(store, env.clone(), crate::syscalls::___syscall14),
"___syscall15" => Function::new_env(store, env, crate::syscalls::___syscall15), "___syscall15" => Function::new_env(store, env.clone(), crate::syscalls::___syscall15),
"___syscall20" => Function::new_env(store, env, crate::syscalls::___syscall20), "___syscall20" => Function::new_env(store, env.clone(), crate::syscalls::___syscall20),
"___syscall21" => Function::new_env(store, env, crate::syscalls::___syscall21), "___syscall21" => Function::new_env(store, env.clone(), crate::syscalls::___syscall21),
"___syscall25" => Function::new_env(store, env, crate::syscalls::___syscall25), "___syscall25" => Function::new_env(store, env.clone(), crate::syscalls::___syscall25),
"___syscall29" => Function::new_env(store, env, crate::syscalls::___syscall29), "___syscall29" => Function::new_env(store, env.clone(), crate::syscalls::___syscall29),
"___syscall32" => Function::new_env(store, env, crate::syscalls::___syscall32), "___syscall32" => Function::new_env(store, env.clone(), crate::syscalls::___syscall32),
"___syscall33" => Function::new_env(store, env, crate::syscalls::___syscall33), "___syscall33" => Function::new_env(store, env.clone(), crate::syscalls::___syscall33),
"___syscall34" => Function::new_env(store, env, crate::syscalls::___syscall34), "___syscall34" => Function::new_env(store, env.clone(), crate::syscalls::___syscall34),
"___syscall36" => Function::new_env(store, env, crate::syscalls::___syscall36), "___syscall36" => Function::new_env(store, env.clone(), crate::syscalls::___syscall36),
"___syscall39" => Function::new_env(store, env, crate::syscalls::___syscall39), "___syscall39" => Function::new_env(store, env.clone(), crate::syscalls::___syscall39),
"___syscall38" => Function::new_env(store, env, crate::syscalls::___syscall38), "___syscall38" => Function::new_env(store, env.clone(), crate::syscalls::___syscall38),
"___syscall40" => Function::new_env(store, env, crate::syscalls::___syscall40), "___syscall40" => Function::new_env(store, env.clone(), crate::syscalls::___syscall40),
"___syscall41" => Function::new_env(store, env, crate::syscalls::___syscall41), "___syscall41" => Function::new_env(store, env.clone(), crate::syscalls::___syscall41),
"___syscall42" => Function::new_env(store, env, crate::syscalls::___syscall42), "___syscall42" => Function::new_env(store, env.clone(), crate::syscalls::___syscall42),
"___syscall51" => Function::new_env(store, env, crate::syscalls::___syscall51), "___syscall51" => Function::new_env(store, env.clone(), crate::syscalls::___syscall51),
"___syscall52" => Function::new_env(store, env, crate::syscalls::___syscall52), "___syscall52" => Function::new_env(store, env.clone(), crate::syscalls::___syscall52),
"___syscall53" => Function::new_env(store, env, crate::syscalls::___syscall53), "___syscall53" => Function::new_env(store, env.clone(), crate::syscalls::___syscall53),
"___syscall54" => Function::new_env(store, env, crate::syscalls::___syscall54), "___syscall54" => Function::new_env(store, env.clone(), crate::syscalls::___syscall54),
"___syscall57" => Function::new_env(store, env, crate::syscalls::___syscall57), "___syscall57" => Function::new_env(store, env.clone(), crate::syscalls::___syscall57),
"___syscall60" => Function::new_env(store, env, crate::syscalls::___syscall60), "___syscall60" => Function::new_env(store, env.clone(), crate::syscalls::___syscall60),
"___syscall63" => Function::new_env(store, env, crate::syscalls::___syscall63), "___syscall63" => Function::new_env(store, env.clone(), crate::syscalls::___syscall63),
"___syscall64" => Function::new_env(store, env, crate::syscalls::___syscall64), "___syscall64" => Function::new_env(store, env.clone(), crate::syscalls::___syscall64),
"___syscall66" => Function::new_env(store, env, crate::syscalls::___syscall66), "___syscall66" => Function::new_env(store, env.clone(), crate::syscalls::___syscall66),
"___syscall75" => Function::new_env(store, env, crate::syscalls::___syscall75), "___syscall75" => Function::new_env(store, env.clone(), crate::syscalls::___syscall75),
"___syscall77" => Function::new_env(store, env, crate::syscalls::___syscall77), "___syscall77" => Function::new_env(store, env.clone(), crate::syscalls::___syscall77),
"___syscall83" => Function::new_env(store, env, crate::syscalls::___syscall83), "___syscall83" => Function::new_env(store, env.clone(), crate::syscalls::___syscall83),
"___syscall85" => Function::new_env(store, env, crate::syscalls::___syscall85), "___syscall85" => Function::new_env(store, env.clone(), crate::syscalls::___syscall85),
"___syscall91" => Function::new_env(store, env, crate::syscalls::___syscall91), "___syscall91" => Function::new_env(store, env.clone(), crate::syscalls::___syscall91),
"___syscall94" => Function::new_env(store, env, crate::syscalls::___syscall94), "___syscall94" => Function::new_env(store, env.clone(), crate::syscalls::___syscall94),
"___syscall96" => Function::new_env(store, env, crate::syscalls::___syscall96), "___syscall96" => Function::new_env(store, env.clone(), crate::syscalls::___syscall96),
"___syscall97" => Function::new_env(store, env, crate::syscalls::___syscall97), "___syscall97" => Function::new_env(store, env.clone(), crate::syscalls::___syscall97),
"___syscall102" => Function::new_env(store, env, crate::syscalls::___syscall102), "___syscall102" => Function::new_env(store, env.clone(), crate::syscalls::___syscall102),
"___syscall110" => Function::new_env(store, env, crate::syscalls::___syscall110), "___syscall110" => Function::new_env(store, env.clone(), crate::syscalls::___syscall110),
"___syscall114" => Function::new_env(store, env, crate::syscalls::___syscall114), "___syscall114" => Function::new_env(store, env.clone(), crate::syscalls::___syscall114),
"___syscall118" => Function::new_env(store, env, crate::syscalls::___syscall118), "___syscall118" => Function::new_env(store, env.clone(), crate::syscalls::___syscall118),
"___syscall121" => Function::new_env(store, env, crate::syscalls::___syscall121), "___syscall121" => Function::new_env(store, env.clone(), crate::syscalls::___syscall121),
"___syscall122" => Function::new_env(store, env, crate::syscalls::___syscall122), "___syscall122" => Function::new_env(store, env.clone(), crate::syscalls::___syscall122),
"___syscall125" => Function::new_env(store, env, crate::syscalls::___syscall125), "___syscall125" => Function::new_env(store, env.clone(), crate::syscalls::___syscall125),
"___syscall132" => Function::new_env(store, env, crate::syscalls::___syscall132), "___syscall132" => Function::new_env(store, env.clone(), crate::syscalls::___syscall132),
"___syscall133" => Function::new_env(store, env, crate::syscalls::___syscall133), "___syscall133" => Function::new_env(store, env.clone(), crate::syscalls::___syscall133),
"___syscall140" => Function::new_env(store, env, crate::syscalls::___syscall140), "___syscall140" => Function::new_env(store, env.clone(), crate::syscalls::___syscall140),
"___syscall142" => Function::new_env(store, env, crate::syscalls::___syscall142), "___syscall142" => Function::new_env(store, env.clone(), crate::syscalls::___syscall142),
"___syscall144" => Function::new_env(store, env, crate::syscalls::___syscall144), "___syscall144" => Function::new_env(store, env.clone(), crate::syscalls::___syscall144),
"___syscall145" => Function::new_env(store, env, crate::syscalls::___syscall145), "___syscall145" => Function::new_env(store, env.clone(), crate::syscalls::___syscall145),
"___syscall146" => Function::new_env(store, env, crate::syscalls::___syscall146), "___syscall146" => Function::new_env(store, env.clone(), crate::syscalls::___syscall146),
"___syscall147" => Function::new_env(store, env, crate::syscalls::___syscall147), "___syscall147" => Function::new_env(store, env.clone(), crate::syscalls::___syscall147),
"___syscall148" => Function::new_env(store, env, crate::syscalls::___syscall148), "___syscall148" => Function::new_env(store, env.clone(), crate::syscalls::___syscall148),
"___syscall150" => Function::new_env(store, env, crate::syscalls::___syscall150), "___syscall150" => Function::new_env(store, env.clone(), crate::syscalls::___syscall150),
"___syscall151" => Function::new_env(store, env, crate::syscalls::___syscall151), "___syscall151" => Function::new_env(store, env.clone(), crate::syscalls::___syscall151),
"___syscall152" => Function::new_env(store, env, crate::syscalls::___syscall152), "___syscall152" => Function::new_env(store, env.clone(), crate::syscalls::___syscall152),
"___syscall153" => Function::new_env(store, env, crate::syscalls::___syscall153), "___syscall153" => Function::new_env(store, env.clone(), crate::syscalls::___syscall153),
"___syscall163" => Function::new_env(store, env, crate::syscalls::___syscall163), "___syscall163" => Function::new_env(store, env.clone(), crate::syscalls::___syscall163),
"___syscall168" => Function::new_env(store, env, crate::syscalls::___syscall168), "___syscall168" => Function::new_env(store, env.clone(), crate::syscalls::___syscall168),
"___syscall180" => Function::new_env(store, env, crate::syscalls::___syscall180), "___syscall180" => Function::new_env(store, env.clone(), crate::syscalls::___syscall180),
"___syscall181" => Function::new_env(store, env, crate::syscalls::___syscall181), "___syscall181" => Function::new_env(store, env.clone(), crate::syscalls::___syscall181),
"___syscall183" => Function::new_env(store, env, crate::syscalls::___syscall183), "___syscall183" => Function::new_env(store, env.clone(), crate::syscalls::___syscall183),
"___syscall191" => Function::new_env(store, env, crate::syscalls::___syscall191), "___syscall191" => Function::new_env(store, env.clone(), crate::syscalls::___syscall191),
"___syscall192" => Function::new_env(store, env, crate::syscalls::___syscall192), "___syscall192" => Function::new_env(store, env.clone(), crate::syscalls::___syscall192),
"___syscall193" => Function::new_env(store, env, crate::syscalls::___syscall193), "___syscall193" => Function::new_env(store, env.clone(), crate::syscalls::___syscall193),
"___syscall194" => Function::new_env(store, env, crate::syscalls::___syscall194), "___syscall194" => Function::new_env(store, env.clone(), crate::syscalls::___syscall194),
"___syscall195" => Function::new_env(store, env, crate::syscalls::___syscall195), "___syscall195" => Function::new_env(store, env.clone(), crate::syscalls::___syscall195),
"___syscall196" => Function::new_env(store, env, crate::syscalls::___syscall196), "___syscall196" => Function::new_env(store, env.clone(), crate::syscalls::___syscall196),
"___syscall197" => Function::new_env(store, env, crate::syscalls::___syscall197), "___syscall197" => Function::new_env(store, env.clone(), crate::syscalls::___syscall197),
"___syscall198" => Function::new_env(store, env, crate::syscalls::___syscall198), "___syscall198" => Function::new_env(store, env.clone(), crate::syscalls::___syscall198),
"___syscall199" => Function::new_env(store, env, crate::syscalls::___syscall199), "___syscall199" => Function::new_env(store, env.clone(), crate::syscalls::___syscall199),
"___syscall200" => Function::new_env(store, env, crate::syscalls::___syscall200), "___syscall200" => Function::new_env(store, env.clone(), crate::syscalls::___syscall200),
"___syscall201" => Function::new_env(store, env, crate::syscalls::___syscall201), "___syscall201" => Function::new_env(store, env.clone(), crate::syscalls::___syscall201),
"___syscall202" => Function::new_env(store, env, crate::syscalls::___syscall202), "___syscall202" => Function::new_env(store, env.clone(), crate::syscalls::___syscall202),
"___syscall205" => Function::new_env(store, env, crate::syscalls::___syscall205), "___syscall205" => Function::new_env(store, env.clone(), crate::syscalls::___syscall205),
"___syscall207" => Function::new_env(store, env, crate::syscalls::___syscall207), "___syscall207" => Function::new_env(store, env.clone(), crate::syscalls::___syscall207),
"___syscall209" => Function::new_env(store, env, crate::syscalls::___syscall209), "___syscall209" => Function::new_env(store, env.clone(), crate::syscalls::___syscall209),
"___syscall211" => Function::new_env(store, env, crate::syscalls::___syscall211), "___syscall211" => Function::new_env(store, env.clone(), crate::syscalls::___syscall211),
"___syscall212" => Function::new_env(store, env, crate::syscalls::___syscall212), "___syscall212" => Function::new_env(store, env.clone(), crate::syscalls::___syscall212),
"___syscall218" => Function::new_env(store, env, crate::syscalls::___syscall218), "___syscall218" => Function::new_env(store, env.clone(), crate::syscalls::___syscall218),
"___syscall219" => Function::new_env(store, env, crate::syscalls::___syscall219), "___syscall219" => Function::new_env(store, env.clone(), crate::syscalls::___syscall219),
"___syscall220" => Function::new_env(store, env, crate::syscalls::___syscall220), "___syscall220" => Function::new_env(store, env.clone(), crate::syscalls::___syscall220),
"___syscall221" => Function::new_env(store, env, crate::syscalls::___syscall221), "___syscall221" => Function::new_env(store, env.clone(), crate::syscalls::___syscall221),
"___syscall268" => Function::new_env(store, env, crate::syscalls::___syscall268), "___syscall268" => Function::new_env(store, env.clone(), crate::syscalls::___syscall268),
"___syscall269" => Function::new_env(store, env, crate::syscalls::___syscall269), "___syscall269" => Function::new_env(store, env.clone(), crate::syscalls::___syscall269),
"___syscall272" => Function::new_env(store, env, crate::syscalls::___syscall272), "___syscall272" => Function::new_env(store, env.clone(), crate::syscalls::___syscall272),
"___syscall295" => Function::new_env(store, env, crate::syscalls::___syscall295), "___syscall295" => Function::new_env(store, env.clone(), crate::syscalls::___syscall295),
"___syscall296" => Function::new_env(store, env, crate::syscalls::___syscall296), "___syscall296" => Function::new_env(store, env.clone(), crate::syscalls::___syscall296),
"___syscall297" => Function::new_env(store, env, crate::syscalls::___syscall297), "___syscall297" => Function::new_env(store, env.clone(), crate::syscalls::___syscall297),
"___syscall298" => Function::new_env(store, env, crate::syscalls::___syscall298), "___syscall298" => Function::new_env(store, env.clone(), crate::syscalls::___syscall298),
"___syscall300" => Function::new_env(store, env, crate::syscalls::___syscall300), "___syscall300" => Function::new_env(store, env.clone(), crate::syscalls::___syscall300),
"___syscall301" => Function::new_env(store, env, crate::syscalls::___syscall301), "___syscall301" => Function::new_env(store, env.clone(), crate::syscalls::___syscall301),
"___syscall302" => Function::new_env(store, env, crate::syscalls::___syscall302), "___syscall302" => Function::new_env(store, env.clone(), crate::syscalls::___syscall302),
"___syscall303" => Function::new_env(store, env, crate::syscalls::___syscall303), "___syscall303" => Function::new_env(store, env.clone(), crate::syscalls::___syscall303),
"___syscall304" => Function::new_env(store, env, crate::syscalls::___syscall304), "___syscall304" => Function::new_env(store, env.clone(), crate::syscalls::___syscall304),
"___syscall305" => Function::new_env(store, env, crate::syscalls::___syscall305), "___syscall305" => Function::new_env(store, env.clone(), crate::syscalls::___syscall305),
"___syscall306" => Function::new_env(store, env, crate::syscalls::___syscall306), "___syscall306" => Function::new_env(store, env.clone(), crate::syscalls::___syscall306),
"___syscall307" => Function::new_env(store, env, crate::syscalls::___syscall307), "___syscall307" => Function::new_env(store, env.clone(), crate::syscalls::___syscall307),
"___syscall308" => Function::new_env(store, env, crate::syscalls::___syscall308), "___syscall308" => Function::new_env(store, env.clone(), crate::syscalls::___syscall308),
"___syscall320" => Function::new_env(store, env, crate::syscalls::___syscall320), "___syscall320" => Function::new_env(store, env.clone(), crate::syscalls::___syscall320),
"___syscall324" => Function::new_env(store, env, crate::syscalls::___syscall324), "___syscall324" => Function::new_env(store, env.clone(), crate::syscalls::___syscall324),
"___syscall330" => Function::new_env(store, env, crate::syscalls::___syscall330), "___syscall330" => Function::new_env(store, env.clone(), crate::syscalls::___syscall330),
"___syscall331" => Function::new_env(store, env, crate::syscalls::___syscall331), "___syscall331" => Function::new_env(store, env.clone(), crate::syscalls::___syscall331),
"___syscall333" => Function::new_env(store, env, crate::syscalls::___syscall333), "___syscall333" => Function::new_env(store, env.clone(), crate::syscalls::___syscall333),
"___syscall334" => Function::new_env(store, env, crate::syscalls::___syscall334), "___syscall334" => Function::new_env(store, env.clone(), crate::syscalls::___syscall334),
"___syscall337" => Function::new_env(store, env, crate::syscalls::___syscall337), "___syscall337" => Function::new_env(store, env.clone(), crate::syscalls::___syscall337),
"___syscall340" => Function::new_env(store, env, crate::syscalls::___syscall340), "___syscall340" => Function::new_env(store, env.clone(), crate::syscalls::___syscall340),
"___syscall345" => Function::new_env(store, env, crate::syscalls::___syscall345), "___syscall345" => Function::new_env(store, env.clone(), crate::syscalls::___syscall345),
// Process // Process
"abort" => Function::new_env(store, env, crate::process::em_abort), "abort" => Function::new_env(store, env.clone(), crate::process::em_abort),
"_abort" => Function::new_env(store, env, crate::process::_abort), "_abort" => Function::new_env(store, env.clone(), crate::process::_abort),
"_prctl" => Function::new_env(store, env, crate::process::_prctl), "_prctl" => Function::new_env(store, env.clone(), crate::process::_prctl),
"abortStackOverflow" => Function::new_env(store, env, crate::process::abort_stack_overflow), "abortStackOverflow" => Function::new_env(store, env.clone(), crate::process::abort_stack_overflow),
"_llvm_trap" => Function::new_env(store, env, crate::process::_llvm_trap), "_llvm_trap" => Function::new_env(store, env.clone(), crate::process::_llvm_trap),
"_fork" => Function::new_env(store, env, crate::process::_fork), "_fork" => Function::new_env(store, env.clone(), crate::process::_fork),
"_exit" => Function::new_env(store, env, crate::process::_exit), "_exit" => Function::new_env(store, env.clone(), crate::process::_exit),
"_system" => Function::new_env(store, env, crate::process::_system), "_system" => Function::new_env(store, env.clone(), crate::process::_system),
"_popen" => Function::new_env(store, env, crate::process::_popen), "_popen" => Function::new_env(store, env.clone(), crate::process::_popen),
"_endgrent" => Function::new_env(store, env, crate::process::_endgrent), "_endgrent" => Function::new_env(store, env.clone(), crate::process::_endgrent),
"_execve" => Function::new_env(store, env, crate::process::_execve), "_execve" => Function::new_env(store, env.clone(), crate::process::_execve),
"_kill" => Function::new_env(store, env, crate::process::_kill), "_kill" => Function::new_env(store, env.clone(), crate::process::_kill),
"_llvm_stackrestore" => Function::new_env(store, env, crate::process::_llvm_stackrestore), "_llvm_stackrestore" => Function::new_env(store, env.clone(), crate::process::_llvm_stackrestore),
"_llvm_stacksave" => Function::new_env(store, env, crate::process::_llvm_stacksave), "_llvm_stacksave" => Function::new_env(store, env.clone(), crate::process::_llvm_stacksave),
"_llvm_eh_typeid_for" => Function::new_env(store, env, crate::process::_llvm_eh_typeid_for), "_llvm_eh_typeid_for" => Function::new_env(store, env.clone(), crate::process::_llvm_eh_typeid_for),
"_raise" => Function::new_env(store, env, crate::process::_raise), "_raise" => Function::new_env(store, env.clone(), crate::process::_raise),
"_sem_init" => Function::new_env(store, env, crate::process::_sem_init), "_sem_init" => Function::new_env(store, env.clone(), crate::process::_sem_init),
"_sem_destroy" => Function::new_env(store, env, crate::process::_sem_destroy), "_sem_destroy" => Function::new_env(store, env.clone(), crate::process::_sem_destroy),
"_sem_post" => Function::new_env(store, env, crate::process::_sem_post), "_sem_post" => Function::new_env(store, env.clone(), crate::process::_sem_post),
"_sem_wait" => Function::new_env(store, env, crate::process::_sem_wait), "_sem_wait" => Function::new_env(store, env.clone(), crate::process::_sem_wait),
"_getgrent" => Function::new_env(store, env, crate::process::_getgrent), "_getgrent" => Function::new_env(store, env.clone(), crate::process::_getgrent),
"_sched_yield" => Function::new_env(store, env, crate::process::_sched_yield), "_sched_yield" => Function::new_env(store, env.clone(), crate::process::_sched_yield),
"_setgrent" => Function::new_env(store, env, crate::process::_setgrent), "_setgrent" => Function::new_env(store, env.clone(), crate::process::_setgrent),
"_setgroups" => Function::new_env(store, env, crate::process::_setgroups), "_setgroups" => Function::new_env(store, env.clone(), crate::process::_setgroups),
"_setitimer" => Function::new_env(store, env, crate::process::_setitimer), "_setitimer" => Function::new_env(store, env.clone(), crate::process::_setitimer),
"_usleep" => Function::new_env(store, env, crate::process::_usleep), "_usleep" => Function::new_env(store, env.clone(), crate::process::_usleep),
"_nanosleep" => Function::new_env(store, env, crate::process::_nanosleep), "_nanosleep" => Function::new_env(store, env.clone(), crate::process::_nanosleep),
"_utime" => Function::new_env(store, env, crate::process::_utime), "_utime" => Function::new_env(store, env.clone(), crate::process::_utime),
"_utimes" => Function::new_env(store, env, crate::process::_utimes), "_utimes" => Function::new_env(store, env.clone(), crate::process::_utimes),
"_wait" => Function::new_env(store, env, crate::process::_wait), "_wait" => Function::new_env(store, env.clone(), crate::process::_wait),
"_wait3" => Function::new_env(store, env, crate::process::_wait3), "_wait3" => Function::new_env(store, env.clone(), crate::process::_wait3),
"_wait4" => Function::new_env(store, env, crate::process::_wait4), "_wait4" => Function::new_env(store, env.clone(), crate::process::_wait4),
"_waitid" => Function::new_env(store, env, crate::process::_waitid), "_waitid" => Function::new_env(store, env.clone(), crate::process::_waitid),
"_waitpid" => Function::new_env(store, env, crate::process::_waitpid), "_waitpid" => Function::new_env(store, env.clone(), crate::process::_waitpid),
// Emscripten // Emscripten
"_emscripten_asm_const_i" => Function::new_env(store, env, crate::emscripten_target::asm_const_i), "_emscripten_asm_const_i" => Function::new_env(store, env.clone(), crate::emscripten_target::asm_const_i),
"_emscripten_exit_with_live_runtime" => Function::new_env(store, env, crate::emscripten_target::exit_with_live_runtime), "_emscripten_exit_with_live_runtime" => Function::new_env(store, env.clone(), crate::emscripten_target::exit_with_live_runtime),
// Signal // Signal
"_sigemptyset" => Function::new_env(store, env, crate::signal::_sigemptyset), "_sigemptyset" => Function::new_env(store, env.clone(), crate::signal::_sigemptyset),
"_sigaddset" => Function::new_env(store, env, crate::signal::_sigaddset), "_sigaddset" => Function::new_env(store, env.clone(), crate::signal::_sigaddset),
"_sigprocmask" => Function::new_env(store, env, crate::signal::_sigprocmask), "_sigprocmask" => Function::new_env(store, env.clone(), crate::signal::_sigprocmask),
"_sigaction" => Function::new_env(store, env, crate::signal::_sigaction), "_sigaction" => Function::new_env(store, env.clone(), crate::signal::_sigaction),
"_signal" => Function::new_env(store, env, crate::signal::_signal), "_signal" => Function::new_env(store, env.clone(), crate::signal::_signal),
"_sigsuspend" => Function::new_env(store, env, crate::signal::_sigsuspend), "_sigsuspend" => Function::new_env(store, env.clone(), crate::signal::_sigsuspend),
// Memory // Memory
"abortOnCannotGrowMemory" => abort_on_cannot_grow_memory_export, "abortOnCannotGrowMemory" => abort_on_cannot_grow_memory_export,
"_emscripten_memcpy_big" => Function::new_env(store, env, crate::memory::_emscripten_memcpy_big), "_emscripten_memcpy_big" => Function::new_env(store, env.clone(), crate::memory::_emscripten_memcpy_big),
"_emscripten_get_heap_size" => Function::new_env(store, env, crate::memory::_emscripten_get_heap_size), "_emscripten_get_heap_size" => Function::new_env(store, env.clone(), crate::memory::_emscripten_get_heap_size),
"_emscripten_resize_heap" => Function::new_env(store, env, crate::memory::_emscripten_resize_heap), "_emscripten_resize_heap" => Function::new_env(store, env.clone(), crate::memory::_emscripten_resize_heap),
"enlargeMemory" => Function::new_env(store, env, crate::memory::enlarge_memory), "enlargeMemory" => Function::new_env(store, env.clone(), crate::memory::enlarge_memory),
"segfault" => Function::new_env(store, env, crate::memory::segfault), "segfault" => Function::new_env(store, env.clone(), crate::memory::segfault),
"alignfault" => Function::new_env(store, env, crate::memory::alignfault), "alignfault" => Function::new_env(store, env.clone(), crate::memory::alignfault),
"ftfault" => Function::new_env(store, env, crate::memory::ftfault), "ftfault" => Function::new_env(store, env.clone(), crate::memory::ftfault),
"getTotalMemory" => Function::new_env(store, env, crate::memory::get_total_memory), "getTotalMemory" => Function::new_env(store, env.clone(), crate::memory::get_total_memory),
"_sbrk" => Function::new_env(store, env, crate::memory::sbrk), "_sbrk" => Function::new_env(store, env.clone(), crate::memory::sbrk),
"___map_file" => Function::new_env(store, env, crate::memory::___map_file), "___map_file" => Function::new_env(store, env.clone(), crate::memory::___map_file),
// Exception // Exception
"___cxa_allocate_exception" => Function::new_env(store, env, crate::exception::___cxa_allocate_exception), "___cxa_allocate_exception" => Function::new_env(store, env.clone(), crate::exception::___cxa_allocate_exception),
"___cxa_current_primary_exception" => Function::new_env(store, env, crate::exception::___cxa_current_primary_exception), "___cxa_current_primary_exception" => Function::new_env(store, env.clone(), crate::exception::___cxa_current_primary_exception),
"___cxa_decrement_exception_refcount" => Function::new_env(store, env, crate::exception::___cxa_decrement_exception_refcount), "___cxa_decrement_exception_refcount" => Function::new_env(store, env.clone(), crate::exception::___cxa_decrement_exception_refcount),
"___cxa_increment_exception_refcount" => Function::new_env(store, env, crate::exception::___cxa_increment_exception_refcount), "___cxa_increment_exception_refcount" => Function::new_env(store, env.clone(), crate::exception::___cxa_increment_exception_refcount),
"___cxa_rethrow_primary_exception" => Function::new_env(store, env, crate::exception::___cxa_rethrow_primary_exception), "___cxa_rethrow_primary_exception" => Function::new_env(store, env.clone(), crate::exception::___cxa_rethrow_primary_exception),
"___cxa_throw" => Function::new_env(store, env, crate::exception::___cxa_throw), "___cxa_throw" => Function::new_env(store, env.clone(), crate::exception::___cxa_throw),
"___cxa_begin_catch" => Function::new_env(store, env, crate::exception::___cxa_begin_catch), "___cxa_begin_catch" => Function::new_env(store, env.clone(), crate::exception::___cxa_begin_catch),
"___cxa_end_catch" => Function::new_env(store, env, crate::exception::___cxa_end_catch), "___cxa_end_catch" => Function::new_env(store, env.clone(), crate::exception::___cxa_end_catch),
"___cxa_uncaught_exception" => Function::new_env(store, env, crate::exception::___cxa_uncaught_exception), "___cxa_uncaught_exception" => Function::new_env(store, env.clone(), crate::exception::___cxa_uncaught_exception),
"___cxa_pure_virtual" => Function::new_env(store, env, crate::exception::___cxa_pure_virtual), "___cxa_pure_virtual" => Function::new_env(store, env.clone(), crate::exception::___cxa_pure_virtual),
// Time // Time
"_gettimeofday" => Function::new_env(store, env, crate::time::_gettimeofday), "_gettimeofday" => Function::new_env(store, env.clone(), crate::time::_gettimeofday),
"_clock_getres" => Function::new_env(store, env, crate::time::_clock_getres), "_clock_getres" => Function::new_env(store, env.clone(), crate::time::_clock_getres),
"_clock_gettime" => Function::new_env(store, env, crate::time::_clock_gettime), "_clock_gettime" => Function::new_env(store, env.clone(), crate::time::_clock_gettime),
"_clock_settime" => Function::new_env(store, env, crate::time::_clock_settime), "_clock_settime" => Function::new_env(store, env.clone(), crate::time::_clock_settime),
"___clock_gettime" => Function::new_env(store, env, crate::time::_clock_gettime), "___clock_gettime" => Function::new_env(store, env.clone(), crate::time::_clock_gettime),
"_clock" => Function::new_env(store, env, crate::time::_clock), "_clock" => Function::new_env(store, env.clone(), crate::time::_clock),
"_difftime" => Function::new_env(store, env, crate::time::_difftime), "_difftime" => Function::new_env(store, env.clone(), crate::time::_difftime),
"_asctime" => Function::new_env(store, env, crate::time::_asctime), "_asctime" => Function::new_env(store, env.clone(), crate::time::_asctime),
"_asctime_r" => Function::new_env(store, env, crate::time::_asctime_r), "_asctime_r" => Function::new_env(store, env.clone(), crate::time::_asctime_r),
"_localtime" => Function::new_env(store, env, crate::time::_localtime), "_localtime" => Function::new_env(store, env.clone(), crate::time::_localtime),
"_time" => Function::new_env(store, env, crate::time::_time), "_time" => Function::new_env(store, env.clone(), crate::time::_time),
"_timegm" => Function::new_env(store, env, crate::time::_timegm), "_timegm" => Function::new_env(store, env.clone(), crate::time::_timegm),
"_strftime" => Function::new_env(store, env, crate::time::_strftime), "_strftime" => Function::new_env(store, env.clone(), crate::time::_strftime),
"_strftime_l" => Function::new_env(store, env, crate::time::_strftime_l), "_strftime_l" => Function::new_env(store, env.clone(), crate::time::_strftime_l),
"_localtime_r" => Function::new_env(store, env, crate::time::_localtime_r), "_localtime_r" => Function::new_env(store, env.clone(), crate::time::_localtime_r),
"_gmtime_r" => Function::new_env(store, env, crate::time::_gmtime_r), "_gmtime_r" => Function::new_env(store, env.clone(), crate::time::_gmtime_r),
"_ctime" => Function::new_env(store, env, crate::time::_ctime), "_ctime" => Function::new_env(store, env.clone(), crate::time::_ctime),
"_ctime_r" => Function::new_env(store, env, crate::time::_ctime_r), "_ctime_r" => Function::new_env(store, env.clone(), crate::time::_ctime_r),
"_mktime" => Function::new_env(store, env, crate::time::_mktime), "_mktime" => Function::new_env(store, env.clone(), crate::time::_mktime),
"_gmtime" => Function::new_env(store, env, crate::time::_gmtime), "_gmtime" => Function::new_env(store, env.clone(), crate::time::_gmtime),
// Math // Math
"sqrt" => Function::new(store, crate::math::sqrt), "sqrt" => Function::new(store, crate::math::sqrt),
@@ -937,16 +947,16 @@ pub fn generate_emscripten_env(
"_llvm_exp2_f64" => Function::new(store, crate::math::_llvm_exp2_f64), "_llvm_exp2_f64" => Function::new(store, crate::math::_llvm_exp2_f64),
"_llvm_trunc_f64" => Function::new(store, crate::math::_llvm_trunc_f64), "_llvm_trunc_f64" => Function::new(store, crate::math::_llvm_trunc_f64),
"_llvm_fma_f64" => Function::new(store, crate::math::_llvm_fma_f64), "_llvm_fma_f64" => Function::new(store, crate::math::_llvm_fma_f64),
"_emscripten_random" => Function::new_env(store, env, crate::math::_emscripten_random), "_emscripten_random" => Function::new_env(store, env.clone(), crate::math::_emscripten_random),
// Jump // Jump
"__setjmp" => Function::new_env(store, env, crate::jmp::__setjmp), "__setjmp" => Function::new_env(store, env.clone(), crate::jmp::__setjmp),
"__longjmp" => Function::new_env(store, env, crate::jmp::__longjmp), "__longjmp" => Function::new_env(store, env.clone(), crate::jmp::__longjmp),
"_longjmp" => Function::new_env(store, env, crate::jmp::_longjmp), "_longjmp" => Function::new_env(store, env.clone(), crate::jmp::_longjmp),
"_emscripten_longjmp" => Function::new_env(store, env, crate::jmp::_longjmp), "_emscripten_longjmp" => Function::new_env(store, env.clone(), crate::jmp::_longjmp),
// Bitwise // Bitwise
"_llvm_bswap_i64" => Function::new_env(store, env, crate::bitwise::_llvm_bswap_i64), "_llvm_bswap_i64" => Function::new_env(store, env.clone(), crate::bitwise::_llvm_bswap_i64),
// libc // libc
"_execv" => Function::new(store, crate::libc::execv), "_execv" => Function::new(store, crate::libc::execv),
@@ -956,8 +966,8 @@ pub fn generate_emscripten_env(
"_getitimer" => Function::new(store, crate::libc::getitimer), "_getitimer" => Function::new(store, crate::libc::getitimer),
"_getpwent" => Function::new(store, crate::libc::getpwent), "_getpwent" => Function::new(store, crate::libc::getpwent),
"_killpg" => Function::new(store, crate::libc::killpg), "_killpg" => Function::new(store, crate::libc::killpg),
"_pathconf" => Function::new_env(store, env, crate::libc::pathconf), "_pathconf" => Function::new_env(store, env.clone(), crate::libc::pathconf),
"_siginterrupt" => Function::new_env(store, env, crate::signal::_siginterrupt), "_siginterrupt" => Function::new_env(store, env.clone(), crate::signal::_siginterrupt),
"_setpwent" => Function::new(store, crate::libc::setpwent), "_setpwent" => Function::new(store, crate::libc::setpwent),
"_sigismember" => Function::new(store, crate::libc::sigismember), "_sigismember" => Function::new(store, crate::libc::sigismember),
"_sigpending" => Function::new(store, crate::libc::sigpending), "_sigpending" => Function::new(store, crate::libc::sigpending),
@@ -965,131 +975,131 @@ pub fn generate_emscripten_env(
"___libc_current_sigrtmin" => Function::new(store, crate::libc::current_sigrtmin), "___libc_current_sigrtmin" => Function::new(store, crate::libc::current_sigrtmin),
// Linking // Linking
"_dlclose" => Function::new_env(store, env, crate::linking::_dlclose), "_dlclose" => Function::new_env(store, env.clone(), crate::linking::_dlclose),
"_dlerror" => Function::new_env(store, env, crate::linking::_dlerror), "_dlerror" => Function::new_env(store, env.clone(), crate::linking::_dlerror),
"_dlopen" => Function::new_env(store, env, crate::linking::_dlopen), "_dlopen" => Function::new_env(store, env.clone(), crate::linking::_dlopen),
"_dlsym" => Function::new_env(store, env, crate::linking::_dlsym), "_dlsym" => Function::new_env(store, env.clone(), crate::linking::_dlsym),
// wasm32-unknown-emscripten // wasm32-unknown-emscripten
"_alarm" => Function::new_env(store, env, crate::emscripten_target::_alarm), "_alarm" => Function::new_env(store, env.clone(), crate::emscripten_target::_alarm),
"_atexit" => Function::new_env(store, env, crate::emscripten_target::_atexit), "_atexit" => Function::new_env(store, env.clone(), crate::emscripten_target::_atexit),
"setTempRet0" => Function::new_env(store, env, crate::emscripten_target::setTempRet0), "setTempRet0" => Function::new_env(store, env.clone(), crate::emscripten_target::setTempRet0),
"getTempRet0" => Function::new_env(store, env, crate::emscripten_target::getTempRet0), "getTempRet0" => Function::new_env(store, env.clone(), crate::emscripten_target::getTempRet0),
"invoke_i" => Function::new_env(store, env, crate::emscripten_target::invoke_i), "invoke_i" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_i),
"invoke_ii" => Function::new_env(store, env, crate::emscripten_target::invoke_ii), "invoke_ii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_ii),
"invoke_iii" => Function::new_env(store, env, crate::emscripten_target::invoke_iii), "invoke_iii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_iii),
"invoke_iiii" => Function::new_env(store, env, crate::emscripten_target::invoke_iiii), "invoke_iiii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_iiii),
"invoke_iifi" => Function::new_env(store, env, crate::emscripten_target::invoke_iifi), "invoke_iifi" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_iifi),
"invoke_v" => Function::new_env(store, env, crate::emscripten_target::invoke_v), "invoke_v" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_v),
"invoke_vi" => Function::new_env(store, env, crate::emscripten_target::invoke_vi), "invoke_vi" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_vi),
"invoke_vj" => Function::new_env(store, env, crate::emscripten_target::invoke_vj), "invoke_vj" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_vj),
"invoke_vjji" => Function::new_env(store, env, crate::emscripten_target::invoke_vjji), "invoke_vjji" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_vjji),
"invoke_vii" => Function::new_env(store, env, crate::emscripten_target::invoke_vii), "invoke_vii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_vii),
"invoke_viii" => Function::new_env(store, env, crate::emscripten_target::invoke_viii), "invoke_viii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_viii),
"invoke_viiii" => Function::new_env(store, env, crate::emscripten_target::invoke_viiii), "invoke_viiii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_viiii),
"__Unwind_Backtrace" => Function::new_env(store, env, crate::emscripten_target::__Unwind_Backtrace), "__Unwind_Backtrace" => Function::new_env(store, env.clone(), crate::emscripten_target::__Unwind_Backtrace),
"__Unwind_FindEnclosingFunction" => Function::new_env(store, env, crate::emscripten_target::__Unwind_FindEnclosingFunction), "__Unwind_FindEnclosingFunction" => Function::new_env(store, env.clone(), crate::emscripten_target::__Unwind_FindEnclosingFunction),
"__Unwind_GetIPInfo" => Function::new_env(store, env, crate::emscripten_target::__Unwind_GetIPInfo), "__Unwind_GetIPInfo" => Function::new_env(store, env.clone(), crate::emscripten_target::__Unwind_GetIPInfo),
"___cxa_find_matching_catch_2" => Function::new_env(store, env, crate::emscripten_target::___cxa_find_matching_catch_2), "___cxa_find_matching_catch_2" => Function::new_env(store, env.clone(), crate::emscripten_target::___cxa_find_matching_catch_2),
"___cxa_find_matching_catch_3" => Function::new_env(store, env, crate::emscripten_target::___cxa_find_matching_catch_3), "___cxa_find_matching_catch_3" => Function::new_env(store, env.clone(), crate::emscripten_target::___cxa_find_matching_catch_3),
"___cxa_free_exception" => Function::new_env(store, env, crate::emscripten_target::___cxa_free_exception), "___cxa_free_exception" => Function::new_env(store, env.clone(), crate::emscripten_target::___cxa_free_exception),
"___resumeException" => Function::new_env(store, env, crate::emscripten_target::___resumeException), "___resumeException" => Function::new_env(store, env.clone(), crate::emscripten_target::___resumeException),
"_dladdr" => Function::new_env(store, env, crate::emscripten_target::_dladdr), "_dladdr" => Function::new_env(store, env.clone(), crate::emscripten_target::_dladdr),
"_pthread_attr_destroy" => Function::new_env(store, env, crate::pthread::_pthread_attr_destroy), "_pthread_attr_destroy" => Function::new_env(store, env.clone(), crate::pthread::_pthread_attr_destroy),
"_pthread_attr_getstack" => Function::new_env(store, env, crate::pthread::_pthread_attr_getstack), "_pthread_attr_getstack" => Function::new_env(store, env.clone(), crate::pthread::_pthread_attr_getstack),
"_pthread_attr_init" => Function::new_env(store, env, crate::pthread::_pthread_attr_init), "_pthread_attr_init" => Function::new_env(store, env.clone(), crate::pthread::_pthread_attr_init),
"_pthread_attr_setstacksize" => Function::new_env(store, env, crate::pthread::_pthread_attr_setstacksize), "_pthread_attr_setstacksize" => Function::new_env(store, env.clone(), crate::pthread::_pthread_attr_setstacksize),
"_pthread_cleanup_pop" => Function::new_env(store, env, crate::pthread::_pthread_cleanup_pop), "_pthread_cleanup_pop" => Function::new_env(store, env.clone(), crate::pthread::_pthread_cleanup_pop),
"_pthread_cleanup_push" => Function::new_env(store, env, crate::pthread::_pthread_cleanup_push), "_pthread_cleanup_push" => Function::new_env(store, env.clone(), crate::pthread::_pthread_cleanup_push),
"_pthread_cond_destroy" => Function::new_env(store, env, crate::pthread::_pthread_cond_destroy), "_pthread_cond_destroy" => Function::new_env(store, env.clone(), crate::pthread::_pthread_cond_destroy),
"_pthread_cond_init" => Function::new_env(store, env, crate::pthread::_pthread_cond_init), "_pthread_cond_init" => Function::new_env(store, env.clone(), crate::pthread::_pthread_cond_init),
"_pthread_cond_signal" => Function::new_env(store, env, crate::pthread::_pthread_cond_signal), "_pthread_cond_signal" => Function::new_env(store, env.clone(), crate::pthread::_pthread_cond_signal),
"_pthread_cond_timedwait" => Function::new_env(store, env, crate::pthread::_pthread_cond_timedwait), "_pthread_cond_timedwait" => Function::new_env(store, env.clone(), crate::pthread::_pthread_cond_timedwait),
"_pthread_cond_wait" => Function::new_env(store, env, crate::pthread::_pthread_cond_wait), "_pthread_cond_wait" => Function::new_env(store, env.clone(), crate::pthread::_pthread_cond_wait),
"_pthread_condattr_destroy" => Function::new_env(store, env, crate::pthread::_pthread_condattr_destroy), "_pthread_condattr_destroy" => Function::new_env(store, env.clone(), crate::pthread::_pthread_condattr_destroy),
"_pthread_condattr_init" => Function::new_env(store, env, crate::pthread::_pthread_condattr_init), "_pthread_condattr_init" => Function::new_env(store, env.clone(), crate::pthread::_pthread_condattr_init),
"_pthread_condattr_setclock" => Function::new_env(store, env, crate::pthread::_pthread_condattr_setclock), "_pthread_condattr_setclock" => Function::new_env(store, env.clone(), crate::pthread::_pthread_condattr_setclock),
"_pthread_create" => Function::new_env(store, env, crate::pthread::_pthread_create), "_pthread_create" => Function::new_env(store, env.clone(), crate::pthread::_pthread_create),
"_pthread_detach" => Function::new_env(store, env, crate::pthread::_pthread_detach), "_pthread_detach" => Function::new_env(store, env.clone(), crate::pthread::_pthread_detach),
"_pthread_equal" => Function::new_env(store, env, crate::pthread::_pthread_equal), "_pthread_equal" => Function::new_env(store, env.clone(), crate::pthread::_pthread_equal),
"_pthread_exit" => Function::new_env(store, env, crate::pthread::_pthread_exit), "_pthread_exit" => Function::new_env(store, env.clone(), crate::pthread::_pthread_exit),
"_pthread_self" => Function::new_env(store, env, crate::pthread::_pthread_self), "_pthread_self" => Function::new_env(store, env.clone(), crate::pthread::_pthread_self),
"_pthread_getattr_np" => Function::new_env(store, env, crate::pthread::_pthread_getattr_np), "_pthread_getattr_np" => Function::new_env(store, env.clone(), crate::pthread::_pthread_getattr_np),
"_pthread_getspecific" => Function::new_env(store, env, crate::pthread::_pthread_getspecific), "_pthread_getspecific" => Function::new_env(store, env.clone(), crate::pthread::_pthread_getspecific),
"_pthread_join" => Function::new_env(store, env, crate::pthread::_pthread_join), "_pthread_join" => Function::new_env(store, env.clone(), crate::pthread::_pthread_join),
"_pthread_key_create" => Function::new_env(store, env, crate::pthread::_pthread_key_create), "_pthread_key_create" => Function::new_env(store, env.clone(), crate::pthread::_pthread_key_create),
"_pthread_mutex_destroy" => Function::new_env(store, env, crate::pthread::_pthread_mutex_destroy), "_pthread_mutex_destroy" => Function::new_env(store, env.clone(), crate::pthread::_pthread_mutex_destroy),
"_pthread_mutex_init" => Function::new_env(store, env, crate::pthread::_pthread_mutex_init), "_pthread_mutex_init" => Function::new_env(store, env.clone(), crate::pthread::_pthread_mutex_init),
"_pthread_mutexattr_destroy" => Function::new_env(store, env, crate::pthread::_pthread_mutexattr_destroy), "_pthread_mutexattr_destroy" => Function::new_env(store, env.clone(), crate::pthread::_pthread_mutexattr_destroy),
"_pthread_mutexattr_init" => Function::new_env(store, env, crate::pthread::_pthread_mutexattr_init), "_pthread_mutexattr_init" => Function::new_env(store, env.clone(), crate::pthread::_pthread_mutexattr_init),
"_pthread_mutexattr_settype" => Function::new_env(store, env, crate::pthread::_pthread_mutexattr_settype), "_pthread_mutexattr_settype" => Function::new_env(store, env.clone(), crate::pthread::_pthread_mutexattr_settype),
"_pthread_once" => Function::new_env(store, env, crate::pthread::_pthread_once), "_pthread_once" => Function::new_env(store, env.clone(), crate::pthread::_pthread_once),
"_pthread_rwlock_destroy" => Function::new_env(store, env, crate::pthread::_pthread_rwlock_destroy), "_pthread_rwlock_destroy" => Function::new_env(store, env.clone(), crate::pthread::_pthread_rwlock_destroy),
"_pthread_rwlock_init" => Function::new_env(store, env, crate::pthread::_pthread_rwlock_init), "_pthread_rwlock_init" => Function::new_env(store, env.clone(), crate::pthread::_pthread_rwlock_init),
"_pthread_rwlock_rdlock" => Function::new_env(store, env, crate::pthread::_pthread_rwlock_rdlock), "_pthread_rwlock_rdlock" => Function::new_env(store, env.clone(), crate::pthread::_pthread_rwlock_rdlock),
"_pthread_rwlock_unlock" => Function::new_env(store, env, crate::pthread::_pthread_rwlock_unlock), "_pthread_rwlock_unlock" => Function::new_env(store, env.clone(), crate::pthread::_pthread_rwlock_unlock),
"_pthread_rwlock_wrlock" => Function::new_env(store, env, crate::pthread::_pthread_rwlock_wrlock), "_pthread_rwlock_wrlock" => Function::new_env(store, env.clone(), crate::pthread::_pthread_rwlock_wrlock),
"_pthread_setcancelstate" => Function::new_env(store, env, crate::pthread::_pthread_setcancelstate), "_pthread_setcancelstate" => Function::new_env(store, env.clone(), crate::pthread::_pthread_setcancelstate),
"_pthread_setspecific" => Function::new_env(store, env, crate::pthread::_pthread_setspecific), "_pthread_setspecific" => Function::new_env(store, env.clone(), crate::pthread::_pthread_setspecific),
"_pthread_sigmask" => Function::new_env(store, env, crate::pthread::_pthread_sigmask), "_pthread_sigmask" => Function::new_env(store, env.clone(), crate::pthread::_pthread_sigmask),
"___gxx_personality_v0" => Function::new_env(store, env, crate::emscripten_target::___gxx_personality_v0), "___gxx_personality_v0" => Function::new_env(store, env.clone(), crate::emscripten_target::___gxx_personality_v0),
"_gai_strerror" => Function::new_env(store, env, crate::env::_gai_strerror), "_gai_strerror" => Function::new_env(store, env.clone(), crate::env::_gai_strerror),
"_getdtablesize" => Function::new_env(store, env, crate::emscripten_target::_getdtablesize), "_getdtablesize" => Function::new_env(store, env.clone(), crate::emscripten_target::_getdtablesize),
"_gethostbyaddr" => Function::new_env(store, env, crate::emscripten_target::_gethostbyaddr), "_gethostbyaddr" => Function::new_env(store, env.clone(), crate::emscripten_target::_gethostbyaddr),
"_gethostbyname" => Function::new_env(store, env, crate::emscripten_target::_gethostbyname), "_gethostbyname" => Function::new_env(store, env.clone(), crate::emscripten_target::_gethostbyname),
"_gethostbyname_r" => Function::new_env(store, env, crate::emscripten_target::_gethostbyname_r), "_gethostbyname_r" => Function::new_env(store, env.clone(), crate::emscripten_target::_gethostbyname_r),
"_getloadavg" => Function::new_env(store, env, crate::emscripten_target::_getloadavg), "_getloadavg" => Function::new_env(store, env.clone(), crate::emscripten_target::_getloadavg),
"_getnameinfo" => Function::new_env(store, env, crate::emscripten_target::_getnameinfo), "_getnameinfo" => Function::new_env(store, env.clone(), crate::emscripten_target::_getnameinfo),
"invoke_dii" => Function::new_env(store, env, crate::emscripten_target::invoke_dii), "invoke_dii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_dii),
"invoke_diiii" => Function::new_env(store, env, crate::emscripten_target::invoke_diiii), "invoke_diiii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_diiii),
"invoke_iiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_iiiii), "invoke_iiiii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_iiiii),
"invoke_iiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_iiiiii), "invoke_iiiiii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_iiiiii),
"invoke_iiiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_iiiiiii), "invoke_iiiiiii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_iiiiiii),
"invoke_iiiiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_iiiiiiii), "invoke_iiiiiiii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_iiiiiiii),
"invoke_iiiiiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_iiiiiiiii), "invoke_iiiiiiiii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_iiiiiiiii),
"invoke_iiiiiiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_iiiiiiiiii), "invoke_iiiiiiiiii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_iiiiiiiiii),
"invoke_iiiiiiiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_iiiiiiiiiii), "invoke_iiiiiiiiiii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_iiiiiiiiiii),
"invoke_vd" => Function::new_env(store, env, crate::emscripten_target::invoke_vd), "invoke_vd" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_vd),
"invoke_viiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_viiiii), "invoke_viiiii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_viiiii),
"invoke_viiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_viiiiii), "invoke_viiiiii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_viiiiii),
"invoke_viiiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_viiiiiii), "invoke_viiiiiii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_viiiiiii),
"invoke_viiiiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_viiiiiiii), "invoke_viiiiiiii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_viiiiiiii),
"invoke_viiiiiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_viiiiiiiii), "invoke_viiiiiiiii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_viiiiiiiii),
"invoke_viiiiiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_viiiiiiiii), "invoke_viiiiiiiii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_viiiiiiiii),
"invoke_viiiiiiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_viiiiiiiiii), "invoke_viiiiiiiiii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_viiiiiiiiii),
"invoke_iij" => Function::new_env(store, env, crate::emscripten_target::invoke_iij), "invoke_iij" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_iij),
"invoke_iji" => Function::new_env(store, env, crate::emscripten_target::invoke_iji), "invoke_iji" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_iji),
"invoke_iiji" => Function::new_env(store, env, crate::emscripten_target::invoke_iiji), "invoke_iiji" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_iiji),
"invoke_iiijj" => Function::new_env(store, env, crate::emscripten_target::invoke_iiijj), "invoke_iiijj" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_iiijj),
"invoke_j" => Function::new_env(store, env, crate::emscripten_target::invoke_j), "invoke_j" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_j),
"invoke_ji" => Function::new_env(store, env, crate::emscripten_target::invoke_ji), "invoke_ji" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_ji),
"invoke_jii" => Function::new_env(store, env, crate::emscripten_target::invoke_jii), "invoke_jii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_jii),
"invoke_jij" => Function::new_env(store, env, crate::emscripten_target::invoke_jij), "invoke_jij" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_jij),
"invoke_jjj" => Function::new_env(store, env, crate::emscripten_target::invoke_jjj), "invoke_jjj" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_jjj),
"invoke_viiij" => Function::new_env(store, env, crate::emscripten_target::invoke_viiij), "invoke_viiij" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_viiij),
"invoke_viiijiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_viiijiiii), "invoke_viiijiiii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_viiijiiii),
"invoke_viiijiiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_viiijiiiiii), "invoke_viiijiiiiii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_viiijiiiiii),
"invoke_viij" => Function::new_env(store, env, crate::emscripten_target::invoke_viij), "invoke_viij" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_viij),
"invoke_viiji" => Function::new_env(store, env, crate::emscripten_target::invoke_viiji), "invoke_viiji" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_viiji),
"invoke_viijiii" => Function::new_env(store, env, crate::emscripten_target::invoke_viijiii), "invoke_viijiii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_viijiii),
"invoke_viijj" => Function::new_env(store, env, crate::emscripten_target::invoke_viijj), "invoke_viijj" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_viijj),
"invoke_vij" => Function::new_env(store, env, crate::emscripten_target::invoke_vij), "invoke_vij" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_vij),
"invoke_viji" => Function::new_env(store, env, crate::emscripten_target::invoke_viji), "invoke_viji" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_viji),
"invoke_vijiii" => Function::new_env(store, env, crate::emscripten_target::invoke_vijiii), "invoke_vijiii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_vijiii),
"invoke_vijj" => Function::new_env(store, env, crate::emscripten_target::invoke_vijj), "invoke_vijj" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_vijj),
"invoke_vidd" => Function::new_env(store, env, crate::emscripten_target::invoke_vidd), "invoke_vidd" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_vidd),
"invoke_viid" => Function::new_env(store, env, crate::emscripten_target::invoke_viid), "invoke_viid" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_viid),
"invoke_viidii" => Function::new_env(store, env, crate::emscripten_target::invoke_viidii), "invoke_viidii" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_viidii),
"invoke_viidddddddd" => Function::new_env(store, env, crate::emscripten_target::invoke_viidddddddd), "invoke_viidddddddd" => Function::new_env(store, env.clone(), crate::emscripten_target::invoke_viidddddddd),
// ucontext // ucontext
"_getcontext" => Function::new_env(store, env, crate::ucontext::_getcontext), "_getcontext" => Function::new_env(store, env.clone(), crate::ucontext::_getcontext),
"_makecontext" => Function::new_env(store, env, crate::ucontext::_makecontext), "_makecontext" => Function::new_env(store, env.clone(), crate::ucontext::_makecontext),
"_setcontext" => Function::new_env(store, env, crate::ucontext::_setcontext), "_setcontext" => Function::new_env(store, env.clone(), crate::ucontext::_setcontext),
"_swapcontext" => Function::new_env(store, env, crate::ucontext::_swapcontext), "_swapcontext" => Function::new_env(store, env.clone(), crate::ucontext::_swapcontext),
// unistd // unistd
"_confstr" => Function::new_env(store, env, crate::unistd::confstr), "_confstr" => Function::new_env(store, env.clone(), crate::unistd::confstr),
}; };
// Compatibility with newer versions of Emscripten // Compatibility with newer versions of Emscripten
@@ -1110,7 +1120,7 @@ pub fn generate_emscripten_env(
for null_func_name in globals.null_func_names.iter() { for null_func_name in globals.null_func_names.iter() {
env_ns.insert( env_ns.insert(
null_func_name.as_str(), null_func_name.as_str(),
Function::new_env(store, env, nullfunc), Function::new_env(store, env.clone(), nullfunc),
); );
} }

View File

@@ -65,30 +65,6 @@ impl JITArtifact {
let compiler = inner_jit.compiler()?; let compiler = inner_jit.compiler()?;
// Compile the trampolines
// We compile the call trampolines for all the signatures
let func_types = translation
.module
.signatures
.values()
.cloned()
.collect::<Vec<_>>();
let function_call_trampolines = compiler
.compile_function_call_trampolines(&func_types)?
.into_iter()
.collect::<PrimaryMap<SignatureIndex, _>>();
// We compile the dynamic function trampolines only for the imported functions
let func_types = translation
.module
.functions
.values()
.take(translation.module.num_imported_funcs)
.map(|&sig_index| translation.module.signatures[sig_index].clone())
.collect::<Vec<_>>();
let dynamic_function_trampolines =
compiler.compile_dynamic_function_trampolines(&func_types)?;
// Compile the Module // Compile the Module
let compilation = compiler.compile_module( let compilation = compiler.compile_module(
&translation.module, &translation.module,
@@ -97,6 +73,8 @@ impl JITArtifact {
memory_plans.clone(), memory_plans.clone(),
table_plans.clone(), table_plans.clone(),
)?; )?;
let function_call_trampolines = compilation.get_function_call_trampolines();
let dynamic_function_trampolines = compilation.get_dynamic_function_trampolines();
let data_initializers = translation let data_initializers = translation
.data_initializers .data_initializers

View File

@@ -116,31 +116,6 @@ impl NativeArtifact {
.collect(); .collect();
let compiler = engine_inner.compiler()?; let compiler = engine_inner.compiler()?;
// Compile the trampolines
// We compile the call trampolines for all the signatures
let func_types = translation
.module
.signatures
.values()
.cloned()
.collect::<Vec<_>>();
let function_call_trampolines = compiler
.compile_function_call_trampolines(&func_types)?
.into_iter()
.collect::<PrimaryMap<SignatureIndex, _>>();
// We compile the dynamic function trampolines only for the imported functions
let func_types = translation
.module
.functions
.values()
.take(translation.module.num_imported_funcs)
.map(|&sig_index| translation.module.signatures[sig_index].clone())
.collect::<Vec<_>>();
let dynamic_function_trampolines =
compiler.compile_dynamic_function_trampolines(&func_types)?;
// Compile the Module // Compile the Module
let compilation = compiler.compile_module( let compilation = compiler.compile_module(
&translation.module, &translation.module,
@@ -149,6 +124,8 @@ impl NativeArtifact {
memory_plans.clone(), memory_plans.clone(),
table_plans.clone(), table_plans.clone(),
)?; )?;
let function_call_trampolines = compilation.get_function_call_trampolines();
let dynamic_function_trampolines = compilation.get_dynamic_function_trampolines();
let data_initializers = translation let data_initializers = translation
.data_initializers .data_initializers

View File

@@ -321,6 +321,14 @@ impl ModuleInfo {
None => "<module>".to_string(), None => "<module>".to_string(),
} }
} }
/// Get the imported function types of the module.
pub fn imported_function_types<'a>(&'a self) -> impl Iterator<Item = FunctionType> + 'a {
self.functions
.values()
.take(self.num_imported_funcs)
.map(move |sig_index| self.signatures[*sig_index].clone())
}
} }
impl fmt::Display for ModuleInfo { impl fmt::Display for ModuleInfo {

View File

@@ -28,6 +28,8 @@ pub use crate::utils::{get_wasi_version, is_wasi_module, WasiVersion};
use thiserror::Error; use thiserror::Error;
use wasmer::{imports, Function, ImportObject, Memory, Module, Store}; use wasmer::{imports, Function, ImportObject, Memory, Module, Store};
use std::sync::{Arc, Mutex, MutexGuard};
/// This is returned in `RuntimeError`. /// This is returned in `RuntimeError`.
/// Use `downcast` or `downcast_ref` to retrieve the `ExitCode`. /// Use `downcast` or `downcast_ref` to retrieve the `ExitCode`.
#[derive(Error, Debug)] #[derive(Error, Debug)]
@@ -40,15 +42,16 @@ pub enum WasiError {
/// The environment provided to the WASI imports. /// The environment provided to the WASI imports.
/// It /// It
pub struct WasiEnv<'a> { #[derive(Clone)]
state: WasiState, pub struct WasiEnv {
memory: Option<&'a Memory>, state: Arc<Mutex<WasiState>>,
memory: Option<Arc<Memory>>,
} }
impl<'a> WasiEnv<'a> { impl WasiEnv {
pub fn new(state: WasiState) -> Self { pub fn new(state: WasiState) -> Self {
Self { Self {
state, state: Arc::new(Mutex::new(state)),
memory: None, memory: None,
} }
} }
@@ -57,24 +60,24 @@ impl<'a> WasiEnv<'a> {
let wasi_version = get_wasi_version(module, false).ok_or(WasiError::UnknownWasiVersion)?; let wasi_version = get_wasi_version(module, false).ok_or(WasiError::UnknownWasiVersion)?;
Ok(generate_import_object_from_env( Ok(generate_import_object_from_env(
module.store(), module.store(),
self, self.clone(),
wasi_version, wasi_version,
)) ))
} }
/// Set the memory /// Set the memory
pub fn set_memory(&mut self, memory: &'a Memory) { pub fn set_memory(&mut self, memory: Arc<Memory>) {
self.memory = Some(memory); self.memory = Some(memory);
} }
/// Get the WASI state /// Get the WASI state
pub fn state(&self) -> &WasiState { pub fn state(&self) -> MutexGuard<WasiState> {
&self.state self.state.lock().unwrap()
} }
/// Get the WASI state (mutable) /// Get the WASI state (mutable)
pub fn state_mut(&mut self) -> &mut WasiState { pub fn state_mut(&mut self) -> MutexGuard<WasiState> {
&mut self.state self.state.lock().unwrap()
} }
/// Get a reference to the memory /// Get a reference to the memory
@@ -85,9 +88,9 @@ impl<'a> WasiEnv<'a> {
pub(crate) fn get_memory_and_wasi_state( pub(crate) fn get_memory_and_wasi_state(
&mut self, &mut self,
_mem_index: u32, _mem_index: u32,
) -> (&Memory, &mut WasiState) { ) -> (&Memory, MutexGuard<WasiState>) {
let memory = self.memory.as_ref().unwrap(); let memory = self.memory.as_ref().unwrap();
let state = &mut self.state; let state = self.state.lock().unwrap();
(memory, state) (memory, state)
} }
} }
@@ -96,7 +99,7 @@ impl<'a> WasiEnv<'a> {
/// can be constructed from a [`WasiStateBuilder`](state::WasiStateBuilder). /// can be constructed from a [`WasiStateBuilder`](state::WasiStateBuilder).
pub fn generate_import_object_from_env( pub fn generate_import_object_from_env(
store: &Store, store: &Store,
wasi_env: &mut WasiEnv, wasi_env: WasiEnv,
version: WasiVersion, version: WasiVersion,
) -> ImportObject { ) -> ImportObject {
match version { match version {
@@ -108,107 +111,107 @@ pub fn generate_import_object_from_env(
} }
/// Combines a state generating function with the import list for legacy WASI /// Combines a state generating function with the import list for legacy WASI
fn generate_import_object_snapshot0(store: &Store, env: &mut WasiEnv) -> ImportObject { fn generate_import_object_snapshot0(store: &Store, env: WasiEnv) -> ImportObject {
imports! { imports! {
"wasi_unstable" => { "wasi_unstable" => {
"args_get" => Function::new_env(store, env, args_get), "args_get" => Function::new_env(store, env.clone(), args_get),
"args_sizes_get" => Function::new_env(store, env, args_sizes_get), "args_sizes_get" => Function::new_env(store, env.clone(), args_sizes_get),
"clock_res_get" => Function::new_env(store, env, clock_res_get), "clock_res_get" => Function::new_env(store, env.clone(), clock_res_get),
"clock_time_get" => Function::new_env(store, env, clock_time_get), "clock_time_get" => Function::new_env(store, env.clone(), clock_time_get),
"environ_get" => Function::new_env(store, env, environ_get), "environ_get" => Function::new_env(store, env.clone(), environ_get),
"environ_sizes_get" => Function::new_env(store, env, environ_sizes_get), "environ_sizes_get" => Function::new_env(store, env.clone(), environ_sizes_get),
"fd_advise" => Function::new_env(store, env, fd_advise), "fd_advise" => Function::new_env(store, env.clone(), fd_advise),
"fd_allocate" => Function::new_env(store, env, fd_allocate), "fd_allocate" => Function::new_env(store, env.clone(), fd_allocate),
"fd_close" => Function::new_env(store, env, fd_close), "fd_close" => Function::new_env(store, env.clone(), fd_close),
"fd_datasync" => Function::new_env(store, env, fd_datasync), "fd_datasync" => Function::new_env(store, env.clone(), fd_datasync),
"fd_fdstat_get" => Function::new_env(store, env, fd_fdstat_get), "fd_fdstat_get" => Function::new_env(store, env.clone(), fd_fdstat_get),
"fd_fdstat_set_flags" => Function::new_env(store, env, fd_fdstat_set_flags), "fd_fdstat_set_flags" => Function::new_env(store, env.clone(), fd_fdstat_set_flags),
"fd_fdstat_set_rights" => Function::new_env(store, env, fd_fdstat_set_rights), "fd_fdstat_set_rights" => Function::new_env(store, env.clone(), fd_fdstat_set_rights),
"fd_filestat_get" => Function::new_env(store, env, legacy::snapshot0::fd_filestat_get), "fd_filestat_get" => Function::new_env(store, env.clone(), legacy::snapshot0::fd_filestat_get),
"fd_filestat_set_size" => Function::new_env(store, env, fd_filestat_set_size), "fd_filestat_set_size" => Function::new_env(store, env.clone(), fd_filestat_set_size),
"fd_filestat_set_times" => Function::new_env(store, env, fd_filestat_set_times), "fd_filestat_set_times" => Function::new_env(store, env.clone(), fd_filestat_set_times),
"fd_pread" => Function::new_env(store, env, fd_pread), "fd_pread" => Function::new_env(store, env.clone(), fd_pread),
"fd_prestat_get" => Function::new_env(store, env, fd_prestat_get), "fd_prestat_get" => Function::new_env(store, env.clone(), fd_prestat_get),
"fd_prestat_dir_name" => Function::new_env(store, env, fd_prestat_dir_name), "fd_prestat_dir_name" => Function::new_env(store, env.clone(), fd_prestat_dir_name),
"fd_pwrite" => Function::new_env(store, env, fd_pwrite), "fd_pwrite" => Function::new_env(store, env.clone(), fd_pwrite),
"fd_read" => Function::new_env(store, env, fd_read), "fd_read" => Function::new_env(store, env.clone(), fd_read),
"fd_readdir" => Function::new_env(store, env, fd_readdir), "fd_readdir" => Function::new_env(store, env.clone(), fd_readdir),
"fd_renumber" => Function::new_env(store, env, fd_renumber), "fd_renumber" => Function::new_env(store, env.clone(), fd_renumber),
"fd_seek" => Function::new_env(store, env, legacy::snapshot0::fd_seek), "fd_seek" => Function::new_env(store, env.clone(), legacy::snapshot0::fd_seek),
"fd_sync" => Function::new_env(store, env, fd_sync), "fd_sync" => Function::new_env(store, env.clone(), fd_sync),
"fd_tell" => Function::new_env(store, env, fd_tell), "fd_tell" => Function::new_env(store, env.clone(), fd_tell),
"fd_write" => Function::new_env(store, env, fd_write), "fd_write" => Function::new_env(store, env.clone(), fd_write),
"path_create_directory" => Function::new_env(store, env, path_create_directory), "path_create_directory" => Function::new_env(store, env.clone(), path_create_directory),
"path_filestat_get" => Function::new_env(store, env, legacy::snapshot0::path_filestat_get), "path_filestat_get" => Function::new_env(store, env.clone(), legacy::snapshot0::path_filestat_get),
"path_filestat_set_times" => Function::new_env(store, env, path_filestat_set_times), "path_filestat_set_times" => Function::new_env(store, env.clone(), path_filestat_set_times),
"path_link" => Function::new_env(store, env, path_link), "path_link" => Function::new_env(store, env.clone(), path_link),
"path_open" => Function::new_env(store, env, path_open), "path_open" => Function::new_env(store, env.clone(), path_open),
"path_readlink" => Function::new_env(store, env, path_readlink), "path_readlink" => Function::new_env(store, env.clone(), path_readlink),
"path_remove_directory" => Function::new_env(store, env, path_remove_directory), "path_remove_directory" => Function::new_env(store, env.clone(), path_remove_directory),
"path_rename" => Function::new_env(store, env, path_rename), "path_rename" => Function::new_env(store, env.clone(), path_rename),
"path_symlink" => Function::new_env(store, env, path_symlink), "path_symlink" => Function::new_env(store, env.clone(), path_symlink),
"path_unlink_file" => Function::new_env(store, env, path_unlink_file), "path_unlink_file" => Function::new_env(store, env.clone(), path_unlink_file),
"poll_oneoff" => Function::new_env(store, env, legacy::snapshot0::poll_oneoff), "poll_oneoff" => Function::new_env(store, env.clone(), legacy::snapshot0::poll_oneoff),
"proc_exit" => Function::new_env(store, env, proc_exit), "proc_exit" => Function::new_env(store, env.clone(), proc_exit),
"proc_raise" => Function::new_env(store, env, proc_raise), "proc_raise" => Function::new_env(store, env.clone(), proc_raise),
"random_get" => Function::new_env(store, env, random_get), "random_get" => Function::new_env(store, env.clone(), random_get),
"sched_yield" => Function::new_env(store, env, sched_yield), "sched_yield" => Function::new_env(store, env.clone(), sched_yield),
"sock_recv" => Function::new_env(store, env, sock_recv), "sock_recv" => Function::new_env(store, env.clone(), sock_recv),
"sock_send" => Function::new_env(store, env, sock_send), "sock_send" => Function::new_env(store, env.clone(), sock_send),
"sock_shutdown" => Function::new_env(store, env, sock_shutdown), "sock_shutdown" => Function::new_env(store, env.clone(), sock_shutdown),
}, },
} }
} }
/// Combines a state generating function with the import list for snapshot 1 /// Combines a state generating function with the import list for snapshot 1
fn generate_import_object_snapshot1(store: &Store, env: &mut WasiEnv) -> ImportObject { fn generate_import_object_snapshot1(store: &Store, env: WasiEnv) -> ImportObject {
imports! { imports! {
"wasi_snapshot_preview1" => { "wasi_snapshot_preview1" => {
"args_get" => Function::new_env(store, env, args_get), "args_get" => Function::new_env(store, env.clone(), args_get),
"args_sizes_get" => Function::new_env(store, env, args_sizes_get), "args_sizes_get" => Function::new_env(store, env.clone(), args_sizes_get),
"clock_res_get" => Function::new_env(store, env, clock_res_get), "clock_res_get" => Function::new_env(store, env.clone(), clock_res_get),
"clock_time_get" => Function::new_env(store, env, clock_time_get), "clock_time_get" => Function::new_env(store, env.clone(), clock_time_get),
"environ_get" => Function::new_env(store, env, environ_get), "environ_get" => Function::new_env(store, env.clone(), environ_get),
"environ_sizes_get" => Function::new_env(store, env, environ_sizes_get), "environ_sizes_get" => Function::new_env(store, env.clone(), environ_sizes_get),
"fd_advise" => Function::new_env(store, env, fd_advise), "fd_advise" => Function::new_env(store, env.clone(), fd_advise),
"fd_allocate" => Function::new_env(store, env, fd_allocate), "fd_allocate" => Function::new_env(store, env.clone(), fd_allocate),
"fd_close" => Function::new_env(store, env, fd_close), "fd_close" => Function::new_env(store, env.clone(), fd_close),
"fd_datasync" => Function::new_env(store, env, fd_datasync), "fd_datasync" => Function::new_env(store, env.clone(), fd_datasync),
"fd_fdstat_get" => Function::new_env(store, env, fd_fdstat_get), "fd_fdstat_get" => Function::new_env(store, env.clone(), fd_fdstat_get),
"fd_fdstat_set_flags" => Function::new_env(store, env, fd_fdstat_set_flags), "fd_fdstat_set_flags" => Function::new_env(store, env.clone(), fd_fdstat_set_flags),
"fd_fdstat_set_rights" => Function::new_env(store, env, fd_fdstat_set_rights), "fd_fdstat_set_rights" => Function::new_env(store, env.clone(), fd_fdstat_set_rights),
"fd_filestat_get" => Function::new_env(store, env, fd_filestat_get), "fd_filestat_get" => Function::new_env(store, env.clone(), fd_filestat_get),
"fd_filestat_set_size" => Function::new_env(store, env, fd_filestat_set_size), "fd_filestat_set_size" => Function::new_env(store, env.clone(), fd_filestat_set_size),
"fd_filestat_set_times" => Function::new_env(store, env, fd_filestat_set_times), "fd_filestat_set_times" => Function::new_env(store, env.clone(), fd_filestat_set_times),
"fd_pread" => Function::new_env(store, env, fd_pread), "fd_pread" => Function::new_env(store, env.clone(), fd_pread),
"fd_prestat_get" => Function::new_env(store, env, fd_prestat_get), "fd_prestat_get" => Function::new_env(store, env.clone(), fd_prestat_get),
"fd_prestat_dir_name" => Function::new_env(store, env, fd_prestat_dir_name), "fd_prestat_dir_name" => Function::new_env(store, env.clone(), fd_prestat_dir_name),
"fd_pwrite" => Function::new_env(store, env, fd_pwrite), "fd_pwrite" => Function::new_env(store, env.clone(), fd_pwrite),
"fd_read" => Function::new_env(store, env, fd_read), "fd_read" => Function::new_env(store, env.clone(), fd_read),
"fd_readdir" => Function::new_env(store, env, fd_readdir), "fd_readdir" => Function::new_env(store, env.clone(), fd_readdir),
"fd_renumber" => Function::new_env(store, env, fd_renumber), "fd_renumber" => Function::new_env(store, env.clone(), fd_renumber),
"fd_seek" => Function::new_env(store, env, fd_seek), "fd_seek" => Function::new_env(store, env.clone(), fd_seek),
"fd_sync" => Function::new_env(store, env, fd_sync), "fd_sync" => Function::new_env(store, env.clone(), fd_sync),
"fd_tell" => Function::new_env(store, env, fd_tell), "fd_tell" => Function::new_env(store, env.clone(), fd_tell),
"fd_write" => Function::new_env(store, env, fd_write), "fd_write" => Function::new_env(store, env.clone(), fd_write),
"path_create_directory" => Function::new_env(store, env, path_create_directory), "path_create_directory" => Function::new_env(store, env.clone(), path_create_directory),
"path_filestat_get" => Function::new_env(store, env, path_filestat_get), "path_filestat_get" => Function::new_env(store, env.clone(), path_filestat_get),
"path_filestat_set_times" => Function::new_env(store, env, path_filestat_set_times), "path_filestat_set_times" => Function::new_env(store, env.clone(), path_filestat_set_times),
"path_link" => Function::new_env(store, env, path_link), "path_link" => Function::new_env(store, env.clone(), path_link),
"path_open" => Function::new_env(store, env, path_open), "path_open" => Function::new_env(store, env.clone(), path_open),
"path_readlink" => Function::new_env(store, env, path_readlink), "path_readlink" => Function::new_env(store, env.clone(), path_readlink),
"path_remove_directory" => Function::new_env(store, env, path_remove_directory), "path_remove_directory" => Function::new_env(store, env.clone(), path_remove_directory),
"path_rename" => Function::new_env(store, env, path_rename), "path_rename" => Function::new_env(store, env.clone(), path_rename),
"path_symlink" => Function::new_env(store, env, path_symlink), "path_symlink" => Function::new_env(store, env.clone(), path_symlink),
"path_unlink_file" => Function::new_env(store, env, path_unlink_file), "path_unlink_file" => Function::new_env(store, env.clone(), path_unlink_file),
"poll_oneoff" => Function::new_env(store, env, poll_oneoff), "poll_oneoff" => Function::new_env(store, env.clone(), poll_oneoff),
"proc_exit" => Function::new_env(store, env, proc_exit), "proc_exit" => Function::new_env(store, env.clone(), proc_exit),
"proc_raise" => Function::new_env(store, env, proc_raise), "proc_raise" => Function::new_env(store, env.clone(), proc_raise),
"random_get" => Function::new_env(store, env, random_get), "random_get" => Function::new_env(store, env.clone(), random_get),
"sched_yield" => Function::new_env(store, env, sched_yield), "sched_yield" => Function::new_env(store, env.clone(), sched_yield),
"sock_recv" => Function::new_env(store, env, sock_recv), "sock_recv" => Function::new_env(store, env.clone(), sock_recv),
"sock_send" => Function::new_env(store, env, sock_send), "sock_send" => Function::new_env(store, env.clone(), sock_send),
"sock_shutdown" => Function::new_env(store, env, sock_shutdown), "sock_shutdown" => Function::new_env(store, env.clone(), sock_shutdown),
} }
} }
} }

View File

@@ -140,7 +140,7 @@ pub fn args_get(
argv_buf: WasmPtr<u8, Array>, argv_buf: WasmPtr<u8, Array>,
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::args_get"); debug!("wasi::args_get");
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let result = write_buffer_array(memory, &*state.args, argv, argv_buf); let result = write_buffer_array(memory, &*state.args, argv, argv_buf);
@@ -175,7 +175,7 @@ pub fn args_sizes_get(
argv_buf_size: WasmPtr<u32>, argv_buf_size: WasmPtr<u32>,
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::args_sizes_get"); debug!("wasi::args_sizes_get");
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let argc = wasi_try!(argc.deref(memory)); let argc = wasi_try!(argc.deref(memory));
let argv_buf_size = wasi_try!(argv_buf_size.deref(memory)); let argv_buf_size = wasi_try!(argv_buf_size.deref(memory));
@@ -256,7 +256,7 @@ pub fn environ_get(
environ_buf: WasmPtr<u8, Array>, environ_buf: WasmPtr<u8, Array>,
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::environ_get"); debug!("wasi::environ_get");
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
write_buffer_array(memory, &*state.envs, environ, environ_buf) write_buffer_array(memory, &*state.envs, environ, environ_buf)
} }
@@ -274,7 +274,7 @@ pub fn environ_sizes_get(
environ_buf_size: WasmPtr<u32>, environ_buf_size: WasmPtr<u32>,
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::environ_sizes_get"); debug!("wasi::environ_sizes_get");
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let environ_count = wasi_try!(environ_count.deref(memory)); let environ_count = wasi_try!(environ_count.deref(memory));
let environ_buf_size = wasi_try!(environ_buf_size.deref(memory)); let environ_buf_size = wasi_try!(environ_buf_size.deref(memory));
@@ -333,7 +333,7 @@ pub fn fd_allocate(
len: __wasi_filesize_t, len: __wasi_filesize_t,
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::fd_allocate"); debug!("wasi::fd_allocate");
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let fd_entry = wasi_try!(state.fs.get_fd(fd)); let fd_entry = wasi_try!(state.fs.get_fd(fd));
let inode = fd_entry.inode; let inode = fd_entry.inode;
@@ -374,7 +374,7 @@ pub fn fd_allocate(
/// If `fd` is invalid or not open /// If `fd` is invalid or not open
pub fn fd_close(env: &mut WasiEnv, fd: __wasi_fd_t) -> __wasi_errno_t { pub fn fd_close(env: &mut WasiEnv, fd: __wasi_fd_t) -> __wasi_errno_t {
debug!("wasi::fd_close: fd={}", fd); debug!("wasi::fd_close: fd={}", fd);
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let fd_entry = wasi_try!(state.fs.get_fd(fd)); let fd_entry = wasi_try!(state.fs.get_fd(fd));
@@ -390,7 +390,7 @@ pub fn fd_close(env: &mut WasiEnv, fd: __wasi_fd_t) -> __wasi_errno_t {
/// The file descriptor to sync /// The file descriptor to sync
pub fn fd_datasync(env: &mut WasiEnv, fd: __wasi_fd_t) -> __wasi_errno_t { pub fn fd_datasync(env: &mut WasiEnv, fd: __wasi_fd_t) -> __wasi_errno_t {
debug!("wasi::fd_datasync"); debug!("wasi::fd_datasync");
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let fd_entry = wasi_try!(state.fs.get_fd(fd)); let fd_entry = wasi_try!(state.fs.get_fd(fd));
if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_DATASYNC) { if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_DATASYNC) {
return __WASI_EACCES; return __WASI_EACCES;
@@ -421,7 +421,7 @@ pub fn fd_fdstat_get(
fd, fd,
buf_ptr.offset() buf_ptr.offset()
); );
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let fd_entry = wasi_try!(state.fs.get_fd(fd)); let fd_entry = wasi_try!(state.fs.get_fd(fd));
let stat = wasi_try!(state.fs.fdstat(fd)); let stat = wasi_try!(state.fs.fdstat(fd));
@@ -445,7 +445,7 @@ pub fn fd_fdstat_set_flags(
flags: __wasi_fdflags_t, flags: __wasi_fdflags_t,
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::fd_fdstat_set_flags"); debug!("wasi::fd_fdstat_set_flags");
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let fd_entry = wasi_try!(state.fs.fd_map.get_mut(&fd).ok_or(__WASI_EBADF)); let fd_entry = wasi_try!(state.fs.fd_map.get_mut(&fd).ok_or(__WASI_EBADF));
if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_FDSTAT_SET_FLAGS) { if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_FDSTAT_SET_FLAGS) {
@@ -472,7 +472,7 @@ pub fn fd_fdstat_set_rights(
fs_rights_inheriting: __wasi_rights_t, fs_rights_inheriting: __wasi_rights_t,
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::fd_fdstat_set_rights"); debug!("wasi::fd_fdstat_set_rights");
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let fd_entry = wasi_try!(state.fs.fd_map.get_mut(&fd).ok_or(__WASI_EBADF)); let fd_entry = wasi_try!(state.fs.fd_map.get_mut(&fd).ok_or(__WASI_EBADF));
// ensure new rights are a subset of current rights // ensure new rights are a subset of current rights
@@ -502,7 +502,7 @@ pub fn fd_filestat_get(
buf: WasmPtr<__wasi_filestat_t>, buf: WasmPtr<__wasi_filestat_t>,
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::fd_filestat_get"); debug!("wasi::fd_filestat_get");
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let fd_entry = wasi_try!(state.fs.get_fd(fd)); let fd_entry = wasi_try!(state.fs.get_fd(fd));
if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_FILESTAT_GET) { if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_FILESTAT_GET) {
return __WASI_EACCES; return __WASI_EACCES;
@@ -529,7 +529,7 @@ pub fn fd_filestat_set_size(
st_size: __wasi_filesize_t, st_size: __wasi_filesize_t,
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::fd_filestat_set_size"); debug!("wasi::fd_filestat_set_size");
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let fd_entry = wasi_try!(state.fs.get_fd(fd)); let fd_entry = wasi_try!(state.fs.get_fd(fd));
let inode = fd_entry.inode; let inode = fd_entry.inode;
@@ -573,7 +573,7 @@ pub fn fd_filestat_set_times(
fst_flags: __wasi_fstflags_t, fst_flags: __wasi_fstflags_t,
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::fd_filestat_set_times"); debug!("wasi::fd_filestat_set_times");
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let fd_entry = wasi_try!(state.fs.fd_map.get_mut(&fd).ok_or(__WASI_EBADF)); let fd_entry = wasi_try!(state.fs.fd_map.get_mut(&fd).ok_or(__WASI_EBADF));
if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_FILESTAT_SET_TIMES) { if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_FILESTAT_SET_TIMES) {
@@ -587,7 +587,8 @@ pub fn fd_filestat_set_times(
return __WASI_EINVAL; return __WASI_EINVAL;
} }
let inode = &mut state.fs.inodes[fd_entry.inode]; let inode_idx = fd_entry.inode;
let inode = &mut state.fs.inodes[inode_idx];
if fst_flags & __WASI_FILESTAT_SET_ATIM != 0 || fst_flags & __WASI_FILESTAT_SET_ATIM_NOW != 0 { if fst_flags & __WASI_FILESTAT_SET_ATIM != 0 || fst_flags & __WASI_FILESTAT_SET_ATIM_NOW != 0 {
let time_to_set = if fst_flags & __WASI_FILESTAT_SET_ATIM != 0 { let time_to_set = if fst_flags & __WASI_FILESTAT_SET_ATIM != 0 {
@@ -646,7 +647,7 @@ pub fn fd_pread(
nread: WasmPtr<u32>, nread: WasmPtr<u32>,
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::fd_pread: fd={}, offset={}", fd, offset); debug!("wasi::fd_pread: fd={}, offset={}", fd, offset);
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let iov_cells = wasi_try!(iovs.deref(memory, 0, iovs_len)); let iov_cells = wasi_try!(iovs.deref(memory, 0, iovs_len));
let nread_cell = wasi_try!(nread.deref(memory)); let nread_cell = wasi_try!(nread.deref(memory));
@@ -716,7 +717,7 @@ pub fn fd_prestat_get(
buf: WasmPtr<__wasi_prestat_t>, buf: WasmPtr<__wasi_prestat_t>,
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::fd_prestat_get: fd={}", fd); debug!("wasi::fd_prestat_get: fd={}", fd);
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let prestat_ptr = wasi_try!(buf.deref(memory)); let prestat_ptr = wasi_try!(buf.deref(memory));
@@ -735,7 +736,7 @@ pub fn fd_prestat_dir_name(
"wasi::fd_prestat_dir_name: fd={}, path_len={}", "wasi::fd_prestat_dir_name: fd={}, path_len={}",
fd, path_len fd, path_len
); );
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let path_chars = wasi_try!(path.deref(memory, 0, path_len)); let path_chars = wasi_try!(path.deref(memory, 0, path_len));
let real_fd = wasi_try!(state.fs.fd_map.get(&fd).ok_or(__WASI_EBADF)); let real_fd = wasi_try!(state.fs.fd_map.get(&fd).ok_or(__WASI_EBADF));
@@ -795,7 +796,7 @@ pub fn fd_pwrite(
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::fd_pwrite"); debug!("wasi::fd_pwrite");
// TODO: refactor, this is just copied from `fd_write`... // TODO: refactor, this is just copied from `fd_write`...
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let iovs_arr_cell = wasi_try!(iovs.deref(memory, 0, iovs_len)); let iovs_arr_cell = wasi_try!(iovs.deref(memory, 0, iovs_len));
let nwritten_cell = wasi_try!(nwritten.deref(memory)); let nwritten_cell = wasi_try!(nwritten.deref(memory));
@@ -828,7 +829,8 @@ pub fn fd_pwrite(
return __WASI_EACCES; return __WASI_EACCES;
} }
let inode = &mut state.fs.inodes[fd_entry.inode]; let inode_idx = fd_entry.inode;
let inode = &mut state.fs.inodes[inode_idx];
match &mut inode.kind { match &mut inode.kind {
Kind::File { handle, .. } => { Kind::File { handle, .. } => {
@@ -878,7 +880,7 @@ pub fn fd_read(
nread: WasmPtr<u32>, nread: WasmPtr<u32>,
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::fd_read: fd={}", fd); debug!("wasi::fd_read: fd={}", fd);
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let iovs_arr_cell = wasi_try!(iovs.deref(memory, 0, iovs_len)); let iovs_arr_cell = wasi_try!(iovs.deref(memory, 0, iovs_len));
let nread_cell = wasi_try!(nread.deref(memory)); let nread_cell = wasi_try!(nread.deref(memory));
@@ -903,7 +905,8 @@ pub fn fd_read(
} }
let offset = fd_entry.offset as usize; let offset = fd_entry.offset as usize;
let inode = &mut state.fs.inodes[fd_entry.inode]; let inode_idx = fd_entry.inode;
let inode = &mut state.fs.inodes[inode_idx];
let bytes_read = match &mut inode.kind { let bytes_read = match &mut inode.kind {
Kind::File { handle, .. } => { Kind::File { handle, .. } => {
@@ -924,6 +927,8 @@ pub fn fd_read(
} }
}; };
// reborrow
let fd_entry = wasi_try!(state.fs.fd_map.get_mut(&fd).ok_or(__WASI_EBADF));
fd_entry.offset += bytes_read as u64; fd_entry.offset += bytes_read as u64;
bytes_read bytes_read
@@ -959,7 +964,7 @@ pub fn fd_readdir(
bufused: WasmPtr<u32>, bufused: WasmPtr<u32>,
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::fd_readdir"); debug!("wasi::fd_readdir");
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
// TODO: figure out how this is supposed to work; // TODO: figure out how this is supposed to work;
// is it supposed to pack the buffer full every time until it can't? or do one at a time? // is it supposed to pack the buffer full every time until it can't? or do one at a time?
@@ -1069,7 +1074,7 @@ pub fn fd_readdir(
/// Location to copy file descriptor to /// Location to copy file descriptor to
pub fn fd_renumber(env: &mut WasiEnv, from: __wasi_fd_t, to: __wasi_fd_t) -> __wasi_errno_t { pub fn fd_renumber(env: &mut WasiEnv, from: __wasi_fd_t, to: __wasi_fd_t) -> __wasi_errno_t {
debug!("wasi::fd_renumber: from={}, to={}", from, to); debug!("wasi::fd_renumber: from={}, to={}", from, to);
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let fd_entry = wasi_try!(state.fs.fd_map.get(&from).ok_or(__WASI_EBADF)); let fd_entry = wasi_try!(state.fs.fd_map.get(&from).ok_or(__WASI_EBADF));
let new_fd_entry = Fd { let new_fd_entry = Fd {
// TODO: verify this is correct // TODO: verify this is correct
@@ -1102,7 +1107,7 @@ pub fn fd_seek(
newoffset: WasmPtr<__wasi_filesize_t>, newoffset: WasmPtr<__wasi_filesize_t>,
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::fd_seek: fd={}, offset={}", fd, offset); debug!("wasi::fd_seek: fd={}, offset={}", fd, offset);
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let new_offset_cell = wasi_try!(newoffset.deref(memory)); let new_offset_cell = wasi_try!(newoffset.deref(memory));
let fd_entry = wasi_try!(state.fs.fd_map.get_mut(&fd).ok_or(__WASI_EBADF)); let fd_entry = wasi_try!(state.fs.fd_map.get_mut(&fd).ok_or(__WASI_EBADF));
@@ -1116,11 +1121,15 @@ pub fn fd_seek(
__WASI_WHENCE_CUR => fd_entry.offset = (fd_entry.offset as i64 + offset) as u64, __WASI_WHENCE_CUR => fd_entry.offset = (fd_entry.offset as i64 + offset) as u64,
__WASI_WHENCE_END => { __WASI_WHENCE_END => {
use std::io::SeekFrom; use std::io::SeekFrom;
match state.fs.inodes[fd_entry.inode].kind { let inode_idx = fd_entry.inode;
match state.fs.inodes[inode_idx].kind {
Kind::File { ref mut handle, .. } => { Kind::File { ref mut handle, .. } => {
if let Some(handle) = handle { if let Some(handle) = handle {
let end = wasi_try!(handle.seek(SeekFrom::End(0)).ok().ok_or(__WASI_EIO)); let end = wasi_try!(handle.seek(SeekFrom::End(0)).ok().ok_or(__WASI_EIO));
// TODO: handle case if fd_entry.offset uses 64 bits of a u64 // TODO: handle case if fd_entry.offset uses 64 bits of a u64
// reborrow
let fd_entry = wasi_try!(state.fs.fd_map.get_mut(&fd).ok_or(__WASI_EBADF));
fd_entry.offset = (end as i64 + offset) as u64; fd_entry.offset = (end as i64 + offset) as u64;
} else { } else {
return __WASI_EINVAL; return __WASI_EINVAL;
@@ -1143,7 +1152,8 @@ pub fn fd_seek(
__WASI_WHENCE_SET => fd_entry.offset = offset as u64, __WASI_WHENCE_SET => fd_entry.offset = offset as u64,
_ => return __WASI_EINVAL, _ => return __WASI_EINVAL,
} }
// reborrow
let fd_entry = wasi_try!(state.fs.fd_map.get_mut(&fd).ok_or(__WASI_EBADF));
new_offset_cell.set(fd_entry.offset); new_offset_cell.set(fd_entry.offset);
__WASI_ESUCCESS __WASI_ESUCCESS
@@ -1161,7 +1171,7 @@ pub fn fd_seek(
pub fn fd_sync(env: &mut WasiEnv, fd: __wasi_fd_t) -> __wasi_errno_t { pub fn fd_sync(env: &mut WasiEnv, fd: __wasi_fd_t) -> __wasi_errno_t {
debug!("wasi::fd_sync"); debug!("wasi::fd_sync");
debug!("=> fd={}", fd); debug!("=> fd={}", fd);
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let fd_entry = wasi_try!(state.fs.get_fd(fd)); let fd_entry = wasi_try!(state.fs.get_fd(fd));
if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_SYNC) { if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_SYNC) {
return __WASI_EACCES; return __WASI_EACCES;
@@ -1198,7 +1208,7 @@ pub fn fd_tell(
offset: WasmPtr<__wasi_filesize_t>, offset: WasmPtr<__wasi_filesize_t>,
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::fd_tell"); debug!("wasi::fd_tell");
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let offset_cell = wasi_try!(offset.deref(memory)); let offset_cell = wasi_try!(offset.deref(memory));
let fd_entry = wasi_try!(state.fs.fd_map.get_mut(&fd).ok_or(__WASI_EBADF)); let fd_entry = wasi_try!(state.fs.fd_map.get_mut(&fd).ok_or(__WASI_EBADF));
@@ -1241,7 +1251,7 @@ pub fn fd_write(
} else { } else {
trace!("wasi::fd_write: fd={}", fd); trace!("wasi::fd_write: fd={}", fd);
} }
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let iovs_arr_cell = wasi_try!(iovs.deref(memory, 0, iovs_len)); let iovs_arr_cell = wasi_try!(iovs.deref(memory, 0, iovs_len));
let nwritten_cell = wasi_try!(nwritten.deref(memory)); let nwritten_cell = wasi_try!(nwritten.deref(memory));
@@ -1273,7 +1283,8 @@ pub fn fd_write(
} }
let offset = fd_entry.offset as usize; let offset = fd_entry.offset as usize;
let inode = &mut state.fs.inodes[fd_entry.inode]; let inode_idx = fd_entry.inode;
let inode = &mut state.fs.inodes[inode_idx];
let bytes_written = match &mut inode.kind { let bytes_written = match &mut inode.kind {
Kind::File { handle, .. } => { Kind::File { handle, .. } => {
@@ -1294,6 +1305,8 @@ pub fn fd_write(
} }
}; };
// reborrow
let fd_entry = wasi_try!(state.fs.fd_map.get_mut(&fd).ok_or(__WASI_EBADF));
fd_entry.offset += bytes_written as u64; fd_entry.offset += bytes_written as u64;
wasi_try!(state.fs.filestat_resync_size(fd)); wasi_try!(state.fs.filestat_resync_size(fd));
@@ -1326,7 +1339,7 @@ pub fn path_create_directory(
path_len: u32, path_len: u32,
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::path_create_directory"); debug!("wasi::path_create_directory");
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let working_dir = wasi_try!(state.fs.get_fd(fd)); let working_dir = wasi_try!(state.fs.get_fd(fd));
if let Kind::Root { .. } = &state.fs.inodes[working_dir.inode].kind { if let Kind::Root { .. } = &state.fs.inodes[working_dir.inode].kind {
@@ -1431,7 +1444,7 @@ pub fn path_filestat_get(
buf: WasmPtr<__wasi_filestat_t>, buf: WasmPtr<__wasi_filestat_t>,
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::path_filestat_get"); debug!("wasi::path_filestat_get");
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let root_dir = wasi_try!(state.fs.get_fd(fd)); let root_dir = wasi_try!(state.fs.get_fd(fd));
@@ -1490,7 +1503,7 @@ pub fn path_filestat_set_times(
fst_flags: __wasi_fstflags_t, fst_flags: __wasi_fstflags_t,
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::path_filestat_set_times"); debug!("wasi::path_filestat_set_times");
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let fd_entry = wasi_try!(state.fs.get_fd(fd)); let fd_entry = wasi_try!(state.fs.get_fd(fd));
let fd_inode = fd_entry.inode; let fd_inode = fd_entry.inode;
if !has_rights(fd_entry.rights, __WASI_RIGHT_PATH_FILESTAT_SET_TIMES) { if !has_rights(fd_entry.rights, __WASI_RIGHT_PATH_FILESTAT_SET_TIMES) {
@@ -1581,7 +1594,7 @@ pub fn path_link(
if old_flags & __WASI_LOOKUP_SYMLINK_FOLLOW != 0 { if old_flags & __WASI_LOOKUP_SYMLINK_FOLLOW != 0 {
debug!(" - will follow symlinks when opening path"); debug!(" - will follow symlinks when opening path");
} }
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let old_path_str = get_input_str!(memory, old_path, old_path_len); let old_path_str = get_input_str!(memory, old_path, old_path_len);
let new_path_str = get_input_str!(memory, new_path, new_path_len); let new_path_str = get_input_str!(memory, new_path, new_path_len);
let source_fd = wasi_try!(state.fs.get_fd(old_fd)); let source_fd = wasi_try!(state.fs.get_fd(old_fd));
@@ -1666,7 +1679,7 @@ pub fn path_open(
if dirflags & __WASI_LOOKUP_SYMLINK_FOLLOW != 0 { if dirflags & __WASI_LOOKUP_SYMLINK_FOLLOW != 0 {
debug!(" - will follow symlinks when opening path"); debug!(" - will follow symlinks when opening path");
} }
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
/* TODO: find actual upper bound on name size (also this is a path, not a name :think-fish:) */ /* TODO: find actual upper bound on name size (also this is a path, not a name :think-fish:) */
if path_len > 1024 * 1024 { if path_len > 1024 * 1024 {
return __WASI_ENAMETOOLONG; return __WASI_ENAMETOOLONG;
@@ -1897,7 +1910,7 @@ pub fn path_readlink(
buf_used: WasmPtr<u32>, buf_used: WasmPtr<u32>,
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::path_readlink"); debug!("wasi::path_readlink");
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let base_dir = wasi_try!(state.fs.fd_map.get(&dir_fd).ok_or(__WASI_EBADF)); let base_dir = wasi_try!(state.fs.fd_map.get(&dir_fd).ok_or(__WASI_EBADF));
if !has_rights(base_dir.rights, __WASI_RIGHT_PATH_READLINK) { if !has_rights(base_dir.rights, __WASI_RIGHT_PATH_READLINK) {
@@ -1940,7 +1953,7 @@ pub fn path_remove_directory(
) -> __wasi_errno_t { ) -> __wasi_errno_t {
// TODO check if fd is a dir, ensure it's within sandbox, etc. // TODO check if fd is a dir, ensure it's within sandbox, etc.
debug!("wasi::path_remove_directory"); debug!("wasi::path_remove_directory");
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let base_dir = wasi_try!(state.fs.fd_map.get(&fd), __WASI_EBADF); let base_dir = wasi_try!(state.fs.fd_map.get(&fd), __WASI_EBADF);
let path_str = get_input_str!(memory, path, path_len); let path_str = get_input_str!(memory, path, path_len);
@@ -2018,7 +2031,7 @@ pub fn path_rename(
new_path_len: u32, new_path_len: u32,
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::path_rename"); debug!("wasi::path_rename");
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let source_str = get_input_str!(memory, old_path, old_path_len); let source_str = get_input_str!(memory, old_path, old_path_len);
let source_path = std::path::Path::new(source_str); let source_path = std::path::Path::new(source_str);
let target_str = get_input_str!(memory, new_path, new_path_len); let target_str = get_input_str!(memory, new_path, new_path_len);
@@ -2126,7 +2139,7 @@ pub fn path_symlink(
new_path_len: u32, new_path_len: u32,
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::path_symlink"); debug!("wasi::path_symlink");
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let old_path_str = get_input_str!(memory, old_path, old_path_len); let old_path_str = get_input_str!(memory, old_path, old_path_len);
let new_path_str = get_input_str!(memory, new_path, new_path_len); let new_path_str = get_input_str!(memory, new_path, new_path_len);
let base_fd = wasi_try!(state.fs.get_fd(fd)); let base_fd = wasi_try!(state.fs.get_fd(fd));
@@ -2203,7 +2216,7 @@ pub fn path_unlink_file(
path_len: u32, path_len: u32,
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::path_unlink_file"); debug!("wasi::path_unlink_file");
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let base_dir = wasi_try!(state.fs.fd_map.get(&fd).ok_or(__WASI_EBADF)); let base_dir = wasi_try!(state.fs.fd_map.get(&fd).ok_or(__WASI_EBADF));
if !has_rights(base_dir.rights, __WASI_RIGHT_PATH_UNLINK_FILE) { if !has_rights(base_dir.rights, __WASI_RIGHT_PATH_UNLINK_FILE) {
@@ -2299,7 +2312,7 @@ pub fn poll_oneoff(
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::poll_oneoff"); debug!("wasi::poll_oneoff");
debug!(" => nsubscriptions = {}", nsubscriptions); debug!(" => nsubscriptions = {}", nsubscriptions);
let (memory, state) = env.get_memory_and_wasi_state(0); let (memory, mut state) = env.get_memory_and_wasi_state(0);
let subscription_array = wasi_try!(in_.deref(memory, 0, nsubscriptions)); let subscription_array = wasi_try!(in_.deref(memory, 0, nsubscriptions));
let event_array = wasi_try!(out_.deref(memory, 0, nsubscriptions)); let event_array = wasi_try!(out_.deref(memory, 0, nsubscriptions));

View File

@@ -1,6 +1,7 @@
use crate::utils::{parse_envvar, parse_mapdir}; use crate::utils::{parse_envvar, parse_mapdir};
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::Arc;
use wasmer::{Instance, Module}; use wasmer::{Instance, Module};
use wasmer_wasi::{get_wasi_version, WasiState, WasiVersion}; use wasmer_wasi::{get_wasi_version, WasiState, WasiVersion};
@@ -58,7 +59,7 @@ impl Wasi {
let import_object = wasi_env.import_object(&module)?; let import_object = wasi_env.import_object(&module)?;
let instance = Instance::new(&module, &import_object)?; let instance = Instance::new(&module, &import_object)?;
wasi_env.set_memory(instance.exports.get_memory("memory")?); wasi_env.set_memory(Arc::new(instance.exports.get_memory("memory")?.clone()));
let start = instance.exports.get_function("_start")?; let start = instance.exports.get_function("_start")?;
start start

View File

@@ -136,7 +136,7 @@ impl StoreOptions {
} else { } else {
// Auto mode, we choose the best compiler for that platform // Auto mode, we choose the best compiler for that platform
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(all(feature = "cranelift", target_arch = "x86_64"))] { if #[cfg(all(feature = "cranelift", any(target_arch = "x86_64", target_arch = "aarch64")))] {
Ok(CompilerType::Cranelift) Ok(CompilerType::Cranelift)
} }
else if #[cfg(all(feature = "singlepass", target_arch = "x86_64"))] { else if #[cfg(all(feature = "singlepass", target_arch = "x86_64"))] {

View File

@@ -1,5 +1,7 @@
use crate::utils::get_store; use crate::utils::get_store;
use anyhow::Result; use anyhow::Result;
use std::cell::RefCell;
use std::rc::Rc;
use wasmer::*; use wasmer::*;
@@ -57,10 +59,13 @@ fn static_raw_call_no_env() -> anyhow::Result<()> {
#[test] #[test]
fn static_raw_call_with_env() -> anyhow::Result<()> { fn static_raw_call_with_env() -> anyhow::Result<()> {
let store = get_store(); let store = get_store();
#[derive(Clone)]
struct Env { struct Env {
val: i32, val: Rc<RefCell<i32>>,
};
let env = Env {
val: Rc::new(RefCell::new(100)),
}; };
let mut env = Env { val: 100 };
fn reverse_duplicate_host( fn reverse_duplicate_host(
env: &mut Env, env: &mut Env,
a: i32, a: i32,
@@ -68,17 +73,17 @@ fn static_raw_call_with_env() -> anyhow::Result<()> {
c: f32, c: f32,
d: f64, d: f64,
) -> (f64, f32, i64, i32) { ) -> (f64, f32, i64, i32) {
assert_eq!(env.val, 100); assert_eq!(*env.val.borrow(), 100);
env.val = 101; env.val.replace(101);
(d * 4.0, c * 3.0, b * 2, a * 1) (d * 4.0, c * 3.0, b * 2, a * 1)
} }
let reverse_duplicate = wasmer::Function::new_env(&store, &mut env, reverse_duplicate_host); let reverse_duplicate = wasmer::Function::new_env(&store, env.clone(), reverse_duplicate_host);
let reverse_duplicate_native: NativeFunc<(i32, i64, f32, f64), (f64, f32, i64, i32)> = let reverse_duplicate_native: NativeFunc<(i32, i64, f32, f64), (f64, f32, i64, i32)> =
reverse_duplicate.native().unwrap(); reverse_duplicate.native().unwrap();
assert_eq!(env.val, 100); assert_eq!(*env.val.borrow(), 100);
let result = reverse_duplicate_native.call(1, 3, 5.0, 7.0)?; let result = reverse_duplicate_native.call(1, 3, 5.0, 7.0)?;
assert_eq!(result, (28.0, 15.0, 6, 1)); assert_eq!(result, (28.0, 15.0, 6, 1));
assert_eq!(env.val, 101); assert_eq!(*env.val.borrow(), 101);
Ok(()) Ok(())
} }
@@ -120,10 +125,13 @@ fn dynamic_raw_call_no_env() -> anyhow::Result<()> {
#[test] #[test]
fn dynamic_raw_call_with_env() -> anyhow::Result<()> { fn dynamic_raw_call_with_env() -> anyhow::Result<()> {
let store = get_store(); let store = get_store();
#[derive(Clone)]
struct Env { struct Env {
val: i32, val: Rc<RefCell<i32>>,
};
let env = Env {
val: Rc::new(RefCell::new(100)),
}; };
let mut env = Env { val: 100 };
let reverse_duplicate = wasmer::Function::new_dynamic_env( let reverse_duplicate = wasmer::Function::new_dynamic_env(
&store, &store,
&wasmer::FunctionType::new( &wasmer::FunctionType::new(
@@ -140,10 +148,10 @@ fn dynamic_raw_call_with_env() -> anyhow::Result<()> {
wasmer::ValType::I32, wasmer::ValType::I32,
], ],
), ),
&mut env, env.clone(),
|env, values| { |env, values| {
assert_eq!(env.val, 100); assert_eq!(*env.val.borrow(), 100);
env.val = 101; env.val.replace(101);
Ok(vec![ Ok(vec![
Value::F64(values[3].unwrap_f64() * 4.0), Value::F64(values[3].unwrap_f64() * 4.0),
Value::F32(values[2].unwrap_f32() * 3.0), Value::F32(values[2].unwrap_f32() * 3.0),
@@ -154,9 +162,9 @@ fn dynamic_raw_call_with_env() -> anyhow::Result<()> {
); );
let reverse_duplicate_native: NativeFunc<(i32, i64, f32, f64), (f64, f32, i64, i32)> = let reverse_duplicate_native: NativeFunc<(i32, i64, f32, f64), (f64, f32, i64, i32)> =
reverse_duplicate.native().unwrap(); reverse_duplicate.native().unwrap();
assert_eq!(env.val, 100); assert_eq!(*env.val.borrow(), 100);
let result = reverse_duplicate_native.call(1, 3, 5.0, 7.0)?; let result = reverse_duplicate_native.call(1, 3, 5.0, 7.0)?;
assert_eq!(result, (28.0, 15.0, 6, 1)); assert_eq!(result, (28.0, 15.0, 6, 1));
assert_eq!(env.val, 101); assert_eq!(*env.val.borrow(), 101);
Ok(()) Ok(())
} }

View File

@@ -5,6 +5,7 @@
use crate::utils::get_store; use crate::utils::get_store;
use anyhow::Result; use anyhow::Result;
use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
use std::sync::Arc;
use wasmer::*; use wasmer::*;
fn get_module(store: &Store) -> Result<Module> { fn get_module(store: &Store) -> Result<Module> {
@@ -82,27 +83,27 @@ fn dynamic_function_with_env() -> Result<()> {
let store = get_store(); let store = get_store();
let module = get_module(&store)?; let module = get_module(&store)?;
let mut env: AtomicUsize = AtomicUsize::new(0); let env: Arc<AtomicUsize> = Arc::new(AtomicUsize::new(0));
Instance::new( Instance::new(
&module, &module,
&imports! { &imports! {
"host" => { "host" => {
"0" => Function::new_dynamic_env(&store, &FunctionType::new(vec![], vec![]), &mut env, |env, _values| { "0" => Function::new_dynamic_env(&store, &FunctionType::new(vec![], vec![]), env.clone(), |env, _values| {
assert_eq!(env.fetch_add(1, SeqCst), 0); assert_eq!(env.fetch_add(1, SeqCst), 0);
Ok(vec![]) Ok(vec![])
}), }),
"1" => Function::new_dynamic_env(&store, &FunctionType::new(vec![ValType::I32], vec![ValType::I32]), &mut env, |env, values| { "1" => Function::new_dynamic_env(&store, &FunctionType::new(vec![ValType::I32], vec![ValType::I32]), env.clone(), |env, values| {
assert_eq!(values[0], Value::I32(0)); assert_eq!(values[0], Value::I32(0));
assert_eq!(env.fetch_add(1, SeqCst), 1); assert_eq!(env.fetch_add(1, SeqCst), 1);
Ok(vec![Value::I32(1)]) Ok(vec![Value::I32(1)])
}), }),
"2" => Function::new_dynamic_env(&store, &FunctionType::new(vec![ValType::I32, ValType::I64], vec![]), &mut env, |env, values| { "2" => Function::new_dynamic_env(&store, &FunctionType::new(vec![ValType::I32, ValType::I64], vec![]), env.clone(), |env, values| {
assert_eq!(values[0], Value::I32(2)); assert_eq!(values[0], Value::I32(2));
assert_eq!(values[1], Value::I64(3)); assert_eq!(values[1], Value::I64(3));
assert_eq!(env.fetch_add(1, SeqCst), 2); assert_eq!(env.fetch_add(1, SeqCst), 2);
Ok(vec![]) Ok(vec![])
}), }),
"3" => Function::new_dynamic_env(&store, &FunctionType::new(vec![ValType::I32, ValType::I64, ValType::I32, ValType::F32, ValType::F64], vec![]), &mut env, |env, values| { "3" => Function::new_dynamic_env(&store, &FunctionType::new(vec![ValType::I32, ValType::I64, ValType::I32, ValType::F32, ValType::F64], vec![]), env.clone(), |env, values| {
assert_eq!(values[0], Value::I32(100)); assert_eq!(values[0], Value::I32(100));
assert_eq!(values[1], Value::I64(200)); assert_eq!(values[1], Value::I64(200));
assert_eq!(values[2], Value::I32(300)); assert_eq!(values[2], Value::I32(300));
@@ -161,25 +162,25 @@ fn native_function_with_env() -> Result<()> {
let store = get_store(); let store = get_store();
let module = get_module(&store)?; let module = get_module(&store)?;
let mut env: AtomicUsize = AtomicUsize::new(0); let env: Arc<AtomicUsize> = Arc::new(AtomicUsize::new(0));
Instance::new( Instance::new(
&module, &module,
&imports! { &imports! {
"host" => { "host" => {
"0" => Function::new_env(&store, &mut env, |env: &mut AtomicUsize| { "0" => Function::new_env(&store, env.clone(), |env: &mut Arc<AtomicUsize>| {
assert_eq!(env.fetch_add(1, SeqCst), 0); assert_eq!(env.fetch_add(1, SeqCst), 0);
}), }),
"1" => Function::new_env(&store, &mut env, |env: &mut AtomicUsize, x: i32| -> i32 { "1" => Function::new_env(&store, env.clone(), |env: &mut Arc<AtomicUsize>, x: i32| -> i32 {
assert_eq!(x, 0); assert_eq!(x, 0);
assert_eq!(env.fetch_add(1, SeqCst), 1); assert_eq!(env.fetch_add(1, SeqCst), 1);
1 1
}), }),
"2" => Function::new_env(&store, &mut env, |env: &mut AtomicUsize, x: i32, y: i64| { "2" => Function::new_env(&store, env.clone(), |env: &mut Arc<AtomicUsize>, x: i32, y: i64| {
assert_eq!(x, 2); assert_eq!(x, 2);
assert_eq!(y, 3); assert_eq!(y, 3);
assert_eq!(env.fetch_add(1, SeqCst), 2); assert_eq!(env.fetch_add(1, SeqCst), 2);
}), }),
"3" => Function::new_env(&store, &mut env, |env: &mut AtomicUsize, a: i32, b: i64, c: i32, d: f32, e: f64| { "3" => Function::new_env(&store, env.clone(), |env: &mut Arc<AtomicUsize>, a: i32, b: i64, c: i32, d: f32, e: f64| {
assert_eq!(a, 100); assert_eq!(a, 100);
assert_eq!(b, 200); assert_eq!(b, 200);
assert_eq!(c, 300); assert_eq!(c, 300);