Merge remote-tracking branch 'origin/master' into feature/make-instance-send

This commit is contained in:
Mark McCaskey 2019-09-23 11:05:00 -07:00
commit 1e637badc4
31 changed files with 364 additions and 174 deletions

View File

@ -12,4 +12,4 @@ links to related issues, and the context of the PR.
# Review # Review
- [ ] Create a short description of the the change in the CHANGELOG.md file - [ ] Add a short description of the the change to the CHANGELOG.md file

View File

@ -7,6 +7,8 @@ Blocks of changes will separated by version increments.
## **[Unreleased]** ## **[Unreleased]**
- [#807](https://github.com/wasmerio/wasmer/pull/807) Implement Send for `Instance`, breaking change on `ImportObject`, remove method `get_namespace` replaced with `with_namespace` and `maybe_with_namespace` - [#807](https://github.com/wasmerio/wasmer/pull/807) Implement Send for `Instance`, breaking change on `ImportObject`, remove method `get_namespace` replaced with `with_namespace` and `maybe_with_namespace`
- [#820](https://github.com/wasmerio/wasmer/issues/820) Remove null-pointer checks in `WasmPtr` from runtime-core, re-add them in Emscripten
- [#803](https://github.com/wasmerio/wasmer/issues/803) Add method to `Ctx` to invoke functions by their `TableIndex`
- [#790](https://github.com/wasmerio/wasmer/pull/790) Fix flaky test failure with LLVM, switch to large code model. - [#790](https://github.com/wasmerio/wasmer/pull/790) Fix flaky test failure with LLVM, switch to large code model.
- [#788](https://github.com/wasmerio/wasmer/pull/788) Use union merge on the changelog file. - [#788](https://github.com/wasmerio/wasmer/pull/788) Use union merge on the changelog file.
- [#785](https://github.com/wasmerio/wasmer/pull/785) Include Apache license file for spectests. - [#785](https://github.com/wasmerio/wasmer/pull/785) Include Apache license file for spectests.

79
Cargo.lock generated
View File

@ -16,11 +16,6 @@ dependencies = [
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "approx"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "arrayref" name = "arrayref"
version = "0.3.5" version = "0.3.5"
@ -205,16 +200,6 @@ name = "cfg-if"
version = "0.1.9" version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cgmath"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"approx 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "clang-sys" name = "clang-sys"
version = "0.28.1" version = "0.28.1"
@ -255,15 +240,6 @@ dependencies = [
"cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "colored"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winconsole 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "constant_time_eq" name = "constant_time_eq"
version = "0.1.4" version = "0.1.4"
@ -810,14 +786,6 @@ dependencies = [
"version_check 0.1.5 (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 = "num-traits"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "num-traits" name = "num-traits"
version = "0.2.8" version = "0.2.8"
@ -949,19 +917,7 @@ dependencies = [
[[package]] [[package]]
name = "rand" name = "rand"
version = "0.4.6" version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"getrandom 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "getrandom 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1108,11 +1064,6 @@ dependencies = [
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "rgb"
version = "0.8.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "rustc-demangle" name = "rustc-demangle"
version = "0.1.16" version = "0.1.16"
@ -1333,7 +1284,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)",
"remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1590,7 +1541,7 @@ dependencies = [
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmer-runtime-core 0.7.0", "wasmer-runtime-core 0.7.0",
] ]
@ -1691,7 +1642,6 @@ dependencies = [
"bincode 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "bincode 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"blake2b_simd 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)", "blake2b_simd 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)",
"cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)",
"colored 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"errno 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "field-offset 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1717,7 +1667,6 @@ name = "wasmer-singlepass-backend"
version = "0.7.0" version = "0.7.0"
dependencies = [ dependencies = [
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"colored 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"dynasm 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "dynasm 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"dynasmrt 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "dynasmrt 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1749,7 +1698,7 @@ dependencies = [
"generational-arena 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "generational-arena 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.100 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.100 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
"typetag 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "typetag 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1843,21 +1792,9 @@ dependencies = [
"winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "winconsole"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cgmath 0.16.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rgb 0.8.14 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[metadata] [metadata]
"checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d" "checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d"
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
"checksum approx 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08abcc3b4e9339e33a3d0a5ed15d84a687350c05689d825e0f6655eef9e76a94"
"checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee" "checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee"
"checksum arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d73f9beda665eaa98ab9e4f7442bd4e7de6652587de55b2525e52e29c1b0ba" "checksum arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d73f9beda665eaa98ab9e4f7442bd4e7de6652587de55b2525e52e29c1b0ba"
"checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" "checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90"
@ -1879,12 +1816,10 @@ dependencies = [
"checksum cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)" = "4fc9a35e1f4290eb9e5fc54ba6cf40671ed2a2514c3eeb2b2a908dda2ea5a1be" "checksum cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)" = "4fc9a35e1f4290eb9e5fc54ba6cf40671ed2a2514c3eeb2b2a908dda2ea5a1be"
"checksum cexpr 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a7fa24eb00d5ffab90eaeaf1092ac85c04c64aaf358ea6f84505b8116d24c6af" "checksum cexpr 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a7fa24eb00d5ffab90eaeaf1092ac85c04c64aaf358ea6f84505b8116d24c6af"
"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" "checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33"
"checksum cgmath 0.16.1 (registry+https://github.com/rust-lang/crates.io-index)" = "64a4b57c8f4e3a2e9ac07e0f6abc9c24b6fc9e1b54c3478cfb598f3d0023e51c"
"checksum clang-sys 0.28.1 (registry+https://github.com/rust-lang/crates.io-index)" = "81de550971c976f176130da4b2978d3b524eaa0fd9ac31f3ceb5ae1231fb4853" "checksum clang-sys 0.28.1 (registry+https://github.com/rust-lang/crates.io-index)" = "81de550971c976f176130da4b2978d3b524eaa0fd9ac31f3ceb5ae1231fb4853"
"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
"checksum cmake 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "81fb25b677f8bf1eb325017cb6bb8452f87969db0fedb4f757b297bee78a7c62" "checksum cmake 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "81fb25b677f8bf1eb325017cb6bb8452f87969db0fedb4f757b297bee78a7c62"
"checksum colored 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6cdb90b60f2927f8d76139c72dbde7e10c3a2bc47c8594c9c7a66529f2687c03"
"checksum constant_time_eq 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "995a44c877f9212528ccc74b21a232f66ad69001e40ede5bcee2ac9ef2657120" "checksum constant_time_eq 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "995a44c877f9212528ccc74b21a232f66ad69001e40ede5bcee2ac9ef2657120"
"checksum cranelift-bforest 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)" = "409f92af3dd276e112b72873a3ef02613e3c5f55b81d5d5d04f3157d4f8b8c54" "checksum cranelift-bforest 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)" = "409f92af3dd276e112b72873a3ef02613e3c5f55b81d5d5d04f3157d4f8b8c54"
"checksum cranelift-codegen 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b303542a56fba4cbaeea099fb30ed078b50de0e765fd69f7f5f410adbe31d95b" "checksum cranelift-codegen 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b303542a56fba4cbaeea099fb30ed078b50de0e765fd69f7f5f410adbe31d95b"
@ -1946,7 +1881,6 @@ dependencies = [
"checksum nix 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3b2e0b4f3320ed72aaedb9a5ac838690a8047c7b275da22711fddff4f8a14229" "checksum nix 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3b2e0b4f3320ed72aaedb9a5ac838690a8047c7b275da22711fddff4f8a14229"
"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" "checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945"
"checksum nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6" "checksum nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6"
"checksum num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31"
"checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32" "checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32"
"checksum num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcef43580c035376c0705c42792c294b66974abbfd2789b511784023f71f3273" "checksum num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcef43580c035376c0705c42792c294b66974abbfd2789b511784023f71f3273"
"checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" "checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37"
@ -1963,8 +1897,7 @@ dependencies = [
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
"checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" "checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" "checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe"
"checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" "checksum rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3ae1b169243eaf61759b8475a998f0a385e42042370f3a7dbaf35246eacc8412"
"checksum rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d47eab0e83d9693d40f825f86948aa16eff6750ead4bdffc4ab95b8b3a7f052c"
"checksum rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853" "checksum rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853"
"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" "checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
"checksum rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" "checksum rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
@ -1981,7 +1914,6 @@ dependencies = [
"checksum regex-automata 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "92b73c2a1770c255c240eaa4ee600df1704a38dc3feaa6e949e7fcd4f8dc09f9" "checksum regex-automata 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "92b73c2a1770c255c240eaa4ee600df1704a38dc3feaa6e949e7fcd4f8dc09f9"
"checksum regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716" "checksum regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716"
"checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" "checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e"
"checksum rgb 0.8.14 (registry+https://github.com/rust-lang/crates.io-index)" = "2089e4031214d129e201f8c3c8c2fe97cd7322478a0d1cdf78e7029b0042efdb"
"checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" "checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
"checksum ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c92464b447c0ee8c4fb3824ecc8383b81717b9f1e74ba2e72540aef7b9f82997" "checksum ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c92464b447c0ee8c4fb3824ecc8383b81717b9f1e74ba2e72540aef7b9f82997"
@ -2043,4 +1975,3 @@ dependencies = [
"checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" "checksum winapi-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 winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
"checksum wincolor 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "96f5016b18804d24db43cebf3c77269e7569b8954a8464501c216cc5e070eaa9" "checksum wincolor 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "96f5016b18804d24db43cebf3c77269e7569b8954a8464501c216cc5e070eaa9"
"checksum winconsole 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ef84b96d10db72dd980056666d7f1e7663ce93d82fa33b63e71c966f4cf5032"

View File

@ -58,7 +58,7 @@ members = [
"lib/wasi-tests", "lib/wasi-tests",
"lib/emscripten-tests", "lib/emscripten-tests",
"lib/middleware-common-tests", "lib/middleware-common-tests",
"examples/plugin-for-example" "examples/plugin-for-example",
] ]
[build-dependencies] [build-dependencies]
@ -105,3 +105,7 @@ managed = ["backend-singlepass", "wasmer-runtime-core/managed"]
[[example]] [[example]]
name = "plugin" name = "plugin"
crate-type = ["bin"] crate-type = ["bin"]
[[example]]
name = "callback"
crate-type = ["bin"]

View File

@ -1,4 +1,4 @@
.PHONY: spectests emtests clean build install lint precommit docs .PHONY: spectests emtests clean build install lint precommit docs examples
# Generate files # Generate files
generate-spectests: generate-spectests:
@ -111,12 +111,16 @@ test: spectests emtests middleware wasitests circleci-clean test-rest
# Integration tests # Integration tests
integration-tests: release-clif integration-tests: release-clif examples
echo "Running Integration Tests" echo "Running Integration Tests"
./integration_tests/lua/test.sh ./integration_tests/lua/test.sh
./integration_tests/nginx/test.sh ./integration_tests/nginx/test.sh
./integration_tests/cowsay/test.sh ./integration_tests/cowsay/test.sh
examples:
cargo run --example plugin
cargo run --example callback
# Utils # Utils
lint: lint:

View File

@ -0,0 +1,5 @@
# Call back guest
This is part of the `callback` example. This Wasm module passes host imports and its own functions to the Wasm host to execute.
See `examples/callback.rs` for the host

View File

@ -0,0 +1,24 @@
extern "C" {
fn call_guest_fn(f: u32) -> u32;
fn call_guest_fn2(f: u32) -> u32;
fn host_callback() -> u32;
}
#[no_mangle]
fn test_callback() -> u32 {
42
}
#[no_mangle]
fn test_callback2() -> u32 {
45
}
fn main() {
unsafe { call_guest_fn(test_callback as usize as u32) };
unsafe { call_guest_fn(host_callback as usize as u32) };
unsafe { call_guest_fn(test_callback2 as usize as u32) };
unsafe { call_guest_fn2(test_callback2 as usize as u32) };
unsafe { call_guest_fn2(test_callback as usize as u32) };
unsafe { call_guest_fn2(host_callback as usize as u32) };
}

Binary file not shown.

46
examples/callback.rs Normal file
View File

@ -0,0 +1,46 @@
/// This example demonstrates the use of callbacks: calling functions (Host and Wasm)
/// passed to us from the Wasm via hostcall
use wasmer_runtime::{compile_with, compiler_for_backend, func, imports, Backend, Ctx};
use wasmer_runtime_core::{structures::TypedIndex, types::TableIndex};
static WASM: &'static str = "examples/callback-guest/callback-guest.wasm";
/// This function matches our arbitrarily decided callback signature
/// in this example we'll only call functions that take no arguments and return one value
fn host_callback(_ctx: &mut Ctx) -> u32 {
55
}
fn call_guest_fn(ctx: &mut Ctx, guest_fn: u32) -> u32 {
// We get a TableIndex from our raw value passed in
let guest_fn_typed = TableIndex::new(guest_fn as usize);
// and use it to call the corresponding function
let result = ctx.call_with_table_index(guest_fn_typed, &[]).unwrap();
println!("Guest fn {} returned {:?}", guest_fn, result);
0
}
fn main() {
let wasm_bytes =
std::fs::read(WASM).expect(&format!("Could not read in WASM plugin at {}", WASM));
let imports = imports! {
"env" => {
"call_guest_fn" => func!(call_guest_fn),
"call_guest_fn2" => func!(call_guest_fn),
"host_callback" => func!(host_callback),
},
};
let compiler = compiler_for_backend(Backend::default()).unwrap();
let module = compile_with(&wasm_bytes[..], compiler.as_ref()).unwrap();
let instance = module
.instantiate(&imports)
.expect("failed to instantiate wasm module");
let entry_point = instance.func::<(u32, u32), u32>("main").unwrap();
entry_point.call(0, 0).expect("START");
}

View File

@ -12,14 +12,14 @@ pub use self::windows::*;
use libc::c_char; use libc::c_char;
use crate::{allocate_on_stack, EmscriptenData}; use crate::{
allocate_on_stack,
ptr::{Array, WasmPtr},
EmscriptenData,
};
use std::os::raw::c_int; use std::os::raw::c_int;
use wasmer_runtime_core::{ use wasmer_runtime_core::{types::ValueType, vm::Ctx};
memory::ptr::{Array, WasmPtr},
types::ValueType,
vm::Ctx,
};
pub fn call_malloc(ctx: &mut Ctx, size: u32) -> u32 { pub fn call_malloc(ctx: &mut Ctx, size: u32) -> u32 {
get_emscripten_data(ctx) get_emscripten_data(ctx)

View File

@ -9,11 +9,9 @@ use std::mem;
use std::os::raw::c_char; use std::os::raw::c_char;
use crate::env::{call_malloc, call_malloc_with_cast, EmAddrInfo, EmSockAddr}; use crate::env::{call_malloc, call_malloc_with_cast, EmAddrInfo, EmSockAddr};
use crate::ptr::{Array, WasmPtr};
use crate::utils::{copy_cstr_into_wasm, copy_terminated_array_of_cstrs}; use crate::utils::{copy_cstr_into_wasm, copy_terminated_array_of_cstrs};
use wasmer_runtime_core::{ use wasmer_runtime_core::vm::Ctx;
memory::ptr::{Array, WasmPtr},
vm::Ctx,
};
// #[no_mangle] // #[no_mangle]
/// emscripten: _getenv // (name: *const char) -> *const c_char; /// emscripten: _getenv // (name: *const char) -> *const c_char;

View File

@ -6,8 +6,9 @@ use std::mem;
use std::os::raw::c_char; use std::os::raw::c_char;
use crate::env::{call_malloc, EmAddrInfo}; use crate::env::{call_malloc, EmAddrInfo};
use crate::ptr::WasmPtr;
use crate::utils::{copy_cstr_into_wasm, read_string_from_wasm}; use crate::utils::{copy_cstr_into_wasm, read_string_from_wasm};
use wasmer_runtime_core::{memory::ptr::WasmPtr, vm::Ctx}; use wasmer_runtime_core::vm::Ctx;
extern "C" { extern "C" {
#[link_name = "_putenv"] #[link_name = "_putenv"]

View File

@ -62,6 +62,7 @@ mod math;
mod memory; mod memory;
mod process; mod process;
mod pthread; mod pthread;
mod ptr;
mod signal; mod signal;
mod storage; mod storage;
mod syscalls; mod syscalls;

116
lib/emscripten/src/ptr.rs Normal file
View File

@ -0,0 +1,116 @@
//! This is a wrapper around the `WasmPtr` abstraction that does not allow deref of address 0
//! This is a common assumption in Emscripten code
// this is a wrapper with extra logic around the runtime-core `WasmPtr`, so we
// don't want to warn about unusued code here
#![allow(dead_code)]
use std::{cell::Cell, fmt};
pub use wasmer_runtime_core::memory::ptr::Array;
use wasmer_runtime_core::{
memory::{ptr, Memory},
types::{ValueType, WasmExternType},
};
#[repr(transparent)]
pub struct WasmPtr<T: Copy, Ty = ptr::Item>(ptr::WasmPtr<T, Ty>);
unsafe impl<T: Copy, Ty> ValueType for WasmPtr<T, Ty> {}
impl<T: Copy, Ty> Copy for WasmPtr<T, Ty> {}
impl<T: Copy, Ty> Clone for WasmPtr<T, Ty> {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}
impl<T: Copy, Ty> fmt::Debug for WasmPtr<T, Ty> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self.0)
}
}
unsafe impl<T: Copy, Ty> WasmExternType for WasmPtr<T, Ty> {
type Native = <ptr::WasmPtr<T, Ty> as WasmExternType>::Native;
fn to_native(self) -> Self::Native {
self.0.to_native()
}
fn from_native(n: Self::Native) -> Self {
Self(ptr::WasmPtr::from_native(n))
}
}
impl<T: Copy, Ty> PartialEq for WasmPtr<T, Ty> {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl<T: Copy, Ty> Eq for WasmPtr<T, Ty> {}
impl<T: Copy, Ty> WasmPtr<T, Ty> {
#[inline(always)]
pub fn new(offset: u32) -> Self {
Self(ptr::WasmPtr::new(offset))
}
#[inline(always)]
pub fn offset(self) -> u32 {
self.0.offset()
}
}
impl<T: Copy + ValueType> WasmPtr<T, ptr::Item> {
#[inline(always)]
pub fn deref<'a>(self, memory: &'a Memory) -> Option<&'a Cell<T>> {
if self.0.offset() == 0 {
None
} else {
self.0.deref(memory)
}
}
#[inline(always)]
pub unsafe fn deref_mut<'a>(self, memory: &'a Memory) -> Option<&'a mut Cell<T>> {
if self.0.offset() == 0 {
None
} else {
self.0.deref_mut(memory)
}
}
}
impl<T: Copy + ValueType> WasmPtr<T, ptr::Array> {
#[inline(always)]
pub fn deref<'a>(self, memory: &'a Memory, index: u32, length: u32) -> Option<&'a [Cell<T>]> {
if self.0.offset() == 0 {
None
} else {
self.0.deref(memory, index, length)
}
}
#[inline]
pub unsafe fn deref_mut<'a>(
self,
memory: &'a Memory,
index: u32,
length: u32,
) -> Option<&'a mut [Cell<T>]> {
if self.0.offset() == 0 {
None
} else {
self.0.deref_mut(memory, index, length)
}
}
#[inline(always)]
pub fn get_utf8_string<'a>(self, memory: &'a Memory, str_len: u32) -> Option<&'a str> {
if self.0.offset() == 0 {
None
} else {
self.0.get_utf8_string(memory, str_len)
}
}
}

View File

@ -10,7 +10,10 @@ pub use self::unix::*;
#[cfg(windows)] #[cfg(windows)]
pub use self::windows::*; pub use self::windows::*;
use crate::utils::{copy_stat_into_wasm, get_cstr_path, get_current_directory}; use crate::{
ptr::{Array, WasmPtr},
utils::{copy_stat_into_wasm, get_cstr_path, get_current_directory},
};
use super::varargs::VarArgs; use super::varargs::VarArgs;
use byteorder::{ByteOrder, LittleEndian}; use byteorder::{ByteOrder, LittleEndian};
@ -40,10 +43,7 @@ use libc::{
write, write,
// ENOTTY, // ENOTTY,
}; };
use wasmer_runtime_core::{ use wasmer_runtime_core::vm::Ctx;
memory::ptr::{Array, WasmPtr},
vm::Ctx,
};
use super::env; use super::env;
use std::cell::Cell; use std::cell::Cell;

View File

@ -1,4 +1,4 @@
use crate::varargs::VarArgs; use crate::{ptr::WasmPtr, varargs::VarArgs};
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
use libc::size_t; use libc::size_t;
/// NOTE: TODO: These syscalls only support wasm_32 for now because they assume offsets are u32 /// NOTE: TODO: These syscalls only support wasm_32 for now because they assume offsets are u32
@ -111,7 +111,7 @@ fn translate_ioctl(wasm_ioctl: u32) -> c_ulong {
#[allow(unused_imports)] #[allow(unused_imports)]
use std::ffi::CStr; use std::ffi::CStr;
use wasmer_runtime_core::{memory::ptr::WasmPtr, vm::Ctx}; use wasmer_runtime_core::vm::Ctx;
use crate::env::EmSockAddr; use crate::env::EmSockAddr;
use crate::utils::{self, get_cstr_path}; use crate::utils::{self, get_cstr_path};

View File

@ -1176,7 +1176,11 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
BasicTypeEnum::FloatType(float_ty) => { BasicTypeEnum::FloatType(float_ty) => {
float_ty.const_float(0.0).as_basic_value_enum() float_ty.const_float(0.0).as_basic_value_enum()
} }
_ => unimplemented!(), _ => {
return Err(CodegenError {
message: "Operator::End phi type unimplemented".to_string(),
});
}
}; };
state.push1(placeholder_value); state.push1(placeholder_value);
phi.as_instruction().erase_from_basic_block(); phi.as_instruction().erase_from_basic_block();
@ -1741,7 +1745,12 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
_ => value, _ => value,
}); });
} }
_ => unimplemented!("multi-value returns"), _ => {
return Err(CodegenError {
message: "Operator::CallIndirect multi-value returns unimplemented"
.to_string(),
});
}
} }
} }
@ -6853,7 +6862,9 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
state.push1(result.try_as_basic_value().left().unwrap()); state.push1(result.try_as_basic_value().left().unwrap());
} }
_ => { _ => {
unimplemented!("{:?}", op); return Err(CodegenError {
message: format!("Operator {:?} unimplemented", op),
});
} }
} }
@ -6876,7 +6887,11 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
"return", "return",
))); )));
} }
_ => unimplemented!("multi-value returns not yet implemented"), _ => {
return Err(CodegenError {
message: "multi-value returns not yet implemented".to_string(),
});
}
} }
Ok(()) Ok(())
} }
@ -7051,7 +7066,10 @@ impl ModuleCodeGenerator<LLVMFunctionCodeGenerator, LLVMBackend, CodegenError>
self.context.as_ref().unwrap(), self.context.as_ref().unwrap(),
self.builder.as_ref().unwrap(), self.builder.as_ref().unwrap(),
self.intrinsics.as_ref().unwrap(), self.intrinsics.as_ref().unwrap(),
); )
.map_err(|e| CodegenError {
message: format!("trampolines generation error: {:?}", e),
})?;
if let Some(path) = unsafe { &crate::GLOBAL_OPTIONS.pre_opt_ir } { if let Some(path) = unsafe { &crate::GLOBAL_OPTIONS.pre_opt_ir } {
self.module.print_to_file(path).unwrap(); self.module.print_to_file(path).unwrap();

View File

@ -20,7 +20,7 @@ pub fn generate_trampolines(
context: &Context, context: &Context,
builder: &Builder, builder: &Builder,
intrinsics: &Intrinsics, intrinsics: &Intrinsics,
) { ) -> Result<(), String> {
for (sig_index, sig) in info.signatures.iter() { for (sig_index, sig) in info.signatures.iter() {
let func_type = signatures[sig_index]; let func_type = signatures[sig_index];
@ -42,8 +42,9 @@ pub fn generate_trampolines(
Some(Linkage::External), Some(Linkage::External),
); );
generate_trampoline(trampoline_func, sig, context, builder, intrinsics); generate_trampoline(trampoline_func, sig, context, builder, intrinsics)?;
} }
Ok(())
} }
fn generate_trampoline( fn generate_trampoline(
@ -52,7 +53,7 @@ fn generate_trampoline(
context: &Context, context: &Context,
builder: &Builder, builder: &Builder,
intrinsics: &Intrinsics, intrinsics: &Intrinsics,
) { ) -> Result<(), String> {
let entry_block = context.append_basic_block(&trampoline_func, "entry"); let entry_block = context.append_basic_block(&trampoline_func, "entry");
builder.position_at_end(&entry_block); builder.position_at_end(&entry_block);
@ -64,7 +65,7 @@ fn generate_trampoline(
args_ptr.into_pointer_value(), args_ptr.into_pointer_value(),
returns_ptr.into_pointer_value(), returns_ptr.into_pointer_value(),
), ),
_ => unimplemented!(), _ => return Err("trampoline function unimplemented".to_string()),
}; };
let cast_ptr_ty = |wasmer_ty| match wasmer_ty { let cast_ptr_ty = |wasmer_ty| match wasmer_ty {
@ -108,8 +109,11 @@ fn generate_trampoline(
call_site.try_as_basic_value().left().unwrap(), call_site.try_as_basic_value().left().unwrap(),
); );
} }
_ => unimplemented!("multi-value returns"), _ => {
return Err("trampoline function multi-value returns unimplemented".to_string());
}
} }
builder.build_return(None); builder.build_return(None);
Ok(())
} }

