diff --git a/Cargo.lock b/Cargo.lock index 9a2da8f47cd..a4aa7427890 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -46,15 +46,6 @@ dependencies = [ "libc", ] -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - [[package]] name = "anyhow" version = "1.0.65" @@ -96,6 +87,17 @@ dependencies = [ "wait-timeout", ] +[[package]] +name = "async-trait" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76464446b8bc32758d7e88ee1a804d9914cd9b1cb264c029899680b0be29826f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "atty" version = "0.2.14" @@ -149,34 +151,11 @@ dependencies = [ "serde", ] -[[package]] -name = "bindgen" -version = "0.56.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2da379dbebc0b76ef63ca68d8fc6e71c0f13e59432e0987e508c1820e6ab5239" -dependencies = [ - "bitflags", - "cexpr", - "clang-sys", - "clap 2.34.0", - "env_logger", - "lazy_static", - "lazycell", - "log", - "peeking_take_while", - "proc-macro2", - "quote", - "regex", - "rustc-hash", - "shlex", - "which", -] - [[package]] name = "bitflags" -version = "1.2.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "blake3" @@ -280,7 +259,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6358dedf60f4d9b8db43ad187391afe959746101346fe51bb978126bec61dfb" dependencies = [ "clap 3.2.21", - "heck", + "heck 0.4.0", "indexmap", "log", "proc-macro2", @@ -301,15 +280,6 @@ dependencies = [ "jobserver", ] -[[package]] -name = "cexpr" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27" -dependencies = [ - "nom 5.1.2", -] - [[package]] name = "cfg-if" version = "0.1.10" @@ -336,30 +306,15 @@ dependencies = [ "winapi", ] -[[package]] -name = "clang-sys" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a050e2153c5be08febd6734e29298e844fdb0fa21aeddd63b4eb7baa106c69b" -dependencies = [ - "glob", - "libc", - "libloading", -] - [[package]] name = "clap" version = "2.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ - "ansi_term", - "atty", "bitflags", - "strsim 0.8.0", "textwrap 0.11.0", "unicode-width", - "vec_map", ] [[package]] @@ -374,7 +329,7 @@ dependencies = [ "clap_lex", "indexmap", "once_cell", - "strsim 0.10.0", + "strsim", "termcolor", "textwrap 0.15.0", ] @@ -385,7 +340,7 @@ version = "3.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65" dependencies = [ - "heck", + "heck 0.4.0", "proc-macro-error", "proc-macro2", "quote", @@ -487,6 +442,12 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" +[[package]] +name = "convert_case" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb4a24b1aaf0fd0ce8b45161144d6f42cd91677fd5940fd431183eb023b3a2b8" + [[package]] name = "core-foundation-sys" version = "0.8.3" @@ -844,6 +805,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d9d8664cf849d7d0f3114a3a387d2f5e4303176d746d5a951aaddc66dfe9240" +[[package]] +name = "dlib" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac1b7517328c04c2aa68422fc60a41b92208182142ed04a25879c26c8f878794" +dependencies = [ + "libloading", +] + [[package]] name = "doc-comment" version = "0.3.3" @@ -929,19 +899,6 @@ dependencies = [ "syn", ] -[[package]] -name = "env_logger" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" -dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", -] - [[package]] name = "erased-serde" version = "0.3.23" @@ -1013,6 +970,95 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "futures" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f21eda599937fba36daeb58a22e8f5cee2d14c4a17b5b7739c7c8e5e3b8230c" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" + +[[package]] +name = "futures-executor" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ff63c23854bee61b6e9cd331d523909f238fc7636290b96826e9cfa5faa00ab" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbf4d2a7a308fd4578637c0b17c7e1c7ba127b8f6ba00b29f717e9655d85eb68" + +[[package]] +name = "futures-macro" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42cd15d1c7456c04dbdf7e88bcd69760d74f3a798d6444e16974b505b0e62f17" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" + +[[package]] +name = "futures-task" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" + +[[package]] +name = "futures-util" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + [[package]] name = "fxhash" version = "0.2.1" @@ -1136,6 +1182,15 @@ dependencies = [ "ahash", ] +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "heck" version = "0.4.0" @@ -1169,12 +1224,6 @@ dependencies = [ "webpki-roots", ] -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - [[package]] name = "iana-time-zone" version = "0.1.48" @@ -1189,6 +1238,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + [[package]] name = "ident_case" version = "1.0.1" @@ -1267,6 +1322,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", ] [[package]] @@ -1324,12 +1382,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - [[package]] name = "leb128" version = "0.2.5" @@ -1449,21 +1501,28 @@ dependencies = [ [[package]] name = "minifb" -version = "0.19.3" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b6e41119d1667465608d36488fa5dcd228057a26c156e25f17f492f38435124" +checksum = "d9e21c5f89bb820c7878c300c5b944e65de0f1b2a75e0be92ce670b95943740e" dependencies = [ "cc", + "dlib", + "futures", + "instant", + "js-sys", + "lazy_static", + "libc", "orbclient", - "raw-window-handle 0.3.4", + "raw-window-handle 0.4.3", + "serde", + "serde_derive", "tempfile", + "wasm-bindgen-futures", "wayland-client", "wayland-cursor", "wayland-protocols", "winapi", "x11-dl", - "xkb", - "xkbcommon-sys", ] [[package]] @@ -1498,25 +1557,28 @@ checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" [[package]] name = "nix" -version = "0.20.2" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5e06129fb611568ef4e868c14b326274959aa70ff7776e9d55323531c374945" +checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc" dependencies = [ "bitflags", - "cc", "cfg-if 1.0.0", "libc", "memoffset", ] [[package]] -name = "nom" -version = "5.1.2" +name = "nix" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af" +checksum = "e322c04a9e3440c327fca7b6c8a63e6890a32fa2ad689db972425f07e0d22abb" dependencies = [ - "memchr", - "version_check", + "autocfg", + "bitflags", + "cfg-if 1.0.0", + "libc", + "memoffset", + "pin-utils", ] [[package]] @@ -1658,12 +1720,6 @@ version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1" -[[package]] -name = "peeking_take_while" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" - [[package]] name = "pest" version = "2.3.1" @@ -1680,6 +1736,12 @@ version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "pkg-config" version = "0.3.25" @@ -1845,6 +1907,17 @@ dependencies = [ "syn", ] +[[package]] +name = "pulldown-cmark" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffade02495f22453cd593159ea2f59827aae7f53fa8323f756799b670881dcf8" +dependencies = [ + "bitflags", + "memchr", + "unicase", +] + [[package]] name = "quote" version = "1.0.21" @@ -1877,9 +1950,9 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ "getrandom", ] @@ -2068,12 +2141,6 @@ version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" -[[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.2.3" @@ -2335,12 +2402,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "shlex" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" - [[package]] name = "slab" version = "0.4.7" @@ -2432,12 +2493,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" -[[package]] -name = "strsim" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - [[package]] name = "strsim" version = "0.10.0" @@ -2637,6 +2692,21 @@ dependencies = [ "serde_json", ] +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + [[package]] name = "toml" version = "0.5.9" @@ -2771,12 +2841,33 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" +[[package]] +name = "unicode-normalization" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-segmentation" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a" + [[package]] name = "unicode-width" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + [[package]] name = "unix_mode" version = "0.1.3" @@ -2789,12 +2880,6 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - [[package]] name = "version-compare" version = "0.1.0" @@ -2845,6 +2930,14 @@ dependencies = [ "wast 24.0.0", ] +[[package]] +name = "wasi-types-generator-extra" +version = "0.1.0" +dependencies = [ + "convert_case", + "wasmer-wit-parser", +] + [[package]] name = "wasm-bindgen" version = "0.2.83" @@ -3399,7 +3492,7 @@ name = "wasmer-wasi-experimental-io-devices" version = "3.0.0-beta.2" dependencies = [ "minifb", - "nix", + "nix 0.25.0", "ref_thread_local", "serde", "tracing", @@ -3422,10 +3515,16 @@ name = "wasmer-wasi-types" version = "3.0.0-beta.2" dependencies = [ "byteorder", + "pretty_assertions", "serde", "time", + "wasmer", "wasmer-derive", "wasmer-types", + "wasmer-wit-bindgen-gen-core", + "wasmer-wit-bindgen-gen-rust-wasm", + "wasmer-wit-bindgen-rust", + "wasmer-wit-parser", ] [[package]] @@ -3442,6 +3541,73 @@ dependencies = [ "wast 38.0.1", ] +[[package]] +name = "wasmer-wit-bindgen-gen-core" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff8aa5be5ae5d61f5e151dc2c0e603093fe28395d2083b65ef7a3547844054fe" +dependencies = [ + "anyhow", + "wasmer-wit-parser", +] + +[[package]] +name = "wasmer-wit-bindgen-gen-rust" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "438bce7c4589842bf100cc9b312443a9b5fc6440e58ab0b8c114e460219c3c3b" +dependencies = [ + "heck 0.3.3", + "wasmer-wit-bindgen-gen-core", +] + +[[package]] +name = "wasmer-wit-bindgen-gen-rust-wasm" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "505f5168cfee591840e13e158a5c5e2f95d6df1df710839021564f36bee7bafc" +dependencies = [ + "heck 0.3.3", + "wasmer-wit-bindgen-gen-core", + "wasmer-wit-bindgen-gen-rust", +] + +[[package]] +name = "wasmer-wit-bindgen-rust" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "968747f1271f74aab9b70d9c5d4921db9bd13b4ec3ba5506506e6e7dc58c918c" +dependencies = [ + "async-trait", + "bitflags", + "wasmer-wit-bindgen-rust-impl", +] + +[[package]] +name = "wasmer-wit-bindgen-rust-impl" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd26fe00d08bd2119870b017d13413dfbd51e7750b6634d649fc7a7bbc057b85" +dependencies = [ + "proc-macro2", + "syn", + "wasmer-wit-bindgen-gen-core", + "wasmer-wit-bindgen-gen-rust-wasm", +] + +[[package]] +name = "wasmer-wit-parser" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46c9a15086be8a2eb3790613902b9d3a9a687833b17cd021de263a20378585a" +dependencies = [ + "anyhow", + "id-arena", + "pulldown-cmark", + "unicode-normalization", + "unicode-xid", +] + [[package]] name = "wasmer-workspace" version = "3.0.0-beta.2" @@ -3540,14 +3706,15 @@ dependencies = [ [[package]] name = "wayland-client" -version = "0.28.6" +version = "0.29.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3ab332350e502f159382201394a78e3cc12d0f04db863429260164ea40e0355" +checksum = "3f3b068c05a039c9f755f881dc50f01732214f5685e379829759088967c46715" dependencies = [ "bitflags", "downcast-rs", "libc", - "nix", + "nix 0.24.2", + "scoped-tls", "wayland-commons", "wayland-scanner", "wayland-sys", @@ -3555,11 +3722,11 @@ dependencies = [ [[package]] name = "wayland-commons" -version = "0.28.6" +version = "0.29.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a21817947c7011bbd0a27e11b17b337bfd022e8544b071a2641232047966fbda" +checksum = "8691f134d584a33a6606d9d717b95c4fa20065605f798a3f350d78dced02a902" dependencies = [ - "nix", + "nix 0.24.2", "once_cell", "smallvec", "wayland-sys", @@ -3567,20 +3734,20 @@ dependencies = [ [[package]] name = "wayland-cursor" -version = "0.28.6" +version = "0.29.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be610084edd1586d45e7bdd275fe345c7c1873598caa464c4fb835dee70fa65a" +checksum = "6865c6b66f13d6257bef1cd40cbfe8ef2f150fb8ebbdb1e8e873455931377661" dependencies = [ - "nix", + "nix 0.24.2", "wayland-client", "xcursor", ] [[package]] name = "wayland-protocols" -version = "0.28.6" +version = "0.29.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "286620ea4d803bacf61fa087a4242ee316693099ee5a140796aaba02b29f861f" +checksum = "b950621f9354b322ee817a23474e479b34be96c2e909c14f7bc0100e9a970bc6" dependencies = [ "bitflags", "wayland-client", @@ -3590,9 +3757,9 @@ dependencies = [ [[package]] name = "wayland-scanner" -version = "0.28.6" +version = "0.29.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce923eb2deb61de332d1f356ec7b6bf37094dc5573952e1c8936db03b54c03f1" +checksum = "8f4303d8fa22ab852f789e75a967f0a2cdc430a607751c0499bada3e451cbd53" dependencies = [ "proc-macro2", "quote", @@ -3601,10 +3768,12 @@ dependencies = [ [[package]] name = "wayland-sys" -version = "0.28.6" +version = "0.29.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d841fca9aed7febf9bed2e9796c49bf58d4152ceda8ac949ebe00868d8f0feb8" +checksum = "be12ce1a3c39ec7dba25594b97b42cb3195d54953ddb9d3d95a7c3902bc6e9d4" dependencies = [ + "dlib", + "lazy_static", "pkg-config", ] @@ -3637,15 +3806,6 @@ dependencies = [ "webpki", ] -[[package]] -name = "which" -version = "3.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d011071ae14a2f6671d0b74080ae0cd8ebf3a6f8c9589a2cd45f23126fe29724" -dependencies = [ - "libc", -] - [[package]] name = "winapi" version = "0.3.9" @@ -3780,29 +3940,7 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "463705a63313cd4301184381c5e8042f0a7e9b4bb63653f216311d4ae74690b7" dependencies = [ - "nom 7.1.1", -] - -[[package]] -name = "xkb" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aec02bc5de902aa579f3d2f2c522edaf40fa42963cbaffe645b058ddcc68fdb2" -dependencies = [ - "bitflags", - "libc", - "xkbcommon-sys", -] - -[[package]] -name = "xkbcommon-sys" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a001b79d45b0b4541c228a501177f2b35db976bf7ee3f7fce8fa2381554ab5" -dependencies = [ - "bindgen", - "libc", - "pkg-config", + "nom", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 6ed449f5f8b..783aa175f5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,7 @@ members = [ "lib/vm", "lib/wasi", "lib/wasi-types", + "lib/wasi-types/wasi-types-generator-extra", "lib/wasi-experimental-io-devices", "lib/wasi-local-networking", "lib/c-api/tests/wasmer-c-api-test-runner", diff --git a/lib/api/src/js/externals/memory_view.rs b/lib/api/src/js/externals/memory_view.rs index 45863229d5f..a219572207e 100644 --- a/lib/api/src/js/externals/memory_view.rs +++ b/lib/api/src/js/externals/memory_view.rs @@ -58,6 +58,35 @@ impl<'a> MemoryView<'a> { self.size } + // TODO: do we want a proper implementation here instead? + /// Retrieve a slice of the memory contents. + /// + /// # Safety + /// + /// Until the returned slice is dropped, it is undefined behaviour to + /// modify the memory contents in any way including by calling a wasm + /// function that writes to the memory or by resizing the memory. + #[doc(hidden)] + pub unsafe fn data_unchecked(&self) -> &[u8] { + unimplemented!("direct data pointer access is not possible in JavaScript"); + } + + // TODO: do we want a proper implementation here instead? + /// Retrieve a mutable slice of the memory contents. + /// + /// # Safety + /// + /// This method provides interior mutability without an UnsafeCell. Until + /// the returned value is dropped, it is undefined behaviour to read or + /// write to the pointed-to memory in any way except through this slice, + /// including by calling a wasm function that reads the memory contents or + /// by resizing this Memory. + #[allow(clippy::mut_from_ref)] + #[doc(hidden)] + pub unsafe fn data_unchecked_mut(&self) -> &mut [u8] { + unimplemented!("direct data pointer access is not possible in JavaScript"); + } + /// Returns the size (in [`Pages`]) of the `Memory`. /// /// # Example diff --git a/lib/api/src/sys/module.rs b/lib/api/src/sys/module.rs index 24e372663bb..4b6807178ae 100644 --- a/lib/api/src/sys/module.rs +++ b/lib/api/src/sys/module.rs @@ -234,7 +234,9 @@ impl Module { } /// Serializes a module into a binary representation that the `Engine` - /// can later process via [`Module::deserialize`]. + /// can later process via + #[cfg_attr(feature = "compiler", doc = "[`Module::deserialize`].")] + #[cfg_attr(not(feature = "compiler"), doc = "`Module::deserialize`.")] /// /// # Usage /// @@ -252,7 +254,9 @@ impl Module { } /// Serializes a module into a file that the `Engine` - /// can later process via [`Module::deserialize_from_file`]. + /// can later process via + #[cfg_attr(feature = "compiler", doc = "[`Module::deserialize_from_file`].")] + #[cfg_attr(not(feature = "compiler"), doc = "`Module::deserialize_from_file`.")] /// /// # Usage /// diff --git a/lib/api/src/sys/store.rs b/lib/api/src/sys/store.rs index 542ef61f7e2..e8d7ea44a37 100644 --- a/lib/api/src/sys/store.rs +++ b/lib/api/src/sys/store.rs @@ -26,7 +26,9 @@ pub(crate) struct StoreInner { /// /// The `Store` holds the engine (that is —amongst many things— used to compile /// the Wasm bytes into a valid module artifact), in addition to the -/// [`Tunables`] (that are used to create the memories, tables and globals). +#[cfg_attr(feature = "compiler", doc = "[`Tunables`]")] +#[cfg_attr(not(feature = "compiler"), doc = "`Tunables`")] +/// (that are used to create the memories, tables and globals). /// /// Spec: pub struct Store { diff --git a/lib/types/src/value.rs b/lib/types/src/value.rs index 2347832cc03..e07d2d5231e 100644 --- a/lib/types/src/value.rs +++ b/lib/types/src/value.rs @@ -98,6 +98,7 @@ macro_rules! primitives { )*) } primitives! { + bool i8 u8 i16 u16 i32 u32 diff --git a/lib/wasi-experimental-io-devices/Cargo.toml b/lib/wasi-experimental-io-devices/Cargo.toml index d409a30be77..9996fac8afa 100644 --- a/lib/wasi-experimental-io-devices/Cargo.toml +++ b/lib/wasi-experimental-io-devices/Cargo.toml @@ -16,8 +16,8 @@ maintenance = { status = "experimental" } [dependencies] wasmer-wasi = { version = "=3.0.0-beta.2", path = "../wasi", default-features=false } tracing = "0.1" -minifb = { version = "0.19", optional = true } -nix = "0.20.2" +minifb = { version = "0.23", optional = true } +nix = "0.25.0" ref_thread_local = "0.1" serde = "1" typetag = "0.1" diff --git a/lib/wasi-experimental-io-devices/src/link-ext.rs b/lib/wasi-experimental-io-devices/src/link-ext.rs index d549810b52c..6ebfc5ad7b5 100644 --- a/lib/wasi-experimental-io-devices/src/link-ext.rs +++ b/lib/wasi-experimental-io-devices/src/link-ext.rs @@ -5,7 +5,10 @@ use std::collections::{BTreeSet, VecDeque}; use std::convert::TryInto; use std::io::{Read, Seek, SeekFrom, Write}; use tracing::debug; -use wasmer_wasi::{types::*, WasiInodes}; +use wasmer_wasi::{ + types::{wasi::Filesize, *}, + WasiInodes, +}; use wasmer_wasi::{Fd, VirtualFile, WasiFs, WasiFsError, ALL_RIGHTS, VIRTUAL_ROOT_FD}; use minifb::{Key, KeyRepeat, MouseButton, Scale, Window, WindowOptions}; @@ -417,7 +420,7 @@ impl VirtualFile for FrameBuffer { fn size(&self) -> u64 { 0 } - fn set_len(&mut self, _new_size: __wasi_filesize_t) -> Result<(), WasiFsError> { + fn set_len(&mut self, _new_size: Filesize) -> Result<(), WasiFsError> { Ok(()) } fn unlink(&mut self) -> Result<(), WasiFsError> { diff --git a/lib/wasi-types/.gitignore b/lib/wasi-types/.gitignore new file mode 100644 index 00000000000..6c8fbf34887 --- /dev/null +++ b/lib/wasi-types/.gitignore @@ -0,0 +1 @@ +wit-bindgen/ \ No newline at end of file diff --git a/lib/wasi-types/Cargo.toml b/lib/wasi-types/Cargo.toml index 4c1bc489968..33b41bf84c4 100644 --- a/lib/wasi-types/Cargo.toml +++ b/lib/wasi-types/Cargo.toml @@ -10,12 +10,24 @@ license = "MIT" readme = "README.md" edition = "2018" +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + [dependencies] +wasmer = { default-features = false, path = "../api", version = "3.0.0-beta" } +wit-bindgen-rust = { package = "wasmer-wit-bindgen-rust", version = "0.1.1" } +wit-bindgen-rust-wasm = { package = "wasmer-wit-bindgen-gen-rust-wasm", version = "0.1.1" } +wit-bindgen-core = { package = "wasmer-wit-bindgen-gen-core", version = "0.1.1" } +wit-parser = { package = "wasmer-wit-parser", version = "0.1.1" } wasmer-types = { path = "../types", version = "=3.0.0-beta.2" } wasmer-derive = { path = "../derive", version = "=3.0.0-beta.2" } serde = { version = "1.0", features = ["derive"], optional = true } byteorder = "1.3" time = "0.2" +[dev-dependencies.pretty_assertions] +version = "1.3.0" + [features] enable-serde = ["serde", "wasmer-types/serde"] +js = ["wasmer/js"] +sys = ["wasmer/sys"] diff --git a/lib/wasi-types/README.md b/lib/wasi-types/README.md index 96010bacf45..43da4e41a3c 100644 --- a/lib/wasi-types/README.md +++ b/lib/wasi-types/README.md @@ -1,3 +1,11 @@ # `wasmer-wasi-types` [![Build Status](https://github.com/wasmerio/wasmer/workflows/build/badge.svg?style=flat-square)](https://github.com/wasmerio/wasmer/actions?query=workflow%3Abuild) [![Join Wasmer Slack](https://img.shields.io/static/v1?label=Slack&message=join%20chat&color=brighgreen&style=flat-square)](https://slack.wasmer.io) [![MIT License](https://img.shields.io/github/license/wasmerio/wasmer.svg?style=flat-square)](https://github.com/wasmerio/wasmer/blob/master/LICENSE) [![crates.io](https://img.shields.io/crates/v/wasmer-wasi-types.svg)](https://crates.io/crates/wasmer-wasi-types) This crate contains the WASI types necessary for `wasmer-wasi`. Please check this crate to learn more! + +--- + +Run `regenerate.sh` to regenerate the wasi-types from +the `wasi-clean/typenames.wit` into the final Rust bindings. + +The `wasi-types-generator-extra` generates some extra code +that wit-bindgen currently can't provide. \ No newline at end of file diff --git a/lib/wasi-types/regenerate.sh b/lib/wasi-types/regenerate.sh new file mode 100755 index 00000000000..0264c473090 --- /dev/null +++ b/lib/wasi-types/regenerate.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +BASEDIR=$(dirname "$0") + +rm -f \ + "$BASEDIR"/src/bindings.rs \ + "$BASEDIR"/src/*/bindings.rs + +cat "$BASEDIR"/wit-clean/typenames.wit "$BASEDIR"/wit-clean/wasi_unstable.wit > "$BASEDIR"/wit-clean/output.wit + +git clone https://github.com/wasmerio/wit-bindgen --branch force-generate-structs --single-branch +git pull origin force-generate-structs +cd wit-bindgen +cargo build +cd .. + +./wit-bindgen/target/debug/wit-bindgen rust-wasm \ + --import "$BASEDIR"/wit-clean/output.wit \ + --force-generate-structs \ + --out-dir "$BASEDIR"/src/wasi \ + +awk '{sub(/mod output/,"pub mod output")}1' src/wasi/bindings.rs > src/wasi/bindings2.rs +cargo fmt --all +cp src/wasi/bindings2.rs src/wasi/bindings.rs +rm src/wasi/bindings2.rs + +cd ./wasi-types-generator-extra +cargo build +pwd +../../../target/debug/wasi-types-generator-extra +cd .. + +cargo fmt --all \ No newline at end of file diff --git a/lib/wasi-types/src/advice.rs b/lib/wasi-types/src/advice.rs deleted file mode 100644 index 55cf4aebcd2..00000000000 --- a/lib/wasi-types/src/advice.rs +++ /dev/null @@ -1,7 +0,0 @@ -pub type __wasi_advice_t = u8; -pub const __WASI_ADVICE_NORMAL: u8 = 0; -pub const __WASI_ADVICE_SEQUENTIAL: u8 = 1; -pub const __WASI_ADVICE_RANDOM: u8 = 2; -pub const __WASI_ADVICE_WILLNEED: u8 = 3; -pub const __WASI_ADVICE_DONTNEED: u8 = 4; -pub const __WASI_ADVICE_NOREUSE: u8 = 5; diff --git a/lib/wasi-types/src/bus.rs b/lib/wasi-types/src/bus.rs deleted file mode 100644 index ff8bea2ecb3..00000000000 --- a/lib/wasi-types/src/bus.rs +++ /dev/null @@ -1,113 +0,0 @@ -use super::*; -use wasmer_derive::ValueType; -use wasmer_types::MemorySize; - -pub type __wasi_busdataformat_t = u8; -pub const __WASI_BUS_DATA_FORMAT_RAW: __wasi_busdataformat_t = 0; -pub const __WASI_BUS_DATA_FORMAT_BINCODE: __wasi_busdataformat_t = 1; -pub const __WASI_BUS_DATA_FORMAT_MESSAGE_PACK: __wasi_busdataformat_t = 2; -pub const __WASI_BUS_DATA_FORMAT_JSON: __wasi_busdataformat_t = 3; -pub const __WASI_BUS_DATA_FORMAT_YAML: __wasi_busdataformat_t = 4; -pub const __WASI_BUS_DATA_FORMAT_XML: __wasi_busdataformat_t = 5; -pub const __WASI_BUS_DATA_FORMAT_RKYV: __wasi_busdataformat_t = 6; - -pub type __wasi_buseventtype_t = u8; -pub const __WASI_BUS_EVENT_TYPE_NOOP: __wasi_buseventtype_t = 0; -pub const __WASI_BUS_EVENT_TYPE_EXIT: __wasi_buseventtype_t = 1; -pub const __WASI_BUS_EVENT_TYPE_CALL: __wasi_buseventtype_t = 2; -pub const __WASI_BUS_EVENT_TYPE_RESULT: __wasi_buseventtype_t = 3; -pub const __WASI_BUS_EVENT_TYPE_FAULT: __wasi_buseventtype_t = 4; -pub const __WASI_BUS_EVENT_TYPE_CLOSE: __wasi_buseventtype_t = 5; - -pub type __wasi_bid_t = u32; - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_option_bid_t { - pub tag: __wasi_option_t, - pub bid: __wasi_bid_t, -} - -pub type __wasi_cid_t = u8; - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_option_fd_t { - pub tag: __wasi_option_t, - pub fd: __wasi_fd_t, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_option_cid_t { - pub tag: __wasi_option_t, - pub cid: __wasi_cid_t, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_bus_handles_t { - pub bid: __wasi_bid_t, - pub stdin: __wasi_option_fd_t, - pub stdout: __wasi_option_fd_t, - pub stderr: __wasi_option_fd_t, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_busevent_exit_t { - pub bid: __wasi_bid_t, - pub rval: __wasi_exitcode_t, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_busevent_call_t { - pub parent: __wasi_option_cid_t, - pub cid: __wasi_cid_t, - pub format: __wasi_busdataformat_t, - pub topic_ptr: M::Offset, - pub topic_len: M::Offset, - pub buf_ptr: M::Offset, - pub buf_len: M::Offset, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_busevent_result_t { - pub format: __wasi_busdataformat_t, - pub cid: __wasi_cid_t, - pub buf_ptr: M::Offset, - pub buf_len: M::Offset, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_busevent_fault_t { - pub cid: __wasi_cid_t, - pub err: __bus_errno_t, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_busevent_close_t { - pub cid: __wasi_cid_t, -} - -#[derive(Copy, Clone)] -#[repr(C)] -pub union __wasi_busevent_u { - pub noop: u8, - pub exit: __wasi_busevent_exit_t, - pub call: __wasi_busevent_call_t, - pub result: __wasi_busevent_result_t, - pub fault: __wasi_busevent_fault_t, - pub close: __wasi_busevent_close_t, -} - -#[derive(Copy, Clone)] -#[repr(C)] -pub struct __wasi_busevent_t { - pub tag: __wasi_buseventtype_t, - pub u: __wasi_busevent_u, -} diff --git a/lib/wasi-types/src/directory.rs b/lib/wasi-types/src/directory.rs deleted file mode 100644 index d43b709f61f..00000000000 --- a/lib/wasi-types/src/directory.rs +++ /dev/null @@ -1,60 +0,0 @@ -use crate::*; -use std::mem; -use wasmer_derive::ValueType; - -pub type __wasi_dircookie_t = u64; -pub const __WASI_DIRCOOKIE_START: u64 = 0; - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_dirent_t { - pub d_next: __wasi_dircookie_t, - pub d_ino: __wasi_inode_t, - pub d_namlen: u32, - pub d_type: __wasi_filetype_t, -} - -pub fn dirent_to_le_bytes(ent: &__wasi_dirent_t) -> Vec { - let out: Vec = std::iter::empty() - .chain(ent.d_next.to_le_bytes()) - .chain(ent.d_ino.to_le_bytes()) - .chain(ent.d_namlen.to_le_bytes()) - .chain(u32::from(ent.d_type).to_le_bytes()) - .collect(); - - assert_eq!(out.len(), mem::size_of::<__wasi_dirent_t>()); - out -} - -#[cfg(test)] -mod tests { - use super::{__wasi_dirent_t, dirent_to_le_bytes}; - - #[test] - fn test_dirent_to_le_bytes() { - let s = __wasi_dirent_t { - d_next: 0x0123456789abcdef, - d_ino: 0xfedcba9876543210, - d_namlen: 0xaabbccdd, - d_type: 0x99, - }; - - assert_eq!( - vec![ - // d_next - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, - // - // d_ino - 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe, - // - // d_namelen - 0xdd, 0xcc, 0xbb, 0xaa, - // - // d_type - // plus padding - 0x99, 0x00, 0x00, 0x00, - ], - dirent_to_le_bytes(&s) - ); - } -} diff --git a/lib/wasi-types/src/error.rs b/lib/wasi-types/src/error.rs deleted file mode 100644 index fa1bf528126..00000000000 --- a/lib/wasi-types/src/error.rs +++ /dev/null @@ -1,100 +0,0 @@ -pub type __wasi_errno_t = u16; -pub const __WASI_ESUCCESS: u16 = 0; -pub const __WASI_E2BIG: u16 = 1; -pub const __WASI_EACCES: u16 = 2; -pub const __WASI_EADDRINUSE: u16 = 3; -pub const __WASI_EADDRNOTAVAIL: u16 = 4; -pub const __WASI_EAFNOSUPPORT: u16 = 5; -pub const __WASI_EAGAIN: u16 = 6; -pub const __WASI_EALREADY: u16 = 7; -pub const __WASI_EBADF: u16 = 8; -pub const __WASI_EBADMSG: u16 = 9; -pub const __WASI_EBUSY: u16 = 10; -pub const __WASI_ECANCELED: u16 = 11; -pub const __WASI_ECHILD: u16 = 12; -pub const __WASI_ECONNABORTED: u16 = 13; -pub const __WASI_ECONNREFUSED: u16 = 14; -pub const __WASI_ECONNRESET: u16 = 15; -pub const __WASI_EDEADLK: u16 = 16; -pub const __WASI_EDESTADDRREQ: u16 = 17; -pub const __WASI_EDOM: u16 = 18; -pub const __WASI_EDQUOT: u16 = 19; -pub const __WASI_EEXIST: u16 = 20; -pub const __WASI_EFAULT: u16 = 21; -pub const __WASI_EFBIG: u16 = 22; -pub const __WASI_EHOSTUNREACH: u16 = 23; -pub const __WASI_EIDRM: u16 = 24; -pub const __WASI_EILSEQ: u16 = 25; -pub const __WASI_EINPROGRESS: u16 = 26; -pub const __WASI_EINTR: u16 = 27; -pub const __WASI_EINVAL: u16 = 28; -pub const __WASI_EIO: u16 = 29; -pub const __WASI_EISCONN: u16 = 30; -pub const __WASI_EISDIR: u16 = 31; -pub const __WASI_ELOOP: u16 = 32; -pub const __WASI_EMFILE: u16 = 33; -pub const __WASI_EMLINK: u16 = 34; -pub const __WASI_EMSGSIZE: u16 = 35; -pub const __WASI_EMULTIHOP: u16 = 36; -pub const __WASI_ENAMETOOLONG: u16 = 37; -pub const __WASI_ENETDOWN: u16 = 38; -pub const __WASI_ENETRESET: u16 = 39; -pub const __WASI_ENETUNREACH: u16 = 40; -pub const __WASI_ENFILE: u16 = 41; -pub const __WASI_ENOBUFS: u16 = 42; -pub const __WASI_ENODEV: u16 = 43; -pub const __WASI_ENOENT: u16 = 44; -pub const __WASI_ENOEXEC: u16 = 45; -pub const __WASI_ENOLCK: u16 = 46; -pub const __WASI_ENOLINK: u16 = 47; -pub const __WASI_ENOMEM: u16 = 48; -pub const __WASI_ENOMSG: u16 = 49; -pub const __WASI_ENOPROTOOPT: u16 = 50; -pub const __WASI_ENOSPC: u16 = 51; -pub const __WASI_ENOSYS: u16 = 52; -pub const __WASI_ENOTCONN: u16 = 53; -pub const __WASI_ENOTDIR: u16 = 54; -pub const __WASI_ENOTEMPTY: u16 = 55; -pub const __WASI_ENOTRECOVERABLE: u16 = 56; -pub const __WASI_ENOTSOCK: u16 = 57; -pub const __WASI_ENOTSUP: u16 = 58; -pub const __WASI_ENOTTY: u16 = 59; -pub const __WASI_ENXIO: u16 = 60; -pub const __WASI_EOVERFLOW: u16 = 61; -pub const __WASI_EOWNERDEAD: u16 = 62; -pub const __WASI_EPERM: u16 = 63; -pub const __WASI_EPIPE: u16 = 64; -pub const __WASI_EPROTO: u16 = 65; -pub const __WASI_EPROTONOSUPPORT: u16 = 66; -pub const __WASI_EPROTOTYPE: u16 = 67; -pub const __WASI_ERANGE: u16 = 68; -pub const __WASI_EROFS: u16 = 69; -pub const __WASI_ESPIPE: u16 = 70; -pub const __WASI_ESRCH: u16 = 71; -pub const __WASI_ESTALE: u16 = 72; -pub const __WASI_ETIMEDOUT: u16 = 73; -pub const __WASI_ETXTBSY: u16 = 74; -pub const __WASI_EXDEV: u16 = 75; -pub const __WASI_ENOTCAPABLE: u16 = 76; - -pub type __bus_errno_t = u32; -pub const __BUS_ESUCCESS: u32 = 0; -pub const __BUS_ESER: u32 = 1; -pub const __BUS_EDES: u32 = 2; -pub const __BUS_EWAPM: u32 = 3; -pub const __BUS_EFETCH: u32 = 4; -pub const __BUS_ECOMPILE: u32 = 5; -pub const __BUS_EABI: u32 = 6; -pub const __BUS_EABORTED: u32 = 7; -pub const __BUS_EBADHANDLE: u32 = 8; -pub const __BUS_ETOPIC: u32 = 9; -pub const __BUS_EBADCB: u32 = 10; -pub const __BUS_EUNSUPPORTED: u32 = 11; -pub const __BUS_EBADREQUEST: u32 = 12; -pub const __BUS_EDENIED: u32 = 13; -pub const __BUS_EINTERNAL: u32 = 14; -pub const __BUS_EALLOC: u32 = 15; -pub const __BUS_EINVOKE: u32 = 16; -pub const __BUS_ECONSUMED: u32 = 17; -pub const __BUS_EMEMVIOLATION: u32 = 18; -pub const __BUS_EUNKNOWN: u32 = 19; diff --git a/lib/wasi-types/src/event.rs b/lib/wasi-types/src/event.rs deleted file mode 100644 index c368f5b9b5a..00000000000 --- a/lib/wasi-types/src/event.rs +++ /dev/null @@ -1,126 +0,0 @@ -use crate::*; -use std::{ - fmt, - mem::{self, MaybeUninit}, -}; -use wasmer_derive::ValueType; -use wasmer_types::ValueType; - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_event_fd_readwrite_t { - pub nbytes: __wasi_filesize_t, - pub flags: __wasi_eventrwflags_t, -} - -#[derive(Copy, Clone)] -#[repr(C)] -pub union __wasi_event_u { - pub fd_readwrite: __wasi_event_fd_readwrite_t, -} - -// TODO: remove this implementation of Debug when `__wasi_event_u` gets more than 1 variant -impl fmt::Debug for __wasi_event_u { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("__wasi_event_u") - .field("fd_readwrite", unsafe { &self.fd_readwrite }) - .finish() - } -} - -#[derive(Debug, Copy, Clone)] -pub enum EventEnum { - FdReadWrite { - nbytes: __wasi_filesize_t, - flags: __wasi_eventrwflags_t, - }, -} - -impl EventEnum { - pub fn untagged(self) -> __wasi_event_u { - match self { - EventEnum::FdReadWrite { nbytes, flags } => __wasi_event_u { - fd_readwrite: __wasi_event_fd_readwrite_t { nbytes, flags }, - }, - } - } -} - -#[derive(Debug, Copy, Clone)] -#[repr(C)] -pub struct __wasi_event_t { - pub userdata: __wasi_userdata_t, - pub error: __wasi_errno_t, - pub type_: __wasi_eventtype_t, - pub u: __wasi_event_u, -} - -impl __wasi_event_t { - pub fn tagged(&self) -> Option { - match self.type_ { - __WASI_EVENTTYPE_FD_READ | __WASI_EVENTTYPE_FD_WRITE => Some(EventEnum::FdReadWrite { - nbytes: unsafe { self.u.fd_readwrite.nbytes }, - flags: unsafe { self.u.fd_readwrite.flags }, - }), - _ => None, - } - } -} - -unsafe impl ValueType for __wasi_event_t { - fn zero_padding_bytes(&self, bytes: &mut [MaybeUninit]) { - macro_rules! field { - ($($f:tt)*) => { - &self.$($f)* as *const _ as usize - self as *const _ as usize - }; - } - macro_rules! field_end { - ($($f:tt)*) => { - field!($($f)*) + mem::size_of_val(&self.$($f)*) - }; - } - macro_rules! zero { - ($start:expr, $end:expr) => { - for i in $start..$end { - bytes[i] = MaybeUninit::new(0); - } - }; - } - self.userdata - .zero_padding_bytes(&mut bytes[field!(userdata)..field_end!(userdata)]); - zero!(field_end!(userdata), field!(error)); - self.error - .zero_padding_bytes(&mut bytes[field!(error)..field_end!(error)]); - zero!(field_end!(error), field!(type_)); - self.type_ - .zero_padding_bytes(&mut bytes[field!(type_)..field_end!(type_)]); - zero!(field_end!(type_), field!(u)); - match self.type_ { - __WASI_EVENTTYPE_FD_READ | __WASI_EVENTTYPE_FD_WRITE => unsafe { - self.u.fd_readwrite.zero_padding_bytes( - &mut bytes[field!(u.fd_readwrite)..field_end!(u.fd_readwrite)], - ); - zero!(field_end!(u.fd_readwrite), field_end!(u)); - }, - _ => zero!(field!(u), field_end!(u)), - } - zero!(field_end!(u), mem::size_of_val(self)); - } -} - -pub type __wasi_eventrwflags_t = u16; -pub const __WASI_EVENT_FD_READWRITE_HANGUP: u16 = 1 << 0; - -pub type __wasi_eventtype_t = u8; -pub const __WASI_EVENTTYPE_CLOCK: u8 = 0; -pub const __WASI_EVENTTYPE_FD_READ: u8 = 1; -pub const __WASI_EVENTTYPE_FD_WRITE: u8 = 2; - -pub fn eventtype_to_str(event_type: __wasi_eventtype_t) -> &'static str { - match event_type { - __WASI_EVENTTYPE_CLOCK => "__WASI_EVENTTYPE_CLOCK", - __WASI_EVENTTYPE_FD_READ => "__WASI_EVENTTYPE_FD_READ", - __WASI_EVENTTYPE_FD_WRITE => "__WASI_EVENTTYPE_FD_WRITE", - _ => "INVALID EVENTTYPE", - } -} diff --git a/lib/wasi-types/src/file.rs b/lib/wasi-types/src/file.rs deleted file mode 100644 index 0d58ba9bbe4..00000000000 --- a/lib/wasi-types/src/file.rs +++ /dev/null @@ -1,337 +0,0 @@ -use crate::*; -#[cfg(feature = "enable-serde")] -use serde::{Deserialize, Serialize}; -use std::{ - fmt, - mem::{self, MaybeUninit}, -}; -use wasmer_derive::ValueType; -use wasmer_types::ValueType; - -pub type __wasi_device_t = u64; - -pub type __wasi_fd_t = u32; -pub const __WASI_STDIN_FILENO: __wasi_fd_t = 0; -pub const __WASI_STDOUT_FILENO: __wasi_fd_t = 1; -pub const __WASI_STDERR_FILENO: __wasi_fd_t = 2; - -pub type __wasi_pid_t = u32; -pub type __wasi_tid_t = u32; - -pub type __wasi_fdflags_t = u16; -pub const __WASI_FDFLAG_APPEND: __wasi_fdflags_t = 1 << 0; -pub const __WASI_FDFLAG_DSYNC: __wasi_fdflags_t = 1 << 1; -pub const __WASI_FDFLAG_NONBLOCK: __wasi_fdflags_t = 1 << 2; -pub const __WASI_FDFLAG_RSYNC: __wasi_fdflags_t = 1 << 3; -pub const __WASI_FDFLAG_SYNC: __wasi_fdflags_t = 1 << 4; - -pub type __wasi_eventfdflags = u16; -pub const __WASI_EVENTFDFLAGS_SEMAPHORE: __wasi_eventfdflags = 1 << 0; - -pub type __wasi_preopentype_t = u8; -pub const __WASI_PREOPENTYPE_DIR: __wasi_preopentype_t = 0; - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_prestat_u_dir_t { - pub pr_name_len: u32, -} - -#[derive(Copy, Clone)] -#[repr(C)] -pub union __wasi_prestat_u { - dir: __wasi_prestat_u_dir_t, -} - -impl fmt::Debug for __wasi_prestat_u { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "__wasi_prestat_u") - } -} - -#[derive(Debug, Copy, Clone)] -#[repr(C)] -pub struct __wasi_prestat_t { - pub pr_type: __wasi_preopentype_t, - pub u: __wasi_prestat_u, -} - -#[derive(Copy, Clone)] -pub enum PrestatEnum { - Dir { pr_name_len: u32 }, -} - -impl PrestatEnum { - pub fn untagged(self) -> __wasi_prestat_u { - match self { - PrestatEnum::Dir { pr_name_len } => __wasi_prestat_u { - dir: __wasi_prestat_u_dir_t { pr_name_len }, - }, - } - } -} - -impl __wasi_prestat_t { - #[allow(clippy::trivially_copy_pass_by_ref)] - pub fn tagged(&self) -> Option { - match self.pr_type { - __WASI_PREOPENTYPE_DIR => Some(PrestatEnum::Dir { - pr_name_len: unsafe { self.u.dir.pr_name_len }, - }), - _ => None, - } - } -} - -unsafe impl ValueType for __wasi_prestat_t { - fn zero_padding_bytes(&self, bytes: &mut [MaybeUninit]) { - macro_rules! field { - ($($f:tt)*) => { - &self.$($f)* as *const _ as usize - self as *const _ as usize - }; - } - macro_rules! field_end { - ($($f:tt)*) => { - field!($($f)*) + mem::size_of_val(&self.$($f)*) - }; - } - macro_rules! zero { - ($start:expr, $end:expr) => { - for i in $start..$end { - bytes[i] = MaybeUninit::new(0); - } - }; - } - self.pr_type - .zero_padding_bytes(&mut bytes[field!(pr_type)..field_end!(pr_type)]); - zero!(field_end!(pr_type), field!(u)); - match self.pr_type { - __WASI_PREOPENTYPE_DIR => unsafe { - self.u - .dir - .zero_padding_bytes(&mut bytes[field!(u.dir)..field_end!(u.dir)]); - zero!(field_end!(u.dir), field_end!(u)); - }, - _ => zero!(field!(u), field_end!(u)), - } - zero!(field_end!(u), mem::size_of_val(self)); - } -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_fdstat_t { - pub fs_filetype: __wasi_filetype_t, - pub fs_flags: __wasi_fdflags_t, - pub fs_rights_base: __wasi_rights_t, - pub fs_rights_inheriting: __wasi_rights_t, -} - -pub type __wasi_filedelta_t = i64; - -pub type __wasi_filesize_t = u64; - -#[derive(Copy, Clone, PartialEq, Eq, ValueType)] -#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[repr(C)] -pub struct __wasi_filestat_t { - pub st_dev: __wasi_device_t, - pub st_ino: __wasi_inode_t, - pub st_filetype: __wasi_filetype_t, - pub st_nlink: __wasi_linkcount_t, - pub st_size: __wasi_filesize_t, - pub st_atim: __wasi_timestamp_t, - pub st_mtim: __wasi_timestamp_t, - pub st_ctim: __wasi_timestamp_t, -} - -impl Default for __wasi_filestat_t { - fn default() -> Self { - __wasi_filestat_t { - st_dev: Default::default(), - st_ino: Default::default(), - st_filetype: __WASI_FILETYPE_UNKNOWN, - st_nlink: 1, - st_size: Default::default(), - st_atim: Default::default(), - st_mtim: Default::default(), - st_ctim: Default::default(), - } - } -} - -impl fmt::Debug for __wasi_filestat_t { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let convert_ts_into_time_string = |ts| { - let tspec = ::time::OffsetDateTime::from_unix_timestamp_nanos(ts); - format!("{} ({})", tspec.format("%a, %d %b %Y %T %z"), ts) - }; - f.debug_struct("__wasi_filestat_t") - .field("st_dev", &self.st_dev) - .field("st_ino", &self.st_ino) - .field( - "st_filetype", - &format!( - "{} ({})", - wasi_filetype_to_name(self.st_filetype), - self.st_filetype, - ), - ) - .field("st_nlink", &self.st_nlink) - .field("st_size", &self.st_size) - .field( - "st_atim", - &convert_ts_into_time_string(self.st_atim as i128), - ) - .field( - "st_mtim", - &convert_ts_into_time_string(self.st_mtim as i128), - ) - .field( - "st_ctim", - &convert_ts_into_time_string(self.st_ctim as i128), - ) - .finish() - } -} - -pub fn wasi_filetype_to_name(ft: __wasi_filetype_t) -> &'static str { - match ft { - __WASI_FILETYPE_UNKNOWN => "Unknown", - __WASI_FILETYPE_BLOCK_DEVICE => "Block device", - __WASI_FILETYPE_CHARACTER_DEVICE => "Character device", - __WASI_FILETYPE_DIRECTORY => "Directory", - __WASI_FILETYPE_REGULAR_FILE => "Regular file", - __WASI_FILETYPE_SOCKET_DGRAM => "Socket dgram", - __WASI_FILETYPE_SOCKET_STREAM => "Socket stream", - __WASI_FILETYPE_SYMBOLIC_LINK => "Symbolic link", - _ => "Invalid", - } -} - -pub type __wasi_filetype_t = u8; -pub const __WASI_FILETYPE_UNKNOWN: __wasi_filetype_t = 0; -pub const __WASI_FILETYPE_BLOCK_DEVICE: __wasi_filetype_t = 1; -pub const __WASI_FILETYPE_CHARACTER_DEVICE: __wasi_filetype_t = 2; -pub const __WASI_FILETYPE_DIRECTORY: __wasi_filetype_t = 3; -pub const __WASI_FILETYPE_REGULAR_FILE: __wasi_filetype_t = 4; -pub const __WASI_FILETYPE_SOCKET_DGRAM: __wasi_filetype_t = 5; -pub const __WASI_FILETYPE_SOCKET_STREAM: __wasi_filetype_t = 6; -pub const __WASI_FILETYPE_SYMBOLIC_LINK: __wasi_filetype_t = 7; -pub const __WASI_FILETYPE_SOCKET_RAW: __wasi_filetype_t = 8; -pub const __WASI_FILETYPE_SOCKET_SEQPACKET: __wasi_filetype_t = 9; - -pub type __wasi_fstflags_t = u16; -pub const __WASI_FILESTAT_SET_ATIM: __wasi_fstflags_t = 1 << 0; -pub const __WASI_FILESTAT_SET_ATIM_NOW: __wasi_fstflags_t = 1 << 1; -pub const __WASI_FILESTAT_SET_MTIM: __wasi_fstflags_t = 1 << 2; -pub const __WASI_FILESTAT_SET_MTIM_NOW: __wasi_fstflags_t = 1 << 3; - -pub type __wasi_inode_t = u64; - -pub type __wasi_linkcount_t = u64; - -pub type __wasi_lookupflags_t = u32; -pub const __WASI_LOOKUP_SYMLINK_FOLLOW: __wasi_lookupflags_t = 1 << 0; - -pub type __wasi_oflags_t = u16; -pub const __WASI_O_CREAT: __wasi_oflags_t = 1 << 0; -pub const __WASI_O_DIRECTORY: __wasi_oflags_t = 1 << 1; -pub const __WASI_O_EXCL: __wasi_oflags_t = 1 << 2; -pub const __WASI_O_TRUNC: __wasi_oflags_t = 1 << 3; - -pub type __wasi_rights_t = u64; -pub const __WASI_RIGHT_FD_DATASYNC: __wasi_rights_t = 1 << 0; -pub const __WASI_RIGHT_FD_READ: __wasi_rights_t = 1 << 1; -pub const __WASI_RIGHT_FD_SEEK: __wasi_rights_t = 1 << 2; -pub const __WASI_RIGHT_FD_FDSTAT_SET_FLAGS: __wasi_rights_t = 1 << 3; -pub const __WASI_RIGHT_FD_SYNC: __wasi_rights_t = 1 << 4; -pub const __WASI_RIGHT_FD_TELL: __wasi_rights_t = 1 << 5; -pub const __WASI_RIGHT_FD_WRITE: __wasi_rights_t = 1 << 6; -pub const __WASI_RIGHT_FD_ADVISE: __wasi_rights_t = 1 << 7; -pub const __WASI_RIGHT_FD_ALLOCATE: __wasi_rights_t = 1 << 8; -pub const __WASI_RIGHT_PATH_CREATE_DIRECTORY: __wasi_rights_t = 1 << 9; -pub const __WASI_RIGHT_PATH_CREATE_FILE: __wasi_rights_t = 1 << 10; -pub const __WASI_RIGHT_PATH_LINK_SOURCE: __wasi_rights_t = 1 << 11; -pub const __WASI_RIGHT_PATH_LINK_TARGET: __wasi_rights_t = 1 << 12; -pub const __WASI_RIGHT_PATH_OPEN: __wasi_rights_t = 1 << 13; -pub const __WASI_RIGHT_FD_READDIR: __wasi_rights_t = 1 << 14; -pub const __WASI_RIGHT_PATH_READLINK: __wasi_rights_t = 1 << 15; -pub const __WASI_RIGHT_PATH_RENAME_SOURCE: __wasi_rights_t = 1 << 16; -pub const __WASI_RIGHT_PATH_RENAME_TARGET: __wasi_rights_t = 1 << 17; -pub const __WASI_RIGHT_PATH_FILESTAT_GET: __wasi_rights_t = 1 << 18; -pub const __WASI_RIGHT_PATH_FILESTAT_SET_SIZE: __wasi_rights_t = 1 << 19; -pub const __WASI_RIGHT_PATH_FILESTAT_SET_TIMES: __wasi_rights_t = 1 << 20; -pub const __WASI_RIGHT_FD_FILESTAT_GET: __wasi_rights_t = 1 << 21; -pub const __WASI_RIGHT_FD_FILESTAT_SET_SIZE: __wasi_rights_t = 1 << 22; -pub const __WASI_RIGHT_FD_FILESTAT_SET_TIMES: __wasi_rights_t = 1 << 23; -pub const __WASI_RIGHT_PATH_SYMLINK: __wasi_rights_t = 1 << 24; -pub const __WASI_RIGHT_PATH_REMOVE_DIRECTORY: __wasi_rights_t = 1 << 25; -pub const __WASI_RIGHT_PATH_UNLINK_FILE: __wasi_rights_t = 1 << 26; -pub const __WASI_RIGHT_POLL_FD_READWRITE: __wasi_rights_t = 1 << 27; -pub const __WASI_RIGHT_SOCK_SHUTDOWN: __wasi_rights_t = 1 << 28; -pub const __WASI_RIGHT_SOCK_ACCEPT: __wasi_rights_t = 1 << 29; -pub const __WASI_RIGHT_SOCK_CONNECT: __wasi_rights_t = 1 << 30; -pub const __WASI_RIGHT_SOCK_LISTEN: __wasi_rights_t = 1 << 31; -pub const __WASI_RIGHT_SOCK_BIND: __wasi_rights_t = 1 << 32; -pub const __WASI_RIGHT_SOCK_RECV: __wasi_rights_t = 1 << 33; -pub const __WASI_RIGHT_SOCK_SEND: __wasi_rights_t = 1 << 34; -pub const __WASI_RIGHT_SOCK_ADDR_LOCAL: __wasi_rights_t = 1 << 35; -pub const __WASI_RIGHT_SOCK_ADDR_REMOTE: __wasi_rights_t = 1 << 36; -pub const __WASI_RIGHT_SOCK_RECV_FROM: __wasi_rights_t = 1 << 37; -pub const __WASI_RIGHT_SOCK_SEND_TO: __wasi_rights_t = 1 << 38; - -/// function for debugging rights issues -#[allow(dead_code)] -pub fn print_right_set(rights: __wasi_rights_t) { - // BTreeSet for consistent order - let mut right_set = std::collections::BTreeSet::new(); - for i in 0..28 { - let cur_right = rights & (1 << i); - if cur_right != 0 { - right_set.insert(right_to_string(cur_right).unwrap_or("INVALID RIGHT")); - } - } - println!("{:#?}", right_set); -} - -/// expects a single right, returns None if out of bounds or > 1 bit set -pub fn right_to_string(right: __wasi_rights_t) -> Option<&'static str> { - Some(match right { - __WASI_RIGHT_FD_DATASYNC => "__WASI_RIGHT_FD_DATASYNC", - __WASI_RIGHT_FD_READ => "__WASI_RIGHT_FD_READ", - __WASI_RIGHT_FD_SEEK => "__WASI_RIGHT_FD_SEEK", - __WASI_RIGHT_FD_FDSTAT_SET_FLAGS => "__WASI_RIGHT_FD_FDSTAT_SET_FLAGS", - __WASI_RIGHT_FD_SYNC => "__WASI_RIGHT_FD_SYNC", - __WASI_RIGHT_FD_TELL => "__WASI_RIGHT_FD_TELL", - __WASI_RIGHT_FD_WRITE => "__WASI_RIGHT_FD_WRITE", - __WASI_RIGHT_FD_ADVISE => "__WASI_RIGHT_FD_ADVISE", - __WASI_RIGHT_FD_ALLOCATE => "__WASI_RIGHT_FD_ALLOCATE", - __WASI_RIGHT_PATH_CREATE_DIRECTORY => "__WASI_RIGHT_PATH_CREATE_DIRECTORY", - __WASI_RIGHT_PATH_CREATE_FILE => "__WASI_RIGHT_PATH_CREATE_FILE", - __WASI_RIGHT_PATH_LINK_SOURCE => "__WASI_RIGHT_PATH_LINK_SOURCE", - __WASI_RIGHT_PATH_LINK_TARGET => "__WASI_RIGHT_PATH_LINK_TARGET", - __WASI_RIGHT_PATH_OPEN => "__WASI_RIGHT_PATH_OPEN", - __WASI_RIGHT_FD_READDIR => "__WASI_RIGHT_FD_READDIR", - __WASI_RIGHT_PATH_READLINK => "__WASI_RIGHT_PATH_READLINK", - __WASI_RIGHT_PATH_RENAME_SOURCE => "__WASI_RIGHT_PATH_RENAME_SOURCE", - __WASI_RIGHT_PATH_RENAME_TARGET => "__WASI_RIGHT_PATH_RENAME_TARGET", - __WASI_RIGHT_PATH_FILESTAT_GET => "__WASI_RIGHT_PATH_FILESTAT_GET", - __WASI_RIGHT_PATH_FILESTAT_SET_SIZE => "__WASI_RIGHT_PATH_FILESTAT_SET_SIZE", - __WASI_RIGHT_PATH_FILESTAT_SET_TIMES => "__WASI_RIGHT_PATH_FILESTAT_SET_TIMES", - __WASI_RIGHT_FD_FILESTAT_GET => "__WASI_RIGHT_FD_FILESTAT_GET", - __WASI_RIGHT_FD_FILESTAT_SET_SIZE => "__WASI_RIGHT_FD_FILESTAT_SET_SIZE", - __WASI_RIGHT_FD_FILESTAT_SET_TIMES => "__WASI_RIGHT_FD_FILESTAT_SET_TIMES", - __WASI_RIGHT_PATH_SYMLINK => "__WASI_RIGHT_PATH_SYMLINK", - __WASI_RIGHT_PATH_UNLINK_FILE => "__WASI_RIGHT_PATH_UNLINK_FILE", - __WASI_RIGHT_PATH_REMOVE_DIRECTORY => "__WASI_RIGHT_PATH_REMOVE_DIRECTORY", - __WASI_RIGHT_POLL_FD_READWRITE => "__WASI_RIGHT_POLL_FD_READWRITE", - __WASI_RIGHT_SOCK_SHUTDOWN => "__WASI_RIGHT_SOCK_SHUTDOWN", - _ => return None, - }) -} - -pub type __wasi_whence_t = u8; -pub const __WASI_WHENCE_SET: __wasi_whence_t = 0; -pub const __WASI_WHENCE_CUR: __wasi_whence_t = 1; -pub const __WASI_WHENCE_END: __wasi_whence_t = 2; diff --git a/lib/wasi-types/src/io.rs b/lib/wasi-types/src/io.rs deleted file mode 100644 index f80ffcfb3eb..00000000000 --- a/lib/wasi-types/src/io.rs +++ /dev/null @@ -1,55 +0,0 @@ -use wasmer_derive::ValueType; -use wasmer_types::MemorySize; - -use crate::__wasi_fd_t; - -pub type __wasi_count_t = u32; - -pub type __wasi_option_t = u8; -pub const __WASI_OPTION_NONE: __wasi_option_t = 0; -pub const __WASI_OPTION_SOME: __wasi_option_t = 1; - -pub type __wasi_bool_t = u8; -pub const __WASI_BOOL_FALSE: __wasi_bool_t = 0; -pub const __WASI_BOOL_TRUE: __wasi_bool_t = 1; - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_ciovec_t { - pub buf: M::Offset, - pub buf_len: M::Offset, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_iovec_t { - pub buf: M::Offset, - pub buf_len: M::Offset, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_tty_t { - pub cols: u32, - pub rows: u32, - pub width: u32, - pub height: u32, - pub stdin_tty: __wasi_bool_t, - pub stdout_tty: __wasi_bool_t, - pub stderr_tty: __wasi_bool_t, - pub echo: __wasi_bool_t, - pub line_buffered: __wasi_bool_t, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_pipe_handles_t { - pub pipe: __wasi_fd_t, - pub other: __wasi_fd_t, -} - -pub type __wasi_stdiomode_t = u8; -pub const __WASI_STDIO_MODE_PIPED: __wasi_stdiomode_t = 1; -pub const __WASI_STDIO_MODE_INHERIT: __wasi_stdiomode_t = 2; -pub const __WASI_STDIO_MODE_NULL: __wasi_stdiomode_t = 3; -pub const __WASI_STDIO_MODE_LOG: __wasi_stdiomode_t = 4; diff --git a/lib/wasi-types/src/lib.rs b/lib/wasi-types/src/lib.rs index 14f9bff188b..2e54b95e5f9 100644 --- a/lib/wasi-types/src/lib.rs +++ b/lib/wasi-types/src/lib.rs @@ -1,42 +1,43 @@ -#![deny(unused_mut)] -#![doc(html_favicon_url = "https://wasmer.io/images/icons/favicon-32x32.png")] -#![doc(html_logo_url = "https://github.com/wasmerio.png?size=200")] -#![allow(non_camel_case_types, clippy::identity_op)] +pub mod types; +pub mod wasi; -//! Wasmer's WASI types implementation. -//! -//! Those types aim at being used by [the `wasmer-wasi` -//! crate](https://github.com/wasmerio/wasmer/blob/master/lib/wasi). +// Prevent the CI from passing if the wasi/bindings.rs is not +// up to date with the output.wit file +#[test] +#[cfg(feature = "sys")] +fn fail_if_wit_files_arent_up_to_date() { + use wit_bindgen_core::Generator; -// Needed for #[derive(ValueType)] -extern crate wasmer_types as wasmer; - -mod advice; -mod bus; -mod directory; -mod error; -mod event; -mod file; -mod io; -mod net; -mod signal; -mod subscription; -mod time; -mod versions; - -pub use crate::time::*; -pub use advice::*; -pub use bus::*; -pub use directory::*; -pub use error::*; -pub use event::*; -pub use file::*; -pub use io::*; -pub use net::*; -pub use signal::*; -pub use subscription::*; -pub use versions::*; - -pub type __wasi_exitcode_t = u32; - -pub type __wasi_userdata_t = u64; + let output_wit = concat!(env!("CARGO_MANIFEST_DIR"), "/wit-clean/output.wit"); + let bindings_target = + include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/wasi/bindings.rs")); + let mut generator = wit_bindgen_rust_wasm::Opts { + ..wit_bindgen_rust_wasm::Opts::default() + } + .build(); + let output_wit_parsed = wit_parser::Interface::parse_file(output_wit).unwrap(); + let imports = vec![output_wit_parsed]; + let exports = vec![]; + let mut files = Default::default(); + generator.generate_all( + &imports, &exports, &mut files, /* generate_structs */ true, + ); + let generated = files + .iter() + .filter_map(|(k, v)| if k == "bindings.rs" { Some(v) } else { None }) + .next() + .unwrap(); + let generated_str = String::from_utf8_lossy(generated); + let generated_str = generated_str + .lines() + .map(|s| s.to_string()) + .collect::>() + .join("\r\n"); + let generated_str = generated_str.replace("mod output {", "pub mod output {"); + let bindings_target = bindings_target + .lines() + .map(|s| s.to_string()) + .collect::>() + .join("\r\n"); + pretty_assertions::assert_eq!(generated_str, bindings_target); // output.wit out of date? regenerate bindings.rs +} diff --git a/lib/wasi-types/src/net.rs b/lib/wasi-types/src/net.rs deleted file mode 100644 index 7f0cbd79f64..00000000000 --- a/lib/wasi-types/src/net.rs +++ /dev/null @@ -1,494 +0,0 @@ -use super::*; -use wasmer_derive::ValueType; - -use crate::__wasi_option_timestamp_t; - -pub type __wasi_socktype_t = u16; -pub const __WASI_SOCK_TYPE_DGRAM: __wasi_socktype_t = 0; -pub const __WASI_SOCK_TYPE_STREAM: __wasi_socktype_t = 1; -pub const __WASI_SOCK_TYPE_RAW: __wasi_socktype_t = 2; -pub const __WASI_SOCK_TYPE_SEQPACKET: __wasi_socktype_t = 3; - -pub type __wasi_sockstatus_t = u8; -pub const __WASI_SOCK_STATUS_OPENING: __wasi_sockstatus_t = 0; -pub const __WASI_SOCK_STATUS_OPENED: __wasi_sockstatus_t = 1; -pub const __WASI_SOCK_STATUS_CLOSED: __wasi_sockstatus_t = 2; -pub const __WASI_SOCK_STATUS_FAILED: __wasi_sockstatus_t = 3; - -pub type __wasi_sockoption_t = u8; -pub const __WASI_SOCK_OPTION_NOOP: __wasi_sockoption_t = 0; -pub const __WASI_SOCK_OPTION_REUSE_PORT: __wasi_sockoption_t = 1; -pub const __WASI_SOCK_OPTION_REUSE_ADDR: __wasi_sockoption_t = 2; -pub const __WASI_SOCK_OPTION_NO_DELAY: __wasi_sockoption_t = 3; -pub const __WASI_SOCK_OPTION_DONT_ROUTE: __wasi_sockoption_t = 4; -pub const __WASI_SOCK_OPTION_ONLY_V6: __wasi_sockoption_t = 5; -pub const __WASI_SOCK_OPTION_BROADCAST: __wasi_sockoption_t = 6; -pub const __WASI_SOCK_OPTION_MULTICAST_LOOP_V4: __wasi_sockoption_t = 7; -pub const __WASI_SOCK_OPTION_MULTICAST_LOOP_V6: __wasi_sockoption_t = 8; -pub const __WASI_SOCK_OPTION_PROMISCUOUS: __wasi_sockoption_t = 9; -pub const __WASI_SOCK_OPTION_LISTENING: __wasi_sockoption_t = 10; -pub const __WASI_SOCK_OPTION_LAST_ERROR: __wasi_sockoption_t = 11; -pub const __WASI_SOCK_OPTION_KEEP_ALIVE: __wasi_sockoption_t = 12; -pub const __WASI_SOCK_OPTION_LINGER: __wasi_sockoption_t = 13; -pub const __WASI_SOCK_OPTION_OOB_INLINE: __wasi_sockoption_t = 14; -pub const __WASI_SOCK_OPTION_RECV_BUF_SIZE: __wasi_sockoption_t = 15; -pub const __WASI_SOCK_OPTION_SEND_BUF_SIZE: __wasi_sockoption_t = 16; -pub const __WASI_SOCK_OPTION_RECV_LOWAT: __wasi_sockoption_t = 17; -pub const __WASI_SOCK_OPTION_SEND_LOWAT: __wasi_sockoption_t = 18; -pub const __WASI_SOCK_OPTION_RECV_TIMEOUT: __wasi_sockoption_t = 19; -pub const __WASI_SOCK_OPTION_SEND_TIMEOUT: __wasi_sockoption_t = 20; -pub const __WASI_SOCK_OPTION_CONNECT_TIMEOUT: __wasi_sockoption_t = 21; -pub const __WASI_SOCK_OPTION_ACCEPT_TIMEOUT: __wasi_sockoption_t = 22; -pub const __WASI_SOCK_OPTION_TTL: __wasi_sockoption_t = 23; -pub const __WASI_SOCK_OPTION_MULTICAST_TTL_V4: __wasi_sockoption_t = 24; -pub const __WASI_SOCK_OPTION_TYPE: __wasi_sockoption_t = 25; -pub const __WASI_SOCK_OPTION_PROTO: __wasi_sockoption_t = 26; - -pub type __wasi_streamsecurity_t = u8; -pub const __WASI_STREAM_SECURITY_UNENCRYPTED: __wasi_streamsecurity_t = 0; -pub const __WASI_STREAM_SECURITY_ANY_ENCRYPTION: __wasi_streamsecurity_t = 1; -pub const __WASI_STREAM_SECURITY_CLASSIC_ENCRYPTION: __wasi_streamsecurity_t = 2; -pub const __WASI_STREAM_SECURITY_DOUBLE_ENCRYPTION: __wasi_streamsecurity_t = 3; - -pub type __wasi_sockproto_t = u16; -pub const __WASI_SOCK_PROTO_IP: __wasi_sockproto_t = 0; -pub const __WASI_SOCK_PROTO_ICMP: __wasi_sockproto_t = 1; -pub const __WASI_SOCK_PROTO_IGMP: __wasi_sockproto_t = 2; -pub const __WASI_SOCK_PROTO_PROTO_3: __wasi_sockproto_t = 3; -pub const __WASI_SOCK_PROTO_IPIP: __wasi_sockproto_t = 4; -pub const __WASI_SOCK_PROTO_PROTO_5: __wasi_sockproto_t = 5; -pub const __WASI_SOCK_PROTO_TCP: __wasi_sockproto_t = 6; -pub const __WASI_SOCK_PROTO_PROTO_7: __wasi_sockproto_t = 7; -pub const __WASI_SOCK_PROTO_EGP: __wasi_sockproto_t = 8; -pub const __WASI_SOCK_PROTO_PROTO_9: __wasi_sockproto_t = 9; -pub const __WASI_SOCK_PROTO_PROTO_10: __wasi_sockproto_t = 10; -pub const __WASI_SOCK_PROTO_PROTO_11: __wasi_sockproto_t = 11; -pub const __WASI_SOCK_PROTO_PUP: __wasi_sockproto_t = 12; -pub const __WASI_SOCK_PROTO_PROTO_13: __wasi_sockproto_t = 13; -pub const __WASI_SOCK_PROTO_PROTO_14: __wasi_sockproto_t = 14; -pub const __WASI_SOCK_PROTO_PROTO_15: __wasi_sockproto_t = 15; -pub const __WASI_SOCK_PROTO_PROTO_16: __wasi_sockproto_t = 16; -pub const __WASI_SOCK_PROTO_UDP: __wasi_sockproto_t = 17; -pub const __WASI_SOCK_PROTO_PROTO_18: __wasi_sockproto_t = 18; -pub const __WASI_SOCK_PROTO_PROTO_19: __wasi_sockproto_t = 19; -pub const __WASI_SOCK_PROTO_PROTO_20: __wasi_sockproto_t = 20; -pub const __WASI_SOCK_PROTO_PROTO_21: __wasi_sockproto_t = 21; -pub const __WASI_SOCK_PROTO_IDP: __wasi_sockproto_t = 22; -pub const __WASI_SOCK_PROTO_PROTO_23: __wasi_sockproto_t = 23; -pub const __WASI_SOCK_PROTO_PROTO_24: __wasi_sockproto_t = 24; -pub const __WASI_SOCK_PROTO_PROTO_25: __wasi_sockproto_t = 25; -pub const __WASI_SOCK_PROTO_PROTO_26: __wasi_sockproto_t = 26; -pub const __WASI_SOCK_PROTO_PROTO_27: __wasi_sockproto_t = 27; -pub const __WASI_SOCK_PROTO_PROTO_28: __wasi_sockproto_t = 28; -pub const __WASI_SOCK_PROTO_PROTO_TP: __wasi_sockproto_t = 29; -pub const __WASI_SOCK_PROTO_PROTO_30: __wasi_sockproto_t = 30; -pub const __WASI_SOCK_PROTO_PROTO_31: __wasi_sockproto_t = 31; -pub const __WASI_SOCK_PROTO_PROTO_32: __wasi_sockproto_t = 32; -pub const __WASI_SOCK_PROTO_DCCP: __wasi_sockproto_t = 33; -pub const __WASI_SOCK_PROTO_PROTO_34: __wasi_sockproto_t = 34; -pub const __WASI_SOCK_PROTO_PROTO_35: __wasi_sockproto_t = 35; -pub const __WASI_SOCK_PROTO_PROTO_36: __wasi_sockproto_t = 36; -pub const __WASI_SOCK_PROTO_PROTO_37: __wasi_sockproto_t = 37; -pub const __WASI_SOCK_PROTO_PROTO_38: __wasi_sockproto_t = 38; -pub const __WASI_SOCK_PROTO_PROTO_39: __wasi_sockproto_t = 39; -pub const __WASI_SOCK_PROTO_PROTO_40: __wasi_sockproto_t = 40; -pub const __WASI_SOCK_PROTO_IPV6: __wasi_sockproto_t = 41; -pub const __WASI_SOCK_PROTO_PROTO_42: __wasi_sockproto_t = 42; -pub const __WASI_SOCK_PROTO_ROUTING: __wasi_sockproto_t = 43; -pub const __WASI_SOCK_PROTO_FRAGMENT: __wasi_sockproto_t = 44; -pub const __WASI_SOCK_PROTO_PROTO_45: __wasi_sockproto_t = 45; -pub const __WASI_SOCK_PROTO_RSVP: __wasi_sockproto_t = 46; -pub const __WASI_SOCK_PROTO_GRE: __wasi_sockproto_t = 47; -pub const __WASI_SOCK_PROTO_PROTO_48: __wasi_sockproto_t = 48; -pub const __WASI_SOCK_PROTO_PROTO_49: __wasi_sockproto_t = 49; -pub const __WASI_SOCK_PROTO_ESP: __wasi_sockproto_t = 50; -pub const __WASI_SOCK_PROTO_AH: __wasi_sockproto_t = 51; -pub const __WASI_SOCK_PROTO_PROTO_52: __wasi_sockproto_t = 52; -pub const __WASI_SOCK_PROTO_PROTO_53: __wasi_sockproto_t = 53; -pub const __WASI_SOCK_PROTO_PROTO_54: __wasi_sockproto_t = 54; -pub const __WASI_SOCK_PROTO_PROTO_55: __wasi_sockproto_t = 55; -pub const __WASI_SOCK_PROTO_PROTO_56: __wasi_sockproto_t = 56; -pub const __WASI_SOCK_PROTO_PROTO_57: __wasi_sockproto_t = 57; -pub const __WASI_SOCK_PROTO_ICMPV6: __wasi_sockproto_t = 58; -pub const __WASI_SOCK_PROTO_NONE: __wasi_sockproto_t = 59; -pub const __WASI_SOCK_PROTO_DSTOPTS: __wasi_sockproto_t = 60; -pub const __WASI_SOCK_PROTO_PROTO_61: __wasi_sockproto_t = 61; -pub const __WASI_SOCK_PROTO_PROTO_62: __wasi_sockproto_t = 62; -pub const __WASI_SOCK_PROTO_PROTO_63: __wasi_sockproto_t = 63; -pub const __WASI_SOCK_PROTO_PROTO_64: __wasi_sockproto_t = 64; -pub const __WASI_SOCK_PROTO_PROTO_65: __wasi_sockproto_t = 65; -pub const __WASI_SOCK_PROTO_PROTO_66: __wasi_sockproto_t = 66; -pub const __WASI_SOCK_PROTO_PROTO_67: __wasi_sockproto_t = 67; -pub const __WASI_SOCK_PROTO_PROTO_68: __wasi_sockproto_t = 68; -pub const __WASI_SOCK_PROTO_PROTO_69: __wasi_sockproto_t = 69; -pub const __WASI_SOCK_PROTO_PROTO_70: __wasi_sockproto_t = 70; -pub const __WASI_SOCK_PROTO_PROTO_71: __wasi_sockproto_t = 71; -pub const __WASI_SOCK_PROTO_PROTO_72: __wasi_sockproto_t = 72; -pub const __WASI_SOCK_PROTO_PROTO_73: __wasi_sockproto_t = 73; -pub const __WASI_SOCK_PROTO_PROTO_74: __wasi_sockproto_t = 74; -pub const __WASI_SOCK_PROTO_PROTO_75: __wasi_sockproto_t = 75; -pub const __WASI_SOCK_PROTO_PROTO_76: __wasi_sockproto_t = 76; -pub const __WASI_SOCK_PROTO_PROTO_77: __wasi_sockproto_t = 77; -pub const __WASI_SOCK_PROTO_PROTO_78: __wasi_sockproto_t = 78; -pub const __WASI_SOCK_PROTO_PROTO_79: __wasi_sockproto_t = 79; -pub const __WASI_SOCK_PROTO_PROTO_80: __wasi_sockproto_t = 80; -pub const __WASI_SOCK_PROTO_PROTO_81: __wasi_sockproto_t = 81; -pub const __WASI_SOCK_PROTO_PROTO_82: __wasi_sockproto_t = 82; -pub const __WASI_SOCK_PROTO_PROTO_83: __wasi_sockproto_t = 83; -pub const __WASI_SOCK_PROTO_PROTO_84: __wasi_sockproto_t = 84; -pub const __WASI_SOCK_PROTO_PROTO_85: __wasi_sockproto_t = 85; -pub const __WASI_SOCK_PROTO_PROTO_86: __wasi_sockproto_t = 86; -pub const __WASI_SOCK_PROTO_PROTO_87: __wasi_sockproto_t = 87; -pub const __WASI_SOCK_PROTO_PROTO_88: __wasi_sockproto_t = 88; -pub const __WASI_SOCK_PROTO_PROTO_89: __wasi_sockproto_t = 89; -pub const __WASI_SOCK_PROTO_PROTO_90: __wasi_sockproto_t = 90; -pub const __WASI_SOCK_PROTO_PROTO_91: __wasi_sockproto_t = 91; -pub const __WASI_SOCK_PROTO_MTP: __wasi_sockproto_t = 92; -pub const __WASI_SOCK_PROTO_PROTO_93: __wasi_sockproto_t = 93; -pub const __WASI_SOCK_PROTO_BEETPH: __wasi_sockproto_t = 94; -pub const __WASI_SOCK_PROTO_PROTO_95: __wasi_sockproto_t = 95; -pub const __WASI_SOCK_PROTO_PROTO_96: __wasi_sockproto_t = 96; -pub const __WASI_SOCK_PROTO_PROTO_97: __wasi_sockproto_t = 97; -pub const __WASI_SOCK_PROTO_ENCAP: __wasi_sockproto_t = 98; -pub const __WASI_SOCK_PROTO_PROTO_99: __wasi_sockproto_t = 99; -pub const __WASI_SOCK_PROTO_PROTO_100: __wasi_sockproto_t = 100; -pub const __WASI_SOCK_PROTO_PROTO_101: __wasi_sockproto_t = 101; -pub const __WASI_SOCK_PROTO_PROTO_102: __wasi_sockproto_t = 102; -pub const __WASI_SOCK_PROTO_PIM: __wasi_sockproto_t = 103; -pub const __WASI_SOCK_PROTO_PROTO_104: __wasi_sockproto_t = 104; -pub const __WASI_SOCK_PROTO_PROTO_105: __wasi_sockproto_t = 105; -pub const __WASI_SOCK_PROTO_PROTO_106: __wasi_sockproto_t = 106; -pub const __WASI_SOCK_PROTO_PROTO_107: __wasi_sockproto_t = 107; -pub const __WASI_SOCK_PROTO_COMP: __wasi_sockproto_t = 108; -pub const __WASI_SOCK_PROTO_PROTO_109: __wasi_sockproto_t = 109; -pub const __WASI_SOCK_PROTO_PROTO_110: __wasi_sockproto_t = 110; -pub const __WASI_SOCK_PROTO_PROTO_111: __wasi_sockproto_t = 111; -pub const __WASI_SOCK_PROTO_PROTO_112: __wasi_sockproto_t = 112; -pub const __WASI_SOCK_PROTO_PROTO_113: __wasi_sockproto_t = 113; -pub const __WASI_SOCK_PROTO_PROTO_114: __wasi_sockproto_t = 114; -pub const __WASI_SOCK_PROTO_PROTO_115: __wasi_sockproto_t = 115; -pub const __WASI_SOCK_PROTO_PROTO_116: __wasi_sockproto_t = 116; -pub const __WASI_SOCK_PROTO_PROTO_117: __wasi_sockproto_t = 117; -pub const __WASI_SOCK_PROTO_PROTO_118: __wasi_sockproto_t = 118; -pub const __WASI_SOCK_PROTO_PROTO_119: __wasi_sockproto_t = 119; -pub const __WASI_SOCK_PROTO_PROTO_120: __wasi_sockproto_t = 120; -pub const __WASI_SOCK_PROTO_PROTO_121: __wasi_sockproto_t = 121; -pub const __WASI_SOCK_PROTO_PROTO_122: __wasi_sockproto_t = 122; -pub const __WASI_SOCK_PROTO_PROTO_123: __wasi_sockproto_t = 123; -pub const __WASI_SOCK_PROTO_PROTO_124: __wasi_sockproto_t = 124; -pub const __WASI_SOCK_PROTO_PROTO_125: __wasi_sockproto_t = 125; -pub const __WASI_SOCK_PROTO_PROTO_126: __wasi_sockproto_t = 126; -pub const __WASI_SOCK_PROTO_PROTO_127: __wasi_sockproto_t = 127; -pub const __WASI_SOCK_PROTO_PROTO_128: __wasi_sockproto_t = 128; -pub const __WASI_SOCK_PROTO_PROTO_129: __wasi_sockproto_t = 129; -pub const __WASI_SOCK_PROTO_PROTO_130: __wasi_sockproto_t = 130; -pub const __WASI_SOCK_PROTO_PROTO_131: __wasi_sockproto_t = 131; -pub const __WASI_SOCK_PROTO_SCTP: __wasi_sockproto_t = 132; -pub const __WASI_SOCK_PROTO_PROTO_133: __wasi_sockproto_t = 133; -pub const __WASI_SOCK_PROTO_PROTO_134: __wasi_sockproto_t = 134; -pub const __WASI_SOCK_PROTO_MH: __wasi_sockproto_t = 135; -pub const __WASI_SOCK_PROTO_UDPLITE: __wasi_sockproto_t = 136; -pub const __WASI_SOCK_PROTO_MPLS: __wasi_sockproto_t = 137; -pub const __WASI_SOCK_PROTO_PROTO_138: __wasi_sockproto_t = 138; -pub const __WASI_SOCK_PROTO_PROTO_139: __wasi_sockproto_t = 139; -pub const __WASI_SOCK_PROTO_PROTO_140: __wasi_sockproto_t = 140; -pub const __WASI_SOCK_PROTO_PROTO_141: __wasi_sockproto_t = 141; -pub const __WASI_SOCK_PROTO_PROTO_142: __wasi_sockproto_t = 142; -pub const __WASI_SOCK_PROTO_ETHERNET: __wasi_sockproto_t = 143; -pub const __WASI_SOCK_PROTO_PROTO_144: __wasi_sockproto_t = 144; -pub const __WASI_SOCK_PROTO_PROTO_145: __wasi_sockproto_t = 145; -pub const __WASI_SOCK_PROTO_PROTO_146: __wasi_sockproto_t = 146; -pub const __WASI_SOCK_PROTO_PROTO_147: __wasi_sockproto_t = 147; -pub const __WASI_SOCK_PROTO_PROTO_148: __wasi_sockproto_t = 148; -pub const __WASI_SOCK_PROTO_PROTO_149: __wasi_sockproto_t = 149; -pub const __WASI_SOCK_PROTO_PROTO_150: __wasi_sockproto_t = 150; -pub const __WASI_SOCK_PROTO_PROTO_151: __wasi_sockproto_t = 151; -pub const __WASI_SOCK_PROTO_PROTO_152: __wasi_sockproto_t = 152; -pub const __WASI_SOCK_PROTO_PROTO_153: __wasi_sockproto_t = 153; -pub const __WASI_SOCK_PROTO_PROTO_154: __wasi_sockproto_t = 154; -pub const __WASI_SOCK_PROTO_PROTO_155: __wasi_sockproto_t = 155; -pub const __WASI_SOCK_PROTO_PROTO_156: __wasi_sockproto_t = 156; -pub const __WASI_SOCK_PROTO_PROTO_157: __wasi_sockproto_t = 157; -pub const __WASI_SOCK_PROTO_PROTO_158: __wasi_sockproto_t = 158; -pub const __WASI_SOCK_PROTO_PROTO_159: __wasi_sockproto_t = 159; -pub const __WASI_SOCK_PROTO_PROTO_160: __wasi_sockproto_t = 160; -pub const __WASI_SOCK_PROTO_PROTO_161: __wasi_sockproto_t = 161; -pub const __WASI_SOCK_PROTO_PROTO_162: __wasi_sockproto_t = 162; -pub const __WASI_SOCK_PROTO_PROTO_163: __wasi_sockproto_t = 163; -pub const __WASI_SOCK_PROTO_PROTO_164: __wasi_sockproto_t = 164; -pub const __WASI_SOCK_PROTO_PROTO_165: __wasi_sockproto_t = 165; -pub const __WASI_SOCK_PROTO_PROTO_166: __wasi_sockproto_t = 166; -pub const __WASI_SOCK_PROTO_PROTO_167: __wasi_sockproto_t = 167; -pub const __WASI_SOCK_PROTO_PROTO_168: __wasi_sockproto_t = 168; -pub const __WASI_SOCK_PROTO_PROTO_169: __wasi_sockproto_t = 169; -pub const __WASI_SOCK_PROTO_PROTO_170: __wasi_sockproto_t = 170; -pub const __WASI_SOCK_PROTO_PROTO_171: __wasi_sockproto_t = 171; -pub const __WASI_SOCK_PROTO_PROTO_172: __wasi_sockproto_t = 172; -pub const __WASI_SOCK_PROTO_PROTO_173: __wasi_sockproto_t = 173; -pub const __WASI_SOCK_PROTO_PROTO_174: __wasi_sockproto_t = 174; -pub const __WASI_SOCK_PROTO_PROTO_175: __wasi_sockproto_t = 175; -pub const __WASI_SOCK_PROTO_PROTO_176: __wasi_sockproto_t = 176; -pub const __WASI_SOCK_PROTO_PROTO_177: __wasi_sockproto_t = 177; -pub const __WASI_SOCK_PROTO_PROTO_178: __wasi_sockproto_t = 178; -pub const __WASI_SOCK_PROTO_PROTO_179: __wasi_sockproto_t = 179; -pub const __WASI_SOCK_PROTO_PROTO_180: __wasi_sockproto_t = 180; -pub const __WASI_SOCK_PROTO_PROTO_181: __wasi_sockproto_t = 181; -pub const __WASI_SOCK_PROTO_PROTO_182: __wasi_sockproto_t = 182; -pub const __WASI_SOCK_PROTO_PROTO_183: __wasi_sockproto_t = 183; -pub const __WASI_SOCK_PROTO_PROTO_184: __wasi_sockproto_t = 184; -pub const __WASI_SOCK_PROTO_PROTO_185: __wasi_sockproto_t = 185; -pub const __WASI_SOCK_PROTO_PROTO_186: __wasi_sockproto_t = 186; -pub const __WASI_SOCK_PROTO_PROTO_187: __wasi_sockproto_t = 187; -pub const __WASI_SOCK_PROTO_PROTO_188: __wasi_sockproto_t = 188; -pub const __WASI_SOCK_PROTO_PROTO_189: __wasi_sockproto_t = 189; -pub const __WASI_SOCK_PROTO_PROTO_190: __wasi_sockproto_t = 190; -pub const __WASI_SOCK_PROTO_PROTO_191: __wasi_sockproto_t = 191; -pub const __WASI_SOCK_PROTO_PROTO_192: __wasi_sockproto_t = 192; -pub const __WASI_SOCK_PROTO_PROTO_193: __wasi_sockproto_t = 193; -pub const __WASI_SOCK_PROTO_PROTO_194: __wasi_sockproto_t = 194; -pub const __WASI_SOCK_PROTO_PROTO_195: __wasi_sockproto_t = 195; -pub const __WASI_SOCK_PROTO_PROTO_196: __wasi_sockproto_t = 196; -pub const __WASI_SOCK_PROTO_PROTO_197: __wasi_sockproto_t = 197; -pub const __WASI_SOCK_PROTO_PROTO_198: __wasi_sockproto_t = 198; -pub const __WASI_SOCK_PROTO_PROTO_199: __wasi_sockproto_t = 199; -pub const __WASI_SOCK_PROTO_PROTO_200: __wasi_sockproto_t = 200; -pub const __WASI_SOCK_PROTO_PROTO_201: __wasi_sockproto_t = 201; -pub const __WASI_SOCK_PROTO_PROTO_202: __wasi_sockproto_t = 202; -pub const __WASI_SOCK_PROTO_PROTO_203: __wasi_sockproto_t = 203; -pub const __WASI_SOCK_PROTO_PROTO_204: __wasi_sockproto_t = 204; -pub const __WASI_SOCK_PROTO_PROTO_205: __wasi_sockproto_t = 205; -pub const __WASI_SOCK_PROTO_PROTO_206: __wasi_sockproto_t = 206; -pub const __WASI_SOCK_PROTO_PROTO_207: __wasi_sockproto_t = 207; -pub const __WASI_SOCK_PROTO_PROTO_208: __wasi_sockproto_t = 208; -pub const __WASI_SOCK_PROTO_PROTO_209: __wasi_sockproto_t = 209; -pub const __WASI_SOCK_PROTO_PROTO_210: __wasi_sockproto_t = 210; -pub const __WASI_SOCK_PROTO_PROTO_211: __wasi_sockproto_t = 211; -pub const __WASI_SOCK_PROTO_PROTO_212: __wasi_sockproto_t = 212; -pub const __WASI_SOCK_PROTO_PROTO_213: __wasi_sockproto_t = 213; -pub const __WASI_SOCK_PROTO_PROTO_214: __wasi_sockproto_t = 214; -pub const __WASI_SOCK_PROTO_PROTO_215: __wasi_sockproto_t = 215; -pub const __WASI_SOCK_PROTO_PROTO_216: __wasi_sockproto_t = 216; -pub const __WASI_SOCK_PROTO_PROTO_217: __wasi_sockproto_t = 217; -pub const __WASI_SOCK_PROTO_PROTO_218: __wasi_sockproto_t = 218; -pub const __WASI_SOCK_PROTO_PROTO_219: __wasi_sockproto_t = 219; -pub const __WASI_SOCK_PROTO_PROTO_220: __wasi_sockproto_t = 220; -pub const __WASI_SOCK_PROTO_PROTO_221: __wasi_sockproto_t = 221; -pub const __WASI_SOCK_PROTO_PROTO_222: __wasi_sockproto_t = 222; -pub const __WASI_SOCK_PROTO_PROTO_223: __wasi_sockproto_t = 223; -pub const __WASI_SOCK_PROTO_PROTO_224: __wasi_sockproto_t = 224; -pub const __WASI_SOCK_PROTO_PROTO_225: __wasi_sockproto_t = 225; -pub const __WASI_SOCK_PROTO_PROTO_226: __wasi_sockproto_t = 226; -pub const __WASI_SOCK_PROTO_PROTO_227: __wasi_sockproto_t = 227; -pub const __WASI_SOCK_PROTO_PROTO_228: __wasi_sockproto_t = 228; -pub const __WASI_SOCK_PROTO_PROTO_229: __wasi_sockproto_t = 229; -pub const __WASI_SOCK_PROTO_PROTO_230: __wasi_sockproto_t = 230; -pub const __WASI_SOCK_PROTO_PROTO_231: __wasi_sockproto_t = 231; -pub const __WASI_SOCK_PROTO_PROTO_232: __wasi_sockproto_t = 232; -pub const __WASI_SOCK_PROTO_PROTO_233: __wasi_sockproto_t = 233; -pub const __WASI_SOCK_PROTO_PROTO_234: __wasi_sockproto_t = 234; -pub const __WASI_SOCK_PROTO_PROTO_235: __wasi_sockproto_t = 235; -pub const __WASI_SOCK_PROTO_PROTO_236: __wasi_sockproto_t = 236; -pub const __WASI_SOCK_PROTO_PROTO_237: __wasi_sockproto_t = 237; -pub const __WASI_SOCK_PROTO_PROTO_238: __wasi_sockproto_t = 238; -pub const __WASI_SOCK_PROTO_PROTO_239: __wasi_sockproto_t = 239; -pub const __WASI_SOCK_PROTO_PROTO_240: __wasi_sockproto_t = 240; -pub const __WASI_SOCK_PROTO_PROTO_241: __wasi_sockproto_t = 241; -pub const __WASI_SOCK_PROTO_PROTO_242: __wasi_sockproto_t = 242; -pub const __WASI_SOCK_PROTO_PROTO_243: __wasi_sockproto_t = 243; -pub const __WASI_SOCK_PROTO_PROTO_244: __wasi_sockproto_t = 244; -pub const __WASI_SOCK_PROTO_PROTO_245: __wasi_sockproto_t = 245; -pub const __WASI_SOCK_PROTO_PROTO_246: __wasi_sockproto_t = 246; -pub const __WASI_SOCK_PROTO_PROTO_247: __wasi_sockproto_t = 247; -pub const __WASI_SOCK_PROTO_PROTO_248: __wasi_sockproto_t = 248; -pub const __WASI_SOCK_PROTO_PROTO_249: __wasi_sockproto_t = 249; -pub const __WASI_SOCK_PROTO_PROTO_250: __wasi_sockproto_t = 250; -pub const __WASI_SOCK_PROTO_PROTO_251: __wasi_sockproto_t = 251; -pub const __WASI_SOCK_PROTO_PROTO_252: __wasi_sockproto_t = 252; -pub const __WASI_SOCK_PROTO_PROTO_253: __wasi_sockproto_t = 253; -pub const __WASI_SOCK_PROTO_PROTO_254: __wasi_sockproto_t = 254; -pub const __WASI_SOCK_PROTO_PROTO_RAW: __wasi_sockproto_t = 255; -pub const __WASI_SOCK_PROTO_PROTO_256: __wasi_sockproto_t = 256; -pub const __WASI_SOCK_PROTO_PROTO_257: __wasi_sockproto_t = 257; -pub const __WASI_SOCK_PROTO_PROTO_258: __wasi_sockproto_t = 258; -pub const __WASI_SOCK_PROTO_PROTO_259: __wasi_sockproto_t = 259; -pub const __WASI_SOCK_PROTO_PROTO_260: __wasi_sockproto_t = 260; -pub const __WASI_SOCK_PROTO_PROTO_261: __wasi_sockproto_t = 261; -pub const __WASI_SOCK_PROTO_MPTCP: __wasi_sockproto_t = 262; -pub const __WASI_SOCK_PROTO_MAX: __wasi_sockproto_t = 263; - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_hardwareaddress_t { - pub octs: [u8; 6], -} - -pub type __wasi_addressfamily_t = u16; -pub const __WASI_ADDRESS_FAMILY_UNSPEC: __wasi_addressfamily_t = 0; -pub const __WASI_ADDRESS_FAMILY_INET4: __wasi_addressfamily_t = 1; -pub const __WASI_ADDRESS_FAMILY_INET6: __wasi_addressfamily_t = 2; -pub const __WASI_ADDRESS_FAMILY_UNIX: __wasi_addressfamily_t = 3; - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_addr_unspec_t { - pub n0: u8, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_addr_unspec_port_t { - pub port: u16, - pub addr: __wasi_addr_unspec_t, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_cidr_unspec_t { - pub addr: __wasi_addr_unspec_t, - pub prefix: u8, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_addr_ip4_t { - pub octs: [u8; 4], -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_addr_ip4_port_t { - pub port: u16, - pub ip: __wasi_addr_ip4_t, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_cidr_ip4_t { - pub ip: __wasi_addr_ip4_t, - pub prefix: u8, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_addr_unix_t { - pub octs: [u8; 16], -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_addr_unix_port_t { - pub port: u16, - pub unix: __wasi_addr_unix_t, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_cidr_unix_t { - pub unix: __wasi_addr_unix_t, - pub prefix: u8, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_addr_ip6_t { - pub segs: [u8; 16], -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_addr_ip6_port_t { - pub port: u16, - pub ip: __wasi_addr_ip6_t, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_cidr_ip6_t { - pub ip: __wasi_addr_ip6_t, - pub prefix: u8, -} - -#[derive(Debug, Copy, Clone, ValueType)] -#[repr(C)] -pub struct __wasi_addr_u { - pub octs: [u8; 16], -} - -#[derive(Debug, Copy, Clone, ValueType)] -#[repr(C)] -pub struct __wasi_addr_t { - pub tag: __wasi_addressfamily_t, - pub u: __wasi_addr_u, -} - -#[derive(Debug, Copy, Clone, ValueType)] -#[repr(C)] -pub struct __wasi_addr_port_u { - pub octs: [u8; 18], -} - -#[derive(Debug, Copy, Clone, ValueType)] -#[repr(C)] -pub struct __wasi_addr_port_t { - pub tag: __wasi_addressfamily_t, - pub u: __wasi_addr_port_u, -} - -#[derive(Debug, Copy, Clone, ValueType)] -#[repr(C)] -pub struct __wasi_cidr_u { - pub octs: [u8; 17], -} - -#[derive(Debug, Copy, Clone, ValueType)] -#[repr(C)] -pub struct __wasi_cidr_t { - pub tag: __wasi_addressfamily_t, - pub u: __wasi_cidr_u, -} - -#[derive(Debug, Copy, Clone, ValueType)] -#[repr(C)] -pub struct __wasi_route_t { - pub cidr: __wasi_cidr_t, - pub via_router: __wasi_addr_t, - pub preferred_until: __wasi_option_timestamp_t, - pub expires_at: __wasi_option_timestamp_t, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_http_handles_t { - pub req: __wasi_fd_t, - pub res: __wasi_fd_t, - pub hdr: __wasi_fd_t, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_http_status_t { - pub ok: __wasi_bool_t, - pub redirect: __wasi_bool_t, - pub size: __wasi_filesize_t, - pub status: u16, -} - -pub type __wasi_riflags_t = u16; -pub const __WASI_SOCK_RECV_INPUT_PEEK: __wasi_riflags_t = 1 << 0; -pub const __WASI_SOCK_RECV_INPUT_WAITALL: __wasi_riflags_t = 1 << 1; -pub const __WASI_SOCK_RECV_INPUT_DATA_TRUNCATED: __wasi_riflags_t = 1 << 2; - -pub type __wasi_roflags_t = u16; -pub const __WASI_SOCK_RECV_OUTPUT_DATA_TRUNCATED: __wasi_roflags_t = 1 << 0; - -pub type __wasi_sdflags_t = u8; -pub const __WASI_SHUT_RD: __wasi_sdflags_t = 1 << 0; -pub const __WASI_SHUT_WR: __wasi_sdflags_t = 1 << 1; - -pub type __wasi_siflags_t = u16; - -pub type __wasi_timeout_t = u8; -pub const __WASI_TIMEOUT_READ: __wasi_timeout_t = 0; -pub const __WASI_TIMEOUT_WRITE: __wasi_timeout_t = 1; -pub const __WASI_TIMEOUT_CONNECT: __wasi_timeout_t = 2; -pub const __WASI_TIMEOUT_ACCEPT: __wasi_timeout_t = 3; diff --git a/lib/wasi-types/src/signal.rs b/lib/wasi-types/src/signal.rs deleted file mode 100644 index 55d093d842e..00000000000 --- a/lib/wasi-types/src/signal.rs +++ /dev/null @@ -1,31 +0,0 @@ -pub type __wasi_signal_t = u8; -pub const __WASI_SIGHUP: u8 = 1; -pub const __WASI_SIGINT: u8 = 2; -pub const __WASI_SIGQUIT: u8 = 3; -pub const __WASI_SIGILL: u8 = 4; -pub const __WASI_SIGTRAP: u8 = 5; -pub const __WASI_SIGABRT: u8 = 6; -pub const __WASI_SIGBUS: u8 = 7; -pub const __WASI_SIGFPE: u8 = 8; -pub const __WASI_SIGKILL: u8 = 9; -pub const __WASI_SIGUSR1: u8 = 10; -pub const __WASI_SIGSEGV: u8 = 11; -pub const __WASI_SIGUSR2: u8 = 12; -pub const __WASI_SIGPIPE: u8 = 13; -pub const __WASI_SIGALRM: u8 = 14; -pub const __WASI_SIGTERM: u8 = 15; -pub const __WASI_SIGCHLD: u8 = 16; -pub const __WASI_SIGCONT: u8 = 17; -pub const __WASI_SIGSTOP: u8 = 18; -pub const __WASI_SIGTSTP: u8 = 19; -pub const __WASI_SIGTTIN: u8 = 20; -pub const __WASI_SIGTTOU: u8 = 21; -pub const __WASI_SIGURG: u8 = 22; -pub const __WASI_SIGXCPU: u8 = 23; -pub const __WASI_SIGXFSZ: u8 = 24; -pub const __WASI_SIGVTALRM: u8 = 25; -pub const __WASI_SIGPROF: u8 = 26; -pub const __WASI_SIGWINCH: u8 = 27; -pub const __WASI_SIGPOLL: u8 = 28; -pub const __WASI_SIGPWR: u8 = 29; -pub const __WASI_SIGSYS: u8 = 30; diff --git a/lib/wasi-types/src/subscription.rs b/lib/wasi-types/src/subscription.rs deleted file mode 100644 index be8d0c4768e..00000000000 --- a/lib/wasi-types/src/subscription.rs +++ /dev/null @@ -1,188 +0,0 @@ -use crate::*; -use std::convert::TryFrom; -use std::fmt; -use std::mem::{self, MaybeUninit}; -use wasmer_derive::ValueType; -use wasmer_types::ValueType; - -pub type __wasi_subclockflags_t = u16; -pub const __WASI_SUBSCRIPTION_CLOCK_ABSTIME: u16 = 1 << 0; - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_subscription_clock_t { - pub clock_id: __wasi_clockid_t, - pub timeout: __wasi_timestamp_t, - pub precision: __wasi_timestamp_t, - pub flags: __wasi_subclockflags_t, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_subscription_fs_readwrite_t { - pub fd: __wasi_fd_t, -} - -#[derive(Copy, Clone)] -#[repr(C)] -pub union __wasi_subscription_u { - pub clock: __wasi_subscription_clock_t, - pub fd_readwrite: __wasi_subscription_fs_readwrite_t, -} - -#[derive(Copy, Clone)] -#[repr(C)] -pub struct __wasi_subscription_t { - pub userdata: __wasi_userdata_t, - pub type_: __wasi_eventtype_t, - pub u: __wasi_subscription_u, -} - -/// Safe Rust wrapper around `__wasi_subscription_t::type_` and `__wasi_subscription_t::u` -#[derive(Debug, Clone)] -pub enum EventType { - Clock(__wasi_subscription_clock_t), - Read(__wasi_subscription_fs_readwrite_t), - Write(__wasi_subscription_fs_readwrite_t), -} - -impl EventType { - pub fn raw_tag(&self) -> __wasi_eventtype_t { - match self { - EventType::Clock(_) => __WASI_EVENTTYPE_CLOCK, - EventType::Read(_) => __WASI_EVENTTYPE_FD_READ, - EventType::Write(_) => __WASI_EVENTTYPE_FD_WRITE, - } - } -} - -/// Safe Rust wrapper around `__wasi_subscription_t` -#[derive(Debug, Clone)] -pub struct WasiSubscription { - pub user_data: __wasi_userdata_t, - pub event_type: EventType, -} - -impl TryFrom<__wasi_subscription_t> for WasiSubscription { - type Error = __wasi_errno_t; - - fn try_from(ws: __wasi_subscription_t) -> Result { - Ok(Self { - user_data: ws.userdata, - event_type: match ws.type_ { - __WASI_EVENTTYPE_CLOCK => EventType::Clock(unsafe { ws.u.clock }), - __WASI_EVENTTYPE_FD_READ => EventType::Read(unsafe { ws.u.fd_readwrite }), - __WASI_EVENTTYPE_FD_WRITE => EventType::Write(unsafe { ws.u.fd_readwrite }), - _ => return Err(__WASI_EINVAL), - }, - }) - } -} - -impl TryFrom for __wasi_subscription_t { - type Error = __wasi_errno_t; - - fn try_from(ws: WasiSubscription) -> Result { - #[allow(unreachable_patterns)] - let (type_, u) = match ws.event_type { - EventType::Clock(c) => (__WASI_EVENTTYPE_CLOCK, __wasi_subscription_u { clock: c }), - EventType::Read(rw) => ( - __WASI_EVENTTYPE_FD_READ, - __wasi_subscription_u { fd_readwrite: rw }, - ), - EventType::Write(rw) => ( - __WASI_EVENTTYPE_FD_WRITE, - __wasi_subscription_u { fd_readwrite: rw }, - ), - _ => return Err(__WASI_EINVAL), - }; - - Ok(Self { - userdata: ws.user_data, - type_, - u, - }) - } -} - -impl fmt::Debug for __wasi_subscription_t { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("__wasi_subscription_t") - .field("userdata", &self.userdata) - .field("type", &eventtype_to_str(self.type_)) - .field( - "u", - match self.type_ { - __WASI_EVENTTYPE_CLOCK => unsafe { &self.u.clock }, - __WASI_EVENTTYPE_FD_READ | __WASI_EVENTTYPE_FD_WRITE => unsafe { - &self.u.fd_readwrite - }, - _ => &"INVALID EVENTTYPE", - }, - ) - .finish() - } -} - -unsafe impl ValueType for __wasi_subscription_t { - fn zero_padding_bytes(&self, bytes: &mut [MaybeUninit]) { - macro_rules! field { - ($($f:tt)*) => { - &self.$($f)* as *const _ as usize - self as *const _ as usize - }; - } - macro_rules! field_end { - ($($f:tt)*) => { - field!($($f)*) + mem::size_of_val(&self.$($f)*) - }; - } - macro_rules! zero { - ($start:expr, $end:expr) => { - for i in $start..$end { - bytes[i] = MaybeUninit::new(0); - } - }; - } - self.userdata - .zero_padding_bytes(&mut bytes[field!(userdata)..field_end!(userdata)]); - zero!(field_end!(userdata), field!(type_)); - self.type_ - .zero_padding_bytes(&mut bytes[field!(type_)..field_end!(type_)]); - zero!(field_end!(type_), field!(u)); - match self.type_ { - __WASI_EVENTTYPE_FD_READ | __WASI_EVENTTYPE_FD_WRITE => unsafe { - self.u.fd_readwrite.zero_padding_bytes( - &mut bytes[field!(u.fd_readwrite)..field_end!(u.fd_readwrite)], - ); - zero!(field_end!(u.fd_readwrite), field_end!(u)); - }, - __WASI_EVENTTYPE_CLOCK => unsafe { - self.u - .clock - .zero_padding_bytes(&mut bytes[field!(u.clock)..field_end!(u.clock)]); - zero!(field_end!(u.clock), field_end!(u)); - }, - _ => zero!(field!(u), field_end!(u)), - } - zero!(field_end!(u), mem::size_of_val(self)); - } -} - -pub enum SubscriptionEnum { - Clock(__wasi_subscription_clock_t), - FdReadWrite(__wasi_subscription_fs_readwrite_t), -} - -impl __wasi_subscription_t { - pub fn tagged(&self) -> Option { - match self.type_ { - __WASI_EVENTTYPE_CLOCK => Some(SubscriptionEnum::Clock(unsafe { self.u.clock })), - __WASI_EVENTTYPE_FD_READ | __WASI_EVENTTYPE_FD_WRITE => { - Some(SubscriptionEnum::FdReadWrite(unsafe { - self.u.fd_readwrite - })) - } - _ => None, - } - } -} diff --git a/lib/wasi-types/src/time.rs b/lib/wasi-types/src/time.rs deleted file mode 100644 index de9a2b26b92..00000000000 --- a/lib/wasi-types/src/time.rs +++ /dev/null @@ -1,17 +0,0 @@ -use super::io::__wasi_option_t; -use wasmer_derive::ValueType; - -pub type __wasi_clockid_t = u32; -pub const __WASI_CLOCK_REALTIME: __wasi_clockid_t = 0; -pub const __WASI_CLOCK_MONOTONIC: __wasi_clockid_t = 1; -pub const __WASI_CLOCK_PROCESS_CPUTIME_ID: __wasi_clockid_t = 2; -pub const __WASI_CLOCK_THREAD_CPUTIME_ID: __wasi_clockid_t = 3; - -pub type __wasi_timestamp_t = u64; - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_option_timestamp_t { - pub tag: __wasi_option_t, - pub u: __wasi_timestamp_t, -} diff --git a/lib/wasi-types/src/types.rs b/lib/wasi-types/src/types.rs new file mode 100644 index 00000000000..9eee82f3ef1 --- /dev/null +++ b/lib/wasi-types/src/types.rs @@ -0,0 +1,347 @@ +#![deny(unused_mut)] +#![doc(html_favicon_url = "https://wasmer.io/images/icons/favicon-32x32.png")] +#![doc(html_logo_url = "https://github.com/wasmerio.png?size=200")] +#![allow(non_camel_case_types, clippy::identity_op)] + +//! Wasmer's WASI types implementation. +//! +//! Those types aim at being used by [the `wasmer-wasi` +//! crate](https://github.com/wasmerio/wasmer/blob/master/lib/wasi). + +// Needed for #[derive(ValueType)] +extern crate wasmer_types as wasmer; + +pub use crate::types::time::*; +pub use bus::*; +pub use directory::*; +pub use file::*; +pub use io::*; +pub use net::*; +pub use signal::*; +pub use subscription::*; + +pub type __wasi_exitcode_t = u32; +pub type __wasi_userdata_t = u64; + +pub mod bus { + use crate::wasi::{ + BusDataFormat, BusEventClose, BusEventExit, BusEventFault, BusEventType, Cid, OptionCid, + }; + use wasmer_derive::ValueType; + use wasmer_types::MemorySize; + + // Not sure how to port these types to .wit with generics ... + + #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] + #[repr(C)] + pub struct __wasi_busevent_call_t { + pub parent: OptionCid, + pub cid: Cid, + pub format: BusDataFormat, + pub topic_ptr: M::Offset, + pub topic_len: M::Offset, + pub buf_ptr: M::Offset, + pub buf_len: M::Offset, + } + + #[derive(Copy, Clone)] + #[repr(C)] + pub union __wasi_busevent_u { + pub noop: u8, + pub exit: BusEventExit, + pub call: __wasi_busevent_call_t, + pub result: __wasi_busevent_result_t, + pub fault: BusEventFault, + pub close: BusEventClose, + } + + #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] + #[repr(C)] + pub struct __wasi_busevent_result_t { + pub format: BusDataFormat, + pub cid: Cid, + pub buf_ptr: M::Offset, + pub buf_len: M::Offset, + } + + #[derive(Copy, Clone)] + #[repr(C)] + pub struct __wasi_busevent_t { + pub tag: BusEventType, + pub u: __wasi_busevent_u, + } +} + +pub mod file { + use crate::wasi::{Fd, Rights}; + + pub use crate::wasi::{EventFdFlags, FileDelta, LookupFlags, Oflags}; + + pub const __WASI_STDIN_FILENO: Fd = 0; + pub const __WASI_STDOUT_FILENO: Fd = 1; + pub const __WASI_STDERR_FILENO: Fd = 2; + + pub const EVENT_FD_FLAGS_SEMAPHORE: EventFdFlags = 1; + + pub const __WASI_LOOKUP_SYMLINK_FOLLOW: LookupFlags = 1; + + /// function for debugging rights issues + #[allow(dead_code)] + pub fn print_right_set(rights: Rights) { + // BTreeSet for consistent order + let mut right_set = std::collections::BTreeSet::new(); + for i in 0..28 { + let cur_right = rights & Rights::from_bits(1 << i).unwrap(); + if !cur_right.is_empty() { + right_set.insert(cur_right.to_str().unwrap_or("INVALID RIGHT")); + } + } + println!("{:#?}", right_set); + } +} + +pub mod directory { + use crate::wasi; + use std::mem; + + pub const __WASI_DIRCOOKIE_START: wasi::Dircookie = 0; + + pub fn dirent_to_le_bytes(ent: &wasi::Dirent) -> Vec { + let out: Vec = std::iter::empty() + .chain(ent.d_next.to_le_bytes()) + .chain(ent.d_ino.to_le_bytes()) + .chain(ent.d_namlen.to_le_bytes()) + .chain(u32::from(ent.d_type as u8).to_le_bytes()) + .collect(); + + assert_eq!(out.len(), mem::size_of::()); + out + } + + #[cfg(test)] + mod tests { + use super::dirent_to_le_bytes; + use crate::wasi; + + #[test] + fn test_dirent_to_le_bytes() { + let s = wasi::Dirent { + d_next: 0x0123456789abcdef, + d_ino: 0xfedcba9876543210, + d_namlen: 0xaabbccdd, + d_type: wasi::Filetype::Directory, + }; + + assert_eq!( + vec![ + // d_next + 0xef, + 0xcd, + 0xab, + 0x89, + 0x67, + 0x45, + 0x23, + 0x01, + // + // d_ino + 0x10, + 0x32, + 0x54, + 0x76, + 0x98, + 0xba, + 0xdc, + 0xfe, + // + // d_namelen + 0xdd, + 0xcc, + 0xbb, + 0xaa, + // + // d_type + // plus padding + wasi::Filetype::Directory as u8, + 0x00, + 0x00, + 0x00, + ], + dirent_to_le_bytes(&s) + ); + } + } +} + +pub mod io { + use wasmer_derive::ValueType; + use wasmer_types::MemorySize; + + pub use crate::wasi::Bool; + pub use crate::wasi::Count; + pub use crate::wasi::OptionTag; + pub use crate::wasi::StdioMode; + + #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] + #[repr(C)] + pub struct __wasi_ciovec_t { + pub buf: M::Offset, + pub buf_len: M::Offset, + } + + #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] + #[repr(C)] + pub struct __wasi_iovec_t { + pub buf: M::Offset, + pub buf_len: M::Offset, + } +} + +pub mod time { + pub use crate::wasi::OptionTimestamp; +} + +pub mod net { + use crate::wasi::Addressfamily; + use wasmer_derive::ValueType; + + use crate::wasi::OptionTimestamp; + + pub use crate::wasi::{ + AddrUnspec, AddrUnspecPort, CidrUnspec, HttpHandles, HttpStatus, RiFlags, RoFlags, SdFlags, + SiFlags, SockProto, Timeout, + }; + + #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] + #[repr(C)] + pub struct __wasi_hardwareaddress_t { + pub octs: [u8; 6], + } + + #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] + #[repr(C)] + pub struct __wasi_addr_ip4_t { + pub octs: [u8; 4], + } + + #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] + #[repr(C)] + pub struct __wasi_addr_ip4_port_t { + pub port: u16, + pub ip: __wasi_addr_ip4_t, + } + + #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] + #[repr(C)] + pub struct __wasi_cidr_ip4_t { + pub ip: __wasi_addr_ip4_t, + pub prefix: u8, + } + + #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] + #[repr(C)] + pub struct __wasi_addr_unix_t { + pub octs: [u8; 16], + } + + #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] + #[repr(C)] + pub struct __wasi_addr_unix_port_t { + pub port: u16, + pub unix: __wasi_addr_unix_t, + } + + #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] + #[repr(C)] + pub struct __wasi_cidr_unix_t { + pub unix: __wasi_addr_unix_t, + pub prefix: u8, + } + + #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] + #[repr(C)] + pub struct __wasi_addr_ip6_t { + pub segs: [u8; 16], + } + + #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] + #[repr(C)] + pub struct __wasi_addr_ip6_port_t { + pub port: u16, + pub ip: __wasi_addr_ip6_t, + } + + #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] + #[repr(C)] + pub struct __wasi_cidr_ip6_t { + pub ip: __wasi_addr_ip6_t, + pub prefix: u8, + } + + #[derive(Debug, Copy, Clone, ValueType)] + #[repr(C)] + pub struct __wasi_addr_u { + pub octs: [u8; 16], + } + + #[derive(Debug, Copy, Clone, ValueType)] + #[repr(C)] + pub struct __wasi_addr_t { + pub tag: Addressfamily, + pub u: __wasi_addr_u, + } + + #[derive(Debug, Copy, Clone, ValueType)] + #[repr(C)] + pub struct __wasi_addr_port_u { + pub octs: [u8; 18], + } + + #[derive(Debug, Copy, Clone, ValueType)] + #[repr(C)] + pub struct __wasi_addr_port_t { + pub tag: Addressfamily, + pub u: __wasi_addr_port_u, + } + + #[derive(Debug, Copy, Clone, ValueType)] + #[repr(C)] + pub struct __wasi_cidr_u { + pub octs: [u8; 17], + } + + #[derive(Debug, Copy, Clone, ValueType)] + #[repr(C)] + pub struct __wasi_cidr_t { + pub tag: Addressfamily, + pub u: __wasi_cidr_u, + } + + #[derive(Debug, Copy, Clone, ValueType)] + #[repr(C)] + pub struct Route { + pub cidr: __wasi_cidr_t, + pub via_router: __wasi_addr_t, + pub preferred_until: OptionTimestamp, + pub expires_at: OptionTimestamp, + } + + pub const __WASI_SOCK_RECV_INPUT_PEEK: RiFlags = 1 << 0; + pub const __WASI_SOCK_RECV_INPUT_WAITALL: RiFlags = 1 << 1; + pub const __WASI_SOCK_RECV_INPUT_DATA_TRUNCATED: RiFlags = 1 << 2; + + pub const __WASI_SOCK_RECV_OUTPUT_DATA_TRUNCATED: RoFlags = 1 << 0; + + pub const __WASI_SHUT_RD: SdFlags = 1 << 0; + pub const __WASI_SHUT_WR: SdFlags = 1 << 1; +} + +pub mod signal { + pub use crate::wasi::Signal; +} + +pub mod subscription { + pub use crate::wasi::{ + Eventtype, SubscriptionClock, SubscriptionEnum as EventType, SubscriptionFsReadwrite, + }; +} diff --git a/lib/wasi-types/src/versions/mod.rs b/lib/wasi-types/src/versions/mod.rs deleted file mode 100644 index 9ed2b1d4f5f..00000000000 --- a/lib/wasi-types/src/versions/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod snapshot0; diff --git a/lib/wasi-types/src/versions/snapshot0.rs b/lib/wasi-types/src/versions/snapshot0.rs deleted file mode 100644 index 45fec2bb339..00000000000 --- a/lib/wasi-types/src/versions/snapshot0.rs +++ /dev/null @@ -1,151 +0,0 @@ -use crate::*; -#[cfg(feature = "enable-serde")] -use serde::{Deserialize, Serialize}; -use std::fmt; -use std::mem::{self, MaybeUninit}; -use wasmer_derive::ValueType; -use wasmer_types::ValueType; - -pub type __wasi_linkcount_t = u32; - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_subscription_clock_t { - pub userdata: __wasi_userdata_t, - pub clock_id: __wasi_clockid_t, - pub timeout: __wasi_timestamp_t, - pub precision: __wasi_timestamp_t, - pub flags: __wasi_subclockflags_t, -} - -#[derive(Copy, Clone)] -#[repr(C)] -pub union __wasi_subscription_u { - pub clock: __wasi_subscription_clock_t, - pub fd_readwrite: __wasi_subscription_fs_readwrite_t, -} - -#[derive(Copy, Clone)] -#[repr(C)] -pub struct __wasi_subscription_t { - pub userdata: __wasi_userdata_t, - pub type_: __wasi_eventtype_t, - pub u: __wasi_subscription_u, -} - -unsafe impl ValueType for __wasi_subscription_t { - fn zero_padding_bytes(&self, bytes: &mut [MaybeUninit]) { - macro_rules! field { - ($($f:tt)*) => { - &self.$($f)* as *const _ as usize - self as *const _ as usize - }; - } - macro_rules! field_end { - ($($f:tt)*) => { - field!($($f)*) + mem::size_of_val(&self.$($f)*) - }; - } - macro_rules! zero { - ($start:expr, $end:expr) => { - for i in $start..$end { - bytes[i] = MaybeUninit::new(0); - } - }; - } - self.userdata - .zero_padding_bytes(&mut bytes[field!(userdata)..field_end!(userdata)]); - zero!(field_end!(userdata), field!(type_)); - self.type_ - .zero_padding_bytes(&mut bytes[field!(type_)..field_end!(type_)]); - zero!(field_end!(type_), field!(u)); - match self.type_ { - __WASI_EVENTTYPE_FD_READ | __WASI_EVENTTYPE_FD_WRITE => unsafe { - self.u.fd_readwrite.zero_padding_bytes( - &mut bytes[field!(u.fd_readwrite)..field_end!(u.fd_readwrite)], - ); - zero!(field_end!(u.fd_readwrite), field_end!(u)); - }, - __WASI_EVENTTYPE_CLOCK => unsafe { - self.u - .clock - .zero_padding_bytes(&mut bytes[field!(u.clock)..field_end!(u.clock)]); - zero!(field_end!(u.clock), field_end!(u)); - }, - _ => zero!(field!(u), field_end!(u)), - } - zero!(field_end!(u), mem::size_of_val(self)); - } -} - -pub type __wasi_whence_t = u8; -pub const __WASI_WHENCE_CUR: u8 = 0; -pub const __WASI_WHENCE_END: u8 = 1; -pub const __WASI_WHENCE_SET: u8 = 2; - -#[derive(Copy, Clone, PartialEq, Eq, ValueType)] -#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[repr(C)] -pub struct __wasi_filestat_t { - pub st_dev: __wasi_device_t, - pub st_ino: __wasi_inode_t, - pub st_filetype: __wasi_filetype_t, - pub st_nlink: __wasi_linkcount_t, - pub st_size: __wasi_filesize_t, - pub st_atim: __wasi_timestamp_t, - pub st_mtim: __wasi_timestamp_t, - pub st_ctim: __wasi_timestamp_t, -} - -impl fmt::Debug for __wasi_filestat_t { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let convert_ts_into_time_string = |ts| { - let tspec = ::time::OffsetDateTime::from_unix_timestamp_nanos(ts); - format!("{} ({})", tspec.format("%a, %d %b %Y %T %z"), ts) - }; - f.debug_struct("__wasi_filestat_t") - .field("st_dev", &self.st_dev) - .field("st_ino", &self.st_ino) - .field( - "st_filetype", - &format!( - "{} ({})", - wasi_filetype_to_name(self.st_filetype), - self.st_filetype, - ), - ) - .field("st_nlink", &self.st_nlink) - .field("st_size", &self.st_size) - .field( - "st_atim", - &convert_ts_into_time_string(self.st_atim as i128), - ) - .field( - "st_mtim", - &convert_ts_into_time_string(self.st_mtim as i128), - ) - .field( - "st_ctim", - &convert_ts_into_time_string(self.st_ctim as i128), - ) - .finish() - } -} - -impl fmt::Debug for __wasi_subscription_t { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("__wasi_subscription_t") - .field("userdata", &self.userdata) - .field("type", &eventtype_to_str(self.type_)) - .field( - "u", - match self.type_ { - __WASI_EVENTTYPE_CLOCK => unsafe { &self.u.clock }, - __WASI_EVENTTYPE_FD_READ | __WASI_EVENTTYPE_FD_WRITE => unsafe { - &self.u.fd_readwrite - }, - _ => &"INVALID EVENTTYPE", - }, - ) - .finish() - } -} diff --git a/lib/wasi-types/src/wasi/bindings.rs b/lib/wasi-types/src/wasi/bindings.rs new file mode 100644 index 00000000000..3d88e9fda80 --- /dev/null +++ b/lib/wasi-types/src/wasi/bindings.rs @@ -0,0 +1,2998 @@ +#[allow(clippy::all)] +pub mod output { + /// Type names used by low-level WASI interfaces. + /// An array size. + /// + /// Note: This is similar to `size_t` in POSIX. + pub type Size = u32; + /// Non-negative file size or length of a region within a file. + pub type Filesize = u64; + /// Timestamp in nanoseconds. + pub type Timestamp = u64; + /// A file descriptor handle. + pub type Fd = u32; + /// A reference to the offset of a directory entry. + pub type Dircookie = u64; + /// The type for the `dirent::d-namlen` field of `dirent` struct. + pub type Dirnamlen = u32; + /// File serial number that is unique within its file system. + pub type Inode = u64; + /// Identifier for a device containing a file system. Can be used in combination + /// with `inode` to uniquely identify a file or directory in the filesystem. + pub type Device = u64; + pub type Linkcount = u64; + pub type Snapshot0Linkcount = u32; + pub type Tid = u32; + pub type Pid = u32; + /// Identifiers for clocks, snapshot0 version. + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum Snapshot0Clockid { + /// The clock measuring real time. Time value zero corresponds with + /// 1970-01-01T00:00:00Z. + Realtime, + /// The store-wide monotonic clock, which is defined as a clock measuring + /// real time, whose value cannot be adjusted and which cannot have negative + /// clock jumps. The epoch of this clock is undefined. The absolute time + /// value of this clock therefore has no meaning. + Monotonic, + /// The CPU-time clock associated with the current process. + ProcessCputimeId, + /// The CPU-time clock associated with the current thread. + ThreadCputimeId, + } + impl core::fmt::Debug for Snapshot0Clockid { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Snapshot0Clockid::Realtime => { + f.debug_tuple("Snapshot0Clockid::Realtime").finish() + } + Snapshot0Clockid::Monotonic => { + f.debug_tuple("Snapshot0Clockid::Monotonic").finish() + } + Snapshot0Clockid::ProcessCputimeId => { + f.debug_tuple("Snapshot0Clockid::ProcessCputimeId").finish() + } + Snapshot0Clockid::ThreadCputimeId => { + f.debug_tuple("Snapshot0Clockid::ThreadCputimeId").finish() + } + } + } + } + /// Identifiers for clocks. + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum Clockid { + /// The clock measuring real time. Time value zero corresponds with + /// 1970-01-01T00:00:00Z. + Realtime, + /// The store-wide monotonic clock, which is defined as a clock measuring + /// real time, whose value cannot be adjusted and which cannot have negative + /// clock jumps. The epoch of this clock is undefined. The absolute time + /// value of this clock therefore has no meaning. + Monotonic, + } + impl core::fmt::Debug for Clockid { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Clockid::Realtime => { + f.debug_tuple("Clockid::Realtime").finish() + } + Clockid::Monotonic => { + f.debug_tuple("Clockid::Monotonic").finish() + } + } + } + } + /// Error codes returned by functions. + /// Not all of these error codes are returned by the functions provided by this + /// API; some are used in higher-level library layers, and others are provided + /// merely for alignment with POSIX. + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum Errno { + /// No error occurred. System call completed successfully. + Success, + /// Argument list too long. + Toobig, + /// Permission denied. + Access, + /// Address in use. + Addrinuse, + /// Address not available. + Addrnotavail, + /// Address family not supported. + Afnosupport, + /// Resource unavailable, or operation would block. + Again, + /// Connection already in progress. + Already, + /// Bad file descriptor. + Badf, + /// Bad message. + Badmsg, + /// Device or resource busy. + Busy, + /// Operation canceled. + Canceled, + /// No child processes. + Child, + /// Connection aborted. + Connaborted, + /// Connection refused. + Connrefused, + /// Connection reset. + Connreset, + /// Resource deadlock would occur. + Deadlk, + /// Destination address required. + Destaddrreq, + /// Mathematics argument out of domain of function. + Dom, + /// Reserved. + Dquot, + /// File exists. + Exist, + /// Bad address. + Fault, + /// File too large. + Fbig, + /// Host is unreachable. + Hostunreach, + /// Identifier removed. + Idrm, + /// Illegal byte sequence. + Ilseq, + /// Operation in progress. + Inprogress, + /// Interrupted function. + Intr, + /// Invalid argument. + Inval, + /// I/O error. + Io, + /// Socket is connected. + Isconn, + /// Is a directory. + Isdir, + /// Too many levels of symbolic links. + Loop, + /// File descriptor value too large. + Mfile, + /// Too many links. + Mlink, + /// Message too large. + Msgsize, + /// Reserved. + Multihop, + /// Filename too long. + Nametoolong, + /// Network is down. + Netdown, + /// Connection aborted by network. + Netreset, + /// Network unreachable. + Netunreach, + /// Too many files open in system. + Nfile, + /// No buffer space available. + Nobufs, + /// No such device. + Nodev, + /// No such file or directory. + Noent, + /// Executable file format error. + Noexec, + /// No locks available. + Nolck, + /// Reserved. + Nolink, + /// Not enough space. + Nomem, + /// No message of the desired type. + Nomsg, + /// Protocol not available. + Noprotoopt, + /// No space left on device. + Nospc, + /// Function not supported. + Nosys, + /// The socket is not connected. + Notconn, + /// Not a directory or a symbolic link to a directory. + Notdir, + /// Directory not empty. + Notempty, + /// State not recoverable. + Notrecoverable, + /// Not a socket. + Notsock, + /// Not supported, or operation not supported on socket. + Notsup, + /// Inappropriate I/O control operation. + Notty, + /// No such device or address. + Nxio, + /// Value too large to be stored in data type. + Overflow, + /// Previous owner died. + Ownerdead, + /// Operation not permitted. + Perm, + /// Broken pipe. + Pipe, + /// Protocol error. + Proto, + /// Protocol not supported. + Protonosupport, + /// Protocol wrong type for socket. + Prototype, + /// Result too large. + Range, + /// Read-only file system. + Rofs, + /// Invalid seek. + Spipe, + /// No such process. + Srch, + /// Reserved. + Stale, + /// Connection timed out. + Timedout, + /// Text file busy. + Txtbsy, + /// Cross-device link. + Xdev, + /// Extension: Capabilities insufficient. + Notcapable, + } + 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", + } + } + 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.", + } + } + } + impl core::fmt::Debug for Errno{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Errno") + .field("code", &(*self as i32)) + .field("name", &self.name()) + .field("message", &self.message()) + .finish() + } + } + impl core::fmt::Display for Errno{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "{} (error {})", self.name(), *self as i32)} + } + + impl std::error::Error for Errno{} + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum BusErrno { + /// No error occurred. Call completed successfully. + Success, + /// Failed during serialization + Ser, + /// Failed during deserialization + Des, + /// Invalid WAPM process + Wapm, + /// Failed to fetch the WAPM process + Fetch, + /// Failed to compile the WAPM process + Compile, + /// Invalid ABI + Abi, + /// Call was aborted + Aborted, + /// Bad handle + Badhandle, + /// Invalid topic + Topic, + /// Invalid callback + Badcb, + /// Call is unsupported + Unsupported, + /// Bad request + Badrequest, + /// Access denied + Denied, + /// Internal error has occured + Internal, + /// Memory allocation failed + Alloc, + /// Invocation has failed + Invoke, + /// Already consumed + Consumed, + /// Memory access violation + Memviolation, + /// Some other unhandled error. If you see this, it's probably a bug. + Unknown, + } + impl BusErrno{ + pub fn name(&self) -> &'static str { + match self { + BusErrno::Success => "success", + BusErrno::Ser => "ser", + BusErrno::Des => "des", + BusErrno::Wapm => "wapm", + BusErrno::Fetch => "fetch", + BusErrno::Compile => "compile", + BusErrno::Abi => "abi", + BusErrno::Aborted => "aborted", + BusErrno::Badhandle => "badhandle", + BusErrno::Topic => "topic", + BusErrno::Badcb => "badcb", + BusErrno::Unsupported => "unsupported", + BusErrno::Badrequest => "badrequest", + BusErrno::Denied => "denied", + BusErrno::Internal => "internal", + BusErrno::Alloc => "alloc", + BusErrno::Invoke => "invoke", + BusErrno::Consumed => "consumed", + BusErrno::Memviolation => "memviolation", + BusErrno::Unknown => "unknown", + } + } + pub fn message(&self) -> &'static str { + match self { + BusErrno::Success => "No error occurred. Call completed successfully.", + BusErrno::Ser => "Failed during serialization", + BusErrno::Des => "Failed during deserialization", + BusErrno::Wapm => "Invalid WAPM process", + BusErrno::Fetch => "Failed to fetch the WAPM process", + BusErrno::Compile => "Failed to compile the WAPM process", + BusErrno::Abi => "Invalid ABI", + BusErrno::Aborted => "Call was aborted", + BusErrno::Badhandle => "Bad handle", + BusErrno::Topic => "Invalid topic", + BusErrno::Badcb => "Invalid callback", + BusErrno::Unsupported => "Call is unsupported", + BusErrno::Badrequest => "Bad request", + BusErrno::Denied => "Access denied", + BusErrno::Internal => "Internal error has occured", + BusErrno::Alloc => "Memory allocation failed", + BusErrno::Invoke => "Invocation has failed", + BusErrno::Consumed => "Already consumed", + BusErrno::Memviolation => "Memory access violation", + BusErrno::Unknown => "Some other unhandled error. If you see this, it's probably a bug.", + } + } + } + impl core::fmt::Debug for BusErrno{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("BusErrno") + .field("code", &(*self as i32)) + .field("name", &self.name()) + .field("message", &self.message()) + .finish() + } + } + impl core::fmt::Display for BusErrno{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "{} (error {})", self.name(), *self as i32)} + } + + impl std::error::Error for BusErrno{} + wit_bindgen_rust::bitflags::bitflags! { + /// File descriptor rights, determining which actions may be performed. + pub struct Rights: u64 { + /// The right to invoke `fd_datasync`. + /// + /// If `rights::path_open` is set, includes the right to invoke + /// `path_open` with `fdflags::dsync`. + const FD_DATASYNC = 1 << 0; + /// The right to invoke `fd_read` and `sock_recv`. + /// + /// If `rights::fd_seek` is set, includes the right to invoke `fd_pread`. + const FD_READ = 1 << 1; + /// The right to invoke `fd_seek`. This flag implies `rights::fd_tell`. + const FD_SEEK = 1 << 2; + /// The right to invoke `fd_fdstat_set_flags`. + const FD_FDSTAT_SET_FLAGS = 1 << 3; + /// The right to invoke `fd_sync`. + /// + /// If `rights::path_open` is set, includes the right to invoke + /// `path_open` with `fdflags::rsync` and `fdflags::dsync`. + const FD_SYNC = 1 << 4; + /// The right to invoke `fd_seek` in such a way that the file offset + /// remains unaltered (i.e., `whence::cur` with offset zero), or to + /// invoke `fd_tell`. + const FD_TELL = 1 << 5; + /// The right to invoke `fd_write` and `sock_send`. + /// If `rights::fd_seek` is set, includes the right to invoke `fd_pwrite`. + const FD_WRITE = 1 << 6; + /// The right to invoke `fd_advise`. + const FD_ADVISE = 1 << 7; + /// The right to invoke `fd_allocate`. + const FD_ALLOCATE = 1 << 8; + /// The right to invoke `path_create_directory`. + const PATH_CREATE_DIRECTORY = 1 << 9; + /// If `rights::path_open` is set, the right to invoke `path_open` with `oflags::creat`. + const PATH_CREATE_FILE = 1 << 10; + /// The right to invoke `path_link` with the file descriptor as the + /// source directory. + const PATH_LINK_SOURCE = 1 << 11; + /// The right to invoke `path_link` with the file descriptor as the + /// target directory. + const PATH_LINK_TARGET = 1 << 12; + /// The right to invoke `path_open`. + const PATH_OPEN = 1 << 13; + /// The right to invoke `fd_readdir`. + const FD_READDIR = 1 << 14; + /// The right to invoke `path_readlink`. + const PATH_READLINK = 1 << 15; + /// The right to invoke `path_rename` with the file descriptor as the source directory. + const PATH_RENAME_SOURCE = 1 << 16; + /// The right to invoke `path_rename` with the file descriptor as the target directory. + const PATH_RENAME_TARGET = 1 << 17; + /// The right to invoke `path_filestat_get`. + const PATH_FILESTAT_GET = 1 << 18; + /// The right to change a file's size (there is no `path_filestat_set_size`). + /// If `rights::path_open` is set, includes the right to invoke `path_open` with `oflags::trunc`. + const PATH_FILESTAT_SET_SIZE = 1 << 19; + /// The right to invoke `path_filestat_set_times`. + const PATH_FILESTAT_SET_TIMES = 1 << 20; + /// The right to invoke `fd_filestat_get`. + const FD_FILESTAT_GET = 1 << 21; + /// The right to invoke `fd_filestat_set_size`. + const FD_FILESTAT_SET_SIZE = 1 << 22; + /// The right to invoke `fd_filestat_set_times`. + const FD_FILESTAT_SET_TIMES = 1 << 23; + /// The right to invoke `path_symlink`. + const PATH_SYMLINK = 1 << 24; + /// The right to invoke `path_remove_directory`. + const PATH_REMOVE_DIRECTORY = 1 << 25; + /// The right to invoke `path_unlink_file`. + const PATH_UNLINK_FILE = 1 << 26; + /// If `rights::fd_read` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_read`. + /// If `rights::fd_write` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_write`. + const POLL_FD_READWRITE = 1 << 27; + /// The right to invoke `sock_shutdown`. + const SOCK_SHUTDOWN = 1 << 28; + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + const SOCK_ACCEPT = 1 << 29; + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + const SOCK_CONNECT = 1 << 30; + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + const SOCK_LISTEN = 1 << 31; + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + const SOCK_BIND = 1 << 32; + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + const SOCK_RECV = 1 << 33; + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + const SOCK_SEND = 1 << 34; + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + const SOCK_ADDR_LOCAL = 1 << 35; + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + const SOCK_ADDR_REMOTE = 1 << 36; + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + const SOCK_RECV_FROM = 1 << 37; + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + const SOCK_SEND_TO = 1 << 38; + } + } + impl Rights { + /// Convert from a raw integer, preserving any unknown bits. See + /// + pub fn from_bits_preserve(bits: u64) -> Self { + Self { bits } + } + } + /// The type of a file descriptor or file. + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum Filetype { + /// The type of the file descriptor or file is unknown or is different from any of the other types specified. + Unknown, + /// The file descriptor or file refers to a block device inode. + BlockDevice, + /// The file descriptor or file refers to a character device inode. + CharacterDevice, + /// The file descriptor or file refers to a directory inode. + Directory, + /// The file descriptor or file refers to a regular file inode. + RegularFile, + /// The file descriptor or file refers to a datagram socket. + SocketDgram, + /// The file descriptor or file refers to a byte-stream socket. + SocketStream, + /// The file refers to a symbolic link inode. + SymbolicLink, + /// The file descriptor or file refers to a FIFO. + Fifo, + } + impl core::fmt::Debug for Filetype { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Filetype::Unknown => { + f.debug_tuple("Filetype::Unknown").finish() + } + Filetype::BlockDevice => { + f.debug_tuple("Filetype::BlockDevice").finish() + } + Filetype::CharacterDevice => { + f.debug_tuple("Filetype::CharacterDevice").finish() + } + Filetype::Directory => { + f.debug_tuple("Filetype::Directory").finish() + } + Filetype::RegularFile => { + f.debug_tuple("Filetype::RegularFile").finish() + } + Filetype::SocketDgram => { + f.debug_tuple("Filetype::SocketDgram").finish() + } + Filetype::SocketStream => { + f.debug_tuple("Filetype::SocketStream").finish() + } + Filetype::SymbolicLink => { + f.debug_tuple("Filetype::SymbolicLink").finish() + } + Filetype::Fifo => { + f.debug_tuple("Filetype::Fifo").finish() + } + } + } + } + /// A directory entry, snapshot0 version. + #[repr(C)] + #[derive(Copy, Clone)] + pub struct Snapshot0Dirent { + /// The offset of the next directory entry stored in this directory. + pub d_next: Dircookie, + /// The serial number of the file referred to by this directory entry. + pub d_ino: Inode, + /// The length of the name of the directory entry. + pub d_namlen: Dirnamlen, + /// The type of the file referred to by this directory entry. + pub d_type: Filetype, + } + impl core::fmt::Debug for Snapshot0Dirent { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Snapshot0Dirent").field("d-next", &self.d_next).field("d-ino", &self.d_ino).field("d-namlen", &self.d_namlen).field("d-type", &self.d_type).finish()} + } + /// A directory entry. + #[repr(C)] + #[derive(Copy, Clone)] + pub struct Dirent { + /// The offset of the next directory entry stored in this directory. + pub d_next: Dircookie, + /// The serial number of the file referred to by this directory entry. + pub d_ino: Inode, + /// The type of the file referred to by this directory entry. + pub d_type: Filetype, + /// The length of the name of the directory entry. + pub d_namlen: Dirnamlen, + } + impl core::fmt::Debug for Dirent { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Dirent").field("d-next", &self.d_next).field("d-ino", &self.d_ino).field("d-type", &self.d_type).field("d-namlen", &self.d_namlen).finish()} + } + /// File or memory access pattern advisory information. + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum Advice { + /// The application has no advice to give on its behavior with respect to the specified data. + Normal, + /// The application expects to access the specified data sequentially from lower offsets to higher offsets. + Sequential, + /// The application expects to access the specified data in a random order. + Random, + /// The application expects to access the specified data in the near future. + Willneed, + /// The application expects that it will not access the specified data in the near future. + Dontneed, + /// The application expects to access the specified data once and then not reuse it thereafter. + Noreuse, + } + impl core::fmt::Debug for Advice { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Advice::Normal => { + f.debug_tuple("Advice::Normal").finish() + } + Advice::Sequential => { + f.debug_tuple("Advice::Sequential").finish() + } + Advice::Random => { + f.debug_tuple("Advice::Random").finish() + } + Advice::Willneed => { + f.debug_tuple("Advice::Willneed").finish() + } + Advice::Dontneed => { + f.debug_tuple("Advice::Dontneed").finish() + } + Advice::Noreuse => { + f.debug_tuple("Advice::Noreuse").finish() + } + } + } + } + wit_bindgen_rust::bitflags::bitflags! { + /// File descriptor flags. + pub struct Fdflags: u8 { + /// Append mode: Data written to the file is always appended to the file's end. + const APPEND = 1 << 0; + /// Write according to synchronized I/O data integrity completion. Only the data stored in the file is synchronized. + const DSYNC = 1 << 1; + /// Non-blocking mode. + const NONBLOCK = 1 << 2; + /// Synchronized read I/O operations. + const RSYNC = 1 << 3; + /// Write according to synchronized I/O file integrity completion. In + /// addition to synchronizing the data stored in the file, the implementation + /// may also synchronously update the file's metadata. + const SYNC = 1 << 4; + } + } + impl Fdflags { + /// Convert from a raw integer, preserving any unknown bits. See + /// + pub fn from_bits_preserve(bits: u8) -> Self { + Self { bits } + } + } + /// File descriptor attributes. + #[repr(C)] + #[derive(Copy, Clone)] + pub struct Fdstat { + /// File type. + pub fs_filetype: Filetype, + /// File descriptor flags. + pub fs_flags: Fdflags, + /// Rights that apply to this file descriptor. + pub fs_rights_base: Rights, + /// Maximum set of rights that may be installed on new file descriptors that + /// are created through this file descriptor, e.g., through `path_open`. + pub fs_rights_inheriting: Rights, + } + impl core::fmt::Debug for Fdstat { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Fdstat").field("fs-filetype", &self.fs_filetype).field("fs-flags", &self.fs_flags).field("fs-rights-base", &self.fs_rights_base).field("fs-rights-inheriting", &self.fs_rights_inheriting).finish()} + } + wit_bindgen_rust::bitflags::bitflags! { + /// Which file time attributes to adjust. + /// TODO: wit appears to not have support for flags repr + /// (@witx repr u16) + pub struct Fstflags: u8 { + /// Adjust the last data access timestamp to the value stored in `filestat::atim`. + const SET_ATIM = 1 << 0; + /// Adjust the last data access timestamp to the time of clock `clockid::realtime`. + const SET_ATIM_NOW = 1 << 1; + /// Adjust the last data modification timestamp to the value stored in `filestat::mtim`. + const SET_MTIM = 1 << 2; + /// Adjust the last data modification timestamp to the time of clock `clockid::realtime`. + const SET_MTIM_NOW = 1 << 3; + } + } + impl Fstflags { + /// Convert from a raw integer, preserving any unknown bits. See + /// + pub fn from_bits_preserve(bits: u8) -> Self { + Self { bits } + } + } + wit_bindgen_rust::bitflags::bitflags! { + /// Flags determining the method of how paths are resolved. + /// TODO: wit appears to not have support for flags repr + /// (@witx repr u32) + pub struct Lookup: u8 { + /// As long as the resolved path corresponds to a symbolic link, it is expanded. + const SYMLINK_FOLLOW = 1 << 0; + } + } + impl Lookup { + /// Convert from a raw integer, preserving any unknown bits. See + /// + pub fn from_bits_preserve(bits: u8) -> Self { + Self { bits } + } + } + wit_bindgen_rust::bitflags::bitflags! { + /// Open flags used by `path_open`. + /// TODO: wit appears to not have support for flags repr + /// (@witx repr u16) + pub struct Oflags: u8 { + /// Create file if it does not exist. + const CREATE = 1 << 0; + /// Fail if not a directory. + const DIRECTORY = 1 << 1; + /// Fail if file already exists. + const EXCL = 1 << 2; + /// Truncate file to size 0. + const TRUNC = 1 << 3; + } + } + impl Oflags { + /// Convert from a raw integer, preserving any unknown bits. See + /// + pub fn from_bits_preserve(bits: u8) -> Self { + Self { bits } + } + } + /// User-provided value that may be attached to objects that is retained when + /// extracted from the implementation. + pub type Userdata = u64; + /// Type of a subscription to an event or its occurrence. + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum Eventtype { + /// The time value of clock `subscription_clock::id` has + /// reached timestamp `subscription_clock::timeout`. + Clock, + /// File descriptor `subscription_fd_readwrite::fd` has data + /// available for reading. This event always triggers for regular files. + FdRead, + /// File descriptor `subscription_fd_readwrite::fd` has capacity + /// available for writing. This event always triggers for regular files. + FdWrite, + } + impl core::fmt::Debug for Eventtype { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Eventtype::Clock => { + f.debug_tuple("Eventtype::Clock").finish() + } + Eventtype::FdRead => { + f.debug_tuple("Eventtype::FdRead").finish() + } + Eventtype::FdWrite => { + f.debug_tuple("Eventtype::FdWrite").finish() + } + } + } + } + wit_bindgen_rust::bitflags::bitflags! { + /// Flags determining how to interpret the timestamp provided in + /// `subscription-clock::timeout`. + pub struct Subclockflags: u8 { + /// If set, treat the timestamp provided in + /// `subscription-clock::timeout` as an absolute timestamp of clock + /// `subscription-clock::id`. If clear, treat the timestamp + /// provided in `subscription-clock::timeout` relative to the + /// current time value of clock `subscription-clock::id`. + const SUBSCRIPTION_CLOCK_ABSTIME = 1 << 0; + } + } + impl Subclockflags { + /// Convert from a raw integer, preserving any unknown bits. See + /// + pub fn from_bits_preserve(bits: u8) -> Self { + Self { bits } + } + } + /// The contents of a `subscription` when type is `eventtype::clock`. + #[repr(C)] + #[derive(Copy, Clone)] + pub struct Snapshot0SubscriptionClock { + /// The user-defined unique identifier of the clock. + pub identifier: Userdata, + /// The clock against which to compare the timestamp. + pub id: Snapshot0Clockid, + /// The absolute or relative timestamp. + pub timeout: Timestamp, + /// The amount of time that the implementation may wait additionally + /// to coalesce with other events. + pub precision: Timestamp, + /// Flags specifying whether the timeout is absolute or relative + pub flags: Subclockflags, + } + impl core::fmt::Debug for Snapshot0SubscriptionClock { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Snapshot0SubscriptionClock").field("identifier", &self.identifier).field("id", &self.id).field("timeout", &self.timeout).field("precision", &self.precision).field("flags", &self.flags).finish()} + } + /// The contents of a `subscription` when type is `eventtype::clock`. + #[repr(C)] + #[derive(Copy, Clone)] + pub struct SubscriptionClock { + /// The clock against which to compare the timestamp. + pub clock_id: Clockid, + /// The absolute or relative timestamp. + pub timeout: Timestamp, + /// The amount of time that the implementation may wait additionally + /// to coalesce with other events. + pub precision: Timestamp, + /// Flags specifying whether the timeout is absolute or relative + pub flags: Subclockflags, + } + impl core::fmt::Debug for SubscriptionClock { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("SubscriptionClock").field("clock-id", &self.clock_id).field("timeout", &self.timeout).field("precision", &self.precision).field("flags", &self.flags).finish()} + } + /// Identifiers for preopened capabilities. + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum Preopentype { + /// A pre-opened directory. + Dir, + } + impl core::fmt::Debug for Preopentype { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Preopentype::Dir => { + f.debug_tuple("Preopentype::Dir").finish() + } + } + } + } + wit_bindgen_rust::bitflags::bitflags! { + /// The state of the file descriptor subscribed to with + /// `eventtype::fd_read` or `eventtype::fd_write`. + pub struct Eventrwflags: u8 { + /// The peer of this socket has closed or disconnected. + const FD_READWRITE_HANGUP = 1 << 0; + } + } + impl Eventrwflags { + /// Convert from a raw integer, preserving any unknown bits. See + /// + pub fn from_bits_preserve(bits: u8) -> Self { + Self { bits } + } + } + /// The contents of an `event` for the `eventtype::fd_read` and + /// `eventtype::fd_write` variants + #[repr(C)] + #[derive(Copy, Clone)] + pub struct EventFdReadwrite { + /// The number of bytes available for reading or writing. + pub nbytes: Filesize, + /// The state of the file descriptor. + pub flags: Eventrwflags, + } + impl core::fmt::Debug for EventFdReadwrite { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("EventFdReadwrite").field("nbytes", &self.nbytes).field("flags", &self.flags).finish()} + } + /// An event that occurred. + #[repr(C)] + #[derive(Copy, Clone)] + pub struct Event { + /// User-provided value that got attached to `subscription::userdata`. + pub userdata: Userdata, + /// If non-zero, an error that occurred while processing the subscription request. + pub error: Errno, + /// The type of the event that occurred, and the contents of the event + pub data: EventEnum, + } + impl core::fmt::Debug for Event { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Event").field("userdata", &self.userdata).field("error", &self.error).field("data", &self.data).finish()} + } + /// The contents of an `event`. + #[derive(Clone, Copy)] + pub enum EventEnum{ + FdRead(EventFdReadwrite), + FdWrite(EventFdReadwrite), + Clock, + } + impl core::fmt::Debug for EventEnum { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + EventEnum::FdRead(e) => { + f.debug_tuple("EventEnum::FdRead").field(e).finish() + } + EventEnum::FdWrite(e) => { + f.debug_tuple("EventEnum::FdWrite").field(e).finish() + } + EventEnum::Clock => { + f.debug_tuple("EventEnum::Clock").finish() + } + } + } + } + /// An event that occurred. + #[repr(C)] + #[derive(Copy, Clone)] + pub struct Snapshot0Event { + /// User-provided value that got attached to `subscription::userdata`. + pub userdata: Userdata, + /// If non-zero, an error that occurred while processing the subscription request. + pub error: Errno, + /// The type of event that occured + pub type_: Eventtype, + /// The contents of the event, if it is an `eventtype::fd_read` or + /// `eventtype::fd_write`. `eventtype::clock` events ignore this field. + pub fd_readwrite: EventFdReadwrite, + } + impl core::fmt::Debug for Snapshot0Event { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Snapshot0Event").field("userdata", &self.userdata).field("error", &self.error).field("type", &self.type_).field("fd-readwrite", &self.fd_readwrite).finish()} + } + /// The contents of a `subscription`, snapshot0 version. + #[derive(Clone, Copy)] + pub enum Snapshot0SubscriptionEnum{ + Clock(Snapshot0SubscriptionClock), + Read(SubscriptionFsReadwrite), + Write(SubscriptionFsReadwrite), + } + impl core::fmt::Debug for Snapshot0SubscriptionEnum { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Snapshot0SubscriptionEnum::Clock(e) => { + f.debug_tuple("Snapshot0SubscriptionEnum::Clock").field(e).finish() + } + Snapshot0SubscriptionEnum::Read(e) => { + f.debug_tuple("Snapshot0SubscriptionEnum::Read").field(e).finish() + } + Snapshot0SubscriptionEnum::Write(e) => { + f.debug_tuple("Snapshot0SubscriptionEnum::Write").field(e).finish() + } + } + } + } + /// The contents of a `subscription`. + #[derive(Clone, Copy)] + pub enum SubscriptionEnum{ + Clock(SubscriptionClock), + Read(SubscriptionFsReadwrite), + Write(SubscriptionFsReadwrite), + } + impl core::fmt::Debug for SubscriptionEnum { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + SubscriptionEnum::Clock(e) => { + f.debug_tuple("SubscriptionEnum::Clock").field(e).finish() + } + SubscriptionEnum::Read(e) => { + f.debug_tuple("SubscriptionEnum::Read").field(e).finish() + } + SubscriptionEnum::Write(e) => { + f.debug_tuple("SubscriptionEnum::Write").field(e).finish() + } + } + } + } + /// The contents of a `subscription` when the variant is + /// `eventtype::fd_read` or `eventtype::fd_write`. + #[repr(C)] + #[derive(Copy, Clone)] + pub struct SubscriptionFsReadwrite { + /// The file descriptor on which to wait for it to become ready for reading or writing. + pub file_descriptor: Fd, + } + impl core::fmt::Debug for SubscriptionFsReadwrite { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("SubscriptionFsReadwrite").field("file-descriptor", &self.file_descriptor).finish()} + } + #[repr(C)] + #[derive(Copy, Clone)] + pub struct Snapshot0Subscription { + pub userdata: Userdata, + pub data: Snapshot0SubscriptionEnum, + } + impl core::fmt::Debug for Snapshot0Subscription { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Snapshot0Subscription").field("userdata", &self.userdata).field("data", &self.data).finish()} + } + #[repr(C)] + #[derive(Copy, Clone)] + pub struct Subscription { + pub userdata: Userdata, + pub data: SubscriptionEnum, + } + impl core::fmt::Debug for Subscription { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Subscription").field("userdata", &self.userdata).field("data", &self.data).finish()} + } + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum Socktype { + Dgram, + Stream, + Raw, + Seqpacket, + } + impl core::fmt::Debug for Socktype { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Socktype::Dgram => { + f.debug_tuple("Socktype::Dgram").finish() + } + Socktype::Stream => { + f.debug_tuple("Socktype::Stream").finish() + } + Socktype::Raw => { + f.debug_tuple("Socktype::Raw").finish() + } + Socktype::Seqpacket => { + f.debug_tuple("Socktype::Seqpacket").finish() + } + } + } + } + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum Sockstatus { + Opening, + Opened, + Closed, + Failed, + } + impl core::fmt::Debug for Sockstatus { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Sockstatus::Opening => { + f.debug_tuple("Sockstatus::Opening").finish() + } + Sockstatus::Opened => { + f.debug_tuple("Sockstatus::Opened").finish() + } + Sockstatus::Closed => { + f.debug_tuple("Sockstatus::Closed").finish() + } + Sockstatus::Failed => { + f.debug_tuple("Sockstatus::Failed").finish() + } + } + } + } + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum Sockoption { + Noop, + ReusePort, + ReuseAddr, + NoDelay, + DontRoute, + OnlyV6, + Broadcast, + MulticastLoopV4, + MulticastLoopV6, + Promiscuous, + Listening, + LastError, + KeepAlive, + Linger, + OobInline, + RecvBufSize, + SendBufSize, + RecvLowat, + SendLowat, + RecvTimeout, + SendTimeout, + ConnectTimeout, + AcceptTimeout, + Ttl, + MulticastTtlV4, + Type, + Proto, + } + impl core::fmt::Debug for Sockoption { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Sockoption::Noop => { + f.debug_tuple("Sockoption::Noop").finish() + } + Sockoption::ReusePort => { + f.debug_tuple("Sockoption::ReusePort").finish() + } + Sockoption::ReuseAddr => { + f.debug_tuple("Sockoption::ReuseAddr").finish() + } + Sockoption::NoDelay => { + f.debug_tuple("Sockoption::NoDelay").finish() + } + Sockoption::DontRoute => { + f.debug_tuple("Sockoption::DontRoute").finish() + } + Sockoption::OnlyV6 => { + f.debug_tuple("Sockoption::OnlyV6").finish() + } + Sockoption::Broadcast => { + f.debug_tuple("Sockoption::Broadcast").finish() + } + Sockoption::MulticastLoopV4 => { + f.debug_tuple("Sockoption::MulticastLoopV4").finish() + } + Sockoption::MulticastLoopV6 => { + f.debug_tuple("Sockoption::MulticastLoopV6").finish() + } + Sockoption::Promiscuous => { + f.debug_tuple("Sockoption::Promiscuous").finish() + } + Sockoption::Listening => { + f.debug_tuple("Sockoption::Listening").finish() + } + Sockoption::LastError => { + f.debug_tuple("Sockoption::LastError").finish() + } + Sockoption::KeepAlive => { + f.debug_tuple("Sockoption::KeepAlive").finish() + } + Sockoption::Linger => { + f.debug_tuple("Sockoption::Linger").finish() + } + Sockoption::OobInline => { + f.debug_tuple("Sockoption::OobInline").finish() + } + Sockoption::RecvBufSize => { + f.debug_tuple("Sockoption::RecvBufSize").finish() + } + Sockoption::SendBufSize => { + f.debug_tuple("Sockoption::SendBufSize").finish() + } + Sockoption::RecvLowat => { + f.debug_tuple("Sockoption::RecvLowat").finish() + } + Sockoption::SendLowat => { + f.debug_tuple("Sockoption::SendLowat").finish() + } + Sockoption::RecvTimeout => { + f.debug_tuple("Sockoption::RecvTimeout").finish() + } + Sockoption::SendTimeout => { + f.debug_tuple("Sockoption::SendTimeout").finish() + } + Sockoption::ConnectTimeout => { + f.debug_tuple("Sockoption::ConnectTimeout").finish() + } + Sockoption::AcceptTimeout => { + f.debug_tuple("Sockoption::AcceptTimeout").finish() + } + Sockoption::Ttl => { + f.debug_tuple("Sockoption::Ttl").finish() + } + Sockoption::MulticastTtlV4 => { + f.debug_tuple("Sockoption::MulticastTtlV4").finish() + } + Sockoption::Type => { + f.debug_tuple("Sockoption::Type").finish() + } + Sockoption::Proto => { + f.debug_tuple("Sockoption::Proto").finish() + } + } + } + } + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum Streamsecurity { + Unencrypted, + AnyEncryption, + ClassicEncryption, + DoubleEncryption, + } + impl core::fmt::Debug for Streamsecurity { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Streamsecurity::Unencrypted => { + f.debug_tuple("Streamsecurity::Unencrypted").finish() + } + Streamsecurity::AnyEncryption => { + f.debug_tuple("Streamsecurity::AnyEncryption").finish() + } + Streamsecurity::ClassicEncryption => { + f.debug_tuple("Streamsecurity::ClassicEncryption").finish() + } + Streamsecurity::DoubleEncryption => { + f.debug_tuple("Streamsecurity::DoubleEncryption").finish() + } + } + } + } + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum Addressfamily { + Unspec, + Inet4, + Inet6, + Unix, + } + impl core::fmt::Debug for Addressfamily { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Addressfamily::Unspec => { + f.debug_tuple("Addressfamily::Unspec").finish() + } + Addressfamily::Inet4 => { + f.debug_tuple("Addressfamily::Inet4").finish() + } + Addressfamily::Inet6 => { + f.debug_tuple("Addressfamily::Inet6").finish() + } + Addressfamily::Unix => { + f.debug_tuple("Addressfamily::Unix").finish() + } + } + } + } + #[repr(C)] + #[derive(Copy, Clone)] + pub struct Snapshot0Filestat { + pub st_dev: Device, + pub st_ino: Inode, + pub st_filetype: Filetype, + pub st_nlink: Snapshot0Linkcount, + pub st_size: Filesize, + pub st_atim: Timestamp, + pub st_mtim: Timestamp, + pub st_ctim: Timestamp, + } + impl core::fmt::Debug for Snapshot0Filestat { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Snapshot0Filestat").field("st-dev", &self.st_dev).field("st-ino", &self.st_ino).field("st-filetype", &self.st_filetype).field("st-nlink", &self.st_nlink).field("st-size", &self.st_size).field("st-atim", &self.st_atim).field("st-mtim", &self.st_mtim).field("st-ctim", &self.st_ctim).finish()} + } + #[repr(C)] + #[derive(Copy, Clone)] + pub struct Filestat { + pub st_dev: Device, + pub st_ino: Inode, + pub st_filetype: Filetype, + pub st_nlink: Linkcount, + pub st_size: Filesize, + pub st_atim: Timestamp, + pub st_mtim: Timestamp, + pub st_ctim: Timestamp, + } + impl core::fmt::Debug for Filestat { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Filestat").field("st-dev", &self.st_dev).field("st-ino", &self.st_ino).field("st-filetype", &self.st_filetype).field("st-nlink", &self.st_nlink).field("st-size", &self.st_size).field("st-atim", &self.st_atim).field("st-mtim", &self.st_mtim).field("st-ctim", &self.st_ctim).finish()} + } + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum Snapshot0Whence { + Cur, + End, + Set, + } + impl core::fmt::Debug for Snapshot0Whence { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Snapshot0Whence::Cur => { + f.debug_tuple("Snapshot0Whence::Cur").finish() + } + Snapshot0Whence::End => { + f.debug_tuple("Snapshot0Whence::End").finish() + } + Snapshot0Whence::Set => { + f.debug_tuple("Snapshot0Whence::Set").finish() + } + } + } + } + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum Whence { + Set, + Cur, + End, + } + impl core::fmt::Debug for Whence { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Whence::Set => { + f.debug_tuple("Whence::Set").finish() + } + Whence::Cur => { + f.debug_tuple("Whence::Cur").finish() + } + Whence::End => { + f.debug_tuple("Whence::End").finish() + } + } + } + } + #[repr(C)] + #[derive(Copy, Clone)] + pub struct Tty { + pub cols: u32, + pub rows: u32, + pub width: u32, + pub height: u32, + pub stdin_tty: bool, + pub stdout_tty: bool, + pub stderr_tty: bool, + pub echo: bool, + pub line_buffered: bool, + } + impl core::fmt::Debug for Tty { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Tty").field("cols", &self.cols).field("rows", &self.rows).field("width", &self.width).field("height", &self.height).field("stdin-tty", &self.stdin_tty).field("stdout-tty", &self.stdout_tty).field("stderr-tty", &self.stderr_tty).field("echo", &self.echo).field("line-buffered", &self.line_buffered).finish()} + } + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum BusDataFormat { + Raw, + Bincode, + MessagePack, + Json, + Yaml, + Xml, + Rkyv, + } + impl core::fmt::Debug for BusDataFormat { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + BusDataFormat::Raw => { + f.debug_tuple("BusDataFormat::Raw").finish() + } + BusDataFormat::Bincode => { + f.debug_tuple("BusDataFormat::Bincode").finish() + } + BusDataFormat::MessagePack => { + f.debug_tuple("BusDataFormat::MessagePack").finish() + } + BusDataFormat::Json => { + f.debug_tuple("BusDataFormat::Json").finish() + } + BusDataFormat::Yaml => { + f.debug_tuple("BusDataFormat::Yaml").finish() + } + BusDataFormat::Xml => { + f.debug_tuple("BusDataFormat::Xml").finish() + } + BusDataFormat::Rkyv => { + f.debug_tuple("BusDataFormat::Rkyv").finish() + } + } + } + } + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum BusEventType { + Noop, + Exit, + Call, + Result, + Fault, + Close, + } + impl core::fmt::Debug for BusEventType { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + BusEventType::Noop => { + f.debug_tuple("BusEventType::Noop").finish() + } + BusEventType::Exit => { + f.debug_tuple("BusEventType::Exit").finish() + } + BusEventType::Call => { + f.debug_tuple("BusEventType::Call").finish() + } + BusEventType::Result => { + f.debug_tuple("BusEventType::Result").finish() + } + BusEventType::Fault => { + f.debug_tuple("BusEventType::Fault").finish() + } + BusEventType::Close => { + f.debug_tuple("BusEventType::Close").finish() + } + } + } + } + pub type Bid = u32; + pub type Cid = u32; + /// __wasi_option_t + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum OptionTag { + None, + Some, + } + impl core::fmt::Debug for OptionTag { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + OptionTag::None => { + f.debug_tuple("OptionTag::None").finish() + } + OptionTag::Some => { + f.debug_tuple("OptionTag::Some").finish() + } + } + } + } + #[repr(C)] + #[derive(Copy, Clone)] + pub struct OptionBid { + pub tag: OptionTag, + pub bid: Bid, + } + impl core::fmt::Debug for OptionBid { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("OptionBid").field("tag", &self.tag).field("bid", &self.bid).finish()} + } + #[repr(C)] + #[derive(Copy, Clone)] + pub struct OptionCid { + pub tag: OptionTag, + pub cid: Cid, + } + impl core::fmt::Debug for OptionCid { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("OptionCid").field("tag", &self.tag).field("cid", &self.cid).finish()} + } + #[repr(C)] + #[derive(Copy, Clone)] + pub struct OptionFd { + pub tag: OptionTag, + pub fd: Fd, + } + impl core::fmt::Debug for OptionFd { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("OptionFd").field("tag", &self.tag).field("fd", &self.fd).finish()} + } + #[repr(C)] + #[derive(Copy, Clone)] + pub struct BusHandles { + pub bid: Bid, + pub stdin: OptionFd, + pub stdout: OptionFd, + pub stderr: OptionFd, + } + impl core::fmt::Debug for BusHandles { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("BusHandles").field("bid", &self.bid).field("stdin", &self.stdin).field("stdout", &self.stdout).field("stderr", &self.stderr).finish()} + } + pub type ExitCode = u32; + #[repr(C)] + #[derive(Copy, Clone)] + pub struct BusEventExit { + pub bid: Bid, + pub rval: ExitCode, + } + impl core::fmt::Debug for BusEventExit { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("BusEventExit").field("bid", &self.bid).field("rval", &self.rval).finish()} + } + #[repr(C)] + #[derive(Copy, Clone)] + pub struct BusEventFault { + pub cid: Cid, + pub err: BusErrno, + } + impl core::fmt::Debug for BusEventFault { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("BusEventFault").field("cid", &self.cid).field("err", &self.err).finish()} + } + #[repr(C)] + #[derive(Copy, Clone)] + pub struct BusEventClose { + pub cid: Cid, + } + impl core::fmt::Debug for BusEventClose { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("BusEventClose").field("cid", &self.cid).finish()} + } + pub type EventFdFlags = u16; + #[repr(C)] + #[derive(Copy, Clone)] + pub struct PrestatUDir { + pub pr_name_len: u32, + } + impl core::fmt::Debug for PrestatUDir { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("PrestatUDir").field("pr-name-len", &self.pr_name_len).finish()} + } + #[repr(C)] + #[derive(Copy, Clone)] + pub struct PrestatU { + pub dir: PrestatUDir, + } + impl core::fmt::Debug for PrestatU { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("PrestatU").field("dir", &self.dir).finish()} + } + #[repr(C)] + #[derive(Copy, Clone)] + pub struct Prestat { + pub pr_type: Preopentype, + pub u: PrestatU, + } + impl core::fmt::Debug for Prestat { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Prestat").field("pr-type", &self.pr_type).field("u", &self.u).finish()} + } + pub type FileDelta = i64; + pub type LookupFlags = u32; + pub type Count = u32; + #[repr(C)] + #[derive(Copy, Clone)] + pub struct PipeHandles { + pub pipe: Fd, + pub other: Fd, + } + impl core::fmt::Debug for PipeHandles { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("PipeHandles").field("pipe", &self.pipe).field("other", &self.other).finish()} + } + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum StdioMode { + Reserved, + Piped, + Inherit, + Null, + Log, + } + impl core::fmt::Debug for StdioMode { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + StdioMode::Reserved => { + f.debug_tuple("StdioMode::Reserved").finish() + } + StdioMode::Piped => { + f.debug_tuple("StdioMode::Piped").finish() + } + StdioMode::Inherit => { + f.debug_tuple("StdioMode::Inherit").finish() + } + StdioMode::Null => { + f.debug_tuple("StdioMode::Null").finish() + } + StdioMode::Log => { + f.debug_tuple("StdioMode::Log").finish() + } + } + } + } + #[repr(u16)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum SockProto { + Ip, + Icmp, + Igmp, + ProtoThree, + Ipip, + ProtoFive, + Tcp, + ProtoSeven, + Egp, + ProtoNine, + ProtoTen, + ProtoEleven, + Pup, + ProtoThirteen, + ProtoFourteen, + ProtoFifteen, + ProtoSixteen, + Udp, + ProtoEighteen, + ProtoNineteen, + ProtoTwenty, + ProtoTwentyone, + Idp, + ProtoTwentythree, + ProtoTwentyfour, + ProtoTwentyfive, + ProtoTwentysix, + ProtoTwentyseven, + ProtoTwentyeight, + ProtoTp, + ProtoThirty, + ProtoThirtyone, + ProtoThirtytwo, + Dccp, + ProtoThirtyfour, + ProtoThirtyfive, + ProtoThirtysix, + ProtoThirtyseven, + ProtoThirtyeight, + ProtoThirtynine, + ProtoFourty, + Ipv6, + ProtoFourtytwo, + Routing, + Fragment, + ProtoFourtyfive, + Rsvp, + Gre, + ProtoFourtyeight, + ProtoFourtynine, + Esp, + Ah, + ProtoFiftytwo, + ProtoFiftythree, + ProtoFiftyfour, + ProtoFiftyfive, + ProtoFiftysix, + ProtoFiftyseven, + Icmpv6, + None, + Dstopts, + ProtoSixtyone, + ProtoSixtytwo, + ProtoSixtythree, + ProtoSixtyfour, + ProtoSixtyfive, + ProtoSixtysix, + ProtoSixtyseven, + ProtoSixtyeight, + ProtoSixtynine, + ProtoSeventy, + ProtoSeventyone, + ProtoSeventytwo, + ProtoSeventythree, + ProtoSeventyfour, + ProtoSeventyfive, + ProtoSeventysix, + ProtoSeventyseven, + ProtoSeventyeight, + ProtoSeventynine, + ProtoEighty, + ProtoEightyone, + ProtoEightytwo, + ProtoEightythree, + ProtoEightyfour, + ProtoEightyfive, + ProtoEightysix, + ProtoEightyseven, + ProtoEightyeight, + ProtoEightynine, + ProtoNinety, + ProtoNinetyone, + Mtp, + ProtoNinetythree, + Beetph, + ProtoNinetyfive, + ProtoNinetysix, + ProtoNineetyseven, + Encap, + ProtoNinetynine, + ProtoOnehundred, + ProtoOnehundredandone, + ProtoOnehundredandtwo, + Pim, + ProtoOnehundredandfour, + ProtoOnehundredandfive, + ProtoOnehundredandsix, + ProtoOnehundredandseven, + Comp, + ProtoOnehundredandnine, + ProtoOnehundredandten, + ProtoOnehundredandeleven, + ProtoOnehundredandtwelve, + ProtoOnehundredandthirteen, + ProtoOnehundredandfourteen, + ProtoOnehundredandfifteen, + ProtoOnehundredandsixteen, + ProtoOnehundredandseventeen, + ProtoOnehundredandeighteen, + ProtoOnehundredandnineteen, + ProtoOnehundredandtwenty, + ProtoOnehundredandtwentyone, + ProtoOnehundredandtwentytwo, + ProtoOnehundredandtwentythree, + ProtoOnehundredandtwentyfour, + ProtoOnehundredandtwentyfive, + ProtoOnehundredandtwentysix, + ProtoOnehundredandtwentyseven, + ProtoOnehundredandtwentyeight, + ProtoOnehundredandtwentynine, + ProtoOnehundredandthirty, + ProtoOnehundredandthirtyone, + Sctp, + ProtoOnehundredandthirtythree, + ProtoOnehundredandthirtyfour, + Mh, + Udplite, + Mpls, + ProtoOnehundredandthirtyeight, + ProtoOnehundredandthirtynine, + ProtoOnehundredandfourty, + ProtoOnehundredandfourtyone, + ProtoOnehundredandfourtytwo, + Ethernet, + ProtoOnehundredandfourtyfour, + ProtoOnehundredandfourtyfive, + ProtoOnehundredandfourtysix, + ProtoOnehundredandfourtyseven, + ProtoOnehundredandfourtyeight, + ProtoOnehundredandfourtynine, + ProtoOnehundredandfifty, + ProtoOnehundredandfiftyone, + ProtoOnehundredandfiftytwo, + ProtoOnehundredandfiftythree, + ProtoOnehundredandfiftyfour, + ProtoOnehundredandfiftyfive, + ProtoOnehundredandfiftysix, + ProtoOnehundredandfiftyseven, + ProtoOnehundredandfiftyeight, + ProtoOnehundredandfiftynine, + ProtoOnehundredandsixty, + ProtoOnehundredandsixtyone, + ProtoOnehundredandsixtytwo, + ProtoOnehundredandsixtythree, + ProtoOnehundredandsixtyfour, + ProtoOnehundredandsixtyfive, + ProtoOnehundredandsixtysix, + ProtoOnehundredandsixtyseven, + ProtoOnehundredandsixtyeight, + ProtoOnehundredandsixtynine, + ProtoOnehundredandseventy, + ProtoOnehundredandseventyone, + ProtoOnehundredandseventytwo, + ProtoOnehundredandseventythree, + ProtoOnehundredandseventyfour, + ProtoOnehundredandseventyfive, + ProtoOnehundredandseventysix, + ProtoOnehundredandseventyseven, + ProtoOnehundredandseventyeight, + ProtoOnehundredandseventynine, + ProtoOnehundredandeighty, + ProtoOnehundredandeightyone, + ProtoOnehundredandeightytwo, + ProtoOnehundredandeightythree, + ProtoOnehundredandeightyfour, + ProtoOnehundredandeightyfive, + ProtoOnehundredandeightysix, + ProtoOnehundredandeightyseven, + ProtoOnehundredandeightyeight, + ProtoOnehundredandeightynine, + ProtoOnehundredandninety, + ProtoOnehundredandninetyone, + ProtoOnehundredandninetytwo, + ProtoOnehundredandninetythree, + ProtoOnehundredandninetyfour, + ProtoOnehundredandninetyfive, + ProtoOnehundredandninetysix, + ProtoOnehundredandninetyseven, + ProtoOnehundredandninetyeight, + ProtoOnehundredandninetynine, + ProtoTwohundred, + ProtoTwohundredandone, + ProtoTwohundredandtwo, + ProtoTwohundredandthree, + ProtoTwohundredandfour, + ProtoTwohundredandfive, + ProtoTwohundredandsix, + ProtoTwohundredandseven, + ProtoTwohundredandeight, + ProtoTwohundredandnine, + ProtoTwohundredandten, + ProtoTwohundredandeleven, + ProtoTwohundredandtwelve, + ProtoTwohundredandthirteen, + ProtoTwohundredandfourteen, + ProtoTwohundredandfifteen, + ProtoTwohundredandsixteen, + ProtoTwohundredandseventeen, + ProtoTwohundredandeighteen, + ProtoTwohundredandnineteen, + ProtoTwohundredandtwenty, + ProtoTwohundredandtwentyone, + ProtoTwohundredandtwentytwo, + ProtoTwohundredandtwentythree, + ProtoTwohundredandtwentyfour, + ProtoTwohundredandtwentyfive, + ProtoTwohundredandtwentysix, + ProtoTwohundredandtwentyseven, + ProtoTwohundredandtwentyeight, + ProtoTwohundredandtwentynine, + ProtoTwohundredandthirty, + ProtoTwohundredandthirtyone, + ProtoTwohundredandthirtytwo, + ProtoTwohundredandthirtythree, + ProtoTwohundredandthirtyfour, + ProtoTwohundredandthirtyfive, + ProtoTwohundredandthirtysix, + ProtoTwohundredandthirtyseven, + ProtoTwohundredandthirtyeight, + ProtoTwohundredandthirtynine, + ProtoTwohundredandfourty, + ProtoTwohundredandfourtyone, + ProtoTwohundredandfourtytwo, + ProtoTwohundredandfourtythree, + ProtoTwohundredandfourtyfour, + ProtoTwohundredandfourtyfive, + ProtoTwohundredandfourtysix, + ProtoTwohundredandfourtyseven, + ProtoTwohundredandfourtyeight, + ProtoTwohundredandfourtynine, + ProtoTwohundredandfifty, + ProtoTwohundredandfiftyone, + ProtoTwohundredandfiftytwo, + ProtoTwohundredandfiftythree, + ProtoTwohundredandfiftyfour, + ProtoRaw, + ProtoTwohundredandfiftysix, + ProtoTwohundredandfiftyseven, + ProtoTwohundredandfiftyeight, + ProtoTwohundredandfiftynine, + ProtoTwohundredandsixty, + ProtoTwohundredandsixtyone, + Mptcp, + Max, + } + impl core::fmt::Debug for SockProto { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + SockProto::Ip => { + f.debug_tuple("SockProto::Ip").finish() + } + SockProto::Icmp => { + f.debug_tuple("SockProto::Icmp").finish() + } + SockProto::Igmp => { + f.debug_tuple("SockProto::Igmp").finish() + } + SockProto::ProtoThree => { + f.debug_tuple("SockProto::ProtoThree").finish() + } + SockProto::Ipip => { + f.debug_tuple("SockProto::Ipip").finish() + } + SockProto::ProtoFive => { + f.debug_tuple("SockProto::ProtoFive").finish() + } + SockProto::Tcp => { + f.debug_tuple("SockProto::Tcp").finish() + } + SockProto::ProtoSeven => { + f.debug_tuple("SockProto::ProtoSeven").finish() + } + SockProto::Egp => { + f.debug_tuple("SockProto::Egp").finish() + } + SockProto::ProtoNine => { + f.debug_tuple("SockProto::ProtoNine").finish() + } + SockProto::ProtoTen => { + f.debug_tuple("SockProto::ProtoTen").finish() + } + SockProto::ProtoEleven => { + f.debug_tuple("SockProto::ProtoEleven").finish() + } + SockProto::Pup => { + f.debug_tuple("SockProto::Pup").finish() + } + SockProto::ProtoThirteen => { + f.debug_tuple("SockProto::ProtoThirteen").finish() + } + SockProto::ProtoFourteen => { + f.debug_tuple("SockProto::ProtoFourteen").finish() + } + SockProto::ProtoFifteen => { + f.debug_tuple("SockProto::ProtoFifteen").finish() + } + SockProto::ProtoSixteen => { + f.debug_tuple("SockProto::ProtoSixteen").finish() + } + SockProto::Udp => { + f.debug_tuple("SockProto::Udp").finish() + } + SockProto::ProtoEighteen => { + f.debug_tuple("SockProto::ProtoEighteen").finish() + } + SockProto::ProtoNineteen => { + f.debug_tuple("SockProto::ProtoNineteen").finish() + } + SockProto::ProtoTwenty => { + f.debug_tuple("SockProto::ProtoTwenty").finish() + } + SockProto::ProtoTwentyone => { + f.debug_tuple("SockProto::ProtoTwentyone").finish() + } + SockProto::Idp => { + f.debug_tuple("SockProto::Idp").finish() + } + SockProto::ProtoTwentythree => { + f.debug_tuple("SockProto::ProtoTwentythree").finish() + } + SockProto::ProtoTwentyfour => { + f.debug_tuple("SockProto::ProtoTwentyfour").finish() + } + SockProto::ProtoTwentyfive => { + f.debug_tuple("SockProto::ProtoTwentyfive").finish() + } + SockProto::ProtoTwentysix => { + f.debug_tuple("SockProto::ProtoTwentysix").finish() + } + SockProto::ProtoTwentyseven => { + f.debug_tuple("SockProto::ProtoTwentyseven").finish() + } + SockProto::ProtoTwentyeight => { + f.debug_tuple("SockProto::ProtoTwentyeight").finish() + } + SockProto::ProtoTp => { + f.debug_tuple("SockProto::ProtoTp").finish() + } + SockProto::ProtoThirty => { + f.debug_tuple("SockProto::ProtoThirty").finish() + } + SockProto::ProtoThirtyone => { + f.debug_tuple("SockProto::ProtoThirtyone").finish() + } + SockProto::ProtoThirtytwo => { + f.debug_tuple("SockProto::ProtoThirtytwo").finish() + } + SockProto::Dccp => { + f.debug_tuple("SockProto::Dccp").finish() + } + SockProto::ProtoThirtyfour => { + f.debug_tuple("SockProto::ProtoThirtyfour").finish() + } + SockProto::ProtoThirtyfive => { + f.debug_tuple("SockProto::ProtoThirtyfive").finish() + } + SockProto::ProtoThirtysix => { + f.debug_tuple("SockProto::ProtoThirtysix").finish() + } + SockProto::ProtoThirtyseven => { + f.debug_tuple("SockProto::ProtoThirtyseven").finish() + } + SockProto::ProtoThirtyeight => { + f.debug_tuple("SockProto::ProtoThirtyeight").finish() + } + SockProto::ProtoThirtynine => { + f.debug_tuple("SockProto::ProtoThirtynine").finish() + } + SockProto::ProtoFourty => { + f.debug_tuple("SockProto::ProtoFourty").finish() + } + SockProto::Ipv6 => { + f.debug_tuple("SockProto::Ipv6").finish() + } + SockProto::ProtoFourtytwo => { + f.debug_tuple("SockProto::ProtoFourtytwo").finish() + } + SockProto::Routing => { + f.debug_tuple("SockProto::Routing").finish() + } + SockProto::Fragment => { + f.debug_tuple("SockProto::Fragment").finish() + } + SockProto::ProtoFourtyfive => { + f.debug_tuple("SockProto::ProtoFourtyfive").finish() + } + SockProto::Rsvp => { + f.debug_tuple("SockProto::Rsvp").finish() + } + SockProto::Gre => { + f.debug_tuple("SockProto::Gre").finish() + } + SockProto::ProtoFourtyeight => { + f.debug_tuple("SockProto::ProtoFourtyeight").finish() + } + SockProto::ProtoFourtynine => { + f.debug_tuple("SockProto::ProtoFourtynine").finish() + } + SockProto::Esp => { + f.debug_tuple("SockProto::Esp").finish() + } + SockProto::Ah => { + f.debug_tuple("SockProto::Ah").finish() + } + SockProto::ProtoFiftytwo => { + f.debug_tuple("SockProto::ProtoFiftytwo").finish() + } + SockProto::ProtoFiftythree => { + f.debug_tuple("SockProto::ProtoFiftythree").finish() + } + SockProto::ProtoFiftyfour => { + f.debug_tuple("SockProto::ProtoFiftyfour").finish() + } + SockProto::ProtoFiftyfive => { + f.debug_tuple("SockProto::ProtoFiftyfive").finish() + } + SockProto::ProtoFiftysix => { + f.debug_tuple("SockProto::ProtoFiftysix").finish() + } + SockProto::ProtoFiftyseven => { + f.debug_tuple("SockProto::ProtoFiftyseven").finish() + } + SockProto::Icmpv6 => { + f.debug_tuple("SockProto::Icmpv6").finish() + } + SockProto::None => { + f.debug_tuple("SockProto::None").finish() + } + SockProto::Dstopts => { + f.debug_tuple("SockProto::Dstopts").finish() + } + SockProto::ProtoSixtyone => { + f.debug_tuple("SockProto::ProtoSixtyone").finish() + } + SockProto::ProtoSixtytwo => { + f.debug_tuple("SockProto::ProtoSixtytwo").finish() + } + SockProto::ProtoSixtythree => { + f.debug_tuple("SockProto::ProtoSixtythree").finish() + } + SockProto::ProtoSixtyfour => { + f.debug_tuple("SockProto::ProtoSixtyfour").finish() + } + SockProto::ProtoSixtyfive => { + f.debug_tuple("SockProto::ProtoSixtyfive").finish() + } + SockProto::ProtoSixtysix => { + f.debug_tuple("SockProto::ProtoSixtysix").finish() + } + SockProto::ProtoSixtyseven => { + f.debug_tuple("SockProto::ProtoSixtyseven").finish() + } + SockProto::ProtoSixtyeight => { + f.debug_tuple("SockProto::ProtoSixtyeight").finish() + } + SockProto::ProtoSixtynine => { + f.debug_tuple("SockProto::ProtoSixtynine").finish() + } + SockProto::ProtoSeventy => { + f.debug_tuple("SockProto::ProtoSeventy").finish() + } + SockProto::ProtoSeventyone => { + f.debug_tuple("SockProto::ProtoSeventyone").finish() + } + SockProto::ProtoSeventytwo => { + f.debug_tuple("SockProto::ProtoSeventytwo").finish() + } + SockProto::ProtoSeventythree => { + f.debug_tuple("SockProto::ProtoSeventythree").finish() + } + SockProto::ProtoSeventyfour => { + f.debug_tuple("SockProto::ProtoSeventyfour").finish() + } + SockProto::ProtoSeventyfive => { + f.debug_tuple("SockProto::ProtoSeventyfive").finish() + } + SockProto::ProtoSeventysix => { + f.debug_tuple("SockProto::ProtoSeventysix").finish() + } + SockProto::ProtoSeventyseven => { + f.debug_tuple("SockProto::ProtoSeventyseven").finish() + } + SockProto::ProtoSeventyeight => { + f.debug_tuple("SockProto::ProtoSeventyeight").finish() + } + SockProto::ProtoSeventynine => { + f.debug_tuple("SockProto::ProtoSeventynine").finish() + } + SockProto::ProtoEighty => { + f.debug_tuple("SockProto::ProtoEighty").finish() + } + SockProto::ProtoEightyone => { + f.debug_tuple("SockProto::ProtoEightyone").finish() + } + SockProto::ProtoEightytwo => { + f.debug_tuple("SockProto::ProtoEightytwo").finish() + } + SockProto::ProtoEightythree => { + f.debug_tuple("SockProto::ProtoEightythree").finish() + } + SockProto::ProtoEightyfour => { + f.debug_tuple("SockProto::ProtoEightyfour").finish() + } + SockProto::ProtoEightyfive => { + f.debug_tuple("SockProto::ProtoEightyfive").finish() + } + SockProto::ProtoEightysix => { + f.debug_tuple("SockProto::ProtoEightysix").finish() + } + SockProto::ProtoEightyseven => { + f.debug_tuple("SockProto::ProtoEightyseven").finish() + } + SockProto::ProtoEightyeight => { + f.debug_tuple("SockProto::ProtoEightyeight").finish() + } + SockProto::ProtoEightynine => { + f.debug_tuple("SockProto::ProtoEightynine").finish() + } + SockProto::ProtoNinety => { + f.debug_tuple("SockProto::ProtoNinety").finish() + } + SockProto::ProtoNinetyone => { + f.debug_tuple("SockProto::ProtoNinetyone").finish() + } + SockProto::Mtp => { + f.debug_tuple("SockProto::Mtp").finish() + } + SockProto::ProtoNinetythree => { + f.debug_tuple("SockProto::ProtoNinetythree").finish() + } + SockProto::Beetph => { + f.debug_tuple("SockProto::Beetph").finish() + } + SockProto::ProtoNinetyfive => { + f.debug_tuple("SockProto::ProtoNinetyfive").finish() + } + SockProto::ProtoNinetysix => { + f.debug_tuple("SockProto::ProtoNinetysix").finish() + } + SockProto::ProtoNineetyseven => { + f.debug_tuple("SockProto::ProtoNineetyseven").finish() + } + SockProto::Encap => { + f.debug_tuple("SockProto::Encap").finish() + } + SockProto::ProtoNinetynine => { + f.debug_tuple("SockProto::ProtoNinetynine").finish() + } + SockProto::ProtoOnehundred => { + f.debug_tuple("SockProto::ProtoOnehundred").finish() + } + SockProto::ProtoOnehundredandone => { + f.debug_tuple("SockProto::ProtoOnehundredandone").finish() + } + SockProto::ProtoOnehundredandtwo => { + f.debug_tuple("SockProto::ProtoOnehundredandtwo").finish() + } + SockProto::Pim => { + f.debug_tuple("SockProto::Pim").finish() + } + SockProto::ProtoOnehundredandfour => { + f.debug_tuple("SockProto::ProtoOnehundredandfour").finish() + } + SockProto::ProtoOnehundredandfive => { + f.debug_tuple("SockProto::ProtoOnehundredandfive").finish() + } + SockProto::ProtoOnehundredandsix => { + f.debug_tuple("SockProto::ProtoOnehundredandsix").finish() + } + SockProto::ProtoOnehundredandseven => { + f.debug_tuple("SockProto::ProtoOnehundredandseven").finish() + } + SockProto::Comp => { + f.debug_tuple("SockProto::Comp").finish() + } + SockProto::ProtoOnehundredandnine => { + f.debug_tuple("SockProto::ProtoOnehundredandnine").finish() + } + SockProto::ProtoOnehundredandten => { + f.debug_tuple("SockProto::ProtoOnehundredandten").finish() + } + SockProto::ProtoOnehundredandeleven => { + f.debug_tuple("SockProto::ProtoOnehundredandeleven").finish() + } + SockProto::ProtoOnehundredandtwelve => { + f.debug_tuple("SockProto::ProtoOnehundredandtwelve").finish() + } + SockProto::ProtoOnehundredandthirteen => { + f.debug_tuple("SockProto::ProtoOnehundredandthirteen").finish() + } + SockProto::ProtoOnehundredandfourteen => { + f.debug_tuple("SockProto::ProtoOnehundredandfourteen").finish() + } + SockProto::ProtoOnehundredandfifteen => { + f.debug_tuple("SockProto::ProtoOnehundredandfifteen").finish() + } + SockProto::ProtoOnehundredandsixteen => { + f.debug_tuple("SockProto::ProtoOnehundredandsixteen").finish() + } + SockProto::ProtoOnehundredandseventeen => { + f.debug_tuple("SockProto::ProtoOnehundredandseventeen").finish() + } + SockProto::ProtoOnehundredandeighteen => { + f.debug_tuple("SockProto::ProtoOnehundredandeighteen").finish() + } + SockProto::ProtoOnehundredandnineteen => { + f.debug_tuple("SockProto::ProtoOnehundredandnineteen").finish() + } + SockProto::ProtoOnehundredandtwenty => { + f.debug_tuple("SockProto::ProtoOnehundredandtwenty").finish() + } + SockProto::ProtoOnehundredandtwentyone => { + f.debug_tuple("SockProto::ProtoOnehundredandtwentyone").finish() + } + SockProto::ProtoOnehundredandtwentytwo => { + f.debug_tuple("SockProto::ProtoOnehundredandtwentytwo").finish() + } + SockProto::ProtoOnehundredandtwentythree => { + f.debug_tuple("SockProto::ProtoOnehundredandtwentythree").finish() + } + SockProto::ProtoOnehundredandtwentyfour => { + f.debug_tuple("SockProto::ProtoOnehundredandtwentyfour").finish() + } + SockProto::ProtoOnehundredandtwentyfive => { + f.debug_tuple("SockProto::ProtoOnehundredandtwentyfive").finish() + } + SockProto::ProtoOnehundredandtwentysix => { + f.debug_tuple("SockProto::ProtoOnehundredandtwentysix").finish() + } + SockProto::ProtoOnehundredandtwentyseven => { + f.debug_tuple("SockProto::ProtoOnehundredandtwentyseven").finish() + } + SockProto::ProtoOnehundredandtwentyeight => { + f.debug_tuple("SockProto::ProtoOnehundredandtwentyeight").finish() + } + SockProto::ProtoOnehundredandtwentynine => { + f.debug_tuple("SockProto::ProtoOnehundredandtwentynine").finish() + } + SockProto::ProtoOnehundredandthirty => { + f.debug_tuple("SockProto::ProtoOnehundredandthirty").finish() + } + SockProto::ProtoOnehundredandthirtyone => { + f.debug_tuple("SockProto::ProtoOnehundredandthirtyone").finish() + } + SockProto::Sctp => { + f.debug_tuple("SockProto::Sctp").finish() + } + SockProto::ProtoOnehundredandthirtythree => { + f.debug_tuple("SockProto::ProtoOnehundredandthirtythree").finish() + } + SockProto::ProtoOnehundredandthirtyfour => { + f.debug_tuple("SockProto::ProtoOnehundredandthirtyfour").finish() + } + SockProto::Mh => { + f.debug_tuple("SockProto::Mh").finish() + } + SockProto::Udplite => { + f.debug_tuple("SockProto::Udplite").finish() + } + SockProto::Mpls => { + f.debug_tuple("SockProto::Mpls").finish() + } + SockProto::ProtoOnehundredandthirtyeight => { + f.debug_tuple("SockProto::ProtoOnehundredandthirtyeight").finish() + } + SockProto::ProtoOnehundredandthirtynine => { + f.debug_tuple("SockProto::ProtoOnehundredandthirtynine").finish() + } + SockProto::ProtoOnehundredandfourty => { + f.debug_tuple("SockProto::ProtoOnehundredandfourty").finish() + } + SockProto::ProtoOnehundredandfourtyone => { + f.debug_tuple("SockProto::ProtoOnehundredandfourtyone").finish() + } + SockProto::ProtoOnehundredandfourtytwo => { + f.debug_tuple("SockProto::ProtoOnehundredandfourtytwo").finish() + } + SockProto::Ethernet => { + f.debug_tuple("SockProto::Ethernet").finish() + } + SockProto::ProtoOnehundredandfourtyfour => { + f.debug_tuple("SockProto::ProtoOnehundredandfourtyfour").finish() + } + SockProto::ProtoOnehundredandfourtyfive => { + f.debug_tuple("SockProto::ProtoOnehundredandfourtyfive").finish() + } + SockProto::ProtoOnehundredandfourtysix => { + f.debug_tuple("SockProto::ProtoOnehundredandfourtysix").finish() + } + SockProto::ProtoOnehundredandfourtyseven => { + f.debug_tuple("SockProto::ProtoOnehundredandfourtyseven").finish() + } + SockProto::ProtoOnehundredandfourtyeight => { + f.debug_tuple("SockProto::ProtoOnehundredandfourtyeight").finish() + } + SockProto::ProtoOnehundredandfourtynine => { + f.debug_tuple("SockProto::ProtoOnehundredandfourtynine").finish() + } + SockProto::ProtoOnehundredandfifty => { + f.debug_tuple("SockProto::ProtoOnehundredandfifty").finish() + } + SockProto::ProtoOnehundredandfiftyone => { + f.debug_tuple("SockProto::ProtoOnehundredandfiftyone").finish() + } + SockProto::ProtoOnehundredandfiftytwo => { + f.debug_tuple("SockProto::ProtoOnehundredandfiftytwo").finish() + } + SockProto::ProtoOnehundredandfiftythree => { + f.debug_tuple("SockProto::ProtoOnehundredandfiftythree").finish() + } + SockProto::ProtoOnehundredandfiftyfour => { + f.debug_tuple("SockProto::ProtoOnehundredandfiftyfour").finish() + } + SockProto::ProtoOnehundredandfiftyfive => { + f.debug_tuple("SockProto::ProtoOnehundredandfiftyfive").finish() + } + SockProto::ProtoOnehundredandfiftysix => { + f.debug_tuple("SockProto::ProtoOnehundredandfiftysix").finish() + } + SockProto::ProtoOnehundredandfiftyseven => { + f.debug_tuple("SockProto::ProtoOnehundredandfiftyseven").finish() + } + SockProto::ProtoOnehundredandfiftyeight => { + f.debug_tuple("SockProto::ProtoOnehundredandfiftyeight").finish() + } + SockProto::ProtoOnehundredandfiftynine => { + f.debug_tuple("SockProto::ProtoOnehundredandfiftynine").finish() + } + SockProto::ProtoOnehundredandsixty => { + f.debug_tuple("SockProto::ProtoOnehundredandsixty").finish() + } + SockProto::ProtoOnehundredandsixtyone => { + f.debug_tuple("SockProto::ProtoOnehundredandsixtyone").finish() + } + SockProto::ProtoOnehundredandsixtytwo => { + f.debug_tuple("SockProto::ProtoOnehundredandsixtytwo").finish() + } + SockProto::ProtoOnehundredandsixtythree => { + f.debug_tuple("SockProto::ProtoOnehundredandsixtythree").finish() + } + SockProto::ProtoOnehundredandsixtyfour => { + f.debug_tuple("SockProto::ProtoOnehundredandsixtyfour").finish() + } + SockProto::ProtoOnehundredandsixtyfive => { + f.debug_tuple("SockProto::ProtoOnehundredandsixtyfive").finish() + } + SockProto::ProtoOnehundredandsixtysix => { + f.debug_tuple("SockProto::ProtoOnehundredandsixtysix").finish() + } + SockProto::ProtoOnehundredandsixtyseven => { + f.debug_tuple("SockProto::ProtoOnehundredandsixtyseven").finish() + } + SockProto::ProtoOnehundredandsixtyeight => { + f.debug_tuple("SockProto::ProtoOnehundredandsixtyeight").finish() + } + SockProto::ProtoOnehundredandsixtynine => { + f.debug_tuple("SockProto::ProtoOnehundredandsixtynine").finish() + } + SockProto::ProtoOnehundredandseventy => { + f.debug_tuple("SockProto::ProtoOnehundredandseventy").finish() + } + SockProto::ProtoOnehundredandseventyone => { + f.debug_tuple("SockProto::ProtoOnehundredandseventyone").finish() + } + SockProto::ProtoOnehundredandseventytwo => { + f.debug_tuple("SockProto::ProtoOnehundredandseventytwo").finish() + } + SockProto::ProtoOnehundredandseventythree => { + f.debug_tuple("SockProto::ProtoOnehundredandseventythree").finish() + } + SockProto::ProtoOnehundredandseventyfour => { + f.debug_tuple("SockProto::ProtoOnehundredandseventyfour").finish() + } + SockProto::ProtoOnehundredandseventyfive => { + f.debug_tuple("SockProto::ProtoOnehundredandseventyfive").finish() + } + SockProto::ProtoOnehundredandseventysix => { + f.debug_tuple("SockProto::ProtoOnehundredandseventysix").finish() + } + SockProto::ProtoOnehundredandseventyseven => { + f.debug_tuple("SockProto::ProtoOnehundredandseventyseven").finish() + } + SockProto::ProtoOnehundredandseventyeight => { + f.debug_tuple("SockProto::ProtoOnehundredandseventyeight").finish() + } + SockProto::ProtoOnehundredandseventynine => { + f.debug_tuple("SockProto::ProtoOnehundredandseventynine").finish() + } + SockProto::ProtoOnehundredandeighty => { + f.debug_tuple("SockProto::ProtoOnehundredandeighty").finish() + } + SockProto::ProtoOnehundredandeightyone => { + f.debug_tuple("SockProto::ProtoOnehundredandeightyone").finish() + } + SockProto::ProtoOnehundredandeightytwo => { + f.debug_tuple("SockProto::ProtoOnehundredandeightytwo").finish() + } + SockProto::ProtoOnehundredandeightythree => { + f.debug_tuple("SockProto::ProtoOnehundredandeightythree").finish() + } + SockProto::ProtoOnehundredandeightyfour => { + f.debug_tuple("SockProto::ProtoOnehundredandeightyfour").finish() + } + SockProto::ProtoOnehundredandeightyfive => { + f.debug_tuple("SockProto::ProtoOnehundredandeightyfive").finish() + } + SockProto::ProtoOnehundredandeightysix => { + f.debug_tuple("SockProto::ProtoOnehundredandeightysix").finish() + } + SockProto::ProtoOnehundredandeightyseven => { + f.debug_tuple("SockProto::ProtoOnehundredandeightyseven").finish() + } + SockProto::ProtoOnehundredandeightyeight => { + f.debug_tuple("SockProto::ProtoOnehundredandeightyeight").finish() + } + SockProto::ProtoOnehundredandeightynine => { + f.debug_tuple("SockProto::ProtoOnehundredandeightynine").finish() + } + SockProto::ProtoOnehundredandninety => { + f.debug_tuple("SockProto::ProtoOnehundredandninety").finish() + } + SockProto::ProtoOnehundredandninetyone => { + f.debug_tuple("SockProto::ProtoOnehundredandninetyone").finish() + } + SockProto::ProtoOnehundredandninetytwo => { + f.debug_tuple("SockProto::ProtoOnehundredandninetytwo").finish() + } + SockProto::ProtoOnehundredandninetythree => { + f.debug_tuple("SockProto::ProtoOnehundredandninetythree").finish() + } + SockProto::ProtoOnehundredandninetyfour => { + f.debug_tuple("SockProto::ProtoOnehundredandninetyfour").finish() + } + SockProto::ProtoOnehundredandninetyfive => { + f.debug_tuple("SockProto::ProtoOnehundredandninetyfive").finish() + } + SockProto::ProtoOnehundredandninetysix => { + f.debug_tuple("SockProto::ProtoOnehundredandninetysix").finish() + } + SockProto::ProtoOnehundredandninetyseven => { + f.debug_tuple("SockProto::ProtoOnehundredandninetyseven").finish() + } + SockProto::ProtoOnehundredandninetyeight => { + f.debug_tuple("SockProto::ProtoOnehundredandninetyeight").finish() + } + SockProto::ProtoOnehundredandninetynine => { + f.debug_tuple("SockProto::ProtoOnehundredandninetynine").finish() + } + SockProto::ProtoTwohundred => { + f.debug_tuple("SockProto::ProtoTwohundred").finish() + } + SockProto::ProtoTwohundredandone => { + f.debug_tuple("SockProto::ProtoTwohundredandone").finish() + } + SockProto::ProtoTwohundredandtwo => { + f.debug_tuple("SockProto::ProtoTwohundredandtwo").finish() + } + SockProto::ProtoTwohundredandthree => { + f.debug_tuple("SockProto::ProtoTwohundredandthree").finish() + } + SockProto::ProtoTwohundredandfour => { + f.debug_tuple("SockProto::ProtoTwohundredandfour").finish() + } + SockProto::ProtoTwohundredandfive => { + f.debug_tuple("SockProto::ProtoTwohundredandfive").finish() + } + SockProto::ProtoTwohundredandsix => { + f.debug_tuple("SockProto::ProtoTwohundredandsix").finish() + } + SockProto::ProtoTwohundredandseven => { + f.debug_tuple("SockProto::ProtoTwohundredandseven").finish() + } + SockProto::ProtoTwohundredandeight => { + f.debug_tuple("SockProto::ProtoTwohundredandeight").finish() + } + SockProto::ProtoTwohundredandnine => { + f.debug_tuple("SockProto::ProtoTwohundredandnine").finish() + } + SockProto::ProtoTwohundredandten => { + f.debug_tuple("SockProto::ProtoTwohundredandten").finish() + } + SockProto::ProtoTwohundredandeleven => { + f.debug_tuple("SockProto::ProtoTwohundredandeleven").finish() + } + SockProto::ProtoTwohundredandtwelve => { + f.debug_tuple("SockProto::ProtoTwohundredandtwelve").finish() + } + SockProto::ProtoTwohundredandthirteen => { + f.debug_tuple("SockProto::ProtoTwohundredandthirteen").finish() + } + SockProto::ProtoTwohundredandfourteen => { + f.debug_tuple("SockProto::ProtoTwohundredandfourteen").finish() + } + SockProto::ProtoTwohundredandfifteen => { + f.debug_tuple("SockProto::ProtoTwohundredandfifteen").finish() + } + SockProto::ProtoTwohundredandsixteen => { + f.debug_tuple("SockProto::ProtoTwohundredandsixteen").finish() + } + SockProto::ProtoTwohundredandseventeen => { + f.debug_tuple("SockProto::ProtoTwohundredandseventeen").finish() + } + SockProto::ProtoTwohundredandeighteen => { + f.debug_tuple("SockProto::ProtoTwohundredandeighteen").finish() + } + SockProto::ProtoTwohundredandnineteen => { + f.debug_tuple("SockProto::ProtoTwohundredandnineteen").finish() + } + SockProto::ProtoTwohundredandtwenty => { + f.debug_tuple("SockProto::ProtoTwohundredandtwenty").finish() + } + SockProto::ProtoTwohundredandtwentyone => { + f.debug_tuple("SockProto::ProtoTwohundredandtwentyone").finish() + } + SockProto::ProtoTwohundredandtwentytwo => { + f.debug_tuple("SockProto::ProtoTwohundredandtwentytwo").finish() + } + SockProto::ProtoTwohundredandtwentythree => { + f.debug_tuple("SockProto::ProtoTwohundredandtwentythree").finish() + } + SockProto::ProtoTwohundredandtwentyfour => { + f.debug_tuple("SockProto::ProtoTwohundredandtwentyfour").finish() + } + SockProto::ProtoTwohundredandtwentyfive => { + f.debug_tuple("SockProto::ProtoTwohundredandtwentyfive").finish() + } + SockProto::ProtoTwohundredandtwentysix => { + f.debug_tuple("SockProto::ProtoTwohundredandtwentysix").finish() + } + SockProto::ProtoTwohundredandtwentyseven => { + f.debug_tuple("SockProto::ProtoTwohundredandtwentyseven").finish() + } + SockProto::ProtoTwohundredandtwentyeight => { + f.debug_tuple("SockProto::ProtoTwohundredandtwentyeight").finish() + } + SockProto::ProtoTwohundredandtwentynine => { + f.debug_tuple("SockProto::ProtoTwohundredandtwentynine").finish() + } + SockProto::ProtoTwohundredandthirty => { + f.debug_tuple("SockProto::ProtoTwohundredandthirty").finish() + } + SockProto::ProtoTwohundredandthirtyone => { + f.debug_tuple("SockProto::ProtoTwohundredandthirtyone").finish() + } + SockProto::ProtoTwohundredandthirtytwo => { + f.debug_tuple("SockProto::ProtoTwohundredandthirtytwo").finish() + } + SockProto::ProtoTwohundredandthirtythree => { + f.debug_tuple("SockProto::ProtoTwohundredandthirtythree").finish() + } + SockProto::ProtoTwohundredandthirtyfour => { + f.debug_tuple("SockProto::ProtoTwohundredandthirtyfour").finish() + } + SockProto::ProtoTwohundredandthirtyfive => { + f.debug_tuple("SockProto::ProtoTwohundredandthirtyfive").finish() + } + SockProto::ProtoTwohundredandthirtysix => { + f.debug_tuple("SockProto::ProtoTwohundredandthirtysix").finish() + } + SockProto::ProtoTwohundredandthirtyseven => { + f.debug_tuple("SockProto::ProtoTwohundredandthirtyseven").finish() + } + SockProto::ProtoTwohundredandthirtyeight => { + f.debug_tuple("SockProto::ProtoTwohundredandthirtyeight").finish() + } + SockProto::ProtoTwohundredandthirtynine => { + f.debug_tuple("SockProto::ProtoTwohundredandthirtynine").finish() + } + SockProto::ProtoTwohundredandfourty => { + f.debug_tuple("SockProto::ProtoTwohundredandfourty").finish() + } + SockProto::ProtoTwohundredandfourtyone => { + f.debug_tuple("SockProto::ProtoTwohundredandfourtyone").finish() + } + SockProto::ProtoTwohundredandfourtytwo => { + f.debug_tuple("SockProto::ProtoTwohundredandfourtytwo").finish() + } + SockProto::ProtoTwohundredandfourtythree => { + f.debug_tuple("SockProto::ProtoTwohundredandfourtythree").finish() + } + SockProto::ProtoTwohundredandfourtyfour => { + f.debug_tuple("SockProto::ProtoTwohundredandfourtyfour").finish() + } + SockProto::ProtoTwohundredandfourtyfive => { + f.debug_tuple("SockProto::ProtoTwohundredandfourtyfive").finish() + } + SockProto::ProtoTwohundredandfourtysix => { + f.debug_tuple("SockProto::ProtoTwohundredandfourtysix").finish() + } + SockProto::ProtoTwohundredandfourtyseven => { + f.debug_tuple("SockProto::ProtoTwohundredandfourtyseven").finish() + } + SockProto::ProtoTwohundredandfourtyeight => { + f.debug_tuple("SockProto::ProtoTwohundredandfourtyeight").finish() + } + SockProto::ProtoTwohundredandfourtynine => { + f.debug_tuple("SockProto::ProtoTwohundredandfourtynine").finish() + } + SockProto::ProtoTwohundredandfifty => { + f.debug_tuple("SockProto::ProtoTwohundredandfifty").finish() + } + SockProto::ProtoTwohundredandfiftyone => { + f.debug_tuple("SockProto::ProtoTwohundredandfiftyone").finish() + } + SockProto::ProtoTwohundredandfiftytwo => { + f.debug_tuple("SockProto::ProtoTwohundredandfiftytwo").finish() + } + SockProto::ProtoTwohundredandfiftythree => { + f.debug_tuple("SockProto::ProtoTwohundredandfiftythree").finish() + } + SockProto::ProtoTwohundredandfiftyfour => { + f.debug_tuple("SockProto::ProtoTwohundredandfiftyfour").finish() + } + SockProto::ProtoRaw => { + f.debug_tuple("SockProto::ProtoRaw").finish() + } + SockProto::ProtoTwohundredandfiftysix => { + f.debug_tuple("SockProto::ProtoTwohundredandfiftysix").finish() + } + SockProto::ProtoTwohundredandfiftyseven => { + f.debug_tuple("SockProto::ProtoTwohundredandfiftyseven").finish() + } + SockProto::ProtoTwohundredandfiftyeight => { + f.debug_tuple("SockProto::ProtoTwohundredandfiftyeight").finish() + } + SockProto::ProtoTwohundredandfiftynine => { + f.debug_tuple("SockProto::ProtoTwohundredandfiftynine").finish() + } + SockProto::ProtoTwohundredandsixty => { + f.debug_tuple("SockProto::ProtoTwohundredandsixty").finish() + } + SockProto::ProtoTwohundredandsixtyone => { + f.debug_tuple("SockProto::ProtoTwohundredandsixtyone").finish() + } + SockProto::Mptcp => { + f.debug_tuple("SockProto::Mptcp").finish() + } + SockProto::Max => { + f.debug_tuple("SockProto::Max").finish() + } + } + } + } + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum Bool { + False, + True, + } + impl core::fmt::Debug for Bool { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Bool::False => { + f.debug_tuple("Bool::False").finish() + } + Bool::True => { + f.debug_tuple("Bool::True").finish() + } + } + } + } + #[repr(C)] + #[derive(Copy, Clone)] + pub struct OptionTimestamp { + pub tag: OptionTag, + pub u: Timestamp, + } + impl core::fmt::Debug for OptionTimestamp { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("OptionTimestamp").field("tag", &self.tag).field("u", &self.u).finish()} + } + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum Signal { + Sighup, + Sigint, + Sigquit, + Sigill, + Sigtrap, + Sigabrt, + Sigbus, + Sigfpe, + Sigkill, + Sigusr1, + Sigsegv, + Sigusr2, + Sigpipe, + Sigalrm, + Sigterm, + Sigchld, + Sigcont, + Sigstop, + Sigtstp, + Sigttin, + Sigttou, + Sigurg, + Sigxcpu, + Sigxfsz, + Sigvtalrm, + Sigprof, + Sigwinch, + Sigpoll, + Sigpwr, + Sigsys, + } + impl core::fmt::Debug for Signal { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Signal::Sighup => { + f.debug_tuple("Signal::Sighup").finish() + } + Signal::Sigint => { + f.debug_tuple("Signal::Sigint").finish() + } + Signal::Sigquit => { + f.debug_tuple("Signal::Sigquit").finish() + } + Signal::Sigill => { + f.debug_tuple("Signal::Sigill").finish() + } + Signal::Sigtrap => { + f.debug_tuple("Signal::Sigtrap").finish() + } + Signal::Sigabrt => { + f.debug_tuple("Signal::Sigabrt").finish() + } + Signal::Sigbus => { + f.debug_tuple("Signal::Sigbus").finish() + } + Signal::Sigfpe => { + f.debug_tuple("Signal::Sigfpe").finish() + } + Signal::Sigkill => { + f.debug_tuple("Signal::Sigkill").finish() + } + Signal::Sigusr1 => { + f.debug_tuple("Signal::Sigusr1").finish() + } + Signal::Sigsegv => { + f.debug_tuple("Signal::Sigsegv").finish() + } + Signal::Sigusr2 => { + f.debug_tuple("Signal::Sigusr2").finish() + } + Signal::Sigpipe => { + f.debug_tuple("Signal::Sigpipe").finish() + } + Signal::Sigalrm => { + f.debug_tuple("Signal::Sigalrm").finish() + } + Signal::Sigterm => { + f.debug_tuple("Signal::Sigterm").finish() + } + Signal::Sigchld => { + f.debug_tuple("Signal::Sigchld").finish() + } + Signal::Sigcont => { + f.debug_tuple("Signal::Sigcont").finish() + } + Signal::Sigstop => { + f.debug_tuple("Signal::Sigstop").finish() + } + Signal::Sigtstp => { + f.debug_tuple("Signal::Sigtstp").finish() + } + Signal::Sigttin => { + f.debug_tuple("Signal::Sigttin").finish() + } + Signal::Sigttou => { + f.debug_tuple("Signal::Sigttou").finish() + } + Signal::Sigurg => { + f.debug_tuple("Signal::Sigurg").finish() + } + Signal::Sigxcpu => { + f.debug_tuple("Signal::Sigxcpu").finish() + } + Signal::Sigxfsz => { + f.debug_tuple("Signal::Sigxfsz").finish() + } + Signal::Sigvtalrm => { + f.debug_tuple("Signal::Sigvtalrm").finish() + } + Signal::Sigprof => { + f.debug_tuple("Signal::Sigprof").finish() + } + Signal::Sigwinch => { + f.debug_tuple("Signal::Sigwinch").finish() + } + Signal::Sigpoll => { + f.debug_tuple("Signal::Sigpoll").finish() + } + Signal::Sigpwr => { + f.debug_tuple("Signal::Sigpwr").finish() + } + Signal::Sigsys => { + f.debug_tuple("Signal::Sigsys").finish() + } + } + } + } + #[repr(C)] + #[derive(Copy, Clone)] + pub struct AddrUnspec { + pub n0: u8, + } + impl core::fmt::Debug for AddrUnspec { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("AddrUnspec").field("n0", &self.n0).finish()} + } + #[repr(C)] + #[derive(Copy, Clone)] + pub struct AddrUnspecPort { + pub port: u16, + pub addr: AddrUnspec, + } + impl core::fmt::Debug for AddrUnspecPort { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("AddrUnspecPort").field("port", &self.port).field("addr", &self.addr).finish()} + } + #[repr(C)] + #[derive(Copy, Clone)] + pub struct CidrUnspec { + pub addr: AddrUnspec, + pub prefix: u8, + } + impl core::fmt::Debug for CidrUnspec { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("CidrUnspec").field("addr", &self.addr).field("prefix", &self.prefix).finish()} + } + #[repr(C)] + #[derive(Copy, Clone)] + pub struct HttpHandles { + pub req: Fd, + pub res: Fd, + pub hdr: Fd, + } + impl core::fmt::Debug for HttpHandles { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("HttpHandles").field("req", &self.req).field("res", &self.res).field("hdr", &self.hdr).finish()} + } + #[repr(C)] + #[derive(Copy, Clone)] + pub struct HttpStatus { + pub ok: Bool, + pub redirect: Bool, + pub size: Filesize, + pub status: u16, + } + impl core::fmt::Debug for HttpStatus { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("HttpStatus").field("ok", &self.ok).field("redirect", &self.redirect).field("size", &self.size).field("status", &self.status).finish()} + } + pub type RiFlags = u16; + pub type RoFlags = u16; + pub type SdFlags = u8; + pub type SiFlags = u16; + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum Timeout { + Read, + Write, + Connect, + Accept, + } + impl core::fmt::Debug for Timeout { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Timeout::Read => { + f.debug_tuple("Timeout::Read").finish() + } + Timeout::Write => { + f.debug_tuple("Timeout::Write").finish() + } + Timeout::Connect => { + f.debug_tuple("Timeout::Connect").finish() + } + Timeout::Accept => { + f.debug_tuple("Timeout::Accept").finish() + } + } + } + } +} diff --git a/lib/wasi-types/src/wasi/extra.rs b/lib/wasi-types/src/wasi/extra.rs new file mode 100644 index 00000000000..4d74ab8d816 --- /dev/null +++ b/lib/wasi-types/src/wasi/extra.rs @@ -0,0 +1,3982 @@ +use std::mem::MaybeUninit; +use wasmer::ValueType; + +/// Type names used by low-level WASI interfaces. +/// An array size. +/// +/// Note: This is similar to `size_t` in POSIX. +pub type Size = u32; +/// Non-negative file size or length of a region within a file. +pub type Filesize = u64; +/// Timestamp in nanoseconds. +pub type Timestamp = u64; +/// A file descriptor handle. +pub type Fd = u32; +/// A reference to the offset of a directory entry. +pub type Dircookie = u64; +/// The type for the `dirent::d-namlen` field of `dirent` struct. +pub type Dirnamlen = u32; +/// File serial number that is unique within its file system. +pub type Inode = u64; +/// Identifier for a device containing a file system. Can be used in combination +/// with `inode` to uniquely identify a file or directory in the filesystem. +pub type Device = u64; +pub type Linkcount = u64; +pub type Snapshot0Linkcount = u32; +pub type Tid = u32; +pub type Pid = u32; +/// Identifiers for clocks, snapshot0 version. +#[repr(u8)] +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum Snapshot0Clockid { + /// The clock measuring real time. Time value zero corresponds with + /// 1970-01-01T00:00:00Z. + Realtime, + /// The store-wide monotonic clock, which is defined as a clock measuring + /// real time, whose value cannot be adjusted and which cannot have negative + /// clock jumps. The epoch of this clock is undefined. The absolute time + /// value of this clock therefore has no meaning. + Monotonic, + /// The CPU-time clock associated with the current process. + ProcessCputimeId, + /// The CPU-time clock associated with the current thread. + ThreadCputimeId, +} +impl core::fmt::Debug for Snapshot0Clockid { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Snapshot0Clockid::Realtime => f.debug_tuple("Snapshot0Clockid::Realtime").finish(), + Snapshot0Clockid::Monotonic => f.debug_tuple("Snapshot0Clockid::Monotonic").finish(), + Snapshot0Clockid::ProcessCputimeId => { + f.debug_tuple("Snapshot0Clockid::ProcessCputimeId").finish() + } + Snapshot0Clockid::ThreadCputimeId => { + f.debug_tuple("Snapshot0Clockid::ThreadCputimeId").finish() + } + } + } +} +/// Identifiers for clocks. +#[repr(u8)] +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum Clockid { + /// The clock measuring real time. Time value zero corresponds with + /// 1970-01-01T00:00:00Z. + Realtime, + /// The store-wide monotonic clock, which is defined as a clock measuring + /// real time, whose value cannot be adjusted and which cannot have negative + /// clock jumps. The epoch of this clock is undefined. The absolute time + /// value of this clock therefore has no meaning. + Monotonic, +} +impl core::fmt::Debug for Clockid { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Clockid::Realtime => f.debug_tuple("Clockid::Realtime").finish(), + Clockid::Monotonic => f.debug_tuple("Clockid::Monotonic").finish(), + } + } +} +/// Error codes returned by functions. +/// Not all of these error codes are returned by the functions provided by this +/// API; some are used in higher-level library layers, and others are provided +/// merely for alignment with POSIX. +#[repr(u8)] +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum Errno { + /// No error occurred. System call completed successfully. + Success, + /// Argument list too long. + Toobig, + /// Permission denied. + Access, + /// Address in use. + Addrinuse, + /// Address not available. + Addrnotavail, + /// Address family not supported. + Afnosupport, + /// Resource unavailable, or operation would block. + Again, + /// Connection already in progress. + Already, + /// Bad file descriptor. + Badf, + /// Bad message. + Badmsg, + /// Device or resource busy. + Busy, + /// Operation canceled. + Canceled, + /// No child processes. + Child, + /// Connection aborted. + Connaborted, + /// Connection refused. + Connrefused, + /// Connection reset. + Connreset, + /// Resource deadlock would occur. + Deadlk, + /// Destination address required. + Destaddrreq, + /// Mathematics argument out of domain of function. + Dom, + /// Reserved. + Dquot, + /// File exists. + Exist, + /// Bad address. + Fault, + /// File too large. + Fbig, + /// Host is unreachable. + Hostunreach, + /// Identifier removed. + Idrm, + /// Illegal byte sequence. + Ilseq, + /// Operation in progress. + Inprogress, + /// Interrupted function. + Intr, + /// Invalid argument. + Inval, + /// I/O error. + Io, + /// Socket is connected. + Isconn, + /// Is a directory. + Isdir, + /// Too many levels of symbolic links. + Loop, + /// File descriptor value too large. + Mfile, + /// Too many links. + Mlink, + /// Message too large. + Msgsize, + /// Reserved. + Multihop, + /// Filename too long. + Nametoolong, + /// Network is down. + Netdown, + /// Connection aborted by network. + Netreset, + /// Network unreachable. + Netunreach, + /// Too many files open in system. + Nfile, + /// No buffer space available. + Nobufs, + /// No such device. + Nodev, + /// No such file or directory. + Noent, + /// Executable file format error. + Noexec, + /// No locks available. + Nolck, + /// Reserved. + Nolink, + /// Not enough space. + Nomem, + /// No message of the desired type. + Nomsg, + /// Protocol not available. + Noprotoopt, + /// No space left on device. + Nospc, + /// Function not supported. + Nosys, + /// The socket is not connected. + Notconn, + /// Not a directory or a symbolic link to a directory. + Notdir, + /// Directory not empty. + Notempty, + /// State not recoverable. + Notrecoverable, + /// Not a socket. + Notsock, + /// Not supported, or operation not supported on socket. + Notsup, + /// Inappropriate I/O control operation. + Notty, + /// No such device or address. + Nxio, + /// Value too large to be stored in data type. + Overflow, + /// Previous owner died. + Ownerdead, + /// Operation not permitted. + Perm, + /// Broken pipe. + Pipe, + /// Protocol error. + Proto, + /// Protocol not supported. + Protonosupport, + /// Protocol wrong type for socket. + Prototype, + /// Result too large. + Range, + /// Read-only file system. + Rofs, + /// Invalid seek. + Spipe, + /// No such process. + Srch, + /// Reserved. + Stale, + /// Connection timed out. + Timedout, + /// Text file busy. + Txtbsy, + /// Cross-device link. + Xdev, + /// Extension: Capabilities insufficient. + Notcapable, +} +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", + } + } + 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.", + } + } +} +impl core::fmt::Debug for Errno { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Errno") + .field("code", &(*self as i32)) + .field("name", &self.name()) + .field("message", &self.message()) + .finish() + } +} +impl core::fmt::Display for Errno { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "{} (error {})", self.name(), *self as i32) + } +} + +impl std::error::Error for Errno {} +#[repr(u8)] +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum BusErrno { + /// No error occurred. Call completed successfully. + Success, + /// Failed during serialization + Ser, + /// Failed during deserialization + Des, + /// Invalid WAPM process + Wapm, + /// Failed to fetch the WAPM process + Fetch, + /// Failed to compile the WAPM process + Compile, + /// Invalid ABI + Abi, + /// Call was aborted + Aborted, + /// Bad handle + Badhandle, + /// Invalid topic + Topic, + /// Invalid callback + Badcb, + /// Call is unsupported + Unsupported, + /// Bad request + Badrequest, + /// Access denied + Denied, + /// Internal error has occured + Internal, + /// Memory allocation failed + Alloc, + /// Invocation has failed + Invoke, + /// Already consumed + Consumed, + /// Memory access violation + Memviolation, + /// Some other unhandled error. If you see this, it's probably a bug. + Unknown, +} +impl BusErrno { + pub fn name(&self) -> &'static str { + match self { + BusErrno::Success => "success", + BusErrno::Ser => "ser", + BusErrno::Des => "des", + BusErrno::Wapm => "wapm", + BusErrno::Fetch => "fetch", + BusErrno::Compile => "compile", + BusErrno::Abi => "abi", + BusErrno::Aborted => "aborted", + BusErrno::Badhandle => "badhandle", + BusErrno::Topic => "topic", + BusErrno::Badcb => "badcb", + BusErrno::Unsupported => "unsupported", + BusErrno::Badrequest => "badrequest", + BusErrno::Denied => "denied", + BusErrno::Internal => "internal", + BusErrno::Alloc => "alloc", + BusErrno::Invoke => "invoke", + BusErrno::Consumed => "consumed", + BusErrno::Memviolation => "memviolation", + BusErrno::Unknown => "unknown", + } + } + pub fn message(&self) -> &'static str { + match self { + BusErrno::Success => "No error occurred. Call completed successfully.", + BusErrno::Ser => "Failed during serialization", + BusErrno::Des => "Failed during deserialization", + BusErrno::Wapm => "Invalid WAPM process", + BusErrno::Fetch => "Failed to fetch the WAPM process", + BusErrno::Compile => "Failed to compile the WAPM process", + BusErrno::Abi => "Invalid ABI", + BusErrno::Aborted => "Call was aborted", + BusErrno::Badhandle => "Bad handle", + BusErrno::Topic => "Invalid topic", + BusErrno::Badcb => "Invalid callback", + BusErrno::Unsupported => "Call is unsupported", + BusErrno::Badrequest => "Bad request", + BusErrno::Denied => "Access denied", + BusErrno::Internal => "Internal error has occured", + BusErrno::Alloc => "Memory allocation failed", + BusErrno::Invoke => "Invocation has failed", + BusErrno::Consumed => "Already consumed", + BusErrno::Memviolation => "Memory access violation", + BusErrno::Unknown => { + "Some other unhandled error. If you see this, it's probably a bug." + } + } + } +} +impl core::fmt::Debug for BusErrno { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("BusErrno") + .field("code", &(*self as i32)) + .field("name", &self.name()) + .field("message", &self.message()) + .finish() + } +} +impl core::fmt::Display for BusErrno { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "{} (error {})", self.name(), *self as i32) + } +} + +impl std::error::Error for BusErrno {} +wit_bindgen_rust::bitflags::bitflags! { + /// File descriptor rights, determining which actions may be performed. + pub struct Rights: u64 { + /// The right to invoke `fd_datasync`. + /// + /// If `rights::path_open` is set, includes the right to invoke + /// `path_open` with `fdflags::dsync`. + const FD_DATASYNC = 1 << 0; + /// The right to invoke `fd_read` and `sock_recv`. + /// + /// If `rights::fd_seek` is set, includes the right to invoke `fd_pread`. + const FD_READ = 1 << 1; + /// The right to invoke `fd_seek`. This flag implies `rights::fd_tell`. + const FD_SEEK = 1 << 2; + /// The right to invoke `fd_fdstat_set_flags`. + const FD_FDSTAT_SET_FLAGS = 1 << 3; + /// The right to invoke `fd_sync`. + /// + /// If `rights::path_open` is set, includes the right to invoke + /// `path_open` with `fdflags::rsync` and `fdflags::dsync`. + const FD_SYNC = 1 << 4; + /// The right to invoke `fd_seek` in such a way that the file offset + /// remains unaltered (i.e., `whence::cur` with offset zero), or to + /// invoke `fd_tell`. + const FD_TELL = 1 << 5; + /// The right to invoke `fd_write` and `sock_send`. + /// If `rights::fd_seek` is set, includes the right to invoke `fd_pwrite`. + const FD_WRITE = 1 << 6; + /// The right to invoke `fd_advise`. + const FD_ADVISE = 1 << 7; + /// The right to invoke `fd_allocate`. + const FD_ALLOCATE = 1 << 8; + /// The right to invoke `path_create_directory`. + const PATH_CREATE_DIRECTORY = 1 << 9; + /// If `rights::path_open` is set, the right to invoke `path_open` with `oflags::creat`. + const PATH_CREATE_FILE = 1 << 10; + /// The right to invoke `path_link` with the file descriptor as the + /// source directory. + const PATH_LINK_SOURCE = 1 << 11; + /// The right to invoke `path_link` with the file descriptor as the + /// target directory. + const PATH_LINK_TARGET = 1 << 12; + /// The right to invoke `path_open`. + const PATH_OPEN = 1 << 13; + /// The right to invoke `fd_readdir`. + const FD_READDIR = 1 << 14; + /// The right to invoke `path_readlink`. + const PATH_READLINK = 1 << 15; + /// The right to invoke `path_rename` with the file descriptor as the source directory. + const PATH_RENAME_SOURCE = 1 << 16; + /// The right to invoke `path_rename` with the file descriptor as the target directory. + const PATH_RENAME_TARGET = 1 << 17; + /// The right to invoke `path_filestat_get`. + const PATH_FILESTAT_GET = 1 << 18; + /// The right to change a file's size (there is no `path_filestat_set_size`). + /// If `rights::path_open` is set, includes the right to invoke `path_open` with `oflags::trunc`. + const PATH_FILESTAT_SET_SIZE = 1 << 19; + /// The right to invoke `path_filestat_set_times`. + const PATH_FILESTAT_SET_TIMES = 1 << 20; + /// The right to invoke `fd_filestat_get`. + const FD_FILESTAT_GET = 1 << 21; + /// The right to invoke `fd_filestat_set_size`. + const FD_FILESTAT_SET_SIZE = 1 << 22; + /// The right to invoke `fd_filestat_set_times`. + const FD_FILESTAT_SET_TIMES = 1 << 23; + /// The right to invoke `path_symlink`. + const PATH_SYMLINK = 1 << 24; + /// The right to invoke `path_remove_directory`. + const PATH_REMOVE_DIRECTORY = 1 << 25; + /// The right to invoke `path_unlink_file`. + const PATH_UNLINK_FILE = 1 << 26; + /// If `rights::fd_read` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_read`. + /// If `rights::fd_write` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_write`. + const POLL_FD_READWRITE = 1 << 27; + /// The right to invoke `sock_shutdown`. + const SOCK_SHUTDOWN = 1 << 28; + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + const SOCK_ACCEPT = 1 << 29; + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + const SOCK_CONNECT = 1 << 30; + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + const SOCK_LISTEN = 1 << 31; + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + const SOCK_BIND = 1 << 32; + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + const SOCK_RECV = 1 << 33; + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + const SOCK_SEND = 1 << 34; + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + const SOCK_ADDR_LOCAL = 1 << 35; + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + const SOCK_ADDR_REMOTE = 1 << 36; + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + const SOCK_RECV_FROM = 1 << 37; + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + const SOCK_SEND_TO = 1 << 38; + } +} +impl Rights { + /// Convert from a raw integer, preserving any unknown bits. See + /// + pub fn from_bits_preserve(bits: u64) -> Self { + Self { bits } + } +} +/// The type of a file descriptor or file. +#[repr(u8)] +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum Filetype { + /// The type of the file descriptor or file is unknown or is different from any of the other types specified. + Unknown, + /// The file descriptor or file refers to a block device inode. + BlockDevice, + /// The file descriptor or file refers to a character device inode. + CharacterDevice, + /// The file descriptor or file refers to a directory inode. + Directory, + /// The file descriptor or file refers to a regular file inode. + RegularFile, + /// The file descriptor or file refers to a datagram socket. + SocketDgram, + /// The file descriptor or file refers to a byte-stream socket. + SocketStream, + /// The file refers to a symbolic link inode. + SymbolicLink, + /// The file descriptor or file refers to a FIFO. + Fifo, +} +impl core::fmt::Debug for Filetype { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Filetype::Unknown => f.debug_tuple("Filetype::Unknown").finish(), + Filetype::BlockDevice => f.debug_tuple("Filetype::BlockDevice").finish(), + Filetype::CharacterDevice => f.debug_tuple("Filetype::CharacterDevice").finish(), + Filetype::Directory => f.debug_tuple("Filetype::Directory").finish(), + Filetype::RegularFile => f.debug_tuple("Filetype::RegularFile").finish(), + Filetype::SocketDgram => f.debug_tuple("Filetype::SocketDgram").finish(), + Filetype::SocketStream => f.debug_tuple("Filetype::SocketStream").finish(), + Filetype::SymbolicLink => f.debug_tuple("Filetype::SymbolicLink").finish(), + Filetype::Fifo => f.debug_tuple("Filetype::Fifo").finish(), + } + } +} +/// A directory entry, snapshot0 version. +#[repr(C)] +#[derive(Copy, Clone)] +pub struct Snapshot0Dirent { + /// The offset of the next directory entry stored in this directory. + pub d_next: Dircookie, + /// The serial number of the file referred to by this directory entry. + pub d_ino: Inode, + /// The length of the name of the directory entry. + pub d_namlen: Dirnamlen, + /// The type of the file referred to by this directory entry. + pub d_type: Filetype, +} +impl core::fmt::Debug for Snapshot0Dirent { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Snapshot0Dirent") + .field("d-next", &self.d_next) + .field("d-ino", &self.d_ino) + .field("d-namlen", &self.d_namlen) + .field("d-type", &self.d_type) + .finish() + } +} +/// A directory entry. +#[repr(C)] +#[derive(Copy, Clone)] +pub struct Dirent { + /// The offset of the next directory entry stored in this directory. + pub d_next: Dircookie, + /// The serial number of the file referred to by this directory entry. + pub d_ino: Inode, + /// The type of the file referred to by this directory entry. + pub d_type: Filetype, + /// The length of the name of the directory entry. + pub d_namlen: Dirnamlen, +} +impl core::fmt::Debug for Dirent { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Dirent") + .field("d-next", &self.d_next) + .field("d-ino", &self.d_ino) + .field("d-type", &self.d_type) + .field("d-namlen", &self.d_namlen) + .finish() + } +} +/// File or memory access pattern advisory information. +#[repr(u8)] +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum Advice { + /// The application has no advice to give on its behavior with respect to the specified data. + Normal, + /// The application expects to access the specified data sequentially from lower offsets to higher offsets. + Sequential, + /// The application expects to access the specified data in a random order. + Random, + /// The application expects to access the specified data in the near future. + Willneed, + /// The application expects that it will not access the specified data in the near future. + Dontneed, + /// The application expects to access the specified data once and then not reuse it thereafter. + Noreuse, +} +impl core::fmt::Debug for Advice { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Advice::Normal => f.debug_tuple("Advice::Normal").finish(), + Advice::Sequential => f.debug_tuple("Advice::Sequential").finish(), + Advice::Random => f.debug_tuple("Advice::Random").finish(), + Advice::Willneed => f.debug_tuple("Advice::Willneed").finish(), + Advice::Dontneed => f.debug_tuple("Advice::Dontneed").finish(), + Advice::Noreuse => f.debug_tuple("Advice::Noreuse").finish(), + } + } +} +wit_bindgen_rust::bitflags::bitflags! { + /// File descriptor flags. + pub struct Fdflags: u16 { + /// Append mode: Data written to the file is always appended to the file's end. + const APPEND = 1 << 0; + /// Write according to synchronized I/O data integrity completion. Only the data stored in the file is synchronized. + const DSYNC = 1 << 1; + /// Non-blocking mode. + const NONBLOCK = 1 << 2; + /// Synchronized read I/O operations. + const RSYNC = 1 << 3; + /// Write according to synchronized I/O file integrity completion. In + /// addition to synchronizing the data stored in the file, the implementation + /// may also synchronously update the file's metadata. + const SYNC = 1 << 4; + } +} +impl Fdflags { + /// Convert from a raw integer, preserving any unknown bits. See + /// + pub fn from_bits_preserve(bits: u16) -> Self { + Self { bits } + } +} +/// File descriptor attributes. +#[repr(C)] +#[derive(Copy, Clone)] +pub struct Fdstat { + /// File type. + pub fs_filetype: Filetype, + /// File descriptor flags. + pub fs_flags: Fdflags, + /// Rights that apply to this file descriptor. + pub fs_rights_base: Rights, + /// Maximum set of rights that may be installed on new file descriptors that + /// are created through this file descriptor, e.g., through `path_open`. + pub fs_rights_inheriting: Rights, +} +impl core::fmt::Debug for Fdstat { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Fdstat") + .field("fs-filetype", &self.fs_filetype) + .field("fs-flags", &self.fs_flags) + .field("fs-rights-base", &self.fs_rights_base) + .field("fs-rights-inheriting", &self.fs_rights_inheriting) + .finish() + } +} +wit_bindgen_rust::bitflags::bitflags! { + /// Which file time attributes to adjust. + /// TODO: wit appears to not have support for flags repr + /// (@witx repr u16) + pub struct Fstflags: u16 { + /// Adjust the last data access timestamp to the value stored in `filestat::atim`. + const SET_ATIM = 1 << 0; + /// Adjust the last data access timestamp to the time of clock `clockid::realtime`. + const SET_ATIM_NOW = 1 << 1; + /// Adjust the last data modification timestamp to the value stored in `filestat::mtim`. + const SET_MTIM = 1 << 2; + /// Adjust the last data modification timestamp to the time of clock `clockid::realtime`. + const SET_MTIM_NOW = 1 << 3; + } +} +impl Fstflags { + /// Convert from a raw integer, preserving any unknown bits. See + /// + pub fn from_bits_preserve(bits: u16) -> Self { + Self { bits } + } +} +wit_bindgen_rust::bitflags::bitflags! { + /// Flags determining the method of how paths are resolved. + /// TODO: wit appears to not have support for flags repr + /// (@witx repr u32) + pub struct Lookup: u32 { + /// As long as the resolved path corresponds to a symbolic link, it is expanded. + const SYMLINK_FOLLOW = 1 << 0; + } +} +impl Lookup { + /// Convert from a raw integer, preserving any unknown bits. See + /// + pub fn from_bits_preserve(bits: u32) -> Self { + Self { bits } + } +} +wit_bindgen_rust::bitflags::bitflags! { + /// Open flags used by `path_open`. + /// TODO: wit appears to not have support for flags repr + /// (@witx repr u16) + pub struct Oflags: u16 { + /// Create file if it does not exist. + const CREATE = 1 << 0; + /// Fail if not a directory. + const DIRECTORY = 1 << 1; + /// Fail if file already exists. + const EXCL = 1 << 2; + /// Truncate file to size 0. + const TRUNC = 1 << 3; + } +} +impl Oflags { + /// Convert from a raw integer, preserving any unknown bits. See + /// + pub fn from_bits_preserve(bits: u16) -> Self { + Self { bits } + } +} +/// User-provided value that may be attached to objects that is retained when +/// extracted from the implementation. +pub type Userdata = u64; +/// Type of a subscription to an event or its occurrence. +#[repr(u8)] +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum Eventtype { + /// The time value of clock `subscription_clock::id` has + /// reached timestamp `subscription_clock::timeout`. + Clock, + /// File descriptor `subscription_fd_readwrite::fd` has data + /// available for reading. This event always triggers for regular files. + FdRead, + /// File descriptor `subscription_fd_readwrite::fd` has capacity + /// available for writing. This event always triggers for regular files. + FdWrite, +} +impl core::fmt::Debug for Eventtype { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Eventtype::Clock => f.debug_tuple("Eventtype::Clock").finish(), + Eventtype::FdRead => f.debug_tuple("Eventtype::FdRead").finish(), + Eventtype::FdWrite => f.debug_tuple("Eventtype::FdWrite").finish(), + } + } +} +wit_bindgen_rust::bitflags::bitflags! { + /// Flags determining how to interpret the timestamp provided in + /// `subscription-clock::timeout`. + pub struct Subclockflags: u16 { + /// If set, treat the timestamp provided in + /// `subscription-clock::timeout` as an absolute timestamp of clock + /// `subscription-clock::id`. If clear, treat the timestamp + /// provided in `subscription-clock::timeout` relative to the + /// current time value of clock `subscription-clock::id`. + const SUBSCRIPTION_CLOCK_ABSTIME = 1 << 0; + } +} +impl Subclockflags { + /// Convert from a raw integer, preserving any unknown bits. See + /// + pub fn from_bits_preserve(bits: u16) -> Self { + Self { bits } + } +} +/// The contents of a `subscription` when type is `eventtype::clock`. +#[repr(C)] +#[derive(Copy, Clone)] +pub struct Snapshot0SubscriptionClock { + /// The user-defined unique identifier of the clock. + pub identifier: Userdata, + /// The clock against which to compare the timestamp. + pub id: Snapshot0Clockid, + /// The absolute or relative timestamp. + pub timeout: Timestamp, + /// The amount of time that the implementation may wait additionally + /// to coalesce with other events. + pub precision: Timestamp, + /// Flags specifying whether the timeout is absolute or relative + pub flags: Subclockflags, +} +impl core::fmt::Debug for Snapshot0SubscriptionClock { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Snapshot0SubscriptionClock") + .field("identifier", &self.identifier) + .field("id", &self.id) + .field("timeout", &self.timeout) + .field("precision", &self.precision) + .field("flags", &self.flags) + .finish() + } +} +/// The contents of a `subscription` when type is `eventtype::clock`. +#[repr(C)] +#[derive(Copy, Clone)] +pub struct SubscriptionClock { + /// The clock against which to compare the timestamp. + pub clock_id: Clockid, + /// The absolute or relative timestamp. + pub timeout: Timestamp, + /// The amount of time that the implementation may wait additionally + /// to coalesce with other events. + pub precision: Timestamp, + /// Flags specifying whether the timeout is absolute or relative + pub flags: Subclockflags, +} +impl core::fmt::Debug for SubscriptionClock { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("SubscriptionClock") + .field("clock-id", &self.clock_id) + .field("timeout", &self.timeout) + .field("precision", &self.precision) + .field("flags", &self.flags) + .finish() + } +} +/// Identifiers for preopened capabilities. +#[repr(u8)] +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum Preopentype { + /// A pre-opened directory. + Dir, +} +impl core::fmt::Debug for Preopentype { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Preopentype::Dir => f.debug_tuple("Preopentype::Dir").finish(), + } + } +} +wit_bindgen_rust::bitflags::bitflags! { + /// The state of the file descriptor subscribed to with + /// `eventtype::fd_read` or `eventtype::fd_write`. + pub struct Eventrwflags: u16 { + /// The peer of this socket has closed or disconnected. + const FD_READWRITE_HANGUP = 1 << 0; + } +} +impl Eventrwflags { + /// Convert from a raw integer, preserving any unknown bits. See + /// + pub fn from_bits_preserve(bits: u16) -> Self { + Self { bits } + } +} +/// The contents of an `event` for the `eventtype::fd_read` and +/// `eventtype::fd_write` variants +#[repr(C)] +#[derive(Copy, Clone)] +pub struct EventFdReadwrite { + /// The number of bytes available for reading or writing. + pub nbytes: Filesize, + /// The state of the file descriptor. + pub flags: Eventrwflags, +} +impl core::fmt::Debug for EventFdReadwrite { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("EventFdReadwrite") + .field("nbytes", &self.nbytes) + .field("flags", &self.flags) + .finish() + } +} +/// An event that occurred. +#[repr(C)] +#[derive(Copy, Clone)] +pub struct Event { + /// User-provided value that got attached to `subscription::userdata`. + pub userdata: Userdata, + /// If non-zero, an error that occurred while processing the subscription request. + pub error: Errno, + /// The type of the event that occurred, and the contents of the event + pub data: EventEnum, +} +impl core::fmt::Debug for Event { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Event") + .field("userdata", &self.userdata) + .field("error", &self.error) + .field("data", &self.data) + .finish() + } +} +/// The contents of an `event`. +#[derive(Clone, Copy)] +pub enum EventEnum { + FdRead(EventFdReadwrite), + FdWrite(EventFdReadwrite), + Clock, +} +impl core::fmt::Debug for EventEnum { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + EventEnum::FdRead(e) => f.debug_tuple("EventEnum::FdRead").field(e).finish(), + EventEnum::FdWrite(e) => f.debug_tuple("EventEnum::FdWrite").field(e).finish(), + EventEnum::Clock => f.debug_tuple("EventEnum::Clock").finish(), + } + } +} +/// An event that occurred. +#[repr(C)] +#[derive(Copy, Clone)] +pub struct Snapshot0Event { + /// User-provided value that got attached to `subscription::userdata`. + pub userdata: Userdata, + /// If non-zero, an error that occurred while processing the subscription request. + pub error: Errno, + /// The type of event that occured + pub type_: Eventtype, + /// The contents of the event, if it is an `eventtype::fd_read` or + /// `eventtype::fd_write`. `eventtype::clock` events ignore this field. + pub fd_readwrite: EventFdReadwrite, +} +impl core::fmt::Debug for Snapshot0Event { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Snapshot0Event") + .field("userdata", &self.userdata) + .field("error", &self.error) + .field("type", &self.type_) + .field("fd-readwrite", &self.fd_readwrite) + .finish() + } +} +/// The contents of a `subscription`, snapshot0 version. +#[derive(Clone, Copy)] +pub enum Snapshot0SubscriptionEnum { + Clock(Snapshot0SubscriptionClock), + Read(SubscriptionFsReadwrite), + Write(SubscriptionFsReadwrite), +} +impl core::fmt::Debug for Snapshot0SubscriptionEnum { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Snapshot0SubscriptionEnum::Clock(e) => f + .debug_tuple("Snapshot0SubscriptionEnum::Clock") + .field(e) + .finish(), + Snapshot0SubscriptionEnum::Read(e) => f + .debug_tuple("Snapshot0SubscriptionEnum::Read") + .field(e) + .finish(), + Snapshot0SubscriptionEnum::Write(e) => f + .debug_tuple("Snapshot0SubscriptionEnum::Write") + .field(e) + .finish(), + } + } +} +/// The contents of a `subscription`. +#[derive(Clone, Copy)] +pub enum SubscriptionEnum { + Clock(SubscriptionClock), + Read(SubscriptionFsReadwrite), + Write(SubscriptionFsReadwrite), +} +impl core::fmt::Debug for SubscriptionEnum { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + SubscriptionEnum::Clock(e) => { + f.debug_tuple("SubscriptionEnum::Clock").field(e).finish() + } + SubscriptionEnum::Read(e) => f.debug_tuple("SubscriptionEnum::Read").field(e).finish(), + SubscriptionEnum::Write(e) => { + f.debug_tuple("SubscriptionEnum::Write").field(e).finish() + } + } + } +} +/// The contents of a `subscription` when the variant is +/// `eventtype::fd_read` or `eventtype::fd_write`. +#[repr(C)] +#[derive(Copy, Clone)] +pub struct SubscriptionFsReadwrite { + /// The file descriptor on which to wait for it to become ready for reading or writing. + pub file_descriptor: Fd, +} +impl core::fmt::Debug for SubscriptionFsReadwrite { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("SubscriptionFsReadwrite") + .field("file-descriptor", &self.file_descriptor) + .finish() + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct Snapshot0Subscription { + pub userdata: Userdata, + pub data: Snapshot0SubscriptionEnum, +} +impl core::fmt::Debug for Snapshot0Subscription { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Snapshot0Subscription") + .field("userdata", &self.userdata) + .field("data", &self.data) + .finish() + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct Subscription { + pub userdata: Userdata, + pub data: SubscriptionEnum, +} +impl core::fmt::Debug for Subscription { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Subscription") + .field("userdata", &self.userdata) + .field("data", &self.data) + .finish() + } +} +#[repr(u8)] +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum Socktype { + Dgram, + Stream, + Raw, + Seqpacket, +} +impl core::fmt::Debug for Socktype { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Socktype::Dgram => f.debug_tuple("Socktype::Dgram").finish(), + Socktype::Stream => f.debug_tuple("Socktype::Stream").finish(), + Socktype::Raw => f.debug_tuple("Socktype::Raw").finish(), + Socktype::Seqpacket => f.debug_tuple("Socktype::Seqpacket").finish(), + } + } +} +#[repr(u8)] +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum Sockstatus { + Opening, + Opened, + Closed, + Failed, +} +impl core::fmt::Debug for Sockstatus { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Sockstatus::Opening => f.debug_tuple("Sockstatus::Opening").finish(), + Sockstatus::Opened => f.debug_tuple("Sockstatus::Opened").finish(), + Sockstatus::Closed => f.debug_tuple("Sockstatus::Closed").finish(), + Sockstatus::Failed => f.debug_tuple("Sockstatus::Failed").finish(), + } + } +} +#[repr(u8)] +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum Sockoption { + Noop, + ReusePort, + ReuseAddr, + NoDelay, + DontRoute, + OnlyV6, + Broadcast, + MulticastLoopV4, + MulticastLoopV6, + Promiscuous, + Listening, + LastError, + KeepAlive, + Linger, + OobInline, + RecvBufSize, + SendBufSize, + RecvLowat, + SendLowat, + RecvTimeout, + SendTimeout, + ConnectTimeout, + AcceptTimeout, + Ttl, + MulticastTtlV4, + Type, + Proto, +} +impl core::fmt::Debug for Sockoption { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Sockoption::Noop => f.debug_tuple("Sockoption::Noop").finish(), + Sockoption::ReusePort => f.debug_tuple("Sockoption::ReusePort").finish(), + Sockoption::ReuseAddr => f.debug_tuple("Sockoption::ReuseAddr").finish(), + Sockoption::NoDelay => f.debug_tuple("Sockoption::NoDelay").finish(), + Sockoption::DontRoute => f.debug_tuple("Sockoption::DontRoute").finish(), + Sockoption::OnlyV6 => f.debug_tuple("Sockoption::OnlyV6").finish(), + Sockoption::Broadcast => f.debug_tuple("Sockoption::Broadcast").finish(), + Sockoption::MulticastLoopV4 => f.debug_tuple("Sockoption::MulticastLoopV4").finish(), + Sockoption::MulticastLoopV6 => f.debug_tuple("Sockoption::MulticastLoopV6").finish(), + Sockoption::Promiscuous => f.debug_tuple("Sockoption::Promiscuous").finish(), + Sockoption::Listening => f.debug_tuple("Sockoption::Listening").finish(), + Sockoption::LastError => f.debug_tuple("Sockoption::LastError").finish(), + Sockoption::KeepAlive => f.debug_tuple("Sockoption::KeepAlive").finish(), + Sockoption::Linger => f.debug_tuple("Sockoption::Linger").finish(), + Sockoption::OobInline => f.debug_tuple("Sockoption::OobInline").finish(), + Sockoption::RecvBufSize => f.debug_tuple("Sockoption::RecvBufSize").finish(), + Sockoption::SendBufSize => f.debug_tuple("Sockoption::SendBufSize").finish(), + Sockoption::RecvLowat => f.debug_tuple("Sockoption::RecvLowat").finish(), + Sockoption::SendLowat => f.debug_tuple("Sockoption::SendLowat").finish(), + Sockoption::RecvTimeout => f.debug_tuple("Sockoption::RecvTimeout").finish(), + Sockoption::SendTimeout => f.debug_tuple("Sockoption::SendTimeout").finish(), + Sockoption::ConnectTimeout => f.debug_tuple("Sockoption::ConnectTimeout").finish(), + Sockoption::AcceptTimeout => f.debug_tuple("Sockoption::AcceptTimeout").finish(), + Sockoption::Ttl => f.debug_tuple("Sockoption::Ttl").finish(), + Sockoption::MulticastTtlV4 => f.debug_tuple("Sockoption::MulticastTtlV4").finish(), + Sockoption::Type => f.debug_tuple("Sockoption::Type").finish(), + Sockoption::Proto => f.debug_tuple("Sockoption::Proto").finish(), + } + } +} +#[repr(u8)] +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum Streamsecurity { + Unencrypted, + AnyEncryption, + ClassicEncryption, + DoubleEncryption, +} +impl core::fmt::Debug for Streamsecurity { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Streamsecurity::Unencrypted => f.debug_tuple("Streamsecurity::Unencrypted").finish(), + Streamsecurity::AnyEncryption => { + f.debug_tuple("Streamsecurity::AnyEncryption").finish() + } + Streamsecurity::ClassicEncryption => { + f.debug_tuple("Streamsecurity::ClassicEncryption").finish() + } + Streamsecurity::DoubleEncryption => { + f.debug_tuple("Streamsecurity::DoubleEncryption").finish() + } + } + } +} +#[repr(u8)] +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum Addressfamily { + Unspec, + Inet4, + Inet6, + Unix, +} +impl core::fmt::Debug for Addressfamily { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Addressfamily::Unspec => f.debug_tuple("Addressfamily::Unspec").finish(), + Addressfamily::Inet4 => f.debug_tuple("Addressfamily::Inet4").finish(), + Addressfamily::Inet6 => f.debug_tuple("Addressfamily::Inet6").finish(), + Addressfamily::Unix => f.debug_tuple("Addressfamily::Unix").finish(), + } + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct Snapshot0Filestat { + pub st_dev: Device, + pub st_ino: Inode, + pub st_filetype: Filetype, + pub st_nlink: Snapshot0Linkcount, + pub st_size: Filesize, + pub st_atim: Timestamp, + pub st_mtim: Timestamp, + pub st_ctim: Timestamp, +} +impl core::fmt::Debug for Snapshot0Filestat { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Snapshot0Filestat") + .field("st-dev", &self.st_dev) + .field("st-ino", &self.st_ino) + .field("st-filetype", &self.st_filetype) + .field("st-nlink", &self.st_nlink) + .field("st-size", &self.st_size) + .field("st-atim", &self.st_atim) + .field("st-mtim", &self.st_mtim) + .field("st-ctim", &self.st_ctim) + .finish() + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct Filestat { + pub st_dev: Device, + pub st_ino: Inode, + pub st_filetype: Filetype, + pub st_nlink: Linkcount, + pub st_size: Filesize, + pub st_atim: Timestamp, + pub st_mtim: Timestamp, + pub st_ctim: Timestamp, +} +impl core::fmt::Debug for Filestat { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Filestat") + .field("st-dev", &self.st_dev) + .field("st-ino", &self.st_ino) + .field("st-filetype", &self.st_filetype) + .field("st-nlink", &self.st_nlink) + .field("st-size", &self.st_size) + .field("st-atim", &self.st_atim) + .field("st-mtim", &self.st_mtim) + .field("st-ctim", &self.st_ctim) + .finish() + } +} +#[repr(u8)] +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum Snapshot0Whence { + Cur, + End, + Set, +} +impl core::fmt::Debug for Snapshot0Whence { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Snapshot0Whence::Cur => f.debug_tuple("Snapshot0Whence::Cur").finish(), + Snapshot0Whence::End => f.debug_tuple("Snapshot0Whence::End").finish(), + Snapshot0Whence::Set => f.debug_tuple("Snapshot0Whence::Set").finish(), + } + } +} +#[repr(u8)] +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum Whence { + Set, + Cur, + End, +} +impl core::fmt::Debug for Whence { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Whence::Set => f.debug_tuple("Whence::Set").finish(), + Whence::Cur => f.debug_tuple("Whence::Cur").finish(), + Whence::End => f.debug_tuple("Whence::End").finish(), + } + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct Tty { + pub cols: u32, + pub rows: u32, + pub width: u32, + pub height: u32, + pub stdin_tty: bool, + pub stdout_tty: bool, + pub stderr_tty: bool, + pub echo: bool, + pub line_buffered: bool, +} +impl core::fmt::Debug for Tty { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Tty") + .field("cols", &self.cols) + .field("rows", &self.rows) + .field("width", &self.width) + .field("height", &self.height) + .field("stdin-tty", &self.stdin_tty) + .field("stdout-tty", &self.stdout_tty) + .field("stderr-tty", &self.stderr_tty) + .field("echo", &self.echo) + .field("line-buffered", &self.line_buffered) + .finish() + } +} +#[repr(u8)] +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum BusDataFormat { + Raw, + Bincode, + MessagePack, + Json, + Yaml, + Xml, + Rkyv, +} +impl core::fmt::Debug for BusDataFormat { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + BusDataFormat::Raw => f.debug_tuple("BusDataFormat::Raw").finish(), + BusDataFormat::Bincode => f.debug_tuple("BusDataFormat::Bincode").finish(), + BusDataFormat::MessagePack => f.debug_tuple("BusDataFormat::MessagePack").finish(), + BusDataFormat::Json => f.debug_tuple("BusDataFormat::Json").finish(), + BusDataFormat::Yaml => f.debug_tuple("BusDataFormat::Yaml").finish(), + BusDataFormat::Xml => f.debug_tuple("BusDataFormat::Xml").finish(), + BusDataFormat::Rkyv => f.debug_tuple("BusDataFormat::Rkyv").finish(), + } + } +} +#[repr(u8)] +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum BusEventType { + Noop, + Exit, + Call, + Result, + Fault, + Close, +} +impl core::fmt::Debug for BusEventType { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + BusEventType::Noop => f.debug_tuple("BusEventType::Noop").finish(), + BusEventType::Exit => f.debug_tuple("BusEventType::Exit").finish(), + BusEventType::Call => f.debug_tuple("BusEventType::Call").finish(), + BusEventType::Result => f.debug_tuple("BusEventType::Result").finish(), + BusEventType::Fault => f.debug_tuple("BusEventType::Fault").finish(), + BusEventType::Close => f.debug_tuple("BusEventType::Close").finish(), + } + } +} +pub type Bid = u32; +pub type Cid = u32; +/// __wasi_option_t +#[repr(u8)] +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum OptionTag { + None, + Some, +} +impl core::fmt::Debug for OptionTag { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + OptionTag::None => f.debug_tuple("OptionTag::None").finish(), + OptionTag::Some => f.debug_tuple("OptionTag::Some").finish(), + } + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct OptionBid { + pub tag: OptionTag, + pub bid: Bid, +} +impl core::fmt::Debug for OptionBid { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("OptionBid") + .field("tag", &self.tag) + .field("bid", &self.bid) + .finish() + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct OptionCid { + pub tag: OptionTag, + pub cid: Cid, +} +impl core::fmt::Debug for OptionCid { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("OptionCid") + .field("tag", &self.tag) + .field("cid", &self.cid) + .finish() + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct OptionFd { + pub tag: OptionTag, + pub fd: Fd, +} +impl core::fmt::Debug for OptionFd { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("OptionFd") + .field("tag", &self.tag) + .field("fd", &self.fd) + .finish() + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct BusHandles { + pub bid: Bid, + pub stdin: OptionFd, + pub stdout: OptionFd, + pub stderr: OptionFd, +} +impl core::fmt::Debug for BusHandles { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("BusHandles") + .field("bid", &self.bid) + .field("stdin", &self.stdin) + .field("stdout", &self.stdout) + .field("stderr", &self.stderr) + .finish() + } +} +pub type ExitCode = u32; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct BusEventExit { + pub bid: Bid, + pub rval: ExitCode, +} +impl core::fmt::Debug for BusEventExit { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("BusEventExit") + .field("bid", &self.bid) + .field("rval", &self.rval) + .finish() + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct BusEventFault { + pub cid: Cid, + pub err: BusErrno, +} +impl core::fmt::Debug for BusEventFault { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("BusEventFault") + .field("cid", &self.cid) + .field("err", &self.err) + .finish() + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct BusEventClose { + pub cid: Cid, +} +impl core::fmt::Debug for BusEventClose { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("BusEventClose") + .field("cid", &self.cid) + .finish() + } +} +pub type EventFdFlags = u16; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct PrestatUDir { + pub pr_name_len: u32, +} +impl core::fmt::Debug for PrestatUDir { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("PrestatUDir") + .field("pr-name-len", &self.pr_name_len) + .finish() + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct PrestatU { + pub dir: PrestatUDir, +} +impl core::fmt::Debug for PrestatU { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("PrestatU").field("dir", &self.dir).finish() + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct Prestat { + pub pr_type: Preopentype, + pub u: PrestatU, +} +impl core::fmt::Debug for Prestat { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Prestat") + .field("pr-type", &self.pr_type) + .field("u", &self.u) + .finish() + } +} +pub type FileDelta = i64; +pub type LookupFlags = u32; +pub type Count = u32; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct PipeHandles { + pub pipe: Fd, + pub other: Fd, +} +impl core::fmt::Debug for PipeHandles { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("PipeHandles") + .field("pipe", &self.pipe) + .field("other", &self.other) + .finish() + } +} +#[repr(u8)] +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum StdioMode { + Reserved, + Piped, + Inherit, + Null, + Log, +} +impl core::fmt::Debug for StdioMode { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + StdioMode::Reserved => f.debug_tuple("StdioMode::Reserved").finish(), + StdioMode::Piped => f.debug_tuple("StdioMode::Piped").finish(), + StdioMode::Inherit => f.debug_tuple("StdioMode::Inherit").finish(), + StdioMode::Null => f.debug_tuple("StdioMode::Null").finish(), + StdioMode::Log => f.debug_tuple("StdioMode::Log").finish(), + } + } +} +#[repr(u16)] +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum SockProto { + Ip, + Icmp, + Igmp, + ProtoThree, + Ipip, + ProtoFive, + Tcp, + ProtoSeven, + Egp, + ProtoNine, + ProtoTen, + ProtoEleven, + Pup, + ProtoThirteen, + ProtoFourteen, + ProtoFifteen, + ProtoSixteen, + Udp, + ProtoEighteen, + ProtoNineteen, + ProtoTwenty, + ProtoTwentyone, + Idp, + ProtoTwentythree, + ProtoTwentyfour, + ProtoTwentyfive, + ProtoTwentysix, + ProtoTwentyseven, + ProtoTwentyeight, + ProtoTp, + ProtoThirty, + ProtoThirtyone, + ProtoThirtytwo, + Dccp, + ProtoThirtyfour, + ProtoThirtyfive, + ProtoThirtysix, + ProtoThirtyseven, + ProtoThirtyeight, + ProtoThirtynine, + ProtoFourty, + Ipv6, + ProtoFourtytwo, + Routing, + Fragment, + ProtoFourtyfive, + Rsvp, + Gre, + ProtoFourtyeight, + ProtoFourtynine, + Esp, + Ah, + ProtoFiftytwo, + ProtoFiftythree, + ProtoFiftyfour, + ProtoFiftyfive, + ProtoFiftysix, + ProtoFiftyseven, + Icmpv6, + None, + Dstopts, + ProtoSixtyone, + ProtoSixtytwo, + ProtoSixtythree, + ProtoSixtyfour, + ProtoSixtyfive, + ProtoSixtysix, + ProtoSixtyseven, + ProtoSixtyeight, + ProtoSixtynine, + ProtoSeventy, + ProtoSeventyone, + ProtoSeventytwo, + ProtoSeventythree, + ProtoSeventyfour, + ProtoSeventyfive, + ProtoSeventysix, + ProtoSeventyseven, + ProtoSeventyeight, + ProtoSeventynine, + ProtoEighty, + ProtoEightyone, + ProtoEightytwo, + ProtoEightythree, + ProtoEightyfour, + ProtoEightyfive, + ProtoEightysix, + ProtoEightyseven, + ProtoEightyeight, + ProtoEightynine, + ProtoNinety, + ProtoNinetyone, + Mtp, + ProtoNinetythree, + Beetph, + ProtoNinetyfive, + ProtoNinetysix, + ProtoNineetyseven, + Encap, + ProtoNinetynine, + ProtoOnehundred, + ProtoOnehundredandone, + ProtoOnehundredandtwo, + Pim, + ProtoOnehundredandfour, + ProtoOnehundredandfive, + ProtoOnehundredandsix, + ProtoOnehundredandseven, + Comp, + ProtoOnehundredandnine, + ProtoOnehundredandten, + ProtoOnehundredandeleven, + ProtoOnehundredandtwelve, + ProtoOnehundredandthirteen, + ProtoOnehundredandfourteen, + ProtoOnehundredandfifteen, + ProtoOnehundredandsixteen, + ProtoOnehundredandseventeen, + ProtoOnehundredandeighteen, + ProtoOnehundredandnineteen, + ProtoOnehundredandtwenty, + ProtoOnehundredandtwentyone, + ProtoOnehundredandtwentytwo, + ProtoOnehundredandtwentythree, + ProtoOnehundredandtwentyfour, + ProtoOnehundredandtwentyfive, + ProtoOnehundredandtwentysix, + ProtoOnehundredandtwentyseven, + ProtoOnehundredandtwentyeight, + ProtoOnehundredandtwentynine, + ProtoOnehundredandthirty, + ProtoOnehundredandthirtyone, + Sctp, + ProtoOnehundredandthirtythree, + ProtoOnehundredandthirtyfour, + Mh, + Udplite, + Mpls, + ProtoOnehundredandthirtyeight, + ProtoOnehundredandthirtynine, + ProtoOnehundredandfourty, + ProtoOnehundredandfourtyone, + ProtoOnehundredandfourtytwo, + Ethernet, + ProtoOnehundredandfourtyfour, + ProtoOnehundredandfourtyfive, + ProtoOnehundredandfourtysix, + ProtoOnehundredandfourtyseven, + ProtoOnehundredandfourtyeight, + ProtoOnehundredandfourtynine, + ProtoOnehundredandfifty, + ProtoOnehundredandfiftyone, + ProtoOnehundredandfiftytwo, + ProtoOnehundredandfiftythree, + ProtoOnehundredandfiftyfour, + ProtoOnehundredandfiftyfive, + ProtoOnehundredandfiftysix, + ProtoOnehundredandfiftyseven, + ProtoOnehundredandfiftyeight, + ProtoOnehundredandfiftynine, + ProtoOnehundredandsixty, + ProtoOnehundredandsixtyone, + ProtoOnehundredandsixtytwo, + ProtoOnehundredandsixtythree, + ProtoOnehundredandsixtyfour, + ProtoOnehundredandsixtyfive, + ProtoOnehundredandsixtysix, + ProtoOnehundredandsixtyseven, + ProtoOnehundredandsixtyeight, + ProtoOnehundredandsixtynine, + ProtoOnehundredandseventy, + ProtoOnehundredandseventyone, + ProtoOnehundredandseventytwo, + ProtoOnehundredandseventythree, + ProtoOnehundredandseventyfour, + ProtoOnehundredandseventyfive, + ProtoOnehundredandseventysix, + ProtoOnehundredandseventyseven, + ProtoOnehundredandseventyeight, + ProtoOnehundredandseventynine, + ProtoOnehundredandeighty, + ProtoOnehundredandeightyone, + ProtoOnehundredandeightytwo, + ProtoOnehundredandeightythree, + ProtoOnehundredandeightyfour, + ProtoOnehundredandeightyfive, + ProtoOnehundredandeightysix, + ProtoOnehundredandeightyseven, + ProtoOnehundredandeightyeight, + ProtoOnehundredandeightynine, + ProtoOnehundredandninety, + ProtoOnehundredandninetyone, + ProtoOnehundredandninetytwo, + ProtoOnehundredandninetythree, + ProtoOnehundredandninetyfour, + ProtoOnehundredandninetyfive, + ProtoOnehundredandninetysix, + ProtoOnehundredandninetyseven, + ProtoOnehundredandninetyeight, + ProtoOnehundredandninetynine, + ProtoTwohundred, + ProtoTwohundredandone, + ProtoTwohundredandtwo, + ProtoTwohundredandthree, + ProtoTwohundredandfour, + ProtoTwohundredandfive, + ProtoTwohundredandsix, + ProtoTwohundredandseven, + ProtoTwohundredandeight, + ProtoTwohundredandnine, + ProtoTwohundredandten, + ProtoTwohundredandeleven, + ProtoTwohundredandtwelve, + ProtoTwohundredandthirteen, + ProtoTwohundredandfourteen, + ProtoTwohundredandfifteen, + ProtoTwohundredandsixteen, + ProtoTwohundredandseventeen, + ProtoTwohundredandeighteen, + ProtoTwohundredandnineteen, + ProtoTwohundredandtwenty, + ProtoTwohundredandtwentyone, + ProtoTwohundredandtwentytwo, + ProtoTwohundredandtwentythree, + ProtoTwohundredandtwentyfour, + ProtoTwohundredandtwentyfive, + ProtoTwohundredandtwentysix, + ProtoTwohundredandtwentyseven, + ProtoTwohundredandtwentyeight, + ProtoTwohundredandtwentynine, + ProtoTwohundredandthirty, + ProtoTwohundredandthirtyone, + ProtoTwohundredandthirtytwo, + ProtoTwohundredandthirtythree, + ProtoTwohundredandthirtyfour, + ProtoTwohundredandthirtyfive, + ProtoTwohundredandthirtysix, + ProtoTwohundredandthirtyseven, + ProtoTwohundredandthirtyeight, + ProtoTwohundredandthirtynine, + ProtoTwohundredandfourty, + ProtoTwohundredandfourtyone, + ProtoTwohundredandfourtytwo, + ProtoTwohundredandfourtythree, + ProtoTwohundredandfourtyfour, + ProtoTwohundredandfourtyfive, + ProtoTwohundredandfourtysix, + ProtoTwohundredandfourtyseven, + ProtoTwohundredandfourtyeight, + ProtoTwohundredandfourtynine, + ProtoTwohundredandfifty, + ProtoTwohundredandfiftyone, + ProtoTwohundredandfiftytwo, + ProtoTwohundredandfiftythree, + ProtoTwohundredandfiftyfour, + ProtoRaw, + ProtoTwohundredandfiftysix, + ProtoTwohundredandfiftyseven, + ProtoTwohundredandfiftyeight, + ProtoTwohundredandfiftynine, + ProtoTwohundredandsixty, + ProtoTwohundredandsixtyone, + Mptcp, + Max, +} +impl core::fmt::Debug for SockProto { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + SockProto::Ip => f.debug_tuple("SockProto::Ip").finish(), + SockProto::Icmp => f.debug_tuple("SockProto::Icmp").finish(), + SockProto::Igmp => f.debug_tuple("SockProto::Igmp").finish(), + SockProto::ProtoThree => f.debug_tuple("SockProto::ProtoThree").finish(), + SockProto::Ipip => f.debug_tuple("SockProto::Ipip").finish(), + SockProto::ProtoFive => f.debug_tuple("SockProto::ProtoFive").finish(), + SockProto::Tcp => f.debug_tuple("SockProto::Tcp").finish(), + SockProto::ProtoSeven => f.debug_tuple("SockProto::ProtoSeven").finish(), + SockProto::Egp => f.debug_tuple("SockProto::Egp").finish(), + SockProto::ProtoNine => f.debug_tuple("SockProto::ProtoNine").finish(), + SockProto::ProtoTen => f.debug_tuple("SockProto::ProtoTen").finish(), + SockProto::ProtoEleven => f.debug_tuple("SockProto::ProtoEleven").finish(), + SockProto::Pup => f.debug_tuple("SockProto::Pup").finish(), + SockProto::ProtoThirteen => f.debug_tuple("SockProto::ProtoThirteen").finish(), + SockProto::ProtoFourteen => f.debug_tuple("SockProto::ProtoFourteen").finish(), + SockProto::ProtoFifteen => f.debug_tuple("SockProto::ProtoFifteen").finish(), + SockProto::ProtoSixteen => f.debug_tuple("SockProto::ProtoSixteen").finish(), + SockProto::Udp => f.debug_tuple("SockProto::Udp").finish(), + SockProto::ProtoEighteen => f.debug_tuple("SockProto::ProtoEighteen").finish(), + SockProto::ProtoNineteen => f.debug_tuple("SockProto::ProtoNineteen").finish(), + SockProto::ProtoTwenty => f.debug_tuple("SockProto::ProtoTwenty").finish(), + SockProto::ProtoTwentyone => f.debug_tuple("SockProto::ProtoTwentyone").finish(), + SockProto::Idp => f.debug_tuple("SockProto::Idp").finish(), + SockProto::ProtoTwentythree => f.debug_tuple("SockProto::ProtoTwentythree").finish(), + SockProto::ProtoTwentyfour => f.debug_tuple("SockProto::ProtoTwentyfour").finish(), + SockProto::ProtoTwentyfive => f.debug_tuple("SockProto::ProtoTwentyfive").finish(), + SockProto::ProtoTwentysix => f.debug_tuple("SockProto::ProtoTwentysix").finish(), + SockProto::ProtoTwentyseven => f.debug_tuple("SockProto::ProtoTwentyseven").finish(), + SockProto::ProtoTwentyeight => f.debug_tuple("SockProto::ProtoTwentyeight").finish(), + SockProto::ProtoTp => f.debug_tuple("SockProto::ProtoTp").finish(), + SockProto::ProtoThirty => f.debug_tuple("SockProto::ProtoThirty").finish(), + SockProto::ProtoThirtyone => f.debug_tuple("SockProto::ProtoThirtyone").finish(), + SockProto::ProtoThirtytwo => f.debug_tuple("SockProto::ProtoThirtytwo").finish(), + SockProto::Dccp => f.debug_tuple("SockProto::Dccp").finish(), + SockProto::ProtoThirtyfour => f.debug_tuple("SockProto::ProtoThirtyfour").finish(), + SockProto::ProtoThirtyfive => f.debug_tuple("SockProto::ProtoThirtyfive").finish(), + SockProto::ProtoThirtysix => f.debug_tuple("SockProto::ProtoThirtysix").finish(), + SockProto::ProtoThirtyseven => f.debug_tuple("SockProto::ProtoThirtyseven").finish(), + SockProto::ProtoThirtyeight => f.debug_tuple("SockProto::ProtoThirtyeight").finish(), + SockProto::ProtoThirtynine => f.debug_tuple("SockProto::ProtoThirtynine").finish(), + SockProto::ProtoFourty => f.debug_tuple("SockProto::ProtoFourty").finish(), + SockProto::Ipv6 => f.debug_tuple("SockProto::Ipv6").finish(), + SockProto::ProtoFourtytwo => f.debug_tuple("SockProto::ProtoFourtytwo").finish(), + SockProto::Routing => f.debug_tuple("SockProto::Routing").finish(), + SockProto::Fragment => f.debug_tuple("SockProto::Fragment").finish(), + SockProto::ProtoFourtyfive => f.debug_tuple("SockProto::ProtoFourtyfive").finish(), + SockProto::Rsvp => f.debug_tuple("SockProto::Rsvp").finish(), + SockProto::Gre => f.debug_tuple("SockProto::Gre").finish(), + SockProto::ProtoFourtyeight => f.debug_tuple("SockProto::ProtoFourtyeight").finish(), + SockProto::ProtoFourtynine => f.debug_tuple("SockProto::ProtoFourtynine").finish(), + SockProto::Esp => f.debug_tuple("SockProto::Esp").finish(), + SockProto::Ah => f.debug_tuple("SockProto::Ah").finish(), + SockProto::ProtoFiftytwo => f.debug_tuple("SockProto::ProtoFiftytwo").finish(), + SockProto::ProtoFiftythree => f.debug_tuple("SockProto::ProtoFiftythree").finish(), + SockProto::ProtoFiftyfour => f.debug_tuple("SockProto::ProtoFiftyfour").finish(), + SockProto::ProtoFiftyfive => f.debug_tuple("SockProto::ProtoFiftyfive").finish(), + SockProto::ProtoFiftysix => f.debug_tuple("SockProto::ProtoFiftysix").finish(), + SockProto::ProtoFiftyseven => f.debug_tuple("SockProto::ProtoFiftyseven").finish(), + SockProto::Icmpv6 => f.debug_tuple("SockProto::Icmpv6").finish(), + SockProto::None => f.debug_tuple("SockProto::None").finish(), + SockProto::Dstopts => f.debug_tuple("SockProto::Dstopts").finish(), + SockProto::ProtoSixtyone => f.debug_tuple("SockProto::ProtoSixtyone").finish(), + SockProto::ProtoSixtytwo => f.debug_tuple("SockProto::ProtoSixtytwo").finish(), + SockProto::ProtoSixtythree => f.debug_tuple("SockProto::ProtoSixtythree").finish(), + SockProto::ProtoSixtyfour => f.debug_tuple("SockProto::ProtoSixtyfour").finish(), + SockProto::ProtoSixtyfive => f.debug_tuple("SockProto::ProtoSixtyfive").finish(), + SockProto::ProtoSixtysix => f.debug_tuple("SockProto::ProtoSixtysix").finish(), + SockProto::ProtoSixtyseven => f.debug_tuple("SockProto::ProtoSixtyseven").finish(), + SockProto::ProtoSixtyeight => f.debug_tuple("SockProto::ProtoSixtyeight").finish(), + SockProto::ProtoSixtynine => f.debug_tuple("SockProto::ProtoSixtynine").finish(), + SockProto::ProtoSeventy => f.debug_tuple("SockProto::ProtoSeventy").finish(), + SockProto::ProtoSeventyone => f.debug_tuple("SockProto::ProtoSeventyone").finish(), + SockProto::ProtoSeventytwo => f.debug_tuple("SockProto::ProtoSeventytwo").finish(), + SockProto::ProtoSeventythree => f.debug_tuple("SockProto::ProtoSeventythree").finish(), + SockProto::ProtoSeventyfour => f.debug_tuple("SockProto::ProtoSeventyfour").finish(), + SockProto::ProtoSeventyfive => f.debug_tuple("SockProto::ProtoSeventyfive").finish(), + SockProto::ProtoSeventysix => f.debug_tuple("SockProto::ProtoSeventysix").finish(), + SockProto::ProtoSeventyseven => f.debug_tuple("SockProto::ProtoSeventyseven").finish(), + SockProto::ProtoSeventyeight => f.debug_tuple("SockProto::ProtoSeventyeight").finish(), + SockProto::ProtoSeventynine => f.debug_tuple("SockProto::ProtoSeventynine").finish(), + SockProto::ProtoEighty => f.debug_tuple("SockProto::ProtoEighty").finish(), + SockProto::ProtoEightyone => f.debug_tuple("SockProto::ProtoEightyone").finish(), + SockProto::ProtoEightytwo => f.debug_tuple("SockProto::ProtoEightytwo").finish(), + SockProto::ProtoEightythree => f.debug_tuple("SockProto::ProtoEightythree").finish(), + SockProto::ProtoEightyfour => f.debug_tuple("SockProto::ProtoEightyfour").finish(), + SockProto::ProtoEightyfive => f.debug_tuple("SockProto::ProtoEightyfive").finish(), + SockProto::ProtoEightysix => f.debug_tuple("SockProto::ProtoEightysix").finish(), + SockProto::ProtoEightyseven => f.debug_tuple("SockProto::ProtoEightyseven").finish(), + SockProto::ProtoEightyeight => f.debug_tuple("SockProto::ProtoEightyeight").finish(), + SockProto::ProtoEightynine => f.debug_tuple("SockProto::ProtoEightynine").finish(), + SockProto::ProtoNinety => f.debug_tuple("SockProto::ProtoNinety").finish(), + SockProto::ProtoNinetyone => f.debug_tuple("SockProto::ProtoNinetyone").finish(), + SockProto::Mtp => f.debug_tuple("SockProto::Mtp").finish(), + SockProto::ProtoNinetythree => f.debug_tuple("SockProto::ProtoNinetythree").finish(), + SockProto::Beetph => f.debug_tuple("SockProto::Beetph").finish(), + SockProto::ProtoNinetyfive => f.debug_tuple("SockProto::ProtoNinetyfive").finish(), + SockProto::ProtoNinetysix => f.debug_tuple("SockProto::ProtoNinetysix").finish(), + SockProto::ProtoNineetyseven => f.debug_tuple("SockProto::ProtoNineetyseven").finish(), + SockProto::Encap => f.debug_tuple("SockProto::Encap").finish(), + SockProto::ProtoNinetynine => f.debug_tuple("SockProto::ProtoNinetynine").finish(), + SockProto::ProtoOnehundred => f.debug_tuple("SockProto::ProtoOnehundred").finish(), + SockProto::ProtoOnehundredandone => { + f.debug_tuple("SockProto::ProtoOnehundredandone").finish() + } + SockProto::ProtoOnehundredandtwo => { + f.debug_tuple("SockProto::ProtoOnehundredandtwo").finish() + } + SockProto::Pim => f.debug_tuple("SockProto::Pim").finish(), + SockProto::ProtoOnehundredandfour => { + f.debug_tuple("SockProto::ProtoOnehundredandfour").finish() + } + SockProto::ProtoOnehundredandfive => { + f.debug_tuple("SockProto::ProtoOnehundredandfive").finish() + } + SockProto::ProtoOnehundredandsix => { + f.debug_tuple("SockProto::ProtoOnehundredandsix").finish() + } + SockProto::ProtoOnehundredandseven => { + f.debug_tuple("SockProto::ProtoOnehundredandseven").finish() + } + SockProto::Comp => f.debug_tuple("SockProto::Comp").finish(), + SockProto::ProtoOnehundredandnine => { + f.debug_tuple("SockProto::ProtoOnehundredandnine").finish() + } + SockProto::ProtoOnehundredandten => { + f.debug_tuple("SockProto::ProtoOnehundredandten").finish() + } + SockProto::ProtoOnehundredandeleven => f + .debug_tuple("SockProto::ProtoOnehundredandeleven") + .finish(), + SockProto::ProtoOnehundredandtwelve => f + .debug_tuple("SockProto::ProtoOnehundredandtwelve") + .finish(), + SockProto::ProtoOnehundredandthirteen => f + .debug_tuple("SockProto::ProtoOnehundredandthirteen") + .finish(), + SockProto::ProtoOnehundredandfourteen => f + .debug_tuple("SockProto::ProtoOnehundredandfourteen") + .finish(), + SockProto::ProtoOnehundredandfifteen => f + .debug_tuple("SockProto::ProtoOnehundredandfifteen") + .finish(), + SockProto::ProtoOnehundredandsixteen => f + .debug_tuple("SockProto::ProtoOnehundredandsixteen") + .finish(), + SockProto::ProtoOnehundredandseventeen => f + .debug_tuple("SockProto::ProtoOnehundredandseventeen") + .finish(), + SockProto::ProtoOnehundredandeighteen => f + .debug_tuple("SockProto::ProtoOnehundredandeighteen") + .finish(), + SockProto::ProtoOnehundredandnineteen => f + .debug_tuple("SockProto::ProtoOnehundredandnineteen") + .finish(), + SockProto::ProtoOnehundredandtwenty => f + .debug_tuple("SockProto::ProtoOnehundredandtwenty") + .finish(), + SockProto::ProtoOnehundredandtwentyone => f + .debug_tuple("SockProto::ProtoOnehundredandtwentyone") + .finish(), + SockProto::ProtoOnehundredandtwentytwo => f + .debug_tuple("SockProto::ProtoOnehundredandtwentytwo") + .finish(), + SockProto::ProtoOnehundredandtwentythree => f + .debug_tuple("SockProto::ProtoOnehundredandtwentythree") + .finish(), + SockProto::ProtoOnehundredandtwentyfour => f + .debug_tuple("SockProto::ProtoOnehundredandtwentyfour") + .finish(), + SockProto::ProtoOnehundredandtwentyfive => f + .debug_tuple("SockProto::ProtoOnehundredandtwentyfive") + .finish(), + SockProto::ProtoOnehundredandtwentysix => f + .debug_tuple("SockProto::ProtoOnehundredandtwentysix") + .finish(), + SockProto::ProtoOnehundredandtwentyseven => f + .debug_tuple("SockProto::ProtoOnehundredandtwentyseven") + .finish(), + SockProto::ProtoOnehundredandtwentyeight => f + .debug_tuple("SockProto::ProtoOnehundredandtwentyeight") + .finish(), + SockProto::ProtoOnehundredandtwentynine => f + .debug_tuple("SockProto::ProtoOnehundredandtwentynine") + .finish(), + SockProto::ProtoOnehundredandthirty => f + .debug_tuple("SockProto::ProtoOnehundredandthirty") + .finish(), + SockProto::ProtoOnehundredandthirtyone => f + .debug_tuple("SockProto::ProtoOnehundredandthirtyone") + .finish(), + SockProto::Sctp => f.debug_tuple("SockProto::Sctp").finish(), + SockProto::ProtoOnehundredandthirtythree => f + .debug_tuple("SockProto::ProtoOnehundredandthirtythree") + .finish(), + SockProto::ProtoOnehundredandthirtyfour => f + .debug_tuple("SockProto::ProtoOnehundredandthirtyfour") + .finish(), + SockProto::Mh => f.debug_tuple("SockProto::Mh").finish(), + SockProto::Udplite => f.debug_tuple("SockProto::Udplite").finish(), + SockProto::Mpls => f.debug_tuple("SockProto::Mpls").finish(), + SockProto::ProtoOnehundredandthirtyeight => f + .debug_tuple("SockProto::ProtoOnehundredandthirtyeight") + .finish(), + SockProto::ProtoOnehundredandthirtynine => f + .debug_tuple("SockProto::ProtoOnehundredandthirtynine") + .finish(), + SockProto::ProtoOnehundredandfourty => f + .debug_tuple("SockProto::ProtoOnehundredandfourty") + .finish(), + SockProto::ProtoOnehundredandfourtyone => f + .debug_tuple("SockProto::ProtoOnehundredandfourtyone") + .finish(), + SockProto::ProtoOnehundredandfourtytwo => f + .debug_tuple("SockProto::ProtoOnehundredandfourtytwo") + .finish(), + SockProto::Ethernet => f.debug_tuple("SockProto::Ethernet").finish(), + SockProto::ProtoOnehundredandfourtyfour => f + .debug_tuple("SockProto::ProtoOnehundredandfourtyfour") + .finish(), + SockProto::ProtoOnehundredandfourtyfive => f + .debug_tuple("SockProto::ProtoOnehundredandfourtyfive") + .finish(), + SockProto::ProtoOnehundredandfourtysix => f + .debug_tuple("SockProto::ProtoOnehundredandfourtysix") + .finish(), + SockProto::ProtoOnehundredandfourtyseven => f + .debug_tuple("SockProto::ProtoOnehundredandfourtyseven") + .finish(), + SockProto::ProtoOnehundredandfourtyeight => f + .debug_tuple("SockProto::ProtoOnehundredandfourtyeight") + .finish(), + SockProto::ProtoOnehundredandfourtynine => f + .debug_tuple("SockProto::ProtoOnehundredandfourtynine") + .finish(), + SockProto::ProtoOnehundredandfifty => { + f.debug_tuple("SockProto::ProtoOnehundredandfifty").finish() + } + SockProto::ProtoOnehundredandfiftyone => f + .debug_tuple("SockProto::ProtoOnehundredandfiftyone") + .finish(), + SockProto::ProtoOnehundredandfiftytwo => f + .debug_tuple("SockProto::ProtoOnehundredandfiftytwo") + .finish(), + SockProto::ProtoOnehundredandfiftythree => f + .debug_tuple("SockProto::ProtoOnehundredandfiftythree") + .finish(), + SockProto::ProtoOnehundredandfiftyfour => f + .debug_tuple("SockProto::ProtoOnehundredandfiftyfour") + .finish(), + SockProto::ProtoOnehundredandfiftyfive => f + .debug_tuple("SockProto::ProtoOnehundredandfiftyfive") + .finish(), + SockProto::ProtoOnehundredandfiftysix => f + .debug_tuple("SockProto::ProtoOnehundredandfiftysix") + .finish(), + SockProto::ProtoOnehundredandfiftyseven => f + .debug_tuple("SockProto::ProtoOnehundredandfiftyseven") + .finish(), + SockProto::ProtoOnehundredandfiftyeight => f + .debug_tuple("SockProto::ProtoOnehundredandfiftyeight") + .finish(), + SockProto::ProtoOnehundredandfiftynine => f + .debug_tuple("SockProto::ProtoOnehundredandfiftynine") + .finish(), + SockProto::ProtoOnehundredandsixty => { + f.debug_tuple("SockProto::ProtoOnehundredandsixty").finish() + } + SockProto::ProtoOnehundredandsixtyone => f + .debug_tuple("SockProto::ProtoOnehundredandsixtyone") + .finish(), + SockProto::ProtoOnehundredandsixtytwo => f + .debug_tuple("SockProto::ProtoOnehundredandsixtytwo") + .finish(), + SockProto::ProtoOnehundredandsixtythree => f + .debug_tuple("SockProto::ProtoOnehundredandsixtythree") + .finish(), + SockProto::ProtoOnehundredandsixtyfour => f + .debug_tuple("SockProto::ProtoOnehundredandsixtyfour") + .finish(), + SockProto::ProtoOnehundredandsixtyfive => f + .debug_tuple("SockProto::ProtoOnehundredandsixtyfive") + .finish(), + SockProto::ProtoOnehundredandsixtysix => f + .debug_tuple("SockProto::ProtoOnehundredandsixtysix") + .finish(), + SockProto::ProtoOnehundredandsixtyseven => f + .debug_tuple("SockProto::ProtoOnehundredandsixtyseven") + .finish(), + SockProto::ProtoOnehundredandsixtyeight => f + .debug_tuple("SockProto::ProtoOnehundredandsixtyeight") + .finish(), + SockProto::ProtoOnehundredandsixtynine => f + .debug_tuple("SockProto::ProtoOnehundredandsixtynine") + .finish(), + SockProto::ProtoOnehundredandseventy => f + .debug_tuple("SockProto::ProtoOnehundredandseventy") + .finish(), + SockProto::ProtoOnehundredandseventyone => f + .debug_tuple("SockProto::ProtoOnehundredandseventyone") + .finish(), + SockProto::ProtoOnehundredandseventytwo => f + .debug_tuple("SockProto::ProtoOnehundredandseventytwo") + .finish(), + SockProto::ProtoOnehundredandseventythree => f + .debug_tuple("SockProto::ProtoOnehundredandseventythree") + .finish(), + SockProto::ProtoOnehundredandseventyfour => f + .debug_tuple("SockProto::ProtoOnehundredandseventyfour") + .finish(), + SockProto::ProtoOnehundredandseventyfive => f + .debug_tuple("SockProto::ProtoOnehundredandseventyfive") + .finish(), + SockProto::ProtoOnehundredandseventysix => f + .debug_tuple("SockProto::ProtoOnehundredandseventysix") + .finish(), + SockProto::ProtoOnehundredandseventyseven => f + .debug_tuple("SockProto::ProtoOnehundredandseventyseven") + .finish(), + SockProto::ProtoOnehundredandseventyeight => f + .debug_tuple("SockProto::ProtoOnehundredandseventyeight") + .finish(), + SockProto::ProtoOnehundredandseventynine => f + .debug_tuple("SockProto::ProtoOnehundredandseventynine") + .finish(), + SockProto::ProtoOnehundredandeighty => f + .debug_tuple("SockProto::ProtoOnehundredandeighty") + .finish(), + SockProto::ProtoOnehundredandeightyone => f + .debug_tuple("SockProto::ProtoOnehundredandeightyone") + .finish(), + SockProto::ProtoOnehundredandeightytwo => f + .debug_tuple("SockProto::ProtoOnehundredandeightytwo") + .finish(), + SockProto::ProtoOnehundredandeightythree => f + .debug_tuple("SockProto::ProtoOnehundredandeightythree") + .finish(), + SockProto::ProtoOnehundredandeightyfour => f + .debug_tuple("SockProto::ProtoOnehundredandeightyfour") + .finish(), + SockProto::ProtoOnehundredandeightyfive => f + .debug_tuple("SockProto::ProtoOnehundredandeightyfive") + .finish(), + SockProto::ProtoOnehundredandeightysix => f + .debug_tuple("SockProto::ProtoOnehundredandeightysix") + .finish(), + SockProto::ProtoOnehundredandeightyseven => f + .debug_tuple("SockProto::ProtoOnehundredandeightyseven") + .finish(), + SockProto::ProtoOnehundredandeightyeight => f + .debug_tuple("SockProto::ProtoOnehundredandeightyeight") + .finish(), + SockProto::ProtoOnehundredandeightynine => f + .debug_tuple("SockProto::ProtoOnehundredandeightynine") + .finish(), + SockProto::ProtoOnehundredandninety => f + .debug_tuple("SockProto::ProtoOnehundredandninety") + .finish(), + SockProto::ProtoOnehundredandninetyone => f + .debug_tuple("SockProto::ProtoOnehundredandninetyone") + .finish(), + SockProto::ProtoOnehundredandninetytwo => f + .debug_tuple("SockProto::ProtoOnehundredandninetytwo") + .finish(), + SockProto::ProtoOnehundredandninetythree => f + .debug_tuple("SockProto::ProtoOnehundredandninetythree") + .finish(), + SockProto::ProtoOnehundredandninetyfour => f + .debug_tuple("SockProto::ProtoOnehundredandninetyfour") + .finish(), + SockProto::ProtoOnehundredandninetyfive => f + .debug_tuple("SockProto::ProtoOnehundredandninetyfive") + .finish(), + SockProto::ProtoOnehundredandninetysix => f + .debug_tuple("SockProto::ProtoOnehundredandninetysix") + .finish(), + SockProto::ProtoOnehundredandninetyseven => f + .debug_tuple("SockProto::ProtoOnehundredandninetyseven") + .finish(), + SockProto::ProtoOnehundredandninetyeight => f + .debug_tuple("SockProto::ProtoOnehundredandninetyeight") + .finish(), + SockProto::ProtoOnehundredandninetynine => f + .debug_tuple("SockProto::ProtoOnehundredandninetynine") + .finish(), + SockProto::ProtoTwohundred => f.debug_tuple("SockProto::ProtoTwohundred").finish(), + SockProto::ProtoTwohundredandone => { + f.debug_tuple("SockProto::ProtoTwohundredandone").finish() + } + SockProto::ProtoTwohundredandtwo => { + f.debug_tuple("SockProto::ProtoTwohundredandtwo").finish() + } + SockProto::ProtoTwohundredandthree => { + f.debug_tuple("SockProto::ProtoTwohundredandthree").finish() + } + SockProto::ProtoTwohundredandfour => { + f.debug_tuple("SockProto::ProtoTwohundredandfour").finish() + } + SockProto::ProtoTwohundredandfive => { + f.debug_tuple("SockProto::ProtoTwohundredandfive").finish() + } + SockProto::ProtoTwohundredandsix => { + f.debug_tuple("SockProto::ProtoTwohundredandsix").finish() + } + SockProto::ProtoTwohundredandseven => { + f.debug_tuple("SockProto::ProtoTwohundredandseven").finish() + } + SockProto::ProtoTwohundredandeight => { + f.debug_tuple("SockProto::ProtoTwohundredandeight").finish() + } + SockProto::ProtoTwohundredandnine => { + f.debug_tuple("SockProto::ProtoTwohundredandnine").finish() + } + SockProto::ProtoTwohundredandten => { + f.debug_tuple("SockProto::ProtoTwohundredandten").finish() + } + SockProto::ProtoTwohundredandeleven => f + .debug_tuple("SockProto::ProtoTwohundredandeleven") + .finish(), + SockProto::ProtoTwohundredandtwelve => f + .debug_tuple("SockProto::ProtoTwohundredandtwelve") + .finish(), + SockProto::ProtoTwohundredandthirteen => f + .debug_tuple("SockProto::ProtoTwohundredandthirteen") + .finish(), + SockProto::ProtoTwohundredandfourteen => f + .debug_tuple("SockProto::ProtoTwohundredandfourteen") + .finish(), + SockProto::ProtoTwohundredandfifteen => f + .debug_tuple("SockProto::ProtoTwohundredandfifteen") + .finish(), + SockProto::ProtoTwohundredandsixteen => f + .debug_tuple("SockProto::ProtoTwohundredandsixteen") + .finish(), + SockProto::ProtoTwohundredandseventeen => f + .debug_tuple("SockProto::ProtoTwohundredandseventeen") + .finish(), + SockProto::ProtoTwohundredandeighteen => f + .debug_tuple("SockProto::ProtoTwohundredandeighteen") + .finish(), + SockProto::ProtoTwohundredandnineteen => f + .debug_tuple("SockProto::ProtoTwohundredandnineteen") + .finish(), + SockProto::ProtoTwohundredandtwenty => f + .debug_tuple("SockProto::ProtoTwohundredandtwenty") + .finish(), + SockProto::ProtoTwohundredandtwentyone => f + .debug_tuple("SockProto::ProtoTwohundredandtwentyone") + .finish(), + SockProto::ProtoTwohundredandtwentytwo => f + .debug_tuple("SockProto::ProtoTwohundredandtwentytwo") + .finish(), + SockProto::ProtoTwohundredandtwentythree => f + .debug_tuple("SockProto::ProtoTwohundredandtwentythree") + .finish(), + SockProto::ProtoTwohundredandtwentyfour => f + .debug_tuple("SockProto::ProtoTwohundredandtwentyfour") + .finish(), + SockProto::ProtoTwohundredandtwentyfive => f + .debug_tuple("SockProto::ProtoTwohundredandtwentyfive") + .finish(), + SockProto::ProtoTwohundredandtwentysix => f + .debug_tuple("SockProto::ProtoTwohundredandtwentysix") + .finish(), + SockProto::ProtoTwohundredandtwentyseven => f + .debug_tuple("SockProto::ProtoTwohundredandtwentyseven") + .finish(), + SockProto::ProtoTwohundredandtwentyeight => f + .debug_tuple("SockProto::ProtoTwohundredandtwentyeight") + .finish(), + SockProto::ProtoTwohundredandtwentynine => f + .debug_tuple("SockProto::ProtoTwohundredandtwentynine") + .finish(), + SockProto::ProtoTwohundredandthirty => f + .debug_tuple("SockProto::ProtoTwohundredandthirty") + .finish(), + SockProto::ProtoTwohundredandthirtyone => f + .debug_tuple("SockProto::ProtoTwohundredandthirtyone") + .finish(), + SockProto::ProtoTwohundredandthirtytwo => f + .debug_tuple("SockProto::ProtoTwohundredandthirtytwo") + .finish(), + SockProto::ProtoTwohundredandthirtythree => f + .debug_tuple("SockProto::ProtoTwohundredandthirtythree") + .finish(), + SockProto::ProtoTwohundredandthirtyfour => f + .debug_tuple("SockProto::ProtoTwohundredandthirtyfour") + .finish(), + SockProto::ProtoTwohundredandthirtyfive => f + .debug_tuple("SockProto::ProtoTwohundredandthirtyfive") + .finish(), + SockProto::ProtoTwohundredandthirtysix => f + .debug_tuple("SockProto::ProtoTwohundredandthirtysix") + .finish(), + SockProto::ProtoTwohundredandthirtyseven => f + .debug_tuple("SockProto::ProtoTwohundredandthirtyseven") + .finish(), + SockProto::ProtoTwohundredandthirtyeight => f + .debug_tuple("SockProto::ProtoTwohundredandthirtyeight") + .finish(), + SockProto::ProtoTwohundredandthirtynine => f + .debug_tuple("SockProto::ProtoTwohundredandthirtynine") + .finish(), + SockProto::ProtoTwohundredandfourty => f + .debug_tuple("SockProto::ProtoTwohundredandfourty") + .finish(), + SockProto::ProtoTwohundredandfourtyone => f + .debug_tuple("SockProto::ProtoTwohundredandfourtyone") + .finish(), + SockProto::ProtoTwohundredandfourtytwo => f + .debug_tuple("SockProto::ProtoTwohundredandfourtytwo") + .finish(), + SockProto::ProtoTwohundredandfourtythree => f + .debug_tuple("SockProto::ProtoTwohundredandfourtythree") + .finish(), + SockProto::ProtoTwohundredandfourtyfour => f + .debug_tuple("SockProto::ProtoTwohundredandfourtyfour") + .finish(), + SockProto::ProtoTwohundredandfourtyfive => f + .debug_tuple("SockProto::ProtoTwohundredandfourtyfive") + .finish(), + SockProto::ProtoTwohundredandfourtysix => f + .debug_tuple("SockProto::ProtoTwohundredandfourtysix") + .finish(), + SockProto::ProtoTwohundredandfourtyseven => f + .debug_tuple("SockProto::ProtoTwohundredandfourtyseven") + .finish(), + SockProto::ProtoTwohundredandfourtyeight => f + .debug_tuple("SockProto::ProtoTwohundredandfourtyeight") + .finish(), + SockProto::ProtoTwohundredandfourtynine => f + .debug_tuple("SockProto::ProtoTwohundredandfourtynine") + .finish(), + SockProto::ProtoTwohundredandfifty => { + f.debug_tuple("SockProto::ProtoTwohundredandfifty").finish() + } + SockProto::ProtoTwohundredandfiftyone => f + .debug_tuple("SockProto::ProtoTwohundredandfiftyone") + .finish(), + SockProto::ProtoTwohundredandfiftytwo => f + .debug_tuple("SockProto::ProtoTwohundredandfiftytwo") + .finish(), + SockProto::ProtoTwohundredandfiftythree => f + .debug_tuple("SockProto::ProtoTwohundredandfiftythree") + .finish(), + SockProto::ProtoTwohundredandfiftyfour => f + .debug_tuple("SockProto::ProtoTwohundredandfiftyfour") + .finish(), + SockProto::ProtoRaw => f.debug_tuple("SockProto::ProtoRaw").finish(), + SockProto::ProtoTwohundredandfiftysix => f + .debug_tuple("SockProto::ProtoTwohundredandfiftysix") + .finish(), + SockProto::ProtoTwohundredandfiftyseven => f + .debug_tuple("SockProto::ProtoTwohundredandfiftyseven") + .finish(), + SockProto::ProtoTwohundredandfiftyeight => f + .debug_tuple("SockProto::ProtoTwohundredandfiftyeight") + .finish(), + SockProto::ProtoTwohundredandfiftynine => f + .debug_tuple("SockProto::ProtoTwohundredandfiftynine") + .finish(), + SockProto::ProtoTwohundredandsixty => { + f.debug_tuple("SockProto::ProtoTwohundredandsixty").finish() + } + SockProto::ProtoTwohundredandsixtyone => f + .debug_tuple("SockProto::ProtoTwohundredandsixtyone") + .finish(), + SockProto::Mptcp => f.debug_tuple("SockProto::Mptcp").finish(), + SockProto::Max => f.debug_tuple("SockProto::Max").finish(), + } + } +} +#[repr(u8)] +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum Bool { + False, + True, +} +impl core::fmt::Debug for Bool { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Bool::False => f.debug_tuple("Bool::False").finish(), + Bool::True => f.debug_tuple("Bool::True").finish(), + } + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct OptionTimestamp { + pub tag: OptionTag, + pub u: Timestamp, +} +impl core::fmt::Debug for OptionTimestamp { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("OptionTimestamp") + .field("tag", &self.tag) + .field("u", &self.u) + .finish() + } +} +#[repr(u8)] +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum Signal { + Sighup, + Sigint, + Sigquit, + Sigill, + Sigtrap, + Sigabrt, + Sigbus, + Sigfpe, + Sigkill, + Sigusr1, + Sigsegv, + Sigusr2, + Sigpipe, + Sigalrm, + Sigterm, + Sigchld, + Sigcont, + Sigstop, + Sigtstp, + Sigttin, + Sigttou, + Sigurg, + Sigxcpu, + Sigxfsz, + Sigvtalrm, + Sigprof, + Sigwinch, + Sigpoll, + Sigpwr, + Sigsys, +} +impl core::fmt::Debug for Signal { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Signal::Sighup => f.debug_tuple("Signal::Sighup").finish(), + Signal::Sigint => f.debug_tuple("Signal::Sigint").finish(), + Signal::Sigquit => f.debug_tuple("Signal::Sigquit").finish(), + Signal::Sigill => f.debug_tuple("Signal::Sigill").finish(), + Signal::Sigtrap => f.debug_tuple("Signal::Sigtrap").finish(), + Signal::Sigabrt => f.debug_tuple("Signal::Sigabrt").finish(), + Signal::Sigbus => f.debug_tuple("Signal::Sigbus").finish(), + Signal::Sigfpe => f.debug_tuple("Signal::Sigfpe").finish(), + Signal::Sigkill => f.debug_tuple("Signal::Sigkill").finish(), + Signal::Sigusr1 => f.debug_tuple("Signal::Sigusr1").finish(), + Signal::Sigsegv => f.debug_tuple("Signal::Sigsegv").finish(), + Signal::Sigusr2 => f.debug_tuple("Signal::Sigusr2").finish(), + Signal::Sigpipe => f.debug_tuple("Signal::Sigpipe").finish(), + Signal::Sigalrm => f.debug_tuple("Signal::Sigalrm").finish(), + Signal::Sigterm => f.debug_tuple("Signal::Sigterm").finish(), + Signal::Sigchld => f.debug_tuple("Signal::Sigchld").finish(), + Signal::Sigcont => f.debug_tuple("Signal::Sigcont").finish(), + Signal::Sigstop => f.debug_tuple("Signal::Sigstop").finish(), + Signal::Sigtstp => f.debug_tuple("Signal::Sigtstp").finish(), + Signal::Sigttin => f.debug_tuple("Signal::Sigttin").finish(), + Signal::Sigttou => f.debug_tuple("Signal::Sigttou").finish(), + Signal::Sigurg => f.debug_tuple("Signal::Sigurg").finish(), + Signal::Sigxcpu => f.debug_tuple("Signal::Sigxcpu").finish(), + Signal::Sigxfsz => f.debug_tuple("Signal::Sigxfsz").finish(), + Signal::Sigvtalrm => f.debug_tuple("Signal::Sigvtalrm").finish(), + Signal::Sigprof => f.debug_tuple("Signal::Sigprof").finish(), + Signal::Sigwinch => f.debug_tuple("Signal::Sigwinch").finish(), + Signal::Sigpoll => f.debug_tuple("Signal::Sigpoll").finish(), + Signal::Sigpwr => f.debug_tuple("Signal::Sigpwr").finish(), + Signal::Sigsys => f.debug_tuple("Signal::Sigsys").finish(), + } + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct AddrUnspec { + pub n0: u8, +} +impl core::fmt::Debug for AddrUnspec { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("AddrUnspec").field("n0", &self.n0).finish() + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct AddrUnspecPort { + pub port: u16, + pub addr: AddrUnspec, +} +impl core::fmt::Debug for AddrUnspecPort { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("AddrUnspecPort") + .field("port", &self.port) + .field("addr", &self.addr) + .finish() + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct CidrUnspec { + pub addr: AddrUnspec, + pub prefix: u8, +} +impl core::fmt::Debug for CidrUnspec { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("CidrUnspec") + .field("addr", &self.addr) + .field("prefix", &self.prefix) + .finish() + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct HttpHandles { + pub req: Fd, + pub res: Fd, + pub hdr: Fd, +} +impl core::fmt::Debug for HttpHandles { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("HttpHandles") + .field("req", &self.req) + .field("res", &self.res) + .field("hdr", &self.hdr) + .finish() + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct HttpStatus { + pub ok: Bool, + pub redirect: Bool, + pub size: Filesize, + pub status: u16, +} +impl core::fmt::Debug for HttpStatus { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("HttpStatus") + .field("ok", &self.ok) + .field("redirect", &self.redirect) + .field("size", &self.size) + .field("status", &self.status) + .finish() + } +} +pub type RiFlags = u16; +pub type RoFlags = u16; +pub type SdFlags = u8; +pub type SiFlags = u16; +#[repr(u8)] +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum Timeout { + Read, + Write, + Connect, + Accept, +} +impl core::fmt::Debug for Timeout { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Timeout::Read => f.debug_tuple("Timeout::Read").finish(), + Timeout::Write => f.debug_tuple("Timeout::Write").finish(), + Timeout::Connect => f.debug_tuple("Timeout::Connect").finish(), + Timeout::Accept => f.debug_tuple("Timeout::Accept").finish(), + } + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Snapshot0Clockid { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +unsafe impl wasmer::FromToNativeWasmType for Snapshot0Clockid { + type Native = i32; + + fn to_native(self) -> Self::Native { + self as i32 + } + + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::Realtime, + 1 => Self::Monotonic, + 2 => Self::ProcessCputimeId, + 3 => Self::ThreadCputimeId, + + q => todo!("could not serialize number {q} to enum Snapshot0Clockid"), + } + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Clockid { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +unsafe impl wasmer::FromToNativeWasmType for Clockid { + type Native = i32; + + fn to_native(self) -> Self::Native { + self as i32 + } + + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::Realtime, + 1 => Self::Monotonic, + + q => todo!("could not serialize number {q} to enum Clockid"), + } + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Errno { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +unsafe impl wasmer::FromToNativeWasmType for Errno { + type Native = i32; + + fn to_native(self) -> Self::Native { + self as i32 + } + + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::Success, + 1 => Self::Toobig, + 2 => Self::Access, + 3 => Self::Addrinuse, + 4 => Self::Addrnotavail, + 5 => Self::Afnosupport, + 6 => Self::Again, + 7 => Self::Already, + 8 => Self::Badf, + 9 => Self::Badmsg, + 10 => Self::Busy, + 11 => Self::Canceled, + 12 => Self::Child, + 13 => Self::Connaborted, + 14 => Self::Connrefused, + 15 => Self::Connreset, + 16 => Self::Deadlk, + 17 => Self::Destaddrreq, + 18 => Self::Dom, + 19 => Self::Dquot, + 20 => Self::Exist, + 21 => Self::Fault, + 22 => Self::Fbig, + 23 => Self::Hostunreach, + 24 => Self::Idrm, + 25 => Self::Ilseq, + 26 => Self::Inprogress, + 27 => Self::Intr, + 28 => Self::Inval, + 29 => Self::Io, + 30 => Self::Isconn, + 31 => Self::Isdir, + 32 => Self::Loop, + 33 => Self::Mfile, + 34 => Self::Mlink, + 35 => Self::Msgsize, + 36 => Self::Multihop, + 37 => Self::Nametoolong, + 38 => Self::Netdown, + 39 => Self::Netreset, + 40 => Self::Netunreach, + 41 => Self::Nfile, + 42 => Self::Nobufs, + 43 => Self::Nodev, + 44 => Self::Noent, + 45 => Self::Noexec, + 46 => Self::Nolck, + 47 => Self::Nolink, + 48 => Self::Nomem, + 49 => Self::Nomsg, + 50 => Self::Noprotoopt, + 51 => Self::Nospc, + 52 => Self::Nosys, + 53 => Self::Notconn, + 54 => Self::Notdir, + 55 => Self::Notempty, + 56 => Self::Notrecoverable, + 57 => Self::Notsock, + 58 => Self::Notsup, + 59 => Self::Notty, + 60 => Self::Nxio, + 61 => Self::Overflow, + 62 => Self::Ownerdead, + 63 => Self::Perm, + 64 => Self::Pipe, + 65 => Self::Proto, + 66 => Self::Protonosupport, + 67 => Self::Prototype, + 68 => Self::Range, + 69 => Self::Rofs, + 70 => Self::Spipe, + 71 => Self::Srch, + 72 => Self::Stale, + 73 => Self::Timedout, + 74 => Self::Txtbsy, + 75 => Self::Xdev, + 76 => Self::Notcapable, + + q => todo!("could not serialize number {q} to enum Errno"), + } + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for BusErrno { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +unsafe impl wasmer::FromToNativeWasmType for BusErrno { + type Native = i32; + + fn to_native(self) -> Self::Native { + self as i32 + } + + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::Success, + 1 => Self::Ser, + 2 => Self::Des, + 3 => Self::Wapm, + 4 => Self::Fetch, + 5 => Self::Compile, + 6 => Self::Abi, + 7 => Self::Aborted, + 8 => Self::Badhandle, + 9 => Self::Topic, + 10 => Self::Badcb, + 11 => Self::Unsupported, + 12 => Self::Badrequest, + 13 => Self::Denied, + 14 => Self::Internal, + 15 => Self::Alloc, + 16 => Self::Invoke, + 17 => Self::Consumed, + 18 => Self::Memviolation, + 19 => Self::Unknown, + + q => todo!("could not serialize number {q} to enum BusErrno"), + } + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Rights { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Filetype { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +unsafe impl wasmer::FromToNativeWasmType for Filetype { + type Native = i32; + + fn to_native(self) -> Self::Native { + self as i32 + } + + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::Unknown, + 1 => Self::BlockDevice, + 2 => Self::CharacterDevice, + 3 => Self::Directory, + 4 => Self::RegularFile, + 5 => Self::SocketDgram, + 6 => Self::SocketStream, + 7 => Self::SymbolicLink, + 8 => Self::Fifo, + + q => todo!("could not serialize number {q} to enum Filetype"), + } + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Snapshot0Dirent { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Dirent { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Advice { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +unsafe impl wasmer::FromToNativeWasmType for Advice { + type Native = i32; + + fn to_native(self) -> Self::Native { + self as i32 + } + + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::Normal, + 1 => Self::Sequential, + 2 => Self::Random, + 3 => Self::Willneed, + 4 => Self::Dontneed, + 5 => Self::Noreuse, + + q => todo!("could not serialize number {q} to enum Advice"), + } + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Fdflags { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Fdstat { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Fstflags { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Lookup { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Oflags { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Eventtype { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +unsafe impl wasmer::FromToNativeWasmType for Eventtype { + type Native = i32; + + fn to_native(self) -> Self::Native { + self as i32 + } + + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::Clock, + 1 => Self::FdRead, + 2 => Self::FdWrite, + + q => todo!("could not serialize number {q} to enum Eventtype"), + } + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Subclockflags { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Snapshot0SubscriptionClock { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for SubscriptionClock { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Preopentype { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +unsafe impl wasmer::FromToNativeWasmType for Preopentype { + type Native = i32; + + fn to_native(self) -> Self::Native { + self as i32 + } + + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::Dir, + + q => todo!("could not serialize number {q} to enum Preopentype"), + } + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Eventrwflags { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for EventFdReadwrite { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Event { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for EventEnum { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Snapshot0Event { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Snapshot0SubscriptionEnum { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for SubscriptionEnum { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for SubscriptionFsReadwrite { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Snapshot0Subscription { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Subscription { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Socktype { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +unsafe impl wasmer::FromToNativeWasmType for Socktype { + type Native = i32; + + fn to_native(self) -> Self::Native { + self as i32 + } + + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::Dgram, + 1 => Self::Stream, + 2 => Self::Raw, + 3 => Self::Seqpacket, + + q => todo!("could not serialize number {q} to enum Socktype"), + } + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Sockstatus { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +unsafe impl wasmer::FromToNativeWasmType for Sockstatus { + type Native = i32; + + fn to_native(self) -> Self::Native { + self as i32 + } + + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::Opening, + 1 => Self::Opened, + 2 => Self::Closed, + 3 => Self::Failed, + + q => todo!("could not serialize number {q} to enum Sockstatus"), + } + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Sockoption { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +unsafe impl wasmer::FromToNativeWasmType for Sockoption { + type Native = i32; + + fn to_native(self) -> Self::Native { + self as i32 + } + + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::Noop, + 1 => Self::ReusePort, + 2 => Self::ReuseAddr, + 3 => Self::NoDelay, + 4 => Self::DontRoute, + 5 => Self::OnlyV6, + 6 => Self::Broadcast, + 7 => Self::MulticastLoopV4, + 8 => Self::MulticastLoopV6, + 9 => Self::Promiscuous, + 10 => Self::Listening, + 11 => Self::LastError, + 12 => Self::KeepAlive, + 13 => Self::Linger, + 14 => Self::OobInline, + 15 => Self::RecvBufSize, + 16 => Self::SendBufSize, + 17 => Self::RecvLowat, + 18 => Self::SendLowat, + 19 => Self::RecvTimeout, + 20 => Self::SendTimeout, + 21 => Self::ConnectTimeout, + 22 => Self::AcceptTimeout, + 23 => Self::Ttl, + 24 => Self::MulticastTtlV4, + 25 => Self::Type, + 26 => Self::Proto, + + q => todo!("could not serialize number {q} to enum Sockoption"), + } + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Streamsecurity { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +unsafe impl wasmer::FromToNativeWasmType for Streamsecurity { + type Native = i32; + + fn to_native(self) -> Self::Native { + self as i32 + } + + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::Unencrypted, + 1 => Self::AnyEncryption, + 2 => Self::ClassicEncryption, + 3 => Self::DoubleEncryption, + + q => todo!("could not serialize number {q} to enum Streamsecurity"), + } + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Addressfamily { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +unsafe impl wasmer::FromToNativeWasmType for Addressfamily { + type Native = i32; + + fn to_native(self) -> Self::Native { + self as i32 + } + + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::Unspec, + 1 => Self::Inet4, + 2 => Self::Inet6, + 3 => Self::Unix, + + q => todo!("could not serialize number {q} to enum Addressfamily"), + } + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Snapshot0Filestat { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Filestat { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Snapshot0Whence { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +unsafe impl wasmer::FromToNativeWasmType for Snapshot0Whence { + type Native = i32; + + fn to_native(self) -> Self::Native { + self as i32 + } + + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::Cur, + 1 => Self::End, + 2 => Self::Set, + + q => todo!("could not serialize number {q} to enum Snapshot0Whence"), + } + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Whence { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +unsafe impl wasmer::FromToNativeWasmType for Whence { + type Native = i32; + + fn to_native(self) -> Self::Native { + self as i32 + } + + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::Set, + 1 => Self::Cur, + 2 => Self::End, + + q => todo!("could not serialize number {q} to enum Whence"), + } + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Tty { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for BusDataFormat { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +unsafe impl wasmer::FromToNativeWasmType for BusDataFormat { + type Native = i32; + + fn to_native(self) -> Self::Native { + self as i32 + } + + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::Raw, + 1 => Self::Bincode, + 2 => Self::MessagePack, + 3 => Self::Json, + 4 => Self::Yaml, + 5 => Self::Xml, + 6 => Self::Rkyv, + + q => todo!("could not serialize number {q} to enum BusDataFormat"), + } + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for BusEventType { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +unsafe impl wasmer::FromToNativeWasmType for BusEventType { + type Native = i32; + + fn to_native(self) -> Self::Native { + self as i32 + } + + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::Noop, + 1 => Self::Exit, + 2 => Self::Call, + 3 => Self::Result, + 4 => Self::Fault, + 5 => Self::Close, + + q => todo!("could not serialize number {q} to enum BusEventType"), + } + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for OptionTag { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +unsafe impl wasmer::FromToNativeWasmType for OptionTag { + type Native = i32; + + fn to_native(self) -> Self::Native { + self as i32 + } + + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::None, + 1 => Self::Some, + + q => todo!("could not serialize number {q} to enum OptionTag"), + } + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for OptionBid { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for OptionCid { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for OptionFd { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for BusHandles { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for BusEventExit { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for BusEventFault { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for BusEventClose { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for PrestatUDir { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for PrestatU { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for PipeHandles { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for StdioMode { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +unsafe impl wasmer::FromToNativeWasmType for StdioMode { + type Native = i32; + + fn to_native(self) -> Self::Native { + self as i32 + } + + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::Reserved, + 1 => Self::Piped, + 2 => Self::Inherit, + 3 => Self::Null, + 4 => Self::Log, + + q => todo!("could not serialize number {q} to enum StdioMode"), + } + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for SockProto { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +unsafe impl wasmer::FromToNativeWasmType for SockProto { + type Native = i32; + + fn to_native(self) -> Self::Native { + self as i32 + } + + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::Ip, + 1 => Self::Icmp, + 2 => Self::Igmp, + 3 => Self::ProtoThree, + 4 => Self::Ipip, + 5 => Self::ProtoFive, + 6 => Self::Tcp, + 7 => Self::ProtoSeven, + 8 => Self::Egp, + 9 => Self::ProtoNine, + 10 => Self::ProtoTen, + 11 => Self::ProtoEleven, + 12 => Self::Pup, + 13 => Self::ProtoThirteen, + 14 => Self::ProtoFourteen, + 15 => Self::ProtoFifteen, + 16 => Self::ProtoSixteen, + 17 => Self::Udp, + 18 => Self::ProtoEighteen, + 19 => Self::ProtoNineteen, + 20 => Self::ProtoTwenty, + 21 => Self::ProtoTwentyone, + 22 => Self::Idp, + 23 => Self::ProtoTwentythree, + 24 => Self::ProtoTwentyfour, + 25 => Self::ProtoTwentyfive, + 26 => Self::ProtoTwentysix, + 27 => Self::ProtoTwentyseven, + 28 => Self::ProtoTwentyeight, + 29 => Self::ProtoTp, + 30 => Self::ProtoThirty, + 31 => Self::ProtoThirtyone, + 32 => Self::ProtoThirtytwo, + 33 => Self::Dccp, + 34 => Self::ProtoThirtyfour, + 35 => Self::ProtoThirtyfive, + 36 => Self::ProtoThirtysix, + 37 => Self::ProtoThirtyseven, + 38 => Self::ProtoThirtyeight, + 39 => Self::ProtoThirtynine, + 40 => Self::ProtoFourty, + 41 => Self::Ipv6, + 42 => Self::ProtoFourtytwo, + 43 => Self::Routing, + 44 => Self::Fragment, + 45 => Self::ProtoFourtyfive, + 46 => Self::Rsvp, + 47 => Self::Gre, + 48 => Self::ProtoFourtyeight, + 49 => Self::ProtoFourtynine, + 50 => Self::Esp, + 51 => Self::Ah, + 52 => Self::ProtoFiftytwo, + 53 => Self::ProtoFiftythree, + 54 => Self::ProtoFiftyfour, + 55 => Self::ProtoFiftyfive, + 56 => Self::ProtoFiftysix, + 57 => Self::ProtoFiftyseven, + 58 => Self::Icmpv6, + 59 => Self::None, + 60 => Self::Dstopts, + 61 => Self::ProtoSixtyone, + 62 => Self::ProtoSixtytwo, + 63 => Self::ProtoSixtythree, + 64 => Self::ProtoSixtyfour, + 65 => Self::ProtoSixtyfive, + 66 => Self::ProtoSixtysix, + 67 => Self::ProtoSixtyseven, + 68 => Self::ProtoSixtyeight, + 69 => Self::ProtoSixtynine, + 70 => Self::ProtoSeventy, + 71 => Self::ProtoSeventyone, + 72 => Self::ProtoSeventytwo, + 73 => Self::ProtoSeventythree, + 74 => Self::ProtoSeventyfour, + 75 => Self::ProtoSeventyfive, + 76 => Self::ProtoSeventysix, + 77 => Self::ProtoSeventyseven, + 78 => Self::ProtoSeventyeight, + 79 => Self::ProtoSeventynine, + 80 => Self::ProtoEighty, + 81 => Self::ProtoEightyone, + 82 => Self::ProtoEightytwo, + 83 => Self::ProtoEightythree, + 84 => Self::ProtoEightyfour, + 85 => Self::ProtoEightyfive, + 86 => Self::ProtoEightysix, + 87 => Self::ProtoEightyseven, + 88 => Self::ProtoEightyeight, + 89 => Self::ProtoEightynine, + 90 => Self::ProtoNinety, + 91 => Self::ProtoNinetyone, + 92 => Self::Mtp, + 93 => Self::ProtoNinetythree, + 94 => Self::Beetph, + 95 => Self::ProtoNinetyfive, + 96 => Self::ProtoNinetysix, + 97 => Self::ProtoNineetyseven, + 98 => Self::Encap, + 99 => Self::ProtoNinetynine, + 100 => Self::ProtoOnehundred, + 101 => Self::ProtoOnehundredandone, + 102 => Self::ProtoOnehundredandtwo, + 103 => Self::Pim, + 104 => Self::ProtoOnehundredandfour, + 105 => Self::ProtoOnehundredandfive, + 106 => Self::ProtoOnehundredandsix, + 107 => Self::ProtoOnehundredandseven, + 108 => Self::Comp, + 109 => Self::ProtoOnehundredandnine, + 110 => Self::ProtoOnehundredandten, + 111 => Self::ProtoOnehundredandeleven, + 112 => Self::ProtoOnehundredandtwelve, + 113 => Self::ProtoOnehundredandthirteen, + 114 => Self::ProtoOnehundredandfourteen, + 115 => Self::ProtoOnehundredandfifteen, + 116 => Self::ProtoOnehundredandsixteen, + 117 => Self::ProtoOnehundredandseventeen, + 118 => Self::ProtoOnehundredandeighteen, + 119 => Self::ProtoOnehundredandnineteen, + 120 => Self::ProtoOnehundredandtwenty, + 121 => Self::ProtoOnehundredandtwentyone, + 122 => Self::ProtoOnehundredandtwentytwo, + 123 => Self::ProtoOnehundredandtwentythree, + 124 => Self::ProtoOnehundredandtwentyfour, + 125 => Self::ProtoOnehundredandtwentyfive, + 126 => Self::ProtoOnehundredandtwentysix, + 127 => Self::ProtoOnehundredandtwentyseven, + 128 => Self::ProtoOnehundredandtwentyeight, + 129 => Self::ProtoOnehundredandtwentynine, + 130 => Self::ProtoOnehundredandthirty, + 131 => Self::ProtoOnehundredandthirtyone, + 132 => Self::Sctp, + 133 => Self::ProtoOnehundredandthirtythree, + 134 => Self::ProtoOnehundredandthirtyfour, + 135 => Self::Mh, + 136 => Self::Udplite, + 137 => Self::Mpls, + 138 => Self::ProtoOnehundredandthirtyeight, + 139 => Self::ProtoOnehundredandthirtynine, + 140 => Self::ProtoOnehundredandfourty, + 141 => Self::ProtoOnehundredandfourtyone, + 142 => Self::ProtoOnehundredandfourtytwo, + 143 => Self::Ethernet, + 144 => Self::ProtoOnehundredandfourtyfour, + 145 => Self::ProtoOnehundredandfourtyfive, + 146 => Self::ProtoOnehundredandfourtysix, + 147 => Self::ProtoOnehundredandfourtyseven, + 148 => Self::ProtoOnehundredandfourtyeight, + 149 => Self::ProtoOnehundredandfourtynine, + 150 => Self::ProtoOnehundredandfifty, + 151 => Self::ProtoOnehundredandfiftyone, + 152 => Self::ProtoOnehundredandfiftytwo, + 153 => Self::ProtoOnehundredandfiftythree, + 154 => Self::ProtoOnehundredandfiftyfour, + 155 => Self::ProtoOnehundredandfiftyfive, + 156 => Self::ProtoOnehundredandfiftysix, + 157 => Self::ProtoOnehundredandfiftyseven, + 158 => Self::ProtoOnehundredandfiftyeight, + 159 => Self::ProtoOnehundredandfiftynine, + 160 => Self::ProtoOnehundredandsixty, + 161 => Self::ProtoOnehundredandsixtyone, + 162 => Self::ProtoOnehundredandsixtytwo, + 163 => Self::ProtoOnehundredandsixtythree, + 164 => Self::ProtoOnehundredandsixtyfour, + 165 => Self::ProtoOnehundredandsixtyfive, + 166 => Self::ProtoOnehundredandsixtysix, + 167 => Self::ProtoOnehundredandsixtyseven, + 168 => Self::ProtoOnehundredandsixtyeight, + 169 => Self::ProtoOnehundredandsixtynine, + 170 => Self::ProtoOnehundredandseventy, + 171 => Self::ProtoOnehundredandseventyone, + 172 => Self::ProtoOnehundredandseventytwo, + 173 => Self::ProtoOnehundredandseventythree, + 174 => Self::ProtoOnehundredandseventyfour, + 175 => Self::ProtoOnehundredandseventyfive, + 176 => Self::ProtoOnehundredandseventysix, + 177 => Self::ProtoOnehundredandseventyseven, + 178 => Self::ProtoOnehundredandseventyeight, + 179 => Self::ProtoOnehundredandseventynine, + 180 => Self::ProtoOnehundredandeighty, + 181 => Self::ProtoOnehundredandeightyone, + 182 => Self::ProtoOnehundredandeightytwo, + 183 => Self::ProtoOnehundredandeightythree, + 184 => Self::ProtoOnehundredandeightyfour, + 185 => Self::ProtoOnehundredandeightyfive, + 186 => Self::ProtoOnehundredandeightysix, + 187 => Self::ProtoOnehundredandeightyseven, + 188 => Self::ProtoOnehundredandeightyeight, + 189 => Self::ProtoOnehundredandeightynine, + 190 => Self::ProtoOnehundredandninety, + 191 => Self::ProtoOnehundredandninetyone, + 192 => Self::ProtoOnehundredandninetytwo, + 193 => Self::ProtoOnehundredandninetythree, + 194 => Self::ProtoOnehundredandninetyfour, + 195 => Self::ProtoOnehundredandninetyfive, + 196 => Self::ProtoOnehundredandninetysix, + 197 => Self::ProtoOnehundredandninetyseven, + 198 => Self::ProtoOnehundredandninetyeight, + 199 => Self::ProtoOnehundredandninetynine, + 200 => Self::ProtoTwohundred, + 201 => Self::ProtoTwohundredandone, + 202 => Self::ProtoTwohundredandtwo, + 203 => Self::ProtoTwohundredandthree, + 204 => Self::ProtoTwohundredandfour, + 205 => Self::ProtoTwohundredandfive, + 206 => Self::ProtoTwohundredandsix, + 207 => Self::ProtoTwohundredandseven, + 208 => Self::ProtoTwohundredandeight, + 209 => Self::ProtoTwohundredandnine, + 210 => Self::ProtoTwohundredandten, + 211 => Self::ProtoTwohundredandeleven, + 212 => Self::ProtoTwohundredandtwelve, + 213 => Self::ProtoTwohundredandthirteen, + 214 => Self::ProtoTwohundredandfourteen, + 215 => Self::ProtoTwohundredandfifteen, + 216 => Self::ProtoTwohundredandsixteen, + 217 => Self::ProtoTwohundredandseventeen, + 218 => Self::ProtoTwohundredandeighteen, + 219 => Self::ProtoTwohundredandnineteen, + 220 => Self::ProtoTwohundredandtwenty, + 221 => Self::ProtoTwohundredandtwentyone, + 222 => Self::ProtoTwohundredandtwentytwo, + 223 => Self::ProtoTwohundredandtwentythree, + 224 => Self::ProtoTwohundredandtwentyfour, + 225 => Self::ProtoTwohundredandtwentyfive, + 226 => Self::ProtoTwohundredandtwentysix, + 227 => Self::ProtoTwohundredandtwentyseven, + 228 => Self::ProtoTwohundredandtwentyeight, + 229 => Self::ProtoTwohundredandtwentynine, + 230 => Self::ProtoTwohundredandthirty, + 231 => Self::ProtoTwohundredandthirtyone, + 232 => Self::ProtoTwohundredandthirtytwo, + 233 => Self::ProtoTwohundredandthirtythree, + 234 => Self::ProtoTwohundredandthirtyfour, + 235 => Self::ProtoTwohundredandthirtyfive, + 236 => Self::ProtoTwohundredandthirtysix, + 237 => Self::ProtoTwohundredandthirtyseven, + 238 => Self::ProtoTwohundredandthirtyeight, + 239 => Self::ProtoTwohundredandthirtynine, + 240 => Self::ProtoTwohundredandfourty, + 241 => Self::ProtoTwohundredandfourtyone, + 242 => Self::ProtoTwohundredandfourtytwo, + 243 => Self::ProtoTwohundredandfourtythree, + 244 => Self::ProtoTwohundredandfourtyfour, + 245 => Self::ProtoTwohundredandfourtyfive, + 246 => Self::ProtoTwohundredandfourtysix, + 247 => Self::ProtoTwohundredandfourtyseven, + 248 => Self::ProtoTwohundredandfourtyeight, + 249 => Self::ProtoTwohundredandfourtynine, + 250 => Self::ProtoTwohundredandfifty, + 251 => Self::ProtoTwohundredandfiftyone, + 252 => Self::ProtoTwohundredandfiftytwo, + 253 => Self::ProtoTwohundredandfiftythree, + 254 => Self::ProtoTwohundredandfiftyfour, + 255 => Self::ProtoRaw, + 256 => Self::ProtoTwohundredandfiftysix, + 257 => Self::ProtoTwohundredandfiftyseven, + 258 => Self::ProtoTwohundredandfiftyeight, + 259 => Self::ProtoTwohundredandfiftynine, + 260 => Self::ProtoTwohundredandsixty, + 261 => Self::ProtoTwohundredandsixtyone, + 262 => Self::Mptcp, + 263 => Self::Max, + + q => todo!("could not serialize number {q} to enum SockProto"), + } + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Bool { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +unsafe impl wasmer::FromToNativeWasmType for Bool { + type Native = i32; + + fn to_native(self) -> Self::Native { + self as i32 + } + + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::False, + 1 => Self::True, + + q => todo!("could not serialize number {q} to enum Bool"), + } + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for OptionTimestamp { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Signal { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +unsafe impl wasmer::FromToNativeWasmType for Signal { + type Native = i32; + + fn to_native(self) -> Self::Native { + self as i32 + } + + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::Sighup, + 1 => Self::Sigint, + 2 => Self::Sigquit, + 3 => Self::Sigill, + 4 => Self::Sigtrap, + 5 => Self::Sigabrt, + 6 => Self::Sigbus, + 7 => Self::Sigfpe, + 8 => Self::Sigkill, + 9 => Self::Sigusr1, + 10 => Self::Sigsegv, + 11 => Self::Sigusr2, + 12 => Self::Sigpipe, + 13 => Self::Sigalrm, + 14 => Self::Sigterm, + 15 => Self::Sigchld, + 16 => Self::Sigcont, + 17 => Self::Sigstop, + 18 => Self::Sigtstp, + 19 => Self::Sigttin, + 20 => Self::Sigttou, + 21 => Self::Sigurg, + 22 => Self::Sigxcpu, + 23 => Self::Sigxfsz, + 24 => Self::Sigvtalrm, + 25 => Self::Sigprof, + 26 => Self::Sigwinch, + 27 => Self::Sigpoll, + 28 => Self::Sigpwr, + 29 => Self::Sigsys, + + q => todo!("could not serialize number {q} to enum Signal"), + } + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for AddrUnspec { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for AddrUnspecPort { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for CidrUnspec { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for HttpHandles { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for HttpStatus { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Timeout { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +unsafe impl wasmer::FromToNativeWasmType for Timeout { + type Native = i32; + + fn to_native(self) -> Self::Native { + self as i32 + } + + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::Read, + 1 => Self::Write, + 2 => Self::Connect, + 3 => Self::Accept, + + q => todo!("could not serialize number {q} to enum Timeout"), + } + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } +} diff --git a/lib/wasi-types/src/wasi/extra_manual.rs b/lib/wasi-types/src/wasi/extra_manual.rs new file mode 100644 index 00000000000..0c6456441a0 --- /dev/null +++ b/lib/wasi-types/src/wasi/extra_manual.rs @@ -0,0 +1,328 @@ +use crate::wasi::extra::*; + +impl Rights { + pub const fn all_socket() -> Self { + Self::from_bits_truncate( + Self::FD_FDSTAT_SET_FLAGS.bits() + | Self::FD_FILESTAT_GET.bits() + | Self::FD_READ.bits() + | Self::FD_WRITE.bits() + | Self::POLL_FD_READWRITE.bits() + | Self::SOCK_SHUTDOWN.bits() + | Self::SOCK_CONNECT.bits() + | Self::SOCK_LISTEN.bits() + | Self::SOCK_BIND.bits() + | Self::SOCK_ACCEPT.bits() + | Self::SOCK_RECV.bits() + | Self::SOCK_SEND.bits() + | Self::SOCK_ADDR_LOCAL.bits() + | Self::SOCK_ADDR_REMOTE.bits() + | Self::SOCK_RECV_FROM.bits() + | Self::SOCK_SEND_TO.bits(), + ) + } + + /// expects a single right, returns None if out of bounds or > 1 bit set + pub fn to_str(self) -> Option<&'static str> { + Some(match self { + Rights::FD_DATASYNC => "Rights::FD_DATASYNC", + Rights::FD_READ => "Rights::FD_READ", + Rights::FD_SEEK => "Rights::FD_SEEK", + Rights::FD_FDSTAT_SET_FLAGS => "Rights::FD_FDSTAT_SET_FLAGS", + Rights::FD_SYNC => "Rights::FD_SYNC", + Rights::FD_TELL => "Rights::FD_TELL", + Rights::FD_WRITE => "Rights::FD_WRITE", + Rights::FD_ADVISE => "Rights::FD_ADVISE", + Rights::FD_ALLOCATE => "Rights::FD_ALLOCATE", + Rights::PATH_CREATE_DIRECTORY => "Rights::PATH_CREATE_DIRECTORY", + Rights::PATH_CREATE_FILE => "Rights::PATH_CREATE_FILE", + Rights::PATH_LINK_SOURCE => "Rights::PATH_LINK_SOURCE", + Rights::PATH_LINK_TARGET => "Rights::PATH_LINK_TARGET", + Rights::PATH_OPEN => "Rights::PATH_OPEN", + Rights::FD_READDIR => "Rights::FD_READDIR", + Rights::PATH_READLINK => "Rights::PATH_READLINK", + Rights::PATH_RENAME_SOURCE => "Rights::PATH_RENAME_SOURCE", + Rights::PATH_RENAME_TARGET => "Rights::PATH_RENAME_TARGET", + Rights::PATH_FILESTAT_GET => "Rights::PATH_FILESTAT_GET", + Rights::PATH_FILESTAT_SET_SIZE => "Rights::PATH_FILESTAT_SET_SIZE", + Rights::PATH_FILESTAT_SET_TIMES => "Rights::PATH_FILESTAT_SET_TIMES", + Rights::FD_FILESTAT_GET => "Rights::FD_FILESTAT_GET", + Rights::FD_FILESTAT_SET_SIZE => "Rights::FD_FILESTAT_SET_SIZE", + Rights::FD_FILESTAT_SET_TIMES => "Rights::FD_FILESTAT_SET_TIMES", + Rights::PATH_SYMLINK => "Rights::PATH_SYMLINK", + Rights::PATH_REMOVE_DIRECTORY => "Rights::PATH_REMOVE_DIRECTORY", + Rights::PATH_UNLINK_FILE => "Rights::PATH_UNLINK_FILE", + Rights::POLL_FD_READWRITE => "Rights::POLL_FD_READWRITE", + Rights::SOCK_SHUTDOWN => "Rights::SOCK_SHUTDOWN", + Rights::SOCK_ACCEPT => "Rights::SOCK_ACCEPT", + Rights::SOCK_CONNECT => "Rights::SOCK_CONNECT", + Rights::SOCK_LISTEN => "Rights::SOCK_LISTEN", + Rights::SOCK_BIND => "Rights::SOCK_BIND", + Rights::SOCK_RECV => "Rights::SOCK_RECV", + Rights::SOCK_SEND => "Rights::SOCK_SEND", + Rights::SOCK_ADDR_LOCAL => "Rights::SOCK_ADDR_LOCAL", + Rights::SOCK_ADDR_REMOTE => "Rights::SOCK_ADDR_REMOTE", + Rights::SOCK_RECV_FROM => "Rights::SOCK_RECV_FROM", + Rights::SOCK_SEND_TO => "Rights::SOCK_SEND_TO", + _ => return None, + }) + } +} + +impl Default for Filestat { + fn default() -> Self { + Self { + st_dev: Default::default(), + st_ino: Default::default(), + st_filetype: Filetype::Unknown, + st_nlink: 1, + st_size: Default::default(), + st_atim: Default::default(), + st_mtim: Default::default(), + st_ctim: Default::default(), + } + } +} + +/// Workaround implementation because `wit-bindgen` does not generate +/// type aliases, but instead creates the same filetype in each module +/// for `use` statements in the `.wit` file. +impl From for Snapshot0Clockid { + fn from(other: Clockid) -> Self { + match other { + Clockid::Realtime => Self::Realtime, + Clockid::Monotonic => Self::Monotonic, + } + } +} + +impl From for Clockid { + fn from(other: Snapshot0Clockid) -> Self { + match other { + Snapshot0Clockid::Realtime => Self::Realtime, + Snapshot0Clockid::Monotonic => Self::Monotonic, + Snapshot0Clockid::ProcessCputimeId => todo!("not implemented for now"), + Snapshot0Clockid::ThreadCputimeId => todo!("not implemented for now"), + } + } +} + +impl From for SubscriptionClock { + fn from(other: Snapshot0SubscriptionClock) -> Self { + // TODO: this removes Snapshot0SubscriptionClock::identifier, I don't + // think this is how it should be + Self { + clock_id: Clockid::from(other.id), + timeout: other.timeout, + precision: other.precision, + flags: other.flags, + } + } +} + +impl From for SubscriptionEnum { + fn from(other: Snapshot0SubscriptionEnum) -> Self { + match other { + Snapshot0SubscriptionEnum::Clock(d) => Self::Clock(SubscriptionClock::from(d)), + Snapshot0SubscriptionEnum::Read(d) => Self::Read(d), + Snapshot0SubscriptionEnum::Write(d) => Self::Write(d), + } + } +} + +impl From for Subscription { + fn from(other: Snapshot0Subscription) -> Self { + Self { + userdata: other.userdata, + data: SubscriptionEnum::from(other.data), + } + } +} + +impl std::fmt::Display for BusDataFormat { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self) + } +} + +impl std::fmt::Display for Sockoption { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let s = match *self { + Self::Noop => "Sockoption::Noop", + Self::ReusePort => "Sockoption::ReusePort", + Self::ReuseAddr => "Sockoption::ReuseAddr", + Self::NoDelay => "Sockoption::NoDelay", + Self::DontRoute => "Sockoption::DontRoute", + Self::OnlyV6 => "Sockoption::OnlyV6", + Self::Broadcast => "Sockoption::Broadcast", + Self::MulticastLoopV4 => "Sockoption::MulticastLoopV4", + Self::MulticastLoopV6 => "Sockoption::MulticastLoopV6", + Self::Promiscuous => "Sockoption::Promiscuous", + Self::Listening => "Sockoption::Listening", + Self::LastError => "Sockoption::LastError", + Self::KeepAlive => "Sockoption::KeepAlive", + Self::Linger => "Sockoption::Linger", + Self::OobInline => "Sockoption::OobInline", + Self::RecvBufSize => "Sockoption::RecvBufSize", + Self::SendBufSize => "Sockoption::SendBufSize", + Self::RecvLowat => "Sockoption::RecvLowat", + Self::SendLowat => "Sockoption::SendLowat", + Self::RecvTimeout => "Sockoption::RecvTimeout", + Self::SendTimeout => "Sockoption::SendTimeout", + Self::ConnectTimeout => "Sockoption::ConnectTimeout", + Self::AcceptTimeout => "Sockoption::AcceptTimeout", + Self::Ttl => "Sockoption::Ttl", + Self::MulticastTtlV4 => "Sockoption::MulticastTtlV4", + Self::Type => "Sockoption::Type", + Self::Proto => "Sockoption::Proto", + }; + write!(f, "{}", s) + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wasmer::FromToNativeWasmType for Fdflags { + type Native = i32; + + fn to_native(self) -> Self::Native { + self.bits() as i32 + } + fn from_native(n: Self::Native) -> Self { + Self::from_bits_truncate(n as u16) + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wasmer::FromToNativeWasmType for Rights { + type Native = i64; + + fn to_native(self) -> Self::Native { + self.bits() as i64 + } + + fn from_native(n: Self::Native) -> Self { + Self::from_bits_truncate(n as u64) + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wasmer::FromToNativeWasmType for Fstflags { + type Native = i32; + + fn to_native(self) -> Self::Native { + self.bits() as i32 + } + fn from_native(n: Self::Native) -> Self { + Self::from_bits_truncate(n as u16) + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wasmer::FromToNativeWasmType for Oflags { + type Native = i32; + + fn to_native(self) -> Self::Native { + self.bits() as i32 + } + fn from_native(n: Self::Native) -> Self { + Self::from_bits_truncate(n as u16) + } + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + +impl PartialEq for OptionCid { + fn eq(&self, other: &Self) -> bool { + self.tag == other.tag && self.cid == other.cid + } +} + +impl Eq for OptionCid {} + +#[derive(Copy, Clone)] +pub enum PrestatEnum { + Dir { pr_name_len: u32 }, +} + +impl PrestatEnum { + pub fn untagged(self) -> PrestatU { + match self { + PrestatEnum::Dir { pr_name_len } => PrestatU { + dir: PrestatUDir { pr_name_len }, + }, + } + } +} + +impl Prestat { + #[allow(clippy::trivially_copy_pass_by_ref)] + pub fn tagged(&self) -> Option { + match self.pr_type { + Preopentype::Dir => Some(PrestatEnum::Dir { + pr_name_len: self.u.dir.pr_name_len, + }), + } + } +} + +unsafe impl wasmer::ValueType for Prestat { + fn zero_padding_bytes(&self, bytes: &mut [core::mem::MaybeUninit]) { + macro_rules! field { + ($($f:tt)*) => { + &self.$($f)* as *const _ as usize - self as *const _ as usize + }; + } + macro_rules! field_end { + ($($f:tt)*) => { + field!($($f)*) + core::mem::size_of_val(&self.$($f)*) + }; + } + macro_rules! zero { + ($start:expr, $end:expr) => { + for i in $start..$end { + bytes[i] = core::mem::MaybeUninit::new(0); + } + }; + } + self.pr_type + .zero_padding_bytes(&mut bytes[field!(pr_type)..field_end!(pr_type)]); + zero!(field_end!(pr_type), field!(u)); + match self.pr_type { + Preopentype::Dir => { + self.u + .dir + .zero_padding_bytes(&mut bytes[field!(u.dir)..field_end!(u.dir)]); + zero!(field_end!(u.dir), field_end!(u)); + } + } + zero!(field_end!(u), core::mem::size_of_val(self)); + } +} + +impl SubscriptionEnum { + pub fn raw_tag(&self) -> Eventtype { + match self { + SubscriptionEnum::Clock(_) => Eventtype::Clock, + SubscriptionEnum::Read(_) => Eventtype::FdRead, + SubscriptionEnum::Write(_) => Eventtype::FdWrite, + } + } +} diff --git a/lib/wasi-types/src/wasi/mod.rs b/lib/wasi-types/src/wasi/mod.rs new file mode 100644 index 00000000000..f0247f05cdf --- /dev/null +++ b/lib/wasi-types/src/wasi/mod.rs @@ -0,0 +1,4 @@ +pub(crate) mod extra; +pub(crate) mod extra_manual; +pub use extra::*; +pub use extra_manual::*; diff --git a/lib/wasi-types/wasi-types-generator-extra/.gitignore b/lib/wasi-types/wasi-types-generator-extra/.gitignore new file mode 100644 index 00000000000..9f970225adb --- /dev/null +++ b/lib/wasi-types/wasi-types-generator-extra/.gitignore @@ -0,0 +1 @@ +target/ \ No newline at end of file diff --git a/lib/wasi-types/wasi-types-generator-extra/Cargo.toml b/lib/wasi-types/wasi-types-generator-extra/Cargo.toml new file mode 100644 index 00000000000..fab10cc5c33 --- /dev/null +++ b/lib/wasi-types/wasi-types-generator-extra/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "wasi-types-generator-extra" +version = "0.1.0" +edition = "2021" +license = "MIT" +description = "Generator for wasi-types" + +[dependencies] +convert_case = "0.5.0" + +[dependencies.wit-parser] +default-features = false +package = "wasmer-wit-parser" +version = "0.1.1" \ No newline at end of file diff --git a/lib/wasi-types/wasi-types-generator-extra/src/main.rs b/lib/wasi-types/wasi-types-generator-extra/src/main.rs new file mode 100644 index 00000000000..70dded6e090 --- /dev/null +++ b/lib/wasi-types/wasi-types-generator-extra/src/main.rs @@ -0,0 +1,152 @@ +//! This generator is run when regenerate.sh is executed and fixes a couple +//! of issues that wit-bindgen currently doesn't support. +//! +//! Eventually this functionality should be upstreamed into wit-bindgen, +//! see issue [#3177](https://github.com/wasmerio/wasmer/issues/3177). + +use convert_case::{Case, Casing}; +use wit_parser::TypeDefKind; + +const WIT_1: &str = include_str!("../../wit-clean/output.wit"); +const BINDINGS_RS: &str = include_str!("../../src/wasi/bindings.rs"); + +fn replace_in_string(s: &str, id: &str, ty: &str) -> String { + let parts = s.split(&format!("impl {id} {{")).collect::>(); + if parts.len() == 1 { + return s.to_string(); + } + let replaced = parts[1].replacen( + "from_bits_preserve(bits: u8)", + &format!("from_bits_preserve(bits: {ty})"), + 1, + ); + format!("{}impl {id} {{ {replaced}", parts[0]) +} + +fn main() { + let mut bindings_rs = BINDINGS_RS + .replace("#[allow(clippy::all)]", "") + .replace("pub mod output {", "") + .replace("mod output {", "") + .replace("pub struct Rights: u8 {", "pub struct Rights: u64 {") + .replace("pub struct Lookup: u8 {", "pub struct Lookup: u32 {") + .replace("pub struct Oflags: u8 {", "pub struct Oflags: u16 {") + .replace( + "pub struct Subclockflags: u8 {", + "pub struct Subclockflags: u16 {", + ) + .replace( + "pub struct Eventrwflags: u8 {", + "pub struct Eventrwflags: u16 {", + ) + .replace("pub struct Fstflags: u8 {", "pub struct Fstflags: u16 {") + .replace("pub struct Fdflags: u8 {", "pub struct Fdflags: u16 {"); + + bindings_rs = replace_in_string(&bindings_rs, "Oflags", "u16"); + bindings_rs = replace_in_string(&bindings_rs, "Subclockflags", "u16"); + bindings_rs = replace_in_string(&bindings_rs, "Eventrwflags", "u16"); + bindings_rs = replace_in_string(&bindings_rs, "Fstflags", "u16"); + bindings_rs = replace_in_string(&bindings_rs, "Fdflags", "u16"); + bindings_rs = replace_in_string(&bindings_rs, "Lookup", "u32"); + bindings_rs = replace_in_string(&bindings_rs, "Rights", "u64"); + + let mut bindings_rs = bindings_rs.lines().collect::>(); + bindings_rs.pop(); + let bindings_rs = bindings_rs.join("\n"); + + let target_path = env!("CARGO_MANIFEST_DIR"); + let path = std::path::Path::new(&target_path) + .parent() + .unwrap() + .join("src") + .join("wasi") + .join("extra.rs"); + let result = wit_parser::Interface::parse("output.wit", WIT_1).unwrap(); + let mut contents = format!( + " + use std::mem::MaybeUninit; + use wasmer::ValueType; + + {bindings_rs} + + " + ) + .replace(" ", ""); + + println!("output to {}", path.display()); + + let excluded_from_impl_valuetype = ["Prestat"]; + + for (_, i) in result.types.iter() { + match i.kind { + | TypeDefKind::Record(_) + | TypeDefKind::Flags(_) + | TypeDefKind::Tuple(_) + | TypeDefKind::Variant(_) + | TypeDefKind::Enum(_) + | TypeDefKind::Option(_) + | TypeDefKind::Expected(_) + | TypeDefKind::Union(_) + | TypeDefKind::List(_) + | TypeDefKind::Future(_) + | TypeDefKind::Stream(_) + // | TypeDefKind::Type(_) + => { + let name = i.name.clone().unwrap_or_default().to_case(Case::Pascal); + if excluded_from_impl_valuetype.iter().any(|s| *s == name.as_str()) { + continue; + } + contents.push_str(&format!(" + // TODO: if necessary, must be implemented in wit-bindgen + unsafe impl ValueType for {name} {{ + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {{ }} + }} + + ").replace(" ", "")) + }, + _ => { } + } + + let name = i.name.clone().unwrap_or_default().to_case(Case::Pascal); + + if let wit_parser::TypeDefKind::Enum(e) = &i.kind { + contents.push_str( + &format!( + " + unsafe impl wasmer::FromToNativeWasmType for {name} {{ + type Native = i32; + + fn to_native(self) -> Self::Native {{ + self as i32 + }} + + fn from_native(n: Self::Native) -> Self {{ + match n {{\n" + ) + .replace(" ", ""), + ); + + for (i, case) in e.cases.iter().enumerate() { + contents.push_str(&format!( + " {i} => Self::{},\n", + case.name.to_case(Case::Pascal) + )); + } + contents.push_str( + &format!( + " + q => todo!(\"could not serialize number {{q}} to enum {name}\"), + }} + }} + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool {{ false }} + }} + " + ) + .replace(" ", ""), + ); + } + } + std::fs::write(path, contents).unwrap(); +} diff --git a/lib/wasi-types/wit-clean/output.wit b/lib/wasi-types/wit-clean/output.wit new file mode 100644 index 00000000000..33c26abbdbe --- /dev/null +++ b/lib/wasi-types/wit-clean/output.wit @@ -0,0 +1,1750 @@ +// Extracted from: +// https://github.com/WebAssembly/WASI/blob/main/phases/old/snapshot_0/witx/typenames.witx +// https://github.com/WebAssembly/wasi-io/blob/main/standard/io/witx/typenames.witx + +/// Type names used by low-level WASI interfaces. + +/// An array size. +/// +/// Note: This is similar to `size_t` in POSIX. +// TODO: This is defined as `usize` in the original witx file. Should verify that this type is good as it is defined here +type size = u32 + +/// Non-negative file size or length of a region within a file. +type filesize = u64 + +/// Timestamp in nanoseconds. +type timestamp = u64 + +/// A file descriptor handle. +// TODO: this is of type `handle` in the witx file +type fd = u32 + +/// A reference to the offset of a directory entry. +type dircookie = u64 + +// In an `fd_readdir` call, this value signifies the start of the directory. +// TODO: this cannot be represented in .wit files as of today +// (@witx const $dircookie $start 0) + +/// The type for the `dirent::d-namlen` field of `dirent` struct. +type dirnamlen = u32 + +/// File serial number that is unique within its file system. +type inode = u64 + +/// Identifier for a device containing a file system. Can be used in combination +/// with `inode` to uniquely identify a file or directory in the filesystem. +type device = u64 + +type linkcount = u64 +type snapshot0-linkcount = u32 + +type tid = u32 +type pid = u32 + +/// Identifiers for clocks, snapshot0 version. +enum snapshot0-clockid { + // TODO: wit appears to not have support for enum tag types + //(@witx tag u32) + + /// The clock measuring real time. Time value zero corresponds with + /// 1970-01-01T00:00:00Z. + realtime, + /// The store-wide monotonic clock, which is defined as a clock measuring + /// real time, whose value cannot be adjusted and which cannot have negative + /// clock jumps. The epoch of this clock is undefined. The absolute time + /// value of this clock therefore has no meaning. + monotonic, + /// The CPU-time clock associated with the current process. + process-cputime-id, + /// The CPU-time clock associated with the current thread. + thread-cputime-id, +} + +/// Identifiers for clocks. +enum clockid { + // TODO: wit appears to not have support for enum tag types + //(@witx tag u32) + + /// The clock measuring real time. Time value zero corresponds with + /// 1970-01-01T00:00:00Z. + realtime, + /// The store-wide monotonic clock, which is defined as a clock measuring + /// real time, whose value cannot be adjusted and which cannot have negative + /// clock jumps. The epoch of this clock is undefined. The absolute time + /// value of this clock therefore has no meaning. + monotonic, +} + +/// Error codes returned by functions. +/// Not all of these error codes are returned by the functions provided by this +/// API; some are used in higher-level library layers, and others are provided +/// merely for alignment with POSIX. +enum errno { + // TODO: wit appears to not have support for enum tag types + //(@witx tag u16) + + /// No error occurred. System call completed successfully. + success, + /// Argument list too long. + toobig, + /// Permission denied. + access, + /// Address in use. + addrinuse, + /// Address not available. + addrnotavail, + /// Address family not supported. + afnosupport, + /// Resource unavailable, or operation would block. + again, + /// Connection already in progress. + already, + /// Bad file descriptor. + badf, + /// Bad message. + badmsg, + /// Device or resource busy. + busy, + /// Operation canceled. + canceled, + /// No child processes. + child, + /// Connection aborted. + connaborted, + /// Connection refused. + connrefused, + /// Connection reset. + connreset, + /// Resource deadlock would occur. + deadlk, + /// Destination address required. + destaddrreq, + /// Mathematics argument out of domain of function. + dom, + /// Reserved. + dquot, + /// File exists. + exist, + /// Bad address. + fault, + /// File too large. + fbig, + /// Host is unreachable. + hostunreach, + /// Identifier removed. + idrm, + /// Illegal byte sequence. + ilseq, + /// Operation in progress. + inprogress, + /// Interrupted function. + intr, + /// Invalid argument. + inval, + /// I/O error. + io, + /// Socket is connected. + isconn, + /// Is a directory. + isdir, + /// Too many levels of symbolic links. + loop, + /// File descriptor value too large. + mfile, + /// Too many links. + mlink, + /// Message too large. + msgsize, + /// Reserved. + multihop, + /// Filename too long. + nametoolong, + /// Network is down. + netdown, + /// Connection aborted by network. + netreset, + /// Network unreachable. + netunreach, + /// Too many files open in system. + nfile, + /// No buffer space available. + nobufs, + /// No such device. + nodev, + /// No such file or directory. + noent, + /// Executable file format error. + noexec, + /// No locks available. + nolck, + /// Reserved. + nolink, + /// Not enough space. + nomem, + /// No message of the desired type. + nomsg, + /// Protocol not available. + noprotoopt, + /// No space left on device. + nospc, + /// Function not supported. + nosys, + /// The socket is not connected. + notconn, + /// Not a directory or a symbolic link to a directory. + notdir, + /// Directory not empty. + notempty, + /// State not recoverable. + notrecoverable, + /// Not a socket. + notsock, + /// Not supported, or operation not supported on socket. + notsup, + /// Inappropriate I/O control operation. + notty, + /// No such device or address. + nxio, + /// Value too large to be stored in data type. + overflow, + /// Previous owner died. + ownerdead, + /// Operation not permitted. + perm, + /// Broken pipe. + pipe, + /// Protocol error. + proto, + /// Protocol not supported. + protonosupport, + /// Protocol wrong type for socket. + prototype, + /// Result too large. + range, + /// Read-only file system. + rofs, + /// Invalid seek. + spipe, + /// No such process. + srch, + /// Reserved. + stale, + /// Connection timed out. + timedout, + /// Text file busy. + txtbsy, + /// Cross-device link. + xdev, + /// Extension: Capabilities insufficient. + notcapable, +} + +enum bus-errno { + // TODO: wit appears to not have support for enum tag types + //(@witx tag u32) + + /// No error occurred. Call completed successfully. + success, + /// Failed during serialization + ser, + /// Failed during deserialization + des, + /// Invalid WAPM process + wapm, + /// Failed to fetch the WAPM process + fetch, + /// Failed to compile the WAPM process + compile, + /// Invalid ABI + abi, + /// Call was aborted + aborted, + /// Bad handle + badhandle, + /// Invalid topic + topic, + /// Invalid callback + badcb, + /// Call is unsupported + unsupported, + /// Bad request + badrequest, + /// Access denied + denied, + /// Internal error has occured + internal, + /// Memory allocation failed + alloc, + /// Invocation has failed + invoke, + /// Already consumed + consumed, + /// Memory access violation + memviolation, + /// Some other unhandled error. If you see this, it's probably a bug. + unknown, +} + +/// File descriptor rights, determining which actions may be performed. +flags rights { + // TODO: wit doesnt appear to support repr + // flags (@witx repr u64) + + /// The right to invoke `fd_datasync`. + /// + /// If `rights::path_open` is set, includes the right to invoke + /// `path_open` with `fdflags::dsync`. + fd-datasync, + /// The right to invoke `fd_read` and `sock_recv`. + /// + /// If `rights::fd_seek` is set, includes the right to invoke `fd_pread`. + fd-read, + /// The right to invoke `fd_seek`. This flag implies `rights::fd_tell`. + fd-seek, + /// The right to invoke `fd_fdstat_set_flags`. + fd-fdstat-set-flags, + /// The right to invoke `fd_sync`. + /// + /// If `rights::path_open` is set, includes the right to invoke + /// `path_open` with `fdflags::rsync` and `fdflags::dsync`. + fd-sync, + /// The right to invoke `fd_seek` in such a way that the file offset + /// remains unaltered (i.e., `whence::cur` with offset zero), or to + /// invoke `fd_tell`. + fd-tell, + /// The right to invoke `fd_write` and `sock_send`. + /// If `rights::fd_seek` is set, includes the right to invoke `fd_pwrite`. + fd-write, + /// The right to invoke `fd_advise`. + fd-advise, + /// The right to invoke `fd_allocate`. + fd-allocate, + /// The right to invoke `path_create_directory`. + path-create-directory, + /// If `rights::path_open` is set, the right to invoke `path_open` with `oflags::creat`. + path-create-file, + /// The right to invoke `path_link` with the file descriptor as the + /// source directory. + path-link-source, + /// The right to invoke `path_link` with the file descriptor as the + /// target directory. + path-link-target, + /// The right to invoke `path_open`. + path-open, + /// The right to invoke `fd_readdir`. + fd-readdir, + /// The right to invoke `path_readlink`. + path-readlink, + /// The right to invoke `path_rename` with the file descriptor as the source directory. + path-rename-source, + /// The right to invoke `path_rename` with the file descriptor as the target directory. + path-rename-target, + /// The right to invoke `path_filestat_get`. + path-filestat-get, + /// The right to change a file's size (there is no `path_filestat_set_size`). + /// If `rights::path_open` is set, includes the right to invoke `path_open` with `oflags::trunc`. + path-filestat-set-size, + /// The right to invoke `path_filestat_set_times`. + path-filestat-set-times, + /// The right to invoke `fd_filestat_get`. + fd-filestat-get, + /// The right to invoke `fd_filestat_set_size`. + fd-filestat-set-size, + /// The right to invoke `fd_filestat_set_times`. + fd-filestat-set-times, + /// The right to invoke `path_symlink`. + path-symlink, + /// The right to invoke `path_remove_directory`. + path-remove-directory, + /// The right to invoke `path_unlink_file`. + path-unlink-file, + /// If `rights::fd_read` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_read`. + /// If `rights::fd_write` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_write`. + poll-fd-readwrite, + /// The right to invoke `sock_shutdown`. + sock-shutdown, + + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + sock-accept, + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + sock-connect, + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + sock-listen, + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + sock-bind, + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + sock-recv, + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + sock-send, + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + sock-addr-local, + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + sock-addr-remote, + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + sock-recv-from, + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + sock-send-to, +} + +/// The type of a file descriptor or file. +enum filetype { + // TODO: wit appears to not have support for enum tag types + //(@witx tag u8) + + /// The type of the file descriptor or file is unknown or is different from any of the other types specified. + unknown, + /// The file descriptor or file refers to a block device inode. + block-device, + /// The file descriptor or file refers to a character device inode. + character-device, + /// The file descriptor or file refers to a directory inode. + directory, + /// The file descriptor or file refers to a regular file inode. + regular-file, + /// The file descriptor or file refers to a datagram socket. + socket-dgram, + /// The file descriptor or file refers to a byte-stream socket. + socket-stream, + /// The file refers to a symbolic link inode. + symbolic-link, + /// The file descriptor or file refers to a FIFO. + fifo, +} + +/// A directory entry, snapshot0 version. +record snapshot0-dirent { + /// The offset of the next directory entry stored in this directory. + d-next: dircookie, + /// The serial number of the file referred to by this directory entry. + d-ino: inode, + /// The length of the name of the directory entry. + d-namlen: dirnamlen, + /// The type of the file referred to by this directory entry. + d-type: filetype, +} + +/// A directory entry. +record dirent { + /// The offset of the next directory entry stored in this directory. + d-next: dircookie, + /// The serial number of the file referred to by this directory entry. + d-ino: inode, + /// The type of the file referred to by this directory entry. + d-type: filetype, + /// The length of the name of the directory entry. + d-namlen: dirnamlen, +} + +/// File or memory access pattern advisory information. +enum advice { + // TODO: wit appears to not have support for enum tag types + //enum (@witx tag u8) + + /// The application has no advice to give on its behavior with respect to the specified data. + normal, + /// The application expects to access the specified data sequentially from lower offsets to higher offsets. + sequential, + /// The application expects to access the specified data in a random order. + random, + /// The application expects to access the specified data in the near future. + willneed, + /// The application expects that it will not access the specified data in the near future. + dontneed, + /// The application expects to access the specified data once and then not reuse it thereafter. + noreuse, +} + +/// File descriptor flags. +flags fdflags { + // TODO: wit appears to not have support for flags repr + //(@witx repr u16) + + /// Append mode: Data written to the file is always appended to the file's end. + append, + /// Write according to synchronized I/O data integrity completion. Only the data stored in the file is synchronized. + dsync, + /// Non-blocking mode. + nonblock, + /// Synchronized read I/O operations. + rsync, + /// Write according to synchronized I/O file integrity completion. In + /// addition to synchronizing the data stored in the file, the implementation + /// may also synchronously update the file's metadata. + sync, +} + +/// File descriptor attributes. +record fdstat { + /// File type. + fs-filetype: filetype, + /// File descriptor flags. + fs-flags: fdflags, + /// Rights that apply to this file descriptor. + fs-rights-base: rights, + /// Maximum set of rights that may be installed on new file descriptors that + /// are created through this file descriptor, e.g., through `path_open`. + fs-rights-inheriting: rights, +} + +/// Which file time attributes to adjust. +/// TODO: wit appears to not have support for flags repr +/// (@witx repr u16) +flags fstflags { + /// Adjust the last data access timestamp to the value stored in `filestat::atim`. + set-atim, + /// Adjust the last data access timestamp to the time of clock `clockid::realtime`. + set-atim-now, + /// Adjust the last data modification timestamp to the value stored in `filestat::mtim`. + set-mtim, + /// Adjust the last data modification timestamp to the time of clock `clockid::realtime`. + set-mtim-now, +} + +/// Flags determining the method of how paths are resolved. +/// TODO: wit appears to not have support for flags repr +/// (@witx repr u32) +flags lookup { + /// As long as the resolved path corresponds to a symbolic link, it is expanded. + symlink-follow, +} + +/// Open flags used by `path_open`. +/// TODO: wit appears to not have support for flags repr +/// (@witx repr u16) +flags oflags { + /// Create file if it does not exist. + create, + /// Fail if not a directory. + directory, + /// Fail if file already exists. + excl, + /// Truncate file to size 0. + trunc, +} + +/// User-provided value that may be attached to objects that is retained when +/// extracted from the implementation. +type userdata = u64 + +/// Type of a subscription to an event or its occurrence. +enum eventtype { + // TODO: wit appears to not have support for enum tag types + //(@witx tag u8) + + /// The time value of clock `subscription_clock::id` has + /// reached timestamp `subscription_clock::timeout`. + clock, + /// File descriptor `subscription_fd_readwrite::fd` has data + /// available for reading. This event always triggers for regular files. + fd-read, + /// File descriptor `subscription_fd_readwrite::fd` has capacity + /// available for writing. This event always triggers for regular files. + fd-write, +} + +/// Flags determining how to interpret the timestamp provided in +/// `subscription-clock::timeout`. +flags subclockflags { + // TODO: wit appears to not have support for flags repr + //@witx repr u16) + /// If set, treat the timestamp provided in + /// `subscription-clock::timeout` as an absolute timestamp of clock + /// `subscription-clock::id`. If clear, treat the timestamp + /// provided in `subscription-clock::timeout` relative to the + /// current time value of clock `subscription-clock::id`. + subscription-clock-abstime, +} + +/// The contents of a `subscription` when type is `eventtype::clock`. +record snapshot0-subscription-clock { + /// The user-defined unique identifier of the clock. + identifier: userdata, + /// The clock against which to compare the timestamp. + id: snapshot0-clockid, + /// The absolute or relative timestamp. + timeout: timestamp, + /// The amount of time that the implementation may wait additionally + /// to coalesce with other events. + precision: timestamp, + /// Flags specifying whether the timeout is absolute or relative + %flags: subclockflags +} + +/// The contents of a `subscription` when type is `eventtype::clock`. +record subscription-clock { + /// The clock against which to compare the timestamp. + clock-id: clockid, + /// The absolute or relative timestamp. + timeout: timestamp, + /// The amount of time that the implementation may wait additionally + /// to coalesce with other events. + precision: timestamp, + /// Flags specifying whether the timeout is absolute or relative + %flags: subclockflags, +} + +/// Identifiers for preopened capabilities. +enum preopentype { + // TODO: wit appears to not have support for enum tag types + //(@witx tag u8) + + /// A pre-opened directory. + dir, +} + +/// The state of the file descriptor subscribed to with +/// `eventtype::fd_read` or `eventtype::fd_write`. +flags eventrwflags { + // TODO: wit appears to not have support for flags repr + //@witx repr u16) + + /// The peer of this socket has closed or disconnected. + fd-readwrite-hangup, +} + +/// The contents of an `event` for the `eventtype::fd_read` and +/// `eventtype::fd_write` variants +record event-fd-readwrite { + /// The number of bytes available for reading or writing. + nbytes: filesize, + /// The state of the file descriptor. + %flags: eventrwflags, +} + +/// An event that occurred. +record event { + /// User-provided value that got attached to `subscription::userdata`. + userdata: userdata, + /// If non-zero, an error that occurred while processing the subscription request. + error: errno, + /// The type of the event that occurred, and the contents of the event + data: event-enum +} + +/// The contents of an `event`. +variant event-enum { + // TODO: wit appears to not have support for tag type + //(@witx tag $eventtype) + fd-read(event-fd-readwrite), + fd-write(event-fd-readwrite), + clock, +} + + +/// An event that occurred. +record snapshot0-event { + /// User-provided value that got attached to `subscription::userdata`. + userdata: userdata, + /// If non-zero, an error that occurred while processing the subscription request. + error: errno, + /// The type of event that occured + %type: eventtype, + /// The contents of the event, if it is an `eventtype::fd_read` or + /// `eventtype::fd_write`. `eventtype::clock` events ignore this field. + fd-readwrite: event-fd-readwrite, +} + +/// The contents of a `subscription`, snapshot0 version. +variant snapshot0-subscription-enum { + // TODO: wit appears to have no support for tag types + //(@witx tag $eventtype) + clock(snapshot0-subscription-clock), + read(subscription-fs-readwrite), + write(subscription-fs-readwrite), +} + +/// The contents of a `subscription`. +variant subscription-enum { + // TODO: wit appears to have no support for tag types + //(@witx tag $eventtype) + clock(subscription-clock), + read(subscription-fs-readwrite), + write(subscription-fs-readwrite), +} + +/// The contents of a `subscription` when the variant is +/// `eventtype::fd_read` or `eventtype::fd_write`. +record subscription-fs-readwrite { + /// The file descriptor on which to wait for it to become ready for reading or writing. + file-descriptor: fd, +} + +record snapshot0-subscription { + userdata: userdata, + data: snapshot0-subscription-enum, +} + +record subscription { + userdata: userdata, + data: subscription-enum, +} + +enum socktype { + dgram, + %stream, + raw, + seqpacket, +} + +enum sockstatus { + opening, + opened, + closed, + failed, +} + +enum sockoption { + noop, + reuse-port, + reuse-addr, + no-delay, + dont-route, + only-v6, + broadcast, + multicast-loop-v4, + multicast-loop-v6, + promiscuous, + listening, + last-error, + keep-alive, + linger, + oob-inline, + recv-buf-size, + send-buf-size, + recv-lowat, + send-lowat, + recv-timeout, + send-timeout, + connect-timeout, + accept-timeout, + ttl, + multicast-ttl-v4, + %type, + proto, +} + +enum streamsecurity { + unencrypted, + any-encryption, + classic-encryption, + double-encryption, +} + +enum addressfamily { + unspec, + inet4, + inet6, + unix, +} + +record snapshot0-filestat { + st-dev: device, + st-ino: inode, + st-filetype: filetype, + st-nlink: snapshot0-linkcount, + st-size: filesize, + st-atim: timestamp, + st-mtim: timestamp, + st-ctim: timestamp, +} + +record filestat { + st-dev: device, + st-ino: inode, + st-filetype: filetype, + st-nlink: linkcount, + st-size: filesize, + st-atim: timestamp, + st-mtim: timestamp, + st-ctim: timestamp, +} + +enum snapshot0-whence { + cur, + end, + set, +} + +enum whence { + set, + cur, + end, +} + +record tty { + cols: u32, + rows: u32, + width: u32, + height: u32, + stdin-tty: bool, + stdout-tty: bool, + stderr-tty: bool, + echo: bool, + line-buffered: bool, +} + +enum bus-data-format { + raw, + bincode, + message-pack, + json, + yaml, + xml, + rkyv, +} + +enum bus-event-type { + noop, + exit, + call, + result, + fault, + close, +} + +type bid = u32 + +type cid = u32 + +/// __wasi_option_t +enum option-tag { + none, + some, +} + +record option-bid { + tag: option-tag, + bid: bid +} + +record option-cid { + tag: option-tag, + cid: cid +} + +record option-fd { + tag: option-tag, + fd: fd +} + +record bus-handles { + bid: bid, + stdin: option-fd, + stdout: option-fd, + stderr: option-fd, +} + +type exit-code = u32 + +record bus-event-exit { + bid: bid, + rval: exit-code, +} + +record bus-event-fault { + cid: cid, + err: bus-errno, +} + +record bus-event-close { + cid: cid, +} + +type event-fd-flags = u16 + +record prestat-u-dir { + pr-name-len: u32, +} + +record prestat-u { + dir: prestat-u-dir, +} + +record prestat { + pr-type: preopentype, + u: prestat-u, +} + +type file-delta = s64 + +type lookup-flags = u32 + +type count = u32 + +record pipe-handles { + pipe: fd, + other: fd, +} + +enum stdio-mode { + reserved, // = 0, stdio-mode starts at 1 + piped, + inherit, + null, + log, +} + +enum sock-proto { + ip, + icmp, + igmp, + proto-three, + ipip, + proto-five, + tcp, + proto-seven, + egp, + proto-nine, + proto-ten, + proto-eleven, + pup, + proto-thirteen, + proto-fourteen, + proto-fifteen, + proto-sixteen, + udp, + proto-eighteen, + proto-nineteen, + proto-twenty, + proto-twentyone, + idp, + proto-twentythree, + proto-twentyfour, + proto-twentyfive, + proto-twentysix, + proto-twentyseven, + proto-twentyeight, + proto-tp, + proto-thirty, + proto-thirtyone, + proto-thirtytwo, + dccp, + proto-thirtyfour, + proto-thirtyfive, + proto-thirtysix, + proto-thirtyseven, + proto-thirtyeight, + proto-thirtynine, + proto-fourty, + ipv6, + proto-fourtytwo, + routing, + fragment, + proto-fourtyfive, + rsvp, + gre, + proto-fourtyeight, + proto-fourtynine, + esp, + ah, + proto-fiftytwo, + proto-fiftythree, + proto-fiftyfour, + proto-fiftyfive, + proto-fiftysix, + proto-fiftyseven, + icmpv6, + none, + dstopts, + proto-sixtyone, + proto-sixtytwo, + proto-sixtythree, + proto-sixtyfour, + proto-sixtyfive, + proto-sixtysix, + proto-sixtyseven, + proto-sixtyeight, + proto-sixtynine, + proto-seventy, + proto-seventyone, + proto-seventytwo, + proto-seventythree, + proto-seventyfour, + proto-seventyfive, + proto-seventysix, + proto-seventyseven, + proto-seventyeight, + proto-seventynine, + proto-eighty, + proto-eightyone, + proto-eightytwo, + proto-eightythree, + proto-eightyfour, + proto-eightyfive, + proto-eightysix, + proto-eightyseven, + proto-eightyeight, + proto-eightynine, + proto-ninety, + proto-ninetyone, + mtp, + proto-ninetythree, + beetph, + proto-ninetyfive, + proto-ninetysix, + proto-nineetyseven, + encap, + proto-ninetynine, + proto-onehundred, + proto-onehundredandone, + proto-onehundredandtwo, + pim, + proto-onehundredandfour, + proto-onehundredandfive, + proto-onehundredandsix, + proto-onehundredandseven, + comp, + proto-onehundredandnine, + proto-onehundredandten, + proto-onehundredandeleven, + proto-onehundredandtwelve, + proto-onehundredandthirteen, + proto-onehundredandfourteen, + proto-onehundredandfifteen, + proto-onehundredandsixteen, + proto-onehundredandseventeen, + proto-onehundredandeighteen, + proto-onehundredandnineteen, + proto-onehundredandtwenty, + proto-onehundredandtwentyone, + proto-onehundredandtwentytwo, + proto-onehundredandtwentythree, + proto-onehundredandtwentyfour, + proto-onehundredandtwentyfive, + proto-onehundredandtwentysix, + proto-onehundredandtwentyseven, + proto-onehundredandtwentyeight, + proto-onehundredandtwentynine, + proto-onehundredandthirty, + proto-onehundredandthirtyone, + sctp, + proto-onehundredandthirtythree, + proto-onehundredandthirtyfour, + mh, + udplite, + mpls, + proto-onehundredandthirtyeight, + proto-onehundredandthirtynine, + proto-onehundredandfourty, + proto-onehundredandfourtyone, + proto-onehundredandfourtytwo, + ethernet, + proto-onehundredandfourtyfour, + proto-onehundredandfourtyfive, + proto-onehundredandfourtysix, + proto-onehundredandfourtyseven, + proto-onehundredandfourtyeight, + proto-onehundredandfourtynine, + proto-onehundredandfifty, + proto-onehundredandfiftyone, + proto-onehundredandfiftytwo, + proto-onehundredandfiftythree, + proto-onehundredandfiftyfour, + proto-onehundredandfiftyfive, + proto-onehundredandfiftysix, + proto-onehundredandfiftyseven, + proto-onehundredandfiftyeight, + proto-onehundredandfiftynine, + proto-onehundredandsixty, + proto-onehundredandsixtyone, + proto-onehundredandsixtytwo, + proto-onehundredandsixtythree, + proto-onehundredandsixtyfour, + proto-onehundredandsixtyfive, + proto-onehundredandsixtysix, + proto-onehundredandsixtyseven, + proto-onehundredandsixtyeight, + proto-onehundredandsixtynine, + proto-onehundredandseventy, + proto-onehundredandseventyone, + proto-onehundredandseventytwo, + proto-onehundredandseventythree, + proto-onehundredandseventyfour, + proto-onehundredandseventyfive, + proto-onehundredandseventysix, + proto-onehundredandseventyseven, + proto-onehundredandseventyeight, + proto-onehundredandseventynine, + proto-onehundredandeighty, + proto-onehundredandeightyone, + proto-onehundredandeightytwo, + proto-onehundredandeightythree, + proto-onehundredandeightyfour, + proto-onehundredandeightyfive, + proto-onehundredandeightysix, + proto-onehundredandeightyseven, + proto-onehundredandeightyeight, + proto-onehundredandeightynine, + proto-onehundredandninety, + proto-onehundredandninetyone, + proto-onehundredandninetytwo, + proto-onehundredandninetythree, + proto-onehundredandninetyfour, + proto-onehundredandninetyfive, + proto-onehundredandninetysix, + proto-onehundredandninetyseven, + proto-onehundredandninetyeight, + proto-onehundredandninetynine, + proto-twohundred, + proto-twohundredandone, + proto-twohundredandtwo, + proto-twohundredandthree, + proto-twohundredandfour, + proto-twohundredandfive, + proto-twohundredandsix, + proto-twohundredandseven, + proto-twohundredandeight, + proto-twohundredandnine, + proto-twohundredandten, + proto-twohundredandeleven, + proto-twohundredandtwelve, + proto-twohundredandthirteen, + proto-twohundredandfourteen, + proto-twohundredandfifteen, + proto-twohundredandsixteen, + proto-twohundredandseventeen, + proto-twohundredandeighteen, + proto-twohundredandnineteen, + proto-twohundredandtwenty, + proto-twohundredandtwentyone, + proto-twohundredandtwentytwo, + proto-twohundredandtwentythree, + proto-twohundredandtwentyfour, + proto-twohundredandtwentyfive, + proto-twohundredandtwentysix, + proto-twohundredandtwentyseven, + proto-twohundredandtwentyeight, + proto-twohundredandtwentynine, + proto-twohundredandthirty, + proto-twohundredandthirtyone, + proto-twohundredandthirtytwo, + proto-twohundredandthirtythree, + proto-twohundredandthirtyfour, + proto-twohundredandthirtyfive, + proto-twohundredandthirtysix, + proto-twohundredandthirtyseven, + proto-twohundredandthirtyeight, + proto-twohundredandthirtynine, + proto-twohundredandfourty, + proto-twohundredandfourtyone, + proto-twohundredandfourtytwo, + proto-twohundredandfourtythree, + proto-twohundredandfourtyfour, + proto-twohundredandfourtyfive, + proto-twohundredandfourtysix, + proto-twohundredandfourtyseven, + proto-twohundredandfourtyeight, + proto-twohundredandfourtynine, + proto-twohundredandfifty, + proto-twohundredandfiftyone, + proto-twohundredandfiftytwo, + proto-twohundredandfiftythree, + proto-twohundredandfiftyfour, + proto-raw, + proto-twohundredandfiftysix, + proto-twohundredandfiftyseven, + proto-twohundredandfiftyeight, + proto-twohundredandfiftynine, + proto-twohundredandsixty, + proto-twohundredandsixtyone, + mptcp, + max, +} + +enum %bool { + %false, + %true, +} + +record option-timestamp { + tag: option-tag, + u: timestamp, +} + +enum signal { + sighup, + sigint, + sigquit, + sigill, + sigtrap, + sigabrt, + sigbus, + sigfpe, + sigkill, + sigusr1, + sigsegv, + sigusr2, + sigpipe, + sigalrm, + sigterm, + sigchld, + sigcont, + sigstop, + sigtstp, + sigttin, + sigttou, + sigurg, + sigxcpu, + sigxfsz, + sigvtalrm, + sigprof, + sigwinch, + sigpoll, + sigpwr, + sigsys, +} + +record addr-unspec { + n0: u8, +} + +record addr-unspec-port { + port: u16, + addr: addr-unspec, +} + +record cidr-unspec { + addr: addr-unspec, + prefix: u8, +} + +record http-handles { + req: fd, + res: fd, + hdr: fd, +} + +record http-status { + ok: %bool, + redirect: %bool, + size: filesize, + status: u16, +} + +type ri-flags = u16 + +type ro-flags = u16 + +type sd-flags = u8 + +type si-flags = u16 + +enum timeout { + read, + write, + connect, + accept, +}// WASI Preview. This is an evolution of the API that WASI initially +// launched with. +// +// Some content here is derived from [CloudABI](https://github.com/NuxiNL/cloudabi). + +/// This API predated the convention of naming modules with a `wasi_unstable_` +/// prefix and a version number. It is preserved here for compatibility, but +/// we shouldn't follow this pattern in new APIs. +/* +(module $wasi_unstable + /// Linear memory to be accessed by WASI functions that need it. + (import "memory" (memory)) + + /// Read command-line argument data. + /// The size of the array should match that returned by `args_sizes_get`. + /// Each argument is expected to be `\0` terminated. + (@interface func (export "args_get") + (param $argv (@witx pointer (@witx pointer u8))) + (param $argv_buf (@witx pointer u8)) + (result $error (expected (error $errno))) + ) + + /// Return command-line argument data sizes. + (@interface func (export "args_sizes_get") + /// Returns the number of arguments and the size of the argument string + /// data, or an error. + (result $error (expected (tuple $size $size) (error $errno))) + ) + + /// Read environment variable data. + /// The sizes of the buffers should match that returned by `environ_sizes_get`. + /// Key/value pairs are expected to be joined with `=`s, and terminated with `\0`s. + (@interface func (export "environ_get") + (param $environ (@witx pointer (@witx pointer u8))) + (param $environ_buf (@witx pointer u8)) + (result $error (expected (error $errno))) + ) + + /// Return environment variable data sizes. + (@interface func (export "environ_sizes_get") + /// Returns the number of environment variable arguments and the size of the + /// environment variable data. + (result $error (expected (tuple $size $size) (error $errno))) + ) + + /// Return the resolution of a clock. + /// Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks, return + /// `errno::inval`. + /// Note: This is similar to `clock_getres` in POSIX. + (@interface func (export "clock_res_get") + /// The clock for which to return the resolution. + (param $id $clockid) + /// The resolution of the clock, or an error if one happened. + (result $error (expected $timestamp (error $errno))) + ) + /// Return the time value of a clock. + /// Note: This is similar to `clock_gettime` in POSIX. + (@interface func (export "clock_time_get") + /// The clock for which to return the time. + (param $id $clockid) + /// The maximum lag (exclusive) that the returned time value may have, compared to its actual value. + (param $precision $timestamp) + /// The time value of the clock. + (result $error (expected $timestamp (error $errno))) + ) + + /// Provide file advisory information on a file descriptor. + /// Note: This is similar to `posix_fadvise` in POSIX. + (@interface func (export "fd_advise") + (param $fd $fd) + /// The offset within the file to which the advisory applies. + (param $offset $filesize) + /// The length of the region to which the advisory applies. + (param $len $filesize) + /// The advice. + (param $advice $advice) + (result $error (expected (error $errno))) + ) + + /// Force the allocation of space in a file. + /// Note: This is similar to `posix_fallocate` in POSIX. + (@interface func (export "fd_allocate") + (param $fd $fd) + /// The offset at which to start the allocation. + (param $offset $filesize) + /// The length of the area that is allocated. + (param $len $filesize) + (result $error (expected (error $errno))) + ) + + /// Close a file descriptor. + /// Note: This is similar to `close` in POSIX. + (@interface func (export "fd_close") + (param $fd $fd) + (result $error (expected (error $errno))) + ) + + /// Synchronize the data of a file to disk. + /// Note: This is similar to `fdatasync` in POSIX. + (@interface func (export "fd_datasync") + (param $fd $fd) + (result $error (expected (error $errno))) + ) + + /// Get the attributes of a file descriptor. + /// Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well as additional fields. + (@interface func (export "fd_fdstat_get") + (param $fd $fd) + /// The buffer where the file descriptor's attributes are stored. + (result $error (expected $fdstat (error $errno))) + ) + + /// Adjust the flags associated with a file descriptor. + /// Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX. + (@interface func (export "fd_fdstat_set_flags") + (param $fd $fd) + /// The desired values of the file descriptor flags. + (param $flags $fdflags) + (result $error (expected (error $errno))) + ) + + /// Adjust the rights associated with a file descriptor. + /// This can only be used to remove rights, and returns `errno::notcapable` if called in a way that would attempt to add rights + (@interface func (export "fd_fdstat_set_rights") + (param $fd $fd) + /// The desired rights of the file descriptor. + (param $fs_rights_base $rights) + (param $fs_rights_inheriting $rights) + (result $error (expected (error $errno))) + ) + + /// Return the attributes of an open file. + (@interface func (export "fd_filestat_get") + (param $fd $fd) + /// The buffer where the file's attributes are stored. + (result $error (expected $filestat (error $errno))) + ) + + /// Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros. + /// Note: This is similar to `ftruncate` in POSIX. + (@interface func (export "fd_filestat_set_size") + (param $fd $fd) + /// The desired file size. + (param $size $filesize) + (result $error (expected (error $errno))) + ) + + /// Adjust the timestamps of an open file or directory. + /// Note: This is similar to `futimens` in POSIX. + (@interface func (export "fd_filestat_set_times") + (param $fd $fd) + /// The desired values of the data access timestamp. + (param $atim $timestamp) + /// The desired values of the data modification timestamp. + (param $mtim $timestamp) + /// A bitmask indicating which timestamps to adjust. + (param $fst_flags $fstflags) + (result $error (expected (error $errno))) + ) + + /// Read from a file descriptor, without using and updating the file descriptor's offset. + /// Note: This is similar to `preadv` in POSIX. + (@interface func (export "fd_pread") + (param $fd $fd) + /// List of scatter/gather vectors in which to store data. + (param $iovs $iovec_array) + /// The offset within the file at which to read. + (param $offset $filesize) + /// The number of bytes read. + (result $error (expected $size (error $errno))) + ) + + /// Return a description of the given preopened file descriptor. + (@interface func (export "fd_prestat_get") + (param $fd $fd) + /// The buffer where the description is stored. + (result $error (expected $prestat (error $errno))) + ) + + /// Return a description of the given preopened file descriptor. + (@interface func (export "fd_prestat_dir_name") + (param $fd $fd) + /// A buffer into which to write the preopened directory name. + (param $path (@witx pointer u8)) + (param $path_len $size) + (result $error (expected (error $errno))) + ) + + /// Write to a file descriptor, without using and updating the file descriptor's offset. + /// Note: This is similar to `pwritev` in POSIX. + (@interface func (export "fd_pwrite") + (param $fd $fd) + /// List of scatter/gather vectors from which to retrieve data. + (param $iovs $ciovec_array) + /// The offset within the file at which to write. + (param $offset $filesize) + /// The number of bytes written. + (result $error (expected $size (error $errno))) + ) + + /// Read from a file descriptor. + /// Note: This is similar to `readv` in POSIX. + (@interface func (export "fd_read") + (param $fd $fd) + /// List of scatter/gather vectors to which to store data. + (param $iovs $iovec_array) + /// The number of bytes read. + (result $error (expected $size (error $errno))) + ) + + /// Read directory entries from a directory. + /// When successful, the contents of the output buffer consist of a sequence of + /// directory entries. Each directory entry consists of a `dirent` object, + /// followed by `dirent::d_namlen` bytes holding the name of the directory + /// entry. + /// + /// This function fills the output buffer as much as possible, potentially + /// truncating the last directory entry. This allows the caller to grow its + /// read buffer size in case it's too small to fit a single large directory + /// entry, or skip the oversized directory entry. + (@interface func (export "fd_readdir") + (param $fd $fd) + /// The buffer where directory entries are stored + (param $buf (@witx pointer u8)) + (param $buf_len $size) + /// The location within the directory to start reading + (param $cookie $dircookie) + /// The number of bytes stored in the read buffer. If less than the size of the read buffer, the end of the directory has been reached. + (result $error (expected $size (error $errno))) + ) + + /// Atomically replace a file descriptor by renumbering another file descriptor. + // + /// Due to the strong focus on thread safety, this environment does not provide + /// a mechanism to duplicate or renumber a file descriptor to an arbitrary + /// number, like `dup2()`. This would be prone to race conditions, as an actual + /// file descriptor with the same number could be allocated by a different + /// thread at the same time. + // + /// This function provides a way to atomically renumber file descriptors, which + /// would disappear if `dup2()` were to be removed entirely. + (@interface func (export "fd_renumber") + (param $fd $fd) + /// The file descriptor to overwrite. + (param $to $fd) + (result $error (expected (error $errno))) + ) + + /// Move the offset of a file descriptor. + /// Note: This is similar to `lseek` in POSIX. + (@interface func (export "fd_seek") + (param $fd $fd) + /// The number of bytes to move. + (param $offset $filedelta) + /// The base from which the offset is relative. + (param $whence $whence) + /// The new offset of the file descriptor, relative to the start of the file. + (result $error (expected $filesize (error $errno))) + ) + + /// Synchronize the data and metadata of a file to disk. + /// Note: This is similar to `fsync` in POSIX. + (@interface func (export "fd_sync") + (param $fd $fd) + (result $error (expected (error $errno))) + ) + + /// Return the current offset of a file descriptor. + /// Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX. + (@interface func (export "fd_tell") + (param $fd $fd) + /// The current offset of the file descriptor, relative to the start of the file. + (result $error (expected $filesize (error $errno))) + ) + + /// Write to a file descriptor. + /// Note: This is similar to `writev` in POSIX. + (@interface func (export "fd_write") + (param $fd $fd) + /// List of scatter/gather vectors from which to retrieve data. + (param $iovs $ciovec_array) + (result $error (expected $size (error $errno))) + ) + + /// Create a directory. + /// Note: This is similar to `mkdirat` in POSIX. + (@interface func (export "path_create_directory") + (param $fd $fd) + /// The path at which to create the directory. + (param $path string) + (result $error (expected (error $errno))) + ) + + /// Return the attributes of a file or directory. + /// Note: This is similar to `stat` in POSIX. + (@interface func (export "path_filestat_get") + (param $fd $fd) + /// Flags determining the method of how the path is resolved. + (param $flags $lookupflags) + /// The path of the file or directory to inspect. + (param $path string) + /// The buffer where the file's attributes are stored. + (result $error (expected $filestat (error $errno))) + ) + + /// Adjust the timestamps of a file or directory. + /// Note: This is similar to `utimensat` in POSIX. + (@interface func (export "path_filestat_set_times") + (param $fd $fd) + /// Flags determining the method of how the path is resolved. + (param $flags $lookupflags) + /// The path of the file or directory to operate on. + (param $path string) + /// The desired values of the data access timestamp. + (param $atim $timestamp) + /// The desired values of the data modification timestamp. + (param $mtim $timestamp) + /// A bitmask indicating which timestamps to adjust. + (param $fst_flags $fstflags) + (result $error (expected (error $errno))) + ) + + /// Create a hard link. + /// Note: This is similar to `linkat` in POSIX. + (@interface func (export "path_link") + (param $old_fd $fd) + /// Flags determining the method of how the path is resolved. + (param $old_flags $lookupflags) + /// The source path from which to link. + (param $old_path string) + /// The working directory at which the resolution of the new path starts. + (param $new_fd $fd) + /// The destination path at which to create the hard link. + (param $new_path string) + (result $error (expected (error $errno))) + ) + + /// Open a file or directory. + // + /// The returned file descriptor is not guaranteed to be the lowest-numbered + /// file descriptor not currently open; it is randomized to prevent + /// applications from depending on making assumptions about indexes, since this + /// is error-prone in multi-threaded contexts. The returned file descriptor is + /// guaranteed to be less than 2**31. + // + /// Note: This is similar to `openat` in POSIX. + (@interface func (export "path_open") + (param $fd $fd) + /// Flags determining the method of how the path is resolved. + (param $dirflags $lookupflags) + /// The relative path of the file or directory to open, relative to the + /// `path_open::fd` directory. + (param $path string) + /// The method by which to open the file. + (param $oflags $oflags) + /// The initial rights of the newly created file descriptor. The + /// implementation is allowed to return a file descriptor with fewer rights + /// than specified, if and only if those rights do not apply to the type of + /// file being opened. + // + /// The *base* rights are rights that will apply to operations using the file + /// descriptor itself, while the *inheriting* rights are rights that apply to + /// file descriptors derived from it. + (param $fs_rights_base $rights) + (param $fs_rights_inheriting $rights) + (param $fdflags $fdflags) + /// The file descriptor of the file that has been opened. + (result $error (expected $fd (error $errno))) + ) + + /// Read the contents of a symbolic link. + /// Note: This is similar to `readlinkat` in POSIX. + (@interface func (export "path_readlink") + (param $fd $fd) + /// The path of the symbolic link from which to read. + (param $path string) + /// The buffer to which to write the contents of the symbolic link. + (param $buf (@witx pointer u8)) + (param $buf_len $size) + /// The number of bytes placed in the buffer. + (result $error (expected $size (error $errno))) + ) + + /// Remove a directory. + /// Return `errno::notempty` if the directory is not empty. + /// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. + (@interface func (export "path_remove_directory") + (param $fd $fd) + /// The path to a directory to remove. + (param $path string) + (result $error (expected (error $errno))) + ) + + /// Rename a file or directory. + /// Note: This is similar to `renameat` in POSIX. + (@interface func (export "path_rename") + (param $fd $fd) + /// The source path of the file or directory to rename. + (param $old_path string) + /// The working directory at which the resolution of the new path starts. + (param $new_fd $fd) + /// The destination path to which to rename the file or directory. + (param $new_path string) + (result $error (expected (error $errno))) + ) + + /// Create a symbolic link. + /// Note: This is similar to `symlinkat` in POSIX. + (@interface func (export "path_symlink") + /// The contents of the symbolic link. + (param $old_path string) + (param $fd $fd) + /// The destination path at which to create the symbolic link. + (param $new_path string) + (result $error (expected (error $errno))) + ) + + + /// Unlink a file. + /// Return `errno::isdir` if the path refers to a directory. + /// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. + (@interface func (export "path_unlink_file") + (param $fd $fd) + /// The path to a file to unlink. + (param $path string) + (result $error (expected (error $errno))) + ) + + /// Concurrently poll for the occurrence of a set of events. + (@interface func (export "poll_oneoff") + /// The events to which to subscribe. + (param $in (@witx const_pointer $subscription)) + /// The events that have occurred. + (param $out (@witx pointer $event)) + /// Both the number of subscriptions and events. + (param $nsubscriptions $size) + /// The number of events stored. + (result $error (expected $size (error $errno))) + ) + + /// Terminate the process normally. An exit code of 0 indicates successful + /// termination of the program. The meanings of other values is dependent on + /// the environment. + (@interface func (export "proc_exit") + /// The exit code returned by the process. + (param $rval $exitcode) + (@witx noreturn) + ) + + /// Send a signal to the process of the calling thread. + /// Note: This is similar to `raise` in POSIX. + (@interface func (export "proc_raise") + /// The signal condition to trigger. + (param $sig $signal) + (result $error (expected (error $errno))) + ) + + /// Temporarily yield execution of the calling thread. + /// Note: This is similar to `sched_yield` in POSIX. + (@interface func (export "sched_yield") + (result $error (expected (error $errno))) + ) + + /// Write high-quality random data into a buffer. + /// This function blocks when the implementation is unable to immediately + /// provide sufficient high-quality random data. + /// This function may execute slowly, so when large mounts of random data are + /// required, it's advisable to use this function to seed a pseudo-random + /// number generator, rather than to provide the random data directly. + (@interface func (export "random_get") + /// The buffer to fill with random data. + (param $buf (@witx pointer u8)) + (param $buf_len $size) + (result $error (expected (error $errno))) + ) + + /// Receive a message from a socket. + /// Note: This is similar to `recv` in POSIX, though it also supports reading + /// the data into multiple buffers in the manner of `readv`. + (@interface func (export "sock_recv") + (param $fd $fd) + /// List of scatter/gather vectors to which to store data. + (param $ri_data $iovec_array) + /// Message flags. + (param $ri_flags $riflags) + /// Number of bytes stored in ri_data and message flags. + (result $error (expected (tuple $size $roflags) (error $errno))) + ) + + /// Send a message on a socket. + /// Note: This is similar to `send` in POSIX, though it also supports writing + /// the data from multiple buffers in the manner of `writev`. + (@interface func (export "sock_send") + (param $fd $fd) + /// List of scatter/gather vectors to which to retrieve data + (param $si_data $ciovec_array) + /// Message flags. + (param $si_flags $siflags) + /// Number of bytes transmitted. + (result $error (expected $size (error $errno))) + ) + + /// Shut down socket send and receive channels. + /// Note: This is similar to `shutdown` in POSIX. + (@interface func (export "sock_shutdown") + (param $fd $fd) + /// Which channels on the socket to shut down. + (param $how $sdflags) + (result $error (expected (error $errno))) + ) +) +*/ \ No newline at end of file diff --git a/lib/wasi-types/wit-clean/typenames.wit b/lib/wasi-types/wit-clean/typenames.wit new file mode 100644 index 00000000000..a4bf2927b39 --- /dev/null +++ b/lib/wasi-types/wit-clean/typenames.wit @@ -0,0 +1,1239 @@ +// Extracted from: +// https://github.com/WebAssembly/WASI/blob/main/phases/old/snapshot_0/witx/typenames.witx +// https://github.com/WebAssembly/wasi-io/blob/main/standard/io/witx/typenames.witx + +/// Type names used by low-level WASI interfaces. + +/// An array size. +/// +/// Note: This is similar to `size_t` in POSIX. +// TODO: This is defined as `usize` in the original witx file. Should verify that this type is good as it is defined here +type size = u32 + +/// Non-negative file size or length of a region within a file. +type filesize = u64 + +/// Timestamp in nanoseconds. +type timestamp = u64 + +/// A file descriptor handle. +// TODO: this is of type `handle` in the witx file +type fd = u32 + +/// A reference to the offset of a directory entry. +type dircookie = u64 + +// In an `fd_readdir` call, this value signifies the start of the directory. +// TODO: this cannot be represented in .wit files as of today +// (@witx const $dircookie $start 0) + +/// The type for the `dirent::d-namlen` field of `dirent` struct. +type dirnamlen = u32 + +/// File serial number that is unique within its file system. +type inode = u64 + +/// Identifier for a device containing a file system. Can be used in combination +/// with `inode` to uniquely identify a file or directory in the filesystem. +type device = u64 + +type linkcount = u64 +type snapshot0-linkcount = u32 + +type tid = u32 +type pid = u32 + +/// Identifiers for clocks, snapshot0 version. +enum snapshot0-clockid { + // TODO: wit appears to not have support for enum tag types + //(@witx tag u32) + + /// The clock measuring real time. Time value zero corresponds with + /// 1970-01-01T00:00:00Z. + realtime, + /// The store-wide monotonic clock, which is defined as a clock measuring + /// real time, whose value cannot be adjusted and which cannot have negative + /// clock jumps. The epoch of this clock is undefined. The absolute time + /// value of this clock therefore has no meaning. + monotonic, + /// The CPU-time clock associated with the current process. + process-cputime-id, + /// The CPU-time clock associated with the current thread. + thread-cputime-id, +} + +/// Identifiers for clocks. +enum clockid { + // TODO: wit appears to not have support for enum tag types + //(@witx tag u32) + + /// The clock measuring real time. Time value zero corresponds with + /// 1970-01-01T00:00:00Z. + realtime, + /// The store-wide monotonic clock, which is defined as a clock measuring + /// real time, whose value cannot be adjusted and which cannot have negative + /// clock jumps. The epoch of this clock is undefined. The absolute time + /// value of this clock therefore has no meaning. + monotonic, +} + +/// Error codes returned by functions. +/// Not all of these error codes are returned by the functions provided by this +/// API; some are used in higher-level library layers, and others are provided +/// merely for alignment with POSIX. +enum errno { + // TODO: wit appears to not have support for enum tag types + //(@witx tag u16) + + /// No error occurred. System call completed successfully. + success, + /// Argument list too long. + toobig, + /// Permission denied. + access, + /// Address in use. + addrinuse, + /// Address not available. + addrnotavail, + /// Address family not supported. + afnosupport, + /// Resource unavailable, or operation would block. + again, + /// Connection already in progress. + already, + /// Bad file descriptor. + badf, + /// Bad message. + badmsg, + /// Device or resource busy. + busy, + /// Operation canceled. + canceled, + /// No child processes. + child, + /// Connection aborted. + connaborted, + /// Connection refused. + connrefused, + /// Connection reset. + connreset, + /// Resource deadlock would occur. + deadlk, + /// Destination address required. + destaddrreq, + /// Mathematics argument out of domain of function. + dom, + /// Reserved. + dquot, + /// File exists. + exist, + /// Bad address. + fault, + /// File too large. + fbig, + /// Host is unreachable. + hostunreach, + /// Identifier removed. + idrm, + /// Illegal byte sequence. + ilseq, + /// Operation in progress. + inprogress, + /// Interrupted function. + intr, + /// Invalid argument. + inval, + /// I/O error. + io, + /// Socket is connected. + isconn, + /// Is a directory. + isdir, + /// Too many levels of symbolic links. + loop, + /// File descriptor value too large. + mfile, + /// Too many links. + mlink, + /// Message too large. + msgsize, + /// Reserved. + multihop, + /// Filename too long. + nametoolong, + /// Network is down. + netdown, + /// Connection aborted by network. + netreset, + /// Network unreachable. + netunreach, + /// Too many files open in system. + nfile, + /// No buffer space available. + nobufs, + /// No such device. + nodev, + /// No such file or directory. + noent, + /// Executable file format error. + noexec, + /// No locks available. + nolck, + /// Reserved. + nolink, + /// Not enough space. + nomem, + /// No message of the desired type. + nomsg, + /// Protocol not available. + noprotoopt, + /// No space left on device. + nospc, + /// Function not supported. + nosys, + /// The socket is not connected. + notconn, + /// Not a directory or a symbolic link to a directory. + notdir, + /// Directory not empty. + notempty, + /// State not recoverable. + notrecoverable, + /// Not a socket. + notsock, + /// Not supported, or operation not supported on socket. + notsup, + /// Inappropriate I/O control operation. + notty, + /// No such device or address. + nxio, + /// Value too large to be stored in data type. + overflow, + /// Previous owner died. + ownerdead, + /// Operation not permitted. + perm, + /// Broken pipe. + pipe, + /// Protocol error. + proto, + /// Protocol not supported. + protonosupport, + /// Protocol wrong type for socket. + prototype, + /// Result too large. + range, + /// Read-only file system. + rofs, + /// Invalid seek. + spipe, + /// No such process. + srch, + /// Reserved. + stale, + /// Connection timed out. + timedout, + /// Text file busy. + txtbsy, + /// Cross-device link. + xdev, + /// Extension: Capabilities insufficient. + notcapable, +} + +enum bus-errno { + // TODO: wit appears to not have support for enum tag types + //(@witx tag u32) + + /// No error occurred. Call completed successfully. + success, + /// Failed during serialization + ser, + /// Failed during deserialization + des, + /// Invalid WAPM process + wapm, + /// Failed to fetch the WAPM process + fetch, + /// Failed to compile the WAPM process + compile, + /// Invalid ABI + abi, + /// Call was aborted + aborted, + /// Bad handle + badhandle, + /// Invalid topic + topic, + /// Invalid callback + badcb, + /// Call is unsupported + unsupported, + /// Bad request + badrequest, + /// Access denied + denied, + /// Internal error has occured + internal, + /// Memory allocation failed + alloc, + /// Invocation has failed + invoke, + /// Already consumed + consumed, + /// Memory access violation + memviolation, + /// Some other unhandled error. If you see this, it's probably a bug. + unknown, +} + +/// File descriptor rights, determining which actions may be performed. +flags rights { + // TODO: wit doesnt appear to support repr + // flags (@witx repr u64) + + /// The right to invoke `fd_datasync`. + /// + /// If `rights::path_open` is set, includes the right to invoke + /// `path_open` with `fdflags::dsync`. + fd-datasync, + /// The right to invoke `fd_read` and `sock_recv`. + /// + /// If `rights::fd_seek` is set, includes the right to invoke `fd_pread`. + fd-read, + /// The right to invoke `fd_seek`. This flag implies `rights::fd_tell`. + fd-seek, + /// The right to invoke `fd_fdstat_set_flags`. + fd-fdstat-set-flags, + /// The right to invoke `fd_sync`. + /// + /// If `rights::path_open` is set, includes the right to invoke + /// `path_open` with `fdflags::rsync` and `fdflags::dsync`. + fd-sync, + /// The right to invoke `fd_seek` in such a way that the file offset + /// remains unaltered (i.e., `whence::cur` with offset zero), or to + /// invoke `fd_tell`. + fd-tell, + /// The right to invoke `fd_write` and `sock_send`. + /// If `rights::fd_seek` is set, includes the right to invoke `fd_pwrite`. + fd-write, + /// The right to invoke `fd_advise`. + fd-advise, + /// The right to invoke `fd_allocate`. + fd-allocate, + /// The right to invoke `path_create_directory`. + path-create-directory, + /// If `rights::path_open` is set, the right to invoke `path_open` with `oflags::creat`. + path-create-file, + /// The right to invoke `path_link` with the file descriptor as the + /// source directory. + path-link-source, + /// The right to invoke `path_link` with the file descriptor as the + /// target directory. + path-link-target, + /// The right to invoke `path_open`. + path-open, + /// The right to invoke `fd_readdir`. + fd-readdir, + /// The right to invoke `path_readlink`. + path-readlink, + /// The right to invoke `path_rename` with the file descriptor as the source directory. + path-rename-source, + /// The right to invoke `path_rename` with the file descriptor as the target directory. + path-rename-target, + /// The right to invoke `path_filestat_get`. + path-filestat-get, + /// The right to change a file's size (there is no `path_filestat_set_size`). + /// If `rights::path_open` is set, includes the right to invoke `path_open` with `oflags::trunc`. + path-filestat-set-size, + /// The right to invoke `path_filestat_set_times`. + path-filestat-set-times, + /// The right to invoke `fd_filestat_get`. + fd-filestat-get, + /// The right to invoke `fd_filestat_set_size`. + fd-filestat-set-size, + /// The right to invoke `fd_filestat_set_times`. + fd-filestat-set-times, + /// The right to invoke `path_symlink`. + path-symlink, + /// The right to invoke `path_remove_directory`. + path-remove-directory, + /// The right to invoke `path_unlink_file`. + path-unlink-file, + /// If `rights::fd_read` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_read`. + /// If `rights::fd_write` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_write`. + poll-fd-readwrite, + /// The right to invoke `sock_shutdown`. + sock-shutdown, + + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + sock-accept, + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + sock-connect, + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + sock-listen, + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + sock-bind, + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + sock-recv, + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + sock-send, + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + sock-addr-local, + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + sock-addr-remote, + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + sock-recv-from, + /// TODO: Found in wasmer-wasi-types rust project, but not in wasi-snapshot0 + sock-send-to, +} + +/// The type of a file descriptor or file. +enum filetype { + // TODO: wit appears to not have support for enum tag types + //(@witx tag u8) + + /// The type of the file descriptor or file is unknown or is different from any of the other types specified. + unknown, + /// The file descriptor or file refers to a block device inode. + block-device, + /// The file descriptor or file refers to a character device inode. + character-device, + /// The file descriptor or file refers to a directory inode. + directory, + /// The file descriptor or file refers to a regular file inode. + regular-file, + /// The file descriptor or file refers to a datagram socket. + socket-dgram, + /// The file descriptor or file refers to a byte-stream socket. + socket-stream, + /// The file refers to a symbolic link inode. + symbolic-link, + /// The file descriptor or file refers to a FIFO. + fifo, +} + +/// A directory entry, snapshot0 version. +record snapshot0-dirent { + /// The offset of the next directory entry stored in this directory. + d-next: dircookie, + /// The serial number of the file referred to by this directory entry. + d-ino: inode, + /// The length of the name of the directory entry. + d-namlen: dirnamlen, + /// The type of the file referred to by this directory entry. + d-type: filetype, +} + +/// A directory entry. +record dirent { + /// The offset of the next directory entry stored in this directory. + d-next: dircookie, + /// The serial number of the file referred to by this directory entry. + d-ino: inode, + /// The type of the file referred to by this directory entry. + d-type: filetype, + /// The length of the name of the directory entry. + d-namlen: dirnamlen, +} + +/// File or memory access pattern advisory information. +enum advice { + // TODO: wit appears to not have support for enum tag types + //enum (@witx tag u8) + + /// The application has no advice to give on its behavior with respect to the specified data. + normal, + /// The application expects to access the specified data sequentially from lower offsets to higher offsets. + sequential, + /// The application expects to access the specified data in a random order. + random, + /// The application expects to access the specified data in the near future. + willneed, + /// The application expects that it will not access the specified data in the near future. + dontneed, + /// The application expects to access the specified data once and then not reuse it thereafter. + noreuse, +} + +/// File descriptor flags. +flags fdflags { + // TODO: wit appears to not have support for flags repr + //(@witx repr u16) + + /// Append mode: Data written to the file is always appended to the file's end. + append, + /// Write according to synchronized I/O data integrity completion. Only the data stored in the file is synchronized. + dsync, + /// Non-blocking mode. + nonblock, + /// Synchronized read I/O operations. + rsync, + /// Write according to synchronized I/O file integrity completion. In + /// addition to synchronizing the data stored in the file, the implementation + /// may also synchronously update the file's metadata. + sync, +} + +/// File descriptor attributes. +record fdstat { + /// File type. + fs-filetype: filetype, + /// File descriptor flags. + fs-flags: fdflags, + /// Rights that apply to this file descriptor. + fs-rights-base: rights, + /// Maximum set of rights that may be installed on new file descriptors that + /// are created through this file descriptor, e.g., through `path_open`. + fs-rights-inheriting: rights, +} + +/// Which file time attributes to adjust. +/// TODO: wit appears to not have support for flags repr +/// (@witx repr u16) +flags fstflags { + /// Adjust the last data access timestamp to the value stored in `filestat::atim`. + set-atim, + /// Adjust the last data access timestamp to the time of clock `clockid::realtime`. + set-atim-now, + /// Adjust the last data modification timestamp to the value stored in `filestat::mtim`. + set-mtim, + /// Adjust the last data modification timestamp to the time of clock `clockid::realtime`. + set-mtim-now, +} + +/// Flags determining the method of how paths are resolved. +/// TODO: wit appears to not have support for flags repr +/// (@witx repr u32) +flags lookup { + /// As long as the resolved path corresponds to a symbolic link, it is expanded. + symlink-follow, +} + +/// Open flags used by `path_open`. +/// TODO: wit appears to not have support for flags repr +/// (@witx repr u16) +flags oflags { + /// Create file if it does not exist. + create, + /// Fail if not a directory. + directory, + /// Fail if file already exists. + excl, + /// Truncate file to size 0. + trunc, +} + +/// User-provided value that may be attached to objects that is retained when +/// extracted from the implementation. +type userdata = u64 + +/// Type of a subscription to an event or its occurrence. +enum eventtype { + // TODO: wit appears to not have support for enum tag types + //(@witx tag u8) + + /// The time value of clock `subscription_clock::id` has + /// reached timestamp `subscription_clock::timeout`. + clock, + /// File descriptor `subscription_fd_readwrite::fd` has data + /// available for reading. This event always triggers for regular files. + fd-read, + /// File descriptor `subscription_fd_readwrite::fd` has capacity + /// available for writing. This event always triggers for regular files. + fd-write, +} + +/// Flags determining how to interpret the timestamp provided in +/// `subscription-clock::timeout`. +flags subclockflags { + // TODO: wit appears to not have support for flags repr + //@witx repr u16) + /// If set, treat the timestamp provided in + /// `subscription-clock::timeout` as an absolute timestamp of clock + /// `subscription-clock::id`. If clear, treat the timestamp + /// provided in `subscription-clock::timeout` relative to the + /// current time value of clock `subscription-clock::id`. + subscription-clock-abstime, +} + +/// The contents of a `subscription` when type is `eventtype::clock`. +record snapshot0-subscription-clock { + /// The user-defined unique identifier of the clock. + identifier: userdata, + /// The clock against which to compare the timestamp. + id: snapshot0-clockid, + /// The absolute or relative timestamp. + timeout: timestamp, + /// The amount of time that the implementation may wait additionally + /// to coalesce with other events. + precision: timestamp, + /// Flags specifying whether the timeout is absolute or relative + %flags: subclockflags +} + +/// The contents of a `subscription` when type is `eventtype::clock`. +record subscription-clock { + /// The clock against which to compare the timestamp. + clock-id: clockid, + /// The absolute or relative timestamp. + timeout: timestamp, + /// The amount of time that the implementation may wait additionally + /// to coalesce with other events. + precision: timestamp, + /// Flags specifying whether the timeout is absolute or relative + %flags: subclockflags, +} + +/// Identifiers for preopened capabilities. +enum preopentype { + // TODO: wit appears to not have support for enum tag types + //(@witx tag u8) + + /// A pre-opened directory. + dir, +} + +/// The state of the file descriptor subscribed to with +/// `eventtype::fd_read` or `eventtype::fd_write`. +flags eventrwflags { + // TODO: wit appears to not have support for flags repr + //@witx repr u16) + + /// The peer of this socket has closed or disconnected. + fd-readwrite-hangup, +} + +/// The contents of an `event` for the `eventtype::fd_read` and +/// `eventtype::fd_write` variants +record event-fd-readwrite { + /// The number of bytes available for reading or writing. + nbytes: filesize, + /// The state of the file descriptor. + %flags: eventrwflags, +} + +/// An event that occurred. +record event { + /// User-provided value that got attached to `subscription::userdata`. + userdata: userdata, + /// If non-zero, an error that occurred while processing the subscription request. + error: errno, + /// The type of the event that occurred, and the contents of the event + data: event-enum +} + +/// The contents of an `event`. +variant event-enum { + // TODO: wit appears to not have support for tag type + //(@witx tag $eventtype) + fd-read(event-fd-readwrite), + fd-write(event-fd-readwrite), + clock, +} + + +/// An event that occurred. +record snapshot0-event { + /// User-provided value that got attached to `subscription::userdata`. + userdata: userdata, + /// If non-zero, an error that occurred while processing the subscription request. + error: errno, + /// The type of event that occured + %type: eventtype, + /// The contents of the event, if it is an `eventtype::fd_read` or + /// `eventtype::fd_write`. `eventtype::clock` events ignore this field. + fd-readwrite: event-fd-readwrite, +} + +/// The contents of a `subscription`, snapshot0 version. +variant snapshot0-subscription-enum { + // TODO: wit appears to have no support for tag types + //(@witx tag $eventtype) + clock(snapshot0-subscription-clock), + read(subscription-fs-readwrite), + write(subscription-fs-readwrite), +} + +/// The contents of a `subscription`. +variant subscription-enum { + // TODO: wit appears to have no support for tag types + //(@witx tag $eventtype) + clock(subscription-clock), + read(subscription-fs-readwrite), + write(subscription-fs-readwrite), +} + +/// The contents of a `subscription` when the variant is +/// `eventtype::fd_read` or `eventtype::fd_write`. +record subscription-fs-readwrite { + /// The file descriptor on which to wait for it to become ready for reading or writing. + file-descriptor: fd, +} + +record snapshot0-subscription { + userdata: userdata, + data: snapshot0-subscription-enum, +} + +record subscription { + userdata: userdata, + data: subscription-enum, +} + +enum socktype { + dgram, + %stream, + raw, + seqpacket, +} + +enum sockstatus { + opening, + opened, + closed, + failed, +} + +enum sockoption { + noop, + reuse-port, + reuse-addr, + no-delay, + dont-route, + only-v6, + broadcast, + multicast-loop-v4, + multicast-loop-v6, + promiscuous, + listening, + last-error, + keep-alive, + linger, + oob-inline, + recv-buf-size, + send-buf-size, + recv-lowat, + send-lowat, + recv-timeout, + send-timeout, + connect-timeout, + accept-timeout, + ttl, + multicast-ttl-v4, + %type, + proto, +} + +enum streamsecurity { + unencrypted, + any-encryption, + classic-encryption, + double-encryption, +} + +enum addressfamily { + unspec, + inet4, + inet6, + unix, +} + +record snapshot0-filestat { + st-dev: device, + st-ino: inode, + st-filetype: filetype, + st-nlink: snapshot0-linkcount, + st-size: filesize, + st-atim: timestamp, + st-mtim: timestamp, + st-ctim: timestamp, +} + +record filestat { + st-dev: device, + st-ino: inode, + st-filetype: filetype, + st-nlink: linkcount, + st-size: filesize, + st-atim: timestamp, + st-mtim: timestamp, + st-ctim: timestamp, +} + +enum snapshot0-whence { + cur, + end, + set, +} + +enum whence { + set, + cur, + end, +} + +record tty { + cols: u32, + rows: u32, + width: u32, + height: u32, + stdin-tty: bool, + stdout-tty: bool, + stderr-tty: bool, + echo: bool, + line-buffered: bool, +} + +enum bus-data-format { + raw, + bincode, + message-pack, + json, + yaml, + xml, + rkyv, +} + +enum bus-event-type { + noop, + exit, + call, + result, + fault, + close, +} + +type bid = u32 + +type cid = u32 + +/// __wasi_option_t +enum option-tag { + none, + some, +} + +record option-bid { + tag: option-tag, + bid: bid +} + +record option-cid { + tag: option-tag, + cid: cid +} + +record option-fd { + tag: option-tag, + fd: fd +} + +record bus-handles { + bid: bid, + stdin: option-fd, + stdout: option-fd, + stderr: option-fd, +} + +type exit-code = u32 + +record bus-event-exit { + bid: bid, + rval: exit-code, +} + +record bus-event-fault { + cid: cid, + err: bus-errno, +} + +record bus-event-close { + cid: cid, +} + +type event-fd-flags = u16 + +record prestat-u-dir { + pr-name-len: u32, +} + +record prestat-u { + dir: prestat-u-dir, +} + +record prestat { + pr-type: preopentype, + u: prestat-u, +} + +type file-delta = s64 + +type lookup-flags = u32 + +type count = u32 + +record pipe-handles { + pipe: fd, + other: fd, +} + +enum stdio-mode { + reserved, // = 0, stdio-mode starts at 1 + piped, + inherit, + null, + log, +} + +enum sock-proto { + ip, + icmp, + igmp, + proto-three, + ipip, + proto-five, + tcp, + proto-seven, + egp, + proto-nine, + proto-ten, + proto-eleven, + pup, + proto-thirteen, + proto-fourteen, + proto-fifteen, + proto-sixteen, + udp, + proto-eighteen, + proto-nineteen, + proto-twenty, + proto-twentyone, + idp, + proto-twentythree, + proto-twentyfour, + proto-twentyfive, + proto-twentysix, + proto-twentyseven, + proto-twentyeight, + proto-tp, + proto-thirty, + proto-thirtyone, + proto-thirtytwo, + dccp, + proto-thirtyfour, + proto-thirtyfive, + proto-thirtysix, + proto-thirtyseven, + proto-thirtyeight, + proto-thirtynine, + proto-fourty, + ipv6, + proto-fourtytwo, + routing, + fragment, + proto-fourtyfive, + rsvp, + gre, + proto-fourtyeight, + proto-fourtynine, + esp, + ah, + proto-fiftytwo, + proto-fiftythree, + proto-fiftyfour, + proto-fiftyfive, + proto-fiftysix, + proto-fiftyseven, + icmpv6, + none, + dstopts, + proto-sixtyone, + proto-sixtytwo, + proto-sixtythree, + proto-sixtyfour, + proto-sixtyfive, + proto-sixtysix, + proto-sixtyseven, + proto-sixtyeight, + proto-sixtynine, + proto-seventy, + proto-seventyone, + proto-seventytwo, + proto-seventythree, + proto-seventyfour, + proto-seventyfive, + proto-seventysix, + proto-seventyseven, + proto-seventyeight, + proto-seventynine, + proto-eighty, + proto-eightyone, + proto-eightytwo, + proto-eightythree, + proto-eightyfour, + proto-eightyfive, + proto-eightysix, + proto-eightyseven, + proto-eightyeight, + proto-eightynine, + proto-ninety, + proto-ninetyone, + mtp, + proto-ninetythree, + beetph, + proto-ninetyfive, + proto-ninetysix, + proto-nineetyseven, + encap, + proto-ninetynine, + proto-onehundred, + proto-onehundredandone, + proto-onehundredandtwo, + pim, + proto-onehundredandfour, + proto-onehundredandfive, + proto-onehundredandsix, + proto-onehundredandseven, + comp, + proto-onehundredandnine, + proto-onehundredandten, + proto-onehundredandeleven, + proto-onehundredandtwelve, + proto-onehundredandthirteen, + proto-onehundredandfourteen, + proto-onehundredandfifteen, + proto-onehundredandsixteen, + proto-onehundredandseventeen, + proto-onehundredandeighteen, + proto-onehundredandnineteen, + proto-onehundredandtwenty, + proto-onehundredandtwentyone, + proto-onehundredandtwentytwo, + proto-onehundredandtwentythree, + proto-onehundredandtwentyfour, + proto-onehundredandtwentyfive, + proto-onehundredandtwentysix, + proto-onehundredandtwentyseven, + proto-onehundredandtwentyeight, + proto-onehundredandtwentynine, + proto-onehundredandthirty, + proto-onehundredandthirtyone, + sctp, + proto-onehundredandthirtythree, + proto-onehundredandthirtyfour, + mh, + udplite, + mpls, + proto-onehundredandthirtyeight, + proto-onehundredandthirtynine, + proto-onehundredandfourty, + proto-onehundredandfourtyone, + proto-onehundredandfourtytwo, + ethernet, + proto-onehundredandfourtyfour, + proto-onehundredandfourtyfive, + proto-onehundredandfourtysix, + proto-onehundredandfourtyseven, + proto-onehundredandfourtyeight, + proto-onehundredandfourtynine, + proto-onehundredandfifty, + proto-onehundredandfiftyone, + proto-onehundredandfiftytwo, + proto-onehundredandfiftythree, + proto-onehundredandfiftyfour, + proto-onehundredandfiftyfive, + proto-onehundredandfiftysix, + proto-onehundredandfiftyseven, + proto-onehundredandfiftyeight, + proto-onehundredandfiftynine, + proto-onehundredandsixty, + proto-onehundredandsixtyone, + proto-onehundredandsixtytwo, + proto-onehundredandsixtythree, + proto-onehundredandsixtyfour, + proto-onehundredandsixtyfive, + proto-onehundredandsixtysix, + proto-onehundredandsixtyseven, + proto-onehundredandsixtyeight, + proto-onehundredandsixtynine, + proto-onehundredandseventy, + proto-onehundredandseventyone, + proto-onehundredandseventytwo, + proto-onehundredandseventythree, + proto-onehundredandseventyfour, + proto-onehundredandseventyfive, + proto-onehundredandseventysix, + proto-onehundredandseventyseven, + proto-onehundredandseventyeight, + proto-onehundredandseventynine, + proto-onehundredandeighty, + proto-onehundredandeightyone, + proto-onehundredandeightytwo, + proto-onehundredandeightythree, + proto-onehundredandeightyfour, + proto-onehundredandeightyfive, + proto-onehundredandeightysix, + proto-onehundredandeightyseven, + proto-onehundredandeightyeight, + proto-onehundredandeightynine, + proto-onehundredandninety, + proto-onehundredandninetyone, + proto-onehundredandninetytwo, + proto-onehundredandninetythree, + proto-onehundredandninetyfour, + proto-onehundredandninetyfive, + proto-onehundredandninetysix, + proto-onehundredandninetyseven, + proto-onehundredandninetyeight, + proto-onehundredandninetynine, + proto-twohundred, + proto-twohundredandone, + proto-twohundredandtwo, + proto-twohundredandthree, + proto-twohundredandfour, + proto-twohundredandfive, + proto-twohundredandsix, + proto-twohundredandseven, + proto-twohundredandeight, + proto-twohundredandnine, + proto-twohundredandten, + proto-twohundredandeleven, + proto-twohundredandtwelve, + proto-twohundredandthirteen, + proto-twohundredandfourteen, + proto-twohundredandfifteen, + proto-twohundredandsixteen, + proto-twohundredandseventeen, + proto-twohundredandeighteen, + proto-twohundredandnineteen, + proto-twohundredandtwenty, + proto-twohundredandtwentyone, + proto-twohundredandtwentytwo, + proto-twohundredandtwentythree, + proto-twohundredandtwentyfour, + proto-twohundredandtwentyfive, + proto-twohundredandtwentysix, + proto-twohundredandtwentyseven, + proto-twohundredandtwentyeight, + proto-twohundredandtwentynine, + proto-twohundredandthirty, + proto-twohundredandthirtyone, + proto-twohundredandthirtytwo, + proto-twohundredandthirtythree, + proto-twohundredandthirtyfour, + proto-twohundredandthirtyfive, + proto-twohundredandthirtysix, + proto-twohundredandthirtyseven, + proto-twohundredandthirtyeight, + proto-twohundredandthirtynine, + proto-twohundredandfourty, + proto-twohundredandfourtyone, + proto-twohundredandfourtytwo, + proto-twohundredandfourtythree, + proto-twohundredandfourtyfour, + proto-twohundredandfourtyfive, + proto-twohundredandfourtysix, + proto-twohundredandfourtyseven, + proto-twohundredandfourtyeight, + proto-twohundredandfourtynine, + proto-twohundredandfifty, + proto-twohundredandfiftyone, + proto-twohundredandfiftytwo, + proto-twohundredandfiftythree, + proto-twohundredandfiftyfour, + proto-raw, + proto-twohundredandfiftysix, + proto-twohundredandfiftyseven, + proto-twohundredandfiftyeight, + proto-twohundredandfiftynine, + proto-twohundredandsixty, + proto-twohundredandsixtyone, + mptcp, + max, +} + +enum %bool { + %false, + %true, +} + +record option-timestamp { + tag: option-tag, + u: timestamp, +} + +enum signal { + sighup, + sigint, + sigquit, + sigill, + sigtrap, + sigabrt, + sigbus, + sigfpe, + sigkill, + sigusr1, + sigsegv, + sigusr2, + sigpipe, + sigalrm, + sigterm, + sigchld, + sigcont, + sigstop, + sigtstp, + sigttin, + sigttou, + sigurg, + sigxcpu, + sigxfsz, + sigvtalrm, + sigprof, + sigwinch, + sigpoll, + sigpwr, + sigsys, +} + +record addr-unspec { + n0: u8, +} + +record addr-unspec-port { + port: u16, + addr: addr-unspec, +} + +record cidr-unspec { + addr: addr-unspec, + prefix: u8, +} + +record http-handles { + req: fd, + res: fd, + hdr: fd, +} + +record http-status { + ok: %bool, + redirect: %bool, + size: filesize, + status: u16, +} + +type ri-flags = u16 + +type ro-flags = u16 + +type sd-flags = u8 + +type si-flags = u16 + +enum timeout { + read, + write, + connect, + accept, +} \ No newline at end of file diff --git a/lib/wasi-types/wit-clean/wasi_unstable.wit b/lib/wasi-types/wit-clean/wasi_unstable.wit new file mode 100644 index 00000000000..0e37989f8e8 --- /dev/null +++ b/lib/wasi-types/wit-clean/wasi_unstable.wit @@ -0,0 +1,512 @@ +// WASI Preview. This is an evolution of the API that WASI initially +// launched with. +// +// Some content here is derived from [CloudABI](https://github.com/NuxiNL/cloudabi). + +/// This API predated the convention of naming modules with a `wasi_unstable_` +/// prefix and a version number. It is preserved here for compatibility, but +/// we shouldn't follow this pattern in new APIs. +/* +(module $wasi_unstable + /// Linear memory to be accessed by WASI functions that need it. + (import "memory" (memory)) + + /// Read command-line argument data. + /// The size of the array should match that returned by `args_sizes_get`. + /// Each argument is expected to be `\0` terminated. + (@interface func (export "args_get") + (param $argv (@witx pointer (@witx pointer u8))) + (param $argv_buf (@witx pointer u8)) + (result $error (expected (error $errno))) + ) + + /// Return command-line argument data sizes. + (@interface func (export "args_sizes_get") + /// Returns the number of arguments and the size of the argument string + /// data, or an error. + (result $error (expected (tuple $size $size) (error $errno))) + ) + + /// Read environment variable data. + /// The sizes of the buffers should match that returned by `environ_sizes_get`. + /// Key/value pairs are expected to be joined with `=`s, and terminated with `\0`s. + (@interface func (export "environ_get") + (param $environ (@witx pointer (@witx pointer u8))) + (param $environ_buf (@witx pointer u8)) + (result $error (expected (error $errno))) + ) + + /// Return environment variable data sizes. + (@interface func (export "environ_sizes_get") + /// Returns the number of environment variable arguments and the size of the + /// environment variable data. + (result $error (expected (tuple $size $size) (error $errno))) + ) + + /// Return the resolution of a clock. + /// Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks, return + /// `errno::inval`. + /// Note: This is similar to `clock_getres` in POSIX. + (@interface func (export "clock_res_get") + /// The clock for which to return the resolution. + (param $id $clockid) + /// The resolution of the clock, or an error if one happened. + (result $error (expected $timestamp (error $errno))) + ) + /// Return the time value of a clock. + /// Note: This is similar to `clock_gettime` in POSIX. + (@interface func (export "clock_time_get") + /// The clock for which to return the time. + (param $id $clockid) + /// The maximum lag (exclusive) that the returned time value may have, compared to its actual value. + (param $precision $timestamp) + /// The time value of the clock. + (result $error (expected $timestamp (error $errno))) + ) + + /// Provide file advisory information on a file descriptor. + /// Note: This is similar to `posix_fadvise` in POSIX. + (@interface func (export "fd_advise") + (param $fd $fd) + /// The offset within the file to which the advisory applies. + (param $offset $filesize) + /// The length of the region to which the advisory applies. + (param $len $filesize) + /// The advice. + (param $advice $advice) + (result $error (expected (error $errno))) + ) + + /// Force the allocation of space in a file. + /// Note: This is similar to `posix_fallocate` in POSIX. + (@interface func (export "fd_allocate") + (param $fd $fd) + /// The offset at which to start the allocation. + (param $offset $filesize) + /// The length of the area that is allocated. + (param $len $filesize) + (result $error (expected (error $errno))) + ) + + /// Close a file descriptor. + /// Note: This is similar to `close` in POSIX. + (@interface func (export "fd_close") + (param $fd $fd) + (result $error (expected (error $errno))) + ) + + /// Synchronize the data of a file to disk. + /// Note: This is similar to `fdatasync` in POSIX. + (@interface func (export "fd_datasync") + (param $fd $fd) + (result $error (expected (error $errno))) + ) + + /// Get the attributes of a file descriptor. + /// Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well as additional fields. + (@interface func (export "fd_fdstat_get") + (param $fd $fd) + /// The buffer where the file descriptor's attributes are stored. + (result $error (expected $fdstat (error $errno))) + ) + + /// Adjust the flags associated with a file descriptor. + /// Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX. + (@interface func (export "fd_fdstat_set_flags") + (param $fd $fd) + /// The desired values of the file descriptor flags. + (param $flags $fdflags) + (result $error (expected (error $errno))) + ) + + /// Adjust the rights associated with a file descriptor. + /// This can only be used to remove rights, and returns `errno::notcapable` if called in a way that would attempt to add rights + (@interface func (export "fd_fdstat_set_rights") + (param $fd $fd) + /// The desired rights of the file descriptor. + (param $fs_rights_base $rights) + (param $fs_rights_inheriting $rights) + (result $error (expected (error $errno))) + ) + + /// Return the attributes of an open file. + (@interface func (export "fd_filestat_get") + (param $fd $fd) + /// The buffer where the file's attributes are stored. + (result $error (expected $filestat (error $errno))) + ) + + /// Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros. + /// Note: This is similar to `ftruncate` in POSIX. + (@interface func (export "fd_filestat_set_size") + (param $fd $fd) + /// The desired file size. + (param $size $filesize) + (result $error (expected (error $errno))) + ) + + /// Adjust the timestamps of an open file or directory. + /// Note: This is similar to `futimens` in POSIX. + (@interface func (export "fd_filestat_set_times") + (param $fd $fd) + /// The desired values of the data access timestamp. + (param $atim $timestamp) + /// The desired values of the data modification timestamp. + (param $mtim $timestamp) + /// A bitmask indicating which timestamps to adjust. + (param $fst_flags $fstflags) + (result $error (expected (error $errno))) + ) + + /// Read from a file descriptor, without using and updating the file descriptor's offset. + /// Note: This is similar to `preadv` in POSIX. + (@interface func (export "fd_pread") + (param $fd $fd) + /// List of scatter/gather vectors in which to store data. + (param $iovs $iovec_array) + /// The offset within the file at which to read. + (param $offset $filesize) + /// The number of bytes read. + (result $error (expected $size (error $errno))) + ) + + /// Return a description of the given preopened file descriptor. + (@interface func (export "fd_prestat_get") + (param $fd $fd) + /// The buffer where the description is stored. + (result $error (expected $prestat (error $errno))) + ) + + /// Return a description of the given preopened file descriptor. + (@interface func (export "fd_prestat_dir_name") + (param $fd $fd) + /// A buffer into which to write the preopened directory name. + (param $path (@witx pointer u8)) + (param $path_len $size) + (result $error (expected (error $errno))) + ) + + /// Write to a file descriptor, without using and updating the file descriptor's offset. + /// Note: This is similar to `pwritev` in POSIX. + (@interface func (export "fd_pwrite") + (param $fd $fd) + /// List of scatter/gather vectors from which to retrieve data. + (param $iovs $ciovec_array) + /// The offset within the file at which to write. + (param $offset $filesize) + /// The number of bytes written. + (result $error (expected $size (error $errno))) + ) + + /// Read from a file descriptor. + /// Note: This is similar to `readv` in POSIX. + (@interface func (export "fd_read") + (param $fd $fd) + /// List of scatter/gather vectors to which to store data. + (param $iovs $iovec_array) + /// The number of bytes read. + (result $error (expected $size (error $errno))) + ) + + /// Read directory entries from a directory. + /// When successful, the contents of the output buffer consist of a sequence of + /// directory entries. Each directory entry consists of a `dirent` object, + /// followed by `dirent::d_namlen` bytes holding the name of the directory + /// entry. + /// + /// This function fills the output buffer as much as possible, potentially + /// truncating the last directory entry. This allows the caller to grow its + /// read buffer size in case it's too small to fit a single large directory + /// entry, or skip the oversized directory entry. + (@interface func (export "fd_readdir") + (param $fd $fd) + /// The buffer where directory entries are stored + (param $buf (@witx pointer u8)) + (param $buf_len $size) + /// The location within the directory to start reading + (param $cookie $dircookie) + /// The number of bytes stored in the read buffer. If less than the size of the read buffer, the end of the directory has been reached. + (result $error (expected $size (error $errno))) + ) + + /// Atomically replace a file descriptor by renumbering another file descriptor. + // + /// Due to the strong focus on thread safety, this environment does not provide + /// a mechanism to duplicate or renumber a file descriptor to an arbitrary + /// number, like `dup2()`. This would be prone to race conditions, as an actual + /// file descriptor with the same number could be allocated by a different + /// thread at the same time. + // + /// This function provides a way to atomically renumber file descriptors, which + /// would disappear if `dup2()` were to be removed entirely. + (@interface func (export "fd_renumber") + (param $fd $fd) + /// The file descriptor to overwrite. + (param $to $fd) + (result $error (expected (error $errno))) + ) + + /// Move the offset of a file descriptor. + /// Note: This is similar to `lseek` in POSIX. + (@interface func (export "fd_seek") + (param $fd $fd) + /// The number of bytes to move. + (param $offset $filedelta) + /// The base from which the offset is relative. + (param $whence $whence) + /// The new offset of the file descriptor, relative to the start of the file. + (result $error (expected $filesize (error $errno))) + ) + + /// Synchronize the data and metadata of a file to disk. + /// Note: This is similar to `fsync` in POSIX. + (@interface func (export "fd_sync") + (param $fd $fd) + (result $error (expected (error $errno))) + ) + + /// Return the current offset of a file descriptor. + /// Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX. + (@interface func (export "fd_tell") + (param $fd $fd) + /// The current offset of the file descriptor, relative to the start of the file. + (result $error (expected $filesize (error $errno))) + ) + + /// Write to a file descriptor. + /// Note: This is similar to `writev` in POSIX. + (@interface func (export "fd_write") + (param $fd $fd) + /// List of scatter/gather vectors from which to retrieve data. + (param $iovs $ciovec_array) + (result $error (expected $size (error $errno))) + ) + + /// Create a directory. + /// Note: This is similar to `mkdirat` in POSIX. + (@interface func (export "path_create_directory") + (param $fd $fd) + /// The path at which to create the directory. + (param $path string) + (result $error (expected (error $errno))) + ) + + /// Return the attributes of a file or directory. + /// Note: This is similar to `stat` in POSIX. + (@interface func (export "path_filestat_get") + (param $fd $fd) + /// Flags determining the method of how the path is resolved. + (param $flags $lookupflags) + /// The path of the file or directory to inspect. + (param $path string) + /// The buffer where the file's attributes are stored. + (result $error (expected $filestat (error $errno))) + ) + + /// Adjust the timestamps of a file or directory. + /// Note: This is similar to `utimensat` in POSIX. + (@interface func (export "path_filestat_set_times") + (param $fd $fd) + /// Flags determining the method of how the path is resolved. + (param $flags $lookupflags) + /// The path of the file or directory to operate on. + (param $path string) + /// The desired values of the data access timestamp. + (param $atim $timestamp) + /// The desired values of the data modification timestamp. + (param $mtim $timestamp) + /// A bitmask indicating which timestamps to adjust. + (param $fst_flags $fstflags) + (result $error (expected (error $errno))) + ) + + /// Create a hard link. + /// Note: This is similar to `linkat` in POSIX. + (@interface func (export "path_link") + (param $old_fd $fd) + /// Flags determining the method of how the path is resolved. + (param $old_flags $lookupflags) + /// The source path from which to link. + (param $old_path string) + /// The working directory at which the resolution of the new path starts. + (param $new_fd $fd) + /// The destination path at which to create the hard link. + (param $new_path string) + (result $error (expected (error $errno))) + ) + + /// Open a file or directory. + // + /// The returned file descriptor is not guaranteed to be the lowest-numbered + /// file descriptor not currently open; it is randomized to prevent + /// applications from depending on making assumptions about indexes, since this + /// is error-prone in multi-threaded contexts. The returned file descriptor is + /// guaranteed to be less than 2**31. + // + /// Note: This is similar to `openat` in POSIX. + (@interface func (export "path_open") + (param $fd $fd) + /// Flags determining the method of how the path is resolved. + (param $dirflags $lookupflags) + /// The relative path of the file or directory to open, relative to the + /// `path_open::fd` directory. + (param $path string) + /// The method by which to open the file. + (param $oflags $oflags) + /// The initial rights of the newly created file descriptor. The + /// implementation is allowed to return a file descriptor with fewer rights + /// than specified, if and only if those rights do not apply to the type of + /// file being opened. + // + /// The *base* rights are rights that will apply to operations using the file + /// descriptor itself, while the *inheriting* rights are rights that apply to + /// file descriptors derived from it. + (param $fs_rights_base $rights) + (param $fs_rights_inheriting $rights) + (param $fdflags $fdflags) + /// The file descriptor of the file that has been opened. + (result $error (expected $fd (error $errno))) + ) + + /// Read the contents of a symbolic link. + /// Note: This is similar to `readlinkat` in POSIX. + (@interface func (export "path_readlink") + (param $fd $fd) + /// The path of the symbolic link from which to read. + (param $path string) + /// The buffer to which to write the contents of the symbolic link. + (param $buf (@witx pointer u8)) + (param $buf_len $size) + /// The number of bytes placed in the buffer. + (result $error (expected $size (error $errno))) + ) + + /// Remove a directory. + /// Return `errno::notempty` if the directory is not empty. + /// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. + (@interface func (export "path_remove_directory") + (param $fd $fd) + /// The path to a directory to remove. + (param $path string) + (result $error (expected (error $errno))) + ) + + /// Rename a file or directory. + /// Note: This is similar to `renameat` in POSIX. + (@interface func (export "path_rename") + (param $fd $fd) + /// The source path of the file or directory to rename. + (param $old_path string) + /// The working directory at which the resolution of the new path starts. + (param $new_fd $fd) + /// The destination path to which to rename the file or directory. + (param $new_path string) + (result $error (expected (error $errno))) + ) + + /// Create a symbolic link. + /// Note: This is similar to `symlinkat` in POSIX. + (@interface func (export "path_symlink") + /// The contents of the symbolic link. + (param $old_path string) + (param $fd $fd) + /// The destination path at which to create the symbolic link. + (param $new_path string) + (result $error (expected (error $errno))) + ) + + + /// Unlink a file. + /// Return `errno::isdir` if the path refers to a directory. + /// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. + (@interface func (export "path_unlink_file") + (param $fd $fd) + /// The path to a file to unlink. + (param $path string) + (result $error (expected (error $errno))) + ) + + /// Concurrently poll for the occurrence of a set of events. + (@interface func (export "poll_oneoff") + /// The events to which to subscribe. + (param $in (@witx const_pointer $subscription)) + /// The events that have occurred. + (param $out (@witx pointer $event)) + /// Both the number of subscriptions and events. + (param $nsubscriptions $size) + /// The number of events stored. + (result $error (expected $size (error $errno))) + ) + + /// Terminate the process normally. An exit code of 0 indicates successful + /// termination of the program. The meanings of other values is dependent on + /// the environment. + (@interface func (export "proc_exit") + /// The exit code returned by the process. + (param $rval $exitcode) + (@witx noreturn) + ) + + /// Send a signal to the process of the calling thread. + /// Note: This is similar to `raise` in POSIX. + (@interface func (export "proc_raise") + /// The signal condition to trigger. + (param $sig $signal) + (result $error (expected (error $errno))) + ) + + /// Temporarily yield execution of the calling thread. + /// Note: This is similar to `sched_yield` in POSIX. + (@interface func (export "sched_yield") + (result $error (expected (error $errno))) + ) + + /// Write high-quality random data into a buffer. + /// This function blocks when the implementation is unable to immediately + /// provide sufficient high-quality random data. + /// This function may execute slowly, so when large mounts of random data are + /// required, it's advisable to use this function to seed a pseudo-random + /// number generator, rather than to provide the random data directly. + (@interface func (export "random_get") + /// The buffer to fill with random data. + (param $buf (@witx pointer u8)) + (param $buf_len $size) + (result $error (expected (error $errno))) + ) + + /// Receive a message from a socket. + /// Note: This is similar to `recv` in POSIX, though it also supports reading + /// the data into multiple buffers in the manner of `readv`. + (@interface func (export "sock_recv") + (param $fd $fd) + /// List of scatter/gather vectors to which to store data. + (param $ri_data $iovec_array) + /// Message flags. + (param $ri_flags $riflags) + /// Number of bytes stored in ri_data and message flags. + (result $error (expected (tuple $size $roflags) (error $errno))) + ) + + /// Send a message on a socket. + /// Note: This is similar to `send` in POSIX, though it also supports writing + /// the data from multiple buffers in the manner of `writev`. + (@interface func (export "sock_send") + (param $fd $fd) + /// List of scatter/gather vectors to which to retrieve data + (param $si_data $ciovec_array) + /// Message flags. + (param $si_flags $siflags) + /// Number of bytes transmitted. + (result $error (expected $size (error $errno))) + ) + + /// Shut down socket send and receive channels. + /// Note: This is similar to `shutdown` in POSIX. + (@interface func (export "sock_shutdown") + (param $fd $fd) + /// Which channels on the socket to shut down. + (param $how $sdflags) + (result $error (expected (error $errno))) + ) +) +*/ \ No newline at end of file diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml index 6c9cee8d719..97665bf1f8e 100644 --- a/lib/wasi/Cargo.toml +++ b/lib/wasi/Cargo.toml @@ -46,11 +46,11 @@ tracing-wasm = "0.2" default = ["sys-default"] wasix = [] -sys = ["wasmer/sys", "wasix"] +sys = ["wasmer/sys", "wasix", "wasmer-wasi-types/sys"] sys-default = ["wasmer/wat", "wasmer/compiler", "sys", "logging", "host-fs", "sys-poll", "host-vnet" ] sys-poll = [] -js = ["wasmer/js", "mem-fs", "wasmer-vfs/no-time", "getrandom/js", "chrono"] +js = ["wasmer/js", "mem-fs", "wasmer-vfs/no-time", "getrandom/js", "chrono", "wasmer-wasi-types/js"] js-default = ["js", "wasmer/js-default"] test-js = ["js", "wasmer/js-default", "wasmer/wat"] diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index d4971f50f15..1d1b76cfa46 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -57,7 +57,6 @@ pub use wasmer_vfs::FsError as WasiFsError; pub use wasmer_vfs::VirtualFile as WasiFile; pub use wasmer_vfs::{FsError, VirtualFile}; pub use wasmer_vnet::{UnsupportedVirtualNetworking, VirtualNetworking}; -use wasmer_wasi_types::__WASI_CLOCK_MONOTONIC; use derivative::*; use std::ops::Deref; @@ -68,6 +67,7 @@ use wasmer::{ Imports, Instance, Memory, Memory32, MemoryAccessError, MemorySize, MemoryView, Module, TypedFunction, }; +use wasmer_wasi_types::wasi::{BusErrno, Errno, Snapshot0Clockid}; pub use runtime::{ PluggableRuntimeImplementation, WasiRuntimeImplementation, WasiThreadError, WasiTtyState, @@ -321,10 +321,12 @@ impl WasiEnv { // Sleeps for a period of time pub fn sleep(&self, duration: Duration) -> Result<(), WasiError> { let duration = duration.as_nanos(); - let start = platform_clock_time_get(__WASI_CLOCK_MONOTONIC, 1_000_000).unwrap() as u128; + let start = + platform_clock_time_get(Snapshot0Clockid::Monotonic, 1_000_000).unwrap() as u128; self.yield_now()?; loop { - let now = platform_clock_time_get(__WASI_CLOCK_MONOTONIC, 1_000_000).unwrap() as u128; + let now = + platform_clock_time_get(Snapshot0Clockid::Monotonic, 1_000_000).unwrap() as u128; let delta = match now.checked_sub(start) { Some(a) => a, None => { @@ -809,20 +811,20 @@ fn generate_import_object_wasix64_v1( } } -fn mem_error_to_wasi(err: MemoryAccessError) -> types::__wasi_errno_t { +fn mem_error_to_wasi(err: MemoryAccessError) -> Errno { match err { - MemoryAccessError::HeapOutOfBounds => types::__WASI_EFAULT, - MemoryAccessError::Overflow => types::__WASI_EOVERFLOW, - MemoryAccessError::NonUtf8String => types::__WASI_EINVAL, - _ => types::__WASI_EINVAL, + MemoryAccessError::HeapOutOfBounds => Errno::Fault, + MemoryAccessError::Overflow => Errno::Overflow, + MemoryAccessError::NonUtf8String => Errno::Inval, + _ => Errno::Inval, } } -fn mem_error_to_bus(err: MemoryAccessError) -> types::__bus_errno_t { +fn mem_error_to_bus(err: MemoryAccessError) -> BusErrno { match err { - MemoryAccessError::HeapOutOfBounds => types::__BUS_EMEMVIOLATION, - MemoryAccessError::Overflow => types::__BUS_EMEMVIOLATION, - MemoryAccessError::NonUtf8String => types::__BUS_EBADREQUEST, - _ => types::__BUS_EUNKNOWN, + MemoryAccessError::HeapOutOfBounds => BusErrno::Memviolation, + MemoryAccessError::Overflow => BusErrno::Memviolation, + MemoryAccessError::NonUtf8String => BusErrno::Badrequest, + _ => BusErrno::Unknown, } } diff --git a/lib/wasi/src/macros.rs b/lib/wasi/src/macros.rs index b9ec4245597..450e88cd637 100644 --- a/lib/wasi/src/macros.rs +++ b/lib/wasi/src/macros.rs @@ -4,7 +4,7 @@ /// succeeded or returns the error value. macro_rules! wasi_try { ($expr:expr) => {{ - let res: Result<_, crate::syscalls::types::__wasi_errno_t> = $expr; + let res: Result<_, crate::syscalls::types::wasi::Errno> = $expr; match res { Ok(val) => { tracing::trace!("wasi::wasi_try::val: {:?}", val); @@ -22,7 +22,7 @@ macro_rules! wasi_try { /// succeeded or returns the error value. Results are wrapped in an Ok macro_rules! wasi_try_ok { ($expr:expr) => {{ - let res: Result<_, crate::syscalls::types::__wasi_errno_t> = $expr; + let res: Result<_, crate::syscalls::types::wasi::Errno> = $expr; match res { Ok(val) => { tracing::trace!("wasi::wasi_try_ok::val: {:?}", val); @@ -36,14 +36,14 @@ macro_rules! wasi_try_ok { }}; ($expr:expr, $thread:expr) => {{ - let res: Result<_, crate::syscalls::types::__wasi_errno_t> = $expr; + let res: Result<_, crate::syscalls::types::wasi::Errno> = $expr; match res { Ok(val) => { tracing::trace!("wasi::wasi_try_ok::val: {:?}", val); val } Err(err) => { - if err == __WASI_EINTR { + if err == crate::syscalls::types::wasi::Errno::Intr { $thread.yield_now()?; } tracing::debug!("wasi::wasi_try_ok::err: {:?}", err); @@ -57,7 +57,7 @@ macro_rules! wasi_try_ok { /// succeeded or returns the error value. macro_rules! wasi_try_bus { ($expr:expr) => {{ - let res: Result<_, crate::syscalls::types::__bus_errno_t> = $expr; + let res: Result<_, crate::syscalls::types::wasi::BusErrno> = $expr; match res { Ok(val) => { tracing::trace!("wasi::wasi_try_bus::val: {:?}", val); @@ -71,21 +71,21 @@ macro_rules! wasi_try_bus { }}; } -/// Like `wasi_try` but converts a `MemoryAccessError` to a __wasi_errno_t`. +/// Like `wasi_try` but converts a `MemoryAccessError` to a `wasi::Errno`. macro_rules! wasi_try_mem { ($expr:expr) => {{ wasi_try!($expr.map_err($crate::mem_error_to_wasi)) }}; } -/// Like `wasi_try` but converts a `MemoryAccessError` to a __bus_errno_t`. +/// Like `wasi_try` but converts a `MemoryAccessError` to a `wasi::BusErrno`. macro_rules! wasi_try_mem_bus { ($expr:expr) => {{ wasi_try_bus!($expr.map_err($crate::mem_error_to_bus)) }}; } -/// Like `wasi_try` but converts a `MemoryAccessError` to a __wasi_errno_t`. +/// Like `wasi_try` but converts a `MemoryAccessError` to a `wasi::Errno`. macro_rules! wasi_try_mem_ok { ($expr:expr) => {{ wasi_try_ok!($expr.map_err($crate::mem_error_to_wasi)) diff --git a/lib/wasi/src/runtime.rs b/lib/wasi/src/runtime.rs index 00c208bd166..1394e010b8a 100644 --- a/lib/wasi/src/runtime.rs +++ b/lib/wasi/src/runtime.rs @@ -4,8 +4,8 @@ use std::sync::atomic::{AtomicU32, Ordering}; use thiserror::Error; use wasmer_vbus::{UnsupportedVirtualBus, VirtualBus}; use wasmer_vnet::VirtualNetworking; +use wasmer_wasi_types::wasi::Errno; -use super::types::*; use super::WasiError; use super::WasiThreadId; @@ -17,11 +17,11 @@ pub enum WasiThreadError { MethodNotFound, } -impl From for __wasi_errno_t { - fn from(a: WasiThreadError) -> __wasi_errno_t { +impl From for Errno { + fn from(a: WasiThreadError) -> Errno { match a { - WasiThreadError::Unsupported => __WASI_ENOTSUP, - WasiThreadError::MethodNotFound => __WASI_EINVAL, + WasiThreadError::Unsupported => Errno::Notsup, + WasiThreadError::MethodNotFound => Errno::Inval, } } } diff --git a/lib/wasi/src/state/guard.rs b/lib/wasi/src/state/guard.rs index e37c9c97845..d3a84ffcabd 100644 --- a/lib/wasi/src/state/guard.rs +++ b/lib/wasi/src/state/guard.rs @@ -50,7 +50,7 @@ pub(crate) struct WasiStateFileGuard { } impl WasiStateFileGuard { - pub fn new(state: &WasiState, fd: __wasi_fd_t) -> Result, FsError> { + pub fn new(state: &WasiState, fd: wasi::Fd) -> Result, FsError> { let inodes = state.inodes.read().unwrap(); let fd_map = state.fs.fd_map.read().unwrap(); if let Some(fd) = fd_map.get(&fd) { diff --git a/lib/wasi/src/state/mod.rs b/lib/wasi/src/state/mod.rs index 4b1a75a718d..58f94dcd83a 100644 --- a/lib/wasi/src/state/mod.rs +++ b/lib/wasi/src/state/mod.rs @@ -52,26 +52,42 @@ use std::{ }; use tracing::{debug, trace}; use wasmer_vbus::BusSpawnedProcess; +use wasmer_wasi_types::wasi::{ + Errno, Fd as WasiFd, Fdflags, Fdstat, Filesize, Filestat, Filetype, Preopentype, Rights, +}; +use wasmer_wasi_types::wasi::{Prestat, PrestatEnum}; use wasmer_vfs::{FileSystem, FsError, OpenOptions, VirtualFile}; /// the fd value of the virtual root -pub const VIRTUAL_ROOT_FD: __wasi_fd_t = 3; +pub const VIRTUAL_ROOT_FD: WasiFd = 3; /// all the rights enabled -pub const ALL_RIGHTS: __wasi_rights_t = 0x1FFF_FFFF; -const STDIN_DEFAULT_RIGHTS: __wasi_rights_t = __WASI_RIGHT_FD_DATASYNC - | __WASI_RIGHT_FD_READ - | __WASI_RIGHT_FD_SYNC - | __WASI_RIGHT_FD_ADVISE - | __WASI_RIGHT_FD_FILESTAT_GET - | __WASI_RIGHT_POLL_FD_READWRITE; -const STDOUT_DEFAULT_RIGHTS: __wasi_rights_t = __WASI_RIGHT_FD_DATASYNC - | __WASI_RIGHT_FD_WRITE - | __WASI_RIGHT_FD_SYNC - | __WASI_RIGHT_FD_ADVISE - | __WASI_RIGHT_FD_FILESTAT_GET - | __WASI_RIGHT_POLL_FD_READWRITE; -const STDERR_DEFAULT_RIGHTS: __wasi_rights_t = STDOUT_DEFAULT_RIGHTS; +pub const ALL_RIGHTS: Rights = Rights::all(); +const STDIN_DEFAULT_RIGHTS: Rights = { + // This might seem a bit overenineered, but it's the only way I + // discovered for getting the values in a const environment + Rights::from_bits_truncate( + Rights::FD_DATASYNC.bits() + | Rights::FD_READ.bits() + | Rights::FD_SYNC.bits() + | Rights::FD_ADVISE.bits() + | Rights::FD_FILESTAT_GET.bits() + | Rights::POLL_FD_READWRITE.bits(), + ) +}; +const STDOUT_DEFAULT_RIGHTS: Rights = { + // This might seem a bit overenineered, but it's the only way I + // discovered for getting the values in a const environment + Rights::from_bits_truncate( + Rights::FD_DATASYNC.bits() + | Rights::FD_SYNC.bits() + | Rights::FD_WRITE.bits() + | Rights::FD_ADVISE.bits() + | Rights::FD_FILESTAT_GET.bits() + | Rights::POLL_FD_READWRITE.bits(), + ) +}; +const STDERR_DEFAULT_RIGHTS: Rights = STDOUT_DEFAULT_RIGHTS; /// A completely aribtrary "big enough" number used as the upper limit for /// the number of symlinks that can be traversed when resolving a path @@ -81,7 +97,7 @@ pub const MAX_SYMLINKS: u32 = 128; #[derive(Debug)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct InodeVal { - pub stat: RwLock<__wasi_filestat_t>, + pub stat: RwLock, pub is_preopened: bool, pub name: String, pub kind: RwLock, @@ -149,7 +165,7 @@ pub enum Kind { /// - There is always a closer pre-opened dir to the symlink file (by definition of the root being a collection of preopened dirs) Symlink { /// The preopened dir that this symlink file is relative to (via `path_to_symlink`) - base_po_dir: __wasi_fd_t, + base_po_dir: WasiFd, /// The path to the symlink from the `base_po_dir` path_to_symlink: PathBuf, /// the value of the symlink as a relative path @@ -172,9 +188,9 @@ pub enum Kind { #[derive(Debug, Clone)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct Fd { - pub rights: __wasi_rights_t, - pub rights_inheriting: __wasi_rights_t, - pub flags: __wasi_fdflags_t, + pub rights: Rights, + pub rights_inheriting: Rights, + pub flags: Fdflags, pub offset: u64, /// Flags that determine how the [`Fd`] can be used. /// @@ -212,14 +228,11 @@ pub struct WasiInodes { impl WasiInodes { /// gets either a normal inode or an orphaned inode - pub fn get_inodeval( - &self, - inode: generational_arena::Index, - ) -> Result<&InodeVal, __wasi_errno_t> { + pub fn get_inodeval(&self, inode: generational_arena::Index) -> Result<&InodeVal, Errno> { if let Some(iv) = self.arena.get(inode) { Ok(iv) } else { - self.orphan_fds.get(&inode).ok_or(__WASI_EBADF) + self.orphan_fds.get(&inode).ok_or(Errno::Badf) } } @@ -227,11 +240,11 @@ impl WasiInodes { pub fn get_inodeval_mut( &mut self, inode: generational_arena::Index, - ) -> Result<&mut InodeVal, __wasi_errno_t> { + ) -> Result<&mut InodeVal, Errno> { if let Some(iv) = self.arena.get_mut(inode) { Ok(iv) } else { - self.orphan_fds.get_mut(&inode).ok_or(__WASI_EBADF) + self.orphan_fds.get_mut(&inode).ok_or(Errno::Badf) } } @@ -285,7 +298,7 @@ impl WasiInodes { fn std_dev_get<'a>( &'a self, fd_map: &RwLock>, - fd: __wasi_fd_t, + fd: WasiFd, ) -> Result, FsError> { if let Some(fd) = fd_map.read().unwrap().get(&fd) { let guard = self.arena[fd.inode].read(); @@ -305,7 +318,7 @@ impl WasiInodes { fn std_dev_get_mut<'a>( &'a self, fd_map: &RwLock>, - fd: __wasi_fd_t, + fd: WasiFd, ) -> Result, FsError> { if let Some(fd) = fd_map.read().unwrap().get(&fd) { let guard = self.arena[fd.inode].write(); @@ -404,19 +417,19 @@ impl WasiFs { path: PathBuf::from(preopen_name), entries: Default::default(), }; - let rights = __WASI_RIGHT_FD_ADVISE - | __WASI_RIGHT_FD_TELL - | __WASI_RIGHT_FD_SEEK - | __WASI_RIGHT_FD_READ - | __WASI_RIGHT_PATH_OPEN - | __WASI_RIGHT_FD_READDIR - | __WASI_RIGHT_PATH_READLINK - | __WASI_RIGHT_PATH_FILESTAT_GET - | __WASI_RIGHT_FD_FILESTAT_GET - | __WASI_RIGHT_PATH_LINK_SOURCE - | __WASI_RIGHT_PATH_RENAME_SOURCE - | __WASI_RIGHT_POLL_FD_READWRITE - | __WASI_RIGHT_SOCK_SHUTDOWN; + let rights = Rights::FD_ADVISE + | Rights::FD_TELL + | Rights::FD_SEEK + | Rights::FD_READ + | Rights::PATH_OPEN + | Rights::FD_READDIR + | Rights::PATH_READLINK + | Rights::PATH_FILESTAT_GET + | Rights::FD_FILESTAT_GET + | Rights::PATH_LINK_SOURCE + | Rights::PATH_RENAME_SOURCE + | Rights::POLL_FD_READWRITE + | Rights::SOCK_SHUTDOWN; let inode = wasi_fs .create_inode(inodes, kind, true, preopen_name.clone()) .map_err(|e| { @@ -427,7 +440,7 @@ impl WasiFs { })?; let fd_flags = Fd::READ; let fd = wasi_fs - .create_fd(rights, rights, 0, fd_flags, inode) + .create_fd(rights, rights, Fdflags::empty(), fd_flags, inode) .map_err(|e| format!("Could not open fd for file {:?}: {}", preopen_name, e))?; { let mut guard = inodes.arena[root_inode].write(); @@ -478,44 +491,43 @@ impl WasiFs { let rights = { // TODO: review tell' and fd_readwrite - let mut rights = - __WASI_RIGHT_FD_ADVISE | __WASI_RIGHT_FD_TELL | __WASI_RIGHT_FD_SEEK; + let mut rights = Rights::FD_ADVISE | Rights::FD_TELL | Rights::FD_SEEK; if *read { - rights |= __WASI_RIGHT_FD_READ - | __WASI_RIGHT_PATH_OPEN - | __WASI_RIGHT_FD_READDIR - | __WASI_RIGHT_PATH_READLINK - | __WASI_RIGHT_PATH_FILESTAT_GET - | __WASI_RIGHT_FD_FILESTAT_GET - | __WASI_RIGHT_PATH_LINK_SOURCE - | __WASI_RIGHT_PATH_RENAME_SOURCE - | __WASI_RIGHT_POLL_FD_READWRITE - | __WASI_RIGHT_SOCK_SHUTDOWN; + rights |= Rights::FD_READ + | Rights::PATH_OPEN + | Rights::FD_READDIR + | Rights::PATH_READLINK + | Rights::PATH_FILESTAT_GET + | Rights::FD_FILESTAT_GET + | Rights::PATH_LINK_SOURCE + | Rights::PATH_RENAME_SOURCE + | Rights::POLL_FD_READWRITE + | Rights::SOCK_SHUTDOWN; } if *write { - rights |= __WASI_RIGHT_FD_DATASYNC - | __WASI_RIGHT_FD_FDSTAT_SET_FLAGS - | __WASI_RIGHT_FD_WRITE - | __WASI_RIGHT_FD_SYNC - | __WASI_RIGHT_FD_ALLOCATE - | __WASI_RIGHT_PATH_OPEN - | __WASI_RIGHT_PATH_RENAME_TARGET - | __WASI_RIGHT_PATH_FILESTAT_SET_SIZE - | __WASI_RIGHT_PATH_FILESTAT_SET_TIMES - | __WASI_RIGHT_FD_FILESTAT_SET_SIZE - | __WASI_RIGHT_FD_FILESTAT_SET_TIMES - | __WASI_RIGHT_PATH_REMOVE_DIRECTORY - | __WASI_RIGHT_PATH_UNLINK_FILE - | __WASI_RIGHT_POLL_FD_READWRITE - | __WASI_RIGHT_SOCK_SHUTDOWN; + rights |= Rights::FD_DATASYNC + | Rights::FD_FDSTAT_SET_FLAGS + | Rights::FD_WRITE + | Rights::FD_SYNC + | Rights::FD_ALLOCATE + | Rights::PATH_OPEN + | Rights::PATH_RENAME_TARGET + | Rights::PATH_FILESTAT_SET_SIZE + | Rights::PATH_FILESTAT_SET_TIMES + | Rights::FD_FILESTAT_SET_SIZE + | Rights::FD_FILESTAT_SET_TIMES + | Rights::PATH_REMOVE_DIRECTORY + | Rights::PATH_UNLINK_FILE + | Rights::POLL_FD_READWRITE + | Rights::SOCK_SHUTDOWN; } if *create { - rights |= __WASI_RIGHT_PATH_CREATE_DIRECTORY - | __WASI_RIGHT_PATH_CREATE_FILE - | __WASI_RIGHT_PATH_LINK_TARGET - | __WASI_RIGHT_PATH_OPEN - | __WASI_RIGHT_PATH_RENAME_TARGET - | __WASI_RIGHT_PATH_SYMLINK; + rights |= Rights::PATH_CREATE_DIRECTORY + | Rights::PATH_CREATE_FILE + | Rights::PATH_LINK_TARGET + | Rights::PATH_OPEN + | Rights::PATH_RENAME_TARGET + | Rights::PATH_SYMLINK; } rights @@ -546,7 +558,7 @@ impl WasiFs { fd_flags }; let fd = wasi_fs - .create_fd(rights, rights, 0, fd_flags, inode) + .create_fd(rights, rights, Fdflags::empty(), fd_flags, inode) .map_err(|e| format!("Could not open fd for file {:?}: {}", path, e))?; { let mut guard = inodes.arena[root_inode].write(); @@ -596,23 +608,25 @@ impl WasiFs { // TODO: make this a list of positive rigths instead of negative ones // root gets all right for now let root_rights = all_rights - /*& (!__WASI_RIGHT_FD_WRITE) - & (!__WASI_RIGHT_FD_ALLOCATE) - & (!__WASI_RIGHT_PATH_CREATE_DIRECTORY) - & (!__WASI_RIGHT_PATH_CREATE_FILE) - & (!__WASI_RIGHT_PATH_LINK_SOURCE) - & (!__WASI_RIGHT_PATH_RENAME_SOURCE) - & (!__WASI_RIGHT_PATH_RENAME_TARGET) - & (!__WASI_RIGHT_PATH_FILESTAT_SET_SIZE) - & (!__WASI_RIGHT_PATH_FILESTAT_SET_TIMES) - & (!__WASI_RIGHT_FD_FILESTAT_SET_SIZE) - & (!__WASI_RIGHT_FD_FILESTAT_SET_TIMES) - & (!__WASI_RIGHT_PATH_SYMLINK) - & (!__WASI_RIGHT_PATH_UNLINK_FILE) - & (!__WASI_RIGHT_PATH_REMOVE_DIRECTORY)*/; + /* + & (!Rights::FD_WRITE) + & (!Rights::FD_ALLOCATE) + & (!Rights::PATH_CREATE_DIRECTORY) + & (!Rights::PATH_CREATE_FILE) + & (!Rights::PATH_LINK_SOURCE) + & (!Rights::PATH_RENAME_SOURCE) + & (!Rights::PATH_RENAME_TARGET) + & (!Rights::PATH_FILESTAT_SET_SIZE) + & (!Rights::PATH_FILESTAT_SET_TIMES) + & (!Rights::FD_FILESTAT_SET_SIZE) + & (!Rights::FD_FILESTAT_SET_TIMES) + & (!Rights::PATH_SYMLINK) + & (!Rights::PATH_UNLINK_FILE) + & (!Rights::PATH_REMOVE_DIRECTORY) + */; let inode = wasi_fs.create_virtual_root(inodes); let fd = wasi_fs - .create_fd(root_rights, root_rights, 0, Fd::READ, inode) + .create_fd(root_rights, root_rights, Fdflags::empty(), Fd::READ, inode) .map_err(|e| format!("Could not create root fd: {}", e))?; wasi_fs.preopen_fds.write().unwrap().push(fd); inode @@ -639,12 +653,12 @@ impl WasiFs { pub unsafe fn open_dir_all( &mut self, inodes: &mut WasiInodes, - base: __wasi_fd_t, + base: WasiFd, name: String, - rights: __wasi_rights_t, - rights_inheriting: __wasi_rights_t, - flags: __wasi_fdflags_t, - ) -> Result<__wasi_fd_t, FsError> { + rights: Rights, + rights_inheriting: Rights, + flags: Fdflags, + ) -> Result { // TODO: check permissions here? probably not, but this should be // an explicit choice, so justify it in a comment when we remove this one let mut cur_inode = self.get_fd_inode(base).map_err(fs_error_from_wasi_err)?; @@ -714,14 +728,14 @@ impl WasiFs { pub fn open_file_at( &mut self, inodes: &mut WasiInodes, - base: __wasi_fd_t, + base: WasiFd, file: Box, open_flags: u16, name: String, - rights: __wasi_rights_t, - rights_inheriting: __wasi_rights_t, - flags: __wasi_fdflags_t, - ) -> Result<__wasi_fd_t, FsError> { + rights: Rights, + rights_inheriting: Rights, + flags: Fdflags, + ) -> Result { // TODO: check permissions here? probably not, but this should be // an explicit choice, so justify it in a comment when we remove this one let base_inode = self.get_fd_inode(base).map_err(fs_error_from_wasi_err)?; @@ -774,7 +788,7 @@ impl WasiFs { pub fn swap_file( &self, inodes: &WasiInodes, - fd: __wasi_fd_t, + fd: WasiFd, file: Box, ) -> Result>, FsError> { let mut ret = Some(file); @@ -811,8 +825,8 @@ impl WasiFs { pub(crate) fn filestat_resync_size( &self, inodes: &WasiInodes, - fd: __wasi_fd_t, - ) -> Result<__wasi_filesize_t, __wasi_errno_t> { + fd: WasiFd, + ) -> Result { let inode = self.get_fd_inode(fd)?; let mut guard = inodes.arena[inode].write(); let deref_mut = guard.deref_mut(); @@ -823,13 +837,13 @@ impl WasiFs { drop(guard); inodes.arena[inode].stat.write().unwrap().st_size = new_size; - Ok(new_size as __wasi_filesize_t) + Ok(new_size as Filesize) } else { - Err(__WASI_EBADF) + Err(Errno::Badf) } } - Kind::Dir { .. } | Kind::Root { .. } => Err(__WASI_EISDIR), - _ => Err(__WASI_EINVAL), + Kind::Dir { .. } | Kind::Root { .. } => Err(Errno::Isdir), + _ => Err(Errno::Inval), } } @@ -843,17 +857,17 @@ impl WasiFs { pub fn get_current_dir( &self, inodes: &mut WasiInodes, - base: __wasi_fd_t, - ) -> Result<(Inode, String), __wasi_errno_t> { + base: WasiFd, + ) -> Result<(Inode, String), Errno> { self.get_current_dir_inner(inodes, base, 0) } pub(crate) fn get_current_dir_inner( &self, inodes: &mut WasiInodes, - base: __wasi_fd_t, + base: WasiFd, symlink_count: u32, - ) -> Result<(Inode, String), __wasi_errno_t> { + ) -> Result<(Inode, String), Errno> { let current_dir = { let guard = self.current_dir.lock().unwrap(); guard.clone() @@ -889,9 +903,9 @@ impl WasiFs { path: &str, mut symlink_count: u32, follow_symlinks: bool, - ) -> Result { + ) -> Result { if symlink_count > MAX_SYMLINKS { - return Err(__WASI_EMLINK); + return Err(Errno::Mlink); } let path: &Path = Path::new(path); @@ -920,7 +934,7 @@ impl WasiFs { cur_inode = *p; continue 'path_iter; } else { - return Err(__WASI_EACCES); + return Err(Errno::Access); } } "." => continue 'path_iter, @@ -942,7 +956,7 @@ impl WasiFs { .fs_backing .symlink_metadata(&file) .ok() - .ok_or(__WASI_ENOENT)?; + .ok_or(Errno::Noent)?; let file_type = metadata.file_type(); // we want to insert newly opened dirs and files, but not transient symlinks // TODO: explain why (think about this deeply when well rested) @@ -985,18 +999,17 @@ impl WasiFs { #[cfg(unix)] { //use std::os::unix::fs::FileTypeExt; - let file_type: __wasi_filetype_t = if file_type.is_char_device() - { - __WASI_FILETYPE_CHARACTER_DEVICE + let file_type: Filetype = if file_type.is_char_device() { + Filetype::CharacterDevice } else if file_type.is_block_device() { - __WASI_FILETYPE_BLOCK_DEVICE + Filetype::BlockDevice } else if file_type.is_fifo() { // FIFO doesn't seem to fit any other type, so unknown - __WASI_FILETYPE_UNKNOWN + Filetype::Unknown } else if file_type.is_socket() { - // TODO: how do we know if it's a `__WASI_FILETYPE_SOCKET_STREAM` or - // a `__WASI_FILETYPE_SOCKET_DGRAM`? - __WASI_FILETYPE_SOCKET_STREAM + // TODO: how do we know if it's a `SocketStream` or + // a `SocketDgram`? + Filetype::SocketStream } else { unimplemented!("state::get_inode_at_path unknown file type: not file, directory, symlink, char device, block device, fifo, or socket"); }; @@ -1012,9 +1025,9 @@ impl WasiFs { kind, false, file.to_string_lossy().to_string(), - __wasi_filestat_t { + Filestat { st_filetype: file_type, - ..__wasi_filestat_t::default() + ..Filestat::default() }, ); @@ -1080,14 +1093,14 @@ impl WasiFs { { cur_inode = *entry; } else { - return Err(__WASI_ENOENT); + return Err(Errno::Noent); } } Kind::File { .. } | Kind::Socket { .. } | Kind::Pipe { .. } | Kind::EventNotifications { .. } => { - return Err(__WASI_ENOTDIR); + return Err(Errno::Notdir); } Kind::Symlink { base_po_dir, @@ -1151,11 +1164,11 @@ impl WasiFs { &self, inodes: &WasiInodes, path: &'path Path, - ) -> Result<(__wasi_fd_t, &'path Path), __wasi_errno_t> { + ) -> Result<(WasiFd, &'path Path), Errno> { enum BaseFdAndRelPath<'a> { None, BestMatch { - fd: __wasi_fd_t, + fd: WasiFd, rel_path: &'a Path, max_seen: usize, }, @@ -1199,7 +1212,7 @@ impl WasiFs { } match res { // this error may not make sense depending on where it's called - BaseFdAndRelPath::None => Err(__WASI_EINVAL), + BaseFdAndRelPath::None => Err(Errno::Inval), BaseFdAndRelPath::BestMatch { fd, rel_path, .. } => Ok((fd, rel_path)), } } @@ -1209,9 +1222,9 @@ impl WasiFs { pub(crate) fn path_depth_from_fd( &self, inodes: &WasiInodes, - fd: __wasi_fd_t, + fd: WasiFd, inode: Inode, - ) -> Result { + ) -> Result { let mut counter = 0; let base_inode = self.get_fd_inode(fd)?; let mut cur_inode = inode; @@ -1226,7 +1239,7 @@ impl WasiFs { cur_inode = *p; } } - _ => return Err(__WASI_EINVAL), + _ => return Err(Errno::Inval), } } @@ -1242,10 +1255,10 @@ impl WasiFs { pub(crate) fn get_inode_at_path( &self, inodes: &mut WasiInodes, - base: __wasi_fd_t, + base: WasiFd, path: &str, follow_symlinks: bool, - ) -> Result { + ) -> Result { let start_inode = if !path.starts_with('/') && self.is_wasix.load(Ordering::Acquire) { let (cur_inode, _) = self.get_current_dir(inodes, base)?; cur_inode @@ -1261,15 +1274,15 @@ impl WasiFs { pub(crate) fn get_parent_inode_at_path( &self, inodes: &mut WasiInodes, - base: __wasi_fd_t, + base: WasiFd, path: &Path, follow_symlinks: bool, - ) -> Result<(Inode, String), __wasi_errno_t> { + ) -> Result<(Inode, String), Errno> { let mut parent_dir = std::path::PathBuf::new(); let mut components = path.components().rev(); let new_entity_name = components .next() - .ok_or(__WASI_EINVAL)? + .ok_or(Errno::Inval)? .as_os_str() .to_string_lossy() .to_string(); @@ -1280,70 +1293,59 @@ impl WasiFs { .map(|v| (v, new_entity_name)) } - pub fn get_fd(&self, fd: __wasi_fd_t) -> Result { + pub fn get_fd(&self, fd: WasiFd) -> Result { self.fd_map .read() .unwrap() .get(&fd) - .ok_or(__WASI_EBADF) + .ok_or(Errno::Badf) .map(|a| a.clone()) } - pub fn get_fd_inode( - &self, - fd: __wasi_fd_t, - ) -> Result { + pub fn get_fd_inode(&self, fd: WasiFd) -> Result { self.fd_map .read() .unwrap() .get(&fd) - .ok_or(__WASI_EBADF) + .ok_or(Errno::Badf) .map(|a| a.inode) } - pub fn filestat_fd( - &self, - inodes: &WasiInodes, - fd: __wasi_fd_t, - ) -> Result<__wasi_filestat_t, __wasi_errno_t> { + pub fn filestat_fd(&self, inodes: &WasiInodes, fd: WasiFd) -> Result { let inode = self.get_fd_inode(fd)?; Ok(*inodes.arena[inode].stat.read().unwrap().deref()) } - pub fn fdstat( - &self, - inodes: &WasiInodes, - fd: __wasi_fd_t, - ) -> Result<__wasi_fdstat_t, __wasi_errno_t> { + pub fn fdstat(&self, inodes: &WasiInodes, fd: WasiFd) -> Result { match fd { __WASI_STDIN_FILENO => { - return Ok(__wasi_fdstat_t { - fs_filetype: __WASI_FILETYPE_CHARACTER_DEVICE, - fs_flags: 0, + return Ok(Fdstat { + fs_filetype: Filetype::CharacterDevice, + fs_flags: Fdflags::empty(), fs_rights_base: STDIN_DEFAULT_RIGHTS, - fs_rights_inheriting: 0, + fs_rights_inheriting: Rights::empty(), }) } __WASI_STDOUT_FILENO => { - return Ok(__wasi_fdstat_t { - fs_filetype: __WASI_FILETYPE_CHARACTER_DEVICE, - fs_flags: __WASI_FDFLAG_APPEND, + return Ok(Fdstat { + fs_filetype: Filetype::CharacterDevice, + fs_flags: Fdflags::APPEND, fs_rights_base: STDOUT_DEFAULT_RIGHTS, - fs_rights_inheriting: 0, + fs_rights_inheriting: Rights::empty(), }) } __WASI_STDERR_FILENO => { - return Ok(__wasi_fdstat_t { - fs_filetype: __WASI_FILETYPE_CHARACTER_DEVICE, - fs_flags: __WASI_FDFLAG_APPEND, + return Ok(Fdstat { + fs_filetype: Filetype::CharacterDevice, + fs_flags: Fdflags::APPEND, fs_rights_base: STDERR_DEFAULT_RIGHTS, - fs_rights_inheriting: 0, + fs_rights_inheriting: Rights::empty(), }) } VIRTUAL_ROOT_FD => { - return Ok(__wasi_fdstat_t { - fs_filetype: __WASI_FILETYPE_DIRECTORY, - fs_flags: 0, + return Ok(Fdstat { + fs_filetype: Filetype::Directory, + fs_flags: Fdflags::empty(), // TODO: fix this fs_rights_base: ALL_RIGHTS, fs_rights_inheriting: ALL_RIGHTS, @@ -1356,12 +1358,12 @@ impl WasiFs { let guard = inodes.arena[fd.inode].read(); let deref = guard.deref(); - Ok(__wasi_fdstat_t { + Ok(Fdstat { fs_filetype: match deref { - Kind::File { .. } => __WASI_FILETYPE_REGULAR_FILE, - Kind::Dir { .. } => __WASI_FILETYPE_DIRECTORY, - Kind::Symlink { .. } => __WASI_FILETYPE_SYMBOLIC_LINK, - _ => __WASI_FILETYPE_UNKNOWN, + Kind::File { .. } => Filetype::RegularFile, + Kind::Dir { .. } => Filetype::Directory, + Kind::Symlink { .. } => Filetype::SymbolicLink, + _ => Filetype::Unknown, }, fs_flags: fd.flags, fs_rights_base: fd.rights, @@ -1369,11 +1371,7 @@ impl WasiFs { }) } - pub fn prestat_fd( - &self, - inodes: &WasiInodes, - fd: __wasi_fd_t, - ) -> Result<__wasi_prestat_t, __wasi_errno_t> { + pub fn prestat_fd(&self, inodes: &WasiInodes, fd: WasiFd) -> Result { let inode = self.get_fd_inode(fd)?; trace!("in prestat_fd {:?}", self.get_fd(fd)?); @@ -1382,13 +1380,13 @@ impl WasiFs { if inode_val.is_preopened { Ok(self.prestat_fd_inner(inode_val)) } else { - Err(__WASI_EBADF) + Err(Errno::Badf) } } - pub(crate) fn prestat_fd_inner(&self, inode_val: &InodeVal) -> __wasi_prestat_t { - __wasi_prestat_t { - pr_type: __WASI_PREOPENTYPE_DIR, + pub(crate) fn prestat_fd_inner(&self, inode_val: &InodeVal) -> Prestat { + Prestat { + pr_type: Preopentype::Dir, u: PrestatEnum::Dir { // REVIEW: pr_name_len: inode_val.name.len() as u32 + 1, @@ -1397,7 +1395,7 @@ impl WasiFs { } } - pub fn flush(&self, inodes: &WasiInodes, fd: __wasi_fd_t) -> Result<(), __wasi_errno_t> { + pub fn flush(&self, inodes: &WasiInodes, fd: WasiFd) -> Result<(), Errno> { match fd { __WASI_STDIN_FILENO => (), __WASI_STDOUT_FILENO => inodes @@ -1405,17 +1403,17 @@ impl WasiFs { .map_err(fs_error_into_wasi_err)? .as_mut() .map(|f| f.flush().map_err(map_io_err)) - .unwrap_or_else(|| Err(__WASI_EIO))?, + .unwrap_or_else(|| Err(Errno::Io))?, __WASI_STDERR_FILENO => inodes .stderr_mut(&self.fd_map) .map_err(fs_error_into_wasi_err)? .as_mut() .and_then(|f| f.flush().ok()) - .ok_or(__WASI_EIO)?, + .ok_or(Errno::Io)?, _ => { let fd = self.get_fd(fd)?; - if fd.rights & __WASI_RIGHT_FD_DATASYNC == 0 { - return Err(__WASI_EACCES); + if !fd.rights.contains(Rights::FD_DATASYNC) { + return Err(Errno::Access); } let mut guard = inodes.arena[fd.inode].write(); @@ -1423,12 +1421,12 @@ impl WasiFs { match deref_mut { Kind::File { handle: Some(file), .. - } => file.flush().map_err(|_| __WASI_EIO)?, + } => file.flush().map_err(|_| Errno::Io)?, // TODO: verify this behavior - Kind::Dir { .. } => return Err(__WASI_EISDIR), + Kind::Dir { .. } => return Err(Errno::Isdir), Kind::Symlink { .. } => unimplemented!("WasiFs::flush Kind::Symlink"), Kind::Buffer { .. } => (), - _ => return Err(__WASI_EIO), + _ => return Err(Errno::Io), } } } @@ -1442,7 +1440,7 @@ impl WasiFs { kind: Kind, is_preopened: bool, name: String, - ) -> Result { + ) -> Result { let stat = self.get_stat_for_kind(inodes, &kind)?; Ok(self.create_inode_with_stat(inodes, kind, is_preopened, name, stat)) } @@ -1455,7 +1453,7 @@ impl WasiFs { is_preopened: bool, name: String, ) -> Inode { - let stat = __wasi_filestat_t::default(); + let stat = Filestat::default(); self.create_inode_with_stat(inodes, kind, is_preopened, name, stat) } @@ -1466,7 +1464,7 @@ impl WasiFs { kind: Kind, is_preopened: bool, name: String, - mut stat: __wasi_filestat_t, + mut stat: Filestat, ) -> Inode { stat.st_ino = self.get_next_inode_index(); @@ -1480,12 +1478,12 @@ impl WasiFs { pub fn create_fd( &self, - rights: __wasi_rights_t, - rights_inheriting: __wasi_rights_t, - flags: __wasi_fdflags_t, + rights: Rights, + rights_inheriting: Rights, + flags: Fdflags, open_flags: u16, inode: Inode, - ) -> Result<__wasi_fd_t, __wasi_errno_t> { + ) -> Result { let idx = self.next_fd.fetch_add(1, Ordering::AcqRel); self.fd_map.write().unwrap().insert( idx, @@ -1501,7 +1499,7 @@ impl WasiFs { Ok(idx) } - pub fn clone_fd(&self, fd: __wasi_fd_t) -> Result<__wasi_fd_t, __wasi_errno_t> { + pub fn clone_fd(&self, fd: WasiFd) -> Result { let fd = self.get_fd(fd)?; let idx = self.next_fd.fetch_add(1, Ordering::AcqRel); self.fd_map.write().unwrap().insert( @@ -1531,10 +1529,10 @@ impl WasiFs { } fn create_virtual_root(&self, inodes: &mut WasiInodes) -> Inode { - let stat = __wasi_filestat_t { - st_filetype: __WASI_FILETYPE_DIRECTORY, + let stat = Filestat { + st_filetype: Filetype::Directory, st_ino: self.get_next_inode_index(), - ..__wasi_filestat_t::default() + ..Filestat::default() }; let root_kind = Kind::Root { entries: HashMap::new(), @@ -1555,7 +1553,7 @@ impl WasiFs { "stdout", __WASI_STDOUT_FILENO, STDOUT_DEFAULT_RIGHTS, - __WASI_FDFLAG_APPEND, + Fdflags::APPEND, ); } fn create_stdin(&self, inodes: &mut WasiInodes) { @@ -1565,7 +1563,7 @@ impl WasiFs { "stdin", __WASI_STDIN_FILENO, STDIN_DEFAULT_RIGHTS, - 0, + Fdflags::empty(), ); } fn create_stderr(&self, inodes: &mut WasiInodes) { @@ -1575,7 +1573,7 @@ impl WasiFs { "stderr", __WASI_STDERR_FILENO, STDERR_DEFAULT_RIGHTS, - __WASI_FDFLAG_APPEND, + Fdflags::APPEND, ); } @@ -1584,14 +1582,14 @@ impl WasiFs { inodes: &mut WasiInodes, handle: Box, name: &'static str, - raw_fd: __wasi_fd_t, - rights: __wasi_rights_t, - fd_flags: __wasi_fdflags_t, + raw_fd: WasiFd, + rights: Rights, + fd_flags: Fdflags, ) { - let stat = __wasi_filestat_t { - st_filetype: __WASI_FILETYPE_CHARACTER_DEVICE, + let stat = Filestat { + st_filetype: Filetype::CharacterDevice, st_ino: self.get_next_inode_index(), - ..__wasi_filestat_t::default() + ..Filestat::default() }; let kind = Kind::File { fd: Some(raw_fd), @@ -1610,7 +1608,7 @@ impl WasiFs { raw_fd, Fd { rights, - rights_inheriting: 0, + rights_inheriting: Rights::empty(), flags: fd_flags, // since we're not calling open on this, we don't need open flags open_flags: 0, @@ -1620,22 +1618,18 @@ impl WasiFs { ); } - pub fn get_stat_for_kind( - &self, - inodes: &WasiInodes, - kind: &Kind, - ) -> Result<__wasi_filestat_t, __wasi_errno_t> { + pub fn get_stat_for_kind(&self, inodes: &WasiInodes, kind: &Kind) -> Result { let md = match kind { Kind::File { handle, path, .. } => match handle { Some(wf) => { - return Ok(__wasi_filestat_t { - st_filetype: __WASI_FILETYPE_REGULAR_FILE, + return Ok(Filestat { + st_filetype: Filetype::RegularFile, st_size: wf.size(), st_atim: wf.last_accessed(), st_mtim: wf.last_modified(), st_ctim: wf.created_time(), - ..__wasi_filestat_t::default() + ..Filestat::default() }) } None => self @@ -1675,24 +1669,20 @@ impl WasiFs { _ => unreachable!("Symlink pointing to something that's not a directory as its base preopened directory"), } } - _ => return Err(__WASI_EIO), + _ => return Err(Errno::Io), }; - Ok(__wasi_filestat_t { + Ok(Filestat { st_filetype: virtual_file_type_to_wasi_file_type(md.file_type()), st_size: md.len(), st_atim: md.accessed(), st_mtim: md.modified(), st_ctim: md.created(), - ..__wasi_filestat_t::default() + ..Filestat::default() }) } /// Closes an open FD, handling all details such as FD being preopen - pub(crate) fn close_fd( - &self, - inodes: &WasiInodes, - fd: __wasi_fd_t, - ) -> Result<(), __wasi_errno_t> { + pub(crate) fn close_fd(&self, inodes: &WasiInodes, fd: WasiFd) -> Result<(), Errno> { let inode = self.get_fd_inode(fd)?; let inodeval = inodes.get_inodeval(inode)?; let is_preopened = inodeval.is_preopened; @@ -1715,7 +1705,7 @@ impl WasiFs { debug!("Closing dir {:?}", &path); let key = path .file_name() - .ok_or(__WASI_EINVAL)? + .ok_or(Errno::Inval)? .to_string_lossy() .to_string(); if let Some(p) = *parent { @@ -1753,12 +1743,12 @@ impl WasiFs { } else { // this shouldn't be possible anymore due to Root debug!("HIT UNREACHABLE CODE! Non-root directory does not have a parent"); - return Err(__WASI_EINVAL); + return Err(Errno::Inval); } } Kind::EventNotifications { .. } => {} - Kind::Root { .. } => return Err(__WASI_EACCES), - Kind::Symlink { .. } | Kind::Buffer { .. } => return Err(__WASI_EINVAL), + Kind::Root { .. } => return Err(Errno::Access), + Kind::Symlink { .. } | Kind::Buffer { .. } => return Err(Errno::Inval), } Ok(()) @@ -1770,21 +1760,21 @@ impl WasiState { pub(crate) fn fs_read_dir>( &self, path: P, - ) -> Result { + ) -> Result { self.fs .fs_backing .read_dir(path.as_ref()) .map_err(fs_error_into_wasi_err) } - pub(crate) fn fs_create_dir>(&self, path: P) -> Result<(), __wasi_errno_t> { + pub(crate) fn fs_create_dir>(&self, path: P) -> Result<(), Errno> { self.fs .fs_backing .create_dir(path.as_ref()) .map_err(fs_error_into_wasi_err) } - pub(crate) fn fs_remove_dir>(&self, path: P) -> Result<(), __wasi_errno_t> { + pub(crate) fn fs_remove_dir>(&self, path: P) -> Result<(), Errno> { self.fs .fs_backing .remove_dir(path.as_ref()) @@ -1795,14 +1785,14 @@ impl WasiState { &self, from: P, to: Q, - ) -> Result<(), __wasi_errno_t> { + ) -> Result<(), Errno> { self.fs .fs_backing .rename(from.as_ref(), to.as_ref()) .map_err(fs_error_into_wasi_err) } - pub(crate) fn fs_remove_file>(&self, path: P) -> Result<(), __wasi_errno_t> { + pub(crate) fn fs_remove_file>(&self, path: P) -> Result<(), Errno> { self.fs .fs_backing .remove_file(path.as_ref()) @@ -1938,7 +1928,7 @@ impl WasiState { /// Expects one of `__WASI_STDIN_FILENO`, `__WASI_STDOUT_FILENO`, `__WASI_STDERR_FILENO`. fn std_dev_get( &self, - fd: __wasi_fd_t, + fd: WasiFd, ) -> Result>, FsError> { let ret = WasiStateFileGuard::new(self, fd)?.map(|a| { let ret = Box::new(a); @@ -1949,15 +1939,15 @@ impl WasiState { } } -pub fn virtual_file_type_to_wasi_file_type(file_type: wasmer_vfs::FileType) -> __wasi_filetype_t { +pub fn virtual_file_type_to_wasi_file_type(file_type: wasmer_vfs::FileType) -> Filetype { // TODO: handle other file types if file_type.is_dir() { - __WASI_FILETYPE_DIRECTORY + Filetype::Directory } else if file_type.is_file() { - __WASI_FILETYPE_REGULAR_FILE + Filetype::RegularFile } else if file_type.is_symlink() { - __WASI_FILETYPE_SYMBOLIC_LINK + Filetype::SymbolicLink } else { - __WASI_FILETYPE_UNKNOWN + Filetype::Unknown } } diff --git a/lib/wasi/src/state/pipe.rs b/lib/wasi/src/state/pipe.rs index 12c0084d43d..4781ab0a02f 100644 --- a/lib/wasi/src/state/pipe.rs +++ b/lib/wasi/src/state/pipe.rs @@ -8,6 +8,7 @@ use std::sync::mpsc; use std::sync::Mutex; use wasmer::WasmSlice; use wasmer::{MemorySize, MemoryView}; +use wasmer_wasi_types::wasi::Errno; #[derive(Debug)] pub struct WasiPipe { @@ -43,7 +44,7 @@ impl WasiPipe { &mut self, memory: &MemoryView, iov: WasmSlice<__wasi_iovec_t>, - ) -> Result { + ) -> Result { loop { if let Some(buf) = self.read_buffer.as_mut() { let buf_len = buf.len(); @@ -55,7 +56,7 @@ impl WasiPipe { } } let rx = self.rx.lock().unwrap(); - let data = rx.recv().map_err(|_| __WASI_EIO)?; + let data = rx.recv().map_err(|_| Errno::Io)?; self.read_buffer.replace(Bytes::from(data)); } } @@ -64,17 +65,17 @@ impl WasiPipe { &mut self, memory: &MemoryView, iov: WasmSlice<__wasi_ciovec_t>, - ) -> Result { + ) -> Result { let buf_len: M::Offset = iov .iter() .filter_map(|a| a.read().ok()) .map(|a| a.buf_len) .sum(); - let buf_len: usize = buf_len.try_into().map_err(|_| __WASI_EINVAL)?; + let buf_len: usize = buf_len.try_into().map_err(|_| Errno::Inval)?; let mut buf = Vec::with_capacity(buf_len); write_bytes(&mut buf, memory, iov)?; let tx = self.tx.lock().unwrap(); - tx.send(buf).map_err(|_| __WASI_EIO)?; + tx.send(buf).map_err(|_| Errno::Io)?; Ok(buf_len) } diff --git a/lib/wasi/src/state/socket.rs b/lib/wasi/src/state/socket.rs index 9f1b9765478..788c0e17827 100644 --- a/lib/wasi/src/state/socket.rs +++ b/lib/wasi/src/state/socket.rs @@ -16,6 +16,7 @@ use wasmer_vnet::{ IpCidr, IpRoute, SocketHttpRequest, VirtualIcmpSocket, VirtualNetworking, VirtualRawSocket, VirtualTcpListener, VirtualTcpSocket, VirtualUdpSocket, VirtualWebSocket, }; +use wasmer_wasi_types::wasi::{Addressfamily, Errno, Fdflags, OptionTag, Sockoption, Socktype}; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; @@ -35,9 +36,9 @@ pub enum InodeHttpSocketType { //#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub enum InodeSocketKind { PreSocket { - family: __wasi_addressfamily_t, - ty: __wasi_socktype_t, - pt: __wasi_sockproto_t, + family: Addressfamily, + ty: Socktype, + pt: SockProto, addr: Option, only_v6: bool, reuse_port: bool, @@ -89,38 +90,37 @@ pub enum WasiSocketOption { Proto, } -impl From<__wasi_sockoption_t> for WasiSocketOption { - fn from(opt: __wasi_sockoption_t) -> Self { +impl From for WasiSocketOption { + fn from(opt: Sockoption) -> Self { use WasiSocketOption::*; match opt { - __WASI_SOCK_OPTION_NOOP => Noop, - __WASI_SOCK_OPTION_REUSE_PORT => ReusePort, - __WASI_SOCK_OPTION_REUSE_ADDR => ReuseAddr, - __WASI_SOCK_OPTION_NO_DELAY => NoDelay, - __WASI_SOCK_OPTION_DONT_ROUTE => DontRoute, - __WASI_SOCK_OPTION_ONLY_V6 => OnlyV6, - __WASI_SOCK_OPTION_BROADCAST => Broadcast, - __WASI_SOCK_OPTION_MULTICAST_LOOP_V4 => MulticastLoopV4, - __WASI_SOCK_OPTION_MULTICAST_LOOP_V6 => MulticastLoopV6, - __WASI_SOCK_OPTION_PROMISCUOUS => Promiscuous, - __WASI_SOCK_OPTION_LISTENING => Listening, - __WASI_SOCK_OPTION_LAST_ERROR => LastError, - __WASI_SOCK_OPTION_KEEP_ALIVE => KeepAlive, - __WASI_SOCK_OPTION_LINGER => Linger, - __WASI_SOCK_OPTION_OOB_INLINE => OobInline, - __WASI_SOCK_OPTION_RECV_BUF_SIZE => RecvBufSize, - __WASI_SOCK_OPTION_SEND_BUF_SIZE => SendBufSize, - __WASI_SOCK_OPTION_RECV_LOWAT => RecvLowat, - __WASI_SOCK_OPTION_SEND_LOWAT => SendLowat, - __WASI_SOCK_OPTION_RECV_TIMEOUT => RecvTimeout, - __WASI_SOCK_OPTION_SEND_TIMEOUT => SendTimeout, - __WASI_SOCK_OPTION_CONNECT_TIMEOUT => ConnectTimeout, - __WASI_SOCK_OPTION_ACCEPT_TIMEOUT => AcceptTimeout, - __WASI_SOCK_OPTION_TTL => Ttl, - __WASI_SOCK_OPTION_MULTICAST_TTL_V4 => MulticastTtlV4, - __WASI_SOCK_OPTION_TYPE => Type, - __WASI_SOCK_OPTION_PROTO => Proto, - _ => Noop, + Sockoption::Noop => Noop, + Sockoption::ReusePort => ReusePort, + Sockoption::ReuseAddr => ReuseAddr, + Sockoption::NoDelay => NoDelay, + Sockoption::DontRoute => DontRoute, + Sockoption::OnlyV6 => OnlyV6, + Sockoption::Broadcast => Broadcast, + Sockoption::MulticastLoopV4 => MulticastLoopV4, + Sockoption::MulticastLoopV6 => MulticastLoopV6, + Sockoption::Promiscuous => Promiscuous, + Sockoption::Listening => Listening, + Sockoption::LastError => LastError, + Sockoption::KeepAlive => KeepAlive, + Sockoption::Linger => Linger, + Sockoption::OobInline => OobInline, + Sockoption::RecvBufSize => RecvBufSize, + Sockoption::SendBufSize => SendBufSize, + Sockoption::RecvLowat => RecvLowat, + Sockoption::SendLowat => SendLowat, + Sockoption::RecvTimeout => RecvTimeout, + Sockoption::SendTimeout => SendTimeout, + Sockoption::ConnectTimeout => ConnectTimeout, + Sockoption::AcceptTimeout => AcceptTimeout, + Sockoption::Ttl => Ttl, + Sockoption::MulticastTtlV4 => MulticastTtlV4, + Sockoption::Type => Type, + Sockoption::Proto => Proto, } } } @@ -162,7 +162,7 @@ impl InodeSocket { &mut self, net: &(dyn VirtualNetworking), set_addr: SocketAddr, - ) -> Result, __wasi_errno_t> { + ) -> Result, Errno> { match &mut self.kind { InodeSocketKind::PreSocket { family, @@ -173,18 +173,18 @@ impl InodeSocket { .. } => { match *family { - __WASI_ADDRESS_FAMILY_INET4 => { + Addressfamily::Inet4 => { if !set_addr.is_ipv4() { - return Err(__WASI_EINVAL); + return Err(Errno::Inval); } } - __WASI_ADDRESS_FAMILY_INET6 => { + Addressfamily::Inet6 => { if !set_addr.is_ipv6() { - return Err(__WASI_EINVAL); + return Err(Errno::Inval); } } _ => { - return Err(__WASI_ENOTSUP); + return Err(Errno::Notsup); } } @@ -192,21 +192,21 @@ impl InodeSocket { let addr = (*addr).unwrap(); Ok(match *ty { - __WASI_SOCK_TYPE_STREAM => { + Socktype::Stream => { // we already set the socket address - next we need a bind or connect so nothing // more to do at this time None } - __WASI_SOCK_TYPE_DGRAM => { + Socktype::Dgram => { let socket = net .bind_udp(addr, *reuse_port, *reuse_addr) .map_err(net_error_into_wasi_err)?; Some(InodeSocket::new(InodeSocketKind::UdpSocket(socket))) } - _ => return Err(__WASI_EINVAL), + _ => return Err(Errno::Inval), }) } - _ => Err(__WASI_ENOTSUP), + _ => Err(Errno::Notsup), } } @@ -214,7 +214,7 @@ impl InodeSocket { &mut self, net: &(dyn VirtualNetworking), _backlog: usize, - ) -> Result, __wasi_errno_t> { + ) -> Result, Errno> { match &self.kind { InodeSocketKind::PreSocket { ty, @@ -225,9 +225,9 @@ impl InodeSocket { accept_timeout, .. } => Ok(match *ty { - __WASI_SOCK_TYPE_STREAM => { + Socktype::Stream => { if addr.is_none() { - return Err(__WASI_EINVAL); + return Err(Errno::Inval); } let addr = *addr.as_ref().unwrap(); let mut socket = net @@ -240,38 +240,38 @@ impl InodeSocket { } Some(InodeSocket::new(InodeSocketKind::TcpListener(socket))) } - _ => return Err(__WASI_ENOTSUP), + _ => return Err(Errno::Notsup), }), - InodeSocketKind::Closed => Err(__WASI_EIO), - _ => Err(__WASI_ENOTSUP), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } } pub fn accept( &self, - _fd_flags: __wasi_fdflags_t, - ) -> Result<(Box, SocketAddr), __wasi_errno_t> { + _fd_flags: Fdflags, + ) -> Result<(Box, SocketAddr), Errno> { let (sock, addr) = match &self.kind { InodeSocketKind::TcpListener(sock) => sock.accept().map_err(net_error_into_wasi_err), - InodeSocketKind::PreSocket { .. } => Err(__WASI_ENOTCONN), - InodeSocketKind::Closed => Err(__WASI_EIO), - _ => Err(__WASI_ENOTSUP), + InodeSocketKind::PreSocket { .. } => Err(Errno::Notconn), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), }?; Ok((sock, addr)) } pub fn accept_timeout( &self, - _fd_flags: __wasi_fdflags_t, + _fd_flags: Fdflags, timeout: Duration, - ) -> Result<(Box, SocketAddr), __wasi_errno_t> { + ) -> Result<(Box, SocketAddr), Errno> { let (sock, addr) = match &self.kind { InodeSocketKind::TcpListener(sock) => sock .accept_timeout(timeout) .map_err(net_error_into_wasi_err), - InodeSocketKind::PreSocket { .. } => Err(__WASI_ENOTCONN), - InodeSocketKind::Closed => Err(__WASI_EIO), - _ => Err(__WASI_ENOTSUP), + InodeSocketKind::PreSocket { .. } => Err(Errno::Notconn), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), }?; Ok((sock, addr)) } @@ -280,7 +280,7 @@ impl InodeSocket { &mut self, net: &(dyn VirtualNetworking), peer: SocketAddr, - ) -> Result, __wasi_errno_t> { + ) -> Result, Errno> { match &mut self.kind { InodeSocketKind::PreSocket { ty, @@ -290,7 +290,7 @@ impl InodeSocket { connect_timeout, .. } => Ok(match *ty { - __WASI_SOCK_TYPE_STREAM => { + Socktype::Stream => { let addr = match addr { Some(a) => *a, None => { @@ -316,19 +316,19 @@ impl InodeSocket { } Some(InodeSocket::new(InodeSocketKind::TcpStream(socket))) } - __WASI_SOCK_TYPE_DGRAM => return Err(__WASI_EINVAL), - _ => return Err(__WASI_ENOTSUP), + Socktype::Dgram => return Err(Errno::Inval), + _ => return Err(Errno::Notsup), }), InodeSocketKind::UdpSocket(sock) => { sock.connect(peer).map_err(net_error_into_wasi_err)?; Ok(None) } - InodeSocketKind::Closed => Err(__WASI_EIO), - _ => Err(__WASI_ENOTSUP), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } } - pub fn status(&self) -> Result { + pub fn status(&self) -> Result { Ok(match &self.kind { InodeSocketKind::PreSocket { .. } => WasiSocketStatus::Opening, InodeSocketKind::WebSocket(_) => WasiSocketStatus::Opened, @@ -341,14 +341,14 @@ impl InodeSocket { }) } - pub fn http_status(&self) -> Result { + pub fn http_status(&self) -> Result { Ok(match &self.kind { InodeSocketKind::HttpRequest(http, ..) => { let http = http.lock().unwrap(); let guard = http.status.lock().unwrap(); let status = guard .recv() - .map_err(|_| __WASI_EIO)? + .map_err(|_| Errno::Io)? .map_err(net_error_into_wasi_err)?; WasiHttpStatus { ok: true, @@ -357,12 +357,12 @@ impl InodeSocket { size: status.size as u64, } } - InodeSocketKind::Closed => return Err(__WASI_EIO), - _ => return Err(__WASI_ENOTSUP), + InodeSocketKind::Closed => return Err(Errno::Io), + _ => return Err(Errno::Notsup), }) } - pub fn addr_local(&self) -> Result { + pub fn addr_local(&self) -> Result { Ok(match &self.kind { InodeSocketKind::PreSocket { family, addr, .. } => { if let Some(addr) = addr { @@ -370,9 +370,9 @@ impl InodeSocket { } else { SocketAddr::new( match *family { - __WASI_ADDRESS_FAMILY_INET4 => IpAddr::V4(Ipv4Addr::UNSPECIFIED), - __WASI_ADDRESS_FAMILY_INET6 => IpAddr::V6(Ipv6Addr::UNSPECIFIED), - _ => return Err(__WASI_EINVAL), + Addressfamily::Inet4 => IpAddr::V4(Ipv4Addr::UNSPECIFIED), + Addressfamily::Inet6 => IpAddr::V6(Ipv6Addr::UNSPECIFIED), + _ => return Err(Errno::Inval), }, 0, ) @@ -388,18 +388,18 @@ impl InodeSocket { InodeSocketKind::UdpSocket(sock) => { sock.addr_local().map_err(net_error_into_wasi_err)? } - InodeSocketKind::Closed => return Err(__WASI_EIO), - _ => return Err(__WASI_ENOTSUP), + InodeSocketKind::Closed => return Err(Errno::Io), + _ => return Err(Errno::Notsup), }) } - pub fn addr_peer(&self) -> Result { + pub fn addr_peer(&self) -> Result { Ok(match &self.kind { InodeSocketKind::PreSocket { family, .. } => SocketAddr::new( match *family { - __WASI_ADDRESS_FAMILY_INET4 => IpAddr::V4(Ipv4Addr::UNSPECIFIED), - __WASI_ADDRESS_FAMILY_INET6 => IpAddr::V6(Ipv6Addr::UNSPECIFIED), - _ => return Err(__WASI_EINVAL), + Addressfamily::Inet4 => IpAddr::V4(Ipv4Addr::UNSPECIFIED), + Addressfamily::Inet6 => IpAddr::V6(Ipv6Addr::UNSPECIFIED), + _ => return Err(Errno::Inval), }, 0, ), @@ -423,16 +423,12 @@ impl InodeSocket { ) }) })?, - InodeSocketKind::Closed => return Err(__WASI_EIO), - _ => return Err(__WASI_ENOTSUP), + InodeSocketKind::Closed => return Err(Errno::Io), + _ => return Err(Errno::Notsup), }) } - pub fn set_opt_flag( - &mut self, - option: WasiSocketOption, - val: bool, - ) -> Result<(), __wasi_errno_t> { + pub fn set_opt_flag(&mut self, option: WasiSocketOption, val: bool) -> Result<(), Errno> { match &mut self.kind { InodeSocketKind::PreSocket { only_v6, @@ -444,20 +440,20 @@ impl InodeSocket { WasiSocketOption::OnlyV6 => *only_v6 = val, WasiSocketOption::ReusePort => *reuse_port = val, WasiSocketOption::ReuseAddr => *reuse_addr = val, - _ => return Err(__WASI_EINVAL), + _ => return Err(Errno::Inval), }; } InodeSocketKind::Raw(sock) => match option { WasiSocketOption::Promiscuous => { sock.set_promiscuous(val).map_err(net_error_into_wasi_err)? } - _ => return Err(__WASI_EINVAL), + _ => return Err(Errno::Inval), }, InodeSocketKind::TcpStream(sock) => match option { WasiSocketOption::NoDelay => { sock.set_nodelay(val).map_err(net_error_into_wasi_err)? } - _ => return Err(__WASI_EINVAL), + _ => return Err(Errno::Inval), }, InodeSocketKind::UdpSocket(sock) => match option { WasiSocketOption::Broadcast => { @@ -469,15 +465,15 @@ impl InodeSocket { WasiSocketOption::MulticastLoopV6 => sock .set_multicast_loop_v6(val) .map_err(net_error_into_wasi_err)?, - _ => return Err(__WASI_EINVAL), + _ => return Err(Errno::Inval), }, - InodeSocketKind::Closed => return Err(__WASI_EIO), - _ => return Err(__WASI_ENOTSUP), + InodeSocketKind::Closed => return Err(Errno::Io), + _ => return Err(Errno::Notsup), } Ok(()) } - pub fn get_opt_flag(&self, option: WasiSocketOption) -> Result { + pub fn get_opt_flag(&self, option: WasiSocketOption) -> Result { Ok(match &self.kind { InodeSocketKind::PreSocket { only_v6, @@ -488,17 +484,17 @@ impl InodeSocket { WasiSocketOption::OnlyV6 => *only_v6, WasiSocketOption::ReusePort => *reuse_port, WasiSocketOption::ReuseAddr => *reuse_addr, - _ => return Err(__WASI_EINVAL), + _ => return Err(Errno::Inval), }, InodeSocketKind::Raw(sock) => match option { WasiSocketOption::Promiscuous => { sock.promiscuous().map_err(net_error_into_wasi_err)? } - _ => return Err(__WASI_EINVAL), + _ => return Err(Errno::Inval), }, InodeSocketKind::TcpStream(sock) => match option { WasiSocketOption::NoDelay => sock.nodelay().map_err(net_error_into_wasi_err)?, - _ => return Err(__WASI_EINVAL), + _ => return Err(Errno::Inval), }, InodeSocketKind::UdpSocket(sock) => match option { WasiSocketOption::Broadcast => sock.broadcast().map_err(net_error_into_wasi_err)?, @@ -508,14 +504,14 @@ impl InodeSocket { WasiSocketOption::MulticastLoopV6 => { sock.multicast_loop_v6().map_err(net_error_into_wasi_err)? } - _ => return Err(__WASI_EINVAL), + _ => return Err(Errno::Inval), }, - InodeSocketKind::Closed => return Err(__WASI_EIO), - _ => return Err(__WASI_ENOTSUP), + InodeSocketKind::Closed => return Err(Errno::Io), + _ => return Err(Errno::Notsup), }) } - pub fn set_send_buf_size(&mut self, size: usize) -> Result<(), __wasi_errno_t> { + pub fn set_send_buf_size(&mut self, size: usize) -> Result<(), Errno> { match &mut self.kind { InodeSocketKind::PreSocket { send_buf_size, .. } => { *send_buf_size = Some(size); @@ -524,13 +520,13 @@ impl InodeSocket { sock.set_send_buf_size(size) .map_err(net_error_into_wasi_err)?; } - InodeSocketKind::Closed => return Err(__WASI_EIO), - _ => return Err(__WASI_ENOTSUP), + InodeSocketKind::Closed => return Err(Errno::Io), + _ => return Err(Errno::Notsup), } Ok(()) } - pub fn send_buf_size(&self) -> Result { + pub fn send_buf_size(&self) -> Result { match &self.kind { InodeSocketKind::PreSocket { send_buf_size, .. } => { Ok((*send_buf_size).unwrap_or_default()) @@ -538,12 +534,12 @@ impl InodeSocket { InodeSocketKind::TcpStream(sock) => { sock.send_buf_size().map_err(net_error_into_wasi_err) } - InodeSocketKind::Closed => Err(__WASI_EIO), - _ => Err(__WASI_ENOTSUP), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } } - pub fn set_recv_buf_size(&mut self, size: usize) -> Result<(), __wasi_errno_t> { + pub fn set_recv_buf_size(&mut self, size: usize) -> Result<(), Errno> { match &mut self.kind { InodeSocketKind::PreSocket { recv_buf_size, .. } => { *recv_buf_size = Some(size); @@ -552,13 +548,13 @@ impl InodeSocket { sock.set_recv_buf_size(size) .map_err(net_error_into_wasi_err)?; } - InodeSocketKind::Closed => return Err(__WASI_EIO), - _ => return Err(__WASI_ENOTSUP), + InodeSocketKind::Closed => return Err(Errno::Io), + _ => return Err(Errno::Notsup), } Ok(()) } - pub fn recv_buf_size(&self) -> Result { + pub fn recv_buf_size(&self) -> Result { match &self.kind { InodeSocketKind::PreSocket { recv_buf_size, .. } => { Ok((*recv_buf_size).unwrap_or_default()) @@ -566,31 +562,28 @@ impl InodeSocket { InodeSocketKind::TcpStream(sock) => { sock.recv_buf_size().map_err(net_error_into_wasi_err) } - InodeSocketKind::Closed => Err(__WASI_EIO), - _ => Err(__WASI_ENOTSUP), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } } - pub fn set_linger( - &mut self, - linger: Option, - ) -> Result<(), __wasi_errno_t> { + pub fn set_linger(&mut self, linger: Option) -> Result<(), Errno> { match &mut self.kind { InodeSocketKind::TcpStream(sock) => { sock.set_linger(linger).map_err(net_error_into_wasi_err) } - InodeSocketKind::PreSocket { .. } => Err(__WASI_EIO), - InodeSocketKind::Closed => Err(__WASI_EIO), - _ => Err(__WASI_ENOTSUP), + InodeSocketKind::PreSocket { .. } => Err(Errno::Io), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } } - pub fn linger(&self) -> Result, __wasi_errno_t> { + pub fn linger(&self) -> Result, Errno> { match &self.kind { InodeSocketKind::TcpStream(sock) => sock.linger().map_err(net_error_into_wasi_err), - InodeSocketKind::PreSocket { .. } => Err(__WASI_EIO), - InodeSocketKind::Closed => Err(__WASI_EIO), - _ => Err(__WASI_ENOTSUP), + InodeSocketKind::PreSocket { .. } => Err(Errno::Io), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } } @@ -598,7 +591,7 @@ impl InodeSocket { &mut self, ty: TimeType, timeout: Option, - ) -> Result<(), __wasi_errno_t> { + ) -> Result<(), Errno> { match &mut self.kind { InodeSocketKind::TcpStream(sock) => sock .set_opt_time(ty, timeout) @@ -607,7 +600,7 @@ impl InodeSocket { TimeType::AcceptTimeout => { sock.set_timeout(timeout).map_err(net_error_into_wasi_err) } - _ => Err(__WASI_EINVAL), + _ => Err(Errno::Inval), }, InodeSocketKind::PreSocket { recv_timeout, @@ -632,19 +625,19 @@ impl InodeSocket { *send_timeout = timeout; Ok(()) } - _ => Err(__WASI_EIO), + _ => Err(Errno::Io), }, - InodeSocketKind::Closed => Err(__WASI_EIO), - _ => Err(__WASI_ENOTSUP), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } } - pub fn opt_time(&self, ty: TimeType) -> Result, __wasi_errno_t> { + pub fn opt_time(&self, ty: TimeType) -> Result, Errno> { match &self.kind { InodeSocketKind::TcpStream(sock) => sock.opt_time(ty).map_err(net_error_into_wasi_err), InodeSocketKind::TcpListener(sock) => match ty { TimeType::AcceptTimeout => sock.timeout().map_err(net_error_into_wasi_err), - _ => Err(__WASI_EINVAL), + _ => Err(Errno::Inval), }, InodeSocketKind::PreSocket { recv_timeout, @@ -657,67 +650,63 @@ impl InodeSocket { TimeType::AcceptTimeout => Ok(*accept_timeout), TimeType::ReadTimeout => Ok(*recv_timeout), TimeType::WriteTimeout => Ok(*send_timeout), - _ => Err(__WASI_EINVAL), + _ => Err(Errno::Inval), }, - InodeSocketKind::Closed => Err(__WASI_EIO), - _ => Err(__WASI_ENOTSUP), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } } - pub fn set_ttl(&mut self, ttl: u32) -> Result<(), __wasi_errno_t> { + pub fn set_ttl(&mut self, ttl: u32) -> Result<(), Errno> { match &mut self.kind { InodeSocketKind::TcpStream(sock) => sock.set_ttl(ttl).map_err(net_error_into_wasi_err), InodeSocketKind::UdpSocket(sock) => sock.set_ttl(ttl).map_err(net_error_into_wasi_err), - InodeSocketKind::PreSocket { .. } => Err(__WASI_EIO), - InodeSocketKind::Closed => Err(__WASI_EIO), - _ => Err(__WASI_ENOTSUP), + InodeSocketKind::PreSocket { .. } => Err(Errno::Io), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } } - pub fn ttl(&self) -> Result { + pub fn ttl(&self) -> Result { match &self.kind { InodeSocketKind::TcpStream(sock) => sock.ttl().map_err(net_error_into_wasi_err), InodeSocketKind::UdpSocket(sock) => sock.ttl().map_err(net_error_into_wasi_err), - InodeSocketKind::PreSocket { .. } => Err(__WASI_EIO), - InodeSocketKind::Closed => Err(__WASI_EIO), - _ => Err(__WASI_ENOTSUP), + InodeSocketKind::PreSocket { .. } => Err(Errno::Io), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } } - pub fn set_multicast_ttl_v4(&mut self, ttl: u32) -> Result<(), __wasi_errno_t> { + pub fn set_multicast_ttl_v4(&mut self, ttl: u32) -> Result<(), Errno> { match &mut self.kind { InodeSocketKind::UdpSocket(sock) => sock .set_multicast_ttl_v4(ttl) .map_err(net_error_into_wasi_err), - InodeSocketKind::PreSocket { .. } => Err(__WASI_EIO), - InodeSocketKind::Closed => Err(__WASI_EIO), - _ => Err(__WASI_ENOTSUP), + InodeSocketKind::PreSocket { .. } => Err(Errno::Io), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } } - pub fn multicast_ttl_v4(&self) -> Result { + pub fn multicast_ttl_v4(&self) -> Result { match &self.kind { InodeSocketKind::UdpSocket(sock) => { sock.multicast_ttl_v4().map_err(net_error_into_wasi_err) } - InodeSocketKind::PreSocket { .. } => Err(__WASI_EIO), - InodeSocketKind::Closed => Err(__WASI_EIO), - _ => Err(__WASI_ENOTSUP), + InodeSocketKind::PreSocket { .. } => Err(Errno::Io), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } } - pub fn join_multicast_v4( - &mut self, - multiaddr: Ipv4Addr, - iface: Ipv4Addr, - ) -> Result<(), __wasi_errno_t> { + pub fn join_multicast_v4(&mut self, multiaddr: Ipv4Addr, iface: Ipv4Addr) -> Result<(), Errno> { match &mut self.kind { InodeSocketKind::UdpSocket(sock) => sock .join_multicast_v4(multiaddr, iface) .map_err(net_error_into_wasi_err), - InodeSocketKind::PreSocket { .. } => Err(__WASI_EIO), - InodeSocketKind::Closed => Err(__WASI_EIO), - _ => Err(__WASI_ENOTSUP), + InodeSocketKind::PreSocket { .. } => Err(Errno::Io), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } } @@ -725,44 +714,36 @@ impl InodeSocket { &mut self, multiaddr: Ipv4Addr, iface: Ipv4Addr, - ) -> Result<(), __wasi_errno_t> { + ) -> Result<(), Errno> { match &mut self.kind { InodeSocketKind::UdpSocket(sock) => sock .leave_multicast_v4(multiaddr, iface) .map_err(net_error_into_wasi_err), - InodeSocketKind::PreSocket { .. } => Err(__WASI_EIO), - InodeSocketKind::Closed => Err(__WASI_EIO), - _ => Err(__WASI_ENOTSUP), + InodeSocketKind::PreSocket { .. } => Err(Errno::Io), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } } - pub fn join_multicast_v6( - &mut self, - multiaddr: Ipv6Addr, - iface: u32, - ) -> Result<(), __wasi_errno_t> { + pub fn join_multicast_v6(&mut self, multiaddr: Ipv6Addr, iface: u32) -> Result<(), Errno> { match &mut self.kind { InodeSocketKind::UdpSocket(sock) => sock .join_multicast_v6(multiaddr, iface) .map_err(net_error_into_wasi_err), - InodeSocketKind::PreSocket { .. } => Err(__WASI_EIO), - InodeSocketKind::Closed => Err(__WASI_EIO), - _ => Err(__WASI_ENOTSUP), + InodeSocketKind::PreSocket { .. } => Err(Errno::Io), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } } - pub fn leave_multicast_v6( - &mut self, - multiaddr: Ipv6Addr, - iface: u32, - ) -> Result<(), __wasi_errno_t> { + pub fn leave_multicast_v6(&mut self, multiaddr: Ipv6Addr, iface: u32) -> Result<(), Errno> { match &mut self.kind { InodeSocketKind::UdpSocket(sock) => sock .leave_multicast_v6(multiaddr, iface) .map_err(net_error_into_wasi_err), - InodeSocketKind::PreSocket { .. } => Err(__WASI_EIO), - InodeSocketKind::Closed => Err(__WASI_EIO), - _ => Err(__WASI_ENOTSUP), + InodeSocketKind::PreSocket { .. } => Err(Errno::Io), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } } @@ -770,13 +751,13 @@ impl InodeSocket { &mut self, memory: &MemoryView, iov: WasmSlice<__wasi_ciovec_t>, - ) -> Result { + ) -> Result { let buf_len: M::Offset = iov .iter() .filter_map(|a| a.read().ok()) .map(|a| a.buf_len) .sum(); - let buf_len: usize = buf_len.try_into().map_err(|_| __WASI_EINVAL)?; + let buf_len: usize = buf_len.try_into().map_err(|_| Errno::Inval)?; let mut buf = Vec::with_capacity(buf_len); write_bytes(&mut buf, memory, iov)?; match &mut self.kind { @@ -785,13 +766,13 @@ impl InodeSocket { match ty { InodeHttpSocketType::Request => { if sock.request.is_none() { - return Err(__WASI_EIO); + return Err(Errno::Io); } let request = sock.request.as_ref().unwrap(); - request.send(buf).map(|_| buf_len).map_err(|_| __WASI_EIO) + request.send(buf).map(|_| buf_len).map_err(|_| Errno::Io) } _ => { - return Err(__WASI_EIO); + return Err(Errno::Io); } } } @@ -808,14 +789,14 @@ impl InodeSocket { InodeSocketKind::UdpSocket(sock) => { sock.send(Bytes::from(buf)).map_err(net_error_into_wasi_err) } - InodeSocketKind::PreSocket { .. } => Err(__WASI_ENOTCONN), - InodeSocketKind::Closed => Err(__WASI_EIO), - _ => Err(__WASI_ENOTSUP), + InodeSocketKind::PreSocket { .. } => Err(Errno::Notconn), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } .map(|_| buf_len) } - pub fn send_bytes(&mut self, buf: Bytes) -> Result { + pub fn send_bytes(&mut self, buf: Bytes) -> Result { let buf_len = buf.len(); match &mut self.kind { InodeSocketKind::HttpRequest(sock, ty) => { @@ -823,16 +804,16 @@ impl InodeSocket { match ty { InodeHttpSocketType::Request => { if sock.request.is_none() { - return Err(__WASI_EIO); + return Err(Errno::Io); } let request = sock.request.as_ref().unwrap(); request .send(buf.to_vec()) .map(|_| buf_len) - .map_err(|_| __WASI_EIO) + .map_err(|_| Errno::Io) } _ => { - return Err(__WASI_EIO); + return Err(Errno::Io); } } } @@ -843,9 +824,9 @@ impl InodeSocket { InodeSocketKind::Raw(sock) => sock.send(buf).map_err(net_error_into_wasi_err), InodeSocketKind::TcpStream(sock) => sock.send(buf).map_err(net_error_into_wasi_err), InodeSocketKind::UdpSocket(sock) => sock.send(buf).map_err(net_error_into_wasi_err), - InodeSocketKind::PreSocket { .. } => Err(__WASI_ENOTCONN), - InodeSocketKind::Closed => Err(__WASI_EIO), - _ => Err(__WASI_ENOTSUP), + InodeSocketKind::PreSocket { .. } => Err(Errno::Notconn), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } .map(|_| buf_len) } @@ -855,7 +836,7 @@ impl InodeSocket { memory: &MemoryView, iov: WasmSlice<__wasi_ciovec_t>, addr: WasmPtr<__wasi_addr_port_t, M>, - ) -> Result { + ) -> Result { let (addr_ip, addr_port) = read_ip_port(memory, addr)?; let addr = SocketAddr::new(addr_ip, addr_port); let buf_len: M::Offset = iov @@ -863,7 +844,7 @@ impl InodeSocket { .filter_map(|a| a.read().ok()) .map(|a| a.buf_len) .sum(); - let buf_len: usize = buf_len.try_into().map_err(|_| __WASI_EINVAL)?; + let buf_len: usize = buf_len.try_into().map_err(|_| Errno::Inval)?; let mut buf = Vec::with_capacity(buf_len); write_bytes(&mut buf, memory, iov)?; match &mut self.kind { @@ -873,9 +854,9 @@ impl InodeSocket { InodeSocketKind::UdpSocket(sock) => sock .send_to(Bytes::from(buf), addr) .map_err(net_error_into_wasi_err), - InodeSocketKind::PreSocket { .. } => Err(__WASI_ENOTCONN), - InodeSocketKind::Closed => Err(__WASI_EIO), - _ => Err(__WASI_ENOTSUP), + InodeSocketKind::PreSocket { .. } => Err(Errno::Notconn), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } .map(|_| buf_len) } @@ -884,7 +865,7 @@ impl InodeSocket { &mut self, memory: &MemoryView, iov: WasmSlice<__wasi_iovec_t>, - ) -> Result { + ) -> Result { loop { if let Some(buf) = self.read_buffer.as_mut() { let buf_len = buf.len(); @@ -905,22 +886,22 @@ impl InodeSocket { match ty { InodeHttpSocketType::Response => { if sock.response.is_none() { - return Err(__WASI_EIO); + return Err(Errno::Io); } let response = sock.response.as_ref().unwrap(); - Bytes::from(response.recv().map_err(|_| __WASI_EIO)?) + Bytes::from(response.recv().map_err(|_| Errno::Io)?) } InodeHttpSocketType::Headers => { if sock.headers.is_none() { - return Err(__WASI_EIO); + return Err(Errno::Io); } let headers = sock.headers.as_ref().unwrap(); - let headers = headers.recv().map_err(|_| __WASI_EIO)?; + let headers = headers.recv().map_err(|_| Errno::Io)?; let headers = format!("{}: {}", headers.0, headers.1); Bytes::from(headers.as_bytes().to_vec()) } _ => { - return Err(__WASI_EIO); + return Err(Errno::Io); } } } @@ -940,9 +921,9 @@ impl InodeSocket { let read = sock.recv().map_err(net_error_into_wasi_err)?; read.data } - InodeSocketKind::PreSocket { .. } => return Err(__WASI_ENOTCONN), - InodeSocketKind::Closed => return Err(__WASI_EIO), - _ => return Err(__WASI_ENOTSUP), + InodeSocketKind::PreSocket { .. } => return Err(Errno::Notconn), + InodeSocketKind::Closed => return Err(Errno::Io), + _ => return Err(Errno::Notsup), }; self.read_buffer.replace(data); self.read_addr.take(); @@ -954,7 +935,7 @@ impl InodeSocket { memory: &MemoryView, iov: WasmSlice<__wasi_iovec_t>, addr: WasmPtr<__wasi_addr_port_t, M>, - ) -> Result { + ) -> Result { loop { if let Some(buf) = self.read_buffer.as_mut() { if !buf.is_empty() { @@ -972,16 +953,16 @@ impl InodeSocket { InodeSocketKind::UdpSocket(sock) => { sock.recv_from().map_err(net_error_into_wasi_err)? } - InodeSocketKind::PreSocket { .. } => return Err(__WASI_ENOTCONN), - InodeSocketKind::Closed => return Err(__WASI_EIO), - _ => return Err(__WASI_ENOTSUP), + InodeSocketKind::PreSocket { .. } => return Err(Errno::Notconn), + InodeSocketKind::Closed => return Err(Errno::Io), + _ => return Err(Errno::Notsup), }; self.read_buffer.replace(rcv.data); self.read_addr.replace(rcv.addr); } } - pub fn shutdown(&mut self, how: std::net::Shutdown) -> Result<(), __wasi_errno_t> { + pub fn shutdown(&mut self, how: std::net::Shutdown) -> Result<(), Errno> { use std::net::Shutdown; match &mut self.kind { InodeSocketKind::TcpStream(sock) => { @@ -1004,9 +985,9 @@ impl InodeSocket { } }; } - InodeSocketKind::PreSocket { .. } => return Err(__WASI_ENOTCONN), - InodeSocketKind::Closed => return Err(__WASI_EIO), - _ => return Err(__WASI_ENOTSUP), + InodeSocketKind::PreSocket { .. } => return Err(Errno::Notconn), + InodeSocketKind::Closed => return Err(Errno::Io), + _ => return Err(Errno::Notsup), } Ok(()) } @@ -1132,25 +1113,25 @@ impl Drop for InodeSocket { pub(crate) fn read_ip( memory: &MemoryView, ptr: WasmPtr<__wasi_addr_t, M>, -) -> Result { +) -> Result { let addr_ptr = ptr.deref(memory); let addr = addr_ptr.read().map_err(crate::mem_error_to_wasi)?; let o = addr.u.octs; Ok(match addr.tag { - __WASI_ADDRESS_FAMILY_INET4 => IpAddr::V4(Ipv4Addr::new(o[0], o[1], o[2], o[3])), - __WASI_ADDRESS_FAMILY_INET6 => { + Addressfamily::Inet4 => IpAddr::V4(Ipv4Addr::new(o[0], o[1], o[2], o[3])), + Addressfamily::Inet6 => { let [a, b, c, d, e, f, g, h] = unsafe { transmute::<_, [u16; 8]>(o) }; IpAddr::V6(Ipv6Addr::new(a, b, c, d, e, f, g, h)) } - _ => return Err(__WASI_EINVAL), + _ => return Err(Errno::Inval), }) } pub(crate) fn read_ip_v4( memory: &MemoryView, ptr: WasmPtr<__wasi_addr_ip4_t, M>, -) -> Result { +) -> Result { let addr_ptr = ptr.deref(memory); let addr = addr_ptr.read().map_err(crate::mem_error_to_wasi)?; @@ -1161,7 +1142,7 @@ pub(crate) fn read_ip_v4( pub(crate) fn read_ip_v6( memory: &MemoryView, ptr: WasmPtr<__wasi_addr_ip6_t, M>, -) -> Result { +) -> Result { let addr_ptr = ptr.deref(memory); let addr = addr_ptr.read().map_err(crate::mem_error_to_wasi)?; @@ -1173,12 +1154,12 @@ pub(crate) fn write_ip( memory: &MemoryView, ptr: WasmPtr<__wasi_addr_t, M>, ip: IpAddr, -) -> Result<(), __wasi_errno_t> { +) -> Result<(), Errno> { let ip = match ip { IpAddr::V4(ip) => { let o = ip.octets(); __wasi_addr_t { - tag: __WASI_ADDRESS_FAMILY_INET4, + tag: Addressfamily::Inet4, u: __wasi_addr_u { octs: [o[0], o[1], o[2], o[3], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], }, @@ -1187,7 +1168,7 @@ pub(crate) fn write_ip( IpAddr::V6(ip) => { let o = ip.octets(); __wasi_addr_t { - tag: __WASI_ADDRESS_FAMILY_INET6, + tag: Addressfamily::Inet6, u: __wasi_addr_u { octs: o }, } } @@ -1202,17 +1183,17 @@ pub(crate) fn write_ip( pub(crate) fn read_cidr( memory: &MemoryView, ptr: WasmPtr<__wasi_cidr_t, M>, -) -> Result { +) -> Result { let addr_ptr = ptr.deref(memory); let addr = addr_ptr.read().map_err(crate::mem_error_to_wasi)?; let o = addr.u.octs; Ok(match addr.tag { - __WASI_ADDRESS_FAMILY_INET4 => IpCidr { + Addressfamily::Inet4 => IpCidr { ip: IpAddr::V4(Ipv4Addr::new(o[0], o[1], o[2], o[3])), prefix: o[4], }, - __WASI_ADDRESS_FAMILY_INET6 => { + Addressfamily::Inet6 => { let [a, b, c, d, e, f, g, h] = { let o = [ o[0], o[1], o[2], o[3], o[4], o[5], o[6], o[7], o[8], o[9], o[10], o[11], @@ -1225,7 +1206,7 @@ pub(crate) fn read_cidr( prefix: o[16], } } - _ => return Err(__WASI_EINVAL), + _ => return Err(Errno::Inval), }) } @@ -1234,13 +1215,13 @@ pub(crate) fn write_cidr( memory: &MemoryView, ptr: WasmPtr<__wasi_cidr_t, M>, cidr: IpCidr, -) -> Result<(), __wasi_errno_t> { +) -> Result<(), Errno> { let p = cidr.prefix; let cidr = match cidr.ip { IpAddr::V4(ip) => { let o = ip.octets(); __wasi_cidr_t { - tag: __WASI_ADDRESS_FAMILY_INET4, + tag: Addressfamily::Inet4, u: __wasi_cidr_u { octs: [ o[0], o[1], o[2], o[3], p, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -1251,7 +1232,7 @@ pub(crate) fn write_cidr( IpAddr::V6(ip) => { let o = ip.octets(); __wasi_cidr_t { - tag: __WASI_ADDRESS_FAMILY_INET6, + tag: Addressfamily::Inet6, u: __wasi_cidr_u { octs: [ o[0], o[1], o[2], o[3], o[4], o[5], o[6], o[7], o[8], o[9], o[10], o[11], @@ -1270,17 +1251,17 @@ pub(crate) fn write_cidr( pub(crate) fn read_ip_port( memory: &MemoryView, ptr: WasmPtr<__wasi_addr_port_t, M>, -) -> Result<(IpAddr, u16), __wasi_errno_t> { +) -> Result<(IpAddr, u16), Errno> { let addr_ptr = ptr.deref(memory); let addr = addr_ptr.read().map_err(crate::mem_error_to_wasi)?; let o = addr.u.octs; Ok(match addr.tag { - __WASI_ADDRESS_FAMILY_INET4 => { + Addressfamily::Inet4 => { let port = u16::from_ne_bytes([o[0], o[1]]); (IpAddr::V4(Ipv4Addr::new(o[2], o[3], o[4], o[5])), port) } - __WASI_ADDRESS_FAMILY_INET6 => { + Addressfamily::Inet6 => { let [a, b, c, d, e, f, g, h] = { let o = [ o[2], o[3], o[4], o[5], o[6], o[7], o[8], o[9], o[10], o[11], o[12], o[13], @@ -1293,7 +1274,7 @@ pub(crate) fn read_ip_port( u16::from_ne_bytes([o[0], o[1]]), ) } - _ => return Err(__WASI_EINVAL), + _ => return Err(Errno::Inval), }) } @@ -1303,13 +1284,13 @@ pub(crate) fn write_ip_port( ptr: WasmPtr<__wasi_addr_port_t, M>, ip: IpAddr, port: u16, -) -> Result<(), __wasi_errno_t> { +) -> Result<(), Errno> { let p = port.to_be_bytes(); let ipport = match ip { IpAddr::V4(ip) => { let o = ip.octets(); __wasi_addr_port_t { - tag: __WASI_ADDRESS_FAMILY_INET4, + tag: Addressfamily::Inet4, u: __wasi_addr_port_u { octs: [ p[0], p[1], o[0], o[1], o[2], o[3], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -1320,7 +1301,7 @@ pub(crate) fn write_ip_port( IpAddr::V6(ip) => { let o = ip.octets(); __wasi_addr_port_t { - tag: __WASI_ADDRESS_FAMILY_INET6, + tag: Addressfamily::Inet6, u: __wasi_addr_port_u { octs: [ p[0], p[1], o[0], o[1], o[2], o[3], o[4], o[5], o[6], o[7], o[8], o[9], @@ -1339,8 +1320,8 @@ pub(crate) fn write_ip_port( #[allow(dead_code)] pub(crate) fn read_route( memory: &MemoryView, - ptr: WasmPtr<__wasi_route_t, M>, -) -> Result { + ptr: WasmPtr, +) -> Result { let route_ptr = ptr.deref(memory); let route = route_ptr.read().map_err(crate::mem_error_to_wasi)?; @@ -1348,11 +1329,11 @@ pub(crate) fn read_route( cidr: { let o = route.cidr.u.octs; match route.cidr.tag { - __WASI_ADDRESS_FAMILY_INET4 => IpCidr { + Addressfamily::Inet4 => IpCidr { ip: IpAddr::V4(Ipv4Addr::new(o[0], o[1], o[2], o[3])), prefix: o[4], }, - __WASI_ADDRESS_FAMILY_INET6 => { + Addressfamily::Inet6 => { let [a, b, c, d, e, f, g, h] = { let o = [ o[0], o[1], o[2], o[3], o[4], o[5], o[6], o[7], o[8], o[9], o[10], @@ -1365,45 +1346,43 @@ pub(crate) fn read_route( prefix: o[16], } } - _ => return Err(__WASI_EINVAL), + _ => return Err(Errno::Inval), } }, via_router: { let o = route.via_router.u.octs; match route.via_router.tag { - __WASI_ADDRESS_FAMILY_INET4 => IpAddr::V4(Ipv4Addr::new(o[0], o[1], o[2], o[3])), - __WASI_ADDRESS_FAMILY_INET6 => { + Addressfamily::Inet4 => IpAddr::V4(Ipv4Addr::new(o[0], o[1], o[2], o[3])), + Addressfamily::Inet6 => { let [a, b, c, d, e, f, g, h] = unsafe { transmute::<_, [u16; 8]>(o) }; IpAddr::V6(Ipv6Addr::new(a, b, c, d, e, f, g, h)) } - _ => return Err(__WASI_EINVAL), + _ => return Err(Errno::Inval), } }, preferred_until: match route.preferred_until.tag { - __WASI_OPTION_NONE => None, - __WASI_OPTION_SOME => Some(Duration::from_nanos(route.preferred_until.u)), - _ => return Err(__WASI_EINVAL), + OptionTag::None => None, + OptionTag::Some => Some(Duration::from_nanos(route.preferred_until.u)), }, expires_at: match route.expires_at.tag { - __WASI_OPTION_NONE => None, - __WASI_OPTION_SOME => Some(Duration::from_nanos(route.expires_at.u)), - _ => return Err(__WASI_EINVAL), + OptionTag::None => None, + OptionTag::Some => Some(Duration::from_nanos(route.expires_at.u)), }, }) } pub(crate) fn write_route( memory: &MemoryView, - ptr: WasmPtr<__wasi_route_t, M>, + ptr: WasmPtr, route: IpRoute, -) -> Result<(), __wasi_errno_t> { +) -> Result<(), Errno> { let cidr = { let p = route.cidr.prefix; match route.cidr.ip { IpAddr::V4(ip) => { let o = ip.octets(); __wasi_cidr_t { - tag: __WASI_ADDRESS_FAMILY_INET4, + tag: Addressfamily::Inet4, u: __wasi_cidr_u { octs: [ o[0], o[1], o[2], o[3], p, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -1414,7 +1393,7 @@ pub(crate) fn write_route( IpAddr::V6(ip) => { let o = ip.octets(); __wasi_cidr_t { - tag: __WASI_ADDRESS_FAMILY_INET6, + tag: Addressfamily::Inet6, u: __wasi_cidr_u { octs: [ o[0], o[1], o[2], o[3], o[4], o[5], o[6], o[7], o[8], o[9], o[10], @@ -1429,7 +1408,7 @@ pub(crate) fn write_route( IpAddr::V4(ip) => { let o = ip.octets(); __wasi_addr_t { - tag: __WASI_ADDRESS_FAMILY_INET4, + tag: Addressfamily::Inet4, u: __wasi_addr_u { octs: [o[0], o[1], o[2], o[3], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], }, @@ -1438,33 +1417,33 @@ pub(crate) fn write_route( IpAddr::V6(ip) => { let o = ip.octets(); __wasi_addr_t { - tag: __WASI_ADDRESS_FAMILY_INET6, + tag: Addressfamily::Inet6, u: __wasi_addr_u { octs: o }, } } }; let preferred_until = match route.preferred_until { - None => __wasi_option_timestamp_t { - tag: __WASI_OPTION_NONE, + None => OptionTimestamp { + tag: OptionTag::None, u: 0, }, - Some(u) => __wasi_option_timestamp_t { - tag: __WASI_OPTION_SOME, + Some(u) => OptionTimestamp { + tag: OptionTag::Some, u: u.as_nanos() as u64, }, }; let expires_at = match route.expires_at { - None => __wasi_option_timestamp_t { - tag: __WASI_OPTION_NONE, + None => OptionTimestamp { + tag: OptionTag::None, u: 0, }, - Some(u) => __wasi_option_timestamp_t { - tag: __WASI_OPTION_SOME, + Some(u) => OptionTimestamp { + tag: OptionTag::Some, u: u.as_nanos() as u64, }, }; - let route = __wasi_route_t { + let route = Route { cidr, via_router, preferred_until, @@ -1475,22 +1454,3 @@ pub(crate) fn write_route( route_ptr.write(route).map_err(crate::mem_error_to_wasi)?; Ok(()) } - -pub(crate) fn all_socket_rights() -> __wasi_rights_t { - __WASI_RIGHT_FD_FDSTAT_SET_FLAGS - | __WASI_RIGHT_FD_FILESTAT_GET - | __WASI_RIGHT_FD_READ - | __WASI_RIGHT_FD_WRITE - | __WASI_RIGHT_POLL_FD_READWRITE - | __WASI_RIGHT_SOCK_SHUTDOWN - | __WASI_RIGHT_SOCK_CONNECT - | __WASI_RIGHT_SOCK_LISTEN - | __WASI_RIGHT_SOCK_BIND - | __WASI_RIGHT_SOCK_ACCEPT - | __WASI_RIGHT_SOCK_RECV - | __WASI_RIGHT_SOCK_SEND - | __WASI_RIGHT_SOCK_ADDR_LOCAL - | __WASI_RIGHT_SOCK_ADDR_REMOTE - | __WASI_RIGHT_SOCK_RECV_FROM - | __WASI_RIGHT_SOCK_SEND_TO -} diff --git a/lib/wasi/src/state/types.rs b/lib/wasi/src/state/types.rs index 462a008f19f..f4aca85ab3f 100644 --- a/lib/wasi/src/state/types.rs +++ b/lib/wasi/src/state/types.rs @@ -1,5 +1,4 @@ /// types for use in the WASI filesystem -use crate::syscalls::types::*; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; #[cfg(all(unix, feature = "sys-poll"))] @@ -11,6 +10,7 @@ use std::{ time::Duration, }; use wasmer_vbus::BusError; +use wasmer_wasi_types::wasi::{BusErrno, Errno}; #[cfg(feature = "host-fs")] pub use wasmer_vfs::host_fs::{Stderr, Stdin, Stdout}; @@ -20,135 +20,136 @@ pub use wasmer_vfs::mem_fs::{Stderr, Stdin, Stdout}; use wasmer_vfs::{FsError, VirtualFile}; use wasmer_vnet::NetworkError; -pub fn fs_error_from_wasi_err(err: __wasi_errno_t) -> FsError { +pub fn fs_error_from_wasi_err(err: Errno) -> FsError { match err { - __WASI_EBADF => FsError::InvalidFd, - __WASI_EEXIST => FsError::AlreadyExists, - __WASI_EIO => FsError::IOError, - __WASI_EADDRINUSE => FsError::AddressInUse, - __WASI_EADDRNOTAVAIL => FsError::AddressNotAvailable, - __WASI_EPIPE => FsError::BrokenPipe, - __WASI_ECONNABORTED => FsError::ConnectionAborted, - __WASI_ECONNREFUSED => FsError::ConnectionRefused, - __WASI_ECONNRESET => FsError::ConnectionReset, - __WASI_EINTR => FsError::Interrupted, - __WASI_EINVAL => FsError::InvalidInput, - __WASI_ENOTCONN => FsError::NotConnected, - __WASI_ENODEV => FsError::NoDevice, - __WASI_ENOENT => FsError::EntityNotFound, - __WASI_EPERM => FsError::PermissionDenied, - __WASI_ETIMEDOUT => FsError::TimedOut, - __WASI_EPROTO => FsError::UnexpectedEof, - __WASI_EAGAIN => FsError::WouldBlock, - __WASI_ENOSPC => FsError::WriteZero, - __WASI_ENOTEMPTY => FsError::DirectoryNotEmpty, + Errno::Badf => FsError::InvalidFd, + Errno::Exist => FsError::AlreadyExists, + Errno::Io => FsError::IOError, + Errno::Addrinuse => FsError::AddressInUse, + Errno::Addrnotavail => FsError::AddressNotAvailable, + Errno::Pipe => FsError::BrokenPipe, + Errno::Connaborted => FsError::ConnectionAborted, + Errno::Connrefused => FsError::ConnectionRefused, + Errno::Connreset => FsError::ConnectionReset, + Errno::Intr => FsError::Interrupted, + Errno::Inval => FsError::InvalidInput, + Errno::Notconn => FsError::NotConnected, + Errno::Nodev => FsError::NoDevice, + Errno::Noent => FsError::EntityNotFound, + Errno::Perm => FsError::PermissionDenied, + Errno::Timedout => FsError::TimedOut, + Errno::Proto => FsError::UnexpectedEof, + Errno::Again => FsError::WouldBlock, + Errno::Nospc => FsError::WriteZero, + Errno::Notempty => FsError::DirectoryNotEmpty, _ => FsError::UnknownError, } } -pub fn fs_error_into_wasi_err(fs_error: FsError) -> __wasi_errno_t { +pub fn fs_error_into_wasi_err(fs_error: FsError) -> Errno { match fs_error { - FsError::AlreadyExists => __WASI_EEXIST, - FsError::AddressInUse => __WASI_EADDRINUSE, - FsError::AddressNotAvailable => __WASI_EADDRNOTAVAIL, - FsError::BaseNotDirectory => __WASI_ENOTDIR, - FsError::BrokenPipe => __WASI_EPIPE, - FsError::ConnectionAborted => __WASI_ECONNABORTED, - FsError::ConnectionRefused => __WASI_ECONNREFUSED, - FsError::ConnectionReset => __WASI_ECONNRESET, - FsError::Interrupted => __WASI_EINTR, - FsError::InvalidData => __WASI_EIO, - FsError::InvalidFd => __WASI_EBADF, - FsError::InvalidInput => __WASI_EINVAL, - FsError::IOError => __WASI_EIO, - FsError::NoDevice => __WASI_ENODEV, - FsError::NotAFile => __WASI_EINVAL, - FsError::NotConnected => __WASI_ENOTCONN, - FsError::EntityNotFound => __WASI_ENOENT, - FsError::PermissionDenied => __WASI_EPERM, - FsError::TimedOut => __WASI_ETIMEDOUT, - FsError::UnexpectedEof => __WASI_EPROTO, - FsError::WouldBlock => __WASI_EAGAIN, - FsError::WriteZero => __WASI_ENOSPC, - FsError::DirectoryNotEmpty => __WASI_ENOTEMPTY, - FsError::Lock | FsError::UnknownError => __WASI_EIO, + FsError::AlreadyExists => Errno::Exist, + FsError::AddressInUse => Errno::Addrinuse, + FsError::AddressNotAvailable => Errno::Addrnotavail, + FsError::BaseNotDirectory => Errno::Notdir, + FsError::BrokenPipe => Errno::Pipe, + FsError::ConnectionAborted => Errno::Connaborted, + FsError::ConnectionRefused => Errno::Connrefused, + FsError::ConnectionReset => Errno::Connreset, + FsError::Interrupted => Errno::Intr, + FsError::InvalidData => Errno::Io, + FsError::InvalidFd => Errno::Badf, + FsError::InvalidInput => Errno::Inval, + FsError::IOError => Errno::Io, + FsError::NoDevice => Errno::Nodev, + FsError::NotAFile => Errno::Inval, + FsError::NotConnected => Errno::Notconn, + FsError::EntityNotFound => Errno::Noent, + FsError::PermissionDenied => Errno::Perm, + FsError::TimedOut => Errno::Timedout, + FsError::UnexpectedEof => Errno::Proto, + FsError::WouldBlock => Errno::Again, + FsError::WriteZero => Errno::Nospc, + FsError::DirectoryNotEmpty => Errno::Notempty, + FsError::Lock | FsError::UnknownError => Errno::Io, } } -pub fn net_error_into_wasi_err(net_error: NetworkError) -> __wasi_errno_t { +pub fn net_error_into_wasi_err(net_error: NetworkError) -> Errno { match net_error { - NetworkError::InvalidFd => __WASI_EBADF, - NetworkError::AlreadyExists => __WASI_EEXIST, - NetworkError::Lock => __WASI_EIO, - NetworkError::IOError => __WASI_EIO, - NetworkError::AddressInUse => __WASI_EADDRINUSE, - NetworkError::AddressNotAvailable => __WASI_EADDRNOTAVAIL, - NetworkError::BrokenPipe => __WASI_EPIPE, - NetworkError::ConnectionAborted => __WASI_ECONNABORTED, - NetworkError::ConnectionRefused => __WASI_ECONNREFUSED, - NetworkError::ConnectionReset => __WASI_ECONNRESET, - NetworkError::Interrupted => __WASI_EINTR, - NetworkError::InvalidData => __WASI_EIO, - NetworkError::InvalidInput => __WASI_EINVAL, - NetworkError::NotConnected => __WASI_ENOTCONN, - NetworkError::NoDevice => __WASI_ENODEV, - NetworkError::PermissionDenied => __WASI_EPERM, - NetworkError::TimedOut => __WASI_ETIMEDOUT, - NetworkError::UnexpectedEof => __WASI_EPROTO, - NetworkError::WouldBlock => __WASI_EAGAIN, - NetworkError::WriteZero => __WASI_ENOSPC, - NetworkError::Unsupported => __WASI_ENOTSUP, - NetworkError::UnknownError => __WASI_EIO, + NetworkError::InvalidFd => Errno::Badf, + NetworkError::AlreadyExists => Errno::Exist, + NetworkError::Lock => Errno::Io, + NetworkError::IOError => Errno::Io, + NetworkError::AddressInUse => Errno::Addrinuse, + NetworkError::AddressNotAvailable => Errno::Addrnotavail, + NetworkError::BrokenPipe => Errno::Pipe, + NetworkError::ConnectionAborted => Errno::Connaborted, + NetworkError::ConnectionRefused => Errno::Connrefused, + NetworkError::ConnectionReset => Errno::Connreset, + NetworkError::Interrupted => Errno::Intr, + NetworkError::InvalidData => Errno::Io, + NetworkError::InvalidInput => Errno::Inval, + NetworkError::NotConnected => Errno::Notconn, + NetworkError::NoDevice => Errno::Nodev, + NetworkError::PermissionDenied => Errno::Perm, + NetworkError::TimedOut => Errno::Timedout, + NetworkError::UnexpectedEof => Errno::Proto, + NetworkError::WouldBlock => Errno::Again, + NetworkError::WriteZero => Errno::Nospc, + NetworkError::Unsupported => Errno::Notsup, + NetworkError::UnknownError => Errno::Io, } } -pub fn bus_error_into_wasi_err(bus_error: BusError) -> __bus_errno_t { +pub fn bus_error_into_wasi_err(bus_error: BusError) -> BusErrno { use BusError::*; match bus_error { - Serialization => __BUS_ESER, - Deserialization => __BUS_EDES, - InvalidWapm => __BUS_EWAPM, - FetchFailed => __BUS_EFETCH, - CompileError => __BUS_ECOMPILE, - InvalidABI => __BUS_EABI, - Aborted => __BUS_EABORTED, - BadHandle => __BUS_EBADHANDLE, - InvalidTopic => __BUS_ETOPIC, - BadCallback => __BUS_EBADCB, - Unsupported => __BUS_EUNSUPPORTED, - BadRequest => __BUS_EBADREQUEST, - AccessDenied => __BUS_EDENIED, - InternalError => __BUS_EINTERNAL, - MemoryAllocationFailed => __BUS_EALLOC, - InvokeFailed => __BUS_EINVOKE, - AlreadyConsumed => __BUS_ECONSUMED, - MemoryAccessViolation => __BUS_EMEMVIOLATION, - UnknownError => __BUS_EUNKNOWN, + Serialization => BusErrno::Ser, + Deserialization => BusErrno::Des, + InvalidWapm => BusErrno::Wapm, + FetchFailed => BusErrno::Fetch, + CompileError => BusErrno::Compile, + InvalidABI => BusErrno::Abi, + Aborted => BusErrno::Aborted, + BadHandle => BusErrno::Badhandle, + InvalidTopic => BusErrno::Topic, + BadCallback => BusErrno::Badcb, + Unsupported => BusErrno::Unsupported, + BadRequest => BusErrno::Badrequest, + AccessDenied => BusErrno::Denied, + InternalError => BusErrno::Internal, + MemoryAllocationFailed => BusErrno::Alloc, + InvokeFailed => BusErrno::Invoke, + AlreadyConsumed => BusErrno::Consumed, + MemoryAccessViolation => BusErrno::Memviolation, + UnknownError => BusErrno::Unknown, } } -pub fn wasi_error_into_bus_err(bus_error: __bus_errno_t) -> BusError { +pub fn wasi_error_into_bus_err(bus_error: BusErrno) -> BusError { use BusError::*; match bus_error { - __BUS_ESER => Serialization, - __BUS_EDES => Deserialization, - __BUS_EWAPM => InvalidWapm, - __BUS_EFETCH => FetchFailed, - __BUS_ECOMPILE => CompileError, - __BUS_EABI => InvalidABI, - __BUS_EABORTED => Aborted, - __BUS_EBADHANDLE => BadHandle, - __BUS_ETOPIC => InvalidTopic, - __BUS_EBADCB => BadCallback, - __BUS_EUNSUPPORTED => Unsupported, - __BUS_EBADREQUEST => BadRequest, - __BUS_EDENIED => AccessDenied, - __BUS_EINTERNAL => InternalError, - __BUS_EALLOC => MemoryAllocationFailed, - __BUS_EINVOKE => InvokeFailed, - __BUS_ECONSUMED => AlreadyConsumed, - __BUS_EMEMVIOLATION => MemoryAccessViolation, - /*__BUS_EUNKNOWN |*/ _ => UnknownError, + BusErrno::Success => UnknownError, + BusErrno::Ser => Serialization, + BusErrno::Des => Deserialization, + BusErrno::Wapm => InvalidWapm, + BusErrno::Fetch => FetchFailed, + BusErrno::Compile => CompileError, + BusErrno::Abi => InvalidABI, + BusErrno::Aborted => Aborted, + BusErrno::Badhandle => BadHandle, + BusErrno::Topic => InvalidTopic, + BusErrno::Badcb => BadCallback, + BusErrno::Unsupported => Unsupported, + BusErrno::Badrequest => BadRequest, + BusErrno::Denied => AccessDenied, + BusErrno::Internal => InternalError, + BusErrno::Alloc => MemoryAllocationFailed, + BusErrno::Invoke => InvokeFailed, + BusErrno::Consumed => AlreadyConsumed, + BusErrno::Memviolation => MemoryAccessViolation, + BusErrno::Unknown => UnknownError, } } @@ -452,8 +453,8 @@ impl VirtualFile for Pipe { /* TODO: Think about using this trait WasiFdBacking: std::fmt::Debug { - fn get_stat(&self) -> &__wasi_filestat_t; - fn get_stat_mut(&mut self) -> &mut __wasi_filestat_t; + fn get_stat(&self) -> &Filestat; + fn get_stat_mut(&mut self) -> &mut Filestat; fn is_preopened(&self) -> bool; fn get_name(&self) -> &str; } diff --git a/lib/wasi/src/syscalls/legacy/snapshot0.rs b/lib/wasi/src/syscalls/legacy/snapshot0.rs index 033abe11e04..176e94a5d6b 100644 --- a/lib/wasi/src/syscalls/legacy/snapshot0.rs +++ b/lib/wasi/src/syscalls/legacy/snapshot0.rs @@ -1,7 +1,11 @@ use crate::syscalls; -use crate::syscalls::types::{self, snapshot0}; +use crate::syscalls::types; use crate::{mem_error_to_wasi, Memory32, MemorySize, WasiEnv, WasiError, WasiThread}; use wasmer::{AsStoreMut, FunctionEnvMut, WasmPtr}; +use wasmer_wasi_types::wasi::{ + Errno, Event, Fd, Filesize, Filestat, Filetype, Snapshot0Filestat, Snapshot0Subscription, + Snapshot0Whence, Subscription, Whence, +}; /// Wrapper around `syscalls::fd_filestat_get` with extra logic to handle the size /// difference of `wasi_filestat_t` @@ -11,19 +15,20 @@ use wasmer::{AsStoreMut, FunctionEnvMut, WasmPtr}; /// that syscall, then it may break. pub fn fd_filestat_get( mut ctx: FunctionEnvMut, - fd: types::__wasi_fd_t, - buf: WasmPtr, -) -> types::__wasi_errno_t { + fd: Fd, + buf: WasmPtr, +) -> Errno { let env = ctx.data(); let memory = env.memory_view(&ctx); + // TODO: understand what's happening inside this function, then do the correct thing // transmute the WasmPtr into a WasmPtr where T2 > T1, this will read extra memory. // The edge case of this cenv.mausing an OOB is not handled, if the new field is OOB, then the entire // memory access will fail. - let new_buf: WasmPtr = buf.cast(); + let new_buf: WasmPtr = buf.cast(); // Copy the data including the extra data - let new_filestat_setup: types::__wasi_filestat_t = wasi_try_mem!(new_buf.read(&memory)); + let new_filestat_setup: Filestat = wasi_try_mem!(new_buf.read(&memory)); // Set up complete, make the call with the pointer that will write to the // struct and some unrelated memory after the struct. @@ -36,7 +41,7 @@ pub fn fd_filestat_get( // get the values written to memory let new_filestat = wasi_try_mem!(new_buf.deref(&memory).read()); // translate the new struct into the old struct in host memory - let old_stat = snapshot0::__wasi_filestat_t { + let old_stat = Snapshot0Filestat { st_dev: new_filestat.st_dev, st_ino: new_filestat.st_ino, st_filetype: new_filestat.st_filetype, @@ -62,18 +67,20 @@ pub fn fd_filestat_get( /// difference of `wasi_filestat_t` pub fn path_filestat_get( mut ctx: FunctionEnvMut, - fd: types::__wasi_fd_t, - flags: types::__wasi_lookupflags_t, + fd: Fd, + flags: types::LookupFlags, path: WasmPtr, path_len: u32, - buf: WasmPtr, -) -> types::__wasi_errno_t { + buf: WasmPtr, +) -> Errno { + // TODO: understand what's happening inside this function, then do the correct thing + // see `fd_filestat_get` in this file for an explanation of this strange behavior let env = ctx.data(); let memory = env.memory_view(&ctx); - let new_buf: WasmPtr = buf.cast(); - let new_filestat_setup: types::__wasi_filestat_t = wasi_try_mem!(new_buf.read(&memory)); + let new_buf: WasmPtr = buf.cast(); + let new_filestat_setup: Filestat = wasi_try_mem!(new_buf.read(&memory)); let result = syscalls::path_filestat_get::(ctx.as_mut(), fd, flags, path, path_len, new_buf); @@ -82,7 +89,7 @@ pub fn path_filestat_get( let env = ctx.data(); let memory = env.memory_view(&ctx); let new_filestat = wasi_try_mem!(new_buf.deref(&memory).read()); - let old_stat = snapshot0::__wasi_filestat_t { + let old_stat = Snapshot0Filestat { st_dev: new_filestat.st_dev, st_ino: new_filestat.st_ino, st_filetype: new_filestat.st_filetype, @@ -100,20 +107,18 @@ pub fn path_filestat_get( } /// Wrapper around `syscalls::fd_seek` with extra logic to remap the values -/// of `__wasi_whence_t` +/// of `Whence` pub fn fd_seek( ctx: FunctionEnvMut, - fd: types::__wasi_fd_t, - offset: types::__wasi_filedelta_t, - whence: snapshot0::__wasi_whence_t, - newoffset: WasmPtr, -) -> Result { + fd: Fd, + offset: types::FileDelta, + whence: Snapshot0Whence, + newoffset: WasmPtr, +) -> Result { let new_whence = match whence { - snapshot0::__WASI_WHENCE_CUR => types::__WASI_WHENCE_CUR, - snapshot0::__WASI_WHENCE_END => types::__WASI_WHENCE_END, - snapshot0::__WASI_WHENCE_SET => types::__WASI_WHENCE_SET, - // if it's invalid, let the new fd_seek handle it - _ => whence, + Snapshot0Whence::Cur => Whence::Cur, + Snapshot0Whence::End => Whence::End, + Snapshot0Whence::Set => Whence::Set, }; syscalls::fd_seek::(ctx, fd, offset, new_whence, newoffset) } @@ -122,11 +127,12 @@ pub fn fd_seek( /// userdata field back pub fn poll_oneoff( mut ctx: FunctionEnvMut, - in_: WasmPtr, - out_: WasmPtr, + in_: WasmPtr, + out_: WasmPtr, nsubscriptions: u32, nevents: WasmPtr, -) -> Result { +) -> Result { + // TODO: verify that the assumptions in the comment here still applyd // in this case the new type is smaller than the old type, so it all fits into memory, // we just need to readjust and copy it @@ -138,31 +144,14 @@ pub fn poll_oneoff( let in_origs = wasi_try_mem_ok!(in_origs.read_to_vec()); // get a pointer to the smaller new type - let in_new_type_ptr: WasmPtr = in_.cast(); + let in_new_type_ptr: WasmPtr = in_.cast(); for (in_sub_new, orig) in wasi_try_mem_ok!(in_new_type_ptr.slice(&memory, nsubscriptions_offset)) .iter() .zip(in_origs.iter()) { - wasi_try_mem_ok!(in_sub_new.write(types::__wasi_subscription_t { - userdata: orig.userdata, - type_: orig.type_, - u: if orig.type_ == types::__WASI_EVENTTYPE_CLOCK { - types::__wasi_subscription_u { - clock: types::__wasi_subscription_clock_t { - clock_id: unsafe { orig.u.clock.clock_id }, - timeout: unsafe { orig.u.clock.timeout }, - precision: unsafe { orig.u.clock.precision }, - flags: unsafe { orig.u.clock.flags }, - }, - } - } else { - types::__wasi_subscription_u { - fd_readwrite: unsafe { orig.u.fd_readwrite }, - } - }, - })); + wasi_try_mem_ok!(in_sub_new.write(Subscription::from(*orig))); } // make the call diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 903abae2a27..202fb0b2048 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -1,7 +1,8 @@ #![allow(unused, clippy::too_many_arguments, clippy::cognitive_complexity)] pub mod types { - pub use wasmer_wasi_types::*; + pub use wasmer_wasi_types::types::*; + pub use wasmer_wasi_types::wasi; } #[cfg(any( @@ -23,7 +24,17 @@ pub mod wasix32; #[cfg(feature = "wasix")] pub mod wasix64; -use self::types::*; +use self::types::{ + wasi::{ + Addressfamily, Advice, Bid, BusDataFormat, BusErrno, BusHandles, Cid, Clockid, Dircookie, + Dirent, Errno, Event, EventEnum, EventFdReadwrite, Eventrwflags, Eventtype, Fd as WasiFd, + Fdflags, Fdstat, Filesize, Filestat, Filetype, Fstflags, Linkcount, OptionFd, Pid, Prestat, + Rights, Snapshot0Clockid, Sockoption, Sockstatus, Socktype, StdioMode as WasiStdioMode, + Streamsecurity, Subscription, SubscriptionEnum, SubscriptionFsReadwrite, Tid, Timestamp, + Tty, Whence, + }, + *, +}; use crate::state::{bus_error_into_wasi_err, wasi_error_into_bus_err, InodeHttpSocketType}; use crate::utils::map_io_err; use crate::WasiBusProcessId; @@ -31,10 +42,10 @@ use crate::{ mem_error_to_wasi, state::{ self, fs_error_into_wasi_err, iterate_poll_events, net_error_into_wasi_err, poll, - virtual_file_type_to_wasi_file_type, Fd, Inode, InodeSocket, InodeSocketKind, InodeVal, - Kind, PollEvent, PollEventBuilder, WasiPipe, WasiState, MAX_SYMLINKS, + virtual_file_type_to_wasi_file_type, Inode, InodeSocket, InodeSocketKind, InodeVal, Kind, + PollEvent, PollEventBuilder, WasiPipe, WasiState, MAX_SYMLINKS, }, - WasiEnv, WasiError, WasiThread, WasiThreadId, + Fd, WasiEnv, WasiError, WasiThread, WasiThreadId, }; use bytes::Bytes; use std::borrow::{Borrow, Cow}; @@ -70,13 +81,13 @@ pub use windows::*; #[cfg(any(target_arch = "wasm32"))] pub use wasm32::*; -fn to_offset(offset: usize) -> Result { - let ret: M::Offset = offset.try_into().map_err(|_| __WASI_EINVAL)?; +fn to_offset(offset: usize) -> Result { + let ret: M::Offset = offset.try_into().map_err(|_| Errno::Inval)?; Ok(ret) } -fn from_offset(offset: M::Offset) -> Result { - let ret: usize = offset.try_into().map_err(|_| __WASI_EINVAL)?; +fn from_offset(offset: M::Offset) -> Result { + let ret: usize = offset.try_into().map_err(|_| Errno::Inval)?; Ok(ret) } @@ -84,7 +95,7 @@ fn write_bytes_inner( mut write_loc: T, memory: &MemoryView, iovs_arr_cell: WasmSlice<__wasi_ciovec_t>, -) -> Result { +) -> Result { let mut bytes_written = 0usize; for iov in iovs_arr_cell.iter() { let iov_inner = iov.read().map_err(mem_error_to_wasi)?; @@ -103,7 +114,7 @@ pub(crate) fn write_bytes( mut write_loc: T, memory: &MemoryView, iovs_arr: WasmSlice<__wasi_ciovec_t>, -) -> Result { +) -> Result { let result = write_bytes_inner::<_, M>(&mut write_loc, memory, iovs_arr); write_loc.flush(); result @@ -113,7 +124,7 @@ pub(crate) fn read_bytes( mut reader: T, memory: &MemoryView, iovs_arr: WasmSlice<__wasi_iovec_t>, -) -> Result { +) -> Result { let mut bytes_read = 0usize; // We allocate the raw_bytes first once instead of @@ -139,27 +150,22 @@ pub(crate) fn read_bytes( Ok(bytes_read) } -/// checks that `rights_check_set` is a subset of `rights_set` -fn has_rights(rights_set: __wasi_rights_t, rights_check_set: __wasi_rights_t) -> bool { - rights_set | rights_check_set == rights_set -} - fn __sock_actor( ctx: &FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, - rights: __wasi_rights_t, + sock: WasiFd, + rights: Rights, actor: F, -) -> Result +) -> Result where - F: FnOnce(&crate::state::InodeSocket) -> Result, + F: FnOnce(&crate::state::InodeSocket) -> Result, { let env = ctx.data(); let (_, state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0); let fd_entry = state.fs.get_fd(sock)?; let ret = { - if rights != 0 && !has_rights(fd_entry.rights, rights) { - return Err(__WASI_EACCES); + if !rights.is_empty() && !fd_entry.rights.contains(rights) { + return Err(Errno::Access); } let inode_idx = fd_entry.inode; @@ -170,7 +176,7 @@ where match deref { Kind::Socket { socket } => actor(socket)?, _ => { - return Err(__WASI_ENOTSOCK); + return Err(Errno::Notsock); } } }; @@ -180,20 +186,20 @@ where fn __sock_actor_mut( ctx: &FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, - rights: __wasi_rights_t, + sock: WasiFd, + rights: Rights, actor: F, -) -> Result +) -> Result where - F: FnOnce(&mut crate::state::InodeSocket) -> Result, + F: FnOnce(&mut crate::state::InodeSocket) -> Result, { let env = ctx.data(); let (_, state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0); let fd_entry = state.fs.get_fd(sock)?; let ret = { - if rights != 0 && !has_rights(fd_entry.rights, rights) { - return Err(__WASI_EACCES); + if !rights.is_empty() && !fd_entry.rights.contains(rights) { + return Err(Errno::Access); } let inode_idx = fd_entry.inode; @@ -204,7 +210,7 @@ where match deref_mut { Kind::Socket { socket } => actor(socket)?, _ => { - return Err(__WASI_ENOTSOCK); + return Err(Errno::Notsock); } } }; @@ -214,21 +220,19 @@ where fn __sock_upgrade( ctx: &FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, - rights: __wasi_rights_t, + sock: WasiFd, + rights: Rights, actor: F, -) -> Result<(), __wasi_errno_t> +) -> Result<(), Errno> where - F: FnOnce( - &mut crate::state::InodeSocket, - ) -> Result, __wasi_errno_t>, + F: FnOnce(&mut crate::state::InodeSocket) -> Result, Errno>, { let env = ctx.data(); let (_, state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0); let fd_entry = state.fs.get_fd(sock)?; - if rights != 0 && !has_rights(fd_entry.rights, rights) { - return Err(__WASI_EACCES); + if !rights.is_empty() && !fd_entry.rights.contains(rights) { + return Err(Errno::Access); } let inode_idx = fd_entry.inode; @@ -245,7 +249,7 @@ where } } _ => { - return Err(__WASI_ENOTSOCK); + return Err(Errno::Notsock); } } @@ -258,7 +262,7 @@ fn write_buffer_array( from: &[Vec], ptr_buffer: WasmPtr, M>, buffer: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { let ptrs = wasi_try_mem!(ptr_buffer.slice(memory, wasi_try!(to_offset::(from.len())))); let mut current_buffer_offset = 0usize; @@ -280,15 +284,15 @@ fn write_buffer_array( current_buffer_offset += sub_buffer.len() + 1; } - __WASI_ESUCCESS + Errno::Success } -fn get_current_time_in_nanos() -> Result<__wasi_timestamp_t, __wasi_errno_t> { +fn get_current_time_in_nanos() -> Result { let now = std::time::SystemTime::now(); let duration = now .duration_since(std::time::SystemTime::UNIX_EPOCH) - .map_err(|_| __WASI_EIO)?; - Ok(duration.as_nanos() as __wasi_timestamp_t) + .map_err(|_| Errno::Io)?; + Ok(duration.as_nanos() as Timestamp) } /// ### `args_get()` @@ -304,7 +308,7 @@ pub fn args_get( mut ctx: FunctionEnvMut<'_, WasiEnv>, argv: WasmPtr, M>, argv_buf: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::args_get"); let env = ctx.data(); let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0); @@ -336,7 +340,7 @@ pub fn args_sizes_get( mut ctx: FunctionEnvMut<'_, WasiEnv>, argc: WasmPtr, argv_buf_size: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::args_sizes_get"); let env = ctx.data(); let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0); @@ -344,68 +348,74 @@ pub fn args_sizes_get( let argc = argc.deref(&memory); let argv_buf_size = argv_buf_size.deref(&memory); - let argc_val: M::Offset = wasi_try!(state.args.len().try_into().map_err(|_| __WASI_EOVERFLOW)); + let argc_val: M::Offset = wasi_try!(state.args.len().try_into().map_err(|_| Errno::Overflow)); let argv_buf_size_val: usize = state.args.iter().map(|v| v.len() + 1).sum(); let argv_buf_size_val: M::Offset = - wasi_try!(argv_buf_size_val.try_into().map_err(|_| __WASI_EOVERFLOW)); + wasi_try!(argv_buf_size_val.try_into().map_err(|_| Errno::Overflow)); wasi_try_mem!(argc.write(argc_val)); wasi_try_mem!(argv_buf_size.write(argv_buf_size_val)); debug!("=> argc={}, argv_buf_size={}", argc_val, argv_buf_size_val); - __WASI_ESUCCESS + Errno::Success } /// ### `clock_res_get()` /// Get the resolution of the specified clock /// Input: -/// - `__wasi_clockid_t clock_id` +/// - `Clockid clock_id` /// The ID of the clock to get the resolution of /// Output: -/// - `__wasi_timestamp_t *resolution` +/// - `Timestamp *resolution` /// The resolution of the clock in nanoseconds pub fn clock_res_get( mut ctx: FunctionEnvMut<'_, WasiEnv>, - clock_id: __wasi_clockid_t, - resolution: WasmPtr<__wasi_timestamp_t, M>, -) -> __wasi_errno_t { + clock_id: Clockid, + resolution: WasmPtr, +) -> Errno { trace!("wasi::clock_res_get"); let env = ctx.data(); let memory = env.memory_view(&ctx); let out_addr = resolution.deref(&memory); - let t_out = wasi_try!(platform_clock_res_get(clock_id, out_addr)); - wasi_try_mem!(resolution.write(&memory, t_out as __wasi_timestamp_t)); - __WASI_ESUCCESS + let t_out = wasi_try!(platform_clock_res_get( + Snapshot0Clockid::from(clock_id), + out_addr + )); + wasi_try_mem!(resolution.write(&memory, t_out as Timestamp)); + Errno::Success } /// ### `clock_time_get()` /// Get the time of the specified clock /// Inputs: -/// - `__wasi_clockid_t clock_id` +/// - `Clockid clock_id` /// The ID of the clock to query -/// - `__wasi_timestamp_t precision` +/// - `Timestamp precision` /// The maximum amount of error the reading may have /// Output: -/// - `__wasi_timestamp_t *time` +/// - `Timestamp *time` /// The value of the clock in nanoseconds pub fn clock_time_get( ctx: FunctionEnvMut<'_, WasiEnv>, - clock_id: __wasi_clockid_t, - precision: __wasi_timestamp_t, - time: WasmPtr<__wasi_timestamp_t, M>, -) -> __wasi_errno_t { + clock_id: Clockid, + precision: Timestamp, + time: WasmPtr, +) -> Errno { debug!( "wasi::clock_time_get clock_id: {}, precision: {}", - clock_id, precision + clock_id as u8, precision ); let env = ctx.data(); let memory = env.memory_view(&ctx); - let t_out = wasi_try!(platform_clock_time_get(clock_id, precision)); - wasi_try_mem!(time.write(&memory, t_out as __wasi_timestamp_t)); + let t_out = wasi_try!(platform_clock_time_get( + Snapshot0Clockid::from(clock_id), + precision + )); + wasi_try_mem!(time.write(&memory, t_out as Timestamp)); - let result = __WASI_ESUCCESS; + let result = Errno::Success; trace!( "time: {} => {}", wasi_try_mem!(time.deref(&memory).read()), @@ -426,7 +436,7 @@ pub fn environ_get( ctx: FunctionEnvMut<'_, WasiEnv>, environ: WasmPtr, M>, environ_buf: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { debug!( "wasi::environ_get. Environ: {:?}, environ_buf: {:?}", environ, environ_buf @@ -449,7 +459,7 @@ pub fn environ_sizes_get( ctx: FunctionEnvMut<'_, WasiEnv>, environ_count: WasmPtr, environ_buf_size: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { trace!("wasi::environ_sizes_get"); let env = ctx.data(); let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0); @@ -458,9 +468,9 @@ pub fn environ_sizes_get( let environ_buf_size = environ_buf_size.deref(&memory); let env_var_count: M::Offset = - wasi_try!(state.envs.len().try_into().map_err(|_| __WASI_EOVERFLOW)); + wasi_try!(state.envs.len().try_into().map_err(|_| Errno::Overflow)); let env_buf_size: usize = state.envs.iter().map(|v| v.len() + 1).sum(); - let env_buf_size: M::Offset = wasi_try!(env_buf_size.try_into().map_err(|_| __WASI_EOVERFLOW)); + let env_buf_size: M::Offset = wasi_try!(env_buf_size.try_into().map_err(|_| Errno::Overflow)); wasi_try_mem!(environ_count.write(env_var_count)); wasi_try_mem!(environ_buf_size.write(env_buf_size)); @@ -470,59 +480,59 @@ pub fn environ_sizes_get( env_buf_size ); - __WASI_ESUCCESS + Errno::Success } /// ### `fd_advise()` /// Advise the system about how a file will be used /// Inputs: -/// - `__wasi_fd_t fd` +/// - `Fd fd` /// The file descriptor the advice applies to -/// - `__wasi_filesize_t offset` +/// - `Filesize offset` /// The offset from which the advice applies -/// - `__wasi_filesize_t len` +/// - `Filesize len` /// The length from the offset to which the advice applies /// - `__wasi_advice_t advice` /// The advice to give pub fn fd_advise( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, - offset: __wasi_filesize_t, - len: __wasi_filesize_t, - advice: __wasi_advice_t, -) -> __wasi_errno_t { + fd: WasiFd, + offset: Filesize, + len: Filesize, + advice: Advice, +) -> Errno { debug!("wasi::fd_advise: fd={}", fd); // this is used for our own benefit, so just returning success is a valid // implementation for now - __WASI_ESUCCESS + Errno::Success } /// ### `fd_allocate` /// Allocate extra space for a file descriptor /// Inputs: -/// - `__wasi_fd_t fd` +/// - `Fd fd` /// The file descriptor to allocate for -/// - `__wasi_filesize_t offset` +/// - `Filesize offset` /// The offset from the start marking the beginning of the allocation -/// - `__wasi_filesize_t len` +/// - `Filesize len` /// The length from the offset marking the end of the allocation pub fn fd_allocate( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, - offset: __wasi_filesize_t, - len: __wasi_filesize_t, -) -> __wasi_errno_t { + fd: WasiFd, + offset: Filesize, + len: Filesize, +) -> Errno { debug!("wasi::fd_allocate"); let env = ctx.data(); let (_, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0); let fd_entry = wasi_try!(state.fs.get_fd(fd)); let inode = fd_entry.inode; - if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_ALLOCATE) { - return __WASI_EACCES; + if !fd_entry.rights.contains(Rights::FD_ALLOCATE) { + return Errno::Access; } - let new_size = wasi_try!(offset.checked_add(len).ok_or(__WASI_EINVAL)); + let new_size = wasi_try!(offset.checked_add(len).ok_or(Errno::Inval)); { let mut guard = inodes.arena[inode].write(); let deref_mut = guard.deref_mut(); @@ -531,36 +541,36 @@ pub fn fd_allocate( if let Some(handle) = handle { wasi_try!(handle.set_len(new_size).map_err(fs_error_into_wasi_err)); } else { - return __WASI_EBADF; + return Errno::Badf; } } - Kind::Socket { .. } => return __WASI_EBADF, - Kind::Pipe { .. } => return __WASI_EBADF, + Kind::Socket { .. } => return Errno::Badf, + Kind::Pipe { .. } => return Errno::Badf, Kind::Buffer { buffer } => { buffer.resize(new_size as usize, 0); } - Kind::Symlink { .. } => return __WASI_EBADF, - Kind::EventNotifications { .. } => return __WASI_EBADF, - Kind::Dir { .. } | Kind::Root { .. } => return __WASI_EISDIR, + Kind::Symlink { .. } => return Errno::Badf, + Kind::EventNotifications { .. } => return Errno::Badf, + Kind::Dir { .. } | Kind::Root { .. } => return Errno::Isdir, } } inodes.arena[inode].stat.write().unwrap().st_size = new_size; debug!("New file size: {}", new_size); - __WASI_ESUCCESS + Errno::Success } /// ### `fd_close()` /// Close an open file descriptor /// Inputs: -/// - `__wasi_fd_t fd` +/// - `Fd fd` /// A file descriptor mapping to an open file to close /// Errors: -/// - `__WASI_EISDIR` +/// - `Errno::Isdir` /// If `fd` is a directory -/// - `__WASI_EBADF` +/// - `Errno::Badf` /// If `fd` is invalid or not open -pub fn fd_close(ctx: FunctionEnvMut<'_, WasiEnv>, fd: __wasi_fd_t) -> __wasi_errno_t { +pub fn fd_close(ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd) -> Errno { debug!("wasi::fd_close: fd={}", fd); let env = ctx.data(); let (_, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0); @@ -569,43 +579,43 @@ pub fn fd_close(ctx: FunctionEnvMut<'_, WasiEnv>, fd: __wasi_fd_t) -> __wasi_err wasi_try!(state.fs.close_fd(inodes.deref(), fd)); - __WASI_ESUCCESS + Errno::Success } /// ### `fd_datasync()` /// Synchronize the file data to disk /// Inputs: -/// - `__wasi_fd_t fd` +/// - `Fd fd` /// The file descriptor to sync -pub fn fd_datasync(ctx: FunctionEnvMut<'_, WasiEnv>, fd: __wasi_fd_t) -> __wasi_errno_t { +pub fn fd_datasync(ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd) -> Errno { debug!("wasi::fd_datasync"); let env = ctx.data(); let (_, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0); let fd_entry = wasi_try!(state.fs.get_fd(fd)); - if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_DATASYNC) { - return __WASI_EACCES; + if !fd_entry.rights.contains(Rights::FD_DATASYNC) { + return Errno::Access; } if let Err(e) = state.fs.flush(inodes.deref(), fd) { e } else { - __WASI_ESUCCESS + Errno::Success } } /// ### `fd_fdstat_get()` /// Get metadata of a file descriptor /// Input: -/// - `__wasi_fd_t fd` +/// - `Fd fd` /// The file descriptor whose metadata will be accessed /// Output: -/// - `__wasi_fdstat_t *buf` +/// - `Fdstat *buf` /// The location where the metadata will be written pub fn fd_fdstat_get( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, - buf_ptr: WasmPtr<__wasi_fdstat_t, M>, -) -> __wasi_errno_t { + fd: WasiFd, + buf_ptr: WasmPtr, +) -> Errno { debug!( "wasi::fd_fdstat_get: fd={}, buf_ptr={}", fd, @@ -619,88 +629,84 @@ pub fn fd_fdstat_get( wasi_try_mem!(buf.write(stat)); - __WASI_ESUCCESS + Errno::Success } /// ### `fd_fdstat_set_flags()` /// Set file descriptor flags for a file descriptor /// Inputs: -/// - `__wasi_fd_t fd` +/// - `Fd fd` /// The file descriptor to apply the new flags to -/// - `__wasi_fdflags_t flags` +/// - `Fdflags flags` /// The flags to apply to `fd` -pub fn fd_fdstat_set_flags( - ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, - flags: __wasi_fdflags_t, -) -> __wasi_errno_t { +pub fn fd_fdstat_set_flags(ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd, flags: Fdflags) -> Errno { debug!("wasi::fd_fdstat_set_flags"); let env = ctx.data(); let (_, mut state) = env.get_memory_and_wasi_state(&ctx, 0); let mut fd_map = state.fs.fd_map.write().unwrap(); - let fd_entry = wasi_try!(fd_map.get_mut(&fd).ok_or(__WASI_EBADF)); + let fd_entry = wasi_try!(fd_map.get_mut(&fd).ok_or(Errno::Badf)); - if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_FDSTAT_SET_FLAGS) { - return __WASI_EACCES; + if !fd_entry.rights.contains(Rights::FD_FDSTAT_SET_FLAGS) { + return Errno::Access; } fd_entry.flags = flags; - __WASI_ESUCCESS + Errno::Success } /// ### `fd_fdstat_set_rights()` /// Set the rights of a file descriptor. This can only be used to remove rights /// Inputs: -/// - `__wasi_fd_t fd` +/// - `Fd fd` /// The file descriptor to apply the new rights to -/// - `__wasi_rights_t fs_rights_base` +/// - `Rights fs_rights_base` /// The rights to apply to `fd` -/// - `__wasi_rights_t fs_rights_inheriting` +/// - `Rights fs_rights_inheriting` /// The inheriting rights to apply to `fd` pub fn fd_fdstat_set_rights( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, - fs_rights_base: __wasi_rights_t, - fs_rights_inheriting: __wasi_rights_t, -) -> __wasi_errno_t { + fd: WasiFd, + fs_rights_base: Rights, + fs_rights_inheriting: Rights, +) -> Errno { debug!("wasi::fd_fdstat_set_rights"); let env = ctx.data(); let (_, mut state) = env.get_memory_and_wasi_state(&ctx, 0); let mut fd_map = state.fs.fd_map.write().unwrap(); - let fd_entry = wasi_try!(fd_map.get_mut(&fd).ok_or(__WASI_EBADF)); + let fd_entry = wasi_try!(fd_map.get_mut(&fd).ok_or(Errno::Badf)); // ensure new rights are a subset of current rights if fd_entry.rights | fs_rights_base != fd_entry.rights || fd_entry.rights_inheriting | fs_rights_inheriting != fd_entry.rights_inheriting { - return __WASI_ENOTCAPABLE; + return Errno::Notcapable; } fd_entry.rights = fs_rights_base; fd_entry.rights_inheriting = fs_rights_inheriting; - __WASI_ESUCCESS + Errno::Success } /// ### `fd_filestat_get()` /// Get the metadata of an open file /// Input: -/// - `__wasi_fd_t fd` +/// - `Fd fd` /// The open file descriptor whose metadata will be read /// Output: -/// - `__wasi_filestat_t *buf` +/// - `Filestat *buf` /// Where the metadata from `fd` will be written pub fn fd_filestat_get( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, - buf: WasmPtr<__wasi_filestat_t, M>, -) -> __wasi_errno_t { + fd: WasiFd, + buf: WasmPtr, +) -> Errno { debug!("wasi::fd_filestat_get"); let env = ctx.data(); let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0); let fd_entry = wasi_try!(state.fs.get_fd(fd)); - if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_FILESTAT_GET) { - return __WASI_EACCES; + if !fd_entry.rights.contains(Rights::FD_FILESTAT_GET) { + return Errno::Access; } let stat = wasi_try!(state.fs.filestat_fd(inodes.deref(), fd)); @@ -708,29 +714,29 @@ pub fn fd_filestat_get( let buf = buf.deref(&memory); wasi_try_mem!(buf.write(stat)); - __WASI_ESUCCESS + Errno::Success } /// ### `fd_filestat_set_size()` /// Change the size of an open file, zeroing out any new bytes /// Inputs: -/// - `__wasi_fd_t fd` +/// - `Fd fd` /// File descriptor to adjust -/// - `__wasi_filesize_t st_size` +/// - `Filesize st_size` /// New size that `fd` will be set to pub fn fd_filestat_set_size( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, - st_size: __wasi_filesize_t, -) -> __wasi_errno_t { + fd: WasiFd, + st_size: Filesize, +) -> Errno { debug!("wasi::fd_filestat_set_size"); let env = ctx.data(); let (_, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0); let fd_entry = wasi_try!(state.fs.get_fd(fd)); let inode = fd_entry.inode; - if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_FILESTAT_SET_SIZE) { - return __WASI_EACCES; + if !fd_entry.rights.contains(Rights::FD_FILESTAT_SET_SIZE) { + return Errno::Access; } { @@ -741,61 +747,60 @@ pub fn fd_filestat_set_size( if let Some(handle) = handle { wasi_try!(handle.set_len(st_size).map_err(fs_error_into_wasi_err)); } else { - return __WASI_EBADF; + return Errno::Badf; } } Kind::Buffer { buffer } => { buffer.resize(st_size as usize, 0); } - Kind::Socket { .. } => return __WASI_EBADF, - Kind::Pipe { .. } => return __WASI_EBADF, - Kind::Symlink { .. } => return __WASI_EBADF, - Kind::EventNotifications { .. } => return __WASI_EBADF, - Kind::Dir { .. } | Kind::Root { .. } => return __WASI_EISDIR, + Kind::Socket { .. } => return Errno::Badf, + Kind::Pipe { .. } => return Errno::Badf, + Kind::Symlink { .. } => return Errno::Badf, + Kind::EventNotifications { .. } => return Errno::Badf, + Kind::Dir { .. } | Kind::Root { .. } => return Errno::Isdir, } } inodes.arena[inode].stat.write().unwrap().st_size = st_size; - __WASI_ESUCCESS + Errno::Success } /// ### `fd_filestat_set_times()` /// Set timestamp metadata on a file /// Inputs: -/// - `__wasi_timestamp_t st_atim` +/// - `Timestamp st_atim` /// Last accessed time -/// - `__wasi_timestamp_t st_mtim` +/// - `Timestamp st_mtim` /// Last modified time -/// - `__wasi_fstflags_t fst_flags` +/// - `Fstflags fst_flags` /// Bit-vector for controlling which times get set pub fn fd_filestat_set_times( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, - st_atim: __wasi_timestamp_t, - st_mtim: __wasi_timestamp_t, - fst_flags: __wasi_fstflags_t, -) -> __wasi_errno_t { + fd: WasiFd, + st_atim: Timestamp, + st_mtim: Timestamp, + fst_flags: Fstflags, +) -> Errno { debug!("wasi::fd_filestat_set_times"); let env = ctx.data(); let (_, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0); let fd_entry = wasi_try!(state.fs.get_fd(fd)); - if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_FILESTAT_SET_TIMES) { - return __WASI_EACCES; + if !fd_entry.rights.contains(Rights::FD_FILESTAT_SET_TIMES) { + return Errno::Access; } - if (fst_flags & __WASI_FILESTAT_SET_ATIM != 0 && fst_flags & __WASI_FILESTAT_SET_ATIM_NOW != 0) - || (fst_flags & __WASI_FILESTAT_SET_MTIM != 0 - && fst_flags & __WASI_FILESTAT_SET_MTIM_NOW != 0) + if (fst_flags.contains(Fstflags::SET_ATIM) && fst_flags.contains(Fstflags::SET_ATIM_NOW)) + || (fst_flags.contains(Fstflags::SET_MTIM) && fst_flags.contains(Fstflags::SET_MTIM_NOW)) { - return __WASI_EINVAL; + return Errno::Inval; } let inode_idx = fd_entry.inode; let inode = &inodes.arena[inode_idx]; - if fst_flags & __WASI_FILESTAT_SET_ATIM != 0 || fst_flags & __WASI_FILESTAT_SET_ATIM_NOW != 0 { - let time_to_set = if fst_flags & __WASI_FILESTAT_SET_ATIM != 0 { + if fst_flags.contains(Fstflags::SET_ATIM) || fst_flags.contains(Fstflags::SET_ATIM_NOW) { + let time_to_set = if fst_flags.contains(Fstflags::SET_ATIM) { st_atim } else { wasi_try!(get_current_time_in_nanos()) @@ -803,8 +808,8 @@ pub fn fd_filestat_set_times( inode.stat.write().unwrap().st_atim = time_to_set; } - if fst_flags & __WASI_FILESTAT_SET_MTIM != 0 || fst_flags & __WASI_FILESTAT_SET_MTIM_NOW != 0 { - let time_to_set = if fst_flags & __WASI_FILESTAT_SET_MTIM != 0 { + if fst_flags.contains(Fstflags::SET_MTIM) || fst_flags.contains(Fstflags::SET_MTIM_NOW) { + let time_to_set = if fst_flags.contains(Fstflags::SET_MTIM) { st_mtim } else { wasi_try!(get_current_time_in_nanos()) @@ -812,32 +817,32 @@ pub fn fd_filestat_set_times( inode.stat.write().unwrap().st_mtim = time_to_set; } - __WASI_ESUCCESS + Errno::Success } /// ### `fd_pread()` /// Read from the file at the given offset without updating the file cursor. /// This acts like a stateless version of Seek + Read /// Inputs: -/// - `__wasi_fd_t fd` +/// - `Fd fd` /// The file descriptor to read the data with /// - `const __wasi_iovec_t* iovs' /// Vectors where the data will be stored /// - `size_t iovs_len` /// The number of vectors to store the data into -/// - `__wasi_filesize_t offset` +/// - `Filesize offset` /// The file cursor to use: the starting position from which data will be read /// Output: /// - `size_t nread` /// The number of bytes read pub fn fd_pread( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: WasiFd, iovs: WasmPtr<__wasi_iovec_t, M>, iovs_len: M::Offset, - offset: __wasi_filesize_t, + offset: Filesize, nread: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { trace!("wasi::fd_pread: fd={}, offset={}", fd, offset); let env = ctx.data(); let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0); @@ -857,22 +862,20 @@ pub fn fd_pread( if let Some(ref mut stdin) = guard.deref_mut() { wasi_try_ok!(read_bytes(stdin, &memory, iovs), env) } else { - return Ok(__WASI_EBADF); + return Ok(Errno::Badf); } } - __WASI_STDOUT_FILENO => return Ok(__WASI_EINVAL), - __WASI_STDERR_FILENO => return Ok(__WASI_EINVAL), + __WASI_STDOUT_FILENO => return Ok(Errno::Inval), + __WASI_STDERR_FILENO => return Ok(Errno::Inval), _ => { let inode = fd_entry.inode; - if !(has_rights(fd_entry.rights, __WASI_RIGHT_FD_READ) - && has_rights(fd_entry.rights, __WASI_RIGHT_FD_SEEK)) - { + if !fd_entry.rights.contains(Rights::FD_READ | Rights::FD_SEEK) { debug!( "Invalid rights on {:X}: expected READ and SEEK", fd_entry.rights ); - return Ok(__WASI_EACCES); + return Ok(Errno::Access); } let mut guard = inodes.arena[inode].write(); let deref_mut = guard.deref_mut(); @@ -886,7 +889,7 @@ pub fn fd_pread( ); wasi_try_ok!(read_bytes(h, &memory, iovs), env) } else { - return Ok(__WASI_EINVAL); + return Ok(Errno::Inval); } } Kind::Socket { socket } => { @@ -895,8 +898,8 @@ pub fn fd_pread( Kind::Pipe { pipe } => { wasi_try_ok!(pipe.recv(&memory, iovs), env) } - Kind::EventNotifications { .. } => return Ok(__WASI_EINVAL), - Kind::Dir { .. } | Kind::Root { .. } => return Ok(__WASI_EISDIR), + Kind::EventNotifications { .. } => return Ok(Errno::Inval), + Kind::Dir { .. } | Kind::Root { .. } => return Ok(Errno::Isdir), Kind::Symlink { .. } => unimplemented!("Symlinks in wasi::fd_pread"), Kind::Buffer { buffer } => { wasi_try_ok!(read_bytes(&buffer[(offset as usize)..], &memory, iovs), env) @@ -905,25 +908,25 @@ pub fn fd_pread( } }; - let bytes_read: M::Offset = wasi_try_ok!(bytes_read.try_into().map_err(|_| __WASI_EOVERFLOW)); + let bytes_read: M::Offset = wasi_try_ok!(bytes_read.try_into().map_err(|_| Errno::Overflow)); wasi_try_mem_ok!(nread_ref.write(bytes_read)); debug!("Success: {} bytes read", bytes_read); - Ok(__WASI_ESUCCESS) + Ok(Errno::Success) } /// ### `fd_prestat_get()` /// Get metadata about a preopened file descriptor /// Input: -/// - `__wasi_fd_t fd` +/// - `Fd fd` /// The preopened file descriptor to query /// Output: /// - `__wasi_prestat *buf` /// Where the metadata will be written pub fn fd_prestat_get( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, - buf: WasmPtr<__wasi_prestat_t, M>, -) -> __wasi_errno_t { + fd: WasiFd, + buf: WasmPtr, +) -> Errno { trace!("wasi::fd_prestat_get: fd={}", fd); let env = ctx.data(); let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0); @@ -938,15 +941,15 @@ pub fn fd_prestat_get( ))) ); - __WASI_ESUCCESS + Errno::Success } pub fn fd_prestat_dir_name( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: WasiFd, path: WasmPtr, path_len: M::Offset, -) -> __wasi_errno_t { +) -> Errno { trace!( "wasi::fd_prestat_dir_name: fd={}, path_len={}", fd, @@ -976,9 +979,9 @@ pub fn fd_prestat_dir_name( trace!("=> result: \"{}\"", inode_val.name); - __WASI_ESUCCESS + Errno::Success } else { - __WASI_EOVERFLOW + Errno::Overflow } } Kind::Symlink { .. } @@ -986,32 +989,32 @@ pub fn fd_prestat_dir_name( | Kind::File { .. } | Kind::Socket { .. } | Kind::Pipe { .. } - | Kind::EventNotifications { .. } => __WASI_ENOTDIR, + | Kind::EventNotifications { .. } => Errno::Notdir, } } /// ### `fd_pwrite()` /// Write to a file without adjusting its offset /// Inputs: -/// - `__wasi_fd_t` +/// - `Fd` /// File descriptor (opened with writing) to write to /// - `const __wasi_ciovec_t *iovs` /// List of vectors to read data from /// - `u32 iovs_len` /// Length of data in `iovs` -/// - `__wasi_filesize_t offset` +/// - `Filesize offset` /// The offset to write at /// Output: /// - `u32 *nwritten` /// Number of bytes written pub fn fd_pwrite( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: WasiFd, iovs: WasmPtr<__wasi_ciovec_t, M>, iovs_len: M::Offset, - offset: __wasi_filesize_t, + offset: Filesize, nwritten: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { trace!("wasi::fd_pwrite"); // TODO: refactor, this is just copied from `fd_write`... let env = ctx.data(); @@ -1021,7 +1024,7 @@ pub fn fd_pwrite( let fd_entry = wasi_try_ok!(state.fs.get_fd(fd)); let bytes_written = match fd { - __WASI_STDIN_FILENO => return Ok(__WASI_EINVAL), + __WASI_STDIN_FILENO => return Ok(Errno::Inval), __WASI_STDOUT_FILENO => { let mut guard = wasi_try_ok!( inodes @@ -1032,7 +1035,7 @@ pub fn fd_pwrite( if let Some(ref mut stdout) = guard.deref_mut() { wasi_try_ok!(write_bytes(stdout, &memory, iovs_arr), env) } else { - return Ok(__WASI_EBADF); + return Ok(Errno::Badf); } } __WASI_STDERR_FILENO => { @@ -1045,14 +1048,12 @@ pub fn fd_pwrite( if let Some(ref mut stderr) = guard.deref_mut() { wasi_try_ok!(write_bytes(stderr, &memory, iovs_arr), env) } else { - return Ok(__WASI_EBADF); + return Ok(Errno::Badf); } } _ => { - if !(has_rights(fd_entry.rights, __WASI_RIGHT_FD_WRITE) - && has_rights(fd_entry.rights, __WASI_RIGHT_FD_SEEK)) - { - return Ok(__WASI_EACCES); + if !fd_entry.rights.contains(Rights::FD_WRITE | Rights::FD_SEEK) { + return Ok(Errno::Access); } let inode_idx = fd_entry.inode; @@ -1071,7 +1072,7 @@ pub fn fd_pwrite( ); wasi_try_ok!(write_bytes(handle, &memory, iovs_arr), env) } else { - return Ok(__WASI_EINVAL); + return Ok(Errno::Inval); } } Kind::Socket { socket } => { @@ -1082,9 +1083,9 @@ pub fn fd_pwrite( } Kind::Dir { .. } | Kind::Root { .. } => { // TODO: verify - return Ok(__WASI_EISDIR); + return Ok(Errno::Isdir); } - Kind::EventNotifications { .. } => return Ok(__WASI_EINVAL), + Kind::EventNotifications { .. } => return Ok(Errno::Inval), Kind::Symlink { .. } => unimplemented!("Symlinks in wasi::fd_pwrite"), Kind::Buffer { buffer } => { wasi_try_ok!( @@ -1097,16 +1098,16 @@ pub fn fd_pwrite( }; let bytes_written: M::Offset = - wasi_try_ok!(bytes_written.try_into().map_err(|_| __WASI_EOVERFLOW)); + wasi_try_ok!(bytes_written.try_into().map_err(|_| Errno::Overflow)); wasi_try_mem_ok!(nwritten_ref.write(bytes_written)); - Ok(__WASI_ESUCCESS) + Ok(Errno::Success) } /// ### `fd_read()` /// Read data from file descriptor /// Inputs: -/// - `__wasi_fd_t fd` +/// - `Fd fd` /// File descriptor from which data will be read /// - `const __wasi_iovec_t *iovs` /// Vectors where data will be stored @@ -1118,11 +1119,11 @@ pub fn fd_pwrite( /// pub fn fd_read( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: WasiFd, iovs: WasmPtr<__wasi_iovec_t, M>, iovs_len: M::Offset, nread: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { trace!("wasi::fd_read: fd={}", fd); let env = ctx.data(); let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0); @@ -1142,17 +1143,17 @@ pub fn fd_read( if let Some(ref mut stdin) = guard.deref_mut() { wasi_try_ok!(read_bytes(stdin, &memory, iovs_arr), env) } else { - return Ok(__WASI_EBADF); + return Ok(Errno::Badf); } } - __WASI_STDOUT_FILENO | __WASI_STDERR_FILENO => return Ok(__WASI_EINVAL), + __WASI_STDOUT_FILENO | __WASI_STDERR_FILENO => return Ok(Errno::Inval), _ => { - if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_READ) { + if !fd_entry.rights.contains(Rights::FD_READ) { // TODO: figure out the error to return when lacking rights - return Ok(__WASI_EACCES); + return Ok(Errno::Access); } - let is_non_blocking = fd_entry.flags & __WASI_FDFLAG_NONBLOCK != 0; + let is_non_blocking = fd_entry.flags.contains(Fdflags::NONBLOCK); let offset = fd_entry.offset as usize; let inode_idx = fd_entry.inode; let inode = &inodes.arena[inode_idx]; @@ -1171,7 +1172,7 @@ pub fn fd_read( ); wasi_try_ok!(read_bytes(handle, &memory, iovs_arr), env) } else { - return Ok(__WASI_EINVAL); + return Ok(Errno::Inval); } } Kind::Socket { socket } => { @@ -1182,7 +1183,7 @@ pub fn fd_read( } Kind::Dir { .. } | Kind::Root { .. } => { // TODO: verify - return Ok(__WASI_EISDIR); + return Ok(Errno::Isdir); } Kind::EventNotifications { counter, @@ -1228,7 +1229,7 @@ pub fn fd_read( // If its none blocking then exit if is_non_blocking { - return Ok(__WASI_EAGAIN); + return Ok(Errno::Again); } // Yield for a fixed period of time and then check again @@ -1248,28 +1249,28 @@ pub fn fd_read( // reborrow let mut fd_map = state.fs.fd_map.write().unwrap(); - let fd_entry = wasi_try_ok!(fd_map.get_mut(&fd).ok_or(__WASI_EBADF)); + let fd_entry = wasi_try_ok!(fd_map.get_mut(&fd).ok_or(Errno::Badf)); fd_entry.offset += bytes_read as u64; bytes_read } }; - let bytes_read: M::Offset = wasi_try_ok!(bytes_read.try_into().map_err(|_| __WASI_EOVERFLOW)); + let bytes_read: M::Offset = wasi_try_ok!(bytes_read.try_into().map_err(|_| Errno::Overflow)); wasi_try_mem_ok!(nread_ref.write(bytes_read)); - Ok(__WASI_ESUCCESS) + Ok(Errno::Success) } /// ### `fd_readdir()` /// Read data from directory specified by file descriptor /// Inputs: -/// - `__wasi_fd_t fd` +/// - `Fd fd` /// File descriptor from which directory data will be read /// - `void *buf` /// Buffer where directory entries are stored /// - `u32 buf_len` /// Length of data in `buf` -/// - `__wasi_dircookie_t cookie` +/// - `Dircookie cookie` /// Where the directory reading should start from /// Output: /// - `u32 *bufused` @@ -1277,12 +1278,12 @@ pub fn fd_read( /// directory has been read pub fn fd_readdir( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: WasiFd, buf: WasmPtr, buf_len: M::Offset, - cookie: __wasi_dircookie_t, + cookie: Dircookie, bufused: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { trace!("wasi::fd_readdir"); let env = ctx.data(); let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0); @@ -1295,7 +1296,7 @@ pub fn fd_readdir( let mut cur_cookie = cookie; let mut buf_idx = 0usize; - let entries: Vec<(String, u8, u64)> = { + let entries: Vec<(String, Filetype, u64)> = { let guard = inodes.arena[working_dir.inode].read(); let deref = guard.deref(); match deref { @@ -1320,7 +1321,7 @@ pub fn fd_readdir( filename, filetype, 0, // TODO: inode )) }) - .collect::, _>>()); + .collect::, _>>()); entry_vec.extend( entries .iter() @@ -1333,8 +1334,8 @@ pub fn fd_readdir( ); // adding . and .. special folders // TODO: inode - entry_vec.push((".".to_string(), __WASI_FILETYPE_DIRECTORY, 0)); - entry_vec.push(("..".to_string(), __WASI_FILETYPE_DIRECTORY, 0)); + entry_vec.push((".".to_string(), Filetype::Directory, 0)); + entry_vec.push(("..".to_string(), Filetype::Directory, 0)); entry_vec.sort_by(|a, b| a.0.cmp(&b.0)); entry_vec } @@ -1360,7 +1361,7 @@ pub fn fd_readdir( | Kind::Buffer { .. } | Kind::Socket { .. } | Kind::Pipe { .. } - | Kind::EventNotifications { .. } => return __WASI_ENOTDIR, + | Kind::EventNotifications { .. } => return Errno::Notdir, } }; @@ -1368,7 +1369,7 @@ pub fn fd_readdir( cur_cookie += 1; let namlen = entry_path_str.len(); debug!("Returning dirent for {}", entry_path_str); - let dirent = __wasi_dirent_t { + let dirent = Dirent { d_next: cur_cookie, d_ino: *ino, d_namlen: namlen as u32, @@ -1378,13 +1379,13 @@ pub fn fd_readdir( let buf_len: u64 = buf_len.into(); let upper_limit = std::cmp::min( (buf_len - buf_idx as u64) as usize, - std::mem::size_of::<__wasi_dirent_t>(), + std::mem::size_of::(), ); for (i, b) in dirent_bytes.iter().enumerate().take(upper_limit) { wasi_try_mem!(buf_arr.index((i + buf_idx) as u64).write(*b)); } buf_idx += upper_limit; - if upper_limit != std::mem::size_of::<__wasi_dirent_t>() { + if upper_limit != std::mem::size_of::() { break; } let upper_limit = std::cmp::min((buf_len - buf_idx as u64) as usize, namlen); @@ -1397,29 +1398,25 @@ pub fn fd_readdir( } } - let buf_idx: M::Offset = wasi_try!(buf_idx.try_into().map_err(|_| __WASI_EOVERFLOW)); + let buf_idx: M::Offset = wasi_try!(buf_idx.try_into().map_err(|_| Errno::Overflow)); wasi_try_mem!(bufused_ref.write(buf_idx)); - __WASI_ESUCCESS + Errno::Success } /// ### `fd_renumber()` /// Atomically copy file descriptor /// Inputs: -/// - `__wasi_fd_t from` +/// - `Fd from` /// File descriptor to copy -/// - `__wasi_fd_t to` +/// - `Fd to` /// Location to copy file descriptor to -pub fn fd_renumber( - ctx: FunctionEnvMut<'_, WasiEnv>, - from: __wasi_fd_t, - to: __wasi_fd_t, -) -> __wasi_errno_t { +pub fn fd_renumber(ctx: FunctionEnvMut<'_, WasiEnv>, from: WasiFd, to: WasiFd) -> Errno { debug!("wasi::fd_renumber: from={}, to={}", from, to); let env = ctx.data(); let (_, mut state) = env.get_memory_and_wasi_state(&ctx, 0); let mut fd_map = state.fs.fd_map.write().unwrap(); - let fd_entry = wasi_try!(fd_map.get_mut(&from).ok_or(__WASI_EBADF)); + let fd_entry = wasi_try!(fd_map.get_mut(&from).ok_or(Errno::Badf)); let new_fd_entry = Fd { // TODO: verify this is correct @@ -1429,22 +1426,22 @@ pub fn fd_renumber( fd_map.insert(to, new_fd_entry); fd_map.remove(&from); - __WASI_ESUCCESS + Errno::Success } /// ### `fd_dup()` /// Duplicates the file handle /// Inputs: -/// - `__wasi_fd_t fd` +/// - `Fd fd` /// File handle to be cloned /// Outputs: -/// - `__wasi_fd_t fd` +/// - `Fd fd` /// The new file handle that is a duplicate of the original pub fn fd_dup( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, - ret_fd: WasmPtr<__wasi_fd_t, M>, -) -> __wasi_errno_t { + fd: WasiFd, + ret_fd: WasmPtr, +) -> Errno { debug!("wasi::fd_dup"); let env = ctx.data(); @@ -1453,7 +1450,7 @@ pub fn fd_dup( wasi_try_mem!(ret_fd.write(&memory, fd)); - __WASI_ESUCCESS + Errno::Success } /// ### `fd_event()` @@ -1461,9 +1458,9 @@ pub fn fd_dup( pub fn fd_event( ctx: FunctionEnvMut<'_, WasiEnv>, initial_val: u64, - flags: __wasi_eventfdflags, - ret_fd: WasmPtr<__wasi_fd_t, M>, -) -> __wasi_errno_t { + flags: EventFdFlags, + ret_fd: WasmPtr, +) -> Errno { debug!("wasi::fd_event"); let env = ctx.data(); @@ -1471,7 +1468,7 @@ pub fn fd_event( let kind = Kind::EventNotifications { counter: Arc::new(AtomicU64::new(initial_val)), - is_semaphore: flags & __WASI_EVENTFDFLAGS_SEMAPHORE != 0, + is_semaphore: flags & EVENT_FD_FLAGS_SEMAPHORE != 0, wakers: Default::default(), }; @@ -1481,51 +1478,53 @@ pub fn fd_event( false, "event".to_string(), ); - let rights = __WASI_RIGHT_FD_READ | __WASI_RIGHT_FD_WRITE | __WASI_RIGHT_POLL_FD_READWRITE; - let fd = wasi_try!(state.fs.create_fd(rights, rights, 0, 0, inode)); + let rights = Rights::FD_READ | Rights::FD_WRITE | Rights::POLL_FD_READWRITE; + let fd = wasi_try!(state + .fs + .create_fd(rights, rights, Fdflags::empty(), 0, inode)); wasi_try_mem!(ret_fd.write(&memory, fd)); - __WASI_ESUCCESS + Errno::Success } /// ### `fd_seek()` /// Update file descriptor offset /// Inputs: -/// - `__wasi_fd_t fd` +/// - `Fd fd` /// File descriptor to mutate -/// - `__wasi_filedelta_t offset` +/// - `FileDelta offset` /// Number of bytes to adjust offset by -/// - `__wasi_whence_t whence` +/// - `Whence whence` /// What the offset is relative to /// Output: -/// - `__wasi_filesize_t *fd` +/// - `Filesize *fd` /// The new offset relative to the start of the file pub fn fd_seek( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, - offset: __wasi_filedelta_t, - whence: __wasi_whence_t, - newoffset: WasmPtr<__wasi_filesize_t, M>, -) -> Result<__wasi_errno_t, WasiError> { + fd: WasiFd, + offset: FileDelta, + whence: Whence, + newoffset: WasmPtr, +) -> Result { trace!("wasi::fd_seek: fd={}, offset={}", fd, offset); let env = ctx.data(); let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0); let new_offset_ref = newoffset.deref(&memory); let fd_entry = wasi_try_ok!(state.fs.get_fd(fd)); - if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_SEEK) { - return Ok(__WASI_EACCES); + if !fd_entry.rights.contains(Rights::FD_SEEK) { + return Ok(Errno::Access); } // TODO: handle case if fd is a dir? match whence { - __WASI_WHENCE_CUR => { + Whence::Cur => { let mut fd_map = state.fs.fd_map.write().unwrap(); - let fd_entry = wasi_try_ok!(fd_map.get_mut(&fd).ok_or(__WASI_EBADF)); + let fd_entry = wasi_try_ok!(fd_map.get_mut(&fd).ok_or(Errno::Badf)); fd_entry.offset = (fd_entry.offset as i64 + offset) as u64 } - __WASI_WHENCE_END => { + Whence::End => { use std::io::SeekFrom; let inode_idx = fd_entry.inode; let mut guard = inodes.arena[inode_idx].write(); @@ -1539,10 +1538,10 @@ pub fn fd_seek( // TODO: handle case if fd_entry.offset uses 64 bits of a u64 drop(guard); let mut fd_map = state.fs.fd_map.write().unwrap(); - let fd_entry = wasi_try_ok!(fd_map.get_mut(&fd).ok_or(__WASI_EBADF)); + let fd_entry = wasi_try_ok!(fd_map.get_mut(&fd).ok_or(Errno::Badf)); fd_entry.offset = (end as i64 + offset) as u64; } else { - return Ok(__WASI_EINVAL); + return Ok(Errno::Inval); } } Kind::Symlink { .. } => { @@ -1554,46 +1553,46 @@ pub fn fd_seek( | Kind::Pipe { .. } | Kind::EventNotifications { .. } => { // TODO: check this - return Ok(__WASI_EINVAL); + return Ok(Errno::Inval); } Kind::Buffer { .. } => { // seeking buffers probably makes sense // TODO: implement this - return Ok(__WASI_EINVAL); + return Ok(Errno::Inval); } } } - __WASI_WHENCE_SET => { + Whence::Set => { let mut fd_map = state.fs.fd_map.write().unwrap(); - let fd_entry = wasi_try_ok!(fd_map.get_mut(&fd).ok_or(__WASI_EBADF)); + let fd_entry = wasi_try_ok!(fd_map.get_mut(&fd).ok_or(Errno::Badf)); fd_entry.offset = offset as u64 } - _ => return Ok(__WASI_EINVAL), + _ => return Ok(Errno::Inval), } // reborrow let fd_entry = wasi_try_ok!(state.fs.get_fd(fd)); wasi_try_mem_ok!(new_offset_ref.write(fd_entry.offset)); - Ok(__WASI_ESUCCESS) + Ok(Errno::Success) } /// ### `fd_sync()` /// Synchronize file and metadata to disk (TODO: expand upon what this means in our system) /// Inputs: -/// - `__wasi_fd_t fd` +/// - `Fd fd` /// The file descriptor to sync /// Errors: /// TODO: figure out which errors this should return -/// - `__WASI_EPERM` -/// - `__WASI_ENOTCAPABLE` -pub fn fd_sync(ctx: FunctionEnvMut<'_, WasiEnv>, fd: __wasi_fd_t) -> __wasi_errno_t { +/// - `Errno::Perm` +/// - `Errno::Notcapable` +pub fn fd_sync(ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd) -> Errno { debug!("wasi::fd_sync"); debug!("=> fd={}", fd); let env = ctx.data(); let (_, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0); let fd_entry = wasi_try!(state.fs.get_fd(fd)); - if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_SYNC) { - return __WASI_EACCES; + if !fd_entry.rights.contains(Rights::FD_SYNC) { + return Errno::Access; } let inode = fd_entry.inode; @@ -1606,34 +1605,34 @@ pub fn fd_sync(ctx: FunctionEnvMut<'_, WasiEnv>, fd: __wasi_fd_t) -> __wasi_errn if let Some(h) = handle { wasi_try!(h.sync_to_disk().map_err(fs_error_into_wasi_err)); } else { - return __WASI_EINVAL; + return Errno::Inval; } } - Kind::Root { .. } | Kind::Dir { .. } => return __WASI_EISDIR, + Kind::Root { .. } | Kind::Dir { .. } => return Errno::Isdir, Kind::Buffer { .. } | Kind::Symlink { .. } | Kind::Socket { .. } | Kind::Pipe { .. } - | Kind::EventNotifications { .. } => return __WASI_EINVAL, + | Kind::EventNotifications { .. } => return Errno::Inval, } } - __WASI_ESUCCESS + Errno::Success } /// ### `fd_tell()` /// Get the offset of the file descriptor /// Inputs: -/// - `__wasi_fd_t fd` +/// - `Fd fd` /// The file descriptor to access /// Output: -/// - `__wasi_filesize_t *offset` +/// - `Filesize *offset` /// The offset of `fd` relative to the start of the file pub fn fd_tell( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, - offset: WasmPtr<__wasi_filesize_t, M>, -) -> __wasi_errno_t { + fd: WasiFd, + offset: WasmPtr, +) -> Errno { debug!("wasi::fd_tell"); let env = ctx.data(); let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0); @@ -1641,19 +1640,19 @@ pub fn fd_tell( let fd_entry = wasi_try!(state.fs.get_fd(fd)); - if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_TELL) { - return __WASI_EACCES; + if !fd_entry.rights.contains(Rights::FD_TELL) { + return Errno::Access; } wasi_try_mem!(offset_ref.write(fd_entry.offset)); - __WASI_ESUCCESS + Errno::Success } /// ### `fd_write()` /// Write data to the file descriptor /// Inputs: -/// - `__wasi_fd_t` +/// - `Fd` /// File descriptor (opened with writing) to write to /// - `const __wasi_ciovec_t *iovs` /// List of vectors to read data from @@ -1666,11 +1665,11 @@ pub fn fd_tell( /// pub fn fd_write( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: WasiFd, iovs: WasmPtr<__wasi_ciovec_t, M>, iovs_len: M::Offset, nwritten: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { trace!("wasi::fd_write: fd={}", fd); let env = ctx.data(); let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0); @@ -1679,7 +1678,7 @@ pub fn fd_write( let fd_entry = wasi_try_ok!(state.fs.get_fd(fd)); let bytes_written = match fd { - __WASI_STDIN_FILENO => return Ok(__WASI_EINVAL), + __WASI_STDIN_FILENO => return Ok(Errno::Inval), __WASI_STDOUT_FILENO => { let mut guard = wasi_try_ok!( inodes @@ -1690,7 +1689,7 @@ pub fn fd_write( if let Some(ref mut stdout) = guard.deref_mut() { wasi_try_ok!(write_bytes(stdout, &memory, iovs_arr), env) } else { - return Ok(__WASI_EBADF); + return Ok(Errno::Badf); } } __WASI_STDERR_FILENO => { @@ -1703,12 +1702,12 @@ pub fn fd_write( if let Some(ref mut stderr) = guard.deref_mut() { wasi_try_ok!(write_bytes(stderr, &memory, iovs_arr), env) } else { - return Ok(__WASI_EBADF); + return Ok(Errno::Badf); } } _ => { - if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_WRITE) { - return Ok(__WASI_EACCES); + if !fd_entry.rights.contains(Rights::FD_WRITE) { + return Ok(Errno::Access); } let offset = fd_entry.offset as usize; @@ -1729,7 +1728,7 @@ pub fn fd_write( ); wasi_try_ok!(write_bytes(handle, &memory, iovs_arr), env) } else { - return Ok(__WASI_EINVAL); + return Ok(Errno::Inval); } } Kind::Socket { socket } => { @@ -1740,7 +1739,7 @@ pub fn fd_write( } Kind::Dir { .. } | Kind::Root { .. } => { // TODO: verify - return Ok(__WASI_EISDIR); + return Ok(Errno::Isdir); } Kind::EventNotifications { counter, wakers, .. @@ -1748,7 +1747,7 @@ pub fn fd_write( let mut val = 0u64.to_ne_bytes(); let written = wasi_try_ok!(write_bytes(&mut val[..], &memory, iovs_arr)); if written != val.len() { - return Ok(__WASI_EINVAL); + return Ok(Errno::Inval); } let val = u64::from_ne_bytes(val); @@ -1774,7 +1773,7 @@ pub fn fd_write( // reborrow { let mut fd_map = state.fs.fd_map.write().unwrap(); - let fd_entry = wasi_try_ok!(fd_map.get_mut(&fd).ok_or(__WASI_EBADF)); + let fd_entry = wasi_try_ok!(fd_map.get_mut(&fd).ok_or(Errno::Badf)); fd_entry.offset += bytes_written as u64; } wasi_try_ok!(state.fs.filestat_resync_size(inodes.deref(), fd), env); @@ -1784,24 +1783,24 @@ pub fn fd_write( }; let bytes_written: M::Offset = - wasi_try_ok!(bytes_written.try_into().map_err(|_| __WASI_EOVERFLOW)); + wasi_try_ok!(bytes_written.try_into().map_err(|_| Errno::Overflow)); wasi_try_mem_ok!(nwritten_ref.write(bytes_written)); - Ok(__WASI_ESUCCESS) + Ok(Errno::Success) } /// ### `fd_pipe()` /// Creates ta pipe that feeds data between two file handles /// Output: -/// - `__wasi_fd_t` +/// - `Fd` /// First file handle that represents one end of the pipe -/// - `__wasi_fd_t` +/// - `Fd` /// Second file handle that represents the other end of the pipe pub fn fd_pipe( ctx: FunctionEnvMut<'_, WasiEnv>, - ro_fd1: WasmPtr<__wasi_fd_t, M>, - ro_fd2: WasmPtr<__wasi_fd_t, M>, -) -> __wasi_errno_t { + ro_fd1: WasmPtr, + ro_fd2: WasmPtr, +) -> Errno { trace!("wasi::fd_pipe"); let env = ctx.data(); @@ -1822,20 +1821,24 @@ pub fn fd_pipe( "pipe".to_string(), ); - let rights = super::state::all_socket_rights(); - let fd1 = wasi_try!(state.fs.create_fd(rights, rights, 0, 0, inode1)); - let fd2 = wasi_try!(state.fs.create_fd(rights, rights, 0, 0, inode2)); + let rights = Rights::all_socket(); + let fd1 = wasi_try!(state + .fs + .create_fd(rights, rights, Fdflags::empty(), 0, inode1)); + let fd2 = wasi_try!(state + .fs + .create_fd(rights, rights, Fdflags::empty(), 0, inode2)); wasi_try_mem!(ro_fd1.write(&memory, fd1)); wasi_try_mem!(ro_fd2.write(&memory, fd2)); - __WASI_ESUCCESS + Errno::Success } /// ### `path_create_directory()` /// Create directory at a path /// Inputs: -/// - `__wasi_fd_t fd` +/// - `Fd fd` /// The directory that the path is relative to /// - `const char *path` /// String containing path data @@ -1843,14 +1846,14 @@ pub fn fd_pipe( /// The length of `path` /// Errors: /// Required Rights: -/// - __WASI_RIGHT_PATH_CREATE_DIRECTORY +/// - Rights::PATH_CREATE_DIRECTORY /// This right must be set on the directory that the file is created in (TODO: verify that this is true) pub fn path_create_directory( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: WasiFd, path: WasmPtr, path_len: M::Offset, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::path_create_directory"); let env = ctx.data(); let (memory, state, mut inodes) = env.get_memory_and_wasi_state_and_inodes_mut(&ctx, 0); @@ -1859,11 +1862,11 @@ pub fn path_create_directory( { let guard = inodes.arena[working_dir.inode].read(); if let Kind::Root { .. } = guard.deref() { - return __WASI_EACCES; + return Errno::Access; } } - if !has_rights(working_dir.rights, __WASI_RIGHT_PATH_CREATE_DIRECTORY) { - return __WASI_EACCES; + if !working_dir.rights.contains(Rights::PATH_CREATE_DIRECTORY) { + return Errno::Access; } let path_string = unsafe { get_input_str!(&memory, path, path_len) }; debug!("=> fd: {}, path: {}", fd, &path_string); @@ -1875,11 +1878,11 @@ pub fn path_create_directory( comp.as_os_str() .to_str() .map(|inner_str| inner_str.to_string()) - .ok_or(__WASI_EINVAL) + .ok_or(Errno::Inval) }) - .collect::, __wasi_errno_t>>()); + .collect::, Errno>>()); if path_vec.is_empty() { - return __WASI_EINVAL; + return Errno::Inval; } debug!("Looking at components {:?}", &path_vec); @@ -1921,8 +1924,8 @@ pub fn path_create_directory( 0, &adjusted_path.to_string_lossy(), ) { - if adjusted_path_stat.st_filetype != __WASI_FILETYPE_DIRECTORY { - return __WASI_ENOTDIR; + if adjusted_path_stat.st_filetype != Filetype::Directory { + return Errno::Notdir; } } else { wasi_try!(state.fs_create_dir(&adjusted_path)); @@ -1952,20 +1955,20 @@ pub fn path_create_directory( cur_dir_inode = new_inode; } } - Kind::Root { .. } => return __WASI_EACCES, - _ => return __WASI_ENOTDIR, + Kind::Root { .. } => return Errno::Access, + _ => return Errno::Notdir, } } - __WASI_ESUCCESS + Errno::Success } /// ### `path_filestat_get()` /// Access metadata about a file or directory /// Inputs: -/// - `__wasi_fd_t fd` +/// - `Fd fd` /// The directory that `path` is relative to -/// - `__wasi_lookupflags_t flags` +/// - `LookupFlags flags` /// Flags to control how `path` is understood /// - `const char *path` /// String containing the file path @@ -1976,12 +1979,12 @@ pub fn path_create_directory( /// The location where the metadata will be stored pub fn path_filestat_get( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, - flags: __wasi_lookupflags_t, + fd: WasiFd, + flags: LookupFlags, path: WasmPtr, path_len: M::Offset, - buf: WasmPtr<__wasi_filestat_t, M>, -) -> __wasi_errno_t { + buf: WasmPtr, +) -> Errno { debug!("wasi::path_filestat_get (fd={})", fd); let env = ctx.data(); let (memory, mut state, mut inodes) = env.get_memory_and_wasi_state_and_inodes_mut(&ctx, 0); @@ -1999,15 +2002,15 @@ pub fn path_filestat_get( wasi_try_mem!(buf.deref(&memory).write(stat)); - __WASI_ESUCCESS + Errno::Success } /// ### `path_filestat_get()` /// Access metadata about a file or directory /// Inputs: -/// - `__wasi_fd_t fd` +/// - `Fd fd` /// The directory that `path` is relative to -/// - `__wasi_lookupflags_t flags` +/// - `LookupFlags flags` /// Flags to control how `path` is understood /// - `const char *path` /// String containing the file path @@ -2020,14 +2023,14 @@ pub fn path_filestat_get_internal( memory: &MemoryView, state: &WasiState, inodes: &mut crate::WasiInodes, - fd: __wasi_fd_t, - flags: __wasi_lookupflags_t, + fd: WasiFd, + flags: LookupFlags, path_string: &str, -) -> Result<__wasi_filestat_t, __wasi_errno_t> { +) -> Result { let root_dir = state.fs.get_fd(fd)?; - if !has_rights(root_dir.rights, __WASI_RIGHT_PATH_FILESTAT_GET) { - return Err(__WASI_EACCES); + if !root_dir.rights.contains(Rights::PATH_FILESTAT_GET) { + return Err(Errno::Access); } debug!("=> base_fd: {}, path: {}", fd, path_string); @@ -2048,43 +2051,42 @@ pub fn path_filestat_get_internal( /// ### `path_filestat_set_times()` /// Update time metadata on a file or directory /// Inputs: -/// - `__wasi_fd_t fd` +/// - `Fd fd` /// The directory relative to which the path is resolved -/// - `__wasi_lookupflags_t flags` +/// - `LookupFlags flags` /// Flags to control how the path is understood /// - `const char *path` /// String containing the file path /// - `u32 path_len` /// The length of the `path` string -/// - `__wasi_timestamp_t st_atim` +/// - `Timestamp st_atim` /// The timestamp that the last accessed time attribute is set to -/// - `__wasi_timestamp_t st_mtim` +/// - `Timestamp st_mtim` /// The timestamp that the last modified time attribute is set to -/// - `__wasi_fstflags_t fst_flags` +/// - `Fstflags fst_flags` /// A bitmask controlling which attributes are set pub fn path_filestat_set_times( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, - flags: __wasi_lookupflags_t, + fd: WasiFd, + flags: LookupFlags, path: WasmPtr, path_len: M::Offset, - st_atim: __wasi_timestamp_t, - st_mtim: __wasi_timestamp_t, - fst_flags: __wasi_fstflags_t, -) -> __wasi_errno_t { + st_atim: Timestamp, + st_mtim: Timestamp, + fst_flags: Fstflags, +) -> Errno { debug!("wasi::path_filestat_set_times"); let env = ctx.data(); let (memory, mut state, mut inodes) = env.get_memory_and_wasi_state_and_inodes_mut(&ctx, 0); let fd_entry = wasi_try!(state.fs.get_fd(fd)); let fd_inode = fd_entry.inode; - if !has_rights(fd_entry.rights, __WASI_RIGHT_PATH_FILESTAT_SET_TIMES) { - return __WASI_EACCES; + if !fd_entry.rights.contains(Rights::PATH_FILESTAT_SET_TIMES) { + return Errno::Access; } - if (fst_flags & __WASI_FILESTAT_SET_ATIM != 0 && fst_flags & __WASI_FILESTAT_SET_ATIM_NOW != 0) - || (fst_flags & __WASI_FILESTAT_SET_MTIM != 0 - && fst_flags & __WASI_FILESTAT_SET_MTIM_NOW != 0) + if (fst_flags.contains(Fstflags::SET_ATIM) && fst_flags.contains(Fstflags::SET_ATIM_NOW)) + || (fst_flags.contains(Fstflags::SET_MTIM) && fst_flags.contains(Fstflags::SET_MTIM_NOW)) { - return __WASI_EINVAL; + return Errno::Inval; } let path_string = unsafe { get_input_str!(&memory, path, path_len) }; @@ -2103,16 +2105,16 @@ pub fn path_filestat_set_times( let inode = &inodes.arena[fd_inode]; - if fst_flags & __WASI_FILESTAT_SET_ATIM != 0 || fst_flags & __WASI_FILESTAT_SET_ATIM_NOW != 0 { - let time_to_set = if fst_flags & __WASI_FILESTAT_SET_ATIM != 0 { + if fst_flags.contains(Fstflags::SET_ATIM) || fst_flags.contains(Fstflags::SET_ATIM_NOW) { + let time_to_set = if fst_flags.contains(Fstflags::SET_ATIM) { st_atim } else { wasi_try!(get_current_time_in_nanos()) }; inode.stat.write().unwrap().st_atim = time_to_set; } - if fst_flags & __WASI_FILESTAT_SET_MTIM != 0 || fst_flags & __WASI_FILESTAT_SET_MTIM_NOW != 0 { - let time_to_set = if fst_flags & __WASI_FILESTAT_SET_MTIM != 0 { + if fst_flags.contains(Fstflags::SET_MTIM) || fst_flags.contains(Fstflags::SET_MTIM_NOW) { + let time_to_set = if fst_flags.contains(Fstflags::SET_MTIM) { st_mtim } else { wasi_try!(get_current_time_in_nanos()) @@ -2120,21 +2122,21 @@ pub fn path_filestat_set_times( inode.stat.write().unwrap().st_mtim = time_to_set; } - __WASI_ESUCCESS + Errno::Success } /// ### `path_link()` /// Create a hard link /// Inputs: -/// - `__wasi_fd_t old_fd` +/// - `Fd old_fd` /// The directory relative to which the `old_path` is -/// - `__wasi_lookupflags_t old_flags` +/// - `LookupFlags old_flags` /// Flags to control how `old_path` is understood /// - `const char *old_path` /// String containing the old file path /// - `u32 old_path_len` /// Length of the `old_path` string -/// - `__wasi_fd_t new_fd` +/// - `Fd new_fd` /// The directory relative to which the `new_path` is /// - `const char *new_path` /// String containing the new file path @@ -2142,14 +2144,14 @@ pub fn path_filestat_set_times( /// Length of the `new_path` string pub fn path_link( ctx: FunctionEnvMut<'_, WasiEnv>, - old_fd: __wasi_fd_t, - old_flags: __wasi_lookupflags_t, + old_fd: WasiFd, + old_flags: LookupFlags, old_path: WasmPtr, old_path_len: M::Offset, - new_fd: __wasi_fd_t, + new_fd: WasiFd, new_path: WasmPtr, new_path_len: M::Offset, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::path_link"); if old_flags & __WASI_LOOKUP_SYMLINK_FOLLOW != 0 { debug!(" - will follow symlinks when opening path"); @@ -2165,10 +2167,10 @@ pub fn path_link( old_fd, &old_path_str, new_fd, new_path_str ); - if !(has_rights(source_fd.rights, __WASI_RIGHT_PATH_LINK_SOURCE) - && has_rights(target_fd.rights, __WASI_RIGHT_PATH_LINK_TARGET)) + if !source_fd.rights.contains(Rights::PATH_LINK_SOURCE) + || !target_fd.rights.contains(Rights::PATH_LINK_TARGET) { - return __WASI_EACCES; + return Errno::Access; } let source_inode = wasi_try!(state.fs.get_inode_at_path( @@ -2185,9 +2187,8 @@ pub fn path_link( false )); - if inodes.arena[source_inode].stat.write().unwrap().st_nlink == __wasi_linkcount_t::max_value() - { - return __WASI_EMLINK; + if inodes.arena[source_inode].stat.write().unwrap().st_nlink == Linkcount::max_value() { + return Errno::Mlink; } { let mut guard = inodes.arena[target_parent_inode].write(); @@ -2195,60 +2196,60 @@ pub fn path_link( match deref_mut { Kind::Dir { entries, .. } => { if entries.contains_key(&new_entry_name) { - return __WASI_EEXIST; + return Errno::Exist; } entries.insert(new_entry_name, source_inode); } - Kind::Root { .. } => return __WASI_EINVAL, + Kind::Root { .. } => return Errno::Inval, Kind::File { .. } | Kind::Symlink { .. } | Kind::Buffer { .. } | Kind::Socket { .. } | Kind::Pipe { .. } - | Kind::EventNotifications { .. } => return __WASI_ENOTDIR, + | Kind::EventNotifications { .. } => return Errno::Notdir, } } inodes.arena[source_inode].stat.write().unwrap().st_nlink += 1; - __WASI_ESUCCESS + Errno::Success } /// ### `path_open()` /// Open file located at the given path /// Inputs: -/// - `__wasi_fd_t dirfd` +/// - `Fd dirfd` /// The fd corresponding to the directory that the file is in -/// - `__wasi_lookupflags_t dirflags` +/// - `LookupFlags dirflags` /// Flags specifying how the path will be resolved /// - `char *path` /// The path of the file or directory to open /// - `u32 path_len` /// The length of the `path` string -/// - `__wasi_oflags_t o_flags` +/// - `Oflags o_flags` /// How the file will be opened -/// - `__wasi_rights_t fs_rights_base` +/// - `Rights fs_rights_base` /// The rights of the created file descriptor -/// - `__wasi_rights_t fs_rightsinheriting` +/// - `Rights fs_rightsinheriting` /// The rights of file descriptors derived from the created file descriptor -/// - `__wasi_fdflags_t fs_flags` +/// - `Fdflags fs_flags` /// The flags of the file descriptor /// Output: -/// - `__wasi_fd_t* fd` +/// - `Fd* fd` /// The new file descriptor /// Possible Errors: -/// - `__WASI_EACCES`, `__WASI_EBADF`, `__WASI_EFAULT`, `__WASI_EFBIG?`, `__WASI_EINVAL`, `__WASI_EIO`, `__WASI_ELOOP`, `__WASI_EMFILE`, `__WASI_ENAMETOOLONG?`, `__WASI_ENFILE`, `__WASI_ENOENT`, `__WASI_ENOTDIR`, `__WASI_EROFS`, and `__WASI_ENOTCAPABLE` +/// - `Errno::Access`, `Errno::Badf`, `Errno::Fault`, `Errno::Fbig?`, `Errno::Inval`, `Errno::Io`, `Errno::Loop`, `Errno::Mfile`, `Errno::Nametoolong?`, `Errno::Nfile`, `Errno::Noent`, `Errno::Notdir`, `Errno::Rofs`, and `Errno::Notcapable` pub fn path_open( ctx: FunctionEnvMut<'_, WasiEnv>, - dirfd: __wasi_fd_t, - dirflags: __wasi_lookupflags_t, + dirfd: WasiFd, + dirflags: LookupFlags, path: WasmPtr, path_len: M::Offset, - o_flags: __wasi_oflags_t, - fs_rights_base: __wasi_rights_t, - fs_rights_inheriting: __wasi_rights_t, - fs_flags: __wasi_fdflags_t, - fd: WasmPtr<__wasi_fd_t, M>, -) -> __wasi_errno_t { + o_flags: Oflags, + fs_rights_base: Rights, + fs_rights_inheriting: Rights, + fs_flags: Fdflags, + fd: WasmPtr, +) -> Errno { debug!("wasi::path_open"); if dirflags & __WASI_LOOKUP_SYMLINK_FOLLOW != 0 { debug!(" - will follow symlinks when opening path"); @@ -2258,7 +2259,7 @@ pub fn path_open( /* TODO: find actual upper bound on name size (also this is a path, not a name :think-fish:) */ let path_len64: u64 = path_len.into(); if path_len64 > 1024u64 * 1024u64 { - return __WASI_ENAMETOOLONG; + return Errno::Nametoolong; } let fd_ref = fd.deref(&memory); @@ -2273,8 +2274,8 @@ pub fn path_open( let working_dir_rights_inheriting = working_dir.rights_inheriting; // ASSUMPTION: open rights apply recursively - if !has_rights(working_dir.rights, __WASI_RIGHT_PATH_OPEN) { - return __WASI_EACCES; + if !working_dir.rights.contains(Rights::PATH_OPEN) { + return Errno::Access; } let path_string = unsafe { get_input_str!(&memory, path, path_len) }; @@ -2308,23 +2309,23 @@ pub fn path_open( // short circuit if we're dealing with a special file assert!(handle.is_some()); wasi_try_mem!(fd_ref.write(*special_fd)); - return __WASI_ESUCCESS; + return Errno::Success; } - if o_flags & __WASI_O_DIRECTORY != 0 { - return __WASI_ENOTDIR; + if o_flags.contains(Oflags::DIRECTORY) { + return Errno::Notdir; } - if o_flags & __WASI_O_EXCL != 0 { - return __WASI_EEXIST; + if o_flags.contains(Oflags::EXCL) { + return Errno::Exist; } - let write_permission = adjusted_rights & __WASI_RIGHT_FD_WRITE != 0; + let write_permission = adjusted_rights.contains(Rights::FD_WRITE); // append, truncate, and create all require the permission to write let (append_permission, truncate_permission, create_permission) = if write_permission { ( - fs_flags & __WASI_FDFLAG_APPEND != 0, - o_flags & __WASI_O_TRUNC != 0, - o_flags & __WASI_O_CREAT != 0, + fs_flags.contains(Fdflags::APPEND), + o_flags.contains(Oflags::TRUNC), + o_flags.contains(Oflags::CREATE), ) } else { (false, false, false) @@ -2337,13 +2338,13 @@ pub fn path_open( .append(append_permission) .truncate(truncate_permission); open_flags |= Fd::READ; - if adjusted_rights & __WASI_RIGHT_FD_WRITE != 0 { + if adjusted_rights.contains(Rights::FD_WRITE) { open_flags |= Fd::WRITE; } - if o_flags & __WASI_O_CREAT != 0 { + if o_flags.contains(Oflags::CREATE) { open_flags |= Fd::CREATE; } - if o_flags & __WASI_O_TRUNC != 0 { + if o_flags.contains(Oflags::TRUNC) { open_flags |= Fd::TRUNCATE; } *handle = Some(wasi_try!(open_options @@ -2370,9 +2371,9 @@ pub fn path_open( } else { // less-happy path, we have to try to create the file debug!("Maybe creating file"); - if o_flags & __WASI_O_CREAT != 0 { - if o_flags & __WASI_O_DIRECTORY != 0 { - return __WASI_ENOTDIR; + if o_flags.contains(Oflags::CREATE) { + if o_flags.contains(Oflags::DIRECTORY) { + return Errno::Notdir; } debug!("Creating file"); // strip end file name @@ -2392,8 +2393,8 @@ pub fn path_open( new_path.push(&new_entity_name); new_path } - Kind::Root { .. } => return __WASI_EACCES, - _ => return __WASI_EINVAL, + Kind::Root { .. } => return Errno::Access, + _ => return Errno::Inval, } }; // once we got the data we need from the parent, we lookup the host file @@ -2401,7 +2402,7 @@ pub fn path_open( let handle = { let open_options = open_options .read(true) - .append(fs_flags & __WASI_FDFLAG_APPEND != 0) + .append(fs_flags.contains(Fdflags::APPEND)) // TODO: ensure these rights are actually valid given parent, etc. // write access is required for creating a file .write(true) @@ -2463,13 +2464,13 @@ pub fn path_open( wasi_try_mem!(fd_ref.write(out_fd)); debug!("wasi::path_open returning fd {}", out_fd); - __WASI_ESUCCESS + Errno::Success } /// ### `path_readlink()` /// Read the value of a symlink /// Inputs: -/// - `__wasi_fd_t dir_fd` +/// - `Fd dir_fd` /// The base directory from which `path` is understood /// - `const char *path` /// Pointer to UTF-8 bytes that make up the path to the symlink @@ -2484,20 +2485,20 @@ pub fn path_open( /// The number of bytes written to `buf` pub fn path_readlink( ctx: FunctionEnvMut<'_, WasiEnv>, - dir_fd: __wasi_fd_t, + dir_fd: WasiFd, path: WasmPtr, path_len: M::Offset, buf: WasmPtr, buf_len: M::Offset, buf_used: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::path_readlink"); let env = ctx.data(); let (memory, mut state, mut inodes) = env.get_memory_and_wasi_state_and_inodes_mut(&ctx, 0); let base_dir = wasi_try!(state.fs.get_fd(dir_fd)); - if !has_rights(base_dir.rights, __WASI_RIGHT_PATH_READLINK) { - return __WASI_EACCES; + if !base_dir.rights.contains(Rights::PATH_READLINK) { + return Errno::Access; } let path_str = unsafe { get_input_str!(&memory, path, path_len) }; let inode = wasi_try!(state @@ -2512,7 +2513,7 @@ pub fn path_readlink( let buf_len: u64 = buf_len.into(); let bytes = rel_path_str.bytes(); if bytes.len() as u64 >= buf_len { - return __WASI_EOVERFLOW; + return Errno::Overflow; } let bytes: Vec<_> = bytes.collect(); @@ -2521,23 +2522,23 @@ pub fn path_readlink( // should we null terminate this? let bytes_len: M::Offset = - wasi_try!(bytes.len().try_into().map_err(|_| __WASI_EOVERFLOW)); + wasi_try!(bytes.len().try_into().map_err(|_| Errno::Overflow)); wasi_try_mem!(buf_used.deref(&memory).write(bytes_len)); } else { - return __WASI_EINVAL; + return Errno::Inval; } } - __WASI_ESUCCESS + Errno::Success } -/// Returns __WASI_ENOTEMTPY if directory is not empty +/// Returns Errno::Notemtpy if directory is not empty pub fn path_remove_directory( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: WasiFd, path: WasmPtr, path_len: M::Offset, -) -> __wasi_errno_t { +) -> Errno { // TODO check if fd is a dir, ensure it's within sandbox, etc. debug!("wasi::path_remove_directory"); let env = ctx.data(); @@ -2562,12 +2563,12 @@ pub fn path_remove_directory( match deref { Kind::Dir { entries, path, .. } => { if !entries.is_empty() || wasi_try!(state.fs_read_dir(path)).count() != 0 { - return __WASI_ENOTEMPTY; + return Errno::Notempty; } path.clone() } - Kind::Root { .. } => return __WASI_EACCES, - _ => return __WASI_ENOTDIR, + Kind::Root { .. } => return Errno::Access, + _ => return Errno::Notdir, } }; @@ -2578,11 +2579,11 @@ pub fn path_remove_directory( Kind::Dir { ref mut entries, .. } => { - let removed_inode = wasi_try!(entries.remove(&childs_name).ok_or(__WASI_EINVAL)); + let removed_inode = wasi_try!(entries.remove(&childs_name).ok_or(Errno::Inval)); // TODO: make this a debug assert in the future assert!(inode == removed_inode); } - Kind::Root { .. } => return __WASI_EACCES, + Kind::Root { .. } => return Errno::Access, _ => unreachable!( "Internal logic error in wasi::path_remove_directory, parent is not a directory" ), @@ -2601,19 +2602,19 @@ pub fn path_remove_directory( return err; } - __WASI_ESUCCESS + Errno::Success } /// ### `path_rename()` /// Rename a file or directory /// Inputs: -/// - `__wasi_fd_t old_fd` +/// - `Fd old_fd` /// The base directory for `old_path` /// - `const char* old_path` /// Pointer to UTF8 bytes, the file to be renamed /// - `u32 old_path_len` /// The number of bytes to read from `old_path` -/// - `__wasi_fd_t new_fd` +/// - `Fd new_fd` /// The base directory for `new_path` /// - `const char* new_path` /// Pointer to UTF8 bytes, the new file name @@ -2621,13 +2622,13 @@ pub fn path_remove_directory( /// The number of bytes to read from `new_path` pub fn path_rename( ctx: FunctionEnvMut<'_, WasiEnv>, - old_fd: __wasi_fd_t, + old_fd: WasiFd, old_path: WasmPtr, old_path_len: M::Offset, - new_fd: __wasi_fd_t, + new_fd: WasiFd, new_path: WasmPtr, new_path_len: M::Offset, -) -> __wasi_errno_t { +) -> Errno { debug!( "wasi::path_rename: old_fd = {}, new_fd = {}", old_fd, new_fd @@ -2642,12 +2643,12 @@ pub fn path_rename( { let source_fd = wasi_try!(state.fs.get_fd(old_fd)); - if !has_rights(source_fd.rights, __WASI_RIGHT_PATH_RENAME_SOURCE) { - return __WASI_EACCES; + if !source_fd.rights.contains(Rights::PATH_RENAME_SOURCE) { + return Errno::Access; } let target_fd = wasi_try!(state.fs.get_fd(new_fd)); - if !has_rights(target_fd.rights, __WASI_RIGHT_PATH_RENAME_TARGET) { - return __WASI_EACCES; + if !target_fd.rights.contains(Rights::PATH_RENAME_TARGET) { + return Errno::Access; } } @@ -2668,7 +2669,7 @@ pub fn path_rename( ) .is_ok() { - return __WASI_EEXIST; + return Errno::Exist; } let (source_parent_inode, source_entry_name) = wasi_try!(state @@ -2684,15 +2685,15 @@ pub fn path_rename( match deref { Kind::Dir { entries, path, .. } => { if entries.contains_key(&target_entry_name) { - return __WASI_EEXIST; + return Errno::Exist; } let mut out_path = path.clone(); out_path.push(std::path::Path::new(&target_entry_name)); out_path } - Kind::Root { .. } => return __WASI_ENOTCAPABLE, + Kind::Root { .. } => return Errno::Notcapable, Kind::Socket { .. } | Kind::Pipe { .. } | Kind::EventNotifications { .. } => { - return __WASI_EINVAL + return Errno::Inval } Kind::Symlink { .. } | Kind::File { .. } | Kind::Buffer { .. } => { unreachable!("Fatal internal logic error: parent of inode is not a directory") @@ -2705,11 +2706,11 @@ pub fn path_rename( let deref_mut = guard.deref_mut(); match deref_mut { Kind::Dir { entries, .. } => { - wasi_try!(entries.remove(&source_entry_name).ok_or(__WASI_ENOENT)) + wasi_try!(entries.remove(&source_entry_name).ok_or(Errno::Noent)) } - Kind::Root { .. } => return __WASI_ENOTCAPABLE, + Kind::Root { .. } => return Errno::Notcapable, Kind::Socket { .. } | Kind::Pipe { .. } | Kind::EventNotifications { .. } => { - return __WASI_EINVAL + return Errno::Inval } Kind::Symlink { .. } | Kind::File { .. } | Kind::Buffer { .. } => { unreachable!("Fatal internal logic error: parent of inode is not a directory") @@ -2788,7 +2789,7 @@ pub fn path_rename( } } - __WASI_ESUCCESS + Errno::Success } /// ### `path_symlink()` @@ -2798,7 +2799,7 @@ pub fn path_rename( /// Array of UTF-8 bytes representing the source path /// - `u32 old_path_len` /// The number of bytes to read from `old_path` -/// - `__wasi_fd_t fd` +/// - `Fd fd` /// The base directory from which the paths are understood /// - `const char *new_path` /// Array of UTF-8 bytes representing the target path @@ -2808,18 +2809,18 @@ pub fn path_symlink( ctx: FunctionEnvMut<'_, WasiEnv>, old_path: WasmPtr, old_path_len: M::Offset, - fd: __wasi_fd_t, + fd: WasiFd, new_path: WasmPtr, new_path_len: M::Offset, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::path_symlink"); let env = ctx.data(); let (memory, mut state, mut inodes) = env.get_memory_and_wasi_state_and_inodes_mut(&ctx, 0); let old_path_str = unsafe { get_input_str!(&memory, old_path, old_path_len) }; let new_path_str = unsafe { get_input_str!(&memory, new_path, new_path_len) }; let base_fd = wasi_try!(state.fs.get_fd(fd)); - if !has_rights(base_fd.rights, __WASI_RIGHT_PATH_SYMLINK) { - return __WASI_EACCES; + if !base_fd.rights.contains(Rights::PATH_SYMLINK) { + return Errno::Access; } // get the depth of the parent + 1 (UNDER INVESTIGATION HMMMMMMMM THINK FISH ^ THINK FISH) @@ -2846,12 +2847,12 @@ pub fn path_symlink( match deref { Kind::Dir { entries, .. } => { if entries.contains_key(&entry_name) { - return __WASI_EEXIST; + return Errno::Exist; } } - Kind::Root { .. } => return __WASI_ENOTCAPABLE, + Kind::Root { .. } => return Errno::Notcapable, Kind::Socket { .. } | Kind::Pipe { .. } | Kind::EventNotifications { .. } => { - return __WASI_EINVAL + return Errno::Inval } Kind::File { .. } | Kind::Symlink { .. } | Kind::Buffer { .. } => { unreachable!("get_parent_inode_at_path returned something other than a Dir or Root") @@ -2893,13 +2894,13 @@ pub fn path_symlink( } } - __WASI_ESUCCESS + Errno::Success } /// ### `path_unlink_file()` /// Unlink a file, deleting if the number of hardlinks is 1 /// Inputs: -/// - `__wasi_fd_t fd` +/// - `Fd fd` /// The base file descriptor from which the path is understood /// - `const char *path` /// Array of UTF-8 bytes representing the path @@ -2907,17 +2908,17 @@ pub fn path_symlink( /// The number of bytes in the `path` array pub fn path_unlink_file( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: WasiFd, path: WasmPtr, path_len: M::Offset, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::path_unlink_file"); let env = ctx.data(); let (memory, mut state, mut inodes) = env.get_memory_and_wasi_state_and_inodes_mut(&ctx, 0); let base_dir = wasi_try!(state.fs.get_fd(fd)); - if !has_rights(base_dir.rights, __WASI_RIGHT_PATH_UNLINK_FILE) { - return __WASI_EACCES; + if !base_dir.rights.contains(Rights::PATH_UNLINK_FILE) { + return Errno::Access; } let path_str = unsafe { get_input_str!(&memory, path, path_len) }; debug!("Requested file: {}", path_str); @@ -2939,13 +2940,13 @@ pub fn path_unlink_file( Kind::Dir { ref mut entries, .. } => { - let removed_inode = wasi_try!(entries.remove(&childs_name).ok_or(__WASI_EINVAL)); + let removed_inode = wasi_try!(entries.remove(&childs_name).ok_or(Errno::Inval)); // TODO: make this a debug assert in the future assert!(inode == removed_inode); debug_assert!(inodes.arena[inode].stat.read().unwrap().st_nlink > 0); removed_inode } - Kind::Root { .. } => return __WASI_EACCES, + Kind::Root { .. } => return Errno::Access, _ => unreachable!( "Internal logic error in wasi::path_unlink_file, parent is not a directory" ), @@ -2973,7 +2974,7 @@ pub fn path_unlink_file( wasi_try!(state.fs_remove_file(path)); } } - Kind::Dir { .. } | Kind::Root { .. } => return __WASI_EISDIR, + Kind::Dir { .. } | Kind::Root { .. } => return Errno::Isdir, Kind::Symlink { .. } => { // TODO: actually delete real symlinks and do nothing for virtual symlinks } @@ -3003,7 +3004,7 @@ pub fn path_unlink_file( } } - __WASI_ESUCCESS + Errno::Success } /// ### `poll_oneoff()` @@ -3011,7 +3012,7 @@ pub fn path_unlink_file( /// Inputs: /// - `const __wasi_subscription_t *in` /// The events to subscribe to -/// - `__wasi_event_t *out` +/// - `Event *out` /// The events that have occured /// - `u32 nsubscriptions` /// The number of subscriptions and the number of events @@ -3020,11 +3021,11 @@ pub fn path_unlink_file( /// The number of events seen pub fn poll_oneoff( ctx: FunctionEnvMut<'_, WasiEnv>, - in_: WasmPtr<__wasi_subscription_t, M>, - out_: WasmPtr<__wasi_event_t, M>, + in_: WasmPtr, + out_: WasmPtr, nsubscriptions: M::Offset, nevents: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { trace!("wasi::poll_oneoff"); trace!(" => nsubscriptions = {}", nsubscriptions); let env = ctx.data(); @@ -3041,44 +3042,42 @@ pub fn poll_oneoff( let mut time_to_sleep = Duration::from_millis(5); for sub in subscription_array.iter() { - let s: WasiSubscription = wasi_try_ok!(wasi_try_mem_ok!(sub.read()).try_into()); + let s: Subscription = wasi_try_mem_ok!(sub.read()); let mut peb = PollEventBuilder::new(); - let fd = match s.event_type { - EventType::Read(__wasi_subscription_fs_readwrite_t { fd }) => { - match fd { + let fd = match s.data { + SubscriptionEnum::Read(SubscriptionFsReadwrite { file_descriptor }) => { + match file_descriptor { __WASI_STDIN_FILENO | __WASI_STDOUT_FILENO | __WASI_STDERR_FILENO => (), _ => { - let fd_entry = wasi_try_ok!(state.fs.get_fd(fd), env); - if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_READ) { - return Ok(__WASI_EACCES); + let fd_entry = wasi_try_ok!(state.fs.get_fd(file_descriptor), env); + if !fd_entry.rights.contains(Rights::FD_READ) { + return Ok(Errno::Access); } } } in_events.push(peb.add(PollEvent::PollIn).build()); - Some(fd) + Some(file_descriptor) } - EventType::Write(__wasi_subscription_fs_readwrite_t { fd }) => { - match fd { + SubscriptionEnum::Write(SubscriptionFsReadwrite { file_descriptor }) => { + match file_descriptor { __WASI_STDIN_FILENO | __WASI_STDOUT_FILENO | __WASI_STDERR_FILENO => (), _ => { - let fd_entry = wasi_try_ok!(state.fs.get_fd(fd), env); - if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_WRITE) { - return Ok(__WASI_EACCES); + let fd_entry = wasi_try_ok!(state.fs.get_fd(file_descriptor), env); + if !fd_entry.rights.contains(Rights::FD_WRITE) { + return Ok(Errno::Access); } } } in_events.push(peb.add(PollEvent::PollOut).build()); - Some(fd) + Some(file_descriptor) } - EventType::Clock(clock_info) => { - if clock_info.clock_id == __WASI_CLOCK_REALTIME - || clock_info.clock_id == __WASI_CLOCK_MONOTONIC - { + SubscriptionEnum::Clock(clock_info) => { + if matches!(clock_info.clock_id, Clockid::Realtime | Clockid::Monotonic) { // this is a hack // TODO: do this properly time_to_sleep = Duration::from_nanos(clock_info.timeout); - clock_subs.push((clock_info, s.user_data)); + clock_subs.push((clock_info, s.userdata)); None } else { unimplemented!("Polling not implemented for clocks yet"); @@ -3115,8 +3114,8 @@ pub fn poll_oneoff( _ => { let fd_entry = wasi_try_ok!(state.fs.get_fd(fd), env); let inode = fd_entry.inode; - if !has_rights(fd_entry.rights, __WASI_RIGHT_POLL_FD_READWRITE) { - return Ok(__WASI_EACCES); + if !fd_entry.rights.contains(Rights::POLL_FD_READWRITE) { + return Ok(Errno::Access); } { @@ -3127,13 +3126,13 @@ pub fn poll_oneoff( if let Some(h) = handle { crate::state::InodeValFileReadGuard { guard } } else { - return Ok(__WASI_EBADF); + return Ok(Errno::Badf); } } Kind::Socket { .. } | Kind::Pipe { .. } | Kind::EventNotifications { .. } => { - return Ok(__WASI_EBADF); + return Ok(Errno::Badf); } Kind::Dir { .. } | Kind::Root { .. } @@ -3153,17 +3152,17 @@ pub fn poll_oneoff( let fds = { let mut f = vec![]; for fd in fd_guards.iter() { - f.push(wasi_try_ok!(fd.as_ref().ok_or(__WASI_EBADF)).deref()); + f.push(wasi_try_ok!(fd.as_ref().ok_or(Errno::Badf)).deref()); } f }; let mut seen_events = vec![Default::default(); in_events.len()]; - let start = platform_clock_time_get(__WASI_CLOCK_MONOTONIC, 1_000_000).unwrap() as u128; + let start = platform_clock_time_get(Snapshot0Clockid::Monotonic, 1_000_000).unwrap() as u128; let mut triggered = 0; while triggered == 0 { - let now = platform_clock_time_get(__WASI_CLOCK_MONOTONIC, 1_000_000).unwrap() as u128; + let now = platform_clock_time_get(Snapshot0Clockid::Monotonic, 1_000_000).unwrap() as u128; let delta = match now.checked_sub(start) { Some(a) => Duration::from_nanos(a as u64), None => Duration::ZERO, @@ -3193,15 +3192,15 @@ pub fn poll_oneoff( } for (i, seen_event) in seen_events.into_iter().enumerate() { - let mut flags = 0; - let mut error = __WASI_EAGAIN; + let mut flags = Eventrwflags::empty(); + let mut error = Errno::Again; let mut bytes_available = 0; let event_iter = iterate_poll_events(seen_event); for event in event_iter { match event { - PollEvent::PollError => error = __WASI_EIO, - PollEvent::PollHangUp => flags = __WASI_EVENT_FD_READWRITE_HANGUP, - PollEvent::PollInvalid => error = __WASI_EINVAL, + PollEvent::PollError => error = Errno::Io, + PollEvent::PollHangUp => flags = Eventrwflags::FD_READWRITE_HANGUP, + PollEvent::PollInvalid => error = Errno::Inval, PollEvent::PollIn => { bytes_available = wasi_try_ok!( fds[i] @@ -3210,7 +3209,7 @@ pub fn poll_oneoff( env ) .unwrap_or(0usize); - error = __WASI_ESUCCESS; + error = Errno::Success; } PollEvent::PollOut => { bytes_available = wasi_try_ok!( @@ -3220,21 +3219,23 @@ pub fn poll_oneoff( env ) .unwrap_or(0usize); - error = __WASI_ESUCCESS; + error = Errno::Success; } } } - let event = __wasi_event_t { + let event = Event { userdata: wasi_try_mem_ok!(subscription_array.index(i as u64).read()).userdata, error, - type_: wasi_try_mem_ok!(subscription_array.index(i as u64).read()).type_, - u: unsafe { - __wasi_event_u { - fd_readwrite: __wasi_event_fd_readwrite_t { - nbytes: bytes_available as u64, - flags, - }, - } + data: match wasi_try_mem_ok!(subscription_array.index(i as u64).read()).data { + SubscriptionEnum::Read(d) => EventEnum::FdRead(EventFdReadwrite { + nbytes: bytes_available as u64, + flags, + }), + SubscriptionEnum::Write(d) => EventEnum::FdWrite(EventFdReadwrite { + nbytes: bytes_available as u64, + flags, + }), + SubscriptionEnum::Clock(_) => EventEnum::Clock, }, }; wasi_try_mem_ok!(event_array.index(events_seen as u64).write(event)); @@ -3242,26 +3243,18 @@ pub fn poll_oneoff( } if triggered == 0 { for (clock_info, userdata) in clock_subs { - let event = __wasi_event_t { + let event = Event { userdata, - error: __WASI_ESUCCESS, - type_: __WASI_EVENTTYPE_CLOCK, - u: unsafe { - __wasi_event_u { - fd_readwrite: __wasi_event_fd_readwrite_t { - nbytes: 0, - flags: 0, - }, - } - }, + error: Errno::Success, + data: EventEnum::Clock, }; wasi_try_mem_ok!(event_array.index(events_seen as u64).write(event)); events_seen += 1; } } - let events_seen: M::Offset = wasi_try_ok!(events_seen.try_into().map_err(|_| __WASI_EOVERFLOW)); + let events_seen: M::Offset = wasi_try_ok!(events_seen.try_into().map_err(|_| Errno::Overflow)); wasi_try_mem_ok!(out_ptr.write(events_seen)); - Ok(__WASI_ESUCCESS) + Ok(Errno::Success) } /// ### `proc_exit()` @@ -3283,20 +3276,20 @@ pub fn proc_exit( /// Send a signal to the process of the calling thread. /// Note: This is similar to `raise` in POSIX. /// Inputs: -/// - `__wasi_signal_t` +/// - `Signal` /// Signal to be raised for this process -pub fn proc_raise(ctx: FunctionEnvMut<'_, WasiEnv>, sig: __wasi_signal_t) -> __wasi_errno_t { +pub fn proc_raise(ctx: FunctionEnvMut<'_, WasiEnv>, sig: Signal) -> Errno { debug!("wasi::proc_raise"); unimplemented!("wasi::proc_raise") } /// ### `sched_yield()` /// Yields execution of the thread -pub fn sched_yield(ctx: FunctionEnvMut<'_, WasiEnv>) -> Result<__wasi_errno_t, WasiError> { +pub fn sched_yield(ctx: FunctionEnvMut<'_, WasiEnv>) -> Result { trace!("wasi::sched_yield"); let env = ctx.data(); env.yield_now()?; - Ok(__WASI_ESUCCESS) + Ok(Errno::Success) } /// ### `random_get()` @@ -3310,7 +3303,7 @@ pub fn random_get( ctx: FunctionEnvMut<'_, WasiEnv>, buf: WasmPtr, buf_len: M::Offset, -) -> __wasi_errno_t { +) -> Errno { trace!("wasi::random_get buf_len: {}", buf_len); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -3321,9 +3314,9 @@ pub fn random_get( Ok(()) => { let buf = wasi_try_mem!(buf.slice(&memory, buf_len)); wasi_try_mem!(buf.write_slice(&u8_buffer)); - __WASI_ESUCCESS + Errno::Success } - Err(_) => __WASI_EIO, + Err(_) => Errno::Io, } } @@ -3331,51 +3324,36 @@ pub fn random_get( /// Retrieves the current state of the TTY pub fn tty_get( ctx: FunctionEnvMut<'_, WasiEnv>, - tty_state: WasmPtr<__wasi_tty_t, M>, -) -> __wasi_errno_t { + tty_state: WasmPtr, +) -> Errno { debug!("wasi::tty_stdin"); let env = ctx.data(); let state = env.runtime.tty_get(); - let state = __wasi_tty_t { + let state = Tty { cols: state.cols, rows: state.rows, width: state.width, height: state.height, - stdin_tty: match state.stdin_tty { - false => __WASI_BOOL_FALSE, - true => __WASI_BOOL_TRUE, - }, - stdout_tty: match state.stdout_tty { - false => __WASI_BOOL_FALSE, - true => __WASI_BOOL_TRUE, - }, - stderr_tty: match state.stderr_tty { - false => __WASI_BOOL_FALSE, - true => __WASI_BOOL_TRUE, - }, - echo: match state.echo { - false => __WASI_BOOL_FALSE, - true => __WASI_BOOL_TRUE, - }, - line_buffered: match state.line_buffered { - false => __WASI_BOOL_FALSE, - true => __WASI_BOOL_TRUE, - }, + stdin_tty: state.stdin_tty, + stdout_tty: state.stdout_tty, + stderr_tty: state.stderr_tty, + echo: state.echo, + line_buffered: state.line_buffered, }; let memory = env.memory_view(&ctx); wasi_try_mem!(tty_state.write(&memory, state)); - __WASI_ESUCCESS + Errno::Success } /// ### `tty_set()` /// Updates the properties of the rect pub fn tty_set( ctx: FunctionEnvMut<'_, WasiEnv>, - tty_state: WasmPtr<__wasi_tty_t, M>, -) -> __wasi_errno_t { + tty_state: WasmPtr, +) -> Errno { debug!("wasi::tty_set"); let env = ctx.data(); @@ -3386,36 +3364,16 @@ pub fn tty_set( rows: state.rows, width: state.width, height: state.height, - stdin_tty: match state.stdin_tty { - __WASI_BOOL_FALSE => false, - __WASI_BOOL_TRUE => true, - _ => return __WASI_EINVAL, - }, - stdout_tty: match state.stdout_tty { - __WASI_BOOL_FALSE => false, - __WASI_BOOL_TRUE => true, - _ => return __WASI_EINVAL, - }, - stderr_tty: match state.stderr_tty { - __WASI_BOOL_FALSE => false, - __WASI_BOOL_TRUE => true, - _ => return __WASI_EINVAL, - }, - echo: match state.echo { - __WASI_BOOL_FALSE => false, - __WASI_BOOL_TRUE => true, - _ => return __WASI_EINVAL, - }, - line_buffered: match state.line_buffered { - __WASI_BOOL_FALSE => false, - __WASI_BOOL_TRUE => true, - _ => return __WASI_EINVAL, - }, + stdin_tty: state.stdin_tty, + stdout_tty: state.stdout_tty, + stderr_tty: state.stderr_tty, + echo: state.echo, + line_buffered: state.line_buffered, }; env.runtime.tty_set(state); - __WASI_ESUCCESS + Errno::Success } /// ### `getcwd()` @@ -3426,7 +3384,7 @@ pub fn getcwd( ctx: FunctionEnvMut<'_, WasiEnv>, path: WasmPtr, path_len: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::getcwd"); let env = ctx.data(); let (memory, mut state, mut inodes) = env.get_memory_and_wasi_state_and_inodes_mut(&ctx, 0); @@ -3442,7 +3400,7 @@ pub fn getcwd( let cur_dir = cur_dir.as_bytes(); wasi_try_mem!(path_len.write(&memory, wasi_try!(to_offset::(cur_dir.len())))); if cur_dir.len() as u64 >= max_path_len { - return __WASI_EOVERFLOW; + return Errno::Overflow; } let cur_dir = { @@ -3452,13 +3410,13 @@ pub fn getcwd( u8_buffer[..cur_dir_len].clone_from_slice(cur_dir); u8_buffer[cur_dir_len] = 0; } else { - return __WASI_EOVERFLOW; + return Errno::Overflow; } u8_buffer }; wasi_try_mem!(path_slice.write_slice(&cur_dir[..])); - __WASI_ESUCCESS + Errno::Success } /// ### `chdir()` @@ -3467,14 +3425,14 @@ pub fn chdir( ctx: FunctionEnvMut<'_, WasiEnv>, path: WasmPtr, path_len: M::Offset, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::chdir"); let env = ctx.data(); let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0); let path = unsafe { get_input_str!(&memory, path, path_len) }; state.fs.set_current_dir(path.as_str()); - __WASI_ESUCCESS + Errno::Success } /// ### `thread_spawn()` @@ -3500,9 +3458,9 @@ pub fn thread_spawn( method: WasmPtr, method_len: M::Offset, user_data: u64, - reactor: __wasi_bool_t, - ret_tid: WasmPtr<__wasi_tid_t, M>, -) -> __wasi_errno_t { + reactor: Bool, + ret_tid: WasmPtr, +) -> Errno { debug!("wasi::thread_spawn"); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -3510,21 +3468,21 @@ pub fn thread_spawn( // Load the callback function if method.as_str() != "_thread_start" { - return __WASI_ENOTCAPABLE; + return Errno::Notcapable; }; /* let funct = unsafe { if env.thread_start_ref().is_none() { - return __WASI_EADDRNOTAVAIL; + return Errno::Addrnotavail; } env.thread_start_ref_unchecked() }; */ let reactor = match reactor { - __WASI_BOOL_FALSE => false, - __WASI_BOOL_TRUE => true, - _ => return __WASI_EINVAL, + Bool::False => false, + Bool::True => true, + _ => return Errno::Inval, }; // Create the sub-thread @@ -3565,15 +3523,15 @@ pub fn thread_spawn( drop(sub_thread); })) .map_err(|err| { - let err: __wasi_errno_t = err.into(); + let err: Errno = err.into(); err })); id }; - let child: __wasi_tid_t = child.into(); + let child: Tid = child.into(); wasi_try_mem!(ret_tid.write(&memory, child)); - __WASI_ESUCCESS + Errno::Success } /// ### `thread_sleep()` @@ -3584,14 +3542,14 @@ pub fn thread_spawn( /// * `duration` - Amount of time that the thread should sleep pub fn thread_sleep( ctx: FunctionEnvMut<'_, WasiEnv>, - duration: __wasi_timestamp_t, -) -> Result<__wasi_errno_t, WasiError> { + duration: Timestamp, +) -> Result { debug!("wasi::thread_sleep"); let env = ctx.data(); let duration = Duration::from_nanos(duration as u64); env.sleep(duration)?; - Ok(__WASI_ESUCCESS) + Ok(Errno::Success) } /// ### `thread_id()` @@ -3599,15 +3557,15 @@ pub fn thread_sleep( /// (threads indices are sequencial from zero) pub fn thread_id( ctx: FunctionEnvMut<'_, WasiEnv>, - ret_tid: WasmPtr<__wasi_tid_t, M>, -) -> __wasi_errno_t { + ret_tid: WasmPtr, +) -> Errno { debug!("wasi::thread_id"); let env = ctx.data(); - let tid: __wasi_tid_t = env.id.into(); + let tid: Tid = env.id.into(); let memory = env.memory_view(&ctx); wasi_try_mem!(ret_tid.write(&memory, tid)); - __WASI_ESUCCESS + Errno::Success } /// ### `thread_join()` @@ -3617,10 +3575,7 @@ pub fn thread_id( /// ## Parameters /// /// * `tid` - Handle of the thread to wait on -pub fn thread_join( - ctx: FunctionEnvMut<'_, WasiEnv>, - tid: __wasi_tid_t, -) -> Result<__wasi_errno_t, WasiError> { +pub fn thread_join(ctx: FunctionEnvMut<'_, WasiEnv>, tid: Tid) -> Result { debug!("wasi::thread_join"); let env = ctx.data(); @@ -3636,9 +3591,9 @@ pub fn thread_join( } env.yield_now()?; } - Ok(__WASI_ESUCCESS) + Ok(Errno::Success) } else { - Ok(__WASI_ESUCCESS) + Ok(Errno::Success) } } @@ -3648,36 +3603,33 @@ pub fn thread_join( pub fn thread_parallelism( ctx: FunctionEnvMut<'_, WasiEnv>, ret_parallelism: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::thread_parallelism"); let env = ctx.data(); let parallelism = wasi_try!(env.runtime().thread_parallelism().map_err(|err| { - let err: __wasi_errno_t = err.into(); + let err: Errno = err.into(); err })); - let parallelism: M::Offset = wasi_try!(parallelism.try_into().map_err(|_| __WASI_EOVERFLOW)); + let parallelism: M::Offset = wasi_try!(parallelism.try_into().map_err(|_| Errno::Overflow)); let memory = env.memory_view(&ctx); wasi_try_mem!(ret_parallelism.write(&memory, parallelism)); - __WASI_ESUCCESS + Errno::Success } /// ### `getpid()` /// Returns the handle of the current process -pub fn getpid( - ctx: FunctionEnvMut<'_, WasiEnv>, - ret_pid: WasmPtr<__wasi_pid_t, M>, -) -> __wasi_errno_t { +pub fn getpid(ctx: FunctionEnvMut<'_, WasiEnv>, ret_pid: WasmPtr) -> Errno { debug!("wasi::getpid"); let env = ctx.data(); let pid = env.runtime().getpid(); if let Some(pid) = pid { let memory = env.memory_view(&ctx); - wasi_try_mem!(ret_pid.write(&memory, pid as __wasi_pid_t)); - __WASI_ESUCCESS + wasi_try_mem!(ret_pid.write(&memory, pid as Pid)); + Errno::Success } else { - __WASI_ENOTSUP + Errno::Notsup } } @@ -3693,7 +3645,7 @@ pub fn getpid( pub fn thread_exit( ctx: FunctionEnvMut<'_, WasiEnv>, exitcode: __wasi_exitcode_t, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { debug!("wasi::thread_exit"); Err(WasiError::Exit(exitcode)) } @@ -3721,18 +3673,18 @@ pub fn process_spawn( ctx: FunctionEnvMut<'_, WasiEnv>, name: WasmPtr, name_len: M::Offset, - chroot: __wasi_bool_t, + chroot: Bool, args: WasmPtr, args_len: M::Offset, preopen: WasmPtr, preopen_len: M::Offset, - stdin: __wasi_stdiomode_t, - stdout: __wasi_stdiomode_t, - stderr: __wasi_stdiomode_t, + stdin: WasiStdioMode, + stdout: WasiStdioMode, + stderr: WasiStdioMode, working_dir: WasmPtr, working_dir_len: M::Offset, - ret_handles: WasmPtr<__wasi_bus_handles_t, M>, -) -> __bus_errno_t { + ret_handles: WasmPtr, +) -> BusErrno { let env = ctx.data(); let bus = env.runtime.bus(); let memory = env.memory_view(&ctx); @@ -3740,7 +3692,7 @@ pub fn process_spawn( let args = unsafe { get_input_str_bus!(&memory, args, args_len) }; let preopen = unsafe { get_input_str_bus!(&memory, preopen, preopen_len) }; let working_dir = unsafe { get_input_str_bus!(&memory, working_dir, working_dir_len) }; - let chroot = chroot == __WASI_BOOL_TRUE; + let chroot = chroot == Bool::True; debug!("wasi::process_spawn (name={})", name); let args: Vec<_> = args.split(&['\n', '\r']).map(|a| a.to_string()).collect(); @@ -3750,10 +3702,10 @@ pub fn process_spawn( .map(|a| a.to_string()) .collect(); - let conv_stdio_mode = |mode: __wasi_stdiomode_t| match mode { - __WASI_STDIO_MODE_PIPED => StdioMode::Piped, - __WASI_STDIO_MODE_INHERIT => StdioMode::Inherit, - __WASI_STDIO_MODE_LOG => StdioMode::Log, + let conv_stdio_mode = |mode: WasiStdioMode| match mode { + WasiStdioMode::Piped => StdioMode::Piped, + WasiStdioMode::Inherit => StdioMode::Inherit, + WasiStdioMode::Log => StdioMode::Log, /*__WASI_STDIO_MODE_NULL |*/ _ => StdioMode::Null, }; @@ -3770,12 +3722,12 @@ pub fn process_spawn( .map_err(bus_error_into_wasi_err)); let conv_stdio_fd = |a: Option| match a { - Some(fd) => __wasi_option_fd_t { - tag: __WASI_OPTION_SOME, + Some(fd) => OptionFd { + tag: OptionTag::Some, fd: fd.into(), }, - None => __wasi_option_fd_t { - tag: __WASI_OPTION_NONE, + None => OptionFd { + tag: OptionTag::None, fd: 0, }, }; @@ -3794,7 +3746,7 @@ pub fn process_spawn( bid }; - let handles = __wasi_bus_handles_t { + let handles = BusHandles { bid, stdin, stdout, @@ -3803,7 +3755,7 @@ pub fn process_spawn( wasi_try_mem_bus!(ret_handles.write(&memory, handles)); - __BUS_ESUCCESS + BusErrno::Success } /// Spawns a new bus process for a particular web WebAssembly @@ -3822,14 +3774,14 @@ pub fn bus_open_local( ctx: FunctionEnvMut<'_, WasiEnv>, name: WasmPtr, name_len: M::Offset, - reuse: __wasi_bool_t, - ret_bid: WasmPtr<__wasi_bid_t, M>, -) -> __bus_errno_t { + reuse: Bool, + ret_bid: WasmPtr, +) -> BusErrno { let env = ctx.data(); let bus = env.runtime.bus(); let memory = env.memory_view(&ctx); let name = unsafe { get_input_str_bus!(&memory, name, name_len) }; - let reuse = reuse == __WASI_BOOL_TRUE; + let reuse = reuse == Bool::True; debug!("wasi::bus_open_local (name={}, reuse={})", name, reuse); bus_open_local_internal(ctx, name, reuse, None, None, ret_bid) @@ -3853,20 +3805,20 @@ pub fn bus_open_remote( ctx: FunctionEnvMut<'_, WasiEnv>, name: WasmPtr, name_len: M::Offset, - reuse: __wasi_bool_t, + reuse: Bool, instance: WasmPtr, instance_len: M::Offset, token: WasmPtr, token_len: M::Offset, - ret_bid: WasmPtr<__wasi_bid_t, M>, -) -> __bus_errno_t { + ret_bid: WasmPtr, +) -> BusErrno { let env = ctx.data(); let bus = env.runtime.bus(); let memory = env.memory_view(&ctx); let name = unsafe { get_input_str_bus!(&memory, name, name_len) }; let instance = unsafe { get_input_str_bus!(&memory, instance, instance_len) }; let token = unsafe { get_input_str_bus!(&memory, token, token_len) }; - let reuse = reuse == __WASI_BOOL_TRUE; + let reuse = reuse == Bool::True; debug!( "wasi::bus_open_remote (name={}, reuse={}, instance={})", name, reuse, instance @@ -3881,8 +3833,8 @@ fn bus_open_local_internal( reuse: bool, instance: Option, token: Option, - ret_bid: WasmPtr<__wasi_bid_t, M>, -) -> __bus_errno_t { + ret_bid: WasmPtr, +) -> BusErrno { let env = ctx.data(); let bus = env.runtime.bus(); let memory = env.memory_view(&ctx); @@ -3894,7 +3846,7 @@ fn bus_open_local_internal( if let Some(bid) = guard.process_reuse.get(&name) { if guard.processes.contains_key(bid) { wasi_try_mem_bus!(ret_bid.write(&memory, (*bid).into())); - return __BUS_ESUCCESS; + return BusErrno::Success; } } } @@ -3930,7 +3882,7 @@ fn bus_open_local_internal( wasi_try_mem_bus!(ret_bid.write(&memory, bid.into())); - __BUS_ESUCCESS + BusErrno::Success } /// Closes a bus process and releases all associated resources @@ -3938,7 +3890,7 @@ fn bus_open_local_internal( /// ## Parameters /// /// * `bid` - Handle of the bus process handle to be closed -pub fn bus_close(ctx: FunctionEnvMut<'_, WasiEnv>, bid: __wasi_bid_t) -> __bus_errno_t { +pub fn bus_close(ctx: FunctionEnvMut<'_, WasiEnv>, bid: Bid) -> BusErrno { trace!("wasi::bus_close (bid={})", bid); let bid: WasiBusProcessId = bid.into(); @@ -3946,7 +3898,7 @@ pub fn bus_close(ctx: FunctionEnvMut<'_, WasiEnv>, bid: __wasi_bid_t) -> __bus_e let mut guard = env.state.threading.lock().unwrap(); guard.processes.remove(&bid); - __BUS_EUNSUPPORTED + BusErrno::Unsupported } /// Invokes a call within a running bus process. @@ -3962,20 +3914,20 @@ pub fn bus_close(ctx: FunctionEnvMut<'_, WasiEnv>, bid: __wasi_bid_t) -> __bus_e /// * `buf` - The buffer where data to be transmitted is stored pub fn bus_call( ctx: FunctionEnvMut<'_, WasiEnv>, - bid: __wasi_bid_t, - keep_alive: __wasi_bool_t, + bid: Bid, + keep_alive: Bool, topic: WasmPtr, topic_len: M::Offset, - format: __wasi_busdataformat_t, + format: BusDataFormat, buf: WasmPtr, buf_len: M::Offset, - ret_cid: WasmPtr<__wasi_cid_t, M>, -) -> __bus_errno_t { + ret_cid: WasmPtr, +) -> BusErrno { let env = ctx.data(); let bus = env.runtime.bus(); let memory = env.memory_view(&ctx); let topic = unsafe { get_input_str_bus!(&memory, topic, topic_len) }; - let keep_alive = keep_alive == __WASI_BOOL_TRUE; + let keep_alive = keep_alive == Bool::True; trace!( "wasi::bus_call (bid={}, topic={}, buf_len={})", bid, @@ -3983,7 +3935,7 @@ pub fn bus_call( buf_len ); - __BUS_EUNSUPPORTED + BusErrno::Unsupported } /// Invokes a call within the context of another call @@ -3999,20 +3951,20 @@ pub fn bus_call( /// * `buf` - The buffer where data to be transmitted is stored pub fn bus_subcall( ctx: FunctionEnvMut<'_, WasiEnv>, - parent: __wasi_cid_t, - keep_alive: __wasi_bool_t, + parent: Cid, + keep_alive: Bool, topic: WasmPtr, topic_len: M::Offset, - format: __wasi_busdataformat_t, + format: BusDataFormat, buf: WasmPtr, buf_len: M::Offset, - ret_cid: WasmPtr<__wasi_cid_t, M>, -) -> __bus_errno_t { + ret_cid: WasmPtr, +) -> BusErrno { let env = ctx.data(); let bus = env.runtime.bus(); let memory = env.memory_view(&ctx); let topic = unsafe { get_input_str_bus!(&memory, topic, topic_len) }; - let keep_alive = keep_alive == __WASI_BOOL_TRUE; + let keep_alive = keep_alive == Bool::True; trace!( "wasi::bus_subcall (parent={}, topic={}, buf_len={})", parent, @@ -4020,7 +3972,7 @@ pub fn bus_subcall( buf_len ); - __BUS_EUNSUPPORTED + BusErrno::Unsupported } /// Polls for any outstanding events from a particular @@ -4039,20 +3991,20 @@ pub fn bus_subcall( /// Returns the number of events that have occured pub fn bus_poll( ctx: FunctionEnvMut<'_, WasiEnv>, - timeout: __wasi_timestamp_t, + timeout: Timestamp, events: WasmPtr, nevents: M::Offset, malloc: WasmPtr, malloc_len: M::Offset, ret_nevents: WasmPtr, -) -> __bus_errno_t { +) -> BusErrno { let env = ctx.data(); let bus = env.runtime.bus(); let memory = env.memory_view(&ctx); let malloc = unsafe { get_input_str_bus!(&memory, malloc, malloc_len) }; trace!("wasi::bus_poll (timeout={}, malloc={})", timeout, malloc); - __BUS_EUNSUPPORTED + BusErrno::Unsupported } /// Replies to a call that was made to this process @@ -4067,11 +4019,11 @@ pub fn bus_poll( /// * `buf` - The buffer where data to be transmitted is stored pub fn call_reply( ctx: FunctionEnvMut<'_, WasiEnv>, - cid: __wasi_cid_t, - format: __wasi_busdataformat_t, + cid: Cid, + format: BusDataFormat, buf: WasmPtr, buf_len: M::Offset, -) -> __bus_errno_t { +) -> BusErrno { let env = ctx.data(); let bus = env.runtime.bus(); trace!( @@ -4081,7 +4033,7 @@ pub fn call_reply( buf_len ); - __BUS_EUNSUPPORTED + BusErrno::Unsupported } /// Causes a fault on a particular call that was made @@ -4092,16 +4044,12 @@ pub fn call_reply( /// /// * `cid` - Handle of the call to raise a fault on /// * `fault` - Fault to be raised on the bus -pub fn call_fault( - ctx: FunctionEnvMut<'_, WasiEnv>, - cid: __wasi_cid_t, - fault: __bus_errno_t, -) -> __bus_errno_t { +pub fn call_fault(ctx: FunctionEnvMut<'_, WasiEnv>, cid: Cid, fault: BusErrno) -> BusErrno { let env = ctx.data(); let bus = env.runtime.bus(); debug!("wasi::call_fault (cid={}, fault={})", cid, fault); - __BUS_EUNSUPPORTED + BusErrno::Unsupported } /// Closes a bus call based on its bus call handle @@ -4109,12 +4057,12 @@ pub fn call_fault( /// ## Parameters /// /// * `cid` - Handle of the bus call handle to be dropped -pub fn call_close(ctx: FunctionEnvMut<'_, WasiEnv>, cid: __wasi_cid_t) -> __bus_errno_t { +pub fn call_close(ctx: FunctionEnvMut<'_, WasiEnv>, cid: Cid) -> BusErrno { let env = ctx.data(); let bus = env.runtime.bus(); trace!("wasi::call_close (cid={})", cid); - __BUS_EUNSUPPORTED + BusErrno::Unsupported } /// ### `ws_connect()` @@ -4131,8 +4079,8 @@ pub fn ws_connect( ctx: FunctionEnvMut<'_, WasiEnv>, url: WasmPtr, url_len: M::Offset, - ret_sock: WasmPtr<__wasi_fd_t, M>, -) -> __wasi_errno_t { + ret_sock: WasmPtr, +) -> Errno { debug!("wasi::ws_connect"); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -4155,12 +4103,14 @@ pub fn ws_connect( false, "socket".to_string(), ); - let rights = super::state::all_socket_rights(); - let fd = wasi_try!(state.fs.create_fd(rights, rights, 0, 0, inode)); + let rights = Rights::all_socket(); + let fd = wasi_try!(state + .fs + .create_fd(rights, rights, Fdflags::empty(), 0, inode)); wasi_try_mem!(ret_sock.write(&memory, fd)); - __WASI_ESUCCESS + Errno::Success } /// ### `http_request()` @@ -4187,9 +4137,9 @@ pub fn http_request( method_len: M::Offset, headers: WasmPtr, headers_len: M::Offset, - gzip: __wasi_bool_t, - ret_handles: WasmPtr<__wasi_http_handles_t, M>, -) -> __wasi_errno_t { + gzip: Bool, + ret_handles: WasmPtr, +) -> Errno { debug!("wasi::http_request"); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -4198,9 +4148,9 @@ pub fn http_request( let headers = unsafe { get_input_str!(&memory, headers, headers_len) }; let gzip = match gzip { - __WASI_BOOL_FALSE => false, - __WASI_BOOL_TRUE => true, - _ => return __WASI_EINVAL, + Bool::False => false, + Bool::True => true, + _ => return Errno::Inval, }; let socket = wasi_try!(env @@ -4265,17 +4215,23 @@ pub fn http_request( false, "http_headers".to_string(), ); - let rights = super::state::all_socket_rights(); + let rights = Rights::all_socket(); - let handles = __wasi_http_handles_t { - req: wasi_try!(state.fs.create_fd(rights, rights, 0, 0, inode_req)), - res: wasi_try!(state.fs.create_fd(rights, rights, 0, 0, inode_res)), - hdr: wasi_try!(state.fs.create_fd(rights, rights, 0, 0, inode_hdr)), + let handles = HttpHandles { + req: wasi_try!(state + .fs + .create_fd(rights, rights, Fdflags::empty(), 0, inode_req)), + res: wasi_try!(state + .fs + .create_fd(rights, rights, Fdflags::empty(), 0, inode_res)), + hdr: wasi_try!(state + .fs + .create_fd(rights, rights, Fdflags::empty(), 0, inode_hdr)), }; wasi_try_mem!(ret_handles.write(&memory, handles)); - __WASI_ESUCCESS + Errno::Success } /// ### `http_status()` @@ -4288,25 +4244,25 @@ pub fn http_request( /// status of this HTTP request pub fn http_status( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, - status: WasmPtr<__wasi_http_status_t, M>, -) -> __wasi_errno_t { + sock: WasiFd, + status: WasmPtr, +) -> Errno { debug!("wasi::http_status"); let env = ctx.data(); let memory = env.memory_view(&ctx); let ref_status = status.deref(&memory); - let http_status = wasi_try!(__sock_actor(&ctx, sock, 0, |socket| { + let http_status = wasi_try!(__sock_actor(&ctx, sock, Rights::empty(), |socket| { socket.http_status() })); // Write everything else and return the status to the caller - let status = __wasi_http_status_t { - ok: __WASI_BOOL_TRUE, + let status = HttpStatus { + ok: Bool::True, redirect: match http_status.redirected { - true => __WASI_BOOL_TRUE, - false => __WASI_BOOL_FALSE, + true => Bool::True, + false => Bool::False, }, size: wasi_try!(Ok(http_status.size)), status: http_status.status, @@ -4314,7 +4270,7 @@ pub fn http_status( wasi_try_mem!(ref_status.write(status)); - __WASI_ESUCCESS + Errno::Success } /// ### `port_bridge()` @@ -4331,44 +4287,44 @@ pub fn port_bridge( network_len: M::Offset, token: WasmPtr, token_len: M::Offset, - security: __wasi_streamsecurity_t, -) -> __wasi_errno_t { + security: Streamsecurity, +) -> Errno { debug!("wasi::port_bridge"); let env = ctx.data(); let memory = env.memory_view(&ctx); let network = unsafe { get_input_str!(&memory, network, network_len) }; let token = unsafe { get_input_str!(&memory, token, token_len) }; let security = match security { - __WASI_STREAM_SECURITY_UNENCRYPTED => StreamSecurity::Unencrypted, - __WASI_STREAM_SECURITY_ANY_ENCRYPTION => StreamSecurity::AnyEncyption, - __WASI_STREAM_SECURITY_CLASSIC_ENCRYPTION => StreamSecurity::ClassicEncryption, - __WASI_STREAM_SECURITY_DOUBLE_ENCRYPTION => StreamSecurity::DoubleEncryption, - _ => return __WASI_EINVAL, + Streamsecurity::Unencrypted => StreamSecurity::Unencrypted, + Streamsecurity::AnyEncryption => StreamSecurity::AnyEncyption, + Streamsecurity::ClassicEncryption => StreamSecurity::ClassicEncryption, + Streamsecurity::DoubleEncryption => StreamSecurity::DoubleEncryption, + _ => return Errno::Inval, }; wasi_try!(env .net() .bridge(network.as_str(), token.as_str(), security) .map_err(net_error_into_wasi_err)); - __WASI_ESUCCESS + Errno::Success } /// ### `port_unbridge()` /// Disconnects from a remote network -pub fn port_unbridge(ctx: FunctionEnvMut<'_, WasiEnv>) -> __wasi_errno_t { +pub fn port_unbridge(ctx: FunctionEnvMut<'_, WasiEnv>) -> Errno { debug!("wasi::port_unbridge"); let env = ctx.data(); wasi_try!(env.net().unbridge().map_err(net_error_into_wasi_err)); - __WASI_ESUCCESS + Errno::Success } /// ### `port_dhcp_acquire()` /// Acquires a set of IP addresses using DHCP -pub fn port_dhcp_acquire(ctx: FunctionEnvMut<'_, WasiEnv>) -> __wasi_errno_t { +pub fn port_dhcp_acquire(ctx: FunctionEnvMut<'_, WasiEnv>) -> Errno { debug!("wasi::port_dhcp_acquire"); let env = ctx.data(); wasi_try!(env.net().dhcp_acquire().map_err(net_error_into_wasi_err)); - __WASI_ESUCCESS + Errno::Success } /// ### `port_addr_add()` @@ -4380,7 +4336,7 @@ pub fn port_dhcp_acquire(ctx: FunctionEnvMut<'_, WasiEnv>) -> __wasi_errno_t { pub fn port_addr_add( ctx: FunctionEnvMut<'_, WasiEnv>, ip: WasmPtr<__wasi_cidr_t, M>, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::port_addr_add"); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -4389,7 +4345,7 @@ pub fn port_addr_add( .net() .ip_add(cidr.ip, cidr.prefix) .map_err(net_error_into_wasi_err)); - __WASI_ESUCCESS + Errno::Success } /// ### `port_addr_remove()` @@ -4401,22 +4357,22 @@ pub fn port_addr_add( pub fn port_addr_remove( ctx: FunctionEnvMut<'_, WasiEnv>, ip: WasmPtr<__wasi_addr_t, M>, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::port_addr_remove"); let env = ctx.data(); let memory = env.memory_view(&ctx); let ip = wasi_try!(super::state::read_ip(&memory, ip)); wasi_try!(env.net().ip_remove(ip).map_err(net_error_into_wasi_err)); - __WASI_ESUCCESS + Errno::Success } /// ### `port_addr_clear()` /// Clears all the addresses on the local port -pub fn port_addr_clear(ctx: FunctionEnvMut<'_, WasiEnv>) -> __wasi_errno_t { +pub fn port_addr_clear(ctx: FunctionEnvMut<'_, WasiEnv>) -> Errno { debug!("wasi::port_addr_clear"); let env = ctx.data(); wasi_try!(env.net().ip_clear().map_err(net_error_into_wasi_err)); - __WASI_ESUCCESS + Errno::Success } /// ### `port_mac()` @@ -4424,14 +4380,14 @@ pub fn port_addr_clear(ctx: FunctionEnvMut<'_, WasiEnv>) -> __wasi_errno_t { pub fn port_mac( ctx: FunctionEnvMut<'_, WasiEnv>, ret_mac: WasmPtr<__wasi_hardwareaddress_t, M>, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::port_mac"); let env = ctx.data(); let memory = env.memory_view(&ctx); let mac = wasi_try!(env.net().mac().map_err(net_error_into_wasi_err)); let mac = __wasi_hardwareaddress_t { octs: mac }; wasi_try_mem!(ret_mac.write(&memory, mac)); - __WASI_ESUCCESS + Errno::Success } /// ### `port_ip_list()` @@ -4451,21 +4407,21 @@ pub fn port_addr_list( ctx: FunctionEnvMut<'_, WasiEnv>, addrs: WasmPtr<__wasi_cidr_t, M>, naddrs: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::port_addr_list"); let env = ctx.data(); let memory = env.memory_view(&ctx); let max_addrs = wasi_try_mem!(naddrs.read(&memory)); - let max_addrs: u64 = wasi_try!(max_addrs.try_into().map_err(|_| __WASI_EOVERFLOW)); + let max_addrs: u64 = wasi_try!(max_addrs.try_into().map_err(|_| Errno::Overflow)); let ref_addrs = wasi_try_mem!(addrs.slice(&memory, wasi_try!(to_offset::(max_addrs as usize)))); let addrs = wasi_try!(env.net().ip_list().map_err(net_error_into_wasi_err)); - let addrs_len: M::Offset = wasi_try!(addrs.len().try_into().map_err(|_| __WASI_EOVERFLOW)); + let addrs_len: M::Offset = wasi_try!(addrs.len().try_into().map_err(|_| Errno::Overflow)); wasi_try_mem!(naddrs.write(&memory, addrs_len)); if addrs.len() as u64 > max_addrs { - return __WASI_EOVERFLOW; + return Errno::Overflow; } for n in 0..addrs.len() { @@ -4473,7 +4429,7 @@ pub fn port_addr_list( super::state::write_cidr(&memory, nip.as_ptr::(), *addrs.get(n).unwrap()); } - __WASI_ESUCCESS + Errno::Success } /// ### `port_gateway_set()` @@ -4485,14 +4441,14 @@ pub fn port_addr_list( pub fn port_gateway_set( ctx: FunctionEnvMut<'_, WasiEnv>, ip: WasmPtr<__wasi_addr_t, M>, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::port_gateway_set"); let env = ctx.data(); let memory = env.memory_view(&ctx); let ip = wasi_try!(super::state::read_ip(&memory, ip)); wasi_try!(env.net().gateway_set(ip).map_err(net_error_into_wasi_err)); - __WASI_ESUCCESS + Errno::Success } /// ### `port_route_add()` @@ -4501,9 +4457,9 @@ pub fn port_route_add( ctx: FunctionEnvMut<'_, WasiEnv>, cidr: WasmPtr<__wasi_cidr_t, M>, via_router: WasmPtr<__wasi_addr_t, M>, - preferred_until: WasmPtr<__wasi_option_timestamp_t, M>, - expires_at: WasmPtr<__wasi_option_timestamp_t, M>, -) -> __wasi_errno_t { + preferred_until: WasmPtr, + expires_at: WasmPtr, +) -> Errno { debug!("wasi::port_route_add"); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -4511,22 +4467,22 @@ pub fn port_route_add( let via_router = wasi_try!(super::state::read_ip(&memory, via_router)); let preferred_until = wasi_try_mem!(preferred_until.read(&memory)); let preferred_until = match preferred_until.tag { - __WASI_OPTION_NONE => None, - __WASI_OPTION_SOME => Some(Duration::from_nanos(preferred_until.u)), - _ => return __WASI_EINVAL, + OptionTag::None => None, + OptionTag::Some => Some(Duration::from_nanos(preferred_until.u)), + _ => return Errno::Inval, }; let expires_at = wasi_try_mem!(expires_at.read(&memory)); let expires_at = match expires_at.tag { - __WASI_OPTION_NONE => None, - __WASI_OPTION_SOME => Some(Duration::from_nanos(expires_at.u)), - _ => return __WASI_EINVAL, + OptionTag::None => None, + OptionTag::Some => Some(Duration::from_nanos(expires_at.u)), + _ => return Errno::Inval, }; wasi_try!(env .net() .route_add(cidr, via_router, preferred_until, expires_at) .map_err(net_error_into_wasi_err)); - __WASI_ESUCCESS + Errno::Success } /// ### `port_route_remove()` @@ -4534,22 +4490,22 @@ pub fn port_route_add( pub fn port_route_remove( ctx: FunctionEnvMut<'_, WasiEnv>, ip: WasmPtr<__wasi_addr_t, M>, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::port_route_remove"); let env = ctx.data(); let memory = env.memory_view(&ctx); let ip = wasi_try!(super::state::read_ip(&memory, ip)); wasi_try!(env.net().route_remove(ip).map_err(net_error_into_wasi_err)); - __WASI_ESUCCESS + Errno::Success } /// ### `port_route_clear()` /// Clears all the routes in the local port -pub fn port_route_clear(ctx: FunctionEnvMut<'_, WasiEnv>) -> __wasi_errno_t { +pub fn port_route_clear(ctx: FunctionEnvMut<'_, WasiEnv>) -> Errno { debug!("wasi::port_route_clear"); let env = ctx.data(); wasi_try!(env.net().route_clear().map_err(net_error_into_wasi_err)); - __WASI_ESUCCESS + Errno::Success } /// ### `port_route_list()` @@ -4563,24 +4519,24 @@ pub fn port_route_clear(ctx: FunctionEnvMut<'_, WasiEnv>) -> __wasi_errno_t { /// * `routes` - The buffer where routes will be stored pub fn port_route_list( ctx: FunctionEnvMut<'_, WasiEnv>, - routes: WasmPtr<__wasi_route_t, M>, + routes: WasmPtr, nroutes: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::port_route_list"); let env = ctx.data(); let memory = env.memory_view(&ctx); let nroutes = nroutes.deref(&memory); let max_routes: usize = wasi_try!(wasi_try_mem!(nroutes.read()) .try_into() - .map_err(|_| __WASI_EINVAL)); + .map_err(|_| Errno::Inval)); let ref_routes = wasi_try_mem!(routes.slice(&memory, wasi_try!(to_offset::(max_routes)))); let routes = wasi_try!(env.net().route_list().map_err(net_error_into_wasi_err)); - let routes_len: M::Offset = wasi_try!(routes.len().try_into().map_err(|_| __WASI_EINVAL)); + let routes_len: M::Offset = wasi_try!(routes.len().try_into().map_err(|_| Errno::Inval)); wasi_try_mem!(nroutes.write(routes_len)); if routes.len() > max_routes { - return __WASI_EOVERFLOW; + return Errno::Overflow; } for n in 0..routes.len() { @@ -4592,7 +4548,7 @@ pub fn port_route_list( ); } - __WASI_ESUCCESS + Errno::Success } /// ### `sock_shutdown()` @@ -4602,11 +4558,7 @@ pub fn port_route_list( /// ## Parameters /// /// * `how` - Which channels on the socket to shut down. -pub fn sock_shutdown( - ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, - how: __wasi_sdflags_t, -) -> __wasi_errno_t { +pub fn sock_shutdown(ctx: FunctionEnvMut<'_, WasiEnv>, sock: WasiFd, how: SdFlags) -> Errno { debug!("wasi::sock_shutdown"); let both = __WASI_SHUT_RD | __WASI_SHUT_WR; @@ -4614,43 +4566,45 @@ pub fn sock_shutdown( __WASI_SHUT_RD => std::net::Shutdown::Read, __WASI_SHUT_WR => std::net::Shutdown::Write, a if a == both => std::net::Shutdown::Both, - _ => return __WASI_EINVAL, + _ => return Errno::Inval, }; wasi_try!(__sock_actor_mut( &ctx, sock, - __WASI_RIGHT_SOCK_SHUTDOWN, + Rights::SOCK_SHUTDOWN, |socket| { socket.shutdown(how) } )); - __WASI_ESUCCESS + Errno::Success } /// ### `sock_status()` /// Returns the current status of a socket pub fn sock_status( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, - ret_status: WasmPtr<__wasi_sockstatus_t, M>, -) -> __wasi_errno_t { + sock: WasiFd, + ret_status: WasmPtr, +) -> Errno { debug!("wasi::sock_status"); - let status = wasi_try!(__sock_actor(&ctx, sock, 0, |socket| { socket.status() })); + let status = wasi_try!(__sock_actor(&ctx, sock, Rights::empty(), |socket| { + socket.status() + })); use super::state::WasiSocketStatus; let status = match status { - WasiSocketStatus::Opening => __WASI_SOCK_STATUS_OPENING, - WasiSocketStatus::Opened => __WASI_SOCK_STATUS_OPENED, - WasiSocketStatus::Closed => __WASI_SOCK_STATUS_CLOSED, - WasiSocketStatus::Failed => __WASI_SOCK_STATUS_FAILED, + WasiSocketStatus::Opening => Sockstatus::Opening, + WasiSocketStatus::Opened => Sockstatus::Opened, + WasiSocketStatus::Closed => Sockstatus::Closed, + WasiSocketStatus::Failed => Sockstatus::Failed, }; let env = ctx.data(); let memory = env.memory_view(&ctx); wasi_try_mem!(ret_status.write(&memory, status)); - __WASI_ESUCCESS + Errno::Success } /// ### `sock_addr_local()` @@ -4666,12 +4620,12 @@ pub fn sock_status( /// * `fd` - Socket that the address is bound to pub fn sock_addr_local( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, + sock: WasiFd, ret_addr: WasmPtr<__wasi_addr_port_t, M>, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::sock_addr_local"); - let addr = wasi_try!(__sock_actor(&ctx, sock, 0, |socket| { + let addr = wasi_try!(__sock_actor(&ctx, sock, Rights::empty(), |socket| { socket.addr_local() })); let memory = ctx.data().memory_view(&ctx); @@ -4681,7 +4635,7 @@ pub fn sock_addr_local( addr.ip(), addr.port() )); - __WASI_ESUCCESS + Errno::Success } /// ### `sock_addr_peer()` @@ -4697,13 +4651,15 @@ pub fn sock_addr_local( /// * `fd` - Socket that the address is bound to pub fn sock_addr_peer( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, + sock: WasiFd, ro_addr: WasmPtr<__wasi_addr_port_t, M>, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::sock_addr_peer"); let env = ctx.data(); - let addr = wasi_try!(__sock_actor(&ctx, sock, 0, |socket| { socket.addr_peer() })); + let addr = wasi_try!(__sock_actor(&ctx, sock, Rights::empty(), |socket| { + socket.addr_peer() + })); let memory = env.memory_view(&ctx); wasi_try!(super::state::write_ip_port( &memory, @@ -4711,7 +4667,7 @@ pub fn sock_addr_peer( addr.ip(), addr.port() )); - __WASI_ESUCCESS + Errno::Success } /// ### `sock_open()` @@ -4735,18 +4691,18 @@ pub fn sock_addr_peer( /// The file descriptor of the socket that has been opened. pub fn sock_open( ctx: FunctionEnvMut<'_, WasiEnv>, - af: __wasi_addressfamily_t, - ty: __wasi_socktype_t, - pt: __wasi_sockproto_t, - ro_sock: WasmPtr<__wasi_fd_t, M>, -) -> __wasi_errno_t { + af: Addressfamily, + ty: Socktype, + pt: SockProto, + ro_sock: WasmPtr, +) -> Errno { debug!("wasi::sock_open"); let env = ctx.data(); let (memory, state, mut inodes) = env.get_memory_and_wasi_state_and_inodes_mut(&ctx, 0); let kind = match ty { - __WASI_SOCK_TYPE_STREAM | __WASI_SOCK_TYPE_DGRAM => Kind::Socket { + Socktype::Stream | Socktype::Dgram => Kind::Socket { socket: InodeSocket::new(InodeSocketKind::PreSocket { family: af, ty, @@ -4763,7 +4719,7 @@ pub fn sock_open( accept_timeout: None, }), }, - _ => return __WASI_ENOTSUP, + _ => return Errno::Notsup, }; let inode = state.fs.create_inode_with_default_stat( @@ -4772,12 +4728,14 @@ pub fn sock_open( false, "socket".to_string(), ); - let rights = super::state::all_socket_rights(); - let fd = wasi_try!(state.fs.create_fd(rights, rights, 0, 0, inode)); + let rights = Rights::all_socket(); + let fd = wasi_try!(state + .fs + .create_fd(rights, rights, Fdflags::empty(), 0, inode)); wasi_try_mem!(ro_sock.write(&memory, fd)); - __WASI_ESUCCESS + Errno::Success } /// ### `sock_set_opt_flag()` @@ -4791,23 +4749,23 @@ pub fn sock_open( /// * `flag` - Value to set the option to pub fn sock_set_opt_flag( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, - opt: __wasi_sockoption_t, - flag: __wasi_bool_t, -) -> __wasi_errno_t { + sock: WasiFd, + opt: Sockoption, + flag: Bool, +) -> Errno { debug!("wasi::sock_set_opt_flag(ty={})", opt); let flag = match flag { - __WASI_BOOL_FALSE => false, - __WASI_BOOL_TRUE => true, - _ => return __WASI_EINVAL, + Bool::False => false, + Bool::True => true, + _ => return Errno::Inval, }; let option: super::state::WasiSocketOption = opt.into(); - wasi_try!(__sock_actor_mut(&ctx, sock, 0, |socket| { + wasi_try!(__sock_actor_mut(&ctx, sock, Rights::empty(), |socket| { socket.set_opt_flag(option, flag) })); - __WASI_ESUCCESS + Errno::Success } /// ### `sock_get_opt_flag()` @@ -4820,26 +4778,26 @@ pub fn sock_set_opt_flag( /// * `sockopt` - Socket option to be retrieved pub fn sock_get_opt_flag( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, - opt: __wasi_sockoption_t, - ret_flag: WasmPtr<__wasi_bool_t, M>, -) -> __wasi_errno_t { + sock: WasiFd, + opt: Sockoption, + ret_flag: WasmPtr, +) -> Errno { debug!("wasi::sock_get_opt_flag(ty={})", opt); let env = ctx.data(); let memory = env.memory_view(&ctx); let option: super::state::WasiSocketOption = opt.into(); - let flag = wasi_try!(__sock_actor(&ctx, sock, 0, |socket| { + let flag = wasi_try!(__sock_actor(&ctx, sock, Rights::empty(), |socket| { socket.get_opt_flag(option) })); let flag = match flag { - false => __WASI_BOOL_FALSE, - true => __WASI_BOOL_TRUE, + false => Bool::False, + true => Bool::True, }; wasi_try_mem!(ret_flag.write(&memory, flag)); - __WASI_ESUCCESS + Errno::Success } /// ### `sock_set_opt_time()` @@ -4852,35 +4810,35 @@ pub fn sock_get_opt_flag( /// * `time` - Value to set the time to pub fn sock_set_opt_time( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, - opt: __wasi_sockoption_t, - time: WasmPtr<__wasi_option_timestamp_t, M>, -) -> __wasi_errno_t { + sock: WasiFd, + opt: Sockoption, + time: WasmPtr, +) -> Errno { debug!("wasi::sock_set_opt_time(ty={})", opt); let env = ctx.data(); let memory = env.memory_view(&ctx); let time = wasi_try_mem!(time.read(&memory)); let time = match time.tag { - __WASI_OPTION_NONE => None, - __WASI_OPTION_SOME => Some(Duration::from_nanos(time.u)), - _ => return __WASI_EINVAL, + OptionTag::None => None, + OptionTag::Some => Some(Duration::from_nanos(time.u)), + _ => return Errno::Inval, }; let ty = match opt { - __WASI_SOCK_OPTION_RECV_TIMEOUT => wasmer_vnet::TimeType::ReadTimeout, - __WASI_SOCK_OPTION_SEND_TIMEOUT => wasmer_vnet::TimeType::WriteTimeout, - __WASI_SOCK_OPTION_CONNECT_TIMEOUT => wasmer_vnet::TimeType::ConnectTimeout, - __WASI_SOCK_OPTION_ACCEPT_TIMEOUT => wasmer_vnet::TimeType::AcceptTimeout, - __WASI_SOCK_OPTION_LINGER => wasmer_vnet::TimeType::Linger, - _ => return __WASI_EINVAL, + Sockoption::RecvTimeout => wasmer_vnet::TimeType::ReadTimeout, + Sockoption::SendTimeout => wasmer_vnet::TimeType::WriteTimeout, + Sockoption::ConnectTimeout => wasmer_vnet::TimeType::ConnectTimeout, + Sockoption::AcceptTimeout => wasmer_vnet::TimeType::AcceptTimeout, + Sockoption::Linger => wasmer_vnet::TimeType::Linger, + _ => return Errno::Inval, }; let option: super::state::WasiSocketOption = opt.into(); - wasi_try!(__sock_actor_mut(&ctx, sock, 0, |socket| { + wasi_try!(__sock_actor_mut(&ctx, sock, Rights::empty(), |socket| { socket.set_opt_time(ty, time) })); - __WASI_ESUCCESS + Errno::Success } /// ### `sock_get_opt_time()` @@ -4892,40 +4850,40 @@ pub fn sock_set_opt_time( /// * `sockopt` - Socket option to be retrieved pub fn sock_get_opt_time( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, - opt: __wasi_sockoption_t, - ret_time: WasmPtr<__wasi_option_timestamp_t, M>, -) -> __wasi_errno_t { + sock: WasiFd, + opt: Sockoption, + ret_time: WasmPtr, +) -> Errno { debug!("wasi::sock_get_opt_time(ty={})", opt); let env = ctx.data(); let memory = env.memory_view(&ctx); let ty = match opt { - __WASI_SOCK_OPTION_RECV_TIMEOUT => wasmer_vnet::TimeType::ReadTimeout, - __WASI_SOCK_OPTION_SEND_TIMEOUT => wasmer_vnet::TimeType::WriteTimeout, - __WASI_SOCK_OPTION_CONNECT_TIMEOUT => wasmer_vnet::TimeType::ConnectTimeout, - __WASI_SOCK_OPTION_ACCEPT_TIMEOUT => wasmer_vnet::TimeType::AcceptTimeout, - __WASI_SOCK_OPTION_LINGER => wasmer_vnet::TimeType::Linger, - _ => return __WASI_EINVAL, + Sockoption::RecvTimeout => wasmer_vnet::TimeType::ReadTimeout, + Sockoption::SendTimeout => wasmer_vnet::TimeType::WriteTimeout, + Sockoption::ConnectTimeout => wasmer_vnet::TimeType::ConnectTimeout, + Sockoption::AcceptTimeout => wasmer_vnet::TimeType::AcceptTimeout, + Sockoption::Linger => wasmer_vnet::TimeType::Linger, + _ => return Errno::Inval, }; - let time = wasi_try!(__sock_actor(&ctx, sock, 0, |socket| { + let time = wasi_try!(__sock_actor(&ctx, sock, Rights::empty(), |socket| { socket.opt_time(ty) })); let time = match time { - None => __wasi_option_timestamp_t { - tag: __WASI_OPTION_NONE, + None => OptionTimestamp { + tag: OptionTag::None, u: 0, }, - Some(timeout) => __wasi_option_timestamp_t { - tag: __WASI_OPTION_SOME, - u: timeout.as_nanos() as __wasi_timestamp_t, + Some(timeout) => OptionTimestamp { + tag: OptionTag::Some, + u: timeout.as_nanos() as Timestamp, }, }; wasi_try_mem!(ret_time.write(&memory, time)); - __WASI_ESUCCESS + Errno::Success } /// ### `sock_set_opt_size() @@ -4939,32 +4897,32 @@ pub fn sock_get_opt_time( /// * `size` - Buffer size pub fn sock_set_opt_size( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, - opt: __wasi_sockoption_t, - size: __wasi_filesize_t, -) -> __wasi_errno_t { + sock: WasiFd, + opt: Sockoption, + size: Filesize, +) -> Errno { debug!("wasi::sock_set_opt_size(ty={})", opt); let ty = match opt { - __WASI_SOCK_OPTION_RECV_TIMEOUT => wasmer_vnet::TimeType::ReadTimeout, - __WASI_SOCK_OPTION_SEND_TIMEOUT => wasmer_vnet::TimeType::WriteTimeout, - __WASI_SOCK_OPTION_CONNECT_TIMEOUT => wasmer_vnet::TimeType::ConnectTimeout, - __WASI_SOCK_OPTION_ACCEPT_TIMEOUT => wasmer_vnet::TimeType::AcceptTimeout, - __WASI_SOCK_OPTION_LINGER => wasmer_vnet::TimeType::Linger, - _ => return __WASI_EINVAL, + Sockoption::RecvTimeout => wasmer_vnet::TimeType::ReadTimeout, + Sockoption::SendTimeout => wasmer_vnet::TimeType::WriteTimeout, + Sockoption::ConnectTimeout => wasmer_vnet::TimeType::ConnectTimeout, + Sockoption::AcceptTimeout => wasmer_vnet::TimeType::AcceptTimeout, + Sockoption::Linger => wasmer_vnet::TimeType::Linger, + _ => return Errno::Inval, }; let option: super::state::WasiSocketOption = opt.into(); - wasi_try!(__sock_actor_mut(&ctx, sock, 0, |socket| { + wasi_try!(__sock_actor_mut(&ctx, sock, Rights::empty(), |socket| { match opt { - __WASI_SOCK_OPTION_RECV_BUF_SIZE => socket.set_recv_buf_size(size as usize), - __WASI_SOCK_OPTION_SEND_BUF_SIZE => socket.set_send_buf_size(size as usize), - __WASI_SOCK_OPTION_TTL => socket.set_ttl(size as u32), - __WASI_SOCK_OPTION_MULTICAST_TTL_V4 => socket.set_multicast_ttl_v4(size as u32), - _ => Err(__WASI_EINVAL), + Sockoption::RecvBufSize => socket.set_recv_buf_size(size as usize), + Sockoption::SendBufSize => socket.set_send_buf_size(size as usize), + Sockoption::Ttl => socket.set_ttl(size as u32), + Sockoption::MulticastTtlV4 => socket.set_multicast_ttl_v4(size as u32), + _ => Err(Errno::Inval), } })); - __WASI_ESUCCESS + Errno::Success } /// ### `sock_get_opt_size()` @@ -4977,32 +4935,26 @@ pub fn sock_set_opt_size( /// * `sockopt` - Socket option to be retrieved pub fn sock_get_opt_size( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, - opt: __wasi_sockoption_t, - ret_size: WasmPtr<__wasi_filesize_t, M>, -) -> __wasi_errno_t { + sock: WasiFd, + opt: Sockoption, + ret_size: WasmPtr, +) -> Errno { debug!("wasi::sock_get_opt_size(ty={})", opt); let env = ctx.data(); let memory = env.memory_view(&ctx); - let size = wasi_try!(__sock_actor(&ctx, sock, 0, |socket| { + let size = wasi_try!(__sock_actor(&ctx, sock, Rights::empty(), |socket| { match opt { - __WASI_SOCK_OPTION_RECV_BUF_SIZE => { - socket.recv_buf_size().map(|a| a as __wasi_filesize_t) - } - __WASI_SOCK_OPTION_SEND_BUF_SIZE => { - socket.send_buf_size().map(|a| a as __wasi_filesize_t) - } - __WASI_SOCK_OPTION_TTL => socket.ttl().map(|a| a as __wasi_filesize_t), - __WASI_SOCK_OPTION_MULTICAST_TTL_V4 => { - socket.multicast_ttl_v4().map(|a| a as __wasi_filesize_t) - } - _ => Err(__WASI_EINVAL), + Sockoption::RecvBufSize => socket.recv_buf_size().map(|a| a as Filesize), + Sockoption::SendBufSize => socket.send_buf_size().map(|a| a as Filesize), + Sockoption::Ttl => socket.ttl().map(|a| a as Filesize), + Sockoption::MulticastTtlV4 => socket.multicast_ttl_v4().map(|a| a as Filesize), + _ => Err(Errno::Inval), } })); wasi_try_mem!(ret_size.write(&memory, size)); - __WASI_ESUCCESS + Errno::Success } /// ### `sock_join_multicast_v4()` @@ -5015,20 +4967,20 @@ pub fn sock_get_opt_size( /// * `interface` - Interface that will join pub fn sock_join_multicast_v4( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, + sock: WasiFd, multiaddr: WasmPtr<__wasi_addr_ip4_t, M>, iface: WasmPtr<__wasi_addr_ip4_t, M>, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::sock_join_multicast_v4"); let env = ctx.data(); let memory = env.memory_view(&ctx); let multiaddr = wasi_try!(super::state::read_ip_v4(&memory, multiaddr)); let iface = wasi_try!(super::state::read_ip_v4(&memory, iface)); - wasi_try!(__sock_actor_mut(&ctx, sock, 0, |socket| { + wasi_try!(__sock_actor_mut(&ctx, sock, Rights::empty(), |socket| { socket.join_multicast_v4(multiaddr, iface) })); - __WASI_ESUCCESS + Errno::Success } /// ### `sock_leave_multicast_v4()` @@ -5041,20 +4993,20 @@ pub fn sock_join_multicast_v4( /// * `interface` - Interface that will left pub fn sock_leave_multicast_v4( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, + sock: WasiFd, multiaddr: WasmPtr<__wasi_addr_ip4_t, M>, iface: WasmPtr<__wasi_addr_ip4_t, M>, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::sock_leave_multicast_v4"); let env = ctx.data(); let memory = env.memory_view(&ctx); let multiaddr = wasi_try!(super::state::read_ip_v4(&memory, multiaddr)); let iface = wasi_try!(super::state::read_ip_v4(&memory, iface)); - wasi_try!(__sock_actor_mut(&ctx, sock, 0, |socket| { + wasi_try!(__sock_actor_mut(&ctx, sock, Rights::empty(), |socket| { socket.leave_multicast_v4(multiaddr, iface) })); - __WASI_ESUCCESS + Errno::Success } /// ### `sock_join_multicast_v6()` @@ -5067,19 +5019,19 @@ pub fn sock_leave_multicast_v4( /// * `interface` - Interface that will join pub fn sock_join_multicast_v6( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, + sock: WasiFd, multiaddr: WasmPtr<__wasi_addr_ip6_t, M>, iface: u32, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::sock_join_multicast_v6"); let env = ctx.data(); let memory = env.memory_view(&ctx); let multiaddr = wasi_try!(super::state::read_ip_v6(&memory, multiaddr)); - wasi_try!(__sock_actor_mut(&ctx, sock, 0, |socket| { + wasi_try!(__sock_actor_mut(&ctx, sock, Rights::empty(), |socket| { socket.join_multicast_v6(multiaddr, iface) })); - __WASI_ESUCCESS + Errno::Success } /// ### `sock_leave_multicast_v6()` @@ -5092,19 +5044,19 @@ pub fn sock_join_multicast_v6( /// * `interface` - Interface that will left pub fn sock_leave_multicast_v6( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, + sock: WasiFd, multiaddr: WasmPtr<__wasi_addr_ip6_t, M>, iface: u32, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::sock_leave_multicast_v6"); let env = ctx.data(); let memory = env.memory_view(&ctx); let multiaddr = wasi_try!(super::state::read_ip_v6(&memory, multiaddr)); - wasi_try!(__sock_actor_mut(&ctx, sock, 0, |socket| { + wasi_try!(__sock_actor_mut(&ctx, sock, Rights::empty(), |socket| { socket.leave_multicast_v6(multiaddr, iface) })); - __WASI_ESUCCESS + Errno::Success } /// ### `sock_bind()` @@ -5117,22 +5069,19 @@ pub fn sock_leave_multicast_v6( /// * `addr` - Address to bind the socket to pub fn sock_bind( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, + sock: WasiFd, addr: WasmPtr<__wasi_addr_port_t, M>, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::sock_bind"); let env = ctx.data(); let memory = env.memory_view(&ctx); let addr = wasi_try!(super::state::read_ip_port(&memory, addr)); let addr = SocketAddr::new(addr.0, addr.1); - wasi_try!(__sock_upgrade( - &ctx, - sock, - __WASI_RIGHT_SOCK_BIND, - |socket| { socket.bind(env.net(), addr) } - )); - __WASI_ESUCCESS + wasi_try!(__sock_upgrade(&ctx, sock, Rights::SOCK_BIND, |socket| { + socket.bind(env.net(), addr) + })); + Errno::Success } /// ### `sock_listen()` @@ -5149,20 +5098,17 @@ pub fn sock_bind( /// * `backlog` - Maximum size of the queue for pending connections pub fn sock_listen( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, + sock: WasiFd, backlog: M::Offset, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::sock_listen"); let env = ctx.data(); - let backlog: usize = wasi_try!(backlog.try_into().map_err(|_| __WASI_EINVAL)); - wasi_try!(__sock_upgrade( - &ctx, - sock, - __WASI_RIGHT_SOCK_BIND, - |socket| { socket.listen(env.net(), backlog) } - )); - __WASI_ESUCCESS + let backlog: usize = wasi_try!(backlog.try_into().map_err(|_| Errno::Inval)); + wasi_try!(__sock_upgrade(&ctx, sock, Rights::SOCK_BIND, |socket| { + socket.listen(env.net(), backlog) + })); + Errno::Success } /// ### `sock_accept()` @@ -5179,11 +5125,11 @@ pub fn sock_listen( /// New socket connection pub fn sock_accept( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, - fd_flags: __wasi_fdflags_t, - ro_fd: WasmPtr<__wasi_fd_t, M>, + sock: WasiFd, + fd_flags: Fdflags, + ro_fd: WasmPtr, ro_addr: WasmPtr<__wasi_addr_port_t, M>, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { debug!("wasi::sock_accept"); let env = ctx.data(); @@ -5192,18 +5138,18 @@ pub fn sock_accept( let (_, state) = env.get_memory_and_wasi_state(&ctx, 0); loop { wasi_try_ok!( - match __sock_actor(&ctx, sock, __WASI_RIGHT_SOCK_ACCEPT, |socket| socket + match __sock_actor(&ctx, sock, Rights::SOCK_ACCEPT, |socket| socket .accept_timeout(fd_flags, Duration::from_millis(5))) { Ok(a) => { ret = a; break; } - Err(__WASI_ETIMEDOUT) => { + Err(Errno::Timedout) => { env.yield_now()?; continue; } - Err(__WASI_EAGAIN) => { + Err(Errno::Again) => { env.sleep(Duration::from_millis(5))?; continue; } @@ -5226,8 +5172,10 @@ pub fn sock_accept( "socket".to_string(), ); - let rights = super::state::all_socket_rights(); - let fd = wasi_try_ok!(state.fs.create_fd(rights, rights, 0, 0, inode)); + let rights = Rights::all_socket(); + let fd = wasi_try_ok!(state + .fs + .create_fd(rights, rights, Fdflags::empty(), 0, inode)); wasi_try_mem_ok!(ro_fd.write(&memory, fd)); wasi_try_ok!(super::state::write_ip_port( @@ -5237,7 +5185,7 @@ pub fn sock_accept( addr.port() )); - Ok(__WASI_ESUCCESS) + Ok(Errno::Success) } /// ### `sock_connect()` @@ -5254,22 +5202,19 @@ pub fn sock_accept( /// * `addr` - Address of the socket to connect to pub fn sock_connect( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, + sock: WasiFd, addr: WasmPtr<__wasi_addr_port_t, M>, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::sock_connect"); let env = ctx.data(); let memory = env.memory_view(&ctx); let addr = wasi_try!(super::state::read_ip_port(&memory, addr)); let addr = SocketAddr::new(addr.0, addr.1); - wasi_try!(__sock_upgrade( - &ctx, - sock, - __WASI_RIGHT_SOCK_CONNECT, - |socket| { socket.connect(env.net(), addr) } - )); - __WASI_ESUCCESS + wasi_try!(__sock_upgrade(&ctx, sock, Rights::SOCK_CONNECT, |socket| { + socket.connect(env.net(), addr) + })); + Errno::Success } /// ### `sock_recv()` @@ -5287,31 +5232,28 @@ pub fn sock_connect( /// Number of bytes stored in ri_data and message flags. pub fn sock_recv( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, + sock: WasiFd, ri_data: WasmPtr<__wasi_iovec_t, M>, ri_data_len: M::Offset, - _ri_flags: __wasi_riflags_t, + _ri_flags: RiFlags, ro_data_len: WasmPtr, - ro_flags: WasmPtr<__wasi_roflags_t, M>, -) -> Result<__wasi_errno_t, WasiError> { + ro_flags: WasmPtr, +) -> Result { debug!("wasi::sock_recv"); let env = ctx.data(); let memory = env.memory_view(&ctx); let iovs_arr = wasi_try_mem_ok!(ri_data.slice(&memory, ri_data_len)); - let bytes_read = wasi_try_ok!(__sock_actor_mut( - &ctx, - sock, - __WASI_RIGHT_SOCK_RECV, - |socket| { socket.recv(&memory, iovs_arr) } - )); - let bytes_read: M::Offset = wasi_try_ok!(bytes_read.try_into().map_err(|_| __WASI_EOVERFLOW)); + let bytes_read = wasi_try_ok!(__sock_actor_mut(&ctx, sock, Rights::SOCK_RECV, |socket| { + socket.recv(&memory, iovs_arr) + })); + let bytes_read: M::Offset = wasi_try_ok!(bytes_read.try_into().map_err(|_| Errno::Overflow)); wasi_try_mem_ok!(ro_flags.write(&memory, 0)); wasi_try_mem_ok!(ro_data_len.write(&memory, bytes_read)); - Ok(__WASI_ESUCCESS) + Ok(Errno::Success) } /// ### `sock_recv_from()` @@ -5329,14 +5271,14 @@ pub fn sock_recv( /// Number of bytes stored in ri_data and message flags. pub fn sock_recv_from( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, + sock: WasiFd, ri_data: WasmPtr<__wasi_iovec_t, M>, ri_data_len: M::Offset, - _ri_flags: __wasi_riflags_t, + _ri_flags: RiFlags, ro_data_len: WasmPtr, - ro_flags: WasmPtr<__wasi_roflags_t, M>, + ro_flags: WasmPtr, ro_addr: WasmPtr<__wasi_addr_port_t, M>, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { debug!("wasi::sock_recv_from"); let env = ctx.data(); @@ -5346,15 +5288,15 @@ pub fn sock_recv_from( let bytes_read = wasi_try_ok!(__sock_actor_mut( &ctx, sock, - __WASI_RIGHT_SOCK_RECV_FROM, + Rights::SOCK_RECV_FROM, |socket| { socket.recv_from(&memory, iovs_arr, ro_addr) } )); - let bytes_read: M::Offset = wasi_try_ok!(bytes_read.try_into().map_err(|_| __WASI_EOVERFLOW)); + let bytes_read: M::Offset = wasi_try_ok!(bytes_read.try_into().map_err(|_| Errno::Overflow)); wasi_try_mem_ok!(ro_flags.write(&memory, 0)); wasi_try_mem_ok!(ro_data_len.write(&memory, bytes_read)); - Ok(__WASI_ESUCCESS) + Ok(Errno::Success) } /// ### `sock_send()` @@ -5372,30 +5314,27 @@ pub fn sock_recv_from( /// Number of bytes transmitted. pub fn sock_send( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, + sock: WasiFd, si_data: WasmPtr<__wasi_ciovec_t, M>, si_data_len: M::Offset, - _si_flags: __wasi_siflags_t, + _si_flags: SiFlags, ret_data_len: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { debug!("wasi::sock_send"); let env = ctx.data(); let memory = env.memory_view(&ctx); let iovs_arr = wasi_try_mem_ok!(si_data.slice(&memory, si_data_len)); - let bytes_written = wasi_try_ok!(__sock_actor_mut( - &ctx, - sock, - __WASI_RIGHT_SOCK_SEND, - |socket| { socket.send(&memory, iovs_arr) } - )); + let bytes_written = wasi_try_ok!(__sock_actor_mut(&ctx, sock, Rights::SOCK_SEND, |socket| { + socket.send(&memory, iovs_arr) + })); let bytes_written: M::Offset = - wasi_try_ok!(bytes_written.try_into().map_err(|_| __WASI_EOVERFLOW)); + wasi_try_ok!(bytes_written.try_into().map_err(|_| Errno::Overflow)); wasi_try_mem_ok!(ret_data_len.write(&memory, bytes_written)); - Ok(__WASI_ESUCCESS) + Ok(Errno::Success) } /// ### `sock_send_to()` @@ -5414,13 +5353,13 @@ pub fn sock_send( /// Number of bytes transmitted. pub fn sock_send_to( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, + sock: WasiFd, si_data: WasmPtr<__wasi_ciovec_t, M>, si_data_len: M::Offset, - _si_flags: __wasi_siflags_t, + _si_flags: SiFlags, addr: WasmPtr<__wasi_addr_port_t, M>, ret_data_len: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { debug!("wasi::sock_send_to"); let env = ctx.data(); @@ -5430,15 +5369,15 @@ pub fn sock_send_to( let bytes_written = wasi_try_ok!(__sock_actor_mut( &ctx, sock, - __WASI_RIGHT_SOCK_SEND_TO, + Rights::SOCK_SEND_TO, |socket| { socket.send_to::(&memory, iovs_arr, addr) } )); let bytes_written: M::Offset = - wasi_try_ok!(bytes_written.try_into().map_err(|_| __WASI_EOVERFLOW)); + wasi_try_ok!(bytes_written.try_into().map_err(|_| Errno::Overflow)); wasi_try_mem_ok!(ret_data_len.write(&memory, bytes_written as M::Offset)); - Ok(__WASI_ESUCCESS) + Ok(Errno::Success) } /// ### `sock_send_file()` @@ -5455,12 +5394,12 @@ pub fn sock_send_to( /// Number of bytes transmitted. pub unsafe fn sock_send_file( mut ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, - in_fd: __wasi_fd_t, - offset: __wasi_filesize_t, - mut count: __wasi_filesize_t, - ret_sent: WasmPtr<__wasi_filesize_t, M>, -) -> Result<__wasi_errno_t, WasiError> { + sock: WasiFd, + in_fd: WasiFd, + offset: Filesize, + mut count: Filesize, + ret_sent: WasmPtr, +) -> Result { debug!("wasi::send_file"); let env = ctx.data(); let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0); @@ -5468,12 +5407,12 @@ pub unsafe fn sock_send_file( // Set the offset of the file { let mut fd_map = state.fs.fd_map.write().unwrap(); - let fd_entry = wasi_try_ok!(fd_map.get_mut(&in_fd).ok_or(__WASI_EBADF)); + let fd_entry = wasi_try_ok!(fd_map.get_mut(&in_fd).ok_or(Errno::Badf)); fd_entry.offset = offset as u64; } // Enter a loop that will process all the data - let mut total_written: __wasi_filesize_t = 0; + let mut total_written: Filesize = 0; while (count > 0) { let mut buf = [0; 4096]; let sub_count = count.min(4096); @@ -5491,14 +5430,14 @@ pub unsafe fn sock_send_file( if let Some(ref mut stdin) = guard.deref_mut() { wasi_try_ok!(stdin.read(&mut buf).map_err(map_io_err)) } else { - return Ok(__WASI_EBADF); + return Ok(Errno::Badf); } } - __WASI_STDOUT_FILENO | __WASI_STDERR_FILENO => return Ok(__WASI_EINVAL), + __WASI_STDOUT_FILENO | __WASI_STDERR_FILENO => return Ok(Errno::Inval), _ => { - if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_READ) { + if !fd_entry.rights.contains(Rights::FD_READ) { // TODO: figure out the error to return when lacking rights - return Ok(__WASI_EACCES); + return Ok(Errno::Access); } let offset = fd_entry.offset as usize; @@ -5519,7 +5458,7 @@ pub unsafe fn sock_send_file( ); wasi_try_ok!(handle.read(&mut buf).map_err(map_io_err)) } else { - return Ok(__WASI_EINVAL); + return Ok(Errno::Inval); } } Kind::Socket { socket } => { @@ -5529,10 +5468,10 @@ pub unsafe fn sock_send_file( wasi_try_ok!(pipe.read(&mut buf).map_err(map_io_err)) } Kind::Dir { .. } | Kind::Root { .. } => { - return Ok(__WASI_EISDIR); + return Ok(Errno::Isdir); } Kind::EventNotifications { .. } => { - return Ok(__WASI_EINVAL); + return Ok(Errno::Inval); } Kind::Symlink { .. } => unimplemented!("Symlinks in wasi::fd_read"), Kind::Buffer { buffer } => { @@ -5544,7 +5483,7 @@ pub unsafe fn sock_send_file( // reborrow let mut fd_map = state.fs.fd_map.write().unwrap(); - let fd_entry = wasi_try_ok!(fd_map.get_mut(&in_fd).ok_or(__WASI_EBADF)); + let fd_entry = wasi_try_ok!(fd_map.get_mut(&in_fd).ok_or(Errno::Badf)); fd_entry.offset += bytes_read as u64; bytes_read @@ -5552,21 +5491,17 @@ pub unsafe fn sock_send_file( }; // Write it down to the socket - let bytes_written = wasi_try_ok!(__sock_actor_mut( - &ctx, - sock, - __WASI_RIGHT_SOCK_SEND, - |socket| { - let buf = (buf[..]).to_vec(); + let bytes_written = + wasi_try_ok!(__sock_actor_mut(&ctx, sock, Rights::SOCK_SEND, |socket| { + let buf = (&buf[..]).to_vec(); socket.send_bytes::(Bytes::from(buf)) - } - )); + })); total_written += bytes_written as u64; } - wasi_try_mem_ok!(ret_sent.write(&memory, total_written as __wasi_filesize_t)); + wasi_try_mem_ok!(ret_sent.write(&memory, total_written as Filesize)); - Ok(__WASI_ESUCCESS) + Ok(Errno::Success) } /// ### `resolve()` @@ -5595,10 +5530,10 @@ pub fn resolve( addrs: WasmPtr<__wasi_addr_t, M>, naddrs: M::Offset, ret_naddrs: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { debug!("wasi::resolve"); - let naddrs: usize = wasi_try!(naddrs.try_into().map_err(|_| __WASI_EINVAL)); + let naddrs: usize = wasi_try!(naddrs.try_into().map_err(|_| Errno::Inval)); let env = ctx.data(); let memory = env.memory_view(&ctx); let host_str = unsafe { get_input_str!(&memory, host, host_len) }; @@ -5617,8 +5552,8 @@ pub fn resolve( idx += 1; } - let idx: M::Offset = wasi_try!(idx.try_into().map_err(|_| __WASI_EOVERFLOW)); + let idx: M::Offset = wasi_try!(idx.try_into().map_err(|_| Errno::Overflow)); wasi_try_mem!(ret_naddrs.write(&memory, idx)); - __WASI_ESUCCESS + Errno::Success } diff --git a/lib/wasi/src/syscalls/unix/mod.rs b/lib/wasi/src/syscalls/unix/mod.rs index 9e3a5e35d16..916b1de0265 100644 --- a/lib/wasi/src/syscalls/unix/mod.rs +++ b/lib/wasi/src/syscalls/unix/mod.rs @@ -5,17 +5,18 @@ use libc::{ }; use std::mem; use wasmer::WasmRef; +use wasmer_wasi_types::wasi::{Errno, Snapshot0Clockid, Timestamp}; pub fn platform_clock_res_get( - clock_id: __wasi_clockid_t, - resolution: WasmRef<__wasi_timestamp_t>, -) -> Result { + clock_id: Snapshot0Clockid, + resolution: WasmRef, +) -> Result { let unix_clock_id = match clock_id { - __WASI_CLOCK_MONOTONIC => CLOCK_MONOTONIC, - __WASI_CLOCK_PROCESS_CPUTIME_ID => CLOCK_PROCESS_CPUTIME_ID, - __WASI_CLOCK_REALTIME => CLOCK_REALTIME, - __WASI_CLOCK_THREAD_CPUTIME_ID => CLOCK_THREAD_CPUTIME_ID, - _ => return Err(__WASI_EINVAL), + Snapshot0Clockid::Monotonic => CLOCK_MONOTONIC, + Snapshot0Clockid::ProcessCputimeId => CLOCK_PROCESS_CPUTIME_ID, + Snapshot0Clockid::Realtime => CLOCK_REALTIME, + Snapshot0Clockid::ThreadCputimeId => CLOCK_THREAD_CPUTIME_ID, + _ => return Err(Errno::Inval), }; let (output, timespec_out) = unsafe { @@ -31,15 +32,15 @@ pub fn platform_clock_res_get( } pub fn platform_clock_time_get( - clock_id: __wasi_clockid_t, - precision: __wasi_timestamp_t, -) -> Result { + clock_id: Snapshot0Clockid, + precision: Timestamp, +) -> Result { let unix_clock_id = match clock_id { - __WASI_CLOCK_MONOTONIC => CLOCK_MONOTONIC, - __WASI_CLOCK_PROCESS_CPUTIME_ID => CLOCK_PROCESS_CPUTIME_ID, - __WASI_CLOCK_REALTIME => CLOCK_REALTIME, - __WASI_CLOCK_THREAD_CPUTIME_ID => CLOCK_THREAD_CPUTIME_ID, - _ => return Err(__WASI_EINVAL), + Snapshot0Clockid::Monotonic => CLOCK_MONOTONIC, + Snapshot0Clockid::ProcessCputimeId => CLOCK_PROCESS_CPUTIME_ID, + Snapshot0Clockid::Realtime => CLOCK_REALTIME, + Snapshot0Clockid::ThreadCputimeId => CLOCK_THREAD_CPUTIME_ID, + _ => return Err(Errno::Inval), }; let (output, timespec_out) = unsafe { diff --git a/lib/wasi/src/syscalls/wasi.rs b/lib/wasi/src/syscalls/wasi.rs index b2575f6e53c..f90e5955ba0 100644 --- a/lib/wasi/src/syscalls/wasi.rs +++ b/lib/wasi/src/syscalls/wasi.rs @@ -1,7 +1,10 @@ #![deny(dead_code)] use crate::{WasiEnv, WasiError, WasiState, WasiThread}; -use wasmer::{StoreMut, Memory, Memory32, MemorySize, WasmPtr, WasmSlice}; -use wasmer_wasi_types::*; +use wasmer::{Memory, Memory32, MemorySize, StoreMut, WasmPtr, WasmSlice}; +use wasmer_wasi_types::{ + wasi::{Errno, Event, Fd as WasiFd, Filesize, Fstflags, Fstflags, Timestamp, Whence, Clockid}, + types::*, +}; type MemoryType = Memory32; type MemoryOffset = u32; @@ -10,7 +13,7 @@ pub(crate) fn args_get( ctx: FunctionEnvMut, argv: WasmPtr, MemoryType>, argv_buf: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::args_get::(ctx, argv, argv_buf) } @@ -18,24 +21,24 @@ pub(crate) fn args_sizes_get( ctx: FunctionEnvMut, argc: WasmPtr, argv_buf_size: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::args_sizes_get::(ctx, argc, argv_buf_size) } pub(crate) fn clock_res_get( ctx: FunctionEnvMut, - clock_id: __wasi_clockid_t, - resolution: WasmPtr<__wasi_timestamp_t, MemoryType>, -) -> __wasi_errno_t { + clock_id: Clockid, + resolution: WasmPtr, +) -> Errno { super::clock_res_get::(ctx, clock_id, resolution) } pub(crate) fn clock_time_get( ctx: FunctionEnvMut, - clock_id: __wasi_clockid_t, - precision: __wasi_timestamp_t, - time: WasmPtr<__wasi_timestamp_t, MemoryType>, -) -> __wasi_errno_t { + clock_id: Clockid, + precision: Timestamp, + time: WasmPtr, +) -> Errno { super::clock_time_get::(ctx, clock_id, precision, time) } @@ -43,7 +46,7 @@ pub(crate) fn environ_get( ctx: FunctionEnvMut, environ: WasmPtr, MemoryType>, environ_buf: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::environ_get::(ctx, environ, environ_buf) } @@ -51,218 +54,214 @@ pub(crate) fn environ_sizes_get( ctx: FunctionEnvMut, environ_count: WasmPtr, environ_buf_size: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::environ_sizes_get::(ctx, environ_count, environ_buf_size) } pub(crate) fn fd_advise( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - offset: __wasi_filesize_t, - len: __wasi_filesize_t, + fd: WasiFd, + offset: Filesize, + len: Filesize, advice: __wasi_advice_t, -) -> __wasi_errno_t { +) -> Errno { super::fd_advise(ctx, fd, offset, len, advice) } pub(crate) fn fd_allocate( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - offset: __wasi_filesize_t, - len: __wasi_filesize_t, -) -> __wasi_errno_t { + fd: WasiFd, + offset: Filesize, + len: Filesize, +) -> Errno { super::fd_allocate(ctx, fd, offset, len) } -pub(crate) fn fd_close(ctx: FunctionEnvMut, fd: __wasi_fd_t) -> __wasi_errno_t { +pub(crate) fn fd_close(ctx: FunctionEnvMut, fd: WasiFd) -> Errno { super::fd_close(ctx, fd) } -pub(crate) fn fd_datasync(ctx: FunctionEnvMut, fd: __wasi_fd_t) -> __wasi_errno_t { +pub(crate) fn fd_datasync(ctx: FunctionEnvMut, fd: WasiFd) -> Errno { super::fd_datasync(ctx, fd) } pub(crate) fn fd_fdstat_get( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - buf_ptr: WasmPtr<__wasi_fdstat_t, MemoryType>, -) -> __wasi_errno_t { + fd: WasiFd, + buf_ptr: WasmPtr, +) -> Errno { super::fd_fdstat_get::(ctx, fd, buf_ptr) } pub(crate) fn fd_fdstat_set_flags( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - flags: __wasi_fdflags_t, -) -> __wasi_errno_t { + fd: WasiFd, + flags: WasiFdflags, +) -> Errno { super::fd_fdstat_set_flags(ctx, fd, flags) } pub(crate) fn fd_fdstat_set_rights( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: WasiFd, fs_rights_base: __wasi_rights_t, fs_rights_inheriting: __wasi_rights_t, -) -> __wasi_errno_t { +) -> Errno { super::fd_fdstat_set_rights(ctx, fd, fs_rights_base, fs_rights_inheriting) } pub(crate) fn fd_filestat_get( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - buf: WasmPtr<__wasi_filestat_t, MemoryType>, -) -> __wasi_errno_t { + fd: WasiFd, + buf: WasmPtr, +) -> Errno { super::fd_filestat_get::(ctx, fd, buf) } pub(crate) fn fd_filestat_set_size( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - st_size: __wasi_filesize_t, -) -> __wasi_errno_t { + fd: WasiFd, + st_size: Filesize, +) -> Errno { super::fd_filestat_set_size(ctx, fd, st_size) } pub(crate) fn fd_filestat_set_times( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - st_atim: __wasi_timestamp_t, - st_mtim: __wasi_timestamp_t, - fst_flags: __wasi_fstflags_t, -) -> __wasi_errno_t { + fd: WasiFd, + st_atim: Timestamp, + st_mtim: Timestamp, + fst_flags: Fstflags, +) -> Errno { super::fd_filestat_set_times(ctx, fd, st_atim, st_mtim, fst_flags) } pub(crate) fn fd_pread( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: WasiFd, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, - offset: __wasi_filesize_t, + offset: Filesize, nread: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::fd_pread::(ctx, fd, iovs, iovs_len, offset, nread) } pub(crate) fn fd_prestat_get( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - buf: WasmPtr<__wasi_prestat_t, MemoryType>, -) -> __wasi_errno_t { + fd: WasiFd, + buf: WasmPtr, +) -> Errno { super::fd_prestat_get::(ctx, fd, buf) } pub(crate) fn fd_prestat_dir_name( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: WasiFd, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::fd_prestat_dir_name::(ctx, fd, path, path_len) } pub(crate) fn fd_pwrite( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: WasiFd, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, - offset: __wasi_filesize_t, + offset: Filesize, nwritten: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::fd_pwrite::(ctx, fd, iovs, iovs_len, offset, nwritten) } pub(crate) fn fd_read( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: WasiFd, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, nread: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::fd_read::(ctx, fd, iovs, iovs_len, nread) } pub(crate) fn fd_readdir( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: WasiFd, buf: WasmPtr, buf_len: MemoryOffset, cookie: __wasi_dircookie_t, bufused: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::fd_readdir::(ctx, fd, buf, buf_len, cookie, bufused) } -pub(crate) fn fd_renumber( - ctx: FunctionEnvMut, - from: __wasi_fd_t, - to: __wasi_fd_t, -) -> __wasi_errno_t { +pub(crate) fn fd_renumber(ctx: FunctionEnvMut, from: WasiFd, to: WasiFd) -> Errno { super::fd_renumber(ctx, from, to) } pub(crate) fn fd_seek( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - offset: __wasi_filedelta_t, - whence: __wasi_whence_t, - newoffset: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> Result<__wasi_errno_t, WasiError> { + fd: WasiFd, + offset: FileDelta, + whence: Whence, + newoffset: WasmPtr, +) -> Result { super::fd_seek::(ctx, fd, offset, whence, newoffset) } -pub(crate) fn fd_sync(ctx: FunctionEnvMut, fd: __wasi_fd_t) -> __wasi_errno_t { +pub(crate) fn fd_sync(ctx: FunctionEnvMut, fd: WasiFd) -> Errno { super::fd_sync(ctx, fd) } pub(crate) fn fd_tell( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - offset: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> __wasi_errno_t { + fd: WasiFd, + offset: WasmPtr, +) -> Errno { super::fd_tell::(ctx, fd, offset) } pub(crate) fn fd_write( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: WasiFd, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, nwritten: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::fd_write::(ctx, fd, iovs, iovs_len, nwritten) } pub(crate) fn path_create_directory( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: WasiFd, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::path_create_directory::(ctx, fd, path, path_len) } pub(crate) fn path_filestat_get( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - flags: __wasi_lookupflags_t, + fd: WasiFd, + flags: LookupFlags, path: WasmPtr, path_len: MemoryOffset, - buf: WasmPtr<__wasi_filestat_t, MemoryType>, -) -> __wasi_errno_t { + buf: WasmPtr, +) -> Errno { super::path_filestat_get::(ctx, fd, flags, path, path_len, buf) } pub(crate) fn path_filestat_set_times( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - flags: __wasi_lookupflags_t, + fd: WasiFd, + flags: LookupFlags, path: WasmPtr, path_len: MemoryOffset, - st_atim: __wasi_timestamp_t, - st_mtim: __wasi_timestamp_t, - fst_flags: __wasi_fstflags_t, -) -> __wasi_errno_t { + st_atim: Timestamp, + st_mtim: Timestamp, + fst_flags: Fstflags, +) -> Errno { super::path_filestat_set_times::( ctx, fd, flags, path, path_len, st_atim, st_mtim, fst_flags, ) @@ -270,14 +269,14 @@ pub(crate) fn path_filestat_set_times( pub(crate) fn path_link( ctx: FunctionEnvMut, - old_fd: __wasi_fd_t, - old_flags: __wasi_lookupflags_t, + old_fd: WasiFd, + old_flags: LookupFlags, old_path: WasmPtr, old_path_len: MemoryOffset, - new_fd: __wasi_fd_t, + new_fd: WasiFd, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::path_link::( ctx, old_fd, @@ -292,16 +291,16 @@ pub(crate) fn path_link( pub(crate) fn path_open( ctx: FunctionEnvMut, - dirfd: __wasi_fd_t, - dirflags: __wasi_lookupflags_t, + dirfd: WasiFd, + dirflags: LookupFlags, path: WasmPtr, path_len: MemoryOffset, - o_flags: __wasi_oflags_t, + o_flags: Oflags, fs_rights_base: __wasi_rights_t, fs_rights_inheriting: __wasi_rights_t, - fs_flags: __wasi_fdflags_t, - fd: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { + fs_flags: WasiFdflags, + fd: WasmPtr, +) -> Errno { super::path_open::( ctx, dirfd, @@ -318,34 +317,34 @@ pub(crate) fn path_open( pub(crate) fn path_readlink( ctx: FunctionEnvMut, - dir_fd: __wasi_fd_t, + dir_fd: WasiFd, path: WasmPtr, path_len: MemoryOffset, buf: WasmPtr, buf_len: MemoryOffset, buf_used: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::path_readlink::(ctx, dir_fd, path, path_len, buf, buf_len, buf_used) } pub(crate) fn path_remove_directory( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: WasiFd, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::path_remove_directory::(ctx, fd, path, path_len) } pub(crate) fn path_rename( ctx: FunctionEnvMut, - old_fd: __wasi_fd_t, + old_fd: WasiFd, old_path: WasmPtr, old_path_len: MemoryOffset, - new_fd: __wasi_fd_t, + new_fd: WasiFd, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::path_rename::( ctx, old_fd, @@ -361,29 +360,29 @@ pub(crate) fn path_symlink( ctx: FunctionEnvMut, old_path: WasmPtr, old_path_len: MemoryOffset, - fd: __wasi_fd_t, + fd: WasiFd, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::path_symlink::(ctx, old_path, old_path_len, fd, new_path, new_path_len) } pub(crate) fn path_unlink_file( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: WasiFd, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::path_unlink_file::(ctx, fd, path, path_len) } pub(crate) fn poll_oneoff( ctx: FunctionEnvMut, in_: WasmPtr<__wasi_subscription_t, MemoryType>, - out_: WasmPtr<__wasi_event_t, MemoryType>, + out_: WasmPtr, nsubscriptions: MemoryOffset, nevents: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::poll_oneoff::(ctx, in_, out_, nsubscriptions, nevents) } @@ -394,7 +393,7 @@ pub(crate) fn proc_exit( super::proc_exit(ctx, code) } -pub(crate) fn proc_raise(ctx: FunctionEnvMut, sig: __wasi_signal_t) -> __wasi_errno_t { +pub(crate) fn proc_raise(ctx: FunctionEnvMut, sig: Signal) -> Errno { super::proc_raise(ctx, sig) } @@ -402,23 +401,23 @@ pub(crate) fn random_get( ctx: FunctionEnvMut, buf: WasmPtr, buf_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::random_get::(ctx, buf, buf_len) } -pub(crate) fn sched_yield(ctx: FunctionEnvMut) -> Result<__wasi_errno_t, WasiError> { +pub(crate) fn sched_yield(ctx: FunctionEnvMut) -> Result { super::sched_yield(ctx) } pub(crate) fn sock_recv( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: WasiFd, ri_data: WasmPtr<__wasi_iovec_t, MemoryType>, ri_data_len: MemoryOffset, - ri_flags: __wasi_riflags_t, + ri_flags: RiFlags, ro_data_len: WasmPtr, - ro_flags: WasmPtr<__wasi_roflags_t, MemoryType>, -) -> Result<__wasi_errno_t, WasiError> { + ro_flags: WasmPtr, +) -> Result { super::sock_recv::( ctx, sock, @@ -432,19 +431,19 @@ pub(crate) fn sock_recv( pub(crate) fn sock_send( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: WasiFd, si_data: WasmPtr<__wasi_ciovec_t, MemoryType>, si_data_len: MemoryOffset, - si_flags: __wasi_siflags_t, + si_flags: SiFlags, ret_data_len: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::sock_send::(ctx, sock, si_data, si_data_len, si_flags, ret_data_len) } pub(crate) fn sock_shutdown( ctx: FunctionEnvMut, - sock: __wasi_fd_t, - how: __wasi_sdflags_t, -) -> __wasi_errno_t { + sock: WasiFd, + how: SdFlags, +) -> Errno { super::sock_shutdown(ctx, sock, how) } diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index 5cb6899c3ef..53ca959643d 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -1,7 +1,13 @@ #![deny(dead_code)] use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{FunctionEnvMut, Memory, Memory32, MemorySize, StoreMut, WasmPtr, WasmSlice}; -use wasmer_wasi_types::*; +use wasmer_wasi_types::types::*; +use wasmer_wasi_types::wasi::{ + Addressfamily, Advice, Bid, BusDataFormat, BusErrno, BusHandles, Cid, Clockid, Dircookie, + Errno, Event, EventFdFlags, Fd, Fdflags, Fdstat, Filesize, Filestat, Fstflags, Pid, Prestat, + Rights, Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, Tid, Timestamp, Tty, + Whence, +}; type MemoryType = Memory32; type MemoryOffset = u32; @@ -10,7 +16,7 @@ pub(crate) fn args_get( ctx: FunctionEnvMut, argv: WasmPtr, MemoryType>, argv_buf: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::args_get::(ctx, argv, argv_buf) } @@ -18,24 +24,24 @@ pub(crate) fn args_sizes_get( ctx: FunctionEnvMut, argc: WasmPtr, argv_buf_size: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::args_sizes_get::(ctx, argc, argv_buf_size) } pub(crate) fn clock_res_get( ctx: FunctionEnvMut, - clock_id: __wasi_clockid_t, - resolution: WasmPtr<__wasi_timestamp_t, MemoryType>, -) -> __wasi_errno_t { + clock_id: Clockid, + resolution: WasmPtr, +) -> Errno { super::clock_res_get::(ctx, clock_id, resolution) } pub(crate) fn clock_time_get( ctx: FunctionEnvMut, - clock_id: __wasi_clockid_t, - precision: __wasi_timestamp_t, - time: WasmPtr<__wasi_timestamp_t, MemoryType>, -) -> __wasi_errno_t { + clock_id: Clockid, + precision: Timestamp, + time: WasmPtr, +) -> Errno { super::clock_time_get::(ctx, clock_id, precision, time) } @@ -43,7 +49,7 @@ pub(crate) fn environ_get( ctx: FunctionEnvMut, environ: WasmPtr, MemoryType>, environ_buf: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::environ_get::(ctx, environ, environ_buf) } @@ -51,218 +57,210 @@ pub(crate) fn environ_sizes_get( ctx: FunctionEnvMut, environ_count: WasmPtr, environ_buf_size: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::environ_sizes_get::(ctx, environ_count, environ_buf_size) } pub(crate) fn fd_advise( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - offset: __wasi_filesize_t, - len: __wasi_filesize_t, - advice: __wasi_advice_t, -) -> __wasi_errno_t { + fd: Fd, + offset: Filesize, + len: Filesize, + advice: Advice, +) -> Errno { super::fd_advise(ctx, fd, offset, len, advice) } pub(crate) fn fd_allocate( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - offset: __wasi_filesize_t, - len: __wasi_filesize_t, -) -> __wasi_errno_t { + fd: Fd, + offset: Filesize, + len: Filesize, +) -> Errno { super::fd_allocate(ctx, fd, offset, len) } -pub(crate) fn fd_close(ctx: FunctionEnvMut, fd: __wasi_fd_t) -> __wasi_errno_t { +pub(crate) fn fd_close(ctx: FunctionEnvMut, fd: Fd) -> Errno { super::fd_close(ctx, fd) } -pub(crate) fn fd_datasync(ctx: FunctionEnvMut, fd: __wasi_fd_t) -> __wasi_errno_t { +pub(crate) fn fd_datasync(ctx: FunctionEnvMut, fd: Fd) -> Errno { super::fd_datasync(ctx, fd) } pub(crate) fn fd_fdstat_get( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - buf_ptr: WasmPtr<__wasi_fdstat_t, MemoryType>, -) -> __wasi_errno_t { + fd: Fd, + buf_ptr: WasmPtr, +) -> Errno { super::fd_fdstat_get::(ctx, fd, buf_ptr) } -pub(crate) fn fd_fdstat_set_flags( - ctx: FunctionEnvMut, - fd: __wasi_fd_t, - flags: __wasi_fdflags_t, -) -> __wasi_errno_t { +pub(crate) fn fd_fdstat_set_flags(ctx: FunctionEnvMut, fd: Fd, flags: Fdflags) -> Errno { super::fd_fdstat_set_flags(ctx, fd, flags) } pub(crate) fn fd_fdstat_set_rights( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - fs_rights_base: __wasi_rights_t, - fs_rights_inheriting: __wasi_rights_t, -) -> __wasi_errno_t { + fd: Fd, + fs_rights_base: Rights, + fs_rights_inheriting: Rights, +) -> Errno { super::fd_fdstat_set_rights(ctx, fd, fs_rights_base, fs_rights_inheriting) } pub(crate) fn fd_filestat_get( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - buf: WasmPtr<__wasi_filestat_t, MemoryType>, -) -> __wasi_errno_t { + fd: Fd, + buf: WasmPtr, +) -> Errno { super::fd_filestat_get::(ctx, fd, buf) } pub(crate) fn fd_filestat_set_size( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - st_size: __wasi_filesize_t, -) -> __wasi_errno_t { + fd: Fd, + st_size: Filesize, +) -> Errno { super::fd_filestat_set_size(ctx, fd, st_size) } pub(crate) fn fd_filestat_set_times( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - st_atim: __wasi_timestamp_t, - st_mtim: __wasi_timestamp_t, - fst_flags: __wasi_fstflags_t, -) -> __wasi_errno_t { + fd: Fd, + st_atim: Timestamp, + st_mtim: Timestamp, + fst_flags: Fstflags, +) -> Errno { super::fd_filestat_set_times(ctx, fd, st_atim, st_mtim, fst_flags) } pub(crate) fn fd_pread( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: Fd, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, - offset: __wasi_filesize_t, + offset: Filesize, nread: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::fd_pread::(ctx, fd, iovs, iovs_len, offset, nread) } pub(crate) fn fd_prestat_get( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - buf: WasmPtr<__wasi_prestat_t, MemoryType>, -) -> __wasi_errno_t { + fd: Fd, + buf: WasmPtr, +) -> Errno { super::fd_prestat_get::(ctx, fd, buf) } pub(crate) fn fd_prestat_dir_name( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: Fd, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::fd_prestat_dir_name::(ctx, fd, path, path_len) } pub(crate) fn fd_pwrite( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: Fd, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, - offset: __wasi_filesize_t, + offset: Filesize, nwritten: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::fd_pwrite::(ctx, fd, iovs, iovs_len, offset, nwritten) } pub(crate) fn fd_read( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: Fd, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, nread: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::fd_read::(ctx, fd, iovs, iovs_len, nread) } pub(crate) fn fd_readdir( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: Fd, buf: WasmPtr, buf_len: MemoryOffset, - cookie: __wasi_dircookie_t, + cookie: Dircookie, bufused: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::fd_readdir::(ctx, fd, buf, buf_len, cookie, bufused) } -pub(crate) fn fd_renumber( - ctx: FunctionEnvMut, - from: __wasi_fd_t, - to: __wasi_fd_t, -) -> __wasi_errno_t { +pub(crate) fn fd_renumber(ctx: FunctionEnvMut, from: Fd, to: Fd) -> Errno { super::fd_renumber(ctx, from, to) } pub(crate) fn fd_seek( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - offset: __wasi_filedelta_t, - whence: __wasi_whence_t, - newoffset: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> Result<__wasi_errno_t, WasiError> { + fd: Fd, + offset: FileDelta, + whence: Whence, + newoffset: WasmPtr, +) -> Result { super::fd_seek::(ctx, fd, offset, whence, newoffset) } -pub(crate) fn fd_sync(ctx: FunctionEnvMut, fd: __wasi_fd_t) -> __wasi_errno_t { +pub(crate) fn fd_sync(ctx: FunctionEnvMut, fd: Fd) -> Errno { super::fd_sync(ctx, fd) } pub(crate) fn fd_tell( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - offset: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> __wasi_errno_t { + fd: Fd, + offset: WasmPtr, +) -> Errno { super::fd_tell::(ctx, fd, offset) } pub(crate) fn fd_write( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: Fd, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, nwritten: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::fd_write::(ctx, fd, iovs, iovs_len, nwritten) } pub(crate) fn path_create_directory( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: Fd, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::path_create_directory::(ctx, fd, path, path_len) } pub(crate) fn path_filestat_get( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - flags: __wasi_lookupflags_t, + fd: Fd, + flags: LookupFlags, path: WasmPtr, path_len: MemoryOffset, - buf: WasmPtr<__wasi_filestat_t, MemoryType>, -) -> __wasi_errno_t { + buf: WasmPtr, +) -> Errno { super::path_filestat_get::(ctx, fd, flags, path, path_len, buf) } pub(crate) fn path_filestat_set_times( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - flags: __wasi_lookupflags_t, + fd: Fd, + flags: LookupFlags, path: WasmPtr, path_len: MemoryOffset, - st_atim: __wasi_timestamp_t, - st_mtim: __wasi_timestamp_t, - fst_flags: __wasi_fstflags_t, -) -> __wasi_errno_t { + st_atim: Timestamp, + st_mtim: Timestamp, + fst_flags: Fstflags, +) -> Errno { super::path_filestat_set_times::( ctx, fd, flags, path, path_len, st_atim, st_mtim, fst_flags, ) @@ -270,14 +268,14 @@ pub(crate) fn path_filestat_set_times( pub(crate) fn path_link( ctx: FunctionEnvMut, - old_fd: __wasi_fd_t, - old_flags: __wasi_lookupflags_t, + old_fd: Fd, + old_flags: LookupFlags, old_path: WasmPtr, old_path_len: MemoryOffset, - new_fd: __wasi_fd_t, + new_fd: Fd, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::path_link::( ctx, old_fd, @@ -292,16 +290,16 @@ pub(crate) fn path_link( pub(crate) fn path_open( ctx: FunctionEnvMut, - dirfd: __wasi_fd_t, - dirflags: __wasi_lookupflags_t, + dirfd: Fd, + dirflags: LookupFlags, path: WasmPtr, path_len: MemoryOffset, - o_flags: __wasi_oflags_t, - fs_rights_base: __wasi_rights_t, - fs_rights_inheriting: __wasi_rights_t, - fs_flags: __wasi_fdflags_t, - fd: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { + o_flags: Oflags, + fs_rights_base: Rights, + fs_rights_inheriting: Rights, + fs_flags: Fdflags, + fd: WasmPtr, +) -> Errno { super::path_open::( ctx, dirfd, @@ -318,34 +316,34 @@ pub(crate) fn path_open( pub(crate) fn path_readlink( ctx: FunctionEnvMut, - dir_fd: __wasi_fd_t, + dir_fd: Fd, path: WasmPtr, path_len: MemoryOffset, buf: WasmPtr, buf_len: MemoryOffset, buf_used: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::path_readlink::(ctx, dir_fd, path, path_len, buf, buf_len, buf_used) } pub(crate) fn path_remove_directory( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: Fd, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::path_remove_directory::(ctx, fd, path, path_len) } pub(crate) fn path_rename( ctx: FunctionEnvMut, - old_fd: __wasi_fd_t, + old_fd: Fd, old_path: WasmPtr, old_path_len: MemoryOffset, - new_fd: __wasi_fd_t, + new_fd: Fd, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::path_rename::( ctx, old_fd, @@ -361,29 +359,29 @@ pub(crate) fn path_symlink( ctx: FunctionEnvMut, old_path: WasmPtr, old_path_len: MemoryOffset, - fd: __wasi_fd_t, + fd: Fd, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::path_symlink::(ctx, old_path, old_path_len, fd, new_path, new_path_len) } pub(crate) fn path_unlink_file( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: Fd, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::path_unlink_file::(ctx, fd, path, path_len) } pub(crate) fn poll_oneoff( ctx: FunctionEnvMut, - in_: WasmPtr<__wasi_subscription_t, MemoryType>, - out_: WasmPtr<__wasi_event_t, MemoryType>, + in_: WasmPtr, + out_: WasmPtr, nsubscriptions: MemoryOffset, nevents: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::poll_oneoff::(ctx, in_, out_, nsubscriptions, nevents) } @@ -394,7 +392,7 @@ pub(crate) fn proc_exit( super::proc_exit(ctx, code) } -pub(crate) fn proc_raise(ctx: FunctionEnvMut, sig: __wasi_signal_t) -> __wasi_errno_t { +pub(crate) fn proc_raise(ctx: FunctionEnvMut, sig: Signal) -> Errno { super::proc_raise(ctx, sig) } @@ -402,46 +400,40 @@ pub(crate) fn random_get( ctx: FunctionEnvMut, buf: WasmPtr, buf_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::random_get::(ctx, buf, buf_len) } pub(crate) fn fd_dup( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - ret_fd: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { + fd: Fd, + ret_fd: WasmPtr, +) -> Errno { super::fd_dup::(ctx, fd, ret_fd) } pub(crate) fn fd_event( ctx: FunctionEnvMut, initial_val: u64, - flags: __wasi_eventfdflags, - ret_fd: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { + flags: EventFdFlags, + ret_fd: WasmPtr, +) -> Errno { super::fd_event(ctx, initial_val, flags, ret_fd) } pub(crate) fn fd_pipe( ctx: FunctionEnvMut, - ro_fd1: WasmPtr<__wasi_fd_t, MemoryType>, - ro_fd2: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { + ro_fd1: WasmPtr, + ro_fd2: WasmPtr, +) -> Errno { super::fd_pipe::(ctx, ro_fd1, ro_fd2) } -pub(crate) fn tty_get( - ctx: FunctionEnvMut, - tty_state: WasmPtr<__wasi_tty_t, MemoryType>, -) -> __wasi_errno_t { +pub(crate) fn tty_get(ctx: FunctionEnvMut, tty_state: WasmPtr) -> Errno { super::tty_get::(ctx, tty_state) } -pub(crate) fn tty_set( - ctx: FunctionEnvMut, - tty_state: WasmPtr<__wasi_tty_t, MemoryType>, -) -> __wasi_errno_t { +pub(crate) fn tty_set(ctx: FunctionEnvMut, tty_state: WasmPtr) -> Errno { super::tty_set::(ctx, tty_state) } @@ -449,7 +441,7 @@ pub(crate) fn getcwd( ctx: FunctionEnvMut, path: WasmPtr, path_len: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::getcwd::(ctx, path, path_len) } @@ -457,7 +449,7 @@ pub(crate) fn chdir( ctx: FunctionEnvMut, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::chdir::(ctx, path, path_len) } @@ -466,55 +458,46 @@ pub(crate) fn thread_spawn( method: WasmPtr, method_len: MemoryOffset, user_data: u64, - reactor: __wasi_bool_t, - ret_tid: WasmPtr<__wasi_tid_t, MemoryType>, -) -> __wasi_errno_t { + reactor: Bool, + ret_tid: WasmPtr, +) -> Errno { super::thread_spawn::(ctx, method, method_len, user_data, reactor, ret_tid) } pub(crate) fn thread_sleep( ctx: FunctionEnvMut, - duration: __wasi_timestamp_t, -) -> Result<__wasi_errno_t, WasiError> { + duration: Timestamp, +) -> Result { super::thread_sleep(ctx, duration) } -pub(crate) fn thread_id( - ctx: FunctionEnvMut, - ret_tid: WasmPtr<__wasi_tid_t, MemoryType>, -) -> __wasi_errno_t { +pub(crate) fn thread_id(ctx: FunctionEnvMut, ret_tid: WasmPtr) -> Errno { super::thread_id::(ctx, ret_tid) } -pub(crate) fn thread_join( - ctx: FunctionEnvMut, - tid: __wasi_tid_t, -) -> Result<__wasi_errno_t, WasiError> { +pub(crate) fn thread_join(ctx: FunctionEnvMut, tid: Tid) -> Result { super::thread_join(ctx, tid) } pub(crate) fn thread_parallelism( ctx: FunctionEnvMut, ret_parallelism: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::thread_parallelism::(ctx, ret_parallelism) } pub(crate) fn thread_exit( ctx: FunctionEnvMut, exitcode: __wasi_exitcode_t, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::thread_exit(ctx, exitcode) } -pub(crate) fn sched_yield(ctx: FunctionEnvMut) -> Result<__wasi_errno_t, WasiError> { +pub(crate) fn sched_yield(ctx: FunctionEnvMut) -> Result { super::sched_yield(ctx) } -pub(crate) fn getpid( - ctx: FunctionEnvMut, - ret_pid: WasmPtr<__wasi_pid_t, MemoryType>, -) -> __wasi_errno_t { +pub(crate) fn getpid(ctx: FunctionEnvMut, ret_pid: WasmPtr) -> Errno { super::getpid::(ctx, ret_pid) } @@ -522,18 +505,18 @@ pub(crate) fn process_spawn( ctx: FunctionEnvMut, name: WasmPtr, name_len: MemoryOffset, - chroot: __wasi_bool_t, + chroot: Bool, args: WasmPtr, args_len: MemoryOffset, preopen: WasmPtr, preopen_len: MemoryOffset, - stdin: __wasi_stdiomode_t, - stdout: __wasi_stdiomode_t, - stderr: __wasi_stdiomode_t, + stdin: StdioMode, + stdout: StdioMode, + stderr: StdioMode, working_dir: WasmPtr, working_dir_len: MemoryOffset, - ret_handles: WasmPtr<__wasi_bus_handles_t, MemoryType>, -) -> __bus_errno_t { + ret_handles: WasmPtr, +) -> BusErrno { super::process_spawn::( ctx, name, @@ -556,9 +539,9 @@ pub(crate) fn bus_open_local( ctx: FunctionEnvMut, name: WasmPtr, name_len: MemoryOffset, - reuse: __wasi_bool_t, - ret_bid: WasmPtr<__wasi_bid_t, MemoryType>, -) -> __bus_errno_t { + reuse: Bool, + ret_bid: WasmPtr, +) -> BusErrno { super::bus_open_local::(ctx, name, name_len, reuse, ret_bid) } @@ -566,13 +549,13 @@ pub(crate) fn bus_open_remote( ctx: FunctionEnvMut, name: WasmPtr, name_len: MemoryOffset, - reuse: __wasi_bool_t, + reuse: Bool, instance: WasmPtr, instance_len: MemoryOffset, token: WasmPtr, token_len: MemoryOffset, - ret_bid: WasmPtr<__wasi_bid_t, MemoryType>, -) -> __bus_errno_t { + ret_bid: WasmPtr, +) -> BusErrno { super::bus_open_remote::( ctx, name, @@ -586,21 +569,21 @@ pub(crate) fn bus_open_remote( ) } -pub(crate) fn bus_close(ctx: FunctionEnvMut, bid: __wasi_bid_t) -> __bus_errno_t { +pub(crate) fn bus_close(ctx: FunctionEnvMut, bid: Bid) -> BusErrno { super::bus_close(ctx, bid) } pub(crate) fn bus_call( ctx: FunctionEnvMut, - bid: __wasi_bid_t, - keep_alive: __wasi_bool_t, + bid: Bid, + keep_alive: Bool, topic: WasmPtr, topic_len: MemoryOffset, - format: __wasi_busdataformat_t, + format: BusDataFormat, buf: WasmPtr, buf_len: MemoryOffset, - ret_cid: WasmPtr<__wasi_cid_t, MemoryType>, -) -> __bus_errno_t { + ret_cid: WasmPtr, +) -> BusErrno { super::bus_call::( ctx, bid, keep_alive, topic, topic_len, format, buf, buf_len, ret_cid, ) @@ -608,15 +591,15 @@ pub(crate) fn bus_call( pub(crate) fn bus_subcall( ctx: FunctionEnvMut, - parent: __wasi_cid_t, - keep_alive: __wasi_bool_t, + parent: Cid, + keep_alive: Bool, topic: WasmPtr, topic_len: MemoryOffset, - format: __wasi_busdataformat_t, + format: BusDataFormat, buf: WasmPtr, buf_len: MemoryOffset, - ret_cid: WasmPtr<__wasi_cid_t, MemoryType>, -) -> __bus_errno_t { + ret_cid: WasmPtr, +) -> BusErrno { super::bus_subcall::( ctx, parent, keep_alive, topic, topic_len, format, buf, buf_len, ret_cid, ) @@ -624,13 +607,13 @@ pub(crate) fn bus_subcall( pub(crate) fn bus_poll( ctx: FunctionEnvMut, - timeout: __wasi_timestamp_t, + timeout: Timestamp, events: WasmPtr, nevents: MemoryOffset, malloc: WasmPtr, malloc_len: MemoryOffset, ret_nevents: WasmPtr, -) -> __bus_errno_t { +) -> BusErrno { super::bus_poll::( ctx, timeout, @@ -644,23 +627,19 @@ pub(crate) fn bus_poll( pub(crate) fn call_reply( ctx: FunctionEnvMut, - cid: __wasi_cid_t, - format: __wasi_busdataformat_t, + cid: Cid, + format: BusDataFormat, buf: WasmPtr, buf_len: MemoryOffset, -) -> __bus_errno_t { +) -> BusErrno { super::call_reply::(ctx, cid, format, buf, buf_len) } -pub(crate) fn call_fault( - ctx: FunctionEnvMut, - cid: __wasi_cid_t, - fault: __bus_errno_t, -) -> __bus_errno_t { +pub(crate) fn call_fault(ctx: FunctionEnvMut, cid: Cid, fault: BusErrno) -> BusErrno { super::call_fault(ctx, cid, fault) } -pub(crate) fn call_close(ctx: FunctionEnvMut, cid: __wasi_cid_t) -> __bus_errno_t { +pub(crate) fn call_close(ctx: FunctionEnvMut, cid: Cid) -> BusErrno { super::call_close(ctx, cid) } @@ -670,34 +649,34 @@ pub(crate) fn port_bridge( network_len: MemoryOffset, token: WasmPtr, token_len: MemoryOffset, - security: __wasi_streamsecurity_t, -) -> __wasi_errno_t { + security: Streamsecurity, +) -> Errno { super::port_bridge::(ctx, network, network_len, token, token_len, security) } -pub(crate) fn port_unbridge(ctx: FunctionEnvMut) -> __wasi_errno_t { +pub(crate) fn port_unbridge(ctx: FunctionEnvMut) -> Errno { super::port_unbridge(ctx) } -pub(crate) fn port_dhcp_acquire(ctx: FunctionEnvMut) -> __wasi_errno_t { +pub(crate) fn port_dhcp_acquire(ctx: FunctionEnvMut) -> Errno { super::port_dhcp_acquire(ctx) } pub(crate) fn port_addr_add( ctx: FunctionEnvMut, addr: WasmPtr<__wasi_cidr_t, MemoryType>, -) -> __wasi_errno_t { +) -> Errno { super::port_addr_add::(ctx, addr) } pub(crate) fn port_addr_remove( ctx: FunctionEnvMut, addr: WasmPtr<__wasi_addr_t, MemoryType>, -) -> __wasi_errno_t { +) -> Errno { super::port_addr_remove::(ctx, addr) } -pub(crate) fn port_addr_clear(ctx: FunctionEnvMut) -> __wasi_errno_t { +pub(crate) fn port_addr_clear(ctx: FunctionEnvMut) -> Errno { super::port_addr_clear(ctx) } @@ -705,21 +684,21 @@ pub(crate) fn port_addr_list( ctx: FunctionEnvMut, addrs: WasmPtr<__wasi_cidr_t, MemoryType>, naddrs: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::port_addr_list::(ctx, addrs, naddrs) } pub(crate) fn port_mac( ctx: FunctionEnvMut, ret_mac: WasmPtr<__wasi_hardwareaddress_t, MemoryType>, -) -> __wasi_errno_t { +) -> Errno { super::port_mac::(ctx, ret_mac) } pub(crate) fn port_gateway_set( ctx: FunctionEnvMut, ip: WasmPtr<__wasi_addr_t, MemoryType>, -) -> __wasi_errno_t { +) -> Errno { super::port_gateway_set::(ctx, ip) } @@ -727,28 +706,28 @@ pub(crate) fn port_route_add( ctx: FunctionEnvMut, cidr: WasmPtr<__wasi_cidr_t, MemoryType>, via_router: WasmPtr<__wasi_addr_t, MemoryType>, - preferred_until: WasmPtr<__wasi_option_timestamp_t, MemoryType>, - expires_at: WasmPtr<__wasi_option_timestamp_t, MemoryType>, -) -> __wasi_errno_t { + preferred_until: WasmPtr, + expires_at: WasmPtr, +) -> Errno { super::port_route_add::(ctx, cidr, via_router, preferred_until, expires_at) } pub(crate) fn port_route_remove( ctx: FunctionEnvMut, ip: WasmPtr<__wasi_addr_t, MemoryType>, -) -> __wasi_errno_t { +) -> Errno { super::port_route_remove::(ctx, ip) } -pub(crate) fn port_route_clear(ctx: FunctionEnvMut) -> __wasi_errno_t { +pub(crate) fn port_route_clear(ctx: FunctionEnvMut) -> Errno { super::port_route_clear(ctx) } pub(crate) fn port_route_list( ctx: FunctionEnvMut, - routes: WasmPtr<__wasi_route_t, MemoryType>, + routes: WasmPtr, nroutes: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::port_route_list::(ctx, routes, nroutes) } @@ -756,8 +735,8 @@ pub(crate) fn ws_connect( ctx: FunctionEnvMut, url: WasmPtr, url_len: MemoryOffset, - ret_sock: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { + ret_sock: WasmPtr, +) -> Errno { super::ws_connect::(ctx, url, url_len, ret_sock) } @@ -769,9 +748,9 @@ pub(crate) fn http_request( method_len: MemoryOffset, headers: WasmPtr, headers_len: MemoryOffset, - gzip: __wasi_bool_t, - ret_handles: WasmPtr<__wasi_http_handles_t, MemoryType>, -) -> __wasi_errno_t { + gzip: Bool, + ret_handles: WasmPtr, +) -> Errno { super::http_request::( ctx, url, @@ -787,183 +766,179 @@ pub(crate) fn http_request( pub(crate) fn http_status( ctx: FunctionEnvMut, - sock: __wasi_fd_t, - status: WasmPtr<__wasi_http_status_t, MemoryType>, + sock: Fd, + status: WasmPtr, status_text: WasmPtr, status_text_len: WasmPtr, headers: WasmPtr, headers_len: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::http_status::(ctx, sock, status) } pub(crate) fn sock_status( ctx: FunctionEnvMut, - sock: __wasi_fd_t, - ret_status: WasmPtr<__wasi_sockstatus_t, MemoryType>, -) -> __wasi_errno_t { + sock: Fd, + ret_status: WasmPtr, +) -> Errno { super::sock_status::(ctx, sock, ret_status) } pub(crate) fn sock_addr_local( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: Fd, ret_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> __wasi_errno_t { +) -> Errno { super::sock_addr_local::(ctx, sock, ret_addr) } pub(crate) fn sock_addr_peer( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: Fd, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> __wasi_errno_t { +) -> Errno { super::sock_addr_peer::(ctx, sock, ro_addr) } pub(crate) fn sock_open( ctx: FunctionEnvMut, - af: __wasi_addressfamily_t, - ty: __wasi_socktype_t, - pt: __wasi_sockproto_t, - ro_sock: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { + af: Addressfamily, + ty: Socktype, + pt: SockProto, + ro_sock: WasmPtr, +) -> Errno { super::sock_open::(ctx, af, ty, pt, ro_sock) } pub(crate) fn sock_set_opt_flag( ctx: FunctionEnvMut, - sock: __wasi_fd_t, - opt: __wasi_sockoption_t, - flag: __wasi_bool_t, -) -> __wasi_errno_t { + sock: Fd, + opt: Sockoption, + flag: Bool, +) -> Errno { super::sock_set_opt_flag(ctx, sock, opt, flag) } pub(crate) fn sock_get_opt_flag( ctx: FunctionEnvMut, - sock: __wasi_fd_t, - opt: __wasi_sockoption_t, - ret_flag: WasmPtr<__wasi_bool_t, MemoryType>, -) -> __wasi_errno_t { + sock: Fd, + opt: Sockoption, + ret_flag: WasmPtr, +) -> Errno { super::sock_get_opt_flag::(ctx, sock, opt, ret_flag) } pub fn sock_set_opt_time( ctx: FunctionEnvMut, - sock: __wasi_fd_t, - opt: __wasi_sockoption_t, - time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, -) -> __wasi_errno_t { + sock: Fd, + opt: Sockoption, + time: WasmPtr, +) -> Errno { super::sock_set_opt_time(ctx, sock, opt, time) } pub fn sock_get_opt_time( ctx: FunctionEnvMut, - sock: __wasi_fd_t, - opt: __wasi_sockoption_t, - ret_time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, -) -> __wasi_errno_t { + sock: Fd, + opt: Sockoption, + ret_time: WasmPtr, +) -> Errno { super::sock_get_opt_time(ctx, sock, opt, ret_time) } pub fn sock_set_opt_size( ctx: FunctionEnvMut, - sock: __wasi_fd_t, - opt: __wasi_sockoption_t, - size: __wasi_filesize_t, -) -> __wasi_errno_t { + sock: Fd, + opt: Sockoption, + size: Filesize, +) -> Errno { super::sock_set_opt_size(ctx, sock, opt, size) } pub fn sock_get_opt_size( ctx: FunctionEnvMut, - sock: __wasi_fd_t, - opt: __wasi_sockoption_t, - ret_size: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> __wasi_errno_t { + sock: Fd, + opt: Sockoption, + ret_size: WasmPtr, +) -> Errno { super::sock_get_opt_size(ctx, sock, opt, ret_size) } pub(crate) fn sock_join_multicast_v4( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: Fd, multiaddr: WasmPtr<__wasi_addr_ip4_t, MemoryType>, iface: WasmPtr<__wasi_addr_ip4_t, MemoryType>, -) -> __wasi_errno_t { +) -> Errno { super::sock_join_multicast_v4::(ctx, sock, multiaddr, iface) } pub(crate) fn sock_leave_multicast_v4( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: Fd, multiaddr: WasmPtr<__wasi_addr_ip4_t, MemoryType>, iface: WasmPtr<__wasi_addr_ip4_t, MemoryType>, -) -> __wasi_errno_t { +) -> Errno { super::sock_leave_multicast_v4::(ctx, sock, multiaddr, iface) } pub(crate) fn sock_join_multicast_v6( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: Fd, multiaddr: WasmPtr<__wasi_addr_ip6_t, MemoryType>, iface: u32, -) -> __wasi_errno_t { +) -> Errno { super::sock_join_multicast_v6::(ctx, sock, multiaddr, iface) } pub(crate) fn sock_leave_multicast_v6( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: Fd, multiaddr: WasmPtr<__wasi_addr_ip6_t, MemoryType>, iface: u32, -) -> __wasi_errno_t { +) -> Errno { super::sock_leave_multicast_v6::(ctx, sock, multiaddr, iface) } pub(crate) fn sock_bind( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: Fd, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> __wasi_errno_t { +) -> Errno { super::sock_bind::(ctx, sock, addr) } -pub(crate) fn sock_listen( - ctx: FunctionEnvMut, - sock: __wasi_fd_t, - backlog: MemoryOffset, -) -> __wasi_errno_t { +pub(crate) fn sock_listen(ctx: FunctionEnvMut, sock: Fd, backlog: MemoryOffset) -> Errno { super::sock_listen::(ctx, sock, backlog) } pub(crate) fn sock_accept( ctx: FunctionEnvMut, - sock: __wasi_fd_t, - fd_flags: __wasi_fdflags_t, - ro_fd: WasmPtr<__wasi_fd_t, MemoryType>, + sock: Fd, + fd_flags: Fdflags, + ro_fd: WasmPtr, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::sock_accept::(ctx, sock, fd_flags, ro_fd, ro_addr) } pub(crate) fn sock_connect( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: Fd, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> __wasi_errno_t { +) -> Errno { super::sock_connect::(ctx, sock, addr) } pub(crate) fn sock_recv( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: Fd, ri_data: WasmPtr<__wasi_iovec_t, MemoryType>, ri_data_len: MemoryOffset, - ri_flags: __wasi_riflags_t, + ri_flags: RiFlags, ro_data_len: WasmPtr, - ro_flags: WasmPtr<__wasi_roflags_t, MemoryType>, -) -> Result<__wasi_errno_t, WasiError> { + ro_flags: WasmPtr, +) -> Result { super::sock_recv::( ctx, sock, @@ -977,14 +952,14 @@ pub(crate) fn sock_recv( pub(crate) fn sock_recv_from( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: Fd, ri_data: WasmPtr<__wasi_iovec_t, MemoryType>, ri_data_len: MemoryOffset, - ri_flags: __wasi_riflags_t, + ri_flags: RiFlags, ro_data_len: WasmPtr, - ro_flags: WasmPtr<__wasi_roflags_t, MemoryType>, + ro_flags: WasmPtr, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::sock_recv_from::( ctx, sock, @@ -999,24 +974,24 @@ pub(crate) fn sock_recv_from( pub(crate) fn sock_send( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: Fd, si_data: WasmPtr<__wasi_ciovec_t, MemoryType>, si_data_len: MemoryOffset, - si_flags: __wasi_siflags_t, + si_flags: SiFlags, ret_data_len: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::sock_send::(ctx, sock, si_data, si_data_len, si_flags, ret_data_len) } pub(crate) fn sock_send_to( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: Fd, si_data: WasmPtr<__wasi_ciovec_t, MemoryType>, si_data_len: MemoryOffset, - si_flags: __wasi_siflags_t, + si_flags: SiFlags, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ret_data_len: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::sock_send_to::( ctx, sock, @@ -1030,20 +1005,16 @@ pub(crate) fn sock_send_to( pub(crate) fn sock_send_file( ctx: FunctionEnvMut, - out_fd: __wasi_fd_t, - in_fd: __wasi_fd_t, - offset: __wasi_filesize_t, - count: __wasi_filesize_t, - ret_sent: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> Result<__wasi_errno_t, WasiError> { + out_fd: Fd, + in_fd: Fd, + offset: Filesize, + count: Filesize, + ret_sent: WasmPtr, +) -> Result { unsafe { super::sock_send_file::(ctx, out_fd, in_fd, offset, count, ret_sent) } } -pub(crate) fn sock_shutdown( - ctx: FunctionEnvMut, - sock: __wasi_fd_t, - how: __wasi_sdflags_t, -) -> __wasi_errno_t { +pub(crate) fn sock_shutdown(ctx: FunctionEnvMut, sock: Fd, how: SdFlags) -> Errno { super::sock_shutdown(ctx, sock, how) } @@ -1055,6 +1026,6 @@ pub(crate) fn resolve( ips: WasmPtr<__wasi_addr_t, MemoryType>, nips: MemoryOffset, ret_nips: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::resolve::(ctx, host, host_len, port, ips, nips, ret_nips) } diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index b42307e0da8..df48c26a6ea 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -1,7 +1,13 @@ #![deny(dead_code)] use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{FunctionEnvMut, Memory, Memory64, MemorySize, StoreMut, WasmPtr, WasmSlice}; -use wasmer_wasi_types::*; +use wasmer_wasi_types::types::*; +use wasmer_wasi_types::wasi::{ + Addressfamily, Advice, Bid, BusDataFormat, BusErrno, BusHandles, Cid, Clockid, Dircookie, + Errno, Event, EventFdFlags, Fd, Fdflags, Fdstat, Filesize, Filestat, Fstflags, Pid, Prestat, + Rights, Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, Tid, Timestamp, Tty, + Whence, +}; type MemoryType = Memory64; type MemoryOffset = u64; @@ -10,7 +16,7 @@ pub(crate) fn args_get( ctx: FunctionEnvMut, argv: WasmPtr, MemoryType>, argv_buf: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::args_get::(ctx, argv, argv_buf) } @@ -18,24 +24,24 @@ pub(crate) fn args_sizes_get( ctx: FunctionEnvMut, argc: WasmPtr, argv_buf_size: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::args_sizes_get::(ctx, argc, argv_buf_size) } pub(crate) fn clock_res_get( ctx: FunctionEnvMut, - clock_id: __wasi_clockid_t, - resolution: WasmPtr<__wasi_timestamp_t, MemoryType>, -) -> __wasi_errno_t { + clock_id: Clockid, + resolution: WasmPtr, +) -> Errno { super::clock_res_get::(ctx, clock_id, resolution) } pub(crate) fn clock_time_get( ctx: FunctionEnvMut, - clock_id: __wasi_clockid_t, - precision: __wasi_timestamp_t, - time: WasmPtr<__wasi_timestamp_t, MemoryType>, -) -> __wasi_errno_t { + clock_id: Clockid, + precision: Timestamp, + time: WasmPtr, +) -> Errno { super::clock_time_get::(ctx, clock_id, precision, time) } @@ -43,7 +49,7 @@ pub(crate) fn environ_get( ctx: FunctionEnvMut, environ: WasmPtr, MemoryType>, environ_buf: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::environ_get::(ctx, environ, environ_buf) } @@ -51,218 +57,210 @@ pub(crate) fn environ_sizes_get( ctx: FunctionEnvMut, environ_count: WasmPtr, environ_buf_size: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::environ_sizes_get::(ctx, environ_count, environ_buf_size) } pub(crate) fn fd_advise( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - offset: __wasi_filesize_t, - len: __wasi_filesize_t, - advice: __wasi_advice_t, -) -> __wasi_errno_t { + fd: Fd, + offset: Filesize, + len: Filesize, + advice: Advice, +) -> Errno { super::fd_advise(ctx, fd, offset, len, advice) } pub(crate) fn fd_allocate( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - offset: __wasi_filesize_t, - len: __wasi_filesize_t, -) -> __wasi_errno_t { + fd: Fd, + offset: Filesize, + len: Filesize, +) -> Errno { super::fd_allocate(ctx, fd, offset, len) } -pub(crate) fn fd_close(ctx: FunctionEnvMut, fd: __wasi_fd_t) -> __wasi_errno_t { +pub(crate) fn fd_close(ctx: FunctionEnvMut, fd: Fd) -> Errno { super::fd_close(ctx, fd) } -pub(crate) fn fd_datasync(ctx: FunctionEnvMut, fd: __wasi_fd_t) -> __wasi_errno_t { +pub(crate) fn fd_datasync(ctx: FunctionEnvMut, fd: Fd) -> Errno { super::fd_datasync(ctx, fd) } pub(crate) fn fd_fdstat_get( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - buf_ptr: WasmPtr<__wasi_fdstat_t, MemoryType>, -) -> __wasi_errno_t { + fd: Fd, + buf_ptr: WasmPtr, +) -> Errno { super::fd_fdstat_get::(ctx, fd, buf_ptr) } -pub(crate) fn fd_fdstat_set_flags( - ctx: FunctionEnvMut, - fd: __wasi_fd_t, - flags: __wasi_fdflags_t, -) -> __wasi_errno_t { +pub(crate) fn fd_fdstat_set_flags(ctx: FunctionEnvMut, fd: Fd, flags: Fdflags) -> Errno { super::fd_fdstat_set_flags(ctx, fd, flags) } pub(crate) fn fd_fdstat_set_rights( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - fs_rights_base: __wasi_rights_t, - fs_rights_inheriting: __wasi_rights_t, -) -> __wasi_errno_t { + fd: Fd, + fs_rights_base: Rights, + fs_rights_inheriting: Rights, +) -> Errno { super::fd_fdstat_set_rights(ctx, fd, fs_rights_base, fs_rights_inheriting) } pub(crate) fn fd_filestat_get( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - buf: WasmPtr<__wasi_filestat_t, MemoryType>, -) -> __wasi_errno_t { + fd: Fd, + buf: WasmPtr, +) -> Errno { super::fd_filestat_get::(ctx, fd, buf) } pub(crate) fn fd_filestat_set_size( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - st_size: __wasi_filesize_t, -) -> __wasi_errno_t { + fd: Fd, + st_size: Filesize, +) -> Errno { super::fd_filestat_set_size(ctx, fd, st_size) } pub(crate) fn fd_filestat_set_times( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - st_atim: __wasi_timestamp_t, - st_mtim: __wasi_timestamp_t, - fst_flags: __wasi_fstflags_t, -) -> __wasi_errno_t { + fd: Fd, + st_atim: Timestamp, + st_mtim: Timestamp, + fst_flags: Fstflags, +) -> Errno { super::fd_filestat_set_times(ctx, fd, st_atim, st_mtim, fst_flags) } pub(crate) fn fd_pread( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: Fd, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, - offset: __wasi_filesize_t, + offset: Filesize, nread: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::fd_pread::(ctx, fd, iovs, iovs_len, offset, nread) } pub(crate) fn fd_prestat_get( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - buf: WasmPtr<__wasi_prestat_t, MemoryType>, -) -> __wasi_errno_t { + fd: Fd, + buf: WasmPtr, +) -> Errno { super::fd_prestat_get::(ctx, fd, buf) } pub(crate) fn fd_prestat_dir_name( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: Fd, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::fd_prestat_dir_name::(ctx, fd, path, path_len) } pub(crate) fn fd_pwrite( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: Fd, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, - offset: __wasi_filesize_t, + offset: Filesize, nwritten: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::fd_pwrite::(ctx, fd, iovs, iovs_len, offset, nwritten) } pub(crate) fn fd_read( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: Fd, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, nread: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::fd_read::(ctx, fd, iovs, iovs_len, nread) } pub(crate) fn fd_readdir( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: Fd, buf: WasmPtr, buf_len: MemoryOffset, - cookie: __wasi_dircookie_t, + cookie: Dircookie, bufused: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::fd_readdir::(ctx, fd, buf, buf_len, cookie, bufused) } -pub(crate) fn fd_renumber( - ctx: FunctionEnvMut, - from: __wasi_fd_t, - to: __wasi_fd_t, -) -> __wasi_errno_t { +pub(crate) fn fd_renumber(ctx: FunctionEnvMut, from: Fd, to: Fd) -> Errno { super::fd_renumber(ctx, from, to) } pub(crate) fn fd_seek( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - offset: __wasi_filedelta_t, - whence: __wasi_whence_t, - newoffset: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> Result<__wasi_errno_t, WasiError> { + fd: Fd, + offset: FileDelta, + whence: Whence, + newoffset: WasmPtr, +) -> Result { super::fd_seek::(ctx, fd, offset, whence, newoffset) } -pub(crate) fn fd_sync(ctx: FunctionEnvMut, fd: __wasi_fd_t) -> __wasi_errno_t { +pub(crate) fn fd_sync(ctx: FunctionEnvMut, fd: Fd) -> Errno { super::fd_sync(ctx, fd) } pub(crate) fn fd_tell( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - offset: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> __wasi_errno_t { + fd: Fd, + offset: WasmPtr, +) -> Errno { super::fd_tell::(ctx, fd, offset) } pub(crate) fn fd_write( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: Fd, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, nwritten: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::fd_write::(ctx, fd, iovs, iovs_len, nwritten) } pub(crate) fn path_create_directory( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: Fd, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::path_create_directory::(ctx, fd, path, path_len) } pub(crate) fn path_filestat_get( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - flags: __wasi_lookupflags_t, + fd: Fd, + flags: LookupFlags, path: WasmPtr, path_len: MemoryOffset, - buf: WasmPtr<__wasi_filestat_t, MemoryType>, -) -> __wasi_errno_t { + buf: WasmPtr, +) -> Errno { super::path_filestat_get::(ctx, fd, flags, path, path_len, buf) } pub(crate) fn path_filestat_set_times( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - flags: __wasi_lookupflags_t, + fd: Fd, + flags: LookupFlags, path: WasmPtr, path_len: MemoryOffset, - st_atim: __wasi_timestamp_t, - st_mtim: __wasi_timestamp_t, - fst_flags: __wasi_fstflags_t, -) -> __wasi_errno_t { + st_atim: Timestamp, + st_mtim: Timestamp, + fst_flags: Fstflags, +) -> Errno { super::path_filestat_set_times::( ctx, fd, flags, path, path_len, st_atim, st_mtim, fst_flags, ) @@ -270,14 +268,14 @@ pub(crate) fn path_filestat_set_times( pub(crate) fn path_link( ctx: FunctionEnvMut, - old_fd: __wasi_fd_t, - old_flags: __wasi_lookupflags_t, + old_fd: Fd, + old_flags: LookupFlags, old_path: WasmPtr, old_path_len: MemoryOffset, - new_fd: __wasi_fd_t, + new_fd: Fd, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::path_link::( ctx, old_fd, @@ -292,16 +290,16 @@ pub(crate) fn path_link( pub(crate) fn path_open( ctx: FunctionEnvMut, - dirfd: __wasi_fd_t, - dirflags: __wasi_lookupflags_t, + dirfd: Fd, + dirflags: LookupFlags, path: WasmPtr, path_len: MemoryOffset, - o_flags: __wasi_oflags_t, - fs_rights_base: __wasi_rights_t, - fs_rights_inheriting: __wasi_rights_t, - fs_flags: __wasi_fdflags_t, - fd: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { + o_flags: Oflags, + fs_rights_base: Rights, + fs_rights_inheriting: Rights, + fs_flags: Fdflags, + fd: WasmPtr, +) -> Errno { super::path_open::( ctx, dirfd, @@ -318,34 +316,34 @@ pub(crate) fn path_open( pub(crate) fn path_readlink( ctx: FunctionEnvMut, - dir_fd: __wasi_fd_t, + dir_fd: Fd, path: WasmPtr, path_len: MemoryOffset, buf: WasmPtr, buf_len: MemoryOffset, buf_used: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::path_readlink::(ctx, dir_fd, path, path_len, buf, buf_len, buf_used) } pub(crate) fn path_remove_directory( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: Fd, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::path_remove_directory::(ctx, fd, path, path_len) } pub(crate) fn path_rename( ctx: FunctionEnvMut, - old_fd: __wasi_fd_t, + old_fd: Fd, old_path: WasmPtr, old_path_len: MemoryOffset, - new_fd: __wasi_fd_t, + new_fd: Fd, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::path_rename::( ctx, old_fd, @@ -361,29 +359,29 @@ pub(crate) fn path_symlink( ctx: FunctionEnvMut, old_path: WasmPtr, old_path_len: MemoryOffset, - fd: __wasi_fd_t, + fd: Fd, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::path_symlink::(ctx, old_path, old_path_len, fd, new_path, new_path_len) } pub(crate) fn path_unlink_file( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: Fd, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::path_unlink_file::(ctx, fd, path, path_len) } pub(crate) fn poll_oneoff( ctx: FunctionEnvMut, - in_: WasmPtr<__wasi_subscription_t, MemoryType>, - out_: WasmPtr<__wasi_event_t, MemoryType>, + in_: WasmPtr, + out_: WasmPtr, nsubscriptions: MemoryOffset, nevents: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::poll_oneoff::(ctx, in_, out_, nsubscriptions, nevents) } @@ -394,7 +392,7 @@ pub(crate) fn proc_exit( super::proc_exit(ctx, code) } -pub(crate) fn proc_raise(ctx: FunctionEnvMut, sig: __wasi_signal_t) -> __wasi_errno_t { +pub(crate) fn proc_raise(ctx: FunctionEnvMut, sig: Signal) -> Errno { super::proc_raise(ctx, sig) } @@ -402,46 +400,40 @@ pub(crate) fn random_get( ctx: FunctionEnvMut, buf: WasmPtr, buf_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::random_get::(ctx, buf, buf_len) } pub(crate) fn fd_dup( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - ret_fd: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { + fd: Fd, + ret_fd: WasmPtr, +) -> Errno { super::fd_dup::(ctx, fd, ret_fd) } pub(crate) fn fd_event( ctx: FunctionEnvMut, initial_val: u64, - flags: __wasi_eventfdflags, - ret_fd: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { + flags: EventFdFlags, + ret_fd: WasmPtr, +) -> Errno { super::fd_event(ctx, initial_val, flags, ret_fd) } pub(crate) fn fd_pipe( ctx: FunctionEnvMut, - ro_fd1: WasmPtr<__wasi_fd_t, MemoryType>, - ro_fd2: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { + ro_fd1: WasmPtr, + ro_fd2: WasmPtr, +) -> Errno { super::fd_pipe::(ctx, ro_fd1, ro_fd2) } -pub(crate) fn tty_get( - ctx: FunctionEnvMut, - tty_state: WasmPtr<__wasi_tty_t, MemoryType>, -) -> __wasi_errno_t { +pub(crate) fn tty_get(ctx: FunctionEnvMut, tty_state: WasmPtr) -> Errno { super::tty_get::(ctx, tty_state) } -pub(crate) fn tty_set( - ctx: FunctionEnvMut, - tty_state: WasmPtr<__wasi_tty_t, MemoryType>, -) -> __wasi_errno_t { +pub(crate) fn tty_set(ctx: FunctionEnvMut, tty_state: WasmPtr) -> Errno { super::tty_set::(ctx, tty_state) } @@ -449,7 +441,7 @@ pub(crate) fn getcwd( ctx: FunctionEnvMut, path: WasmPtr, path_len: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::getcwd::(ctx, path, path_len) } @@ -457,7 +449,7 @@ pub(crate) fn chdir( ctx: FunctionEnvMut, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> Errno { super::chdir::(ctx, path, path_len) } @@ -466,55 +458,46 @@ pub(crate) fn thread_spawn( method: WasmPtr, method_len: MemoryOffset, user_data: u64, - reactor: __wasi_bool_t, - ret_tid: WasmPtr<__wasi_tid_t, MemoryType>, -) -> __wasi_errno_t { + reactor: Bool, + ret_tid: WasmPtr, +) -> Errno { super::thread_spawn::(ctx, method, method_len, user_data, reactor, ret_tid) } pub(crate) fn thread_sleep( ctx: FunctionEnvMut, - duration: __wasi_timestamp_t, -) -> Result<__wasi_errno_t, WasiError> { + duration: Timestamp, +) -> Result { super::thread_sleep(ctx, duration) } -pub(crate) fn thread_id( - ctx: FunctionEnvMut, - ret_tid: WasmPtr<__wasi_tid_t, MemoryType>, -) -> __wasi_errno_t { +pub(crate) fn thread_id(ctx: FunctionEnvMut, ret_tid: WasmPtr) -> Errno { super::thread_id::(ctx, ret_tid) } -pub(crate) fn thread_join( - ctx: FunctionEnvMut, - tid: __wasi_tid_t, -) -> Result<__wasi_errno_t, WasiError> { +pub(crate) fn thread_join(ctx: FunctionEnvMut, tid: Tid) -> Result { super::thread_join(ctx, tid) } pub(crate) fn thread_parallelism( ctx: FunctionEnvMut, ret_parallelism: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::thread_parallelism::(ctx, ret_parallelism) } pub(crate) fn thread_exit( ctx: FunctionEnvMut, exitcode: __wasi_exitcode_t, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::thread_exit(ctx, exitcode) } -pub(crate) fn sched_yield(ctx: FunctionEnvMut) -> Result<__wasi_errno_t, WasiError> { +pub(crate) fn sched_yield(ctx: FunctionEnvMut) -> Result { super::sched_yield(ctx) } -pub(crate) fn getpid( - ctx: FunctionEnvMut, - ret_pid: WasmPtr<__wasi_pid_t, MemoryType>, -) -> __wasi_errno_t { +pub(crate) fn getpid(ctx: FunctionEnvMut, ret_pid: WasmPtr) -> Errno { super::getpid::(ctx, ret_pid) } @@ -522,18 +505,18 @@ pub(crate) fn process_spawn( ctx: FunctionEnvMut, name: WasmPtr, name_len: MemoryOffset, - chroot: __wasi_bool_t, + chroot: Bool, args: WasmPtr, args_len: MemoryOffset, preopen: WasmPtr, preopen_len: MemoryOffset, - stdin: __wasi_stdiomode_t, - stdout: __wasi_stdiomode_t, - stderr: __wasi_stdiomode_t, + stdin: StdioMode, + stdout: StdioMode, + stderr: StdioMode, working_dir: WasmPtr, working_dir_len: MemoryOffset, - ret_handles: WasmPtr<__wasi_bus_handles_t, MemoryType>, -) -> __bus_errno_t { + ret_handles: WasmPtr, +) -> BusErrno { super::process_spawn::( ctx, name, @@ -556,9 +539,9 @@ pub(crate) fn bus_open_local( ctx: FunctionEnvMut, name: WasmPtr, name_len: MemoryOffset, - reuse: __wasi_bool_t, - ret_bid: WasmPtr<__wasi_bid_t, MemoryType>, -) -> __bus_errno_t { + reuse: Bool, + ret_bid: WasmPtr, +) -> BusErrno { super::bus_open_local::(ctx, name, name_len, reuse, ret_bid) } @@ -566,13 +549,13 @@ pub(crate) fn bus_open_remote( ctx: FunctionEnvMut, name: WasmPtr, name_len: MemoryOffset, - reuse: __wasi_bool_t, + reuse: Bool, instance: WasmPtr, instance_len: MemoryOffset, token: WasmPtr, token_len: MemoryOffset, - ret_bid: WasmPtr<__wasi_bid_t, MemoryType>, -) -> __bus_errno_t { + ret_bid: WasmPtr, +) -> BusErrno { super::bus_open_remote::( ctx, name, @@ -586,21 +569,21 @@ pub(crate) fn bus_open_remote( ) } -pub(crate) fn bus_close(ctx: FunctionEnvMut, bid: __wasi_bid_t) -> __bus_errno_t { +pub(crate) fn bus_close(ctx: FunctionEnvMut, bid: Bid) -> BusErrno { super::bus_close(ctx, bid) } pub(crate) fn bus_call( ctx: FunctionEnvMut, - bid: __wasi_bid_t, - keep_alive: __wasi_bool_t, + bid: Bid, + keep_alive: Bool, topic: WasmPtr, topic_len: MemoryOffset, - format: __wasi_busdataformat_t, + format: BusDataFormat, buf: WasmPtr, buf_len: MemoryOffset, - ret_cid: WasmPtr<__wasi_cid_t, MemoryType>, -) -> __bus_errno_t { + ret_cid: WasmPtr, +) -> BusErrno { super::bus_call::( ctx, bid, keep_alive, topic, topic_len, format, buf, buf_len, ret_cid, ) @@ -608,15 +591,15 @@ pub(crate) fn bus_call( pub(crate) fn bus_subcall( ctx: FunctionEnvMut, - parent: __wasi_cid_t, - keep_alive: __wasi_bool_t, + parent: Cid, + keep_alive: Bool, topic: WasmPtr, topic_len: MemoryOffset, - format: __wasi_busdataformat_t, + format: BusDataFormat, buf: WasmPtr, buf_len: MemoryOffset, - ret_cid: WasmPtr<__wasi_cid_t, MemoryType>, -) -> __bus_errno_t { + ret_cid: WasmPtr, +) -> BusErrno { super::bus_subcall::( ctx, parent, keep_alive, topic, topic_len, format, buf, buf_len, ret_cid, ) @@ -624,13 +607,13 @@ pub(crate) fn bus_subcall( pub(crate) fn bus_poll( ctx: FunctionEnvMut, - timeout: __wasi_timestamp_t, + timeout: Timestamp, events: WasmPtr, nevents: MemoryOffset, malloc: WasmPtr, malloc_len: MemoryOffset, ret_nevents: WasmPtr, -) -> __bus_errno_t { +) -> BusErrno { super::bus_poll::( ctx, timeout, @@ -644,23 +627,19 @@ pub(crate) fn bus_poll( pub(crate) fn call_reply( ctx: FunctionEnvMut, - cid: __wasi_cid_t, - format: __wasi_busdataformat_t, + cid: Cid, + format: BusDataFormat, buf: WasmPtr, buf_len: MemoryOffset, -) -> __bus_errno_t { +) -> BusErrno { super::call_reply::(ctx, cid, format, buf, buf_len) } -pub(crate) fn call_fault( - ctx: FunctionEnvMut, - cid: __wasi_cid_t, - fault: __bus_errno_t, -) -> __bus_errno_t { +pub(crate) fn call_fault(ctx: FunctionEnvMut, cid: Cid, fault: BusErrno) -> BusErrno { super::call_fault(ctx, cid, fault) } -pub(crate) fn call_close(ctx: FunctionEnvMut, cid: __wasi_cid_t) -> __bus_errno_t { +pub(crate) fn call_close(ctx: FunctionEnvMut, cid: Cid) -> BusErrno { super::call_close(ctx, cid) } @@ -670,34 +649,34 @@ pub(crate) fn port_bridge( network_len: MemoryOffset, token: WasmPtr, token_len: MemoryOffset, - security: __wasi_streamsecurity_t, -) -> __wasi_errno_t { + security: Streamsecurity, +) -> Errno { super::port_bridge::(ctx, network, network_len, token, token_len, security) } -pub(crate) fn port_unbridge(ctx: FunctionEnvMut) -> __wasi_errno_t { +pub(crate) fn port_unbridge(ctx: FunctionEnvMut) -> Errno { super::port_unbridge(ctx) } -pub(crate) fn port_dhcp_acquire(ctx: FunctionEnvMut) -> __wasi_errno_t { +pub(crate) fn port_dhcp_acquire(ctx: FunctionEnvMut) -> Errno { super::port_dhcp_acquire(ctx) } pub(crate) fn port_addr_add( ctx: FunctionEnvMut, addr: WasmPtr<__wasi_cidr_t, MemoryType>, -) -> __wasi_errno_t { +) -> Errno { super::port_addr_add::(ctx, addr) } pub(crate) fn port_addr_remove( ctx: FunctionEnvMut, addr: WasmPtr<__wasi_addr_t, MemoryType>, -) -> __wasi_errno_t { +) -> Errno { super::port_addr_remove::(ctx, addr) } -pub(crate) fn port_addr_clear(ctx: FunctionEnvMut) -> __wasi_errno_t { +pub(crate) fn port_addr_clear(ctx: FunctionEnvMut) -> Errno { super::port_addr_clear(ctx) } @@ -705,21 +684,21 @@ pub(crate) fn port_addr_list( ctx: FunctionEnvMut, addrs: WasmPtr<__wasi_cidr_t, MemoryType>, naddrs: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::port_addr_list::(ctx, addrs, naddrs) } pub(crate) fn port_mac( ctx: FunctionEnvMut, ret_mac: WasmPtr<__wasi_hardwareaddress_t, MemoryType>, -) -> __wasi_errno_t { +) -> Errno { super::port_mac::(ctx, ret_mac) } pub(crate) fn port_gateway_set( ctx: FunctionEnvMut, ip: WasmPtr<__wasi_addr_t, MemoryType>, -) -> __wasi_errno_t { +) -> Errno { super::port_gateway_set::(ctx, ip) } @@ -727,28 +706,28 @@ pub(crate) fn port_route_add( ctx: FunctionEnvMut, cidr: WasmPtr<__wasi_cidr_t, MemoryType>, via_router: WasmPtr<__wasi_addr_t, MemoryType>, - preferred_until: WasmPtr<__wasi_option_timestamp_t, MemoryType>, - expires_at: WasmPtr<__wasi_option_timestamp_t, MemoryType>, -) -> __wasi_errno_t { + preferred_until: WasmPtr, + expires_at: WasmPtr, +) -> Errno { super::port_route_add::(ctx, cidr, via_router, preferred_until, expires_at) } pub(crate) fn port_route_remove( ctx: FunctionEnvMut, ip: WasmPtr<__wasi_addr_t, MemoryType>, -) -> __wasi_errno_t { +) -> Errno { super::port_route_remove::(ctx, ip) } -pub(crate) fn port_route_clear(ctx: FunctionEnvMut) -> __wasi_errno_t { +pub(crate) fn port_route_clear(ctx: FunctionEnvMut) -> Errno { super::port_route_clear(ctx) } pub(crate) fn port_route_list( ctx: FunctionEnvMut, - routes: WasmPtr<__wasi_route_t, MemoryType>, + routes: WasmPtr, nroutes: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::port_route_list::(ctx, routes, nroutes) } @@ -756,8 +735,8 @@ pub(crate) fn ws_connect( ctx: FunctionEnvMut, url: WasmPtr, url_len: MemoryOffset, - ret_sock: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { + ret_sock: WasmPtr, +) -> Errno { super::ws_connect::(ctx, url, url_len, ret_sock) } @@ -769,9 +748,9 @@ pub(crate) fn http_request( method_len: MemoryOffset, headers: WasmPtr, headers_len: MemoryOffset, - gzip: __wasi_bool_t, - ret_handles: WasmPtr<__wasi_http_handles_t, MemoryType>, -) -> __wasi_errno_t { + gzip: Bool, + ret_handles: WasmPtr, +) -> Errno { super::http_request::( ctx, url, @@ -787,183 +766,179 @@ pub(crate) fn http_request( pub(crate) fn http_status( ctx: FunctionEnvMut, - sock: __wasi_fd_t, - status: WasmPtr<__wasi_http_status_t, MemoryType>, + sock: Fd, + status: WasmPtr, status_text: WasmPtr, status_text_len: WasmPtr, headers: WasmPtr, headers_len: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::http_status::(ctx, sock, status) } pub(crate) fn sock_status( ctx: FunctionEnvMut, - sock: __wasi_fd_t, - ret_status: WasmPtr<__wasi_sockstatus_t, MemoryType>, -) -> __wasi_errno_t { + sock: Fd, + ret_status: WasmPtr, +) -> Errno { super::sock_status::(ctx, sock, ret_status) } pub(crate) fn sock_addr_local( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: Fd, ret_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> __wasi_errno_t { +) -> Errno { super::sock_addr_local::(ctx, sock, ret_addr) } pub(crate) fn sock_addr_peer( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: Fd, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> __wasi_errno_t { +) -> Errno { super::sock_addr_peer::(ctx, sock, ro_addr) } pub(crate) fn sock_open( ctx: FunctionEnvMut, - af: __wasi_addressfamily_t, - ty: __wasi_socktype_t, - pt: __wasi_sockproto_t, - ro_sock: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { + af: Addressfamily, + ty: Socktype, + pt: SockProto, + ro_sock: WasmPtr, +) -> Errno { super::sock_open::(ctx, af, ty, pt, ro_sock) } pub(crate) fn sock_set_opt_flag( ctx: FunctionEnvMut, - sock: __wasi_fd_t, - opt: __wasi_sockoption_t, - flag: __wasi_bool_t, -) -> __wasi_errno_t { + sock: Fd, + opt: Sockoption, + flag: Bool, +) -> Errno { super::sock_set_opt_flag(ctx, sock, opt, flag) } pub(crate) fn sock_get_opt_flag( ctx: FunctionEnvMut, - sock: __wasi_fd_t, - opt: __wasi_sockoption_t, - ret_flag: WasmPtr<__wasi_bool_t, MemoryType>, -) -> __wasi_errno_t { + sock: Fd, + opt: Sockoption, + ret_flag: WasmPtr, +) -> Errno { super::sock_get_opt_flag::(ctx, sock, opt, ret_flag) } pub fn sock_set_opt_time( ctx: FunctionEnvMut, - sock: __wasi_fd_t, - opt: __wasi_sockoption_t, - time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, -) -> __wasi_errno_t { + sock: Fd, + opt: Sockoption, + time: WasmPtr, +) -> Errno { super::sock_set_opt_time(ctx, sock, opt, time) } pub fn sock_get_opt_time( ctx: FunctionEnvMut, - sock: __wasi_fd_t, - opt: __wasi_sockoption_t, - ret_time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, -) -> __wasi_errno_t { + sock: Fd, + opt: Sockoption, + ret_time: WasmPtr, +) -> Errno { super::sock_get_opt_time(ctx, sock, opt, ret_time) } pub fn sock_set_opt_size( ctx: FunctionEnvMut, - sock: __wasi_fd_t, - opt: __wasi_sockoption_t, - size: __wasi_filesize_t, -) -> __wasi_errno_t { + sock: Fd, + opt: Sockoption, + size: Filesize, +) -> Errno { super::sock_set_opt_size(ctx, sock, opt, size) } pub fn sock_get_opt_size( ctx: FunctionEnvMut, - sock: __wasi_fd_t, - opt: __wasi_sockoption_t, - ret_size: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> __wasi_errno_t { + sock: Fd, + opt: Sockoption, + ret_size: WasmPtr, +) -> Errno { super::sock_get_opt_size(ctx, sock, opt, ret_size) } pub(crate) fn sock_join_multicast_v4( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: Fd, multiaddr: WasmPtr<__wasi_addr_ip4_t, MemoryType>, iface: WasmPtr<__wasi_addr_ip4_t, MemoryType>, -) -> __wasi_errno_t { +) -> Errno { super::sock_join_multicast_v4::(ctx, sock, multiaddr, iface) } pub(crate) fn sock_leave_multicast_v4( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: Fd, multiaddr: WasmPtr<__wasi_addr_ip4_t, MemoryType>, iface: WasmPtr<__wasi_addr_ip4_t, MemoryType>, -) -> __wasi_errno_t { +) -> Errno { super::sock_leave_multicast_v4::(ctx, sock, multiaddr, iface) } pub(crate) fn sock_join_multicast_v6( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: Fd, multiaddr: WasmPtr<__wasi_addr_ip6_t, MemoryType>, iface: u32, -) -> __wasi_errno_t { +) -> Errno { super::sock_join_multicast_v6::(ctx, sock, multiaddr, iface) } pub(crate) fn sock_leave_multicast_v6( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: Fd, multiaddr: WasmPtr<__wasi_addr_ip6_t, MemoryType>, iface: u32, -) -> __wasi_errno_t { +) -> Errno { super::sock_leave_multicast_v6::(ctx, sock, multiaddr, iface) } pub(crate) fn sock_bind( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: Fd, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> __wasi_errno_t { +) -> Errno { super::sock_bind::(ctx, sock, addr) } -pub(crate) fn sock_listen( - ctx: FunctionEnvMut, - sock: __wasi_fd_t, - backlog: MemoryOffset, -) -> __wasi_errno_t { +pub(crate) fn sock_listen(ctx: FunctionEnvMut, sock: Fd, backlog: MemoryOffset) -> Errno { super::sock_listen::(ctx, sock, backlog) } pub(crate) fn sock_accept( ctx: FunctionEnvMut, - sock: __wasi_fd_t, - fd_flags: __wasi_fdflags_t, - ro_fd: WasmPtr<__wasi_fd_t, MemoryType>, + sock: Fd, + fd_flags: Fdflags, + ro_fd: WasmPtr, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::sock_accept::(ctx, sock, fd_flags, ro_fd, ro_addr) } pub(crate) fn sock_connect( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: Fd, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> __wasi_errno_t { +) -> Errno { super::sock_connect::(ctx, sock, addr) } pub(crate) fn sock_recv( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: Fd, ri_data: WasmPtr<__wasi_iovec_t, MemoryType>, ri_data_len: MemoryOffset, - ri_flags: __wasi_riflags_t, + ri_flags: RiFlags, ro_data_len: WasmPtr, - ro_flags: WasmPtr<__wasi_roflags_t, MemoryType>, -) -> Result<__wasi_errno_t, WasiError> { + ro_flags: WasmPtr, +) -> Result { super::sock_recv::( ctx, sock, @@ -977,14 +952,14 @@ pub(crate) fn sock_recv( pub(crate) fn sock_recv_from( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: Fd, ri_data: WasmPtr<__wasi_iovec_t, MemoryType>, ri_data_len: MemoryOffset, - ri_flags: __wasi_riflags_t, + ri_flags: RiFlags, ro_data_len: WasmPtr, - ro_flags: WasmPtr<__wasi_roflags_t, MemoryType>, + ro_flags: WasmPtr, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::sock_recv_from::( ctx, sock, @@ -999,24 +974,24 @@ pub(crate) fn sock_recv_from( pub(crate) fn sock_send( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: Fd, si_data: WasmPtr<__wasi_ciovec_t, MemoryType>, si_data_len: MemoryOffset, - si_flags: __wasi_siflags_t, + si_flags: SiFlags, ret_data_len: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::sock_send::(ctx, sock, si_data, si_data_len, si_flags, ret_data_len) } pub(crate) fn sock_send_to( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: Fd, si_data: WasmPtr<__wasi_ciovec_t, MemoryType>, si_data_len: MemoryOffset, - si_flags: __wasi_siflags_t, + si_flags: SiFlags, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ret_data_len: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::sock_send_to::( ctx, sock, @@ -1030,20 +1005,16 @@ pub(crate) fn sock_send_to( pub(crate) fn sock_send_file( ctx: FunctionEnvMut, - out_fd: __wasi_fd_t, - in_fd: __wasi_fd_t, - offset: __wasi_filesize_t, - count: __wasi_filesize_t, - ret_sent: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> Result<__wasi_errno_t, WasiError> { + out_fd: Fd, + in_fd: Fd, + offset: Filesize, + count: Filesize, + ret_sent: WasmPtr, +) -> Result { unsafe { super::sock_send_file::(ctx, out_fd, in_fd, offset, count, ret_sent) } } -pub(crate) fn sock_shutdown( - ctx: FunctionEnvMut, - sock: __wasi_fd_t, - how: __wasi_sdflags_t, -) -> __wasi_errno_t { +pub(crate) fn sock_shutdown(ctx: FunctionEnvMut, sock: Fd, how: SdFlags) -> Errno { super::sock_shutdown(ctx, sock, how) } @@ -1055,6 +1026,6 @@ pub(crate) fn resolve( ips: WasmPtr<__wasi_addr_t, MemoryType>, nips: MemoryOffset, ret_nips: WasmPtr, -) -> __wasi_errno_t { +) -> Errno { super::resolve::(ctx, host, host_len, port, ips, nips, ret_nips) } diff --git a/lib/wasi/src/syscalls/wasm32.rs b/lib/wasi/src/syscalls/wasm32.rs index d9f56ac85c1..2796eca5e7d 100644 --- a/lib/wasi/src/syscalls/wasm32.rs +++ b/lib/wasi/src/syscalls/wasm32.rs @@ -1,26 +1,29 @@ -use crate::syscalls::types::*; +use crate::syscalls::types::{ + wasi::{Errno, Snapshot0Clockid, Timestamp}, + *, +}; use chrono::prelude::*; use std::mem; use wasmer::WasmRef; pub fn platform_clock_res_get( - clock_id: __wasi_clockid_t, - resolution: WasmRef<__wasi_timestamp_t>, -) -> Result { + clock_id: Snapshot0Clockid, + resolution: WasmRef, +) -> Result { let t_out = match clock_id { - __WASI_CLOCK_MONOTONIC => 10_000_000, - __WASI_CLOCK_REALTIME => 1, - __WASI_CLOCK_PROCESS_CPUTIME_ID => 1, - __WASI_CLOCK_THREAD_CPUTIME_ID => 1, - _ => return Err(__WASI_EINVAL), + Snapshot0Clockid::Monotonic => 10_000_000, + Snapshot0Clockid::Realtime => 1, + Snapshot0Clockid::ProcessCputimeId => 1, + Snapshot0Clockid::ThreadCputimeId => 1, + _ => return Err(Errno::Inval), }; Ok(t_out) } pub fn platform_clock_time_get( - clock_id: __wasi_clockid_t, - precision: __wasi_timestamp_t, -) -> Result { + clock_id: Snapshot0Clockid, + precision: Timestamp, +) -> Result { let new_time: DateTime = Local::now(); Ok(new_time.timestamp_nanos() as i64) } diff --git a/lib/wasi/src/syscalls/windows.rs b/lib/wasi/src/syscalls/windows.rs index c461fa44ca8..656c70a4242 100644 --- a/lib/wasi/src/syscalls/windows.rs +++ b/lib/wasi/src/syscalls/windows.rs @@ -1,53 +1,53 @@ -use crate::syscalls::types::*; +use crate::syscalls::types::wasi::{self, Timestamp}; use tracing::debug; use wasmer::WasmRef; pub fn platform_clock_res_get( - clock_id: __wasi_clockid_t, - resolution: WasmRef<__wasi_timestamp_t>, -) -> Result { + clock_id: wasi::Snapshot0Clockid, + resolution: WasmRef, +) -> Result { let resolution_val = match clock_id { // resolution of monotonic clock at 10ms, from: // https://docs.microsoft.com/en-us/windows/desktop/api/sysinfoapi/nf-sysinfoapi-gettickcount64 - __WASI_CLOCK_MONOTONIC => 10_000_000, + wasi::Snapshot0Clockid::Monotonic => 10_000_000, // TODO: verify or compute this - __WASI_CLOCK_REALTIME => 1, - __WASI_CLOCK_PROCESS_CPUTIME_ID => { - return Err(__WASI_EINVAL); + wasi::Snapshot0Clockid::Realtime => 1, + wasi::Snapshot0Clockid::ProcessCputimeId => { + return Err(wasi::Errno::Inval); } - __WASI_CLOCK_THREAD_CPUTIME_ID => { - return Err(__WASI_EINVAL); + wasi::Snapshot0Clockid::ThreadCputimeId => { + return Err(wasi::Errno::Inval); } - _ => return Err(__WASI_EINVAL), + _ => return Err(wasi::Errno::Inval), }; Ok(resolution_val) } pub fn platform_clock_time_get( - clock_id: __wasi_clockid_t, - precision: __wasi_timestamp_t, -) -> Result { + clock_id: wasi::Snapshot0Clockid, + precision: Timestamp, +) -> Result { let nanos = match clock_id { - __WASI_CLOCK_MONOTONIC => { + wasi::Snapshot0Clockid::Monotonic => { let tick_ms = unsafe { winapi::um::sysinfoapi::GetTickCount64() }; tick_ms * 1_000_000 } - __WASI_CLOCK_REALTIME => { + wasi::Snapshot0Clockid::Realtime => { let duration = std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) .map_err(|e| { debug!("Error in wasi::platform_clock_time_get: {:?}", e); - __WASI_EIO + wasi::Errno::Io })?; duration.as_nanos() as u64 } - __WASI_CLOCK_PROCESS_CPUTIME_ID => { - unimplemented!("wasi::platform_clock_time_get(__WASI_CLOCK_PROCESS_CPUTIME_ID, ..)") + wasi::Snapshot0Clockid::ProcessCputimeId => { + unimplemented!("wasi::platform_clock_time_get(wasi::Clockid::ProcessCputimeId, ..)") } - __WASI_CLOCK_THREAD_CPUTIME_ID => { - unimplemented!("wasi::platform_clock_time_get(__WASI_CLOCK_THREAD_CPUTIME_ID, ..)") + wasi::Snapshot0Clockid::ThreadCputimeId => { + unimplemented!("wasi::platform_clock_time_get(wasi::Clockid::ThreadCputimeId, ..)") } - _ => return Err(__WASI_EINVAL), + _ => return Err(wasi::Errno::Inval), }; Ok(nanos as i64) } diff --git a/lib/wasi/src/utils.rs b/lib/wasi/src/utils.rs index 0fbc5c221c6..571a954fc38 100644 --- a/lib/wasi/src/utils.rs +++ b/lib/wasi/src/utils.rs @@ -1,6 +1,6 @@ -use super::types::*; use std::collections::BTreeSet; use wasmer::Module; +use wasmer_wasi_types::wasi::Errno; #[allow(dead_code)] /// Check if a provided module is compiled for some version of WASI. @@ -22,29 +22,29 @@ pub fn is_wasix_module(module: &Module) -> bool { } } -pub fn map_io_err(err: std::io::Error) -> __wasi_errno_t { +pub fn map_io_err(err: std::io::Error) -> Errno { use std::io::ErrorKind; match err.kind() { - ErrorKind::NotFound => __WASI_ENOENT, - ErrorKind::PermissionDenied => __WASI_EPERM, - ErrorKind::ConnectionRefused => __WASI_ECONNREFUSED, - ErrorKind::ConnectionReset => __WASI_ECONNRESET, - ErrorKind::ConnectionAborted => __WASI_ECONNABORTED, - ErrorKind::NotConnected => __WASI_ENOTCONN, - ErrorKind::AddrInUse => __WASI_EADDRINUSE, - ErrorKind::AddrNotAvailable => __WASI_EADDRNOTAVAIL, - ErrorKind::BrokenPipe => __WASI_EPIPE, - ErrorKind::AlreadyExists => __WASI_EEXIST, - ErrorKind::WouldBlock => __WASI_EAGAIN, - ErrorKind::InvalidInput => __WASI_EIO, - ErrorKind::InvalidData => __WASI_EIO, - ErrorKind::TimedOut => __WASI_ETIMEDOUT, - ErrorKind::WriteZero => __WASI_EIO, - ErrorKind::Interrupted => __WASI_EINTR, - ErrorKind::Other => __WASI_EIO, - ErrorKind::UnexpectedEof => __WASI_EIO, - ErrorKind::Unsupported => __WASI_ENOTSUP, - _ => __WASI_EIO, + ErrorKind::NotFound => Errno::Noent, + ErrorKind::PermissionDenied => Errno::Perm, + ErrorKind::ConnectionRefused => Errno::Connrefused, + ErrorKind::ConnectionReset => Errno::Connreset, + ErrorKind::ConnectionAborted => Errno::Connaborted, + ErrorKind::NotConnected => Errno::Notconn, + ErrorKind::AddrInUse => Errno::Addrinuse, + ErrorKind::AddrNotAvailable => Errno::Addrnotavail, + ErrorKind::BrokenPipe => Errno::Pipe, + ErrorKind::AlreadyExists => Errno::Exist, + ErrorKind::WouldBlock => Errno::Again, + ErrorKind::InvalidInput => Errno::Io, + ErrorKind::InvalidData => Errno::Io, + ErrorKind::TimedOut => Errno::Timedout, + ErrorKind::WriteZero => Errno::Io, + ErrorKind::Interrupted => Errno::Intr, + ErrorKind::Other => Errno::Io, + ErrorKind::UnexpectedEof => Errno::Io, + ErrorKind::Unsupported => Errno::Notsup, + _ => Errno::Io, } } diff --git a/tests/lib/wast/src/wasi_wast.rs b/tests/lib/wast/src/wasi_wast.rs index 6b2e13aac4c..e31993deb0f 100644 --- a/tests/lib/wast/src/wasi_wast.rs +++ b/tests/lib/wast/src/wasi_wast.rs @@ -3,10 +3,9 @@ use std::fs::{read_dir, File, OpenOptions, ReadDir}; use std::io::{self, Read, Seek, Write}; use std::path::{Path, PathBuf}; use std::sync::{mpsc, Arc, Mutex}; -use wasmer::FunctionEnv; -use wasmer::{Imports, Instance, Module, Store}; +use wasmer::{FunctionEnv, Imports, Instance, Module, Store}; use wasmer_vfs::{host_fs, mem_fs, FileSystem}; -use wasmer_wasi::types::{__wasi_filesize_t, __wasi_timestamp_t}; +use wasmer_wasi::types::wasi::{Filesize, Timestamp}; use wasmer_wasi::{ generate_import_object_from_env, get_wasi_version, FsError, Pipe, VirtualFile, WasiEnv, WasiFunctionEnv, WasiState, WasiVersion, @@ -614,19 +613,19 @@ impl Write for OutputCapturerer { } impl VirtualFile for OutputCapturerer { - fn last_accessed(&self) -> __wasi_timestamp_t { + fn last_accessed(&self) -> Timestamp { 0 } - fn last_modified(&self) -> __wasi_timestamp_t { + fn last_modified(&self) -> Timestamp { 0 } - fn created_time(&self) -> __wasi_timestamp_t { + fn created_time(&self) -> Timestamp { 0 } fn size(&self) -> u64 { 0 } - fn set_len(&mut self, _new_size: __wasi_filesize_t) -> Result<(), FsError> { + fn set_len(&mut self, _new_size: Filesize) -> Result<(), FsError> { Ok(()) } fn unlink(&mut self) -> Result<(), FsError> {