diff --git a/.appveyor.yml b/.appveyor.yml index 488e400fd..2a67567e4 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -14,30 +14,36 @@ environment: cache: - 'C:\Users\appveyor\.cargo' + - target install: - - appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe - - rustup-init.exe -yv --default-host %target% + # uncomment these lines if the cache is cleared, or if we must re-install rust for some reason + # - appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe + # - rustup-init.exe -yv --default-host %target% - set PATH=%PATH%;%USERPROFILE%\.cargo\bin + - rustup default stable-%target% + - rustup update - rustc -vV - cargo -vV + # Install InnoSetup + - appveyor-retry appveyor DownloadFile https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rust-ci-mirror/2017-08-22-is.exe + - 2017-08-22-is.exe /VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP- + - set PATH="C:\Program Files (x86)\Inno Setup 5";%PATH% +# uncomment to RDP to appveyor +# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) build_script: - - cargo build --verbose + - cargo build --release --verbose test_script: - - set RUST_BACKTRACE=1 - - cd ./lib/spectests && cargo test -- --test-threads 1 && cd ../.. + - cargo test --package wasmer-spectests -before_deploy: +after_build: - cd ./src/installer - iscc wasmer.iss - copy /y .\WasmerInstaller.exe ..\..\WasmerInstaller-%APPVEYOR_REPO_TAG_NAME%.exe - - appveyor PushArtifact WasmerInstaller-%APPVEYOR_REPO_TAG_NAME%.exe - -artifacts: - - path: WasmerInstaller-%APPVEYOR_REPO_TAG_NAME%.exe - name: WasmerInstaller.exe + - appveyor PushArtifact ..\..\WasmerInstaller-%APPVEYOR_REPO_TAG_NAME%.exe + - cd ..\..\ deploy: description: 'WasmerInstaller' diff --git a/Cargo.lock b/Cargo.lock deleted file mode 100644 index a31fa0a7d..000000000 --- a/Cargo.lock +++ /dev/null @@ -1,1514 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "aho-corasick" -version = "0.6.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "ansi_term" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "atty" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", - "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "autocfg" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "backtrace" -version = "0.3.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "backtrace-sys" -version = "0.1.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cc 1.0.29 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "bindgen" -version = "0.46.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)", - "cexpr 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "clang-sys 0.26.4 (registry+https://github.com/rust-lang/crates.io-index)", - "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", - "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "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)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "which 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "bitflags" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "block-buffer" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "block-padding 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "block-padding" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "byte-tools" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "byteorder" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "capstone" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "capstone-sys 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "capstone-sys" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cc 1.0.29 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "cast" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "cbindgen" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.58 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)", - "tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)", - "toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "cc" -version = "1.0.29" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "cexpr" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "nom 4.2.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "cfg-if" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "clang-sys" -version = "0.26.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", - "libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "clap" -version = "2.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "cloudabi" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "cmake" -version = "0.1.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cc 1.0.29 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "cranelift-bforest" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cranelift-entity 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "cranelift-codegen" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cranelift-bforest 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cranelift-codegen-meta 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cranelift-entity 0.26.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)", - "target-lexicon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "cranelift-codegen-meta" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cranelift-entity 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "cranelift-entity" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "cranelift-frontend" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cranelift-codegen 0.26.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.2.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "cranelift-native" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cranelift-codegen 0.26.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.2.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "cranelift-wasm" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cranelift-codegen 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cranelift-entity 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cranelift-frontend 0.26.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)", - "wasmparser 0.22.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "digest" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "either" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "enum-methods" -version = "0.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "env_logger" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "errno" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "errno-dragonfly 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "errno-dragonfly" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "failure" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", - "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "failure_derive" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)", - "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "fake-simd" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "field-offset" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "gcc" -version = "0.3.55" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "generic-array" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "glob" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "goblin" -version = "0.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "plain 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "scroll 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "hashbrown" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "heck" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "hex" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "humantime" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "indexmap" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "inkwell" -version = "0.1.0" -source = "git+https://github.com/TheDan64/inkwell?branch=llvm7-0#b8699b0ee594e4162ce850fbedb37892e9cdb7e4" -dependencies = [ - "either 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "enum-methods 0.0.8 (registry+https://github.com/rust-lang/crates.io-index)", - "inkwell_internal_macros 0.1.0 (git+https://github.com/TheDan64/inkwell?branch=llvm7-0)", - "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", - "llvm-sys 70.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "inkwell_internal_macros" -version = "0.1.0" -source = "git+https://github.com/TheDan64/inkwell?branch=llvm7-0#b8699b0ee594e4162ce850fbedb37892e9cdb7e4" -dependencies = [ - "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "itoa" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "lazy_static" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "libc" -version = "0.2.49" -source = "git+https://github.com/rust-lang/libc#b905aef34008c962ef8a4410216eae65bbb7f68f" - -[[package]] -name = "libc" -version = "0.2.49" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "libloading" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cc 1.0.29 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "llvm-sys" -version = "70.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cc 1.0.29 (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.49 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "lock_api" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "log" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "memchr" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "memmap" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (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.29 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.49 (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" -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.29 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", - "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "nom" -version = "4.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "opaque-debug" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "owning_ref" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "page_size" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "parking_lot" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "parking_lot_core" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "peeking_take_while" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "plain" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "proc-macro2" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "proc-macro2" -version = "0.4.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "quick-error" -version = "1.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "quote" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "quote" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "quote" -version = "0.6.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rand" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_jitter 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_os 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rand_chacha" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rand_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rand_core" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "rand_hc" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rand_isaac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rand_jitter" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rand_os" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.4.0 (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.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rand_pcg" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rand_xorshift" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "raw-cpuid" -version = "6.1.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.29 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "redox_syscall" -version = "0.1.51" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "redox_termios" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "regex" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "regex-syntax" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "remove_dir_all" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "ryu" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "scopeguard" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "scroll" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "scroll_derive 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "scroll_derive" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "serde" -version = "1.0.88" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "serde_derive 1.0.58 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "serde-bench" -version = "0.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "serde_bytes" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "serde_derive" -version = "1.0.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.13.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "serde_json" -version = "1.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "sha2" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "block-buffer 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "smallvec" -version = "0.6.9" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "stable_deref_trait" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "strsim" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "structopt" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", - "structopt-derive 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "structopt-derive" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "syn" -version = "0.11.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", - "synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "syn" -version = "0.13.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "syn" -version = "0.15.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "synom" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "synstructure" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "target-lexicon" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "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)", - "serde_json 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "tempfile" -version = "3.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", - "remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "termcolor" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "termion" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "textwrap" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "thread_local" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "time" -version = "0.1.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "toml" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "typenum" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "ucd-util" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "unicode-segmentation" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "unicode-width" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "unicode-xid" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "unicode-xid" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "utf8-ranges" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "vec_map" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "version_check" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "void" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "wabt" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.58 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)", - "wabt-sys 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "wabt-sys" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cc 1.0.29 (registry+https://github.com/rust-lang/crates.io-index)", - "cmake 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", - "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "wasmer" -version = "0.1.4" -dependencies = [ - "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "structopt 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", - "wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-clif-backend 0.1.2", - "wasmer-emscripten 0.1.0", - "wasmer-runtime 0.1.4", - "wasmer-runtime-core 0.1.2", -] - -[[package]] -name = "wasmer-clif-backend" -version = "0.1.2" -dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "cranelift-codegen 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cranelift-entity 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cranelift-native 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cranelift-wasm 0.26.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.49 (registry+https://github.com/rust-lang/crates.io-index)", - "nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.88 (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.58 (registry+https://github.com/rust-lang/crates.io-index)", - "target-lexicon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-runtime-core 0.1.2", - "wasmer-win-exception-handler 0.0.1", - "wasmparser 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "wasmer-emscripten" -version = "0.1.0" -dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.49 (git+https://github.com/rust-lang/libc)", - "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", - "wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-clif-backend 0.1.2", - "wasmer-runtime-core 0.1.2", -] - -[[package]] -name = "wasmer-llvm-backend" -version = "0.1.0" -dependencies = [ - "capstone 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.29 (registry+https://github.com/rust-lang/crates.io-index)", - "goblin 0.0.20 (registry+https://github.com/rust-lang/crates.io-index)", - "hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "inkwell 0.1.0 (git+https://github.com/TheDan64/inkwell?branch=llvm7-0)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", - "nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.0 (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.1.2", - "wasmparser 0.28.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "wasmer-runtime" -version = "0.1.4" -dependencies = [ - "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)", - "wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-clif-backend 0.1.2", - "wasmer-llvm-backend 0.1.0", - "wasmer-runtime-core 0.1.2", -] - -[[package]] -name = "wasmer-runtime-c-api" -version = "0.1.4" -dependencies = [ - "cbindgen 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-runtime 0.1.4", - "wasmer-runtime-core 0.1.2", -] - -[[package]] -name = "wasmer-runtime-core" -version = "0.1.2" -dependencies = [ - "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)", - "hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "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.49 (registry+https://github.com/rust-lang/crates.io-index)", - "nix 0.12.0 (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)", - "serde 1.0.88 (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.58 (registry+https://github.com/rust-lang/crates.io-index)", - "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-clif-backend 0.1.2", - "wasmparser 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "wasmer-spectests" -version = "0.1.2" -dependencies = [ - "wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-clif-backend 0.1.2", - "wasmer-llvm-backend 0.1.0", - "wasmer-runtime-core 0.1.2", -] - -[[package]] -name = "wasmer-win-exception-handler" -version = "0.0.1" -dependencies = [ - "bindgen 0.46.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cmake 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-runtime-core 0.1.2", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "wasmparser" -version = "0.22.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "wasmparser" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "wasmparser" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "which" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "winapi" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "winapi-util" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "wincolor" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[metadata] -"checksum aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5" -"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" -"checksum autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a6d640bee2da49f60a4068a7fae53acde8982514ab7bae8b8cea9e88cbcfd799" -"checksum backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "cd5a90e2b463010cd0e0ce9a11d4a9d5d58d9f41d4a6ba3dcaf9e68b466e88b4" -"checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6" -"checksum bindgen 0.46.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8f7f7f0701772b17de73e4f5cbcb1dd6926f4706cba4c1ab62c5367f8bdc94e1" -"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" -"checksum block-buffer 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49665c62e0e700857531fa5d3763e91b539ff1abeebd56808d378b495870d60d" -"checksum block-padding 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d75255892aeb580d3c566f213a2b6fdc1c66667839f45719ee1d30ebf2aea591" -"checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" -"checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb" -"checksum capstone 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "00be9d203fa0e078b93b24603633fb081851dfe0c1086364431f52587a47157e" -"checksum capstone-sys 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2dc8d32bc5c1e6d0fcde10af411c98b07d93498d51654f678757f08fa2acd6a6" -"checksum cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427" -"checksum cbindgen 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "32e01024aaf5390d6a8145047371a4f5b0063a14c1e411bc731353bd2278ca44" -"checksum cc 1.0.29 (registry+https://github.com/rust-lang/crates.io-index)" = "4390a3b5f4f6bce9c1d0c00128379df433e53777fdd30e92f16a529332baec4e" -"checksum cexpr 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "644d693ecfa91955ed32dcc7eda4914e1be97a641fb6f0645a37348e20b230da" -"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4" -"checksum clang-sys 0.26.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6ef0c1bcf2e99c649104bd7a7012d8f8802684400e03db0ec0af48583c6fa0e4" -"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" -"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -"checksum cmake 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "6ec65ee4f9c9d16f335091d23693457ed4928657ba4982289d7fafee03bc614a" -"checksum cranelift-bforest 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)" = "40f8ff24e9a6c89b8a846b14df9a34d2cac17cea7bdb5c81ed6b4744ee0e38bf" -"checksum cranelift-codegen 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)" = "42f5b809bd885c368e01aeec8fe04f21dcb07569834b907d75b4a7bed8d067eb" -"checksum cranelift-codegen-meta 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)" = "014c23ed3ebdc8377d41540af638245207dd169f421df042dfccc867465734ed" -"checksum cranelift-entity 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4df40e26c0cf7b4d86919cb995bb412ee3001cc18e4f3c83a903f30b7007d8b" -"checksum cranelift-frontend 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)" = "789907218eeebebcea8122c2053d71affac91c96ce72cea35ebfdbbf547e82af" -"checksum cranelift-native 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)" = "474bee81d620a473bf43411a3d6f10ffbf7965141dc5e5b76d8d2151dde3285d" -"checksum cranelift-wasm 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49723365dab9a48b354bdc24cb6d9d5719bc1d3b858ffd2ea179d0d7d885804a" -"checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c" -"checksum either 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c67353c641dc847124ea1902d69bd753dee9bb3beff9aa3662ecf86c971d1fac" -"checksum enum-methods 0.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7798e7da2d4cb0d6d6fc467e8d6b5bf247e9e989f786dde1732d79899c32bb10" -"checksum env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "afb070faf94c85d17d50ca44f6ad076bce18ae92f0037d350947240a36e9d42e" -"checksum errno 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c2a071601ed01b988f896ab14b95e67335d1eeb50190932a1320f7fe3cadc84e" -"checksum errno-dragonfly 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "14ca354e36190500e1e1fb267c647932382b54053c50b14970856c0b00a35067" -"checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" -"checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" -"checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" -"checksum field-offset 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "64e9bc339e426139e02601fa69d101e96a92aee71b58bc01697ec2a63a5c9e68" -"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" -"checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" -"checksum generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c0f28c2f5bfb5960175af447a2da7c18900693738343dc896ffbcabd9839592" -"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 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" -"checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d" -"checksum inkwell 0.1.0 (git+https://github.com/TheDan64/inkwell?branch=llvm7-0)" = "" -"checksum inkwell_internal_macros 0.1.0 (git+https://github.com/TheDan64/inkwell?branch=llvm7-0)" = "" -"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b" -"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" -"checksum libc 0.2.49 (git+https://github.com/rust-lang/libc)" = "" -"checksum libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)" = "413f3dfc802c5dc91dc570b05125b6cda9855edfaa9825c9849807876376e70e" -"checksum libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3ad660d7cb8c5822cd83d10897b0f1f1526792737a179e73896152f85b88c2" -"checksum llvm-sys 70.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "60a9ee82fe0fa72ae6ef6d018b407296085863836451c7a97384f84ed7e26b9f" -"checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" -"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" -"checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" -"checksum memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" -"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 nom 4.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4836e9d6036552017e107edc598c97b2dee245161ff1b1ad4af215004774b354" -"checksum opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "93f5bb2e8e8dec81642920ccff6b61f1eb94fa3020c5a325c9851ff604152409" -"checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13" -"checksum page_size 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f89ef58b3d32420dbd1a43d2f38ae92f6239ef12bb556ab09ca55445f5a67242" -"checksum parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337" -"checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" -"checksum peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" -"checksum plain 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" -"checksum proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1b06e2f335f48d24442b35a19df506a835fb3547bc3c06ef27340da9acf5cae7" -"checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915" -"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" -"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" -"checksum quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9949cfe66888ffe1d53e6ec9d9f3b70714083854be20fd5e271b232a017401e8" -"checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1" -"checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" -"checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" -"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -"checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0" -"checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" -"checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -"checksum rand_jitter 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b9ea758282efe12823e0d952ddb269d2e1897227e464919a554f2a03ef1b832" -"checksum rand_os 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b7c690732391ae0abafced5015ffb53656abfaec61b342290e5eb56b286a679d" -"checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" -"checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" -"checksum raw-cpuid 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "30a9d219c32c9132f7be513c18be77c9881c7107d2ab5569d205a6a0f0e6dc7d" -"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -"checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85" -"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" -"checksum regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "37e7cbbd370869ce2e8dff25c7018702d10b21a20ef7135316f8daecd6c25b7f" -"checksum regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8c2f35eedad5295fdf00a63d7d4b238135723f92b434ec06774dad15c7ab0861" -"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" -"checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619" -"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" -"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" -"checksum scroll 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2f84d114ef17fd144153d608fba7c446b0145d038985e7a8cc5d08bb0ce20383" -"checksum scroll_derive 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8f1aa96c45e7f5a91cb7fabe7b279f02fea7126239fc40b732316e8b6a2d0fcb" -"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -"checksum serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)" = "9f301d728f2b94c9a7691c90f07b0b4e8a4517181d9461be94c04bddeb4bd850" -"checksum serde-bench 0.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "d733da87e79faaac25616e33d26299a41143fd4cd42746cbb0e91d8feea243fd" -"checksum serde_bytes 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)" = "defbb8a83d7f34cc8380751eeb892b825944222888aff18996ea7901f24aec88" -"checksum serde_derive 1.0.58 (registry+https://github.com/rust-lang/crates.io-index)" = "ac38f51a52a556cd17545798e29536885fb1a3fa63d6399f5ef650f4a7d35901" -"checksum serde_json 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)" = "27dce848e7467aa0e2fcaf0a413641499c0b745452aaca1194d24dedde9e13c9" -"checksum sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4d8bfd0e469f417657573d8451fb33d16cfe0989359b93baf3a1ffc639543d" -"checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" -"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" -"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" -"checksum structopt 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "670ad348dc73012fcf78c71f06f9d942232cdd4c859d4b6975e27836c3efc0c3" -"checksum structopt-derive 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "ef98172b1a00b0bec738508d3726540edcbd186d50dfd326f2b1febbb3559f04" -"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" -"checksum syn 0.13.11 (registry+https://github.com/rust-lang/crates.io-index)" = "14f9bf6292f3a61d2c716723fdb789a41bbe104168e6f496dc6497e531ea1b9b" -"checksum syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)" = "f92e629aa1d9c827b2bb8297046c1ccffc57c99b947a680d3ccff1f136a3bee9" -"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" -"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" -"checksum target-lexicon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4af5e2227f0b887d591d3724b796a96eff04226104d872f5b3883fcd427d64b9" -"checksum tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b86c784c88d98c801132806dadd3819ed29d8600836c4088e855cdf3e178ed8a" -"checksum termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4096add70612622289f2fdcdbd5086dc81c1e2675e6ae58d6c4f62a16c6d7f2f" -"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" -"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6" -"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" -"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" -"checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" -"checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" -"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" -"checksum unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aa6024fc12ddfd1c6dbc14a80fa2324d4568849869b779f6bd37e5e4c03344d1" -"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" -"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" -"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" -"checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" -"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" -"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" -"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" -"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 wasmparser 0.22.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f46e666ecb4a406483a59a49f9d0c17f327e70da53a128eccddae2eadb95865c" -"checksum wasmparser 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b5e01c420bc7d36e778bd242e1167b079562ba8b34087122cc9057187026d060" -"checksum wasmparser 0.28.0 (registry+https://github.com/rust-lang/crates.io-index)" = "40f426b1929bd26517fb10702e2a8e520d1845c49567aa4d244f426f10b206c1" -"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" -"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" -"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" -"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -"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.1 (registry+https://github.com/rust-lang/crates.io-index)" = "561ed901ae465d6185fa7864d63fbd5720d0ef718366c9a4dc83cf6170d7e9ba" diff --git a/Cargo.toml b/Cargo.toml index 062f66ba3..d987498cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer" -version = "0.1.4" +version = "0.2.1" authors = ["The Wasmer Engineering Team "] edition = "2018" repository = "https://github.com/wasmerio/wasmer" @@ -36,6 +36,6 @@ glob = "0.2.11" [features] default = ["fast-tests"] -debug = [] +debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] # This feature will allow cargo test to run much faster fast-tests = [] diff --git a/Makefile b/Makefile index 2506f196c..74e3428fc 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ capi: # rm -rf artifacts build: - cargo build + cargo build --features debug install: cargo install --path . @@ -47,6 +47,9 @@ release: # brew install mingw-w64 cargo build --release +debug-release: + cargo build --release --features debug + debug-release: cargo build --release --features "debug" diff --git a/README.md b/README.md index bdb921afd..74e9ef575 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,14 @@ You can also run integration tests with: make integration-tests ``` +## Benchmarking + +Benchmarks can be run with: + +```sh +cargo bench --all +``` + ## Roadmap Wasmer is an open project guided by strong principles, aiming to be modular, flexible and fast. It is open to the community to help set its direction. diff --git a/examples/nginx/LICENSE b/examples/nginx/LICENSE new file mode 100644 index 000000000..c63e0ba4e --- /dev/null +++ b/examples/nginx/LICENSE @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2002-2019 Igor Sysoev + * Copyright (C) 2011-2019 Nginx, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ diff --git a/install.sh b/install.sh index 04b5f364a..0b7da4ca2 100755 --- a/install.sh +++ b/install.sh @@ -133,7 +133,7 @@ wasmer_link() { SOURCE_STR="# Wasmer config\nexport WASMER_DIR=\"\$HOME/.wasmer\"\nexport WASMER_CACHE_DIR=\"\$WASMER_DIR/cache\"\nexport PATH=\"\$HOME/.wasmer/bin:\$PATH\"\n" # We create the wasmer.sh file - echo "$SOURCE_STR" > "$HOME/.wasmer/wasmer.sh" + printf "$SOURCE_STR" > "$HOME/.wasmer/wasmer.sh" if [ -z "${WASMER_PROFILE-}" ] ; then printf "${red}Profile not found. Tried:\n* ${WASMER_PROFILE} (as defined in \$PROFILE)\n* ~/.bashrc\n* ~/.bash_profile\n* ~/.zshrc\n* ~/.profile.\n" diff --git a/lib/clif-backend/Cargo.toml b/lib/clif-backend/Cargo.toml index 701f821fc..3ac5105cf 100644 --- a/lib/clif-backend/Cargo.toml +++ b/lib/clif-backend/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer-clif-backend" -version = "0.1.2" +version = "0.2.0" description = "Wasmer runtime Cranelift compiler backend" 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.1.2" } +wasmer-runtime-core = { path = "../runtime-core", version = "0.2.0" } cranelift-native = "0.26.0" cranelift-codegen = "0.26.0" cranelift-entity = "0.26.0" @@ -18,7 +18,8 @@ target-lexicon = "0.2.0" wasmparser = "0.23.0" byteorder = "1" nix = "0.13.0" -libc = "0.2.48" +libc = "0.2.49" +rayon = "1.0" # Dependencies for caching. [dependencies.serde] @@ -32,7 +33,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.0.1" } +wasmer-win-exception-handler = { path = "../win-exception-handler", version = "0.2.0" } [features] debug = ["wasmer-runtime-core/debug"] diff --git a/lib/clif-backend/src/lib.rs b/lib/clif-backend/src/lib.rs index 967cdd5ed..88de51e12 100644 --- a/lib/clif-backend/src/lib.rs +++ b/lib/clif-backend/src/lib.rs @@ -24,6 +24,7 @@ use wasmer_runtime_core::{ #[macro_use] extern crate serde_derive; +extern crate rayon; extern crate serde; use wasmparser::{self, WasmDecoder}; diff --git a/lib/clif-backend/src/resolver.rs b/lib/clif-backend/src/resolver.rs index 3095e8882..94713e0b2 100644 --- a/lib/clif-backend/src/resolver.rs +++ b/lib/clif-backend/src/resolver.rs @@ -7,6 +7,7 @@ use crate::{ }, signal::HandlerData, }; +use rayon::prelude::*; use byteorder::{ByteOrder, LittleEndian}; use cranelift_codegen::{ir, isa, Context}; @@ -92,25 +93,44 @@ impl FuncResolverBuilder { function_bodies: Map, info: &ModuleInfo, ) -> CompileResult<(Self, HandlerData)> { - let mut compiled_functions: Vec> = Vec::with_capacity(function_bodies.len()); - let mut local_relocs = Map::with_capacity(function_bodies.len()); - let mut external_relocs = Map::new(); + let num_func_bodies = function_bodies.len(); + let mut local_relocs = Map::with_capacity(num_func_bodies); + let mut external_relocs = Map::with_capacity(num_func_bodies); let mut trap_sink = TrapSink::new(); - let mut local_trap_sink = LocalTrapSink::new(); - let mut ctx = Context::new(); + let compiled_functions: Result, (RelocSink, LocalTrapSink))>, CompileError> = + function_bodies + .into_vec() + .par_iter() + .map_init( + || Context::new(), + |ctx, func| { + let mut code_buf = Vec::new(); + ctx.func = func.to_owned(); + let mut reloc_sink = RelocSink::new(); + let mut local_trap_sink = LocalTrapSink::new(); + + ctx.compile_and_emit( + isa, + &mut code_buf, + &mut reloc_sink, + &mut local_trap_sink, + ) + .map_err(|e| CompileError::InternalError { msg: e.to_string() })?; + ctx.clear(); + Ok((code_buf, (reloc_sink, local_trap_sink))) + }, + ) + .collect(); + + let compiled_functions = compiled_functions?; let mut total_size = 0; - - for (_, func) in function_bodies { - ctx.func = func; - let mut code_buf = Vec::new(); - let mut reloc_sink = RelocSink::new(); - - ctx.compile_and_emit(isa, &mut code_buf, &mut reloc_sink, &mut local_trap_sink) - .map_err(|e| CompileError::InternalError { msg: e.to_string() })?; - ctx.clear(); - + // We separate into two iterators, one iterable and one into iterable + let (code_bufs, sinks): (Vec>, Vec<(RelocSink, LocalTrapSink)>) = + compiled_functions.into_iter().unzip(); + for (code_buf, (reloc_sink, mut local_trap_sink)) in code_bufs.iter().zip(sinks.into_iter()) + { // Clear the local trap sink and consolidate all trap info // into a single location. trap_sink.drain_local(total_size, &mut local_trap_sink); @@ -118,7 +138,6 @@ impl FuncResolverBuilder { // Round up each function's size to pointer alignment. total_size += round_up(code_buf.len(), mem::size_of::()); - compiled_functions.push(code_buf); local_relocs.push(reloc_sink.local_relocs.into_boxed_slice()); external_relocs.push(reloc_sink.external_relocs.into_boxed_slice()); } @@ -145,10 +164,10 @@ impl FuncResolverBuilder { *i = 0xCC; } - let mut map = Map::with_capacity(compiled_functions.len()); + let mut map = Map::with_capacity(num_func_bodies); let mut previous_end = 0; - for compiled in compiled_functions.iter() { + for compiled in code_bufs.iter() { let new_end = previous_end + round_up(compiled.len(), mem::size_of::()); unsafe { memory.as_slice_mut()[previous_end..previous_end + compiled.len()] diff --git a/lib/clif-backend/src/signal/mod.rs b/lib/clif-backend/src/signal/mod.rs index f73edd2a2..04b97e832 100644 --- a/lib/clif-backend/src/signal/mod.rs +++ b/lib/clif-backend/src/signal/mod.rs @@ -2,7 +2,7 @@ use crate::relocation::{TrapData, TrapSink}; use crate::trampoline::Trampolines; use hashbrown::HashSet; use libc::c_void; -use std::{cell::Cell, sync::Arc}; +use std::{any::Any, cell::Cell, sync::Arc}; use wasmer_runtime_core::{ backend::{ProtectedCaller, Token, UserTrapper}, error::RuntimeResult, @@ -25,14 +25,14 @@ pub use self::unix::*; pub use self::windows::*; thread_local! { - pub static TRAP_EARLY_DATA: Cell> = Cell::new(None); + pub static TRAP_EARLY_DATA: Cell>> = Cell::new(None); } pub struct Trapper; impl UserTrapper for Trapper { - unsafe fn do_early_trap(&self, msg: String) -> ! { - TRAP_EARLY_DATA.with(|cell| cell.set(Some(msg))); + unsafe fn do_early_trap(&self, data: Box) -> ! { + TRAP_EARLY_DATA.with(|cell| cell.set(Some(data))); trigger_trap() } } diff --git a/lib/clif-backend/src/signal/unix.rs b/lib/clif-backend/src/signal/unix.rs index 9d2f80eca..86cc53638 100644 --- a/lib/clif-backend/src/signal/unix.rs +++ b/lib/clif-backend/src/signal/unix.rs @@ -79,8 +79,8 @@ pub fn call_protected(handler_data: &HandlerData, f: impl FnOnce() -> T) -> R if signum != 0 { *jmp_buf = prev_jmp_buf; - if let Some(msg) = super::TRAP_EARLY_DATA.with(|cell| cell.replace(None)) { - Err(RuntimeError::User { msg }) + if let Some(data) = super::TRAP_EARLY_DATA.with(|cell| cell.replace(None)) { + Err(RuntimeError::Panic { data }) } else { let (faulting_addr, inst_ptr) = CAUGHT_ADDRESSES.with(|cell| cell.get()); @@ -91,28 +91,28 @@ pub fn call_protected(handler_data: &HandlerData, f: impl FnOnce() -> T) -> R { Err(match Signal::from_c_int(signum) { Ok(SIGILL) => match trapcode { - TrapCode::BadSignature => RuntimeError::IndirectCallSignature { - table: TableIndex::new(0), + TrapCode::BadSignature => RuntimeError::Trap { + msg: "incorrect call_indirect signature".into(), }, - TrapCode::IndirectCallToNull => RuntimeError::IndirectCallToNull { - table: TableIndex::new(0), + TrapCode::IndirectCallToNull => RuntimeError::Trap { + msg: "indirect call to null".into(), }, - TrapCode::HeapOutOfBounds => RuntimeError::OutOfBoundsAccess { - memory: MemoryIndex::new(0), - addr: None, + TrapCode::HeapOutOfBounds => RuntimeError::Trap { + msg: "memory out-of-bounds access".into(), }, - TrapCode::TableOutOfBounds => RuntimeError::TableOutOfBounds { - table: TableIndex::new(0), + TrapCode::TableOutOfBounds => RuntimeError::Trap { + msg: "table out-of-bounds access".into(), }, - _ => RuntimeError::Unknown { - msg: "unknown trap".to_string(), + _ => RuntimeError::Trap { + msg: "unknown trap".into(), }, }, - Ok(SIGSEGV) | Ok(SIGBUS) => RuntimeError::OutOfBoundsAccess { - memory: MemoryIndex::new(0), - addr: None, + Ok(SIGSEGV) | Ok(SIGBUS) => RuntimeError::Trap { + msg: "memory out-of-bounds access".into(), + }, + Ok(SIGFPE) => RuntimeError::Trap { + msg: "illegal arithmetic operation".into(), }, - Ok(SIGFPE) => RuntimeError::IllegalArithmeticOperation, _ => unimplemented!(), } .into()) @@ -126,8 +126,8 @@ pub fn call_protected(handler_data: &HandlerData, f: impl FnOnce() -> T) -> R _ => "unkown trapped signal", }; // When the trap-handler is fully implemented, this will return more information. - Err(RuntimeError::Unknown { - msg: format!("trap at {:p} - {}", faulting_addr, signal), + Err(RuntimeError::Trap { + msg: format!("unknown trap at {:p} - {}", faulting_addr, signal).into(), } .into()) } diff --git a/lib/clif-backend/src/signal/windows.rs b/lib/clif-backend/src/signal/windows.rs index 191085d91..e5bd41994 100644 --- a/lib/clif-backend/src/signal/windows.rs +++ b/lib/clif-backend/src/signal/windows.rs @@ -57,35 +57,34 @@ pub fn call_protected( }) = handler_data.lookup(instruction_pointer as _) { Err(match signum as DWORD { - EXCEPTION_ACCESS_VIOLATION => RuntimeError::OutOfBoundsAccess { - memory: MemoryIndex::new(0), - addr: None, + EXCEPTION_ACCESS_VIOLATION => RuntimeError::Trap { + msg: "memory out-of-bounds access".into(), }, EXCEPTION_ILLEGAL_INSTRUCTION => match trapcode { - TrapCode::BadSignature => RuntimeError::IndirectCallSignature { - table: TableIndex::new(0), + TrapCode::BadSignature => RuntimeError::Trap { + msg: "incorrect call_indirect signature".into(), }, - TrapCode::IndirectCallToNull => RuntimeError::IndirectCallToNull { - table: TableIndex::new(0), + TrapCode::IndirectCallToNull => RuntimeError::Trap { + msg: "indirect call to null".into(), }, - TrapCode::HeapOutOfBounds => RuntimeError::OutOfBoundsAccess { - memory: MemoryIndex::new(0), - addr: None, + TrapCode::HeapOutOfBounds => RuntimeError::Trap { + msg: "memory out-of-bounds access".into(), }, - TrapCode::TableOutOfBounds => RuntimeError::TableOutOfBounds { - table: TableIndex::new(0), + TrapCode::TableOutOfBounds => RuntimeError::Trap { + msg: "table out-of-bounds access".into(), }, - _ => RuntimeError::Unknown { - msg: "unknown trap".to_string(), + _ => RuntimeError::Trap { + msg: "unknown trap".into(), }, }, - EXCEPTION_STACK_OVERFLOW => RuntimeError::Unknown { - msg: "unknown trap".to_string(), + EXCEPTION_STACK_OVERFLOW => RuntimeError::Trap { + msg: "stack overflow trap".into(), }, - EXCEPTION_INT_DIVIDE_BY_ZERO => RuntimeError::IllegalArithmeticOperation, - EXCEPTION_INT_OVERFLOW => RuntimeError::IllegalArithmeticOperation, - _ => RuntimeError::Unknown { - msg: "unknown trap".to_string(), + EXCEPTION_INT_DIVIDE_BY_ZERO | EXCEPTION_INT_OVERFLOW => RuntimeError::Trap { + msg: "illegal arithmetic operation".into(), + }, + _ => RuntimeError::Trap { + msg: "unknown trap".into(), }, } .into()) @@ -103,8 +102,8 @@ pub fn call_protected( _ => "unkown trapped signal", }; - Err(RuntimeError::Unknown { - msg: format!("trap at {} - {}", exception_address, signal), + Err(RuntimeError::Trap { + msg: format!("unknown trap at {} - {}", exception_address, signal).into(), } .into()) } diff --git a/lib/emscripten/Cargo.toml b/lib/emscripten/Cargo.toml index ec5e035d6..62fb40c5a 100644 --- a/lib/emscripten/Cargo.toml +++ b/lib/emscripten/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer-emscripten" -version = "0.1.0" +version = "0.2.1" description = "Wasmer runtime emscripten implementation library" license = "MIT" authors = ["The Wasmer Engineering Team "] @@ -9,9 +9,9 @@ edition = "2018" build = "build/mod.rs" [dependencies] -wasmer-runtime-core = { path = "../runtime-core", version = "0.1.0" } +wasmer-runtime-core = { path = "../runtime-core", version = "0.2.1" } lazy_static = "1.2.0" -libc = { git = "https://github.com/rust-lang/libc" } +libc = "0.2.49" byteorder = "1" time = "0.1.41" @@ -19,7 +19,7 @@ time = "0.1.41" rand = "0.6" [dev-dependencies] -wasmer-clif-backend = { path = "../clif-backend", version = "0.1.0" } +wasmer-clif-backend = { path = "../clif-backend", version = "0.2.0" } wabt = "0.7.2" [build-dependencies] diff --git a/lib/emscripten/emtests/test_getcwd.c b/lib/emscripten/emtests/test_getcwd.c new file mode 100644 index 000000000..a3955d470 --- /dev/null +++ b/lib/emscripten/emtests/test_getcwd.c @@ -0,0 +1,10 @@ +#include +#include + +int main() { + const unsigned int size = 256; + char cwd[size] = {}; + char* buf = getcwd(cwd, size); + printf("getcwd\n"); + return 0; +} diff --git a/lib/emscripten/emtests/test_getcwd.out b/lib/emscripten/emtests/test_getcwd.out new file mode 100644 index 000000000..263db4c74 --- /dev/null +++ b/lib/emscripten/emtests/test_getcwd.out @@ -0,0 +1 @@ +getcwd diff --git a/lib/emscripten/emtests/test_getcwd.wasm b/lib/emscripten/emtests/test_getcwd.wasm new file mode 100644 index 000000000..0cf6f73a2 Binary files /dev/null and b/lib/emscripten/emtests/test_getcwd.wasm differ diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index 4f3fa0d3d..362218a30 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -502,6 +502,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "___syscall168" => func!(crate::syscalls::___syscall168), "___syscall180" => func!(crate::syscalls::___syscall180), "___syscall181" => func!(crate::syscalls::___syscall181), + "___syscall183" => func!(crate::syscalls::___syscall183), "___syscall191" => func!(crate::syscalls::___syscall191), "___syscall192" => func!(crate::syscalls::___syscall192), "___syscall194" => func!(crate::syscalls::___syscall194), diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index ef9ef40ee..7c5ee578b 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -46,8 +46,13 @@ use std::slice; // Another conditional constant for name resolution: Macos et iOS use // SO_NOSIGPIPE as a setsockopt flag to disable SIGPIPE emission on socket. // Other platforms do otherwise. +use crate::env::get_emscripten_data; +use crate::utils::copy_cstr_into_wasm; +use crate::utils::read_string_from_wasm; #[cfg(target_os = "darwin")] use libc::SO_NOSIGPIPE; +use std::ffi::CString; + #[cfg(not(target_os = "darwin"))] const SO_NOSIGPIPE: c_int = 0; @@ -66,10 +71,10 @@ pub fn ___syscall3(ctx: &mut Ctx, which: i32, mut varargs: VarArgs) -> i32 { debug!("emscripten::___syscall3 (read) {}", which); let fd: i32 = varargs.get(ctx); let buf: u32 = varargs.get(ctx); - let count = varargs.get(ctx); + let count: i32 = varargs.get(ctx); debug!("=> fd: {}, buf_offset: {}, count: {}", fd, buf, count); let buf_addr = emscripten_memory_pointer!(ctx.memory(0), buf) as *mut c_void; - let ret = unsafe { read(fd, buf_addr, count) }; + let ret = unsafe { read(fd, buf_addr, count as _) }; debug!("=> ret: {}", ret); ret as _ } @@ -79,10 +84,10 @@ pub fn ___syscall4(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall4 (write) {}", which); let fd: i32 = varargs.get(ctx); let buf: u32 = varargs.get(ctx); - let count = varargs.get(ctx); + let count: i32 = varargs.get(ctx); debug!("=> fd: {}, buf: {}, count: {}", fd, buf, count); let buf_addr = emscripten_memory_pointer!(ctx.memory(0), buf) as *const c_void; - unsafe { write(fd, buf_addr, count) as i32 } + unsafe { write(fd, buf_addr, count as _) as i32 } } /// close @@ -186,6 +191,25 @@ pub fn ___syscall110(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { -1 } +// getcwd +pub fn ___syscall183(ctx: &mut Ctx, buf_offset: u32, _size: u32) -> u32 { + debug!("emscripten::___syscall183"); + use std::env; + let path = env::current_dir(); + let path_string = path.unwrap().display().to_string(); + let len = path_string.len(); + unsafe { + let pointer_to_buffer = + emscripten_memory_pointer!(ctx.memory(0), buf_offset) as *mut libc::c_char; + let slice = slice::from_raw_parts_mut(pointer_to_buffer, len.clone()); + for (byte, loc) in path_string.bytes().zip(slice.iter_mut()) { + *loc = byte as _; + } + *pointer_to_buffer.add(len.clone()) = 0; + } + buf_offset +} + // mmap2 pub fn ___syscall192(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall192 (mmap2) {}", which); @@ -217,10 +241,10 @@ pub fn ___syscall140(ctx: &mut Ctx, which: i32, mut varargs: VarArgs) -> i32 { // -> c_int debug!("emscripten::___syscall140 (lseek) {}", which); let fd: i32 = varargs.get(ctx); - let offset = varargs.get(ctx); + let offset: i32 = varargs.get(ctx); let whence: i32 = varargs.get(ctx); debug!("=> fd: {}, offset: {}, whence = {}", fd, offset, whence); - unsafe { lseek(fd, offset, whence) as _ } + unsafe { lseek(fd, offset as _, whence) as _ } } /// readv diff --git a/lib/emscripten/tests/emtests/mod.rs b/lib/emscripten/tests/emtests/mod.rs index 37c88a041..a280fc48a 100644 --- a/lib/emscripten/tests/emtests/mod.rs +++ b/lib/emscripten/tests/emtests/mod.rs @@ -54,6 +54,7 @@ mod test_funcptrfunc; mod test_funcs; mod test_functionpointer_libfunc_varargs; mod test_fwrite_0; +mod test_getcwd; mod test_getgep; mod test_getloadavg; mod test_getopt; diff --git a/lib/emscripten/tests/emtests/test_getcwd.rs b/lib/emscripten/tests/emtests/test_getcwd.rs new file mode 100644 index 000000000..ec770b505 --- /dev/null +++ b/lib/emscripten/tests/emtests/test_getcwd.rs @@ -0,0 +1,9 @@ +#[test] +fn test_getcwd() { + assert_emscripten_output!( + "../../emtests/test_getcwd.wasm", + "getcwd", + vec![], + "../../emtests/test_getcwd.out" + ); +} diff --git a/lib/runtime-c-api/Cargo.toml b/lib/runtime-c-api/Cargo.toml index 692c03cd7..3a88431f7 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.1.4" +version = "0.2.1" description = "Wasmer c-api library" license = "MIT" authors = ["The Wasmer Engineering Team "] @@ -9,8 +9,8 @@ edition = "2018" readme = "README.md" [dependencies] -wasmer-runtime = { path = "../runtime", version = "0.1.2" } -wasmer-runtime-core = { path = "../runtime-core", version = "0.1.2" } +wasmer-runtime = { path = "../runtime", version = "0.2.1" } +wasmer-runtime-core = { path = "../runtime-core", version = "0.2.1" } libc = "0.2" [lib] diff --git a/lib/runtime-c-api/src/lib.rs b/lib/runtime-c-api/src/lib.rs index f19380cdb..5512c0287 100644 --- a/lib/runtime-c-api/src/lib.rs +++ b/lib/runtime-c-api/src/lib.rs @@ -13,12 +13,10 @@ use std::{ffi::c_void, ptr}; use wasmer_runtime::{Ctx, Global, ImportObject, Instance, Memory, Module, Table, Value}; use wasmer_runtime_core::export::{Context, Export, FuncPointer}; use wasmer_runtime_core::import::Namespace; +use wasmer_runtime_core::module::{ExportIndex, ImportName}; use wasmer_runtime_core::types::{ElementType, FuncSig, MemoryDescriptor, TableDescriptor, Type}; use wasmer_runtime_core::units::{Bytes, Pages}; -#[allow(non_camel_case_types)] -pub struct wasmer_import_object_t(); - #[allow(non_camel_case_types)] pub struct wasmer_module_t(); @@ -78,7 +76,11 @@ pub struct wasmer_table_t(); #[repr(C)] #[derive(Clone)] -pub struct wasmer_func_t(); +pub struct wasmer_import_func_t(); + +#[repr(C)] +#[derive(Clone)] +pub struct wasmer_export_func_t(); #[repr(C)] #[derive(Clone)] @@ -96,14 +98,6 @@ pub struct wasmer_limit_option_t { pub some: uint32_t, } -#[repr(C)] -pub struct wasmer_func_signature { - pub params: *const wasmer_value_tag, - pub params_len: c_int, - pub returns: *const wasmer_value_tag, - pub returns_len: c_int, -} - #[repr(C)] pub struct wasmer_import_t { module_name: wasmer_byte_array, @@ -112,6 +106,14 @@ pub struct wasmer_import_t { value: wasmer_import_export_value, } +#[repr(C)] +#[derive(Clone)] +pub struct wasmer_import_descriptor_t; + +#[repr(C)] +#[derive(Clone)] +pub struct wasmer_import_descriptors_t; + #[repr(C)] #[derive(Clone)] pub struct wasmer_export_t; @@ -120,6 +122,14 @@ pub struct wasmer_export_t; #[derive(Clone)] pub struct wasmer_exports_t; +#[repr(C)] +#[derive(Clone)] +pub struct wasmer_export_descriptor_t; + +#[repr(C)] +#[derive(Clone)] +pub struct wasmer_export_descriptors_t; + #[repr(u32)] #[derive(Clone)] pub enum wasmer_import_export_kind { @@ -132,7 +142,7 @@ pub enum wasmer_import_export_kind { #[repr(C)] #[derive(Clone, Copy)] pub union wasmer_import_export_value { - func: *const wasmer_func_t, + func: *const wasmer_import_func_t, table: *const wasmer_table_t, memory: *const wasmer_memory_t, global: *const wasmer_global_t, @@ -208,14 +218,13 @@ pub extern "C" fn wasmer_memory_grow( delta: uint32_t, ) -> wasmer_result_t { let memory = unsafe { &*(memory as *mut Memory) }; - let maybe_delta = memory.grow(Pages(delta)); - if let Some(_delta) = maybe_delta { - wasmer_result_t::WASMER_OK - } else { - update_last_error(CApiError { - msg: "unable to grow memory".to_string(), - }); - wasmer_result_t::WASMER_ERROR + let delta_result = memory.grow(Pages(delta)); + match delta_result { + Ok(_) => wasmer_result_t::WASMER_OK, + Err(grow_error) => { + update_last_error(grow_error); + wasmer_result_t::WASMER_ERROR + } } } @@ -277,14 +286,13 @@ pub extern "C" fn wasmer_table_grow( delta: uint32_t, ) -> wasmer_result_t { let table = unsafe { &*(table as *mut Table) }; - let maybe_delta = table.grow(delta); - if let Some(_delta) = maybe_delta { - wasmer_result_t::WASMER_OK - } else { - update_last_error(CApiError { - msg: "unable to grow table".to_string(), - }); - wasmer_result_t::WASMER_ERROR + let delta_result = table.grow(delta); + match delta_result { + Ok(_) => wasmer_result_t::WASMER_OK, + Err(grow_error) => { + update_last_error(grow_error); + wasmer_result_t::WASMER_ERROR + } } } @@ -446,12 +454,24 @@ pub unsafe extern "C" fn wasmer_module_instantiate( .or_insert_with(|| Namespace::new()); let export = match import.tag { - wasmer_import_export_kind::WASM_MEMORY => import.value.memory as *mut Export, - wasmer_import_export_kind::WASM_FUNCTION => import.value.func as *mut Export, - wasmer_import_export_kind::WASM_GLOBAL => import.value.global as *mut Export, - wasmer_import_export_kind::WASM_TABLE => import.value.table as *mut Export, + wasmer_import_export_kind::WASM_MEMORY => { + let mem = import.value.memory as *mut Memory; + Export::Memory((&*mem).clone()) + } + wasmer_import_export_kind::WASM_FUNCTION => { + let func_export = import.value.func as *mut Export; + (&*func_export).clone() + } + wasmer_import_export_kind::WASM_GLOBAL => { + let global = import.value.global as *mut Global; + Export::Global((&*global).clone()) + } + wasmer_import_export_kind::WASM_TABLE => { + let table = import.value.table as *mut Table; + Export::Table((&*table).clone()) + } }; - namespace.insert(import_name, unsafe { (&*export).clone() }); + namespace.insert(import_name, export); } for (module_name, namespace) in namespaces.into_iter() { import_object.register(module_name, namespace); @@ -470,6 +490,91 @@ pub unsafe extern "C" fn wasmer_module_instantiate( wasmer_result_t::WASMER_OK } +/// Gets export descriptors for the given module +/// +/// The caller owns the object and should call `wasmer_export_descriptors_destroy` to free it. +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +pub unsafe extern "C" fn wasmer_export_descriptors( + module: *mut wasmer_module_t, + export_descriptors: *mut *mut wasmer_export_descriptors_t, +) { + let mut module = unsafe { &*(module as *mut Module) }; + + let named_export_descriptors: Box = Box::new(NamedExportDescriptors( + module.info().exports.iter().map(|e| e.into()).collect(), + )); + unsafe { + *export_descriptors = + Box::into_raw(named_export_descriptors) as *mut wasmer_export_descriptors_t + }; +} + +pub struct NamedExportDescriptors(Vec); + +/// Frees the memory for the given export descriptors +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +pub unsafe extern "C" fn wasmer_export_descriptors_destroy( + export_descriptors: *mut wasmer_export_descriptors_t, +) { + if !export_descriptors.is_null() { + drop(unsafe { Box::from_raw(export_descriptors as *mut NamedExportDescriptors) }); + } +} + +/// Gets the length of the export descriptors +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +pub unsafe extern "C" fn wasmer_export_descriptors_len( + exports: *mut wasmer_export_descriptors_t, +) -> c_int { + if exports.is_null() { + return 0; + } + (*(exports as *mut NamedExportDescriptors)).0.len() as c_int +} + +/// Gets export descriptor by index +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +pub unsafe extern "C" fn wasmer_export_descriptors_get( + export_descriptors: *mut wasmer_export_descriptors_t, + idx: c_int, +) -> *mut wasmer_export_descriptor_t { + if export_descriptors.is_null() { + return ptr::null_mut(); + } + let mut named_export_descriptors = + unsafe { &mut *(export_descriptors as *mut NamedExportDescriptors) }; + let ptr = &mut (*named_export_descriptors).0[idx as usize] as *mut NamedExportDescriptor + as *mut wasmer_export_descriptor_t; + ptr +} + +/// Gets name for the export descriptor +#[no_mangle] +#[allow(clippy::cast_ptr_alignment)] +pub unsafe extern "C" fn wasmer_export_descriptor_name( + export_descriptor: *mut wasmer_export_descriptor_t, +) -> wasmer_byte_array { + let named_export_descriptor = &*(export_descriptor as *mut NamedExportDescriptor); + wasmer_byte_array { + bytes: named_export_descriptor.name.as_ptr(), + bytes_len: named_export_descriptor.name.len() as u32, + } +} + +/// Gets export descriptor kind +#[no_mangle] +#[allow(clippy::cast_ptr_alignment)] +pub unsafe extern "C" fn wasmer_export_descriptor_kind( + export: *mut wasmer_export_descriptor_t, +) -> wasmer_import_export_kind { + let named_export_descriptor = &*(export as *mut NamedExportDescriptor); + named_export_descriptor.kind.clone() +} + /// Frees memory for the given Module #[allow(clippy::cast_ptr_alignment)] #[no_mangle] @@ -479,6 +584,185 @@ pub extern "C" fn wasmer_module_destroy(module: *mut wasmer_module_t) { } } +/// Gets import descriptors for the given module +/// +/// The caller owns the object and should call `wasmer_import_descriptors_destroy` to free it. +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +pub unsafe extern "C" fn wasmer_import_descriptors( + module: *mut wasmer_module_t, + import_descriptors: *mut *mut wasmer_import_descriptors_t, +) { + let mut module = unsafe { &*(module as *mut Module) }; + let total_imports = module.info().imported_functions.len() + + module.info().imported_tables.len() + + module.info().imported_globals.len() + + module.info().imported_memories.len(); + let mut descriptors: Vec = Vec::with_capacity(total_imports); + + for ( + index, + ImportName { + namespace_index, + name_index, + }, + ) in &module.info().imported_functions + { + let namespace = module.info().namespace_table.get(*namespace_index); + let name = module.info().name_table.get(*name_index); + descriptors.push(NamedImportDescriptor { + module: namespace.to_string(), + name: name.to_string(), + kind: wasmer_import_export_kind::WASM_FUNCTION, + }); + } + + for ( + index, + ( + ImportName { + namespace_index, + name_index, + }, + _, + ), + ) in &module.info().imported_tables + { + let namespace = module.info().namespace_table.get(*namespace_index); + let name = module.info().name_table.get(*name_index); + descriptors.push(NamedImportDescriptor { + module: namespace.to_string(), + name: name.to_string(), + kind: wasmer_import_export_kind::WASM_TABLE, + }); + } + + for ( + index, + ( + ImportName { + namespace_index, + name_index, + }, + _, + ), + ) in &module.info().imported_globals + { + let namespace = module.info().namespace_table.get(*namespace_index); + let name = module.info().name_table.get(*name_index); + descriptors.push(NamedImportDescriptor { + module: namespace.to_string(), + name: name.to_string(), + kind: wasmer_import_export_kind::WASM_GLOBAL, + }); + } + + for ( + index, + ( + ImportName { + namespace_index, + name_index, + }, + _, + ), + ) in &module.info().imported_memories + { + let namespace = module.info().namespace_table.get(*namespace_index); + let name = module.info().name_table.get(*name_index); + descriptors.push(NamedImportDescriptor { + module: namespace.to_string(), + name: name.to_string(), + kind: wasmer_import_export_kind::WASM_MEMORY, + }); + } + + let named_import_descriptors: Box = + Box::new(NamedImportDescriptors(descriptors)); + unsafe { + *import_descriptors = + Box::into_raw(named_import_descriptors) as *mut wasmer_import_descriptors_t + }; +} + +pub struct NamedImportDescriptors(Vec); + +/// Frees the memory for the given import descriptors +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +pub unsafe extern "C" fn wasmer_import_descriptors_destroy( + import_descriptors: *mut wasmer_import_descriptors_t, +) { + if !import_descriptors.is_null() { + drop(unsafe { Box::from_raw(import_descriptors as *mut NamedImportDescriptors) }); + } +} + +/// Gets the length of the import descriptors +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +pub unsafe extern "C" fn wasmer_import_descriptors_len( + exports: *mut wasmer_import_descriptors_t, +) -> c_int { + if exports.is_null() { + return 0; + } + (*(exports as *mut NamedImportDescriptors)).0.len() as c_int +} + +/// Gets import descriptor by index +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +pub unsafe extern "C" fn wasmer_import_descriptors_get( + import_descriptors: *mut wasmer_import_descriptors_t, + idx: c_int, +) -> *mut wasmer_import_descriptor_t { + if import_descriptors.is_null() { + return ptr::null_mut(); + } + let mut named_import_descriptors = + unsafe { &mut *(import_descriptors as *mut NamedImportDescriptors) }; + let ptr = &mut (*named_import_descriptors).0[idx as usize] as *mut NamedImportDescriptor + as *mut wasmer_import_descriptor_t; + ptr +} + +/// Gets name for the import descriptor +#[no_mangle] +#[allow(clippy::cast_ptr_alignment)] +pub unsafe extern "C" fn wasmer_import_descriptor_name( + import_descriptor: *mut wasmer_import_descriptor_t, +) -> wasmer_byte_array { + let named_import_descriptor = &*(import_descriptor as *mut NamedImportDescriptor); + wasmer_byte_array { + bytes: named_import_descriptor.name.as_ptr(), + bytes_len: named_import_descriptor.name.len() as u32, + } +} + +/// Gets module name for the import descriptor +#[no_mangle] +#[allow(clippy::cast_ptr_alignment)] +pub unsafe extern "C" fn wasmer_import_descriptor_module_name( + import_descriptor: *mut wasmer_import_descriptor_t, +) -> wasmer_byte_array { + let named_import_descriptor = &*(import_descriptor as *mut NamedImportDescriptor); + wasmer_byte_array { + bytes: named_import_descriptor.module.as_ptr(), + bytes_len: named_import_descriptor.module.len() as u32, + } +} + +/// Gets export descriptor kind +#[no_mangle] +#[allow(clippy::cast_ptr_alignment)] +pub unsafe extern "C" fn wasmer_import_descriptor_kind( + export: *mut wasmer_import_descriptor_t, +) -> wasmer_import_export_kind { + let named_import_descriptor = &*(export as *mut NamedImportDescriptor); + named_import_descriptor.kind.clone() +} + /// Creates a new Instance from the given wasm bytes and imports. /// /// Returns `wasmer_result_t::WASMER_OK` upon success. @@ -534,12 +818,24 @@ pub unsafe extern "C" fn wasmer_instantiate( .or_insert_with(|| Namespace::new()); let export = match import.tag { - wasmer_import_export_kind::WASM_MEMORY => import.value.memory as *mut Export, - wasmer_import_export_kind::WASM_FUNCTION => import.value.func as *mut Export, - wasmer_import_export_kind::WASM_GLOBAL => import.value.global as *mut Export, - wasmer_import_export_kind::WASM_TABLE => import.value.table as *mut Export, + wasmer_import_export_kind::WASM_MEMORY => { + let mem = import.value.memory as *mut Memory; + Export::Memory((&*mem).clone()) + } + wasmer_import_export_kind::WASM_FUNCTION => { + let func_export = import.value.func as *mut Export; + (&*func_export).clone() + } + wasmer_import_export_kind::WASM_GLOBAL => { + let global = import.value.global as *mut Global; + Export::Global((&*global).clone()) + } + wasmer_import_export_kind::WASM_TABLE => { + let table = import.value.table as *mut Table; + Export::Table((&*table).clone()) + } }; - namespace.insert(import_name, unsafe { (&*export).clone() }); + namespace.insert(import_name, unsafe { export }); } for (module_name, namespace) in namespaces.into_iter() { import_object.register(module_name, namespace); @@ -649,9 +945,16 @@ pub unsafe extern "C" fn wasmer_instance_exports( instance: *mut wasmer_instance_t, exports: *mut *mut wasmer_exports_t, ) { - let mut instance = unsafe { &mut *(instance as *mut Instance) }; - let named_exports: Box = - Box::new(NamedExports(instance.exports().map(|e| e.into()).collect())); + let mut instance_ref = unsafe { &mut *(instance as *mut Instance) }; + let mut exports_vec: Vec = Vec::with_capacity(instance_ref.exports().count()); + for (name, export) in instance_ref.exports() { + exports_vec.push(NamedExport { + name: name.clone(), + export: export.clone(), + instance: instance as *mut Instance, + }); + } + let named_exports: Box = Box::new(NamedExports(exports_vec)); unsafe { *exports = Box::into_raw(named_exports) as *mut wasmer_exports_t }; } @@ -706,18 +1009,157 @@ pub unsafe extern "C" fn wasmer_export_kind( } } -/// Creates new func +/// Sets the result parameter to the arity of the params of the wasmer_export_func_t /// -/// The caller owns the object and should call `wasmer_func_destroy` to free it. +/// Returns `wasmer_result_t::WASMER_OK` upon success. +/// +/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` +/// and `wasmer_last_error_message` to get an error message. #[no_mangle] #[allow(clippy::cast_ptr_alignment)] -pub unsafe extern "C" fn wasmer_func_new( +pub unsafe extern "C" fn wasmer_export_func_params_arity( + func: *mut wasmer_export_func_t, + result: *mut uint32_t, +) -> wasmer_result_t { + let mut named_export = unsafe { &*(func as *mut NamedExport) }; + let mut export = &named_export.export; + let result = if let Export::Function { ref signature, .. } = *export { + unsafe { *result = signature.params().len() as uint32_t }; + wasmer_result_t::WASMER_OK + } else { + update_last_error(CApiError { + msg: "func ptr error in wasmer_export_func_params_arity".to_string(), + }); + wasmer_result_t::WASMER_ERROR + }; + result +} + +/// Sets the params buffer to the parameter types of the given wasmer_export_func_t +/// +/// Returns `wasmer_result_t::WASMER_OK` upon success. +/// +/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` +/// and `wasmer_last_error_message` to get an error message. +#[no_mangle] +#[allow(clippy::cast_ptr_alignment)] +pub unsafe extern "C" fn wasmer_export_func_params( + func: *mut wasmer_export_func_t, + params: *mut wasmer_value_tag, + params_len: c_int, +) -> wasmer_result_t { + let mut named_export = unsafe { &*(func as *mut NamedExport) }; + let mut export = &named_export.export; + let result = if let Export::Function { ref signature, .. } = *export { + let params: &mut [wasmer_value_tag] = + slice::from_raw_parts_mut(params, params_len as usize); + for (i, item) in signature.params().iter().enumerate() { + params[i] = item.into(); + } + wasmer_result_t::WASMER_OK + } else { + update_last_error(CApiError { + msg: "func ptr error in wasmer_export_func_params".to_string(), + }); + wasmer_result_t::WASMER_ERROR + }; + result +} + +/// Sets the returns buffer to the parameter types of the given wasmer_export_func_t +/// +/// Returns `wasmer_result_t::WASMER_OK` upon success. +/// +/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` +/// and `wasmer_last_error_message` to get an error message. +#[no_mangle] +#[allow(clippy::cast_ptr_alignment)] +pub unsafe extern "C" fn wasmer_export_func_returns( + func: *mut wasmer_export_func_t, + returns: *mut wasmer_value_tag, + returns_len: c_int, +) -> wasmer_result_t { + let mut named_export = unsafe { &*(func as *mut NamedExport) }; + let mut export = &named_export.export; + let result = if let Export::Function { ref signature, .. } = *export { + let returns: &mut [wasmer_value_tag] = + slice::from_raw_parts_mut(returns, returns_len as usize); + for (i, item) in signature.returns().iter().enumerate() { + returns[i] = item.into(); + } + wasmer_result_t::WASMER_OK + } else { + update_last_error(CApiError { + msg: "func ptr error in wasmer_export_func_returns".to_string(), + }); + wasmer_result_t::WASMER_ERROR + }; + result +} + +/// Sets the result parameter to the arity of the returns of the wasmer_export_func_t +/// +/// Returns `wasmer_result_t::WASMER_OK` upon success. +/// +/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` +/// and `wasmer_last_error_message` to get an error message. +#[no_mangle] +#[allow(clippy::cast_ptr_alignment)] +pub unsafe extern "C" fn wasmer_export_func_returns_arity( + func: *mut wasmer_export_func_t, + result: *mut uint32_t, +) -> wasmer_result_t { + let mut named_export = unsafe { &*(func as *mut NamedExport) }; + let mut export = &named_export.export; + let result = if let Export::Function { ref signature, .. } = *export { + unsafe { *result = signature.returns().len() as uint32_t }; + wasmer_result_t::WASMER_OK + } else { + update_last_error(CApiError { + msg: "func ptr error in wasmer_export_func_results_arity".to_string(), + }); + wasmer_result_t::WASMER_ERROR + }; + result +} + +/// Sets the result parameter to the arity of the params of the wasmer_import_func_t +/// +/// Returns `wasmer_result_t::WASMER_OK` upon success. +/// +/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` +/// and `wasmer_last_error_message` to get an error message. +#[no_mangle] +#[allow(clippy::cast_ptr_alignment)] +pub unsafe extern "C" fn wasmer_import_func_params_arity( + func: *mut wasmer_import_func_t, + result: *mut uint32_t, +) -> wasmer_result_t { + let mut export = unsafe { &mut *(func as *mut Export) }; + let result = if let Export::Function { ref signature, .. } = *export { + unsafe { *result = signature.params().len() as uint32_t }; + wasmer_result_t::WASMER_OK + } else { + update_last_error(CApiError { + msg: "func ptr error in wasmer_import_func_params_arity".to_string(), + }); + wasmer_result_t::WASMER_ERROR + }; + result +} + +/// Creates new func +/// +/// The caller owns the object and should call `wasmer_import_func_destroy` to free it. +#[no_mangle] +#[allow(clippy::cast_ptr_alignment)] +pub unsafe extern "C" fn wasmer_import_func_new( func: extern "C" fn(data: *mut c_void), params: *const wasmer_value_tag, params_len: c_int, returns: *const wasmer_value_tag, returns_len: c_int, -) -> *const wasmer_func_t { +) -> *const wasmer_import_func_t { let params: &[wasmer_value_tag] = slice::from_raw_parts(params, params_len as usize); let params: Vec = params.iter().cloned().map(|x| x.into()).collect(); let returns: &[wasmer_value_tag] = slice::from_raw_parts(returns, returns_len as usize); @@ -728,10 +1170,10 @@ pub unsafe extern "C" fn wasmer_func_new( ctx: Context::Internal, signature: Arc::new(FuncSig::new(params, returns)), }); - Box::into_raw(export) as *mut wasmer_func_t + Box::into_raw(export) as *mut wasmer_import_func_t } -/// Sets the result parameter to the arity of the params of the wasmer_func_t +/// Sets the params buffer to the parameter types of the given wasmer_import_func_t /// /// Returns `wasmer_result_t::WASMER_OK` upon success. /// @@ -739,33 +1181,8 @@ pub unsafe extern "C" fn wasmer_func_new( /// and `wasmer_last_error_message` to get an error message. #[no_mangle] #[allow(clippy::cast_ptr_alignment)] -pub unsafe extern "C" fn wasmer_func_params_arity( - func: *mut wasmer_func_t, - result: *mut uint32_t, -) -> wasmer_result_t { - let mut export = unsafe { &mut *(func as *mut Export) }; - let result = if let Export::Function { ref signature, .. } = *export { - unsafe { *result = signature.params().len() as uint32_t }; - wasmer_result_t::WASMER_OK - } else { - update_last_error(CApiError { - msg: "func ptr error in wasmer_func_params_arity".to_string(), - }); - wasmer_result_t::WASMER_ERROR - }; - result -} - -/// Sets the params buffer to the parameter types of the given wasmer_func_t -/// -/// Returns `wasmer_result_t::WASMER_OK` upon success. -/// -/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` -/// and `wasmer_last_error_message` to get an error message. -#[no_mangle] -#[allow(clippy::cast_ptr_alignment)] -pub unsafe extern "C" fn wasmer_func_params( - func: *mut wasmer_func_t, +pub unsafe extern "C" fn wasmer_import_func_params( + func: *mut wasmer_import_func_t, params: *mut wasmer_value_tag, params_len: c_int, ) -> wasmer_result_t { @@ -779,14 +1196,14 @@ pub unsafe extern "C" fn wasmer_func_params( wasmer_result_t::WASMER_OK } else { update_last_error(CApiError { - msg: "func ptr error in wasmer_func_params".to_string(), + msg: "func ptr error in wasmer_import_func_params".to_string(), }); wasmer_result_t::WASMER_ERROR }; result } -/// Sets the returns buffer to the parameter types of the given wasmer_func_t +/// Sets the returns buffer to the parameter types of the given wasmer_import_func_t /// /// Returns `wasmer_result_t::WASMER_OK` upon success. /// @@ -794,8 +1211,8 @@ pub unsafe extern "C" fn wasmer_func_params( /// and `wasmer_last_error_message` to get an error message. #[no_mangle] #[allow(clippy::cast_ptr_alignment)] -pub unsafe extern "C" fn wasmer_func_returns( - func: *mut wasmer_func_t, +pub unsafe extern "C" fn wasmer_import_func_returns( + func: *mut wasmer_import_func_t, returns: *mut wasmer_value_tag, returns_len: c_int, ) -> wasmer_result_t { @@ -809,14 +1226,14 @@ pub unsafe extern "C" fn wasmer_func_returns( wasmer_result_t::WASMER_OK } else { update_last_error(CApiError { - msg: "func ptr error in wasmer_func_returns".to_string(), + msg: "func ptr error in wasmer_import_func_returns".to_string(), }); wasmer_result_t::WASMER_ERROR }; result } -/// Sets the result parameter to the arity of the returns of the wasmer_func_t +/// Sets the result parameter to the arity of the returns of the wasmer_import_func_t /// /// Returns `wasmer_result_t::WASMER_OK` upon success. /// @@ -824,8 +1241,8 @@ pub unsafe extern "C" fn wasmer_func_returns( /// and `wasmer_last_error_message` to get an error message. #[no_mangle] #[allow(clippy::cast_ptr_alignment)] -pub unsafe extern "C" fn wasmer_func_returns_arity( - func: *mut wasmer_func_t, +pub unsafe extern "C" fn wasmer_import_func_returns_arity( + func: *mut wasmer_import_func_t, result: *mut uint32_t, ) -> wasmer_result_t { let mut export = unsafe { &*(func as *mut Export) }; @@ -834,7 +1251,7 @@ pub unsafe extern "C" fn wasmer_func_returns_arity( wasmer_result_t::WASMER_OK } else { update_last_error(CApiError { - msg: "func ptr error in wasmer_func_results_arity".to_string(), + msg: "func ptr error in wasmer_import_func_results_arity".to_string(), }); wasmer_result_t::WASMER_ERROR }; @@ -844,20 +1261,19 @@ pub unsafe extern "C" fn wasmer_func_returns_arity( /// Frees memory for the given Func #[allow(clippy::cast_ptr_alignment)] #[no_mangle] -pub extern "C" fn wasmer_func_destroy(func: *mut wasmer_func_t) { +pub extern "C" fn wasmer_import_func_destroy(func: *mut wasmer_import_func_t) { if !func.is_null() { drop(unsafe { Box::from_raw(func as *mut Export) }); } } -/// Gets func from wasm_export +/// Gets export func from export #[no_mangle] #[allow(clippy::cast_ptr_alignment)] pub unsafe extern "C" fn wasmer_export_to_func( export: *mut wasmer_export_t, -) -> *const wasmer_func_t { - let named_export = &*(export as *mut NamedExport); - &named_export.export as *const Export as *const wasmer_func_t +) -> *const wasmer_export_func_t { + export as *const wasmer_export_func_t } /// Gets name from wasmer_export @@ -880,8 +1296,8 @@ pub unsafe extern "C" fn wasmer_export_name(export: *mut wasmer_export_t) -> was /// and `wasmer_last_error_message` to get an error message. #[allow(clippy::cast_ptr_alignment)] #[no_mangle] -pub unsafe extern "C" fn wasmer_func_call( - func: *mut wasmer_func_t, +pub unsafe extern "C" fn wasmer_export_func_call( + func: *mut wasmer_export_func_t, params: *const wasmer_value_t, params_len: c_int, results: *mut wasmer_value_t, @@ -903,46 +1319,42 @@ pub unsafe extern "C" fn wasmer_func_call( let params: &[wasmer_value_t] = slice::from_raw_parts(params, params_len as usize); let params: Vec = params.iter().cloned().map(|x| x.into()).collect(); - let export_func = unsafe { &*(func as *mut Export) }; + let named_export = unsafe { &*(func as *mut NamedExport) }; let results: &mut [wasmer_value_t] = slice::from_raw_parts_mut(results, results_len as usize); - // TODO implement func.call - update_last_error(CApiError { - msg: "wasmer_func_call not yet implemented".to_string(), - }); - wasmer_result_t::WASMER_ERROR - // let result = instance.call(func_name_r, ¶ms[..]); - // Box::into_raw(export_func); - // match result { - // Ok(results_vec) => { - // if results_vec.len() > 0 { - // let ret = match results_vec[0] { - // Value::I32(x) => wasmer_value_t { - // tag: wasmer_value_tag::WASM_I32, - // value: wasmer_value { I32: x }, - // }, - // Value::I64(x) => wasmer_value_t { - // tag: wasmer_value_tag::WASM_I64, - // value: wasmer_value { I64: x }, - // }, - // Value::F32(x) => wasmer_value_t { - // tag: wasmer_value_tag::WASM_F32, - // value: wasmer_value { F32: x }, - // }, - // Value::F64(x) => wasmer_value_t { - // tag: wasmer_value_tag::WASM_F64, - // value: wasmer_value { F64: x }, - // }, - // }; - // results[0] = ret; - // } - // wasmer_result_t::WASMER_OK - // } - // Err(err) => { - // update_last_error(err); - // wasmer_result_t::WASMER_ERROR - // } - // } + + let instance = &*named_export.instance; + let result = instance.call(&named_export.name, ¶ms[..]); + match result { + Ok(results_vec) => { + if results_vec.len() > 0 { + let ret = match results_vec[0] { + Value::I32(x) => wasmer_value_t { + tag: wasmer_value_tag::WASM_I32, + value: wasmer_value { I32: x }, + }, + Value::I64(x) => wasmer_value_t { + tag: wasmer_value_tag::WASM_I64, + value: wasmer_value { I64: x }, + }, + Value::F32(x) => wasmer_value_t { + tag: wasmer_value_tag::WASM_F32, + value: wasmer_value { F32: x }, + }, + Value::F64(x) => wasmer_value_t { + tag: wasmer_value_tag::WASM_F64, + value: wasmer_value { F64: x }, + }, + }; + results[0] = ret; + } + wasmer_result_t::WASMER_OK + } + Err(err) => { + update_last_error(err); + wasmer_result_t::WASMER_ERROR + } + } } /// Gets the memory within the context at the index `memory_idx`. @@ -1060,12 +1472,6 @@ impl From for Type { } } -impl From<(std::string::String, wasmer_runtime_core::export::Export)> for NamedExport { - fn from((name, export): (String, Export)) -> Self { - NamedExport { name, export } - } -} - impl From<&wasmer_runtime::wasm::Type> for wasmer_value_tag { fn from(ty: &Type) -> Self { match *ty { @@ -1077,6 +1483,21 @@ impl From<&wasmer_runtime::wasm::Type> for wasmer_value_tag { } } +impl From<(&std::string::String, &ExportIndex)> for NamedExportDescriptor { + fn from((name, export_index): (&String, &ExportIndex)) -> Self { + let kind = match *export_index { + ExportIndex::Memory(_) => wasmer_import_export_kind::WASM_MEMORY, + ExportIndex::Global(_) => wasmer_import_export_kind::WASM_GLOBAL, + ExportIndex::Table(_) => wasmer_import_export_kind::WASM_TABLE, + ExportIndex::Func(_) => wasmer_import_export_kind::WASM_FUNCTION, + }; + NamedExportDescriptor { + name: name.clone(), + kind, + } + } +} + // Error reporting thread_local! { @@ -1171,7 +1592,19 @@ impl fmt::Display for CApiError { impl Error for CApiError {} +struct NamedImportDescriptor { + module: String, + name: String, + kind: wasmer_import_export_kind, +} + struct NamedExport { name: String, export: Export, + instance: *mut Instance, +} + +struct NamedExportDescriptor { + name: String, + kind: wasmer_import_export_kind, } diff --git a/lib/runtime-c-api/tests/.gitignore b/lib/runtime-c-api/tests/.gitignore index 6ea57c28d..15e33d2cf 100644 --- a/lib/runtime-c-api/tests/.gitignore +++ b/lib/runtime-c-api/tests/.gitignore @@ -12,9 +12,12 @@ _deps test-globals test-exports test-instantiate +test-imports test-import-function test-memory +test-module-imports test-module +test-module-exports test-tables test-validate rust-build \ No newline at end of file diff --git a/lib/runtime-c-api/tests/CMakeLists.txt b/lib/runtime-c-api/tests/CMakeLists.txt index 788ee1c6a..6f899b5b5 100644 --- a/lib/runtime-c-api/tests/CMakeLists.txt +++ b/lib/runtime-c-api/tests/CMakeLists.txt @@ -1,12 +1,15 @@ cmake_minimum_required (VERSION 2.6) project (WasmerCApiTests) +add_executable(test-imports test-imports.c) add_executable(test-exports test-exports.c) add_executable(test-globals test-globals.c) add_executable(test-instantiate test-instantiate.c) add_executable(test-import-function test-import-function.c) add_executable(test-memory test-memory.c) +add_executable(test-module-imports test-module-imports.c) add_executable(test-module test-module.c) +add_executable(test-module-exports test-module-exports.c) add_executable(test-validate test-validate.c) add_executable(test-tables test-tables.c) @@ -19,6 +22,8 @@ if(NOT WASMER_LIB) message(FATAL_ERROR "wasmer library not found") endif() +target_link_libraries(test-imports + general ${WASMER_LIB}) target_link_libraries(test-exports general ${WASMER_LIB}) target_link_libraries(test-globals @@ -29,20 +34,27 @@ target_link_libraries(test-import-function general ${WASMER_LIB}) target_link_libraries(test-memory general ${WASMER_LIB}) +target_link_libraries(test-module-imports + general ${WASMER_LIB}) target_link_libraries(test-module general ${WASMER_LIB}) +target_link_libraries(test-module-exports + general ${WASMER_LIB}) target_link_libraries(test-validate general ${WASMER_LIB}) target_link_libraries(test-tables general ${WASMER_LIB}) enable_testing() +add_test(test-imports test-imports) add_test(test-exports test-exports) add_test(test-globals test-globals) add_test(test-instantiate test-instantiate) add_test(test-import-function test-import-function) add_test(test-memory test-memory) +add_test(test-module-imports test-module-imports) add_test(test-module test-module) +add_test(test-module-exports test-module-exports) add_test(test-validate test-validate) add_test(test-tables test-tables) diff --git a/lib/runtime-c-api/tests/hello_wasm.wasm b/lib/runtime-c-api/tests/hello_wasm.wasm new file mode 100644 index 000000000..b2287be03 Binary files /dev/null and b/lib/runtime-c-api/tests/hello_wasm.wasm differ diff --git a/lib/runtime-c-api/tests/test-exports.c b/lib/runtime-c-api/tests/test-exports.c index 3f458ebab..75368ad16 100644 --- a/lib/runtime-c-api/tests/test-exports.c +++ b/lib/runtime-c-api/tests/test-exports.c @@ -31,7 +31,7 @@ int main() wasmer_import_export_kind kind = wasmer_export_kind(export); assert(kind == WASM_FUNCTION); - wasmer_func_t *func = wasmer_export_to_func(export); + wasmer_export_func_t *func = wasmer_export_to_func(export); wasmer_byte_array name_bytes = wasmer_export_name(export); assert(name_bytes.bytes_len == 3); @@ -42,40 +42,40 @@ int main() } uint32_t params_arity; - wasmer_func_params_arity(func, ¶ms_arity); + wasmer_export_func_params_arity(func, ¶ms_arity); assert(params_arity == 2); wasmer_value_tag *params_sig = malloc(sizeof(wasmer_value_tag) * params_arity); - wasmer_func_params(func, params_sig , params_arity); + wasmer_export_func_params(func, params_sig , params_arity); assert(params_sig[0] == WASM_I32); assert(params_sig[1] == WASM_I32); free(params_sig); uint32_t returns_arity; - wasmer_func_returns_arity(func, &returns_arity); + wasmer_export_func_returns_arity(func, &returns_arity); assert(returns_arity == 1); wasmer_value_tag *returns_sig = malloc(sizeof(wasmer_value_tag) * returns_arity); - wasmer_func_returns(func, returns_sig , returns_arity); + wasmer_export_func_returns(func, returns_sig , returns_arity); assert(returns_sig[0] == WASM_I32); free(returns_sig); -// wasmer_value_t param_one; -// param_one.tag = WASM_I32; -// param_one.value.I32 = 7; -// wasmer_value_t param_two; -// param_two.tag = WASM_I32; -// param_two.value.I32 = 8; -// wasmer_value_t params[] = {param_one, param_two}; -// wasmer_value_t result_one; -// wasmer_value_t results[] = {result_one}; -// -// wasmer_result_t call_result = wasmer_func_call(func, params, 2, results, 1); -// printf("Call result: %d\n", call_result); -// printf("Result: %d\n", results[0].value.I32); -// assert(results[0].value.I32 == 15); -// assert(call_result == WASMER_OK); + wasmer_value_t param_one; + param_one.tag = WASM_I32; + param_one.value.I32 = 7; + wasmer_value_t param_two; + param_two.tag = WASM_I32; + param_two.value.I32 = 8; + wasmer_value_t params[] = {param_one, param_two}; + wasmer_value_t result_one; + wasmer_value_t results[] = {result_one}; + + wasmer_result_t call_result = wasmer_export_func_call(func, params, 2, results, 1); + printf("Call result: %d\n", call_result); + printf("Result: %d\n", results[0].value.I32); + assert(results[0].value.I32 == 15); + assert(call_result == WASMER_OK); printf("Destroy instance\n"); diff --git a/lib/runtime-c-api/tests/test-import-function.c b/lib/runtime-c-api/tests/test-import-function.c index e7caed874..b28465683 100644 --- a/lib/runtime-c-api/tests/test-import-function.c +++ b/lib/runtime-c-api/tests/test-import-function.c @@ -31,7 +31,7 @@ int main() wasmer_value_tag returns_sig[] = {}; printf("Creating new func\n"); - wasmer_func_t *func = wasmer_func_new(print_str, params_sig, 2, returns_sig, 0); + wasmer_import_func_t *func = wasmer_import_func_new(print_str, params_sig, 2, returns_sig, 0); wasmer_import_t import; char *module_name = "env"; @@ -84,7 +84,7 @@ int main() assert(0 == strcmp(actual_str, "Hello, World!")); printf("Destroying func\n"); - wasmer_func_destroy(func); + wasmer_import_func_destroy(func); printf("Destroy instance\n"); wasmer_instance_destroy(instance); return 0; diff --git a/lib/runtime-c-api/tests/test-imports.c b/lib/runtime-c-api/tests/test-imports.c new file mode 100644 index 000000000..4410c4dd6 --- /dev/null +++ b/lib/runtime-c-api/tests/test-imports.c @@ -0,0 +1,154 @@ +#include +#include "../wasmer.h" +#include +#include + +static print_str_called = false; + +// Host function that will be imported into the Web Assembly Instance +void print_str(wasmer_instance_context_t *ctx, int32_t ptr, int32_t len) +{ + print_str_called = true; + wasmer_memory_t *memory = wasmer_instance_context_memory(ctx, 0); + uint32_t mem_len = wasmer_memory_length(memory); + uint8_t *mem_bytes = wasmer_memory_data(memory); + printf("%.*s", len, mem_bytes + ptr); +} + +// Use the last_error API to retrieve error messages +void print_wasmer_error() +{ + int error_len = wasmer_last_error_length(); + printf("Error len: `%d`\n", error_len); + char *error_str = malloc(error_len); + wasmer_last_error_message(error_str, error_len); + printf("Error str: `%s`\n", error_str); +} + +int main() +{ + // Create a new func to hold the parameter and signature + // of our `print_str` host function + wasmer_value_tag params_sig[] = {WASM_I32, WASM_I32}; + wasmer_value_tag returns_sig[] = {}; + wasmer_import_func_t *func = wasmer_import_func_new(print_str, params_sig, 2, returns_sig, 0); + + // Create module name for our imports + // represented in bytes for UTF-8 compatability + char *module_name = "env"; + wasmer_byte_array module_name_bytes; + module_name_bytes.bytes = module_name; + module_name_bytes.bytes_len = strlen(module_name); + + // Define a function import + char *import_name = "_print_str"; + wasmer_byte_array import_name_bytes; + import_name_bytes.bytes = import_name; + import_name_bytes.bytes_len = strlen(import_name); + wasmer_import_t func_import; + func_import.module_name = module_name_bytes; + func_import.import_name = import_name_bytes; + func_import.tag = WASM_FUNCTION; + func_import.value.func = func; + + // Define a memory import + char *import_memory_name = "memory"; + wasmer_byte_array import_memory_name_bytes; + import_memory_name_bytes.bytes = import_memory_name; + import_memory_name_bytes.bytes_len = strlen(import_memory_name); + wasmer_import_t memory_import; + memory_import.module_name = module_name_bytes; + memory_import.import_name = import_memory_name_bytes; + memory_import.tag = WASM_MEMORY; + wasmer_memory_t *memory = NULL; + wasmer_limits_t descriptor; + descriptor.min = 256; + wasmer_limit_option_t max; + max.has_some = true; + max.some = 256; + descriptor.max = max; + wasmer_result_t memory_result = wasmer_memory_new(&memory, descriptor); + if (memory_result != WASMER_OK) + { + print_wasmer_error(); + } + memory_import.value.memory = memory; + + // Define a global import + char *import_global_name = "__memory_base"; + wasmer_byte_array import_global_name_bytes; + import_global_name_bytes.bytes = import_global_name; + import_global_name_bytes.bytes_len = strlen(import_global_name); + wasmer_import_t global_import; + global_import.module_name = module_name_bytes; + global_import.import_name = import_global_name_bytes; + global_import.tag = WASM_GLOBAL; + wasmer_value_t val; + val.tag = WASM_I32; + val.value.I32 = 1024; + wasmer_global_t *global = wasmer_global_new(val, false); + global_import.value.global = global; + + // Define a table import + char *import_table_name = "table"; + wasmer_byte_array import_table_name_bytes; + import_table_name_bytes.bytes = import_table_name; + import_table_name_bytes.bytes_len = strlen(import_table_name); + wasmer_import_t table_import; + table_import.module_name = module_name_bytes; + table_import.import_name = import_table_name_bytes; + table_import.tag = WASM_TABLE; + wasmer_table_t *table = NULL; + wasmer_limits_t table_descriptor; + table_descriptor.min = 256; + wasmer_limit_option_t table_max; + table_max.has_some = true; + table_max.some = 256; + table_descriptor.max = table_max; + wasmer_result_t table_result = wasmer_table_new(&table, table_descriptor); + if (table_result != WASMER_OK) + { + print_wasmer_error(); + } + table_import.value.table = table; + + // Define an array containing our imports + wasmer_import_t imports[] = {func_import, global_import, memory_import, table_import}; + + // Read the wasm file bytes + FILE *file = fopen("hello_wasm.wasm", "r"); + fseek(file, 0, SEEK_END); + long len = ftell(file); + uint8_t *bytes = malloc(len); + fseek(file, 0, SEEK_SET); + fread(bytes, 1, len, file); + fclose(file); + + // Creates a WebAssembly Instance from wasm bytes and imports + wasmer_instance_t *instance = NULL; + wasmer_result_t compile_result = wasmer_instantiate(&instance, bytes, len, imports, 3); + printf("Compile result: %d\n", compile_result); + if (compile_result != WASMER_OK) + { + print_wasmer_error(); + } + assert(compile_result == WASMER_OK); + + // Call the exported "hello_wasm" function of our instance + wasmer_value_t params[] = {}; + wasmer_value_t result_one; + wasmer_value_t results[] = {result_one}; + wasmer_result_t call_result = wasmer_instance_call(instance, "_hello_wasm", params, 0, results, 1); + printf("Call result: %d\n", call_result); + assert(call_result == WASMER_OK); + assert(print_str_called); + + // Use *_destroy methods to cleanup as specified in the header documentation + wasmer_import_func_destroy(func); + wasmer_global_destroy(global); + wasmer_memory_destroy(memory); + wasmer_table_destroy(table); + wasmer_instance_destroy(instance); + + return 0; +} diff --git a/lib/runtime-c-api/tests/test-memory.c b/lib/runtime-c-api/tests/test-memory.c index 63913c73b..64e028693 100644 --- a/lib/runtime-c-api/tests/test-memory.c +++ b/lib/runtime-c-api/tests/test-memory.c @@ -23,13 +23,13 @@ int main() wasmer_result_t grow_result = wasmer_memory_grow(memory, 2); assert(grow_result == WASMER_OK); - uint32_t new_len = wasmer_memory_length(memory); + uint32_t new_len = wasmer_memory_length(memory); printf("Memory pages length: %d\n", new_len); assert(new_len == 12); - uint32_t bytes_len = wasmer_memory_data_length(memory); + uint32_t bytes_len = wasmer_memory_data_length(memory); printf("Memory bytes length: %d\n", bytes_len); - assert(bytes_len == 12 * 65536); + assert(bytes_len == 12 * 65536); // Err, grow beyond max wasmer_result_t grow_result2 = wasmer_memory_grow(memory, 10); @@ -38,23 +38,26 @@ int main() char *error_str = malloc(error_len); wasmer_last_error_message(error_str, error_len); printf("Error str: `%s`\n", error_str); - assert(0 == strcmp(error_str, "unable to grow memory")); + assert(0 == strcmp(error_str, "Failed to add pages because would exceed maximum number of pages for the memory. Left: 22, Added: 15")); free(error_str); + wasmer_memory_t *bad_memory = NULL; + wasmer_limits_t bad_descriptor; + bad_descriptor.min = 15; + wasmer_limit_option_t max2; + max2.has_some = true; + max2.some = 10; + bad_descriptor.max = max2; + wasmer_result_t bad_memory_result = wasmer_memory_new(&bad_memory, bad_descriptor); + printf("Bad memory result: %d\n", bad_memory_result); + assert(bad_memory_result == WASMER_ERROR); -// wasmer_memory_t *bad_memory = NULL; -// wasmer_limits_t bad_descriptor; -// bad_descriptor.min = 15; -// bad_descriptor.max = 10; -// wasmer_result_t bad_memory_result = wasmer_memory_new(&bad_memory, bad_descriptor); -// printf("Bad memory result: %d\n", bad_memory_result); -// assert(memory_result == WASMER_MEMORY_ERROR); -// -// int error_len = wasmer_last_error_length(); -// char *error_str = malloc(error_len); -// wasmer_last_error_message(error_str, error_len); -// assert(0 == strcmp(error_str, "Creation error")); -// free(error_str); + int error_len2 = wasmer_last_error_length(); + char *error_str2 = malloc(error_len2); + wasmer_last_error_message(error_str2, error_len2); + printf("Error str 2: `%s`\n", error_str2); + assert(0 == strcmp(error_str2, "Unable to create because the supplied descriptor is invalid: \"Max number of memory pages is less than the minimum number of pages\"")); + free(error_str2); printf("Destroy memory\n"); wasmer_memory_destroy(memory); diff --git a/lib/runtime-c-api/tests/test-module-exports.c b/lib/runtime-c-api/tests/test-module-exports.c new file mode 100644 index 000000000..48fe6f25b --- /dev/null +++ b/lib/runtime-c-api/tests/test-module-exports.c @@ -0,0 +1,53 @@ +#include +#include "../wasmer.h" +#include +#include + +int main() +{ + // Read the wasm file bytes + FILE *file = fopen("sum.wasm", "r"); + fseek(file, 0, SEEK_END); + long len = ftell(file); + uint8_t *bytes = malloc(len); + fseek(file, 0, SEEK_SET); + fread(bytes, 1, len, file); + fclose(file); + + wasmer_module_t *module = NULL; + wasmer_result_t compile_result = wasmer_compile(&module, bytes, len); + printf("Compile result: %d\n", compile_result); + assert(compile_result == WASMER_OK); + + wasmer_import_t imports[] = {}; + wasmer_instance_t *instance = NULL; + wasmer_result_t instantiate_result = wasmer_module_instantiate(module, &instance, imports, 0); + printf("Instantiate result: %d\n", compile_result); + assert(instantiate_result == WASMER_OK); + + wasmer_export_descriptors_t *exports = NULL; + wasmer_export_descriptors(module, &exports); + + int exports_len = wasmer_export_descriptors_len(exports); + printf("exports_len: %d\n", exports_len); + assert(exports_len == 1); + + wasmer_export_descriptor_t *export = wasmer_export_descriptors_get(exports, 0); + + wasmer_import_export_kind kind = wasmer_export_descriptor_kind(export); + assert(kind == WASM_FUNCTION); + + wasmer_byte_array name_bytes = wasmer_export_descriptor_name(export); + assert(name_bytes.bytes_len == 3); + char expected[] = {'s', 'u', 'm'}; + for(int idx = 0; idx < 3; idx++){ + printf("%c\n", name_bytes.bytes[idx]); + assert(name_bytes.bytes[idx] == expected[idx]); + } + + printf("Destroy module\n"); + wasmer_module_destroy(module); + printf("Destroy exports\n"); + wasmer_export_descriptors_destroy(exports); + return 0; +} \ No newline at end of file diff --git a/lib/runtime-c-api/tests/test-module-imports.c b/lib/runtime-c-api/tests/test-module-imports.c new file mode 100644 index 000000000..b63d308f2 --- /dev/null +++ b/lib/runtime-c-api/tests/test-module-imports.c @@ -0,0 +1,56 @@ +#include +#include "../wasmer.h" +#include +#include + +int main() +{ + // Read the wasm file bytes + FILE *file = fopen("wasm_sample_app.wasm", "r"); + fseek(file, 0, SEEK_END); + long len = ftell(file); + uint8_t *bytes = malloc(len); + fseek(file, 0, SEEK_SET); + fread(bytes, 1, len, file); + fclose(file); + + wasmer_module_t *module = NULL; + wasmer_result_t compile_result = wasmer_compile(&module, bytes, len); + printf("Compile result: %d\n", compile_result); + assert(compile_result == WASMER_OK); + + wasmer_import_descriptors_t *imports = NULL; + wasmer_import_descriptors(module, &imports); + + int imports_len = wasmer_import_descriptors_len(imports); + printf("imports_len: %d\n", imports_len); + assert(imports_len == 1); + + wasmer_import_descriptor_t *import = wasmer_import_descriptors_get(imports, 0); + + wasmer_import_export_kind kind = wasmer_import_descriptor_kind(import); + assert(kind == WASM_FUNCTION); + + wasmer_byte_array name_bytes = wasmer_import_descriptor_name(import); + assert(name_bytes.bytes_len == 9); + char expected[] = {'p', 'r', 'i', 'n', 't', '_', 's', 't', 'r'}; + + for(int idx = 0; idx < 9; idx++){ + printf("%c\n", name_bytes.bytes[idx]); + assert(name_bytes.bytes[idx] == expected[idx]); + } + + wasmer_byte_array module_name_bytes = wasmer_import_descriptor_module_name(import); + assert(module_name_bytes.bytes_len == 3); + char module_expected[] = {'e', 'n', 'v'}; + for(int idx = 0; idx < 3; idx++){ + printf("%c\n", module_name_bytes.bytes[idx]); + assert(module_name_bytes.bytes[idx] == module_expected[idx]); + } + + printf("Destroy module\n"); + wasmer_module_destroy(module); + printf("Destroy imports\n"); + wasmer_import_descriptors_destroy(imports); + return 0; +} diff --git a/lib/runtime-c-api/tests/test-tables.c b/lib/runtime-c-api/tests/test-tables.c index 48b7be710..ac093d182 100644 --- a/lib/runtime-c-api/tests/test-tables.c +++ b/lib/runtime-c-api/tests/test-tables.c @@ -9,7 +9,7 @@ int main() wasmer_limits_t descriptor; descriptor.min = 10; wasmer_limit_option_t max; -// max.has_some = false; + // max.has_some = false; max.has_some = true; max.some = 15; descriptor.max = max; @@ -21,26 +21,29 @@ int main() printf("Table length: %d\n", len); assert(len == 10); -// wasmer_result_t grow_result1 = wasmer_table_grow(table, 5); -// assert(grow_result1 == WASMER_OK); -// uint32_t len_grow1 = wasmer_table_length(table); -// printf("Table length: %d\n", len_grow1); -// assert(len_grow1 == 15); + wasmer_result_t grow_result1 = wasmer_table_grow(table, 5); + assert(grow_result1 == WASMER_OK); + uint32_t len_grow1 = wasmer_table_length(table); + printf("Table length: %d\n", len_grow1); + assert(len_grow1 == 15); - // // Try to grow beyond max - // wasmer_result_t grow_result2 = wasmer_table_grow(&table, 1); - // assert(grow_result2 == WASMER_ERROR); - // uint32_t len_grow2 = wasmer_table_length(table); - // printf("Table length: %d\n", len_grow2); - // assert(len_grow2 == 15); + // Try to grow beyond max + wasmer_result_t grow_result2 = wasmer_table_grow(table, 1); + assert(grow_result2 == WASMER_ERROR); + uint32_t len_grow2 = wasmer_table_length(table); + printf("Table length: %d\n", len_grow2); + assert(len_grow2 == 15); -// wasmer_table_t *table_bad = NULL; -// wasmer_limits_t bad_descriptor; -// bad_descriptor.min = 15; -// bad_descriptor.max = 10; -// wasmer_result_t table_bad_result = wasmer_table_new(&table_bad, bad_descriptor); -// printf("Table result: %d\n", table_bad_result); -// assert(table_result == WASMER_ERROR); + wasmer_table_t *table_bad = NULL; + wasmer_limits_t bad_descriptor; + bad_descriptor.min = 15; + wasmer_limit_option_t max2; + max2.has_some = true; + max2.some = 10; + bad_descriptor.max = max2; + wasmer_result_t table_bad_result = wasmer_table_new(&table_bad, bad_descriptor); + printf("Table result: %d\n", table_bad_result); + assert(table_bad_result == WASMER_ERROR); printf("Destroy table\n"); wasmer_table_destroy(table); diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index 6c0494e01..f790b140e 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -35,7 +35,7 @@ typedef struct wasmer_module_t wasmer_module_t; typedef struct { -} wasmer_export_t; +} wasmer_export_descriptor_t; typedef struct { const uint8_t *bytes; @@ -44,11 +44,11 @@ typedef struct { typedef struct { -} wasmer_func_t; +} wasmer_export_descriptors_t; typedef struct { -} wasmer_exports_t; +} wasmer_export_func_t; typedef union { int32_t I32; @@ -64,6 +64,14 @@ typedef struct { typedef struct { +} wasmer_export_t; + +typedef struct { + +} wasmer_exports_t; + +typedef struct { + } wasmer_global_t; typedef struct { @@ -73,6 +81,18 @@ typedef struct { typedef struct { +} wasmer_import_descriptor_t; + +typedef struct { + +} wasmer_import_descriptors_t; + +typedef struct { + +} wasmer_import_func_t; + +typedef struct { + } wasmer_memory_t; typedef struct { @@ -80,7 +100,7 @@ typedef struct { } wasmer_table_t; typedef union { - const wasmer_func_t *func; + const wasmer_import_func_t *func; const wasmer_table_t *table; const wasmer_memory_t *memory; const wasmer_global_t *global; @@ -113,6 +133,88 @@ wasmer_result_t wasmer_compile(wasmer_module_t **module, uint8_t *wasm_bytes, uint32_t wasm_bytes_len); +/** + * Gets export descriptor kind + */ +wasmer_import_export_kind wasmer_export_descriptor_kind(wasmer_export_descriptor_t *export_); + +/** + * Gets name for the export descriptor + */ +wasmer_byte_array wasmer_export_descriptor_name(wasmer_export_descriptor_t *export_descriptor); + +/** + * Gets export descriptors for the given module + * The caller owns the object and should call `wasmer_export_descriptors_destroy` to free it. + */ +void wasmer_export_descriptors(wasmer_module_t *module, + wasmer_export_descriptors_t **export_descriptors); + +/** + * Frees the memory for the given export descriptors + */ +void wasmer_export_descriptors_destroy(wasmer_export_descriptors_t *export_descriptors); + +/** + * Gets export descriptor by index + */ +wasmer_export_descriptor_t *wasmer_export_descriptors_get(wasmer_export_descriptors_t *export_descriptors, + int idx); + +/** + * Gets the length of the export descriptors + */ +int wasmer_export_descriptors_len(wasmer_export_descriptors_t *exports); + +/** + * Calls a `func` with the provided parameters. + * Results are set using the provided `results` pointer. + * Returns `wasmer_result_t::WASMER_OK` upon success. + * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` + * and `wasmer_last_error_message` to get an error message. + */ +wasmer_result_t wasmer_export_func_call(wasmer_export_func_t *func, + const wasmer_value_t *params, + int params_len, + wasmer_value_t *results, + int results_len); + +/** + * Sets the params buffer to the parameter types of the given wasmer_export_func_t + * Returns `wasmer_result_t::WASMER_OK` upon success. + * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` + * and `wasmer_last_error_message` to get an error message. + */ +wasmer_result_t wasmer_export_func_params(wasmer_export_func_t *func, + wasmer_value_tag *params, + int params_len); + +/** + * Sets the result parameter to the arity of the params of the wasmer_export_func_t + * Returns `wasmer_result_t::WASMER_OK` upon success. + * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` + * and `wasmer_last_error_message` to get an error message. + */ +wasmer_result_t wasmer_export_func_params_arity(wasmer_export_func_t *func, uint32_t *result); + +/** + * Sets the returns buffer to the parameter types of the given wasmer_export_func_t + * Returns `wasmer_result_t::WASMER_OK` upon success. + * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` + * and `wasmer_last_error_message` to get an error message. + */ +wasmer_result_t wasmer_export_func_returns(wasmer_export_func_t *func, + wasmer_value_tag *returns, + int returns_len); + +/** + * Sets the result parameter to the arity of the returns of the wasmer_export_func_t + * Returns `wasmer_result_t::WASMER_OK` upon success. + * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` + * and `wasmer_last_error_message` to get an error message. + */ +wasmer_result_t wasmer_export_func_returns_arity(wasmer_export_func_t *func, uint32_t *result); + /** * Gets wasmer_export kind */ @@ -124,9 +226,9 @@ wasmer_import_export_kind wasmer_export_kind(wasmer_export_t *export_); wasmer_byte_array wasmer_export_name(wasmer_export_t *export_); /** - * Gets func from wasm_export + * Gets export func from export */ -const wasmer_func_t *wasmer_export_to_func(wasmer_export_t *export_); +const wasmer_export_func_t *wasmer_export_to_func(wasmer_export_t *export_); /** * Frees the memory for the given exports @@ -143,68 +245,6 @@ wasmer_export_t *wasmer_exports_get(wasmer_exports_t *exports, int idx); */ int wasmer_exports_len(wasmer_exports_t *exports); -/** - * Calls a `func` with the provided parameters. - * Results are set using the provided `results` pointer. - * Returns `wasmer_result_t::WASMER_OK` upon success. - * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` - * and `wasmer_last_error_message` to get an error message. - */ -wasmer_result_t wasmer_func_call(wasmer_func_t *func, - const wasmer_value_t *params, - int params_len, - wasmer_value_t *results, - int results_len); - -/** - * Frees memory for the given Func - */ -void wasmer_func_destroy(wasmer_func_t *func); - -/** - * Creates new func - * The caller owns the object and should call `wasmer_func_destroy` to free it. - */ -const wasmer_func_t *wasmer_func_new(void (*func)(void *data), - const wasmer_value_tag *params, - int params_len, - const wasmer_value_tag *returns, - int returns_len); - -/** - * Sets the params buffer to the parameter types of the given wasmer_func_t - * Returns `wasmer_result_t::WASMER_OK` upon success. - * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` - * and `wasmer_last_error_message` to get an error message. - */ -wasmer_result_t wasmer_func_params(wasmer_func_t *func, wasmer_value_tag *params, int params_len); - -/** - * Sets the result parameter to the arity of the params of the wasmer_func_t - * Returns `wasmer_result_t::WASMER_OK` upon success. - * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` - * and `wasmer_last_error_message` to get an error message. - */ -wasmer_result_t wasmer_func_params_arity(wasmer_func_t *func, uint32_t *result); - -/** - * Sets the returns buffer to the parameter types of the given wasmer_func_t - * Returns `wasmer_result_t::WASMER_OK` upon success. - * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` - * and `wasmer_last_error_message` to get an error message. - */ -wasmer_result_t wasmer_func_returns(wasmer_func_t *func, - wasmer_value_tag *returns, - int returns_len); - -/** - * Sets the result parameter to the arity of the returns of the wasmer_func_t - * Returns `wasmer_result_t::WASMER_OK` upon success. - * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` - * and `wasmer_last_error_message` to get an error message. - */ -wasmer_result_t wasmer_func_returns_arity(wasmer_func_t *func, uint32_t *result); - /** * Frees memory for the given Global */ @@ -231,6 +271,95 @@ wasmer_global_t *wasmer_global_new(wasmer_value_t value, bool mutable_); */ void wasmer_global_set(wasmer_global_t *global, wasmer_value_t value); +/** + * Gets export descriptor kind + */ +wasmer_import_export_kind wasmer_import_descriptor_kind(wasmer_import_descriptor_t *export_); + +/** + * Gets module name for the import descriptor + */ +wasmer_byte_array wasmer_import_descriptor_module_name(wasmer_import_descriptor_t *import_descriptor); + +/** + * Gets name for the import descriptor + */ +wasmer_byte_array wasmer_import_descriptor_name(wasmer_import_descriptor_t *import_descriptor); + +/** + * Gets import descriptors for the given module + * The caller owns the object and should call `wasmer_import_descriptors_destroy` to free it. + */ +void wasmer_import_descriptors(wasmer_module_t *module, + wasmer_import_descriptors_t **import_descriptors); + +/** + * Frees the memory for the given import descriptors + */ +void wasmer_import_descriptors_destroy(wasmer_import_descriptors_t *import_descriptors); + +/** + * Gets import descriptor by index + */ +wasmer_import_descriptor_t *wasmer_import_descriptors_get(wasmer_import_descriptors_t *import_descriptors, + int idx); + +/** + * Gets the length of the import descriptors + */ +int wasmer_import_descriptors_len(wasmer_import_descriptors_t *exports); + +/** + * Frees memory for the given Func + */ +void wasmer_import_func_destroy(wasmer_import_func_t *func); + +/** + * Creates new func + * The caller owns the object and should call `wasmer_import_func_destroy` to free it. + */ +const wasmer_import_func_t *wasmer_import_func_new(void (*func)(void *data), + const wasmer_value_tag *params, + int params_len, + const wasmer_value_tag *returns, + int returns_len); + +/** + * Sets the params buffer to the parameter types of the given wasmer_import_func_t + * Returns `wasmer_result_t::WASMER_OK` upon success. + * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` + * and `wasmer_last_error_message` to get an error message. + */ +wasmer_result_t wasmer_import_func_params(wasmer_import_func_t *func, + wasmer_value_tag *params, + int params_len); + +/** + * Sets the result parameter to the arity of the params of the wasmer_import_func_t + * Returns `wasmer_result_t::WASMER_OK` upon success. + * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` + * and `wasmer_last_error_message` to get an error message. + */ +wasmer_result_t wasmer_import_func_params_arity(wasmer_import_func_t *func, uint32_t *result); + +/** + * Sets the returns buffer to the parameter types of the given wasmer_import_func_t + * Returns `wasmer_result_t::WASMER_OK` upon success. + * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` + * and `wasmer_last_error_message` to get an error message. + */ +wasmer_result_t wasmer_import_func_returns(wasmer_import_func_t *func, + wasmer_value_tag *returns, + int returns_len); + +/** + * Sets the result parameter to the arity of the returns of the wasmer_import_func_t + * Returns `wasmer_result_t::WASMER_OK` upon success. + * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` + * and `wasmer_last_error_message` to get an error message. + */ +wasmer_result_t wasmer_import_func_returns_arity(wasmer_import_func_t *func, uint32_t *result); + /** * Calls an instances exported function by `name` with the provided parameters. * Results are set using the provided `results` pointer. diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 2bb55de45..df9904e86 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -30,7 +30,7 @@ struct wasmer_instance_t; struct wasmer_module_t; -struct wasmer_export_t { +struct wasmer_export_descriptor_t { }; @@ -39,11 +39,11 @@ struct wasmer_byte_array { uint32_t bytes_len; }; -struct wasmer_func_t { +struct wasmer_export_descriptors_t { }; -struct wasmer_exports_t { +struct wasmer_export_func_t { }; @@ -59,6 +59,14 @@ struct wasmer_value_t { wasmer_value value; }; +struct wasmer_export_t { + +}; + +struct wasmer_exports_t { + +}; + struct wasmer_global_t { }; @@ -68,6 +76,18 @@ struct wasmer_global_descriptor_t { wasmer_value_tag kind; }; +struct wasmer_import_descriptor_t { + +}; + +struct wasmer_import_descriptors_t { + +}; + +struct wasmer_import_func_t { + +}; + struct wasmer_memory_t { }; @@ -77,7 +97,7 @@ struct wasmer_table_t { }; union wasmer_import_export_value { - const wasmer_func_t *func; + const wasmer_import_func_t *func; const wasmer_table_t *table; const wasmer_memory_t *memory; const wasmer_global_t *global; @@ -110,14 +130,74 @@ wasmer_result_t wasmer_compile(wasmer_module_t **module, uint8_t *wasm_bytes, uint32_t wasm_bytes_len); +/// Gets export descriptor kind +wasmer_import_export_kind wasmer_export_descriptor_kind(wasmer_export_descriptor_t *export_); + +/// Gets name for the export descriptor +wasmer_byte_array wasmer_export_descriptor_name(wasmer_export_descriptor_t *export_descriptor); + +/// Gets export descriptors for the given module +/// The caller owns the object and should call `wasmer_export_descriptors_destroy` to free it. +void wasmer_export_descriptors(wasmer_module_t *module, + wasmer_export_descriptors_t **export_descriptors); + +/// Frees the memory for the given export descriptors +void wasmer_export_descriptors_destroy(wasmer_export_descriptors_t *export_descriptors); + +/// Gets export descriptor by index +wasmer_export_descriptor_t *wasmer_export_descriptors_get(wasmer_export_descriptors_t *export_descriptors, + int idx); + +/// Gets the length of the export descriptors +int wasmer_export_descriptors_len(wasmer_export_descriptors_t *exports); + +/// Calls a `func` with the provided parameters. +/// Results are set using the provided `results` pointer. +/// Returns `wasmer_result_t::WASMER_OK` upon success. +/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` +/// and `wasmer_last_error_message` to get an error message. +wasmer_result_t wasmer_export_func_call(wasmer_export_func_t *func, + const wasmer_value_t *params, + int params_len, + wasmer_value_t *results, + int results_len); + +/// Sets the params buffer to the parameter types of the given wasmer_export_func_t +/// Returns `wasmer_result_t::WASMER_OK` upon success. +/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` +/// and `wasmer_last_error_message` to get an error message. +wasmer_result_t wasmer_export_func_params(wasmer_export_func_t *func, + wasmer_value_tag *params, + int params_len); + +/// Sets the result parameter to the arity of the params of the wasmer_export_func_t +/// Returns `wasmer_result_t::WASMER_OK` upon success. +/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` +/// and `wasmer_last_error_message` to get an error message. +wasmer_result_t wasmer_export_func_params_arity(wasmer_export_func_t *func, uint32_t *result); + +/// Sets the returns buffer to the parameter types of the given wasmer_export_func_t +/// Returns `wasmer_result_t::WASMER_OK` upon success. +/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` +/// and `wasmer_last_error_message` to get an error message. +wasmer_result_t wasmer_export_func_returns(wasmer_export_func_t *func, + wasmer_value_tag *returns, + int returns_len); + +/// Sets the result parameter to the arity of the returns of the wasmer_export_func_t +/// Returns `wasmer_result_t::WASMER_OK` upon success. +/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` +/// and `wasmer_last_error_message` to get an error message. +wasmer_result_t wasmer_export_func_returns_arity(wasmer_export_func_t *func, uint32_t *result); + /// Gets wasmer_export kind wasmer_import_export_kind wasmer_export_kind(wasmer_export_t *export_); /// Gets name from wasmer_export wasmer_byte_array wasmer_export_name(wasmer_export_t *export_); -/// Gets func from wasm_export -const wasmer_func_t *wasmer_export_to_func(wasmer_export_t *export_); +/// Gets export func from export +const wasmer_export_func_t *wasmer_export_to_func(wasmer_export_t *export_); /// Frees the memory for the given exports void wasmer_exports_destroy(wasmer_exports_t *exports); @@ -128,54 +208,6 @@ wasmer_export_t *wasmer_exports_get(wasmer_exports_t *exports, int idx); /// Gets the length of the exports int wasmer_exports_len(wasmer_exports_t *exports); -/// Calls a `func` with the provided parameters. -/// Results are set using the provided `results` pointer. -/// Returns `wasmer_result_t::WASMER_OK` upon success. -/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` -/// and `wasmer_last_error_message` to get an error message. -wasmer_result_t wasmer_func_call(wasmer_func_t *func, - const wasmer_value_t *params, - int params_len, - wasmer_value_t *results, - int results_len); - -/// Frees memory for the given Func -void wasmer_func_destroy(wasmer_func_t *func); - -/// Creates new func -/// The caller owns the object and should call `wasmer_func_destroy` to free it. -const wasmer_func_t *wasmer_func_new(void (*func)(void *data), - const wasmer_value_tag *params, - int params_len, - const wasmer_value_tag *returns, - int returns_len); - -/// Sets the params buffer to the parameter types of the given wasmer_func_t -/// Returns `wasmer_result_t::WASMER_OK` upon success. -/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` -/// and `wasmer_last_error_message` to get an error message. -wasmer_result_t wasmer_func_params(wasmer_func_t *func, wasmer_value_tag *params, int params_len); - -/// Sets the result parameter to the arity of the params of the wasmer_func_t -/// Returns `wasmer_result_t::WASMER_OK` upon success. -/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` -/// and `wasmer_last_error_message` to get an error message. -wasmer_result_t wasmer_func_params_arity(wasmer_func_t *func, uint32_t *result); - -/// Sets the returns buffer to the parameter types of the given wasmer_func_t -/// Returns `wasmer_result_t::WASMER_OK` upon success. -/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` -/// and `wasmer_last_error_message` to get an error message. -wasmer_result_t wasmer_func_returns(wasmer_func_t *func, - wasmer_value_tag *returns, - int returns_len); - -/// Sets the result parameter to the arity of the returns of the wasmer_func_t -/// Returns `wasmer_result_t::WASMER_OK` upon success. -/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` -/// and `wasmer_last_error_message` to get an error message. -wasmer_result_t wasmer_func_returns_arity(wasmer_func_t *func, uint32_t *result); - /// Frees memory for the given Global void wasmer_global_destroy(wasmer_global_t *global); @@ -192,6 +224,69 @@ wasmer_global_t *wasmer_global_new(wasmer_value_t value, bool mutable_); /// Sets the value stored by the given Global void wasmer_global_set(wasmer_global_t *global, wasmer_value_t value); +/// Gets export descriptor kind +wasmer_import_export_kind wasmer_import_descriptor_kind(wasmer_import_descriptor_t *export_); + +/// Gets module name for the import descriptor +wasmer_byte_array wasmer_import_descriptor_module_name(wasmer_import_descriptor_t *import_descriptor); + +/// Gets name for the import descriptor +wasmer_byte_array wasmer_import_descriptor_name(wasmer_import_descriptor_t *import_descriptor); + +/// Gets import descriptors for the given module +/// The caller owns the object and should call `wasmer_import_descriptors_destroy` to free it. +void wasmer_import_descriptors(wasmer_module_t *module, + wasmer_import_descriptors_t **import_descriptors); + +/// Frees the memory for the given import descriptors +void wasmer_import_descriptors_destroy(wasmer_import_descriptors_t *import_descriptors); + +/// Gets import descriptor by index +wasmer_import_descriptor_t *wasmer_import_descriptors_get(wasmer_import_descriptors_t *import_descriptors, + int idx); + +/// Gets the length of the import descriptors +int wasmer_import_descriptors_len(wasmer_import_descriptors_t *exports); + +/// Frees memory for the given Func +void wasmer_import_func_destroy(wasmer_import_func_t *func); + +/// Creates new func +/// The caller owns the object and should call `wasmer_import_func_destroy` to free it. +const wasmer_import_func_t *wasmer_import_func_new(void (*func)(void *data), + const wasmer_value_tag *params, + int params_len, + const wasmer_value_tag *returns, + int returns_len); + +/// Sets the params buffer to the parameter types of the given wasmer_import_func_t +/// Returns `wasmer_result_t::WASMER_OK` upon success. +/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` +/// and `wasmer_last_error_message` to get an error message. +wasmer_result_t wasmer_import_func_params(wasmer_import_func_t *func, + wasmer_value_tag *params, + int params_len); + +/// Sets the result parameter to the arity of the params of the wasmer_import_func_t +/// Returns `wasmer_result_t::WASMER_OK` upon success. +/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` +/// and `wasmer_last_error_message` to get an error message. +wasmer_result_t wasmer_import_func_params_arity(wasmer_import_func_t *func, uint32_t *result); + +/// Sets the returns buffer to the parameter types of the given wasmer_import_func_t +/// Returns `wasmer_result_t::WASMER_OK` upon success. +/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` +/// and `wasmer_last_error_message` to get an error message. +wasmer_result_t wasmer_import_func_returns(wasmer_import_func_t *func, + wasmer_value_tag *returns, + int returns_len); + +/// Sets the result parameter to the arity of the returns of the wasmer_import_func_t +/// Returns `wasmer_result_t::WASMER_OK` upon success. +/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` +/// and `wasmer_last_error_message` to get an error message. +wasmer_result_t wasmer_import_func_returns_arity(wasmer_import_func_t *func, uint32_t *result); + /// Calls an instances exported function by `name` with the provided parameters. /// Results are set using the provided `results` pointer. /// Returns `wasmer_result_t::WASMER_OK` upon success. diff --git a/lib/runtime-core/Cargo.toml b/lib/runtime-core/Cargo.toml index cb5a6b4b1..c6ac22f40 100644 --- a/lib/runtime-core/Cargo.toml +++ b/lib/runtime-core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer-runtime-core" -version = "0.1.2" +version = "0.2.1" description = "Wasmer runtime core library" license = "MIT" authors = ["The Wasmer Engineering Team "] @@ -15,7 +15,7 @@ parking_lot = "0.7.1" lazy_static = "1.2.0" indexmap = "1.0.2" errno = "0.2.4" -libc = "0.2.48" +libc = "0.2.49" hex = "0.3.2" # Dependencies for caching. @@ -29,7 +29,9 @@ version = "1.0" version = "0.10" [dependencies.serde-bench] version = "0.0.7" -[dependencies.sha2] +[dependencies.blake2b_simd] +version = "0.4.1" +[dependencies.digest] version = "0.8.0" [dependencies.hashbrown] version = "0.1" @@ -39,7 +41,6 @@ features = ["serde"] winapi = { version = "0.3", features = ["memoryapi"] } [dev-dependencies] -wasmer-clif-backend = { path = "../clif-backend", version = "0.1.2" } field-offset = "0.1.1" [features] diff --git a/lib/runtime-core/src/backend.rs b/lib/runtime-core/src/backend.rs index 52978cf08..47f0fbae9 100644 --- a/lib/runtime-core/src/backend.rs +++ b/lib/runtime-core/src/backend.rs @@ -12,7 +12,7 @@ use crate::{ module::ModuleInfo, sys::Memory, }; -use std::ptr::NonNull; +use std::{any::Any, ptr::NonNull}; pub mod sys { pub use crate::sys::*; @@ -79,7 +79,7 @@ pub trait ProtectedCaller: Send + Sync { } pub trait UserTrapper { - unsafe fn do_early_trap(&self, msg: String) -> !; + unsafe fn do_early_trap(&self, data: Box) -> !; } pub trait FuncResolver: Send + Sync { diff --git a/lib/runtime-core/src/cache.rs b/lib/runtime-core/src/cache.rs index e47a944d3..1cb804655 100644 --- a/lib/runtime-core/src/cache.rs +++ b/lib/runtime-core/src/cache.rs @@ -2,8 +2,8 @@ use crate::{ module::{Module, ModuleInfo}, sys::Memory, }; -use sha2::{Digest, Sha256}; -use std::{io, mem, slice}; +use blake2b_simd::blake2bp; +use std::{fmt, io, mem, slice}; #[derive(Debug)] pub enum InvalidFileType { @@ -33,7 +33,7 @@ impl From for Error { /// /// [`Cache`]: trait.Cache.html #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] -pub struct WasmHash([u8; 32]); +pub struct WasmHash([u8; 32], [u8; 32]); impl WasmHash { /// Hash a wasm module. @@ -42,19 +42,31 @@ impl WasmHash { /// This does no verification that the supplied data /// is, in fact, a wasm module. pub fn generate(wasm: &[u8]) -> Self { - let mut array = [0u8; 32]; - array.copy_from_slice(Sha256::digest(wasm).as_slice()); - WasmHash(array) + let mut first_part = [0u8; 32]; + let mut second_part = [0u8; 32]; + + let mut state = blake2bp::State::new(); + state.update(wasm); + + let hasher = state.finalize(); + let generic_array = hasher.as_bytes(); + + first_part.copy_from_slice(&generic_array[0..32]); + second_part.copy_from_slice(&generic_array[32..64]); + WasmHash(first_part, second_part) } /// Create the hexadecimal representation of the /// stored hash. pub fn encode(self) -> String { - hex::encode(self.0) + hex::encode(&self.into_array() as &[u8]) } - pub(crate) fn into_array(self) -> [u8; 32] { - self.0 + pub(crate) fn into_array(self) -> [u8; 64] { + let mut total = [0u8; 64]; + total[0..32].copy_from_slice(&self.0); + total[32..64].copy_from_slice(&self.1); + total } } @@ -189,8 +201,8 @@ impl Artifact { /// /// The `wasmer-runtime` supplies a naive `FileSystemCache` api. pub trait Cache { - type LoadError; - type StoreError; + type LoadError: fmt::Debug; + type StoreError: fmt::Debug; fn load(&self, key: WasmHash) -> Result; fn store(&mut self, key: WasmHash, module: Module) -> Result<(), Self::StoreError>; diff --git a/lib/runtime-core/src/error.rs b/lib/runtime-core/src/error.rs index ad7063493..45c627aec 100644 --- a/lib/runtime-core/src/error.rs +++ b/lib/runtime-core/src/error.rs @@ -1,8 +1,9 @@ use crate::types::{ FuncSig, GlobalDescriptor, MemoryDescriptor, MemoryIndex, TableDescriptor, TableIndex, Type, + Value, }; use core::borrow::Borrow; -use std::sync::Arc; +use std::{any::Any, sync::Arc}; pub type Result = std::result::Result; pub type CompileResult = std::result::Result; @@ -120,28 +121,11 @@ impl std::error::Error for LinkError {} /// The main way to do this is `Instance.call`. /// /// Comparing two `RuntimeError`s always evaluates to false. -#[derive(Debug, Clone)] +#[derive(Debug)] pub enum RuntimeError { - OutOfBoundsAccess { - memory: MemoryIndex, - addr: Option, - }, - TableOutOfBounds { - table: TableIndex, - }, - IndirectCallSignature { - table: TableIndex, - }, - IndirectCallToNull { - table: TableIndex, - }, - IllegalArithmeticOperation, - User { - msg: String, - }, - Unknown { - msg: String, - }, + Trap { msg: Box }, + Exception { data: Box<[Value]> }, + Panic { data: Box }, } impl PartialEq for RuntimeError { @@ -153,30 +137,13 @@ impl PartialEq for RuntimeError { impl std::fmt::Display for RuntimeError { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { match self { - RuntimeError::IndirectCallSignature { table } => write!( - f, - "Indirect call signature error with Table Index \"{:?}\"", - table - ), - RuntimeError::IndirectCallToNull { table } => { - write!(f, "Indirect call to null with table index \"{:?}\"", table) + RuntimeError::Trap { ref msg } => { + write!(f, "WebAssembly trap occured during runtime: {}", msg) } - RuntimeError::IllegalArithmeticOperation => write!(f, "Illegal arithmetic operation"), - RuntimeError::OutOfBoundsAccess { memory, addr } => match addr { - Some(addr) => write!( - f, - "Out-of-bounds access with memory index {:?} and address {}", - memory, addr - ), - None => write!(f, "Out-of-bounds access with memory index {:?}", memory), - }, - RuntimeError::TableOutOfBounds { table } => { - write!(f, "Table out of bounds with table index \"{:?}\"", table) + RuntimeError::Exception { ref data } => { + write!(f, "Uncaught WebAssembly exception: {:?}", data) } - RuntimeError::Unknown { msg } => { - write!(f, "Unknown runtime error with message: \"{}\"", msg) - } - RuntimeError::User { msg } => write!(f, "User runtime error with message: \"{}\"", msg), + RuntimeError::Panic { data: _ } => write!(f, "User-defined \"panic\""), } } } @@ -232,7 +199,7 @@ impl std::error::Error for ResolveError {} /// be the `CallError::Runtime(RuntimeError)` variant. /// /// Comparing two `CallError`s always evaluates to false. -#[derive(Debug, Clone)] +#[derive(Debug)] pub enum CallError { Resolve(ResolveError), Runtime(RuntimeError), @@ -291,7 +258,7 @@ impl std::error::Error for CreationError {} /// of a webassembly module. /// /// Comparing two `Error`s always evaluates to false. -#[derive(Debug, Clone)] +#[derive(Debug)] pub enum Error { CompileError(CompileError), LinkError(Vec), @@ -357,8 +324,127 @@ impl From for CallError { impl std::fmt::Display for Error { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{}", self) + match self { + Error::CompileError(err) => write!(f, "compile error: {}", err), + Error::LinkError(errs) => { + if errs.len() == 1 { + write!(f, "link error: {}", errs[0]) + } else { + write!(f, "{} link errors:", errs.len())?; + for (i, err) in errs.iter().enumerate() { + write!(f, " ({} of {}) {}", i + 1, errs.len(), err)?; + } + Ok(()) + } + } + Error::RuntimeError(err) => write!(f, "runtime error: {}", err), + Error::ResolveError(err) => write!(f, "resolve error: {}", err), + Error::CallError(err) => write!(f, "call error: {}", err), + Error::CreationError(err) => write!(f, "creation error: {}", err), + } } } impl std::error::Error for Error {} + +#[derive(Debug)] +pub enum GrowError { + MemoryGrowError, + TableGrowError, + ExceededMaxPages(PageError), + ExceededMaxPagesForMemory(usize, usize), + CouldNotProtectMemory(MemoryProtectionError), + CouldNotCreateMemory(MemoryCreationError), +} + +impl std::fmt::Display for GrowError { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self { + GrowError::MemoryGrowError => write!(f, "Unable to grow memory"), + GrowError::TableGrowError => write!(f, "Unable to grow table"), + GrowError::ExceededMaxPages(e) => write!(f, "Grow Error: {}", e), + GrowError::ExceededMaxPagesForMemory(left, added) => write!(f, "Failed to add pages because would exceed maximum number of pages for the memory. Left: {}, Added: {}", left, added), + GrowError::CouldNotCreateMemory(e) => write!(f, "Grow Error: {}", e), + GrowError::CouldNotProtectMemory(e) => write!(f, "Grow Error: {}", e), + } + } +} + +impl std::error::Error for GrowError {} + +#[derive(Debug)] +pub enum PageError { + // left, right, added + ExceededMaxPages(usize, usize, usize), +} + +impl std::fmt::Display for PageError { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self { + PageError::ExceededMaxPages(left, right, added) => write!(f, "Failed to add pages because would exceed maximum number of pages. Left: {}, Right: {}, Pages added: {}", left, right, added), + } + } +} +impl std::error::Error for PageError {} + +impl Into for PageError { + fn into(self) -> GrowError { + GrowError::ExceededMaxPages(self) + } +} + +#[derive(Debug)] +pub enum MemoryCreationError { + VirtualMemoryAllocationFailed(usize, String), + CouldNotCreateMemoryFromFile(std::io::Error), +} + +impl std::fmt::Display for MemoryCreationError { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self { + MemoryCreationError::VirtualMemoryAllocationFailed(size, msg) => write!( + f, + "Allocation virtual memory with size {} failed. \nErrno message: {}", + size, msg + ), + MemoryCreationError::CouldNotCreateMemoryFromFile(e) => write!(f, "IO Error: {}", e), + } + } +} +impl std::error::Error for MemoryCreationError {} + +impl Into for MemoryCreationError { + fn into(self) -> GrowError { + GrowError::CouldNotCreateMemory(self) + } +} + +impl From for MemoryCreationError { + fn from(io_error: std::io::Error) -> Self { + MemoryCreationError::CouldNotCreateMemoryFromFile(io_error) + } +} + +#[derive(Debug)] +pub enum MemoryProtectionError { + ProtectionFailed(usize, usize, String), +} + +impl std::fmt::Display for MemoryProtectionError { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self { + MemoryProtectionError::ProtectionFailed(start, size, msg) => write!( + f, + "Allocation virtual memory starting at {} with size {} failed. \nErrno message: {}", + start, size, msg + ), + } + } +} +impl std::error::Error for MemoryProtectionError {} + +impl Into for MemoryProtectionError { + fn into(self) -> GrowError { + GrowError::CouldNotProtectMemory(self) + } +} diff --git a/lib/runtime-core/src/memory/dynamic.rs b/lib/runtime-core/src/memory/dynamic.rs index bfe731a83..332a37acb 100644 --- a/lib/runtime-core/src/memory/dynamic.rs +++ b/lib/runtime-core/src/memory/dynamic.rs @@ -1,3 +1,4 @@ +use crate::error::GrowError; use crate::{ error::CreationError, sys, @@ -14,9 +15,9 @@ pub const DYNAMIC_GUARD_SIZE: usize = 4096; /// when first created. Over time, as it grows, it may reallocate to /// a different location and size. /// -/// Dynamic memories are signifigantly faster to create than static +/// Dynamic memories are significantly faster to create than static /// memories and use much less virtual memory, however, they require -/// the webassembly module to bounds-check memory accesses. +/// the WebAssembly module to bounds-check memory accesses. /// /// While, a dynamic memory could use a vector of some sort as its /// backing memory, we use mmap (or the platform-equivalent) to allow @@ -65,26 +66,29 @@ impl DynamicMemory { self.current } - pub fn grow(&mut self, delta: Pages, local: &mut vm::LocalMemory) -> Option { + pub fn grow(&mut self, delta: Pages, local: &mut vm::LocalMemory) -> Result { if delta == Pages(0) { - return Some(self.current); + return Ok(self.current); } - let new_pages = self.current.checked_add(delta)?; + let new_pages = self.current.checked_add(delta).map_err(|e| e.into())?; if let Some(max) = self.max { if new_pages > max { - return None; + return Err(GrowError::ExceededMaxPagesForMemory( + new_pages.0 as usize, + max.0 as usize, + )); } } - let mut new_memory = - sys::Memory::with_size(new_pages.bytes().0 + DYNAMIC_GUARD_SIZE).ok()?; + let mut new_memory = sys::Memory::with_size(new_pages.bytes().0 + DYNAMIC_GUARD_SIZE) + .map_err(|e| e.into())?; unsafe { new_memory .protect(0..new_pages.bytes().0, sys::Protect::ReadWrite) - .ok()?; + .map_err(|e| e.into())?; new_memory.as_slice_mut()[..self.current.bytes().0] .copy_from_slice(&self.memory.as_slice()[..self.current.bytes().0]); @@ -97,7 +101,7 @@ impl DynamicMemory { let old_pages = self.current; self.current = new_pages; - Some(old_pages) + Ok(old_pages) } pub fn as_slice(&self) -> &[u8] { diff --git a/lib/runtime-core/src/memory/mod.rs b/lib/runtime-core/src/memory/mod.rs index bc706b564..4a9dccba7 100644 --- a/lib/runtime-core/src/memory/mod.rs +++ b/lib/runtime-core/src/memory/mod.rs @@ -1,5 +1,5 @@ use crate::{ - error::CreationError, + error::{CreationError, GrowError}, export::Export, import::IsExport, memory::dynamic::DYNAMIC_GUARD_SIZE, @@ -89,8 +89,8 @@ impl Memory { self.desc } - /// Grow this memory by the specfied number of pages. - pub fn grow(&self, delta: Pages) -> Option { + /// Grow this memory by the specified number of pages. + pub fn grow(&self, delta: Pages) -> Result { match &self.variant { MemoryVariant::Unshared(unshared_mem) => unshared_mem.grow(delta), MemoryVariant::Shared(shared_mem) => shared_mem.grow(delta), @@ -244,7 +244,7 @@ impl UnsharedMemory { }) } - pub fn grow(&self, delta: Pages) -> Option { + pub fn grow(&self, delta: Pages) -> Result { let mut storage = self.internal.storage.borrow_mut(); let mut local = self.internal.local.get(); @@ -292,7 +292,7 @@ impl SharedMemory { Ok(Self { desc }) } - pub fn grow(&self, _delta: Pages) -> Option { + pub fn grow(&self, _delta: Pages) -> Result { unimplemented!() } diff --git a/lib/runtime-core/src/memory/static_/unshared.rs b/lib/runtime-core/src/memory/static_/unshared.rs index 420fdc716..b9e66de0a 100644 --- a/lib/runtime-core/src/memory/static_/unshared.rs +++ b/lib/runtime-core/src/memory/static_/unshared.rs @@ -1,3 +1,4 @@ +use crate::error::GrowError; use crate::{ error::CreationError, memory::static_::{SAFE_STATIC_GUARD_SIZE, SAFE_STATIC_HEAP_SIZE}, @@ -61,27 +62,30 @@ impl StaticMemory { self.current } - pub fn grow(&mut self, delta: Pages, local: &mut vm::LocalMemory) -> Option { + pub fn grow(&mut self, delta: Pages, local: &mut vm::LocalMemory) -> Result { if delta == Pages(0) { - return Some(self.current); + return Ok(self.current); } - let new_pages = self.current.checked_add(delta)?; + let new_pages = self.current.checked_add(delta).map_err(|e| e.into())?; if let Some(max) = self.max { if new_pages > max { - return None; + return Err(GrowError::ExceededMaxPagesForMemory( + new_pages.0 as usize, + max.0 as usize, + )); } } - unsafe { + let _ = unsafe { self.memory .protect( self.current.bytes().0..new_pages.bytes().0, sys::Protect::ReadWrite, ) - .ok()?; - } + .map_err(|e| e.into()) + }?; local.bound = new_pages.bytes().0; @@ -89,7 +93,7 @@ impl StaticMemory { self.current = new_pages; - Some(old_pages) + Ok(old_pages) } pub fn as_slice(&self) -> &[u8] { diff --git a/lib/runtime-core/src/module.rs b/lib/runtime-core/src/module.rs index c76e8eed3..212c197c3 100644 --- a/lib/runtime-core/src/module.rs +++ b/lib/runtime-core/src/module.rs @@ -1,6 +1,6 @@ use crate::{ backend::{Backend, FuncResolver, ProtectedCaller}, - cache::{Artifact, Error as CacheError, WasmHash}, + cache::{Artifact, Error as CacheError}, error, import::ImportObject, structures::{Map, TypedIndex}, diff --git a/lib/runtime-core/src/structures/map.rs b/lib/runtime-core/src/structures/map.rs index d7177c427..add5b0257 100644 --- a/lib/runtime-core/src/structures/map.rs +++ b/lib/runtime-core/src/structures/map.rs @@ -56,6 +56,10 @@ where pub fn into_boxed_map(self) -> BoxedMap { BoxedMap::new(self.elems.into_boxed_slice()) } + + pub fn into_vec(self) -> Vec { + self.elems + } } impl Map diff --git a/lib/runtime-core/src/sys/unix/memory.rs b/lib/runtime-core/src/sys/unix/memory.rs index 8c76e6c14..338024d09 100644 --- a/lib/runtime-core/src/sys/unix/memory.rs +++ b/lib/runtime-core/src/sys/unix/memory.rs @@ -1,3 +1,5 @@ +use crate::error::MemoryCreationError; +use crate::error::MemoryProtectionError; use errno; use nix::libc; use page_size; @@ -16,13 +18,13 @@ pub struct Memory { } impl Memory { - pub fn from_file_path

