diff --git a/Cargo.lock b/Cargo.lock index 08497cae6..f823bcd2c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,11 +4,11 @@ version = 4 [[package]] name = "addr2line" -version = "0.25.1" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5d307320b3181d6d7954e663bd7c774a838b8220fe0593c86d9fb09f498b4b" +checksum = "59317f77929f0e679d39364702289274de2f0f0b22cbf50b2b8cff2169a0b27a" dependencies = [ - "gimli", + "gimli 0.33.0", ] [[package]] @@ -376,9 +376,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.19.0" +version = "3.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" +checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" dependencies = [ "allocator-api2", ] @@ -585,46 +585,48 @@ dependencies = [ [[package]] name = "cranelift-assembler-x64" -version = "0.127.4" +version = "0.130.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6abf69c884fde2d9d4cc232a585fb18f16af3ae04c634315c84ebe158ded92d" +checksum = "046d4b584c3bb9b5eb500c8f29549bec36be11000f1ba2a927cef3d1a9875691" dependencies = [ "cranelift-assembler-x64-meta", ] [[package]] name = "cranelift-assembler-x64-meta" -version = "0.127.4" +version = "0.130.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "263d31fcdf83a10267e8c38b53bc8f7688dfbc331267fd8fdf5b22e0dc47a55b" +checksum = "b9b194a7870becb1490366fc0ae392ccd188065ff35f8391e77ac659db6fb977" dependencies = [ "cranelift-srcgen", ] [[package]] name = "cranelift-bforest" -version = "0.127.4" +version = "0.130.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d459d5377c01c4472b71029caa2df41afaf47711676aa9b12d7414f15104637b" +checksum = "bb6a4ab44c6b371e661846b97dab687387a60ac4e2f864e2d4257284aad9e889" dependencies = [ "cranelift-entity", + "wasmtime-internal-core", ] [[package]] name = "cranelift-bitset" -version = "0.127.4" +version = "0.130.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8283088d5823ba7856ab8d531b7c3654b24984748f9fd99dcf3210701fd1d065" +checksum = "b8b7a44150c2f471a94023482bda1902710746e4bed9f9973d60c5a94319b06d" dependencies = [ "serde", "serde_derive", + "wasmtime-internal-core", ] [[package]] name = "cranelift-codegen" -version = "0.127.4" +version = "0.130.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d3138316d8dd341d725d6ab1598750545c76ad32892837fde558edd68a01b43" +checksum = "01b06598133b1dd76758b8b95f8d6747c124124aade50cea96a3d88b962da9fa" dependencies = [ "bumpalo", "cranelift-assembler-x64", @@ -635,8 +637,9 @@ dependencies = [ "cranelift-control", "cranelift-entity", "cranelift-isle", - "gimli", - "hashbrown 0.15.5", + "gimli 0.33.0", + "hashbrown 0.16.1", + "libm", "log", "pulley-interpreter", "regalloc2", @@ -644,14 +647,14 @@ dependencies = [ "serde", "smallvec", "target-lexicon", - "wasmtime-internal-math", + "wasmtime-internal-core", ] [[package]] name = "cranelift-codegen-meta" -version = "0.127.4" +version = "0.130.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "505cead19304a8dc8689e31b29038775c3f73f9d5ea7a5e33864437a1f46c6b6" +checksum = "6190e2e7bcf0a678da2f715363d34ed530fedf7a2f0ab75edaefef72a70465ff" dependencies = [ "cranelift-assembler-x64-meta", "cranelift-codegen-shared", @@ -662,35 +665,36 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" -version = "0.127.4" +version = "0.130.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce62ba94f570644ce7de6ed05bd39ca28936665dec10a2a1f6f2c531d6add45c" +checksum = "f583cf203d1aa8b79560e3b01f929bdacf9070b015eec4ea9c46e22a3f83e4a0" [[package]] name = "cranelift-control" -version = "0.127.4" +version = "0.130.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db6cfe339689c3926412a7060ab00ef3b2b43d936b537e7a3f696121be9d0eaa" +checksum = "803159df35cc398ae54473c150b16d6c77e92ab2948be638488de126a3328fbc" dependencies = [ "arbitrary", ] [[package]] name = "cranelift-entity" -version = "0.127.4" +version = "0.130.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "625518090e912bdfe3c41464bf97ae421f6044d4ca0f5c3267dcacdb352b033d" +checksum = "3109e417257082d88087f5bcce677525bdaa8322b88dd7f175ed1a1fd41d546c" dependencies = [ "cranelift-bitset", "serde", "serde_derive", + "wasmtime-internal-core", ] [[package]] name = "cranelift-frontend" -version = "0.127.4" +version = "0.130.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17f652d40ddf3afb55be64d8979d312b52b384a8cebbcde1dd1c2e32ebcd4466" +checksum = "14db6b0e0e4994c581092df78d837be2072578f7cb2528f96a6cf895e56dee63" dependencies = [ "cranelift-codegen", "log", @@ -700,15 +704,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.127.4" +version = "0.130.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f512767e83015f4baf6e732cabca93cea82907e3ab237f826ef64f7ece75eb6" +checksum = "ec66ea5025c7317383699778282ac98741d68444f956e3b1d7b62f12b7216e67" [[package]] name = "cranelift-native" -version = "0.127.4" +version = "0.130.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb1ca6e4dca568ff988d367e4707be2362cee9782265b0a501eaf467ffd550a8" +checksum = "373ade56438e6232619d85678477d0a88a31b3581936e0503e61e96b546b0800" dependencies = [ "cranelift-codegen", "libc", @@ -717,9 +721,9 @@ dependencies = [ [[package]] name = "cranelift-srcgen" -version = "0.127.4" +version = "0.130.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97400ad8fbd3a434092fc0b486fa7784150b53187941d818b1087f3ac0a547f0" +checksum = "ef53619d3cd5c78fd998c6d9420547af26b72e6456f94c2a8a2334cb76b42baa" [[package]] name = "crc32fast" @@ -1284,12 +1288,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foldhash" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" - [[package]] name = "foldhash" version = "0.2.0" @@ -1446,6 +1444,18 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "gimli" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf7f043f89559805f8c7cacc432749b2fa0d0a0a9ee46ce47164ed5ba7f126c" +dependencies = [ + "fnv", + "hashbrown 0.16.1", + "indexmap", + "stable_deref_trait", +] + [[package]] name = "glob" version = "0.3.3" @@ -1511,10 +1521,6 @@ name = "hashbrown" version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" -dependencies = [ - "foldhash 0.1.5", - "serde", -] [[package]] name = "hashbrown" @@ -1522,7 +1528,7 @@ version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" dependencies = [ - "foldhash 0.2.0", + "foldhash", "serde", "serde_core", ] @@ -2291,12 +2297,12 @@ dependencies = [ [[package]] name = "object" -version = "0.37.3" +version = "0.38.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff76201f031d8863c38aa7f905eca4f53abbfa15f609db4277d44cd8938f33fe" +checksum = "271638cd5fa9cca89c4c304675ca658efc4e64a66c716b7cfe1afb4b9611dbbc" dependencies = [ "crc32fast", - "hashbrown 0.15.5", + "hashbrown 0.16.1", "indexmap", "memchr", ] @@ -2731,21 +2737,21 @@ checksum = "33cb294fe86a74cbcf50d4445b37da762029549ebeea341421c7c70370f86cac" [[package]] name = "pulley-interpreter" -version = "40.0.4" +version = "43.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5de307c194cf6310d486dd5595ffc329c53b4acafd54e214752c1eb2e68be3a9" +checksum = "010dec3755eb61b2f1051ecb3611b718460b7a74c131e474de2af20a845938af" dependencies = [ "cranelift-bitset", "log", "pulley-macros", - "wasmtime-internal-math", + "wasmtime-internal-core", ] [[package]] name = "pulley-macros" -version = "40.0.4" +version = "43.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99dca2747e910d10bafe911e172a1b35860268421c3ee5ddb7e16c35e0288b4a" +checksum = "ad360c32e85ca4b083ac0e2b6856e8f11c3d5060dafa7d5dc57b370857fa3018" dependencies = [ "proc-macro2", "quote", @@ -2926,9 +2932,9 @@ dependencies = [ [[package]] name = "regalloc2" -version = "0.13.5" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08effbc1fa53aaebff69521a5c05640523fab037b34a4a2c109506bc938246fa" +checksum = "952ddbfc6f9f64d006c3efd8c9851a6ba2f2b944ba94730db255d55006e0ffda" dependencies = [ "allocator-api2", "bumpalo", @@ -4055,13 +4061,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e151599d689dac80e85c66a7cfa6ffd1b2ab79220517f9161040a87a5041aee3" dependencies = [ "anyhow", - "gimli", + "gimli 0.32.3", "id-arena", "leb128", "log", "walrus-macro", - "wasm-encoder 0.245.1", - "wasmparser 0.245.1", + "wasm-encoder", + "wasmparser", ] [[package]] @@ -4185,16 +4191,6 @@ version = "0.2.117" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c29582b14d5bf030b02fa232b9b57faf2afc322d2c61964dd80bad02bf76207" -[[package]] -name = "wasm-encoder" -version = "0.243.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c55db9c896d70bd9fa535ce83cd4e1f2ec3726b0edd2142079f594fc3be1cb35" -dependencies = [ - "leb128fmt", - "wasmparser 0.243.0", -] - [[package]] name = "wasm-encoder" version = "0.245.1" @@ -4202,20 +4198,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9dca005e69bf015e45577e415b9af8c67e8ee3c0e38b5b0add5aa92581ed5c" dependencies = [ "leb128fmt", - "wasmparser 0.245.1", -] - -[[package]] -name = "wasmparser" -version = "0.243.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6d8db401b0528ec316dfbe579e6ab4152d61739cfe076706d2009127970159d" -dependencies = [ - "bitflags 2.11.0", - "hashbrown 0.15.5", - "indexmap", - "semver 1.0.27", - "serde", + "wasmparser", ] [[package]] @@ -4233,30 +4216,27 @@ dependencies = [ [[package]] name = "wasmprinter" -version = "0.243.0" +version = "0.245.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb2b6035559e146114c29a909a3232928ee488d6507a1504d8934e8607b36d7b" +checksum = "5f41517a3716fbb8ccf46daa9c1325f760fcbff5168e75c7392288e410b91ac8" dependencies = [ "anyhow", "termcolor", - "wasmparser 0.243.0", + "wasmparser", ] [[package]] name = "wasmtime" -version = "40.0.4" +version = "43.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0702b64d4c3fe43ae4ce229e06af06a27783e48c519e68586d180717cdd24314" +checksum = "ce205cd643d661b5ba5ba4717e13730262e8cdbc8f2eacbc7b906d45c1a74026" dependencies = [ "addr2line", - "anyhow", "async-trait", "bitflags 2.11.0", "bumpalo", "cc", "cfg-if", - "hashbrown 0.15.5", - "indexmap", "libc", "log", "mach2", @@ -4271,14 +4251,13 @@ dependencies = [ "serde_derive", "smallvec", "target-lexicon", - "wasmparser 0.243.0", + "wasmparser", "wasmtime-environ", + "wasmtime-internal-core", "wasmtime-internal-cranelift", "wasmtime-internal-fiber", "wasmtime-internal-jit-debug", "wasmtime-internal-jit-icache-coherence", - "wasmtime-internal-math", - "wasmtime-internal-slab", "wasmtime-internal-unwinder", "wasmtime-internal-versioned-export-macros", "windows-sys 0.61.2", @@ -4286,41 +4265,55 @@ dependencies = [ [[package]] name = "wasmtime-environ" -version = "40.0.4" +version = "43.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ffeb777a21965a85e4b1ce7b308c63ba130df91912096b49b95523bf3bdd2c7" +checksum = "0b8b78abf3677d4a0a5db82e5015b4d085ff3a1b8b472cbb8c70d4b769f019ce" dependencies = [ "anyhow", + "cranelift-bforest", "cranelift-bitset", "cranelift-entity", - "gimli", + "gimli 0.33.0", + "hashbrown 0.16.1", "indexmap", "log", "object", "postcard", "serde", "serde_derive", + "sha2 0.10.9", "smallvec", "target-lexicon", - "wasm-encoder 0.243.0", - "wasmparser 0.243.0", + "wasm-encoder", + "wasmparser", "wasmprinter", + "wasmtime-internal-core", +] + +[[package]] +name = "wasmtime-internal-core" +version = "43.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22632b187e1b0716f1b9ac57ad29013bed33175fcb19e10bb6896126f82fac67" +dependencies = [ + "hashbrown 0.16.1", + "libm", + "serde", ] [[package]] name = "wasmtime-internal-cranelift" -version = "40.0.4" +version = "43.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85da1ba5fee01a3ee21c4d0c8052cc9035388639fa091a969b534d4c6f8449d4" +checksum = "8b3ca07b3e0bb3429674b173b5800577719d600774dd81bff58f775c0aaa64ee" dependencies = [ - "anyhow", "cfg-if", "cranelift-codegen", "cranelift-control", "cranelift-entity", "cranelift-frontend", "cranelift-native", - "gimli", + "gimli 0.33.0", "itertools 0.14.0", "log", "object", @@ -4328,33 +4321,33 @@ dependencies = [ "smallvec", "target-lexicon", "thiserror 2.0.18", - "wasmparser 0.243.0", + "wasmparser", "wasmtime-environ", - "wasmtime-internal-math", + "wasmtime-internal-core", "wasmtime-internal-unwinder", "wasmtime-internal-versioned-export-macros", ] [[package]] name = "wasmtime-internal-fiber" -version = "40.0.4" +version = "43.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c7de5a0872764c1ca640886af10a70cf7f8526386906245b43cdb345ece0e6" +checksum = "20c8b2c9704eb1f33ead025ec16038277ccb63d0a14c31e99d5b765d7c36da55" dependencies = [ - "anyhow", "cc", "cfg-if", "libc", "rustix 1.1.2", + "wasmtime-environ", "wasmtime-internal-versioned-export-macros", "windows-sys 0.61.2", ] [[package]] name = "wasmtime-internal-jit-debug" -version = "40.0.4" +version = "43.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "160acd973d770d62bef1b2697d7fac83a8fe63ef966215e624382b2a9532bd58" +checksum = "d950310d07391d34369f62c48336ebb14eacbd4d6f772bb5f349c24e838e0664" dependencies = [ "cc", "wasmtime-internal-versioned-export-macros", @@ -4362,49 +4355,34 @@ dependencies = [ [[package]] name = "wasmtime-internal-jit-icache-coherence" -version = "40.0.4" +version = "43.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc57f590ba7ea967ea9e8c8560175c6926e5b15d11c29bbde3ad0013a29470eb" +checksum = "3606662c156962d096be3127b8b8ae8ee2f8be3f896dad29259ff01ddb64abfd" dependencies = [ - "anyhow", "cfg-if", "libc", + "wasmtime-internal-core", "windows-sys 0.61.2", ] -[[package]] -name = "wasmtime-internal-math" -version = "40.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07612904518d47b677e8db67ca47c16d8c8cefb0099020729f886776950cb58b" -dependencies = [ - "libm", -] - -[[package]] -name = "wasmtime-internal-slab" -version = "40.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc83ff16531e1e1537e0de2b630af56a0a9e1fab864130c5b7e213da71783a0f" - [[package]] name = "wasmtime-internal-unwinder" -version = "40.0.4" +version = "43.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47371d697244785e4bbb371229f9a2daa8628d1e03368ec895cf658370e1bf38" +checksum = "75eef0747e52dc545b075f64fd0e0cc237ae738e641266b1970e07e2d744bc32" dependencies = [ - "anyhow", "cfg-if", "cranelift-codegen", "log", "object", + "wasmtime-environ", ] [[package]] name = "wasmtime-internal-versioned-export-macros" -version = "40.0.4" +version = "43.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad3cd4aff8f2e7ec658c7a0424b74ad88a6940505303fb0616323592a1c400a6" +checksum = "d8b0a5dab02a8fb527f547855ecc0e05f9fdc3d5bd57b8b080349408f9a6cece" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 7ab8fb608..e3a4da952 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -106,7 +106,7 @@ walrus = "0.26.1" wasm-bindgen = "0.2.117" wasm-bindgen-test = "0.3.67" wasm-opt = "0.116.1" -wasmtime = { version = "40.0.4", default-features = false } +wasmtime = { version = "43.0.1", default-features = false } x509-parser = "0.18.0" yansi = "1.0.1" yara-x = { path = "lib", version = "1.15.0" } diff --git a/lib/src/compiler/errors.rs b/lib/src/compiler/errors.rs index 5b8447d39..62aa50421 100644 --- a/lib/src/compiler/errors.rs +++ b/lib/src/compiler/errors.rs @@ -652,7 +652,7 @@ pub struct InvalidModifier { #[associated_enum(CompileError)] #[error(code = "E034", title = "potentially slow loop")] #[label( -"this range can be very large", + "this range can be very large", loc )] pub struct PotentiallySlowLoop { diff --git a/lib/src/compiler/rules.rs b/lib/src/compiler/rules.rs index c6d533587..690dbb97a 100644 --- a/lib/src/compiler/rules.rs +++ b/lib/src/compiler/rules.rs @@ -6,6 +6,7 @@ use std::slice::Iter; use std::time::Instant; use aho_corasick::AhoCorasick; +use anyhow::anyhow; #[cfg(feature = "logging")] use log::*; use regex_automata::meta::Regex; @@ -225,11 +226,13 @@ impl Rules { #[cfg(feature = "logging")] let start = Instant::now(); - rules.compiled_wasm_mod = - Some(wasm::runtime::Module::from_binary( + rules.compiled_wasm_mod = Some( + wasm::runtime::Module::from_binary( wasm::get_engine(), rules.wasm_mod.as_slice(), - )?); + ) + .map_err(|e| SerializationError::from(anyhow!(e)))?, + ); #[cfg(feature = "logging")] info!("WASM build time: {:?}", Instant::elapsed(&start)); diff --git a/lib/src/wasm/mod.rs b/lib/src/wasm/mod.rs index c1173f8b6..87081599c 100644 --- a/lib/src/wasm/mod.rs +++ b/lib/src/wasm/mod.rs @@ -99,8 +99,8 @@ use crate::types::{ }; use crate::wasm::integer::RangedInteger; use crate::wasm::runtime::{ - AsContext, AsContextMut, Caller, Config, Engine, FuncType, Linker, ValRaw, - ValType, + AsContext, AsContextMut, Caller, Config, Engine, FuncType, Linker, + Trampoline, TrampolineResult, ValRaw, ValType, }; use crate::wasm::string::RuntimeString; use crate::wasm::string::String as _; @@ -279,7 +279,7 @@ impl WasmExport { pub(crate) trait WasmExportedFn { /// Returns the function that will be passed to the selected runtime linker /// while linking the WASM code to this function. - fn trampoline(&'static self) -> TrampolineFn; + fn trampoline(&'static self) -> Trampoline>; /// Returns a [`Vec`] with the types of the function's /// arguments @@ -302,13 +302,6 @@ pub(crate) trait WasmExportedFn { } } -type TrampolineFn = Box< - dyn Fn(Caller<'_, ScanContext>, &mut [ValRaw]) -> anyhow::Result<()> - + Send - + Sync - + 'static, ->; - const MAX_RESULTS: usize = 4; type WasmResultArray = SmallVec<[T; MAX_RESULTS]>; @@ -689,11 +682,11 @@ macro_rules! impl_wasm_exported_fn { #[allow(unused_variables)] #[allow(non_snake_case)] #[allow(unused_mut)] - fn trampoline(&'static self) -> TrampolineFn { + fn trampoline(&'static self) -> Trampoline> { Box::new( |mut caller: Caller<'_, ScanContext>, args_and_results: &mut [ValRaw]| - -> anyhow::Result<()> { + -> TrampolineResult { let mut i = 0; $( let $args = args_and_results[i].raw_into(caller.data_mut()); @@ -707,7 +700,8 @@ macro_rules! impl_wasm_exported_fn { let num_results = result_slice.len(); args_and_results[0..num_results].clone_from_slice(result_slice); - anyhow::Ok(()) + + TrampolineResult::Ok(()) }, ) } diff --git a/lib/src/wasm/runtime/browser.rs b/lib/src/wasm/runtime/browser.rs index d0f061500..5e80d941a 100644 --- a/lib/src/wasm/runtime/browser.rs +++ b/lib/src/wasm/runtime/browser.rs @@ -40,6 +40,9 @@ pub(crate) use super::common::{ ValType, }; +pub(crate) type Trampoline = common::Trampoline; +pub(crate) type TrampolineResult = common::TrampolineResult; + struct GlobalInner { val_type: ValType, mutability: Mutability, diff --git a/lib/src/wasm/runtime/common.rs b/lib/src/wasm/runtime/common.rs index b1a8381bd..26f1a22fb 100644 --- a/lib/src/wasm/runtime/common.rs +++ b/lib/src/wasm/runtime/common.rs @@ -529,6 +529,15 @@ pub(crate) struct Linker { _phantom: PhantomData, } +pub(crate) type Trampoline = Box< + dyn Fn(Caller<'_, T, B>, &mut [ValRaw]) -> TrampolineResult + + Send + + Sync + + 'static, +>; + +pub(crate) type TrampolineResult = Result<()>; + impl Linker { /// Creates an empty linker. /// @@ -552,13 +561,8 @@ impl Linker { name: &str, ty: FuncType, sync_flags: u32, - trampoline: Box< - dyn Fn(Caller<'_, T, B>, &mut [ValRaw]) -> Result<()> - + Send - + Sync - + 'static, - >, - ) -> Result<()> { + trampoline: Trampoline, + ) -> TrampolineResult { // This mirrors Wasmtime's unchecked registration API. The generated // WASM determines the ABI, so the runtime only needs to record the // metadata and trampoline here. @@ -571,7 +575,8 @@ impl Linker { sync_flags, trampoline: Arc::from(trampoline), }); - Ok(()) + + TrampolineResult::Ok(()) } /// Defines an extern import. diff --git a/lib/src/wasm/runtime/native.rs b/lib/src/wasm/runtime/native.rs index 9b929010d..4be78e3c0 100644 --- a/lib/src/wasm/runtime/native.rs +++ b/lib/src/wasm/runtime/native.rs @@ -3,8 +3,9 @@ //! This adapter exists only to normalize a couple of APIs so the rest of the //! crate can talk to native and custom runtimes through the same interface. -use anyhow::Result; - +use crate::errors::SerializationError; +use anyhow::anyhow; +use std::mem::transmute; /// Wasmtime types re-exported by the native runtime. pub(crate) use wasmtime::{ AsContext, AsContextMut, Caller, Config, Engine, Extern, FuncType, Global, @@ -15,8 +16,14 @@ pub(crate) use wasmtime::{ /// Thin wrapper around [`wasmtime::Linker`] with a backend-neutral API. pub(crate) struct Linker(wasmtime::Linker); -type Trampoline = - dyn Fn(Caller<'_, T>, &mut [ValRaw]) -> Result<()> + Send + Sync + 'static; +pub(crate) type Trampoline = Box< + dyn Fn(Caller<'_, T>, &mut [ValRaw]) -> TrampolineResult + + Send + + Sync + + 'static, +>; + +pub(crate) type TrampolineResult = wasmtime::Result<()>; impl Linker { /// Creates a new linker. @@ -35,11 +42,21 @@ impl Linker { name: &str, ty: FuncType, sync_flags: u32, - trampoline: Box>, - ) -> Result<()> { + trampoline: Trampoline, + ) -> TrampolineResult { let _ = sync_flags; unsafe { - self.0.func_new_unchecked(module, name, ty, trampoline).map(|_| ()) + self.0 + .func_new_unchecked(module, name, ty, move |caller, args| { + trampoline( + caller, + transmute::< + &mut [std::mem::MaybeUninit], + &mut [ValRaw], + >(args), + ) + }) + .map(|_| ()) } } @@ -50,7 +67,7 @@ impl Linker { module: &str, name: &str, item: impl Into, - ) -> Result<&mut Self> { + ) -> wasmtime::Result<&mut Self> { self.0.define(store, module, name, item)?; Ok(self) } @@ -60,7 +77,9 @@ impl Linker { &self, store: impl AsContextMut, module: &Module, - ) -> Result { - self.0.instantiate(store, module) + ) -> Result { + self.0 + .instantiate(store, module) + .map_err(|e| SerializationError::InvalidWASM(anyhow!(e))) } } diff --git a/ls/src/features/diagnostics.rs b/ls/src/features/diagnostics.rs index 40cd39e83..93d4ad443 100644 --- a/ls/src/features/diagnostics.rs +++ b/ls/src/features/diagnostics.rs @@ -163,7 +163,7 @@ pub fn compiler_diagnostics( |meta| { matches!( meta.value, - yara_x_parser::ast::MetaValue::Float(_) + yara_x_parser::ast::MetaValue::Bool(_) ) }, format!(