diff --git a/.appveyor.yml b/.appveyor.yml index b0a5e2904..c057f81d3 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -49,8 +49,9 @@ install: # - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) build_script: - - git submodule update --init - cargo build --release --verbose + - git submodule init + - git submodule update # Cache wapm cli target in dir above to prevent breaking git submodule on windows - if not exist wapm-cli-target mkdir wapm-cli-target - move wapm-cli-target wapm-cli diff --git a/.circleci/config.yml b/.circleci/config.yml index e02dd9a55..40c2772ea 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -111,6 +111,10 @@ jobs: name: Debug flag checked command: | cargo check --features "debug" --release + - run: + name: Check + command: | + make check - run: name: Release command: make release-fast @@ -163,6 +167,11 @@ jobs: ulimit -n 8000 sudo sysctl -w kern.maxfiles=655360 kern.maxfilesperproc=327680 make test + - run: + name: Check + command: | + export PATH="$HOME/.cargo/bin:$PATH" + make check - run: name: Release command: | diff --git a/.gitmodules b/.gitmodules index a928e9b14..af96cdf0e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,7 +1,3 @@ [submodule "wapm-cli"] path = wapm-cli url = https://github.com/wasmerio/wapm-cli.git -[submodule "lib/clif-backend/cranelift"] - path = lib/clif-backend/cranelift - url = https://github.com/wasmerio/cranelift - branch = wasmer diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a2add63b..cb9552b62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ All PRs to the Wasmer repository must add to this file. Blocks of changes will separated by version increments. ## **[Unreleased]** +- [#554](https://github.com/wasmerio/wasmer/pull/554) Finish implementation of `wasi::fd_seek`, fix bug in filestat + +## 0.5.5 - [#541](https://github.com/wasmerio/wasmer/pull/541) Fix dependency graph by making separate test crates; ABI implementations should not depend on compilers. Add Cranelift fork as git submodule of clif-backend - [#537](https://github.com/wasmerio/wasmer/pull/537) Add hidden flag (`--cache-key`) to use prehashed key into the compiled wasm cache and change compiler backend-specific caching to use directories - [#536](https://github.com/wasmerio/wasmer/pull/536) ~Update cache to use compiler backend name in cache key~ diff --git a/Cargo.lock b/Cargo.lock index 4f702993b..b34471ef5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -245,20 +245,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cranelift-bforest" version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cranelift-entity 0.31.0", + "cranelift-entity 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "cranelift-codegen" version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cranelift-bforest 0.31.0", - "cranelift-codegen-meta 0.31.0", - "cranelift-entity 0.31.0", + "cranelift-bforest 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cranelift-codegen-meta 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cranelift-entity 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "hashmap_core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "target-lexicon 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -266,49 +267,26 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cranelift-entity 0.31.0", + "cranelift-entity 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "cranelift-entity" version = "0.31.0" - -[[package]] -name = "cranelift-frontend" -version = "0.31.0" -dependencies = [ - "cranelift-codegen 0.31.0", - "hashmap_core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "target-lexicon 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", -] +source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cranelift-native" version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cranelift-codegen 0.31.0", + "cranelift-codegen 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)", "raw-cpuid 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "target-lexicon 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "cranelift-wasm" -version = "0.31.0" -dependencies = [ - "cranelift-codegen 0.31.0", - "cranelift-entity 0.31.0", - "cranelift-frontend 0.31.0", - "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "hashmap_core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "target-lexicon 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmparser 0.32.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "criterion" version = "0.2.11" @@ -548,16 +526,6 @@ dependencies = [ "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "hashbrown" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "hashmap_core" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "heck" version = "0.3.1" @@ -712,19 +680,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "nix" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)", - "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "nix" -version = "0.13.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1421,7 +1377,7 @@ dependencies = [ [[package]] name = "wasmer" -version = "0.5.4" +version = "0.5.5" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "errno 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1430,55 +1386,79 @@ dependencies = [ "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "structopt 0.2.17 (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.5.4", - "wasmer-dev-utils 0.5.4", - "wasmer-emscripten 0.5.4", - "wasmer-emscripten-tests 0.5.4", + "wasmer-clif-backend 0.5.5", + "wasmer-dev-utils 0.5.5", + "wasmer-emscripten 0.5.5", + "wasmer-emscripten-tests 0.5.5", "wasmer-kernel-loader 0.1.0", - "wasmer-llvm-backend 0.5.4", - "wasmer-middleware-common 0.5.4", - "wasmer-runtime 0.5.4", - "wasmer-runtime-core 0.5.4", - "wasmer-singlepass-backend 0.5.4", - "wasmer-wasi 0.5.4", - "wasmer-wasi-tests 0.5.4", + "wasmer-llvm-backend 0.5.5", + "wasmer-middleware-common 0.5.5", + "wasmer-runtime 0.5.5", + "wasmer-runtime-core 0.5.5", + "wasmer-singlepass-backend 0.5.5", + "wasmer-wasi 0.5.5", + "wasmer-wasi-tests 0.5.5", ] [[package]] name = "wasmer-clif-backend" -version = "0.5.4" +version = "0.5.5" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "cranelift-codegen 0.31.0", - "cranelift-entity 0.31.0", - "cranelift-frontend 0.31.0", - "cranelift-native 0.31.0", - "cranelift-wasm 0.31.0", + "cranelift-codegen 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cranelift-entity 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cranelift-native 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)", "hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)", - "nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", + "nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde-bench 0.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "serde_bytes 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "target-lexicon 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-runtime-core 0.5.4", - "wasmer-win-exception-handler 0.5.4", + "wasmer-clif-fork-frontend 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmer-clif-fork-wasm 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmer-runtime-core 0.5.5", + "wasmer-win-exception-handler 0.5.5", "wasmparser 0.32.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "wasmer-clif-fork-frontend" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cranelift-codegen 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "target-lexicon 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wasmer-clif-fork-wasm" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cranelift-codegen 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cranelift-entity 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmer-clif-fork-frontend 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmparser 0.32.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "wasmer-dev-utils" -version = "0.5.4" +version = "0.5.5" dependencies = [ "libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasmer-emscripten" -version = "0.5.4" +version = "0.5.5" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1486,21 +1466,21 @@ dependencies = [ "libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)", "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)", - "wasmer-runtime-core 0.5.4", + "wasmer-runtime-core 0.5.5", ] [[package]] name = "wasmer-emscripten-tests" -version = "0.5.4" +version = "0.5.5" dependencies = [ "glob 0.2.11 (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.5.4", - "wasmer-dev-utils 0.5.4", - "wasmer-emscripten 0.5.4", - "wasmer-llvm-backend 0.5.4", - "wasmer-runtime-core 0.5.4", - "wasmer-singlepass-backend 0.5.4", + "wasmer-clif-backend 0.5.5", + "wasmer-dev-utils 0.5.5", + "wasmer-emscripten 0.5.5", + "wasmer-llvm-backend 0.5.5", + "wasmer-runtime-core 0.5.5", + "wasmer-singlepass-backend 0.5.5", ] [[package]] @@ -1508,12 +1488,12 @@ name = "wasmer-kernel-loader" version = "0.1.0" dependencies = [ "libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-runtime-core 0.5.4", + "wasmer-runtime-core 0.5.5", ] [[package]] name = "wasmer-llvm-backend" -version = "0.5.4" +version = "0.5.5" dependencies = [ "capstone 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1522,56 +1502,56 @@ dependencies = [ "inkwell 0.1.0 (git+https://github.com/wasmerio/inkwell?branch=llvm7-0)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)", - "nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", + "nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", "wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-runtime-core 0.5.4", + "wasmer-runtime-core 0.5.5", "wasmparser 0.32.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasmer-middleware-common" -version = "0.5.4" +version = "0.5.5" dependencies = [ "criterion 0.2.11 (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.5.4", - "wasmer-llvm-backend 0.5.4", - "wasmer-runtime-core 0.5.4", - "wasmer-singlepass-backend 0.5.4", + "wasmer-clif-backend 0.5.5", + "wasmer-llvm-backend 0.5.5", + "wasmer-runtime-core 0.5.5", + "wasmer-singlepass-backend 0.5.5", ] [[package]] name = "wasmer-runtime" -version = "0.5.4" +version = "0.5.5" dependencies = [ "criterion 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.8 (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.5.4", - "wasmer-llvm-backend 0.5.4", - "wasmer-runtime-core 0.5.4", - "wasmer-singlepass-backend 0.5.4", + "wasmer-clif-backend 0.5.5", + "wasmer-llvm-backend 0.5.5", + "wasmer-runtime-core 0.5.5", + "wasmer-singlepass-backend 0.5.5", ] [[package]] name = "wasmer-runtime-c-api" -version = "0.5.4" +version = "0.5.5" dependencies = [ "cbindgen 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-runtime 0.5.4", - "wasmer-runtime-core 0.5.4", + "wasmer-runtime 0.5.5", + "wasmer-runtime-core 0.5.5", ] [[package]] name = "wasmer-runtime-core" -version = "0.5.4" +version = "0.5.5" dependencies = [ "bincode 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "blake2b_simd 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1585,7 +1565,7 @@ dependencies = [ "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)", - "nix 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", "page_size 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1600,7 +1580,7 @@ dependencies = [ [[package]] name = "wasmer-singlepass-backend" -version = "0.5.4" +version = "0.5.5" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "colored 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1609,26 +1589,26 @@ dependencies = [ "hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)", - "nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", + "nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-runtime-core 0.5.4", + "wasmer-runtime-core 0.5.5", "wasmparser 0.32.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasmer-spectests" -version = "0.5.4" +version = "0.5.5" dependencies = [ "wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-clif-backend 0.5.4", - "wasmer-llvm-backend 0.5.4", - "wasmer-runtime-core 0.5.4", - "wasmer-singlepass-backend 0.5.4", + "wasmer-clif-backend 0.5.5", + "wasmer-llvm-backend 0.5.5", + "wasmer-runtime-core 0.5.5", + "wasmer-singlepass-backend 0.5.5", ] [[package]] name = "wasmer-wasi" -version = "0.5.4" +version = "0.5.5" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "generational-arena 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1636,32 +1616,32 @@ dependencies = [ "libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-runtime-core 0.5.4", + "wasmer-runtime-core 0.5.5", "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasmer-wasi-tests" -version = "0.5.4" +version = "0.5.5" dependencies = [ "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-clif-backend 0.5.4", - "wasmer-dev-utils 0.5.4", - "wasmer-llvm-backend 0.5.4", - "wasmer-runtime-core 0.5.4", - "wasmer-singlepass-backend 0.5.4", - "wasmer-wasi 0.5.4", + "wasmer-clif-backend 0.5.5", + "wasmer-dev-utils 0.5.5", + "wasmer-llvm-backend 0.5.5", + "wasmer-runtime-core 0.5.5", + "wasmer-singlepass-backend 0.5.5", + "wasmer-wasi 0.5.5", ] [[package]] name = "wasmer-win-exception-handler" -version = "0.5.4" +version = "0.5.5" dependencies = [ "bindgen 0.46.0 (registry+https://github.com/rust-lang/crates.io-index)", "cmake 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-runtime-core 0.5.4", + "wasmer-runtime-core 0.5.5", "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1669,9 +1649,6 @@ dependencies = [ name = "wasmparser" version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "hashbrown 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", -] [[package]] name = "which" @@ -1768,6 +1745,11 @@ dependencies = [ "checksum cmake 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "2ca4386c8954b76a8415b63959337d940d724b336cabd3afe189c2b51a7e1ff0" "checksum colored 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6cdb90b60f2927f8d76139c72dbde7e10c3a2bc47c8594c9c7a66529f2687c03" "checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e" +"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" +"checksum cranelift-codegen-meta 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0fee15ed430092a6d14b7c6d627540bef732509b8097ae31e4e35526edaa129c" +"checksum cranelift-entity 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)" = "739222c3740e4a8d6f0375bd95caba9b6c11afcba9f0e1d4f944d6bd99f84600" +"checksum cranelift-native 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce451162d18b7d82118e23ea7e12f7d8b98557549404bd71215548de79eb0736" "checksum criterion 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0363053954f3e679645fc443321ca128b7b950a6fe288cf5f9335cc22ee58394" "checksum criterion-plot 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "76f9212ddf2f4a9eb2d401635190600656a1f88a932ef53d06e7fa4c7e02fb8e" "checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" @@ -1793,8 +1775,6 @@ dependencies = [ "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" "checksum goblin 0.0.20 (registry+https://github.com/rust-lang/crates.io-index)" = "84473a5302fa5094d3d9911c2f312f522f9a37462a777f195f63fae1bf7faf4d" "checksum hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3bae29b6653b3412c2e71e9d486db9f9df5d701941d86683005efb9f2d28e3da" -"checksum hashbrown 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e1de41fb8dba9714efd92241565cdff73f78508c95697dd56787d3cba27e2353" -"checksum hashmap_core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "8e04cb7a5051270ef3fa79f8c7604d581ecfa73d520e74f554e45541c4b5881a" "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" "checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" "checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114" @@ -1814,8 +1794,7 @@ dependencies = [ "checksum memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2ffa2c986de11a9df78620c01eeaaf27d94d3ff02bf81bfcca953102dd0c6ff" "checksum memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" -"checksum nix 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "921f61dc817b379d0834e45d5ec45beaacfae97082090a49c2cf30dcbc30206f" -"checksum nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "46f0f3210768d796e8fa79ec70ee6af172dacbe7147f5e69be5240a47778302b" +"checksum nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6c722bee1037d430d0f8e687bbdbf222f27cc6e4e68d5caf630857bb2b6dbdce" "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" @@ -1901,6 +1880,8 @@ dependencies = [ "checksum wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "74e463a508e390cc7447e70f640fbf44ad52e1bd095314ace1fdf99516d32add" "checksum wabt-sys 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a6265b25719e82598d104b3717375e37661d41753e2c84cde3f51050c7ed7e3c" "checksum walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d9d7ed3431229a144296213105a390676cc49c9b6a72bd19f3176c98e129fa1" +"checksum wasmer-clif-fork-frontend 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)" = "620fd484c3348e4bb565d861cddb0c05170337aaa152b6ba61620d054ab17cd9" +"checksum wasmer-clif-fork-wasm 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b5e42fa4281de137d5a23b8197d29c218212077c6d55d0dfed7bb80c76308ba4" "checksum wasmparser 0.32.1 (registry+https://github.com/rust-lang/crates.io-index)" = "22d1801de30f112ddaf665291097694ee33a36d1cb414b53a921d05b3519674a" "checksum which 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b57acb10231b9493c8472b20cb57317d0679a49e0bdbee44b3b803a6473af164" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" diff --git a/Cargo.toml b/Cargo.toml index 921a3c456..dbb82e820 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer" -version = "0.5.4" +version = "0.5.5" authors = ["The Wasmer Engineering Team "] edition = "2018" repository = "https://github.com/wasmerio/wasmer" @@ -67,14 +67,14 @@ rustc_version = "0.2.3" [features] default = ["fast-tests", "wasi"] -"loader:kernel" = ["wasmer-kernel-loader"] +"loader-kernel" = ["wasmer-kernel-loader"] debug = ["wasmer-runtime-core/debug"] trace = ["wasmer-runtime-core/trace"] extra-debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] # This feature will allow cargo test to run much faster fast-tests = [] -"backend:llvm" = ["wasmer-llvm-backend", "wasmer-runtime-core/backend:llvm"] -"backend:singlepass" = ["wasmer-singlepass-backend", "wasmer-runtime-core/backend:singlepass"] +"backend-llvm" = ["wasmer-llvm-backend", "wasmer-runtime-core/backend-llvm"] +"backend-singlepass" = ["wasmer-singlepass-backend", "wasmer-runtime-core/backend-singlepass"] wasi = ["wasmer-wasi"] # vfs = ["wasmer-runtime-abi"] diff --git a/Makefile b/Makefile index a8a56ef40..deffef349 100644 --- a/Makefile +++ b/Makefile @@ -112,13 +112,16 @@ lint: precommit: lint test debug: - cargo build --release --features backend:singlepass,debug,trace + cargo build --release --features backend-singlepass,debug,trace install: cargo install --path . +check: + cargo check --release --features backend-singlepass,backend-llvm,loader-kernel + release: - cargo build --release --features backend:singlepass,backend:llvm,loader:kernel + cargo build --release --features backend-singlepass,backend-llvm,loader-kernel # Only one backend (cranelift) release-fast: @@ -127,10 +130,10 @@ release-fast: cargo build --release release-singlepass: - cargo build --release --features backend:singlepass + cargo build --release --features backend-singlepass release-llvm: - cargo build --release --features backend:llvm + cargo build --release --features backend-llvm bench: cargo bench --all diff --git a/fuzz/.gitignore b/fuzz/.gitignore new file mode 100644 index 000000000..572e03bdf --- /dev/null +++ b/fuzz/.gitignore @@ -0,0 +1,4 @@ + +target +corpus +artifacts diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml new file mode 100644 index 000000000..5c37cb47e --- /dev/null +++ b/fuzz/Cargo.toml @@ -0,0 +1,21 @@ + +[package] +name = "wasmer-fuzz" +version = "0.0.1" +authors = ["Automatically generated"] +publish = false + +[package.metadata] +cargo-fuzz = true + +[dependencies] +wasmer-runtime = { path = "../lib/runtime" } +libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git" } + +# Prevent this from interfering with workspaces +[workspace] +members = ["."] + +[[bin]] +name = "simple_instantiate" +path = "fuzz_targets/simple_instantiate.rs" diff --git a/fuzz/README.md b/fuzz/README.md new file mode 100644 index 000000000..eeb43ebd5 --- /dev/null +++ b/fuzz/README.md @@ -0,0 +1,38 @@ +This directory contains the fuzz tests for wasmer. To fuzz, we use the `cargo-fuzz` package. + +## Installation + +You may need to install the `cargo-fuzz` package to get the `cargo fuzz` subcommand. Use + +```sh +$ cargo install cargo-fuzz +``` + +`cargo-fuzz` is documented in the [Rust Fuzz Book](https://rust-fuzz.github.io/book/cargo-fuzz.html). + +## Running a fuzzer + +Once `cargo-fuzz` is installed, you can run the `simple_instantiate` fuzzer with +```sh +cargo fuzz run simple_instantiate +``` + +You should see output that looks something like this: + +``` +INFO: Seed: 3276026494 +INFO: 8 files found in wasmer/fuzz/corpus/simple_instantiate +INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 4096 bytes +INFO: seed corpus: files: 8 min: 1b max: 1b total: 8b rss: 133Mb +#9 INITED ft: 3 corp: 3/3b lim: 4 exec/s: 0 rss: 142Mb +#23 NEW ft: 4 corp: 4/5b lim: 4 exec/s: 0 rss: 142Mb L: 2/2 MS: 4 ChangeByte-InsertByte-ShuffleBytes-ChangeBit- +#25 NEW ft: 5 corp: 5/6b lim: 4 exec/s: 0 rss: 142Mb L: 1/2 MS: 2 ChangeBinInt-ChangeBit- +#27 NEW ft: 6 corp: 6/9b lim: 4 exec/s: 0 rss: 142Mb L: 3/3 MS: 2 InsertByte-ChangeByte- +#190 REDUCE ft: 6 corp: 6/7b lim: 4 exec/s: 0 rss: 142Mb L: 1/2 MS: 3 ChangeBit-EraseBytes-CrossOver- +#205 REDUCE ft: 7 corp: 7/11b lim: 4 exec/s: 0 rss: 142Mb L: 4/4 MS: 5 ShuffleBytes-CrossOver-InsertByte-ChangeBinInt-CrossOver- +``` +It will continue to generate random inputs forever, until it finds a bug or is terminated. The testcases for bugs it finds go into `fuzz/artifacts/simple_instantiate` and you can rerun the fuzzer on a single input by passing it on the command line `cargo fuzz run simple_instantiate my_testcase.wasm`. + +## Trophy case + +- [x] https://github.com/wasmerio/wasmer/issues/558 diff --git a/fuzz/fuzz_targets/simple_instantiate.rs b/fuzz/fuzz_targets/simple_instantiate.rs new file mode 100644 index 000000000..831bbb1a5 --- /dev/null +++ b/fuzz/fuzz_targets/simple_instantiate.rs @@ -0,0 +1,13 @@ +#![no_main] +#[macro_use] extern crate libfuzzer_sys; +extern crate wasmer_runtime; + +use wasmer_runtime::{ + instantiate, + imports, +}; + +fuzz_target!(|data: &[u8]| { + let import_object = imports! {}; + instantiate(data, &import_object); +}); diff --git a/install.sh b/install.sh index 8d4e1e9d2..154e44d46 100755 --- a/install.sh +++ b/install.sh @@ -365,10 +365,14 @@ wasmer_download() { # determine install directory if required if [ -z "$INSTALL_DIRECTORY" ]; then - # findWasmerBinDirectory INSTALL_DIRECTORY - INSTALL_DIRECTORY="$HOME/.wasmer" + if [ -z "$WASMER_DIR" ]; then + # If WASMER_DIR is not present + INSTALL_DIRECTORY="$HOME/.wasmer" + else + # If WASMER_DIR is present + INSTALL_DIRECTORY="${WASMER_DIR}" + fi fi - WASMER=INSTALL_DIRECTORY # assemble expected release artifact name BINARY="wasmer-${OS}-${ARCH}.tar.gz" diff --git a/lib/clif-backend/Cargo.toml b/lib/clif-backend/Cargo.toml index b208933c6..e2c3dce0c 100644 --- a/lib/clif-backend/Cargo.toml +++ b/lib/clif-backend/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer-clif-backend" -version = "0.5.4" +version = "0.5.5" description = "Wasmer runtime Cranelift compiler backend" license = "MIT" authors = ["The Wasmer Engineering Team "] @@ -8,17 +8,17 @@ repository = "https://github.com/wasmerio/wasmer" edition = "2018" [dependencies] -wasmer-runtime-core = { path = "../runtime-core", version = "0.5.4" } -cranelift-native = { path = "cranelift/cranelift-native", version = "0.31" } -cranelift-codegen = { path = "cranelift/cranelift-codegen", version = "0.31" } -cranelift-entity = { path = "cranelift/cranelift-entity", version = "0.31" } -cranelift-frontend = { path = "cranelift/cranelift-frontend", version = "0.31" } -cranelift-wasm = { path = "cranelift/cranelift-wasm", version = "0.31" } +wasmer-runtime-core = { path = "../runtime-core", version = "0.5.5" } +cranelift-native = { version = "0.31" } +cranelift-codegen = { version = "0.31" } +cranelift-entity = { version = "0.31" } +cranelift-frontend = { package = "wasmer-clif-fork-frontend", version = "0.31" } +cranelift-wasm = { package = "wasmer-clif-fork-wasm", version = "0.31" } hashbrown = "0.1" target-lexicon = "0.4.0" wasmparser = "0.32.1" byteorder = "1" -nix = "0.13.0" +nix = "0.14.0" libc = "0.2.49" rayon = "1.0" @@ -34,7 +34,7 @@ version = "0.0.7" [target.'cfg(windows)'.dependencies] winapi = { version = "0.3", features = ["errhandlingapi", "minwindef", "minwinbase", "winnt"] } -wasmer-win-exception-handler = { path = "../win-exception-handler", version = "0.5.4" } +wasmer-win-exception-handler = { path = "../win-exception-handler", version = "0.5.5" } [features] debug = ["wasmer-runtime-core/debug"] diff --git a/lib/clif-backend/cranelift b/lib/clif-backend/cranelift deleted file mode 160000 index 19b19f171..000000000 --- a/lib/clif-backend/cranelift +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 19b19f171cf4511660c5f2097af41a9b49774825 diff --git a/lib/dev-utils/Cargo.toml b/lib/dev-utils/Cargo.toml index 4d2e2b9bb..3ce2fef48 100644 --- a/lib/dev-utils/Cargo.toml +++ b/lib/dev-utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer-dev-utils" -version = "0.5.4" +version = "0.5.5" description = "Wasmer runtime core library" license = "MIT" authors = ["The Wasmer Engineering Team "] diff --git a/lib/emscripten-tests/Cargo.toml b/lib/emscripten-tests/Cargo.toml index fc8510b56..f6da02b99 100644 --- a/lib/emscripten-tests/Cargo.toml +++ b/lib/emscripten-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer-emscripten-tests" -version = "0.5.4" +version = "0.5.5" description = "Tests for our Emscripten implementation" license = "MIT" authors = ["The Wasmer Engineering Team "] @@ -9,15 +9,15 @@ publish = false build = "build/mod.rs" [dependencies] -wasmer-emscripten = { path = "../emscripten", version = "0.5.4" } -wasmer-runtime-core = { path = "../runtime-core", version = "0.5.4" } -wasmer-clif-backend = { path = "../clif-backend", version = "0.5.4" } -wasmer-llvm-backend = { path = "../llvm-backend", version = "0.5.4", optional = true } -wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.5.4", optional = true } +wasmer-emscripten = { path = "../emscripten", version = "0.5.5" } +wasmer-runtime-core = { path = "../runtime-core", version = "0.5.5" } +wasmer-clif-backend = { path = "../clif-backend", version = "0.5.5" } +wasmer-llvm-backend = { path = "../llvm-backend", version = "0.5.5", optional = true } +wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.5.5", optional = true } [dev-dependencies] wabt = "0.7.2" -wasmer-dev-utils = { path = "../dev-utils", version = "0.5.4"} +wasmer-dev-utils = { path = "../dev-utils", version = "0.5.5"} [build-dependencies] glob = "0.2.11" @@ -25,4 +25,4 @@ glob = "0.2.11" [features] clif = [] llvm = ["wasmer-llvm-backend"] -singlepass = ["wasmer-singlepass-backend"] \ No newline at end of file +singlepass = ["wasmer-singlepass-backend"] diff --git a/lib/emscripten/Cargo.toml b/lib/emscripten/Cargo.toml index 995325595..f8b641cab 100644 --- a/lib/emscripten/Cargo.toml +++ b/lib/emscripten/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer-emscripten" -version = "0.5.4" +version = "0.5.5" description = "Wasmer runtime emscripten implementation library" license = "MIT" authors = ["The Wasmer Engineering Team "] @@ -13,10 +13,10 @@ hashbrown = "0.1" lazy_static = "1.2.0" libc = "0.2.49" time = "0.1.41" -wasmer-runtime-core = { path = "../runtime-core", version = "0.5.4" } +wasmer-runtime-core = { path = "../runtime-core", version = "0.5.5" } [target.'cfg(windows)'.dependencies] rand = "0.6" [features] -debug = ["wasmer-runtime-core/debug"] \ No newline at end of file +debug = ["wasmer-runtime-core/debug"] diff --git a/lib/llvm-backend/Cargo.toml b/lib/llvm-backend/Cargo.toml index 3456daeb8..766fbd95e 100644 --- a/lib/llvm-backend/Cargo.toml +++ b/lib/llvm-backend/Cargo.toml @@ -1,18 +1,18 @@ [package] name = "wasmer-llvm-backend" -version = "0.5.4" +version = "0.5.5" authors = ["Lachlan Sneff "] edition = "2018" [dependencies] -wasmer-runtime-core = { path = "../runtime-core", version = "0.5.4" } +wasmer-runtime-core = { path = "../runtime-core", version = "0.5.5" } inkwell = { git = "https://github.com/wasmerio/inkwell", branch = "llvm7-0" } wasmparser = "0.32.1" hashbrown = "0.1.8" smallvec = "0.6.8" goblin = "0.0.20" libc = "0.2.49" -nix = "0.13.0" +nix = "0.14.0" capstone = { version = "0.5.0", optional = true } [build-dependencies] diff --git a/lib/llvm-backend/src/code.rs b/lib/llvm-backend/src/code.rs index 0359b3dd8..2eb8d441e 100644 --- a/lib/llvm-backend/src/code.rs +++ b/lib/llvm-backend/src/code.rs @@ -60,106 +60,37 @@ fn type_to_llvm(intrinsics: &Intrinsics, ty: Type) -> BasicTypeEnum { } } -fn trap_if_not_representatable_as_int( +fn trap_if_not_representable_as_int( builder: &Builder, intrinsics: &Intrinsics, context: &Context, function: &FunctionValue, - lower_bounds: f64, + lower_bound: f64, upper_bound: f64, value: FloatValue, ) { - enum FloatSize { - Bits32, - Bits64, - } + let float_ty = value.get_type(); + + let lower_bound = float_ty.const_float(lower_bound); + let upper_bound = float_ty.const_float(upper_bound); + + // The 'U' in the float predicate is short for "unordered" which means that + // the comparison will compare true if either operand is a NaN. Thus, NaNs + // are out of bounds. + let above_upper_bound_cmp = + builder.build_float_compare(FloatPredicate::UGT, value, upper_bound, "above_upper_bound"); + let below_lower_bound_cmp = + builder.build_float_compare(FloatPredicate::ULT, value, lower_bound, "below_lower_bound"); + let out_of_bounds = builder.build_or( + above_upper_bound_cmp, + below_lower_bound_cmp, + "out_of_bounds", + ); let failure_block = context.append_basic_block(function, "conversion_failure_block"); let continue_block = context.append_basic_block(function, "conversion_success_block"); - let float_ty = value.get_type(); - let (int_ty, float_ptr_ty, float_size) = if float_ty == intrinsics.f32_ty { - (intrinsics.i32_ty, intrinsics.f32_ptr_ty, FloatSize::Bits32) - } else if float_ty == intrinsics.f64_ty { - (intrinsics.i64_ty, intrinsics.f64_ptr_ty, FloatSize::Bits64) - } else { - unreachable!() - }; - - let (exponent, invalid_exponent) = { - let float_bits = { - let space = builder.build_alloca(int_ty, "space"); - let float_ptr = builder.build_pointer_cast(space, float_ptr_ty, "float_ptr"); - builder.build_store(float_ptr, value); - builder.build_load(space, "float_bits").into_int_value() - }; - - let (shift_amount, exponent_mask, invalid_exponent) = match float_size { - FloatSize::Bits32 => (23, 0b01111111100000000000000000000000, 0b11111111), - FloatSize::Bits64 => ( - 52, - 0b0111111111110000000000000000000000000000000000000000000000000000, - 0b11111111111, - ), - }; - - builder.build_and( - float_bits, - int_ty.const_int(exponent_mask, false), - "masked_bits", - ); - - ( - builder.build_right_shift( - float_bits, - int_ty.const_int(shift_amount, false), - false, - "exponent", - ), - invalid_exponent, - ) - }; - - let is_invalid_float = builder.build_or( - builder.build_int_compare( - IntPredicate::EQ, - exponent, - int_ty.const_int(invalid_exponent, false), - "is_not_normal", - ), - builder.build_or( - builder.build_float_compare( - FloatPredicate::ULT, - value, - float_ty.const_float(lower_bounds), - "less_than_lower_bounds", - ), - builder.build_float_compare( - FloatPredicate::UGT, - value, - float_ty.const_float(upper_bound), - "greater_than_upper_bounds", - ), - "float_not_in_bounds", - ), - "is_invalid_float", - ); - - let is_invalid_float = builder - .build_call( - intrinsics.expect_i1, - &[ - is_invalid_float.as_basic_value_enum(), - intrinsics.i1_ty.const_int(0, false).as_basic_value_enum(), - ], - "is_invalid_float_expect", - ) - .try_as_basic_value() - .left() - .unwrap() - .into_int_value(); - - builder.build_conditional_branch(is_invalid_float, &failure_block, &continue_block); + builder.build_conditional_branch(out_of_bounds, &failure_block, &continue_block); builder.position_at_end(&failure_block); builder.build_call( intrinsics.throw_trap, @@ -1726,7 +1657,7 @@ impl FunctionCodeGenerator for LLVMFunctionCodeGenerator { } Operator::I32TruncSF32 => { let v1 = state.pop1()?.into_float_value(); - trap_if_not_representatable_as_int( + trap_if_not_representable_as_int( builder, intrinsics, context, @@ -1741,7 +1672,7 @@ impl FunctionCodeGenerator for LLVMFunctionCodeGenerator { } Operator::I32TruncSF64 => { let v1 = state.pop1()?.into_float_value(); - trap_if_not_representatable_as_int( + trap_if_not_representable_as_int( builder, intrinsics, context, @@ -1762,7 +1693,7 @@ impl FunctionCodeGenerator for LLVMFunctionCodeGenerator { } Operator::I64TruncSF32 => { let v1 = state.pop1()?.into_float_value(); - trap_if_not_representatable_as_int( + trap_if_not_representable_as_int( builder, intrinsics, context, @@ -1777,7 +1708,7 @@ impl FunctionCodeGenerator for LLVMFunctionCodeGenerator { } Operator::I64TruncSF64 => { let v1 = state.pop1()?.into_float_value(); - trap_if_not_representatable_as_int( + trap_if_not_representable_as_int( builder, intrinsics, context, @@ -1798,7 +1729,7 @@ impl FunctionCodeGenerator for LLVMFunctionCodeGenerator { } Operator::I32TruncUF32 => { let v1 = state.pop1()?.into_float_value(); - trap_if_not_representatable_as_int( + trap_if_not_representable_as_int( builder, intrinsics, context, @@ -1813,7 +1744,7 @@ impl FunctionCodeGenerator for LLVMFunctionCodeGenerator { } Operator::I32TruncUF64 => { let v1 = state.pop1()?.into_float_value(); - trap_if_not_representatable_as_int( + trap_if_not_representable_as_int( builder, intrinsics, context, @@ -1834,7 +1765,7 @@ impl FunctionCodeGenerator for LLVMFunctionCodeGenerator { } Operator::I64TruncUF32 => { let v1 = state.pop1()?.into_float_value(); - trap_if_not_representatable_as_int( + trap_if_not_representable_as_int( builder, intrinsics, context, @@ -1849,7 +1780,7 @@ impl FunctionCodeGenerator for LLVMFunctionCodeGenerator { } Operator::I64TruncUF64 => { let v1 = state.pop1()?.into_float_value(); - trap_if_not_representatable_as_int( + trap_if_not_representable_as_int( builder, intrinsics, context, @@ -1904,43 +1835,23 @@ impl FunctionCodeGenerator for LLVMFunctionCodeGenerator { } Operator::I32ReinterpretF32 => { let v = state.pop1()?; - let space = - builder.build_alloca(intrinsics.i32_ty.as_basic_type_enum(), &state.var_name()); - let f32_space = - builder.build_pointer_cast(space, intrinsics.f32_ptr_ty, &state.var_name()); - builder.build_store(f32_space, v); - let int = builder.build_load(space, &state.var_name()); - state.push1(int); + let ret = builder.build_bitcast(v, intrinsics.i32_ty, &state.var_name()); + state.push1(ret); } Operator::I64ReinterpretF64 => { let v = state.pop1()?; - let space = - builder.build_alloca(intrinsics.i64_ty.as_basic_type_enum(), &state.var_name()); - let f64_space = - builder.build_pointer_cast(space, intrinsics.f64_ptr_ty, &state.var_name()); - builder.build_store(f64_space, v); - let int = builder.build_load(space, &state.var_name()); - state.push1(int); + let ret = builder.build_bitcast(v, intrinsics.i64_ty, &state.var_name()); + state.push1(ret); } Operator::F32ReinterpretI32 => { let v = state.pop1()?; - let space = - builder.build_alloca(intrinsics.f32_ty.as_basic_type_enum(), &state.var_name()); - let i32_space = - builder.build_pointer_cast(space, intrinsics.i32_ptr_ty, &state.var_name()); - builder.build_store(i32_space, v); - let f = builder.build_load(space, &state.var_name()); - state.push1(f); + let ret = builder.build_bitcast(v, intrinsics.f32_ty, &state.var_name()); + state.push1(ret); } Operator::F64ReinterpretI64 => { let v = state.pop1()?; - let space = - builder.build_alloca(intrinsics.f64_ty.as_basic_type_enum(), &state.var_name()); - let i64_space = - builder.build_pointer_cast(space, intrinsics.i64_ptr_ty, &state.var_name()); - builder.build_store(i64_space, v); - let f = builder.build_load(space, &state.var_name()); - state.push1(f); + let ret = builder.build_bitcast(v, intrinsics.f64_ty, &state.var_name()); + state.push1(ret); } /*************************** @@ -2607,13 +2518,19 @@ impl ModuleCodeGenerator if cfg!(test) { pass_manager.add_verifier_pass(); } - pass_manager.add_function_inlining_pass(); - pass_manager.add_promote_memory_to_register_pass(); + pass_manager.add_lower_expect_intrinsic_pass(); + pass_manager.add_scalar_repl_aggregates_pass(); + pass_manager.add_instruction_combining_pass(); pass_manager.add_cfg_simplification_pass(); - pass_manager.add_aggressive_inst_combiner_pass(); - pass_manager.add_merged_load_store_motion_pass(); - pass_manager.add_new_gvn_pass(); - pass_manager.add_aggressive_dce_pass(); + pass_manager.add_gvn_pass(); + pass_manager.add_jump_threading_pass(); + pass_manager.add_correlated_value_propagation_pass(); + pass_manager.add_sccp_pass(); + pass_manager.add_instruction_combining_pass(); + pass_manager.add_reassociate_pass(); + pass_manager.add_cfg_simplification_pass(); + pass_manager.add_bit_tracking_dce_pass(); + pass_manager.add_slp_vectorize_pass(); pass_manager.run_on_module(&self.module); // self.module.print_to_stderr(); diff --git a/lib/middleware-common/Cargo.toml b/lib/middleware-common/Cargo.toml index b365e023b..09d1593d3 100644 --- a/lib/middleware-common/Cargo.toml +++ b/lib/middleware-common/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer-middleware-common" -version = "0.5.4" +version = "0.5.5" repository = "https://github.com/wasmerio/wasmer" description = "Wasmer runtime common middlewares" license = "MIT" @@ -9,9 +9,9 @@ edition = "2018" [dependencies] wasmer-runtime-core = { path = "../runtime-core" } -wasmer-clif-backend = { path = "../clif-backend", version = "0.5.4" } -wasmer-llvm-backend = { path = "../llvm-backend", version = "0.5.4", optional = true } -wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.5.4", optional = true } +wasmer-clif-backend = { path = "../clif-backend", version = "0.5.5" } +wasmer-llvm-backend = { path = "../llvm-backend", version = "0.5.5", optional = true } +wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.5.5", optional = true } [dev-dependencies] wabt = "0.7.4" diff --git a/lib/runtime-abi/Cargo.toml b/lib/runtime-abi/Cargo.toml index ea1167621..d9e8073f9 100644 --- a/lib/runtime-abi/Cargo.toml +++ b/lib/runtime-abi/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer-runtime-abi" -version = "0.5.4" +version = "0.5.5" description = "Wasmer runtime core library" license = "MIT" authors = ["The Wasmer Engineering Team "] diff --git a/lib/runtime-c-api/Cargo.toml b/lib/runtime-c-api/Cargo.toml index 335958504..fe41899fd 100644 --- a/lib/runtime-c-api/Cargo.toml +++ b/lib/runtime-c-api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer-runtime-c-api" -version = "0.5.4" +version = "0.5.5" description = "Wasmer C API library" license = "MIT" authors = ["The Wasmer Engineering Team "] @@ -16,11 +16,11 @@ libc = "0.2" [dependencies.wasmer-runtime] path = "../runtime" -version = "0.5.4" +version = "0.5.5" [dependencies.wasmer-runtime-core] path = "../runtime-core" -version = "0.5.4" +version = "0.5.5" [features] debug = ["wasmer-runtime/debug"] diff --git a/lib/runtime-core/Cargo.toml b/lib/runtime-core/Cargo.toml index 936b66e16..86e2d99ff 100644 --- a/lib/runtime-core/Cargo.toml +++ b/lib/runtime-core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer-runtime-core" -version = "0.5.4" +version = "0.5.5" description = "Wasmer runtime core library" license = "MIT" authors = ["The Wasmer Engineering Team "] @@ -8,7 +8,7 @@ repository = "https://github.com/wasmerio/wasmer" edition = "2018" [dependencies] -nix = "0.12.0" +nix = "0.14.0" page_size = "0.4.1" wasmparser = "0.32.1" parking_lot = "0.7.1" @@ -55,5 +55,5 @@ cc = "1.0" debug = [] trace = ["debug"] # backend flags used in conditional compilation of Backend::variants -"backend:singlepass" = [] -"backend:llvm" = [] +"backend-singlepass" = [] +"backend-llvm" = [] diff --git a/lib/runtime-core/src/backend.rs b/lib/runtime-core/src/backend.rs index 2c51cb576..1eb8ba108 100644 --- a/lib/runtime-core/src/backend.rs +++ b/lib/runtime-core/src/backend.rs @@ -33,9 +33,9 @@ impl Backend { pub fn variants() -> &'static [&'static str] { &[ "cranelift", - #[cfg(feature = "backend:singlepass")] + #[cfg(feature = "backend-singlepass")] "singlepass", - #[cfg(feature = "backend:llvm")] + #[cfg(feature = "backend-llvm")] "llvm", ] } @@ -117,6 +117,7 @@ pub struct CompilerConfig { pub symbol_map: Option>, pub memory_bound_check_mode: MemoryBoundCheckMode, pub enforce_stack_check: bool, + pub track_state: bool, } pub trait Compiler { diff --git a/lib/runtime-core/src/state.rs b/lib/runtime-core/src/state.rs index 72046bf6f..8650cb4ac 100644 --- a/lib/runtime-core/src/state.rs +++ b/lib/runtime-core/src/state.rs @@ -111,7 +111,13 @@ impl ModuleStateMap { .unwrap(); match fsm.call_offsets.get(&(ip - base)) { - Some(x) => Some((fsm, fsm.diffs[x.diff_id].build_state(fsm))), + Some(x) => { + if x.diff_id < fsm.diffs.len() { + Some((fsm, fsm.diffs[x.diff_id].build_state(fsm))) + } else { + None + } + } None => None, } } @@ -132,7 +138,13 @@ impl ModuleStateMap { .unwrap(); match fsm.trappable_offsets.get(&(ip - base)) { - Some(x) => Some((fsm, fsm.diffs[x.diff_id].build_state(fsm))), + Some(x) => { + if x.diff_id < fsm.diffs.len() { + Some((fsm, fsm.diffs[x.diff_id].build_state(fsm))) + } else { + None + } + } None => None, } } @@ -149,7 +161,13 @@ impl ModuleStateMap { .unwrap(); match fsm.loop_offsets.get(&(ip - base)) { - Some(x) => Some((fsm, fsm.diffs[x.diff_id].build_state(fsm))), + Some(x) => { + if x.diff_id < fsm.diffs.len() { + Some((fsm, fsm.diffs[x.diff_id].build_state(fsm))) + } else { + None + } + } None => None, } } diff --git a/lib/runtime/Cargo.toml b/lib/runtime/Cargo.toml index 52951437e..596b6a16f 100644 --- a/lib/runtime/Cargo.toml +++ b/lib/runtime/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer-runtime" -version = "0.5.4" +version = "0.5.5" description = "Wasmer runtime library" license = "MIT" authors = ["The Wasmer Engineering Team "] @@ -9,17 +9,17 @@ edition = "2018" readme = "README.md" [dependencies] -wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.5.4", optional = true } +wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.5.5", optional = true } lazy_static = "1.2.0" memmap = "0.7.0" [dependencies.wasmer-runtime-core] path = "../runtime-core" -version = "0.5.4" +version = "0.5.5" [dependencies.wasmer-clif-backend] path = "../clif-backend" -version = "0.5.4" +version = "0.5.5" optional = true [dev-dependencies] diff --git a/lib/singlepass-backend/Cargo.toml b/lib/singlepass-backend/Cargo.toml index 509b423b5..2a8e5c647 100644 --- a/lib/singlepass-backend/Cargo.toml +++ b/lib/singlepass-backend/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer-singlepass-backend" -version = "0.5.4" +version = "0.5.5" repository = "https://github.com/wasmerio/wasmer" description = "Wasmer runtime single pass compiler backend" license = "MIT" @@ -8,13 +8,13 @@ authors = ["The Wasmer Engineering Team "] edition = "2018" [dependencies] -wasmer-runtime-core = { path = "../runtime-core", version = "0.5.4" } +wasmer-runtime-core = { path = "../runtime-core", version = "0.5.5" } wasmparser = "0.32.1" dynasm = "0.3.2" dynasmrt = "0.3.1" lazy_static = "1.2.0" byteorder = "1" -nix = "0.13.0" +nix = "0.14.0" libc = "0.2.49" smallvec = "0.6.9" hashbrown = "0.1" diff --git a/lib/singlepass-backend/src/codegen_x64.rs b/lib/singlepass-backend/src/codegen_x64.rs index dde93b57b..7bc6581ba 100644 --- a/lib/singlepass-backend/src/codegen_x64.rs +++ b/lib/singlepass-backend/src/codegen_x64.rs @@ -317,6 +317,7 @@ pub struct CodegenError { struct CodegenConfig { memory_bound_check_mode: MemoryBoundCheckMode, enforce_stack_check: bool, + track_state: bool, } impl ModuleCodeGenerator @@ -366,7 +367,8 @@ impl ModuleCodeGenerator begin_label_info.1 = Some(begin_offset); let begin_label = begin_label_info.0; - let machine = Machine::new(); + let mut machine = Machine::new(); + machine.track_state = self.config.as_ref().unwrap().track_state; dynasm!( assembler @@ -532,6 +534,7 @@ impl ModuleCodeGenerator self.config = Some(Arc::new(CodegenConfig { memory_bound_check_mode: config.memory_bound_check_mode, enforce_stack_check: config.enforce_stack_check, + track_state: config.track_state, })); Ok(()) } @@ -641,6 +644,13 @@ impl X64FunctionCode { BothToGPR, } let mode = match (src, dst) { + (Location::GPR(_), Location::GPR(_)) + if (op as *const u8 == Assembler::emit_imul as *const u8) => + { + RelaxMode::Direct + } + _ if (op as *const u8 == Assembler::emit_imul as *const u8) => RelaxMode::BothToGPR, + (Location::Memory(_, _), Location::Memory(_, _)) => RelaxMode::SrcToGPR, (Location::Imm64(_), Location::Imm64(_)) | (Location::Imm64(_), Location::Imm32(_)) => { RelaxMode::BothToGPR @@ -653,7 +663,6 @@ impl X64FunctionCode { RelaxMode::SrcToGPR } (_, Location::XMM(_)) => RelaxMode::SrcToGPR, - _ if (op as *const u8 == Assembler::emit_imul as *const u8) => RelaxMode::BothToGPR, // TODO: optimize this _ => RelaxMode::Direct, }; @@ -1588,6 +1597,9 @@ impl X64FunctionCode { fsm: &mut FunctionStateMap, control_stack: &mut [ControlFrame], ) -> usize { + if !m.track_state { + return ::std::usize::MAX; + } let last_frame = control_stack.last_mut().unwrap(); let mut diff = m.state.diff(&last_frame.state); diff.last = Some(last_frame.state_diff_id); @@ -1763,7 +1775,7 @@ impl FunctionCodeGenerator for X64FunctionCode { .unwrap() .insert(a.get_offset(), callback); } - InternalEvent::FunctionBegin(_) | InternalEvent::FunctionEnd => {}, + InternalEvent::FunctionBegin(_) | InternalEvent::FunctionEnd => {} InternalEvent::GetInternal(idx) => { let idx = idx as usize; assert!(idx < INTERNALS_SIZE); @@ -1814,7 +1826,11 @@ impl FunctionCodeGenerator for X64FunctionCode { ), Location::GPR(tmp), ); - let loc = get_location_released(a, &mut self.machine, self.value_stack.pop().unwrap()); + let loc = get_location_released( + a, + &mut self.machine, + self.value_stack.pop().unwrap(), + ); // Move internal into storage. Self::emit_relaxed_binop( @@ -1826,8 +1842,7 @@ impl FunctionCodeGenerator for X64FunctionCode { Location::Memory(tmp, (idx * 8) as i32), ); self.machine.release_temp_gpr(tmp); - } - //_ => unimplemented!(), + } //_ => unimplemented!(), } return Ok(()); } @@ -2405,7 +2420,14 @@ impl FunctionCodeGenerator for X64FunctionCode { loc_b, ); a.emit_jmp(Condition::NotEqual, normal_path); - a.emit_mov(Size::S64, Location::Imm64(0), ret); + Self::emit_relaxed_binop( + a, + &mut self.machine, + Assembler::emit_mov, + Size::S64, + Location::Imm64(0), + ret, + ); a.emit_jmp(Condition::None, end); a.emit_label(normal_path); @@ -4519,9 +4541,14 @@ impl FunctionCodeGenerator for X64FunctionCode { |a, m, addr| { match ret { Location::GPR(_) => {} - _ => { - a.emit_mov(Size::S64, Location::Imm64(0), ret); + Location::Memory(base, offset) => { + a.emit_mov( + Size::S32, + Location::Imm32(0), + Location::Memory(base, offset + 4), + ); // clear upper bits } + _ => unreachable!(), } Self::emit_relaxed_binop( a, diff --git a/lib/singlepass-backend/src/machine.rs b/lib/singlepass-backend/src/machine.rs index 61c3c79ce..b09d0bf85 100644 --- a/lib/singlepass-backend/src/machine.rs +++ b/lib/singlepass-backend/src/machine.rs @@ -13,6 +13,7 @@ pub struct Machine { stack_offset: MachineStackOffset, save_area_offset: Option, pub state: MachineState, + pub(crate) track_state: bool, } impl Machine { @@ -23,6 +24,7 @@ impl Machine { stack_offset: MachineStackOffset(0), save_area_offset: None, state: x64::new_machine_state(), + track_state: true, } } diff --git a/lib/spectests/Cargo.toml b/lib/spectests/Cargo.toml index ea17aa8a9..b40e17a2c 100644 --- a/lib/spectests/Cargo.toml +++ b/lib/spectests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer-spectests" -version = "0.5.4" +version = "0.5.5" description = "Wasmer spectests library" license = "MIT" authors = ["The Wasmer Engineering Team "] @@ -9,10 +9,10 @@ edition = "2018" build = "build/mod.rs" [dependencies] -wasmer-runtime-core = { path = "../runtime-core", version = "0.5.4" } -wasmer-clif-backend = { path = "../clif-backend", version = "0.5.4" } -wasmer-llvm-backend = { path = "../llvm-backend", version = "0.5.4", optional = true } -wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.5.4", optional = true } +wasmer-runtime-core = { path = "../runtime-core", version = "0.5.5" } +wasmer-clif-backend = { path = "../clif-backend", version = "0.5.5" } +wasmer-llvm-backend = { path = "../llvm-backend", version = "0.5.5", optional = true } +wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.5.5", optional = true } [build-dependencies] wabt = "0.7.2" diff --git a/lib/wasi-tests/Cargo.toml b/lib/wasi-tests/Cargo.toml index 45cd69dfd..0b86212d6 100644 --- a/lib/wasi-tests/Cargo.toml +++ b/lib/wasi-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer-wasi-tests" -version = "0.5.4" +version = "0.5.5" description = "Tests for our WASI implementation" license = "MIT" authors = ["The Wasmer Engineering Team "] @@ -9,19 +9,19 @@ publish = false build = "build/mod.rs" [dependencies] -wasmer-runtime-core = { path = "../runtime-core", version = "0.5.4" } -wasmer-wasi = { path = "../wasi", version = "0.5.4" } +wasmer-runtime-core = { path = "../runtime-core", version = "0.5.5" } +wasmer-wasi = { path = "../wasi", version = "0.5.5" } # hack to get tests to work -wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.5.4", optional = true } -wasmer-llvm-backend = { path = "../llvm-backend", version = "0.5.4", optional = true } +wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.5.5", optional = true } +wasmer-llvm-backend = { path = "../llvm-backend", version = "0.5.5", optional = true } [build-dependencies] glob = "0.2.11" [dev-dependencies] -wasmer-clif-backend = { path = "../clif-backend", version = "0.5.4" } -wasmer-dev-utils = { path = "../dev-utils", version = "0.5.4"} +wasmer-clif-backend = { path = "../clif-backend", version = "0.5.5" } +wasmer-dev-utils = { path = "../dev-utils", version = "0.5.5"} [features] clif = [] diff --git a/lib/wasi-tests/build/wasitests.rs b/lib/wasi-tests/build/wasitests.rs index c305ee44e..fc4380a61 100644 --- a/lib/wasi-tests/build/wasitests.rs +++ b/lib/wasi-tests/build/wasitests.rs @@ -32,7 +32,6 @@ pub fn compile(file: &str, ignores: &HashSet) -> Option { }; Command::new("rustc") - .arg("+nightly") .arg(file) .arg("-o") .arg(&normalized_name) @@ -85,7 +84,7 @@ pub fn compile(file: &str, ignores: &HashSet) -> Option { out_str.push_str("vec!["); for (alias, real_dir) in args.mapdir { out_str.push_str(&format!( - "(\"{}\".to_string(), \"{}\".to_string()),", + "(\"{}\".to_string(), ::std::path::PathBuf::from(\"{}\")),", alias, real_dir )); } diff --git a/lib/wasi-tests/tests/wasitests/fseek.rs b/lib/wasi-tests/tests/wasitests/fseek.rs new file mode 100644 index 000000000..e48dd5814 --- /dev/null +++ b/lib/wasi-tests/tests/wasitests/fseek.rs @@ -0,0 +1,13 @@ +#[test] +fn test_fseek() { + assert_wasi_output!( + "../../wasitests/fseek.wasm", + "fseek", + vec![( + ".".to_string(), + ::std::path::PathBuf::from("wasitests/test_fs/hamlet") + ),], + vec![], + "../../wasitests/fseek.out" + ); +} diff --git a/lib/wasi-tests/tests/wasitests/mapdir.rs b/lib/wasi-tests/tests/wasitests/mapdir.rs index beddf10c8..efb99c7a4 100644 --- a/lib/wasi-tests/tests/wasitests/mapdir.rs +++ b/lib/wasi-tests/tests/wasitests/mapdir.rs @@ -3,7 +3,10 @@ fn test_mapdir() { assert_wasi_output!( "../../wasitests/mapdir.wasm", "mapdir", - vec![], + vec![( + ".".to_string(), + ::std::path::PathBuf::from("wasitests/test_fs/hamlet") + ),], vec![], "../../wasitests/mapdir.out" ); diff --git a/lib/wasi-tests/tests/wasitests/mod.rs b/lib/wasi-tests/tests/wasitests/mod.rs index 362573068..7331b3098 100644 --- a/lib/wasi-tests/tests/wasitests/mod.rs +++ b/lib/wasi-tests/tests/wasitests/mod.rs @@ -9,6 +9,7 @@ mod create_dir; mod envvar; mod file_metadata; mod fs_sandbox_test; +mod fseek; mod hello; mod mapdir; mod quine; diff --git a/lib/wasi-tests/wasitests/create_dir.wasm b/lib/wasi-tests/wasitests/create_dir.wasm index adfb1c2d3..107c7fd37 100755 Binary files a/lib/wasi-tests/wasitests/create_dir.wasm and b/lib/wasi-tests/wasitests/create_dir.wasm differ diff --git a/lib/wasi-tests/wasitests/envvar.wasm b/lib/wasi-tests/wasitests/envvar.wasm index 2fb521f3c..41b18fe0a 100755 Binary files a/lib/wasi-tests/wasitests/envvar.wasm and b/lib/wasi-tests/wasitests/envvar.wasm differ diff --git a/lib/wasi-tests/wasitests/file_metadata.wasm b/lib/wasi-tests/wasitests/file_metadata.wasm index a51bcdf7d..daf95fbed 100755 Binary files a/lib/wasi-tests/wasitests/file_metadata.wasm and b/lib/wasi-tests/wasitests/file_metadata.wasm differ diff --git a/lib/wasi-tests/wasitests/fs_sandbox_test.wasm b/lib/wasi-tests/wasitests/fs_sandbox_test.wasm index f41bc5a17..175cea243 100755 Binary files a/lib/wasi-tests/wasitests/fs_sandbox_test.wasm and b/lib/wasi-tests/wasitests/fs_sandbox_test.wasm differ diff --git a/lib/wasi-tests/wasitests/fseek.out b/lib/wasi-tests/wasitests/fseek.out new file mode 100644 index 000000000..c9f09be6e --- /dev/null +++ b/lib/wasi-tests/wasitests/fseek.out @@ -0,0 +1,11 @@ +SCENE III. A room in Polonius' h +ouse. + + Enter LAERTES and OPH + And, sister, as the winds gi +r talk with the Lord Hamlet. + +uits, + Breathing like sanctif +is is for all: + I would not, diff --git a/lib/wasi-tests/wasitests/fseek.rs b/lib/wasi-tests/wasitests/fseek.rs new file mode 100644 index 000000000..9b9e9f65e --- /dev/null +++ b/lib/wasi-tests/wasitests/fseek.rs @@ -0,0 +1,47 @@ +// Args: +// mapdir: .:wasitests/test_fs/hamlet + +use std::fs; +use std::io::{Read, Seek, SeekFrom}; +use std::path::PathBuf; + +fn main() { + #[cfg(not(target_os = "wasi"))] + let mut base = PathBuf::from("wasitests/test_fs/hamlet"); + #[cfg(target_os = "wasi")] + let mut base = PathBuf::from("."); + + base.push("act1/scene3.txt"); + + let mut file = fs::File::open(&base).expect("Could not open file"); + + let mut buffer = [0u8; 32]; + + assert_eq!(file.read(&mut buffer).unwrap(), 32); + let str_val = std::str::from_utf8(&buffer[..]).unwrap(); + println!("{}", str_val); + + assert_eq!(file.read(&mut buffer).unwrap(), 32); + let str_val = std::str::from_utf8(&buffer[..]).unwrap(); + println!("{}", str_val); + + assert_eq!(file.seek(SeekFrom::Start(123)).unwrap(), 123); + assert_eq!(file.read(&mut buffer).unwrap(), 32); + let str_val = std::str::from_utf8(&buffer[..]).unwrap(); + println!("{}", str_val); + + assert_eq!(file.seek(SeekFrom::End(-123)).unwrap(), 6617); + assert_eq!(file.read(&mut buffer).unwrap(), 32); + let str_val = std::str::from_utf8(&buffer[..]).unwrap(); + println!("{}", str_val); + + assert_eq!(file.seek(SeekFrom::Current(-250)).unwrap(), 6399); + assert_eq!(file.read(&mut buffer).unwrap(), 32); + let str_val = std::str::from_utf8(&buffer[..]).unwrap(); + println!("{}", str_val); + + assert_eq!(file.seek(SeekFrom::Current(50)).unwrap(), 6481); + assert_eq!(file.read(&mut buffer).unwrap(), 32); + let str_val = std::str::from_utf8(&buffer[..]).unwrap(); + println!("{}", str_val); +} diff --git a/lib/wasi-tests/wasitests/fseek.wasm b/lib/wasi-tests/wasitests/fseek.wasm new file mode 100755 index 000000000..381f768e1 Binary files /dev/null and b/lib/wasi-tests/wasitests/fseek.wasm differ diff --git a/lib/wasi-tests/wasitests/hello.wasm b/lib/wasi-tests/wasitests/hello.wasm index 958d5e36d..2703be2d1 100755 Binary files a/lib/wasi-tests/wasitests/hello.wasm and b/lib/wasi-tests/wasitests/hello.wasm differ diff --git a/lib/wasi-tests/wasitests/mapdir.out b/lib/wasi-tests/wasitests/mapdir.out index baa3809d2..a40625b24 100644 --- a/lib/wasi-tests/wasitests/mapdir.out +++ b/lib/wasi-tests/wasitests/mapdir.out @@ -1,6 +1,6 @@ -"wasitests/test_fs/hamlet/README.md" -"wasitests/test_fs/hamlet/act1" -"wasitests/test_fs/hamlet/act2" -"wasitests/test_fs/hamlet/act3" -"wasitests/test_fs/hamlet/act4" -"wasitests/test_fs/hamlet/act5" +"./README.md" +"./act1" +"./act2" +"./act3" +"./act4" +"./act5" diff --git a/lib/wasi-tests/wasitests/mapdir.rs b/lib/wasi-tests/wasitests/mapdir.rs index 915e0249c..d13cf2593 100644 --- a/lib/wasi-tests/wasitests/mapdir.rs +++ b/lib/wasi-tests/wasitests/mapdir.rs @@ -4,9 +4,9 @@ use std::fs; fn main() { - #[cfg(not(target = "wasi"))] - let read_dir = fs::read_dir("wasitests/test_fs/hamlet").unwrap(); - #[cfg(target = "wasi")] + // #[cfg(not(target_os = "wasi"))] + // let read_dir = fs::read_dir("wasitests/test_fs/hamlet").unwrap(); + // #[cfg(target_os = "wasi")] let read_dir = fs::read_dir(".").unwrap(); let mut out = vec![]; for entry in read_dir { diff --git a/lib/wasi-tests/wasitests/mapdir.wasm b/lib/wasi-tests/wasitests/mapdir.wasm index 32e34888c..ff940d0e6 100755 Binary files a/lib/wasi-tests/wasitests/mapdir.wasm and b/lib/wasi-tests/wasitests/mapdir.wasm differ diff --git a/lib/wasi-tests/wasitests/quine.wasm b/lib/wasi-tests/wasitests/quine.wasm index 3b195bb08..fa5e14270 100755 Binary files a/lib/wasi-tests/wasitests/quine.wasm and b/lib/wasi-tests/wasitests/quine.wasm differ diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml index 28426be0d..d4fe8023a 100644 --- a/lib/wasi/Cargo.toml +++ b/lib/wasi/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer-wasi" -version = "0.5.4" +version = "0.5.5" description = "Wasmer runtime WASI implementation library" license = "MIT" authors = ["The Wasmer Engineering Team "] @@ -8,7 +8,7 @@ repository = "https://github.com/wasmerio/wasmer" edition = "2018" [dependencies] -wasmer-runtime-core = { path = "../runtime-core", version = "0.5.4" } +wasmer-runtime-core = { path = "../runtime-core", version = "0.5.5" } libc = "0.2.50" rand = "0.6.5" # wasmer-runtime-abi = { path = "../runtime-abi" } @@ -18,4 +18,4 @@ log = "0.4.6" byteorder = "1.3.1" [target.'cfg(windows)'.dependencies] -winapi = "0.3" \ No newline at end of file +winapi = "0.3" diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 452532627..440103a99 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -903,7 +903,28 @@ pub fn fd_seek( // TODO: handle case if fd is a dir? match whence { __WASI_WHENCE_CUR => fd_entry.offset = (fd_entry.offset as i64 + offset) as u64, - __WASI_WHENCE_END => unimplemented!("__WASI__WHENCE_END in wasi::fd_seek"), + __WASI_WHENCE_END => { + use std::io::SeekFrom; + match state.fs.inodes[fd_entry.inode].kind { + Kind::File { ref mut handle } => { + let end = wasi_try!(handle.seek(SeekFrom::End(0)).ok().ok_or(__WASI_EIO)); + // TODO: handle case if fd_entry.offset uses 64 bits of a u64 + fd_entry.offset = (end as i64 + offset) as u64; + } + Kind::Symlink { .. } => { + unimplemented!("wasi::fd_seek not implemented for symlinks") + } + Kind::Dir { .. } => { + // TODO: check this + return __WASI_EINVAL; + } + Kind::Buffer { .. } => { + // seeking buffers probably makes sense + // TODO: implement this + return __WASI_EINVAL; + } + } + } __WASI_WHENCE_SET => fd_entry.offset = offset as u64, _ => return __WASI_EINVAL, } @@ -1235,6 +1256,7 @@ pub fn path_filestat_get( let last_segment = path_vec.last().unwrap(); cumulative_path.push(last_segment); + // read it from wasi FS cache first, otherwise check host system if entries.contains_key(last_segment) { state.fs.inodes[entries[last_segment]].stat } else { @@ -1244,7 +1266,25 @@ pub fn path_filestat_get( } let final_path_metadata = wasi_try!(cumulative_path.metadata().map_err(|_| __WASI_EIO)); - wasi_try!(get_stat_for_kind(&state.fs.inodes[inode].kind).ok_or(__WASI_EIO)) + let kind = if final_path_metadata.is_file() { + let file = + wasi_try!(std::fs::File::open(&cumulative_path).ok().ok_or(__WASI_EIO)); + Kind::File { + handle: WasiFile::HostFile(file), + } + } else if final_path_metadata.is_dir() { + Kind::Dir { + parent: Some(inode), + // TODO: verify that this doesn't cause issues with relative paths + path: cumulative_path.clone(), + entries: Default::default(), + } + } else { + // TODO: check this + return __WASI_EINVAL; + }; + + wasi_try!(get_stat_for_kind(&kind).ok_or(__WASI_EIO)) } } _ => { diff --git a/lib/win-exception-handler/Cargo.toml b/lib/win-exception-handler/Cargo.toml index 20c175198..1a98fba2f 100644 --- a/lib/win-exception-handler/Cargo.toml +++ b/lib/win-exception-handler/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer-win-exception-handler" -version = "0.5.4" +version = "0.5.5" description = "Wasmer runtime exception handling for Windows" license = "MIT" authors = ["The Wasmer Engineering Team "] @@ -8,7 +8,7 @@ repository = "https://github.com/wasmerio/wasmer" edition = "2018" [target.'cfg(windows)'.dependencies] -wasmer-runtime-core = { path = "../runtime-core", version = "0.5.4" } +wasmer-runtime-core = { path = "../runtime-core", version = "0.5.5" } winapi = { version = "0.3", features = ["winbase", "errhandlingapi", "minwindef", "minwinbase", "winnt"] } libc = "0.2.49" diff --git a/src/bin/kwasmd.rs b/src/bin/kwasmd.rs index d7c05d48d..def71d589 100644 --- a/src/bin/kwasmd.rs +++ b/src/bin/kwasmd.rs @@ -5,10 +5,10 @@ extern crate structopt; use structopt::StructOpt; -#[cfg(feature = "loader:kernel")] +#[cfg(feature = "loader-kernel")] use wasmer_singlepass_backend::SinglePassCompiler; -#[cfg(feature = "loader:kernel")] +#[cfg(feature = "loader-kernel")] use std::os::unix::net::{UnixListener, UnixStream}; #[derive(Debug, StructOpt)] @@ -24,14 +24,14 @@ struct Listen { socket: String, } -#[cfg(feature = "loader:kernel")] +#[cfg(feature = "loader-kernel")] const CMD_RUN_CODE: u32 = 0x901; -#[cfg(feature = "loader:kernel")] +#[cfg(feature = "loader-kernel")] const CMD_READ_MEMORY: u32 = 0x902; -#[cfg(feature = "loader:kernel")] +#[cfg(feature = "loader-kernel")] const CMD_WRITE_MEMORY: u32 = 0x903; -#[cfg(feature = "loader:kernel")] +#[cfg(feature = "loader-kernel")] fn handle_client(mut stream: UnixStream) { use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use std::io::{Read, Write}; @@ -54,6 +54,7 @@ fn handle_client(mut stream: UnixStream) { symbol_map: None, memory_bound_check_mode: MemoryBoundCheckMode::Disable, enforce_stack_check: true, + track_state: false, }, &SinglePassCompiler::new(), ) @@ -131,7 +132,7 @@ fn handle_client(mut stream: UnixStream) { } } -#[cfg(feature = "loader:kernel")] +#[cfg(feature = "loader-kernel")] fn run_listen(opts: Listen) { let listener = UnixListener::bind(&opts.socket).unwrap(); use std::thread; @@ -154,7 +155,7 @@ fn run_listen(opts: Listen) { } } -#[cfg(feature = "loader:kernel")] +#[cfg(feature = "loader-kernel")] fn main() { let options = CLIOptions::from_args(); match options { @@ -164,7 +165,7 @@ fn main() { } } -#[cfg(not(feature = "loader:kernel"))] +#[cfg(not(feature = "loader-kernel"))] fn main() { panic!("Kwasm loader is not enabled during compilation."); } diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index d1e46fbd6..070acd9e8 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -15,7 +15,7 @@ use structopt::StructOpt; use wasmer::*; use wasmer_clif_backend::CraneliftCompiler; -#[cfg(feature = "backend:llvm")] +#[cfg(feature = "backend-llvm")] use wasmer_llvm_backend::LLVMCompiler; use wasmer_runtime::{ cache::{Cache as BaseCache, FileSystemCache, WasmHash, WASMER_VERSION_HASH}, @@ -27,7 +27,7 @@ use wasmer_runtime_core::{ debug, loader::{Instance as LoadedInstance, LocalLoader}, }; -#[cfg(feature = "backend:singlepass")] +#[cfg(feature = "backend-singlepass")] use wasmer_singlepass_backend::SinglePassCompiler; #[cfg(feature = "wasi")] use wasmer_wasi; @@ -112,10 +112,16 @@ struct Run { )] loader: Option, - #[cfg(feature = "backend:singlepass")] + /// Path to previously saved instance image to resume. + #[cfg(feature = "backend-singlepass")] #[structopt(long = "resume")] resume: Option, + /// Whether or not state tracking should be disabled during compilation. + /// State tracking is necessary for tier switching and backtracing. + #[structopt(long = "no-track-state")] + no_track_state: bool, + /// The command name is a string that will override the first argument passed /// to the wasm program. This is used in wapm to provide nicer output in /// help commands and error messages of the running wasm program @@ -137,7 +143,7 @@ struct Run { #[derive(Debug, Copy, Clone)] enum LoaderName { Local, - #[cfg(feature = "loader:kernel")] + #[cfg(feature = "loader-kernel")] Kernel, } @@ -145,7 +151,7 @@ impl LoaderName { pub fn variants() -> &'static [&'static str] { &[ "local", - #[cfg(feature = "loader:kernel")] + #[cfg(feature = "loader-kernel")] "kernel", ] } @@ -156,7 +162,7 @@ impl FromStr for LoaderName { fn from_str(s: &str) -> Result { match s.to_lowercase().as_str() { "local" => Ok(LoaderName::Local), - #[cfg(feature = "loader:kernel")] + #[cfg(feature = "loader-kernel")] "kernel" => Ok(LoaderName::Kernel), _ => Err(format!("The loader {} doesn't exist", s)), } @@ -315,25 +321,27 @@ fn execute_wasm(options: &Run) -> Result<(), String> { } let compiler: Box = match options.backend { - #[cfg(feature = "backend:singlepass")] + #[cfg(feature = "backend-singlepass")] Backend::Singlepass => Box::new(SinglePassCompiler::new()), - #[cfg(not(feature = "backend:singlepass"))] + #[cfg(not(feature = "backend-singlepass"))] Backend::Singlepass => return Err("The singlepass backend is not enabled".to_string()), Backend::Cranelift => Box::new(CraneliftCompiler::new()), - #[cfg(feature = "backend:llvm")] + #[cfg(feature = "backend-llvm")] Backend::LLVM => Box::new(LLVMCompiler::new()), - #[cfg(not(feature = "backend:llvm"))] + #[cfg(not(feature = "backend-llvm"))] Backend::LLVM => return Err("the llvm backend is not enabled".to_string()), }; - #[cfg(feature = "loader:kernel")] + let track_state = !options.no_track_state; + + #[cfg(feature = "loader-kernel")] let is_kernel_loader = if let Some(LoaderName::Kernel) = options.loader { true } else { false }; - #[cfg(not(feature = "loader:kernel"))] + #[cfg(not(feature = "loader-kernel"))] let is_kernel_loader = false; let module = if is_kernel_loader { @@ -343,6 +351,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> { symbol_map: em_symbol_map, memory_bound_check_mode: MemoryBoundCheckMode::Disable, enforce_stack_check: true, + track_state, }, &*compiler, ) @@ -352,6 +361,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> { &wasm_binary[..], CompilerConfig { symbol_map: em_symbol_map, + track_state, ..Default::default() }, &*compiler, @@ -397,6 +407,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> { &wasm_binary[..], CompilerConfig { symbol_map: em_symbol_map, + track_state, ..Default::default() }, &*compiler, @@ -440,7 +451,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> { .load(LocalLoader) .expect("Can't use the local loader"), ), - #[cfg(feature = "loader:kernel")] + #[cfg(feature = "loader-kernel")] LoaderName::Kernel => Box::new( instance .load(::wasmer_kernel_loader::KernelLoader) @@ -501,7 +512,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> { let start: Func<(), ()> = instance.func("_start").map_err(|e| format!("{:?}", e))?; - #[cfg(feature = "backend:singlepass")] + #[cfg(feature = "backend-singlepass")] unsafe { if options.backend == Backend::Singlepass { use wasmer_runtime_core::fault::{catch_unsafe_unwind, ensure_sighandler}; @@ -608,18 +619,18 @@ fn execute_wasm(options: &Run) -> Result<(), String> { Ok(()) } -#[cfg(feature = "backend:singlepass")] +#[cfg(feature = "backend-singlepass")] struct InteractiveShellContext { image: Option, } -#[cfg(feature = "backend:singlepass")] +#[cfg(feature = "backend-singlepass")] #[derive(Debug)] enum ShellExitOperation { ContinueWith(wasmer_runtime_core::state::InstanceImage), } -#[cfg(feature = "backend:singlepass")] +#[cfg(feature = "backend-singlepass")] fn interactive_shell(mut ctx: InteractiveShellContext) -> ShellExitOperation { use std::io::Write; diff --git a/update_version_numbers.sh b/update_version_numbers.sh index b9cf47dc8..7196d7ef1 100755 --- a/update_version_numbers.sh +++ b/update_version_numbers.sh @@ -1,5 +1,5 @@ -PREVIOUS_VERSION='0.5.3' -NEXT_VERSION='0.5.4' +PREVIOUS_VERSION='0.5.4' +NEXT_VERSION='0.5.5' # quick hack fd Cargo.toml --exec sed -i '' "s/version = \"$PREVIOUS_VERSION\"/version = \"$NEXT_VERSION\"/"