diff --git a/lib/api/src/native.rs b/lib/api/src/native.rs index a7eecde14..559d81e02 100644 --- a/lib/api/src/native.rs +++ b/lib/api/src/native.rs @@ -9,12 +9,7 @@ use wasmer_runtime::{ wasmer_call_trampoline, ExportFunction, VMContext, VMFunctionBody, VMFunctionKind, }; -#[derive(Clone)] -pub struct UnprovidedArgs; -#[derive(Clone)] -pub struct UnprovidedRets; - -pub struct NativeFunc<'a, Args = UnprovidedArgs, Rets = UnprovidedRets> { +pub struct NativeFunc<'a, Args = (), Rets = ()> { definition: FunctionDefinition, store: Store, address: *const VMFunctionBody, diff --git a/lib/emscripten/src/bitwise.rs b/lib/emscripten/src/bitwise.rs index 6868c402a..fb9c20b66 100644 --- a/lib/emscripten/src/bitwise.rs +++ b/lib/emscripten/src/bitwise.rs @@ -1,9 +1,9 @@ use crate::emscripten_target; -use wasmer_runtime_core::vm::Ctx; +use crate::EmEnv; ///emscripten: _llvm_bswap_i64 -pub fn _llvm_bswap_i64(_ctx: &mut Ctx, _low: i32, high: i32) -> i32 { +pub fn _llvm_bswap_i64(ctx: &mut EmEnv, _low: i32, high: i32) -> i32 { debug!("emscripten::_llvm_bswap_i64"); - emscripten_target::setTempRet0(_ctx, _low.swap_bytes()); + emscripten_target::setTempRet0(ctx, _low.swap_bytes()); high.swap_bytes() } diff --git a/lib/emscripten/src/emscripten_target.rs b/lib/emscripten/src/emscripten_target.rs index 1098d5926..2458cc8f2 100644 --- a/lib/emscripten/src/emscripten_target.rs +++ b/lib/emscripten/src/emscripten_target.rs @@ -1,35 +1,35 @@ #![allow(non_snake_case)] use crate::env::get_emscripten_data; +use crate::EmEnv; #[cfg(target_os = "linux")] use libc::getdtablesize; -use wasmer_runtime_core::vm::Ctx; -pub fn asm_const_i(_ctx: &mut Ctx, _val: i32) -> i32 { +pub fn asm_const_i(_ctx: &mut EmEnv, _val: i32) -> i32 { debug!("emscripten::asm_const_i: {}", _val); 0 } -pub fn exit_with_live_runtime(_ctx: &mut Ctx) { +pub fn exit_with_live_runtime(_ctx: &mut EmEnv) { debug!("emscripten::exit_with_live_runtime"); } -pub fn setTempRet0(ctx: &mut Ctx, val: i32) { +pub fn setTempRet0(ctx: &mut EmEnv, val: i32) { trace!("emscripten::setTempRet0: {}", val); get_emscripten_data(ctx).temp_ret_0 = val; } -pub fn getTempRet0(ctx: &mut Ctx) -> i32 { +pub fn getTempRet0(ctx: &mut EmEnv) -> i32 { trace!("emscripten::getTempRet0"); get_emscripten_data(ctx).temp_ret_0 } -pub fn _alarm(_ctx: &mut Ctx, _seconds: u32) -> i32 { +pub fn _alarm(_ctx: &mut EmEnv, _seconds: u32) -> i32 { debug!("emscripten::_alarm({})", _seconds); 0 } -pub fn _atexit(_ctx: &mut Ctx, _func: i32) -> i32 { +pub fn _atexit(_ctx: &mut EmEnv, _func: i32) -> i32 { debug!("emscripten::_atexit"); // TODO: implement atexit properly // __ATEXIT__.unshift({ @@ -38,38 +38,38 @@ pub fn _atexit(_ctx: &mut Ctx, _func: i32) -> i32 { // }); 0 } -pub fn __Unwind_Backtrace(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { +pub fn __Unwind_Backtrace(_ctx: &mut EmEnv, _a: i32, _b: i32) -> i32 { debug!("emscripten::__Unwind_Backtrace"); 0 } -pub fn __Unwind_FindEnclosingFunction(_ctx: &mut Ctx, _a: i32) -> i32 { +pub fn __Unwind_FindEnclosingFunction(_ctx: &mut EmEnv, _a: i32) -> i32 { debug!("emscripten::__Unwind_FindEnclosingFunction"); 0 } -pub fn __Unwind_GetIPInfo(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { +pub fn __Unwind_GetIPInfo(_ctx: &mut EmEnv, _a: i32, _b: i32) -> i32 { debug!("emscripten::__Unwind_GetIPInfo"); 0 } -pub fn ___cxa_find_matching_catch_2(_ctx: &mut Ctx) -> i32 { +pub fn ___cxa_find_matching_catch_2(_ctx: &mut EmEnv) -> i32 { debug!("emscripten::___cxa_find_matching_catch_2"); 0 } -pub fn ___cxa_find_matching_catch_3(_ctx: &mut Ctx, _a: i32) -> i32 { +pub fn ___cxa_find_matching_catch_3(_ctx: &mut EmEnv, _a: i32) -> i32 { debug!("emscripten::___cxa_find_matching_catch_3"); 0 } -pub fn ___cxa_free_exception(_ctx: &mut Ctx, _a: i32) { +pub fn ___cxa_free_exception(_ctx: &mut EmEnv, _a: i32) { debug!("emscripten::___cxa_free_exception"); } -pub fn ___resumeException(_ctx: &mut Ctx, _a: i32) { +pub fn ___resumeException(_ctx: &mut EmEnv, _a: i32) { debug!("emscripten::___resumeException"); } -pub fn _dladdr(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { +pub fn _dladdr(_ctx: &mut EmEnv, _a: i32, _b: i32) -> i32 { debug!("emscripten::_dladdr"); 0 } pub fn ___gxx_personality_v0( - _ctx: &mut Ctx, + _ctx: &mut EmEnv, _a: i32, _b: i32, _c: i32, @@ -82,25 +82,25 @@ pub fn ___gxx_personality_v0( } #[cfg(target_os = "linux")] -pub fn _getdtablesize(_ctx: &mut Ctx) -> i32 { +pub fn _getdtablesize(_ctx: &mut EmEnv) -> i32 { debug!("emscripten::getdtablesize"); unsafe { getdtablesize() } } #[cfg(not(target_os = "linux"))] -pub fn _getdtablesize(_ctx: &mut Ctx) -> i32 { +pub fn _getdtablesize(_ctx: &mut EmEnv) -> i32 { debug!("emscripten::getdtablesize"); -1 } -pub fn _gethostbyaddr(_ctx: &mut Ctx, _addr: i32, _addrlen: i32, _atype: i32) -> i32 { +pub fn _gethostbyaddr(_ctx: &mut EmEnv, _addr: i32, _addrlen: i32, _atype: i32) -> i32 { debug!("emscripten::gethostbyaddr"); 0 } -pub fn _gethostbyname(_ctx: &mut Ctx, _name: i32) -> i32 { +pub fn _gethostbyname(_ctx: &mut EmEnv, _name: i32) -> i32 { debug!("emscripten::gethostbyname_r"); 0 } pub fn _gethostbyname_r( - _ctx: &mut Ctx, + _ctx: &mut EmEnv, _name: i32, _ret: i32, _buf: i32, @@ -112,12 +112,12 @@ pub fn _gethostbyname_r( 0 } // NOTE: php.js has proper impl; libc has proper impl for linux -pub fn _getloadavg(_ctx: &mut Ctx, _loadavg: i32, _nelem: i32) -> i32 { +pub fn _getloadavg(_ctx: &mut EmEnv, _loadavg: i32, _nelem: i32) -> i32 { debug!("emscripten::getloadavg"); 0 } pub fn _getnameinfo( - _ctx: &mut Ctx, + _ctx: &mut EmEnv, _addr: i32, _addrlen: i32, _host: i32, @@ -170,61 +170,61 @@ macro_rules! invoke_no_return { } // Invoke functions -pub fn invoke_i(ctx: &mut Ctx, index: i32) -> i32 { +pub fn invoke_i(ctx: &mut EmEnv, index: i32) -> i32 { debug!("emscripten::invoke_i"); invoke!(ctx, dyn_call_i, index) } -pub fn invoke_ii(ctx: &mut Ctx, index: i32, a1: i32) -> i32 { +pub fn invoke_ii(ctx: &mut EmEnv, index: i32, a1: i32) -> i32 { debug!("emscripten::invoke_ii"); invoke!(ctx, dyn_call_ii, index, a1) } -pub fn invoke_iii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32) -> i32 { +pub fn invoke_iii(ctx: &mut EmEnv, index: i32, a1: i32, a2: i32) -> i32 { debug!("emscripten::invoke_iii"); invoke!(ctx, dyn_call_iii, index, a1, a2) } -pub fn invoke_iiii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32) -> i32 { +pub fn invoke_iiii(ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, a3: i32) -> i32 { debug!("emscripten::invoke_iiii"); invoke!(ctx, dyn_call_iiii, index, a1, a2, a3) } -pub fn invoke_iifi(ctx: &mut Ctx, index: i32, a1: i32, a2: f64, a3: i32) -> i32 { +pub fn invoke_iifi(ctx: &mut EmEnv, index: i32, a1: i32, a2: f64, a3: i32) -> i32 { debug!("emscripten::invoke_iifi"); invoke!(ctx, dyn_call_iifi, index, a1, a2, a3) } -pub fn invoke_v(ctx: &mut Ctx, index: i32) { +pub fn invoke_v(ctx: &mut EmEnv, index: i32) { debug!("emscripten::invoke_v"); invoke_no_return!(ctx, dyn_call_v, index); } -pub fn invoke_vi(ctx: &mut Ctx, index: i32, a1: i32) { +pub fn invoke_vi(ctx: &mut EmEnv, index: i32, a1: i32) { debug!("emscripten::invoke_vi"); invoke_no_return!(ctx, dyn_call_vi, index, a1); } -pub fn invoke_vii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32) { +pub fn invoke_vii(ctx: &mut EmEnv, index: i32, a1: i32, a2: i32) { debug!("emscripten::invoke_vii"); invoke_no_return!(ctx, dyn_call_vii, index, a1, a2); } -pub fn invoke_viii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32) { +pub fn invoke_viii(ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, a3: i32) { debug!("emscripten::invoke_viii"); invoke_no_return!(ctx, dyn_call_viii, index, a1, a2, a3); } -pub fn invoke_viiii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) { +pub fn invoke_viiii(ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) { debug!("emscripten::invoke_viiii"); invoke_no_return!(ctx, dyn_call_viiii, index, a1, a2, a3, a4); } -pub fn invoke_dii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32) -> f64 { +pub fn invoke_dii(ctx: &mut EmEnv, index: i32, a1: i32, a2: i32) -> f64 { debug!("emscripten::invoke_dii"); invoke!(ctx, dyn_call_dii, index, a1, a2) } -pub fn invoke_diiii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) -> f64 { +pub fn invoke_diiii(ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) -> f64 { debug!("emscripten::invoke_diiii"); invoke!(ctx, dyn_call_diiii, index, a1, a2, a3, a4) } -pub fn invoke_iiiii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) -> i32 { +pub fn invoke_iiiii(ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) -> i32 { debug!("emscripten::invoke_iiiii"); invoke!(ctx, dyn_call_iiiii, index, a1, a2, a3, a4) } pub fn invoke_iiiiii( - ctx: &mut Ctx, + ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, @@ -236,7 +236,7 @@ pub fn invoke_iiiiii( invoke!(ctx, dyn_call_iiiiii, index, a1, a2, a3, a4, a5) } pub fn invoke_iiiiiii( - ctx: &mut Ctx, + ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, @@ -249,7 +249,7 @@ pub fn invoke_iiiiiii( invoke!(ctx, dyn_call_iiiiiii, index, a1, a2, a3, a4, a5, a6) } pub fn invoke_iiiiiiii( - ctx: &mut Ctx, + ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, @@ -263,7 +263,7 @@ pub fn invoke_iiiiiiii( invoke!(ctx, dyn_call_iiiiiiii, index, a1, a2, a3, a4, a5, a6, a7) } pub fn invoke_iiiiiiiii( - ctx: &mut Ctx, + ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, @@ -290,7 +290,7 @@ pub fn invoke_iiiiiiiii( ) } pub fn invoke_iiiiiiiiii( - ctx: &mut Ctx, + ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, @@ -319,7 +319,7 @@ pub fn invoke_iiiiiiiiii( ) } pub fn invoke_iiiiiiiiiii( - ctx: &mut Ctx, + ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, @@ -349,16 +349,16 @@ pub fn invoke_iiiiiiiiiii( a10 ) } -pub fn invoke_vd(ctx: &mut Ctx, index: i32, a1: f64) { +pub fn invoke_vd(ctx: &mut EmEnv, index: i32, a1: f64) { debug!("emscripten::invoke_vd"); invoke_no_return!(ctx, dyn_call_vd, index, a1) } -pub fn invoke_viiiii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32, a5: i32) { +pub fn invoke_viiiii(ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, a3: i32, a4: i32, a5: i32) { debug!("emscripten::invoke_viiiii"); invoke_no_return!(ctx, dyn_call_viiiii, index, a1, a2, a3, a4, a5) } pub fn invoke_viiiiii( - ctx: &mut Ctx, + ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, @@ -371,7 +371,7 @@ pub fn invoke_viiiiii( invoke_no_return!(ctx, dyn_call_viiiiii, index, a1, a2, a3, a4, a5, a6) } pub fn invoke_viiiiiii( - ctx: &mut Ctx, + ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, @@ -385,7 +385,7 @@ pub fn invoke_viiiiiii( invoke_no_return!(ctx, dyn_call_viiiiiii, index, a1, a2, a3, a4, a5, a6, a7) } pub fn invoke_viiiiiiii( - ctx: &mut Ctx, + ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, @@ -412,7 +412,7 @@ pub fn invoke_viiiiiiii( ) } pub fn invoke_viiiiiiiii( - ctx: &mut Ctx, + ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, @@ -441,7 +441,7 @@ pub fn invoke_viiiiiiiii( ) } pub fn invoke_viiiiiiiiii( - ctx: &mut Ctx, + ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, @@ -472,23 +472,23 @@ pub fn invoke_viiiiiiiiii( ) } -pub fn invoke_iij(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32) -> i32 { +pub fn invoke_iij(ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, a3: i32) -> i32 { debug!("emscripten::invoke_iij"); invoke!(ctx, dyn_call_iij, index, a1, a2, a3) } -pub fn invoke_iji(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32) -> i32 { +pub fn invoke_iji(ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, a3: i32) -> i32 { debug!("emscripten::invoke_iji"); invoke!(ctx, dyn_call_iji, index, a1, a2, a3) } -pub fn invoke_iiji(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) -> i32 { +pub fn invoke_iiji(ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) -> i32 { debug!("emscripten::invoke_iiji"); invoke!(ctx, dyn_call_iiji, index, a1, a2, a3, a4) } pub fn invoke_iiijj( - ctx: &mut Ctx, + ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, @@ -500,7 +500,7 @@ pub fn invoke_iiijj( debug!("emscripten::invoke_iiijj"); invoke!(ctx, dyn_call_iiijj, index, a1, a2, a3, a4, a5, a6) } -pub fn invoke_j(ctx: &mut Ctx, index: i32) -> i32 { +pub fn invoke_j(ctx: &mut EmEnv, index: i32) -> i32 { debug!("emscripten::invoke_j"); if let Some(dyn_call_j) = &get_emscripten_data(ctx).dyn_call_j { dyn_call_j.call(index).unwrap() @@ -508,7 +508,7 @@ pub fn invoke_j(ctx: &mut Ctx, index: i32) -> i32 { panic!("dyn_call_j is set to None"); } } -pub fn invoke_ji(ctx: &mut Ctx, index: i32, a1: i32) -> i32 { +pub fn invoke_ji(ctx: &mut EmEnv, index: i32, a1: i32) -> i32 { debug!("emscripten::invoke_ji"); if let Some(dyn_call_ji) = &get_emscripten_data(ctx).dyn_call_ji { dyn_call_ji.call(index, a1).unwrap() @@ -516,7 +516,7 @@ pub fn invoke_ji(ctx: &mut Ctx, index: i32, a1: i32) -> i32 { panic!("dyn_call_ji is set to None"); } } -pub fn invoke_jii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32) -> i32 { +pub fn invoke_jii(ctx: &mut EmEnv, index: i32, a1: i32, a2: i32) -> i32 { debug!("emscripten::invoke_jii"); if let Some(dyn_call_jii) = &get_emscripten_data(ctx).dyn_call_jii { dyn_call_jii.call(index, a1, a2).unwrap() @@ -525,7 +525,7 @@ pub fn invoke_jii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32) -> i32 { } } -pub fn invoke_jij(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32) -> i32 { +pub fn invoke_jij(ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, a3: i32) -> i32 { debug!("emscripten::invoke_jij"); if let Some(dyn_call_jij) = &get_emscripten_data(ctx).dyn_call_jij { dyn_call_jij.call(index, a1, a2, a3).unwrap() @@ -533,7 +533,7 @@ pub fn invoke_jij(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32) -> i32 { panic!("dyn_call_jij is set to None"); } } -pub fn invoke_jjj(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) -> i32 { +pub fn invoke_jjj(ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) -> i32 { debug!("emscripten::invoke_jjj"); if let Some(dyn_call_jjj) = &get_emscripten_data(ctx).dyn_call_jjj { dyn_call_jjj.call(index, a1, a2, a3, a4).unwrap() @@ -541,7 +541,7 @@ pub fn invoke_jjj(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) panic!("dyn_call_jjj is set to None"); } } -pub fn invoke_viiij(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32, a5: i32) { +pub fn invoke_viiij(ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, a3: i32, a4: i32, a5: i32) { debug!("emscripten::invoke_viiij"); if let Some(dyn_call_viiij) = &get_emscripten_data(ctx).dyn_call_viiij { dyn_call_viiij.call(index, a1, a2, a3, a4, a5).unwrap(); @@ -550,7 +550,7 @@ pub fn invoke_viiij(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i3 } } pub fn invoke_viiijiiii( - ctx: &mut Ctx, + ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, @@ -572,7 +572,7 @@ pub fn invoke_viiijiiii( } } pub fn invoke_viiijiiiiii( - ctx: &mut Ctx, + ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, @@ -595,7 +595,7 @@ pub fn invoke_viiijiiiiii( panic!("dyn_call_viiijiiiiii is set to None"); } } -pub fn invoke_viij(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) { +pub fn invoke_viij(ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) { debug!("emscripten::invoke_viij"); if let Some(dyn_call_viij) = &get_emscripten_data(ctx).dyn_call_viij { dyn_call_viij.call(index, a1, a2, a3, a4).unwrap(); @@ -603,7 +603,7 @@ pub fn invoke_viij(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32 panic!("dyn_call_viij is set to None"); } } -pub fn invoke_viiji(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32, a5: i32) { +pub fn invoke_viiji(ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, a3: i32, a4: i32, a5: i32) { debug!("emscripten::invoke_viiji"); if let Some(dyn_call_viiji) = &get_emscripten_data(ctx).dyn_call_viiji { dyn_call_viiji.call(index, a1, a2, a3, a4, a5).unwrap(); @@ -612,7 +612,7 @@ pub fn invoke_viiji(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i3 } } pub fn invoke_viijiii( - ctx: &mut Ctx, + ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, @@ -632,7 +632,7 @@ pub fn invoke_viijiii( } } pub fn invoke_viijj( - ctx: &mut Ctx, + ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, @@ -648,7 +648,7 @@ pub fn invoke_viijj( panic!("dyn_call_viijj is set to None"); } } -pub fn invoke_vj(ctx: &mut Ctx, index: i32, a1: i32, a2: i32) { +pub fn invoke_vj(ctx: &mut EmEnv, index: i32, a1: i32, a2: i32) { debug!("emscripten::invoke_vj"); if let Some(dyn_call_vj) = &get_emscripten_data(ctx).dyn_call_vj { dyn_call_vj.call(index, a1, a2).unwrap(); @@ -656,11 +656,11 @@ pub fn invoke_vj(ctx: &mut Ctx, index: i32, a1: i32, a2: i32) { panic!("dyn_call_vj is set to None"); } } -pub fn invoke_vjji(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32, a5: i32) { +pub fn invoke_vjji(ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, a3: i32, a4: i32, a5: i32) { debug!("emscripten::invoke_vjji"); invoke_no_return!(ctx, dyn_call_vjji, index, a1, a2, a3, a4, a5) } -pub fn invoke_vij(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32) { +pub fn invoke_vij(ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, a3: i32) { debug!("emscripten::invoke_vij"); if let Some(dyn_call_vij) = &get_emscripten_data(ctx).dyn_call_vij { dyn_call_vij.call(index, a1, a2, a3).unwrap(); @@ -668,7 +668,7 @@ pub fn invoke_vij(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32) { panic!("dyn_call_vij is set to None"); } } -pub fn invoke_viji(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) { +pub fn invoke_viji(ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) { debug!("emscripten::invoke_viji"); if let Some(dyn_call_viji) = &get_emscripten_data(ctx).dyn_call_viji { dyn_call_viji.call(index, a1, a2, a3, a4).unwrap() @@ -677,7 +677,7 @@ pub fn invoke_viji(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32 } } pub fn invoke_vijiii( - ctx: &mut Ctx, + ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, @@ -693,7 +693,7 @@ pub fn invoke_vijiii( panic!("dyn_call_vijiii is set to None"); } } -pub fn invoke_vijj(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32, a5: i32) { +pub fn invoke_vijj(ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, a3: i32, a4: i32, a5: i32) { debug!("emscripten::invoke_vijj"); if let Some(dyn_call_vijj) = &get_emscripten_data(ctx).dyn_call_vijj { dyn_call_vijj.call(index, a1, a2, a3, a4, a5).unwrap() @@ -701,20 +701,20 @@ pub fn invoke_vijj(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32 panic!("dyn_call_vijj is set to None"); } } -pub fn invoke_vidd(ctx: &mut Ctx, index: i32, a1: i32, a2: f64, a3: f64) { +pub fn invoke_vidd(ctx: &mut EmEnv, index: i32, a1: i32, a2: f64, a3: f64) { debug!("emscripten::invoke_viid"); invoke_no_return!(ctx, dyn_call_vidd, index, a1, a2, a3); } -pub fn invoke_viid(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: f64) { +pub fn invoke_viid(ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, a3: f64) { debug!("emscripten::invoke_viid"); invoke_no_return!(ctx, dyn_call_viid, index, a1, a2, a3); } -pub fn invoke_viidii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: f64, a4: i32, a5: i32) { +pub fn invoke_viidii(ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, a3: f64, a4: i32, a5: i32) { debug!("emscripten::invoke_viidii"); invoke_no_return!(ctx, dyn_call_viidii, index, a1, a2, a3, a4, a5); } pub fn invoke_viidddddddd( - ctx: &mut Ctx, + ctx: &mut EmEnv, index: i32, a1: i32, a2: i32, diff --git a/lib/emscripten/src/env/mod.rs b/lib/emscripten/src/env/mod.rs index a61a2bb9f..59b3255e8 100644 --- a/lib/emscripten/src/env/mod.rs +++ b/lib/emscripten/src/env/mod.rs @@ -19,9 +19,11 @@ use crate::{ }; use std::os::raw::c_int; -use wasmer_runtime_core::{types::ValueType, vm::Ctx}; -pub fn call_malloc(ctx: &mut Ctx, size: u32) -> u32 { +use crate::EmEnv; +use wasmer::ValueType; + +pub fn call_malloc(ctx: &mut EmEnv, size: u32) -> u32 { get_emscripten_data(ctx) .malloc .as_ref() @@ -31,11 +33,11 @@ pub fn call_malloc(ctx: &mut Ctx, size: u32) -> u32 { } #[warn(dead_code)] -pub fn call_malloc_with_cast(ctx: &mut Ctx, size: u32) -> WasmPtr { +pub fn call_malloc_with_cast(ctx: &mut EmEnv, size: u32) -> WasmPtr { WasmPtr::new(call_malloc(ctx, size)) } -pub fn call_memalign(ctx: &mut Ctx, alignment: u32, size: u32) -> u32 { +pub fn call_memalign(ctx: &mut EmEnv, alignment: u32, size: u32) -> u32 { if let Some(memalign) = &get_emscripten_data(ctx).memalign { memalign.call(alignment, size).unwrap() } else { @@ -43,7 +45,7 @@ pub fn call_memalign(ctx: &mut Ctx, alignment: u32, size: u32) -> u32 { } } -pub fn call_memset(ctx: &mut Ctx, pointer: u32, value: u32, size: u32) -> u32 { +pub fn call_memset(ctx: &mut EmEnv, pointer: u32, value: u32, size: u32) -> u32 { get_emscripten_data(ctx) .memset .as_ref() @@ -52,16 +54,16 @@ pub fn call_memset(ctx: &mut Ctx, pointer: u32, value: u32, size: u32) -> u32 { .unwrap() } -pub(crate) fn get_emscripten_data(ctx: &mut Ctx) -> &mut EmscriptenData { - unsafe { &mut *(ctx.data as *mut EmscriptenData) } +pub(crate) fn get_emscripten_data<'a, 'b>(ctx: &'a mut EmEnv<'b>) -> &'a mut EmscriptenData<'b> { + ctx.data } -pub fn _getpagesize(_ctx: &mut Ctx) -> u32 { +pub fn _getpagesize(_ctx: &mut EmEnv) -> u32 { debug!("emscripten::_getpagesize"); 16384 } -pub fn _times(ctx: &mut Ctx, buffer: u32) -> u32 { +pub fn _times(ctx: &mut EmEnv, buffer: u32) -> u32 { if buffer != 0 { call_memset(ctx, buffer, 0, 16); } @@ -69,7 +71,7 @@ pub fn _times(ctx: &mut Ctx, buffer: u32) -> u32 { } #[allow(clippy::cast_ptr_alignment)] -pub fn ___build_environment(ctx: &mut Ctx, environ: c_int) { +pub fn ___build_environment(ctx: &mut EmEnv, environ: c_int) { debug!("emscripten::___build_environment {}", environ); const MAX_ENV_VALUES: u32 = 64; const TOTAL_ENV_SIZE: u32 = 1024; @@ -121,13 +123,13 @@ pub fn ___build_environment(ctx: &mut Ctx, environ: c_int) { } } -pub fn ___assert_fail(_ctx: &mut Ctx, _a: c_int, _b: c_int, _c: c_int, _d: c_int) { +pub fn ___assert_fail(_ctx: &mut EmEnv, _a: c_int, _b: c_int, _c: c_int, _d: c_int) { debug!("emscripten::___assert_fail {} {} {} {}", _a, _b, _c, _d); // TODO: Implement like emscripten expects regarding memory/page size // TODO raise an error } -pub fn _pathconf(ctx: &mut Ctx, path_addr: c_int, name: c_int) -> c_int { +pub fn _pathconf(ctx: &mut EmEnv, path_addr: c_int, name: c_int) -> c_int { debug!( "emscripten::_pathconf {} {} - UNIMPLEMENTED", path_addr, name @@ -148,7 +150,7 @@ pub fn _pathconf(ctx: &mut Ctx, path_addr: c_int, name: c_int) -> c_int { } } -pub fn _fpathconf(_ctx: &mut Ctx, _fildes: c_int, name: c_int) -> c_int { +pub fn _fpathconf(_ctx: &mut EmEnv, _fildes: c_int, name: c_int) -> c_int { debug!("emscripten::_fpathconf {} {}", _fildes, name); match name { 0 => 32000, diff --git a/lib/emscripten/src/env/unix/mod.rs b/lib/emscripten/src/env/unix/mod.rs index 951650495..92fc3b1e4 100644 --- a/lib/emscripten/src/env/unix/mod.rs +++ b/lib/emscripten/src/env/unix/mod.rs @@ -11,11 +11,11 @@ use std::os::raw::c_char; use crate::env::{call_malloc, call_malloc_with_cast, EmAddrInfo, EmSockAddr}; use crate::ptr::{Array, WasmPtr}; use crate::utils::{copy_cstr_into_wasm, copy_terminated_array_of_cstrs}; -use wasmer_runtime_core::vm::Ctx; +use crate::EmEnv; // #[no_mangle] /// emscripten: _getenv // (name: *const char) -> *const c_char; -pub fn _getenv(ctx: &mut Ctx, name: i32) -> u32 { +pub fn _getenv(ctx: &mut EmEnv, name: i32) -> u32 { debug!("emscripten::_getenv"); let name_addr = emscripten_memory_pointer!(ctx.memory(0), name) as *const c_char; @@ -31,7 +31,7 @@ pub fn _getenv(ctx: &mut Ctx, name: i32) -> u32 { } /// emscripten: _setenv // (name: *const char, name: *const value, overwrite: int); -pub fn _setenv(ctx: &mut Ctx, name: c_int, value: c_int, overwrite: c_int) -> c_int { +pub fn _setenv(ctx: &mut EmEnv, name: c_int, value: c_int, overwrite: c_int) -> c_int { debug!("emscripten::_setenv"); let name_addr = emscripten_memory_pointer!(ctx.memory(0), name) as *const c_char; @@ -44,7 +44,7 @@ pub fn _setenv(ctx: &mut Ctx, name: c_int, value: c_int, overwrite: c_int) -> c_ } /// emscripten: _putenv // (name: *const char); -pub fn _putenv(ctx: &mut Ctx, name: c_int) -> c_int { +pub fn _putenv(ctx: &mut EmEnv, name: c_int) -> c_int { debug!("emscripten::_putenv"); let name_addr = emscripten_memory_pointer!(ctx.memory(0), name) as *const c_char; @@ -55,7 +55,7 @@ pub fn _putenv(ctx: &mut Ctx, name: c_int) -> c_int { } /// emscripten: _unsetenv // (name: *const char); -pub fn _unsetenv(ctx: &mut Ctx, name: c_int) -> c_int { +pub fn _unsetenv(ctx: &mut EmEnv, name: c_int) -> c_int { debug!("emscripten::_unsetenv"); let name_addr = emscripten_memory_pointer!(ctx.memory(0), name) as *const c_char; @@ -66,7 +66,7 @@ pub fn _unsetenv(ctx: &mut Ctx, name: c_int) -> c_int { } #[allow(clippy::cast_ptr_alignment)] -pub fn _getpwnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int { +pub fn _getpwnam(ctx: &mut EmEnv, name_ptr: c_int) -> c_int { debug!("emscripten::_getpwnam {}", name_ptr); #[cfg(feature = "debug")] let _ = name_ptr; @@ -106,7 +106,7 @@ pub fn _getpwnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int { } #[allow(clippy::cast_ptr_alignment)] -pub fn _getgrnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int { +pub fn _getgrnam(ctx: &mut EmEnv, name_ptr: c_int) -> c_int { debug!("emscripten::_getgrnam {}", name_ptr); #[repr(C)] @@ -137,14 +137,14 @@ pub fn _getgrnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int { } } -pub fn _sysconf(_ctx: &mut Ctx, name: c_int) -> i32 { +pub fn _sysconf(_ctx: &mut EmEnv, name: c_int) -> i32 { debug!("emscripten::_sysconf {}", name); // TODO: Implement like emscripten expects regarding memory/page size unsafe { sysconf(name) as i32 } // TODO review i64 } // this may be a memory leak, probably not though because emscripten does the same thing -pub fn _gai_strerror(ctx: &mut Ctx, ecode: i32) -> i32 { +pub fn _gai_strerror(ctx: &mut EmEnv, ecode: i32) -> i32 { debug!("emscripten::_gai_strerror({})", ecode); let cstr = unsafe { std::ffi::CStr::from_ptr(libc::gai_strerror(ecode)) }; @@ -164,7 +164,7 @@ pub fn _gai_strerror(ctx: &mut Ctx, ecode: i32) -> i32 { } pub fn _getaddrinfo( - ctx: &mut Ctx, + ctx: &mut EmEnv, node_ptr: WasmPtr, service_str_ptr: WasmPtr, hints_ptr: WasmPtr, diff --git a/lib/emscripten/src/env/windows/mod.rs b/lib/emscripten/src/env/windows/mod.rs index 025a01bd7..f7783bcf8 100644 --- a/lib/emscripten/src/env/windows/mod.rs +++ b/lib/emscripten/src/env/windows/mod.rs @@ -8,7 +8,7 @@ use std::os::raw::c_char; use crate::env::{call_malloc, EmAddrInfo}; use crate::ptr::WasmPtr; use crate::utils::{copy_cstr_into_wasm, read_string_from_wasm}; -use wasmer_runtime_core::vm::Ctx; +use crate::EmEnv; extern "C" { #[link_name = "_putenv"] @@ -17,7 +17,7 @@ extern "C" { // #[no_mangle] /// emscripten: _getenv // (name: *const char) -> *const c_char; -pub fn _getenv(ctx: &mut Ctx, name: u32) -> u32 { +pub fn _getenv(ctx: &mut EmEnv, name: u32) -> u32 { debug!("emscripten::_getenv"); let name_string = read_string_from_wasm(ctx.memory(0), name); debug!("=> name({:?})", name_string); @@ -29,7 +29,7 @@ pub fn _getenv(ctx: &mut Ctx, name: u32) -> u32 { } /// emscripten: _setenv // (name: *const char, name: *const value, overwrite: int); -pub fn _setenv(ctx: &mut Ctx, name: u32, value: u32, _overwrite: u32) -> c_int { +pub fn _setenv(ctx: &mut EmEnv, name: u32, value: u32, _overwrite: u32) -> c_int { debug!("emscripten::_setenv"); // setenv does not exist on windows, so we hack it with _putenv let name = read_string_from_wasm(ctx.memory(0), name); @@ -43,7 +43,7 @@ pub fn _setenv(ctx: &mut Ctx, name: u32, value: u32, _overwrite: u32) -> c_int { } /// emscripten: _putenv // (name: *const char); -pub fn _putenv(ctx: &mut Ctx, name: c_int) -> c_int { +pub fn _putenv(ctx: &mut EmEnv, name: c_int) -> c_int { debug!("emscripten::_putenv"); let name_addr = emscripten_memory_pointer!(ctx.memory(0), name) as *const c_char; debug!("=> name({:?})", unsafe { @@ -53,7 +53,7 @@ pub fn _putenv(ctx: &mut Ctx, name: c_int) -> c_int { } /// emscripten: _unsetenv // (name: *const char); -pub fn _unsetenv(ctx: &mut Ctx, name: u32) -> c_int { +pub fn _unsetenv(ctx: &mut EmEnv, name: u32) -> c_int { debug!("emscripten::_unsetenv"); let name = read_string_from_wasm(ctx.memory(0), name); // no unsetenv on windows, so use putenv with an empty value @@ -65,7 +65,7 @@ pub fn _unsetenv(ctx: &mut Ctx, name: u32) -> c_int { } #[allow(clippy::cast_ptr_alignment)] -pub fn _getpwnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int { +pub fn _getpwnam(ctx: &mut EmEnv, name_ptr: c_int) -> c_int { debug!("emscripten::_getpwnam {}", name_ptr); #[cfg(not(feature = "debug"))] let _ = name_ptr; @@ -99,7 +99,7 @@ pub fn _getpwnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int { } #[allow(clippy::cast_ptr_alignment)] -pub fn _getgrnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int { +pub fn _getgrnam(ctx: &mut EmEnv, name_ptr: c_int) -> c_int { debug!("emscripten::_getgrnam {}", name_ptr); #[cfg(not(feature = "debug"))] let _ = name_ptr; @@ -125,7 +125,7 @@ pub fn _getgrnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int { } } -pub fn _sysconf(_ctx: &mut Ctx, name: c_int) -> c_long { +pub fn _sysconf(_ctx: &mut EmEnv, name: c_int) -> c_long { debug!("emscripten::_sysconf {}", name); #[cfg(not(feature = "debug"))] let _ = name; @@ -133,13 +133,13 @@ pub fn _sysconf(_ctx: &mut Ctx, name: c_int) -> c_long { 0 } -pub fn _gai_strerror(_ctx: &mut Ctx, _ecode: i32) -> i32 { +pub fn _gai_strerror(_ctx: &mut EmEnv, _ecode: i32) -> i32 { debug!("emscripten::_gai_strerror({}) - stub", _ecode); -1 } pub fn _getaddrinfo( - _ctx: &mut Ctx, + _ctx: &mut EmEnv, _node_ptr: WasmPtr, _service_str_ptr: WasmPtr, _hints_ptr: WasmPtr, diff --git a/lib/emscripten/src/errno.rs b/lib/emscripten/src/errno.rs index ff1d09b7f..c1e54170b 100644 --- a/lib/emscripten/src/errno.rs +++ b/lib/emscripten/src/errno.rs @@ -1,7 +1,7 @@ // use std::collections::HashMap; -use wasmer_runtime_core::vm::Ctx; +use crate::EmEnv; -pub fn ___seterrno(_ctx: &mut Ctx, _value: i32) { +pub fn ___seterrno(_ctx: &mut EmEnv, _value: i32) { debug!("emscripten::___seterrno {}", _value); // TODO: Incomplete impl eprintln!("failed to set errno!"); diff --git a/lib/emscripten/src/exception.rs b/lib/emscripten/src/exception.rs index 74c834378..f968addc4 100644 --- a/lib/emscripten/src/exception.rs +++ b/lib/emscripten/src/exception.rs @@ -1,56 +1,56 @@ use super::env; use super::process::_abort; -use wasmer_runtime_core::vm::Ctx; +use crate::EmEnv; /// emscripten: ___cxa_allocate_exception -pub fn ___cxa_allocate_exception(ctx: &mut Ctx, size: u32) -> u32 { +pub fn ___cxa_allocate_exception(ctx: &mut EmEnv, size: u32) -> u32 { debug!("emscripten::___cxa_allocate_exception"); env::call_malloc(ctx, size as _) } -pub fn ___cxa_current_primary_exception(_ctx: &mut Ctx) -> u32 { +pub fn ___cxa_current_primary_exception(_ctx: &mut EmEnv) -> u32 { debug!("emscripten::___cxa_current_primary_exception"); unimplemented!("emscripten::___cxa_current_primary_exception") } -pub fn ___cxa_decrement_exception_refcount(_ctx: &mut Ctx, _a: u32) { +pub fn ___cxa_decrement_exception_refcount(_ctx: &mut EmEnv, _a: u32) { debug!("emscripten::___cxa_decrement_exception_refcount({})", _a); unimplemented!("emscripten::___cxa_decrement_exception_refcount({})", _a) } -pub fn ___cxa_increment_exception_refcount(_ctx: &mut Ctx, _a: u32) { +pub fn ___cxa_increment_exception_refcount(_ctx: &mut EmEnv, _a: u32) { debug!("emscripten::___cxa_increment_exception_refcount({})", _a); unimplemented!("emscripten::___cxa_increment_exception_refcount({})", _a) } -pub fn ___cxa_rethrow_primary_exception(_ctx: &mut Ctx, _a: u32) { +pub fn ___cxa_rethrow_primary_exception(_ctx: &mut EmEnv, _a: u32) { debug!("emscripten::___cxa_rethrow_primary_exception({})", _a); unimplemented!("emscripten::___cxa_rethrow_primary_exception({})", _a) } /// emscripten: ___cxa_throw /// TODO: We don't have support for exceptions yet -pub fn ___cxa_throw(ctx: &mut Ctx, _ptr: u32, _ty: u32, _destructor: u32) { +pub fn ___cxa_throw(ctx: &mut EmEnv, _ptr: u32, _ty: u32, _destructor: u32) { debug!("emscripten::___cxa_throw"); eprintln!("Throwing exceptions not yet implemented: aborting!"); _abort(ctx); } -pub fn ___cxa_begin_catch(_ctx: &mut Ctx, _exception_object_ptr: u32) -> i32 { +pub fn ___cxa_begin_catch(_ctx: &mut EmEnv, _exception_object_ptr: u32) -> i32 { debug!("emscripten::___cxa_begin_catch"); -1 } -pub fn ___cxa_end_catch(_ctx: &mut Ctx) { +pub fn ___cxa_end_catch(_ctx: &mut EmEnv) { debug!("emscripten::___cxa_end_catch"); } -pub fn ___cxa_uncaught_exception(_ctx: &mut Ctx) -> i32 { +pub fn ___cxa_uncaught_exception(_ctx: &mut EmEnv) -> i32 { debug!("emscripten::___cxa_uncaught_exception"); -1 } -pub fn ___cxa_pure_virtual(_ctx: &mut Ctx) { +pub fn ___cxa_pure_virtual(_ctx: &mut EmEnv) { debug!("emscripten::___cxa_pure_virtual"); // ABORT = true panic!("Pure virtual function called!"); diff --git a/lib/emscripten/src/exec.rs b/lib/emscripten/src/exec.rs index 87971c69b..46a3331f2 100644 --- a/lib/emscripten/src/exec.rs +++ b/lib/emscripten/src/exec.rs @@ -1,10 +1,10 @@ use crate::varargs::VarArgs; +use crate::EmEnv; use libc::execvp as libc_execvp; use std::cell::Cell; use std::ffi::CString; -use wasmer_runtime_core::vm::Ctx; -pub fn execvp(ctx: &mut Ctx, command_name_offset: u32, argv_offset: u32) -> i32 { +pub fn execvp(ctx: &mut EmEnv, command_name_offset: u32, argv_offset: u32) -> i32 { // a single reference to re-use let emscripten_memory = ctx.memory(0); @@ -41,13 +41,13 @@ pub fn execvp(ctx: &mut Ctx, command_name_offset: u32, argv_offset: u32) -> i32 } /// execl -pub fn execl(_ctx: &mut Ctx, _path_ptr: i32, _arg0_ptr: i32, _varargs: VarArgs) -> i32 { +pub fn execl(_ctx: &mut EmEnv, _path_ptr: i32, _arg0_ptr: i32, _varargs: VarArgs) -> i32 { debug!("emscripten::execl"); -1 } /// execle -pub fn execle(_ctx: &mut Ctx, _path_ptr: i32, _arg0_ptr: i32, _varargs: VarArgs) -> i32 { +pub fn execle(_ctx: &mut EmEnv, _path_ptr: i32, _arg0_ptr: i32, _varargs: VarArgs) -> i32 { debug!("emscripten::execle"); -1 } diff --git a/lib/emscripten/src/exit.rs b/lib/emscripten/src/exit.rs index d3f57a7a2..b9b69a9dc 100644 --- a/lib/emscripten/src/exit.rs +++ b/lib/emscripten/src/exit.rs @@ -1,7 +1,7 @@ -use wasmer_runtime_core::vm::Ctx; +use crate::EmEnv; // __exit -pub fn exit(_ctx: &mut Ctx, value: i32) { +pub fn exit(_ctx: &mut EmEnv, value: i32) { debug!("emscripten::exit {}", value); ::std::process::exit(value); } diff --git a/lib/emscripten/src/inet.rs b/lib/emscripten/src/inet.rs index 097dffa39..79d2e946e 100644 --- a/lib/emscripten/src/inet.rs +++ b/lib/emscripten/src/inet.rs @@ -1,6 +1,6 @@ -use wasmer_runtime_core::vm::Ctx; +use crate::EmEnv; -pub fn addr(_ctx: &mut Ctx, _cp: i32) -> i32 { +pub fn addr(_ctx: &mut EmEnv, _cp: i32) -> i32 { debug!("inet::addr({})", _cp); 0 } diff --git a/lib/emscripten/src/io/mod.rs b/lib/emscripten/src/io/mod.rs index bad5935fe..37d7c5bd7 100644 --- a/lib/emscripten/src/io/mod.rs +++ b/lib/emscripten/src/io/mod.rs @@ -10,22 +10,22 @@ pub use self::unix::*; #[cfg(windows)] pub use self::windows::*; -use wasmer_runtime_core::vm::Ctx; +use crate::EmEnv; /// getprotobyname -pub fn getprotobyname(_ctx: &mut Ctx, _name_ptr: i32) -> i32 { +pub fn getprotobyname(_ctx: &mut EmEnv, _name_ptr: i32) -> i32 { debug!("emscripten::getprotobyname"); unimplemented!("emscripten::getprotobyname") } /// getprotobynumber -pub fn getprotobynumber(_ctx: &mut Ctx, _one: i32) -> i32 { +pub fn getprotobynumber(_ctx: &mut EmEnv, _one: i32) -> i32 { debug!("emscripten::getprotobynumber"); unimplemented!("emscripten::getprotobynumber") } /// sigdelset -pub fn sigdelset(ctx: &mut Ctx, set: i32, signum: i32) -> i32 { +pub fn sigdelset(ctx: &mut EmEnv, set: i32, signum: i32) -> i32 { debug!("emscripten::sigdelset"); let memory = ctx.memory(0); #[allow(clippy::cast_ptr_alignment)] @@ -37,7 +37,7 @@ pub fn sigdelset(ctx: &mut Ctx, set: i32, signum: i32) -> i32 { } /// sigfillset -pub fn sigfillset(ctx: &mut Ctx, set: i32) -> i32 { +pub fn sigfillset(ctx: &mut EmEnv, set: i32) -> i32 { debug!("emscripten::sigfillset"); let memory = ctx.memory(0); #[allow(clippy::cast_ptr_alignment)] @@ -51,13 +51,13 @@ pub fn sigfillset(ctx: &mut Ctx, set: i32) -> i32 { } /// tzset -pub fn tzset(_ctx: &mut Ctx) { +pub fn tzset(_ctx: &mut EmEnv) { debug!("emscripten::tzset - stub"); //unimplemented!("emscripten::tzset - stub") } /// strptime -pub fn strptime(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 { +pub fn strptime(_ctx: &mut EmEnv, _one: i32, _two: i32, _three: i32) -> i32 { debug!("emscripten::strptime"); unimplemented!("emscripten::strptime") } diff --git a/lib/emscripten/src/io/unix.rs b/lib/emscripten/src/io/unix.rs index 740210d46..4591accd8 100644 --- a/lib/emscripten/src/io/unix.rs +++ b/lib/emscripten/src/io/unix.rs @@ -3,15 +3,15 @@ use super::super::utils::copy_cstr_into_wasm; use libc::{chroot as _chroot, getpwuid as _getpwuid, printf as _printf}; use std::mem; -use wasmer_runtime_core::vm::Ctx; +use crate::EmEnv; /// putchar -pub fn putchar(_ctx: &mut Ctx, chr: i32) { +pub fn putchar(_ctx: &mut EmEnv, chr: i32) { unsafe { libc::putchar(chr) }; } /// printf -pub fn printf(ctx: &mut Ctx, memory_offset: i32, extra: i32) -> i32 { +pub fn printf(ctx: &mut EmEnv, memory_offset: i32, extra: i32) -> i32 { debug!("emscripten::printf {}, {}", memory_offset, extra); unsafe { let addr = emscripten_memory_pointer!(ctx.memory(0), memory_offset) as _; @@ -20,7 +20,7 @@ pub fn printf(ctx: &mut Ctx, memory_offset: i32, extra: i32) -> i32 { } /// chroot -pub fn chroot(ctx: &mut Ctx, name_ptr: i32) -> i32 { +pub fn chroot(ctx: &mut EmEnv, name_ptr: i32) -> i32 { debug!("emscripten::chroot"); let name = emscripten_memory_pointer!(ctx.memory(0), name_ptr) as *const i8; unsafe { _chroot(name as *const _) } @@ -28,7 +28,7 @@ pub fn chroot(ctx: &mut Ctx, name_ptr: i32) -> i32 { /// getpwuid #[allow(clippy::cast_ptr_alignment)] -pub fn getpwuid(ctx: &mut Ctx, uid: i32) -> i32 { +pub fn getpwuid(ctx: &mut EmEnv, uid: i32) -> i32 { debug!("emscripten::getpwuid {}", uid); #[repr(C)] diff --git a/lib/emscripten/src/io/windows.rs b/lib/emscripten/src/io/windows.rs index a7d6dc60b..a29677b90 100644 --- a/lib/emscripten/src/io/windows.rs +++ b/lib/emscripten/src/io/windows.rs @@ -1,4 +1,4 @@ -use wasmer_runtime_core::vm::Ctx; +use crate::EmEnv; // This may be problematic for msvc which uses inline functions for the printf family // this cfg_attr will try to link with the legacy lib that does not inline printf @@ -14,12 +14,12 @@ use wasmer_runtime_core::vm::Ctx; //} /// putchar -pub fn putchar(_ctx: &mut Ctx, chr: i32) { +pub fn putchar(_ctx: &mut EmEnv, chr: i32) { unsafe { libc::putchar(chr) }; } /// printf -pub fn printf(_ctx: &mut Ctx, memory_offset: i32, extra: i32) -> i32 { +pub fn printf(_ctx: &mut EmEnv, memory_offset: i32, extra: i32) -> i32 { debug!("emscripten::printf {}, {}", memory_offset, extra); #[cfg(not(feature = "debug"))] { @@ -34,13 +34,13 @@ pub fn printf(_ctx: &mut Ctx, memory_offset: i32, extra: i32) -> i32 { } /// chroot -pub fn chroot(_ctx: &mut Ctx, _name_ptr: i32) -> i32 { +pub fn chroot(_ctx: &mut EmEnv, _name_ptr: i32) -> i32 { debug!("emscripten::chroot"); unimplemented!("emscripten::chroot") } /// getpwuid -pub fn getpwuid(_ctx: &mut Ctx, _uid: i32) -> i32 { +pub fn getpwuid(_ctx: &mut EmEnv, _uid: i32) -> i32 { debug!("emscripten::getpwuid"); unimplemented!("emscripten::getpwuid") } diff --git a/lib/emscripten/src/jmp.rs b/lib/emscripten/src/jmp.rs index 1d9691bc1..ed3b7d057 100644 --- a/lib/emscripten/src/jmp.rs +++ b/lib/emscripten/src/jmp.rs @@ -2,10 +2,10 @@ use super::env::get_emscripten_data; use super::process::abort_with_message; use libc::c_int; // use std::cell::UnsafeCell; -use wasmer_runtime_core::vm::Ctx; +use crate::EmEnv; /// setjmp -pub fn __setjmp(ctx: &mut Ctx, _env_addr: u32) -> c_int { +pub fn __setjmp(ctx: &mut EmEnv, _env_addr: u32) -> c_int { debug!("emscripten::__setjmp (setjmp)"); abort_with_message(ctx, "missing function: _setjmp"); unreachable!() @@ -28,7 +28,7 @@ pub fn __setjmp(ctx: &mut Ctx, _env_addr: u32) -> c_int { /// longjmp #[allow(unreachable_code)] -pub fn __longjmp(ctx: &mut Ctx, _env_addr: u32, _val: c_int) { +pub fn __longjmp(ctx: &mut EmEnv, _env_addr: u32, _val: c_int) { debug!("emscripten::__longjmp (longmp)"); abort_with_message(ctx, "missing function: _longjmp"); // unsafe { @@ -43,7 +43,7 @@ pub fn __longjmp(ctx: &mut Ctx, _env_addr: u32, _val: c_int) { /// _longjmp // This function differs from the js implementation, it should return Result<(), &'static str> -pub fn _longjmp(ctx: &mut Ctx, env_addr: i32, val: c_int) -> Result<(), ()> { +pub fn _longjmp(ctx: &mut EmEnv, env_addr: i32, val: c_int) -> Result<(), ()> { let val = if val == 0 { 1 } else { val }; get_emscripten_data(ctx) .set_threw diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index abd5e5557..52622d854 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -1,4 +1,4 @@ -#![deny( +/*#![deny( dead_code, nonstandard_style, unused_imports, @@ -7,6 +7,7 @@ unused_unsafe, unreachable_patterns )] +*/ #![doc(html_favicon_url = "https://wasmer.io/static/icons/favicon.ico")] #![doc(html_logo_url = "https://avatars3.githubusercontent.com/u/44205449?s=200&v=4")] @@ -19,8 +20,8 @@ use std::collections::HashMap; use std::path::PathBuf; use std::{f64, ffi::c_void}; use wasmer::{ - imports, Function, FunctionType, Global, ImportObject, Instance, Memory, MemoryType, Module, - Pages, Table, TableType, Val, ValType, + imports, Exportable, Function, FunctionType, Global, ImportObject, Instance, Memory, + MemoryType, Module, NativeFunc, Pages, RuntimeError, Store, Table, TableType, Val, ValType, }; /*use wasmer_runtime_core::{ error::{CallError, CallResult, ResolveError}, @@ -76,6 +77,23 @@ pub use self::utils::{ get_emscripten_table_size, is_emscripten_module, }; +/// The environment provided to the Emscripten imports. +pub struct EmEnv<'a> { + memory: Memory, + data: &'a mut EmscriptenData<'a>, +} + +impl<'a> EmEnv<'a> { + pub fn new(memory: Memory, data: &'a mut EmscriptenData) -> Self { + Self { memory, data } + } + + /// Get a reference to the memory + pub fn memory(&self, _mem_idx: u32) -> &Memory { + &self.memory + } +} + // TODO: Magic number - how is this calculated? const TOTAL_STACK: u32 = 5_242_880; // TODO: make this variable @@ -83,7 +101,7 @@ const STATIC_BUMP: u32 = 215_536; lazy_static! { static ref OLD_ABORT_ON_CANNOT_GROW_MEMORY_SIG: FunctionType = - { FunctionType::new(vec![], vec![Type::I32]) }; + { FunctionType::new(vec![], vec![ValType::I32]) }; } // The address globals begin at. Very low in memory, for code size and optimization opportunities. @@ -96,78 +114,81 @@ const STATIC_BASE: u32 = GLOBAL_BASE; pub struct EmscriptenData<'a> { pub globals: &'a EmscriptenGlobalsData, - pub malloc: Option>, - pub free: Option>, - pub memalign: Option>, - pub memset: Option>, - pub stack_alloc: Option>, + pub malloc: Option>, + pub free: Option>, + pub memalign: Option>, + pub memset: Option>, + pub stack_alloc: Option>, pub jumps: Vec>, pub opened_dirs: HashMap>, - pub dyn_call_i: Option>, - pub dyn_call_ii: Option>, - pub dyn_call_iii: Option>, - pub dyn_call_iiii: Option>, - pub dyn_call_iifi: Option>, - pub dyn_call_v: Option>, - pub dyn_call_vi: Option>, - pub dyn_call_vii: Option>, - pub dyn_call_viii: Option>, - pub dyn_call_viiii: Option>, + pub dyn_call_i: Option>, + pub dyn_call_ii: Option>, + pub dyn_call_iii: Option>, + pub dyn_call_iiii: Option>, + pub dyn_call_iifi: Option>, + pub dyn_call_v: Option>, + pub dyn_call_vi: Option>, + pub dyn_call_vii: Option>, + pub dyn_call_viii: Option>, + pub dyn_call_viiii: Option>, // round 2 - pub dyn_call_dii: Option>, - pub dyn_call_diiii: Option>, - pub dyn_call_iiiii: Option>, - pub dyn_call_iiiiii: Option>, - pub dyn_call_iiiiiii: Option>, - pub dyn_call_iiiiiiii: Option>, - pub dyn_call_iiiiiiiii: Option>, + pub dyn_call_dii: Option>, + pub dyn_call_diiii: Option>, + pub dyn_call_iiiii: Option>, + pub dyn_call_iiiiii: Option>, + pub dyn_call_iiiiiii: Option>, + pub dyn_call_iiiiiiii: Option>, + pub dyn_call_iiiiiiiii: + Option>, pub dyn_call_iiiiiiiiii: - Option>, + Option>, pub dyn_call_iiiiiiiiiii: - Option>, - pub dyn_call_vd: Option>, - pub dyn_call_viiiii: Option>, - pub dyn_call_viiiiii: Option>, - pub dyn_call_viiiiiii: Option>, - pub dyn_call_viiiiiiii: Option>, - pub dyn_call_viiiiiiiii: Option>, + Option>, + pub dyn_call_vd: Option>, + pub dyn_call_viiiii: Option>, + pub dyn_call_viiiiii: Option>, + pub dyn_call_viiiiiii: Option>, + pub dyn_call_viiiiiiii: Option>, + pub dyn_call_viiiiiiiii: + Option>, pub dyn_call_viiiiiiiiii: - Option>, - pub dyn_call_iij: Option>, - pub dyn_call_iji: Option>, - pub dyn_call_iiji: Option>, - pub dyn_call_iiijj: Option>, - pub dyn_call_j: Option>, - pub dyn_call_ji: Option>, - pub dyn_call_jii: Option>, - pub dyn_call_jij: Option>, - pub dyn_call_jjj: Option>, - pub dyn_call_viiij: Option>, - pub dyn_call_viiijiiii: Option>, + Option>, + pub dyn_call_iij: Option>, + pub dyn_call_iji: Option>, + pub dyn_call_iiji: Option>, + pub dyn_call_iiijj: Option>, + pub dyn_call_j: Option>, + pub dyn_call_ji: Option>, + pub dyn_call_jii: Option>, + pub dyn_call_jij: Option>, + pub dyn_call_jjj: Option>, + pub dyn_call_viiij: Option>, + pub dyn_call_viiijiiii: + Option>, pub dyn_call_viiijiiiiii: - Option>, - pub dyn_call_viij: Option>, - pub dyn_call_viiji: Option>, - pub dyn_call_viijiii: Option>, - pub dyn_call_viijj: Option>, - pub dyn_call_vj: Option>, - pub dyn_call_vjji: Option>, - pub dyn_call_vij: Option>, - pub dyn_call_viji: Option>, - pub dyn_call_vijiii: Option>, - pub dyn_call_vijj: Option>, - pub dyn_call_viid: Option>, - pub dyn_call_vidd: Option>, - pub dyn_call_viidii: Option>, + Option>, + pub dyn_call_viij: Option>, + pub dyn_call_viiji: Option>, + pub dyn_call_viijiii: Option>, + pub dyn_call_viijj: Option>, + pub dyn_call_vj: Option>, + pub dyn_call_vjji: Option>, + pub dyn_call_vij: Option>, + pub dyn_call_viji: Option>, + pub dyn_call_vijiii: Option>, + pub dyn_call_vijj: Option>, + pub dyn_call_viid: Option>, + pub dyn_call_vidd: Option>, + pub dyn_call_viidii: Option>, pub dyn_call_viidddddddd: - Option>, + Option>, pub temp_ret_0: i32, - pub stack_save: Option>, - pub stack_restore: Option>, - pub set_threw: Option>, + pub stack_save: Option>, + pub stack_restore: Option>, + pub set_threw: Option>, pub mapped_dirs: HashMap, } @@ -342,16 +363,16 @@ impl<'a> EmscriptenData<'a> { /// Note that this function does not completely set up Emscripten to be called. /// before calling this function, please initialize `Ctx::data` with a pointer /// to [`EmscriptenData`]. -pub fn set_up_emscripten(instance: &mut Instance) -> CallResult<()> { +pub fn set_up_emscripten(instance: &mut Instance) -> Result<(), RuntimeError> { // ATINIT // (used by C++) - if let Ok(func) = instance.exports.get::("globalCtors") { + if let Ok(func) = instance.exports.get::("globalCtors") { func.call(&[])?; } if let Ok(func) = instance .exports - .get::("___emscripten_environ_constructor") + .get::("___emscripten_environ_constructor") { func.call(&[])?; } @@ -362,10 +383,14 @@ pub fn set_up_emscripten(instance: &mut Instance) -> CallResult<()> { /// set up. /// /// If you don't want to set it up yourself, consider using [`run_emscripten_instance`]. -pub fn emscripten_call_main(instance: &mut Instance, path: &str, args: &[&str]) -> CallResult<()> { - let (func_name, main_func) = match instance.exports.get::("_main") { +pub fn emscripten_call_main( + instance: &mut Instance, + path: &str, + args: &[&str], +) -> Result<(), RuntimeError> { + let (func_name, main_func) = match instance.exports.get::("_main") { Ok(func) => Ok(("_main", func)), - Err(_e) => match instance.exports.get::("main") { + Err(_e) => match instance.exports.get::("main") { Ok(func) => Ok(("main", func)), Err(e) => Err(e), }, @@ -376,17 +401,18 @@ pub fn emscripten_call_main(instance: &mut Instance, path: &str, args: &[&str]) let mut new_args = vec![path]; new_args.extend(args); let (argc, argv) = store_module_arguments(instance.context_mut(), new_args); - let func: DynFunc = instance.exports.get(func_name)?; - func.call(&[Value::I32(argc as i32), Value::I32(argv as i32)])?; + let func: Function = instance.exports.get(func_name)?; + func.call(&[Val::I32(argc as i32), Val::I32(argv as i32)])?; } 0 => { - let func: DynFunc = instance.exports.get(func_name)?; + let func: Function = instance.exports.get(func_name)?; func.call(&[])?; } _ => { - return Err(CallError::Resolve(ResolveError::ExportWrongType { + todo!("Update error type to be able to express this"); + /*return Err(RuntimeError:: CallError::Resolve(ResolveError::ExportWrongType { name: "main".to_string(), - })) + }))*/ } }; @@ -402,10 +428,9 @@ pub fn run_emscripten_instance( args: Vec<&str>, entrypoint: Option, mapped_dirs: Vec<(String, PathBuf)>, -) -> CallResult<()> { +) -> Result<(), RuntimeError> { let mut data = EmscriptenData::new(instance, &globals.data, mapped_dirs.into_iter().collect()); - let data_ptr = &mut data as *mut _ as *mut c_void; - instance.context_mut().data = data_ptr; + let env = EmEnv::new(globals.memory, &mut data); set_up_emscripten(instance)?; @@ -415,8 +440,8 @@ pub fn run_emscripten_instance( debug!("Running entry point: {}", &ep); let arg = unsafe { allocate_cstr_on_stack(instance.context_mut(), args[0]).0 }; //let (argc, argv) = store_module_arguments(instance.context_mut(), args); - let func: DynFunc = instance.exports.get(&ep)?; - func.call(&[Value::I32(arg as i32)])?; + let func: Function = instance.exports.get(&ep)?; + func.call(&[Val::I32(arg as i32)])?; } else { emscripten_call_main(instance, path, &args)?; } @@ -426,7 +451,7 @@ pub fn run_emscripten_instance( Ok(()) } -fn store_module_arguments(ctx: &mut Ctx, args: Vec<&str>) -> (u32, u32) { +fn store_module_arguments(ctx: &mut EmEnv, args: Vec<&str>) -> (u32, u32) { let argc = args.len() + 1; let mut args_slice = vec![0; argc]; @@ -484,7 +509,10 @@ pub struct EmscriptenGlobals { } impl EmscriptenGlobals { - pub fn new(module: &Module /*, static_bump: u32 */) -> Result { + pub fn new( + store: &Store, + module: &Module, /*, static_bump: u32 */ + ) -> Result { let mut use_old_abort_on_cannot_grow_memory = false; for ( index, @@ -510,10 +538,10 @@ impl EmscriptenGlobals { let (memory_min, memory_max, shared) = get_emscripten_memory_size(&module)?; // Memory initialization - let memory_type = MemoryType::new(memory_min, memory_max, shared)?; - let memory = Memory::new(memory_type).unwrap(); + let memory_type = MemoryType::new(memory_min, memory_max, shared); + let memory = Memory::new(store, memory_type).unwrap(); - let table_type = TableTable { + let table_type = TableType { element: ElementType::Anyfunc, minimum: table_min, maximum: table_max, @@ -569,7 +597,7 @@ impl EmscriptenGlobals { { let namespace = module.info().namespace_table.get(*namespace_index); let name = module.info().name_table.get(*name_index); - if namespace == "env" && name.starts_with("nullFunc_") { + if namespace == "env" && name.starts_with("nullFunction_") { null_func_names.push(name.to_string()) } } @@ -585,11 +613,15 @@ impl EmscriptenGlobals { } } -pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject { +pub fn generate_emscripten_env( + globals: &mut EmscriptenGlobals, + store: &Store, + env: &mut EmEnv, +) -> ImportObject { let abort_on_cannot_grow_memory_export = if globals.data.use_old_abort_on_cannot_grow_memory { - func!(crate::memory::abort_on_cannot_grow_memory_old).to_export() + Function::new_env(store, env, crate::memory::abort_on_cannot_grow_memory_old).to_export() } else { - func!(crate::memory::abort_on_cannot_grow_memory).to_export() + Function::new_env(store, env, crate::memory::abort_on_cannot_grow_memory).to_export() }; let mut env_ns = namespace! { @@ -610,427 +642,427 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "tempDoublePtr" => Global::new(Value::I32(globals.data.temp_double_ptr as i32)), // inet - "_inet_addr" => func!(crate::inet::addr), + "_inet_addr" => Function::new_env(store, env, crate::inet::addr), // IO - "printf" => func!(crate::io::printf), - "putchar" => func!(crate::io::putchar), - "___lock" => func!(crate::lock::___lock), - "___unlock" => func!(crate::lock::___unlock), - "___wait" => func!(crate::lock::___wait), - "_flock" => func!(crate::lock::_flock), - "_chroot" => func!(crate::io::chroot), - "_getprotobyname" => func!(crate::io::getprotobyname), - "_getprotobynumber" => func!(crate::io::getprotobynumber), - "_getpwuid" => func!(crate::io::getpwuid), - "_sigdelset" => func!(crate::io::sigdelset), - "_sigfillset" => func!(crate::io::sigfillset), - "_tzset" => func!(crate::io::tzset), - "_strptime" => func!(crate::io::strptime), + "printf" => Function::new_env(store, env, crate::io::printf), + "putchar" => Function::new_env(store, env, crate::io::putchar), + "___lock" => Function::new_env(store, env, crate::lock::___lock), + "___unlock" => Function::new_env(store, env, crate::lock::___unlock), + "___wait" => Function::new_env(store, env, crate::lock::___wait), + "_flock" => Function::new_env(store, env, crate::lock::_flock), + "_chroot" => Function::new_env(store, env, crate::io::chroot), + "_getprotobyname" => Function::new_env(store, env, crate::io::getprotobyname), + "_getprotobynumber" => Function::new_env(store, env, crate::io::getprotobynumber), + "_getpwuid" => Function::new_env(store, env, crate::io::getpwuid), + "_sigdelset" => Function::new_env(store, env, crate::io::sigdelset), + "_sigfillset" => Function::new_env(store, env, crate::io::sigfillset), + "_tzset" => Function::new_env(store, env, crate::io::tzset), + "_strptime" => Function::new_env(store, env, crate::io::strptime), // exec - "_execvp" => func!(crate::exec::execvp), - "_execl" => func!(crate::exec::execl), - "_execle" => func!(crate::exec::execle), + "_execvp" => Function::new_env(store, env, crate::exec::execvp), + "_execl" => Function::new_env(store, env, crate::exec::execl), + "_execle" => Function::new_env(store, env, crate::exec::execle), // exit - "__exit" => func!(crate::exit::exit), + "__exit" => Function::new_env(store, env, crate::exit::exit), // Env - "___assert_fail" => func!(crate::env::___assert_fail), - "_getenv" => func!(crate::env::_getenv), - "_setenv" => func!(crate::env::_setenv), - "_putenv" => func!(crate::env::_putenv), - "_unsetenv" => func!(crate::env::_unsetenv), - "_getpwnam" => func!(crate::env::_getpwnam), - "_getgrnam" => func!(crate::env::_getgrnam), - "___buildEnvironment" => func!(crate::env::___build_environment), - "___setErrNo" => func!(crate::errno::___seterrno), - "_getpagesize" => func!(crate::env::_getpagesize), - "_sysconf" => func!(crate::env::_sysconf), - "_getaddrinfo" => func!(crate::env::_getaddrinfo), - "_times" => func!(crate::env::_times), - "_pathconf" => func!(crate::env::_pathconf), - "_fpathconf" => func!(crate::env::_fpathconf), + "___assert_fail" => Function::new_env(store, env, crate::env::___assert_fail), + "_getenv" => Function::new_env(store, env, crate::env::_getenv), + "_setenv" => Function::new_env(store, env, crate::env::_setenv), + "_putenv" => Function::new_env(store, env, crate::env::_putenv), + "_unsetenv" => Function::new_env(store, env, crate::env::_unsetenv), + "_getpwnam" => Function::new_env(store, env, crate::env::_getpwnam), + "_getgrnam" => Function::new_env(store, env, crate::env::_getgrnam), + "___buildEnvironment" => Function::new_env(store, env, crate::env::___build_environment), + "___setErrNo" => Function::new_env(store, env, crate::errno::___seterrno), + "_getpagesize" => Function::new_env(store, env, crate::env::_getpagesize), + "_sysconf" => Function::new_env(store, env, crate::env::_sysconf), + "_getaddrinfo" => Function::new_env(store, env, crate::env::_getaddrinfo), + "_times" => Function::new_env(store, env, crate::env::_times), + "_pathconf" => Function::new_env(store, env, crate::env::_pathconf), + "_fpathconf" => Function::new_env(store, env, crate::env::_fpathconf), // Syscalls - "___syscall1" => func!(crate::syscalls::___syscall1), - "___syscall3" => func!(crate::syscalls::___syscall3), - "___syscall4" => func!(crate::syscalls::___syscall4), - "___syscall5" => func!(crate::syscalls::___syscall5), - "___syscall6" => func!(crate::syscalls::___syscall6), - "___syscall9" => func!(crate::syscalls::___syscall9), - "___syscall10" => func!(crate::syscalls::___syscall10), - "___syscall12" => func!(crate::syscalls::___syscall12), - "___syscall14" => func!(crate::syscalls::___syscall14), - "___syscall15" => func!(crate::syscalls::___syscall15), - "___syscall20" => func!(crate::syscalls::___syscall20), - "___syscall21" => func!(crate::syscalls::___syscall21), - "___syscall25" => func!(crate::syscalls::___syscall25), - "___syscall29" => func!(crate::syscalls::___syscall29), - "___syscall32" => func!(crate::syscalls::___syscall32), - "___syscall33" => func!(crate::syscalls::___syscall33), - "___syscall34" => func!(crate::syscalls::___syscall34), - "___syscall36" => func!(crate::syscalls::___syscall36), - "___syscall39" => func!(crate::syscalls::___syscall39), - "___syscall38" => func!(crate::syscalls::___syscall38), - "___syscall40" => func!(crate::syscalls::___syscall40), - "___syscall41" => func!(crate::syscalls::___syscall41), - "___syscall42" => func!(crate::syscalls::___syscall42), - "___syscall51" => func!(crate::syscalls::___syscall51), - "___syscall52" => func!(crate::syscalls::___syscall52), - "___syscall53" => func!(crate::syscalls::___syscall53), - "___syscall54" => func!(crate::syscalls::___syscall54), - "___syscall57" => func!(crate::syscalls::___syscall57), - "___syscall60" => func!(crate::syscalls::___syscall60), - "___syscall63" => func!(crate::syscalls::___syscall63), - "___syscall64" => func!(crate::syscalls::___syscall64), - "___syscall66" => func!(crate::syscalls::___syscall66), - "___syscall75" => func!(crate::syscalls::___syscall75), - "___syscall77" => func!(crate::syscalls::___syscall77), - "___syscall83" => func!(crate::syscalls::___syscall83), - "___syscall85" => func!(crate::syscalls::___syscall85), - "___syscall91" => func!(crate::syscalls::___syscall91), - "___syscall94" => func!(crate::syscalls::___syscall94), - "___syscall96" => func!(crate::syscalls::___syscall96), - "___syscall97" => func!(crate::syscalls::___syscall97), - "___syscall102" => func!(crate::syscalls::___syscall102), - "___syscall110" => func!(crate::syscalls::___syscall110), - "___syscall114" => func!(crate::syscalls::___syscall114), - "___syscall118" => func!(crate::syscalls::___syscall118), - "___syscall121" => func!(crate::syscalls::___syscall121), - "___syscall122" => func!(crate::syscalls::___syscall122), - "___syscall125" => func!(crate::syscalls::___syscall125), - "___syscall132" => func!(crate::syscalls::___syscall132), - "___syscall133" => func!(crate::syscalls::___syscall133), - "___syscall140" => func!(crate::syscalls::___syscall140), - "___syscall142" => func!(crate::syscalls::___syscall142), - "___syscall144" => func!(crate::syscalls::___syscall144), - "___syscall145" => func!(crate::syscalls::___syscall145), - "___syscall146" => func!(crate::syscalls::___syscall146), - "___syscall147" => func!(crate::syscalls::___syscall147), - "___syscall148" => func!(crate::syscalls::___syscall148), - "___syscall150" => func!(crate::syscalls::___syscall150), - "___syscall151" => func!(crate::syscalls::___syscall151), - "___syscall152" => func!(crate::syscalls::___syscall152), - "___syscall153" => func!(crate::syscalls::___syscall153), - "___syscall163" => func!(crate::syscalls::___syscall163), - "___syscall168" => func!(crate::syscalls::___syscall168), - "___syscall180" => func!(crate::syscalls::___syscall180), - "___syscall181" => func!(crate::syscalls::___syscall181), - "___syscall183" => func!(crate::syscalls::___syscall183), - "___syscall191" => func!(crate::syscalls::___syscall191), - "___syscall192" => func!(crate::syscalls::___syscall192), - "___syscall193" => func!(crate::syscalls::___syscall193), - "___syscall194" => func!(crate::syscalls::___syscall194), - "___syscall195" => func!(crate::syscalls::___syscall195), - "___syscall196" => func!(crate::syscalls::___syscall196), - "___syscall197" => func!(crate::syscalls::___syscall197), - "___syscall198" => func!(crate::syscalls::___syscall198), - "___syscall199" => func!(crate::syscalls::___syscall199), - "___syscall200" => func!(crate::syscalls::___syscall200), - "___syscall201" => func!(crate::syscalls::___syscall201), - "___syscall202" => func!(crate::syscalls::___syscall202), - "___syscall205" => func!(crate::syscalls::___syscall205), - "___syscall207" => func!(crate::syscalls::___syscall207), - "___syscall209" => func!(crate::syscalls::___syscall209), - "___syscall211" => func!(crate::syscalls::___syscall211), - "___syscall212" => func!(crate::syscalls::___syscall212), - "___syscall218" => func!(crate::syscalls::___syscall218), - "___syscall219" => func!(crate::syscalls::___syscall219), - "___syscall220" => func!(crate::syscalls::___syscall220), - "___syscall221" => func!(crate::syscalls::___syscall221), - "___syscall268" => func!(crate::syscalls::___syscall268), - "___syscall269" => func!(crate::syscalls::___syscall269), - "___syscall272" => func!(crate::syscalls::___syscall272), - "___syscall295" => func!(crate::syscalls::___syscall295), - "___syscall296" => func!(crate::syscalls::___syscall296), - "___syscall297" => func!(crate::syscalls::___syscall297), - "___syscall298" => func!(crate::syscalls::___syscall298), - "___syscall300" => func!(crate::syscalls::___syscall300), - "___syscall301" => func!(crate::syscalls::___syscall301), - "___syscall302" => func!(crate::syscalls::___syscall302), - "___syscall303" => func!(crate::syscalls::___syscall303), - "___syscall304" => func!(crate::syscalls::___syscall304), - "___syscall305" => func!(crate::syscalls::___syscall305), - "___syscall306" => func!(crate::syscalls::___syscall306), - "___syscall307" => func!(crate::syscalls::___syscall307), - "___syscall308" => func!(crate::syscalls::___syscall308), - "___syscall320" => func!(crate::syscalls::___syscall320), - "___syscall324" => func!(crate::syscalls::___syscall324), - "___syscall330" => func!(crate::syscalls::___syscall330), - "___syscall331" => func!(crate::syscalls::___syscall331), - "___syscall333" => func!(crate::syscalls::___syscall333), - "___syscall334" => func!(crate::syscalls::___syscall334), - "___syscall337" => func!(crate::syscalls::___syscall337), - "___syscall340" => func!(crate::syscalls::___syscall340), - "___syscall345" => func!(crate::syscalls::___syscall345), + "___syscall1" => Function::new_env(store, env, crate::syscalls::___syscall1), + "___syscall3" => Function::new_env(store, env, crate::syscalls::___syscall3), + "___syscall4" => Function::new_env(store, env, crate::syscalls::___syscall4), + "___syscall5" => Function::new_env(store, env, crate::syscalls::___syscall5), + "___syscall6" => Function::new_env(store, env, crate::syscalls::___syscall6), + "___syscall9" => Function::new_env(store, env, crate::syscalls::___syscall9), + "___syscall10" => Function::new_env(store, env, crate::syscalls::___syscall10), + "___syscall12" => Function::new_env(store, env, crate::syscalls::___syscall12), + "___syscall14" => Function::new_env(store, env, crate::syscalls::___syscall14), + "___syscall15" => Function::new_env(store, env, crate::syscalls::___syscall15), + "___syscall20" => Function::new_env(store, env, crate::syscalls::___syscall20), + "___syscall21" => Function::new_env(store, env, crate::syscalls::___syscall21), + "___syscall25" => Function::new_env(store, env, crate::syscalls::___syscall25), + "___syscall29" => Function::new_env(store, env, crate::syscalls::___syscall29), + "___syscall32" => Function::new_env(store, env, crate::syscalls::___syscall32), + "___syscall33" => Function::new_env(store, env, crate::syscalls::___syscall33), + "___syscall34" => Function::new_env(store, env, crate::syscalls::___syscall34), + "___syscall36" => Function::new_env(store, env, crate::syscalls::___syscall36), + "___syscall39" => Function::new_env(store, env, crate::syscalls::___syscall39), + "___syscall38" => Function::new_env(store, env, crate::syscalls::___syscall38), + "___syscall40" => Function::new_env(store, env, crate::syscalls::___syscall40), + "___syscall41" => Function::new_env(store, env, crate::syscalls::___syscall41), + "___syscall42" => Function::new_env(store, env, crate::syscalls::___syscall42), + "___syscall51" => Function::new_env(store, env, crate::syscalls::___syscall51), + "___syscall52" => Function::new_env(store, env, crate::syscalls::___syscall52), + "___syscall53" => Function::new_env(store, env, crate::syscalls::___syscall53), + "___syscall54" => Function::new_env(store, env, crate::syscalls::___syscall54), + "___syscall57" => Function::new_env(store, env, crate::syscalls::___syscall57), + "___syscall60" => Function::new_env(store, env, crate::syscalls::___syscall60), + "___syscall63" => Function::new_env(store, env, crate::syscalls::___syscall63), + "___syscall64" => Function::new_env(store, env, crate::syscalls::___syscall64), + "___syscall66" => Function::new_env(store, env, crate::syscalls::___syscall66), + "___syscall75" => Function::new_env(store, env, crate::syscalls::___syscall75), + "___syscall77" => Function::new_env(store, env, crate::syscalls::___syscall77), + "___syscall83" => Function::new_env(store, env, crate::syscalls::___syscall83), + "___syscall85" => Function::new_env(store, env, crate::syscalls::___syscall85), + "___syscall91" => Function::new_env(store, env, crate::syscalls::___syscall91), + "___syscall94" => Function::new_env(store, env, crate::syscalls::___syscall94), + "___syscall96" => Function::new_env(store, env, crate::syscalls::___syscall96), + "___syscall97" => Function::new_env(store, env, crate::syscalls::___syscall97), + "___syscall102" => Function::new_env(store, env, crate::syscalls::___syscall102), + "___syscall110" => Function::new_env(store, env, crate::syscalls::___syscall110), + "___syscall114" => Function::new_env(store, env, crate::syscalls::___syscall114), + "___syscall118" => Function::new_env(store, env, crate::syscalls::___syscall118), + "___syscall121" => Function::new_env(store, env, crate::syscalls::___syscall121), + "___syscall122" => Function::new_env(store, env, crate::syscalls::___syscall122), + "___syscall125" => Function::new_env(store, env, crate::syscalls::___syscall125), + "___syscall132" => Function::new_env(store, env, crate::syscalls::___syscall132), + "___syscall133" => Function::new_env(store, env, crate::syscalls::___syscall133), + "___syscall140" => Function::new_env(store, env, crate::syscalls::___syscall140), + "___syscall142" => Function::new_env(store, env, crate::syscalls::___syscall142), + "___syscall144" => Function::new_env(store, env, crate::syscalls::___syscall144), + "___syscall145" => Function::new_env(store, env, crate::syscalls::___syscall145), + "___syscall146" => Function::new_env(store, env, crate::syscalls::___syscall146), + "___syscall147" => Function::new_env(store, env, crate::syscalls::___syscall147), + "___syscall148" => Function::new_env(store, env, crate::syscalls::___syscall148), + "___syscall150" => Function::new_env(store, env, crate::syscalls::___syscall150), + "___syscall151" => Function::new_env(store, env, crate::syscalls::___syscall151), + "___syscall152" => Function::new_env(store, env, crate::syscalls::___syscall152), + "___syscall153" => Function::new_env(store, env, crate::syscalls::___syscall153), + "___syscall163" => Function::new_env(store, env, crate::syscalls::___syscall163), + "___syscall168" => Function::new_env(store, env, crate::syscalls::___syscall168), + "___syscall180" => Function::new_env(store, env, crate::syscalls::___syscall180), + "___syscall181" => Function::new_env(store, env, crate::syscalls::___syscall181), + "___syscall183" => Function::new_env(store, env, crate::syscalls::___syscall183), + "___syscall191" => Function::new_env(store, env, crate::syscalls::___syscall191), + "___syscall192" => Function::new_env(store, env, crate::syscalls::___syscall192), + "___syscall193" => Function::new_env(store, env, crate::syscalls::___syscall193), + "___syscall194" => Function::new_env(store, env, crate::syscalls::___syscall194), + "___syscall195" => Function::new_env(store, env, crate::syscalls::___syscall195), + "___syscall196" => Function::new_env(store, env, crate::syscalls::___syscall196), + "___syscall197" => Function::new_env(store, env, crate::syscalls::___syscall197), + "___syscall198" => Function::new_env(store, env, crate::syscalls::___syscall198), + "___syscall199" => Function::new_env(store, env, crate::syscalls::___syscall199), + "___syscall200" => Function::new_env(store, env, crate::syscalls::___syscall200), + "___syscall201" => Function::new_env(store, env, crate::syscalls::___syscall201), + "___syscall202" => Function::new_env(store, env, crate::syscalls::___syscall202), + "___syscall205" => Function::new_env(store, env, crate::syscalls::___syscall205), + "___syscall207" => Function::new_env(store, env, crate::syscalls::___syscall207), + "___syscall209" => Function::new_env(store, env, crate::syscalls::___syscall209), + "___syscall211" => Function::new_env(store, env, crate::syscalls::___syscall211), + "___syscall212" => Function::new_env(store, env, crate::syscalls::___syscall212), + "___syscall218" => Function::new_env(store, env, crate::syscalls::___syscall218), + "___syscall219" => Function::new_env(store, env, crate::syscalls::___syscall219), + "___syscall220" => Function::new_env(store, env, crate::syscalls::___syscall220), + "___syscall221" => Function::new_env(store, env, crate::syscalls::___syscall221), + "___syscall268" => Function::new_env(store, env, crate::syscalls::___syscall268), + "___syscall269" => Function::new_env(store, env, crate::syscalls::___syscall269), + "___syscall272" => Function::new_env(store, env, crate::syscalls::___syscall272), + "___syscall295" => Function::new_env(store, env, crate::syscalls::___syscall295), + "___syscall296" => Function::new_env(store, env, crate::syscalls::___syscall296), + "___syscall297" => Function::new_env(store, env, crate::syscalls::___syscall297), + "___syscall298" => Function::new_env(store, env, crate::syscalls::___syscall298), + "___syscall300" => Function::new_env(store, env, crate::syscalls::___syscall300), + "___syscall301" => Function::new_env(store, env, crate::syscalls::___syscall301), + "___syscall302" => Function::new_env(store, env, crate::syscalls::___syscall302), + "___syscall303" => Function::new_env(store, env, crate::syscalls::___syscall303), + "___syscall304" => Function::new_env(store, env, crate::syscalls::___syscall304), + "___syscall305" => Function::new_env(store, env, crate::syscalls::___syscall305), + "___syscall306" => Function::new_env(store, env, crate::syscalls::___syscall306), + "___syscall307" => Function::new_env(store, env, crate::syscalls::___syscall307), + "___syscall308" => Function::new_env(store, env, crate::syscalls::___syscall308), + "___syscall320" => Function::new_env(store, env, crate::syscalls::___syscall320), + "___syscall324" => Function::new_env(store, env, crate::syscalls::___syscall324), + "___syscall330" => Function::new_env(store, env, crate::syscalls::___syscall330), + "___syscall331" => Function::new_env(store, env, crate::syscalls::___syscall331), + "___syscall333" => Function::new_env(store, env, crate::syscalls::___syscall333), + "___syscall334" => Function::new_env(store, env, crate::syscalls::___syscall334), + "___syscall337" => Function::new_env(store, env, crate::syscalls::___syscall337), + "___syscall340" => Function::new_env(store, env, crate::syscalls::___syscall340), + "___syscall345" => Function::new_env(store, env, crate::syscalls::___syscall345), // Process - "abort" => func!(crate::process::em_abort), - "_abort" => func!(crate::process::_abort), - "_prctl" => func!(crate::process::_prctl), - "abortStackOverflow" => func!(crate::process::abort_stack_overflow), - "_llvm_trap" => func!(crate::process::_llvm_trap), - "_fork" => func!(crate::process::_fork), - "_exit" => func!(crate::process::_exit), - "_system" => func!(crate::process::_system), - "_popen" => func!(crate::process::_popen), - "_endgrent" => func!(crate::process::_endgrent), - "_execve" => func!(crate::process::_execve), - "_kill" => func!(crate::process::_kill), - "_llvm_stackrestore" => func!(crate::process::_llvm_stackrestore), - "_llvm_stacksave" => func!(crate::process::_llvm_stacksave), - "_llvm_eh_typeid_for" => func!(crate::process::_llvm_eh_typeid_for), - "_raise" => func!(crate::process::_raise), - "_sem_init" => func!(crate::process::_sem_init), - "_sem_destroy" => func!(crate::process::_sem_destroy), - "_sem_post" => func!(crate::process::_sem_post), - "_sem_wait" => func!(crate::process::_sem_wait), - "_getgrent" => func!(crate::process::_getgrent), - "_sched_yield" => func!(crate::process::_sched_yield), - "_setgrent" => func!(crate::process::_setgrent), - "_setgroups" => func!(crate::process::_setgroups), - "_setitimer" => func!(crate::process::_setitimer), - "_usleep" => func!(crate::process::_usleep), - "_nanosleep" => func!(crate::process::_nanosleep), - "_utime" => func!(crate::process::_utime), - "_utimes" => func!(crate::process::_utimes), - "_wait" => func!(crate::process::_wait), - "_wait3" => func!(crate::process::_wait3), - "_wait4" => func!(crate::process::_wait4), - "_waitid" => func!(crate::process::_waitid), - "_waitpid" => func!(crate::process::_waitpid), + "abort" => Function::new_env(store, env, crate::process::em_abort), + "_abort" => Function::new_env(store, env, crate::process::_abort), + "_prctl" => Function::new_env(store, env, crate::process::_prctl), + "abortStackOverflow" => Function::new_env(store, env, crate::process::abort_stack_overflow), + "_llvm_trap" => Function::new_env(store, env, crate::process::_llvm_trap), + "_fork" => Function::new_env(store, env, crate::process::_fork), + "_exit" => Function::new_env(store, env, crate::process::_exit), + "_system" => Function::new_env(store, env, crate::process::_system), + "_popen" => Function::new_env(store, env, crate::process::_popen), + "_endgrent" => Function::new_env(store, env, crate::process::_endgrent), + "_execve" => Function::new_env(store, env, crate::process::_execve), + "_kill" => Function::new_env(store, env, crate::process::_kill), + "_llvm_stackrestore" => Function::new_env(store, env, crate::process::_llvm_stackrestore), + "_llvm_stacksave" => Function::new_env(store, env, crate::process::_llvm_stacksave), + "_llvm_eh_typeid_for" => Function::new_env(store, env, crate::process::_llvm_eh_typeid_for), + "_raise" => Function::new_env(store, env, crate::process::_raise), + "_sem_init" => Function::new_env(store, env, crate::process::_sem_init), + "_sem_destroy" => Function::new_env(store, env, crate::process::_sem_destroy), + "_sem_post" => Function::new_env(store, env, crate::process::_sem_post), + "_sem_wait" => Function::new_env(store, env, crate::process::_sem_wait), + "_getgrent" => Function::new_env(store, env, crate::process::_getgrent), + "_sched_yield" => Function::new_env(store, env, crate::process::_sched_yield), + "_setgrent" => Function::new_env(store, env, crate::process::_setgrent), + "_setgroups" => Function::new_env(store, env, crate::process::_setgroups), + "_setitimer" => Function::new_env(store, env, crate::process::_setitimer), + "_usleep" => Function::new_env(store, env, crate::process::_usleep), + "_nanosleep" => Function::new_env(store, env, crate::process::_nanosleep), + "_utime" => Function::new_env(store, env, crate::process::_utime), + "_utimes" => Function::new_env(store, env, crate::process::_utimes), + "_wait" => Function::new_env(store, env, crate::process::_wait), + "_wait3" => Function::new_env(store, env, crate::process::_wait3), + "_wait4" => Function::new_env(store, env, crate::process::_wait4), + "_waitid" => Function::new_env(store, env, crate::process::_waitid), + "_waitpid" => Function::new_env(store, env, crate::process::_waitpid), // Emscripten - "_emscripten_asm_const_i" => func!(crate::emscripten_target::asm_const_i), - "_emscripten_exit_with_live_runtime" => func!(crate::emscripten_target::exit_with_live_runtime), + "_emscripten_asm_const_i" => Function::new_env(store, env, crate::emscripten_target::asm_const_i), + "_emscripten_exit_with_live_runtime" => Function::new_env(store, env, crate::emscripten_target::exit_with_live_runtime), // Signal - "_sigemptyset" => func!(crate::signal::_sigemptyset), - "_sigaddset" => func!(crate::signal::_sigaddset), - "_sigprocmask" => func!(crate::signal::_sigprocmask), - "_sigaction" => func!(crate::signal::_sigaction), - "_signal" => func!(crate::signal::_signal), - "_sigsuspend" => func!(crate::signal::_sigsuspend), + "_sigemptyset" => Function::new_env(store, env, crate::signal::_sigemptyset), + "_sigaddset" => Function::new_env(store, env, crate::signal::_sigaddset), + "_sigprocmask" => Function::new_env(store, env, crate::signal::_sigprocmask), + "_sigaction" => Function::new_env(store, env, crate::signal::_sigaction), + "_signal" => Function::new_env(store, env, crate::signal::_signal), + "_sigsuspend" => Function::new_env(store, env, crate::signal::_sigsuspend), // Memory "abortOnCannotGrowMemory" => abort_on_cannot_grow_memory_export, - "_emscripten_memcpy_big" => func!(crate::memory::_emscripten_memcpy_big), - "_emscripten_get_heap_size" => func!(crate::memory::_emscripten_get_heap_size), - "_emscripten_resize_heap" => func!(crate::memory::_emscripten_resize_heap), - "enlargeMemory" => func!(crate::memory::enlarge_memory), - "segfault" => func!(crate::memory::segfault), - "alignfault" => func!(crate::memory::alignfault), - "ftfault" => func!(crate::memory::ftfault), - "getTotalMemory" => func!(crate::memory::get_total_memory), - "_sbrk" => func!(crate::memory::sbrk), - "___map_file" => func!(crate::memory::___map_file), + "_emscripten_memcpy_big" => Function::new_env(store, env, crate::memory::_emscripten_memcpy_big), + "_emscripten_get_heap_size" => Function::new_env(store, env, crate::memory::_emscripten_get_heap_size), + "_emscripten_resize_heap" => Function::new_env(store, env, crate::memory::_emscripten_resize_heap), + "enlargeMemory" => Function::new_env(store, env, crate::memory::enlarge_memory), + "segfault" => Function::new_env(store, env, crate::memory::segfault), + "alignfault" => Function::new_env(store, env, crate::memory::alignfault), + "ftfault" => Function::new_env(store, env, crate::memory::ftfault), + "getTotalMemory" => Function::new_env(store, env, crate::memory::get_total_memory), + "_sbrk" => Function::new_env(store, env, crate::memory::sbrk), + "___map_file" => Function::new_env(store, env, crate::memory::___map_file), // Exception - "___cxa_allocate_exception" => func!(crate::exception::___cxa_allocate_exception), - "___cxa_current_primary_exception" => func!(crate::exception::___cxa_current_primary_exception), - "___cxa_decrement_exception_refcount" => func!(crate::exception::___cxa_decrement_exception_refcount), - "___cxa_increment_exception_refcount" => func!(crate::exception::___cxa_increment_exception_refcount), - "___cxa_rethrow_primary_exception" => func!(crate::exception::___cxa_rethrow_primary_exception), - "___cxa_throw" => func!(crate::exception::___cxa_throw), - "___cxa_begin_catch" => func!(crate::exception::___cxa_begin_catch), - "___cxa_end_catch" => func!(crate::exception::___cxa_end_catch), - "___cxa_uncaught_exception" => func!(crate::exception::___cxa_uncaught_exception), - "___cxa_pure_virtual" => func!(crate::exception::___cxa_pure_virtual), + "___cxa_allocate_exception" => Function::new_env(store, env, crate::exception::___cxa_allocate_exception), + "___cxa_current_primary_exception" => Function::new_env(store, env, crate::exception::___cxa_current_primary_exception), + "___cxa_decrement_exception_refcount" => Function::new_env(store, env, crate::exception::___cxa_decrement_exception_refcount), + "___cxa_increment_exception_refcount" => Function::new_env(store, env, crate::exception::___cxa_increment_exception_refcount), + "___cxa_rethrow_primary_exception" => Function::new_env(store, env, crate::exception::___cxa_rethrow_primary_exception), + "___cxa_throw" => Function::new_env(store, env, crate::exception::___cxa_throw), + "___cxa_begin_catch" => Function::new_env(store, env, crate::exception::___cxa_begin_catch), + "___cxa_end_catch" => Function::new_env(store, env, crate::exception::___cxa_end_catch), + "___cxa_uncaught_exception" => Function::new_env(store, env, crate::exception::___cxa_uncaught_exception), + "___cxa_pure_virtual" => Function::new_env(store, env, crate::exception::___cxa_pure_virtual), // Time - "_gettimeofday" => func!(crate::time::_gettimeofday), - "_clock_getres" => func!(crate::time::_clock_getres), - "_clock_gettime" => func!(crate::time::_clock_gettime), - "_clock_settime" => func!(crate::time::_clock_settime), - "___clock_gettime" => func!(crate::time::_clock_gettime), - "_clock" => func!(crate::time::_clock), - "_difftime" => func!(crate::time::_difftime), - "_asctime" => func!(crate::time::_asctime), - "_asctime_r" => func!(crate::time::_asctime_r), - "_localtime" => func!(crate::time::_localtime), - "_time" => func!(crate::time::_time), - "_timegm" => func!(crate::time::_timegm), - "_strftime" => func!(crate::time::_strftime), - "_strftime_l" => func!(crate::time::_strftime_l), - "_localtime_r" => func!(crate::time::_localtime_r), - "_gmtime_r" => func!(crate::time::_gmtime_r), - "_ctime" => func!(crate::time::_ctime), - "_ctime_r" => func!(crate::time::_ctime_r), - "_mktime" => func!(crate::time::_mktime), - "_gmtime" => func!(crate::time::_gmtime), + "_gettimeofday" => Function::new_env(store, env, crate::time::_gettimeofday), + "_clock_getres" => Function::new_env(store, env, crate::time::_clock_getres), + "_clock_gettime" => Function::new_env(store, env, crate::time::_clock_gettime), + "_clock_settime" => Function::new_env(store, env, crate::time::_clock_settime), + "___clock_gettime" => Function::new_env(store, env, crate::time::_clock_gettime), + "_clock" => Function::new_env(store, env, crate::time::_clock), + "_difftime" => Function::new_env(store, env, crate::time::_difftime), + "_asctime" => Function::new_env(store, env, crate::time::_asctime), + "_asctime_r" => Function::new_env(store, env, crate::time::_asctime_r), + "_localtime" => Function::new_env(store, env, crate::time::_localtime), + "_time" => Function::new_env(store, env, crate::time::_time), + "_timegm" => Function::new_env(store, env, crate::time::_timegm), + "_strftime" => Function::new_env(store, env, crate::time::_strftime), + "_strftime_l" => Function::new_env(store, env, crate::time::_strftime_l), + "_localtime_r" => Function::new_env(store, env, crate::time::_localtime_r), + "_gmtime_r" => Function::new_env(store, env, crate::time::_gmtime_r), + "_ctime" => Function::new_env(store, env, crate::time::_ctime), + "_ctime_r" => Function::new_env(store, env, crate::time::_ctime_r), + "_mktime" => Function::new_env(store, env, crate::time::_mktime), + "_gmtime" => Function::new_env(store, env, crate::time::_gmtime), // Math - "sqrt" => func!(crate::math::sqrt), - "floor" => func!(crate::math::floor), - "fabs" => func!(crate::math::fabs), - "f64-rem" => func!(crate::math::f64_rem), - "_llvm_copysign_f32" => func!(crate::math::_llvm_copysign_f32), - "_llvm_copysign_f64" => func!(crate::math::_llvm_copysign_f64), - "_llvm_log10_f64" => func!(crate::math::_llvm_log10_f64), - "_llvm_log2_f64" => func!(crate::math::_llvm_log2_f64), - "_llvm_log10_f32" => func!(crate::math::_llvm_log10_f32), - "_llvm_log2_f32" => func!(crate::math::_llvm_log2_f64), - "_llvm_sin_f64" => func!(crate::math::_llvm_sin_f64), - "_llvm_cos_f64" => func!(crate::math::_llvm_cos_f64), - "_llvm_exp2_f32" => func!(crate::math::_llvm_exp2_f32), - "_llvm_exp2_f64" => func!(crate::math::_llvm_exp2_f64), - "_llvm_trunc_f64" => func!(crate::math::_llvm_trunc_f64), - "_llvm_fma_f64" => func!(crate::math::_llvm_fma_f64), - "_emscripten_random" => func!(crate::math::_emscripten_random), + "sqrt" => Function::new_env(store, env, crate::math::sqrt), + "floor" => Function::new_env(store, env, crate::math::floor), + "fabs" => Function::new_env(store, env, crate::math::fabs), + "f64-rem" => Function::new_env(store, env, crate::math::f64_rem), + "_llvm_copysign_f32" => Function::new_env(store, env, crate::math::_llvm_copysign_f32), + "_llvm_copysign_f64" => Function::new_env(store, env, crate::math::_llvm_copysign_f64), + "_llvm_log10_f64" => Function::new_env(store, env, crate::math::_llvm_log10_f64), + "_llvm_log2_f64" => Function::new_env(store, env, crate::math::_llvm_log2_f64), + "_llvm_log10_f32" => Function::new_env(store, env, crate::math::_llvm_log10_f32), + "_llvm_log2_f32" => Function::new_env(store, env, crate::math::_llvm_log2_f64), + "_llvm_sin_f64" => Function::new_env(store, env, crate::math::_llvm_sin_f64), + "_llvm_cos_f64" => Function::new_env(store, env, crate::math::_llvm_cos_f64), + "_llvm_exp2_f32" => Function::new_env(store, env, crate::math::_llvm_exp2_f32), + "_llvm_exp2_f64" => Function::new_env(store, env, crate::math::_llvm_exp2_f64), + "_llvm_trunc_f64" => Function::new_env(store, env, crate::math::_llvm_trunc_f64), + "_llvm_fma_f64" => Function::new_env(store, env, crate::math::_llvm_fma_f64), + "_emscripten_random" => Function::new_env(store, env, crate::math::_emscripten_random), // Jump - "__setjmp" => func!(crate::jmp::__setjmp), - "__longjmp" => func!(crate::jmp::__longjmp), - "_longjmp" => func!(crate::jmp::_longjmp), - "_emscripten_longjmp" => func!(crate::jmp::_longjmp), + "__setjmp" => Function::new_env(store, env, crate::jmp::__setjmp), + "__longjmp" => Function::new_env(store, env, crate::jmp::__longjmp), + "_longjmp" => Function::new_env(store, env, crate::jmp::_longjmp), + "_emscripten_longjmp" => Function::new_env(store, env, crate::jmp::_longjmp), // Bitwise - "_llvm_bswap_i64" => func!(crate::bitwise::_llvm_bswap_i64), + "_llvm_bswap_i64" => Function::new_env(store, env, crate::bitwise::_llvm_bswap_i64), // libc - "_execv" => func!(crate::libc::execv), - "_endpwent" => func!(crate::libc::endpwent), - "_fexecve" => func!(crate::libc::fexecve), - "_fpathconf" => func!(crate::libc::fpathconf), - "_getitimer" => func!(crate::libc::getitimer), - "_getpwent" => func!(crate::libc::getpwent), - "_killpg" => func!(crate::libc::killpg), - "_pathconf" => func!(crate::libc::pathconf), - "_siginterrupt" => func!(crate::signal::_siginterrupt), - "_setpwent" => func!(crate::libc::setpwent), - "_sigismember" => func!(crate::libc::sigismember), - "_sigpending" => func!(crate::libc::sigpending), - "___libc_current_sigrtmax" => func!(crate::libc::current_sigrtmax), - "___libc_current_sigrtmin" => func!(crate::libc::current_sigrtmin), + "_execv" => Function::new_env(store, env, crate::libc::execv), + "_endpwent" => Function::new_env(store, env, crate::libc::endpwent), + "_fexecve" => Function::new_env(store, env, crate::libc::fexecve), + "_fpathconf" => Function::new_env(store, env, crate::libc::fpathconf), + "_getitimer" => Function::new_env(store, env, crate::libc::getitimer), + "_getpwent" => Function::new_env(store, env, crate::libc::getpwent), + "_killpg" => Function::new_env(store, env, crate::libc::killpg), + "_pathconf" => Function::new_env(store, env, crate::libc::pathconf), + "_siginterrupt" => Function::new_env(store, env, crate::signal::_siginterrupt), + "_setpwent" => Function::new_env(store, env, crate::libc::setpwent), + "_sigismember" => Function::new_env(store, env, crate::libc::sigismember), + "_sigpending" => Function::new_env(store, env, crate::libc::sigpending), + "___libc_current_sigrtmax" => Function::new_env(store, env, crate::libc::current_sigrtmax), + "___libc_current_sigrtmin" => Function::new_env(store, env, crate::libc::current_sigrtmin), // Linking - "_dlclose" => func!(crate::linking::_dlclose), - "_dlerror" => func!(crate::linking::_dlerror), - "_dlopen" => func!(crate::linking::_dlopen), - "_dlsym" => func!(crate::linking::_dlsym), + "_dlclose" => Function::new_env(store, env, crate::linking::_dlclose), + "_dlerror" => Function::new_env(store, env, crate::linking::_dlerror), + "_dlopen" => Function::new_env(store, env, crate::linking::_dlopen), + "_dlsym" => Function::new_env(store, env, crate::linking::_dlsym), // wasm32-unknown-emscripten - "_alarm" => func!(crate::emscripten_target::_alarm), - "_atexit" => func!(crate::emscripten_target::_atexit), - "setTempRet0" => func!(crate::emscripten_target::setTempRet0), - "getTempRet0" => func!(crate::emscripten_target::getTempRet0), - "invoke_i" => func!(crate::emscripten_target::invoke_i), - "invoke_ii" => func!(crate::emscripten_target::invoke_ii), - "invoke_iii" => func!(crate::emscripten_target::invoke_iii), - "invoke_iiii" => func!(crate::emscripten_target::invoke_iiii), - "invoke_iifi" => func!(crate::emscripten_target::invoke_iifi), - "invoke_v" => func!(crate::emscripten_target::invoke_v), - "invoke_vi" => func!(crate::emscripten_target::invoke_vi), - "invoke_vj" => func!(crate::emscripten_target::invoke_vj), - "invoke_vjji" => func!(crate::emscripten_target::invoke_vjji), - "invoke_vii" => func!(crate::emscripten_target::invoke_vii), - "invoke_viii" => func!(crate::emscripten_target::invoke_viii), - "invoke_viiii" => func!(crate::emscripten_target::invoke_viiii), - "__Unwind_Backtrace" => func!(crate::emscripten_target::__Unwind_Backtrace), - "__Unwind_FindEnclosingFunction" => func!(crate::emscripten_target::__Unwind_FindEnclosingFunction), - "__Unwind_GetIPInfo" => func!(crate::emscripten_target::__Unwind_GetIPInfo), - "___cxa_find_matching_catch_2" => func!(crate::emscripten_target::___cxa_find_matching_catch_2), - "___cxa_find_matching_catch_3" => func!(crate::emscripten_target::___cxa_find_matching_catch_3), - "___cxa_free_exception" => func!(crate::emscripten_target::___cxa_free_exception), - "___resumeException" => func!(crate::emscripten_target::___resumeException), - "_dladdr" => func!(crate::emscripten_target::_dladdr), - "_pthread_attr_destroy" => func!(crate::pthread::_pthread_attr_destroy), - "_pthread_attr_getstack" => func!(crate::pthread::_pthread_attr_getstack), - "_pthread_attr_init" => func!(crate::pthread::_pthread_attr_init), - "_pthread_attr_setstacksize" => func!(crate::pthread::_pthread_attr_setstacksize), - "_pthread_cleanup_pop" => func!(crate::pthread::_pthread_cleanup_pop), - "_pthread_cleanup_push" => func!(crate::pthread::_pthread_cleanup_push), - "_pthread_cond_destroy" => func!(crate::pthread::_pthread_cond_destroy), - "_pthread_cond_init" => func!(crate::pthread::_pthread_cond_init), - "_pthread_cond_signal" => func!(crate::pthread::_pthread_cond_signal), - "_pthread_cond_timedwait" => func!(crate::pthread::_pthread_cond_timedwait), - "_pthread_cond_wait" => func!(crate::pthread::_pthread_cond_wait), - "_pthread_condattr_destroy" => func!(crate::pthread::_pthread_condattr_destroy), - "_pthread_condattr_init" => func!(crate::pthread::_pthread_condattr_init), - "_pthread_condattr_setclock" => func!(crate::pthread::_pthread_condattr_setclock), - "_pthread_create" => func!(crate::pthread::_pthread_create), - "_pthread_detach" => func!(crate::pthread::_pthread_detach), - "_pthread_equal" => func!(crate::pthread::_pthread_equal), - "_pthread_exit" => func!(crate::pthread::_pthread_exit), - "_pthread_self" => func!(crate::pthread::_pthread_self), - "_pthread_getattr_np" => func!(crate::pthread::_pthread_getattr_np), - "_pthread_getspecific" => func!(crate::pthread::_pthread_getspecific), - "_pthread_join" => func!(crate::pthread::_pthread_join), - "_pthread_key_create" => func!(crate::pthread::_pthread_key_create), - "_pthread_mutex_destroy" => func!(crate::pthread::_pthread_mutex_destroy), - "_pthread_mutex_init" => func!(crate::pthread::_pthread_mutex_init), - "_pthread_mutexattr_destroy" => func!(crate::pthread::_pthread_mutexattr_destroy), - "_pthread_mutexattr_init" => func!(crate::pthread::_pthread_mutexattr_init), - "_pthread_mutexattr_settype" => func!(crate::pthread::_pthread_mutexattr_settype), - "_pthread_once" => func!(crate::pthread::_pthread_once), - "_pthread_rwlock_destroy" => func!(crate::pthread::_pthread_rwlock_destroy), - "_pthread_rwlock_init" => func!(crate::pthread::_pthread_rwlock_init), - "_pthread_rwlock_rdlock" => func!(crate::pthread::_pthread_rwlock_rdlock), - "_pthread_rwlock_unlock" => func!(crate::pthread::_pthread_rwlock_unlock), - "_pthread_rwlock_wrlock" => func!(crate::pthread::_pthread_rwlock_wrlock), - "_pthread_setcancelstate" => func!(crate::pthread::_pthread_setcancelstate), - "_pthread_setspecific" => func!(crate::pthread::_pthread_setspecific), - "_pthread_sigmask" => func!(crate::pthread::_pthread_sigmask), - "___gxx_personality_v0" => func!(crate::emscripten_target::___gxx_personality_v0), - "_gai_strerror" => func!(crate::env::_gai_strerror), - "_getdtablesize" => func!(crate::emscripten_target::_getdtablesize), - "_gethostbyaddr" => func!(crate::emscripten_target::_gethostbyaddr), - "_gethostbyname" => func!(crate::emscripten_target::_gethostbyname), - "_gethostbyname_r" => func!(crate::emscripten_target::_gethostbyname_r), - "_getloadavg" => func!(crate::emscripten_target::_getloadavg), - "_getnameinfo" => func!(crate::emscripten_target::_getnameinfo), - "invoke_dii" => func!(crate::emscripten_target::invoke_dii), - "invoke_diiii" => func!(crate::emscripten_target::invoke_diiii), - "invoke_iiiii" => func!(crate::emscripten_target::invoke_iiiii), - "invoke_iiiiii" => func!(crate::emscripten_target::invoke_iiiiii), - "invoke_iiiiiii" => func!(crate::emscripten_target::invoke_iiiiiii), - "invoke_iiiiiiii" => func!(crate::emscripten_target::invoke_iiiiiiii), - "invoke_iiiiiiiii" => func!(crate::emscripten_target::invoke_iiiiiiiii), - "invoke_iiiiiiiiii" => func!(crate::emscripten_target::invoke_iiiiiiiiii), - "invoke_iiiiiiiiiii" => func!(crate::emscripten_target::invoke_iiiiiiiiiii), - "invoke_vd" => func!(crate::emscripten_target::invoke_vd), - "invoke_viiiii" => func!(crate::emscripten_target::invoke_viiiii), - "invoke_viiiiii" => func!(crate::emscripten_target::invoke_viiiiii), - "invoke_viiiiiii" => func!(crate::emscripten_target::invoke_viiiiiii), - "invoke_viiiiiiii" => func!(crate::emscripten_target::invoke_viiiiiiii), - "invoke_viiiiiiiii" => func!(crate::emscripten_target::invoke_viiiiiiiii), - "invoke_viiiiiiiii" => func!(crate::emscripten_target::invoke_viiiiiiiii), - "invoke_viiiiiiiiii" => func!(crate::emscripten_target::invoke_viiiiiiiiii), - "invoke_iij" => func!(crate::emscripten_target::invoke_iij), - "invoke_iji" => func!(crate::emscripten_target::invoke_iji), - "invoke_iiji" => func!(crate::emscripten_target::invoke_iiji), - "invoke_iiijj" => func!(crate::emscripten_target::invoke_iiijj), - "invoke_j" => func!(crate::emscripten_target::invoke_j), - "invoke_ji" => func!(crate::emscripten_target::invoke_ji), - "invoke_jii" => func!(crate::emscripten_target::invoke_jii), - "invoke_jij" => func!(crate::emscripten_target::invoke_jij), - "invoke_jjj" => func!(crate::emscripten_target::invoke_jjj), - "invoke_viiij" => func!(crate::emscripten_target::invoke_viiij), - "invoke_viiijiiii" => func!(crate::emscripten_target::invoke_viiijiiii), - "invoke_viiijiiiiii" => func!(crate::emscripten_target::invoke_viiijiiiiii), - "invoke_viij" => func!(crate::emscripten_target::invoke_viij), - "invoke_viiji" => func!(crate::emscripten_target::invoke_viiji), - "invoke_viijiii" => func!(crate::emscripten_target::invoke_viijiii), - "invoke_viijj" => func!(crate::emscripten_target::invoke_viijj), - "invoke_vij" => func!(crate::emscripten_target::invoke_vij), - "invoke_viji" => func!(crate::emscripten_target::invoke_viji), - "invoke_vijiii" => func!(crate::emscripten_target::invoke_vijiii), - "invoke_vijj" => func!(crate::emscripten_target::invoke_vijj), - "invoke_vidd" => func!(crate::emscripten_target::invoke_vidd), - "invoke_viid" => func!(crate::emscripten_target::invoke_viid), - "invoke_viidii" => func!(crate::emscripten_target::invoke_viidii), - "invoke_viidddddddd" => func!(crate::emscripten_target::invoke_viidddddddd), + "_alarm" => Function::new_env(store, env, crate::emscripten_target::_alarm), + "_atexit" => Function::new_env(store, env, crate::emscripten_target::_atexit), + "setTempRet0" => Function::new_env(store, env, crate::emscripten_target::setTempRet0), + "getTempRet0" => Function::new_env(store, env, crate::emscripten_target::getTempRet0), + "invoke_i" => Function::new_env(store, env, crate::emscripten_target::invoke_i), + "invoke_ii" => Function::new_env(store, env, crate::emscripten_target::invoke_ii), + "invoke_iii" => Function::new_env(store, env, crate::emscripten_target::invoke_iii), + "invoke_iiii" => Function::new_env(store, env, crate::emscripten_target::invoke_iiii), + "invoke_iifi" => Function::new_env(store, env, crate::emscripten_target::invoke_iifi), + "invoke_v" => Function::new_env(store, env, crate::emscripten_target::invoke_v), + "invoke_vi" => Function::new_env(store, env, crate::emscripten_target::invoke_vi), + "invoke_vj" => Function::new_env(store, env, crate::emscripten_target::invoke_vj), + "invoke_vjji" => Function::new_env(store, env, crate::emscripten_target::invoke_vjji), + "invoke_vii" => Function::new_env(store, env, crate::emscripten_target::invoke_vii), + "invoke_viii" => Function::new_env(store, env, crate::emscripten_target::invoke_viii), + "invoke_viiii" => Function::new_env(store, env, crate::emscripten_target::invoke_viiii), + "__Unwind_Backtrace" => Function::new_env(store, env, crate::emscripten_target::__Unwind_Backtrace), + "__Unwind_FindEnclosingFunction" => Function::new_env(store, env, crate::emscripten_target::__Unwind_FindEnclosingFunction), + "__Unwind_GetIPInfo" => Function::new_env(store, env, 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_3" => Function::new_env(store, env, crate::emscripten_target::___cxa_find_matching_catch_3), + "___cxa_free_exception" => Function::new_env(store, env, crate::emscripten_target::___cxa_free_exception), + "___resumeException" => Function::new_env(store, env, crate::emscripten_target::___resumeException), + "_dladdr" => Function::new_env(store, env, crate::emscripten_target::_dladdr), + "_pthread_attr_destroy" => Function::new_env(store, env, crate::pthread::_pthread_attr_destroy), + "_pthread_attr_getstack" => Function::new_env(store, env, crate::pthread::_pthread_attr_getstack), + "_pthread_attr_init" => Function::new_env(store, env, crate::pthread::_pthread_attr_init), + "_pthread_attr_setstacksize" => Function::new_env(store, env, crate::pthread::_pthread_attr_setstacksize), + "_pthread_cleanup_pop" => Function::new_env(store, env, crate::pthread::_pthread_cleanup_pop), + "_pthread_cleanup_push" => Function::new_env(store, env, crate::pthread::_pthread_cleanup_push), + "_pthread_cond_destroy" => Function::new_env(store, env, crate::pthread::_pthread_cond_destroy), + "_pthread_cond_init" => Function::new_env(store, env, crate::pthread::_pthread_cond_init), + "_pthread_cond_signal" => Function::new_env(store, env, crate::pthread::_pthread_cond_signal), + "_pthread_cond_timedwait" => Function::new_env(store, env, crate::pthread::_pthread_cond_timedwait), + "_pthread_cond_wait" => Function::new_env(store, env, crate::pthread::_pthread_cond_wait), + "_pthread_condattr_destroy" => Function::new_env(store, env, crate::pthread::_pthread_condattr_destroy), + "_pthread_condattr_init" => Function::new_env(store, env, crate::pthread::_pthread_condattr_init), + "_pthread_condattr_setclock" => Function::new_env(store, env, crate::pthread::_pthread_condattr_setclock), + "_pthread_create" => Function::new_env(store, env, crate::pthread::_pthread_create), + "_pthread_detach" => Function::new_env(store, env, crate::pthread::_pthread_detach), + "_pthread_equal" => Function::new_env(store, env, crate::pthread::_pthread_equal), + "_pthread_exit" => Function::new_env(store, env, crate::pthread::_pthread_exit), + "_pthread_self" => Function::new_env(store, env, crate::pthread::_pthread_self), + "_pthread_getattr_np" => Function::new_env(store, env, crate::pthread::_pthread_getattr_np), + "_pthread_getspecific" => Function::new_env(store, env, crate::pthread::_pthread_getspecific), + "_pthread_join" => Function::new_env(store, env, crate::pthread::_pthread_join), + "_pthread_key_create" => Function::new_env(store, env, crate::pthread::_pthread_key_create), + "_pthread_mutex_destroy" => Function::new_env(store, env, crate::pthread::_pthread_mutex_destroy), + "_pthread_mutex_init" => Function::new_env(store, env, crate::pthread::_pthread_mutex_init), + "_pthread_mutexattr_destroy" => Function::new_env(store, env, crate::pthread::_pthread_mutexattr_destroy), + "_pthread_mutexattr_init" => Function::new_env(store, env, crate::pthread::_pthread_mutexattr_init), + "_pthread_mutexattr_settype" => Function::new_env(store, env, crate::pthread::_pthread_mutexattr_settype), + "_pthread_once" => Function::new_env(store, env, crate::pthread::_pthread_once), + "_pthread_rwlock_destroy" => Function::new_env(store, env, crate::pthread::_pthread_rwlock_destroy), + "_pthread_rwlock_init" => Function::new_env(store, env, crate::pthread::_pthread_rwlock_init), + "_pthread_rwlock_rdlock" => Function::new_env(store, env, crate::pthread::_pthread_rwlock_rdlock), + "_pthread_rwlock_unlock" => Function::new_env(store, env, crate::pthread::_pthread_rwlock_unlock), + "_pthread_rwlock_wrlock" => Function::new_env(store, env, crate::pthread::_pthread_rwlock_wrlock), + "_pthread_setcancelstate" => Function::new_env(store, env, crate::pthread::_pthread_setcancelstate), + "_pthread_setspecific" => Function::new_env(store, env, crate::pthread::_pthread_setspecific), + "_pthread_sigmask" => Function::new_env(store, env, crate::pthread::_pthread_sigmask), + "___gxx_personality_v0" => Function::new_env(store, env, crate::emscripten_target::___gxx_personality_v0), + "_gai_strerror" => Function::new_env(store, env, crate::env::_gai_strerror), + "_getdtablesize" => Function::new_env(store, env, crate::emscripten_target::_getdtablesize), + "_gethostbyaddr" => Function::new_env(store, env, crate::emscripten_target::_gethostbyaddr), + "_gethostbyname" => Function::new_env(store, env, crate::emscripten_target::_gethostbyname), + "_gethostbyname_r" => Function::new_env(store, env, crate::emscripten_target::_gethostbyname_r), + "_getloadavg" => Function::new_env(store, env, crate::emscripten_target::_getloadavg), + "_getnameinfo" => Function::new_env(store, env, crate::emscripten_target::_getnameinfo), + "invoke_dii" => Function::new_env(store, env, crate::emscripten_target::invoke_dii), + "invoke_diiii" => Function::new_env(store, env, crate::emscripten_target::invoke_diiii), + "invoke_iiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_iiiii), + "invoke_iiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_iiiiii), + "invoke_iiiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_iiiiiii), + "invoke_iiiiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_iiiiiiii), + "invoke_iiiiiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_iiiiiiiii), + "invoke_iiiiiiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_iiiiiiiiii), + "invoke_iiiiiiiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_iiiiiiiiiii), + "invoke_vd" => Function::new_env(store, env, crate::emscripten_target::invoke_vd), + "invoke_viiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_viiiii), + "invoke_viiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_viiiiii), + "invoke_viiiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_viiiiiii), + "invoke_viiiiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_viiiiiiii), + "invoke_viiiiiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_viiiiiiiii), + "invoke_viiiiiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_viiiiiiiii), + "invoke_viiiiiiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_viiiiiiiiii), + "invoke_iij" => Function::new_env(store, env, crate::emscripten_target::invoke_iij), + "invoke_iji" => Function::new_env(store, env, crate::emscripten_target::invoke_iji), + "invoke_iiji" => Function::new_env(store, env, crate::emscripten_target::invoke_iiji), + "invoke_iiijj" => Function::new_env(store, env, crate::emscripten_target::invoke_iiijj), + "invoke_j" => Function::new_env(store, env, crate::emscripten_target::invoke_j), + "invoke_ji" => Function::new_env(store, env, crate::emscripten_target::invoke_ji), + "invoke_jii" => Function::new_env(store, env, crate::emscripten_target::invoke_jii), + "invoke_jij" => Function::new_env(store, env, crate::emscripten_target::invoke_jij), + "invoke_jjj" => Function::new_env(store, env, crate::emscripten_target::invoke_jjj), + "invoke_viiij" => Function::new_env(store, env, crate::emscripten_target::invoke_viiij), + "invoke_viiijiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_viiijiiii), + "invoke_viiijiiiiii" => Function::new_env(store, env, crate::emscripten_target::invoke_viiijiiiiii), + "invoke_viij" => Function::new_env(store, env, crate::emscripten_target::invoke_viij), + "invoke_viiji" => Function::new_env(store, env, crate::emscripten_target::invoke_viiji), + "invoke_viijiii" => Function::new_env(store, env, crate::emscripten_target::invoke_viijiii), + "invoke_viijj" => Function::new_env(store, env, crate::emscripten_target::invoke_viijj), + "invoke_vij" => Function::new_env(store, env, crate::emscripten_target::invoke_vij), + "invoke_viji" => Function::new_env(store, env, crate::emscripten_target::invoke_viji), + "invoke_vijiii" => Function::new_env(store, env, crate::emscripten_target::invoke_vijiii), + "invoke_vijj" => Function::new_env(store, env, crate::emscripten_target::invoke_vijj), + "invoke_vidd" => Function::new_env(store, env, crate::emscripten_target::invoke_vidd), + "invoke_viid" => Function::new_env(store, env, crate::emscripten_target::invoke_viid), + "invoke_viidii" => Function::new_env(store, env, crate::emscripten_target::invoke_viidii), + "invoke_viidddddddd" => Function::new_env(store, env, crate::emscripten_target::invoke_viidddddddd), // ucontext - "_getcontext" => func!(crate::ucontext::_getcontext), - "_makecontext" => func!(crate::ucontext::_makecontext), - "_setcontext" => func!(crate::ucontext::_setcontext), - "_swapcontext" => func!(crate::ucontext::_swapcontext), + "_getcontext" => Function::new_env(store, env, crate::ucontext::_getcontext), + "_makecontext" => Function::new_env(store, env, crate::ucontext::_makecontext), + "_setcontext" => Function::new_env(store, env, crate::ucontext::_setcontext), + "_swapcontext" => Function::new_env(store, env, crate::ucontext::_swapcontext), // unistd - "_confstr" => func!(crate::unistd::confstr), + "_confstr" => Function::new_env(store, env, crate::unistd::confstr), }; // Compatibility with newer versions of Emscripten @@ -1045,30 +1077,30 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject } for null_func_name in globals.null_func_names.iter() { - env_ns.insert(null_func_name.as_str(), Func::new(nullfunc).to_export()); + env_ns.insert(null_func_name.as_str(), Function::new(nullfunc).to_export()); } let import_object: ImportObject = imports! { "env" => env_ns, "global" => { - "NaN" => Global::new(Value::F64(f64::NAN)), - "Infinity" => Global::new(Value::F64(f64::INFINITY)), + "NaN" => Global::new(Val::F64(f64::NAN)), + "Infinity" => Global::new(Val::F64(f64::INFINITY)), }, "global.Math" => { - "pow" => func!(crate::math::pow), - "exp" => func!(crate::math::exp), - "log" => func!(crate::math::log), + "pow" => Function::new(store, crate::math::pow), + "exp" => Function::new(store, crate::math::exp), + "log" => Function::new(store, env, crate::math::log), }, "asm2wasm" => { - "f64-rem" => func!(crate::math::f64_rem), - "f64-to-int" => func!(crate::math::f64_to_int), + "f64-rem" => Function::new_env(store, env, crate::math::f64_rem), + "f64-to-int" => Function::new_env(store, env, crate::math::f64_to_int), }, }; import_object } -pub fn nullfunc(ctx: &mut Ctx, _x: u32) { +pub fn nullfunc(ctx: &mut EmEnv, _x: u32) { use crate::process::abort_with_message; debug!("emscripten::nullfunc_i {}", _x); abort_with_message( diff --git a/lib/emscripten/src/libc.rs b/lib/emscripten/src/libc.rs index dfaa5331b..e1dc1f0a2 100644 --- a/lib/emscripten/src/libc.rs +++ b/lib/emscripten/src/libc.rs @@ -1,4 +1,5 @@ extern crate libc; +use crate::EmEnv; #[cfg(unix)] use std::convert::TryInto; @@ -48,7 +49,7 @@ pub fn killpg(_a: i32, _b: i32) -> i32 { } #[cfg(unix)] -pub fn pathconf(ctx: &mut Ctx, path_ptr: i32, name: i32) -> i32 { +pub fn pathconf(ctx: &mut EmEnv, path_ptr: i32, name: i32) -> i32 { debug!("emscripten::pathconf"); let path = emscripten_memory_pointer!(ctx.memory(0), path_ptr) as *const i8; unsafe { libc::pathconf(path as *const _, name).try_into().unwrap() } diff --git a/lib/emscripten/src/linking.rs b/lib/emscripten/src/linking.rs index 831712e91..03ad29fc5 100644 --- a/lib/emscripten/src/linking.rs +++ b/lib/emscripten/src/linking.rs @@ -1,27 +1,27 @@ -use wasmer_runtime_core::vm::Ctx; +use crate::EmEnv; // TODO: Need to implement. /// emscripten: dlopen(filename: *const c_char, flag: c_int) -> *mut c_void -pub fn _dlopen(_ctx: &mut Ctx, _filename: u32, _flag: u32) -> i32 { +pub fn _dlopen(_ctx: &mut EmEnv, _filename: u32, _flag: u32) -> i32 { debug!("emscripten::_dlopen"); -1 } /// emscripten: dlclose(handle: *mut c_void) -> c_int -pub fn _dlclose(_ctx: &mut Ctx, _filename: u32) -> i32 { +pub fn _dlclose(_ctx: &mut EmEnv, _filename: u32) -> i32 { debug!("emscripten::_dlclose"); -1 } /// emscripten: dlsym(handle: *mut c_void, symbol: *const c_char) -> *mut c_void -pub fn _dlsym(_ctx: &mut Ctx, _filepath: u32, _symbol: u32) -> i32 { +pub fn _dlsym(_ctx: &mut EmEnv, _filepath: u32, _symbol: u32) -> i32 { debug!("emscripten::_dlsym"); -1 } /// emscripten: dlerror() -> *mut c_char -pub fn _dlerror(_ctx: &mut Ctx) -> i32 { +pub fn _dlerror(_ctx: &mut EmEnv) -> i32 { debug!("emscripten::_dlerror"); -1 } diff --git a/lib/emscripten/src/lock.rs b/lib/emscripten/src/lock.rs index f6804e9d1..6058ac8e8 100644 --- a/lib/emscripten/src/lock.rs +++ b/lib/emscripten/src/lock.rs @@ -1,22 +1,22 @@ +use crate::EmEnv; use libc::c_int; -use wasmer_runtime_core::vm::Ctx; // NOTE: Not implemented by Emscripten -pub fn ___lock(_ctx: &mut Ctx, _what: c_int) { +pub fn ___lock(_ctx: &mut EmEnv, _what: c_int) { debug!("emscripten::___lock {}", _what); } // NOTE: Not implemented by Emscripten -pub fn ___unlock(_ctx: &mut Ctx, _what: c_int) { +pub fn ___unlock(_ctx: &mut EmEnv, _what: c_int) { debug!("emscripten::___unlock {}", _what); } // NOTE: Not implemented by Emscripten -pub fn ___wait(_ctx: &mut Ctx, _which: u32, _varargs: u32, _three: u32, _four: u32) { +pub fn ___wait(_ctx: &mut EmEnv, _which: u32, _varargs: u32, _three: u32, _four: u32) { debug!("emscripten::___wait"); } -pub fn _flock(_ctx: &mut Ctx, _fd: u32, _op: u32) -> u32 { +pub fn _flock(_ctx: &mut EmEnv, _fd: u32, _op: u32) -> u32 { debug!("emscripten::_flock"); 0 } diff --git a/lib/emscripten/src/math.rs b/lib/emscripten/src/math.rs index ff9d2dc97..056075714 100644 --- a/lib/emscripten/src/math.rs +++ b/lib/emscripten/src/math.rs @@ -1,4 +1,4 @@ -use wasmer_runtime_core::vm::Ctx; +use crate::EmEnv; pub fn _llvm_copysign_f32(x: f64, y: f64) -> f64 { x.copysign(y) @@ -62,7 +62,7 @@ pub fn _llvm_fma_f64(value: f64, a: f64, b: f64) -> f64 { value.mul_add(a, b) } -pub fn _emscripten_random(_ctx: &mut Ctx) -> f64 { +pub fn _emscripten_random(_ctx: &mut EmEnv) -> f64 { debug!("emscripten::_emscripten_random"); -1.0 } diff --git a/lib/emscripten/src/memory.rs b/lib/emscripten/src/memory.rs index 0aea2c254..7c08a58fa 100644 --- a/lib/emscripten/src/memory.rs +++ b/lib/emscripten/src/memory.rs @@ -1,13 +1,12 @@ use super::env::get_emscripten_data; use super::process::abort_with_message; +use crate::EmEnv; use libc::{c_int, c_void, memcpy, size_t}; -use wasmer_runtime_core::{ - units::{Pages, WASM_MAX_PAGES, WASM_MIN_PAGES, WASM_PAGE_SIZE}, - vm::Ctx, -}; +// TODO: investigate max pages etc. probably in Wasm Common, maybe reexport +use wasmer::{Pages, WASM_MAX_PAGES, WASM_MIN_PAGES, WASM_PAGE_SIZE}; /// emscripten: _emscripten_memcpy_big -pub fn _emscripten_memcpy_big(ctx: &mut Ctx, dest: u32, src: u32, len: u32) -> u32 { +pub fn _emscripten_memcpy_big(ctx: &mut EmEnv, dest: u32, src: u32, len: u32) -> u32 { debug!( "emscripten::_emscripten_memcpy_big {}, {}, {}", dest, src, len @@ -21,7 +20,7 @@ pub fn _emscripten_memcpy_big(ctx: &mut Ctx, dest: u32, src: u32, len: u32) -> u } /// emscripten: _emscripten_get_heap_size -pub fn _emscripten_get_heap_size(ctx: &mut Ctx) -> u32 { +pub fn _emscripten_get_heap_size(ctx: &mut EmEnv) -> u32 { trace!("emscripten::_emscripten_get_heap_size"); let result = ctx.memory(0).size().bytes().0 as u32; trace!("=> {}", result); @@ -39,7 +38,7 @@ fn align_up(mut val: usize, multiple: usize) -> usize { /// emscripten: _emscripten_resize_heap /// Note: this function only allows growing the size of heap -pub fn _emscripten_resize_heap(ctx: &mut Ctx, requested_size: u32) -> u32 { +pub fn _emscripten_resize_heap(ctx: &mut EmEnv, requested_size: u32) -> u32 { debug!("emscripten::_emscripten_resize_heap {}", requested_size); let current_memory_pages = ctx.memory(0).size(); let current_memory = current_memory_pages.bytes().0 as u32; @@ -67,7 +66,7 @@ pub fn _emscripten_resize_heap(ctx: &mut Ctx, requested_size: u32) -> u32 { } /// emscripten: sbrk -pub fn sbrk(ctx: &mut Ctx, increment: i32) -> i32 { +pub fn sbrk(ctx: &mut EmEnv, increment: i32) -> i32 { debug!("emscripten::sbrk"); // let old_dynamic_top = 0; // let new_dynamic_top = 0; @@ -95,7 +94,7 @@ pub fn sbrk(ctx: &mut Ctx, increment: i32) -> i32 { } /// emscripten: getTotalMemory -pub fn get_total_memory(_ctx: &mut Ctx) -> u32 { +pub fn get_total_memory(_ctx: &mut EmEnv) -> u32 { debug!("emscripten::get_total_memory"); // instance.memories[0].current_pages() // TODO: Fix implementation @@ -103,7 +102,7 @@ pub fn get_total_memory(_ctx: &mut Ctx) -> u32 { } /// emscripten: enlargeMemory -pub fn enlarge_memory(_ctx: &mut Ctx) -> u32 { +pub fn enlarge_memory(_ctx: &mut EmEnv) -> u32 { debug!("emscripten::enlarge_memory"); // instance.memories[0].grow(100); // TODO: Fix implementation @@ -111,7 +110,7 @@ pub fn enlarge_memory(_ctx: &mut Ctx) -> u32 { } /// emscripten: abortOnCannotGrowMemory -pub fn abort_on_cannot_grow_memory(ctx: &mut Ctx, _requested_size: u32) -> u32 { +pub fn abort_on_cannot_grow_memory(ctx: &mut EmEnv, _requested_size: u32) -> u32 { debug!( "emscripten::abort_on_cannot_grow_memory {}", _requested_size @@ -121,32 +120,32 @@ pub fn abort_on_cannot_grow_memory(ctx: &mut Ctx, _requested_size: u32) -> u32 { } /// emscripten: abortOnCannotGrowMemory -pub fn abort_on_cannot_grow_memory_old(ctx: &mut Ctx) -> u32 { +pub fn abort_on_cannot_grow_memory_old(ctx: &mut EmEnv) -> u32 { debug!("emscripten::abort_on_cannot_grow_memory"); abort_with_message(ctx, "Cannot enlarge memory arrays!"); 0 } /// emscripten: segfault -pub fn segfault(ctx: &mut Ctx) { +pub fn segfault(ctx: &mut EmEnv) { debug!("emscripten::segfault"); abort_with_message(ctx, "segmentation fault"); } /// emscripten: alignfault -pub fn alignfault(ctx: &mut Ctx) { +pub fn alignfault(ctx: &mut EmEnv) { debug!("emscripten::alignfault"); abort_with_message(ctx, "alignment fault"); } /// emscripten: ftfault -pub fn ftfault(ctx: &mut Ctx) { +pub fn ftfault(ctx: &mut EmEnv) { debug!("emscripten::ftfault"); abort_with_message(ctx, "Function table mask error"); } /// emscripten: ___map_file -pub fn ___map_file(_ctx: &mut Ctx, _one: u32, _two: u32) -> c_int { +pub fn ___map_file(_ctx: &mut EmEnv, _one: u32, _two: u32) -> c_int { debug!("emscripten::___map_file"); // NOTE: TODO: Em returns -1 here as well. May need to implement properly -1 diff --git a/lib/emscripten/src/process.rs b/lib/emscripten/src/process.rs index 7592e0708..39b88d273 100644 --- a/lib/emscripten/src/process.rs +++ b/lib/emscripten/src/process.rs @@ -5,35 +5,35 @@ type PidT = libc::pid_t; #[cfg(target_os = "windows")] type PidT = c_int; -use wasmer_runtime_core::vm::Ctx; +use crate::EmEnv; -pub fn abort_with_message(ctx: &mut Ctx, message: &str) { +pub fn abort_with_message(ctx: &mut EmEnv, message: &str) { debug!("emscripten::abort_with_message"); println!("{}", message); _abort(ctx); } /// The name of this call is `abort` but we want to avoid conflicts with libc::abort -pub fn em_abort(ctx: &mut Ctx, arg: u32) { +pub fn em_abort(ctx: &mut EmEnv, arg: u32) { debug!("emscripten::abort"); eprintln!("Program aborted with value {}", arg); _abort(ctx); } -pub fn _abort(_ctx: &mut Ctx) { +pub fn _abort(_ctx: &mut EmEnv) { debug!("emscripten::_abort"); unsafe { abort(); } } -pub fn _prctl(ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { +pub fn _prctl(ctx: &mut EmEnv, _a: i32, _b: i32) -> i32 { debug!("emscripten::_prctl"); abort_with_message(ctx, "missing function: prctl"); -1 } -pub fn _fork(_ctx: &mut Ctx) -> PidT { +pub fn _fork(_ctx: &mut EmEnv) -> PidT { debug!("emscripten::_fork"); // unsafe { // fork() @@ -41,132 +41,132 @@ pub fn _fork(_ctx: &mut Ctx) -> PidT { -1 } -pub fn _endgrent(_ctx: &mut Ctx) { +pub fn _endgrent(_ctx: &mut EmEnv) { debug!("emscripten::_endgrent"); } -pub fn _execve(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 { +pub fn _execve(_ctx: &mut EmEnv, _one: i32, _two: i32, _three: i32) -> i32 { debug!("emscripten::_execve"); -1 } #[allow(unreachable_code)] -pub fn _exit(_ctx: &mut Ctx, status: c_int) { +pub fn _exit(_ctx: &mut EmEnv, status: c_int) { // -> ! debug!("emscripten::_exit {}", status); unsafe { exit(status) } } -pub fn _kill(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn _kill(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::_kill"); -1 } -pub fn _sched_yield(_ctx: &mut Ctx) -> i32 { +pub fn _sched_yield(_ctx: &mut EmEnv) -> i32 { debug!("emscripten::_sched_yield"); -1 } -pub fn _llvm_stacksave(_ctx: &mut Ctx) -> i32 { +pub fn _llvm_stacksave(_ctx: &mut EmEnv) -> i32 { debug!("emscripten::_llvm_stacksave"); -1 } -pub fn _llvm_stackrestore(_ctx: &mut Ctx, _one: i32) { +pub fn _llvm_stackrestore(_ctx: &mut EmEnv, _one: i32) { debug!("emscripten::_llvm_stackrestore"); } -pub fn _raise(_ctx: &mut Ctx, _one: i32) -> i32 { +pub fn _raise(_ctx: &mut EmEnv, _one: i32) -> i32 { debug!("emscripten::_raise"); -1 } -pub fn _sem_init(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 { +pub fn _sem_init(_ctx: &mut EmEnv, _one: i32, _two: i32, _three: i32) -> i32 { debug!("emscripten::_sem_init: {}, {}, {}", _one, _two, _three); 0 } -pub fn _sem_destroy(_ctx: &mut Ctx, _one: i32) -> i32 { +pub fn _sem_destroy(_ctx: &mut EmEnv, _one: i32) -> i32 { debug!("emscripten::_sem_destroy"); 0 } -pub fn _sem_post(_ctx: &mut Ctx, _one: i32) -> i32 { +pub fn _sem_post(_ctx: &mut EmEnv, _one: i32) -> i32 { debug!("emscripten::_sem_post"); -1 } -pub fn _sem_wait(_ctx: &mut Ctx, _one: i32) -> i32 { +pub fn _sem_wait(_ctx: &mut EmEnv, _one: i32) -> i32 { debug!("emscripten::_sem_post"); -1 } #[allow(clippy::cast_ptr_alignment)] -pub fn _getgrent(_ctx: &mut Ctx) -> c_int { +pub fn _getgrent(_ctx: &mut EmEnv) -> c_int { debug!("emscripten::_getgrent"); -1 } -pub fn _setgrent(_ctx: &mut Ctx) { +pub fn _setgrent(_ctx: &mut EmEnv) { debug!("emscripten::_setgrent"); } -pub fn _setgroups(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn _setgroups(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::_setgroups"); -1 } -pub fn _setitimer(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 { +pub fn _setitimer(_ctx: &mut EmEnv, _one: i32, _two: i32, _three: i32) -> i32 { debug!("emscripten::_setitimer"); -1 } -pub fn _usleep(_ctx: &mut Ctx, _one: i32) -> i32 { +pub fn _usleep(_ctx: &mut EmEnv, _one: i32) -> i32 { debug!("emscripten::_usleep"); -1 } -pub fn _nanosleep(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn _nanosleep(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::_nanosleep"); -1 } -pub fn _utime(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn _utime(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::_utime"); -1 } -pub fn _utimes(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn _utimes(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::_utimes"); -1 } -pub fn _wait(_ctx: &mut Ctx, _one: i32) -> i32 { +pub fn _wait(_ctx: &mut EmEnv, _one: i32) -> i32 { debug!("emscripten::_wait"); -1 } -pub fn _wait3(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 { +pub fn _wait3(_ctx: &mut EmEnv, _one: i32, _two: i32, _three: i32) -> i32 { debug!("emscripten::_wait3"); -1 } -pub fn _wait4(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32, _d: i32) -> i32 { +pub fn _wait4(_ctx: &mut EmEnv, _one: i32, _two: i32, _three: i32, _d: i32) -> i32 { debug!("emscripten::_wait4"); -1 } -pub fn _waitid(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32, _d: i32) -> i32 { +pub fn _waitid(_ctx: &mut EmEnv, _one: i32, _two: i32, _three: i32, _d: i32) -> i32 { debug!("emscripten::_waitid"); -1 } -pub fn _waitpid(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 { +pub fn _waitpid(_ctx: &mut EmEnv, _one: i32, _two: i32, _three: i32) -> i32 { debug!("emscripten::_waitpid"); -1 } -pub fn abort_stack_overflow(ctx: &mut Ctx, _what: c_int) { +pub fn abort_stack_overflow(ctx: &mut EmEnv, _what: c_int) { debug!("emscripten::abort_stack_overflow"); // TODO: Message incomplete. Need to finish em runtime data first abort_with_message( @@ -175,24 +175,24 @@ pub fn abort_stack_overflow(ctx: &mut Ctx, _what: c_int) { ); } -pub fn _llvm_trap(ctx: &mut Ctx) { +pub fn _llvm_trap(ctx: &mut EmEnv) { debug!("emscripten::_llvm_trap"); abort_with_message(ctx, "abort!"); } -pub fn _llvm_eh_typeid_for(_ctx: &mut Ctx, _type_info_addr: u32) -> i32 { +pub fn _llvm_eh_typeid_for(_ctx: &mut EmEnv, _type_info_addr: u32) -> i32 { debug!("emscripten::_llvm_eh_typeid_for"); -1 } -pub fn _system(_ctx: &mut Ctx, _one: i32) -> c_int { +pub fn _system(_ctx: &mut EmEnv, _one: i32) -> c_int { debug!("emscripten::_system"); // TODO: May need to change this Em impl to a working version eprintln!("Can't call external programs"); EAGAIN } -pub fn _popen(_ctx: &mut Ctx, _one: i32, _two: i32) -> c_int { +pub fn _popen(_ctx: &mut EmEnv, _one: i32, _two: i32) -> c_int { debug!("emscripten::_popen"); // TODO: May need to change this Em impl to a working version eprintln!("Missing function: popen"); diff --git a/lib/emscripten/src/pthread.rs b/lib/emscripten/src/pthread.rs index ac7e70838..6e5ae66b2 100644 --- a/lib/emscripten/src/pthread.rs +++ b/lib/emscripten/src/pthread.rs @@ -1,12 +1,12 @@ -use wasmer_runtime_core::vm::Ctx; +use crate::EmEnv; -pub fn _pthread_attr_destroy(_ctx: &mut Ctx, _a: i32) -> i32 { +pub fn _pthread_attr_destroy(_ctx: &mut EmEnv, _a: i32) -> i32 { trace!("emscripten::_pthread_attr_destroy"); 0 } pub fn _pthread_attr_getstack( - _ctx: &mut Ctx, + _ctx: &mut EmEnv, _stackaddr: i32, _stacksize: i32, _other: i32, @@ -23,175 +23,175 @@ pub fn _pthread_attr_getstack( 0 } -pub fn _pthread_attr_init(_ctx: &mut Ctx, _a: i32) -> i32 { +pub fn _pthread_attr_init(_ctx: &mut EmEnv, _a: i32) -> i32 { trace!("emscripten::_pthread_attr_init({})", _a); 0 } -pub fn _pthread_attr_setstacksize(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { +pub fn _pthread_attr_setstacksize(_ctx: &mut EmEnv, _a: i32, _b: i32) -> i32 { trace!("emscripten::_pthread_attr_setstacksize"); 0 } -pub fn _pthread_cleanup_pop(_ctx: &mut Ctx, _a: i32) -> () { +pub fn _pthread_cleanup_pop(_ctx: &mut EmEnv, _a: i32) -> () { trace!("emscripten::_pthread_cleanup_pop"); } -pub fn _pthread_cleanup_push(_ctx: &mut Ctx, _a: i32, _b: i32) -> () { +pub fn _pthread_cleanup_push(_ctx: &mut EmEnv, _a: i32, _b: i32) -> () { trace!("emscripten::_pthread_cleanup_push"); } -pub fn _pthread_cond_destroy(_ctx: &mut Ctx, _a: i32) -> i32 { +pub fn _pthread_cond_destroy(_ctx: &mut EmEnv, _a: i32) -> i32 { trace!("emscripten::_pthread_cond_destroy"); 0 } -pub fn _pthread_cond_init(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { +pub fn _pthread_cond_init(_ctx: &mut EmEnv, _a: i32, _b: i32) -> i32 { trace!("emscripten::_pthread_cond_init"); 0 } -pub fn _pthread_cond_signal(_ctx: &mut Ctx, _a: i32) -> i32 { +pub fn _pthread_cond_signal(_ctx: &mut EmEnv, _a: i32) -> i32 { trace!("emscripten::_pthread_cond_signal"); 0 } -pub fn _pthread_cond_timedwait(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32) -> i32 { +pub fn _pthread_cond_timedwait(_ctx: &mut EmEnv, _a: i32, _b: i32, _c: i32) -> i32 { trace!("emscripten::_pthread_cond_timedwait"); 0 } -pub fn _pthread_cond_wait(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { +pub fn _pthread_cond_wait(_ctx: &mut EmEnv, _a: i32, _b: i32) -> i32 { trace!("emscripten::_pthread_cond_wait"); 0 } -pub fn _pthread_condattr_destroy(_ctx: &mut Ctx, _a: i32) -> i32 { +pub fn _pthread_condattr_destroy(_ctx: &mut EmEnv, _a: i32) -> i32 { trace!("emscripten::_pthread_condattr_destroy"); 0 } -pub fn _pthread_condattr_init(_ctx: &mut Ctx, _a: i32) -> i32 { +pub fn _pthread_condattr_init(_ctx: &mut EmEnv, _a: i32) -> i32 { trace!("emscripten::_pthread_condattr_init"); 0 } -pub fn _pthread_condattr_setclock(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { +pub fn _pthread_condattr_setclock(_ctx: &mut EmEnv, _a: i32, _b: i32) -> i32 { trace!("emscripten::_pthread_condattr_setclock"); 0 } -pub fn _pthread_create(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32, _d: i32) -> i32 { +pub fn _pthread_create(_ctx: &mut EmEnv, _a: i32, _b: i32, _c: i32, _d: i32) -> i32 { trace!("emscripten::_pthread_create"); // 11 seems to mean "no" 11 } -pub fn _pthread_detach(_ctx: &mut Ctx, _a: i32) -> i32 { +pub fn _pthread_detach(_ctx: &mut EmEnv, _a: i32) -> i32 { trace!("emscripten::_pthread_detach"); 0 } -pub fn _pthread_equal(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { +pub fn _pthread_equal(_ctx: &mut EmEnv, _a: i32, _b: i32) -> i32 { trace!("emscripten::_pthread_equal"); 0 } -pub fn _pthread_exit(_ctx: &mut Ctx, _a: i32) -> () { +pub fn _pthread_exit(_ctx: &mut EmEnv, _a: i32) -> () { trace!("emscripten::_pthread_exit"); } -pub fn _pthread_getattr_np(_ctx: &mut Ctx, _thread: i32, _attr: i32) -> i32 { +pub fn _pthread_getattr_np(_ctx: &mut EmEnv, _thread: i32, _attr: i32) -> i32 { trace!("emscripten::_pthread_getattr_np({}, {})", _thread, _attr); 0 } -pub fn _pthread_getspecific(_ctx: &mut Ctx, _a: i32) -> i32 { +pub fn _pthread_getspecific(_ctx: &mut EmEnv, _a: i32) -> i32 { trace!("emscripten::_pthread_getspecific"); 0 } -pub fn _pthread_join(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { +pub fn _pthread_join(_ctx: &mut EmEnv, _a: i32, _b: i32) -> i32 { trace!("emscripten::_pthread_join"); 0 } -pub fn _pthread_self(_ctx: &mut Ctx) -> i32 { +pub fn _pthread_self(_ctx: &mut EmEnv) -> i32 { trace!("emscripten::_pthread_self"); 0 } -pub fn _pthread_key_create(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { +pub fn _pthread_key_create(_ctx: &mut EmEnv, _a: i32, _b: i32) -> i32 { trace!("emscripten::_pthread_key_create"); 0 } -pub fn _pthread_mutex_destroy(_ctx: &mut Ctx, _a: i32) -> i32 { +pub fn _pthread_mutex_destroy(_ctx: &mut EmEnv, _a: i32) -> i32 { trace!("emscripten::_pthread_mutex_destroy"); 0 } -pub fn _pthread_mutex_init(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { +pub fn _pthread_mutex_init(_ctx: &mut EmEnv, _a: i32, _b: i32) -> i32 { trace!("emscripten::_pthread_mutex_init"); 0 } -pub fn _pthread_mutexattr_destroy(_ctx: &mut Ctx, _a: i32) -> i32 { +pub fn _pthread_mutexattr_destroy(_ctx: &mut EmEnv, _a: i32) -> i32 { trace!("emscripten::_pthread_mutexattr_destroy"); 0 } -pub fn _pthread_mutexattr_init(_ctx: &mut Ctx, _a: i32) -> i32 { +pub fn _pthread_mutexattr_init(_ctx: &mut EmEnv, _a: i32) -> i32 { trace!("emscripten::_pthread_mutexattr_init"); 0 } -pub fn _pthread_mutexattr_settype(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { +pub fn _pthread_mutexattr_settype(_ctx: &mut EmEnv, _a: i32, _b: i32) -> i32 { trace!("emscripten::_pthread_mutexattr_settype"); 0 } -pub fn _pthread_once(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { +pub fn _pthread_once(_ctx: &mut EmEnv, _a: i32, _b: i32) -> i32 { trace!("emscripten::_pthread_once"); 0 } -pub fn _pthread_rwlock_destroy(_ctx: &mut Ctx, _rwlock: i32) -> i32 { +pub fn _pthread_rwlock_destroy(_ctx: &mut EmEnv, _rwlock: i32) -> i32 { trace!("emscripten::_pthread_rwlock_destroy({})", _rwlock); 0 } -pub fn _pthread_rwlock_init(_ctx: &mut Ctx, _rwlock: i32, _attr: i32) -> i32 { +pub fn _pthread_rwlock_init(_ctx: &mut EmEnv, _rwlock: i32, _attr: i32) -> i32 { trace!("emscripten::_pthread_rwlock_init({}, {})", _rwlock, _attr); 0 } -pub fn _pthread_rwlock_rdlock(_ctx: &mut Ctx, _a: i32) -> i32 { +pub fn _pthread_rwlock_rdlock(_ctx: &mut EmEnv, _a: i32) -> i32 { trace!("emscripten::_pthread_rwlock_rdlock"); 0 } -pub fn _pthread_rwlock_unlock(_ctx: &mut Ctx, _a: i32) -> i32 { +pub fn _pthread_rwlock_unlock(_ctx: &mut EmEnv, _a: i32) -> i32 { trace!("emscripten::_pthread_rwlock_unlock"); 0 } -pub fn _pthread_rwlock_wrlock(_ctx: &mut Ctx, _rwlock: i32) -> i32 { +pub fn _pthread_rwlock_wrlock(_ctx: &mut EmEnv, _rwlock: i32) -> i32 { trace!("emscripten::_pthread_rwlock_wrlock({})", _rwlock); 0 } -pub fn _pthread_setcancelstate(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { +pub fn _pthread_setcancelstate(_ctx: &mut EmEnv, _a: i32, _b: i32) -> i32 { trace!("emscripten::_pthread_setcancelstate"); 0 } -pub fn _pthread_setspecific(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { +pub fn _pthread_setspecific(_ctx: &mut EmEnv, _a: i32, _b: i32) -> i32 { trace!("emscripten::_pthread_setspecific"); 0 } -pub fn _pthread_sigmask(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32) -> i32 { +pub fn _pthread_sigmask(_ctx: &mut EmEnv, _a: i32, _b: i32, _c: i32) -> i32 { trace!("emscripten::_pthread_sigmask"); 0 } diff --git a/lib/emscripten/src/ptr.rs b/lib/emscripten/src/ptr.rs index 34cd68364..727b3541c 100644 --- a/lib/emscripten/src/ptr.rs +++ b/lib/emscripten/src/ptr.rs @@ -6,14 +6,10 @@ #![allow(dead_code)] use std::{cell::Cell, fmt}; -pub use wasmer_runtime_core::memory::ptr::Array; -use wasmer_runtime_core::{ - memory::{ptr, Memory}, - types::{ValueType, WasmExternType}, -}; +pub use wasmer::{Array, Memory, ValueType, WasmExternType}; #[repr(transparent)] -pub struct WasmPtr(ptr::WasmPtr); +pub struct WasmPtr(wasmer::WasmPtr); unsafe impl ValueType for WasmPtr {} impl Copy for WasmPtr {} @@ -31,13 +27,13 @@ impl fmt::Debug for WasmPtr { } unsafe impl WasmExternType for WasmPtr { - type Native = as WasmExternType>::Native; + type Native = as WasmExternType>::Native; fn to_native(self) -> Self::Native { self.0.to_native() } fn from_native(n: Self::Native) -> Self { - Self(ptr::WasmPtr::from_native(n)) + Self(wasmer::WasmPtr::from_native(n)) } } @@ -52,7 +48,7 @@ impl Eq for WasmPtr {} impl WasmPtr { #[inline(always)] pub fn new(offset: u32) -> Self { - Self(ptr::WasmPtr::new(offset)) + Self(wasmer::WasmPtr::new(offset)) } #[inline(always)] @@ -61,7 +57,7 @@ impl WasmPtr { } } -impl WasmPtr { +impl WasmPtr { #[inline(always)] pub fn deref<'a>(self, memory: &'a Memory) -> Option<&'a Cell> { if self.0.offset() == 0 { @@ -81,7 +77,7 @@ impl WasmPtr { } } -impl WasmPtr { +impl WasmPtr { #[inline(always)] pub fn deref<'a>(self, memory: &'a Memory, index: u32, length: u32) -> Option<&'a [Cell]> { if self.0.offset() == 0 { diff --git a/lib/emscripten/src/signal.rs b/lib/emscripten/src/signal.rs index 9b17cd8b4..16d365860 100644 --- a/lib/emscripten/src/signal.rs +++ b/lib/emscripten/src/signal.rs @@ -1,8 +1,8 @@ // use super::varargs::VarArgs; -use wasmer_runtime_core::vm::Ctx; +use crate::EmEnv; #[allow(clippy::cast_ptr_alignment)] -pub fn _sigemptyset(ctx: &mut Ctx, set: u32) -> i32 { +pub fn _sigemptyset(ctx: &mut EmEnv, set: u32) -> i32 { debug!("emscripten::_sigemptyset"); let set_addr = emscripten_memory_pointer!(ctx.memory(0), set) as *mut u32; unsafe { @@ -11,18 +11,18 @@ pub fn _sigemptyset(ctx: &mut Ctx, set: u32) -> i32 { 0 } -pub fn _sigaction(_ctx: &mut Ctx, _signum: u32, _act: u32, _oldact: u32) -> i32 { +pub fn _sigaction(_ctx: &mut EmEnv, _signum: u32, _act: u32, _oldact: u32) -> i32 { debug!("emscripten::_sigaction {}, {}, {}", _signum, _act, _oldact); 0 } -pub fn _siginterrupt(_ctx: &mut Ctx, _a: u32, _b: u32) -> i32 { +pub fn _siginterrupt(_ctx: &mut EmEnv, _a: u32, _b: u32) -> i32 { debug!("emscripten::_siginterrupt {}, {}", _a, _b); 0 } #[allow(clippy::cast_ptr_alignment)] -pub fn _sigaddset(ctx: &mut Ctx, set: u32, signum: u32) -> i32 { +pub fn _sigaddset(ctx: &mut EmEnv, set: u32, signum: u32) -> i32 { debug!("emscripten::_sigaddset {}, {}", set, signum); let set_addr = emscripten_memory_pointer!(ctx.memory(0), set) as *mut u32; unsafe { @@ -31,17 +31,17 @@ pub fn _sigaddset(ctx: &mut Ctx, set: u32, signum: u32) -> i32 { 0 } -pub fn _sigsuspend(_ctx: &mut Ctx, _one: i32) -> i32 { +pub fn _sigsuspend(_ctx: &mut EmEnv, _one: i32) -> i32 { debug!("emscripten::_sigsuspend"); -1 } -pub fn _sigprocmask(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 { +pub fn _sigprocmask(_ctx: &mut EmEnv, _one: i32, _two: i32, _three: i32) -> i32 { debug!("emscripten::_sigprocmask"); 0 } -pub fn _signal(_ctx: &mut Ctx, _sig: u32, _two: i32) -> i32 { +pub fn _signal(_ctx: &mut EmEnv, _sig: u32, _two: i32) -> i32 { debug!("emscripten::_signal ({})", _sig); 0 } diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index ba5965fde..dc1b4d2f3 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -13,6 +13,7 @@ pub use self::windows::*; use crate::{ ptr::{Array, WasmPtr}, utils::{copy_stat_into_wasm, get_cstr_path, get_current_directory}, + EmEnv, }; use super::varargs::VarArgs; @@ -43,7 +44,6 @@ use libc::{ write, // ENOTTY, }; -use wasmer_runtime_core::vm::Ctx; use super::env; use std::cell::Cell; @@ -52,7 +52,7 @@ use std::io::Error; use std::slice; /// exit -pub fn ___syscall1(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) { +pub fn ___syscall1(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) { debug!("emscripten::___syscall1 (exit) {}", _which); let status: i32 = varargs.get(ctx); unsafe { @@ -61,7 +61,7 @@ pub fn ___syscall1(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) { } /// read -pub fn ___syscall3(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { +pub fn ___syscall3(ctx: &mut EmEnv, _which: i32, mut varargs: VarArgs) -> i32 { // -> ssize_t debug!("emscripten::___syscall3 (read) {}", _which); let fd: i32 = varargs.get(ctx); @@ -75,7 +75,7 @@ pub fn ___syscall3(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { } /// write -pub fn ___syscall4(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall4(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall4 (write) {}", _which); let fd: i32 = varargs.get(ctx); let buf: i32 = varargs.get(ctx); @@ -86,7 +86,7 @@ pub fn ___syscall4(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int } /// close -pub fn ___syscall6(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall6(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall6 (close) {}", _which); let fd: i32 = varargs.get(ctx); debug!("fd: {}", fd); @@ -94,7 +94,7 @@ pub fn ___syscall6(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int } // chdir -pub fn ___syscall12(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall12(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall12 (chdir) {}", _which); let path_ptr = varargs.get_str(ctx); let real_path_owned = get_cstr_path(ctx, path_ptr as *const _); @@ -112,59 +112,59 @@ pub fn ___syscall12(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int ret } -pub fn ___syscall10(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall10(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall10"); -1 } -pub fn ___syscall14(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall14(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall14"); -1 } -pub fn ___syscall15(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall15(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall15"); -1 } // getpid -pub fn ___syscall20(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall20(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall20 (getpid)"); unsafe { getpid() } } -pub fn ___syscall21(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall21(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall21"); -1 } -pub fn ___syscall25(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall25(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall25"); -1 } -pub fn ___syscall29(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall29(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall29"); -1 } -pub fn ___syscall32(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall32(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall32"); -1 } -pub fn ___syscall33(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall33(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall33"); -1 } -pub fn ___syscall36(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall36(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall36"); -1 } // rename -pub fn ___syscall38(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> i32 { +pub fn ___syscall38(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> i32 { debug!("emscripten::___syscall38 (rename)"); let old_path = varargs.get_str(ctx); let new_path = varargs.get_str(ctx); @@ -191,7 +191,7 @@ pub fn ___syscall38(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> i32 { } // rmdir -pub fn ___syscall40(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall40(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall40 (rmdir)"); let pathname_addr = varargs.get_str(ctx); let real_path_owned = get_cstr_path(ctx, pathname_addr as *const _); @@ -204,7 +204,7 @@ pub fn ___syscall40(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int } // pipe -pub fn ___syscall42(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall42(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall42 (pipe)"); // offset to a file descriptor, which contains a read end and write end, 2 integers let fd_offset: u32 = varargs.get(ctx); @@ -232,28 +232,28 @@ pub fn ___syscall42(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int result } -pub fn ___syscall51(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall51(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall51"); -1 } -pub fn ___syscall52(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall52(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall52"); -1 } -pub fn ___syscall53(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall53(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall53"); -1 } -pub fn ___syscall60(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall60(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall60"); -1 } // dup2 -pub fn ___syscall63(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall63(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall63 (dup2) {}", _which); let src: i32 = varargs.get(ctx); @@ -263,93 +263,93 @@ pub fn ___syscall63(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int } // getppid -pub fn ___syscall64(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall64(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall64 (getppid)"); unsafe { getpid() } } -pub fn ___syscall66(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall66(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall66"); -1 } -pub fn ___syscall75(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall75(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall75"); -1 } -pub fn ___syscall91(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall91(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall91 - stub"); 0 } -pub fn ___syscall96(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall96(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall96"); -1 } -pub fn ___syscall97(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall97(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall97"); -1 } -pub fn ___syscall110(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall110(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall110"); -1 } -pub fn ___syscall121(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall121(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall121"); -1 } -pub fn ___syscall125(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall125(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall125"); -1 } -pub fn ___syscall133(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall133(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall133"); -1 } -pub fn ___syscall144(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall144(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall144"); -1 } -pub fn ___syscall147(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall147(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall147"); -1 } -pub fn ___syscall150(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall150(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall150"); -1 } -pub fn ___syscall151(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall151(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall151"); -1 } -pub fn ___syscall152(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall152(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall152"); -1 } -pub fn ___syscall153(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall153(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall153"); -1 } -pub fn ___syscall163(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall163(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall163"); -1 } // getcwd -pub fn ___syscall183(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> i32 { +pub fn ___syscall183(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> i32 { debug!("emscripten::___syscall183"); let buf_offset: WasmPtr = varargs.get(ctx); let _size: c_int = varargs.get(ctx); @@ -366,7 +366,7 @@ pub fn ___syscall183(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> i32 } // mmap2 -pub fn ___syscall192(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall192(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall192 (mmap2) {}", _which); let _addr: i32 = varargs.get(ctx); let len: u32 = varargs.get(ctx); @@ -401,7 +401,7 @@ pub fn ___syscall192(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in } /// lseek -pub fn ___syscall140(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { +pub fn ___syscall140(ctx: &mut EmEnv, _which: i32, mut varargs: VarArgs) -> i32 { // -> c_int debug!("emscripten::___syscall140 (lseek) {}", _which); let fd: i32 = varargs.get(ctx); @@ -429,7 +429,7 @@ pub fn ___syscall140(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { /// readv #[allow(clippy::cast_ptr_alignment)] -pub fn ___syscall145(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> i32 { +pub fn ___syscall145(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> i32 { // -> ssize_t debug!("emscripten::___syscall145 (readv) {}", _which); @@ -466,7 +466,7 @@ pub fn ___syscall145(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> i32 // writev #[allow(clippy::cast_ptr_alignment)] -pub fn ___syscall146(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { +pub fn ___syscall146(ctx: &mut EmEnv, _which: i32, mut varargs: VarArgs) -> i32 { // -> ssize_t debug!("emscripten::___syscall146 (writev) {}", _which); let fd: i32 = varargs.get(ctx); @@ -507,7 +507,7 @@ pub fn ___syscall146(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { ret as _ } -pub fn ___syscall191(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { +pub fn ___syscall191(ctx: &mut EmEnv, _which: i32, mut varargs: VarArgs) -> i32 { let _resource: i32 = varargs.get(ctx); debug!( "emscripten::___syscall191 - mostly stub, resource: {}", @@ -524,13 +524,13 @@ pub fn ___syscall191(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { 0 } -pub fn ___syscall193(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall193(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall193"); -1 } // stat64 -pub fn ___syscall195(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall195(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall195 (stat64) {}", _which); let pathname_addr = varargs.get_str(ctx); let buf: u32 = varargs.get(ctx); @@ -561,7 +561,7 @@ pub fn ___syscall195(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in } // fstat64 -pub fn ___syscall197(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall197(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall197 (fstat64) {}", _which); let fd: c_int = varargs.get(ctx); @@ -580,129 +580,129 @@ pub fn ___syscall197(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in 0 } -pub fn ___syscall209(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall209(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall209"); -1 } -pub fn ___syscall211(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall211(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall211"); -1 } -pub fn ___syscall218(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall218(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall218"); -1 } -pub fn ___syscall268(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall268(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall268"); -1 } -pub fn ___syscall269(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall269(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall269"); -1 } -pub fn ___syscall272(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall272(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall272"); -1 } -pub fn ___syscall295(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall295(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall295"); -1 } -pub fn ___syscall296(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall296(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall296"); -1 } -pub fn ___syscall297(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall297(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall297"); -1 } -pub fn ___syscall298(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall298(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall298"); -1 } -pub fn ___syscall300(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall300(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall300"); -1 } -pub fn ___syscall301(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall301(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall301"); -1 } -pub fn ___syscall302(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall302(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall302"); -1 } -pub fn ___syscall303(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall303(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall303"); -1 } -pub fn ___syscall304(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall304(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall304"); -1 } -pub fn ___syscall305(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall305(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall305"); -1 } -pub fn ___syscall306(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall306(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall306"); -1 } -pub fn ___syscall307(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall307(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall307"); -1 } -pub fn ___syscall308(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall308(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall308"); -1 } // utimensat -pub fn ___syscall320(_ctx: &mut Ctx, _which: c_int, mut _varargs: VarArgs) -> c_int { +pub fn ___syscall320(_ctx: &mut EmEnv, _which: c_int, mut _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall320 (utimensat), {}", _which); 0 } -pub fn ___syscall331(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall331(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall331"); -1 } -pub fn ___syscall333(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall333(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall333"); -1 } -pub fn ___syscall334(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall334(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall334"); -1 } -pub fn ___syscall337(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall337(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall337"); -1 } // prlimit64 -pub fn ___syscall340(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall340(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall340 (prlimit64), {}", _which); // NOTE: Doesn't really matter. Wasm modules cannot exceed WASM_PAGE_SIZE anyway. let _pid: i32 = varargs.get(ctx); @@ -728,7 +728,7 @@ pub fn ___syscall340(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in 0 } -pub fn ___syscall345(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall345(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall345"); -1 } diff --git a/lib/emscripten/src/syscalls/unix.rs b/lib/emscripten/src/syscalls/unix.rs index d9ea55858..357d4d465 100644 --- a/lib/emscripten/src/syscalls/unix.rs +++ b/lib/emscripten/src/syscalls/unix.rs @@ -112,10 +112,10 @@ fn translate_ioctl(wasm_ioctl: u32) -> c_ulong { #[allow(unused_imports)] use std::ffi::CStr; -use wasmer_runtime_core::vm::Ctx; use crate::env::EmSockAddr; use crate::utils::{self, get_cstr_path}; +use crate::EmEnv; #[allow(unused_imports)] use std::io::Error; use std::mem; @@ -156,7 +156,7 @@ use libc::SO_NOSIGPIPE; const SO_NOSIGPIPE: c_int = 0; /// open -pub fn ___syscall5(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall5(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall5 (open) {}", _which); let pathname_addr = varargs.get_str(ctx); let flags: i32 = varargs.get(ctx); @@ -180,7 +180,7 @@ pub fn ___syscall5(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int } /// link -pub fn ___syscall9(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall9(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall9 (link) {}", _which); let oldname_ptr = varargs.get_str(ctx); @@ -196,7 +196,7 @@ pub fn ___syscall9(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int } /// getrusage -pub fn ___syscall77(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall77(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall77 (getrusage) {}", _which); let resource: c_int = varargs.get(ctx); @@ -208,7 +208,7 @@ pub fn ___syscall77(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int } /// symlink -pub fn ___syscall83(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall83(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall83 (symlink) {}", _which); let path1 = varargs.get_str(ctx); @@ -236,7 +236,7 @@ pub fn ___syscall83(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int } /// readlink -pub fn ___syscall85(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> i32 { +pub fn ___syscall85(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> i32 { debug!("emscripten::___syscall85 (readlink)"); let pathname_addr = varargs.get_str(ctx); let buf = varargs.get_str(ctx); @@ -265,7 +265,7 @@ pub fn ___syscall85(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> i32 { } /// ftruncate64 -pub fn ___syscall194(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall194(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall194 (ftruncate64) {}", _which); let _fd: c_int = varargs.get(ctx); let _length: i64 = varargs.get(ctx); @@ -282,7 +282,7 @@ pub fn ___syscall194(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in } /// lchown -pub fn ___syscall198(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall198(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall198 (lchown) {}", _which); let path_ptr = varargs.get_str(ctx); let real_path_owned = utils::get_cstr_path(ctx, path_ptr as *const _); @@ -305,7 +305,7 @@ pub fn ___syscall198(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in } /// getgroups -pub fn ___syscall205(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall205(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall205 (getgroups) {}", _which); let ngroups_max: c_int = varargs.get(ctx); let groups: c_int = varargs.get(ctx); @@ -322,7 +322,7 @@ pub fn ___syscall205(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in } // chown -pub fn ___syscall212(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall212(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall212 (chown) {}", _which); let pathname_addr = varargs.get_str(ctx); @@ -339,7 +339,7 @@ pub fn ___syscall212(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in } /// madvise -pub fn ___syscall219(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall219(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall212 (chown) {}", _which); let addr_ptr: c_int = varargs.get(ctx); @@ -352,7 +352,7 @@ pub fn ___syscall219(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in } /// access -pub fn ___syscall33(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall33(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall33 (access) {}", _which); let path = varargs.get_str(ctx); let real_path_owned = utils::get_cstr_path(ctx, path as *const _); @@ -373,14 +373,14 @@ pub fn ___syscall33(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int } /// nice -pub fn ___syscall34(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall34(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall34 (nice) {}", _which); let inc_r: c_int = varargs.get(ctx); unsafe { nice(inc_r) } } // mkdir -pub fn ___syscall39(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall39(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall39 (mkdir) {}", _which); let pathname_addr = varargs.get_str(ctx); let real_path_owned = utils::get_cstr_path(ctx, pathname_addr as *const _); @@ -394,20 +394,20 @@ pub fn ___syscall39(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int } /// dup -pub fn ___syscall41(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall41(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall41 (dup) {}", _which); let fd: c_int = varargs.get(ctx); unsafe { dup(fd) } } /// getgid32 -pub fn ___syscall200(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall200(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall200 (getgid32)"); unsafe { getgid() as i32 } } // geteuid32 -pub fn ___syscall201(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall201(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall201 (geteuid32)"); unsafe { // Maybe fix: Emscripten returns 0 always @@ -416,7 +416,7 @@ pub fn ___syscall201(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { } // getegid32 -pub fn ___syscall202(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall202(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { // gid_t debug!("emscripten::___syscall202 (getegid32)"); unsafe { @@ -426,7 +426,7 @@ pub fn ___syscall202(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { } /// fchown -pub fn ___syscall207(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall207(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall207 (fchown) {}", _which); let fd: c_int = varargs.get(ctx); let owner: uid_t = varargs.get(ctx); @@ -435,7 +435,7 @@ pub fn ___syscall207(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in } /// dup3 -pub fn ___syscall330(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> pid_t { +pub fn ___syscall330(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> pid_t { // Implementation based on description at https://linux.die.net/man/2/dup3 debug!("emscripten::___syscall330 (dup3)"); let oldfd: c_int = varargs.get(ctx); @@ -469,7 +469,7 @@ pub fn ___syscall330(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> pid_ } /// ioctl -pub fn ___syscall54(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall54(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall54 (ioctl) {}", _which); let fd: i32 = varargs.get(ctx); @@ -511,7 +511,7 @@ const SOCK_CLOEXC: i32 = 0x80000; // socketcall #[allow(clippy::cast_ptr_alignment)] -pub fn ___syscall102(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall102(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall102 (socketcall) {}", _which); let call: u32 = varargs.get(ctx); let mut socket_varargs: VarArgs = varargs.get(ctx); @@ -829,7 +829,7 @@ fn translate_socket_name_flag(name: i32) -> i32 { } /// getpgid -pub fn ___syscall132(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall132(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall132 (getpgid)"); let pid: pid_t = varargs.get(ctx); @@ -850,10 +850,10 @@ pub struct EmPollFd { pub revents: i16, } -unsafe impl wasmer_runtime_core::types::ValueType for EmPollFd {} +unsafe impl wasmer::ValueType for EmPollFd {} /// poll -pub fn ___syscall168(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { +pub fn ___syscall168(ctx: &mut EmEnv, _which: i32, mut varargs: VarArgs) -> i32 { debug!("emscripten::___syscall168(poll)"); let fds: WasmPtr = varargs.get(ctx); let nfds: u32 = varargs.get(ctx); @@ -873,7 +873,7 @@ pub fn ___syscall168(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { } // pread -pub fn ___syscall180(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall180(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall180 (pread) {}", _which); let fd: i32 = varargs.get(ctx); let buf: u32 = varargs.get(ctx); @@ -890,7 +890,7 @@ pub fn ___syscall180(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in } // pwrite -pub fn ___syscall181(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall181(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall181 (pwrite) {}", _which); let fd: i32 = varargs.get(ctx); let buf: u32 = varargs.get(ctx); @@ -911,7 +911,7 @@ pub fn ___syscall181(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in } /// fchmod -pub fn ___syscall94(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall94(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall118 (fchmod) {}", _which); let fd: c_int = varargs.get(ctx); let mode: mode_t = varargs.get(ctx); @@ -920,7 +920,7 @@ pub fn ___syscall94(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int /// wait4 #[allow(clippy::cast_ptr_alignment)] -pub fn ___syscall114(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> pid_t { +pub fn ___syscall114(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> pid_t { debug!("emscripten::___syscall114 (wait4)"); let pid: pid_t = varargs.get(ctx); let status: u32 = varargs.get(ctx); @@ -938,7 +938,7 @@ pub fn ___syscall114(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> pid_ } /// fsync -pub fn ___syscall118(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall118(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall118 (fsync) {}", _which); let fd: c_int = varargs.get(ctx); unsafe { fsync(fd) } @@ -946,7 +946,7 @@ pub fn ___syscall118(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in // select #[allow(clippy::cast_ptr_alignment)] -pub fn ___syscall142(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall142(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall142 (newselect) {}", _which); let nfds: i32 = varargs.get(ctx); @@ -968,7 +968,7 @@ pub fn ___syscall142(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in } /// fdatasync -pub fn ___syscall148(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall148(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall148 (fdatasync) {}", _which); let fd: i32 = varargs.get(ctx); @@ -977,7 +977,7 @@ pub fn ___syscall148(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in } // setpgid -pub fn ___syscall57(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall57(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall57 (setpgid) {}", _which); let pid: i32 = varargs.get(ctx); @@ -993,7 +993,7 @@ pub fn ___syscall57(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int /// uname // NOTE: Wondering if we should return custom utsname, like Emscripten. -pub fn ___syscall122(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall122(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall122 (uname) {}", _which); let buf: u32 = varargs.get(ctx); debug!("=> buf: {}", buf); @@ -1002,7 +1002,7 @@ pub fn ___syscall122(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in } /// lstat64 -pub fn ___syscall196(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { +pub fn ___syscall196(ctx: &mut EmEnv, _which: i32, mut varargs: VarArgs) -> i32 { debug!("emscripten::___syscall196 (lstat64) {}", _which); let path = varargs.get_str(ctx); let real_path_owned = utils::get_cstr_path(ctx, path as *const _); @@ -1035,7 +1035,7 @@ pub fn ___syscall196(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { } // getuid -pub fn ___syscall199(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall199(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall199 (getuid)"); let uid = unsafe { getuid() as _ }; debug!(" => {}", uid); @@ -1045,7 +1045,7 @@ pub fn ___syscall199(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { // getdents // dirent structure is // i64, i64, u16 (280), i8, [i8; 256] -pub fn ___syscall220(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { +pub fn ___syscall220(ctx: &mut EmEnv, _which: i32, mut varargs: VarArgs) -> i32 { use super::super::env::get_emscripten_data; let fd: i32 = varargs.get(ctx); @@ -1109,7 +1109,7 @@ pub fn ___syscall220(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { } // fcntl64 -pub fn ___syscall221(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall221(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall221 (fcntl64) {}", _which); let fd: i32 = varargs.get(ctx); let cmd: i32 = varargs.get(ctx); @@ -1127,7 +1127,7 @@ pub fn ___syscall221(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in } /// fallocate -pub fn ___syscall324(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall324(ctx: &mut EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall324 (fallocate) {}", _which); let _fd: c_int = varargs.get(ctx); let _mode: c_int = varargs.get(ctx); diff --git a/lib/emscripten/src/syscalls/windows.rs b/lib/emscripten/src/syscalls/windows.rs index b5ed6cc83..ca1acb4f3 100644 --- a/lib/emscripten/src/syscalls/windows.rs +++ b/lib/emscripten/src/syscalls/windows.rs @@ -1,5 +1,6 @@ use crate::utils::{copy_cstr_into_wasm, get_cstr_path}; use crate::varargs::VarArgs; +use crate::EmEnv; use libc::mkdir; use libc::open; use std::env; @@ -7,13 +8,12 @@ use std::ffi::CString; use std::fs::File; use std::io::Write; use std::os::raw::c_int; -use wasmer_runtime_core::vm::Ctx; #[allow(non_camel_case_types)] type pid_t = c_int; /// open -pub fn ___syscall5(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall5(ctx: &mut EmEnv, which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall5 (open) {}", which); #[cfg(not(feature = "debug"))] let _ = which; @@ -64,19 +64,19 @@ pub fn ___syscall5(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { } /// link -pub fn ___syscall9(_ctx: &mut Ctx, _which: c_int, mut _varargs: VarArgs) -> c_int { +pub fn ___syscall9(_ctx: &mut EmEnv, _which: c_int, mut _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall9 (link) {}", _which); unimplemented!("emscripten::___syscall9 (link) {}", _which); } /// ftruncate64 -pub fn ___syscall194(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall194(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall194 - stub"); unimplemented!("emscripten::___syscall194 - stub") } // chown -pub fn ___syscall212(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int { +pub fn ___syscall212(_ctx: &mut EmEnv, which: c_int, mut _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall212 (chown) {}", which); #[cfg(not(feature = "debug"))] let _ = which; @@ -84,19 +84,19 @@ pub fn ___syscall212(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_i } /// access -pub fn ___syscall33(_ctx: &mut Ctx, _which: c_int, mut _varargs: VarArgs) -> c_int { +pub fn ___syscall33(_ctx: &mut EmEnv, _which: c_int, mut _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall33 (access) {}", _which); unimplemented!("emscripten::___syscall33 (access) {}", _which); } /// nice -pub fn ___syscall34(_ctx: &mut Ctx, _which: c_int, mut _varargs: VarArgs) -> c_int { +pub fn ___syscall34(_ctx: &mut EmEnv, _which: c_int, mut _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall34 (nice) {}", _which); unimplemented!("emscripten::___syscall34 (nice) {}", _which); } // mkdir -pub fn ___syscall39(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall39(ctx: &mut EmEnv, which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall39 (mkdir) {}", which); #[cfg(not(feature = "debug"))] let _ = which; @@ -111,80 +111,80 @@ pub fn ___syscall39(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int } /// dup -pub fn ___syscall41(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int { +pub fn ___syscall41(_ctx: &mut EmEnv, _which: c_int, _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall41 (dup) {}", _which); unimplemented!("emscripten::___syscall41 (dup) {}", _which); } /// getrusage -pub fn ___syscall77(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int { +pub fn ___syscall77(_ctx: &mut EmEnv, _which: c_int, _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall77 (getrusage) {}", _which); unimplemented!("emscripten::___syscall77 (getrusage) {}", _which); } /// symlink -pub fn ___syscall83(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int { +pub fn ___syscall83(_ctx: &mut EmEnv, _which: c_int, _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall83 (symlink) {}", _which); unimplemented!("emscripten::___syscall83 (symlink) {}", _which); } /// readlink -pub fn ___syscall85(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int { +pub fn ___syscall85(_ctx: &mut EmEnv, _which: c_int, _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall85 (readlink) {}", _which); -1 } /// getpgid -pub fn ___syscall132(_ctx: &mut Ctx, _which: c_int, mut _varargs: VarArgs) -> c_int { +pub fn ___syscall132(_ctx: &mut EmEnv, _which: c_int, mut _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall132 (getpgid)"); -1 } /// lchown -pub fn ___syscall198(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int { +pub fn ___syscall198(_ctx: &mut EmEnv, _which: c_int, _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall198 (lchown) {}", _which); unimplemented!("emscripten::___syscall198 (lchown) {}", _which); } /// getgid32 -pub fn ___syscall200(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall200(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall200 (getgid32)"); unimplemented!("emscripten::___syscall200 (getgid32)"); } // geteuid32 -pub fn ___syscall201(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall201(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall201 (geteuid32)"); unimplemented!("emscripten::___syscall201 (geteuid32)"); } // getegid32 -pub fn ___syscall202(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall202(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { // gid_t debug!("emscripten::___syscall202 (getegid32)"); unimplemented!("emscripten::___syscall202 (getegid32)"); } /// getgroups -pub fn ___syscall205(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int { +pub fn ___syscall205(_ctx: &mut EmEnv, _which: c_int, _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall205 (getgroups) {}", _which); unimplemented!("emscripten::___syscall205 (getgroups) {}", _which); } /// madvise -pub fn ___syscall219(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int { +pub fn ___syscall219(_ctx: &mut EmEnv, _which: c_int, _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall212 (chown) {}", _which); unimplemented!("emscripten::___syscall212 (chown) {}", _which); } /// dup3 -pub fn ___syscall330(_ctx: &mut Ctx, _which: c_int, mut _varargs: VarArgs) -> pid_t { +pub fn ___syscall330(_ctx: &mut EmEnv, _which: c_int, mut _varargs: VarArgs) -> pid_t { debug!("emscripten::___syscall330 (dup3)"); -1 } /// ioctl -pub fn ___syscall54(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int { +pub fn ___syscall54(_ctx: &mut EmEnv, which: c_int, mut _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall54 (ioctl) {}", which); #[cfg(not(feature = "debug"))] let _ = which; @@ -192,14 +192,14 @@ pub fn ___syscall54(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_in } /// fchmod -pub fn ___syscall94(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int { +pub fn ___syscall94(_ctx: &mut EmEnv, _which: c_int, _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall118 (fchmod) {}", _which); unimplemented!("emscripten::___syscall118 (fchmod) {}", _which); } // socketcall #[allow(clippy::cast_ptr_alignment)] -pub fn ___syscall102(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int { +pub fn ___syscall102(_ctx: &mut EmEnv, which: c_int, mut _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall102 (socketcall) {}", which); #[cfg(not(feature = "debug"))] let _ = which; @@ -207,13 +207,13 @@ pub fn ___syscall102(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_i } /// fsync -pub fn ___syscall118(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int { +pub fn ___syscall118(_ctx: &mut EmEnv, _which: c_int, _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall118 (fsync) {}", _which); unimplemented!("emscripten::___syscall118 (fsync) {}", _which); } // pread -pub fn ___syscall180(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int { +pub fn ___syscall180(_ctx: &mut EmEnv, which: c_int, mut _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall180 (pread) {}", which); #[cfg(not(feature = "debug"))] let _ = which; @@ -221,7 +221,7 @@ pub fn ___syscall180(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_i } // pwrite -pub fn ___syscall181(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int { +pub fn ___syscall181(_ctx: &mut EmEnv, which: c_int, mut _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall181 (pwrite) {}", which); #[cfg(not(feature = "debug"))] let _ = which; @@ -230,14 +230,14 @@ pub fn ___syscall181(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_i /// wait4 #[allow(clippy::cast_ptr_alignment)] -pub fn ___syscall114(_ctx: &mut Ctx, _which: c_int, mut _varargs: VarArgs) -> pid_t { +pub fn ___syscall114(_ctx: &mut EmEnv, _which: c_int, mut _varargs: VarArgs) -> pid_t { debug!("emscripten::___syscall114 (wait4)"); -1 } // select #[allow(clippy::cast_ptr_alignment)] -pub fn ___syscall142(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int { +pub fn ___syscall142(_ctx: &mut EmEnv, which: c_int, mut _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall142 (newselect) {}", which); #[cfg(not(feature = "debug"))] let _ = which; @@ -245,13 +245,13 @@ pub fn ___syscall142(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_i } /// fdatasync -pub fn ___syscall148(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int { +pub fn ___syscall148(_ctx: &mut EmEnv, _which: c_int, _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall148 (fdatasync) {}", _which); unimplemented!("emscripten::___syscall148 (fdatasync) {}", _which); } // setpgid -pub fn ___syscall57(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int { +pub fn ___syscall57(_ctx: &mut EmEnv, which: c_int, mut _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall57 (setpgid) {}", which); #[cfg(not(feature = "debug"))] let _ = which; @@ -260,7 +260,7 @@ pub fn ___syscall57(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_in /// uname // NOTE: Wondering if we should return custom utsname, like Emscripten. -pub fn ___syscall122(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int { +pub fn ___syscall122(_ctx: &mut EmEnv, which: c_int, mut _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall122 (uname) {}", which); #[cfg(not(feature = "debug"))] let _ = which; @@ -268,43 +268,43 @@ pub fn ___syscall122(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_i } /// poll -pub fn ___syscall168(_ctx: &mut Ctx, _which: i32, _varargs: VarArgs) -> i32 { +pub fn ___syscall168(_ctx: &mut EmEnv, _which: i32, _varargs: VarArgs) -> i32 { debug!("emscripten::___syscall168(poll) - stub"); -1 } /// lstat64 -pub fn ___syscall196(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall196(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall196 (lstat64) - stub"); -1 } // getuid -pub fn ___syscall199(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall199(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall199 (getuid)"); -1 } // getdents -pub fn ___syscall220(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn ___syscall220(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall220"); -1 } // fcntl64 -pub fn ___syscall221(_ctx: &mut Ctx, _which: c_int, mut _varargs: VarArgs) -> c_int { +pub fn ___syscall221(_ctx: &mut EmEnv, _which: c_int, mut _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall221 (fcntl64) {}", _which); -1 } /// fchown -pub fn ___syscall207(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int { +pub fn ___syscall207(_ctx: &mut EmEnv, _which: c_int, _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall207 (fchown) {}", _which); unimplemented!("emscripten::___syscall207 (fchown) {}", _which) } /// fallocate -pub fn ___syscall324(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int { +pub fn ___syscall324(_ctx: &mut EmEnv, _which: c_int, _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall324 (fallocate) {}", _which); unimplemented!("emscripten::___syscall324 (fallocate) {}", _which) } diff --git a/lib/emscripten/src/time.rs b/lib/emscripten/src/time.rs index c341d4be8..239f8da89 100644 --- a/lib/emscripten/src/time.rs +++ b/lib/emscripten/src/time.rs @@ -1,5 +1,5 @@ use super::utils::{copy_cstr_into_wasm, write_to_buf}; -use crate::allocate_on_stack; +use crate::{allocate_on_stack, EmEnv}; use libc::{c_char, c_int}; // use libc::{c_char, c_int, clock_getres, clock_settime}; use std::mem; @@ -26,7 +26,6 @@ extern "C" { use time; use super::env; -use wasmer_runtime_core::vm::Ctx; #[cfg(any(target_os = "linux", target_os = "android"))] use libc::{CLOCK_MONOTONIC, CLOCK_MONOTONIC_COARSE, CLOCK_REALTIME}; @@ -53,7 +52,7 @@ const CLOCK_MONOTONIC_COARSE: clockid_t = 6; /// emscripten: _gettimeofday #[allow(clippy::cast_ptr_alignment)] -pub fn _gettimeofday(ctx: &mut Ctx, tp: c_int, tz: c_int) -> c_int { +pub fn _gettimeofday(ctx: &mut EmEnv, tp: c_int, tz: c_int) -> c_int { debug!("emscripten::_gettimeofday {} {}", tp, tz); #[repr(C)] struct GuestTimeVal { @@ -76,7 +75,7 @@ pub fn _gettimeofday(ctx: &mut Ctx, tp: c_int, tz: c_int) -> c_int { 0 } -pub fn _clock_getres(_ctx: &mut Ctx, _clk_id: i32, _tp: i32) -> i32 { +pub fn _clock_getres(_ctx: &mut EmEnv, _clk_id: i32, _tp: i32) -> i32 { debug!("emscripten::_clock_getres"); // clock_getres(clk_id, tp) 0 @@ -84,7 +83,7 @@ pub fn _clock_getres(_ctx: &mut Ctx, _clk_id: i32, _tp: i32) -> i32 { /// emscripten: _clock_gettime #[allow(clippy::cast_ptr_alignment)] -pub fn _clock_gettime(ctx: &mut Ctx, clk_id: clockid_t, tp: c_int) -> c_int { +pub fn _clock_gettime(ctx: &mut EmEnv, clk_id: clockid_t, tp: c_int) -> c_int { debug!("emscripten::_clock_gettime {} {}", clk_id, tp); // debug!("Memory {:?}", ctx.memory(0)[..]); #[repr(C)] @@ -116,41 +115,41 @@ pub fn _clock_gettime(ctx: &mut Ctx, clk_id: clockid_t, tp: c_int) -> c_int { 0 } -pub fn _clock_settime(_ctx: &mut Ctx, _clk_id: i32, _tp: i32) -> i32 { +pub fn _clock_settime(_ctx: &mut EmEnv, _clk_id: i32, _tp: i32) -> i32 { debug!("emscripten::_clock_settime"); // clock_settime(clk_id, tp) 0 } /// emscripten: ___clock_gettime -pub fn ___clock_gettime(ctx: &mut Ctx, clk_id: clockid_t, tp: c_int) -> c_int { +pub fn ___clock_gettime(ctx: &mut EmEnv, clk_id: clockid_t, tp: c_int) -> c_int { debug!("emscripten::___clock_gettime {} {}", clk_id, tp); _clock_gettime(ctx, clk_id, tp) } /// emscripten: _clock -pub fn _clock(_ctx: &mut Ctx) -> c_int { +pub fn _clock(_ctx: &mut EmEnv) -> c_int { debug!("emscripten::_clock"); 0 // TODO: unimplemented } /// emscripten: _difftime -pub fn _difftime(_ctx: &mut Ctx, t0: u32, t1: u32) -> f64 { +pub fn _difftime(_ctx: &mut EmEnv, t0: u32, t1: u32) -> f64 { debug!("emscripten::_difftime"); (t0 - t1) as _ } -pub fn _gmtime_r(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn _gmtime_r(_ctx: &mut EmEnv, _one: i32, _two: i32) -> i32 { debug!("emscripten::_gmtime_r"); -1 } -pub fn _mktime(_ctx: &mut Ctx, _one: i32) -> i32 { +pub fn _mktime(_ctx: &mut EmEnv, _one: i32) -> i32 { debug!("emscripten::_mktime"); -1 } -pub fn _gmtime(_ctx: &mut Ctx, _one: i32) -> i32 { +pub fn _gmtime(_ctx: &mut EmEnv, _one: i32) -> i32 { debug!("emscripten::_gmtime"); -1 } @@ -171,13 +170,13 @@ struct guest_tm { } /// emscripten: _tvset -pub fn _tvset(_ctx: &mut Ctx) { +pub fn _tvset(_ctx: &mut EmEnv) { debug!("emscripten::_tvset UNIMPLEMENTED"); } /// formats time as a C string #[allow(clippy::cast_ptr_alignment)] -unsafe fn fmt_time(ctx: &mut Ctx, time: u32) -> *const c_char { +unsafe fn fmt_time(ctx: &mut EmEnv, time: u32) -> *const c_char { let date = &*(emscripten_memory_pointer!(ctx.memory(0), time) as *mut guest_tm); let days = vec!["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; @@ -202,7 +201,7 @@ unsafe fn fmt_time(ctx: &mut Ctx, time: u32) -> *const c_char { } /// emscripten: _asctime -pub fn _asctime(ctx: &mut Ctx, time: u32) -> u32 { +pub fn _asctime(ctx: &mut EmEnv, time: u32) -> u32 { debug!("emscripten::_asctime {}", time); unsafe { @@ -216,7 +215,7 @@ pub fn _asctime(ctx: &mut Ctx, time: u32) -> u32 { } /// emscripten: _asctime_r -pub fn _asctime_r(ctx: &mut Ctx, time: u32, buf: u32) -> u32 { +pub fn _asctime_r(ctx: &mut EmEnv, time: u32, buf: u32) -> u32 { debug!("emscripten::_asctime_r {}, {}", time, buf); unsafe { @@ -235,7 +234,7 @@ pub fn _asctime_r(ctx: &mut Ctx, time: u32, buf: u32) -> u32 { /// emscripten: _localtime #[allow(clippy::cast_ptr_alignment)] -pub fn _localtime(ctx: &mut Ctx, time_p: u32) -> c_int { +pub fn _localtime(ctx: &mut EmEnv, time_p: u32) -> c_int { debug!("emscripten::_localtime {}", time_p); // NOTE: emscripten seems to want tzset() called in this function // https://stackoverflow.com/questions/19170721/real-time-awareness-of-timezone-change-in-localtime-vs-localtime-r @@ -273,7 +272,7 @@ pub fn _localtime(ctx: &mut Ctx, time_p: u32) -> c_int { } /// emscripten: _localtime_r #[allow(clippy::cast_ptr_alignment)] -pub fn _localtime_r(ctx: &mut Ctx, time_p: u32, result: u32) -> c_int { +pub fn _localtime_r(ctx: &mut EmEnv, time_p: u32, result: u32) -> c_int { debug!("emscripten::_localtime_r {}", time_p); // NOTE: emscripten seems to want tzset() called in this function @@ -310,7 +309,7 @@ pub fn _localtime_r(ctx: &mut Ctx, time_p: u32, result: u32) -> c_int { /// emscripten: _time #[allow(clippy::cast_ptr_alignment)] -pub fn _time(ctx: &mut Ctx, time_p: u32) -> i32 { +pub fn _time(ctx: &mut EmEnv, time_p: u32) -> i32 { debug!("emscripten::_time {}", time_p); unsafe { @@ -319,7 +318,7 @@ pub fn _time(ctx: &mut Ctx, time_p: u32) -> i32 { } } -pub fn _ctime_r(ctx: &mut Ctx, time_p: u32, buf: u32) -> u32 { +pub fn _ctime_r(ctx: &mut EmEnv, time_p: u32, buf: u32) -> u32 { debug!("emscripten::_ctime_r {} {}", time_p, buf); // var stack = stackSave(); @@ -330,7 +329,7 @@ pub fn _ctime_r(ctx: &mut Ctx, time_p: u32, buf: u32) -> u32 { rv } -pub fn _ctime(ctx: &mut Ctx, time_p: u32) -> u32 { +pub fn _ctime(ctx: &mut EmEnv, time_p: u32) -> u32 { debug!("emscripten::_ctime {}", time_p); let tm_current = 2414544; _ctime_r(ctx, time_p, tm_current) @@ -339,7 +338,7 @@ pub fn _ctime(ctx: &mut Ctx, time_p: u32) -> u32 { /// emscripten: _timegm #[cfg(not(target_os = "windows"))] #[allow(clippy::cast_ptr_alignment)] -pub fn _timegm(ctx: &mut Ctx, time_ptr: u32) -> i32 { +pub fn _timegm(ctx: &mut EmEnv, time_ptr: u32) -> i32 { debug!("emscripten::_timegm {}", time_ptr); unsafe { @@ -379,7 +378,7 @@ pub fn _timegm(ctx: &mut Ctx, time_ptr: u32) -> i32 { } #[cfg(target_os = "windows")] -pub fn _timegm(_ctx: &mut Ctx, _time_ptr: c_int) -> i32 { +pub fn _timegm(_ctx: &mut EmEnv, _time_ptr: c_int) -> i32 { debug!( "emscripten::_timegm - UNIMPLEMENTED IN WINDOWS {}", _time_ptr @@ -389,7 +388,7 @@ pub fn _timegm(_ctx: &mut Ctx, _time_ptr: c_int) -> i32 { /// emscripten: _strftime pub fn _strftime( - ctx: &mut Ctx, + ctx: &mut EmEnv, s_ptr: c_int, maxsize: u32, format_ptr: c_int, @@ -449,7 +448,7 @@ pub fn _strftime( /// emscripten: _strftime_l pub fn _strftime_l( - ctx: &mut Ctx, + ctx: &mut EmEnv, s_ptr: c_int, maxsize: u32, format_ptr: c_int, diff --git a/lib/emscripten/src/ucontext.rs b/lib/emscripten/src/ucontext.rs index abf4e1de2..fcb11d25a 100644 --- a/lib/emscripten/src/ucontext.rs +++ b/lib/emscripten/src/ucontext.rs @@ -1,20 +1,20 @@ -use wasmer_runtime_core::vm::Ctx; +use crate::EmEnv; -pub fn _getcontext(_ctx: &mut Ctx, _ucp: i32) -> i32 { +pub fn _getcontext(_ctx: &mut EmEnv, _ucp: i32) -> i32 { debug!("emscripten::_getcontext({})", _ucp); 0 } -pub fn _makecontext(_ctx: &mut Ctx, _ucp: i32, _func: i32, _argc: i32, _argv: i32) { +pub fn _makecontext(_ctx: &mut EmEnv, _ucp: i32, _func: i32, _argc: i32, _argv: i32) { debug!( "emscripten::_makecontext({}, {}, {}, {})", _ucp, _func, _argc, _argv ); } -pub fn _setcontext(_ctx: &mut Ctx, _ucp: i32) -> i32 { +pub fn _setcontext(_ctx: &mut EmEnv, _ucp: i32) -> i32 { debug!("emscripten::_setcontext({})", _ucp); 0 } -pub fn _swapcontext(_ctx: &mut Ctx, _oucp: i32, _ucp: i32) -> i32 { +pub fn _swapcontext(_ctx: &mut EmEnv, _oucp: i32, _ucp: i32) -> i32 { debug!("emscripten::_swapcontext({}, {})", _oucp, _ucp); 0 } diff --git a/lib/emscripten/src/unistd.rs b/lib/emscripten/src/unistd.rs index 08c06ce50..b0439fb1e 100644 --- a/lib/emscripten/src/unistd.rs +++ b/lib/emscripten/src/unistd.rs @@ -1,6 +1,6 @@ -use wasmer_runtime_core::vm::Ctx; +use crate::EmEnv; -pub fn confstr(_ctx: &mut Ctx, _name: i32, _buf_pointer: i32, _len: i32) -> i32 { +pub fn confstr(_ctx: &mut EmEnv, _name: i32, _buf_pointer: i32, _len: i32) -> i32 { debug!("unistd::confstr({}, {}, {})", _name, _buf_pointer, _len); 0 } diff --git a/lib/emscripten/src/utils.rs b/lib/emscripten/src/utils.rs index e1c403565..70d64930c 100644 --- a/lib/emscripten/src/utils.rs +++ b/lib/emscripten/src/utils.rs @@ -1,19 +1,17 @@ use super::env; use super::env::get_emscripten_data; use crate::storage::align_memory; +use crate::EmEnv; use libc::stat; use std::ffi::CStr; use std::mem::size_of; use std::os::raw::c_char; use std::path::PathBuf; use std::slice; -use wasmer_runtime_core::memory::Memory; +use wasmer::{Memory, Module, Pages}; use wasmer_runtime_core::{ - module::Module, structures::TypedIndex, types::{ImportedMemoryIndex, ImportedTableIndex}, - units::Pages, - vm::Ctx, }; /// We check if a provided module is an Emscripten generated one @@ -104,7 +102,7 @@ pub fn get_emscripten_metadata(module: &Module) -> Result, St } } -pub unsafe fn write_to_buf(ctx: &mut Ctx, string: *const c_char, buf: u32, max: u32) -> u32 { +pub unsafe fn write_to_buf(ctx: &mut EmEnv, string: *const c_char, buf: u32, max: u32) -> u32 { let buf_addr = emscripten_memory_pointer!(ctx.memory(0), buf) as *mut c_char; for i in 0..max { @@ -115,7 +113,7 @@ pub unsafe fn write_to_buf(ctx: &mut Ctx, string: *const c_char, buf: u32, max: } /// This function expects nullbyte to be appended. -pub unsafe fn copy_cstr_into_wasm(ctx: &mut Ctx, cstr: *const c_char) -> u32 { +pub unsafe fn copy_cstr_into_wasm(ctx: &mut EmEnv, cstr: *const c_char) -> u32 { let s = CStr::from_ptr(cstr).to_str().unwrap(); let cstr_len = s.len(); let space_offset = env::call_malloc(ctx, (cstr_len as u32) + 1); @@ -133,7 +131,7 @@ pub unsafe fn copy_cstr_into_wasm(ctx: &mut Ctx, cstr: *const c_char) -> u32 { space_offset } -pub unsafe fn allocate_on_stack<'a, T: Copy>(ctx: &'a mut Ctx, count: u32) -> (u32, &'a mut [T]) { +pub unsafe fn allocate_on_stack<'a, T: Copy>(ctx: &'a mut EmEnv, count: u32) -> (u32, &'a mut [T]) { let offset = get_emscripten_data(ctx) .stack_alloc .as_ref() @@ -146,7 +144,7 @@ pub unsafe fn allocate_on_stack<'a, T: Copy>(ctx: &'a mut Ctx, count: u32) -> (u (offset, slice) } -pub unsafe fn allocate_cstr_on_stack<'a>(ctx: &'a mut Ctx, s: &str) -> (u32, &'a [u8]) { +pub unsafe fn allocate_cstr_on_stack<'a>(ctx: &'a mut EmEnv, s: &str) -> (u32, &'a [u8]) { let (offset, slice) = allocate_on_stack(ctx, (s.len() + 1) as u32); use std::iter; @@ -158,7 +156,7 @@ pub unsafe fn allocate_cstr_on_stack<'a>(ctx: &'a mut Ctx, s: &str) -> (u32, &'a } #[cfg(not(target_os = "windows"))] -pub unsafe fn copy_terminated_array_of_cstrs(_ctx: &mut Ctx, cstrs: *mut *mut c_char) -> u32 { +pub unsafe fn copy_terminated_array_of_cstrs(_ctx: &mut EmEnv, cstrs: *mut *mut c_char) -> u32 { let _total_num = { let mut ptr = cstrs; let mut counter = 0; @@ -196,7 +194,7 @@ pub struct GuestStat { } #[allow(clippy::cast_ptr_alignment)] -pub unsafe fn copy_stat_into_wasm(ctx: &mut Ctx, buf: u32, stat: &stat) { +pub unsafe fn copy_stat_into_wasm(ctx: &mut EmEnv, buf: u32, stat: &stat) { let stat_ptr = emscripten_memory_pointer!(ctx.memory(0), buf) as *mut GuestStat; (*stat_ptr).st_dev = stat.st_dev as _; (*stat_ptr).__st_dev_padding = 0; @@ -235,7 +233,7 @@ pub fn read_string_from_wasm(memory: &Memory, offset: u32) -> String { /// This function trys to find an entry in mapdir /// translating paths into their correct value -pub fn get_cstr_path(ctx: &mut Ctx, path: *const i8) -> Option { +pub fn get_cstr_path(ctx: &mut EmEnv, path: *const i8) -> Option { use std::collections::VecDeque; let path_str = @@ -271,7 +269,7 @@ pub fn get_cstr_path(ctx: &mut Ctx, path: *const i8) -> Option Option { +pub fn get_current_directory(ctx: &mut EmEnv) -> Option { if let Some(val) = get_emscripten_data(ctx).mapped_dirs.get(".") { return Some(val.clone()); } diff --git a/lib/emscripten/src/varargs.rs b/lib/emscripten/src/varargs.rs index 8daf78dc8..72f9f16ad 100644 --- a/lib/emscripten/src/varargs.rs +++ b/lib/emscripten/src/varargs.rs @@ -1,5 +1,6 @@ +use crate::EmEnv; use std::mem; -use wasmer_runtime_core::{types::WasmExternType, vm::Ctx}; +use wasmer::WasmExternType; // use std::ffi::CStr; use std::os::raw::c_char; @@ -10,14 +11,14 @@ pub struct VarArgs { } impl VarArgs { - pub fn get(&mut self, ctx: &mut Ctx) -> T { + pub fn get(&mut self, ctx: &mut EmEnv) -> T { let ptr = emscripten_memory_pointer!(ctx.memory(0), self.pointer); self.pointer += mem::size_of::() as u32; unsafe { (ptr as *const T).read() } } // pub fn getStr<'a>(&mut self, ctx: &mut Ctx) -> &'a CStr { - pub fn get_str(&mut self, ctx: &mut Ctx) -> *const c_char { + pub fn get_str(&mut self, ctx: &mut EmEnv) -> *const c_char { let ptr_addr: u32 = self.get(ctx); let ptr = emscripten_memory_pointer!(ctx.memory(0), ptr_addr) as *const c_char; ptr diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index 41ea47b82..db9074387 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -51,7 +51,7 @@ impl<'a> WasiEnv<'a> { } } - /// Set the state + /// Set the memory pub fn set_memory(&mut self, memory: &'a Memory) { self.memory = Some(memory); }