diff --git a/Cargo.lock b/Cargo.lock index aa14e70be..4bb493f9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1090,6 +1090,7 @@ dependencies = [ "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.48 (git+https://github.com/rust-lang/libc)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-clif-backend 0.1.2", diff --git a/lib/emscripten/Cargo.toml b/lib/emscripten/Cargo.toml index 648817eec..ec5e035d6 100644 --- a/lib/emscripten/Cargo.toml +++ b/lib/emscripten/Cargo.toml @@ -15,6 +15,9 @@ libc = { git = "https://github.com/rust-lang/libc" } byteorder = "1" time = "0.1.41" +[target.'cfg(windows)'.dependencies] +rand = "0.6" + [dev-dependencies] wasmer-clif-backend = { path = "../clif-backend", version = "0.1.0" } wabt = "0.7.2" diff --git a/lib/emscripten/src/emscripten_target.rs b/lib/emscripten/src/emscripten_target.rs index 4f831e909..e850757f6 100644 --- a/lib/emscripten/src/emscripten_target.rs +++ b/lib/emscripten/src/emscripten_target.rs @@ -173,3 +173,393 @@ pub fn ___gxx_personality_v0(ctx: &mut Ctx, a: i32, b: i32, c: i32, d: i32, e: i debug!("emscripten::___gxx_personality_v0"); 0 } +// round 2 +pub fn nullFunc_dii(ctx: &mut Ctx, index: i32) { + debug!("emscripten::nullFunc_dii"); +} +pub fn nullFunc_diiii(ctx: &mut Ctx, index: i32) { + debug!("emscripten::nullFunc_diiii"); +} +pub fn nullFunc_iiji(ctx: &mut Ctx, index: i32) { + debug!("emscripten::nullFunc_iiji"); +} +pub fn nullFunc_j(ctx: &mut Ctx, index: i32) { + debug!("emscripten::nullFunc_j"); +} +pub fn nullFunc_jij(ctx: &mut Ctx, index: i32) { + debug!("emscripten::nullFunc_jij"); +} +pub fn nullFunc_jjj(ctx: &mut Ctx, index: i32) { + debug!("emscripten::nullFunc_jjj"); +} +pub fn nullFunc_vd(ctx: &mut Ctx, index: i32) { + debug!("emscripten::nullFunc_vd"); +} +pub fn nullFunc_viiiiiii(ctx: &mut Ctx, index: i32) { + debug!("emscripten::nullFunc_viiiiiii"); +} +pub fn nullFunc_viiiiiiii(ctx: &mut Ctx, index: i32) { + debug!("emscripten::nullFunc_viiiiiiii"); +} +pub fn nullFunc_viiiiiiiii(ctx: &mut Ctx, index: i32) { + debug!("emscripten::nullFunc_viiiiiiiii"); +} +pub fn nullFunc_viiij(ctx: &mut Ctx, index: i32) { + debug!("emscripten::nullFunc_viiij"); +} +pub fn nullFunc_viiijiiii(ctx: &mut Ctx, index: i32) { + debug!("emscripten::nullFunc_viiijiiii"); +} +pub fn nullFunc_viiijiiiiii(ctx: &mut Ctx, index: i32) { + debug!("emscripten::nullFunc_viiijiiiiii"); +} +pub fn nullFunc_viij(ctx: &mut Ctx, index: i32) { + debug!("emscripten::nullFunc_viij"); +} +pub fn nullFunc_viiji(ctx: &mut Ctx, index: i32) { + debug!("emscripten::nullFunc_viiji"); +} +pub fn nullFunc_viijiii(ctx: &mut Ctx, index: i32) { + debug!("emscripten::nullFunc_viijiii"); +} +pub fn nullFunc_viijj(ctx: &mut Ctx, index: i32) { + debug!("emscripten::nullFunc_viijj"); +} +pub fn nullFunc_vij(ctx: &mut Ctx, index: i32) { + debug!("emscripten::nullFunc_vij"); +} +pub fn nullFunc_viji(ctx: &mut Ctx, index: i32) { + debug!("emscripten::nullFunc_viji"); +} +pub fn nullFunc_vijiii(ctx: &mut Ctx, index: i32) { + debug!("emscripten::nullFunc_vijiii"); +} +pub fn nullFunc_vijj(ctx: &mut Ctx, index: i32) { + debug!("emscripten::nullFunc_vijj"); +} +pub fn invoke_dii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32) -> f64 { + debug!("emscripten::invoke_dii"); + if let Some(dyn_call_dii) = &get_emscripten_data(ctx).dyn_call_dii { + dyn_call_dii.call(index, a1, a2).unwrap() + } else { + panic!("dyn_call_dii is set to None"); + } +} +pub fn invoke_diiii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) -> f64 { + debug!("emscripten::invoke_diiii"); + if let Some(dyn_call_diiii) = &get_emscripten_data(ctx).dyn_call_diiii { + dyn_call_diiii.call(index, a1, a2, a3, a4).unwrap() + } else { + panic!("dyn_call_diiii is set to None"); + } +} +pub fn invoke_iiiii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) -> i32 { + debug!("emscripten::invoke_iiiii"); + if let Some(dyn_call_iiiii) = &get_emscripten_data(ctx).dyn_call_iiiii { + dyn_call_iiiii.call(index, a1, a2, a3, a4).unwrap() + } else { + panic!("dyn_call_iiiii is set to None"); + } +} +pub fn invoke_iiiiii( + ctx: &mut Ctx, + index: i32, + a1: i32, + a2: i32, + a3: i32, + a4: i32, + a5: i32, +) -> i32 { + debug!("emscripten::invoke_iiiiii"); + if let Some(dyn_call_iiiiii) = &get_emscripten_data(ctx).dyn_call_iiiiii { + dyn_call_iiiiii.call(index, a1, a2, a3, a4, a5).unwrap() + } else { + panic!("dyn_call_iiiiii is set to None"); + } +} +pub fn invoke_vd(ctx: &mut Ctx, index: i32, a1: f64) { + debug!("emscripten::invoke_vd"); + if let Some(dyn_call_vd) = &get_emscripten_data(ctx).dyn_call_vd { + dyn_call_vd.call(index, a1).unwrap(); + } else { + panic!("dyn_call_vd is set to None"); + } +} +pub fn invoke_viiiii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32, a5: i32) { + debug!("emscripten::invoke_viiiii"); + if let Some(dyn_call_viiiii) = &get_emscripten_data(ctx).dyn_call_viiiii { + dyn_call_viiiii.call(index, a1, a2, a3, a4, a5).unwrap(); + } else { + panic!("dyn_call_viiiii is set to None"); + } +} +pub fn invoke_viiiiii( + ctx: &mut Ctx, + index: i32, + a1: i32, + a2: i32, + a3: i32, + a4: i32, + a5: i32, + a6: i32, +) { + debug!("emscripten::invoke_viiiiii"); + if let Some(dyn_call_viiiiii) = &get_emscripten_data(ctx).dyn_call_viiiiii { + dyn_call_viiiiii + .call(index, a1, a2, a3, a4, a5, a6) + .unwrap(); + } else { + panic!("dyn_call_viiiiii is set to None"); + } +} +pub fn invoke_viiiiiii( + ctx: &mut Ctx, + index: i32, + a1: i32, + a2: i32, + a3: i32, + a4: i32, + a5: i32, + a6: i32, + a7: i32, +) { + debug!("emscripten::invoke_viiiiiii"); + if let Some(dyn_call_viiiiiii) = &get_emscripten_data(ctx).dyn_call_viiiiiii { + dyn_call_viiiiiii + .call(index, a1, a2, a3, a4, a5, a6, a7) + .unwrap(); + } else { + panic!("dyn_call_viiiiiii is set to None"); + } +} +pub fn invoke_viiiiiiii( + ctx: &mut Ctx, + index: i32, + a1: i32, + a2: i32, + a3: i32, + a4: i32, + a5: i32, + a6: i32, + a7: i32, + a8: i32, +) { + debug!("emscripten::invoke_viiiiiiii"); + if let Some(dyn_call_viiiiiiii) = &get_emscripten_data(ctx).dyn_call_viiiiiiii { + dyn_call_viiiiiiii + .call(index, a1, a2, a3, a4, a5, a6, a7, a8) + .unwrap(); + } else { + panic!("dyn_call_viiiiiiii is set to None"); + } +} +pub fn invoke_viiiiiiiii( + ctx: &mut Ctx, + index: i32, + a1: i32, + a2: i32, + a3: i32, + a4: i32, + a5: i32, + a6: i32, + a7: i32, + a8: i32, + a9: i32, +) { + debug!("emscripten::invoke_viiiiiiiii"); + if let Some(dyn_call_viiiiiiiii) = &get_emscripten_data(ctx).dyn_call_viiiiiiiii { + dyn_call_viiiiiiiii + .call(index, a1, a2, a3, a4, a5, a6, a7, a8, a9) + .unwrap(); + } else { + panic!("dyn_call_viiiiiiiii is set to None"); + } +} +pub fn invoke_iiji(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) -> i32 { + debug!("emscripten::invoke_iiji"); + if let Some(dyn_call_iiji) = &get_emscripten_data(ctx).dyn_call_iiji { + dyn_call_iiji.call(index, a1, a2, a3, a4).unwrap() + } else { + panic!("dyn_call_iiji is set to None"); + } +} +pub fn invoke_j(ctx: &mut Ctx, 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() + } else { + panic!("dyn_call_j is set to None"); + } +} +pub fn invoke_ji(ctx: &mut Ctx, 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() + } else { + panic!("dyn_call_ji is set to None"); + } +} +pub fn invoke_jij(ctx: &mut Ctx, 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() + } else { + 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 { + 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() + } else { + 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) { + 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(); + } else { + panic!("dyn_call_viiij is set to None"); + } +} +pub fn invoke_viiijiiii( + ctx: &mut Ctx, + index: i32, + a1: i32, + a2: i32, + a3: i32, + a4: i32, + a5: i32, + a6: i32, + a7: i32, + a8: i32, + a9: i32, +) { + debug!("emscripten::invoke_viiijiiii"); + if let Some(dyn_call_viiijiiii) = &get_emscripten_data(ctx).dyn_call_viiijiiii { + dyn_call_viiijiiii + .call(index, a1, a2, a3, a4, a5, a6, a7, a8, a9) + .unwrap(); + } else { + panic!("dyn_call_viiijiiii is set to None"); + } +} +pub fn invoke_viiijiiiiii( + ctx: &mut Ctx, + index: i32, + a1: i32, + a2: i32, + a3: i32, + a4: i32, + a5: i32, + a6: i32, + a7: i32, + a8: i32, + a9: i32, + a10: i32, + a11: i32, +) { + debug!("emscripten::invoke_viiijiiiiii"); + if let Some(dyn_call_viiijiiiiii) = &get_emscripten_data(ctx).dyn_call_viiijiiiiii { + dyn_call_viiijiiiiii + .call(index, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) + .unwrap(); + } else { + 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) { + 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(); + } else { + 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) { + 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(); + } else { + panic!("dyn_call_viiji is set to None"); + } +} +pub fn invoke_viijiii( + ctx: &mut Ctx, + index: i32, + a1: i32, + a2: i32, + a3: i32, + a4: i32, + a5: i32, + a6: i32, + a7: i32, +) { + debug!("emscripten::invoke_viijiii"); + if let Some(dyn_call_viijiii) = &get_emscripten_data(ctx).dyn_call_viijiii { + dyn_call_viijiii + .call(index, a1, a2, a3, a4, a5, a6, a7) + .unwrap(); + } else { + panic!("dyn_call_viijiii is set to None"); + } +} +pub fn invoke_viijj( + ctx: &mut Ctx, + index: i32, + a1: i32, + a2: i32, + a3: i32, + a4: i32, + a5: i32, + a6: i32, +) { + debug!("emscripten::invoke_viijj"); + if let Some(dyn_call_viijj) = &get_emscripten_data(ctx).dyn_call_viijj { + dyn_call_viijj.call(index, a1, a2, a3, a4, a5, a6).unwrap(); + } else { + panic!("dyn_call_viijj is set to None"); + } +} +pub fn invoke_vij(ctx: &mut Ctx, 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(); + } else { + 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) { + 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() + } else { + panic!("dyn_call_viji is set to None"); + } +} +pub fn invoke_vijiii( + ctx: &mut Ctx, + index: i32, + a1: i32, + a2: i32, + a3: i32, + a4: i32, + a5: i32, + a6: i32, +) { + debug!("emscripten::invoke_vijiii"); + if let Some(dyn_call_vijiii) = &get_emscripten_data(ctx).dyn_call_vijiii { + dyn_call_vijiii.call(index, a1, a2, a3, a4, a5, a6).unwrap() + } else { + 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) { + 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() + } else { + panic!("dyn_call_vijj is set to None"); + } +} diff --git a/lib/emscripten/src/env/windows/mod.rs b/lib/emscripten/src/env/windows/mod.rs index b4ee6ecff..e95a66ec2 100644 --- a/lib/emscripten/src/env/windows/mod.rs +++ b/lib/emscripten/src/env/windows/mod.rs @@ -7,6 +7,7 @@ use std::os::raw::c_char; use crate::env::call_malloc; use crate::utils::{copy_cstr_into_wasm, read_string_from_wasm}; +use std::ffi::CStr; use wasmer_runtime_core::vm::Ctx; extern "C" { diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index 8911b823d..5a7f008f1 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -104,6 +104,35 @@ pub struct EmscriptenData<'a> { 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_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_iiji: Option>, + pub dyn_call_j: Option>, + pub dyn_call_ji: 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_vij: Option>, + pub dyn_call_viji: Option>, + pub dyn_call_vijiii: Option>, + pub dyn_call_vijj: Option>, } impl<'a> EmscriptenData<'a> { @@ -128,6 +157,34 @@ impl<'a> EmscriptenData<'a> { let dyn_call_viii = instance.func("dynCall_viii").ok(); let dyn_call_viiii = instance.func("dynCall_viiii").ok(); + // round 2 + let dyn_call_dii = instance.func("dynCall_dii").ok(); + let dyn_call_diiii = instance.func("dynCall_diiii").ok(); + let dyn_call_iiiii = instance.func("dynCall_iiiii").ok(); + let dyn_call_iiiiii = instance.func("dynCall_iiiiii").ok(); + let dyn_call_vd = instance.func("dynCall_vd").ok(); + let dyn_call_viiiii = instance.func("dynCall_viiiii").ok(); + let dyn_call_viiiiii = instance.func("dynCall_viiiiii").ok(); + let dyn_call_viiiiiii = instance.func("dynCall_viiiiiii").ok(); + let dyn_call_viiiiiiii = instance.func("dynCall_viiiiiiii").ok(); + let dyn_call_viiiiiiiii = instance.func("dynCall_viiiiiiiii").ok(); + let dyn_call_iiji = instance.func("dynCall_iiji").ok(); + let dyn_call_j = instance.func("dynCall_j").ok(); + let dyn_call_ji = instance.func("dynCall_ji").ok(); + let dyn_call_jij = instance.func("dynCall_jij").ok(); + let dyn_call_jjj = instance.func("dynCall_jjj").ok(); + let dyn_call_viiij = instance.func("dynCall_viiij").ok(); + let dyn_call_viiijiiii = instance.func("dynCall_viiijiiii").ok(); + let dyn_call_viiijiiiiii = instance.func("dynCall_viiijiiiiii").ok(); + let dyn_call_viij = instance.func("dynCall_viij").ok(); + let dyn_call_viiji = instance.func("dynCall_viiji").ok(); + let dyn_call_viijiii = instance.func("dynCall_viijiii").ok(); + let dyn_call_viijj = instance.func("dynCall_viijj").ok(); + let dyn_call_vij = instance.func("dynCall_vij").ok(); + let dyn_call_viji = instance.func("dynCall_viji").ok(); + let dyn_call_vijiii = instance.func("dynCall_vijiii").ok(); + let dyn_call_vijj = instance.func("dynCall_vijj").ok(); + EmscriptenData { malloc, free, @@ -144,6 +201,34 @@ impl<'a> EmscriptenData<'a> { dyn_call_vii, dyn_call_viii, dyn_call_viiii, + + // round 2 + dyn_call_dii, + dyn_call_diiii, + dyn_call_iiiii, + dyn_call_iiiiii, + dyn_call_vd, + dyn_call_viiiii, + dyn_call_viiiiii, + dyn_call_viiiiiii, + dyn_call_viiiiiiii, + dyn_call_viiiiiiiii, + dyn_call_iiji, + dyn_call_j, + dyn_call_ji, + dyn_call_jij, + dyn_call_jjj, + dyn_call_viiij, + dyn_call_viiijiiii, + dyn_call_viiijiiiiii, + dyn_call_viij, + dyn_call_viiji, + dyn_call_viijiii, + dyn_call_viijj, + dyn_call_vij, + dyn_call_viji, + dyn_call_vijiii, + dyn_call_vijj, } } } @@ -556,6 +641,54 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "_pthread_rwlock_rdlock" => func!(crate::emscripten_target::_pthread_rwlock_rdlock), "_pthread_rwlock_unlock" => func!(crate::emscripten_target::_pthread_rwlock_unlock), "___gxx_personality_v0" => func!(crate::emscripten_target::___gxx_personality_v0), + // round 2 + "nullFunc_dii" => func!(crate::emscripten_target::nullFunc_dii), + "nullFunc_diiii" => func!(crate::emscripten_target::nullFunc_diiii), + "nullFunc_iiji" => func!(crate::emscripten_target::nullFunc_iiji), + "nullFunc_j" => func!(crate::emscripten_target::nullFunc_j), + "nullFunc_jij" => func!(crate::emscripten_target::nullFunc_jij), + "nullFunc_jjj" => func!(crate::emscripten_target::nullFunc_jjj), + "nullFunc_vd" => func!(crate::emscripten_target::nullFunc_vd), + "nullFunc_viiiiiii" => func!(crate::emscripten_target::nullFunc_viiiiiii), + "nullFunc_viiiiiiii" => func!(crate::emscripten_target::nullFunc_viiiiiiii), + "nullFunc_viiiiiiiii" => func!(crate::emscripten_target::nullFunc_viiiiiiiii), + "nullFunc_viiij" => func!(crate::emscripten_target::nullFunc_viiij), + "nullFunc_viiijiiii" => func!(crate::emscripten_target::nullFunc_viiijiiii), + "nullFunc_viiijiiiiii" => func!(crate::emscripten_target::nullFunc_viiijiiiiii), + "nullFunc_viij" => func!(crate::emscripten_target::nullFunc_viij), + "nullFunc_viiji" => func!(crate::emscripten_target::nullFunc_viiji), + "nullFunc_viijiii" => func!(crate::emscripten_target::nullFunc_viijiii), + "nullFunc_viijj" => func!(crate::emscripten_target::nullFunc_viijj), + "nullFunc_vij" => func!(crate::emscripten_target::nullFunc_vij), + "nullFunc_viji" => func!(crate::emscripten_target::nullFunc_viji), + "nullFunc_vijiii" => func!(crate::emscripten_target::nullFunc_vijiii), + "nullFunc_vijj" => func!(crate::emscripten_target::nullFunc_vijj), + "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_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_iiji" => func!(crate::emscripten_target::invoke_iiji), + "invoke_j" => func!(crate::emscripten_target::invoke_j), + "invoke_ji" => func!(crate::emscripten_target::invoke_ji), + "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), }, "global" => { "NaN" => Global::new(Value::F64(f64::NAN)), diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index c722e3a79..ef9ef40ee 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -28,7 +28,7 @@ use libc::{ getpid, // iovec, lseek, - open, + // open, read, // readv, rmdir, @@ -85,22 +85,6 @@ pub fn ___syscall4(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { unsafe { write(fd, buf_addr, count) as i32 } } -/// open -pub fn ___syscall5(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { - debug!("emscripten::___syscall5 (open) {}", which); - let pathname: u32 = varargs.get(ctx); - let flags: i32 = varargs.get(ctx); - let mode: u32 = varargs.get(ctx); - let pathname_addr = emscripten_memory_pointer!(ctx.memory(0), pathname) as *const i8; - let path_str = unsafe { std::ffi::CStr::from_ptr(pathname_addr).to_str().unwrap() }; - let fd = unsafe { open(pathname_addr, flags, mode) }; - debug!( - "=> pathname: {}, flags: {}, mode: {} = fd: {}\npath: {}", - pathname, flags, mode, fd, path_str - ); - fd -} - /// close pub fn ___syscall6(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall6 (close) {}", which); diff --git a/lib/emscripten/src/syscalls/unix.rs b/lib/emscripten/src/syscalls/unix.rs index c95c8c7dd..a73456d09 100644 --- a/lib/emscripten/src/syscalls/unix.rs +++ b/lib/emscripten/src/syscalls/unix.rs @@ -24,6 +24,7 @@ use libc::{ listen, mkdir, msghdr, + open, pid_t, pread, pwrite, @@ -76,6 +77,22 @@ use libc::SO_NOSIGPIPE; #[cfg(not(target_os = "darwin"))] const SO_NOSIGPIPE: c_int = 0; +/// open +pub fn ___syscall5(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { + debug!("emscripten::___syscall5 (open) {}", which); + let pathname: u32 = varargs.get(ctx); + let flags: i32 = varargs.get(ctx); + let mode: u32 = varargs.get(ctx); + let pathname_addr = emscripten_memory_pointer!(ctx.memory(0), pathname) as *const i8; + let path_str = unsafe { std::ffi::CStr::from_ptr(pathname_addr).to_str().unwrap() }; + let fd = unsafe { open(pathname_addr, flags, mode) }; + debug!( + "=> pathname: {}, flags: {}, mode: {} = fd: {}\npath: {}", + pathname, flags, mode, fd, path_str + ); + fd +} + // chown pub fn ___syscall212(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall212 (chown) {}", which); diff --git a/lib/emscripten/src/syscalls/windows.rs b/lib/emscripten/src/syscalls/windows.rs index 41c4cf7eb..d2584bbd4 100644 --- a/lib/emscripten/src/syscalls/windows.rs +++ b/lib/emscripten/src/syscalls/windows.rs @@ -1,10 +1,62 @@ +use crate::utils::copy_cstr_into_wasm; +use crate::utils::read_string_from_wasm; use crate::varargs::VarArgs; use libc::mkdir; +use libc::open; +use rand::Rng; +use std::env; +use std::ffi::CStr; +use std::ffi::CString; +use std::fs::File; +use std::io::Write; use std::os::raw::c_int; use wasmer_runtime_core::vm::Ctx; type pid_t = c_int; +/// open +pub fn ___syscall5(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { + debug!("emscripten::___syscall5 (open) {}", which); + let pathname: u32 = varargs.get(ctx); + let flags: i32 = varargs.get(ctx); + let mode: u32 = varargs.get(ctx); + let pathname_addr = emscripten_memory_pointer!(ctx.memory(0), pathname) as *const i8; + let path_str = unsafe { std::ffi::CStr::from_ptr(pathname_addr).to_str().unwrap() }; + match path_str { + "/dev/urandom" => { + // create a fake urandom file for windows, super hacky + // put it in the temp directory so we can just forget about it + let mut tmp_dir = env::temp_dir(); + tmp_dir.push("urandom"); + let tmp_dir_str = tmp_dir.to_str().unwrap(); + let tmp_dir_c_str = CString::new(tmp_dir_str).unwrap(); + let ptr = tmp_dir_c_str.as_ptr() as *const i8; + let mut urandom_file = File::create(tmp_dir).unwrap(); + // create some random bytes and put them into the file + let random_bytes = rand::thread_rng().gen::<[u8; 32]>(); + urandom_file.write_all(&random_bytes); + // put the file path string into wasm memory + let urandom_file_offset = unsafe { copy_cstr_into_wasm(ctx, ptr) }; + let raw_pointer_to_urandom_file = + emscripten_memory_pointer!(ctx.memory(0), urandom_file_offset) as *const i8; + let fd = unsafe { open(raw_pointer_to_urandom_file, flags, mode) }; + debug!( + "=> pathname: {}, flags: {}, mode: {} = fd: {}\npath: {}", + pathname, flags, mode, fd, s + ); + fd + } + _ => { + let fd = unsafe { open(pathname_addr, flags, mode) }; + debug!( + "=> pathname: {}, flags: {}, mode: {} = fd: {}\npath: {}", + pathname, flags, mode, fd, path_str + ); + fd + } + } +} + // chown pub fn ___syscall212(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall212 (chown) {}", which); diff --git a/lib/runtime-core/src/typed_func.rs b/lib/runtime-core/src/typed_func.rs index 19efcbe4e..6e59d0d4a 100644 --- a/lib/runtime-core/src/typed_func.rs +++ b/lib/runtime-core/src/typed_func.rs @@ -246,6 +246,7 @@ impl_traits!([C] S8, A, B, C, D, E, F, G, H); impl_traits!([C] S9, A, B, C, D, E, F, G, H, I); impl_traits!([C] S10, A, B, C, D, E, F, G, H, I, J); impl_traits!([C] S11, A, B, C, D, E, F, G, H, I, J, K); +impl_traits!([C] S12, A, B, C, D, E, F, G, H, I, J, K, L); impl<'a, Args, Rets, Safety> IsExport for Func<'a, Args, Rets, Safety> where