From e6dd79a2fb5441102b2c52fa3ef1f7ff0a7301ef Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2020 20:59:11 +0000 Subject: [PATCH 01/19] Bump structopt from 0.3.5 to 0.3.7 Bumps [structopt](https://github.com/TeXitoi/structopt) from 0.3.5 to 0.3.7. - [Release notes](https://github.com/TeXitoi/structopt/releases) - [Changelog](https://github.com/TeXitoi/structopt/blob/master/CHANGELOG.md) - [Commits](https://github.com/TeXitoi/structopt/compare/v0.3.5...v0.3.7) Signed-off-by: dependabot-preview[bot] --- Cargo.lock | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0f5d6d7c81c..8f2365de818 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -901,15 +901,30 @@ checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" [[package]] name = "proc-macro-error" -version = "0.2.6" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aeccfe4d5d8ea175d5f0e4a2ad0637e0f4121d63bd99d356fb1f39ab2e7c6097" +checksum = "53c98547ceaea14eeb26fcadf51dc70d01a2479a7839170eae133721105e4428" dependencies = [ + "proc-macro-error-attr", "proc-macro2 1.0.6", "quote 1.0.2", + "rustversion", "syn 1.0.11", ] +[[package]] +name = "proc-macro-error-attr" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2bf5d493cf5d3e296beccfd61794e445e830dfc8070a9c248ad3ee071392c6c" +dependencies = [ + "proc-macro2 1.0.6", + "quote 1.0.2", + "rustversion", + "syn 1.0.11", + "syn-mid", +] + [[package]] name = "proc-macro2" version = "0.4.30" @@ -1204,6 +1219,17 @@ dependencies = [ "semver", ] +[[package]] +name = "rustversion" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a0538bd897e17257b0128d2fd95c2ed6df939374073a36166051a79e2eb7986" +dependencies = [ + "proc-macro2 1.0.6", + "quote 1.0.2", + "syn 1.0.11", +] + [[package]] name = "ryu" version = "1.0.2" @@ -1364,9 +1390,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "structopt" -version = "0.3.5" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30b3a3e93f5ad553c38b3301c8a0a0cec829a36783f6a0c467fc4bf553a5f5bf" +checksum = "884ae79d6aad1e738f4a70dff314203fd498490a63ebc4d03ea83323c40b7b72" dependencies = [ "clap", "structopt-derive", @@ -1374,9 +1400,9 @@ dependencies = [ [[package]] name = "structopt-derive" -version = "0.3.5" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea692d40005b3ceba90a9fe7a78fa8d4b82b0ce627eebbffc329aab850f3410e" +checksum = "0a97f829a34a0a9d5b353a881025a23b8c9fd09d46be6045df6b22920dbd7a93" dependencies = [ "heck", "proc-macro-error", @@ -1407,6 +1433,17 @@ dependencies = [ "unicode-xid 0.2.0", ] +[[package]] +name = "syn-mid" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fd3937748a7eccff61ba5b90af1a20dbf610858923a9192ea0ecb0cb77db1d0" +dependencies = [ + "proc-macro2 1.0.6", + "quote 1.0.2", + "syn 1.0.11", +] + [[package]] name = "target-lexicon" version = "0.9.0" From f134f01983de64ed5655b6cc808e06dba9d124d8 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2020 20:59:13 +0000 Subject: [PATCH 02/19] Bump smallvec from 0.6.13 to 1.1.0 Bumps [smallvec](https://github.com/servo/rust-smallvec) from 0.6.13 to 1.1.0. - [Release notes](https://github.com/servo/rust-smallvec/releases) - [Commits](https://github.com/servo/rust-smallvec/compare/v0.6.13...v1.1.0) Signed-off-by: dependabot-preview[bot] --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0f5d6d7c81c..fad7151e433 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1708,7 +1708,7 @@ dependencies = [ "regex", "rustc_version", "semver", - "smallvec 0.6.13", + "smallvec 1.1.0", "wabt", "wasmer-runtime-core", "wasmparser", @@ -1793,7 +1793,7 @@ dependencies = [ "serde-bench", "serde_bytes", "serde_derive", - "smallvec 0.6.13", + "smallvec 1.1.0", "wasmparser", "winapi", ] @@ -1822,7 +1822,7 @@ dependencies = [ "nix", "serde", "serde_derive", - "smallvec 0.6.13", + "smallvec 1.1.0", "wasmer-runtime-core", ] From 37a3a15ea8d08d7f43f743cccdf71e7f8ee7b192 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2020 20:59:14 +0000 Subject: [PATCH 03/19] Bump generational-arena from 0.2.6 to 0.2.7 Bumps [generational-arena](https://github.com/fitzgen/generational-arena) from 0.2.6 to 0.2.7. - [Release notes](https://github.com/fitzgen/generational-arena/releases) - [Changelog](https://github.com/fitzgen/generational-arena/blob/master/CHANGELOG.md) - [Commits](https://github.com/fitzgen/generational-arena/compare/0.2.6...0.2.7) Signed-off-by: dependabot-preview[bot] --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0f5d6d7c81c..c9354a8f07f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -452,9 +452,9 @@ checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" [[package]] name = "generational-arena" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "675c9623fbcdb4b402176db720bf5d95883a36303703ed1bd3a03482382f735a" +checksum = "0e40d0cee2e2fb4fba18b55a27bf96faf49fa86d49f178695bd3bf4500b156b4" dependencies = [ "cfg-if", "serde", From 6e52685b642df84296c5630ab2c69a86f1b2e751 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2020 20:59:17 +0000 Subject: [PATCH 04/19] Bump blake2b_simd from 0.5.9 to 0.5.10 Bumps [blake2b_simd](https://github.com/oconnor663/blake2_simd) from 0.5.9 to 0.5.10. - [Release notes](https://github.com/oconnor663/blake2_simd/releases) - [Commits](https://github.com/oconnor663/blake2_simd/compare/0.5.9...0.5.10) Signed-off-by: dependabot-preview[bot] --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0f5d6d7c81c..c9dd23116b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -64,9 +64,9 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "blake2b_simd" -version = "0.5.9" +version = "0.5.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b83b7baab1e671718d78204225800d6b170e648188ac7dc992e9d6bddf87d0c0" +checksum = "d8fb2d74254a3a0b5cac33ac9f8ed0e44aa50378d9dbb2e5d83bd21ed1dc2c8a" dependencies = [ "arrayref", "arrayvec", From 8f694dab54e0ca9751a560135941dd2179c7230c Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2020 20:59:17 +0000 Subject: [PATCH 05/19] Bump rayon from 1.2.1 to 1.3.0 Bumps [rayon](https://github.com/rayon-rs/rayon) from 1.2.1 to 1.3.0. - [Release notes](https://github.com/rayon-rs/rayon/releases) - [Changelog](https://github.com/rayon-rs/rayon/blob/master/RELEASES.md) - [Commits](https://github.com/rayon-rs/rayon/compare/rayon-core-v1.2.1...rayon-core-v1.3.0) Signed-off-by: dependabot-preview[bot] --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0f5d6d7c81c..afaba470d29 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1116,9 +1116,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43739f8831493b276363637423d3622d4bd6394ab6f0a9c4a552e208aeb7fddd" +checksum = "db6ce3297f9c85e16621bb8cca38a06779ffc31bb8184e1be4bed2be4678a098" dependencies = [ "crossbeam-deque", "either", @@ -1127,9 +1127,9 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8bf17de6f23b05473c437eb958b9c850bfc8af0961fe17b4cc92d5a627b4791" +checksum = "08a89b46efaf957e52b18062fb2f4660f8b8a4dde1807ca002690868ef2c85a9" dependencies = [ "crossbeam-deque", "crossbeam-queue", From 078242b55b502ef926c15f9f1053e4c60eca0425 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 7 Jan 2020 12:04:50 -0500 Subject: [PATCH 06/19] Add test for ImportObject's `allow_missing_functions` --- lib/runtime/tests/allow_missing_functions.rs | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 lib/runtime/tests/allow_missing_functions.rs diff --git a/lib/runtime/tests/allow_missing_functions.rs b/lib/runtime/tests/allow_missing_functions.rs new file mode 100644 index 00000000000..152634cf484 --- /dev/null +++ b/lib/runtime/tests/allow_missing_functions.rs @@ -0,0 +1,24 @@ +#[test] +fn allow_missing() { + use wabt::wat2wasm; + use wasmer_runtime::{imports, instantiate}; + + static WAT: &'static str = r#" + (module + (type (;0;) (func)) + (type (;1;) (func (result i32))) + (import "env" "ret_err" (func $ret_err (type 0))) + (func $get_num (type 1) + i32.const 42 + ) + (export "get_num" (func $get_num)) + ) + "#; + + let wasm = wat2wasm(WAT).unwrap(); + + let mut import_object = imports! {}; + import_object.allow_missing_functions = true; + + assert!(instantiate(&wasm, &import_object).is_ok()); +} From b31a3dcdec8e71c1e1b5479015b890bad7eef669 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Wed, 8 Jan 2020 15:02:57 +0100 Subject: [PATCH 07/19] feat(runtime-c-api) Define the `DEPRECATED` macro. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR defines a cross-compiler `DEPRECATED(message)` macro. It must be used as follows in Rust: ```rust /// This is a documentation. /// cbindgen:prefix=DEPRECATED(This is a deprecation message.") pub extern "C" fn wasmer_foo() -> c_uint { 42 } ``` It will generate the following C header: ```c /** * This is a documentation. */ DEPRECATED("This is a deprecation message.") unsigned int wasmer_foo(); ``` And once this code is used by a C compiler, it will print something like this (example from Clang): ``` …/test.c:…:…: error: 'wasmer_foo' is deprecated: This is a deprecation message. [-Werror,-Wdeprecated-declarations] unsigned int x = wasmer_foo(); ^ …/wasmer.h:…:…: note: 'wasmer_foo' has been explicitly marked deprecated here DEPRECATED("This is a deprecation message.") ^ …/wasmer.h:…:…: note: expanded from macro 'DEPRECATED' ``` This is required for further deprecations. --- lib/runtime-c-api/build.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/runtime-c-api/build.rs b/lib/runtime-c-api/build.rs index 3b54a6c4214..6e8af3fc533 100644 --- a/lib/runtime-c-api/build.rs +++ b/lib/runtime-c-api/build.rs @@ -14,18 +14,21 @@ fn main() { let mut pre_header = r#" #if !defined(WASMER_H_MACROS) + #define WASMER_H_MACROS -#if defined(MSVC) -#if defined(_M_AMD64) -#define ARCH_X86_64 -#endif +// Define the `ARCH_X86_X64` constant. +#if defined(MSVC) && defined(_M_AMD64) +# define ARCH_X86_64 +#elif (defined(GCC) || defined(__GNUC__) || defined(__clang__)) && defined(__x86_64__) +# define ARCH_X86_64 #endif +// Define the `DEPRECATED` macro. #if defined(GCC) || defined(__GNUC__) || defined(__clang__) -#if defined(__x86_64__) -#define ARCH_X86_64 -#endif +# define DEPRECATED(message) __attribute__((deprecated(message))) +#elif defined(MSVC) +# define DEPRECATED(message) __declspec(deprecated(message)) #endif "# @@ -41,7 +44,7 @@ fn main() { pre_header += "#define WASMER_EMSCRIPTEN_ENABLED\n"; } - // close pre header + // Close pre header. pre_header += "#endif // WASMER_H_MACROS\n"; // Generate the C bindings in the `OUT_DIR`. From 4f691dde175e31b34c7ad938e3340516fdb00e2e Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Wed, 8 Jan 2020 15:25:48 +0100 Subject: [PATCH 08/19] chore(runtime-c-api) Update headers. --- lib/runtime-c-api/wasmer.h | 17 ++++++++++------- lib/runtime-c-api/wasmer.hh | 17 ++++++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index 5bb86b42212..cb69a2c68ce 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -1,17 +1,20 @@ #if !defined(WASMER_H_MACROS) + #define WASMER_H_MACROS -#if defined(MSVC) -#if defined(_M_AMD64) -#define ARCH_X86_64 -#endif +// Define the `ARCH_X86_X64` constant. +#if defined(MSVC) && defined(_M_AMD64) +# define ARCH_X86_64 +#elif (defined(GCC) || defined(__GNUC__) || defined(__clang__)) && defined(__x86_64__) +# define ARCH_X86_64 #endif +// Define the `DEPRECATED` macro. #if defined(GCC) || defined(__GNUC__) || defined(__clang__) -#if defined(__x86_64__) -#define ARCH_X86_64 -#endif +# define DEPRECATED(message) __attribute__((deprecated(message))) +#elif defined(MSVC) +# define DEPRECATED(message) __declspec(deprecated(message)) #endif #define WASMER_WASI_ENABLED diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index fe0fcd7f546..00b3c287a78 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -1,17 +1,20 @@ #if !defined(WASMER_H_MACROS) + #define WASMER_H_MACROS -#if defined(MSVC) -#if defined(_M_AMD64) -#define ARCH_X86_64 -#endif +// Define the `ARCH_X86_X64` constant. +#if defined(MSVC) && defined(_M_AMD64) +# define ARCH_X86_64 +#elif (defined(GCC) || defined(__GNUC__) || defined(__clang__)) && defined(__x86_64__) +# define ARCH_X86_64 #endif +// Define the `DEPRECATED` macro. #if defined(GCC) || defined(__GNUC__) || defined(__clang__) -#if defined(__x86_64__) -#define ARCH_X86_64 -#endif +# define DEPRECATED(message) __attribute__((deprecated(message))) +#elif defined(MSVC) +# define DEPRECATED(message) __declspec(deprecated(message)) #endif #define WASMER_WASI_ENABLED From 34bf88688355786a2b386c7426d3438760d84694 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Wed, 8 Jan 2020 13:37:29 -0500 Subject: [PATCH 09/19] Update wapm submodule to 0.4.2 --- wapm-cli | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wapm-cli b/wapm-cli index 3562d6dda52..e2d3eb18f30 160000 --- a/wapm-cli +++ b/wapm-cli @@ -1 +1 @@ -Subproject commit 3562d6dda52df526e6e1917dd33bb2454917ab9c +Subproject commit e2d3eb18f304e165b5840aebba1917f9d14c77b4 From 67b684ac8554480575bc21ca7b1d4f77fdd0a436 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 9 Jan 2020 10:13:22 +0100 Subject: [PATCH 10/19] feat(runtime-c-api) Improve `DEPRECATED` compatibility. Clang can emulate GNUC or MSVC behaviors. So instead of detecting whether Clang is used to compile the code, it's better to detect the targeted features are available. Code proposed by @nlewycky, thanks! --- lib/runtime-c-api/build.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/runtime-c-api/build.rs b/lib/runtime-c-api/build.rs index 6e8af3fc533..370d434a7cf 100644 --- a/lib/runtime-c-api/build.rs +++ b/lib/runtime-c-api/build.rs @@ -24,10 +24,20 @@ fn main() { # define ARCH_X86_64 #endif +// Compatibility with non-Clang compilers. +#if !defined(__has_attribute) +# define __has_attribute(x) 0 +#endif + +// Compatibility with non-Clang compilers. +#if !defined(__has_declspec_attribute) +# define __has_declspec_attribute(x) 0 +#endif + // Define the `DEPRECATED` macro. -#if defined(GCC) || defined(__GNUC__) || defined(__clang__) +#if defined(GCC) || defined(__GNUC__) || __has_attribute(deprecated) # define DEPRECATED(message) __attribute__((deprecated(message))) -#elif defined(MSVC) +#elif defined(MSVC) || __has_declspec_attribute(deprecated) # define DEPRECATED(message) __declspec(deprecated(message)) #endif From 7b6d8993e135af76a7bbd587c4a8e5d76b90fec0 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 9 Jan 2020 10:17:34 +0100 Subject: [PATCH 11/19] chore(runtime-c-api) Update C/C++ headers. --- lib/runtime-c-api/wasmer.h | 14 ++++++++++++-- lib/runtime-c-api/wasmer.hh | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index cb69a2c68ce..1c3bf4c7ea4 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -10,10 +10,20 @@ # define ARCH_X86_64 #endif +// Compatibility with non-Clang compilers. +#if !defined(__has_attribute) +# define __has_attribute(x) 0 +#endif + +// Compatibility with non-Clang compilers. +#if !defined(__has_declspec_attribute) +# define __has_declspec_attribute(x) 0 +#endif + // Define the `DEPRECATED` macro. -#if defined(GCC) || defined(__GNUC__) || defined(__clang__) +#if defined(GCC) || defined(__GNUC__) || __has_attribute(deprecated) # define DEPRECATED(message) __attribute__((deprecated(message))) -#elif defined(MSVC) +#elif defined(MSVC) || __has_declspec_attribute(deprecated) # define DEPRECATED(message) __declspec(deprecated(message)) #endif diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 00b3c287a78..0f4f44441a0 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -10,10 +10,20 @@ # define ARCH_X86_64 #endif +// Compatibility with non-Clang compilers. +#if !defined(__has_attribute) +# define __has_attribute(x) 0 +#endif + +// Compatibility with non-Clang compilers. +#if !defined(__has_declspec_attribute) +# define __has_declspec_attribute(x) 0 +#endif + // Define the `DEPRECATED` macro. -#if defined(GCC) || defined(__GNUC__) || defined(__clang__) +#if defined(GCC) || defined(__GNUC__) || __has_attribute(deprecated) # define DEPRECATED(message) __attribute__((deprecated(message))) -#elif defined(MSVC) +#elif defined(MSVC) || __has_declspec_attribute(deprecated) # define DEPRECATED(message) __declspec(deprecated(message)) #endif From f48a74e44ad9f088a33c563924408d91ebf6825f Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Thu, 9 Jan 2020 06:48:03 -0500 Subject: [PATCH 12/19] Set default scale on fb window to fit screen --- lib/wasi-experimental-io-devices/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wasi-experimental-io-devices/src/lib.rs b/lib/wasi-experimental-io-devices/src/lib.rs index d713a18af8c..b93ae4c8faf 100644 --- a/lib/wasi-experimental-io-devices/src/lib.rs +++ b/lib/wasi-experimental-io-devices/src/lib.rs @@ -81,7 +81,7 @@ impl FrameBufferState { y, WindowOptions { resize: true, - scale: Scale::X4, + scale: Scale::FitScreen, ..WindowOptions::default() }, ) From cd6e4bdaeeb93de5e3ac43e3c46bffcb3747619b Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 9 Jan 2020 15:10:23 +0100 Subject: [PATCH 13/19] test(runtime) Fix CS. --- lib/runtime/tests/error_propagation.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/runtime/tests/error_propagation.rs b/lib/runtime/tests/error_propagation.rs index 1b9f9fccfbf..44cfa3fd943 100644 --- a/lib/runtime/tests/error_propagation.rs +++ b/lib/runtime/tests/error_propagation.rs @@ -30,9 +30,9 @@ fn error_propagation() { let instance = module .instantiate(&imports! { - "env" => { - "ret_err" => Func::new(ret_err), - }, + "env" => { + "ret_err" => Func::new(ret_err), + }, }) .unwrap(); From 19c38378818780bd066b575d957be431b23d009f Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 9 Jan 2020 15:10:53 +0100 Subject: [PATCH 14/19] feat(runtime-core) Create the `always_trap` host function. --- lib/runtime-core/src/typed_func.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/runtime-core/src/typed_func.rs b/lib/runtime-core/src/typed_func.rs index a653725abf5..24f35bd6944 100644 --- a/lib/runtime-core/src/typed_func.rs +++ b/lib/runtime-core/src/typed_func.rs @@ -733,6 +733,12 @@ where } } +/// Function that always fails. It can be used as a placeholder when a +/// host function is missing for instance. +pub(crate) fn always_trap() -> Result<(), &'static str> { + Err("not implemented") +} + #[cfg(test)] mod tests { use super::*; From 6018aa32e1c90152b59f9e442cfeebf288f58229 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 9 Jan 2020 15:11:25 +0100 Subject: [PATCH 15/19] fix(runtime-core) Drop `vm::FuncCtx` if not null. --- lib/runtime-core/src/backing.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/runtime-core/src/backing.rs b/lib/runtime-core/src/backing.rs index 1b50abaf6ab..21fed0c42d9 100644 --- a/lib/runtime-core/src/backing.rs +++ b/lib/runtime-core/src/backing.rs @@ -563,7 +563,9 @@ impl Drop for ImportBacking { fn drop(&mut self) { // Properly drop the `vm::FuncCtx` in `vm::ImportedFunc`. for (_imported_func_index, imported_func) in (*self.vm_functions).iter_mut() { - let _: Box = unsafe { Box::from_raw(imported_func.func_ctx.as_ptr()) }; + if !imported_func.func_ctx.as_ptr().is_null() { + let _: Box = unsafe { Box::from_raw(imported_func.func_ctx.as_ptr()) }; + } } } } From c81e49a091847c7c5cfc37959f09b1ea4c361741 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 9 Jan 2020 15:12:09 +0100 Subject: [PATCH 16/19] feat(runtime-core) Replace missing host function by `always_trap`. --- lib/runtime-core/src/backing.rs | 20 +++++++++++++------- lib/runtime-core/src/typed_func.rs | 10 +++++----- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/runtime-core/src/backing.rs b/lib/runtime-core/src/backing.rs index 21fed0c42d9..437f5f724a9 100644 --- a/lib/runtime-core/src/backing.rs +++ b/lib/runtime-core/src/backing.rs @@ -8,6 +8,7 @@ use crate::{ sig_registry::SigRegistry, structures::{BoxedMap, Map, SliceMap, TypedIndex}, table::Table, + typed_func::{always_trap, Func}, types::{ ImportedFuncIndex, ImportedGlobalIndex, ImportedMemoryIndex, ImportedTableIndex, Initializer, LocalFuncIndex, LocalGlobalIndex, LocalMemoryIndex, LocalOrImport, @@ -15,11 +16,7 @@ use crate::{ }, vm, }; -use std::{ - fmt::Debug, - ptr::{self, NonNull}, - slice, -}; +use std::{fmt::Debug, ptr::NonNull, slice}; /// Size of the array for internal instance usage pub const INTERNALS_SIZE: usize = 256; @@ -652,9 +649,18 @@ fn import_functions( } None => { if imports.allow_missing_functions { + let always_trap = Func::new(always_trap); + functions.push(vm::ImportedFunc { - func: ptr::null(), - func_ctx: unsafe { NonNull::new_unchecked(ptr::null_mut()) }, // TODO: Non-sense… + func: always_trap.get_vm_func().as_ptr(), + func_ctx: NonNull::new(Box::into_raw(Box::new(vm::FuncCtx { + // ^^^^^^^^ `vm::FuncCtx` is purposely leaked. + // It is dropped by the specific `Drop` + // implementation of `ImportBacking`. + vmctx: NonNull::new(vmctx).expect("`vmctx` must not be null."), + func_env: None, + }))) + .unwrap(), }); } else { link_errors.push(LinkError::ImportNotFound { diff --git a/lib/runtime-core/src/typed_func.rs b/lib/runtime-core/src/typed_func.rs index 24f35bd6944..9de9d40e2e3 100644 --- a/lib/runtime-core/src/typed_func.rs +++ b/lib/runtime-core/src/typed_func.rs @@ -258,11 +258,6 @@ where _phantom: PhantomData, } } - - /// Get the underlying func pointer. - pub fn get_vm_func(&self) -> NonNull { - self.func - } } impl<'a, Args, Rets> Func<'a, Args, Rets, Host> @@ -303,6 +298,11 @@ where pub fn returns(&self) -> &'static [Type] { Rets::types() } + + /// Get the underlying func pointer. + pub fn get_vm_func(&self) -> NonNull { + self.func + } } impl WasmTypeList for Infallible { From b08b65913b0d191fb1ba82ede58facbb09e23a2b Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Thu, 9 Jan 2020 12:11:34 -0500 Subject: [PATCH 17/19] Add WindowClosed event to experimental fb --- lib/wasi-experimental-io-devices/src/lib.rs | 3 +++ lib/wasi-experimental-io-devices/src/util.rs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/lib/wasi-experimental-io-devices/src/lib.rs b/lib/wasi-experimental-io-devices/src/lib.rs index d713a18af8c..5b890b5ae48 100644 --- a/lib/wasi-experimental-io-devices/src/lib.rs +++ b/lib/wasi-experimental-io-devices/src/lib.rs @@ -114,6 +114,9 @@ impl FrameBufferState { pub fn fill_input_buffer(&mut self) -> Option<()> { let keys_pressed = self.keys_pressed.iter().cloned().collect::>(); + if !self.window.is_open() { + self.push_input_event(InputEvent::WindowClosed)?; + } for key in keys_pressed { if self.window.is_key_released(key) { self.keys_pressed.remove(&key); diff --git a/lib/wasi-experimental-io-devices/src/util.rs b/lib/wasi-experimental-io-devices/src/util.rs index a3e4daf087a..1b6107505e3 100644 --- a/lib/wasi-experimental-io-devices/src/util.rs +++ b/lib/wasi-experimental-io-devices/src/util.rs @@ -6,6 +6,7 @@ pub const KEY_RELEASE: u8 = 3; pub const MOUSE_PRESS_LEFT: u8 = 4; pub const MOUSE_PRESS_RIGHT: u8 = 5; pub const MOUSE_PRESS_MIDDLE: u8 = 7; +pub const WINDOW_CLOSED: u8 = 8; use minifb::{Key, MouseButton}; @@ -15,6 +16,7 @@ pub enum InputEvent { KeyRelease(Key), MouseEvent(u32, u32, MouseButton), MouseMoved(u32, u32), + WindowClosed, } /// Returns the tag as the first return value @@ -58,6 +60,7 @@ pub fn bytes_for_input_event(input_event: InputEvent) -> (u8, [u8; 8], usize) { } (MOUSE_MOVE, data, 8) } + InputEvent::WindowClosed => (WINDOW_CLOSED, data, 0), } } From 9b2f0fc635a5de2e5c07647a7dc7d508c965e5da Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 10 Jan 2020 10:15:26 +0100 Subject: [PATCH 18/19] chore(runtime-core) Avoid code duplication. --- lib/runtime-core/src/backing.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/runtime-core/src/backing.rs b/lib/runtime-core/src/backing.rs index 437f5f724a9..cf787675228 100644 --- a/lib/runtime-core/src/backing.rs +++ b/lib/runtime-core/src/backing.rs @@ -560,8 +560,10 @@ impl Drop for ImportBacking { fn drop(&mut self) { // Properly drop the `vm::FuncCtx` in `vm::ImportedFunc`. for (_imported_func_index, imported_func) in (*self.vm_functions).iter_mut() { - if !imported_func.func_ctx.as_ptr().is_null() { - let _: Box = unsafe { Box::from_raw(imported_func.func_ctx.as_ptr()) }; + let func_ctx_ptr = imported_func.func_ctx.as_ptr(); + + if !func_ctx_ptr.is_null() { + let _: Box = unsafe { Box::from_raw(func_ctx_ptr) }; } } } From 43742cf980ce000c044c231c40ec6515ef6834a8 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 10 Jan 2020 10:18:51 +0100 Subject: [PATCH 19/19] doc(changelog) Add #1128. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f9528b5f48..fe82692b441 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## **[Unreleased]** +- [#1128](https://github.com/wasmerio/wasmer/pull/1128) Fix a crash when a host function is missing and the `allow_missing_functions` flag is enabled - [#1097](https://github.com/wasmerio/wasmer/pull/1097) Move inline breakpoint outside of runtime backend - [#1095](https://github.com/wasmerio/wasmer/pull/1095) Update to cranelift 0.52. - [#1092](https://github.com/wasmerio/wasmer/pull/1092) Add `get_utf8_string_with_nul` to `WasmPtr` to read nul-terminated strings from memory.