diff --git a/.gitignore b/.gitignore index 69c84cd8..53463fea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ target tinywasm +wasmtime-as-lib +image_content .VSCodeCounter .gdbinit diff --git a/Cargo.lock b/Cargo.lock index 2810f6b6..a4c08b0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -92,6 +92,12 @@ version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" +[[package]] +name = "arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" + [[package]] name = "async-trait" version = "0.1.74" @@ -182,7 +188,7 @@ dependencies = [ "cfg-if", "libc", "miniz_oxide", - "object", + "object 0.32.1", "rustc-demangle", ] @@ -198,6 +204,12 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + [[package]] name = "byteorder" version = "1.5.0" @@ -271,6 +283,12 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" +[[package]] +name = "cobs" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" + [[package]] name = "colorchoice" version = "1.0.0" @@ -283,6 +301,125 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" +[[package]] +name = "cranelift-bforest" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6b33d7e757a887989eb18b35712b2a67d96171ec3149d1bfb657b29b7b367c" +dependencies = [ + "cranelift-entity", +] + +[[package]] +name = "cranelift-codegen" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9acf15cb22be42d07c3b57d7856329cb228b7315d385346149df2566ad5e4aa" +dependencies = [ + "bumpalo", + "cranelift-bforest", + "cranelift-codegen-meta", + "cranelift-codegen-shared", + "cranelift-control", + "cranelift-entity", + "cranelift-isle", + "gimli 0.28.1", + "hashbrown 0.14.5", + "log", + "regalloc2", + "rustc-hash", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e934d301392b73b3f8b0540391fb82465a0f179a3cee7c726482ac4727efcc97" +dependencies = [ + "cranelift-codegen-shared", +] + +[[package]] +name = "cranelift-codegen-shared" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb2a2566b3d54b854dfb288b3b187f6d3d17d6f762c92898207eba302931da" + +[[package]] +name = "cranelift-control" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0100f33b704cdacd01ad66ff41f8c5030d57cbff078e2a4e49ab1822591299fa" +dependencies = [ + "arbitrary", +] + +[[package]] +name = "cranelift-entity" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8cfdc315e5d18997093e040a8d234bea1ac1e118a716d3e30f40d449e78207b" +dependencies = [ + "serde", + "serde_derive", +] + +[[package]] +name = "cranelift-frontend" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f74b84f16af2e982b0c0c72233503d9d55cbfe3865dbe807ca28dc6642a28b5" +dependencies = [ + "cranelift-codegen", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-isle" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adf306d3dde705fb94bd48082f01d38c4ededc74293a4c007805f610bf08bc6e" + +[[package]] +name = "cranelift-native" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ea0ebdef7aff4a79bcbc8b6495f31315f16b3bf311152f472eaa8d679352581" +dependencies = [ + "cranelift-codegen", + "libc", + "target-lexicon", +] + +[[package]] +name = "cranelift-wasm" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d549108a1942065cdbac3bb96c2952afa0e1b9a3beff4b08c4308ac72257576d" +dependencies = [ + "cranelift-codegen", + "cranelift-entity", + "cranelift-frontend", + "itertools", + "log", + "smallvec", + "wasmparser 0.209.1", + "wasmtime-types", +] + +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + [[package]] name = "derive_more" version = "0.99.17" @@ -296,6 +433,33 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[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.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + [[package]] name = "env_logger" version = "0.10.1" @@ -325,12 +489,24 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -391,6 +567,11 @@ 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 = "hash32" @@ -401,6 +582,15 @@ 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" @@ -408,6 +598,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ "ahash", + "serde", +] + +[[package]] +name = "hashbrown" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +dependencies = [ + "foldhash", ] [[package]] @@ -495,6 +695,12 @@ dependencies = [ "want", ] +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + [[package]] name = "indexmap" version = "2.5.0" @@ -502,7 +708,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.14.5", + "serde", ] [[package]] @@ -516,6 +723,15 @@ dependencies = [ "windows-sys 0.48.0", ] +[[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.9" @@ -531,6 +747,12 @@ dependencies = [ "spin 0.5.2", ] +[[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.158" @@ -582,9 +804,15 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.11" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" +checksum = "b1ad52afd8f9448cbbe722ae722849cc41f1d365e285cca386896352bc08e1a9" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "lock_api" @@ -602,6 +830,15 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +[[package]] +name = "mach2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" +dependencies = [ + "libc", +] + [[package]] name = "matchit" version = "0.7.3" @@ -614,6 +851,24 @@ version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" +[[package]] +name = "memfd" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" +dependencies = [ + "rustix", +] + +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + [[package]] name = "mime" version = "0.3.17" @@ -698,6 +953,27 @@ dependencies = [ "tokio", ] +[[package]] +name = "naked-function" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b8d5fca6ab1e6215b010aefd3b9ac5aae369dae0faea3a7f34f296cc9f719ac" +dependencies = [ + "cfg-if", + "naked-function-macro", +] + +[[package]] +name = "naked-function-macro" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b4123e70df5fe0bb370cff166ae453b9c5324a2cfc932c0f7e55498147a0475" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "nix" version = "0.28.0" @@ -729,12 +1005,30 @@ dependencies = [ "memchr", ] +[[package]] +name = "object" +version = "0.36.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" +dependencies = [ + "crc32fast", + "hashbrown 0.15.0", + "indexmap", + "memchr", +] + [[package]] name = "once_cell" version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + [[package]] name = "percent-encoding" version = "2.3.1" @@ -773,6 +1067,18 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "postcard" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f7f0a8d620d71c457dd1d47df76bb18960378da56af4527aaa10f515eee732e" +dependencies = [ + "cobs", + "embedded-io 0.4.0", + "embedded-io 0.6.1", + "serde", +] + [[package]] name = "proc-macro2" version = "1.0.76" @@ -782,6 +1088,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "psm" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa37f80ca58604976033fae9515a8a2989fc13797d953f7c04fb8fa36a11f205" +dependencies = [ + "cc", +] + [[package]] name = "quote" version = "1.0.35" @@ -791,6 +1106,19 @@ dependencies = [ "proc-macro2", ] +[[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 = "regex" version = "1.10.2" @@ -826,6 +1154,12 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "rustc_version" version = "0.4.0" @@ -837,15 +1171,15 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.25" +version = "0.38.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc99bc2d4f1fed22595588a013687477aedf3cdcfb26558c559edb67b4d9b22e" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" dependencies = [ "bitflags 2.6.0", "errno", "libc", - "linux-raw-sys", - "windows-sys 0.48.0", + "linux-raw-sys 0.4.14", + "windows-sys 0.52.0", ] [[package]] @@ -860,6 +1194,12 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" +[[package]] +name = "sc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "010e18bd3bfd1d45a7e666b236c78720df0d9a7698ebaa9c1c559961eb60a38b" + [[package]] name = "scopeguard" version = "1.2.0" @@ -925,6 +1265,32 @@ dependencies = [ "serde", ] +[[package]] +name = "sjlj" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9b43efc387069aabdc27124a294337c7032a3cb62df0108d2578eff7f08e39" +dependencies = [ + "linux-raw-sys 0.2.2", + "naked-function", + "sc", +] + +[[package]] +name = "slice-group-by" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +dependencies = [ + "serde", +] + [[package]] name = "socket2" version = "0.4.10" @@ -969,6 +1335,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" @@ -1009,6 +1381,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[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.0" @@ -1074,7 +1452,7 @@ version = "0.7.0" source = "git+https://github.com/anti-entropy123/tinywasm?branch=master#31b2d363cd2f1ae36754fd4934acf02f333af95a" dependencies = [ "tinywasm-types", - "wasmparser", + "wasmparser 0.207.0", ] [[package]] @@ -1169,6 +1547,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + [[package]] name = "unwinding" version = "0.2.0" @@ -1210,7 +1594,7 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" name = "wasi_api" version = "0.1.0" dependencies = [ - "hashbrown", + "hashbrown 0.14.5", "lazy_static", "ms_hostcall", "ms_std", @@ -1219,6 +1603,15 @@ dependencies = [ "tinywasm", ] +[[package]] +name = "wasm-encoder" +version = "0.209.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4a05336882dae732ce6bd48b7e11fe597293cb72c13da4f35d7d5f8d53b2a7" +dependencies = [ + "leb128", +] + [[package]] name = "wasmparser" version = "0.207.0" @@ -1227,11 +1620,240 @@ checksum = "e19bb9f8ab07616da582ef8adb24c54f1424c7ec876720b7da9db8ec0626c92c" dependencies = [ "ahash", "bitflags 2.6.0", - "hashbrown", + "hashbrown 0.14.5", "indexmap", "semver", ] +[[package]] +name = "wasmparser" +version = "0.209.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07035cc9a9b41e62d3bb3a3815a66ab87c993c06fe1cf6b2a3f2a18499d937db" +dependencies = [ + "ahash", + "bitflags 2.6.0", + "hashbrown 0.14.5", + "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 = "wasmtime" +version = "22.0.0" +source = "git+https://gitee.com/tju-cloud-computing/wasmtime-as-lib?branch=master#fb45fb8dde6d068abb3ae78bfab78253c9654af5" +dependencies = [ + "anyhow", + "bumpalo", + "cc", + "cfg-if", + "encoding_rs", + "hashbrown 0.14.5", + "indexmap", + "libc", + "libm", + "log", + "mach2", + "memfd", + "memoffset", + "object 0.36.5", + "once_cell", + "paste", + "postcard", + "psm", + "rustix", + "semver", + "serde", + "serde_derive", + "smallvec", + "sptr", + "target-lexicon", + "wasmparser 0.209.1", + "wasmtime-asm-macros", + "wasmtime-component-macro", + "wasmtime-component-util", + "wasmtime-cranelift", + "wasmtime-environ", + "wasmtime-jit-icache-coherence", + "wasmtime-slab", + "wasmtime-versioned-export-macros", + "wasmtime-winch", + "windows-sys 0.52.0", +] + +[[package]] +name = "wasmtime-asm-macros" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d697d99c341d4a9ffb72f3af7a02124d233eeb59aee010f36d88e97cca553d5e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "wasmtime-component-macro" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b29b462b068e73b5b27fae092a27f47e5937cabf6b26be2779c978698a52feca" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn 2.0.48", + "wasmtime-component-util", + "wasmtime-wit-bindgen", + "wit-parser", +] + +[[package]] +name = "wasmtime-component-util" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d2912c53d9054984b380dfbd7579f9c3681b2a73b903a56bd71a1c4f175f1e" + +[[package]] +name = "wasmtime-cranelift" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3975deafea000457ba84355c7c0fce0372937204f77026510b7b454f28a3a65" +dependencies = [ + "anyhow", + "cfg-if", + "cranelift-codegen", + "cranelift-control", + "cranelift-entity", + "cranelift-frontend", + "cranelift-native", + "cranelift-wasm", + "gimli 0.28.1", + "log", + "object 0.36.5", + "target-lexicon", + "thiserror", + "wasmparser 0.209.1", + "wasmtime-environ", + "wasmtime-versioned-export-macros", +] + +[[package]] +name = "wasmtime-environ" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f444e900e848b884d8a8a2949b6f5b92af642a3e663ff8fbe78731143a55be61" +dependencies = [ + "anyhow", + "cranelift-entity", + "gimli 0.28.1", + "indexmap", + "log", + "object 0.36.5", + "postcard", + "serde", + "serde_derive", + "target-lexicon", + "wasm-encoder", + "wasmparser 0.209.1", + "wasmprinter", + "wasmtime-component-util", + "wasmtime-types", +] + +[[package]] +name = "wasmtime-jit-icache-coherence" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5afe2f0499542f9a4bcfa1b55bfdda803b6ade4e7c93c6b99e0f39dba44b0a91" +dependencies = [ + "anyhow", + "cfg-if", + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "wasmtime-slab" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a7de1f2bec5bbb35d532e61c85c049dc84ae671df60492f90b954ecf21169e7" + +[[package]] +name = "wasmtime-types" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "412463e9000e14cf6856be48628d2213c20c153e29ffc22b036980c892ea6964" +dependencies = [ + "cranelift-entity", + "serde", + "serde_derive", + "smallvec", + "wasmparser 0.209.1", +] + +[[package]] +name = "wasmtime-versioned-export-macros" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de5a9bc4f44ceeb168e9e8e3be4e0b4beb9095b468479663a9e24c667e36826f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "wasmtime-winch" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed4db238a0241df2d15f79ad17b3a37a27f2ea6cb885894d81b42ae107544466" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli 0.28.1", + "object 0.36.5", + "target-lexicon", + "wasmparser 0.209.1", + "wasmtime-cranelift", + "wasmtime-environ", + "winch-codegen", +] + +[[package]] +name = "wasmtime-wit-bindgen" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc077306b38288262e5ba01d4b21532a6987416cdc0aedf04bb06c22a68fdc" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "wit-parser", +] + +[[package]] +name = "wasmtime_wasi_api" +version = "0.1.0" +dependencies = [ + "hashbrown 0.14.5", + "lazy_static", + "ms_hostcall", + "ms_std", + "ms_std_proc_macro", + "sjlj", + "spin 0.9.8", + "wasmtime", +] + [[package]] name = "winapi" version = "0.3.9" @@ -1263,6 +1885,23 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "winch-codegen" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85c6915884e731b2db0d8cf08cb64474cb69221a161675fd3c135f91febc3daa" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli 0.28.1", + "regalloc2", + "smallvec", + "target-lexicon", + "wasmparser 0.209.1", + "wasmtime-cranelift", + "wasmtime-environ", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -1395,6 +2034,24 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" +[[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 = "xmas-elf" version = "0.9.1" diff --git a/Cargo.toml b/Cargo.toml index 04e20c32..6a75463e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ members = [ "ms_std_proc_macro", "ms_std", "wasi_api", + "wasmtime_wasi_api", ] # The reason for excluding "user/" is obvious. This workspace can be regarded as diff --git a/build_wasm.rs b/build_wasm.rs new file mode 100644 index 00000000..12a61982 --- /dev/null +++ b/build_wasm.rs @@ -0,0 +1,43 @@ +use std::{path::PathBuf, process::Command}; + +fn get_build_mode() -> &'static str { + if cfg!(debug_assertions) { + "debug" + } else { + "release" + } +} + +fn main() { + let crate_dir: PathBuf = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let workspace_dir: PathBuf = crate_dir.parent().unwrap().parent().unwrap().to_path_buf(); + + let func_name = crate_dir.file_name().unwrap().to_string_lossy(); + + let src_file = crate_dir.join(format!("target/x86_64-unknown-none/{}/lib{}.so", get_build_mode(), func_name)); + let dst_dir = workspace_dir.join(format!("target/{}", get_build_mode())); + if !dst_dir.exists() { + assert!(Command::new("mkdir") + .arg("-p") + .arg(&dst_dir) + .status() + .unwrap() + .success()); + } + let dst_file = dst_dir.join(format!("lib{}.so", func_name)); + + if dst_file.is_symlink() { + return; + } + + let mut ln_commd = Command::new("ln"); + ln_commd.arg("-s"); + ln_commd.args([src_file, dst_file.to_owned()]); + assert!( + ln_commd.status().unwrap().success(), + "ln -s failed, command: {:?}", + ln_commd + ); + + assert!(dst_file.is_symlink(), "build symbol link failed.") +} diff --git a/common_service/mm/src/mmap.rs b/common_service/mm/src/mmap.rs index 2223e326..3b3138f5 100644 --- a/common_service/mm/src/mmap.rs +++ b/common_service/mm/src/mmap.rs @@ -13,7 +13,7 @@ use ms_std::libos::libos; const PAGE_SIZE: usize = 0x1000; #[no_mangle] -pub fn libos_mmap(length: usize, prot: ProtFlags, fd: Fd) -> MMResult { +pub fn libos_mmap(addr: usize, length: usize, prot: ProtFlags, fd: Fd) -> MMResult { if length % PAGE_SIZE > 0 { Err(MMError::InvaildArg( "length % PAGE_SIZE == 0".to_owned(), @@ -24,7 +24,13 @@ pub fn libos_mmap(length: usize, prot: ProtFlags, fd: Fd) -> MMResult { let layout = Layout::from_size_align(length, PAGE_SIZE)?; let mmap_addr = unsafe { - let addr = alloc::alloc::alloc(layout) as usize as *mut libc::c_void; + let addr = { + if addr == 0 { + alloc::alloc::alloc(layout) as usize as *mut libc::c_void + } else { + addr as *mut libc::c_void + } + }; if libc::munmap(addr, length) != 0 { Err(MMError::LibcErr("munmap failed".to_owned()))? } @@ -43,6 +49,10 @@ pub fn libos_mmap(length: usize, prot: ProtFlags, fd: Fd) -> MMResult { addr as usize }; + if fd == u32::MAX { + return Ok(mmap_addr); + } + let mm_region = unsafe { core::slice::from_raw_parts_mut(mmap_addr as *mut c_void, length) }; libos!(register_file_backend(mm_region, fd))?; @@ -51,8 +61,10 @@ pub fn libos_mmap(length: usize, prot: ProtFlags, fd: Fd) -> MMResult { } #[no_mangle] -pub fn libos_munmap(mem_region: &mut [u8], _file_based: bool) -> MMResult<()> { - libos!(unregister_file_backend(mem_region.as_ptr() as usize))?; +pub fn libos_munmap(mem_region: &mut [u8], file_based: bool) -> MMResult<()> { + if file_based { + libos!(unregister_file_backend(mem_region.as_ptr() as usize))?; + } let aligned_length = (mem_region.len() + PAGE_SIZE - 1) & (!PAGE_SIZE + 1); unsafe { @@ -73,6 +85,22 @@ pub fn libos_munmap(mem_region: &mut [u8], _file_based: bool) -> MMResult<()> { Ok(()) } +#[no_mangle] +pub fn libos_mprotect(addr: usize, length: usize, prot: ProtFlags) -> MMResult<()> { + let aligned_length = (length + PAGE_SIZE - 1) & (!PAGE_SIZE + 1); + unsafe { + if libc::mprotect( + addr as *mut libc::c_void, + aligned_length, + trans_protflag(prot), + ) != 0 + { + Err(MMError::LibcErr("mprotect failed".to_owned()))? + }; + } + Ok(()) +} + pub fn trans_protflag(flags: ProtFlags) -> i32 { let mut result = Default::default(); if flags.contains(ProtFlags::READ) { @@ -81,9 +109,9 @@ pub fn trans_protflag(flags: ProtFlags) -> i32 { if flags.contains(ProtFlags::WRITE) { result |= libc::PROT_WRITE } - // if flags.contains(ProtFlags::EXEC) { - // unimplemented!("ProtFlags::EXEC") - // } + if flags.contains(ProtFlags::EXEC) { + result |= libc::PROT_EXEC + } result } diff --git a/common_service/ruxfdtab/src/as_apis.rs b/common_service/ruxfdtab/src/as_apis.rs index 36063e47..025e739a 100644 --- a/common_service/ruxfdtab/src/as_apis.rs +++ b/common_service/ruxfdtab/src/as_apis.rs @@ -1,3 +1,4 @@ + extern crate alloc; use std::path::PathBuf; @@ -18,6 +19,35 @@ use ruxdriver::init_drivers; use ruxfdtable::{FileLike, RuxStat}; use ruxfs::{fops::OpenOptions, init_blkfs, init_filesystems, prepare_commonfs}; +fn convert(ruxstat: RuxStat) -> Stat { + return Stat { + st_dev: ruxstat.st_dev, + st_ino: ruxstat.st_ino, + st_nlink: ruxstat.st_nlink, + st_mode: ruxstat.st_mode, + st_uid: ruxstat.st_uid, + st_gid: ruxstat.st_gid, + __pad0: ruxstat.__pad0, + st_rdev: ruxstat.st_rdev, + st_size: ruxstat.st_size as usize, + st_blksize: ruxstat.st_blksize, + st_blocks: ruxstat.st_blocks, + st_atime: TimeSpec { + tv_sec: ruxstat.st_atime.tv_sec, + tv_nsec: ruxstat.st_atime.tv_nsec, + }, + st_mtime: TimeSpec { + tv_sec: ruxstat.st_mtime.tv_sec, + tv_nsec: ruxstat.st_mtime.tv_nsec, + }, + st_ctime: TimeSpec { + tv_sec: ruxstat.st_ctime.tv_sec, + tv_nsec: ruxstat.st_ctime.tv_nsec, + }, + __unused: ruxstat.__unused, + } +} + fn get_fs_image_path() -> PathBuf { let image_path = match libos!(fs_image(ms_std::init_context::isolation_ctx().isol_id)) { Some(s) => s, @@ -124,35 +154,6 @@ pub fn lseek(fd: Fd, pos: u32) -> FdtabResult<()> { Ok(()) } -fn convert(ruxstat: RuxStat) -> Stat { - return Stat { - st_dev: ruxstat.st_dev, - st_ino: ruxstat.st_ino, - st_nlink: ruxstat.st_nlink, - st_mode: ruxstat.st_mode, - st_uid: ruxstat.st_uid, - st_gid: ruxstat.st_gid, - __pad0: ruxstat.__pad0, - st_rdev: ruxstat.st_rdev, - st_size: ruxstat.st_size as usize, - st_blksize: ruxstat.st_blksize, - st_blocks: ruxstat.st_blocks, - st_atime: TimeSpec { - tv_sec: ruxstat.st_atime.tv_sec, - tv_nsec: ruxstat.st_atime.tv_nsec, - }, - st_mtime: TimeSpec { - tv_sec: ruxstat.st_mtime.tv_sec, - tv_nsec: ruxstat.st_mtime.tv_nsec, - }, - st_ctime: TimeSpec { - tv_sec: ruxstat.st_ctime.tv_sec, - tv_nsec: ruxstat.st_ctime.tv_nsec, - }, - __unused: ruxstat.__unused, - } -} - #[no_mangle] pub fn stat(fd: Fd) -> FdtabResult { let _exec = MUST_EXIC.lock(); @@ -168,6 +169,7 @@ pub fn stat(fd: Fd) -> FdtabResult { #[no_mangle] pub fn readdir(path: &str) -> FdtabResult> { + let _exec = MUST_EXIC.lock(); #[cfg(feature = "log")] println!("[DEBUG] ruxfs read_dir: {:?}", path); @@ -186,4 +188,3 @@ pub fn readdir(path: &str) -> FdtabResult> { Ok(entries) } - diff --git a/common_service/signal/Cargo.lock b/common_service/signal/Cargo.lock new file mode 100644 index 00000000..ef6ace57 --- /dev/null +++ b/common_service/signal/Cargo.lock @@ -0,0 +1,259 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cc" +version = "1.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d6dbb628b8f8555f86d0323c2eb39e3ec81901f4b83e091db8a6a76d316a333" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn 2.0.79", +] + +[[package]] +name = "hash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" +dependencies = [ + "byteorder", +] + +[[package]] +name = "heapless" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" +dependencies = [ + "hash32", + "stable_deref_trait", +] + +[[package]] +name = "linked_list_allocator" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286" +dependencies = [ + "spinning_top", +] + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "ms_hostcall" +version = "0.1.0" +dependencies = [ + "bitflags", + "derive_more", + "thiserror-no-std", +] + +[[package]] +name = "ms_std" +version = "0.1.0" +dependencies = [ + "cfg-if", + "heapless", + "linked_list_allocator", + "ms_hostcall", + "ms_std_proc_macro", + "spin", + "thiserror-no-std", +] + +[[package]] +name = "ms_std_proc_macro" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "nc" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34566634a278b9af0f62b872339d884ea689982514825ba306705f264038144e" +dependencies = [ + "cc", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal" +version = "0.1.0" +dependencies = [ + "ms_hostcall", + "ms_std", + "nc", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spinning_top" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b9eb1a2f4c41445a3a0ff9abc5221c5fcd28e1f13cd7c0397706f9ac938ddb0" +dependencies = [ + "lock_api", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror-impl-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58e6318948b519ba6dc2b442a6d0b904ebfb8d411a3ad3e07843615a72249758" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "thiserror-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3ad459d94dd517257cc96add8a43190ee620011bb6e6cdc82dafd97dfafafea" +dependencies = [ + "thiserror-impl-no-std", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" diff --git a/common_service/signal/Cargo.toml b/common_service/signal/Cargo.toml new file mode 100644 index 00000000..b2e6a64e --- /dev/null +++ b/common_service/signal/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "signal" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +crate-type = ["dylib"] + +[dependencies] +nc = { version = "0.9.5", default-features = false } +ms_std = { path = "../../ms_std", features = [] } +ms_hostcall = { path = "../../ms_hostcall", features = ["signal"]} + +[features] +mpk = ["ms_std/mpk"] +default = [] \ No newline at end of file diff --git a/common_service/signal/src/lib.rs b/common_service/signal/src/lib.rs new file mode 100644 index 00000000..197fe628 --- /dev/null +++ b/common_service/signal/src/lib.rs @@ -0,0 +1,36 @@ +use ms_hostcall::signal::SigAction; +pub use ms_std; +use nc::{self, sigset_t}; + +#[no_mangle] +#[allow(clippy::not_unsafe_ptr_arg_deref)] +pub fn libos_sigaction(signum: i32, act: *const SigAction, old_act: *const SigAction) -> i32 { + let ret = unsafe { + let act = nc::sigaction_t { + sa_handler: (*act).sa_handler as nc::sighandler_t, + sa_flags: (*act).sa_flags as usize, + sa_mask: sigset_t { + sig: (*act).sa_mask.sig, + }, + ..nc::sigaction_t::default() + }; + if old_act.is_null() { + nc::rt_sigaction(signum, Some(&act), None) + } else { + let mut old_act = nc::sigaction_t { + sa_handler: (*old_act).sa_handler as nc::sighandler_t, + sa_flags: (*old_act).sa_flags as usize, + sa_mask: sigset_t { + sig: (*old_act).sa_mask.sig, + }, + ..nc::sigaction_t::default() + }; + nc::rt_sigaction(signum, Some(&act), Some(&mut old_act)) + } + }; + let ret = match ret { + Ok(_) => 0, + Err(errno) => -errno, + }; + ret +} diff --git a/common_service/socket/src/apis.rs b/common_service/socket/src/apis.rs index 1c00fc09..94bd6fd6 100644 --- a/common_service/socket/src/apis.rs +++ b/common_service/socket/src/apis.rs @@ -28,7 +28,7 @@ pub fn addrinfo(name: &str) -> SmoltcpResult { let mut iface = acquire_iface()?; let (dns_handle, query) = { - let servers = &[Ipv4Address::new(114, 114, 114, 114).into()]; + let servers = &[Ipv4Address::new(8, 8, 8, 8).into()]; let dns_socket = dns::Socket::new(servers, vec![]); let mut sockets = acquire_sockets()?; diff --git a/common_service/socket/src/setup_tap.rs b/common_service/socket/src/setup_tap.rs index 5cabb255..b9e59cfb 100644 --- a/common_service/socket/src/setup_tap.rs +++ b/common_service/socket/src/setup_tap.rs @@ -168,7 +168,7 @@ fn exec_sudo_commands(commands: Vec) -> Result<(), String> { } // println!("the sudo passwd: {}", passwd); - assert_eq!(passwd.as_bytes(), b"cptbtptp\n"); + // assert_eq!(passwd.as_bytes(), b"cptbtptp\n"); for mut comd in commands { // println!("The next cmd: {:?}", comd); let mut child = comd diff --git a/cp_data.sh b/cp_data.sh new file mode 100755 index 00000000..f5def0b8 --- /dev/null +++ b/cp_data.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# 检查是否有参数传递 +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +case $1 in + "c1") + case $2 in + "10m") + src_path="/home/wyj/alloy_stack/asstlane/word_count/fake_data_0_" + dest_path="./image_content/" + sudo cp ./../asstlane/word_count/fake_data_ + ;; + "n10") + + ;; + "n15") + + ;; + *) + echo "Unknown command: $2" + exit 1 + ;; + esac + + ;; + "map_reduce") + echo "Executing map_reduce" + *) + echo "Unknown command: $1" + exit 1 + ;; +esac + + + +sudo cp ./ \ No newline at end of file diff --git a/create_image.sh b/create_image.sh new file mode 100755 index 00000000..384af723 --- /dev/null +++ b/create_image.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +sudo umount ./image_content + +rm ./fs_images/new_image.img + +IMAGE_DIR="fs_images" +IMAGE_FILE="new_image.img" + +IMAGE_PATH="$IMAGE_DIR/$IMAGE_FILE" + +dd if=/dev/zero of="$IMAGE_PATH" bs=1M count=400 + +mkfs.vfat -F 32 "$IMAGE_PATH" + +sudo mount ./fs_images/new_image.img ./image_content \ No newline at end of file diff --git a/isol_config/long_chain.json b/isol_config/long_chain.json index 3815b068..d2c93748 100644 --- a/isol_config/long_chain.json +++ b/isol_config/long_chain.json @@ -23,123 +23,16 @@ ], "apps": [ [ - "file_reader", - "libfile_reader.so" - ], - [ - "array_sum1", - "libarray_sum.so" - ], - [ - "array_sum2", - "libarray_sum.so" - ], - [ - "array_sum3", - "libarray_sum.so" - ], - [ - "array_sum4", - "libarray_sum.so" - ], - [ - "array_sum5", - "libarray_sum.so" - ], - [ - "array_sum6", - "libarray_sum.so" - ], - [ - "array_sum7", - "libarray_sum.so" - ], - [ - "array_sum8", - "libarray_sum.so" - ], - [ - "array_sum9", - "libarray_sum.so" - ], - [ - "array_sum10", + "array_sum", "libarray_sum.so" ] ], - "fs_image": "fs_images/fatfs.img", "groups": [ { "list": [ - { - "name": "file_reader", - "args": { - "slot_name": "part-0-0", - "input_file": "fake_data_0.txt" - } - } - ], - "args": {} - }, - { - "list": [ - "array_sum1" - ], - "args": {"array_num": "1"} - }, - { - "list": [ - "array_sum2" - ], - "args": {"array_num": "2"} - }, - { - "list": [ - "array_sum3" - ], - "args": {"array_num": "3"} - }, - { - "list": [ - "array_sum4" - ], - "args": {"array_num": "4"} - }, - { - "list": [ - "array_sum5" - ], - "args": {"array_num": "5"} - }, - { - "list": [ - "array_sum6" - ], - "args": {"array_num": "6"} - }, - { - "list": [ - "array_sum7" - ], - "args": {"array_num": "7"} - }, - { - "list": [ - "array_sum8" - ], - "args": {"array_num": "8"} - }, - { - "list": [ - "array_sum9" - ], - "args": {"array_num": "9"} - }, - { - "list": [ - "array_sum10" + "array_sum" ], - "args": {"array_num": "10"} + "args": {"array_num": "0"} } ] } \ No newline at end of file diff --git a/isol_config/long_chain_c5.json b/isol_config/long_chain_c5.json deleted file mode 100644 index a5b3a93b..00000000 --- a/isol_config/long_chain_c5.json +++ /dev/null @@ -1,213 +0,0 @@ -{ - "services": [ - [ - "mm", - "libmm.so" - ], - [ - "time", - "libtime.so" - ], - [ - "fdtab", - "libfdtab.so" - ], - [ - "stdio", - "libstdio.so" - ], - [ - "fatfs", - "libfatfs.so" - ] - ], - "apps": [ - [ - "file_reader", - "libfile_reader.so" - ], - [ - "array_sum1", - "libarray_sum.so" - ], - [ - "array_sum2", - "libarray_sum.so" - ], - [ - "array_sum3", - "libarray_sum.so" - ], - [ - "array_sum4", - "libarray_sum.so" - ], - [ - "array_sum5", - "libarray_sum.so" - ], - [ - "array_sum6", - "libarray_sum.so" - ], - [ - "array_sum7", - "libarray_sum.so" - ], - [ - "array_sum8", - "libarray_sum.so" - ], - [ - "array_sum9", - "libarray_sum.so" - ], - [ - "array_sum10", - "libarray_sum.so" - ] - ], - "fs_image": "fs_images/fatfs.img", - "groups": [ - { - "list": [ - { - "name": "file_reader", - "args": { - "slot_name": "part-0-0", - "input_file": "fake_data_0.txt" - } - }, - { - "name": "file_reader", - "args": { - "slot_name": "part-0-1", - "input_file": "fake_data_1.txt" - } - }, - { - "name": "file_reader", - "args": { - "slot_name": "part-0-2", - "input_file": "fake_data_2.txt" - } - }, - { - "name": "file_reader", - "args": { - "slot_name": "part-0-3", - "input_file": "fake_data_3.txt" - } - }, - { - "name": "file_reader", - "args": { - "slot_name": "part-0-4", - "input_file": "fake_data_4.txt" - } - } - ], - "args": {} - }, - { - "list": [ - "array_sum1", - "array_sum1", - "array_sum1", - "array_sum1", - "array_sum1" - ], - "args": {"array_num": "1"} - }, - { - "list": [ - "array_sum2", - "array_sum2", - "array_sum2", - "array_sum2", - "array_sum2" - ], - "args": {"array_num": "2"} - }, - { - "list": [ - "array_sum3", - "array_sum3", - "array_sum3", - "array_sum3", - "array_sum3" - ], - "args": {"array_num": "3"} - }, - { - "list": [ - "array_sum4", - "array_sum4", - "array_sum4", - "array_sum4", - "array_sum4" - ], - "args": {"array_num": "4"} - }, - { - "list": [ - "array_sum5", - "array_sum5", - "array_sum5", - "array_sum5", - "array_sum5" - ], - "args": {"array_num": "5"} - }, - { - "list": [ - "array_sum6", - "array_sum6", - "array_sum6", - "array_sum6", - "array_sum6" - ], - "args": {"array_num": "6"} - }, - { - "list": [ - "array_sum7", - "array_sum7", - "array_sum7", - "array_sum7", - "array_sum7" - ], - "args": {"array_num": "7"} - }, - { - "list": [ - "array_sum8", - "array_sum8", - "array_sum8", - "array_sum8", - "array_sum8" - ], - "args": {"array_num": "8"} - }, - { - "list": [ - "array_sum9", - "array_sum9", - "array_sum9", - "array_sum9", - "array_sum9" - ], - "args": {"array_num": "9"} - }, - { - "list": [ - "array_sum10", - "array_sum10", - "array_sum10", - "array_sum10", - "array_sum10" - ], - "args": {"array_num": "10"} - } - ] -} \ No newline at end of file diff --git a/isol_config/long_chain_c1.json b/isol_config/long_chain_n10.json similarity index 81% rename from isol_config/long_chain_c1.json rename to isol_config/long_chain_n10.json index 3815b068..b6a84962 100644 --- a/isol_config/long_chain_c1.json +++ b/isol_config/long_chain_n10.json @@ -23,8 +23,8 @@ ], "apps": [ [ - "file_reader", - "libfile_reader.so" + "array_sum0", + "libarray_sum.so" ], [ "array_sum1", @@ -61,25 +61,14 @@ [ "array_sum9", "libarray_sum.so" - ], - [ - "array_sum10", - "libarray_sum.so" ] ], - "fs_image": "fs_images/fatfs.img", "groups": [ { "list": [ - { - "name": "file_reader", - "args": { - "slot_name": "part-0-0", - "input_file": "fake_data_0.txt" - } - } + "array_sum0" ], - "args": {} + "args": {"array_num": "0"} }, { "list": [ @@ -134,12 +123,6 @@ "array_sum9" ], "args": {"array_num": "9"} - }, - { - "list": [ - "array_sum10" - ], - "args": {"array_num": "10"} } ] } \ No newline at end of file diff --git a/isol_config/long_chain_c3.json b/isol_config/long_chain_n15.json similarity index 63% rename from isol_config/long_chain_c3.json rename to isol_config/long_chain_n15.json index 5025d52f..ecd83002 100644 --- a/isol_config/long_chain_c3.json +++ b/isol_config/long_chain_n15.json @@ -23,8 +23,8 @@ ], "apps": [ [ - "file_reader", - "libfile_reader.so" + "array_sum0", + "libarray_sum.so" ], [ "array_sum1", @@ -65,115 +65,114 @@ [ "array_sum10", "libarray_sum.so" + ], + [ + "array_sum11", + "libarray_sum.so" + ], + [ + "array_sum12", + "libarray_sum.so" + ], + [ + "array_sum13", + "libarray_sum.so" + ], + [ + "array_sum14", + "libarray_sum.so" ] ], - "fs_image": "fs_images/fatfs.img", "groups": [ { "list": [ - { - "name": "file_reader", - "args": { - "slot_name": "part-0-0", - "input_file": "fake_data_0.txt" - } - }, - { - "name": "file_reader", - "args": { - "slot_name": "part-0-1", - "input_file": "fake_data_1.txt" - } - }, - { - "name": "file_reader", - "args": { - "slot_name": "part-0-2", - "input_file": "fake_data_2.txt" - } - } + "array_sum0" ], - "args": {} + "args": {"array_num": "0"} }, { "list": [ - "array_sum1", - "array_sum1", "array_sum1" ], "args": {"array_num": "1"} }, { "list": [ - "array_sum2", - "array_sum2", "array_sum2" ], "args": {"array_num": "2"} }, { "list": [ - "array_sum3", - "array_sum3", "array_sum3" ], "args": {"array_num": "3"} }, { "list": [ - "array_sum4", - "array_sum4", "array_sum4" ], "args": {"array_num": "4"} }, { "list": [ - "array_sum5", - "array_sum5", "array_sum5" ], "args": {"array_num": "5"} }, { "list": [ - "array_sum6", - "array_sum6", "array_sum6" ], "args": {"array_num": "6"} }, { "list": [ - "array_sum7", - "array_sum7", "array_sum7" ], "args": {"array_num": "7"} }, { "list": [ - "array_sum8", - "array_sum8", "array_sum8" ], "args": {"array_num": "8"} }, { "list": [ - "array_sum9", - "array_sum9", "array_sum9" ], "args": {"array_num": "9"} }, { "list": [ - "array_sum10", - "array_sum10", "array_sum10" ], "args": {"array_num": "10"} + }, + { + "list": [ + "array_sum11" + ], + "args": {"array_num": "11"} + }, + { + "list": [ + "array_sum12" + ], + "args": {"array_num": "12"} + }, + { + "list": [ + "array_sum13" + ], + "args": {"array_num": "13"} + }, + { + "list": [ + "array_sum14" + ], + "args": {"array_num": "14"} } ] } \ No newline at end of file diff --git a/isol_config/long_chain_n5.json b/isol_config/long_chain_n5.json new file mode 100644 index 00000000..94bb1b2f --- /dev/null +++ b/isol_config/long_chain_n5.json @@ -0,0 +1,78 @@ +{ + "services": [ + [ + "mm", + "libmm.so" + ], + [ + "time", + "libtime.so" + ], + [ + "fdtab", + "libfdtab.so" + ], + [ + "stdio", + "libstdio.so" + ], + [ + "fatfs", + "libfatfs.so" + ] + ], + "apps": [ + [ + "array_sum0", + "libarray_sum.so" + ], + [ + "array_sum1", + "libarray_sum.so" + ], + [ + "array_sum2", + "libarray_sum.so" + ], + [ + "array_sum3", + "libarray_sum.so" + ], + [ + "array_sum4", + "libarray_sum.so" + ] + ], + "groups": [ + { + "list": [ + "array_sum0" + ], + "args": {"array_num": "0"} + }, + { + "list": [ + "array_sum1" + ], + "args": {"array_num": "1"} + }, + { + "list": [ + "array_sum2" + ], + "args": {"array_num": "2"} + }, + { + "list": [ + "array_sum3" + ], + "args": {"array_num": "3"} + }, + { + "list": [ + "array_sum4" + ], + "args": {"array_num": "4"} + } + ] +} \ No newline at end of file diff --git a/isol_config/map_reduce.json b/isol_config/map_reduce.json index 50eea73b..95a22279 100644 --- a/isol_config/map_reduce.json +++ b/isol_config/map_reduce.json @@ -15,6 +15,10 @@ [ "fatfs", "libfatfs.so" + ], + [ + "time", + "libtime.so" ] ], "apps": [ diff --git a/isol_config/map_reduce_large_c1.json b/isol_config/map_reduce_large_c1.json index 055e0629..3f883530 100644 --- a/isol_config/map_reduce_large_c1.json +++ b/isol_config/map_reduce_large_c1.json @@ -12,16 +12,16 @@ "mm", "libmm.so" ], + [ + "time", + "libtime.so" + ], [ "fatfs", "libfatfs.so" ] ], "apps": [ - [ - "file_reader", - "libfile_reader.so" - ], [ "mapper", "libmapper.so" @@ -31,20 +31,8 @@ "libreducer.so" ] ], - "fs_image": "fs_images/fatfs_large.img", + "fs_image": "fs_images/new_image.img", "groups": [ - { - "list": [ - { - "name": "file_reader", - "args": { - "slot_name": "part-0", - "input_file": "fake_data_0.txt" - } - } - ], - "args": {} - }, { "list": [ "mapper" diff --git a/isol_config/map_reduce_large_c3.json b/isol_config/map_reduce_large_c3.json index 32a9165a..0773ecfd 100644 --- a/isol_config/map_reduce_large_c3.json +++ b/isol_config/map_reduce_large_c3.json @@ -12,16 +12,16 @@ "mm", "libmm.so" ], + [ + "time", + "libtime.so" + ], [ "fatfs", "libfatfs.so" ] ], "apps": [ - [ - "file_reader", - "libfile_reader.so" - ], [ "mapper", "libmapper.so" @@ -31,34 +31,8 @@ "libreducer.so" ] ], - "fs_image": "fs_images/fatfs_large.img", + "fs_image": "fs_images/new_image.img", "groups": [ - { - "list": [ - { - "name": "file_reader", - "args": { - "slot_name": "part-0", - "input_file": "fake_data_0.txt" - } - }, - { - "name": "file_reader", - "args": { - "slot_name": "part-1", - "input_file": "fake_data_1.txt" - } - }, - { - "name": "file_reader", - "args": { - "slot_name": "part-2", - "input_file": "fake_data_2.txt" - } - } - ], - "args": {} - }, { "list": [ "mapper", diff --git a/isol_config/map_reduce_large_c5.json b/isol_config/map_reduce_large_c5.json index e3a1a88b..5ea45aae 100644 --- a/isol_config/map_reduce_large_c5.json +++ b/isol_config/map_reduce_large_c5.json @@ -12,16 +12,16 @@ "mm", "libmm.so" ], + [ + "time", + "libtime.so" + ], [ "fatfs", "libfatfs.so" ] ], "apps": [ - [ - "file_reader", - "libfile_reader.so" - ], [ "mapper", "libmapper.so" @@ -31,48 +31,8 @@ "libreducer.so" ] ], - "fs_image": "fs_images/fatfs_large.img", + "fs_image": "fs_images/new_image.img", "groups": [ - { - "list": [ - { - "name": "file_reader", - "args": { - "slot_name": "part-0", - "input_file": "fake_data_0.txt" - } - }, - { - "name": "file_reader", - "args": { - "slot_name": "part-1", - "input_file": "fake_data_1.txt" - } - }, - { - "name": "file_reader", - "args": { - "slot_name": "part-2", - "input_file": "fake_data_2.txt" - } - }, - { - "name": "file_reader", - "args": { - "slot_name": "part-3", - "input_file": "fake_data_3.txt" - } - }, - { - "name": "file_reader", - "args": { - "slot_name": "part-4", - "input_file": "fake_data_4.txt" - } - } - ], - "args": {} - }, { "list": [ "mapper", diff --git a/isol_config/parallel_sort.json b/isol_config/parallel_sort.json index 58a57ac3..1210cc9f 100644 --- a/isol_config/parallel_sort.json +++ b/isol_config/parallel_sort.json @@ -25,18 +25,6 @@ [ "sorter", "libsorter.so" - ], - [ - "splitter", - "libsplitter.so" - ], - [ - "merger", - "libmerger.so" - ], - [ - "checker", - "libchecker.so" ] ], "fs_image": "fs_images/fatfs_large_sort.img", @@ -49,78 +37,17 @@ "slot_name": "input-part-0", "input_file": "sort_data_0.txt" } - }, - { - "name": "file_reader", - "args": { - "slot_name": "input-part-1", - "input_file": "sort_data_1.txt" - } - }, - { - "name": "file_reader", - "args": { - "slot_name": "input-part-2", - "input_file": "sort_data_2.txt" - } - }, - { - "name": "file_reader", - "args": { - "slot_name": "input-part-3", - "input_file": "sort_data_3.txt" - } - }, - { - "name": "file_reader", - "args": { - "slot_name": "input-part-4", - "input_file": "sort_data_4.txt" - } } ], "args": {} }, { "list": [ - "sorter", - "sorter", - "sorter", - "sorter", "sorter" ], "args": { - "sorter_num": "5", - "merger_num": "4" - } - }, - { - "list": [ - "splitter", - "splitter", - "splitter", - "splitter", - "splitter" - ], - "args": {} - }, - { - "list": [ - "merger", - "merger", - "merger", - "merger" - ], - "args": { - "sorter_num": "5" - } - }, - { - "list": [ - "checker" - ], - "args": { - "merger_num": "4" + "sorter_num": "1", + "merger_num": "1" } } ] diff --git a/isol_config/parallel_sort_c1.json b/isol_config/parallel_sort_c1.json index 113778de..89bb546a 100644 --- a/isol_config/parallel_sort_c1.json +++ b/isol_config/parallel_sort_c1.json @@ -39,7 +39,7 @@ "libchecker.so" ] ], - "fs_image": "fs_images/fatfs_large_sort.img", + "fs_image": "fs_images/new_image.img", "groups": [ { "list": [ diff --git a/isol_config/parallel_sort_c3.json b/isol_config/parallel_sort_c3.json index 114611bb..ec5b8c78 100644 --- a/isol_config/parallel_sort_c3.json +++ b/isol_config/parallel_sort_c3.json @@ -12,6 +12,10 @@ "mm", "libmm.so" ], + [ + "time", + "libtime.so" + ], [ "fatfs", "libfatfs.so" @@ -39,7 +43,7 @@ "libchecker.so" ] ], - "fs_image": "fs_images/fatfs_large_sort.img", + "fs_image": "fs_images/new_image.img", "groups": [ { "list": [ diff --git a/isol_config/parallel_sort_c5.json b/isol_config/parallel_sort_c5.json index 50b44261..c33beca2 100644 --- a/isol_config/parallel_sort_c5.json +++ b/isol_config/parallel_sort_c5.json @@ -39,7 +39,7 @@ "libchecker.so" ] ], - "fs_image": "fs_images/fatfs_large_sort.img", + "fs_image": "fs_images/new_image.img", "groups": [ { "list": [ diff --git a/isol_config/read_wrie.json b/isol_config/read_wrie.json new file mode 100644 index 00000000..e170c3b0 --- /dev/null +++ b/isol_config/read_wrie.json @@ -0,0 +1,45 @@ +{ + "services": [ + [ + "fdtab", + "libfdtab.so" + ], + [ + "stdio", + "libstdio.so" + ], + [ + "mm", + "libmm.so" + ], + [ + "time", + "libtime.so" + ], + [ + "fatfs", + "libfatfs.so" + ] + ], + "apps": [ + [ + "file_reader", + "libfile_reader.so" + ] + ], + "fs_image": "fs_images/new_image.img", + "groups": [ + { + "list": [ + { + "name": "file_reader", + "args": { + "slot_name": "input-part-0", + "input_file": "fake_data_0.txt" + } + } + ], + "args": {} + } + ] +} \ No newline at end of file diff --git a/isol_config/wasmtime_cpython.json b/isol_config/wasmtime_cpython.json new file mode 100755 index 00000000..97ff06ef --- /dev/null +++ b/isol_config/wasmtime_cpython.json @@ -0,0 +1,37 @@ +{ + "services": [ + [ + "fdtab", + "libruxfdtab.so" + ], + [ + "time", + "libtime.so" + ], + [ + "stdio", + "libstdio.so" + ], + [ + "fatfs", + "libfatfs.so" + ] + ], + "apps": [ + [ + "cpython", + "libwasmtime_cpython.so" + ] + ], + "fs_image": "fs_images/fatfs.img", + "groups": [ + { + "list": [ + "cpython" + ], + "args": { + "pyfile_path": "/wasm_bench/alu.py" + } + } + ] +} diff --git a/isol_config/wasmtime_hello.json b/isol_config/wasmtime_hello.json new file mode 100644 index 00000000..6b102f5e --- /dev/null +++ b/isol_config/wasmtime_hello.json @@ -0,0 +1,32 @@ +{ + "services": [ + [ + "fdtab", + "libfdtab.so" + ], + [ + "stdio", + "libstdio.so" + ], + [ + "mm", + "libmm.so" + ], + [ + "signal", + "libsignal.so" + ] + ], + "apps": [ + [ + "hello1", + "libwasmtime_hello.so" + ] + ], + "groups": [{ + "list": [ + "hello1" + ], + "args": {} + }] +} diff --git a/isol_config/wasmtime_longchain.json b/isol_config/wasmtime_longchain.json new file mode 100644 index 00000000..dc97a18c --- /dev/null +++ b/isol_config/wasmtime_longchain.json @@ -0,0 +1,148 @@ +{ + "services": [ + [ + "fdtab", + "libruxfdtab.so" + ], + [ + "stdio", + "libstdio.so" + ], + [ + "mm", + "libmm.so" + ], + [ + "time", + "libtime.so" + ], + [ + "fatfs", + "libfatfs.so" + ] + ], + "apps": [ + [ + "func1", + "libwasmtime_func.so" + ], + [ + "func2", + "libwasmtime_func.so" + ], + [ + "func3", + "libwasmtime_func.so" + ], + [ + "func4", + "libwasmtime_func.so" + ], + [ + "func5", + "libwasmtime_func.so" + ], + [ + "func6", + "libwasmtime_func.so" + ], + [ + "func7", + "libwasmtime_func.so" + ], + [ + "func8", + "libwasmtime_func.so" + ], + [ + "func9", + "libwasmtime_func.so" + ], + [ + "func10", + "libwasmtime_func.so" + ] + ], + "groups": [ + { + "list": [ + "func1" + ], + "args": { + "func_num": "0" + } + }, + { + "list": [ + "func2" + ], + "args": { + "func_num": "1" + } + }, + { + "list": [ + "func3" + ], + "args": { + "func_num": "2" + } + }, + { + "list": [ + "func4" + ], + "args": { + "func_num": "3" + } + }, + { + "list": [ + "func5" + ], + "args": { + "func_num": "4" + } + }, + { + "list": [ + "func6" + ], + "args": { + "func_num": "5" + } + }, + { + "list": [ + "func7" + ], + "args": { + "func_num": "6" + } + }, + { + "list": [ + "func8" + ], + "args": { + "func_num": "7" + } + }, + { + "list": [ + "func9" + ], + "args": { + "func_num": "8" + } + }, + { + "list": [ + "func10" + ], + "args": { + "func_num": "9" + } + } + ] + } \ No newline at end of file diff --git a/isol_config/wasmtime_longchain_n10.json b/isol_config/wasmtime_longchain_n10.json new file mode 100644 index 00000000..dc97a18c --- /dev/null +++ b/isol_config/wasmtime_longchain_n10.json @@ -0,0 +1,148 @@ +{ + "services": [ + [ + "fdtab", + "libruxfdtab.so" + ], + [ + "stdio", + "libstdio.so" + ], + [ + "mm", + "libmm.so" + ], + [ + "time", + "libtime.so" + ], + [ + "fatfs", + "libfatfs.so" + ] + ], + "apps": [ + [ + "func1", + "libwasmtime_func.so" + ], + [ + "func2", + "libwasmtime_func.so" + ], + [ + "func3", + "libwasmtime_func.so" + ], + [ + "func4", + "libwasmtime_func.so" + ], + [ + "func5", + "libwasmtime_func.so" + ], + [ + "func6", + "libwasmtime_func.so" + ], + [ + "func7", + "libwasmtime_func.so" + ], + [ + "func8", + "libwasmtime_func.so" + ], + [ + "func9", + "libwasmtime_func.so" + ], + [ + "func10", + "libwasmtime_func.so" + ] + ], + "groups": [ + { + "list": [ + "func1" + ], + "args": { + "func_num": "0" + } + }, + { + "list": [ + "func2" + ], + "args": { + "func_num": "1" + } + }, + { + "list": [ + "func3" + ], + "args": { + "func_num": "2" + } + }, + { + "list": [ + "func4" + ], + "args": { + "func_num": "3" + } + }, + { + "list": [ + "func5" + ], + "args": { + "func_num": "4" + } + }, + { + "list": [ + "func6" + ], + "args": { + "func_num": "5" + } + }, + { + "list": [ + "func7" + ], + "args": { + "func_num": "6" + } + }, + { + "list": [ + "func8" + ], + "args": { + "func_num": "7" + } + }, + { + "list": [ + "func9" + ], + "args": { + "func_num": "8" + } + }, + { + "list": [ + "func10" + ], + "args": { + "func_num": "9" + } + } + ] + } \ No newline at end of file diff --git a/isol_config/wasmtime_longchain_n15.json b/isol_config/wasmtime_longchain_n15.json new file mode 100644 index 00000000..7b3b67c5 --- /dev/null +++ b/isol_config/wasmtime_longchain_n15.json @@ -0,0 +1,208 @@ +{ + "services": [ + [ + "fdtab", + "libruxfdtab.so" + ], + [ + "stdio", + "libstdio.so" + ], + [ + "mm", + "libmm.so" + ], + [ + "time", + "libtime.so" + ], + [ + "fatfs", + "libfatfs.so" + ] + ], + "apps": [ + [ + "func1", + "libwasmtime_func.so" + ], + [ + "func2", + "libwasmtime_func.so" + ], + [ + "func3", + "libwasmtime_func.so" + ], + [ + "func4", + "libwasmtime_func.so" + ], + [ + "func5", + "libwasmtime_func.so" + ], + [ + "func6", + "libwasmtime_func.so" + ], + [ + "func7", + "libwasmtime_func.so" + ], + [ + "func8", + "libwasmtime_func.so" + ], + [ + "func9", + "libwasmtime_func.so" + ], + [ + "func10", + "libwasmtime_func.so" + ], + [ + "func11", + "libwasmtime_func.so" + ], + [ + "func12", + "libwasmtime_func.so" + ], + [ + "func13", + "libwasmtime_func.so" + ], + [ + "func14", + "libwasmtime_func.so" + ], + [ + "func15", + "libwasmtime_func.so" + ] + ], + "groups": [ + { + "list": [ + "func1" + ], + "args": { + "func_num": "0" + } + }, + { + "list": [ + "func2" + ], + "args": { + "func_num": "1" + } + }, + { + "list": [ + "func3" + ], + "args": { + "func_num": "2" + } + }, + { + "list": [ + "func4" + ], + "args": { + "func_num": "3" + } + }, + { + "list": [ + "func5" + ], + "args": { + "func_num": "4" + } + }, + { + "list": [ + "func6" + ], + "args": { + "func_num": "5" + } + }, + { + "list": [ + "func7" + ], + "args": { + "func_num": "6" + } + }, + { + "list": [ + "func8" + ], + "args": { + "func_num": "7" + } + }, + { + "list": [ + "func9" + ], + "args": { + "func_num": "8" + } + }, + { + "list": [ + "func10" + ], + "args": { + "func_num": "9" + } + }, + { + "list": [ + "func11" + ], + "args": { + "func_num": "10" + } + }, + { + "list": [ + "func12" + ], + "args": { + "func_num": "11" + } + }, + { + "list": [ + "func13" + ], + "args": { + "func_num": "12" + } + }, + { + "list": [ + "func14" + ], + "args": { + "func_num": "13" + } + }, + { + "list": [ + "func15" + ], + "args": { + "func_num": "14" + } + } + ] + } \ No newline at end of file diff --git a/isol_config/wasmtime_longchain_n5.json b/isol_config/wasmtime_longchain_n5.json new file mode 100644 index 00000000..ab0362c8 --- /dev/null +++ b/isol_config/wasmtime_longchain_n5.json @@ -0,0 +1,88 @@ +{ + "services": [ + [ + "fdtab", + "libruxfdtab.so" + ], + [ + "stdio", + "libstdio.so" + ], + [ + "mm", + "libmm.so" + ], + [ + "time", + "libtime.so" + ], + [ + "fatfs", + "libfatfs.so" + ] + ], + "apps": [ + [ + "func1", + "libwasmtime_func.so" + ], + [ + "func2", + "libwasmtime_func.so" + ], + [ + "func3", + "libwasmtime_func.so" + ], + [ + "func4", + "libwasmtime_func.so" + ], + [ + "func5", + "libwasmtime_func.so" + ] + ], + "groups": [ + { + "list": [ + "func1" + ], + "args": { + "func_num": "0" + } + }, + { + "list": [ + "func2" + ], + "args": { + "func_num": "1" + } + }, + { + "list": [ + "func3" + ], + "args": { + "func_num": "2" + } + }, + { + "list": [ + "func4" + ], + "args": { + "func_num": "3" + } + }, + { + "list": [ + "func5" + ], + "args": { + "func_num": "4" + } + } + ] + } \ No newline at end of file diff --git a/isol_config/wasmtime_parallel_sort.json b/isol_config/wasmtime_parallel_sort.json new file mode 100644 index 00000000..32e7d8ac --- /dev/null +++ b/isol_config/wasmtime_parallel_sort.json @@ -0,0 +1,63 @@ +{ + "services": [ + [ + "fdtab", + "libruxfdtab.so" + ], + [ + "stdio", + "libstdio.so" + ], + [ + "mm", + "libmm.so" + ], + [ + "time", + "libtime.so" + ], + [ + "fatfs", + "libfatfs.so" + ] + ], + "apps": [ + [ + "sorter", + "libwasmtime_sorter.so" + ], + [ + "spliter", + "libwasmtime_spliter.so" + ], + [ + "merger", + "libwasmtime_merger.so" + ], + [ + "checker", + "libwasmtime_checker.so" + ] + ], + "fs_image": "fs_images/new_image.img", + "groups": [ + { + "list": [ + "sorter" + ], + "args": { + "sorter_num": "1", + "merger_num": "1" + } + }, + { + "list": [ + "spliter" + ], + "args": { + "sorter_num": "1", + "merger_num": "1" + } + } + ] + } \ No newline at end of file diff --git a/isol_config/wasmtime_parallel_sort_c1.json b/isol_config/wasmtime_parallel_sort_c1.json new file mode 100644 index 00000000..e8bb75a2 --- /dev/null +++ b/isol_config/wasmtime_parallel_sort_c1.json @@ -0,0 +1,81 @@ +{ + "services": [ + [ + "fdtab", + "libruxfdtab.so" + ], + [ + "stdio", + "libstdio.so" + ], + [ + "mm", + "libmm.so" + ], + [ + "time", + "libtime.so" + ], + [ + "fatfs", + "libfatfs.so" + ] + ], + "apps": [ + [ + "sorter", + "libwasmtime_sorter.so" + ], + [ + "spliter", + "libwasmtime_spliter.so" + ], + [ + "merger", + "libwasmtime_merger.so" + ], + [ + "checker", + "libwasmtime_checker.so" + ] + ], + "fs_image": "fs_images/new_image.img", + "groups": [ + { + "list": [ + "sorter" + ], + "args": { + "sorter_num": "1", + "merger_num": "1" + } + }, + { + "list": [ + "spliter" + ], + "args": { + "sorter_num": "1", + "merger_num": "1" + } + }, + { + "list": [ + "merger" + ], + "args": { + "sorter_num": "1", + "merger_num": "1" + } + }, + { + "list": [ + "checker" + ], + "args": { + "sorter_num": "1", + "merger_num": "1" + } + } + ] + } \ No newline at end of file diff --git a/isol_config/wasmtime_parallel_sort_c3.json b/isol_config/wasmtime_parallel_sort_c3.json new file mode 100644 index 00000000..fe4a553d --- /dev/null +++ b/isol_config/wasmtime_parallel_sort_c3.json @@ -0,0 +1,87 @@ +{ + "services": [ + [ + "fdtab", + "libruxfdtab.so" + ], + [ + "stdio", + "libstdio.so" + ], + [ + "mm", + "libmm.so" + ], + [ + "time", + "libtime.so" + ], + [ + "fatfs", + "libfatfs.so" + ] + ], + "apps": [ + [ + "sorter", + "libwasmtime_sorter.so" + ], + [ + "spliter", + "libwasmtime_spliter.so" + ], + [ + "merger", + "libwasmtime_merger.so" + ], + [ + "checker", + "libwasmtime_checker.so" + ] + ], + "fs_image": "fs_images/new_image.img", + "groups": [ + { + "list": [ + "sorter", + "sorter", + "sorter" + ], + "args": { + "sorter_num": "3", + "merger_num": "3" + } + }, + { + "list": [ + "spliter", + "spliter", + "spliter" + ], + "args": { + "sorter_num": "3", + "merger_num": "3" + } + }, + { + "list": [ + "merger", + "merger", + "merger" + ], + "args": { + "sorter_num": "3", + "merger_num": "3" + } + }, + { + "list": [ + "checker" + ], + "args": { + "sorter_num": "3", + "merger_num": "3" + } + } + ] + } \ No newline at end of file diff --git a/isol_config/wasmtime_parallel_sort_c5.json b/isol_config/wasmtime_parallel_sort_c5.json new file mode 100644 index 00000000..3aa27e47 --- /dev/null +++ b/isol_config/wasmtime_parallel_sort_c5.json @@ -0,0 +1,93 @@ +{ + "services": [ + [ + "fdtab", + "libruxfdtab.so" + ], + [ + "stdio", + "libstdio.so" + ], + [ + "mm", + "libmm.so" + ], + [ + "time", + "libtime.so" + ], + [ + "fatfs", + "libfatfs.so" + ] + ], + "apps": [ + [ + "sorter", + "libwasmtime_sorter.so" + ], + [ + "spliter", + "libwasmtime_spliter.so" + ], + [ + "merger", + "libwasmtime_merger.so" + ], + [ + "checker", + "libwasmtime_checker.so" + ] + ], + "fs_image": "fs_images/new_image.img", + "groups": [ + { + "list": [ + "sorter", + "sorter", + "sorter", + "sorter", + "sorter" + ], + "args": { + "sorter_num": "5", + "merger_num": "5" + } + }, + { + "list": [ + "spliter", + "spliter", + "spliter", + "spliter", + "spliter" + ], + "args": { + "sorter_num": "5", + "merger_num": "5" + } + }, + { + "list": [ + "merger", + "merger", + "merger", + "merger", + "merger" + ], + "args": { + "sorter_num": "5", + "merger_num": "5" + } + }, + { + "list": [ + "checker" + ], + "args": { + "sorter_num": "5", + "merger_num": "5" + } + } + ] + } \ No newline at end of file diff --git a/isol_config/wasmtime_trans_data.json b/isol_config/wasmtime_trans_data.json new file mode 100644 index 00000000..33a1af2c --- /dev/null +++ b/isol_config/wasmtime_trans_data.json @@ -0,0 +1,30 @@ +{ + "services": [ + [ + "fdtab", + "libruxfdtab.so" + ], + [ + "stdio", + "libstdio.so" + ], + [ + "mm", + "libmm.so" + ], + [ + "time", + "libtime.so" + ], + [ + "fatfs", + "libfatfs.so" + ] + ], + "apps": [ + [ + "trans_data", + "libwasmtime_trans_data.so" + ] + ] + } \ No newline at end of file diff --git a/isol_config/wasmtime_wordcount.json b/isol_config/wasmtime_wordcount.json new file mode 100644 index 00000000..6d95f27b --- /dev/null +++ b/isol_config/wasmtime_wordcount.json @@ -0,0 +1,45 @@ +{ + "services": [ + [ + "fdtab", + "libruxfdtab.so" + ], + [ + "stdio", + "libstdio.so" + ], + [ + "mm", + "libmm.so" + ], + [ + "time", + "libtime.so" + ], + [ + "fatfs", + "libfatfs.so" + ] + ], + "apps": [ + [ + "mapper", + "libwasmtime_mapper.so" + ], + [ + "reducer", + "libwasmtime_reducer.so" + ] + ], + "fs_image": "fs_images/fatfs_large.img", + "groups": [ + { + "list": [ + "mapper" + ], + "args": { + "reducer_num": "1" + } + } + ] + } \ No newline at end of file diff --git a/isol_config/wasmtime_wordcount_c1.json b/isol_config/wasmtime_wordcount_c1.json new file mode 100644 index 00000000..40d1a3c9 --- /dev/null +++ b/isol_config/wasmtime_wordcount_c1.json @@ -0,0 +1,53 @@ +{ + "services": [ + [ + "fdtab", + "libruxfdtab.so" + ], + [ + "stdio", + "libstdio.so" + ], + [ + "mm", + "libmm.so" + ], + [ + "time", + "libtime.so" + ], + [ + "fatfs", + "libfatfs.so" + ] + ], + "apps": [ + [ + "mapper", + "libwasmtime_mapper.so" + ], + [ + "reducer", + "libwasmtime_reducer.so" + ] + ], + "fs_image": "fs_images/new_image.img", + "groups": [ + { + "list": [ + "mapper" + ], + "args": { + "reducer_num": "1" + } + }, + { + "list": [ + "reducer" + ], + "args": { + "mapper_num": "1" + } + } + ] + } \ No newline at end of file diff --git a/isol_config/wasmtime_wordcount_c3.json b/isol_config/wasmtime_wordcount_c3.json new file mode 100644 index 00000000..86403831 --- /dev/null +++ b/isol_config/wasmtime_wordcount_c3.json @@ -0,0 +1,57 @@ +{ + "services": [ + [ + "fdtab", + "libruxfdtab.so" + ], + [ + "stdio", + "libstdio.so" + ], + [ + "mm", + "libmm.so" + ], + [ + "time", + "libtime.so" + ], + [ + "fatfs", + "libfatfs.so" + ] + ], + "apps": [ + [ + "mapper", + "libwasmtime_mapper.so" + ], + [ + "reducer", + "libwasmtime_reducer.so" + ] + ], + "fs_image": "fs_images/new_image.img", + "groups": [ + { + "list": [ + "mapper", + "mapper", + "mapper" + ], + "args": { + "reducer_num": "3" + } + }, + { + "list": [ + "reducer", + "reducer", + "reducer" + ], + "args": { + "mapper_num": "3" + } + } + ] + } \ No newline at end of file diff --git a/isol_config/wasmtime_wordcount_c5.json b/isol_config/wasmtime_wordcount_c5.json new file mode 100644 index 00000000..61f11e2b --- /dev/null +++ b/isol_config/wasmtime_wordcount_c5.json @@ -0,0 +1,61 @@ +{ + "services": [ + [ + "fdtab", + "libruxfdtab.so" + ], + [ + "stdio", + "libstdio.so" + ], + [ + "mm", + "libmm.so" + ], + [ + "time", + "libtime.so" + ], + [ + "fatfs", + "libfatfs.so" + ] + ], + "apps": [ + [ + "mapper", + "libwasmtime_mapper.so" + ], + [ + "reducer", + "libwasmtime_reducer.so" + ] + ], + "fs_image": "fs_images/new_image.img", + "groups": [ + { + "list": [ + "mapper", + "mapper", + "mapper", + "mapper", + "mapper" + ], + "args": { + "reducer_num": "5" + } + }, + { + "list": [ + "reducer", + "reducer", + "reducer", + "reducer", + "reducer" + ], + "args": { + "mapper_num": "5" + } + } + ] + } \ No newline at end of file diff --git a/isol_config/wasmtime_write.json b/isol_config/wasmtime_write.json new file mode 100644 index 00000000..6fae02e5 --- /dev/null +++ b/isol_config/wasmtime_write.json @@ -0,0 +1,26 @@ +{ + "services": [ + [ + "fdtab", + "libfdtab.so" + ], + [ + "stdio", + "libstdio.so" + ] + ], + "apps": [ + [ + "hello", + "libwasmtime_write.so" + ] + ], + "groups": [ + { + "list": [ + "hello" + ], + "args": {} + } + ] +} \ No newline at end of file diff --git a/ms_hostcall/Cargo.toml b/ms_hostcall/Cargo.toml index 8e6f2696..229c7153 100644 --- a/ms_hostcall/Cargo.toml +++ b/ms_hostcall/Cargo.toml @@ -19,6 +19,7 @@ thiserror-no-std = "2.0.2" [features] fatfs = [] socket = [] +signal = [] fdtab = ["fatfs", "socket"] mmap_file_backend = ["fdtab"] diff --git a/ms_hostcall/src/lib.rs b/ms_hostcall/src/lib.rs index 8d630f7f..8d0ba84c 100644 --- a/ms_hostcall/src/lib.rs +++ b/ms_hostcall/src/lib.rs @@ -16,6 +16,8 @@ pub mod mm; pub mod mmap_file_backend; #[cfg(feature = "socket")] pub mod socket; +#[cfg(feature = "signal")] +pub mod signal; pub mod types; use alloc::{borrow::ToOwned, string::String}; @@ -97,6 +99,8 @@ pub enum CommonHostCall { Mmap, #[display(fmt = "libos_munmap")] Munmap, + #[display(fmt = "libos_mprotect")] + Mprotect, #[display(fmt = "register_file_backend")] RegisterFileBackend, @@ -109,6 +113,9 @@ pub enum CommonHostCall { GetTime, #[display(fmt = "host_nanosleep")] NanoSleep, + + #[display(fmt = "libos_sigaction")] + SigAction, } #[derive(Debug, Display)] @@ -158,12 +165,15 @@ impl HostCallID { | CommonHostCall::AccessBuffer | CommonHostCall::BufferDealloc | CommonHostCall::Mmap - | CommonHostCall::Munmap => "mm".to_owned(), + | CommonHostCall::Munmap + | CommonHostCall::Mprotect => "mm".to_owned(), CommonHostCall::RegisterFileBackend | CommonHostCall::FilePageFaultHandler | CommonHostCall::UnregisterFileBackend => "mmap_file_backend".to_owned(), + CommonHostCall::SigAction => "signal".to_owned(), + CommonHostCall::GetTime | CommonHostCall::NanoSleep => "time".to_owned(), }, HostCallID::Custom(_) => todo!(), diff --git a/ms_hostcall/src/mm.rs b/ms_hostcall/src/mm.rs index c199c0b3..8f8f1530 100644 --- a/ms_hostcall/src/mm.rs +++ b/ms_hostcall/src/mm.rs @@ -11,15 +11,16 @@ bitflags! { pub struct ProtFlags: u32 { const READ = 1; const WRITE = 2; - // const EXEC = 3; + const EXEC = 4; } } pub type BufferAllocFunc = fn(&str, Layout, u64) -> MMResult; pub type AccessBufferFunc = fn(&str) -> Option<(usize, u64)>; pub type BufferDeallocFunc = fn(usize, Layout); -pub type MemmapFunc = fn(usize, ProtFlags, Fd) -> MMResult; -pub type MemunmapFunc = fn(&mut [u8]) -> MMResult<()>; +pub type MemmapFunc = fn(usize, usize, ProtFlags, Fd) -> MMResult; +pub type MemunmapFunc = fn(&mut [u8], bool) -> MMResult<()>; +pub type MprotectFunc = fn(usize, usize, ProtFlags) -> MMResult<()>; pub type MMResult = Result; diff --git a/ms_hostcall/src/signal.rs b/ms_hostcall/src/signal.rs new file mode 100644 index 00000000..5adb5d88 --- /dev/null +++ b/ms_hostcall/src/signal.rs @@ -0,0 +1,133 @@ +pub type SigActionFunc = unsafe extern "C" fn(i32, *const SigAction, *const SigAction) -> i32; + +#[repr(C)] +#[derive(Clone, Copy)] +pub struct SigInfo { + pub siginfo: SigInfoIntern, + si_pad: [u8; 128], +} + +#[repr(C)] +#[derive(Clone, Copy)] +pub struct SigAction { + pub sa_handler: usize, + pub sa_flags: usize, + // pub sa_restorer: Option, + pub sa_mask: Sigset, +} + +#[repr(C)] +#[derive(Clone, Copy)] +pub struct Ucontext { + pub uc_flags: u64, + pub uc_link: *const Ucontext, + pub uc_stack: StackT, + pub uc_mcontext: Mcontext, + pub uc_sigmask: Sigset, +} + +#[repr(C)] +#[derive(Clone, Copy)] +pub struct StackT { + pub ss_sp: *mut u8, + pub ss_flags: i32, + pub ss_size: usize, +} + +#[repr(C)] +#[derive(Clone, Copy)] +pub struct Mcontext { + pub gregs: [usize; 23], + pub fpregs: *const u8, + pub __reserved1: [usize; 8], +} + +#[repr(C)] +#[derive(Clone, Copy)] +pub struct Sigset { + pub sig: [usize; 1], +} + +#[repr(C)] +#[derive(Clone, Copy)] +pub struct SigInfoIntern { + pub si_signo: i32, + pub si_errno: i32, + pub si_code: i32, + pub sifields: Sifields, +} + + +#[repr(C)] +#[derive(Clone, Copy)] +pub union Sifields { + pub kill: si_kill_t, + + pub timer: si_timer_t, + + pub rt: si_rt_t, + + pub sigchld: si_sigchld_t, + pub sigpoll: si_sigpoll_t, + + pub sigsys: si_sigsys_t, +} + +#[repr(C)] +#[derive(Clone, Copy)] +pub struct si_rt_t { + /// sender's pid + pub pid: i32, + /// sender's uid + pub uid: u32, + pub sigval: sigval_t, +} + +#[repr(C)] +#[derive(Debug, Default, Clone, Copy)] +pub struct si_sigpoll_t { + /// `POLL_IN`, `POLL_OUT`, `POLL_MSG` + pub band: isize, + pub fd: i32, +} + +#[repr(C)] +#[derive(Clone, Copy)] +pub union sigval_t { + pub sival_int: i32, + pub sival_ptr: usize, +} + +#[repr(C)] +#[derive(Debug, Default, Clone, Copy)] +pub struct si_sigsys_t { + pub call_addr: usize, + pub syscall: i32, + pub arch: u32, +} + +#[repr(C)] +#[derive(Clone, Copy)] +pub struct si_timer_t { + pub tid: i32, + pub overrun: i32, + pub sigval: sigval_t, + sys_private: i32, +} + +#[repr(C)] +#[derive(Debug, Default, Clone, Copy)] +pub struct si_kill_t { + pub pid: i32, + pub uid: u32, +} + +#[repr(C)] +#[derive(Debug, Default, Clone, Copy)] +pub struct si_sigchld_t { + pub pid: i32, + pub uid: u32, + pub status: i32, + pub utime: isize, + pub stime: isize, +} diff --git a/ms_std/src/agent.rs b/ms_std/src/agent.rs index 5685d778..07c8ad4e 100644 --- a/ms_std/src/agent.rs +++ b/ms_std/src/agent.rs @@ -7,7 +7,12 @@ use alloc::{ }; use ms_hostcall::Verify; -use crate::{libos::libos, println}; +use crate::{libos::libos, println, time::{SystemTime, UNIX_EPOCH},}; + +pub static mut PHASE31: u128 = 0; +pub static mut PHASE32: u128 = 0; +pub static mut PHASE33: u128 = 0; +pub static mut PHASE34: u128 = 0; pub type FaaSFuncResult = Result, FaaSFuncError>; @@ -87,16 +92,26 @@ where } pub fn from_buffer_slot(slot: String) -> Option { + unsafe { + PHASE31 = SystemTime::now().duration_since(UNIX_EPOCH).as_nanos(); + } let buffer_meta: Option<(usize, u64)> = libos!(access_buffer(&slot)); - + unsafe { + PHASE32 = SystemTime::now().duration_since(UNIX_EPOCH).as_nanos(); + } buffer_meta.map(|(raw_ptr, fingerprint)| { if fingerprint != T::__fingerprint() { println!("wrong data type, {}, {}", fingerprint, T::__fingerprint()); panic!(""); }; + unsafe { + PHASE33 = SystemTime::now().duration_since(UNIX_EPOCH).as_nanos(); + } let inner = unsafe { Box::from_raw(raw_ptr as *mut T) }; - + unsafe { + PHASE34 = SystemTime::now().duration_since(UNIX_EPOCH).as_nanos(); + } Self { inner: ManuallyDrop::new(inner), used: true, diff --git a/ms_std/src/lib.rs b/ms_std/src/lib.rs index 2d3f751e..5737794d 100644 --- a/ms_std/src/lib.rs +++ b/ms_std/src/lib.rs @@ -50,7 +50,7 @@ cfg_if::cfg_if! { #[panic_handler] fn panic_handler(_info: &PanicInfo) -> ! { let panic_addr = isolation_ctx().panic_handler; - + crate::println!("panic_handler: {:?}", _info); let host_panic_handler: unsafe extern "C" fn() -> ! = unsafe { core::mem::transmute(panic_addr) }; unsafe { host_panic_handler() } diff --git a/ms_std/src/libos/mod.rs b/ms_std/src/libos/mod.rs index 9e27c7cd..bb767b6b 100644 --- a/ms_std/src/libos/mod.rs +++ b/ms_std/src/libos/mod.rs @@ -57,6 +57,7 @@ pub struct UserHostCall { dealloc_buffer_addr: Option, mmap_addr: Option, munmap_addr: Option, + mprotect_addr: Option, pf_handler_addr: Option, register_file_backend_addr: Option, @@ -64,6 +65,8 @@ pub struct UserHostCall { get_time_addr: Option, nanosleep_addr: Option, + + sigaction_addr: Option, } impl UserHostCall { @@ -114,6 +117,7 @@ impl UserHostCall { CommonHostCall::BufferDealloc => &mut self.dealloc_buffer_addr, CommonHostCall::Mmap => &mut self.mmap_addr, CommonHostCall::Munmap => &mut self.munmap_addr, + CommonHostCall::Mprotect => &mut self.mprotect_addr, CommonHostCall::RegisterFileBackend => &mut self.register_file_backend_addr, CommonHostCall::UnregisterFileBackend => &mut self.unregister_file_backend_addr, @@ -121,6 +125,8 @@ impl UserHostCall { CommonHostCall::GetTime => &mut self.get_time_addr, CommonHostCall::NanoSleep => &mut self.nanosleep_addr, + + CommonHostCall::SigAction => &mut self.sigaction_addr, }; if entry_addr.is_none() { diff --git a/ms_std/src/libos/utils.rs b/ms_std/src/libos/utils.rs index 0bd382cd..12b5a622 100644 --- a/ms_std/src/libos/utils.rs +++ b/ms_std/src/libos/utils.rs @@ -33,10 +33,12 @@ pub macro func_type { (buffer_dealloc) => (ms_hostcall::mm::BufferDeallocFunc), (mmap) => (ms_hostcall::mm::MemmapFunc), (munmap) => (ms_hostcall::mm::MemunmapFunc), + (mprotect) => (ms_hostcall::mm::MprotectFunc), (register_file_backend) => (ms_hostcall::mmap_file_backend::RegisterFileBackendFunc), (unregister_file_backend) => (ms_hostcall::mmap_file_backend::UnregisterFileBackendFunc), (get_time) => (ms_hostcall::types::GetTimeFunc), (nanosleep) => (ms_hostcall::types::NanoSleepFunc), + (sigaction) => (ms_hostcall::signal::SigActionFunc), } pub macro hostcall_id { @@ -72,10 +74,12 @@ pub macro hostcall_id { (buffer_dealloc) => (ms_hostcall::CommonHostCall::BufferDealloc), (mmap) => (ms_hostcall::CommonHostCall::Mmap), (munmap) => (ms_hostcall::CommonHostCall::Munmap), + (mprotect) => (ms_hostcall::CommonHostCall::Mprotect), (register_file_backend) => (ms_hostcall::CommonHostCall::RegisterFileBackend), (unregister_file_backend) => (ms_hostcall::CommonHostCall::UnregisterFileBackend), (get_time) => (ms_hostcall::CommonHostCall::GetTime), (nanosleep) => (ms_hostcall::CommonHostCall::NanoSleep), + (sigaction) => (ms_hostcall::CommonHostCall::SigAction), } pub macro libos { diff --git a/ms_std/src/mm.rs b/ms_std/src/mm.rs index c36fed3d..2ba8df42 100644 --- a/ms_std/src/mm.rs +++ b/ms_std/src/mm.rs @@ -28,7 +28,7 @@ impl Mmap { let file = ManuallyDrop::new(file); let length = file.metadata()?.st_size; let aligned_length = (length + PAGE_SIZE - 1) & (!PAGE_SIZE + 1); - let ptr = libos!(mmap(aligned_length, ProtFlags::READ, file.as_raw_fd()))?; + let ptr = libos!(mmap(0, aligned_length, ProtFlags::READ, file.as_raw_fd()))?; Ok(Mmap { ptr, length }) } @@ -43,6 +43,6 @@ impl AsRef<[u8]> for Mmap { impl Drop for Mmap { fn drop(&mut self) { let region = unsafe { slice::from_raw_parts_mut(self.ptr as *mut u8, self.length) }; - libos!(munmap(region)).expect("munmap failed") + libos!(munmap(region, true)).expect("munmap failed") } } diff --git a/scripts/build_user.sh b/scripts/build_user.sh index f34f6ab3..527394b5 100755 --- a/scripts/build_user.sh +++ b/scripts/build_user.sh @@ -26,9 +26,6 @@ find user -name 'Cargo.toml' \ -not -path 'user/simple_http/Cargo.toml' \ -not -path 'user/never_stop/Cargo.toml' \ -not -path 'user/hello_world/Cargo.toml' \ - -not -path 'user/tinywasm_pass_str/Cargo.toml' \ - -not -path 'user/tinywasm_u/Cargo.toml' \ - -not -path 'user/tinywasm_write/Cargo.toml' \ - -not -path 'user/tinywasm_recv_str/Cargo.toml' \ - -not -path 'user/tinywasm_c_printf/Cargo.toml' | \ + -not -path 'user/tinywasm*/Cargo.toml' \ + -not -path 'user/wasmtime*/Cargo.toml' | \ xargs -I {} bash -c "cargo build $feature_arg --manifest-path {} $release_flag" \ No newline at end of file diff --git a/scripts/c_end_to_end.sh b/scripts/c_end_to_end.sh new file mode 100644 index 00000000..e69de29b diff --git a/scripts/gen_data.py b/scripts/gen_data.py index b158e533..b672816b 100755 --- a/scripts/gen_data.py +++ b/scripts/gen_data.py @@ -7,10 +7,12 @@ def gen_word_count(file_num: int, total_size: int): from faker import Faker fake = Faker() + # 设置种子 + Faker.seed(42) # 使用固定的种子值 one_size = int(total_size / file_num) for i in range(file_num): - file_name = f'fake_data_{i}.txt' + file_name = f'./image_content/fake_data_{i}.txt' with open(file_name, 'w') as f: while True: f.write(fake.text(10_000)) @@ -21,10 +23,11 @@ def gen_word_count(file_num: int, total_size: int): def gen_parallel_sort(file_num: int, total_size: int): import random + random.seed(42) one_size = int(total_size / file_num) for i in range(file_num): - file_name = f'part-{i}' + file_name = f'./image_content/sort_data_{i}.txt' first = True with open(file_name, 'w') as f: @@ -43,4 +46,5 @@ def gen_parallel_sort(file_num: int, total_size: int): if __name__ == "__main__": - gen_parallel_sort(1, 5*1024*1024) + # gen_word_count(3, 10 * 1024 * 1024) + gen_parallel_sort(3, 25 * 1024 * 1024) diff --git a/scripts/long_chain_parallel.py b/scripts/long_chain_parallel.py new file mode 100755 index 00000000..ca10eb41 --- /dev/null +++ b/scripts/long_chain_parallel.py @@ -0,0 +1,42 @@ +#!/usr/bin/python3 + +import subprocess +import re + +# 并行执行 ./scripts/rust_end_to_end.sh long_chain n5 + + +def test_long_chain_parallel(): + import concurrent.futures + + def run_script(instance): + command = f"./scripts/rust_end_to_end.sh long_chain {instance}" + result = subprocess.run(command, shell=True, + capture_output=True, text=True) + return result.stdout, result.stderr + + instances = ['n5', 'n5', 'n5', 'n5', 'n5', 'n5', 'n5', + 'n5', 'n5', 'n5'] # Add more instances as needed + latencies = [] + + with concurrent.futures.ThreadPoolExecutor() as executor: + futures = [executor.submit(run_script, instance) + for instance in instances] + for future in concurrent.futures.as_completed(futures): + stdout, stderr = future.result() + # 从 stdout 中提取 'Total Dur (ms): 37.825' 中的数字 + for line in stdout.splitlines(): + match = re.search(r'Total Dur \(ms\): (\d+\.\d+)', line) + if match: + duration = float(match.group(1)) + # print("Total Duration (ms):", duration) + latencies.append(duration) + # print("Output:", stdout) + if stderr: + print("Error:", stderr) + + print("Latencies:", sorted(latencies)) + + +if __name__ == '__main__': + test_long_chain_parallel() diff --git a/scripts/map_reduce_parallel.py b/scripts/map_reduce_parallel.py new file mode 100755 index 00000000..b3b63270 --- /dev/null +++ b/scripts/map_reduce_parallel.py @@ -0,0 +1,42 @@ +#!/usr/bin/python3 + +import subprocess +import re + +# 并行执行 ./scripts/rust_end_to_end.sh map_reduce c3 + + +def test_map_reduce_parallel(): + import concurrent.futures + + def run_script(instance): + command = f"./scripts/rust_end_to_end.sh map_reduce {instance}" + result = subprocess.run(command, shell=True, + capture_output=True, text=True) + return result.stdout, result.stderr + + instances = ['c3', 'c3', 'c3', 'c3', 'c3', 'c3', 'c3', + 'c3', 'c3', 'c3'] # Add more instances as needed + latencies = [] + + with concurrent.futures.ThreadPoolExecutor() as executor: + futures = [executor.submit(run_script, instance) + for instance in instances] + for future in concurrent.futures.as_completed(futures): + stdout, stderr = future.result() + # 从 stdout 中提取 'Total Dur (ms): 37.825' 中的数字 + for line in stdout.splitlines(): + match = re.search(r'Total Dur \(ms\): (\d+\.\d+)', line) + if match: + duration = float(match.group(1)) + # print("Total Duration (ms):", duration) + latencies.append(duration) + # print("Output:", stdout) + if stderr: + print("Error:", stderr) + + print("Latencies:", sorted(latencies)) + + +if __name__ == '__main__': + test_map_reduce_parallel() diff --git a/scripts/run_tests.sh b/scripts/run_tests.sh index e273eb24..f4934ca2 100755 --- a/scripts/run_tests.sh +++ b/scripts/run_tests.sh @@ -3,7 +3,7 @@ declare -A test_groups=( [faasflow_test]="long_chain map_reduce pass_complex_args" [file_test]="simple_file" - [wasm_test]="tinywasm_wordcount tinywasm_parallel_sort tinywasm_cpython" + # [wasm_test]="tinywasm_wordcount tinywasm_parallel_sort tinywasm_cpython" ) passed_count=0 diff --git a/scripts/rust_cold_start.sh b/scripts/rust_cold_start.sh index 10d1dc25..e3753818 100755 --- a/scripts/rust_cold_start.sh +++ b/scripts/rust_cold_start.sh @@ -1,7 +1,7 @@ #!/bin/bash # 定义执行次数 -EXECUTIONS=100 +EXECUTIONS=10 # 初始化变量来累加 total_dur 的值 total_dur_sum=0 @@ -10,7 +10,7 @@ if [ -f "./user/hello_world/Cargo.toml" ]; then cargo clean --manifest-path ./user/hello_world/Cargo.toml fi -cargo build --features mpk --manifest-path ./user/hello_world/Cargo.toml --release +cargo build --manifest-path ./user/hello_world/Cargo.toml --release # 循环执行十次 for (( i=1; i<=EXECUTIONS; i++ )) @@ -18,7 +18,8 @@ do echo "Running iteration $i..." # 运行项目并提取 "total_dur(ms)" 的值 - output=$(cargo run --release --features mpk -- --metrics all --files ./isol_config/base_config.json 2>&1) + output=$(cargo run --release -- --metrics all --files ./isol_config/base_config.json 2>&1) + # output=$(cargo run --release -- --preload --metrics all --files ./isol_config/base_config.json 2>&1) total_dur=$(echo "$output" | grep -o '"total_dur(ms)": [0-9.]*' | awk -F': ' '{print $2}') # 保留三位小数,并进行四舍五入 diff --git a/scripts/rust_data_trans.sh b/scripts/rust_data_trans.sh index e784322c..d1e818ff 100755 --- a/scripts/rust_data_trans.sh +++ b/scripts/rust_data_trans.sh @@ -7,16 +7,10 @@ if [ -f "./user/func_a/Cargo.toml" ]; then cargo clean --manifest-path ./user/func_a/Cargo.toml fi -if [ -f "./user/func_b/Cargo.toml" ]; then - cargo clean --manifest-path ./user/func_b/Cargo.toml -fi - -cargo build --features mpk --manifest-path ./user/func_a/Cargo.toml --release -cargo build --features mpk --manifest-path ./user/func_b/Cargo.toml --release +cargo build --manifest-path ./user/func_a/Cargo.toml --release # 初始化变量来累加 total_dur 的值 total_dur_sum=0 -total_rate_sum=0 # 循环执行十次 for (( i=1; i<=EXECUTIONS; i++ )) @@ -24,35 +18,18 @@ do echo "Running iteration $i..." # 运行项目并提取 "total_dur(ms)" 的值 - # output=$(cargo run --release --features mpk -- --preload --metrics all --files ./isol_config/pass_complex_args.json 2>&1) - output=$(cargo run --release --features mpk -- --metrics all --files ./isol_config/pass_complex_args.json 2>&1) - total_dur=$(echo "$output" | grep -o '"total_dur(ms)": [0-9.]*' | awk -F': ' '{print $2}') - - # 提取 trans data time、total_size 和 transfer rate - # trans_data_time=$(echo "$output" | grep -o 'trans data time: [0-9.]*µs' | awk -F': ' '{print $2}' | awk -F'µs' '{print $1}') - trans_data_time=$(echo "$output" | grep -o 'trans data time: [0-9.]*[µm]s' | awk -F': ' '{print $2}' | awk '{ - if ($1 ~ /µs$/) { - print $1 - } else if ($1 ~ /ms$/) { - gsub(/ms$/, "", $1) - print $1 * 1000 "µs" - } - }' | awk -F'µs' '{print $1}') - total_size=$(echo "$output" | grep -o 'total_size: [0-9]* Bytes' | awk -F': ' '{print $2}' | awk -F' Bytes' '{print $1}') - transfer_rate=$(echo "$output" | grep -o 'transfer rate: [0-9]* MB/s' | awk -F': ' '{print $2}' | awk -F' MB/s' '{print $1}') - + # output=$(cargo run --release -- --preload --metrics all --files ./isol_config/pass_complex_args.json 2>&1) + output=$(cargo run --release -- --preload --files ./isol_config/pass_complex_args.json 2>&1) + + total_dur=$(echo "$output" | grep 'opt_dur=' | cut -d'=' -f2) # 累加 total_dur 的值 - total_dur_sum=$(echo "$total_dur_sum + $trans_data_time" | bc) - - # 累加 total_rate 的值 - total_rate_sum=$(echo "$total_rate_sum + $transfer_rate" | bc) + total_dur_sum=$(echo "$total_dur_sum + $total_dur" | bc) # 打印结果 - echo "$trans_data_time $total_size $transfer_rate" + echo "$total_dur" done + # 计算平均值 -average_total_dur=$(echo "scale=3; $total_dur_sum / $EXECUTIONS" | bc) -echo "Average Total Dur (us): $average_total_dur" -average_total_rate=$(echo "scale=3; $total_rate_sum / $EXECUTIONS" | bc) -echo "Average Total Dur (MB/s): $average_total_rate" +average_total_dur=$(echo "scale=6; $total_dur_sum / $EXECUTIONS / 1000" | bc) +echo "Average Total Dur (ms): $average_total_dur" \ No newline at end of file diff --git a/scripts/rust_end_to_end.sh b/scripts/rust_end_to_end.sh index 41adc6c5..74d9d179 100755 --- a/scripts/rust_end_to_end.sh +++ b/scripts/rust_end_to_end.sh @@ -16,14 +16,10 @@ fi case $1 in "long_chain") echo "Executing long_chain" - if [ -f "./user/file_reader/Cargo.toml" ]; then - cargo clean --manifest-path ./user/file_reader/Cargo.toml - fi - if [ -f "./user/array_sum/Cargo.toml" ]; then - cargo clean --manifest-path ./user/array_sum/Cargo.toml - fi - cargo build --features mpk --manifest-path ./user/file_reader/Cargo.toml --release - cargo build --features mpk --manifest-path ./user/array_sum/Cargo.toml --release + # if [ -f "./user/array_sum/Cargo.toml" ]; then + # cargo clean --manifest-path ./user/array_sum/Cargo.toml + # fi + # cargo build --manifest-path ./user/array_sum/Cargo.toml --release # 循环执行十次 for (( i=1; i<=EXECUTIONS; i++ )) @@ -32,17 +28,21 @@ case $1 in # 运行项目并提取 "total_dur(ms)" 的值 case $2 in - "c1") + "n5") echo "Executing c1" - output=$(cargo run --release --features mpk -- --metrics all --files ./isol_config/long_chain_c1.json 2>&1) + # output=$(cargo run --release -- --metrics all --files ./isol_config/long_chain_c1.json 2>&1) + # output=$(cargo run --release -- --preload --metrics all --files ./isol_config/long_chain_n5.json 2>&1) + output=$(./target/release/msvisor --preload --metrics all --files ./isol_config/long_chain_n5.json 2>&1) ;; - "c3") + "n10") echo "Executing c3" - output=$(cargo run --release --features mpk -- --metrics all --files ./isol_config/long_chain_c3.json 2>&1) + # output=$(cargo run --release -- --metrics all --files ./isol_config/long_chain_c3.json 2>&1) + output=$(cargo run --release -- --preload --metrics all --files ./isol_config/long_chain_n10.json 2>&1) ;; - "c5") + "n15") echo "Executing c5" - output=$(cargo run --release --features mpk -- --metrics all --files ./isol_config/long_chain_c5.json 2>&1) + # output=$(cargo run --release -- --metrics all --files ./isol_config/long_chain_c5.json 2>&1) + output=$(cargo run --release -- --preload --metrics all --files ./isol_config/long_chain_n15.json 2>&1) ;; *) echo "Unknown command: $2" @@ -66,18 +66,14 @@ case $1 in ;; "map_reduce") echo "Executing map_reduce" - if [ -f "./user/file_reader/Cargo.toml" ]; then - cargo clean --manifest-path ./user/file_reader/Cargo.toml - fi - if [ -f "./user/mapper/Cargo.toml" ]; then - cargo clean --manifest-path ./user/mapper/Cargo.toml - fi - if [ -f "./user/reducer/Cargo.toml" ]; then - cargo clean --manifest-path ./user/reducer/Cargo.toml - fi - cargo build --features mpk --manifest-path ./user/file_reader/Cargo.toml --release - cargo build --features mpk --manifest-path ./user/mapper/Cargo.toml --release - cargo build --features mpk --manifest-path ./user/reducer/Cargo.toml --release + # if [ -f "./user/mapper/Cargo.toml" ]; then + # cargo clean --manifest-path ./user/mapper/Cargo.toml + # fi + # if [ -f "./user/reducer/Cargo.toml" ]; then + # cargo clean --manifest-path ./user/reducer/Cargo.toml + # fi + # cargo build --manifest-path ./user/mapper/Cargo.toml --release + # cargo build --manifest-path ./user/reducer/Cargo.toml --release # 循环执行十次 for (( i=1; i<=EXECUTIONS; i++ )) do @@ -87,15 +83,18 @@ case $1 in case $2 in "c1") echo "Executing c1" - output=$(cargo run --release --features mpk -- --metrics all --files ./isol_config/map_reduce_large_c1.json 2>&1) + output=$(cargo run --release -- --metrics all --files ./isol_config/map_reduce_large_c1.json 2>&1) + # output=$(cargo run --release -- --preload --metrics all --files ./isol_config/map_reduce_large_c1.json 2>&1) ;; "c3") echo "Executing c3" - output=$(cargo run --release --features mpk -- --metrics all --files ./isol_config/map_reduce_large_c3.json 2>&1) + # output=$(cargo run --release -- --metrics all --files ./isol_config/map_reduce_large_c3.json 2>&1) + output=$(./target/release/msvisor --metrics all --files ./isol_config/map_reduce_large_c3.json 2>&1) ;; "c5") echo "Executing c5" - output=$(cargo run --release --features mpk -- --metrics all --files ./isol_config/map_reduce_large_c5.json 2>&1) + # output=$(cargo run --release -- --metrics all --files ./isol_config/map_reduce_large_c5.json 2>&1) + output=$(cargo run --release -- --metrics all --files ./isol_config/map_reduce_large_c5.json 2>&1) ;; *) echo "Unknown command: $2" @@ -131,10 +130,10 @@ case $1 in if [ -f "./user/checker/Cargo.toml" ]; then cargo clean --manifest-path ./user/checker/Cargo.toml fi - cargo build --features mpk --manifest-path ./user/sorter/Cargo.toml --release - cargo build --features mpk --manifest-path ./user/splitter/Cargo.toml --release - cargo build --features mpk --manifest-path ./user/merger/Cargo.toml --release - cargo build --features mpk --manifest-path ./user/checker/Cargo.toml --release + cargo build --manifest-path ./user/sorter/Cargo.toml --release + cargo build --manifest-path ./user/splitter/Cargo.toml --release + cargo build --manifest-path ./user/merger/Cargo.toml --release + cargo build --manifest-path ./user/checker/Cargo.toml --release # 循环执行十次 for (( i=1; i<=EXECUTIONS; i++ )) do @@ -145,15 +144,18 @@ case $1 in case $2 in "c1") echo "Executing c1" - output=$(cargo run --release --features mpk -- --metrics all --files ./isol_config/parallel_sort_c1.json 2>&1) + # output=$(cargo run --release -- --metrics all --files ./isol_config/parallel_sort_c1.json 2>&1) + output=$(cargo run --release -- --preload --metrics all --files ./isol_config/parallel_sort_c1.json 2>&1) ;; "c3") echo "Executing c3" - output=$(cargo run --release --features mpk -- --metrics all --files ./isol_config/parallel_sort_c3.json 2>&1) + # output=$(cargo run --release -- --metrics all --files ./isol_config/parallel_sort_c3.json 2>&1) + output=$(cargo run --release -- --preload --metrics all --files ./isol_config/parallel_sort_c3.json 2>&1) ;; "c5") echo "Executing c5" - output=$(cargo run --release --features mpk -- --metrics all --files ./isol_config/parallel_sort_c5.json 2>&1) + # output=$(cargo run --release -- --metrics all --files ./isol_config/parallel_sort_c5.json 2>&1) + output=$(cargo run --release -- --preload --metrics all --files ./isol_config/parallel_sort_c5.json 2>&1) ;; *) echo "Unknown command: $2" diff --git a/scripts/wasmtime_data_trans.sh b/scripts/wasmtime_data_trans.sh new file mode 100755 index 00000000..7f0bcb08 --- /dev/null +++ b/scripts/wasmtime_data_trans.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# 定义执行次数 +EXECUTIONS=10 + +# 初始化变量来累加 total_dur 的值 +total_dur_sum=0 + +# 循环执行十次 +for (( i=1; i<=EXECUTIONS; i++ )) +do + echo "Running iteration $i..." + + output=$(cargo run --release -- --preload --files ./isol_config/wasmtime_trans_data.json 2>&1) + + numbers=($(echo "$output" | grep -o '[0-9]\+\.[0-9]\+')) + + # 获取最后两个数字 + num1=${numbers[-2]} + num2=${numbers[-1]} + + # 计算差值 + difference=$(echo "$num2 - $num1" | bc) + + # 累加 total_dur 的值 + total_dur_sum=$(echo "$total_dur_sum + $difference" | bc) + + # 打印结果 + echo "Difference: $difference" +done + + +# 计算平均值 +average_total_dur=$(echo "scale=3; $total_dur_sum * 1000 / $EXECUTIONS" | bc) +echo "Average Total Dur (ms): $average_total_dur" \ No newline at end of file diff --git a/scripts/wasmtime_end_to_end.sh b/scripts/wasmtime_end_to_end.sh new file mode 100755 index 00000000..be271840 --- /dev/null +++ b/scripts/wasmtime_end_to_end.sh @@ -0,0 +1,109 @@ +#!/bin/bash + +# 定义执行次数 +EXECUTIONS=10 + +# 初始化变量来累加 total_dur 的值 +total_dur_sum=0 + +# 检查是否有参数传递 +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +# 根据第一个参数决定执行哪个命令 +case $1 in + "long_chain") + echo "Executing long_chain" + ;; + "map_reduce") + echo "Executing map_reduce" + + # 循环执行十次 + for (( i=1; i<=EXECUTIONS; i++ )) + do + echo "Running iteration $i..." + + # 运行项目并提取 "total_dur(ms)" 的值 + case $2 in + "c1") + echo "Executing c1" + output=$(cargo run --release -- --metrics all --files ./isol_config/wasmtime_wordcount_c1.json 2>&1) + ;; + "c3") + echo "Executing c3" + output=$(cargo run --release -- --metrics all --files ./isol_config/wasmtime_wordcount_c3.json 2>&1) + ;; + "c5") + echo "Executing c5" + output=$(cargo run --release -- --metrics all --files ./isol_config/wasmtime_wordcount_c5.json 2>&1) + ;; + *) + echo "Unknown command: $2" + exit 1 + ;; + esac + total_dur=$(echo "$output" | grep -o '"total_dur(ms)": [0-9.]*' | awk -F': ' '{print $2}') + + # 保留三位小数,并进行四舍五入 + total_dur_rounded=$(printf "%.3f\n" "$total_dur") + + # 累加 total_dur 的值 + total_dur_sum=$(echo "$total_dur_sum + $total_dur_rounded" | bc) + + # 打印结果 + echo "Total Dur (ms): $total_dur_rounded" + done + # 计算平均值 + average_total_dur=$(echo "scale=3; $total_dur_sum / $EXECUTIONS" | bc) + echo "Average Total Dur (ms): $average_total_dur" + ;; + "parallel_sort") + echo "Executing parallel_sort" + # 循环执行十次 + for (( i=1; i<=EXECUTIONS; i++ )) + do + echo "Running iteration $i..." + + # 运行项目并提取 "total_dur(ms)" 的值 + + case $2 in + "c1") + echo "Executing c1" + output=$(cargo run --release -- --metrics all --files ./isol_config/wasmtime_parallel_sort_c1.json 2>&1) + ;; + "c3") + echo "Executing c3" + output=$(cargo run --release -- --metrics all --files ./isol_config/wasmtime_parallel_sort_c3.json 2>&1) + ;; + "c5") + echo "Executing c5" + output=$(cargo run --release -- --metrics all --files ./isol_config/wasmtime_parallel_sort_c5.json 2>&1) + ;; + *) + echo "Unknown command: $2" + exit 1 + ;; + esac + total_dur=$(echo "$output" | grep -o '"total_dur(ms)": [0-9.]*' | awk -F': ' '{print $2}') + + # 保留三位小数,并进行四舍五入 + total_dur_rounded=$(printf "%.3f\n" "$total_dur") + + # 累加 total_dur 的值 + total_dur_sum=$(echo "$total_dur_sum + $total_dur_rounded" | bc) + + # 打印结果 + echo "Total Dur (ms): $total_dur_rounded" + done + # 计算平均值 + average_total_dur=$(echo "scale=3; $total_dur_sum / $EXECUTIONS" | bc) + echo "Average Total Dur (ms): $average_total_dur" + ;; + *) + echo "Unknown command: $1" + exit 1 + ;; +esac + diff --git a/user/array_sum/src/lib.rs b/user/array_sum/src/lib.rs index 44ab6ed3..6bb1398f 100644 --- a/user/array_sum/src/lib.rs +++ b/user/array_sum/src/lib.rs @@ -3,16 +3,13 @@ extern crate alloc; // use alloc::vec::Vec; -use alloc::{borrow::ToOwned, format, string::String, vec::Vec}; +use alloc::{format, string::String}; // use ms_std::{ // agent::{DataBuffer, FaaSFuncResult as Result}, // println, // time::{SystemTime, UNIX_EPOCH}, // }; -use ms_std::{ - agent::{DataBuffer, FaaSFuncResult as Result}, - args, println, -}; +use ms_std::agent::{DataBuffer, FaaSFuncResult as Result}; use ms_std_proc_macro::FaasData; #[derive(Default, FaasData)] @@ -20,58 +17,45 @@ struct Reader2Arraysum { raw_data: String, } -// #[allow(dead_code)] -// #[derive(FaasData, Default, Clone)] -// pub struct ArrayData { -// // start_times: Vec, -// // end_times: Vec, -// n: i32, -// } +const DATA_SIZE: usize = 1024 * 1024 * 1; #[allow(clippy::result_unit_err)] #[no_mangle] pub fn main() -> Result<()> { -// pub fn main() -> Result {/ - // println!("start main()"); - // let start_time = SystemTime::now().duration_since(UNIX_EPOCH).as_millis(); - - // let mut d: ArrayData = match DataBuffer::::from_buffer() { - // Some(array_data) => { - // println!("n: {}", array_data.n); - // array_data.clone() - // } - // None => { - // println!("the first function."); - // Default::default() - // } - // }; - - // d.start_times.push(start_time); - // d.end_times - // .push(SystemTime::now().duration_since(UNIX_EPOCH).as_millis()); - // d.n += 1; - - // if d.n == 10 { - // println!( - // "start_time: {:?}, end_time: {:?}", - // d.start_times, d.end_times - // ); - // }; - - // let mut buffer = DataBuffer::default(); - // *buffer = d; - - let my_id = args::get("id").unwrap(); - let array_num: u64 = args::get("array_num") - .expect("missing arg reducer_num") - .parse() - .unwrap_or_else(|_| panic!("bad arg, array_num={}", args::get("array_num").unwrap())); + // let my_id = args::get("id").unwrap(); + // let array_num: u64 = args::get("array_num") + // .expect("missing arg reducer_num") + // .parse() + // .unwrap_or_else(|_| panic!("bad arg, array_num={}", args::get("array_num").unwrap())); // println!("get id {}", my_id); - let reader: DataBuffer = - DataBuffer::from_buffer_slot(format!("part-{}-{}", array_num-1, my_id)).expect("missing input data."); - // println!("read buffer"); - let mut buffer: DataBuffer = - DataBuffer::with_slot(format!("part-{}-{}", array_num, my_id)); - buffer.raw_data = reader.raw_data.clone(); + // if array_num == 0 { + // let mut buffer: DataBuffer = DataBuffer::with_slot(format!("part-{}-{}", array_num, my_id)); + // buffer.raw_data = "a".repeat(DATA_SIZE); + // } else if array_num == 9 { + // let reader: DataBuffer = DataBuffer::from_buffer_slot(format!("part-{}-{}", array_num-1, my_id)).expect("missing input data."); + // let result = reader.raw_data.clone(); + // } else { + // let mut buffer: DataBuffer = DataBuffer::with_slot(format!("part-{}-{}", array_num, my_id)); + // let reader: DataBuffer = DataBuffer::from_buffer_slot(format!("part-{}-{}", array_num-1, my_id)).expect("missing input data."); + // buffer.raw_data = reader.raw_data.clone(); + // } + let mut buffer: DataBuffer = DataBuffer::with_slot(format!("part-{}", 0)); + buffer.raw_data = "a".repeat(DATA_SIZE); + // println!("hhh1"); + let mut count = 0; + while count < 13 { + // println!("hhh{}", count); + let mut buffer2: DataBuffer = + DataBuffer::with_slot(format!("part-{}", count + 1)); + let reader: DataBuffer = + DataBuffer::from_buffer_slot(format!("part-{}", count)).expect("missing input data."); + buffer2.raw_data = reader.raw_data.clone(); + count += 1; + } + // println!("hhh100"); + let reader2: DataBuffer = + DataBuffer::from_buffer_slot(format!("part-{}", 13)).expect("missing input data."); + let _result = reader2.raw_data.clone(); + // println!("hhh101"); Ok(().into()) } diff --git a/user/checker/src/lib.rs b/user/checker/src/lib.rs index 2f8588d8..25b87b57 100644 --- a/user/checker/src/lib.rs +++ b/user/checker/src/lib.rs @@ -3,7 +3,7 @@ use alloc::{format, vec::Vec}; -use ms_std::{args, prelude::*}; +use ms_std::{args, prelude::*,time::{SystemTime, UNIX_EPOCH}}; use ms_std_proc_macro::FaasData; #[derive(Default, FaasData)] @@ -13,6 +13,7 @@ struct VecArg { #[no_mangle] pub fn main() -> Result<()> { + println!("com_start4: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); let merger_num: u32 = { let m = args::get("merger_num").unwrap(); m.parse().unwrap() @@ -37,7 +38,7 @@ pub fn main() -> Result<()> { last_max = *first } } - + println!("com_end4: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); println!("sort result is ok, total sort {} numbers", counter); Ok(().into()) } diff --git a/user/file_reader/src/lib.rs b/user/file_reader/src/lib.rs index 9c395885..13bf9bdf 100644 --- a/user/file_reader/src/lib.rs +++ b/user/file_reader/src/lib.rs @@ -1,27 +1,45 @@ #![no_std] -use alloc::{borrow::ToOwned, string::String}; -use ms_std::{args, fs::File, io::Read, prelude::*}; -use ms_std_proc_macro::FaasData; +use alloc::string::String; +use ms_std::{ + args, + fs::File, + io::Read, + prelude::*, + println, + time::{SystemTime, UNIX_EPOCH}, +}; +// use ms_std_proc_macro::FaasData; -#[derive(Default, FaasData)] -struct VecArg { - content: String, -} +// #[derive(Default, FaasData)] +// struct VecArg { +// content: String, +// } #[no_mangle] pub fn main() -> Result<()> { - let slot_name = args::get("slot_name").unwrap(); + // let slot_name = args::get("slot_name").unwrap(); let input_file = args::get("input_file").unwrap(); - let mut buffer: DataBuffer = DataBuffer::with_slot(slot_name.to_owned()); - - buffer.content = { - let mut f = File::open(input_file)?; - let mut buf = String::new(); - f.read_to_string(&mut buf).expect("read file failed."); - buf - }; + // let mut buffer: DataBuffer = DataBuffer::with_slot(slot_name.to_owned()); + let mut f = File::open(input_file)?; + let mut buf = String::new(); + println!( + "read_start: {}", + SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64 + ); + // buffer.content = { + // let mut f = File::open(input_file)?; + // let mut buf = String::new(); + // f.read_to_string(&mut buf).expect("read file failed."); + // buf + // }; + // println!("buffer_long={}", buffer.content.len()); + f.read_to_string(&mut buf).expect("read file failed."); + println!( + "read_end: {}", + SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64 + ); Ok(().into()) } diff --git a/user/func_a/src/lib.rs b/user/func_a/src/lib.rs index e531a78a..329f21c2 100644 --- a/user/func_a/src/lib.rs +++ b/user/func_a/src/lib.rs @@ -2,50 +2,50 @@ extern crate alloc; -use alloc::{borrow::ToOwned, string::String}; +use alloc::borrow::ToOwned; use ms_std::{ agent::{DataBuffer, FaaSFuncResult as Result}, - // println, - time::SystemTime, + println, + time::{SystemTime, UNIX_EPOCH}, }; use ms_std_proc_macro::FaasData; -const DATA_SIZE: usize = (1024*1024*256-48); +// const DATA_SIZE: usize = 1024 * 1024 * 256 / 8; +const DATA_SIZE: usize = 1024 * 1024 * 16 / 8; -#[allow(dead_code)] #[derive(FaasData)] -pub struct MyComplexData { - pub current_time: SystemTime, - pub year: i64, - pub name: String, - pub big_data: [u8; DATA_SIZE], +struct VecArg { + data: [u64; DATA_SIZE], } -impl Default for MyComplexData { +impl Default for VecArg { fn default() -> Self { Self { - current_time: SystemTime::now(), - year: 0, - name: "".to_owned(), - big_data: [0; DATA_SIZE], + data: [0; DATA_SIZE], } } } #[allow(clippy::result_unit_err)] #[no_mangle] -pub fn main() -> Result { - let mut d = DataBuffer::::with_slot("Conference".to_owned()); - d.year = 2025; - d.name = "Euro".to_owned(); - - for (idx, val) in &mut d.big_data.iter_mut().enumerate() { - *val = (idx % 109usize) as u8 +pub fn main() -> Result<()> { + let mut d = DataBuffer::::with_slot("Conference".to_owned()); + + for (idx, val) in &mut d.data.iter_mut().enumerate() { + *val = (idx % (u64::MAX - 1) as usize) as u64 + } + + let register_start = SystemTime::now().duration_since(UNIX_EPOCH).as_nanos(); + let result = DataBuffer::::from_buffer_slot("Conference".to_owned()); + + if let Some(buffer) = result { + for i in 0..buffer.data.len() { + let _ = unsafe { core::ptr::read_volatile((&buffer.data[i]) as *const u64) }; + } } - d.current_time = SystemTime::now(); - // println!("construct d ok."); - // println!("some_str={}, some_int={}", d.some_str, d.some_int); + let access_end2 = SystemTime::now().duration_since(UNIX_EPOCH).as_nanos(); + + println!("phase34_dur={}", access_end2 - register_start); - - Ok(d) + Ok(().into()) } diff --git a/user/func_b/src/lib.rs b/user/func_b/src/lib.rs index 62f22136..9fb73add 100644 --- a/user/func_b/src/lib.rs +++ b/user/func_b/src/lib.rs @@ -2,9 +2,7 @@ extern crate alloc; -use core::{mem::size_of, /* ptr */}; - -use alloc::{borrow::ToOwned, string::String}; +use alloc::borrow::ToOwned; use ms_std::{ agent::{DataBuffer, FaaSFuncResult as Result}, println, @@ -12,48 +10,37 @@ use ms_std::{ }; use ms_std_proc_macro::FaasData; -const DATA_SIZE: usize = (1024*1024*256-48); +const DATA_SIZE: usize = 1024 * 1024 * 16 / 8; #[derive(FaasData)] pub struct MyComplexData { - pub current_time: SystemTime, - pub year: i64, - pub name: String, - pub big_data: [u8; DATA_SIZE], + data: [u64; DATA_SIZE], } impl Default for MyComplexData { fn default() -> Self { Self { - current_time: SystemTime::now(), - year: Default::default(), - name: Default::default(), - big_data: [0; DATA_SIZE], + data: [0; DATA_SIZE], } } } #[no_mangle] #[allow(clippy::result_unit_err)] -pub fn main() -> Result { +pub fn main() -> Result<()> { println!("func b"); + let func_b_start = SystemTime::now(); let data = DataBuffer::::from_buffer_slot("Conference".to_owned()); if let Some(buffer) = data { - let size = size_of::(); - for i in 0..buffer.big_data.len() { - let _ = unsafe { core::ptr::read_volatile((&buffer.big_data[i]) as *const u8) }; + for i in 0..buffer.data.len() { + let _ = unsafe { core::ptr::read_volatile((&buffer.data[i]) as *const u64) }; } - let dur = buffer.current_time.elapsed(); + core::mem::forget(buffer); println!( - // "try recovery data. total_size: {} Bytes", - "try recovery data. trans data time: {:?}, total_size: {} Bytes, transfer rate: {} MB/s", - dur, - size, - size as u128 / dur.as_micros(), + "phase34_dur={}", + SystemTime::now().duration_since(func_b_start).as_nanos() ); - println!("{}Sys, {}", buffer.name, buffer.year); - assert_eq!(buffer.year, 2025); - Ok(buffer) + Ok(().into()) } else { Err("buffer is none")? } diff --git a/user/hello_world/Cargo.lock b/user/hello_world/Cargo.lock index 2e5d5d9c..719a4934 100644 --- a/user/hello_world/Cargo.lock +++ b/user/hello_world/Cargo.lock @@ -2,24 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] - -[[package]] -name = "allocator-api2" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" - [[package]] name = "autocfg" version = "1.1.0" @@ -72,16 +54,6 @@ dependencies = [ "byteorder", ] -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" -dependencies = [ - "ahash", - "allocator-api2", -] - [[package]] name = "heapless" version = "0.8.0" @@ -97,7 +69,6 @@ name = "hello_world" version = "0.1.0" dependencies = [ "cfg-if", - "hashbrown", "ms_hostcall", "ms_std", ] @@ -152,12 +123,6 @@ dependencies = [ "syn 2.0.39", ] -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - [[package]] name = "proc-macro2" version = "1.0.70" @@ -268,29 +233,3 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - -[[package]] -name = "zerocopy" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.39", -] diff --git a/user/hello_world/Cargo.toml b/user/hello_world/Cargo.toml index 055b1389..6e62675a 100644 --- a/user/hello_world/Cargo.toml +++ b/user/hello_world/Cargo.toml @@ -15,7 +15,6 @@ ms_std = { path = "../../ms_std", features = [ ], optional = true } ms_hostcall = { path = "../../ms_hostcall", optional = true } cfg-if = "1.0.0" -hashbrown = "0.14.5" [features] with_libos = ["ms_std", "ms_hostcall"] diff --git a/user/load_all/Cargo.toml b/user/load_all/Cargo.toml index 45faf71e..a296d7ee 100644 --- a/user/load_all/Cargo.toml +++ b/user/load_all/Cargo.toml @@ -19,5 +19,5 @@ cfg-if = "1.0.0" [features] with_libos = ["ms_std", "ms_hostcall"] measure_mem = ["with_libos"] -mpk = ["ms_std/mpk"] +# mpk = ["ms_std/mpk"] default = ["measure_mem"] diff --git a/user/load_all/src/lib.rs b/user/load_all/src/lib.rs index d61e349c..f26d1dd9 100644 --- a/user/load_all/src/lib.rs +++ b/user/load_all/src/lib.rs @@ -16,7 +16,7 @@ cfg_if::cfg_if! { pub fn main() -> Result<()> { println!("Hello, world! id: {}", args::get("id").unwrap()); - libos!(addrinfo("localhost")).unwrap(); + libos!(addrinfo("www.baidu.com")).unwrap(); if let Err(e) = File::open(".") { println!("{:#?}", e); } diff --git a/user/mapper/src/lib.rs b/user/mapper/src/lib.rs index 55604823..74ddf3db 100644 --- a/user/mapper/src/lib.rs +++ b/user/mapper/src/lib.rs @@ -4,16 +4,20 @@ use hashbrown::HashMap; pub use ms_hostcall::Verify; use ms_std::{ agent::{DataBuffer, FaaSFuncResult as Result}, - args, println, + args, + fs::File, + io::Read, + println, + time::{SystemTime, UNIX_EPOCH}, }; use ms_std_proc_macro::FaasData; extern crate alloc; -#[derive(Default, FaasData)] -struct Reader2Mapper { - content: String, -} +// #[derive(Default, FaasData)] +// struct Reader2Mapper { +// content: String, +// } #[derive(FaasData)] struct Mapper2Reducer { @@ -37,32 +41,46 @@ pub fn getidx(word: &str, reducer_num: u64) -> u64 { hash_val } -#[allow(clippy::result_unit_err)] -#[no_mangle] -pub fn main() -> Result<()> { - let my_id = args::get("id").unwrap(); - let reducer_num: u64 = args::get("reducer_num") - .expect("missing arg reducer_num") - .parse() - .unwrap_or_else(|_| panic!("bad arg, reducer_num={}", args::get("reducer_num").unwrap())); +fn mapper_func(my_id: &str, reducer_num: u64) -> Result<()> { + // let reader: DataBuffer = + // DataBuffer::from_buffer_slot(format!("part-{}", my_id)).expect("missing input data."); + // println!("access_buffer_long={}", reader.content.len()); - let reader: DataBuffer = - DataBuffer::from_buffer_slot(format!("part-{}", my_id)).expect("missing input data."); + let file_name = format!("fake_data_{}.txt", my_id); + let mut f = File::open(&file_name)?; + let mut content = String::new(); + println!( + "read_start: {}", + SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64 + ); + f.read_to_string(&mut content).expect("read file failed."); + println!( + "read_end: {}", + SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64 + ); let mut counter = HashMap::new(); - - for line in reader.content.lines() { - let words = line - .trim() - .split(' ') - .filter(|word| word.chars().all(char::is_alphanumeric)); + println!( + "comput_start: {}", + SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64 + ); + for line in content.lines() { + let words = line.trim().split(' '); + // .filter(|word| word.chars().all(char::is_alphanumeric)); for word in words { let old_count = *counter.entry(word).or_insert(0u32); counter.insert(word, old_count + 1); } } - + println!( + "comput_end: {}", + SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64 + ); + let total: u32 = counter.values().sum(); + // 打印总和 + println!("The sum of all values is: {}", total); + println!("the counter nums is {}", counter.len()); let mut data_buffers: Vec> = Vec::with_capacity(reducer_num as usize); @@ -74,6 +92,10 @@ pub fn main() -> Result<()> { } ms_std::println!("the counter nums is {}", counter.len()); + println!( + "register_start: {}", + SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64 + ); for (word, count) in counter { let shuffle_idx = getidx(word, reducer_num); @@ -86,6 +108,22 @@ pub fn main() -> Result<()> { .shuffle .insert(word.to_owned(), count); } + println!( + "register_end: {}", + SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64 + ); Ok(().into()) } + +#[allow(clippy::result_unit_err)] +#[no_mangle] +pub fn main() -> Result<()> { + let my_id = args::get("id").unwrap(); + let reducer_num: u64 = args::get("reducer_num") + .expect("missing arg reducer_num") + .parse() + .unwrap_or_else(|_| panic!("bad arg, reducer_num={}", args::get("reducer_num").unwrap())); + + mapper_func(my_id, reducer_num) +} diff --git a/user/merger/src/lib.rs b/user/merger/src/lib.rs index 5554fab9..3e0393af 100644 --- a/user/merger/src/lib.rs +++ b/user/merger/src/lib.rs @@ -1,7 +1,7 @@ #![no_std] use alloc::{format, vec::Vec}; -use ms_std::{args, prelude::*}; +use ms_std::{args, prelude::*,time::{SystemTime, UNIX_EPOCH}}; use ms_std_proc_macro::FaasData; #[derive(Default, FaasData)] @@ -11,6 +11,7 @@ struct VecArg { #[no_mangle] pub fn main() -> Result<()> { + println!("com_start3: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); let my_id = args::get("id").unwrap(); let sorter_num: u32 = { let m = args::get("sorter_num").unwrap(); @@ -28,7 +29,7 @@ pub fn main() -> Result<()> { merged_result.array = merge_partitions(partitions.iter().map(|buffer| &buffer.array).collect()); // println!("merged_result: {:?}", merged_result); - + println!("com_end3: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); Ok(().into()) } diff --git a/user/reducer/src/lib.rs b/user/reducer/src/lib.rs index 56b6dca9..9bb2eee6 100644 --- a/user/reducer/src/lib.rs +++ b/user/reducer/src/lib.rs @@ -9,6 +9,7 @@ pub use ms_hostcall::Verify; use ms_std::{ agent::{DataBuffer, FaaSFuncResult as Result}, args, println, + time::{SystemTime, UNIX_EPOCH}, }; use ms_std_proc_macro::FaasData; @@ -31,6 +32,7 @@ pub fn main() -> Result<()> { .unwrap_or_else(|_| panic!("bad arg, mapper_num={}", args::get("mapper_num").unwrap())); let mut counter: HashMap = HashMap::new(); + println!("access_start: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); for i in 0..mapper_num { // println!("need databuffer slot={}-{}", i, reducer_id); let mapper_result: DataBuffer = @@ -42,6 +44,7 @@ pub fn main() -> Result<()> { counter.insert(word.to_owned(), old_count + count); } } + println!("access_end: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); // for (word, count) in counter { // println!("{}:{}", word, count); diff --git a/user/sorter/src/lib.rs b/user/sorter/src/lib.rs index 624b01c1..630217f9 100644 --- a/user/sorter/src/lib.rs +++ b/user/sorter/src/lib.rs @@ -2,7 +2,7 @@ use alloc::{format, string::String, vec::Vec}; -use ms_std::{args, prelude::*}; +use ms_std::{args, prelude::*,time::{SystemTime, UNIX_EPOCH}}; use ms_std_proc_macro::FaasData; #[derive(Default, FaasData)] @@ -17,6 +17,7 @@ struct VecArg { #[no_mangle] pub fn main() -> Result<()> { + println!("com_start1: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); let my_id = args::get("id").unwrap(); let sorter_num: usize = { let n = args::get("sorter_num").unwrap(); @@ -26,7 +27,7 @@ pub fn main() -> Result<()> { let n = args::get("merger_num").unwrap(); n.parse().unwrap() }; - + let input: DataBuffer = DataBuffer::from_buffer_slot(format!("input-part-{}", my_id)).unwrap(); @@ -42,8 +43,9 @@ pub fn main() -> Result<()> { .map_err(|_| format!("parse Int failed, num={}", num))?, ) } - + array.array.sort(); + if my_id.eq("0") { // let mut pivots: DataBuffer = ; let pivots: Vec<_> = (0..merger_num - 1) @@ -59,6 +61,6 @@ pub fn main() -> Result<()> { pivots_buffer.array = pivots.clone(); } } - + println!("com_end1: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); Ok(().into()) } diff --git a/user/splitter/src/lib.rs b/user/splitter/src/lib.rs index 14b3b326..9694ea85 100644 --- a/user/splitter/src/lib.rs +++ b/user/splitter/src/lib.rs @@ -1,7 +1,7 @@ #![no_std] use alloc::{format, vec::Vec}; -use ms_std::{args, prelude::*, println}; +use ms_std::{args, prelude::*, println,time::{SystemTime, UNIX_EPOCH}}; use ms_std_proc_macro::FaasData; #[derive(Default, FaasData)] @@ -11,6 +11,7 @@ struct VecArg { #[no_mangle] pub fn main() -> Result<()> { + println!("com_start2: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); let my_id = args::get("id").unwrap(); let numbers: DataBuffer = @@ -34,6 +35,7 @@ pub fn main() -> Result<()> { .map(|part| part.len()) .collect::>() ); + println!("com_end2: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); Ok(().into()) } diff --git a/user/tinywasm_checker/Cargo.lock b/user/tinywasm_checker/Cargo.lock index a17c9114..214c01a4 100644 --- a/user/tinywasm_checker/Cargo.lock +++ b/user/tinywasm_checker/Cargo.lock @@ -22,9 +22,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.6.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "byteorder" diff --git a/user/tinywasm_merger/Cargo.lock b/user/tinywasm_merger/Cargo.lock index 5dbb00c3..59ceb608 100644 --- a/user/tinywasm_merger/Cargo.lock +++ b/user/tinywasm_merger/Cargo.lock @@ -22,9 +22,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.6.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "byteorder" diff --git a/user/tinywasm_pass_str/main.wasm b/user/tinywasm_pass_str/main.wasm index 74971395..d7b2a9ec 100755 Binary files a/user/tinywasm_pass_str/main.wasm and b/user/tinywasm_pass_str/main.wasm differ diff --git a/user/tinywasm_sorter/Cargo.lock b/user/tinywasm_sorter/Cargo.lock index e18d6c86..7a946b0c 100644 --- a/user/tinywasm_sorter/Cargo.lock +++ b/user/tinywasm_sorter/Cargo.lock @@ -22,9 +22,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.6.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "byteorder" diff --git a/user/tinywasm_spliter/Cargo.lock b/user/tinywasm_spliter/Cargo.lock index 81d5f3b4..90554a47 100644 --- a/user/tinywasm_spliter/Cargo.lock +++ b/user/tinywasm_spliter/Cargo.lock @@ -22,9 +22,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.6.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "byteorder" diff --git a/user/wasmtime_checker/Cargo.lock b/user/wasmtime_checker/Cargo.lock new file mode 100644 index 00000000..a2c98f72 --- /dev/null +++ b/user/wasmtime_checker/Cargo.lock @@ -0,0 +1,1194 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + +[[package]] +name = "arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cc" +version = "1.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4cbd4ab9fef358caa9c599eae3105af638ead5fb47a718315d8e03c852b9f0d" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cobs" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "cranelift-bforest" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6b33d7e757a887989eb18b35712b2a67d96171ec3149d1bfb657b29b7b367c" +dependencies = [ + "cranelift-entity", +] + +[[package]] +name = "cranelift-codegen" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9acf15cb22be42d07c3b57d7856329cb228b7315d385346149df2566ad5e4aa" +dependencies = [ + "bumpalo", + "cranelift-bforest", + "cranelift-codegen-meta", + "cranelift-codegen-shared", + "cranelift-control", + "cranelift-entity", + "cranelift-isle", + "gimli", + "hashbrown 0.14.5", + "log", + "regalloc2", + "rustc-hash", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e934d301392b73b3f8b0540391fb82465a0f179a3cee7c726482ac4727efcc97" +dependencies = [ + "cranelift-codegen-shared", +] + +[[package]] +name = "cranelift-codegen-shared" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb2a2566b3d54b854dfb288b3b187f6d3d17d6f762c92898207eba302931da" + +[[package]] +name = "cranelift-control" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0100f33b704cdacd01ad66ff41f8c5030d57cbff078e2a4e49ab1822591299fa" +dependencies = [ + "arbitrary", +] + +[[package]] +name = "cranelift-entity" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8cfdc315e5d18997093e040a8d234bea1ac1e118a716d3e30f40d449e78207b" +dependencies = [ + "serde", + "serde_derive", +] + +[[package]] +name = "cranelift-frontend" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f74b84f16af2e982b0c0c72233503d9d55cbfe3865dbe807ca28dc6642a28b5" +dependencies = [ + "cranelift-codegen", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-isle" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adf306d3dde705fb94bd48082f01d38c4ededc74293a4c007805f610bf08bc6e" + +[[package]] +name = "cranelift-native" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ea0ebdef7aff4a79bcbc8b6495f31315f16b3bf311152f472eaa8d679352581" +dependencies = [ + "cranelift-codegen", + "libc", + "target-lexicon", +] + +[[package]] +name = "cranelift-wasm" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d549108a1942065cdbac3bb96c2952afa0e1b9a3beff4b08c4308ac72257576d" +dependencies = [ + "cranelift-codegen", + "cranelift-entity", + "cranelift-frontend", + "itertools", + "log", + "smallvec", + "wasmparser", + "wasmtime-types", +] + +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "derive_more" +version = "0.99.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn 1.0.109", +] + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[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.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + +[[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 = "hash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" +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.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +dependencies = [ + "foldhash", +] + +[[package]] +name = "heapless" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" +dependencies = [ + "hash32", + "stable_deref_trait", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + +[[package]] +name = "indexmap" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +dependencies = [ + "equivalent", + "hashbrown 0.14.5", + "serde", +] + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + +[[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.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "linked_list_allocator" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286" +dependencies = [ + "spinning_top", +] + +[[package]] +name = "linux-raw-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1ad52afd8f9448cbbe722ae722849cc41f1d365e285cca386896352bc08e1a9" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mach2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" +dependencies = [ + "libc", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "memfd" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" +dependencies = [ + "rustix", +] + +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "ms_hostcall" +version = "0.1.0" +dependencies = [ + "bitflags", + "derive_more", + "thiserror-no-std", +] + +[[package]] +name = "ms_std" +version = "0.1.0" +dependencies = [ + "cfg-if", + "heapless", + "linked_list_allocator", + "ms_hostcall", + "ms_std_proc_macro", + "spin", + "thiserror-no-std", +] + +[[package]] +name = "ms_std_proc_macro" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "naked-function" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b8d5fca6ab1e6215b010aefd3b9ac5aae369dae0faea3a7f34f296cc9f719ac" +dependencies = [ + "cfg-if", + "naked-function-macro", +] + +[[package]] +name = "naked-function-macro" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b4123e70df5fe0bb370cff166ae453b9c5324a2cfc932c0f7e55498147a0475" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "object" +version = "0.36.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" +dependencies = [ + "crc32fast", + "hashbrown 0.15.0", + "indexmap", + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "postcard" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f7f0a8d620d71c457dd1d47df76bb18960378da56af4527aaa10f515eee732e" +dependencies = [ + "cobs", + "embedded-io 0.4.0", + "embedded-io 0.6.1", + "serde", +] + +[[package]] +name = "proc-macro2" +version = "1.0.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "psm" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa37f80ca58604976033fae9515a8a2989fc13797d953f7c04fb8fa36a11f205" +dependencies = [ + "cc", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[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 = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys 0.4.14", + "windows-sys", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "sc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "010e18bd3bfd1d45a7e666b236c78720df0d9a7698ebaa9c1c559961eb60a38b" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" + +[[package]] +name = "serde" +version = "1.0.193" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.193" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "serde_json" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0652c533506ad7a2e353cce269330d6afd8bdfb6d75e0ace5b35aacbd7b9e9" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "sjlj" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9b43efc387069aabdc27124a294337c7032a3cb62df0108d2578eff7f08e39" +dependencies = [ + "linux-raw-sys 0.2.2", + "naked-function", + "sc", +] + +[[package]] +name = "slice-group-by" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +dependencies = [ + "serde", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spinning_top" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b9eb1a2f4c41445a3a0ff9abc5221c5fcd28e1f13cd7c0397706f9ac938ddb0" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "target-lexicon" +version = "0.12.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" + +[[package]] +name = "thiserror" +version = "1.0.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e3de26b0965292219b4287ff031fcba86837900fe9cd2b34ea8ad893c0953d2" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "268026685b2be38d7103e9e507c938a1fcb3d7e6eb15e87870b617bf37b6d581" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "thiserror-impl-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58e6318948b519ba6dc2b442a6d0b904ebfb8d411a3ad3e07843615a72249758" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "thiserror-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3ad459d94dd517257cc96add8a43190ee620011bb6e6cdc82dafd97dfafafea" +dependencies = [ + "thiserror-impl-no-std", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasm-encoder" +version = "0.209.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4a05336882dae732ce6bd48b7e11fe597293cb72c13da4f35d7d5f8d53b2a7" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasmparser" +version = "0.209.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07035cc9a9b41e62d3bb3a3815a66ab87c993c06fe1cf6b2a3f2a18499d937db" +dependencies = [ + "ahash", + "bitflags", + "hashbrown 0.14.5", + "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", +] + +[[package]] +name = "wasmtime" +version = "22.0.0" +source = "git+https://gitee.com/tju-cloud-computing/wasmtime-as-lib?branch=master#fb45fb8dde6d068abb3ae78bfab78253c9654af5" +dependencies = [ + "anyhow", + "bumpalo", + "cc", + "cfg-if", + "encoding_rs", + "hashbrown 0.14.5", + "indexmap", + "libc", + "libm", + "log", + "mach2", + "memfd", + "memoffset", + "object", + "once_cell", + "paste", + "postcard", + "psm", + "rustix", + "semver", + "serde", + "serde_derive", + "smallvec", + "sptr", + "target-lexicon", + "wasmparser", + "wasmtime-asm-macros", + "wasmtime-component-macro", + "wasmtime-component-util", + "wasmtime-cranelift", + "wasmtime-environ", + "wasmtime-jit-icache-coherence", + "wasmtime-slab", + "wasmtime-versioned-export-macros", + "wasmtime-winch", + "windows-sys", +] + +[[package]] +name = "wasmtime-asm-macros" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d697d99c341d4a9ffb72f3af7a02124d233eeb59aee010f36d88e97cca553d5e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "wasmtime-component-macro" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b29b462b068e73b5b27fae092a27f47e5937cabf6b26be2779c978698a52feca" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn 2.0.39", + "wasmtime-component-util", + "wasmtime-wit-bindgen", + "wit-parser", +] + +[[package]] +name = "wasmtime-component-util" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d2912c53d9054984b380dfbd7579f9c3681b2a73b903a56bd71a1c4f175f1e" + +[[package]] +name = "wasmtime-cranelift" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3975deafea000457ba84355c7c0fce0372937204f77026510b7b454f28a3a65" +dependencies = [ + "anyhow", + "cfg-if", + "cranelift-codegen", + "cranelift-control", + "cranelift-entity", + "cranelift-frontend", + "cranelift-native", + "cranelift-wasm", + "gimli", + "log", + "object", + "target-lexicon", + "thiserror", + "wasmparser", + "wasmtime-environ", + "wasmtime-versioned-export-macros", +] + +[[package]] +name = "wasmtime-environ" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f444e900e848b884d8a8a2949b6f5b92af642a3e663ff8fbe78731143a55be61" +dependencies = [ + "anyhow", + "cranelift-entity", + "gimli", + "indexmap", + "log", + "object", + "postcard", + "serde", + "serde_derive", + "target-lexicon", + "wasm-encoder", + "wasmparser", + "wasmprinter", + "wasmtime-component-util", + "wasmtime-types", +] + +[[package]] +name = "wasmtime-jit-icache-coherence" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5afe2f0499542f9a4bcfa1b55bfdda803b6ade4e7c93c6b99e0f39dba44b0a91" +dependencies = [ + "anyhow", + "cfg-if", + "libc", + "windows-sys", +] + +[[package]] +name = "wasmtime-slab" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a7de1f2bec5bbb35d532e61c85c049dc84ae671df60492f90b954ecf21169e7" + +[[package]] +name = "wasmtime-types" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "412463e9000e14cf6856be48628d2213c20c153e29ffc22b036980c892ea6964" +dependencies = [ + "cranelift-entity", + "serde", + "serde_derive", + "smallvec", + "wasmparser", +] + +[[package]] +name = "wasmtime-versioned-export-macros" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de5a9bc4f44ceeb168e9e8e3be4e0b4beb9095b468479663a9e24c667e36826f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "wasmtime-winch" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed4db238a0241df2d15f79ad17b3a37a27f2ea6cb885894d81b42ae107544466" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "object", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", + "winch-codegen", +] + +[[package]] +name = "wasmtime-wit-bindgen" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc077306b38288262e5ba01d4b21532a6987416cdc0aedf04bb06c22a68fdc" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "wit-parser", +] + +[[package]] +name = "wasmtime_checker" +version = "0.1.0" +dependencies = [ + "lazy_static", + "ms_hostcall", + "ms_std", + "spin", + "wasmtime_wasi_api", +] + +[[package]] +name = "wasmtime_wasi_api" +version = "0.1.0" +dependencies = [ + "hashbrown 0.14.5", + "lazy_static", + "ms_hostcall", + "ms_std", + "ms_std_proc_macro", + "sjlj", + "spin", + "wasmtime", +] + +[[package]] +name = "winch-codegen" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85c6915884e731b2db0d8cf08cb64474cb69221a161675fd3c135f91febc3daa" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "regalloc2", + "smallvec", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +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", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[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", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] diff --git a/user/wasmtime_checker/Cargo.toml b/user/wasmtime_checker/Cargo.toml new file mode 100644 index 00000000..158722d8 --- /dev/null +++ b/user/wasmtime_checker/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "wasmtime_checker" +version = "0.1.0" +edition = "2021" +build = "build.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +crate-type = ["staticlib"] + +[dependencies] +ms_std = { path = "../../ms_std", features = ["panic_def", "alloc_def"] } +ms_hostcall = { path = "../../ms_hostcall" } +wasmtime_wasi_api = { path = "../../wasmtime_wasi_api" } + +lazy_static = { version = "1.5.0", features = ["spin_no_std"] } +spin = "0.9.8" + +[features] +mpk = ["ms_std/mpk"] diff --git a/user/wasmtime_checker/build.rs b/user/wasmtime_checker/build.rs new file mode 100644 index 00000000..9fc09ddf --- /dev/null +++ b/user/wasmtime_checker/build.rs @@ -0,0 +1,4 @@ +fn main() { + println!("cargo:rustc-link-lib=static={}", "wasmtime-platform"); + println!("cargo:rustc-link-search=native={}", "./"); +} diff --git a/user/wasmtime_checker/build.sh b/user/wasmtime_checker/build.sh new file mode 100755 index 00000000..6d929791 --- /dev/null +++ b/user/wasmtime_checker/build.sh @@ -0,0 +1,16 @@ +# $CPP checker.cpp -o checker.wasm -fno-exceptions -fno-rtti -ffast-math -funroll-loops -fomit-frame-pointer -Ofast +$CPP checker_ori.cpp -o checker.wasm -fno-exceptions -fno-rtti -ffast-math -funroll-loops -fomit-frame-pointer -Ofast +# $CC checker.c -o checker.wasm +wasmtime compile --target x86_64-unknown-none -W threads=n,tail-call=n checker.wasm +# wasmtime compile --target x86_64-unknown-none -W simd=y,threads=n,tail-call=n checker.wasm + +cargo build --target x86_64-unknown-none --release && cc \ + -Wl,--gc-sections -nostdlib \ + -Wl,--whole-archive \ + target/x86_64-unknown-none/release/libwasmtime_checker.a \ + -Wl,--no-whole-archive \ + -shared \ + -o target/x86_64-unknown-none/release/libwasmtime_checker.so + +ln -s /home/wyj/alloy_stack/mslibos/user/wasmtime_checker/target/x86_64-unknown-none/release/libwasmtime_checker.so /home/wyj/alloy_stack/mslibos/target/release/libwasmtime_checker.so + diff --git a/user/wasmtime_checker/checker.c b/user/wasmtime_checker/checker.c new file mode 100644 index 00000000..626137d3 --- /dev/null +++ b/user/wasmtime_checker/checker.c @@ -0,0 +1,58 @@ +#include +#include +#include + +__attribute__((import_module("env"), import_name("access_buffer"))) void access_buffer(void *slot_name, int name_size, void *buffer, int buffer_size); + +#define MAX_ARRAY_LENGTH 20000000 +#define MAX_BUFFER_SIZE 200000000 + +int result[MAX_ARRAY_LENGTH]; + +int main(int argc, char* argv[]) { + int id = atoi(argv[1]); + int sorter_num = atoi(argv[2]); + int merger_num = atoi(argv[3]); + printf("checker_%d start!\n", id); + int bufferSize = MAX_BUFFER_SIZE; + int index = 0; + for (int i = 0; i < merger_num; i++) { + char slot_name[20]; + sprintf(slot_name, "checker_%d", i); + // printf("pivotname: %s\n", slot_name); + char *buffer; + buffer = (char *)malloc(bufferSize * sizeof(char)); + if (buffer == NULL) { + perror("malloc error"); + return 1; + } + memset(buffer, 0, bufferSize * sizeof(char)); + buffer[0] = '\0'; // 初始化为空字符串 + access_buffer(slot_name, strlen(slot_name), buffer, bufferSize); + char *ptr = buffer; + int num; + while (sscanf(ptr, "%d", &num) == 1) { + result[index] = num; + index++; + // 移动指针到下一个数字 + while (*ptr && *ptr != ' ') { + ptr++; + } + if (*ptr == ' ') { + ptr++; + } + } + free(buffer); + } + printf("result_array: "); + for (int i = 0; i < index-1; i++) { + if (result[i] > result[i+1]) { + printf("sort error!\n"); + return 0; + } + printf("%d ", result[i]); + } + printf("%d\n", result[index-1]); + printf("checker_%d all finished!\n", id); + return 0; +} \ No newline at end of file diff --git a/user/wasmtime_checker/checker.cpp b/user/wasmtime_checker/checker.cpp new file mode 100644 index 00000000..30aa13c7 --- /dev/null +++ b/user/wasmtime_checker/checker.cpp @@ -0,0 +1,51 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +__attribute__((import_module("env"), import_name("access_buffer"))) void access_buffer(void *slot_name, int name_size, void *buffer, int buffer_size); + +#define MAX_ARRAY_LENGTH 8000000 +#define MAX_BUFFER_SIZE 80000000 + +int result[MAX_ARRAY_LENGTH]; + +int main(int argc, char* argv[]) { + int id = atoi(argv[1]); + int sorter_num = atoi(argv[2]); + int merger_num = atoi(argv[3]); + printf("checker_%d start!\n", id); + int bufferSize = MAX_BUFFER_SIZE; + int index = 0; + for (int i = 0; i < merger_num; i++) { + string slot_name = "checker_" + to_string(i); + string buffer = string(MAX_BUFFER_SIZE, 0); + access_buffer((void*)slot_name.c_str(), slot_name.length(), (void*)buffer.c_str(), MAX_BUFFER_SIZE); + istringstream iss(buffer); + int num; + while (iss >> num) { + result[index++] = num; + } + } + // printf("result_array: "); + // for (int i = 0; i < index-1; i++) { + // if (result[i] > result[i+1]) { + // printf("sort error!\n"); + // printf("%d %d\n", result[i], result[i + 1]); + // return 0; + // } + // printf("%d ", result[i]); + // } + // printf("%d\n", result[index-1]); + printf("checker_%d all finished!\n", id); + return 0; +} \ No newline at end of file diff --git a/user/wasmtime_checker/checker.cwasm b/user/wasmtime_checker/checker.cwasm new file mode 100644 index 00000000..5c560725 Binary files /dev/null and b/user/wasmtime_checker/checker.cwasm differ diff --git a/user/wasmtime_checker/checker.wasm b/user/wasmtime_checker/checker.wasm new file mode 100755 index 00000000..35c5cab7 Binary files /dev/null and b/user/wasmtime_checker/checker.wasm differ diff --git a/user/wasmtime_checker/checker_ori.cpp b/user/wasmtime_checker/checker_ori.cpp new file mode 100644 index 00000000..8251687d --- /dev/null +++ b/user/wasmtime_checker/checker_ori.cpp @@ -0,0 +1,75 @@ +#include +#include +#include +#include + +__attribute__((import_module("env"), import_name("access_buffer"))) void access_buffer(void *slot_name, int name_size, void *buffer, int buffer_size); + +// #define MAX_ARRAY_LENGTH 152221 +// #define MAX_BUFFER_SIZE 1024*1024+152221 + +#define MAX_ARRAY_LENGTH 3805441 +#define MAX_BUFFER_SIZE 25*1024*1024+3805441 + +// #define MAX_ARRAY_LENGTH 7611001 +// #define MAX_BUFFER_SIZE 50*1024*1024+7611001 + +int result[MAX_ARRAY_LENGTH]; + +void get_time(int num, int phase) { + timeval tv{}; + gettimeofday(&tv, nullptr); + printf("%lld.%06lld--%d--%d\n", tv.tv_sec, tv.tv_usec, num, phase); +} + +int main(int argc, char* argv[]) { + // get_time(); + int id = atoi(argv[1]); + int sorter_num = atoi(argv[2]); + int merger_num = atoi(argv[3]); + // printf("checker_%d start!\n", id); + int bufferSize = MAX_BUFFER_SIZE; + int index = 0; + int time_num = 16; + for (int i = 0; i < merger_num; i++) { + char slot_name[20]; + sprintf(slot_name, "checker_%d", i); + // printf("pivotname: %s\n", slot_name); + char *buffer; + buffer = (char *)malloc(bufferSize * sizeof(char)); + memset(buffer, 0, bufferSize * sizeof(char)); + buffer[0] = '\0'; // 初始化为空字符串 + if (id == 0) + get_time(time_num, 0); + access_buffer(slot_name, strlen(slot_name), buffer, bufferSize); + if (id == 0) + get_time(time_num, 1); + time_num++; + char *ptr = buffer; + int num; + while (sscanf(ptr, "%d", &num) == 1) { + result[index] = num; + index++; + // 移动指针到下一个数字 + while (*ptr && *ptr != ' ') { + ptr++; + } + if (*ptr == ' ') { + ptr++; + } + } + free(buffer); + } + // printf("result_array: "); + // for (int i = 0; i < index-1; i++) { + // if (result[i] > result[i+1]) { + // printf("sort error!\n"); + // return 0; + // } + // printf("%d ", result[i]); + // } + // printf("%d\n", result[index-1]); + // printf("checker_%d all finished!\n", id); + // get_time(); + return 0; +} \ No newline at end of file diff --git a/user/wasmtime_checker/libwasmtime-platform.a b/user/wasmtime_checker/libwasmtime-platform.a new file mode 100644 index 00000000..beebf570 Binary files /dev/null and b/user/wasmtime_checker/libwasmtime-platform.a differ diff --git a/user/wasmtime_checker/libwasmtime-platform.o b/user/wasmtime_checker/libwasmtime-platform.o new file mode 100644 index 00000000..90bbf6dd Binary files /dev/null and b/user/wasmtime_checker/libwasmtime-platform.o differ diff --git a/user/wasmtime_checker/src/lib.rs b/user/wasmtime_checker/src/lib.rs new file mode 100644 index 00000000..0ea90e53 --- /dev/null +++ b/user/wasmtime_checker/src/lib.rs @@ -0,0 +1,75 @@ +#![no_std] + +extern crate alloc; +use core::mem::forget; + +use alloc::{string::{String, ToString}, vec::Vec}; +use spin::Mutex; + +use ms_hostcall::types::{OpenFlags, OpenMode}; +use ms_std::{agent::FaaSFuncResult as Result, args, println, libos::libos, time::{SystemTime, UNIX_EPOCH}}; + +use wasmtime_wasi_api::{wasmtime, LibosCtx}; +use wasmtime::Store; + +static CWASM: &[u8] = include_bytes!("../checker.cwasm"); + +static INIT_LOCK: Mutex<()> = Mutex::new(()); + +lazy_static::lazy_static! { + static ref MUST_OPEN_ROOT: bool = { + libos!(open("/", OpenFlags::empty(), OpenMode::RD)).unwrap(); + true + }; +} + +fn func_body(my_id: &str, sorter_num: u64, merger_num: u64) -> Result<()> { + // #[cfg(feature = "log")] + println!("rust: my_id: {:?}, sorter_num: {:?}, merger_num: {:?}", my_id, sorter_num, merger_num); + + let wasi_args: Vec = Vec::from([ + "fake system path!".to_string(), + my_id.to_string(), + sorter_num.to_string(), + merger_num.to_string(), + ]); + wasmtime_wasi_api::set_wasi_args(my_id, wasi_args); + + let _open_root = *MUST_OPEN_ROOT; + + let lock = INIT_LOCK.lock(); + let (engine, module, linker) = wasmtime_wasi_api::build_wasm(CWASM); + drop(lock); + + let mut store = Store::new(&engine, LibosCtx{id: my_id.to_string()}); + let instance = linker.instantiate(&mut store, &module)?; + + let mut memory = instance.get_memory(&mut store, "memory").unwrap(); + let pages = memory.grow(&mut store, 20000).unwrap(); + + let main = instance + .get_typed_func::<(), ()>(&mut store, "_start") + .map_err(|e| e.to_string())?; + + // main.call(store, ()).map_err(|e| e.to_string())?; + main.call(&mut store, ()).map_err(|e| e.to_string())?; + forget(store); + let end_time = SystemTime::now().duration_since(UNIX_EPOCH).as_millis(); + println!("end_time: {:?}", end_time); + Ok(().into()) +} + +#[no_mangle] +pub fn main() -> Result<()> { + let my_id = args::get("id").unwrap(); + let sorter_num: u64 = args::get("sorter_num") + .expect("missing arg sorter_num") + .parse() + .unwrap_or_else(|_| panic!("bad arg, sorter_num={}", args::get("sorter_num").unwrap())); + let merger_num: u64 = args::get("merger_num") + .expect("missing arg merger_num") + .parse() + .unwrap_or_else(|_| panic!("bad arg, merger_num={}", args::get("merger_num").unwrap())); + + func_body(my_id, sorter_num, merger_num) +} diff --git a/user/wasmtime_cpython/Cargo.lock b/user/wasmtime_cpython/Cargo.lock new file mode 100644 index 00000000..5e1bcd12 --- /dev/null +++ b/user/wasmtime_cpython/Cargo.lock @@ -0,0 +1,1151 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + +[[package]] +name = "arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cc" +version = "1.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cobs" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "cranelift-bforest" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6b33d7e757a887989eb18b35712b2a67d96171ec3149d1bfb657b29b7b367c" +dependencies = [ + "cranelift-entity", +] + +[[package]] +name = "cranelift-codegen" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9acf15cb22be42d07c3b57d7856329cb228b7315d385346149df2566ad5e4aa" +dependencies = [ + "bumpalo", + "cranelift-bforest", + "cranelift-codegen-meta", + "cranelift-codegen-shared", + "cranelift-control", + "cranelift-entity", + "cranelift-isle", + "gimli", + "hashbrown 0.14.5", + "log", + "regalloc2", + "rustc-hash", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e934d301392b73b3f8b0540391fb82465a0f179a3cee7c726482ac4727efcc97" +dependencies = [ + "cranelift-codegen-shared", +] + +[[package]] +name = "cranelift-codegen-shared" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb2a2566b3d54b854dfb288b3b187f6d3d17d6f762c92898207eba302931da" + +[[package]] +name = "cranelift-control" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0100f33b704cdacd01ad66ff41f8c5030d57cbff078e2a4e49ab1822591299fa" +dependencies = [ + "arbitrary", +] + +[[package]] +name = "cranelift-entity" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8cfdc315e5d18997093e040a8d234bea1ac1e118a716d3e30f40d449e78207b" +dependencies = [ + "serde", + "serde_derive", +] + +[[package]] +name = "cranelift-frontend" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f74b84f16af2e982b0c0c72233503d9d55cbfe3865dbe807ca28dc6642a28b5" +dependencies = [ + "cranelift-codegen", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-isle" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adf306d3dde705fb94bd48082f01d38c4ededc74293a4c007805f610bf08bc6e" + +[[package]] +name = "cranelift-native" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ea0ebdef7aff4a79bcbc8b6495f31315f16b3bf311152f472eaa8d679352581" +dependencies = [ + "cranelift-codegen", + "libc", + "target-lexicon", +] + +[[package]] +name = "cranelift-wasm" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d549108a1942065cdbac3bb96c2952afa0e1b9a3beff4b08c4308ac72257576d" +dependencies = [ + "cranelift-codegen", + "cranelift-entity", + "cranelift-frontend", + "itertools", + "log", + "smallvec", + "wasmparser", + "wasmtime-types", +] + +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn 2.0.79", +] + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[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.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + +[[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 = "hash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" +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.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +dependencies = [ + "foldhash", +] + +[[package]] +name = "heapless" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" +dependencies = [ + "hash32", + "stable_deref_trait", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + +[[package]] +name = "indexmap" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +dependencies = [ + "equivalent", + "hashbrown 0.15.0", + "serde", +] + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + +[[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.159" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "linked_list_allocator" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286" +dependencies = [ + "spinning_top", +] + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mach2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" +dependencies = [ + "libc", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "memfd" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" +dependencies = [ + "rustix", +] + +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "ms_hostcall" +version = "0.1.0" +dependencies = [ + "bitflags", + "derive_more", + "thiserror-no-std", +] + +[[package]] +name = "ms_std" +version = "0.1.0" +dependencies = [ + "cfg-if", + "heapless", + "linked_list_allocator", + "ms_hostcall", + "ms_std_proc_macro", + "spin", + "thiserror-no-std", +] + +[[package]] +name = "ms_std_proc_macro" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "object" +version = "0.36.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" +dependencies = [ + "crc32fast", + "hashbrown 0.15.0", + "indexmap", + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "postcard" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f7f0a8d620d71c457dd1d47df76bb18960378da56af4527aaa10f515eee732e" +dependencies = [ + "cobs", + "embedded-io 0.4.0", + "embedded-io 0.6.1", + "serde", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "psm" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa37f80ca58604976033fae9515a8a2989fc13797d953f7c04fb8fa36a11f205" +dependencies = [ + "cc", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[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 = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "slice-group-by" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +dependencies = [ + "serde", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spinning_top" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b9eb1a2f4c41445a3a0ff9abc5221c5fcd28e1f13cd7c0397706f9ac938ddb0" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "target-lexicon" +version = "0.12.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" + +[[package]] +name = "thiserror" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "thiserror-impl-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58e6318948b519ba6dc2b442a6d0b904ebfb8d411a3ad3e07843615a72249758" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "thiserror-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3ad459d94dd517257cc96add8a43190ee620011bb6e6cdc82dafd97dfafafea" +dependencies = [ + "thiserror-impl-no-std", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasm-encoder" +version = "0.209.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4a05336882dae732ce6bd48b7e11fe597293cb72c13da4f35d7d5f8d53b2a7" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasmparser" +version = "0.209.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07035cc9a9b41e62d3bb3a3815a66ab87c993c06fe1cf6b2a3f2a18499d937db" +dependencies = [ + "ahash", + "bitflags", + "hashbrown 0.14.5", + "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", +] + +[[package]] +name = "wasmtime" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "786d8b5e7a4d54917c5ebe555b9667337e5f93383f49bddaaeec2eba68093b45" +dependencies = [ + "anyhow", + "bumpalo", + "cc", + "cfg-if", + "encoding_rs", + "hashbrown 0.14.5", + "indexmap", + "libc", + "libm", + "log", + "mach2", + "memfd", + "memoffset", + "object", + "once_cell", + "paste", + "postcard", + "psm", + "rustix", + "semver", + "serde", + "serde_derive", + "smallvec", + "sptr", + "target-lexicon", + "wasmparser", + "wasmtime-asm-macros", + "wasmtime-component-macro", + "wasmtime-component-util", + "wasmtime-cranelift", + "wasmtime-environ", + "wasmtime-jit-icache-coherence", + "wasmtime-slab", + "wasmtime-versioned-export-macros", + "wasmtime-winch", + "windows-sys", +] + +[[package]] +name = "wasmtime-asm-macros" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d697d99c341d4a9ffb72f3af7a02124d233eeb59aee010f36d88e97cca553d5e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "wasmtime-component-macro" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b29b462b068e73b5b27fae092a27f47e5937cabf6b26be2779c978698a52feca" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn 2.0.79", + "wasmtime-component-util", + "wasmtime-wit-bindgen", + "wit-parser", +] + +[[package]] +name = "wasmtime-component-util" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d2912c53d9054984b380dfbd7579f9c3681b2a73b903a56bd71a1c4f175f1e" + +[[package]] +name = "wasmtime-cranelift" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3975deafea000457ba84355c7c0fce0372937204f77026510b7b454f28a3a65" +dependencies = [ + "anyhow", + "cfg-if", + "cranelift-codegen", + "cranelift-control", + "cranelift-entity", + "cranelift-frontend", + "cranelift-native", + "cranelift-wasm", + "gimli", + "log", + "object", + "target-lexicon", + "thiserror", + "wasmparser", + "wasmtime-environ", + "wasmtime-versioned-export-macros", +] + +[[package]] +name = "wasmtime-environ" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f444e900e848b884d8a8a2949b6f5b92af642a3e663ff8fbe78731143a55be61" +dependencies = [ + "anyhow", + "cranelift-entity", + "gimli", + "indexmap", + "log", + "object", + "postcard", + "serde", + "serde_derive", + "target-lexicon", + "wasm-encoder", + "wasmparser", + "wasmprinter", + "wasmtime-component-util", + "wasmtime-types", +] + +[[package]] +name = "wasmtime-jit-icache-coherence" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5afe2f0499542f9a4bcfa1b55bfdda803b6ade4e7c93c6b99e0f39dba44b0a91" +dependencies = [ + "anyhow", + "cfg-if", + "libc", + "windows-sys", +] + +[[package]] +name = "wasmtime-slab" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a7de1f2bec5bbb35d532e61c85c049dc84ae671df60492f90b954ecf21169e7" + +[[package]] +name = "wasmtime-types" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "412463e9000e14cf6856be48628d2213c20c153e29ffc22b036980c892ea6964" +dependencies = [ + "cranelift-entity", + "serde", + "serde_derive", + "smallvec", + "wasmparser", +] + +[[package]] +name = "wasmtime-versioned-export-macros" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de5a9bc4f44ceeb168e9e8e3be4e0b4beb9095b468479663a9e24c667e36826f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "wasmtime-winch" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed4db238a0241df2d15f79ad17b3a37a27f2ea6cb885894d81b42ae107544466" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "object", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", + "winch-codegen", +] + +[[package]] +name = "wasmtime-wit-bindgen" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc077306b38288262e5ba01d4b21532a6987416cdc0aedf04bb06c22a68fdc" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "wit-parser", +] + +[[package]] +name = "wasmtime_cpython" +version = "0.1.0" +dependencies = [ + "lazy_static", + "ms_hostcall", + "ms_std", + "spin", + "wasmtime_wasi_api", +] + +[[package]] +name = "wasmtime_wasi_api" +version = "0.1.0" +dependencies = [ + "hashbrown 0.14.5", + "lazy_static", + "ms_hostcall", + "ms_std", + "ms_std_proc_macro", + "spin", + "wasmtime", +] + +[[package]] +name = "winch-codegen" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85c6915884e731b2db0d8cf08cb64474cb69221a161675fd3c135f91febc3daa" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "regalloc2", + "smallvec", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +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", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[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", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] diff --git a/user/wasmtime_cpython/Cargo.toml b/user/wasmtime_cpython/Cargo.toml new file mode 100755 index 00000000..9c43bdf7 --- /dev/null +++ b/user/wasmtime_cpython/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "wasmtime_cpython" +version = "0.1.0" +edition = "2021" +build = "build.rs" +# build = "../../build_user.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +# crate-type = ["dylib"] +crate-type = ["staticlib"] + +[dependencies] +ms_std = { path = "../../ms_std", features = ["panic_def", "alloc_def"] } +ms_hostcall = { path = "../../ms_hostcall" } +wasmtime_wasi_api = { path = "../../wasmtime_wasi_api" } + +lazy_static = { version = "1.5.0", features = ["spin_no_std"] } +spin = "0.9.8" + +[features] +mpk = ["ms_std/mpk"] +log = ["wasmtime_wasi_api/log"] diff --git a/user/wasmtime_cpython/build.rs b/user/wasmtime_cpython/build.rs new file mode 100644 index 00000000..9fc09ddf --- /dev/null +++ b/user/wasmtime_cpython/build.rs @@ -0,0 +1,4 @@ +fn main() { + println!("cargo:rustc-link-lib=static={}", "wasmtime-platform"); + println!("cargo:rustc-link-search=native={}", "./"); +} diff --git a/user/wasmtime_cpython/libwasmtime-platform.a b/user/wasmtime_cpython/libwasmtime-platform.a new file mode 100644 index 00000000..beebf570 Binary files /dev/null and b/user/wasmtime_cpython/libwasmtime-platform.a differ diff --git a/user/wasmtime_cpython/libwasmtime-platform.o b/user/wasmtime_cpython/libwasmtime-platform.o new file mode 100644 index 00000000..90bbf6dd Binary files /dev/null and b/user/wasmtime_cpython/libwasmtime-platform.o differ diff --git a/user/wasmtime_cpython/python.cwasm b/user/wasmtime_cpython/python.cwasm new file mode 100644 index 00000000..998e1f6e Binary files /dev/null and b/user/wasmtime_cpython/python.cwasm differ diff --git a/user/wasmtime_cpython/python.wasm b/user/wasmtime_cpython/python.wasm new file mode 100755 index 00000000..b9ce0324 Binary files /dev/null and b/user/wasmtime_cpython/python.wasm differ diff --git a/user/wasmtime_cpython/src/lib.rs b/user/wasmtime_cpython/src/lib.rs new file mode 100755 index 00000000..f70f3094 --- /dev/null +++ b/user/wasmtime_cpython/src/lib.rs @@ -0,0 +1,64 @@ +#![no_std] + +extern crate alloc; + +use alloc::{string::{String, ToString}, vec::Vec}; +use spin::Mutex; + +use ms_hostcall::types::{OpenFlags, OpenMode}; +use ms_std::{agent::FaaSFuncResult as Result, args, libos::libos, println, time::{SystemTime, UNIX_EPOCH},}; + +use wasmtime_wasi_api::{wasmtime, LibosCtx}; +use wasmtime::Store; + +const CWASM: &[u8] = include_bytes!("../python.cwasm"); + +static INIT_LOCK: Mutex<()> = Mutex::new(()); + +lazy_static::lazy_static! { + static ref MUST_OPEN_ROOT: bool = { + libos!(open("/", OpenFlags::empty(), OpenMode::RD)).unwrap(); + true + }; +} + +fn func_body(my_id: &str, pyfile_path: &str) -> Result<()> { + #[cfg(feature = "log")] + println!("rust: my_id: {:?}, pyfile_path: {:?}", my_id, pyfile_path); + + let wasi_args: Vec = Vec::from([ + "fake system path!".to_string(), + pyfile_path.to_string(), + ]); + wasmtime_wasi_api::set_wasi_args(my_id, wasi_args); + + let _open_root = *MUST_OPEN_ROOT; + + let lock = INIT_LOCK.lock(); + let (engine, module, linker) = wasmtime_wasi_api::build_wasm(CWASM); + drop(lock); + + let mut store = Store::new(&engine, LibosCtx{id: my_id.to_string()}); + let instance = linker.instantiate(&mut store, &module)?; + + let main = instance + .get_typed_func::<(), ()>(&mut store, "_start") + .map_err(|e| e.to_string())?; + + println!("{}", SystemTime::now().duration_since(UNIX_EPOCH).as_nanos()); + main.call(store, ()).map_err(|e| e.to_string())?; + + #[cfg(feature = "log")] + println!("rust: wasmtime_cpython_{:?} finished!", my_id); + + Ok(().into()) +} + + +#[no_mangle] +pub fn main() -> Result<()> { + let my_id = args::get("id").unwrap(); + let pyfile_path = args::get("pyfile_path").unwrap(); + + func_body(my_id, pyfile_path) +} diff --git a/user/wasmtime_func_a/Cargo.lock b/user/wasmtime_func_a/Cargo.lock new file mode 100644 index 00000000..cab80106 --- /dev/null +++ b/user/wasmtime_func_a/Cargo.lock @@ -0,0 +1,1195 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + +[[package]] +name = "arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cc" +version = "1.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cobs" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "cranelift-bforest" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6b33d7e757a887989eb18b35712b2a67d96171ec3149d1bfb657b29b7b367c" +dependencies = [ + "cranelift-entity", +] + +[[package]] +name = "cranelift-codegen" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9acf15cb22be42d07c3b57d7856329cb228b7315d385346149df2566ad5e4aa" +dependencies = [ + "bumpalo", + "cranelift-bforest", + "cranelift-codegen-meta", + "cranelift-codegen-shared", + "cranelift-control", + "cranelift-entity", + "cranelift-isle", + "gimli", + "hashbrown 0.14.5", + "log", + "regalloc2", + "rustc-hash", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e934d301392b73b3f8b0540391fb82465a0f179a3cee7c726482ac4727efcc97" +dependencies = [ + "cranelift-codegen-shared", +] + +[[package]] +name = "cranelift-codegen-shared" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb2a2566b3d54b854dfb288b3b187f6d3d17d6f762c92898207eba302931da" + +[[package]] +name = "cranelift-control" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0100f33b704cdacd01ad66ff41f8c5030d57cbff078e2a4e49ab1822591299fa" +dependencies = [ + "arbitrary", +] + +[[package]] +name = "cranelift-entity" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8cfdc315e5d18997093e040a8d234bea1ac1e118a716d3e30f40d449e78207b" +dependencies = [ + "serde", + "serde_derive", +] + +[[package]] +name = "cranelift-frontend" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f74b84f16af2e982b0c0c72233503d9d55cbfe3865dbe807ca28dc6642a28b5" +dependencies = [ + "cranelift-codegen", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-isle" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adf306d3dde705fb94bd48082f01d38c4ededc74293a4c007805f610bf08bc6e" + +[[package]] +name = "cranelift-native" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ea0ebdef7aff4a79bcbc8b6495f31315f16b3bf311152f472eaa8d679352581" +dependencies = [ + "cranelift-codegen", + "libc", + "target-lexicon", +] + +[[package]] +name = "cranelift-wasm" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d549108a1942065cdbac3bb96c2952afa0e1b9a3beff4b08c4308ac72257576d" +dependencies = [ + "cranelift-codegen", + "cranelift-entity", + "cranelift-frontend", + "itertools", + "log", + "smallvec", + "wasmparser", + "wasmtime-types", +] + +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn 2.0.79", +] + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[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.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + +[[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 = "hash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" +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.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +dependencies = [ + "foldhash", +] + +[[package]] +name = "heapless" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" +dependencies = [ + "hash32", + "stable_deref_trait", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + +[[package]] +name = "indexmap" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +dependencies = [ + "equivalent", + "hashbrown 0.15.0", + "serde", +] + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + +[[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.159" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "linked_list_allocator" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286" +dependencies = [ + "spinning_top", +] + +[[package]] +name = "linux-raw-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1ad52afd8f9448cbbe722ae722849cc41f1d365e285cca386896352bc08e1a9" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mach2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" +dependencies = [ + "libc", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "memfd" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" +dependencies = [ + "rustix", +] + +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "ms_hostcall" +version = "0.1.0" +dependencies = [ + "bitflags", + "derive_more", + "thiserror-no-std", +] + +[[package]] +name = "ms_std" +version = "0.1.0" +dependencies = [ + "cfg-if", + "heapless", + "linked_list_allocator", + "ms_hostcall", + "ms_std_proc_macro", + "spin", + "thiserror-no-std", +] + +[[package]] +name = "ms_std_proc_macro" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "naked-function" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b8d5fca6ab1e6215b010aefd3b9ac5aae369dae0faea3a7f34f296cc9f719ac" +dependencies = [ + "cfg-if", + "naked-function-macro", +] + +[[package]] +name = "naked-function-macro" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b4123e70df5fe0bb370cff166ae453b9c5324a2cfc932c0f7e55498147a0475" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "object" +version = "0.36.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" +dependencies = [ + "crc32fast", + "hashbrown 0.15.0", + "indexmap", + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "postcard" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f7f0a8d620d71c457dd1d47df76bb18960378da56af4527aaa10f515eee732e" +dependencies = [ + "cobs", + "embedded-io 0.4.0", + "embedded-io 0.6.1", + "serde", +] + +[[package]] +name = "proc-macro2" +version = "1.0.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "psm" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa37f80ca58604976033fae9515a8a2989fc13797d953f7c04fb8fa36a11f205" +dependencies = [ + "cc", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[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 = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys 0.4.14", + "windows-sys", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "sc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "010e18bd3bfd1d45a7e666b236c78720df0d9a7698ebaa9c1c559961eb60a38b" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "sjlj" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9b43efc387069aabdc27124a294337c7032a3cb62df0108d2578eff7f08e39" +dependencies = [ + "linux-raw-sys 0.2.2", + "naked-function", + "sc", +] + +[[package]] +name = "slice-group-by" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +dependencies = [ + "serde", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spinning_top" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b9eb1a2f4c41445a3a0ff9abc5221c5fcd28e1f13cd7c0397706f9ac938ddb0" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "target-lexicon" +version = "0.12.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" + +[[package]] +name = "thiserror" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "thiserror-impl-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58e6318948b519ba6dc2b442a6d0b904ebfb8d411a3ad3e07843615a72249758" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "thiserror-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3ad459d94dd517257cc96add8a43190ee620011bb6e6cdc82dafd97dfafafea" +dependencies = [ + "thiserror-impl-no-std", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasm-encoder" +version = "0.209.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4a05336882dae732ce6bd48b7e11fe597293cb72c13da4f35d7d5f8d53b2a7" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasmparser" +version = "0.209.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07035cc9a9b41e62d3bb3a3815a66ab87c993c06fe1cf6b2a3f2a18499d937db" +dependencies = [ + "ahash", + "bitflags", + "hashbrown 0.14.5", + "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", +] + +[[package]] +name = "wasmtime" +version = "22.0.0" +source = "git+https://gitee.com/tju-cloud-computing/wasmtime-as-lib?branch=master#fb45fb8dde6d068abb3ae78bfab78253c9654af5" +dependencies = [ + "anyhow", + "bumpalo", + "cc", + "cfg-if", + "encoding_rs", + "hashbrown 0.14.5", + "indexmap", + "libc", + "libm", + "log", + "mach2", + "memfd", + "memoffset", + "object", + "once_cell", + "paste", + "postcard", + "psm", + "rustix", + "semver", + "serde", + "serde_derive", + "smallvec", + "sptr", + "target-lexicon", + "wasmparser", + "wasmtime-asm-macros", + "wasmtime-component-macro", + "wasmtime-component-util", + "wasmtime-cranelift", + "wasmtime-environ", + "wasmtime-jit-icache-coherence", + "wasmtime-slab", + "wasmtime-versioned-export-macros", + "wasmtime-winch", + "windows-sys", +] + +[[package]] +name = "wasmtime-asm-macros" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d697d99c341d4a9ffb72f3af7a02124d233eeb59aee010f36d88e97cca553d5e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "wasmtime-component-macro" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b29b462b068e73b5b27fae092a27f47e5937cabf6b26be2779c978698a52feca" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn 2.0.79", + "wasmtime-component-util", + "wasmtime-wit-bindgen", + "wit-parser", +] + +[[package]] +name = "wasmtime-component-util" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d2912c53d9054984b380dfbd7579f9c3681b2a73b903a56bd71a1c4f175f1e" + +[[package]] +name = "wasmtime-cranelift" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3975deafea000457ba84355c7c0fce0372937204f77026510b7b454f28a3a65" +dependencies = [ + "anyhow", + "cfg-if", + "cranelift-codegen", + "cranelift-control", + "cranelift-entity", + "cranelift-frontend", + "cranelift-native", + "cranelift-wasm", + "gimli", + "log", + "object", + "target-lexicon", + "thiserror", + "wasmparser", + "wasmtime-environ", + "wasmtime-versioned-export-macros", +] + +[[package]] +name = "wasmtime-environ" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f444e900e848b884d8a8a2949b6f5b92af642a3e663ff8fbe78731143a55be61" +dependencies = [ + "anyhow", + "cranelift-entity", + "gimli", + "indexmap", + "log", + "object", + "postcard", + "serde", + "serde_derive", + "target-lexicon", + "wasm-encoder", + "wasmparser", + "wasmprinter", + "wasmtime-component-util", + "wasmtime-types", +] + +[[package]] +name = "wasmtime-jit-icache-coherence" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5afe2f0499542f9a4bcfa1b55bfdda803b6ade4e7c93c6b99e0f39dba44b0a91" +dependencies = [ + "anyhow", + "cfg-if", + "libc", + "windows-sys", +] + +[[package]] +name = "wasmtime-slab" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a7de1f2bec5bbb35d532e61c85c049dc84ae671df60492f90b954ecf21169e7" + +[[package]] +name = "wasmtime-types" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "412463e9000e14cf6856be48628d2213c20c153e29ffc22b036980c892ea6964" +dependencies = [ + "cranelift-entity", + "serde", + "serde_derive", + "smallvec", + "wasmparser", +] + +[[package]] +name = "wasmtime-versioned-export-macros" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de5a9bc4f44ceeb168e9e8e3be4e0b4beb9095b468479663a9e24c667e36826f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "wasmtime-winch" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed4db238a0241df2d15f79ad17b3a37a27f2ea6cb885894d81b42ae107544466" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "object", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", + "winch-codegen", +] + +[[package]] +name = "wasmtime-wit-bindgen" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc077306b38288262e5ba01d4b21532a6987416cdc0aedf04bb06c22a68fdc" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "wit-parser", +] + +[[package]] +name = "wasmtime_mapper" +version = "0.1.0" +dependencies = [ + "lazy_static", + "ms_hostcall", + "ms_std", + "spin", + "wasmtime_wasi_api", +] + +[[package]] +name = "wasmtime_wasi_api" +version = "0.1.0" +dependencies = [ + "hashbrown 0.14.5", + "lazy_static", + "ms_hostcall", + "ms_std", + "ms_std_proc_macro", + "sjlj", + "spin", + "wasmtime", +] + +[[package]] +name = "winch-codegen" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85c6915884e731b2db0d8cf08cb64474cb69221a161675fd3c135f91febc3daa" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "regalloc2", + "smallvec", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +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", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[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", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] diff --git a/user/wasmtime_func_a/Cargo.toml b/user/wasmtime_func_a/Cargo.toml new file mode 100644 index 00000000..73966ea7 --- /dev/null +++ b/user/wasmtime_func_a/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "wasmtime_mapper" +version = "0.1.0" +edition = "2021" +build = "build.rs" +# build = "../../build_wasm.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +crate-type = ["staticlib"] + +[dependencies] +ms_std = { path = "../../ms_std", features = ["panic_def", "alloc_def"] } +ms_hostcall = { path = "../../ms_hostcall", features = ["signal"] } + +wasmtime_wasi_api = { path = "../../wasmtime_wasi_api" } + +lazy_static = { version = "1.5.0", features = ["spin_no_std"] } +spin = "0.9.8" + +[features] +mpk = ["ms_std/mpk"] diff --git a/user/wasmtime_func_a/build.rs b/user/wasmtime_func_a/build.rs new file mode 100644 index 00000000..9fc09ddf --- /dev/null +++ b/user/wasmtime_func_a/build.rs @@ -0,0 +1,4 @@ +fn main() { + println!("cargo:rustc-link-lib=static={}", "wasmtime-platform"); + println!("cargo:rustc-link-search=native={}", "./"); +} diff --git a/user/wasmtime_func_a/build.sh b/user/wasmtime_func_a/build.sh new file mode 100755 index 00000000..0c6cecb6 --- /dev/null +++ b/user/wasmtime_func_a/build.sh @@ -0,0 +1,15 @@ +$CPP mapper.cpp -o mapper.wasm -fno-exceptions -fno-rtti -ffast-math -funroll-loops -fomit-frame-pointer -Ofast +# $CC mapper.c -o mapper.wasm -O3 + +wasmtime compile --target x86_64-unknown-none -W threads=n,tail-call=n mapper.wasm + +cargo build --target x86_64-unknown-none --release && cc \ + -Wl,--gc-sections -nostdlib \ + -Wl,--whole-archive \ + target/x86_64-unknown-none/release/libwasmtime_mapper.a \ + -Wl,--no-whole-archive \ + -shared \ + -o target/x86_64-unknown-none/release/libwasmtime_mapper.so + +ln -s /home/wyj/alloy_stack/mslibos/user/wasmtime_mapper/target/x86_64-unknown-none/release/libwasmtime_mapper.so /home/wyj/alloy_stack/mslibos/target/release/libwasmtime_mapper.so + diff --git a/user/wasmtime_func_a/func_a.cpp b/user/wasmtime_func_a/func_a.cpp new file mode 100644 index 00000000..c41965d8 --- /dev/null +++ b/user/wasmtime_func_a/func_a.cpp @@ -0,0 +1,109 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +#define MAX_SLOT_NUM 10 +#define MAX_WORDS 20000000 +#define MAX_BUFFER_SIZE 500000 + +string words[MAX_WORDS]; +int counts[MAX_WORDS]; + +__attribute__((import_module("env"), import_name("buffer_register"))) void buffer_register(void *slot_name, int name_size, void *buffer, int buffer_size); + +void get_time() { + timeval tv{}; + gettimeofday(&tv, nullptr); + printf("%lld.%lld\n", tv.tv_sec, tv.tv_usec); +} + +int main(int argc, char* argv[]) { + int id = atoi(argv[1]); + int reducer_num = atoi(argv[2]); + cout << "mapper_" << id << " start!" << endl; + + string input_file = "fake_data_" + to_string(id) + ".txt"; + ifstream file(input_file); + + int word_index = 0; + + string word; + // vector words; + // vector counts; + + + printf("start reading file\n"); + get_time(); + while (file >> word) { + transform(word.begin(), word.end(), word.begin(), + [](unsigned char c) { return std::tolower(c); }); + int found = 0; + for (int i = 0; i < word_index; i++) { + if (words[i] == word) { + counts[i]++; + found = 1; + break; + } + } + if (!found) { + words[word_index] = word; + counts[word_index] = 1; + // words.push_back(word); + // counts.push_back(1); + // words.emplace_back(word); + // count.emplace_back(1); + word_index++; + } + } + printf("finish reading file\n"); + get_time(); + // return 0; + file.close(); + + cout << "mapper_" << id << " read success!" << endl; + + string buffer[MAX_SLOT_NUM]; + string slot_name[MAX_SLOT_NUM]; + int slot_index = 0; + + for (int i = 0; i < word_index; i++) { + int partition_index = i % reducer_num; + string slot = "buffer_" + to_string(partition_index) + "_" + to_string(id); + int found = 0; + for (int j = 0; j < slot_index; j++) { + if (slot_name[j] == slot) { + found = 1; + buffer[j].append(words[i] + ": " + to_string(counts[i]) + "\n"); + break; + } + } + + if (!found) { + slot_name[slot_index] = slot; + buffer[slot_index] = words[i] + ": " + to_string(counts[i]) + "\n"; + slot_index++; + } + } + + for (int i = 0; i < MAX_SLOT_NUM; i++) { + buffer[i].resize(MAX_BUFFER_SIZE, '\0'); + } + + + cout << "mapper_" << id << " solved " << word_index << " words!" << endl; + for (int i = 0; i < slot_index; i++) { + buffer_register((void*)slot_name[i].c_str(), slot_name[i].length(), (void*)buffer[i].c_str(), buffer[i].size()); + // cout << "buffersize" << i << ": " << buffer[i].size() << endl; + } + cout << "mapper_" << id << " write finished!" << endl; + + return 0; +} \ No newline at end of file diff --git a/user/wasmtime_func_a/libwasmtime-platform.a b/user/wasmtime_func_a/libwasmtime-platform.a new file mode 100644 index 00000000..beebf570 Binary files /dev/null and b/user/wasmtime_func_a/libwasmtime-platform.a differ diff --git a/user/wasmtime_func_a/libwasmtime-platform.o b/user/wasmtime_func_a/libwasmtime-platform.o new file mode 100644 index 00000000..90bbf6dd Binary files /dev/null and b/user/wasmtime_func_a/libwasmtime-platform.o differ diff --git a/user/wasmtime_func_a/src/lib.rs b/user/wasmtime_func_a/src/lib.rs new file mode 100644 index 00000000..fd2abb4e --- /dev/null +++ b/user/wasmtime_func_a/src/lib.rs @@ -0,0 +1,76 @@ +#![no_std] + +extern crate alloc; +use core::mem::forget; + +use alloc::{string::{String, ToString}, vec::Vec}; +use spin::Mutex; + +use ms_hostcall::types::{OpenFlags, OpenMode}; +use ms_std::{agent::FaaSFuncResult as Result, args, println, libos::libos, time::{SystemTime, UNIX_EPOCH}}; + + +use wasmtime_wasi_api::{wasmtime, LibosCtx}; +use wasmtime::Store; + +static CWASM: &[u8] = include_bytes!("../mapper.cwasm"); + +static INIT_LOCK: Mutex<()> = Mutex::new(()); + +lazy_static::lazy_static! { + static ref MUST_OPEN_ROOT: bool = { + libos!(open("/", OpenFlags::empty(), OpenMode::RD)).unwrap(); + true + }; +} + +fn func_body(my_id: &str, reducer_num: u64) -> Result<()> { + #[cfg(feature = "log")] + + println!("rust: my_id: {:?}, reducer_num: {:?}", my_id, reducer_num); + + let wasi_args: Vec = Vec::from([ + "fake system path!".to_string(), + my_id.to_string(), + reducer_num.to_string(), + ]); + wasmtime_wasi_api::set_wasi_args(my_id, wasi_args); + + let _open_root = *MUST_OPEN_ROOT; + + let lock = INIT_LOCK.lock(); + let (engine, module, linker) = wasmtime_wasi_api::build_wasm(CWASM); + drop(lock); + + let mut store = Store::new(&engine, LibosCtx{id: my_id.to_string()}); + let instance = linker.instantiate(&mut store, &module)?; + + let mut memory = instance.get_memory(&mut store, "memory").unwrap(); + let pages = memory.grow(&mut store, 20000).unwrap(); + println!("rust: pages: {}", pages); + + let main = instance + .get_typed_func::<(), ()>(&mut store, "_start") + .map_err(|e| e.to_string())?; + + let start_time = SystemTime::now().duration_since(UNIX_EPOCH).as_millis(); + println!("start_time: {:?}", start_time); + main.call(store, ()).map_err(|e| e.to_string())?; + + #[cfg(feature = "log")] + println!("rust: wasmtime_mapper_{:?} finished!", my_id); + let end_time = SystemTime::now().duration_since(UNIX_EPOCH).as_millis(); + println!("end_time: {:?}", end_time); + Ok(().into()) +} + +#[no_mangle] +pub fn main() -> Result<()> { + let my_id = args::get("id").unwrap(); + let reducer_num: u64 = args::get("reducer_num") + .expect("missing arg reducer_num") + .parse() + .unwrap_or_else(|_| panic!("bad arg, reducer_num={}", args::get("reducer_num").unwrap())); + + func_body(my_id, reducer_num) +} diff --git a/user/wasmtime_func_b/Cargo.lock b/user/wasmtime_func_b/Cargo.lock new file mode 100644 index 00000000..cab80106 --- /dev/null +++ b/user/wasmtime_func_b/Cargo.lock @@ -0,0 +1,1195 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + +[[package]] +name = "arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cc" +version = "1.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cobs" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "cranelift-bforest" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6b33d7e757a887989eb18b35712b2a67d96171ec3149d1bfb657b29b7b367c" +dependencies = [ + "cranelift-entity", +] + +[[package]] +name = "cranelift-codegen" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9acf15cb22be42d07c3b57d7856329cb228b7315d385346149df2566ad5e4aa" +dependencies = [ + "bumpalo", + "cranelift-bforest", + "cranelift-codegen-meta", + "cranelift-codegen-shared", + "cranelift-control", + "cranelift-entity", + "cranelift-isle", + "gimli", + "hashbrown 0.14.5", + "log", + "regalloc2", + "rustc-hash", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e934d301392b73b3f8b0540391fb82465a0f179a3cee7c726482ac4727efcc97" +dependencies = [ + "cranelift-codegen-shared", +] + +[[package]] +name = "cranelift-codegen-shared" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb2a2566b3d54b854dfb288b3b187f6d3d17d6f762c92898207eba302931da" + +[[package]] +name = "cranelift-control" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0100f33b704cdacd01ad66ff41f8c5030d57cbff078e2a4e49ab1822591299fa" +dependencies = [ + "arbitrary", +] + +[[package]] +name = "cranelift-entity" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8cfdc315e5d18997093e040a8d234bea1ac1e118a716d3e30f40d449e78207b" +dependencies = [ + "serde", + "serde_derive", +] + +[[package]] +name = "cranelift-frontend" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f74b84f16af2e982b0c0c72233503d9d55cbfe3865dbe807ca28dc6642a28b5" +dependencies = [ + "cranelift-codegen", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-isle" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adf306d3dde705fb94bd48082f01d38c4ededc74293a4c007805f610bf08bc6e" + +[[package]] +name = "cranelift-native" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ea0ebdef7aff4a79bcbc8b6495f31315f16b3bf311152f472eaa8d679352581" +dependencies = [ + "cranelift-codegen", + "libc", + "target-lexicon", +] + +[[package]] +name = "cranelift-wasm" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d549108a1942065cdbac3bb96c2952afa0e1b9a3beff4b08c4308ac72257576d" +dependencies = [ + "cranelift-codegen", + "cranelift-entity", + "cranelift-frontend", + "itertools", + "log", + "smallvec", + "wasmparser", + "wasmtime-types", +] + +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn 2.0.79", +] + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[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.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + +[[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 = "hash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" +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.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +dependencies = [ + "foldhash", +] + +[[package]] +name = "heapless" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" +dependencies = [ + "hash32", + "stable_deref_trait", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + +[[package]] +name = "indexmap" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +dependencies = [ + "equivalent", + "hashbrown 0.15.0", + "serde", +] + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + +[[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.159" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "linked_list_allocator" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286" +dependencies = [ + "spinning_top", +] + +[[package]] +name = "linux-raw-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1ad52afd8f9448cbbe722ae722849cc41f1d365e285cca386896352bc08e1a9" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mach2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" +dependencies = [ + "libc", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "memfd" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" +dependencies = [ + "rustix", +] + +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "ms_hostcall" +version = "0.1.0" +dependencies = [ + "bitflags", + "derive_more", + "thiserror-no-std", +] + +[[package]] +name = "ms_std" +version = "0.1.0" +dependencies = [ + "cfg-if", + "heapless", + "linked_list_allocator", + "ms_hostcall", + "ms_std_proc_macro", + "spin", + "thiserror-no-std", +] + +[[package]] +name = "ms_std_proc_macro" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "naked-function" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b8d5fca6ab1e6215b010aefd3b9ac5aae369dae0faea3a7f34f296cc9f719ac" +dependencies = [ + "cfg-if", + "naked-function-macro", +] + +[[package]] +name = "naked-function-macro" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b4123e70df5fe0bb370cff166ae453b9c5324a2cfc932c0f7e55498147a0475" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "object" +version = "0.36.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" +dependencies = [ + "crc32fast", + "hashbrown 0.15.0", + "indexmap", + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "postcard" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f7f0a8d620d71c457dd1d47df76bb18960378da56af4527aaa10f515eee732e" +dependencies = [ + "cobs", + "embedded-io 0.4.0", + "embedded-io 0.6.1", + "serde", +] + +[[package]] +name = "proc-macro2" +version = "1.0.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "psm" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa37f80ca58604976033fae9515a8a2989fc13797d953f7c04fb8fa36a11f205" +dependencies = [ + "cc", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[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 = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys 0.4.14", + "windows-sys", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "sc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "010e18bd3bfd1d45a7e666b236c78720df0d9a7698ebaa9c1c559961eb60a38b" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "sjlj" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9b43efc387069aabdc27124a294337c7032a3cb62df0108d2578eff7f08e39" +dependencies = [ + "linux-raw-sys 0.2.2", + "naked-function", + "sc", +] + +[[package]] +name = "slice-group-by" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +dependencies = [ + "serde", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spinning_top" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b9eb1a2f4c41445a3a0ff9abc5221c5fcd28e1f13cd7c0397706f9ac938ddb0" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "target-lexicon" +version = "0.12.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" + +[[package]] +name = "thiserror" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "thiserror-impl-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58e6318948b519ba6dc2b442a6d0b904ebfb8d411a3ad3e07843615a72249758" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "thiserror-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3ad459d94dd517257cc96add8a43190ee620011bb6e6cdc82dafd97dfafafea" +dependencies = [ + "thiserror-impl-no-std", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasm-encoder" +version = "0.209.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4a05336882dae732ce6bd48b7e11fe597293cb72c13da4f35d7d5f8d53b2a7" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasmparser" +version = "0.209.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07035cc9a9b41e62d3bb3a3815a66ab87c993c06fe1cf6b2a3f2a18499d937db" +dependencies = [ + "ahash", + "bitflags", + "hashbrown 0.14.5", + "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", +] + +[[package]] +name = "wasmtime" +version = "22.0.0" +source = "git+https://gitee.com/tju-cloud-computing/wasmtime-as-lib?branch=master#fb45fb8dde6d068abb3ae78bfab78253c9654af5" +dependencies = [ + "anyhow", + "bumpalo", + "cc", + "cfg-if", + "encoding_rs", + "hashbrown 0.14.5", + "indexmap", + "libc", + "libm", + "log", + "mach2", + "memfd", + "memoffset", + "object", + "once_cell", + "paste", + "postcard", + "psm", + "rustix", + "semver", + "serde", + "serde_derive", + "smallvec", + "sptr", + "target-lexicon", + "wasmparser", + "wasmtime-asm-macros", + "wasmtime-component-macro", + "wasmtime-component-util", + "wasmtime-cranelift", + "wasmtime-environ", + "wasmtime-jit-icache-coherence", + "wasmtime-slab", + "wasmtime-versioned-export-macros", + "wasmtime-winch", + "windows-sys", +] + +[[package]] +name = "wasmtime-asm-macros" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d697d99c341d4a9ffb72f3af7a02124d233eeb59aee010f36d88e97cca553d5e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "wasmtime-component-macro" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b29b462b068e73b5b27fae092a27f47e5937cabf6b26be2779c978698a52feca" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn 2.0.79", + "wasmtime-component-util", + "wasmtime-wit-bindgen", + "wit-parser", +] + +[[package]] +name = "wasmtime-component-util" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d2912c53d9054984b380dfbd7579f9c3681b2a73b903a56bd71a1c4f175f1e" + +[[package]] +name = "wasmtime-cranelift" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3975deafea000457ba84355c7c0fce0372937204f77026510b7b454f28a3a65" +dependencies = [ + "anyhow", + "cfg-if", + "cranelift-codegen", + "cranelift-control", + "cranelift-entity", + "cranelift-frontend", + "cranelift-native", + "cranelift-wasm", + "gimli", + "log", + "object", + "target-lexicon", + "thiserror", + "wasmparser", + "wasmtime-environ", + "wasmtime-versioned-export-macros", +] + +[[package]] +name = "wasmtime-environ" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f444e900e848b884d8a8a2949b6f5b92af642a3e663ff8fbe78731143a55be61" +dependencies = [ + "anyhow", + "cranelift-entity", + "gimli", + "indexmap", + "log", + "object", + "postcard", + "serde", + "serde_derive", + "target-lexicon", + "wasm-encoder", + "wasmparser", + "wasmprinter", + "wasmtime-component-util", + "wasmtime-types", +] + +[[package]] +name = "wasmtime-jit-icache-coherence" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5afe2f0499542f9a4bcfa1b55bfdda803b6ade4e7c93c6b99e0f39dba44b0a91" +dependencies = [ + "anyhow", + "cfg-if", + "libc", + "windows-sys", +] + +[[package]] +name = "wasmtime-slab" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a7de1f2bec5bbb35d532e61c85c049dc84ae671df60492f90b954ecf21169e7" + +[[package]] +name = "wasmtime-types" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "412463e9000e14cf6856be48628d2213c20c153e29ffc22b036980c892ea6964" +dependencies = [ + "cranelift-entity", + "serde", + "serde_derive", + "smallvec", + "wasmparser", +] + +[[package]] +name = "wasmtime-versioned-export-macros" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de5a9bc4f44ceeb168e9e8e3be4e0b4beb9095b468479663a9e24c667e36826f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "wasmtime-winch" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed4db238a0241df2d15f79ad17b3a37a27f2ea6cb885894d81b42ae107544466" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "object", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", + "winch-codegen", +] + +[[package]] +name = "wasmtime-wit-bindgen" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc077306b38288262e5ba01d4b21532a6987416cdc0aedf04bb06c22a68fdc" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "wit-parser", +] + +[[package]] +name = "wasmtime_mapper" +version = "0.1.0" +dependencies = [ + "lazy_static", + "ms_hostcall", + "ms_std", + "spin", + "wasmtime_wasi_api", +] + +[[package]] +name = "wasmtime_wasi_api" +version = "0.1.0" +dependencies = [ + "hashbrown 0.14.5", + "lazy_static", + "ms_hostcall", + "ms_std", + "ms_std_proc_macro", + "sjlj", + "spin", + "wasmtime", +] + +[[package]] +name = "winch-codegen" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85c6915884e731b2db0d8cf08cb64474cb69221a161675fd3c135f91febc3daa" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "regalloc2", + "smallvec", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +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", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[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", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] diff --git a/user/wasmtime_func_b/Cargo.toml b/user/wasmtime_func_b/Cargo.toml new file mode 100644 index 00000000..73966ea7 --- /dev/null +++ b/user/wasmtime_func_b/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "wasmtime_mapper" +version = "0.1.0" +edition = "2021" +build = "build.rs" +# build = "../../build_wasm.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +crate-type = ["staticlib"] + +[dependencies] +ms_std = { path = "../../ms_std", features = ["panic_def", "alloc_def"] } +ms_hostcall = { path = "../../ms_hostcall", features = ["signal"] } + +wasmtime_wasi_api = { path = "../../wasmtime_wasi_api" } + +lazy_static = { version = "1.5.0", features = ["spin_no_std"] } +spin = "0.9.8" + +[features] +mpk = ["ms_std/mpk"] diff --git a/user/wasmtime_func_b/build.rs b/user/wasmtime_func_b/build.rs new file mode 100644 index 00000000..9fc09ddf --- /dev/null +++ b/user/wasmtime_func_b/build.rs @@ -0,0 +1,4 @@ +fn main() { + println!("cargo:rustc-link-lib=static={}", "wasmtime-platform"); + println!("cargo:rustc-link-search=native={}", "./"); +} diff --git a/user/wasmtime_func_b/build.sh b/user/wasmtime_func_b/build.sh new file mode 100755 index 00000000..0c6cecb6 --- /dev/null +++ b/user/wasmtime_func_b/build.sh @@ -0,0 +1,15 @@ +$CPP mapper.cpp -o mapper.wasm -fno-exceptions -fno-rtti -ffast-math -funroll-loops -fomit-frame-pointer -Ofast +# $CC mapper.c -o mapper.wasm -O3 + +wasmtime compile --target x86_64-unknown-none -W threads=n,tail-call=n mapper.wasm + +cargo build --target x86_64-unknown-none --release && cc \ + -Wl,--gc-sections -nostdlib \ + -Wl,--whole-archive \ + target/x86_64-unknown-none/release/libwasmtime_mapper.a \ + -Wl,--no-whole-archive \ + -shared \ + -o target/x86_64-unknown-none/release/libwasmtime_mapper.so + +ln -s /home/wyj/alloy_stack/mslibos/user/wasmtime_mapper/target/x86_64-unknown-none/release/libwasmtime_mapper.so /home/wyj/alloy_stack/mslibos/target/release/libwasmtime_mapper.so + diff --git a/user/wasmtime_func_b/func_a.cpp b/user/wasmtime_func_b/func_a.cpp new file mode 100644 index 00000000..c41965d8 --- /dev/null +++ b/user/wasmtime_func_b/func_a.cpp @@ -0,0 +1,109 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +#define MAX_SLOT_NUM 10 +#define MAX_WORDS 20000000 +#define MAX_BUFFER_SIZE 500000 + +string words[MAX_WORDS]; +int counts[MAX_WORDS]; + +__attribute__((import_module("env"), import_name("buffer_register"))) void buffer_register(void *slot_name, int name_size, void *buffer, int buffer_size); + +void get_time() { + timeval tv{}; + gettimeofday(&tv, nullptr); + printf("%lld.%lld\n", tv.tv_sec, tv.tv_usec); +} + +int main(int argc, char* argv[]) { + int id = atoi(argv[1]); + int reducer_num = atoi(argv[2]); + cout << "mapper_" << id << " start!" << endl; + + string input_file = "fake_data_" + to_string(id) + ".txt"; + ifstream file(input_file); + + int word_index = 0; + + string word; + // vector words; + // vector counts; + + + printf("start reading file\n"); + get_time(); + while (file >> word) { + transform(word.begin(), word.end(), word.begin(), + [](unsigned char c) { return std::tolower(c); }); + int found = 0; + for (int i = 0; i < word_index; i++) { + if (words[i] == word) { + counts[i]++; + found = 1; + break; + } + } + if (!found) { + words[word_index] = word; + counts[word_index] = 1; + // words.push_back(word); + // counts.push_back(1); + // words.emplace_back(word); + // count.emplace_back(1); + word_index++; + } + } + printf("finish reading file\n"); + get_time(); + // return 0; + file.close(); + + cout << "mapper_" << id << " read success!" << endl; + + string buffer[MAX_SLOT_NUM]; + string slot_name[MAX_SLOT_NUM]; + int slot_index = 0; + + for (int i = 0; i < word_index; i++) { + int partition_index = i % reducer_num; + string slot = "buffer_" + to_string(partition_index) + "_" + to_string(id); + int found = 0; + for (int j = 0; j < slot_index; j++) { + if (slot_name[j] == slot) { + found = 1; + buffer[j].append(words[i] + ": " + to_string(counts[i]) + "\n"); + break; + } + } + + if (!found) { + slot_name[slot_index] = slot; + buffer[slot_index] = words[i] + ": " + to_string(counts[i]) + "\n"; + slot_index++; + } + } + + for (int i = 0; i < MAX_SLOT_NUM; i++) { + buffer[i].resize(MAX_BUFFER_SIZE, '\0'); + } + + + cout << "mapper_" << id << " solved " << word_index << " words!" << endl; + for (int i = 0; i < slot_index; i++) { + buffer_register((void*)slot_name[i].c_str(), slot_name[i].length(), (void*)buffer[i].c_str(), buffer[i].size()); + // cout << "buffersize" << i << ": " << buffer[i].size() << endl; + } + cout << "mapper_" << id << " write finished!" << endl; + + return 0; +} \ No newline at end of file diff --git a/user/wasmtime_func_b/libwasmtime-platform.a b/user/wasmtime_func_b/libwasmtime-platform.a new file mode 100644 index 00000000..beebf570 Binary files /dev/null and b/user/wasmtime_func_b/libwasmtime-platform.a differ diff --git a/user/wasmtime_func_b/libwasmtime-platform.o b/user/wasmtime_func_b/libwasmtime-platform.o new file mode 100644 index 00000000..90bbf6dd Binary files /dev/null and b/user/wasmtime_func_b/libwasmtime-platform.o differ diff --git a/user/wasmtime_func_b/src/lib.rs b/user/wasmtime_func_b/src/lib.rs new file mode 100644 index 00000000..fd2abb4e --- /dev/null +++ b/user/wasmtime_func_b/src/lib.rs @@ -0,0 +1,76 @@ +#![no_std] + +extern crate alloc; +use core::mem::forget; + +use alloc::{string::{String, ToString}, vec::Vec}; +use spin::Mutex; + +use ms_hostcall::types::{OpenFlags, OpenMode}; +use ms_std::{agent::FaaSFuncResult as Result, args, println, libos::libos, time::{SystemTime, UNIX_EPOCH}}; + + +use wasmtime_wasi_api::{wasmtime, LibosCtx}; +use wasmtime::Store; + +static CWASM: &[u8] = include_bytes!("../mapper.cwasm"); + +static INIT_LOCK: Mutex<()> = Mutex::new(()); + +lazy_static::lazy_static! { + static ref MUST_OPEN_ROOT: bool = { + libos!(open("/", OpenFlags::empty(), OpenMode::RD)).unwrap(); + true + }; +} + +fn func_body(my_id: &str, reducer_num: u64) -> Result<()> { + #[cfg(feature = "log")] + + println!("rust: my_id: {:?}, reducer_num: {:?}", my_id, reducer_num); + + let wasi_args: Vec = Vec::from([ + "fake system path!".to_string(), + my_id.to_string(), + reducer_num.to_string(), + ]); + wasmtime_wasi_api::set_wasi_args(my_id, wasi_args); + + let _open_root = *MUST_OPEN_ROOT; + + let lock = INIT_LOCK.lock(); + let (engine, module, linker) = wasmtime_wasi_api::build_wasm(CWASM); + drop(lock); + + let mut store = Store::new(&engine, LibosCtx{id: my_id.to_string()}); + let instance = linker.instantiate(&mut store, &module)?; + + let mut memory = instance.get_memory(&mut store, "memory").unwrap(); + let pages = memory.grow(&mut store, 20000).unwrap(); + println!("rust: pages: {}", pages); + + let main = instance + .get_typed_func::<(), ()>(&mut store, "_start") + .map_err(|e| e.to_string())?; + + let start_time = SystemTime::now().duration_since(UNIX_EPOCH).as_millis(); + println!("start_time: {:?}", start_time); + main.call(store, ()).map_err(|e| e.to_string())?; + + #[cfg(feature = "log")] + println!("rust: wasmtime_mapper_{:?} finished!", my_id); + let end_time = SystemTime::now().duration_since(UNIX_EPOCH).as_millis(); + println!("end_time: {:?}", end_time); + Ok(().into()) +} + +#[no_mangle] +pub fn main() -> Result<()> { + let my_id = args::get("id").unwrap(); + let reducer_num: u64 = args::get("reducer_num") + .expect("missing arg reducer_num") + .parse() + .unwrap_or_else(|_| panic!("bad arg, reducer_num={}", args::get("reducer_num").unwrap())); + + func_body(my_id, reducer_num) +} diff --git a/user/wasmtime_hello/Cargo.lock b/user/wasmtime_hello/Cargo.lock new file mode 100644 index 00000000..96f71e97 --- /dev/null +++ b/user/wasmtime_hello/Cargo.lock @@ -0,0 +1,1169 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + +[[package]] +name = "arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cc" +version = "1.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "812acba72f0a070b003d3697490d2b55b837230ae7c6c6497f05cc2ddbb8d938" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cobs" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "cranelift-bforest" +version = "0.108.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29daf137addc15da6bab6eae2c4a11e274b1d270bf2759508e62f6145e863ef6" +dependencies = [ + "cranelift-entity", +] + +[[package]] +name = "cranelift-codegen" +version = "0.108.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de619867d5de4c644b7fd9904d6e3295269c93d8a71013df796ab338681222d4" +dependencies = [ + "bumpalo", + "cranelift-bforest", + "cranelift-codegen-meta", + "cranelift-codegen-shared", + "cranelift-control", + "cranelift-entity", + "cranelift-isle", + "gimli", + "hashbrown 0.14.5", + "log", + "regalloc2", + "rustc-hash", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.108.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29f5cf277490037d8dae9513d35e0ee8134670ae4a964a5ed5b198d4249d7c10" +dependencies = [ + "cranelift-codegen-shared", +] + +[[package]] +name = "cranelift-codegen-shared" +version = "0.108.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3e22ecad1123343a3c09ac6ecc532bb5c184b6fcb7888df0ea953727f79924" + +[[package]] +name = "cranelift-control" +version = "0.108.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53ca3ec6d30bce84ccf59c81fead4d16381a3ef0ef75e8403bc1e7385980da09" +dependencies = [ + "arbitrary", +] + +[[package]] +name = "cranelift-entity" +version = "0.108.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eabb8d36b0ca8906bec93c78ea516741cac2d7e6b266fa7b0ffddcc09004990" +dependencies = [ + "serde", + "serde_derive", +] + +[[package]] +name = "cranelift-frontend" +version = "0.108.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44b42630229e49a8cfcae90bdc43c8c4c08f7a7aa4618b67f79265cd2f996dd2" +dependencies = [ + "cranelift-codegen", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-isle" +version = "0.108.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "918d1e36361805dfe0b6cdfd5a5ffdb5d03fa796170c5717d2727cbe623b93a0" + +[[package]] +name = "cranelift-native" +version = "0.108.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75aea85a0d7e1800b14ce9d3f53adf8ad4d1ee8a9e23b0269bdc50285e93b9b3" +dependencies = [ + "cranelift-codegen", + "libc", + "target-lexicon", +] + +[[package]] +name = "cranelift-wasm" +version = "0.108.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dac491fd3473944781f0cf9528c90cc899d18ad438da21961a839a3a44d57dfb" +dependencies = [ + "cranelift-codegen", + "cranelift-entity", + "cranelift-frontend", + "itertools", + "log", + "smallvec", + "wasmparser", + "wasmtime-types", +] + +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "derive_more" +version = "0.99.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn 1.0.109", +] + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[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.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[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 = "hash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" +dependencies = [ + "byteorder", +] + +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" +dependencies = [ + "ahash", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", +] + +[[package]] +name = "hashbrown" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" + +[[package]] +name = "heapless" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" +dependencies = [ + "hash32", + "stable_deref_trait", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + +[[package]] +name = "indexmap" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +dependencies = [ + "equivalent", + "hashbrown 0.15.0", + "serde", +] + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "leb128" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" + +[[package]] +name = "libc" +version = "0.2.159" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "linked_list_allocator" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286" +dependencies = [ + "spinning_top", +] + +[[package]] +name = "linux-raw-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1ad52afd8f9448cbbe722ae722849cc41f1d365e285cca386896352bc08e1a9" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mach2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" +dependencies = [ + "libc", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "memfd" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" +dependencies = [ + "rustix", +] + +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "ms_hostcall" +version = "0.1.0" +dependencies = [ + "bitflags", + "derive_more", + "thiserror-no-std", +] + +[[package]] +name = "ms_std" +version = "0.1.0" +dependencies = [ + "cfg-if", + "heapless", + "linked_list_allocator", + "ms_hostcall", + "ms_std_proc_macro", + "spin", + "thiserror-no-std", +] + +[[package]] +name = "ms_std_proc_macro" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "naked-function" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b8d5fca6ab1e6215b010aefd3b9ac5aae369dae0faea3a7f34f296cc9f719ac" +dependencies = [ + "cfg-if", + "naked-function-macro", +] + +[[package]] +name = "naked-function-macro" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b4123e70df5fe0bb370cff166ae453b9c5324a2cfc932c0f7e55498147a0475" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "object" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8dd6c0cdf9429bce006e1362bfce61fa1bfd8c898a643ed8d2b471934701d3d" +dependencies = [ + "crc32fast", + "hashbrown 0.14.5", + "indexmap", + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1" +dependencies = [ + "portable-atomic", +] + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "portable-atomic" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" + +[[package]] +name = "postcard" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f7f0a8d620d71c457dd1d47df76bb18960378da56af4527aaa10f515eee732e" +dependencies = [ + "cobs", + "embedded-io 0.4.0", + "embedded-io 0.6.1", + "serde", +] + +[[package]] +name = "proc-macro2" +version = "1.0.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "psm" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa37f80ca58604976033fae9515a8a2989fc13797d953f7c04fb8fa36a11f205" +dependencies = [ + "cc", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[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 = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys 0.4.14", + "windows-sys", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "sc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "010e18bd3bfd1d45a7e666b236c78720df0d9a7698ebaa9c1c559961eb60a38b" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" + +[[package]] +name = "serde" +version = "1.0.193" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.193" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "serde_json" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0652c533506ad7a2e353cce269330d6afd8bdfb6d75e0ace5b35aacbd7b9e9" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "sjlj" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9b43efc387069aabdc27124a294337c7032a3cb62df0108d2578eff7f08e39" +dependencies = [ + "linux-raw-sys 0.2.2", + "naked-function", + "sc", +] + +[[package]] +name = "slice-group-by" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +dependencies = [ + "serde", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spinning_top" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b9eb1a2f4c41445a3a0ff9abc5221c5fcd28e1f13cd7c0397706f9ac938ddb0" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "target-lexicon" +version = "0.12.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" + +[[package]] +name = "thiserror" +version = "1.0.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e3de26b0965292219b4287ff031fcba86837900fe9cd2b34ea8ad893c0953d2" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "268026685b2be38d7103e9e507c938a1fcb3d7e6eb15e87870b617bf37b6d581" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "thiserror-impl-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58e6318948b519ba6dc2b442a6d0b904ebfb8d411a3ad3e07843615a72249758" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "thiserror-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3ad459d94dd517257cc96add8a43190ee620011bb6e6cdc82dafd97dfafafea" +dependencies = [ + "thiserror-impl-no-std", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasm-encoder" +version = "0.207.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d996306fb3aeaee0d9157adbe2f670df0236caf19f6728b221e92d0f27b3fe17" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasmparser" +version = "0.207.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e19bb9f8ab07616da582ef8adb24c54f1424c7ec876720b7da9db8ec0626c92c" +dependencies = [ + "ahash", + "bitflags", + "hashbrown 0.14.5", + "indexmap", + "semver", +] + +[[package]] +name = "wasmprinter" +version = "0.207.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c2d8a7b4dabb460208e6b4334d9db5766e84505038b2529e69c3d07ac619115" +dependencies = [ + "anyhow", + "wasmparser", +] + +[[package]] +name = "wasmtime" +version = "21.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2db63de4669214120414ae6d86afb6bb011748bf942836aba2d45f011972b" +dependencies = [ + "anyhow", + "bumpalo", + "cc", + "cfg-if", + "encoding_rs", + "hashbrown 0.14.5", + "indexmap", + "libc", + "libm", + "log", + "mach2", + "memfd", + "memoffset", + "object", + "once_cell", + "paste", + "postcard", + "psm", + "rustix", + "semver", + "serde", + "serde_derive", + "smallvec", + "sptr", + "target-lexicon", + "wasmparser", + "wasmtime-asm-macros", + "wasmtime-component-macro", + "wasmtime-component-util", + "wasmtime-cranelift", + "wasmtime-environ", + "wasmtime-jit-icache-coherence", + "wasmtime-slab", + "wasmtime-versioned-export-macros", + "wasmtime-winch", + "windows-sys", +] + +[[package]] +name = "wasmtime-asm-macros" +version = "21.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "821f87828a6508995bf1243fda9dafd1b671a49b3bf998394c7b73f0f5d9eb5f" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "wasmtime-component-macro" +version = "21.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aab7a588beec0116e99488768395eee70a1dc53869aae111d006f8928a16ed46" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn 2.0.39", + "wasmtime-component-util", + "wasmtime-wit-bindgen", + "wit-parser", +] + +[[package]] +name = "wasmtime-component-util" +version = "21.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52cc81977f24da3071f3f4b32f40ef6d8fb4f14e12f0bc4c68163935d6694ded" + +[[package]] +name = "wasmtime-cranelift" +version = "21.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e45cc4915c2b37b4d8b49aaab29d6e2612b393eabb01ae3a410d95e372c22d13" +dependencies = [ + "anyhow", + "cfg-if", + "cranelift-codegen", + "cranelift-control", + "cranelift-entity", + "cranelift-frontend", + "cranelift-native", + "cranelift-wasm", + "gimli", + "log", + "object", + "target-lexicon", + "thiserror", + "wasmparser", + "wasmtime-environ", + "wasmtime-versioned-export-macros", +] + +[[package]] +name = "wasmtime-environ" +version = "21.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bba5317f774e37197d588deadb794289438866b72bc1531c593506a004d6cfe0" +dependencies = [ + "anyhow", + "cranelift-entity", + "gimli", + "indexmap", + "log", + "object", + "postcard", + "serde", + "serde_derive", + "target-lexicon", + "wasm-encoder", + "wasmparser", + "wasmprinter", + "wasmtime-component-util", + "wasmtime-types", +] + +[[package]] +name = "wasmtime-jit-icache-coherence" +version = "21.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6ce46bf24b027e1ede83d14ed544c736d7e939a849c4429551eb27842356c77" +dependencies = [ + "anyhow", + "cfg-if", + "libc", + "windows-sys", +] + +[[package]] +name = "wasmtime-slab" +version = "21.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90814f57c64afa02324829c3a8f88616ce3a75f1b2ce9728d34827d21329a836" + +[[package]] +name = "wasmtime-types" +version = "21.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f2fa462bfea3220711c84e2b549f147e4df89eeb49b8a2a3d89148f6cc4a8b1" +dependencies = [ + "cranelift-entity", + "serde", + "serde_derive", + "smallvec", + "wasmparser", +] + +[[package]] +name = "wasmtime-versioned-export-macros" +version = "21.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89b3438cb56868e235825c7026e85fe8a6c4b5437b5786ad010948e5c6eff0d4" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "wasmtime-winch" +version = "21.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd04ad4f7bbcf7925455cec6420481b972071284e611e105cc16b847fc6415e8" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "object", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", + "winch-codegen", +] + +[[package]] +name = "wasmtime-wit-bindgen" +version = "21.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50c5e4fc265a4d78c334b9fcd846ffd94859bf821ee34a77bc68035526d455ee" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "wit-parser", +] + +[[package]] +name = "wasmtime_hello" +version = "0.1.0" +dependencies = [ + "ms_hostcall", + "ms_std", + "sjlj", + "wasmtime", +] + +[[package]] +name = "winch-codegen" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48691637c874363258ea7295497afdcfd426e5608fa36f62ab6bd0b9cac2bcb8" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "regalloc2", + "smallvec", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +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", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "wit-parser" +version = "0.207.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c83dab33a9618d86cfe3563cc864deffd08c17efc5db31a3b7cd1edeffe6e1" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] diff --git a/user/wasmtime_hello/Cargo.toml b/user/wasmtime_hello/Cargo.toml new file mode 100644 index 00000000..0cf9fce0 --- /dev/null +++ b/user/wasmtime_hello/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "wasmtime_hello" +version = "0.1.0" +edition = "2021" +build = "../../build_user.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +crate-type = ["staticlib"] + +[dependencies] +ms_std = { path = "../../ms_std", features = ["panic_def", "alloc_def"] } +ms_hostcall = { path = "../../ms_hostcall", features = ["signal"] } +sjlj = { version="0.1.3" } +wasmtime = { version = "=21.0.0", default-features = false, features = [ + "runtime", + "gc", + "component-model", +] } + +[features] +mpk = ["ms_std/mpk"] + +default = [] diff --git a/user/wasmtime_hello/add.cwasm b/user/wasmtime_hello/add.cwasm new file mode 100644 index 00000000..d85ec6b2 Binary files /dev/null and b/user/wasmtime_hello/add.cwasm differ diff --git a/user/wasmtime_hello/add.wasm b/user/wasmtime_hello/add.wasm new file mode 100644 index 00000000..92e34327 Binary files /dev/null and b/user/wasmtime_hello/add.wasm differ diff --git a/user/wasmtime_hello/build.rs b/user/wasmtime_hello/build.rs new file mode 100644 index 00000000..9fc09ddf --- /dev/null +++ b/user/wasmtime_hello/build.rs @@ -0,0 +1,4 @@ +fn main() { + println!("cargo:rustc-link-lib=static={}", "wasmtime-platform"); + println!("cargo:rustc-link-search=native={}", "./"); +} diff --git a/user/wasmtime_hello/command.sh b/user/wasmtime_hello/command.sh new file mode 100755 index 00000000..1bb1dcc7 --- /dev/null +++ b/user/wasmtime_hello/command.sh @@ -0,0 +1,49 @@ +cargo build --target x86_64-unknown-none --release && cc \ + -Wl,--gc-sections -nostdlib \ + -Wl,--whole-archive \ + target/x86_64-unknown-none/release/libwasmtime_mapper.a \ + -Wl,--no-whole-archive \ + -shared \ + -o target/x86_64-unknown-none/release/libwasmtime_mapper.so + +cargo run -- --files ./isol_config/wasmtime_wordcount.json + +ln -s /home/wyj/alloy_stack/mslibos/user/wasmtime_mapper/target/x86_64-unknown-none/debug/libwasmtime_mapper.so target/debug/libwasmtime_mapper.so +ln -s /home/wyj/alloy_stack/mslibos/user/wasmtime_mapper/target/x86_64-unknown-none/release/libwasmtime_mapper.so target/release/libwasmtime_mapper.so + +wasmtime compile --target x86_64-unknown-none -W threads=n,tail-call=n mapper.wasm + + + + +cargo build --target x86_64-unknown-none --release && cc \ + -Wl,--gc-sections -nostdlib \ + -Wl,--whole-archive \ + target/x86_64-unknown-none/release/libwasmtime_reducer.a \ + -Wl,--no-whole-archive \ + -shared \ + -o target/x86_64-unknown-none/release/libwasmtime_reducer.so + +cargo run -- --files ./isol_config/wasmtime_wordcount.json + +ln -s /home/wyj/alloy_stack/mslibos/user/wasmtime_reducer/target/x86_64-unknown-none/debug/libwasmtime_reducer.so target/debug/libwasmtime_reducer.so +ln -s /home/wyj/alloy_stack/mslibos/user/wasmtime_reducer/target/x86_64-unknown-none/release/libwasmtime_reducer.so target/release/libwasmtime_reducer.so + +wasmtime compile --target x86_64-unknown-none -W threads=n,tail-call=n reducer.wasm + + + + +cargo build --target x86_64-unknown-none && cc \ + -Wl,--gc-sections -nostdlib \ + -Wl,--whole-archive \ + target/x86_64-unknown-none/debug/libwasmtime_func.a \ + -Wl,--no-whole-archive \ + -shared \ + -o target/x86_64-unknown-none/debug/libwasmtime_func.so + +cargo run -- --files ./isol_config/wasmtime_longchain.json + +ln -s /home/wyj/alloy_stack/mslibos/user/wasmtime_longchain/target/x86_64-unknown-none/debug/libwasmtime_func.so target/debug/libwasmtime_func.so + +wasmtime compile --target x86_64-unknown-none -W threads=n func.wasm diff --git a/user/wasmtime_hello/libwasmtime-platform.a b/user/wasmtime_hello/libwasmtime-platform.a new file mode 100644 index 00000000..3bbde28c Binary files /dev/null and b/user/wasmtime_hello/libwasmtime-platform.a differ diff --git a/user/wasmtime_hello/libwasmtime-platform.o b/user/wasmtime_hello/libwasmtime-platform.o new file mode 100644 index 00000000..98c72200 Binary files /dev/null and b/user/wasmtime_hello/libwasmtime-platform.o differ diff --git a/user/wasmtime_hello/src/capis.rs b/user/wasmtime_hello/src/capis.rs new file mode 100644 index 00000000..19d39f3b --- /dev/null +++ b/user/wasmtime_hello/src/capis.rs @@ -0,0 +1,332 @@ +#![allow(non_camel_case_types)] + +extern crate sjlj; +use core::ptr::{null, null_mut}; + +use ms_hostcall::{mm::{MMResult, ProtFlags}, signal::{SigAction, SigInfo, Sigset, Ucontext}}; +use ms_std::libos::libos; +use ms_std::println; +use sjlj::{JumpBuf, longjmp, setjmp}; + +// Flags to either `wasmtime_mmap_{new,remap}` or `wasmtime_mprotect`. + +/// Indicates that the memory region should be readable. +pub const WASMTIME_PROT_READ: u32 = 1 << 0; +/// Indicates that the memory region should be writable. +pub const WASMTIME_PROT_WRITE: u32 = 1 << 1; +/// Indicates that the memory region should be executable. +pub const WASMTIME_PROT_EXEC: u32 = 1 << 2; + +pub use WASMTIME_PROT_EXEC as PROT_EXEC; +pub use WASMTIME_PROT_READ as PROT_READ; +pub use WASMTIME_PROT_WRITE as PROT_WRITE; + +/// 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. +pub type wasmtime_trap_handler_t = + extern "C" fn(ip: usize, fp: usize, has_faulting_addr: bool, faulting_addr: usize); + +extern "C" fn null_trap_handler( + _ip: usize, + _fp: usize, + _has_faulting_addr: bool, + _faulting_addr: usize, +) { + // no-op +} + +static mut g_handler: wasmtime_trap_handler_t = null_trap_handler; +/// Abstract pointer type used in the `wasmtime_memory_image_*` APIs which +/// is defined by the embedder. +pub enum wasmtime_memory_image {} + +pub static mut WASMTIME_TLS: *mut u8 = 0 as *mut u8; + +/// 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 fn wasmtime_mmap_new(size: usize, prot_flags: u32, ret: &mut *mut u8) -> i32 { + let prot_flags: ProtFlags = ProtFlags::from_bits(prot_flags).unwrap(); + let addr: MMResult = libos!(mmap(0, size, prot_flags, u32::MAX)); + if let Err(e) = addr { + println!("[wasmtime] mmap_new failed: {:?}", e); + return -1; + } + *ret = addr.unwrap() as *mut u8; + 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: u32) -> i32 { + let prot_flags: ProtFlags = ProtFlags::from_bits(prot_flags).unwrap(); + let addr: MMResult = libos!(mmap(addr as usize, size, prot_flags, addr as u32)); + if let Err(e) = addr { + println!("[wasmtime] mmap_remap failed: {:?}", e); + return -1; + } + 0 +} + +/// 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 umap_data: &mut [u8] = unsafe { core::slice::from_raw_parts_mut(ptr, size) }; + if let Err(e) = libos!(munmap(umap_data, false)) { + println!("[wasmtime] munmap failed: {:?}", e); + return -1; + } + 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: u32) -> i32 { + let prot_flags: ProtFlags = ProtFlags::from_bits(prot_flags).unwrap(); + if let Err(e) = libos!(mprotect(ptr as usize, size, prot_flags)) { + println!("[wasmtime] mprotect failed: {:?}", e); + return -1; + } + 0 +} + +/// Returns the page size, in bytes, of the current system. +#[no_mangle] +pub extern "C" fn wasmtime_page_size() -> usize { + 4096 +} + +/// 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 { + unsafe { + let mut buf = JumpBuf::new(); + if setjmp(&mut buf) != 0 { + return 0; + } + *jmp_buf = &buf as *const JumpBuf as *const u8; + } + 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 as *const JumpBuf), 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. +/// + +const SA_SIGINFO: u32 = 0x00000008; +const SA_NODEFER: u32 = 0x40000000; +const SIGILL: i32 = 4; +const SIGSEGV: i32 = 11; +const SIGFPE: i32 = 8; + +/// Returns 0 on success and an error code on failure. +fn handle_signal(sig: i32, info: *mut SigInfo, ctx: *mut Ucontext) { + unsafe { + if g_handler == null_trap_handler { + return; + } + let ip = (*ctx).uc_mcontext.gregs[16]; + let fp = (*ctx).uc_mcontext.gregs[10]; + let has_faulting_addr = sig == SIGSEGV; + let mut faulting_addr = 0; + if has_faulting_addr { + faulting_addr = (*info).siginfo.sifields.sigsys.call_addr as usize; + } + println!("handle_signal: sig: {}, ip: {}, fp: {}, has_faulting_addr: {}, faulting_addr: {}", sig, ip, fp, has_faulting_addr, faulting_addr); + g_handler(ip, fp, has_faulting_addr, faulting_addr); + } + // signal(signo, SIG_DFL); + println!("handle_signal: sig: {}, should signal", sig); +} + + +#[no_mangle] +pub extern "C" fn wasmtime_init_traps(handler: wasmtime_trap_handler_t) -> i32 { + unsafe { + g_handler = handler; + let action = SigAction { + sa_handler: handle_signal as usize, + sa_flags: (SA_NODEFER | SA_SIGINFO) as usize, + sa_mask: Sigset { sig: [0; 1] }, + }; + let rc = libos!(sigaction(SIGILL, &action, null())); + if rc != 0 { + return rc; + } + } + 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 successed 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 { + *ret = 0 as *mut wasmtime_memory_image; + 0 +} + +/// 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 { + 0 +} + +/// 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) { + // no-op +} + +/// 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 { WASMTIME_TLS } +} + +/// 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 { + WASMTIME_TLS = ptr; + } +} diff --git a/user/wasmtime_hello/src/lib.rs b/user/wasmtime_hello/src/lib.rs new file mode 100644 index 00000000..184e90b6 --- /dev/null +++ b/user/wasmtime_hello/src/lib.rs @@ -0,0 +1,47 @@ +#![no_std] + +use alloc::{string::ToString, vec::Vec}; +use ms_std::{agent::FaaSFuncResult as Result, args, println}; +use wasmtime::{component::Func, Engine, Extern, Instance, Linker, Module, Store}; +use wasmtime::{AsContext, Caller}; +mod capis; +extern crate alloc; + +static CWASM: &[u8] = include_bytes!("../add.cwasm"); + +#[no_mangle] +pub fn main() -> Result<()> { + let id = args::get("id").unwrap(); + println!("wasmtiem hello, world! id: {}", id); + + let engine = Engine::default(); + let module = unsafe { Module::deserialize(&engine, CWASM) }.map_err(|e| e.to_string())?; + + let mut linker = Linker::new(&engine); + linker + .func_wrap( + "wasi1", + "fdclose", + |mut caller: Caller<'_, ()>, a: i32, b: i64| -> (i64, i32) { + let memory = caller.get_export("memory").unwrap().into_memory().unwrap(); + let mut buf = [0; 64]; + memory.read(caller, 100, &mut buf); + println!("{:?}", buf); + (b + 1, a + 1) + }, + ) + .unwrap(); + + let mut store = Store::new(&engine, ()); + + let instance = linker.instantiate(&mut store, &module)?; + + let func = instance + .get_typed_func::<(i32, i32), i32>(&mut store, "add") + .map_err(|e| e.to_string())?; + + let ret = func.call(store, (1, 2)).map_err(|e| e.to_string())?; + println!("wasmtime ret: {}", ret); + + Ok(().into()) +} diff --git a/user/wasmtime_hello/ta b/user/wasmtime_hello/ta new file mode 120000 index 00000000..04591154 --- /dev/null +++ b/user/wasmtime_hello/ta @@ -0,0 +1 @@ +/home/dyx/workplace/mslibos/user/wasmtime_write/target/x86_64-unknown-none/debug/libwasmtime_write.so \ No newline at end of file diff --git a/user/wasmtime_hello/wasmtime-platform.c b/user/wasmtime_hello/wasmtime-platform.c new file mode 100644 index 00000000..e7e2124f --- /dev/null +++ b/user/wasmtime_hello/wasmtime-platform.c @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "wasmtime-platform.h" + + +static wasmtime_trap_handler_t g_handler = NULL; + +static void handle_signal(int signo, siginfo_t *info, void *context) +{ + assert(g_handler != NULL); + uintptr_t ip, fp; +#if defined(__aarch64__) + ucontext_t *cx = context; + ip = cx->uc_mcontext.pc; + fp = cx->uc_mcontext.regs[29]; +#elif defined(__x86_64__) + ucontext_t *cx = context; + ip = cx->uc_mcontext.gregs[REG_RIP]; + fp = cx->uc_mcontext.gregs[REG_RBP]; +#else +#error "Unsupported platform" +#endif + + bool has_faulting_addr = signo == SIGSEGV; + uintptr_t faulting_addr = 0; + if (has_faulting_addr) + faulting_addr = (uintptr_t)info->si_addr; + g_handler(ip, fp, has_faulting_addr, faulting_addr); + + // If wasmtime didn't handle this trap then reset the handler to the default + // behavior which will probably abort the process. + signal(signo, SIG_DFL); +} + +int wasmtime_init_traps(wasmtime_trap_handler_t handler) +{ + int rc; + g_handler = handler; + + struct sigaction action; + memset(&action, 0, sizeof(action)); + + action.sa_sigaction = handle_signal; + action.sa_flags = SA_SIGINFO | SA_NODEFER; + sigemptyset(&action.sa_mask); + + rc = sigaction(SIGILL, &action, NULL); + if (rc != 0) + return errno; + rc = sigaction(SIGSEGV, &action, NULL); + if (rc != 0) + return errno; + rc = sigaction(SIGFPE, &action, NULL); + if (rc != 0) + return errno; + return 0; +} \ No newline at end of file diff --git a/user/wasmtime_hello/wasmtime-platform.h b/user/wasmtime_hello/wasmtime-platform.h new file mode 100644 index 00000000..72472fcf --- /dev/null +++ b/user/wasmtime_hello/wasmtime-platform.h @@ -0,0 +1,259 @@ +// Platform support for Wasmtime's `no_std` build. +// +// This header file is what Wasmtime will rely on when it does not otherwise +// have support for the native platform. This can happen with `no_std` binaries +// for example where the traditional Unix-or-Windows implementation is not +// suitable. +// +// Embedders are expected to implement the symbols defined in this header file. +// These symbols can be defined either in C/C++ or in Rust (using +// `#[no_mangle]`). +// +// Some more information about this header can additionally be found at +// . + + +#ifndef _WASMTIME_PLATFORM_H +#define _WASMTIME_PLATFORM_H + +/* Generated with cbindgen:0.27.0 */ + +#include +#include +#include +#include + +/** + * Indicates that the memory region should be readable. + */ +#define WASMTIME_PROT_READ (1 << 0) + +/** + * Indicates that the memory region should be writable. + */ +#define WASMTIME_PROT_WRITE (1 << 1) + +/** + * Indicates that the memory region should be executable. + */ +#define WASMTIME_PROT_EXEC (1 << 2) + +/** + * Abstract pointer type used in the `wasmtime_memory_image_*` APIs which + * is defined by the embedder. + */ +typedef struct wasmtime_memory_image wasmtime_memory_image; + +/** + * 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. + */ +typedef void (*wasmtime_trap_handler_t)(uintptr_t ip, + uintptr_t fp, + bool has_faulting_addr, + uintptr_t faulting_addr); + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +/** + * 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. + */ +extern int32_t wasmtime_mmap_new(uintptr_t size, uint32_t prot_flags, uint8_t **ret); + +/** + * 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. + */ +extern int32_t wasmtime_mmap_remap(uint8_t *addr, uintptr_t size, uint32_t prot_flags); + +/** + * 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. + */ +extern int32_t wasmtime_munmap(uint8_t *ptr, uintptr_t size); + +/** + * 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. + */ +extern int32_t wasmtime_mprotect(uint8_t *ptr, uintptr_t size, uint32_t prot_flags); + +/** + * Returns the page size, in bytes, of the current system. + */ +extern uintptr_t wasmtime_page_size(void); + +/** + * 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. + */ +extern int32_t wasmtime_setjmp(const uint8_t **jmp_buf, + void (*callback)(uint8_t*, uint8_t*), + uint8_t *payload, + uint8_t *callee); + +/** + * 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`. + */ +extern void wasmtime_longjmp(const uint8_t *jmp_buf); + +/** + * 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. + */ +extern int32_t wasmtime_init_traps(wasmtime_trap_handler_t handler); + +/** + * Attempts to create a new in-memory image of the `ptr`/`len` combo which + * can be mapped to virtual addresses in the future. + * + * On successed 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. + */ +extern int32_t wasmtime_memory_image_new(const uint8_t *ptr, + uintptr_t len, + struct wasmtime_memory_image **ret); + +/** + * 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. + */ +extern int32_t wasmtime_memory_image_map_at(struct wasmtime_memory_image *image, + uint8_t *addr, + uintptr_t len); + +/** + * 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. + */ +extern void wasmtime_memory_image_free(struct wasmtime_memory_image *image); + +/** + * 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`. + */ +extern uint8_t *wasmtime_tls_get(void); + +/** + * Sets the current TLS value for Wasmtime to the provided value. + * + * This value should be returned when later calling `wasmtime_tls_get`. + */ +extern void wasmtime_tls_set(uint8_t *ptr); + +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus + +#endif /* _WASMTIME_PLATFORM_H */ diff --git a/user/wasmtime_longchain/Cargo.lock b/user/wasmtime_longchain/Cargo.lock new file mode 100644 index 00000000..78d79910 --- /dev/null +++ b/user/wasmtime_longchain/Cargo.lock @@ -0,0 +1,1196 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + +[[package]] +name = "arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cc" +version = "1.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cobs" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "cranelift-bforest" +version = "0.109.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fad7096c10a285583f2ed620c0c85d7baf745922e33415290f2900b73319f1e0" +dependencies = [ + "cranelift-entity", +] + +[[package]] +name = "cranelift-codegen" +version = "0.109.1" +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", + "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", +] + +[[package]] +name = "cranelift-codegen-shared" +version = "0.109.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "315a326e9f63b996f55e93b73a9a239b55f2de1211fcfbcc99d9423f44dc6ded" + +[[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-entity" +version = "0.109.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9778487136bf37f9007920d9cb332a020e5d7259c1fbf35e625368eb88c7bfe" +dependencies = [ + "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", + "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-native" +version = "0.109.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91c24c076002cb6a926a3f7220040278c7178878cd9142a418ddef9ee5b84963" +dependencies = [ + "cranelift-codegen", + "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", + "cranelift-entity", + "cranelift-frontend", + "itertools", + "log", + "smallvec", + "wasmparser", + "wasmtime-types", +] + +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn 2.0.79", +] + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[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.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + +[[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 = "hash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" +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.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +dependencies = [ + "foldhash", +] + +[[package]] +name = "heapless" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" +dependencies = [ + "hash32", + "stable_deref_trait", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + +[[package]] +name = "indexmap" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +dependencies = [ + "equivalent", + "hashbrown 0.15.0", + "serde", +] + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + +[[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.159" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "linked_list_allocator" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286" +dependencies = [ + "spinning_top", +] + +[[package]] +name = "linux-raw-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1ad52afd8f9448cbbe722ae722849cc41f1d365e285cca386896352bc08e1a9" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mach2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" +dependencies = [ + "libc", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "memfd" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" +dependencies = [ + "rustix", +] + +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "ms_hostcall" +version = "0.1.0" +dependencies = [ + "bitflags", + "derive_more", + "thiserror-no-std", +] + +[[package]] +name = "ms_std" +version = "0.1.0" +dependencies = [ + "cfg-if", + "heapless", + "linked_list_allocator", + "ms_hostcall", + "ms_std_proc_macro", + "spin", + "thiserror-no-std", +] + +[[package]] +name = "ms_std_proc_macro" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "naked-function" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b8d5fca6ab1e6215b010aefd3b9ac5aae369dae0faea3a7f34f296cc9f719ac" +dependencies = [ + "cfg-if", + "naked-function-macro", +] + +[[package]] +name = "naked-function-macro" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b4123e70df5fe0bb370cff166ae453b9c5324a2cfc932c0f7e55498147a0475" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "object" +version = "0.36.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" +dependencies = [ + "crc32fast", + "hashbrown 0.15.0", + "indexmap", + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "postcard" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f7f0a8d620d71c457dd1d47df76bb18960378da56af4527aaa10f515eee732e" +dependencies = [ + "cobs", + "embedded-io 0.4.0", + "embedded-io 0.6.1", + "serde", +] + +[[package]] +name = "proc-macro2" +version = "1.0.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "psm" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa37f80ca58604976033fae9515a8a2989fc13797d953f7c04fb8fa36a11f205" +dependencies = [ + "cc", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[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 = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys 0.4.14", + "windows-sys", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "sc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "010e18bd3bfd1d45a7e666b236c78720df0d9a7698ebaa9c1c559961eb60a38b" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "sjlj" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9b43efc387069aabdc27124a294337c7032a3cb62df0108d2578eff7f08e39" +dependencies = [ + "linux-raw-sys 0.2.2", + "naked-function", + "sc", +] + +[[package]] +name = "slice-group-by" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +dependencies = [ + "serde", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spinning_top" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b9eb1a2f4c41445a3a0ff9abc5221c5fcd28e1f13cd7c0397706f9ac938ddb0" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "target-lexicon" +version = "0.12.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" + +[[package]] +name = "thiserror" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "thiserror-impl-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58e6318948b519ba6dc2b442a6d0b904ebfb8d411a3ad3e07843615a72249758" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "thiserror-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3ad459d94dd517257cc96add8a43190ee620011bb6e6cdc82dafd97dfafafea" +dependencies = [ + "thiserror-impl-no-std", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasm-encoder" +version = "0.209.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4a05336882dae732ce6bd48b7e11fe597293cb72c13da4f35d7d5f8d53b2a7" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasmparser" +version = "0.209.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07035cc9a9b41e62d3bb3a3815a66ab87c993c06fe1cf6b2a3f2a18499d937db" +dependencies = [ + "ahash", + "bitflags", + "hashbrown 0.14.5", + "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", +] + +[[package]] +name = "wasmtime" +version = "22.0.0" +source = "git+https://gitee.com/tju-cloud-computing/wasmtime-as-lib?branch=master#fb45fb8dde6d068abb3ae78bfab78253c9654af5" +dependencies = [ + "anyhow", + "bumpalo", + "cc", + "cfg-if", + "encoding_rs", + "hashbrown 0.14.5", + "indexmap", + "libc", + "libm", + "log", + "mach2", + "memfd", + "memoffset", + "object", + "once_cell", + "paste", + "postcard", + "psm", + "rustix", + "semver", + "serde", + "serde_derive", + "smallvec", + "sptr", + "target-lexicon", + "wasmparser", + "wasmtime-asm-macros", + "wasmtime-component-macro", + "wasmtime-component-util", + "wasmtime-cranelift", + "wasmtime-environ", + "wasmtime-jit-icache-coherence", + "wasmtime-slab", + "wasmtime-versioned-export-macros", + "wasmtime-winch", + "windows-sys", +] + +[[package]] +name = "wasmtime-asm-macros" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d697d99c341d4a9ffb72f3af7a02124d233eeb59aee010f36d88e97cca553d5e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "wasmtime-component-macro" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b29b462b068e73b5b27fae092a27f47e5937cabf6b26be2779c978698a52feca" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn 2.0.79", + "wasmtime-component-util", + "wasmtime-wit-bindgen", + "wit-parser", +] + +[[package]] +name = "wasmtime-component-util" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d2912c53d9054984b380dfbd7579f9c3681b2a73b903a56bd71a1c4f175f1e" + +[[package]] +name = "wasmtime-cranelift" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3975deafea000457ba84355c7c0fce0372937204f77026510b7b454f28a3a65" +dependencies = [ + "anyhow", + "cfg-if", + "cranelift-codegen", + "cranelift-control", + "cranelift-entity", + "cranelift-frontend", + "cranelift-native", + "cranelift-wasm", + "gimli", + "log", + "object", + "target-lexicon", + "thiserror", + "wasmparser", + "wasmtime-environ", + "wasmtime-versioned-export-macros", +] + +[[package]] +name = "wasmtime-environ" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f444e900e848b884d8a8a2949b6f5b92af642a3e663ff8fbe78731143a55be61" +dependencies = [ + "anyhow", + "cranelift-entity", + "gimli", + "indexmap", + "log", + "object", + "postcard", + "serde", + "serde_derive", + "target-lexicon", + "wasm-encoder", + "wasmparser", + "wasmprinter", + "wasmtime-component-util", + "wasmtime-types", +] + +[[package]] +name = "wasmtime-jit-icache-coherence" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5afe2f0499542f9a4bcfa1b55bfdda803b6ade4e7c93c6b99e0f39dba44b0a91" +dependencies = [ + "anyhow", + "cfg-if", + "libc", + "windows-sys", +] + +[[package]] +name = "wasmtime-slab" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a7de1f2bec5bbb35d532e61c85c049dc84ae671df60492f90b954ecf21169e7" + +[[package]] +name = "wasmtime-types" +version = "22.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2017ea47e7a91440f94cc29f5f41d303e80f979a5384bf560d4b0afdabe32d0" +dependencies = [ + "cranelift-entity", + "serde", + "serde_derive", + "smallvec", + "wasmparser", +] + +[[package]] +name = "wasmtime-versioned-export-macros" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de5a9bc4f44ceeb168e9e8e3be4e0b4beb9095b468479663a9e24c667e36826f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "wasmtime-winch" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed4db238a0241df2d15f79ad17b3a37a27f2ea6cb885894d81b42ae107544466" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "object", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", + "winch-codegen", +] + +[[package]] +name = "wasmtime-wit-bindgen" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc077306b38288262e5ba01d4b21532a6987416cdc0aedf04bb06c22a68fdc" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "wit-parser", +] + +[[package]] +name = "wasmtime_func" +version = "0.1.0" +dependencies = [ + "lazy_static", + "ms_hostcall", + "ms_std", + "ms_std_proc_macro", + "spin", + "wasmtime_wasi_api", +] + +[[package]] +name = "wasmtime_wasi_api" +version = "0.1.0" +dependencies = [ + "hashbrown 0.14.5", + "lazy_static", + "ms_hostcall", + "ms_std", + "ms_std_proc_macro", + "sjlj", + "spin", + "wasmtime", +] + +[[package]] +name = "winch-codegen" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85c6915884e731b2db0d8cf08cb64474cb69221a161675fd3c135f91febc3daa" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "regalloc2", + "smallvec", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +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", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[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", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] diff --git a/user/wasmtime_longchain/Cargo.toml b/user/wasmtime_longchain/Cargo.toml new file mode 100644 index 00000000..f02927ca --- /dev/null +++ b/user/wasmtime_longchain/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "wasmtime_func" +version = "0.1.0" +edition = "2021" +build = "build.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +crate-type = ["staticlib"] + +[dependencies] +ms_std = { path = "../../ms_std", features = ["panic_def", "alloc_def"] } +ms_hostcall = { path = "../../ms_hostcall" } +ms_std_proc_macro = { path = "../../ms_std_proc_macro" } +wasmtime_wasi_api = { path = "../../wasmtime_wasi_api" } + +lazy_static = { version = "1.5.0", features = ["spin_no_std"] } +spin = "0.9.8" + +[features] +mpk = ["ms_std/mpk"] diff --git a/user/wasmtime_longchain/build.rs b/user/wasmtime_longchain/build.rs new file mode 100644 index 00000000..9fc09ddf --- /dev/null +++ b/user/wasmtime_longchain/build.rs @@ -0,0 +1,4 @@ +fn main() { + println!("cargo:rustc-link-lib=static={}", "wasmtime-platform"); + println!("cargo:rustc-link-search=native={}", "./"); +} diff --git a/user/wasmtime_longchain/build.sh b/user/wasmtime_longchain/build.sh new file mode 100755 index 00000000..2d7121ce --- /dev/null +++ b/user/wasmtime_longchain/build.sh @@ -0,0 +1,26 @@ +$CC func.c -o func.wasm -fno-exceptions -fno-rtti -ffast-math -funroll-loops -fomit-frame-pointer -Ofast +# $CC func.c -o func.wasm +wasmtime compile --target x86_64-unknown-none -W threads=n,tail-call=n func.wasm + +cargo build --target x86_64-unknown-none --release && cc \ + -Wl,--gc-sections -nostdlib \ + -Wl,--whole-archive \ + target/x86_64-unknown-none/release/libwasmtime_func.a \ + -Wl,--no-whole-archive \ + -shared \ + -o target/x86_64-unknown-none/release/libwasmtime_func.so + + +ln -s /home/wyj/alloy_stack/mslibos/user/wasmtime_longchain/target/x86_64-unknown-none/release/libwasmtime_func.so /home/wyj/alloy_stack/mslibos/target/release/libwasmtime_func.so + + + +# cargo build --target x86_64-unknown-none && cc \ +# -Wl,--gc-sections -nostdlib \ +# -Wl,--whole-archive \ +# target/x86_64-unknown-none/debug/libwasmtime_func.a \ +# -Wl,--no-whole-archive \ +# -shared \ +# -o target/x86_64-unknown-none/debug/libwasmtime_func.so + +# ln -s /home/wyj/alloy_stack/mslibos/user/wasmtime_func/target/x86_64-unknown-none/debug/libwasmtime_func.so /home/wyj/alloy_stack/mslibos/target/debug/libwasmtime_func.so diff --git a/user/wasmtime_longchain/func.c b/user/wasmtime_longchain/func.c new file mode 100644 index 00000000..ba5d5f12 --- /dev/null +++ b/user/wasmtime_longchain/func.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +__attribute__((import_module("env"), import_name("buffer_register"))) void buffer_register(void *slot_name, int name_size, void *buffer, int buffer_size); +__attribute__((import_module("env"), import_name("access_buffer"))) void access_buffer(void *slot_name, int name_size, void *buffer, int buffer_size); + +int main(int argc, char* argv[]) { + int id = atoi(argv[1]); + int func_num = atoi(argv[2]); + printf("func.c recieve: id: %d, func_num: %d\n", id, func_num); + + char slot_name[20] = "buffer"; + int bufferSize = 1024 * 1024 * 256; + char *buffer = (char *)malloc(bufferSize * sizeof(char)); + if (func_num == 0) { + // sprintf(slot_name, "buffer_%d_%d", func_num, id); + memset(buffer, 0, bufferSize * sizeof(char)); + buffer_register(slot_name, strlen(slot_name), buffer, bufferSize); + } else if (func_num == 14) { + access_buffer(slot_name, strlen(slot_name), buffer, bufferSize); + } + else { + // sprintf(slot_name, "buffer_%d_%d", func_num-1, id); + access_buffer(slot_name, strlen(slot_name), buffer, bufferSize); + // sprintf(slot_name, "buffer_%d_%d", func_num, id); + // buffer[0] += 1; + buffer_register(slot_name, strlen(slot_name), buffer, bufferSize); + } + free(buffer); + printf("func_%d finished!\n", func_num); + return 0; +} \ No newline at end of file diff --git a/user/wasmtime_longchain/func.cwasm b/user/wasmtime_longchain/func.cwasm new file mode 100644 index 00000000..a53d7c9c Binary files /dev/null and b/user/wasmtime_longchain/func.cwasm differ diff --git a/user/wasmtime_longchain/func.wasm b/user/wasmtime_longchain/func.wasm new file mode 100755 index 00000000..5dde85eb Binary files /dev/null and b/user/wasmtime_longchain/func.wasm differ diff --git a/user/wasmtime_longchain/libwasmtime-platform.a b/user/wasmtime_longchain/libwasmtime-platform.a new file mode 100644 index 00000000..beebf570 Binary files /dev/null and b/user/wasmtime_longchain/libwasmtime-platform.a differ diff --git a/user/wasmtime_longchain/libwasmtime-platform.o b/user/wasmtime_longchain/libwasmtime-platform.o new file mode 100644 index 00000000..90bbf6dd Binary files /dev/null and b/user/wasmtime_longchain/libwasmtime-platform.o differ diff --git a/user/wasmtime_longchain/src/lib.rs b/user/wasmtime_longchain/src/lib.rs new file mode 100644 index 00000000..5b4d06d4 --- /dev/null +++ b/user/wasmtime_longchain/src/lib.rs @@ -0,0 +1,95 @@ +#![no_std] + +extern crate alloc; +use core::mem::forget; + +use alloc::{string::{String, ToString}, vec::Vec, borrow::ToOwned}; +use spin::Mutex; + +use ms_hostcall::types::{OpenFlags, OpenMode}; +use ms_std::{agent::{DataBuffer, FaaSFuncResult as Result}, args, println, libos::libos, time::{SystemTime, UNIX_EPOCH}}; +use ms_std_proc_macro::FaasData; + +use wasmtime_wasi_api::{wasmtime, LibosCtx}; +use wasmtime::Store; + +static CWASM: &[u8] = include_bytes!("../func.cwasm"); + +static INIT_LOCK: Mutex<()> = Mutex::new(()); + +#[allow(dead_code)] +#[derive(FaasData)] +pub struct MyData { + pub current_time: SystemTime, +} +impl Default for MyData { + fn default() -> Self { + Self { + current_time: SystemTime::now(), + } + } +} + +lazy_static::lazy_static! { + static ref MUST_OPEN_ROOT: bool = { + libos!(open("/", OpenFlags::empty(), OpenMode::RD)).unwrap(); + true + }; +} + +fn func_body(my_id: &str, func_num: u64) -> Result<()> { + // #[cfg(feature = "log")] + println!("rust: my_id: {:?}, func_num: {:?}", my_id, func_num); + + let wasi_args: Vec = Vec::from([ + "fake system path!".to_string(), + my_id.to_string(), + func_num.to_string(), + ]); + wasmtime_wasi_api::set_wasi_args(my_id, wasi_args); + + let _open_root = *MUST_OPEN_ROOT; + + let lock = INIT_LOCK.lock(); + let (engine, module, linker) = wasmtime_wasi_api::build_wasm(CWASM); + drop(lock); + + let mut store = Store::new(&engine, LibosCtx{id: my_id.to_string()}); + let instance = linker.instantiate(&mut store, &module)?; + + let main = instance + .get_typed_func::<(), ()>(&mut store, "_start") + .map_err(|e| e.to_string())?; + + // main.call(store, ()).map_err(|e| e.to_string())?; + main.call(&mut store, ()).map_err(|e| e.to_string())?; + forget(store); + + if func_num == 14 { + let data = DataBuffer::::from_buffer_slot("Conference".to_owned()); + if let Some(buffer) = data { + let dur = buffer.current_time.elapsed(); + println!("end to end latency: {:?}", dur); + } else { + Err("buffer is none")? + } + } + Ok(().into()) +} + +#[no_mangle] +pub fn main() -> Result<()> { + let my_id = args::get("id").unwrap(); + let func_num: u64 = args::get("func_num") + .expect("missing arg func_num") + .parse() + .unwrap_or_else(|_| panic!("bad arg, func_num={}", args::get("func_num").unwrap())); + if func_num == 0 { + let mut d = DataBuffer::::with_slot("Conference".to_owned()); + d.current_time = SystemTime::now(); + // let start_time = SystemTime::now().duration_since(UNIX_EPOCH).as_millis(); + // println!("start_time: {:?}", start_time); + } + + func_body(my_id, func_num) +} diff --git a/user/wasmtime_mapper/Cargo.lock b/user/wasmtime_mapper/Cargo.lock new file mode 100644 index 00000000..cab80106 --- /dev/null +++ b/user/wasmtime_mapper/Cargo.lock @@ -0,0 +1,1195 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + +[[package]] +name = "arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cc" +version = "1.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cobs" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "cranelift-bforest" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6b33d7e757a887989eb18b35712b2a67d96171ec3149d1bfb657b29b7b367c" +dependencies = [ + "cranelift-entity", +] + +[[package]] +name = "cranelift-codegen" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9acf15cb22be42d07c3b57d7856329cb228b7315d385346149df2566ad5e4aa" +dependencies = [ + "bumpalo", + "cranelift-bforest", + "cranelift-codegen-meta", + "cranelift-codegen-shared", + "cranelift-control", + "cranelift-entity", + "cranelift-isle", + "gimli", + "hashbrown 0.14.5", + "log", + "regalloc2", + "rustc-hash", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e934d301392b73b3f8b0540391fb82465a0f179a3cee7c726482ac4727efcc97" +dependencies = [ + "cranelift-codegen-shared", +] + +[[package]] +name = "cranelift-codegen-shared" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb2a2566b3d54b854dfb288b3b187f6d3d17d6f762c92898207eba302931da" + +[[package]] +name = "cranelift-control" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0100f33b704cdacd01ad66ff41f8c5030d57cbff078e2a4e49ab1822591299fa" +dependencies = [ + "arbitrary", +] + +[[package]] +name = "cranelift-entity" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8cfdc315e5d18997093e040a8d234bea1ac1e118a716d3e30f40d449e78207b" +dependencies = [ + "serde", + "serde_derive", +] + +[[package]] +name = "cranelift-frontend" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f74b84f16af2e982b0c0c72233503d9d55cbfe3865dbe807ca28dc6642a28b5" +dependencies = [ + "cranelift-codegen", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-isle" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adf306d3dde705fb94bd48082f01d38c4ededc74293a4c007805f610bf08bc6e" + +[[package]] +name = "cranelift-native" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ea0ebdef7aff4a79bcbc8b6495f31315f16b3bf311152f472eaa8d679352581" +dependencies = [ + "cranelift-codegen", + "libc", + "target-lexicon", +] + +[[package]] +name = "cranelift-wasm" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d549108a1942065cdbac3bb96c2952afa0e1b9a3beff4b08c4308ac72257576d" +dependencies = [ + "cranelift-codegen", + "cranelift-entity", + "cranelift-frontend", + "itertools", + "log", + "smallvec", + "wasmparser", + "wasmtime-types", +] + +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn 2.0.79", +] + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[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.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + +[[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 = "hash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" +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.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +dependencies = [ + "foldhash", +] + +[[package]] +name = "heapless" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" +dependencies = [ + "hash32", + "stable_deref_trait", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + +[[package]] +name = "indexmap" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +dependencies = [ + "equivalent", + "hashbrown 0.15.0", + "serde", +] + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + +[[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.159" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "linked_list_allocator" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286" +dependencies = [ + "spinning_top", +] + +[[package]] +name = "linux-raw-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1ad52afd8f9448cbbe722ae722849cc41f1d365e285cca386896352bc08e1a9" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mach2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" +dependencies = [ + "libc", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "memfd" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" +dependencies = [ + "rustix", +] + +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "ms_hostcall" +version = "0.1.0" +dependencies = [ + "bitflags", + "derive_more", + "thiserror-no-std", +] + +[[package]] +name = "ms_std" +version = "0.1.0" +dependencies = [ + "cfg-if", + "heapless", + "linked_list_allocator", + "ms_hostcall", + "ms_std_proc_macro", + "spin", + "thiserror-no-std", +] + +[[package]] +name = "ms_std_proc_macro" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "naked-function" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b8d5fca6ab1e6215b010aefd3b9ac5aae369dae0faea3a7f34f296cc9f719ac" +dependencies = [ + "cfg-if", + "naked-function-macro", +] + +[[package]] +name = "naked-function-macro" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b4123e70df5fe0bb370cff166ae453b9c5324a2cfc932c0f7e55498147a0475" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "object" +version = "0.36.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" +dependencies = [ + "crc32fast", + "hashbrown 0.15.0", + "indexmap", + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "postcard" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f7f0a8d620d71c457dd1d47df76bb18960378da56af4527aaa10f515eee732e" +dependencies = [ + "cobs", + "embedded-io 0.4.0", + "embedded-io 0.6.1", + "serde", +] + +[[package]] +name = "proc-macro2" +version = "1.0.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "psm" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa37f80ca58604976033fae9515a8a2989fc13797d953f7c04fb8fa36a11f205" +dependencies = [ + "cc", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[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 = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys 0.4.14", + "windows-sys", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "sc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "010e18bd3bfd1d45a7e666b236c78720df0d9a7698ebaa9c1c559961eb60a38b" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "sjlj" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9b43efc387069aabdc27124a294337c7032a3cb62df0108d2578eff7f08e39" +dependencies = [ + "linux-raw-sys 0.2.2", + "naked-function", + "sc", +] + +[[package]] +name = "slice-group-by" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +dependencies = [ + "serde", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spinning_top" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b9eb1a2f4c41445a3a0ff9abc5221c5fcd28e1f13cd7c0397706f9ac938ddb0" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "target-lexicon" +version = "0.12.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" + +[[package]] +name = "thiserror" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "thiserror-impl-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58e6318948b519ba6dc2b442a6d0b904ebfb8d411a3ad3e07843615a72249758" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "thiserror-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3ad459d94dd517257cc96add8a43190ee620011bb6e6cdc82dafd97dfafafea" +dependencies = [ + "thiserror-impl-no-std", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasm-encoder" +version = "0.209.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4a05336882dae732ce6bd48b7e11fe597293cb72c13da4f35d7d5f8d53b2a7" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasmparser" +version = "0.209.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07035cc9a9b41e62d3bb3a3815a66ab87c993c06fe1cf6b2a3f2a18499d937db" +dependencies = [ + "ahash", + "bitflags", + "hashbrown 0.14.5", + "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", +] + +[[package]] +name = "wasmtime" +version = "22.0.0" +source = "git+https://gitee.com/tju-cloud-computing/wasmtime-as-lib?branch=master#fb45fb8dde6d068abb3ae78bfab78253c9654af5" +dependencies = [ + "anyhow", + "bumpalo", + "cc", + "cfg-if", + "encoding_rs", + "hashbrown 0.14.5", + "indexmap", + "libc", + "libm", + "log", + "mach2", + "memfd", + "memoffset", + "object", + "once_cell", + "paste", + "postcard", + "psm", + "rustix", + "semver", + "serde", + "serde_derive", + "smallvec", + "sptr", + "target-lexicon", + "wasmparser", + "wasmtime-asm-macros", + "wasmtime-component-macro", + "wasmtime-component-util", + "wasmtime-cranelift", + "wasmtime-environ", + "wasmtime-jit-icache-coherence", + "wasmtime-slab", + "wasmtime-versioned-export-macros", + "wasmtime-winch", + "windows-sys", +] + +[[package]] +name = "wasmtime-asm-macros" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d697d99c341d4a9ffb72f3af7a02124d233eeb59aee010f36d88e97cca553d5e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "wasmtime-component-macro" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b29b462b068e73b5b27fae092a27f47e5937cabf6b26be2779c978698a52feca" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn 2.0.79", + "wasmtime-component-util", + "wasmtime-wit-bindgen", + "wit-parser", +] + +[[package]] +name = "wasmtime-component-util" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d2912c53d9054984b380dfbd7579f9c3681b2a73b903a56bd71a1c4f175f1e" + +[[package]] +name = "wasmtime-cranelift" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3975deafea000457ba84355c7c0fce0372937204f77026510b7b454f28a3a65" +dependencies = [ + "anyhow", + "cfg-if", + "cranelift-codegen", + "cranelift-control", + "cranelift-entity", + "cranelift-frontend", + "cranelift-native", + "cranelift-wasm", + "gimli", + "log", + "object", + "target-lexicon", + "thiserror", + "wasmparser", + "wasmtime-environ", + "wasmtime-versioned-export-macros", +] + +[[package]] +name = "wasmtime-environ" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f444e900e848b884d8a8a2949b6f5b92af642a3e663ff8fbe78731143a55be61" +dependencies = [ + "anyhow", + "cranelift-entity", + "gimli", + "indexmap", + "log", + "object", + "postcard", + "serde", + "serde_derive", + "target-lexicon", + "wasm-encoder", + "wasmparser", + "wasmprinter", + "wasmtime-component-util", + "wasmtime-types", +] + +[[package]] +name = "wasmtime-jit-icache-coherence" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5afe2f0499542f9a4bcfa1b55bfdda803b6ade4e7c93c6b99e0f39dba44b0a91" +dependencies = [ + "anyhow", + "cfg-if", + "libc", + "windows-sys", +] + +[[package]] +name = "wasmtime-slab" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a7de1f2bec5bbb35d532e61c85c049dc84ae671df60492f90b954ecf21169e7" + +[[package]] +name = "wasmtime-types" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "412463e9000e14cf6856be48628d2213c20c153e29ffc22b036980c892ea6964" +dependencies = [ + "cranelift-entity", + "serde", + "serde_derive", + "smallvec", + "wasmparser", +] + +[[package]] +name = "wasmtime-versioned-export-macros" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de5a9bc4f44ceeb168e9e8e3be4e0b4beb9095b468479663a9e24c667e36826f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "wasmtime-winch" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed4db238a0241df2d15f79ad17b3a37a27f2ea6cb885894d81b42ae107544466" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "object", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", + "winch-codegen", +] + +[[package]] +name = "wasmtime-wit-bindgen" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc077306b38288262e5ba01d4b21532a6987416cdc0aedf04bb06c22a68fdc" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "wit-parser", +] + +[[package]] +name = "wasmtime_mapper" +version = "0.1.0" +dependencies = [ + "lazy_static", + "ms_hostcall", + "ms_std", + "spin", + "wasmtime_wasi_api", +] + +[[package]] +name = "wasmtime_wasi_api" +version = "0.1.0" +dependencies = [ + "hashbrown 0.14.5", + "lazy_static", + "ms_hostcall", + "ms_std", + "ms_std_proc_macro", + "sjlj", + "spin", + "wasmtime", +] + +[[package]] +name = "winch-codegen" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85c6915884e731b2db0d8cf08cb64474cb69221a161675fd3c135f91febc3daa" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "regalloc2", + "smallvec", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +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", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[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", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] diff --git a/user/wasmtime_mapper/Cargo.toml b/user/wasmtime_mapper/Cargo.toml new file mode 100644 index 00000000..16069c69 --- /dev/null +++ b/user/wasmtime_mapper/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "wasmtime_mapper" +version = "0.1.0" +edition = "2021" +build = "build.rs" +# build = "../../build_wasm.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +crate-type = ["staticlib"] + +[dependencies] +ms_std = { path = "../../ms_std", features = ["panic_def", "alloc_def"] } +# ms_hostcall = { path = "../../ms_hostcall", features = ["signal"] } +ms_hostcall = { path = "../../ms_hostcall"} + +wasmtime_wasi_api = { path = "../../wasmtime_wasi_api" } + +lazy_static = { version = "1.5.0", features = ["spin_no_std"] } +spin = "0.9.8" + +[features] +mpk = ["ms_std/mpk"] diff --git a/user/wasmtime_mapper/build.rs b/user/wasmtime_mapper/build.rs new file mode 100644 index 00000000..9fc09ddf --- /dev/null +++ b/user/wasmtime_mapper/build.rs @@ -0,0 +1,4 @@ +fn main() { + println!("cargo:rustc-link-lib=static={}", "wasmtime-platform"); + println!("cargo:rustc-link-search=native={}", "./"); +} diff --git a/user/wasmtime_mapper/build.sh b/user/wasmtime_mapper/build.sh new file mode 100755 index 00000000..683fb8d7 --- /dev/null +++ b/user/wasmtime_mapper/build.sh @@ -0,0 +1,24 @@ +$CPP mapper_new.cpp -o mapper.wasm -fno-exceptions -fno-rtti -ffast-math -funroll-loops -fomit-frame-pointer -Ofast +# $CC mapper.c -o mapper.wasm -O3 + +wasmtime compile --target x86_64-unknown-none -W threads=n,tail-call=n mapper.wasm + +cargo build --target x86_64-unknown-none --release && cc \ + -Wl,--gc-sections -nostdlib \ + -Wl,--whole-archive \ + target/x86_64-unknown-none/release/libwasmtime_mapper.a \ + -Wl,--no-whole-archive \ + -shared \ + -o target/x86_64-unknown-none/release/libwasmtime_mapper.so + +ln -s /home/wyj/alloy_stack/mslibos/user/wasmtime_mapper/target/x86_64-unknown-none/release/libwasmtime_mapper.so /home/wyj/alloy_stack/mslibos/target/release/libwasmtime_mapper.so + +# cargo build --target x86_64-unknown-none && cc \ +# -Wl,--gc-sections -nostdlib \ +# -Wl,--whole-archive \ +# target/x86_64-unknown-none/debug/libwasmtime_mapper.a \ +# -Wl,--no-whole-archive \ +# -shared \ +# -o target/x86_64-unknown-none/debug/libwasmtime_mapper.so + +# ln -s /home/wyj/alloy_stack/mslibos/user/wasmtime_mapper/target/x86_64-unknown-none/debug/libwasmtime_mapper.so /home/wyj/alloy_stack/mslibos/target/debug/libwasmtime_mapper.so diff --git a/user/wasmtime_mapper/libwasmtime-platform.a b/user/wasmtime_mapper/libwasmtime-platform.a new file mode 100644 index 00000000..beebf570 Binary files /dev/null and b/user/wasmtime_mapper/libwasmtime-platform.a differ diff --git a/user/wasmtime_mapper/libwasmtime-platform.o b/user/wasmtime_mapper/libwasmtime-platform.o new file mode 100644 index 00000000..90bbf6dd Binary files /dev/null and b/user/wasmtime_mapper/libwasmtime-platform.o differ diff --git a/user/wasmtime_mapper/mapper b/user/wasmtime_mapper/mapper new file mode 100755 index 00000000..d50be828 Binary files /dev/null and b/user/wasmtime_mapper/mapper differ diff --git a/user/wasmtime_mapper/mapper.c b/user/wasmtime_mapper/mapper.c new file mode 100644 index 00000000..0a4fca59 --- /dev/null +++ b/user/wasmtime_mapper/mapper.c @@ -0,0 +1,166 @@ +#include +#include +#include +#include +#include +#include + +__attribute__((import_module("env"), import_name("buffer_register"))) void buffer_register(void *slot_name, int name_size, void *buffer, int buffer_size); + +#define MAX_WORD_LENGTH 50 +#define MAX_WORDS 18000000 +#define MAX_SLOT_NUM 5 +#define MAX_BUFFER_SIZE 500000 + +int count[MAX_WORDS]; +char *words[MAX_WORDS]; + +void to_lowercase(char *str) { + for (int i = 0; str[i]; i++) { + str[i] = tolower(str[i]); + } +} + +char nc(FILE *stream) { + static char buf[1<<27], *p1 = buf, *p2 = buf; + return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 27, stream), p1 == p2) ? EOF : *p1 ++; +} + +char* readfile(FILE *stream) { + int cnt = 0; + char *buffer = (char *)malloc(MAX_WORD_LENGTH * sizeof(char)); + while (buffer[cnt] = nc(stream)) { + if (buffer[cnt] == ' ' || buffer[cnt] == '\n' || buffer[cnt] == EOF) { + buffer[cnt] = 0; + break; + } + cnt++; + } + return cnt > 0 ? buffer : 0; +} + +void get_now() { + struct timeval tv; + gettimeofday(&tv, NULL); + printf("%lld.%lld\n", tv.tv_sec, tv.tv_usec); +} + +int main(int argc, char* argv[]) { + int id = atoi(argv[1]); + int reducer_num = atoi(argv[2]); + printf("mapper.c recieve: id: %d, reducer_num: %d\n", id, reducer_num); + + char input_file[30]; + sprintf(input_file, "fake_data_%d.txt", id); + FILE *file = fopen(input_file, "r"); + if (!file) { + perror("Failed to open input file\n"); + exit(EXIT_FAILURE); + } + + printf("mapper_%d input file: %s\n", id, input_file); + + char* word; + int word_index = 0; + // int test_num = 0; + get_now(); + while(word = readfile(file)) { + to_lowercase(word); + int found = 0; + + for (int i = 0; i < word_index; i++) { + if (strcmp(words[i], word) == 0) { + count[i]++; + found = 1; + break; + } + + } + + if (!found) { + words[word_index] = strdup(word); + count[word_index]++; + word_index++; + } + + } + get_now(); + + fclose(file); + // return 0; + printf("mapper_%d_index: %d\n", id, word_index); + + + char **slot_name = (char **)malloc(MAX_SLOT_NUM * sizeof(char*)); + for (int i = 0; i < MAX_SLOT_NUM; i++) { + slot_name[i] = (char *)malloc(20 * sizeof(char)); + } + // char *slot_name[MAX_SLOT_NUM]; + char **buffer = (char **)malloc(MAX_SLOT_NUM * sizeof(char*)); + for (int i = 0; i < MAX_SLOT_NUM; i++) { + buffer[i] = (char *)malloc(MAX_BUFFER_SIZE * sizeof(char)); + } + // char *buffer[MAX_SLOT_NUM]; + char slot[20]; + int bufferSize = MAX_BUFFER_SIZE; + int slot_index = 0; + + char *ptr[MAX_SLOT_NUM]; + for (int i = 0; i < reducer_num; i++) { + ptr[i] = buffer[i]; + } + + for (int i = 0; i < word_index; i++) { + int partition_index = i % reducer_num; + sprintf(slot, "buffer_%d_%d", partition_index, id); + int found = 0; + for (int j = 0; j < slot_index; j++) { + if (strcmp(slot_name[j], slot) == 0) { + found = 1; + // sprintf(buffer[j] + total_len[j], "%s: %d\n", words[i], count[i]); + char temp[100]; + snprintf(temp, sizeof(temp), "%s: %d\n", words[i], count[i]); + strncpy(ptr[j], temp, strlen(temp)); + ptr[j] += strlen(temp); + break; + } + } + + if (!found) { + slot_name[slot_index] = strdup(slot); + // buffer[slot_index] = (char *)malloc(bufferSize * sizeof(char)); + // if (buffer[slot_index] == NULL) { + // printf("alloc mem failed\n"); + // return 1; + // } + memset(buffer[slot_index], 0, bufferSize * sizeof(char)); + char temp[100]; + snprintf(temp, sizeof(temp), "%s: %d\n", words[i], count[i]); + strncpy(ptr[slot_index], temp, strlen(temp)); + ptr[slot_index] += strlen(temp); + // sprintf(buffer[slot_index], "%s: %d\n", words[i], count[i]); + // printf("slot: %s; buffer: %s\n", slot_name[slot_index], buffer[slot_index]); + slot_index++; + } + // printf("found: %d; word: %s; count: %d; slot_name: %s; buffer: %s\n", found, words[i], count[i], slot, buffer[slot_index]); + free(words[i]); + } + + for (int i = 0; i < reducer_num; i++) { + *ptr[i] = '\0'; + } + + // printf("buffer: %s\n", buffer[0]); + + for (int i = 0; i < slot_index; i++) { + buffer_register(slot_name[i], strlen(slot_name[i]), buffer[i], bufferSize); + } + + for (int i = 0; i < slot_index; i++) { + free(slot_name[i]); // 释放 strdup 分配的内存 + free(buffer[i]); // 释放 buffer + } + // write(1, "mapper end!\n", sizeof("mapper end!\n")); + // printf("mapper_%d finished!\n", id); + return 0; +} \ No newline at end of file diff --git a/user/wasmtime_mapper/mapper.cpp b/user/wasmtime_mapper/mapper.cpp new file mode 100644 index 00000000..c41965d8 --- /dev/null +++ b/user/wasmtime_mapper/mapper.cpp @@ -0,0 +1,109 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +#define MAX_SLOT_NUM 10 +#define MAX_WORDS 20000000 +#define MAX_BUFFER_SIZE 500000 + +string words[MAX_WORDS]; +int counts[MAX_WORDS]; + +__attribute__((import_module("env"), import_name("buffer_register"))) void buffer_register(void *slot_name, int name_size, void *buffer, int buffer_size); + +void get_time() { + timeval tv{}; + gettimeofday(&tv, nullptr); + printf("%lld.%lld\n", tv.tv_sec, tv.tv_usec); +} + +int main(int argc, char* argv[]) { + int id = atoi(argv[1]); + int reducer_num = atoi(argv[2]); + cout << "mapper_" << id << " start!" << endl; + + string input_file = "fake_data_" + to_string(id) + ".txt"; + ifstream file(input_file); + + int word_index = 0; + + string word; + // vector words; + // vector counts; + + + printf("start reading file\n"); + get_time(); + while (file >> word) { + transform(word.begin(), word.end(), word.begin(), + [](unsigned char c) { return std::tolower(c); }); + int found = 0; + for (int i = 0; i < word_index; i++) { + if (words[i] == word) { + counts[i]++; + found = 1; + break; + } + } + if (!found) { + words[word_index] = word; + counts[word_index] = 1; + // words.push_back(word); + // counts.push_back(1); + // words.emplace_back(word); + // count.emplace_back(1); + word_index++; + } + } + printf("finish reading file\n"); + get_time(); + // return 0; + file.close(); + + cout << "mapper_" << id << " read success!" << endl; + + string buffer[MAX_SLOT_NUM]; + string slot_name[MAX_SLOT_NUM]; + int slot_index = 0; + + for (int i = 0; i < word_index; i++) { + int partition_index = i % reducer_num; + string slot = "buffer_" + to_string(partition_index) + "_" + to_string(id); + int found = 0; + for (int j = 0; j < slot_index; j++) { + if (slot_name[j] == slot) { + found = 1; + buffer[j].append(words[i] + ": " + to_string(counts[i]) + "\n"); + break; + } + } + + if (!found) { + slot_name[slot_index] = slot; + buffer[slot_index] = words[i] + ": " + to_string(counts[i]) + "\n"; + slot_index++; + } + } + + for (int i = 0; i < MAX_SLOT_NUM; i++) { + buffer[i].resize(MAX_BUFFER_SIZE, '\0'); + } + + + cout << "mapper_" << id << " solved " << word_index << " words!" << endl; + for (int i = 0; i < slot_index; i++) { + buffer_register((void*)slot_name[i].c_str(), slot_name[i].length(), (void*)buffer[i].c_str(), buffer[i].size()); + // cout << "buffersize" << i << ": " << buffer[i].size() << endl; + } + cout << "mapper_" << id << " write finished!" << endl; + + return 0; +} \ No newline at end of file diff --git a/user/wasmtime_mapper/mapper.cwasm b/user/wasmtime_mapper/mapper.cwasm new file mode 100644 index 00000000..6b32b55b Binary files /dev/null and b/user/wasmtime_mapper/mapper.cwasm differ diff --git a/user/wasmtime_mapper/mapper.wasm b/user/wasmtime_mapper/mapper.wasm new file mode 100755 index 00000000..e75b2748 Binary files /dev/null and b/user/wasmtime_mapper/mapper.wasm differ diff --git a/user/wasmtime_mapper/mapper_new.cpp b/user/wasmtime_mapper/mapper_new.cpp new file mode 100644 index 00000000..227b2ed6 --- /dev/null +++ b/user/wasmtime_mapper/mapper_new.cpp @@ -0,0 +1,156 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +#define MAX_WORD_LENGTH 50 +#define MAX_SLOT_NUM 10 +#define MAX_WORDS 18000000 +#define MAX_BUFFER_SIZE 500000 + +string words[MAX_WORDS]; +int counts[MAX_WORDS]; + +__attribute__((import_module("env"), import_name("buffer_register"))) void buffer_register(void *slot_name, int name_size, void *buffer, int buffer_size); + +void get_time() { + timeval tv{}; + gettimeofday(&tv, nullptr); + printf("%lld.%06lld\n", tv.tv_sec, tv.tv_usec); +} + +long long get_time2() { + timeval tv{}; + gettimeofday(&tv, nullptr); + // printf("%lld.%06lld\n", (long long)tv.tv_sec, tv.tv_usec); + return (long long)tv.tv_sec * 1000000 + tv.tv_usec; +} + +void to_lowercase(std::string& s) { + for (char& c : s) { + c = std::tolower(c); + } +} + +char nc(FILE *stream) { + static char buf[1<<27], *p1 = buf, *p2 = buf; + return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 27, stream), p1 == p2) ? EOF : *p1 ++; +} + +char* readfile(FILE *stream) { + int cnt = 0; + char *buffer = (char *)malloc(MAX_WORD_LENGTH * sizeof(char)); + while (buffer[cnt] = nc(stream)) { + if (buffer[cnt] == ' ' || buffer[cnt] == '\n' || buffer[cnt] == EOF) { + buffer[cnt] = 0; + break; + } + cnt++; + } + return cnt > 0 ? buffer : 0; +} + +int main(int argc, char* argv[]) { + int id = atoi(argv[1]); + int reducer_num = atoi(argv[2]); + cout << "mapper_" << id << " start!" << endl; + + string word; + unordered_map word_map; + + string input_file = "fake_data_" + to_string(id) + ".txt"; + // c 快读 + // FILE *file = fopen(input_file.c_str(), "r"); + // printf("start reading file\n"); + // get_time(); + // while(true) { + // word = readfile(file); + // if (word.empty()) { + // break; // 假设空字符串表示没有更多的单词可以读取 + // } + // to_lowercase(word); + // ++word_map[word]; + // } + // printf("finish reading file\n"); + // get_time(); + + // 一次性读 + printf("start reading file\n"); + get_time(); + ifstream file(input_file); + string content((std::istreambuf_iterator(file)), istreambuf_iterator()); + printf("finish reading file\n"); + get_time(); + printf("start com\n"); + get_time(); + transform(content.begin(), content.end(), content.begin(), + [](unsigned char c) { return std::tolower(c); }); + // 使用 istringstream 分割单词 + istringstream sfile(content); + while (sfile >> word) { + ++word_map[word]; + } + file.close(); + + // 逐个word读 + // printf("start reading file\n"); + // get_time(); + // ifstream file(input_file); + // while (file >> word) { + + // } + // file.close(); + // printf("finish reading file\n"); + // get_time(); + // printf("start com\n"); + // get_time(); + // ifstream file2(input_file); + // while (file2 >> word) { + // transform(word.begin(), word.end(), word.begin(), + // [](unsigned char c) { return std::tolower(c); }); + // ++word_map[word]; + // } + // file2.close(); + + cout << "mapper_" << id << " read success!" << endl; + cout << word_map.size() << endl; + + string buffer[MAX_SLOT_NUM]; + string slot_name[MAX_SLOT_NUM]; + + for (auto& pair : word_map) { + int partition_index = hash{}(pair.first) % reducer_num; + slot_name[partition_index] = "buffer_" + to_string(partition_index) + "_" + to_string(id); + buffer[partition_index].append(pair.first + " " + to_string(pair.second) + "\n"); + } + + for (int i = 0; i < reducer_num; i++) { + buffer[i].resize(MAX_BUFFER_SIZE, '\0'); + } + + int word_index = word_map.size(); + cout << "mapper_" << id << " solved " << word_index << " words!" << endl; + + printf("finish com\n"); + get_time(); + for (int i = 0; i < reducer_num; i++) { + buffer_register((void*)slot_name[i].c_str(), slot_name[i].length(), (void*)buffer[i].c_str(), buffer[i].size()); + // cout << "buffersize" << i << ": " << buffer[i].size() << endl; + } + cout << "mapper_" << id << " write finished!" << endl; + printf("finish data_trans\n"); + get_time(); + return 0; +} \ No newline at end of file diff --git a/user/wasmtime_mapper/mapper_ori.cpp b/user/wasmtime_mapper/mapper_ori.cpp new file mode 100644 index 00000000..0a4fca59 --- /dev/null +++ b/user/wasmtime_mapper/mapper_ori.cpp @@ -0,0 +1,166 @@ +#include +#include +#include +#include +#include +#include + +__attribute__((import_module("env"), import_name("buffer_register"))) void buffer_register(void *slot_name, int name_size, void *buffer, int buffer_size); + +#define MAX_WORD_LENGTH 50 +#define MAX_WORDS 18000000 +#define MAX_SLOT_NUM 5 +#define MAX_BUFFER_SIZE 500000 + +int count[MAX_WORDS]; +char *words[MAX_WORDS]; + +void to_lowercase(char *str) { + for (int i = 0; str[i]; i++) { + str[i] = tolower(str[i]); + } +} + +char nc(FILE *stream) { + static char buf[1<<27], *p1 = buf, *p2 = buf; + return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 27, stream), p1 == p2) ? EOF : *p1 ++; +} + +char* readfile(FILE *stream) { + int cnt = 0; + char *buffer = (char *)malloc(MAX_WORD_LENGTH * sizeof(char)); + while (buffer[cnt] = nc(stream)) { + if (buffer[cnt] == ' ' || buffer[cnt] == '\n' || buffer[cnt] == EOF) { + buffer[cnt] = 0; + break; + } + cnt++; + } + return cnt > 0 ? buffer : 0; +} + +void get_now() { + struct timeval tv; + gettimeofday(&tv, NULL); + printf("%lld.%lld\n", tv.tv_sec, tv.tv_usec); +} + +int main(int argc, char* argv[]) { + int id = atoi(argv[1]); + int reducer_num = atoi(argv[2]); + printf("mapper.c recieve: id: %d, reducer_num: %d\n", id, reducer_num); + + char input_file[30]; + sprintf(input_file, "fake_data_%d.txt", id); + FILE *file = fopen(input_file, "r"); + if (!file) { + perror("Failed to open input file\n"); + exit(EXIT_FAILURE); + } + + printf("mapper_%d input file: %s\n", id, input_file); + + char* word; + int word_index = 0; + // int test_num = 0; + get_now(); + while(word = readfile(file)) { + to_lowercase(word); + int found = 0; + + for (int i = 0; i < word_index; i++) { + if (strcmp(words[i], word) == 0) { + count[i]++; + found = 1; + break; + } + + } + + if (!found) { + words[word_index] = strdup(word); + count[word_index]++; + word_index++; + } + + } + get_now(); + + fclose(file); + // return 0; + printf("mapper_%d_index: %d\n", id, word_index); + + + char **slot_name = (char **)malloc(MAX_SLOT_NUM * sizeof(char*)); + for (int i = 0; i < MAX_SLOT_NUM; i++) { + slot_name[i] = (char *)malloc(20 * sizeof(char)); + } + // char *slot_name[MAX_SLOT_NUM]; + char **buffer = (char **)malloc(MAX_SLOT_NUM * sizeof(char*)); + for (int i = 0; i < MAX_SLOT_NUM; i++) { + buffer[i] = (char *)malloc(MAX_BUFFER_SIZE * sizeof(char)); + } + // char *buffer[MAX_SLOT_NUM]; + char slot[20]; + int bufferSize = MAX_BUFFER_SIZE; + int slot_index = 0; + + char *ptr[MAX_SLOT_NUM]; + for (int i = 0; i < reducer_num; i++) { + ptr[i] = buffer[i]; + } + + for (int i = 0; i < word_index; i++) { + int partition_index = i % reducer_num; + sprintf(slot, "buffer_%d_%d", partition_index, id); + int found = 0; + for (int j = 0; j < slot_index; j++) { + if (strcmp(slot_name[j], slot) == 0) { + found = 1; + // sprintf(buffer[j] + total_len[j], "%s: %d\n", words[i], count[i]); + char temp[100]; + snprintf(temp, sizeof(temp), "%s: %d\n", words[i], count[i]); + strncpy(ptr[j], temp, strlen(temp)); + ptr[j] += strlen(temp); + break; + } + } + + if (!found) { + slot_name[slot_index] = strdup(slot); + // buffer[slot_index] = (char *)malloc(bufferSize * sizeof(char)); + // if (buffer[slot_index] == NULL) { + // printf("alloc mem failed\n"); + // return 1; + // } + memset(buffer[slot_index], 0, bufferSize * sizeof(char)); + char temp[100]; + snprintf(temp, sizeof(temp), "%s: %d\n", words[i], count[i]); + strncpy(ptr[slot_index], temp, strlen(temp)); + ptr[slot_index] += strlen(temp); + // sprintf(buffer[slot_index], "%s: %d\n", words[i], count[i]); + // printf("slot: %s; buffer: %s\n", slot_name[slot_index], buffer[slot_index]); + slot_index++; + } + // printf("found: %d; word: %s; count: %d; slot_name: %s; buffer: %s\n", found, words[i], count[i], slot, buffer[slot_index]); + free(words[i]); + } + + for (int i = 0; i < reducer_num; i++) { + *ptr[i] = '\0'; + } + + // printf("buffer: %s\n", buffer[0]); + + for (int i = 0; i < slot_index; i++) { + buffer_register(slot_name[i], strlen(slot_name[i]), buffer[i], bufferSize); + } + + for (int i = 0; i < slot_index; i++) { + free(slot_name[i]); // 释放 strdup 分配的内存 + free(buffer[i]); // 释放 buffer + } + // write(1, "mapper end!\n", sizeof("mapper end!\n")); + // printf("mapper_%d finished!\n", id); + return 0; +} \ No newline at end of file diff --git a/user/wasmtime_mapper/src/lib.rs b/user/wasmtime_mapper/src/lib.rs new file mode 100644 index 00000000..22121311 --- /dev/null +++ b/user/wasmtime_mapper/src/lib.rs @@ -0,0 +1,84 @@ +#![no_std] + +extern crate alloc; +use core::mem::forget; + +use alloc::{string::{String, ToString}, vec::Vec}; +use spin::Mutex; + +use ms_hostcall::types::{OpenFlags, OpenMode}; +use ms_std::{agent::FaaSFuncResult as Result, args, libos::libos, println, time::{SystemTime, UNIX_EPOCH}}; + + +use wasmtime_wasi_api::{wasmtime, LibosCtx}; +use wasmtime::Store; + +static CWASM: &[u8] = include_bytes!("../mapper.cwasm"); + +static INIT_LOCK: Mutex<()> = Mutex::new(()); + +lazy_static::lazy_static! { + static ref MUST_OPEN_ROOT: bool = { + libos!(open("/", OpenFlags::empty(), OpenMode::RD)).unwrap(); + true + }; +} + +fn func_body(my_id: &str, reducer_num: u64) -> Result<()> { + #[cfg(feature = "log")] + println!("rust: my_id: {:?}, reducer_num: {:?}", my_id, reducer_num); + + let wasi_args: Vec = Vec::from([ + "fake system path!".to_string(), + my_id.to_string(), + reducer_num.to_string(), + ]); + wasmtime_wasi_api::set_wasi_args(my_id, wasi_args); + + let _open_root = *MUST_OPEN_ROOT; + + let lock = INIT_LOCK.lock(); + let (engine, module, linker) = wasmtime_wasi_api::build_wasm(CWASM); + drop(lock); + + let mut store = Store::new(&engine, LibosCtx{id: my_id.to_string()}); + let instance = linker.instantiate(&mut store, &module)?; + + // let memory_grow_start_time = SystemTime::now().duration_since(UNIX_EPOCH).as_millis(); + // println!("memory_grow_start_time: {:?}", memory_grow_start_time); + let mut memory = instance.get_memory(&mut store, "memory").unwrap(); + let pages = memory.grow(&mut store, 20000).unwrap(); + // println!("rust: pages: {}", pages); + + let main = instance + .get_typed_func::<(), ()>(&mut store, "_start") + .map_err(|e| e.to_string())?; + + // let start_time = SystemTime::now().duration_since(UNIX_EPOCH).as_millis(); + // println!("start_time: {:?}", start_time); + // main.call(store, ()).map_err(|e| e.to_string())?; + main.call(&mut store, ()).map_err(|e| e.to_string())?; + forget(store); + + #[cfg(feature = "log")] + println!("rust: wasmtime_mapper_{:?} finished!", my_id); + let end_time = SystemTime::now().duration_since(UNIX_EPOCH).as_millis(); + // println!("end_time: {:?}", end_time); + Ok(().into()) +} + +#[no_mangle] +pub fn main() -> Result<()> { + // let main_start_time = SystemTime::now().duration_since(UNIX_EPOCH).as_millis(); + // println!("main_start_time: {:?}", main_start_time); + let my_id = args::get("id").unwrap(); + let get_id = SystemTime::now().duration_since(UNIX_EPOCH).as_millis(); + // println!("get_id: {:?}", get_id); + let reducer_num: u64 = args::get("reducer_num") + .expect("missing arg reducer_num") + .parse() + .unwrap_or_else(|_| panic!("bad arg, reducer_num={}", args::get("reducer_num").unwrap())); + // let after_get_args = SystemTime::now().duration_since(UNIX_EPOCH).as_millis(); + // println!("after_get_args: {:?}", after_get_args); + func_body(my_id, reducer_num) +} diff --git a/user/wasmtime_merger/Cargo.lock b/user/wasmtime_merger/Cargo.lock new file mode 100644 index 00000000..8fccfc94 --- /dev/null +++ b/user/wasmtime_merger/Cargo.lock @@ -0,0 +1,1194 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + +[[package]] +name = "arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cc" +version = "1.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4cbd4ab9fef358caa9c599eae3105af638ead5fb47a718315d8e03c852b9f0d" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cobs" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "cranelift-bforest" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6b33d7e757a887989eb18b35712b2a67d96171ec3149d1bfb657b29b7b367c" +dependencies = [ + "cranelift-entity", +] + +[[package]] +name = "cranelift-codegen" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9acf15cb22be42d07c3b57d7856329cb228b7315d385346149df2566ad5e4aa" +dependencies = [ + "bumpalo", + "cranelift-bforest", + "cranelift-codegen-meta", + "cranelift-codegen-shared", + "cranelift-control", + "cranelift-entity", + "cranelift-isle", + "gimli", + "hashbrown 0.14.5", + "log", + "regalloc2", + "rustc-hash", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e934d301392b73b3f8b0540391fb82465a0f179a3cee7c726482ac4727efcc97" +dependencies = [ + "cranelift-codegen-shared", +] + +[[package]] +name = "cranelift-codegen-shared" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb2a2566b3d54b854dfb288b3b187f6d3d17d6f762c92898207eba302931da" + +[[package]] +name = "cranelift-control" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0100f33b704cdacd01ad66ff41f8c5030d57cbff078e2a4e49ab1822591299fa" +dependencies = [ + "arbitrary", +] + +[[package]] +name = "cranelift-entity" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8cfdc315e5d18997093e040a8d234bea1ac1e118a716d3e30f40d449e78207b" +dependencies = [ + "serde", + "serde_derive", +] + +[[package]] +name = "cranelift-frontend" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f74b84f16af2e982b0c0c72233503d9d55cbfe3865dbe807ca28dc6642a28b5" +dependencies = [ + "cranelift-codegen", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-isle" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adf306d3dde705fb94bd48082f01d38c4ededc74293a4c007805f610bf08bc6e" + +[[package]] +name = "cranelift-native" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ea0ebdef7aff4a79bcbc8b6495f31315f16b3bf311152f472eaa8d679352581" +dependencies = [ + "cranelift-codegen", + "libc", + "target-lexicon", +] + +[[package]] +name = "cranelift-wasm" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d549108a1942065cdbac3bb96c2952afa0e1b9a3beff4b08c4308ac72257576d" +dependencies = [ + "cranelift-codegen", + "cranelift-entity", + "cranelift-frontend", + "itertools", + "log", + "smallvec", + "wasmparser", + "wasmtime-types", +] + +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "derive_more" +version = "0.99.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn 1.0.109", +] + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[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.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + +[[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 = "hash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" +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.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +dependencies = [ + "foldhash", +] + +[[package]] +name = "heapless" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" +dependencies = [ + "hash32", + "stable_deref_trait", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + +[[package]] +name = "indexmap" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +dependencies = [ + "equivalent", + "hashbrown 0.14.5", + "serde", +] + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + +[[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.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "linked_list_allocator" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286" +dependencies = [ + "spinning_top", +] + +[[package]] +name = "linux-raw-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1ad52afd8f9448cbbe722ae722849cc41f1d365e285cca386896352bc08e1a9" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mach2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" +dependencies = [ + "libc", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "memfd" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" +dependencies = [ + "rustix", +] + +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "ms_hostcall" +version = "0.1.0" +dependencies = [ + "bitflags", + "derive_more", + "thiserror-no-std", +] + +[[package]] +name = "ms_std" +version = "0.1.0" +dependencies = [ + "cfg-if", + "heapless", + "linked_list_allocator", + "ms_hostcall", + "ms_std_proc_macro", + "spin", + "thiserror-no-std", +] + +[[package]] +name = "ms_std_proc_macro" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "naked-function" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b8d5fca6ab1e6215b010aefd3b9ac5aae369dae0faea3a7f34f296cc9f719ac" +dependencies = [ + "cfg-if", + "naked-function-macro", +] + +[[package]] +name = "naked-function-macro" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b4123e70df5fe0bb370cff166ae453b9c5324a2cfc932c0f7e55498147a0475" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "object" +version = "0.36.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" +dependencies = [ + "crc32fast", + "hashbrown 0.15.0", + "indexmap", + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "postcard" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f7f0a8d620d71c457dd1d47df76bb18960378da56af4527aaa10f515eee732e" +dependencies = [ + "cobs", + "embedded-io 0.4.0", + "embedded-io 0.6.1", + "serde", +] + +[[package]] +name = "proc-macro2" +version = "1.0.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "psm" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa37f80ca58604976033fae9515a8a2989fc13797d953f7c04fb8fa36a11f205" +dependencies = [ + "cc", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[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 = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys 0.4.14", + "windows-sys", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "sc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "010e18bd3bfd1d45a7e666b236c78720df0d9a7698ebaa9c1c559961eb60a38b" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" + +[[package]] +name = "serde" +version = "1.0.193" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.193" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "serde_json" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0652c533506ad7a2e353cce269330d6afd8bdfb6d75e0ace5b35aacbd7b9e9" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "sjlj" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9b43efc387069aabdc27124a294337c7032a3cb62df0108d2578eff7f08e39" +dependencies = [ + "linux-raw-sys 0.2.2", + "naked-function", + "sc", +] + +[[package]] +name = "slice-group-by" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +dependencies = [ + "serde", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spinning_top" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b9eb1a2f4c41445a3a0ff9abc5221c5fcd28e1f13cd7c0397706f9ac938ddb0" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "target-lexicon" +version = "0.12.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" + +[[package]] +name = "thiserror" +version = "1.0.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e3de26b0965292219b4287ff031fcba86837900fe9cd2b34ea8ad893c0953d2" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "268026685b2be38d7103e9e507c938a1fcb3d7e6eb15e87870b617bf37b6d581" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "thiserror-impl-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58e6318948b519ba6dc2b442a6d0b904ebfb8d411a3ad3e07843615a72249758" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "thiserror-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3ad459d94dd517257cc96add8a43190ee620011bb6e6cdc82dafd97dfafafea" +dependencies = [ + "thiserror-impl-no-std", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasm-encoder" +version = "0.209.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4a05336882dae732ce6bd48b7e11fe597293cb72c13da4f35d7d5f8d53b2a7" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasmparser" +version = "0.209.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07035cc9a9b41e62d3bb3a3815a66ab87c993c06fe1cf6b2a3f2a18499d937db" +dependencies = [ + "ahash", + "bitflags", + "hashbrown 0.14.5", + "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", +] + +[[package]] +name = "wasmtime" +version = "22.0.0" +source = "git+https://gitee.com/tju-cloud-computing/wasmtime-as-lib?branch=master#fb45fb8dde6d068abb3ae78bfab78253c9654af5" +dependencies = [ + "anyhow", + "bumpalo", + "cc", + "cfg-if", + "encoding_rs", + "hashbrown 0.14.5", + "indexmap", + "libc", + "libm", + "log", + "mach2", + "memfd", + "memoffset", + "object", + "once_cell", + "paste", + "postcard", + "psm", + "rustix", + "semver", + "serde", + "serde_derive", + "smallvec", + "sptr", + "target-lexicon", + "wasmparser", + "wasmtime-asm-macros", + "wasmtime-component-macro", + "wasmtime-component-util", + "wasmtime-cranelift", + "wasmtime-environ", + "wasmtime-jit-icache-coherence", + "wasmtime-slab", + "wasmtime-versioned-export-macros", + "wasmtime-winch", + "windows-sys", +] + +[[package]] +name = "wasmtime-asm-macros" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d697d99c341d4a9ffb72f3af7a02124d233eeb59aee010f36d88e97cca553d5e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "wasmtime-component-macro" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b29b462b068e73b5b27fae092a27f47e5937cabf6b26be2779c978698a52feca" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn 2.0.39", + "wasmtime-component-util", + "wasmtime-wit-bindgen", + "wit-parser", +] + +[[package]] +name = "wasmtime-component-util" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d2912c53d9054984b380dfbd7579f9c3681b2a73b903a56bd71a1c4f175f1e" + +[[package]] +name = "wasmtime-cranelift" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3975deafea000457ba84355c7c0fce0372937204f77026510b7b454f28a3a65" +dependencies = [ + "anyhow", + "cfg-if", + "cranelift-codegen", + "cranelift-control", + "cranelift-entity", + "cranelift-frontend", + "cranelift-native", + "cranelift-wasm", + "gimli", + "log", + "object", + "target-lexicon", + "thiserror", + "wasmparser", + "wasmtime-environ", + "wasmtime-versioned-export-macros", +] + +[[package]] +name = "wasmtime-environ" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f444e900e848b884d8a8a2949b6f5b92af642a3e663ff8fbe78731143a55be61" +dependencies = [ + "anyhow", + "cranelift-entity", + "gimli", + "indexmap", + "log", + "object", + "postcard", + "serde", + "serde_derive", + "target-lexicon", + "wasm-encoder", + "wasmparser", + "wasmprinter", + "wasmtime-component-util", + "wasmtime-types", +] + +[[package]] +name = "wasmtime-jit-icache-coherence" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5afe2f0499542f9a4bcfa1b55bfdda803b6ade4e7c93c6b99e0f39dba44b0a91" +dependencies = [ + "anyhow", + "cfg-if", + "libc", + "windows-sys", +] + +[[package]] +name = "wasmtime-slab" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a7de1f2bec5bbb35d532e61c85c049dc84ae671df60492f90b954ecf21169e7" + +[[package]] +name = "wasmtime-types" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "412463e9000e14cf6856be48628d2213c20c153e29ffc22b036980c892ea6964" +dependencies = [ + "cranelift-entity", + "serde", + "serde_derive", + "smallvec", + "wasmparser", +] + +[[package]] +name = "wasmtime-versioned-export-macros" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de5a9bc4f44ceeb168e9e8e3be4e0b4beb9095b468479663a9e24c667e36826f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "wasmtime-winch" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed4db238a0241df2d15f79ad17b3a37a27f2ea6cb885894d81b42ae107544466" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "object", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", + "winch-codegen", +] + +[[package]] +name = "wasmtime-wit-bindgen" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc077306b38288262e5ba01d4b21532a6987416cdc0aedf04bb06c22a68fdc" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "wit-parser", +] + +[[package]] +name = "wasmtime_merger" +version = "0.1.0" +dependencies = [ + "lazy_static", + "ms_hostcall", + "ms_std", + "spin", + "wasmtime_wasi_api", +] + +[[package]] +name = "wasmtime_wasi_api" +version = "0.1.0" +dependencies = [ + "hashbrown 0.14.5", + "lazy_static", + "ms_hostcall", + "ms_std", + "ms_std_proc_macro", + "sjlj", + "spin", + "wasmtime", +] + +[[package]] +name = "winch-codegen" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85c6915884e731b2db0d8cf08cb64474cb69221a161675fd3c135f91febc3daa" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "regalloc2", + "smallvec", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +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", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[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", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] diff --git a/user/wasmtime_merger/Cargo.toml b/user/wasmtime_merger/Cargo.toml new file mode 100644 index 00000000..861399cd --- /dev/null +++ b/user/wasmtime_merger/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "wasmtime_merger" +version = "0.1.0" +edition = "2021" +build = "build.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +crate-type = ["staticlib"] + +[dependencies] +ms_std = { path = "../../ms_std", features = ["panic_def", "alloc_def"] } +ms_hostcall = { path = "../../ms_hostcall" } +wasmtime_wasi_api = { path = "../../wasmtime_wasi_api" } + +lazy_static = { version = "1.5.0", features = ["spin_no_std"] } +spin = "0.9.8" + +[features] +mpk = ["ms_std/mpk"] diff --git a/user/wasmtime_merger/build.rs b/user/wasmtime_merger/build.rs new file mode 100644 index 00000000..9fc09ddf --- /dev/null +++ b/user/wasmtime_merger/build.rs @@ -0,0 +1,4 @@ +fn main() { + println!("cargo:rustc-link-lib=static={}", "wasmtime-platform"); + println!("cargo:rustc-link-search=native={}", "./"); +} diff --git a/user/wasmtime_merger/build.sh b/user/wasmtime_merger/build.sh new file mode 100755 index 00000000..487d3949 --- /dev/null +++ b/user/wasmtime_merger/build.sh @@ -0,0 +1,16 @@ +# $CPP merger.cpp -o merger.wasm -fno-exceptions -fno-rtti -ffast-math -funroll-loops -fomit-frame-pointer -Ofast +$CPP merger_ori.cpp -o merger.wasm -fno-exceptions -fno-rtti -ffast-math -funroll-loops -fomit-frame-pointer -Ofast +# $CC merger.c -o merger.wasm +wasmtime compile --target x86_64-unknown-none -W threads=n,tail-call=n merger.wasm +# wasmtime compile --target x86_64-unknown-none -W simd=y,threads=n,tail-call=n merger.wasm + +cargo build --target x86_64-unknown-none --release && cc \ + -Wl,--gc-sections -nostdlib \ + -Wl,--whole-archive \ + target/x86_64-unknown-none/release/libwasmtime_merger.a \ + -Wl,--no-whole-archive \ + -shared \ + -o target/x86_64-unknown-none/release/libwasmtime_merger.so + +ln -s /home/wyj/alloy_stack/mslibos/user/wasmtime_merger/target/x86_64-unknown-none/release/libwasmtime_merger.so /home/wyj/alloy_stack/mslibos/target/release/libwasmtime_merger.so + diff --git a/user/wasmtime_merger/libwasmtime-platform.a b/user/wasmtime_merger/libwasmtime-platform.a new file mode 100644 index 00000000..beebf570 Binary files /dev/null and b/user/wasmtime_merger/libwasmtime-platform.a differ diff --git a/user/wasmtime_merger/libwasmtime-platform.o b/user/wasmtime_merger/libwasmtime-platform.o new file mode 100644 index 00000000..90bbf6dd Binary files /dev/null and b/user/wasmtime_merger/libwasmtime-platform.o differ diff --git a/user/wasmtime_merger/merger.c b/user/wasmtime_merger/merger.c new file mode 100644 index 00000000..2717fe68 --- /dev/null +++ b/user/wasmtime_merger/merger.c @@ -0,0 +1,163 @@ +#include +#include +#include + +__attribute__((import_module("env"), import_name("buffer_register"))) void buffer_register(void *slot_name, int name_size, void *buffer, int buffer_size); +__attribute__((import_module("env"), import_name("access_buffer"))) void access_buffer(void *slot_name, int name_size, void *buffer, int buffer_size); + +#define MAX_ARRAY_LENGTH 20000000 +#define MAX_BUFFER_SIZE 200000000 + +int result[MAX_ARRAY_LENGTH]; + +typedef struct { + int value; // 存储的值 + int arrayIndex; // 数组索引 + int elementIndex; // 元素索引 +} HeapNode; + +// 最小堆的比较函数 +int compare(const void *a, const void *b) { + return ((HeapNode *)a)->value - ((HeapNode *)b)->value; +} + +void heapifyDown(HeapNode *minHeap, int heapSize, int index) { + int smallest = index; + int left = 2 * index + 1; + int right = 2 * index + 2; + + // 比较当前节点与其左子节点 + if (left < heapSize && minHeap[left].value < minHeap[smallest].value) { + smallest = left; + } + + // 比较当前节点与其右子节点 + if (right < heapSize && minHeap[right].value < minHeap[smallest].value) { + smallest = right; + } + + // 如果最小值不是当前节点,则交换并继续下沉 + if (smallest != index) { + HeapNode temp = minHeap[index]; + minHeap[index] = minHeap[smallest]; + minHeap[smallest] = temp; + + // 递归调用下沉操作 + heapifyDown(minHeap, heapSize, smallest); + } +} + +int main(int argc, char* argv[]) { + int id = atoi(argv[1]); + int sorter_num = atoi(argv[2]); + int merger_num = atoi(argv[3]); + printf("merger_%d start!\n", id); + int bufferSize = MAX_BUFFER_SIZE; + + // access buffer + // int array[sorter_num][MAX_ARRAY_LENGTH]; + int **array = (int **)malloc(sorter_num * sizeof(int*)); + for (int i = 0; i < sorter_num; i++) { + array[i] = (int *)malloc(MAX_ARRAY_LENGTH * sizeof(int)); + } + int index[sorter_num]; + // int *index = (int *)malloc(sorter_num * sizeof(int)); + memset(index, 0, sizeof(index)); + for (int i = 0; i < sorter_num; i++) { + char slot_name[20]; + sprintf(slot_name, "merger_%d_%d", i, id); + char *buffer; + buffer = (char *)malloc(bufferSize * sizeof(char)); + if (buffer == NULL) { + perror("malloc error"); + return 1; + } + memset(buffer, 0, bufferSize * sizeof(char)); + buffer[0] = '\0'; // 初始化为空字符串 + access_buffer(slot_name, strlen(slot_name), buffer, bufferSize); + char *ptr = buffer; + int num; + while (sscanf(ptr, "%d", &num) == 1) { + array[i][index[i]] = num; + index[i]++; + // 移动指针到下一个数字 + while (*ptr && *ptr != ' ') { + ptr++; + } + if (*ptr == ' ') { + ptr++; + } + } + free(buffer); + } + + // merge + int resultIndex = 0; + HeapNode *minHeap = (HeapNode *)malloc(sorter_num * sizeof(HeapNode)); + int heapSize = 0; + // 初始化最小堆 + for (int i = 0; i < sorter_num; i++) { + if (index[i] > 0) { // 确保数组非空 + minHeap[heapSize].value = array[i][0]; + minHeap[heapSize].arrayIndex = i; + minHeap[heapSize].elementIndex = 0; + heapSize++; + } + } + // 构建初始最小堆 + // qsort(minHeap, heapSize, sizeof(HeapNode), compare); + // 使用下沉操作调整整个堆以确保最小堆性质 + for (int i = (heapSize - 2) / 2; i >= 0; i--) { + heapifyDown(minHeap, heapSize, i); + } + while (heapSize > 0) { + // 获取最小元素 + HeapNode minNode = minHeap[0]; + result[resultIndex++] = minNode.value; + + // 替换最小值的元素 + if (minNode.elementIndex + 1 < index[minNode.arrayIndex]) { + minNode.elementIndex++; + minNode.value = array[minNode.arrayIndex][minNode.elementIndex]; + // 更新堆 + minHeap[0] = minNode; + // qsort(minHeap, heapSize, sizeof(HeapNode), compare); // 重新构建堆 + } else { + // 如果该数组没有更多元素,则用最后一个元素替换掉 + minHeap[0] = minHeap[--heapSize]; + } + // 执行下沉操作以恢复堆的性质 + heapifyDown(minHeap, heapSize, 0); + } + free(minHeap); + + // rigister mergered array + + char slot_name[20]; + sprintf(slot_name, "checker_%d", id); + char *buffer; + buffer = (char *)malloc(bufferSize * sizeof(char)); + if (buffer == NULL) { + perror("malloc error"); + return 1; + } + memset(buffer, 0, bufferSize * sizeof(char)); + buffer[0] = '\0'; // 初始化为空字符串 + char *ptr = buffer; + for (int i = 0; i < resultIndex; i++) { + char temp[12]; // 临时缓冲区,注意要足够大以容纳最大整数和一个空格 + snprintf(temp, sizeof(temp), "%d ", result[i]); // 将整数转换为字符串,并加上空格 + // strcat(buffer, temp); // 追加到 buffer + strncpy(ptr, temp, strlen(temp)); + ptr += strlen(temp); + } + // 去掉最后一个多余的空格 + // buffer[strlen(buffer) - 1] = '\0'; + *ptr++ = '\0'; + buffer_register(slot_name, strlen(slot_name), buffer, bufferSize); + free(buffer); + + + printf("merger_%d all finished!\n", id); + return 0; +} \ No newline at end of file diff --git a/user/wasmtime_merger/merger.cpp b/user/wasmtime_merger/merger.cpp new file mode 100644 index 00000000..955ef576 --- /dev/null +++ b/user/wasmtime_merger/merger.cpp @@ -0,0 +1,137 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +__attribute__((import_module("env"), import_name("buffer_register"))) void buffer_register(void *slot_name, int name_size, void *buffer, int buffer_size); +__attribute__((import_module("env"), import_name("access_buffer"))) void access_buffer(void *slot_name, int name_size, void *buffer, int buffer_size); + +#define MAX_ARRAY_LENGTH 8000000 +#define MAX_BUFFER_SIZE 80000000 + +int result[MAX_ARRAY_LENGTH]; + +typedef struct { + int value; // 存储的值 + int arrayIndex; // 数组索引 + int elementIndex; // 元素索引 +} HeapNode; + +// 最小堆的比较函数 +int compare(const void *a, const void *b) { + return ((HeapNode *)a)->value - ((HeapNode *)b)->value; +} + +void heapifyDown(HeapNode *minHeap, int heapSize, int index) { + int smallest = index; + int left = 2 * index + 1; + int right = 2 * index + 2; + + // 比较当前节点与其左子节点 + if (left < heapSize && minHeap[left].value < minHeap[smallest].value) { + smallest = left; + } + + // 比较当前节点与其右子节点 + if (right < heapSize && minHeap[right].value < minHeap[smallest].value) { + smallest = right; + } + + // 如果最小值不是当前节点,则交换并继续下沉 + if (smallest != index) { + HeapNode temp = minHeap[index]; + minHeap[index] = minHeap[smallest]; + minHeap[smallest] = temp; + + // 递归调用下沉操作 + heapifyDown(minHeap, heapSize, smallest); + } +} + +int main(int argc, char* argv[]) { + int id = atoi(argv[1]); + int sorter_num = atoi(argv[2]); + int merger_num = atoi(argv[3]); + printf("merger_%d start!\n", id); + int bufferSize = MAX_BUFFER_SIZE; + + // access buffer + // int array[sorter_num][MAX_ARRAY_LENGTH]; + int **arrays = (int **)malloc(sorter_num * sizeof(int*)); + for (int i = 0; i < sorter_num; i++) { + arrays[i] = (int *)malloc(MAX_ARRAY_LENGTH * sizeof(int)); + } + int index[sorter_num]; + // int *index = (int *)malloc(sorter_num * sizeof(int)); + memset(index, 0, sizeof(index)); + for (int i = 0; i < sorter_num; i++) { + string slot_name = "merger_" + to_string(i) + "_" + to_string(id); + string buffer = string(MAX_BUFFER_SIZE, 0); + access_buffer((void*)slot_name.c_str(), slot_name.length(), (void*)buffer.c_str(), MAX_BUFFER_SIZE); + istringstream iss(buffer); + int num; + while (iss >> num) { + arrays[i][index[i]++] = num; + } + } + + // merge + int resultIndex = 0; + HeapNode *minHeap = (HeapNode *)malloc(sorter_num * sizeof(HeapNode)); + int heapSize = 0; + // 初始化最小堆 + for (int i = 0; i < sorter_num; i++) { + if (index[i] > 0) { // 确保数组非空 + minHeap[heapSize].value = arrays[i][0]; + minHeap[heapSize].arrayIndex = i; + minHeap[heapSize].elementIndex = 0; + heapSize++; + } + } + // 构建初始最小堆 + // qsort(minHeap, heapSize, sizeof(HeapNode), compare); + // 使用下沉操作调整整个堆以确保最小堆性质 + for (int i = (heapSize - 2) / 2; i >= 0; i--) { + heapifyDown(minHeap, heapSize, i); + } + while (heapSize > 0) { + // 获取最小元素 + HeapNode minNode = minHeap[0]; + result[resultIndex++] = minNode.value; + + // 替换最小值的元素 + if (minNode.elementIndex + 1 < index[minNode.arrayIndex]) { + minNode.elementIndex++; + minNode.value = arrays[minNode.arrayIndex][minNode.elementIndex]; + // 更新堆 + minHeap[0] = minNode; + // qsort(minHeap, heapSize, sizeof(HeapNode), compare); // 重新构建堆 + } else { + // 如果该数组没有更多元素,则用最后一个元素替换掉 + minHeap[0] = minHeap[--heapSize]; + } + // 执行下沉操作以恢复堆的性质 + heapifyDown(minHeap, heapSize, 0); + } + free(minHeap); + + // rigister mergered array + string slot_name = "checker_" + to_string(id); + string buffer; + for (int i = 0; i < resultIndex; i++) { + buffer.append(to_string(result[i]) + " "); + } + buffer.resize(MAX_BUFFER_SIZE, '\0'); + buffer_register((void*)slot_name.c_str(), slot_name.length(), (void*)buffer.c_str(), MAX_BUFFER_SIZE); + printf("merger_%d all finished!\n", id); + return 0; +} \ No newline at end of file diff --git a/user/wasmtime_merger/merger.cwasm b/user/wasmtime_merger/merger.cwasm new file mode 100644 index 00000000..fd9622b3 Binary files /dev/null and b/user/wasmtime_merger/merger.cwasm differ diff --git a/user/wasmtime_merger/merger.wasm b/user/wasmtime_merger/merger.wasm new file mode 100755 index 00000000..372160be Binary files /dev/null and b/user/wasmtime_merger/merger.wasm differ diff --git a/user/wasmtime_merger/merger_ori.cpp b/user/wasmtime_merger/merger_ori.cpp new file mode 100644 index 00000000..69939819 --- /dev/null +++ b/user/wasmtime_merger/merger_ori.cpp @@ -0,0 +1,182 @@ +#include +#include +#include +#include + +__attribute__((import_module("env"), import_name("buffer_register"))) void buffer_register(void *slot_name, int name_size, void *buffer, int buffer_size); +__attribute__((import_module("env"), import_name("access_buffer"))) void access_buffer(void *slot_name, int name_size, void *buffer, int buffer_size); + +// #define MAX_ARRAY_LENGTH 152221 +// #define MAX_BUFFER_SIZE 1024*1024+152221 + +#define MAX_ARRAY_LENGTH 3805441 +#define MAX_BUFFER_SIZE 25*1024*1024+3805441 + +// #define MAX_ARRAY_LENGTH 7611001 +// #define MAX_BUFFER_SIZE 50*1024*1024+7611001 + +int result[MAX_ARRAY_LENGTH]; + +typedef struct { + int value; // 存储的值 + int arrayIndex; // 数组索引 + int elementIndex; // 元素索引 +} HeapNode; + +void get_time(int num, int phase) { + timeval tv{}; + gettimeofday(&tv, nullptr); + printf("%lld.%06lld--%d--%d\n", tv.tv_sec, tv.tv_usec, num, phase); +} + +// 最小堆的比较函数 +int compare(const void *a, const void *b) { + return ((HeapNode *)a)->value - ((HeapNode *)b)->value; +} + +void heapifyDown(HeapNode *minHeap, int heapSize, int index) { + int smallest = index; + int left = 2 * index + 1; + int right = 2 * index + 2; + + // 比较当前节点与其左子节点 + if (left < heapSize && minHeap[left].value < minHeap[smallest].value) { + smallest = left; + } + + // 比较当前节点与其右子节点 + if (right < heapSize && minHeap[right].value < minHeap[smallest].value) { + smallest = right; + } + + // 如果最小值不是当前节点,则交换并继续下沉 + if (smallest != index) { + HeapNode temp = minHeap[index]; + minHeap[index] = minHeap[smallest]; + minHeap[smallest] = temp; + + // 递归调用下沉操作 + heapifyDown(minHeap, heapSize, smallest); + } +} + +int main(int argc, char* argv[]) { + // get_time(); + int id = atoi(argv[1]); + int sorter_num = atoi(argv[2]); + int merger_num = atoi(argv[3]); + // printf("merger_%d start!\n", id); + // int bufferSize = MAX_BUFFER_SIZE; + + // access buffer + // int array[sorter_num][MAX_ARRAY_LENGTH]; + int **array = (int **)malloc(sorter_num * sizeof(int*)); + for (int i = 0; i < sorter_num; i++) { + array[i] = (int *)malloc(MAX_ARRAY_LENGTH * sizeof(int)); + } + int index[sorter_num]; + // int *index = (int *)malloc(sorter_num * sizeof(int)); + memset(index, 0, sizeof(index)); + int time_num = 12; + for (int i = 0; i < sorter_num; i++) { + char slot_name[20]; + sprintf(slot_name, "merger_%d_%d", i, id); + char *buffer; + buffer = (char *)malloc(MAX_BUFFER_SIZE * sizeof(char)); + memset(buffer, 0, MAX_BUFFER_SIZE * sizeof(char)); + buffer[0] = '\0'; // 初始化为空字符串 + if (id == 0) + get_time(time_num, 0); + access_buffer(slot_name, strlen(slot_name), buffer, MAX_BUFFER_SIZE); + if (id == 0) + get_time(time_num, 1); + time_num++; + char *ptr = buffer; + int num; + while (sscanf(ptr, "%d", &num) == 1) { + array[i][index[i]] = num; + index[i]++; + // 移动指针到下一个数字 + while (*ptr && *ptr != ' ') { + ptr++; + } + if (*ptr == ' ') { + ptr++; + } + } + free(buffer); + printf("merger_index: %d\n", index[i]); + } + + // merge + int resultIndex = 0; + HeapNode *minHeap = (HeapNode *)malloc(sorter_num * sizeof(HeapNode)); + int heapSize = 0; + // 初始化最小堆 + for (int i = 0; i < sorter_num; i++) { + if (index[i] > 0) { // 确保数组非空 + minHeap[heapSize].value = array[i][0]; + minHeap[heapSize].arrayIndex = i; + minHeap[heapSize].elementIndex = 0; + heapSize++; + } + } + // 构建初始最小堆 + // qsort(minHeap, heapSize, sizeof(HeapNode), compare); + // 使用下沉操作调整整个堆以确保最小堆性质 + for (int i = (heapSize - 2) / 2; i >= 0; i--) { + heapifyDown(minHeap, heapSize, i); + } + while (heapSize > 0) { + // 获取最小元素 + HeapNode minNode = minHeap[0]; + result[resultIndex++] = minNode.value; + + // 替换最小值的元素 + if (minNode.elementIndex + 1 < index[minNode.arrayIndex]) { + minNode.elementIndex++; + minNode.value = array[minNode.arrayIndex][minNode.elementIndex]; + // 更新堆 + minHeap[0] = minNode; + // qsort(minHeap, heapSize, sizeof(HeapNode), compare); // 重新构建堆 + } else { + // 如果该数组没有更多元素,则用最后一个元素替换掉 + minHeap[0] = minHeap[--heapSize]; + } + // 执行下沉操作以恢复堆的性质 + heapifyDown(minHeap, heapSize, 0); + } + free(minHeap); + + // rigister mergered array + + char slot_name[20]; + sprintf(slot_name, "checker_%d", id); + char *buffer; + buffer = (char *)malloc(MAX_BUFFER_SIZE * sizeof(char)); + memset(buffer, 0, MAX_BUFFER_SIZE * sizeof(char)); + buffer[0] = '\0'; // 初始化为空字符串 + char *ptr = buffer; + for (int i = 0; i < resultIndex; i++) { + char temp[12]; // 临时缓冲区,注意要足够大以容纳最大整数和一个空格 + snprintf(temp, sizeof(temp), "%d ", result[i]); // 将整数转换为字符串,并加上空格 + // strcat(buffer, temp); // 追加到 buffer + strncpy(ptr, temp, strlen(temp)); + ptr += strlen(temp); + } + // 去掉最后一个多余的空格 + // buffer[strlen(buffer) - 1] = '\0'; + *ptr++ = '\0'; + printf("result_index: %d\n", resultIndex); + if (id == 0) + get_time(15, 0); + buffer_register(slot_name, strlen(slot_name), buffer, MAX_BUFFER_SIZE); + if (id == 0) + get_time(15, 1); + // free(buffer); + + + // printf("merger_%d all finished!\n", id); + // get_time(); + return 0; +} \ No newline at end of file diff --git a/user/wasmtime_merger/src/lib.rs b/user/wasmtime_merger/src/lib.rs new file mode 100644 index 00000000..9d866739 --- /dev/null +++ b/user/wasmtime_merger/src/lib.rs @@ -0,0 +1,74 @@ +#![no_std] + +extern crate alloc; +use core::mem::forget; + +use alloc::{string::{String, ToString}, vec::Vec}; +use spin::Mutex; + +use ms_hostcall::types::{OpenFlags, OpenMode}; +use ms_std::{agent::FaaSFuncResult as Result, args, println, libos::libos}; + +use wasmtime_wasi_api::{wasmtime, LibosCtx}; +use wasmtime::Store; + +static CWASM: &[u8] = include_bytes!("../merger.cwasm"); + +static INIT_LOCK: Mutex<()> = Mutex::new(()); + +lazy_static::lazy_static! { + static ref MUST_OPEN_ROOT: bool = { + libos!(open("/", OpenFlags::empty(), OpenMode::RD)).unwrap(); + true + }; +} + +fn func_body(my_id: &str, sorter_num: u64, merger_num: u64) -> Result<()> { + // #[cfg(feature = "log")] + println!("rust: my_id: {:?}, sorter_num: {:?}, merger_num: {:?}", my_id, sorter_num, merger_num); + + let wasi_args: Vec = Vec::from([ + "fake system path!".to_string(), + my_id.to_string(), + sorter_num.to_string(), + merger_num.to_string(), + ]); + wasmtime_wasi_api::set_wasi_args(my_id, wasi_args); + + let _open_root = *MUST_OPEN_ROOT; + + let lock = INIT_LOCK.lock(); + let (engine, module, linker) = wasmtime_wasi_api::build_wasm(CWASM); + drop(lock); + + let mut store = Store::new(&engine, LibosCtx{id: my_id.to_string()}); + let instance = linker.instantiate(&mut store, &module)?; + + let mut memory = instance.get_memory(&mut store, "memory").unwrap(); + let pages = memory.grow(&mut store, 20000).unwrap(); + + let main = instance + .get_typed_func::<(), ()>(&mut store, "_start") + .map_err(|e| e.to_string())?; + + // main.call(store, ()).map_err(|e| e.to_string())?; + main.call(&mut store, ()).map_err(|e| e.to_string())?; + forget(store); + + Ok(().into()) +} + +#[no_mangle] +pub fn main() -> Result<()> { + let my_id = args::get("id").unwrap(); + let sorter_num: u64 = args::get("sorter_num") + .expect("missing arg sorter_num") + .parse() + .unwrap_or_else(|_| panic!("bad arg, sorter_num={}", args::get("sorter_num").unwrap())); + let merger_num: u64 = args::get("merger_num") + .expect("missing arg merger_num") + .parse() + .unwrap_or_else(|_| panic!("bad arg, merger_num={}", args::get("merger_num").unwrap())); + + func_body(my_id, sorter_num, merger_num) +} diff --git a/user/wasmtime_reducer/Cargo.lock b/user/wasmtime_reducer/Cargo.lock new file mode 100644 index 00000000..801ddb4d --- /dev/null +++ b/user/wasmtime_reducer/Cargo.lock @@ -0,0 +1,1195 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + +[[package]] +name = "arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cc" +version = "1.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cobs" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "cranelift-bforest" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6b33d7e757a887989eb18b35712b2a67d96171ec3149d1bfb657b29b7b367c" +dependencies = [ + "cranelift-entity", +] + +[[package]] +name = "cranelift-codegen" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9acf15cb22be42d07c3b57d7856329cb228b7315d385346149df2566ad5e4aa" +dependencies = [ + "bumpalo", + "cranelift-bforest", + "cranelift-codegen-meta", + "cranelift-codegen-shared", + "cranelift-control", + "cranelift-entity", + "cranelift-isle", + "gimli", + "hashbrown 0.14.5", + "log", + "regalloc2", + "rustc-hash", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e934d301392b73b3f8b0540391fb82465a0f179a3cee7c726482ac4727efcc97" +dependencies = [ + "cranelift-codegen-shared", +] + +[[package]] +name = "cranelift-codegen-shared" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb2a2566b3d54b854dfb288b3b187f6d3d17d6f762c92898207eba302931da" + +[[package]] +name = "cranelift-control" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0100f33b704cdacd01ad66ff41f8c5030d57cbff078e2a4e49ab1822591299fa" +dependencies = [ + "arbitrary", +] + +[[package]] +name = "cranelift-entity" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8cfdc315e5d18997093e040a8d234bea1ac1e118a716d3e30f40d449e78207b" +dependencies = [ + "serde", + "serde_derive", +] + +[[package]] +name = "cranelift-frontend" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f74b84f16af2e982b0c0c72233503d9d55cbfe3865dbe807ca28dc6642a28b5" +dependencies = [ + "cranelift-codegen", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-isle" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adf306d3dde705fb94bd48082f01d38c4ededc74293a4c007805f610bf08bc6e" + +[[package]] +name = "cranelift-native" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ea0ebdef7aff4a79bcbc8b6495f31315f16b3bf311152f472eaa8d679352581" +dependencies = [ + "cranelift-codegen", + "libc", + "target-lexicon", +] + +[[package]] +name = "cranelift-wasm" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d549108a1942065cdbac3bb96c2952afa0e1b9a3beff4b08c4308ac72257576d" +dependencies = [ + "cranelift-codegen", + "cranelift-entity", + "cranelift-frontend", + "itertools", + "log", + "smallvec", + "wasmparser", + "wasmtime-types", +] + +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn 2.0.79", +] + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[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.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + +[[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 = "hash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" +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.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +dependencies = [ + "foldhash", +] + +[[package]] +name = "heapless" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" +dependencies = [ + "hash32", + "stable_deref_trait", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + +[[package]] +name = "indexmap" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +dependencies = [ + "equivalent", + "hashbrown 0.15.0", + "serde", +] + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + +[[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.159" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "linked_list_allocator" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286" +dependencies = [ + "spinning_top", +] + +[[package]] +name = "linux-raw-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1ad52afd8f9448cbbe722ae722849cc41f1d365e285cca386896352bc08e1a9" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mach2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" +dependencies = [ + "libc", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "memfd" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" +dependencies = [ + "rustix", +] + +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "ms_hostcall" +version = "0.1.0" +dependencies = [ + "bitflags", + "derive_more", + "thiserror-no-std", +] + +[[package]] +name = "ms_std" +version = "0.1.0" +dependencies = [ + "cfg-if", + "heapless", + "linked_list_allocator", + "ms_hostcall", + "ms_std_proc_macro", + "spin", + "thiserror-no-std", +] + +[[package]] +name = "ms_std_proc_macro" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "naked-function" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b8d5fca6ab1e6215b010aefd3b9ac5aae369dae0faea3a7f34f296cc9f719ac" +dependencies = [ + "cfg-if", + "naked-function-macro", +] + +[[package]] +name = "naked-function-macro" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b4123e70df5fe0bb370cff166ae453b9c5324a2cfc932c0f7e55498147a0475" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "object" +version = "0.36.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" +dependencies = [ + "crc32fast", + "hashbrown 0.15.0", + "indexmap", + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "postcard" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f7f0a8d620d71c457dd1d47df76bb18960378da56af4527aaa10f515eee732e" +dependencies = [ + "cobs", + "embedded-io 0.4.0", + "embedded-io 0.6.1", + "serde", +] + +[[package]] +name = "proc-macro2" +version = "1.0.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "psm" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa37f80ca58604976033fae9515a8a2989fc13797d953f7c04fb8fa36a11f205" +dependencies = [ + "cc", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[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 = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys 0.4.14", + "windows-sys", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "sc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "010e18bd3bfd1d45a7e666b236c78720df0d9a7698ebaa9c1c559961eb60a38b" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "sjlj" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9b43efc387069aabdc27124a294337c7032a3cb62df0108d2578eff7f08e39" +dependencies = [ + "linux-raw-sys 0.2.2", + "naked-function", + "sc", +] + +[[package]] +name = "slice-group-by" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +dependencies = [ + "serde", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spinning_top" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b9eb1a2f4c41445a3a0ff9abc5221c5fcd28e1f13cd7c0397706f9ac938ddb0" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "target-lexicon" +version = "0.12.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" + +[[package]] +name = "thiserror" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "thiserror-impl-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58e6318948b519ba6dc2b442a6d0b904ebfb8d411a3ad3e07843615a72249758" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "thiserror-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3ad459d94dd517257cc96add8a43190ee620011bb6e6cdc82dafd97dfafafea" +dependencies = [ + "thiserror-impl-no-std", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasm-encoder" +version = "0.209.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4a05336882dae732ce6bd48b7e11fe597293cb72c13da4f35d7d5f8d53b2a7" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasmparser" +version = "0.209.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07035cc9a9b41e62d3bb3a3815a66ab87c993c06fe1cf6b2a3f2a18499d937db" +dependencies = [ + "ahash", + "bitflags", + "hashbrown 0.14.5", + "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", +] + +[[package]] +name = "wasmtime" +version = "22.0.0" +source = "git+https://gitee.com/tju-cloud-computing/wasmtime-as-lib?branch=master#fb45fb8dde6d068abb3ae78bfab78253c9654af5" +dependencies = [ + "anyhow", + "bumpalo", + "cc", + "cfg-if", + "encoding_rs", + "hashbrown 0.14.5", + "indexmap", + "libc", + "libm", + "log", + "mach2", + "memfd", + "memoffset", + "object", + "once_cell", + "paste", + "postcard", + "psm", + "rustix", + "semver", + "serde", + "serde_derive", + "smallvec", + "sptr", + "target-lexicon", + "wasmparser", + "wasmtime-asm-macros", + "wasmtime-component-macro", + "wasmtime-component-util", + "wasmtime-cranelift", + "wasmtime-environ", + "wasmtime-jit-icache-coherence", + "wasmtime-slab", + "wasmtime-versioned-export-macros", + "wasmtime-winch", + "windows-sys", +] + +[[package]] +name = "wasmtime-asm-macros" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d697d99c341d4a9ffb72f3af7a02124d233eeb59aee010f36d88e97cca553d5e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "wasmtime-component-macro" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b29b462b068e73b5b27fae092a27f47e5937cabf6b26be2779c978698a52feca" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn 2.0.79", + "wasmtime-component-util", + "wasmtime-wit-bindgen", + "wit-parser", +] + +[[package]] +name = "wasmtime-component-util" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d2912c53d9054984b380dfbd7579f9c3681b2a73b903a56bd71a1c4f175f1e" + +[[package]] +name = "wasmtime-cranelift" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3975deafea000457ba84355c7c0fce0372937204f77026510b7b454f28a3a65" +dependencies = [ + "anyhow", + "cfg-if", + "cranelift-codegen", + "cranelift-control", + "cranelift-entity", + "cranelift-frontend", + "cranelift-native", + "cranelift-wasm", + "gimli", + "log", + "object", + "target-lexicon", + "thiserror", + "wasmparser", + "wasmtime-environ", + "wasmtime-versioned-export-macros", +] + +[[package]] +name = "wasmtime-environ" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f444e900e848b884d8a8a2949b6f5b92af642a3e663ff8fbe78731143a55be61" +dependencies = [ + "anyhow", + "cranelift-entity", + "gimli", + "indexmap", + "log", + "object", + "postcard", + "serde", + "serde_derive", + "target-lexicon", + "wasm-encoder", + "wasmparser", + "wasmprinter", + "wasmtime-component-util", + "wasmtime-types", +] + +[[package]] +name = "wasmtime-jit-icache-coherence" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5afe2f0499542f9a4bcfa1b55bfdda803b6ade4e7c93c6b99e0f39dba44b0a91" +dependencies = [ + "anyhow", + "cfg-if", + "libc", + "windows-sys", +] + +[[package]] +name = "wasmtime-slab" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a7de1f2bec5bbb35d532e61c85c049dc84ae671df60492f90b954ecf21169e7" + +[[package]] +name = "wasmtime-types" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "412463e9000e14cf6856be48628d2213c20c153e29ffc22b036980c892ea6964" +dependencies = [ + "cranelift-entity", + "serde", + "serde_derive", + "smallvec", + "wasmparser", +] + +[[package]] +name = "wasmtime-versioned-export-macros" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de5a9bc4f44ceeb168e9e8e3be4e0b4beb9095b468479663a9e24c667e36826f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "wasmtime-winch" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed4db238a0241df2d15f79ad17b3a37a27f2ea6cb885894d81b42ae107544466" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "object", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", + "winch-codegen", +] + +[[package]] +name = "wasmtime-wit-bindgen" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc077306b38288262e5ba01d4b21532a6987416cdc0aedf04bb06c22a68fdc" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "wit-parser", +] + +[[package]] +name = "wasmtime_reducer" +version = "0.1.0" +dependencies = [ + "lazy_static", + "ms_hostcall", + "ms_std", + "spin", + "wasmtime_wasi_api", +] + +[[package]] +name = "wasmtime_wasi_api" +version = "0.1.0" +dependencies = [ + "hashbrown 0.14.5", + "lazy_static", + "ms_hostcall", + "ms_std", + "ms_std_proc_macro", + "sjlj", + "spin", + "wasmtime", +] + +[[package]] +name = "winch-codegen" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85c6915884e731b2db0d8cf08cb64474cb69221a161675fd3c135f91febc3daa" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "regalloc2", + "smallvec", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +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", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[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", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] diff --git a/user/wasmtime_reducer/Cargo.toml b/user/wasmtime_reducer/Cargo.toml new file mode 100644 index 00000000..c73a8542 --- /dev/null +++ b/user/wasmtime_reducer/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "wasmtime_reducer" +version = "0.1.0" +edition = "2021" +build = "build.rs" +# build = "../../build_wasm.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +crate-type = ["staticlib"] + +[dependencies] +ms_std = { path = "../../ms_std", features = ["panic_def", "alloc_def"] } +ms_hostcall = { path = "../../ms_hostcall", features = ["signal"] } +wasmtime_wasi_api = { path = "../../wasmtime_wasi_api" } + +lazy_static = { version = "1.5.0", features = ["spin_no_std"] } +spin = "0.9.8" + +[features] +mpk = ["ms_std/mpk"] diff --git a/user/wasmtime_reducer/build.rs b/user/wasmtime_reducer/build.rs new file mode 100644 index 00000000..9fc09ddf --- /dev/null +++ b/user/wasmtime_reducer/build.rs @@ -0,0 +1,4 @@ +fn main() { + println!("cargo:rustc-link-lib=static={}", "wasmtime-platform"); + println!("cargo:rustc-link-search=native={}", "./"); +} diff --git a/user/wasmtime_reducer/build.sh b/user/wasmtime_reducer/build.sh new file mode 100755 index 00000000..d2d2dd4f --- /dev/null +++ b/user/wasmtime_reducer/build.sh @@ -0,0 +1,25 @@ +# $CC reducer.c -o reducer.wasm +$CPP reducer_new.cpp -o reducer.wasm -fno-exceptions -fno-rtti -ffast-math -funroll-loops -fomit-frame-pointer -Ofast + +wasmtime compile --target x86_64-unknown-none -W threads=n,tail-call=n reducer.wasm + +cargo build --target x86_64-unknown-none --release && cc \ + -Wl,--gc-sections -nostdlib \ + -Wl,--whole-archive \ + target/x86_64-unknown-none/release/libwasmtime_reducer.a \ + -Wl,--no-whole-archive \ + -shared \ + -o target/x86_64-unknown-none/release/libwasmtime_reducer.so + +ln -s /home/wyj/alloy_stack/mslibos/user/wasmtime_reducer/target/x86_64-unknown-none/release/libwasmtime_reducer.so /home/wyj/alloy_stack/mslibos/target/release/libwasmtime_reducer.so + + +# cargo build --target x86_64-unknown-none && cc \ +# -Wl,--gc-sections -nostdlib \ +# -Wl,--whole-archive \ +# target/x86_64-unknown-none/debug/libwasmtime_reducer.a \ +# -Wl,--no-whole-archive \ +# -shared \ +# -o target/x86_64-unknown-none/debug/libwasmtime_reducer.so + +# ln -s /home/wyj/alloy_stack/mslibos/user/wasmtime_reducer/target/x86_64-unknown-none/debug/libwasmtime_reducer.so /home/wyj/alloy_stack/mslibos/target/debug/libwasmtime_reducer.so diff --git a/user/wasmtime_reducer/libwasmtime-platform.a b/user/wasmtime_reducer/libwasmtime-platform.a new file mode 100644 index 00000000..beebf570 Binary files /dev/null and b/user/wasmtime_reducer/libwasmtime-platform.a differ diff --git a/user/wasmtime_reducer/libwasmtime-platform.o b/user/wasmtime_reducer/libwasmtime-platform.o new file mode 100644 index 00000000..90bbf6dd Binary files /dev/null and b/user/wasmtime_reducer/libwasmtime-platform.o differ diff --git a/user/wasmtime_reducer/reducer.c b/user/wasmtime_reducer/reducer.c new file mode 100644 index 00000000..f2eb59c4 --- /dev/null +++ b/user/wasmtime_reducer/reducer.c @@ -0,0 +1,104 @@ +#include +#include +#include +#include + +__attribute__((import_module("env"), import_name("access_buffer"))) void access_buffer(void *slot_name, int name_size, void *buffer, int buffer_size); + +#define MAX_WORD_LENGTH 50 +#define MAX_WORDS 18000000 +#define MAX_SLOT_NUM 5 +#define MAX_BUFFER_SIZE 500000 + +int count[MAX_WORDS]; +char *words[MAX_WORDS]; + +void to_lowercase(char *str) { + for (int i = 0; str[i]; i++) { + str[i] = tolower(str[i]); + } +} +int main(int argc, char* argv[]) { + int id = atoi(argv[1]); + int mapper_num = atoi(argv[2]); + printf("reducer.c recieve: id: %d, mapper_num: %d\n", id, mapper_num); + + char **slot_name = (char **)malloc(MAX_SLOT_NUM * sizeof(char*)); + for (int i = 0; i < MAX_SLOT_NUM; i++) { + slot_name[i] = (char *)malloc(20 * sizeof(char)); + } + // char *slot_name[MAX_SLOT_NUM]; + char **buffer = (char **)malloc(MAX_SLOT_NUM * sizeof(char*)); + for (int i = 0; i < MAX_SLOT_NUM; i++) { + buffer[i] = (char *)malloc(MAX_BUFFER_SIZE * sizeof(char)); + } + // char *buffer[MAX_SLOT_NUM]; + char slot[20]; + int bufferSize = MAX_BUFFER_SIZE; + int slot_num = mapper_num; + + printf("access start!\n"); + + for (int i = 0; i < slot_num; ++i) { + sprintf(slot, "buffer_%d_%d", id, i); + slot_name[i] = strdup(slot); + buffer[i] = (char *)malloc(bufferSize * sizeof(char)); + if (buffer[i] == NULL) { + printf("alloc mem failed\n"); + return 1; + } + access_buffer(slot_name[i], strlen(slot_name[i]), buffer[i], bufferSize); + } + printf("access success!\n"); + + char word[MAX_WORD_LENGTH]; + int word_index = 0; + + char *ptr[MAX_SLOT_NUM]; + for (int i = 0; i < slot_num; i++) { + ptr[i] = buffer[i]; + } + int num; + for (int i = 0; i < slot_num; i++) { + while (sscanf(ptr[i], "%s: %d\n", word, &num) == 1) { + to_lowercase(word); + int found = 0; + for (int j = 0; j < word_index; j++) { + if (strcmp(words[j], word) == 0) { + found = 1; + count[j] += num; + break; + } + } + if (!found) { + words[word_index] = strdup(word); + count[word_index] += num; + word_index++; + } + + // 移动指针到下一个char + while (*ptr[i] && *ptr[i] != ' ') { + ptr[i]++; + } + if (*ptr[i] == ' ') { + ptr[i]++; + } + } + } + + printf("reducer_%d_index: %d\n", id, word_index); + printf("reducer_%d read success!\n", id); + + char output_file[30]; + sprintf(output_file, "reducer_%d.txt", id); + FILE *output = fopen(output_file, "w"); + for (int i = 0; i < word_index; i++) { + fprintf(output, "%s %d\n", words[i], count[i]); + free(words[i]); + } + + fclose(output); + + printf("reducer_%d finished!\n", id); + return 0; +} \ No newline at end of file diff --git a/user/wasmtime_reducer/reducer.cpp b/user/wasmtime_reducer/reducer.cpp new file mode 100644 index 00000000..1ca86554 --- /dev/null +++ b/user/wasmtime_reducer/reducer.cpp @@ -0,0 +1,82 @@ +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +#define MAX_SLOT_NUM 10 +#define MAX_WORDS 20000000 +#define MAX_BUFFER_SIZE 500000 + +__attribute__((import_module("env"), import_name("access_buffer"))) void access_buffer(void *slot_name, int name_size, void *buffer, int buffer_size); + +void get_time() { + timeval tv{}; + gettimeofday(&tv, nullptr); + + printf("%lld.%06ld\n", (long long)tv.tv_sec, tv.tv_usec); +} + +string words[MAX_WORDS]; +int counts[MAX_WORDS]; + +int main(int argc, char* argv[]) { + int id = atoi(argv[1]); + int mapper_num = atoi(argv[2]); + cout << "reducer_" << id << " start!" << endl; + int slot_num = mapper_num; + string slot_name[MAX_SLOT_NUM]; + string buffer[MAX_SLOT_NUM]; + + for (int i = 0; i < slot_num; ++i) { + slot_name[i] = "buffer_" + to_string(i) + "_" + to_string(id); + // size_t bufferSize = faasmReadStateSize(slot_name[i].c_str()); + buffer[i] = string(MAX_BUFFER_SIZE, 0); + // faasmReadState(slot_name[i].c_str(), (uint8_t*)buffer[i].c_str(), bufferSize); + access_buffer((void*)slot_name[i].c_str(), slot_name[i].length(), (void*)buffer[i].c_str(), buffer[i].size()); + } + + // vector words; + // vector count; + int word_index = 0; + + for (int i = 0; i < slot_num; i++) { + istringstream iss(buffer[i]); + string word; + int num; + while (iss >> word >> num) { + int found = 0; + for (int i = 0; i < word_index; i++) { + if (words[i] == word) { + counts[i] += num; + found = 1; + break; + } + } + if (!found) { + // words.push_back(word); + // count.push_back(num); + words[word_index] = word; + counts[word_index] = num; + word_index++; + } + } + } + + cout << "reducer_" << id << " solved " << word_index << " words!" << endl; + + // string output_file = "faasm://reducer_" + to_string(id) + "_" + to_string(get_time()) + ".txt"; + // ofstream output(output_file); + // for (int i = 0; i < word_index; i++) { + // output << words[i] << " " << count[i] << endl; + // } + // output.close(); + + cout << "reducer_" << id << " finished!" << endl; + get_time(); + return 0; +} \ No newline at end of file diff --git a/user/wasmtime_reducer/reducer.cwasm b/user/wasmtime_reducer/reducer.cwasm new file mode 100644 index 00000000..4910d330 Binary files /dev/null and b/user/wasmtime_reducer/reducer.cwasm differ diff --git a/user/wasmtime_reducer/reducer.wasm b/user/wasmtime_reducer/reducer.wasm new file mode 100755 index 00000000..49427296 Binary files /dev/null and b/user/wasmtime_reducer/reducer.wasm differ diff --git a/user/wasmtime_reducer/reducer_new.cpp b/user/wasmtime_reducer/reducer_new.cpp new file mode 100644 index 00000000..6c629730 --- /dev/null +++ b/user/wasmtime_reducer/reducer_new.cpp @@ -0,0 +1,66 @@ +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +#define MAX_SLOT_NUM 10 +#define MAX_WORDS 18000000 +#define MAX_BUFFER_SIZE 500000 + +__attribute__((import_module("env"), import_name("access_buffer"))) void access_buffer(void *slot_name, int name_size, void *buffer, int buffer_size); + +void get_time() { + timeval tv{}; + gettimeofday(&tv, nullptr); + printf("%lld.%06lld\n", tv.tv_sec, tv.tv_usec); +} + +string words[MAX_WORDS]; +int counts[MAX_WORDS]; + +int main(int argc, char* argv[]) { + int id = atoi(argv[1]); + int mapper_num = atoi(argv[2]); + cout << "reducer_" << id << " start!" << endl; + int slot_num = mapper_num; + string slot_name[MAX_SLOT_NUM]; + string buffer[MAX_SLOT_NUM]; + + printf("start data_trans\n"); + get_time(); + for (int i = 0; i < slot_num; ++i) { + slot_name[i] = "buffer_" + to_string(i) + "_" + to_string(id); + buffer[i] = string(MAX_BUFFER_SIZE, 0); + access_buffer((void*)slot_name[i].c_str(), slot_name[i].length(), (void*)buffer[i].c_str(), buffer[i].size()); + } + printf("finish data_trans\n"); + get_time(); + unordered_map word_map; + + for (int i = 0; i < slot_num; i++) { + istringstream iss(buffer[i]); + string word; + int num; + while (iss >> word >> num) { + word_map[word] += num; + } + } + + cout << "reducer_" << id << " solved " << word_map.size() << " words!" << endl; + + // string output_file = "faasm://reducer_" + to_string(id) + "_" + to_string(get_time()) + ".txt"; + // ofstream output(output_file); + // for (int i = 0; i < word_index; i++) { + // output << words[i] << " " << count[i] << endl; + // } + // output.close(); + + cout << "reducer_" << id << " finished!" << endl; + get_time(); + return 0; +} \ No newline at end of file diff --git a/user/wasmtime_reducer/reducer_ori.cpp b/user/wasmtime_reducer/reducer_ori.cpp new file mode 100644 index 00000000..f2eb59c4 --- /dev/null +++ b/user/wasmtime_reducer/reducer_ori.cpp @@ -0,0 +1,104 @@ +#include +#include +#include +#include + +__attribute__((import_module("env"), import_name("access_buffer"))) void access_buffer(void *slot_name, int name_size, void *buffer, int buffer_size); + +#define MAX_WORD_LENGTH 50 +#define MAX_WORDS 18000000 +#define MAX_SLOT_NUM 5 +#define MAX_BUFFER_SIZE 500000 + +int count[MAX_WORDS]; +char *words[MAX_WORDS]; + +void to_lowercase(char *str) { + for (int i = 0; str[i]; i++) { + str[i] = tolower(str[i]); + } +} +int main(int argc, char* argv[]) { + int id = atoi(argv[1]); + int mapper_num = atoi(argv[2]); + printf("reducer.c recieve: id: %d, mapper_num: %d\n", id, mapper_num); + + char **slot_name = (char **)malloc(MAX_SLOT_NUM * sizeof(char*)); + for (int i = 0; i < MAX_SLOT_NUM; i++) { + slot_name[i] = (char *)malloc(20 * sizeof(char)); + } + // char *slot_name[MAX_SLOT_NUM]; + char **buffer = (char **)malloc(MAX_SLOT_NUM * sizeof(char*)); + for (int i = 0; i < MAX_SLOT_NUM; i++) { + buffer[i] = (char *)malloc(MAX_BUFFER_SIZE * sizeof(char)); + } + // char *buffer[MAX_SLOT_NUM]; + char slot[20]; + int bufferSize = MAX_BUFFER_SIZE; + int slot_num = mapper_num; + + printf("access start!\n"); + + for (int i = 0; i < slot_num; ++i) { + sprintf(slot, "buffer_%d_%d", id, i); + slot_name[i] = strdup(slot); + buffer[i] = (char *)malloc(bufferSize * sizeof(char)); + if (buffer[i] == NULL) { + printf("alloc mem failed\n"); + return 1; + } + access_buffer(slot_name[i], strlen(slot_name[i]), buffer[i], bufferSize); + } + printf("access success!\n"); + + char word[MAX_WORD_LENGTH]; + int word_index = 0; + + char *ptr[MAX_SLOT_NUM]; + for (int i = 0; i < slot_num; i++) { + ptr[i] = buffer[i]; + } + int num; + for (int i = 0; i < slot_num; i++) { + while (sscanf(ptr[i], "%s: %d\n", word, &num) == 1) { + to_lowercase(word); + int found = 0; + for (int j = 0; j < word_index; j++) { + if (strcmp(words[j], word) == 0) { + found = 1; + count[j] += num; + break; + } + } + if (!found) { + words[word_index] = strdup(word); + count[word_index] += num; + word_index++; + } + + // 移动指针到下一个char + while (*ptr[i] && *ptr[i] != ' ') { + ptr[i]++; + } + if (*ptr[i] == ' ') { + ptr[i]++; + } + } + } + + printf("reducer_%d_index: %d\n", id, word_index); + printf("reducer_%d read success!\n", id); + + char output_file[30]; + sprintf(output_file, "reducer_%d.txt", id); + FILE *output = fopen(output_file, "w"); + for (int i = 0; i < word_index; i++) { + fprintf(output, "%s %d\n", words[i], count[i]); + free(words[i]); + } + + fclose(output); + + printf("reducer_%d finished!\n", id); + return 0; +} \ No newline at end of file diff --git a/user/wasmtime_reducer/src/lib.rs b/user/wasmtime_reducer/src/lib.rs new file mode 100644 index 00000000..b5929859 --- /dev/null +++ b/user/wasmtime_reducer/src/lib.rs @@ -0,0 +1,73 @@ +#![no_std] + +extern crate alloc; +use core::mem::forget; +use alloc::{string::{String, ToString}, vec::Vec}; +use spin::Mutex; + +use ms_hostcall::types::{OpenFlags, OpenMode}; +use ms_std::{agent::FaaSFuncResult as Result, args, libos::libos, println, time::{SystemTime, UNIX_EPOCH}}; + +use wasmtime_wasi_api::{wasmtime, LibosCtx}; +use wasmtime::Store; + +static CWASM: &[u8] = include_bytes!("../reducer.cwasm"); + +static INIT_LOCK: Mutex<()> = Mutex::new(()); + +lazy_static::lazy_static! { + static ref MUST_OPEN_ROOT: bool = { + libos!(open("/", OpenFlags::empty(), OpenMode::RD)).unwrap(); + true + }; +} + +fn func_body(my_id: &str, mapper_num: u64) -> Result<()> { + #[cfg(feature = "log")] + println!("rust: my_id: {:?}, mapper_num: {:?}", my_id, mapper_num); + + let wasi_args: Vec = Vec::from([ + "fake system path!".to_string(), + my_id.to_string(), + mapper_num.to_string(), + ]); + wasmtime_wasi_api::set_wasi_args(my_id, wasi_args); + + let _open_root = *MUST_OPEN_ROOT; + + let lock = INIT_LOCK.lock(); + let (engine, module, linker) = wasmtime_wasi_api::build_wasm(CWASM); + drop(lock); + + let mut store = Store::new(&engine, LibosCtx{id: my_id.to_string()}); + let instance = linker.instantiate(&mut store, &module)?; + + let mut memory = instance.get_memory(&mut store, "memory").unwrap(); + let pages = memory.grow(&mut store, 20000).unwrap(); + // println!("rust: pages: {}", pages); + + let main = instance + .get_typed_func::<(), ()>(&mut store, "_start") + .map_err(|e| e.to_string())?; + + // main.call(store, ()).map_err(|e| e.to_string())?; + main.call(&mut store, ()).map_err(|e| e.to_string())?; + forget(store); + + #[cfg(feature = "log")] + println!("rust: wasmtime_mapper_{:?} finished!", my_id); + let end_time = SystemTime::now().duration_since(UNIX_EPOCH).as_millis(); + // println!("end_time: {:?}", end_time); + Ok(().into()) +} + +#[no_mangle] +pub fn main() -> Result<()> { + let my_id = args::get("id").unwrap(); + let mapper_num: u64 = args::get("mapper_num") + .expect("missing arg mapper_num") + .parse() + .unwrap_or_else(|_| panic!("bad arg, mapper_num={}", args::get("mapper_num").unwrap())); + + func_body(my_id, mapper_num) +} diff --git a/user/wasmtime_sorter/Cargo.lock b/user/wasmtime_sorter/Cargo.lock new file mode 100644 index 00000000..2c12e2b3 --- /dev/null +++ b/user/wasmtime_sorter/Cargo.lock @@ -0,0 +1,1194 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + +[[package]] +name = "arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cc" +version = "1.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4cbd4ab9fef358caa9c599eae3105af638ead5fb47a718315d8e03c852b9f0d" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cobs" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "cranelift-bforest" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6b33d7e757a887989eb18b35712b2a67d96171ec3149d1bfb657b29b7b367c" +dependencies = [ + "cranelift-entity", +] + +[[package]] +name = "cranelift-codegen" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9acf15cb22be42d07c3b57d7856329cb228b7315d385346149df2566ad5e4aa" +dependencies = [ + "bumpalo", + "cranelift-bforest", + "cranelift-codegen-meta", + "cranelift-codegen-shared", + "cranelift-control", + "cranelift-entity", + "cranelift-isle", + "gimli", + "hashbrown 0.14.5", + "log", + "regalloc2", + "rustc-hash", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e934d301392b73b3f8b0540391fb82465a0f179a3cee7c726482ac4727efcc97" +dependencies = [ + "cranelift-codegen-shared", +] + +[[package]] +name = "cranelift-codegen-shared" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb2a2566b3d54b854dfb288b3b187f6d3d17d6f762c92898207eba302931da" + +[[package]] +name = "cranelift-control" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0100f33b704cdacd01ad66ff41f8c5030d57cbff078e2a4e49ab1822591299fa" +dependencies = [ + "arbitrary", +] + +[[package]] +name = "cranelift-entity" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8cfdc315e5d18997093e040a8d234bea1ac1e118a716d3e30f40d449e78207b" +dependencies = [ + "serde", + "serde_derive", +] + +[[package]] +name = "cranelift-frontend" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f74b84f16af2e982b0c0c72233503d9d55cbfe3865dbe807ca28dc6642a28b5" +dependencies = [ + "cranelift-codegen", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-isle" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adf306d3dde705fb94bd48082f01d38c4ededc74293a4c007805f610bf08bc6e" + +[[package]] +name = "cranelift-native" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ea0ebdef7aff4a79bcbc8b6495f31315f16b3bf311152f472eaa8d679352581" +dependencies = [ + "cranelift-codegen", + "libc", + "target-lexicon", +] + +[[package]] +name = "cranelift-wasm" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d549108a1942065cdbac3bb96c2952afa0e1b9a3beff4b08c4308ac72257576d" +dependencies = [ + "cranelift-codegen", + "cranelift-entity", + "cranelift-frontend", + "itertools", + "log", + "smallvec", + "wasmparser", + "wasmtime-types", +] + +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "derive_more" +version = "0.99.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn 1.0.109", +] + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[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.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + +[[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 = "hash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" +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.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +dependencies = [ + "foldhash", +] + +[[package]] +name = "heapless" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" +dependencies = [ + "hash32", + "stable_deref_trait", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + +[[package]] +name = "indexmap" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +dependencies = [ + "equivalent", + "hashbrown 0.14.5", + "serde", +] + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + +[[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.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "linked_list_allocator" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286" +dependencies = [ + "spinning_top", +] + +[[package]] +name = "linux-raw-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1ad52afd8f9448cbbe722ae722849cc41f1d365e285cca386896352bc08e1a9" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mach2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" +dependencies = [ + "libc", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "memfd" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" +dependencies = [ + "rustix", +] + +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "ms_hostcall" +version = "0.1.0" +dependencies = [ + "bitflags", + "derive_more", + "thiserror-no-std", +] + +[[package]] +name = "ms_std" +version = "0.1.0" +dependencies = [ + "cfg-if", + "heapless", + "linked_list_allocator", + "ms_hostcall", + "ms_std_proc_macro", + "spin", + "thiserror-no-std", +] + +[[package]] +name = "ms_std_proc_macro" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "naked-function" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b8d5fca6ab1e6215b010aefd3b9ac5aae369dae0faea3a7f34f296cc9f719ac" +dependencies = [ + "cfg-if", + "naked-function-macro", +] + +[[package]] +name = "naked-function-macro" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b4123e70df5fe0bb370cff166ae453b9c5324a2cfc932c0f7e55498147a0475" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "object" +version = "0.36.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" +dependencies = [ + "crc32fast", + "hashbrown 0.15.0", + "indexmap", + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "postcard" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f7f0a8d620d71c457dd1d47df76bb18960378da56af4527aaa10f515eee732e" +dependencies = [ + "cobs", + "embedded-io 0.4.0", + "embedded-io 0.6.1", + "serde", +] + +[[package]] +name = "proc-macro2" +version = "1.0.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "psm" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa37f80ca58604976033fae9515a8a2989fc13797d953f7c04fb8fa36a11f205" +dependencies = [ + "cc", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[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 = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys 0.4.14", + "windows-sys", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "sc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "010e18bd3bfd1d45a7e666b236c78720df0d9a7698ebaa9c1c559961eb60a38b" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" + +[[package]] +name = "serde" +version = "1.0.193" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.193" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "serde_json" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0652c533506ad7a2e353cce269330d6afd8bdfb6d75e0ace5b35aacbd7b9e9" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "sjlj" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9b43efc387069aabdc27124a294337c7032a3cb62df0108d2578eff7f08e39" +dependencies = [ + "linux-raw-sys 0.2.2", + "naked-function", + "sc", +] + +[[package]] +name = "slice-group-by" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +dependencies = [ + "serde", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spinning_top" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b9eb1a2f4c41445a3a0ff9abc5221c5fcd28e1f13cd7c0397706f9ac938ddb0" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "target-lexicon" +version = "0.12.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" + +[[package]] +name = "thiserror" +version = "1.0.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e3de26b0965292219b4287ff031fcba86837900fe9cd2b34ea8ad893c0953d2" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "268026685b2be38d7103e9e507c938a1fcb3d7e6eb15e87870b617bf37b6d581" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "thiserror-impl-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58e6318948b519ba6dc2b442a6d0b904ebfb8d411a3ad3e07843615a72249758" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "thiserror-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3ad459d94dd517257cc96add8a43190ee620011bb6e6cdc82dafd97dfafafea" +dependencies = [ + "thiserror-impl-no-std", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasm-encoder" +version = "0.209.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4a05336882dae732ce6bd48b7e11fe597293cb72c13da4f35d7d5f8d53b2a7" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasmparser" +version = "0.209.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07035cc9a9b41e62d3bb3a3815a66ab87c993c06fe1cf6b2a3f2a18499d937db" +dependencies = [ + "ahash", + "bitflags", + "hashbrown 0.14.5", + "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", +] + +[[package]] +name = "wasmtime" +version = "22.0.0" +source = "git+https://gitee.com/tju-cloud-computing/wasmtime-as-lib?branch=master#fb45fb8dde6d068abb3ae78bfab78253c9654af5" +dependencies = [ + "anyhow", + "bumpalo", + "cc", + "cfg-if", + "encoding_rs", + "hashbrown 0.14.5", + "indexmap", + "libc", + "libm", + "log", + "mach2", + "memfd", + "memoffset", + "object", + "once_cell", + "paste", + "postcard", + "psm", + "rustix", + "semver", + "serde", + "serde_derive", + "smallvec", + "sptr", + "target-lexicon", + "wasmparser", + "wasmtime-asm-macros", + "wasmtime-component-macro", + "wasmtime-component-util", + "wasmtime-cranelift", + "wasmtime-environ", + "wasmtime-jit-icache-coherence", + "wasmtime-slab", + "wasmtime-versioned-export-macros", + "wasmtime-winch", + "windows-sys", +] + +[[package]] +name = "wasmtime-asm-macros" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d697d99c341d4a9ffb72f3af7a02124d233eeb59aee010f36d88e97cca553d5e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "wasmtime-component-macro" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b29b462b068e73b5b27fae092a27f47e5937cabf6b26be2779c978698a52feca" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn 2.0.39", + "wasmtime-component-util", + "wasmtime-wit-bindgen", + "wit-parser", +] + +[[package]] +name = "wasmtime-component-util" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d2912c53d9054984b380dfbd7579f9c3681b2a73b903a56bd71a1c4f175f1e" + +[[package]] +name = "wasmtime-cranelift" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3975deafea000457ba84355c7c0fce0372937204f77026510b7b454f28a3a65" +dependencies = [ + "anyhow", + "cfg-if", + "cranelift-codegen", + "cranelift-control", + "cranelift-entity", + "cranelift-frontend", + "cranelift-native", + "cranelift-wasm", + "gimli", + "log", + "object", + "target-lexicon", + "thiserror", + "wasmparser", + "wasmtime-environ", + "wasmtime-versioned-export-macros", +] + +[[package]] +name = "wasmtime-environ" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f444e900e848b884d8a8a2949b6f5b92af642a3e663ff8fbe78731143a55be61" +dependencies = [ + "anyhow", + "cranelift-entity", + "gimli", + "indexmap", + "log", + "object", + "postcard", + "serde", + "serde_derive", + "target-lexicon", + "wasm-encoder", + "wasmparser", + "wasmprinter", + "wasmtime-component-util", + "wasmtime-types", +] + +[[package]] +name = "wasmtime-jit-icache-coherence" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5afe2f0499542f9a4bcfa1b55bfdda803b6ade4e7c93c6b99e0f39dba44b0a91" +dependencies = [ + "anyhow", + "cfg-if", + "libc", + "windows-sys", +] + +[[package]] +name = "wasmtime-slab" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a7de1f2bec5bbb35d532e61c85c049dc84ae671df60492f90b954ecf21169e7" + +[[package]] +name = "wasmtime-types" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "412463e9000e14cf6856be48628d2213c20c153e29ffc22b036980c892ea6964" +dependencies = [ + "cranelift-entity", + "serde", + "serde_derive", + "smallvec", + "wasmparser", +] + +[[package]] +name = "wasmtime-versioned-export-macros" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de5a9bc4f44ceeb168e9e8e3be4e0b4beb9095b468479663a9e24c667e36826f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "wasmtime-winch" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed4db238a0241df2d15f79ad17b3a37a27f2ea6cb885894d81b42ae107544466" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "object", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", + "winch-codegen", +] + +[[package]] +name = "wasmtime-wit-bindgen" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc077306b38288262e5ba01d4b21532a6987416cdc0aedf04bb06c22a68fdc" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "wit-parser", +] + +[[package]] +name = "wasmtime_sorter" +version = "0.1.0" +dependencies = [ + "lazy_static", + "ms_hostcall", + "ms_std", + "spin", + "wasmtime_wasi_api", +] + +[[package]] +name = "wasmtime_wasi_api" +version = "0.1.0" +dependencies = [ + "hashbrown 0.14.5", + "lazy_static", + "ms_hostcall", + "ms_std", + "ms_std_proc_macro", + "sjlj", + "spin", + "wasmtime", +] + +[[package]] +name = "winch-codegen" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85c6915884e731b2db0d8cf08cb64474cb69221a161675fd3c135f91febc3daa" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "regalloc2", + "smallvec", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +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", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[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", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] diff --git a/user/wasmtime_sorter/Cargo.toml b/user/wasmtime_sorter/Cargo.toml new file mode 100644 index 00000000..e838e1c6 --- /dev/null +++ b/user/wasmtime_sorter/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "wasmtime_sorter" +version = "0.1.0" +edition = "2021" +build = "build.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +crate-type = ["staticlib"] + +[dependencies] +ms_std = { path = "../../ms_std", features = ["panic_def", "alloc_def"] } +ms_hostcall = { path = "../../ms_hostcall" } +wasmtime_wasi_api = { path = "../../wasmtime_wasi_api" } + +lazy_static = { version = "1.5.0", features = ["spin_no_std"] } +spin = "0.9.8" + +[features] +mpk = ["ms_std/mpk"] diff --git a/user/wasmtime_sorter/build.rs b/user/wasmtime_sorter/build.rs new file mode 100644 index 00000000..9fc09ddf --- /dev/null +++ b/user/wasmtime_sorter/build.rs @@ -0,0 +1,4 @@ +fn main() { + println!("cargo:rustc-link-lib=static={}", "wasmtime-platform"); + println!("cargo:rustc-link-search=native={}", "./"); +} diff --git a/user/wasmtime_sorter/build.sh b/user/wasmtime_sorter/build.sh new file mode 100755 index 00000000..3ac709cd --- /dev/null +++ b/user/wasmtime_sorter/build.sh @@ -0,0 +1,28 @@ +# $CPP sorter.cpp -o sorter.wasm -fno-exceptions -fno-rtti -ffast-math -funroll-loops -fomit-frame-pointer -Ofast +$CPP sorter_ori.cpp -o sorter.wasm -fno-exceptions -fno-rtti -ffast-math -fomit-frame-pointer -Ofast #-funroll-loops +# $CC sorter.c -o sorter.wasm +wasmtime compile --target x86_64-unknown-none -W threads=n,tail-call=n sorter.wasm +# wasmtime compile --target x86_64-unknown-none -W simd=y,threads=n,tail-call=n sorter.wasm + +cargo build --target x86_64-unknown-none --release && cc \ + -Wl,--gc-sections -nostdlib \ + -Wl,--whole-archive \ + target/x86_64-unknown-none/release/libwasmtime_sorter.a \ + -Wl,--no-whole-archive \ + -shared \ + -o target/x86_64-unknown-none/release/libwasmtime_sorter.so + + +ln -s /home/wyj/alloy_stack/mslibos/user/wasmtime_sorter/target/x86_64-unknown-none/release/libwasmtime_sorter.so /home/wyj/alloy_stack/mslibos/target/release/libwasmtime_sorter.so + + + +# cargo build --target x86_64-unknown-none && cc \ +# -Wl,--gc-sections -nostdlib \ +# -Wl,--whole-archive \ +# target/x86_64-unknown-none/debug/libwasmtime_sorter.a \ +# -Wl,--no-whole-archive \ +# -shared \ +# -o target/x86_64-unknown-none/debug/libwasmtime_sorter.so + +# ln -s /home/wyj/alloy_stack/mslibos/user/wasmtime_sorter/target/x86_64-unknown-none/debug/libwasmtime_sorter.so /home/wyj/alloy_stack/mslibos/target/debug/libwasmtime_sorter.so diff --git a/user/wasmtime_sorter/libwasmtime-platform.a b/user/wasmtime_sorter/libwasmtime-platform.a new file mode 100644 index 00000000..beebf570 Binary files /dev/null and b/user/wasmtime_sorter/libwasmtime-platform.a differ diff --git a/user/wasmtime_sorter/libwasmtime-platform.o b/user/wasmtime_sorter/libwasmtime-platform.o new file mode 100644 index 00000000..90bbf6dd Binary files /dev/null and b/user/wasmtime_sorter/libwasmtime-platform.o differ diff --git a/user/wasmtime_sorter/sorter.c b/user/wasmtime_sorter/sorter.c new file mode 100644 index 00000000..932d8589 --- /dev/null +++ b/user/wasmtime_sorter/sorter.c @@ -0,0 +1,142 @@ +#include +#include +#include +#include +#include + +__attribute__((import_module("env"), import_name("buffer_register"))) void buffer_register(void *slot_name, int name_size, void *buffer, int buffer_size); + +#define MAX_ARRAY_LENGTH 20000000 +#define MAX_BUFFER_SIZE 200000000 + +// 比较函数,用于 qsort +int compare(const void *a, const void *b) { + return (*(int *)a - *(int *)b); // 升序排序 +} + +int array[MAX_ARRAY_LENGTH]; + +char nc(FILE *stream) { + static char buf[1<<20], *p1 = buf, *p2 = buf; + return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stream), p1 == p2) ? EOF : *p1 ++; +} + +int readfile(FILE *stream) { + int x = 0, ch = nc(stream); + for (; ch < '0' || ch > '9'; ch = nc(stream)); + for (; ch >= '0' && ch <= '9'; ch = nc(stream)) + x = (x << 1) + (x << 3) + (ch ^ 48); + return x; +} + +int main(int argc, char* argv[]) { + int id = atoi(argv[1]); + int sorter_num = atoi(argv[2]); + int merger_num = atoi(argv[3]); + printf("sorter_%d start!\n", id); + int bufferSize = MAX_BUFFER_SIZE; + char input_file[30]; + sprintf(input_file, "sort_data_%d.txt", id); + FILE *file = fopen(input_file, "r"); + if (!file) { + perror("Failed to open input file\n"); + exit(EXIT_FAILURE); + } + + int index = 0; + // char line[1024]; + // while (fgets(line, sizeof(line), file)) { + // char *token = strtok(line, " \n"); // 以空格和换行作为分隔符 + // while (token != NULL) { + // array[index++] = atoi(token); + // token = strtok(NULL, " \n"); //读取下一个单词 + // } + // } + // time_t now; + // time(&now); + // printf("%ld read start\n", now); + // write(1, "read start\n", sizeof("read start\n")); + char number[10]; + while (array[index++] = readfile(file)); + // time(&now); + // printf("%ld read finished\n", now); + // write(1, "read finished\n", sizeof("read finished\n")); + // while (fscanf(file, "%s", number) != EOF) { + // array[index] = atoi(number); + // // printf("array[%d]: %d\n", index, array[index]); + // index++; + // } + // printf("sorter_%d read finished!\n", id); + // printf("index: %d\n", index); + fclose(file); + // qsort(array, index, sizeof(int), compare); + + // printf("sorter_%d sort finished!\n", id); + + if (merger_num > 1 && id == 0) { + int pivot[merger_num-1]; + for (int i = 0; i < merger_num-1; i++) { + int idx = (i+1) * index / merger_num; + pivot[i] = array[idx]; + } + char *buffer; + buffer = (char *)malloc(bufferSize * sizeof(char)); + if (buffer == NULL) { + perror("malloc error"); + return 1; + } + memset(buffer, 0, bufferSize * sizeof(char)); + buffer[0] = '\0'; + for (int i = 0; i < merger_num-1; i++) { + char temp[12]; + snprintf(temp, sizeof(temp), "%d ", pivot[i]); + strcat(buffer, temp); // 追加到 buffer + } + buffer[strlen(buffer) - 1] = '\0'; + for (int k = 0; k < sorter_num; k++) { + char slot_name[20]; + sprintf(slot_name, "pivot_%d", k); + // printf("pivotname: %s\n", slot_name); + buffer_register(slot_name, strlen(slot_name), buffer, bufferSize); + } + free(buffer); + } + + // printf("sorter_%d pivot finished!\n", id); + // time(&now); + // printf("%ld before alloc\n", now); + // write(1, "alloc start\n", sizeof("alloc start\n")); + char slot_name[20]; + sprintf(slot_name, "sorter_%d", id); + char *buffer; + buffer = (char *)malloc(bufferSize * sizeof(char)); + if (buffer == NULL) { + perror("malloc error"); + return 1; + } + // time(&now); + // printf("%ld alloc finished\n", now); + // write(1, "alloc finished\n", sizeof("alloc finished\n")); + memset(buffer, 0, bufferSize * sizeof(char)); + // time(&now); + // printf("%ld memset finished\n", now); + // write(1, "memset finished\n", sizeof("memset finished\n")); + // buffer[0] = '\0'; // 初始化为空字符串 + char *ptr = buffer; + for (int i = 0; i < index; i++) { + char temp[12]; // 临时缓冲区,注意要足够大以容纳最大整数和一个空格 + snprintf(temp, sizeof(temp), "%d ", array[i]); // 将整数转换为字符串,并加上空格 + strncpy(ptr, temp, strlen(temp)); + ptr += strlen(temp); + // strcat(buffer, temp); // 追加到 buffer + } + *ptr++ = '\0'; + // buffer[strlen(buffer) - 1] = '\0'; + // write(1, "buffer make finished\n", sizeof("buffer make finished\n")); + buffer_register(slot_name, strlen(slot_name), buffer, bufferSize); + // write(1, "buffer register finished\n", sizeof("buffer register finished\n")); + free(buffer); + // printf("sorter_%d all finished!\n", id); + // write(1, "all finished\n", sizeof("all finished\n")); + return 0; +} \ No newline at end of file diff --git a/user/wasmtime_sorter/sorter.cpp b/user/wasmtime_sorter/sorter.cpp new file mode 100644 index 00000000..90488f45 --- /dev/null +++ b/user/wasmtime_sorter/sorter.cpp @@ -0,0 +1,90 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +__attribute__((import_module("env"), import_name("buffer_register"))) void buffer_register(void *slot_name, int name_size, void *buffer, int buffer_size); + +#define MAX_ARRAY_LENGTH 8000000 +#define MAX_BUFFER_SIZE 80000000 + +// 比较函数,用于 qsort +int compare(const void *a, const void *b) { + return (*(int *)a - *(int *)b); // 升序排序 +} + +int arrays[MAX_ARRAY_LENGTH]; + +char nc(FILE *stream) { + static char buf[1<<20], *p1 = buf, *p2 = buf; + return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stream), p1 == p2) ? EOF : *p1 ++; +} + +int readfile(FILE *stream) { + int x = 0, ch = nc(stream); + for (; ch < '0' || ch > '9'; ch = nc(stream)); + for (; ch >= '0' && ch <= '9'; ch = nc(stream)) + x = (x << 1) + (x << 3) + (ch ^ 48); + return x; +} + +int main(int argc, char* argv[]) { + int id = atoi(argv[1]); + int sorter_num = atoi(argv[2]); + int merger_num = atoi(argv[3]); + printf("sorter_%d start!\n", id); + int bufferSize = MAX_BUFFER_SIZE; + char input_file[30]; + sprintf(input_file, "sort_data_%d.txt", id); + FILE *file = fopen(input_file, "r"); + if (!file) { + perror("Failed to open input file\n"); + exit(EXIT_FAILURE); + } + int index = 0; + char number[10]; + while (arrays[index++] = readfile(file)); + printf("sorter_index: %d\n", index); + fclose(file); + + sort(arrays, arrays + index); + + if (merger_num > 1 && id == 0) { + int pivot[merger_num-1]; + for (int i = 0; i < merger_num-1; i++) { + int idx = (i+1) * index / merger_num; + pivot[i] = arrays[idx]; + } + string pivot_buffer; + for (int i = 0; i < merger_num-1; i++) { + pivot_buffer.append(to_string(pivot[i]) + " "); + } + pivot_buffer.resize(MAX_BUFFER_SIZE, '\0'); + for (int k = 0; k < sorter_num; k++) { + string slot_name = "pivot_" + to_string(k); + // printf("pivotname: %s\n", slot_name); + buffer_register((void*)slot_name.c_str(), slot_name.length(), (void*)pivot_buffer.c_str(), MAX_BUFFER_SIZE); + } + } + + string slot_name = "sorter_" + to_string(id); + string buffer; + for (int i = 0; i < index; i++) { + buffer.append(to_string(arrays[i]) + " "); + } + buffer.resize(MAX_BUFFER_SIZE, '\0'); + buffer_register((void*)slot_name.c_str(), slot_name.length(), (void*)buffer.c_str(), MAX_BUFFER_SIZE); + return 0; +} \ No newline at end of file diff --git a/user/wasmtime_sorter/sorter.cwasm b/user/wasmtime_sorter/sorter.cwasm new file mode 100644 index 00000000..abc31a40 Binary files /dev/null and b/user/wasmtime_sorter/sorter.cwasm differ diff --git a/user/wasmtime_sorter/sorter.wasm b/user/wasmtime_sorter/sorter.wasm new file mode 100755 index 00000000..8137e14d Binary files /dev/null and b/user/wasmtime_sorter/sorter.wasm differ diff --git a/user/wasmtime_sorter/sorter_ori.cpp b/user/wasmtime_sorter/sorter_ori.cpp new file mode 100644 index 00000000..df8e3561 --- /dev/null +++ b/user/wasmtime_sorter/sorter_ori.cpp @@ -0,0 +1,176 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +__attribute__((import_module("env"), import_name("buffer_register"))) void buffer_register(void *slot_name, int name_size, void *buffer, int buffer_size); + +// #define MAX_ARRAY_LENGTH 152221 +// #define MAX_BUFFER_SIZE 1024*1024+152221 + +#define MAX_ARRAY_LENGTH 3805441 +#define MAX_BUFFER_SIZE 25*1024*1024+3805441 + +// #define MAX_ARRAY_LENGTH 7611001 +// #define MAX_BUFFER_SIZE 50*1024*1024+7611001 + +// 比较函数,用于 qsort +int compare(const void *a, const void *b) { + return (*(int *)a - *(int *)b); // 升序排序 +} + +char nc(FILE *stream) { + static char buf[1<<25], *p1 = buf, *p2 = buf; + return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 25, stream), p1 == p2) ? EOF : *p1 ++; +} + +int readfile(FILE *stream) { + int x = 0, ch = nc(stream); + for (; ch < '0' || ch > '9'; ch = nc(stream)); + for (; ch >= '0' && ch <= '9'; ch = nc(stream)) + x = (x << 1) + (x << 3) + (ch ^ 48); + return x; +} + +void get_time(int num, int phase) { + timeval tv{}; + gettimeofday(&tv, nullptr); + printf("%lld.%06lld--%d--%d\n", tv.tv_sec, tv.tv_usec, num, phase); +} + +int main(int argc, char* argv[]) { + // get_time(); + int id = atoi(argv[1]); + int sorter_num = atoi(argv[2]); + int merger_num = atoi(argv[3]); + // get_time(); + // printf("sorter_%d start!\n", id); + char input_file[30]; + sprintf(input_file, "sort_data_%d.txt", id); + FILE *file = fopen(input_file, "r"); + if (!file) { + perror("Failed to open input file\n"); + exit(EXIT_FAILURE); + } + vector arrays; + int index = 0; + // char line[1024]; + // while (fgets(line, sizeof(line), file)) { + // char *token = strtok(line, " \n"); // 以空格和换行作为分隔符 + // while (token != NULL) { + // array[index++] = atoi(token); + // token = strtok(NULL, " \n"); //读取下一个单词 + // } + // } + // time_t now; + // time(&now); + // printf("%ld read start\n", now); + // write(1, "read start\n", sizeof("read start\n")); + char number[10]; + if (id == 0) + get_time(0, 0); + // while (array[index++] = readfile(file)); + int ch = nc(file), x = 0; + for (; ch != EOF; ch = nc(file)) { + if (ch == ' ' || ch == '\n') arrays.push_back(x), x = 0; + else x = x * 10 + ch - '0'; + } + arrays.push_back(x); + index = arrays.size(); + // printf("sorter_index: %d\n", index); + if (id == 0) + get_time(0, 1); + // time(&now); + // printf("%ld read finished\n", now); + // write(1, "read finished\n", sizeof("read finished\n")); + // while (fscanf(file, "%s", number) != EOF) { + // array[index] = atoi(number); + // // printf("array[%d]: %d\n", index, array[index]); + // index++; + // } + // printf("sorter_%d read finished!\n", id); + printf("index: %d\n", index); + fclose(file); + // get_time(); + // qsort(arrays.data(), index, sizeof(int), compare); + sort(arrays.data(), arrays.data()+index); + // get_time(); + // printf("sorter_%d sort finished!\n", id); + + if (merger_num > 1 && id == 0) { + int pivot[merger_num-1]; + for (int i = 0; i < merger_num-1; i++) { + int idx = (i+1) * index / merger_num; + pivot[i] = arrays[idx]; + } + char *buffer; + buffer = (char *)malloc(MAX_BUFFER_SIZE * sizeof(char)); + memset(buffer, 0, MAX_BUFFER_SIZE * sizeof(char)); + buffer[0] = '\0'; + for (int i = 0; i < merger_num-1; i++) { + char temp[12]; + snprintf(temp, sizeof(temp), "%d ", pivot[i]); + strcat(buffer, temp); // 追加到 buffer + } + buffer[strlen(buffer) - 1] = '\0'; + for (int k = 0; k < sorter_num; k++) { + char slot_name[20]; + sprintf(slot_name, "pivot_%d", k); + // printf("pivotname: %s\n", slot_name); + if (id == 0) + get_time(k+1, 0); + buffer_register(slot_name, strlen(slot_name), buffer, MAX_BUFFER_SIZE); + if (id == 0) + get_time(k+1, 1); + } + // free(buffer); + } + // printf("sorter_%d pivot finished!\n", id); + // time(&now); + // printf("%ld before alloc\n", now); + // write(1, "alloc start\n", sizeof("alloc start\n")); + char slot_name[20]; + sprintf(slot_name, "sorter_%d", id); + char *buffer; + buffer = (char *)malloc(MAX_BUFFER_SIZE * sizeof(char)); + // time(&now); + // printf("%ld alloc finished\n", now); + // write(1, "alloc finished\n", sizeof("alloc finished\n")); + // memset(buffer, 0, MAX_BUFFER_SIZE * sizeof(char)); + // time(&now); + // printf("%ld memset finished\n", now); + // write(1, "memset finished\n", sizeof("memset finished\n")); + // buffer[0] = '\0'; // 初始化为空字符串 + // get_time(); + char *ptr = buffer; + for (int i = 0; i < index; i++) { + char temp[12]; // 临时缓冲区,注意要足够大以容纳最大整数和一个空格 + snprintf(temp, sizeof(temp), "%d ", arrays[i]); // 将整数转换为字符串,并加上空格 + strncpy(ptr, temp, strlen(temp)); + ptr += strlen(temp); + // strcat(buffer, temp); // 追加到 buffer + } + *ptr++ = '\0'; + // get_time(); + // buffer[strlen(buffer) - 1] = '\0'; + // write(1, "buffer make finished\n", sizeof("buffer make finished\n")); + // get_time(); + if (id == 0) + get_time(4, 0); + buffer_register(slot_name, strlen(slot_name), buffer, MAX_BUFFER_SIZE); + if (id == 0) + get_time(4, 1); + // get_time(); + // write(1, "buffer register finished\n", sizeof("buffer register finished\n")); + // free(buffer); + // printf("sorter_%d all finished!\n", id); + // write(1, "all finished\n", sizeof("all finished\n")); + // get_time(); + return 0; +} \ No newline at end of file diff --git a/user/wasmtime_sorter/src/lib.rs b/user/wasmtime_sorter/src/lib.rs new file mode 100644 index 00000000..831270ad --- /dev/null +++ b/user/wasmtime_sorter/src/lib.rs @@ -0,0 +1,78 @@ +#![no_std] + +extern crate alloc; +use core::mem::forget; + +use alloc::{string::{String, ToString}, vec::Vec}; +use spin::Mutex; + +use ms_hostcall::types::{OpenFlags, OpenMode}; +use ms_std::{agent::FaaSFuncResult as Result, args, println, libos::libos, time::{SystemTime, UNIX_EPOCH}}; + +use wasmtime_wasi_api::{wasmtime, LibosCtx}; +use wasmtime::Store; + +static CWASM: &[u8] = include_bytes!("../sorter.cwasm"); + +static INIT_LOCK: Mutex<()> = Mutex::new(()); + +lazy_static::lazy_static! { + static ref MUST_OPEN_ROOT: bool = { + libos!(open("/", OpenFlags::empty(), OpenMode::RD)).unwrap(); + true + }; +} + +fn func_body(my_id: &str, sorter_num: u64, merger_num: u64) -> Result<()> { + // #[cfg(feature = "log")] + println!("rust: my_id: {:?}, sorter_num: {:?}, merger_num: {:?}", my_id, sorter_num, merger_num); + + let wasi_args: Vec = Vec::from([ + "fake system path!".to_string(), + my_id.to_string(), + sorter_num.to_string(), + merger_num.to_string(), + ]); + wasmtime_wasi_api::set_wasi_args(my_id, wasi_args); + + let _open_root = *MUST_OPEN_ROOT; + + let lock = INIT_LOCK.lock(); + let (engine, module, linker) = wasmtime_wasi_api::build_wasm(CWASM); + drop(lock); + + let mut store = Store::new(&engine, LibosCtx{id: my_id.to_string()}); + let instance = linker.instantiate(&mut store, &module)?; + + let mut memory = instance.get_memory(&mut store, "memory").unwrap(); + let pages = memory.grow(&mut store, 20000).unwrap(); + println!("rust: pages: {}", pages); + // drop(memory); + + let main = instance + .get_typed_func::<(), ()>(&mut store, "_start") + .map_err(|e| e.to_string())?; + + let start_time = SystemTime::now().duration_since(UNIX_EPOCH).as_millis(); + println!("start_time: {:?}", start_time); + main.call(&mut store, ()).map_err(|e| e.to_string())?; + forget(store); + // let end_time = SystemTime::now().duration_since(UNIX_EPOCH).as_millis(); + Ok(().into()) +} + +#[no_mangle] +pub fn main() -> Result<()> { + let start_time = SystemTime::now().duration_since(UNIX_EPOCH).as_millis(); + println!("start_time: {:?}", start_time); + let my_id = args::get("id").unwrap(); + let sorter_num: u64 = args::get("sorter_num") + .expect("missing arg sorter_num") + .parse() + .unwrap_or_else(|_| panic!("bad arg, sorter_num={}", args::get("sorter_num").unwrap())); + let merger_num: u64 = args::get("merger_num") + .expect("missing arg merger_num") + .parse() + .unwrap_or_else(|_| panic!("bad arg, merger_num={}", args::get("merger_num").unwrap())); + func_body(my_id, sorter_num, merger_num) +} diff --git a/user/wasmtime_spliter/Cargo.lock b/user/wasmtime_spliter/Cargo.lock new file mode 100644 index 00000000..461c6e6a --- /dev/null +++ b/user/wasmtime_spliter/Cargo.lock @@ -0,0 +1,1194 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + +[[package]] +name = "arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cc" +version = "1.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4cbd4ab9fef358caa9c599eae3105af638ead5fb47a718315d8e03c852b9f0d" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cobs" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "cranelift-bforest" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6b33d7e757a887989eb18b35712b2a67d96171ec3149d1bfb657b29b7b367c" +dependencies = [ + "cranelift-entity", +] + +[[package]] +name = "cranelift-codegen" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9acf15cb22be42d07c3b57d7856329cb228b7315d385346149df2566ad5e4aa" +dependencies = [ + "bumpalo", + "cranelift-bforest", + "cranelift-codegen-meta", + "cranelift-codegen-shared", + "cranelift-control", + "cranelift-entity", + "cranelift-isle", + "gimli", + "hashbrown 0.14.5", + "log", + "regalloc2", + "rustc-hash", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e934d301392b73b3f8b0540391fb82465a0f179a3cee7c726482ac4727efcc97" +dependencies = [ + "cranelift-codegen-shared", +] + +[[package]] +name = "cranelift-codegen-shared" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb2a2566b3d54b854dfb288b3b187f6d3d17d6f762c92898207eba302931da" + +[[package]] +name = "cranelift-control" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0100f33b704cdacd01ad66ff41f8c5030d57cbff078e2a4e49ab1822591299fa" +dependencies = [ + "arbitrary", +] + +[[package]] +name = "cranelift-entity" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8cfdc315e5d18997093e040a8d234bea1ac1e118a716d3e30f40d449e78207b" +dependencies = [ + "serde", + "serde_derive", +] + +[[package]] +name = "cranelift-frontend" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f74b84f16af2e982b0c0c72233503d9d55cbfe3865dbe807ca28dc6642a28b5" +dependencies = [ + "cranelift-codegen", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-isle" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adf306d3dde705fb94bd48082f01d38c4ededc74293a4c007805f610bf08bc6e" + +[[package]] +name = "cranelift-native" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ea0ebdef7aff4a79bcbc8b6495f31315f16b3bf311152f472eaa8d679352581" +dependencies = [ + "cranelift-codegen", + "libc", + "target-lexicon", +] + +[[package]] +name = "cranelift-wasm" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d549108a1942065cdbac3bb96c2952afa0e1b9a3beff4b08c4308ac72257576d" +dependencies = [ + "cranelift-codegen", + "cranelift-entity", + "cranelift-frontend", + "itertools", + "log", + "smallvec", + "wasmparser", + "wasmtime-types", +] + +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "derive_more" +version = "0.99.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn 1.0.109", +] + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[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.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + +[[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 = "hash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" +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.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +dependencies = [ + "foldhash", +] + +[[package]] +name = "heapless" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" +dependencies = [ + "hash32", + "stable_deref_trait", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + +[[package]] +name = "indexmap" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +dependencies = [ + "equivalent", + "hashbrown 0.14.5", + "serde", +] + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + +[[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.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "linked_list_allocator" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286" +dependencies = [ + "spinning_top", +] + +[[package]] +name = "linux-raw-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1ad52afd8f9448cbbe722ae722849cc41f1d365e285cca386896352bc08e1a9" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mach2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" +dependencies = [ + "libc", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "memfd" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" +dependencies = [ + "rustix", +] + +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "ms_hostcall" +version = "0.1.0" +dependencies = [ + "bitflags", + "derive_more", + "thiserror-no-std", +] + +[[package]] +name = "ms_std" +version = "0.1.0" +dependencies = [ + "cfg-if", + "heapless", + "linked_list_allocator", + "ms_hostcall", + "ms_std_proc_macro", + "spin", + "thiserror-no-std", +] + +[[package]] +name = "ms_std_proc_macro" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "naked-function" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b8d5fca6ab1e6215b010aefd3b9ac5aae369dae0faea3a7f34f296cc9f719ac" +dependencies = [ + "cfg-if", + "naked-function-macro", +] + +[[package]] +name = "naked-function-macro" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b4123e70df5fe0bb370cff166ae453b9c5324a2cfc932c0f7e55498147a0475" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "object" +version = "0.36.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" +dependencies = [ + "crc32fast", + "hashbrown 0.15.0", + "indexmap", + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "postcard" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f7f0a8d620d71c457dd1d47df76bb18960378da56af4527aaa10f515eee732e" +dependencies = [ + "cobs", + "embedded-io 0.4.0", + "embedded-io 0.6.1", + "serde", +] + +[[package]] +name = "proc-macro2" +version = "1.0.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "psm" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa37f80ca58604976033fae9515a8a2989fc13797d953f7c04fb8fa36a11f205" +dependencies = [ + "cc", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[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 = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys 0.4.14", + "windows-sys", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "sc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "010e18bd3bfd1d45a7e666b236c78720df0d9a7698ebaa9c1c559961eb60a38b" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" + +[[package]] +name = "serde" +version = "1.0.193" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.193" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "serde_json" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0652c533506ad7a2e353cce269330d6afd8bdfb6d75e0ace5b35aacbd7b9e9" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "sjlj" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9b43efc387069aabdc27124a294337c7032a3cb62df0108d2578eff7f08e39" +dependencies = [ + "linux-raw-sys 0.2.2", + "naked-function", + "sc", +] + +[[package]] +name = "slice-group-by" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +dependencies = [ + "serde", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spinning_top" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b9eb1a2f4c41445a3a0ff9abc5221c5fcd28e1f13cd7c0397706f9ac938ddb0" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "target-lexicon" +version = "0.12.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" + +[[package]] +name = "thiserror" +version = "1.0.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e3de26b0965292219b4287ff031fcba86837900fe9cd2b34ea8ad893c0953d2" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "268026685b2be38d7103e9e507c938a1fcb3d7e6eb15e87870b617bf37b6d581" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "thiserror-impl-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58e6318948b519ba6dc2b442a6d0b904ebfb8d411a3ad3e07843615a72249758" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "thiserror-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3ad459d94dd517257cc96add8a43190ee620011bb6e6cdc82dafd97dfafafea" +dependencies = [ + "thiserror-impl-no-std", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasm-encoder" +version = "0.209.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4a05336882dae732ce6bd48b7e11fe597293cb72c13da4f35d7d5f8d53b2a7" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasmparser" +version = "0.209.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07035cc9a9b41e62d3bb3a3815a66ab87c993c06fe1cf6b2a3f2a18499d937db" +dependencies = [ + "ahash", + "bitflags", + "hashbrown 0.14.5", + "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", +] + +[[package]] +name = "wasmtime" +version = "22.0.0" +source = "git+https://gitee.com/tju-cloud-computing/wasmtime-as-lib?branch=master#fb45fb8dde6d068abb3ae78bfab78253c9654af5" +dependencies = [ + "anyhow", + "bumpalo", + "cc", + "cfg-if", + "encoding_rs", + "hashbrown 0.14.5", + "indexmap", + "libc", + "libm", + "log", + "mach2", + "memfd", + "memoffset", + "object", + "once_cell", + "paste", + "postcard", + "psm", + "rustix", + "semver", + "serde", + "serde_derive", + "smallvec", + "sptr", + "target-lexicon", + "wasmparser", + "wasmtime-asm-macros", + "wasmtime-component-macro", + "wasmtime-component-util", + "wasmtime-cranelift", + "wasmtime-environ", + "wasmtime-jit-icache-coherence", + "wasmtime-slab", + "wasmtime-versioned-export-macros", + "wasmtime-winch", + "windows-sys", +] + +[[package]] +name = "wasmtime-asm-macros" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d697d99c341d4a9ffb72f3af7a02124d233eeb59aee010f36d88e97cca553d5e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "wasmtime-component-macro" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b29b462b068e73b5b27fae092a27f47e5937cabf6b26be2779c978698a52feca" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn 2.0.39", + "wasmtime-component-util", + "wasmtime-wit-bindgen", + "wit-parser", +] + +[[package]] +name = "wasmtime-component-util" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d2912c53d9054984b380dfbd7579f9c3681b2a73b903a56bd71a1c4f175f1e" + +[[package]] +name = "wasmtime-cranelift" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3975deafea000457ba84355c7c0fce0372937204f77026510b7b454f28a3a65" +dependencies = [ + "anyhow", + "cfg-if", + "cranelift-codegen", + "cranelift-control", + "cranelift-entity", + "cranelift-frontend", + "cranelift-native", + "cranelift-wasm", + "gimli", + "log", + "object", + "target-lexicon", + "thiserror", + "wasmparser", + "wasmtime-environ", + "wasmtime-versioned-export-macros", +] + +[[package]] +name = "wasmtime-environ" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f444e900e848b884d8a8a2949b6f5b92af642a3e663ff8fbe78731143a55be61" +dependencies = [ + "anyhow", + "cranelift-entity", + "gimli", + "indexmap", + "log", + "object", + "postcard", + "serde", + "serde_derive", + "target-lexicon", + "wasm-encoder", + "wasmparser", + "wasmprinter", + "wasmtime-component-util", + "wasmtime-types", +] + +[[package]] +name = "wasmtime-jit-icache-coherence" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5afe2f0499542f9a4bcfa1b55bfdda803b6ade4e7c93c6b99e0f39dba44b0a91" +dependencies = [ + "anyhow", + "cfg-if", + "libc", + "windows-sys", +] + +[[package]] +name = "wasmtime-slab" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a7de1f2bec5bbb35d532e61c85c049dc84ae671df60492f90b954ecf21169e7" + +[[package]] +name = "wasmtime-types" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "412463e9000e14cf6856be48628d2213c20c153e29ffc22b036980c892ea6964" +dependencies = [ + "cranelift-entity", + "serde", + "serde_derive", + "smallvec", + "wasmparser", +] + +[[package]] +name = "wasmtime-versioned-export-macros" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de5a9bc4f44ceeb168e9e8e3be4e0b4beb9095b468479663a9e24c667e36826f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "wasmtime-winch" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed4db238a0241df2d15f79ad17b3a37a27f2ea6cb885894d81b42ae107544466" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "object", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", + "winch-codegen", +] + +[[package]] +name = "wasmtime-wit-bindgen" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc077306b38288262e5ba01d4b21532a6987416cdc0aedf04bb06c22a68fdc" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "wit-parser", +] + +[[package]] +name = "wasmtime_spliter" +version = "0.1.0" +dependencies = [ + "lazy_static", + "ms_hostcall", + "ms_std", + "spin", + "wasmtime_wasi_api", +] + +[[package]] +name = "wasmtime_wasi_api" +version = "0.1.0" +dependencies = [ + "hashbrown 0.14.5", + "lazy_static", + "ms_hostcall", + "ms_std", + "ms_std_proc_macro", + "sjlj", + "spin", + "wasmtime", +] + +[[package]] +name = "winch-codegen" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85c6915884e731b2db0d8cf08cb64474cb69221a161675fd3c135f91febc3daa" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "regalloc2", + "smallvec", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +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", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[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", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] diff --git a/user/wasmtime_spliter/Cargo.toml b/user/wasmtime_spliter/Cargo.toml new file mode 100644 index 00000000..37da7826 --- /dev/null +++ b/user/wasmtime_spliter/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "wasmtime_spliter" +version = "0.1.0" +edition = "2021" +build = "build.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +crate-type = ["staticlib"] + +[dependencies] +ms_std = { path = "../../ms_std", features = ["panic_def", "alloc_def"] } +ms_hostcall = { path = "../../ms_hostcall" } +wasmtime_wasi_api = { path = "../../wasmtime_wasi_api" } + +lazy_static = { version = "1.5.0", features = ["spin_no_std"] } +spin = "0.9.8" + +[features] +mpk = ["ms_std/mpk"] diff --git a/user/wasmtime_spliter/build.rs b/user/wasmtime_spliter/build.rs new file mode 100644 index 00000000..9fc09ddf --- /dev/null +++ b/user/wasmtime_spliter/build.rs @@ -0,0 +1,4 @@ +fn main() { + println!("cargo:rustc-link-lib=static={}", "wasmtime-platform"); + println!("cargo:rustc-link-search=native={}", "./"); +} diff --git a/user/wasmtime_spliter/build.sh b/user/wasmtime_spliter/build.sh new file mode 100755 index 00000000..de3288a2 --- /dev/null +++ b/user/wasmtime_spliter/build.sh @@ -0,0 +1,17 @@ +# $CPP spliter.cpp -o spliter.wasm -fno-exceptions -fno-rtti -ffast-math -funroll-loops -fomit-frame-pointer -Ofast +$CPP spliter_ori.cpp -o spliter.wasm # -fno-exceptions -fno-rtti -ffast-math -funroll-loops -fomit-frame-pointer -Ofast +# $CC spliter.c -o spliter.wasm +wasmtime compile --target x86_64-unknown-none -W threads=n,tail-call=n spliter.wasm +# wasmtime compile --target x86_64-unknown-none -W simd=y,threads=n,tail-call=n spliter.wasm + +cargo build --target x86_64-unknown-none --release && cc \ + -Wl,--gc-sections -nostdlib \ + -Wl,--whole-archive \ + target/x86_64-unknown-none/release/libwasmtime_spliter.a \ + -Wl,--no-whole-archive \ + -shared \ + -o target/x86_64-unknown-none/release/libwasmtime_spliter.so + + +ln -s /home/wyj/alloy_stack/mslibos/user/wasmtime_spliter/target/x86_64-unknown-none/release/libwasmtime_spliter.so /home/wyj/alloy_stack/mslibos/target/release/libwasmtime_spliter.so + diff --git a/user/wasmtime_spliter/libwasmtime-platform.a b/user/wasmtime_spliter/libwasmtime-platform.a new file mode 100644 index 00000000..beebf570 Binary files /dev/null and b/user/wasmtime_spliter/libwasmtime-platform.a differ diff --git a/user/wasmtime_spliter/libwasmtime-platform.o b/user/wasmtime_spliter/libwasmtime-platform.o new file mode 100644 index 00000000..90bbf6dd Binary files /dev/null and b/user/wasmtime_spliter/libwasmtime-platform.o differ diff --git a/user/wasmtime_spliter/spliter.c b/user/wasmtime_spliter/spliter.c new file mode 100644 index 00000000..1967fed1 --- /dev/null +++ b/user/wasmtime_spliter/spliter.c @@ -0,0 +1,131 @@ +#include +#include +#include + +__attribute__((import_module("env"), import_name("buffer_register"))) void buffer_register(void *slot_name, int name_size, void *buffer, int buffer_size); +__attribute__((import_module("env"), import_name("access_buffer"))) void access_buffer(void *slot_name, int name_size, void *buffer, int buffer_size); + +#define MAX_ARRAY_LENGTH 20000000 +#define MAX_BUFFER_SIZE 200000000 + +int sorter_array[MAX_ARRAY_LENGTH]; + +int main(int argc, char* argv[]) { + int id = atoi(argv[1]); + int sorter_num = atoi(argv[2]); + int merger_num = atoi(argv[3]); + printf("spliter_%d start!\n", id); + char slot_name[20]; + int bufferSize = MAX_BUFFER_SIZE; + char *ptr; + int num; + + // access pivot buffer + int pivot_array[10]; + int pivot_index = 0; + if (merger_num > 1) { + sprintf(slot_name, "pivot_%d", id); + char *pivot_buffer; + pivot_buffer = (char *)malloc(bufferSize * sizeof(char)); + if (pivot_buffer == NULL) { + perror("malloc error"); + return 1; + } + memset(pivot_buffer, 0, bufferSize * sizeof(char)); + pivot_buffer[0] = '\0'; // 初始化为空字符串 + access_buffer(slot_name, strlen(slot_name), pivot_buffer, bufferSize); + ptr = pivot_buffer; + printf("pivot_buffer: %s", pivot_buffer); + while (sscanf(ptr, "%d", &num) == 1) { + pivot_array[pivot_index] = num; + pivot_index++; + // 移动指针到下一个数字 + while (*ptr && *ptr != ' ') { + ptr++; + } + if (*ptr == ' ') { + ptr++; + } + } + free(pivot_buffer); + printf("spliter_%d pivot access finished!\n", id); + } + + // access sorter buffer + sprintf(slot_name, "sorter_%d", id); + char *sorter_buffer; + sorter_buffer = (char *)malloc(bufferSize * sizeof(char)); + if (sorter_buffer == NULL) { + perror("malloc error"); + return 1; + } + memset(sorter_buffer, 0, bufferSize * sizeof(char)); + sorter_buffer[0] = '\0'; // 初始化为空字符串 + access_buffer(slot_name, strlen(slot_name), sorter_buffer, bufferSize); + int sorter_index = 0; + ptr = sorter_buffer; + while (sscanf(ptr, "%d", &num) == 1) { + sorter_array[sorter_index] = num; + sorter_index++; + // 移动指针到下一个数字 + while (*ptr && *ptr != ' ') { + ptr++; + } + if (*ptr == ' ') { + ptr++; + } + } + free(sorter_buffer); + printf("spliter_%d sorter access finished!\n", id); + + // trans to merger + // int array[merger_num][MAX_ARRAY_LENGTH]; + int **array = (int **)malloc(merger_num * sizeof(int*)); + for (int i = 0; i < merger_num; i++) { + array[i] = (int *)malloc(MAX_ARRAY_LENGTH * sizeof(int)); + } + int array_index[merger_num]; + memset(array_index, 0, merger_num * sizeof(int)); + for (int i = 0; i < sorter_index; i++) { + int row = 0; + for (int j = 0; j < pivot_index; j++) { + if (sorter_array[i] >= pivot_array[j]) { + row++; + } else { + break; + } + } + array[row][array_index[row]] = sorter_array[i]; + array_index[row]++; + } + + for (int i = 0; i < merger_num; i++) { + char slot_name[20]; + sprintf(slot_name, "merger_%d_%d", id, i); + char *buffer; + buffer = (char *)malloc(bufferSize * sizeof(char)); + if (buffer == NULL) { + perror("malloc error"); + return 1; + } + memset(buffer, 0, bufferSize * sizeof(char)); + buffer[0] = '\0'; // 初始化为空字符串 + ptr = buffer; + for (int j = 0; j < array_index[i]; j++) { + char temp[12]; // 临时缓冲区,注意要足够大以容纳最大整数和一个空格 + snprintf(temp, sizeof(temp), "%d ", array[i][j]); // 将整数转换为字符串,并加上空格 + // strcat(buffer, temp); // 追加到 buffer + strncpy(ptr, temp, strlen(temp)); + ptr += strlen(temp); + } + // 去掉最后一个多余的空格 + // buffer[strlen(buffer) - 1] = '\0'; + *ptr++ = '\0'; + buffer_register(slot_name, strlen(slot_name), buffer, bufferSize); + free(buffer); + free(array[i]); + } + free(array_index); + printf("spliter_%d all finished!\n", id); + return 0; +} \ No newline at end of file diff --git a/user/wasmtime_spliter/spliter.cpp b/user/wasmtime_spliter/spliter.cpp new file mode 100644 index 00000000..e4ec5426 --- /dev/null +++ b/user/wasmtime_spliter/spliter.cpp @@ -0,0 +1,93 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +__attribute__((import_module("env"), import_name("buffer_register"))) void buffer_register(void *slot_name, int name_size, void *buffer, int buffer_size); +__attribute__((import_module("env"), import_name("access_buffer"))) void access_buffer(void *slot_name, int name_size, void *buffer, int buffer_size); + +#define MAX_ARRAY_LENGTH 8000000 +#define MAX_BUFFER_SIZE 80000000 + +int sorter_array[MAX_ARRAY_LENGTH]; + +int main(int argc, char* argv[]) { + int id = atoi(argv[1]); + int sorter_num = atoi(argv[2]); + int merger_num = atoi(argv[3]); + printf("spliter_%d start!\n", id); + string slot_name; + int bufferSize = MAX_BUFFER_SIZE; + + // access pivot buffer + int pivot_array[10]; + int pivot_index = 0; + if (merger_num > 1) { + slot_name = "pivot_" + to_string(id); + string pivot_buffer = string(MAX_BUFFER_SIZE, 0); + access_buffer((void*)slot_name.c_str(), slot_name.length(), (void*)pivot_buffer.c_str(), MAX_BUFFER_SIZE); + // printf("pivot_buffer: %s", pivot_buffer); + istringstream iss(pivot_buffer); + int num; + while (iss >> num) { + pivot_array[pivot_index++] = num; + } + printf("spliter_%d pivot access finished!\n", id); + } + + // access sorter buffer + slot_name = "sorter_" + to_string(id); + string sorter_buffer = string(MAX_BUFFER_SIZE, 0); + access_buffer((void*)slot_name.c_str(), slot_name.length(), (void*)sorter_buffer.c_str(), MAX_BUFFER_SIZE); + int sorter_index = 0; + istringstream iss(sorter_buffer); + int num; + while (iss >> num) { + sorter_array[sorter_index++] = num; + } + printf("access_sorter_index: %d\n", sorter_index); + printf("spliter_%d sorter access finished!\n", id); + + // trans to merger + // int array[merger_num][MAX_ARRAY_LENGTH]; + int **arrays = (int **)malloc(merger_num * sizeof(int*)); + for (int i = 0; i < merger_num; i++) { + arrays[i] = (int *)malloc(MAX_ARRAY_LENGTH * sizeof(int)); + } + int array_index[merger_num]; + memset(array_index, 0, merger_num * sizeof(int)); + for (int i = 0; i < sorter_index; i++) { + int row = 0; + for (int j = 0; j < pivot_index; j++) { + if (sorter_array[i] >= pivot_array[j]) { + row++; + } else { + break; + } + } + arrays[row][array_index[row]] = sorter_array[i]; + array_index[row]++; + } + printf("array_index[0]: %d\n", array_index[0]); + for (int i = 0; i < merger_num; i++) { + string slot_name = "merger_" + to_string(id) + "_" + to_string(i); + string buffer; + for (int j = 0; j < array_index[i]; j++) { + buffer.append(to_string(arrays[i][j]) + " "); + } + buffer.resize(MAX_BUFFER_SIZE, '\0'); + buffer_register((void*)slot_name.c_str(), slot_name.length(), (void*)buffer.c_str(), MAX_BUFFER_SIZE); + free(arrays[i]); + } + printf("spliter_%d all finished!\n", id); + return 0; +} \ No newline at end of file diff --git a/user/wasmtime_spliter/spliter.cwasm b/user/wasmtime_spliter/spliter.cwasm new file mode 100644 index 00000000..7cf54b10 Binary files /dev/null and b/user/wasmtime_spliter/spliter.cwasm differ diff --git a/user/wasmtime_spliter/spliter.wasm b/user/wasmtime_spliter/spliter.wasm new file mode 100755 index 00000000..e9e5492f Binary files /dev/null and b/user/wasmtime_spliter/spliter.wasm differ diff --git a/user/wasmtime_spliter/spliter_ori.cpp b/user/wasmtime_spliter/spliter_ori.cpp new file mode 100644 index 00000000..c7aa3d00 --- /dev/null +++ b/user/wasmtime_spliter/spliter_ori.cpp @@ -0,0 +1,168 @@ +#include +#include +#include +#include + +__attribute__((import_module("env"), import_name("buffer_register"))) void buffer_register(void *slot_name, int name_size, void *buffer, int buffer_size); +__attribute__((import_module("env"), import_name("access_buffer"))) void access_buffer(void *slot_name, int name_size, void *buffer, int buffer_size); + +// #define MAX_ARRAY_LENGTH 152221 +// #define MAX_BUFFER_SIZE 1024*1024+152221 + +#define MAX_ARRAY_LENGTH 3805441 +#define MAX_BUFFER_SIZE 25*1024*1024+3805441 + +// #define MAX_ARRAY_LENGTH 7611001 +// #define MAX_BUFFER_SIZE 50*1024*1024+7611001 + +int sorter_array[MAX_ARRAY_LENGTH]; + +void get_time(int num, int phase) { + timeval tv{}; + gettimeofday(&tv, nullptr); + printf("%lld.%06lld--%d--%d\n", tv.tv_sec, tv.tv_usec, num, phase); +} + +int main(int argc, char* argv[]) { + // get_time(); + int id = atoi(argv[1]); + int sorter_num = atoi(argv[2]); + int merger_num = atoi(argv[3]); + // get_time(); + // printf("spliter_%d start!\n", id); + char slot_name[20]; + int bufferSize = MAX_BUFFER_SIZE; + char *ptr; + int num; + + // access pivot buffer + int pivot_array[10]; + int pivot_index = 0; + int time_num = 5; + if (merger_num > 1) { + sprintf(slot_name, "pivot_%d", id); + char *pivot_buffer; + pivot_buffer = (char *)malloc(bufferSize * sizeof(char)); + memset(pivot_buffer, 0, bufferSize * sizeof(char)); + pivot_buffer[0] = '\0'; // 初始化为空字符串 + if (id == 0) + get_time(time_num, 0); + access_buffer(slot_name, strlen(slot_name), pivot_buffer, bufferSize); + if (id == 0) + get_time(time_num, 1); + time_num++; + ptr = pivot_buffer; + // printf("pivot_buffer: %s", pivot_buffer); + while (sscanf(ptr, "%d", &num) == 1) { + pivot_array[pivot_index] = num; + pivot_index++; + // 移动指针到下一个数字 + while (*ptr && *ptr != ' ') { + ptr++; + } + if (*ptr == ' ') { + ptr++; + } + } + free(pivot_buffer); + // printf("spliter_%d pivot access finished!\n", id); + } + + // access sorter buffer + sprintf(slot_name, "sorter_%d", id); + char *sorter_buffer; + sorter_buffer = (char *)malloc(bufferSize * sizeof(char)); + memset(sorter_buffer, 0, bufferSize * sizeof(char)); + sorter_buffer[0] = '\0'; // 初始化为空字符串 + // get_time(); + if (id == 0) + get_time(8, 0); + access_buffer(slot_name, strlen(slot_name), sorter_buffer, bufferSize); + if (id == 0) + get_time(8, 1); + // get_time(); + int sorter_index = 0; + ptr = sorter_buffer; + // get_time(); + while (sscanf(ptr, "%d", &num) == 1) { + sorter_array[sorter_index] = num; + sorter_index++; + // 移动指针到下一个数字 + while (*ptr && *ptr != ' ') { + ptr++; + } + if (*ptr == ' ') { + ptr++; + } + } + // free(ptr); + printf("sorter_index: %d\n", sorter_index); + // get_time(); + // free(sorter_buffer); + // printf("spliter_%d sorter access finished!\n", id); + + // trans to merger + // int array[merger_num][MAX_ARRAY_LENGTH]; + // get_time(); + int **array = (int **)malloc(merger_num * sizeof(int*)); + for (int i = 0; i < merger_num; i++) { + array[i] = (int *)malloc(MAX_ARRAY_LENGTH * sizeof(int)); + } + int array_index[merger_num]; + memset(array_index, 0, merger_num * sizeof(int)); + for (int i = 0; i < sorter_index; i++) { + int row = 0; + for (int j = 0; j < pivot_index; j++) { + if (sorter_array[i] >= pivot_array[j]) { + row++; + } else { + break; + } + } + array[row][array_index[row]] = sorter_array[i]; + array_index[row]++; + } + printf("merger_index_before_register: %d\n", array_index[0]); + // get_time(); + // get_time(); + printf("array0: %d :%d\n", (void*)(array_index), *array_index); + time_num = 9; + for (int i = 0; i < merger_num; i++) { + printf("i(%d) = %d array0: %d :%d\n", (void*)&i, i, (void*)(array_index), *array_index); + char slot_name[20]; + sprintf(slot_name, "merger_%d_%d", id, i); + char *merger_buffer = (char *)malloc(bufferSize * sizeof(char)); + // memset(merger_buffer, 0, bufferSize * sizeof(char)); + merger_buffer[0] = '\0'; // 初始化为空字符串 + char *merger_ptr = merger_buffer; + printf("array0: %d :%d\n", (void*)(array_index), *array_index); + printf("i: %d; array_index_before_for: %d\n", i, array_index[i]); + printf("%d: %d\n", (void*)(array_index+1), *(array_index+1)); + printf("array_index[0]: %d\n", array_index[0]); + for (int j = 0; j < array_index[i]; j++) { + char temp[12]; // 临时缓冲区,注意要足够大以容纳最大整数和一个空格 + snprintf(temp, sizeof(temp), "%d ", array[i][j]); // 将整数转换为字符串,并加上空格 + // printf("array[i][j]: %d\n", array[i][j]); + // strcat(buffer, temp); // 追加到 buffer + strncpy(merger_ptr, temp, strlen(temp)); + merger_ptr += strlen(temp); + } + // 去掉最后一个多余的空格 + // buffer[strlen(buffer) - 1] = '\0'; + *merger_ptr++ = '\0'; + if (id == 0) + get_time(time_num, 0); + buffer_register(slot_name, strlen(slot_name), merger_buffer, MAX_BUFFER_SIZE); + if (id == 0) + get_time(time_num, 1); + time_num++; + // buffer_register(slot_name, strlen(slot_name), buffer, bufferSize); + // free(buffer); + // free(array[i]); + } + // get_time(); + // free(array_index); + // printf("spliter_%d all finished!\n", id); + // get_time(); + return 0; +} \ No newline at end of file diff --git a/user/wasmtime_spliter/src/lib.rs b/user/wasmtime_spliter/src/lib.rs new file mode 100644 index 00000000..5e153eaa --- /dev/null +++ b/user/wasmtime_spliter/src/lib.rs @@ -0,0 +1,72 @@ +#![no_std] + +extern crate alloc; +use core::mem::forget; + +use alloc::{string::{String, ToString}, vec::Vec}; +use spin::Mutex; + +use ms_hostcall::types::{OpenFlags, OpenMode}; +use ms_std::{agent::FaaSFuncResult as Result, args, println, libos::libos}; + +use wasmtime_wasi_api::{wasmtime, LibosCtx}; +use wasmtime::Store; + +static CWASM: &[u8] = include_bytes!("../spliter.cwasm"); + +static INIT_LOCK: Mutex<()> = Mutex::new(()); + +lazy_static::lazy_static! { + static ref MUST_OPEN_ROOT: bool = { + libos!(open("/", OpenFlags::empty(), OpenMode::RD)).unwrap(); + true + }; +} + +fn func_body(my_id: &str, sorter_num: u64, merger_num: u64) -> Result<()> { + // #[cfg(feature = "log")] + println!("rust: my_id: {:?}, sorter_num: {:?}, merger_num: {:?}", my_id, sorter_num, merger_num); + + let wasi_args: Vec = Vec::from([ + "fake system path!".to_string(), + my_id.to_string(), + sorter_num.to_string(), + merger_num.to_string(), + ]); + wasmtime_wasi_api::set_wasi_args(my_id, wasi_args); + + let _open_root = *MUST_OPEN_ROOT; + + let lock = INIT_LOCK.lock(); + let (engine, module, linker) = wasmtime_wasi_api::build_wasm(CWASM); + drop(lock); + + let mut store = Store::new(&engine, LibosCtx{id: my_id.to_string()}); + let instance = linker.instantiate(&mut store, &module)?; + + let mut memory = instance.get_memory(&mut store, "memory").unwrap(); + let pages = memory.grow(&mut store, 20000).unwrap(); + + let main = instance + .get_typed_func::<(), ()>(&mut store, "_start") + .map_err(|e| e.to_string())?; + + main.call(&mut store, ()).map_err(|e| e.to_string())?; + forget(store); + Ok(().into()) +} + +#[no_mangle] +pub fn main() -> Result<()> { + let my_id = args::get("id").unwrap(); + let sorter_num: u64 = args::get("sorter_num") + .expect("missing arg sorter_num") + .parse() + .unwrap_or_else(|_| panic!("bad arg, sorter_num={}", args::get("sorter_num").unwrap())); + let merger_num: u64 = args::get("merger_num") + .expect("missing arg merger_num") + .parse() + .unwrap_or_else(|_| panic!("bad arg, merger_num={}", args::get("merger_num").unwrap())); + + func_body(my_id, sorter_num, merger_num) +} diff --git a/user/wasmtime_trans_data/Cargo.lock b/user/wasmtime_trans_data/Cargo.lock new file mode 100644 index 00000000..b1b79911 --- /dev/null +++ b/user/wasmtime_trans_data/Cargo.lock @@ -0,0 +1,1195 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + +[[package]] +name = "arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cc" +version = "1.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cobs" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "cranelift-bforest" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6b33d7e757a887989eb18b35712b2a67d96171ec3149d1bfb657b29b7b367c" +dependencies = [ + "cranelift-entity", +] + +[[package]] +name = "cranelift-codegen" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9acf15cb22be42d07c3b57d7856329cb228b7315d385346149df2566ad5e4aa" +dependencies = [ + "bumpalo", + "cranelift-bforest", + "cranelift-codegen-meta", + "cranelift-codegen-shared", + "cranelift-control", + "cranelift-entity", + "cranelift-isle", + "gimli", + "hashbrown 0.14.5", + "log", + "regalloc2", + "rustc-hash", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e934d301392b73b3f8b0540391fb82465a0f179a3cee7c726482ac4727efcc97" +dependencies = [ + "cranelift-codegen-shared", +] + +[[package]] +name = "cranelift-codegen-shared" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb2a2566b3d54b854dfb288b3b187f6d3d17d6f762c92898207eba302931da" + +[[package]] +name = "cranelift-control" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0100f33b704cdacd01ad66ff41f8c5030d57cbff078e2a4e49ab1822591299fa" +dependencies = [ + "arbitrary", +] + +[[package]] +name = "cranelift-entity" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8cfdc315e5d18997093e040a8d234bea1ac1e118a716d3e30f40d449e78207b" +dependencies = [ + "serde", + "serde_derive", +] + +[[package]] +name = "cranelift-frontend" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f74b84f16af2e982b0c0c72233503d9d55cbfe3865dbe807ca28dc6642a28b5" +dependencies = [ + "cranelift-codegen", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-isle" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adf306d3dde705fb94bd48082f01d38c4ededc74293a4c007805f610bf08bc6e" + +[[package]] +name = "cranelift-native" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ea0ebdef7aff4a79bcbc8b6495f31315f16b3bf311152f472eaa8d679352581" +dependencies = [ + "cranelift-codegen", + "libc", + "target-lexicon", +] + +[[package]] +name = "cranelift-wasm" +version = "0.109.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d549108a1942065cdbac3bb96c2952afa0e1b9a3beff4b08c4308ac72257576d" +dependencies = [ + "cranelift-codegen", + "cranelift-entity", + "cranelift-frontend", + "itertools", + "log", + "smallvec", + "wasmparser", + "wasmtime-types", +] + +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn 2.0.79", +] + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[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.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + +[[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 = "hash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" +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.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +dependencies = [ + "foldhash", +] + +[[package]] +name = "heapless" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" +dependencies = [ + "hash32", + "stable_deref_trait", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + +[[package]] +name = "indexmap" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +dependencies = [ + "equivalent", + "hashbrown 0.15.0", + "serde", +] + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + +[[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.159" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "linked_list_allocator" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286" +dependencies = [ + "spinning_top", +] + +[[package]] +name = "linux-raw-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1ad52afd8f9448cbbe722ae722849cc41f1d365e285cca386896352bc08e1a9" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mach2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" +dependencies = [ + "libc", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "memfd" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" +dependencies = [ + "rustix", +] + +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "ms_hostcall" +version = "0.1.0" +dependencies = [ + "bitflags", + "derive_more", + "thiserror-no-std", +] + +[[package]] +name = "ms_std" +version = "0.1.0" +dependencies = [ + "cfg-if", + "heapless", + "linked_list_allocator", + "ms_hostcall", + "ms_std_proc_macro", + "spin", + "thiserror-no-std", +] + +[[package]] +name = "ms_std_proc_macro" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "naked-function" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b8d5fca6ab1e6215b010aefd3b9ac5aae369dae0faea3a7f34f296cc9f719ac" +dependencies = [ + "cfg-if", + "naked-function-macro", +] + +[[package]] +name = "naked-function-macro" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b4123e70df5fe0bb370cff166ae453b9c5324a2cfc932c0f7e55498147a0475" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "object" +version = "0.36.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" +dependencies = [ + "crc32fast", + "hashbrown 0.15.0", + "indexmap", + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "postcard" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f7f0a8d620d71c457dd1d47df76bb18960378da56af4527aaa10f515eee732e" +dependencies = [ + "cobs", + "embedded-io 0.4.0", + "embedded-io 0.6.1", + "serde", +] + +[[package]] +name = "proc-macro2" +version = "1.0.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "psm" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa37f80ca58604976033fae9515a8a2989fc13797d953f7c04fb8fa36a11f205" +dependencies = [ + "cc", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[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 = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys 0.4.14", + "windows-sys", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "sc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "010e18bd3bfd1d45a7e666b236c78720df0d9a7698ebaa9c1c559961eb60a38b" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "sjlj" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9b43efc387069aabdc27124a294337c7032a3cb62df0108d2578eff7f08e39" +dependencies = [ + "linux-raw-sys 0.2.2", + "naked-function", + "sc", +] + +[[package]] +name = "slice-group-by" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +dependencies = [ + "serde", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spinning_top" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b9eb1a2f4c41445a3a0ff9abc5221c5fcd28e1f13cd7c0397706f9ac938ddb0" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "target-lexicon" +version = "0.12.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" + +[[package]] +name = "thiserror" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "thiserror-impl-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58e6318948b519ba6dc2b442a6d0b904ebfb8d411a3ad3e07843615a72249758" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "thiserror-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3ad459d94dd517257cc96add8a43190ee620011bb6e6cdc82dafd97dfafafea" +dependencies = [ + "thiserror-impl-no-std", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasm-encoder" +version = "0.209.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4a05336882dae732ce6bd48b7e11fe597293cb72c13da4f35d7d5f8d53b2a7" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasmparser" +version = "0.209.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07035cc9a9b41e62d3bb3a3815a66ab87c993c06fe1cf6b2a3f2a18499d937db" +dependencies = [ + "ahash", + "bitflags", + "hashbrown 0.14.5", + "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", +] + +[[package]] +name = "wasmtime" +version = "22.0.0" +source = "git+https://gitee.com/tju-cloud-computing/wasmtime-as-lib?branch=master#fb45fb8dde6d068abb3ae78bfab78253c9654af5" +dependencies = [ + "anyhow", + "bumpalo", + "cc", + "cfg-if", + "encoding_rs", + "hashbrown 0.14.5", + "indexmap", + "libc", + "libm", + "log", + "mach2", + "memfd", + "memoffset", + "object", + "once_cell", + "paste", + "postcard", + "psm", + "rustix", + "semver", + "serde", + "serde_derive", + "smallvec", + "sptr", + "target-lexicon", + "wasmparser", + "wasmtime-asm-macros", + "wasmtime-component-macro", + "wasmtime-component-util", + "wasmtime-cranelift", + "wasmtime-environ", + "wasmtime-jit-icache-coherence", + "wasmtime-slab", + "wasmtime-versioned-export-macros", + "wasmtime-winch", + "windows-sys", +] + +[[package]] +name = "wasmtime-asm-macros" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d697d99c341d4a9ffb72f3af7a02124d233eeb59aee010f36d88e97cca553d5e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "wasmtime-component-macro" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b29b462b068e73b5b27fae092a27f47e5937cabf6b26be2779c978698a52feca" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn 2.0.79", + "wasmtime-component-util", + "wasmtime-wit-bindgen", + "wit-parser", +] + +[[package]] +name = "wasmtime-component-util" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d2912c53d9054984b380dfbd7579f9c3681b2a73b903a56bd71a1c4f175f1e" + +[[package]] +name = "wasmtime-cranelift" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3975deafea000457ba84355c7c0fce0372937204f77026510b7b454f28a3a65" +dependencies = [ + "anyhow", + "cfg-if", + "cranelift-codegen", + "cranelift-control", + "cranelift-entity", + "cranelift-frontend", + "cranelift-native", + "cranelift-wasm", + "gimli", + "log", + "object", + "target-lexicon", + "thiserror", + "wasmparser", + "wasmtime-environ", + "wasmtime-versioned-export-macros", +] + +[[package]] +name = "wasmtime-environ" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f444e900e848b884d8a8a2949b6f5b92af642a3e663ff8fbe78731143a55be61" +dependencies = [ + "anyhow", + "cranelift-entity", + "gimli", + "indexmap", + "log", + "object", + "postcard", + "serde", + "serde_derive", + "target-lexicon", + "wasm-encoder", + "wasmparser", + "wasmprinter", + "wasmtime-component-util", + "wasmtime-types", +] + +[[package]] +name = "wasmtime-jit-icache-coherence" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5afe2f0499542f9a4bcfa1b55bfdda803b6ade4e7c93c6b99e0f39dba44b0a91" +dependencies = [ + "anyhow", + "cfg-if", + "libc", + "windows-sys", +] + +[[package]] +name = "wasmtime-slab" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a7de1f2bec5bbb35d532e61c85c049dc84ae671df60492f90b954ecf21169e7" + +[[package]] +name = "wasmtime-types" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "412463e9000e14cf6856be48628d2213c20c153e29ffc22b036980c892ea6964" +dependencies = [ + "cranelift-entity", + "serde", + "serde_derive", + "smallvec", + "wasmparser", +] + +[[package]] +name = "wasmtime-versioned-export-macros" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de5a9bc4f44ceeb168e9e8e3be4e0b4beb9095b468479663a9e24c667e36826f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "wasmtime-winch" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed4db238a0241df2d15f79ad17b3a37a27f2ea6cb885894d81b42ae107544466" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "object", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", + "winch-codegen", +] + +[[package]] +name = "wasmtime-wit-bindgen" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc077306b38288262e5ba01d4b21532a6987416cdc0aedf04bb06c22a68fdc" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "wit-parser", +] + +[[package]] +name = "wasmtime_trans_data" +version = "0.1.0" +dependencies = [ + "lazy_static", + "ms_hostcall", + "ms_std", + "spin", + "wasmtime_wasi_api", +] + +[[package]] +name = "wasmtime_wasi_api" +version = "0.1.0" +dependencies = [ + "hashbrown 0.14.5", + "lazy_static", + "ms_hostcall", + "ms_std", + "ms_std_proc_macro", + "sjlj", + "spin", + "wasmtime", +] + +[[package]] +name = "winch-codegen" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85c6915884e731b2db0d8cf08cb64474cb69221a161675fd3c135f91febc3daa" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "regalloc2", + "smallvec", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +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", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[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", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] diff --git a/user/wasmtime_trans_data/Cargo.toml b/user/wasmtime_trans_data/Cargo.toml new file mode 100644 index 00000000..79f49237 --- /dev/null +++ b/user/wasmtime_trans_data/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "wasmtime_trans_data" +version = "0.1.0" +edition = "2021" +build = "build.rs" +# build = "../../build_wasm.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +crate-type = ["staticlib"] + +[dependencies] +ms_std = { path = "../../ms_std", features = ["panic_def", "alloc_def"] } +ms_hostcall = { path = "../../ms_hostcall", features = ["signal"] } + +wasmtime_wasi_api = { path = "../../wasmtime_wasi_api" } + +lazy_static = { version = "1.5.0", features = ["spin_no_std"] } +spin = "0.9.8" + +[features] +mpk = ["ms_std/mpk"] diff --git a/user/wasmtime_trans_data/build.rs b/user/wasmtime_trans_data/build.rs new file mode 100644 index 00000000..9fc09ddf --- /dev/null +++ b/user/wasmtime_trans_data/build.rs @@ -0,0 +1,4 @@ +fn main() { + println!("cargo:rustc-link-lib=static={}", "wasmtime-platform"); + println!("cargo:rustc-link-search=native={}", "./"); +} diff --git a/user/wasmtime_trans_data/build.sh b/user/wasmtime_trans_data/build.sh new file mode 100755 index 00000000..53981be9 --- /dev/null +++ b/user/wasmtime_trans_data/build.sh @@ -0,0 +1,14 @@ +$CPP trans_data.cpp -o trans_data.wasm -fno-exceptions -fno-rtti -ffast-math -funroll-loops -fomit-frame-pointer -Ofast +# $CPP trans_data.cpp -o trans_data.wasm + +wasmtime compile --target x86_64-unknown-none -W threads=n,tail-call=n trans_data.wasm + +cargo build --target x86_64-unknown-none --release && cc \ + -Wl,--gc-sections -nostdlib \ + -Wl,--whole-archive \ + target/x86_64-unknown-none/release/libwasmtime_trans_data.a \ + -Wl,--no-whole-archive \ + -shared \ + -o target/x86_64-unknown-none/release/libwasmtime_trans_data.so + +ln -s /home/wyj/alloy_stack/mslibos/user/wasmtime_trans_data/target/x86_64-unknown-none/release/libwasmtime_trans_data.so /home/wyj/alloy_stack/mslibos/target/release/libwasmtime_trans_data.so diff --git a/user/wasmtime_trans_data/libwasmtime-platform.a b/user/wasmtime_trans_data/libwasmtime-platform.a new file mode 100644 index 00000000..beebf570 Binary files /dev/null and b/user/wasmtime_trans_data/libwasmtime-platform.a differ diff --git a/user/wasmtime_trans_data/libwasmtime-platform.o b/user/wasmtime_trans_data/libwasmtime-platform.o new file mode 100644 index 00000000..90bbf6dd Binary files /dev/null and b/user/wasmtime_trans_data/libwasmtime-platform.o differ diff --git a/user/wasmtime_trans_data/src/lib.rs b/user/wasmtime_trans_data/src/lib.rs new file mode 100644 index 00000000..45e7db9c --- /dev/null +++ b/user/wasmtime_trans_data/src/lib.rs @@ -0,0 +1,54 @@ +#![no_std] + +extern crate alloc; +use core::mem::forget; + +use alloc::{string::{String, ToString}, vec::Vec}; +use spin::Mutex; + +use ms_hostcall::types::{OpenFlags, OpenMode}; +use ms_std::{agent::FaaSFuncResult as Result, args, println, libos::libos, time::{SystemTime, UNIX_EPOCH}}; + + +use wasmtime_wasi_api::{wasmtime, LibosCtx}; +use wasmtime::Store; + +static CWASM: &[u8] = include_bytes!("../trans_data.cwasm"); + +static INIT_LOCK: Mutex<()> = Mutex::new(()); + +lazy_static::lazy_static! { + static ref MUST_OPEN_ROOT: bool = { + libos!(open("/", OpenFlags::empty(), OpenMode::RD)).unwrap(); + true + }; +} + +fn func_body() -> Result<()> { + let _open_root = *MUST_OPEN_ROOT; + + let lock = INIT_LOCK.lock(); + let (engine, module, linker) = wasmtime_wasi_api::build_wasm(CWASM); + drop(lock); + + let mut store = Store::new(&engine, LibosCtx{id: "0".to_string()}); + let instance = linker.instantiate(&mut store, &module)?; + + let mut memory = instance.get_memory(&mut store, "memory").unwrap(); + let pages = memory.grow(&mut store, 20000).unwrap(); + println!("rust: pages: {}", pages); + + let main = instance + .get_typed_func::<(), ()>(&mut store, "_start") + .map_err(|e| e.to_string())?; + + main.call(store, ()).map_err(|e| e.to_string())?; + + Ok(().into()) +} + +#[no_mangle] +pub fn main() -> Result<()> { + println!("start_time: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + func_body() +} diff --git a/user/wasmtime_trans_data/trans_data.cpp b/user/wasmtime_trans_data/trans_data.cpp new file mode 100644 index 00000000..95b9fd3d --- /dev/null +++ b/user/wasmtime_trans_data/trans_data.cpp @@ -0,0 +1,76 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +#define MAX_BUFFER_SIZE 1024 * 64 + + +__attribute__((import_module("env"), import_name("buffer_register"))) void buffer_register(void *slot_name, int name_size, void *buffer, int buffer_size); +__attribute__((import_module("env"), import_name("access_buffer"))) void access_buffer(void *slot_name, int name_size, void *buffer, int buffer_size); + + +void get_time() { + timeval tv{}; + gettimeofday(&tv, nullptr); + printf("%lld.%06lld\n", tv.tv_sec, tv.tv_usec); +} + +int arrays[100000000]; + +int main() { + // get_time(); + // string slot_name = "tmp"; + // // string buffer(MAX_BUFFER_SIZE, '0'); + // vector buffer(MAX_BUFFER_SIZE, 0); + // buffer_register((void*)slot_name.c_str(), slot_name.length(), (void*)buffer.data(), MAX_BUFFER_SIZE); + + // get_time(); + // access_buffer((void*)slot_name.c_str(), slot_name.length(), (void*)buffer.data(), MAX_BUFFER_SIZE); + // get_time(); + + + //breakdown test + // get_time(); + // const int N = 1e9; + // unsigned int a = 0, b = 1; + // for (int i = 1; i <= N; i++) { + // a += b; + // b *= 2; + // } + // get_time(); + // printf("a: %u\n", a); + + // for (int i = 0; i < 100000000; i++) { + // arrays[i] = 100000000 - i; + // } + // get_time(); + // sort(arrays, arrays+100000000); + // get_time(); + + srand(42); + + get_time(); + for (int i = 0; i < 100000000; i++) { + arrays[i] = rand(); + } + get_time(); + sort(arrays, arrays + 100000000); + get_time(); + printf("%d\n", arrays[9999999]); + // vector arrays; + // get_time(); + // for (int i = 0; i < 100000000; i++) { + // arrays.push_back(1); + // } + // get_time(); + return 0; +} \ No newline at end of file diff --git a/user/wasmtime_trans_data/trans_data.cwasm b/user/wasmtime_trans_data/trans_data.cwasm new file mode 100644 index 00000000..d26828c0 Binary files /dev/null and b/user/wasmtime_trans_data/trans_data.cwasm differ diff --git a/user/wasmtime_trans_data/trans_data.wasm b/user/wasmtime_trans_data/trans_data.wasm new file mode 100755 index 00000000..7b9d015b Binary files /dev/null and b/user/wasmtime_trans_data/trans_data.wasm differ diff --git a/wasi_api/Cargo.toml b/wasi_api/Cargo.toml index 76ae9599..fc89c2ab 100644 --- a/wasi_api/Cargo.toml +++ b/wasi_api/Cargo.toml @@ -26,4 +26,4 @@ tinywasm = { git = "https://github.com/anti-entropy123/tinywasm", branch = "mast [features] log = [] -#default = ["log"] +# default = ["log"] diff --git a/wasi_api/src/lib.rs b/wasi_api/src/lib.rs index c57567f1..6c45b5ad 100644 --- a/wasi_api/src/lib.rs +++ b/wasi_api/src/lib.rs @@ -121,11 +121,6 @@ pub fn import_all() -> tinywasm::Result { "fd_read", Extern::typed_func(wasi::fd_read), )? - .define( - "wasi_snapshot_preview1", - "fd_read", - Extern::typed_func(wasi::fd_read), - )? .define( "wasi_snapshot_preview1", "fd_readdir", diff --git a/wasi_api/src/wasi.rs b/wasi_api/src/wasi.rs index d9a88830..4920dfd7 100644 --- a/wasi_api/src/wasi.rs +++ b/wasi_api/src/wasi.rs @@ -1,14 +1,17 @@ extern crate alloc; -use core::{mem::forget, slice}; +#[cfg(feature = "log")] +use ms_std::println; +#[cfg(feature = "log")] +use alloc::format; use alloc::{borrow::ToOwned, string::String, vec::Vec}; -use spin::{Mutex, MutexGuard}; +use core::{mem::forget, slice}; use hashbrown::HashMap; +use spin::{Mutex, MutexGuard}; use ms_hostcall::{fdtab::FdtabResult, types::{OpenFlags, OpenMode, Stat, Fd, DirEntry}}; use ms_std::{ libos::libos, - println, time::{SystemTime, UNIX_EPOCH}, }; use tinywasm::{FuncContext, MemoryStringExt}; @@ -684,7 +687,6 @@ pub fn fd_readdir(mut ctx: FuncContext<'_>, args: (i32, i32, i32, i64, i32)) -> Ok(0) } - pub fn fd_seek(mut _ctx: FuncContext<'_>, _args: (i32, i64, i32, i32)) -> tinywasm::Result { #[cfg(feature = "log")] { @@ -1106,4 +1108,4 @@ pub fn sock_shutdown(_: FuncContext, _args: (i32, i32)) -> tinywasm::Result } Ok(0) -} \ No newline at end of file +} diff --git a/wasmtime_wasi_api/Cargo.toml b/wasmtime_wasi_api/Cargo.toml new file mode 100644 index 00000000..6b73f0b9 --- /dev/null +++ b/wasmtime_wasi_api/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "wasmtime_wasi_api" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +ms_std = { path = "../ms_std", default-features = false } +ms_hostcall = { path = "../ms_hostcall", default-features = false, features = ["signal"] } +ms_std_proc_macro = { path = "../ms_std_proc_macro" } +spin = "0.9.8" +hashbrown = { version = "0.14", default-features = false, features = ["ahash"] } +lazy_static = { version = "1.4.0", features = ["spin_no_std"] } +sjlj = { version = "0.1.3" } + +# wasmtime = { path = "../wasmtime-as-lib", default-features = false, features = [ +wasmtime = { git = "https://gitee.com/tju-cloud-computing/wasmtime-as-lib", branch = "master", default-features = false, features = [ + "runtime", + "gc", + "component-model", +] } + +[features] +log = [] + +# default = ["log"] diff --git a/wasmtime_wasi_api/src/capis.rs b/wasmtime_wasi_api/src/capis.rs new file mode 100644 index 00000000..19d39f3b --- /dev/null +++ b/wasmtime_wasi_api/src/capis.rs @@ -0,0 +1,332 @@ +#![allow(non_camel_case_types)] + +extern crate sjlj; +use core::ptr::{null, null_mut}; + +use ms_hostcall::{mm::{MMResult, ProtFlags}, signal::{SigAction, SigInfo, Sigset, Ucontext}}; +use ms_std::libos::libos; +use ms_std::println; +use sjlj::{JumpBuf, longjmp, setjmp}; + +// Flags to either `wasmtime_mmap_{new,remap}` or `wasmtime_mprotect`. + +/// Indicates that the memory region should be readable. +pub const WASMTIME_PROT_READ: u32 = 1 << 0; +/// Indicates that the memory region should be writable. +pub const WASMTIME_PROT_WRITE: u32 = 1 << 1; +/// Indicates that the memory region should be executable. +pub const WASMTIME_PROT_EXEC: u32 = 1 << 2; + +pub use WASMTIME_PROT_EXEC as PROT_EXEC; +pub use WASMTIME_PROT_READ as PROT_READ; +pub use WASMTIME_PROT_WRITE as PROT_WRITE; + +/// 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. +pub type wasmtime_trap_handler_t = + extern "C" fn(ip: usize, fp: usize, has_faulting_addr: bool, faulting_addr: usize); + +extern "C" fn null_trap_handler( + _ip: usize, + _fp: usize, + _has_faulting_addr: bool, + _faulting_addr: usize, +) { + // no-op +} + +static mut g_handler: wasmtime_trap_handler_t = null_trap_handler; +/// Abstract pointer type used in the `wasmtime_memory_image_*` APIs which +/// is defined by the embedder. +pub enum wasmtime_memory_image {} + +pub static mut WASMTIME_TLS: *mut u8 = 0 as *mut u8; + +/// 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 fn wasmtime_mmap_new(size: usize, prot_flags: u32, ret: &mut *mut u8) -> i32 { + let prot_flags: ProtFlags = ProtFlags::from_bits(prot_flags).unwrap(); + let addr: MMResult = libos!(mmap(0, size, prot_flags, u32::MAX)); + if let Err(e) = addr { + println!("[wasmtime] mmap_new failed: {:?}", e); + return -1; + } + *ret = addr.unwrap() as *mut u8; + 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: u32) -> i32 { + let prot_flags: ProtFlags = ProtFlags::from_bits(prot_flags).unwrap(); + let addr: MMResult = libos!(mmap(addr as usize, size, prot_flags, addr as u32)); + if let Err(e) = addr { + println!("[wasmtime] mmap_remap failed: {:?}", e); + return -1; + } + 0 +} + +/// 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 umap_data: &mut [u8] = unsafe { core::slice::from_raw_parts_mut(ptr, size) }; + if let Err(e) = libos!(munmap(umap_data, false)) { + println!("[wasmtime] munmap failed: {:?}", e); + return -1; + } + 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: u32) -> i32 { + let prot_flags: ProtFlags = ProtFlags::from_bits(prot_flags).unwrap(); + if let Err(e) = libos!(mprotect(ptr as usize, size, prot_flags)) { + println!("[wasmtime] mprotect failed: {:?}", e); + return -1; + } + 0 +} + +/// Returns the page size, in bytes, of the current system. +#[no_mangle] +pub extern "C" fn wasmtime_page_size() -> usize { + 4096 +} + +/// 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 { + unsafe { + let mut buf = JumpBuf::new(); + if setjmp(&mut buf) != 0 { + return 0; + } + *jmp_buf = &buf as *const JumpBuf as *const u8; + } + 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 as *const JumpBuf), 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. +/// + +const SA_SIGINFO: u32 = 0x00000008; +const SA_NODEFER: u32 = 0x40000000; +const SIGILL: i32 = 4; +const SIGSEGV: i32 = 11; +const SIGFPE: i32 = 8; + +/// Returns 0 on success and an error code on failure. +fn handle_signal(sig: i32, info: *mut SigInfo, ctx: *mut Ucontext) { + unsafe { + if g_handler == null_trap_handler { + return; + } + let ip = (*ctx).uc_mcontext.gregs[16]; + let fp = (*ctx).uc_mcontext.gregs[10]; + let has_faulting_addr = sig == SIGSEGV; + let mut faulting_addr = 0; + if has_faulting_addr { + faulting_addr = (*info).siginfo.sifields.sigsys.call_addr as usize; + } + println!("handle_signal: sig: {}, ip: {}, fp: {}, has_faulting_addr: {}, faulting_addr: {}", sig, ip, fp, has_faulting_addr, faulting_addr); + g_handler(ip, fp, has_faulting_addr, faulting_addr); + } + // signal(signo, SIG_DFL); + println!("handle_signal: sig: {}, should signal", sig); +} + + +#[no_mangle] +pub extern "C" fn wasmtime_init_traps(handler: wasmtime_trap_handler_t) -> i32 { + unsafe { + g_handler = handler; + let action = SigAction { + sa_handler: handle_signal as usize, + sa_flags: (SA_NODEFER | SA_SIGINFO) as usize, + sa_mask: Sigset { sig: [0; 1] }, + }; + let rc = libos!(sigaction(SIGILL, &action, null())); + if rc != 0 { + return rc; + } + } + 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 successed 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 { + *ret = 0 as *mut wasmtime_memory_image; + 0 +} + +/// 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 { + 0 +} + +/// 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) { + // no-op +} + +/// 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 { WASMTIME_TLS } +} + +/// 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 { + WASMTIME_TLS = ptr; + } +} diff --git a/wasmtime_wasi_api/src/data_buffer.rs b/wasmtime_wasi_api/src/data_buffer.rs new file mode 100644 index 00000000..09ccc7ca --- /dev/null +++ b/wasmtime_wasi_api/src/data_buffer.rs @@ -0,0 +1,91 @@ +extern crate alloc; +use core::mem::forget; + +use alloc::{string::String, vec::Vec}; + +use ms_std::agent::DataBuffer; +#[cfg(feature = "log")] +use ms_std::{println, time::{SystemTime, UNIX_EPOCH}}; +use ms_std_proc_macro::FaasData; +use wasmtime::Caller; + +use crate::LibosCtx; + +#[derive(FaasData)] +struct WasmDataBuffer(*mut u8, usize); + +impl Default for WasmDataBuffer { + fn default() -> Self { + Self(core::ptr::null_mut(), Default::default()) + } +} + +pub fn buffer_register( + mut caller: Caller<'_, LibosCtx>, + slot_name_base: i32, slot_name_size: i32, buffer_offset: i32, buffer_size: i32, +) { + #[cfg(feature = "log")] + { + println!("[Debug] buffer_register"); + println!("[Time] buffer_register: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + let memory = caller.get_export("memory").unwrap().into_memory().unwrap(); + let mut slot_name: Vec = Vec::with_capacity(slot_name_size as usize); + slot_name.resize(slot_name_size as usize, 0); + memory.read(&caller, slot_name_base as usize, &mut slot_name).unwrap(); + let slot_name = String::from_utf8(slot_name).expect("[Err] Not a valid UTF-8 sequence"); + + #[cfg(feature = "log")] + println!("slot_name={}", slot_name); + + let content = memory.data_mut(&mut caller) + .get_mut(buffer_offset as usize..) + .and_then(|s| s.get_mut(..buffer_size as usize)) + .unwrap(); + + let buffer_base = content.as_mut_ptr(); + + #[cfg(feature = "log")] + println!("base={:?}, addr={:?}, offset={:?}, size={}", base, buffer_base, buffer_offset, buffer_size); + #[cfg(feature = "log")] + println!("content={:?}", content); + + let mut wasm_buffer: DataBuffer = DataBuffer::with_slot(slot_name); + wasm_buffer.0 = buffer_base; + wasm_buffer.1 = buffer_size as usize; +} + +pub fn access_buffer( + mut caller: Caller<'_, LibosCtx>, + slot_name_base: i32, slot_name_size: i32, buffer_base: i32, buffer_size: i32, +) { + #[cfg(feature = "log")] + { + println!("[Debug] access_buffer"); + println!("[Time] access_buffer: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + let memory = caller.get_export("memory").unwrap().into_memory().unwrap(); + let mut slot_name: Vec = Vec::with_capacity(slot_name_size as usize); + slot_name.resize(slot_name_size as usize, 0); + memory.read(&caller, slot_name_base as usize, &mut slot_name).unwrap(); + let slot_name = String::from_utf8(slot_name).expect("[Err] Not a valid UTF-8 sequence"); + + #[cfg(feature = "log")] + println!("slot_name={}", slot_name); + let wasm_buffer: DataBuffer = DataBuffer::from_buffer_slot(slot_name).unwrap(); + #[cfg(feature = "log")] + println!( + "wasm_buffer -> addr={:?}, size={}", + wasm_buffer.0, wasm_buffer.1 + ); + + if buffer_size as usize != wasm_buffer.1 { + panic!("buffer_size={}, wasm_buffer.1={}, access_buffer's size is different from buffer_register's size", buffer_size, wasm_buffer.1) + } + let buffer = unsafe { core::slice::from_raw_parts(wasm_buffer.0, wasm_buffer.1) }; + #[cfg(feature = "log")] + println!("buffer: {:?}", buffer); + memory.write(&mut caller, buffer_base as usize, buffer).unwrap(); +} diff --git a/wasmtime_wasi_api/src/lib.rs b/wasmtime_wasi_api/src/lib.rs new file mode 100644 index 00000000..20b1a85f --- /dev/null +++ b/wasmtime_wasi_api/src/lib.rs @@ -0,0 +1,341 @@ +#![no_std] + +extern crate alloc; + +use alloc::{string::{String, ToString}, vec::Vec}; +pub use wasmtime; +use wasmtime::{Engine, Linker, Module}; + +pub mod data_buffer; +// mod capis; +mod types; +mod wasi; +pub use wasi::JMP_BUF_MAP; + +pub struct LibosCtx { + pub id: String +} + +pub fn build_wasm(cwasm: &[u8]) -> (Engine, Module, Linker) { + let engine: Engine = Engine::default(); + let module: Module = unsafe { Module::deserialize(&engine, cwasm) }.map_err(|e| e.to_string()).unwrap(); + let mut linker = Linker::new(&engine); + import_all(&mut linker); + (engine, module, linker) +} + +pub fn set_wasi_args(id: &str, args: Vec) { + wasi::set_wasi_state(id, args); +} + +fn import_all(linker: &mut Linker) { + linker + .func_wrap( + "env", + "buffer_register", + data_buffer::buffer_register, + ) + .unwrap(); + linker + .func_wrap( + "env", + "access_buffer", + data_buffer::access_buffer, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "args_get", + wasi::args_get, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "args_sizes_get", + wasi::args_sizes_get, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "clock_res_get", + wasi::clock_res_get, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "clock_time_get", + wasi::clock_time_get, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "environ_get", + wasi::environ_get, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "environ_sizes_get", + wasi::environ_sizes_get, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "fd_advise", + wasi::fd_advise, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "fd_close", + wasi::fd_close, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "fd_datasync", + wasi::fd_datasync, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "fd_fdstat_get", + wasi::fd_fdstat_get, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "fd_fdstat_set_flags", + wasi::fd_fdstat_set_flags, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "fd_filestat_get", + wasi::fd_filestat_get, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "fd_filestat_set_size", + wasi::fd_filestat_set_size, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "fd_filestat_set_times", + wasi::fd_filestat_set_times, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "fd_pread", + wasi::fd_pread, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "fd_pwrite", + wasi::fd_pwrite, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "fd_prestat_get", + wasi::fd_prestat_get, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "fd_prestat_dir_name", + wasi::fd_prestat_dir_name, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "fd_read", + wasi::fd_read, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "fd_readdir", + wasi::fd_readdir, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "fd_seek", + wasi::fd_seek, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "fd_sync", + wasi::fd_sync, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "fd_tell", + wasi::fd_tell, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "fd_write", + wasi::fd_write, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "path_create_directory", + wasi::path_create_directory, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "path_filestat_get", + wasi::path_filestat_get, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "path_filestat_set_times", + wasi::path_filestat_set_times, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "path_link", + wasi::path_link, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "path_open", + wasi::path_open, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "path_readlink", + wasi::path_readlink, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "path_remove_directory", + wasi::path_remove_directory, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "path_rename", + wasi::path_rename, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "path_symlink", + wasi::path_symlink, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "path_unlink_file", + wasi::path_unlink_file, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "poll_oneoff", + wasi::poll_oneoff, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "proc_exit", + wasi::proc_exit, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "random_get", + wasi::random_get, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "sched_yield", + wasi::sched_yield, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "sock_accept", + wasi::sock_accept, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "sock_recv", + wasi::sock_recv, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "sock_send", + wasi::sock_send, + ) + .unwrap(); + linker + .func_wrap( + "wasi_snapshot_preview1", + "sock_shutdown", + wasi::sock_shutdown, + ) + .unwrap(); + +} \ No newline at end of file diff --git a/wasmtime_wasi_api/src/types.rs b/wasmtime_wasi_api/src/types.rs new file mode 100644 index 00000000..5e58d552 --- /dev/null +++ b/wasmtime_wasi_api/src/types.rs @@ -0,0 +1,385 @@ +#![allow(warnings)] + +#[repr(C)] +pub(crate) struct WasiCiovec { + pub(crate) buf: u32, + pub(crate) buf_len: u32, +} + +#[repr(C)] +pub(crate) struct WasiDirent { + pub(crate) d_next: u64, + pub(crate) d_ino: u64, + pub(crate) d_namelen: u32, + pub(crate) d_type: u8 +} + +#[repr(C)] +pub(crate) struct WasiFdstat { + pub(crate) fs_filetype: u8, + pub(crate) fs_flags: u16, + pub(crate) fs_rights_base: u64, + pub(crate) fs_rights_inheriting: u64, +} + +#[repr(C)] +pub(crate) struct WasiFilestat { + pub(crate) dev: u64, + pub(crate) ino: u64, + pub(crate) filetype: u8, + pub(crate) nlink: u64, + pub(crate) size: u64, + pub(crate) atim: u64, + pub(crate) mtim: u64, + pub(crate) ctim: u64, +} + +#[repr(C)] +pub(crate) struct WasiPrestatDir { + pub(crate) dirname_len: u32, +} + +#[repr(C)] +pub(crate) struct WasiPrestatUt { + pub(crate) dir: WasiPrestatDir, +} + +#[repr(C)] +pub(crate) struct WasiPrestatT { + pub(crate) tag: u8, + pub(crate) u: WasiPrestatUt, +} + +pub(crate) enum Errno { + #[doc = " No error occurred. System call completed successfully."] + Success, + #[doc = " Argument list too long."] + Toobig, + #[doc = " Permission denied."] + Access, + #[doc = " Address in use."] + Addrinuse, + #[doc = " Address not available."] + Addrnotavail, + #[doc = " Address family not supported."] + Afnosupport, + #[doc = " Resource unavailable, or operation would block."] + Again, + #[doc = " Connection already in progress."] + Already, + #[doc = " Bad file descriptor."] + Badf, + #[doc = " Bad message."] + Badmsg, + #[doc = " Device or resource busy."] + Busy, + #[doc = " Operation canceled."] + Canceled, + #[doc = " No child processes."] + Child, + #[doc = " Connection aborted."] + Connaborted, + #[doc = " Connection refused."] + Connrefused, + #[doc = " Connection reset."] + Connreset, + #[doc = " Resource deadlock would occur."] + Deadlk, + #[doc = " Destination address required."] + Destaddrreq, + #[doc = " Mathematics argument out of domain of function."] + Dom, + #[doc = " Reserved."] + Dquot, + #[doc = " File exists."] + Exist, + #[doc = " Bad address."] + Fault, + #[doc = " File too large."] + Fbig, + #[doc = " Host is unreachable."] + Hostunreach, + #[doc = " Identifier removed."] + Idrm, + #[doc = " Illegal byte sequence."] + Ilseq, + #[doc = " Operation in progress."] + Inprogress, + #[doc = " Interrupted function."] + Intr, + #[doc = " Invalid argument."] + Inval, + #[doc = " I/O error."] + Io, + #[doc = " Socket is connected."] + Isconn, + #[doc = " Is a directory."] + Isdir, + #[doc = " Too many levels of symbolic links."] + Loop, + #[doc = " File descriptor value too large."] + Mfile, + #[doc = " Too many links."] + Mlink, + #[doc = " Message too large."] + Msgsize, + #[doc = " Reserved."] + Multihop, + #[doc = " Filename too long."] + Nametoolong, + #[doc = " Network is down."] + Netdown, + #[doc = " Connection aborted by network."] + Netreset, + #[doc = " Network unreachable."] + Netunreach, + #[doc = " Too many files open in system."] + Nfile, + #[doc = " No buffer space available."] + Nobufs, + #[doc = " No such device."] + Nodev, + #[doc = " No such file or directory."] + Noent, + #[doc = " Executable file format error."] + Noexec, + #[doc = " No locks available."] + Nolck, + #[doc = " Reserved."] + Nolink, + #[doc = " Not enough space."] + Nomem, + #[doc = " No message of the desired type."] + Nomsg, + #[doc = " Protocol not available."] + Noprotoopt, + #[doc = " No space left on device."] + Nospc, + #[doc = " Function not supported."] + Nosys, + #[doc = " The socket is not connected."] + Notconn, + #[doc = " Not a directory or a symbolic link to a directory."] + Notdir, + #[doc = " Directory not empty."] + Notempty, + #[doc = " State not recoverable."] + Notrecoverable, + #[doc = " Not a socket."] + Notsock, + #[doc = " Not supported, or operation not supported on socket."] + Notsup, + #[doc = " Inappropriate I/O control operation."] + Notty, + #[doc = " No such device or address."] + Nxio, + #[doc = " Value too large to be stored in data type."] + Overflow, + #[doc = " Previous owner died."] + Ownerdead, + #[doc = " Operation not permitted."] + Perm, + #[doc = " Broken pipe."] + Pipe, + #[doc = " Protocol error."] + Proto, + #[doc = " Protocol not supported."] + Protonosupport, + #[doc = " Protocol wrong type for socket."] + Prototype, + #[doc = " Result too large."] + Range, + #[doc = " Read-only file system."] + Rofs, + #[doc = " Invalid seek."] + Spipe, + #[doc = " No such process."] + Srch, + #[doc = " Reserved."] + Stale, + #[doc = " Connection timed out."] + Timedout, + #[doc = " Text file busy."] + Txtbsy, + #[doc = " Cross-device link."] + Xdev, + #[doc = " Extension: Capabilities insufficient."] + Notcapable, + #[doc = " Cannot send after socket shutdown."] + Shutdown, + #[doc = " Memory access violation."] + Memviolation, + #[doc = " An unknown error has occured"] + Unknown, +} + +impl Errno { + pub fn name(&self) -> &'static str { + match self { + Errno::Success => "success", + Errno::Toobig => "toobig", + Errno::Access => "access", + Errno::Addrinuse => "addrinuse", + Errno::Addrnotavail => "addrnotavail", + Errno::Afnosupport => "afnosupport", + Errno::Again => "again", + Errno::Already => "already", + Errno::Badf => "badf", + Errno::Badmsg => "badmsg", + Errno::Busy => "busy", + Errno::Canceled => "canceled", + Errno::Child => "child", + Errno::Connaborted => "connaborted", + Errno::Connrefused => "connrefused", + Errno::Connreset => "connreset", + Errno::Deadlk => "deadlk", + Errno::Destaddrreq => "destaddrreq", + Errno::Dom => "dom", + Errno::Dquot => "dquot", + Errno::Exist => "exist", + Errno::Fault => "fault", + Errno::Fbig => "fbig", + Errno::Hostunreach => "hostunreach", + Errno::Idrm => "idrm", + Errno::Ilseq => "ilseq", + Errno::Inprogress => "inprogress", + Errno::Intr => "intr", + Errno::Inval => "inval", + Errno::Io => "io", + Errno::Isconn => "isconn", + Errno::Isdir => "isdir", + Errno::Loop => "loop", + Errno::Mfile => "mfile", + Errno::Mlink => "mlink", + Errno::Msgsize => "msgsize", + Errno::Multihop => "multihop", + Errno::Nametoolong => "nametoolong", + Errno::Netdown => "netdown", + Errno::Netreset => "netreset", + Errno::Netunreach => "netunreach", + Errno::Nfile => "nfile", + Errno::Nobufs => "nobufs", + Errno::Nodev => "nodev", + Errno::Noent => "noent", + Errno::Noexec => "noexec", + Errno::Nolck => "nolck", + Errno::Nolink => "nolink", + Errno::Nomem => "nomem", + Errno::Nomsg => "nomsg", + Errno::Noprotoopt => "noprotoopt", + Errno::Nospc => "nospc", + Errno::Nosys => "nosys", + Errno::Notconn => "notconn", + Errno::Notdir => "notdir", + Errno::Notempty => "notempty", + Errno::Notrecoverable => "notrecoverable", + Errno::Notsock => "notsock", + Errno::Notsup => "notsup", + Errno::Notty => "notty", + Errno::Nxio => "nxio", + Errno::Overflow => "overflow", + Errno::Ownerdead => "ownerdead", + Errno::Perm => "perm", + Errno::Pipe => "pipe", + Errno::Proto => "proto", + Errno::Protonosupport => "protonosupport", + Errno::Prototype => "prototype", + Errno::Range => "range", + Errno::Rofs => "rofs", + Errno::Spipe => "spipe", + Errno::Srch => "srch", + Errno::Stale => "stale", + Errno::Timedout => "timedout", + Errno::Txtbsy => "txtbsy", + Errno::Xdev => "xdev", + Errno::Notcapable => "notcapable", + Errno::Shutdown => "shutdown", + Errno::Memviolation => "memviolation", + Errno::Unknown => "unknown", + } + } + pub fn message(&self) -> &'static str { + match self { + Errno::Success => "No error occurred. System call completed successfully.", + Errno::Toobig => "Argument list too long.", + Errno::Access => "Permission denied.", + Errno::Addrinuse => "Address in use.", + Errno::Addrnotavail => "Address not available.", + Errno::Afnosupport => "Address family not supported.", + Errno::Again => "Resource unavailable, or operation would block.", + Errno::Already => "Connection already in progress.", + Errno::Badf => "Bad file descriptor.", + Errno::Badmsg => "Bad message.", + Errno::Busy => "Device or resource busy.", + Errno::Canceled => "Operation canceled.", + Errno::Child => "No child processes.", + Errno::Connaborted => "Connection aborted.", + Errno::Connrefused => "Connection refused.", + Errno::Connreset => "Connection reset.", + Errno::Deadlk => "Resource deadlock would occur.", + Errno::Destaddrreq => "Destination address required.", + Errno::Dom => "Mathematics argument out of domain of function.", + Errno::Dquot => "Reserved.", + Errno::Exist => "File exists.", + Errno::Fault => "Bad address.", + Errno::Fbig => "File too large.", + Errno::Hostunreach => "Host is unreachable.", + Errno::Idrm => "Identifier removed.", + Errno::Ilseq => "Illegal byte sequence.", + Errno::Inprogress => "Operation in progress.", + Errno::Intr => "Interrupted function.", + Errno::Inval => "Invalid argument.", + Errno::Io => "I/O error.", + Errno::Isconn => "Socket is connected.", + Errno::Isdir => "Is a directory.", + Errno::Loop => "Too many levels of symbolic links.", + Errno::Mfile => "File descriptor value too large.", + Errno::Mlink => "Too many links.", + Errno::Msgsize => "Message too large.", + Errno::Multihop => "Reserved.", + Errno::Nametoolong => "Filename too long.", + Errno::Netdown => "Network is down.", + Errno::Netreset => "Connection aborted by network.", + Errno::Netunreach => "Network unreachable.", + Errno::Nfile => "Too many files open in system.", + Errno::Nobufs => "No buffer space available.", + Errno::Nodev => "No such device.", + Errno::Noent => "No such file or directory.", + Errno::Noexec => "Executable file format error.", + Errno::Nolck => "No locks available.", + Errno::Nolink => "Reserved.", + Errno::Nomem => "Not enough space.", + Errno::Nomsg => "No message of the desired type.", + Errno::Noprotoopt => "Protocol not available.", + Errno::Nospc => "No space left on device.", + Errno::Nosys => "Function not supported.", + Errno::Notconn => "The socket is not connected.", + Errno::Notdir => "Not a directory or a symbolic link to a directory.", + Errno::Notempty => "Directory not empty.", + Errno::Notrecoverable => "State not recoverable.", + Errno::Notsock => "Not a socket.", + Errno::Notsup => "Not supported, or operation not supported on socket.", + Errno::Notty => "Inappropriate I/O control operation.", + Errno::Nxio => "No such device or address.", + Errno::Overflow => "Value too large to be stored in data type.", + Errno::Ownerdead => "Previous owner died.", + Errno::Perm => "Operation not permitted.", + Errno::Pipe => "Broken pipe.", + Errno::Proto => "Protocol error.", + Errno::Protonosupport => "Protocol not supported.", + Errno::Prototype => "Protocol wrong type for socket.", + Errno::Range => "Result too large.", + Errno::Rofs => "Read-only file system.", + Errno::Spipe => "Invalid seek.", + Errno::Srch => "No such process.", + Errno::Stale => "Reserved.", + Errno::Timedout => "Connection timed out.", + Errno::Txtbsy => "Text file busy.", + Errno::Xdev => "Cross-device link.", + Errno::Notcapable => "Extension: Capabilities insufficient.", + Errno::Shutdown => "Cannot send after socket shutdown.", + Errno::Memviolation => "Memory access violation.", + Errno::Unknown => "An unknown error has occured", + } + } +} \ No newline at end of file diff --git a/wasmtime_wasi_api/src/wasi.rs b/wasmtime_wasi_api/src/wasi.rs new file mode 100644 index 00000000..45909155 --- /dev/null +++ b/wasmtime_wasi_api/src/wasi.rs @@ -0,0 +1,1001 @@ +#![allow(warnings)] + +extern crate alloc; + +use core::mem::forget; + +#[cfg(feature = "log")] +use ms_std::println; +#[cfg(feature = "log")] +use alloc::format; + +use alloc::{borrow::ToOwned, string::{String, ToString}, sync::Arc, vec::Vec}; +use hashbrown::HashMap; +use sjlj::{longjmp, JumpBuf}; +use spin::{Mutex, MutexGuard}; +use wasmtime::Caller; + +use ms_hostcall::{fdtab::FdtabResult, types::{DirEntry, Fd, OpenFlags, OpenMode, Stat}}; +use ms_std::{ + libos::libos, + time::{SystemTime, UNIX_EPOCH}, +}; +use crate::{types::*, LibosCtx}; + +pub(crate) struct WasiState { + pub(crate) args: Vec, +} +lazy_static::lazy_static! { + static ref WASI_STATE: Mutex> = Mutex::new( HashMap::new() ); +} +fn get_hashmap_wasi_state_mut() -> MutexGuard<'static, HashMap> { + WASI_STATE.lock() +} +fn get_wasi_state<'a>(id: &str, map: &'a MutexGuard<'static, HashMap>) -> &'a WasiState { + let wasi_state = map.get(id).unwrap(); + if wasi_state.args.len() == 0 { + panic!("WASI_STATE uninit") + } + wasi_state +} +pub fn set_wasi_state(id: &str, _args: Vec) { + let mut map = get_hashmap_wasi_state_mut(); + map.insert(id.to_string(), WasiState { args: _args }); +} + +lazy_static::lazy_static! { + static ref FD2PATH: Mutex> = Mutex::new( HashMap::new() ); +} +fn get_hashmap_fd2path_mut() -> MutexGuard<'static, HashMap> { + FD2PATH.lock() +} +fn get_fd2path<'a>(fd: u32, map: &'a MutexGuard<'static, HashMap>) -> &'a String { + let path = map.get(&fd).unwrap(); + if path.len() == 0 { + panic!("FD2PATH uninit") + } + path +} +fn set_fd2path(fd: u32, path: String) { + let mut map = get_hashmap_fd2path_mut(); + map.insert(fd, path); +} + +lazy_static::lazy_static! { + pub static ref JMP_BUF_MAP: Mutex>> = Mutex::new( HashMap::new() ); +} + +pub fn args_get(mut caller: Caller<'_, LibosCtx>, argv: i32, argv_buf: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into args_get"); + println!("args: argv: {:?}, argv_buf: {:?}", argv, argv_buf); + println!("[Time] args_get: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + // argv是每个arg在argv_buf中的起始地址的数组的起始地址 + // argv_buf是存arg的buf的起始地址 + // 在buf中存入arg,并以\0结尾 (len需要+1) + + let caller_id = &caller.data().id; + let map = WASI_STATE.lock(); + let wasi_state = get_wasi_state(&caller_id, &map); + let args: Vec<&[u8]> = wasi_state + .args + .iter() + .map(|a| a.as_bytes()) + .collect::>(); + let mut offset: usize = 0; + + let memory = caller.get_export("memory").unwrap().into_memory().unwrap(); + + #[cfg(feature = "log")] + println!("arg_vec len: {}", args.len()); + for (i, arg) in args.iter().enumerate() { + #[cfg(feature = "log")] + println!( + "i: {:?}, offset: {:?}, arg: {:?}, arg_len: {:?}", + i, + offset, + arg, + arg.len() + ); + let arg_addr = argv_buf as usize + offset; + + memory.write(&mut caller, argv as usize + i * core::mem::size_of::(), &(arg_addr as u32).to_ne_bytes()).unwrap(); + memory.write(&mut caller, arg_addr, arg).unwrap(); + memory.write(&mut caller, arg_addr + arg.len(), "\0".as_bytes()).unwrap(); + + offset += arg.len() + 1; + } + + Errno::Success as i32 +} + +pub fn args_sizes_get(mut caller: Caller<'_, LibosCtx>, argc: i32, argv_buf_size: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into args_sizes_get"); + println!("args: argc: {:?}, argv_buf_size: {:?}", argc, argv_buf_size); + println!("[Time] args_sizes_get: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + let caller_id = &caller.data().id; + let map = WASI_STATE.lock(); + let wasi_state = get_wasi_state(&caller_id, &map); + let argc_val = wasi_state.args.len(); + let argv_buf_size_val: usize = wasi_state.args.iter().map(|v| v.len() + 1).sum(); + + #[cfg(feature = "log")] + println!( + "argc_val={:?}, argv_buf_size_val: {:?}", + argc_val, argv_buf_size_val + ); + + let memory = caller.get_export("memory").unwrap().into_memory().unwrap(); + + memory.write(&mut caller, argc as usize, &(argc_val as u32).to_ne_bytes()).unwrap(); + memory.write(&mut caller, argv_buf_size as usize, &(argv_buf_size_val as u32).to_ne_bytes()).unwrap(); + + Errno::Success as i32 +} + +pub fn clock_res_get(mut caller: Caller<'_, LibosCtx>, clock_id: i32, resolution: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into clock_res_get"); + println!("args: clock_id: {:?}, resolution: {:?}", clock_id, resolution); + println!("[Time] clock_res_get: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +} + +pub fn clock_time_get(mut caller: Caller<'_, LibosCtx>, clock_id: i32, precision: i64, time: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into clock_time_get"); + println!( + "args: clock_id: {:?}, precision: {:?}, time: {:?}", + clock_id, precision, time + ); + println!("[Time] clock_time_get: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + let memory = caller.get_export("memory").unwrap().into_memory().unwrap(); + let time_var = SystemTime::now().duration_since(UNIX_EPOCH).as_nanos(); + memory.write(&mut caller, time as usize, &time_var.to_ne_bytes()).unwrap(); + + Errno::Success as i32 +} + +pub fn environ_get(mut caller: Caller<'_, LibosCtx>, environ: i32, environ_buf: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into environ_get"); + println!("args: environ: {:?}, environ_buf: {:?}", environ, environ_buf); + println!("[Time] environ_get: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +} + +pub fn environ_sizes_get(mut caller: Caller<'_, LibosCtx>, environ_count: i32, environ_buf_size: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into environ_sizes_get"); + println!( + "args: environ_count: {:?}, environ_buf_size: {:?}", + environ_count, environ_buf_size + ); + println!("[Time] environ_sizes_get: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + let count = 0i32; + let buf_size = 0i32; + let memory = caller.get_export("memory").unwrap().into_memory().unwrap(); + memory.write(&mut caller, environ_count as usize, &count.to_ne_bytes()).unwrap(); + memory.write(&mut caller, environ_buf_size as usize, &buf_size.to_ne_bytes()).unwrap(); + + Errno::Success as i32 +} + +pub fn fd_advise(mut caller: Caller<'_, LibosCtx>, fd: i32, offset: i64, len: i64, advice: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into fd_advise"); + println!("args: fd: {:?}, offset: {:?}, len: {:?}, advice: {:?}", fd, offset, len, advice); + println!("[Time] fd_advise: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +} + +pub fn fd_close(mut caller: Caller<'_, LibosCtx>, fd: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into fd_close"); + println!("args: fd: {:?}", fd); + println!("[Time] fd_close: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + libos!(close(fd as u32)).unwrap(); + Errno::Success as i32 +} + +pub fn fd_datasync(mut caller: Caller<'_, LibosCtx>, fd: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into fd_datasync"); + println!("args: fd: {:?}", fd); + println!("[Time] fd_datasync: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +} + +pub fn fd_fdstat_get(mut caller: Caller<'_, LibosCtx>, fd: i32, retptr: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into fd_fdstat_get"); + println!("args: fd: {:?}, retptr: {:?}", fd, retptr); + println!("[Time] fd_fdstat_get: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + let memory = caller.get_export("memory").unwrap().into_memory().unwrap(); + let mut fdstat: WasiFdstat = WasiFdstat { + fs_filetype: 0, + fs_flags: 0, + fs_rights_base: 0, + fs_rights_inheriting: 0, + }; + match fd as u32 { + 0 => { + // stdin + fdstat.fs_filetype = 2; // CharacterDevice + fdstat.fs_flags = 0; + fdstat.fs_rights_base = 0xFFFFFFFFFFFFFFFF; + fdstat.fs_rights_inheriting = 0; + } + 1 => { + // stdout + fdstat.fs_filetype = 2; + fdstat.fs_flags = 1; + fdstat.fs_rights_base = 0xFFFFFFFFFFFFFFFF; + fdstat.fs_rights_inheriting = 0; + } + 2 => { + // stderr + fdstat.fs_filetype = 2; + fdstat.fs_flags = 1; + fdstat.fs_rights_base = 0xFFFFFFFFFFFFFFFF; + fdstat.fs_rights_inheriting = 0; + } + 3 => { + // root inode + fdstat.fs_filetype = 3; // Directory + fdstat.fs_flags = 0; + fdstat.fs_rights_base = 0xFFFFFFFFFFFFFFFF; + fdstat.fs_rights_inheriting = 0xFFFFFFFFFFFFFFFF; + } + _ => (), + } + // Todo: 从表中寻找fd + // let msFdStat = table.find(fd); + // fdstat.fs_filetype = match msFdStat.kind { + // 0 => 4, // 0 代表File,4代表RegularFile + // 1 => 3 // 1 代表Dir,3代表Directory + // }; + // fdstat.fs_flags = msFdStat.flags; + // fdstat.fs_rights_base = msFdStat.fs_rights_base; + // fdstat.fs_rights_inheriting = msFdStat.fs_rights_inheriting; + if fd as u32 > 3 { + // 假设打开的都是文件 + fdstat.fs_filetype = 4; + fdstat.fs_flags = 0; + fdstat.fs_rights_base = 0xFFFFFFFFFFFFFFFF; + fdstat.fs_rights_inheriting = 0xFFFFFFFFFFFFFFFF; + } + + let buf = (&fdstat) as *const _ as usize; + let buf = unsafe { + core::slice::from_raw_parts(buf as *const u8, core::mem::size_of::()) + }; + memory.write(&mut caller, retptr as usize, buf).unwrap(); + + Errno::Success as i32 +} + +pub fn fd_fdstat_set_flags(mut caller: Caller<'_, LibosCtx>, fd: i32, offset: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into fd_fdstat_set_flags"); + println!("args: fd: {:?}, flag: {:?}", fd as u32, offset as u16); + println!("[Time] fd_fdstat_set_flags: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +} + +pub fn fd_filestat_get(mut caller: Caller<'_, LibosCtx>, fd: i32, buf: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into fd_filestat_get"); + println!("args: fd: {:?}, buf: {:?}", fd, buf); + println!("[Time] fd_filestat_get: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +} + +pub fn fd_filestat_set_size(mut caller: Caller<'_, LibosCtx>, fd: i32, st_size: i64) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into fd_filestat_set_size"); + println!("args: fd: {:?}, st_size: {:?}", fd, st_size); + println!("[Time] fd_filestat_set_size: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +} + +pub fn fd_filestat_set_times(mut caller: Caller<'_, LibosCtx>, fd: i32, st_atim: i64, st_mtim: i64, fst_flags: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into fd_filestat_set_times"); + println!("args: fd: {:?}, st_atim: {:?}, st_mtim: {:?}, fst_flags: {:?}", fd, st_atim, st_mtim, fst_flags); + println!("[Time] fd_filestat_set_times: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +} + +pub fn fd_pread(mut caller: Caller<'_, LibosCtx>, fd: i32, iovs: i32, iovs_len: i32, offset: i64, nread: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into fd_pread"); + println!( + "args: fd: {:?}, iovs: {:?}, iovs_len: {:?}, offset: {:?}, nread: {:?}", + fd, iovs, iovs_len, offset, nread + ); + println!("[Time] fd_pread: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +} + +pub fn fd_pwrite(mut caller: Caller<'_, LibosCtx>, fd: i32, iovs: i32, iovs_len: i32, offset: i64, nwritten: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into fd_pwrite"); + println!( + "args: fd: {:?}, iovs: {:?}, iovs_len: {:?}, offset: {:?}, nwritten: {:?}", + fd , iovs , iovs_len , offset , nwritten + ); + println!("[Time] fd_pwrite: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +} + +pub fn fd_prestat_get(mut caller: Caller<'_, LibosCtx>, fd: i32, retptr: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into fd_prestat_get"); + println!("args: fd: {:?}, retptr: {:?}", fd, retptr); + println!("[Time] fd_prestat_get: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + let memory = caller.get_export("memory").unwrap().into_memory().unwrap(); + + match fd { + 3 => { + // root inode + let prestat = WasiPrestatT { + tag: 0, // tag 应为 0,表示这是一个目录,非0表示unknown + u: WasiPrestatUt { + dir: WasiPrestatDir { + dirname_len: "/".len() as u32, + }, + }, + }; + + let buf = (&prestat) as *const _ as usize; + let buf = unsafe { + core::slice::from_raw_parts(buf as *const u8, core::mem::size_of::()) + }; + memory.write(&mut caller, retptr as usize, buf).unwrap(); + + Errno::Success as i32 + } + // Todo: libos需要维护一个表,从表中找fd,找不到就返回Badf + _ => { + #[cfg(feature = "log")] + println!("[WASI ERR] Errno in fd_prestat_get: Badf"); + Errno::Badf as i32 + } + } +} + +pub fn fd_prestat_dir_name(mut caller: Caller<'_, LibosCtx>, fd: i32, path_addr: i32, path_len: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into fd_prestat_dir_name"); + println!( + "args: fd: {:?}, path_addr: {:?}, path_len: {:?}", + fd, path_addr, path_len + ); + println!("[Time] fd_prestat_dir_name: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + let memory = caller.get_export("memory").unwrap().into_memory().unwrap(); + + // Todo: 从表中寻找fd + if fd == 3 { + let name = "/"; + memory.write(&mut caller, path_addr as usize, name.as_bytes()).unwrap(); + Errno::Success as i32 + } else { + #[cfg(feature = "log")] + println!("[WASI ERR] Errno in fd_prestat_dir_name: Overflow"); + Errno::Overflow as i32 + } +} + +pub fn fd_read(mut caller: Caller<'_, LibosCtx>, fd: i32, iovs_ptr: i32, iovs_len: i32, retptr: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into fd_read"); + println!( + "args: fd: {:?}, iovs_ptr: {:?}, iovs_len: {:?}, retptr: {:?}", + fd, iovs_ptr, iovs_len, retptr + ); + println!("[Time] fd_read: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + let memory = caller.get_export("memory").unwrap().into_memory().unwrap(); + let mut read_size: usize = 0; + + for i in 0..iovs_len { + let offset: usize = iovs_ptr as usize + i as usize * core::mem::size_of::(); + let iovs = memory.data(&caller) + .get(offset..) + .and_then(|s| s.get(..core::mem::size_of::() as usize)) + .unwrap(); + let iovs: &WasiCiovec = unsafe { &*(iovs.as_ptr() as *const WasiCiovec) }; + let mut buf = memory.data_mut(&mut caller) + .get_mut(iovs.buf as usize..) + .and_then(|s| s.get_mut(..iovs.buf_len as usize)) + .unwrap(); + read_size += libos!(read(fd as u32, &mut buf)).unwrap(); + } + + #[cfg(feature = "log")] + println!("read_size: {:?}", read_size); + memory.write(&mut caller, retptr as usize, &(read_size as u32).to_ne_bytes()).unwrap(); + Errno::Success as i32 +} + +pub fn fd_readdir(mut caller: Caller<'_, LibosCtx>, fd: i32, buf: i32, buf_len: i32, cookie: i64, bufused: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into fd_readdir"); + println!( + "args: fd: {:?}, buf: {:?}, buf_len: {:?}, cookie: {:?}, bufused: {:?}", + fd, buf, buf_len, cookie, bufused + ); + println!("[Time] fd_readdir start: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + let memory = caller.get_export("memory").unwrap().into_memory().unwrap(); + let map = FD2PATH.lock(); + let path = get_fd2path(fd as u32, &map); + + #[cfg(feature = "log")] + println!("fd_readdir: fd = {:?}, path = {:?}", fd, path); + + let mut entries: Vec = libos!(readdir(path)).unwrap(); + entries.push(DirEntry{ + dir_path: ".".to_owned(), + entry_name: ".".to_owned(), + entry_type: 4 // Directory + }); + entries.push(DirEntry{ + dir_path: "..".to_owned(), + entry_name: "..".to_owned(), + entry_type: 4 // Directory + }); + entries.sort_by(|a, b| a.entry_name.cmp(&b.entry_name)); + + let mut cur_cookie = cookie as u64; + let mut cur_buf = buf as u32; + let mut bufused_len: u32 = 0; + for item in entries.iter().skip(cookie as usize) { + cur_cookie += 1; + let dirent = WasiDirent { + d_next: cur_cookie, + d_ino: match item.entry_name.as_str() { + "." | ".." => 0, // fake ino + _ => { + // let item_fd: u32 = libos!(open(&item.dir_path, OpenFlags::empty(), OpenMode::RD)).unwrap(); + // let item_stat = libos!(stat(item_fd)).unwrap(); + // libos!(close(item_fd)).unwrap(); + // item_stat.st_ino + + // fake implement + 0 + } + }, + d_namelen: item.entry_name.len() as u32, + d_type: match item.entry_type { + 2 => 2, // CharacterDevice + 4 => 3, // Directory + 8 => 4, // Regular file + _ => 0 // Unknown + } + }; + let dirent = (&dirent) as *const _ as usize; + let dirent = unsafe { + core::slice::from_raw_parts(dirent as *const u8, core::mem::size_of::()) + }; + + if bufused_len + core::mem::size_of::() as u32 + item.entry_name.len() as u32 > buf_len as u32 { + #[cfg(feature = "log")] + println!("[INFO] fd_readdir: bufused overflow!"); + + let cap: u32 = buf_len as u32 - bufused_len; + let part_buf: Vec = [dirent, item.entry_name.as_bytes()].concat(); + let part_buf: &[u8] = part_buf.get(0..(cap as usize)).unwrap(); + + #[cfg(feature = "log")] + println!("[INFO] fd_readdir: cap: {:?}, bufused_len: {:?}, buf_len: {:?}", cap, bufused_len, buf_len); + + memory.write(&mut caller, cur_buf as usize, part_buf).unwrap(); + memory.write(&mut caller, bufused as usize, &buf_len.to_ne_bytes()).unwrap(); + forget(entries); + return Errno::Success as i32 + } + + memory.write(&mut caller, cur_buf as usize, dirent).unwrap(); + cur_buf += core::mem::size_of::() as u32; + bufused_len += core::mem::size_of::() as u32; + + memory.write(&mut caller, cur_buf as usize, item.entry_name.as_bytes()).unwrap(); + cur_buf += item.entry_name.len() as u32; + bufused_len += item.entry_name.len() as u32; + } + memory.write(&mut caller, bufused as usize, &bufused_len.to_ne_bytes()).unwrap(); + forget(entries); + Errno::Success as i32 +} + +pub fn fd_seek(mut caller: Caller<'_, LibosCtx>, fd: i32, offset: i64, whence: i32, pos: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into fd_seek"); + println!( + "args: fd: {:?}, offset: {:?}, whence: {:?}, pos: {:?}", + fd, offset, whence, pos + ); + println!("[Time] fd_seek: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + // TO BE FIX FOR PY HELLO + // let fd = args.0 as u32; + // let offset = args.1; + // let whence = args.2; + // let pos = offset as u32; + // // if whence == 0 { + + // // } else if whence == 1 { + + // // } else if whence == 2{ + + // // } + + // libos!(lseek(fd, pos)).unwrap(); + + Errno::Success as i32 +} + +pub fn fd_sync(mut caller: Caller<'_, LibosCtx>, fd: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into fd_sync"); + println!("args: fd: {:?}", fd); + println!("[Time] fd_sync: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +} + +pub fn fd_tell(mut caller: Caller<'_, LibosCtx>, fd: i32, offset: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into fd_tell"); + println!("args: fd: {:?}, offset: {:?}", fd, offset); + println!("[Time] fd_tell: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +} + +pub fn fd_write(mut caller: Caller<'_, LibosCtx>, fd: i32, iovs_ptr: i32, iovs_len: i32, retptr: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into fd_write"); + println!( + "args: fd: {:?}, iovs_ptr: {:?}, iovs_len: {:?}, retptr: {:?}", + fd, iovs_ptr, iovs_len, retptr + ); + println!("[Time] fd_write: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + let memory = caller.get_export("memory").unwrap().into_memory().unwrap(); + let mut write_size: usize = 0; + + for i in 0..iovs_len { + let offset: usize = iovs_ptr as usize + i as usize * core::mem::size_of::(); + let iovs = memory.data(&caller) + .get(offset..) + .and_then(|s| s.get(..core::mem::size_of::() as usize)) + .unwrap(); + let iovs: &WasiCiovec = unsafe { &*(iovs.as_ptr() as *const WasiCiovec) }; + let buf = memory.data(&caller) + .get(iovs.buf as usize..) + .and_then(|s| s.get(..iovs.buf_len as usize)) + .unwrap(); + write_size += libos!(write(fd as u32, &buf)).unwrap(); + } + + #[cfg(feature = "log")] + println!("write_size: {:?}", write_size); + memory.write(&mut caller, retptr as usize, &(write_size as u32).to_ne_bytes()).unwrap(); + Errno::Success as i32 +} + +pub fn path_create_directory(mut caller: Caller<'_, LibosCtx>, fd: i32, path: i32, path_len: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into path_create_directory"); + println!( + "args: fd: {:?}, path: {:?}, path_len: {:?}", + fd, path, path_len + ); + println!("[Time] path_create_directory: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +} + +pub fn path_filestat_get(mut caller: Caller<'_, LibosCtx>, fd: i32, flags: i32, path_ptr: i32, path_len: i32, buf: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into path_filestat_get"); + println!( + "args: fd: {:?}, flags: {:?}, path_ptr: {:?}, path_len: {:?}, buf: {:?}", + fd, flags, path_ptr, path_len, buf + ); + println!("[Time] path_filestat_get: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + let memory = caller.get_export("memory").unwrap().into_memory().unwrap(); + let mut path: Vec = Vec::with_capacity(path_len as usize); + path.resize(path_len as usize, 0); + memory.read(&caller, path_ptr as usize, &mut path).unwrap(); + let path = String::from_utf8(path).expect("[Err] Not a valid UTF-8 sequence"); + + #[cfg(feature = "log")] + println!("path: {:?}", path); + + let path_fd: FdtabResult = libos!(open(&path, OpenFlags::empty(), OpenMode::RD)); + let path_fd = if let Err(_e) = path_fd { + #[cfg(feature = "log")] + { + println!("[WASI ERR] Errno in path_filestat_get: Noent"); + println!("[WASI ERR] path error msg: {:?}", _e); + } + + forget(_e); + return Errno::Noent as i32; + } else { + path_fd.unwrap() as u32 + }; + + let ruxstat: Stat = libos!(stat(path_fd)).unwrap(); + libos!(close(path_fd)).unwrap(); + let stat = WasiFilestat{ + dev: ruxstat.st_dev, + ino: ruxstat.st_ino, + filetype: match ruxstat.st_mode >> 12 { + 2 => 2, // CharacterDevice + 4 => 3, // Directory + 8 => 4, // Regular file + _ => 0 // Unknown + }, + nlink: ruxstat.st_nlink, + size: ruxstat.st_size as u64, + atim: ruxstat.st_atime.tv_nsec as u64, + mtim: ruxstat.st_mtime.tv_nsec as u64 , + ctim: ruxstat.st_ctime.tv_nsec as u64, + }; + + let stat = (&stat) as *const _ as usize; + let stat = unsafe { + core::slice::from_raw_parts(stat as *const u8, core::mem::size_of::()) + }; + memory.write(&mut caller, buf as usize, stat).unwrap(); + + Errno::Success as i32 +} + +pub fn path_filestat_set_times(mut caller: Caller<'_, LibosCtx>, fd: i32, flags: i32, path: i32, path_len: i32, st_atim: i64, st_mtim: i64, fst_flags: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into path_filestat_set_times"); + println!( + "args: fd: {:?}, flags: {:?}, path: {:?}, path_len: {:?}, st_atim: {:?}, st_mtim: {:?}, fst_flags: {:?}", + fd, flags, path, path_len, st_atim, st_mtim, fst_flags + ); + println!("[Time] path_filestat_set_times: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +} + +pub fn path_link(mut caller: Caller<'_, LibosCtx>, old_fd: i32, old_flags: i32, old_path: i32, old_path_len: i32, new_fd: i32, new_path: i32, new_path_len: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into path_link"); + println!("args: old_fd: {:?}, old_flags: {:?}, old_path: {:?}, old_path_len: {:?}, new_fd: {:?}, new_path: {:?}, new_path_len: {:?}", old_fd, old_flags, old_path, old_path_len, new_fd, new_path, new_path_len); + println!("[Time] path_link: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +} + +pub fn path_open(mut caller: Caller<'_, LibosCtx>, fd: i32, dirflags: i32, path_addr: i32, path_len: i32, oflags: i32, fs_rights_base: i64, fs_rights_inheriting: i64, fdflags: i32, retptr: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into path_open"); + println!("args: fd: {:?}, dirflags: {:?}, path_addr: {:?}, path_len: {:?}, oflags: {:?}, fs_rights_base: {:?}, fs_rights_inheriting: {:?}, fdflags: {:?}, retptr: {:?}", fd as u32, dirflags as u32, path_addr as u32, path_len as u32, oflags as u16, format!("{:064b}", fs_rights_base as u64), format!("{:064b}", fs_rights_inheriting as u64), fdflags as u16, retptr as u32); + println!("[Time] path_open: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + let memory = caller.get_export("memory").unwrap().into_memory().unwrap(); + + let mut path: Vec = Vec::with_capacity(path_len as usize); + path.resize(path_len as usize, 0); + memory.read(&caller, path_addr as usize, &mut path).unwrap(); + let path = String::from_utf8(path).expect("[Err] Not a valid UTF-8 sequence"); + #[cfg(feature = "log")] + println!("path: {:?}", path); + + let mut flags: OpenFlags = OpenFlags::empty(); + if (fdflags as u16 & 1) == 1 { + flags |= OpenFlags::O_APPEND; + } + if (oflags as u16 & 1) == 1 { + flags |= OpenFlags::O_CREAT; + } + + let mut mode: OpenMode = OpenMode::empty(); + if ((fs_rights_base as u64 >> 1) & 1) == 1 { + mode |= OpenMode::RD; + } + if ((fs_rights_base as u64 >> 6) & 1) == 1 { + mode |= OpenMode::WR; + } + + // Todo: 将对应信息添加到table中,结构体struct {name, fs_flags, fs_rights_base, fs_rights_inheriting, kind} + // 其中,name是路径,fs_flags是Fdflags类型,fs_rights_base和fs_rights_inheriting直接存输入参数。 + // kind表示文件类型,是个enum。eg. File Dir + let path_fd: FdtabResult = libos!(open(&path, flags, mode)); + let path_fd = if let Err(_e) = path_fd { + #[cfg(feature = "log")] { + println!("[WASI ERR] Errno in path_open: Noent"); + println!("[WASI ERR] path error msg: {:?}", _e); + } + + forget(_e); + return Errno::Noent as i32; + } else { + path_fd.unwrap() as u32 + }; + + #[cfg(feature = "log")] + println!("return path_fd: {:?}", path_fd); + memory.write(&mut caller, retptr as usize, &path_fd.to_ne_bytes()).unwrap(); + // set fd2path table + set_fd2path(path_fd as u32, path); + Errno::Success as i32 +} + +pub fn path_readlink(mut caller: Caller<'_, LibosCtx>, dir_fd: i32, path: i32, path_len: i32, buf: i32, buf_len: i32, buf_used: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into path_readlink"); + println!("args: dir_fd: {:?}, path: {:?}, path_len: {:?}, buf: {:?}, buf_len: {:?}, buf_used: {:?}", dir_fd, path, path_len, buf, buf_len, buf_used); + println!("[Time] path_readlink: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +} + +pub fn path_remove_directory(mut caller: Caller<'_, LibosCtx>, fd: i32, path: i32, path_len: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into path_remove_directory"); + println!( + "args: fd: {:?}, path: {:?}, path_len: {:?}", + fd, path, path_len + ); + println!("[Time] path_remove_directory: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +} + +pub fn path_rename(mut caller: Caller<'_, LibosCtx>, old_fd: i32, old_path: i32, old_path_len: i32, new_fd: i32, new_path: i32, new_path_len: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into path_rename"); + println!("args: old_fd: {:?}, old_path: {:?}, old_path_len: {:?}, new_fd: {:?}, new_path: {:?}, new_path_len: {:?}", old_fd, old_path, old_path_len, new_fd, new_path, new_path_len); + println!("[Time] path_rename: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +} + +pub fn path_symlink(mut caller: Caller<'_, LibosCtx>, old_path: i32, old_path_len: i32, fd: i32, new_path: i32, new_path_len: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into path_symlink"); + println!( + "args: old_path: {:?}, old_path_len: {:?}, fd: {:?}, new_path: {:?}, new_path_len: {:?}", + old_path, old_path_len, fd, new_path, new_path_len + ); + println!("[Time] path_symlink: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +} + +pub fn path_unlink_file(mut caller: Caller<'_, LibosCtx>, fd: i32, path: i32, path_len: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into path_unlink_file"); + println!( + "args: fd: {:?}, path: {:?}, path_len: {:?}", + fd, path, path_len + ); + println!("[Time] path_unlink_file: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +} + +pub fn poll_oneoff(mut caller: Caller<'_, LibosCtx>, in_: i32, out_: i32, nsubscriptions: i32, nevents: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into poll_oneoff"); + println!( + "args: in_: {:?}, out_: {:?}, nsubscriptions: {:?}, nevents: {:?}", + in_, out_, nsubscriptions, nevents + ); + println!("[Time] poll_oneoff: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +} + +pub fn proc_exit(mut caller: Caller<'_, LibosCtx>, code: i32) { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into proc_exit"); + // An exit code of 0 indicates successful termination of the program. + println!("args: code: {:?}", code); + println!("[Time] proc_exit: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + match code { + 0 => { + let caller_id = &caller.data().id; + let jmpbuf = { + Arc::clone(JMP_BUF_MAP.lock().get(caller_id).unwrap()) + }; + unsafe { longjmp(jmpbuf.as_ref(), 1); }; + }, + _ => { panic!("[ERR] proc_exit got error code {:?}", code); } + } +} + +pub fn random_get(mut caller: Caller<'_, LibosCtx>, buf: i32, buf_len: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into random_get"); + println!("args: buf: {:?}, buf_len: {:?}", buf, buf_len); + println!("[Time] random_get: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + let memory = caller.get_export("memory").unwrap().into_memory().unwrap(); + let array: Vec = { + // LCG算法 + let mut seed = buf as u64; + let mut next_u8 = || { + const A: u64 = 1664525; + const C: u64 = 1013904223; + const MOD: u64 = 1 << 32; + seed = (A.wrapping_mul(seed).wrapping_add(C)) % MOD; + + (seed % 256) as u8 + }; + + (0..buf_len as usize).map(|_| next_u8()).collect() + }; + + #[cfg(feature = "log")] + println!("array: {:?}", array); + memory.write(&mut caller, buf as usize, &array).unwrap(); + + Errno::Success as i32 +} + +pub fn sched_yield(mut caller: Caller<'_, LibosCtx>) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into sched_yield"); + println!("[Time] sched_yield: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +} + +pub fn sock_accept(mut caller: Caller<'_, LibosCtx>, sock: i32, fd_flags: i32, ro_fd: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into sock_accept"); + println!( + "args: sock: {:?}, fd_flags: {:?}, ro_fd: {:?}", + sock, fd_flags, ro_fd + ); + println!("[Time] sock_accept: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +} + +pub fn sock_recv(mut caller: Caller<'_, LibosCtx>, sock: i32, ri_data: i32, ri_data_len: i32, ri_flags: i32, ro_data_len: i32, ro_flags: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into sock_recv"); + println!("args: sock: {:?}, ri_data: {:?}, ri_data_len: {:?}, ri_flags: {:?}, ro_data_len: {:?}, ro_flags: {:?}", sock, ri_data, ri_data_len, ri_flags, ro_data_len, ro_flags); + println!("[Time] sock_recv: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +} + +pub fn sock_send(mut caller: Caller<'_, LibosCtx>, sock: i32, si_data: i32, si_data_len: i32, si_flags: i32, ret_data_len: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into sock_send"); + println!( + "args: sock: {:?}, si_data: {:?}, si_data_len: {:?}, si_flags: {:?}, ret_data_len: {:?}", + sock, si_data, si_data_len, si_flags, ret_data_len + ); + println!("[Time] sock_send: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +} + +pub fn sock_shutdown(mut caller: Caller<'_, LibosCtx>, sock: i32, how: i32) -> i32 { + #[cfg(feature = "log")] + { + println!("[Debug] Invoke into sock_shutdown"); + println!("args: sock: {:?}, how: {:?}", sock, how); + println!("[Time] sock_shutdown: {}", SystemTime::now().duration_since(UNIX_EPOCH).as_micros() as f64 / 1000000f64); + } + + Errno::Success as i32 +}