Merge branch 'master' into feature/benchmarks

This commit is contained in:
Mackenzie Clark 2019-02-22 12:14:11 -08:00 committed by GitHub
commit 70ba4ec466
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 637 additions and 22 deletions

1
Cargo.lock generated
View File

@ -1276,6 +1276,7 @@ dependencies = [
"glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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)", "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)", "wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmer-clif-backend 0.1.2", "wasmer-clif-backend 0.1.2",

View File

@ -15,6 +15,9 @@ libc = { git = "https://github.com/rust-lang/libc" }
byteorder = "1" byteorder = "1"
time = "0.1.41" time = "0.1.41"
[target.'cfg(windows)'.dependencies]
rand = "0.6"
[dev-dependencies] [dev-dependencies]
wasmer-clif-backend = { path = "../clif-backend", version = "0.1.0" } wasmer-clif-backend = { path = "../clif-backend", version = "0.1.0" }
wabt = "0.7.2" wabt = "0.7.2"

View File

@ -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"); debug!("emscripten::___gxx_personality_v0");
0 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");
}
}

View File

@ -7,6 +7,7 @@ use std::os::raw::c_char;
use crate::env::call_malloc; use crate::env::call_malloc;
use crate::utils::{copy_cstr_into_wasm, read_string_from_wasm}; use crate::utils::{copy_cstr_into_wasm, read_string_from_wasm};
use std::ffi::CStr;
use wasmer_runtime_core::vm::Ctx; use wasmer_runtime_core::vm::Ctx;
extern "C" { extern "C" {

View File

@ -104,6 +104,35 @@ pub struct EmscriptenData<'a> {
pub dyn_call_vii: Option<Func<'a, (i32, i32, i32)>>, pub dyn_call_vii: Option<Func<'a, (i32, i32, i32)>>,
pub dyn_call_viii: Option<Func<'a, (i32, i32, i32, i32)>>, pub dyn_call_viii: Option<Func<'a, (i32, i32, i32, i32)>>,
pub dyn_call_viiii: Option<Func<'a, (i32, i32, i32, i32, i32)>>, pub dyn_call_viiii: Option<Func<'a, (i32, i32, i32, i32, i32)>>,
// round 2
pub dyn_call_dii: Option<Func<'a, (i32, i32, i32), f64>>,
pub dyn_call_diiii: Option<Func<'a, (i32, i32, i32, i32, i32), f64>>,
pub dyn_call_iiiii: Option<Func<'a, (i32, i32, i32, i32, i32), i32>>,
pub dyn_call_iiiiii: Option<Func<'a, (i32, i32, i32, i32, i32, i32), i32>>,
pub dyn_call_vd: Option<Func<'a, (i32, f64)>>,
pub dyn_call_viiiii: Option<Func<'a, (i32, i32, i32, i32, i32, i32)>>,
pub dyn_call_viiiiii: Option<Func<'a, (i32, i32, i32, i32, i32, i32, i32)>>,
pub dyn_call_viiiiiii: Option<Func<'a, (i32, i32, i32, i32, i32, i32, i32, i32)>>,
pub dyn_call_viiiiiiii: Option<Func<'a, (i32, i32, i32, i32, i32, i32, i32, i32, i32)>>,
pub dyn_call_viiiiiiiii: Option<Func<'a, (i32, i32, i32, i32, i32, i32, i32, i32, i32, i32)>>,
pub dyn_call_iiji: Option<Func<'a, (i32, i32, i32, i32, i32), i32>>,
pub dyn_call_j: Option<Func<'a, i32, i32>>,
pub dyn_call_ji: Option<Func<'a, (i32, i32), i32>>,
pub dyn_call_jij: Option<Func<'a, (i32, i32, i32, i32), i32>>,
pub dyn_call_jjj: Option<Func<'a, (i32, i32, i32, i32, i32), i32>>,
pub dyn_call_viiij: Option<Func<'a, (i32, i32, i32, i32, i32, i32)>>,
pub dyn_call_viiijiiii: Option<Func<'a, (i32, i32, i32, i32, i32, i32, i32, i32, i32, i32)>>,
pub dyn_call_viiijiiiiii:
Option<Func<'a, (i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32)>>,
pub dyn_call_viij: Option<Func<'a, (i32, i32, i32, i32, i32)>>,
pub dyn_call_viiji: Option<Func<'a, (i32, i32, i32, i32, i32, i32)>>,
pub dyn_call_viijiii: Option<Func<'a, (i32, i32, i32, i32, i32, i32, i32, i32)>>,
pub dyn_call_viijj: Option<Func<'a, (i32, i32, i32, i32, i32, i32, i32)>>,
pub dyn_call_vij: Option<Func<'a, (i32, i32, i32, i32)>>,
pub dyn_call_viji: Option<Func<'a, (i32, i32, i32, i32, i32)>>,
pub dyn_call_vijiii: Option<Func<'a, (i32, i32, i32, i32, i32, i32, i32)>>,
pub dyn_call_vijj: Option<Func<'a, (i32, i32, i32, i32, i32, i32)>>,
} }
impl<'a> EmscriptenData<'a> { impl<'a> EmscriptenData<'a> {
@ -128,6 +157,34 @@ impl<'a> EmscriptenData<'a> {
let dyn_call_viii = instance.func("dynCall_viii").ok(); let dyn_call_viii = instance.func("dynCall_viii").ok();
let dyn_call_viiii = instance.func("dynCall_viiii").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 { EmscriptenData {
malloc, malloc,
free, free,
@ -144,6 +201,34 @@ impl<'a> EmscriptenData<'a> {
dyn_call_vii, dyn_call_vii,
dyn_call_viii, dyn_call_viii,
dyn_call_viiii, 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_rdlock" => func!(crate::emscripten_target::_pthread_rwlock_rdlock),
"_pthread_rwlock_unlock" => func!(crate::emscripten_target::_pthread_rwlock_unlock), "_pthread_rwlock_unlock" => func!(crate::emscripten_target::_pthread_rwlock_unlock),
"___gxx_personality_v0" => func!(crate::emscripten_target::___gxx_personality_v0), "___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" => { "global" => {
"NaN" => Global::new(Value::F64(f64::NAN)), "NaN" => Global::new(Value::F64(f64::NAN)),

View File

@ -28,7 +28,7 @@ use libc::{
getpid, getpid,
// iovec, // iovec,
lseek, lseek,
open, // open,
read, read,
// readv, // readv,
rmdir, 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 } 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 /// close
pub fn ___syscall6(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { pub fn ___syscall6(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall6 (close) {}", which); debug!("emscripten::___syscall6 (close) {}", which);

View File

@ -24,6 +24,7 @@ use libc::{
listen, listen,
mkdir, mkdir,
msghdr, msghdr,
open,
pid_t, pid_t,
pread, pread,
pwrite, pwrite,
@ -76,6 +77,22 @@ use libc::SO_NOSIGPIPE;
#[cfg(not(target_os = "darwin"))] #[cfg(not(target_os = "darwin"))]
const SO_NOSIGPIPE: c_int = 0; 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 // chown
pub fn ___syscall212(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { pub fn ___syscall212(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall212 (chown) {}", which); debug!("emscripten::___syscall212 (chown) {}", which);

View File

@ -1,10 +1,62 @@
use crate::utils::copy_cstr_into_wasm;
use crate::utils::read_string_from_wasm;
use crate::varargs::VarArgs; use crate::varargs::VarArgs;
use libc::mkdir; 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 std::os::raw::c_int;
use wasmer_runtime_core::vm::Ctx; use wasmer_runtime_core::vm::Ctx;
type pid_t = c_int; 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 // chown
pub fn ___syscall212(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { pub fn ___syscall212(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall212 (chown) {}", which); debug!("emscripten::___syscall212 (chown) {}", which);

View File

@ -19,7 +19,7 @@ int main()
uint32_t len = wasmer_table_length(table); uint32_t len = wasmer_table_length(table);
printf("Table length: %d\n", len); printf("Table length: %d\n", len);
assert(len == 15); assert(len == 10);
// wasmer_result_t grow_result1 = wasmer_table_grow(table, 5); // wasmer_result_t grow_result1 = wasmer_table_grow(table, 5);
// assert(grow_result1 == WASMER_OK); // assert(grow_result1 == WASMER_OK);

View File

@ -306,3 +306,21 @@ impl Clone for SharedMemory {
unimplemented!() unimplemented!()
} }
} }
#[cfg(test)]
mod memory_tests {
use super::{Memory, MemoryDescriptor, Pages};
#[test]
fn test_initial_memory_size() {
let unshared_memory = Memory::new(MemoryDescriptor {
minimum: Pages(10),
maximum: Some(Pages(20)),
shared: false,
})
.unwrap();
assert_eq!(unshared_memory.size(), Pages(10));
}
}

View File

@ -53,10 +53,7 @@ impl AnyfuncTable {
desc: TableDescriptor, desc: TableDescriptor,
local: &mut vm::LocalTable, local: &mut vm::LocalTable,
) -> Result<Box<Self>, CreationError> { ) -> Result<Box<Self>, CreationError> {
let initial_table_backing_len = match desc.maximum { let initial_table_backing_len = desc.minimum as usize;
Some(max) => max,
None => desc.minimum,
} as usize;
let mut storage = Box::new(AnyfuncTable { let mut storage = Box::new(AnyfuncTable {
backing: vec![vm::Anyfunc::null(); initial_table_backing_len], backing: vec![vm::Anyfunc::null(); initial_table_backing_len],

View File

@ -148,3 +148,21 @@ impl fmt::Debug for Table {
.finish() .finish()
} }
} }
#[cfg(test)]
mod table_tests {
use super::{ElementType, Table, TableDescriptor};
#[test]
fn test_initial_table_size() {
let table = Table::new(TableDescriptor {
element: ElementType::Anyfunc,
minimum: 10,
maximum: Some(20),
})
.unwrap();
assert_eq!(table.size(), 10);
}
}

View File

@ -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] 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] 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] 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> impl<'a, Args, Rets, Safety> IsExport for Func<'a, Args, Rets, Safety>
where where