diff --git a/Cargo.lock b/Cargo.lock index d0905afc35..f4218d1faa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -121,6 +121,12 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +[[package]] +name = "arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" + [[package]] name = "arm-gic" version = "0.1.0" @@ -294,7 +300,7 @@ version = "4.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c780290ccf4fb26629baa7a1081e68ced113f1d3ec302fa5948f1c381ebf06c6" dependencies = [ - "heck", + "heck 0.5.0", "proc-macro2", "quote", "syn 2.0.66", @@ -306,6 +312,12 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" +[[package]] +name = "cobs" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" + [[package]] name = "colorchoice" version = "1.0.1" @@ -327,6 +339,116 @@ version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +[[package]] +name = "cranelift-bforest" +version = "0.108.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29daf137addc15da6bab6eae2c4a11e274b1d270bf2759508e62f6145e863ef6" +dependencies = [ + "cranelift-entity", +] + +[[package]] +name = "cranelift-codegen" +version = "0.108.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de619867d5de4c644b7fd9904d6e3295269c93d8a71013df796ab338681222d4" +dependencies = [ + "bumpalo", + "cranelift-bforest", + "cranelift-codegen-meta", + "cranelift-codegen-shared", + "cranelift-control", + "cranelift-entity", + "cranelift-isle", + "gimli", + "hashbrown 0.14.5", + "log", + "regalloc2", + "rustc-hash", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.108.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29f5cf277490037d8dae9513d35e0ee8134670ae4a964a5ed5b198d4249d7c10" +dependencies = [ + "cranelift-codegen-shared", +] + +[[package]] +name = "cranelift-codegen-shared" +version = "0.108.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3e22ecad1123343a3c09ac6ecc532bb5c184b6fcb7888df0ea953727f79924" + +[[package]] +name = "cranelift-control" +version = "0.108.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53ca3ec6d30bce84ccf59c81fead4d16381a3ef0ef75e8403bc1e7385980da09" +dependencies = [ + "arbitrary", +] + +[[package]] +name = "cranelift-entity" +version = "0.108.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eabb8d36b0ca8906bec93c78ea516741cac2d7e6b266fa7b0ffddcc09004990" +dependencies = [ + "serde", + "serde_derive", +] + +[[package]] +name = "cranelift-frontend" +version = "0.108.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44b42630229e49a8cfcae90bdc43c8c4c08f7a7aa4618b67f79265cd2f996dd2" +dependencies = [ + "cranelift-codegen", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-isle" +version = "0.108.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "918d1e36361805dfe0b6cdfd5a5ffdb5d03fa796170c5717d2727cbe623b93a0" + +[[package]] +name = "cranelift-native" +version = "0.108.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75aea85a0d7e1800b14ce9d3f53adf8ad4d1ee8a9e23b0269bdc50285e93b9b3" +dependencies = [ + "cranelift-codegen", + "libc", + "target-lexicon", +] + +[[package]] +name = "cranelift-wasm" +version = "0.108.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dac491fd3473944781f0cf9528c90cc899d18ad438da21961a839a3a44d57dfb" +dependencies = [ + "cranelift-codegen", + "cranelift-entity", + "cranelift-frontend", + "itertools", + "log", + "smallvec", + "wasmparser", + "wasmtime-types", +] + [[package]] name = "crc32fast" version = "1.4.2" @@ -426,6 +548,21 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "361a90feb7004eca4019fb28352a9465666b24f840f5c3cddf0ff13920590b89" +[[package]] +name = "embedded-io" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + [[package]] name = "endian-num" version = "0.1.1" @@ -437,6 +574,22 @@ dependencies = [ "zerocopy-derive", ] +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys", +] + [[package]] name = "event-listener" version = "5.3.1" @@ -463,6 +616,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5b9e9908e50b47ebbc3d6fd66ed295b997c270e8d2312a035bcc62722a160ef" +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + [[package]] name = "fdt" version = "0.1.5" @@ -534,6 +693,17 @@ dependencies = [ "wasi", ] +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +dependencies = [ + "fallible-iterator", + "indexmap", + "stable_deref_trait", +] + [[package]] name = "goblin" version = "0.8.2" @@ -554,11 +724,23 @@ dependencies = [ "byteorder", ] +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" +dependencies = [ + "ahash", +] + [[package]] name = "hashbrown" version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", +] [[package]] name = "heapless" @@ -570,6 +752,12 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "heck" version = "0.5.0" @@ -614,7 +802,7 @@ dependencies = [ "fdt", "float-cmp", "free-list", - "hashbrown", + "hashbrown 0.14.5", "hermit-dtb", "hermit-entry", "hermit-macro", @@ -644,6 +832,7 @@ dependencies = [ "uart_16550", "virtio-spec", "volatile 0.6.1", + "wasmtime", "x86", "x86_64 0.15.1", "zerocopy", @@ -696,6 +885,12 @@ dependencies = [ "cc", ] +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + [[package]] name = "idna" version = "0.5.0" @@ -706,6 +901,17 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "indexmap" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +dependencies = [ + "equivalent", + "hashbrown 0.14.5", + "serde", +] + [[package]] name = "interrupt-mutex" version = "0.1.0" @@ -732,6 +938,21 @@ version = "1.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + [[package]] name = "js-sys" version = "0.3.69" @@ -741,12 +962,30 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "leb128" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" + [[package]] name = "libc" version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + [[package]] name = "llvm-tools" version = "0.1.1" @@ -769,6 +1008,15 @@ version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +[[package]] +name = "mach2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" +dependencies = [ + "libc", +] + [[package]] name = "managed" version = "0.8.0" @@ -781,6 +1029,24 @@ version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +[[package]] +name = "memfd" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" +dependencies = [ + "rustix", +] + +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -934,6 +1200,18 @@ dependencies = [ "syn 2.0.66", ] +[[package]] +name = "object" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8dd6c0cdf9429bce006e1362bfce61fa1bfd8c898a643ed8d2b471934701d3d" +dependencies = [ + "crc32fast", + "hashbrown 0.14.5", + "indexmap", + "memchr", +] + [[package]] name = "once_cell" version = "1.19.0" @@ -1034,6 +1312,17 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" +[[package]] +name = "postcard" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a55c51ee6c0db07e68448e336cf8ea4131a620edefebf9893e759b2d793420f8" +dependencies = [ + "cobs", + "embedded-io", + "serde", +] + [[package]] name = "powerfmt" version = "0.2.0" @@ -1079,6 +1368,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "psm" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5787f7cda34e3033a72192c018bc5883100330f362ef279a8cbccfce8bb4e874" +dependencies = [ + "cc", +] + [[package]] name = "quote" version = "1.0.36" @@ -1142,6 +1440,19 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "regalloc2" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad156d539c879b7a24a363a2016d77961786e71f48f2e2fc8302a92abd2429a6" +dependencies = [ + "hashbrown 0.13.2", + "log", + "rustc-hash", + "slice-group-by", + "smallvec", +] + [[package]] name = "ring" version = "0.17.8" @@ -1167,6 +1478,25 @@ dependencies = [ "embedded-hal", ] +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags 2.5.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "rustls" version = "0.22.4" @@ -1204,6 +1534,12 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + [[package]] name = "sbi-rt" version = "0.0.3" @@ -1251,6 +1587,43 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92bc56e056d8725553408cc2dfdfb96591c49ef2835d2f6060f28396d645d785" +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + +[[package]] +name = "serde" +version = "1.0.203" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.203" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + +[[package]] +name = "serde_json" +version = "1.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +dependencies = [ + "itoa", + "ryu", + "serde", +] + [[package]] name = "shell-words" version = "1.1.0" @@ -1269,11 +1642,20 @@ version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" +[[package]] +name = "slice-group-by" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" + [[package]] name = "smallvec" version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +dependencies = [ + "serde", +] [[package]] name = "smoltcp" @@ -1304,6 +1686,12 @@ dependencies = [ "lock_api", ] +[[package]] +name = "sptr" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b9b39299b249ad65f3b7e96443bad61c02ca5cd3589f46cb6d610a0fd6c0d6a" + [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -1376,6 +1764,12 @@ dependencies = [ "lock_api", ] +[[package]] +name = "target-lexicon" +version = "0.12.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f" + [[package]] name = "thiserror" version = "1.0.61" @@ -1483,6 +1877,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + [[package]] name = "untrusted" version = "0.9.0" @@ -1636,6 +2036,230 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +[[package]] +name = "wasm-encoder" +version = "0.207.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d996306fb3aeaee0d9157adbe2f670df0236caf19f6728b221e92d0f27b3fe17" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasmparser" +version = "0.207.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e19bb9f8ab07616da582ef8adb24c54f1424c7ec876720b7da9db8ec0626c92c" +dependencies = [ + "ahash", + "bitflags 2.5.0", + "hashbrown 0.14.5", + "indexmap", + "semver", +] + +[[package]] +name = "wasmprinter" +version = "0.207.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c2d8a7b4dabb460208e6b4334d9db5766e84505038b2529e69c3d07ac619115" +dependencies = [ + "anyhow", + "wasmparser", +] + +[[package]] +name = "wasmtime" +version = "21.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f92a1370c66a0022e6d92dcc277e2c84f5dece19569670b8ce7db8162560d8b6" +dependencies = [ + "anyhow", + "bumpalo", + "cc", + "cfg-if", + "encoding_rs", + "hashbrown 0.14.5", + "indexmap", + "libc", + "libm", + "log", + "mach2", + "memfd", + "memoffset", + "object", + "once_cell", + "paste", + "postcard", + "psm", + "rustix", + "semver", + "serde", + "serde_derive", + "smallvec", + "sptr", + "target-lexicon", + "wasmparser", + "wasmtime-asm-macros", + "wasmtime-component-macro", + "wasmtime-component-util", + "wasmtime-cranelift", + "wasmtime-environ", + "wasmtime-jit-icache-coherence", + "wasmtime-slab", + "wasmtime-versioned-export-macros", + "wasmtime-winch", + "windows-sys", +] + +[[package]] +name = "wasmtime-asm-macros" +version = "21.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dee8679c974a7f258c03d60d3c747c426ed219945b6d08cbc77fd2eab15b2d1" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "wasmtime-component-macro" +version = "21.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32cae30035f1cf97dcc6657c979cf39f99ce6be93583675eddf4aeaa5548509c" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn 2.0.66", + "wasmtime-component-util", + "wasmtime-wit-bindgen", + "wit-parser", +] + +[[package]] +name = "wasmtime-component-util" +version = "21.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7ae611f08cea620c67330925be28a96115bf01f8f393a6cbdf4856a86087134" + +[[package]] +name = "wasmtime-cranelift" +version = "21.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2909406a6007e28be964067167890bca4574bd48a9ff18f1fa9f4856d89ea40" +dependencies = [ + "anyhow", + "cfg-if", + "cranelift-codegen", + "cranelift-control", + "cranelift-entity", + "cranelift-frontend", + "cranelift-native", + "cranelift-wasm", + "gimli", + "log", + "object", + "target-lexicon", + "thiserror", + "wasmparser", + "wasmtime-environ", + "wasmtime-versioned-export-macros", +] + +[[package]] +name = "wasmtime-environ" +version = "21.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40e227f9ed2f5421473723d6c0352b5986e6e6044fde5410a274a394d726108f" +dependencies = [ + "anyhow", + "cranelift-entity", + "gimli", + "indexmap", + "log", + "object", + "postcard", + "serde", + "serde_derive", + "target-lexicon", + "wasm-encoder", + "wasmparser", + "wasmprinter", + "wasmtime-component-util", + "wasmtime-types", +] + +[[package]] +name = "wasmtime-jit-icache-coherence" +version = "21.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afe088f9b56bb353adaf837bf7e10f1c2e1676719dd5be4cac8e37f2ba1ee5bc" +dependencies = [ + "anyhow", + "cfg-if", + "libc", + "windows-sys", +] + +[[package]] +name = "wasmtime-slab" +version = "21.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ff75cafffe47b04b036385ce3710f209153525b0ed19d57b0cf44a22d446460" + +[[package]] +name = "wasmtime-types" +version = "21.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f2fa462bfea3220711c84e2b549f147e4df89eeb49b8a2a3d89148f6cc4a8b1" +dependencies = [ + "cranelift-entity", + "serde", + "serde_derive", + "smallvec", + "wasmparser", +] + +[[package]] +name = "wasmtime-versioned-export-macros" +version = "21.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4cedc5bfef3db2a85522ee38564b47ef3b7fc7c92e94cacbce99808e63cdd47" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + +[[package]] +name = "wasmtime-winch" +version = "21.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b27054fed6be4f3800aba5766f7ef435d4220ce290788f021a08d4fa573108" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "object", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", + "winch-codegen", +] + +[[package]] +name = "wasmtime-wit-bindgen" +version = "21.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c936a52ce69c28de2aa3b5fb4f2dbbb2966df304f04cccb7aca4ba56d915fda0" +dependencies = [ + "anyhow", + "heck 0.4.1", + "indexmap", + "wit-parser", +] + [[package]] name = "webpki-roots" version = "0.26.2" @@ -1667,6 +2291,23 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "winch-codegen" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dc69899ccb2da7daa4df31426dcfd284b104d1a85e1dae35806df0c46187f87" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "regalloc2", + "smallvec", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", +] + [[package]] name = "windows" version = "0.52.0" @@ -1759,6 +2400,24 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +[[package]] +name = "wit-parser" +version = "0.207.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c83dab33a9618d86cfe3563cc864deffd08c17efc5db31a3b7cd1edeffe6e1" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + [[package]] name = "x86" version = "0.52.0" diff --git a/Cargo.toml b/Cargo.toml index 5df1ace17a..a662265978 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,6 +70,7 @@ nostd = [] semihosting = ["dep:semihosting"] shell = ["simple-shell"] idle-poll = [] +wasm = ["wasmtime"] [dependencies] hermit-macro = { path = "hermit-macro" } @@ -107,6 +108,7 @@ talc = { version = "4" } time = { version = "0.3", default-features = false } volatile = { version = "0.6", features = ["unstable"] } zerocopy = { version = "0.7", features = ["derive"] } +wasmtime = { version = "21.0", default-features = false, features = ["runtime", "gc", "component-model"], optional = true } [dependencies.smoltcp] version = "0.11" diff --git a/src/arch/x86_64/kernel/longjmp.s b/src/arch/x86_64/kernel/longjmp.s new file mode 100644 index 0000000000..1046296265 --- /dev/null +++ b/src/arch/x86_64/kernel/longjmp.s @@ -0,0 +1,14 @@ +.section .text +.global longjmp +longjmp: + xor eax,eax + cmp esi, 1 /* CF = val ? 0 : 1 */ + adc eax, esi /* eax = val + !val */ + mov rbx, [rdi] + mov rbp, [rdi+8] + mov r12, [rdi+16] + mov r13, [rdi+24] + mov r14, [rdi+32] + mov r15, [rdi+40] + mov rsp, [rdi+48] + jmp [rdi+56] \ No newline at end of file diff --git a/src/arch/x86_64/kernel/mod.rs b/src/arch/x86_64/kernel/mod.rs index e6243eea57..d13062f209 100644 --- a/src/arch/x86_64/kernel/mod.rs +++ b/src/arch/x86_64/kernel/mod.rs @@ -1,5 +1,6 @@ #[cfg(feature = "common-os")] use core::arch::asm; +use core::arch::global_asm; use core::num::NonZeroU64; use core::ptr; use core::sync::atomic::{AtomicPtr, AtomicU32, Ordering}; @@ -38,6 +39,9 @@ pub(crate) mod systemtime; #[cfg(feature = "vga")] mod vga; +global_asm!(include_str!("setjmp.s")); +global_asm!(include_str!("longjmp.s")); + /// Kernel header to announce machine features #[cfg_attr(target_os = "none", link_section = ".data")] static mut RAW_BOOT_INFO: Option<&'static RawBootInfo> = None; diff --git a/src/arch/x86_64/kernel/setjmp.s b/src/arch/x86_64/kernel/setjmp.s new file mode 100644 index 0000000000..efd4875829 --- /dev/null +++ b/src/arch/x86_64/kernel/setjmp.s @@ -0,0 +1,15 @@ +.section .text +.global setjmp +setjmp: +mov [rdi], rbx +mov [rdi+8], rbp +mov [rdi+16], r12 +mov [rdi+24], r13 +mov [rdi+32], r14 +mov [rdi+40], r15 +lea rdx, [rsp+8] # rsp without current ret addr +mov [rdi+48], rdx +mov rdi, rsp # save return addr ptr for new rip +mov [rdi+56], rdx +xor rax, rax +ret \ No newline at end of file diff --git a/src/arch/x86_64/mm/paging.rs b/src/arch/x86_64/mm/paging.rs index 6607671d64..a116778851 100644 --- a/src/arch/x86_64/mm/paging.rs +++ b/src/arch/x86_64/mm/paging.rs @@ -106,7 +106,7 @@ pub fn virtual_to_physical(virtual_address: VirtAddr) -> Option { match translate { TranslateResult::NotMapped | TranslateResult::InvalidFrameAddress(_) => { - warn!( + trace!( "Uable to determine the physical address of 0x{:X}", virtual_address ); diff --git a/src/lib.rs b/src/lib.rs index 2ac8ad8b50..2bf6861d3a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -93,6 +93,8 @@ mod shell; mod synch; pub mod syscalls; pub mod time; +#[cfg(all(target_arch = "x86_64", feature = "wasm"))] +mod wasm; #[cfg(target_os = "none")] hermit_entry::define_entry_version!(); @@ -156,6 +158,11 @@ extern "C" fn initd(_arg: usize) { #[cfg(not(test))] let (argc, argv, environ) = syscalls::get_application_parameters(); + #[cfg(all(target_arch = "x86_64", feature = "wasm"))] + if crate::wasm::init().is_err() { + error!("Unable to initialized wasm support") + } + // give the IP thread time to initialize the network interface core_scheduler().reschedule(); diff --git a/src/wasm/capi.rs b/src/wasm/capi.rs new file mode 100644 index 0000000000..242c69fc06 --- /dev/null +++ b/src/wasm/capi.rs @@ -0,0 +1,330 @@ +use core::arch::global_asm; +use core::cell::UnsafeCell; + +use align_address::Align; + +use crate::arch; +#[cfg(target_arch = "x86_64")] +use crate::arch::mm::paging::PageTableEntryFlagsExt; +use crate::arch::mm::paging::{BasePageSize, PageSize, PageTableEntryFlags}; +use crate::arch::mm::VirtAddr; + +bitflags! { + /// Flags to either `wasmtime_mmap_{new,remap}` or `wasmtime_mprotect`. + #[repr(C)] + #[derive(Debug, Copy, Clone, Default)] + struct WasmProt: u32 { + /// Indicates that the memory region should be readable. + const Read = 1 << 0; + /// Indicates that the memory region should be writable. + const Write = 1 << 1; + /// Indicates that the memory region should be executable. + const Exec = 1 << 2; + } +} + +/// Handler function for traps in Wasmtime passed to `wasmtime_init_traps`. +/// +/// This function is invoked whenever a trap is caught by the system. For +/// example this would be invoked during a signal handler on Linux. This +/// function is passed a number of parameters indicating information about the +/// trap: +/// +/// * `ip` - the instruction pointer at the time of the trap. +/// * `fp` - the frame pointer register's value at the time of the trap. +/// * `has_faulting_addr` - whether this trap is associated with an access +/// violation (e.g. a segfault) meaning memory was accessed when it shouldn't +/// be. If this is `true` then the next parameter is filled in. +/// * `faulting_addr` - if `has_faulting_addr` is true then this is the address +/// that was attempted to be accessed. Otherwise this value is not used. +/// +/// If this function returns then the trap was not handled by Wasmtime. This +/// means that it's left up to the embedder how to deal with the trap/signal +/// depending on its default behavior. This could mean forwarding to a +/// non-Wasmtime handler, aborting the process, logging then crashing, etc. The +/// meaning of a trap that's not handled by Wasmtime depends on the context in +/// which the trap was generated. +/// +/// When this function does not return it's because `wasmtime_longjmp` is +/// used to handle a Wasm-based trap. +#[allow(non_camel_case_types)] +type wasmtime_trap_handler_t = + extern "C" fn(ip: usize, fp: usize, has_faulting_addr: bool, faulting_addr: usize); + +/// Abstract pointer type used in the `wasmtime_memory_image_*` APIs which +/// is defined by the embedder. +#[allow(non_camel_case_types)] +enum wasmtime_memory_image {} + +#[thread_local] +static TLS: UnsafeCell<*mut u8> = UnsafeCell::new(core::ptr::null_mut()); + +/// Wasmtime requires a single pointer's space of TLS to be used at runtime, +/// and this function returns the current value of the TLS variable. +/// +/// This value should default to `NULL`. +#[no_mangle] +pub extern "C" fn wasmtime_tls_get() -> *mut u8 { + unsafe { TLS.get().read() } +} + +// Sets the current TLS value for Wasmtime to the provided value. +/// +/// This value should be returned when later calling `wasmtime_tls_get`. +#[no_mangle] +pub extern "C" fn wasmtime_tls_set(ptr: *mut u8) { + unsafe { + TLS.get().write(ptr); + } +} + +/// Returns the page size, in bytes, of the current system. +#[no_mangle] +pub extern "C" fn wasmtime_page_size() -> usize { + BasePageSize::SIZE as usize +} + +/// Creates a new virtual memory mapping of the `size` specified with +/// protection bits specified in `prot_flags`. +/// +/// Memory can be lazily committed. +/// +/// Stores the base pointer of the new mapping in `ret` on success. +/// +/// Returns 0 on success and an error code on failure. +/// +/// Similar to `mmap(0, size, prot_flags, MAP_PRIVATE, 0, -1)` on Linux. +#[no_mangle] +pub extern "C" fn wasmtime_mmap_new(size: usize, prot_flags: WasmProt, ret: &mut *mut u8) -> i32 { + let size = size.align_up(BasePageSize::SIZE as usize); + let virtual_address = arch::mm::virtualmem::allocate(size).unwrap(); + if prot_flags.is_empty() { + *ret = virtual_address.as_mut_ptr(); + return 0; + } + let physical_address = arch::mm::physicalmem::allocate(size).unwrap(); + + let count = size / BasePageSize::SIZE as usize; + let mut flags = PageTableEntryFlags::empty(); + flags.normal().writable(); + if prot_flags.contains(WasmProt::Write) { + flags.writable(); + } + if !prot_flags.contains(WasmProt::Exec) { + flags.execute_disable(); + } + + arch::mm::paging::map::(virtual_address, physical_address, count, flags); + + *ret = virtual_address.as_mut_ptr(); + + 0 +} + +/// Remaps the virtual memory starting at `addr` going for `size` bytes to +/// the protections specified with a new blank mapping. +/// +/// This will unmap any prior mappings and decommit them. New mappings for +/// anonymous memory are used to replace these mappings and the new area +/// should have the protection specified by `prot_flags`. +/// +/// Returns 0 on success and an error code on failure. +/// +/// Similar to `mmap(addr, size, prot_flags, MAP_PRIVATE | MAP_FIXED, 0, -1)` on Linux. +#[no_mangle] +pub extern "C" fn wasmtime_mmap_remap(_addr: *mut u8, _size: usize, _prot_flags: WasmProt) -> i32 { + error!("Currently. HermitOS doesn't support wasmtime_mmap_remap!"); + -1 +} + +/// Unmaps memory at the specified `ptr` for `size` bytes. +/// +/// The memory should be discarded and decommitted and should generate a +/// segfault if accessed after this function call. +/// +/// Returns 0 on success and an error code on failure. +/// +/// Similar to `munmap` on Linux. +#[no_mangle] +pub extern "C" fn wasmtime_munmap(ptr: *mut u8, size: usize) -> i32 { + let virtual_address = VirtAddr::from_usize(ptr as usize); + let size = size.align_up(BasePageSize::SIZE as usize); + + if let Some(phys_addr) = arch::mm::paging::virtual_to_physical(virtual_address) { + arch::mm::paging::unmap::( + virtual_address, + size / BasePageSize::SIZE as usize, + ); + arch::mm::physicalmem::deallocate(phys_addr, size); + } + + arch::mm::virtualmem::deallocate(virtual_address, size); + + 0 +} + +/// Configures the protections associated with a region of virtual memory +/// starting at `ptr` and going to `size`. +/// +/// Returns 0 on success and an error code on failure. +/// +/// Similar to `mprotect` on Linux. +#[no_mangle] +pub extern "C" fn wasmtime_mprotect(ptr: *mut u8, size: usize, prot_flags: WasmProt) -> i32 { + let count = size / BasePageSize::SIZE as usize; + let mut flags = PageTableEntryFlags::empty(); + flags.normal().writable(); + if prot_flags.contains(WasmProt::Write) { + flags.writable(); + } + if !prot_flags.contains(WasmProt::Exec) { + flags.execute_disable(); + } + + let virtual_address = VirtAddr::from_usize(ptr as usize); + + if let Some(physical_address) = arch::mm::paging::virtual_to_physical(virtual_address) { + arch::mm::paging::map::(virtual_address, physical_address, count, flags); + 0 + } else { + let physical_address = arch::mm::physicalmem::allocate(size).unwrap(); + arch::mm::paging::map::(virtual_address, physical_address, count, flags); + 0 + } +} + +extern "C" { + fn setjmp(buf: *const u8) -> i32; + fn longjmp(jmp_buf: *const u8, val: i32) -> !; +} + +/// Used to setup a frame on the stack to longjmp back to in the future. +/// +/// This function is used for handling traps in WebAssembly and is paried +/// with `wasmtime_longjmp`. +/// +/// * `jmp_buf` - this argument is filled in with a pointer which if used +/// will be passed to `wasmtime_longjmp` later on by the runtime. +/// * `callback` - this callback should be invoked after `jmp_buf` is +/// configured. +/// * `payload` and `callee` - the two arguments to pass to `callback`. +/// +/// Returns 0 if `wasmtime_longjmp` was used to return to this function. +/// Returns 1 if `wasmtime_longjmp` was not called and `callback` returned. +#[no_mangle] +pub extern "C" fn wasmtime_setjmp( + jmp_buf: *mut *const u8, + callback: extern "C" fn(*mut u8, *mut u8), + payload: *mut u8, + callee: *mut u8, +) -> i32 { + let buf: [u8; 64] = [0; 64]; + + unsafe { + if setjmp(buf.as_ptr()) != 0 { + return 0; + } + + *jmp_buf = buf.as_ptr(); + } + + callback(payload, callee); + + 1 +} + +/// Paired with `wasmtime_setjmp` this is used to jump back to the `setjmp` +/// point. +/// +/// The argument here was originally passed to `wasmtime_setjmp` through its +/// out-param. +/// +/// This function cannot return. +/// +/// This function may be invoked from the `wasmtime_trap_handler_t` +/// configured by `wasmtime_init_traps`. +#[no_mangle] +pub extern "C" fn wasmtime_longjmp(jmp_buf: *const u8) -> ! { + unsafe { + longjmp(jmp_buf, 1); + } +} + +/// Initializes trap-handling logic for this platform. +/// +/// Wasmtime's implementation of WebAssembly relies on the ability to catch +/// signals/traps/etc. For example divide-by-zero may raise a machine +/// exception. Out-of-bounds memory accesses may also raise a machine +/// exception. This function is used to initialize trap handling. +/// +/// The `handler` provided is a function pointer to invoke whenever a trap +/// is encountered. The `handler` is invoked whenever a trap is caught by +/// the system. +/// +/// Returns 0 on success and an error code on failure. +#[no_mangle] +pub extern "C" fn wasmtime_init_traps(_handler: wasmtime_trap_handler_t) -> i32 { + 0 +} + +/// Attempts to create a new in-memory image of the `ptr`/`len` combo which +/// can be mapped to virtual addresses in the future. +/// +/// On success the returned `wasmtime_memory_image` pointer is stored into `ret`. +/// This value stored can be `NULL` to indicate that an image cannot be +/// created but no failure occurred. The structure otherwise will later be +/// deallocated with `wasmtime_memory_image_free` and +/// `wasmtime_memory_image_map_at` will be used to map the image into new +/// regions of the address space. +/// +/// The `ptr` and `len` arguments are only valid for this function call, if +/// the image needs to refer to them in the future then it must make a copy. +/// +/// Both `ptr` and `len` are guaranteed to be page-aligned. +/// +/// Returns 0 on success and an error code on failure. Note that storing +/// `NULL` into `ret` is not considered a failure, and failure is used to +/// indicate that something fatal has happened and Wasmtime will propagate +/// the error upwards. +#[no_mangle] +pub extern "C" fn wasmtime_memory_image_new( + _ptr: *const u8, + _len: usize, + _ret: &mut *mut wasmtime_memory_image, +) -> i32 { + error!("Currently. HermitOS doesn't support wasmtime_memory_image_new!"); + -1 +} + +/// Maps the `image` provided to the virtual address at `addr` and `len`. +/// +/// This semantically should make it such that `addr` and `len` looks the +/// same as the contents of what the memory image was first created with. +/// The mappings of `addr` should be private and changes do not reflect back +/// to `wasmtime_memory_image`. +/// +/// In effect this is to create a copy-on-write mapping at `addr`/`len` +/// pointing back to the memory used by the image originally. +/// +/// Note that the memory region will be unmapped with `wasmtime_munmap` in +/// the future. +/// +/// Aborts the process on failure. +#[no_mangle] +pub extern "C" fn wasmtime_memory_image_map_at( + _image: *mut wasmtime_memory_image, + _addr: *mut u8, + _len: usize, +) -> i32 { + error!("Currently. HermitOS doesn't support wasmtime_memory_image_map_at!"); + -1 +} + +/// Deallocates the provided `wasmtime_memory_image`. +/// +/// Note that mappings created from this image are not guaranteed to be +/// deallocated and/or unmapped before this is called. +#[no_mangle] +pub extern "C" fn wasmtime_memory_image_free(_image: *mut wasmtime_memory_image) { + error!("Currently. HermitOS doesn't support wasmtime_memory_image_free!"); +} diff --git a/src/wasm/fib.cwasm b/src/wasm/fib.cwasm new file mode 100644 index 0000000000..1c7cd542b2 Binary files /dev/null and b/src/wasm/fib.cwasm differ diff --git a/src/wasm/fib.wasm b/src/wasm/fib.wasm new file mode 100755 index 0000000000..a0dfaf9cf0 Binary files /dev/null and b/src/wasm/fib.wasm differ diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs new file mode 100644 index 0000000000..cf918cc7b4 --- /dev/null +++ b/src/wasm/mod.rs @@ -0,0 +1,42 @@ +mod capi; + +use wasmtime::*; + +pub(crate) fn init() -> Result<(), Error> { + let mut config: Config = Config::new(); + config.memory_init_cow(false); + config.wasm_simd(false); + config.wasm_relaxed_simd(false); + + // First step is to create the Wasm execution engine with some config. + // In this example we are using the default configuration. + let engine = Engine::new(&config)?; + + debug!("Create Module"); + let module_bytes = include_bytes!("fib.cwasm"); + let module = unsafe { Module::deserialize(&engine, &module_bytes[..])? }; + + debug!("Create Linker"); + let linker = Linker::new(&engine); + + // All wasm objects operate within the context of a "store". Each + // `Store` has a type parameter to store host-specific data, which in + // this case we're using `4` for. + let mut store = Store::new(&engine, 4); + debug!("Create instance"); + let instance = linker.instantiate(&mut store, &module)?; + + debug!("Try to find function fibonacci"); + let fibonacci = instance.get_typed_func::(&mut store, "fibonacci")?; + + // And finally we can call the wasm function + info!("Call function fibonacci"); + let result = fibonacci.call(&mut store, 30)?; + info!("fibonacci(30) = {}", result); + assert!( + result == 832040, + "Error in the calculation of fibonacci(30) " + ); + + Ok(()) +}