(path: P, protection: Protect) -> Result + pub fn from_file_path

(path: P, protection: Protect) -> Result where P: AsRef, { - let file = File::open(path).map_err(|e| e.to_string())?; + let file = File::open(path)?; - let file_len = file.metadata().map_err(|e| e.to_string())?.len(); + let file_len = file.metadata()?.len(); let raw_fd = RawFd::from_file(file); @@ -38,7 +40,10 @@ impl Memory { }; if ptr == -1 as _ { - Err(errno::errno().to_string()) + Err(MemoryCreationError::VirtualMemoryAllocationFailed( + file_len as usize, + errno::errno().to_string(), + )) } else { Ok(Self { ptr: ptr as *mut u8, @@ -84,7 +89,7 @@ impl Memory { } } - pub fn with_size(size: usize) -> Result { + pub fn with_size(size: usize) -> Result { if size == 0 { return Ok(Self { ptr: ptr::null_mut(), @@ -108,7 +113,10 @@ impl Memory { }; if ptr == -1 as _ { - Err(errno::errno().to_string()) + Err(MemoryCreationError::VirtualMemoryAllocationFailed( + size, + errno::errno().to_string(), + )) } else { Ok(Self { ptr: ptr as *mut u8, @@ -123,7 +131,7 @@ impl Memory { &mut self, range: impl RangeBounds, protection: Protect, - ) -> Result<(), String> { + ) -> Result<(), MemoryProtectionError> { let protect = protection.to_protect_const(); let range_start = match range.start_bound() { @@ -147,7 +155,11 @@ impl Memory { let success = libc::mprotect(start as _, size, protect as i32); if success == -1 { - Err(errno::errno().to_string()) + Err(MemoryProtectionError::ProtectionFailed( + start as usize, + size, + errno::errno().to_string(), + )) } else { self.protection = protection; Ok(()) diff --git a/lib/runtime-core/src/sys/windows/memory.rs b/lib/runtime-core/src/sys/windows/memory.rs index 771ac6788..d47388170 100644 --- a/lib/runtime-core/src/sys/windows/memory.rs +++ b/lib/runtime-core/src/sys/windows/memory.rs @@ -1,3 +1,5 @@ +use crate::error::MemoryCreationError; +use crate::error::MemoryProtectionError; use page_size; use std::ops::{Bound, RangeBounds}; use std::{ptr, slice}; @@ -44,7 +46,7 @@ impl Memory { } } - pub fn with_size(size: usize) -> Result { + pub fn with_size(size: usize) -> Result { if size == 0 { return Ok(Self { ptr: ptr::null_mut(), @@ -58,7 +60,10 @@ impl Memory { let ptr = unsafe { VirtualAlloc(ptr::null_mut(), size, MEM_RESERVE, PAGE_NOACCESS) }; if ptr.is_null() { - Err("unable to allocate memory".to_string()) + Err(MemoryCreationError::VirtualMemoryAllocationFailed( + size, + "unable to allocate memory".to_string(), + )) } else { Ok(Self { ptr: ptr as *mut u8, @@ -72,7 +77,7 @@ impl Memory { &mut self, range: impl RangeBounds, protect: Protect, - ) -> Result<(), String> { + ) -> Result<(), MemoryProtectionError> { let protect_const = protect.to_protect_const(); let range_start = match range.start_bound() { @@ -98,7 +103,11 @@ impl Memory { let ptr = VirtualAlloc(start as _, size, MEM_COMMIT, protect_const); if ptr.is_null() { - Err("unable to protect memory".to_string()) + Err(MemoryProtectionError::ProtectionFailed( + start as usize, + size, + "unable to protect memory".to_string(), + )) } else { self.protection = protect; Ok(()) diff --git a/lib/runtime-core/src/table/mod.rs b/lib/runtime-core/src/table/mod.rs index a45593802..1c97b89f3 100644 --- a/lib/runtime-core/src/table/mod.rs +++ b/lib/runtime-core/src/table/mod.rs @@ -11,6 +11,7 @@ mod anyfunc; pub use self::anyfunc::Anyfunc; use self::anyfunc::AnyfuncTable; +use crate::error::GrowError; pub enum Element<'a> { Anyfunc(Anyfunc<'a>), @@ -108,15 +109,15 @@ impl Table { } /// Grow this table by `delta`. - pub fn grow(&self, delta: u32) -> Option { + pub fn grow(&self, delta: u32) -> Result { if delta == 0 { - return Some(self.size()); + return Ok(self.size()); } match &mut *self.storage.borrow_mut() { - (TableStorage::Anyfunc(ref mut anyfunc_table), ref mut local) => { - anyfunc_table.grow(delta, local) - } + (TableStorage::Anyfunc(ref mut anyfunc_table), ref mut local) => anyfunc_table + .grow(delta, local) + .ok_or(GrowError::TableGrowError), } } diff --git a/lib/runtime-core/src/typed_func.rs b/lib/runtime-core/src/typed_func.rs index 6e59d0d4a..6e2a4d26c 100644 --- a/lib/runtime-core/src/typed_func.rs +++ b/lib/runtime-core/src/typed_func.rs @@ -6,7 +6,7 @@ use crate::{ types::{FuncSig, Type, WasmExternType}, vm::Ctx, }; -use std::{cell::UnsafeCell, fmt, marker::PhantomData, mem, panic, ptr, sync::Arc}; +use std::{any::Any, cell::UnsafeCell, fmt, marker::PhantomData, mem, panic, ptr, sync::Arc}; thread_local! { pub static EARLY_TRAPPER: UnsafeCell>> = UnsafeCell::new(None); @@ -40,14 +40,14 @@ pub trait TrapEarly where Rets: WasmTypeList, { - fn report(self) -> Result; + fn report(self) -> Result>; } impl TrapEarly for Rets where Rets: WasmTypeList, { - fn report(self) -> Result { + fn report(self) -> Result> { Ok(self) } } @@ -55,10 +55,10 @@ where impl TrapEarly for Result where Rets: WasmTypeList, - E: fmt::Debug, + E: Any, { - fn report(self) -> Result { - self.map_err(|err| format!("Error: {:?}", err)) + fn report(self) -> Result> { + self.map_err(|err| Box::new(err) as Box) } } @@ -191,25 +191,17 @@ macro_rules! impl_traits { extern fn wrap<$( $x: WasmExternType, )* Rets: WasmTypeList, Trap: TrapEarly, FN: Fn( &mut Ctx $( ,$x )* ) -> Trap>( ctx: &mut Ctx $( ,$x: $x )* ) -> Rets::CStruct { let f: FN = unsafe { mem::transmute_copy(&()) }; - let msg = match panic::catch_unwind(panic::AssertUnwindSafe(|| { + let err = match panic::catch_unwind(panic::AssertUnwindSafe(|| { f( ctx $( ,$x )* ).report() })) { Ok(Ok(returns)) => return returns.into_c_struct(), Ok(Err(err)) => err, - Err(err) => { - if let Some(s) = err.downcast_ref::<&str>() { - s.to_string() - } else if let Some(s) = err.downcast_ref::() { - s.clone() - } else { - "a panic occurred, but no additional information is available".to_string() - } - }, + Err(err) => err, }; unsafe { if let Some(early_trapper) = &*EARLY_TRAPPER.with(|ucell| ucell.get()) { - early_trapper.do_early_trap(msg) + early_trapper.do_early_trap(err) } else { eprintln!("panic handling not setup"); std::process::exit(1) diff --git a/lib/runtime-core/src/units.rs b/lib/runtime-core/src/units.rs index 2486c5738..56d501438 100644 --- a/lib/runtime-core/src/units.rs +++ b/lib/runtime-core/src/units.rs @@ -1,3 +1,4 @@ +use crate::error::PageError; use std::{ fmt, ops::{Add, Sub}, @@ -11,12 +12,16 @@ const WASM_MAX_PAGES: usize = 65_536; pub struct Pages(pub u32); impl Pages { - pub fn checked_add(self, rhs: Pages) -> Option { + pub fn checked_add(self, rhs: Pages) -> Result { let added = (self.0 as usize) + (rhs.0 as usize); if added <= WASM_MAX_PAGES { - Some(Pages(added as u32)) + Ok(Pages(added as u32)) } else { - None + Err(PageError::ExceededMaxPages( + self.0 as usize, + rhs.0 as usize, + added, + )) } } diff --git a/lib/runtime-core/src/vmcalls.rs b/lib/runtime-core/src/vmcalls.rs index 576ca34ce..b428fb24e 100644 --- a/lib/runtime-core/src/vmcalls.rs +++ b/lib/runtime-core/src/vmcalls.rs @@ -20,10 +20,9 @@ pub unsafe extern "C" fn local_static_memory_grow( let local_memory = *ctx.memories.add(memory_index.index()); let memory = (*local_memory).memory as *mut StaticMemory; - if let Some(old) = (*memory).grow(delta, &mut *local_memory) { - old.0 as i32 - } else { - -1 + match (*memory).grow(delta, &mut *local_memory) { + Ok(old) => old.0 as i32, + Err(_) => -1, } } @@ -45,10 +44,9 @@ pub unsafe extern "C" fn local_dynamic_memory_grow( let local_memory = *ctx.memories.add(memory_index.index()); let memory = (*local_memory).memory as *mut DynamicMemory; - if let Some(old) = (*memory).grow(delta, &mut *local_memory) { - old.0 as i32 - } else { - -1 + match (*memory).grow(delta, &mut *local_memory) { + Ok(old) => old.0 as i32, + Err(_) => -1, } } @@ -74,10 +72,9 @@ pub unsafe extern "C" fn imported_static_memory_grow( let local_memory = *ctx.imported_memories.add(import_memory_index.index()); let memory = (*local_memory).memory as *mut StaticMemory; - if let Some(old) = (*memory).grow(delta, &mut *local_memory) { - old.0 as i32 - } else { - -1 + match (*memory).grow(delta, &mut *local_memory) { + Ok(old) => old.0 as i32, + Err(_) => -1, } } @@ -99,10 +96,9 @@ pub unsafe extern "C" fn imported_dynamic_memory_grow( let local_memory = *ctx.imported_memories.add(memory_index.index()); let memory = (*local_memory).memory as *mut DynamicMemory; - if let Some(old) = (*memory).grow(delta, &mut *local_memory) { - old.0 as i32 - } else { - -1 + match (*memory).grow(delta, &mut *local_memory) { + Ok(old) => old.0 as i32, + Err(_) => -1, } } diff --git a/lib/runtime/Cargo.toml b/lib/runtime/Cargo.toml index e0c23af11..12b719248 100644 --- a/lib/runtime/Cargo.toml +++ b/lib/runtime/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer-runtime" -version = "0.1.4" +version = "0.2.1" description = "Wasmer runtime library" license = "MIT" authors = ["The Wasmer Engineering Team "] @@ -14,11 +14,16 @@ memmap = "0.7.0" [dependencies.wasmer-runtime-core] path = "../runtime-core" -version = "0.1.2" +version = "0.2.1" [dependencies.wasmer-clif-backend] path = "../clif-backend" -version = "0.1.2" +version = "0.2.0" + +[dev-dependencies] +tempfile = "3.0.7" +criterion = "0.2" +wabt = "0.7.4" [dependencies.wasmer-llvm-backend] path = "../llvm-backend" @@ -26,5 +31,6 @@ path = "../llvm-backend" [features] debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] -[dev-dependencies] -wabt = "0.7.4" \ No newline at end of file +[[bench]] +name = "nginx" +harness = false diff --git a/lib/runtime/README.md b/lib/runtime/README.md index bd9bb0f0c..5e5542c8d 100644 --- a/lib/runtime/README.md +++ b/lib/runtime/README.md @@ -51,7 +51,7 @@ fn main() -> error::Result<()> { // We're not importing anything, so make an empty import object. let import_object = imports! {}; - let mut instance = instantiate(WASM, import_object)?; + let mut instance = instantiate(WASM, &import_object)?; let values = instance .func("add_one")? diff --git a/lib/runtime/benches/nginx.rs b/lib/runtime/benches/nginx.rs new file mode 100644 index 000000000..1466addb1 --- /dev/null +++ b/lib/runtime/benches/nginx.rs @@ -0,0 +1,53 @@ +#[macro_use] +extern crate criterion; +use criterion::Criterion; +use tempfile::tempdir; +use wasmer_runtime::{ + cache::{Cache, FileSystemCache, WasmHash}, + compile, validate, +}; + +static NGINX_WASM: &'static [u8] = include_bytes!("../../../examples/nginx/nginx.wasm"); + +fn compile_module() { + compile(NGINX_WASM).unwrap(); +} + +fn load_module(hash: WasmHash, cache: &impl Cache) { + cache.load(hash).expect("could not load module"); +} + +fn hashing_benchmark(c: &mut Criterion) { + c.bench_function("nginx HASH", |b| b.iter(|| WasmHash::generate(NGINX_WASM))); +} + +fn validate_benchmark(c: &mut Criterion) { + c.bench_function("nginx validate", |b| b.iter(|| validate(NGINX_WASM))); +} + +fn compile_benchmark(c: &mut Criterion) { + c.bench_function("nginx compile", |b| b.iter(|| compile_module())); +} + +fn load_benchmark(c: &mut Criterion) { + c.bench_function("nginx load", |b| { + let tempdir = tempdir().unwrap(); + let mut cache = unsafe { + FileSystemCache::new(tempdir.path()).expect("unable to create file system cache") + }; + let module = compile(NGINX_WASM).unwrap(); + let wasm_hash = WasmHash::generate(NGINX_WASM); + cache + .store(wasm_hash, module) + .expect("unable to store into cache"); + + b.iter(|| load_module(wasm_hash, &cache)) + }); +} + +criterion_group! { + name = benches; + config = Criterion::default().sample_size(10); + targets = validate_benchmark, hashing_benchmark, compile_benchmark, load_benchmark +} +criterion_main!(benches); diff --git a/lib/spectests/Cargo.toml b/lib/spectests/Cargo.toml index 49f052d77..32b14e421 100644 --- a/lib/spectests/Cargo.toml +++ b/lib/spectests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer-spectests" -version = "0.1.2" +version = "0.2.0" description = "Wasmer spectests library" license = "MIT" authors = ["The Wasmer Engineering Team "] @@ -9,13 +9,13 @@ edition = "2018" build = "build/mod.rs" [dependencies] -wasmer-runtime-core = { path = "../runtime-core" } +wasmer-runtime-core = { path = "../runtime-core", version = "0.2.0" } [build-dependencies] wabt = "0.7.2" [dev-dependencies] -wasmer-clif-backend = { path = "../clif-backend", version = "0.1.2" } +wasmer-clif-backend = { path = "../clif-backend", version = "0.2.0" } wasmer-llvm-backend = { path = "../llvm-backend", version = "0.1.0" } wabt = "0.7.2" diff --git a/lib/spectests/build/spectests.rs b/lib/spectests/build/spectests.rs index 25b3b63b8..c533a2951 100644 --- a/lib/spectests/build/spectests.rs +++ b/lib/spectests/build/spectests.rs @@ -569,7 +569,7 @@ fn {}_assert_malformed() {{ let assertion = if expected.len() > 0 && is_nan(&expected[0]) { format!( "let expected = {expected_result}; - if let {return_type_destructure} = result.clone().unwrap().first().unwrap() {{ + if let {return_type_destructure} = result.as_ref().unwrap().first().unwrap() {{ assert!((*result as {return_type}).is_nan()); assert_eq!((*result as {return_type}).is_sign_positive(), (expected as {return_type}).is_sign_positive()); }} else {{ diff --git a/lib/spectests/tests/semantics.rs b/lib/spectests/tests/semantics.rs index c364dca29..0bffa9dca 100644 --- a/lib/spectests/tests/semantics.rs +++ b/lib/spectests/tests/semantics.rs @@ -31,7 +31,7 @@ mod tests { match result { Err(err) => match err { - CallError::Runtime(RuntimeError::Unknown { msg }) => { + CallError::Runtime(RuntimeError::Trap { msg }) => { assert!(!msg.contains("segmentation violation")); assert!(!msg.contains("bus error")); } diff --git a/lib/win-exception-handler/Cargo.toml b/lib/win-exception-handler/Cargo.toml index 043dc3c59..18855212b 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.0.1" +version = "0.2.0" description = "Wasmer runtime exception handling for Windows" license = "MIT" authors = ["The Wasmer Engineering Team "] @@ -8,9 +8,9 @@ repository = "https://github.com/wasmerio/wasmer" edition = "2018" [target.'cfg(windows)'.dependencies] -wasmer-runtime-core = { path = "../runtime-core", version = "0.1.2" } +wasmer-runtime-core = { path = "../runtime-core", version = "0.2.0" } winapi = { version = "0.3", features = ["winbase", "errhandlingapi", "minwindef", "minwinbase", "winnt"] } -libc = "0.2.48" +libc = "0.2.49" [build-dependencies] cmake = "0.1.35" diff --git a/lib/win-exception-handler/exception_handling/exception_handling.c b/lib/win-exception-handler/exception_handling/exception_handling.c index 3284034cc..eb45b204d 100644 --- a/lib/win-exception-handler/exception_handling/exception_handling.c +++ b/lib/win-exception-handler/exception_handling/exception_handling.c @@ -10,6 +10,7 @@ __declspec(thread) DWORD64 caughtInstructionPointer; __declspec(thread) PVOID savedStackPointer; __declspec(thread) BOOL exceptionHandlerInstalled = FALSE; __declspec(thread) BOOL alreadyHandlingException = FALSE; +__declspec(thread) PVOID handle; void longjmpOutOfHere() { longjmp(jmpBuf, 1); @@ -38,6 +39,14 @@ exceptionHandler(struct _EXCEPTION_POINTERS *ExceptionInfo) { return EXCEPTION_CONTINUE_EXECUTION; } +static void removeExceptionHandler() { + if (exceptionHandlerInstalled == FALSE) { + return; + } + RemoveVectoredExceptionHandler(handle); + exceptionHandlerInstalled = FALSE; +} + uint8_t callProtected(trampoline_t trampoline, const struct wasmer_instance_context_t* ctx, const struct func_t* func, @@ -48,7 +57,7 @@ uint8_t callProtected(trampoline_t trampoline, // install exception handler if (exceptionHandlerInstalled == FALSE) { exceptionHandlerInstalled = TRUE; - AddVectoredExceptionHandler(CALL_FIRST, exceptionHandler); + handle = AddVectoredExceptionHandler(CALL_FIRST, exceptionHandler); } // jmp jmp jmp! @@ -60,6 +69,8 @@ uint8_t callProtected(trampoline_t trampoline, out_result->code = 0; out_result->exceptionAddress = 0; out_result->instructionPointer = 0; + + removeExceptionHandler(); return TRUE; } @@ -70,5 +81,6 @@ uint8_t callProtected(trampoline_t trampoline, caughtExceptionAddress = 0; caughtInstructionPointer = 0; + removeExceptionHandler(); return FALSE; } diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index 6b8c9b54b..e36e99cb6 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -1,7 +1,6 @@ extern crate structopt; use std::env; -use std::fs; use std::fs::File; use std::io; use std::io::Read; @@ -14,7 +13,6 @@ use wasmer::webassembly::InstanceABI; use wasmer::*; use wasmer_emscripten; use wasmer_runtime::cache::{Cache as BaseCache, FileSystemCache, WasmHash}; -use wasmer_runtime::error::CacheError; #[derive(Debug, StructOpt)] #[structopt(name = "wasmer", about = "Wasm execution runtime.")] @@ -35,9 +33,6 @@ enum CLIOptions { #[derive(Debug, StructOpt)] struct Run { - #[structopt(short = "d", long = "debug")] - debug: bool, - // Disable the cache #[structopt(long = "disable-cache")] disable_cache: bool, @@ -84,6 +79,12 @@ fn get_cache_dir() -> PathBuf { /// Execute a wasm/wat file fn execute_wasm(options: &Run) -> Result<(), String> { + // force disable caching on windows + #[cfg(target_os = "windows")] + let disable_cache = true; + #[cfg(not(target_os = "windows"))] + let disable_cache = options.disable_cache; + let wasm_path = &options.path; let mut wasm_binary: Vec = read_file_contents(wasm_path).map_err(|err| { @@ -99,7 +100,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> { .map_err(|e| format!("Can't convert from wast to wasm: {:?}", e))?; } - let module = if !options.disable_cache { + let module = if !disable_cache { // If we have cache enabled // We generate a hash for the given binary, so we can use it as key @@ -188,8 +189,10 @@ fn main() { CLIOptions::SelfUpdate => { println!("Self update is not supported on Windows. Use install instructions on the Wasmer homepage: https://wasmer.io"); } + #[cfg(not(target_os = "windows"))] CLIOptions::Cache(cache) => match cache { Cache::Clean => { + use std::fs; let cache_dir = get_cache_dir(); fs::remove_dir_all(cache_dir.clone()).expect("Can't remove cache dir"); fs::create_dir(cache_dir.clone()).expect("Can't create cache dir"); @@ -198,5 +201,9 @@ fn main() { println!("{}", get_cache_dir().to_string_lossy()); } }, + #[cfg(target_os = "windows")] + CLIOptions::Cache(_) => { + println!("Caching is disabled for Windows."); + } } } diff --git a/src/installer/wasmer.iss b/src/installer/wasmer.iss index 04850eb7a..f844eb4da 100644 --- a/src/installer/wasmer.iss +++ b/src/installer/wasmer.iss @@ -11,7 +11,7 @@ ChangesEnvironment=yes OutputBaseFilename=WasmerInstaller [Files] -Source: "..\target\release\wasmer.exe"; DestDir: "{app}\bin" +Source: "..\..\target\release\wasmer.exe"; DestDir: "{app}\bin" [Code] const EnvironmentKey = 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment';