From ea201274f8d7641984e0e4ea913f0eebd3e0e2f2 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sat, 22 Jun 2024 00:13:45 +0200 Subject: [PATCH 01/24] add draft to support WebAssembly within the kernel --- Cargo.lock | 1074 +++++++++++++++++++++++++----- Cargo.toml | 2 + src/arch/x86_64/kernel/longjmp.s | 14 + src/arch/x86_64/kernel/mod.rs | 55 ++ src/arch/x86_64/kernel/setjmp.s | 15 + src/lib.rs | 7 + src/wasm/capi.rs | 330 +++++++++ src/wasm/fib.cwasm | Bin 0 -> 14344 bytes src/wasm/fib.wasm | Bin 0 -> 582 bytes src/wasm/mod.rs | 42 ++ 10 files changed, 1387 insertions(+), 152 deletions(-) create mode 100644 src/arch/x86_64/kernel/longjmp.s create mode 100644 src/arch/x86_64/kernel/setjmp.s create mode 100644 src/wasm/capi.rs create mode 100644 src/wasm/fib.cwasm create mode 100755 src/wasm/fib.wasm create mode 100644 src/wasm/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 153110dac1..9b6662974f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -44,9 +44,9 @@ dependencies = [ [[package]] name = "adler2" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" [[package]] name = "ahash" @@ -66,6 +66,12 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ac6c08a67736554282858203cd9b7ff53cf55f54c34e85689962748a350cbf0" +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + [[package]] name = "allocator-api2" version = "0.3.0" @@ -89,9 +95,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.18" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" +checksum = "3ae563653d1938f79b1ab1b5e668c87c76a9930414574a6583a7b7e11a8e6192" dependencies = [ "anstyle", "anstyle-parse", @@ -110,31 +116,31 @@ checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" [[package]] name = "anstyle-parse" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" +checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.1.2" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" +checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] name = "anstyle-wincon" -version = "3.0.7" +version = "3.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e" +checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a" dependencies = [ "anstyle", - "once_cell", - "windows-sys 0.59.0", + "once_cell_polyfill", + "windows-sys 0.60.2", ] [[package]] @@ -143,6 +149,12 @@ version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100" +[[package]] +name = "arbitrary" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d036a3c4ab069c7b410a2ce876bd74808d2d0888a82667669f8e783a898bf1" + [[package]] name = "arm-gic" version = "0.6.1" @@ -199,9 +211,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" [[package]] name = "base64" @@ -272,9 +284,12 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.17.0" +version = "3.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" +checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" +dependencies = [ + "allocator-api2 0.2.21", +] [[package]] name = "byteorder" @@ -296,9 +311,9 @@ checksum = "3a57a50948117a233b27f9bf73ab74709ab90d245216c4707cc16eea067a50bb" [[package]] name = "cc" -version = "1.2.17" +version = "1.2.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fcb57c740ae1daf453ae85f16e37396f672b039e00d9d866e07ddb24e328e3a" +checksum = "42bc4aea80032b7bf409b0bc7ccad88853858911b7713a8062fdc0623867bedc" dependencies = [ "jobserver", "libc", @@ -319,9 +334,9 @@ checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" [[package]] name = "chrono" -version = "0.4.40" +version = "0.4.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a7964611d71df112cb1730f2ee67324fcf4d0fc6606acbbe9bfe06df124637c" +checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" dependencies = [ "android-tzdata", "iana-time-zone", @@ -365,15 +380,24 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.4" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" + +[[package]] +name = "cobs" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" +checksum = "0fa961b519f0b462e3a3b4a34b64d119eeaca1d59af726fe450bbba07a9fc0a1" +dependencies = [ + "thiserror", +] [[package]] name = "colorchoice" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" +checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" [[package]] name = "concurrent-queue" @@ -411,11 +435,148 @@ dependencies = [ "libc", ] +[[package]] +name = "cranelift-assembler-x64" +version = "0.122.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ae7b60ec3fd7162427d3b3801520a1908bef7c035b52983cd3ca11b8e7deb51" +dependencies = [ + "cranelift-assembler-x64-meta", +] + +[[package]] +name = "cranelift-assembler-x64-meta" +version = "0.122.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6511c200fed36452697b4b6b161eae57d917a2044e6333b1c1389ed63ccadeee" +dependencies = [ + "cranelift-srcgen", +] + +[[package]] +name = "cranelift-bforest" +version = "0.122.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f7086a645aa58bae979312f64e3029ac760ac1b577f5cd2417844842a2ca07f" +dependencies = [ + "cranelift-entity", +] + +[[package]] +name = "cranelift-bitset" +version = "0.122.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5225b4dec45f3f3dbf383f12560fac5ce8d780f399893607e21406e12e77f491" +dependencies = [ + "serde", + "serde_derive", +] + +[[package]] +name = "cranelift-codegen" +version = "0.122.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "858fb3331e53492a95979378d6df5208dd1d0d315f19c052be8115f4efc888e0" +dependencies = [ + "bumpalo", + "cranelift-assembler-x64", + "cranelift-bforest", + "cranelift-bitset", + "cranelift-codegen-meta", + "cranelift-codegen-shared", + "cranelift-control", + "cranelift-entity", + "cranelift-isle", + "gimli", + "hashbrown", + "log", + "pulley-interpreter", + "regalloc2", + "rustc-hash", + "serde", + "smallvec", + "target-lexicon", + "wasmtime-internal-math", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.122.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456715b9d5f12398f156d5081096e7b5d039f01b9ecc49790a011c8e43e65b5f" +dependencies = [ + "cranelift-assembler-x64-meta", + "cranelift-codegen-shared", + "cranelift-srcgen", + "pulley-interpreter", +] + +[[package]] +name = "cranelift-codegen-shared" +version = "0.122.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0306041099499833f167a0ddb707e1e54100f1a84eab5631bc3dad249708f482" + +[[package]] +name = "cranelift-control" +version = "0.122.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1672945e1f9afc2297f49c92623f5eabc64398e2cb0d824f8f72a2db2df5af23" +dependencies = [ + "arbitrary", +] + +[[package]] +name = "cranelift-entity" +version = "0.122.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa3cd55eb5f3825b9ae5de1530887907360a6334caccdc124c52f6d75246c98a" +dependencies = [ + "cranelift-bitset", + "serde", + "serde_derive", +] + +[[package]] +name = "cranelift-frontend" +version = "0.122.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "781f9905f8139b8de22987b66b522b416fe63eb76d823f0b3a8c02c8fd9500c7" +dependencies = [ + "cranelift-codegen", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-isle" +version = "0.122.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a05337a2b02c3df00b4dd9a263a027a07b3dff49f61f7da3b5d195c21eaa633d" + +[[package]] +name = "cranelift-native" +version = "0.122.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2eee7a496dd66380082c9c5b6f2d5fa149cec0ec383feec5caf079ca2b3671c2" +dependencies = [ + "cranelift-codegen", + "libc", + "target-lexicon", +] + +[[package]] +name = "cranelift-srcgen" +version = "0.122.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b530783809a55cb68d070e0de60cfbb3db0dc94c8850dd5725411422bedcf6bb" + [[package]] name = "crc" -version = "3.2.1" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69e6e4d7b33a94f0991c26729976b10ebde1d34c3ee82408fb536164fa10d636" +checksum = "9710d3b3739c2e349eb44fe848ad0b7c8cb1e42bd87ee49371df2f7acaf3e675" dependencies = [ "crc-catalog", ] @@ -428,9 +589,9 @@ checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" [[package]] name = "crc32fast" -version = "1.4.2" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" dependencies = [ "cfg-if", ] @@ -459,9 +620,18 @@ dependencies = [ [[package]] name = "defmt" -version = "0.3.10" +version = "0.3.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0963443817029b2024136fc4dd07a5107eb8f977eaf18fcd1fdeb11306b64ad" +dependencies = [ + "defmt 1.0.1", +] + +[[package]] +name = "defmt" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86f6162c53f659f65d00619fe31f14556a6e9f8752ccc4a41bd177ffcf3d6130" +checksum = "548d977b6da32fa1d1fda2876453da1e7df63ad0304c8b3dae4dbe7b96f39b78" dependencies = [ "bitflags 1.3.2", "defmt-macros", @@ -469,9 +639,9 @@ dependencies = [ [[package]] name = "defmt-macros" -version = "0.4.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d135dd939bad62d7490b0002602d35b358dce5fd9233a709d3c1ef467d4bde6" +checksum = "3d4fc12a85bcf441cfe44344c4b72d58493178ce635338a3f3b78943aceb258e" dependencies = [ "defmt-parser", "proc-macro-error2", @@ -482,18 +652,18 @@ dependencies = [ [[package]] name = "defmt-parser" -version = "0.4.1" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3983b127f13995e68c1e29071e5d115cd96f215ccb5e6812e3728cd6f92653b3" +checksum = "10d60334b3b2e7c9d91ef8150abfb6fa4c1c39ebbcf4a81c2e346aad939fee3e" dependencies = [ "thiserror", ] [[package]] name = "deranged" -version = "0.4.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28cfac68e08048ae1883171632c2aef3ebc555621ae56fbccce1cbf22dd7f058" +checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e" dependencies = [ "powerfmt", ] @@ -519,18 +689,39 @@ dependencies = [ "syn", ] +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" + [[package]] name = "embedded-hal" 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 = "embedded-io" version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" +[[package]] +name = "encoding_rs" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" +dependencies = [ + "cfg-if", +] + [[package]] name = "endian-num" version = "0.2.0" @@ -554,21 +745,27 @@ dependencies = [ "syn", ] +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + [[package]] name = "errno" -version = "0.3.10" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" +checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad" dependencies = [ "libc", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] name = "event-listener" -version = "5.4.0" +version = "5.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3492acde4c3fc54c845eaab3eed8bd00c7a7d881f78bfc801e43a93dec1331ae" +checksum = "e13b66accf52311f30a0db42147dadea9850cb48cd070028831ae5f5d4b856ab" dependencies = [ "concurrent-queue", "pin-project-lite", @@ -576,9 +773,9 @@ dependencies = [ [[package]] name = "event-listener-strategy" -version = "0.5.3" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c3e4e0dd3673c1139bf041f3008816d9cf2946bbfac2945c09e523b8d7b05b2" +checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93" dependencies = [ "event-listener", "pin-project-lite", @@ -590,6 +787,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 = "fastrand" version = "2.3.0" @@ -604,21 +807,21 @@ checksum = "784a4df722dc6267a04af36895398f59d21d07dce47232adf31ec0ff2fa45e67" [[package]] name = "filetime" -version = "0.2.25" +version = "0.2.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35c0522e981e68cbfa8c3f978441a5f34b30b96e146b33cd3359176b50fe8586" +checksum = "bc0505cd1b6fa6580283f6bdf70a73fcf4aba1184038c90902b92b3dd0df63ed" dependencies = [ "cfg-if", "libc", "libredox", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] name = "flate2" -version = "1.1.0" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11faaf5a5236997af9848be0bef4db95824b1d534ebc64d0f0c6cf3e67bd38dc" +checksum = "4a3d7db9596fecd151c5f638c0ee5d5bd487b6e0ea232e5dc96d5250f6f94b1d" dependencies = [ "crc32fast", "miniz_oxide", @@ -639,11 +842,17 @@ 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 = "form_urlencoded" -version = "1.2.1" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" dependencies = [ "percent-encoding", ] @@ -682,9 +891,9 @@ checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-lite" -version = "2.6.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5edaec856126859abb19ed65f39e90fea3a9574b9707f13539acf4abf7eb532" +checksum = "f78e10609fe0e0b3f4157ffab1876319b5b0db102a2c60dc4626306dc46b44ad" dependencies = [ "fastrand", "futures-core", @@ -714,13 +923,13 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" dependencies = [ "cfg-if", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi 0.11.1+wasi-snapshot-preview1", ] [[package]] @@ -732,7 +941,18 @@ dependencies = [ "cfg-if", "libc", "r-efi", - "wasi 0.14.2+wasi-0.2.4", + "wasi 0.14.3+wasi-0.2.4", +] + +[[package]] +name = "gimli" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" +dependencies = [ + "fallible-iterator", + "indexmap", + "stable_deref_trait", ] [[package]] @@ -773,6 +993,10 @@ name = "hashbrown" version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash", + "serde", +] [[package]] name = "heapless" @@ -830,7 +1054,7 @@ dependencies = [ "built", "cfg-if", "crossbeam-utils", - "embedded-io", + "embedded-io 0.6.1", "enum_dispatch", "fdt", "float-cmp", @@ -868,6 +1092,7 @@ dependencies = [ "uhyve-interface", "virtio-spec", "volatile 0.6.1", + "wasmtime", "x86_64", "zerocopy", ] @@ -924,9 +1149,9 @@ checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" [[package]] name = "iana-time-zone" -version = "0.1.62" +version = "0.1.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2fd658b06e56721792c5df4475705b6cda790e9298d19d2f8af083457bcd127" +checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -934,7 +1159,7 @@ dependencies = [ "js-sys", "log", "wasm-bindgen", - "windows-core 0.52.0", + "windows-core", ] [[package]] @@ -1032,11 +1257,17 @@ dependencies = [ "zerovec", ] +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + [[package]] name = "idna" -version = "1.0.3" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" dependencies = [ "idna_adapter", "smallvec", @@ -1053,6 +1284,17 @@ dependencies = [ "icu_properties", ] +[[package]] +name = "indexmap" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2481980430f9f78649238835720ddccc57e52df14ffce1c6f37391d61b563e9" +dependencies = [ + "equivalent", + "hashbrown", + "serde", +] + [[package]] name = "interrupt-mutex" version = "0.1.0" @@ -1079,6 +1321,15 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +[[package]] +name = "itertools" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.15" @@ -1087,9 +1338,9 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" [[package]] name = "jobserver" -version = "0.1.33" +version = "0.1.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38f262f097c174adebe41eb73d66ae9c06b2844fb0da69969647bbddd9b0538a" +checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33" dependencies = [ "getrandom 0.3.3", "libc", @@ -1105,11 +1356,17 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + [[package]] name = "libc" -version = "0.2.174" +version = "0.2.175" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" +checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" [[package]] name = "libgit2-sys" @@ -1123,11 +1380,17 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "libm" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" + [[package]] name = "libredox" -version = "0.1.3" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +checksum = "391290121bad3d37fbddad76d8f5d1c1c314cfc646d143d7e07a3086ddff0ce3" dependencies = [ "bitflags 2.9.3", "libc", @@ -1148,9 +1411,15 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.9.3" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" + +[[package]] +name = "linux-raw-sys" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe7db12097d22ec582439daf8618b8fdd1a7bef6270e9af3b1ebcd30893cf413" +checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" [[package]] name = "litemap" @@ -1190,6 +1459,15 @@ dependencies = [ "crc", ] +[[package]] +name = "mach2" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d640282b302c0bb0a2a8e0233ead9035e3bed871f0b7e81fe4a1ec829765db44" +dependencies = [ + "libc", +] + [[package]] name = "managed" version = "0.8.0" @@ -1198,9 +1476,18 @@ checksum = "0ca88d725a0a943b096803bd34e73a4437208b6077654cc4ecb2947a5f91618d" [[package]] name = "memchr" -version = "2.7.4" +version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" + +[[package]] +name = "memfd" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" +dependencies = [ + "rustix 0.38.44", +] [[package]] name = "memory_addresses" @@ -1221,9 +1508,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.8.5" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e3e04debbb59698c15bacbb6d93584a8c0ca9cc3213cb423d31f760d8843ce5" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" dependencies = [ "adler2", ] @@ -1314,11 +1601,29 @@ dependencies = [ "objc2-core-foundation", ] +[[package]] +name = "object" +version = "0.36.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" +dependencies = [ + "crc32fast", + "hashbrown", + "indexmap", + "memchr", +] + [[package]] name = "once_cell" -version = "1.21.1" +version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d75b0bedcc4fe52caa0e03d9f1151a323e4aa5e2d78ba3580400cd3c9e2bc4bc" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "once_cell_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" [[package]] name = "one-shot-mutex" @@ -1379,9 +1684,9 @@ dependencies = [ [[package]] name = "percent-encoding" -version = "2.3.1" +version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" [[package]] name = "phf" @@ -1439,11 +1744,23 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" +[[package]] +name = "postcard" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6764c3b5dd454e283a30e6dfe78e9b31096d9e32036b5d1eaac7a6119ccb9a24" +dependencies = [ + "cobs", + "embedded-io 0.4.0", + "embedded-io 0.6.1", + "serde", +] + [[package]] name = "potential_utf" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5a7c30837279ca13e7c867e9e40053bc68740f988cb07f7ca6df43cc734b585" +checksum = "84df19adbe5b5a0782edcab45899906947ab039ccf4573713735ee7de1e6b08a" dependencies = [ "zerovec", ] @@ -1494,6 +1811,29 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "pulley-interpreter" +version = "35.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b89c4319786b16c1a6a38ee04788d32c669b61ba4b69da2162c868c18be99c1b" +dependencies = [ + "cranelift-bitset", + "log", + "pulley-macros", + "wasmtime-internal-math", +] + +[[package]] +name = "pulley-macros" +version = "35.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "938543690519c20c3a480d20a8efcc8e69abeb44093ab1df4e7c1f81f26c677a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "quote" version = "1.0.40" @@ -1560,13 +1900,27 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.10" +version = "0.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b8c0c260b63a8219631167be35e6a988e9554dbd323f8bd08439c8ed1302bd1" +checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77" dependencies = [ "bitflags 2.9.3", ] +[[package]] +name = "regalloc2" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5216b1837de2149f8bc8e6d5f88a9326b63b8c836ed58ce4a0a29ec736a59734" +dependencies = [ + "allocator-api2 0.2.21", + "bumpalo", + "hashbrown", + "log", + "rustc-hash", + "smallvec", +] + [[package]] name = "ring" version = "0.17.14" @@ -1575,7 +1929,7 @@ checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" dependencies = [ "cc", "cfg-if", - "getrandom 0.2.15", + "getrandom 0.2.16", "libc", "untrusted", "windows-sys 0.52.0", @@ -1611,24 +1965,43 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8188909339ccc0c68cfb5a04648313f09621e8b87dc03095454f1a11f6c5d436" +[[package]] +name = "rustc-hash" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" + [[package]] name = "rustix" -version = "1.0.3" +version = "0.38.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e56a18552996ac8d29ecc3b190b4fdbb2d91ca4ec396de7bbffaf43f3d637e96" +checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" dependencies = [ "bitflags 2.9.3", "errno", "libc", - "linux-raw-sys", + "linux-raw-sys 0.4.15", "windows-sys 0.59.0", ] +[[package]] +name = "rustix" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8" +dependencies = [ + "bitflags 2.9.3", + "errno", + "libc", + "linux-raw-sys 0.9.4", + "windows-sys 0.60.2", +] + [[package]] name = "rustls" -version = "0.23.25" +version = "0.23.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "822ee9188ac4ec04a2f0531e55d035fb2de73f18b41a63c70c2712503b6fb13c" +checksum = "c0ebcbd2f03de0fc1122ad9bb24b127a5a6cd51d72604a3f3c50ac459762b6cc" dependencies = [ "log", "once_cell", @@ -1650,15 +2023,18 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "917ce264624a4b4db1c364dcc35bfca9ded014d0a958cd47ad3e960e988ea51c" +checksum = "229a4a4c221013e7e1f1a043678c5cc39fe5171437c88fb47151a21e6f5b5c79" +dependencies = [ + "zeroize", +] [[package]] name = "rustls-webpki" -version = "0.103.0" +version = "0.103.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0aa4eeac2588ffff23e9d7a7e9b3f971c5fb5b7ebc9452745e0c232c64f83b2f" +checksum = "0a17884ae0c1b773f1ccd2bd4a8c72f16da897310a98b0e84bf349ad5ead92fc" dependencies = [ "ring", "rustls-pki-types", @@ -1667,9 +2043,15 @@ dependencies = [ [[package]] name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "ryu" version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" [[package]] name = "safe-mmio" @@ -1727,6 +2109,15 @@ version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3e1c7d2b77d80283c750a39c52f1ab4d17234e8f30bca43550f5b2375f41d5f" +[[package]] +name = "semver" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" +dependencies = [ + "serde", +] + [[package]] name = "serde" version = "1.0.219" @@ -1747,11 +2138,23 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_json" +version = "1.0.143" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d401abef1d108fbd9cbaebc3e46611f4b1021f714a0597a71f41ee463f5f4a5a" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + [[package]] name = "sha2" -version = "0.10.8" +version = "0.10.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" dependencies = [ "cfg-if", "cpufeatures", @@ -1793,6 +2196,9 @@ name = "smallvec" version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" +dependencies = [ + "serde", +] [[package]] name = "smoltcp" @@ -1803,7 +2209,7 @@ dependencies = [ "bitflags 1.3.2", "byteorder", "cfg-if", - "defmt", + "defmt 0.3.100", "heapless 0.8.0", "log", "managed", @@ -1901,6 +2307,21 @@ dependencies = [ "xattr", ] +[[package]] +name = "target-lexicon" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e502f78cdbb8ba4718f566c418c52bc729126ffd16baee5baa718cf25dd5a69a" + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + [[package]] name = "thiserror" version = "2.0.16" @@ -2011,6 +2432,12 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + [[package]] name = "untrusted" version = "0.9.0" @@ -2037,9 +2464,9 @@ dependencies = [ [[package]] name = "ureq-proto" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5b6cabebbecc4c45189ab06b52f956206cea7d8c8a20851c35a85cb169224cc" +checksum = "bbe120bb823a0061680e66e9075942fcdba06d46551548c2c259766b9558bc9a" dependencies = [ "base64", "http", @@ -2049,13 +2476,14 @@ dependencies = [ [[package]] name = "url" -version = "2.5.4" +version = "2.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" +checksum = "08bc136a29a3d1758e07a9cca267be308aeebf5cfd5a10f3f67ab2097683ef5b" dependencies = [ "form_urlencoded", "idna", "percent-encoding", + "serde", ] [[package]] @@ -2090,11 +2518,11 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "virtio-spec" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d48795f97c4b2b552fa2bd4d9549831ce622579088e1f1e7d3ba57eee74f21f" +checksum = "98a3331a2a575016037262a2744834e996a21a360d536f5c75d91e6e18f3ce58" dependencies = [ - "allocator-api2", + "allocator-api2 0.3.0", "bitfield-struct", "bitflags 2.9.3", "endian-num", @@ -2140,17 +2568,17 @@ dependencies = [ [[package]] name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" +version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasi" -version = "0.14.2+wasi-0.2.4" +version = "0.14.3+wasi-0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" +checksum = "6a51ae83037bdd272a9e28ce236db8c07016dd0d50c27038b3f407533c030c95" dependencies = [ - "wit-bindgen-rt", + "wit-bindgen", ] [[package]] @@ -2211,6 +2639,229 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "wasm-encoder" +version = "0.235.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3bc393c395cb621367ff02d854179882b9a351b4e0c93d1397e6090b53a5c2a" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.235.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "161296c618fa2d63f6ed5fffd1112937e803cb9ec71b32b01a76321555660917" +dependencies = [ + "bitflags 2.9.3", + "hashbrown", + "indexmap", + "semver", + "serde", +] + +[[package]] +name = "wasmprinter" +version = "0.235.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75aa8e9076de6b9544e6dab4badada518cca0bf4966d35b131bbd057aed8fa0a" +dependencies = [ + "anyhow", + "termcolor", + "wasmparser", +] + +[[package]] +name = "wasmtime" +version = "35.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6fe976922a16af3b0d67172c473d1fd4f1aa5d0af9c8ba6538c741f3af686f4" +dependencies = [ + "anyhow", + "bitflags 2.9.3", + "bumpalo", + "cc", + "cfg-if", + "encoding_rs", + "hashbrown", + "indexmap", + "libc", + "log", + "mach2", + "memfd", + "object", + "postcard", + "pulley-interpreter", + "semver", + "serde", + "serde_derive", + "smallvec", + "target-lexicon", + "wasmparser", + "wasmtime-environ", + "wasmtime-internal-asm-macros", + "wasmtime-internal-component-macro", + "wasmtime-internal-component-util", + "wasmtime-internal-cranelift", + "wasmtime-internal-math", + "wasmtime-internal-slab", + "wasmtime-internal-unwinder", + "wasmtime-internal-versioned-export-macros", + "wasmtime-internal-winch", + "windows-sys 0.59.0", +] + +[[package]] +name = "wasmtime-environ" +version = "35.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44b6264a78d806924abbc76bbc75eac24976bc83bdfb938e5074ae551242436f" +dependencies = [ + "anyhow", + "cranelift-bitset", + "cranelift-entity", + "gimli", + "indexmap", + "log", + "object", + "postcard", + "semver", + "serde", + "serde_derive", + "smallvec", + "target-lexicon", + "wasm-encoder", + "wasmparser", + "wasmprinter", + "wasmtime-internal-component-util", +] + +[[package]] +name = "wasmtime-internal-asm-macros" +version = "35.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6775a9b516559716e5710e95a8014ca0adcc81e5bf4d3ad7899d89ae40094d1a" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "wasmtime-internal-component-macro" +version = "35.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc3d098205e405e6b5ced06c1815621b823464b6ea289eaafe494139b0aee287" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn", + "wasmtime-internal-component-util", + "wasmtime-internal-wit-bindgen", + "wit-parser", +] + +[[package]] +name = "wasmtime-internal-component-util" +version = "35.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "219252067216242ed2b32665611b0ee356d6e92cbb897ecb9a10cae0b97bdeca" + +[[package]] +name = "wasmtime-internal-cranelift" +version = "35.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ec9ad7565e6a8de7cb95484e230ff689db74a4a085219e0da0cbd637a29c01c" +dependencies = [ + "anyhow", + "cfg-if", + "cranelift-codegen", + "cranelift-control", + "cranelift-entity", + "cranelift-frontend", + "cranelift-native", + "gimli", + "itertools", + "log", + "object", + "pulley-interpreter", + "smallvec", + "target-lexicon", + "thiserror", + "wasmparser", + "wasmtime-environ", + "wasmtime-internal-math", + "wasmtime-internal-versioned-export-macros", +] + +[[package]] +name = "wasmtime-internal-math" +version = "35.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7710d5c4ecdaa772927fd11e5dc30a9a62d1fc8fe933e11ad5576ad596ab6612" +dependencies = [ + "libm", +] + +[[package]] +name = "wasmtime-internal-slab" +version = "35.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6ab22fabe1eed27ab01fd47cd89deacf43ad222ed7fd169ba6f4dd1fbddc53b" + +[[package]] +name = "wasmtime-internal-unwinder" +version = "35.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "307708f302f5dcf19c1bbbfb3d9f2cbc837dd18088a7988747b043a46ba38ecc" +dependencies = [ + "anyhow", + "cfg-if", + "log", + "object", +] + +[[package]] +name = "wasmtime-internal-versioned-export-macros" +version = "35.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "342b0466f92b7217a4de9e114175fedee1907028567d2548bcd42f71a8b5b016" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "wasmtime-internal-winch" +version = "35.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2012e7384c25b91aab2f1b6a1e1cbab9d0f199bbea06cc873597a3f047f05730" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "object", + "target-lexicon", + "wasmparser", + "wasmtime-environ", + "wasmtime-internal-cranelift", + "winch-codegen", +] + +[[package]] +name = "wasmtime-internal-wit-bindgen" +version = "35.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ae057d44a5b60e6ec529b0c21809a9d1fc92e91ef6e0f6771ed11dd02a94a08" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "wit-parser", +] + [[package]] name = "webpki-roots" version = "1.0.2" @@ -2236,20 +2887,49 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0978bf7171b3d90bac376700cb56d606feb40f251a475a5d6634613564460b22" +dependencies = [ + "windows-sys 0.60.2", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "winch-codegen" +version = "35.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "839a334ef7c62d8368dbd427e767a6fbb1ba08cc12ecce19cbb666c10613b585" +dependencies = [ + "anyhow", + "cranelift-assembler-x64", + "cranelift-codegen", + "gimli", + "regalloc2", + "smallvec", + "target-lexicon", + "thiserror", + "wasmparser", + "wasmtime-environ", + "wasmtime-internal-cranelift", + "wasmtime-internal-math", +] + [[package]] name = "windows" -version = "0.61.1" +version = "0.61.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5ee8f3d025738cb02bad7868bbb5f8a6327501e870bf51f1b455b0a2454a419" +checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893" dependencies = [ "windows-collections", - "windows-core 0.61.0", + "windows-core", "windows-future", "windows-link", "windows-numerics", @@ -2261,23 +2941,14 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3beeceb5e5cfd9eb1d76b381630e82c4241ccd0d27f1a39ed41b2760b255c5e8" dependencies = [ - "windows-core 0.61.0", + "windows-core", ] [[package]] name = "windows-core" -version = "0.52.0" +version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-core" -version = "0.61.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4763c1de310c86d75a878046489e2e5ba02c649d185f21c67d4cf8a56d098980" +checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" dependencies = [ "windows-implement", "windows-interface", @@ -2288,12 +2959,13 @@ dependencies = [ [[package]] name = "windows-future" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a1d6bbefcb7b60acd19828e1bc965da6fcf18a7e39490c5f8be71e54a19ba32" +checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e" dependencies = [ - "windows-core 0.61.0", + "windows-core", "windows-link", + "windows-threading", ] [[package]] @@ -2320,9 +2992,9 @@ dependencies = [ [[package]] name = "windows-link" -version = "0.1.1" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" [[package]] name = "windows-numerics" @@ -2330,24 +3002,24 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1" dependencies = [ - "windows-core 0.61.0", + "windows-core", "windows-link", ] [[package]] name = "windows-result" -version = "0.3.2" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c64fd11a4fd95df68efcfee5f44a294fe71b8bc6a91993e2791938abcc712252" +checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" dependencies = [ "windows-link", ] [[package]] name = "windows-strings" -version = "0.4.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2ba9642430ee452d5a7aa78d72907ebe8cfda358e8cb7918a2050581322f97" +checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" dependencies = [ "windows-link", ] @@ -2358,7 +3030,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -2367,7 +3039,16 @@ version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.3", ] [[package]] @@ -2376,14 +3057,40 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.0", + "windows_aarch64_msvc 0.53.0", + "windows_i686_gnu 0.53.0", + "windows_i686_gnullvm 0.53.0", + "windows_i686_msvc 0.53.0", + "windows_x86_64_gnu 0.53.0", + "windows_x86_64_gnullvm 0.53.0", + "windows_x86_64_msvc 0.53.0", +] + +[[package]] +name = "windows-threading" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b66463ad2e0ea3bbf808b7f1d371311c80e115c0b71d60efc142cafbcfb057a6" +dependencies = [ + "windows-link", ] [[package]] @@ -2392,42 +3099,84 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" + [[package]] name = "windows_i686_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" +[[package]] +name = "windows_i686_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" + [[package]] name = "windows_i686_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" + [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_i686_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" @@ -2435,12 +3184,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] -name = "wit-bindgen-rt" -version = "0.39.0" +name = "windows_x86_64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" + +[[package]] +name = "wit-bindgen" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" +checksum = "052283831dbae3d879dc7f51f3d92703a316ca49f91540417d38591826127814" + +[[package]] +name = "wit-parser" +version = "0.235.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a1f95a87d03a33e259af286b857a95911eb46236a0f726cbaec1227b3dfc67a" dependencies = [ - "bitflags 2.9.3", + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", ] [[package]] @@ -2463,7 +3233,7 @@ dependencies = [ [[package]] name = "x86_64" version = "0.15.2" -source = "git+https://github.com/rust-osdev/x86_64.git#72954bba37d591341ee5a982df4e06f23ec9b738" +source = "git+https://github.com/rust-osdev/x86_64.git#fd55fa6d508ab0cd0fb269baab98219b80ffdbae" dependencies = [ "bit_field", "bitflags 2.9.3", @@ -2474,12 +3244,12 @@ dependencies = [ [[package]] name = "xattr" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d65cbf2f12c15564212d48f4e3dfb87923d25d611f2aed18f4cb23f0413d89e" +checksum = "af3a19837351dc82ba89f8a125e22a3c475f05aba604acc023d62b2739ae2909" dependencies = [ "libc", - "rustix", + "rustix 1.0.8", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 0a821ace3d..4647001964 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,6 +76,7 @@ vga = [] virtio = ["dep:virtio"] virtio-net = ["virtio"] vsock = ["virtio", "pci"] +wasm = ["wasmtime"] [lints.rust] rust_2018_idioms = "warn" @@ -144,6 +145,7 @@ time = { version = "0.3", default-features = false } volatile = "0.6" zerocopy = { version = "0.8", default-features = false } uhyve-interface = "0.1.3" +wasmtime = { version = "35.0", default-features = false, features = ["runtime", "gc", "component-model"], optional = true } [dependencies.smoltcp] version = "0.12" 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 7921abe5d2..f672aa2653 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::ptr; use core::sync::atomic::{AtomicPtr, AtomicU32, Ordering}; @@ -42,6 +43,60 @@ pub(crate) mod systemtime; #[cfg(feature = "vga")] pub mod vga; +global_asm!(include_str!("setjmp.s")); +global_asm!(include_str!("longjmp.s")); + +pub(crate) struct Console { + serial_port: SerialPort, +} + +impl Console { + pub fn new() -> Self { + CoreLocal::install(); + + let base = env::boot_info() + .hardware_info + .serial_port_base + .unwrap() + .get(); + let serial_port = unsafe { SerialPort::new(base) }; + Self { serial_port } + } + + pub fn write(&mut self, buf: &[u8]) { + self.serial_port.send(buf); + + #[cfg(feature = "vga")] + for &byte in buf { + // vga::write_byte() checks if VGA support has been initialized, + // so we don't need any additional if clause around it. + vga::write_byte(byte); + } + } + + pub fn buffer_input(&mut self) { + self.serial_port.buffer_input(); + } + + pub fn read(&mut self) -> Option { + self.serial_port.read() + } + + pub fn is_empty(&self) -> bool { + self.serial_port.is_empty() + } + + pub fn register_waker(&mut self, waker: &Waker) { + self.serial_port.register_waker(waker); + } +} + +impl Default for Console { + fn default() -> Self { + Self::new() + } +} + pub fn get_ram_address() -> PhysAddr { PhysAddr::new(env::boot_info().hardware_info.phys_addr_range.start) } 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/lib.rs b/src/lib.rs index 326d7db3ba..bf9f1b75fc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -82,6 +82,8 @@ mod shell; mod synch; pub mod syscalls; pub mod time; +#[cfg(all(target_arch = "x86_64", feature = "wasm"))] +mod wasm; mod built_info { include!(concat!(env!("OUT_DIR"), "/built.rs")); @@ -147,6 +149,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 0000000000000000000000000000000000000000..1c7cd542b201d1a1d8bb6fe49519e3e048d17fb3 GIT binary patch literal 14344 zcmeHOZEPGz8J=C=IcMU;myb3vEyyZINFh1djvIw26jveb9-I}o2qkJrR(p4QzHRp7 zdb@V)5UG)lq*`4AjhG_j#Xr=b62eW^VVXBl(AANxI5Jk=TPw3OkYd>R8aBYva5*&Ni`r z#(GCbvcuVtZLDrnkLXa|*iaX~om3Yn;_p)0rBT`nN^hUQP4#sX5kb z*rs9YgN1@x)k-D9p5kcLGVEzr#aI$c*Yqh2<`mUpMK7M#Ycjj5?V8bR1;^z>xbW+? zRxou{GY!pEHCr?1T*H;60pSPQC>zA^9^t7Li!zdM)vAHU-P52dIv5Mtl~gfJ5cdms z*>p5dmhKT_vKaWT(ys)Dt1U45U-`hsS(t&feg{rcFb z%r+24o0*jv4@4_;mMsl*;_?F{qXh#aV=ekuU8N`2bZ1Pg)auolf@MJXRYw^&4)v-| zwP<@{M1YVI9~?~#&a*bpa>V)biSsC_u;$-EDfp@`UF?xi;Oh3(<;eIWRv=a&Rv=a& zRv=a&Rv=a&Rv=a&R^T&=|A&0zSZboNHCJC4&VBT)fu~PH7Nvf3Nb&E@j^7UxWA>#8+R$2scmuWME@t8P?{L=J~vz^6^)4{?!ZD20l;dyuYCMe`|gm z#2pkA&s~CZE#DC5%MxGxW;*Zh$>jWZ^ZuXm{yWVDkfBMu-=k(@PX;Ms+G|qm#`j>G zF9W^KWl}l+UwQvV-v49sxfLS4k@H_8UWX6y_k065NRYZi{?&XBAz$#V4t$Pd7;9_Jzn=H6(L(3^-%a?B?{4nnx%^e}<$PmoHIm{!(b$^zmz2gQ z(~$thUudd`;d%rr90l216aJ&Sn>Ub4*9&{25lZ9Xl;XdwH2M@@*~wcuIFuo!aWvKX zWt)I-Ilnp4z&elbW6V8Jj7r4GPxWk)zBe-YL z4*8TdI2!*lADQ?TVHLr5{1)7$#F1xu7~yWho)@@V`GT1cZae1xO4oTHKjjMv8iH_# zfLjtcItk&0>$7$qCE$J`aD(gME&=zWJHUMhxR(TO_d0xUMsWA9gG++ z%3jzo>>%u8u*YD>U?*UwU=^4NtHb7DFT!4i{Q&l3*sHK5*soyAus-BTnh(Nu!G>X{ zU?%KImtgpV-KiT2k~zYy_% zQ?$Q@`n$02N3Oks_JZgyM*KfR`{%INg)fPk=1p^?xlrDeXIx?hVg+IaVg+IaVg+Ia zVg+IaVg+Ia{?`hWje=w2*=(br+r>(0+OpOcoDYTN)l6*JrCv z&Ep{*J}CusmIzo+uccc~Z4S>dw;5O>$)i}3KdKx&zudzl>_8dA^YeTUHz3h2Z9tBE z;>l(dyr@81DJe}K;e*ipsc4C=Gc={%&oXuasIN)bFX9y98xmWRaLVwa#Fi!O`hO^~ zm*nHp8$Ac4mlK1p0@b5P^NC&3>xn@eKJ-a_NqKX!XWN!UW@qxy_8!(u?3U(}_sdt3 z*lRz|7_yaQxrd&(MvGGCIne~xDW3yKMr>HZ^OUmi(>|F>cy98j@Y6n-N_b8}XAZ=( z%)NMyLDX-eCO_?+sf6bs=g=lU?VYKF_`je{{x^g_9QTXDpXMuqJuC&G+%3l4FZ|&- z2JP#K=V*uj)52d7erU(bhlPJ$_``DvN`rW=bl{n5Oxc<@jh7TojGjDrkl&h~qrzw4 zodvx8VO1S^@goWxxl`cqxKZ20!X`UuJq#h?Kct#{hx2I@Pvw9_XFNI~@itE+ziU?X^J!et>zf$Pj zD!2#N(v6GmS69Ef+#|j=ZSW*o-Qur{xK4bxKKbwyw6@T19hI;Sdbji)_`8kIhJt`S z;(HZ_caFc~Ht~Dz3nDTd0Uceo;WqJ;9|+>#7gX)f&iKQ(iRTB6?WjnjLl64>BF>I! z1_zb!)A~e9=lJwH)GdB;IEZ>T8Z59;R|B0}#)fZlBtT7y0qN2{SGg7=0ArE-QtJGf`~7Lfuin=|2JL9k%a&N literal 0 HcmV?d00001 diff --git a/src/wasm/fib.wasm b/src/wasm/fib.wasm new file mode 100755 index 0000000000000000000000000000000000000000..a0dfaf9cf0154ae1c38e2581e6caee77a70adf4b GIT binary patch literal 582 zcmZ8eU5nE|6umcJZ8vrsKOV#f$qK?QC288krrjqk_yC9^SwP@5Z3(W=HDJp&R-*Zb7enrRx&tmtcJF=K87+!2|;gS-)tTR*7v3KTs)1 z&R{fbUD@Bdcwe-CEMo6aQllo%_wv&q=rjQ(Sr$a1thw^?ZycMJc}|KbV2@Q<3-!gH zaR0G`X9$xZ;DXTmpeoZsuo`~isH)4Tp{(Z8Fe63Mkc6S~so?^iv{#gI&LS(^OKRP6 z^zGdC*S2F7X|fa9-n@3ARp`3jl9&r;;aQGn&Al6ycB}5@OWUzM^Li&l#cyY`Bo(_R z?0n6#?4d7K`^Z;Dg-MvVn6H;1_1112vz6}?pSe*SuR`W79QR$sh!;8j4Xh`E)Cm(o m%!p`e#^tFVHrc(^fAn;cH-dy2vy!X~Nyeu`o+gFG9>s4DjGPq! literal 0 HcmV?d00001 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(()) +} From 0b38f7ee4a235cbedfb55ba878d643933894a976 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sat, 22 Jun 2024 00:59:45 +0200 Subject: [PATCH 02/24] switch to wasmtime 22.0 --- Cargo.lock | 456 ++++++++++++++++++++++----------------------- Cargo.toml | 2 +- src/wasm/fib.cwasm | Bin 14344 -> 14312 bytes 3 files changed, 225 insertions(+), 233 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9b6662974f..86a20d110e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -66,12 +66,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ac6c08a67736554282858203cd9b7ff53cf55f54c34e85689962748a350cbf0" -[[package]] -name = "allocator-api2" -version = "0.2.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" - [[package]] name = "allocator-api2" version = "0.3.0" @@ -163,7 +157,7 @@ checksum = "6bfdb03424c95b58315a4cb0ff4ca919568a5a28ae5ba960a1ad92c9ccaf49b9" dependencies = [ "bitflags 2.9.3", "safe-mmio", - "thiserror", + "thiserror 2.0.16", "zerocopy", ] @@ -287,9 +281,6 @@ name = "bumpalo" version = "3.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" -dependencies = [ - "allocator-api2 0.2.21", -] [[package]] name = "byteorder" @@ -372,7 +363,7 @@ version = "4.5.45" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14cb31bb0a7d536caef2639baa7fad459e15c3144efefa6dbd1c84562c4739f6" dependencies = [ - "heck", + "heck 0.5.0", "proc-macro2", "quote", "syn", @@ -390,7 +381,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fa961b519f0b462e3a3b4a34b64d119eeaca1d59af726fe450bbba07a9fc0a1" dependencies = [ - "thiserror", + "thiserror 2.0.16", ] [[package]] @@ -435,113 +426,76 @@ dependencies = [ "libc", ] -[[package]] -name = "cranelift-assembler-x64" -version = "0.122.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ae7b60ec3fd7162427d3b3801520a1908bef7c035b52983cd3ca11b8e7deb51" -dependencies = [ - "cranelift-assembler-x64-meta", -] - -[[package]] -name = "cranelift-assembler-x64-meta" -version = "0.122.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6511c200fed36452697b4b6b161eae57d917a2044e6333b1c1389ed63ccadeee" -dependencies = [ - "cranelift-srcgen", -] - [[package]] name = "cranelift-bforest" -version = "0.122.0" +version = "0.109.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f7086a645aa58bae979312f64e3029ac760ac1b577f5cd2417844842a2ca07f" +checksum = "fad7096c10a285583f2ed620c0c85d7baf745922e33415290f2900b73319f1e0" dependencies = [ "cranelift-entity", ] -[[package]] -name = "cranelift-bitset" -version = "0.122.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5225b4dec45f3f3dbf383f12560fac5ce8d780f399893607e21406e12e77f491" -dependencies = [ - "serde", - "serde_derive", -] - [[package]] name = "cranelift-codegen" -version = "0.122.0" +version = "0.109.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "858fb3331e53492a95979378d6df5208dd1d0d315f19c052be8115f4efc888e0" +checksum = "bd0d5b0dcd4a4e18c6352304d76f1c63258b5b2c248fc261b89c3a02952d51ff" dependencies = [ "bumpalo", - "cranelift-assembler-x64", "cranelift-bforest", - "cranelift-bitset", "cranelift-codegen-meta", "cranelift-codegen-shared", "cranelift-control", "cranelift-entity", "cranelift-isle", "gimli", - "hashbrown", + "hashbrown 0.14.5", "log", - "pulley-interpreter", "regalloc2", "rustc-hash", - "serde", "smallvec", "target-lexicon", - "wasmtime-internal-math", ] [[package]] name = "cranelift-codegen-meta" -version = "0.122.0" +version = "0.109.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "456715b9d5f12398f156d5081096e7b5d039f01b9ecc49790a011c8e43e65b5f" +checksum = "3d14aa8551924931235a4eec42d561a8415d5a758267a549575a3fe0e13ba84f" dependencies = [ - "cranelift-assembler-x64-meta", "cranelift-codegen-shared", - "cranelift-srcgen", - "pulley-interpreter", ] [[package]] name = "cranelift-codegen-shared" -version = "0.122.0" +version = "0.109.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0306041099499833f167a0ddb707e1e54100f1a84eab5631bc3dad249708f482" +checksum = "315a326e9f63b996f55e93b73a9a239b55f2de1211fcfbcc99d9423f44dc6ded" [[package]] name = "cranelift-control" -version = "0.122.0" +version = "0.109.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1672945e1f9afc2297f49c92623f5eabc64398e2cb0d824f8f72a2db2df5af23" +checksum = "806ca69ca5aa8422035543444e1dc936f8f3e7f6854d562ef31db9fe30355c5c" dependencies = [ "arbitrary", ] [[package]] name = "cranelift-entity" -version = "0.122.0" +version = "0.109.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa3cd55eb5f3825b9ae5de1530887907360a6334caccdc124c52f6d75246c98a" +checksum = "c9778487136bf37f9007920d9cb332a020e5d7259c1fbf35e625368eb88c7bfe" dependencies = [ - "cranelift-bitset", "serde", "serde_derive", ] [[package]] name = "cranelift-frontend" -version = "0.122.0" +version = "0.109.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "781f9905f8139b8de22987b66b522b416fe63eb76d823f0b3a8c02c8fd9500c7" +checksum = "55326cb3b61ca368210899a35892bca66aea4d75e8ceb5464e0539906c2ffb61" dependencies = [ "cranelift-codegen", "log", @@ -551,15 +505,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.122.0" +version = "0.109.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a05337a2b02c3df00b4dd9a263a027a07b3dff49f61f7da3b5d195c21eaa633d" +checksum = "4807df8ebad0106f207bcdc1f38199200ed175066b4122689e7f18e33ec8548c" [[package]] name = "cranelift-native" -version = "0.122.0" +version = "0.109.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2eee7a496dd66380082c9c5b6f2d5fa149cec0ec383feec5caf079ca2b3671c2" +checksum = "91c24c076002cb6a926a3f7220040278c7178878cd9142a418ddef9ee5b84963" dependencies = [ "cranelift-codegen", "libc", @@ -567,10 +521,20 @@ dependencies = [ ] [[package]] -name = "cranelift-srcgen" -version = "0.122.0" +name = "cranelift-wasm" +version = "0.109.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b530783809a55cb68d070e0de60cfbb3db0dc94c8850dd5725411422bedcf6bb" +checksum = "66ba3e8a666222d2df5a79a1279282c04545c4ca9712b7d85f4f54937617a533" +dependencies = [ + "cranelift-codegen", + "cranelift-entity", + "cranelift-frontend", + "itertools", + "log", + "smallvec", + "wasmparser", + "wasmtime-types", +] [[package]] name = "crc" @@ -656,7 +620,7 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10d60334b3b2e7c9d91ef8150abfb6fa4c1c39ebbcf4a81c2e346aad939fee3e" dependencies = [ - "thiserror", + "thiserror 2.0.16", ] [[package]] @@ -946,9 +910,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.31.1" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" dependencies = [ "fallible-iterator", "indexmap", @@ -988,6 +952,25 @@ 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", + "serde", +] + [[package]] name = "hashbrown" version = "0.15.5" @@ -995,7 +978,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" dependencies = [ "foldhash", - "serde", ] [[package]] @@ -1018,6 +1000,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" @@ -1060,7 +1048,7 @@ dependencies = [ "float-cmp", "free-list", "fuse-abi", - "hashbrown", + "hashbrown 0.15.5", "heapless 0.9.1", "hermit-entry", "hermit-macro", @@ -1084,7 +1072,7 @@ dependencies = [ "smoltcp", "take-static", "talc", - "thiserror", + "thiserror 2.0.16", "time", "tock-registers 0.10.0", "trapframe", @@ -1291,7 +1279,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2481980430f9f78649238835720ddccc57e52df14ffce1c6f37391d61b563e9" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.15.5", "serde", ] @@ -1323,9 +1311,9 @@ checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "itertools" -version = "0.14.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" dependencies = [ "either", ] @@ -1357,10 +1345,10 @@ dependencies = [ ] [[package]] -name = "leb128fmt" -version = "0.1.0" +name = "leb128" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" [[package]] name = "libc" @@ -1489,6 +1477,15 @@ dependencies = [ "rustix 0.38.44", ] +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + [[package]] name = "memory_addresses" version = "0.2.3" @@ -1608,7 +1605,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" dependencies = [ "crc32fast", - "hashbrown", + "hashbrown 0.15.5", "indexmap", "memchr", ] @@ -1812,26 +1809,12 @@ dependencies = [ ] [[package]] -name = "pulley-interpreter" -version = "35.0.0" +name = "psm" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b89c4319786b16c1a6a38ee04788d32c669b61ba4b69da2162c868c18be99c1b" +checksum = "6e944464ec8536cd1beb0bbfd96987eb5e3b72f2ecdafdc5c769a37f1fa2ae1f" dependencies = [ - "cranelift-bitset", - "log", - "pulley-macros", - "wasmtime-internal-math", -] - -[[package]] -name = "pulley-macros" -version = "35.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "938543690519c20c3a480d20a8efcc8e69abeb44093ab1df4e7c1f81f26c677a" -dependencies = [ - "proc-macro2", - "quote", - "syn", + "cc", ] [[package]] @@ -1909,15 +1892,14 @@ dependencies = [ [[package]] name = "regalloc2" -version = "0.12.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5216b1837de2149f8bc8e6d5f88a9326b63b8c836ed58ce4a0a29ec736a59734" +checksum = "ad156d539c879b7a24a363a2016d77961786e71f48f2e2fc8302a92abd2429a6" dependencies = [ - "allocator-api2 0.2.21", - "bumpalo", - "hashbrown", + "hashbrown 0.13.2", "log", "rustc-hash", + "slice-group-by", "smallvec", ] @@ -1967,9 +1949,9 @@ checksum = "8188909339ccc0c68cfb5a04648313f09621e8b87dc03095454f1a11f6c5d436" [[package]] name = "rustc-hash" -version = "2.1.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustix" @@ -2114,9 +2096,6 @@ name = "semver" version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" -dependencies = [ - "serde", -] [[package]] name = "serde" @@ -2191,6 +2170,12 @@ version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" +[[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.15.1" @@ -2224,6 +2209,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" @@ -2309,17 +2300,17 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.13.2" +version = "0.12.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e502f78cdbb8ba4718f566c418c52bc729126ffd16baee5baa718cf25dd5a69a" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" [[package]] -name = "termcolor" -version = "1.4.1" +name = "thiserror" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ - "winapi-util", + "thiserror-impl 1.0.69", ] [[package]] @@ -2328,7 +2319,18 @@ version = "2.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0" dependencies = [ - "thiserror-impl", + "thiserror-impl 2.0.16", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -2522,7 +2524,7 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98a3331a2a575016037262a2744834e996a21a360d536f5c75d91e6e18f3ce58" dependencies = [ - "allocator-api2 0.3.0", + "allocator-api2", "bitfield-struct", "bitflags 2.9.3", "endian-num", @@ -2641,22 +2643,22 @@ dependencies = [ [[package]] name = "wasm-encoder" -version = "0.235.0" +version = "0.209.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3bc393c395cb621367ff02d854179882b9a351b4e0c93d1397e6090b53a5c2a" +checksum = "7b4a05336882dae732ce6bd48b7e11fe597293cb72c13da4f35d7d5f8d53b2a7" dependencies = [ - "leb128fmt", - "wasmparser", + "leb128", ] [[package]] name = "wasmparser" -version = "0.235.0" +version = "0.209.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "161296c618fa2d63f6ed5fffd1112937e803cb9ec71b32b01a76321555660917" +checksum = "07035cc9a9b41e62d3bb3a3815a66ab87c993c06fe1cf6b2a3f2a18499d937db" dependencies = [ + "ahash", "bitflags 2.9.3", - "hashbrown", + "hashbrown 0.14.5", "indexmap", "semver", "serde", @@ -2664,115 +2666,93 @@ dependencies = [ [[package]] name = "wasmprinter" -version = "0.235.0" +version = "0.209.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75aa8e9076de6b9544e6dab4badada518cca0bf4966d35b131bbd057aed8fa0a" +checksum = "ceca8ae6eaa8c7c87b33c25c53bdf299f8c2a764aee1179402ff7652ef3a6859" dependencies = [ "anyhow", - "termcolor", "wasmparser", ] [[package]] name = "wasmtime" -version = "35.0.0" +version = "22.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6fe976922a16af3b0d67172c473d1fd4f1aa5d0af9c8ba6538c741f3af686f4" +checksum = "9de397b45aa057cbadd8fbef22227779ef05121d9f47ac55c9a1ff77e0c29695" dependencies = [ "anyhow", - "bitflags 2.9.3", "bumpalo", "cc", "cfg-if", "encoding_rs", - "hashbrown", + "hashbrown 0.14.5", "indexmap", "libc", + "libm", "log", "mach2", "memfd", + "memoffset", "object", + "once_cell", + "paste", "postcard", - "pulley-interpreter", + "psm", + "rustix 0.38.44", "semver", "serde", "serde_derive", "smallvec", + "sptr", "target-lexicon", "wasmparser", + "wasmtime-asm-macros", + "wasmtime-component-macro", + "wasmtime-component-util", + "wasmtime-cranelift", "wasmtime-environ", - "wasmtime-internal-asm-macros", - "wasmtime-internal-component-macro", - "wasmtime-internal-component-util", - "wasmtime-internal-cranelift", - "wasmtime-internal-math", - "wasmtime-internal-slab", - "wasmtime-internal-unwinder", - "wasmtime-internal-versioned-export-macros", - "wasmtime-internal-winch", - "windows-sys 0.59.0", -] - -[[package]] -name = "wasmtime-environ" -version = "35.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44b6264a78d806924abbc76bbc75eac24976bc83bdfb938e5074ae551242436f" -dependencies = [ - "anyhow", - "cranelift-bitset", - "cranelift-entity", - "gimli", - "indexmap", - "log", - "object", - "postcard", - "semver", - "serde", - "serde_derive", - "smallvec", - "target-lexicon", - "wasm-encoder", - "wasmparser", - "wasmprinter", - "wasmtime-internal-component-util", + "wasmtime-jit-icache-coherence", + "wasmtime-slab", + "wasmtime-versioned-export-macros", + "wasmtime-winch", + "windows-sys 0.52.0", ] [[package]] -name = "wasmtime-internal-asm-macros" -version = "35.0.0" +name = "wasmtime-asm-macros" +version = "22.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6775a9b516559716e5710e95a8014ca0adcc81e5bf4d3ad7899d89ae40094d1a" +checksum = "379c81227d624024d8b950a9eb7fc48671f77fff368e021d9b6f16c83a650369" dependencies = [ "cfg-if", ] [[package]] -name = "wasmtime-internal-component-macro" -version = "35.0.0" +name = "wasmtime-component-macro" +version = "22.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc3d098205e405e6b5ced06c1815621b823464b6ea289eaafe494139b0aee287" +checksum = "2f579efa3807fc05078939d001e9295f3ab65613345fa7fe0c19875129aabae4" dependencies = [ "anyhow", "proc-macro2", "quote", "syn", - "wasmtime-internal-component-util", - "wasmtime-internal-wit-bindgen", + "wasmtime-component-util", + "wasmtime-wit-bindgen", "wit-parser", ] [[package]] -name = "wasmtime-internal-component-util" -version = "35.0.0" +name = "wasmtime-component-util" +version = "22.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "219252067216242ed2b32665611b0ee356d6e92cbb897ecb9a10cae0b97bdeca" +checksum = "e935348dec39c79e895f80dd9ea7726b0c9059ef6210deae0c58e7e327422adc" [[package]] -name = "wasmtime-internal-cranelift" -version = "35.0.0" +name = "wasmtime-cranelift" +version = "22.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ec9ad7565e6a8de7cb95484e230ff689db74a4a085219e0da0cbd637a29c01c" +checksum = "8e8ec68af53f896a8c98ce7c540762686239b6b81f83d95ef2a074d8b0d67443" dependencies = [ "anyhow", "cfg-if", @@ -2781,52 +2761,76 @@ dependencies = [ "cranelift-entity", "cranelift-frontend", "cranelift-native", + "cranelift-wasm", "gimli", - "itertools", "log", "object", - "pulley-interpreter", - "smallvec", "target-lexicon", - "thiserror", + "thiserror 1.0.69", "wasmparser", "wasmtime-environ", - "wasmtime-internal-math", - "wasmtime-internal-versioned-export-macros", + "wasmtime-versioned-export-macros", ] [[package]] -name = "wasmtime-internal-math" -version = "35.0.0" +name = "wasmtime-environ" +version = "22.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7710d5c4ecdaa772927fd11e5dc30a9a62d1fc8fe933e11ad5576ad596ab6612" +checksum = "e41bba8b753ccb9426986b106fa03820bc04e097f02e09f28ce85ca0191d7db0" dependencies = [ - "libm", + "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 = "22.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0e7ccd55d5dfff4fb7abc889137c5af6531ad57bbd5890651f7e22533a61c7d" +dependencies = [ + "anyhow", + "cfg-if", + "libc", + "windows-sys 0.52.0", ] [[package]] -name = "wasmtime-internal-slab" -version = "35.0.0" +name = "wasmtime-slab" +version = "22.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6ab22fabe1eed27ab01fd47cd89deacf43ad222ed7fd169ba6f4dd1fbddc53b" +checksum = "7df4e5141e11e6f12330450d97f289ccc8f7de2d3c2db7c46252ccd95d78f093" [[package]] -name = "wasmtime-internal-unwinder" -version = "35.0.0" +name = "wasmtime-types" +version = "22.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "307708f302f5dcf19c1bbbfb3d9f2cbc837dd18088a7988747b043a46ba38ecc" +checksum = "b2017ea47e7a91440f94cc29f5f41d303e80f979a5384bf560d4b0afdabe32d0" dependencies = [ - "anyhow", - "cfg-if", - "log", - "object", + "cranelift-entity", + "serde", + "serde_derive", + "smallvec", + "wasmparser", ] [[package]] -name = "wasmtime-internal-versioned-export-macros" -version = "35.0.0" +name = "wasmtime-versioned-export-macros" +version = "22.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "342b0466f92b7217a4de9e114175fedee1907028567d2548bcd42f71a8b5b016" +checksum = "455fc30062a08ba6a9c2ccc6e8c76ea2759d01324d3548324f5d38257d0e8d96" dependencies = [ "proc-macro2", "quote", @@ -2834,10 +2838,10 @@ dependencies = [ ] [[package]] -name = "wasmtime-internal-winch" -version = "35.0.0" +name = "wasmtime-winch" +version = "22.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2012e7384c25b91aab2f1b6a1e1cbab9d0f199bbea06cc873597a3f047f05730" +checksum = "de67dfca76c725b17179185c6ce2d78766656e150b86773b4ddbd2257240ef57" dependencies = [ "anyhow", "cranelift-codegen", @@ -2845,19 +2849,19 @@ dependencies = [ "object", "target-lexicon", "wasmparser", + "wasmtime-cranelift", "wasmtime-environ", - "wasmtime-internal-cranelift", "winch-codegen", ] [[package]] -name = "wasmtime-internal-wit-bindgen" -version = "35.0.0" +name = "wasmtime-wit-bindgen" +version = "22.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ae057d44a5b60e6ec529b0c21809a9d1fc92e91ef6e0f6771ed11dd02a94a08" +checksum = "e6b893eec1dbf19e20beb6f2821ddd9672978db0e7c00ab8bb628afaad823783" dependencies = [ "anyhow", - "heck", + "heck 0.4.1", "indexmap", "wit-parser", ] @@ -2887,15 +2891,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-util" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0978bf7171b3d90bac376700cb56d606feb40f251a475a5d6634613564460b22" -dependencies = [ - "windows-sys 0.60.2", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -2904,22 +2899,19 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "winch-codegen" -version = "35.0.0" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "839a334ef7c62d8368dbd427e767a6fbb1ba08cc12ecce19cbb666c10613b585" +checksum = "b51d823bdea98f7ce9db47909f1c543b5ae253d3df1aebf7ba3c0f25444daef2" dependencies = [ "anyhow", - "cranelift-assembler-x64", "cranelift-codegen", "gimli", "regalloc2", "smallvec", "target-lexicon", - "thiserror", "wasmparser", + "wasmtime-cranelift", "wasmtime-environ", - "wasmtime-internal-cranelift", - "wasmtime-internal-math", ] [[package]] @@ -3197,9 +3189,9 @@ checksum = "052283831dbae3d879dc7f51f3d92703a316ca49f91540417d38591826127814" [[package]] name = "wit-parser" -version = "0.235.0" +version = "0.209.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a1f95a87d03a33e259af286b857a95911eb46236a0f726cbaec1227b3dfc67a" +checksum = "3e79b9e3c0b6bb589dec46317e645851e0db2734c44e2be5e251b03ff4a51269" dependencies = [ "anyhow", "id-arena", diff --git a/Cargo.toml b/Cargo.toml index 4647001964..7487c4d9a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -145,7 +145,7 @@ time = { version = "0.3", default-features = false } volatile = "0.6" zerocopy = { version = "0.8", default-features = false } uhyve-interface = "0.1.3" -wasmtime = { version = "35.0", default-features = false, features = ["runtime", "gc", "component-model"], optional = true } +wasmtime = { version = "22.0", default-features = false, features = ["runtime", "gc", "component-model"], optional = true } [dependencies.smoltcp] version = "0.12" diff --git a/src/wasm/fib.cwasm b/src/wasm/fib.cwasm index 1c7cd542b201d1a1d8bb6fe49519e3e048d17fb3..fa770cb30da336301946a0060b46c721b3ddcb8b 100644 GIT binary patch delta 1392 zcmah{ZD?C%6h800NqXaM)0?<#fla;5V&|OHG-;X|#%xvEn{neRA{IwUvvgyXB^h1I zS`ZQ`>Mqym==tFXesmz{7zj2Z?8j=s(J}DHIz{}b*ny5(#^^v0`=jx^H*fq^@WAuF z=Y7s|KJMY3J+)do|A_usCpgCF>~XvvXa*I)6N|M++oN9?d3i^rqE*P0O2y^ej*eC5 ztH?*R!zHK;X0$^dT;gT zz_03zKEMX>IejlXfm3u2;{`h3#p`t5zPV_>=G#;U9vBcEG0`qB1WN>J!&$XM|q{z~91C zKHiVlQEtOt6VBIypB3+Jaq~)CzarjVaq}%Wb(~fJhTtC% z{IK8$1#i~*va@E+H4-LC$O|caM6yQX=LO#*__lf&_6z>F;2XaX?ZK&26@0(Y|3Wvf zzv1xr0nqjw!}WNuoJx&M6be&tCU?4UBs!Ez9iJ%X$45)WBc1#)dbCu`<@2NM`BI^f zD~@E3O`a-^jc*}Oko@SeV*bScOXDQXW_ibKUp{y8WOih{GF2?m`6(+ z#2TI~tsZeN_uR>5vvKpaVSdQ`CEZkg4PSECa?)K{a$#P^X4}jMGMwOx?zro*#pWd_ z=lAYpT|Cw9Xft1|H#-BFSp*GpuIKJ1!+iN=paG@%-QwzB3}j~?6>^N!&)A$h!}VJ zYDE_x#v0?_vF_xDSV#FS*4v1dabwkD=hPdt2J`bVU*)1-G1W;$ycRhPa_cMdC&(2= z0#?rRFG!t5Y#PzkLe4~0`%oH}a2dJ|-GC;b`_L5hA2b6wQD+I{h5S$u+5+u{_CZPL z1eAuxp?lCnXd05gp%*oFLDH9YNclrVe5U$vu{=-Kl{KctSjcnUH4?nGkVupwBJjEJ z?O^3@`c2@76-0jsni5X*EoepfhFh$r=$p(E%=Lojd0m9t%OIXh`+ z$+Awx}h_2|F4}h%|3CCoh?x@ z&8;mbwR(;JX^Cj{)vQHUiw Date: Sat, 22 Jun 2024 07:51:18 +0200 Subject: [PATCH 03/24] add license text to the derived implementation of setjmp/longjmp --- src/arch/x86_64/kernel/longjmp.s | 5 +++++ src/arch/x86_64/kernel/setjmp.s | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/arch/x86_64/kernel/longjmp.s b/src/arch/x86_64/kernel/longjmp.s index 1046296265..fd0bdfd9c3 100644 --- a/src/arch/x86_64/kernel/longjmp.s +++ b/src/arch/x86_64/kernel/longjmp.s @@ -1,3 +1,8 @@ +# The code is derived from the musl implementation +# of longjmp. +# +# Copyright 2011-2012 Nicholas J. Kain, +# licensed under standard MIT license .section .text .global longjmp longjmp: diff --git a/src/arch/x86_64/kernel/setjmp.s b/src/arch/x86_64/kernel/setjmp.s index efd4875829..33fe89bbe1 100644 --- a/src/arch/x86_64/kernel/setjmp.s +++ b/src/arch/x86_64/kernel/setjmp.s @@ -1,3 +1,8 @@ +# The code is derived from the musl implementation +# of setjmp. +# +# Copyright 2011-2012 Nicholas J. Kain, +# licensed under standard MIT license .section .text .global setjmp setjmp: @@ -12,4 +17,4 @@ 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 +ret From 8becfea4869a2b7275358331b5e8fecade6e5848 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sat, 22 Jun 2024 08:19:57 +0200 Subject: [PATCH 04/24] update wasm example --- src/wasm/fib.cwasm | Bin 14312 -> 13904 bytes src/wasm/fib.wasm | Bin 582 -> 398 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/src/wasm/fib.cwasm b/src/wasm/fib.cwasm index fa770cb30da336301946a0060b46c721b3ddcb8b..8a137d359a31b025e285d57bc810287ad9ca549d 100644 GIT binary patch delta 679 zcmYLFJ!lkB5T1FDi@8m*9%q6@KyNuYG(y4t4$S*zzWLs~Z+E}>`NsNbk?~$l zy~xmT)ASr40ZHM_a(AQ1bL5bIR_Lx)O91NbC`WfR(&bOTJ45u_ZrvAwI$<%_e%lY-t zTnjf``!Wt+uT`d3qm??OhU#&>dF!r#G;_^HRISzkQkA$-T?Vwma51_ag>hq1;z$@S z$5AV+L@TirfV>yg0lH=o^xVxa$z%i)q0{NG;{Pc+tiO-AhvoMOJuKt8D6q#grc(mm zhe~N)!V50hPQE^&=A1ryf-#{gNm7yjeWnb`ld3dddw)Sp&Rg6d+;G^oRT- z!)Frv00lFT4euL%-tgxP-!(jY)S-Ui6_?sGqjbhA(F1P@i}cq!g)SYN{X%^?MEkQp zah!Hbfi_IiuSWzQz`w3ckmQmQTCK5bfpSixovHxMY&U=5e_lGsS@PSS*? zAZ{S|v0VB=M$sQBrXtj$RMNEmk>XK{QbbID*gsZ?qVXz0QxLR4v%WJs7h_H5cy``- z-e=x3MaQoi>}8`7r#k-B$5*FXmhHY|g);76w!2`v zKUeZAeEvel{eqXsifVt_CDfHr$4dz-b@#1xXO|9y+DrFm#;@FMtre|dy%pQ_Di>C~ zdLHw_8-%x3-`jO#J4v!-BT2HXIWiR!8!qh&QTG-t>C~lB5oM5|rd?_a(c|?NjbGdA z%?UHJ*CRJ-Ce2a(@Di5Arn7VAW@id5c1wmgYw4Z%89UfdAl^W{DLJk=4Nw%~Gf19WllV}^A7Ot9@yVK88RIK* z%+I#E*q0c8h4@->8usIe8wkD`Zak>q%lxHgG8T4vNAme&+3eAtBl&EuXK*mvJ6s$( z(m!yhSm?>+2AXrle7>j9o9!EYu{bn*sIQPad>2PTsBY#3Kn>>m^2MQJ3h1j9AfSm^ zpz)&x!XKal!LtHT9)zH9UPrk9I%Un1Js)dw2u>g{Ha13r&jGwb;4K2vqy;`8Fi&(i zk2!_HWgID;t$5_XKkT}497vAqD;0eiZ!vehRkbJ-7+kF~v&%)5G z3rCIYR4S@N zlh15nGbx93uy}fx-XZtA!B?fD4V`gcW#Xan#{ZXV*yZ#NeKa8mI4!isV^O^!uhY*b&u>d6G4N876ib=t=X|#yS{_>4vb>fBx6sUj?R70o5SG~Nss>=ui{Z*Mb*4I zOtyJim6~Na5T{mVdvGeU(V$}G#xoJwo7R$QYu-)o+{feXHC9ong<*2?qhG!J4$c3z tcubAYh?z(mG<%Y|%FAF4?uQ31$l;C4IhM1a&CY^sO~Z3zts5@g#Wx%mJXin# delta 440 zcmYk2%SyvQ6o${qt(QO>#f5I9%S!FVHd^b>CvfLRWICBl(&$VQl8Kj16Lc?#Z{icU z^0{oSNH;$}KZlQx^QM0rH$ZcV0Dvuhj!Rt5wQ>n_0KH}bY8s$nVv2~Sj^J1gEb+3c zzQC>>>Xzg($(}W61d*4-l(7g5)8jE)fZ2So-pi{}1G@#zOI1~WY1g3x4mi5qT$K(w zxT^4qMocA#Mty}EJg%K?tt~EYu$t)?QaT~M)qv;XM t+KOf&S0vz66&cU Date: Sat, 22 Jun 2024 11:36:31 +0200 Subject: [PATCH 05/24] remove compiler warnings --- src/wasm/capi.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/wasm/capi.rs b/src/wasm/capi.rs index 242c69fc06..96427fbccd 100644 --- a/src/wasm/capi.rs +++ b/src/wasm/capi.rs @@ -1,4 +1,3 @@ -use core::arch::global_asm; use core::cell::UnsafeCell; use align_address::Align; @@ -13,7 +12,7 @@ bitflags! { /// Flags to either `wasmtime_mmap_{new,remap}` or `wasmtime_mprotect`. #[repr(C)] #[derive(Debug, Copy, Clone, Default)] - struct WasmProt: u32 { + pub struct WasmProt: u32 { /// Indicates that the memory region should be readable. const Read = 1 << 0; /// Indicates that the memory region should be writable. @@ -48,13 +47,13 @@ bitflags! { /// 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 = +pub 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 {} +pub enum wasmtime_memory_image {} #[thread_local] static TLS: UnsafeCell<*mut u8> = UnsafeCell::new(core::ptr::null_mut()); From a0e4e5f8d99a56177f2ff2004bb12a255ece6bff Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sat, 22 Jun 2024 11:37:32 +0200 Subject: [PATCH 06/24] prepare wasm support for aarch64 and riscv64 --- Cargo.toml | 8 +++++ src/arch/aarch64/kernel/longjmp.s | 18 ++++++++++++ src/arch/aarch64/kernel/mod.rs | 49 +++++++++++++++++++++++++++++++ src/arch/aarch64/kernel/setjmp.s | 16 ++++++++++ src/arch/riscv64/kernel/longjmp.s | 23 +++++++++++++++ src/arch/riscv64/kernel/mod.rs | 36 +++++++++++++++++++++++ src/arch/riscv64/kernel/setjmp.s | 22 ++++++++++++++ src/lib.rs | 4 +-- 8 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 src/arch/aarch64/kernel/longjmp.s create mode 100644 src/arch/aarch64/kernel/setjmp.s create mode 100644 src/arch/riscv64/kernel/longjmp.s create mode 100644 src/arch/riscv64/kernel/setjmp.s diff --git a/Cargo.toml b/Cargo.toml index 7487c4d9a9..0d5e355bce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -171,18 +171,26 @@ free-list = { version = "0.3", features = ["x86_64"] } raw-cpuid = "11" uart_16550 = "0.4" x86_64 = "0.15" +<<<<<<< HEAD memory_addresses = { version = "0.2.3", default-features = false, features = [ "x86_64", "conv-x86_64", ] } +======= +wasmtime = { version = "22.0", default-features = false, features = ["runtime", "gc", "component-model"], optional = true } +>>>>>>> cd1d8b6fa (prepare wasm support for aarch64 and riscv64) [target.'cfg(target_arch = "aarch64")'.dependencies] aarch64 = { version = "0.0.14", default-features = false } arm-gic = { version = "0.6" } semihosting = { version = "0.1", optional = true } +<<<<<<< HEAD memory_addresses = { version = "0.2.3", default-features = false, features = [ "aarch64", ] } +======= +wasmtime = { version = "22.0", default-features = false, features = ["runtime", "gc", "component-model"], optional = true } +>>>>>>> cd1d8b6fa (prepare wasm support for aarch64 and riscv64) [target.'cfg(target_arch = "riscv64")'.dependencies] riscv = "0.14" diff --git a/src/arch/aarch64/kernel/longjmp.s b/src/arch/aarch64/kernel/longjmp.s new file mode 100644 index 0000000000..f930d09382 --- /dev/null +++ b/src/arch/aarch64/kernel/longjmp.s @@ -0,0 +1,18 @@ +# The code is derived from the musl implementation +# of longjmp. +.section .text +.global longjmp +longjmp: + # IHI0055B_aapcs64.pdf 5.1.1, 5.1.2 callee saved registers + ldp x19, x20, [x0,#0] + ldp x21, x22, [x0,#16] + ldp x23, x24, [x0,#32] + ldp x25, x26, [x0,#48] + ldp x27, x28, [x0,#64] + ldp x29, x30, [x0,#80] + ldr x2, [x0,#104] + mov sp, x2 + + cmp w1, 0 + csinc w0, w1, wzr, ne + br x30 \ No newline at end of file diff --git a/src/arch/aarch64/kernel/mod.rs b/src/arch/aarch64/kernel/mod.rs index 2f30e67d3f..d1de0cc029 100644 --- a/src/arch/aarch64/kernel/mod.rs +++ b/src/arch/aarch64/kernel/mod.rs @@ -31,6 +31,55 @@ use crate::arch::aarch64::mm::paging::{BasePageSize, PageSize}; use crate::config::*; use crate::env; +const SERIAL_PORT_BAUDRATE: u32 = 115_200; + +global_asm!(include_str!("setjmp.s")); +global_asm!(include_str!("longjmp.s")); + +pub(crate) struct Console { + serial_port: SerialPort, +} + +impl Console { + pub fn new() -> Self { + CoreLocal::install(); + + let base = env::boot_info() + .hardware_info + .serial_port_base + .map(|uartport| uartport.get()) + .unwrap_or_default() + .try_into() + .unwrap(); + + let serial_port = SerialPort::new(base); + + serial_port.init(SERIAL_PORT_BAUDRATE); + + Self { serial_port } + } + + pub fn write(&mut self, buf: &[u8]) { + self.serial_port.write_buf(buf); + } + + pub fn read(&mut self) -> Option { + None + } + + pub fn is_empty(&self) -> bool { + true + } + + pub fn register_waker(&mut self, _waker: &Waker) {} +} + +impl Default for Console { + fn default() -> Self { + Self::new() + } +} + #[repr(align(8))] pub(crate) struct AlignedAtomicU32(AtomicU32); diff --git a/src/arch/aarch64/kernel/setjmp.s b/src/arch/aarch64/kernel/setjmp.s new file mode 100644 index 0000000000..5c3f751ad7 --- /dev/null +++ b/src/arch/aarch64/kernel/setjmp.s @@ -0,0 +1,16 @@ +# The code is derived from the musl implementation +# of setjmp. +.section .text +.global setjmp +setjmp: + # IHI0055B_aapcs64.pdf 5.1.1, 5.1.2 callee saved registers + stp x19, x20, [x0,#0] + stp x21, x22, [x0,#16] + stp x23, x24, [x0,#32] + stp x25, x26, [x0,#48] + stp x27, x28, [x0,#64] + stp x29, x30, [x0,#80] + mov x2, sp + str x2, [x0,#104] + mov x0, #0 + ret diff --git a/src/arch/riscv64/kernel/longjmp.s b/src/arch/riscv64/kernel/longjmp.s new file mode 100644 index 0000000000..3d04fd8054 --- /dev/null +++ b/src/arch/riscv64/kernel/longjmp.s @@ -0,0 +1,23 @@ +# The code is derived from the musl implementation +# of longjmp. +.section .text +.global longjmp +longjmp: + ld s0, 0(a0) + ld s1, 8(a0) + ld s2, 16(a0) + ld s3, 24(a0) + ld s4, 32(a0) + ld s5, 40(a0) + ld s6, 48(a0) + ld s7, 56(a0) + ld s8, 64(a0) + ld s9, 72(a0) + ld s10, 80(a0) + ld s11, 88(a0) + ld sp, 96(a0) + ld ra, 104(a0) + + seqz a0, a1 + add a0, a0, a1 + ret \ No newline at end of file diff --git a/src/arch/riscv64/kernel/mod.rs b/src/arch/riscv64/kernel/mod.rs index c415467589..1dc2137ccf 100644 --- a/src/arch/riscv64/kernel/mod.rs +++ b/src/arch/riscv64/kernel/mod.rs @@ -19,6 +19,7 @@ mod start; pub mod switch; pub mod systemtime; use alloc::vec::Vec; +use core::arch::global_asm; use core::ptr; use core::sync::atomic::{AtomicPtr, AtomicU32, AtomicU64, Ordering}; @@ -35,6 +36,41 @@ use crate::env; use crate::init_cell::InitCell; use crate::mm::physicalmem::PHYSICAL_FREE_LIST; +pub(crate) struct Console {} + +impl Console { + pub fn new() -> Self { + CoreLocal::install(); + + Self {} + } + + pub fn write(&mut self, buf: &[u8]) { + for byte in buf { + sbi_rt::console_write_byte(*byte); + } + } + + pub fn read(&mut self) -> Option { + None + } + + pub fn is_empty(&self) -> bool { + true + } + + pub fn register_waker(&mut self, _waker: &Waker) {} +} + +impl Default for Console { + fn default() -> Self { + Self::new() + } +} + +global_asm!(include_str!("setjmp.s")); +global_asm!(include_str!("longjmp.s")); + // Used to store information about available harts. The index of the hart in the vector // represents its CpuId and does not need to match its hart_id pub(crate) static HARTS_AVAILABLE: InitCell> = InitCell::new(Vec::new()); diff --git a/src/arch/riscv64/kernel/setjmp.s b/src/arch/riscv64/kernel/setjmp.s new file mode 100644 index 0000000000..393bbeb622 --- /dev/null +++ b/src/arch/riscv64/kernel/setjmp.s @@ -0,0 +1,22 @@ +# The code is derived from the musl implementation +# of setjmp. +.section .text +.global setjmp +setjmp: + sd s0, 0(a0) + sd s1, 8(a0) + sd s2, 16(a0) + sd s3, 24(a0) + sd s4, 32(a0) + sd s5, 40(a0) + sd s6, 48(a0) + sd s7, 56(a0) + sd s8, 64(a0) + sd s9, 72(a0) + sd s10, 80(a0) + sd s11, 88(a0) + sd sp, 96(a0) + sd ra, 104(a0) + + li a0, 0 + ret diff --git a/src/lib.rs b/src/lib.rs index bf9f1b75fc..8153818b60 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -82,7 +82,7 @@ mod shell; mod synch; pub mod syscalls; pub mod time; -#[cfg(all(target_arch = "x86_64", feature = "wasm"))] +#[cfg(all(any(target_arch = "x86_64", target_arch = "aarch64"), feature = "wasm"))] mod wasm; mod built_info { @@ -149,7 +149,7 @@ 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"))] + #[cfg(all(any(target_arch = "x86_64", target_arch = "aarch64"), feature = "wasm"))] if crate::wasm::init().is_err() { error!("Unable to initialized wasm support") } From 801e760ee602d89736fbdda599e4a3ba6f9163e7 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sun, 23 Jun 2024 12:49:34 +0200 Subject: [PATCH 07/24] extend demo with a small benchmark --- src/wasm/fib.cwasm | Bin 13904 -> 14208 bytes src/wasm/fib.wasm | Bin 398 -> 444 bytes src/wasm/mod.rs | 70 +++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/src/wasm/fib.cwasm b/src/wasm/fib.cwasm index 8a137d359a31b025e285d57bc810287ad9ca549d..b593ea16bff4ce6b5817b7787ebe8b024fb7e0c7 100644 GIT binary patch delta 1779 zcmZWqYiJx*6rMY?yY8AcJH?c4Ot6!(V66VwM{3eqZDX7EZk%8u)I?)gHp#{Wl3h(w zgEVvtA+?uj($cH8{u7jn{t!xkRci@8sEU%*zCuKs7KKEDwklLAX8q3H*-+?(Z_c^j zdEPU3n3?_q*`w9^_L@^0=Yn1?mO8$W*Nt_@%#U;16Ps@Y-*{isG(NTz;i58Zi|(-B z7X4w<7Q^9?Ek?r@7t0CpeL`IQr)gSv3y`k-3 z$sR6#9V)$CfNQyvdzi2wCJ#fD0Z{S__C~%XW7A?TMQ38K%zk zXMKJq;rOUw6PcnI7@94#dQXM~GH{iFPn3mu^cw`r=$aQAam1IxFzmwN7Mq+v6KX0g z;fHGRiOMh+4{-4eCX@7^(bZ(<>hl-5V{iwdD`Pr+Va?pCV^$~{hEF9h{|DX_RsgzM z^`+)PeaC8_yL}9DCon6ktcUAqHw^Hbg{X7T)lyNdt9^XT-*EW8h6!K8q_^RShpNyO zy5jnm%MYyz?{{F%%NA>`oU}?i{>JXAYu^T4tzsAah==x+rxFwW-Sul!PIwgk5|b-_ zJK<;ED)bkjdcJ-zpYeVi$s871amV1(nsU$?xXlM~(0Zl+N@FLIw3<4v-K43p^ z2sjM92TTF~0VUK3un~v@o0*o=o`SL)cn;VDv;pnFC_p{GjX;v`K%R7U+MjmyPa(es zW`GMWNA@ewXMt_pYAn#x*O|?vy1M!_-P@VYboFY+{mEo^YB-flXSxkml1%od zQ?DdDQ$uNkYEV6zCDRSkJTz9ublosCW|I8?mPrr4dKl7)l;@1M;2dDfdie>aS>ucy zH|j1jZHk>^Y}(j{90oHC-4`%|UXM2EX=JmWhmDm)es@^(Hz|>yZF)4YJyx*vC|~pOP~c>|z({#2zW#qg Ce)5w5 delta 946 zcmYL|Ur19?9LLW&7i|}tTT^L}Ad2!A)S?7CTi$mH_||Fv}_o6Q=0yY02BK-}Bq z3oD3C{?p*hOxOC2)Pmc}o-_E@hP21zi$=Q1ZKhis5xyDa7b*=tzm>!tk@B2BrbYO& znLgz(_;(}iiSTAGJTu+oh;lzSzK-!E+^M8Rj^dT}Bse##i)t=S)VqNbhJ~ z^&k?ZU|mGC{iI2|1^nK0;@UCPq3amm*YkTq+pd>P)&sXl; zhAZr3Ba*v^AP|pSV26MX>cMev7PNp?a0zsQ9*_bP;01UK-h(Bu0%Y48*l*jujPKk2 zB=#rZIhf69^-+|fav_Y^8#+)J1CYe1u1DE0awC+k((oK5 z6EsZ6Sq09iRLx`L8H>`C(n!d4s|sZd7v*JnpXTZ+RDK|r6vc*8CYl58p%K{@<^zl< z*4xQAEEm{QAoW!%`mc}Ky4xCpQO| z;sf2uM5`_m)n#e`lJ!dBTXjDTh@l!k)y1QlPhz-sofeB&T}UmKW5e!>hjk$~4~X`fvw*h-04r}evH`MoDO$w+rrVX!xlWou3fl0 z02lv!`!{ges|~k?ObY?lURNJ%`=gEl{Tb|M+5al(@8kL0dM?#s!$n!)ekZx8DzWgh r8qIQ3t@$Vlrcn_3GJjmHpKAB)VkTl9Mm%=oFh2Lgi632lJmB~T>>)?_ delta 284 zcmYk0%SyvQ7={0TCXuFNLFi5q5U=4bpw>i8V|EJ^L#k0l2s_HUsq^dO;tVEGCB2j2OH+l`n xeI=FFDt4n5&AQLz<;1%UJ>M;|Bweps`^t~+qS-9C5%$!d2Cg5tlVJae*T05ON38$= diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs index cf918cc7b4..8cd26c56c7 100644 --- a/src/wasm/mod.rs +++ b/src/wasm/mod.rs @@ -2,6 +2,17 @@ mod capi; use wasmtime::*; +use crate::kernel::systemtime::now_micros; + +#[inline(never)] +pub fn native_fibonacci(n: u64) -> u64 { + match n { + 0 => 0, + 1 => 1, + _ => native_fibonacci(n - 1) + native_fibonacci(n - 2), + } +} + pub(crate) fn init() -> Result<(), Error> { let mut config: Config = Config::new(); config.memory_init_cow(false); @@ -12,21 +23,34 @@ pub(crate) fn init() -> Result<(), Error> { // In this example we are using the default configuration. let engine = Engine::new(&config)?; - debug!("Create Module"); + info!("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); + let mut imports = module.imports(); + while let Some(i) = imports.next() { + info!("import from module {} symbol {}", i.module(), i.name()); + } + + info!("Create Linker"); + let mut linker = Linker::new(&engine); + + // In case WASI, it is required to emulate + // https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md + + linker.func_wrap("env", "now", || { + crate::arch::kernel::systemtime::now_micros() + })?; + linker.func_wrap("env", "exit", || panic!("Panic in WASM module"))?; // 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)?; + info!("Create instance"); + let instance = linker.instantiate(&mut store, &module).unwrap(); - debug!("Try to find function fibonacci"); + info!("Try to find function fibonacci"); let fibonacci = instance.get_typed_func::(&mut store, "fibonacci")?; // And finally we can call the wasm function @@ -38,5 +62,39 @@ pub(crate) fn init() -> Result<(), Error> { "Error in the calculation of fibonacci(30) " ); + const N: u64 = 100; + let start = now_micros(); + for _ in 0..N { + let _result = fibonacci.call(&mut store, 30)?; + } + let end = now_micros(); + info!( + "Average time to call fibonacci(30): {} usec", + (end - start) / N + ); + + let start = now_micros(); + for _ in 0..N { + let _result = native_fibonacci(30); + } + let end = now_micros(); + info!( + "Average time to call native_fibonacci(30): {} usec", + (end - start) / N + ); + + let bench = instance.get_typed_func::<(u64, u64), i64>(&mut store, "bench")?; + let usec = bench.call(&mut store, (N, 30))?; + info!("Benchmark takes {} msec", usec / 1000); + + let foo = instance.get_typed_func::<(), ()>(&mut store, "foo")?; + foo.call(&mut store, ())?; + let start = now_micros(); + for _ in 0..N { + foo.call(&mut store, ())?; + } + let end = now_micros(); + info!("Average time to call foo: {} usec", (end - start) / N); + Ok(()) } From 4089cd81801f397d33b5eb1167d289bcfa61355e Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sun, 23 Jun 2024 12:51:04 +0200 Subject: [PATCH 08/24] remove some compiler warnings --- src/wasm/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs index 8cd26c56c7..ad38696e92 100644 --- a/src/wasm/mod.rs +++ b/src/wasm/mod.rs @@ -1,3 +1,4 @@ +#![allow(dependency_on_unit_never_type_fallback)] mod capi; use wasmtime::*; From 2231f2d8340387717a038b544502ce3240ae1504 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sun, 25 Aug 2024 14:40:36 +0200 Subject: [PATCH 09/24] switch to wasmtime 24.0 and enable RISCV support --- Cargo.lock | 545 +++++++++++++++++++++++++++++++++++++++------ Cargo.toml | 9 +- src/lib.rs | 2 +- src/wasm/fib.cwasm | Bin 14208 -> 14208 bytes 4 files changed, 484 insertions(+), 72 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 86a20d110e..33c15d09ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -432,7 +432,26 @@ version = "0.109.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fad7096c10a285583f2ed620c0c85d7baf745922e33415290f2900b73319f1e0" dependencies = [ - "cranelift-entity", + "cranelift-entity 0.109.1", +] + +[[package]] +name = "cranelift-bforest" +version = "0.111.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8d9d85c160b2dc97abeaf7612fcd0a438d81d7205bf38001df8af483c1fc10d" +dependencies = [ + "cranelift-entity 0.111.4", +] + +[[package]] +name = "cranelift-bitset" +version = "0.111.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44e3f0967ffc68f96829478c3fc295db33284b5db833e4875f69b3af426614af" +dependencies = [ + "serde", + "serde_derive", ] [[package]] @@ -442,13 +461,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd0d5b0dcd4a4e18c6352304d76f1c63258b5b2c248fc261b89c3a02952d51ff" dependencies = [ "bumpalo", - "cranelift-bforest", - "cranelift-codegen-meta", - "cranelift-codegen-shared", - "cranelift-control", - "cranelift-entity", - "cranelift-isle", - "gimli", + "cranelift-bforest 0.109.1", + "cranelift-codegen-meta 0.109.1", + "cranelift-codegen-shared 0.109.1", + "cranelift-control 0.109.1", + "cranelift-entity 0.109.1", + "cranelift-isle 0.109.1", + "gimli 0.28.1", + "hashbrown 0.14.5", + "log", + "regalloc2", + "rustc-hash", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-codegen" +version = "0.111.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d572c4f4f4bb9aa9238f5631ce97a4ff101bfb562a2fcd5486db83a0590a5fbe" +dependencies = [ + "bumpalo", + "cranelift-bforest 0.111.4", + "cranelift-bitset", + "cranelift-codegen-meta 0.111.4", + "cranelift-codegen-shared 0.111.4", + "cranelift-control 0.111.4", + "cranelift-entity 0.111.4", + "cranelift-isle 0.111.4", + "gimli 0.29.0", "hashbrown 0.14.5", "log", "regalloc2", @@ -463,7 +505,16 @@ version = "0.109.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d14aa8551924931235a4eec42d561a8415d5a758267a549575a3fe0e13ba84f" dependencies = [ - "cranelift-codegen-shared", + "cranelift-codegen-shared 0.109.1", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.111.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95b2f7ef9839f4008e190e04c9e7a20f3e7a01fcdbad4828ea36ff88f241d1ea" +dependencies = [ + "cranelift-codegen-shared 0.111.4", ] [[package]] @@ -472,6 +523,12 @@ version = "0.109.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "315a326e9f63b996f55e93b73a9a239b55f2de1211fcfbcc99d9423f44dc6ded" +[[package]] +name = "cranelift-codegen-shared" +version = "0.111.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567ed6b15c467671047c8cd493d497ec435ebad4c578487822ce90b03f6019d1" + [[package]] name = "cranelift-control" version = "0.109.1" @@ -481,6 +538,15 @@ dependencies = [ "arbitrary", ] +[[package]] +name = "cranelift-control" +version = "0.111.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a0b581398d1c17feff3c4ae1b03dc3582f3253b02a5d215455207bd01eee4d9" +dependencies = [ + "arbitrary", +] + [[package]] name = "cranelift-entity" version = "0.109.1" @@ -491,13 +557,36 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "cranelift-entity" +version = "0.111.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b72b691a782c7c4ad896b057adc792e2edb17daaf6b7608a85fa39176de56e25" +dependencies = [ + "cranelift-bitset", + "serde", + "serde_derive", +] + [[package]] name = "cranelift-frontend" version = "0.109.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55326cb3b61ca368210899a35892bca66aea4d75e8ceb5464e0539906c2ffb61" dependencies = [ - "cranelift-codegen", + "cranelift-codegen 0.109.1", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-frontend" +version = "0.111.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06b6a93016a8a10efcfe5cfdc2de532db4030a5e5d8b3a1405fba86d726268b6" +dependencies = [ + "cranelift-codegen 0.111.4", "log", "smallvec", "target-lexicon", @@ -509,13 +598,30 @@ version = "0.109.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4807df8ebad0106f207bcdc1f38199200ed175066b4122689e7f18e33ec8548c" +[[package]] +name = "cranelift-isle" +version = "0.111.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92e6486aa1973e6787e6f0002f1d1b3668178c3c47761ba9c7421966bae518f0" + [[package]] name = "cranelift-native" version = "0.109.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91c24c076002cb6a926a3f7220040278c7178878cd9142a418ddef9ee5b84963" dependencies = [ - "cranelift-codegen", + "cranelift-codegen 0.109.1", + "libc", + "target-lexicon", +] + +[[package]] +name = "cranelift-native" +version = "0.111.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6396f2eb31ebc859d2bd4e4e514d906a6d3c3cf16e70fc4f0286d3f4e1f6119e" +dependencies = [ + "cranelift-codegen 0.111.4", "libc", "target-lexicon", ] @@ -526,14 +632,30 @@ version = "0.109.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "66ba3e8a666222d2df5a79a1279282c04545c4ca9712b7d85f4f54937617a533" dependencies = [ - "cranelift-codegen", - "cranelift-entity", - "cranelift-frontend", + "cranelift-codegen 0.109.1", + "cranelift-entity 0.109.1", + "cranelift-frontend 0.109.1", "itertools", "log", "smallvec", - "wasmparser", - "wasmtime-types", + "wasmparser 0.209.1", + "wasmtime-types 22.0.1", +] + +[[package]] +name = "cranelift-wasm" +version = "0.111.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42c3f6c50d8613ceaba24c4cc3eb37d7b3318626097fb5d52598be78a5e6cbf" +dependencies = [ + "cranelift-codegen 0.111.4", + "cranelift-entity 0.111.4", + "cranelift-frontend 0.111.4", + "itertools", + "log", + "smallvec", + "wasmparser 0.215.0", + "wasmtime-types 24.0.4", ] [[package]] @@ -919,6 +1041,17 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +dependencies = [ + "fallible-iterator", + "indexmap", + "stable_deref_trait", +] + [[package]] name = "git2" version = "0.20.2" @@ -1080,7 +1213,8 @@ dependencies = [ "uhyve-interface", "virtio-spec", "volatile 0.6.1", - "wasmtime", + "wasmtime 22.0.1", + "wasmtime 24.0.4", "x86_64", "zerocopy", ] @@ -2096,6 +2230,9 @@ name = "semver" version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" +dependencies = [ + "serde", +] [[package]] name = "serde" @@ -2304,6 +2441,15 @@ version = "0.12.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + [[package]] name = "thiserror" version = "1.0.69" @@ -2650,6 +2796,15 @@ dependencies = [ "leb128", ] +[[package]] +name = "wasm-encoder" +version = "0.215.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb56df3e06b8e6b77e37d2969a50ba51281029a9aeb3855e76b7f49b6418847" +dependencies = [ + "leb128", +] + [[package]] name = "wasmparser" version = "0.209.1" @@ -2664,6 +2819,20 @@ dependencies = [ "serde", ] +[[package]] +name = "wasmparser" +version = "0.215.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fbde0881f24199b81cf49b6ff8f9c145ac8eb1b7fc439adb5c099734f7d90e" +dependencies = [ + "ahash", + "bitflags 2.9.3", + "hashbrown 0.14.5", + "indexmap", + "semver", + "serde", +] + [[package]] name = "wasmprinter" version = "0.209.1" @@ -2671,7 +2840,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ceca8ae6eaa8c7c87b33c25c53bdf299f8c2a764aee1179402ff7652ef3a6859" dependencies = [ "anyhow", - "wasmparser", + "wasmparser 0.209.1", +] + +[[package]] +name = "wasmprinter" +version = "0.215.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8e9a325d85053408209b3d2ce5eaddd0dd6864d1cff7a007147ba073157defc" +dependencies = [ + "anyhow", + "termcolor", + "wasmparser 0.215.0", ] [[package]] @@ -2705,16 +2885,60 @@ dependencies = [ "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", + "wasmparser 0.209.1", + "wasmtime-asm-macros 22.0.1", + "wasmtime-component-macro 22.0.1", + "wasmtime-component-util 22.0.1", + "wasmtime-cranelift 22.0.1", + "wasmtime-environ 22.0.1", + "wasmtime-jit-icache-coherence 22.0.1", + "wasmtime-slab 22.0.1", + "wasmtime-versioned-export-macros 22.0.1", + "wasmtime-winch 22.0.1", + "windows-sys 0.52.0", +] + +[[package]] +name = "wasmtime" +version = "24.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a637ea0b672d1c9f3f9889d6a87bb65f56ec3599d708dbf6528d6a3e138f1034" +dependencies = [ + "anyhow", + "bitflags 2.9.3", + "bumpalo", + "cc", + "cfg-if", + "encoding_rs", + "hashbrown 0.14.5", + "indexmap", + "libc", + "libm", + "log", + "mach2", + "memfd", + "object", + "once_cell", + "paste", + "postcard", + "psm", + "rustix 0.38.44", + "semver", + "serde", + "serde_derive", + "smallvec", + "sptr", + "target-lexicon", + "wasmparser 0.215.0", + "wasmtime-asm-macros 24.0.4", + "wasmtime-component-macro 24.0.4", + "wasmtime-component-util 24.0.4", + "wasmtime-cranelift 24.0.4", + "wasmtime-environ 24.0.4", + "wasmtime-jit-icache-coherence 24.0.4", + "wasmtime-slab 24.0.4", + "wasmtime-versioned-export-macros 24.0.4", + "wasmtime-winch 24.0.4", "windows-sys 0.52.0", ] @@ -2727,6 +2951,15 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "wasmtime-asm-macros" +version = "24.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc21ec6ae7bb6ad4f032ac26e9db5efc7b759f215403e30231326b726507857" +dependencies = [ + "cfg-if", +] + [[package]] name = "wasmtime-component-macro" version = "22.0.1" @@ -2737,9 +2970,24 @@ dependencies = [ "proc-macro2", "quote", "syn", - "wasmtime-component-util", - "wasmtime-wit-bindgen", - "wit-parser", + "wasmtime-component-util 22.0.1", + "wasmtime-wit-bindgen 22.0.1", + "wit-parser 0.209.1", +] + +[[package]] +name = "wasmtime-component-macro" +version = "24.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f379126eb37fb4313a7800308e638e6fc334e698d5abae5ad04b757295c28844" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn", + "wasmtime-component-util 24.0.4", + "wasmtime-wit-bindgen 24.0.4", + "wit-parser 0.215.0", ] [[package]] @@ -2748,6 +2996,12 @@ version = "22.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e935348dec39c79e895f80dd9ea7726b0c9059ef6210deae0c58e7e327422adc" +[[package]] +name = "wasmtime-component-util" +version = "24.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8ee69966520737396114a6196e0ddca4bfe121638eaeff834b422a4d151b1fc" + [[package]] name = "wasmtime-cranelift" version = "22.0.1" @@ -2756,20 +3010,44 @@ checksum = "8e8ec68af53f896a8c98ce7c540762686239b6b81f83d95ef2a074d8b0d67443" dependencies = [ "anyhow", "cfg-if", - "cranelift-codegen", - "cranelift-control", - "cranelift-entity", - "cranelift-frontend", - "cranelift-native", - "cranelift-wasm", - "gimli", + "cranelift-codegen 0.109.1", + "cranelift-control 0.109.1", + "cranelift-entity 0.109.1", + "cranelift-frontend 0.109.1", + "cranelift-native 0.109.1", + "cranelift-wasm 0.109.1", + "gimli 0.28.1", + "log", + "object", + "target-lexicon", + "thiserror 1.0.69", + "wasmparser 0.209.1", + "wasmtime-environ 22.0.1", + "wasmtime-versioned-export-macros 22.0.1", +] + +[[package]] +name = "wasmtime-cranelift" +version = "24.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fae748c777cdf248beb9caa2cf6546180ee34cba02af8535f485289209ec8242" +dependencies = [ + "anyhow", + "cfg-if", + "cranelift-codegen 0.111.4", + "cranelift-control 0.111.4", + "cranelift-entity 0.111.4", + "cranelift-frontend 0.111.4", + "cranelift-native 0.111.4", + "cranelift-wasm 0.111.4", + "gimli 0.29.0", "log", "object", "target-lexicon", "thiserror 1.0.69", - "wasmparser", - "wasmtime-environ", - "wasmtime-versioned-export-macros", + "wasmparser 0.215.0", + "wasmtime-environ 24.0.4", + "wasmtime-versioned-export-macros 24.0.4", ] [[package]] @@ -2779,20 +3057,45 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e41bba8b753ccb9426986b106fa03820bc04e097f02e09f28ce85ca0191d7db0" dependencies = [ "anyhow", - "cranelift-entity", - "gimli", + "cranelift-entity 0.109.1", + "gimli 0.28.1", + "indexmap", + "log", + "object", + "postcard", + "serde", + "serde_derive", + "target-lexicon", + "wasm-encoder 0.209.1", + "wasmparser 0.209.1", + "wasmprinter 0.209.1", + "wasmtime-component-util 22.0.1", + "wasmtime-types 22.0.1", +] + +[[package]] +name = "wasmtime-environ" +version = "24.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e455e71a3196d664da3c735746418490a62e5c9e48ee04e185279289deb23b6f" +dependencies = [ + "anyhow", + "cranelift-bitset", + "cranelift-entity 0.111.4", + "gimli 0.29.0", "indexmap", "log", "object", "postcard", + "semver", "serde", "serde_derive", "target-lexicon", - "wasm-encoder", - "wasmparser", - "wasmprinter", - "wasmtime-component-util", - "wasmtime-types", + "wasm-encoder 0.215.0", + "wasmparser 0.215.0", + "wasmprinter 0.215.0", + "wasmtime-component-util 24.0.4", + "wasmtime-types 24.0.4", ] [[package]] @@ -2807,23 +3110,55 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "wasmtime-jit-icache-coherence" +version = "24.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23efd70fc31afcde7ef3f5b9d375517379d2c777fe9f23f7b90c67ba83bb5d96" +dependencies = [ + "anyhow", + "cfg-if", + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "wasmtime-slab" version = "22.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7df4e5141e11e6f12330450d97f289ccc8f7de2d3c2db7c46252ccd95d78f093" +[[package]] +name = "wasmtime-slab" +version = "24.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "740f8765b45df80e150d31f441c1640048817e373e871e147865be8689105412" + [[package]] name = "wasmtime-types" version = "22.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2017ea47e7a91440f94cc29f5f41d303e80f979a5384bf560d4b0afdabe32d0" dependencies = [ - "cranelift-entity", + "cranelift-entity 0.109.1", + "serde", + "serde_derive", + "smallvec", + "wasmparser 0.209.1", +] + +[[package]] +name = "wasmtime-types" +version = "24.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "628d33a0f60048dfd8d82cc784892401ca1397fd6a5d4a26331e9bd28d938710" +dependencies = [ + "anyhow", + "cranelift-entity 0.111.4", "serde", "serde_derive", "smallvec", - "wasmparser", + "wasmparser 0.215.0", ] [[package]] @@ -2837,6 +3172,17 @@ dependencies = [ "syn", ] +[[package]] +name = "wasmtime-versioned-export-macros" +version = "24.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04fe757e59789ef15c5f774e0e500f710ec7638af450b4d9d664efa2c9116b4c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "wasmtime-winch" version = "22.0.1" @@ -2844,14 +3190,31 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de67dfca76c725b17179185c6ce2d78766656e150b86773b4ddbd2257240ef57" dependencies = [ "anyhow", - "cranelift-codegen", - "gimli", + "cranelift-codegen 0.109.1", + "gimli 0.28.1", + "object", + "target-lexicon", + "wasmparser 0.209.1", + "wasmtime-cranelift 22.0.1", + "wasmtime-environ 22.0.1", + "winch-codegen 0.20.1", +] + +[[package]] +name = "wasmtime-winch" +version = "24.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b311edc2e784f41d38ce89b294f9b9dc18aecf6aed82c5ab6dc7c6d9f2816d6" +dependencies = [ + "anyhow", + "cranelift-codegen 0.111.4", + "gimli 0.29.0", "object", "target-lexicon", - "wasmparser", - "wasmtime-cranelift", - "wasmtime-environ", - "winch-codegen", + "wasmparser 0.215.0", + "wasmtime-cranelift 24.0.4", + "wasmtime-environ 24.0.4", + "winch-codegen 0.22.4", ] [[package]] @@ -2863,7 +3226,19 @@ dependencies = [ "anyhow", "heck 0.4.1", "indexmap", - "wit-parser", + "wit-parser 0.209.1", +] + +[[package]] +name = "wasmtime-wit-bindgen" +version = "24.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64cebe3cd91765ca3a3676fc5e3af20323c9f336917f1b8dfc36345f0ee2fa03" +dependencies = [ + "anyhow", + "heck 0.4.1", + "indexmap", + "wit-parser 0.215.0", ] [[package]] @@ -2891,6 +3266,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0978bf7171b3d90bac376700cb56d606feb40f251a475a5d6634613564460b22" +dependencies = [ + "windows-sys 0.60.2", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -2904,14 +3288,31 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b51d823bdea98f7ce9db47909f1c543b5ae253d3df1aebf7ba3c0f25444daef2" dependencies = [ "anyhow", - "cranelift-codegen", - "gimli", + "cranelift-codegen 0.109.1", + "gimli 0.28.1", "regalloc2", "smallvec", "target-lexicon", - "wasmparser", - "wasmtime-cranelift", - "wasmtime-environ", + "wasmparser 0.209.1", + "wasmtime-cranelift 22.0.1", + "wasmtime-environ 22.0.1", +] + +[[package]] +name = "winch-codegen" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f4eff291a302df370d172be239a33c16917749859c25d1005bba7a790827190" +dependencies = [ + "anyhow", + "cranelift-codegen 0.111.4", + "gimli 0.29.0", + "regalloc2", + "smallvec", + "target-lexicon", + "wasmparser 0.215.0", + "wasmtime-cranelift 24.0.4", + "wasmtime-environ 24.0.4", ] [[package]] @@ -3202,7 +3603,25 @@ dependencies = [ "serde_derive", "serde_json", "unicode-xid", - "wasmparser", + "wasmparser 0.209.1", +] + +[[package]] +name = "wit-parser" +version = "0.215.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "935a97eaffd57c3b413aa510f8f0b550a4a9fe7d59e79cd8b89a83dcb860321f" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser 0.215.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 0d5e355bce..bfe08aa244 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -145,7 +145,7 @@ time = { version = "0.3", default-features = false } volatile = "0.6" zerocopy = { version = "0.8", default-features = false } uhyve-interface = "0.1.3" -wasmtime = { version = "22.0", default-features = false, features = ["runtime", "gc", "component-model"], optional = true } +wasmtime = { version = "24.0", default-features = false, features = ["runtime", "gc", "component-model"], optional = true } [dependencies.smoltcp] version = "0.12" @@ -171,26 +171,19 @@ free-list = { version = "0.3", features = ["x86_64"] } raw-cpuid = "11" uart_16550 = "0.4" x86_64 = "0.15" -<<<<<<< HEAD memory_addresses = { version = "0.2.3", default-features = false, features = [ "x86_64", "conv-x86_64", ] } -======= -wasmtime = { version = "22.0", default-features = false, features = ["runtime", "gc", "component-model"], optional = true } ->>>>>>> cd1d8b6fa (prepare wasm support for aarch64 and riscv64) [target.'cfg(target_arch = "aarch64")'.dependencies] aarch64 = { version = "0.0.14", default-features = false } arm-gic = { version = "0.6" } semihosting = { version = "0.1", optional = true } -<<<<<<< HEAD memory_addresses = { version = "0.2.3", default-features = false, features = [ "aarch64", ] } -======= wasmtime = { version = "22.0", default-features = false, features = ["runtime", "gc", "component-model"], optional = true } ->>>>>>> cd1d8b6fa (prepare wasm support for aarch64 and riscv64) [target.'cfg(target_arch = "riscv64")'.dependencies] riscv = "0.14" diff --git a/src/lib.rs b/src/lib.rs index 8153818b60..0f6cdfd7d0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -82,7 +82,7 @@ mod shell; mod synch; pub mod syscalls; pub mod time; -#[cfg(all(any(target_arch = "x86_64", target_arch = "aarch64"), feature = "wasm"))] +#[cfg(feature = "wasm")] mod wasm; mod built_info { diff --git a/src/wasm/fib.cwasm b/src/wasm/fib.cwasm index b593ea16bff4ce6b5817b7787ebe8b024fb7e0c7..27e1eeff0e7bbb040a812386996a630229fb96d9 100644 GIT binary patch delta 62 zcmZq3Z^)nE%xJRFrHPr15eOI8>H)}UT9*@ SczyFtljDqxijx&F%vLRLc~X From 8048f023f92b722bac94764699a673b046687445 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Tue, 22 Jul 2025 11:11:47 +0200 Subject: [PATCH 10/24] add draft of wasm support within the kernel --- Cargo.lock | 952 ++++----------------------------------------- Cargo.toml | 6 +- src/lib.rs | 7 +- src/wasm/capi.rs | 44 +-- src/wasm/fib.cwasm | Bin 14208 -> 0 bytes src/wasm/mod.rs | 386 ++++++++++++++---- 6 files changed, 418 insertions(+), 977 deletions(-) delete mode 100644 src/wasm/fib.cwasm diff --git a/Cargo.lock b/Cargo.lock index 33c15d09ee..fa97839d6c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -143,12 +143,6 @@ version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100" -[[package]] -name = "arbitrary" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d036a3c4ab069c7b410a2ce876bd74808d2d0888a82667669f8e783a898bf1" - [[package]] name = "arm-gic" version = "0.6.1" @@ -157,7 +151,7 @@ checksum = "6bfdb03424c95b58315a4cb0ff4ca919568a5a28ae5ba960a1ad92c9ccaf49b9" dependencies = [ "bitflags 2.9.3", "safe-mmio", - "thiserror 2.0.16", + "thiserror", "zerocopy", ] @@ -363,7 +357,7 @@ version = "4.5.45" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14cb31bb0a7d536caef2639baa7fad459e15c3144efefa6dbd1c84562c4739f6" dependencies = [ - "heck 0.5.0", + "heck", "proc-macro2", "quote", "syn", @@ -381,7 +375,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fa961b519f0b462e3a3b4a34b64d119eeaca1d59af726fe450bbba07a9fc0a1" dependencies = [ - "thiserror 2.0.16", + "thiserror", ] [[package]] @@ -426,132 +420,11 @@ dependencies = [ "libc", ] -[[package]] -name = "cranelift-bforest" -version = "0.109.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fad7096c10a285583f2ed620c0c85d7baf745922e33415290f2900b73319f1e0" -dependencies = [ - "cranelift-entity 0.109.1", -] - -[[package]] -name = "cranelift-bforest" -version = "0.111.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8d9d85c160b2dc97abeaf7612fcd0a438d81d7205bf38001df8af483c1fc10d" -dependencies = [ - "cranelift-entity 0.111.4", -] - [[package]] name = "cranelift-bitset" -version = "0.111.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44e3f0967ffc68f96829478c3fc295db33284b5db833e4875f69b3af426614af" -dependencies = [ - "serde", - "serde_derive", -] - -[[package]] -name = "cranelift-codegen" -version = "0.109.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd0d5b0dcd4a4e18c6352304d76f1c63258b5b2c248fc261b89c3a02952d51ff" -dependencies = [ - "bumpalo", - "cranelift-bforest 0.109.1", - "cranelift-codegen-meta 0.109.1", - "cranelift-codegen-shared 0.109.1", - "cranelift-control 0.109.1", - "cranelift-entity 0.109.1", - "cranelift-isle 0.109.1", - "gimli 0.28.1", - "hashbrown 0.14.5", - "log", - "regalloc2", - "rustc-hash", - "smallvec", - "target-lexicon", -] - -[[package]] -name = "cranelift-codegen" -version = "0.111.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d572c4f4f4bb9aa9238f5631ce97a4ff101bfb562a2fcd5486db83a0590a5fbe" -dependencies = [ - "bumpalo", - "cranelift-bforest 0.111.4", - "cranelift-bitset", - "cranelift-codegen-meta 0.111.4", - "cranelift-codegen-shared 0.111.4", - "cranelift-control 0.111.4", - "cranelift-entity 0.111.4", - "cranelift-isle 0.111.4", - "gimli 0.29.0", - "hashbrown 0.14.5", - "log", - "regalloc2", - "rustc-hash", - "smallvec", - "target-lexicon", -] - -[[package]] -name = "cranelift-codegen-meta" -version = "0.109.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d14aa8551924931235a4eec42d561a8415d5a758267a549575a3fe0e13ba84f" -dependencies = [ - "cranelift-codegen-shared 0.109.1", -] - -[[package]] -name = "cranelift-codegen-meta" -version = "0.111.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95b2f7ef9839f4008e190e04c9e7a20f3e7a01fcdbad4828ea36ff88f241d1ea" -dependencies = [ - "cranelift-codegen-shared 0.111.4", -] - -[[package]] -name = "cranelift-codegen-shared" -version = "0.109.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "315a326e9f63b996f55e93b73a9a239b55f2de1211fcfbcc99d9423f44dc6ded" - -[[package]] -name = "cranelift-codegen-shared" -version = "0.111.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567ed6b15c467671047c8cd493d497ec435ebad4c578487822ce90b03f6019d1" - -[[package]] -name = "cranelift-control" -version = "0.109.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "806ca69ca5aa8422035543444e1dc936f8f3e7f6854d562ef31db9fe30355c5c" -dependencies = [ - "arbitrary", -] - -[[package]] -name = "cranelift-control" -version = "0.111.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a0b581398d1c17feff3c4ae1b03dc3582f3253b02a5d215455207bd01eee4d9" -dependencies = [ - "arbitrary", -] - -[[package]] -name = "cranelift-entity" -version = "0.109.1" +version = "0.121.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9778487136bf37f9007920d9cb332a020e5d7259c1fbf35e625368eb88c7bfe" +checksum = "ebb6f5d0df5bd0d02c63ec48e8f2e38a176b123f59e084f22caf89a0d0593e7e" dependencies = [ "serde", "serde_derive", @@ -559,105 +432,15 @@ dependencies = [ [[package]] name = "cranelift-entity" -version = "0.111.4" +version = "0.121.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b72b691a782c7c4ad896b057adc792e2edb17daaf6b7608a85fa39176de56e25" +checksum = "ee832f8329fa87c5df6c1d64a8506a58031e6f8a190d9b21b1900272a4dbb47d" dependencies = [ "cranelift-bitset", "serde", "serde_derive", ] -[[package]] -name = "cranelift-frontend" -version = "0.109.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55326cb3b61ca368210899a35892bca66aea4d75e8ceb5464e0539906c2ffb61" -dependencies = [ - "cranelift-codegen 0.109.1", - "log", - "smallvec", - "target-lexicon", -] - -[[package]] -name = "cranelift-frontend" -version = "0.111.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06b6a93016a8a10efcfe5cfdc2de532db4030a5e5d8b3a1405fba86d726268b6" -dependencies = [ - "cranelift-codegen 0.111.4", - "log", - "smallvec", - "target-lexicon", -] - -[[package]] -name = "cranelift-isle" -version = "0.109.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4807df8ebad0106f207bcdc1f38199200ed175066b4122689e7f18e33ec8548c" - -[[package]] -name = "cranelift-isle" -version = "0.111.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92e6486aa1973e6787e6f0002f1d1b3668178c3c47761ba9c7421966bae518f0" - -[[package]] -name = "cranelift-native" -version = "0.109.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91c24c076002cb6a926a3f7220040278c7178878cd9142a418ddef9ee5b84963" -dependencies = [ - "cranelift-codegen 0.109.1", - "libc", - "target-lexicon", -] - -[[package]] -name = "cranelift-native" -version = "0.111.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6396f2eb31ebc859d2bd4e4e514d906a6d3c3cf16e70fc4f0286d3f4e1f6119e" -dependencies = [ - "cranelift-codegen 0.111.4", - "libc", - "target-lexicon", -] - -[[package]] -name = "cranelift-wasm" -version = "0.109.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66ba3e8a666222d2df5a79a1279282c04545c4ca9712b7d85f4f54937617a533" -dependencies = [ - "cranelift-codegen 0.109.1", - "cranelift-entity 0.109.1", - "cranelift-frontend 0.109.1", - "itertools", - "log", - "smallvec", - "wasmparser 0.209.1", - "wasmtime-types 22.0.1", -] - -[[package]] -name = "cranelift-wasm" -version = "0.111.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b42c3f6c50d8613ceaba24c4cc3eb37d7b3318626097fb5d52598be78a5e6cbf" -dependencies = [ - "cranelift-codegen 0.111.4", - "cranelift-entity 0.111.4", - "cranelift-frontend 0.111.4", - "itertools", - "log", - "smallvec", - "wasmparser 0.215.0", - "wasmtime-types 24.0.4", -] - [[package]] name = "crc" version = "3.3.0" @@ -742,7 +525,7 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10d60334b3b2e7c9d91ef8150abfb6fa4c1c39ebbcf4a81c2e346aad939fee3e" dependencies = [ - "thiserror 2.0.16", + "thiserror", ] [[package]] @@ -775,12 +558,6 @@ dependencies = [ "syn", ] -[[package]] -name = "either" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" - [[package]] name = "embedded-hal" version = "1.0.0" @@ -799,15 +576,6 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" -[[package]] -name = "encoding_rs" -version = "0.8.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" -dependencies = [ - "cfg-if", -] - [[package]] name = "endian-num" version = "0.2.0" @@ -873,12 +641,6 @@ 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 = "fastrand" version = "2.3.0" @@ -1032,25 +794,9 @@ dependencies = [ [[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 = "gimli" -version = "0.29.0" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" -dependencies = [ - "fallible-iterator", - "indexmap", - "stable_deref_trait", -] +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "git2" @@ -1085,25 +831,6 @@ 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", - "serde", -] - [[package]] name = "hashbrown" version = "0.15.5" @@ -1111,6 +838,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" dependencies = [ "foldhash", + "serde", ] [[package]] @@ -1133,12 +861,6 @@ 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" @@ -1181,7 +903,7 @@ dependencies = [ "float-cmp", "free-list", "fuse-abi", - "hashbrown 0.15.5", + "hashbrown", "heapless 0.9.1", "hermit-entry", "hermit-macro", @@ -1205,7 +927,7 @@ dependencies = [ "smoltcp", "take-static", "talc", - "thiserror 2.0.16", + "thiserror", "time", "tock-registers 0.10.0", "trapframe", @@ -1213,8 +935,8 @@ dependencies = [ "uhyve-interface", "virtio-spec", "volatile 0.6.1", - "wasmtime 22.0.1", - "wasmtime 24.0.4", + "wasi 0.11.1+wasi-snapshot-preview1", + "wasmtime", "x86_64", "zerocopy", ] @@ -1379,12 +1101,6 @@ dependencies = [ "zerovec", ] -[[package]] -name = "id-arena" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" - [[package]] name = "idna" version = "1.1.0" @@ -1413,7 +1129,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2481980430f9f78649238835720ddccc57e52df14ffce1c6f37391d61b563e9" dependencies = [ "equivalent", - "hashbrown 0.15.5", + "hashbrown", "serde", ] @@ -1443,15 +1159,6 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" -[[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.15" @@ -1478,12 +1185,6 @@ 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.175" @@ -1611,15 +1312,6 @@ dependencies = [ "rustix 0.38.44", ] -[[package]] -name = "memoffset" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" -dependencies = [ - "autocfg", -] - [[package]] name = "memory_addresses" version = "0.2.3" @@ -1738,9 +1430,6 @@ version = "0.36.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" dependencies = [ - "crc32fast", - "hashbrown 0.15.5", - "indexmap", "memchr", ] @@ -1951,6 +1640,29 @@ dependencies = [ "cc", ] +[[package]] +name = "pulley-interpreter" +version = "34.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be14280b69a9cbb6ada02a7aa5f7b3f1b72d1043b5bc9336990b700525dea6e3" +dependencies = [ + "cranelift-bitset", + "log", + "pulley-macros", + "wasmtime-math", +] + +[[package]] +name = "pulley-macros" +version = "34.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "076f1be746801280af4c96c4407b5fd1d09cfa53ab27ba0ac7dd8f207e7bbf83" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "quote" version = "1.0.40" @@ -2024,19 +1736,6 @@ dependencies = [ "bitflags 2.9.3", ] -[[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.14" @@ -2081,12 +1780,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8188909339ccc0c68cfb5a04648313f09621e8b87dc03095454f1a11f6c5d436" -[[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.44" @@ -2163,12 +1856,6 @@ version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" -[[package]] -name = "ryu" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" - [[package]] name = "safe-mmio" version = "0.2.5" @@ -2225,15 +1912,6 @@ version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3e1c7d2b77d80283c750a39c52f1ab4d17234e8f30bca43550f5b2375f41d5f" -[[package]] -name = "semver" -version = "1.0.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" -dependencies = [ - "serde", -] - [[package]] name = "serde" version = "1.0.219" @@ -2254,18 +1932,6 @@ dependencies = [ "syn", ] -[[package]] -name = "serde_json" -version = "1.0.143" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d401abef1d108fbd9cbaebc3e46611f4b1021f714a0597a71f41ee463f5f4a5a" -dependencies = [ - "itoa", - "memchr", - "ryu", - "serde", -] - [[package]] name = "sha2" version = "0.10.9" @@ -2307,12 +1973,6 @@ version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" -[[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.15.1" @@ -2346,12 +2006,6 @@ 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" @@ -2437,27 +2091,9 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.12.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" - -[[package]] -name = "termcolor" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "thiserror" -version = "1.0.69" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" -dependencies = [ - "thiserror-impl 1.0.69", -] +checksum = "e502f78cdbb8ba4718f566c418c52bc729126ffd16baee5baa718cf25dd5a69a" [[package]] name = "thiserror" @@ -2465,18 +2101,7 @@ version = "2.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0" dependencies = [ - "thiserror-impl 2.0.16", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" -dependencies = [ - "proc-macro2", - "quote", - "syn", + "thiserror-impl", ] [[package]] @@ -2580,12 +2205,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" -[[package]] -name = "unicode-xid" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" - [[package]] name = "untrusted" version = "0.9.0" @@ -2787,460 +2406,122 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "wasm-encoder" -version = "0.209.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b4a05336882dae732ce6bd48b7e11fe597293cb72c13da4f35d7d5f8d53b2a7" -dependencies = [ - "leb128", -] - -[[package]] -name = "wasm-encoder" -version = "0.215.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb56df3e06b8e6b77e37d2969a50ba51281029a9aeb3855e76b7f49b6418847" -dependencies = [ - "leb128", -] - -[[package]] -name = "wasmparser" -version = "0.209.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07035cc9a9b41e62d3bb3a3815a66ab87c993c06fe1cf6b2a3f2a18499d937db" -dependencies = [ - "ahash", - "bitflags 2.9.3", - "hashbrown 0.14.5", - "indexmap", - "semver", - "serde", -] - [[package]] name = "wasmparser" -version = "0.215.0" +version = "0.233.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fbde0881f24199b81cf49b6ff8f9c145ac8eb1b7fc439adb5c099734f7d90e" +checksum = "b51cb03afce7964bbfce46602d6cb358726f36430b6ba084ac6020d8ce5bc102" dependencies = [ - "ahash", "bitflags 2.9.3", - "hashbrown 0.14.5", + "hashbrown", "indexmap", - "semver", - "serde", -] - -[[package]] -name = "wasmprinter" -version = "0.209.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ceca8ae6eaa8c7c87b33c25c53bdf299f8c2a764aee1179402ff7652ef3a6859" -dependencies = [ - "anyhow", - "wasmparser 0.209.1", -] - -[[package]] -name = "wasmprinter" -version = "0.215.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8e9a325d85053408209b3d2ce5eaddd0dd6864d1cff7a007147ba073157defc" -dependencies = [ - "anyhow", - "termcolor", - "wasmparser 0.215.0", -] - -[[package]] -name = "wasmtime" -version = "22.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9de397b45aa057cbadd8fbef22227779ef05121d9f47ac55c9a1ff77e0c29695" -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 0.38.44", - "semver", "serde", - "serde_derive", - "smallvec", - "sptr", - "target-lexicon", - "wasmparser 0.209.1", - "wasmtime-asm-macros 22.0.1", - "wasmtime-component-macro 22.0.1", - "wasmtime-component-util 22.0.1", - "wasmtime-cranelift 22.0.1", - "wasmtime-environ 22.0.1", - "wasmtime-jit-icache-coherence 22.0.1", - "wasmtime-slab 22.0.1", - "wasmtime-versioned-export-macros 22.0.1", - "wasmtime-winch 22.0.1", - "windows-sys 0.52.0", ] [[package]] name = "wasmtime" -version = "24.0.4" +version = "34.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a637ea0b672d1c9f3f9889d6a87bb65f56ec3599d708dbf6528d6a3e138f1034" +checksum = "ec10e50038f22ab407fdd8708120b8feed3450a02618efcf26ca47e82122927d" dependencies = [ "anyhow", "bitflags 2.9.3", "bumpalo", "cc", "cfg-if", - "encoding_rs", - "hashbrown 0.14.5", + "hashbrown", "indexmap", "libc", - "libm", "log", "mach2", "memfd", "object", - "once_cell", - "paste", "postcard", "psm", - "rustix 0.38.44", - "semver", + "pulley-interpreter", + "rustix 1.0.8", "serde", "serde_derive", "smallvec", - "sptr", "target-lexicon", - "wasmparser 0.215.0", - "wasmtime-asm-macros 24.0.4", - "wasmtime-component-macro 24.0.4", - "wasmtime-component-util 24.0.4", - "wasmtime-cranelift 24.0.4", - "wasmtime-environ 24.0.4", - "wasmtime-jit-icache-coherence 24.0.4", - "wasmtime-slab 24.0.4", - "wasmtime-versioned-export-macros 24.0.4", - "wasmtime-winch 24.0.4", - "windows-sys 0.52.0", -] - -[[package]] -name = "wasmtime-asm-macros" -version = "22.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "379c81227d624024d8b950a9eb7fc48671f77fff368e021d9b6f16c83a650369" -dependencies = [ - "cfg-if", + "wasmparser", + "wasmtime-asm-macros", + "wasmtime-environ", + "wasmtime-jit-icache-coherence", + "wasmtime-math", + "wasmtime-slab", + "wasmtime-versioned-export-macros", + "windows-sys 0.59.0", ] [[package]] name = "wasmtime-asm-macros" -version = "24.0.4" +version = "34.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc21ec6ae7bb6ad4f032ac26e9db5efc7b759f215403e30231326b726507857" +checksum = "4d379cda46d6fd18619e282a75fbb09b70b3d0f166b605f45b4059dfaf9dc6ce" dependencies = [ "cfg-if", ] -[[package]] -name = "wasmtime-component-macro" -version = "22.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f579efa3807fc05078939d001e9295f3ab65613345fa7fe0c19875129aabae4" -dependencies = [ - "anyhow", - "proc-macro2", - "quote", - "syn", - "wasmtime-component-util 22.0.1", - "wasmtime-wit-bindgen 22.0.1", - "wit-parser 0.209.1", -] - -[[package]] -name = "wasmtime-component-macro" -version = "24.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f379126eb37fb4313a7800308e638e6fc334e698d5abae5ad04b757295c28844" -dependencies = [ - "anyhow", - "proc-macro2", - "quote", - "syn", - "wasmtime-component-util 24.0.4", - "wasmtime-wit-bindgen 24.0.4", - "wit-parser 0.215.0", -] - -[[package]] -name = "wasmtime-component-util" -version = "22.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e935348dec39c79e895f80dd9ea7726b0c9059ef6210deae0c58e7e327422adc" - -[[package]] -name = "wasmtime-component-util" -version = "24.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8ee69966520737396114a6196e0ddca4bfe121638eaeff834b422a4d151b1fc" - -[[package]] -name = "wasmtime-cranelift" -version = "22.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e8ec68af53f896a8c98ce7c540762686239b6b81f83d95ef2a074d8b0d67443" -dependencies = [ - "anyhow", - "cfg-if", - "cranelift-codegen 0.109.1", - "cranelift-control 0.109.1", - "cranelift-entity 0.109.1", - "cranelift-frontend 0.109.1", - "cranelift-native 0.109.1", - "cranelift-wasm 0.109.1", - "gimli 0.28.1", - "log", - "object", - "target-lexicon", - "thiserror 1.0.69", - "wasmparser 0.209.1", - "wasmtime-environ 22.0.1", - "wasmtime-versioned-export-macros 22.0.1", -] - -[[package]] -name = "wasmtime-cranelift" -version = "24.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fae748c777cdf248beb9caa2cf6546180ee34cba02af8535f485289209ec8242" -dependencies = [ - "anyhow", - "cfg-if", - "cranelift-codegen 0.111.4", - "cranelift-control 0.111.4", - "cranelift-entity 0.111.4", - "cranelift-frontend 0.111.4", - "cranelift-native 0.111.4", - "cranelift-wasm 0.111.4", - "gimli 0.29.0", - "log", - "object", - "target-lexicon", - "thiserror 1.0.69", - "wasmparser 0.215.0", - "wasmtime-environ 24.0.4", - "wasmtime-versioned-export-macros 24.0.4", -] - -[[package]] -name = "wasmtime-environ" -version = "22.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e41bba8b753ccb9426986b106fa03820bc04e097f02e09f28ce85ca0191d7db0" -dependencies = [ - "anyhow", - "cranelift-entity 0.109.1", - "gimli 0.28.1", - "indexmap", - "log", - "object", - "postcard", - "serde", - "serde_derive", - "target-lexicon", - "wasm-encoder 0.209.1", - "wasmparser 0.209.1", - "wasmprinter 0.209.1", - "wasmtime-component-util 22.0.1", - "wasmtime-types 22.0.1", -] - [[package]] name = "wasmtime-environ" -version = "24.0.4" +version = "34.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e455e71a3196d664da3c735746418490a62e5c9e48ee04e185279289deb23b6f" +checksum = "317081a0cbbb1f749d348b262575608fc082d47ab11b6247bbe9163eeb955777" dependencies = [ "anyhow", "cranelift-bitset", - "cranelift-entity 0.111.4", - "gimli 0.29.0", + "cranelift-entity", + "gimli", "indexmap", "log", "object", "postcard", - "semver", "serde", "serde_derive", + "smallvec", "target-lexicon", - "wasm-encoder 0.215.0", - "wasmparser 0.215.0", - "wasmprinter 0.215.0", - "wasmtime-component-util 24.0.4", - "wasmtime-types 24.0.4", + "wasmparser", ] [[package]] name = "wasmtime-jit-icache-coherence" -version = "22.0.1" +version = "34.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0e7ccd55d5dfff4fb7abc889137c5af6531ad57bbd5890651f7e22533a61c7d" +checksum = "8ea6b740d1a35f2cebfe88e013ac8a4a84ff8dabc3a392df920abf554e871cf2" dependencies = [ "anyhow", "cfg-if", "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] -name = "wasmtime-jit-icache-coherence" -version = "24.0.4" +name = "wasmtime-math" +version = "34.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23efd70fc31afcde7ef3f5b9d375517379d2c777fe9f23f7b90c67ba83bb5d96" +checksum = "62fa317691aedc64aae3a86b3d786e4b2b0007bc0b56e0b6098b8b5a85ab2134" dependencies = [ - "anyhow", - "cfg-if", - "libc", - "windows-sys 0.52.0", + "libm", ] [[package]] name = "wasmtime-slab" -version = "22.0.1" +version = "34.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7df4e5141e11e6f12330450d97f289ccc8f7de2d3c2db7c46252ccd95d78f093" - -[[package]] -name = "wasmtime-slab" -version = "24.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "740f8765b45df80e150d31f441c1640048817e373e871e147865be8689105412" - -[[package]] -name = "wasmtime-types" -version = "22.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2017ea47e7a91440f94cc29f5f41d303e80f979a5384bf560d4b0afdabe32d0" -dependencies = [ - "cranelift-entity 0.109.1", - "serde", - "serde_derive", - "smallvec", - "wasmparser 0.209.1", -] - -[[package]] -name = "wasmtime-types" -version = "24.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "628d33a0f60048dfd8d82cc784892401ca1397fd6a5d4a26331e9bd28d938710" -dependencies = [ - "anyhow", - "cranelift-entity 0.111.4", - "serde", - "serde_derive", - "smallvec", - "wasmparser 0.215.0", -] +checksum = "60a06819d24370273021054b50589e3078e7f5cfac15515e58b3fbbebf5e5b39" [[package]] name = "wasmtime-versioned-export-macros" -version = "22.0.1" +version = "34.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "455fc30062a08ba6a9c2ccc6e8c76ea2759d01324d3548324f5d38257d0e8d96" +checksum = "9ca100ed168ffc9b37aefc07a5be440645eab612a2ff6e2ff884e8cc3740e666" dependencies = [ "proc-macro2", "quote", "syn", ] -[[package]] -name = "wasmtime-versioned-export-macros" -version = "24.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04fe757e59789ef15c5f774e0e500f710ec7638af450b4d9d664efa2c9116b4c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "wasmtime-winch" -version = "22.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de67dfca76c725b17179185c6ce2d78766656e150b86773b4ddbd2257240ef57" -dependencies = [ - "anyhow", - "cranelift-codegen 0.109.1", - "gimli 0.28.1", - "object", - "target-lexicon", - "wasmparser 0.209.1", - "wasmtime-cranelift 22.0.1", - "wasmtime-environ 22.0.1", - "winch-codegen 0.20.1", -] - -[[package]] -name = "wasmtime-winch" -version = "24.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b311edc2e784f41d38ce89b294f9b9dc18aecf6aed82c5ab6dc7c6d9f2816d6" -dependencies = [ - "anyhow", - "cranelift-codegen 0.111.4", - "gimli 0.29.0", - "object", - "target-lexicon", - "wasmparser 0.215.0", - "wasmtime-cranelift 24.0.4", - "wasmtime-environ 24.0.4", - "winch-codegen 0.22.4", -] - -[[package]] -name = "wasmtime-wit-bindgen" -version = "22.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6b893eec1dbf19e20beb6f2821ddd9672978db0e7c00ab8bb628afaad823783" -dependencies = [ - "anyhow", - "heck 0.4.1", - "indexmap", - "wit-parser 0.209.1", -] - -[[package]] -name = "wasmtime-wit-bindgen" -version = "24.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64cebe3cd91765ca3a3676fc5e3af20323c9f336917f1b8dfc36345f0ee2fa03" -dependencies = [ - "anyhow", - "heck 0.4.1", - "indexmap", - "wit-parser 0.215.0", -] - [[package]] name = "webpki-roots" version = "1.0.2" @@ -3266,55 +2547,12 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-util" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0978bf7171b3d90bac376700cb56d606feb40f251a475a5d6634613564460b22" -dependencies = [ - "windows-sys 0.60.2", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "winch-codegen" -version = "0.20.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b51d823bdea98f7ce9db47909f1c543b5ae253d3df1aebf7ba3c0f25444daef2" -dependencies = [ - "anyhow", - "cranelift-codegen 0.109.1", - "gimli 0.28.1", - "regalloc2", - "smallvec", - "target-lexicon", - "wasmparser 0.209.1", - "wasmtime-cranelift 22.0.1", - "wasmtime-environ 22.0.1", -] - -[[package]] -name = "winch-codegen" -version = "0.22.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f4eff291a302df370d172be239a33c16917749859c25d1005bba7a790827190" -dependencies = [ - "anyhow", - "cranelift-codegen 0.111.4", - "gimli 0.29.0", - "regalloc2", - "smallvec", - "target-lexicon", - "wasmparser 0.215.0", - "wasmtime-cranelift 24.0.4", - "wasmtime-environ 24.0.4", -] - [[package]] name = "windows" version = "0.61.3" @@ -3588,42 +2826,6 @@ version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "052283831dbae3d879dc7f51f3d92703a316ca49f91540417d38591826127814" -[[package]] -name = "wit-parser" -version = "0.209.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e79b9e3c0b6bb589dec46317e645851e0db2734c44e2be5e251b03ff4a51269" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", - "wasmparser 0.209.1", -] - -[[package]] -name = "wit-parser" -version = "0.215.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "935a97eaffd57c3b413aa510f8f0b550a4a9fe7d59e79cd8b89a83dcb860321f" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", - "wasmparser 0.215.0", -] - [[package]] name = "writeable" version = "0.6.1" diff --git a/Cargo.toml b/Cargo.toml index bfe08aa244..858e0e0918 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,7 +76,7 @@ vga = [] virtio = ["dep:virtio"] virtio-net = ["virtio"] vsock = ["virtio", "pci"] -wasm = ["wasmtime"] +wasm = ["wasmtime", "mmap"] [lints.rust] rust_2018_idioms = "warn" @@ -145,7 +145,8 @@ time = { version = "0.3", default-features = false } volatile = "0.6" zerocopy = { version = "0.8", default-features = false } uhyve-interface = "0.1.3" -wasmtime = { version = "24.0", default-features = false, features = ["runtime", "gc", "component-model"], optional = true } +wasmtime = { version = "34.0.2", default-features = false, features = ["runtime", "custom-virtual-memory"], optional = true } +wasi = { version = "0.11", default-features = false } [dependencies.smoltcp] version = "0.12" @@ -183,7 +184,6 @@ semihosting = { version = "0.1", optional = true } memory_addresses = { version = "0.2.3", default-features = false, features = [ "aarch64", ] } -wasmtime = { version = "22.0", default-features = false, features = ["runtime", "gc", "component-model"], optional = true } [target.'cfg(target_arch = "riscv64")'.dependencies] riscv = "0.14" diff --git a/src/lib.rs b/src/lib.rs index 0f6cdfd7d0..dbfb2e31cc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -83,7 +83,7 @@ mod synch; pub mod syscalls; pub mod time; #[cfg(feature = "wasm")] -mod wasm; +pub mod wasm; mod built_info { include!(concat!(env!("OUT_DIR"), "/built.rs")); @@ -149,11 +149,6 @@ extern "C" fn initd(_arg: usize) { #[cfg(not(test))] let (argc, argv, environ) = syscalls::get_application_parameters(); - #[cfg(all(any(target_arch = "x86_64", target_arch = "aarch64"), 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 index 96427fbccd..bec37f1ad2 100644 --- a/src/wasm/capi.rs +++ b/src/wasm/capi.rs @@ -1,12 +1,12 @@ use core::cell::UnsafeCell; use align_address::Align; +use memory_addresses::VirtAddr; 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`. @@ -62,7 +62,7 @@ static TLS: UnsafeCell<*mut u8> = UnsafeCell::new(core::ptr::null_mut()); /// and this function returns the current value of the TLS variable. /// /// This value should default to `NULL`. -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn wasmtime_tls_get() -> *mut u8 { unsafe { TLS.get().read() } } @@ -70,7 +70,7 @@ pub extern "C" fn wasmtime_tls_get() -> *mut u8 { // Sets the current TLS value for Wasmtime to the provided value. /// /// This value should be returned when later calling `wasmtime_tls_get`. -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn wasmtime_tls_set(ptr: *mut u8) { unsafe { TLS.get().write(ptr); @@ -78,7 +78,7 @@ pub extern "C" fn wasmtime_tls_set(ptr: *mut u8) { } /// Returns the page size, in bytes, of the current system. -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn wasmtime_page_size() -> usize { BasePageSize::SIZE as usize } @@ -93,15 +93,15 @@ pub extern "C" fn wasmtime_page_size() -> usize { /// 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] +#[unsafe(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(); + let virtual_address = crate::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 physical_address = crate::mm::physicalmem::allocate(size).unwrap(); let count = size / BasePageSize::SIZE as usize; let mut flags = PageTableEntryFlags::empty(); @@ -130,7 +130,7 @@ pub extern "C" fn wasmtime_mmap_new(size: usize, prot_flags: WasmProt, ret: &mut /// 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] +#[unsafe(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 @@ -144,9 +144,9 @@ pub extern "C" fn wasmtime_mmap_remap(_addr: *mut u8, _size: usize, _prot_flags: /// Returns 0 on success and an error code on failure. /// /// Similar to `munmap` on Linux. -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn wasmtime_munmap(ptr: *mut u8, size: usize) -> i32 { - let virtual_address = VirtAddr::from_usize(ptr as usize); + let virtual_address = VirtAddr::new(ptr as u64); let size = size.align_up(BasePageSize::SIZE as usize); if let Some(phys_addr) = arch::mm::paging::virtual_to_physical(virtual_address) { @@ -154,10 +154,10 @@ pub extern "C" fn wasmtime_munmap(ptr: *mut u8, size: usize) -> i32 { virtual_address, size / BasePageSize::SIZE as usize, ); - arch::mm::physicalmem::deallocate(phys_addr, size); + crate::mm::physicalmem::deallocate(phys_addr, size); } - arch::mm::virtualmem::deallocate(virtual_address, size); + crate::mm::virtualmem::deallocate(virtual_address, size); 0 } @@ -168,7 +168,7 @@ pub extern "C" fn wasmtime_munmap(ptr: *mut u8, size: usize) -> i32 { /// Returns 0 on success and an error code on failure. /// /// Similar to `mprotect` on Linux. -#[no_mangle] +#[unsafe(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(); @@ -180,19 +180,19 @@ pub extern "C" fn wasmtime_mprotect(ptr: *mut u8, size: usize, prot_flags: WasmP flags.execute_disable(); } - let virtual_address = VirtAddr::from_usize(ptr as usize); + let virtual_address = VirtAddr::new(ptr as u64); 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(); + let physical_address = crate::mm::physicalmem::allocate(size).unwrap(); arch::mm::paging::map::(virtual_address, physical_address, count, flags); 0 } } -extern "C" { +unsafe extern "C" { fn setjmp(buf: *const u8) -> i32; fn longjmp(jmp_buf: *const u8, val: i32) -> !; } @@ -210,7 +210,7 @@ extern "C" { /// /// 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] +#[unsafe(no_mangle)] pub extern "C" fn wasmtime_setjmp( jmp_buf: *mut *const u8, callback: extern "C" fn(*mut u8, *mut u8), @@ -242,7 +242,7 @@ pub extern "C" fn wasmtime_setjmp( /// /// This function may be invoked from the `wasmtime_trap_handler_t` /// configured by `wasmtime_init_traps`. -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn wasmtime_longjmp(jmp_buf: *const u8) -> ! { unsafe { longjmp(jmp_buf, 1); @@ -261,7 +261,7 @@ pub extern "C" fn wasmtime_longjmp(jmp_buf: *const u8) -> ! { /// the system. /// /// Returns 0 on success and an error code on failure. -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn wasmtime_init_traps(_handler: wasmtime_trap_handler_t) -> i32 { 0 } @@ -285,7 +285,7 @@ pub extern "C" fn wasmtime_init_traps(_handler: wasmtime_trap_handler_t) -> i32 /// `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] +#[unsafe(no_mangle)] pub extern "C" fn wasmtime_memory_image_new( _ptr: *const u8, _len: usize, @@ -309,7 +309,7 @@ pub extern "C" fn wasmtime_memory_image_new( /// the future. /// /// Aborts the process on failure. -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn wasmtime_memory_image_map_at( _image: *mut wasmtime_memory_image, _addr: *mut u8, @@ -323,7 +323,7 @@ pub extern "C" fn wasmtime_memory_image_map_at( /// /// Note that mappings created from this image are not guaranteed to be /// deallocated and/or unmapped before this is called. -#[no_mangle] +#[unsafe(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 deleted file mode 100644 index 27e1eeff0e7bbb040a812386996a630229fb96d9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 14208 zcmeHOZEPGz8J^uc+vnPeuSrUrCPFScN($7n9aE(xv^J^J-E!qUu-d!ZvzP4c z9=B^JPOCQ3DKx8%Q=|fce@IkC{N`7os-jX9kU&Yll87HPf+9I6g7P618R6r3XJ_xu zXCI0Xe~@;hcW36E=lz&x<}B@a_W2p@fGkPBV4_IuVJ5|$wt8wZ>d@E}Z%(mIY>=_u ziOJEi(Xp*3_dcLMFnRyHbKG%HIQKiQWA5yCtG;fV3#QF_ysBxI`hDBeD{cvjG$HP^ ztwPbTZ9RIp&H@{-JVP&;WnJdavlG(b)^@dDGkkM)k@Z@R zZ8_$SLP4(@rIO{$a+ujC^rmAJ zY*ROE%kXr=G3-Up@?>d9=z+G%7J0ZsXsX4cj3hk0YN7G5dAKUNh=uG*x|k*$4+?nM zb`4*ac8acJIN$)3SYX0BW%!os$n4J8x8*qSf?Q>`S?CPktyo2*6oWjYY*t;%@u9n0 zfNXoAq8kNEH&6Pe$J(KMxd z1&-VOC*WrU&~l13vtl~Fft}-4s+P??fk7;6w78gOHZzB{^E`8p%=)8dd)u5GZ|cp- z37Pc~##lHhGj51htSnayxD&&l8=ojxh>W!uY^h3LU(;Q%u~Mzkg+j#w@hwFe8;5#T zw_0?35fLDy#Dk-W;5=*l6i1v!$GE8D8a2`KkGsUjceiIOg`MA*54RYAN<|W3&(*~>bFLe zU{_8HO1X>{Je$iZ!9VlkA1L(|d8nQNLJh9nycac;XsSzx8%pq7C3t`NM~y~9tzTMI zr8m`jLmGPF1{9Akr9Y*F@E4N5ko?u(L;|_-MNEt`@AQ!6oI)+e2q4l}LYc z8=6}1M`8Q!YJ=t%8RUZ%?Y=8*)1mMog~!B3FfpXYC&t+ayJ~Pl3%gJi9Y$Wfg2XMd?!wA#r+m= zUl6z_*5T@W9;BxAp+brg2>Cn&c^YyIQiGg;JOg26-=i%CuPtdJz;niiKR?uAq5aF`uA4Mid$QhSqc_R>Ten`xrf`a)E&BB zGJHcfol;5~&~<+EyI^=`ir(Y+Rb{-bN^*+c=F;@yDoL`ON--%5MOLDF&G98?+;oPX zW(G9$ux>q5-^NJ4v?}lTuEa*pNYaJW-ghK+QF>jHE~g%Wr~E>NSQ4)5dB2x|36^e#HYM`S5QNp&fdFc@l% z#^)wGg?>bg#OEZR7y64rAD@Rz!x8y;jvS)I=N@z>LHY|qAD?r41Ptjf3w?a9aarg$ z(*mHx=NLakoA5`3evFSY_Po%a75ey`;;_)aC-lv83ECz{$BsSpPTUkD$%WkalZ=T|pDK0~*I!&Zv(sI2iv;`c}mp1qD^Ft&cBWY89i} zrlGGp*rv8};TqzlIMp(2DED3iba- z<*V>RTUKnVrq?Oay3qP5agEsCP23^0HnP7a>^kuq^+^|>XEq(vA0#Sq9rf1rUFbK8 z&qgAH*E#}rblLVU_OIO&*?$mK&1a{5Ul;rDeV~g>T csfh?s?g-e?Ws6 u64 { +fn native_fibonacci(n: u64) -> u64 { match n { 0 => 0, 1 => 1, @@ -14,88 +22,324 @@ pub fn native_fibonacci(n: u64) -> u64 { } } -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); +pub fn measure_fibonacci(n: u64) { + const RUNS: u64 = 100; + info!("Measure native_fibonacci({})", n); - // 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)?; + let start = now_micros(); + for _ in 0..RUNS { + black_box(native_fibonacci(black_box(n))); + } + let end = now_micros(); + info!( + "Average time to call native_fibonacci({}): {} usec", + n, + (end - start) / RUNS + ); +} - info!("Create Module"); - let module_bytes = include_bytes!("fib.cwasm"); - let module = unsafe { Module::deserialize(&engine, &module_bytes[..])? }; +pub(crate) static WASM_MANAGER: InterruptTicketMutex> = + InterruptTicketMutex::new(None); +pub(crate) static INPUT: InterruptTicketMutex>> = + InterruptTicketMutex::new(VecDeque::new()); - let mut imports = module.imports(); - while let Some(i) = imports.next() { - info!("import from module {} symbol {}", i.module(), i.name()); - } +pub(crate) struct WasmManager { + store: Store, + instance: Instance, +} - info!("Create Linker"); - let mut linker = Linker::new(&engine); +impl WasmManager { + pub fn new(slice: &[u8]) -> Self { + let mut config: Config = Config::new(); + config.memory_init_cow(false); + config.memory_guard_size(8192); + config.wasm_simd(false); + config.wasm_relaxed_simd(false); + //config.wasm_reference_types(true); + //config.wasm_gc(true); - // In case WASI, it is required to emulate - // https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md + let engine = Engine::new(&config).unwrap(); + let module = unsafe { Module::deserialize(&engine, slice).unwrap() }; + let mut linker = Linker::new(&engine); + linker + .func_wrap("env", "now", || { + crate::arch::kernel::systemtime::now_micros() + }) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "fd_read", + |mut caller: Caller<'_, _>, + fd: i32, + iovs_ptr: i32, + iovs_len: i32, + nread_ptr: i32| { + without_interrupts(|| { + if let Some(Extern::Memory(mem)) = caller.get_export("memory") { + info!("A"); + let mut iovs = vec![0i32; (2 * iovs_len).try_into().unwrap()]; + let _ = mem.read( + caller.as_context(), + iovs_ptr.try_into().unwrap(), + iovs.as_mut_bytes(), + ); - linker.func_wrap("env", "now", || { - crate::arch::kernel::systemtime::now_micros() - })?; - linker.func_wrap("env", "exit", || panic!("Panic in WASM module"))?; + info!("B"); + let mut nread_bytes: i32 = 0; + let mut i = 0; + //if let Some(data) = INPUT.lock().pop_front() { + info!("iovs.len() = {}, {}", iovs.len(), 0); //data.len()); - // 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); - info!("Create instance"); - let instance = linker.instantiate(&mut store, &module).unwrap(); + /*while i < iovs.len() { + let _ = mem.write( + caller.as_context_mut(), + iovs[i].try_into().unwrap(), + &data, + ); - info!("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) " - ); + nread_bytes += data.len() as i32; + //if result < len.try_into().unwrap() { + break; + //} - const N: u64 = 100; - let start = now_micros(); - for _ in 0..N { - let _result = fibonacci.call(&mut store, 30)?; + i += 2; + }*/ + //} + + let _ = mem.write( + caller.as_context_mut(), + nread_ptr.try_into().unwrap(), + nread_bytes.as_bytes(), + ); + + return ERRNO_SUCCESS.raw() as i32; + } + + ERRNO_INVAL.raw() as i32 + }) + }, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "fd_write", + |mut caller: Caller<'_, u32>, + fd: i32, + iovs_ptr: i32, + iovs_len: i32, + nwritten_ptr: i32| { + let fd = if fd <= 2 { + fd + } else { + panic!("fd_write: invalid file descriptor {}", fd); + }; + + info!("fd_write: fd = {}", fd); + if let Some(Extern::Memory(mem)) = caller.get_export("memory") { + let mut iovs = vec![0i32; (2 * iovs_len).try_into().unwrap()]; + let _ = mem.read( + caller.as_context(), + iovs_ptr.try_into().unwrap(), + iovs.as_mut_bytes(), + ); + + let mut nwritten_bytes: i32 = 0; + let mut i = 0; + info!("iovs.len() = {}", iovs.len()); + while i < iovs.len() { + let len = iovs[i + 1]; + + info!("len = {}", len); + // len = 0 => ignore entry nothing to write + if len == 0 { + i += 2; + continue; + } + + let mut data: Vec> = + Vec::with_capacity(len.try_into().unwrap()); + unsafe { + data.set_len(len as usize); + } + + let _ = mem.read( + caller.as_context(), + iovs[i].try_into().unwrap(), + unsafe { data.assume_init_mut() }, + ); + let result = unsafe { + sys_write( + fd, + data.assume_init_ref().as_ptr(), + len.try_into().unwrap(), + ) + }; + + info!("fd_write: result = {}", result); + + if result >= 0 { + nwritten_bytes += result as i32; + info!("nwritten_bytes = {}, len = {}", nwritten_bytes, len); + /*if result >= len.try_into().unwrap() { + info!("break"); + break; + }*/ + } else { + return (-result).try_into().unwrap(); + } + + i += 2; + } + + info!("JJ"); + let _ = mem.write( + caller.as_context_mut(), + nwritten_ptr.try_into().unwrap(), + nwritten_bytes.as_bytes(), + ); + + info!("KK"); + return ERRNO_SUCCESS.raw() as i32; + } + + ERRNO_INVAL.raw() as i32 + }, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "environ_get", + |mut caller: Caller<'_, _>, env_ptr: i32, env_buffer_ptr: i32| { + if let Some(Extern::Memory(mem)) = caller.get_export("memory") { + let mut _pos: u32 = env_buffer_ptr as u32; + } + ERRNO_SUCCESS.raw() as i32 + }, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "environ_sizes_get", + |mut caller: Caller<'_, _>, + number_env_variables_ptr: i32, + env_buffer_size_ptr: i32| { + if let Some(Extern::Memory(mem)) = caller.get_export("memory") { + let env_buffer_size: u32 = 0; + let nnumber_env_variables: u32 = 0; + + let _ = mem.write( + caller.as_context_mut(), + number_env_variables_ptr.try_into().unwrap(), + nnumber_env_variables.as_bytes(), + ); + let _ = mem.write( + caller.as_context_mut(), + env_buffer_size_ptr.try_into().unwrap(), + env_buffer_size.as_bytes(), + ); + + return ERRNO_SUCCESS.raw() as i32; + } + + ERRNO_INVAL.raw() as i32 + }, + ) + .unwrap(); + linker + .func_wrap("wasi_snapshot_preview1", "proc_exit", |_: i32| { + error!("Panic in WASM module") + }) + .unwrap(); + + // 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); + let instance = linker.instantiate(&mut store, &module).unwrap(); + + let func = instance + .get_typed_func::<(), ()>(&mut store, "hello_world") + .unwrap(); + func.call(&mut store, ()).unwrap(); + + Self { store, instance } } - let end = now_micros(); - info!( - "Average time to call fibonacci(30): {} usec", - (end - start) / N - ); - let start = now_micros(); - for _ in 0..N { - let _result = native_fibonacci(30); + pub fn call_func(&mut self, name: &str, arg: P) -> Result + where + P: wasmtime::WasmParams, + R: wasmtime::WasmResults, + { + let func = self + .instance + .get_typed_func::(&mut self.store, name)?; + func.call(&mut self.store, arg) } - let end = now_micros(); - info!( - "Average time to call native_fibonacci(30): {} usec", - (end - start) / N - ); +} +#[hermit_macro::system] +#[unsafe(no_mangle)] +pub extern "C" fn sys_load_binary(ptr: *const u8, len: usize) -> i32 { + info!("Loading WebAssembly binary..."); - let bench = instance.get_typed_func::<(u64, u64), i64>(&mut store, "bench")?; - let usec = bench.call(&mut store, (N, 30))?; - info!("Benchmark takes {} msec", usec / 1000); + // copy module into the kernel space + let slice = unsafe { core::slice::from_raw_parts(ptr, len) }; + let wasm_manager = WasmManager::new(slice); - let foo = instance.get_typed_func::<(), ()>(&mut store, "foo")?; - foo.call(&mut store, ())?; - let start = now_micros(); - for _ in 0..N { - foo.call(&mut store, ())?; + *WASM_MANAGER.lock() = Some(wasm_manager); + + if let Some(ref mut wasm_manager) = WASM_MANAGER.lock().as_mut() { + info!("Call function fibonacci"); + let result = wasm_manager.call_func::("fibonacci", 30).unwrap(); + info!("fibonacci(30) = {}", result); + + wasm_manager.call_func::<(), ()>("hello_world", ()).unwrap(); + } + + 0 +} + +#[hermit_macro::system] +#[unsafe(no_mangle)] +pub extern "C" fn sys_fibonacci() -> i32 { + info!("Try to find function fibonacci"); + + measure_fibonacci(30); + + if let Some(ref mut wasm_manager) = WASM_MANAGER.lock().as_mut() { + // And finally we can call the wasm function + info!("Call function fibonacci"); + let result = wasm_manager.call_func::("fibonacci", 30).unwrap(); + info!("fibonacci(30) = {}", result); + assert!( + result == 832040, + "Error in the calculation of fibonacci(30) " + ); + + const RUNS: u64 = 100; + let n = 30; + let start = now_micros(); + for _ in 0..RUNS { + black_box(wasm_manager.call_func::("fibonacci", n).unwrap()); + } + let end = now_micros(); + info!( + "Average time to call fibonacci({}) in WASM: {} usec", + n, + (end - start) / RUNS + ); + + info!( + "Average time to call measure_fibonacci({}) in WASM: {} usec", + n, + wasm_manager + .call_func::("measure_fibonacci", n) + .unwrap() + ); } - let end = now_micros(); - info!("Average time to call foo: {} usec", (end - start) / N); - Ok(()) + 0 } From 83285852d5948807f293e7b3a4e1b531811606a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Tue, 22 Jul 2025 18:17:11 +0200 Subject: [PATCH 11/24] fix(fd_write): break on incomplete write --- src/wasm/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs index a4057a271b..83eb24bcf9 100644 --- a/src/wasm/mod.rs +++ b/src/wasm/mod.rs @@ -182,10 +182,10 @@ impl WasmManager { if result >= 0 { nwritten_bytes += result as i32; info!("nwritten_bytes = {}, len = {}", nwritten_bytes, len); - /*if result >= len.try_into().unwrap() { + if result < len.try_into().unwrap() { info!("break"); break; - }*/ + } } else { return (-result).try_into().unwrap(); } From 87c04a761ae431d3bb1687dbec3844402726327e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Tue, 22 Jul 2025 18:21:56 +0200 Subject: [PATCH 12/24] fix(fd_write): don't use system call - remove obsolete wasm file --- src/arch/aarch64/kernel/mod.rs | 44 ------------ src/arch/riscv64/kernel/mod.rs | 32 --------- src/arch/x86_64/kernel/mod.rs | 51 ------------- src/arch/x86_64/mm/paging.rs | 4 +- src/wasm/capi.rs | 13 ++-- src/wasm/fib.wasm | Bin 444 -> 0 bytes src/wasm/mod.rs | 126 ++++++++++++++------------------- 7 files changed, 59 insertions(+), 211 deletions(-) delete mode 100755 src/wasm/fib.wasm diff --git a/src/arch/aarch64/kernel/mod.rs b/src/arch/aarch64/kernel/mod.rs index d1de0cc029..05992ac6b9 100644 --- a/src/arch/aarch64/kernel/mod.rs +++ b/src/arch/aarch64/kernel/mod.rs @@ -36,50 +36,6 @@ const SERIAL_PORT_BAUDRATE: u32 = 115_200; global_asm!(include_str!("setjmp.s")); global_asm!(include_str!("longjmp.s")); -pub(crate) struct Console { - serial_port: SerialPort, -} - -impl Console { - pub fn new() -> Self { - CoreLocal::install(); - - let base = env::boot_info() - .hardware_info - .serial_port_base - .map(|uartport| uartport.get()) - .unwrap_or_default() - .try_into() - .unwrap(); - - let serial_port = SerialPort::new(base); - - serial_port.init(SERIAL_PORT_BAUDRATE); - - Self { serial_port } - } - - pub fn write(&mut self, buf: &[u8]) { - self.serial_port.write_buf(buf); - } - - pub fn read(&mut self) -> Option { - None - } - - pub fn is_empty(&self) -> bool { - true - } - - pub fn register_waker(&mut self, _waker: &Waker) {} -} - -impl Default for Console { - fn default() -> Self { - Self::new() - } -} - #[repr(align(8))] pub(crate) struct AlignedAtomicU32(AtomicU32); diff --git a/src/arch/riscv64/kernel/mod.rs b/src/arch/riscv64/kernel/mod.rs index 1dc2137ccf..b5d959d839 100644 --- a/src/arch/riscv64/kernel/mod.rs +++ b/src/arch/riscv64/kernel/mod.rs @@ -36,38 +36,6 @@ use crate::env; use crate::init_cell::InitCell; use crate::mm::physicalmem::PHYSICAL_FREE_LIST; -pub(crate) struct Console {} - -impl Console { - pub fn new() -> Self { - CoreLocal::install(); - - Self {} - } - - pub fn write(&mut self, buf: &[u8]) { - for byte in buf { - sbi_rt::console_write_byte(*byte); - } - } - - pub fn read(&mut self) -> Option { - None - } - - pub fn is_empty(&self) -> bool { - true - } - - pub fn register_waker(&mut self, _waker: &Waker) {} -} - -impl Default for Console { - fn default() -> Self { - Self::new() - } -} - global_asm!(include_str!("setjmp.s")); global_asm!(include_str!("longjmp.s")); diff --git a/src/arch/x86_64/kernel/mod.rs b/src/arch/x86_64/kernel/mod.rs index f672aa2653..e25d9f3821 100644 --- a/src/arch/x86_64/kernel/mod.rs +++ b/src/arch/x86_64/kernel/mod.rs @@ -46,57 +46,6 @@ pub mod vga; global_asm!(include_str!("setjmp.s")); global_asm!(include_str!("longjmp.s")); -pub(crate) struct Console { - serial_port: SerialPort, -} - -impl Console { - pub fn new() -> Self { - CoreLocal::install(); - - let base = env::boot_info() - .hardware_info - .serial_port_base - .unwrap() - .get(); - let serial_port = unsafe { SerialPort::new(base) }; - Self { serial_port } - } - - pub fn write(&mut self, buf: &[u8]) { - self.serial_port.send(buf); - - #[cfg(feature = "vga")] - for &byte in buf { - // vga::write_byte() checks if VGA support has been initialized, - // so we don't need any additional if clause around it. - vga::write_byte(byte); - } - } - - pub fn buffer_input(&mut self) { - self.serial_port.buffer_input(); - } - - pub fn read(&mut self) -> Option { - self.serial_port.read() - } - - pub fn is_empty(&self) -> bool { - self.serial_port.is_empty() - } - - pub fn register_waker(&mut self, waker: &Waker) { - self.serial_port.register_waker(waker); - } -} - -impl Default for Console { - fn default() -> Self { - Self::new() - } -} - pub fn get_ram_address() -> PhysAddr { PhysAddr::new(env::boot_info().hardware_info.phys_addr_range.start) } diff --git a/src/arch/x86_64/mm/paging.rs b/src/arch/x86_64/mm/paging.rs index 109770afc4..b9798c4e23 100644 --- a/src/arch/x86_64/mm/paging.rs +++ b/src/arch/x86_64/mm/paging.rs @@ -173,7 +173,7 @@ pub fn map( if let Ok((_frame, flush)) = unmap { unmapped = true; flush.flush(); - debug!("Had to unmap page {page:?} before mapping."); + trace!("Had to unmap page {page:?} before mapping."); } let map = unsafe { mapper.map_to(page, frame, flags, &mut *frame_allocator) }; match map { @@ -267,7 +267,7 @@ where // FIXME: Some sentinel pages around stacks are supposed to be unmapped. // We should handle this case there instead of here. Err(UnmapError::PageNotMapped) => { - debug!("Tried to unmap {page:?}, which was not mapped."); + trace!("Tried to unmap {page:?}, which was not mapped."); } Err(err) => panic!("{err:?}"), } diff --git a/src/wasm/capi.rs b/src/wasm/capi.rs index bec37f1ad2..fb479d1092 100644 --- a/src/wasm/capi.rs +++ b/src/wasm/capi.rs @@ -1,6 +1,5 @@ -use core::cell::UnsafeCell; - use align_address::Align; +use hermit_sync::InterruptTicketMutex; use memory_addresses::VirtAddr; use crate::arch; @@ -55,8 +54,8 @@ pub type wasmtime_trap_handler_t = #[allow(non_camel_case_types)] pub enum wasmtime_memory_image {} -#[thread_local] -static TLS: UnsafeCell<*mut u8> = UnsafeCell::new(core::ptr::null_mut()); +/// We support only single threaded application and use lock to get access to the TLS variable. +static TLS: InterruptTicketMutex = InterruptTicketMutex::new(0); /// 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. @@ -64,7 +63,7 @@ static TLS: UnsafeCell<*mut u8> = UnsafeCell::new(core::ptr::null_mut()); /// This value should default to `NULL`. #[unsafe(no_mangle)] pub extern "C" fn wasmtime_tls_get() -> *mut u8 { - unsafe { TLS.get().read() } + *TLS.lock() as *mut u8 } // Sets the current TLS value for Wasmtime to the provided value. @@ -72,9 +71,7 @@ pub extern "C" fn wasmtime_tls_get() -> *mut u8 { /// This value should be returned when later calling `wasmtime_tls_get`. #[unsafe(no_mangle)] pub extern "C" fn wasmtime_tls_set(ptr: *mut u8) { - unsafe { - TLS.get().write(ptr); - } + *TLS.lock() = ptr as usize; } /// Returns the page size, in bytes, of the current system. diff --git a/src/wasm/fib.wasm b/src/wasm/fib.wasm deleted file mode 100755 index 73b6a36fc8b0f37216c410babbbeda042742cbcb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 444 zcmY*VQBN8{5T4lu6jlPUPny^qCMFs@3Zz!s7cEWSeK5W*d&>Zqa=YYqQAy}=@t5_d z^)8qgUuNd}zM0841Ii@`0Qjjg2F%6)W6X-ovLZ5poXit9_8EXzI5J-42<_St-{Q|a z{|90VAM@UAt(H(?(=`J=wHB~GjU#K6)-kYZL`KhnH>8{>uOyiXMhPc_H91FuOFItHusBlaDMfjhPpq{!(iASehvHI q!ol?gT(-PQXXNFSlwYOfShtm|yoweS&K5RO3)kIu@yvwu;{O9qHgN_3 diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs index 83eb24bcf9..e5bc15b55d 100644 --- a/src/wasm/mod.rs +++ b/src/wasm/mod.rs @@ -3,13 +3,13 @@ use alloc::vec::Vec; use core::hint::black_box; use core::mem::MaybeUninit; -use hermit_sync::{InterruptTicketMutex, without_interrupts}; +use hermit_sync::InterruptTicketMutex; use wasi::*; use wasmtime::*; use zerocopy::IntoBytes; +use crate::fd; use crate::kernel::systemtime::now_micros; -use crate::syscalls::sys_write; mod capi; @@ -49,17 +49,15 @@ pub(crate) struct WasmManager { } impl WasmManager { - pub fn new(slice: &[u8]) -> Self { + pub fn new(data: &[u8]) -> Self { let mut config: Config = Config::new(); config.memory_init_cow(false); config.memory_guard_size(8192); config.wasm_simd(false); config.wasm_relaxed_simd(false); - //config.wasm_reference_types(true); - //config.wasm_gc(true); let engine = Engine::new(&config).unwrap(); - let module = unsafe { Module::deserialize(&engine, slice).unwrap() }; + let module = unsafe { Module::deserialize(&engine, data).unwrap() }; let mut linker = Linker::new(&engine); linker .func_wrap("env", "now", || { @@ -75,23 +73,28 @@ impl WasmManager { iovs_ptr: i32, iovs_len: i32, nread_ptr: i32| { - without_interrupts(|| { - if let Some(Extern::Memory(mem)) = caller.get_export("memory") { - info!("A"); - let mut iovs = vec![0i32; (2 * iovs_len).try_into().unwrap()]; - let _ = mem.read( - caller.as_context(), - iovs_ptr.try_into().unwrap(), - iovs.as_mut_bytes(), - ); + let _fd = if fd <= 2 { + fd + } else { + panic!("fd_read: invalid file descriptor {}", fd); + }; + + info!("fd {}", fd); + if let Some(Extern::Memory(mem)) = caller.get_export("memory") { + let mut iovs = vec![0i32; (2 * iovs_len).try_into().unwrap()]; + let _ = mem.read( + caller.as_context(), + iovs_ptr.try_into().unwrap(), + iovs.as_mut_bytes(), + ); - info!("B"); - let mut nread_bytes: i32 = 0; - let mut i = 0; - //if let Some(data) = INPUT.lock().pop_front() { - info!("iovs.len() = {}, {}", iovs.len(), 0); //data.len()); + let mut nread_bytes: i32 = 0; + let mut i = 0; + if let Some(data) = INPUT.lock().pop_front() { + let len = iovs[i + 1]; + info!("len = {}, {}", len, data.len()); - /*while i < iovs.len() { + while i < iovs.len() { let _ = mem.write( caller.as_context_mut(), iovs[i].try_into().unwrap(), @@ -99,25 +102,21 @@ impl WasmManager { ); nread_bytes += data.len() as i32; - //if result < len.try_into().unwrap() { - break; - //} i += 2; - }*/ - //} + } + } - let _ = mem.write( - caller.as_context_mut(), - nread_ptr.try_into().unwrap(), - nread_bytes.as_bytes(), - ); + let _ = mem.write( + caller.as_context_mut(), + nread_ptr.try_into().unwrap(), + nread_bytes.as_bytes(), + ); - return ERRNO_SUCCESS.raw() as i32; - } + return ERRNO_SUCCESS.raw() as i32; + } - ERRNO_INVAL.raw() as i32 - }) + ERRNO_INVAL.raw() as i32 }, ) .unwrap(); @@ -136,7 +135,6 @@ impl WasmManager { panic!("fd_write: invalid file descriptor {}", fd); }; - info!("fd_write: fd = {}", fd); if let Some(Extern::Memory(mem)) = caller.get_export("memory") { let mut iovs = vec![0i32; (2 * iovs_len).try_into().unwrap()]; let _ = mem.read( @@ -147,11 +145,9 @@ impl WasmManager { let mut nwritten_bytes: i32 = 0; let mut i = 0; - info!("iovs.len() = {}", iovs.len()); while i < iovs.len() { let len = iovs[i + 1]; - info!("len = {}", len); // len = 0 => ignore entry nothing to write if len == 0 { i += 2; @@ -169,38 +165,24 @@ impl WasmManager { iovs[i].try_into().unwrap(), unsafe { data.assume_init_mut() }, ); - let result = unsafe { - sys_write( - fd, - data.assume_init_ref().as_ptr(), - len.try_into().unwrap(), - ) - }; - - info!("fd_write: result = {}", result); - - if result >= 0 { - nwritten_bytes += result as i32; - info!("nwritten_bytes = {}, len = {}", nwritten_bytes, len); - if result < len.try_into().unwrap() { - info!("break"); - break; + let result = fd::write(fd, unsafe { data.assume_init_ref() }); + + match result { + Ok(n) => { + nwritten_bytes += n as i32; } - } else { - return (-result).try_into().unwrap(); + Err(err) => return -i32::from(err), } i += 2; } - info!("JJ"); let _ = mem.write( caller.as_context_mut(), nwritten_ptr.try_into().unwrap(), nwritten_bytes.as_bytes(), ); - info!("KK"); return ERRNO_SUCCESS.raw() as i32; } @@ -212,10 +194,7 @@ impl WasmManager { .func_wrap( "wasi_snapshot_preview1", "environ_get", - |mut caller: Caller<'_, _>, env_ptr: i32, env_buffer_ptr: i32| { - if let Some(Extern::Memory(mem)) = caller.get_export("memory") { - let mut _pos: u32 = env_buffer_ptr as u32; - } + |mut _caller: Caller<'_, _>, _env_ptr: i32, _env_buffer_ptr: i32| { ERRNO_SUCCESS.raw() as i32 }, ) @@ -261,11 +240,6 @@ impl WasmManager { let mut store = Store::new(&engine, 4); let instance = linker.instantiate(&mut store, &module).unwrap(); - let func = instance - .get_typed_func::<(), ()>(&mut store, "hello_world") - .unwrap(); - func.call(&mut store, ()).unwrap(); - Self { store, instance } } @@ -280,23 +254,27 @@ impl WasmManager { func.call(&mut self.store, arg) } } + +#[hermit_macro::system] +#[unsafe(no_mangle)] +pub extern "C" fn sys_unload_binary() -> i32 { + *WASM_MANAGER.lock() = None; + + 0 +} + #[hermit_macro::system] #[unsafe(no_mangle)] pub extern "C" fn sys_load_binary(ptr: *const u8, len: usize) -> i32 { info!("Loading WebAssembly binary..."); - // copy module into the kernel space let slice = unsafe { core::slice::from_raw_parts(ptr, len) }; let wasm_manager = WasmManager::new(slice); *WASM_MANAGER.lock() = Some(wasm_manager); - if let Some(ref mut wasm_manager) = WASM_MANAGER.lock().as_mut() { - info!("Call function fibonacci"); - let result = wasm_manager.call_func::("fibonacci", 30).unwrap(); - info!("fibonacci(30) = {}", result); - - wasm_manager.call_func::<(), ()>("hello_world", ()).unwrap(); + if let Some(ref mut wasm_manager) = crate::wasm::WASM_MANAGER.lock().as_mut() { + let _ = wasm_manager.call_func::<(), ()>("hello_world", ()); } 0 From 97251515c2c2f28c6d05da8c1aeb59d69a9174ce Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Thu, 24 Jul 2025 12:02:20 +0200 Subject: [PATCH 13/24] handle wasm io to a asynchronous task --- src/wasm/mod.rs | 67 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 23 deletions(-) diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs index e5bc15b55d..56884a9f5e 100644 --- a/src/wasm/mod.rs +++ b/src/wasm/mod.rs @@ -1,14 +1,17 @@ use alloc::collections::VecDeque; use alloc::vec::Vec; +use core::future; use core::hint::black_box; use core::mem::MaybeUninit; +use core::task::Poll; use hermit_sync::InterruptTicketMutex; use wasi::*; use wasmtime::*; use zerocopy::IntoBytes; -use crate::fd; +use crate::console::CONSOLE; +use crate::executor::{WakerRegistration, spawn}; use crate::kernel::systemtime::now_micros; mod capi; @@ -42,6 +45,26 @@ pub(crate) static WASM_MANAGER: InterruptTicketMutex> = InterruptTicketMutex::new(None); pub(crate) static INPUT: InterruptTicketMutex>> = InterruptTicketMutex::new(VecDeque::new()); +static OUTPUT: InterruptTicketMutex = InterruptTicketMutex::new(WasmStdout::new()); + +struct WasmStdout { + pub data: VecDeque>, + pub waker: WakerRegistration, +} + +impl WasmStdout { + pub const fn new() -> Self { + Self { + data: VecDeque::new(), + waker: WakerRegistration::new(), + } + } + + pub fn write(&mut self, buf: &[u8]) { + self.data.push_back(buf.to_vec()); + self.waker.wake(); + } +} pub(crate) struct WasmManager { store: Store, @@ -79,7 +102,6 @@ impl WasmManager { panic!("fd_read: invalid file descriptor {}", fd); }; - info!("fd {}", fd); if let Some(Extern::Memory(mem)) = caller.get_export("memory") { let mut iovs = vec![0i32; (2 * iovs_len).try_into().unwrap()]; let _ = mem.read( @@ -89,12 +111,11 @@ impl WasmManager { ); let mut nread_bytes: i32 = 0; - let mut i = 0; + let i = 0; if let Some(data) = INPUT.lock().pop_front() { - let len = iovs[i + 1]; - info!("len = {}, {}", len, data.len()); + let _len = iovs[i + 1]; - while i < iovs.len() { + if !data.is_empty() { let _ = mem.write( caller.as_context_mut(), iovs[i].try_into().unwrap(), @@ -102,8 +123,6 @@ impl WasmManager { ); nread_bytes += data.len() as i32; - - i += 2; } } @@ -125,16 +144,10 @@ impl WasmManager { "wasi_snapshot_preview1", "fd_write", |mut caller: Caller<'_, u32>, - fd: i32, + _fd: i32, iovs_ptr: i32, iovs_len: i32, nwritten_ptr: i32| { - let fd = if fd <= 2 { - fd - } else { - panic!("fd_write: invalid file descriptor {}", fd); - }; - if let Some(Extern::Memory(mem)) = caller.get_export("memory") { let mut iovs = vec![0i32; (2 * iovs_len).try_into().unwrap()]; let _ = mem.read( @@ -165,14 +178,8 @@ impl WasmManager { iovs[i].try_into().unwrap(), unsafe { data.assume_init_mut() }, ); - let result = fd::write(fd, unsafe { data.assume_init_ref() }); - - match result { - Ok(n) => { - nwritten_bytes += n as i32; - } - Err(err) => return -i32::from(err), - } + OUTPUT.lock().write(unsafe { data.assume_init_mut() }); + nwritten_bytes += len; i += 2; } @@ -263,6 +270,18 @@ pub extern "C" fn sys_unload_binary() -> i32 { 0 } +async fn wasm_run() { + future::poll_fn(|cx| { + let mut guard = OUTPUT.lock(); + while let Some(data) = guard.data.pop_front() { + CONSOLE.lock().write(&data); + } + guard.waker.register(cx.waker()); + Poll::<()>::Pending + }) + .await; +} + #[hermit_macro::system] #[unsafe(no_mangle)] pub extern "C" fn sys_load_binary(ptr: *const u8, len: usize) -> i32 { @@ -277,6 +296,8 @@ pub extern "C" fn sys_load_binary(ptr: *const u8, len: usize) -> i32 { let _ = wasm_manager.call_func::<(), ()>("hello_world", ()); } + spawn(wasm_run()); + 0 } From f3a39afd02d65e57cef0beda1e52914201b40cab Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Thu, 24 Jul 2025 16:54:52 +0200 Subject: [PATCH 14/24] using IO interface instead calling the console --- src/executor/mod.rs | 2 +- src/wasm/mod.rs | 30 +++++++++++++++++++++--------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/executor/mod.rs b/src/executor/mod.rs index 04d4a73b59..f52c9f890b 100644 --- a/src/executor/mod.rs +++ b/src/executor/mod.rs @@ -113,7 +113,7 @@ pub(crate) fn run() { )] pub(crate) fn spawn(future: F) where - F: Future + Send + 'static, + F: Future + 'static, { core_local::ex().spawn(AsyncTask::new(future)).detach(); } diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs index 56884a9f5e..865b05fab2 100644 --- a/src/wasm/mod.rs +++ b/src/wasm/mod.rs @@ -10,8 +10,8 @@ use wasi::*; use wasmtime::*; use zerocopy::IntoBytes; -use crate::console::CONSOLE; use crate::executor::{WakerRegistration, spawn}; +use crate::fd; use crate::kernel::systemtime::now_micros; mod capi; @@ -271,15 +271,27 @@ pub extern "C" fn sys_unload_binary() -> i32 { } async fn wasm_run() { - future::poll_fn(|cx| { - let mut guard = OUTPUT.lock(); - while let Some(data) = guard.data.pop_front() { - CONSOLE.lock().write(&data); + loop { + let obj = crate::core_scheduler() + .get_object(fd::STDOUT_FILENO) + .await + .unwrap(); + + while let Some(data) = OUTPUT.lock().data.pop_front() { + obj.write(&data).await.unwrap(); } - guard.waker.register(cx.waker()); - Poll::<()>::Pending - }) - .await; + + future::poll_fn(|cx| { + let mut guard = OUTPUT.lock(); + if guard.data.is_empty() { + guard.waker.register(cx.waker()); + Poll::Pending + } else { + Poll::Ready(()) + } + }) + .await; + } } #[hermit_macro::system] From 5bfb7c1ac11ec0afbd9785e8cc0dab5a19e0ff13 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Thu, 24 Jul 2025 20:11:35 +0200 Subject: [PATCH 15/24] revise interface to allocate physical / virtual memory regions --- src/wasm/capi.rs | 40 ++++++++++++++++++++++++++++++++++------ src/wasm/mod.rs | 1 - 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/wasm/capi.rs b/src/wasm/capi.rs index fb479d1092..20fac44d7e 100644 --- a/src/wasm/capi.rs +++ b/src/wasm/capi.rs @@ -1,6 +1,7 @@ use align_address::Align; +use free_list::{PageLayout, PageRange}; use hermit_sync::InterruptTicketMutex; -use memory_addresses::VirtAddr; +use memory_addresses::{PhysAddr, VirtAddr}; use crate::arch; #[cfg(target_arch = "x86_64")] @@ -93,12 +94,22 @@ pub extern "C" fn wasmtime_page_size() -> usize { #[unsafe(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 = crate::mm::virtualmem::allocate(size).unwrap(); + let layout = PageLayout::from_size(size).unwrap(); + let page_range = crate::mm::virtualmem::KERNEL_FREE_LIST + .lock() + .allocate(layout) + .unwrap(); + let virtual_address = VirtAddr::from(page_range.start()); if prot_flags.is_empty() { *ret = virtual_address.as_mut_ptr(); return 0; } - let physical_address = crate::mm::physicalmem::allocate(size).unwrap(); + let frame_layout = PageLayout::from_size(size).unwrap(); + let frame_range = crate::mm::physicalmem::PHYSICAL_FREE_LIST + .lock() + .allocate(frame_layout) + .expect("Failed to allocate Physical Memory for wasmtime"); + let physical_address = PhysAddr::from(frame_range.start()); let count = size / BasePageSize::SIZE as usize; let mut flags = PageTableEntryFlags::empty(); @@ -151,10 +162,22 @@ pub extern "C" fn wasmtime_munmap(ptr: *mut u8, size: usize) -> i32 { virtual_address, size / BasePageSize::SIZE as usize, ); - crate::mm::physicalmem::deallocate(phys_addr, size); + let range = PageRange::from_start_len(phys_addr.as_usize(), size).unwrap(); + unsafe { + crate::mm::physicalmem::PHYSICAL_FREE_LIST + .lock() + .deallocate(range) + .unwrap(); + } } - crate::mm::virtualmem::deallocate(virtual_address, size); + let range = PageRange::from_start_len(virtual_address.as_usize(), size).unwrap(); + unsafe { + crate::mm::virtualmem::KERNEL_FREE_LIST + .lock() + .deallocate(range) + .unwrap(); + } 0 } @@ -183,7 +206,12 @@ pub extern "C" fn wasmtime_mprotect(ptr: *mut u8, size: usize, prot_flags: WasmP arch::mm::paging::map::(virtual_address, physical_address, count, flags); 0 } else { - let physical_address = crate::mm::physicalmem::allocate(size).unwrap(); + let frame_layout = PageLayout::from_size(size).unwrap(); + let frame_range = crate::mm::physicalmem::PHYSICAL_FREE_LIST + .lock() + .allocate(frame_layout) + .expect("Failed to allocate Physical Memory for TaskStacks"); + let physical_address = PhysAddr::from(frame_range.start()); arch::mm::paging::map::(virtual_address, physical_address, count, flags); 0 } diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs index 865b05fab2..ff4f82a853 100644 --- a/src/wasm/mod.rs +++ b/src/wasm/mod.rs @@ -274,7 +274,6 @@ async fn wasm_run() { loop { let obj = crate::core_scheduler() .get_object(fd::STDOUT_FILENO) - .await .unwrap(); while let Some(data) = OUTPUT.lock().data.pop_front() { From d288c3d44908e65ff4312ff6f411adf7076ae420 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sat, 26 Jul 2025 08:11:32 +0200 Subject: [PATCH 16/24] extend linker to run C programs in kernel space --- src/wasm/mod.rs | 172 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 171 insertions(+), 1 deletion(-) diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs index ff4f82a853..ce441c6a72 100644 --- a/src/wasm/mod.rs +++ b/src/wasm/mod.rs @@ -5,7 +5,7 @@ use core::hint::black_box; use core::mem::MaybeUninit; use core::task::Poll; -use hermit_sync::InterruptTicketMutex; +use hermit_sync::{InterruptTicketMutex, Lazy}; use wasi::*; use wasmtime::*; use zerocopy::IntoBytes; @@ -25,6 +25,9 @@ fn native_fibonacci(n: u64) -> u64 { } } +#[inline(never)] +fn native_foo() {} + pub fn measure_fibonacci(n: u64) { const RUNS: u64 = 100; info!("Measure native_fibonacci({})", n); @@ -73,6 +76,7 @@ pub(crate) struct WasmManager { impl WasmManager { pub fn new(data: &[u8]) -> Self { + static MODULE_AND_ARGS: Lazy> = Lazy::new(|| vec![b"dummy\0"]); let mut config: Config = Config::new(); config.memory_init_cow(false); config.memory_guard_size(8192); @@ -235,6 +239,122 @@ impl WasmManager { }, ) .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "args_get", + |mut caller: Caller<'_, _>, argv_ptr: i32, argv_buf_ptr: i32| { + if let Some(Extern::Memory(mem)) = caller.get_export("memory") { + let mut pos: u32 = argv_buf_ptr as u32; + for (i, element) in MODULE_AND_ARGS.iter().enumerate() { + let _ = mem.write( + caller.as_context_mut(), + (argv_ptr + (i * size_of::()) as i32) + .try_into() + .unwrap(), + pos.as_bytes(), + ); + + let _ = mem.write( + caller.as_context_mut(), + pos.try_into().unwrap(), + element, + ); + + pos += element.len() as u32; + } + } + ERRNO_SUCCESS.raw() as i32 + }, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "args_sizes_get", + move |mut caller: Caller<'_, _>, number_args_ptr: i32, args_size_ptr: i32| { + let nargs: u32 = MODULE_AND_ARGS.len().try_into().unwrap(); + // Currently, we ignore the arguments + if let Some(Extern::Memory(mem)) = caller.get_export("memory") { + let _ = mem.write( + caller.as_context_mut(), + number_args_ptr.try_into().unwrap(), + nargs.as_bytes(), + ); + + let nargs_size: u32 = MODULE_AND_ARGS + .iter() + .fold(0, |acc, arg| acc + arg.len()) + .try_into() + .unwrap(); + let _ = mem.write( + caller.as_context_mut(), + args_size_ptr.try_into().unwrap(), + nargs_size.as_bytes(), + ); + + return ERRNO_SUCCESS.raw() as i32; + } + + ERRNO_INVAL.raw() as i32 + }, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "clock_time_get", + |mut caller: Caller<'_, _>, clock_id: i32, _precision: i64, timestamp_ptr: i32| { + match clock_id { + 0 => { + let usec = crate::arch::kernel::systemtime::now_micros(); + if let Some(Extern::Memory(mem)) = caller.get_export("memory") { + let nanos = usec * 1000; + let _ = mem.write( + caller.as_context_mut(), + timestamp_ptr.try_into().unwrap(), + nanos.as_bytes(), + ); + + return ERRNO_SUCCESS.raw() as i32; + } + + ERRNO_INVAL.raw() as i32 + } + 1 => { + warn!("Unsupported clock_id"); + ERRNO_INVAL.raw() as i32 + } + _ => ERRNO_INVAL.raw() as i32, + } + }, + ) + .unwrap(); + linker + .func_wrap("wasi_snapshot_preview1", "fd_close", |_fd: i32| { + ERRNO_SUCCESS.raw() as i32 + }) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "fd_fdstat_get", + |_: i32, _: i32| { + warn!("Unsupported function fd_fdstat_get"); + ERRNO_SUCCESS.raw() as i32 + }, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "fd_seek", + |_: i32, _: i64, _: i32, _: i32| { + warn!("Unsupported function fd_seek"); + ERRNO_SUCCESS.raw() as i32 + }, + ) + .unwrap(); linker .func_wrap("wasi_snapshot_preview1", "proc_exit", |_: i32| { error!("Panic in WASM module") @@ -298,10 +418,13 @@ async fn wasm_run() { pub extern "C" fn sys_load_binary(ptr: *const u8, len: usize) -> i32 { info!("Loading WebAssembly binary..."); + let start = now_micros(); let slice = unsafe { core::slice::from_raw_parts(ptr, len) }; let wasm_manager = WasmManager::new(slice); *WASM_MANAGER.lock() = Some(wasm_manager); + let end = now_micros(); + info!("Time to initiate WASM module {} usec", end - start); if let Some(ref mut wasm_manager) = crate::wasm::WASM_MANAGER.lock().as_mut() { let _ = wasm_manager.call_func::<(), ()>("hello_world", ()); @@ -312,6 +435,53 @@ pub extern "C" fn sys_load_binary(ptr: *const u8, len: usize) -> i32 { 0 } +#[hermit_macro::system] +#[unsafe(no_mangle)] +pub extern "C" fn sys_dhrystone() -> i32 { + if let Some(ref mut wasm_manager) = WASM_MANAGER.lock().as_mut() { + // And finally we can call the wasm function + info!("Call function dhrystone"); + let _result = wasm_manager.call_func::<(), ()>("_start", ()).unwrap(); + } + + 0 +} + +#[hermit_macro::system] +#[unsafe(no_mangle)] +pub extern "C" fn sys_foo() -> i32 { + if let Some(ref mut wasm_manager) = WASM_MANAGER.lock().as_mut() { + // And finally we can call the wasm function + info!("Call function foo"); + let _result = wasm_manager.call_func::<(), ()>("foo", ()).unwrap(); + + const RUNS: u64 = 1000000; + let start = now_micros(); + for _ in 0..RUNS { + black_box(wasm_manager.call_func::<(), ()>("foo", ()).unwrap()); + } + let end = now_micros(); + info!( + "Average time to call the WASM function foo: {} nsec", + (1000 * (end - start)) / RUNS + ); + + let start = now_micros(); + for _ in 0..RUNS { + black_box(native_foo()); + } + let end = now_micros(); + + info!( + "Time to call {} times the function foo: {} nsec", + RUNS, + 1000 * (end - start) + ); + } + + 0 +} + #[hermit_macro::system] #[unsafe(no_mangle)] pub extern "C" fn sys_fibonacci() -> i32 { From 6e2a3fbd06eadf35a0a12498c89a68d356f911ab Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 28 Jul 2025 19:03:28 +0200 Subject: [PATCH 17/24] allow WASM to write data in a file --- src/wasm/mod.rs | 254 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 233 insertions(+), 21 deletions(-) diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs index ce441c6a72..e0a52bf22b 100644 --- a/src/wasm/mod.rs +++ b/src/wasm/mod.rs @@ -1,5 +1,8 @@ +use alloc::borrow::ToOwned; use alloc::collections::VecDeque; +use alloc::string::String; use alloc::vec::Vec; +use core::ffi::CStr; use core::future; use core::hint::black_box; use core::mem::MaybeUninit; @@ -11,7 +14,7 @@ use wasmtime::*; use zerocopy::IntoBytes; use crate::executor::{WakerRegistration, spawn}; -use crate::fd; +use crate::fd::{self, remove_object}; use crate::kernel::systemtime::now_micros; mod capi; @@ -44,14 +47,47 @@ pub fn measure_fibonacci(n: u64) { ); } +#[derive(Debug, Clone, PartialEq)] +enum Descriptor { + None, + Stdin, + Stdout, + Stderr, + Directory(String), + RawFd(fd::FileDescriptor), +} + +impl Descriptor { + #[inline] + pub fn is_none(&self) -> bool { + *self == Self::None + } +} + +bitflags! { + /// Options for opening files + #[derive(Debug, Copy, Clone, Default)] + pub(crate) struct Oflags: i32 { + /// Create file if it does not exist. + const OFLAGS_CREAT = 1 << 0; + /// Fail if not a directory. + const OFLAGS_DIRECTORY = 1 << 1; + /// Fail if file already exists. + const OFLAGS_EXCL = 1 << 2; + /// Truncate file to size 0. + const OFLAGS_TRUNC = 1 << 3; + } +} + pub(crate) static WASM_MANAGER: InterruptTicketMutex> = InterruptTicketMutex::new(None); pub(crate) static INPUT: InterruptTicketMutex>> = InterruptTicketMutex::new(VecDeque::new()); static OUTPUT: InterruptTicketMutex = InterruptTicketMutex::new(WasmStdout::new()); +static FD: InterruptTicketMutex> = InterruptTicketMutex::new(Vec::new()); struct WasmStdout { - pub data: VecDeque>, + pub data: VecDeque<(Descriptor, Vec)>, pub waker: WakerRegistration, } @@ -63,8 +99,8 @@ impl WasmStdout { } } - pub fn write(&mut self, buf: &[u8]) { - self.data.push_back(buf.to_vec()); + pub fn write(&mut self, desc: &Descriptor, buf: &[u8]) { + self.data.push_back((desc.clone(), buf.to_vec())); self.waker.wake(); } } @@ -91,6 +127,80 @@ impl WasmManager { crate::arch::kernel::systemtime::now_micros() }) .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "path_open", + |mut caller: Caller<'_, _>, + _fd: i32, + _dirflags: i32, + path_ptr: i32, + path_len: i32, + oflags: i32, + _fs_rights_base: Rights, + _fs_rights_inheriting: Rights, + _fdflags: i32, + fd_ptr: i32| { + let oflags = Oflags::from_bits(oflags).unwrap(); + if let Some(Extern::Memory(mem)) = caller.get_export("memory") { + let mut path = vec![0u8; path_len.try_into().unwrap()]; + + let _ = mem.read( + caller.as_context_mut(), + path_ptr.try_into().unwrap(), + path.as_mut_bytes(), + ); + let path = "/".to_owned() + str::from_utf8(&path).unwrap(); + + let mut flags = fd::OpenOption::empty(); + if oflags.contains(Oflags::OFLAGS_CREAT) { + flags |= fd::OpenOption::O_CREAT; + } + if oflags.contains(Oflags::OFLAGS_TRUNC) { + flags |= fd::OpenOption::O_TRUNC; + } + flags |= fd::OpenOption::O_RDWR; + + let mode = fd::AccessPermission::from_bits(0).unwrap(); + let mut c_path = vec![0u8; path.len() + 1]; + c_path[..path.len()].copy_from_slice(path.as_bytes()); + let path = CStr::from_bytes_until_nul(&c_path) + .unwrap() + .to_str() + .unwrap(); + { + let raw_fd = crate::fs::open(path, flags, mode).unwrap(); + let mut guard = FD.lock(); + for (i, entry) in guard.iter_mut().enumerate() { + if entry.is_none() { + *entry = Descriptor::RawFd(raw_fd); + let _ = mem.write( + caller.as_context_mut(), + fd_ptr.try_into().unwrap(), + i.as_bytes(), + ); + + guard.push(Descriptor::RawFd(raw_fd)); + + return ERRNO_SUCCESS.raw() as i32; + } + } + + let new_fd: i32 = (guard.len() - 1).try_into().unwrap(); + let _ = mem.write( + caller.as_context_mut(), + fd_ptr.try_into().unwrap(), + new_fd.as_bytes(), + ); + } + + return ERRNO_SUCCESS.raw() as i32; + } + + ERRNO_INVAL.raw() as i32 + }, + ) + .unwrap(); linker .func_wrap( "wasi_snapshot_preview1", @@ -148,10 +258,17 @@ impl WasmManager { "wasi_snapshot_preview1", "fd_write", |mut caller: Caller<'_, u32>, - _fd: i32, + fd: i32, iovs_ptr: i32, iovs_len: i32, nwritten_ptr: i32| { + let desc = match fd { + fd::STDIN_FILENO => Descriptor::Stdin, + fd::STDOUT_FILENO => Descriptor::Stdout, + fd::STDERR_FILENO => Descriptor::Stderr, + _ => Descriptor::RawFd(fd), + }; + if let Some(Extern::Memory(mem)) = caller.get_export("memory") { let mut iovs = vec![0i32; (2 * iovs_len).try_into().unwrap()]; let _ = mem.read( @@ -182,7 +299,9 @@ impl WasmManager { iovs[i].try_into().unwrap(), unsafe { data.assume_init_mut() }, ); - OUTPUT.lock().write(unsafe { data.assume_init_mut() }); + OUTPUT + .lock() + .write(&desc, unsafe { data.assume_init_mut() }); nwritten_bytes += len; i += 2; @@ -300,6 +419,43 @@ impl WasmManager { }, ) .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "fd_prestat_get", + |mut caller: Caller<'_, _>, fd: i32, prestat_ptr: i32| { + let guard = FD.lock(); + if fd < guard.len().try_into().unwrap() + && let Some(Extern::Memory(mem)) = caller.get_export("memory") + && let Descriptor::Directory(name) = &guard[fd as usize] + { + let stat = Prestat { + tag: PREOPENTYPE_DIR.raw(), + u: PrestatU { + dir: PrestatDir { + pr_name_len: name.len(), + }, + }, + }; + + let _ = mem.write( + caller.as_context_mut(), + prestat_ptr.try_into().unwrap(), + unsafe { + core::slice::from_raw_parts( + (&stat as *const _) as *const u8, + size_of::(), + ) + }, + ); + + return ERRNO_SUCCESS.raw() as i32; + } + + ERRNO_BADF.raw() as i32 + }, + ) + .unwrap(); linker .func_wrap( "wasi_snapshot_preview1", @@ -331,7 +487,46 @@ impl WasmManager { ) .unwrap(); linker - .func_wrap("wasi_snapshot_preview1", "fd_close", |_fd: i32| { + .func_wrap( + "wasi_snapshot_preview1", + "fd_prestat_dir_name", + |mut caller: Caller<'_, _>, fd: i32, path_ptr: i32, path_len: i32| { + let guard = FD.lock(); + if fd < guard.len().try_into().unwrap() + && let Descriptor::Directory(path) = &guard[fd as usize] + { + if let Some(Extern::Memory(mem)) = caller.get_export( + "memory +", + ) { + if path_len < path.len().try_into().unwrap() { + return ERRNO_INVAL.raw() as i32; + } + + let _ = mem.write( + caller.as_context_mut(), + path_ptr.try_into().unwrap(), + path.as_bytes(), + ); + } + + return ERRNO_SUCCESS.raw() as i32; + } + + ERRNO_BADF.raw() as i32 + }, + ) + .unwrap(); + linker + .func_wrap("wasi_snapshot_preview1", "fd_close", |fd: i32| { + let mut guard = FD.lock(); + if fd < guard.len().try_into().unwrap() + && let Descriptor::RawFd(os_fd) = guard[fd as usize] + { + let _obj = remove_object(os_fd); + guard[fd as usize] = Descriptor::None; + } + ERRNO_SUCCESS.raw() as i32 }) .unwrap(); @@ -382,21 +577,20 @@ impl WasmManager { } } -#[hermit_macro::system] -#[unsafe(no_mangle)] -pub extern "C" fn sys_unload_binary() -> i32 { - *WASM_MANAGER.lock() = None; - - 0 -} - async fn wasm_run() { loop { - let obj = crate::core_scheduler() - .get_object(fd::STDOUT_FILENO) - .unwrap(); + while let Some((fd, data)) = OUTPUT.lock().data.pop_front() { + let obj = match fd { + Descriptor::Stdout => crate::core_scheduler() + .get_object(fd::STDOUT_FILENO) + .unwrap(), + Descriptor::Stderr => crate::core_scheduler() + .get_object(fd::STDERR_FILENO) + .unwrap(), + Descriptor::RawFd(raw_fd) => crate::core_scheduler().get_object(raw_fd).unwrap(), + _ => panic!("Unsuppted {fd:?}"), + }; - while let Some(data) = OUTPUT.lock().data.pop_front() { obj.write(&data).await.unwrap(); } @@ -426,15 +620,33 @@ pub extern "C" fn sys_load_binary(ptr: *const u8, len: usize) -> i32 { let end = now_micros(); info!("Time to initiate WASM module {} usec", end - start); - if let Some(ref mut wasm_manager) = crate::wasm::WASM_MANAGER.lock().as_mut() { - let _ = wasm_manager.call_func::<(), ()>("hello_world", ()); + { + let mut guard = FD.lock(); + guard.push(Descriptor::Stdin); + guard.push(Descriptor::Stdout); + guard.push(Descriptor::Stderr); + guard.push(Descriptor::Directory(String::from("tmp"))); + guard.push(Descriptor::Directory(String::from("root"))); } + /*if let Some(ref mut wasm_manager) = crate::wasm::WASM_MANAGER.lock().as_mut() { + let _ = wasm_manager.call_func::<(), ()>("hello_world", ()); + }*/ + spawn(wasm_run()); 0 } +#[hermit_macro::system] +#[unsafe(no_mangle)] +pub extern "C" fn sys_unload_binary() -> i32 { + *WASM_MANAGER.lock() = None; + FD.lock().clear(); + + 0 +} + #[hermit_macro::system] #[unsafe(no_mangle)] pub extern "C" fn sys_dhrystone() -> i32 { From 3c6a0e6cff36fbef7e170ac74e82a24cd3218143 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 28 Jul 2025 22:40:03 +0200 Subject: [PATCH 18/24] remove blocking locks in async tasks otherwise, within an interrupt handler isn't possible to poll a network device. --- src/executor/network.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/executor/network.rs b/src/executor/network.rs index 0b07ed6e1f..272a095d88 100644 --- a/src/executor/network.rs +++ b/src/executor/network.rs @@ -182,7 +182,7 @@ async fn dhcpv4_run() { nic.dns_handle = None; } } - }; + } Poll::<()>::Pending }) @@ -229,7 +229,7 @@ pub(crate) async fn get_query_result(query: QueryHandle) -> io::Result { socket.register_query_waker(query, cx.waker()); From d3a598d738bc2dfd0dd58ea175ccf1e3ba750754 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sun, 31 Aug 2025 12:33:58 +0200 Subject: [PATCH 19/24] avoid the usage of blocking spinlock by polling the wasm interface --- src/executor/mod.rs | 2 +- src/executor/network.rs | 4 ++-- src/wasm/mod.rs | 47 +++++++++++++++++++++++------------------ 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/executor/mod.rs b/src/executor/mod.rs index f52c9f890b..714641c326 100644 --- a/src/executor/mod.rs +++ b/src/executor/mod.rs @@ -113,7 +113,7 @@ pub(crate) fn run() { )] pub(crate) fn spawn(future: F) where - F: Future + 'static, + F: Future + 'static + core::marker::Send, { core_local::ex().spawn(AsyncTask::new(future)).detach(); } diff --git a/src/executor/network.rs b/src/executor/network.rs index 272a095d88..0b07ed6e1f 100644 --- a/src/executor/network.rs +++ b/src/executor/network.rs @@ -182,7 +182,7 @@ async fn dhcpv4_run() { nic.dns_handle = None; } } - } + }; Poll::<()>::Pending }) @@ -229,7 +229,7 @@ pub(crate) async fn get_query_result(query: QueryHandle) -> io::Result { socket.register_query_waker(query, cx.waker()); diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs index e0a52bf22b..62cf01f90e 100644 --- a/src/wasm/mod.rs +++ b/src/wasm/mod.rs @@ -6,6 +6,7 @@ use core::ffi::CStr; use core::future; use core::hint::black_box; use core::mem::MaybeUninit; +use core::pin::pin; use core::task::Poll; use hermit_sync::{InterruptTicketMutex, Lazy}; @@ -579,28 +580,34 @@ impl WasmManager { async fn wasm_run() { loop { - while let Some((fd, data)) = OUTPUT.lock().data.pop_front() { - let obj = match fd { - Descriptor::Stdout => crate::core_scheduler() - .get_object(fd::STDOUT_FILENO) - .unwrap(), - Descriptor::Stderr => crate::core_scheduler() - .get_object(fd::STDERR_FILENO) - .unwrap(), - Descriptor::RawFd(raw_fd) => crate::core_scheduler().get_object(raw_fd).unwrap(), - _ => panic!("Unsuppted {fd:?}"), - }; - - obj.write(&data).await.unwrap(); - } - future::poll_fn(|cx| { - let mut guard = OUTPUT.lock(); - if guard.data.is_empty() { - guard.waker.register(cx.waker()); - Poll::Pending + if let Some(mut guard) = OUTPUT.try_lock() { + if let Some((fd, data)) = guard.data.pop_front() { + let obj = match fd { + Descriptor::Stdout => crate::core_scheduler() + .get_object(fd::STDOUT_FILENO) + .unwrap(), + Descriptor::Stderr => crate::core_scheduler() + .get_object(fd::STDERR_FILENO) + .unwrap(), + Descriptor::RawFd(raw_fd) => { + crate::core_scheduler().get_object(raw_fd).unwrap() + } + _ => panic!("Unsuppted {fd:?}"), + }; + + drop(guard); + while let Poll::Pending = pin!(obj.write(&data)).poll(cx) {} + + cx.waker().wake_by_ref(); + Poll::<()>::Pending + } else { + guard.waker.register(cx.waker()); + Poll::<()>::Pending + } } else { - Poll::Ready(()) + cx.waker().wake_by_ref(); + Poll::<()>::Pending } }) .await; From 15de9243d12b498495c75424defa467df7db36dc Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 1 Sep 2025 11:21:57 +0200 Subject: [PATCH 20/24] using try_lock instead of lock - offers the option for a nested call of block_on --- src/executor/mod.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/executor/mod.rs b/src/executor/mod.rs index 714641c326..c0820a2488 100644 --- a/src/executor/mod.rs +++ b/src/executor/mod.rs @@ -169,19 +169,18 @@ where { if let Some(mut guard) = crate::executor::network::NIC.try_lock() { let delay = if let Ok(nic) = guard.as_nic_mut() { + nic.set_polling_mode(false); + nic.poll_delay(Instant::from_micros_const(now.try_into().unwrap())) .map(|d| d.total_micros()) } else { None }; + core_local::core_scheduler().add_network_timer( delay.map(|d| crate::arch::processor::get_timer_ticks() + d), ); } - - if let Ok(device) = crate::executor::network::NIC.lock().as_nic_mut() { - device.set_polling_mode(false); - } } return t; From fb6213c4c7ddec0b836f55f5283852b61ea2d30e Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 1 Sep 2025 11:24:47 +0200 Subject: [PATCH 21/24] call wasm function to trace the network traffic --- src/drivers/net/virtio/mod.rs | 14 +++++++++ src/wasm/mod.rs | 54 +++++++++++++++++------------------ 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/src/drivers/net/virtio/mod.rs b/src/drivers/net/virtio/mod.rs index 86397e8f05..28babb25ac 100644 --- a/src/drivers/net/virtio/mod.rs +++ b/src/drivers/net/virtio/mod.rs @@ -265,6 +265,12 @@ impl smoltcp::phy::TxToken for TxToken<'_> { result }; + #[cfg(feature = "wasm")] + if let Some(ref mut wasm_manager) = crate::wasm::WASM_MANAGER.lock().as_mut() { + crate::wasm::INPUT.lock().push_back(packet.to_vec()); + let _ = wasm_manager.call_func::<(), ()>("pcap_writer", ()); + } + let mut header = Box::new_in(::default(), DeviceAlloc); // If a checksum calculation by the host is necessary, we have to inform the host within the header @@ -361,6 +367,14 @@ impl smoltcp::phy::RxToken for RxToken<'_> { .unwrap(); } + #[cfg(feature = "wasm")] + if let Some(ref mut wasm_manager) = crate::wasm::WASM_MANAGER.lock().as_mut() { + crate::wasm::INPUT + .lock() + .push_back(combined_packets.to_vec()); + let _ = wasm_manager.call_func::<(), ()>("pcap_writer", ()); + } + f(&combined_packets) } } diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs index 62cf01f90e..421dca39b3 100644 --- a/src/wasm/mod.rs +++ b/src/wasm/mod.rs @@ -579,39 +579,37 @@ impl WasmManager { } async fn wasm_run() { - loop { - future::poll_fn(|cx| { - if let Some(mut guard) = OUTPUT.try_lock() { - if let Some((fd, data)) = guard.data.pop_front() { - let obj = match fd { - Descriptor::Stdout => crate::core_scheduler() - .get_object(fd::STDOUT_FILENO) - .unwrap(), - Descriptor::Stderr => crate::core_scheduler() - .get_object(fd::STDERR_FILENO) - .unwrap(), - Descriptor::RawFd(raw_fd) => { - crate::core_scheduler().get_object(raw_fd).unwrap() - } - _ => panic!("Unsuppted {fd:?}"), - }; + future::poll_fn(|cx| { + if let Some(mut guard) = OUTPUT.try_lock() { + if let Some((fd, data)) = guard.data.pop_front() { + let obj = match fd { + Descriptor::Stdout => crate::core_scheduler() + .get_object(fd::STDOUT_FILENO) + .unwrap(), + Descriptor::Stderr => crate::core_scheduler() + .get_object(fd::STDERR_FILENO) + .unwrap(), + Descriptor::RawFd(raw_fd) => { + crate::core_scheduler().get_object(raw_fd).unwrap() + } + _ => panic!("Unsuppted {fd:?}"), + }; - drop(guard); - while let Poll::Pending = pin!(obj.write(&data)).poll(cx) {} + drop(guard); + while let Poll::Pending = pin!(obj.write(&data)).poll(cx) {} - cx.waker().wake_by_ref(); - Poll::<()>::Pending - } else { - guard.waker.register(cx.waker()); - Poll::<()>::Pending - } - } else { cx.waker().wake_by_ref(); Poll::<()>::Pending + } else { + guard.waker.register(cx.waker()); + Poll::<()>::Pending } - }) - .await; - } + } else { + cx.waker().wake_by_ref(); + Poll::<()>::Pending + } + }) + .await; } #[hermit_macro::system] From d9aa35e67e5b8943d4fe6f9fac2126b1a041a105 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 1 Sep 2025 22:41:12 +0200 Subject: [PATCH 22/24] remove clippy warnings and some typos --- src/arch/aarch64/kernel/mod.rs | 2 - src/executor/mod.rs | 8 +++- src/wasm/mod.rs | 74 +++++++++++++++++----------------- 3 files changed, 45 insertions(+), 39 deletions(-) diff --git a/src/arch/aarch64/kernel/mod.rs b/src/arch/aarch64/kernel/mod.rs index 05992ac6b9..49b8d0b9ec 100644 --- a/src/arch/aarch64/kernel/mod.rs +++ b/src/arch/aarch64/kernel/mod.rs @@ -31,8 +31,6 @@ use crate::arch::aarch64::mm::paging::{BasePageSize, PageSize}; use crate::config::*; use crate::env; -const SERIAL_PORT_BAUDRATE: u32 = 115_200; - global_asm!(include_str!("setjmp.s")); global_asm!(include_str!("longjmp.s")); diff --git a/src/executor/mod.rs b/src/executor/mod.rs index c0820a2488..65335cfb46 100644 --- a/src/executor/mod.rs +++ b/src/executor/mod.rs @@ -108,7 +108,13 @@ pub(crate) fn run() { /// Spawns a future on the executor. #[cfg_attr( - not(any(feature = "shell", feature = "tcp", feature = "udp", feature = "vsock")), + not(any( + feature = "shell", + feature = "tcp", + feature = "udp", + feature = "vsock", + feature = "wasm" + )), expect(dead_code) )] pub(crate) fn spawn(future: F) diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs index 421dca39b3..2c125a5454 100644 --- a/src/wasm/mod.rs +++ b/src/wasm/mod.rs @@ -34,7 +34,7 @@ fn native_foo() {} pub fn measure_fibonacci(n: u64) { const RUNS: u64 = 100; - info!("Measure native_fibonacci({})", n); + info!("Measure native_fibonacci({n})"); let start = now_micros(); for _ in 0..RUNS { @@ -183,7 +183,7 @@ impl WasmManager { guard.push(Descriptor::RawFd(raw_fd)); - return ERRNO_SUCCESS.raw() as i32; + return i32::from(ERRNO_SUCCESS.raw()); } } @@ -195,10 +195,10 @@ impl WasmManager { ); } - return ERRNO_SUCCESS.raw() as i32; + return i32::from(ERRNO_SUCCESS.raw()); } - ERRNO_INVAL.raw() as i32 + i32::from(ERRNO_INVAL.raw()) }, ) .unwrap(); @@ -247,10 +247,10 @@ impl WasmManager { nread_bytes.as_bytes(), ); - return ERRNO_SUCCESS.raw() as i32; + return i32::from(ERRNO_SUCCESS.raw()); } - ERRNO_INVAL.raw() as i32 + i32::from(ERRNO_INVAL.raw()) }, ) .unwrap(); @@ -314,10 +314,10 @@ impl WasmManager { nwritten_bytes.as_bytes(), ); - return ERRNO_SUCCESS.raw() as i32; + return i32::from(ERRNO_SUCCESS.raw()); } - ERRNO_INVAL.raw() as i32 + i32::from(ERRNO_INVAL.raw()) }, ) .unwrap(); @@ -326,7 +326,7 @@ impl WasmManager { "wasi_snapshot_preview1", "environ_get", |mut _caller: Caller<'_, _>, _env_ptr: i32, _env_buffer_ptr: i32| { - ERRNO_SUCCESS.raw() as i32 + i32::from(ERRNO_SUCCESS.raw()) }, ) .unwrap(); @@ -339,12 +339,12 @@ impl WasmManager { env_buffer_size_ptr: i32| { if let Some(Extern::Memory(mem)) = caller.get_export("memory") { let env_buffer_size: u32 = 0; - let nnumber_env_variables: u32 = 0; + let number_env_variables: u32 = 0; let _ = mem.write( caller.as_context_mut(), number_env_variables_ptr.try_into().unwrap(), - nnumber_env_variables.as_bytes(), + number_env_variables.as_bytes(), ); let _ = mem.write( caller.as_context_mut(), @@ -352,10 +352,10 @@ impl WasmManager { env_buffer_size.as_bytes(), ); - return ERRNO_SUCCESS.raw() as i32; + return i32::from(ERRNO_SUCCESS.raw()); } - ERRNO_INVAL.raw() as i32 + i32::from(ERRNO_INVAL.raw()) }, ) .unwrap(); @@ -384,7 +384,7 @@ impl WasmManager { pos += element.len() as u32; } } - ERRNO_SUCCESS.raw() as i32 + i32::from(ERRNO_SUCCESS.raw()) }, ) .unwrap(); @@ -413,10 +413,10 @@ impl WasmManager { nargs_size.as_bytes(), ); - return ERRNO_SUCCESS.raw() as i32; + return i32::from(ERRNO_SUCCESS.raw()); } - ERRNO_INVAL.raw() as i32 + i32::from(ERRNO_INVAL.raw()) }, ) .unwrap(); @@ -444,16 +444,16 @@ impl WasmManager { prestat_ptr.try_into().unwrap(), unsafe { core::slice::from_raw_parts( - (&stat as *const _) as *const u8, + (&raw const stat).cast::(), size_of::(), ) }, ); - return ERRNO_SUCCESS.raw() as i32; + return i32::from(ERRNO_SUCCESS.raw()); } - ERRNO_BADF.raw() as i32 + i32::from(ERRNO_BADF.raw()) }, ) .unwrap(); @@ -473,16 +473,16 @@ impl WasmManager { nanos.as_bytes(), ); - return ERRNO_SUCCESS.raw() as i32; + return i32::from(ERRNO_SUCCESS.raw()); } - ERRNO_INVAL.raw() as i32 + i32::from(ERRNO_INVAL.raw()) } 1 => { warn!("Unsupported clock_id"); - ERRNO_INVAL.raw() as i32 + i32::from(ERRNO_INVAL.raw()) } - _ => ERRNO_INVAL.raw() as i32, + _ => i32::from(ERRNO_INVAL.raw()), } }, ) @@ -501,7 +501,7 @@ impl WasmManager { ", ) { if path_len < path.len().try_into().unwrap() { - return ERRNO_INVAL.raw() as i32; + return i32::from(ERRNO_INVAL.raw()); } let _ = mem.write( @@ -511,10 +511,10 @@ impl WasmManager { ); } - return ERRNO_SUCCESS.raw() as i32; + return i32::from(ERRNO_SUCCESS.raw()); } - ERRNO_BADF.raw() as i32 + i32::from(ERRNO_BADF.raw()) }, ) .unwrap(); @@ -528,7 +528,7 @@ impl WasmManager { guard[fd as usize] = Descriptor::None; } - ERRNO_SUCCESS.raw() as i32 + i32::from(ERRNO_SUCCESS.raw()) }) .unwrap(); linker @@ -537,7 +537,7 @@ impl WasmManager { "fd_fdstat_get", |_: i32, _: i32| { warn!("Unsupported function fd_fdstat_get"); - ERRNO_SUCCESS.raw() as i32 + i32::from(ERRNO_SUCCESS.raw()) }, ) .unwrap(); @@ -547,13 +547,13 @@ impl WasmManager { "fd_seek", |_: i32, _: i64, _: i32, _: i32| { warn!("Unsupported function fd_seek"); - ERRNO_SUCCESS.raw() as i32 + i32::from(ERRNO_SUCCESS.raw()) }, ) .unwrap(); linker .func_wrap("wasi_snapshot_preview1", "proc_exit", |_: i32| { - error!("Panic in WASM module") + error!("Panic in WASM module"); }) .unwrap(); @@ -596,7 +596,7 @@ async fn wasm_run() { }; drop(guard); - while let Poll::Pending = pin!(obj.write(&data)).poll(cx) {} + while pin!(obj.write(&data)).poll(cx).is_pending() {} cx.waker().wake_by_ref(); Poll::<()>::Pending @@ -658,7 +658,7 @@ pub extern "C" fn sys_dhrystone() -> i32 { if let Some(ref mut wasm_manager) = WASM_MANAGER.lock().as_mut() { // And finally we can call the wasm function info!("Call function dhrystone"); - let _result = wasm_manager.call_func::<(), ()>("_start", ()).unwrap(); + wasm_manager.call_func::<(), ()>("_start", ()).unwrap(); } 0 @@ -670,11 +670,12 @@ pub extern "C" fn sys_foo() -> i32 { if let Some(ref mut wasm_manager) = WASM_MANAGER.lock().as_mut() { // And finally we can call the wasm function info!("Call function foo"); - let _result = wasm_manager.call_func::<(), ()>("foo", ()).unwrap(); + wasm_manager.call_func::<(), ()>("foo", ()).unwrap(); - const RUNS: u64 = 1000000; + const RUNS: u64 = 1_000_000; let start = now_micros(); for _ in 0..RUNS { + #[allow(clippy::unit_arg)] black_box(wasm_manager.call_func::<(), ()>("foo", ()).unwrap()); } let end = now_micros(); @@ -685,6 +686,7 @@ pub extern "C" fn sys_foo() -> i32 { let start = now_micros(); for _ in 0..RUNS { + #[allow(clippy::unit_arg)] black_box(native_foo()); } let end = now_micros(); @@ -710,9 +712,9 @@ pub extern "C" fn sys_fibonacci() -> i32 { // And finally we can call the wasm function info!("Call function fibonacci"); let result = wasm_manager.call_func::("fibonacci", 30).unwrap(); - info!("fibonacci(30) = {}", result); + info!("fibonacci(30) = {result}"); assert!( - result == 832040, + result == 832_040, "Error in the calculation of fibonacci(30) " ); From 3738fc8f536c147712bd7f819b8d5f67dad44884 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Tue, 2 Sep 2025 11:17:39 +0200 Subject: [PATCH 23/24] disable code, which is only necessary to measure the performance of wasm --- src/wasm/mod.rs | 69 +++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs index 2c125a5454..ad56fa89d3 100644 --- a/src/wasm/mod.rs +++ b/src/wasm/mod.rs @@ -4,7 +4,6 @@ use alloc::string::String; use alloc::vec::Vec; use core::ffi::CStr; use core::future; -use core::hint::black_box; use core::mem::MaybeUninit; use core::pin::pin; use core::task::Poll; @@ -20,34 +19,6 @@ use crate::kernel::systemtime::now_micros; mod capi; -#[inline(never)] -fn native_fibonacci(n: u64) -> u64 { - match n { - 0 => 0, - 1 => 1, - _ => native_fibonacci(n - 1) + native_fibonacci(n - 2), - } -} - -#[inline(never)] -fn native_foo() {} - -pub fn measure_fibonacci(n: u64) { - const RUNS: u64 = 100; - info!("Measure native_fibonacci({n})"); - - let start = now_micros(); - for _ in 0..RUNS { - black_box(native_fibonacci(black_box(n))); - } - let end = now_micros(); - info!( - "Average time to call native_fibonacci({}): {} usec", - n, - (end - start) / RUNS - ); -} - #[derive(Debug, Clone, PartialEq)] enum Descriptor { None, @@ -106,6 +77,7 @@ impl WasmStdout { } } +#[allow(dead_code)] pub(crate) struct WasmManager { store: Store, instance: Instance, @@ -566,6 +538,7 @@ impl WasmManager { Self { store, instance } } + #[allow(dead_code)] pub fn call_func(&mut self, name: &str, arg: P) -> Result where P: wasmtime::WasmParams, @@ -652,7 +625,7 @@ pub extern "C" fn sys_unload_binary() -> i32 { 0 } -#[hermit_macro::system] +/*#[hermit_macro::system] #[unsafe(no_mangle)] pub extern "C" fn sys_dhrystone() -> i32 { if let Some(ref mut wasm_manager) = WASM_MANAGER.lock().as_mut() { @@ -667,6 +640,8 @@ pub extern "C" fn sys_dhrystone() -> i32 { #[hermit_macro::system] #[unsafe(no_mangle)] pub extern "C" fn sys_foo() -> i32 { + use core::hint::black_box; + if let Some(ref mut wasm_manager) = WASM_MANAGER.lock().as_mut() { // And finally we can call the wasm function info!("Call function foo"); @@ -701,9 +676,41 @@ pub extern "C" fn sys_foo() -> i32 { 0 } +#[inline(never)] +fn native_fibonacci(n: u64) -> u64 { + match n { + 0 => 0, + 1 => 1, + _ => native_fibonacci(n - 1) + native_fibonacci(n - 2), + } +} + +#[inline(never)] +fn native_foo() {} + +#[inline(never)] +fn measure_fibonacci(n: u64) { + use core::hint::black_box; + const RUNS: u64 = 100; + info!("Measure native_fibonacci({n})"); + + let start = now_micros(); + for _ in 0..RUNS { + black_box(native_fibonacci(black_box(n))); + } + let end = now_micros(); + info!( + "Average time to call native_fibonacci({}): {} usec", + n, + (end - start) / RUNS + ); +} + #[hermit_macro::system] #[unsafe(no_mangle)] pub extern "C" fn sys_fibonacci() -> i32 { + use core::hint::black_box; + info!("Try to find function fibonacci"); measure_fibonacci(30); @@ -741,4 +748,4 @@ pub extern "C" fn sys_fibonacci() -> i32 { } 0 -} +}*/ From 0f26efdc8c25d0213ddfc0e3cb780b09064a01e4 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Tue, 2 Sep 2025 20:40:55 +0200 Subject: [PATCH 24/24] define wasi as optional - only the feature wasm depends on wasi --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 858e0e0918..fbf0d395fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,7 +76,7 @@ vga = [] virtio = ["dep:virtio"] virtio-net = ["virtio"] vsock = ["virtio", "pci"] -wasm = ["wasmtime", "mmap"] +wasm = ["wasmtime", "wasi", "mmap"] [lints.rust] rust_2018_idioms = "warn" @@ -146,7 +146,7 @@ volatile = "0.6" zerocopy = { version = "0.8", default-features = false } uhyve-interface = "0.1.3" wasmtime = { version = "34.0.2", default-features = false, features = ["runtime", "custom-virtual-memory"], optional = true } -wasi = { version = "0.11", default-features = false } +wasi = { version = "0.11", default-features = false, optional = true } [dependencies.smoltcp] version = "0.12"