diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 609e0c83f7c..b29669d33b3 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -12,4 +12,4 @@ links to related issues, and the context of the PR. # Review -- [ ] Create a short description of the the change in the CHANGELOG.md file +- [ ] Add a short description of the the change to the CHANGELOG.md file diff --git a/CHANGELOG.md b/CHANGELOG.md index 1651f7ffbeb..14f7480991d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ Blocks of changes will separated by version increments. ## **[Unreleased]** +- [#821](https://github.com/wasmerio/wasmer/issues/821) Remove patch version on most deps Cargo manifests. This gives Wasmer library users more control over which versions of the deps they use. +- [#820](https://github.com/wasmerio/wasmer/issues/820) Remove null-pointer checks in `WasmPtr` from runtime-core, re-add them in Emscripten +- [#803](https://github.com/wasmerio/wasmer/issues/803) Add method to `Ctx` to invoke functions by their `TableIndex` - [#790](https://github.com/wasmerio/wasmer/pull/790) Fix flaky test failure with LLVM, switch to large code model. - [#788](https://github.com/wasmerio/wasmer/pull/788) Use union merge on the changelog file. - [#785](https://github.com/wasmerio/wasmer/pull/785) Include Apache license file for spectests. diff --git a/Cargo.lock b/Cargo.lock index b26948e6846..3d8c85a48c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,11 +16,6 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "approx" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "arrayref" version = "0.3.5" @@ -205,16 +200,6 @@ name = "cfg-if" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "cgmath" -version = "0.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "approx 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "clang-sys" version = "0.28.1" @@ -255,15 +240,6 @@ dependencies = [ "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "colored" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winconsole 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "constant_time_eq" version = "0.1.4" @@ -810,14 +786,6 @@ dependencies = [ "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "num-traits" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "num-traits" version = "0.2.8" @@ -947,18 +915,6 @@ dependencies = [ "proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "rand" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "rand" version = "0.7.2" @@ -1108,11 +1064,6 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "rgb" -version = "0.8.14" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "rustc-demangle" version = "0.1.16" @@ -1691,7 +1642,6 @@ dependencies = [ "bincode 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "blake2b_simd 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", - "colored 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "errno 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "field-offset 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1717,7 +1667,6 @@ name = "wasmer-singlepass-backend" version = "0.7.0" dependencies = [ "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "colored 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "dynasm 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "dynasmrt 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1843,21 +1792,9 @@ dependencies = [ "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "winconsole" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cgmath 0.16.1 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rgb 0.8.14 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - [metadata] "checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -"checksum approx 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08abcc3b4e9339e33a3d0a5ed15d84a687350c05689d825e0f6655eef9e76a94" "checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee" "checksum arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d73f9beda665eaa98ab9e4f7442bd4e7de6652587de55b2525e52e29c1b0ba" "checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" @@ -1879,12 +1816,10 @@ dependencies = [ "checksum cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)" = "4fc9a35e1f4290eb9e5fc54ba6cf40671ed2a2514c3eeb2b2a908dda2ea5a1be" "checksum cexpr 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a7fa24eb00d5ffab90eaeaf1092ac85c04c64aaf358ea6f84505b8116d24c6af" "checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" -"checksum cgmath 0.16.1 (registry+https://github.com/rust-lang/crates.io-index)" = "64a4b57c8f4e3a2e9ac07e0f6abc9c24b6fc9e1b54c3478cfb598f3d0023e51c" "checksum clang-sys 0.28.1 (registry+https://github.com/rust-lang/crates.io-index)" = "81de550971c976f176130da4b2978d3b524eaa0fd9ac31f3ceb5ae1231fb4853" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum cmake 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "81fb25b677f8bf1eb325017cb6bb8452f87969db0fedb4f757b297bee78a7c62" -"checksum colored 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6cdb90b60f2927f8d76139c72dbde7e10c3a2bc47c8594c9c7a66529f2687c03" "checksum constant_time_eq 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "995a44c877f9212528ccc74b21a232f66ad69001e40ede5bcee2ac9ef2657120" "checksum cranelift-bforest 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)" = "409f92af3dd276e112b72873a3ef02613e3c5f55b81d5d5d04f3157d4f8b8c54" "checksum cranelift-codegen 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b303542a56fba4cbaeea099fb30ed078b50de0e765fd69f7f5f410adbe31d95b" @@ -1946,7 +1881,6 @@ dependencies = [ "checksum nix 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3b2e0b4f3320ed72aaedb9a5ac838690a8047c7b275da22711fddff4f8a14229" "checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" "checksum nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6" -"checksum num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31" "checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32" "checksum num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcef43580c035376c0705c42792c294b66974abbfd2789b511784023f71f3273" "checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" @@ -1963,7 +1897,6 @@ dependencies = [ "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" "checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" "checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" -"checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" "checksum rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3ae1b169243eaf61759b8475a998f0a385e42042370f3a7dbaf35246eacc8412" "checksum rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853" "checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" @@ -1981,7 +1914,6 @@ dependencies = [ "checksum regex-automata 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "92b73c2a1770c255c240eaa4ee600df1704a38dc3feaa6e949e7fcd4f8dc09f9" "checksum regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716" "checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" -"checksum rgb 0.8.14 (registry+https://github.com/rust-lang/crates.io-index)" = "2089e4031214d129e201f8c3c8c2fe97cd7322478a0d1cdf78e7029b0042efdb" "checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c92464b447c0ee8c4fb3824ecc8383b81717b9f1e74ba2e72540aef7b9f82997" @@ -2043,4 +1975,3 @@ dependencies = [ "checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" "checksum wincolor 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "96f5016b18804d24db43cebf3c77269e7569b8954a8464501c216cc5e070eaa9" -"checksum winconsole 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ef84b96d10db72dd980056666d7f1e7663ce93d82fa33b63e71c966f4cf5032" diff --git a/Cargo.toml b/Cargo.toml index 31ba526bd0b..d433ad45630 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,9 +19,9 @@ include = [ ] [dependencies] -byteorder = "1.3.2" -errno = "0.2.4" -structopt = "0.3.0" +byteorder = "1.3" +errno = "0.2" +structopt = "0.3" wabt = "0.9.1" wasmer-clif-backend = { path = "lib/clif-backend" } wasmer-singlepass-backend = { path = "lib/singlepass-backend", optional = true } @@ -58,13 +58,13 @@ members = [ "lib/wasi-tests", "lib/emscripten-tests", "lib/middleware-common-tests", - "examples/plugin-for-example" + "examples/plugin-for-example", ] [build-dependencies] wabt = "0.9.1" -glob = "0.3.0" -rustc_version = "0.2.3" +glob = "0.3" +rustc_version = "0.2" [dev-dependencies] serde = { version = "1", features = ["derive"] } # used by the plugin example @@ -105,3 +105,7 @@ managed = ["backend-singlepass", "wasmer-runtime-core/managed"] [[example]] name = "plugin" crate-type = ["bin"] + +[[example]] +name = "callback" +crate-type = ["bin"] diff --git a/Makefile b/Makefile index 007e89853b0..5eb9c9aa23e 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: spectests emtests clean build install lint precommit docs +.PHONY: spectests emtests clean build install lint precommit docs examples # Generate files generate-spectests: @@ -111,12 +111,16 @@ test: spectests emtests middleware wasitests circleci-clean test-rest # Integration tests -integration-tests: release-clif +integration-tests: release-clif examples echo "Running Integration Tests" ./integration_tests/lua/test.sh ./integration_tests/nginx/test.sh ./integration_tests/cowsay/test.sh +examples: + cargo run --example plugin + cargo run --example callback + # Utils lint: diff --git a/examples/callback-guest/README.md b/examples/callback-guest/README.md new file mode 100644 index 00000000000..6439ef00dd4 --- /dev/null +++ b/examples/callback-guest/README.md @@ -0,0 +1,5 @@ +# Call back guest + +This is part of the `callback` example. This Wasm module passes host imports and its own functions to the Wasm host to execute. + +See `examples/callback.rs` for the host diff --git a/examples/callback-guest/callback-guest.rs b/examples/callback-guest/callback-guest.rs new file mode 100644 index 00000000000..129ad05c8ac --- /dev/null +++ b/examples/callback-guest/callback-guest.rs @@ -0,0 +1,24 @@ +extern "C" { + fn call_guest_fn(f: u32) -> u32; + fn call_guest_fn2(f: u32) -> u32; + fn host_callback() -> u32; +} + +#[no_mangle] +fn test_callback() -> u32 { + 42 +} + +#[no_mangle] +fn test_callback2() -> u32 { + 45 +} + +fn main() { + unsafe { call_guest_fn(test_callback as usize as u32) }; + unsafe { call_guest_fn(host_callback as usize as u32) }; + unsafe { call_guest_fn(test_callback2 as usize as u32) }; + unsafe { call_guest_fn2(test_callback2 as usize as u32) }; + unsafe { call_guest_fn2(test_callback as usize as u32) }; + unsafe { call_guest_fn2(host_callback as usize as u32) }; +} diff --git a/examples/callback-guest/callback-guest.wasm b/examples/callback-guest/callback-guest.wasm new file mode 100755 index 00000000000..05558297595 Binary files /dev/null and b/examples/callback-guest/callback-guest.wasm differ diff --git a/examples/callback.rs b/examples/callback.rs new file mode 100644 index 00000000000..e5969fec971 --- /dev/null +++ b/examples/callback.rs @@ -0,0 +1,46 @@ +/// This example demonstrates the use of callbacks: calling functions (Host and Wasm) +/// passed to us from the Wasm via hostcall +use wasmer_runtime::{compile_with, compiler_for_backend, func, imports, Backend, Ctx}; +use wasmer_runtime_core::{structures::TypedIndex, types::TableIndex}; + +static WASM: &'static str = "examples/callback-guest/callback-guest.wasm"; + +/// This function matches our arbitrarily decided callback signature +/// in this example we'll only call functions that take no arguments and return one value +fn host_callback(_ctx: &mut Ctx) -> u32 { + 55 +} + +fn call_guest_fn(ctx: &mut Ctx, guest_fn: u32) -> u32 { + // We get a TableIndex from our raw value passed in + let guest_fn_typed = TableIndex::new(guest_fn as usize); + // and use it to call the corresponding function + let result = ctx.call_with_table_index(guest_fn_typed, &[]).unwrap(); + + println!("Guest fn {} returned {:?}", guest_fn, result); + + 0 +} + +fn main() { + let wasm_bytes = + std::fs::read(WASM).expect(&format!("Could not read in WASM plugin at {}", WASM)); + + let imports = imports! { + "env" => { + "call_guest_fn" => func!(call_guest_fn), + "call_guest_fn2" => func!(call_guest_fn), + "host_callback" => func!(host_callback), + }, + }; + + let compiler = compiler_for_backend(Backend::default()).unwrap(); + let module = compile_with(&wasm_bytes[..], compiler.as_ref()).unwrap(); + let instance = module + .instantiate(&imports) + .expect("failed to instantiate wasm module"); + + let entry_point = instance.func::<(u32, u32), u32>("main").unwrap(); + + entry_point.call(0, 0).expect("START"); +} diff --git a/lib/clif-backend/Cargo.toml b/lib/clif-backend/Cargo.toml index be48208c7c5..3b662358d87 100644 --- a/lib/clif-backend/Cargo.toml +++ b/lib/clif-backend/Cargo.toml @@ -15,26 +15,26 @@ cranelift-codegen = { version = "0.31" } cranelift-entity = { version = "0.31" } cranelift-frontend = { package = "wasmer-clif-fork-frontend", version = "0.33" } cranelift-wasm = { package = "wasmer-clif-fork-wasm", version = "0.33" } -target-lexicon = "0.4.0" +target-lexicon = "0.4" wasmparser = "0.35.1" -byteorder = "1.3.2" -nix = "0.15.0" +byteorder = "1.3" +nix = "0.15" libc = "0.2.60" -rayon = "1.1.0" +rayon = "1.1" # Dependencies for caching. [dependencies.serde] -version = "1.0.99" +version = "1.0" features = ["rc"] [dependencies.serde_derive] -version = "1.0.98" +version = "1.0" [dependencies.serde_bytes] -version = "0.11.2" +version = "0.11" [dependencies.serde-bench] version = "0.0.7" [target.'cfg(windows)'.dependencies] -winapi = { version = "0.3.8", features = ["errhandlingapi", "minwindef", "minwinbase", "winnt"] } +winapi = { version = "0.3", features = ["errhandlingapi", "minwindef", "minwinbase", "winnt"] } wasmer-win-exception-handler = { path = "../win-exception-handler", version = "0.7.0" } [features] diff --git a/lib/emscripten-tests/Cargo.toml b/lib/emscripten-tests/Cargo.toml index 8c5f6c93e74..2954e84fbe5 100644 --- a/lib/emscripten-tests/Cargo.toml +++ b/lib/emscripten-tests/Cargo.toml @@ -20,7 +20,7 @@ wabt = "0.9.1" wasmer-dev-utils = { path = "../dev-utils", version = "0.7.0"} [build-dependencies] -glob = "0.3.0" +glob = "0.3" [features] clif = [] diff --git a/lib/emscripten/Cargo.toml b/lib/emscripten/Cargo.toml index f547e640e56..f5b6222b2db 100644 --- a/lib/emscripten/Cargo.toml +++ b/lib/emscripten/Cargo.toml @@ -8,14 +8,14 @@ repository = "https://github.com/wasmerio/wasmer" edition = "2018" [dependencies] -byteorder = "1.3.2" -lazy_static = "1.4.0" +byteorder = "1.3" +lazy_static = "1.4" libc = "0.2.60" -time = "0.1.42" +time = "0.1" wasmer-runtime-core = { path = "../runtime-core", version = "0.7.0" } [target.'cfg(windows)'.dependencies] -rand = "0.7.0" +rand = "0.7" [features] debug = ["wasmer-runtime-core/debug"] diff --git a/lib/emscripten/src/env/mod.rs b/lib/emscripten/src/env/mod.rs index 88fba54a6fc..a61a2bb9f28 100644 --- a/lib/emscripten/src/env/mod.rs +++ b/lib/emscripten/src/env/mod.rs @@ -12,14 +12,14 @@ pub use self::windows::*; use libc::c_char; -use crate::{allocate_on_stack, EmscriptenData}; +use crate::{ + allocate_on_stack, + ptr::{Array, WasmPtr}, + EmscriptenData, +}; use std::os::raw::c_int; -use wasmer_runtime_core::{ - memory::ptr::{Array, WasmPtr}, - types::ValueType, - vm::Ctx, -}; +use wasmer_runtime_core::{types::ValueType, vm::Ctx}; pub fn call_malloc(ctx: &mut Ctx, size: u32) -> u32 { get_emscripten_data(ctx) diff --git a/lib/emscripten/src/env/unix/mod.rs b/lib/emscripten/src/env/unix/mod.rs index 0e62e8e2f62..9516504950d 100644 --- a/lib/emscripten/src/env/unix/mod.rs +++ b/lib/emscripten/src/env/unix/mod.rs @@ -9,11 +9,9 @@ use std::mem; 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::{ - memory::ptr::{Array, WasmPtr}, - vm::Ctx, -}; +use wasmer_runtime_core::vm::Ctx; // #[no_mangle] /// emscripten: _getenv // (name: *const char) -> *const c_char; diff --git a/lib/emscripten/src/env/windows/mod.rs b/lib/emscripten/src/env/windows/mod.rs index d6ba0b0da27..025a01bd742 100644 --- a/lib/emscripten/src/env/windows/mod.rs +++ b/lib/emscripten/src/env/windows/mod.rs @@ -6,8 +6,9 @@ use std::mem; 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::{memory::ptr::WasmPtr, vm::Ctx}; +use wasmer_runtime_core::vm::Ctx; extern "C" { #[link_name = "_putenv"] diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index ba25b4be82a..72740538139 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -62,6 +62,7 @@ mod math; mod memory; mod process; mod pthread; +mod ptr; mod signal; mod storage; mod syscalls; diff --git a/lib/emscripten/src/ptr.rs b/lib/emscripten/src/ptr.rs new file mode 100644 index 00000000000..34cd683648e --- /dev/null +++ b/lib/emscripten/src/ptr.rs @@ -0,0 +1,116 @@ +//! This is a wrapper around the `WasmPtr` abstraction that does not allow deref of address 0 +//! This is a common assumption in Emscripten code + +// this is a wrapper with extra logic around the runtime-core `WasmPtr`, so we +// don't want to warn about unusued code here +#![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}, +}; + +#[repr(transparent)] +pub struct WasmPtr(ptr::WasmPtr); + +unsafe impl ValueType for WasmPtr {} +impl Copy for WasmPtr {} + +impl Clone for WasmPtr { + fn clone(&self) -> Self { + Self(self.0.clone()) + } +} + +impl fmt::Debug for WasmPtr { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{:?}", self.0) + } +} + +unsafe impl WasmExternType for WasmPtr { + 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)) + } +} + +impl PartialEq for WasmPtr { + fn eq(&self, other: &Self) -> bool { + self.0 == other.0 + } +} + +impl Eq for WasmPtr {} + +impl WasmPtr { + #[inline(always)] + pub fn new(offset: u32) -> Self { + Self(ptr::WasmPtr::new(offset)) + } + + #[inline(always)] + pub fn offset(self) -> u32 { + self.0.offset() + } +} + +impl WasmPtr { + #[inline(always)] + pub fn deref<'a>(self, memory: &'a Memory) -> Option<&'a Cell> { + if self.0.offset() == 0 { + None + } else { + self.0.deref(memory) + } + } + + #[inline(always)] + pub unsafe fn deref_mut<'a>(self, memory: &'a Memory) -> Option<&'a mut Cell> { + if self.0.offset() == 0 { + None + } else { + self.0.deref_mut(memory) + } + } +} + +impl WasmPtr { + #[inline(always)] + pub fn deref<'a>(self, memory: &'a Memory, index: u32, length: u32) -> Option<&'a [Cell]> { + if self.0.offset() == 0 { + None + } else { + self.0.deref(memory, index, length) + } + } + + #[inline] + pub unsafe fn deref_mut<'a>( + self, + memory: &'a Memory, + index: u32, + length: u32, + ) -> Option<&'a mut [Cell]> { + if self.0.offset() == 0 { + None + } else { + self.0.deref_mut(memory, index, length) + } + } + + #[inline(always)] + pub fn get_utf8_string<'a>(self, memory: &'a Memory, str_len: u32) -> Option<&'a str> { + if self.0.offset() == 0 { + None + } else { + self.0.get_utf8_string(memory, str_len) + } + } +} diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index b098bd1529e..ba5965fde34 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -10,7 +10,10 @@ pub use self::unix::*; #[cfg(windows)] pub use self::windows::*; -use crate::utils::{copy_stat_into_wasm, get_cstr_path, get_current_directory}; +use crate::{ + ptr::{Array, WasmPtr}, + utils::{copy_stat_into_wasm, get_cstr_path, get_current_directory}, +}; use super::varargs::VarArgs; use byteorder::{ByteOrder, LittleEndian}; @@ -40,10 +43,7 @@ use libc::{ write, // ENOTTY, }; -use wasmer_runtime_core::{ - memory::ptr::{Array, WasmPtr}, - vm::Ctx, -}; +use wasmer_runtime_core::vm::Ctx; use super::env; use std::cell::Cell; diff --git a/lib/emscripten/src/syscalls/unix.rs b/lib/emscripten/src/syscalls/unix.rs index 000a3e31920..efcff0a5ead 100644 --- a/lib/emscripten/src/syscalls/unix.rs +++ b/lib/emscripten/src/syscalls/unix.rs @@ -1,4 +1,4 @@ -use crate::varargs::VarArgs; +use crate::{ptr::WasmPtr, varargs::VarArgs}; #[cfg(target_os = "macos")] use libc::size_t; /// NOTE: TODO: These syscalls only support wasm_32 for now because they assume offsets are u32 @@ -111,7 +111,7 @@ fn translate_ioctl(wasm_ioctl: u32) -> c_ulong { #[allow(unused_imports)] use std::ffi::CStr; -use wasmer_runtime_core::{memory::ptr::WasmPtr, vm::Ctx}; +use wasmer_runtime_core::vm::Ctx; use crate::env::EmSockAddr; use crate::utils::{self, get_cstr_path}; diff --git a/lib/llvm-backend/Cargo.toml b/lib/llvm-backend/Cargo.toml index ca4e1e51ea6..2e198a6c39f 100644 --- a/lib/llvm-backend/Cargo.toml +++ b/lib/llvm-backend/Cargo.toml @@ -8,10 +8,10 @@ readme = "README.md" [dependencies] wasmer-runtime-core = { path = "../runtime-core", version = "0.7.0" } wasmparser = "0.35.1" -smallvec = "0.6.10" +smallvec = "0.6" goblin = "0.0.24" libc = "0.2.60" -capstone = { version = "0.6.0", optional = true } +capstone = { version = "0.6", optional = true } byteorder = "1" [dependencies.inkwell] @@ -21,17 +21,17 @@ default-features = false features = ["llvm8-0", "target-x86"] [target.'cfg(unix)'.dependencies] -nix = "0.15.0" +nix = "0.15" [target.'cfg(windows)'.dependencies] -winapi = { version = "0.3.8", features = ["memoryapi"] } +winapi = { version = "0.3", features = ["memoryapi"] } [build-dependencies] cc = "1.0" -lazy_static = "1.4.0" -regex = "1.2.1" +lazy_static = "1.4" +regex = "1.2" semver = "0.9" -rustc_version = "0.2.3" +rustc_version = "0.2" [dev-dependencies] wabt = "0.9.1" diff --git a/lib/llvm-backend/src/code.rs b/lib/llvm-backend/src/code.rs index 2696d2896c6..8ac76fe269b 100644 --- a/lib/llvm-backend/src/code.rs +++ b/lib/llvm-backend/src/code.rs @@ -1176,7 +1176,11 @@ impl FunctionCodeGenerator for LLVMFunctionCodeGenerator { BasicTypeEnum::FloatType(float_ty) => { float_ty.const_float(0.0).as_basic_value_enum() } - _ => unimplemented!(), + _ => { + return Err(CodegenError { + message: "Operator::End phi type unimplemented".to_string(), + }); + } }; state.push1(placeholder_value); phi.as_instruction().erase_from_basic_block(); @@ -1741,7 +1745,12 @@ impl FunctionCodeGenerator for LLVMFunctionCodeGenerator { _ => value, }); } - _ => unimplemented!("multi-value returns"), + _ => { + return Err(CodegenError { + message: "Operator::CallIndirect multi-value returns unimplemented" + .to_string(), + }); + } } } @@ -6853,7 +6862,9 @@ impl FunctionCodeGenerator for LLVMFunctionCodeGenerator { state.push1(result.try_as_basic_value().left().unwrap()); } _ => { - unimplemented!("{:?}", op); + return Err(CodegenError { + message: format!("Operator {:?} unimplemented", op), + }); } } @@ -6876,7 +6887,11 @@ impl FunctionCodeGenerator for LLVMFunctionCodeGenerator { "return", ))); } - _ => unimplemented!("multi-value returns not yet implemented"), + _ => { + return Err(CodegenError { + message: "multi-value returns not yet implemented".to_string(), + }); + } } Ok(()) } @@ -7051,7 +7066,10 @@ impl ModuleCodeGenerator self.context.as_ref().unwrap(), self.builder.as_ref().unwrap(), self.intrinsics.as_ref().unwrap(), - ); + ) + .map_err(|e| CodegenError { + message: format!("trampolines generation error: {:?}", e), + })?; if let Some(path) = unsafe { &crate::GLOBAL_OPTIONS.pre_opt_ir } { self.module.print_to_file(path).unwrap(); diff --git a/lib/llvm-backend/src/trampolines.rs b/lib/llvm-backend/src/trampolines.rs index cebfa9d4671..c9bd50e1b47 100644 --- a/lib/llvm-backend/src/trampolines.rs +++ b/lib/llvm-backend/src/trampolines.rs @@ -20,7 +20,7 @@ pub fn generate_trampolines( context: &Context, builder: &Builder, intrinsics: &Intrinsics, -) { +) -> Result<(), String> { for (sig_index, sig) in info.signatures.iter() { let func_type = signatures[sig_index]; @@ -42,8 +42,9 @@ pub fn generate_trampolines( Some(Linkage::External), ); - generate_trampoline(trampoline_func, sig, context, builder, intrinsics); + generate_trampoline(trampoline_func, sig, context, builder, intrinsics)?; } + Ok(()) } fn generate_trampoline( @@ -52,7 +53,7 @@ fn generate_trampoline( context: &Context, builder: &Builder, intrinsics: &Intrinsics, -) { +) -> Result<(), String> { let entry_block = context.append_basic_block(&trampoline_func, "entry"); builder.position_at_end(&entry_block); @@ -64,7 +65,7 @@ fn generate_trampoline( args_ptr.into_pointer_value(), returns_ptr.into_pointer_value(), ), - _ => unimplemented!(), + _ => return Err("trampoline function unimplemented".to_string()), }; let cast_ptr_ty = |wasmer_ty| match wasmer_ty { @@ -108,8 +109,11 @@ fn generate_trampoline( call_site.try_as_basic_value().left().unwrap(), ); } - _ => unimplemented!("multi-value returns"), + _ => { + return Err("trampoline function multi-value returns unimplemented".to_string()); + } } builder.build_return(None); + Ok(()) } diff --git a/lib/runtime-c-api/Cargo.toml b/lib/runtime-c-api/Cargo.toml index 8aac30da31e..bcfa4bec5d1 100644 --- a/lib/runtime-c-api/Cargo.toml +++ b/lib/runtime-c-api/Cargo.toml @@ -32,4 +32,4 @@ llvm-backend = ["wasmer-runtime/llvm", "wasmer-runtime/default-backend-llvm"] singlepass-backend = ["wasmer-runtime/singlepass", "wasmer-runtime/default-backend-singlepass"] [build-dependencies] -cbindgen = "0.9.1" +cbindgen = "0.9" diff --git a/lib/runtime-c-api/tests/test-exports.c b/lib/runtime-c-api/tests/test-exports.c index 3af813d0e5c..893174908a5 100644 --- a/lib/runtime-c-api/tests/test-exports.c +++ b/lib/runtime-c-api/tests/test-exports.c @@ -242,7 +242,7 @@ int main() wasmer_result_t call_result = wasmer_export_func_call(exported_function, inputs, inputs_arity, outputs, outputs_arity); - printf("Result: %lld\n", outputs[0].value.I64); + printf("Result: %ld\n", outputs[0].value.I64); assert(outputs[0].value.I64 == 7); assert(call_result == WASMER_OK); diff --git a/lib/runtime-core/Cargo.toml b/lib/runtime-core/Cargo.toml index 8ce52ebe048..f683a974eb5 100644 --- a/lib/runtime-core/Cargo.toml +++ b/lib/runtime-core/Cargo.toml @@ -8,47 +8,46 @@ repository = "https://github.com/wasmerio/wasmer" edition = "2018" [dependencies] -nix = "0.15.0" -page_size = "0.4.1" +nix = "0.15" +page_size = "0.4" wasmparser = "0.35.1" -parking_lot = "0.9.0" -lazy_static = "1.4.0" -errno = "0.2.4" +parking_lot = "0.9" +lazy_static = "1.4" +errno = "0.2" libc = "0.2.60" -hex = "0.3.2" -smallvec = "0.6.10" +hex = "0.3" +smallvec = "0.6" bincode = "1.1" -colored = "1.8" [dependencies.indexmap] -version = "1.2.0" +version = "1.2" features = ["serde-1"] # Dependencies for caching. [dependencies.serde] -version = "1.0.99" +version = "1.0" # This feature is required for serde to support serializing/deserializing reference counted pointers (e.g. Rc and Arc). features = ["rc"] [dependencies.serde_derive] -version = "1.0.98" +version = "1.0" [dependencies.serde_bytes] -version = "0.11.2" +version = "0.11" [dependencies.serde-bench] version = "0.0.7" [dependencies.blake2b_simd] -version = "0.5.8" +version = "0.5" [dependencies.digest] -version = "0.8.1" +version = "0.8" [target.'cfg(windows)'.dependencies] -winapi = { version = "0.3.8", features = ["memoryapi"] } +winapi = { version = "0.3", features = ["memoryapi"] } [dev-dependencies] -field-offset = "0.1.1" +field-offset = "0.1" [build-dependencies] -blake2b_simd = "0.5.8" -rustc_version = "0.2.3" +blake2b_simd = "0.5" +rustc_version = "0.2" cc = "1.0" [features] diff --git a/lib/runtime-core/image-loading-linux-x86-64.s b/lib/runtime-core/image-loading-linux-x86-64.s index 1d86bab0806..859f010f830 100644 --- a/lib/runtime-core/image-loading-linux-x86-64.s +++ b/lib/runtime-core/image-loading-linux-x86-64.s @@ -81,7 +81,7 @@ pushq %r8 pushq %r9 pushq %r10 -callq get_boundary_register_preservation +callq get_boundary_register_preservation@PLT # Keep this consistent with BoundaryRegisterPreservation movq %r15, 0(%rax) diff --git a/lib/runtime-core/src/fault.rs b/lib/runtime-core/src/fault.rs index 2d46d8ca25c..a1a1f58c2f5 100644 --- a/lib/runtime-core/src/fault.rs +++ b/lib/runtime-core/src/fault.rs @@ -283,13 +283,10 @@ extern "C" fn signal_trap_handler( let image = build_instance_image(ctx, es_image); unwind_result = Box::new(image); } else { - use colored::*; if es_image.frames.len() > 0 { eprintln!( "\n{}", "Wasmer encountered an error while running your WebAssembly program." - .bold() - .red() ); es_image.print_backtrace_if_needed(); } diff --git a/lib/runtime-core/src/instance.rs b/lib/runtime-core/src/instance.rs index e6ba365f6ef..f1ce0a19376 100644 --- a/lib/runtime-core/src/instance.rs +++ b/lib/runtime-core/src/instance.rs @@ -527,29 +527,12 @@ fn call_func_with_index( args: &[Value], rets: &mut Vec, ) -> CallResult<()> { - rets.clear(); - let sig_index = *info .func_assoc .get(func_index) .expect("broken invariant, incorrect func index"); let signature = &info.signatures[sig_index]; - let num_results = signature.returns().len(); - let num_results = num_results - + signature - .returns() - .iter() - .filter(|&&ty| ty == Type::V128) - .count(); - rets.reserve(num_results); - - if !signature.check_param_value_types(args) { - Err(ResolveError::Signature { - expected: signature.clone(), - found: args.iter().map(|val| val.ty()).collect(), - })? - } let func_ptr = match func_index.local_or_import(info) { LocalOrImport::Local(local_func_index) => { @@ -567,6 +550,39 @@ fn call_func_with_index( } }; + let wasm = runnable + .get_trampoline(info, sig_index) + .expect("wasm trampoline"); + + call_func_with_index_inner(ctx_ptr, func_ptr, signature, wasm, args, rets) +} + +pub(crate) fn call_func_with_index_inner( + ctx_ptr: *mut vm::Ctx, + func_ptr: NonNull, + signature: &FuncSig, + wasm: Wasm, + args: &[Value], + rets: &mut Vec, +) -> CallResult<()> { + rets.clear(); + + let num_results = signature.returns().len(); + let num_results = num_results + + signature + .returns() + .iter() + .filter(|&&ty| ty == Type::V128) + .count(); + rets.reserve(num_results); + + if !signature.check_param_value_types(args) { + Err(ResolveError::Signature { + expected: signature.clone(), + found: args.iter().map(|val| val.ty()).collect(), + })? + } + let mut raw_args: SmallVec<[u64; 8]> = SmallVec::new(); for v in args { match v { @@ -598,9 +614,7 @@ fn call_func_with_index( trampoline, invoke, invoke_env, - } = runnable - .get_trampoline(info, sig_index) - .expect("wasm trampoline"); + } = wasm; let run_wasm = |result_space: *mut u64| unsafe { let mut trap_info = WasmTrapInfo::Unknown; diff --git a/lib/runtime-core/src/memory/ptr.rs b/lib/runtime-core/src/memory/ptr.rs index 0a9454acc27..abed45bfb67 100644 --- a/lib/runtime-core/src/memory/ptr.rs +++ b/lib/runtime-core/src/memory/ptr.rs @@ -46,9 +46,7 @@ fn align_pointer(ptr: usize, align: usize) -> usize { impl WasmPtr { #[inline] pub fn deref<'a>(self, memory: &'a Memory) -> Option<&'a Cell> { - if self.offset == 0 - || (self.offset as usize) + mem::size_of::() >= memory.size().bytes().0 - { + if (self.offset as usize) + mem::size_of::() >= memory.size().bytes().0 { return None; } unsafe { @@ -62,9 +60,7 @@ impl WasmPtr { #[inline] pub unsafe fn deref_mut<'a>(self, memory: &'a Memory) -> Option<&'a mut Cell> { - if self.offset == 0 - || (self.offset as usize) + mem::size_of::() >= memory.size().bytes().0 - { + if (self.offset as usize) + mem::size_of::() >= memory.size().bytes().0 { return None; } let cell_ptr = align_pointer( @@ -83,9 +79,7 @@ impl WasmPtr { let item_size = mem::size_of::() + (mem::size_of::() % mem::align_of::()); let slice_full_len = index as usize + length as usize; - if self.offset == 0 - || (self.offset as usize) + (item_size * slice_full_len) >= memory.size().bytes().0 - { + if (self.offset as usize) + (item_size * slice_full_len) >= memory.size().bytes().0 { return None; } @@ -112,9 +106,7 @@ impl WasmPtr { let item_size = mem::size_of::() + (mem::size_of::() % mem::align_of::()); let slice_full_len = index as usize + length as usize; - if self.offset == 0 - || (self.offset as usize) + (item_size * slice_full_len) >= memory.size().bytes().0 - { + if (self.offset as usize) + (item_size * slice_full_len) >= memory.size().bytes().0 { return None; } diff --git a/lib/runtime-core/src/parse.rs b/lib/runtime-core/src/parse.rs index 259a628dd74..b2ad3051e6c 100644 --- a/lib/runtime-core/src/parse.rs +++ b/lib/runtime-core/src/parse.rs @@ -392,14 +392,19 @@ pub fn read_module< } pub fn wp_type_to_type(ty: WpType) -> Result { - Ok(match ty { - WpType::I32 => Type::I32, - WpType::I64 => Type::I64, - WpType::F32 => Type::F32, - WpType::F64 => Type::F64, - WpType::V128 => Type::V128, - _ => panic!("broken invariant, invalid type"), - }) + match ty { + WpType::I32 => Ok(Type::I32), + WpType::I64 => Ok(Type::I64), + WpType::F32 => Ok(Type::F32), + WpType::F64 => Ok(Type::F64), + WpType::V128 => Ok(Type::V128), + _ => { + return Err(BinaryReaderError { + message: "broken invariant, invalid type", + offset: -1isize as usize, + }); + } + } } pub fn type_to_wp_type(ty: Type) -> WpType { diff --git a/lib/runtime-core/src/state.rs b/lib/runtime-core/src/state.rs index b6bbb95f50d..7b8dcd2b1c9 100644 --- a/lib/runtime-core/src/state.rs +++ b/lib/runtime-core/src/state.rs @@ -303,7 +303,7 @@ impl ExecutionStateImage { if let Ok(x) = env::var("WASMER_BACKTRACE") { if x == "1" { - eprintln!("{}", self.colored_output()); + eprintln!("{}", self.output()); return; } } @@ -311,9 +311,7 @@ impl ExecutionStateImage { eprintln!("Run with `WASMER_BACKTRACE=1` environment variable to display a backtrace."); } - pub fn colored_output(&self) -> String { - use colored::*; - + pub fn output(&self) -> String { fn join_strings(x: impl Iterator, sep: &str) -> String { let mut ret = String::new(); let mut first = true; @@ -341,8 +339,6 @@ impl ExecutionStateImage { i, x.map(|x| format!("{}", x)) .unwrap_or_else(|| "?".to_string()) - .bold() - .cyan() ) }), ", ", @@ -353,27 +349,23 @@ impl ExecutionStateImage { let mut ret = String::new(); if self.frames.len() == 0 { - ret += &"Unknown fault address, cannot read stack.".yellow(); + ret += &"Unknown fault address, cannot read stack."; ret += "\n"; } else { - ret += &"Backtrace:".bold(); + ret += &"Backtrace:"; ret += "\n"; for (i, f) in self.frames.iter().enumerate() { - ret += &format!("* Frame {} @ Local function {}", i, f.local_function_id).bold(); + ret += &format!("* Frame {} @ Local function {}", i, f.local_function_id); ret += "\n"; + ret += &format!(" {} {}\n", "Offset:", format!("{}", f.wasm_inst_offset),); ret += &format!( " {} {}\n", - "Offset:".bold().yellow(), - format!("{}", f.wasm_inst_offset).bold().cyan(), - ); - ret += &format!( - " {} {}\n", - "Locals:".bold().yellow(), + "Locals:", format_optional_u64_sequence(&f.locals) ); ret += &format!( " {} {}\n\n", - "Stack:".bold().yellow(), + "Stack:", format_optional_u64_sequence(&f.stack) ); } diff --git a/lib/runtime-core/src/table/anyfunc.rs b/lib/runtime-core/src/table/anyfunc.rs index 789f67ada2b..4a63c8f6249 100644 --- a/lib/runtime-core/src/table/anyfunc.rs +++ b/lib/runtime-core/src/table/anyfunc.rs @@ -44,7 +44,7 @@ impl<'a> From> for Anyfunc<'a> { } pub struct AnyfuncTable { - backing: Vec, + pub(crate) backing: Vec, max: Option, } diff --git a/lib/runtime-core/src/table/mod.rs b/lib/runtime-core/src/table/mod.rs index 2e11507b1de..1b61cd75438 100644 --- a/lib/runtime-core/src/table/mod.rs +++ b/lib/runtime-core/src/table/mod.rs @@ -10,7 +10,7 @@ use std::{cell::RefCell, fmt, ptr, rc::Rc}; mod anyfunc; pub use self::anyfunc::Anyfunc; -use self::anyfunc::AnyfuncTable; +pub(crate) use self::anyfunc::AnyfuncTable; use crate::error::GrowError; pub enum Element<'a> { diff --git a/lib/runtime-core/src/vm.rs b/lib/runtime-core/src/vm.rs index 51f883318d1..e3084a9c5fa 100644 --- a/lib/runtime-core/src/vm.rs +++ b/lib/runtime-core/src/vm.rs @@ -1,15 +1,19 @@ pub use crate::backing::{ImportBacking, LocalBacking, INTERNALS_SIZE}; use crate::{ + error::CallResult, + instance::call_func_with_index_inner, memory::{Memory, MemoryType}, module::{ModuleInfo, ModuleInner}, + sig_registry::SigRegistry, structures::TypedIndex, - types::{LocalOrImport, MemoryIndex}, + types::{LocalOrImport, MemoryIndex, TableIndex, Value}, vmcalls, }; use std::{ cell::UnsafeCell, ffi::c_void, - mem, ptr, + mem, + ptr::{self, NonNull}, sync::atomic::{AtomicUsize, Ordering}, sync::Once, }; @@ -393,6 +397,41 @@ impl Ctx { (*self.internal.internals)[field.index()] = value; } } + + /// Calls a host or Wasm function at the given table index + pub fn call_with_table_index( + &mut self, + index: TableIndex, + args: &[Value], + ) -> CallResult> { + let anyfunc_table = + unsafe { &*((**self.internal.tables).table as *mut crate::table::AnyfuncTable) }; + let Anyfunc { func, ctx, sig_id } = anyfunc_table.backing[index.index()]; + + let signature = SigRegistry.lookup_signature(unsafe { std::mem::transmute(sig_id.0) }); + let mut rets = vec![]; + + let wasm = { + let module = unsafe { &*self.module }; + let runnable = &module.runnable_module; + + let sig_index = SigRegistry.lookup_sig_index(signature.clone()); + runnable + .get_trampoline(&module.info, sig_index) + .expect("wasm trampoline") + }; + + call_func_with_index_inner( + ctx, + NonNull::new(func as *mut _).unwrap(), + &signature, + wasm, + args, + &mut rets, + )?; + + Ok(rets) + } } #[doc(hidden)] diff --git a/lib/runtime/Cargo.toml b/lib/runtime/Cargo.toml index 2321cf99607..29b90955e03 100644 --- a/lib/runtime/Cargo.toml +++ b/lib/runtime/Cargo.toml @@ -10,8 +10,8 @@ readme = "README.md" [dependencies] wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.7.0", optional = true } -lazy_static = "1.4.0" -memmap = "0.7.0" +lazy_static = "1.4" +memmap = "0.7" [dependencies.wasmer-runtime-core] path = "../runtime-core" @@ -23,7 +23,7 @@ version = "0.7.0" optional = true [dev-dependencies] -tempfile = "3.1.0" +tempfile = "3.1" criterion = "0.2" wabt = "0.9.1" diff --git a/lib/singlepass-backend/Cargo.toml b/lib/singlepass-backend/Cargo.toml index fd649456953..f90afad1278 100644 --- a/lib/singlepass-backend/Cargo.toml +++ b/lib/singlepass-backend/Cargo.toml @@ -13,9 +13,8 @@ wasmer-runtime-core = { path = "../runtime-core", version = "0.7.0" } wasmparser = "0.35.1" dynasm = "0.3.2" dynasmrt = "0.3.1" -lazy_static = "1.4.0" -byteorder = "1.3.2" -nix = "0.15.0" +lazy_static = "1.4" +byteorder = "1.3" +nix = "0.15" libc = "0.2.60" -smallvec = "0.6.10" -colored = "1.8" +smallvec = "0.6" diff --git a/lib/spectests/Cargo.toml b/lib/spectests/Cargo.toml index feab4eccbda..7b3e6adbea7 100644 --- a/lib/spectests/Cargo.toml +++ b/lib/spectests/Cargo.toml @@ -8,7 +8,7 @@ repository = "https://github.com/wasmerio/wasmer" edition = "2018" [dependencies] -glob = "0.3.0" +glob = "0.3" wasmer-runtime-core = { path = "../runtime-core", version = "0.7.0" } wasmer-clif-backend = { path = "../clif-backend", version = "0.7.0" } wasmer-llvm-backend = { path = "../llvm-backend", version = "0.7.0", optional = true } diff --git a/lib/wasi-tests/Cargo.toml b/lib/wasi-tests/Cargo.toml index 7b092710190..9462fc73173 100644 --- a/lib/wasi-tests/Cargo.toml +++ b/lib/wasi-tests/Cargo.toml @@ -18,7 +18,7 @@ wasmer-llvm-backend = { path = "../llvm-backend", version = "0.7.0", optional = [build-dependencies] -glob = "0.3.0" +glob = "0.3" [dev-dependencies] wasmer-clif-backend = { path = "../clif-backend", version = "0.7.0" } diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml index 70bdd69966c..af65b65e86a 100644 --- a/lib/wasi/Cargo.toml +++ b/lib/wasi/Cargo.toml @@ -9,16 +9,16 @@ edition = "2018" [dependencies] bincode = "1" -byteorder = "1.3.2" -generational-arena = { version = "0.2.2", features = ["serde"] } +byteorder = "1.3" +generational-arena = { version = "0.2", features = ["serde"] } libc = "0.2.60" -log = "0.4.8" -rand = "0.7.0" -time = "0.1.42" +log = "0.4" +rand = "0.7" +time = "0.1" typetag = "0.1" serde = { version = "1", features = ["derive"] } # wasmer-runtime-abi = { path = "../runtime-abi" } wasmer-runtime-core = { path = "../runtime-core", version = "0.7.0" } [target.'cfg(windows)'.dependencies] -winapi = "0.3.8" +winapi = "0.3" diff --git a/lib/win-exception-handler/Cargo.toml b/lib/win-exception-handler/Cargo.toml index dd67b673328..4254ee5ae47 100644 --- a/lib/win-exception-handler/Cargo.toml +++ b/lib/win-exception-handler/Cargo.toml @@ -13,6 +13,6 @@ winapi = { version = "0.3.8", features = ["winbase", "errhandlingapi", "minwinde libc = "0.2.60" [build-dependencies] -cmake = "0.1.40" -bindgen = "0.51.0" -regex = "1.2.1" +cmake = "0.1" +bindgen = "0.51" +regex = "1.2" diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index f9cffd1ae2e..659f53c715f 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -732,7 +732,7 @@ fn interactive_shell(mut ctx: InteractiveShellContext) -> ShellExitOperation { } "backtrace" | "bt" => { if let Some(ref image) = ctx.image { - println!("{}", image.execution_state.colored_output()); + println!("{}", image.execution_state.output()); } else { println!("State not available"); }