From 17901f992a0f10285814aeaf5f132db4804e2b57 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Fri, 22 Feb 2019 12:07:07 -0800 Subject: [PATCH 01/42] Add benchmark runner and nginx compile vs. load bench --- Cargo.lock | 207 ++++++++++++++++++++++++++++++++++ lib/runtime-core/src/cache.rs | 6 +- lib/runtime/Cargo.toml | 7 ++ lib/runtime/benches/nginx.rs | 39 +++++++ 4 files changed, 256 insertions(+), 3 deletions(-) create mode 100644 lib/runtime/benches/nginx.rs diff --git a/Cargo.lock b/Cargo.lock index aa14e70be..229eb1638 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,6 +16,14 @@ dependencies = [ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "arrayvec" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "atty" version = "0.2.11" @@ -256,6 +264,88 @@ dependencies = [ "wasmparser 0.22.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "criterion" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", + "criterion-plot 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "csv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_os 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_xoshiro 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.85 (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.37 (registry+https://github.com/rust-lang/crates.io-index)", + "tinytemplate 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "criterion-plot" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-deque" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", + "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-utils" +version = "0.2.2" +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 = "csv" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "csv-core 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "csv-core" +version = "0.1.5" +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 = "digest" version = "0.8.0" @@ -264,6 +354,11 @@ 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 = "env_logger" version = "0.6.0" @@ -393,6 +488,14 @@ name = "indexmap" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "itertools" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "either 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "itoa" version = "0.4.3" @@ -452,6 +555,9 @@ dependencies = [ name = "memchr" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "memmap" @@ -462,6 +568,11 @@ dependencies = [ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "memoffset" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "nix" version = "0.12.0" @@ -486,6 +597,11 @@ dependencies = [ "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "nodrop" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "nom" version = "4.2.0" @@ -495,6 +611,19 @@ dependencies = [ "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "num-traits" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "num_cpus" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "opaque-debug" version = "0.2.2" @@ -677,6 +806,15 @@ dependencies = [ "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rand_xoshiro" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.1 (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 = "raw-cpuid" version = "6.1.0" @@ -687,6 +825,27 @@ dependencies = [ "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rayon" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "either 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rayon-core" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rdrand" version = "0.4.0" @@ -754,6 +913,14 @@ name = "ryu" version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "same-file" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "scopeguard" version = "0.3.3" @@ -964,6 +1131,15 @@ dependencies = [ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "tinytemplate" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "toml" version = "0.4.10" @@ -1046,6 +1222,16 @@ dependencies = [ "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "walkdir" +version = "2.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "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)", +] + [[package]] name = "wasmer" version = "0.1.4" @@ -1100,6 +1286,7 @@ dependencies = [ name = "wasmer-runtime" version = "0.1.4" dependencies = [ + "criterion 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-clif-backend 0.1.2", @@ -1229,6 +1416,7 @@ dependencies = [ [metadata] "checksum aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1e9a933f4e58658d7b12defcf96dc5c720f20832deebe3e0a19efd3b6aaeeb9e" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +"checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71" "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.13 (registry+https://github.com/rust-lang/crates.io-index)" = "b5b493b66e03090ebc4343eb02f94ff944e0cbc9ac6571491d170ba026741eb5" @@ -1255,7 +1443,15 @@ dependencies = [ "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 criterion 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "1c6e5ee5b9652d4f851418c448af105642e1f99e9a2741a8ff45c0d2c911b1e0" +"checksum criterion-plot 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4107e4a5abb94267e0149922b8ff49dc70a87cc202820fdbfc0d3e1edbdc4b16" +"checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" +"checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150" +"checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" +"checksum csv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "9fd1c44c58078cfbeaf11fbb3eac9ae5534c23004ed770cc4bfb48e658ae4f04" +"checksum csv-core 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa5cdef62f37e6ffe7d1f07a381bc0db32b7a3ff1cac0de56cb0d81e71f53d65" "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 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" @@ -1273,6 +1469,7 @@ dependencies = [ "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 itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b8467d9c1cebe26feb08c640139247fac215782d35371ade9a2136ed6085358" "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.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1" @@ -1283,9 +1480,13 @@ dependencies = [ "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 memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum nix 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "921f61dc817b379d0834e45d5ec45beaacfae97082090a49c2cf30dcbc30206f" "checksum nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "46f0f3210768d796e8fa79ec70ee6af172dacbe7147f5e69be5240a47778302b" +"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" "checksum nom 4.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b30adc557058ce00c9d0d7cb3c6e0b5bc6f36e2e2eabe74b0ba726d194abd588" +"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" +"checksum num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba" "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" @@ -1307,7 +1508,10 @@ dependencies = [ "checksum rand_os 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f46fbd5550acf75b0c2730f5dd1873751daf9beb8f11b44027778fae50d7feca" "checksum rand_pcg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "086bd09a33c7044e56bb44d5bdde5a60e7f119a9e95b0775f545de759a32fe05" "checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +"checksum rand_xoshiro 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "03b418169fb9c46533f326efd6eed2576699c44ca92d3052a066214a8d828929" "checksum raw-cpuid 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "30a9d219c32c9132f7be513c18be77c9881c7107d2ab5569d205a6a0f0e6dc7d" +"checksum rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "373814f27745b2686b350dd261bfd24576a6fb0e2c5919b3a2b6005f820b0473" +"checksum rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b055d1e92aba6877574d8fe604a63c8b5df60f60e5982bf7ccbb1338ea527356" "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" @@ -1317,6 +1521,7 @@ dependencies = [ "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 same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" "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" @@ -1341,6 +1546,7 @@ dependencies = [ "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 tinytemplate 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7655088894274afb52b807bd3c87072daa1fedd155068b8705cabfd628956115" "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" @@ -1354,6 +1560,7 @@ dependencies = [ "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 walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d9d7ed3431229a144296213105a390676cc49c9b6a72bd19f3176c98e129fa1" "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 which 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b57acb10231b9493c8472b20cb57317d0679a49e0bdbee44b3b803a6473af164" diff --git a/lib/runtime-core/src/cache.rs b/lib/runtime-core/src/cache.rs index 3d894bb09..a00e0f6f2 100644 --- a/lib/runtime-core/src/cache.rs +++ b/lib/runtime-core/src/cache.rs @@ -3,7 +3,7 @@ use crate::{ sys::Memory, }; use sha2::{Digest, Sha256}; -use std::{io, mem, slice}; +use std::{io, mem, slice, fmt}; #[derive(Debug)] pub enum InvalidFileType { @@ -191,8 +191,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, module: Module) -> Result; diff --git a/lib/runtime/Cargo.toml b/lib/runtime/Cargo.toml index e4169a652..d7a7effa7 100644 --- a/lib/runtime/Cargo.toml +++ b/lib/runtime/Cargo.toml @@ -20,5 +20,12 @@ version = "0.1.2" path = "../clif-backend" version = "0.1.2" +[dev-dependencies] +criterion = "0.2" + [features] debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] + +[[bench]] +name = "nginx" +harness = false \ No newline at end of file diff --git a/lib/runtime/benches/nginx.rs b/lib/runtime/benches/nginx.rs new file mode 100644 index 000000000..f7f2244b9 --- /dev/null +++ b/lib/runtime/benches/nginx.rs @@ -0,0 +1,39 @@ +#[macro_use] +extern crate criterion; +use criterion::Criterion; +use wasmer_runtime::{ + cache::{Cache, FileSystemCache, WasmHash}, + compile, +}; + +static NGINX_WASM: &'static [u8] = include_bytes!("../../../examples/nginx/nginx.wasm"); + +fn compile_module() { + compile(NGINX_WASM).unwrap(); +} + +fn load_module(cache: &impl Cache) { + let wasm_hash = WasmHash::generate(NGINX_WASM); + cache.load(wasm_hash).unwrap(); +} + +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 mut cache = unsafe { FileSystemCache::new(".").unwrap() }; + let module = compile(NGINX_WASM).unwrap(); + cache.store(module).unwrap(); + + b.iter(|| load_module(&cache)) + }); +} + +criterion_group! { + name = benches; + config = Criterion::default().sample_size(10); + targets = compile_benchmark, load_benchmark +} +criterion_main!(benches); From 6d092dc1215ad1af6312e59f9db688966164a96c Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Fri, 22 Feb 2019 12:08:56 -0800 Subject: [PATCH 02/42] Fix lint --- lib/runtime-core/src/cache.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runtime-core/src/cache.rs b/lib/runtime-core/src/cache.rs index a00e0f6f2..dd1e24a9d 100644 --- a/lib/runtime-core/src/cache.rs +++ b/lib/runtime-core/src/cache.rs @@ -3,7 +3,7 @@ use crate::{ sys::Memory, }; use sha2::{Digest, Sha256}; -use std::{io, mem, slice, fmt}; +use std::{fmt, io, mem, slice}; #[derive(Debug)] pub enum InvalidFileType { From 687f70df8928654d2b728a63aa9a43322eb0b965 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Fri, 22 Feb 2019 12:20:16 -0800 Subject: [PATCH 03/42] Add validation benchmark --- lib/runtime/benches/nginx.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/runtime/benches/nginx.rs b/lib/runtime/benches/nginx.rs index f7f2244b9..f1287dee8 100644 --- a/lib/runtime/benches/nginx.rs +++ b/lib/runtime/benches/nginx.rs @@ -3,7 +3,7 @@ extern crate criterion; use criterion::Criterion; use wasmer_runtime::{ cache::{Cache, FileSystemCache, WasmHash}, - compile, + compile, validate, }; static NGINX_WASM: &'static [u8] = include_bytes!("../../../examples/nginx/nginx.wasm"); @@ -17,6 +17,10 @@ fn load_module(cache: &impl Cache) { cache.load(wasm_hash).unwrap(); } +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())); } @@ -34,6 +38,6 @@ fn load_benchmark(c: &mut Criterion) { criterion_group! { name = benches; config = Criterion::default().sample_size(10); - targets = compile_benchmark, load_benchmark + targets = validate_benchmark, compile_benchmark, load_benchmark } criterion_main!(benches); From cb84894d42f63ae43b8954266c39a3cf9ddd0800 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Fri, 22 Feb 2019 12:31:31 -0800 Subject: [PATCH 04/42] Add section about benchmarking to readme --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) 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. From ad3d361f76fb123633d29d30c2331a7abb03847a Mon Sep 17 00:00:00 2001 From: Mackenzie Clark Date: Fri, 22 Feb 2019 12:32:14 -0800 Subject: [PATCH 05/42] add the syscall and create a test --- lib/emscripten/emtests/test_getcwd.c | 10 +++++++++ lib/emscripten/emtests/test_getcwd.out | 1 + lib/emscripten/emtests/test_getcwd.wasm | Bin 0 -> 22468 bytes lib/emscripten/src/lib.rs | 1 + lib/emscripten/src/syscalls/mod.rs | 23 ++++++++++++++++++++ lib/emscripten/tests/emtests/test_getcwd.rs | 9 ++++++++ 6 files changed, 44 insertions(+) create mode 100644 lib/emscripten/emtests/test_getcwd.c create mode 100644 lib/emscripten/emtests/test_getcwd.out create mode 100644 lib/emscripten/emtests/test_getcwd.wasm create mode 100644 lib/emscripten/tests/emtests/test_getcwd.rs 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 0000000000000000000000000000000000000000..5f93e3aa2931553d2a51b3b3910c18d16ab17c6d GIT binary patch literal 22468 z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(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..c6590cb2d 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -48,6 +48,10 @@ use std::slice; // Other platforms do otherwise. #[cfg(target_os = "darwin")] use libc::SO_NOSIGPIPE; +use crate::utils::copy_cstr_into_wasm; +use crate::env::get_emscripten_data; +use std::ffi::CString; + #[cfg(not(target_os = "darwin"))] const SO_NOSIGPIPE: c_int = 0; @@ -186,6 +190,25 @@ pub fn ___syscall110(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { -1 } +// getcwd +pub fn ___syscall183(ctx: &mut Ctx, buf: u32, _size: u32) -> u32 { + debug!("emscripten::___syscall183"); + use std::env; + let path = env::current_dir(); + match path { + Ok(path_buf) => { + // write path into buffer + let path_string = path_buf.display().to_string(); + let path_c_string = CString::new(path_string).unwrap(); + let offset = unsafe { copy_cstr_into_wasm(ctx, path_c_string.as_ptr()) }; + offset + } + Err(e) => { + unimplemented!() + } + } +} + // mmap2 pub fn ___syscall192(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall192 (mmap2) {}", which); 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" + ); +} From 0f9369c67d67a3d4794ad0edc7ceab0190db43d3 Mon Sep 17 00:00:00 2001 From: Mackenzie Clark Date: Fri, 22 Feb 2019 12:39:19 -0800 Subject: [PATCH 06/42] cargo fmt and better error message --- lib/emscripten/src/syscalls/mod.rs | 8 +++----- lib/emscripten/tests/emtests/mod.rs | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index c6590cb2d..71cd43549 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -46,10 +46,10 @@ 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; #[cfg(target_os = "darwin")] use libc::SO_NOSIGPIPE; -use crate::utils::copy_cstr_into_wasm; -use crate::env::get_emscripten_data; use std::ffi::CString; #[cfg(not(target_os = "darwin"))] @@ -203,9 +203,7 @@ pub fn ___syscall183(ctx: &mut Ctx, buf: u32, _size: u32) -> u32 { let offset = unsafe { copy_cstr_into_wasm(ctx, path_c_string.as_ptr()) }; offset } - Err(e) => { - unimplemented!() - } + Err(e) => panic!("Failed to read current directory from environment."), } } 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; From 4042cff91460876679803501ed8614503199dd4f Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Fri, 22 Feb 2019 13:02:28 -0800 Subject: [PATCH 07/42] Change hashing algorithm from sha1 to meowhash --- Cargo.lock | 70 ++++++++--------------------------- lib/runtime-core/Cargo.toml | 4 +- lib/runtime-core/src/cache.rs | 26 ++++++++----- lib/runtime/Cargo.toml | 1 + lib/runtime/benches/nginx.rs | 17 ++++++--- 5 files changed, 47 insertions(+), 71 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 87bf6802d..83051c53f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -87,30 +87,6 @@ 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" @@ -132,7 +108,7 @@ dependencies = [ "serde_derive 1.0.58 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.37 (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.6 (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)", ] @@ -410,11 +386,6 @@ dependencies = [ "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" @@ -573,6 +544,14 @@ name = "memoffset" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "meowhash" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "nix" version = "0.12.0" @@ -624,11 +603,6 @@ dependencies = [ "libc 0.2.48 (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" @@ -984,17 +958,6 @@ dependencies = [ "serde 1.0.85 (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.8" @@ -1076,7 +1039,7 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.0.6" +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)", @@ -1290,6 +1253,7 @@ dependencies = [ "criterion 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-clif-backend 0.1.2", "wasmer-runtime-core 0.1.2", ] @@ -1308,6 +1272,7 @@ dependencies = [ name = "wasmer-runtime-core" version = "0.1.2" dependencies = [ + "digest 0.8.0 (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)", "hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1315,6 +1280,7 @@ dependencies = [ "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "meowhash 0.1.2 (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)", @@ -1322,7 +1288,6 @@ dependencies = [ "serde-bench 0.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "serde_bytes 0.10.4 (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)", @@ -1424,9 +1389,6 @@ dependencies = [ "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 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" @@ -1458,7 +1420,6 @@ dependencies = [ "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-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" @@ -1482,13 +1443,13 @@ dependencies = [ "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 memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" +"checksum meowhash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b00a85ae2fa3525c3f0e6e7b87bec96ab5587100d7ba7b3e30e1885960a8230b" "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 nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" "checksum nom 4.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b30adc557058ce00c9d0d7cb3c6e0b5bc6f36e2e2eabe74b0ba726d194abd588" "checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" "checksum num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba" -"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" @@ -1531,7 +1492,6 @@ dependencies = [ "checksum serde_bytes 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)" = "adb6e51a6b3696b301bc221d785f898b4457c619b51d7ce195a6d20baecb37b3" "checksum serde_derive 1.0.58 (registry+https://github.com/rust-lang/crates.io-index)" = "ac38f51a52a556cd17545798e29536885fb1a3fa63d6399f5ef650f4a7d35901" "checksum serde_json 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)" = "4b90a9fbe1211e57d3e1c15670f1cb00802988fb23a1a4aad7a2b63544f1920e" -"checksum sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4d8bfd0e469f417657573d8451fb33d16cfe0989359b93baf3a1ffc639543d" "checksum smallvec 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "88aea073965ab29f6edb5493faf96ad662fb18aa9eeb186a3b7057951605ed15" "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" @@ -1541,7 +1501,7 @@ dependencies = [ "checksum syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)" = "f92e629aa1d9c827b2bb8297046c1ccffc57c99b947a680d3ccff1f136a3bee9" "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.6 (registry+https://github.com/rust-lang/crates.io-index)" = "37daa55a7240c4931c84559f03b3cad7d19535840d1c4a0cc4e9b2fb0dcf70ff" +"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" diff --git a/lib/runtime-core/Cargo.toml b/lib/runtime-core/Cargo.toml index cb5a6b4b1..cd0648613 100644 --- a/lib/runtime-core/Cargo.toml +++ b/lib/runtime-core/Cargo.toml @@ -29,7 +29,9 @@ version = "1.0" version = "0.10" [dependencies.serde-bench] version = "0.0.7" -[dependencies.sha2] +[dependencies.meowhash] +version = "0.1.2" +[dependencies.digest] version = "0.8.0" [dependencies.hashbrown] version = "0.1" diff --git a/lib/runtime-core/src/cache.rs b/lib/runtime-core/src/cache.rs index dd1e24a9d..4d2a7b385 100644 --- a/lib/runtime-core/src/cache.rs +++ b/lib/runtime-core/src/cache.rs @@ -2,7 +2,8 @@ use crate::{ module::{Module, ModuleInfo}, sys::Memory, }; -use sha2::{Digest, Sha256}; +use digest::Digest; +use meowhash::MeowHasher; use std::{fmt, io, mem, slice}; #[derive(Debug)] @@ -33,7 +34,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 +43,26 @@ 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 generic_array = MeowHasher::digest(wasm); + + 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 } } @@ -67,7 +75,7 @@ struct ArtifactHeader { magic: [u8; 8], // [W, A, S, M, E, R, \0, \0] version: u64, data_len: u64, - wasm_hash: [u8; 32], // Sha256 of the wasm in binary format. + wasm_hash: [u8; 64], // Sha256 of the wasm in binary format. } impl ArtifactHeader { diff --git a/lib/runtime/Cargo.toml b/lib/runtime/Cargo.toml index d7a7effa7..979fae140 100644 --- a/lib/runtime/Cargo.toml +++ b/lib/runtime/Cargo.toml @@ -21,6 +21,7 @@ path = "../clif-backend" version = "0.1.2" [dev-dependencies] +tempfile = "3.0.7" criterion = "0.2" [features] diff --git a/lib/runtime/benches/nginx.rs b/lib/runtime/benches/nginx.rs index f1287dee8..542a87d7d 100644 --- a/lib/runtime/benches/nginx.rs +++ b/lib/runtime/benches/nginx.rs @@ -1,6 +1,7 @@ #[macro_use] extern crate criterion; use criterion::Criterion; +use tempfile::tempdir; use wasmer_runtime::{ cache::{Cache, FileSystemCache, WasmHash}, compile, validate, @@ -12,9 +13,12 @@ fn compile_module() { compile(NGINX_WASM).unwrap(); } -fn load_module(cache: &impl Cache) { - let wasm_hash = WasmHash::generate(NGINX_WASM); - cache.load(wasm_hash).unwrap(); +fn load_module(hash: WasmHash, cache: &impl Cache) { + cache.load(hash).unwrap(); +} + +fn hashing_benchmark(c: &mut Criterion) { + c.bench_function("nginx HASH", |b| b.iter(|| WasmHash::generate(NGINX_WASM))); } fn validate_benchmark(c: &mut Criterion) { @@ -27,17 +31,18 @@ fn compile_benchmark(c: &mut Criterion) { fn load_benchmark(c: &mut Criterion) { c.bench_function("nginx load", |b| { - let mut cache = unsafe { FileSystemCache::new(".").unwrap() }; + let mut cache = unsafe { FileSystemCache::new(tempdir().unwrap().path()).unwrap() }; let module = compile(NGINX_WASM).unwrap(); cache.store(module).unwrap(); + let wasm_hash = WasmHash::generate(NGINX_WASM); - b.iter(|| load_module(&cache)) + b.iter(|| load_module(wasm_hash, &cache)) }); } criterion_group! { name = benches; config = Criterion::default().sample_size(10); - targets = validate_benchmark, compile_benchmark, load_benchmark + targets = validate_benchmark, hashing_benchmark, compile_benchmark, load_benchmark } criterion_main!(benches); From 0c1982442522aebad289fa6008604173f3be1e07 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Fri, 22 Feb 2019 14:07:03 -0800 Subject: [PATCH 08/42] Fix after merge --- lib/clif-backend/src/module.rs | 2 +- lib/runtime-core/src/cache.rs | 1 - lib/runtime-core/src/module.rs | 2 +- lib/runtime/benches/nginx.rs | 11 ++++++++--- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/clif-backend/src/module.rs b/lib/clif-backend/src/module.rs index 38a657625..07efe9bd3 100644 --- a/lib/clif-backend/src/module.rs +++ b/lib/clif-backend/src/module.rs @@ -7,7 +7,7 @@ use cranelift_wasm; use hashbrown::HashMap; use std::sync::Arc; -use wasmer_runtime_core::cache::{Artifact, Error as CacheError, WasmHash}; +use wasmer_runtime_core::cache::{Artifact, Error as CacheError}; use wasmer_runtime_core::{ backend::Backend, diff --git a/lib/runtime-core/src/cache.rs b/lib/runtime-core/src/cache.rs index 64fe3e182..4859bd390 100644 --- a/lib/runtime-core/src/cache.rs +++ b/lib/runtime-core/src/cache.rs @@ -75,7 +75,6 @@ struct ArtifactHeader { magic: [u8; 8], // [W, A, S, M, E, R, \0, \0] version: u64, data_len: u64, - wasm_hash: [u8; 64], // Sha256 of the wasm in binary format. } impl ArtifactHeader { diff --git a/lib/runtime-core/src/module.rs b/lib/runtime-core/src/module.rs index cac375b66..43c9be9dc 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/benches/nginx.rs b/lib/runtime/benches/nginx.rs index 542a87d7d..1466addb1 100644 --- a/lib/runtime/benches/nginx.rs +++ b/lib/runtime/benches/nginx.rs @@ -14,7 +14,7 @@ fn compile_module() { } fn load_module(hash: WasmHash, cache: &impl Cache) { - cache.load(hash).unwrap(); + cache.load(hash).expect("could not load module"); } fn hashing_benchmark(c: &mut Criterion) { @@ -31,10 +31,15 @@ fn compile_benchmark(c: &mut Criterion) { fn load_benchmark(c: &mut Criterion) { c.bench_function("nginx load", |b| { - let mut cache = unsafe { FileSystemCache::new(tempdir().unwrap().path()).unwrap() }; + 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(); - cache.store(module).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)) }); From 966be3ee8f7760fffb6e414c577199e2ed480b6f Mon Sep 17 00:00:00 2001 From: Mackenzie Clark Date: Fri, 22 Feb 2019 14:54:01 -0800 Subject: [PATCH 09/42] right to the out buffer that was passed in syscall183 --- lib/emscripten/src/syscalls/mod.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index 71cd43549..3f310be06 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -48,6 +48,7 @@ use std::slice; // 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; @@ -191,20 +192,21 @@ pub fn ___syscall110(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { } // getcwd -pub fn ___syscall183(ctx: &mut Ctx, buf: u32, _size: u32) -> u32 { +pub fn ___syscall183(ctx: &mut Ctx, buf_offset: u32, _size: u32) -> u32 { debug!("emscripten::___syscall183"); use std::env; let path = env::current_dir(); - match path { - Ok(path_buf) => { - // write path into buffer - let path_string = path_buf.display().to_string(); - let path_c_string = CString::new(path_string).unwrap(); - let offset = unsafe { copy_cstr_into_wasm(ctx, path_c_string.as_ptr()) }; - offset + 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 _; } - Err(e) => panic!("Failed to read current directory from environment."), + *pointer_to_buffer.add(len.clone()) = 0; } + buf_offset } // mmap2 From b5056d676acb8f30ae9126cc84dce86e5652e690 Mon Sep 17 00:00:00 2001 From: Mackenzie Clark Date: Fri, 22 Feb 2019 15:07:55 -0800 Subject: [PATCH 10/42] update wasm file --- lib/emscripten/emtests/test_getcwd.wasm | Bin 22468 -> 45896 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/lib/emscripten/emtests/test_getcwd.wasm b/lib/emscripten/emtests/test_getcwd.wasm index 5f93e3aa2931553d2a51b3b3910c18d16ab17c6d..0c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zrY&I4Ml{%$BCw9~cqNlRX92zx_JjprYNunClj$i7w;GvFx-erQlQQkXB@3C9Sr@KY z$fR5*&`WmH!VXE-T)1N)lXBaIISZMTyDltP$fV4>&>cc1rOSn$5HczIUFZuTlhUgp zg)|Vt4oUqk42O_O8FXPZgiOka3lkw^QpQ|37eXfGj0;mCWKt$wm@GZ_H&*|Hx5Ml5*EBpIth zQ)zAfyx!G^OncOVL-fML-KkEMene&C^~4tX;FSBpd}1~J=c!1H>kr21MUDsr0=UIV zK5arHoHiR|+Jv;JcfPabQO3X1?`ZJ!?&XJBY(U%p-2`lZGn4YFi4nn7?FmajSy>TP zxAkR_dv)1;$4g~btkh+X2O@rWmjeGCMPv-`zV)h(+l{G&lX8})(2;O_QNFn)`uBb&W&n^{YmWF z{-mQI|NpvhIieO}r!+wme7{|8qMO03x=-_+XxcHF z_IlX?9omWd=QAx|!$tXtUX#7FBpcV3(wY6r+TD7$G{cK0Cu!jOm?- zmx)P?u*WRCPtfK-#$)#)gNw|WEv|b@!%9A8rB%ZX5AVuXKW@Ab2{2BVDsJP= zB`d?}wxclfj3}7yOh( z%pOI6iNpCBGHTk6o&{NX#WEYRWi*f%R~18RSXAvAs$wPT)KDDndhZXdWJT&fLq(62 zNC1#5hX=sOi_*f;h$Yx5!9^;;6FDxKiQQOw-SHqx|KUW3$a)p;uy&U}@QOM-Ue5Om L_3rrd+z|f-xrN`C From 7fb7529b4803ad487650919d5bd981387b63c03d Mon Sep 17 00:00:00 2001 From: Mackenzie Clark Date: Fri, 22 Feb 2019 15:16:07 -0800 Subject: [PATCH 11/42] cargo fmt --- lib/emscripten/src/syscalls/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index 3f310be06..2143599f7 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -199,7 +199,8 @@ pub fn ___syscall183(ctx: &mut Ctx, buf_offset: u32, _size: u32) -> u32 { 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 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 _; From fa596d2d2325ab07ef3646029602d2f4c30a7f22 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Fri, 22 Feb 2019 17:38:28 -0800 Subject: [PATCH 12/42] Update Cargo.toml --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 67fbda1b7..15b09e542 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer" -version = "0.1.4" +version = "0.2.0" authors = ["The Wasmer Engineering Team "] edition = "2018" repository = "https://github.com/wasmerio/wasmer" From 82eef13f41f3031b35b62e42336ddedec0103216 Mon Sep 17 00:00:00 2001 From: Mackenzie Clark Date: Fri, 22 Feb 2019 22:18:59 -0800 Subject: [PATCH 13/42] Create a grow error and refactor grow impl to return result (#191) --- Cargo.lock | 2 +- lib/runtime-c-api/src/lib.rs | 30 +++-- lib/runtime-c-api/tests/test-memory.c | 37 ++++--- lib/runtime-c-api/tests/test-tables.c | 41 +++---- lib/runtime-core/src/error.rs | 103 ++++++++++++++++++ lib/runtime-core/src/memory/dynamic.rs | 24 ++-- lib/runtime-core/src/memory/mod.rs | 10 +- .../src/memory/static_/unshared.rs | 20 ++-- lib/runtime-core/src/sys/unix/memory.rs | 28 +++-- lib/runtime-core/src/sys/windows/memory.rs | 17 ++- lib/runtime-core/src/table/mod.rs | 11 +- lib/runtime-core/src/units.rs | 11 +- lib/runtime-core/src/vmcalls.rs | 28 ++--- 13 files changed, 250 insertions(+), 112 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 83051c53f..0b062168f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1197,7 +1197,7 @@ dependencies = [ [[package]] name = "wasmer" -version = "0.1.4" +version = "0.2.0" 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)", diff --git a/lib/runtime-c-api/src/lib.rs b/lib/runtime-c-api/src/lib.rs index f19380cdb..f52076d28 100644 --- a/lib/runtime-c-api/src/lib.rs +++ b/lib/runtime-c-api/src/lib.rs @@ -208,14 +208,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 +276,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 + } } } 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-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-core/src/error.rs b/lib/runtime-core/src/error.rs index 33c9fd15f..1f9f60c61 100644 --- a/lib/runtime-core/src/error.rs +++ b/lib/runtime-core/src/error.rs @@ -1,3 +1,4 @@ +use crate::sys::Memory; use crate::types::{ FuncSig, GlobalDescriptor, MemoryDescriptor, MemoryIndex, TableDescriptor, TableIndex, Type, }; @@ -369,3 +370,105 @@ impl std::fmt::Display for Error { } 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/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/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, } } From ed706133c463edfcf61d5b981752ed00e7d92ec4 Mon Sep 17 00:00:00 2001 From: Andrew Cann Date: Sat, 23 Feb 2019 17:00:03 +0800 Subject: [PATCH 14/42] fix stack overflow in Error's Display impl --- lib/runtime-core/src/error.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/runtime-core/src/error.rs b/lib/runtime-core/src/error.rs index 1f9f60c61..fea5c1e2e 100644 --- a/lib/runtime-core/src/error.rs +++ b/lib/runtime-core/src/error.rs @@ -365,7 +365,24 @@ 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), + } } } From 17fe7bdaea038843c0532c16b6af25ef7ca34106 Mon Sep 17 00:00:00 2001 From: Brandon Fish Date: Sat, 23 Feb 2019 15:41:38 -0600 Subject: [PATCH 15/42] Add C API module export descriptors --- lib/runtime-c-api/src/lib.rs | 114 ++++++++++++++++++ lib/runtime-c-api/tests/.gitignore | 1 + lib/runtime-c-api/tests/CMakeLists.txt | 4 + lib/runtime-c-api/tests/test-module-exports.c | 53 ++++++++ lib/runtime-c-api/wasmer.h | 43 ++++++- lib/runtime-c-api/wasmer.hh | 31 ++++- 6 files changed, 244 insertions(+), 2 deletions(-) create mode 100644 lib/runtime-c-api/tests/test-module-exports.c diff --git a/lib/runtime-c-api/src/lib.rs b/lib/runtime-c-api/src/lib.rs index f52076d28..ea56cf7f5 100644 --- a/lib/runtime-c-api/src/lib.rs +++ b/lib/runtime-c-api/src/lib.rs @@ -13,6 +13,7 @@ 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; use wasmer_runtime_core::types::{ElementType, FuncSig, MemoryDescriptor, TableDescriptor, Type}; use wasmer_runtime_core::units::{Bytes, Pages}; @@ -120,6 +121,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 { @@ -468,6 +477,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] @@ -1075,6 +1169,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! { @@ -1173,3 +1282,8 @@ struct NamedExport { name: String, export: Export, } + +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..6ddd85f73 100644 --- a/lib/runtime-c-api/tests/.gitignore +++ b/lib/runtime-c-api/tests/.gitignore @@ -15,6 +15,7 @@ test-instantiate test-import-function test-memory 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..111b374e4 100644 --- a/lib/runtime-c-api/tests/CMakeLists.txt +++ b/lib/runtime-c-api/tests/CMakeLists.txt @@ -7,6 +7,7 @@ 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 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) @@ -31,6 +32,8 @@ target_link_libraries(test-memory 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 @@ -43,6 +46,7 @@ add_test(test-instantiate test-instantiate) add_test(test-import-function test-import-function) add_test(test-memory test-memory) 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/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/wasmer.h b/lib/runtime-c-api/wasmer.h index 6c0494e01..f1d2245c0 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,6 +44,14 @@ typedef struct { typedef struct { +} wasmer_export_descriptors_t; + +typedef struct { + +} wasmer_export_t; + +typedef struct { + } wasmer_func_t; typedef struct { @@ -113,6 +121,39 @@ 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); + /** * Gets wasmer_export kind */ diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 2bb55de45..c0f2234f5 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,6 +39,14 @@ struct wasmer_byte_array { uint32_t bytes_len; }; +struct wasmer_export_descriptors_t { + +}; + +struct wasmer_export_t { + +}; + struct wasmer_func_t { }; @@ -110,6 +118,27 @@ 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); + /// Gets wasmer_export kind wasmer_import_export_kind wasmer_export_kind(wasmer_export_t *export_); From 1dfa106850ef5d4b3e16368fc2fa2078c51d9d31 Mon Sep 17 00:00:00 2001 From: Brandon Fish Date: Sat, 23 Feb 2019 18:25:51 -0600 Subject: [PATCH 16/42] Add C API module import descriptors --- lib/runtime-c-api/src/lib.rs | 194 ++++++++++++++++++ lib/runtime-c-api/tests/.gitignore | 1 + lib/runtime-c-api/tests/CMakeLists.txt | 4 + lib/runtime-c-api/tests/test-module-imports.c | 56 +++++ lib/runtime-c-api/wasmer.h | 46 +++++ lib/runtime-c-api/wasmer.hh | 32 +++ 6 files changed, 333 insertions(+) create mode 100644 lib/runtime-c-api/tests/test-module-imports.c diff --git a/lib/runtime-c-api/src/lib.rs b/lib/runtime-c-api/src/lib.rs index f52076d28..ec19b249c 100644 --- a/lib/runtime-c-api/src/lib.rs +++ b/lib/runtime-c-api/src/lib.rs @@ -13,6 +13,7 @@ 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::ImportName; use wasmer_runtime_core::types::{ElementType, FuncSig, MemoryDescriptor, TableDescriptor, Type}; use wasmer_runtime_core::units::{Bytes, Pages}; @@ -112,6 +113,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; @@ -477,6 +486,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. @@ -1169,6 +1357,12 @@ 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, diff --git a/lib/runtime-c-api/tests/.gitignore b/lib/runtime-c-api/tests/.gitignore index 6ea57c28d..773d7f43d 100644 --- a/lib/runtime-c-api/tests/.gitignore +++ b/lib/runtime-c-api/tests/.gitignore @@ -14,6 +14,7 @@ test-exports test-instantiate test-import-function test-memory +test-module-imports test-module test-tables test-validate diff --git a/lib/runtime-c-api/tests/CMakeLists.txt b/lib/runtime-c-api/tests/CMakeLists.txt index 788ee1c6a..2db4f219a 100644 --- a/lib/runtime-c-api/tests/CMakeLists.txt +++ b/lib/runtime-c-api/tests/CMakeLists.txt @@ -6,6 +6,7 @@ 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-validate test-validate.c) add_executable(test-tables test-tables.c) @@ -29,6 +30,8 @@ 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-validate @@ -42,6 +45,7 @@ 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-validate test-validate) add_test(test-tables test-tables) 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..47757c58c --- /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; +} \ No newline at end of file diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index 6c0494e01..5f01ad65a 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -73,6 +73,14 @@ typedef struct { typedef struct { +} wasmer_import_descriptor_t; + +typedef struct { + +} wasmer_import_descriptors_t; + +typedef struct { + } wasmer_memory_t; typedef struct { @@ -231,6 +239,44 @@ 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); + /** * 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..2af93433d 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -68,6 +68,14 @@ struct wasmer_global_descriptor_t { wasmer_value_tag kind; }; +struct wasmer_import_descriptor_t { + +}; + +struct wasmer_import_descriptors_t { + +}; + struct wasmer_memory_t { }; @@ -192,6 +200,30 @@ 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); + /// 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. From b008a054de2792956bf9b1abd2c7b1fc731e14c8 Mon Sep 17 00:00:00 2001 From: Brandon Fish Date: Sun, 24 Feb 2019 12:22:24 -0600 Subject: [PATCH 17/42] Fix C API to allow calling an exported func --- lib/runtime-c-api/src/lib.rs | 322 ++++++++++++------ lib/runtime-c-api/tests/test-exports.c | 40 +-- .../tests/test-import-function.c | 4 +- lib/runtime-c-api/wasmer.h | 200 ++++++----- lib/runtime-c-api/wasmer.hh | 164 +++++---- 5 files changed, 455 insertions(+), 275 deletions(-) diff --git a/lib/runtime-c-api/src/lib.rs b/lib/runtime-c-api/src/lib.rs index f52076d28..25d56821d 100644 --- a/lib/runtime-c-api/src/lib.rs +++ b/lib/runtime-c-api/src/lib.rs @@ -16,9 +16,6 @@ use wasmer_runtime_core::import::Namespace; 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 +75,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 +97,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, @@ -132,7 +125,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, @@ -647,9 +640,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 }; } @@ -704,18 +704,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); @@ -726,10 +865,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. /// @@ -737,33 +876,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 { @@ -777,14 +891,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. /// @@ -792,8 +906,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 { @@ -807,14 +921,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. /// @@ -822,8 +936,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) }; @@ -832,7 +946,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 }; @@ -842,20 +956,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 @@ -878,8 +991,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, @@ -901,46 +1014,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`. @@ -1058,12 +1167,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 { @@ -1172,4 +1275,5 @@ impl Error for CApiError {} struct NamedExport { name: String, export: Export, + instance: *mut Instance, } 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/wasmer.h b/lib/runtime-c-api/wasmer.h index 6c0494e01..1744289a5 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -35,20 +35,7 @@ typedef struct wasmer_module_t wasmer_module_t; typedef struct { -} wasmer_export_t; - -typedef struct { - const uint8_t *bytes; - uint32_t bytes_len; -} wasmer_byte_array; - -typedef struct { - -} wasmer_func_t; - -typedef struct { - -} wasmer_exports_t; +} wasmer_export_func_t; typedef union { int32_t I32; @@ -64,6 +51,19 @@ typedef struct { typedef struct { +} wasmer_export_t; + +typedef struct { + const uint8_t *bytes; + uint32_t bytes_len; +} wasmer_byte_array; + +typedef struct { + +} wasmer_exports_t; + +typedef struct { + } wasmer_global_t; typedef struct { @@ -73,6 +73,10 @@ typedef struct { typedef struct { +} wasmer_import_func_t; + +typedef struct { + } wasmer_memory_t; typedef struct { @@ -80,7 +84,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 +117,55 @@ wasmer_result_t wasmer_compile(wasmer_module_t **module, uint8_t *wasm_bytes, uint32_t wasm_bytes_len); +/** + * 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 +177,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 +196,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 +222,57 @@ wasmer_global_t *wasmer_global_new(wasmer_value_t value, bool mutable_); */ void wasmer_global_set(wasmer_global_t *global, wasmer_value_t value); +/** + * 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..f79539f3d 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -30,20 +30,7 @@ struct wasmer_instance_t; struct wasmer_module_t; -struct wasmer_export_t { - -}; - -struct wasmer_byte_array { - const uint8_t *bytes; - uint32_t bytes_len; -}; - -struct wasmer_func_t { - -}; - -struct wasmer_exports_t { +struct wasmer_export_func_t { }; @@ -59,6 +46,19 @@ struct wasmer_value_t { wasmer_value value; }; +struct wasmer_export_t { + +}; + +struct wasmer_byte_array { + const uint8_t *bytes; + uint32_t bytes_len; +}; + +struct wasmer_exports_t { + +}; + struct wasmer_global_t { }; @@ -68,6 +68,10 @@ struct wasmer_global_descriptor_t { wasmer_value_tag kind; }; +struct wasmer_import_func_t { + +}; + struct wasmer_memory_t { }; @@ -77,7 +81,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 +114,53 @@ wasmer_result_t wasmer_compile(wasmer_module_t **module, uint8_t *wasm_bytes, uint32_t wasm_bytes_len); +/// 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 +171,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 +187,45 @@ 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); +/// 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. From 2f51694815677da344c9c5e4723179795deac2f6 Mon Sep 17 00:00:00 2001 From: Mackenzie Clark Date: Mon, 25 Feb 2019 11:46:48 -0800 Subject: [PATCH 18/42] no caching on windows --- src/bin/wasmer.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index 6b8c9b54b..a96507f9f 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.")] @@ -84,6 +82,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_windows = options.disable_cache; + let wasm_path = &options.path; let mut wasm_binary: Vec = read_file_contents(wasm_path).map_err(|err| { @@ -99,7 +103,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 +192,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 +204,9 @@ fn main() { println!("{}", get_cache_dir().to_string_lossy()); } }, + #[cfg(target_os = "windows")] + CLIOptions::Cache(_) => { + println!("Caching is disabled for Windows."); + } } } From 9aa63804609a88b92224a7af6d2a31a3ae706d25 Mon Sep 17 00:00:00 2001 From: Mackenzie Clark Date: Mon, 25 Feb 2019 11:53:15 -0800 Subject: [PATCH 19/42] lol --- src/bin/wasmer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index a96507f9f..d5364504b 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -86,7 +86,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> { #[cfg(target_os = "windows")] let disable_cache = true; #[cfg(not(target_os = "windows"))] - let disable_windows = options.disable_cache; + let disable_cache = options.disable_cache; let wasm_path = &options.path; From c5c967da00628f49f8e9c70be584fa606b78abce Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Mon, 25 Feb 2019 12:03:48 -0800 Subject: [PATCH 20/42] Added parallel compilation (#209) --- Cargo.lock | 1 + lib/clif-backend/Cargo.toml | 1 + lib/clif-backend/src/lib.rs | 1 + lib/clif-backend/src/resolver.rs | 56 +++++++++++++++++--------- lib/runtime-core/src/structures/map.rs | 4 ++ 5 files changed, 45 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0b062168f..1b7b19bc5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1220,6 +1220,7 @@ dependencies = [ "hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.85 (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.4 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/lib/clif-backend/Cargo.toml b/lib/clif-backend/Cargo.toml index 701f821fc..06fd397dc 100644 --- a/lib/clif-backend/Cargo.toml +++ b/lib/clif-backend/Cargo.toml @@ -19,6 +19,7 @@ wasmparser = "0.23.0" byteorder = "1" nix = "0.13.0" libc = "0.2.48" +rayon = "1.0" # Dependencies for caching. [dependencies.serde] diff --git a/lib/clif-backend/src/lib.rs b/lib/clif-backend/src/lib.rs index df2e4e208..c4abf644f 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 604778f01..53b3a789a 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,45 @@ 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 compiled_functions: Vec<(Vec, RelocSink)> = Vec::with_capacity(num_func_bodies); + 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 +139,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 +165,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/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 From deac24c0bdef7214b652fdd85076bd7d9141b83b Mon Sep 17 00:00:00 2001 From: Mackenzie Clark Date: Mon, 25 Feb 2019 12:06:23 -0800 Subject: [PATCH 21/42] fix windows installer --- src/installer/wasmer.iss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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'; From f9c0e0c07869306b5fbb027210ae062745e908c8 Mon Sep 17 00:00:00 2001 From: Syrus Date: Mon, 25 Feb 2019 12:25:28 -0800 Subject: [PATCH 22/42] Fix formatting --- lib/runtime-core/src/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runtime-core/src/error.rs b/lib/runtime-core/src/error.rs index fea5c1e2e..abc69cc5e 100644 --- a/lib/runtime-core/src/error.rs +++ b/lib/runtime-core/src/error.rs @@ -377,7 +377,7 @@ impl std::fmt::Display for Error { } 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), From 53c8603464bd2c50fcb3b83cdbbf954e59f3cfa4 Mon Sep 17 00:00:00 2001 From: Syrus Date: Mon, 25 Feb 2019 13:28:37 -0800 Subject: [PATCH 23/42] Updated crates version to 0.2.0 --- Cargo.lock | 107 +++++++++++++-------------- lib/clif-backend/Cargo.toml | 8 +- lib/emscripten/Cargo.toml | 8 +- lib/runtime-c-api/Cargo.toml | 6 +- lib/runtime-core/Cargo.toml | 5 +- lib/runtime/Cargo.toml | 6 +- lib/spectests/Cargo.toml | 6 +- lib/win-exception-handler/Cargo.toml | 6 +- 8 files changed, 72 insertions(+), 80 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1b7b19bc5..2d9f3cca3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,7 +29,7 @@ name = "atty" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "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)", ] @@ -47,7 +47,7 @@ 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.48 (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)", ] @@ -58,7 +58,7 @@ version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -136,7 +136,7 @@ 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.48 (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)", ] @@ -353,7 +353,7 @@ 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.48 (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)", ] @@ -363,7 +363,7 @@ 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.48 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -488,12 +488,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.48" -source = "git+https://github.com/rust-lang/libc#42cd3ba27254c423e03f6f4324de57075047f6a0" - -[[package]] -name = "libc" -version = "0.2.48" +version = "0.2.49" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -527,7 +522,7 @@ name = "memchr" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -535,7 +530,7 @@ name = "memmap" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.48 (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)", ] @@ -560,7 +555,7 @@ dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.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.48 (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)", ] @@ -572,7 +567,7 @@ dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.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.48 (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)", ] @@ -600,7 +595,7 @@ name = "num_cpus" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -617,7 +612,7 @@ 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.48 (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)", ] @@ -635,7 +630,7 @@ name = "parking_lot_core" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.48 (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)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -690,7 +685,7 @@ 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.48 (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)", @@ -745,7 +740,7 @@ name = "rand_jitter" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.48 (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)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -757,7 +752,7 @@ 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-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.48 (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.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.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -816,7 +811,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1043,7 +1038,7 @@ 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.48 (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)", @@ -1063,7 +1058,7 @@ name = "termion" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "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)", ] @@ -1089,7 +1084,7 @@ name = "time" version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "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)", ] @@ -1202,15 +1197,15 @@ 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", + "wasmer-clif-backend 0.2.0", + "wasmer-emscripten 0.2.0", + "wasmer-runtime 0.2.0", + "wasmer-runtime-core 0.2.0", ] [[package]] name = "wasmer-clif-backend" -version = "0.1.2" +version = "0.2.0" 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)", @@ -1218,7 +1213,7 @@ dependencies = [ "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.48 (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)", "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1226,52 +1221,52 @@ dependencies = [ "serde_bytes 0.10.4 (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", + "wasmer-runtime-core 0.2.0", + "wasmer-win-exception-handler 0.2.0", "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" +version = "0.2.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.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.48 (git+https://github.com/rust-lang/libc)", + "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)", "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", + "wasmer-clif-backend 0.2.0", + "wasmer-runtime-core 0.2.0", ] [[package]] name = "wasmer-runtime" -version = "0.1.4" +version = "0.2.0" dependencies = [ "criterion 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-clif-backend 0.1.2", - "wasmer-runtime-core 0.1.2", + "wasmer-clif-backend 0.2.0", + "wasmer-runtime-core 0.2.0", ] [[package]] name = "wasmer-runtime-c-api" -version = "0.1.4" +version = "0.2.0" dependencies = [ "cbindgen 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-runtime 0.1.4", - "wasmer-runtime-core 0.1.2", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmer-runtime 0.2.0", + "wasmer-runtime-core 0.2.0", ] [[package]] name = "wasmer-runtime-core" -version = "0.1.2" +version = "0.2.0" dependencies = [ "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "errno 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1280,7 +1275,7 @@ dependencies = [ "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.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", "meowhash 0.1.2 (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)", @@ -1289,29 +1284,28 @@ dependencies = [ "serde-bench 0.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "serde_bytes 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.58 (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" +version = "0.2.0" dependencies = [ "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", + "wasmer-clif-backend 0.2.0", + "wasmer-runtime-core 0.2.0", ] [[package]] name = "wasmer-win-exception-handler" -version = "0.0.1" +version = "0.2.0" 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.48 (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", + "wasmer-runtime-core 0.2.0", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1331,7 +1325,7 @@ 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.48 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1436,8 +1430,7 @@ dependencies = [ "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.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1" -"checksum libc 0.2.48 (git+https://github.com/rust-lang/libc)" = "" -"checksum libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)" = "e962c7641008ac010fa60a7dfdc1712449f29c44ef2d4702394aea943ee75047" +"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 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" diff --git a/lib/clif-backend/Cargo.toml b/lib/clif-backend/Cargo.toml index 06fd397dc..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,7 @@ 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. @@ -33,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/emscripten/Cargo.toml b/lib/emscripten/Cargo.toml index ec5e035d6..1300eb124 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.0" 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.0" } 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/runtime-c-api/Cargo.toml b/lib/runtime-c-api/Cargo.toml index 692c03cd7..d2b327c22 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.0" 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.0" } +wasmer-runtime-core = { path = "../runtime-core", version = "0.2.0" } libc = "0.2" [lib] diff --git a/lib/runtime-core/Cargo.toml b/lib/runtime-core/Cargo.toml index cd0648613..3d61a858c 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.0" 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. @@ -41,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/Cargo.toml b/lib/runtime/Cargo.toml index 979fae140..f7aa32cb5 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.0" description = "Wasmer runtime library" license = "MIT" authors = ["The Wasmer Engineering Team "] @@ -14,11 +14,11 @@ memmap = "0.7.0" [dependencies.wasmer-runtime-core] path = "../runtime-core" -version = "0.1.2" +version = "0.2.0" [dependencies.wasmer-clif-backend] path = "../clif-backend" -version = "0.1.2" +version = "0.2.0" [dev-dependencies] tempfile = "3.0.7" diff --git a/lib/spectests/Cargo.toml b/lib/spectests/Cargo.toml index f69782b40..672013dd9 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" } wabt = "0.7.2" [features] 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" From 2b1aedfbc40152fff7d34614d4686fcb42b598d2 Mon Sep 17 00:00:00 2001 From: Mackenzie Clark Date: Mon, 25 Feb 2019 14:48:39 -0800 Subject: [PATCH 24/42] install inno setup in appveyor --- .appveyor.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.appveyor.yml b/.appveyor.yml index 488e400fd..4ec05f8c7 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -21,6 +21,10 @@ install: - set PATH=%PATH%;%USERPROFILE%\.cargo\bin - 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% build_script: - cargo build --verbose From e7d08712b53a01581edae5c220da4bdd2a149a31 Mon Sep 17 00:00:00 2001 From: Syrus Date: Mon, 25 Feb 2019 17:37:33 -0800 Subject: [PATCH 25/42] Use blake2 hashing algorithm --- Cargo.lock | 51 ++++++++++++++++++++++++++++------- lib/runtime-core/Cargo.toml | 4 +-- lib/runtime-core/src/cache.rs | 8 +++--- 3 files changed, 48 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2d9f3cca3..f8b6f496b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -87,6 +87,22 @@ name = "bitflags" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "blake2" +version = "0.8.0" +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)", + "crypto-mac 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)", + "opaque-debug 0.2.2 (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" @@ -305,6 +321,15 @@ dependencies = [ "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "crypto-mac" +version = "0.7.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)", + "subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "csv" version = "1.0.5" @@ -539,14 +564,6 @@ name = "memoffset" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "meowhash" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "nix" version = "0.12.0" @@ -598,6 +615,11 @@ dependencies = [ "libc 0.2.49 (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" @@ -991,6 +1013,11 @@ dependencies = [ "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "subtle" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "syn" version = "0.13.11" @@ -1268,6 +1295,7 @@ dependencies = [ name = "wasmer-runtime-core" version = "0.2.0" dependencies = [ + "blake2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.8.0 (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)", @@ -1276,7 +1304,6 @@ dependencies = [ "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", - "meowhash 0.1.2 (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)", @@ -1384,6 +1411,8 @@ dependencies = [ "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 blake2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "91721a6330935673395a0607df4d49a9cb90ae12d259f1b3e0a3f6e1d486872e" +"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 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" @@ -1406,6 +1435,7 @@ dependencies = [ "checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" "checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150" "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" +"checksum crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" "checksum csv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "9fd1c44c58078cfbeaf11fbb3eac9ae5534c23004ed770cc4bfb48e658ae4f04" "checksum csv-core 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa5cdef62f37e6ffe7d1f07a381bc0db32b7a3ff1cac0de56cb0d81e71f53d65" "checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c" @@ -1437,13 +1467,13 @@ dependencies = [ "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 memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" -"checksum meowhash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b00a85ae2fa3525c3f0e6e7b87bec96ab5587100d7ba7b3e30e1885960a8230b" "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 nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" "checksum nom 4.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b30adc557058ce00c9d0d7cb3c6e0b5bc6f36e2e2eabe74b0ba726d194abd588" "checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" "checksum num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba" +"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" @@ -1491,6 +1521,7 @@ dependencies = [ "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 subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" "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 synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" diff --git a/lib/runtime-core/Cargo.toml b/lib/runtime-core/Cargo.toml index 3d61a858c..5e89c7cde 100644 --- a/lib/runtime-core/Cargo.toml +++ b/lib/runtime-core/Cargo.toml @@ -29,8 +29,8 @@ version = "1.0" version = "0.10" [dependencies.serde-bench] version = "0.0.7" -[dependencies.meowhash] -version = "0.1.2" +[dependencies.blake2] +version = "0.8" [dependencies.digest] version = "0.8.0" [dependencies.hashbrown] diff --git a/lib/runtime-core/src/cache.rs b/lib/runtime-core/src/cache.rs index 4859bd390..d4d01edd9 100644 --- a/lib/runtime-core/src/cache.rs +++ b/lib/runtime-core/src/cache.rs @@ -2,8 +2,7 @@ use crate::{ module::{Module, ModuleInfo}, sys::Memory, }; -use digest::Digest; -use meowhash::MeowHasher; +use blake2::{Blake2b, Digest}; use std::{fmt, io, mem, slice}; #[derive(Debug)] @@ -45,7 +44,10 @@ impl WasmHash { pub fn generate(wasm: &[u8]) -> Self { let mut first_part = [0u8; 32]; let mut second_part = [0u8; 32]; - let generic_array = MeowHasher::digest(wasm); + + let mut hasher = Blake2b::new(); + hasher.input(wasm); + let generic_array = hasher.result(); first_part.copy_from_slice(&generic_array[0..32]); second_part.copy_from_slice(&generic_array[32..64]); From 2d49d58665f6447e1f82939c65ccbd0333b121c0 Mon Sep 17 00:00:00 2001 From: Syrus Date: Mon, 25 Feb 2019 17:43:25 -0800 Subject: [PATCH 26/42] Use blake2b (simd) version instead of blake2 --- Cargo.lock | 56 +++++++++++++---------------------- lib/runtime-core/Cargo.toml | 4 +-- lib/runtime-core/src/cache.rs | 7 ++--- 3 files changed, 25 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f8b6f496b..b2222ed55 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,6 +16,11 @@ dependencies = [ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "arrayref" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "arrayvec" version = "0.4.10" @@ -88,21 +93,16 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "blake2" -version = "0.8.0" +name = "blake2b_simd" +version = "0.4.1" 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)", - "crypto-mac 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)", - "opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "constant_time_eq 0.1.3 (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" @@ -186,6 +186,11 @@ dependencies = [ "cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "constant_time_eq" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "cranelift-bforest" version = "0.26.0" @@ -321,15 +326,6 @@ dependencies = [ "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "crypto-mac" -version = "0.7.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)", - "subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "csv" version = "1.0.5" @@ -615,11 +611,6 @@ dependencies = [ "libc 0.2.49 (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" @@ -1013,11 +1004,6 @@ dependencies = [ "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "subtle" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "syn" version = "0.13.11" @@ -1295,7 +1281,7 @@ dependencies = [ name = "wasmer-runtime-core" version = "0.2.0" dependencies = [ - "blake2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "blake2b_simd 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.8.0 (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)", @@ -1404,6 +1390,7 @@ dependencies = [ [metadata] "checksum aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1e9a933f4e58658d7b12defcf96dc5c720f20832deebe3e0a19efd3b6aaeeb9e" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +"checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee" "checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71" "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" @@ -1411,8 +1398,7 @@ dependencies = [ "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 blake2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "91721a6330935673395a0607df4d49a9cb90ae12d259f1b3e0a3f6e1d486872e" -"checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" +"checksum blake2b_simd 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ce2571a6cd634670daa2977cc894c1cc2ba57c563c498e5a82c35446f34d056e" "checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb" "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" @@ -1423,6 +1409,7 @@ dependencies = [ "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 constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e" "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" @@ -1435,7 +1422,6 @@ dependencies = [ "checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" "checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150" "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" -"checksum crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" "checksum csv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "9fd1c44c58078cfbeaf11fbb3eac9ae5534c23004ed770cc4bfb48e658ae4f04" "checksum csv-core 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa5cdef62f37e6ffe7d1f07a381bc0db32b7a3ff1cac0de56cb0d81e71f53d65" "checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c" @@ -1473,7 +1459,6 @@ dependencies = [ "checksum nom 4.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b30adc557058ce00c9d0d7cb3c6e0b5bc6f36e2e2eabe74b0ba726d194abd588" "checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" "checksum num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba" -"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" @@ -1521,7 +1506,6 @@ dependencies = [ "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 subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" "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 synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" diff --git a/lib/runtime-core/Cargo.toml b/lib/runtime-core/Cargo.toml index 5e89c7cde..00ac57189 100644 --- a/lib/runtime-core/Cargo.toml +++ b/lib/runtime-core/Cargo.toml @@ -29,8 +29,8 @@ version = "1.0" version = "0.10" [dependencies.serde-bench] version = "0.0.7" -[dependencies.blake2] -version = "0.8" +[dependencies.blake2b_simd] +version = "0.4.1" [dependencies.digest] version = "0.8.0" [dependencies.hashbrown] diff --git a/lib/runtime-core/src/cache.rs b/lib/runtime-core/src/cache.rs index d4d01edd9..ec2b0b01f 100644 --- a/lib/runtime-core/src/cache.rs +++ b/lib/runtime-core/src/cache.rs @@ -2,7 +2,7 @@ use crate::{ module::{Module, ModuleInfo}, sys::Memory, }; -use blake2::{Blake2b, Digest}; +use blake2b_simd::blake2b; use std::{fmt, io, mem, slice}; #[derive(Debug)] @@ -45,9 +45,8 @@ impl WasmHash { let mut first_part = [0u8; 32]; let mut second_part = [0u8; 32]; - let mut hasher = Blake2b::new(); - hasher.input(wasm); - let generic_array = hasher.result(); + let mut hasher = blake2b(wasm); + let generic_array = hasher.as_bytes(); first_part.copy_from_slice(&generic_array[0..32]); second_part.copy_from_slice(&generic_array[32..64]); From e6d0f91832662dada7a36cbf06e112843a5167a1 Mon Sep 17 00:00:00 2001 From: Syrus Date: Tue, 26 Feb 2019 01:12:34 -0800 Subject: [PATCH 27/42] Use blake2b SIMD version for increased performance --- lib/runtime-core/src/cache.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/runtime-core/src/cache.rs b/lib/runtime-core/src/cache.rs index ec2b0b01f..339b78fcc 100644 --- a/lib/runtime-core/src/cache.rs +++ b/lib/runtime-core/src/cache.rs @@ -2,7 +2,7 @@ use crate::{ module::{Module, ModuleInfo}, sys::Memory, }; -use blake2b_simd::blake2b; +use blake2b_simd::blake2bp; use std::{fmt, io, mem, slice}; #[derive(Debug)] @@ -45,7 +45,10 @@ impl WasmHash { let mut first_part = [0u8; 32]; let mut second_part = [0u8; 32]; - let mut hasher = blake2b(wasm); + let mut state = blake2bp::State::new(); + state.update(wasm); + + let mut hasher = state.finalize(); let generic_array = hasher.as_bytes(); first_part.copy_from_slice(&generic_array[0..32]); From 204d7a8d17a45ac22c4e19eb8ca4eff0cfa84532 Mon Sep 17 00:00:00 2001 From: Mark Roberts Date: Tue, 26 Feb 2019 20:17:48 +0800 Subject: [PATCH 28/42] Add nginx LICENSE --- examples/nginx/LICENSE | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 examples/nginx/LICENSE 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. + */ From d5aed446711bb6436f8a1c47d02527a2af0e6d15 Mon Sep 17 00:00:00 2001 From: Ryan Jacobs Date: Tue, 26 Feb 2019 13:16:06 -0800 Subject: [PATCH 29/42] bugfix: Replace echo with printf so "\n" renders. notes: I could have used the -e flag in echo, however other lines nearby use printf so I figured it would be smart to stay consistent. Also, I see the usage of `command printf`. Not 100% if this is necessary. I don't see why printf would be redefined in the shell. If we're doing this, then we might as well prefix every call to a builtin or binary with `command` _just to be safe_. --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" From f7197bf456299ffb70f3d755d59f513091b9a2da Mon Sep 17 00:00:00 2001 From: Syrus Date: Tue, 26 Feb 2019 15:39:54 -0800 Subject: [PATCH 30/42] Added debug build --- Cargo.toml | 2 +- Makefile | 5 ++++- lib/runtime/README.md | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 15b09e542..21bbfa60c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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/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")? From 2a7a8c0069917d1ce5a8738f8ff99f989418167a Mon Sep 17 00:00:00 2001 From: Mackenzie Clark Date: Wed, 27 Feb 2019 10:41:22 -0800 Subject: [PATCH 31/42] newline in test-module-imports.c --- lib/runtime-c-api/tests/test-module-imports.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runtime-c-api/tests/test-module-imports.c b/lib/runtime-c-api/tests/test-module-imports.c index 47757c58c..b63d308f2 100644 --- a/lib/runtime-c-api/tests/test-module-imports.c +++ b/lib/runtime-c-api/tests/test-module-imports.c @@ -53,4 +53,4 @@ int main() printf("Destroy imports\n"); wasmer_import_descriptors_destroy(imports); return 0; -} \ No newline at end of file +} From ff5e1320daf3b52902f2fb2f69f4d800f495d8f3 Mon Sep 17 00:00:00 2001 From: Mackenzie Clark Date: Wed, 27 Feb 2019 13:54:28 -0800 Subject: [PATCH 32/42] Fix casting errors cause io issues (#222) --- lib/emscripten/src/syscalls/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index 2143599f7..7c5ee578b 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -71,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 _ } @@ -84,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 @@ -241,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 From 95062d524ac56ce3229c2dc28248489c12954a63 Mon Sep 17 00:00:00 2001 From: Mackenzie Clark Date: Wed, 27 Feb 2019 14:20:53 -0800 Subject: [PATCH 33/42] commit virtual memory before copying (#212) --- lib/runtime-core/src/sys/windows/memory.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/runtime-core/src/sys/windows/memory.rs b/lib/runtime-core/src/sys/windows/memory.rs index d47388170..3ca86bec9 100644 --- a/lib/runtime-core/src/sys/windows/memory.rs +++ b/lib/runtime-core/src/sys/windows/memory.rs @@ -33,7 +33,7 @@ impl Memory { let protect = protection.to_protect_const(); - let ptr = unsafe { VirtualAlloc(ptr::null_mut(), size, MEM_RESERVE, protect) }; + let ptr = unsafe { VirtualAlloc(ptr::null_mut(), size, MEM_RESERVE | MEM_COMMIT, protect) }; if ptr.is_null() { Err("unable to allocate memory".to_string()) @@ -57,7 +57,14 @@ impl Memory { let size = round_up_to_page_size(size, page_size::get()); - let ptr = unsafe { VirtualAlloc(ptr::null_mut(), size, MEM_RESERVE, PAGE_NOACCESS) }; + let ptr = unsafe { + VirtualAlloc( + ptr::null_mut(), + size, + MEM_RESERVE | MEM_COMMIT, + PAGE_NOACCESS, + ) + }; if ptr.is_null() { Err(MemoryCreationError::VirtualMemoryAllocationFailed( From 60f8f15db37b004e005a368c23b343f0095aac97 Mon Sep 17 00:00:00 2001 From: Syrus Date: Wed, 27 Feb 2019 17:20:49 -0800 Subject: [PATCH 34/42] Updated version to 0.2.1 --- Cargo.lock | 30 +++++++++++++++--------------- Cargo.toml | 2 +- lib/emscripten/Cargo.toml | 4 ++-- lib/runtime-c-api/Cargo.toml | 6 +++--- lib/runtime-core/Cargo.toml | 2 +- lib/runtime/Cargo.toml | 4 ++-- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b2222ed55..6940f529c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1205,15 +1205,15 @@ dependencies = [ [[package]] name = "wasmer" -version = "0.2.0" +version = "0.2.1" 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.2.0", - "wasmer-emscripten 0.2.0", - "wasmer-runtime 0.2.0", - "wasmer-runtime-core 0.2.0", + "wasmer-emscripten 0.2.1", + "wasmer-runtime 0.2.1", + "wasmer-runtime-core 0.2.1", ] [[package]] @@ -1234,7 +1234,7 @@ dependencies = [ "serde_bytes 0.10.4 (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.2.0", + "wasmer-runtime-core 0.2.1", "wasmer-win-exception-handler 0.2.0", "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)", @@ -1242,7 +1242,7 @@ dependencies = [ [[package]] name = "wasmer-emscripten" -version = "0.2.0" +version = "0.2.1" 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)", @@ -1252,34 +1252,34 @@ dependencies = [ "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.2.0", - "wasmer-runtime-core 0.2.0", + "wasmer-runtime-core 0.2.1", ] [[package]] name = "wasmer-runtime" -version = "0.2.0" +version = "0.2.1" dependencies = [ "criterion 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-clif-backend 0.2.0", - "wasmer-runtime-core 0.2.0", + "wasmer-runtime-core 0.2.1", ] [[package]] name = "wasmer-runtime-c-api" -version = "0.2.0" +version = "0.2.1" 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.2.0", - "wasmer-runtime-core 0.2.0", + "wasmer-runtime 0.2.1", + "wasmer-runtime-core 0.2.1", ] [[package]] name = "wasmer-runtime-core" -version = "0.2.0" +version = "0.2.1" dependencies = [ "blake2b_simd 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1307,7 +1307,7 @@ version = "0.2.0" dependencies = [ "wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-clif-backend 0.2.0", - "wasmer-runtime-core 0.2.0", + "wasmer-runtime-core 0.2.1", ] [[package]] @@ -1318,7 +1318,7 @@ dependencies = [ "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.2.0", + "wasmer-runtime-core 0.2.1", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/Cargo.toml b/Cargo.toml index 21bbfa60c..85dddd1ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer" -version = "0.2.0" +version = "0.2.1" authors = ["The Wasmer Engineering Team "] edition = "2018" repository = "https://github.com/wasmerio/wasmer" diff --git a/lib/emscripten/Cargo.toml b/lib/emscripten/Cargo.toml index 1300eb124..62fb40c5a 100644 --- a/lib/emscripten/Cargo.toml +++ b/lib/emscripten/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer-emscripten" -version = "0.2.0" +version = "0.2.1" description = "Wasmer runtime emscripten implementation library" license = "MIT" authors = ["The Wasmer Engineering Team "] @@ -9,7 +9,7 @@ edition = "2018" build = "build/mod.rs" [dependencies] -wasmer-runtime-core = { path = "../runtime-core", version = "0.2.0" } +wasmer-runtime-core = { path = "../runtime-core", version = "0.2.1" } lazy_static = "1.2.0" libc = "0.2.49" byteorder = "1" diff --git a/lib/runtime-c-api/Cargo.toml b/lib/runtime-c-api/Cargo.toml index d2b327c22..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.2.0" +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.2.0" } -wasmer-runtime-core = { path = "../runtime-core", version = "0.2.0" } +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-core/Cargo.toml b/lib/runtime-core/Cargo.toml index 00ac57189..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.2.0" +version = "0.2.1" description = "Wasmer runtime core library" license = "MIT" authors = ["The Wasmer Engineering Team "] diff --git a/lib/runtime/Cargo.toml b/lib/runtime/Cargo.toml index f7aa32cb5..3ad8cbadc 100644 --- a/lib/runtime/Cargo.toml +++ b/lib/runtime/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer-runtime" -version = "0.2.0" +version = "0.2.1" description = "Wasmer runtime library" license = "MIT" authors = ["The Wasmer Engineering Team "] @@ -14,7 +14,7 @@ memmap = "0.7.0" [dependencies.wasmer-runtime-core] path = "../runtime-core" -version = "0.2.0" +version = "0.2.1" [dependencies.wasmer-clif-backend] path = "../clif-backend" From ea3d5b04d41b93aca2dd7b83f58246f098890764 Mon Sep 17 00:00:00 2001 From: David Calavera Date: Thu, 28 Feb 2019 19:16:22 -0800 Subject: [PATCH 35/42] Remove debug option from run command. I was looking into the code and I noticed that this option is not used. The `debug!` macro is used across the codebase, which looks more ideal. Signed-off-by: David Calavera --- src/bin/wasmer.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index d5364504b..e36e99cb6 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -33,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, From bde2022b581b80e35590c7b748932c8dccf6cf85 Mon Sep 17 00:00:00 2001 From: Mackenzie Clark Date: Fri, 1 Mar 2019 13:16:32 -0800 Subject: [PATCH 36/42] fix appveyor installer and build (#224) * remove exception handler when function returns or throws * revert to only reserving and not committing memory due to issues * appveyor builds for release, caches more, only publish artifact once --- .appveyor.yml | 24 ++++++++++--------- lib/runtime-core/src/sys/windows/memory.rs | 11 ++------- .../exception_handling/exception_handling.c | 14 ++++++++++- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 4ec05f8c7..2a67567e4 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -14,34 +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/lib/runtime-core/src/sys/windows/memory.rs b/lib/runtime-core/src/sys/windows/memory.rs index 3ca86bec9..d47388170 100644 --- a/lib/runtime-core/src/sys/windows/memory.rs +++ b/lib/runtime-core/src/sys/windows/memory.rs @@ -33,7 +33,7 @@ impl Memory { let protect = protection.to_protect_const(); - let ptr = unsafe { VirtualAlloc(ptr::null_mut(), size, MEM_RESERVE | MEM_COMMIT, protect) }; + let ptr = unsafe { VirtualAlloc(ptr::null_mut(), size, MEM_RESERVE, protect) }; if ptr.is_null() { Err("unable to allocate memory".to_string()) @@ -57,14 +57,7 @@ impl Memory { let size = round_up_to_page_size(size, page_size::get()); - let ptr = unsafe { - VirtualAlloc( - ptr::null_mut(), - size, - MEM_RESERVE | MEM_COMMIT, - PAGE_NOACCESS, - ) - }; + let ptr = unsafe { VirtualAlloc(ptr::null_mut(), size, MEM_RESERVE, PAGE_NOACCESS) }; if ptr.is_null() { Err(MemoryCreationError::VirtualMemoryAllocationFailed( 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; } From 2077fb448a84eddac39d38c5270d420a696c21c8 Mon Sep 17 00:00:00 2001 From: Brandon Fish Date: Sat, 2 Mar 2019 22:28:00 -0600 Subject: [PATCH 37/42] Fix C API table/global/memory imports --- lib/runtime-c-api/src/lib.rs | 44 +++++-- lib/runtime-c-api/tests/.gitignore | 1 + lib/runtime-c-api/tests/CMakeLists.txt | 4 + lib/runtime-c-api/tests/hello_wasm.wasm | Bin 0 -> 206 bytes lib/runtime-c-api/tests/test-imports.c | 154 ++++++++++++++++++++++++ 5 files changed, 193 insertions(+), 10 deletions(-) create mode 100644 lib/runtime-c-api/tests/hello_wasm.wasm create mode 100644 lib/runtime-c-api/tests/test-imports.c diff --git a/lib/runtime-c-api/src/lib.rs b/lib/runtime-c-api/src/lib.rs index 2fbf36cf8..5512c0287 100644 --- a/lib/runtime-c-api/src/lib.rs +++ b/lib/runtime-c-api/src/lib.rs @@ -454,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); @@ -806,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); diff --git a/lib/runtime-c-api/tests/.gitignore b/lib/runtime-c-api/tests/.gitignore index a39c13250..15e33d2cf 100644 --- a/lib/runtime-c-api/tests/.gitignore +++ b/lib/runtime-c-api/tests/.gitignore @@ -12,6 +12,7 @@ _deps test-globals test-exports test-instantiate +test-imports test-import-function test-memory test-module-imports diff --git a/lib/runtime-c-api/tests/CMakeLists.txt b/lib/runtime-c-api/tests/CMakeLists.txt index 697729580..6f899b5b5 100644 --- a/lib/runtime-c-api/tests/CMakeLists.txt +++ b/lib/runtime-c-api/tests/CMakeLists.txt @@ -1,6 +1,7 @@ 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) @@ -21,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 @@ -43,6 +46,7 @@ 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) 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 0000000000000000000000000000000000000000..b2287be036ed768bfd608c1a1583fdeb72cf160d GIT binary patch literal 206 zcmXAjK?=e!6h!C$NQH)q=miwJbnU)7Z{YH`V!+lml_n^z(j#~zk7lZ~7={NA29@gw zF^lB#YHNFYj~|`^l&O+KKnV&Zzz3y_eWY?9YU{=M0hmB0(wVLwUUIISQQ-%ZKVpom z6cZIuPblBTCS#TdwIq~pmf72b||tXqPU*svdL*j#TfrJ UIcvS9NOg9cto`QH5A9|91+J +#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; +} From ec4e476cc6aefe8a01544e0c216f5e0b8583e71d Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 4 Mar 2019 13:51:13 +0100 Subject: [PATCH 38/42] fix(runtime-core) Remove an unused import. This patch removes an unused import, namely `crate::sys::Memory`. --- lib/runtime-core/src/error.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/runtime-core/src/error.rs b/lib/runtime-core/src/error.rs index abc69cc5e..0e2ab6eb7 100644 --- a/lib/runtime-core/src/error.rs +++ b/lib/runtime-core/src/error.rs @@ -1,4 +1,3 @@ -use crate::sys::Memory; use crate::types::{ FuncSig, GlobalDescriptor, MemoryDescriptor, MemoryIndex, TableDescriptor, TableIndex, Type, }; From d9073c03c65a899647dee667ebcdd336a53288b9 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 4 Mar 2019 13:53:41 +0100 Subject: [PATCH 39/42] fix(runtime-core) `hasher` does not need to be mutable. This patch updates the `hasher` variable. It is declared as mutable, but it's never mutated. --- lib/runtime-core/src/cache.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runtime-core/src/cache.rs b/lib/runtime-core/src/cache.rs index 339b78fcc..1cb804655 100644 --- a/lib/runtime-core/src/cache.rs +++ b/lib/runtime-core/src/cache.rs @@ -48,7 +48,7 @@ impl WasmHash { let mut state = blake2bp::State::new(); state.update(wasm); - let mut hasher = state.finalize(); + let hasher = state.finalize(); let generic_array = hasher.as_bytes(); first_part.copy_from_slice(&generic_array[0..32]); From 42c9bdf8c233a87ff5434d313fe917f142401e4f Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 4 Mar 2019 13:59:37 +0100 Subject: [PATCH 40/42] fix(clif-backend) Remove an unused variable declaration. The `compiled_functions` variable is declared twice. The first declaration is never used. This patch removes it. --- lib/clif-backend/src/resolver.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/clif-backend/src/resolver.rs b/lib/clif-backend/src/resolver.rs index 53b3a789a..dce331b58 100644 --- a/lib/clif-backend/src/resolver.rs +++ b/lib/clif-backend/src/resolver.rs @@ -94,7 +94,6 @@ impl FuncResolverBuilder { info: &ModuleInfo, ) -> CompileResult<(Self, HandlerData)> { let num_func_bodies = function_bodies.len(); - let mut compiled_functions: Vec<(Vec, RelocSink)> = Vec::with_capacity(num_func_bodies); let mut local_relocs = Map::with_capacity(num_func_bodies); let mut external_relocs = Map::with_capacity(num_func_bodies); From 5744f6896ff44c3c7c57630d3fff040714ac3c47 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 4 Mar 2019 14:03:07 +0100 Subject: [PATCH 41/42] fix(clif-backend) `Module::new` does not use its argument. The `Module::new` method requires an argument (`wasm: &[u8]`) that is never used. This patch removes the argument, and updates the code accordingly. --- lib/clif-backend/src/lib.rs | 2 +- lib/clif-backend/src/module.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/clif-backend/src/lib.rs b/lib/clif-backend/src/lib.rs index c4abf644f..88de51e12 100644 --- a/lib/clif-backend/src/lib.rs +++ b/lib/clif-backend/src/lib.rs @@ -44,7 +44,7 @@ impl Compiler for CraneliftCompiler { let isa = get_isa(); - let mut module = module::Module::new(wasm); + let mut module = module::Module::new(); let module_env = module_env::ModuleEnv::new(&mut module, &*isa); let func_bodies = module_env.translate(wasm)?; diff --git a/lib/clif-backend/src/module.rs b/lib/clif-backend/src/module.rs index 07efe9bd3..9e934ee0a 100644 --- a/lib/clif-backend/src/module.rs +++ b/lib/clif-backend/src/module.rs @@ -25,7 +25,7 @@ pub struct Module { } impl Module { - pub fn new(wasm: &[u8]) -> Self { + pub fn new() -> Self { Self { info: ModuleInfo { memories: Map::new(), From 65ec10961b611468a042712d1cfc7a5871dbbfbf Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Mon, 4 Mar 2019 12:57:26 -0800 Subject: [PATCH 42/42] Change RuntimeError type (#234) * Change RuntimeError type and fix codebase to use it * Fix spectests to work with new runtime error type * Fix windows signal handler in the clif-backend * Add missing conversion * final windows fix --- lib/clif-backend/src/signal/mod.rs | 8 ++-- lib/clif-backend/src/signal/unix.rs | 38 ++++++++--------- lib/clif-backend/src/signal/windows.rs | 43 +++++++++---------- lib/runtime-core/src/backend.rs | 4 +- lib/runtime-core/src/error.rs | 59 ++++++-------------------- lib/runtime-core/src/typed_func.rs | 26 ++++-------- lib/spectests/build/spectests.rs | 2 +- lib/spectests/tests/semantics.rs | 2 +- 8 files changed, 70 insertions(+), 112 deletions(-) diff --git a/lib/clif-backend/src/signal/mod.rs b/lib/clif-backend/src/signal/mod.rs index 9ccbf1822..7ec33d0e1 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/runtime-core/src/backend.rs b/lib/runtime-core/src/backend.rs index e88383800..17266f2a5 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::*; @@ -78,7 +78,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/error.rs b/lib/runtime-core/src/error.rs index 0e2ab6eb7..f1291448f 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\""), } } } @@ -239,7 +206,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), @@ -298,7 +265,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), 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/spectests/build/spectests.rs b/lib/spectests/build/spectests.rs index 54d9404d6..01e9c52dc 100644 --- a/lib/spectests/build/spectests.rs +++ b/lib/spectests/build/spectests.rs @@ -568,7 +568,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")); }