View File

@ -242,7 +242,7 @@ int main()
wasmer_result_t call_result = wasmer_export_func_call(exported_function, inputs, inputs_arity, outputs, outputs_arity); wasmer_result_t call_result = wasmer_export_func_call(exported_function, inputs, inputs_arity, outputs, outputs_arity);
printf("Result: %lld\n", outputs[0].value.I64); printf("Result: %ld\n", outputs[0].value.I64);
assert(outputs[0].value.I64 == 7); assert(outputs[0].value.I64 == 7);
assert(call_result == WASMER_OK); assert(call_result == WASMER_OK);

View File

@ -18,7 +18,6 @@ libc = "0.2.60"
hex = "0.3.2" hex = "0.3.2"
smallvec = "0.6.10" smallvec = "0.6.10"
bincode = "1.1" bincode = "1.1"
colored = "1.8"
[dependencies.indexmap] [dependencies.indexmap]
version = "1.2.0" version = "1.2.0"

View File

@ -283,13 +283,10 @@ extern "C" fn signal_trap_handler(
let image = build_instance_image(ctx, es_image); let image = build_instance_image(ctx, es_image);
unwind_result = Box::new(image); unwind_result = Box::new(image);
} else { } else {
use colored::*;
if es_image.frames.len() > 0 { if es_image.frames.len() > 0 {
eprintln!( eprintln!(
"\n{}", "\n{}",
"Wasmer encountered an error while running your WebAssembly program." "Wasmer encountered an error while running your WebAssembly program."
.bold()
.red()
); );
es_image.print_backtrace_if_needed(); es_image.print_backtrace_if_needed();
} }

View File

@ -530,29 +530,12 @@ fn call_func_with_index(
args: &[Value], args: &[Value],
rets: &mut Vec<Value>, rets: &mut Vec<Value>,
) -> CallResult<()> { ) -> CallResult<()> {
rets.clear();
let sig_index = *info let sig_index = *info
.func_assoc .func_assoc
.get(func_index) .get(func_index)
.expect("broken invariant, incorrect func index"); .expect("broken invariant, incorrect func index");
let signature = &info.signatures[sig_index]; let signature = &info.signatures[sig_index];
let num_results = signature.returns().len();
let num_results = num_results
+ signature
.returns()
.iter()
.filter(|&&ty| ty == Type::V128)
.count();
rets.reserve(num_results);
if !signature.check_param_value_types(args) {
Err(ResolveError::Signature {
expected: signature.clone(),
found: args.iter().map(|val| val.ty()).collect(),
})?
}
let func_ptr = match func_index.local_or_import(info) { let func_ptr = match func_index.local_or_import(info) {
LocalOrImport::Local(local_func_index) => { LocalOrImport::Local(local_func_index) => {
@ -570,6 +553,39 @@ fn call_func_with_index(
} }
}; };
let wasm = runnable
.get_trampoline(info, sig_index)
.expect("wasm trampoline");
call_func_with_index_inner(ctx_ptr, func_ptr, signature, wasm, args, rets)
}
pub(crate) fn call_func_with_index_inner(
ctx_ptr: *mut vm::Ctx,
func_ptr: NonNull<vm::Func>,
signature: &FuncSig,
wasm: Wasm,
args: &[Value],
rets: &mut Vec<Value>,
) -> CallResult<()> {
rets.clear();
let num_results = signature.returns().len();
let num_results = num_results
+ signature
.returns()
.iter()
.filter(|&&ty| ty == Type::V128)
.count();
rets.reserve(num_results);
if !signature.check_param_value_types(args) {
Err(ResolveError::Signature {
expected: signature.clone(),
found: args.iter().map(|val| val.ty()).collect(),
})?
}
let mut raw_args: SmallVec<[u64; 8]> = SmallVec::new(); let mut raw_args: SmallVec<[u64; 8]> = SmallVec::new();
for v in args { for v in args {
match v { match v {
@ -601,9 +617,7 @@ fn call_func_with_index(
trampoline, trampoline,
invoke, invoke,
invoke_env, invoke_env,
} = runnable } = wasm;
.get_trampoline(info, sig_index)
.expect("wasm trampoline");
let run_wasm = |result_space: *mut u64| unsafe { let run_wasm = |result_space: *mut u64| unsafe {
let mut trap_info = WasmTrapInfo::Unknown; let mut trap_info = WasmTrapInfo::Unknown;

View File

@ -46,9 +46,7 @@ fn align_pointer(ptr: usize, align: usize) -> usize {
impl<T: Copy + ValueType> WasmPtr<T, Item> { impl<T: Copy + ValueType> WasmPtr<T, Item> {
#[inline] #[inline]
pub fn deref<'a>(self, memory: &'a Memory) -> Option<&'a Cell<T>> { pub fn deref<'a>(self, memory: &'a Memory) -> Option<&'a Cell<T>> {
if self.offset == 0 if (self.offset as usize) + mem::size_of::<T>() >= memory.size().bytes().0 {
|| (self.offset as usize) + mem::size_of::<T>() >= memory.size().bytes().0
{
return None; return None;
} }
unsafe { unsafe {
@ -62,9 +60,7 @@ impl<T: Copy + ValueType> WasmPtr<T, Item> {
#[inline] #[inline]
pub unsafe fn deref_mut<'a>(self, memory: &'a Memory) -> Option<&'a mut Cell<T>> { pub unsafe fn deref_mut<'a>(self, memory: &'a Memory) -> Option<&'a mut Cell<T>> {
if self.offset == 0 if (self.offset as usize) + mem::size_of::<T>() >= memory.size().bytes().0 {
|| (self.offset as usize) + mem::size_of::<T>() >= memory.size().bytes().0
{
return None; return None;
} }
let cell_ptr = align_pointer( let cell_ptr = align_pointer(
@ -83,9 +79,7 @@ impl<T: Copy + ValueType> WasmPtr<T, Array> {
let item_size = mem::size_of::<T>() + (mem::size_of::<T>() % mem::align_of::<T>()); let item_size = mem::size_of::<T>() + (mem::size_of::<T>() % mem::align_of::<T>());
let slice_full_len = index as usize + length as usize; let slice_full_len = index as usize + length as usize;
if self.offset == 0 if (self.offset as usize) + (item_size * slice_full_len) >= memory.size().bytes().0 {
|| (self.offset as usize) + (item_size * slice_full_len) >= memory.size().bytes().0
{
return None; return None;
} }
@ -112,9 +106,7 @@ impl<T: Copy + ValueType> WasmPtr<T, Array> {
let item_size = mem::size_of::<T>() + (mem::size_of::<T>() % mem::align_of::<T>()); let item_size = mem::size_of::<T>() + (mem::size_of::<T>() % mem::align_of::<T>());
let slice_full_len = index as usize + length as usize; let slice_full_len = index as usize + length as usize;
if self.offset == 0 if (self.offset as usize) + (item_size * slice_full_len) >= memory.size().bytes().0 {
|| (self.offset as usize) + (item_size * slice_full_len) >= memory.size().bytes().0
{
return None; return None;
} }

View File

@ -392,14 +392,19 @@ pub fn read_module<
} }
pub fn wp_type_to_type(ty: WpType) -> Result<Type, BinaryReaderError> { pub fn wp_type_to_type(ty: WpType) -> Result<Type, BinaryReaderError> {
Ok(match ty { match ty {
WpType::I32 => Type::I32, WpType::I32 => Ok(Type::I32),
WpType::I64 => Type::I64, WpType::I64 => Ok(Type::I64),
WpType::F32 => Type::F32, WpType::F32 => Ok(Type::F32),
WpType::F64 => Type::F64, WpType::F64 => Ok(Type::F64),
WpType::V128 => Type::V128, WpType::V128 => Ok(Type::V128),
_ => panic!("broken invariant, invalid type"), _ => {
}) return Err(BinaryReaderError {
message: "broken invariant, invalid type",
offset: -1isize as usize,
});
}
}
} }
pub fn type_to_wp_type(ty: Type) -> WpType { pub fn type_to_wp_type(ty: Type) -> WpType {

View File

@ -303,7 +303,7 @@ impl ExecutionStateImage {
if let Ok(x) = env::var("WASMER_BACKTRACE") { if let Ok(x) = env::var("WASMER_BACKTRACE") {
if x == "1" { if x == "1" {
eprintln!("{}", self.colored_output()); eprintln!("{}", self.output());
return; return;
} }
} }
@ -311,9 +311,7 @@ impl ExecutionStateImage {
eprintln!("Run with `WASMER_BACKTRACE=1` environment variable to display a backtrace."); eprintln!("Run with `WASMER_BACKTRACE=1` environment variable to display a backtrace.");
} }
pub fn colored_output(&self) -> String { pub fn output(&self) -> String {
use colored::*;
fn join_strings(x: impl Iterator<Item = String>, sep: &str) -> String { fn join_strings(x: impl Iterator<Item = String>, sep: &str) -> String {
let mut ret = String::new(); let mut ret = String::new();
let mut first = true; let mut first = true;
@ -341,8 +339,6 @@ impl ExecutionStateImage {
i, i,
x.map(|x| format!("{}", x)) x.map(|x| format!("{}", x))
.unwrap_or_else(|| "?".to_string()) .unwrap_or_else(|| "?".to_string())
.bold()
.cyan()
) )
}), }),
", ", ", ",
@ -353,27 +349,23 @@ impl ExecutionStateImage {
let mut ret = String::new(); let mut ret = String::new();
if self.frames.len() == 0 { if self.frames.len() == 0 {
ret += &"Unknown fault address, cannot read stack.".yellow(); ret += &"Unknown fault address, cannot read stack.";
ret += "\n"; ret += "\n";
} else { } else {
ret += &"Backtrace:".bold(); ret += &"Backtrace:";
ret += "\n"; ret += "\n";
for (i, f) in self.frames.iter().enumerate() { for (i, f) in self.frames.iter().enumerate() {
ret += &format!("* Frame {} @ Local function {}", i, f.local_function_id).bold(); ret += &format!("* Frame {} @ Local function {}", i, f.local_function_id);
ret += "\n"; ret += "\n";
ret += &format!(" {} {}\n", "Offset:", format!("{}", f.wasm_inst_offset),);
ret += &format!( ret += &format!(
" {} {}\n", " {} {}\n",
"Offset:".bold().yellow(), "Locals:",
format!("{}", f.wasm_inst_offset).bold().cyan(),
);
ret += &format!(
" {} {}\n",
"Locals:".bold().yellow(),
format_optional_u64_sequence(&f.locals) format_optional_u64_sequence(&f.locals)
); );
ret += &format!( ret += &format!(
" {} {}\n\n", " {} {}\n\n",
"Stack:".bold().yellow(), "Stack:",
format_optional_u64_sequence(&f.stack) format_optional_u64_sequence(&f.stack)
); );
} }

View File

@ -44,7 +44,7 @@ impl<'a> From<DynFunc<'a>> for Anyfunc<'a> {
} }
pub struct AnyfuncTable { pub struct AnyfuncTable {
backing: Vec<vm::Anyfunc>, pub(crate) backing: Vec<vm::Anyfunc>,
max: Option<u32>, max: Option<u32>,
} }

View File

@ -13,7 +13,7 @@ use std::{
mod anyfunc; mod anyfunc;
pub use self::anyfunc::Anyfunc; pub use self::anyfunc::Anyfunc;
use self::anyfunc::AnyfuncTable; pub(crate) use self::anyfunc::AnyfuncTable;
use crate::error::GrowError; use crate::error::GrowError;
pub enum Element<'a> { pub enum Element<'a> {

View File

@ -1,15 +1,19 @@
pub use crate::backing::{ImportBacking, LocalBacking, INTERNALS_SIZE}; pub use crate::backing::{ImportBacking, LocalBacking, INTERNALS_SIZE};
use crate::{ use crate::{
error::CallResult,
instance::call_func_with_index_inner,
memory::{Memory, MemoryType}, memory::{Memory, MemoryType},
module::{ModuleInfo, ModuleInner}, module::{ModuleInfo, ModuleInner},
sig_registry::SigRegistry,
structures::TypedIndex, structures::TypedIndex,
types::{LocalOrImport, MemoryIndex}, types::{LocalOrImport, MemoryIndex, TableIndex, Value},
vmcalls, vmcalls,
}; };
use std::{ use std::{
cell::UnsafeCell, cell::UnsafeCell,
ffi::c_void, ffi::c_void,
mem, ptr, mem,
ptr::{self, NonNull},
sync::atomic::{AtomicUsize, Ordering}, sync::atomic::{AtomicUsize, Ordering},
sync::Once, sync::Once,
}; };
@ -393,6 +397,41 @@ impl Ctx {
(*self.internal.internals)[field.index()] = value; (*self.internal.internals)[field.index()] = value;
} }
} }
/// Calls a host or Wasm function at the given table index
pub fn call_with_table_index(
&mut self,
index: TableIndex,
args: &[Value],
) -> CallResult<Vec<Value>> {
let anyfunc_table =
unsafe { &*((**self.internal.tables).table as *mut crate::table::AnyfuncTable) };
let Anyfunc { func, ctx, sig_id } = anyfunc_table.backing[index.index()];
let signature = SigRegistry.lookup_signature(unsafe { std::mem::transmute(sig_id.0) });
let mut rets = vec![];
let wasm = {
let module = unsafe { &*self.module };
let runnable = &module.runnable_module;
let sig_index = SigRegistry.lookup_sig_index(signature.clone());
runnable
.get_trampoline(&module.info, sig_index)
.expect("wasm trampoline")
};
call_func_with_index_inner(
ctx,
NonNull::new(func as *mut _).unwrap(),
&signature,
wasm,
args,
&mut rets,
)?;
Ok(rets)
}
} }
#[doc(hidden)] #[doc(hidden)]

View File

@ -18,4 +18,3 @@ byteorder = "1.3.2"
nix = "0.15.0" nix = "0.15.0"
libc = "0.2.60" libc = "0.2.60"
smallvec = "0.6.10" smallvec = "0.6.10"
colored = "1.8"

View File

@ -863,7 +863,6 @@ llvm:skip:unwind.wast:*:windows
# LLVM Linux after OSR - https://github.com/wasmerio/wasmer/pull/567 # LLVM Linux after OSR - https://github.com/wasmerio/wasmer/pull/567
llvm:skip:simd.wast:352:unix # Module - caught panic Any llvm:skip:simd.wast:352:unix # Module - caught panic Any
llvm:skip:simd.wast:355:unix # Module - caught panic Any
llvm:skip:simd_binaryen.wast:*:unix # Module - caught panic Any llvm:skip:simd_binaryen.wast:*:unix # Module - caught panic Any

View File

@ -732,7 +732,7 @@ fn interactive_shell(mut ctx: InteractiveShellContext) -> ShellExitOperation {
} }
"backtrace" | "bt" => { "backtrace" | "bt" => {
if let Some(ref image) = ctx.image { if let Some(ref image) = ctx.image {
println!("{}", image.execution_state.colored_output()); println!("{}", image.execution_state.output());
} else { } else {
println!("State not available"); println!("State not available");
} }