From e33496b3aa93f19f54b3e8093fbdab82fd7c2cf0 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Wed, 10 Aug 2022 09:39:42 +0200 Subject: [PATCH 01/84] WIP --- Cargo.lock | 333 +++++-- Cargo.toml | 1 + lib/wasi-types-generated/Cargo.toml | 14 + lib/wasi-types-generated/src/bindings.rs | 809 ++++++++++++++++++ lib/wasi-types-generated/src/lib.rs | 1 + .../wit/wasi-filesystem.wit | 626 ++++++++++++++ 6 files changed, 1736 insertions(+), 48 deletions(-) create mode 100644 lib/wasi-types-generated/Cargo.toml create mode 100644 lib/wasi-types-generated/src/bindings.rs create mode 100644 lib/wasi-types-generated/src/lib.rs create mode 100644 lib/wasi-types-generated/wit/wasi-filesystem.wit diff --git a/Cargo.lock b/Cargo.lock index 9328944bd83..8020f257a28 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -271,7 +271,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6358dedf60f4d9b8db43ad187391afe959746101346fe51bb978126bec61dfb" dependencies = [ "clap 3.2.16", - "heck", + "heck 0.4.0", "indexmap", "log", "proc-macro2", @@ -372,7 +372,7 @@ version = "3.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ba52acd3b0a5c33aeada5cdaa3267cdc7c594a98731d4268cdc1532f4264cb4" dependencies = [ - "heck", + "heck 0.4.0", "proc-macro-error", "proc-macro2", "quote", @@ -1123,6 +1123,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" @@ -1162,6 +1171,12 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[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" @@ -1785,6 +1800,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" @@ -2577,6 +2603,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" @@ -2711,12 +2752,33 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" +[[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.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" + [[package]] name = "unicode-width" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" +[[package]] +name = "unicode-xid" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" + [[package]] name = "unix_mode" version = "0.1.3" @@ -2785,6 +2847,13 @@ dependencies = [ "wast 24.0.0", ] +[[package]] +name = "wasi-types-generated" +version = "0.1.0" +dependencies = [ + "wit-bindgen-wasmer", +] + [[package]] name = "wasm-bindgen" version = "0.2.82" @@ -2921,18 +2990,39 @@ dependencies = [ "tracing", "wasm-bindgen", "wasm-bindgen-test", - "wasmer-compiler", - "wasmer-compiler-cranelift", + "wasmer-compiler 3.0.0-beta", + "wasmer-compiler-cranelift 3.0.0-beta", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", - "wasmer-derive", - "wasmer-types", - "wasmer-vm", + "wasmer-derive 3.0.0-beta", + "wasmer-types 3.0.0-beta", + "wasmer-vm 3.0.0-beta", "wasmparser 0.83.0", "wat", "winapi", ] +[[package]] +name = "wasmer" +version = "3.0.0-beta" +source = "git+https://github.com/wasmerio/wasmer.git?branch=master#a6ddf4e23ddbba827673e4068e8ae1b2fed4609e" +dependencies = [ + "cfg-if 1.0.0", + "indexmap", + "js-sys", + "more-asserts", + "target-lexicon 0.12.4", + "thiserror", + "wasm-bindgen", + "wasmer-compiler 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=master)", + "wasmer-compiler-cranelift 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=master)", + "wasmer-derive 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=master)", + "wasmer-types 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=master)", + "wasmer-vm 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=master)", + "wat", + "winapi", +] + [[package]] name = "wasmer-bin-fuzz" version = "0.0.0" @@ -2940,9 +3030,9 @@ dependencies = [ "anyhow", "libfuzzer-sys", "wasm-smith", - "wasmer", - "wasmer-compiler", - "wasmer-compiler-cranelift", + "wasmer 3.0.0-beta", + "wasmer-compiler 3.0.0-beta", + "wasmer-compiler-cranelift 3.0.0-beta", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-middlewares", @@ -2963,14 +3053,14 @@ dependencies = [ "paste", "thiserror", "typetag", - "wasmer", - "wasmer-compiler", - "wasmer-compiler-cranelift", + "wasmer 3.0.0-beta", + "wasmer-compiler 3.0.0-beta", + "wasmer-compiler-cranelift 3.0.0-beta", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-emscripten", "wasmer-middlewares", - "wasmer-types", + "wasmer-types 3.0.0-beta", "wasmer-wasi", ] @@ -2984,7 +3074,7 @@ dependencies = [ "rand", "tempfile", "thiserror", - "wasmer", + "wasmer 3.0.0-beta", "wasmer-compiler-singlepass", ] @@ -3007,17 +3097,17 @@ dependencies = [ "target-lexicon 0.12.4", "tempfile", "unix_mode", - "wasmer", + "wasmer 3.0.0-beta", "wasmer-cache", - "wasmer-compiler", - "wasmer-compiler-cranelift", + "wasmer-compiler 3.0.0-beta", + "wasmer-compiler-cranelift 3.0.0-beta", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-emscripten", "wasmer-object", - "wasmer-types", + "wasmer-types 3.0.0-beta", "wasmer-vfs", - "wasmer-vm", + "wasmer-vm 3.0.0-beta", "wasmer-wasi", "wasmer-wasi-experimental-io-devices", "wasmer-wast", @@ -3043,8 +3133,31 @@ dependencies = [ "smallvec", "thiserror", "wasmer-object", - "wasmer-types", - "wasmer-vm", + "wasmer-types 3.0.0-beta", + "wasmer-vm 3.0.0-beta", + "wasmparser 0.83.0", + "winapi", +] + +[[package]] +name = "wasmer-compiler" +version = "3.0.0-beta" +source = "git+https://github.com/wasmerio/wasmer.git?branch=master#a6ddf4e23ddbba827673e4068e8ae1b2fed4609e" +dependencies = [ + "backtrace", + "cfg-if 1.0.0", + "enum-iterator", + "enumset", + "lazy_static", + "leb128", + "memmap2", + "more-asserts", + "region", + "rustc-demangle", + "smallvec", + "thiserror", + "wasmer-types 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=master)", + "wasmer-vm 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=master)", "wasmparser 0.83.0", "winapi", ] @@ -3065,10 +3178,10 @@ dependencies = [ "target-lexicon 0.12.4", "tempfile", "unix_mode", - "wasmer-compiler", - "wasmer-compiler-cranelift", + "wasmer-compiler 3.0.0-beta", + "wasmer-compiler-cranelift 3.0.0-beta", "wasmer-compiler-singlepass", - "wasmer-types", + "wasmer-types 3.0.0-beta", ] [[package]] @@ -3086,8 +3199,26 @@ dependencies = [ "smallvec", "target-lexicon 0.12.4", "tracing", - "wasmer-compiler", - "wasmer-types", + "wasmer-compiler 3.0.0-beta", + "wasmer-types 3.0.0-beta", +] + +[[package]] +name = "wasmer-compiler-cranelift" +version = "3.0.0-beta" +source = "git+https://github.com/wasmerio/wasmer.git?branch=master#a6ddf4e23ddbba827673e4068e8ae1b2fed4609e" +dependencies = [ + "cranelift-codegen", + "cranelift-entity", + "cranelift-frontend", + "gimli", + "more-asserts", + "rayon", + "smallvec", + "target-lexicon 0.12.4", + "tracing", + "wasmer-compiler 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=master)", + "wasmer-types 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=master)", ] [[package]] @@ -3107,9 +3238,9 @@ dependencies = [ "semver 1.0.13", "smallvec", "target-lexicon 0.12.4", - "wasmer-compiler", - "wasmer-types", - "wasmer-vm", + "wasmer-compiler 3.0.0-beta", + "wasmer-types 3.0.0-beta", + "wasmer-vm 3.0.0-beta", ] [[package]] @@ -3126,8 +3257,8 @@ dependencies = [ "rayon", "smallvec", "target-lexicon 0.12.4", - "wasmer-compiler", - "wasmer-types", + "wasmer-compiler 3.0.0-beta", + "wasmer-types 3.0.0-beta", ] [[package]] @@ -3139,7 +3270,18 @@ dependencies = [ "proc-macro2", "quote", "syn", - "wasmer", + "wasmer 3.0.0-beta", +] + +[[package]] +name = "wasmer-derive" +version = "3.0.0-beta" +source = "git+https://github.com/wasmerio/wasmer.git?branch=master#a6ddf4e23ddbba827673e4068e8ae1b2fed4609e" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -3152,8 +3294,8 @@ dependencies = [ "libc", "log", "time", - "wasmer", - "wasmer-types", + "wasmer 3.0.0-beta", + "wasmer-types 3.0.0-beta", ] [[package]] @@ -3173,9 +3315,9 @@ version = "3.0.0-beta" name = "wasmer-middlewares" version = "3.0.0-beta" dependencies = [ - "wasmer", - "wasmer-types", - "wasmer-vm", + "wasmer 3.0.0-beta", + "wasmer-types 3.0.0-beta", + "wasmer-vm 3.0.0-beta", ] [[package]] @@ -3184,7 +3326,7 @@ version = "3.0.0-beta" dependencies = [ "object 0.28.4", "thiserror", - "wasmer-types", + "wasmer-types 3.0.0-beta", ] [[package]] @@ -3202,6 +3344,20 @@ dependencies = [ "thiserror", ] +[[package]] +name = "wasmer-types" +version = "3.0.0-beta" +source = "git+https://github.com/wasmerio/wasmer.git?branch=master#a6ddf4e23ddbba827673e4068e8ae1b2fed4609e" +dependencies = [ + "enum-iterator", + "enumset", + "indexmap", + "more-asserts", + "rkyv", + "target-lexicon 0.12.4", + "thiserror", +] + [[package]] name = "wasmer-vbus" version = "3.0.0-beta" @@ -3245,7 +3401,30 @@ dependencies = [ "scopeguard", "serde", "thiserror", - "wasmer-types", + "wasmer-types 3.0.0-beta", + "winapi", +] + +[[package]] +name = "wasmer-vm" +version = "3.0.0-beta" +source = "git+https://github.com/wasmerio/wasmer.git?branch=master#a6ddf4e23ddbba827673e4068e8ae1b2fed4609e" +dependencies = [ + "backtrace", + "cc", + "cfg-if 1.0.0", + "corosensei", + "enum-iterator", + "indexmap", + "lazy_static", + "libc", + "mach", + "memoffset", + "more-asserts", + "region", + "scopeguard", + "thiserror", + "wasmer-types 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=master)", "winapi", ] @@ -3281,7 +3460,7 @@ dependencies = [ "typetag", "wasm-bindgen", "wasm-bindgen-test", - "wasmer", + "wasmer 3.0.0-beta", "wasmer-vbus", "wasmer-vfs", "wasmer-vnet", @@ -3320,8 +3499,8 @@ dependencies = [ "byteorder", "serde", "time", - "wasmer-derive", - "wasmer-types", + "wasmer-derive 3.0.0-beta", + "wasmer-types 3.0.0-beta", ] [[package]] @@ -3332,7 +3511,7 @@ dependencies = [ "serde", "tempfile", "thiserror", - "wasmer", + "wasmer 3.0.0-beta", "wasmer-vfs", "wasmer-wasi", "wast 38.0.1", @@ -3357,15 +3536,15 @@ dependencies = [ "tracing", "tracing-subscriber", "wasi-test-generator", - "wasmer", + "wasmer 3.0.0-beta", "wasmer-cache", - "wasmer-compiler", - "wasmer-compiler-cranelift", + "wasmer-compiler 3.0.0-beta", + "wasmer-compiler-cranelift 3.0.0-beta", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-emscripten", "wasmer-middlewares", - "wasmer-types", + "wasmer-types 3.0.0-beta", "wasmer-wasi", "wasmer-wast", ] @@ -3659,6 +3838,64 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +[[package]] +name = "wit-bindgen-gen-core" +version = "0.1.0" +dependencies = [ + "anyhow", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-gen-rust" +version = "0.1.0" +dependencies = [ + "heck 0.3.3", + "wit-bindgen-gen-core", +] + +[[package]] +name = "wit-bindgen-gen-wasmer" +version = "0.1.0" +dependencies = [ + "heck 0.3.3", + "wit-bindgen-gen-core", + "wit-bindgen-gen-rust", +] + +[[package]] +name = "wit-bindgen-wasmer" +version = "0.1.0" +dependencies = [ + "anyhow", + "bitflags", + "once_cell", + "thiserror", + "wasmer 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=master)", + "wit-bindgen-wasmer-impl", +] + +[[package]] +name = "wit-bindgen-wasmer-impl" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "syn", + "wit-bindgen-gen-core", + "wit-bindgen-gen-wasmer", +] + +[[package]] +name = "wit-parser" +version = "0.1.0" +dependencies = [ + "anyhow", + "id-arena", + "pulldown-cmark", + "unicode-normalization", + "unicode-xid", +] + [[package]] name = "x11-dl" version = "2.19.1" diff --git a/Cargo.toml b/Cargo.toml index 6ee42dd2c37..3cb8f29b56e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,6 +44,7 @@ members = [ "lib/vm", "lib/wasi", "lib/wasi-types", + "lib/wasi-types-generated", "lib/wasi-experimental-io-devices", "lib/wasi-local-networking", "lib/types", diff --git a/lib/wasi-types-generated/Cargo.toml b/lib/wasi-types-generated/Cargo.toml new file mode 100644 index 00000000000..bc2c634373e --- /dev/null +++ b/lib/wasi-types-generated/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "wasi-types-generated" +version = "0.1.0" +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +#[dependencies] +#wasmer = { version = "3.0.0-beta", path = "../api" } + +[dependencies.wit-bindgen-wasmer] +path = "/home/silwol/Projects/wasmerio/wit-bindgen/crates/wasmer" +#git = "https://github.com/wasmerio/wit-bindgen.git" +#branch = "wasmer" diff --git a/lib/wasi-types-generated/src/bindings.rs b/lib/wasi-types-generated/src/bindings.rs new file mode 100644 index 00000000000..29a2d7135f0 --- /dev/null +++ b/lib/wasi-types-generated/src/bindings.rs @@ -0,0 +1,809 @@ +#[allow(clippy::all)] +pub mod wasi_filesystem { + #[allow(unused_imports)] + use wit_bindgen_wasmer::{anyhow, wasmer}; + /// The type of a filesystem object referenced by a descriptor. + /// + /// Note: This was called `filetype` in earlier versions of WASI. + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum Type { + /// The type of the descriptor or file is unknown or is different from + /// any of the other types specified. + Unknown, + /// The descriptor refers to a block device inode. + BlockDevice, + /// The descriptor refers to a character device inode. + CharacterDevice, + /// The descriptor refers to a directory inode. + Directory, + /// The descriptor refers to a named pipe. + Fifo, + /// The file refers to a symbolic link inode. + SymbolicLink, + /// The descriptor refers to a regular file inode. + RegularFile, + /// The descriptor refers to a socket. + Socket, + } + impl core::fmt::Debug for Type { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Type::Unknown => f.debug_tuple("Type::Unknown").finish(), + Type::BlockDevice => f.debug_tuple("Type::BlockDevice").finish(), + Type::CharacterDevice => f.debug_tuple("Type::CharacterDevice").finish(), + Type::Directory => f.debug_tuple("Type::Directory").finish(), + Type::Fifo => f.debug_tuple("Type::Fifo").finish(), + Type::SymbolicLink => f.debug_tuple("Type::SymbolicLink").finish(), + Type::RegularFile => f.debug_tuple("Type::RegularFile").finish(), + Type::Socket => f.debug_tuple("Type::Socket").finish(), + } + } + } + wit_bindgen_wasmer::bitflags::bitflags! { + /// Descriptor flags. + /// + /// Note: This was called `fd-flags` in earlier versions of WASI. + pub struct Flags: u8 {/// Read mode: Data can be read. + const READ = 1 << 0; + /// Write mode: Data can be written to. + const WRITE = 1 << 1; + /// Append mode: Data written to the file is always appended to the file's + /// end. + const APPEND = 1 << 2; + /// Write according to synchronized I/O data integrity completion. Only the + /// data stored in the file is synchronized. + const DSYNC = 1 << 3; + /// Non-blocking mode. + const NONBLOCK = 1 << 4; + /// Synchronized read I/O operations. + const RSYNC = 1 << 5; + /// 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 << 6; + } + } + + impl core::fmt::Display for Flags { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("Flags(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(()) + } + } + + wit_bindgen_wasmer::bitflags::bitflags! { + /// Flags determining the method of how paths are resolved. + pub struct AtFlags: u8 {/// As long as the resolved path corresponds to a symbolic link, it is expanded. + const SYMLINK_FOLLOW = 1 << 0; + } + } + + impl core::fmt::Display for AtFlags { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("AtFlags(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(()) + } + } + + wit_bindgen_wasmer::bitflags::bitflags! { + /// Open flags used by `open-at`. + 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 core::fmt::Display for OFlags { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("OFlags(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(()) + } + } + + wit_bindgen_wasmer::bitflags::bitflags! { + /// Permissions mode used by `open-at`, `change-permissions-at`, and similar. + pub struct Mode: u8 {/// True if the resource is considered readable by the containing + /// filesystem. + const READABLE = 1 << 0; + /// True if the resource is considered writeable by the containing + /// filesystem. + const WRITEABLE = 1 << 1; + /// True if the resource is considered executable by the containing + /// filesystem. This does not apply to directories. + const EXECUTABLE = 1 << 2; + } + } + + impl core::fmt::Display for Mode { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("Mode(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(()) + } + } + + /// 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. This is similar to `E2BIG` in POSIX. + 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 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, + } + 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::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", + } + } + pub fn message(&self) -> &'static str { + match self { + Errno::Success => "No error occurred. System call completed successfully.", + Errno::Toobig => "Argument list too long. This is similar to `E2BIG` in POSIX.", + 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::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.", + } + } + } + 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 {} + /// 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(), + } + } + } + /// A descriptor is a reference to a filesystem object, which may be a file, + /// directory, named pipe, special file, or other object on which filesystem + /// calls may be made. + #[derive(Debug)] + pub struct Descriptor(wit_bindgen_wasmer::rt::ResourceIndex); + + /// Auxiliary data associated with the wasm exports. + #[derive(Default)] + pub struct WasiFilesystemData { + index_slab0: wit_bindgen_wasmer::rt::IndexSlab, + resource_slab0: wit_bindgen_wasmer::rt::ResourceSlab, + dtor0: OnceCell>, + } + + pub struct WasiFilesystem { + #[allow(dead_code)] + env: wasmer::FunctionEnv, + func_descriptor_fadvise: wasmer::TypedFunction<(i32, i64, i64, i32), i32>, + memory: wasmer::Memory, + } + impl WasiFilesystem { + /// Adds any intrinsics, if necessary for this exported wasm + /// functionality to the `ImportObject` provided. + /// + /// This function returns the `WasiFilesystemData` which needs to be + /// passed through to `WasiFilesystem::new`. + fn add_to_imports( + mut store: impl wasmer::AsStoreMut, + imports: &mut wasmer::Imports, + ) -> wasmer::FunctionEnv { + let env = wasmer::FunctionEnv::new(&mut store, WasiFilesystemData::default()); + let mut canonical_abi = imports + .get_namespace_exports("canonical_abi") + .unwrap_or_else(wasmer::Exports::new); + + canonical_abi.insert( + "resource_drop_descriptor", + wasmer::Function::new_typed_with_env( + &mut store, + &env, + move |mut store: wasmer::FunctionEnvMut, + idx: u32| + -> Result<(), wasmer::RuntimeError> { + let resource_idx = store.data_mut().index_slab0.remove(idx)?; + let wasm = match store.data_mut().resource_slab0.drop(resource_idx) { + Some(wasm) => wasm, + None => return Ok(()), + }; + let dtor = store.data_mut().dtor0.get().unwrap().clone(); + dtor.call(&mut store, wasm)?; + Ok(()) + }, + ), + ); + canonical_abi.insert( + "resource_clone_descriptor", + wasmer::Function::new_typed_with_env( + &mut store, + &env, + move |mut store: wasmer::FunctionEnvMut, + idx: u32| + -> Result { + let state = &mut *store.data_mut(); + let resource_idx = state.index_slab0.get(idx)?; + state.resource_slab0.clone(resource_idx)?; + Ok(state.index_slab0.insert(resource_idx)) + }, + ), + ); + canonical_abi.insert( + "resource_get_descriptor", + wasmer::Function::new_typed_with_env( + &mut store, + &env, + move |mut store: wasmer::FunctionEnvMut, + idx: u32| + -> Result { + let state = &mut *store.data_mut(); + let resource_idx = state.index_slab0.get(idx)?; + Ok(state.resource_slab0.get(resource_idx)) + }, + ), + ); + canonical_abi.insert( + "resource_new_descriptor", + wasmer::Function::new_typed_with_env( + &mut store, + &env, + move |mut store: wasmer::FunctionEnvMut, + val: i32| + -> Result { + let state = &mut *store.data_mut(); + let resource_idx = state.resource_slab0.insert(val); + Ok(state.index_slab0.insert(resource_idx)) + }, + ), + ); + imports.register_namespace("canonical_abi", canonical_abi); + env + } + + /// Instantiates the provided `module` using the specified + /// parameters, wrapping up the result in a structure that + /// translates between wasm and the host. + /// + /// The `imports` provided will have intrinsics added to it + /// automatically, so it's not necessary to call + /// `add_to_imports` beforehand. This function will + /// instantiate the `module` otherwise using `imports`, and + /// both an instance of this structure and the underlying + /// `wasmer::Instance` will be returned. + pub fn instantiate( + mut store: impl wasmer::AsStoreMut, + module: &wasmer::Module, + imports: &mut wasmer::Imports, + ) -> anyhow::Result<(Self, wasmer::Instance)> { + let env = Self::add_to_imports(&mut store, imports); + let instance = wasmer::Instance::new(&mut store, module, &*imports)?; + { + let dtor0 = instance + .exports + .get_typed_function(&store, "canonical_abi_drop_descriptor")? + .clone(); + + env.as_mut(&mut store) + .dtor0 + .set(dtor0) + .map_err(|_e| anyhow::anyhow!("Couldn't set canonical_abi_drop_descriptor"))?; + } + + Ok((Self::new(store, &instance, env)?, instance)) + } + + /// Low-level creation wrapper for wrapping up the exports + /// of the `instance` provided in this structure of wasm + /// exports. + /// + /// This function will extract exports from the `instance` + /// and wrap them all up in the returned structure which can + /// be used to interact with the wasm module. + pub fn new( + store: impl wasmer::AsStoreMut, + _instance: &wasmer::Instance, + env: wasmer::FunctionEnv, + ) -> Result { + let func_descriptor_fadvise = _instance + .exports + .get_typed_function(&store, "descriptor::fadvise")?; + let memory = _instance.exports.get_memory("memory")?.clone(); + Ok(WasiFilesystem { + func_descriptor_fadvise, + memory, + env, + }) + } + /// Provide file advisory information on a descriptor. + /// + /// This is similar to `posix_fadvise` in POSIX. + pub fn descriptor_fadvise( + &self, + store: &mut wasmer::Store, + self_: &Descriptor, + offset: u64, + len: u64, + advice: Advice, + ) -> Result, wasmer::RuntimeError> { + let _memory = &self.memory; + + let obj0 = self_; + let handle0 = { + let state = self.env.as_mut(store); + state.resource_slab0.clone(obj0.0)?; + state.index_slab0.insert(obj0.0) + }; + let result1 = self.func_descriptor_fadvise.call( + store, + handle0 as i32, + wit_bindgen_wasmer::rt::as_i64(offset), + wit_bindgen_wasmer::rt::as_i64(len), + advice as i32, + )?; + let load2 = unsafe { _memory.data_unchecked_mut(&store.as_store_ref()) } + .load::(result1 + 0)?; + Ok(match i32::from(load2) { + 0 => Ok(()), + 1 => Err({ + let load3 = unsafe { _memory.data_unchecked_mut(&store.as_store_ref()) } + .load::(result1 + 1)?; + match i32::from(load3) { + 0 => Errno::Success, + 1 => Errno::Toobig, + 2 => Errno::Access, + 3 => Errno::Addrinuse, + 4 => Errno::Addrnotavail, + 5 => Errno::Afnosupport, + 6 => Errno::Again, + 7 => Errno::Already, + 8 => Errno::Badmsg, + 9 => Errno::Busy, + 10 => Errno::Canceled, + 11 => Errno::Child, + 12 => Errno::Connaborted, + 13 => Errno::Connrefused, + 14 => Errno::Connreset, + 15 => Errno::Deadlk, + 16 => Errno::Destaddrreq, + 17 => Errno::Dom, + 18 => Errno::Dquot, + 19 => Errno::Exist, + 20 => Errno::Fault, + 21 => Errno::Fbig, + 22 => Errno::Hostunreach, + 23 => Errno::Idrm, + 24 => Errno::Ilseq, + 25 => Errno::Inprogress, + 26 => Errno::Intr, + 27 => Errno::Inval, + 28 => Errno::Io, + 29 => Errno::Isconn, + 30 => Errno::Isdir, + 31 => Errno::Loop, + 32 => Errno::Mfile, + 33 => Errno::Mlink, + 34 => Errno::Msgsize, + 35 => Errno::Multihop, + 36 => Errno::Nametoolong, + 37 => Errno::Netdown, + 38 => Errno::Netreset, + 39 => Errno::Netunreach, + 40 => Errno::Nfile, + 41 => Errno::Nobufs, + 42 => Errno::Nodev, + 43 => Errno::Noent, + 44 => Errno::Noexec, + 45 => Errno::Nolck, + 46 => Errno::Nolink, + 47 => Errno::Nomem, + 48 => Errno::Nomsg, + 49 => Errno::Noprotoopt, + 50 => Errno::Nospc, + 51 => Errno::Nosys, + 52 => Errno::Notconn, + 53 => Errno::Notdir, + 54 => Errno::Notempty, + 55 => Errno::Notrecoverable, + 56 => Errno::Notsock, + 57 => Errno::Notsup, + 58 => Errno::Notty, + 59 => Errno::Nxio, + 60 => Errno::Overflow, + 61 => Errno::Ownerdead, + 62 => Errno::Perm, + 63 => Errno::Pipe, + 64 => Errno::Proto, + 65 => Errno::Protonosupport, + 66 => Errno::Prototype, + 67 => Errno::Range, + 68 => Errno::Rofs, + 69 => Errno::Spipe, + 70 => Errno::Srch, + 71 => Errno::Stale, + 72 => Errno::Timedout, + 73 => Errno::Txtbsy, + 74 => Errno::Xdev, + _ => return Err(invalid_variant("Errno")), + } + }), + _ => return Err(invalid_variant("expected")), + }) + } + + /// Drops the host-owned handle to the resource + /// specified. + /// + /// Note that this may execute the WebAssembly-defined + /// destructor for this type. This also may not run + /// the destructor if there are still other references + /// to this type. + pub fn drop_descriptor( + &self, + store: &mut wasmer::Store, + val: Descriptor, + ) -> Result<(), wasmer::RuntimeError> { + let state = self.env.as_mut(store); + let wasm = match state.resource_slab0.drop(val.0) { + Some(val) => val, + None => return Ok(()), + }; + let dtor0 = state.dtor0.get().unwrap().clone(); + dtor0.call(store, wasm)?; + Ok(()) + } + } + #[allow(unused_imports)] + use wasmer::AsStoreMut as _; + #[allow(unused_imports)] + use wasmer::AsStoreRef as _; + use wit_bindgen_wasmer::once_cell::unsync::OnceCell; + use wit_bindgen_wasmer::rt::invalid_variant; + use wit_bindgen_wasmer::rt::RawMem; +} diff --git a/lib/wasi-types-generated/src/lib.rs b/lib/wasi-types-generated/src/lib.rs new file mode 100644 index 00000000000..f1f0747b9b3 --- /dev/null +++ b/lib/wasi-types-generated/src/lib.rs @@ -0,0 +1 @@ +mod bindings; diff --git a/lib/wasi-types-generated/wit/wasi-filesystem.wit b/lib/wasi-types-generated/wit/wasi-filesystem.wit new file mode 100644 index 00000000000..c5154f03793 --- /dev/null +++ b/lib/wasi-types-generated/wit/wasi-filesystem.wit @@ -0,0 +1,626 @@ +// Extracted from https://github.com/WebAssembly/wasi-filesystem/blob/main/wasi-filesystem.wit.md + +/// Size of a range of bytes in memory. +type size = u32 + +/// Non-negative file size or length of a region within a file. +type filesize = u64 + +/// Relative offset within a file. +type filedelta = s64 + +/// Timestamp in nanoseconds. +/// +/// TODO: wasi-clocks is moving to seconds+nanoseconds. +type timestamp = u64 + +/// Information associated with a descriptor. +/// +/// Note: This was called `fdstat` in earlier versions of WASI. +record info { + /// The type of filesystem object referenced by a descriptor. + %type: %type, + /// Flags associated with a descriptor. + %flags: %flags, +} + +/// The type of a filesystem object referenced by a descriptor. +/// +/// Note: This was called `filetype` in earlier versions of WASI. +enum %type { + /// The type of the descriptor or file is unknown or is different from + /// any of the other types specified. + unknown, + /// The descriptor refers to a block device inode. + block-device, + /// The descriptor refers to a character device inode. + character-device, + /// The descriptor refers to a directory inode. + directory, + /// The descriptor refers to a named pipe. + fifo, + /// The file refers to a symbolic link inode. + symbolic-link, + /// The descriptor refers to a regular file inode. + regular-file, + /// The descriptor refers to a socket. + socket, +} + +/// Descriptor flags. +/// +/// Note: This was called `fd-flags` in earlier versions of WASI. +flags %flags { + /// Read mode: Data can be read. + read, + /// Write mode: Data can be written to. + write, + /// 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 attributes. +/// +/// Note: This was called `filestat` in earlier versions of WASI. +record stat { + /// Device ID of device containing the file. + dev: device, + /// File serial number. + ino: inode, + /// File type. + %type: %type, + /// Number of hard links to the file. + nlink: linkcount, + /// For regular files, the file size in bytes. For symbolic links, the length + /// in bytes of the pathname contained in the symbolic link. + size: filesize, + /// Last data access timestamp. + atim: timestamp, + /// Last data modification timestamp. + mtim: timestamp, + /// Last file status change timestamp. + ctim: timestamp, +} + +/// Flags determining the method of how paths are resolved. +flags at-flags { + /// As long as the resolved path corresponds to a symbolic link, it is expanded. + symlink-follow, +} + +/// Open flags used by `open-at`. +flags o-flags { + /// 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, +} + +/// Permissions mode used by `open-at`, `change-permissions-at`, and similar. +flags mode { + /// True if the resource is considered readable by the containing + /// filesystem. + readable, + /// True if the resource is considered writeable by the containing + /// filesystem. + writeable, + /// True if the resource is considered executable by the containing + /// filesystem. This does not apply to directories. + executable, +} + +/// Number of hard links to an inode. +type linkcount = 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 + +/// Filesystem object serial number that is unique within its file system. +type inode = u64 + +/// When setting a timestamp, this gives the value to set it to. +variant new-timestamp { + /// Leave the timestamp set to its previous value. + no-change, + /// Set the timestamp to the current time of the system clock associated + /// with the filesystem. + now, + /// Set the timestamp to the given value. + timestamp(timestamp), +} + +/// A directory entry. +record dirent { + /// The serial number of the file referred to by this directory entry. + ino: inode, + /// The length of the name of the directory entry. + namelen: size, + /// The type of the file referred to by this directory entry. + %type: %type, +} + +/// 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 { + /// No error occurred. System call completed successfully. + success, + /// Argument list too long. This is similar to `E2BIG` in POSIX. + 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 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, +} + +/// File or memory access pattern advisory information. +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. + will-need, + /// The application expects that it will not access the specified data in the near future. + dont-need, + /// The application expects to access the specified data once and then not reuse it thereafter. + no-reuse, +} + +/// The position relative to which to set the offset of the descriptor. +variant seek-from { + /// Seek relative to start-of-file. + set(filesize), + /// Seek relative to current position. + cur(filedelta), + /// Seek relative to end-of-file. + end(filesize), +} + +/// A descriptor is a reference to a filesystem object, which may be a file, +/// directory, named pipe, special file, or other object on which filesystem +/// calls may be made. +resource descriptor { + /// Provide file advisory information on a descriptor. + /// + /// This is similar to `posix_fadvise` in POSIX. + fadvise: func( + /// The offset within the file to which the advisory applies. + offset: u64, + /// The length of the region to which the advisory applies. + len: u64, + /// The advice. + advice: advice + ) -> expected + +// /// Force the allocation of space in a file. +// /// +// /// Note: This is similar to `posix_fallocate` in POSIX. +// fallocate: func( +// /// The offset at which to start the allocation. +// offset: filesize, +// /// The length of the area that is allocated. +// len: filesize +// ) -> expected +// +// /// Synchronize the data of a file to disk. +// /// +// /// Note: This is similar to `fdatasync` in POSIX. +// datasync: func() -> expected +// +// /// Get information associated with a descriptor. +// /// +// /// Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well +// /// as additional fields. +// /// +// /// Note: This was called `fdstat_get` in earlier versions of WASI. +// info: func() -> expected +// +// /// Adjust the size of an open file. If this increases the file's size, the +// /// extra bytes are filled with zeros. +// /// +// /// Note: This was called `fd_filestat_set_size` in earlier versions of WASI. +// set-size: func(size: filesize) -> expected +// +// /// Adjust the timestamps of an open file or directory. +// /// +// /// Note: This is similar to `futimens` in POSIX. +// /// +// /// Note: This was called `fd_filestat_set_times` in earlier versions of WASI. +// set-times: func( +// /// The desired values of the data access timestamp. +// atim: new-timestamp, +// /// The desired values of the data modification timestamp. +// mtim: new-timestamp, +// ) -> expected +// +// /// Read from a descriptor, without using and updating the descriptor's offset. +// /// +// /// Note: This is similar to `pread` in POSIX. +// pread: func( +// /// The offset within the file at which to read. +// offset: filesize, +// ) -> stream +// +// /// Write to a descriptor, without using and updating the descriptor's offset. +// /// +// /// Note: This is similar to `pwrite` in POSIX. +// pwrite: func( +// /// Data to write +// buf: stream, +// /// The offset within the file at which to write. +// offset: filesize, +// ) -> future> +// +// /// Read from a descriptor. +// /// +// /// The meaning of `read` on a directory is unspecified. +// /// +// /// Note: This is similar to `read` in POSIX. +// read: func() -> stream +// +// /// 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. +// readdir: func( +// /// If true, rewind the current position to the beginning before reading. +// rewind: bool +// ) -> stream +// +// /// Move the offset of a descriptor. +// /// +// /// The meaning of `seek` on a directory is unspecified. +// /// +// /// Returns new offset of the descriptor, relative to the start of the file. +// /// +// /// Note: This is similar to `lseek` in POSIX. +// seek: func( +// /// The method to compute the new offset. +// %from: seek-from, +// ) -> expected +// +// /// Synchronize the data and metadata of a file to disk. +// /// +// /// Note: This is similar to `fsync` in POSIX. +// sync: func() -> expected +// +// /// Return the current offset of a descriptor. +// /// +// /// Returns the current offset of the descriptor, relative to the start of the file. +// /// +// /// Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX. +// tell: func() -> expected +// +// /// Write to a descriptor. +// /// +// /// Note: This is similar to `write` in POSIX. +// write: func( +// /// Data to write +// buf: stream, +// ) -> future> +// +// /// Create a directory. +// /// +// /// Note: This is similar to `mkdirat` in POSIX. +// create-directory-at: func( +// /// The relative path at which to create the directory. +// path: string, +// ) -> expected +// +// /// Return the attributes of a file or directory. +// /// +// /// Note: This is similar to `fstatat` in POSIX. +// /// +// /// Note: This was called `fd_filestat_get` in earlier versions of WASI. +// stat-at: func( +// /// Flags determining the method of how the path is resolved. +// at-flags: at-flags, +// /// The relative path of the file or directory to inspect. +// path: string, +// ) -> expected +// +// /// Adjust the timestamps of a file or directory. +// /// +// /// Note: This is similar to `utimensat` in POSIX. +// /// +// /// Note: This was called `path_filestat_set_times` in earlier versions of WASI. +// set-times-at: func( +// /// Flags determining the method of how the path is resolved. +// at-flags: at-flags, +// /// The relative path of the file or directory to operate on. +// path: string, +// /// The desired values of the data access timestamp. +// atim: new-timestamp, +// /// The desired values of the data modification timestamp. +// mtim: new-timestamp, +// ) -> expected +// +// /// Create a hard link. +// /// +// /// Note: This is similar to `linkat` in POSIX. +// link-at: func( +// /// Flags determining the method of how the path is resolved. +// old-at-flags: at-flags, +// /// The relative source path from which to link. +// old-path: string, +// /// The base directory for `new-path`. +// new-descriptor: handle descriptor, +// /// The relative destination path at which to create the hard link. +// new-path: string, +// ) -> expected +// +// /// Open a file or directory. +// /// +// /// The returned descriptor is not guaranteed to be the lowest-numbered +// /// 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 descriptor is +// /// guaranteed to be less than 2**31. +// /// +// /// Note: This is similar to `openat` in POSIX. +// open-at: func( +// /// Flags determining the method of how the path is resolved. +// at-flags: at-flags, +// /// The relative path of the object to open. +// path: string, +// /// The method by which to open the file. +// o-flags: o-flags, +// /// Flags to use for the resulting descriptor. +// %flags: %flags, +// /// Permissions to use when creating a new file. +// mode: mode +// ) -> expected +// +// /// Read the contents of a symbolic link. +// /// +// /// Note: This is similar to `readlinkat` in POSIX. +// readlink-at: func( +// /// The relative path of the symbolic link from which to read. +// path: string, +// ) -> expected +// +// /// Remove a directory. +// /// +// /// Return `errno::notempty` if the directory is not empty. +// /// +// /// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. +// remove-directory-at: func( +// /// The relative path to a directory to remove. +// path: string, +// ) -> expected +// +// /// Rename a filesystem object. +// /// +// /// Note: This is similar to `renameat` in POSIX. +// rename-at: func( +// /// The relative source path of the file or directory to rename. +// old-path: string, +// /// The base directory for `new-path`. +// new-descriptor: handle descriptor, +// /// The relative destination path to which to rename the file or directory. +// new-path: string, +// ) -> expected +// +// /// Create a symbolic link. +// /// +// /// Note: This is similar to `symlinkat` in POSIX. +// symlink-at: func( +// /// The contents of the symbolic link. +// old-path: string, +// /// The relative destination path at which to create the symbolic link. +// new-path: string, +// ) -> expected +// +// /// Unlink a filesystem object that is not a directory. +// /// +// /// Return `errno::isdir` if the path refers to a directory. +// /// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. +// unlink-file-at: func( +// /// The relative path to a file to unlink. +// path: string, +// ) -> expected +// +// /// Change the permissions of a filesystem object that is not a directory. +// /// +// /// Note that the ultimate meanings of these permissions is +// /// filesystem-specific. +// /// +// /// Note: This is similar to `fchmodat` in POSIX. +// change-file-permissions-at: func( +// /// Flags determining the method of how the path is resolved. +// at-flags: at-flags, +// /// The relative path to operate on. +// path: string, +// /// The new permissions for the filesystem object. +// mode: mode, +// ) -> expected +// +// /// Change the permissions of a directory. +// /// +// /// Note that the ultimate meanings of these permissions is +// /// filesystem-specific. +// /// +// /// Unlike in POSIX, the `executable` flag is not reinterpreted as a "search" +// /// flag. `read` on a directory implies readability and searchability, and +// /// `execute` is not valid for directories. +// /// +// /// Note: This is similar to `fchmodat` in POSIX. +// change-directory-permissions-at: func( +// /// Flags determining the method of how the path is resolved. +// at-flags: at-flags, +// /// The relative path to operate on. +// path: string, +// /// The new permissions for the directory. +// mode: mode, +// ) -> expected +} From f2a4b8731e252745534d3abf89dab3bfc36432b8 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Tue, 16 Aug 2022 09:05:40 +0200 Subject: [PATCH 02/84] Generate bindings directly for now --- lib/wasi-types-generated/Cargo.toml | 8 +- lib/wasi-types-generated/regenerate.sh | 3 + lib/wasi-types-generated/src/bindings.rs | 2085 ++++++++++------- lib/wasi-types-generated/src/lib.rs | 2 + .../wit/wasi-snapshot0.wit | 749 ++++++ 5 files changed, 2061 insertions(+), 786 deletions(-) create mode 100755 lib/wasi-types-generated/regenerate.sh create mode 100644 lib/wasi-types-generated/wit/wasi-snapshot0.wit diff --git a/lib/wasi-types-generated/Cargo.toml b/lib/wasi-types-generated/Cargo.toml index bc2c634373e..a56be5143df 100644 --- a/lib/wasi-types-generated/Cargo.toml +++ b/lib/wasi-types-generated/Cargo.toml @@ -1,12 +1,12 @@ [package] -name = "wasi-types-generated" -version = "0.1.0" +name = "wasmer-wasi-types-generated" +version = "3.0.0-beta" edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -#[dependencies] -#wasmer = { version = "3.0.0-beta", path = "../api" } +[dependencies] +wasmer-derive = { path = "../derive", version = "=3.0.0-beta" } [dependencies.wit-bindgen-wasmer] path = "/home/silwol/Projects/wasmerio/wit-bindgen/crates/wasmer" diff --git a/lib/wasi-types-generated/regenerate.sh b/lib/wasi-types-generated/regenerate.sh new file mode 100755 index 00000000000..37874c7968c --- /dev/null +++ b/lib/wasi-types-generated/regenerate.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +wit-bindgen wasmer --import wit/wasi-snapshot0.wit wit/wasi-filesystem.wit --out-dir src/ diff --git a/lib/wasi-types-generated/src/bindings.rs b/lib/wasi-types-generated/src/bindings.rs index 29a2d7135f0..ea91e4c23c4 100644 --- a/lib/wasi-types-generated/src/bindings.rs +++ b/lib/wasi-types-generated/src/bindings.rs @@ -1,809 +1,1330 @@ #[allow(clippy::all)] -pub mod wasi_filesystem { - #[allow(unused_imports)] - use wit_bindgen_wasmer::{anyhow, wasmer}; - /// The type of a filesystem object referenced by a descriptor. - /// - /// Note: This was called `filetype` in earlier versions of WASI. - #[repr(u8)] - #[derive(Clone, Copy, PartialEq, Eq)] - pub enum Type { - /// The type of the descriptor or file is unknown or is different from - /// any of the other types specified. - Unknown, - /// The descriptor refers to a block device inode. - BlockDevice, - /// The descriptor refers to a character device inode. - CharacterDevice, - /// The descriptor refers to a directory inode. - Directory, - /// The descriptor refers to a named pipe. - Fifo, - /// The file refers to a symbolic link inode. - SymbolicLink, - /// The descriptor refers to a regular file inode. - RegularFile, - /// The descriptor refers to a socket. - Socket, - } - impl core::fmt::Debug for Type { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - match self { - Type::Unknown => f.debug_tuple("Type::Unknown").finish(), - Type::BlockDevice => f.debug_tuple("Type::BlockDevice").finish(), - Type::CharacterDevice => f.debug_tuple("Type::CharacterDevice").finish(), - Type::Directory => f.debug_tuple("Type::Directory").finish(), - Type::Fifo => f.debug_tuple("Type::Fifo").finish(), - Type::SymbolicLink => f.debug_tuple("Type::SymbolicLink").finish(), - Type::RegularFile => f.debug_tuple("Type::RegularFile").finish(), - Type::Socket => f.debug_tuple("Type::Socket").finish(), - } - } - } - wit_bindgen_wasmer::bitflags::bitflags! { - /// Descriptor flags. - /// - /// Note: This was called `fd-flags` in earlier versions of WASI. - pub struct Flags: u8 {/// Read mode: Data can be read. - const READ = 1 << 0; - /// Write mode: Data can be written to. - const WRITE = 1 << 1; - /// Append mode: Data written to the file is always appended to the file's - /// end. - const APPEND = 1 << 2; - /// Write according to synchronized I/O data integrity completion. Only the - /// data stored in the file is synchronized. - const DSYNC = 1 << 3; - /// Non-blocking mode. - const NONBLOCK = 1 << 4; - /// Synchronized read I/O operations. - const RSYNC = 1 << 5; - /// 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 << 6; +pub mod wasi_snapshot0 { + #[allow(unused_imports)] + use wit_bindgen_wasmer::{anyhow, wasmer}; + /// 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. + Acces, + /// 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::Acces => "acces", + 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", } } - - impl core::fmt::Display for Flags { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("Flags(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(()) - } - } - - wit_bindgen_wasmer::bitflags::bitflags! { - /// Flags determining the method of how paths are resolved. - pub struct AtFlags: u8 {/// As long as the resolved path corresponds to a symbolic link, it is expanded. - const SYMLINK_FOLLOW = 1 << 0; + pub fn message(&self) -> &'static str { + match self { + Errno::Success => "No error occurred. System call completed successfully.", + Errno::Toobig => "Argument list too long.", + Errno::Acces => "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::Display for AtFlags { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("AtFlags(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(()) - } + } + 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() } - - wit_bindgen_wasmer::bitflags::bitflags! { - /// Open flags used by `open-at`. - 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 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{} + wit_bindgen_wasmer::bitflags::bitflags! { + /// File descriptor rights, determining which actions may be performed. + pub struct Rights: u32 {/// 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; } - - impl core::fmt::Display for OFlags { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("OFlags(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(()) + } + + impl core::fmt::Display for Rights{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("Rights(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(())} + } + + /// 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, + } + 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() } - } - - wit_bindgen_wasmer::bitflags::bitflags! { - /// Permissions mode used by `open-at`, `change-permissions-at`, and similar. - pub struct Mode: u8 {/// True if the resource is considered readable by the containing - /// filesystem. - const READABLE = 1 << 0; - /// True if the resource is considered writeable by the containing - /// filesystem. - const WRITEABLE = 1 << 1; - /// True if the resource is considered executable by the containing - /// filesystem. This does not apply to directories. - const EXECUTABLE = 1 << 2; - } - } - - impl core::fmt::Display for Mode { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("Mode(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(()) + 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() + } + } } - - /// 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. This is similar to `E2BIG` in POSIX. - 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 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, + } + wit_bindgen_wasmer::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 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::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", - } + } + + impl core::fmt::Display for Fdflags{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("Fdflags(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(())} + } + + #[allow(unused_imports)] + use wasmer::AsStoreMut as _; + #[allow(unused_imports)] + use wasmer::AsStoreRef as _; +} +#[allow(clippy::all)] +pub mod wasi_filesystem { + #[allow(unused_imports)] + use wit_bindgen_wasmer::{anyhow, wasmer}; + /// The type of a filesystem object referenced by a descriptor. + /// + /// Note: This was called `filetype` in earlier versions of WASI. + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum Type { + /// The type of the descriptor or file is unknown or is different from + /// any of the other types specified. + Unknown, + /// The descriptor refers to a block device inode. + BlockDevice, + /// The descriptor refers to a character device inode. + CharacterDevice, + /// The descriptor refers to a directory inode. + Directory, + /// The descriptor refers to a named pipe. + Fifo, + /// The file refers to a symbolic link inode. + SymbolicLink, + /// The descriptor refers to a regular file inode. + RegularFile, + /// The descriptor refers to a socket. + Socket, + } + impl core::fmt::Debug for Type { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Type::Unknown => { + f.debug_tuple("Type::Unknown").finish() } - pub fn message(&self) -> &'static str { - match self { - Errno::Success => "No error occurred. System call completed successfully.", - Errno::Toobig => "Argument list too long. This is similar to `E2BIG` in POSIX.", - 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::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.", - } + Type::BlockDevice => { + f.debug_tuple("Type::BlockDevice").finish() } - } - 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() + Type::CharacterDevice => { + f.debug_tuple("Type::CharacterDevice").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) + Type::Directory => { + f.debug_tuple("Type::Directory").finish() } + Type::Fifo => { + f.debug_tuple("Type::Fifo").finish() + } + Type::SymbolicLink => { + f.debug_tuple("Type::SymbolicLink").finish() + } + Type::RegularFile => { + f.debug_tuple("Type::RegularFile").finish() + } + Type::Socket => { + f.debug_tuple("Type::Socket").finish() + } + } } - - impl std::error::Error for Errno {} - /// 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, + } + wit_bindgen_wasmer::bitflags::bitflags! { + /// Descriptor flags. + /// + /// Note: This was called `fd-flags` in earlier versions of WASI. + pub struct Flags: u8 {/// Read mode: Data can be read. + const READ = 1 << 0; + /// Write mode: Data can be written to. + const WRITE = 1 << 1; + /// Append mode: Data written to the file is always appended to the file's + /// end. + const APPEND = 1 << 2; + /// Write according to synchronized I/O data integrity completion. Only the + /// data stored in the file is synchronized. + const DSYNC = 1 << 3; + /// Non-blocking mode. + const NONBLOCK = 1 << 4; + /// Synchronized read I/O operations. + const RSYNC = 1 << 5; + /// 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 << 6; } - 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(), - } - } + } + + impl core::fmt::Display for Flags{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("Flags(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(())} + } + + wit_bindgen_wasmer::bitflags::bitflags! { + /// Flags determining the method of how paths are resolved. + pub struct AtFlags: u8 {/// As long as the resolved path corresponds to a symbolic link, it is expanded. + const SYMLINK_FOLLOW = 1 << 0; } - /// A descriptor is a reference to a filesystem object, which may be a file, - /// directory, named pipe, special file, or other object on which filesystem - /// calls may be made. - #[derive(Debug)] - pub struct Descriptor(wit_bindgen_wasmer::rt::ResourceIndex); - - /// Auxiliary data associated with the wasm exports. - #[derive(Default)] - pub struct WasiFilesystemData { - index_slab0: wit_bindgen_wasmer::rt::IndexSlab, - resource_slab0: wit_bindgen_wasmer::rt::ResourceSlab, - dtor0: OnceCell>, + } + + impl core::fmt::Display for AtFlags{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("AtFlags(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(())} + } + + wit_bindgen_wasmer::bitflags::bitflags! { + /// Open flags used by `open-at`. + 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; } - - pub struct WasiFilesystem { - #[allow(dead_code)] - env: wasmer::FunctionEnv, - func_descriptor_fadvise: wasmer::TypedFunction<(i32, i64, i64, i32), i32>, - memory: wasmer::Memory, + } + + impl core::fmt::Display for OFlags{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("OFlags(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(())} + } + + wit_bindgen_wasmer::bitflags::bitflags! { + /// Permissions mode used by `open-at`, `change-permissions-at`, and similar. + pub struct Mode: u8 {/// True if the resource is considered readable by the containing + /// filesystem. + const READABLE = 1 << 0; + /// True if the resource is considered writeable by the containing + /// filesystem. + const WRITEABLE = 1 << 1; + /// True if the resource is considered executable by the containing + /// filesystem. This does not apply to directories. + const EXECUTABLE = 1 << 2; } - impl WasiFilesystem { - /// Adds any intrinsics, if necessary for this exported wasm - /// functionality to the `ImportObject` provided. - /// - /// This function returns the `WasiFilesystemData` which needs to be - /// passed through to `WasiFilesystem::new`. - fn add_to_imports( - mut store: impl wasmer::AsStoreMut, - imports: &mut wasmer::Imports, - ) -> wasmer::FunctionEnv { - let env = wasmer::FunctionEnv::new(&mut store, WasiFilesystemData::default()); - let mut canonical_abi = imports - .get_namespace_exports("canonical_abi") - .unwrap_or_else(wasmer::Exports::new); - - canonical_abi.insert( - "resource_drop_descriptor", - wasmer::Function::new_typed_with_env( - &mut store, - &env, - move |mut store: wasmer::FunctionEnvMut, - idx: u32| - -> Result<(), wasmer::RuntimeError> { - let resource_idx = store.data_mut().index_slab0.remove(idx)?; - let wasm = match store.data_mut().resource_slab0.drop(resource_idx) { - Some(wasm) => wasm, - None => return Ok(()), - }; - let dtor = store.data_mut().dtor0.get().unwrap().clone(); - dtor.call(&mut store, wasm)?; - Ok(()) - }, - ), - ); - canonical_abi.insert( - "resource_clone_descriptor", - wasmer::Function::new_typed_with_env( - &mut store, - &env, - move |mut store: wasmer::FunctionEnvMut, - idx: u32| - -> Result { - let state = &mut *store.data_mut(); - let resource_idx = state.index_slab0.get(idx)?; - state.resource_slab0.clone(resource_idx)?; - Ok(state.index_slab0.insert(resource_idx)) - }, - ), - ); - canonical_abi.insert( - "resource_get_descriptor", - wasmer::Function::new_typed_with_env( - &mut store, - &env, - move |mut store: wasmer::FunctionEnvMut, - idx: u32| - -> Result { - let state = &mut *store.data_mut(); - let resource_idx = state.index_slab0.get(idx)?; - Ok(state.resource_slab0.get(resource_idx)) - }, - ), - ); - canonical_abi.insert( - "resource_new_descriptor", - wasmer::Function::new_typed_with_env( - &mut store, - &env, - move |mut store: wasmer::FunctionEnvMut, - val: i32| - -> Result { - let state = &mut *store.data_mut(); - let resource_idx = state.resource_slab0.insert(val); - Ok(state.index_slab0.insert(resource_idx)) - }, - ), - ); - imports.register_namespace("canonical_abi", canonical_abi); - env + } + + impl core::fmt::Display for Mode{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("Mode(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(())} + } + + /// 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. This is similar to `E2BIG` in POSIX. + 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 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, + } + 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::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", + } + } + pub fn message(&self) -> &'static str { + match self { + Errno::Success => "No error occurred. System call completed successfully.", + Errno::Toobig => "Argument list too long. This is similar to `E2BIG` in POSIX.", + 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::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.", + } + } + } + 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{} + /// 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() } - - /// Instantiates the provided `module` using the specified - /// parameters, wrapping up the result in a structure that - /// translates between wasm and the host. - /// - /// The `imports` provided will have intrinsics added to it - /// automatically, so it's not necessary to call - /// `add_to_imports` beforehand. This function will - /// instantiate the `module` otherwise using `imports`, and - /// both an instance of this structure and the underlying - /// `wasmer::Instance` will be returned. - pub fn instantiate( - mut store: impl wasmer::AsStoreMut, - module: &wasmer::Module, - imports: &mut wasmer::Imports, - ) -> anyhow::Result<(Self, wasmer::Instance)> { - let env = Self::add_to_imports(&mut store, imports); - let instance = wasmer::Instance::new(&mut store, module, &*imports)?; - { - let dtor0 = instance - .exports - .get_typed_function(&store, "canonical_abi_drop_descriptor")? - .clone(); - - env.as_mut(&mut store) - .dtor0 - .set(dtor0) - .map_err(|_e| anyhow::anyhow!("Couldn't set canonical_abi_drop_descriptor"))?; - } - - Ok((Self::new(store, &instance, env)?, instance)) + Advice::Random => { + f.debug_tuple("Advice::Random").finish() } - - /// Low-level creation wrapper for wrapping up the exports - /// of the `instance` provided in this structure of wasm - /// exports. - /// - /// This function will extract exports from the `instance` - /// and wrap them all up in the returned structure which can - /// be used to interact with the wasm module. - pub fn new( - store: impl wasmer::AsStoreMut, - _instance: &wasmer::Instance, - env: wasmer::FunctionEnv, - ) -> Result { - let func_descriptor_fadvise = _instance - .exports - .get_typed_function(&store, "descriptor::fadvise")?; - let memory = _instance.exports.get_memory("memory")?.clone(); - Ok(WasiFilesystem { - func_descriptor_fadvise, - memory, - env, - }) + Advice::WillNeed => { + f.debug_tuple("Advice::WillNeed").finish() } - /// Provide file advisory information on a descriptor. - /// - /// This is similar to `posix_fadvise` in POSIX. - pub fn descriptor_fadvise( - &self, - store: &mut wasmer::Store, - self_: &Descriptor, - offset: u64, - len: u64, - advice: Advice, - ) -> Result, wasmer::RuntimeError> { - let _memory = &self.memory; - - let obj0 = self_; - let handle0 = { - let state = self.env.as_mut(store); - state.resource_slab0.clone(obj0.0)?; - state.index_slab0.insert(obj0.0) - }; - let result1 = self.func_descriptor_fadvise.call( - store, - handle0 as i32, - wit_bindgen_wasmer::rt::as_i64(offset), - wit_bindgen_wasmer::rt::as_i64(len), - advice as i32, - )?; - let load2 = unsafe { _memory.data_unchecked_mut(&store.as_store_ref()) } - .load::(result1 + 0)?; - Ok(match i32::from(load2) { - 0 => Ok(()), - 1 => Err({ - let load3 = unsafe { _memory.data_unchecked_mut(&store.as_store_ref()) } - .load::(result1 + 1)?; - match i32::from(load3) { - 0 => Errno::Success, - 1 => Errno::Toobig, - 2 => Errno::Access, - 3 => Errno::Addrinuse, - 4 => Errno::Addrnotavail, - 5 => Errno::Afnosupport, - 6 => Errno::Again, - 7 => Errno::Already, - 8 => Errno::Badmsg, - 9 => Errno::Busy, - 10 => Errno::Canceled, - 11 => Errno::Child, - 12 => Errno::Connaborted, - 13 => Errno::Connrefused, - 14 => Errno::Connreset, - 15 => Errno::Deadlk, - 16 => Errno::Destaddrreq, - 17 => Errno::Dom, - 18 => Errno::Dquot, - 19 => Errno::Exist, - 20 => Errno::Fault, - 21 => Errno::Fbig, - 22 => Errno::Hostunreach, - 23 => Errno::Idrm, - 24 => Errno::Ilseq, - 25 => Errno::Inprogress, - 26 => Errno::Intr, - 27 => Errno::Inval, - 28 => Errno::Io, - 29 => Errno::Isconn, - 30 => Errno::Isdir, - 31 => Errno::Loop, - 32 => Errno::Mfile, - 33 => Errno::Mlink, - 34 => Errno::Msgsize, - 35 => Errno::Multihop, - 36 => Errno::Nametoolong, - 37 => Errno::Netdown, - 38 => Errno::Netreset, - 39 => Errno::Netunreach, - 40 => Errno::Nfile, - 41 => Errno::Nobufs, - 42 => Errno::Nodev, - 43 => Errno::Noent, - 44 => Errno::Noexec, - 45 => Errno::Nolck, - 46 => Errno::Nolink, - 47 => Errno::Nomem, - 48 => Errno::Nomsg, - 49 => Errno::Noprotoopt, - 50 => Errno::Nospc, - 51 => Errno::Nosys, - 52 => Errno::Notconn, - 53 => Errno::Notdir, - 54 => Errno::Notempty, - 55 => Errno::Notrecoverable, - 56 => Errno::Notsock, - 57 => Errno::Notsup, - 58 => Errno::Notty, - 59 => Errno::Nxio, - 60 => Errno::Overflow, - 61 => Errno::Ownerdead, - 62 => Errno::Perm, - 63 => Errno::Pipe, - 64 => Errno::Proto, - 65 => Errno::Protonosupport, - 66 => Errno::Prototype, - 67 => Errno::Range, - 68 => Errno::Rofs, - 69 => Errno::Spipe, - 70 => Errno::Srch, - 71 => Errno::Stale, - 72 => Errno::Timedout, - 73 => Errno::Txtbsy, - 74 => Errno::Xdev, - _ => return Err(invalid_variant("Errno")), - } - }), - _ => return Err(invalid_variant("expected")), - }) + Advice::DontNeed => { + f.debug_tuple("Advice::DontNeed").finish() } - - /// Drops the host-owned handle to the resource - /// specified. - /// - /// Note that this may execute the WebAssembly-defined - /// destructor for this type. This also may not run - /// the destructor if there are still other references - /// to this type. - pub fn drop_descriptor( - &self, - store: &mut wasmer::Store, - val: Descriptor, - ) -> Result<(), wasmer::RuntimeError> { - let state = self.env.as_mut(store); - let wasm = match state.resource_slab0.drop(val.0) { - Some(val) => val, - None => return Ok(()), - }; - let dtor0 = state.dtor0.get().unwrap().clone(); - dtor0.call(store, wasm)?; - Ok(()) + Advice::NoReuse => { + f.debug_tuple("Advice::NoReuse").finish() } + } + } + } + /// A descriptor is a reference to a filesystem object, which may be a file, + /// directory, named pipe, special file, or other object on which filesystem + /// calls may be made. + #[derive(Debug)] + pub struct Descriptor(wit_bindgen_wasmer::rt::ResourceIndex); + + /// Auxiliary data associated with the wasm exports. + #[derive(Default)] + pub struct WasiFilesystemData { + + index_slab0: wit_bindgen_wasmer::rt::IndexSlab, + resource_slab0: wit_bindgen_wasmer::rt::ResourceSlab, + dtor0: OnceCell>, + } + + pub struct WasiFilesystem { + #[allow(dead_code)] + env: wasmer::FunctionEnv, + func_descriptor_fadvise: wasmer::TypedFunction<(i32,i64,i64,i32,), i32>, + memory: wasmer::Memory, + } + impl WasiFilesystem { + + /// Adds any intrinsics, if necessary for this exported wasm + /// functionality to the `ImportObject` provided. + /// + /// This function returns the `WasiFilesystemData` which needs to be + /// passed through to `WasiFilesystem::new`. + fn add_to_imports( + mut store: impl wasmer::AsStoreMut, + imports: &mut wasmer::Imports, + ) -> wasmer::FunctionEnv { + let env = wasmer::FunctionEnv::new(&mut store, WasiFilesystemData::default()); + let mut canonical_abi = imports.get_namespace_exports("canonical_abi").unwrap_or_else(wasmer::Exports::new); + + canonical_abi.insert( + "resource_drop_descriptor", + wasmer::Function::new_typed_with_env( + &mut store, + &env, + move |mut store: wasmer::FunctionEnvMut, idx: u32| -> Result<(), wasmer::RuntimeError> { + let resource_idx = store.data_mut().index_slab0.remove(idx)?; + let wasm = match store.data_mut().resource_slab0.drop(resource_idx) { + Some(wasm) => wasm, + None => return Ok(()), + }; + let dtor = store.data_mut().dtor0.get().unwrap().clone(); + dtor.call(&mut store, wasm)?; + Ok(()) + }, + ) + ); + canonical_abi.insert( + "resource_clone_descriptor", + wasmer::Function::new_typed_with_env( + &mut store, + &env, + move |mut store: wasmer::FunctionEnvMut, idx: u32| -> Result { + let state = &mut *store.data_mut(); + let resource_idx = state.index_slab0.get(idx)?; + state.resource_slab0.clone(resource_idx)?; + Ok(state.index_slab0.insert(resource_idx)) + }, + ) + ); + canonical_abi.insert( + "resource_get_descriptor", + wasmer::Function::new_typed_with_env( + &mut store, + &env, + move |mut store: wasmer::FunctionEnvMut, idx: u32| -> Result { + let state = &mut *store.data_mut(); + let resource_idx = state.index_slab0.get(idx)?; + Ok(state.resource_slab0.get(resource_idx)) + }, + ) + ); + canonical_abi.insert( + "resource_new_descriptor", + wasmer::Function::new_typed_with_env( + &mut store, + &env, + move |mut store: wasmer::FunctionEnvMut, val: i32| -> Result { + let state = &mut *store.data_mut(); + let resource_idx = state.resource_slab0.insert(val); + Ok(state.index_slab0.insert(resource_idx)) + }, + ) + ); + imports.register_namespace("canonical_abi", canonical_abi); + env + } + + /// Instantiates the provided `module` using the specified + /// parameters, wrapping up the result in a structure that + /// translates between wasm and the host. + /// + /// The `imports` provided will have intrinsics added to it + /// automatically, so it's not necessary to call + /// `add_to_imports` beforehand. This function will + /// instantiate the `module` otherwise using `imports`, and + /// both an instance of this structure and the underlying + /// `wasmer::Instance` will be returned. + pub fn instantiate( + mut store: impl wasmer::AsStoreMut, + module: &wasmer::Module, + imports: &mut wasmer::Imports, + ) -> anyhow::Result<(Self, wasmer::Instance)> { + let env = Self::add_to_imports(&mut store, imports); + let instance = wasmer::Instance::new( + &mut store, module, &*imports)?; + { + let dtor0 = instance + .exports + .get_typed_function( + &store, + "canonical_abi_drop_descriptor", + )? + .clone(); + + env + .as_mut(&mut store) + .dtor0 + .set(dtor0) + .map_err(|_e| anyhow::anyhow!("Couldn't set canonical_abi_drop_descriptor"))?; + } + + Ok((Self::new(store, &instance, env)?, instance)) + } + + /// Low-level creation wrapper for wrapping up the exports + /// of the `instance` provided in this structure of wasm + /// exports. + /// + /// This function will extract exports from the `instance` + /// and wrap them all up in the returned structure which can + /// be used to interact with the wasm module. + pub fn new( + store: impl wasmer::AsStoreMut, + _instance: &wasmer::Instance, + env: wasmer::FunctionEnv, + ) -> Result { + let func_descriptor_fadvise= _instance.exports.get_typed_function(&store, "descriptor::fadvise")?; + let memory= _instance.exports.get_memory("memory")?.clone(); + Ok(WasiFilesystem{ + func_descriptor_fadvise, + memory, + env, + }) + } + /// Provide file advisory information on a descriptor. + /// + /// This is similar to `posix_fadvise` in POSIX. + pub fn descriptor_fadvise(&self, store: &mut wasmer::Store,self_: & Descriptor,offset: u64,len: u64,advice: Advice,)-> Result, wasmer::RuntimeError> { + let _memory = &self.memory; + + let obj0 = self_; + let handle0 = { + let state = self.env.as_mut(store); + state.resource_slab0.clone(obj0.0)?; + state.index_slab0.insert(obj0.0) + }; + let result1 = self.func_descriptor_fadvise.call(store, handle0 as i32, wit_bindgen_wasmer::rt::as_i64(offset), wit_bindgen_wasmer::rt::as_i64(len), advice as i32, )?; + let _memory_view = _memory.view(&store); + let load2 = unsafe { _memory_view.data_unchecked_mut() }.load::(result1 + 0)?; + Ok(match i32::from(load2) { + 0 => Ok(()), + 1 => Err({ + let _memory_view = _memory.view(&store); + let load3 = unsafe { _memory_view.data_unchecked_mut() }.load::(result1 + 1)?; + match i32::from(load3) { + 0 => Errno::Success, + 1 => Errno::Toobig, + 2 => Errno::Access, + 3 => Errno::Addrinuse, + 4 => Errno::Addrnotavail, + 5 => Errno::Afnosupport, + 6 => Errno::Again, + 7 => Errno::Already, + 8 => Errno::Badmsg, + 9 => Errno::Busy, + 10 => Errno::Canceled, + 11 => Errno::Child, + 12 => Errno::Connaborted, + 13 => Errno::Connrefused, + 14 => Errno::Connreset, + 15 => Errno::Deadlk, + 16 => Errno::Destaddrreq, + 17 => Errno::Dom, + 18 => Errno::Dquot, + 19 => Errno::Exist, + 20 => Errno::Fault, + 21 => Errno::Fbig, + 22 => Errno::Hostunreach, + 23 => Errno::Idrm, + 24 => Errno::Ilseq, + 25 => Errno::Inprogress, + 26 => Errno::Intr, + 27 => Errno::Inval, + 28 => Errno::Io, + 29 => Errno::Isconn, + 30 => Errno::Isdir, + 31 => Errno::Loop, + 32 => Errno::Mfile, + 33 => Errno::Mlink, + 34 => Errno::Msgsize, + 35 => Errno::Multihop, + 36 => Errno::Nametoolong, + 37 => Errno::Netdown, + 38 => Errno::Netreset, + 39 => Errno::Netunreach, + 40 => Errno::Nfile, + 41 => Errno::Nobufs, + 42 => Errno::Nodev, + 43 => Errno::Noent, + 44 => Errno::Noexec, + 45 => Errno::Nolck, + 46 => Errno::Nolink, + 47 => Errno::Nomem, + 48 => Errno::Nomsg, + 49 => Errno::Noprotoopt, + 50 => Errno::Nospc, + 51 => Errno::Nosys, + 52 => Errno::Notconn, + 53 => Errno::Notdir, + 54 => Errno::Notempty, + 55 => Errno::Notrecoverable, + 56 => Errno::Notsock, + 57 => Errno::Notsup, + 58 => Errno::Notty, + 59 => Errno::Nxio, + 60 => Errno::Overflow, + 61 => Errno::Ownerdead, + 62 => Errno::Perm, + 63 => Errno::Pipe, + 64 => Errno::Proto, + 65 => Errno::Protonosupport, + 66 => Errno::Prototype, + 67 => Errno::Range, + 68 => Errno::Rofs, + 69 => Errno::Spipe, + 70 => Errno::Srch, + 71 => Errno::Stale, + 72 => Errno::Timedout, + 73 => Errno::Txtbsy, + 74 => Errno::Xdev, + _ => return Err(invalid_variant("Errno")), + } + }), + _ => return Err(invalid_variant("expected")), + }) + } + + /// Drops the host-owned handle to the resource + /// specified. + /// + /// Note that this may execute the WebAssembly-defined + /// destructor for this type. This also may not run + /// the destructor if there are still other references + /// to this type. + pub fn drop_descriptor( + &self, + store: &mut wasmer::Store, + val: Descriptor, + ) -> Result<(), wasmer::RuntimeError> { + let state = self.env.as_mut(store); + let wasm = match state.resource_slab0.drop(val.0) { + Some(val) => val, + None => return Ok(()), + }; + let dtor0 = state.dtor0.get().unwrap().clone(); + dtor0.call(store, wasm)?; + Ok(()) } - #[allow(unused_imports)] - use wasmer::AsStoreMut as _; - #[allow(unused_imports)] - use wasmer::AsStoreRef as _; - use wit_bindgen_wasmer::once_cell::unsync::OnceCell; - use wit_bindgen_wasmer::rt::invalid_variant; - use wit_bindgen_wasmer::rt::RawMem; + } + use wit_bindgen_wasmer::once_cell::unsync::OnceCell; + #[allow(unused_imports)] + use wasmer::AsStoreMut as _; + #[allow(unused_imports)] + use wasmer::AsStoreRef as _; + use wit_bindgen_wasmer::rt::RawMem; + use wit_bindgen_wasmer::rt::invalid_variant; } diff --git a/lib/wasi-types-generated/src/lib.rs b/lib/wasi-types-generated/src/lib.rs index f1f0747b9b3..892ac88634f 100644 --- a/lib/wasi-types-generated/src/lib.rs +++ b/lib/wasi-types-generated/src/lib.rs @@ -1 +1,3 @@ mod bindings; + +pub use bindings::*; diff --git a/lib/wasi-types-generated/wit/wasi-snapshot0.wit b/lib/wasi-types-generated/wit/wasi-snapshot0.wit new file mode 100644 index 00000000000..e942f04f3dc --- /dev/null +++ b/lib/wasi-types-generated/wit/wasi-snapshot0.wit @@ -0,0 +1,749 @@ +// Extracted from https://github.com/WebAssembly/WASI/blob/main/phases/old/snapshot_0/witx/typenames.witx + +type size = u32 + +/// Non-negative file size or length of a region within a file. +type filesize = u64 + +/// Timestamp in nanoseconds. +type timestamp = u64 + + + +// ;;; Identifiers for clocks. +// (typename $clockid +// (enum (@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 +// ) +// ) + + + + +/// 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 type size + //enum (@witx tag u16) + + /// No error occurred. System call completed successfully. + success, + /// Argument list too long. + toobig, + /// Permission denied. + acces, + /// 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, +} + +/// 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, +} + +// ;;; A file descriptor handle. +// (typename $fd (handle)) +// +// ;;; A region of memory for scatter/gather reads. +// (typename $iovec +// (record +// ;;; The address of the buffer to be filled. +// (field $buf (@witx pointer u8)) +// ;;; The length of the buffer to be filled. +// (field $buf_len $size) +// ) +// ) +// +// ;;; A region of memory for scatter/gather writes. +// (typename $ciovec +// (record +// ;;; The address of the buffer to be written. +// (field $buf (@witx const_pointer u8)) +// ;;; The length of the buffer to be written. +// (field $buf_len $size) +// ) +// ) +// +// (typename $iovec_array (list $iovec)) +// (typename $ciovec_array (list $ciovec)) +// +// ;;; Relative offset within a file. +// (typename $filedelta s64) +// +// ;;; The position relative to which to set the offset of the file descriptor. +// (typename $whence +// (enum (@witx tag u8) +// ;;; Seek relative to current position. +// $cur +// ;;; Seek relative to end-of-file. +// $end +// ;;; Seek relative to start-of-file. +// $set +// ) +// ) +// +// ;;; A reference to the offset of a directory entry. +// (typename $dircookie u64) +// +// ;;; The type for the `dirent::d_namlen` field of `dirent` struct. +// (typename $dirnamlen u32) +// +// ;;; File serial number that is unique within its file system. +// (typename $inode u64) + +/// The type of a file descriptor or file. +enum filetype { + // TODO: wit appears to not have support for enum type size + //enum (@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, +} + +// ;;; A directory entry. +// (typename $dirent +// (record +// ;;; The offset of the next directory entry stored in this directory. +// (field $d_next $dircookie) +// ;;; The serial number of the file referred to by this directory entry. +// (field $d_ino $inode) +// ;;; The length of the name of the directory entry. +// (field $d_namlen $dirnamlen) +// ;;; The type of the file referred to by this directory entry. +// (field $d_type $filetype) +// ) +// ) +// +// ;;; File or memory access pattern advisory information. +// (typename $advice +// (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 flag type size + //flags (@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, +} + +// ;;; 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. +// (typename $device u64) +// +// ;;; Which file time attributes to adjust. +// (typename $fstflags +// (flags (@witx repr u16) +// ;;; Adjust the last data access timestamp to the value stored in `filestat::atim`. +// $atim +// ;;; Adjust the last data access timestamp to the time of clock `clockid::realtime`. +// $atim_now +// ;;; Adjust the last data modification timestamp to the value stored in `filestat::mtim`. +// $mtim +// ;;; Adjust the last data modification timestamp to the time of clock `clockid::realtime`. +// $mtim_now +// ) +// ) +// +// ;;; Flags determining the method of how paths are resolved. +// (typename $lookupflags +// (flags (@witx repr u32) +// ;;; As long as the resolved path corresponds to a symbolic link, it is expanded. +// $symlink_follow +// ) +// ) +// +// ;;; Open flags used by `path_open`. +// (typename $oflags +// (flags (@witx repr u16) +// ;;; Create file if it does not exist. +// $creat +// ;;; Fail if not a directory. +// $directory +// ;;; Fail if file already exists. +// $excl +// ;;; Truncate file to size 0. +// $trunc +// ) +// ) +// +// ;;; Number of hard links to an inode. +// (typename $linkcount u32) +// +// ;;; File attributes. +// (typename $filestat +// (record +// ;;; Device ID of device containing the file. +// (field $dev $device) +// ;;; File serial number. +// (field $ino $inode) +// ;;; File type. +// (field $filetype $filetype) +// ;;; Number of hard links to the file. +// (field $nlink $linkcount) +// ;;; For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link. +// (field $size $filesize) +// ;;; Last data access timestamp. +// (field $atim $timestamp) +// ;;; Last data modification timestamp. +// (field $mtim $timestamp) +// ;;; Last file status change timestamp. +// (field $ctim $timestamp) +// ) +// ) +// +// ;;; User-provided value that may be attached to objects that is retained when +// ;;; extracted from the implementation. +// (typename $userdata u64) +// +// ;;; Type of a subscription to an event or its occurrence. +// (typename $eventtype +// (enum (@witx tag u8) +// ;;; The time value of clock `subscription_clock::id` has +// ;;; reached timestamp `subscription_clock::timeout`. +// $clock +// ;;; File descriptor `subscription_fd_readwrite::file_descriptor` has data +// ;;; available for reading. This event always triggers for regular files. +// $fd_read +// ;;; File descriptor `subscription_fd_readwrite::file_descriptor` has capacity +// ;;; available for writing. This event always triggers for regular files. +// $fd_write +// ) +// ) +// +// ;;; The state of the file descriptor subscribed to with +// ;;; `eventtype::fd_read` or `eventtype::fd_write`. +// (typename $eventrwflags +// (flags (@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 +// (typename $event_fd_readwrite +// (record +// ;;; The number of bytes available for reading or writing. +// (field $nbytes $filesize) +// ;;; The state of the file descriptor. +// (field $flags $eventrwflags) +// ) +// ) +// +// ;;; An event that occurred. +// (typename $event +// (record +// ;;; User-provided value that got attached to `subscription::userdata`. +// (field $userdata $userdata) +// ;;; If non-zero, an error that occurred while processing the subscription request. +// (field $error $errno) +// ;;; The type of event that occured +// (field $type $eventtype) +// ;;; The contents of the event, if it is an `eventtype::fd_read` or +// ;;; `eventtype::fd_write`. `eventtype::clock` events ignore this field. +// (field $fd_readwrite $event_fd_readwrite) +// ) +// ) +// +// ;;; Flags determining how to interpret the timestamp provided in +// ;;; `subscription_clock::timeout`. +// (typename $subclockflags +// (flags (@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`. +// (typename $subscription_clock +// (record +// ;;; The user-defined unique identifier of the clock. +// (field $identifier $userdata) +// ;;; The clock against which to compare the timestamp. +// (field $id $clockid) +// ;;; The absolute or relative timestamp. +// (field $timeout $timestamp) +// ;;; The amount of time that the implementation may wait additionally +// ;;; to coalesce with other events. +// (field $precision $timestamp) +// ;;; Flags specifying whether the timeout is absolute or relative +// (field $flags $subclockflags) +// ) +// ) +// +// ;;; The contents of a `subscription` when the variant is +// ;;; `eventtype::fd_read` or `eventtype::fd_write`. +// (typename $subscription_fd_readwrite +// (record +// ;;; The file descriptor on which to wait for it to become ready for reading or writing. +// (field $file_descriptor $fd) +// ) +// ) +// +// ;;; The contents of a `subscription`. +// (typename $subscription_u +// (union (@witx tag $eventtype) +// $subscription_clock +// $subscription_fd_readwrite +// $subscription_fd_readwrite +// ) +// ) +// +// ;;; Subscription to an event. +// (typename $subscription +// (record +// ;;; User-provided value that is attached to the subscription in the +// ;;; implementation and returned through `event::userdata`. +// (field $userdata $userdata) +// ;;; The type of the event to which to subscribe. +// (field $u $subscription_u) +// ) +// ) +// +// ;;; Exit code generated by a process when exiting. +// (typename $exitcode u32) +// +// ;;; Signal condition. +// (typename $signal +// (enum (@witx tag u8) +// ;;; No signal. Note that POSIX has special semantics for `kill(pid, 0)`, +// ;;; so this value is reserved. +// $none +// ;;; Hangup. +// ;;; Action: Terminates the process. +// $hup +// ;;; Terminate interrupt signal. +// ;;; Action: Terminates the process. +// $int +// ;;; Terminal quit signal. +// ;;; Action: Terminates the process. +// $quit +// ;;; Illegal instruction. +// ;;; Action: Terminates the process. +// $ill +// ;;; Trace/breakpoint trap. +// ;;; Action: Terminates the process. +// $trap +// ;;; Process abort signal. +// ;;; Action: Terminates the process. +// $abrt +// ;;; Access to an undefined portion of a memory object. +// ;;; Action: Terminates the process. +// $bus +// ;;; Erroneous arithmetic operation. +// ;;; Action: Terminates the process. +// $fpe +// ;;; Kill. +// ;;; Action: Terminates the process. +// $kill +// ;;; User-defined signal 1. +// ;;; Action: Terminates the process. +// $usr1 +// ;;; Invalid memory reference. +// ;;; Action: Terminates the process. +// $segv +// ;;; User-defined signal 2. +// ;;; Action: Terminates the process. +// $usr2 +// ;;; Write on a pipe with no one to read it. +// ;;; Action: Ignored. +// $pipe +// ;;; Alarm clock. +// ;;; Action: Terminates the process. +// $alrm +// ;;; Termination signal. +// ;;; Action: Terminates the process. +// $term +// ;;; Child process terminated, stopped, or continued. +// ;;; Action: Ignored. +// $chld +// ;;; Continue executing, if stopped. +// ;;; Action: Continues executing, if stopped. +// $cont +// ;;; Stop executing. +// ;;; Action: Stops executing. +// $stop +// ;;; Terminal stop signal. +// ;;; Action: Stops executing. +// $tstp +// ;;; Background process attempting read. +// ;;; Action: Stops executing. +// $ttin +// ;;; Background process attempting write. +// ;;; Action: Stops executing. +// $ttou +// ;;; High bandwidth data is available at a socket. +// ;;; Action: Ignored. +// $urg +// ;;; CPU time limit exceeded. +// ;;; Action: Terminates the process. +// $xcpu +// ;;; File size limit exceeded. +// ;;; Action: Terminates the process. +// $xfsz +// ;;; Virtual timer expired. +// ;;; Action: Terminates the process. +// $vtalrm +// ;;; Profiling timer expired. +// ;;; Action: Terminates the process. +// $prof +// ;;; Window changed. +// ;;; Action: Ignored. +// $winch +// ;;; I/O possible. +// ;;; Action: Terminates the process. +// $poll +// ;;; Power failure. +// ;;; Action: Terminates the process. +// $pwr +// ;;; Bad system call. +// ;;; Action: Terminates the process. +// $sys +// ) +// ) +// +// ;;; Flags provided to `sock_recv`. +// (typename $riflags +// (flags (@witx repr u16) +// ;;; Returns the message without removing it from the socket's receive queue. +// $recv_peek +// ;;; On byte-stream sockets, block until the full amount of data can be returned. +// $recv_waitall +// ) +// ) +// +// ;;; Flags returned by `sock_recv`. +// (typename $roflags +// (flags (@witx repr u16) +// ;;; Returned by `sock_recv`: Message data has been truncated. +// $recv_data_truncated +// ) +// ) +// +// ;;; Flags provided to `sock_send`. As there are currently no flags +// ;;; defined, it must be set to zero. +// (typename $siflags u16) +// +// ;;; Which channels on a socket to shut down. +// (typename $sdflags +// (flags (@witx repr u8) +// ;;; Disables further receive operations. +// $rd +// ;;; Disables further send operations. +// $wr +// ) +// ) +// +// ;;; Identifiers for preopened capabilities. +// (typename $preopentype +// (enum (@witx tag u8) +// ;;; A pre-opened directory. +// $dir +// ) +// ) +// +// ;;; The contents of a $prestat when type is `preopentype::dir`. +// (typename $prestat_dir +// (record +// ;;; The length of the directory name for use with `fd_prestat_dir_name`. +// (field $pr_name_len $size) +// ) +// ) +// +// ;;; Information about a pre-opened capability. +// (typename $prestat +// (union (@witx tag $preopentype) +// $prestat_dir +// ) +// ) From 1a48fab797ce6445c9f77d196398c669640edd6d Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Tue, 16 Aug 2022 12:42:16 +0200 Subject: [PATCH 03/84] WIP --- Cargo.lock | 18 +- lib/wasi-types-generated/Cargo.toml | 1 + lib/wasi-types-generated/src/lib.rs | 8 + lib/wasi-types/Cargo.toml | 1 + lib/wasi-types/src/error.rs | 79 -- lib/wasi-types/src/event.rs | 3 +- lib/wasi-types/src/subscription.rs | 9 +- lib/wasi/Cargo.toml | 1 + lib/wasi/src/lib.rs | 10 +- lib/wasi/src/macros.rs | 10 +- lib/wasi/src/runtime.rs | 9 +- lib/wasi/src/state/mod.rs | 120 +-- lib/wasi/src/state/pipe.rs | 12 +- lib/wasi/src/state/socket.rs | 347 +++++---- lib/wasi/src/state/types.rs | 139 ++-- lib/wasi/src/syscalls/legacy/snapshot0.rs | 10 +- lib/wasi/src/syscalls/mod.rs | 890 ++++++++++++---------- lib/wasi/src/syscalls/unix/mod.rs | 9 +- lib/wasi/src/syscalls/wasix32.rs | 198 ++--- lib/wasi/src/syscalls/wasix64.rs | 198 ++--- lib/wasi/src/utils.rs | 42 +- 21 files changed, 1074 insertions(+), 1040 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8020f257a28..9c195462afb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2847,13 +2847,6 @@ dependencies = [ "wast 24.0.0", ] -[[package]] -name = "wasi-types-generated" -version = "0.1.0" -dependencies = [ - "wit-bindgen-wasmer", -] - [[package]] name = "wasm-bindgen" version = "0.2.82" @@ -3466,6 +3459,7 @@ dependencies = [ "wasmer-vnet", "wasmer-wasi-local-networking", "wasmer-wasi-types", + "wasmer-wasi-types-generated", "winapi", ] @@ -3501,6 +3495,16 @@ dependencies = [ "time", "wasmer-derive 3.0.0-beta", "wasmer-types 3.0.0-beta", + "wasmer-wasi-types-generated", +] + +[[package]] +name = "wasmer-wasi-types-generated" +version = "3.0.0-beta" +dependencies = [ + "wasmer-derive 3.0.0-beta", + "wasmer-types 3.0.0-beta", + "wit-bindgen-wasmer", ] [[package]] diff --git a/lib/wasi-types-generated/Cargo.toml b/lib/wasi-types-generated/Cargo.toml index a56be5143df..2ba55270724 100644 --- a/lib/wasi-types-generated/Cargo.toml +++ b/lib/wasi-types-generated/Cargo.toml @@ -7,6 +7,7 @@ edition = "2018" [dependencies] wasmer-derive = { path = "../derive", version = "=3.0.0-beta" } +wasmer-types = { path = "../types", version = "=3.0.0-beta" } [dependencies.wit-bindgen-wasmer] path = "/home/silwol/Projects/wasmerio/wit-bindgen/crates/wasmer" diff --git a/lib/wasi-types-generated/src/lib.rs b/lib/wasi-types-generated/src/lib.rs index 892ac88634f..bf524665ea7 100644 --- a/lib/wasi-types-generated/src/lib.rs +++ b/lib/wasi-types-generated/src/lib.rs @@ -1,3 +1,11 @@ mod bindings; pub use bindings::*; + +use std::mem::MaybeUninit; +use wasmer_types::ValueType; + +unsafe impl ValueType for wasi_snapshot0::Errno { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} diff --git a/lib/wasi-types/Cargo.toml b/lib/wasi-types/Cargo.toml index d89a5410ab2..bfcef194396 100644 --- a/lib/wasi-types/Cargo.toml +++ b/lib/wasi-types/Cargo.toml @@ -13,6 +13,7 @@ edition = "2018" [dependencies] wasmer-types = { path = "../types", version = "=3.0.0-beta" } wasmer-derive = { path = "../derive", version = "=3.0.0-beta" } +wasmer-wasi-types-generated = { path = "../wasi-types-generated", version = "=3.0.0-beta" } serde = { version = "1.0", features = ["derive"], optional = true } byteorder = "1.3" time = "0.2" diff --git a/lib/wasi-types/src/error.rs b/lib/wasi-types/src/error.rs index fa1bf528126..6837314eabd 100644 --- a/lib/wasi-types/src/error.rs +++ b/lib/wasi-types/src/error.rs @@ -1,82 +1,3 @@ -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; diff --git a/lib/wasi-types/src/event.rs b/lib/wasi-types/src/event.rs index c368f5b9b5a..ff28b7508f0 100644 --- a/lib/wasi-types/src/event.rs +++ b/lib/wasi-types/src/event.rs @@ -5,6 +5,7 @@ use std::{ }; use wasmer_derive::ValueType; use wasmer_types::ValueType; +use wasmer_wasi_types_generated::wasi_snapshot0; #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] #[repr(C)] @@ -50,7 +51,7 @@ impl EventEnum { #[repr(C)] pub struct __wasi_event_t { pub userdata: __wasi_userdata_t, - pub error: __wasi_errno_t, + pub error: wasi_snapshot0::Errno, pub type_: __wasi_eventtype_t, pub u: __wasi_event_u, } diff --git a/lib/wasi-types/src/subscription.rs b/lib/wasi-types/src/subscription.rs index be8d0c4768e..690b77fa542 100644 --- a/lib/wasi-types/src/subscription.rs +++ b/lib/wasi-types/src/subscription.rs @@ -4,6 +4,7 @@ use std::fmt; use std::mem::{self, MaybeUninit}; use wasmer_derive::ValueType; use wasmer_types::ValueType; +use wasmer_wasi_types_generated::wasi_snapshot0; pub type __wasi_subclockflags_t = u16; pub const __WASI_SUBSCRIPTION_CLOCK_ABSTIME: u16 = 1 << 0; @@ -64,7 +65,7 @@ pub struct WasiSubscription { } impl TryFrom<__wasi_subscription_t> for WasiSubscription { - type Error = __wasi_errno_t; + type Error = wasi_snapshot0::Errno; fn try_from(ws: __wasi_subscription_t) -> Result { Ok(Self { @@ -73,14 +74,14 @@ impl TryFrom<__wasi_subscription_t> for WasiSubscription { __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), + _ => return Err(wasi_snapshot0::Errno::Inval), }, }) } } impl TryFrom for __wasi_subscription_t { - type Error = __wasi_errno_t; + type Error = wasi_snapshot0::Errno; fn try_from(ws: WasiSubscription) -> Result { #[allow(unreachable_patterns)] @@ -94,7 +95,7 @@ impl TryFrom for __wasi_subscription_t { __WASI_EVENTTYPE_FD_WRITE, __wasi_subscription_u { fd_readwrite: rw }, ), - _ => return Err(__WASI_EINVAL), + _ => return Err(wasi_snapshot0::Errno::Inval), }; Ok(Self { diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml index bfa746e2921..7b3e248be03 100644 --- a/lib/wasi/Cargo.toml +++ b/lib/wasi/Cargo.toml @@ -25,6 +25,7 @@ wasmer-vfs = { path = "../vfs", version = "=3.0.0-beta", default-features = fals wasmer-vbus = { path = "../vbus", version = "=3.0.0-beta", default-features = false } wasmer-vnet = { path = "../vnet", version = "=3.0.0-beta", default-features = false } wasmer-wasi-local-networking = { path = "../wasi-local-networking", version = "=3.0.0-beta", default-features = false, optional = true } +wasmer-wasi-types-generated = { path = "../wasi-types-generated", version = "=3.0.0-beta", default-features = false } typetag = { version = "0.1", optional = true } serde = { version = "1.0", default-features = false, features = ["derive"], optional = true } bincode = { version = "1.3", optional = true } diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index 4daeb25a47d..d339b807be9 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -773,12 +773,12 @@ fn generate_import_object_wasix64_v1( } } -fn mem_error_to_wasi(err: MemoryAccessError) -> types::__wasi_errno_t { +fn mem_error_to_wasi(err: MemoryAccessError) -> types::wasi_snapshot0::Errno { match err { - MemoryAccessError::HeapOutOfBounds => types::__WASI_EFAULT, - MemoryAccessError::Overflow => types::__WASI_EOVERFLOW, - MemoryAccessError::NonUtf8String => types::__WASI_EINVAL, - _ => types::__WASI_EINVAL, + MemoryAccessError::HeapOutOfBounds => types::wasi_snapshot0::Errno::Fault, + MemoryAccessError::Overflow => types::wasi_snapshot0::Errno::Overflow, + MemoryAccessError::NonUtf8String => types::wasi_snapshot0::Errno::Inval, + _ => types::wasi_snapshot0::Errno::Inval, } } diff --git a/lib/wasi/src/macros.rs b/lib/wasi/src/macros.rs index b9ec4245597..b4e58882cd0 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_snapshot0::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_snapshot0::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_snapshot0::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_snapshot0::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_snapshot0::Errno> = $expr; match res { Ok(val) => { tracing::trace!("wasi::wasi_try_bus::val: {:?}", val); diff --git a/lib/wasi/src/runtime.rs b/lib/wasi/src/runtime.rs index 00c208bd166..aa8f58066f5 100644 --- a/lib/wasi/src/runtime.rs +++ b/lib/wasi/src/runtime.rs @@ -4,6 +4,7 @@ use std::sync::atomic::{AtomicU32, Ordering}; use thiserror::Error; use wasmer_vbus::{UnsupportedVirtualBus, VirtualBus}; use wasmer_vnet::VirtualNetworking; +use wasmer_wasi_types_generated::wasi_snapshot0; use super::types::*; use super::WasiError; @@ -17,11 +18,11 @@ pub enum WasiThreadError { MethodNotFound, } -impl From for __wasi_errno_t { - fn from(a: WasiThreadError) -> __wasi_errno_t { +impl From for wasi_snapshot0::Errno { + fn from(a: WasiThreadError) -> wasi_snapshot0::Errno { match a { - WasiThreadError::Unsupported => __WASI_ENOTSUP, - WasiThreadError::MethodNotFound => __WASI_EINVAL, + WasiThreadError::Unsupported => wasi_snapshot0::Errno::Notsup, + WasiThreadError::MethodNotFound => wasi_snapshot0::Errno::Inval, } } } diff --git a/lib/wasi/src/state/mod.rs b/lib/wasi/src/state/mod.rs index 4b1a75a718d..a91a87a9a1d 100644 --- a/lib/wasi/src/state/mod.rs +++ b/lib/wasi/src/state/mod.rs @@ -52,6 +52,7 @@ use std::{ }; use tracing::{debug, trace}; use wasmer_vbus::BusSpawnedProcess; +use wasmer_wasi_types_generated::wasi_snapshot0; use wasmer_vfs::{FileSystem, FsError, OpenOptions, VirtualFile}; @@ -215,11 +216,13 @@ impl WasiInodes { pub fn get_inodeval( &self, inode: generational_arena::Index, - ) -> Result<&InodeVal, __wasi_errno_t> { + ) -> Result<&InodeVal, wasi_snapshot0::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(wasi_snapshot0::Errno::Badf) } } @@ -227,11 +230,13 @@ impl WasiInodes { pub fn get_inodeval_mut( &mut self, inode: generational_arena::Index, - ) -> Result<&mut InodeVal, __wasi_errno_t> { + ) -> Result<&mut InodeVal, wasi_snapshot0::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(wasi_snapshot0::Errno::Badf) } } @@ -812,7 +817,7 @@ impl WasiFs { &self, inodes: &WasiInodes, fd: __wasi_fd_t, - ) -> Result<__wasi_filesize_t, __wasi_errno_t> { + ) -> Result<__wasi_filesize_t, wasi_snapshot0::Errno> { let inode = self.get_fd_inode(fd)?; let mut guard = inodes.arena[inode].write(); let deref_mut = guard.deref_mut(); @@ -825,11 +830,11 @@ impl WasiFs { inodes.arena[inode].stat.write().unwrap().st_size = new_size; Ok(new_size as __wasi_filesize_t) } else { - Err(__WASI_EBADF) + Err(wasi_snapshot0::Errno::Badf) } } - Kind::Dir { .. } | Kind::Root { .. } => Err(__WASI_EISDIR), - _ => Err(__WASI_EINVAL), + Kind::Dir { .. } | Kind::Root { .. } => Err(wasi_snapshot0::Errno::Isdir), + _ => Err(wasi_snapshot0::Errno::Inval), } } @@ -844,7 +849,7 @@ impl WasiFs { &self, inodes: &mut WasiInodes, base: __wasi_fd_t, - ) -> Result<(Inode, String), __wasi_errno_t> { + ) -> Result<(Inode, String), wasi_snapshot0::Errno> { self.get_current_dir_inner(inodes, base, 0) } @@ -853,7 +858,7 @@ impl WasiFs { inodes: &mut WasiInodes, base: __wasi_fd_t, symlink_count: u32, - ) -> Result<(Inode, String), __wasi_errno_t> { + ) -> Result<(Inode, String), wasi_snapshot0::Errno> { let current_dir = { let guard = self.current_dir.lock().unwrap(); guard.clone() @@ -889,9 +894,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(wasi_snapshot0::Errno::Mlink); } let path: &Path = Path::new(path); @@ -920,7 +925,7 @@ impl WasiFs { cur_inode = *p; continue 'path_iter; } else { - return Err(__WASI_EACCES); + return Err(wasi_snapshot0::Errno::Acces); } } "." => continue 'path_iter, @@ -942,7 +947,7 @@ impl WasiFs { .fs_backing .symlink_metadata(&file) .ok() - .ok_or(__WASI_ENOENT)?; + .ok_or(wasi_snapshot0::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) @@ -1080,14 +1085,14 @@ impl WasiFs { { cur_inode = *entry; } else { - return Err(__WASI_ENOENT); + return Err(wasi_snapshot0::Errno::Noent); } } Kind::File { .. } | Kind::Socket { .. } | Kind::Pipe { .. } | Kind::EventNotifications { .. } => { - return Err(__WASI_ENOTDIR); + return Err(wasi_snapshot0::Errno::Notdir); } Kind::Symlink { base_po_dir, @@ -1151,7 +1156,7 @@ impl WasiFs { &self, inodes: &WasiInodes, path: &'path Path, - ) -> Result<(__wasi_fd_t, &'path Path), __wasi_errno_t> { + ) -> Result<(__wasi_fd_t, &'path Path), wasi_snapshot0::Errno> { enum BaseFdAndRelPath<'a> { None, BestMatch { @@ -1199,7 +1204,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(wasi_snapshot0::Errno::Inval), BaseFdAndRelPath::BestMatch { fd, rel_path, .. } => Ok((fd, rel_path)), } } @@ -1211,7 +1216,7 @@ impl WasiFs { inodes: &WasiInodes, fd: __wasi_fd_t, inode: Inode, - ) -> Result { + ) -> Result { let mut counter = 0; let base_inode = self.get_fd_inode(fd)?; let mut cur_inode = inode; @@ -1226,7 +1231,7 @@ impl WasiFs { cur_inode = *p; } } - _ => return Err(__WASI_EINVAL), + _ => return Err(wasi_snapshot0::Errno::Inval), } } @@ -1245,7 +1250,7 @@ impl WasiFs { base: __wasi_fd_t, 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 @@ -1264,12 +1269,12 @@ impl WasiFs { base: __wasi_fd_t, path: &Path, follow_symlinks: bool, - ) -> Result<(Inode, String), __wasi_errno_t> { + ) -> Result<(Inode, String), wasi_snapshot0::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(wasi_snapshot0::Errno::Inval)? .as_os_str() .to_string_lossy() .to_string(); @@ -1280,24 +1285,24 @@ impl WasiFs { .map(|v| (v, new_entity_name)) } - pub fn get_fd(&self, fd: __wasi_fd_t) -> Result { + pub fn get_fd(&self, fd: __wasi_fd_t) -> Result { self.fd_map .read() .unwrap() .get(&fd) - .ok_or(__WASI_EBADF) + .ok_or(wasi_snapshot0::Errno::Badf) .map(|a| a.clone()) } pub fn get_fd_inode( &self, fd: __wasi_fd_t, - ) -> Result { + ) -> Result { self.fd_map .read() .unwrap() .get(&fd) - .ok_or(__WASI_EBADF) + .ok_or(wasi_snapshot0::Errno::Badf) .map(|a| a.inode) } @@ -1305,7 +1310,7 @@ impl WasiFs { &self, inodes: &WasiInodes, fd: __wasi_fd_t, - ) -> Result<__wasi_filestat_t, __wasi_errno_t> { + ) -> Result<__wasi_filestat_t, wasi_snapshot0::Errno> { let inode = self.get_fd_inode(fd)?; Ok(*inodes.arena[inode].stat.read().unwrap().deref()) } @@ -1314,7 +1319,7 @@ impl WasiFs { &self, inodes: &WasiInodes, fd: __wasi_fd_t, - ) -> Result<__wasi_fdstat_t, __wasi_errno_t> { + ) -> Result<__wasi_fdstat_t, wasi_snapshot0::Errno> { match fd { __WASI_STDIN_FILENO => { return Ok(__wasi_fdstat_t { @@ -1373,7 +1378,7 @@ impl WasiFs { &self, inodes: &WasiInodes, fd: __wasi_fd_t, - ) -> Result<__wasi_prestat_t, __wasi_errno_t> { + ) -> Result<__wasi_prestat_t, wasi_snapshot0::Errno> { let inode = self.get_fd_inode(fd)?; trace!("in prestat_fd {:?}", self.get_fd(fd)?); @@ -1382,7 +1387,7 @@ impl WasiFs { if inode_val.is_preopened { Ok(self.prestat_fd_inner(inode_val)) } else { - Err(__WASI_EBADF) + Err(wasi_snapshot0::Errno::Badf) } } @@ -1397,7 +1402,7 @@ impl WasiFs { } } - pub fn flush(&self, inodes: &WasiInodes, fd: __wasi_fd_t) -> Result<(), __wasi_errno_t> { + pub fn flush(&self, inodes: &WasiInodes, fd: __wasi_fd_t) -> Result<(), wasi_snapshot0::Errno> { match fd { __WASI_STDIN_FILENO => (), __WASI_STDOUT_FILENO => inodes @@ -1405,17 +1410,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(wasi_snapshot0::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(wasi_snapshot0::Errno::Io)?, _ => { let fd = self.get_fd(fd)?; if fd.rights & __WASI_RIGHT_FD_DATASYNC == 0 { - return Err(__WASI_EACCES); + return Err(wasi_snapshot0::Errno::Acces); } let mut guard = inodes.arena[fd.inode].write(); @@ -1423,12 +1428,12 @@ impl WasiFs { match deref_mut { Kind::File { handle: Some(file), .. - } => file.flush().map_err(|_| __WASI_EIO)?, + } => file.flush().map_err(|_| wasi_snapshot0::Errno::Io)?, // TODO: verify this behavior - Kind::Dir { .. } => return Err(__WASI_EISDIR), + Kind::Dir { .. } => return Err(wasi_snapshot0::Errno::Isdir), Kind::Symlink { .. } => unimplemented!("WasiFs::flush Kind::Symlink"), Kind::Buffer { .. } => (), - _ => return Err(__WASI_EIO), + _ => return Err(wasi_snapshot0::Errno::Io), } } } @@ -1442,7 +1447,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)) } @@ -1485,7 +1490,7 @@ impl WasiFs { flags: __wasi_fdflags_t, open_flags: u16, inode: Inode, - ) -> Result<__wasi_fd_t, __wasi_errno_t> { + ) -> Result<__wasi_fd_t, wasi_snapshot0::Errno> { let idx = self.next_fd.fetch_add(1, Ordering::AcqRel); self.fd_map.write().unwrap().insert( idx, @@ -1501,7 +1506,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: __wasi_fd_t) -> Result<__wasi_fd_t, wasi_snapshot0::Errno> { let fd = self.get_fd(fd)?; let idx = self.next_fd.fetch_add(1, Ordering::AcqRel); self.fd_map.write().unwrap().insert( @@ -1624,7 +1629,7 @@ impl WasiFs { &self, inodes: &WasiInodes, kind: &Kind, - ) -> Result<__wasi_filestat_t, __wasi_errno_t> { + ) -> Result<__wasi_filestat_t, wasi_snapshot0::Errno> { let md = match kind { Kind::File { handle, path, .. } => match handle { Some(wf) => { @@ -1675,7 +1680,7 @@ impl WasiFs { _ => unreachable!("Symlink pointing to something that's not a directory as its base preopened directory"), } } - _ => return Err(__WASI_EIO), + _ => return Err(wasi_snapshot0::Errno::Io), }; Ok(__wasi_filestat_t { st_filetype: virtual_file_type_to_wasi_file_type(md.file_type()), @@ -1692,7 +1697,7 @@ impl WasiFs { &self, inodes: &WasiInodes, fd: __wasi_fd_t, - ) -> Result<(), __wasi_errno_t> { + ) -> Result<(), wasi_snapshot0::Errno> { let inode = self.get_fd_inode(fd)?; let inodeval = inodes.get_inodeval(inode)?; let is_preopened = inodeval.is_preopened; @@ -1715,7 +1720,7 @@ impl WasiFs { debug!("Closing dir {:?}", &path); let key = path .file_name() - .ok_or(__WASI_EINVAL)? + .ok_or(wasi_snapshot0::Errno::Inval)? .to_string_lossy() .to_string(); if let Some(p) = *parent { @@ -1753,12 +1758,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(wasi_snapshot0::Errno::Inval); } } Kind::EventNotifications { .. } => {} - Kind::Root { .. } => return Err(__WASI_EACCES), - Kind::Symlink { .. } | Kind::Buffer { .. } => return Err(__WASI_EINVAL), + Kind::Root { .. } => return Err(wasi_snapshot0::Errno::Acces), + Kind::Symlink { .. } | Kind::Buffer { .. } => return Err(wasi_snapshot0::Errno::Inval), } Ok(()) @@ -1770,21 +1775,27 @@ 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<(), wasi_snapshot0::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<(), wasi_snapshot0::Errno> { self.fs .fs_backing .remove_dir(path.as_ref()) @@ -1795,14 +1806,17 @@ impl WasiState { &self, from: P, to: Q, - ) -> Result<(), __wasi_errno_t> { + ) -> Result<(), wasi_snapshot0::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<(), wasi_snapshot0::Errno> { self.fs .fs_backing .remove_file(path.as_ref()) diff --git a/lib/wasi/src/state/pipe.rs b/lib/wasi/src/state/pipe.rs index 12c0084d43d..4cbbe58b564 100644 --- a/lib/wasi/src/state/pipe.rs +++ b/lib/wasi/src/state/pipe.rs @@ -43,7 +43,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 +55,7 @@ impl WasiPipe { } } let rx = self.rx.lock().unwrap(); - let data = rx.recv().map_err(|_| __WASI_EIO)?; + let data = rx.recv().map_err(|_| wasi_snapshot0::Errno::Io)?; self.read_buffer.replace(Bytes::from(data)); } } @@ -64,17 +64,19 @@ 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(|_| wasi_snapshot0::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(|_| wasi_snapshot0::Errno::Io)?; Ok(buf_len) } diff --git a/lib/wasi/src/state/socket.rs b/lib/wasi/src/state/socket.rs index 9f1b9765478..a31e402eb86 100644 --- a/lib/wasi/src/state/socket.rs +++ b/lib/wasi/src/state/socket.rs @@ -162,7 +162,7 @@ impl InodeSocket { &mut self, net: &(dyn VirtualNetworking), set_addr: SocketAddr, - ) -> Result, __wasi_errno_t> { + ) -> Result, wasi_snapshot0::Errno> { match &mut self.kind { InodeSocketKind::PreSocket { family, @@ -175,16 +175,16 @@ impl InodeSocket { match *family { __WASI_ADDRESS_FAMILY_INET4 => { if !set_addr.is_ipv4() { - return Err(__WASI_EINVAL); + return Err(wasi_snapshot0::Errno::Inval); } } __WASI_ADDRESS_FAMILY_INET6 => { if !set_addr.is_ipv6() { - return Err(__WASI_EINVAL); + return Err(wasi_snapshot0::Errno::Inval); } } _ => { - return Err(__WASI_ENOTSUP); + return Err(wasi_snapshot0::Errno::Notsup); } } @@ -203,10 +203,10 @@ impl InodeSocket { .map_err(net_error_into_wasi_err)?; Some(InodeSocket::new(InodeSocketKind::UdpSocket(socket))) } - _ => return Err(__WASI_EINVAL), + _ => return Err(wasi_snapshot0::Errno::Inval), }) } - _ => Err(__WASI_ENOTSUP), + _ => Err(wasi_snapshot0::Errno::Notsup), } } @@ -214,7 +214,7 @@ impl InodeSocket { &mut self, net: &(dyn VirtualNetworking), _backlog: usize, - ) -> Result, __wasi_errno_t> { + ) -> Result, wasi_snapshot0::Errno> { match &self.kind { InodeSocketKind::PreSocket { ty, @@ -227,7 +227,7 @@ impl InodeSocket { } => Ok(match *ty { __WASI_SOCK_TYPE_STREAM => { if addr.is_none() { - return Err(__WASI_EINVAL); + return Err(wasi_snapshot0::Errno::Inval); } let addr = *addr.as_ref().unwrap(); let mut socket = net @@ -240,22 +240,22 @@ impl InodeSocket { } Some(InodeSocket::new(InodeSocketKind::TcpListener(socket))) } - _ => return Err(__WASI_ENOTSUP), + _ => return Err(wasi_snapshot0::Errno::Notsup), }), - InodeSocketKind::Closed => Err(__WASI_EIO), - _ => Err(__WASI_ENOTSUP), + InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), + _ => Err(wasi_snapshot0::Errno::Notsup), } } pub fn accept( &self, _fd_flags: __wasi_fdflags_t, - ) -> Result<(Box, SocketAddr), __wasi_errno_t> { + ) -> Result<(Box, SocketAddr), wasi_snapshot0::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(wasi_snapshot0::Errno::Notconn), + InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), + _ => Err(wasi_snapshot0::Errno::Notsup), }?; Ok((sock, addr)) } @@ -264,14 +264,14 @@ impl InodeSocket { &self, _fd_flags: __wasi_fdflags_t, timeout: Duration, - ) -> Result<(Box, SocketAddr), __wasi_errno_t> { + ) -> Result<(Box, SocketAddr), wasi_snapshot0::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(wasi_snapshot0::Errno::Notconn), + InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), + _ => Err(wasi_snapshot0::Errno::Notsup), }?; Ok((sock, addr)) } @@ -280,7 +280,7 @@ impl InodeSocket { &mut self, net: &(dyn VirtualNetworking), peer: SocketAddr, - ) -> Result, __wasi_errno_t> { + ) -> Result, wasi_snapshot0::Errno> { match &mut self.kind { InodeSocketKind::PreSocket { ty, @@ -316,19 +316,19 @@ impl InodeSocket { } Some(InodeSocket::new(InodeSocketKind::TcpStream(socket))) } - __WASI_SOCK_TYPE_DGRAM => return Err(__WASI_EINVAL), - _ => return Err(__WASI_ENOTSUP), + __WASI_SOCK_TYPE_DGRAM => return Err(wasi_snapshot0::Errno::Inval), + _ => return Err(wasi_snapshot0::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(wasi_snapshot0::Errno::Io), + _ => Err(wasi_snapshot0::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(|_| wasi_snapshot0::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(wasi_snapshot0::Errno::Io), + _ => return Err(wasi_snapshot0::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 { @@ -372,7 +372,7 @@ impl InodeSocket { match *family { __WASI_ADDRESS_FAMILY_INET4 => IpAddr::V4(Ipv4Addr::UNSPECIFIED), __WASI_ADDRESS_FAMILY_INET6 => IpAddr::V6(Ipv6Addr::UNSPECIFIED), - _ => return Err(__WASI_EINVAL), + _ => return Err(wasi_snapshot0::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(wasi_snapshot0::Errno::Io), + _ => return Err(wasi_snapshot0::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), + _ => return Err(wasi_snapshot0::Errno::Inval), }, 0, ), @@ -423,8 +423,8 @@ impl InodeSocket { ) }) })?, - InodeSocketKind::Closed => return Err(__WASI_EIO), - _ => return Err(__WASI_ENOTSUP), + InodeSocketKind::Closed => return Err(wasi_snapshot0::Errno::Io), + _ => return Err(wasi_snapshot0::Errno::Notsup), }) } @@ -432,7 +432,7 @@ impl InodeSocket { &mut self, option: WasiSocketOption, val: bool, - ) -> Result<(), __wasi_errno_t> { + ) -> Result<(), wasi_snapshot0::Errno> { match &mut self.kind { InodeSocketKind::PreSocket { only_v6, @@ -444,20 +444,20 @@ impl InodeSocket { WasiSocketOption::OnlyV6 => *only_v6 = val, WasiSocketOption::ReusePort => *reuse_port = val, WasiSocketOption::ReuseAddr => *reuse_addr = val, - _ => return Err(__WASI_EINVAL), + _ => return Err(wasi_snapshot0::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(wasi_snapshot0::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(wasi_snapshot0::Errno::Inval), }, InodeSocketKind::UdpSocket(sock) => match option { WasiSocketOption::Broadcast => { @@ -469,15 +469,15 @@ impl InodeSocket { WasiSocketOption::MulticastLoopV6 => sock .set_multicast_loop_v6(val) .map_err(net_error_into_wasi_err)?, - _ => return Err(__WASI_EINVAL), + _ => return Err(wasi_snapshot0::Errno::Inval), }, - InodeSocketKind::Closed => return Err(__WASI_EIO), - _ => return Err(__WASI_ENOTSUP), + InodeSocketKind::Closed => return Err(wasi_snapshot0::Errno::Io), + _ => return Err(wasi_snapshot0::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 +488,17 @@ impl InodeSocket { WasiSocketOption::OnlyV6 => *only_v6, WasiSocketOption::ReusePort => *reuse_port, WasiSocketOption::ReuseAddr => *reuse_addr, - _ => return Err(__WASI_EINVAL), + _ => return Err(wasi_snapshot0::Errno::Inval), }, InodeSocketKind::Raw(sock) => match option { WasiSocketOption::Promiscuous => { sock.promiscuous().map_err(net_error_into_wasi_err)? } - _ => return Err(__WASI_EINVAL), + _ => return Err(wasi_snapshot0::Errno::Inval), }, InodeSocketKind::TcpStream(sock) => match option { WasiSocketOption::NoDelay => sock.nodelay().map_err(net_error_into_wasi_err)?, - _ => return Err(__WASI_EINVAL), + _ => return Err(wasi_snapshot0::Errno::Inval), }, InodeSocketKind::UdpSocket(sock) => match option { WasiSocketOption::Broadcast => sock.broadcast().map_err(net_error_into_wasi_err)?, @@ -508,14 +508,14 @@ impl InodeSocket { WasiSocketOption::MulticastLoopV6 => { sock.multicast_loop_v6().map_err(net_error_into_wasi_err)? } - _ => return Err(__WASI_EINVAL), + _ => return Err(wasi_snapshot0::Errno::Inval), }, - InodeSocketKind::Closed => return Err(__WASI_EIO), - _ => return Err(__WASI_ENOTSUP), + InodeSocketKind::Closed => return Err(wasi_snapshot0::Errno::Io), + _ => return Err(wasi_snapshot0::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<(), wasi_snapshot0::Errno> { match &mut self.kind { InodeSocketKind::PreSocket { send_buf_size, .. } => { *send_buf_size = Some(size); @@ -524,13 +524,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(wasi_snapshot0::Errno::Io), + _ => return Err(wasi_snapshot0::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 +538,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(wasi_snapshot0::Errno::Io), + _ => Err(wasi_snapshot0::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<(), wasi_snapshot0::Errno> { match &mut self.kind { InodeSocketKind::PreSocket { recv_buf_size, .. } => { *recv_buf_size = Some(size); @@ -552,13 +552,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(wasi_snapshot0::Errno::Io), + _ => return Err(wasi_snapshot0::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 +566,31 @@ 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(wasi_snapshot0::Errno::Io), + _ => Err(wasi_snapshot0::Errno::Notsup), } } pub fn set_linger( &mut self, linger: Option, - ) -> Result<(), __wasi_errno_t> { + ) -> Result<(), wasi_snapshot0::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(wasi_snapshot0::Errno::Io), + InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), + _ => Err(wasi_snapshot0::Errno::Notsup), } } - pub fn linger(&self) -> Result, __wasi_errno_t> { + pub fn linger(&self) -> Result, wasi_snapshot0::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(wasi_snapshot0::Errno::Io), + InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), + _ => Err(wasi_snapshot0::Errno::Notsup), } } @@ -598,7 +598,7 @@ impl InodeSocket { &mut self, ty: TimeType, timeout: Option, - ) -> Result<(), __wasi_errno_t> { + ) -> Result<(), wasi_snapshot0::Errno> { match &mut self.kind { InodeSocketKind::TcpStream(sock) => sock .set_opt_time(ty, timeout) @@ -607,7 +607,7 @@ impl InodeSocket { TimeType::AcceptTimeout => { sock.set_timeout(timeout).map_err(net_error_into_wasi_err) } - _ => Err(__WASI_EINVAL), + _ => Err(wasi_snapshot0::Errno::Inval), }, InodeSocketKind::PreSocket { recv_timeout, @@ -632,19 +632,22 @@ impl InodeSocket { *send_timeout = timeout; Ok(()) } - _ => Err(__WASI_EIO), + _ => Err(wasi_snapshot0::Errno::Io), }, - InodeSocketKind::Closed => Err(__WASI_EIO), - _ => Err(__WASI_ENOTSUP), + InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), + _ => Err(wasi_snapshot0::Errno::Notsup), } } - pub fn opt_time(&self, ty: TimeType) -> Result, __wasi_errno_t> { + pub fn opt_time( + &self, + ty: TimeType, + ) -> Result, wasi_snapshot0::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(wasi_snapshot0::Errno::Inval), }, InodeSocketKind::PreSocket { recv_timeout, @@ -657,52 +660,52 @@ impl InodeSocket { TimeType::AcceptTimeout => Ok(*accept_timeout), TimeType::ReadTimeout => Ok(*recv_timeout), TimeType::WriteTimeout => Ok(*send_timeout), - _ => Err(__WASI_EINVAL), + _ => Err(wasi_snapshot0::Errno::Inval), }, - InodeSocketKind::Closed => Err(__WASI_EIO), - _ => Err(__WASI_ENOTSUP), + InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), + _ => Err(wasi_snapshot0::Errno::Notsup), } } - pub fn set_ttl(&mut self, ttl: u32) -> Result<(), __wasi_errno_t> { + pub fn set_ttl(&mut self, ttl: u32) -> Result<(), wasi_snapshot0::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(wasi_snapshot0::Errno::Io), + InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), + _ => Err(wasi_snapshot0::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(wasi_snapshot0::Errno::Io), + InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), + _ => Err(wasi_snapshot0::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<(), wasi_snapshot0::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(wasi_snapshot0::Errno::Io), + InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), + _ => Err(wasi_snapshot0::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(wasi_snapshot0::Errno::Io), + InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), + _ => Err(wasi_snapshot0::Errno::Notsup), } } @@ -710,14 +713,14 @@ impl InodeSocket { &mut self, multiaddr: Ipv4Addr, iface: Ipv4Addr, - ) -> Result<(), __wasi_errno_t> { + ) -> Result<(), wasi_snapshot0::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(wasi_snapshot0::Errno::Io), + InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), + _ => Err(wasi_snapshot0::Errno::Notsup), } } @@ -725,14 +728,14 @@ impl InodeSocket { &mut self, multiaddr: Ipv4Addr, iface: Ipv4Addr, - ) -> Result<(), __wasi_errno_t> { + ) -> Result<(), wasi_snapshot0::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(wasi_snapshot0::Errno::Io), + InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), + _ => Err(wasi_snapshot0::Errno::Notsup), } } @@ -740,14 +743,14 @@ impl InodeSocket { &mut self, multiaddr: Ipv6Addr, iface: u32, - ) -> Result<(), __wasi_errno_t> { + ) -> Result<(), wasi_snapshot0::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(wasi_snapshot0::Errno::Io), + InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), + _ => Err(wasi_snapshot0::Errno::Notsup), } } @@ -755,14 +758,14 @@ impl InodeSocket { &mut self, multiaddr: Ipv6Addr, iface: u32, - ) -> Result<(), __wasi_errno_t> { + ) -> Result<(), wasi_snapshot0::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(wasi_snapshot0::Errno::Io), + InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), + _ => Err(wasi_snapshot0::Errno::Notsup), } } @@ -770,13 +773,15 @@ 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(|_| wasi_snapshot0::Errno::Inval)?; let mut buf = Vec::with_capacity(buf_len); write_bytes(&mut buf, memory, iov)?; match &mut self.kind { @@ -785,13 +790,16 @@ impl InodeSocket { match ty { InodeHttpSocketType::Request => { if sock.request.is_none() { - return Err(__WASI_EIO); + return Err(wasi_snapshot0::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(|_| wasi_snapshot0::Errno::Io) } _ => { - return Err(__WASI_EIO); + return Err(wasi_snapshot0::Errno::Io); } } } @@ -808,14 +816,17 @@ 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(wasi_snapshot0::Errno::Notconn), + InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), + _ => Err(wasi_snapshot0::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 +834,16 @@ impl InodeSocket { match ty { InodeHttpSocketType::Request => { if sock.request.is_none() { - return Err(__WASI_EIO); + return Err(wasi_snapshot0::Errno::Io); } let request = sock.request.as_ref().unwrap(); request .send(buf.to_vec()) .map(|_| buf_len) - .map_err(|_| __WASI_EIO) + .map_err(|_| wasi_snapshot0::Errno::Io) } _ => { - return Err(__WASI_EIO); + return Err(wasi_snapshot0::Errno::Io); } } } @@ -843,9 +854,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(wasi_snapshot0::Errno::Notconn), + InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), + _ => Err(wasi_snapshot0::Errno::Notsup), } .map(|_| buf_len) } @@ -855,7 +866,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 +874,9 @@ 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(|_| wasi_snapshot0::Errno::Inval)?; let mut buf = Vec::with_capacity(buf_len); write_bytes(&mut buf, memory, iov)?; match &mut self.kind { @@ -873,9 +886,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(wasi_snapshot0::Errno::Notconn), + InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), + _ => Err(wasi_snapshot0::Errno::Notsup), } .map(|_| buf_len) } @@ -884,7 +897,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 +918,22 @@ impl InodeSocket { match ty { InodeHttpSocketType::Response => { if sock.response.is_none() { - return Err(__WASI_EIO); + return Err(wasi_snapshot0::Errno::Io); } let response = sock.response.as_ref().unwrap(); - Bytes::from(response.recv().map_err(|_| __WASI_EIO)?) + Bytes::from(response.recv().map_err(|_| wasi_snapshot0::Errno::Io)?) } InodeHttpSocketType::Headers => { if sock.headers.is_none() { - return Err(__WASI_EIO); + return Err(wasi_snapshot0::Errno::Io); } let headers = sock.headers.as_ref().unwrap(); - let headers = headers.recv().map_err(|_| __WASI_EIO)?; + let headers = headers.recv().map_err(|_| wasi_snapshot0::Errno::Io)?; let headers = format!("{}: {}", headers.0, headers.1); Bytes::from(headers.as_bytes().to_vec()) } _ => { - return Err(__WASI_EIO); + return Err(wasi_snapshot0::Errno::Io); } } } @@ -940,9 +953,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(wasi_snapshot0::Errno::Notconn), + InodeSocketKind::Closed => return Err(wasi_snapshot0::Errno::Io), + _ => return Err(wasi_snapshot0::Errno::Notsup), }; self.read_buffer.replace(data); self.read_addr.take(); @@ -954,7 +967,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 +985,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(wasi_snapshot0::Errno::Notconn), + InodeSocketKind::Closed => return Err(wasi_snapshot0::Errno::Io), + _ => return Err(wasi_snapshot0::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<(), wasi_snapshot0::Errno> { use std::net::Shutdown; match &mut self.kind { InodeSocketKind::TcpStream(sock) => { @@ -1004,9 +1017,9 @@ impl InodeSocket { } }; } - InodeSocketKind::PreSocket { .. } => return Err(__WASI_ENOTCONN), - InodeSocketKind::Closed => return Err(__WASI_EIO), - _ => return Err(__WASI_ENOTSUP), + InodeSocketKind::PreSocket { .. } => return Err(wasi_snapshot0::Errno::Notconn), + InodeSocketKind::Closed => return Err(wasi_snapshot0::Errno::Io), + _ => return Err(wasi_snapshot0::Errno::Notsup), } Ok(()) } @@ -1132,7 +1145,7 @@ 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)?; @@ -1143,14 +1156,14 @@ pub(crate) fn read_ip( 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(wasi_snapshot0::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 +1174,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,7 +1186,7 @@ pub(crate) fn write_ip( memory: &MemoryView, ptr: WasmPtr<__wasi_addr_t, M>, ip: IpAddr, -) -> Result<(), __wasi_errno_t> { +) -> Result<(), wasi_snapshot0::Errno> { let ip = match ip { IpAddr::V4(ip) => { let o = ip.octets(); @@ -1202,7 +1215,7 @@ 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)?; @@ -1225,7 +1238,7 @@ pub(crate) fn read_cidr( prefix: o[16], } } - _ => return Err(__WASI_EINVAL), + _ => return Err(wasi_snapshot0::Errno::Inval), }) } @@ -1234,7 +1247,7 @@ pub(crate) fn write_cidr( memory: &MemoryView, ptr: WasmPtr<__wasi_cidr_t, M>, cidr: IpCidr, -) -> Result<(), __wasi_errno_t> { +) -> Result<(), wasi_snapshot0::Errno> { let p = cidr.prefix; let cidr = match cidr.ip { IpAddr::V4(ip) => { @@ -1270,7 +1283,7 @@ 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), wasi_snapshot0::Errno> { let addr_ptr = ptr.deref(memory); let addr = addr_ptr.read().map_err(crate::mem_error_to_wasi)?; @@ -1293,7 +1306,7 @@ pub(crate) fn read_ip_port( u16::from_ne_bytes([o[0], o[1]]), ) } - _ => return Err(__WASI_EINVAL), + _ => return Err(wasi_snapshot0::Errno::Inval), }) } @@ -1303,7 +1316,7 @@ pub(crate) fn write_ip_port( ptr: WasmPtr<__wasi_addr_port_t, M>, ip: IpAddr, port: u16, -) -> Result<(), __wasi_errno_t> { +) -> Result<(), wasi_snapshot0::Errno> { let p = port.to_be_bytes(); let ipport = match ip { IpAddr::V4(ip) => { @@ -1340,7 +1353,7 @@ pub(crate) fn write_ip_port( pub(crate) fn read_route( memory: &MemoryView, ptr: WasmPtr<__wasi_route_t, M>, -) -> Result { +) -> Result { let route_ptr = ptr.deref(memory); let route = route_ptr.read().map_err(crate::mem_error_to_wasi)?; @@ -1365,7 +1378,7 @@ pub(crate) fn read_route( prefix: o[16], } } - _ => return Err(__WASI_EINVAL), + _ => return Err(wasi_snapshot0::Errno::Inval), } }, via_router: { @@ -1376,18 +1389,18 @@ pub(crate) fn read_route( 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(wasi_snapshot0::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), + _ => return Err(wasi_snapshot0::Errno::Inval), }, 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), + _ => return Err(wasi_snapshot0::Errno::Inval), }, }) } @@ -1396,7 +1409,7 @@ pub(crate) fn write_route( memory: &MemoryView, ptr: WasmPtr<__wasi_route_t, M>, route: IpRoute, -) -> Result<(), __wasi_errno_t> { +) -> Result<(), wasi_snapshot0::Errno> { let cidr = { let p = route.cidr.prefix; match route.cidr.ip { diff --git a/lib/wasi/src/state/types.rs b/lib/wasi/src/state/types.rs index 462a008f19f..0b225605385 100644 --- a/lib/wasi/src/state/types.rs +++ b/lib/wasi/src/state/types.rs @@ -11,6 +11,7 @@ use std::{ time::Duration, }; use wasmer_vbus::BusError; +use wasmer_wasi_types_generated::wasi_snapshot0; #[cfg(feature = "host-fs")] pub use wasmer_vfs::host_fs::{Stderr, Stdin, Stdout}; @@ -20,85 +21,85 @@ 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: wasi_snapshot0::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, + wasi_snapshot0::Errno::Badf => FsError::InvalidFd, + wasi_snapshot0::Errno::Exist => FsError::AlreadyExists, + wasi_snapshot0::Errno::Io => FsError::IOError, + wasi_snapshot0::Errno::Addrinuse => FsError::AddressInUse, + wasi_snapshot0::Errno::Addrnotavail => FsError::AddressNotAvailable, + wasi_snapshot0::Errno::Pipe => FsError::BrokenPipe, + wasi_snapshot0::Errno::Connaborted => FsError::ConnectionAborted, + wasi_snapshot0::Errno::Connrefused => FsError::ConnectionRefused, + wasi_snapshot0::Errno::Connreset => FsError::ConnectionReset, + wasi_snapshot0::Errno::Intr => FsError::Interrupted, + wasi_snapshot0::Errno::Inval => FsError::InvalidInput, + wasi_snapshot0::Errno::Notconn => FsError::NotConnected, + wasi_snapshot0::Errno::Nodev => FsError::NoDevice, + wasi_snapshot0::Errno::Noent => FsError::EntityNotFound, + wasi_snapshot0::Errno::Perm => FsError::PermissionDenied, + wasi_snapshot0::Errno::Timedout => FsError::TimedOut, + wasi_snapshot0::Errno::Proto => FsError::UnexpectedEof, + wasi_snapshot0::Errno::Again => FsError::WouldBlock, + wasi_snapshot0::Errno::Nospc => FsError::WriteZero, + wasi_snapshot0::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) -> wasi_snapshot0::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 => wasi_snapshot0::Errno::Exist, + FsError::AddressInUse => wasi_snapshot0::Errno::Addrinuse, + FsError::AddressNotAvailable => wasi_snapshot0::Errno::Addrnotavail, + FsError::BaseNotDirectory => wasi_snapshot0::Errno::Notdir, + FsError::BrokenPipe => wasi_snapshot0::Errno::Pipe, + FsError::ConnectionAborted => wasi_snapshot0::Errno::Connaborted, + FsError::ConnectionRefused => wasi_snapshot0::Errno::Connrefused, + FsError::ConnectionReset => wasi_snapshot0::Errno::Connreset, + FsError::Interrupted => wasi_snapshot0::Errno::Intr, + FsError::InvalidData => wasi_snapshot0::Errno::Io, + FsError::InvalidFd => wasi_snapshot0::Errno::Badf, + FsError::InvalidInput => wasi_snapshot0::Errno::Inval, + FsError::IOError => wasi_snapshot0::Errno::Io, + FsError::NoDevice => wasi_snapshot0::Errno::Nodev, + FsError::NotAFile => wasi_snapshot0::Errno::Inval, + FsError::NotConnected => wasi_snapshot0::Errno::Notconn, + FsError::EntityNotFound => wasi_snapshot0::Errno::Noent, + FsError::PermissionDenied => wasi_snapshot0::Errno::Perm, + FsError::TimedOut => wasi_snapshot0::Errno::Timedout, + FsError::UnexpectedEof => wasi_snapshot0::Errno::Proto, + FsError::WouldBlock => wasi_snapshot0::Errno::Again, + FsError::WriteZero => wasi_snapshot0::Errno::Nospc, + FsError::DirectoryNotEmpty => wasi_snapshot0::Errno::Notempty, + FsError::Lock | FsError::UnknownError => wasi_snapshot0::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) -> wasi_snapshot0::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 => wasi_snapshot0::Errno::Badf, + NetworkError::AlreadyExists => wasi_snapshot0::Errno::Exist, + NetworkError::Lock => wasi_snapshot0::Errno::Io, + NetworkError::IOError => wasi_snapshot0::Errno::Io, + NetworkError::AddressInUse => wasi_snapshot0::Errno::Addrinuse, + NetworkError::AddressNotAvailable => wasi_snapshot0::Errno::Addrnotavail, + NetworkError::BrokenPipe => wasi_snapshot0::Errno::Pipe, + NetworkError::ConnectionAborted => wasi_snapshot0::Errno::Connaborted, + NetworkError::ConnectionRefused => wasi_snapshot0::Errno::Connrefused, + NetworkError::ConnectionReset => wasi_snapshot0::Errno::Connreset, + NetworkError::Interrupted => wasi_snapshot0::Errno::Intr, + NetworkError::InvalidData => wasi_snapshot0::Errno::Io, + NetworkError::InvalidInput => wasi_snapshot0::Errno::Inval, + NetworkError::NotConnected => wasi_snapshot0::Errno::Notconn, + NetworkError::NoDevice => wasi_snapshot0::Errno::Nodev, + NetworkError::PermissionDenied => wasi_snapshot0::Errno::Perm, + NetworkError::TimedOut => wasi_snapshot0::Errno::Timedout, + NetworkError::UnexpectedEof => wasi_snapshot0::Errno::Proto, + NetworkError::WouldBlock => wasi_snapshot0::Errno::Again, + NetworkError::WriteZero => wasi_snapshot0::Errno::Nospc, + NetworkError::Unsupported => wasi_snapshot0::Errno::Notsup, + NetworkError::UnknownError => wasi_snapshot0::Errno::Io, } } diff --git a/lib/wasi/src/syscalls/legacy/snapshot0.rs b/lib/wasi/src/syscalls/legacy/snapshot0.rs index 033abe11e04..1fcc773d2d5 100644 --- a/lib/wasi/src/syscalls/legacy/snapshot0.rs +++ b/lib/wasi/src/syscalls/legacy/snapshot0.rs @@ -1,5 +1,5 @@ use crate::syscalls; -use crate::syscalls::types::{self, snapshot0}; +use crate::syscalls::types::{self, snapshot0, wasi_snapshot0}; use crate::{mem_error_to_wasi, Memory32, MemorySize, WasiEnv, WasiError, WasiThread}; use wasmer::{AsStoreMut, FunctionEnvMut, WasmPtr}; @@ -13,7 +13,7 @@ pub fn fd_filestat_get( mut ctx: FunctionEnvMut, fd: types::__wasi_fd_t, buf: WasmPtr, -) -> types::__wasi_errno_t { +) -> wasi_snapshot0::Errno { let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -67,7 +67,7 @@ pub fn path_filestat_get( path: WasmPtr, path_len: u32, buf: WasmPtr, -) -> types::__wasi_errno_t { +) -> wasi_snapshot0::Errno { // see `fd_filestat_get` in this file for an explanation of this strange behavior let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -107,7 +107,7 @@ pub fn fd_seek( offset: types::__wasi_filedelta_t, whence: snapshot0::__wasi_whence_t, newoffset: WasmPtr, -) -> Result { +) -> Result { let new_whence = match whence { snapshot0::__WASI_WHENCE_CUR => types::__WASI_WHENCE_CUR, snapshot0::__WASI_WHENCE_END => types::__WASI_WHENCE_END, @@ -126,7 +126,7 @@ pub fn poll_oneoff( out_: WasmPtr, nsubscriptions: u32, nevents: WasmPtr, -) -> Result { +) -> Result { // 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 diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 0c5266e6efc..9db54761e28 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -2,6 +2,7 @@ pub mod types { pub use wasmer_wasi_types::*; + pub use wasmer_wasi_types_generated::wasi_snapshot0; } #[cfg(any( @@ -53,6 +54,7 @@ use wasmer::{ use wasmer_vbus::{FileDescriptor, StdioMode}; use wasmer_vfs::{FsError, VirtualFile}; use wasmer_vnet::{SocketHttpRequest, StreamSecurity}; +use wasmer_wasi_types_generated::wasi_snapshot0; #[cfg(any( target_os = "freebsd", @@ -68,13 +70,17 @@ 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(|_| wasi_snapshot0::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(|_| wasi_snapshot0::Errno::Inval)?; Ok(ret) } @@ -82,7 +88,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)?; @@ -101,7 +107,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 @@ -111,7 +117,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 @@ -147,9 +153,9 @@ fn __sock_actor( sock: __wasi_fd_t, rights: __wasi_rights_t, 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); @@ -157,7 +163,7 @@ where let fd_entry = state.fs.get_fd(sock)?; let ret = { if rights != 0 && !has_rights(fd_entry.rights, rights) { - return Err(__WASI_EACCES); + return Err(wasi_snapshot0::Errno::Acces); } let inode_idx = fd_entry.inode; @@ -168,7 +174,7 @@ where match deref { Kind::Socket { socket } => actor(socket)?, _ => { - return Err(__WASI_ENOTSOCK); + return Err(wasi_snapshot0::Errno::Notsock); } } }; @@ -181,9 +187,9 @@ fn __sock_actor_mut( sock: __wasi_fd_t, rights: __wasi_rights_t, 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); @@ -191,7 +197,7 @@ where let fd_entry = state.fs.get_fd(sock)?; let ret = { if rights != 0 && !has_rights(fd_entry.rights, rights) { - return Err(__WASI_EACCES); + return Err(wasi_snapshot0::Errno::Acces); } let inode_idx = fd_entry.inode; @@ -202,7 +208,7 @@ where match deref_mut { Kind::Socket { socket } => actor(socket)?, _ => { - return Err(__WASI_ENOTSOCK); + return Err(wasi_snapshot0::Errno::Notsock); } } }; @@ -215,18 +221,18 @@ fn __sock_upgrade( sock: __wasi_fd_t, rights: __wasi_rights_t, actor: F, -) -> Result<(), __wasi_errno_t> +) -> Result<(), wasi_snapshot0::Errno> where F: FnOnce( &mut crate::state::InodeSocket, - ) -> Result, __wasi_errno_t>, + ) -> Result, wasi_snapshot0::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); + return Err(wasi_snapshot0::Errno::Acces); } let inode_idx = fd_entry.inode; @@ -243,7 +249,7 @@ where } } _ => { - return Err(__WASI_ENOTSOCK); + return Err(wasi_snapshot0::Errno::Notsock); } } @@ -256,7 +262,7 @@ fn write_buffer_array( from: &[Vec], ptr_buffer: WasmPtr, M>, buffer: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { let ptrs = wasi_try_mem!(ptr_buffer.slice(memory, wasi_try!(to_offset::(from.len())))); let mut current_buffer_offset = 0usize; @@ -278,14 +284,14 @@ fn write_buffer_array( current_buffer_offset += sub_buffer.len() + 1; } - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } -fn get_current_time_in_nanos() -> Result<__wasi_timestamp_t, __wasi_errno_t> { +fn get_current_time_in_nanos() -> Result<__wasi_timestamp_t, wasi_snapshot0::Errno> { let now = std::time::SystemTime::now(); let duration = now .duration_since(std::time::SystemTime::UNIX_EPOCH) - .map_err(|_| __WASI_EIO)?; + .map_err(|_| wasi_snapshot0::Errno::Io)?; Ok(duration.as_nanos() as __wasi_timestamp_t) } @@ -302,7 +308,7 @@ pub fn args_get( mut ctx: FunctionEnvMut<'_, WasiEnv>, argv: WasmPtr, M>, argv_buf: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::args_get"); let env = ctx.data(); let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0); @@ -334,7 +340,7 @@ pub fn args_sizes_get( mut ctx: FunctionEnvMut<'_, WasiEnv>, argc: WasmPtr, argv_buf_size: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::args_sizes_get"); let env = ctx.data(); let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0); @@ -342,16 +348,21 @@ 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(|_| wasi_snapshot0::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)); + let argv_buf_size_val: M::Offset = wasi_try!(argv_buf_size_val + .try_into() + .map_err(|_| wasi_snapshot0::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 + wasi_snapshot0::Errno::Success } /// ### `clock_res_get()` @@ -366,7 +377,7 @@ pub fn clock_res_get( mut ctx: FunctionEnvMut<'_, WasiEnv>, clock_id: __wasi_clockid_t, resolution: WasmPtr<__wasi_timestamp_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { trace!("wasi::clock_res_get"); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -374,7 +385,7 @@ pub fn clock_res_get( 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 + wasi_snapshot0::Errno::Success } /// ### `clock_time_get()` @@ -392,7 +403,7 @@ pub fn clock_time_get( clock_id: __wasi_clockid_t, precision: __wasi_timestamp_t, time: WasmPtr<__wasi_timestamp_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!( "wasi::clock_time_get clock_id: {}, precision: {}", clock_id, precision @@ -403,7 +414,7 @@ pub fn clock_time_get( 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 result = __WASI_ESUCCESS; + let result = wasi_snapshot0::Errno::Success; trace!( "time: {} => {}", wasi_try_mem!(time.deref(&memory).read()), @@ -424,7 +435,7 @@ pub fn environ_get( ctx: FunctionEnvMut<'_, WasiEnv>, environ: WasmPtr, M>, environ_buf: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!( "wasi::environ_get. Environ: {:?}, environ_buf: {:?}", environ, environ_buf @@ -447,7 +458,7 @@ pub fn environ_sizes_get( ctx: FunctionEnvMut<'_, WasiEnv>, environ_count: WasmPtr, environ_buf_size: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { trace!("wasi::environ_sizes_get"); let env = ctx.data(); let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0); @@ -455,10 +466,15 @@ pub fn environ_sizes_get( let environ_count = environ_count.deref(&memory); 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)); + let env_var_count: M::Offset = wasi_try!(state + .envs + .len() + .try_into() + .map_err(|_| wasi_snapshot0::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(|_| wasi_snapshot0::Errno::Overflow)); wasi_try_mem!(environ_count.write(env_var_count)); wasi_try_mem!(environ_buf_size.write(env_buf_size)); @@ -468,7 +484,7 @@ pub fn environ_sizes_get( env_buf_size ); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `fd_advise()` @@ -488,12 +504,12 @@ pub fn fd_advise( offset: __wasi_filesize_t, len: __wasi_filesize_t, advice: __wasi_advice_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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 + wasi_snapshot0::Errno::Success } /// ### `fd_allocate` @@ -510,7 +526,7 @@ pub fn fd_allocate( fd: __wasi_fd_t, offset: __wasi_filesize_t, len: __wasi_filesize_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::fd_allocate"); let env = ctx.data(); let (_, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0); @@ -518,9 +534,9 @@ pub fn fd_allocate( let inode = fd_entry.inode; if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_ALLOCATE) { - return __WASI_EACCES; + return wasi_snapshot0::Errno::Acces; } - let new_size = wasi_try!(offset.checked_add(len).ok_or(__WASI_EINVAL)); + let new_size = wasi_try!(offset.checked_add(len).ok_or(wasi_snapshot0::Errno::Inval)); { let mut guard = inodes.arena[inode].write(); let deref_mut = guard.deref_mut(); @@ -529,23 +545,23 @@ 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 wasi_snapshot0::Errno::Badf; } } - Kind::Socket { .. } => return __WASI_EBADF, - Kind::Pipe { .. } => return __WASI_EBADF, + Kind::Socket { .. } => return wasi_snapshot0::Errno::Badf, + Kind::Pipe { .. } => return wasi_snapshot0::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 wasi_snapshot0::Errno::Badf, + Kind::EventNotifications { .. } => return wasi_snapshot0::Errno::Badf, + Kind::Dir { .. } | Kind::Root { .. } => return wasi_snapshot0::Errno::Isdir, } } inodes.arena[inode].stat.write().unwrap().st_size = new_size; debug!("New file size: {}", new_size); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `fd_close()` @@ -554,11 +570,11 @@ pub fn fd_allocate( /// - `__wasi_fd_t fd` /// A file descriptor mapping to an open file to close /// Errors: -/// - `__WASI_EISDIR` +/// - `wasi_snapshot0::Errno::Isdir` /// If `fd` is a directory -/// - `__WASI_EBADF` +/// - `wasi_snapshot0::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: __wasi_fd_t) -> wasi_snapshot0::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); @@ -567,7 +583,7 @@ pub fn fd_close(ctx: FunctionEnvMut<'_, WasiEnv>, fd: __wasi_fd_t) -> __wasi_err wasi_try!(state.fs.close_fd(inodes.deref(), fd)); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `fd_datasync()` @@ -575,19 +591,19 @@ pub fn fd_close(ctx: FunctionEnvMut<'_, WasiEnv>, fd: __wasi_fd_t) -> __wasi_err /// Inputs: /// - `__wasi_fd_t 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: __wasi_fd_t) -> wasi_snapshot0::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; + return wasi_snapshot0::Errno::Acces; } if let Err(e) = state.fs.flush(inodes.deref(), fd) { e } else { - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } } @@ -603,7 +619,7 @@ pub fn fd_fdstat_get( ctx: FunctionEnvMut<'_, WasiEnv>, fd: __wasi_fd_t, buf_ptr: WasmPtr<__wasi_fdstat_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!( "wasi::fd_fdstat_get: fd={}, buf_ptr={}", fd, @@ -617,7 +633,7 @@ pub fn fd_fdstat_get( wasi_try_mem!(buf.write(stat)); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `fd_fdstat_set_flags()` @@ -631,19 +647,19 @@ pub fn fd_fdstat_set_flags( ctx: FunctionEnvMut<'_, WasiEnv>, fd: __wasi_fd_t, flags: __wasi_fdflags_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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(wasi_snapshot0::Errno::Badf)); if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_FDSTAT_SET_FLAGS) { - return __WASI_EACCES; + return wasi_snapshot0::Errno::Acces; } fd_entry.flags = flags; - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `fd_fdstat_set_rights()` @@ -660,24 +676,24 @@ pub fn fd_fdstat_set_rights( fd: __wasi_fd_t, fs_rights_base: __wasi_rights_t, fs_rights_inheriting: __wasi_rights_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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(wasi_snapshot0::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 wasi_snapshot0::Errno::Notcapable; } fd_entry.rights = fs_rights_base; fd_entry.rights_inheriting = fs_rights_inheriting; - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `fd_filestat_get()` @@ -692,13 +708,13 @@ pub fn fd_filestat_get( ctx: FunctionEnvMut<'_, WasiEnv>, fd: __wasi_fd_t, buf: WasmPtr<__wasi_filestat_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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; + return wasi_snapshot0::Errno::Acces; } let stat = wasi_try!(state.fs.filestat_fd(inodes.deref(), fd)); @@ -706,7 +722,7 @@ pub fn fd_filestat_get( let buf = buf.deref(&memory); wasi_try_mem!(buf.write(stat)); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `fd_filestat_set_size()` @@ -720,7 +736,7 @@ pub fn fd_filestat_set_size( ctx: FunctionEnvMut<'_, WasiEnv>, fd: __wasi_fd_t, st_size: __wasi_filesize_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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); @@ -728,7 +744,7 @@ pub fn fd_filestat_set_size( let inode = fd_entry.inode; if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_FILESTAT_SET_SIZE) { - return __WASI_EACCES; + return wasi_snapshot0::Errno::Acces; } { @@ -739,22 +755,22 @@ 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 wasi_snapshot0::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 wasi_snapshot0::Errno::Badf, + Kind::Pipe { .. } => return wasi_snapshot0::Errno::Badf, + Kind::Symlink { .. } => return wasi_snapshot0::Errno::Badf, + Kind::EventNotifications { .. } => return wasi_snapshot0::Errno::Badf, + Kind::Dir { .. } | Kind::Root { .. } => return wasi_snapshot0::Errno::Isdir, } } inodes.arena[inode].stat.write().unwrap().st_size = st_size; - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `fd_filestat_set_times()` @@ -772,21 +788,21 @@ pub fn fd_filestat_set_times( st_atim: __wasi_timestamp_t, st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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; + return wasi_snapshot0::Errno::Acces; } 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) { - return __WASI_EINVAL; + return wasi_snapshot0::Errno::Inval; } let inode_idx = fd_entry.inode; @@ -810,7 +826,7 @@ pub fn fd_filestat_set_times( inode.stat.write().unwrap().st_mtim = time_to_set; } - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `fd_pread()` @@ -835,7 +851,7 @@ pub fn fd_pread( iovs_len: M::Offset, offset: __wasi_filesize_t, 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); @@ -855,11 +871,11 @@ 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(wasi_snapshot0::Errno::Badf); } } - __WASI_STDOUT_FILENO => return Ok(__WASI_EINVAL), - __WASI_STDERR_FILENO => return Ok(__WASI_EINVAL), + __WASI_STDOUT_FILENO => return Ok(wasi_snapshot0::Errno::Inval), + __WASI_STDERR_FILENO => return Ok(wasi_snapshot0::Errno::Inval), _ => { let inode = fd_entry.inode; @@ -870,7 +886,7 @@ pub fn fd_pread( "Invalid rights on {:X}: expected READ and SEEK", fd_entry.rights ); - return Ok(__WASI_EACCES); + return Ok(wasi_snapshot0::Errno::Acces); } let mut guard = inodes.arena[inode].write(); let deref_mut = guard.deref_mut(); @@ -884,7 +900,7 @@ pub fn fd_pread( ); wasi_try_ok!(read_bytes(h, &memory, iovs), env) } else { - return Ok(__WASI_EINVAL); + return Ok(wasi_snapshot0::Errno::Inval); } } Kind::Socket { socket } => { @@ -893,8 +909,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(wasi_snapshot0::Errno::Inval), + Kind::Dir { .. } | Kind::Root { .. } => return Ok(wasi_snapshot0::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) @@ -903,10 +919,12 @@ 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(|_| wasi_snapshot0::Errno::Overflow)); wasi_try_mem_ok!(nread_ref.write(bytes_read)); debug!("Success: {} bytes read", bytes_read); - Ok(__WASI_ESUCCESS) + Ok(wasi_snapshot0::Errno::Success) } /// ### `fd_prestat_get()` @@ -921,7 +939,7 @@ pub fn fd_prestat_get( ctx: FunctionEnvMut<'_, WasiEnv>, fd: __wasi_fd_t, buf: WasmPtr<__wasi_prestat_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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); @@ -936,7 +954,7 @@ pub fn fd_prestat_get( ))) ); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } pub fn fd_prestat_dir_name( @@ -944,7 +962,7 @@ pub fn fd_prestat_dir_name( fd: __wasi_fd_t, path: WasmPtr, path_len: M::Offset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { trace!( "wasi::fd_prestat_dir_name: fd={}, path_len={}", fd, @@ -974,9 +992,9 @@ pub fn fd_prestat_dir_name( trace!("=> result: \"{}\"", inode_val.name); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } else { - __WASI_EOVERFLOW + wasi_snapshot0::Errno::Overflow } } Kind::Symlink { .. } @@ -984,7 +1002,7 @@ pub fn fd_prestat_dir_name( | Kind::File { .. } | Kind::Socket { .. } | Kind::Pipe { .. } - | Kind::EventNotifications { .. } => __WASI_ENOTDIR, + | Kind::EventNotifications { .. } => wasi_snapshot0::Errno::Notdir, } } @@ -1009,7 +1027,7 @@ pub fn fd_pwrite( iovs_len: M::Offset, offset: __wasi_filesize_t, 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(); @@ -1019,7 +1037,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(wasi_snapshot0::Errno::Inval), __WASI_STDOUT_FILENO => { let mut guard = wasi_try_ok!( inodes @@ -1030,7 +1048,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(wasi_snapshot0::Errno::Badf); } } __WASI_STDERR_FILENO => { @@ -1043,14 +1061,14 @@ 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(wasi_snapshot0::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); + return Ok(wasi_snapshot0::Errno::Acces); } let inode_idx = fd_entry.inode; @@ -1069,7 +1087,7 @@ pub fn fd_pwrite( ); wasi_try_ok!(write_bytes(handle, &memory, iovs_arr), env) } else { - return Ok(__WASI_EINVAL); + return Ok(wasi_snapshot0::Errno::Inval); } } Kind::Socket { socket } => { @@ -1080,9 +1098,9 @@ pub fn fd_pwrite( } Kind::Dir { .. } | Kind::Root { .. } => { // TODO: verify - return Ok(__WASI_EISDIR); + return Ok(wasi_snapshot0::Errno::Isdir); } - Kind::EventNotifications { .. } => return Ok(__WASI_EINVAL), + Kind::EventNotifications { .. } => return Ok(wasi_snapshot0::Errno::Inval), Kind::Symlink { .. } => unimplemented!("Symlinks in wasi::fd_pwrite"), Kind::Buffer { buffer } => { wasi_try_ok!( @@ -1094,11 +1112,12 @@ pub fn fd_pwrite( } }; - let bytes_written: M::Offset = - wasi_try_ok!(bytes_written.try_into().map_err(|_| __WASI_EOVERFLOW)); + let bytes_written: M::Offset = wasi_try_ok!(bytes_written + .try_into() + .map_err(|_| wasi_snapshot0::Errno::Overflow)); wasi_try_mem_ok!(nwritten_ref.write(bytes_written)); - Ok(__WASI_ESUCCESS) + Ok(wasi_snapshot0::Errno::Success) } /// ### `fd_read()` @@ -1120,7 +1139,7 @@ pub fn fd_read( 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); @@ -1140,14 +1159,14 @@ 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(wasi_snapshot0::Errno::Badf); } } - __WASI_STDOUT_FILENO | __WASI_STDERR_FILENO => return Ok(__WASI_EINVAL), + __WASI_STDOUT_FILENO | __WASI_STDERR_FILENO => return Ok(wasi_snapshot0::Errno::Inval), _ => { if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_READ) { // TODO: figure out the error to return when lacking rights - return Ok(__WASI_EACCES); + return Ok(wasi_snapshot0::Errno::Acces); } let is_non_blocking = fd_entry.flags & __WASI_FDFLAG_NONBLOCK != 0; @@ -1169,7 +1188,7 @@ pub fn fd_read( ); wasi_try_ok!(read_bytes(handle, &memory, iovs_arr), env) } else { - return Ok(__WASI_EINVAL); + return Ok(wasi_snapshot0::Errno::Inval); } } Kind::Socket { socket } => { @@ -1180,7 +1199,7 @@ pub fn fd_read( } Kind::Dir { .. } | Kind::Root { .. } => { // TODO: verify - return Ok(__WASI_EISDIR); + return Ok(wasi_snapshot0::Errno::Isdir); } Kind::EventNotifications { counter, @@ -1226,7 +1245,7 @@ pub fn fd_read( // If its none blocking then exit if is_non_blocking { - return Ok(__WASI_EAGAIN); + return Ok(wasi_snapshot0::Errno::Again); } // Yield for a fixed period of time and then check again @@ -1246,16 +1265,18 @@ 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(wasi_snapshot0::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(|_| wasi_snapshot0::Errno::Overflow)); wasi_try_mem_ok!(nread_ref.write(bytes_read)); - Ok(__WASI_ESUCCESS) + Ok(wasi_snapshot0::Errno::Success) } /// ### `fd_readdir()` @@ -1280,7 +1301,7 @@ pub fn fd_readdir( buf_len: M::Offset, cookie: __wasi_dircookie_t, bufused: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { trace!("wasi::fd_readdir"); let env = ctx.data(); let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0); @@ -1358,7 +1379,7 @@ pub fn fd_readdir( | Kind::Buffer { .. } | Kind::Socket { .. } | Kind::Pipe { .. } - | Kind::EventNotifications { .. } => return __WASI_ENOTDIR, + | Kind::EventNotifications { .. } => return wasi_snapshot0::Errno::Notdir, } }; @@ -1395,9 +1416,11 @@ 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(|_| wasi_snapshot0::Errno::Overflow)); wasi_try_mem!(bufused_ref.write(buf_idx)); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `fd_renumber()` @@ -1411,13 +1434,13 @@ pub fn fd_renumber( ctx: FunctionEnvMut<'_, WasiEnv>, from: __wasi_fd_t, to: __wasi_fd_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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(wasi_snapshot0::Errno::Badf)); let new_fd_entry = Fd { // TODO: verify this is correct @@ -1427,7 +1450,7 @@ pub fn fd_renumber( fd_map.insert(to, new_fd_entry); fd_map.remove(&from); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `fd_dup()` @@ -1442,7 +1465,7 @@ pub fn fd_dup( ctx: FunctionEnvMut<'_, WasiEnv>, fd: __wasi_fd_t, ret_fd: WasmPtr<__wasi_fd_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::fd_dup"); let env = ctx.data(); @@ -1451,7 +1474,7 @@ pub fn fd_dup( wasi_try_mem!(ret_fd.write(&memory, fd)); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `fd_event()` @@ -1461,7 +1484,7 @@ pub fn fd_event( initial_val: u64, flags: __wasi_eventfdflags, ret_fd: WasmPtr<__wasi_fd_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::fd_event"); let env = ctx.data(); @@ -1484,7 +1507,7 @@ pub fn fd_event( wasi_try_mem!(ret_fd.write(&memory, fd)); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `fd_seek()` @@ -1505,7 +1528,7 @@ pub fn fd_seek( offset: __wasi_filedelta_t, whence: __wasi_whence_t, newoffset: WasmPtr<__wasi_filesize_t, M>, -) -> Result<__wasi_errno_t, WasiError> { +) -> 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); @@ -1513,14 +1536,14 @@ pub fn fd_seek( 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); + return Ok(wasi_snapshot0::Errno::Acces); } // TODO: handle case if fd is a dir? match whence { __WASI_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(wasi_snapshot0::Errno::Badf)); fd_entry.offset = (fd_entry.offset as i64 + offset) as u64 } __WASI_WHENCE_END => { @@ -1537,10 +1560,11 @@ 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(wasi_snapshot0::Errno::Badf)); fd_entry.offset = (end as i64 + offset) as u64; } else { - return Ok(__WASI_EINVAL); + return Ok(wasi_snapshot0::Errno::Inval); } } Kind::Symlink { .. } => { @@ -1552,27 +1576,27 @@ pub fn fd_seek( | Kind::Pipe { .. } | Kind::EventNotifications { .. } => { // TODO: check this - return Ok(__WASI_EINVAL); + return Ok(wasi_snapshot0::Errno::Inval); } Kind::Buffer { .. } => { // seeking buffers probably makes sense // TODO: implement this - return Ok(__WASI_EINVAL); + return Ok(wasi_snapshot0::Errno::Inval); } } } __WASI_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(wasi_snapshot0::Errno::Badf)); fd_entry.offset = offset as u64 } - _ => return Ok(__WASI_EINVAL), + _ => return Ok(wasi_snapshot0::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(wasi_snapshot0::Errno::Success) } /// ### `fd_sync()` @@ -1582,16 +1606,16 @@ pub fn fd_seek( /// 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 { +/// - `wasi_snapshot0::Errno::Perm` +/// - `wasi_snapshot0::Errno::Notcapable` +pub fn fd_sync(ctx: FunctionEnvMut<'_, WasiEnv>, fd: __wasi_fd_t) -> wasi_snapshot0::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; + return wasi_snapshot0::Errno::Acces; } let inode = fd_entry.inode; @@ -1604,19 +1628,19 @@ 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 wasi_snapshot0::Errno::Inval; } } - Kind::Root { .. } | Kind::Dir { .. } => return __WASI_EISDIR, + Kind::Root { .. } | Kind::Dir { .. } => return wasi_snapshot0::Errno::Isdir, Kind::Buffer { .. } | Kind::Symlink { .. } | Kind::Socket { .. } | Kind::Pipe { .. } - | Kind::EventNotifications { .. } => return __WASI_EINVAL, + | Kind::EventNotifications { .. } => return wasi_snapshot0::Errno::Inval, } } - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `fd_tell()` @@ -1631,7 +1655,7 @@ pub fn fd_tell( ctx: FunctionEnvMut<'_, WasiEnv>, fd: __wasi_fd_t, offset: WasmPtr<__wasi_filesize_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::fd_tell"); let env = ctx.data(); let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0); @@ -1640,12 +1664,12 @@ 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; + return wasi_snapshot0::Errno::Acces; } wasi_try_mem!(offset_ref.write(fd_entry.offset)); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `fd_write()` @@ -1668,7 +1692,7 @@ pub fn fd_write( 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); @@ -1677,7 +1701,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(wasi_snapshot0::Errno::Inval), __WASI_STDOUT_FILENO => { let mut guard = wasi_try_ok!( inodes @@ -1688,7 +1712,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(wasi_snapshot0::Errno::Badf); } } __WASI_STDERR_FILENO => { @@ -1701,12 +1725,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(wasi_snapshot0::Errno::Badf); } } _ => { if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_WRITE) { - return Ok(__WASI_EACCES); + return Ok(wasi_snapshot0::Errno::Acces); } let offset = fd_entry.offset as usize; @@ -1727,7 +1751,7 @@ pub fn fd_write( ); wasi_try_ok!(write_bytes(handle, &memory, iovs_arr), env) } else { - return Ok(__WASI_EINVAL); + return Ok(wasi_snapshot0::Errno::Inval); } } Kind::Socket { socket } => { @@ -1738,7 +1762,7 @@ pub fn fd_write( } Kind::Dir { .. } | Kind::Root { .. } => { // TODO: verify - return Ok(__WASI_EISDIR); + return Ok(wasi_snapshot0::Errno::Isdir); } Kind::EventNotifications { counter, wakers, .. @@ -1746,7 +1770,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(wasi_snapshot0::Errno::Inval); } let val = u64::from_ne_bytes(val); @@ -1772,7 +1796,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(wasi_snapshot0::Errno::Badf)); fd_entry.offset += bytes_written as u64; } wasi_try_ok!(state.fs.filestat_resync_size(inodes.deref(), fd), env); @@ -1781,11 +1805,12 @@ pub fn fd_write( } }; - let bytes_written: M::Offset = - wasi_try_ok!(bytes_written.try_into().map_err(|_| __WASI_EOVERFLOW)); + let bytes_written: M::Offset = wasi_try_ok!(bytes_written + .try_into() + .map_err(|_| wasi_snapshot0::Errno::Overflow)); wasi_try_mem_ok!(nwritten_ref.write(bytes_written)); - Ok(__WASI_ESUCCESS) + Ok(wasi_snapshot0::Errno::Success) } /// ### `fd_pipe()` @@ -1799,7 +1824,7 @@ pub fn fd_pipe( ctx: FunctionEnvMut<'_, WasiEnv>, ro_fd1: WasmPtr<__wasi_fd_t, M>, ro_fd2: WasmPtr<__wasi_fd_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { trace!("wasi::fd_pipe"); let env = ctx.data(); @@ -1827,7 +1852,7 @@ pub fn fd_pipe( wasi_try_mem!(ro_fd1.write(&memory, fd1)); wasi_try_mem!(ro_fd2.write(&memory, fd2)); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `path_create_directory()` @@ -1848,7 +1873,7 @@ pub fn path_create_directory( fd: __wasi_fd_t, path: WasmPtr, path_len: M::Offset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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); @@ -1857,11 +1882,11 @@ pub fn path_create_directory( { let guard = inodes.arena[working_dir.inode].read(); if let Kind::Root { .. } = guard.deref() { - return __WASI_EACCES; + return wasi_snapshot0::Errno::Acces; } } if !has_rights(working_dir.rights, __WASI_RIGHT_PATH_CREATE_DIRECTORY) { - return __WASI_EACCES; + return wasi_snapshot0::Errno::Acces; } let path_string = unsafe { get_input_str!(&memory, path, path_len) }; debug!("=> fd: {}, path: {}", fd, &path_string); @@ -1873,11 +1898,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(wasi_snapshot0::Errno::Inval) }) - .collect::, __wasi_errno_t>>()); + .collect::, wasi_snapshot0::Errno>>()); if path_vec.is_empty() { - return __WASI_EINVAL; + return wasi_snapshot0::Errno::Inval; } debug!("Looking at components {:?}", &path_vec); @@ -1920,7 +1945,7 @@ pub fn path_create_directory( &adjusted_path.to_string_lossy(), ) { if adjusted_path_stat.st_filetype != __WASI_FILETYPE_DIRECTORY { - return __WASI_ENOTDIR; + return wasi_snapshot0::Errno::Notdir; } } else { wasi_try!(state.fs_create_dir(&adjusted_path)); @@ -1950,12 +1975,12 @@ pub fn path_create_directory( cur_dir_inode = new_inode; } } - Kind::Root { .. } => return __WASI_EACCES, - _ => return __WASI_ENOTDIR, + Kind::Root { .. } => return wasi_snapshot0::Errno::Acces, + _ => return wasi_snapshot0::Errno::Notdir, } } - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `path_filestat_get()` @@ -1979,7 +2004,7 @@ pub fn path_filestat_get( path: WasmPtr, path_len: M::Offset, buf: WasmPtr<__wasi_filestat_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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); @@ -1997,7 +2022,7 @@ pub fn path_filestat_get( wasi_try_mem!(buf.deref(&memory).write(stat)); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `path_filestat_get()` @@ -2021,11 +2046,11 @@ pub fn path_filestat_get_internal( fd: __wasi_fd_t, flags: __wasi_lookupflags_t, path_string: &str, -) -> Result<__wasi_filestat_t, __wasi_errno_t> { +) -> Result<__wasi_filestat_t, wasi_snapshot0::Errno> { let root_dir = state.fs.get_fd(fd)?; if !has_rights(root_dir.rights, __WASI_RIGHT_PATH_FILESTAT_GET) { - return Err(__WASI_EACCES); + return Err(wasi_snapshot0::Errno::Acces); } debug!("=> base_fd: {}, path: {}", fd, path_string); @@ -2069,20 +2094,20 @@ pub fn path_filestat_set_times( st_atim: __wasi_timestamp_t, st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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; + return wasi_snapshot0::Errno::Acces; } 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) { - return __WASI_EINVAL; + return wasi_snapshot0::Errno::Inval; } let path_string = unsafe { get_input_str!(&memory, path, path_len) }; @@ -2118,7 +2143,7 @@ pub fn path_filestat_set_times( inode.stat.write().unwrap().st_mtim = time_to_set; } - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `path_link()` @@ -2147,7 +2172,7 @@ pub fn path_link( new_fd: __wasi_fd_t, new_path: WasmPtr, new_path_len: M::Offset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::path_link"); if old_flags & __WASI_LOOKUP_SYMLINK_FOLLOW != 0 { debug!(" - will follow symlinks when opening path"); @@ -2166,7 +2191,7 @@ pub fn path_link( if !(has_rights(source_fd.rights, __WASI_RIGHT_PATH_LINK_SOURCE) && has_rights(target_fd.rights, __WASI_RIGHT_PATH_LINK_TARGET)) { - return __WASI_EACCES; + return wasi_snapshot0::Errno::Acces; } let source_inode = wasi_try!(state.fs.get_inode_at_path( @@ -2185,7 +2210,7 @@ pub fn path_link( if inodes.arena[source_inode].stat.write().unwrap().st_nlink == __wasi_linkcount_t::max_value() { - return __WASI_EMLINK; + return wasi_snapshot0::Errno::Mlink; } { let mut guard = inodes.arena[target_parent_inode].write(); @@ -2193,22 +2218,22 @@ pub fn path_link( match deref_mut { Kind::Dir { entries, .. } => { if entries.contains_key(&new_entry_name) { - return __WASI_EEXIST; + return wasi_snapshot0::Errno::Exist; } entries.insert(new_entry_name, source_inode); } - Kind::Root { .. } => return __WASI_EINVAL, + Kind::Root { .. } => return wasi_snapshot0::Errno::Inval, Kind::File { .. } | Kind::Symlink { .. } | Kind::Buffer { .. } | Kind::Socket { .. } | Kind::Pipe { .. } - | Kind::EventNotifications { .. } => return __WASI_ENOTDIR, + | Kind::EventNotifications { .. } => return wasi_snapshot0::Errno::Notdir, } } inodes.arena[source_inode].stat.write().unwrap().st_nlink += 1; - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `path_open()` @@ -2234,7 +2259,7 @@ pub fn path_link( /// - `__wasi_fd_t* 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` +/// - `wasi_snapshot0::Errno::Acces`, `__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` pub fn path_open( ctx: FunctionEnvMut<'_, WasiEnv>, dirfd: __wasi_fd_t, @@ -2246,7 +2271,7 @@ pub fn path_open( fs_rights_inheriting: __wasi_rights_t, fs_flags: __wasi_fdflags_t, fd: WasmPtr<__wasi_fd_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::path_open"); if dirflags & __WASI_LOOKUP_SYMLINK_FOLLOW != 0 { debug!(" - will follow symlinks when opening path"); @@ -2256,7 +2281,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 wasi_snapshot0::Errno::Nametoolong; } let fd_ref = fd.deref(&memory); @@ -2272,7 +2297,7 @@ pub fn path_open( // ASSUMPTION: open rights apply recursively if !has_rights(working_dir.rights, __WASI_RIGHT_PATH_OPEN) { - return __WASI_EACCES; + return wasi_snapshot0::Errno::Acces; } let path_string = unsafe { get_input_str!(&memory, path, path_len) }; @@ -2306,13 +2331,13 @@ 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 wasi_snapshot0::Errno::Success; } if o_flags & __WASI_O_DIRECTORY != 0 { - return __WASI_ENOTDIR; + return wasi_snapshot0::Errno::Notdir; } if o_flags & __WASI_O_EXCL != 0 { - return __WASI_EEXIST; + return wasi_snapshot0::Errno::Exist; } let write_permission = adjusted_rights & __WASI_RIGHT_FD_WRITE != 0; @@ -2370,7 +2395,7 @@ pub fn path_open( debug!("Maybe creating file"); if o_flags & __WASI_O_CREAT != 0 { if o_flags & __WASI_O_DIRECTORY != 0 { - return __WASI_ENOTDIR; + return wasi_snapshot0::Errno::Notdir; } debug!("Creating file"); // strip end file name @@ -2390,8 +2415,8 @@ pub fn path_open( new_path.push(&new_entity_name); new_path } - Kind::Root { .. } => return __WASI_EACCES, - _ => return __WASI_EINVAL, + Kind::Root { .. } => return wasi_snapshot0::Errno::Acces, + _ => return wasi_snapshot0::Errno::Inval, } }; // once we got the data we need from the parent, we lookup the host file @@ -2461,7 +2486,7 @@ pub fn path_open( wasi_try_mem!(fd_ref.write(out_fd)); debug!("wasi::path_open returning fd {}", out_fd); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `path_readlink()` @@ -2488,14 +2513,14 @@ pub fn path_readlink( buf: WasmPtr, buf_len: M::Offset, buf_used: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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; + return wasi_snapshot0::Errno::Acces; } let path_str = unsafe { get_input_str!(&memory, path, path_len) }; let inode = wasi_try!(state @@ -2510,7 +2535,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 wasi_snapshot0::Errno::Overflow; } let bytes: Vec<_> = bytes.collect(); @@ -2518,24 +2543,26 @@ pub fn path_readlink( wasi_try_mem!(out.write_slice(&bytes)); // should we null terminate this? - let bytes_len: M::Offset = - wasi_try!(bytes.len().try_into().map_err(|_| __WASI_EOVERFLOW)); + let bytes_len: M::Offset = wasi_try!(bytes + .len() + .try_into() + .map_err(|_| wasi_snapshot0::Errno::Overflow)); wasi_try_mem!(buf_used.deref(&memory).write(bytes_len)); } else { - return __WASI_EINVAL; + return wasi_snapshot0::Errno::Inval; } } - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } -/// Returns __WASI_ENOTEMTPY if directory is not empty +/// Returns wasi_snapshot0::Errno::Notemtpy if directory is not empty pub fn path_remove_directory( ctx: FunctionEnvMut<'_, WasiEnv>, fd: __wasi_fd_t, path: WasmPtr, path_len: M::Offset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { // TODO check if fd is a dir, ensure it's within sandbox, etc. debug!("wasi::path_remove_directory"); let env = ctx.data(); @@ -2560,12 +2587,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 wasi_snapshot0::Errno::Notempty; } path.clone() } - Kind::Root { .. } => return __WASI_EACCES, - _ => return __WASI_ENOTDIR, + Kind::Root { .. } => return wasi_snapshot0::Errno::Acces, + _ => return wasi_snapshot0::Errno::Notdir, } }; @@ -2576,11 +2603,13 @@ 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(wasi_snapshot0::Errno::Inval)); // TODO: make this a debug assert in the future assert!(inode == removed_inode); } - Kind::Root { .. } => return __WASI_EACCES, + Kind::Root { .. } => return wasi_snapshot0::Errno::Acces, _ => unreachable!( "Internal logic error in wasi::path_remove_directory, parent is not a directory" ), @@ -2599,7 +2628,7 @@ pub fn path_remove_directory( return err; } - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `path_rename()` @@ -2625,7 +2654,7 @@ pub fn path_rename( new_fd: __wasi_fd_t, new_path: WasmPtr, new_path_len: M::Offset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!( "wasi::path_rename: old_fd = {}, new_fd = {}", old_fd, new_fd @@ -2641,11 +2670,11 @@ 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; + return wasi_snapshot0::Errno::Acces; } 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; + return wasi_snapshot0::Errno::Acces; } } @@ -2666,7 +2695,7 @@ pub fn path_rename( ) .is_ok() { - return __WASI_EEXIST; + return wasi_snapshot0::Errno::Exist; } let (source_parent_inode, source_entry_name) = wasi_try!(state @@ -2682,15 +2711,15 @@ pub fn path_rename( match deref { Kind::Dir { entries, path, .. } => { if entries.contains_key(&target_entry_name) { - return __WASI_EEXIST; + return wasi_snapshot0::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 wasi_snapshot0::Errno::Notcapable, Kind::Socket { .. } | Kind::Pipe { .. } | Kind::EventNotifications { .. } => { - return __WASI_EINVAL + return wasi_snapshot0::Errno::Inval } Kind::Symlink { .. } | Kind::File { .. } | Kind::Buffer { .. } => { unreachable!("Fatal internal logic error: parent of inode is not a directory") @@ -2703,11 +2732,13 @@ 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(wasi_snapshot0::Errno::Noent)) } - Kind::Root { .. } => return __WASI_ENOTCAPABLE, + Kind::Root { .. } => return wasi_snapshot0::Errno::Notcapable, Kind::Socket { .. } | Kind::Pipe { .. } | Kind::EventNotifications { .. } => { - return __WASI_EINVAL + return wasi_snapshot0::Errno::Inval } Kind::Symlink { .. } | Kind::File { .. } | Kind::Buffer { .. } => { unreachable!("Fatal internal logic error: parent of inode is not a directory") @@ -2786,7 +2817,7 @@ pub fn path_rename( } } - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `path_symlink()` @@ -2809,7 +2840,7 @@ pub fn path_symlink( fd: __wasi_fd_t, new_path: WasmPtr, new_path_len: M::Offset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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); @@ -2817,7 +2848,7 @@ pub fn path_symlink( 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; + return wasi_snapshot0::Errno::Acces; } // get the depth of the parent + 1 (UNDER INVESTIGATION HMMMMMMMM THINK FISH ^ THINK FISH) @@ -2844,12 +2875,12 @@ pub fn path_symlink( match deref { Kind::Dir { entries, .. } => { if entries.contains_key(&entry_name) { - return __WASI_EEXIST; + return wasi_snapshot0::Errno::Exist; } } - Kind::Root { .. } => return __WASI_ENOTCAPABLE, + Kind::Root { .. } => return wasi_snapshot0::Errno::Notcapable, Kind::Socket { .. } | Kind::Pipe { .. } | Kind::EventNotifications { .. } => { - return __WASI_EINVAL + return wasi_snapshot0::Errno::Inval } Kind::File { .. } | Kind::Symlink { .. } | Kind::Buffer { .. } => { unreachable!("get_parent_inode_at_path returned something other than a Dir or Root") @@ -2891,7 +2922,7 @@ pub fn path_symlink( } } - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `path_unlink_file()` @@ -2908,14 +2939,14 @@ pub fn path_unlink_file( fd: __wasi_fd_t, path: WasmPtr, path_len: M::Offset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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; + return wasi_snapshot0::Errno::Acces; } let path_str = unsafe { get_input_str!(&memory, path, path_len) }; debug!("Requested file: {}", path_str); @@ -2937,13 +2968,15 @@ 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(wasi_snapshot0::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 wasi_snapshot0::Errno::Acces, _ => unreachable!( "Internal logic error in wasi::path_unlink_file, parent is not a directory" ), @@ -2971,7 +3004,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 wasi_snapshot0::Errno::Isdir, Kind::Symlink { .. } => { // TODO: actually delete real symlinks and do nothing for virtual symlinks } @@ -3001,7 +3034,7 @@ pub fn path_unlink_file( } } - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `poll_oneoff()` @@ -3022,7 +3055,7 @@ pub fn poll_oneoff( out_: WasmPtr<__wasi_event_t, M>, nsubscriptions: M::Offset, nevents: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { trace!("wasi::poll_oneoff"); trace!(" => nsubscriptions = {}", nsubscriptions); let env = ctx.data(); @@ -3049,7 +3082,7 @@ pub fn poll_oneoff( _ => { 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); + return Ok(wasi_snapshot0::Errno::Acces); } } } @@ -3062,7 +3095,7 @@ pub fn poll_oneoff( _ => { 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); + return Ok(wasi_snapshot0::Errno::Acces); } } } @@ -3114,7 +3147,7 @@ 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); + return Ok(wasi_snapshot0::Errno::Acces); } { @@ -3125,13 +3158,13 @@ pub fn poll_oneoff( if let Some(h) = handle { crate::state::InodeValFileReadGuard { guard } } else { - return Ok(__WASI_EBADF); + return Ok(wasi_snapshot0::Errno::Badf); } } Kind::Socket { .. } | Kind::Pipe { .. } | Kind::EventNotifications { .. } => { - return Ok(__WASI_EBADF); + return Ok(wasi_snapshot0::Errno::Badf); } Kind::Dir { .. } | Kind::Root { .. } @@ -3151,7 +3184,7 @@ 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(wasi_snapshot0::Errno::Badf)).deref()); } f }; @@ -3192,14 +3225,14 @@ 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 error = wasi_snapshot0::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 = wasi_snapshot0::Errno::Io, + PollEvent::PollHangUp => flags = wasi_snapshot0::Errno::VentFdReadwriteHangup, + PollEvent::PollInvalid => error = wasi_snapshot0::Errno::Inval, PollEvent::PollIn => { bytes_available = wasi_try_ok!( fds[i] @@ -3208,7 +3241,7 @@ pub fn poll_oneoff( env ) .unwrap_or(0usize); - error = __WASI_ESUCCESS; + error = wasi_snapshot0::Errno::Success; } PollEvent::PollOut => { bytes_available = wasi_try_ok!( @@ -3218,7 +3251,7 @@ pub fn poll_oneoff( env ) .unwrap_or(0usize); - error = __WASI_ESUCCESS; + error = wasi_snapshot0::Errno::Success; } } } @@ -3242,7 +3275,7 @@ pub fn poll_oneoff( for (clock_info, userdata) in clock_subs { let event = __wasi_event_t { userdata, - error: __WASI_ESUCCESS, + error: wasi_snapshot0::Errno::Success, type_: __WASI_EVENTTYPE_CLOCK, u: unsafe { __wasi_event_u { @@ -3257,9 +3290,11 @@ pub fn poll_oneoff( 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(|_| wasi_snapshot0::Errno::Overflow)); wasi_try_mem_ok!(out_ptr.write(events_seen)); - Ok(__WASI_ESUCCESS) + Ok(wasi_snapshot0::Errno::Success) } /// ### `proc_exit()` @@ -3283,18 +3318,18 @@ pub fn proc_exit( /// Inputs: /// - `__wasi_signal_t` /// 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: __wasi_signal_t) -> wasi_snapshot0::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(wasi_snapshot0::Errno::Success) } /// ### `random_get()` @@ -3308,7 +3343,7 @@ pub fn random_get( ctx: FunctionEnvMut<'_, WasiEnv>, buf: WasmPtr, buf_len: M::Offset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { trace!("wasi::random_get buf_len: {}", buf_len); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -3319,9 +3354,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 + wasi_snapshot0::Errno::Success } - Err(_) => __WASI_EIO, + Err(_) => wasi_snapshot0::Errno::Io, } } @@ -3330,7 +3365,7 @@ pub fn random_get( pub fn tty_get( ctx: FunctionEnvMut<'_, WasiEnv>, tty_state: WasmPtr<__wasi_tty_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::tty_stdin"); let env = ctx.data(); @@ -3365,7 +3400,7 @@ pub fn tty_get( let memory = env.memory_view(&ctx); wasi_try_mem!(tty_state.write(&memory, state)); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `tty_set()` @@ -3373,7 +3408,7 @@ pub fn tty_get( pub fn tty_set( ctx: FunctionEnvMut<'_, WasiEnv>, tty_state: WasmPtr<__wasi_tty_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::tty_set"); let env = ctx.data(); @@ -3387,33 +3422,33 @@ pub fn tty_set( stdin_tty: match state.stdin_tty { __WASI_BOOL_FALSE => false, __WASI_BOOL_TRUE => true, - _ => return __WASI_EINVAL, + _ => return wasi_snapshot0::Errno::Inval, }, stdout_tty: match state.stdout_tty { __WASI_BOOL_FALSE => false, __WASI_BOOL_TRUE => true, - _ => return __WASI_EINVAL, + _ => return wasi_snapshot0::Errno::Inval, }, stderr_tty: match state.stderr_tty { __WASI_BOOL_FALSE => false, __WASI_BOOL_TRUE => true, - _ => return __WASI_EINVAL, + _ => return wasi_snapshot0::Errno::Inval, }, echo: match state.echo { __WASI_BOOL_FALSE => false, __WASI_BOOL_TRUE => true, - _ => return __WASI_EINVAL, + _ => return wasi_snapshot0::Errno::Inval, }, line_buffered: match state.line_buffered { __WASI_BOOL_FALSE => false, __WASI_BOOL_TRUE => true, - _ => return __WASI_EINVAL, + _ => return wasi_snapshot0::Errno::Inval, }, }; env.runtime.tty_set(state); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `getcwd()` @@ -3424,7 +3459,7 @@ pub fn getcwd( ctx: FunctionEnvMut<'_, WasiEnv>, path: WasmPtr, path_len: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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); @@ -3440,7 +3475,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 wasi_snapshot0::Errno::Overflow; } let cur_dir = { @@ -3450,13 +3485,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 wasi_snapshot0::Errno::Overflow; } u8_buffer }; wasi_try_mem!(path_slice.write_slice(&cur_dir[..])); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `chdir()` @@ -3465,14 +3500,14 @@ pub fn chdir( ctx: FunctionEnvMut<'_, WasiEnv>, path: WasmPtr, path_len: M::Offset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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 + wasi_snapshot0::Errno::Success } /// ### `thread_spawn()` @@ -3500,7 +3535,7 @@ pub fn thread_spawn( user_data: u64, reactor: __wasi_bool_t, ret_tid: WasmPtr<__wasi_tid_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::thread_spawn"); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -3508,12 +3543,12 @@ pub fn thread_spawn( // Load the callback function if method.as_str() != "_thread_start" { - return __WASI_ENOTCAPABLE; + return wasi_snapshot0::Errno::Notcapable; }; /* let funct = unsafe { if env.thread_start_ref().is_none() { - return __WASI_EADDRNOTAVAIL; + return wasi_snapshot0::Errno::Addrnotavail; } env.thread_start_ref_unchecked() }; @@ -3522,7 +3557,7 @@ pub fn thread_spawn( let reactor = match reactor { __WASI_BOOL_FALSE => false, __WASI_BOOL_TRUE => true, - _ => return __WASI_EINVAL, + _ => return wasi_snapshot0::Errno::Inval, }; // Create the sub-thread @@ -3563,7 +3598,7 @@ pub fn thread_spawn( drop(sub_thread); })) .map_err(|err| { - let err: __wasi_errno_t = err.into(); + let err: wasi_snapshot0::Errno = err.into(); err })); id @@ -3571,7 +3606,7 @@ pub fn thread_spawn( let child: __wasi_tid_t = child.into(); wasi_try_mem!(ret_tid.write(&memory, child)); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `thread_sleep()` @@ -3583,13 +3618,13 @@ pub fn thread_spawn( pub fn thread_sleep( ctx: FunctionEnvMut<'_, WasiEnv>, duration: __wasi_timestamp_t, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { debug!("wasi::thread_sleep"); let env = ctx.data(); let duration = Duration::from_nanos(duration as u64); env.sleep(duration)?; - Ok(__WASI_ESUCCESS) + Ok(wasi_snapshot0::Errno::Success) } /// ### `thread_id()` @@ -3598,14 +3633,14 @@ pub fn thread_sleep( pub fn thread_id( ctx: FunctionEnvMut<'_, WasiEnv>, ret_tid: WasmPtr<__wasi_tid_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::thread_id"); let env = ctx.data(); let tid: __wasi_tid_t = env.id.into(); let memory = env.memory_view(&ctx); wasi_try_mem!(ret_tid.write(&memory, tid)); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `thread_join()` @@ -3618,7 +3653,7 @@ pub fn thread_id( pub fn thread_join( ctx: FunctionEnvMut<'_, WasiEnv>, tid: __wasi_tid_t, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { debug!("wasi::thread_join"); let env = ctx.data(); @@ -3634,9 +3669,9 @@ pub fn thread_join( } env.yield_now()?; } - Ok(__WASI_ESUCCESS) + Ok(wasi_snapshot0::Errno::Success) } else { - Ok(__WASI_ESUCCESS) + Ok(wasi_snapshot0::Errno::Success) } } @@ -3646,18 +3681,20 @@ pub fn thread_join( pub fn thread_parallelism( ctx: FunctionEnvMut<'_, WasiEnv>, ret_parallelism: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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: wasi_snapshot0::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(|_| wasi_snapshot0::Errno::Overflow)); let memory = env.memory_view(&ctx); wasi_try_mem!(ret_parallelism.write(&memory, parallelism)); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `getpid()` @@ -3665,7 +3702,7 @@ pub fn thread_parallelism( pub fn getpid( ctx: FunctionEnvMut<'_, WasiEnv>, ret_pid: WasmPtr<__wasi_pid_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::getpid"); let env = ctx.data(); @@ -3673,9 +3710,9 @@ pub fn 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_snapshot0::Errno::Success } else { - __WASI_ENOTSUP + wasi_snapshot0::Errno::Notsup } } @@ -3691,7 +3728,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)) } @@ -4130,7 +4167,7 @@ pub fn ws_connect( url: WasmPtr, url_len: M::Offset, ret_sock: WasmPtr<__wasi_fd_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::ws_connect"); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -4158,7 +4195,7 @@ pub fn ws_connect( wasi_try_mem!(ret_sock.write(&memory, fd)); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `http_request()` @@ -4187,7 +4224,7 @@ pub fn http_request( headers_len: M::Offset, gzip: __wasi_bool_t, ret_handles: WasmPtr<__wasi_http_handles_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::http_request"); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -4198,7 +4235,7 @@ pub fn http_request( let gzip = match gzip { __WASI_BOOL_FALSE => false, __WASI_BOOL_TRUE => true, - _ => return __WASI_EINVAL, + _ => return wasi_snapshot0::Errno::Inval, }; let socket = wasi_try!(env @@ -4273,7 +4310,7 @@ pub fn http_request( wasi_try_mem!(ret_handles.write(&memory, handles)); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `http_status()` @@ -4288,7 +4325,7 @@ pub fn http_status( ctx: FunctionEnvMut<'_, WasiEnv>, sock: __wasi_fd_t, status: WasmPtr<__wasi_http_status_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::http_status"); let env = ctx.data(); @@ -4312,7 +4349,7 @@ pub fn http_status( wasi_try_mem!(ref_status.write(status)); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `port_bridge()` @@ -4330,7 +4367,7 @@ pub fn port_bridge( token: WasmPtr, token_len: M::Offset, security: __wasi_streamsecurity_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::port_bridge"); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -4341,32 +4378,32 @@ pub fn port_bridge( __WASI_STREAM_SECURITY_ANY_ENCRYPTION => StreamSecurity::AnyEncyption, __WASI_STREAM_SECURITY_CLASSIC_ENCRYPTION => StreamSecurity::ClassicEncryption, __WASI_STREAM_SECURITY_DOUBLE_ENCRYPTION => StreamSecurity::DoubleEncryption, - _ => return __WASI_EINVAL, + _ => return wasi_snapshot0::Errno::Inval, }; wasi_try!(env .net() .bridge(network.as_str(), token.as_str(), security) .map_err(net_error_into_wasi_err)); - __WASI_ESUCCESS + wasi_snapshot0::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>) -> wasi_snapshot0::Errno { debug!("wasi::port_unbridge"); let env = ctx.data(); wasi_try!(env.net().unbridge().map_err(net_error_into_wasi_err)); - __WASI_ESUCCESS + wasi_snapshot0::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>) -> wasi_snapshot0::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 + wasi_snapshot0::Errno::Success } /// ### `port_addr_add()` @@ -4378,7 +4415,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 { +) -> wasi_snapshot0::Errno { debug!("wasi::port_addr_add"); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -4387,7 +4424,7 @@ pub fn port_addr_add( .net() .ip_add(cidr.ip, cidr.prefix) .map_err(net_error_into_wasi_err)); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `port_addr_remove()` @@ -4399,22 +4436,22 @@ pub fn port_addr_add( pub fn port_addr_remove( ctx: FunctionEnvMut<'_, WasiEnv>, ip: WasmPtr<__wasi_addr_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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 + wasi_snapshot0::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>) -> wasi_snapshot0::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 + wasi_snapshot0::Errno::Success } /// ### `port_mac()` @@ -4422,14 +4459,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 { +) -> wasi_snapshot0::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 + wasi_snapshot0::Errno::Success } /// ### `port_ip_list()` @@ -4449,21 +4486,26 @@ pub fn port_addr_list( ctx: FunctionEnvMut<'_, WasiEnv>, addrs: WasmPtr<__wasi_cidr_t, M>, naddrs: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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(|_| wasi_snapshot0::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(|_| wasi_snapshot0::Errno::Overflow)); wasi_try_mem!(naddrs.write(&memory, addrs_len)); if addrs.len() as u64 > max_addrs { - return __WASI_EOVERFLOW; + return wasi_snapshot0::Errno::Overflow; } for n in 0..addrs.len() { @@ -4471,7 +4513,7 @@ pub fn port_addr_list( super::state::write_cidr(&memory, nip.as_ptr::(), *addrs.get(n).unwrap()); } - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `port_gateway_set()` @@ -4483,14 +4525,14 @@ pub fn port_addr_list( pub fn port_gateway_set( ctx: FunctionEnvMut<'_, WasiEnv>, ip: WasmPtr<__wasi_addr_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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 + wasi_snapshot0::Errno::Success } /// ### `port_route_add()` @@ -4501,7 +4543,7 @@ pub fn port_route_add( 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 { +) -> wasi_snapshot0::Errno { debug!("wasi::port_route_add"); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -4511,20 +4553,20 @@ pub fn port_route_add( let preferred_until = match preferred_until.tag { __WASI_OPTION_NONE => None, __WASI_OPTION_SOME => Some(Duration::from_nanos(preferred_until.u)), - _ => return __WASI_EINVAL, + _ => return wasi_snapshot0::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, + _ => return wasi_snapshot0::Errno::Inval, }; wasi_try!(env .net() .route_add(cidr, via_router, preferred_until, expires_at) .map_err(net_error_into_wasi_err)); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `port_route_remove()` @@ -4532,22 +4574,22 @@ pub fn port_route_add( pub fn port_route_remove( ctx: FunctionEnvMut<'_, WasiEnv>, ip: WasmPtr<__wasi_addr_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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 + wasi_snapshot0::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>) -> wasi_snapshot0::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 + wasi_snapshot0::Errno::Success } /// ### `port_route_list()` @@ -4563,22 +4605,25 @@ pub fn port_route_list( ctx: FunctionEnvMut<'_, WasiEnv>, routes: WasmPtr<__wasi_route_t, M>, nroutes: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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(|_| wasi_snapshot0::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(|_| wasi_snapshot0::Errno::Inval)); wasi_try_mem!(nroutes.write(routes_len)); if routes.len() > max_routes { - return __WASI_EOVERFLOW; + return wasi_snapshot0::Errno::Overflow; } for n in 0..routes.len() { @@ -4590,7 +4635,7 @@ pub fn port_route_list( ); } - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `sock_shutdown()` @@ -4604,7 +4649,7 @@ pub fn sock_shutdown( ctx: FunctionEnvMut<'_, WasiEnv>, sock: __wasi_fd_t, how: __wasi_sdflags_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::sock_shutdown"); let both = __WASI_SHUT_RD | __WASI_SHUT_WR; @@ -4612,7 +4657,7 @@ 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 wasi_snapshot0::Errno::Inval, }; wasi_try!(__sock_actor_mut( @@ -4622,7 +4667,7 @@ pub fn sock_shutdown( |socket| { socket.shutdown(how) } )); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `sock_status()` @@ -4631,7 +4676,7 @@ pub fn sock_status( ctx: FunctionEnvMut<'_, WasiEnv>, sock: __wasi_fd_t, ret_status: WasmPtr<__wasi_sockstatus_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::sock_status"); let status = wasi_try!(__sock_actor(&ctx, sock, 0, |socket| { socket.status() })); @@ -4648,7 +4693,7 @@ pub fn sock_status( let memory = env.memory_view(&ctx); wasi_try_mem!(ret_status.write(&memory, status)); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `sock_addr_local()` @@ -4666,7 +4711,7 @@ pub fn sock_addr_local( ctx: FunctionEnvMut<'_, WasiEnv>, sock: __wasi_fd_t, ret_addr: WasmPtr<__wasi_addr_port_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::sock_addr_local"); let addr = wasi_try!(__sock_actor(&ctx, sock, 0, |socket| { @@ -4679,7 +4724,7 @@ pub fn sock_addr_local( addr.ip(), addr.port() )); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `sock_addr_peer()` @@ -4697,7 +4742,7 @@ pub fn sock_addr_peer( ctx: FunctionEnvMut<'_, WasiEnv>, sock: __wasi_fd_t, ro_addr: WasmPtr<__wasi_addr_port_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::sock_addr_peer"); let env = ctx.data(); @@ -4709,7 +4754,7 @@ pub fn sock_addr_peer( addr.ip(), addr.port() )); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `sock_open()` @@ -4737,7 +4782,7 @@ pub fn sock_open( ty: __wasi_socktype_t, pt: __wasi_sockproto_t, ro_sock: WasmPtr<__wasi_fd_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::sock_open"); let env = ctx.data(); @@ -4761,7 +4806,7 @@ pub fn sock_open( accept_timeout: None, }), }, - _ => return __WASI_ENOTSUP, + _ => return wasi_snapshot0::Errno::Notsup, }; let inode = state.fs.create_inode_with_default_stat( @@ -4775,7 +4820,7 @@ pub fn sock_open( wasi_try_mem!(ro_sock.write(&memory, fd)); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `sock_set_opt_flag()` @@ -4792,20 +4837,20 @@ pub fn sock_set_opt_flag( sock: __wasi_fd_t, opt: __wasi_sockoption_t, flag: __wasi_bool_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::sock_set_opt_flag(ty={})", opt); let flag = match flag { __WASI_BOOL_FALSE => false, __WASI_BOOL_TRUE => true, - _ => return __WASI_EINVAL, + _ => return wasi_snapshot0::Errno::Inval, }; let option: super::state::WasiSocketOption = opt.into(); wasi_try!(__sock_actor_mut(&ctx, sock, 0, |socket| { socket.set_opt_flag(option, flag) })); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `sock_get_opt_flag()` @@ -4821,7 +4866,7 @@ pub fn sock_get_opt_flag( sock: __wasi_fd_t, opt: __wasi_sockoption_t, ret_flag: WasmPtr<__wasi_bool_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::sock_get_opt_flag(ty={})", opt); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -4837,7 +4882,7 @@ pub fn sock_get_opt_flag( wasi_try_mem!(ret_flag.write(&memory, flag)); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `sock_set_opt_time()` @@ -4853,7 +4898,7 @@ pub fn sock_set_opt_time( sock: __wasi_fd_t, opt: __wasi_sockoption_t, time: WasmPtr<__wasi_option_timestamp_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::sock_set_opt_time(ty={})", opt); let env = ctx.data(); @@ -4862,7 +4907,7 @@ pub fn sock_set_opt_time( let time = match time.tag { __WASI_OPTION_NONE => None, __WASI_OPTION_SOME => Some(Duration::from_nanos(time.u)), - _ => return __WASI_EINVAL, + _ => return wasi_snapshot0::Errno::Inval, }; let ty = match opt { @@ -4871,14 +4916,14 @@ pub fn sock_set_opt_time( __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, + _ => return wasi_snapshot0::Errno::Inval, }; let option: super::state::WasiSocketOption = opt.into(); wasi_try!(__sock_actor_mut(&ctx, sock, 0, |socket| { socket.set_opt_time(ty, time) })); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `sock_get_opt_time()` @@ -4893,7 +4938,7 @@ pub fn sock_get_opt_time( sock: __wasi_fd_t, opt: __wasi_sockoption_t, ret_time: WasmPtr<__wasi_option_timestamp_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::sock_get_opt_time(ty={})", opt); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -4904,7 +4949,7 @@ pub fn sock_get_opt_time( __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, + _ => return wasi_snapshot0::Errno::Inval, }; let time = wasi_try!(__sock_actor(&ctx, sock, 0, |socket| { @@ -4923,7 +4968,7 @@ pub fn sock_get_opt_time( wasi_try_mem!(ret_time.write(&memory, time)); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `sock_set_opt_size() @@ -4940,7 +4985,7 @@ pub fn sock_set_opt_size( sock: __wasi_fd_t, opt: __wasi_sockoption_t, size: __wasi_filesize_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::sock_set_opt_size(ty={})", opt); let ty = match opt { @@ -4949,7 +4994,7 @@ pub fn sock_set_opt_size( __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, + _ => return wasi_snapshot0::Errno::Inval, }; let option: super::state::WasiSocketOption = opt.into(); @@ -4959,10 +5004,10 @@ pub fn sock_set_opt_size( __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), + _ => Err(wasi_snapshot0::Errno::Inval), } })); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `sock_get_opt_size()` @@ -4978,7 +5023,7 @@ pub fn sock_get_opt_size( sock: __wasi_fd_t, opt: __wasi_sockoption_t, ret_size: WasmPtr<__wasi_filesize_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::sock_get_opt_size(ty={})", opt); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -4995,12 +5040,12 @@ pub fn sock_get_opt_size( __WASI_SOCK_OPTION_MULTICAST_TTL_V4 => { socket.multicast_ttl_v4().map(|a| a as __wasi_filesize_t) } - _ => Err(__WASI_EINVAL), + _ => Err(wasi_snapshot0::Errno::Inval), } })); wasi_try_mem!(ret_size.write(&memory, size)); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `sock_join_multicast_v4()` @@ -5016,7 +5061,7 @@ pub fn sock_join_multicast_v4( sock: __wasi_fd_t, multiaddr: WasmPtr<__wasi_addr_ip4_t, M>, iface: WasmPtr<__wasi_addr_ip4_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::sock_join_multicast_v4"); let env = ctx.data(); @@ -5026,7 +5071,7 @@ pub fn sock_join_multicast_v4( wasi_try!(__sock_actor_mut(&ctx, sock, 0, |socket| { socket.join_multicast_v4(multiaddr, iface) })); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `sock_leave_multicast_v4()` @@ -5042,7 +5087,7 @@ pub fn sock_leave_multicast_v4( sock: __wasi_fd_t, multiaddr: WasmPtr<__wasi_addr_ip4_t, M>, iface: WasmPtr<__wasi_addr_ip4_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::sock_leave_multicast_v4"); let env = ctx.data(); @@ -5052,7 +5097,7 @@ pub fn sock_leave_multicast_v4( wasi_try!(__sock_actor_mut(&ctx, sock, 0, |socket| { socket.leave_multicast_v4(multiaddr, iface) })); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `sock_join_multicast_v6()` @@ -5068,7 +5113,7 @@ pub fn sock_join_multicast_v6( sock: __wasi_fd_t, multiaddr: WasmPtr<__wasi_addr_ip6_t, M>, iface: u32, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::sock_join_multicast_v6"); let env = ctx.data(); @@ -5077,7 +5122,7 @@ pub fn sock_join_multicast_v6( wasi_try!(__sock_actor_mut(&ctx, sock, 0, |socket| { socket.join_multicast_v6(multiaddr, iface) })); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `sock_leave_multicast_v6()` @@ -5093,7 +5138,7 @@ pub fn sock_leave_multicast_v6( sock: __wasi_fd_t, multiaddr: WasmPtr<__wasi_addr_ip6_t, M>, iface: u32, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::sock_leave_multicast_v6"); let env = ctx.data(); @@ -5102,7 +5147,7 @@ pub fn sock_leave_multicast_v6( wasi_try!(__sock_actor_mut(&ctx, sock, 0, |socket| { socket.leave_multicast_v6(multiaddr, iface) })); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `sock_bind()` @@ -5117,7 +5162,7 @@ pub fn sock_bind( ctx: FunctionEnvMut<'_, WasiEnv>, sock: __wasi_fd_t, addr: WasmPtr<__wasi_addr_port_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::sock_bind"); let env = ctx.data(); @@ -5130,7 +5175,7 @@ pub fn sock_bind( __WASI_RIGHT_SOCK_BIND, |socket| { socket.bind(env.net(), addr) } )); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `sock_listen()` @@ -5149,18 +5194,18 @@ pub fn sock_listen( ctx: FunctionEnvMut<'_, WasiEnv>, sock: __wasi_fd_t, backlog: M::Offset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::sock_listen"); let env = ctx.data(); - let backlog: usize = wasi_try!(backlog.try_into().map_err(|_| __WASI_EINVAL)); + let backlog: usize = wasi_try!(backlog.try_into().map_err(|_| wasi_snapshot0::Errno::Inval)); wasi_try!(__sock_upgrade( &ctx, sock, __WASI_RIGHT_SOCK_BIND, |socket| { socket.listen(env.net(), backlog) } )); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `sock_accept()` @@ -5181,7 +5226,7 @@ pub fn sock_accept( fd_flags: __wasi_fdflags_t, ro_fd: WasmPtr<__wasi_fd_t, M>, ro_addr: WasmPtr<__wasi_addr_port_t, M>, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { debug!("wasi::sock_accept"); let env = ctx.data(); @@ -5197,11 +5242,11 @@ pub fn sock_accept( ret = a; break; } - Err(__WASI_ETIMEDOUT) => { + Err(wasi_snapshot0::Errno::Timedout) => { env.yield_now()?; continue; } - Err(__WASI_EAGAIN) => { + Err(wasi_snapshot0::Errno::Again) => { env.sleep(Duration::from_millis(5))?; continue; } @@ -5235,7 +5280,7 @@ pub fn sock_accept( addr.port() )); - Ok(__WASI_ESUCCESS) + Ok(wasi_snapshot0::Errno::Success) } /// ### `sock_connect()` @@ -5254,7 +5299,7 @@ pub fn sock_connect( ctx: FunctionEnvMut<'_, WasiEnv>, sock: __wasi_fd_t, addr: WasmPtr<__wasi_addr_port_t, M>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { debug!("wasi::sock_connect"); let env = ctx.data(); @@ -5267,7 +5312,7 @@ pub fn sock_connect( __WASI_RIGHT_SOCK_CONNECT, |socket| { socket.connect(env.net(), addr) } )); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } /// ### `sock_recv()` @@ -5291,7 +5336,7 @@ pub fn sock_recv( _ri_flags: __wasi_riflags_t, ro_data_len: WasmPtr, ro_flags: WasmPtr<__wasi_roflags_t, M>, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { debug!("wasi::sock_recv"); let env = ctx.data(); @@ -5304,12 +5349,14 @@ pub fn sock_recv( __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: M::Offset = wasi_try_ok!(bytes_read + .try_into() + .map_err(|_| wasi_snapshot0::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(wasi_snapshot0::Errno::Success) } /// ### `sock_recv_from()` @@ -5334,7 +5381,7 @@ pub fn sock_recv_from( ro_data_len: WasmPtr, ro_flags: WasmPtr<__wasi_roflags_t, M>, ro_addr: WasmPtr<__wasi_addr_port_t, M>, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { debug!("wasi::sock_recv_from"); let env = ctx.data(); @@ -5347,12 +5394,14 @@ pub fn sock_recv_from( __WASI_RIGHT_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(|_| wasi_snapshot0::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(wasi_snapshot0::Errno::Success) } /// ### `sock_send()` @@ -5375,7 +5424,7 @@ pub fn sock_send( si_data_len: M::Offset, _si_flags: __wasi_siflags_t, ret_data_len: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { debug!("wasi::sock_send"); let env = ctx.data(); @@ -5389,11 +5438,12 @@ pub fn sock_send( |socket| { socket.send(&memory, iovs_arr) } )); - let bytes_written: M::Offset = - wasi_try_ok!(bytes_written.try_into().map_err(|_| __WASI_EOVERFLOW)); + let bytes_written: M::Offset = wasi_try_ok!(bytes_written + .try_into() + .map_err(|_| wasi_snapshot0::Errno::Overflow)); wasi_try_mem_ok!(ret_data_len.write(&memory, bytes_written)); - Ok(__WASI_ESUCCESS) + Ok(wasi_snapshot0::Errno::Success) } /// ### `sock_send_to()` @@ -5418,7 +5468,7 @@ pub fn sock_send_to( _si_flags: __wasi_siflags_t, 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(); @@ -5432,11 +5482,12 @@ pub fn 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)); + let bytes_written: M::Offset = wasi_try_ok!(bytes_written + .try_into() + .map_err(|_| wasi_snapshot0::Errno::Overflow)); wasi_try_mem_ok!(ret_data_len.write(&memory, bytes_written as M::Offset)); - Ok(__WASI_ESUCCESS) + Ok(wasi_snapshot0::Errno::Success) } /// ### `sock_send_file()` @@ -5458,7 +5509,7 @@ pub unsafe fn sock_send_file( offset: __wasi_filesize_t, mut count: __wasi_filesize_t, ret_sent: WasmPtr<__wasi_filesize_t, M>, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { debug!("wasi::send_file"); let env = ctx.data(); let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0); @@ -5466,7 +5517,7 @@ 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(wasi_snapshot0::Errno::Badf)); fd_entry.offset = offset as u64; } @@ -5489,14 +5540,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(wasi_snapshot0::Errno::Badf); } } - __WASI_STDOUT_FILENO | __WASI_STDERR_FILENO => return Ok(__WASI_EINVAL), + __WASI_STDOUT_FILENO | __WASI_STDERR_FILENO => return Ok(wasi_snapshot0::Errno::Inval), _ => { if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_READ) { // TODO: figure out the error to return when lacking rights - return Ok(__WASI_EACCES); + return Ok(wasi_snapshot0::Errno::Acces); } let offset = fd_entry.offset as usize; @@ -5517,7 +5568,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(wasi_snapshot0::Errno::Inval); } } Kind::Socket { socket } => { @@ -5527,10 +5578,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(wasi_snapshot0::Errno::Isdir); } Kind::EventNotifications { .. } => { - return Ok(__WASI_EINVAL); + return Ok(wasi_snapshot0::Errno::Inval); } Kind::Symlink { .. } => unimplemented!("Symlinks in wasi::fd_read"), Kind::Buffer { buffer } => { @@ -5542,7 +5593,8 @@ 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(wasi_snapshot0::Errno::Badf)); fd_entry.offset += bytes_read as u64; bytes_read @@ -5564,7 +5616,7 @@ pub unsafe fn sock_send_file( wasi_try_mem_ok!(ret_sent.write(&memory, total_written as __wasi_filesize_t)); - Ok(__WASI_ESUCCESS) + Ok(wasi_snapshot0::Errno::Success) } /// ### `resolve()` @@ -5593,10 +5645,10 @@ pub fn resolve( addrs: WasmPtr<__wasi_addr_t, M>, naddrs: M::Offset, ret_naddrs: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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(|_| wasi_snapshot0::Errno::Inval)); let env = ctx.data(); let memory = env.memory_view(&ctx); let host_str = unsafe { get_input_str!(&memory, host, host_len) }; @@ -5615,8 +5667,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(|_| wasi_snapshot0::Errno::Overflow)); wasi_try_mem!(ret_naddrs.write(&memory, idx)); - __WASI_ESUCCESS + wasi_snapshot0::Errno::Success } diff --git a/lib/wasi/src/syscalls/unix/mod.rs b/lib/wasi/src/syscalls/unix/mod.rs index 9e3a5e35d16..a8ad2083acc 100644 --- a/lib/wasi/src/syscalls/unix/mod.rs +++ b/lib/wasi/src/syscalls/unix/mod.rs @@ -1,3 +1,4 @@ +use crate::syscalls::types::wasi_snapshot0; use crate::syscalls::types::*; use libc::{ clock_getres, clock_gettime, timespec, CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID, @@ -9,13 +10,13 @@ use wasmer::WasmRef; pub fn platform_clock_res_get( clock_id: __wasi_clockid_t, resolution: WasmRef<__wasi_timestamp_t>, -) -> Result { +) -> 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), + _ => return Err(wasi_snapshot0::Errno::Inval), }; let (output, timespec_out) = unsafe { @@ -33,13 +34,13 @@ pub fn platform_clock_res_get( pub fn platform_clock_time_get( clock_id: __wasi_clockid_t, precision: __wasi_timestamp_t, -) -> Result { +) -> 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), + _ => return Err(wasi_snapshot0::Errno::Inval), }; let (output, timespec_out) = unsafe { diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index 5cb6899c3ef..4cb232ed951 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -2,6 +2,7 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{FunctionEnvMut, Memory, Memory32, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; +use wasmer_wasi_types_generated::wasi_snapshot0; type MemoryType = Memory32; type MemoryOffset = u32; @@ -10,7 +11,7 @@ pub(crate) fn args_get( ctx: FunctionEnvMut, argv: WasmPtr, MemoryType>, argv_buf: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::args_get::(ctx, argv, argv_buf) } @@ -18,7 +19,7 @@ pub(crate) fn args_sizes_get( ctx: FunctionEnvMut, argc: WasmPtr, argv_buf_size: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::args_sizes_get::(ctx, argc, argv_buf_size) } @@ -26,7 +27,7 @@ pub(crate) fn clock_res_get( ctx: FunctionEnvMut, clock_id: __wasi_clockid_t, resolution: WasmPtr<__wasi_timestamp_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::clock_res_get::(ctx, clock_id, resolution) } @@ -35,7 +36,7 @@ pub(crate) fn clock_time_get( clock_id: __wasi_clockid_t, precision: __wasi_timestamp_t, time: WasmPtr<__wasi_timestamp_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::clock_time_get::(ctx, clock_id, precision, time) } @@ -43,7 +44,7 @@ pub(crate) fn environ_get( ctx: FunctionEnvMut, environ: WasmPtr, MemoryType>, environ_buf: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::environ_get::(ctx, environ, environ_buf) } @@ -51,7 +52,7 @@ pub(crate) fn environ_sizes_get( ctx: FunctionEnvMut, environ_count: WasmPtr, environ_buf_size: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::environ_sizes_get::(ctx, environ_count, environ_buf_size) } @@ -61,7 +62,7 @@ pub(crate) fn fd_advise( offset: __wasi_filesize_t, len: __wasi_filesize_t, advice: __wasi_advice_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_advise(ctx, fd, offset, len, advice) } @@ -70,15 +71,15 @@ pub(crate) fn fd_allocate( fd: __wasi_fd_t, offset: __wasi_filesize_t, len: __wasi_filesize_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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: __wasi_fd_t) -> wasi_snapshot0::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: __wasi_fd_t) -> wasi_snapshot0::Errno { super::fd_datasync(ctx, fd) } @@ -86,7 +87,7 @@ pub(crate) fn fd_fdstat_get( ctx: FunctionEnvMut, fd: __wasi_fd_t, buf_ptr: WasmPtr<__wasi_fdstat_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_fdstat_get::(ctx, fd, buf_ptr) } @@ -94,7 +95,7 @@ pub(crate) fn fd_fdstat_set_flags( ctx: FunctionEnvMut, fd: __wasi_fd_t, flags: __wasi_fdflags_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_fdstat_set_flags(ctx, fd, flags) } @@ -103,7 +104,7 @@ pub(crate) fn fd_fdstat_set_rights( fd: __wasi_fd_t, fs_rights_base: __wasi_rights_t, fs_rights_inheriting: __wasi_rights_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_fdstat_set_rights(ctx, fd, fs_rights_base, fs_rights_inheriting) } @@ -111,7 +112,7 @@ pub(crate) fn fd_filestat_get( ctx: FunctionEnvMut, fd: __wasi_fd_t, buf: WasmPtr<__wasi_filestat_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_filestat_get::(ctx, fd, buf) } @@ -119,7 +120,7 @@ pub(crate) fn fd_filestat_set_size( ctx: FunctionEnvMut, fd: __wasi_fd_t, st_size: __wasi_filesize_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_filestat_set_size(ctx, fd, st_size) } @@ -129,7 +130,7 @@ pub(crate) fn fd_filestat_set_times( st_atim: __wasi_timestamp_t, st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_filestat_set_times(ctx, fd, st_atim, st_mtim, fst_flags) } @@ -140,7 +141,7 @@ pub(crate) fn fd_pread( iovs_len: MemoryOffset, offset: __wasi_filesize_t, nread: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::fd_pread::(ctx, fd, iovs, iovs_len, offset, nread) } @@ -148,7 +149,7 @@ pub(crate) fn fd_prestat_get( ctx: FunctionEnvMut, fd: __wasi_fd_t, buf: WasmPtr<__wasi_prestat_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_prestat_get::(ctx, fd, buf) } @@ -157,7 +158,7 @@ pub(crate) fn fd_prestat_dir_name( fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_prestat_dir_name::(ctx, fd, path, path_len) } @@ -168,7 +169,7 @@ pub(crate) fn fd_pwrite( iovs_len: MemoryOffset, offset: __wasi_filesize_t, nwritten: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::fd_pwrite::(ctx, fd, iovs, iovs_len, offset, nwritten) } @@ -178,7 +179,7 @@ pub(crate) fn fd_read( 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) } @@ -189,7 +190,7 @@ pub(crate) fn fd_readdir( buf_len: MemoryOffset, cookie: __wasi_dircookie_t, bufused: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_readdir::(ctx, fd, buf, buf_len, cookie, bufused) } @@ -197,7 +198,7 @@ pub(crate) fn fd_renumber( ctx: FunctionEnvMut, from: __wasi_fd_t, to: __wasi_fd_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_renumber(ctx, from, to) } @@ -207,11 +208,11 @@ pub(crate) fn fd_seek( offset: __wasi_filedelta_t, whence: __wasi_whence_t, newoffset: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> Result<__wasi_errno_t, WasiError> { +) -> 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: __wasi_fd_t) -> wasi_snapshot0::Errno { super::fd_sync(ctx, fd) } @@ -219,7 +220,7 @@ pub(crate) fn fd_tell( ctx: FunctionEnvMut, fd: __wasi_fd_t, offset: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_tell::(ctx, fd, offset) } @@ -229,7 +230,7 @@ pub(crate) fn fd_write( 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) } @@ -238,7 +239,7 @@ pub(crate) fn path_create_directory( fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_create_directory::(ctx, fd, path, path_len) } @@ -249,7 +250,7 @@ pub(crate) fn path_filestat_get( path: WasmPtr, path_len: MemoryOffset, buf: WasmPtr<__wasi_filestat_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_filestat_get::(ctx, fd, flags, path, path_len, buf) } @@ -262,7 +263,7 @@ pub(crate) fn path_filestat_set_times( st_atim: __wasi_timestamp_t, st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_filestat_set_times::( ctx, fd, flags, path, path_len, st_atim, st_mtim, fst_flags, ) @@ -277,7 +278,7 @@ pub(crate) fn path_link( new_fd: __wasi_fd_t, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_link::( ctx, old_fd, @@ -301,7 +302,7 @@ pub(crate) fn path_open( fs_rights_inheriting: __wasi_rights_t, fs_flags: __wasi_fdflags_t, fd: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_open::( ctx, dirfd, @@ -324,7 +325,7 @@ pub(crate) fn path_readlink( buf: WasmPtr, buf_len: MemoryOffset, buf_used: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_readlink::(ctx, dir_fd, path, path_len, buf, buf_len, buf_used) } @@ -333,7 +334,7 @@ pub(crate) fn path_remove_directory( fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_remove_directory::(ctx, fd, path, path_len) } @@ -345,7 +346,7 @@ pub(crate) fn path_rename( new_fd: __wasi_fd_t, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_rename::( ctx, old_fd, @@ -364,7 +365,7 @@ pub(crate) fn path_symlink( fd: __wasi_fd_t, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_symlink::(ctx, old_path, old_path_len, fd, new_path, new_path_len) } @@ -373,7 +374,7 @@ pub(crate) fn path_unlink_file( fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_unlink_file::(ctx, fd, path, path_len) } @@ -383,7 +384,7 @@ pub(crate) fn poll_oneoff( out_: WasmPtr<__wasi_event_t, MemoryType>, nsubscriptions: MemoryOffset, nevents: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::poll_oneoff::(ctx, in_, out_, nsubscriptions, nevents) } @@ -394,7 +395,10 @@ 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: __wasi_signal_t, +) -> wasi_snapshot0::Errno { super::proc_raise(ctx, sig) } @@ -402,7 +406,7 @@ pub(crate) fn random_get( ctx: FunctionEnvMut, buf: WasmPtr, buf_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::random_get::(ctx, buf, buf_len) } @@ -410,7 +414,7 @@ pub(crate) fn fd_dup( ctx: FunctionEnvMut, fd: __wasi_fd_t, ret_fd: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_dup::(ctx, fd, ret_fd) } @@ -419,7 +423,7 @@ pub(crate) fn fd_event( initial_val: u64, flags: __wasi_eventfdflags, ret_fd: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_event(ctx, initial_val, flags, ret_fd) } @@ -427,21 +431,21 @@ pub(crate) fn fd_pipe( ctx: FunctionEnvMut, ro_fd1: WasmPtr<__wasi_fd_t, MemoryType>, ro_fd2: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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 { +) -> wasi_snapshot0::Errno { super::tty_get::(ctx, tty_state) } pub(crate) fn tty_set( ctx: FunctionEnvMut, tty_state: WasmPtr<__wasi_tty_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::tty_set::(ctx, tty_state) } @@ -449,7 +453,7 @@ pub(crate) fn getcwd( ctx: FunctionEnvMut, path: WasmPtr, path_len: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::getcwd::(ctx, path, path_len) } @@ -457,7 +461,7 @@ pub(crate) fn chdir( ctx: FunctionEnvMut, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::chdir::(ctx, path, path_len) } @@ -468,53 +472,55 @@ pub(crate) fn thread_spawn( user_data: u64, reactor: __wasi_bool_t, ret_tid: WasmPtr<__wasi_tid_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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> { +) -> Result { super::thread_sleep(ctx, duration) } pub(crate) fn thread_id( ctx: FunctionEnvMut, ret_tid: WasmPtr<__wasi_tid_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::thread_id::(ctx, ret_tid) } pub(crate) fn thread_join( ctx: FunctionEnvMut, tid: __wasi_tid_t, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::thread_join(ctx, tid) } pub(crate) fn thread_parallelism( ctx: FunctionEnvMut, ret_parallelism: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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 { +) -> wasi_snapshot0::Errno { super::getpid::(ctx, ret_pid) } @@ -671,33 +677,33 @@ pub(crate) fn port_bridge( token: WasmPtr, token_len: MemoryOffset, security: __wasi_streamsecurity_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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) -> wasi_snapshot0::Errno { super::port_unbridge(ctx) } -pub(crate) fn port_dhcp_acquire(ctx: FunctionEnvMut) -> __wasi_errno_t { +pub(crate) fn port_dhcp_acquire(ctx: FunctionEnvMut) -> wasi_snapshot0::Errno { super::port_dhcp_acquire(ctx) } pub(crate) fn port_addr_add( ctx: FunctionEnvMut, addr: WasmPtr<__wasi_cidr_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::port_addr_add::(ctx, addr) } pub(crate) fn port_addr_remove( ctx: FunctionEnvMut, addr: WasmPtr<__wasi_addr_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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) -> wasi_snapshot0::Errno { super::port_addr_clear(ctx) } @@ -705,21 +711,21 @@ pub(crate) fn port_addr_list( ctx: FunctionEnvMut, addrs: WasmPtr<__wasi_cidr_t, MemoryType>, naddrs: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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 { +) -> wasi_snapshot0::Errno { super::port_mac::(ctx, ret_mac) } pub(crate) fn port_gateway_set( ctx: FunctionEnvMut, ip: WasmPtr<__wasi_addr_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::port_gateway_set::(ctx, ip) } @@ -729,18 +735,18 @@ pub(crate) fn port_route_add( 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 { +) -> wasi_snapshot0::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 { +) -> wasi_snapshot0::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) -> wasi_snapshot0::Errno { super::port_route_clear(ctx) } @@ -748,7 +754,7 @@ pub(crate) fn port_route_list( ctx: FunctionEnvMut, routes: WasmPtr<__wasi_route_t, MemoryType>, nroutes: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::port_route_list::(ctx, routes, nroutes) } @@ -757,7 +763,7 @@ pub(crate) fn ws_connect( url: WasmPtr, url_len: MemoryOffset, ret_sock: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::ws_connect::(ctx, url, url_len, ret_sock) } @@ -771,7 +777,7 @@ pub(crate) fn http_request( headers_len: MemoryOffset, gzip: __wasi_bool_t, ret_handles: WasmPtr<__wasi_http_handles_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::http_request::( ctx, url, @@ -793,7 +799,7 @@ pub(crate) fn http_status( status_text_len: WasmPtr, headers: WasmPtr, headers_len: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::http_status::(ctx, sock, status) } @@ -801,7 +807,7 @@ pub(crate) fn sock_status( ctx: FunctionEnvMut, sock: __wasi_fd_t, ret_status: WasmPtr<__wasi_sockstatus_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_status::(ctx, sock, ret_status) } @@ -809,7 +815,7 @@ pub(crate) fn sock_addr_local( ctx: FunctionEnvMut, sock: __wasi_fd_t, ret_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_addr_local::(ctx, sock, ret_addr) } @@ -817,7 +823,7 @@ pub(crate) fn sock_addr_peer( ctx: FunctionEnvMut, sock: __wasi_fd_t, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_addr_peer::(ctx, sock, ro_addr) } @@ -827,7 +833,7 @@ pub(crate) fn sock_open( ty: __wasi_socktype_t, pt: __wasi_sockproto_t, ro_sock: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_open::(ctx, af, ty, pt, ro_sock) } @@ -836,7 +842,7 @@ pub(crate) fn sock_set_opt_flag( sock: __wasi_fd_t, opt: __wasi_sockoption_t, flag: __wasi_bool_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_set_opt_flag(ctx, sock, opt, flag) } @@ -845,7 +851,7 @@ pub(crate) fn sock_get_opt_flag( sock: __wasi_fd_t, opt: __wasi_sockoption_t, ret_flag: WasmPtr<__wasi_bool_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_get_opt_flag::(ctx, sock, opt, ret_flag) } @@ -854,7 +860,7 @@ pub fn sock_set_opt_time( sock: __wasi_fd_t, opt: __wasi_sockoption_t, time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_set_opt_time(ctx, sock, opt, time) } @@ -863,7 +869,7 @@ pub fn sock_get_opt_time( sock: __wasi_fd_t, opt: __wasi_sockoption_t, ret_time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_get_opt_time(ctx, sock, opt, ret_time) } @@ -872,7 +878,7 @@ pub fn sock_set_opt_size( sock: __wasi_fd_t, opt: __wasi_sockoption_t, size: __wasi_filesize_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_set_opt_size(ctx, sock, opt, size) } @@ -881,7 +887,7 @@ pub fn sock_get_opt_size( sock: __wasi_fd_t, opt: __wasi_sockoption_t, ret_size: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_get_opt_size(ctx, sock, opt, ret_size) } @@ -890,7 +896,7 @@ pub(crate) fn sock_join_multicast_v4( sock: __wasi_fd_t, multiaddr: WasmPtr<__wasi_addr_ip4_t, MemoryType>, iface: WasmPtr<__wasi_addr_ip4_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_join_multicast_v4::(ctx, sock, multiaddr, iface) } @@ -899,7 +905,7 @@ pub(crate) fn sock_leave_multicast_v4( sock: __wasi_fd_t, multiaddr: WasmPtr<__wasi_addr_ip4_t, MemoryType>, iface: WasmPtr<__wasi_addr_ip4_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_leave_multicast_v4::(ctx, sock, multiaddr, iface) } @@ -908,7 +914,7 @@ pub(crate) fn sock_join_multicast_v6( sock: __wasi_fd_t, multiaddr: WasmPtr<__wasi_addr_ip6_t, MemoryType>, iface: u32, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_join_multicast_v6::(ctx, sock, multiaddr, iface) } @@ -917,7 +923,7 @@ pub(crate) fn sock_leave_multicast_v6( sock: __wasi_fd_t, multiaddr: WasmPtr<__wasi_addr_ip6_t, MemoryType>, iface: u32, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_leave_multicast_v6::(ctx, sock, multiaddr, iface) } @@ -925,7 +931,7 @@ pub(crate) fn sock_bind( ctx: FunctionEnvMut, sock: __wasi_fd_t, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_bind::(ctx, sock, addr) } @@ -933,7 +939,7 @@ pub(crate) fn sock_listen( ctx: FunctionEnvMut, sock: __wasi_fd_t, backlog: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_listen::(ctx, sock, backlog) } @@ -943,7 +949,7 @@ pub(crate) fn sock_accept( fd_flags: __wasi_fdflags_t, ro_fd: WasmPtr<__wasi_fd_t, MemoryType>, 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) } @@ -951,7 +957,7 @@ pub(crate) fn sock_connect( ctx: FunctionEnvMut, sock: __wasi_fd_t, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_connect::(ctx, sock, addr) } @@ -963,7 +969,7 @@ pub(crate) fn sock_recv( ri_flags: __wasi_riflags_t, ro_data_len: WasmPtr, ro_flags: WasmPtr<__wasi_roflags_t, MemoryType>, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::sock_recv::( ctx, sock, @@ -984,7 +990,7 @@ pub(crate) fn sock_recv_from( ro_data_len: WasmPtr, ro_flags: WasmPtr<__wasi_roflags_t, MemoryType>, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::sock_recv_from::( ctx, sock, @@ -1004,7 +1010,7 @@ pub(crate) fn sock_send( si_data_len: MemoryOffset, si_flags: __wasi_siflags_t, 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) } @@ -1016,7 +1022,7 @@ pub(crate) fn sock_send_to( si_flags: __wasi_siflags_t, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ret_data_len: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::sock_send_to::( ctx, sock, @@ -1035,7 +1041,7 @@ pub(crate) fn sock_send_file( offset: __wasi_filesize_t, count: __wasi_filesize_t, ret_sent: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { unsafe { super::sock_send_file::(ctx, out_fd, in_fd, offset, count, ret_sent) } } @@ -1043,7 +1049,7 @@ pub(crate) fn sock_shutdown( ctx: FunctionEnvMut, sock: __wasi_fd_t, how: __wasi_sdflags_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_shutdown(ctx, sock, how) } @@ -1055,6 +1061,6 @@ pub(crate) fn resolve( ips: WasmPtr<__wasi_addr_t, MemoryType>, nips: MemoryOffset, ret_nips: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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..60261970ac7 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -2,6 +2,7 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{FunctionEnvMut, Memory, Memory64, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; +use wasmer_wasi_types_generated::wasi_snapshot0; type MemoryType = Memory64; type MemoryOffset = u64; @@ -10,7 +11,7 @@ pub(crate) fn args_get( ctx: FunctionEnvMut, argv: WasmPtr, MemoryType>, argv_buf: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::args_get::(ctx, argv, argv_buf) } @@ -18,7 +19,7 @@ pub(crate) fn args_sizes_get( ctx: FunctionEnvMut, argc: WasmPtr, argv_buf_size: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::args_sizes_get::(ctx, argc, argv_buf_size) } @@ -26,7 +27,7 @@ pub(crate) fn clock_res_get( ctx: FunctionEnvMut, clock_id: __wasi_clockid_t, resolution: WasmPtr<__wasi_timestamp_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::clock_res_get::(ctx, clock_id, resolution) } @@ -35,7 +36,7 @@ pub(crate) fn clock_time_get( clock_id: __wasi_clockid_t, precision: __wasi_timestamp_t, time: WasmPtr<__wasi_timestamp_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::clock_time_get::(ctx, clock_id, precision, time) } @@ -43,7 +44,7 @@ pub(crate) fn environ_get( ctx: FunctionEnvMut, environ: WasmPtr, MemoryType>, environ_buf: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::environ_get::(ctx, environ, environ_buf) } @@ -51,7 +52,7 @@ pub(crate) fn environ_sizes_get( ctx: FunctionEnvMut, environ_count: WasmPtr, environ_buf_size: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::environ_sizes_get::(ctx, environ_count, environ_buf_size) } @@ -61,7 +62,7 @@ pub(crate) fn fd_advise( offset: __wasi_filesize_t, len: __wasi_filesize_t, advice: __wasi_advice_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_advise(ctx, fd, offset, len, advice) } @@ -70,15 +71,15 @@ pub(crate) fn fd_allocate( fd: __wasi_fd_t, offset: __wasi_filesize_t, len: __wasi_filesize_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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: __wasi_fd_t) -> wasi_snapshot0::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: __wasi_fd_t) -> wasi_snapshot0::Errno { super::fd_datasync(ctx, fd) } @@ -86,7 +87,7 @@ pub(crate) fn fd_fdstat_get( ctx: FunctionEnvMut, fd: __wasi_fd_t, buf_ptr: WasmPtr<__wasi_fdstat_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_fdstat_get::(ctx, fd, buf_ptr) } @@ -94,7 +95,7 @@ pub(crate) fn fd_fdstat_set_flags( ctx: FunctionEnvMut, fd: __wasi_fd_t, flags: __wasi_fdflags_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_fdstat_set_flags(ctx, fd, flags) } @@ -103,7 +104,7 @@ pub(crate) fn fd_fdstat_set_rights( fd: __wasi_fd_t, fs_rights_base: __wasi_rights_t, fs_rights_inheriting: __wasi_rights_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_fdstat_set_rights(ctx, fd, fs_rights_base, fs_rights_inheriting) } @@ -111,7 +112,7 @@ pub(crate) fn fd_filestat_get( ctx: FunctionEnvMut, fd: __wasi_fd_t, buf: WasmPtr<__wasi_filestat_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_filestat_get::(ctx, fd, buf) } @@ -119,7 +120,7 @@ pub(crate) fn fd_filestat_set_size( ctx: FunctionEnvMut, fd: __wasi_fd_t, st_size: __wasi_filesize_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_filestat_set_size(ctx, fd, st_size) } @@ -129,7 +130,7 @@ pub(crate) fn fd_filestat_set_times( st_atim: __wasi_timestamp_t, st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_filestat_set_times(ctx, fd, st_atim, st_mtim, fst_flags) } @@ -140,7 +141,7 @@ pub(crate) fn fd_pread( iovs_len: MemoryOffset, offset: __wasi_filesize_t, nread: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::fd_pread::(ctx, fd, iovs, iovs_len, offset, nread) } @@ -148,7 +149,7 @@ pub(crate) fn fd_prestat_get( ctx: FunctionEnvMut, fd: __wasi_fd_t, buf: WasmPtr<__wasi_prestat_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_prestat_get::(ctx, fd, buf) } @@ -157,7 +158,7 @@ pub(crate) fn fd_prestat_dir_name( fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_prestat_dir_name::(ctx, fd, path, path_len) } @@ -168,7 +169,7 @@ pub(crate) fn fd_pwrite( iovs_len: MemoryOffset, offset: __wasi_filesize_t, nwritten: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::fd_pwrite::(ctx, fd, iovs, iovs_len, offset, nwritten) } @@ -178,7 +179,7 @@ pub(crate) fn fd_read( 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) } @@ -189,7 +190,7 @@ pub(crate) fn fd_readdir( buf_len: MemoryOffset, cookie: __wasi_dircookie_t, bufused: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_readdir::(ctx, fd, buf, buf_len, cookie, bufused) } @@ -197,7 +198,7 @@ pub(crate) fn fd_renumber( ctx: FunctionEnvMut, from: __wasi_fd_t, to: __wasi_fd_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_renumber(ctx, from, to) } @@ -207,11 +208,11 @@ pub(crate) fn fd_seek( offset: __wasi_filedelta_t, whence: __wasi_whence_t, newoffset: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> Result<__wasi_errno_t, WasiError> { +) -> 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: __wasi_fd_t) -> wasi_snapshot0::Errno { super::fd_sync(ctx, fd) } @@ -219,7 +220,7 @@ pub(crate) fn fd_tell( ctx: FunctionEnvMut, fd: __wasi_fd_t, offset: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_tell::(ctx, fd, offset) } @@ -229,7 +230,7 @@ pub(crate) fn fd_write( 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) } @@ -238,7 +239,7 @@ pub(crate) fn path_create_directory( fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_create_directory::(ctx, fd, path, path_len) } @@ -249,7 +250,7 @@ pub(crate) fn path_filestat_get( path: WasmPtr, path_len: MemoryOffset, buf: WasmPtr<__wasi_filestat_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_filestat_get::(ctx, fd, flags, path, path_len, buf) } @@ -262,7 +263,7 @@ pub(crate) fn path_filestat_set_times( st_atim: __wasi_timestamp_t, st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_filestat_set_times::( ctx, fd, flags, path, path_len, st_atim, st_mtim, fst_flags, ) @@ -277,7 +278,7 @@ pub(crate) fn path_link( new_fd: __wasi_fd_t, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_link::( ctx, old_fd, @@ -301,7 +302,7 @@ pub(crate) fn path_open( fs_rights_inheriting: __wasi_rights_t, fs_flags: __wasi_fdflags_t, fd: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_open::( ctx, dirfd, @@ -324,7 +325,7 @@ pub(crate) fn path_readlink( buf: WasmPtr, buf_len: MemoryOffset, buf_used: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_readlink::(ctx, dir_fd, path, path_len, buf, buf_len, buf_used) } @@ -333,7 +334,7 @@ pub(crate) fn path_remove_directory( fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_remove_directory::(ctx, fd, path, path_len) } @@ -345,7 +346,7 @@ pub(crate) fn path_rename( new_fd: __wasi_fd_t, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_rename::( ctx, old_fd, @@ -364,7 +365,7 @@ pub(crate) fn path_symlink( fd: __wasi_fd_t, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_symlink::(ctx, old_path, old_path_len, fd, new_path, new_path_len) } @@ -373,7 +374,7 @@ pub(crate) fn path_unlink_file( fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_unlink_file::(ctx, fd, path, path_len) } @@ -383,7 +384,7 @@ pub(crate) fn poll_oneoff( out_: WasmPtr<__wasi_event_t, MemoryType>, nsubscriptions: MemoryOffset, nevents: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::poll_oneoff::(ctx, in_, out_, nsubscriptions, nevents) } @@ -394,7 +395,10 @@ 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: __wasi_signal_t, +) -> wasi_snapshot0::Errno { super::proc_raise(ctx, sig) } @@ -402,7 +406,7 @@ pub(crate) fn random_get( ctx: FunctionEnvMut, buf: WasmPtr, buf_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::random_get::(ctx, buf, buf_len) } @@ -410,7 +414,7 @@ pub(crate) fn fd_dup( ctx: FunctionEnvMut, fd: __wasi_fd_t, ret_fd: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_dup::(ctx, fd, ret_fd) } @@ -419,7 +423,7 @@ pub(crate) fn fd_event( initial_val: u64, flags: __wasi_eventfdflags, ret_fd: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_event(ctx, initial_val, flags, ret_fd) } @@ -427,21 +431,21 @@ pub(crate) fn fd_pipe( ctx: FunctionEnvMut, ro_fd1: WasmPtr<__wasi_fd_t, MemoryType>, ro_fd2: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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 { +) -> wasi_snapshot0::Errno { super::tty_get::(ctx, tty_state) } pub(crate) fn tty_set( ctx: FunctionEnvMut, tty_state: WasmPtr<__wasi_tty_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::tty_set::(ctx, tty_state) } @@ -449,7 +453,7 @@ pub(crate) fn getcwd( ctx: FunctionEnvMut, path: WasmPtr, path_len: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::getcwd::(ctx, path, path_len) } @@ -457,7 +461,7 @@ pub(crate) fn chdir( ctx: FunctionEnvMut, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::chdir::(ctx, path, path_len) } @@ -468,53 +472,55 @@ pub(crate) fn thread_spawn( user_data: u64, reactor: __wasi_bool_t, ret_tid: WasmPtr<__wasi_tid_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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> { +) -> Result { super::thread_sleep(ctx, duration) } pub(crate) fn thread_id( ctx: FunctionEnvMut, ret_tid: WasmPtr<__wasi_tid_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::thread_id::(ctx, ret_tid) } pub(crate) fn thread_join( ctx: FunctionEnvMut, tid: __wasi_tid_t, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::thread_join(ctx, tid) } pub(crate) fn thread_parallelism( ctx: FunctionEnvMut, ret_parallelism: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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 { +) -> wasi_snapshot0::Errno { super::getpid::(ctx, ret_pid) } @@ -671,33 +677,33 @@ pub(crate) fn port_bridge( token: WasmPtr, token_len: MemoryOffset, security: __wasi_streamsecurity_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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) -> wasi_snapshot0::Errno { super::port_unbridge(ctx) } -pub(crate) fn port_dhcp_acquire(ctx: FunctionEnvMut) -> __wasi_errno_t { +pub(crate) fn port_dhcp_acquire(ctx: FunctionEnvMut) -> wasi_snapshot0::Errno { super::port_dhcp_acquire(ctx) } pub(crate) fn port_addr_add( ctx: FunctionEnvMut, addr: WasmPtr<__wasi_cidr_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::port_addr_add::(ctx, addr) } pub(crate) fn port_addr_remove( ctx: FunctionEnvMut, addr: WasmPtr<__wasi_addr_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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) -> wasi_snapshot0::Errno { super::port_addr_clear(ctx) } @@ -705,21 +711,21 @@ pub(crate) fn port_addr_list( ctx: FunctionEnvMut, addrs: WasmPtr<__wasi_cidr_t, MemoryType>, naddrs: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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 { +) -> wasi_snapshot0::Errno { super::port_mac::(ctx, ret_mac) } pub(crate) fn port_gateway_set( ctx: FunctionEnvMut, ip: WasmPtr<__wasi_addr_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::port_gateway_set::(ctx, ip) } @@ -729,18 +735,18 @@ pub(crate) fn port_route_add( 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 { +) -> wasi_snapshot0::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 { +) -> wasi_snapshot0::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) -> wasi_snapshot0::Errno { super::port_route_clear(ctx) } @@ -748,7 +754,7 @@ pub(crate) fn port_route_list( ctx: FunctionEnvMut, routes: WasmPtr<__wasi_route_t, MemoryType>, nroutes: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::port_route_list::(ctx, routes, nroutes) } @@ -757,7 +763,7 @@ pub(crate) fn ws_connect( url: WasmPtr, url_len: MemoryOffset, ret_sock: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::ws_connect::(ctx, url, url_len, ret_sock) } @@ -771,7 +777,7 @@ pub(crate) fn http_request( headers_len: MemoryOffset, gzip: __wasi_bool_t, ret_handles: WasmPtr<__wasi_http_handles_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::http_request::( ctx, url, @@ -793,7 +799,7 @@ pub(crate) fn http_status( status_text_len: WasmPtr, headers: WasmPtr, headers_len: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::http_status::(ctx, sock, status) } @@ -801,7 +807,7 @@ pub(crate) fn sock_status( ctx: FunctionEnvMut, sock: __wasi_fd_t, ret_status: WasmPtr<__wasi_sockstatus_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_status::(ctx, sock, ret_status) } @@ -809,7 +815,7 @@ pub(crate) fn sock_addr_local( ctx: FunctionEnvMut, sock: __wasi_fd_t, ret_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_addr_local::(ctx, sock, ret_addr) } @@ -817,7 +823,7 @@ pub(crate) fn sock_addr_peer( ctx: FunctionEnvMut, sock: __wasi_fd_t, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_addr_peer::(ctx, sock, ro_addr) } @@ -827,7 +833,7 @@ pub(crate) fn sock_open( ty: __wasi_socktype_t, pt: __wasi_sockproto_t, ro_sock: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_open::(ctx, af, ty, pt, ro_sock) } @@ -836,7 +842,7 @@ pub(crate) fn sock_set_opt_flag( sock: __wasi_fd_t, opt: __wasi_sockoption_t, flag: __wasi_bool_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_set_opt_flag(ctx, sock, opt, flag) } @@ -845,7 +851,7 @@ pub(crate) fn sock_get_opt_flag( sock: __wasi_fd_t, opt: __wasi_sockoption_t, ret_flag: WasmPtr<__wasi_bool_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_get_opt_flag::(ctx, sock, opt, ret_flag) } @@ -854,7 +860,7 @@ pub fn sock_set_opt_time( sock: __wasi_fd_t, opt: __wasi_sockoption_t, time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_set_opt_time(ctx, sock, opt, time) } @@ -863,7 +869,7 @@ pub fn sock_get_opt_time( sock: __wasi_fd_t, opt: __wasi_sockoption_t, ret_time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_get_opt_time(ctx, sock, opt, ret_time) } @@ -872,7 +878,7 @@ pub fn sock_set_opt_size( sock: __wasi_fd_t, opt: __wasi_sockoption_t, size: __wasi_filesize_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_set_opt_size(ctx, sock, opt, size) } @@ -881,7 +887,7 @@ pub fn sock_get_opt_size( sock: __wasi_fd_t, opt: __wasi_sockoption_t, ret_size: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_get_opt_size(ctx, sock, opt, ret_size) } @@ -890,7 +896,7 @@ pub(crate) fn sock_join_multicast_v4( sock: __wasi_fd_t, multiaddr: WasmPtr<__wasi_addr_ip4_t, MemoryType>, iface: WasmPtr<__wasi_addr_ip4_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_join_multicast_v4::(ctx, sock, multiaddr, iface) } @@ -899,7 +905,7 @@ pub(crate) fn sock_leave_multicast_v4( sock: __wasi_fd_t, multiaddr: WasmPtr<__wasi_addr_ip4_t, MemoryType>, iface: WasmPtr<__wasi_addr_ip4_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_leave_multicast_v4::(ctx, sock, multiaddr, iface) } @@ -908,7 +914,7 @@ pub(crate) fn sock_join_multicast_v6( sock: __wasi_fd_t, multiaddr: WasmPtr<__wasi_addr_ip6_t, MemoryType>, iface: u32, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_join_multicast_v6::(ctx, sock, multiaddr, iface) } @@ -917,7 +923,7 @@ pub(crate) fn sock_leave_multicast_v6( sock: __wasi_fd_t, multiaddr: WasmPtr<__wasi_addr_ip6_t, MemoryType>, iface: u32, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_leave_multicast_v6::(ctx, sock, multiaddr, iface) } @@ -925,7 +931,7 @@ pub(crate) fn sock_bind( ctx: FunctionEnvMut, sock: __wasi_fd_t, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_bind::(ctx, sock, addr) } @@ -933,7 +939,7 @@ pub(crate) fn sock_listen( ctx: FunctionEnvMut, sock: __wasi_fd_t, backlog: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_listen::(ctx, sock, backlog) } @@ -943,7 +949,7 @@ pub(crate) fn sock_accept( fd_flags: __wasi_fdflags_t, ro_fd: WasmPtr<__wasi_fd_t, MemoryType>, 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) } @@ -951,7 +957,7 @@ pub(crate) fn sock_connect( ctx: FunctionEnvMut, sock: __wasi_fd_t, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_connect::(ctx, sock, addr) } @@ -963,7 +969,7 @@ pub(crate) fn sock_recv( ri_flags: __wasi_riflags_t, ro_data_len: WasmPtr, ro_flags: WasmPtr<__wasi_roflags_t, MemoryType>, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::sock_recv::( ctx, sock, @@ -984,7 +990,7 @@ pub(crate) fn sock_recv_from( ro_data_len: WasmPtr, ro_flags: WasmPtr<__wasi_roflags_t, MemoryType>, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::sock_recv_from::( ctx, sock, @@ -1004,7 +1010,7 @@ pub(crate) fn sock_send( si_data_len: MemoryOffset, si_flags: __wasi_siflags_t, 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) } @@ -1016,7 +1022,7 @@ pub(crate) fn sock_send_to( si_flags: __wasi_siflags_t, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ret_data_len: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::sock_send_to::( ctx, sock, @@ -1035,7 +1041,7 @@ pub(crate) fn sock_send_file( offset: __wasi_filesize_t, count: __wasi_filesize_t, ret_sent: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { unsafe { super::sock_send_file::(ctx, out_fd, in_fd, offset, count, ret_sent) } } @@ -1043,7 +1049,7 @@ pub(crate) fn sock_shutdown( ctx: FunctionEnvMut, sock: __wasi_fd_t, how: __wasi_sdflags_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_shutdown(ctx, sock, how) } @@ -1055,6 +1061,6 @@ pub(crate) fn resolve( ips: WasmPtr<__wasi_addr_t, MemoryType>, nips: MemoryOffset, ret_nips: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::resolve::(ctx, host, host_len, port, ips, nips, ret_nips) } diff --git a/lib/wasi/src/utils.rs b/lib/wasi/src/utils.rs index 77222889179..01e8e7497a4 100644 --- a/lib/wasi/src/utils.rs +++ b/lib/wasi/src/utils.rs @@ -21,29 +21,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) -> wasi_snapshot0::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 => wasi_snapshot0::Errno::Noent, + ErrorKind::PermissionDenied => wasi_snapshot0::Errno::Perm, + ErrorKind::ConnectionRefused => wasi_snapshot0::Errno::Connrefused, + ErrorKind::ConnectionReset => wasi_snapshot0::Errno::Connreset, + ErrorKind::ConnectionAborted => wasi_snapshot0::Errno::Connaborted, + ErrorKind::NotConnected => wasi_snapshot0::Errno::Notconn, + ErrorKind::AddrInUse => wasi_snapshot0::Errno::Addrinuse, + ErrorKind::AddrNotAvailable => wasi_snapshot0::Errno::Addrnotavail, + ErrorKind::BrokenPipe => wasi_snapshot0::Errno::Pipe, + ErrorKind::AlreadyExists => wasi_snapshot0::Errno::Exist, + ErrorKind::WouldBlock => wasi_snapshot0::Errno::Again, + ErrorKind::InvalidInput => wasi_snapshot0::Errno::Io, + ErrorKind::InvalidData => wasi_snapshot0::Errno::Io, + ErrorKind::TimedOut => wasi_snapshot0::Errno::Timedout, + ErrorKind::WriteZero => wasi_snapshot0::Errno::Io, + ErrorKind::Interrupted => wasi_snapshot0::Errno::Intr, + ErrorKind::Other => wasi_snapshot0::Errno::Io, + ErrorKind::UnexpectedEof => wasi_snapshot0::Errno::Io, + ErrorKind::Unsupported => wasi_snapshot0::Errno::Notsup, + _ => wasi_snapshot0::Errno::Io, } } From 8d36b49f334377d40795189a3e6c88836ad380bd Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Tue, 16 Aug 2022 14:42:57 +0200 Subject: [PATCH 04/84] WIP: something that builds with Errno from wasi-types-generated --- Cargo.lock | 208 +++++++--------------------- lib/wasi-types-generated/src/lib.rs | 98 +++++++++++++ lib/wasi/src/macros.rs | 4 +- lib/wasi/src/runtime.rs | 1 - lib/wasi/src/syscalls/mod.rs | 2 +- 5 files changed, 150 insertions(+), 163 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9c195462afb..67d1c0ddede 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2983,39 +2983,18 @@ dependencies = [ "tracing", "wasm-bindgen", "wasm-bindgen-test", - "wasmer-compiler 3.0.0-beta", - "wasmer-compiler-cranelift 3.0.0-beta", + "wasmer-compiler", + "wasmer-compiler-cranelift", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", - "wasmer-derive 3.0.0-beta", - "wasmer-types 3.0.0-beta", - "wasmer-vm 3.0.0-beta", + "wasmer-derive", + "wasmer-types", + "wasmer-vm", "wasmparser 0.83.0", "wat", "winapi", ] -[[package]] -name = "wasmer" -version = "3.0.0-beta" -source = "git+https://github.com/wasmerio/wasmer.git?branch=master#a6ddf4e23ddbba827673e4068e8ae1b2fed4609e" -dependencies = [ - "cfg-if 1.0.0", - "indexmap", - "js-sys", - "more-asserts", - "target-lexicon 0.12.4", - "thiserror", - "wasm-bindgen", - "wasmer-compiler 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=master)", - "wasmer-compiler-cranelift 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=master)", - "wasmer-derive 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=master)", - "wasmer-types 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=master)", - "wasmer-vm 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=master)", - "wat", - "winapi", -] - [[package]] name = "wasmer-bin-fuzz" version = "0.0.0" @@ -3023,9 +3002,9 @@ dependencies = [ "anyhow", "libfuzzer-sys", "wasm-smith", - "wasmer 3.0.0-beta", - "wasmer-compiler 3.0.0-beta", - "wasmer-compiler-cranelift 3.0.0-beta", + "wasmer", + "wasmer-compiler", + "wasmer-compiler-cranelift", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-middlewares", @@ -3046,14 +3025,14 @@ dependencies = [ "paste", "thiserror", "typetag", - "wasmer 3.0.0-beta", - "wasmer-compiler 3.0.0-beta", - "wasmer-compiler-cranelift 3.0.0-beta", + "wasmer", + "wasmer-compiler", + "wasmer-compiler-cranelift", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-emscripten", "wasmer-middlewares", - "wasmer-types 3.0.0-beta", + "wasmer-types", "wasmer-wasi", ] @@ -3067,7 +3046,7 @@ dependencies = [ "rand", "tempfile", "thiserror", - "wasmer 3.0.0-beta", + "wasmer", "wasmer-compiler-singlepass", ] @@ -3090,17 +3069,17 @@ dependencies = [ "target-lexicon 0.12.4", "tempfile", "unix_mode", - "wasmer 3.0.0-beta", + "wasmer", "wasmer-cache", - "wasmer-compiler 3.0.0-beta", - "wasmer-compiler-cranelift 3.0.0-beta", + "wasmer-compiler", + "wasmer-compiler-cranelift", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-emscripten", "wasmer-object", - "wasmer-types 3.0.0-beta", + "wasmer-types", "wasmer-vfs", - "wasmer-vm 3.0.0-beta", + "wasmer-vm", "wasmer-wasi", "wasmer-wasi-experimental-io-devices", "wasmer-wast", @@ -3126,31 +3105,8 @@ dependencies = [ "smallvec", "thiserror", "wasmer-object", - "wasmer-types 3.0.0-beta", - "wasmer-vm 3.0.0-beta", - "wasmparser 0.83.0", - "winapi", -] - -[[package]] -name = "wasmer-compiler" -version = "3.0.0-beta" -source = "git+https://github.com/wasmerio/wasmer.git?branch=master#a6ddf4e23ddbba827673e4068e8ae1b2fed4609e" -dependencies = [ - "backtrace", - "cfg-if 1.0.0", - "enum-iterator", - "enumset", - "lazy_static", - "leb128", - "memmap2", - "more-asserts", - "region", - "rustc-demangle", - "smallvec", - "thiserror", - "wasmer-types 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=master)", - "wasmer-vm 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=master)", + "wasmer-types", + "wasmer-vm", "wasmparser 0.83.0", "winapi", ] @@ -3171,10 +3127,10 @@ dependencies = [ "target-lexicon 0.12.4", "tempfile", "unix_mode", - "wasmer-compiler 3.0.0-beta", - "wasmer-compiler-cranelift 3.0.0-beta", + "wasmer-compiler", + "wasmer-compiler-cranelift", "wasmer-compiler-singlepass", - "wasmer-types 3.0.0-beta", + "wasmer-types", ] [[package]] @@ -3192,26 +3148,8 @@ dependencies = [ "smallvec", "target-lexicon 0.12.4", "tracing", - "wasmer-compiler 3.0.0-beta", - "wasmer-types 3.0.0-beta", -] - -[[package]] -name = "wasmer-compiler-cranelift" -version = "3.0.0-beta" -source = "git+https://github.com/wasmerio/wasmer.git?branch=master#a6ddf4e23ddbba827673e4068e8ae1b2fed4609e" -dependencies = [ - "cranelift-codegen", - "cranelift-entity", - "cranelift-frontend", - "gimli", - "more-asserts", - "rayon", - "smallvec", - "target-lexicon 0.12.4", - "tracing", - "wasmer-compiler 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=master)", - "wasmer-types 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=master)", + "wasmer-compiler", + "wasmer-types", ] [[package]] @@ -3231,9 +3169,9 @@ dependencies = [ "semver 1.0.13", "smallvec", "target-lexicon 0.12.4", - "wasmer-compiler 3.0.0-beta", - "wasmer-types 3.0.0-beta", - "wasmer-vm 3.0.0-beta", + "wasmer-compiler", + "wasmer-types", + "wasmer-vm", ] [[package]] @@ -3250,8 +3188,8 @@ dependencies = [ "rayon", "smallvec", "target-lexicon 0.12.4", - "wasmer-compiler 3.0.0-beta", - "wasmer-types 3.0.0-beta", + "wasmer-compiler", + "wasmer-types", ] [[package]] @@ -3263,18 +3201,7 @@ dependencies = [ "proc-macro2", "quote", "syn", - "wasmer 3.0.0-beta", -] - -[[package]] -name = "wasmer-derive" -version = "3.0.0-beta" -source = "git+https://github.com/wasmerio/wasmer.git?branch=master#a6ddf4e23ddbba827673e4068e8ae1b2fed4609e" -dependencies = [ - "proc-macro-error", - "proc-macro2", - "quote", - "syn", + "wasmer", ] [[package]] @@ -3287,8 +3214,8 @@ dependencies = [ "libc", "log", "time", - "wasmer 3.0.0-beta", - "wasmer-types 3.0.0-beta", + "wasmer", + "wasmer-types", ] [[package]] @@ -3308,9 +3235,9 @@ version = "3.0.0-beta" name = "wasmer-middlewares" version = "3.0.0-beta" dependencies = [ - "wasmer 3.0.0-beta", - "wasmer-types 3.0.0-beta", - "wasmer-vm 3.0.0-beta", + "wasmer", + "wasmer-types", + "wasmer-vm", ] [[package]] @@ -3319,7 +3246,7 @@ version = "3.0.0-beta" dependencies = [ "object 0.28.4", "thiserror", - "wasmer-types 3.0.0-beta", + "wasmer-types", ] [[package]] @@ -3337,20 +3264,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "wasmer-types" -version = "3.0.0-beta" -source = "git+https://github.com/wasmerio/wasmer.git?branch=master#a6ddf4e23ddbba827673e4068e8ae1b2fed4609e" -dependencies = [ - "enum-iterator", - "enumset", - "indexmap", - "more-asserts", - "rkyv", - "target-lexicon 0.12.4", - "thiserror", -] - [[package]] name = "wasmer-vbus" version = "3.0.0-beta" @@ -3394,30 +3307,7 @@ dependencies = [ "scopeguard", "serde", "thiserror", - "wasmer-types 3.0.0-beta", - "winapi", -] - -[[package]] -name = "wasmer-vm" -version = "3.0.0-beta" -source = "git+https://github.com/wasmerio/wasmer.git?branch=master#a6ddf4e23ddbba827673e4068e8ae1b2fed4609e" -dependencies = [ - "backtrace", - "cc", - "cfg-if 1.0.0", - "corosensei", - "enum-iterator", - "indexmap", - "lazy_static", - "libc", - "mach", - "memoffset", - "more-asserts", - "region", - "scopeguard", - "thiserror", - "wasmer-types 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=master)", + "wasmer-types", "winapi", ] @@ -3453,7 +3343,7 @@ dependencies = [ "typetag", "wasm-bindgen", "wasm-bindgen-test", - "wasmer 3.0.0-beta", + "wasmer", "wasmer-vbus", "wasmer-vfs", "wasmer-vnet", @@ -3493,8 +3383,8 @@ dependencies = [ "byteorder", "serde", "time", - "wasmer-derive 3.0.0-beta", - "wasmer-types 3.0.0-beta", + "wasmer-derive", + "wasmer-types", "wasmer-wasi-types-generated", ] @@ -3502,8 +3392,8 @@ dependencies = [ name = "wasmer-wasi-types-generated" version = "3.0.0-beta" dependencies = [ - "wasmer-derive 3.0.0-beta", - "wasmer-types 3.0.0-beta", + "wasmer-derive", + "wasmer-types", "wit-bindgen-wasmer", ] @@ -3515,7 +3405,7 @@ dependencies = [ "serde", "tempfile", "thiserror", - "wasmer 3.0.0-beta", + "wasmer", "wasmer-vfs", "wasmer-wasi", "wast 38.0.1", @@ -3540,15 +3430,15 @@ dependencies = [ "tracing", "tracing-subscriber", "wasi-test-generator", - "wasmer 3.0.0-beta", + "wasmer", "wasmer-cache", - "wasmer-compiler 3.0.0-beta", - "wasmer-compiler-cranelift 3.0.0-beta", + "wasmer-compiler", + "wasmer-compiler-cranelift", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-emscripten", "wasmer-middlewares", - "wasmer-types 3.0.0-beta", + "wasmer-types", "wasmer-wasi", "wasmer-wast", ] @@ -3875,7 +3765,7 @@ dependencies = [ "bitflags", "once_cell", "thiserror", - "wasmer 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=master)", + "wasmer", "wit-bindgen-wasmer-impl", ] diff --git a/lib/wasi-types-generated/src/lib.rs b/lib/wasi-types-generated/src/lib.rs index bf524665ea7..2aa91cdf50e 100644 --- a/lib/wasi-types-generated/src/lib.rs +++ b/lib/wasi-types-generated/src/lib.rs @@ -5,7 +5,105 @@ pub use bindings::*; use std::mem::MaybeUninit; use wasmer_types::ValueType; +// TODO: if necessary, must be implemented in wit-bindgen unsafe impl ValueType for wasi_snapshot0::Errno { #[inline] fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0::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::Acces, + 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, + // TODO: What should we map invalid native values to? + _ => Self::Inval, + } + } + + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} diff --git a/lib/wasi/src/macros.rs b/lib/wasi/src/macros.rs index b4e58882cd0..938f7dcab26 100644 --- a/lib/wasi/src/macros.rs +++ b/lib/wasi/src/macros.rs @@ -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::wasi_snapshot0::Errno> = $expr; + let res: Result<_, __bus_errno_t> = $expr; match res { Ok(val) => { tracing::trace!("wasi::wasi_try_bus::val: {:?}", val); @@ -71,7 +71,7 @@ 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_snapshot0::Errno`. macro_rules! wasi_try_mem { ($expr:expr) => {{ wasi_try!($expr.map_err($crate::mem_error_to_wasi)) diff --git a/lib/wasi/src/runtime.rs b/lib/wasi/src/runtime.rs index aa8f58066f5..b2c345dcdfc 100644 --- a/lib/wasi/src/runtime.rs +++ b/lib/wasi/src/runtime.rs @@ -6,7 +6,6 @@ use wasmer_vbus::{UnsupportedVirtualBus, VirtualBus}; use wasmer_vnet::VirtualNetworking; use wasmer_wasi_types_generated::wasi_snapshot0; -use super::types::*; use super::WasiError; use super::WasiThreadId; diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 9db54761e28..66912d30231 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -3231,7 +3231,7 @@ pub fn poll_oneoff( for event in event_iter { match event { PollEvent::PollError => error = wasi_snapshot0::Errno::Io, - PollEvent::PollHangUp => flags = wasi_snapshot0::Errno::VentFdReadwriteHangup, + PollEvent::PollHangUp => flags = __WASI_EVENT_FD_READWRITE_HANGUP, PollEvent::PollInvalid => error = wasi_snapshot0::Errno::Inval, PollEvent::PollIn => { bytes_available = wasi_try_ok!( From 8fdbde469de47276071f487fd6a4d86d4147efd7 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Wed, 17 Aug 2022 09:18:34 +0200 Subject: [PATCH 05/84] WIP --- Cargo.lock | 13 +++++++ lib/wasi-types-generated/Cargo.toml | 5 +++ lib/wasi-types-generated/regenerate.sh | 1 + lib/wasi-types-generated/src/lib.rs | 6 +++ lib/wasi-types/Cargo.toml | 6 ++- lib/wasi-types/src/directory.rs | 36 +++++++++++++---- lib/wasi-types/src/file.rs | 43 +++++++-------------- lib/wasi-types/src/versions/snapshot0.rs | 8 ++-- lib/wasi/Cargo.toml | 1 + lib/wasi/src/state/mod.rs | 49 +++++++++++++----------- lib/wasi/src/syscalls/mod.rs | 10 ++--- 11 files changed, 108 insertions(+), 70 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 67d1c0ddede..c6e4f62c56a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2255,6 +2255,17 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_repr" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fe39d9fbb0ebf5eb2c7cb7e2a47e4f462fad1379f1166b8ae49ad9eae89a7ca" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "serial_test" version = "0.5.1" @@ -3392,6 +3403,8 @@ dependencies = [ name = "wasmer-wasi-types-generated" version = "3.0.0-beta" dependencies = [ + "serde", + "serde_repr", "wasmer-derive", "wasmer-types", "wit-bindgen-wasmer", diff --git a/lib/wasi-types-generated/Cargo.toml b/lib/wasi-types-generated/Cargo.toml index 2ba55270724..1b43694a301 100644 --- a/lib/wasi-types-generated/Cargo.toml +++ b/lib/wasi-types-generated/Cargo.toml @@ -6,6 +6,8 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +serde = { version = "1.0", features = ["derive"], optional = true } +serde_repr = { version = "0.1", optional = true } wasmer-derive = { path = "../derive", version = "=3.0.0-beta" } wasmer-types = { path = "../types", version = "=3.0.0-beta" } @@ -13,3 +15,6 @@ wasmer-types = { path = "../types", version = "=3.0.0-beta" } path = "/home/silwol/Projects/wasmerio/wit-bindgen/crates/wasmer" #git = "https://github.com/wasmerio/wit-bindgen.git" #branch = "wasmer" + +[features] +enable-serde = ["serde", "serde_repr", "wasmer-types/serde"] diff --git a/lib/wasi-types-generated/regenerate.sh b/lib/wasi-types-generated/regenerate.sh index 37874c7968c..fa31ebd9e88 100755 --- a/lib/wasi-types-generated/regenerate.sh +++ b/lib/wasi-types-generated/regenerate.sh @@ -1,3 +1,4 @@ #!/bin/bash +rm src/bindings.rs wit-bindgen wasmer --import wit/wasi-snapshot0.wit wit/wasi-filesystem.wit --out-dir src/ diff --git a/lib/wasi-types-generated/src/lib.rs b/lib/wasi-types-generated/src/lib.rs index 2aa91cdf50e..23b93bf9179 100644 --- a/lib/wasi-types-generated/src/lib.rs +++ b/lib/wasi-types-generated/src/lib.rs @@ -11,6 +11,12 @@ unsafe impl ValueType for wasi_snapshot0::Errno { fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for wasi_snapshot0::Filetype { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + // TODO: if necessary, must be implemented in wit-bindgen unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0::Errno { type Native = i32; diff --git a/lib/wasi-types/Cargo.toml b/lib/wasi-types/Cargo.toml index bfcef194396..6a704eb178f 100644 --- a/lib/wasi-types/Cargo.toml +++ b/lib/wasi-types/Cargo.toml @@ -19,4 +19,8 @@ byteorder = "1.3" time = "0.2" [features] -enable-serde = ["serde", "wasmer-types/serde"] +enable-serde = [ + "serde", + "wasmer-types/serde", + "wasmer-wasi-types-generated/enable-serde", +] diff --git a/lib/wasi-types/src/directory.rs b/lib/wasi-types/src/directory.rs index d43b709f61f..360bdf076b8 100644 --- a/lib/wasi-types/src/directory.rs +++ b/lib/wasi-types/src/directory.rs @@ -1,6 +1,7 @@ use crate::*; use std::mem; use wasmer_derive::ValueType; +use wasmer_wasi_types_generated::wasi_snapshot0; pub type __wasi_dircookie_t = u64; pub const __WASI_DIRCOOKIE_START: u64 = 0; @@ -11,7 +12,7 @@ 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 d_type: wasi_snapshot0::Filetype, } pub fn dirent_to_le_bytes(ent: &__wasi_dirent_t) -> Vec { @@ -19,7 +20,7 @@ pub fn dirent_to_le_bytes(ent: &__wasi_dirent_t) -> Vec { .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()) + .chain(u32::from(ent.d_type as u8).to_le_bytes()) .collect(); assert_eq!(out.len(), mem::size_of::<__wasi_dirent_t>()); @@ -29,6 +30,7 @@ pub fn dirent_to_le_bytes(ent: &__wasi_dirent_t) -> Vec { #[cfg(test)] mod tests { use super::{__wasi_dirent_t, dirent_to_le_bytes}; + use wasmer_wasi_types_generated::wasi_snapshot0; #[test] fn test_dirent_to_le_bytes() { @@ -36,23 +38,43 @@ mod tests { d_next: 0x0123456789abcdef, d_ino: 0xfedcba9876543210, d_namlen: 0xaabbccdd, - d_type: 0x99, + d_type: wasi_snapshot0::Filetype::Directory, }; assert_eq!( vec![ // d_next - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, + 0xef, + 0xcd, + 0xab, + 0x89, + 0x67, + 0x45, + 0x23, + 0x01, // // d_ino - 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe, + 0x10, + 0x32, + 0x54, + 0x76, + 0x98, + 0xba, + 0xdc, + 0xfe, // // d_namelen - 0xdd, 0xcc, 0xbb, 0xaa, + 0xdd, + 0xcc, + 0xbb, + 0xaa, // // d_type // plus padding - 0x99, 0x00, 0x00, 0x00, + wasi_snapshot0::Filetype::Directory as u8, + 0x00, + 0x00, + 0x00, ], dirent_to_le_bytes(&s) ); diff --git a/lib/wasi-types/src/file.rs b/lib/wasi-types/src/file.rs index 0d58ba9bbe4..f95445f22fc 100644 --- a/lib/wasi-types/src/file.rs +++ b/lib/wasi-types/src/file.rs @@ -1,12 +1,11 @@ use crate::*; -#[cfg(feature = "enable-serde")] -use serde::{Deserialize, Serialize}; use std::{ fmt, mem::{self, MaybeUninit}, }; use wasmer_derive::ValueType; use wasmer_types::ValueType; +use wasmer_wasi_types_generated::wasi_snapshot0; pub type __wasi_device_t = u64; @@ -121,7 +120,7 @@ unsafe impl ValueType for __wasi_prestat_t { #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] #[repr(C)] pub struct __wasi_fdstat_t { - pub fs_filetype: __wasi_filetype_t, + pub fs_filetype: wasi_snapshot0::Filetype, pub fs_flags: __wasi_fdflags_t, pub fs_rights_base: __wasi_rights_t, pub fs_rights_inheriting: __wasi_rights_t, @@ -132,12 +131,11 @@ 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_filetype: wasi_snapshot0::Filetype, pub st_nlink: __wasi_linkcount_t, pub st_size: __wasi_filesize_t, pub st_atim: __wasi_timestamp_t, @@ -150,7 +148,7 @@ impl Default for __wasi_filestat_t { __wasi_filestat_t { st_dev: Default::default(), st_ino: Default::default(), - st_filetype: __WASI_FILETYPE_UNKNOWN, + st_filetype: wasi_snapshot0::Filetype::Unknown, st_nlink: 1, st_size: Default::default(), st_atim: Default::default(), @@ -174,7 +172,7 @@ impl fmt::Debug for __wasi_filestat_t { &format!( "{} ({})", wasi_filetype_to_name(self.st_filetype), - self.st_filetype, + self.st_filetype as u8, ), ) .field("st_nlink", &self.st_nlink) @@ -195,32 +193,19 @@ impl fmt::Debug for __wasi_filestat_t { } } -pub fn wasi_filetype_to_name(ft: __wasi_filetype_t) -> &'static str { +pub fn wasi_filetype_to_name(ft: wasi_snapshot0::Filetype) -> &'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", + wasi_snapshot0::Filetype::Unknown => "Unknown", + wasi_snapshot0::Filetype::BlockDevice => "Block device", + wasi_snapshot0::Filetype::CharacterDevice => "Character device", + wasi_snapshot0::Filetype::Directory => "Directory", + wasi_snapshot0::Filetype::RegularFile => "Regular file", + wasi_snapshot0::Filetype::SocketDgram => "Socket dgram", + wasi_snapshot0::Filetype::SocketStream => "Socket stream", + wasi_snapshot0::Filetype::SymbolicLink => "Symbolic link", } } -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; diff --git a/lib/wasi-types/src/versions/snapshot0.rs b/lib/wasi-types/src/versions/snapshot0.rs index 45fec2bb339..cee8ae5d3aa 100644 --- a/lib/wasi-types/src/versions/snapshot0.rs +++ b/lib/wasi-types/src/versions/snapshot0.rs @@ -1,10 +1,9 @@ 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; +use wasmer_wasi_types_generated::wasi_snapshot0; pub type __wasi_linkcount_t = u32; @@ -83,12 +82,11 @@ 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_filetype: wasi_snapshot0::Filetype, pub st_nlink: __wasi_linkcount_t, pub st_size: __wasi_filesize_t, pub st_atim: __wasi_timestamp_t, @@ -110,7 +108,7 @@ impl fmt::Debug for __wasi_filestat_t { &format!( "{} ({})", wasi_filetype_to_name(self.st_filetype), - self.st_filetype, + self.st_filetype as u8, ), ) .field("st_nlink", &self.st_nlink) diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml index 7b3e248be03..a8b4ad72ec7 100644 --- a/lib/wasi/Cargo.toml +++ b/lib/wasi/Cargo.toml @@ -73,4 +73,5 @@ enable-serde = [ "wasmer-vfs/enable-serde", "generational-arena/serde", "wasmer-wasi-types/enable-serde", + "wasmer-wasi-types-generated/enable-serde", ] diff --git a/lib/wasi/src/state/mod.rs b/lib/wasi/src/state/mod.rs index a91a87a9a1d..ad20eed8f25 100644 --- a/lib/wasi/src/state/mod.rs +++ b/lib/wasi/src/state/mod.rs @@ -990,18 +990,19 @@ impl WasiFs { #[cfg(unix)] { //use std::os::unix::fs::FileTypeExt; - let file_type: __wasi_filetype_t = if file_type.is_char_device() + let file_type: wasi_snapshot0::Filetype = if file_type + .is_char_device() { - __WASI_FILETYPE_CHARACTER_DEVICE + wasi_snapshot0::Filetype::CharacterDevice } else if file_type.is_block_device() { - __WASI_FILETYPE_BLOCK_DEVICE + wasi_snapshot0::Filetype::BlockDevice } else if file_type.is_fifo() { // FIFO doesn't seem to fit any other type, so unknown - __WASI_FILETYPE_UNKNOWN + wasi_snapshot0::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`? + wasi_snapshot0::Filetype::SocketStream } else { unimplemented!("state::get_inode_at_path unknown file type: not file, directory, symlink, char device, block device, fifo, or socket"); }; @@ -1323,7 +1324,7 @@ impl WasiFs { match fd { __WASI_STDIN_FILENO => { return Ok(__wasi_fdstat_t { - fs_filetype: __WASI_FILETYPE_CHARACTER_DEVICE, + fs_filetype: wasi_snapshot0::Filetype::CharacterDevice, fs_flags: 0, fs_rights_base: STDIN_DEFAULT_RIGHTS, fs_rights_inheriting: 0, @@ -1331,7 +1332,7 @@ impl WasiFs { } __WASI_STDOUT_FILENO => { return Ok(__wasi_fdstat_t { - fs_filetype: __WASI_FILETYPE_CHARACTER_DEVICE, + fs_filetype: wasi_snapshot0::Filetype::CharacterDevice, fs_flags: __WASI_FDFLAG_APPEND, fs_rights_base: STDOUT_DEFAULT_RIGHTS, fs_rights_inheriting: 0, @@ -1339,7 +1340,7 @@ impl WasiFs { } __WASI_STDERR_FILENO => { return Ok(__wasi_fdstat_t { - fs_filetype: __WASI_FILETYPE_CHARACTER_DEVICE, + fs_filetype: wasi_snapshot0::Filetype::CharacterDevice, fs_flags: __WASI_FDFLAG_APPEND, fs_rights_base: STDERR_DEFAULT_RIGHTS, fs_rights_inheriting: 0, @@ -1347,7 +1348,7 @@ impl WasiFs { } VIRTUAL_ROOT_FD => { return Ok(__wasi_fdstat_t { - fs_filetype: __WASI_FILETYPE_DIRECTORY, + fs_filetype: wasi_snapshot0::Filetype::Directory, fs_flags: 0, // TODO: fix this fs_rights_base: ALL_RIGHTS, @@ -1363,10 +1364,10 @@ impl WasiFs { let deref = guard.deref(); Ok(__wasi_fdstat_t { 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 { .. } => wasi_snapshot0::Filetype::RegularFile, + Kind::Dir { .. } => wasi_snapshot0::Filetype::Directory, + Kind::Symlink { .. } => wasi_snapshot0::Filetype::SymbolicLink, + _ => wasi_snapshot0::Filetype::Unknown, }, fs_flags: fd.flags, fs_rights_base: fd.rights, @@ -1537,7 +1538,7 @@ impl WasiFs { fn create_virtual_root(&self, inodes: &mut WasiInodes) -> Inode { let stat = __wasi_filestat_t { - st_filetype: __WASI_FILETYPE_DIRECTORY, + st_filetype: wasi_snapshot0::Filetype::Directory, st_ino: self.get_next_inode_index(), ..__wasi_filestat_t::default() }; @@ -1594,7 +1595,7 @@ impl WasiFs { fd_flags: __wasi_fdflags_t, ) { let stat = __wasi_filestat_t { - st_filetype: __WASI_FILETYPE_CHARACTER_DEVICE, + st_filetype: wasi_snapshot0::Filetype::CharacterDevice, st_ino: self.get_next_inode_index(), ..__wasi_filestat_t::default() }; @@ -1634,7 +1635,7 @@ impl WasiFs { Kind::File { handle, path, .. } => match handle { Some(wf) => { return Ok(__wasi_filestat_t { - st_filetype: __WASI_FILETYPE_REGULAR_FILE, + st_filetype: wasi_snapshot0::Filetype::RegularFile, st_size: wf.size(), st_atim: wf.last_accessed(), st_mtim: wf.last_modified(), @@ -1963,15 +1964,17 @@ 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, +) -> wasi_snapshot0::Filetype { // TODO: handle other file types if file_type.is_dir() { - __WASI_FILETYPE_DIRECTORY + wasi_snapshot0::Filetype::Directory } else if file_type.is_file() { - __WASI_FILETYPE_REGULAR_FILE + wasi_snapshot0::Filetype::RegularFile } else if file_type.is_symlink() { - __WASI_FILETYPE_SYMBOLIC_LINK + wasi_snapshot0::Filetype::SymbolicLink } else { - __WASI_FILETYPE_UNKNOWN + wasi_snapshot0::Filetype::Unknown } } diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 66912d30231..95a833047b6 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -1314,7 +1314,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, wasi_snapshot0::Filetype, u64)> = { let guard = inodes.arena[working_dir.inode].read(); let deref = guard.deref(); match deref { @@ -1339,7 +1339,7 @@ pub fn fd_readdir( filename, filetype, 0, // TODO: inode )) }) - .collect::, _>>()); + .collect::, _>>()); entry_vec.extend( entries .iter() @@ -1352,8 +1352,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(), wasi_snapshot0::Filetype::Directory, 0)); + entry_vec.push(("..".to_string(), wasi_snapshot0::Filetype::Directory, 0)); entry_vec.sort_by(|a, b| a.0.cmp(&b.0)); entry_vec } @@ -1944,7 +1944,7 @@ pub fn path_create_directory( 0, &adjusted_path.to_string_lossy(), ) { - if adjusted_path_stat.st_filetype != __WASI_FILETYPE_DIRECTORY { + if adjusted_path_stat.st_filetype != wasi_snapshot0::Filetype::Directory { return wasi_snapshot0::Errno::Notdir; } } else { From d1bc30d09c278b4cc4d63629522a5d870b94dc37 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Wed, 17 Aug 2022 09:35:49 +0200 Subject: [PATCH 06/84] WIP --- Cargo.lock | 13 ------------- lib/wasi-types-generated/Cargo.toml | 5 ----- lib/wasi-types/Cargo.toml | 6 +----- lib/wasi/Cargo.toml | 3 +-- 4 files changed, 2 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c6e4f62c56a..67d1c0ddede 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2255,17 +2255,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_repr" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fe39d9fbb0ebf5eb2c7cb7e2a47e4f462fad1379f1166b8ae49ad9eae89a7ca" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "serial_test" version = "0.5.1" @@ -3403,8 +3392,6 @@ dependencies = [ name = "wasmer-wasi-types-generated" version = "3.0.0-beta" dependencies = [ - "serde", - "serde_repr", "wasmer-derive", "wasmer-types", "wit-bindgen-wasmer", diff --git a/lib/wasi-types-generated/Cargo.toml b/lib/wasi-types-generated/Cargo.toml index 1b43694a301..2ba55270724 100644 --- a/lib/wasi-types-generated/Cargo.toml +++ b/lib/wasi-types-generated/Cargo.toml @@ -6,8 +6,6 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -serde = { version = "1.0", features = ["derive"], optional = true } -serde_repr = { version = "0.1", optional = true } wasmer-derive = { path = "../derive", version = "=3.0.0-beta" } wasmer-types = { path = "../types", version = "=3.0.0-beta" } @@ -15,6 +13,3 @@ wasmer-types = { path = "../types", version = "=3.0.0-beta" } path = "/home/silwol/Projects/wasmerio/wit-bindgen/crates/wasmer" #git = "https://github.com/wasmerio/wit-bindgen.git" #branch = "wasmer" - -[features] -enable-serde = ["serde", "serde_repr", "wasmer-types/serde"] diff --git a/lib/wasi-types/Cargo.toml b/lib/wasi-types/Cargo.toml index 6a704eb178f..bfcef194396 100644 --- a/lib/wasi-types/Cargo.toml +++ b/lib/wasi-types/Cargo.toml @@ -19,8 +19,4 @@ byteorder = "1.3" time = "0.2" [features] -enable-serde = [ - "serde", - "wasmer-types/serde", - "wasmer-wasi-types-generated/enable-serde", -] +enable-serde = ["serde", "wasmer-types/serde"] diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml index a8b4ad72ec7..22ecc9dc57f 100644 --- a/lib/wasi/Cargo.toml +++ b/lib/wasi/Cargo.toml @@ -25,7 +25,7 @@ wasmer-vfs = { path = "../vfs", version = "=3.0.0-beta", default-features = fals wasmer-vbus = { path = "../vbus", version = "=3.0.0-beta", default-features = false } wasmer-vnet = { path = "../vnet", version = "=3.0.0-beta", default-features = false } wasmer-wasi-local-networking = { path = "../wasi-local-networking", version = "=3.0.0-beta", default-features = false, optional = true } -wasmer-wasi-types-generated = { path = "../wasi-types-generated", version = "=3.0.0-beta", default-features = false } +wasmer-wasi-types-generated = { path = "../wasi-types-generated", version = "=3.0.0-beta" } typetag = { version = "0.1", optional = true } serde = { version = "1.0", default-features = false, features = ["derive"], optional = true } bincode = { version = "1.3", optional = true } @@ -73,5 +73,4 @@ enable-serde = [ "wasmer-vfs/enable-serde", "generational-arena/serde", "wasmer-wasi-types/enable-serde", - "wasmer-wasi-types-generated/enable-serde", ] From a54005ff713e0b880a6fb9b6ad39eca8426e4638 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Wed, 17 Aug 2022 11:22:42 +0200 Subject: [PATCH 07/84] WIP --- lib/api/src/js/externals/memory_view.rs | 29 +++++++++++++++++++++++++ lib/wasi-types-generated/Cargo.toml | 5 +++++ lib/wasi-types-generated/src/lib.rs | 1 + lib/wasi/Cargo.toml | 6 ++--- lib/wasi/src/syscalls/wasm32.rs | 6 ++--- 5 files changed, 41 insertions(+), 6 deletions(-) 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/wasi-types-generated/Cargo.toml b/lib/wasi-types-generated/Cargo.toml index 2ba55270724..d776d7ae028 100644 --- a/lib/wasi-types-generated/Cargo.toml +++ b/lib/wasi-types-generated/Cargo.toml @@ -11,5 +11,10 @@ wasmer-types = { path = "../types", version = "=3.0.0-beta" } [dependencies.wit-bindgen-wasmer] path = "/home/silwol/Projects/wasmerio/wit-bindgen/crates/wasmer" +default-features = false #git = "https://github.com/wasmerio/wit-bindgen.git" #branch = "wasmer" + +[features] +js = ["wit-bindgen-wasmer/js"] +sys = ["wit-bindgen-wasmer/sys"] diff --git a/lib/wasi-types-generated/src/lib.rs b/lib/wasi-types-generated/src/lib.rs index 23b93bf9179..268156c3917 100644 --- a/lib/wasi-types-generated/src/lib.rs +++ b/lib/wasi-types-generated/src/lib.rs @@ -108,6 +108,7 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0: } } + #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { // TODO: find correct implementation false diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml index 22ecc9dc57f..dc1deba1371 100644 --- a/lib/wasi/Cargo.toml +++ b/lib/wasi/Cargo.toml @@ -25,7 +25,7 @@ wasmer-vfs = { path = "../vfs", version = "=3.0.0-beta", default-features = fals wasmer-vbus = { path = "../vbus", version = "=3.0.0-beta", default-features = false } wasmer-vnet = { path = "../vnet", version = "=3.0.0-beta", default-features = false } wasmer-wasi-local-networking = { path = "../wasi-local-networking", version = "=3.0.0-beta", default-features = false, optional = true } -wasmer-wasi-types-generated = { path = "../wasi-types-generated", version = "=3.0.0-beta" } +wasmer-wasi-types-generated = { path = "../wasi-types-generated", version = "=3.0.0-beta", default-features = false } typetag = { version = "0.1", optional = true } serde = { version = "1.0", default-features = false, features = ["derive"], optional = true } bincode = { version = "1.3", optional = true } @@ -49,11 +49,11 @@ tracing-wasm = "0.2" [features] default = ["sys-default"] -sys = ["wasmer/sys"] +sys = ["wasmer/sys", "wasmer-wasi-types-generated/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-generated/js"] js-default = ["js", "wasmer/js-default"] test-js = ["js", "wasmer/js-default", "wasmer/wat"] diff --git a/lib/wasi/src/syscalls/wasm32.rs b/lib/wasi/src/syscalls/wasm32.rs index d9f56ac85c1..f62a4f3e4e1 100644 --- a/lib/wasi/src/syscalls/wasm32.rs +++ b/lib/wasi/src/syscalls/wasm32.rs @@ -6,13 +6,13 @@ use wasmer::WasmRef; pub fn platform_clock_res_get( clock_id: __wasi_clockid_t, resolution: WasmRef<__wasi_timestamp_t>, -) -> Result { +) -> 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), + _ => return Err(wasi_snapshot0::Errno::Inval), }; Ok(t_out) } @@ -20,7 +20,7 @@ pub fn platform_clock_res_get( pub fn platform_clock_time_get( clock_id: __wasi_clockid_t, precision: __wasi_timestamp_t, -) -> Result { +) -> Result { let new_time: DateTime = Local::now(); Ok(new_time.timestamp_nanos() as i64) } From c6e2eb0ded729422606990f3512be8c2338051f8 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Wed, 17 Aug 2022 14:39:48 +0200 Subject: [PATCH 08/84] Eventtype --- lib/wasi-types-generated/src/bindings.rs | 29 ++++++++++++ lib/wasi-types-generated/src/lib.rs | 6 +++ .../wit/wasi-snapshot0.wit | 32 ++++++------- lib/wasi-types/src/event.rs | 28 +++++------- lib/wasi-types/src/subscription.rs | 45 ++++++++++--------- lib/wasi-types/src/versions/snapshot0.rs | 12 +++-- lib/wasi/src/syscalls/legacy/snapshot0.rs | 2 +- lib/wasi/src/syscalls/mod.rs | 2 +- 8 files changed, 95 insertions(+), 61 deletions(-) diff --git a/lib/wasi-types-generated/src/bindings.rs b/lib/wasi-types-generated/src/bindings.rs index ea91e4c23c4..67c37b87316 100644 --- a/lib/wasi-types-generated/src/bindings.rs +++ b/lib/wasi-types-generated/src/bindings.rs @@ -509,6 +509,35 @@ pub mod wasi_snapshot0 { Ok(())} } + /// 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::file-descriptor` has data + /// available for reading. This event always triggers for regular files. + FdRead, + /// File descriptor `subscription-fd-readwrite::file-descriptor` 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() + } + } + } + } #[allow(unused_imports)] use wasmer::AsStoreMut as _; #[allow(unused_imports)] diff --git a/lib/wasi-types-generated/src/lib.rs b/lib/wasi-types-generated/src/lib.rs index 268156c3917..777c3982f85 100644 --- a/lib/wasi-types-generated/src/lib.rs +++ b/lib/wasi-types-generated/src/lib.rs @@ -17,6 +17,12 @@ unsafe impl ValueType for wasi_snapshot0::Filetype { fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for wasi_snapshot0::Eventtype { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + // TODO: if necessary, must be implemented in wit-bindgen unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0::Errno { type Native = i32; diff --git a/lib/wasi-types-generated/wit/wasi-snapshot0.wit b/lib/wasi-types-generated/wit/wasi-snapshot0.wit index e942f04f3dc..eb7ff29fb15 100644 --- a/lib/wasi-types-generated/wit/wasi-snapshot0.wit +++ b/lib/wasi-types-generated/wit/wasi-snapshot0.wit @@ -481,21 +481,23 @@ record fdstat { // ;;; User-provided value that may be attached to objects that is retained when // ;;; extracted from the implementation. // (typename $userdata u64) -// -// ;;; Type of a subscription to an event or its occurrence. -// (typename $eventtype -// (enum (@witx tag u8) -// ;;; The time value of clock `subscription_clock::id` has -// ;;; reached timestamp `subscription_clock::timeout`. -// $clock -// ;;; File descriptor `subscription_fd_readwrite::file_descriptor` has data -// ;;; available for reading. This event always triggers for regular files. -// $fd_read -// ;;; File descriptor `subscription_fd_readwrite::file_descriptor` has capacity -// ;;; available for writing. This event always triggers for regular files. -// $fd_write -// ) -// ) + +/// Type of a subscription to an event or its occurrence. +enum eventtype { + // TODO: wit appears to not have support for enum type size + //enum (@witx tag u8) + + /// The time value of clock `subscription-clock::id` has + /// reached timestamp `subscription-clock::timeout`. + clock, + /// File descriptor `subscription-fd-readwrite::file-descriptor` has data + /// available for reading. This event always triggers for regular files. + fd-read, + /// File descriptor `subscription-fd-readwrite::file-descriptor` has capacity + /// available for writing. This event always triggers for regular files. + fd-write, +} + // // ;;; The state of the file descriptor subscribed to with // ;;; `eventtype::fd_read` or `eventtype::fd_write`. diff --git a/lib/wasi-types/src/event.rs b/lib/wasi-types/src/event.rs index ff28b7508f0..5a6235eb294 100644 --- a/lib/wasi-types/src/event.rs +++ b/lib/wasi-types/src/event.rs @@ -52,17 +52,19 @@ impl EventEnum { pub struct __wasi_event_t { pub userdata: __wasi_userdata_t, pub error: wasi_snapshot0::Errno, - pub type_: __wasi_eventtype_t, + pub type_: wasi_snapshot0::Eventtype, 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 }, - }), + wasi_snapshot0::Eventtype::FdRead | wasi_snapshot0::Eventtype::FdWrite => { + Some(EventEnum::FdReadWrite { + nbytes: unsafe { self.u.fd_readwrite.nbytes }, + flags: unsafe { self.u.fd_readwrite.flags }, + }) + } _ => None, } } @@ -97,7 +99,7 @@ unsafe impl ValueType for __wasi_event_t { .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 { + wasi_snapshot0::Eventtype::FdRead | wasi_snapshot0::Eventtype::FdWrite => unsafe { self.u.fd_readwrite.zero_padding_bytes( &mut bytes[field!(u.fd_readwrite)..field_end!(u.fd_readwrite)], ); @@ -112,16 +114,10 @@ unsafe impl ValueType for __wasi_event_t { 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 { +pub fn eventtype_to_str(event_type: wasi_snapshot0::Eventtype) -> &'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", + wasi_snapshot0::Eventtype::Clock => "Wasi::Eventtype::Clock", + wasi_snapshot0::Eventtype::FdRead => "Wasi::Eventtype::FdRead", + wasi_snapshot0::Eventtype::FdWrite => "Wasi::Eventtype::FdWrite", } } diff --git a/lib/wasi-types/src/subscription.rs b/lib/wasi-types/src/subscription.rs index 690b77fa542..d69181f4028 100644 --- a/lib/wasi-types/src/subscription.rs +++ b/lib/wasi-types/src/subscription.rs @@ -35,7 +35,7 @@ pub union __wasi_subscription_u { #[repr(C)] pub struct __wasi_subscription_t { pub userdata: __wasi_userdata_t, - pub type_: __wasi_eventtype_t, + pub type_: wasi_snapshot0::Eventtype, pub u: __wasi_subscription_u, } @@ -48,11 +48,11 @@ pub enum EventType { } impl EventType { - pub fn raw_tag(&self) -> __wasi_eventtype_t { + pub fn raw_tag(&self) -> wasi_snapshot0::Eventtype { match self { - EventType::Clock(_) => __WASI_EVENTTYPE_CLOCK, - EventType::Read(_) => __WASI_EVENTTYPE_FD_READ, - EventType::Write(_) => __WASI_EVENTTYPE_FD_WRITE, + EventType::Clock(_) => wasi_snapshot0::Eventtype::Clock, + EventType::Read(_) => wasi_snapshot0::Eventtype::FdRead, + EventType::Write(_) => wasi_snapshot0::Eventtype::FdWrite, } } } @@ -71,10 +71,11 @@ impl TryFrom<__wasi_subscription_t> for WasiSubscription { 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_snapshot0::Errno::Inval), + wasi_snapshot0::Eventtype::Clock => EventType::Clock(unsafe { ws.u.clock }), + wasi_snapshot0::Eventtype::FdRead => EventType::Read(unsafe { ws.u.fd_readwrite }), + wasi_snapshot0::Eventtype::FdWrite => { + EventType::Write(unsafe { ws.u.fd_readwrite }) + } }, }) } @@ -86,13 +87,16 @@ impl TryFrom for __wasi_subscription_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::Clock(c) => ( + wasi_snapshot0::Eventtype::Clock, + __wasi_subscription_u { clock: c }, + ), EventType::Read(rw) => ( - __WASI_EVENTTYPE_FD_READ, + wasi_snapshot0::Eventtype::FdRead, __wasi_subscription_u { fd_readwrite: rw }, ), EventType::Write(rw) => ( - __WASI_EVENTTYPE_FD_WRITE, + wasi_snapshot0::Eventtype::FdWrite, __wasi_subscription_u { fd_readwrite: rw }, ), _ => return Err(wasi_snapshot0::Errno::Inval), @@ -114,11 +118,10 @@ impl fmt::Debug for __wasi_subscription_t { .field( "u", match self.type_ { - __WASI_EVENTTYPE_CLOCK => unsafe { &self.u.clock }, - __WASI_EVENTTYPE_FD_READ | __WASI_EVENTTYPE_FD_WRITE => unsafe { + wasi_snapshot0::Eventtype::Clock=> unsafe { &self.u.clock }, + wasi_snapshot0::Eventtype::FdRead | wasi_snapshot0::Eventtype::FdWrite => unsafe { &self.u.fd_readwrite }, - _ => &"INVALID EVENTTYPE", }, ) .finish() @@ -151,19 +154,18 @@ unsafe impl ValueType for __wasi_subscription_t { .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 { + wasi_snapshot0::Eventtype::FdRead | wasi_snapshot0::Eventtype::FdWrite => 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 { + wasi_snapshot0::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)); } @@ -177,13 +179,14 @@ pub enum SubscriptionEnum { 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 => { + wasi_snapshot0::Eventtype::Clock => { + Some(SubscriptionEnum::Clock(unsafe { self.u.clock })) + } + wasi_snapshot0::Eventtype::FdRead | wasi_snapshot0::Eventtype::FdWrite => { Some(SubscriptionEnum::FdReadWrite(unsafe { self.u.fd_readwrite })) } - _ => None, } } } diff --git a/lib/wasi-types/src/versions/snapshot0.rs b/lib/wasi-types/src/versions/snapshot0.rs index cee8ae5d3aa..3872b112c8f 100644 --- a/lib/wasi-types/src/versions/snapshot0.rs +++ b/lib/wasi-types/src/versions/snapshot0.rs @@ -28,7 +28,7 @@ pub union __wasi_subscription_u { #[repr(C)] pub struct __wasi_subscription_t { pub userdata: __wasi_userdata_t, - pub type_: __wasi_eventtype_t, + pub type_: wasi_snapshot0::Eventtype, pub u: __wasi_subscription_u, } @@ -58,19 +58,18 @@ unsafe impl ValueType for __wasi_subscription_t { .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 { + wasi_snapshot0::Eventtype::FdRead | wasi_snapshot0::Eventtype::FdWrite => 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 { + wasi_snapshot0::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)); } @@ -137,11 +136,10 @@ impl fmt::Debug for __wasi_subscription_t { .field( "u", match self.type_ { - __WASI_EVENTTYPE_CLOCK => unsafe { &self.u.clock }, - __WASI_EVENTTYPE_FD_READ | __WASI_EVENTTYPE_FD_WRITE => unsafe { + wasi_snapshot0::Eventtype::Clock => unsafe { &self.u.clock }, + wasi_snapshot0::Eventtype::FdRead | wasi_snapshot0::Eventtype::FdWrite => unsafe { &self.u.fd_readwrite }, - _ => &"INVALID EVENTTYPE", }, ) .finish() diff --git a/lib/wasi/src/syscalls/legacy/snapshot0.rs b/lib/wasi/src/syscalls/legacy/snapshot0.rs index 1fcc773d2d5..8d570c00327 100644 --- a/lib/wasi/src/syscalls/legacy/snapshot0.rs +++ b/lib/wasi/src/syscalls/legacy/snapshot0.rs @@ -148,7 +148,7 @@ pub fn poll_oneoff( 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 { + u: if orig.type_ == wasi_snapshot0::Eventtype::Clock { types::__wasi_subscription_u { clock: types::__wasi_subscription_clock_t { clock_id: unsafe { orig.u.clock.clock_id }, diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 95a833047b6..a7bbd7216d2 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -3276,7 +3276,7 @@ pub fn poll_oneoff( let event = __wasi_event_t { userdata, error: wasi_snapshot0::Errno::Success, - type_: __WASI_EVENTTYPE_CLOCK, + type_: wasi_snapshot0::Eventtype::Clock, u: unsafe { __wasi_event_u { fd_readwrite: __wasi_event_fd_readwrite_t { From 6d53f235b513831b1b453d10b833cd2552ad72eb Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Wed, 17 Aug 2022 15:53:20 +0200 Subject: [PATCH 09/84] Advice --- lib/wasi-types-generated/src/bindings.rs | 41 +++++++++++++++++++ lib/wasi-types-generated/src/lib.rs | 27 ++++++++++++ .../wit/wasi-snapshot0.wit | 37 +++++++++-------- lib/wasi-types/src/advice.rs | 7 ---- lib/wasi-types/src/lib.rs | 2 - lib/wasi/src/syscalls/mod.rs | 2 +- lib/wasi/src/syscalls/wasix32.rs | 2 +- lib/wasi/src/syscalls/wasix64.rs | 2 +- 8 files changed, 90 insertions(+), 30 deletions(-) delete mode 100644 lib/wasi-types/src/advice.rs diff --git a/lib/wasi-types-generated/src/bindings.rs b/lib/wasi-types-generated/src/bindings.rs index 67c37b87316..17623ee1ba5 100644 --- a/lib/wasi-types-generated/src/bindings.rs +++ b/lib/wasi-types-generated/src/bindings.rs @@ -482,6 +482,47 @@ pub mod wasi_snapshot0 { } } } + /// 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_wasmer::bitflags::bitflags! { /// File descriptor flags. pub struct Fdflags: u8 {/// Append mode: Data written to the file is always appended to the file's end. diff --git a/lib/wasi-types-generated/src/lib.rs b/lib/wasi-types-generated/src/lib.rs index 777c3982f85..4faecf1890b 100644 --- a/lib/wasi-types-generated/src/lib.rs +++ b/lib/wasi-types-generated/src/lib.rs @@ -120,3 +120,30 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0: false } } + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0::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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} diff --git a/lib/wasi-types-generated/wit/wasi-snapshot0.wit b/lib/wasi-types-generated/wit/wasi-snapshot0.wit index eb7ff29fb15..2111cbf4872 100644 --- a/lib/wasi-types-generated/wit/wasi-snapshot0.wit +++ b/lib/wasi-types-generated/wit/wasi-snapshot0.wit @@ -360,24 +360,25 @@ enum filetype { // (field $d_type $filetype) // ) // ) -// -// ;;; File or memory access pattern advisory information. -// (typename $advice -// (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 or memory access pattern advisory information. +enum advice { + // TODO: wit appears to not have support for enum type size + //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 { 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/lib.rs b/lib/wasi-types/src/lib.rs index 14f9bff188b..06d13658d01 100644 --- a/lib/wasi-types/src/lib.rs +++ b/lib/wasi-types/src/lib.rs @@ -11,7 +11,6 @@ // Needed for #[derive(ValueType)] extern crate wasmer_types as wasmer; -mod advice; mod bus; mod directory; mod error; @@ -25,7 +24,6 @@ mod time; mod versions; pub use crate::time::*; -pub use advice::*; pub use bus::*; pub use directory::*; pub use error::*; diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index a7bbd7216d2..6b5b079f93c 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -503,7 +503,7 @@ pub fn fd_advise( fd: __wasi_fd_t, offset: __wasi_filesize_t, len: __wasi_filesize_t, - advice: __wasi_advice_t, + advice: wasi_snapshot0::Advice, ) -> wasi_snapshot0::Errno { debug!("wasi::fd_advise: fd={}", fd); diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index 4cb232ed951..82e614f9512 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -61,7 +61,7 @@ pub(crate) fn fd_advise( fd: __wasi_fd_t, offset: __wasi_filesize_t, len: __wasi_filesize_t, - advice: __wasi_advice_t, + advice: wasi_snapshot0::Advice, ) -> wasi_snapshot0::Errno { super::fd_advise(ctx, fd, offset, len, advice) } diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index 60261970ac7..abf04951a73 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -61,7 +61,7 @@ pub(crate) fn fd_advise( fd: __wasi_fd_t, offset: __wasi_filesize_t, len: __wasi_filesize_t, - advice: __wasi_advice_t, + advice: wasi_snapshot0::Advice, ) -> wasi_snapshot0::Errno { super::fd_advise(ctx, fd, offset, len, advice) } From 293c67f64b79936cf0371741ed03a95f548158f4 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Wed, 17 Aug 2022 18:18:20 +0200 Subject: [PATCH 10/84] WIP: Rights --- lib/wasi-types-generated/src/bindings.rs | 22 +- lib/wasi-types-generated/src/lib.rs | 24 ++ .../wit/wasi-snapshot0.wit | 21 + lib/wasi-types/src/file.rs | 113 ++---- lib/wasi/src/state/mod.rs | 192 ++++----- lib/wasi/src/state/socket.rs | 38 +- lib/wasi/src/syscalls/mod.rs | 370 +++++++++++------- lib/wasi/src/syscalls/wasix32.rs | 8 +- lib/wasi/src/syscalls/wasix64.rs | 8 +- 9 files changed, 471 insertions(+), 325 deletions(-) diff --git a/lib/wasi-types-generated/src/bindings.rs b/lib/wasi-types-generated/src/bindings.rs index 17623ee1ba5..defcd3c4ba6 100644 --- a/lib/wasi-types-generated/src/bindings.rs +++ b/lib/wasi-types-generated/src/bindings.rs @@ -345,7 +345,7 @@ pub mod wasi_snapshot0 { impl std::error::Error for Errno{} wit_bindgen_wasmer::bitflags::bitflags! { /// File descriptor rights, determining which actions may be performed. - pub struct Rights: u32 {/// The right to invoke `fd_datasync`. + 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`. @@ -418,6 +418,26 @@ pub mod wasi_snapshot0 { const POLL_FD_READWRITE = 1 << 27; /// The right to invoke `sock_shutdown`. const SOCK_SHUTDOWN = 1 << 28; + /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 + const SOCK_ACCEPT = 1 << 29; + /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 + const SOCK_CONNECT = 1 << 30; + /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 + const SOCK_LISTEN = 1 << 31; + /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 + const SOCK_BIND = 1 << 32; + /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 + const SOCK_RECV = 1 << 33; + /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 + const SOCK_SEND = 1 << 34; + /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 + const SOCK_ADDR_LOCAL = 1 << 35; + /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 + const SOCK_ADDR_REMOTE = 1 << 36; + /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 + const SOCK_RECV_FROM = 1 << 37; + /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 + const SOCK_SEND_TO = 1 << 38; } } diff --git a/lib/wasi-types-generated/src/lib.rs b/lib/wasi-types-generated/src/lib.rs index 4faecf1890b..eadf46b277b 100644 --- a/lib/wasi-types-generated/src/lib.rs +++ b/lib/wasi-types-generated/src/lib.rs @@ -23,6 +23,12 @@ unsafe impl ValueType for wasi_snapshot0::Eventtype { fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for wasi_snapshot0::Rights { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + // TODO: if necessary, must be implemented in wit-bindgen unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0::Errno { type Native = i32; @@ -147,3 +153,21 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0: false } } + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0::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) + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} diff --git a/lib/wasi-types-generated/wit/wasi-snapshot0.wit b/lib/wasi-types-generated/wit/wasi-snapshot0.wit index 2111cbf4872..95f9ffb89fa 100644 --- a/lib/wasi-types-generated/wit/wasi-snapshot0.wit +++ b/lib/wasi-types-generated/wit/wasi-snapshot0.wit @@ -273,6 +273,27 @@ flags rights { poll-fd-readwrite, /// The right to invoke `sock_shutdown`. sock-shutdown, + + /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 + sock-accept, + /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 + sock-connect, + /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 + sock-listen, + /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 + sock-bind, + /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 + sock-recv, + /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 + sock-send, + /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 + sock-addr-local, + /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 + sock-addr-remote, + /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 + sock-recv-from, + /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 + sock-send-to, } // ;;; A file descriptor handle. diff --git a/lib/wasi-types/src/file.rs b/lib/wasi-types/src/file.rs index f95445f22fc..ea26e23aa2c 100644 --- a/lib/wasi-types/src/file.rs +++ b/lib/wasi-types/src/file.rs @@ -5,7 +5,7 @@ use std::{ }; use wasmer_derive::ValueType; use wasmer_types::ValueType; -use wasmer_wasi_types_generated::wasi_snapshot0; +use wasmer_wasi_types_generated::{wasi_filesystem, wasi_snapshot0}; pub type __wasi_device_t = u64; @@ -122,8 +122,8 @@ unsafe impl ValueType for __wasi_prestat_t { pub struct __wasi_fdstat_t { pub fs_filetype: wasi_snapshot0::Filetype, pub fs_flags: __wasi_fdflags_t, - pub fs_rights_base: __wasi_rights_t, - pub fs_rights_inheriting: __wasi_rights_t, + pub fs_rights_base: wasi_snapshot0::Rights, + pub fs_rights_inheriting: wasi_snapshot0::Rights, } pub type __wasi_filedelta_t = i64; @@ -225,55 +225,14 @@ 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) { +pub fn print_right_set(rights: wasi_snapshot0::Rights) { // 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 { + let cur_right = rights & wasi_snapshot0::Rights::from_bits(1 << i).unwrap(); + if !cur_right.is_empty() { right_set.insert(right_to_string(cur_right).unwrap_or("INVALID RIGHT")); } } @@ -281,37 +240,37 @@ pub fn print_right_set(rights: __wasi_rights_t) { } /// 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> { +pub fn right_to_string(right: wasi_snapshot0::Rights) -> 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", + wasi_snapshot0::Rights::FD_DATASYNC => "Rights::_FD_DATASYNC", + wasi_snapshot0::Rights::FD_READ => "Rights::FD_READ", + wasi_snapshot0::Rights::FD_SEEK => "Rights::FD_SEEK", + wasi_snapshot0::Rights::FD_FDSTAT_SET_FLAGS => "Rights::FD_FDSTAT_SET_FLAGS", + wasi_snapshot0::Rights::FD_SYNC => "Rights::FD_SYNC", + wasi_snapshot0::Rights::FD_TELL => "Rights::FD_TELL", + wasi_snapshot0::Rights::FD_WRITE => "Rights::FD_WRITE", + wasi_snapshot0::Rights::FD_ADVISE => "Rights::FD_ADVISE", + wasi_snapshot0::Rights::FD_ALLOCATE => "Rights::FD_ALLOCATE", + wasi_snapshot0::Rights::PATH_CREATE_DIRECTORY => "Rights::PATH_CREATE_DIRECTORY", + wasi_snapshot0::Rights::PATH_CREATE_FILE => "Rights::PATH_CREATE_FILE", + wasi_snapshot0::Rights::PATH_LINK_SOURCE => "Rights::PATH_LINK_SOURCE", + wasi_snapshot0::Rights::PATH_LINK_TARGET => "Rights::PATH_LINK_TARGET", + wasi_snapshot0::Rights::PATH_OPEN => "Rights::PATH_OPEN", + wasi_snapshot0::Rights::FD_READDIR => "Rights::FD_READDIR", + wasi_snapshot0::Rights::PATH_READLINK => "Rights::PATH_READLINK", + wasi_snapshot0::Rights::PATH_RENAME_SOURCE => "Rights::PATH_RENAME_SOURCE", + wasi_snapshot0::Rights::PATH_RENAME_TARGET => "Rights::PATH_RENAME_TARGET", + wasi_snapshot0::Rights::PATH_FILESTAT_GET => "Rights::PATH_FILESTAT_GET", + wasi_snapshot0::Rights::PATH_FILESTAT_SET_SIZE => "Rights::PATH_FILESTAT_SET_SIZE", + wasi_snapshot0::Rights::PATH_FILESTAT_SET_TIMES => "Rights::PATH_FILESTAT_SET_TIMES", + wasi_snapshot0::Rights::FD_FILESTAT_GET => "Rights::FD_FILESTAT_GET", + wasi_snapshot0::Rights::FD_FILESTAT_SET_SIZE => "Rights::FD_FILESTAT_SET_SIZE", + wasi_snapshot0::Rights::FD_FILESTAT_SET_TIMES => "Rights::FD_FILESTAT_SET_TIMES", + wasi_snapshot0::Rights::PATH_SYMLINK => "Rights::PATH_SYMLINK", + wasi_snapshot0::Rights::PATH_UNLINK_FILE => "Rights::PATH_UNLINK_FILE", + wasi_snapshot0::Rights::PATH_REMOVE_DIRECTORY => "Rights::PATH_REMOVE_DIRECTORY", + wasi_snapshot0::Rights::POLL_FD_READWRITE => "Rights::POLL_FD_READWRITE", + wasi_snapshot0::Rights::SOCK_SHUTDOWN => "Rights::SOCK_SHUTDOWN", _ => return None, }) } diff --git a/lib/wasi/src/state/mod.rs b/lib/wasi/src/state/mod.rs index ad20eed8f25..76b6bb1e8ec 100644 --- a/lib/wasi/src/state/mod.rs +++ b/lib/wasi/src/state/mod.rs @@ -59,20 +59,33 @@ use wasmer_vfs::{FileSystem, FsError, OpenOptions, VirtualFile}; /// the fd value of the virtual root pub const VIRTUAL_ROOT_FD: __wasi_fd_t = 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: wasi_snapshot0::Rights = wasi_snapshot0::Rights::all(); +const STDIN_DEFAULT_RIGHTS: wasi_snapshot0::Rights = { + // This might seem a bit overenineered, but it's the only way I + // discovered for getting the values in a const environment + wasi_snapshot0::Rights::from_bits_truncate( + wasi_snapshot0::Rights::FD_DATASYNC.bits() + | wasi_snapshot0::Rights::FD_READ.bits() + | wasi_snapshot0::Rights::FD_SYNC.bits() + | wasi_snapshot0::Rights::FD_ADVISE.bits() + | wasi_snapshot0::Rights::FD_FILESTAT_GET.bits() + | wasi_snapshot0::Rights::POLL_FD_READWRITE.bits(), + ) +}; +const STDOUT_DEFAULT_RIGHTS: wasi_snapshot0::Rights = { + // Not sure it is possible to use the bitflags consts directly in a + // const environment, found no way to do so, therefore the flags are + // duplicated below. + wasi_snapshot0::Rights::from_bits_truncate( + wasi_snapshot0::Rights::FD_DATASYNC.bits() + | wasi_snapshot0::Rights::FD_SYNC.bits() + | wasi_snapshot0::Rights::FD_WRITE.bits() + | wasi_snapshot0::Rights::FD_ADVISE.bits() + | wasi_snapshot0::Rights::FD_FILESTAT_GET.bits() + | wasi_snapshot0::Rights::POLL_FD_READWRITE.bits(), + ) +}; +const STDERR_DEFAULT_RIGHTS: wasi_snapshot0::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 @@ -173,8 +186,8 @@ 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 rights: wasi_snapshot0::Rights, + pub rights_inheriting: wasi_snapshot0::Rights, pub flags: __wasi_fdflags_t, pub offset: u64, /// Flags that determine how the [`Fd`] can be used. @@ -409,19 +422,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 = wasi_snapshot0::Rights::FD_ADVISE + | wasi_snapshot0::Rights::FD_TELL + | wasi_snapshot0::Rights::FD_SEEK + | wasi_snapshot0::Rights::FD_READ + | wasi_snapshot0::Rights::PATH_OPEN + | wasi_snapshot0::Rights::FD_READDIR + | wasi_snapshot0::Rights::PATH_READLINK + | wasi_snapshot0::Rights::PATH_FILESTAT_GET + | wasi_snapshot0::Rights::FD_FILESTAT_GET + | wasi_snapshot0::Rights::PATH_LINK_SOURCE + | wasi_snapshot0::Rights::PATH_RENAME_SOURCE + | wasi_snapshot0::Rights::POLL_FD_READWRITE + | wasi_snapshot0::Rights::SOCK_SHUTDOWN; let inode = wasi_fs .create_inode(inodes, kind, true, preopen_name.clone()) .map_err(|e| { @@ -483,44 +496,45 @@ 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 = wasi_snapshot0::Rights::FD_ADVISE + | wasi_snapshot0::Rights::FD_TELL + | wasi_snapshot0::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 |= wasi_snapshot0::Rights::FD_READ + | wasi_snapshot0::Rights::PATH_OPEN + | wasi_snapshot0::Rights::FD_READDIR + | wasi_snapshot0::Rights::PATH_READLINK + | wasi_snapshot0::Rights::PATH_FILESTAT_GET + | wasi_snapshot0::Rights::FD_FILESTAT_GET + | wasi_snapshot0::Rights::PATH_LINK_SOURCE + | wasi_snapshot0::Rights::PATH_RENAME_SOURCE + | wasi_snapshot0::Rights::POLL_FD_READWRITE + | wasi_snapshot0::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 |= wasi_snapshot0::Rights::FD_DATASYNC + | wasi_snapshot0::Rights::FD_FDSTAT_SET_FLAGS + | wasi_snapshot0::Rights::FD_WRITE + | wasi_snapshot0::Rights::FD_SYNC + | wasi_snapshot0::Rights::FD_ALLOCATE + | wasi_snapshot0::Rights::PATH_OPEN + | wasi_snapshot0::Rights::PATH_RENAME_TARGET + | wasi_snapshot0::Rights::PATH_FILESTAT_SET_SIZE + | wasi_snapshot0::Rights::PATH_FILESTAT_SET_TIMES + | wasi_snapshot0::Rights::FD_FILESTAT_SET_SIZE + | wasi_snapshot0::Rights::FD_FILESTAT_SET_TIMES + | wasi_snapshot0::Rights::PATH_REMOVE_DIRECTORY + | wasi_snapshot0::Rights::PATH_UNLINK_FILE + | wasi_snapshot0::Rights::POLL_FD_READWRITE + | wasi_snapshot0::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 |= wasi_snapshot0::Rights::PATH_CREATE_DIRECTORY + | wasi_snapshot0::Rights::PATH_CREATE_FILE + | wasi_snapshot0::Rights::PATH_LINK_TARGET + | wasi_snapshot0::Rights::PATH_OPEN + | wasi_snapshot0::Rights::PATH_RENAME_TARGET + | wasi_snapshot0::Rights::PATH_SYMLINK; } rights @@ -601,20 +615,22 @@ 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)*/; + /* + & (!wasi_snapshot0::Rights::FD_WRITE) + & (!wasi_snapshot0::Rights::FD_ALLOCATE) + & (!wasi_snapshot0::Rights::PATH_CREATE_DIRECTORY) + & (!wasi_snapshot0::Rights::PATH_CREATE_FILE) + & (!wasi_snapshot0::Rights::PATH_LINK_SOURCE) + & (!wasi_snapshot0::Rights::PATH_RENAME_SOURCE) + & (!wasi_snapshot0::Rights::PATH_RENAME_TARGET) + & (!wasi_snapshot0::Rights::PATH_FILESTAT_SET_SIZE) + & (!wasi_snapshot0::Rights::PATH_FILESTAT_SET_TIMES) + & (!wasi_snapshot0::Rights::FD_FILESTAT_SET_SIZE) + & (!wasi_snapshot0::Rights::FD_FILESTAT_SET_TIMES) + & (!wasi_snapshot0::Rights::PATH_SYMLINK) + & (!wasi_snapshot0::Rights::PATH_UNLINK_FILE) + & (!wasi_snapshot0::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) @@ -646,8 +662,8 @@ impl WasiFs { inodes: &mut WasiInodes, base: __wasi_fd_t, name: String, - rights: __wasi_rights_t, - rights_inheriting: __wasi_rights_t, + rights: wasi_snapshot0::Rights, + rights_inheriting: wasi_snapshot0::Rights, flags: __wasi_fdflags_t, ) -> Result<__wasi_fd_t, FsError> { // TODO: check permissions here? probably not, but this should be @@ -723,8 +739,8 @@ impl WasiFs { file: Box, open_flags: u16, name: String, - rights: __wasi_rights_t, - rights_inheriting: __wasi_rights_t, + rights: wasi_snapshot0::Rights, + rights_inheriting: wasi_snapshot0::Rights, flags: __wasi_fdflags_t, ) -> Result<__wasi_fd_t, FsError> { // TODO: check permissions here? probably not, but this should be @@ -1327,7 +1343,7 @@ impl WasiFs { fs_filetype: wasi_snapshot0::Filetype::CharacterDevice, fs_flags: 0, fs_rights_base: STDIN_DEFAULT_RIGHTS, - fs_rights_inheriting: 0, + fs_rights_inheriting: wasi_snapshot0::Rights::empty(), }) } __WASI_STDOUT_FILENO => { @@ -1335,7 +1351,7 @@ impl WasiFs { fs_filetype: wasi_snapshot0::Filetype::CharacterDevice, fs_flags: __WASI_FDFLAG_APPEND, fs_rights_base: STDOUT_DEFAULT_RIGHTS, - fs_rights_inheriting: 0, + fs_rights_inheriting: wasi_snapshot0::Rights::empty(), }) } __WASI_STDERR_FILENO => { @@ -1343,7 +1359,7 @@ impl WasiFs { fs_filetype: wasi_snapshot0::Filetype::CharacterDevice, fs_flags: __WASI_FDFLAG_APPEND, fs_rights_base: STDERR_DEFAULT_RIGHTS, - fs_rights_inheriting: 0, + fs_rights_inheriting: wasi_snapshot0::Rights::empty(), }) } VIRTUAL_ROOT_FD => { @@ -1420,7 +1436,7 @@ impl WasiFs { .ok_or(wasi_snapshot0::Errno::Io)?, _ => { let fd = self.get_fd(fd)?; - if fd.rights & __WASI_RIGHT_FD_DATASYNC == 0 { + if !fd.rights.contains(wasi_snapshot0::Rights::FD_DATASYNC) { return Err(wasi_snapshot0::Errno::Acces); } @@ -1486,8 +1502,8 @@ impl WasiFs { pub fn create_fd( &self, - rights: __wasi_rights_t, - rights_inheriting: __wasi_rights_t, + rights: wasi_snapshot0::Rights, + rights_inheriting: wasi_snapshot0::Rights, flags: __wasi_fdflags_t, open_flags: u16, inode: Inode, @@ -1591,7 +1607,7 @@ impl WasiFs { handle: Box, name: &'static str, raw_fd: __wasi_fd_t, - rights: __wasi_rights_t, + rights: wasi_snapshot0::Rights, fd_flags: __wasi_fdflags_t, ) { let stat = __wasi_filestat_t { @@ -1616,7 +1632,7 @@ impl WasiFs { raw_fd, Fd { rights, - rights_inheriting: 0, + rights_inheriting: wasi_snapshot0::Rights::empty(), flags: fd_flags, // since we're not calling open on this, we don't need open flags open_flags: 0, diff --git a/lib/wasi/src/state/socket.rs b/lib/wasi/src/state/socket.rs index a31e402eb86..6a14837b699 100644 --- a/lib/wasi/src/state/socket.rs +++ b/lib/wasi/src/state/socket.rs @@ -1489,21 +1489,25 @@ pub(crate) fn write_route( 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 +pub(crate) const fn all_socket_rights() -> wasi_snapshot0::Rights { + // This might seem a bit overenineered, but it's the only way I + // discovered for getting the values in a const environment + wasi_snapshot0::Rights::from_bits_truncate( + wasi_snapshot0::Rights::FD_FDSTAT_SET_FLAGS.bits() + | wasi_snapshot0::Rights::FD_FILESTAT_GET.bits() + | wasi_snapshot0::Rights::FD_READ.bits() + | wasi_snapshot0::Rights::FD_WRITE.bits() + | wasi_snapshot0::Rights::POLL_FD_READWRITE.bits() + | wasi_snapshot0::Rights::SOCK_SHUTDOWN.bits() + | wasi_snapshot0::Rights::SOCK_CONNECT.bits() + | wasi_snapshot0::Rights::SOCK_LISTEN.bits() + | wasi_snapshot0::Rights::SOCK_BIND.bits() + | wasi_snapshot0::Rights::SOCK_ACCEPT.bits() + | wasi_snapshot0::Rights::SOCK_RECV.bits() + | wasi_snapshot0::Rights::SOCK_SEND.bits() + | wasi_snapshot0::Rights::SOCK_ADDR_LOCAL.bits() + | wasi_snapshot0::Rights::SOCK_ADDR_REMOTE.bits() + | wasi_snapshot0::Rights::SOCK_RECV_FROM.bits() + | wasi_snapshot0::Rights::SOCK_SEND_TO.bits(), + ) } diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 6b5b079f93c..053078494b1 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -143,15 +143,10 @@ 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, + rights: wasi_snapshot0::Rights, actor: F, ) -> Result where @@ -162,7 +157,7 @@ where let fd_entry = state.fs.get_fd(sock)?; let ret = { - if rights != 0 && !has_rights(fd_entry.rights, rights) { + if !rights.is_empty() && !fd_entry.rights.contains(rights) { return Err(wasi_snapshot0::Errno::Acces); } @@ -185,7 +180,7 @@ where fn __sock_actor_mut( ctx: &FunctionEnvMut<'_, WasiEnv>, sock: __wasi_fd_t, - rights: __wasi_rights_t, + rights: wasi_snapshot0::Rights, actor: F, ) -> Result where @@ -196,7 +191,7 @@ where let fd_entry = state.fs.get_fd(sock)?; let ret = { - if rights != 0 && !has_rights(fd_entry.rights, rights) { + if !rights.is_empty() && !fd_entry.rights.contains(rights) { return Err(wasi_snapshot0::Errno::Acces); } @@ -219,7 +214,7 @@ where fn __sock_upgrade( ctx: &FunctionEnvMut<'_, WasiEnv>, sock: __wasi_fd_t, - rights: __wasi_rights_t, + rights: wasi_snapshot0::Rights, actor: F, ) -> Result<(), wasi_snapshot0::Errno> where @@ -231,7 +226,7 @@ where 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) { + if !rights.is_empty() && !fd_entry.rights.contains(rights) { return Err(wasi_snapshot0::Errno::Acces); } @@ -533,7 +528,10 @@ pub fn fd_allocate( 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) { + if !fd_entry + .rights + .contains(wasi_snapshot0::Rights::FD_ALLOCATE) + { return wasi_snapshot0::Errno::Acces; } let new_size = wasi_try!(offset.checked_add(len).ok_or(wasi_snapshot0::Errno::Inval)); @@ -596,7 +594,10 @@ pub fn fd_datasync(ctx: FunctionEnvMut<'_, WasiEnv>, fd: __wasi_fd_t) -> wasi_sn 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) { + if !fd_entry + .rights + .contains(wasi_snapshot0::Rights::FD_DATASYNC) + { return wasi_snapshot0::Errno::Acces; } @@ -654,7 +655,10 @@ pub fn fd_fdstat_set_flags( let mut fd_map = state.fs.fd_map.write().unwrap(); let fd_entry = wasi_try!(fd_map.get_mut(&fd).ok_or(wasi_snapshot0::Errno::Badf)); - if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_FDSTAT_SET_FLAGS) { + if !fd_entry + .rights + .contains(wasi_snapshot0::Rights::FD_FDSTAT_SET_FLAGS) + { return wasi_snapshot0::Errno::Acces; } @@ -667,15 +671,15 @@ pub fn fd_fdstat_set_flags( /// Inputs: /// - `__wasi_fd_t fd` /// The file descriptor to apply the new rights to -/// - `__wasi_rights_t fs_rights_base` +/// - `wasi_snapshot0::Rights fs_rights_base` /// The rights to apply to `fd` -/// - `__wasi_rights_t fs_rights_inheriting` +/// - `wasi_snapshot0::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, + fs_rights_base: wasi_snapshot0::Rights, + fs_rights_inheriting: wasi_snapshot0::Rights, ) -> wasi_snapshot0::Errno { debug!("wasi::fd_fdstat_set_rights"); let env = ctx.data(); @@ -713,7 +717,10 @@ pub fn 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) { + if !fd_entry + .rights + .contains(wasi_snapshot0::Rights::FD_FILESTAT_GET) + { return wasi_snapshot0::Errno::Acces; } @@ -743,7 +750,10 @@ pub fn fd_filestat_set_size( 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) { + if !fd_entry + .rights + .contains(wasi_snapshot0::Rights::FD_FILESTAT_SET_SIZE) + { return wasi_snapshot0::Errno::Acces; } @@ -794,7 +804,10 @@ pub fn fd_filestat_set_times( 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) { + if !fd_entry + .rights + .contains(wasi_snapshot0::Rights::FD_FILESTAT_SET_TIMES) + { return wasi_snapshot0::Errno::Acces; } @@ -879,8 +892,9 @@ pub fn fd_pread( _ => { 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(wasi_snapshot0::Rights::FD_READ | wasi_snapshot0::Rights::FD_SEEK) { debug!( "Invalid rights on {:X}: expected READ and SEEK", @@ -1065,8 +1079,9 @@ pub fn fd_pwrite( } } _ => { - if !(has_rights(fd_entry.rights, __WASI_RIGHT_FD_WRITE) - && has_rights(fd_entry.rights, __WASI_RIGHT_FD_SEEK)) + if !fd_entry + .rights + .contains(wasi_snapshot0::Rights::FD_WRITE | wasi_snapshot0::Rights::FD_SEEK) { return Ok(wasi_snapshot0::Errno::Acces); } @@ -1164,7 +1179,7 @@ pub fn fd_read( } __WASI_STDOUT_FILENO | __WASI_STDERR_FILENO => return Ok(wasi_snapshot0::Errno::Inval), _ => { - if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_READ) { + if !fd_entry.rights.contains(wasi_snapshot0::Rights::FD_READ) { // TODO: figure out the error to return when lacking rights return Ok(wasi_snapshot0::Errno::Acces); } @@ -1502,7 +1517,9 @@ pub fn fd_event( false, "event".to_string(), ); - let rights = __WASI_RIGHT_FD_READ | __WASI_RIGHT_FD_WRITE | __WASI_RIGHT_POLL_FD_READWRITE; + let rights = wasi_snapshot0::Rights::FD_READ + | wasi_snapshot0::Rights::FD_WRITE + | wasi_snapshot0::Rights::POLL_FD_READWRITE; let fd = wasi_try!(state.fs.create_fd(rights, rights, 0, 0, inode)); wasi_try_mem!(ret_fd.write(&memory, fd)); @@ -1535,7 +1552,7 @@ pub fn fd_seek( 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) { + if !fd_entry.rights.contains(wasi_snapshot0::Rights::FD_SEEK) { return Ok(wasi_snapshot0::Errno::Acces); } @@ -1614,7 +1631,7 @@ pub fn fd_sync(ctx: FunctionEnvMut<'_, WasiEnv>, fd: __wasi_fd_t) -> wasi_snapsh 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) { + if !fd_entry.rights.contains(wasi_snapshot0::Rights::FD_SYNC) { return wasi_snapshot0::Errno::Acces; } let inode = fd_entry.inode; @@ -1663,7 +1680,7 @@ pub fn fd_tell( let fd_entry = wasi_try!(state.fs.get_fd(fd)); - if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_TELL) { + if !fd_entry.rights.contains(wasi_snapshot0::Rights::FD_TELL) { return wasi_snapshot0::Errno::Acces; } @@ -1729,7 +1746,7 @@ pub fn fd_write( } } _ => { - if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_WRITE) { + if !fd_entry.rights.contains(wasi_snapshot0::Rights::FD_WRITE) { return Ok(wasi_snapshot0::Errno::Acces); } @@ -1866,7 +1883,7 @@ pub fn fd_pipe( /// The length of `path` /// Errors: /// Required Rights: -/// - __WASI_RIGHT_PATH_CREATE_DIRECTORY +/// - wasi_snapshot0::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>, @@ -1885,7 +1902,10 @@ pub fn path_create_directory( return wasi_snapshot0::Errno::Acces; } } - if !has_rights(working_dir.rights, __WASI_RIGHT_PATH_CREATE_DIRECTORY) { + if !working_dir + .rights + .contains(wasi_snapshot0::Rights::PATH_CREATE_DIRECTORY) + { return wasi_snapshot0::Errno::Acces; } let path_string = unsafe { get_input_str!(&memory, path, path_len) }; @@ -2049,7 +2069,10 @@ pub fn path_filestat_get_internal( ) -> Result<__wasi_filestat_t, wasi_snapshot0::Errno> { let root_dir = state.fs.get_fd(fd)?; - if !has_rights(root_dir.rights, __WASI_RIGHT_PATH_FILESTAT_GET) { + if !root_dir + .rights + .contains(wasi_snapshot0::Rights::PATH_FILESTAT_GET) + { return Err(wasi_snapshot0::Errno::Acces); } debug!("=> base_fd: {}, path: {}", fd, path_string); @@ -2100,7 +2123,10 @@ pub fn path_filestat_set_times( 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) { + if !fd_entry + .rights + .contains(wasi_snapshot0::Rights::PATH_FILESTAT_SET_TIMES) + { return wasi_snapshot0::Errno::Acces; } if (fst_flags & __WASI_FILESTAT_SET_ATIM != 0 && fst_flags & __WASI_FILESTAT_SET_ATIM_NOW != 0) @@ -2188,8 +2214,12 @@ 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(wasi_snapshot0::Rights::PATH_LINK_SOURCE) + || !target_fd + .rights + .contains(wasi_snapshot0::Rights::PATH_LINK_TARGET) { return wasi_snapshot0::Errno::Acces; } @@ -2249,9 +2279,9 @@ pub fn path_link( /// The length of the `path` string /// - `__wasi_oflags_t o_flags` /// How the file will be opened -/// - `__wasi_rights_t fs_rights_base` +/// - `wasi_snapshot0::Rights fs_rights_base` /// The rights of the created file descriptor -/// - `__wasi_rights_t fs_rightsinheriting` +/// - `wasi_snapshot0::Rights fs_rightsinheriting` /// The rights of file descriptors derived from the created file descriptor /// - `__wasi_fdflags_t fs_flags` /// The flags of the file descriptor @@ -2259,7 +2289,7 @@ pub fn path_link( /// - `__wasi_fd_t* fd` /// The new file descriptor /// Possible Errors: -/// - `wasi_snapshot0::Errno::Acces`, `__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` +/// - `wasi_snapshot0::Errno::Acces`, `wasi_snapshot0::Errno::Badf`, `wasi_snapshot0::Errno::Fault`, `wasi_snapshot0::Errno::Toobig?`, `wasi_snapshot0::Errno::Inval`, `wasi_snapshot0::Errno::Io`, `wasi_snapshot0::Errno::Loop`, `wasi_snapshot0::Errno::Mfile`, `wasi_snapshot0::Errno::Nametoolong?`, `wasi_snapshot0::Errno::Nfile`, `wasi_snapshot0::Errno::Noent`, `wasi_snapshot0::Errno::Notdir`, `wasi_snapshot0::Errno::Rofs`, and `wasi_snapshot0::Errno::Notcapable` pub fn path_open( ctx: FunctionEnvMut<'_, WasiEnv>, dirfd: __wasi_fd_t, @@ -2267,8 +2297,8 @@ pub fn path_open( path: WasmPtr, path_len: M::Offset, o_flags: __wasi_oflags_t, - fs_rights_base: __wasi_rights_t, - fs_rights_inheriting: __wasi_rights_t, + fs_rights_base: wasi_snapshot0::Rights, + fs_rights_inheriting: wasi_snapshot0::Rights, fs_flags: __wasi_fdflags_t, fd: WasmPtr<__wasi_fd_t, M>, ) -> wasi_snapshot0::Errno { @@ -2296,7 +2326,10 @@ 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) { + if !working_dir + .rights + .contains(wasi_snapshot0::Rights::PATH_OPEN) + { return wasi_snapshot0::Errno::Acces; } let path_string = unsafe { get_input_str!(&memory, path, path_len) }; @@ -2340,7 +2373,7 @@ pub fn path_open( return wasi_snapshot0::Errno::Exist; } - let write_permission = adjusted_rights & __WASI_RIGHT_FD_WRITE != 0; + let write_permission = adjusted_rights.contains(wasi_snapshot0::Rights::FD_WRITE); // append, truncate, and create all require the permission to write let (append_permission, truncate_permission, create_permission) = if write_permission { @@ -2360,7 +2393,7 @@ 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(wasi_snapshot0::Rights::FD_WRITE) { open_flags |= Fd::WRITE; } if o_flags & __WASI_O_CREAT != 0 { @@ -2519,7 +2552,10 @@ pub fn path_readlink( 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) { + if !base_dir + .rights + .contains(wasi_snapshot0::Rights::PATH_READLINK) + { return wasi_snapshot0::Errno::Acces; } let path_str = unsafe { get_input_str!(&memory, path, path_len) }; @@ -2669,11 +2705,17 @@ 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) { + if !source_fd + .rights + .contains(wasi_snapshot0::Rights::PATH_RENAME_SOURCE) + { return wasi_snapshot0::Errno::Acces; } let target_fd = wasi_try!(state.fs.get_fd(new_fd)); - if !has_rights(target_fd.rights, __WASI_RIGHT_PATH_RENAME_TARGET) { + if !target_fd + .rights + .contains(wasi_snapshot0::Rights::PATH_RENAME_TARGET) + { return wasi_snapshot0::Errno::Acces; } } @@ -2847,7 +2889,10 @@ pub fn path_symlink( 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) { + if !base_fd + .rights + .contains(wasi_snapshot0::Rights::PATH_SYMLINK) + { return wasi_snapshot0::Errno::Acces; } @@ -2945,7 +2990,10 @@ pub fn path_unlink_file( 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) { + if !base_dir + .rights + .contains(wasi_snapshot0::Rights::PATH_UNLINK_FILE) + { return wasi_snapshot0::Errno::Acces; } let path_str = unsafe { get_input_str!(&memory, path, path_len) }; @@ -3081,7 +3129,7 @@ pub fn poll_oneoff( __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) { + if !fd_entry.rights.contains(wasi_snapshot0::Rights::FD_READ) { return Ok(wasi_snapshot0::Errno::Acces); } } @@ -3094,7 +3142,7 @@ pub fn poll_oneoff( __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) { + if !fd_entry.rights.contains(wasi_snapshot0::Rights::FD_WRITE) { return Ok(wasi_snapshot0::Errno::Acces); } } @@ -3146,7 +3194,10 @@ 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) { + if !fd_entry + .rights + .contains(wasi_snapshot0::Rights::POLL_FD_READWRITE) + { return Ok(wasi_snapshot0::Errno::Acces); } @@ -4332,9 +4383,12 @@ pub fn http_status( let memory = env.memory_view(&ctx); let ref_status = status.deref(&memory); - let http_status = wasi_try!(__sock_actor(&ctx, sock, 0, |socket| { - socket.http_status() - })); + let http_status = wasi_try!(__sock_actor( + &ctx, + sock, + wasi_snapshot0::Rights::empty(), + |socket| { socket.http_status() } + )); // Write everything else and return the status to the caller let status = __wasi_http_status_t { @@ -4663,7 +4717,7 @@ pub fn sock_shutdown( wasi_try!(__sock_actor_mut( &ctx, sock, - __WASI_RIGHT_SOCK_SHUTDOWN, + wasi_snapshot0::Rights::SOCK_SHUTDOWN, |socket| { socket.shutdown(how) } )); @@ -4679,7 +4733,12 @@ pub fn sock_status( ) -> wasi_snapshot0::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, + wasi_snapshot0::Rights::empty(), + |socket| { socket.status() } + )); use super::state::WasiSocketStatus; let status = match status { @@ -4714,9 +4773,12 @@ pub fn sock_addr_local( ) -> wasi_snapshot0::Errno { debug!("wasi::sock_addr_local"); - let addr = wasi_try!(__sock_actor(&ctx, sock, 0, |socket| { - socket.addr_local() - })); + let addr = wasi_try!(__sock_actor( + &ctx, + sock, + wasi_snapshot0::Rights::empty(), + |socket| { socket.addr_local() } + )); let memory = ctx.data().memory_view(&ctx); wasi_try!(super::state::write_ip_port( &memory, @@ -4746,7 +4808,12 @@ pub fn sock_addr_peer( 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, + wasi_snapshot0::Rights::empty(), + |socket| { socket.addr_peer() } + )); let memory = env.memory_view(&ctx); wasi_try!(super::state::write_ip_port( &memory, @@ -4847,9 +4914,12 @@ pub fn sock_set_opt_flag( }; let option: super::state::WasiSocketOption = opt.into(); - wasi_try!(__sock_actor_mut(&ctx, sock, 0, |socket| { - socket.set_opt_flag(option, flag) - })); + wasi_try!(__sock_actor_mut( + &ctx, + sock, + wasi_snapshot0::Rights::empty(), + |socket| { socket.set_opt_flag(option, flag) } + )); wasi_snapshot0::Errno::Success } @@ -4872,9 +4942,12 @@ pub fn sock_get_opt_flag( let memory = env.memory_view(&ctx); let option: super::state::WasiSocketOption = opt.into(); - let flag = wasi_try!(__sock_actor(&ctx, sock, 0, |socket| { - socket.get_opt_flag(option) - })); + let flag = wasi_try!(__sock_actor( + &ctx, + sock, + wasi_snapshot0::Rights::empty(), + |socket| { socket.get_opt_flag(option) } + )); let flag = match flag { false => __WASI_BOOL_FALSE, true => __WASI_BOOL_TRUE, @@ -4920,9 +4993,12 @@ pub fn sock_set_opt_time( }; let option: super::state::WasiSocketOption = opt.into(); - wasi_try!(__sock_actor_mut(&ctx, sock, 0, |socket| { - socket.set_opt_time(ty, time) - })); + wasi_try!(__sock_actor_mut( + &ctx, + sock, + wasi_snapshot0::Rights::empty(), + |socket| { socket.set_opt_time(ty, time) } + )); wasi_snapshot0::Errno::Success } @@ -4952,9 +5028,12 @@ pub fn sock_get_opt_time( _ => return wasi_snapshot0::Errno::Inval, }; - let time = wasi_try!(__sock_actor(&ctx, sock, 0, |socket| { - socket.opt_time(ty) - })); + let time = wasi_try!(__sock_actor( + &ctx, + sock, + wasi_snapshot0::Rights::empty(), + |socket| { socket.opt_time(ty) } + )); let time = match time { None => __wasi_option_timestamp_t { tag: __WASI_OPTION_NONE, @@ -4998,15 +5077,20 @@ pub fn sock_set_opt_size( }; let option: super::state::WasiSocketOption = opt.into(); - wasi_try!(__sock_actor_mut(&ctx, sock, 0, |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_snapshot0::Errno::Inval), + wasi_try!(__sock_actor_mut( + &ctx, + sock, + wasi_snapshot0::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_snapshot0::Errno::Inval), + } } - })); + )); wasi_snapshot0::Errno::Success } @@ -5028,21 +5112,26 @@ pub fn sock_get_opt_size( let env = ctx.data(); let memory = env.memory_view(&ctx); - let size = wasi_try!(__sock_actor(&ctx, sock, 0, |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) + let size = wasi_try!(__sock_actor( + &ctx, + sock, + wasi_snapshot0::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_snapshot0::Errno::Inval), } - _ => Err(wasi_snapshot0::Errno::Inval), } - })); + )); wasi_try_mem!(ret_size.write(&memory, size)); wasi_snapshot0::Errno::Success @@ -5068,9 +5157,12 @@ pub fn sock_join_multicast_v4( 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| { - socket.join_multicast_v4(multiaddr, iface) - })); + wasi_try!(__sock_actor_mut( + &ctx, + sock, + wasi_snapshot0::Rights::empty(), + |socket| { socket.join_multicast_v4(multiaddr, iface) } + )); wasi_snapshot0::Errno::Success } @@ -5094,9 +5186,12 @@ pub fn sock_leave_multicast_v4( 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| { - socket.leave_multicast_v4(multiaddr, iface) - })); + wasi_try!(__sock_actor_mut( + &ctx, + sock, + wasi_snapshot0::Rights::empty(), + |socket| { socket.leave_multicast_v4(multiaddr, iface) } + )); wasi_snapshot0::Errno::Success } @@ -5119,9 +5214,12 @@ pub fn 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| { - socket.join_multicast_v6(multiaddr, iface) - })); + wasi_try!(__sock_actor_mut( + &ctx, + sock, + wasi_snapshot0::Rights::empty(), + |socket| { socket.join_multicast_v6(multiaddr, iface) } + )); wasi_snapshot0::Errno::Success } @@ -5144,9 +5242,12 @@ pub fn 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| { - socket.leave_multicast_v6(multiaddr, iface) - })); + wasi_try!(__sock_actor_mut( + &ctx, + sock, + wasi_snapshot0::Rights::empty(), + |socket| { socket.leave_multicast_v6(multiaddr, iface) } + )); wasi_snapshot0::Errno::Success } @@ -5172,7 +5273,7 @@ pub fn sock_bind( wasi_try!(__sock_upgrade( &ctx, sock, - __WASI_RIGHT_SOCK_BIND, + wasi_snapshot0::Rights::SOCK_BIND, |socket| { socket.bind(env.net(), addr) } )); wasi_snapshot0::Errno::Success @@ -5202,7 +5303,7 @@ pub fn sock_listen( wasi_try!(__sock_upgrade( &ctx, sock, - __WASI_RIGHT_SOCK_BIND, + wasi_snapshot0::Rights::SOCK_BIND, |socket| { socket.listen(env.net(), backlog) } )); wasi_snapshot0::Errno::Success @@ -5234,25 +5335,26 @@ pub fn sock_accept( let mut ret; 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 - .accept_timeout(fd_flags, Duration::from_millis(5))) - { - Ok(a) => { - ret = a; - break; - } - Err(wasi_snapshot0::Errno::Timedout) => { - env.yield_now()?; - continue; - } - Err(wasi_snapshot0::Errno::Again) => { - env.sleep(Duration::from_millis(5))?; - continue; - } - Err(err) => Err(err), + wasi_try_ok!(match __sock_actor( + &ctx, + sock, + wasi_snapshot0::Rights::SOCK_ACCEPT, + |socket| socket.accept_timeout(fd_flags, Duration::from_millis(5)) + ) { + Ok(a) => { + ret = a; + break; } - ); + Err(wasi_snapshot0::Errno::Timedout) => { + env.yield_now()?; + continue; + } + Err(wasi_snapshot0::Errno::Again) => { + env.sleep(Duration::from_millis(5))?; + continue; + } + Err(err) => Err(err), + }); } ret }; @@ -5309,7 +5411,7 @@ pub fn sock_connect( wasi_try!(__sock_upgrade( &ctx, sock, - __WASI_RIGHT_SOCK_CONNECT, + wasi_snapshot0::Rights::SOCK_CONNECT, |socket| { socket.connect(env.net(), addr) } )); wasi_snapshot0::Errno::Success @@ -5346,7 +5448,7 @@ pub fn sock_recv( let bytes_read = wasi_try_ok!(__sock_actor_mut( &ctx, sock, - __WASI_RIGHT_SOCK_RECV, + wasi_snapshot0::Rights::SOCK_RECV, |socket| { socket.recv(&memory, iovs_arr) } )); let bytes_read: M::Offset = wasi_try_ok!(bytes_read @@ -5391,7 +5493,7 @@ pub fn sock_recv_from( let bytes_read = wasi_try_ok!(__sock_actor_mut( &ctx, sock, - __WASI_RIGHT_SOCK_RECV_FROM, + wasi_snapshot0::Rights::SOCK_RECV_FROM, |socket| { socket.recv_from(&memory, iovs_arr, ro_addr) } )); let bytes_read: M::Offset = wasi_try_ok!(bytes_read @@ -5434,7 +5536,7 @@ pub fn sock_send( let bytes_written = wasi_try_ok!(__sock_actor_mut( &ctx, sock, - __WASI_RIGHT_SOCK_SEND, + wasi_snapshot0::Rights::SOCK_SEND, |socket| { socket.send(&memory, iovs_arr) } )); @@ -5478,7 +5580,7 @@ pub fn sock_send_to( let bytes_written = wasi_try_ok!(__sock_actor_mut( &ctx, sock, - __WASI_RIGHT_SOCK_SEND_TO, + wasi_snapshot0::Rights::SOCK_SEND_TO, |socket| { socket.send_to::(&memory, iovs_arr, addr) } )); @@ -5545,7 +5647,7 @@ pub unsafe fn sock_send_file( } __WASI_STDOUT_FILENO | __WASI_STDERR_FILENO => return Ok(wasi_snapshot0::Errno::Inval), _ => { - if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_READ) { + if !fd_entry.rights.contains(wasi_snapshot0::Rights::FD_READ) { // TODO: figure out the error to return when lacking rights return Ok(wasi_snapshot0::Errno::Acces); } @@ -5605,7 +5707,7 @@ pub unsafe fn sock_send_file( let bytes_written = wasi_try_ok!(__sock_actor_mut( &ctx, sock, - __WASI_RIGHT_SOCK_SEND, + wasi_snapshot0::Rights::SOCK_SEND, |socket| { let buf = (&buf[..]).to_vec(); socket.send_bytes::(Bytes::from(buf)) diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index 82e614f9512..2832852a2ee 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -102,8 +102,8 @@ pub(crate) fn fd_fdstat_set_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, + fs_rights_base: wasi_snapshot0::Rights, + fs_rights_inheriting: wasi_snapshot0::Rights, ) -> wasi_snapshot0::Errno { super::fd_fdstat_set_rights(ctx, fd, fs_rights_base, fs_rights_inheriting) } @@ -298,8 +298,8 @@ pub(crate) fn path_open( path: WasmPtr, path_len: MemoryOffset, o_flags: __wasi_oflags_t, - fs_rights_base: __wasi_rights_t, - fs_rights_inheriting: __wasi_rights_t, + fs_rights_base: wasi_snapshot0::Rights, + fs_rights_inheriting: wasi_snapshot0::Rights, fs_flags: __wasi_fdflags_t, fd: WasmPtr<__wasi_fd_t, MemoryType>, ) -> wasi_snapshot0::Errno { diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index abf04951a73..7b2b26590e5 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -102,8 +102,8 @@ pub(crate) fn fd_fdstat_set_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, + fs_rights_base: wasi_snapshot0::Rights, + fs_rights_inheriting: wasi_snapshot0::Rights, ) -> wasi_snapshot0::Errno { super::fd_fdstat_set_rights(ctx, fd, fs_rights_base, fs_rights_inheriting) } @@ -298,8 +298,8 @@ pub(crate) fn path_open( path: WasmPtr, path_len: MemoryOffset, o_flags: __wasi_oflags_t, - fs_rights_base: __wasi_rights_t, - fs_rights_inheriting: __wasi_rights_t, + fs_rights_base: wasi_snapshot0::Rights, + fs_rights_inheriting: wasi_snapshot0::Rights, fs_flags: __wasi_fdflags_t, fd: WasmPtr<__wasi_fd_t, MemoryType>, ) -> wasi_snapshot0::Errno { From 75be1d3ebcaf4f42244e8133448a6dea1c27ed23 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Thu, 18 Aug 2022 06:06:08 +0200 Subject: [PATCH 11/84] WIP: Eventrwflags --- lib/wasi-types-generated/src/bindings.rs | 18 ++++++++++++++ lib/wasi-types-generated/src/lib.rs | 24 +++++++++++++++++++ .../wit/wasi-snapshot0.wit | 21 ++++++++-------- lib/wasi-types/src/event.rs | 9 +++---- lib/wasi/src/syscalls/mod.rs | 6 ++--- 5 files changed, 59 insertions(+), 19 deletions(-) diff --git a/lib/wasi-types-generated/src/bindings.rs b/lib/wasi-types-generated/src/bindings.rs index defcd3c4ba6..012d0acb16b 100644 --- a/lib/wasi-types-generated/src/bindings.rs +++ b/lib/wasi-types-generated/src/bindings.rs @@ -599,6 +599,24 @@ pub mod wasi_snapshot0 { } } } + wit_bindgen_wasmer::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 core::fmt::Display for Eventrwflags{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("Eventrwflags(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(())} + } + #[allow(unused_imports)] use wasmer::AsStoreMut as _; #[allow(unused_imports)] diff --git a/lib/wasi-types-generated/src/lib.rs b/lib/wasi-types-generated/src/lib.rs index eadf46b277b..3cb39f2a179 100644 --- a/lib/wasi-types-generated/src/lib.rs +++ b/lib/wasi-types-generated/src/lib.rs @@ -29,6 +29,12 @@ unsafe impl ValueType for wasi_snapshot0::Rights { fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for wasi_snapshot0::Eventrwflags { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + // TODO: if necessary, must be implemented in wit-bindgen unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0::Errno { type Native = i32; @@ -171,3 +177,21 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0: false } } + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0::Eventrwflags { + 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 u8) + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} diff --git a/lib/wasi-types-generated/wit/wasi-snapshot0.wit b/lib/wasi-types-generated/wit/wasi-snapshot0.wit index 95f9ffb89fa..d63bc01b052 100644 --- a/lib/wasi-types-generated/wit/wasi-snapshot0.wit +++ b/lib/wasi-types-generated/wit/wasi-snapshot0.wit @@ -520,16 +520,17 @@ enum eventtype { fd-write, } -// -// ;;; The state of the file descriptor subscribed to with -// ;;; `eventtype::fd_read` or `eventtype::fd_write`. -// (typename $eventrwflags -// (flags (@witx repr u16) -// ;;; The peer of this socket has closed or disconnected. -// $fd_readwrite_hangup -// ) -// ) -// + +/// 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 type size + //@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 // (typename $event_fd_readwrite diff --git a/lib/wasi-types/src/event.rs b/lib/wasi-types/src/event.rs index 5a6235eb294..833d6b0ecd0 100644 --- a/lib/wasi-types/src/event.rs +++ b/lib/wasi-types/src/event.rs @@ -5,13 +5,13 @@ use std::{ }; use wasmer_derive::ValueType; use wasmer_types::ValueType; -use wasmer_wasi_types_generated::wasi_snapshot0; +use wasmer_wasi_types_generated::{wasi_filesystem, wasi_snapshot0}; #[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, + pub flags: wasi_snapshot0::Eventrwflags, } #[derive(Copy, Clone)] @@ -33,7 +33,7 @@ impl fmt::Debug for __wasi_event_u { pub enum EventEnum { FdReadWrite { nbytes: __wasi_filesize_t, - flags: __wasi_eventrwflags_t, + flags: wasi_snapshot0::Eventrwflags, }, } @@ -111,9 +111,6 @@ unsafe impl ValueType for __wasi_event_t { } } -pub type __wasi_eventrwflags_t = u16; -pub const __WASI_EVENT_FD_READWRITE_HANGUP: u16 = 1 << 0; - pub fn eventtype_to_str(event_type: wasi_snapshot0::Eventtype) -> &'static str { match event_type { wasi_snapshot0::Eventtype::Clock => "Wasi::Eventtype::Clock", diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 053078494b1..47f6585c429 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -3275,14 +3275,14 @@ pub fn poll_oneoff( } for (i, seen_event) in seen_events.into_iter().enumerate() { - let mut flags = 0; + let mut flags = wasi_snapshot0::Eventrwflags::empty(); let mut error = wasi_snapshot0::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_snapshot0::Errno::Io, - PollEvent::PollHangUp => flags = __WASI_EVENT_FD_READWRITE_HANGUP, + PollEvent::PollHangUp => flags = wasi_snapshot0::Eventrwflags::FD_READWRITE_HANGUP, PollEvent::PollInvalid => error = wasi_snapshot0::Errno::Inval, PollEvent::PollIn => { bytes_available = wasi_try_ok!( @@ -3332,7 +3332,7 @@ pub fn poll_oneoff( __wasi_event_u { fd_readwrite: __wasi_event_fd_readwrite_t { nbytes: 0, - flags: 0, + flags: wasi_snapshot0::Eventrwflags::empty(), }, } }, From 40b5b534d6dea48c3c109433a947bdb3811a3aef Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Thu, 18 Aug 2022 06:36:57 +0200 Subject: [PATCH 12/84] WIP: Subcodeflags --- lib/wasi-types-generated/regenerate.sh | 1 + lib/wasi-types-generated/src/bindings.rs | 22 +++++++++++++++ lib/wasi-types-generated/src/lib.rs | 24 ++++++++++++++++ .../wit/wasi-snapshot0.wit | 28 +++++++++---------- lib/wasi-types/src/subscription.rs | 5 +--- lib/wasi-types/src/versions/snapshot0.rs | 2 +- 6 files changed, 63 insertions(+), 19 deletions(-) diff --git a/lib/wasi-types-generated/regenerate.sh b/lib/wasi-types-generated/regenerate.sh index fa31ebd9e88..e181d71caa2 100755 --- a/lib/wasi-types-generated/regenerate.sh +++ b/lib/wasi-types-generated/regenerate.sh @@ -2,3 +2,4 @@ rm src/bindings.rs wit-bindgen wasmer --import wit/wasi-snapshot0.wit wit/wasi-filesystem.wit --out-dir src/ +#wit-bindgen rust-wasm --import wit/wasi-snapshot0.wit wit/wasi-filesystem.wit --out-dir . diff --git a/lib/wasi-types-generated/src/bindings.rs b/lib/wasi-types-generated/src/bindings.rs index 012d0acb16b..7770ae5f665 100644 --- a/lib/wasi-types-generated/src/bindings.rs +++ b/lib/wasi-types-generated/src/bindings.rs @@ -617,6 +617,28 @@ pub mod wasi_snapshot0 { Ok(())} } + wit_bindgen_wasmer::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 core::fmt::Display for Subclockflags{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("Subclockflags(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(())} + } + #[allow(unused_imports)] use wasmer::AsStoreMut as _; #[allow(unused_imports)] diff --git a/lib/wasi-types-generated/src/lib.rs b/lib/wasi-types-generated/src/lib.rs index 3cb39f2a179..c6e4efb6eff 100644 --- a/lib/wasi-types-generated/src/lib.rs +++ b/lib/wasi-types-generated/src/lib.rs @@ -35,6 +35,12 @@ unsafe impl ValueType for wasi_snapshot0::Eventrwflags { fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for wasi_snapshot0::Subclockflags { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + // TODO: if necessary, must be implemented in wit-bindgen unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0::Errno { type Native = i32; @@ -195,3 +201,21 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0: false } } + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0::Subclockflags { + 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 u8) + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} diff --git a/lib/wasi-types-generated/wit/wasi-snapshot0.wit b/lib/wasi-types-generated/wit/wasi-snapshot0.wit index d63bc01b052..042b224fa39 100644 --- a/lib/wasi-types-generated/wit/wasi-snapshot0.wit +++ b/lib/wasi-types-generated/wit/wasi-snapshot0.wit @@ -556,20 +556,20 @@ flags eventrwflags { // (field $fd_readwrite $event_fd_readwrite) // ) // ) -// -// ;;; Flags determining how to interpret the timestamp provided in -// ;;; `subscription_clock::timeout`. -// (typename $subclockflags -// (flags (@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 -// ) -// ) -// + +/// Flags determining how to interpret the timestamp provided in +/// `subscription-clock::timeout`. +flags subclockflags { + // TODO: wit appears to not have support for flags type size + //@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`. // (typename $subscription_clock // (record diff --git a/lib/wasi-types/src/subscription.rs b/lib/wasi-types/src/subscription.rs index d69181f4028..8f3a89453d0 100644 --- a/lib/wasi-types/src/subscription.rs +++ b/lib/wasi-types/src/subscription.rs @@ -6,16 +6,13 @@ use wasmer_derive::ValueType; use wasmer_types::ValueType; use wasmer_wasi_types_generated::wasi_snapshot0; -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, + pub flags: wasi_snapshot0::Subclockflags, } #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] diff --git a/lib/wasi-types/src/versions/snapshot0.rs b/lib/wasi-types/src/versions/snapshot0.rs index 3872b112c8f..1841086d4b3 100644 --- a/lib/wasi-types/src/versions/snapshot0.rs +++ b/lib/wasi-types/src/versions/snapshot0.rs @@ -14,7 +14,7 @@ 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, + pub flags: wasi_snapshot0::Subclockflags, } #[derive(Copy, Clone)] From 24f88fda59bd3f01d2687389bb069d8afebfa378 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Thu, 18 Aug 2022 07:08:01 +0200 Subject: [PATCH 13/84] WIP: Clockid --- lib/wasi-types-generated/src/bindings.rs | 35 +++++++ lib/wasi-types-generated/src/lib.rs | 31 ++++++ .../wit/wasi-snapshot0.wit | 37 ++++--- lib/wasi-types/src/subscription.rs | 2 +- lib/wasi-types/src/time.rs | 6 -- lib/wasi-types/src/versions/snapshot0.rs | 2 +- lib/wasi/src/lib.rs | 8 +- lib/wasi/src/macros.rs | 2 +- lib/wasi/src/syscalls/mod.rs | 23 +++-- lib/wasi/src/syscalls/unix/mod.rs | 20 ++-- lib/wasi/src/syscalls/wasi.rs | 99 ++++++++++--------- lib/wasi/src/syscalls/wasix32.rs | 4 +- lib/wasi/src/syscalls/wasix64.rs | 4 +- lib/wasi/src/syscalls/wasm32.rs | 12 +-- lib/wasi/src/syscalls/windows.rs | 42 ++++---- 15 files changed, 200 insertions(+), 127 deletions(-) diff --git a/lib/wasi-types-generated/src/bindings.rs b/lib/wasi-types-generated/src/bindings.rs index 7770ae5f665..12a8b3a672b 100644 --- a/lib/wasi-types-generated/src/bindings.rs +++ b/lib/wasi-types-generated/src/bindings.rs @@ -2,6 +2,41 @@ pub mod wasi_snapshot0 { #[allow(unused_imports)] use wit_bindgen_wasmer::{anyhow, wasmer}; + /// 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, + /// 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 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() + } + Clockid::ProcessCputimeId => { + f.debug_tuple("Clockid::ProcessCputimeId").finish() + } + Clockid::ThreadCputimeId => { + f.debug_tuple("Clockid::ThreadCputimeId").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 diff --git a/lib/wasi-types-generated/src/lib.rs b/lib/wasi-types-generated/src/lib.rs index c6e4efb6eff..193b9329dac 100644 --- a/lib/wasi-types-generated/src/lib.rs +++ b/lib/wasi-types-generated/src/lib.rs @@ -41,6 +41,12 @@ unsafe impl ValueType for wasi_snapshot0::Subclockflags { fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for wasi_snapshot0::Clockid { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + // TODO: if necessary, must be implemented in wit-bindgen unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0::Errno { type Native = i32; @@ -219,3 +225,28 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0: false } } + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0::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, + 2 => Self::ProcessCputimeId, + 3 => Self::ThreadCputimeId, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} diff --git a/lib/wasi-types-generated/wit/wasi-snapshot0.wit b/lib/wasi-types-generated/wit/wasi-snapshot0.wit index 042b224fa39..8618b208649 100644 --- a/lib/wasi-types-generated/wit/wasi-snapshot0.wit +++ b/lib/wasi-types-generated/wit/wasi-snapshot0.wit @@ -8,25 +8,24 @@ type filesize = u64 /// Timestamp in nanoseconds. type timestamp = u64 - - -// ;;; Identifiers for clocks. -// (typename $clockid -// (enum (@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 type size + //(@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, +} diff --git a/lib/wasi-types/src/subscription.rs b/lib/wasi-types/src/subscription.rs index 8f3a89453d0..2a281699f24 100644 --- a/lib/wasi-types/src/subscription.rs +++ b/lib/wasi-types/src/subscription.rs @@ -9,7 +9,7 @@ use wasmer_wasi_types_generated::wasi_snapshot0; #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] #[repr(C)] pub struct __wasi_subscription_clock_t { - pub clock_id: __wasi_clockid_t, + pub clock_id: wasi_snapshot0::Clockid, pub timeout: __wasi_timestamp_t, pub precision: __wasi_timestamp_t, pub flags: wasi_snapshot0::Subclockflags, diff --git a/lib/wasi-types/src/time.rs b/lib/wasi-types/src/time.rs index de9a2b26b92..6c021601ef0 100644 --- a/lib/wasi-types/src/time.rs +++ b/lib/wasi-types/src/time.rs @@ -1,12 +1,6 @@ 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)] diff --git a/lib/wasi-types/src/versions/snapshot0.rs b/lib/wasi-types/src/versions/snapshot0.rs index 1841086d4b3..5b117ee7827 100644 --- a/lib/wasi-types/src/versions/snapshot0.rs +++ b/lib/wasi-types/src/versions/snapshot0.rs @@ -11,7 +11,7 @@ pub type __wasi_linkcount_t = u32; #[repr(C)] pub struct __wasi_subscription_clock_t { pub userdata: __wasi_userdata_t, - pub clock_id: __wasi_clockid_t, + pub clock_id: wasi_snapshot0::Clockid, pub timeout: __wasi_timestamp_t, pub precision: __wasi_timestamp_t, pub flags: wasi_snapshot0::Subclockflags, diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index d339b807be9..7245e97e27d 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; @@ -66,6 +65,7 @@ use wasmer::{ imports, namespace, AsStoreMut, AsStoreRef, Exports, Function, FunctionEnv, Imports, Memory, Memory32, MemoryAccessError, MemorySize, MemoryView, Module, TypedFunction, }; +use wasmer_wasi_types_generated::wasi_snapshot0; pub use runtime::{ PluggableRuntimeImplementation, WasiRuntimeImplementation, WasiThreadError, WasiTtyState, @@ -291,10 +291,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(wasi_snapshot0::Clockid::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(wasi_snapshot0::Clockid::Monotonic, 1_000_000) + .unwrap() as u128; let delta = match now.checked_sub(start) { Some(a) => a, None => { diff --git a/lib/wasi/src/macros.rs b/lib/wasi/src/macros.rs index 938f7dcab26..0c503e318cd 100644 --- a/lib/wasi/src/macros.rs +++ b/lib/wasi/src/macros.rs @@ -85,7 +85,7 @@ macro_rules! wasi_try_mem_bus { }}; } -/// Like `wasi_try` but converts a `MemoryAccessError` to a __wasi_errno_t`. +/// Like `wasi_try` but converts a `MemoryAccessError` to a wasi_snapshot0::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/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 47f6585c429..2734ff0efcd 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -363,14 +363,14 @@ pub fn args_sizes_get( /// ### `clock_res_get()` /// Get the resolution of the specified clock /// Input: -/// - `__wasi_clockid_t clock_id` +/// - `wasi_snapshot0::Clockid clock_id` /// The ID of the clock to get the resolution of /// Output: /// - `__wasi_timestamp_t *resolution` /// The resolution of the clock in nanoseconds pub fn clock_res_get( mut ctx: FunctionEnvMut<'_, WasiEnv>, - clock_id: __wasi_clockid_t, + clock_id: wasi_snapshot0::Clockid, resolution: WasmPtr<__wasi_timestamp_t, M>, ) -> wasi_snapshot0::Errno { trace!("wasi::clock_res_get"); @@ -386,7 +386,7 @@ pub fn clock_res_get( /// ### `clock_time_get()` /// Get the time of the specified clock /// Inputs: -/// - `__wasi_clockid_t clock_id` +/// - `wasi_snapshot0::Clockid clock_id` /// The ID of the clock to query /// - `__wasi_timestamp_t precision` /// The maximum amount of error the reading may have @@ -395,13 +395,13 @@ pub fn clock_res_get( /// The value of the clock in nanoseconds pub fn clock_time_get( ctx: FunctionEnvMut<'_, WasiEnv>, - clock_id: __wasi_clockid_t, + clock_id: wasi_snapshot0::Clockid, precision: __wasi_timestamp_t, time: WasmPtr<__wasi_timestamp_t, M>, ) -> wasi_snapshot0::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); @@ -3151,9 +3151,10 @@ pub fn poll_oneoff( Some(fd) } EventType::Clock(clock_info) => { - if clock_info.clock_id == __WASI_CLOCK_REALTIME - || clock_info.clock_id == __WASI_CLOCK_MONOTONIC - { + if matches!( + clock_info.clock_id, + wasi_snapshot0::Clockid::Realtime | wasi_snapshot0::Clockid::Monotonic + ) { // this is a hack // TODO: do this properly time_to_sleep = Duration::from_nanos(clock_info.timeout); @@ -3242,10 +3243,12 @@ pub fn poll_oneoff( 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(wasi_snapshot0::Clockid::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(wasi_snapshot0::Clockid::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, diff --git a/lib/wasi/src/syscalls/unix/mod.rs b/lib/wasi/src/syscalls/unix/mod.rs index a8ad2083acc..b2d0f10c464 100644 --- a/lib/wasi/src/syscalls/unix/mod.rs +++ b/lib/wasi/src/syscalls/unix/mod.rs @@ -8,14 +8,14 @@ use std::mem; use wasmer::WasmRef; pub fn platform_clock_res_get( - clock_id: __wasi_clockid_t, + clock_id: wasi_snapshot0::Clockid, resolution: WasmRef<__wasi_timestamp_t>, ) -> 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, + wasi_snapshot0::Clockid::Monotonic => CLOCK_MONOTONIC, + wasi_snapshot0::Clockid::ProcessCputimeId => CLOCK_PROCESS_CPUTIME_ID, + wasi_snapshot0::Clockid::Realtime => CLOCK_REALTIME, + wasi_snapshot0::Clockid::ThreadCputimeId => CLOCK_THREAD_CPUTIME_ID, _ => return Err(wasi_snapshot0::Errno::Inval), }; @@ -32,14 +32,14 @@ pub fn platform_clock_res_get( } pub fn platform_clock_time_get( - clock_id: __wasi_clockid_t, + clock_id: wasi_snapshot0::Clockid, precision: __wasi_timestamp_t, ) -> 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, + wasi_snapshot0::Clockid::Monotonic => CLOCK_MONOTONIC, + wasi_snapshot0::Clockid::ProcessCputimeId => CLOCK_PROCESS_CPUTIME_ID, + wasi_snapshot0::Clockid::Realtime => CLOCK_REALTIME, + wasi_snapshot0::Clockid::ThreadCputimeId => CLOCK_THREAD_CPUTIME_ID, _ => return Err(wasi_snapshot0::Errno::Inval), }; diff --git a/lib/wasi/src/syscalls/wasi.rs b/lib/wasi/src/syscalls/wasi.rs index b2575f6e53c..6e8b733866c 100644 --- a/lib/wasi/src/syscalls/wasi.rs +++ b/lib/wasi/src/syscalls/wasi.rs @@ -1,6 +1,6 @@ #![deny(dead_code)] use crate::{WasiEnv, WasiError, WasiState, WasiThread}; -use wasmer::{StoreMut, Memory, Memory32, MemorySize, WasmPtr, WasmSlice}; +use wasmer::{Memory, Memory32, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; type MemoryType = Memory32; @@ -10,7 +10,7 @@ pub(crate) fn args_get( ctx: FunctionEnvMut, argv: WasmPtr, MemoryType>, argv_buf: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::args_get::(ctx, argv, argv_buf) } @@ -18,24 +18,24 @@ pub(crate) fn args_sizes_get( ctx: FunctionEnvMut, argc: WasmPtr, argv_buf_size: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::args_sizes_get::(ctx, argc, argv_buf_size) } pub(crate) fn clock_res_get( ctx: FunctionEnvMut, - clock_id: __wasi_clockid_t, + clock_id: wasi_snapshot0::Clockid, resolution: WasmPtr<__wasi_timestamp_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::clock_res_get::(ctx, clock_id, resolution) } pub(crate) fn clock_time_get( ctx: FunctionEnvMut, - clock_id: __wasi_clockid_t, + clock_id: wasi_snapshot0::Clockid, precision: __wasi_timestamp_t, time: WasmPtr<__wasi_timestamp_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::clock_time_get::(ctx, clock_id, precision, time) } @@ -43,7 +43,7 @@ pub(crate) fn environ_get( ctx: FunctionEnvMut, environ: WasmPtr, MemoryType>, environ_buf: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::environ_get::(ctx, environ, environ_buf) } @@ -51,7 +51,7 @@ pub(crate) fn environ_sizes_get( ctx: FunctionEnvMut, environ_count: WasmPtr, environ_buf_size: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::environ_sizes_get::(ctx, environ_count, environ_buf_size) } @@ -61,7 +61,7 @@ pub(crate) fn fd_advise( offset: __wasi_filesize_t, len: __wasi_filesize_t, advice: __wasi_advice_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_advise(ctx, fd, offset, len, advice) } @@ -70,15 +70,15 @@ pub(crate) fn fd_allocate( fd: __wasi_fd_t, offset: __wasi_filesize_t, len: __wasi_filesize_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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: __wasi_fd_t) -> wasi_snapshot0::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: __wasi_fd_t) -> wasi_snapshot0::Errno { super::fd_datasync(ctx, fd) } @@ -86,7 +86,7 @@ pub(crate) fn fd_fdstat_get( ctx: FunctionEnvMut, fd: __wasi_fd_t, buf_ptr: WasmPtr<__wasi_fdstat_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_fdstat_get::(ctx, fd, buf_ptr) } @@ -94,7 +94,7 @@ pub(crate) fn fd_fdstat_set_flags( ctx: FunctionEnvMut, fd: __wasi_fd_t, flags: __wasi_fdflags_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_fdstat_set_flags(ctx, fd, flags) } @@ -103,7 +103,7 @@ pub(crate) fn fd_fdstat_set_rights( fd: __wasi_fd_t, fs_rights_base: __wasi_rights_t, fs_rights_inheriting: __wasi_rights_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_fdstat_set_rights(ctx, fd, fs_rights_base, fs_rights_inheriting) } @@ -111,7 +111,7 @@ pub(crate) fn fd_filestat_get( ctx: FunctionEnvMut, fd: __wasi_fd_t, buf: WasmPtr<__wasi_filestat_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_filestat_get::(ctx, fd, buf) } @@ -119,7 +119,7 @@ pub(crate) fn fd_filestat_set_size( ctx: FunctionEnvMut, fd: __wasi_fd_t, st_size: __wasi_filesize_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_filestat_set_size(ctx, fd, st_size) } @@ -129,7 +129,7 @@ pub(crate) fn fd_filestat_set_times( st_atim: __wasi_timestamp_t, st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_filestat_set_times(ctx, fd, st_atim, st_mtim, fst_flags) } @@ -140,7 +140,7 @@ pub(crate) fn fd_pread( iovs_len: MemoryOffset, offset: __wasi_filesize_t, nread: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::fd_pread::(ctx, fd, iovs, iovs_len, offset, nread) } @@ -148,7 +148,7 @@ pub(crate) fn fd_prestat_get( ctx: FunctionEnvMut, fd: __wasi_fd_t, buf: WasmPtr<__wasi_prestat_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_prestat_get::(ctx, fd, buf) } @@ -157,7 +157,7 @@ pub(crate) fn fd_prestat_dir_name( fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_prestat_dir_name::(ctx, fd, path, path_len) } @@ -168,7 +168,7 @@ pub(crate) fn fd_pwrite( iovs_len: MemoryOffset, offset: __wasi_filesize_t, nwritten: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::fd_pwrite::(ctx, fd, iovs, iovs_len, offset, nwritten) } @@ -178,7 +178,7 @@ pub(crate) fn fd_read( 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) } @@ -189,7 +189,7 @@ pub(crate) fn fd_readdir( buf_len: MemoryOffset, cookie: __wasi_dircookie_t, bufused: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_readdir::(ctx, fd, buf, buf_len, cookie, bufused) } @@ -197,7 +197,7 @@ pub(crate) fn fd_renumber( ctx: FunctionEnvMut, from: __wasi_fd_t, to: __wasi_fd_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_renumber(ctx, from, to) } @@ -207,11 +207,11 @@ pub(crate) fn fd_seek( offset: __wasi_filedelta_t, whence: __wasi_whence_t, newoffset: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> Result<__wasi_errno_t, WasiError> { +) -> 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: __wasi_fd_t) -> wasi_snapshot0::Errno { super::fd_sync(ctx, fd) } @@ -219,7 +219,7 @@ pub(crate) fn fd_tell( ctx: FunctionEnvMut, fd: __wasi_fd_t, offset: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::fd_tell::(ctx, fd, offset) } @@ -229,7 +229,7 @@ pub(crate) fn fd_write( 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) } @@ -238,7 +238,7 @@ pub(crate) fn path_create_directory( fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_create_directory::(ctx, fd, path, path_len) } @@ -249,7 +249,7 @@ pub(crate) fn path_filestat_get( path: WasmPtr, path_len: MemoryOffset, buf: WasmPtr<__wasi_filestat_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_filestat_get::(ctx, fd, flags, path, path_len, buf) } @@ -262,7 +262,7 @@ pub(crate) fn path_filestat_set_times( st_atim: __wasi_timestamp_t, st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_filestat_set_times::( ctx, fd, flags, path, path_len, st_atim, st_mtim, fst_flags, ) @@ -277,7 +277,7 @@ pub(crate) fn path_link( new_fd: __wasi_fd_t, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_link::( ctx, old_fd, @@ -301,7 +301,7 @@ pub(crate) fn path_open( fs_rights_inheriting: __wasi_rights_t, fs_flags: __wasi_fdflags_t, fd: WasmPtr<__wasi_fd_t, MemoryType>, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_open::( ctx, dirfd, @@ -324,7 +324,7 @@ pub(crate) fn path_readlink( buf: WasmPtr, buf_len: MemoryOffset, buf_used: WasmPtr, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_readlink::(ctx, dir_fd, path, path_len, buf, buf_len, buf_used) } @@ -333,7 +333,7 @@ pub(crate) fn path_remove_directory( fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_remove_directory::(ctx, fd, path, path_len) } @@ -345,7 +345,7 @@ pub(crate) fn path_rename( new_fd: __wasi_fd_t, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_rename::( ctx, old_fd, @@ -364,7 +364,7 @@ pub(crate) fn path_symlink( fd: __wasi_fd_t, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_symlink::(ctx, old_path, old_path_len, fd, new_path, new_path_len) } @@ -373,7 +373,7 @@ pub(crate) fn path_unlink_file( fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::path_unlink_file::(ctx, fd, path, path_len) } @@ -383,7 +383,7 @@ pub(crate) fn poll_oneoff( out_: WasmPtr<__wasi_event_t, MemoryType>, nsubscriptions: MemoryOffset, nevents: WasmPtr, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::poll_oneoff::(ctx, in_, out_, nsubscriptions, nevents) } @@ -394,7 +394,10 @@ 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: __wasi_signal_t, +) -> wasi_snapshot0::Errno { super::proc_raise(ctx, sig) } @@ -402,11 +405,13 @@ pub(crate) fn random_get( ctx: FunctionEnvMut, buf: WasmPtr, buf_len: MemoryOffset, -) -> __wasi_errno_t { +) -> wasi_snapshot0::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) } @@ -418,7 +423,7 @@ pub(crate) fn sock_recv( ri_flags: __wasi_riflags_t, ro_data_len: WasmPtr, ro_flags: WasmPtr<__wasi_roflags_t, MemoryType>, -) -> Result<__wasi_errno_t, WasiError> { +) -> Result { super::sock_recv::( ctx, sock, @@ -437,7 +442,7 @@ pub(crate) fn sock_send( si_data_len: MemoryOffset, si_flags: __wasi_siflags_t, 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) } @@ -445,6 +450,6 @@ pub(crate) fn sock_shutdown( ctx: FunctionEnvMut, sock: __wasi_fd_t, how: __wasi_sdflags_t, -) -> __wasi_errno_t { +) -> wasi_snapshot0::Errno { super::sock_shutdown(ctx, sock, how) } diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index 2832852a2ee..20632dc2752 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -25,7 +25,7 @@ pub(crate) fn args_sizes_get( pub(crate) fn clock_res_get( ctx: FunctionEnvMut, - clock_id: __wasi_clockid_t, + clock_id: wasi_snapshot0::Clockid, resolution: WasmPtr<__wasi_timestamp_t, MemoryType>, ) -> wasi_snapshot0::Errno { super::clock_res_get::(ctx, clock_id, resolution) @@ -33,7 +33,7 @@ pub(crate) fn clock_res_get( pub(crate) fn clock_time_get( ctx: FunctionEnvMut, - clock_id: __wasi_clockid_t, + clock_id: wasi_snapshot0::Clockid, precision: __wasi_timestamp_t, time: WasmPtr<__wasi_timestamp_t, MemoryType>, ) -> wasi_snapshot0::Errno { diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index 7b2b26590e5..111aee73090 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -25,7 +25,7 @@ pub(crate) fn args_sizes_get( pub(crate) fn clock_res_get( ctx: FunctionEnvMut, - clock_id: __wasi_clockid_t, + clock_id: wasi_snapshot0::Clockid, resolution: WasmPtr<__wasi_timestamp_t, MemoryType>, ) -> wasi_snapshot0::Errno { super::clock_res_get::(ctx, clock_id, resolution) @@ -33,7 +33,7 @@ pub(crate) fn clock_res_get( pub(crate) fn clock_time_get( ctx: FunctionEnvMut, - clock_id: __wasi_clockid_t, + clock_id: wasi_snapshot0::Clockid, precision: __wasi_timestamp_t, time: WasmPtr<__wasi_timestamp_t, MemoryType>, ) -> wasi_snapshot0::Errno { diff --git a/lib/wasi/src/syscalls/wasm32.rs b/lib/wasi/src/syscalls/wasm32.rs index f62a4f3e4e1..f05930d0fc7 100644 --- a/lib/wasi/src/syscalls/wasm32.rs +++ b/lib/wasi/src/syscalls/wasm32.rs @@ -4,21 +4,21 @@ use std::mem; use wasmer::WasmRef; pub fn platform_clock_res_get( - clock_id: __wasi_clockid_t, + clock_id: wasi_snapshot0::Clockid, resolution: WasmRef<__wasi_timestamp_t>, ) -> 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, + wasi_snapshot0::Clockid::Monotonic => 10_000_000, + wasi_snapshot0::Clockid::Realtime => 1, + wasi_snapshot0::Clockid::ProcessCputimeId => 1, + wasi_snapshot0::Clockid::ThreadCputimeId => 1, _ => return Err(wasi_snapshot0::Errno::Inval), }; Ok(t_out) } pub fn platform_clock_time_get( - clock_id: __wasi_clockid_t, + clock_id: wasi_snapshot0::Clockid, precision: __wasi_timestamp_t, ) -> Result { let new_time: DateTime = Local::now(); diff --git a/lib/wasi/src/syscalls/windows.rs b/lib/wasi/src/syscalls/windows.rs index c461fa44ca8..5da391946e7 100644 --- a/lib/wasi/src/syscalls/windows.rs +++ b/lib/wasi/src/syscalls/windows.rs @@ -3,51 +3,55 @@ use tracing::debug; use wasmer::WasmRef; pub fn platform_clock_res_get( - clock_id: __wasi_clockid_t, + clock_id: wasi_snapshot0::Clockid, resolution: WasmRef<__wasi_timestamp_t>, -) -> Result { +) -> 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_snapshot0::Clockid::Monotonic => 10_000_000, // TODO: verify or compute this - __WASI_CLOCK_REALTIME => 1, - __WASI_CLOCK_PROCESS_CPUTIME_ID => { - return Err(__WASI_EINVAL); + wasi_snapshot0::Clockid::Realtime => 1, + wasi_snapshot0::Clockid::ProcessCputimeId => { + return Err(wasi_snapshot0::Errno::Inval); } - __WASI_CLOCK_THREAD_CPUTIME_ID => { - return Err(__WASI_EINVAL); + wasi_snapshot0::Clockid::ThreadCputimeId => { + return Err(wasi_snapshot0::Errno::Inval); } - _ => return Err(__WASI_EINVAL), + _ => return Err(wasi_snapshot0::Errno::Inval), }; Ok(resolution_val) } pub fn platform_clock_time_get( - clock_id: __wasi_clockid_t, + clock_id: wasi_snapshot0::Clockid, precision: __wasi_timestamp_t, -) -> Result { +) -> Result { let nanos = match clock_id { - __WASI_CLOCK_MONOTONIC => { + wasi_snapshot0::Clockid::MONOTONIC => { let tick_ms = unsafe { winapi::um::sysinfoapi::GetTickCount64() }; tick_ms * 1_000_000 } - __WASI_CLOCK_REALTIME => { + wasi_snapshot0::Clockid::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_snapshot0::Errno::Io })?; duration.as_nanos() as u64 } - __WASI_CLOCK_PROCESS_CPUTIME_ID => { - unimplemented!("wasi::platform_clock_time_get(__WASI_CLOCK_PROCESS_CPUTIME_ID, ..)") + wasi_snapshot0::Clockid::ProcessCputimeId => { + unimplemented!( + "wasi::platform_clock_time_get(wasi_snapshot0::Clockid::ProcessCputimeId, ..)" + ) } - __WASI_CLOCK_THREAD_CPUTIME_ID => { - unimplemented!("wasi::platform_clock_time_get(__WASI_CLOCK_THREAD_CPUTIME_ID, ..)") + wasi_snapshot0::Clockid::ThreadCputimeId => { + unimplemented!( + "wasi::platform_clock_time_get(wasi_snapshot0::Clockid::ThreadCputimeId, ..)" + ) } - _ => return Err(__WASI_EINVAL), + _ => return Err(wasi_snapshot0::Errno::Inval), }; Ok(nanos as i64) } From 5207cc126d25530f2b40540b2b1c9c0924964ed0 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Thu, 18 Aug 2022 07:32:29 +0200 Subject: [PATCH 14/84] WIP: Dirent struct --- lib/api/src/js/native.rs | 1 - lib/wasi-types-generated/src/bindings.rs | 97 +++++++++++++++++++ .../wit/wasi-snapshot0.wit | 44 ++++----- lib/wasi-types/src/directory.rs | 22 +---- lib/wasi-types/src/event.rs | 2 +- lib/wasi-types/src/file.rs | 2 +- lib/wasi/src/syscalls/mod.rs | 10 +- lib/wasi/src/syscalls/wasix32.rs | 2 +- lib/wasi/src/syscalls/wasix64.rs | 2 +- 9 files changed, 133 insertions(+), 49 deletions(-) diff --git a/lib/api/src/js/native.rs b/lib/api/src/js/native.rs index 0e9066edac8..69b350652a1 100644 --- a/lib/api/src/js/native.rs +++ b/lib/api/src/js/native.rs @@ -11,7 +11,6 @@ use std::marker::PhantomData; use crate::js::externals::Function; use crate::js::store::{AsStoreMut, AsStoreRef, StoreHandle}; -use crate::js::FunctionEnv; use crate::js::{FromToNativeWasmType, RuntimeError, WasmTypeList}; // use std::panic::{catch_unwind, AssertUnwindSafe}; use crate::js::export::VMFunction; diff --git a/lib/wasi-types-generated/src/bindings.rs b/lib/wasi-types-generated/src/bindings.rs index 12a8b3a672b..d13c890f1f9 100644 --- a/lib/wasi-types-generated/src/bindings.rs +++ b/lib/wasi-types-generated/src/bindings.rs @@ -486,6 +486,12 @@ pub mod wasi_snapshot0 { Ok(())} } + /// 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; /// The type of a file descriptor or file. #[repr(u8)] #[derive(Clone, Copy, PartialEq, Eq)] @@ -537,6 +543,23 @@ pub mod wasi_snapshot0 { } } } + /// 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 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 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-namlen", &self.d_namlen).field("d-type", &self.d_type).finish()} + } /// File or memory access pattern advisory information. #[repr(u8)] #[derive(Clone, Copy, PartialEq, Eq)] @@ -674,6 +697,80 @@ pub mod wasi_snapshot0 { Ok(())} } + + /// Auxiliary data associated with the wasm exports. + #[derive(Default)] + pub struct WasiSnapshot0Data { + } + + pub struct WasiSnapshot0 { + #[allow(dead_code)] + env: wasmer::FunctionEnv, + func_dirent_dummy_func: wasmer::TypedFunction<(i64,i64,i32,i32,), ()>, + } + impl WasiSnapshot0 { + #[allow(unused_variables)] + + /// Adds any intrinsics, if necessary for this exported wasm + /// functionality to the `ImportObject` provided. + /// + /// This function returns the `WasiSnapshot0Data` which needs to be + /// passed through to `WasiSnapshot0::new`. + fn add_to_imports( + mut store: impl wasmer::AsStoreMut, + imports: &mut wasmer::Imports, + ) -> wasmer::FunctionEnv { + let env = wasmer::FunctionEnv::new(&mut store, WasiSnapshot0Data::default()); + env + } + + /// Instantiates the provided `module` using the specified + /// parameters, wrapping up the result in a structure that + /// translates between wasm and the host. + /// + /// The `imports` provided will have intrinsics added to it + /// automatically, so it's not necessary to call + /// `add_to_imports` beforehand. This function will + /// instantiate the `module` otherwise using `imports`, and + /// both an instance of this structure and the underlying + /// `wasmer::Instance` will be returned. + pub fn instantiate( + mut store: impl wasmer::AsStoreMut, + module: &wasmer::Module, + imports: &mut wasmer::Imports, + ) -> anyhow::Result<(Self, wasmer::Instance)> { + let env = Self::add_to_imports(&mut store, imports); + let instance = wasmer::Instance::new( + &mut store, module, &*imports)?; + + Ok((Self::new(store, &instance, env)?, instance)) + } + + /// Low-level creation wrapper for wrapping up the exports + /// of the `instance` provided in this structure of wasm + /// exports. + /// + /// This function will extract exports from the `instance` + /// and wrap them all up in the returned structure which can + /// be used to interact with the wasm module. + pub fn new( + store: impl wasmer::AsStoreMut, + _instance: &wasmer::Instance, + env: wasmer::FunctionEnv, + ) -> Result { + let func_dirent_dummy_func= _instance.exports.get_typed_function(&store, "dirent-dummy-func")?; + Ok(WasiSnapshot0{ + func_dirent_dummy_func, + env, + }) + } + /// Dummy function to expose dirent into generated code + pub fn dirent_dummy_func(&self, store: &mut wasmer::Store,d: Dirent,)-> Result<(), wasmer::RuntimeError> { + let Dirent{ d_next:d_next0, d_ino:d_ino0, d_namlen:d_namlen0, d_type:d_type0, } = d; + self.func_dirent_dummy_func.call(store, wit_bindgen_wasmer::rt::as_i64(d_next0), wit_bindgen_wasmer::rt::as_i64(d_ino0), wit_bindgen_wasmer::rt::as_i32(d_namlen0), d_type0 as i32, )?; + Ok(()) + } + } #[allow(unused_imports)] use wasmer::AsStoreMut as _; #[allow(unused_imports)] diff --git a/lib/wasi-types-generated/wit/wasi-snapshot0.wit b/lib/wasi-types-generated/wit/wasi-snapshot0.wit index 8618b208649..13693d060eb 100644 --- a/lib/wasi-types-generated/wit/wasi-snapshot0.wit +++ b/lib/wasi-types-generated/wit/wasi-snapshot0.wit @@ -335,15 +335,15 @@ flags rights { // $set // ) // ) -// -// ;;; A reference to the offset of a directory entry. -// (typename $dircookie u64) -// -// ;;; The type for the `dirent::d_namlen` field of `dirent` struct. -// (typename $dirnamlen u32) -// -// ;;; File serial number that is unique within its file system. -// (typename $inode u64) + +/// A reference to the offset of a directory entry. +type dircookie = u64 + +/// 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 /// The type of a file descriptor or file. enum filetype { @@ -367,19 +367,19 @@ enum filetype { symbolic-link, } -// ;;; A directory entry. -// (typename $dirent -// (record -// ;;; The offset of the next directory entry stored in this directory. -// (field $d_next $dircookie) -// ;;; The serial number of the file referred to by this directory entry. -// (field $d_ino $inode) -// ;;; The length of the name of the directory entry. -// (field $d_namlen $dirnamlen) -// ;;; The type of the file referred to by this directory entry. -// (field $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 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, +} +/// Dummy function to expose dirent into generated code +dirent-dummy-func: func(d: dirent) /// File or memory access pattern advisory information. enum advice { diff --git a/lib/wasi-types/src/directory.rs b/lib/wasi-types/src/directory.rs index 360bdf076b8..585fcff762a 100644 --- a/lib/wasi-types/src/directory.rs +++ b/lib/wasi-types/src/directory.rs @@ -1,21 +1,9 @@ -use crate::*; use std::mem; -use wasmer_derive::ValueType; use wasmer_wasi_types_generated::wasi_snapshot0; -pub type __wasi_dircookie_t = u64; -pub const __WASI_DIRCOOKIE_START: u64 = 0; +pub const __WASI_DIRCOOKIE_START: wasi_snapshot0::Dircookie = 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_snapshot0::Filetype, -} - -pub fn dirent_to_le_bytes(ent: &__wasi_dirent_t) -> Vec { +pub fn dirent_to_le_bytes(ent: &wasi_snapshot0::Dirent) -> Vec { let out: Vec = std::iter::empty() .chain(ent.d_next.to_le_bytes()) .chain(ent.d_ino.to_le_bytes()) @@ -23,18 +11,18 @@ pub fn dirent_to_le_bytes(ent: &__wasi_dirent_t) -> Vec { .chain(u32::from(ent.d_type as u8).to_le_bytes()) .collect(); - assert_eq!(out.len(), mem::size_of::<__wasi_dirent_t>()); + assert_eq!(out.len(), mem::size_of::()); out } #[cfg(test)] mod tests { - use super::{__wasi_dirent_t, dirent_to_le_bytes}; + use super::dirent_to_le_bytes; use wasmer_wasi_types_generated::wasi_snapshot0; #[test] fn test_dirent_to_le_bytes() { - let s = __wasi_dirent_t { + let s = wasi_snapshot0::Dirent { d_next: 0x0123456789abcdef, d_ino: 0xfedcba9876543210, d_namlen: 0xaabbccdd, diff --git a/lib/wasi-types/src/event.rs b/lib/wasi-types/src/event.rs index 833d6b0ecd0..fc7360e7ed0 100644 --- a/lib/wasi-types/src/event.rs +++ b/lib/wasi-types/src/event.rs @@ -5,7 +5,7 @@ use std::{ }; use wasmer_derive::ValueType; use wasmer_types::ValueType; -use wasmer_wasi_types_generated::{wasi_filesystem, wasi_snapshot0}; +use wasmer_wasi_types_generated::wasi_snapshot0; #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] #[repr(C)] diff --git a/lib/wasi-types/src/file.rs b/lib/wasi-types/src/file.rs index ea26e23aa2c..816703ed348 100644 --- a/lib/wasi-types/src/file.rs +++ b/lib/wasi-types/src/file.rs @@ -5,7 +5,7 @@ use std::{ }; use wasmer_derive::ValueType; use wasmer_types::ValueType; -use wasmer_wasi_types_generated::{wasi_filesystem, wasi_snapshot0}; +use wasmer_wasi_types_generated::wasi_snapshot0; pub type __wasi_device_t = u64; diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 2734ff0efcd..a763e3fbf18 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -1303,7 +1303,7 @@ pub fn fd_read( /// Buffer where directory entries are stored /// - `u32 buf_len` /// Length of data in `buf` -/// - `__wasi_dircookie_t cookie` +/// - `wasi_snapshot0::Dircookie cookie` /// Where the directory reading should start from /// Output: /// - `u32 *bufused` @@ -1314,7 +1314,7 @@ pub fn fd_readdir( fd: __wasi_fd_t, buf: WasmPtr, buf_len: M::Offset, - cookie: __wasi_dircookie_t, + cookie: wasi_snapshot0::Dircookie, bufused: WasmPtr, ) -> wasi_snapshot0::Errno { trace!("wasi::fd_readdir"); @@ -1402,7 +1402,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 = wasi_snapshot0::Dirent { d_next: cur_cookie, d_ino: *ino, d_namlen: namlen as u32, @@ -1412,13 +1412,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); diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index 20632dc2752..8c55e699e3c 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -188,7 +188,7 @@ pub(crate) fn fd_readdir( fd: __wasi_fd_t, buf: WasmPtr, buf_len: MemoryOffset, - cookie: __wasi_dircookie_t, + cookie: wasi_snapshot0::Dircookie, bufused: WasmPtr, ) -> wasi_snapshot0::Errno { super::fd_readdir::(ctx, fd, buf, buf_len, cookie, bufused) diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index 111aee73090..da01d923e4d 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -188,7 +188,7 @@ pub(crate) fn fd_readdir( fd: __wasi_fd_t, buf: WasmPtr, buf_len: MemoryOffset, - cookie: __wasi_dircookie_t, + cookie: wasi_snapshot0::Dircookie, bufused: WasmPtr, ) -> wasi_snapshot0::Errno { super::fd_readdir::(ctx, fd, buf, buf_len, cookie, bufused) From a3deb19844a9277e60a87452cfbde1334a636874 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Thu, 18 Aug 2022 09:06:48 +0200 Subject: [PATCH 15/84] WIP: Fdflags --- lib/wasi-types-generated/src/lib.rs | 24 ++++++ .../wit/wasi-snapshot0.wit | 5 +- lib/wasi-types/src/file.rs | 9 +-- lib/wasi/src/state/mod.rs | 53 +++++++++----- lib/wasi/src/state/socket.rs | 4 +- lib/wasi/src/syscalls/mod.rs | 73 ++++++++++++++----- lib/wasi/src/syscalls/wasi.rs | 4 +- lib/wasi/src/syscalls/wasix32.rs | 6 +- lib/wasi/src/syscalls/wasix64.rs | 6 +- 9 files changed, 129 insertions(+), 55 deletions(-) diff --git a/lib/wasi-types-generated/src/lib.rs b/lib/wasi-types-generated/src/lib.rs index 193b9329dac..ad0657a79a8 100644 --- a/lib/wasi-types-generated/src/lib.rs +++ b/lib/wasi-types-generated/src/lib.rs @@ -47,6 +47,12 @@ unsafe impl ValueType for wasi_snapshot0::Clockid { fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for wasi_snapshot0::Fdflags { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + // TODO: if necessary, must be implemented in wit-bindgen unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0::Errno { type Native = i32; @@ -250,3 +256,21 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0: false } } + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0::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 u8) + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} diff --git a/lib/wasi-types-generated/wit/wasi-snapshot0.wit b/lib/wasi-types-generated/wit/wasi-snapshot0.wit index 13693d060eb..154e7eb18d0 100644 --- a/lib/wasi-types-generated/wit/wasi-snapshot0.wit +++ b/lib/wasi-types-generated/wit/wasi-snapshot0.wit @@ -402,8 +402,9 @@ enum advice { /// File descriptor flags. flags fdflags { - // TODO: wit appears to not have support for flag type size - //flags (@witx repr u16) + // TODO: wit appears to not have support for flag type size + //flags (@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. diff --git a/lib/wasi-types/src/file.rs b/lib/wasi-types/src/file.rs index 816703ed348..7c1b01c4abc 100644 --- a/lib/wasi-types/src/file.rs +++ b/lib/wasi-types/src/file.rs @@ -17,13 +17,6 @@ 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; @@ -121,7 +114,7 @@ unsafe impl ValueType for __wasi_prestat_t { #[repr(C)] pub struct __wasi_fdstat_t { pub fs_filetype: wasi_snapshot0::Filetype, - pub fs_flags: __wasi_fdflags_t, + pub fs_flags: wasi_snapshot0::Fdflags, pub fs_rights_base: wasi_snapshot0::Rights, pub fs_rights_inheriting: wasi_snapshot0::Rights, } diff --git a/lib/wasi/src/state/mod.rs b/lib/wasi/src/state/mod.rs index 76b6bb1e8ec..89fa7f24415 100644 --- a/lib/wasi/src/state/mod.rs +++ b/lib/wasi/src/state/mod.rs @@ -73,9 +73,8 @@ const STDIN_DEFAULT_RIGHTS: wasi_snapshot0::Rights = { ) }; const STDOUT_DEFAULT_RIGHTS: wasi_snapshot0::Rights = { - // Not sure it is possible to use the bitflags consts directly in a - // const environment, found no way to do so, therefore the flags are - // duplicated below. + // This might seem a bit overenineered, but it's the only way I + // discovered for getting the values in a const environment wasi_snapshot0::Rights::from_bits_truncate( wasi_snapshot0::Rights::FD_DATASYNC.bits() | wasi_snapshot0::Rights::FD_SYNC.bits() @@ -188,7 +187,7 @@ pub enum Kind { pub struct Fd { pub rights: wasi_snapshot0::Rights, pub rights_inheriting: wasi_snapshot0::Rights, - pub flags: __wasi_fdflags_t, + pub flags: wasi_snapshot0::Fdflags, pub offset: u64, /// Flags that determine how the [`Fd`] can be used. /// @@ -445,7 +444,13 @@ impl WasiFs { })?; let fd_flags = Fd::READ; let fd = wasi_fs - .create_fd(rights, rights, 0, fd_flags, inode) + .create_fd( + rights, + rights, + wasi_snapshot0::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(); @@ -565,7 +570,13 @@ impl WasiFs { fd_flags }; let fd = wasi_fs - .create_fd(rights, rights, 0, fd_flags, inode) + .create_fd( + rights, + rights, + wasi_snapshot0::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(); @@ -633,7 +644,13 @@ impl WasiFs { */; 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, + wasi_snapshot0::Fdflags::empty(), + Fd::READ, + inode, + ) .map_err(|e| format!("Could not create root fd: {}", e))?; wasi_fs.preopen_fds.write().unwrap().push(fd); inode @@ -664,7 +681,7 @@ impl WasiFs { name: String, rights: wasi_snapshot0::Rights, rights_inheriting: wasi_snapshot0::Rights, - flags: __wasi_fdflags_t, + flags: wasi_snapshot0::Fdflags, ) -> Result<__wasi_fd_t, FsError> { // TODO: check permissions here? probably not, but this should be // an explicit choice, so justify it in a comment when we remove this one @@ -741,7 +758,7 @@ impl WasiFs { name: String, rights: wasi_snapshot0::Rights, rights_inheriting: wasi_snapshot0::Rights, - flags: __wasi_fdflags_t, + flags: wasi_snapshot0::Fdflags, ) -> Result<__wasi_fd_t, FsError> { // TODO: check permissions here? probably not, but this should be // an explicit choice, so justify it in a comment when we remove this one @@ -1341,7 +1358,7 @@ impl WasiFs { __WASI_STDIN_FILENO => { return Ok(__wasi_fdstat_t { fs_filetype: wasi_snapshot0::Filetype::CharacterDevice, - fs_flags: 0, + fs_flags: wasi_snapshot0::Fdflags::empty(), fs_rights_base: STDIN_DEFAULT_RIGHTS, fs_rights_inheriting: wasi_snapshot0::Rights::empty(), }) @@ -1349,7 +1366,7 @@ impl WasiFs { __WASI_STDOUT_FILENO => { return Ok(__wasi_fdstat_t { fs_filetype: wasi_snapshot0::Filetype::CharacterDevice, - fs_flags: __WASI_FDFLAG_APPEND, + fs_flags: wasi_snapshot0::Fdflags::APPEND, fs_rights_base: STDOUT_DEFAULT_RIGHTS, fs_rights_inheriting: wasi_snapshot0::Rights::empty(), }) @@ -1357,7 +1374,7 @@ impl WasiFs { __WASI_STDERR_FILENO => { return Ok(__wasi_fdstat_t { fs_filetype: wasi_snapshot0::Filetype::CharacterDevice, - fs_flags: __WASI_FDFLAG_APPEND, + fs_flags: wasi_snapshot0::Fdflags::APPEND, fs_rights_base: STDERR_DEFAULT_RIGHTS, fs_rights_inheriting: wasi_snapshot0::Rights::empty(), }) @@ -1365,7 +1382,7 @@ impl WasiFs { VIRTUAL_ROOT_FD => { return Ok(__wasi_fdstat_t { fs_filetype: wasi_snapshot0::Filetype::Directory, - fs_flags: 0, + fs_flags: wasi_snapshot0::Fdflags::empty(), // TODO: fix this fs_rights_base: ALL_RIGHTS, fs_rights_inheriting: ALL_RIGHTS, @@ -1504,7 +1521,7 @@ impl WasiFs { &self, rights: wasi_snapshot0::Rights, rights_inheriting: wasi_snapshot0::Rights, - flags: __wasi_fdflags_t, + flags: wasi_snapshot0::Fdflags, open_flags: u16, inode: Inode, ) -> Result<__wasi_fd_t, wasi_snapshot0::Errno> { @@ -1577,7 +1594,7 @@ impl WasiFs { "stdout", __WASI_STDOUT_FILENO, STDOUT_DEFAULT_RIGHTS, - __WASI_FDFLAG_APPEND, + wasi_snapshot0::Fdflags::APPEND, ); } fn create_stdin(&self, inodes: &mut WasiInodes) { @@ -1587,7 +1604,7 @@ impl WasiFs { "stdin", __WASI_STDIN_FILENO, STDIN_DEFAULT_RIGHTS, - 0, + wasi_snapshot0::Fdflags::empty(), ); } fn create_stderr(&self, inodes: &mut WasiInodes) { @@ -1597,7 +1614,7 @@ impl WasiFs { "stderr", __WASI_STDERR_FILENO, STDERR_DEFAULT_RIGHTS, - __WASI_FDFLAG_APPEND, + wasi_snapshot0::Fdflags::APPEND, ); } @@ -1608,7 +1625,7 @@ impl WasiFs { name: &'static str, raw_fd: __wasi_fd_t, rights: wasi_snapshot0::Rights, - fd_flags: __wasi_fdflags_t, + fd_flags: wasi_snapshot0::Fdflags, ) { let stat = __wasi_filestat_t { st_filetype: wasi_snapshot0::Filetype::CharacterDevice, diff --git a/lib/wasi/src/state/socket.rs b/lib/wasi/src/state/socket.rs index 6a14837b699..bc78d481695 100644 --- a/lib/wasi/src/state/socket.rs +++ b/lib/wasi/src/state/socket.rs @@ -249,7 +249,7 @@ impl InodeSocket { pub fn accept( &self, - _fd_flags: __wasi_fdflags_t, + _fd_flags: wasi_snapshot0::Fdflags, ) -> Result<(Box, SocketAddr), wasi_snapshot0::Errno> { let (sock, addr) = match &self.kind { InodeSocketKind::TcpListener(sock) => sock.accept().map_err(net_error_into_wasi_err), @@ -262,7 +262,7 @@ impl InodeSocket { pub fn accept_timeout( &self, - _fd_flags: __wasi_fdflags_t, + _fd_flags: wasi_snapshot0::Fdflags, timeout: Duration, ) -> Result<(Box, SocketAddr), wasi_snapshot0::Errno> { let (sock, addr) = match &self.kind { diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index a763e3fbf18..32e5b638b0b 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -642,12 +642,12 @@ pub fn fd_fdstat_get( /// Inputs: /// - `__wasi_fd_t fd` /// The file descriptor to apply the new flags to -/// - `__wasi_fdflags_t flags` +/// - `wasi_snapshot0::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, + flags: wasi_snapshot0::Fdflags, ) -> wasi_snapshot0::Errno { debug!("wasi::fd_fdstat_set_flags"); let env = ctx.data(); @@ -1184,7 +1184,7 @@ pub fn fd_read( return Ok(wasi_snapshot0::Errno::Acces); } - let is_non_blocking = fd_entry.flags & __WASI_FDFLAG_NONBLOCK != 0; + let is_non_blocking = fd_entry.flags.contains(wasi_snapshot0::Fdflags::NONBLOCK); let offset = fd_entry.offset as usize; let inode_idx = fd_entry.inode; let inode = &inodes.arena[inode_idx]; @@ -1520,7 +1520,10 @@ pub fn fd_event( let rights = wasi_snapshot0::Rights::FD_READ | wasi_snapshot0::Rights::FD_WRITE | wasi_snapshot0::Rights::POLL_FD_READWRITE; - let fd = wasi_try!(state.fs.create_fd(rights, rights, 0, 0, inode)); + let fd = + wasi_try!(state + .fs + .create_fd(rights, rights, wasi_snapshot0::Fdflags::empty(), 0, inode)); wasi_try_mem!(ret_fd.write(&memory, fd)); @@ -1863,8 +1866,14 @@ pub fn fd_pipe( ); 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 fd1 = + wasi_try!(state + .fs + .create_fd(rights, rights, wasi_snapshot0::Fdflags::empty(), 0, inode1)); + let fd2 = + wasi_try!(state + .fs + .create_fd(rights, rights, wasi_snapshot0::Fdflags::empty(), 0, inode2)); wasi_try_mem!(ro_fd1.write(&memory, fd1)); wasi_try_mem!(ro_fd2.write(&memory, fd2)); @@ -2283,7 +2292,7 @@ pub fn path_link( /// The rights of the created file descriptor /// - `wasi_snapshot0::Rights fs_rightsinheriting` /// The rights of file descriptors derived from the created file descriptor -/// - `__wasi_fdflags_t fs_flags` +/// - `wasi_snapshot0::Fdflags fs_flags` /// The flags of the file descriptor /// Output: /// - `__wasi_fd_t* fd` @@ -2299,7 +2308,7 @@ pub fn path_open( o_flags: __wasi_oflags_t, fs_rights_base: wasi_snapshot0::Rights, fs_rights_inheriting: wasi_snapshot0::Rights, - fs_flags: __wasi_fdflags_t, + fs_flags: wasi_snapshot0::Fdflags, fd: WasmPtr<__wasi_fd_t, M>, ) -> wasi_snapshot0::Errno { debug!("wasi::path_open"); @@ -2378,7 +2387,7 @@ pub fn path_open( let (append_permission, truncate_permission, create_permission) = if write_permission { ( - fs_flags & __WASI_FDFLAG_APPEND != 0, + fs_flags.contains(wasi_snapshot0::Fdflags::APPEND), o_flags & __WASI_O_TRUNC != 0, o_flags & __WASI_O_CREAT != 0, ) @@ -2457,7 +2466,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(wasi_snapshot0::Fdflags::APPEND)) // TODO: ensure these rights are actually valid given parent, etc. // write access is required for creating a file .write(true) @@ -4245,7 +4254,10 @@ pub fn ws_connect( "socket".to_string(), ); let rights = super::state::all_socket_rights(); - let fd = wasi_try!(state.fs.create_fd(rights, rights, 0, 0, inode)); + let fd = + wasi_try!(state + .fs + .create_fd(rights, rights, wasi_snapshot0::Fdflags::empty(), 0, inode)); wasi_try_mem!(ret_sock.write(&memory, fd)); @@ -4357,9 +4369,27 @@ pub fn http_request( let rights = super::state::all_socket_rights(); 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)), + req: wasi_try!(state.fs.create_fd( + rights, + rights, + wasi_snapshot0::Fdflags::empty(), + 0, + inode_req + )), + res: wasi_try!(state.fs.create_fd( + rights, + rights, + wasi_snapshot0::Fdflags::empty(), + 0, + inode_res + )), + hdr: wasi_try!(state.fs.create_fd( + rights, + rights, + wasi_snapshot0::Fdflags::empty(), + 0, + inode_hdr + )), }; wasi_try_mem!(ret_handles.write(&memory, handles)); @@ -4886,7 +4916,10 @@ pub fn sock_open( "socket".to_string(), ); let rights = super::state::all_socket_rights(); - let fd = wasi_try!(state.fs.create_fd(rights, rights, 0, 0, inode)); + let fd = + wasi_try!(state + .fs + .create_fd(rights, rights, wasi_snapshot0::Fdflags::empty(), 0, inode)); wasi_try_mem!(ro_sock.write(&memory, fd)); @@ -5327,7 +5360,7 @@ pub fn sock_listen( pub fn sock_accept( ctx: FunctionEnvMut<'_, WasiEnv>, sock: __wasi_fd_t, - fd_flags: __wasi_fdflags_t, + fd_flags: wasi_snapshot0::Fdflags, ro_fd: WasmPtr<__wasi_fd_t, M>, ro_addr: WasmPtr<__wasi_addr_port_t, M>, ) -> Result { @@ -5375,7 +5408,13 @@ pub fn sock_accept( ); let rights = super::state::all_socket_rights(); - let fd = wasi_try_ok!(state.fs.create_fd(rights, rights, 0, 0, inode)); + let fd = wasi_try_ok!(state.fs.create_fd( + rights, + rights, + wasi_snapshot0::Fdflags::empty(), + 0, + inode + )); wasi_try_mem_ok!(ro_fd.write(&memory, fd)); wasi_try_ok!(super::state::write_ip_port( diff --git a/lib/wasi/src/syscalls/wasi.rs b/lib/wasi/src/syscalls/wasi.rs index 6e8b733866c..d49b6a29731 100644 --- a/lib/wasi/src/syscalls/wasi.rs +++ b/lib/wasi/src/syscalls/wasi.rs @@ -93,7 +93,7 @@ pub(crate) fn fd_fdstat_get( pub(crate) fn fd_fdstat_set_flags( ctx: FunctionEnvMut, fd: __wasi_fd_t, - flags: __wasi_fdflags_t, + flags: wasi_snapshot0::Fdflags, ) -> wasi_snapshot0::Errno { super::fd_fdstat_set_flags(ctx, fd, flags) } @@ -299,7 +299,7 @@ pub(crate) fn path_open( o_flags: __wasi_oflags_t, fs_rights_base: __wasi_rights_t, fs_rights_inheriting: __wasi_rights_t, - fs_flags: __wasi_fdflags_t, + fs_flags: wasi_snapshot0::Fdflags, fd: WasmPtr<__wasi_fd_t, MemoryType>, ) -> wasi_snapshot0::Errno { super::path_open::( diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index 8c55e699e3c..cf0903c6217 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -94,7 +94,7 @@ pub(crate) fn fd_fdstat_get( pub(crate) fn fd_fdstat_set_flags( ctx: FunctionEnvMut, fd: __wasi_fd_t, - flags: __wasi_fdflags_t, + flags: wasi_snapshot0::Fdflags, ) -> wasi_snapshot0::Errno { super::fd_fdstat_set_flags(ctx, fd, flags) } @@ -300,7 +300,7 @@ pub(crate) fn path_open( o_flags: __wasi_oflags_t, fs_rights_base: wasi_snapshot0::Rights, fs_rights_inheriting: wasi_snapshot0::Rights, - fs_flags: __wasi_fdflags_t, + fs_flags: wasi_snapshot0::Fdflags, fd: WasmPtr<__wasi_fd_t, MemoryType>, ) -> wasi_snapshot0::Errno { super::path_open::( @@ -946,7 +946,7 @@ pub(crate) fn sock_listen( pub(crate) fn sock_accept( ctx: FunctionEnvMut, sock: __wasi_fd_t, - fd_flags: __wasi_fdflags_t, + fd_flags: wasi_snapshot0::Fdflags, ro_fd: WasmPtr<__wasi_fd_t, MemoryType>, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ) -> Result { diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index da01d923e4d..a12a0e02950 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -94,7 +94,7 @@ pub(crate) fn fd_fdstat_get( pub(crate) fn fd_fdstat_set_flags( ctx: FunctionEnvMut, fd: __wasi_fd_t, - flags: __wasi_fdflags_t, + flags: wasi_snapshot0::Fdflags, ) -> wasi_snapshot0::Errno { super::fd_fdstat_set_flags(ctx, fd, flags) } @@ -300,7 +300,7 @@ pub(crate) fn path_open( o_flags: __wasi_oflags_t, fs_rights_base: wasi_snapshot0::Rights, fs_rights_inheriting: wasi_snapshot0::Rights, - fs_flags: __wasi_fdflags_t, + fs_flags: wasi_snapshot0::Fdflags, fd: WasmPtr<__wasi_fd_t, MemoryType>, ) -> wasi_snapshot0::Errno { super::path_open::( @@ -946,7 +946,7 @@ pub(crate) fn sock_listen( pub(crate) fn sock_accept( ctx: FunctionEnvMut, sock: __wasi_fd_t, - fd_flags: __wasi_fdflags_t, + fd_flags: wasi_snapshot0::Fdflags, ro_fd: WasmPtr<__wasi_fd_t, MemoryType>, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ) -> Result { From 7e8b835d0386553d34f391ab726e5061f59d847a Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Thu, 18 Aug 2022 09:34:44 +0200 Subject: [PATCH 16/84] WIP: Preopentype --- lib/wasi-types-generated/src/bindings.rs | 16 +++++++++++ lib/wasi-types-generated/src/lib.rs | 28 +++++++++++++++++++ .../wit/wasi-snapshot0.wit | 18 ++++++------ lib/wasi-types/src/file.rs | 11 ++------ lib/wasi/src/state/mod.rs | 2 +- 5 files changed, 57 insertions(+), 18 deletions(-) diff --git a/lib/wasi-types-generated/src/bindings.rs b/lib/wasi-types-generated/src/bindings.rs index d13c890f1f9..be69865e293 100644 --- a/lib/wasi-types-generated/src/bindings.rs +++ b/lib/wasi-types-generated/src/bindings.rs @@ -697,6 +697,22 @@ pub mod wasi_snapshot0 { Ok(())} } + /// 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() + } + } + } + } /// Auxiliary data associated with the wasm exports. #[derive(Default)] diff --git a/lib/wasi-types-generated/src/lib.rs b/lib/wasi-types-generated/src/lib.rs index ad0657a79a8..2a3866ba5e8 100644 --- a/lib/wasi-types-generated/src/lib.rs +++ b/lib/wasi-types-generated/src/lib.rs @@ -53,6 +53,12 @@ unsafe impl ValueType for wasi_snapshot0::Fdflags { fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for wasi_snapshot0::Preopentype { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + // TODO: if necessary, must be implemented in wit-bindgen unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0::Errno { type Native = i32; @@ -274,3 +280,25 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0: false } } + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0::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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} diff --git a/lib/wasi-types-generated/wit/wasi-snapshot0.wit b/lib/wasi-types-generated/wit/wasi-snapshot0.wit index 154e7eb18d0..68e7d287d2d 100644 --- a/lib/wasi-types-generated/wit/wasi-snapshot0.wit +++ b/lib/wasi-types-generated/wit/wasi-snapshot0.wit @@ -749,15 +749,15 @@ flags subclockflags { // $wr // ) // ) -// -// ;;; Identifiers for preopened capabilities. -// (typename $preopentype -// (enum (@witx tag u8) -// ;;; A pre-opened directory. -// $dir -// ) -// ) -// + +/// Identifiers for preopened capabilities. +enum preopentype { + // TODO: wit appears to not have support for enum type size + // enum (@witx tag u8) + /// A pre-opened directory. + dir, +} + // ;;; The contents of a $prestat when type is `preopentype::dir`. // (typename $prestat_dir // (record diff --git a/lib/wasi-types/src/file.rs b/lib/wasi-types/src/file.rs index 7c1b01c4abc..7bcb2243daa 100644 --- a/lib/wasi-types/src/file.rs +++ b/lib/wasi-types/src/file.rs @@ -20,9 +20,6 @@ pub type __wasi_tid_t = u32; 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 { @@ -44,7 +41,7 @@ impl fmt::Debug for __wasi_prestat_u { #[derive(Debug, Copy, Clone)] #[repr(C)] pub struct __wasi_prestat_t { - pub pr_type: __wasi_preopentype_t, + pub pr_type: wasi_snapshot0::Preopentype, pub u: __wasi_prestat_u, } @@ -67,10 +64,9 @@ 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 { + wasi_snapshot0::Preopentype::Dir => Some(PrestatEnum::Dir { pr_name_len: unsafe { self.u.dir.pr_name_len }, }), - _ => None, } } } @@ -98,13 +94,12 @@ unsafe impl ValueType for __wasi_prestat_t { .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 { + wasi_snapshot0::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)); } diff --git a/lib/wasi/src/state/mod.rs b/lib/wasi/src/state/mod.rs index 89fa7f24415..650e6afd071 100644 --- a/lib/wasi/src/state/mod.rs +++ b/lib/wasi/src/state/mod.rs @@ -1427,7 +1427,7 @@ impl WasiFs { pub(crate) fn prestat_fd_inner(&self, inode_val: &InodeVal) -> __wasi_prestat_t { __wasi_prestat_t { - pr_type: __WASI_PREOPENTYPE_DIR, + pr_type: wasi_snapshot0::Preopentype::Dir, u: PrestatEnum::Dir { // REVIEW: pr_name_len: inode_val.name.len() as u32 + 1, From 39fad86200b9a3612b470341a73606d055542ee3 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Thu, 18 Aug 2022 10:11:24 +0200 Subject: [PATCH 17/84] WIP: Fdstat --- lib/wasi-types-generated/src/bindings.rs | 30 +++++++++++++++ lib/wasi-types-generated/src/lib.rs | 38 +++++++++++++++++++ .../wit/wasi-snapshot0.wit | 2 + lib/wasi-types/src/file.rs | 9 ----- lib/wasi/src/state/mod.rs | 12 +++--- lib/wasi/src/syscalls/mod.rs | 4 +- lib/wasi/src/syscalls/wasi.rs | 2 +- lib/wasi/src/syscalls/wasix32.rs | 2 +- lib/wasi/src/syscalls/wasix64.rs | 2 +- 9 files changed, 81 insertions(+), 20 deletions(-) diff --git a/lib/wasi-types-generated/src/bindings.rs b/lib/wasi-types-generated/src/bindings.rs index be69865e293..0cad9ddb4db 100644 --- a/lib/wasi-types-generated/src/bindings.rs +++ b/lib/wasi-types-generated/src/bindings.rs @@ -628,6 +628,24 @@ pub mod wasi_snapshot0 { Ok(())} } + /// 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()} + } /// Type of a subscription to an event or its occurrence. #[repr(u8)] #[derive(Clone, Copy, PartialEq, Eq)] @@ -723,6 +741,7 @@ pub mod wasi_snapshot0 { #[allow(dead_code)] env: wasmer::FunctionEnv, func_dirent_dummy_func: wasmer::TypedFunction<(i64,i64,i32,i32,), ()>, + func_fdstat_dummy_func: wasmer::TypedFunction<(i32,i32,i32,i32,i32,i32,), ()>, } impl WasiSnapshot0 { #[allow(unused_variables)] @@ -775,8 +794,10 @@ pub mod wasi_snapshot0 { env: wasmer::FunctionEnv, ) -> Result { let func_dirent_dummy_func= _instance.exports.get_typed_function(&store, "dirent-dummy-func")?; + let func_fdstat_dummy_func= _instance.exports.get_typed_function(&store, "fdstat-dummy-func")?; Ok(WasiSnapshot0{ func_dirent_dummy_func, + func_fdstat_dummy_func, env, }) } @@ -786,6 +807,15 @@ pub mod wasi_snapshot0 { self.func_dirent_dummy_func.call(store, wit_bindgen_wasmer::rt::as_i64(d_next0), wit_bindgen_wasmer::rt::as_i64(d_ino0), wit_bindgen_wasmer::rt::as_i32(d_namlen0), d_type0 as i32, )?; Ok(()) } + /// Dummy function to expose fdstat into generated code + pub fn fdstat_dummy_func(&self, store: &mut wasmer::Store,d: Fdstat,)-> Result<(), wasmer::RuntimeError> { + let Fdstat{ fs_filetype:fs_filetype0, fs_flags:fs_flags0, fs_rights_base:fs_rights_base0, fs_rights_inheriting:fs_rights_inheriting0, } = d; + let flags1 = fs_flags0; + let flags2 = fs_rights_base0; + let flags3 = fs_rights_inheriting0; + self.func_fdstat_dummy_func.call(store, fs_filetype0 as i32, (flags1.bits >> 0) as i32, (flags2.bits >> 0) as i32, (flags2.bits >> 32) as i32, (flags3.bits >> 0) as i32, (flags3.bits >> 32) as i32, )?; + Ok(()) + } } #[allow(unused_imports)] use wasmer::AsStoreMut as _; diff --git a/lib/wasi-types-generated/src/lib.rs b/lib/wasi-types-generated/src/lib.rs index 2a3866ba5e8..947ae274af8 100644 --- a/lib/wasi-types-generated/src/lib.rs +++ b/lib/wasi-types-generated/src/lib.rs @@ -59,6 +59,44 @@ unsafe impl ValueType for wasi_snapshot0::Preopentype { fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for wasi_snapshot0::Fdstat { + 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)*) + std::mem::size_of_val(&self.$($f)*) + }; + } + macro_rules! zero { + ($start:expr, $end:expr) => { + for i in $start..$end { + bytes[i] = MaybeUninit::new(0); + } + }; + } + + self.fs_filetype + .zero_padding_bytes(&mut bytes[field!(fs_filetype)..field_end!(fs_filetype)]); + zero!(field_end!(fs_filetype), field!(fs_flags)); + + self.fs_flags + .zero_padding_bytes(&mut bytes[field!(fs_flags)..field_end!(fs_flags)]); + zero!(field_end!(fs_flags), field!(fs_rights_base)); + + self.fs_rights_base + .zero_padding_bytes(&mut bytes[field!(fs_rights_base)..field_end!(fs_rights_base)]); + zero!( + field_end!(fs_rights_inheriting), + std::mem::size_of_val(self) + ); + } +} + // TODO: if necessary, must be implemented in wit-bindgen unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0::Errno { type Native = i32; diff --git a/lib/wasi-types-generated/wit/wasi-snapshot0.wit b/lib/wasi-types-generated/wit/wasi-snapshot0.wit index 68e7d287d2d..99b62b9cb90 100644 --- a/lib/wasi-types-generated/wit/wasi-snapshot0.wit +++ b/lib/wasi-types-generated/wit/wasi-snapshot0.wit @@ -434,6 +434,8 @@ record fdstat { /// are created through this file descriptor, e.g., through `path_open`. fs-rights-inheriting: rights, } +/// Dummy function to expose fdstat into generated code +fdstat-dummy-func: func(d: fdstat) // ;;; 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. diff --git a/lib/wasi-types/src/file.rs b/lib/wasi-types/src/file.rs index 7bcb2243daa..485eef5e4bf 100644 --- a/lib/wasi-types/src/file.rs +++ b/lib/wasi-types/src/file.rs @@ -105,15 +105,6 @@ unsafe impl ValueType for __wasi_prestat_t { } } -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_fdstat_t { - pub fs_filetype: wasi_snapshot0::Filetype, - pub fs_flags: wasi_snapshot0::Fdflags, - pub fs_rights_base: wasi_snapshot0::Rights, - pub fs_rights_inheriting: wasi_snapshot0::Rights, -} - pub type __wasi_filedelta_t = i64; pub type __wasi_filesize_t = u64; diff --git a/lib/wasi/src/state/mod.rs b/lib/wasi/src/state/mod.rs index 650e6afd071..9a7de8d3d5b 100644 --- a/lib/wasi/src/state/mod.rs +++ b/lib/wasi/src/state/mod.rs @@ -1353,10 +1353,10 @@ impl WasiFs { &self, inodes: &WasiInodes, fd: __wasi_fd_t, - ) -> Result<__wasi_fdstat_t, wasi_snapshot0::Errno> { + ) -> Result { match fd { __WASI_STDIN_FILENO => { - return Ok(__wasi_fdstat_t { + return Ok(wasi_snapshot0::Fdstat { fs_filetype: wasi_snapshot0::Filetype::CharacterDevice, fs_flags: wasi_snapshot0::Fdflags::empty(), fs_rights_base: STDIN_DEFAULT_RIGHTS, @@ -1364,7 +1364,7 @@ impl WasiFs { }) } __WASI_STDOUT_FILENO => { - return Ok(__wasi_fdstat_t { + return Ok(wasi_snapshot0::Fdstat { fs_filetype: wasi_snapshot0::Filetype::CharacterDevice, fs_flags: wasi_snapshot0::Fdflags::APPEND, fs_rights_base: STDOUT_DEFAULT_RIGHTS, @@ -1372,7 +1372,7 @@ impl WasiFs { }) } __WASI_STDERR_FILENO => { - return Ok(__wasi_fdstat_t { + return Ok(wasi_snapshot0::Fdstat { fs_filetype: wasi_snapshot0::Filetype::CharacterDevice, fs_flags: wasi_snapshot0::Fdflags::APPEND, fs_rights_base: STDERR_DEFAULT_RIGHTS, @@ -1380,7 +1380,7 @@ impl WasiFs { }) } VIRTUAL_ROOT_FD => { - return Ok(__wasi_fdstat_t { + return Ok(wasi_snapshot0::Fdstat { fs_filetype: wasi_snapshot0::Filetype::Directory, fs_flags: wasi_snapshot0::Fdflags::empty(), // TODO: fix this @@ -1395,7 +1395,7 @@ impl WasiFs { let guard = inodes.arena[fd.inode].read(); let deref = guard.deref(); - Ok(__wasi_fdstat_t { + Ok(wasi_snapshot0::Fdstat { fs_filetype: match deref { Kind::File { .. } => wasi_snapshot0::Filetype::RegularFile, Kind::Dir { .. } => wasi_snapshot0::Filetype::Directory, diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 32e5b638b0b..573390ff13a 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -614,12 +614,12 @@ pub fn fd_datasync(ctx: FunctionEnvMut<'_, WasiEnv>, fd: __wasi_fd_t) -> wasi_sn /// - `__wasi_fd_t fd` /// The file descriptor whose metadata will be accessed /// Output: -/// - `__wasi_fdstat_t *buf` +/// - `wasi_snapshot0::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>, + buf_ptr: WasmPtr, ) -> wasi_snapshot0::Errno { debug!( "wasi::fd_fdstat_get: fd={}, buf_ptr={}", diff --git a/lib/wasi/src/syscalls/wasi.rs b/lib/wasi/src/syscalls/wasi.rs index d49b6a29731..40905b3ffdd 100644 --- a/lib/wasi/src/syscalls/wasi.rs +++ b/lib/wasi/src/syscalls/wasi.rs @@ -85,7 +85,7 @@ pub(crate) fn fd_datasync(ctx: FunctionEnvMut, fd: __wasi_fd_t) -> wasi pub(crate) fn fd_fdstat_get( ctx: FunctionEnvMut, fd: __wasi_fd_t, - buf_ptr: WasmPtr<__wasi_fdstat_t, MemoryType>, + buf_ptr: WasmPtr, ) -> wasi_snapshot0::Errno { super::fd_fdstat_get::(ctx, fd, buf_ptr) } diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index cf0903c6217..956a17275e8 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -86,7 +86,7 @@ pub(crate) fn fd_datasync(ctx: FunctionEnvMut, fd: __wasi_fd_t) -> wasi pub(crate) fn fd_fdstat_get( ctx: FunctionEnvMut, fd: __wasi_fd_t, - buf_ptr: WasmPtr<__wasi_fdstat_t, MemoryType>, + buf_ptr: WasmPtr, ) -> wasi_snapshot0::Errno { super::fd_fdstat_get::(ctx, fd, buf_ptr) } diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index a12a0e02950..81fd53575b5 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -86,7 +86,7 @@ pub(crate) fn fd_datasync(ctx: FunctionEnvMut, fd: __wasi_fd_t) -> wasi pub(crate) fn fd_fdstat_get( ctx: FunctionEnvMut, fd: __wasi_fd_t, - buf_ptr: WasmPtr<__wasi_fdstat_t, MemoryType>, + buf_ptr: WasmPtr, ) -> wasi_snapshot0::Errno { super::fd_fdstat_get::(ctx, fd, buf_ptr) } From 188d069fd1167cc8645640d363522a1943bd22af Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Thu, 18 Aug 2022 12:29:53 +0200 Subject: [PATCH 18/84] WIP: Fd --- lib/wasi-types-generated/src/bindings.rs | 10 + .../wit/wasi-snapshot0.wit | 8 +- lib/wasi-types/src/bus.rs | 3 +- lib/wasi-types/src/file.rs | 7 +- lib/wasi-types/src/io.rs | 7 +- lib/wasi-types/src/net.rs | 7 +- lib/wasi-types/src/subscription.rs | 2 +- lib/wasi/src/state/guard.rs | 2 +- lib/wasi/src/state/mod.rs | 63 ++--- lib/wasi/src/syscalls/legacy/snapshot0.rs | 6 +- lib/wasi/src/syscalls/mod.rs | 221 +++++++++--------- lib/wasi/src/syscalls/wasi.rs | 85 ++++--- lib/wasi/src/syscalls/wasix32.rs | 145 ++++++------ lib/wasi/src/syscalls/wasix64.rs | 145 ++++++------ 14 files changed, 380 insertions(+), 331 deletions(-) diff --git a/lib/wasi-types-generated/src/bindings.rs b/lib/wasi-types-generated/src/bindings.rs index 0cad9ddb4db..871c610e807 100644 --- a/lib/wasi-types-generated/src/bindings.rs +++ b/lib/wasi-types-generated/src/bindings.rs @@ -486,6 +486,8 @@ pub mod wasi_snapshot0 { Ok(())} } + /// 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. @@ -741,6 +743,7 @@ pub mod wasi_snapshot0 { #[allow(dead_code)] env: wasmer::FunctionEnv, func_dirent_dummy_func: wasmer::TypedFunction<(i64,i64,i32,i32,), ()>, + func_fd_dummy_func: wasmer::TypedFunction, func_fdstat_dummy_func: wasmer::TypedFunction<(i32,i32,i32,i32,i32,i32,), ()>, } impl WasiSnapshot0 { @@ -794,13 +797,20 @@ pub mod wasi_snapshot0 { env: wasmer::FunctionEnv, ) -> Result { let func_dirent_dummy_func= _instance.exports.get_typed_function(&store, "dirent-dummy-func")?; + let func_fd_dummy_func= _instance.exports.get_typed_function(&store, "fd-dummy-func")?; let func_fdstat_dummy_func= _instance.exports.get_typed_function(&store, "fdstat-dummy-func")?; Ok(WasiSnapshot0{ func_dirent_dummy_func, + func_fd_dummy_func, func_fdstat_dummy_func, env, }) } + /// Dummy function to expose fd into generated code + pub fn fd_dummy_func(&self, store: &mut wasmer::Store,d: Fd,)-> Result<(), wasmer::RuntimeError> { + self.func_fd_dummy_func.call(store, wit_bindgen_wasmer::rt::as_i32(d), )?; + Ok(()) + } /// Dummy function to expose dirent into generated code pub fn dirent_dummy_func(&self, store: &mut wasmer::Store,d: Dirent,)-> Result<(), wasmer::RuntimeError> { let Dirent{ d_next:d_next0, d_ino:d_ino0, d_namlen:d_namlen0, d_type:d_type0, } = d; diff --git a/lib/wasi-types-generated/wit/wasi-snapshot0.wit b/lib/wasi-types-generated/wit/wasi-snapshot0.wit index 99b62b9cb90..606b3294d4b 100644 --- a/lib/wasi-types-generated/wit/wasi-snapshot0.wit +++ b/lib/wasi-types-generated/wit/wasi-snapshot0.wit @@ -295,9 +295,11 @@ flags rights { sock-send-to, } -// ;;; A file descriptor handle. -// (typename $fd (handle)) -// +/// A file descriptor handle. +type fd = u32 +/// Dummy function to expose fd into generated code +fd-dummy-func: func(d: fd) + // ;;; A region of memory for scatter/gather reads. // (typename $iovec // (record diff --git a/lib/wasi-types/src/bus.rs b/lib/wasi-types/src/bus.rs index ff8bea2ecb3..07f587240b8 100644 --- a/lib/wasi-types/src/bus.rs +++ b/lib/wasi-types/src/bus.rs @@ -1,6 +1,7 @@ use super::*; use wasmer_derive::ValueType; use wasmer_types::MemorySize; +use wasmer_wasi_types_generated::wasi_snapshot0; pub type __wasi_busdataformat_t = u8; pub const __WASI_BUS_DATA_FORMAT_RAW: __wasi_busdataformat_t = 0; @@ -34,7 +35,7 @@ pub type __wasi_cid_t = u8; #[repr(C)] pub struct __wasi_option_fd_t { pub tag: __wasi_option_t, - pub fd: __wasi_fd_t, + pub fd: wasi_snapshot0::Fd, } #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] diff --git a/lib/wasi-types/src/file.rs b/lib/wasi-types/src/file.rs index 485eef5e4bf..89962d40aa8 100644 --- a/lib/wasi-types/src/file.rs +++ b/lib/wasi-types/src/file.rs @@ -9,10 +9,9 @@ use wasmer_wasi_types_generated::wasi_snapshot0; 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 const __WASI_STDIN_FILENO: wasi_snapshot0::Fd = 0; +pub const __WASI_STDOUT_FILENO: wasi_snapshot0::Fd = 1; +pub const __WASI_STDERR_FILENO: wasi_snapshot0::Fd = 2; pub type __wasi_pid_t = u32; pub type __wasi_tid_t = u32; diff --git a/lib/wasi-types/src/io.rs b/lib/wasi-types/src/io.rs index f80ffcfb3eb..40a72c29207 100644 --- a/lib/wasi-types/src/io.rs +++ b/lib/wasi-types/src/io.rs @@ -1,7 +1,6 @@ use wasmer_derive::ValueType; use wasmer_types::MemorySize; - -use crate::__wasi_fd_t; +use wasmer_wasi_types_generated::wasi_snapshot0; pub type __wasi_count_t = u32; @@ -44,8 +43,8 @@ pub struct __wasi_tty_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 pipe: wasi_snapshot0::Fd, + pub other: wasi_snapshot0::Fd, } pub type __wasi_stdiomode_t = u8; diff --git a/lib/wasi-types/src/net.rs b/lib/wasi-types/src/net.rs index 7f0cbd79f64..7af15b8da08 100644 --- a/lib/wasi-types/src/net.rs +++ b/lib/wasi-types/src/net.rs @@ -1,5 +1,6 @@ use super::*; use wasmer_derive::ValueType; +use wasmer_wasi_types_generated::wasi_snapshot0; use crate::__wasi_option_timestamp_t; @@ -459,9 +460,9 @@ pub struct __wasi_route_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, + pub req: wasi_snapshot0::Fd, + pub res: wasi_snapshot0::Fd, + pub hdr: wasi_snapshot0::Fd, } #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] diff --git a/lib/wasi-types/src/subscription.rs b/lib/wasi-types/src/subscription.rs index 2a281699f24..79612089eba 100644 --- a/lib/wasi-types/src/subscription.rs +++ b/lib/wasi-types/src/subscription.rs @@ -18,7 +18,7 @@ pub struct __wasi_subscription_clock_t { #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] #[repr(C)] pub struct __wasi_subscription_fs_readwrite_t { - pub fd: __wasi_fd_t, + pub fd: wasi_snapshot0::Fd, } #[derive(Copy, Clone)] diff --git a/lib/wasi/src/state/guard.rs b/lib/wasi/src/state/guard.rs index e37c9c97845..7b815354006 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_snapshot0::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 9a7de8d3d5b..6b3bda93f75 100644 --- a/lib/wasi/src/state/mod.rs +++ b/lib/wasi/src/state/mod.rs @@ -57,7 +57,7 @@ use wasmer_wasi_types_generated::wasi_snapshot0; 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: wasi_snapshot0::Fd = 3; /// all the rights enabled pub const ALL_RIGHTS: wasi_snapshot0::Rights = wasi_snapshot0::Rights::all(); const STDIN_DEFAULT_RIGHTS: wasi_snapshot0::Rights = { @@ -162,7 +162,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: wasi_snapshot0::Fd, /// The path to the symlink from the `base_po_dir` path_to_symlink: PathBuf, /// the value of the symlink as a relative path @@ -302,7 +302,7 @@ impl WasiInodes { fn std_dev_get<'a>( &'a self, fd_map: &RwLock>, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, ) -> Result, FsError> { if let Some(fd) = fd_map.read().unwrap().get(&fd) { let guard = self.arena[fd.inode].read(); @@ -322,7 +322,7 @@ impl WasiInodes { fn std_dev_get_mut<'a>( &'a self, fd_map: &RwLock>, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, ) -> Result, FsError> { if let Some(fd) = fd_map.read().unwrap().get(&fd) { let guard = self.arena[fd.inode].write(); @@ -677,12 +677,12 @@ impl WasiFs { pub unsafe fn open_dir_all( &mut self, inodes: &mut WasiInodes, - base: __wasi_fd_t, + base: wasi_snapshot0::Fd, name: String, rights: wasi_snapshot0::Rights, rights_inheriting: wasi_snapshot0::Rights, flags: wasi_snapshot0::Fdflags, - ) -> Result<__wasi_fd_t, FsError> { + ) -> 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)?; @@ -752,14 +752,14 @@ impl WasiFs { pub fn open_file_at( &mut self, inodes: &mut WasiInodes, - base: __wasi_fd_t, + base: wasi_snapshot0::Fd, file: Box, open_flags: u16, name: String, rights: wasi_snapshot0::Rights, rights_inheriting: wasi_snapshot0::Rights, flags: wasi_snapshot0::Fdflags, - ) -> Result<__wasi_fd_t, FsError> { + ) -> 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)?; @@ -812,7 +812,7 @@ impl WasiFs { pub fn swap_file( &self, inodes: &WasiInodes, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, file: Box, ) -> Result>, FsError> { let mut ret = Some(file); @@ -849,7 +849,7 @@ impl WasiFs { pub(crate) fn filestat_resync_size( &self, inodes: &WasiInodes, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, ) -> Result<__wasi_filesize_t, wasi_snapshot0::Errno> { let inode = self.get_fd_inode(fd)?; let mut guard = inodes.arena[inode].write(); @@ -881,7 +881,7 @@ impl WasiFs { pub fn get_current_dir( &self, inodes: &mut WasiInodes, - base: __wasi_fd_t, + base: wasi_snapshot0::Fd, ) -> Result<(Inode, String), wasi_snapshot0::Errno> { self.get_current_dir_inner(inodes, base, 0) } @@ -889,7 +889,7 @@ impl WasiFs { pub(crate) fn get_current_dir_inner( &self, inodes: &mut WasiInodes, - base: __wasi_fd_t, + base: wasi_snapshot0::Fd, symlink_count: u32, ) -> Result<(Inode, String), wasi_snapshot0::Errno> { let current_dir = { @@ -1190,11 +1190,11 @@ impl WasiFs { &self, inodes: &WasiInodes, path: &'path Path, - ) -> Result<(__wasi_fd_t, &'path Path), wasi_snapshot0::Errno> { + ) -> Result<(wasi_snapshot0::Fd, &'path Path), wasi_snapshot0::Errno> { enum BaseFdAndRelPath<'a> { None, BestMatch { - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, rel_path: &'a Path, max_seen: usize, }, @@ -1248,7 +1248,7 @@ impl WasiFs { pub(crate) fn path_depth_from_fd( &self, inodes: &WasiInodes, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, inode: Inode, ) -> Result { let mut counter = 0; @@ -1281,7 +1281,7 @@ impl WasiFs { pub(crate) fn get_inode_at_path( &self, inodes: &mut WasiInodes, - base: __wasi_fd_t, + base: wasi_snapshot0::Fd, path: &str, follow_symlinks: bool, ) -> Result { @@ -1300,7 +1300,7 @@ impl WasiFs { pub(crate) fn get_parent_inode_at_path( &self, inodes: &mut WasiInodes, - base: __wasi_fd_t, + base: wasi_snapshot0::Fd, path: &Path, follow_symlinks: bool, ) -> Result<(Inode, String), wasi_snapshot0::Errno> { @@ -1319,7 +1319,7 @@ impl WasiFs { .map(|v| (v, new_entity_name)) } - pub fn get_fd(&self, fd: __wasi_fd_t) -> Result { + pub fn get_fd(&self, fd: wasi_snapshot0::Fd) -> Result { self.fd_map .read() .unwrap() @@ -1330,7 +1330,7 @@ impl WasiFs { pub fn get_fd_inode( &self, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, ) -> Result { self.fd_map .read() @@ -1343,7 +1343,7 @@ impl WasiFs { pub fn filestat_fd( &self, inodes: &WasiInodes, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, ) -> Result<__wasi_filestat_t, wasi_snapshot0::Errno> { let inode = self.get_fd_inode(fd)?; Ok(*inodes.arena[inode].stat.read().unwrap().deref()) @@ -1352,7 +1352,7 @@ impl WasiFs { pub fn fdstat( &self, inodes: &WasiInodes, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, ) -> Result { match fd { __WASI_STDIN_FILENO => { @@ -1411,7 +1411,7 @@ impl WasiFs { pub fn prestat_fd( &self, inodes: &WasiInodes, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, ) -> Result<__wasi_prestat_t, wasi_snapshot0::Errno> { let inode = self.get_fd_inode(fd)?; trace!("in prestat_fd {:?}", self.get_fd(fd)?); @@ -1436,7 +1436,11 @@ impl WasiFs { } } - pub fn flush(&self, inodes: &WasiInodes, fd: __wasi_fd_t) -> Result<(), wasi_snapshot0::Errno> { + pub fn flush( + &self, + inodes: &WasiInodes, + fd: wasi_snapshot0::Fd, + ) -> Result<(), wasi_snapshot0::Errno> { match fd { __WASI_STDIN_FILENO => (), __WASI_STDOUT_FILENO => inodes @@ -1524,7 +1528,7 @@ impl WasiFs { flags: wasi_snapshot0::Fdflags, open_flags: u16, inode: Inode, - ) -> Result<__wasi_fd_t, wasi_snapshot0::Errno> { + ) -> Result { let idx = self.next_fd.fetch_add(1, Ordering::AcqRel); self.fd_map.write().unwrap().insert( idx, @@ -1540,7 +1544,10 @@ impl WasiFs { Ok(idx) } - pub fn clone_fd(&self, fd: __wasi_fd_t) -> Result<__wasi_fd_t, wasi_snapshot0::Errno> { + pub fn clone_fd( + &self, + fd: wasi_snapshot0::Fd, + ) -> Result { let fd = self.get_fd(fd)?; let idx = self.next_fd.fetch_add(1, Ordering::AcqRel); self.fd_map.write().unwrap().insert( @@ -1623,7 +1630,7 @@ impl WasiFs { inodes: &mut WasiInodes, handle: Box, name: &'static str, - raw_fd: __wasi_fd_t, + raw_fd: wasi_snapshot0::Fd, rights: wasi_snapshot0::Rights, fd_flags: wasi_snapshot0::Fdflags, ) { @@ -1730,7 +1737,7 @@ impl WasiFs { pub(crate) fn close_fd( &self, inodes: &WasiInodes, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, ) -> Result<(), wasi_snapshot0::Errno> { let inode = self.get_fd_inode(fd)?; let inodeval = inodes.get_inodeval(inode)?; @@ -1986,7 +1993,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: wasi_snapshot0::Fd, ) -> Result>, FsError> { let ret = WasiStateFileGuard::new(self, fd)?.map(|a| { let ret = Box::new(a); diff --git a/lib/wasi/src/syscalls/legacy/snapshot0.rs b/lib/wasi/src/syscalls/legacy/snapshot0.rs index 8d570c00327..45f858781a6 100644 --- a/lib/wasi/src/syscalls/legacy/snapshot0.rs +++ b/lib/wasi/src/syscalls/legacy/snapshot0.rs @@ -11,7 +11,7 @@ use wasmer::{AsStoreMut, FunctionEnvMut, WasmPtr}; /// that syscall, then it may break. pub fn fd_filestat_get( mut ctx: FunctionEnvMut, - fd: types::__wasi_fd_t, + fd: wasi_snapshot0::Fd, buf: WasmPtr, ) -> wasi_snapshot0::Errno { let env = ctx.data(); @@ -62,7 +62,7 @@ pub fn fd_filestat_get( /// difference of `wasi_filestat_t` pub fn path_filestat_get( mut ctx: FunctionEnvMut, - fd: types::__wasi_fd_t, + fd: wasi_snapshot0::Fd, flags: types::__wasi_lookupflags_t, path: WasmPtr, path_len: u32, @@ -103,7 +103,7 @@ pub fn path_filestat_get( /// of `__wasi_whence_t` pub fn fd_seek( ctx: FunctionEnvMut, - fd: types::__wasi_fd_t, + fd: wasi_snapshot0::Fd, offset: types::__wasi_filedelta_t, whence: snapshot0::__wasi_whence_t, newoffset: WasmPtr, diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 573390ff13a..5b186a3a180 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -145,7 +145,7 @@ pub(crate) fn read_bytes( fn __sock_actor( ctx: &FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, rights: wasi_snapshot0::Rights, actor: F, ) -> Result @@ -179,7 +179,7 @@ where fn __sock_actor_mut( ctx: &FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, rights: wasi_snapshot0::Rights, actor: F, ) -> Result @@ -213,7 +213,7 @@ where fn __sock_upgrade( ctx: &FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, rights: wasi_snapshot0::Rights, actor: F, ) -> Result<(), wasi_snapshot0::Errno> @@ -485,7 +485,7 @@ pub fn environ_sizes_get( /// ### `fd_advise()` /// Advise the system about how a file will be used /// Inputs: -/// - `__wasi_fd_t fd` +/// - `wasi_snapshot0::Fd fd` /// The file descriptor the advice applies to /// - `__wasi_filesize_t offset` /// The offset from which the advice applies @@ -495,7 +495,7 @@ pub fn environ_sizes_get( /// The advice to give pub fn fd_advise( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, offset: __wasi_filesize_t, len: __wasi_filesize_t, advice: wasi_snapshot0::Advice, @@ -510,7 +510,7 @@ pub fn fd_advise( /// ### `fd_allocate` /// Allocate extra space for a file descriptor /// Inputs: -/// - `__wasi_fd_t fd` +/// - `wasi_snapshot0::Fd fd` /// The file descriptor to allocate for /// - `__wasi_filesize_t offset` /// The offset from the start marking the beginning of the allocation @@ -518,7 +518,7 @@ pub fn fd_advise( /// The length from the offset marking the end of the allocation pub fn fd_allocate( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, offset: __wasi_filesize_t, len: __wasi_filesize_t, ) -> wasi_snapshot0::Errno { @@ -565,14 +565,14 @@ pub fn fd_allocate( /// ### `fd_close()` /// Close an open file descriptor /// Inputs: -/// - `__wasi_fd_t fd` +/// - `wasi_snapshot0::Fd fd` /// A file descriptor mapping to an open file to close /// Errors: /// - `wasi_snapshot0::Errno::Isdir` /// If `fd` is a directory /// - `wasi_snapshot0::Errno::Badf` /// If `fd` is invalid or not open -pub fn fd_close(ctx: FunctionEnvMut<'_, WasiEnv>, fd: __wasi_fd_t) -> wasi_snapshot0::Errno { +pub fn fd_close(ctx: FunctionEnvMut<'_, WasiEnv>, fd: wasi_snapshot0::Fd) -> wasi_snapshot0::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); @@ -587,9 +587,12 @@ pub fn fd_close(ctx: FunctionEnvMut<'_, WasiEnv>, fd: __wasi_fd_t) -> wasi_snaps /// ### `fd_datasync()` /// Synchronize the file data to disk /// Inputs: -/// - `__wasi_fd_t fd` +/// - `wasi_snapshot0::Fd fd` /// The file descriptor to sync -pub fn fd_datasync(ctx: FunctionEnvMut<'_, WasiEnv>, fd: __wasi_fd_t) -> wasi_snapshot0::Errno { +pub fn fd_datasync( + ctx: FunctionEnvMut<'_, WasiEnv>, + fd: wasi_snapshot0::Fd, +) -> wasi_snapshot0::Errno { debug!("wasi::fd_datasync"); let env = ctx.data(); let (_, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0); @@ -611,14 +614,14 @@ pub fn fd_datasync(ctx: FunctionEnvMut<'_, WasiEnv>, fd: __wasi_fd_t) -> wasi_sn /// ### `fd_fdstat_get()` /// Get metadata of a file descriptor /// Input: -/// - `__wasi_fd_t fd` +/// - `wasi_snapshot0::Fd fd` /// The file descriptor whose metadata will be accessed /// Output: /// - `wasi_snapshot0::Fdstat *buf` /// The location where the metadata will be written pub fn fd_fdstat_get( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, buf_ptr: WasmPtr, ) -> wasi_snapshot0::Errno { debug!( @@ -640,13 +643,13 @@ pub fn fd_fdstat_get( /// ### `fd_fdstat_set_flags()` /// Set file descriptor flags for a file descriptor /// Inputs: -/// - `__wasi_fd_t fd` +/// - `wasi_snapshot0::Fd fd` /// The file descriptor to apply the new flags to /// - `wasi_snapshot0::Fdflags flags` /// The flags to apply to `fd` pub fn fd_fdstat_set_flags( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, flags: wasi_snapshot0::Fdflags, ) -> wasi_snapshot0::Errno { debug!("wasi::fd_fdstat_set_flags"); @@ -669,7 +672,7 @@ pub fn fd_fdstat_set_flags( /// ### `fd_fdstat_set_rights()` /// Set the rights of a file descriptor. This can only be used to remove rights /// Inputs: -/// - `__wasi_fd_t fd` +/// - `wasi_snapshot0::Fd fd` /// The file descriptor to apply the new rights to /// - `wasi_snapshot0::Rights fs_rights_base` /// The rights to apply to `fd` @@ -677,7 +680,7 @@ pub fn fd_fdstat_set_flags( /// The inheriting rights to apply to `fd` pub fn fd_fdstat_set_rights( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, fs_rights_base: wasi_snapshot0::Rights, fs_rights_inheriting: wasi_snapshot0::Rights, ) -> wasi_snapshot0::Errno { @@ -703,14 +706,14 @@ pub fn fd_fdstat_set_rights( /// ### `fd_filestat_get()` /// Get the metadata of an open file /// Input: -/// - `__wasi_fd_t fd` +/// - `wasi_snapshot0::Fd fd` /// The open file descriptor whose metadata will be read /// Output: /// - `__wasi_filestat_t *buf` /// Where the metadata from `fd` will be written pub fn fd_filestat_get( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, buf: WasmPtr<__wasi_filestat_t, M>, ) -> wasi_snapshot0::Errno { debug!("wasi::fd_filestat_get"); @@ -735,13 +738,13 @@ pub fn fd_filestat_get( /// ### `fd_filestat_set_size()` /// Change the size of an open file, zeroing out any new bytes /// Inputs: -/// - `__wasi_fd_t fd` +/// - `wasi_snapshot0::Fd fd` /// File descriptor to adjust /// - `__wasi_filesize_t st_size` /// New size that `fd` will be set to pub fn fd_filestat_set_size( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, st_size: __wasi_filesize_t, ) -> wasi_snapshot0::Errno { debug!("wasi::fd_filestat_set_size"); @@ -794,7 +797,7 @@ pub fn fd_filestat_set_size( /// Bit-vector for controlling which times get set pub fn fd_filestat_set_times( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, st_atim: __wasi_timestamp_t, st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, @@ -846,7 +849,7 @@ pub fn fd_filestat_set_times( /// 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` +/// - `wasi_snapshot0::Fd fd` /// The file descriptor to read the data with /// - `const __wasi_iovec_t* iovs' /// Vectors where the data will be stored @@ -859,7 +862,7 @@ pub fn fd_filestat_set_times( /// The number of bytes read pub fn fd_pread( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, iovs: WasmPtr<__wasi_iovec_t, M>, iovs_len: M::Offset, offset: __wasi_filesize_t, @@ -944,14 +947,14 @@ pub fn fd_pread( /// ### `fd_prestat_get()` /// Get metadata about a preopened file descriptor /// Input: -/// - `__wasi_fd_t fd` +/// - `wasi_snapshot0::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, + fd: wasi_snapshot0::Fd, buf: WasmPtr<__wasi_prestat_t, M>, ) -> wasi_snapshot0::Errno { trace!("wasi::fd_prestat_get: fd={}", fd); @@ -973,7 +976,7 @@ pub fn fd_prestat_get( pub fn fd_prestat_dir_name( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, path: WasmPtr, path_len: M::Offset, ) -> wasi_snapshot0::Errno { @@ -1023,7 +1026,7 @@ pub fn fd_prestat_dir_name( /// ### `fd_pwrite()` /// Write to a file without adjusting its offset /// Inputs: -/// - `__wasi_fd_t` +/// - `wasi_snapshot0::Fd` /// File descriptor (opened with writing) to write to /// - `const __wasi_ciovec_t *iovs` /// List of vectors to read data from @@ -1036,7 +1039,7 @@ pub fn fd_prestat_dir_name( /// Number of bytes written pub fn fd_pwrite( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, iovs: WasmPtr<__wasi_ciovec_t, M>, iovs_len: M::Offset, offset: __wasi_filesize_t, @@ -1138,7 +1141,7 @@ pub fn fd_pwrite( /// ### `fd_read()` /// Read data from file descriptor /// Inputs: -/// - `__wasi_fd_t fd` +/// - `wasi_snapshot0::Fd fd` /// File descriptor from which data will be read /// - `const __wasi_iovec_t *iovs` /// Vectors where data will be stored @@ -1150,7 +1153,7 @@ pub fn fd_pwrite( /// pub fn fd_read( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, iovs: WasmPtr<__wasi_iovec_t, M>, iovs_len: M::Offset, nread: WasmPtr, @@ -1297,7 +1300,7 @@ pub fn fd_read( /// ### `fd_readdir()` /// Read data from directory specified by file descriptor /// Inputs: -/// - `__wasi_fd_t fd` +/// - `wasi_snapshot0::Fd fd` /// File descriptor from which directory data will be read /// - `void *buf` /// Buffer where directory entries are stored @@ -1311,7 +1314,7 @@ pub fn fd_read( /// directory has been read pub fn fd_readdir( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, buf: WasmPtr, buf_len: M::Offset, cookie: wasi_snapshot0::Dircookie, @@ -1441,14 +1444,14 @@ pub fn fd_readdir( /// ### `fd_renumber()` /// Atomically copy file descriptor /// Inputs: -/// - `__wasi_fd_t from` +/// - `wasi_snapshot0::Fd from` /// File descriptor to copy -/// - `__wasi_fd_t to` +/// - `wasi_snapshot0::Fd to` /// Location to copy file descriptor to pub fn fd_renumber( ctx: FunctionEnvMut<'_, WasiEnv>, - from: __wasi_fd_t, - to: __wasi_fd_t, + from: wasi_snapshot0::Fd, + to: wasi_snapshot0::Fd, ) -> wasi_snapshot0::Errno { debug!("wasi::fd_renumber: from={}, to={}", from, to); let env = ctx.data(); @@ -1471,15 +1474,15 @@ pub fn fd_renumber( /// ### `fd_dup()` /// Duplicates the file handle /// Inputs: -/// - `__wasi_fd_t fd` +/// - `wasi_snapshot0::Fd fd` /// File handle to be cloned /// Outputs: -/// - `__wasi_fd_t fd` +/// - `wasi_snapshot0::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>, + fd: wasi_snapshot0::Fd, + ret_fd: WasmPtr, ) -> wasi_snapshot0::Errno { debug!("wasi::fd_dup"); @@ -1498,7 +1501,7 @@ pub fn fd_event( ctx: FunctionEnvMut<'_, WasiEnv>, initial_val: u64, flags: __wasi_eventfdflags, - ret_fd: WasmPtr<__wasi_fd_t, M>, + ret_fd: WasmPtr, ) -> wasi_snapshot0::Errno { debug!("wasi::fd_event"); @@ -1533,7 +1536,7 @@ pub fn fd_event( /// ### `fd_seek()` /// Update file descriptor offset /// Inputs: -/// - `__wasi_fd_t fd` +/// - `wasi_snapshot0::Fd fd` /// File descriptor to mutate /// - `__wasi_filedelta_t offset` /// Number of bytes to adjust offset by @@ -1544,7 +1547,7 @@ pub fn fd_event( /// The new offset relative to the start of the file pub fn fd_seek( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, offset: __wasi_filedelta_t, whence: __wasi_whence_t, newoffset: WasmPtr<__wasi_filesize_t, M>, @@ -1622,13 +1625,13 @@ pub fn fd_seek( /// ### `fd_sync()` /// Synchronize file and metadata to disk (TODO: expand upon what this means in our system) /// Inputs: -/// - `__wasi_fd_t fd` +/// - `wasi_snapshot0::Fd fd` /// The file descriptor to sync /// Errors: /// TODO: figure out which errors this should return /// - `wasi_snapshot0::Errno::Perm` /// - `wasi_snapshot0::Errno::Notcapable` -pub fn fd_sync(ctx: FunctionEnvMut<'_, WasiEnv>, fd: __wasi_fd_t) -> wasi_snapshot0::Errno { +pub fn fd_sync(ctx: FunctionEnvMut<'_, WasiEnv>, fd: wasi_snapshot0::Fd) -> wasi_snapshot0::Errno { debug!("wasi::fd_sync"); debug!("=> fd={}", fd); let env = ctx.data(); @@ -1666,14 +1669,14 @@ pub fn fd_sync(ctx: FunctionEnvMut<'_, WasiEnv>, fd: __wasi_fd_t) -> wasi_snapsh /// ### `fd_tell()` /// Get the offset of the file descriptor /// Inputs: -/// - `__wasi_fd_t fd` +/// - `wasi_snapshot0::Fd fd` /// The file descriptor to access /// Output: /// - `__wasi_filesize_t *offset` /// The offset of `fd` relative to the start of the file pub fn fd_tell( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, offset: WasmPtr<__wasi_filesize_t, M>, ) -> wasi_snapshot0::Errno { debug!("wasi::fd_tell"); @@ -1695,7 +1698,7 @@ pub fn fd_tell( /// ### `fd_write()` /// Write data to the file descriptor /// Inputs: -/// - `__wasi_fd_t` +/// - `wasi_snapshot0::Fd` /// File descriptor (opened with writing) to write to /// - `const __wasi_ciovec_t *iovs` /// List of vectors to read data from @@ -1708,7 +1711,7 @@ pub fn fd_tell( /// pub fn fd_write( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, iovs: WasmPtr<__wasi_ciovec_t, M>, iovs_len: M::Offset, nwritten: WasmPtr, @@ -1836,14 +1839,14 @@ pub fn fd_write( /// ### `fd_pipe()` /// Creates ta pipe that feeds data between two file handles /// Output: -/// - `__wasi_fd_t` +/// - `wasi_snapshot0::Fd` /// First file handle that represents one end of the pipe -/// - `__wasi_fd_t` +/// - `wasi_snapshot0::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>, + ro_fd1: WasmPtr, + ro_fd2: WasmPtr, ) -> wasi_snapshot0::Errno { trace!("wasi::fd_pipe"); @@ -1884,7 +1887,7 @@ pub fn fd_pipe( /// ### `path_create_directory()` /// Create directory at a path /// Inputs: -/// - `__wasi_fd_t fd` +/// - `wasi_snapshot0::Fd fd` /// The directory that the path is relative to /// - `const char *path` /// String containing path data @@ -1896,7 +1899,7 @@ pub fn fd_pipe( /// 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: wasi_snapshot0::Fd, path: WasmPtr, path_len: M::Offset, ) -> wasi_snapshot0::Errno { @@ -2015,7 +2018,7 @@ pub fn path_create_directory( /// ### `path_filestat_get()` /// Access metadata about a file or directory /// Inputs: -/// - `__wasi_fd_t fd` +/// - `wasi_snapshot0::Fd fd` /// The directory that `path` is relative to /// - `__wasi_lookupflags_t flags` /// Flags to control how `path` is understood @@ -2028,7 +2031,7 @@ 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, + fd: wasi_snapshot0::Fd, flags: __wasi_lookupflags_t, path: WasmPtr, path_len: M::Offset, @@ -2057,7 +2060,7 @@ pub fn path_filestat_get( /// ### `path_filestat_get()` /// Access metadata about a file or directory /// Inputs: -/// - `__wasi_fd_t fd` +/// - `wasi_snapshot0::Fd fd` /// The directory that `path` is relative to /// - `__wasi_lookupflags_t flags` /// Flags to control how `path` is understood @@ -2072,7 +2075,7 @@ pub fn path_filestat_get_internal( memory: &MemoryView, state: &WasiState, inodes: &mut crate::WasiInodes, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, flags: __wasi_lookupflags_t, path_string: &str, ) -> Result<__wasi_filestat_t, wasi_snapshot0::Errno> { @@ -2103,7 +2106,7 @@ pub fn path_filestat_get_internal( /// ### `path_filestat_set_times()` /// Update time metadata on a file or directory /// Inputs: -/// - `__wasi_fd_t fd` +/// - `wasi_snapshot0::Fd fd` /// The directory relative to which the path is resolved /// - `__wasi_lookupflags_t flags` /// Flags to control how the path is understood @@ -2119,7 +2122,7 @@ pub fn path_filestat_get_internal( /// A bitmask controlling which attributes are set pub fn path_filestat_set_times( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, flags: __wasi_lookupflags_t, path: WasmPtr, path_len: M::Offset, @@ -2184,7 +2187,7 @@ pub fn path_filestat_set_times( /// ### `path_link()` /// Create a hard link /// Inputs: -/// - `__wasi_fd_t old_fd` +/// - `wasi_snapshot0::Fd old_fd` /// The directory relative to which the `old_path` is /// - `__wasi_lookupflags_t old_flags` /// Flags to control how `old_path` is understood @@ -2192,7 +2195,7 @@ pub fn path_filestat_set_times( /// String containing the old file path /// - `u32 old_path_len` /// Length of the `old_path` string -/// - `__wasi_fd_t new_fd` +/// - `wasi_snapshot0::Fd new_fd` /// The directory relative to which the `new_path` is /// - `const char *new_path` /// String containing the new file path @@ -2200,11 +2203,11 @@ 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_fd: wasi_snapshot0::Fd, old_flags: __wasi_lookupflags_t, old_path: WasmPtr, old_path_len: M::Offset, - new_fd: __wasi_fd_t, + new_fd: wasi_snapshot0::Fd, new_path: WasmPtr, new_path_len: M::Offset, ) -> wasi_snapshot0::Errno { @@ -2278,7 +2281,7 @@ pub fn path_link( /// ### `path_open()` /// Open file located at the given path /// Inputs: -/// - `__wasi_fd_t dirfd` +/// - `wasi_snapshot0::Fd dirfd` /// The fd corresponding to the directory that the file is in /// - `__wasi_lookupflags_t dirflags` /// Flags specifying how the path will be resolved @@ -2295,13 +2298,13 @@ pub fn path_link( /// - `wasi_snapshot0::Fdflags fs_flags` /// The flags of the file descriptor /// Output: -/// - `__wasi_fd_t* fd` +/// - `wasi_snapshot0::Fd* fd` /// The new file descriptor /// Possible Errors: /// - `wasi_snapshot0::Errno::Acces`, `wasi_snapshot0::Errno::Badf`, `wasi_snapshot0::Errno::Fault`, `wasi_snapshot0::Errno::Toobig?`, `wasi_snapshot0::Errno::Inval`, `wasi_snapshot0::Errno::Io`, `wasi_snapshot0::Errno::Loop`, `wasi_snapshot0::Errno::Mfile`, `wasi_snapshot0::Errno::Nametoolong?`, `wasi_snapshot0::Errno::Nfile`, `wasi_snapshot0::Errno::Noent`, `wasi_snapshot0::Errno::Notdir`, `wasi_snapshot0::Errno::Rofs`, and `wasi_snapshot0::Errno::Notcapable` pub fn path_open( ctx: FunctionEnvMut<'_, WasiEnv>, - dirfd: __wasi_fd_t, + dirfd: wasi_snapshot0::Fd, dirflags: __wasi_lookupflags_t, path: WasmPtr, path_len: M::Offset, @@ -2309,7 +2312,7 @@ pub fn path_open( fs_rights_base: wasi_snapshot0::Rights, fs_rights_inheriting: wasi_snapshot0::Rights, fs_flags: wasi_snapshot0::Fdflags, - fd: WasmPtr<__wasi_fd_t, M>, + fd: WasmPtr, ) -> wasi_snapshot0::Errno { debug!("wasi::path_open"); if dirflags & __WASI_LOOKUP_SYMLINK_FOLLOW != 0 { @@ -2534,7 +2537,7 @@ pub fn path_open( /// ### `path_readlink()` /// Read the value of a symlink /// Inputs: -/// - `__wasi_fd_t dir_fd` +/// - `wasi_snapshot0::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 @@ -2549,7 +2552,7 @@ 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: wasi_snapshot0::Fd, path: WasmPtr, path_len: M::Offset, buf: WasmPtr, @@ -2604,7 +2607,7 @@ pub fn path_readlink( /// Returns wasi_snapshot0::Errno::Notemtpy if directory is not empty pub fn path_remove_directory( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, path: WasmPtr, path_len: M::Offset, ) -> wasi_snapshot0::Errno { @@ -2679,13 +2682,13 @@ pub fn path_remove_directory( /// ### `path_rename()` /// Rename a file or directory /// Inputs: -/// - `__wasi_fd_t old_fd` +/// - `wasi_snapshot0::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` +/// - `wasi_snapshot0::Fd new_fd` /// The base directory for `new_path` /// - `const char* new_path` /// Pointer to UTF8 bytes, the new file name @@ -2693,10 +2696,10 @@ 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: wasi_snapshot0::Fd, old_path: WasmPtr, old_path_len: M::Offset, - new_fd: __wasi_fd_t, + new_fd: wasi_snapshot0::Fd, new_path: WasmPtr, new_path_len: M::Offset, ) -> wasi_snapshot0::Errno { @@ -2878,7 +2881,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` +/// - `wasi_snapshot0::Fd fd` /// The base directory from which the paths are understood /// - `const char *new_path` /// Array of UTF-8 bytes representing the target path @@ -2888,7 +2891,7 @@ pub fn path_symlink( ctx: FunctionEnvMut<'_, WasiEnv>, old_path: WasmPtr, old_path_len: M::Offset, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, new_path: WasmPtr, new_path_len: M::Offset, ) -> wasi_snapshot0::Errno { @@ -2982,7 +2985,7 @@ pub fn path_symlink( /// ### `path_unlink_file()` /// Unlink a file, deleting if the number of hardlinks is 1 /// Inputs: -/// - `__wasi_fd_t fd` +/// - `wasi_snapshot0::Fd fd` /// The base file descriptor from which the path is understood /// - `const char *path` /// Array of UTF-8 bytes representing the path @@ -2990,7 +2993,7 @@ 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: wasi_snapshot0::Fd, path: WasmPtr, path_len: M::Offset, ) -> wasi_snapshot0::Errno { @@ -4229,7 +4232,7 @@ pub fn ws_connect( ctx: FunctionEnvMut<'_, WasiEnv>, url: WasmPtr, url_len: M::Offset, - ret_sock: WasmPtr<__wasi_fd_t, M>, + ret_sock: WasmPtr, ) -> wasi_snapshot0::Errno { debug!("wasi::ws_connect"); let env = ctx.data(); @@ -4407,7 +4410,7 @@ pub fn http_request( /// status of this HTTP request pub fn http_status( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, status: WasmPtr<__wasi_http_status_t, M>, ) -> wasi_snapshot0::Errno { debug!("wasi::http_status"); @@ -4734,7 +4737,7 @@ pub fn port_route_list( /// * `how` - Which channels on the socket to shut down. pub fn sock_shutdown( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, how: __wasi_sdflags_t, ) -> wasi_snapshot0::Errno { debug!("wasi::sock_shutdown"); @@ -4761,7 +4764,7 @@ pub fn sock_shutdown( /// Returns the current status of a socket pub fn sock_status( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, ret_status: WasmPtr<__wasi_sockstatus_t, M>, ) -> wasi_snapshot0::Errno { debug!("wasi::sock_status"); @@ -4801,7 +4804,7 @@ 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: wasi_snapshot0::Fd, ret_addr: WasmPtr<__wasi_addr_port_t, M>, ) -> wasi_snapshot0::Errno { debug!("wasi::sock_addr_local"); @@ -4835,7 +4838,7 @@ 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: wasi_snapshot0::Fd, ro_addr: WasmPtr<__wasi_addr_port_t, M>, ) -> wasi_snapshot0::Errno { debug!("wasi::sock_addr_peer"); @@ -4881,7 +4884,7 @@ pub fn sock_open( af: __wasi_addressfamily_t, ty: __wasi_socktype_t, pt: __wasi_sockproto_t, - ro_sock: WasmPtr<__wasi_fd_t, M>, + ro_sock: WasmPtr, ) -> wasi_snapshot0::Errno { debug!("wasi::sock_open"); @@ -4937,7 +4940,7 @@ pub fn sock_open( /// * `flag` - Value to set the option to pub fn sock_set_opt_flag( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, opt: __wasi_sockoption_t, flag: __wasi_bool_t, ) -> wasi_snapshot0::Errno { @@ -4969,7 +4972,7 @@ 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, + sock: wasi_snapshot0::Fd, opt: __wasi_sockoption_t, ret_flag: WasmPtr<__wasi_bool_t, M>, ) -> wasi_snapshot0::Errno { @@ -5004,7 +5007,7 @@ 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, + sock: wasi_snapshot0::Fd, opt: __wasi_sockoption_t, time: WasmPtr<__wasi_option_timestamp_t, M>, ) -> wasi_snapshot0::Errno { @@ -5047,7 +5050,7 @@ 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, + sock: wasi_snapshot0::Fd, opt: __wasi_sockoption_t, ret_time: WasmPtr<__wasi_option_timestamp_t, M>, ) -> wasi_snapshot0::Errno { @@ -5097,7 +5100,7 @@ pub fn sock_get_opt_time( /// * `size` - Buffer size pub fn sock_set_opt_size( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, opt: __wasi_sockoption_t, size: __wasi_filesize_t, ) -> wasi_snapshot0::Errno { @@ -5140,7 +5143,7 @@ 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, + sock: wasi_snapshot0::Fd, opt: __wasi_sockoption_t, ret_size: WasmPtr<__wasi_filesize_t, M>, ) -> wasi_snapshot0::Errno { @@ -5183,7 +5186,7 @@ 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: wasi_snapshot0::Fd, multiaddr: WasmPtr<__wasi_addr_ip4_t, M>, iface: WasmPtr<__wasi_addr_ip4_t, M>, ) -> wasi_snapshot0::Errno { @@ -5212,7 +5215,7 @@ 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: wasi_snapshot0::Fd, multiaddr: WasmPtr<__wasi_addr_ip4_t, M>, iface: WasmPtr<__wasi_addr_ip4_t, M>, ) -> wasi_snapshot0::Errno { @@ -5241,7 +5244,7 @@ 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: wasi_snapshot0::Fd, multiaddr: WasmPtr<__wasi_addr_ip6_t, M>, iface: u32, ) -> wasi_snapshot0::Errno { @@ -5269,7 +5272,7 @@ 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: wasi_snapshot0::Fd, multiaddr: WasmPtr<__wasi_addr_ip6_t, M>, iface: u32, ) -> wasi_snapshot0::Errno { @@ -5297,7 +5300,7 @@ 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: wasi_snapshot0::Fd, addr: WasmPtr<__wasi_addr_port_t, M>, ) -> wasi_snapshot0::Errno { debug!("wasi::sock_bind"); @@ -5329,7 +5332,7 @@ 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: wasi_snapshot0::Fd, backlog: M::Offset, ) -> wasi_snapshot0::Errno { debug!("wasi::sock_listen"); @@ -5359,9 +5362,9 @@ pub fn sock_listen( /// New socket connection pub fn sock_accept( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, fd_flags: wasi_snapshot0::Fdflags, - ro_fd: WasmPtr<__wasi_fd_t, M>, + ro_fd: WasmPtr, ro_addr: WasmPtr<__wasi_addr_port_t, M>, ) -> Result { debug!("wasi::sock_accept"); @@ -5441,7 +5444,7 @@ pub fn sock_accept( /// * `addr` - Address of the socket to connect to pub fn sock_connect( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, addr: WasmPtr<__wasi_addr_port_t, M>, ) -> wasi_snapshot0::Errno { debug!("wasi::sock_connect"); @@ -5474,7 +5477,7 @@ 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: wasi_snapshot0::Fd, ri_data: WasmPtr<__wasi_iovec_t, M>, ri_data_len: M::Offset, _ri_flags: __wasi_riflags_t, @@ -5518,7 +5521,7 @@ 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: wasi_snapshot0::Fd, ri_data: WasmPtr<__wasi_iovec_t, M>, ri_data_len: M::Offset, _ri_flags: __wasi_riflags_t, @@ -5563,7 +5566,7 @@ pub fn sock_recv_from( /// Number of bytes transmitted. pub fn sock_send( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, si_data: WasmPtr<__wasi_ciovec_t, M>, si_data_len: M::Offset, _si_flags: __wasi_siflags_t, @@ -5606,7 +5609,7 @@ pub fn sock_send( /// Number of bytes transmitted. pub fn sock_send_to( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, si_data: WasmPtr<__wasi_ciovec_t, M>, si_data_len: M::Offset, _si_flags: __wasi_siflags_t, @@ -5648,8 +5651,8 @@ 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, + sock: wasi_snapshot0::Fd, + in_fd: wasi_snapshot0::Fd, offset: __wasi_filesize_t, mut count: __wasi_filesize_t, ret_sent: WasmPtr<__wasi_filesize_t, M>, diff --git a/lib/wasi/src/syscalls/wasi.rs b/lib/wasi/src/syscalls/wasi.rs index 40905b3ffdd..73627b7f75c 100644 --- a/lib/wasi/src/syscalls/wasi.rs +++ b/lib/wasi/src/syscalls/wasi.rs @@ -57,7 +57,7 @@ pub(crate) fn environ_sizes_get( pub(crate) fn fd_advise( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, offset: __wasi_filesize_t, len: __wasi_filesize_t, advice: __wasi_advice_t, @@ -67,24 +67,30 @@ pub(crate) fn fd_advise( pub(crate) fn fd_allocate( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, offset: __wasi_filesize_t, len: __wasi_filesize_t, ) -> wasi_snapshot0::Errno { super::fd_allocate(ctx, fd, offset, len) } -pub(crate) fn fd_close(ctx: FunctionEnvMut, fd: __wasi_fd_t) -> wasi_snapshot0::Errno { +pub(crate) fn fd_close( + ctx: FunctionEnvMut, + fd: wasi_snapshot0::Fd, +) -> wasi_snapshot0::Errno { super::fd_close(ctx, fd) } -pub(crate) fn fd_datasync(ctx: FunctionEnvMut, fd: __wasi_fd_t) -> wasi_snapshot0::Errno { +pub(crate) fn fd_datasync( + ctx: FunctionEnvMut, + fd: wasi_snapshot0::Fd, +) -> wasi_snapshot0::Errno { super::fd_datasync(ctx, fd) } pub(crate) fn fd_fdstat_get( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, buf_ptr: WasmPtr, ) -> wasi_snapshot0::Errno { super::fd_fdstat_get::(ctx, fd, buf_ptr) @@ -92,7 +98,7 @@ pub(crate) fn fd_fdstat_get( pub(crate) fn fd_fdstat_set_flags( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, flags: wasi_snapshot0::Fdflags, ) -> wasi_snapshot0::Errno { super::fd_fdstat_set_flags(ctx, fd, flags) @@ -100,7 +106,7 @@ pub(crate) fn fd_fdstat_set_flags( pub(crate) fn fd_fdstat_set_rights( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, fs_rights_base: __wasi_rights_t, fs_rights_inheriting: __wasi_rights_t, ) -> wasi_snapshot0::Errno { @@ -109,7 +115,7 @@ pub(crate) fn fd_fdstat_set_rights( pub(crate) fn fd_filestat_get( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, buf: WasmPtr<__wasi_filestat_t, MemoryType>, ) -> wasi_snapshot0::Errno { super::fd_filestat_get::(ctx, fd, buf) @@ -117,7 +123,7 @@ pub(crate) fn fd_filestat_get( pub(crate) fn fd_filestat_set_size( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, st_size: __wasi_filesize_t, ) -> wasi_snapshot0::Errno { super::fd_filestat_set_size(ctx, fd, st_size) @@ -125,7 +131,7 @@ pub(crate) fn fd_filestat_set_size( pub(crate) fn fd_filestat_set_times( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, st_atim: __wasi_timestamp_t, st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, @@ -135,7 +141,7 @@ pub(crate) fn fd_filestat_set_times( pub(crate) fn fd_pread( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, offset: __wasi_filesize_t, @@ -146,7 +152,7 @@ pub(crate) fn fd_pread( pub(crate) fn fd_prestat_get( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, buf: WasmPtr<__wasi_prestat_t, MemoryType>, ) -> wasi_snapshot0::Errno { super::fd_prestat_get::(ctx, fd, buf) @@ -154,7 +160,7 @@ pub(crate) fn fd_prestat_get( pub(crate) fn fd_prestat_dir_name( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, path: WasmPtr, path_len: MemoryOffset, ) -> wasi_snapshot0::Errno { @@ -163,7 +169,7 @@ pub(crate) fn fd_prestat_dir_name( pub(crate) fn fd_pwrite( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, offset: __wasi_filesize_t, @@ -174,7 +180,7 @@ pub(crate) fn fd_pwrite( pub(crate) fn fd_read( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, nread: WasmPtr, @@ -184,7 +190,7 @@ pub(crate) fn fd_read( pub(crate) fn fd_readdir( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, buf: WasmPtr, buf_len: MemoryOffset, cookie: __wasi_dircookie_t, @@ -195,15 +201,15 @@ pub(crate) fn fd_readdir( pub(crate) fn fd_renumber( ctx: FunctionEnvMut, - from: __wasi_fd_t, - to: __wasi_fd_t, + from: wasi_snapshot0::Fd, + to: wasi_snapshot0::Fd, ) -> wasi_snapshot0::Errno { super::fd_renumber(ctx, from, to) } pub(crate) fn fd_seek( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, offset: __wasi_filedelta_t, whence: __wasi_whence_t, newoffset: WasmPtr<__wasi_filesize_t, MemoryType>, @@ -211,13 +217,16 @@ pub(crate) fn fd_seek( super::fd_seek::(ctx, fd, offset, whence, newoffset) } -pub(crate) fn fd_sync(ctx: FunctionEnvMut, fd: __wasi_fd_t) -> wasi_snapshot0::Errno { +pub(crate) fn fd_sync( + ctx: FunctionEnvMut, + fd: wasi_snapshot0::Fd, +) -> wasi_snapshot0::Errno { super::fd_sync(ctx, fd) } pub(crate) fn fd_tell( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, offset: WasmPtr<__wasi_filesize_t, MemoryType>, ) -> wasi_snapshot0::Errno { super::fd_tell::(ctx, fd, offset) @@ -225,7 +234,7 @@ pub(crate) fn fd_tell( pub(crate) fn fd_write( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, nwritten: WasmPtr, @@ -235,7 +244,7 @@ pub(crate) fn fd_write( pub(crate) fn path_create_directory( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, path: WasmPtr, path_len: MemoryOffset, ) -> wasi_snapshot0::Errno { @@ -244,7 +253,7 @@ pub(crate) fn path_create_directory( pub(crate) fn path_filestat_get( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, flags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, @@ -255,7 +264,7 @@ pub(crate) fn path_filestat_get( pub(crate) fn path_filestat_set_times( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, flags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, @@ -270,11 +279,11 @@ pub(crate) fn path_filestat_set_times( pub(crate) fn path_link( ctx: FunctionEnvMut, - old_fd: __wasi_fd_t, + old_fd: wasi_snapshot0::Fd, old_flags: __wasi_lookupflags_t, old_path: WasmPtr, old_path_len: MemoryOffset, - new_fd: __wasi_fd_t, + new_fd: wasi_snapshot0::Fd, new_path: WasmPtr, new_path_len: MemoryOffset, ) -> wasi_snapshot0::Errno { @@ -292,7 +301,7 @@ pub(crate) fn path_link( pub(crate) fn path_open( ctx: FunctionEnvMut, - dirfd: __wasi_fd_t, + dirfd: wasi_snapshot0::Fd, dirflags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, @@ -300,7 +309,7 @@ pub(crate) fn path_open( fs_rights_base: __wasi_rights_t, fs_rights_inheriting: __wasi_rights_t, fs_flags: wasi_snapshot0::Fdflags, - fd: WasmPtr<__wasi_fd_t, MemoryType>, + fd: WasmPtr, ) -> wasi_snapshot0::Errno { super::path_open::( ctx, @@ -318,7 +327,7 @@ pub(crate) fn path_open( pub(crate) fn path_readlink( ctx: FunctionEnvMut, - dir_fd: __wasi_fd_t, + dir_fd: wasi_snapshot0::Fd, path: WasmPtr, path_len: MemoryOffset, buf: WasmPtr, @@ -330,7 +339,7 @@ pub(crate) fn path_readlink( pub(crate) fn path_remove_directory( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, path: WasmPtr, path_len: MemoryOffset, ) -> wasi_snapshot0::Errno { @@ -339,10 +348,10 @@ pub(crate) fn path_remove_directory( pub(crate) fn path_rename( ctx: FunctionEnvMut, - old_fd: __wasi_fd_t, + old_fd: wasi_snapshot0::Fd, old_path: WasmPtr, old_path_len: MemoryOffset, - new_fd: __wasi_fd_t, + new_fd: wasi_snapshot0::Fd, new_path: WasmPtr, new_path_len: MemoryOffset, ) -> wasi_snapshot0::Errno { @@ -361,7 +370,7 @@ pub(crate) fn path_symlink( ctx: FunctionEnvMut, old_path: WasmPtr, old_path_len: MemoryOffset, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, new_path: WasmPtr, new_path_len: MemoryOffset, ) -> wasi_snapshot0::Errno { @@ -370,7 +379,7 @@ pub(crate) fn path_symlink( pub(crate) fn path_unlink_file( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, path: WasmPtr, path_len: MemoryOffset, ) -> wasi_snapshot0::Errno { @@ -417,7 +426,7 @@ pub(crate) fn sched_yield( pub(crate) fn sock_recv( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, ri_data: WasmPtr<__wasi_iovec_t, MemoryType>, ri_data_len: MemoryOffset, ri_flags: __wasi_riflags_t, @@ -437,7 +446,7 @@ pub(crate) fn sock_recv( pub(crate) fn sock_send( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, si_data: WasmPtr<__wasi_ciovec_t, MemoryType>, si_data_len: MemoryOffset, si_flags: __wasi_siflags_t, @@ -448,7 +457,7 @@ pub(crate) fn sock_send( pub(crate) fn sock_shutdown( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, how: __wasi_sdflags_t, ) -> wasi_snapshot0::Errno { super::sock_shutdown(ctx, sock, how) diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index 956a17275e8..3a4b86dba39 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -58,7 +58,7 @@ pub(crate) fn environ_sizes_get( pub(crate) fn fd_advise( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, offset: __wasi_filesize_t, len: __wasi_filesize_t, advice: wasi_snapshot0::Advice, @@ -68,24 +68,30 @@ pub(crate) fn fd_advise( pub(crate) fn fd_allocate( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, offset: __wasi_filesize_t, len: __wasi_filesize_t, ) -> wasi_snapshot0::Errno { super::fd_allocate(ctx, fd, offset, len) } -pub(crate) fn fd_close(ctx: FunctionEnvMut, fd: __wasi_fd_t) -> wasi_snapshot0::Errno { +pub(crate) fn fd_close( + ctx: FunctionEnvMut, + fd: wasi_snapshot0::Fd, +) -> wasi_snapshot0::Errno { super::fd_close(ctx, fd) } -pub(crate) fn fd_datasync(ctx: FunctionEnvMut, fd: __wasi_fd_t) -> wasi_snapshot0::Errno { +pub(crate) fn fd_datasync( + ctx: FunctionEnvMut, + fd: wasi_snapshot0::Fd, +) -> wasi_snapshot0::Errno { super::fd_datasync(ctx, fd) } pub(crate) fn fd_fdstat_get( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, buf_ptr: WasmPtr, ) -> wasi_snapshot0::Errno { super::fd_fdstat_get::(ctx, fd, buf_ptr) @@ -93,7 +99,7 @@ pub(crate) fn fd_fdstat_get( pub(crate) fn fd_fdstat_set_flags( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, flags: wasi_snapshot0::Fdflags, ) -> wasi_snapshot0::Errno { super::fd_fdstat_set_flags(ctx, fd, flags) @@ -101,7 +107,7 @@ pub(crate) fn fd_fdstat_set_flags( pub(crate) fn fd_fdstat_set_rights( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, fs_rights_base: wasi_snapshot0::Rights, fs_rights_inheriting: wasi_snapshot0::Rights, ) -> wasi_snapshot0::Errno { @@ -110,7 +116,7 @@ pub(crate) fn fd_fdstat_set_rights( pub(crate) fn fd_filestat_get( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, buf: WasmPtr<__wasi_filestat_t, MemoryType>, ) -> wasi_snapshot0::Errno { super::fd_filestat_get::(ctx, fd, buf) @@ -118,7 +124,7 @@ pub(crate) fn fd_filestat_get( pub(crate) fn fd_filestat_set_size( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, st_size: __wasi_filesize_t, ) -> wasi_snapshot0::Errno { super::fd_filestat_set_size(ctx, fd, st_size) @@ -126,7 +132,7 @@ pub(crate) fn fd_filestat_set_size( pub(crate) fn fd_filestat_set_times( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, st_atim: __wasi_timestamp_t, st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, @@ -136,7 +142,7 @@ pub(crate) fn fd_filestat_set_times( pub(crate) fn fd_pread( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, offset: __wasi_filesize_t, @@ -147,7 +153,7 @@ pub(crate) fn fd_pread( pub(crate) fn fd_prestat_get( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, buf: WasmPtr<__wasi_prestat_t, MemoryType>, ) -> wasi_snapshot0::Errno { super::fd_prestat_get::(ctx, fd, buf) @@ -155,7 +161,7 @@ pub(crate) fn fd_prestat_get( pub(crate) fn fd_prestat_dir_name( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, path: WasmPtr, path_len: MemoryOffset, ) -> wasi_snapshot0::Errno { @@ -164,7 +170,7 @@ pub(crate) fn fd_prestat_dir_name( pub(crate) fn fd_pwrite( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, offset: __wasi_filesize_t, @@ -175,7 +181,7 @@ pub(crate) fn fd_pwrite( pub(crate) fn fd_read( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, nread: WasmPtr, @@ -185,7 +191,7 @@ pub(crate) fn fd_read( pub(crate) fn fd_readdir( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, buf: WasmPtr, buf_len: MemoryOffset, cookie: wasi_snapshot0::Dircookie, @@ -196,15 +202,15 @@ pub(crate) fn fd_readdir( pub(crate) fn fd_renumber( ctx: FunctionEnvMut, - from: __wasi_fd_t, - to: __wasi_fd_t, + from: wasi_snapshot0::Fd, + to: wasi_snapshot0::Fd, ) -> wasi_snapshot0::Errno { super::fd_renumber(ctx, from, to) } pub(crate) fn fd_seek( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, offset: __wasi_filedelta_t, whence: __wasi_whence_t, newoffset: WasmPtr<__wasi_filesize_t, MemoryType>, @@ -212,13 +218,16 @@ pub(crate) fn fd_seek( super::fd_seek::(ctx, fd, offset, whence, newoffset) } -pub(crate) fn fd_sync(ctx: FunctionEnvMut, fd: __wasi_fd_t) -> wasi_snapshot0::Errno { +pub(crate) fn fd_sync( + ctx: FunctionEnvMut, + fd: wasi_snapshot0::Fd, +) -> wasi_snapshot0::Errno { super::fd_sync(ctx, fd) } pub(crate) fn fd_tell( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, offset: WasmPtr<__wasi_filesize_t, MemoryType>, ) -> wasi_snapshot0::Errno { super::fd_tell::(ctx, fd, offset) @@ -226,7 +235,7 @@ pub(crate) fn fd_tell( pub(crate) fn fd_write( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, nwritten: WasmPtr, @@ -236,7 +245,7 @@ pub(crate) fn fd_write( pub(crate) fn path_create_directory( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, path: WasmPtr, path_len: MemoryOffset, ) -> wasi_snapshot0::Errno { @@ -245,7 +254,7 @@ pub(crate) fn path_create_directory( pub(crate) fn path_filestat_get( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, flags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, @@ -256,7 +265,7 @@ pub(crate) fn path_filestat_get( pub(crate) fn path_filestat_set_times( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, flags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, @@ -271,11 +280,11 @@ pub(crate) fn path_filestat_set_times( pub(crate) fn path_link( ctx: FunctionEnvMut, - old_fd: __wasi_fd_t, + old_fd: wasi_snapshot0::Fd, old_flags: __wasi_lookupflags_t, old_path: WasmPtr, old_path_len: MemoryOffset, - new_fd: __wasi_fd_t, + new_fd: wasi_snapshot0::Fd, new_path: WasmPtr, new_path_len: MemoryOffset, ) -> wasi_snapshot0::Errno { @@ -293,7 +302,7 @@ pub(crate) fn path_link( pub(crate) fn path_open( ctx: FunctionEnvMut, - dirfd: __wasi_fd_t, + dirfd: wasi_snapshot0::Fd, dirflags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, @@ -301,7 +310,7 @@ pub(crate) fn path_open( fs_rights_base: wasi_snapshot0::Rights, fs_rights_inheriting: wasi_snapshot0::Rights, fs_flags: wasi_snapshot0::Fdflags, - fd: WasmPtr<__wasi_fd_t, MemoryType>, + fd: WasmPtr, ) -> wasi_snapshot0::Errno { super::path_open::( ctx, @@ -319,7 +328,7 @@ pub(crate) fn path_open( pub(crate) fn path_readlink( ctx: FunctionEnvMut, - dir_fd: __wasi_fd_t, + dir_fd: wasi_snapshot0::Fd, path: WasmPtr, path_len: MemoryOffset, buf: WasmPtr, @@ -331,7 +340,7 @@ pub(crate) fn path_readlink( pub(crate) fn path_remove_directory( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, path: WasmPtr, path_len: MemoryOffset, ) -> wasi_snapshot0::Errno { @@ -340,10 +349,10 @@ pub(crate) fn path_remove_directory( pub(crate) fn path_rename( ctx: FunctionEnvMut, - old_fd: __wasi_fd_t, + old_fd: wasi_snapshot0::Fd, old_path: WasmPtr, old_path_len: MemoryOffset, - new_fd: __wasi_fd_t, + new_fd: wasi_snapshot0::Fd, new_path: WasmPtr, new_path_len: MemoryOffset, ) -> wasi_snapshot0::Errno { @@ -362,7 +371,7 @@ pub(crate) fn path_symlink( ctx: FunctionEnvMut, old_path: WasmPtr, old_path_len: MemoryOffset, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, new_path: WasmPtr, new_path_len: MemoryOffset, ) -> wasi_snapshot0::Errno { @@ -371,7 +380,7 @@ pub(crate) fn path_symlink( pub(crate) fn path_unlink_file( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, path: WasmPtr, path_len: MemoryOffset, ) -> wasi_snapshot0::Errno { @@ -412,8 +421,8 @@ pub(crate) fn random_get( pub(crate) fn fd_dup( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - ret_fd: WasmPtr<__wasi_fd_t, MemoryType>, + fd: wasi_snapshot0::Fd, + ret_fd: WasmPtr, ) -> wasi_snapshot0::Errno { super::fd_dup::(ctx, fd, ret_fd) } @@ -422,15 +431,15 @@ pub(crate) fn fd_event( ctx: FunctionEnvMut, initial_val: u64, flags: __wasi_eventfdflags, - ret_fd: WasmPtr<__wasi_fd_t, MemoryType>, + ret_fd: WasmPtr, ) -> wasi_snapshot0::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>, + ro_fd1: WasmPtr, + ro_fd2: WasmPtr, ) -> wasi_snapshot0::Errno { super::fd_pipe::(ctx, ro_fd1, ro_fd2) } @@ -762,7 +771,7 @@ pub(crate) fn ws_connect( ctx: FunctionEnvMut, url: WasmPtr, url_len: MemoryOffset, - ret_sock: WasmPtr<__wasi_fd_t, MemoryType>, + ret_sock: WasmPtr, ) -> wasi_snapshot0::Errno { super::ws_connect::(ctx, url, url_len, ret_sock) } @@ -793,7 +802,7 @@ pub(crate) fn http_request( pub(crate) fn http_status( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, status: WasmPtr<__wasi_http_status_t, MemoryType>, status_text: WasmPtr, status_text_len: WasmPtr, @@ -805,7 +814,7 @@ pub(crate) fn http_status( pub(crate) fn sock_status( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, ret_status: WasmPtr<__wasi_sockstatus_t, MemoryType>, ) -> wasi_snapshot0::Errno { super::sock_status::(ctx, sock, ret_status) @@ -813,7 +822,7 @@ pub(crate) fn sock_status( pub(crate) fn sock_addr_local( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, ret_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ) -> wasi_snapshot0::Errno { super::sock_addr_local::(ctx, sock, ret_addr) @@ -821,7 +830,7 @@ pub(crate) fn sock_addr_local( pub(crate) fn sock_addr_peer( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ) -> wasi_snapshot0::Errno { super::sock_addr_peer::(ctx, sock, ro_addr) @@ -832,14 +841,14 @@ pub(crate) fn sock_open( af: __wasi_addressfamily_t, ty: __wasi_socktype_t, pt: __wasi_sockproto_t, - ro_sock: WasmPtr<__wasi_fd_t, MemoryType>, + ro_sock: WasmPtr, ) -> wasi_snapshot0::Errno { super::sock_open::(ctx, af, ty, pt, ro_sock) } pub(crate) fn sock_set_opt_flag( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, opt: __wasi_sockoption_t, flag: __wasi_bool_t, ) -> wasi_snapshot0::Errno { @@ -848,7 +857,7 @@ pub(crate) fn sock_set_opt_flag( pub(crate) fn sock_get_opt_flag( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, opt: __wasi_sockoption_t, ret_flag: WasmPtr<__wasi_bool_t, MemoryType>, ) -> wasi_snapshot0::Errno { @@ -857,7 +866,7 @@ pub(crate) fn sock_get_opt_flag( pub fn sock_set_opt_time( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, opt: __wasi_sockoption_t, time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, ) -> wasi_snapshot0::Errno { @@ -866,7 +875,7 @@ pub fn sock_set_opt_time( pub fn sock_get_opt_time( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, opt: __wasi_sockoption_t, ret_time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, ) -> wasi_snapshot0::Errno { @@ -875,7 +884,7 @@ pub fn sock_get_opt_time( pub fn sock_set_opt_size( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, opt: __wasi_sockoption_t, size: __wasi_filesize_t, ) -> wasi_snapshot0::Errno { @@ -884,7 +893,7 @@ pub fn sock_set_opt_size( pub fn sock_get_opt_size( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, opt: __wasi_sockoption_t, ret_size: WasmPtr<__wasi_filesize_t, MemoryType>, ) -> wasi_snapshot0::Errno { @@ -893,7 +902,7 @@ pub fn sock_get_opt_size( pub(crate) fn sock_join_multicast_v4( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, multiaddr: WasmPtr<__wasi_addr_ip4_t, MemoryType>, iface: WasmPtr<__wasi_addr_ip4_t, MemoryType>, ) -> wasi_snapshot0::Errno { @@ -902,7 +911,7 @@ pub(crate) fn sock_join_multicast_v4( pub(crate) fn sock_leave_multicast_v4( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, multiaddr: WasmPtr<__wasi_addr_ip4_t, MemoryType>, iface: WasmPtr<__wasi_addr_ip4_t, MemoryType>, ) -> wasi_snapshot0::Errno { @@ -911,7 +920,7 @@ pub(crate) fn sock_leave_multicast_v4( pub(crate) fn sock_join_multicast_v6( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, multiaddr: WasmPtr<__wasi_addr_ip6_t, MemoryType>, iface: u32, ) -> wasi_snapshot0::Errno { @@ -920,7 +929,7 @@ pub(crate) fn sock_join_multicast_v6( pub(crate) fn sock_leave_multicast_v6( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, multiaddr: WasmPtr<__wasi_addr_ip6_t, MemoryType>, iface: u32, ) -> wasi_snapshot0::Errno { @@ -929,7 +938,7 @@ pub(crate) fn sock_leave_multicast_v6( pub(crate) fn sock_bind( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ) -> wasi_snapshot0::Errno { super::sock_bind::(ctx, sock, addr) @@ -937,7 +946,7 @@ pub(crate) fn sock_bind( pub(crate) fn sock_listen( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, backlog: MemoryOffset, ) -> wasi_snapshot0::Errno { super::sock_listen::(ctx, sock, backlog) @@ -945,9 +954,9 @@ pub(crate) fn sock_listen( pub(crate) fn sock_accept( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, fd_flags: wasi_snapshot0::Fdflags, - ro_fd: WasmPtr<__wasi_fd_t, MemoryType>, + ro_fd: WasmPtr, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ) -> Result { super::sock_accept::(ctx, sock, fd_flags, ro_fd, ro_addr) @@ -955,7 +964,7 @@ pub(crate) fn sock_accept( pub(crate) fn sock_connect( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ) -> wasi_snapshot0::Errno { super::sock_connect::(ctx, sock, addr) @@ -963,7 +972,7 @@ pub(crate) fn sock_connect( pub(crate) fn sock_recv( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, ri_data: WasmPtr<__wasi_iovec_t, MemoryType>, ri_data_len: MemoryOffset, ri_flags: __wasi_riflags_t, @@ -983,7 +992,7 @@ pub(crate) fn sock_recv( pub(crate) fn sock_recv_from( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, ri_data: WasmPtr<__wasi_iovec_t, MemoryType>, ri_data_len: MemoryOffset, ri_flags: __wasi_riflags_t, @@ -1005,7 +1014,7 @@ pub(crate) fn sock_recv_from( pub(crate) fn sock_send( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, si_data: WasmPtr<__wasi_ciovec_t, MemoryType>, si_data_len: MemoryOffset, si_flags: __wasi_siflags_t, @@ -1016,7 +1025,7 @@ pub(crate) fn sock_send( pub(crate) fn sock_send_to( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, si_data: WasmPtr<__wasi_ciovec_t, MemoryType>, si_data_len: MemoryOffset, si_flags: __wasi_siflags_t, @@ -1036,8 +1045,8 @@ pub(crate) fn sock_send_to( pub(crate) fn sock_send_file( ctx: FunctionEnvMut, - out_fd: __wasi_fd_t, - in_fd: __wasi_fd_t, + out_fd: wasi_snapshot0::Fd, + in_fd: wasi_snapshot0::Fd, offset: __wasi_filesize_t, count: __wasi_filesize_t, ret_sent: WasmPtr<__wasi_filesize_t, MemoryType>, @@ -1047,7 +1056,7 @@ pub(crate) fn sock_send_file( pub(crate) fn sock_shutdown( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, how: __wasi_sdflags_t, ) -> wasi_snapshot0::Errno { super::sock_shutdown(ctx, sock, how) diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index 81fd53575b5..004ab8fcb5e 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -58,7 +58,7 @@ pub(crate) fn environ_sizes_get( pub(crate) fn fd_advise( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, offset: __wasi_filesize_t, len: __wasi_filesize_t, advice: wasi_snapshot0::Advice, @@ -68,24 +68,30 @@ pub(crate) fn fd_advise( pub(crate) fn fd_allocate( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, offset: __wasi_filesize_t, len: __wasi_filesize_t, ) -> wasi_snapshot0::Errno { super::fd_allocate(ctx, fd, offset, len) } -pub(crate) fn fd_close(ctx: FunctionEnvMut, fd: __wasi_fd_t) -> wasi_snapshot0::Errno { +pub(crate) fn fd_close( + ctx: FunctionEnvMut, + fd: wasi_snapshot0::Fd, +) -> wasi_snapshot0::Errno { super::fd_close(ctx, fd) } -pub(crate) fn fd_datasync(ctx: FunctionEnvMut, fd: __wasi_fd_t) -> wasi_snapshot0::Errno { +pub(crate) fn fd_datasync( + ctx: FunctionEnvMut, + fd: wasi_snapshot0::Fd, +) -> wasi_snapshot0::Errno { super::fd_datasync(ctx, fd) } pub(crate) fn fd_fdstat_get( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, buf_ptr: WasmPtr, ) -> wasi_snapshot0::Errno { super::fd_fdstat_get::(ctx, fd, buf_ptr) @@ -93,7 +99,7 @@ pub(crate) fn fd_fdstat_get( pub(crate) fn fd_fdstat_set_flags( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, flags: wasi_snapshot0::Fdflags, ) -> wasi_snapshot0::Errno { super::fd_fdstat_set_flags(ctx, fd, flags) @@ -101,7 +107,7 @@ pub(crate) fn fd_fdstat_set_flags( pub(crate) fn fd_fdstat_set_rights( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, fs_rights_base: wasi_snapshot0::Rights, fs_rights_inheriting: wasi_snapshot0::Rights, ) -> wasi_snapshot0::Errno { @@ -110,7 +116,7 @@ pub(crate) fn fd_fdstat_set_rights( pub(crate) fn fd_filestat_get( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, buf: WasmPtr<__wasi_filestat_t, MemoryType>, ) -> wasi_snapshot0::Errno { super::fd_filestat_get::(ctx, fd, buf) @@ -118,7 +124,7 @@ pub(crate) fn fd_filestat_get( pub(crate) fn fd_filestat_set_size( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, st_size: __wasi_filesize_t, ) -> wasi_snapshot0::Errno { super::fd_filestat_set_size(ctx, fd, st_size) @@ -126,7 +132,7 @@ pub(crate) fn fd_filestat_set_size( pub(crate) fn fd_filestat_set_times( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, st_atim: __wasi_timestamp_t, st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, @@ -136,7 +142,7 @@ pub(crate) fn fd_filestat_set_times( pub(crate) fn fd_pread( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, offset: __wasi_filesize_t, @@ -147,7 +153,7 @@ pub(crate) fn fd_pread( pub(crate) fn fd_prestat_get( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, buf: WasmPtr<__wasi_prestat_t, MemoryType>, ) -> wasi_snapshot0::Errno { super::fd_prestat_get::(ctx, fd, buf) @@ -155,7 +161,7 @@ pub(crate) fn fd_prestat_get( pub(crate) fn fd_prestat_dir_name( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, path: WasmPtr, path_len: MemoryOffset, ) -> wasi_snapshot0::Errno { @@ -164,7 +170,7 @@ pub(crate) fn fd_prestat_dir_name( pub(crate) fn fd_pwrite( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, offset: __wasi_filesize_t, @@ -175,7 +181,7 @@ pub(crate) fn fd_pwrite( pub(crate) fn fd_read( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, nread: WasmPtr, @@ -185,7 +191,7 @@ pub(crate) fn fd_read( pub(crate) fn fd_readdir( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, buf: WasmPtr, buf_len: MemoryOffset, cookie: wasi_snapshot0::Dircookie, @@ -196,15 +202,15 @@ pub(crate) fn fd_readdir( pub(crate) fn fd_renumber( ctx: FunctionEnvMut, - from: __wasi_fd_t, - to: __wasi_fd_t, + from: wasi_snapshot0::Fd, + to: wasi_snapshot0::Fd, ) -> wasi_snapshot0::Errno { super::fd_renumber(ctx, from, to) } pub(crate) fn fd_seek( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, offset: __wasi_filedelta_t, whence: __wasi_whence_t, newoffset: WasmPtr<__wasi_filesize_t, MemoryType>, @@ -212,13 +218,16 @@ pub(crate) fn fd_seek( super::fd_seek::(ctx, fd, offset, whence, newoffset) } -pub(crate) fn fd_sync(ctx: FunctionEnvMut, fd: __wasi_fd_t) -> wasi_snapshot0::Errno { +pub(crate) fn fd_sync( + ctx: FunctionEnvMut, + fd: wasi_snapshot0::Fd, +) -> wasi_snapshot0::Errno { super::fd_sync(ctx, fd) } pub(crate) fn fd_tell( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, offset: WasmPtr<__wasi_filesize_t, MemoryType>, ) -> wasi_snapshot0::Errno { super::fd_tell::(ctx, fd, offset) @@ -226,7 +235,7 @@ pub(crate) fn fd_tell( pub(crate) fn fd_write( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, nwritten: WasmPtr, @@ -236,7 +245,7 @@ pub(crate) fn fd_write( pub(crate) fn path_create_directory( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, path: WasmPtr, path_len: MemoryOffset, ) -> wasi_snapshot0::Errno { @@ -245,7 +254,7 @@ pub(crate) fn path_create_directory( pub(crate) fn path_filestat_get( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, flags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, @@ -256,7 +265,7 @@ pub(crate) fn path_filestat_get( pub(crate) fn path_filestat_set_times( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, flags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, @@ -271,11 +280,11 @@ pub(crate) fn path_filestat_set_times( pub(crate) fn path_link( ctx: FunctionEnvMut, - old_fd: __wasi_fd_t, + old_fd: wasi_snapshot0::Fd, old_flags: __wasi_lookupflags_t, old_path: WasmPtr, old_path_len: MemoryOffset, - new_fd: __wasi_fd_t, + new_fd: wasi_snapshot0::Fd, new_path: WasmPtr, new_path_len: MemoryOffset, ) -> wasi_snapshot0::Errno { @@ -293,7 +302,7 @@ pub(crate) fn path_link( pub(crate) fn path_open( ctx: FunctionEnvMut, - dirfd: __wasi_fd_t, + dirfd: wasi_snapshot0::Fd, dirflags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, @@ -301,7 +310,7 @@ pub(crate) fn path_open( fs_rights_base: wasi_snapshot0::Rights, fs_rights_inheriting: wasi_snapshot0::Rights, fs_flags: wasi_snapshot0::Fdflags, - fd: WasmPtr<__wasi_fd_t, MemoryType>, + fd: WasmPtr, ) -> wasi_snapshot0::Errno { super::path_open::( ctx, @@ -319,7 +328,7 @@ pub(crate) fn path_open( pub(crate) fn path_readlink( ctx: FunctionEnvMut, - dir_fd: __wasi_fd_t, + dir_fd: wasi_snapshot0::Fd, path: WasmPtr, path_len: MemoryOffset, buf: WasmPtr, @@ -331,7 +340,7 @@ pub(crate) fn path_readlink( pub(crate) fn path_remove_directory( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, path: WasmPtr, path_len: MemoryOffset, ) -> wasi_snapshot0::Errno { @@ -340,10 +349,10 @@ pub(crate) fn path_remove_directory( pub(crate) fn path_rename( ctx: FunctionEnvMut, - old_fd: __wasi_fd_t, + old_fd: wasi_snapshot0::Fd, old_path: WasmPtr, old_path_len: MemoryOffset, - new_fd: __wasi_fd_t, + new_fd: wasi_snapshot0::Fd, new_path: WasmPtr, new_path_len: MemoryOffset, ) -> wasi_snapshot0::Errno { @@ -362,7 +371,7 @@ pub(crate) fn path_symlink( ctx: FunctionEnvMut, old_path: WasmPtr, old_path_len: MemoryOffset, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, new_path: WasmPtr, new_path_len: MemoryOffset, ) -> wasi_snapshot0::Errno { @@ -371,7 +380,7 @@ pub(crate) fn path_symlink( pub(crate) fn path_unlink_file( ctx: FunctionEnvMut, - fd: __wasi_fd_t, + fd: wasi_snapshot0::Fd, path: WasmPtr, path_len: MemoryOffset, ) -> wasi_snapshot0::Errno { @@ -412,8 +421,8 @@ pub(crate) fn random_get( pub(crate) fn fd_dup( ctx: FunctionEnvMut, - fd: __wasi_fd_t, - ret_fd: WasmPtr<__wasi_fd_t, MemoryType>, + fd: wasi_snapshot0::Fd, + ret_fd: WasmPtr, ) -> wasi_snapshot0::Errno { super::fd_dup::(ctx, fd, ret_fd) } @@ -422,15 +431,15 @@ pub(crate) fn fd_event( ctx: FunctionEnvMut, initial_val: u64, flags: __wasi_eventfdflags, - ret_fd: WasmPtr<__wasi_fd_t, MemoryType>, + ret_fd: WasmPtr, ) -> wasi_snapshot0::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>, + ro_fd1: WasmPtr, + ro_fd2: WasmPtr, ) -> wasi_snapshot0::Errno { super::fd_pipe::(ctx, ro_fd1, ro_fd2) } @@ -762,7 +771,7 @@ pub(crate) fn ws_connect( ctx: FunctionEnvMut, url: WasmPtr, url_len: MemoryOffset, - ret_sock: WasmPtr<__wasi_fd_t, MemoryType>, + ret_sock: WasmPtr, ) -> wasi_snapshot0::Errno { super::ws_connect::(ctx, url, url_len, ret_sock) } @@ -793,7 +802,7 @@ pub(crate) fn http_request( pub(crate) fn http_status( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, status: WasmPtr<__wasi_http_status_t, MemoryType>, status_text: WasmPtr, status_text_len: WasmPtr, @@ -805,7 +814,7 @@ pub(crate) fn http_status( pub(crate) fn sock_status( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, ret_status: WasmPtr<__wasi_sockstatus_t, MemoryType>, ) -> wasi_snapshot0::Errno { super::sock_status::(ctx, sock, ret_status) @@ -813,7 +822,7 @@ pub(crate) fn sock_status( pub(crate) fn sock_addr_local( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, ret_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ) -> wasi_snapshot0::Errno { super::sock_addr_local::(ctx, sock, ret_addr) @@ -821,7 +830,7 @@ pub(crate) fn sock_addr_local( pub(crate) fn sock_addr_peer( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ) -> wasi_snapshot0::Errno { super::sock_addr_peer::(ctx, sock, ro_addr) @@ -832,14 +841,14 @@ pub(crate) fn sock_open( af: __wasi_addressfamily_t, ty: __wasi_socktype_t, pt: __wasi_sockproto_t, - ro_sock: WasmPtr<__wasi_fd_t, MemoryType>, + ro_sock: WasmPtr, ) -> wasi_snapshot0::Errno { super::sock_open::(ctx, af, ty, pt, ro_sock) } pub(crate) fn sock_set_opt_flag( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, opt: __wasi_sockoption_t, flag: __wasi_bool_t, ) -> wasi_snapshot0::Errno { @@ -848,7 +857,7 @@ pub(crate) fn sock_set_opt_flag( pub(crate) fn sock_get_opt_flag( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, opt: __wasi_sockoption_t, ret_flag: WasmPtr<__wasi_bool_t, MemoryType>, ) -> wasi_snapshot0::Errno { @@ -857,7 +866,7 @@ pub(crate) fn sock_get_opt_flag( pub fn sock_set_opt_time( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, opt: __wasi_sockoption_t, time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, ) -> wasi_snapshot0::Errno { @@ -866,7 +875,7 @@ pub fn sock_set_opt_time( pub fn sock_get_opt_time( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, opt: __wasi_sockoption_t, ret_time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, ) -> wasi_snapshot0::Errno { @@ -875,7 +884,7 @@ pub fn sock_get_opt_time( pub fn sock_set_opt_size( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, opt: __wasi_sockoption_t, size: __wasi_filesize_t, ) -> wasi_snapshot0::Errno { @@ -884,7 +893,7 @@ pub fn sock_set_opt_size( pub fn sock_get_opt_size( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, opt: __wasi_sockoption_t, ret_size: WasmPtr<__wasi_filesize_t, MemoryType>, ) -> wasi_snapshot0::Errno { @@ -893,7 +902,7 @@ pub fn sock_get_opt_size( pub(crate) fn sock_join_multicast_v4( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, multiaddr: WasmPtr<__wasi_addr_ip4_t, MemoryType>, iface: WasmPtr<__wasi_addr_ip4_t, MemoryType>, ) -> wasi_snapshot0::Errno { @@ -902,7 +911,7 @@ pub(crate) fn sock_join_multicast_v4( pub(crate) fn sock_leave_multicast_v4( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, multiaddr: WasmPtr<__wasi_addr_ip4_t, MemoryType>, iface: WasmPtr<__wasi_addr_ip4_t, MemoryType>, ) -> wasi_snapshot0::Errno { @@ -911,7 +920,7 @@ pub(crate) fn sock_leave_multicast_v4( pub(crate) fn sock_join_multicast_v6( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, multiaddr: WasmPtr<__wasi_addr_ip6_t, MemoryType>, iface: u32, ) -> wasi_snapshot0::Errno { @@ -920,7 +929,7 @@ pub(crate) fn sock_join_multicast_v6( pub(crate) fn sock_leave_multicast_v6( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, multiaddr: WasmPtr<__wasi_addr_ip6_t, MemoryType>, iface: u32, ) -> wasi_snapshot0::Errno { @@ -929,7 +938,7 @@ pub(crate) fn sock_leave_multicast_v6( pub(crate) fn sock_bind( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ) -> wasi_snapshot0::Errno { super::sock_bind::(ctx, sock, addr) @@ -937,7 +946,7 @@ pub(crate) fn sock_bind( pub(crate) fn sock_listen( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, backlog: MemoryOffset, ) -> wasi_snapshot0::Errno { super::sock_listen::(ctx, sock, backlog) @@ -945,9 +954,9 @@ pub(crate) fn sock_listen( pub(crate) fn sock_accept( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, fd_flags: wasi_snapshot0::Fdflags, - ro_fd: WasmPtr<__wasi_fd_t, MemoryType>, + ro_fd: WasmPtr, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ) -> Result { super::sock_accept::(ctx, sock, fd_flags, ro_fd, ro_addr) @@ -955,7 +964,7 @@ pub(crate) fn sock_accept( pub(crate) fn sock_connect( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ) -> wasi_snapshot0::Errno { super::sock_connect::(ctx, sock, addr) @@ -963,7 +972,7 @@ pub(crate) fn sock_connect( pub(crate) fn sock_recv( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, ri_data: WasmPtr<__wasi_iovec_t, MemoryType>, ri_data_len: MemoryOffset, ri_flags: __wasi_riflags_t, @@ -983,7 +992,7 @@ pub(crate) fn sock_recv( pub(crate) fn sock_recv_from( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, ri_data: WasmPtr<__wasi_iovec_t, MemoryType>, ri_data_len: MemoryOffset, ri_flags: __wasi_riflags_t, @@ -1005,7 +1014,7 @@ pub(crate) fn sock_recv_from( pub(crate) fn sock_send( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, si_data: WasmPtr<__wasi_ciovec_t, MemoryType>, si_data_len: MemoryOffset, si_flags: __wasi_siflags_t, @@ -1016,7 +1025,7 @@ pub(crate) fn sock_send( pub(crate) fn sock_send_to( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, si_data: WasmPtr<__wasi_ciovec_t, MemoryType>, si_data_len: MemoryOffset, si_flags: __wasi_siflags_t, @@ -1036,8 +1045,8 @@ pub(crate) fn sock_send_to( pub(crate) fn sock_send_file( ctx: FunctionEnvMut, - out_fd: __wasi_fd_t, - in_fd: __wasi_fd_t, + out_fd: wasi_snapshot0::Fd, + in_fd: wasi_snapshot0::Fd, offset: __wasi_filesize_t, count: __wasi_filesize_t, ret_sent: WasmPtr<__wasi_filesize_t, MemoryType>, @@ -1047,7 +1056,7 @@ pub(crate) fn sock_send_file( pub(crate) fn sock_shutdown( ctx: FunctionEnvMut, - sock: __wasi_fd_t, + sock: wasi_snapshot0::Fd, how: __wasi_sdflags_t, ) -> wasi_snapshot0::Errno { super::sock_shutdown(ctx, sock, how) From 06ced06008188a0369c96e4db200be6a72d17bd9 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Fri, 19 Aug 2022 11:49:50 +0200 Subject: [PATCH 19/84] WIP --- lib/wasi-types-generated/regenerate.sh | 23 +- lib/wasi-types-generated/src/lib.rs | 345 +--- .../src/wasi_filesystem/bindings.rs | 814 ++++++++ .../src/wasi_filesystem/mod.rs | 2 + .../src/wasi_io_typenames/bindings.rs | 796 ++++++++ .../src/wasi_io_typenames/mod.rs | 156 ++ .../src/{ => wasi_snapshot0}/bindings.rs | 921 +-------- .../src/wasi_snapshot0/mod.rs | 494 +++++ .../wit/wasi-io-typenames.wit | 719 +++++++ .../wit/wasi-snapshot0.wit | 74 +- lib/wasi-types/src/event.rs | 8 - lib/wasi-types/src/subscription.rs | 84 +- lib/wasi-types/src/versions/snapshot0.rs | 14 +- lib/wasi/src/macros.rs | 12 +- lib/wasi/src/state/mod.rs | 478 +++-- lib/wasi/src/state/types.rs | 140 +- lib/wasi/src/syscalls/legacy/snapshot0.rs | 40 +- lib/wasi/src/syscalls/mod.rs | 1655 +++++++---------- 18 files changed, 4176 insertions(+), 2599 deletions(-) create mode 100644 lib/wasi-types-generated/src/wasi_filesystem/bindings.rs create mode 100644 lib/wasi-types-generated/src/wasi_filesystem/mod.rs create mode 100644 lib/wasi-types-generated/src/wasi_io_typenames/bindings.rs create mode 100644 lib/wasi-types-generated/src/wasi_io_typenames/mod.rs rename lib/wasi-types-generated/src/{ => wasi_snapshot0}/bindings.rs (51%) create mode 100644 lib/wasi-types-generated/src/wasi_snapshot0/mod.rs create mode 100644 lib/wasi-types-generated/wit/wasi-io-typenames.wit diff --git a/lib/wasi-types-generated/regenerate.sh b/lib/wasi-types-generated/regenerate.sh index e181d71caa2..4aa2a046f4e 100755 --- a/lib/wasi-types-generated/regenerate.sh +++ b/lib/wasi-types-generated/regenerate.sh @@ -1,5 +1,24 @@ #!/bin/bash -rm src/bindings.rs -wit-bindgen wasmer --import wit/wasi-snapshot0.wit wit/wasi-filesystem.wit --out-dir src/ +BASEDIR=$(dirname "$0") + +rm -f \ + "$BASEDIR"/src/bindings.rs \ + "$BASEDIR"/src/*/bindings.rs + +wit-bindgen wasmer \ + --import \ + "$BASEDIR"/wit/wasi-filesystem.wit \ + --out-dir "$BASEDIR"/src/wasi_filesystem + +wit-bindgen wasmer \ + --import \ + "$BASEDIR"/wit/wasi-io-typenames.wit \ + --out-dir "$BASEDIR"/src/wasi_io_typenames + +wit-bindgen wasmer \ + --import \ + "$BASEDIR"/wit/wasi-snapshot0.wit \ + --out-dir "$BASEDIR"/src/wasi_snapshot0 + #wit-bindgen rust-wasm --import wit/wasi-snapshot0.wit wit/wasi-filesystem.wit --out-dir . diff --git a/lib/wasi-types-generated/src/lib.rs b/lib/wasi-types-generated/src/lib.rs index 947ae274af8..6df96306a6a 100644 --- a/lib/wasi-types-generated/src/lib.rs +++ b/lib/wasi-types-generated/src/lib.rs @@ -1,342 +1,3 @@ -mod bindings; - -pub use bindings::*; - -use std::mem::MaybeUninit; -use wasmer_types::ValueType; - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for wasi_snapshot0::Errno { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for wasi_snapshot0::Filetype { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for wasi_snapshot0::Eventtype { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for wasi_snapshot0::Rights { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for wasi_snapshot0::Eventrwflags { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for wasi_snapshot0::Subclockflags { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for wasi_snapshot0::Clockid { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for wasi_snapshot0::Fdflags { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for wasi_snapshot0::Preopentype { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for wasi_snapshot0::Fdstat { - 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)*) + std::mem::size_of_val(&self.$($f)*) - }; - } - macro_rules! zero { - ($start:expr, $end:expr) => { - for i in $start..$end { - bytes[i] = MaybeUninit::new(0); - } - }; - } - - self.fs_filetype - .zero_padding_bytes(&mut bytes[field!(fs_filetype)..field_end!(fs_filetype)]); - zero!(field_end!(fs_filetype), field!(fs_flags)); - - self.fs_flags - .zero_padding_bytes(&mut bytes[field!(fs_flags)..field_end!(fs_flags)]); - zero!(field_end!(fs_flags), field!(fs_rights_base)); - - self.fs_rights_base - .zero_padding_bytes(&mut bytes[field!(fs_rights_base)..field_end!(fs_rights_base)]); - zero!( - field_end!(fs_rights_inheriting), - std::mem::size_of_val(self) - ); - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0::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::Acces, - 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, - // TODO: What should we map invalid native values to? - _ => Self::Inval, - } - } - - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0::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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } - - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0::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) - } - - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0::Eventrwflags { - 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 u8) - } - - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0::Subclockflags { - 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 u8) - } - - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0::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, - 2 => Self::ProcessCputimeId, - 3 => Self::ThreadCputimeId, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } - - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0::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 u8) - } - - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for wasi_snapshot0::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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } - - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} +pub mod wasi_filesystem; +pub mod wasi_io_typenames; +pub mod wasi_snapshot0; diff --git a/lib/wasi-types-generated/src/wasi_filesystem/bindings.rs b/lib/wasi-types-generated/src/wasi_filesystem/bindings.rs new file mode 100644 index 00000000000..7473d7f699e --- /dev/null +++ b/lib/wasi-types-generated/src/wasi_filesystem/bindings.rs @@ -0,0 +1,814 @@ +#[allow(clippy::all)] +pub mod wasi_filesystem { + #[allow(unused_imports)] + use wit_bindgen_wasmer::{anyhow, wasmer}; + /// The type of a filesystem object referenced by a descriptor. + /// + /// Note: This was called `filetype` in earlier versions of WASI. + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum Type { + /// The type of the descriptor or file is unknown or is different from + /// any of the other types specified. + Unknown, + /// The descriptor refers to a block device inode. + BlockDevice, + /// The descriptor refers to a character device inode. + CharacterDevice, + /// The descriptor refers to a directory inode. + Directory, + /// The descriptor refers to a named pipe. + Fifo, + /// The file refers to a symbolic link inode. + SymbolicLink, + /// The descriptor refers to a regular file inode. + RegularFile, + /// The descriptor refers to a socket. + Socket, + } + impl core::fmt::Debug for Type { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Type::Unknown => { + f.debug_tuple("Type::Unknown").finish() + } + Type::BlockDevice => { + f.debug_tuple("Type::BlockDevice").finish() + } + Type::CharacterDevice => { + f.debug_tuple("Type::CharacterDevice").finish() + } + Type::Directory => { + f.debug_tuple("Type::Directory").finish() + } + Type::Fifo => { + f.debug_tuple("Type::Fifo").finish() + } + Type::SymbolicLink => { + f.debug_tuple("Type::SymbolicLink").finish() + } + Type::RegularFile => { + f.debug_tuple("Type::RegularFile").finish() + } + Type::Socket => { + f.debug_tuple("Type::Socket").finish() + } + } + } + } + wit_bindgen_wasmer::bitflags::bitflags! { + /// Descriptor flags. + /// + /// Note: This was called `fd-flags` in earlier versions of WASI. + pub struct Flags: u8 {/// Read mode: Data can be read. + const READ = 1 << 0; + /// Write mode: Data can be written to. + const WRITE = 1 << 1; + /// Append mode: Data written to the file is always appended to the file's + /// end. + const APPEND = 1 << 2; + /// Write according to synchronized I/O data integrity completion. Only the + /// data stored in the file is synchronized. + const DSYNC = 1 << 3; + /// Non-blocking mode. + const NONBLOCK = 1 << 4; + /// Synchronized read I/O operations. + const RSYNC = 1 << 5; + /// 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 << 6; + } + } + + impl core::fmt::Display for Flags{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("Flags(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(())} + } + + wit_bindgen_wasmer::bitflags::bitflags! { + /// Flags determining the method of how paths are resolved. + pub struct AtFlags: u8 {/// As long as the resolved path corresponds to a symbolic link, it is expanded. + const SYMLINK_FOLLOW = 1 << 0; + } + } + + impl core::fmt::Display for AtFlags{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("AtFlags(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(())} + } + + wit_bindgen_wasmer::bitflags::bitflags! { + /// Open flags used by `open-at`. + 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 core::fmt::Display for OFlags{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("OFlags(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(())} + } + + wit_bindgen_wasmer::bitflags::bitflags! { + /// Permissions mode used by `open-at`, `change-permissions-at`, and similar. + pub struct Mode: u8 {/// True if the resource is considered readable by the containing + /// filesystem. + const READABLE = 1 << 0; + /// True if the resource is considered writeable by the containing + /// filesystem. + const WRITEABLE = 1 << 1; + /// True if the resource is considered executable by the containing + /// filesystem. This does not apply to directories. + const EXECUTABLE = 1 << 2; + } + } + + impl core::fmt::Display for Mode{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("Mode(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(())} + } + + /// 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. This is similar to `E2BIG` in POSIX. + 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 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, + } + 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::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", + } + } + pub fn message(&self) -> &'static str { + match self { + Errno::Success => "No error occurred. System call completed successfully.", + Errno::Toobig => "Argument list too long. This is similar to `E2BIG` in POSIX.", + 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::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.", + } + } + } + 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{} + /// 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() + } + } + } + } + /// A descriptor is a reference to a filesystem object, which may be a file, + /// directory, named pipe, special file, or other object on which filesystem + /// calls may be made. + #[derive(Debug)] + pub struct Descriptor(wit_bindgen_wasmer::rt::ResourceIndex); + + /// Auxiliary data associated with the wasm exports. + #[derive(Default)] + pub struct WasiFilesystemData { + + index_slab0: wit_bindgen_wasmer::rt::IndexSlab, + resource_slab0: wit_bindgen_wasmer::rt::ResourceSlab, + dtor0: OnceCell>, + } + + pub struct WasiFilesystem { + #[allow(dead_code)] + env: wasmer::FunctionEnv, + func_descriptor_fadvise: wasmer::TypedFunction<(i32,i64,i64,i32,), i32>, + memory: wasmer::Memory, + } + impl WasiFilesystem { + + /// Adds any intrinsics, if necessary for this exported wasm + /// functionality to the `ImportObject` provided. + /// + /// This function returns the `WasiFilesystemData` which needs to be + /// passed through to `WasiFilesystem::new`. + fn add_to_imports( + mut store: impl wasmer::AsStoreMut, + imports: &mut wasmer::Imports, + ) -> wasmer::FunctionEnv { + let env = wasmer::FunctionEnv::new(&mut store, WasiFilesystemData::default()); + let mut canonical_abi = imports.get_namespace_exports("canonical_abi").unwrap_or_else(wasmer::Exports::new); + + canonical_abi.insert( + "resource_drop_descriptor", + wasmer::Function::new_typed_with_env( + &mut store, + &env, + move |mut store: wasmer::FunctionEnvMut, idx: u32| -> Result<(), wasmer::RuntimeError> { + let resource_idx = store.data_mut().index_slab0.remove(idx)?; + let wasm = match store.data_mut().resource_slab0.drop(resource_idx) { + Some(wasm) => wasm, + None => return Ok(()), + }; + let dtor = store.data_mut().dtor0.get().unwrap().clone(); + dtor.call(&mut store, wasm)?; + Ok(()) + }, + ) + ); + canonical_abi.insert( + "resource_clone_descriptor", + wasmer::Function::new_typed_with_env( + &mut store, + &env, + move |mut store: wasmer::FunctionEnvMut, idx: u32| -> Result { + let state = &mut *store.data_mut(); + let resource_idx = state.index_slab0.get(idx)?; + state.resource_slab0.clone(resource_idx)?; + Ok(state.index_slab0.insert(resource_idx)) + }, + ) + ); + canonical_abi.insert( + "resource_get_descriptor", + wasmer::Function::new_typed_with_env( + &mut store, + &env, + move |mut store: wasmer::FunctionEnvMut, idx: u32| -> Result { + let state = &mut *store.data_mut(); + let resource_idx = state.index_slab0.get(idx)?; + Ok(state.resource_slab0.get(resource_idx)) + }, + ) + ); + canonical_abi.insert( + "resource_new_descriptor", + wasmer::Function::new_typed_with_env( + &mut store, + &env, + move |mut store: wasmer::FunctionEnvMut, val: i32| -> Result { + let state = &mut *store.data_mut(); + let resource_idx = state.resource_slab0.insert(val); + Ok(state.index_slab0.insert(resource_idx)) + }, + ) + ); + imports.register_namespace("canonical_abi", canonical_abi); + env + } + + /// Instantiates the provided `module` using the specified + /// parameters, wrapping up the result in a structure that + /// translates between wasm and the host. + /// + /// The `imports` provided will have intrinsics added to it + /// automatically, so it's not necessary to call + /// `add_to_imports` beforehand. This function will + /// instantiate the `module` otherwise using `imports`, and + /// both an instance of this structure and the underlying + /// `wasmer::Instance` will be returned. + pub fn instantiate( + mut store: impl wasmer::AsStoreMut, + module: &wasmer::Module, + imports: &mut wasmer::Imports, + ) -> anyhow::Result<(Self, wasmer::Instance)> { + let env = Self::add_to_imports(&mut store, imports); + let instance = wasmer::Instance::new( + &mut store, module, &*imports)?; + { + let dtor0 = instance + .exports + .get_typed_function( + &store, + "canonical_abi_drop_descriptor", + )? + .clone(); + + env + .as_mut(&mut store) + .dtor0 + .set(dtor0) + .map_err(|_e| anyhow::anyhow!("Couldn't set canonical_abi_drop_descriptor"))?; + } + + Ok((Self::new(store, &instance, env)?, instance)) + } + + /// Low-level creation wrapper for wrapping up the exports + /// of the `instance` provided in this structure of wasm + /// exports. + /// + /// This function will extract exports from the `instance` + /// and wrap them all up in the returned structure which can + /// be used to interact with the wasm module. + pub fn new( + store: impl wasmer::AsStoreMut, + _instance: &wasmer::Instance, + env: wasmer::FunctionEnv, + ) -> Result { + let func_descriptor_fadvise= _instance.exports.get_typed_function(&store, "descriptor::fadvise")?; + let memory= _instance.exports.get_memory("memory")?.clone(); + Ok(WasiFilesystem{ + func_descriptor_fadvise, + memory, + env, + }) + } + /// Provide file advisory information on a descriptor. + /// + /// This is similar to `posix_fadvise` in POSIX. + pub fn descriptor_fadvise(&self, store: &mut wasmer::Store,self_: & Descriptor,offset: u64,len: u64,advice: Advice,)-> Result, wasmer::RuntimeError> { + let _memory = &self.memory; + + let obj0 = self_; + let handle0 = { + let state = self.env.as_mut(store); + state.resource_slab0.clone(obj0.0)?; + state.index_slab0.insert(obj0.0) + }; + let result1 = self.func_descriptor_fadvise.call(store, handle0 as i32, wit_bindgen_wasmer::rt::as_i64(offset), wit_bindgen_wasmer::rt::as_i64(len), advice as i32, )?; + let _memory_view = _memory.view(&store); + let load2 = unsafe { _memory_view.data_unchecked_mut() }.load::(result1 + 0)?; + Ok(match i32::from(load2) { + 0 => Ok(()), + 1 => Err({ + let _memory_view = _memory.view(&store); + let load3 = unsafe { _memory_view.data_unchecked_mut() }.load::(result1 + 1)?; + match i32::from(load3) { + 0 => Errno::Success, + 1 => Errno::Toobig, + 2 => Errno::Access, + 3 => Errno::Addrinuse, + 4 => Errno::Addrnotavail, + 5 => Errno::Afnosupport, + 6 => Errno::Again, + 7 => Errno::Already, + 8 => Errno::Badmsg, + 9 => Errno::Busy, + 10 => Errno::Canceled, + 11 => Errno::Child, + 12 => Errno::Connaborted, + 13 => Errno::Connrefused, + 14 => Errno::Connreset, + 15 => Errno::Deadlk, + 16 => Errno::Destaddrreq, + 17 => Errno::Dom, + 18 => Errno::Dquot, + 19 => Errno::Exist, + 20 => Errno::Fault, + 21 => Errno::Fbig, + 22 => Errno::Hostunreach, + 23 => Errno::Idrm, + 24 => Errno::Ilseq, + 25 => Errno::Inprogress, + 26 => Errno::Intr, + 27 => Errno::Inval, + 28 => Errno::Io, + 29 => Errno::Isconn, + 30 => Errno::Isdir, + 31 => Errno::Loop, + 32 => Errno::Mfile, + 33 => Errno::Mlink, + 34 => Errno::Msgsize, + 35 => Errno::Multihop, + 36 => Errno::Nametoolong, + 37 => Errno::Netdown, + 38 => Errno::Netreset, + 39 => Errno::Netunreach, + 40 => Errno::Nfile, + 41 => Errno::Nobufs, + 42 => Errno::Nodev, + 43 => Errno::Noent, + 44 => Errno::Noexec, + 45 => Errno::Nolck, + 46 => Errno::Nolink, + 47 => Errno::Nomem, + 48 => Errno::Nomsg, + 49 => Errno::Noprotoopt, + 50 => Errno::Nospc, + 51 => Errno::Nosys, + 52 => Errno::Notconn, + 53 => Errno::Notdir, + 54 => Errno::Notempty, + 55 => Errno::Notrecoverable, + 56 => Errno::Notsock, + 57 => Errno::Notsup, + 58 => Errno::Notty, + 59 => Errno::Nxio, + 60 => Errno::Overflow, + 61 => Errno::Ownerdead, + 62 => Errno::Perm, + 63 => Errno::Pipe, + 64 => Errno::Proto, + 65 => Errno::Protonosupport, + 66 => Errno::Prototype, + 67 => Errno::Range, + 68 => Errno::Rofs, + 69 => Errno::Spipe, + 70 => Errno::Srch, + 71 => Errno::Stale, + 72 => Errno::Timedout, + 73 => Errno::Txtbsy, + 74 => Errno::Xdev, + _ => return Err(invalid_variant("Errno")), + } + }), + _ => return Err(invalid_variant("expected")), + }) + } + + /// Drops the host-owned handle to the resource + /// specified. + /// + /// Note that this may execute the WebAssembly-defined + /// destructor for this type. This also may not run + /// the destructor if there are still other references + /// to this type. + pub fn drop_descriptor( + &self, + store: &mut wasmer::Store, + val: Descriptor, + ) -> Result<(), wasmer::RuntimeError> { + let state = self.env.as_mut(store); + let wasm = match state.resource_slab0.drop(val.0) { + Some(val) => val, + None => return Ok(()), + }; + let dtor0 = state.dtor0.get().unwrap().clone(); + dtor0.call(store, wasm)?; + Ok(()) + } + } + use wit_bindgen_wasmer::once_cell::unsync::OnceCell; + #[allow(unused_imports)] + use wasmer::AsStoreMut as _; + #[allow(unused_imports)] + use wasmer::AsStoreRef as _; + use wit_bindgen_wasmer::rt::RawMem; + use wit_bindgen_wasmer::rt::invalid_variant; +} diff --git a/lib/wasi-types-generated/src/wasi_filesystem/mod.rs b/lib/wasi-types-generated/src/wasi_filesystem/mod.rs new file mode 100644 index 00000000000..3092f553d6d --- /dev/null +++ b/lib/wasi-types-generated/src/wasi_filesystem/mod.rs @@ -0,0 +1,2 @@ +mod bindings; +pub use bindings::wasi_filesystem::*; diff --git a/lib/wasi-types-generated/src/wasi_io_typenames/bindings.rs b/lib/wasi-types-generated/src/wasi_io_typenames/bindings.rs new file mode 100644 index 00000000000..eb2d042c284 --- /dev/null +++ b/lib/wasi-types-generated/src/wasi_io_typenames/bindings.rs @@ -0,0 +1,796 @@ +#[allow(clippy::all)] +pub mod wasi_io_typenames { + #[allow(unused_imports)] + use wit_bindgen_wasmer::{anyhow, wasmer}; + /// Timestamp in nanoseconds. + pub type Timestamp = u64; + /// 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{} + wit_bindgen_wasmer::bitflags::bitflags! { + /// File descriptor rights, determining which actions may be performed. + pub struct Rights: u32 {/// The right to invoke `fd_datasync`. + /// + /// If `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 `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 `path_open` is set, the right to invoke `path_open` with `oflags::create`. + 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. + /// If `path_open` is set, includes the right to invoke `path_open` with `oflags::trunc`. + /// Note: there is no function named `path_filestat_set_size`. This follows POSIX design, + /// which only has `ftruncate` and does not provide `ftruncateat`. + /// While such function would be desirable from the API design perspective, there are virtually + /// no use cases for it since no code written for POSIX systems would use it. + /// Moreover, implementing it would require multiple syscalls, leading to inferior performance. + 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 `path_permissions_set`. + const PATH_PERMISSIONS_SET = 1 << 21; + /// The right to invoke `fd_filestat_get`. + const FD_FILESTAT_GET = 1 << 22; + /// The right to invoke `fd_filestat_set_size`. + const FD_FILESTAT_SET_SIZE = 1 << 23; + /// The right to invoke `fd_filestat_set_times`. + const FD_FILESTAT_SET_TIMES = 1 << 24; + /// The right to invoke `fd_permissions_set`. + const FD_PERMISSIONS_SET = 1 << 25; + /// The right to invoke `path_symlink`. + const PATH_SYMLINK = 1 << 26; + /// The right to invoke `path_remove_directory`. + const PATH_REMOVE_DIRECTORY = 1 << 27; + /// The right to invoke `path_unlink_file`. + const PATH_UNLINK_FILE = 1 << 28; + /// 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 << 29; + /// The right to invoke `sock_shutdown`. + const SOCK_SHUTDOWN = 1 << 30; + } + } + + impl core::fmt::Display for Rights{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("Rights(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(())} + } + + /// A file descriptor handle. + pub type Fd = u32; + /// 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() + } + } + } + } + /// 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_wasmer::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 core::fmt::Display for Fdflags{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("Fdflags(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(())} + } + + /// 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()} + } + /// 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_wasmer::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 core::fmt::Display for Subclockflags{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("Subclockflags(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(())} + } + + /// 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 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("id", &self.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() + } + } + } + } + + /// Auxiliary data associated with the wasm exports. + #[derive(Default)] + pub struct WasiIoTypenamesData { + } + + pub struct WasiIoTypenames { + #[allow(dead_code)] + env: wasmer::FunctionEnv, + func_fd_dummy_func: wasmer::TypedFunction, + func_fdstat_dummy_func: wasmer::TypedFunction<(i32,i32,i32,i32,), ()>, + func_subscription_clock_dummy_func: wasmer::TypedFunction<(i32,i64,i64,i32,), ()>, + } + impl WasiIoTypenames { + #[allow(unused_variables)] + + /// Adds any intrinsics, if necessary for this exported wasm + /// functionality to the `ImportObject` provided. + /// + /// This function returns the `WasiIoTypenamesData` which needs to be + /// passed through to `WasiIoTypenames::new`. + fn add_to_imports( + mut store: impl wasmer::AsStoreMut, + imports: &mut wasmer::Imports, + ) -> wasmer::FunctionEnv { + let env = wasmer::FunctionEnv::new(&mut store, WasiIoTypenamesData::default()); + env + } + + /// Instantiates the provided `module` using the specified + /// parameters, wrapping up the result in a structure that + /// translates between wasm and the host. + /// + /// The `imports` provided will have intrinsics added to it + /// automatically, so it's not necessary to call + /// `add_to_imports` beforehand. This function will + /// instantiate the `module` otherwise using `imports`, and + /// both an instance of this structure and the underlying + /// `wasmer::Instance` will be returned. + pub fn instantiate( + mut store: impl wasmer::AsStoreMut, + module: &wasmer::Module, + imports: &mut wasmer::Imports, + ) -> anyhow::Result<(Self, wasmer::Instance)> { + let env = Self::add_to_imports(&mut store, imports); + let instance = wasmer::Instance::new( + &mut store, module, &*imports)?; + + Ok((Self::new(store, &instance, env)?, instance)) + } + + /// Low-level creation wrapper for wrapping up the exports + /// of the `instance` provided in this structure of wasm + /// exports. + /// + /// This function will extract exports from the `instance` + /// and wrap them all up in the returned structure which can + /// be used to interact with the wasm module. + pub fn new( + store: impl wasmer::AsStoreMut, + _instance: &wasmer::Instance, + env: wasmer::FunctionEnv, + ) -> Result { + let func_fd_dummy_func= _instance.exports.get_typed_function(&store, "fd-dummy-func")?; + let func_fdstat_dummy_func= _instance.exports.get_typed_function(&store, "fdstat-dummy-func")?; + let func_subscription_clock_dummy_func= _instance.exports.get_typed_function(&store, "subscription-clock-dummy-func")?; + Ok(WasiIoTypenames{ + func_fd_dummy_func, + func_fdstat_dummy_func, + func_subscription_clock_dummy_func, + env, + }) + } + /// Dummy function to expose type into generated code + pub fn subscription_clock_dummy_func(&self, store: &mut wasmer::Store,dummy: SubscriptionClock,)-> Result<(), wasmer::RuntimeError> { + let SubscriptionClock{ id:id0, timeout:timeout0, precision:precision0, flags:flags0, } = dummy; + let flags1 = flags0; + self.func_subscription_clock_dummy_func.call(store, id0 as i32, wit_bindgen_wasmer::rt::as_i64(timeout0), wit_bindgen_wasmer::rt::as_i64(precision0), (flags1.bits >> 0) as i32, )?; + Ok(()) + } + pub fn fd_dummy_func(&self, store: &mut wasmer::Store,dummy: Fd,)-> Result<(), wasmer::RuntimeError> { + self.func_fd_dummy_func.call(store, wit_bindgen_wasmer::rt::as_i32(dummy), )?; + Ok(()) + } + pub fn fdstat_dummy_func(&self, store: &mut wasmer::Store,dummy: Fdstat,)-> Result<(), wasmer::RuntimeError> { + let Fdstat{ fs_filetype:fs_filetype0, fs_flags:fs_flags0, fs_rights_base:fs_rights_base0, fs_rights_inheriting:fs_rights_inheriting0, } = dummy; + let flags1 = fs_flags0; + let flags2 = fs_rights_base0; + let flags3 = fs_rights_inheriting0; + self.func_fdstat_dummy_func.call(store, fs_filetype0 as i32, (flags1.bits >> 0) as i32, (flags2.bits >> 0) as i32, (flags3.bits >> 0) as i32, )?; + Ok(()) + } + } + #[allow(unused_imports)] + use wasmer::AsStoreMut as _; + #[allow(unused_imports)] + use wasmer::AsStoreRef as _; +} diff --git a/lib/wasi-types-generated/src/wasi_io_typenames/mod.rs b/lib/wasi-types-generated/src/wasi_io_typenames/mod.rs new file mode 100644 index 00000000000..74c90a099ca --- /dev/null +++ b/lib/wasi-types-generated/src/wasi_io_typenames/mod.rs @@ -0,0 +1,156 @@ +mod bindings; +pub use bindings::wasi_io_typenames::*; + +use std::mem::MaybeUninit; +use wasmer_types::ValueType; + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Eventtype { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// 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 Clockid { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +impl Eventtype { + pub fn to_str(self) -> &'static str { + match self { + Eventtype::Clock => "Wasi::Eventtype::Clock", + Eventtype::FdRead => "Wasi::Eventtype::FdRead", + Eventtype::FdWrite => "Wasi::Eventtype::FdWrite", + } + } +} + +/// 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 Eventtype { + fn from(other: super::wasi_snapshot0::Eventtype) -> Self { + match other { + super::wasi_snapshot0::Eventtype::Clock => Eventtype::Clock, + super::wasi_snapshot0::Eventtype::FdRead => Eventtype::FdRead, + super::wasi_snapshot0::Eventtype::FdWrite => Eventtype::FdWrite, + } + } +} + +/// 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 Clockid { + fn from(other: super::wasi_snapshot0::Clockid) -> Self { + match other { + super::wasi_snapshot0::Clockid::Realtime => Clockid::Realtime, + super::wasi_snapshot0::Clockid::Monotonic => Clockid::Monotonic, + // TODO: no idea what we should be doing here in the end + _ => panic!("unsupported clock wasi_snapshot0 clockid"), + } + } +} + +/// 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 Subclockflags { + fn from(other: super::wasi_snapshot0::Subclockflags) -> Self { + Subclockflags::from_bits_truncate(other.bits()) + } +} + +/// 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 Errno { + fn from(other: super::wasi_snapshot0::Errno) -> Self { + match other { + super::wasi_snapshot0::Errno::Success => Errno::Success, + super::wasi_snapshot0::Errno::Toobig => Errno::Toobig, + super::wasi_snapshot0::Errno::Acces => Errno::Access, + super::wasi_snapshot0::Errno::Addrinuse => Errno::Addrinuse, + super::wasi_snapshot0::Errno::Addrnotavail => Errno::Addrnotavail, + super::wasi_snapshot0::Errno::Afnosupport => Errno::Afnosupport, + super::wasi_snapshot0::Errno::Again => Errno::Again, + super::wasi_snapshot0::Errno::Already => Errno::Already, + super::wasi_snapshot0::Errno::Badf => Errno::Badf, + super::wasi_snapshot0::Errno::Badmsg => Errno::Badmsg, + super::wasi_snapshot0::Errno::Busy => Errno::Busy, + super::wasi_snapshot0::Errno::Canceled => Errno::Canceled, + super::wasi_snapshot0::Errno::Child => Errno::Child, + super::wasi_snapshot0::Errno::Connaborted => Errno::Connaborted, + super::wasi_snapshot0::Errno::Connrefused => Errno::Connrefused, + super::wasi_snapshot0::Errno::Connreset => Errno::Connreset, + super::wasi_snapshot0::Errno::Deadlk => Errno::Deadlk, + super::wasi_snapshot0::Errno::Destaddrreq => Errno::Destaddrreq, + super::wasi_snapshot0::Errno::Dom => Errno::Dom, + super::wasi_snapshot0::Errno::Dquot => Errno::Dquot, + super::wasi_snapshot0::Errno::Exist => Errno::Exist, + super::wasi_snapshot0::Errno::Fault => Errno::Fault, + super::wasi_snapshot0::Errno::Fbig => Errno::Fbig, + super::wasi_snapshot0::Errno::Hostunreach => Errno::Hostunreach, + super::wasi_snapshot0::Errno::Idrm => Errno::Idrm, + super::wasi_snapshot0::Errno::Ilseq => Errno::Ilseq, + super::wasi_snapshot0::Errno::Inprogress => Errno::Inprogress, + super::wasi_snapshot0::Errno::Intr => Errno::Intr, + super::wasi_snapshot0::Errno::Inval => Errno::Inval, + super::wasi_snapshot0::Errno::Io => Errno::Io, + super::wasi_snapshot0::Errno::Isconn => Errno::Isconn, + super::wasi_snapshot0::Errno::Isdir => Errno::Isdir, + super::wasi_snapshot0::Errno::Loop => Errno::Loop, + super::wasi_snapshot0::Errno::Mfile => Errno::Mfile, + super::wasi_snapshot0::Errno::Mlink => Errno::Mlink, + super::wasi_snapshot0::Errno::Msgsize => Errno::Msgsize, + super::wasi_snapshot0::Errno::Multihop => Errno::Multihop, + super::wasi_snapshot0::Errno::Nametoolong => Errno::Nametoolong, + super::wasi_snapshot0::Errno::Netdown => Errno::Netdown, + super::wasi_snapshot0::Errno::Netreset => Errno::Netreset, + super::wasi_snapshot0::Errno::Netunreach => Errno::Netunreach, + super::wasi_snapshot0::Errno::Nfile => Errno::Nfile, + super::wasi_snapshot0::Errno::Nobufs => Errno::Nobufs, + super::wasi_snapshot0::Errno::Nodev => Errno::Nodev, + super::wasi_snapshot0::Errno::Noent => Errno::Noent, + super::wasi_snapshot0::Errno::Noexec => Errno::Noexec, + super::wasi_snapshot0::Errno::Nolck => Errno::Nolck, + super::wasi_snapshot0::Errno::Nolink => Errno::Nolink, + super::wasi_snapshot0::Errno::Nomem => Errno::Nomem, + super::wasi_snapshot0::Errno::Nomsg => Errno::Nomsg, + super::wasi_snapshot0::Errno::Noprotoopt => Errno::Noprotoopt, + super::wasi_snapshot0::Errno::Nospc => Errno::Nospc, + super::wasi_snapshot0::Errno::Nosys => Errno::Nosys, + super::wasi_snapshot0::Errno::Notconn => Errno::Notconn, + super::wasi_snapshot0::Errno::Notdir => Errno::Notdir, + super::wasi_snapshot0::Errno::Notempty => Errno::Notempty, + super::wasi_snapshot0::Errno::Notrecoverable => Errno::Notrecoverable, + super::wasi_snapshot0::Errno::Notsock => Errno::Notsock, + super::wasi_snapshot0::Errno::Notsup => Errno::Notsup, + super::wasi_snapshot0::Errno::Notty => Errno::Notty, + super::wasi_snapshot0::Errno::Nxio => Errno::Nxio, + super::wasi_snapshot0::Errno::Overflow => Errno::Overflow, + super::wasi_snapshot0::Errno::Ownerdead => Errno::Ownerdead, + super::wasi_snapshot0::Errno::Perm => Errno::Perm, + super::wasi_snapshot0::Errno::Pipe => Errno::Pipe, + super::wasi_snapshot0::Errno::Proto => Errno::Proto, + super::wasi_snapshot0::Errno::Protonosupport => Errno::Protonosupport, + super::wasi_snapshot0::Errno::Prototype => Errno::Prototype, + super::wasi_snapshot0::Errno::Range => Errno::Range, + super::wasi_snapshot0::Errno::Rofs => Errno::Rofs, + super::wasi_snapshot0::Errno::Spipe => Errno::Spipe, + super::wasi_snapshot0::Errno::Srch => Errno::Srch, + super::wasi_snapshot0::Errno::Stale => Errno::Stale, + super::wasi_snapshot0::Errno::Timedout => Errno::Timedout, + super::wasi_snapshot0::Errno::Txtbsy => Errno::Txtbsy, + super::wasi_snapshot0::Errno::Xdev => Errno::Xdev, + super::wasi_snapshot0::Errno::Notcapable => Errno::Notcapable, + } + } +} diff --git a/lib/wasi-types-generated/src/bindings.rs b/lib/wasi-types-generated/src/wasi_snapshot0/bindings.rs similarity index 51% rename from lib/wasi-types-generated/src/bindings.rs rename to lib/wasi-types-generated/src/wasi_snapshot0/bindings.rs index 871c610e807..7853da525ce 100644 --- a/lib/wasi-types-generated/src/bindings.rs +++ b/lib/wasi-types-generated/src/wasi_snapshot0/bindings.rs @@ -2,6 +2,37 @@ pub mod wasi_snapshot0 { #[allow(unused_imports)] use wit_bindgen_wasmer::{anyhow, wasmer}; + /// 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() + } + } + } + } + /// Timestamp in nanoseconds. + pub type Timestamp = u64; /// Identifiers for clocks. #[repr(u8)] #[derive(Clone, Copy, PartialEq, Eq)] @@ -648,35 +679,9 @@ pub mod wasi_snapshot0 { 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()} } - /// 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::file-descriptor` has data - /// available for reading. This event always triggers for regular files. - FdRead, - /// File descriptor `subscription-fd-readwrite::file-descriptor` 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() - } - } - } - } + /// User-provided value that may be attached to objects that is retained when + /// extracted from the implementation. + pub type Userdata = u64; wit_bindgen_wasmer::bitflags::bitflags! { /// The state of the file descriptor subscribed to with /// `eventtype::fd_read` or `eventtype::fd_write`. @@ -717,6 +722,26 @@ pub mod wasi_snapshot0 { Ok(())} } + /// The contents of a `subscription` when type is `eventtype::clock`. + #[repr(C)] + #[derive(Copy, Clone)] + pub struct SubscriptionClock { + /// The user-defined unique identifier of the clock. + pub identifier: Userdata, + /// The clock against which to compare the timestamp. + pub 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("identifier", &self.identifier).field("id", &self.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)] @@ -745,6 +770,7 @@ pub mod wasi_snapshot0 { func_dirent_dummy_func: wasmer::TypedFunction<(i64,i64,i32,i32,), ()>, func_fd_dummy_func: wasmer::TypedFunction, func_fdstat_dummy_func: wasmer::TypedFunction<(i32,i32,i32,i32,i32,i32,), ()>, + func_subscription_clock_dummy_func: wasmer::TypedFunction<(i64,i32,i64,i64,i32,), ()>, } impl WasiSnapshot0 { #[allow(unused_variables)] @@ -799,850 +825,45 @@ pub mod wasi_snapshot0 { let func_dirent_dummy_func= _instance.exports.get_typed_function(&store, "dirent-dummy-func")?; let func_fd_dummy_func= _instance.exports.get_typed_function(&store, "fd-dummy-func")?; let func_fdstat_dummy_func= _instance.exports.get_typed_function(&store, "fdstat-dummy-func")?; + let func_subscription_clock_dummy_func= _instance.exports.get_typed_function(&store, "subscription-clock-dummy-func")?; Ok(WasiSnapshot0{ func_dirent_dummy_func, func_fd_dummy_func, func_fdstat_dummy_func, + func_subscription_clock_dummy_func, env, }) } - /// Dummy function to expose fd into generated code - pub fn fd_dummy_func(&self, store: &mut wasmer::Store,d: Fd,)-> Result<(), wasmer::RuntimeError> { - self.func_fd_dummy_func.call(store, wit_bindgen_wasmer::rt::as_i32(d), )?; + /// Dummy function to expose type into generated code + pub fn fd_dummy_func(&self, store: &mut wasmer::Store,dummy: Fd,)-> Result<(), wasmer::RuntimeError> { + self.func_fd_dummy_func.call(store, wit_bindgen_wasmer::rt::as_i32(dummy), )?; Ok(()) } - /// Dummy function to expose dirent into generated code - pub fn dirent_dummy_func(&self, store: &mut wasmer::Store,d: Dirent,)-> Result<(), wasmer::RuntimeError> { - let Dirent{ d_next:d_next0, d_ino:d_ino0, d_namlen:d_namlen0, d_type:d_type0, } = d; + /// Dummy function to expose type into generated code + pub fn dirent_dummy_func(&self, store: &mut wasmer::Store,dummy: Dirent,)-> Result<(), wasmer::RuntimeError> { + let Dirent{ d_next:d_next0, d_ino:d_ino0, d_namlen:d_namlen0, d_type:d_type0, } = dummy; self.func_dirent_dummy_func.call(store, wit_bindgen_wasmer::rt::as_i64(d_next0), wit_bindgen_wasmer::rt::as_i64(d_ino0), wit_bindgen_wasmer::rt::as_i32(d_namlen0), d_type0 as i32, )?; Ok(()) } - /// Dummy function to expose fdstat into generated code - pub fn fdstat_dummy_func(&self, store: &mut wasmer::Store,d: Fdstat,)-> Result<(), wasmer::RuntimeError> { - let Fdstat{ fs_filetype:fs_filetype0, fs_flags:fs_flags0, fs_rights_base:fs_rights_base0, fs_rights_inheriting:fs_rights_inheriting0, } = d; + /// Dummy function to expose type into generated code + pub fn fdstat_dummy_func(&self, store: &mut wasmer::Store,dummy: Fdstat,)-> Result<(), wasmer::RuntimeError> { + let Fdstat{ fs_filetype:fs_filetype0, fs_flags:fs_flags0, fs_rights_base:fs_rights_base0, fs_rights_inheriting:fs_rights_inheriting0, } = dummy; let flags1 = fs_flags0; let flags2 = fs_rights_base0; let flags3 = fs_rights_inheriting0; self.func_fdstat_dummy_func.call(store, fs_filetype0 as i32, (flags1.bits >> 0) as i32, (flags2.bits >> 0) as i32, (flags2.bits >> 32) as i32, (flags3.bits >> 0) as i32, (flags3.bits >> 32) as i32, )?; Ok(()) } - } - #[allow(unused_imports)] - use wasmer::AsStoreMut as _; - #[allow(unused_imports)] - use wasmer::AsStoreRef as _; -} -#[allow(clippy::all)] -pub mod wasi_filesystem { - #[allow(unused_imports)] - use wit_bindgen_wasmer::{anyhow, wasmer}; - /// The type of a filesystem object referenced by a descriptor. - /// - /// Note: This was called `filetype` in earlier versions of WASI. - #[repr(u8)] - #[derive(Clone, Copy, PartialEq, Eq)] - pub enum Type { - /// The type of the descriptor or file is unknown or is different from - /// any of the other types specified. - Unknown, - /// The descriptor refers to a block device inode. - BlockDevice, - /// The descriptor refers to a character device inode. - CharacterDevice, - /// The descriptor refers to a directory inode. - Directory, - /// The descriptor refers to a named pipe. - Fifo, - /// The file refers to a symbolic link inode. - SymbolicLink, - /// The descriptor refers to a regular file inode. - RegularFile, - /// The descriptor refers to a socket. - Socket, - } - impl core::fmt::Debug for Type { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - match self { - Type::Unknown => { - f.debug_tuple("Type::Unknown").finish() - } - Type::BlockDevice => { - f.debug_tuple("Type::BlockDevice").finish() - } - Type::CharacterDevice => { - f.debug_tuple("Type::CharacterDevice").finish() - } - Type::Directory => { - f.debug_tuple("Type::Directory").finish() - } - Type::Fifo => { - f.debug_tuple("Type::Fifo").finish() - } - Type::SymbolicLink => { - f.debug_tuple("Type::SymbolicLink").finish() - } - Type::RegularFile => { - f.debug_tuple("Type::RegularFile").finish() - } - Type::Socket => { - f.debug_tuple("Type::Socket").finish() - } - } - } - } - wit_bindgen_wasmer::bitflags::bitflags! { - /// Descriptor flags. - /// - /// Note: This was called `fd-flags` in earlier versions of WASI. - pub struct Flags: u8 {/// Read mode: Data can be read. - const READ = 1 << 0; - /// Write mode: Data can be written to. - const WRITE = 1 << 1; - /// Append mode: Data written to the file is always appended to the file's - /// end. - const APPEND = 1 << 2; - /// Write according to synchronized I/O data integrity completion. Only the - /// data stored in the file is synchronized. - const DSYNC = 1 << 3; - /// Non-blocking mode. - const NONBLOCK = 1 << 4; - /// Synchronized read I/O operations. - const RSYNC = 1 << 5; - /// 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 << 6; - } - } - - impl core::fmt::Display for Flags{ - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("Flags(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(())} - } - - wit_bindgen_wasmer::bitflags::bitflags! { - /// Flags determining the method of how paths are resolved. - pub struct AtFlags: u8 {/// As long as the resolved path corresponds to a symbolic link, it is expanded. - const SYMLINK_FOLLOW = 1 << 0; - } - } - - impl core::fmt::Display for AtFlags{ - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("AtFlags(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(())} - } - - wit_bindgen_wasmer::bitflags::bitflags! { - /// Open flags used by `open-at`. - 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 core::fmt::Display for OFlags{ - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("OFlags(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(())} - } - - wit_bindgen_wasmer::bitflags::bitflags! { - /// Permissions mode used by `open-at`, `change-permissions-at`, and similar. - pub struct Mode: u8 {/// True if the resource is considered readable by the containing - /// filesystem. - const READABLE = 1 << 0; - /// True if the resource is considered writeable by the containing - /// filesystem. - const WRITEABLE = 1 << 1; - /// True if the resource is considered executable by the containing - /// filesystem. This does not apply to directories. - const EXECUTABLE = 1 << 2; - } - } - - impl core::fmt::Display for Mode{ - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("Mode(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(())} - } - - /// 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. This is similar to `E2BIG` in POSIX. - 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 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, - } - 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::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", - } - } - pub fn message(&self) -> &'static str { - match self { - Errno::Success => "No error occurred. System call completed successfully.", - Errno::Toobig => "Argument list too long. This is similar to `E2BIG` in POSIX.", - 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::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.", - } - } - } - 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{} - /// 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() - } - } - } - } - /// A descriptor is a reference to a filesystem object, which may be a file, - /// directory, named pipe, special file, or other object on which filesystem - /// calls may be made. - #[derive(Debug)] - pub struct Descriptor(wit_bindgen_wasmer::rt::ResourceIndex); - - /// Auxiliary data associated with the wasm exports. - #[derive(Default)] - pub struct WasiFilesystemData { - - index_slab0: wit_bindgen_wasmer::rt::IndexSlab, - resource_slab0: wit_bindgen_wasmer::rt::ResourceSlab, - dtor0: OnceCell>, - } - - pub struct WasiFilesystem { - #[allow(dead_code)] - env: wasmer::FunctionEnv, - func_descriptor_fadvise: wasmer::TypedFunction<(i32,i64,i64,i32,), i32>, - memory: wasmer::Memory, - } - impl WasiFilesystem { - - /// Adds any intrinsics, if necessary for this exported wasm - /// functionality to the `ImportObject` provided. - /// - /// This function returns the `WasiFilesystemData` which needs to be - /// passed through to `WasiFilesystem::new`. - fn add_to_imports( - mut store: impl wasmer::AsStoreMut, - imports: &mut wasmer::Imports, - ) -> wasmer::FunctionEnv { - let env = wasmer::FunctionEnv::new(&mut store, WasiFilesystemData::default()); - let mut canonical_abi = imports.get_namespace_exports("canonical_abi").unwrap_or_else(wasmer::Exports::new); - - canonical_abi.insert( - "resource_drop_descriptor", - wasmer::Function::new_typed_with_env( - &mut store, - &env, - move |mut store: wasmer::FunctionEnvMut, idx: u32| -> Result<(), wasmer::RuntimeError> { - let resource_idx = store.data_mut().index_slab0.remove(idx)?; - let wasm = match store.data_mut().resource_slab0.drop(resource_idx) { - Some(wasm) => wasm, - None => return Ok(()), - }; - let dtor = store.data_mut().dtor0.get().unwrap().clone(); - dtor.call(&mut store, wasm)?; - Ok(()) - }, - ) - ); - canonical_abi.insert( - "resource_clone_descriptor", - wasmer::Function::new_typed_with_env( - &mut store, - &env, - move |mut store: wasmer::FunctionEnvMut, idx: u32| -> Result { - let state = &mut *store.data_mut(); - let resource_idx = state.index_slab0.get(idx)?; - state.resource_slab0.clone(resource_idx)?; - Ok(state.index_slab0.insert(resource_idx)) - }, - ) - ); - canonical_abi.insert( - "resource_get_descriptor", - wasmer::Function::new_typed_with_env( - &mut store, - &env, - move |mut store: wasmer::FunctionEnvMut, idx: u32| -> Result { - let state = &mut *store.data_mut(); - let resource_idx = state.index_slab0.get(idx)?; - Ok(state.resource_slab0.get(resource_idx)) - }, - ) - ); - canonical_abi.insert( - "resource_new_descriptor", - wasmer::Function::new_typed_with_env( - &mut store, - &env, - move |mut store: wasmer::FunctionEnvMut, val: i32| -> Result { - let state = &mut *store.data_mut(); - let resource_idx = state.resource_slab0.insert(val); - Ok(state.index_slab0.insert(resource_idx)) - }, - ) - ); - imports.register_namespace("canonical_abi", canonical_abi); - env - } - - /// Instantiates the provided `module` using the specified - /// parameters, wrapping up the result in a structure that - /// translates between wasm and the host. - /// - /// The `imports` provided will have intrinsics added to it - /// automatically, so it's not necessary to call - /// `add_to_imports` beforehand. This function will - /// instantiate the `module` otherwise using `imports`, and - /// both an instance of this structure and the underlying - /// `wasmer::Instance` will be returned. - pub fn instantiate( - mut store: impl wasmer::AsStoreMut, - module: &wasmer::Module, - imports: &mut wasmer::Imports, - ) -> anyhow::Result<(Self, wasmer::Instance)> { - let env = Self::add_to_imports(&mut store, imports); - let instance = wasmer::Instance::new( - &mut store, module, &*imports)?; - { - let dtor0 = instance - .exports - .get_typed_function( - &store, - "canonical_abi_drop_descriptor", - )? - .clone(); - - env - .as_mut(&mut store) - .dtor0 - .set(dtor0) - .map_err(|_e| anyhow::anyhow!("Couldn't set canonical_abi_drop_descriptor"))?; - } - - Ok((Self::new(store, &instance, env)?, instance)) - } - - /// Low-level creation wrapper for wrapping up the exports - /// of the `instance` provided in this structure of wasm - /// exports. - /// - /// This function will extract exports from the `instance` - /// and wrap them all up in the returned structure which can - /// be used to interact with the wasm module. - pub fn new( - store: impl wasmer::AsStoreMut, - _instance: &wasmer::Instance, - env: wasmer::FunctionEnv, - ) -> Result { - let func_descriptor_fadvise= _instance.exports.get_typed_function(&store, "descriptor::fadvise")?; - let memory= _instance.exports.get_memory("memory")?.clone(); - Ok(WasiFilesystem{ - func_descriptor_fadvise, - memory, - env, - }) - } - /// Provide file advisory information on a descriptor. - /// - /// This is similar to `posix_fadvise` in POSIX. - pub fn descriptor_fadvise(&self, store: &mut wasmer::Store,self_: & Descriptor,offset: u64,len: u64,advice: Advice,)-> Result, wasmer::RuntimeError> { - let _memory = &self.memory; - - let obj0 = self_; - let handle0 = { - let state = self.env.as_mut(store); - state.resource_slab0.clone(obj0.0)?; - state.index_slab0.insert(obj0.0) - }; - let result1 = self.func_descriptor_fadvise.call(store, handle0 as i32, wit_bindgen_wasmer::rt::as_i64(offset), wit_bindgen_wasmer::rt::as_i64(len), advice as i32, )?; - let _memory_view = _memory.view(&store); - let load2 = unsafe { _memory_view.data_unchecked_mut() }.load::(result1 + 0)?; - Ok(match i32::from(load2) { - 0 => Ok(()), - 1 => Err({ - let _memory_view = _memory.view(&store); - let load3 = unsafe { _memory_view.data_unchecked_mut() }.load::(result1 + 1)?; - match i32::from(load3) { - 0 => Errno::Success, - 1 => Errno::Toobig, - 2 => Errno::Access, - 3 => Errno::Addrinuse, - 4 => Errno::Addrnotavail, - 5 => Errno::Afnosupport, - 6 => Errno::Again, - 7 => Errno::Already, - 8 => Errno::Badmsg, - 9 => Errno::Busy, - 10 => Errno::Canceled, - 11 => Errno::Child, - 12 => Errno::Connaborted, - 13 => Errno::Connrefused, - 14 => Errno::Connreset, - 15 => Errno::Deadlk, - 16 => Errno::Destaddrreq, - 17 => Errno::Dom, - 18 => Errno::Dquot, - 19 => Errno::Exist, - 20 => Errno::Fault, - 21 => Errno::Fbig, - 22 => Errno::Hostunreach, - 23 => Errno::Idrm, - 24 => Errno::Ilseq, - 25 => Errno::Inprogress, - 26 => Errno::Intr, - 27 => Errno::Inval, - 28 => Errno::Io, - 29 => Errno::Isconn, - 30 => Errno::Isdir, - 31 => Errno::Loop, - 32 => Errno::Mfile, - 33 => Errno::Mlink, - 34 => Errno::Msgsize, - 35 => Errno::Multihop, - 36 => Errno::Nametoolong, - 37 => Errno::Netdown, - 38 => Errno::Netreset, - 39 => Errno::Netunreach, - 40 => Errno::Nfile, - 41 => Errno::Nobufs, - 42 => Errno::Nodev, - 43 => Errno::Noent, - 44 => Errno::Noexec, - 45 => Errno::Nolck, - 46 => Errno::Nolink, - 47 => Errno::Nomem, - 48 => Errno::Nomsg, - 49 => Errno::Noprotoopt, - 50 => Errno::Nospc, - 51 => Errno::Nosys, - 52 => Errno::Notconn, - 53 => Errno::Notdir, - 54 => Errno::Notempty, - 55 => Errno::Notrecoverable, - 56 => Errno::Notsock, - 57 => Errno::Notsup, - 58 => Errno::Notty, - 59 => Errno::Nxio, - 60 => Errno::Overflow, - 61 => Errno::Ownerdead, - 62 => Errno::Perm, - 63 => Errno::Pipe, - 64 => Errno::Proto, - 65 => Errno::Protonosupport, - 66 => Errno::Prototype, - 67 => Errno::Range, - 68 => Errno::Rofs, - 69 => Errno::Spipe, - 70 => Errno::Srch, - 71 => Errno::Stale, - 72 => Errno::Timedout, - 73 => Errno::Txtbsy, - 74 => Errno::Xdev, - _ => return Err(invalid_variant("Errno")), - } - }), - _ => return Err(invalid_variant("expected")), - }) - } - - /// Drops the host-owned handle to the resource - /// specified. - /// - /// Note that this may execute the WebAssembly-defined - /// destructor for this type. This also may not run - /// the destructor if there are still other references - /// to this type. - pub fn drop_descriptor( - &self, - store: &mut wasmer::Store, - val: Descriptor, - ) -> Result<(), wasmer::RuntimeError> { - let state = self.env.as_mut(store); - let wasm = match state.resource_slab0.drop(val.0) { - Some(val) => val, - None => return Ok(()), - }; - let dtor0 = state.dtor0.get().unwrap().clone(); - dtor0.call(store, wasm)?; + /// Dummy function to expose type into generated code + pub fn subscription_clock_dummy_func(&self, store: &mut wasmer::Store,dummy: SubscriptionClock,)-> Result<(), wasmer::RuntimeError> { + let SubscriptionClock{ identifier:identifier0, id:id0, timeout:timeout0, precision:precision0, flags:flags0, } = dummy; + let flags1 = flags0; + self.func_subscription_clock_dummy_func.call(store, wit_bindgen_wasmer::rt::as_i64(identifier0), id0 as i32, wit_bindgen_wasmer::rt::as_i64(timeout0), wit_bindgen_wasmer::rt::as_i64(precision0), (flags1.bits >> 0) as i32, )?; Ok(()) } } - use wit_bindgen_wasmer::once_cell::unsync::OnceCell; #[allow(unused_imports)] use wasmer::AsStoreMut as _; #[allow(unused_imports)] use wasmer::AsStoreRef as _; - use wit_bindgen_wasmer::rt::RawMem; - use wit_bindgen_wasmer::rt::invalid_variant; } diff --git a/lib/wasi-types-generated/src/wasi_snapshot0/mod.rs b/lib/wasi-types-generated/src/wasi_snapshot0/mod.rs new file mode 100644 index 00000000000..50e78557b1f --- /dev/null +++ b/lib/wasi-types-generated/src/wasi_snapshot0/mod.rs @@ -0,0 +1,494 @@ +mod bindings; +pub use bindings::wasi_snapshot0::*; + +use std::mem::MaybeUninit; +use wasmer_types::ValueType; + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Errno { + #[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]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Eventtype { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// 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 Eventrwflags { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// 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 Clockid { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// 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 Preopentype { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Fdstat { + 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)*) + std::mem::size_of_val(&self.$($f)*) + }; + } + macro_rules! zero { + ($start:expr, $end:expr) => { + for i in $start..$end { + bytes[i] = MaybeUninit::new(0); + } + }; + } + + self.fs_filetype + .zero_padding_bytes(&mut bytes[field!(fs_filetype)..field_end!(fs_filetype)]); + zero!(field_end!(fs_filetype), field!(fs_flags)); + + self.fs_flags + .zero_padding_bytes(&mut bytes[field!(fs_flags)..field_end!(fs_flags)]); + zero!(field_end!(fs_flags), field!(fs_rights_base)); + + self.fs_rights_base + .zero_padding_bytes(&mut bytes[field!(fs_rights_base)..field_end!(fs_rights_base)]); + zero!( + field_end!(fs_rights_inheriting), + std::mem::size_of_val(self) + ); + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for SubscriptionClock { + 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)*) + std::mem::size_of_val(&self.$($f)*) + }; + } + macro_rules! zero { + ($start:expr, $end:expr) => { + for i in $start..$end { + bytes[i] = MaybeUninit::new(0); + } + }; + } + + self.identifier + .zero_padding_bytes(&mut bytes[field!(identifier)..field_end!(identifier)]); + zero!(field_end!(identifier), field!(id)); + + self.id + .zero_padding_bytes(&mut bytes[field!(id)..field_end!(id)]); + zero!(field_end!(id), field!(timeout)); + + self.timeout + .zero_padding_bytes(&mut bytes[field!(timeout)..field_end!(timeout)]); + zero!(field_end!(timeout), field!(precision)); + + self.precision + .zero_padding_bytes(&mut bytes[field!(precision)..field_end!(precision)]); + zero!(field_end!(precision), field!(flags)); + + self.flags + .zero_padding_bytes(&mut bytes[field!(flags)..field_end!(flags)]); + zero!(field_end!(flags), std::mem::size_of_val(self)); + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::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::Acces, + 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, + // TODO: What should we map invalid native values to? + _ => Self::Inval, + } + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::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) + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Eventrwflags { + 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 u8) + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Subclockflags { + 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 u8) + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::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, + 2 => Self::ProcessCputimeId, + 3 => Self::ThreadCputimeId, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::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 u8) + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + +impl Eventtype { + pub fn to_str(self) -> &'static str { + match self { + Eventtype::Clock => "Wasi::Eventtype::Clock", + Eventtype::FdRead => "Wasi::Eventtype::FdRead", + Eventtype::FdWrite => "Wasi::Eventtype::FdWrite", + } + } +} + +/// 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 Eventtype { + fn from(other: super::wasi_io_typenames::Eventtype) -> Self { + match other { + super::wasi_io_typenames::Eventtype::Clock => Eventtype::Clock, + super::wasi_io_typenames::Eventtype::FdRead => Eventtype::FdRead, + super::wasi_io_typenames::Eventtype::FdWrite => Eventtype::FdWrite, + } + } +} + +/// 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 Errno { + fn from(other: super::wasi_io_typenames::Errno) -> Self { + match other { + super::wasi_io_typenames::Errno::Success => Errno::Success, + super::wasi_io_typenames::Errno::Toobig => Errno::Toobig, + super::wasi_io_typenames::Errno::Access => Errno::Acces, + super::wasi_io_typenames::Errno::Addrinuse => Errno::Addrinuse, + super::wasi_io_typenames::Errno::Addrnotavail => Errno::Addrnotavail, + super::wasi_io_typenames::Errno::Afnosupport => Errno::Afnosupport, + super::wasi_io_typenames::Errno::Again => Errno::Again, + super::wasi_io_typenames::Errno::Already => Errno::Already, + super::wasi_io_typenames::Errno::Badf => Errno::Badf, + super::wasi_io_typenames::Errno::Badmsg => Errno::Badmsg, + super::wasi_io_typenames::Errno::Busy => Errno::Busy, + super::wasi_io_typenames::Errno::Canceled => Errno::Canceled, + super::wasi_io_typenames::Errno::Child => Errno::Child, + super::wasi_io_typenames::Errno::Connaborted => Errno::Connaborted, + super::wasi_io_typenames::Errno::Connrefused => Errno::Connrefused, + super::wasi_io_typenames::Errno::Connreset => Errno::Connreset, + super::wasi_io_typenames::Errno::Deadlk => Errno::Deadlk, + super::wasi_io_typenames::Errno::Destaddrreq => Errno::Destaddrreq, + super::wasi_io_typenames::Errno::Dom => Errno::Dom, + super::wasi_io_typenames::Errno::Dquot => Errno::Dquot, + super::wasi_io_typenames::Errno::Exist => Errno::Exist, + super::wasi_io_typenames::Errno::Fault => Errno::Fault, + super::wasi_io_typenames::Errno::Fbig => Errno::Fbig, + super::wasi_io_typenames::Errno::Hostunreach => Errno::Hostunreach, + super::wasi_io_typenames::Errno::Idrm => Errno::Idrm, + super::wasi_io_typenames::Errno::Ilseq => Errno::Ilseq, + super::wasi_io_typenames::Errno::Inprogress => Errno::Inprogress, + super::wasi_io_typenames::Errno::Intr => Errno::Intr, + super::wasi_io_typenames::Errno::Inval => Errno::Inval, + super::wasi_io_typenames::Errno::Io => Errno::Io, + super::wasi_io_typenames::Errno::Isconn => Errno::Isconn, + super::wasi_io_typenames::Errno::Isdir => Errno::Isdir, + super::wasi_io_typenames::Errno::Loop => Errno::Loop, + super::wasi_io_typenames::Errno::Mfile => Errno::Mfile, + super::wasi_io_typenames::Errno::Mlink => Errno::Mlink, + super::wasi_io_typenames::Errno::Msgsize => Errno::Msgsize, + super::wasi_io_typenames::Errno::Multihop => Errno::Multihop, + super::wasi_io_typenames::Errno::Nametoolong => Errno::Nametoolong, + super::wasi_io_typenames::Errno::Netdown => Errno::Netdown, + super::wasi_io_typenames::Errno::Netreset => Errno::Netreset, + super::wasi_io_typenames::Errno::Netunreach => Errno::Netunreach, + super::wasi_io_typenames::Errno::Nfile => Errno::Nfile, + super::wasi_io_typenames::Errno::Nobufs => Errno::Nobufs, + super::wasi_io_typenames::Errno::Nodev => Errno::Nodev, + super::wasi_io_typenames::Errno::Noent => Errno::Noent, + super::wasi_io_typenames::Errno::Noexec => Errno::Noexec, + super::wasi_io_typenames::Errno::Nolck => Errno::Nolck, + super::wasi_io_typenames::Errno::Nolink => Errno::Nolink, + super::wasi_io_typenames::Errno::Nomem => Errno::Nomem, + super::wasi_io_typenames::Errno::Nomsg => Errno::Nomsg, + super::wasi_io_typenames::Errno::Noprotoopt => Errno::Noprotoopt, + super::wasi_io_typenames::Errno::Nospc => Errno::Nospc, + super::wasi_io_typenames::Errno::Nosys => Errno::Nosys, + super::wasi_io_typenames::Errno::Notconn => Errno::Notconn, + super::wasi_io_typenames::Errno::Notdir => Errno::Notdir, + super::wasi_io_typenames::Errno::Notempty => Errno::Notempty, + super::wasi_io_typenames::Errno::Notrecoverable => Errno::Notrecoverable, + super::wasi_io_typenames::Errno::Notsock => Errno::Notsock, + super::wasi_io_typenames::Errno::Notsup => Errno::Notsup, + super::wasi_io_typenames::Errno::Notty => Errno::Notty, + super::wasi_io_typenames::Errno::Nxio => Errno::Nxio, + super::wasi_io_typenames::Errno::Overflow => Errno::Overflow, + super::wasi_io_typenames::Errno::Ownerdead => Errno::Ownerdead, + super::wasi_io_typenames::Errno::Perm => Errno::Perm, + super::wasi_io_typenames::Errno::Pipe => Errno::Pipe, + super::wasi_io_typenames::Errno::Proto => Errno::Proto, + super::wasi_io_typenames::Errno::Protonosupport => Errno::Protonosupport, + super::wasi_io_typenames::Errno::Prototype => Errno::Prototype, + super::wasi_io_typenames::Errno::Range => Errno::Range, + super::wasi_io_typenames::Errno::Rofs => Errno::Rofs, + super::wasi_io_typenames::Errno::Spipe => Errno::Spipe, + super::wasi_io_typenames::Errno::Srch => Errno::Srch, + super::wasi_io_typenames::Errno::Stale => Errno::Stale, + super::wasi_io_typenames::Errno::Timedout => Errno::Timedout, + super::wasi_io_typenames::Errno::Txtbsy => Errno::Txtbsy, + super::wasi_io_typenames::Errno::Xdev => Errno::Xdev, + super::wasi_io_typenames::Errno::Notcapable => Errno::Notcapable, + } + } +} diff --git a/lib/wasi-types-generated/wit/wasi-io-typenames.wit b/lib/wasi-types-generated/wit/wasi-io-typenames.wit new file mode 100644 index 00000000000..720f97019cb --- /dev/null +++ b/lib/wasi-types-generated/wit/wasi-io-typenames.wit @@ -0,0 +1,719 @@ +// Extracted from https://github.com/WebAssembly/wasi-io/blob/main/standard/io/witx/typenames.witx + + +/// Dummy function to expose type into generated code +subscription-clock-dummy-func: func(dummy: subscription-clock) +fd-dummy-func: func(dummy: fd) +fdstat-dummy-func: func(dummy: fdstat) + +/// 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 + +/// Identifiers for clocks. +enum clockid { + // TODO: wit appears to not have support for enum type size + //(@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 type size + //(@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, +} + +/// File descriptor rights, determining which actions may be performed. +flags rights { + // TODO: wit appears to not have support for flags type size + //(@witx repr u64) + + /// The right to invoke `fd_datasync`. + /// + /// If `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 `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 `path_open` is set, the right to invoke `path_open` with `oflags::create`. + 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. + /// If `path_open` is set, includes the right to invoke `path_open` with `oflags::trunc`. + /// Note: there is no function named `path_filestat_set_size`. This follows POSIX design, + /// which only has `ftruncate` and does not provide `ftruncateat`. + /// While such function would be desirable from the API design perspective, there are virtually + /// no use cases for it since no code written for POSIX systems would use it. + /// Moreover, implementing it would require multiple syscalls, leading to inferior performance. + path-filestat-set-size, + /// The right to invoke `path_filestat_set_times`. + path-filestat-set-times, + /// The right to invoke `path_permissions_set`. + path-permissions-set, + /// 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 `fd_permissions_set`. + fd-permissions-set, + /// 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, +} + +/// A file descriptor handle. +// TODO: this is of type `handle` in the witx file +type fd = u32 + +// ;;; A region of memory for scatter/gather reads. +// (typename $iovec +// (record +// ;;; The address of the buffer to be filled. +// (field $buf (@witx pointer u8)) +// ;;; The length of the buffer to be filled. +// (field $buf_len $size) +// ) +// ) +// +// ;;; A region of memory for scatter/gather writes. +// (typename $ciovec +// (record +// ;;; The address of the buffer to be written. +// (field $buf (@witx const_pointer u8)) +// ;;; The length of the buffer to be written. +// (field $buf_len $size) +// ) +// ) +// +// (typename $iovec_array (list $iovec)) +// (typename $ciovec_array (list $ciovec)) +// +// ;;; Relative offset within a file. +// (typename $filedelta s64) +// +// ;;; The position relative to which to set the offset of the file descriptor. +// (typename $whence +// (enum (@witx tag u8) +// ;;; Seek relative to start-of-file. +// $set +// ;;; Seek relative to current position. +// $cur +// ;;; Seek relative to end-of-file. +// $end +// ) +// ) +// +// ;;; A reference to the offset of a directory entry. +// (typename $dircookie u64) +// +// ;;; In an `fd_readdir` call, this value signifies the start of the directory. +// (@witx const $dircookie $start 0) +// +// ;;; The type for the `dirent::d_namlen` field of `dirent`. +// (typename $dirnamlen u32) +// +// ;;; File serial number that is unique within its file system. +// (typename $inode u64) + +/// The type of a file descriptor or file. +enum filetype { + // TODO: wit appears to not have support for enum type size + //(@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. +// (typename $dirent +// (record +// ;;; The offset of the next directory entry stored in this directory. +// (field $d_next $dircookie) +// ;;; The serial number of the file referred to by this directory entry. +// (field $d_ino $inode) +// ;;; The type of the file referred to by this directory entry. +// (field $d_type $filetype) +// ;;; The length of the name of the directory entry. +// (field $d_namlen $dirnamlen) +// ) +// ) + +/// File or memory access pattern advisory information. +enum advice { + // TODO: wit appears to not have support for enum type size + //(@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 type size + //(@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, +} + +// ;;; 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. +// (typename $device u64) +// +// ;;; Which file time attributes to adjust. +// (typename $fstflags +// (flags (@witx repr u16) +// ;;; Adjust the last data access timestamp to the value stored in `filestat::atim`. +// $atim +// ;;; Adjust the last data access timestamp to the time of clock `clockid::realtime`. +// $atim_now +// ;;; Adjust the last data modification timestamp to the value stored in `filestat::mtim`. +// $mtim +// ;;; Adjust the last data modification timestamp to the time of clock `clockid::realtime`. +// $mtim_now +// ) +// ) +// +// ;;; Flags determining the method of how paths are resolved. +// (typename $lookupflags +// (flags (@witx repr u32) +// ;;; As long as the resolved path corresponds to a symbolic link, it is expanded. +// $symlink_follow +// ) +// ) +// +// ;;; Open flags used by `path_open`. +// (typename $oflags +// (flags (@witx repr u16) +// ;;; 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 +// ) +// ) +// +// ;;; Number of hard links to an inode. +// (typename $linkcount u64) +// +// ;;; File permissions. This represents the permissions associated with a +// ;;; file in a filesystem, and don't fully reflect all the conditions +// ;;; which determine whether a given WASI program can access the file. +// (typename $permissions +// (flags (@witx repr u8) +// ;;; For files, permission to read the file. +// ;;; For directories, permission to do `readdir` and access files +// ;;; within the directory. +// ;;; +// ;;; Note: This is similar to the read bit being set on files, and the +// ;;; read *and* execute bits being set on directories, in POSIX. +// $read +// +// ;;; For files, permission to mutate the file. +// ;;; For directories, permission to create, remove, and rename items +// ;;; within the directory. +// $write +// +// ;;; For files, permission to "execute" the file, using whatever +// ;;; concept of "executing" the host filesystem has. +// ;;; This flag is not valid for directories. +// $execute +// +// ;;; For filesystems which have a concept of multiple "users", this flag +// ;;; indicates that the file is only accessible by the effective "user" +// ;;; that the WASI store uses to access the filesystem, and inaccessible +// ;;; to other "users". +// $private +// ) +// ) +// +// ;;; File attributes. +// (typename $filestat +// (record +// ;;; Device ID of device containing the file. +// (field $dev $device) +// ;;; File serial number. +// (field $ino $inode) +// ;;; File type. +// (field $filetype $filetype) +// ;;; File permissions. +// (field $permissions $permissions) +// ;;; Number of hard links to the file. +// (field $nlink $linkcount) +// ;;; For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link. +// (field $size $filesize) +// ;;; Last data access timestamp. +// (field $atim $timestamp) +// ;;; Last data modification timestamp. +// (field $mtim $timestamp) +// ;;; Last file status change timestamp. +// (field $ctim $timestamp) +// ) +// ) +// +// ;;; User-provided value that may be attached to objects that is retained when +// ;;; extracted from the implementation. +// (typename $userdata u64) + +/// Type of a subscription to an event or its occurrence. +enum eventtype { + // TODO: wit appears to not have support for enum type size + //(@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, +} + +// ;;; The state of the file descriptor subscribed to with +// ;;; `eventtype::fd_read` or `eventtype::fd_write`. +// (typename $eventrwflags +// (flags (@witx repr u16) +// ;;; The peer of this socket has closed or disconnected. +// $fd_readwrite_hangup +// ) +// ) +// +// ;;; The contents of an `event` when type is `eventtype::fd_read` or +// ;;; `eventtype::fd_write`. +// (typename $event_fd_readwrite +// (record +// ;;; The number of bytes available for reading or writing. +// (field $nbytes $filesize) +// ;;; The state of the file descriptor. +// (field $flags $eventrwflags) +// ) +// ) +// +// ;;; The contents of an `event`. +// (typename $event_u +// (variant (@witx tag $eventtype) +// (case $fd_read $event_fd_readwrite) +// (case $fd_write $event_fd_readwrite) +// (case $clock) +// ) +// ) +// +// ;;; An event that occurred. +// (typename $event +// (record +// ;;; User-provided value that got attached to `subscription::userdata`. +// (field $userdata $userdata) +// ;;; If non-zero, an error that occurred while processing the subscription request. +// (field $error $errno) +// ;;; The type of the event that occurred, and the contents of the event +// (field $u $event_u) +// ) +// ) + +/// Flags determining how to interpret the timestamp provided in +/// `subscription_clock::timeout`. +flags subclockflags { + // TODO: wit appears to not have support for enum type size + //(@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 subscription-clock { + /// The clock against which to compare the timestamp. + 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, +} + +// ;;; The contents of a `subscription` when type is type is +// ;;; `eventtype::fd_read` or `eventtype::fd_write`. +// (typename $subscription_fd_readwrite +// (record +// ;;; The file descriptor on which to wait for it to become ready for reading or writing. +// (field $fd $fd) +// ) +// ) +// +// ;;; The contents of a `subscription`. +// (typename $subscription_u +// (union (@witx tag $eventtype) +// $subscription_clock +// $subscription_fd_readwrite +// $subscription_fd_readwrite +// ) +// ) +// +// ;;; Subscription to an event. +// (typename $subscription +// (record +// ;;; User-provided value that is attached to the subscription in the +// ;;; implementation and returned through `event::userdata`. +// (field $userdata $userdata) +// ;;; The type of the event to which to subscribe, and the contents of the subscription. +// (field $u $subscription_u) +// ) +// ) +// +// ;;; Exit code generated by a program when exiting. +// (typename $exitcode u8) +// +// ;;; Indicate the program exited successfully. +// ;;; +// ;;; Note: This is similar to `EXIT_SUCCESS` in POSIX. +// (@witx const $exitcode $success 0) +// +// ;;; Indicate the program exited unsuccessfully. +// ;;; +// ;;; Note: This is similar to `EXIT_FAILURE` in POSIX. +// (@witx const $exitcode $failure 1) +// +// ;;; Flags provided to `sock_recv`. +// (typename $riflags +// (flags (@witx repr u16) +// ;;; Returns the message without removing it from the socket's receive queue. +// $recv_peek +// ;;; On byte-stream sockets, block until the full amount of data can be returned. +// $recv_waitall +// ) +// ) +// +// ;;; Flags returned by `sock_recv`. +// (typename $roflags +// (flags (@witx repr u16) +// ;;; Returned by `sock_recv`: Message data has been truncated. +// $recv_data_truncated +// ) +// ) +// +// ;;; Flags provided to `sock_send`. As there are currently no flags +// ;;; defined, it must be set to zero. +// (typename $siflags u16) +// +// ;;; Which channels on a socket to shut down. +// (typename $sdflags +// (flags (@witx repr u8) +// ;;; Disables further receive operations. +// $rd +// ;;; Disables further send operations. +// $wr +// ) +// ) + +/// Identifiers for preopened capabilities. +enum preopentype { + // TODO: wit appears to not have support for enum type size + //(@witx tag u8) + + /// A pre-opened directory. + dir, +} + +// ;;; The contents of a `prestat` when its type is `preopentype::dir`. +// (typename $prestat_dir +// (record +// ;;; The length of the directory name for use with `fd_prestat_dir_name`. +// (field $pr_name_len $size) +// ) +// ) +// +// ;;; Information about a pre-opened capability. +// (typename $prestat +// (union (@witx tag $preopentype) +// ;;; When type is `preopentype::dir`: +// $prestat_dir +// ) +// ) diff --git a/lib/wasi-types-generated/wit/wasi-snapshot0.wit b/lib/wasi-types-generated/wit/wasi-snapshot0.wit index 606b3294d4b..f7c487bc500 100644 --- a/lib/wasi-types-generated/wit/wasi-snapshot0.wit +++ b/lib/wasi-types-generated/wit/wasi-snapshot0.wit @@ -1,13 +1,10 @@ // Extracted from https://github.com/WebAssembly/WASI/blob/main/phases/old/snapshot_0/witx/typenames.witx -type size = u32 +use { eventtype, size, timestamp } from wasi-io-typenames /// Non-negative file size or length of a region within a file. type filesize = u64 -/// Timestamp in nanoseconds. -type timestamp = u64 - /// Identifiers for clocks. enum clockid { // TODO: wit appears to not have support for enum type size @@ -297,8 +294,6 @@ flags rights { /// A file descriptor handle. type fd = u32 -/// Dummy function to expose fd into generated code -fd-dummy-func: func(d: fd) // ;;; A region of memory for scatter/gather reads. // (typename $iovec @@ -380,8 +375,6 @@ record dirent { /// The type of the file referred to by this directory entry. d-type: filetype, } -/// Dummy function to expose dirent into generated code -dirent-dummy-func: func(d: dirent) /// File or memory access pattern advisory information. enum advice { @@ -436,8 +429,6 @@ record fdstat { /// are created through this file descriptor, e.g., through `path_open`. fs-rights-inheriting: rights, } -/// Dummy function to expose fdstat into generated code -fdstat-dummy-func: func(d: fdstat) // ;;; 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. @@ -503,26 +494,10 @@ fdstat-dummy-func: func(d: fdstat) // (field $ctim $timestamp) // ) // ) -// -// ;;; User-provided value that may be attached to objects that is retained when -// ;;; extracted from the implementation. -// (typename $userdata u64) - -/// Type of a subscription to an event or its occurrence. -enum eventtype { - // TODO: wit appears to not have support for enum type size - //enum (@witx tag u8) - /// The time value of clock `subscription-clock::id` has - /// reached timestamp `subscription-clock::timeout`. - clock, - /// File descriptor `subscription-fd-readwrite::file-descriptor` has data - /// available for reading. This event always triggers for regular files. - fd-read, - /// File descriptor `subscription-fd-readwrite::file-descriptor` has capacity - /// available for writing. This event always triggers for regular files. - fd-write, -} +/// User-provided value that may be attached to objects that is retained when +/// extracted from the implementation. +type userdata = u64 /// The state of the file descriptor subscribed to with @@ -574,23 +549,21 @@ flags subclockflags { subscription-clock-abstime, } -// ;;; The contents of a `subscription` when type is `eventtype::clock`. -// (typename $subscription_clock -// (record -// ;;; The user-defined unique identifier of the clock. -// (field $identifier $userdata) -// ;;; The clock against which to compare the timestamp. -// (field $id $clockid) -// ;;; The absolute or relative timestamp. -// (field $timeout $timestamp) -// ;;; The amount of time that the implementation may wait additionally -// ;;; to coalesce with other events. -// (field $precision $timestamp) -// ;;; Flags specifying whether the timeout is absolute or relative -// (field $flags $subclockflags) -// ) -// ) -// +/// The contents of a `subscription` when type is `eventtype::clock`. +record subscription-clock { + /// The user-defined unique identifier of the clock. + identifier: userdata, + /// The clock against which to compare the timestamp. + 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 +} + // ;;; The contents of a `subscription` when the variant is // ;;; `eventtype::fd_read` or `eventtype::fd_write`. // (typename $subscription_fd_readwrite @@ -776,3 +749,12 @@ enum preopentype { // $prestat_dir // ) // ) + +/// Dummy function to expose type into generated code +fd-dummy-func: func(dummy: fd) +/// Dummy function to expose type into generated code +dirent-dummy-func: func(dummy: dirent) +/// Dummy function to expose type into generated code +fdstat-dummy-func: func(dummy: fdstat) +/// Dummy function to expose type into generated code +subscription-clock-dummy-func: func(dummy: subscription-clock) diff --git a/lib/wasi-types/src/event.rs b/lib/wasi-types/src/event.rs index fc7360e7ed0..5c12491605f 100644 --- a/lib/wasi-types/src/event.rs +++ b/lib/wasi-types/src/event.rs @@ -110,11 +110,3 @@ unsafe impl ValueType for __wasi_event_t { zero!(field_end!(u), mem::size_of_val(self)); } } - -pub fn eventtype_to_str(event_type: wasi_snapshot0::Eventtype) -> &'static str { - match event_type { - wasi_snapshot0::Eventtype::Clock => "Wasi::Eventtype::Clock", - wasi_snapshot0::Eventtype::FdRead => "Wasi::Eventtype::FdRead", - wasi_snapshot0::Eventtype::FdWrite => "Wasi::Eventtype::FdWrite", - } -} diff --git a/lib/wasi-types/src/subscription.rs b/lib/wasi-types/src/subscription.rs index 79612089eba..5c8303096a2 100644 --- a/lib/wasi-types/src/subscription.rs +++ b/lib/wasi-types/src/subscription.rs @@ -4,21 +4,21 @@ use std::fmt; use std::mem::{self, MaybeUninit}; use wasmer_derive::ValueType; use wasmer_types::ValueType; -use wasmer_wasi_types_generated::wasi_snapshot0; +use wasmer_wasi_types_generated::{wasi_io_typenames, wasi_snapshot0}; #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] #[repr(C)] pub struct __wasi_subscription_clock_t { - pub clock_id: wasi_snapshot0::Clockid, - pub timeout: __wasi_timestamp_t, - pub precision: __wasi_timestamp_t, - pub flags: wasi_snapshot0::Subclockflags, + pub clock_id: wasi_io_typenames::Clockid, + pub timeout: wasi_io_typenames::Timestamp, + pub precision: wasi_io_typenames::Timestamp, + pub flags: wasi_io_typenames::Subclockflags, } #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] #[repr(C)] pub struct __wasi_subscription_fs_readwrite_t { - pub fd: wasi_snapshot0::Fd, + pub fd: wasi_io_typenames::Fd, } #[derive(Copy, Clone)] @@ -32,10 +32,35 @@ pub union __wasi_subscription_u { #[repr(C)] pub struct __wasi_subscription_t { pub userdata: __wasi_userdata_t, - pub type_: wasi_snapshot0::Eventtype, + pub type_: wasi_io_typenames::Eventtype, pub u: __wasi_subscription_u, } +impl From for __wasi_subscription_t { + fn from(orig: super::snapshot0::__wasi_subscription_t) -> Self { + Self { + userdata: orig.userdata, + type_: wasi_io_typenames::Eventtype::from(orig.type_), + u: if orig.type_ == wasi_snapshot0::Eventtype::Clock { + __wasi_subscription_u { + clock: __wasi_subscription_clock_t { + clock_id: wasi_io_typenames::Clockid::from(unsafe { orig.u.clock.id }), + timeout: unsafe { orig.u.clock.timeout }, + precision: unsafe { orig.u.clock.precision }, + flags: wasi_io_typenames::Subclockflags::from(unsafe { + orig.u.clock.flags + }), + }, + } + } else { + __wasi_subscription_u { + fd_readwrite: unsafe { orig.u.fd_readwrite }, + } + }, + } + } +} + /// Safe Rust wrapper around `__wasi_subscription_t::type_` and `__wasi_subscription_t::u` #[derive(Debug, Clone)] pub enum EventType { @@ -45,11 +70,11 @@ pub enum EventType { } impl EventType { - pub fn raw_tag(&self) -> wasi_snapshot0::Eventtype { + pub fn raw_tag(&self) -> wasi_io_typenames::Eventtype { match self { - EventType::Clock(_) => wasi_snapshot0::Eventtype::Clock, - EventType::Read(_) => wasi_snapshot0::Eventtype::FdRead, - EventType::Write(_) => wasi_snapshot0::Eventtype::FdWrite, + EventType::Clock(_) => wasi_io_typenames::Eventtype::Clock, + EventType::Read(_) => wasi_io_typenames::Eventtype::FdRead, + EventType::Write(_) => wasi_io_typenames::Eventtype::FdWrite, } } } @@ -62,15 +87,17 @@ pub struct WasiSubscription { } impl TryFrom<__wasi_subscription_t> for WasiSubscription { - type Error = wasi_snapshot0::Errno; + type Error = wasi_io_typenames::Errno; fn try_from(ws: __wasi_subscription_t) -> Result { Ok(Self { user_data: ws.userdata, event_type: match ws.type_ { - wasi_snapshot0::Eventtype::Clock => EventType::Clock(unsafe { ws.u.clock }), - wasi_snapshot0::Eventtype::FdRead => EventType::Read(unsafe { ws.u.fd_readwrite }), - wasi_snapshot0::Eventtype::FdWrite => { + wasi_io_typenames::Eventtype::Clock => EventType::Clock(unsafe { ws.u.clock }), + wasi_io_typenames::Eventtype::FdRead => { + EventType::Read(unsafe { ws.u.fd_readwrite }) + } + wasi_io_typenames::Eventtype::FdWrite => { EventType::Write(unsafe { ws.u.fd_readwrite }) } }, @@ -79,24 +106,24 @@ impl TryFrom<__wasi_subscription_t> for WasiSubscription { } impl TryFrom for __wasi_subscription_t { - type Error = wasi_snapshot0::Errno; + type Error = wasi_io_typenames::Errno; fn try_from(ws: WasiSubscription) -> Result { #[allow(unreachable_patterns)] let (type_, u) = match ws.event_type { EventType::Clock(c) => ( - wasi_snapshot0::Eventtype::Clock, + wasi_io_typenames::Eventtype::Clock, __wasi_subscription_u { clock: c }, ), EventType::Read(rw) => ( - wasi_snapshot0::Eventtype::FdRead, + wasi_io_typenames::Eventtype::FdRead, __wasi_subscription_u { fd_readwrite: rw }, ), EventType::Write(rw) => ( - wasi_snapshot0::Eventtype::FdWrite, + wasi_io_typenames::Eventtype::FdWrite, __wasi_subscription_u { fd_readwrite: rw }, ), - _ => return Err(wasi_snapshot0::Errno::Inval), + _ => return Err(wasi_io_typenames::Errno::Inval), }; Ok(Self { @@ -111,14 +138,13 @@ 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("type", &self.type_.to_str()) .field( "u", match self.type_ { - wasi_snapshot0::Eventtype::Clock=> unsafe { &self.u.clock }, - wasi_snapshot0::Eventtype::FdRead | wasi_snapshot0::Eventtype::FdWrite => unsafe { - &self.u.fd_readwrite - }, + wasi_io_typenames::Eventtype::Clock => unsafe { &self.u.clock }, + wasi_io_typenames::Eventtype::FdRead + | wasi_io_typenames::Eventtype::FdWrite => unsafe { &self.u.fd_readwrite }, }, ) .finish() @@ -151,13 +177,13 @@ unsafe impl ValueType for __wasi_subscription_t { .zero_padding_bytes(&mut bytes[field!(type_)..field_end!(type_)]); zero!(field_end!(type_), field!(u)); match self.type_ { - wasi_snapshot0::Eventtype::FdRead | wasi_snapshot0::Eventtype::FdWrite => unsafe { + wasi_io_typenames::Eventtype::FdRead | wasi_io_typenames::Eventtype::FdWrite => 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_snapshot0::Eventtype::Clock => unsafe { + wasi_io_typenames::Eventtype::Clock => unsafe { self.u .clock .zero_padding_bytes(&mut bytes[field!(u.clock)..field_end!(u.clock)]); @@ -176,10 +202,10 @@ pub enum SubscriptionEnum { impl __wasi_subscription_t { pub fn tagged(&self) -> Option { match self.type_ { - wasi_snapshot0::Eventtype::Clock => { + wasi_io_typenames::Eventtype::Clock => { Some(SubscriptionEnum::Clock(unsafe { self.u.clock })) } - wasi_snapshot0::Eventtype::FdRead | wasi_snapshot0::Eventtype::FdWrite => { + wasi_io_typenames::Eventtype::FdRead | wasi_io_typenames::Eventtype::FdWrite => { Some(SubscriptionEnum::FdReadWrite(unsafe { self.u.fd_readwrite })) diff --git a/lib/wasi-types/src/versions/snapshot0.rs b/lib/wasi-types/src/versions/snapshot0.rs index 5b117ee7827..7b5c41c5f16 100644 --- a/lib/wasi-types/src/versions/snapshot0.rs +++ b/lib/wasi-types/src/versions/snapshot0.rs @@ -7,20 +7,10 @@ use wasmer_wasi_types_generated::wasi_snapshot0; 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_snapshot0::Clockid, - pub timeout: __wasi_timestamp_t, - pub precision: __wasi_timestamp_t, - pub flags: wasi_snapshot0::Subclockflags, -} - #[derive(Copy, Clone)] #[repr(C)] pub union __wasi_subscription_u { - pub clock: __wasi_subscription_clock_t, + pub clock: wasi_snapshot0::SubscriptionClock, pub fd_readwrite: __wasi_subscription_fs_readwrite_t, } @@ -132,7 +122,7 @@ 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("type", &self.type_.to_str()) .field( "u", match self.type_ { diff --git a/lib/wasi/src/macros.rs b/lib/wasi/src/macros.rs index 0c503e318cd..4e8db8d4c4e 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_snapshot0::Errno> = $expr; + let res: Result<_, crate::syscalls::types::wasi_io_typenames::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_snapshot0::Errno> = $expr; + let res: Result<_, crate::syscalls::types::wasi_io_typenames::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_snapshot0::Errno> = $expr; + let res: Result<_, crate::syscalls::types::wasi_io_typenames::Errno> = $expr; match res { Ok(val) => { tracing::trace!("wasi::wasi_try_ok::val: {:?}", val); val } Err(err) => { - if err == crate::syscalls::types::wasi_snapshot0::Errno::Intr { + if err == crate::syscalls::types::wasi_io_typenames::Errno::Intr { $thread.yield_now()?; } tracing::debug!("wasi::wasi_try_ok::err: {:?}", err); @@ -71,7 +71,7 @@ macro_rules! wasi_try_bus { }}; } -/// Like `wasi_try` but converts a `MemoryAccessError` to a wasi_snapshot0::Errno`. +/// Like `wasi_try` but converts a `MemoryAccessError` to a wasi_io_typenames::Errno`. macro_rules! wasi_try_mem { ($expr:expr) => {{ wasi_try!($expr.map_err($crate::mem_error_to_wasi)) @@ -85,7 +85,7 @@ macro_rules! wasi_try_mem_bus { }}; } -/// Like `wasi_try` but converts a `MemoryAccessError` to a wasi_snapshot0::Errno`. +/// Like `wasi_try` but converts a `MemoryAccessError` to a wasi_io_typenames::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/state/mod.rs b/lib/wasi/src/state/mod.rs index 6b3bda93f75..c6fbab7abb1 100644 --- a/lib/wasi/src/state/mod.rs +++ b/lib/wasi/src/state/mod.rs @@ -52,39 +52,41 @@ use std::{ }; use tracing::{debug, trace}; use wasmer_vbus::BusSpawnedProcess; -use wasmer_wasi_types_generated::wasi_snapshot0; +use wasmer_wasi_types_generated::wasi_io_typenames::{ + Errno, Fd as WasiFd, Fdflags, Filetype, Preopentype, Rights, +}; use wasmer_vfs::{FileSystem, FsError, OpenOptions, VirtualFile}; /// the fd value of the virtual root -pub const VIRTUAL_ROOT_FD: wasi_snapshot0::Fd = 3; +pub const VIRTUAL_ROOT_FD: WasiFd = 3; /// all the rights enabled -pub const ALL_RIGHTS: wasi_snapshot0::Rights = wasi_snapshot0::Rights::all(); -const STDIN_DEFAULT_RIGHTS: wasi_snapshot0::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 - wasi_snapshot0::Rights::from_bits_truncate( - wasi_snapshot0::Rights::FD_DATASYNC.bits() - | wasi_snapshot0::Rights::FD_READ.bits() - | wasi_snapshot0::Rights::FD_SYNC.bits() - | wasi_snapshot0::Rights::FD_ADVISE.bits() - | wasi_snapshot0::Rights::FD_FILESTAT_GET.bits() - | wasi_snapshot0::Rights::POLL_FD_READWRITE.bits(), + 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: wasi_snapshot0::Rights = { +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 - wasi_snapshot0::Rights::from_bits_truncate( - wasi_snapshot0::Rights::FD_DATASYNC.bits() - | wasi_snapshot0::Rights::FD_SYNC.bits() - | wasi_snapshot0::Rights::FD_WRITE.bits() - | wasi_snapshot0::Rights::FD_ADVISE.bits() - | wasi_snapshot0::Rights::FD_FILESTAT_GET.bits() - | wasi_snapshot0::Rights::POLL_FD_READWRITE.bits(), + 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: wasi_snapshot0::Rights = STDOUT_DEFAULT_RIGHTS; +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 @@ -162,7 +164,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_snapshot0::Fd, + 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 @@ -185,9 +187,9 @@ pub enum Kind { #[derive(Debug, Clone)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct Fd { - pub rights: wasi_snapshot0::Rights, - pub rights_inheriting: wasi_snapshot0::Rights, - pub flags: wasi_snapshot0::Fdflags, + pub rights: Rights, + pub rights_inheriting: Rights, + pub flags: Fdflags, pub offset: u64, /// Flags that determine how the [`Fd`] can be used. /// @@ -225,16 +227,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_snapshot0::Errno> { + 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_snapshot0::Errno::Badf) + self.orphan_fds.get(&inode).ok_or(Errno::Badf) } } @@ -242,13 +239,11 @@ impl WasiInodes { pub fn get_inodeval_mut( &mut self, inode: generational_arena::Index, - ) -> Result<&mut InodeVal, wasi_snapshot0::Errno> { + ) -> 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_snapshot0::Errno::Badf) + self.orphan_fds.get_mut(&inode).ok_or(Errno::Badf) } } @@ -302,7 +297,7 @@ impl WasiInodes { fn std_dev_get<'a>( &'a self, fd_map: &RwLock>, - fd: wasi_snapshot0::Fd, + fd: WasiFd, ) -> Result, FsError> { if let Some(fd) = fd_map.read().unwrap().get(&fd) { let guard = self.arena[fd.inode].read(); @@ -322,7 +317,7 @@ impl WasiInodes { fn std_dev_get_mut<'a>( &'a self, fd_map: &RwLock>, - fd: wasi_snapshot0::Fd, + fd: WasiFd, ) -> Result, FsError> { if let Some(fd) = fd_map.read().unwrap().get(&fd) { let guard = self.arena[fd.inode].write(); @@ -421,19 +416,19 @@ impl WasiFs { path: PathBuf::from(preopen_name), entries: Default::default(), }; - let rights = wasi_snapshot0::Rights::FD_ADVISE - | wasi_snapshot0::Rights::FD_TELL - | wasi_snapshot0::Rights::FD_SEEK - | wasi_snapshot0::Rights::FD_READ - | wasi_snapshot0::Rights::PATH_OPEN - | wasi_snapshot0::Rights::FD_READDIR - | wasi_snapshot0::Rights::PATH_READLINK - | wasi_snapshot0::Rights::PATH_FILESTAT_GET - | wasi_snapshot0::Rights::FD_FILESTAT_GET - | wasi_snapshot0::Rights::PATH_LINK_SOURCE - | wasi_snapshot0::Rights::PATH_RENAME_SOURCE - | wasi_snapshot0::Rights::POLL_FD_READWRITE - | wasi_snapshot0::Rights::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| { @@ -444,13 +439,7 @@ impl WasiFs { })?; let fd_flags = Fd::READ; let fd = wasi_fs - .create_fd( - rights, - rights, - wasi_snapshot0::Fdflags::empty(), - 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(); @@ -501,45 +490,43 @@ impl WasiFs { let rights = { // TODO: review tell' and fd_readwrite - let mut rights = wasi_snapshot0::Rights::FD_ADVISE - | wasi_snapshot0::Rights::FD_TELL - | wasi_snapshot0::Rights::FD_SEEK; + let mut rights = Rights::FD_ADVISE | Rights::FD_TELL | Rights::FD_SEEK; if *read { - rights |= wasi_snapshot0::Rights::FD_READ - | wasi_snapshot0::Rights::PATH_OPEN - | wasi_snapshot0::Rights::FD_READDIR - | wasi_snapshot0::Rights::PATH_READLINK - | wasi_snapshot0::Rights::PATH_FILESTAT_GET - | wasi_snapshot0::Rights::FD_FILESTAT_GET - | wasi_snapshot0::Rights::PATH_LINK_SOURCE - | wasi_snapshot0::Rights::PATH_RENAME_SOURCE - | wasi_snapshot0::Rights::POLL_FD_READWRITE - | wasi_snapshot0::Rights::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_snapshot0::Rights::FD_DATASYNC - | wasi_snapshot0::Rights::FD_FDSTAT_SET_FLAGS - | wasi_snapshot0::Rights::FD_WRITE - | wasi_snapshot0::Rights::FD_SYNC - | wasi_snapshot0::Rights::FD_ALLOCATE - | wasi_snapshot0::Rights::PATH_OPEN - | wasi_snapshot0::Rights::PATH_RENAME_TARGET - | wasi_snapshot0::Rights::PATH_FILESTAT_SET_SIZE - | wasi_snapshot0::Rights::PATH_FILESTAT_SET_TIMES - | wasi_snapshot0::Rights::FD_FILESTAT_SET_SIZE - | wasi_snapshot0::Rights::FD_FILESTAT_SET_TIMES - | wasi_snapshot0::Rights::PATH_REMOVE_DIRECTORY - | wasi_snapshot0::Rights::PATH_UNLINK_FILE - | wasi_snapshot0::Rights::POLL_FD_READWRITE - | wasi_snapshot0::Rights::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_snapshot0::Rights::PATH_CREATE_DIRECTORY - | wasi_snapshot0::Rights::PATH_CREATE_FILE - | wasi_snapshot0::Rights::PATH_LINK_TARGET - | wasi_snapshot0::Rights::PATH_OPEN - | wasi_snapshot0::Rights::PATH_RENAME_TARGET - | wasi_snapshot0::Rights::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 @@ -570,13 +557,7 @@ impl WasiFs { fd_flags }; let fd = wasi_fs - .create_fd( - rights, - rights, - wasi_snapshot0::Fdflags::empty(), - 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(); @@ -627,30 +608,24 @@ impl WasiFs { // root gets all right for now let root_rights = all_rights /* - & (!wasi_snapshot0::Rights::FD_WRITE) - & (!wasi_snapshot0::Rights::FD_ALLOCATE) - & (!wasi_snapshot0::Rights::PATH_CREATE_DIRECTORY) - & (!wasi_snapshot0::Rights::PATH_CREATE_FILE) - & (!wasi_snapshot0::Rights::PATH_LINK_SOURCE) - & (!wasi_snapshot0::Rights::PATH_RENAME_SOURCE) - & (!wasi_snapshot0::Rights::PATH_RENAME_TARGET) - & (!wasi_snapshot0::Rights::PATH_FILESTAT_SET_SIZE) - & (!wasi_snapshot0::Rights::PATH_FILESTAT_SET_TIMES) - & (!wasi_snapshot0::Rights::FD_FILESTAT_SET_SIZE) - & (!wasi_snapshot0::Rights::FD_FILESTAT_SET_TIMES) - & (!wasi_snapshot0::Rights::PATH_SYMLINK) - & (!wasi_snapshot0::Rights::PATH_UNLINK_FILE) - & (!wasi_snapshot0::Rights::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, - wasi_snapshot0::Fdflags::empty(), - 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 @@ -677,12 +652,12 @@ impl WasiFs { pub unsafe fn open_dir_all( &mut self, inodes: &mut WasiInodes, - base: wasi_snapshot0::Fd, + base: WasiFd, name: String, - rights: wasi_snapshot0::Rights, - rights_inheriting: wasi_snapshot0::Rights, - flags: wasi_snapshot0::Fdflags, - ) -> Result { + 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)?; @@ -752,14 +727,14 @@ impl WasiFs { pub fn open_file_at( &mut self, inodes: &mut WasiInodes, - base: wasi_snapshot0::Fd, + base: WasiFd, file: Box, open_flags: u16, name: String, - rights: wasi_snapshot0::Rights, - rights_inheriting: wasi_snapshot0::Rights, - flags: wasi_snapshot0::Fdflags, - ) -> Result { + 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)?; @@ -812,7 +787,7 @@ impl WasiFs { pub fn swap_file( &self, inodes: &WasiInodes, - fd: wasi_snapshot0::Fd, + fd: WasiFd, file: Box, ) -> Result>, FsError> { let mut ret = Some(file); @@ -849,8 +824,8 @@ impl WasiFs { pub(crate) fn filestat_resync_size( &self, inodes: &WasiInodes, - fd: wasi_snapshot0::Fd, - ) -> Result<__wasi_filesize_t, wasi_snapshot0::Errno> { + fd: WasiFd, + ) -> Result<__wasi_filesize_t, Errno> { let inode = self.get_fd_inode(fd)?; let mut guard = inodes.arena[inode].write(); let deref_mut = guard.deref_mut(); @@ -863,11 +838,11 @@ impl WasiFs { inodes.arena[inode].stat.write().unwrap().st_size = new_size; Ok(new_size as __wasi_filesize_t) } else { - Err(wasi_snapshot0::Errno::Badf) + Err(Errno::Badf) } } - Kind::Dir { .. } | Kind::Root { .. } => Err(wasi_snapshot0::Errno::Isdir), - _ => Err(wasi_snapshot0::Errno::Inval), + Kind::Dir { .. } | Kind::Root { .. } => Err(Errno::Isdir), + _ => Err(Errno::Inval), } } @@ -881,17 +856,17 @@ impl WasiFs { pub fn get_current_dir( &self, inodes: &mut WasiInodes, - base: wasi_snapshot0::Fd, - ) -> Result<(Inode, String), wasi_snapshot0::Errno> { + base: Fd, + ) -> 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_snapshot0::Fd, + base: WasiFd, symlink_count: u32, - ) -> Result<(Inode, String), wasi_snapshot0::Errno> { + ) -> Result<(Inode, String), Errno> { let current_dir = { let guard = self.current_dir.lock().unwrap(); guard.clone() @@ -927,9 +902,9 @@ impl WasiFs { path: &str, mut symlink_count: u32, follow_symlinks: bool, - ) -> Result { + ) -> Result { if symlink_count > MAX_SYMLINKS { - return Err(wasi_snapshot0::Errno::Mlink); + return Err(Errno::Mlink); } let path: &Path = Path::new(path); @@ -958,7 +933,7 @@ impl WasiFs { cur_inode = *p; continue 'path_iter; } else { - return Err(wasi_snapshot0::Errno::Acces); + return Err(Errno::Access); } } "." => continue 'path_iter, @@ -980,7 +955,7 @@ impl WasiFs { .fs_backing .symlink_metadata(&file) .ok() - .ok_or(wasi_snapshot0::Errno::Noent)?; + .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) @@ -1023,19 +998,17 @@ impl WasiFs { #[cfg(unix)] { //use std::os::unix::fs::FileTypeExt; - let file_type: wasi_snapshot0::Filetype = if file_type - .is_char_device() - { - wasi_snapshot0::Filetype::CharacterDevice + let file_type: Filetype = if file_type.is_char_device() { + Filetype::CharacterDevice } else if file_type.is_block_device() { - wasi_snapshot0::Filetype::BlockDevice + Filetype::BlockDevice } else if file_type.is_fifo() { // FIFO doesn't seem to fit any other type, so unknown - wasi_snapshot0::Filetype::Unknown + Filetype::Unknown } else if file_type.is_socket() { // TODO: how do we know if it's a `SocketStream` or // a `SocketDgram`? - wasi_snapshot0::Filetype::SocketStream + Filetype::SocketStream } else { unimplemented!("state::get_inode_at_path unknown file type: not file, directory, symlink, char device, block device, fifo, or socket"); }; @@ -1119,14 +1092,14 @@ impl WasiFs { { cur_inode = *entry; } else { - return Err(wasi_snapshot0::Errno::Noent); + return Err(Errno::Noent); } } Kind::File { .. } | Kind::Socket { .. } | Kind::Pipe { .. } | Kind::EventNotifications { .. } => { - return Err(wasi_snapshot0::Errno::Notdir); + return Err(Errno::Notdir); } Kind::Symlink { base_po_dir, @@ -1190,11 +1163,11 @@ impl WasiFs { &self, inodes: &WasiInodes, path: &'path Path, - ) -> Result<(wasi_snapshot0::Fd, &'path Path), wasi_snapshot0::Errno> { + ) -> Result<(Fd, &'path Path), Errno> { enum BaseFdAndRelPath<'a> { None, BestMatch { - fd: wasi_snapshot0::Fd, + fd: Fd, rel_path: &'a Path, max_seen: usize, }, @@ -1238,7 +1211,7 @@ impl WasiFs { } match res { // this error may not make sense depending on where it's called - BaseFdAndRelPath::None => Err(wasi_snapshot0::Errno::Inval), + BaseFdAndRelPath::None => Err(Errno::Inval), BaseFdAndRelPath::BestMatch { fd, rel_path, .. } => Ok((fd, rel_path)), } } @@ -1248,9 +1221,9 @@ impl WasiFs { pub(crate) fn path_depth_from_fd( &self, inodes: &WasiInodes, - fd: wasi_snapshot0::Fd, + fd: Fd, inode: Inode, - ) -> Result { + ) -> Result { let mut counter = 0; let base_inode = self.get_fd_inode(fd)?; let mut cur_inode = inode; @@ -1265,7 +1238,7 @@ impl WasiFs { cur_inode = *p; } } - _ => return Err(wasi_snapshot0::Errno::Inval), + _ => return Err(Errno::Inval), } } @@ -1281,10 +1254,10 @@ impl WasiFs { pub(crate) fn get_inode_at_path( &self, inodes: &mut WasiInodes, - base: wasi_snapshot0::Fd, + base: Fd, 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 @@ -1300,15 +1273,15 @@ impl WasiFs { pub(crate) fn get_parent_inode_at_path( &self, inodes: &mut WasiInodes, - base: wasi_snapshot0::Fd, + base: Fd, path: &Path, follow_symlinks: bool, - ) -> Result<(Inode, String), wasi_snapshot0::Errno> { + ) -> 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_snapshot0::Errno::Inval)? + .ok_or(Errno::Inval)? .as_os_str() .to_string_lossy() .to_string(); @@ -1319,70 +1292,59 @@ impl WasiFs { .map(|v| (v, new_entity_name)) } - pub fn get_fd(&self, fd: wasi_snapshot0::Fd) -> Result { + pub fn get_fd(&self, fd: WasiFd) -> Result { self.fd_map .read() .unwrap() .get(&fd) - .ok_or(wasi_snapshot0::Errno::Badf) + .ok_or(Errno::Badf) .map(|a| a.clone()) } - pub fn get_fd_inode( - &self, - fd: wasi_snapshot0::Fd, - ) -> Result { + pub fn get_fd_inode(&self, fd: WasiFd) -> Result { self.fd_map .read() .unwrap() .get(&fd) - .ok_or(wasi_snapshot0::Errno::Badf) + .ok_or(Errno::Badf) .map(|a| a.inode) } - pub fn filestat_fd( - &self, - inodes: &WasiInodes, - fd: wasi_snapshot0::Fd, - ) -> Result<__wasi_filestat_t, wasi_snapshot0::Errno> { + pub fn filestat_fd(&self, inodes: &WasiInodes, fd: WasiFd) -> Result<__wasi_filestat_t, Errno> { let inode = self.get_fd_inode(fd)?; Ok(*inodes.arena[inode].stat.read().unwrap().deref()) } - pub fn fdstat( - &self, - inodes: &WasiInodes, - fd: wasi_snapshot0::Fd, - ) -> Result { + pub fn fdstat(&self, inodes: &WasiInodes, fd: WasiFd) -> Result { match fd { __WASI_STDIN_FILENO => { - return Ok(wasi_snapshot0::Fdstat { - fs_filetype: wasi_snapshot0::Filetype::CharacterDevice, - fs_flags: wasi_snapshot0::Fdflags::empty(), + return Ok(Fdstat { + fs_filetype: Filetype::CharacterDevice, + fs_flags: Fdflags::empty(), fs_rights_base: STDIN_DEFAULT_RIGHTS, - fs_rights_inheriting: wasi_snapshot0::Rights::empty(), + fs_rights_inheriting: Rights::empty(), }) } __WASI_STDOUT_FILENO => { - return Ok(wasi_snapshot0::Fdstat { - fs_filetype: wasi_snapshot0::Filetype::CharacterDevice, - fs_flags: wasi_snapshot0::Fdflags::APPEND, + return Ok(Fdstat { + fs_filetype: Filetype::CharacterDevice, + fs_flags: Fdflags::APPEND, fs_rights_base: STDOUT_DEFAULT_RIGHTS, - fs_rights_inheriting: wasi_snapshot0::Rights::empty(), + fs_rights_inheriting: Rights::empty(), }) } __WASI_STDERR_FILENO => { - return Ok(wasi_snapshot0::Fdstat { - fs_filetype: wasi_snapshot0::Filetype::CharacterDevice, - fs_flags: wasi_snapshot0::Fdflags::APPEND, + return Ok(Fdstat { + fs_filetype: Filetype::CharacterDevice, + fs_flags: Fdflags::APPEND, fs_rights_base: STDERR_DEFAULT_RIGHTS, - fs_rights_inheriting: wasi_snapshot0::Rights::empty(), + fs_rights_inheriting: Rights::empty(), }) } VIRTUAL_ROOT_FD => { - return Ok(wasi_snapshot0::Fdstat { - fs_filetype: wasi_snapshot0::Filetype::Directory, - fs_flags: wasi_snapshot0::Fdflags::empty(), + return Ok(Fdstat { + fs_filetype: Filetype::Directory, + fs_flags: Fdflags::empty(), // TODO: fix this fs_rights_base: ALL_RIGHTS, fs_rights_inheriting: ALL_RIGHTS, @@ -1395,12 +1357,12 @@ impl WasiFs { let guard = inodes.arena[fd.inode].read(); let deref = guard.deref(); - Ok(wasi_snapshot0::Fdstat { + Ok(Fdstat { fs_filetype: match deref { - Kind::File { .. } => wasi_snapshot0::Filetype::RegularFile, - Kind::Dir { .. } => wasi_snapshot0::Filetype::Directory, - Kind::Symlink { .. } => wasi_snapshot0::Filetype::SymbolicLink, - _ => wasi_snapshot0::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, @@ -1408,11 +1370,7 @@ impl WasiFs { }) } - pub fn prestat_fd( - &self, - inodes: &WasiInodes, - fd: wasi_snapshot0::Fd, - ) -> Result<__wasi_prestat_t, wasi_snapshot0::Errno> { + pub fn prestat_fd(&self, inodes: &WasiInodes, fd: WasiFd) -> Result<__wasi_prestat_t, Errno> { let inode = self.get_fd_inode(fd)?; trace!("in prestat_fd {:?}", self.get_fd(fd)?); @@ -1421,13 +1379,13 @@ impl WasiFs { if inode_val.is_preopened { Ok(self.prestat_fd_inner(inode_val)) } else { - Err(wasi_snapshot0::Errno::Badf) + Err(Errno::Badf) } } pub(crate) fn prestat_fd_inner(&self, inode_val: &InodeVal) -> __wasi_prestat_t { __wasi_prestat_t { - pr_type: wasi_snapshot0::Preopentype::Dir, + pr_type: Preopentype::Dir, u: PrestatEnum::Dir { // REVIEW: pr_name_len: inode_val.name.len() as u32 + 1, @@ -1436,11 +1394,7 @@ impl WasiFs { } } - pub fn flush( - &self, - inodes: &WasiInodes, - fd: wasi_snapshot0::Fd, - ) -> Result<(), wasi_snapshot0::Errno> { + pub fn flush(&self, inodes: &WasiInodes, fd: Fd) -> Result<(), Errno> { match fd { __WASI_STDIN_FILENO => (), __WASI_STDOUT_FILENO => inodes @@ -1448,17 +1402,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_snapshot0::Errno::Io))?, + .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_snapshot0::Errno::Io)?, + .ok_or(Errno::Io)?, _ => { let fd = self.get_fd(fd)?; - if !fd.rights.contains(wasi_snapshot0::Rights::FD_DATASYNC) { - return Err(wasi_snapshot0::Errno::Acces); + if !fd.rights.contains(Rights::FD_DATASYNC) { + return Err(Errno::Acces); } let mut guard = inodes.arena[fd.inode].write(); @@ -1466,12 +1420,12 @@ impl WasiFs { match deref_mut { Kind::File { handle: Some(file), .. - } => file.flush().map_err(|_| wasi_snapshot0::Errno::Io)?, + } => file.flush().map_err(|_| Errno::Io)?, // TODO: verify this behavior - Kind::Dir { .. } => return Err(wasi_snapshot0::Errno::Isdir), + Kind::Dir { .. } => return Err(Errno::Isdir), Kind::Symlink { .. } => unimplemented!("WasiFs::flush Kind::Symlink"), Kind::Buffer { .. } => (), - _ => return Err(wasi_snapshot0::Errno::Io), + _ => return Err(Errno::Io), } } } @@ -1485,7 +1439,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)) } @@ -1523,12 +1477,12 @@ impl WasiFs { pub fn create_fd( &self, - rights: wasi_snapshot0::Rights, - rights_inheriting: wasi_snapshot0::Rights, - flags: wasi_snapshot0::Fdflags, + rights: Rights, + rights_inheriting: Rights, + flags: Fdflags, open_flags: u16, inode: Inode, - ) -> Result { + ) -> Result { let idx = self.next_fd.fetch_add(1, Ordering::AcqRel); self.fd_map.write().unwrap().insert( idx, @@ -1544,10 +1498,7 @@ impl WasiFs { Ok(idx) } - pub fn clone_fd( - &self, - fd: wasi_snapshot0::Fd, - ) -> Result { + pub fn clone_fd(&self, fd: Fd) -> Result { let fd = self.get_fd(fd)?; let idx = self.next_fd.fetch_add(1, Ordering::AcqRel); self.fd_map.write().unwrap().insert( @@ -1578,7 +1529,7 @@ impl WasiFs { fn create_virtual_root(&self, inodes: &mut WasiInodes) -> Inode { let stat = __wasi_filestat_t { - st_filetype: wasi_snapshot0::Filetype::Directory, + st_filetype: Filetype::Directory, st_ino: self.get_next_inode_index(), ..__wasi_filestat_t::default() }; @@ -1601,7 +1552,7 @@ impl WasiFs { "stdout", __WASI_STDOUT_FILENO, STDOUT_DEFAULT_RIGHTS, - wasi_snapshot0::Fdflags::APPEND, + Fdflags::APPEND, ); } fn create_stdin(&self, inodes: &mut WasiInodes) { @@ -1611,7 +1562,7 @@ impl WasiFs { "stdin", __WASI_STDIN_FILENO, STDIN_DEFAULT_RIGHTS, - wasi_snapshot0::Fdflags::empty(), + Fdflags::empty(), ); } fn create_stderr(&self, inodes: &mut WasiInodes) { @@ -1621,7 +1572,7 @@ impl WasiFs { "stderr", __WASI_STDERR_FILENO, STDERR_DEFAULT_RIGHTS, - wasi_snapshot0::Fdflags::APPEND, + Fdflags::APPEND, ); } @@ -1630,12 +1581,12 @@ impl WasiFs { inodes: &mut WasiInodes, handle: Box, name: &'static str, - raw_fd: wasi_snapshot0::Fd, - rights: wasi_snapshot0::Rights, - fd_flags: wasi_snapshot0::Fdflags, + raw_fd: Fd, + rights: Rights, + fd_flags: Fdflags, ) { let stat = __wasi_filestat_t { - st_filetype: wasi_snapshot0::Filetype::CharacterDevice, + st_filetype: Filetype::CharacterDevice, st_ino: self.get_next_inode_index(), ..__wasi_filestat_t::default() }; @@ -1656,7 +1607,7 @@ impl WasiFs { raw_fd, Fd { rights, - rights_inheriting: wasi_snapshot0::Rights::empty(), + rights_inheriting: Rights::empty(), flags: fd_flags, // since we're not calling open on this, we don't need open flags open_flags: 0, @@ -1670,12 +1621,12 @@ impl WasiFs { &self, inodes: &WasiInodes, kind: &Kind, - ) -> Result<__wasi_filestat_t, wasi_snapshot0::Errno> { + ) -> Result<__wasi_filestat_t, Errno> { let md = match kind { Kind::File { handle, path, .. } => match handle { Some(wf) => { return Ok(__wasi_filestat_t { - st_filetype: wasi_snapshot0::Filetype::RegularFile, + st_filetype: Filetype::RegularFile, st_size: wf.size(), st_atim: wf.last_accessed(), st_mtim: wf.last_modified(), @@ -1721,7 +1672,7 @@ impl WasiFs { _ => unreachable!("Symlink pointing to something that's not a directory as its base preopened directory"), } } - _ => return Err(wasi_snapshot0::Errno::Io), + _ => return Err(Errno::Io), }; Ok(__wasi_filestat_t { st_filetype: virtual_file_type_to_wasi_file_type(md.file_type()), @@ -1734,11 +1685,7 @@ impl WasiFs { } /// Closes an open FD, handling all details such as FD being preopen - pub(crate) fn close_fd( - &self, - inodes: &WasiInodes, - fd: wasi_snapshot0::Fd, - ) -> Result<(), wasi_snapshot0::Errno> { + pub(crate) fn close_fd(&self, inodes: &WasiInodes, fd: Fd) -> Result<(), Errno> { let inode = self.get_fd_inode(fd)?; let inodeval = inodes.get_inodeval(inode)?; let is_preopened = inodeval.is_preopened; @@ -1761,7 +1708,7 @@ impl WasiFs { debug!("Closing dir {:?}", &path); let key = path .file_name() - .ok_or(wasi_snapshot0::Errno::Inval)? + .ok_or(Errno::Inval)? .to_string_lossy() .to_string(); if let Some(p) = *parent { @@ -1799,12 +1746,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_snapshot0::Errno::Inval); + return Err(Errno::Inval); } } Kind::EventNotifications { .. } => {} - Kind::Root { .. } => return Err(wasi_snapshot0::Errno::Acces), - Kind::Symlink { .. } | Kind::Buffer { .. } => return Err(wasi_snapshot0::Errno::Inval), + Kind::Root { .. } => return Err(Errno::Acces), + Kind::Symlink { .. } | Kind::Buffer { .. } => return Err(Errno::Inval), } Ok(()) @@ -1816,27 +1763,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_snapshot0::Errno> { + 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_snapshot0::Errno> { + pub(crate) fn fs_remove_dir>(&self, path: P) -> Result<(), Errno> { self.fs .fs_backing .remove_dir(path.as_ref()) @@ -1847,17 +1788,14 @@ impl WasiState { &self, from: P, to: Q, - ) -> Result<(), wasi_snapshot0::Errno> { + ) -> 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_snapshot0::Errno> { + pub(crate) fn fs_remove_file>(&self, path: P) -> Result<(), Errno> { self.fs .fs_backing .remove_file(path.as_ref()) @@ -1993,7 +1931,7 @@ impl WasiState { /// Expects one of `__WASI_STDIN_FILENO`, `__WASI_STDOUT_FILENO`, `__WASI_STDERR_FILENO`. fn std_dev_get( &self, - fd: wasi_snapshot0::Fd, + fd: Fd, ) -> Result>, FsError> { let ret = WasiStateFileGuard::new(self, fd)?.map(|a| { let ret = Box::new(a); @@ -2004,17 +1942,15 @@ impl WasiState { } } -pub fn virtual_file_type_to_wasi_file_type( - file_type: wasmer_vfs::FileType, -) -> wasi_snapshot0::Filetype { +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_snapshot0::Filetype::Directory + Filetype::Directory } else if file_type.is_file() { - wasi_snapshot0::Filetype::RegularFile + Filetype::RegularFile } else if file_type.is_symlink() { - wasi_snapshot0::Filetype::SymbolicLink + Filetype::SymbolicLink } else { - wasi_snapshot0::Filetype::Unknown + Filetype::Unknown } } diff --git a/lib/wasi/src/state/types.rs b/lib/wasi/src/state/types.rs index 0b225605385..f6b8467afde 100644 --- a/lib/wasi/src/state/types.rs +++ b/lib/wasi/src/state/types.rs @@ -11,7 +11,7 @@ use std::{ time::Duration, }; use wasmer_vbus::BusError; -use wasmer_wasi_types_generated::wasi_snapshot0; +use wasmer_wasi_types_generated::wasi_io_typenames::Errno; #[cfg(feature = "host-fs")] pub use wasmer_vfs::host_fs::{Stderr, Stdin, Stdout}; @@ -21,85 +21,85 @@ 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_snapshot0::Errno) -> FsError { +pub fn fs_error_from_wasi_err(err: Errno) -> FsError { match err { - wasi_snapshot0::Errno::Badf => FsError::InvalidFd, - wasi_snapshot0::Errno::Exist => FsError::AlreadyExists, - wasi_snapshot0::Errno::Io => FsError::IOError, - wasi_snapshot0::Errno::Addrinuse => FsError::AddressInUse, - wasi_snapshot0::Errno::Addrnotavail => FsError::AddressNotAvailable, - wasi_snapshot0::Errno::Pipe => FsError::BrokenPipe, - wasi_snapshot0::Errno::Connaborted => FsError::ConnectionAborted, - wasi_snapshot0::Errno::Connrefused => FsError::ConnectionRefused, - wasi_snapshot0::Errno::Connreset => FsError::ConnectionReset, - wasi_snapshot0::Errno::Intr => FsError::Interrupted, - wasi_snapshot0::Errno::Inval => FsError::InvalidInput, - wasi_snapshot0::Errno::Notconn => FsError::NotConnected, - wasi_snapshot0::Errno::Nodev => FsError::NoDevice, - wasi_snapshot0::Errno::Noent => FsError::EntityNotFound, - wasi_snapshot0::Errno::Perm => FsError::PermissionDenied, - wasi_snapshot0::Errno::Timedout => FsError::TimedOut, - wasi_snapshot0::Errno::Proto => FsError::UnexpectedEof, - wasi_snapshot0::Errno::Again => FsError::WouldBlock, - wasi_snapshot0::Errno::Nospc => FsError::WriteZero, - wasi_snapshot0::Errno::Notempty => 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_snapshot0::Errno { +pub fn fs_error_into_wasi_err(fs_error: FsError) -> Errno { match fs_error { - FsError::AlreadyExists => wasi_snapshot0::Errno::Exist, - FsError::AddressInUse => wasi_snapshot0::Errno::Addrinuse, - FsError::AddressNotAvailable => wasi_snapshot0::Errno::Addrnotavail, - FsError::BaseNotDirectory => wasi_snapshot0::Errno::Notdir, - FsError::BrokenPipe => wasi_snapshot0::Errno::Pipe, - FsError::ConnectionAborted => wasi_snapshot0::Errno::Connaborted, - FsError::ConnectionRefused => wasi_snapshot0::Errno::Connrefused, - FsError::ConnectionReset => wasi_snapshot0::Errno::Connreset, - FsError::Interrupted => wasi_snapshot0::Errno::Intr, - FsError::InvalidData => wasi_snapshot0::Errno::Io, - FsError::InvalidFd => wasi_snapshot0::Errno::Badf, - FsError::InvalidInput => wasi_snapshot0::Errno::Inval, - FsError::IOError => wasi_snapshot0::Errno::Io, - FsError::NoDevice => wasi_snapshot0::Errno::Nodev, - FsError::NotAFile => wasi_snapshot0::Errno::Inval, - FsError::NotConnected => wasi_snapshot0::Errno::Notconn, - FsError::EntityNotFound => wasi_snapshot0::Errno::Noent, - FsError::PermissionDenied => wasi_snapshot0::Errno::Perm, - FsError::TimedOut => wasi_snapshot0::Errno::Timedout, - FsError::UnexpectedEof => wasi_snapshot0::Errno::Proto, - FsError::WouldBlock => wasi_snapshot0::Errno::Again, - FsError::WriteZero => wasi_snapshot0::Errno::Nospc, - FsError::DirectoryNotEmpty => wasi_snapshot0::Errno::Notempty, - FsError::Lock | FsError::UnknownError => wasi_snapshot0::Errno::Io, + 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_snapshot0::Errno { +pub fn net_error_into_wasi_err(net_error: NetworkError) -> Errno { match net_error { - NetworkError::InvalidFd => wasi_snapshot0::Errno::Badf, - NetworkError::AlreadyExists => wasi_snapshot0::Errno::Exist, - NetworkError::Lock => wasi_snapshot0::Errno::Io, - NetworkError::IOError => wasi_snapshot0::Errno::Io, - NetworkError::AddressInUse => wasi_snapshot0::Errno::Addrinuse, - NetworkError::AddressNotAvailable => wasi_snapshot0::Errno::Addrnotavail, - NetworkError::BrokenPipe => wasi_snapshot0::Errno::Pipe, - NetworkError::ConnectionAborted => wasi_snapshot0::Errno::Connaborted, - NetworkError::ConnectionRefused => wasi_snapshot0::Errno::Connrefused, - NetworkError::ConnectionReset => wasi_snapshot0::Errno::Connreset, - NetworkError::Interrupted => wasi_snapshot0::Errno::Intr, - NetworkError::InvalidData => wasi_snapshot0::Errno::Io, - NetworkError::InvalidInput => wasi_snapshot0::Errno::Inval, - NetworkError::NotConnected => wasi_snapshot0::Errno::Notconn, - NetworkError::NoDevice => wasi_snapshot0::Errno::Nodev, - NetworkError::PermissionDenied => wasi_snapshot0::Errno::Perm, - NetworkError::TimedOut => wasi_snapshot0::Errno::Timedout, - NetworkError::UnexpectedEof => wasi_snapshot0::Errno::Proto, - NetworkError::WouldBlock => wasi_snapshot0::Errno::Again, - NetworkError::WriteZero => wasi_snapshot0::Errno::Nospc, - NetworkError::Unsupported => wasi_snapshot0::Errno::Notsup, - NetworkError::UnknownError => wasi_snapshot0::Errno::Io, + 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, } } diff --git a/lib/wasi/src/syscalls/legacy/snapshot0.rs b/lib/wasi/src/syscalls/legacy/snapshot0.rs index 45f858781a6..a083a15fc62 100644 --- a/lib/wasi/src/syscalls/legacy/snapshot0.rs +++ b/lib/wasi/src/syscalls/legacy/snapshot0.rs @@ -1,5 +1,8 @@ use crate::syscalls; -use crate::syscalls::types::{self, snapshot0, wasi_snapshot0}; +use crate::syscalls::types::{ + self, snapshot0, + wasi_snapshot0::{self, Errno, Fd}, +}; use crate::{mem_error_to_wasi, Memory32, MemorySize, WasiEnv, WasiError, WasiThread}; use wasmer::{AsStoreMut, FunctionEnvMut, WasmPtr}; @@ -11,9 +14,9 @@ use wasmer::{AsStoreMut, FunctionEnvMut, WasmPtr}; /// that syscall, then it may break. pub fn fd_filestat_get( mut ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, buf: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -55,19 +58,19 @@ pub fn fd_filestat_get( // into memory leaving it as it should be wasi_try_mem!(buf.deref(&memory).write(old_stat)); - result + Errno::from(result) } /// Wrapper around `syscalls::path_filestat_get` with extra logic to handle the size /// difference of `wasi_filestat_t` pub fn path_filestat_get( mut ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, flags: types::__wasi_lookupflags_t, path: WasmPtr, path_len: u32, buf: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { // see `fd_filestat_get` in this file for an explanation of this strange behavior let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -103,11 +106,11 @@ pub fn path_filestat_get( /// of `__wasi_whence_t` pub fn fd_seek( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, offset: types::__wasi_filedelta_t, whence: snapshot0::__wasi_whence_t, newoffset: WasmPtr, -) -> Result { +) -> Result { let new_whence = match whence { snapshot0::__WASI_WHENCE_CUR => types::__WASI_WHENCE_CUR, snapshot0::__WASI_WHENCE_END => types::__WASI_WHENCE_END, @@ -126,7 +129,7 @@ pub fn poll_oneoff( out_: WasmPtr, nsubscriptions: u32, nevents: WasmPtr, -) -> Result { +) -> Result { // 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 @@ -145,24 +148,7 @@ pub fn poll_oneoff( .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_ == wasi_snapshot0::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(types::__wasi_subscription_t::from(*orig))); } // make the call diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 5b186a3a180..1b782a625eb 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -2,7 +2,10 @@ pub mod types { pub use wasmer_wasi_types::*; - pub use wasmer_wasi_types_generated::wasi_snapshot0; + pub use wasmer_wasi_types_generated::wasi_io_typenames::{ + Advice, Clockid, Errno, Fd, Fdflags, Fdstat, Rights, + }; + pub use wasmer_wasi_types_generated::{wasi_filesystem, wasi_io_typenames, wasi_snapshot0}; } #[cfg(any( @@ -30,8 +33,8 @@ 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, }; @@ -54,7 +57,6 @@ use wasmer::{ use wasmer_vbus::{FileDescriptor, StdioMode}; use wasmer_vfs::{FsError, VirtualFile}; use wasmer_vnet::{SocketHttpRequest, StreamSecurity}; -use wasmer_wasi_types_generated::wasi_snapshot0; #[cfg(any( target_os = "freebsd", @@ -70,17 +72,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_snapshot0::Errno::Inval)?; +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_snapshot0::Errno::Inval)?; +fn from_offset(offset: M::Offset) -> Result { + let ret: usize = offset.try_into().map_err(|_| Errno::Inval)?; Ok(ret) } @@ -88,7 +86,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)?; @@ -107,7 +105,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 @@ -117,7 +115,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 @@ -145,12 +143,12 @@ pub(crate) fn read_bytes( fn __sock_actor( ctx: &FunctionEnvMut<'_, WasiEnv>, - sock: wasi_snapshot0::Fd, - rights: wasi_snapshot0::Rights, + sock: Fd, + 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); @@ -158,7 +156,7 @@ where let fd_entry = state.fs.get_fd(sock)?; let ret = { if !rights.is_empty() && !fd_entry.rights.contains(rights) { - return Err(wasi_snapshot0::Errno::Acces); + return Err(Errno::Access); } let inode_idx = fd_entry.inode; @@ -169,7 +167,7 @@ where match deref { Kind::Socket { socket } => actor(socket)?, _ => { - return Err(wasi_snapshot0::Errno::Notsock); + return Err(Errno::Notsock); } } }; @@ -179,12 +177,12 @@ where fn __sock_actor_mut( ctx: &FunctionEnvMut<'_, WasiEnv>, - sock: wasi_snapshot0::Fd, - rights: wasi_snapshot0::Rights, + sock: Fd, + 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); @@ -192,7 +190,7 @@ where let fd_entry = state.fs.get_fd(sock)?; let ret = { if !rights.is_empty() && !fd_entry.rights.contains(rights) { - return Err(wasi_snapshot0::Errno::Acces); + return Err(Errno::Access); } let inode_idx = fd_entry.inode; @@ -203,7 +201,7 @@ where match deref_mut { Kind::Socket { socket } => actor(socket)?, _ => { - return Err(wasi_snapshot0::Errno::Notsock); + return Err(Errno::Notsock); } } }; @@ -213,21 +211,19 @@ where fn __sock_upgrade( ctx: &FunctionEnvMut<'_, WasiEnv>, - sock: wasi_snapshot0::Fd, - rights: wasi_snapshot0::Rights, + sock: Fd, + rights: Rights, actor: F, -) -> Result<(), wasi_snapshot0::Errno> +) -> Result<(), Errno> where - F: FnOnce( - &mut crate::state::InodeSocket, - ) -> Result, wasi_snapshot0::Errno>, + 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.is_empty() && !fd_entry.rights.contains(rights) { - return Err(wasi_snapshot0::Errno::Acces); + return Err(Errno::Access); } let inode_idx = fd_entry.inode; @@ -244,7 +240,7 @@ where } } _ => { - return Err(wasi_snapshot0::Errno::Notsock); + return Err(Errno::Notsock); } } @@ -257,7 +253,7 @@ fn write_buffer_array( from: &[Vec], ptr_buffer: WasmPtr, M>, buffer: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { let ptrs = wasi_try_mem!(ptr_buffer.slice(memory, wasi_try!(to_offset::(from.len())))); let mut current_buffer_offset = 0usize; @@ -279,14 +275,14 @@ fn write_buffer_array( current_buffer_offset += sub_buffer.len() + 1; } - wasi_snapshot0::Errno::Success + Errno::Success } -fn get_current_time_in_nanos() -> Result<__wasi_timestamp_t, wasi_snapshot0::Errno> { +fn get_current_time_in_nanos() -> Result<__wasi_timestamp_t, Errno> { let now = std::time::SystemTime::now(); let duration = now .duration_since(std::time::SystemTime::UNIX_EPOCH) - .map_err(|_| wasi_snapshot0::Errno::Io)?; + .map_err(|_| Errno::Io)?; Ok(duration.as_nanos() as __wasi_timestamp_t) } @@ -303,7 +299,7 @@ pub fn args_get( mut ctx: FunctionEnvMut<'_, WasiEnv>, argv: WasmPtr, M>, argv_buf: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!("wasi::args_get"); let env = ctx.data(); let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0); @@ -335,7 +331,7 @@ pub fn args_sizes_get( mut ctx: FunctionEnvMut<'_, WasiEnv>, argc: WasmPtr, argv_buf_size: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!("wasi::args_sizes_get"); let env = ctx.data(); let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0); @@ -343,36 +339,31 @@ 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_snapshot0::Errno::Overflow)); + 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_snapshot0::Errno::Overflow)); + let argv_buf_size_val: M::Offset = + 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_snapshot0::Errno::Success + Errno::Success } /// ### `clock_res_get()` /// Get the resolution of the specified clock /// Input: -/// - `wasi_snapshot0::Clockid clock_id` +/// - `Clockid clock_id` /// The ID of the clock to get the resolution of /// Output: /// - `__wasi_timestamp_t *resolution` /// The resolution of the clock in nanoseconds pub fn clock_res_get( mut ctx: FunctionEnvMut<'_, WasiEnv>, - clock_id: wasi_snapshot0::Clockid, + clock_id: Clockid, resolution: WasmPtr<__wasi_timestamp_t, M>, -) -> wasi_snapshot0::Errno { +) -> Errno { trace!("wasi::clock_res_get"); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -380,13 +371,13 @@ pub fn clock_res_get( 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_snapshot0::Errno::Success + Errno::Success } /// ### `clock_time_get()` /// Get the time of the specified clock /// Inputs: -/// - `wasi_snapshot0::Clockid clock_id` +/// - `Clockid clock_id` /// The ID of the clock to query /// - `__wasi_timestamp_t precision` /// The maximum amount of error the reading may have @@ -395,10 +386,10 @@ pub fn clock_res_get( /// The value of the clock in nanoseconds pub fn clock_time_get( ctx: FunctionEnvMut<'_, WasiEnv>, - clock_id: wasi_snapshot0::Clockid, + clock_id: Clockid, precision: __wasi_timestamp_t, time: WasmPtr<__wasi_timestamp_t, M>, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!( "wasi::clock_time_get clock_id: {}, precision: {}", clock_id as u8, precision @@ -409,7 +400,7 @@ pub fn clock_time_get( 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 result = wasi_snapshot0::Errno::Success; + let result = Errno::Success; trace!( "time: {} => {}", wasi_try_mem!(time.deref(&memory).read()), @@ -430,7 +421,7 @@ pub fn environ_get( ctx: FunctionEnvMut<'_, WasiEnv>, environ: WasmPtr, M>, environ_buf: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!( "wasi::environ_get. Environ: {:?}, environ_buf: {:?}", environ, environ_buf @@ -453,7 +444,7 @@ pub fn environ_sizes_get( ctx: FunctionEnvMut<'_, WasiEnv>, environ_count: WasmPtr, environ_buf_size: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { trace!("wasi::environ_sizes_get"); let env = ctx.data(); let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0); @@ -461,15 +452,10 @@ pub fn environ_sizes_get( let environ_count = environ_count.deref(&memory); 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_snapshot0::Errno::Overflow)); + let env_var_count: M::Offset = + 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_snapshot0::Errno::Overflow)); + 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)); @@ -479,13 +465,13 @@ pub fn environ_sizes_get( env_buf_size ); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `fd_advise()` /// Advise the system about how a file will be used /// Inputs: -/// - `wasi_snapshot0::Fd fd` +/// - `Fd fd` /// The file descriptor the advice applies to /// - `__wasi_filesize_t offset` /// The offset from which the advice applies @@ -495,22 +481,22 @@ pub fn environ_sizes_get( /// The advice to give pub fn fd_advise( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: wasi_snapshot0::Fd, + fd: Fd, offset: __wasi_filesize_t, len: __wasi_filesize_t, - advice: wasi_snapshot0::Advice, -) -> wasi_snapshot0::Errno { + 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_snapshot0::Errno::Success + Errno::Success } /// ### `fd_allocate` /// Allocate extra space for a file descriptor /// Inputs: -/// - `wasi_snapshot0::Fd fd` +/// - `Fd fd` /// The file descriptor to allocate for /// - `__wasi_filesize_t offset` /// The offset from the start marking the beginning of the allocation @@ -518,23 +504,20 @@ pub fn fd_advise( /// The length from the offset marking the end of the allocation pub fn fd_allocate( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: wasi_snapshot0::Fd, + fd: Fd, offset: __wasi_filesize_t, len: __wasi_filesize_t, -) -> wasi_snapshot0::Errno { +) -> 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 !fd_entry - .rights - .contains(wasi_snapshot0::Rights::FD_ALLOCATE) - { - return wasi_snapshot0::Errno::Acces; + if !fd_entry.rights.contains(Rights::FD_ALLOCATE) { + return Errno::Access; } - let new_size = wasi_try!(offset.checked_add(len).ok_or(wasi_snapshot0::Errno::Inval)); + 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(); @@ -543,36 +526,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_snapshot0::Errno::Badf; + return Errno::Badf; } } - Kind::Socket { .. } => return wasi_snapshot0::Errno::Badf, - Kind::Pipe { .. } => return wasi_snapshot0::Errno::Badf, + Kind::Socket { .. } => return Errno::Badf, + Kind::Pipe { .. } => return Errno::Badf, Kind::Buffer { buffer } => { buffer.resize(new_size as usize, 0); } - Kind::Symlink { .. } => return wasi_snapshot0::Errno::Badf, - Kind::EventNotifications { .. } => return wasi_snapshot0::Errno::Badf, - Kind::Dir { .. } | Kind::Root { .. } => return wasi_snapshot0::Errno::Isdir, + 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_snapshot0::Errno::Success + Errno::Success } /// ### `fd_close()` /// Close an open file descriptor /// Inputs: -/// - `wasi_snapshot0::Fd fd` +/// - `Fd fd` /// A file descriptor mapping to an open file to close /// Errors: -/// - `wasi_snapshot0::Errno::Isdir` +/// - `Errno::Isdir` /// If `fd` is a directory -/// - `wasi_snapshot0::Errno::Badf` +/// - `Errno::Badf` /// If `fd` is invalid or not open -pub fn fd_close(ctx: FunctionEnvMut<'_, WasiEnv>, fd: wasi_snapshot0::Fd) -> wasi_snapshot0::Errno { +pub fn fd_close(ctx: FunctionEnvMut<'_, WasiEnv>, fd: Fd) -> 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); @@ -581,49 +564,43 @@ pub fn fd_close(ctx: FunctionEnvMut<'_, WasiEnv>, fd: wasi_snapshot0::Fd) -> was wasi_try!(state.fs.close_fd(inodes.deref(), fd)); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `fd_datasync()` /// Synchronize the file data to disk /// Inputs: -/// - `wasi_snapshot0::Fd fd` +/// - `Fd fd` /// The file descriptor to sync -pub fn fd_datasync( - ctx: FunctionEnvMut<'_, WasiEnv>, - fd: wasi_snapshot0::Fd, -) -> wasi_snapshot0::Errno { +pub fn fd_datasync(ctx: FunctionEnvMut<'_, WasiEnv>, fd: Fd) -> 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 !fd_entry - .rights - .contains(wasi_snapshot0::Rights::FD_DATASYNC) - { - return wasi_snapshot0::Errno::Acces; + if !fd_entry.rights.contains(Rights::FD_DATASYNC) { + return Errno::Access; } if let Err(e) = state.fs.flush(inodes.deref(), fd) { e } else { - wasi_snapshot0::Errno::Success + Errno::Success } } /// ### `fd_fdstat_get()` /// Get metadata of a file descriptor /// Input: -/// - `wasi_snapshot0::Fd fd` +/// - `Fd fd` /// The file descriptor whose metadata will be accessed /// Output: -/// - `wasi_snapshot0::Fdstat *buf` +/// - `Fdstat *buf` /// The location where the metadata will be written pub fn fd_fdstat_get( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: wasi_snapshot0::Fd, - buf_ptr: WasmPtr, -) -> wasi_snapshot0::Errno { + fd: Fd, + buf_ptr: WasmPtr, +) -> Errno { debug!( "wasi::fd_fdstat_get: fd={}, buf_ptr={}", fd, @@ -637,94 +614,84 @@ pub fn fd_fdstat_get( wasi_try_mem!(buf.write(stat)); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `fd_fdstat_set_flags()` /// Set file descriptor flags for a file descriptor /// Inputs: -/// - `wasi_snapshot0::Fd fd` +/// - `Fd fd` /// The file descriptor to apply the new flags to -/// - `wasi_snapshot0::Fdflags flags` +/// - `Fdflags flags` /// The flags to apply to `fd` -pub fn fd_fdstat_set_flags( - ctx: FunctionEnvMut<'_, WasiEnv>, - fd: wasi_snapshot0::Fd, - flags: wasi_snapshot0::Fdflags, -) -> wasi_snapshot0::Errno { +pub fn fd_fdstat_set_flags(ctx: FunctionEnvMut<'_, WasiEnv>, fd: Fd, 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_snapshot0::Errno::Badf)); + let fd_entry = wasi_try!(fd_map.get_mut(&fd).ok_or(Errno::Badf)); - if !fd_entry - .rights - .contains(wasi_snapshot0::Rights::FD_FDSTAT_SET_FLAGS) - { - return wasi_snapshot0::Errno::Acces; + if !fd_entry.rights.contains(Rights::FD_FDSTAT_SET_FLAGS) { + return Errno::Access; } fd_entry.flags = flags; - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `fd_fdstat_set_rights()` /// Set the rights of a file descriptor. This can only be used to remove rights /// Inputs: -/// - `wasi_snapshot0::Fd fd` +/// - `Fd fd` /// The file descriptor to apply the new rights to -/// - `wasi_snapshot0::Rights fs_rights_base` +/// - `Rights fs_rights_base` /// The rights to apply to `fd` -/// - `wasi_snapshot0::Rights 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_snapshot0::Fd, - fs_rights_base: wasi_snapshot0::Rights, - fs_rights_inheriting: wasi_snapshot0::Rights, -) -> wasi_snapshot0::Errno { + fd: Fd, + 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_snapshot0::Errno::Badf)); + 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_snapshot0::Errno::Notcapable; + return Errno::Notcapable; } fd_entry.rights = fs_rights_base; fd_entry.rights_inheriting = fs_rights_inheriting; - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `fd_filestat_get()` /// Get the metadata of an open file /// Input: -/// - `wasi_snapshot0::Fd fd` +/// - `Fd fd` /// The open file descriptor whose metadata will be read /// Output: /// - `__wasi_filestat_t *buf` /// Where the metadata from `fd` will be written pub fn fd_filestat_get( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: wasi_snapshot0::Fd, + fd: Fd, buf: WasmPtr<__wasi_filestat_t, M>, -) -> wasi_snapshot0::Errno { +) -> 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 !fd_entry - .rights - .contains(wasi_snapshot0::Rights::FD_FILESTAT_GET) - { - return wasi_snapshot0::Errno::Acces; + if !fd_entry.rights.contains(Rights::FD_FILESTAT_GET) { + return Errno::Access; } let stat = wasi_try!(state.fs.filestat_fd(inodes.deref(), fd)); @@ -732,32 +699,29 @@ pub fn fd_filestat_get( let buf = buf.deref(&memory); wasi_try_mem!(buf.write(stat)); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `fd_filestat_set_size()` /// Change the size of an open file, zeroing out any new bytes /// Inputs: -/// - `wasi_snapshot0::Fd fd` +/// - `Fd fd` /// File descriptor to adjust /// - `__wasi_filesize_t st_size` /// New size that `fd` will be set to pub fn fd_filestat_set_size( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: wasi_snapshot0::Fd, + fd: Fd, st_size: __wasi_filesize_t, -) -> wasi_snapshot0::Errno { +) -> 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 !fd_entry - .rights - .contains(wasi_snapshot0::Rights::FD_FILESTAT_SET_SIZE) - { - return wasi_snapshot0::Errno::Acces; + if !fd_entry.rights.contains(Rights::FD_FILESTAT_SET_SIZE) { + return Errno::Access; } { @@ -768,22 +732,22 @@ 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_snapshot0::Errno::Badf; + return Errno::Badf; } } Kind::Buffer { buffer } => { buffer.resize(st_size as usize, 0); } - Kind::Socket { .. } => return wasi_snapshot0::Errno::Badf, - Kind::Pipe { .. } => return wasi_snapshot0::Errno::Badf, - Kind::Symlink { .. } => return wasi_snapshot0::Errno::Badf, - Kind::EventNotifications { .. } => return wasi_snapshot0::Errno::Badf, - Kind::Dir { .. } | Kind::Root { .. } => return wasi_snapshot0::Errno::Isdir, + 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_snapshot0::Errno::Success + Errno::Success } /// ### `fd_filestat_set_times()` @@ -797,28 +761,25 @@ pub fn fd_filestat_set_size( /// Bit-vector for controlling which times get set pub fn fd_filestat_set_times( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: wasi_snapshot0::Fd, + fd: Fd, st_atim: __wasi_timestamp_t, st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, -) -> wasi_snapshot0::Errno { +) -> 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 !fd_entry - .rights - .contains(wasi_snapshot0::Rights::FD_FILESTAT_SET_TIMES) - { - return wasi_snapshot0::Errno::Acces; + 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) { - return wasi_snapshot0::Errno::Inval; + return Errno::Inval; } let inode_idx = fd_entry.inode; @@ -842,14 +803,14 @@ pub fn fd_filestat_set_times( inode.stat.write().unwrap().st_mtim = time_to_set; } - wasi_snapshot0::Errno::Success + 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_snapshot0::Fd fd` +/// - `Fd fd` /// The file descriptor to read the data with /// - `const __wasi_iovec_t* iovs' /// Vectors where the data will be stored @@ -862,12 +823,12 @@ pub fn fd_filestat_set_times( /// The number of bytes read pub fn fd_pread( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: wasi_snapshot0::Fd, + fd: Fd, iovs: WasmPtr<__wasi_iovec_t, M>, iovs_len: M::Offset, offset: __wasi_filesize_t, nread: WasmPtr, -) -> Result { +) -> 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); @@ -887,23 +848,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_snapshot0::Errno::Badf); + return Ok(Errno::Badf); } } - __WASI_STDOUT_FILENO => return Ok(wasi_snapshot0::Errno::Inval), - __WASI_STDERR_FILENO => return Ok(wasi_snapshot0::Errno::Inval), + __WASI_STDOUT_FILENO => return Ok(Errno::Inval), + __WASI_STDERR_FILENO => return Ok(Errno::Inval), _ => { let inode = fd_entry.inode; - if !fd_entry - .rights - .contains(wasi_snapshot0::Rights::FD_READ | wasi_snapshot0::Rights::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_snapshot0::Errno::Acces); + return Ok(Errno::Access); } let mut guard = inodes.arena[inode].write(); let deref_mut = guard.deref_mut(); @@ -917,7 +875,7 @@ pub fn fd_pread( ); wasi_try_ok!(read_bytes(h, &memory, iovs), env) } else { - return Ok(wasi_snapshot0::Errno::Inval); + return Ok(Errno::Inval); } } Kind::Socket { socket } => { @@ -926,8 +884,8 @@ pub fn fd_pread( Kind::Pipe { pipe } => { wasi_try_ok!(pipe.recv(&memory, iovs), env) } - Kind::EventNotifications { .. } => return Ok(wasi_snapshot0::Errno::Inval), - Kind::Dir { .. } | Kind::Root { .. } => return Ok(wasi_snapshot0::Errno::Isdir), + 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) @@ -936,27 +894,25 @@ pub fn fd_pread( } }; - let bytes_read: M::Offset = wasi_try_ok!(bytes_read - .try_into() - .map_err(|_| wasi_snapshot0::Errno::Overflow)); + 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_snapshot0::Errno::Success) + Ok(Errno::Success) } /// ### `fd_prestat_get()` /// Get metadata about a preopened file descriptor /// Input: -/// - `wasi_snapshot0::Fd 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_snapshot0::Fd, + fd: Fd, buf: WasmPtr<__wasi_prestat_t, M>, -) -> wasi_snapshot0::Errno { +) -> 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); @@ -971,15 +927,15 @@ pub fn fd_prestat_get( ))) ); - wasi_snapshot0::Errno::Success + Errno::Success } pub fn fd_prestat_dir_name( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: wasi_snapshot0::Fd, + fd: Fd, path: WasmPtr, path_len: M::Offset, -) -> wasi_snapshot0::Errno { +) -> Errno { trace!( "wasi::fd_prestat_dir_name: fd={}, path_len={}", fd, @@ -1009,9 +965,9 @@ pub fn fd_prestat_dir_name( trace!("=> result: \"{}\"", inode_val.name); - wasi_snapshot0::Errno::Success + Errno::Success } else { - wasi_snapshot0::Errno::Overflow + Errno::Overflow } } Kind::Symlink { .. } @@ -1019,14 +975,14 @@ pub fn fd_prestat_dir_name( | Kind::File { .. } | Kind::Socket { .. } | Kind::Pipe { .. } - | Kind::EventNotifications { .. } => wasi_snapshot0::Errno::Notdir, + | Kind::EventNotifications { .. } => Errno::Notdir, } } /// ### `fd_pwrite()` /// Write to a file without adjusting its offset /// Inputs: -/// - `wasi_snapshot0::Fd` +/// - `Fd` /// File descriptor (opened with writing) to write to /// - `const __wasi_ciovec_t *iovs` /// List of vectors to read data from @@ -1039,12 +995,12 @@ pub fn fd_prestat_dir_name( /// Number of bytes written pub fn fd_pwrite( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: wasi_snapshot0::Fd, + fd: Fd, iovs: WasmPtr<__wasi_ciovec_t, M>, iovs_len: M::Offset, offset: __wasi_filesize_t, nwritten: WasmPtr, -) -> Result { +) -> Result { trace!("wasi::fd_pwrite"); // TODO: refactor, this is just copied from `fd_write`... let env = ctx.data(); @@ -1054,7 +1010,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_snapshot0::Errno::Inval), + __WASI_STDIN_FILENO => return Ok(Errno::Inval), __WASI_STDOUT_FILENO => { let mut guard = wasi_try_ok!( inodes @@ -1065,7 +1021,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_snapshot0::Errno::Badf); + return Ok(Errno::Badf); } } __WASI_STDERR_FILENO => { @@ -1078,15 +1034,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_snapshot0::Errno::Badf); + return Ok(Errno::Badf); } } _ => { - if !fd_entry - .rights - .contains(wasi_snapshot0::Rights::FD_WRITE | wasi_snapshot0::Rights::FD_SEEK) - { - return Ok(wasi_snapshot0::Errno::Acces); + if !fd_entry.rights.contains(Rights::FD_WRITE | Rights::FD_SEEK) { + return Ok(Errno::Access); } let inode_idx = fd_entry.inode; @@ -1105,7 +1058,7 @@ pub fn fd_pwrite( ); wasi_try_ok!(write_bytes(handle, &memory, iovs_arr), env) } else { - return Ok(wasi_snapshot0::Errno::Inval); + return Ok(Errno::Inval); } } Kind::Socket { socket } => { @@ -1116,9 +1069,9 @@ pub fn fd_pwrite( } Kind::Dir { .. } | Kind::Root { .. } => { // TODO: verify - return Ok(wasi_snapshot0::Errno::Isdir); + return Ok(Errno::Isdir); } - Kind::EventNotifications { .. } => return Ok(wasi_snapshot0::Errno::Inval), + Kind::EventNotifications { .. } => return Ok(Errno::Inval), Kind::Symlink { .. } => unimplemented!("Symlinks in wasi::fd_pwrite"), Kind::Buffer { buffer } => { wasi_try_ok!( @@ -1130,18 +1083,17 @@ pub fn fd_pwrite( } }; - let bytes_written: M::Offset = wasi_try_ok!(bytes_written - .try_into() - .map_err(|_| wasi_snapshot0::Errno::Overflow)); + let bytes_written: M::Offset = + wasi_try_ok!(bytes_written.try_into().map_err(|_| Errno::Overflow)); wasi_try_mem_ok!(nwritten_ref.write(bytes_written)); - Ok(wasi_snapshot0::Errno::Success) + Ok(Errno::Success) } /// ### `fd_read()` /// Read data from file descriptor /// Inputs: -/// - `wasi_snapshot0::Fd fd` +/// - `Fd fd` /// File descriptor from which data will be read /// - `const __wasi_iovec_t *iovs` /// Vectors where data will be stored @@ -1153,11 +1105,11 @@ pub fn fd_pwrite( /// pub fn fd_read( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: wasi_snapshot0::Fd, + fd: Fd, iovs: WasmPtr<__wasi_iovec_t, M>, iovs_len: M::Offset, nread: WasmPtr, -) -> Result { +) -> 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); @@ -1177,17 +1129,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_snapshot0::Errno::Badf); + return Ok(Errno::Badf); } } - __WASI_STDOUT_FILENO | __WASI_STDERR_FILENO => return Ok(wasi_snapshot0::Errno::Inval), + __WASI_STDOUT_FILENO | __WASI_STDERR_FILENO => return Ok(Errno::Inval), _ => { - if !fd_entry.rights.contains(wasi_snapshot0::Rights::FD_READ) { + if !fd_entry.rights.contains(Rights::FD_READ) { // TODO: figure out the error to return when lacking rights - return Ok(wasi_snapshot0::Errno::Acces); + return Ok(Errno::Access); } - let is_non_blocking = fd_entry.flags.contains(wasi_snapshot0::Fdflags::NONBLOCK); + 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]; @@ -1206,7 +1158,7 @@ pub fn fd_read( ); wasi_try_ok!(read_bytes(handle, &memory, iovs_arr), env) } else { - return Ok(wasi_snapshot0::Errno::Inval); + return Ok(Errno::Inval); } } Kind::Socket { socket } => { @@ -1217,7 +1169,7 @@ pub fn fd_read( } Kind::Dir { .. } | Kind::Root { .. } => { // TODO: verify - return Ok(wasi_snapshot0::Errno::Isdir); + return Ok(Errno::Isdir); } Kind::EventNotifications { counter, @@ -1263,7 +1215,7 @@ pub fn fd_read( // If its none blocking then exit if is_non_blocking { - return Ok(wasi_snapshot0::Errno::Again); + return Ok(Errno::Again); } // Yield for a fixed period of time and then check again @@ -1283,30 +1235,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_snapshot0::Errno::Badf)); + 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_snapshot0::Errno::Overflow)); + 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_snapshot0::Errno::Success) + Ok(Errno::Success) } /// ### `fd_readdir()` /// Read data from directory specified by file descriptor /// Inputs: -/// - `wasi_snapshot0::Fd 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_snapshot0::Dircookie cookie` +/// - `Dircookie cookie` /// Where the directory reading should start from /// Output: /// - `u32 *bufused` @@ -1314,12 +1264,12 @@ pub fn fd_read( /// directory has been read pub fn fd_readdir( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: wasi_snapshot0::Fd, + fd: Fd, buf: WasmPtr, buf_len: M::Offset, - cookie: wasi_snapshot0::Dircookie, + cookie: Dircookie, bufused: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { trace!("wasi::fd_readdir"); let env = ctx.data(); let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0); @@ -1332,7 +1282,7 @@ pub fn fd_readdir( let mut cur_cookie = cookie; let mut buf_idx = 0usize; - let entries: Vec<(String, wasi_snapshot0::Filetype, u64)> = { + let entries: Vec<(String, Filetype, u64)> = { let guard = inodes.arena[working_dir.inode].read(); let deref = guard.deref(); match deref { @@ -1357,7 +1307,7 @@ pub fn fd_readdir( filename, filetype, 0, // TODO: inode )) }) - .collect::, _>>()); + .collect::, _>>()); entry_vec.extend( entries .iter() @@ -1370,8 +1320,8 @@ pub fn fd_readdir( ); // adding . and .. special folders // TODO: inode - entry_vec.push((".".to_string(), wasi_snapshot0::Filetype::Directory, 0)); - entry_vec.push(("..".to_string(), wasi_snapshot0::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 } @@ -1397,7 +1347,7 @@ pub fn fd_readdir( | Kind::Buffer { .. } | Kind::Socket { .. } | Kind::Pipe { .. } - | Kind::EventNotifications { .. } => return wasi_snapshot0::Errno::Notdir, + | Kind::EventNotifications { .. } => return Errno::Notdir, } }; @@ -1405,7 +1355,7 @@ pub fn fd_readdir( cur_cookie += 1; let namlen = entry_path_str.len(); debug!("Returning dirent for {}", entry_path_str); - let dirent = wasi_snapshot0::Dirent { + let dirent = Dirent { d_next: cur_cookie, d_ino: *ino, d_namlen: namlen as u32, @@ -1415,13 +1365,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::(), + 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::() { + if upper_limit != std::mem::size_of::() { break; } let upper_limit = std::cmp::min((buf_len - buf_idx as u64) as usize, namlen); @@ -1434,31 +1384,25 @@ pub fn fd_readdir( } } - let buf_idx: M::Offset = wasi_try!(buf_idx - .try_into() - .map_err(|_| wasi_snapshot0::Errno::Overflow)); + let buf_idx: M::Offset = wasi_try!(buf_idx.try_into().map_err(|_| Errno::Overflow)); wasi_try_mem!(bufused_ref.write(buf_idx)); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `fd_renumber()` /// Atomically copy file descriptor /// Inputs: -/// - `wasi_snapshot0::Fd from` +/// - `Fd from` /// File descriptor to copy -/// - `wasi_snapshot0::Fd to` +/// - `Fd to` /// Location to copy file descriptor to -pub fn fd_renumber( - ctx: FunctionEnvMut<'_, WasiEnv>, - from: wasi_snapshot0::Fd, - to: wasi_snapshot0::Fd, -) -> wasi_snapshot0::Errno { +pub fn fd_renumber(ctx: FunctionEnvMut<'_, WasiEnv>, from: Fd, to: Fd) -> 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_snapshot0::Errno::Badf)); + let fd_entry = wasi_try!(fd_map.get_mut(&from).ok_or(Errno::Badf)); let new_fd_entry = Fd { // TODO: verify this is correct @@ -1468,22 +1412,22 @@ pub fn fd_renumber( fd_map.insert(to, new_fd_entry); fd_map.remove(&from); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `fd_dup()` /// Duplicates the file handle /// Inputs: -/// - `wasi_snapshot0::Fd fd` +/// - `Fd fd` /// File handle to be cloned /// Outputs: -/// - `wasi_snapshot0::Fd fd` +/// - `Fd fd` /// The new file handle that is a duplicate of the original pub fn fd_dup( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: wasi_snapshot0::Fd, - ret_fd: WasmPtr, -) -> wasi_snapshot0::Errno { + fd: Fd, + ret_fd: WasmPtr, +) -> Errno { debug!("wasi::fd_dup"); let env = ctx.data(); @@ -1492,7 +1436,7 @@ pub fn fd_dup( wasi_try_mem!(ret_fd.write(&memory, fd)); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `fd_event()` @@ -1501,8 +1445,8 @@ pub fn fd_event( ctx: FunctionEnvMut<'_, WasiEnv>, initial_val: u64, flags: __wasi_eventfdflags, - ret_fd: WasmPtr, -) -> wasi_snapshot0::Errno { + ret_fd: WasmPtr, +) -> Errno { debug!("wasi::fd_event"); let env = ctx.data(); @@ -1520,23 +1464,20 @@ pub fn fd_event( false, "event".to_string(), ); - let rights = wasi_snapshot0::Rights::FD_READ - | wasi_snapshot0::Rights::FD_WRITE - | wasi_snapshot0::Rights::POLL_FD_READWRITE; - let fd = - wasi_try!(state - .fs - .create_fd(rights, rights, wasi_snapshot0::Fdflags::empty(), 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_snapshot0::Errno::Success + Errno::Success } /// ### `fd_seek()` /// Update file descriptor offset /// Inputs: -/// - `wasi_snapshot0::Fd fd` +/// - `Fd fd` /// File descriptor to mutate /// - `__wasi_filedelta_t offset` /// Number of bytes to adjust offset by @@ -1547,26 +1488,26 @@ pub fn fd_event( /// The new offset relative to the start of the file pub fn fd_seek( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: wasi_snapshot0::Fd, + fd: Fd, offset: __wasi_filedelta_t, whence: __wasi_whence_t, newoffset: WasmPtr<__wasi_filesize_t, M>, -) -> Result { +) -> 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 !fd_entry.rights.contains(wasi_snapshot0::Rights::FD_SEEK) { - return Ok(wasi_snapshot0::Errno::Acces); + 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 => { let mut fd_map = state.fs.fd_map.write().unwrap(); - let fd_entry = wasi_try_ok!(fd_map.get_mut(&fd).ok_or(wasi_snapshot0::Errno::Badf)); + 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 => { @@ -1583,11 +1524,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_snapshot0::Errno::Badf)); + 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_snapshot0::Errno::Inval); + return Ok(Errno::Inval); } } Kind::Symlink { .. } => { @@ -1599,46 +1539,46 @@ pub fn fd_seek( | Kind::Pipe { .. } | Kind::EventNotifications { .. } => { // TODO: check this - return Ok(wasi_snapshot0::Errno::Inval); + return Ok(Errno::Inval); } Kind::Buffer { .. } => { // seeking buffers probably makes sense // TODO: implement this - return Ok(wasi_snapshot0::Errno::Inval); + return Ok(Errno::Inval); } } } __WASI_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_snapshot0::Errno::Badf)); + let fd_entry = wasi_try_ok!(fd_map.get_mut(&fd).ok_or(Errno::Badf)); fd_entry.offset = offset as u64 } - _ => return Ok(wasi_snapshot0::Errno::Inval), + _ => 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_snapshot0::Errno::Success) + Ok(Errno::Success) } /// ### `fd_sync()` /// Synchronize file and metadata to disk (TODO: expand upon what this means in our system) /// Inputs: -/// - `wasi_snapshot0::Fd fd` +/// - `Fd fd` /// The file descriptor to sync /// Errors: /// TODO: figure out which errors this should return -/// - `wasi_snapshot0::Errno::Perm` -/// - `wasi_snapshot0::Errno::Notcapable` -pub fn fd_sync(ctx: FunctionEnvMut<'_, WasiEnv>, fd: wasi_snapshot0::Fd) -> wasi_snapshot0::Errno { +/// - `Errno::Perm` +/// - `Errno::Notcapable` +pub fn fd_sync(ctx: FunctionEnvMut<'_, WasiEnv>, fd: Fd) -> 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 !fd_entry.rights.contains(wasi_snapshot0::Rights::FD_SYNC) { - return wasi_snapshot0::Errno::Acces; + if !fd_entry.rights.contains(Rights::FD_SYNC) { + return Errno::Access; } let inode = fd_entry.inode; @@ -1651,34 +1591,34 @@ pub fn fd_sync(ctx: FunctionEnvMut<'_, WasiEnv>, fd: wasi_snapshot0::Fd) -> wasi if let Some(h) = handle { wasi_try!(h.sync_to_disk().map_err(fs_error_into_wasi_err)); } else { - return wasi_snapshot0::Errno::Inval; + return Errno::Inval; } } - Kind::Root { .. } | Kind::Dir { .. } => return wasi_snapshot0::Errno::Isdir, + Kind::Root { .. } | Kind::Dir { .. } => return Errno::Isdir, Kind::Buffer { .. } | Kind::Symlink { .. } | Kind::Socket { .. } | Kind::Pipe { .. } - | Kind::EventNotifications { .. } => return wasi_snapshot0::Errno::Inval, + | Kind::EventNotifications { .. } => return Errno::Inval, } } - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `fd_tell()` /// Get the offset of the file descriptor /// Inputs: -/// - `wasi_snapshot0::Fd fd` +/// - `Fd fd` /// The file descriptor to access /// Output: /// - `__wasi_filesize_t *offset` /// The offset of `fd` relative to the start of the file pub fn fd_tell( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: wasi_snapshot0::Fd, + fd: Fd, offset: WasmPtr<__wasi_filesize_t, M>, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!("wasi::fd_tell"); let env = ctx.data(); let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0); @@ -1686,19 +1626,19 @@ pub fn fd_tell( let fd_entry = wasi_try!(state.fs.get_fd(fd)); - if !fd_entry.rights.contains(wasi_snapshot0::Rights::FD_TELL) { - return wasi_snapshot0::Errno::Acces; + if !fd_entry.rights.contains(Rights::FD_TELL) { + return Errno::Access; } wasi_try_mem!(offset_ref.write(fd_entry.offset)); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `fd_write()` /// Write data to the file descriptor /// Inputs: -/// - `wasi_snapshot0::Fd` +/// - `Fd` /// File descriptor (opened with writing) to write to /// - `const __wasi_ciovec_t *iovs` /// List of vectors to read data from @@ -1711,11 +1651,11 @@ pub fn fd_tell( /// pub fn fd_write( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: wasi_snapshot0::Fd, + fd: Fd, iovs: WasmPtr<__wasi_ciovec_t, M>, iovs_len: M::Offset, nwritten: WasmPtr, -) -> Result { +) -> 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); @@ -1724,7 +1664,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_snapshot0::Errno::Inval), + __WASI_STDIN_FILENO => return Ok(Errno::Inval), __WASI_STDOUT_FILENO => { let mut guard = wasi_try_ok!( inodes @@ -1735,7 +1675,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_snapshot0::Errno::Badf); + return Ok(Errno::Badf); } } __WASI_STDERR_FILENO => { @@ -1748,12 +1688,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_snapshot0::Errno::Badf); + return Ok(Errno::Badf); } } _ => { - if !fd_entry.rights.contains(wasi_snapshot0::Rights::FD_WRITE) { - return Ok(wasi_snapshot0::Errno::Acces); + if !fd_entry.rights.contains(Rights::FD_WRITE) { + return Ok(Errno::Access); } let offset = fd_entry.offset as usize; @@ -1774,7 +1714,7 @@ pub fn fd_write( ); wasi_try_ok!(write_bytes(handle, &memory, iovs_arr), env) } else { - return Ok(wasi_snapshot0::Errno::Inval); + return Ok(Errno::Inval); } } Kind::Socket { socket } => { @@ -1785,7 +1725,7 @@ pub fn fd_write( } Kind::Dir { .. } | Kind::Root { .. } => { // TODO: verify - return Ok(wasi_snapshot0::Errno::Isdir); + return Ok(Errno::Isdir); } Kind::EventNotifications { counter, wakers, .. @@ -1793,7 +1733,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_snapshot0::Errno::Inval); + return Ok(Errno::Inval); } let val = u64::from_ne_bytes(val); @@ -1819,7 +1759,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_snapshot0::Errno::Badf)); + 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); @@ -1828,26 +1768,25 @@ pub fn fd_write( } }; - let bytes_written: M::Offset = wasi_try_ok!(bytes_written - .try_into() - .map_err(|_| wasi_snapshot0::Errno::Overflow)); + let bytes_written: M::Offset = + wasi_try_ok!(bytes_written.try_into().map_err(|_| Errno::Overflow)); wasi_try_mem_ok!(nwritten_ref.write(bytes_written)); - Ok(wasi_snapshot0::Errno::Success) + Ok(Errno::Success) } /// ### `fd_pipe()` /// Creates ta pipe that feeds data between two file handles /// Output: -/// - `wasi_snapshot0::Fd` +/// - `Fd` /// First file handle that represents one end of the pipe -/// - `wasi_snapshot0::Fd` +/// - `Fd` /// Second file handle that represents the other end of the pipe pub fn fd_pipe( ctx: FunctionEnvMut<'_, WasiEnv>, - ro_fd1: WasmPtr, - ro_fd2: WasmPtr, -) -> wasi_snapshot0::Errno { + ro_fd1: WasmPtr, + ro_fd2: WasmPtr, +) -> Errno { trace!("wasi::fd_pipe"); let env = ctx.data(); @@ -1869,25 +1808,23 @@ pub fn fd_pipe( ); let rights = super::state::all_socket_rights(); - let fd1 = - wasi_try!(state - .fs - .create_fd(rights, rights, wasi_snapshot0::Fdflags::empty(), 0, inode1)); - let fd2 = - wasi_try!(state - .fs - .create_fd(rights, rights, wasi_snapshot0::Fdflags::empty(), 0, inode2)); + 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_snapshot0::Errno::Success + Errno::Success } /// ### `path_create_directory()` /// Create directory at a path /// Inputs: -/// - `wasi_snapshot0::Fd fd` +/// - `Fd fd` /// The directory that the path is relative to /// - `const char *path` /// String containing path data @@ -1895,14 +1832,14 @@ pub fn fd_pipe( /// The length of `path` /// Errors: /// Required Rights: -/// - wasi_snapshot0::Rights::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_snapshot0::Fd, + fd: Fd, path: WasmPtr, path_len: M::Offset, -) -> wasi_snapshot0::Errno { +) -> 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); @@ -1911,14 +1848,11 @@ pub fn path_create_directory( { let guard = inodes.arena[working_dir.inode].read(); if let Kind::Root { .. } = guard.deref() { - return wasi_snapshot0::Errno::Acces; + return Errno::Access; } } - if !working_dir - .rights - .contains(wasi_snapshot0::Rights::PATH_CREATE_DIRECTORY) - { - return wasi_snapshot0::Errno::Acces; + 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); @@ -1930,11 +1864,11 @@ pub fn path_create_directory( comp.as_os_str() .to_str() .map(|inner_str| inner_str.to_string()) - .ok_or(wasi_snapshot0::Errno::Inval) + .ok_or(Errno::Inval) }) - .collect::, wasi_snapshot0::Errno>>()); + .collect::, Errno>>()); if path_vec.is_empty() { - return wasi_snapshot0::Errno::Inval; + return Errno::Inval; } debug!("Looking at components {:?}", &path_vec); @@ -1976,8 +1910,8 @@ pub fn path_create_directory( 0, &adjusted_path.to_string_lossy(), ) { - if adjusted_path_stat.st_filetype != wasi_snapshot0::Filetype::Directory { - return wasi_snapshot0::Errno::Notdir; + if adjusted_path_stat.st_filetype != Filetype::Directory { + return Errno::Notdir; } } else { wasi_try!(state.fs_create_dir(&adjusted_path)); @@ -2007,18 +1941,18 @@ pub fn path_create_directory( cur_dir_inode = new_inode; } } - Kind::Root { .. } => return wasi_snapshot0::Errno::Acces, - _ => return wasi_snapshot0::Errno::Notdir, + Kind::Root { .. } => return Errno::Access, + _ => return Errno::Notdir, } } - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `path_filestat_get()` /// Access metadata about a file or directory /// Inputs: -/// - `wasi_snapshot0::Fd fd` +/// - `Fd fd` /// The directory that `path` is relative to /// - `__wasi_lookupflags_t flags` /// Flags to control how `path` is understood @@ -2031,12 +1965,12 @@ pub fn path_create_directory( /// The location where the metadata will be stored pub fn path_filestat_get( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: wasi_snapshot0::Fd, + fd: Fd, flags: __wasi_lookupflags_t, path: WasmPtr, path_len: M::Offset, buf: WasmPtr<__wasi_filestat_t, M>, -) -> wasi_snapshot0::Errno { +) -> 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); @@ -2054,13 +1988,13 @@ pub fn path_filestat_get( wasi_try_mem!(buf.deref(&memory).write(stat)); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `path_filestat_get()` /// Access metadata about a file or directory /// Inputs: -/// - `wasi_snapshot0::Fd fd` +/// - `Fd fd` /// The directory that `path` is relative to /// - `__wasi_lookupflags_t flags` /// Flags to control how `path` is understood @@ -2075,17 +2009,14 @@ pub fn path_filestat_get_internal( memory: &MemoryView, state: &WasiState, inodes: &mut crate::WasiInodes, - fd: wasi_snapshot0::Fd, + fd: Fd, flags: __wasi_lookupflags_t, path_string: &str, -) -> Result<__wasi_filestat_t, wasi_snapshot0::Errno> { +) -> Result<__wasi_filestat_t, Errno> { let root_dir = state.fs.get_fd(fd)?; - if !root_dir - .rights - .contains(wasi_snapshot0::Rights::PATH_FILESTAT_GET) - { - return Err(wasi_snapshot0::Errno::Acces); + if !root_dir.rights.contains(Rights::PATH_FILESTAT_GET) { + return Err(Errno::Access); } debug!("=> base_fd: {}, path: {}", fd, path_string); @@ -2106,7 +2037,7 @@ pub fn path_filestat_get_internal( /// ### `path_filestat_set_times()` /// Update time metadata on a file or directory /// Inputs: -/// - `wasi_snapshot0::Fd fd` +/// - `Fd fd` /// The directory relative to which the path is resolved /// - `__wasi_lookupflags_t flags` /// Flags to control how the path is understood @@ -2122,30 +2053,27 @@ pub fn path_filestat_get_internal( /// A bitmask controlling which attributes are set pub fn path_filestat_set_times( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: wasi_snapshot0::Fd, + fd: Fd, flags: __wasi_lookupflags_t, path: WasmPtr, path_len: M::Offset, st_atim: __wasi_timestamp_t, st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, -) -> wasi_snapshot0::Errno { +) -> 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 !fd_entry - .rights - .contains(wasi_snapshot0::Rights::PATH_FILESTAT_SET_TIMES) - { - return wasi_snapshot0::Errno::Acces; + 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) { - return wasi_snapshot0::Errno::Inval; + return Errno::Inval; } let path_string = unsafe { get_input_str!(&memory, path, path_len) }; @@ -2181,13 +2109,13 @@ pub fn path_filestat_set_times( inode.stat.write().unwrap().st_mtim = time_to_set; } - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `path_link()` /// Create a hard link /// Inputs: -/// - `wasi_snapshot0::Fd old_fd` +/// - `Fd old_fd` /// The directory relative to which the `old_path` is /// - `__wasi_lookupflags_t old_flags` /// Flags to control how `old_path` is understood @@ -2195,7 +2123,7 @@ pub fn path_filestat_set_times( /// String containing the old file path /// - `u32 old_path_len` /// Length of the `old_path` string -/// - `wasi_snapshot0::Fd new_fd` +/// - `Fd new_fd` /// The directory relative to which the `new_path` is /// - `const char *new_path` /// String containing the new file path @@ -2203,14 +2131,14 @@ pub fn path_filestat_set_times( /// Length of the `new_path` string pub fn path_link( ctx: FunctionEnvMut<'_, WasiEnv>, - old_fd: wasi_snapshot0::Fd, + old_fd: Fd, old_flags: __wasi_lookupflags_t, old_path: WasmPtr, old_path_len: M::Offset, - new_fd: wasi_snapshot0::Fd, + new_fd: Fd, new_path: WasmPtr, new_path_len: M::Offset, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!("wasi::path_link"); if old_flags & __WASI_LOOKUP_SYMLINK_FOLLOW != 0 { debug!(" - will follow symlinks when opening path"); @@ -2226,14 +2154,10 @@ pub fn path_link( old_fd, &old_path_str, new_fd, new_path_str ); - if !source_fd - .rights - .contains(wasi_snapshot0::Rights::PATH_LINK_SOURCE) - || !target_fd - .rights - .contains(wasi_snapshot0::Rights::PATH_LINK_TARGET) + if !source_fd.rights.contains(Rights::PATH_LINK_SOURCE) + || !target_fd.rights.contains(Rights::PATH_LINK_TARGET) { - return wasi_snapshot0::Errno::Acces; + return Errno::Access; } let source_inode = wasi_try!(state.fs.get_inode_at_path( @@ -2252,7 +2176,7 @@ pub fn path_link( if inodes.arena[source_inode].stat.write().unwrap().st_nlink == __wasi_linkcount_t::max_value() { - return wasi_snapshot0::Errno::Mlink; + return Errno::Mlink; } { let mut guard = inodes.arena[target_parent_inode].write(); @@ -2260,28 +2184,28 @@ pub fn path_link( match deref_mut { Kind::Dir { entries, .. } => { if entries.contains_key(&new_entry_name) { - return wasi_snapshot0::Errno::Exist; + return Errno::Exist; } entries.insert(new_entry_name, source_inode); } - Kind::Root { .. } => return wasi_snapshot0::Errno::Inval, + Kind::Root { .. } => return Errno::Inval, Kind::File { .. } | Kind::Symlink { .. } | Kind::Buffer { .. } | Kind::Socket { .. } | Kind::Pipe { .. } - | Kind::EventNotifications { .. } => return wasi_snapshot0::Errno::Notdir, + | Kind::EventNotifications { .. } => return Errno::Notdir, } } inodes.arena[source_inode].stat.write().unwrap().st_nlink += 1; - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `path_open()` /// Open file located at the given path /// Inputs: -/// - `wasi_snapshot0::Fd dirfd` +/// - `Fd dirfd` /// The fd corresponding to the directory that the file is in /// - `__wasi_lookupflags_t dirflags` /// Flags specifying how the path will be resolved @@ -2291,29 +2215,29 @@ pub fn path_link( /// The length of the `path` string /// - `__wasi_oflags_t o_flags` /// How the file will be opened -/// - `wasi_snapshot0::Rights fs_rights_base` +/// - `Rights fs_rights_base` /// The rights of the created file descriptor -/// - `wasi_snapshot0::Rights fs_rightsinheriting` +/// - `Rights fs_rightsinheriting` /// The rights of file descriptors derived from the created file descriptor -/// - `wasi_snapshot0::Fdflags fs_flags` +/// - `Fdflags fs_flags` /// The flags of the file descriptor /// Output: -/// - `wasi_snapshot0::Fd* fd` +/// - `Fd* fd` /// The new file descriptor /// Possible Errors: -/// - `wasi_snapshot0::Errno::Acces`, `wasi_snapshot0::Errno::Badf`, `wasi_snapshot0::Errno::Fault`, `wasi_snapshot0::Errno::Toobig?`, `wasi_snapshot0::Errno::Inval`, `wasi_snapshot0::Errno::Io`, `wasi_snapshot0::Errno::Loop`, `wasi_snapshot0::Errno::Mfile`, `wasi_snapshot0::Errno::Nametoolong?`, `wasi_snapshot0::Errno::Nfile`, `wasi_snapshot0::Errno::Noent`, `wasi_snapshot0::Errno::Notdir`, `wasi_snapshot0::Errno::Rofs`, and `wasi_snapshot0::Errno::Notcapable` +/// - `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_snapshot0::Fd, + dirfd: Fd, dirflags: __wasi_lookupflags_t, path: WasmPtr, path_len: M::Offset, o_flags: __wasi_oflags_t, - fs_rights_base: wasi_snapshot0::Rights, - fs_rights_inheriting: wasi_snapshot0::Rights, - fs_flags: wasi_snapshot0::Fdflags, - fd: WasmPtr, -) -> wasi_snapshot0::Errno { + 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"); @@ -2323,7 +2247,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_snapshot0::Errno::Nametoolong; + return Errno::Nametoolong; } let fd_ref = fd.deref(&memory); @@ -2338,11 +2262,8 @@ pub fn path_open( let working_dir_rights_inheriting = working_dir.rights_inheriting; // ASSUMPTION: open rights apply recursively - if !working_dir - .rights - .contains(wasi_snapshot0::Rights::PATH_OPEN) - { - return wasi_snapshot0::Errno::Acces; + if !working_dir.rights.contains(Rights::PATH_OPEN) { + return Errno::Access; } let path_string = unsafe { get_input_str!(&memory, path, path_len) }; @@ -2376,21 +2297,21 @@ 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_snapshot0::Errno::Success; + return Errno::Success; } if o_flags & __WASI_O_DIRECTORY != 0 { - return wasi_snapshot0::Errno::Notdir; + return Errno::Notdir; } if o_flags & __WASI_O_EXCL != 0 { - return wasi_snapshot0::Errno::Exist; + return Errno::Exist; } - let write_permission = adjusted_rights.contains(wasi_snapshot0::Rights::FD_WRITE); + 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.contains(wasi_snapshot0::Fdflags::APPEND), + fs_flags.contains(Fdflags::APPEND), o_flags & __WASI_O_TRUNC != 0, o_flags & __WASI_O_CREAT != 0, ) @@ -2405,7 +2326,7 @@ pub fn path_open( .append(append_permission) .truncate(truncate_permission); open_flags |= Fd::READ; - if adjusted_rights.contains(wasi_snapshot0::Rights::FD_WRITE) { + if adjusted_rights.contains(Rights::FD_WRITE) { open_flags |= Fd::WRITE; } if o_flags & __WASI_O_CREAT != 0 { @@ -2440,7 +2361,7 @@ pub fn path_open( debug!("Maybe creating file"); if o_flags & __WASI_O_CREAT != 0 { if o_flags & __WASI_O_DIRECTORY != 0 { - return wasi_snapshot0::Errno::Notdir; + return Errno::Notdir; } debug!("Creating file"); // strip end file name @@ -2460,8 +2381,8 @@ pub fn path_open( new_path.push(&new_entity_name); new_path } - Kind::Root { .. } => return wasi_snapshot0::Errno::Acces, - _ => return wasi_snapshot0::Errno::Inval, + Kind::Root { .. } => return Errno::Access, + _ => return Errno::Inval, } }; // once we got the data we need from the parent, we lookup the host file @@ -2469,7 +2390,7 @@ pub fn path_open( let handle = { let open_options = open_options .read(true) - .append(fs_flags.contains(wasi_snapshot0::Fdflags::APPEND)) + .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) @@ -2531,13 +2452,13 @@ pub fn path_open( wasi_try_mem!(fd_ref.write(out_fd)); debug!("wasi::path_open returning fd {}", out_fd); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `path_readlink()` /// Read the value of a symlink /// Inputs: -/// - `wasi_snapshot0::Fd 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 @@ -2552,23 +2473,20 @@ pub fn path_open( /// The number of bytes written to `buf` pub fn path_readlink( ctx: FunctionEnvMut<'_, WasiEnv>, - dir_fd: wasi_snapshot0::Fd, + dir_fd: Fd, path: WasmPtr, path_len: M::Offset, buf: WasmPtr, buf_len: M::Offset, buf_used: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> 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 !base_dir - .rights - .contains(wasi_snapshot0::Rights::PATH_READLINK) - { - return wasi_snapshot0::Errno::Acces; + 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 @@ -2583,7 +2501,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_snapshot0::Errno::Overflow; + return Errno::Overflow; } let bytes: Vec<_> = bytes.collect(); @@ -2591,26 +2509,24 @@ pub fn path_readlink( wasi_try_mem!(out.write_slice(&bytes)); // should we null terminate this? - let bytes_len: M::Offset = wasi_try!(bytes - .len() - .try_into() - .map_err(|_| wasi_snapshot0::Errno::Overflow)); + let bytes_len: M::Offset = + wasi_try!(bytes.len().try_into().map_err(|_| Errno::Overflow)); wasi_try_mem!(buf_used.deref(&memory).write(bytes_len)); } else { - return wasi_snapshot0::Errno::Inval; + return Errno::Inval; } } - wasi_snapshot0::Errno::Success + Errno::Success } -/// Returns wasi_snapshot0::Errno::Notemtpy if directory is not empty +/// Returns Errno::Notemtpy if directory is not empty pub fn path_remove_directory( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: wasi_snapshot0::Fd, + fd: Fd, path: WasmPtr, path_len: M::Offset, -) -> wasi_snapshot0::Errno { +) -> Errno { // TODO check if fd is a dir, ensure it's within sandbox, etc. debug!("wasi::path_remove_directory"); let env = ctx.data(); @@ -2635,12 +2551,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_snapshot0::Errno::Notempty; + return Errno::Notempty; } path.clone() } - Kind::Root { .. } => return wasi_snapshot0::Errno::Acces, - _ => return wasi_snapshot0::Errno::Notdir, + Kind::Root { .. } => return Errno::Access, + _ => return Errno::Notdir, } }; @@ -2651,13 +2567,11 @@ pub fn path_remove_directory( Kind::Dir { ref mut entries, .. } => { - let removed_inode = wasi_try!(entries - .remove(&childs_name) - .ok_or(wasi_snapshot0::Errno::Inval)); + 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_snapshot0::Errno::Acces, + Kind::Root { .. } => return Errno::Access, _ => unreachable!( "Internal logic error in wasi::path_remove_directory, parent is not a directory" ), @@ -2676,19 +2590,19 @@ pub fn path_remove_directory( return err; } - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `path_rename()` /// Rename a file or directory /// Inputs: -/// - `wasi_snapshot0::Fd 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_snapshot0::Fd new_fd` +/// - `Fd new_fd` /// The base directory for `new_path` /// - `const char* new_path` /// Pointer to UTF8 bytes, the new file name @@ -2696,13 +2610,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_snapshot0::Fd, + old_fd: Fd, old_path: WasmPtr, old_path_len: M::Offset, - new_fd: wasi_snapshot0::Fd, + new_fd: Fd, new_path: WasmPtr, new_path_len: M::Offset, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!( "wasi::path_rename: old_fd = {}, new_fd = {}", old_fd, new_fd @@ -2717,18 +2631,12 @@ pub fn path_rename( { let source_fd = wasi_try!(state.fs.get_fd(old_fd)); - if !source_fd - .rights - .contains(wasi_snapshot0::Rights::PATH_RENAME_SOURCE) - { - return wasi_snapshot0::Errno::Acces; + if !source_fd.rights.contains(Rights::PATH_RENAME_SOURCE) { + return Errno::Access; } let target_fd = wasi_try!(state.fs.get_fd(new_fd)); - if !target_fd - .rights - .contains(wasi_snapshot0::Rights::PATH_RENAME_TARGET) - { - return wasi_snapshot0::Errno::Acces; + if !target_fd.rights.contains(Rights::PATH_RENAME_TARGET) { + return Errno::Access; } } @@ -2749,7 +2657,7 @@ pub fn path_rename( ) .is_ok() { - return wasi_snapshot0::Errno::Exist; + return Errno::Exist; } let (source_parent_inode, source_entry_name) = wasi_try!(state @@ -2765,15 +2673,15 @@ pub fn path_rename( match deref { Kind::Dir { entries, path, .. } => { if entries.contains_key(&target_entry_name) { - return wasi_snapshot0::Errno::Exist; + 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_snapshot0::Errno::Notcapable, + Kind::Root { .. } => return Errno::Notcapable, Kind::Socket { .. } | Kind::Pipe { .. } | Kind::EventNotifications { .. } => { - return wasi_snapshot0::Errno::Inval + return Errno::Inval } Kind::Symlink { .. } | Kind::File { .. } | Kind::Buffer { .. } => { unreachable!("Fatal internal logic error: parent of inode is not a directory") @@ -2786,13 +2694,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_snapshot0::Errno::Noent)) + wasi_try!(entries.remove(&source_entry_name).ok_or(Errno::Noent)) } - Kind::Root { .. } => return wasi_snapshot0::Errno::Notcapable, + Kind::Root { .. } => return Errno::Notcapable, Kind::Socket { .. } | Kind::Pipe { .. } | Kind::EventNotifications { .. } => { - return wasi_snapshot0::Errno::Inval + return Errno::Inval } Kind::Symlink { .. } | Kind::File { .. } | Kind::Buffer { .. } => { unreachable!("Fatal internal logic error: parent of inode is not a directory") @@ -2871,7 +2777,7 @@ pub fn path_rename( } } - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `path_symlink()` @@ -2881,7 +2787,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_snapshot0::Fd 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 @@ -2891,21 +2797,18 @@ pub fn path_symlink( ctx: FunctionEnvMut<'_, WasiEnv>, old_path: WasmPtr, old_path_len: M::Offset, - fd: wasi_snapshot0::Fd, + fd: Fd, new_path: WasmPtr, new_path_len: M::Offset, -) -> wasi_snapshot0::Errno { +) -> 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 !base_fd - .rights - .contains(wasi_snapshot0::Rights::PATH_SYMLINK) - { - return wasi_snapshot0::Errno::Acces; + 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) @@ -2932,12 +2835,12 @@ pub fn path_symlink( match deref { Kind::Dir { entries, .. } => { if entries.contains_key(&entry_name) { - return wasi_snapshot0::Errno::Exist; + return Errno::Exist; } } - Kind::Root { .. } => return wasi_snapshot0::Errno::Notcapable, + Kind::Root { .. } => return Errno::Notcapable, Kind::Socket { .. } | Kind::Pipe { .. } | Kind::EventNotifications { .. } => { - return wasi_snapshot0::Errno::Inval + return Errno::Inval } Kind::File { .. } | Kind::Symlink { .. } | Kind::Buffer { .. } => { unreachable!("get_parent_inode_at_path returned something other than a Dir or Root") @@ -2979,13 +2882,13 @@ pub fn path_symlink( } } - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `path_unlink_file()` /// Unlink a file, deleting if the number of hardlinks is 1 /// Inputs: -/// - `wasi_snapshot0::Fd fd` +/// - `Fd fd` /// The base file descriptor from which the path is understood /// - `const char *path` /// Array of UTF-8 bytes representing the path @@ -2993,20 +2896,17 @@ pub fn path_symlink( /// The number of bytes in the `path` array pub fn path_unlink_file( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: wasi_snapshot0::Fd, + fd: Fd, path: WasmPtr, path_len: M::Offset, -) -> wasi_snapshot0::Errno { +) -> 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 !base_dir - .rights - .contains(wasi_snapshot0::Rights::PATH_UNLINK_FILE) - { - return wasi_snapshot0::Errno::Acces; + 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); @@ -3028,15 +2928,13 @@ pub fn path_unlink_file( Kind::Dir { ref mut entries, .. } => { - let removed_inode = wasi_try!(entries - .remove(&childs_name) - .ok_or(wasi_snapshot0::Errno::Inval)); + 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_snapshot0::Errno::Acces, + Kind::Root { .. } => return Errno::Access, _ => unreachable!( "Internal logic error in wasi::path_unlink_file, parent is not a directory" ), @@ -3064,7 +2962,7 @@ pub fn path_unlink_file( wasi_try!(state.fs_remove_file(path)); } } - Kind::Dir { .. } | Kind::Root { .. } => return wasi_snapshot0::Errno::Isdir, + Kind::Dir { .. } | Kind::Root { .. } => return Errno::Isdir, Kind::Symlink { .. } => { // TODO: actually delete real symlinks and do nothing for virtual symlinks } @@ -3094,7 +2992,7 @@ pub fn path_unlink_file( } } - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `poll_oneoff()` @@ -3115,7 +3013,7 @@ pub fn poll_oneoff( out_: WasmPtr<__wasi_event_t, M>, nsubscriptions: M::Offset, nevents: WasmPtr, -) -> Result { +) -> Result { trace!("wasi::poll_oneoff"); trace!(" => nsubscriptions = {}", nsubscriptions); let env = ctx.data(); @@ -3141,8 +3039,8 @@ pub fn poll_oneoff( __WASI_STDIN_FILENO | __WASI_STDOUT_FILENO | __WASI_STDERR_FILENO => (), _ => { let fd_entry = wasi_try_ok!(state.fs.get_fd(fd), env); - if !fd_entry.rights.contains(wasi_snapshot0::Rights::FD_READ) { - return Ok(wasi_snapshot0::Errno::Acces); + if !fd_entry.rights.contains(Rights::FD_READ) { + return Ok(Errno::Access); } } } @@ -3154,8 +3052,8 @@ pub fn poll_oneoff( __WASI_STDIN_FILENO | __WASI_STDOUT_FILENO | __WASI_STDERR_FILENO => (), _ => { let fd_entry = wasi_try_ok!(state.fs.get_fd(fd), env); - if !fd_entry.rights.contains(wasi_snapshot0::Rights::FD_WRITE) { - return Ok(wasi_snapshot0::Errno::Acces); + if !fd_entry.rights.contains(Rights::FD_WRITE) { + return Ok(Errno::Access); } } } @@ -3163,10 +3061,7 @@ pub fn poll_oneoff( Some(fd) } EventType::Clock(clock_info) => { - if matches!( - clock_info.clock_id, - wasi_snapshot0::Clockid::Realtime | wasi_snapshot0::Clockid::Monotonic - ) { + 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); @@ -3207,11 +3102,8 @@ pub fn poll_oneoff( _ => { let fd_entry = wasi_try_ok!(state.fs.get_fd(fd), env); let inode = fd_entry.inode; - if !fd_entry - .rights - .contains(wasi_snapshot0::Rights::POLL_FD_READWRITE) - { - return Ok(wasi_snapshot0::Errno::Acces); + if !fd_entry.rights.contains(Rights::POLL_FD_READWRITE) { + return Ok(Errno::Access); } { @@ -3222,13 +3114,13 @@ pub fn poll_oneoff( if let Some(h) = handle { crate::state::InodeValFileReadGuard { guard } } else { - return Ok(wasi_snapshot0::Errno::Badf); + return Ok(Errno::Badf); } } Kind::Socket { .. } | Kind::Pipe { .. } | Kind::EventNotifications { .. } => { - return Ok(wasi_snapshot0::Errno::Badf); + return Ok(Errno::Badf); } Kind::Dir { .. } | Kind::Root { .. } @@ -3248,19 +3140,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_snapshot0::Errno::Badf)).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_snapshot0::Clockid::Monotonic, 1_000_000).unwrap() as u128; + let start = platform_clock_time_get(Clockid::Monotonic, 1_000_000).unwrap() as u128; let mut triggered = 0; while triggered == 0 { - let now = - platform_clock_time_get(wasi_snapshot0::Clockid::Monotonic, 1_000_000).unwrap() as u128; + let now = platform_clock_time_get(Clockid::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, @@ -3290,15 +3180,15 @@ pub fn poll_oneoff( } for (i, seen_event) in seen_events.into_iter().enumerate() { - let mut flags = wasi_snapshot0::Eventrwflags::empty(); - let mut error = wasi_snapshot0::Errno::Again; + 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_snapshot0::Errno::Io, - PollEvent::PollHangUp => flags = wasi_snapshot0::Eventrwflags::FD_READWRITE_HANGUP, - PollEvent::PollInvalid => error = wasi_snapshot0::Errno::Inval, + 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] @@ -3307,7 +3197,7 @@ pub fn poll_oneoff( env ) .unwrap_or(0usize); - error = wasi_snapshot0::Errno::Success; + error = Errno::Success; } PollEvent::PollOut => { bytes_available = wasi_try_ok!( @@ -3317,7 +3207,7 @@ pub fn poll_oneoff( env ) .unwrap_or(0usize); - error = wasi_snapshot0::Errno::Success; + error = Errno::Success; } } } @@ -3341,13 +3231,13 @@ pub fn poll_oneoff( for (clock_info, userdata) in clock_subs { let event = __wasi_event_t { userdata, - error: wasi_snapshot0::Errno::Success, - type_: wasi_snapshot0::Eventtype::Clock, + error: Errno::Success, + type_: Eventtype::Clock, u: unsafe { __wasi_event_u { fd_readwrite: __wasi_event_fd_readwrite_t { nbytes: 0, - flags: wasi_snapshot0::Eventrwflags::empty(), + flags: Eventrwflags::empty(), }, } }, @@ -3356,11 +3246,9 @@ pub fn poll_oneoff( events_seen += 1; } } - let events_seen: M::Offset = wasi_try_ok!(events_seen - .try_into() - .map_err(|_| wasi_snapshot0::Errno::Overflow)); + 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_snapshot0::Errno::Success) + Ok(Errno::Success) } /// ### `proc_exit()` @@ -3384,18 +3272,18 @@ pub fn proc_exit( /// Inputs: /// - `__wasi_signal_t` /// Signal to be raised for this process -pub fn proc_raise(ctx: FunctionEnvMut<'_, WasiEnv>, sig: __wasi_signal_t) -> wasi_snapshot0::Errno { +pub fn proc_raise(ctx: FunctionEnvMut<'_, WasiEnv>, sig: __wasi_signal_t) -> Errno { debug!("wasi::proc_raise"); unimplemented!("wasi::proc_raise") } /// ### `sched_yield()` /// Yields execution of the thread -pub fn sched_yield(ctx: FunctionEnvMut<'_, WasiEnv>) -> Result { +pub fn sched_yield(ctx: FunctionEnvMut<'_, WasiEnv>) -> Result { trace!("wasi::sched_yield"); let env = ctx.data(); env.yield_now()?; - Ok(wasi_snapshot0::Errno::Success) + Ok(Errno::Success) } /// ### `random_get()` @@ -3409,7 +3297,7 @@ pub fn random_get( ctx: FunctionEnvMut<'_, WasiEnv>, buf: WasmPtr, buf_len: M::Offset, -) -> wasi_snapshot0::Errno { +) -> Errno { trace!("wasi::random_get buf_len: {}", buf_len); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -3420,9 +3308,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_snapshot0::Errno::Success + Errno::Success } - Err(_) => wasi_snapshot0::Errno::Io, + Err(_) => Errno::Io, } } @@ -3431,7 +3319,7 @@ pub fn random_get( pub fn tty_get( ctx: FunctionEnvMut<'_, WasiEnv>, tty_state: WasmPtr<__wasi_tty_t, M>, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!("wasi::tty_stdin"); let env = ctx.data(); @@ -3466,7 +3354,7 @@ pub fn tty_get( let memory = env.memory_view(&ctx); wasi_try_mem!(tty_state.write(&memory, state)); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `tty_set()` @@ -3474,7 +3362,7 @@ pub fn tty_get( pub fn tty_set( ctx: FunctionEnvMut<'_, WasiEnv>, tty_state: WasmPtr<__wasi_tty_t, M>, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!("wasi::tty_set"); let env = ctx.data(); @@ -3488,33 +3376,33 @@ pub fn tty_set( stdin_tty: match state.stdin_tty { __WASI_BOOL_FALSE => false, __WASI_BOOL_TRUE => true, - _ => return wasi_snapshot0::Errno::Inval, + _ => return Errno::Inval, }, stdout_tty: match state.stdout_tty { __WASI_BOOL_FALSE => false, __WASI_BOOL_TRUE => true, - _ => return wasi_snapshot0::Errno::Inval, + _ => return Errno::Inval, }, stderr_tty: match state.stderr_tty { __WASI_BOOL_FALSE => false, __WASI_BOOL_TRUE => true, - _ => return wasi_snapshot0::Errno::Inval, + _ => return Errno::Inval, }, echo: match state.echo { __WASI_BOOL_FALSE => false, __WASI_BOOL_TRUE => true, - _ => return wasi_snapshot0::Errno::Inval, + _ => return Errno::Inval, }, line_buffered: match state.line_buffered { __WASI_BOOL_FALSE => false, __WASI_BOOL_TRUE => true, - _ => return wasi_snapshot0::Errno::Inval, + _ => return Errno::Inval, }, }; env.runtime.tty_set(state); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `getcwd()` @@ -3525,7 +3413,7 @@ pub fn getcwd( ctx: FunctionEnvMut<'_, WasiEnv>, path: WasmPtr, path_len: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> 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); @@ -3541,7 +3429,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_snapshot0::Errno::Overflow; + return Errno::Overflow; } let cur_dir = { @@ -3551,13 +3439,13 @@ pub fn getcwd( u8_buffer[..cur_dir_len].clone_from_slice(cur_dir); u8_buffer[cur_dir_len] = 0; } else { - return wasi_snapshot0::Errno::Overflow; + return Errno::Overflow; } u8_buffer }; wasi_try_mem!(path_slice.write_slice(&cur_dir[..])); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `chdir()` @@ -3566,14 +3454,14 @@ pub fn chdir( ctx: FunctionEnvMut<'_, WasiEnv>, path: WasmPtr, path_len: M::Offset, -) -> wasi_snapshot0::Errno { +) -> 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_snapshot0::Errno::Success + Errno::Success } /// ### `thread_spawn()` @@ -3601,7 +3489,7 @@ pub fn thread_spawn( user_data: u64, reactor: __wasi_bool_t, ret_tid: WasmPtr<__wasi_tid_t, M>, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!("wasi::thread_spawn"); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -3609,12 +3497,12 @@ pub fn thread_spawn( // Load the callback function if method.as_str() != "_thread_start" { - return wasi_snapshot0::Errno::Notcapable; + return Errno::Notcapable; }; /* let funct = unsafe { if env.thread_start_ref().is_none() { - return wasi_snapshot0::Errno::Addrnotavail; + return Errno::Addrnotavail; } env.thread_start_ref_unchecked() }; @@ -3623,7 +3511,7 @@ pub fn thread_spawn( let reactor = match reactor { __WASI_BOOL_FALSE => false, __WASI_BOOL_TRUE => true, - _ => return wasi_snapshot0::Errno::Inval, + _ => return Errno::Inval, }; // Create the sub-thread @@ -3664,7 +3552,7 @@ pub fn thread_spawn( drop(sub_thread); })) .map_err(|err| { - let err: wasi_snapshot0::Errno = err.into(); + let err: Errno = err.into(); err })); id @@ -3672,7 +3560,7 @@ pub fn thread_spawn( let child: __wasi_tid_t = child.into(); wasi_try_mem!(ret_tid.write(&memory, child)); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `thread_sleep()` @@ -3684,13 +3572,13 @@ pub fn thread_spawn( pub fn thread_sleep( ctx: FunctionEnvMut<'_, WasiEnv>, duration: __wasi_timestamp_t, -) -> Result { +) -> Result { debug!("wasi::thread_sleep"); let env = ctx.data(); let duration = Duration::from_nanos(duration as u64); env.sleep(duration)?; - Ok(wasi_snapshot0::Errno::Success) + Ok(Errno::Success) } /// ### `thread_id()` @@ -3699,14 +3587,14 @@ pub fn thread_sleep( pub fn thread_id( ctx: FunctionEnvMut<'_, WasiEnv>, ret_tid: WasmPtr<__wasi_tid_t, M>, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!("wasi::thread_id"); let env = ctx.data(); let tid: __wasi_tid_t = env.id.into(); let memory = env.memory_view(&ctx); wasi_try_mem!(ret_tid.write(&memory, tid)); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `thread_join()` @@ -3719,7 +3607,7 @@ pub fn thread_id( pub fn thread_join( ctx: FunctionEnvMut<'_, WasiEnv>, tid: __wasi_tid_t, -) -> Result { +) -> Result { debug!("wasi::thread_join"); let env = ctx.data(); @@ -3735,9 +3623,9 @@ pub fn thread_join( } env.yield_now()?; } - Ok(wasi_snapshot0::Errno::Success) + Ok(Errno::Success) } else { - Ok(wasi_snapshot0::Errno::Success) + Ok(Errno::Success) } } @@ -3747,20 +3635,18 @@ pub fn thread_join( pub fn thread_parallelism( ctx: FunctionEnvMut<'_, WasiEnv>, ret_parallelism: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!("wasi::thread_parallelism"); let env = ctx.data(); let parallelism = wasi_try!(env.runtime().thread_parallelism().map_err(|err| { - let err: wasi_snapshot0::Errno = err.into(); + let err: Errno = err.into(); err })); - let parallelism: M::Offset = wasi_try!(parallelism - .try_into() - .map_err(|_| wasi_snapshot0::Errno::Overflow)); + 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_snapshot0::Errno::Success + Errno::Success } /// ### `getpid()` @@ -3768,7 +3654,7 @@ pub fn thread_parallelism( pub fn getpid( ctx: FunctionEnvMut<'_, WasiEnv>, ret_pid: WasmPtr<__wasi_pid_t, M>, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!("wasi::getpid"); let env = ctx.data(); @@ -3776,9 +3662,9 @@ pub fn 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_snapshot0::Errno::Success + Errno::Success } else { - wasi_snapshot0::Errno::Notsup + Errno::Notsup } } @@ -3794,7 +3680,7 @@ pub fn getpid( pub fn thread_exit( ctx: FunctionEnvMut<'_, WasiEnv>, exitcode: __wasi_exitcode_t, -) -> Result { +) -> Result { debug!("wasi::thread_exit"); Err(WasiError::Exit(exitcode)) } @@ -4232,8 +4118,8 @@ pub fn ws_connect( ctx: FunctionEnvMut<'_, WasiEnv>, url: WasmPtr, url_len: M::Offset, - ret_sock: WasmPtr, -) -> wasi_snapshot0::Errno { + ret_sock: WasmPtr, +) -> Errno { debug!("wasi::ws_connect"); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -4257,14 +4143,13 @@ pub fn ws_connect( "socket".to_string(), ); let rights = super::state::all_socket_rights(); - let fd = - wasi_try!(state - .fs - .create_fd(rights, rights, wasi_snapshot0::Fdflags::empty(), 0, inode)); + let fd = wasi_try!(state + .fs + .create_fd(rights, rights, Fdflags::empty(), 0, inode)); wasi_try_mem!(ret_sock.write(&memory, fd)); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `http_request()` @@ -4293,7 +4178,7 @@ pub fn http_request( headers_len: M::Offset, gzip: __wasi_bool_t, ret_handles: WasmPtr<__wasi_http_handles_t, M>, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!("wasi::http_request"); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -4304,7 +4189,7 @@ pub fn http_request( let gzip = match gzip { __WASI_BOOL_FALSE => false, __WASI_BOOL_TRUE => true, - _ => return wasi_snapshot0::Errno::Inval, + _ => return Errno::Inval, }; let socket = wasi_try!(env @@ -4372,32 +4257,20 @@ pub fn http_request( let rights = super::state::all_socket_rights(); let handles = __wasi_http_handles_t { - req: wasi_try!(state.fs.create_fd( - rights, - rights, - wasi_snapshot0::Fdflags::empty(), - 0, - inode_req - )), - res: wasi_try!(state.fs.create_fd( - rights, - rights, - wasi_snapshot0::Fdflags::empty(), - 0, - inode_res - )), - hdr: wasi_try!(state.fs.create_fd( - rights, - rights, - wasi_snapshot0::Fdflags::empty(), - 0, - inode_hdr - )), + 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_snapshot0::Errno::Success + Errno::Success } /// ### `http_status()` @@ -4410,21 +4283,18 @@ pub fn http_request( /// status of this HTTP request pub fn http_status( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: wasi_snapshot0::Fd, + sock: Fd, status: WasmPtr<__wasi_http_status_t, M>, -) -> wasi_snapshot0::Errno { +) -> 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, - wasi_snapshot0::Rights::empty(), - |socket| { socket.http_status() } - )); + 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 { @@ -4439,7 +4309,7 @@ pub fn http_status( wasi_try_mem!(ref_status.write(status)); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `port_bridge()` @@ -4457,7 +4327,7 @@ pub fn port_bridge( token: WasmPtr, token_len: M::Offset, security: __wasi_streamsecurity_t, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!("wasi::port_bridge"); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -4468,32 +4338,32 @@ pub fn port_bridge( __WASI_STREAM_SECURITY_ANY_ENCRYPTION => StreamSecurity::AnyEncyption, __WASI_STREAM_SECURITY_CLASSIC_ENCRYPTION => StreamSecurity::ClassicEncryption, __WASI_STREAM_SECURITY_DOUBLE_ENCRYPTION => StreamSecurity::DoubleEncryption, - _ => return wasi_snapshot0::Errno::Inval, + _ => return Errno::Inval, }; wasi_try!(env .net() .bridge(network.as_str(), token.as_str(), security) .map_err(net_error_into_wasi_err)); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `port_unbridge()` /// Disconnects from a remote network -pub fn port_unbridge(ctx: FunctionEnvMut<'_, WasiEnv>) -> wasi_snapshot0::Errno { +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_snapshot0::Errno::Success + Errno::Success } /// ### `port_dhcp_acquire()` /// Acquires a set of IP addresses using DHCP -pub fn port_dhcp_acquire(ctx: FunctionEnvMut<'_, WasiEnv>) -> wasi_snapshot0::Errno { +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_snapshot0::Errno::Success + Errno::Success } /// ### `port_addr_add()` @@ -4505,7 +4375,7 @@ pub fn port_dhcp_acquire(ctx: FunctionEnvMut<'_, WasiEnv>) -> wasi_snapshot0::Er pub fn port_addr_add( ctx: FunctionEnvMut<'_, WasiEnv>, ip: WasmPtr<__wasi_cidr_t, M>, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!("wasi::port_addr_add"); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -4514,7 +4384,7 @@ pub fn port_addr_add( .net() .ip_add(cidr.ip, cidr.prefix) .map_err(net_error_into_wasi_err)); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `port_addr_remove()` @@ -4526,22 +4396,22 @@ pub fn port_addr_add( pub fn port_addr_remove( ctx: FunctionEnvMut<'_, WasiEnv>, ip: WasmPtr<__wasi_addr_t, M>, -) -> wasi_snapshot0::Errno { +) -> 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_snapshot0::Errno::Success + Errno::Success } /// ### `port_addr_clear()` /// Clears all the addresses on the local port -pub fn port_addr_clear(ctx: FunctionEnvMut<'_, WasiEnv>) -> wasi_snapshot0::Errno { +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_snapshot0::Errno::Success + Errno::Success } /// ### `port_mac()` @@ -4549,14 +4419,14 @@ pub fn port_addr_clear(ctx: FunctionEnvMut<'_, WasiEnv>) -> wasi_snapshot0::Errn pub fn port_mac( ctx: FunctionEnvMut<'_, WasiEnv>, ret_mac: WasmPtr<__wasi_hardwareaddress_t, M>, -) -> wasi_snapshot0::Errno { +) -> 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_snapshot0::Errno::Success + Errno::Success } /// ### `port_ip_list()` @@ -4576,26 +4446,21 @@ pub fn port_addr_list( ctx: FunctionEnvMut<'_, WasiEnv>, addrs: WasmPtr<__wasi_cidr_t, M>, naddrs: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> 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_snapshot0::Errno::Overflow)); + 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_snapshot0::Errno::Overflow)); + 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_snapshot0::Errno::Overflow; + return Errno::Overflow; } for n in 0..addrs.len() { @@ -4603,7 +4468,7 @@ pub fn port_addr_list( super::state::write_cidr(&memory, nip.as_ptr::(), *addrs.get(n).unwrap()); } - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `port_gateway_set()` @@ -4615,14 +4480,14 @@ pub fn port_addr_list( pub fn port_gateway_set( ctx: FunctionEnvMut<'_, WasiEnv>, ip: WasmPtr<__wasi_addr_t, M>, -) -> wasi_snapshot0::Errno { +) -> 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_snapshot0::Errno::Success + Errno::Success } /// ### `port_route_add()` @@ -4633,7 +4498,7 @@ pub fn port_route_add( via_router: WasmPtr<__wasi_addr_t, M>, preferred_until: WasmPtr<__wasi_option_timestamp_t, M>, expires_at: WasmPtr<__wasi_option_timestamp_t, M>, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!("wasi::port_route_add"); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -4643,20 +4508,20 @@ pub fn port_route_add( let preferred_until = match preferred_until.tag { __WASI_OPTION_NONE => None, __WASI_OPTION_SOME => Some(Duration::from_nanos(preferred_until.u)), - _ => return wasi_snapshot0::Errno::Inval, + _ => 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_snapshot0::Errno::Inval, + _ => return Errno::Inval, }; wasi_try!(env .net() .route_add(cidr, via_router, preferred_until, expires_at) .map_err(net_error_into_wasi_err)); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `port_route_remove()` @@ -4664,22 +4529,22 @@ pub fn port_route_add( pub fn port_route_remove( ctx: FunctionEnvMut<'_, WasiEnv>, ip: WasmPtr<__wasi_addr_t, M>, -) -> wasi_snapshot0::Errno { +) -> 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_snapshot0::Errno::Success + Errno::Success } /// ### `port_route_clear()` /// Clears all the routes in the local port -pub fn port_route_clear(ctx: FunctionEnvMut<'_, WasiEnv>) -> wasi_snapshot0::Errno { +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_snapshot0::Errno::Success + Errno::Success } /// ### `port_route_list()` @@ -4695,25 +4560,22 @@ pub fn port_route_list( ctx: FunctionEnvMut<'_, WasiEnv>, routes: WasmPtr<__wasi_route_t, M>, nroutes: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> 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_snapshot0::Errno::Inval)); + .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_snapshot0::Errno::Inval)); + 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_snapshot0::Errno::Overflow; + return Errno::Overflow; } for n in 0..routes.len() { @@ -4725,7 +4587,7 @@ pub fn port_route_list( ); } - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `sock_shutdown()` @@ -4735,11 +4597,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_snapshot0::Fd, - how: __wasi_sdflags_t, -) -> wasi_snapshot0::Errno { +pub fn sock_shutdown(ctx: FunctionEnvMut<'_, WasiEnv>, sock: Fd, how: __wasi_sdflags_t) -> Errno { debug!("wasi::sock_shutdown"); let both = __WASI_SHUT_RD | __WASI_SHUT_WR; @@ -4747,34 +4605,31 @@ 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_snapshot0::Errno::Inval, + _ => return Errno::Inval, }; wasi_try!(__sock_actor_mut( &ctx, sock, - wasi_snapshot0::Rights::SOCK_SHUTDOWN, + Rights::SOCK_SHUTDOWN, |socket| { socket.shutdown(how) } )); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `sock_status()` /// Returns the current status of a socket pub fn sock_status( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: wasi_snapshot0::Fd, + sock: Fd, ret_status: WasmPtr<__wasi_sockstatus_t, M>, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!("wasi::sock_status"); - let status = wasi_try!(__sock_actor( - &ctx, - sock, - wasi_snapshot0::Rights::empty(), - |socket| { socket.status() } - )); + let status = wasi_try!(__sock_actor(&ctx, sock, Rights::empty(), |socket| { + socket.status() + })); use super::state::WasiSocketStatus; let status = match status { @@ -4788,7 +4643,7 @@ pub fn sock_status( let memory = env.memory_view(&ctx); wasi_try_mem!(ret_status.write(&memory, status)); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `sock_addr_local()` @@ -4804,17 +4659,14 @@ pub fn sock_status( /// * `fd` - Socket that the address is bound to pub fn sock_addr_local( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: wasi_snapshot0::Fd, + sock: Fd, ret_addr: WasmPtr<__wasi_addr_port_t, M>, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!("wasi::sock_addr_local"); - let addr = wasi_try!(__sock_actor( - &ctx, - sock, - wasi_snapshot0::Rights::empty(), - |socket| { socket.addr_local() } - )); + let addr = wasi_try!(__sock_actor(&ctx, sock, Rights::empty(), |socket| { + socket.addr_local() + })); let memory = ctx.data().memory_view(&ctx); wasi_try!(super::state::write_ip_port( &memory, @@ -4822,7 +4674,7 @@ pub fn sock_addr_local( addr.ip(), addr.port() )); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `sock_addr_peer()` @@ -4838,18 +4690,15 @@ pub fn sock_addr_local( /// * `fd` - Socket that the address is bound to pub fn sock_addr_peer( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: wasi_snapshot0::Fd, + sock: Fd, ro_addr: WasmPtr<__wasi_addr_port_t, M>, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!("wasi::sock_addr_peer"); let env = ctx.data(); - let addr = wasi_try!(__sock_actor( - &ctx, - sock, - wasi_snapshot0::Rights::empty(), - |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, @@ -4857,7 +4706,7 @@ pub fn sock_addr_peer( addr.ip(), addr.port() )); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `sock_open()` @@ -4884,8 +4733,8 @@ pub fn sock_open( af: __wasi_addressfamily_t, ty: __wasi_socktype_t, pt: __wasi_sockproto_t, - ro_sock: WasmPtr, -) -> wasi_snapshot0::Errno { + ro_sock: WasmPtr, +) -> Errno { debug!("wasi::sock_open"); let env = ctx.data(); @@ -4909,7 +4758,7 @@ pub fn sock_open( accept_timeout: None, }), }, - _ => return wasi_snapshot0::Errno::Notsup, + _ => return Errno::Notsup, }; let inode = state.fs.create_inode_with_default_stat( @@ -4919,14 +4768,13 @@ pub fn sock_open( "socket".to_string(), ); let rights = super::state::all_socket_rights(); - let fd = - wasi_try!(state - .fs - .create_fd(rights, rights, wasi_snapshot0::Fdflags::empty(), 0, inode)); + let fd = wasi_try!(state + .fs + .create_fd(rights, rights, Fdflags::empty(), 0, inode)); wasi_try_mem!(ro_sock.write(&memory, fd)); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `sock_set_opt_flag()` @@ -4940,26 +4788,23 @@ pub fn sock_open( /// * `flag` - Value to set the option to pub fn sock_set_opt_flag( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: wasi_snapshot0::Fd, + sock: Fd, opt: __wasi_sockoption_t, flag: __wasi_bool_t, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!("wasi::sock_set_opt_flag(ty={})", opt); let flag = match flag { __WASI_BOOL_FALSE => false, __WASI_BOOL_TRUE => true, - _ => return wasi_snapshot0::Errno::Inval, + _ => return Errno::Inval, }; let option: super::state::WasiSocketOption = opt.into(); - wasi_try!(__sock_actor_mut( - &ctx, - sock, - wasi_snapshot0::Rights::empty(), - |socket| { socket.set_opt_flag(option, flag) } - )); - wasi_snapshot0::Errno::Success + wasi_try!(__sock_actor_mut(&ctx, sock, Rights::empty(), |socket| { + socket.set_opt_flag(option, flag) + })); + Errno::Success } /// ### `sock_get_opt_flag()` @@ -4972,21 +4817,18 @@ pub fn sock_set_opt_flag( /// * `sockopt` - Socket option to be retrieved pub fn sock_get_opt_flag( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: wasi_snapshot0::Fd, + sock: Fd, opt: __wasi_sockoption_t, ret_flag: WasmPtr<__wasi_bool_t, M>, -) -> wasi_snapshot0::Errno { +) -> 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, - wasi_snapshot0::Rights::empty(), - |socket| { socket.get_opt_flag(option) } - )); + 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, @@ -4994,7 +4836,7 @@ pub fn sock_get_opt_flag( wasi_try_mem!(ret_flag.write(&memory, flag)); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `sock_set_opt_time()` @@ -5007,10 +4849,10 @@ pub fn sock_get_opt_flag( /// * `time` - Value to set the time to pub fn sock_set_opt_time( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: wasi_snapshot0::Fd, + sock: Fd, opt: __wasi_sockoption_t, time: WasmPtr<__wasi_option_timestamp_t, M>, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!("wasi::sock_set_opt_time(ty={})", opt); let env = ctx.data(); @@ -5019,7 +4861,7 @@ pub fn sock_set_opt_time( let time = match time.tag { __WASI_OPTION_NONE => None, __WASI_OPTION_SOME => Some(Duration::from_nanos(time.u)), - _ => return wasi_snapshot0::Errno::Inval, + _ => return Errno::Inval, }; let ty = match opt { @@ -5028,17 +4870,14 @@ pub fn sock_set_opt_time( __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_snapshot0::Errno::Inval, + _ => return Errno::Inval, }; let option: super::state::WasiSocketOption = opt.into(); - wasi_try!(__sock_actor_mut( - &ctx, - sock, - wasi_snapshot0::Rights::empty(), - |socket| { socket.set_opt_time(ty, time) } - )); - wasi_snapshot0::Errno::Success + wasi_try!(__sock_actor_mut(&ctx, sock, Rights::empty(), |socket| { + socket.set_opt_time(ty, time) + })); + Errno::Success } /// ### `sock_get_opt_time()` @@ -5050,10 +4889,10 @@ pub fn sock_set_opt_time( /// * `sockopt` - Socket option to be retrieved pub fn sock_get_opt_time( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: wasi_snapshot0::Fd, + sock: Fd, opt: __wasi_sockoption_t, ret_time: WasmPtr<__wasi_option_timestamp_t, M>, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!("wasi::sock_get_opt_time(ty={})", opt); let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -5064,15 +4903,12 @@ pub fn sock_get_opt_time( __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_snapshot0::Errno::Inval, + _ => return Errno::Inval, }; - let time = wasi_try!(__sock_actor( - &ctx, - sock, - wasi_snapshot0::Rights::empty(), - |socket| { socket.opt_time(ty) } - )); + 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, @@ -5086,7 +4922,7 @@ pub fn sock_get_opt_time( wasi_try_mem!(ret_time.write(&memory, time)); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `sock_set_opt_size() @@ -5100,10 +4936,10 @@ pub fn sock_get_opt_time( /// * `size` - Buffer size pub fn sock_set_opt_size( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: wasi_snapshot0::Fd, + sock: Fd, opt: __wasi_sockoption_t, size: __wasi_filesize_t, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!("wasi::sock_set_opt_size(ty={})", opt); let ty = match opt { @@ -5112,25 +4948,20 @@ pub fn sock_set_opt_size( __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_snapshot0::Errno::Inval, + _ => return Errno::Inval, }; let option: super::state::WasiSocketOption = opt.into(); - wasi_try!(__sock_actor_mut( - &ctx, - sock, - wasi_snapshot0::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_snapshot0::Errno::Inval), - } + 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(Errno::Inval), } - )); - wasi_snapshot0::Errno::Success + })); + Errno::Success } /// ### `sock_get_opt_size()` @@ -5143,37 +4974,32 @@ pub fn sock_set_opt_size( /// * `sockopt` - Socket option to be retrieved pub fn sock_get_opt_size( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: wasi_snapshot0::Fd, + sock: Fd, opt: __wasi_sockoption_t, ret_size: WasmPtr<__wasi_filesize_t, M>, -) -> wasi_snapshot0::Errno { +) -> 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, - wasi_snapshot0::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_snapshot0::Errno::Inval), + 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(Errno::Inval), } - )); + })); wasi_try_mem!(ret_size.write(&memory, size)); - wasi_snapshot0::Errno::Success + Errno::Success } /// ### `sock_join_multicast_v4()` @@ -5186,23 +5012,20 @@ pub fn sock_get_opt_size( /// * `interface` - Interface that will join pub fn sock_join_multicast_v4( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: wasi_snapshot0::Fd, + sock: Fd, multiaddr: WasmPtr<__wasi_addr_ip4_t, M>, iface: WasmPtr<__wasi_addr_ip4_t, M>, -) -> wasi_snapshot0::Errno { +) -> 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, - wasi_snapshot0::Rights::empty(), - |socket| { socket.join_multicast_v4(multiaddr, iface) } - )); - wasi_snapshot0::Errno::Success + wasi_try!(__sock_actor_mut(&ctx, sock, Rights::empty(), |socket| { + socket.join_multicast_v4(multiaddr, iface) + })); + Errno::Success } /// ### `sock_leave_multicast_v4()` @@ -5215,23 +5038,20 @@ pub fn sock_join_multicast_v4( /// * `interface` - Interface that will left pub fn sock_leave_multicast_v4( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: wasi_snapshot0::Fd, + sock: Fd, multiaddr: WasmPtr<__wasi_addr_ip4_t, M>, iface: WasmPtr<__wasi_addr_ip4_t, M>, -) -> wasi_snapshot0::Errno { +) -> 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, - wasi_snapshot0::Rights::empty(), - |socket| { socket.leave_multicast_v4(multiaddr, iface) } - )); - wasi_snapshot0::Errno::Success + wasi_try!(__sock_actor_mut(&ctx, sock, Rights::empty(), |socket| { + socket.leave_multicast_v4(multiaddr, iface) + })); + Errno::Success } /// ### `sock_join_multicast_v6()` @@ -5244,22 +5064,19 @@ pub fn sock_leave_multicast_v4( /// * `interface` - Interface that will join pub fn sock_join_multicast_v6( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: wasi_snapshot0::Fd, + sock: Fd, multiaddr: WasmPtr<__wasi_addr_ip6_t, M>, iface: u32, -) -> wasi_snapshot0::Errno { +) -> 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, - wasi_snapshot0::Rights::empty(), - |socket| { socket.join_multicast_v6(multiaddr, iface) } - )); - wasi_snapshot0::Errno::Success + wasi_try!(__sock_actor_mut(&ctx, sock, Rights::empty(), |socket| { + socket.join_multicast_v6(multiaddr, iface) + })); + Errno::Success } /// ### `sock_leave_multicast_v6()` @@ -5272,22 +5089,19 @@ pub fn sock_join_multicast_v6( /// * `interface` - Interface that will left pub fn sock_leave_multicast_v6( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: wasi_snapshot0::Fd, + sock: Fd, multiaddr: WasmPtr<__wasi_addr_ip6_t, M>, iface: u32, -) -> wasi_snapshot0::Errno { +) -> 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, - wasi_snapshot0::Rights::empty(), - |socket| { socket.leave_multicast_v6(multiaddr, iface) } - )); - wasi_snapshot0::Errno::Success + wasi_try!(__sock_actor_mut(&ctx, sock, Rights::empty(), |socket| { + socket.leave_multicast_v6(multiaddr, iface) + })); + Errno::Success } /// ### `sock_bind()` @@ -5300,22 +5114,19 @@ pub fn sock_leave_multicast_v6( /// * `addr` - Address to bind the socket to pub fn sock_bind( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: wasi_snapshot0::Fd, + sock: Fd, addr: WasmPtr<__wasi_addr_port_t, M>, -) -> wasi_snapshot0::Errno { +) -> 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_snapshot0::Rights::SOCK_BIND, - |socket| { socket.bind(env.net(), addr) } - )); - wasi_snapshot0::Errno::Success + wasi_try!(__sock_upgrade(&ctx, sock, Rights::SOCK_BIND, |socket| { + socket.bind(env.net(), addr) + })); + Errno::Success } /// ### `sock_listen()` @@ -5332,20 +5143,17 @@ pub fn sock_bind( /// * `backlog` - Maximum size of the queue for pending connections pub fn sock_listen( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: wasi_snapshot0::Fd, + sock: Fd, backlog: M::Offset, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!("wasi::sock_listen"); let env = ctx.data(); - let backlog: usize = wasi_try!(backlog.try_into().map_err(|_| wasi_snapshot0::Errno::Inval)); - wasi_try!(__sock_upgrade( - &ctx, - sock, - wasi_snapshot0::Rights::SOCK_BIND, - |socket| { socket.listen(env.net(), backlog) } - )); - wasi_snapshot0::Errno::Success + 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()` @@ -5362,11 +5170,11 @@ pub fn sock_listen( /// New socket connection pub fn sock_accept( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: wasi_snapshot0::Fd, - fd_flags: wasi_snapshot0::Fdflags, - ro_fd: WasmPtr, + sock: Fd, + fd_flags: Fdflags, + ro_fd: WasmPtr, ro_addr: WasmPtr<__wasi_addr_port_t, M>, -) -> Result { +) -> Result { debug!("wasi::sock_accept"); let env = ctx.data(); @@ -5374,26 +5182,25 @@ pub fn sock_accept( let mut ret; let (_, state) = env.get_memory_and_wasi_state(&ctx, 0); loop { - wasi_try_ok!(match __sock_actor( - &ctx, - sock, - wasi_snapshot0::Rights::SOCK_ACCEPT, - |socket| socket.accept_timeout(fd_flags, Duration::from_millis(5)) - ) { - Ok(a) => { - ret = a; - break; - } - Err(wasi_snapshot0::Errno::Timedout) => { - env.yield_now()?; - continue; - } - Err(wasi_snapshot0::Errno::Again) => { - env.sleep(Duration::from_millis(5))?; - continue; + wasi_try_ok!( + match __sock_actor(&ctx, sock, Rights::SOCK_ACCEPT, |socket| socket + .accept_timeout(fd_flags, Duration::from_millis(5))) + { + Ok(a) => { + ret = a; + break; + } + Err(Errno::Timedout) => { + env.yield_now()?; + continue; + } + Err(Errno::Again) => { + env.sleep(Duration::from_millis(5))?; + continue; + } + Err(err) => Err(err), } - Err(err) => Err(err), - }); + ); } ret }; @@ -5411,13 +5218,9 @@ pub fn sock_accept( ); let rights = super::state::all_socket_rights(); - let fd = wasi_try_ok!(state.fs.create_fd( - rights, - rights, - wasi_snapshot0::Fdflags::empty(), - 0, - inode - )); + 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( @@ -5427,7 +5230,7 @@ pub fn sock_accept( addr.port() )); - Ok(wasi_snapshot0::Errno::Success) + Ok(Errno::Success) } /// ### `sock_connect()` @@ -5444,22 +5247,19 @@ pub fn sock_accept( /// * `addr` - Address of the socket to connect to pub fn sock_connect( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: wasi_snapshot0::Fd, + sock: Fd, addr: WasmPtr<__wasi_addr_port_t, M>, -) -> wasi_snapshot0::Errno { +) -> 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_snapshot0::Rights::SOCK_CONNECT, - |socket| { socket.connect(env.net(), addr) } - )); - wasi_snapshot0::Errno::Success + wasi_try!(__sock_upgrade(&ctx, sock, Rights::SOCK_CONNECT, |socket| { + socket.connect(env.net(), addr) + })); + Errno::Success } /// ### `sock_recv()` @@ -5477,33 +5277,28 @@ pub fn sock_connect( /// Number of bytes stored in ri_data and message flags. pub fn sock_recv( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: wasi_snapshot0::Fd, + sock: Fd, ri_data: WasmPtr<__wasi_iovec_t, M>, ri_data_len: M::Offset, _ri_flags: __wasi_riflags_t, ro_data_len: WasmPtr, ro_flags: WasmPtr<__wasi_roflags_t, M>, -) -> Result { +) -> 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_snapshot0::Rights::SOCK_RECV, - |socket| { socket.recv(&memory, iovs_arr) } - )); - let bytes_read: M::Offset = wasi_try_ok!(bytes_read - .try_into() - .map_err(|_| wasi_snapshot0::Errno::Overflow)); + 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_snapshot0::Errno::Success) + Ok(Errno::Success) } /// ### `sock_recv_from()` @@ -5521,14 +5316,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_snapshot0::Fd, + sock: Fd, ri_data: WasmPtr<__wasi_iovec_t, M>, ri_data_len: M::Offset, _ri_flags: __wasi_riflags_t, ro_data_len: WasmPtr, ro_flags: WasmPtr<__wasi_roflags_t, M>, ro_addr: WasmPtr<__wasi_addr_port_t, M>, -) -> Result { +) -> Result { debug!("wasi::sock_recv_from"); let env = ctx.data(); @@ -5538,17 +5333,15 @@ pub fn sock_recv_from( let bytes_read = wasi_try_ok!(__sock_actor_mut( &ctx, sock, - wasi_snapshot0::Rights::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_snapshot0::Errno::Overflow)); + 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_snapshot0::Errno::Success) + Ok(Errno::Success) } /// ### `sock_send()` @@ -5566,31 +5359,27 @@ pub fn sock_recv_from( /// Number of bytes transmitted. pub fn sock_send( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: wasi_snapshot0::Fd, + sock: Fd, si_data: WasmPtr<__wasi_ciovec_t, M>, si_data_len: M::Offset, _si_flags: __wasi_siflags_t, ret_data_len: WasmPtr, -) -> Result { +) -> 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_snapshot0::Rights::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_snapshot0::Errno::Overflow)); + let bytes_written: M::Offset = + wasi_try_ok!(bytes_written.try_into().map_err(|_| Errno::Overflow)); wasi_try_mem_ok!(ret_data_len.write(&memory, bytes_written)); - Ok(wasi_snapshot0::Errno::Success) + Ok(Errno::Success) } /// ### `sock_send_to()` @@ -5609,13 +5398,13 @@ pub fn sock_send( /// Number of bytes transmitted. pub fn sock_send_to( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: wasi_snapshot0::Fd, + sock: Fd, si_data: WasmPtr<__wasi_ciovec_t, M>, si_data_len: M::Offset, _si_flags: __wasi_siflags_t, addr: WasmPtr<__wasi_addr_port_t, M>, ret_data_len: WasmPtr, -) -> Result { +) -> Result { debug!("wasi::sock_send_to"); let env = ctx.data(); @@ -5625,16 +5414,15 @@ pub fn sock_send_to( let bytes_written = wasi_try_ok!(__sock_actor_mut( &ctx, sock, - wasi_snapshot0::Rights::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_snapshot0::Errno::Overflow)); + let bytes_written: M::Offset = + 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_snapshot0::Errno::Success) + Ok(Errno::Success) } /// ### `sock_send_file()` @@ -5651,12 +5439,12 @@ pub fn sock_send_to( /// Number of bytes transmitted. pub unsafe fn sock_send_file( mut ctx: FunctionEnvMut<'_, WasiEnv>, - sock: wasi_snapshot0::Fd, - in_fd: wasi_snapshot0::Fd, + sock: Fd, + in_fd: Fd, offset: __wasi_filesize_t, mut count: __wasi_filesize_t, ret_sent: WasmPtr<__wasi_filesize_t, M>, -) -> Result { +) -> Result { debug!("wasi::send_file"); let env = ctx.data(); let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0); @@ -5664,7 +5452,7 @@ 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_snapshot0::Errno::Badf)); + let fd_entry = wasi_try_ok!(fd_map.get_mut(&in_fd).ok_or(Errno::Badf)); fd_entry.offset = offset as u64; } @@ -5687,14 +5475,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_snapshot0::Errno::Badf); + return Ok(Errno::Badf); } } - __WASI_STDOUT_FILENO | __WASI_STDERR_FILENO => return Ok(wasi_snapshot0::Errno::Inval), + __WASI_STDOUT_FILENO | __WASI_STDERR_FILENO => return Ok(Errno::Inval), _ => { - if !fd_entry.rights.contains(wasi_snapshot0::Rights::FD_READ) { + if !fd_entry.rights.contains(Rights::FD_READ) { // TODO: figure out the error to return when lacking rights - return Ok(wasi_snapshot0::Errno::Acces); + return Ok(Errno::Access); } let offset = fd_entry.offset as usize; @@ -5715,7 +5503,7 @@ pub unsafe fn sock_send_file( ); wasi_try_ok!(handle.read(&mut buf).map_err(map_io_err)) } else { - return Ok(wasi_snapshot0::Errno::Inval); + return Ok(Errno::Inval); } } Kind::Socket { socket } => { @@ -5725,10 +5513,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_snapshot0::Errno::Isdir); + return Ok(Errno::Isdir); } Kind::EventNotifications { .. } => { - return Ok(wasi_snapshot0::Errno::Inval); + return Ok(Errno::Inval); } Kind::Symlink { .. } => unimplemented!("Symlinks in wasi::fd_read"), Kind::Buffer { buffer } => { @@ -5740,8 +5528,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_snapshot0::Errno::Badf)); + 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 @@ -5749,21 +5536,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_snapshot0::Rights::SOCK_SEND, - |socket| { + 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)); - Ok(wasi_snapshot0::Errno::Success) + Ok(Errno::Success) } /// ### `resolve()` @@ -5792,10 +5575,10 @@ pub fn resolve( addrs: WasmPtr<__wasi_addr_t, M>, naddrs: M::Offset, ret_naddrs: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { debug!("wasi::resolve"); - let naddrs: usize = wasi_try!(naddrs.try_into().map_err(|_| wasi_snapshot0::Errno::Inval)); + 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) }; @@ -5814,8 +5597,8 @@ pub fn resolve( idx += 1; } - let idx: M::Offset = wasi_try!(idx.try_into().map_err(|_| wasi_snapshot0::Errno::Overflow)); + let idx: M::Offset = wasi_try!(idx.try_into().map_err(|_| Errno::Overflow)); wasi_try_mem!(ret_naddrs.write(&memory, idx)); - wasi_snapshot0::Errno::Success + Errno::Success } From 005b05d1cac6c9f758f4692232206d6c1b364176 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Fri, 19 Aug 2022 14:22:00 +0200 Subject: [PATCH 20/84] Sauhaufen! --- lib/wasi-types-generated/regenerate.sh | 5 + lib/wasi-types-generated/src/lib.rs | 4 +- lib/wasi-types-generated/src/wasi/bindings.rs | 1105 +++++++++++++++++ lib/wasi-types-generated/src/wasi/mod.rs | 0 .../src/wasi_io_typenames/bindings.rs | 787 ------------ .../src/wasi_snapshot0/bindings.rs | 860 ------------- .../wit/wasi-io-typenames.wit | 518 -------- .../wit/wasi-snapshot0.wit | 511 -------- lib/wasi-types-generated/wit/wasi.wit | 721 +++++++++++ 9 files changed, 1834 insertions(+), 2677 deletions(-) create mode 100644 lib/wasi-types-generated/src/wasi/bindings.rs create mode 100644 lib/wasi-types-generated/src/wasi/mod.rs create mode 100644 lib/wasi-types-generated/wit/wasi.wit diff --git a/lib/wasi-types-generated/regenerate.sh b/lib/wasi-types-generated/regenerate.sh index 4aa2a046f4e..ac5748ec826 100755 --- a/lib/wasi-types-generated/regenerate.sh +++ b/lib/wasi-types-generated/regenerate.sh @@ -6,6 +6,11 @@ rm -f \ "$BASEDIR"/src/bindings.rs \ "$BASEDIR"/src/*/bindings.rs +wit-bindgen wasmer \ + --import \ + "$BASEDIR"/wit/wasi.wit \ + --out-dir "$BASEDIR"/src/wasi + wit-bindgen wasmer \ --import \ "$BASEDIR"/wit/wasi-filesystem.wit \ diff --git a/lib/wasi-types-generated/src/lib.rs b/lib/wasi-types-generated/src/lib.rs index 6df96306a6a..7135f8e6af2 100644 --- a/lib/wasi-types-generated/src/lib.rs +++ b/lib/wasi-types-generated/src/lib.rs @@ -1,3 +1,5 @@ +pub mod wasi; pub mod wasi_filesystem; pub mod wasi_io_typenames; -pub mod wasi_snapshot0; + +pub mod wasi_snapshot0 {} diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs new file mode 100644 index 00000000000..b751a16b61d --- /dev/null +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -0,0 +1,1105 @@ +#[allow(clippy::all)] +pub mod wasi { + #[allow(unused_imports)] + use wit_bindgen_wasmer::{anyhow, wasmer}; + /// 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; + /// 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{} + wit_bindgen_wasmer::bitflags::bitflags! { + /// File descriptor rights, determining which actions may be performed, snapshot0 version. + pub struct Snapshot0Rights: 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 core::fmt::Display for Snapshot0Rights{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("Snapshot0Rights(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(())} + } + + wit_bindgen_wasmer::bitflags::bitflags! { + /// File descriptor rights, determining which actions may be performed. + pub struct Rights: u32 {/// The right to invoke `fd_datasync`. + /// + /// If `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 `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 `path_open` is set, the right to invoke `path_open` with `oflags::create`. + 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. + /// If `path_open` is set, includes the right to invoke `path_open` with `oflags::trunc`. + /// Note: there is no function named `path_filestat_set_size`. This follows POSIX design, + /// which only has `ftruncate` and does not provide `ftruncateat`. + /// While such function would be desirable from the API design perspective, there are virtually + /// no use cases for it since no code written for POSIX systems would use it. + /// Moreover, implementing it would require multiple syscalls, leading to inferior performance. + 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 `path_permissions_set`. + const PATH_PERMISSIONS_SET = 1 << 21; + /// The right to invoke `fd_filestat_get`. + const FD_FILESTAT_GET = 1 << 22; + /// The right to invoke `fd_filestat_set_size`. + const FD_FILESTAT_SET_SIZE = 1 << 23; + /// The right to invoke `fd_filestat_set_times`. + const FD_FILESTAT_SET_TIMES = 1 << 24; + /// The right to invoke `fd_permissions_set`. + const FD_PERMISSIONS_SET = 1 << 25; + /// The right to invoke `path_symlink`. + const PATH_SYMLINK = 1 << 26; + /// The right to invoke `path_remove_directory`. + const PATH_REMOVE_DIRECTORY = 1 << 27; + /// The right to invoke `path_unlink_file`. + const PATH_UNLINK_FILE = 1 << 28; + /// 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 << 29; + /// The right to invoke `sock_shutdown`. + const SOCK_SHUTDOWN = 1 << 30; + } + } + + impl core::fmt::Display for Rights{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("Rights(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(())} + } + + /// The type of a file descriptor or file. + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum Snapshot0Filetype { + /// 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, + } + impl core::fmt::Debug for Snapshot0Filetype { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Snapshot0Filetype::Unknown => { + f.debug_tuple("Snapshot0Filetype::Unknown").finish() + } + Snapshot0Filetype::BlockDevice => { + f.debug_tuple("Snapshot0Filetype::BlockDevice").finish() + } + Snapshot0Filetype::CharacterDevice => { + f.debug_tuple("Snapshot0Filetype::CharacterDevice").finish() + } + Snapshot0Filetype::Directory => { + f.debug_tuple("Snapshot0Filetype::Directory").finish() + } + Snapshot0Filetype::RegularFile => { + f.debug_tuple("Snapshot0Filetype::RegularFile").finish() + } + Snapshot0Filetype::SocketDgram => { + f.debug_tuple("Snapshot0Filetype::SocketDgram").finish() + } + Snapshot0Filetype::SocketStream => { + f.debug_tuple("Snapshot0Filetype::SocketStream").finish() + } + Snapshot0Filetype::SymbolicLink => { + f.debug_tuple("Snapshot0Filetype::SymbolicLink").finish() + } + } + } + } + /// 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. + #[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_wasmer::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 core::fmt::Display for Fdflags{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("Fdflags(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(())} + } + + /// 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_wasmer::bitflags::bitflags! { + /// Which file time attributes to adjust. + pub struct Fstflags: u8 {/// Adjust the last data access timestamp to the value stored in `filestat::atim`. + const ATIM = 1 << 0; + /// Adjust the last data access timestamp to the time of clock `clockid::realtime`. + const ATIM_NOW = 1 << 1; + /// Adjust the last data modification timestamp to the value stored in `filestat::mtim`. + const MTIM = 1 << 2; + /// Adjust the last data modification timestamp to the time of clock `clockid::realtime`. + const MTIM_NOW = 1 << 3; + } + } + + impl core::fmt::Display for Fstflags{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("Fstflags(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(())} + } + + wit_bindgen_wasmer::bitflags::bitflags! { + /// Flags determining the method of how paths are resolved. + pub struct Lookup: u8 {/// As long as the resolved path corresponds to a symbolic link, it is expanded. + const SYMLINK_FOLLOW = 1 << 0; + } + } + + impl core::fmt::Display for Lookup{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("Lookup(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(())} + } + + wit_bindgen_wasmer::bitflags::bitflags! { + /// Open flags used by `path_open`. + 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 core::fmt::Display for Oflags{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("Oflags(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(())} + } + + /// 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_wasmer::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 core::fmt::Display for Subclockflags{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("Subclockflags(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(())} + } + + /// 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 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("id", &self.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_wasmer::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 core::fmt::Display for Eventrwflags{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("Eventrwflags(")?; + core::fmt::Debug::fmt(self, f)?; + f.write_str(" (0x")?; + core::fmt::LowerHex::fmt(&self.bits, f)?; + f.write_str("))")?; + Ok(())} + } + + + /// Auxiliary data associated with the wasm exports. + #[derive(Default)] + pub struct WasiData { + } + + pub struct Wasi { + #[allow(dead_code)] + env: wasmer::FunctionEnv, + func_dirent_dummy_func: wasmer::TypedFunction<(i64,i64,i32,i32,), ()>, + func_fd_dummy_func: wasmer::TypedFunction, + func_fdstat_dummy_func: wasmer::TypedFunction<(i32,i32,i32,i32,), ()>, + func_subscription_clock_dummy_func: wasmer::TypedFunction<(i32,i64,i64,i32,), ()>, + } + impl Wasi { + #[allow(unused_variables)] + + /// Adds any intrinsics, if necessary for this exported wasm + /// functionality to the `ImportObject` provided. + /// + /// This function returns the `WasiData` which needs to be + /// passed through to `Wasi::new`. + fn add_to_imports( + mut store: impl wasmer::AsStoreMut, + imports: &mut wasmer::Imports, + ) -> wasmer::FunctionEnv { + let env = wasmer::FunctionEnv::new(&mut store, WasiData::default()); + env + } + + /// Instantiates the provided `module` using the specified + /// parameters, wrapping up the result in a structure that + /// translates between wasm and the host. + /// + /// The `imports` provided will have intrinsics added to it + /// automatically, so it's not necessary to call + /// `add_to_imports` beforehand. This function will + /// instantiate the `module` otherwise using `imports`, and + /// both an instance of this structure and the underlying + /// `wasmer::Instance` will be returned. + pub fn instantiate( + mut store: impl wasmer::AsStoreMut, + module: &wasmer::Module, + imports: &mut wasmer::Imports, + ) -> anyhow::Result<(Self, wasmer::Instance)> { + let env = Self::add_to_imports(&mut store, imports); + let instance = wasmer::Instance::new( + &mut store, module, &*imports)?; + + Ok((Self::new(store, &instance, env)?, instance)) + } + + /// Low-level creation wrapper for wrapping up the exports + /// of the `instance` provided in this structure of wasm + /// exports. + /// + /// This function will extract exports from the `instance` + /// and wrap them all up in the returned structure which can + /// be used to interact with the wasm module. + pub fn new( + store: impl wasmer::AsStoreMut, + _instance: &wasmer::Instance, + env: wasmer::FunctionEnv, + ) -> Result { + let func_dirent_dummy_func= _instance.exports.get_typed_function(&store, "dirent-dummy-func")?; + let func_fd_dummy_func= _instance.exports.get_typed_function(&store, "fd-dummy-func")?; + let func_fdstat_dummy_func= _instance.exports.get_typed_function(&store, "fdstat-dummy-func")?; + let func_subscription_clock_dummy_func= _instance.exports.get_typed_function(&store, "subscription-clock-dummy-func")?; + Ok(Wasi{ + func_dirent_dummy_func, + func_fd_dummy_func, + func_fdstat_dummy_func, + func_subscription_clock_dummy_func, + env, + }) + } + /// Dummy function to expose type into generated code + pub fn fd_dummy_func(&self, store: &mut wasmer::Store,dummy: Fd,)-> Result<(), wasmer::RuntimeError> { + self.func_fd_dummy_func.call(store, wit_bindgen_wasmer::rt::as_i32(dummy), )?; + Ok(()) + } + /// Dummy function to expose type into generated code + pub fn dirent_dummy_func(&self, store: &mut wasmer::Store,dummy: Dirent,)-> Result<(), wasmer::RuntimeError> { + let Dirent{ d_next:d_next0, d_ino:d_ino0, d_type:d_type0, d_namlen:d_namlen0, } = dummy; + self.func_dirent_dummy_func.call(store, wit_bindgen_wasmer::rt::as_i64(d_next0), wit_bindgen_wasmer::rt::as_i64(d_ino0), d_type0 as i32, wit_bindgen_wasmer::rt::as_i32(d_namlen0), )?; + Ok(()) + } + /// Dummy function to expose type into generated code + pub fn fdstat_dummy_func(&self, store: &mut wasmer::Store,dummy: Fdstat,)-> Result<(), wasmer::RuntimeError> { + let Fdstat{ fs_filetype:fs_filetype0, fs_flags:fs_flags0, fs_rights_base:fs_rights_base0, fs_rights_inheriting:fs_rights_inheriting0, } = dummy; + let flags1 = fs_flags0; + let flags2 = fs_rights_base0; + let flags3 = fs_rights_inheriting0; + self.func_fdstat_dummy_func.call(store, fs_filetype0 as i32, (flags1.bits >> 0) as i32, (flags2.bits >> 0) as i32, (flags3.bits >> 0) as i32, )?; + Ok(()) + } + /// Dummy function to expose type into generated code + pub fn subscription_clock_dummy_func(&self, store: &mut wasmer::Store,dummy: SubscriptionClock,)-> Result<(), wasmer::RuntimeError> { + let SubscriptionClock{ id:id0, timeout:timeout0, precision:precision0, flags:flags0, } = dummy; + let flags1 = flags0; + self.func_subscription_clock_dummy_func.call(store, id0 as i32, wit_bindgen_wasmer::rt::as_i64(timeout0), wit_bindgen_wasmer::rt::as_i64(precision0), (flags1.bits >> 0) as i32, )?; + Ok(()) + } + } + #[allow(unused_imports)] + use wasmer::AsStoreMut as _; + #[allow(unused_imports)] + use wasmer::AsStoreRef as _; +} diff --git a/lib/wasi-types-generated/src/wasi/mod.rs b/lib/wasi-types-generated/src/wasi/mod.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/lib/wasi-types-generated/src/wasi_io_typenames/bindings.rs b/lib/wasi-types-generated/src/wasi_io_typenames/bindings.rs index eb2d042c284..5ee86fb0339 100644 --- a/lib/wasi-types-generated/src/wasi_io_typenames/bindings.rs +++ b/lib/wasi-types-generated/src/wasi_io_typenames/bindings.rs @@ -2,793 +2,6 @@ pub mod wasi_io_typenames { #[allow(unused_imports)] use wit_bindgen_wasmer::{anyhow, wasmer}; - /// Timestamp in nanoseconds. - pub type Timestamp = u64; - /// 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{} - wit_bindgen_wasmer::bitflags::bitflags! { - /// File descriptor rights, determining which actions may be performed. - pub struct Rights: u32 {/// The right to invoke `fd_datasync`. - /// - /// If `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 `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 `path_open` is set, the right to invoke `path_open` with `oflags::create`. - 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. - /// If `path_open` is set, includes the right to invoke `path_open` with `oflags::trunc`. - /// Note: there is no function named `path_filestat_set_size`. This follows POSIX design, - /// which only has `ftruncate` and does not provide `ftruncateat`. - /// While such function would be desirable from the API design perspective, there are virtually - /// no use cases for it since no code written for POSIX systems would use it. - /// Moreover, implementing it would require multiple syscalls, leading to inferior performance. - 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 `path_permissions_set`. - const PATH_PERMISSIONS_SET = 1 << 21; - /// The right to invoke `fd_filestat_get`. - const FD_FILESTAT_GET = 1 << 22; - /// The right to invoke `fd_filestat_set_size`. - const FD_FILESTAT_SET_SIZE = 1 << 23; - /// The right to invoke `fd_filestat_set_times`. - const FD_FILESTAT_SET_TIMES = 1 << 24; - /// The right to invoke `fd_permissions_set`. - const FD_PERMISSIONS_SET = 1 << 25; - /// The right to invoke `path_symlink`. - const PATH_SYMLINK = 1 << 26; - /// The right to invoke `path_remove_directory`. - const PATH_REMOVE_DIRECTORY = 1 << 27; - /// The right to invoke `path_unlink_file`. - const PATH_UNLINK_FILE = 1 << 28; - /// 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 << 29; - /// The right to invoke `sock_shutdown`. - const SOCK_SHUTDOWN = 1 << 30; - } - } - - impl core::fmt::Display for Rights{ - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("Rights(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(())} - } - - /// A file descriptor handle. - pub type Fd = u32; - /// 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() - } - } - } - } - /// 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_wasmer::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 core::fmt::Display for Fdflags{ - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("Fdflags(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(())} - } - - /// 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()} - } - /// 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_wasmer::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 core::fmt::Display for Subclockflags{ - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("Subclockflags(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(())} - } - - /// 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 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("id", &self.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() - } - } - } - } - - /// Auxiliary data associated with the wasm exports. - #[derive(Default)] - pub struct WasiIoTypenamesData { - } - - pub struct WasiIoTypenames { - #[allow(dead_code)] - env: wasmer::FunctionEnv, - func_fd_dummy_func: wasmer::TypedFunction, - func_fdstat_dummy_func: wasmer::TypedFunction<(i32,i32,i32,i32,), ()>, - func_subscription_clock_dummy_func: wasmer::TypedFunction<(i32,i64,i64,i32,), ()>, - } - impl WasiIoTypenames { - #[allow(unused_variables)] - - /// Adds any intrinsics, if necessary for this exported wasm - /// functionality to the `ImportObject` provided. - /// - /// This function returns the `WasiIoTypenamesData` which needs to be - /// passed through to `WasiIoTypenames::new`. - fn add_to_imports( - mut store: impl wasmer::AsStoreMut, - imports: &mut wasmer::Imports, - ) -> wasmer::FunctionEnv { - let env = wasmer::FunctionEnv::new(&mut store, WasiIoTypenamesData::default()); - env - } - - /// Instantiates the provided `module` using the specified - /// parameters, wrapping up the result in a structure that - /// translates between wasm and the host. - /// - /// The `imports` provided will have intrinsics added to it - /// automatically, so it's not necessary to call - /// `add_to_imports` beforehand. This function will - /// instantiate the `module` otherwise using `imports`, and - /// both an instance of this structure and the underlying - /// `wasmer::Instance` will be returned. - pub fn instantiate( - mut store: impl wasmer::AsStoreMut, - module: &wasmer::Module, - imports: &mut wasmer::Imports, - ) -> anyhow::Result<(Self, wasmer::Instance)> { - let env = Self::add_to_imports(&mut store, imports); - let instance = wasmer::Instance::new( - &mut store, module, &*imports)?; - - Ok((Self::new(store, &instance, env)?, instance)) - } - - /// Low-level creation wrapper for wrapping up the exports - /// of the `instance` provided in this structure of wasm - /// exports. - /// - /// This function will extract exports from the `instance` - /// and wrap them all up in the returned structure which can - /// be used to interact with the wasm module. - pub fn new( - store: impl wasmer::AsStoreMut, - _instance: &wasmer::Instance, - env: wasmer::FunctionEnv, - ) -> Result { - let func_fd_dummy_func= _instance.exports.get_typed_function(&store, "fd-dummy-func")?; - let func_fdstat_dummy_func= _instance.exports.get_typed_function(&store, "fdstat-dummy-func")?; - let func_subscription_clock_dummy_func= _instance.exports.get_typed_function(&store, "subscription-clock-dummy-func")?; - Ok(WasiIoTypenames{ - func_fd_dummy_func, - func_fdstat_dummy_func, - func_subscription_clock_dummy_func, - env, - }) - } - /// Dummy function to expose type into generated code - pub fn subscription_clock_dummy_func(&self, store: &mut wasmer::Store,dummy: SubscriptionClock,)-> Result<(), wasmer::RuntimeError> { - let SubscriptionClock{ id:id0, timeout:timeout0, precision:precision0, flags:flags0, } = dummy; - let flags1 = flags0; - self.func_subscription_clock_dummy_func.call(store, id0 as i32, wit_bindgen_wasmer::rt::as_i64(timeout0), wit_bindgen_wasmer::rt::as_i64(precision0), (flags1.bits >> 0) as i32, )?; - Ok(()) - } - pub fn fd_dummy_func(&self, store: &mut wasmer::Store,dummy: Fd,)-> Result<(), wasmer::RuntimeError> { - self.func_fd_dummy_func.call(store, wit_bindgen_wasmer::rt::as_i32(dummy), )?; - Ok(()) - } - pub fn fdstat_dummy_func(&self, store: &mut wasmer::Store,dummy: Fdstat,)-> Result<(), wasmer::RuntimeError> { - let Fdstat{ fs_filetype:fs_filetype0, fs_flags:fs_flags0, fs_rights_base:fs_rights_base0, fs_rights_inheriting:fs_rights_inheriting0, } = dummy; - let flags1 = fs_flags0; - let flags2 = fs_rights_base0; - let flags3 = fs_rights_inheriting0; - self.func_fdstat_dummy_func.call(store, fs_filetype0 as i32, (flags1.bits >> 0) as i32, (flags2.bits >> 0) as i32, (flags3.bits >> 0) as i32, )?; - Ok(()) - } - } #[allow(unused_imports)] use wasmer::AsStoreMut as _; #[allow(unused_imports)] diff --git a/lib/wasi-types-generated/src/wasi_snapshot0/bindings.rs b/lib/wasi-types-generated/src/wasi_snapshot0/bindings.rs index 7853da525ce..28de26091a2 100644 --- a/lib/wasi-types-generated/src/wasi_snapshot0/bindings.rs +++ b/lib/wasi-types-generated/src/wasi_snapshot0/bindings.rs @@ -2,866 +2,6 @@ pub mod wasi_snapshot0 { #[allow(unused_imports)] use wit_bindgen_wasmer::{anyhow, wasmer}; - /// 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() - } - } - } - } - /// Timestamp in nanoseconds. - pub type Timestamp = u64; - /// 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, - /// 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 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() - } - Clockid::ProcessCputimeId => { - f.debug_tuple("Clockid::ProcessCputimeId").finish() - } - Clockid::ThreadCputimeId => { - f.debug_tuple("Clockid::ThreadCputimeId").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. - Acces, - /// 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::Acces => "acces", - 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::Acces => "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{} - wit_bindgen_wasmer::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, but not in wasi-snapshot0 - const SOCK_ACCEPT = 1 << 29; - /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 - const SOCK_CONNECT = 1 << 30; - /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 - const SOCK_LISTEN = 1 << 31; - /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 - const SOCK_BIND = 1 << 32; - /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 - const SOCK_RECV = 1 << 33; - /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 - const SOCK_SEND = 1 << 34; - /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 - const SOCK_ADDR_LOCAL = 1 << 35; - /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 - const SOCK_ADDR_REMOTE = 1 << 36; - /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 - const SOCK_RECV_FROM = 1 << 37; - /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 - const SOCK_SEND_TO = 1 << 38; - } - } - - impl core::fmt::Display for Rights{ - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("Rights(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(())} - } - - /// 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; - /// 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, - } - 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() - } - } - } - } - /// 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 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 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-namlen", &self.d_namlen).field("d-type", &self.d_type).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_wasmer::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 core::fmt::Display for Fdflags{ - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("Fdflags(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(())} - } - - /// 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()} - } - /// User-provided value that may be attached to objects that is retained when - /// extracted from the implementation. - pub type Userdata = u64; - wit_bindgen_wasmer::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 core::fmt::Display for Eventrwflags{ - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("Eventrwflags(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(())} - } - - wit_bindgen_wasmer::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 core::fmt::Display for Subclockflags{ - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("Subclockflags(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(())} - } - - /// The contents of a `subscription` when type is `eventtype::clock`. - #[repr(C)] - #[derive(Copy, Clone)] - pub struct SubscriptionClock { - /// The user-defined unique identifier of the clock. - pub identifier: Userdata, - /// The clock against which to compare the timestamp. - pub 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("identifier", &self.identifier).field("id", &self.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() - } - } - } - } - - /// Auxiliary data associated with the wasm exports. - #[derive(Default)] - pub struct WasiSnapshot0Data { - } - - pub struct WasiSnapshot0 { - #[allow(dead_code)] - env: wasmer::FunctionEnv, - func_dirent_dummy_func: wasmer::TypedFunction<(i64,i64,i32,i32,), ()>, - func_fd_dummy_func: wasmer::TypedFunction, - func_fdstat_dummy_func: wasmer::TypedFunction<(i32,i32,i32,i32,i32,i32,), ()>, - func_subscription_clock_dummy_func: wasmer::TypedFunction<(i64,i32,i64,i64,i32,), ()>, - } - impl WasiSnapshot0 { - #[allow(unused_variables)] - - /// Adds any intrinsics, if necessary for this exported wasm - /// functionality to the `ImportObject` provided. - /// - /// This function returns the `WasiSnapshot0Data` which needs to be - /// passed through to `WasiSnapshot0::new`. - fn add_to_imports( - mut store: impl wasmer::AsStoreMut, - imports: &mut wasmer::Imports, - ) -> wasmer::FunctionEnv { - let env = wasmer::FunctionEnv::new(&mut store, WasiSnapshot0Data::default()); - env - } - - /// Instantiates the provided `module` using the specified - /// parameters, wrapping up the result in a structure that - /// translates between wasm and the host. - /// - /// The `imports` provided will have intrinsics added to it - /// automatically, so it's not necessary to call - /// `add_to_imports` beforehand. This function will - /// instantiate the `module` otherwise using `imports`, and - /// both an instance of this structure and the underlying - /// `wasmer::Instance` will be returned. - pub fn instantiate( - mut store: impl wasmer::AsStoreMut, - module: &wasmer::Module, - imports: &mut wasmer::Imports, - ) -> anyhow::Result<(Self, wasmer::Instance)> { - let env = Self::add_to_imports(&mut store, imports); - let instance = wasmer::Instance::new( - &mut store, module, &*imports)?; - - Ok((Self::new(store, &instance, env)?, instance)) - } - - /// Low-level creation wrapper for wrapping up the exports - /// of the `instance` provided in this structure of wasm - /// exports. - /// - /// This function will extract exports from the `instance` - /// and wrap them all up in the returned structure which can - /// be used to interact with the wasm module. - pub fn new( - store: impl wasmer::AsStoreMut, - _instance: &wasmer::Instance, - env: wasmer::FunctionEnv, - ) -> Result { - let func_dirent_dummy_func= _instance.exports.get_typed_function(&store, "dirent-dummy-func")?; - let func_fd_dummy_func= _instance.exports.get_typed_function(&store, "fd-dummy-func")?; - let func_fdstat_dummy_func= _instance.exports.get_typed_function(&store, "fdstat-dummy-func")?; - let func_subscription_clock_dummy_func= _instance.exports.get_typed_function(&store, "subscription-clock-dummy-func")?; - Ok(WasiSnapshot0{ - func_dirent_dummy_func, - func_fd_dummy_func, - func_fdstat_dummy_func, - func_subscription_clock_dummy_func, - env, - }) - } - /// Dummy function to expose type into generated code - pub fn fd_dummy_func(&self, store: &mut wasmer::Store,dummy: Fd,)-> Result<(), wasmer::RuntimeError> { - self.func_fd_dummy_func.call(store, wit_bindgen_wasmer::rt::as_i32(dummy), )?; - Ok(()) - } - /// Dummy function to expose type into generated code - pub fn dirent_dummy_func(&self, store: &mut wasmer::Store,dummy: Dirent,)-> Result<(), wasmer::RuntimeError> { - let Dirent{ d_next:d_next0, d_ino:d_ino0, d_namlen:d_namlen0, d_type:d_type0, } = dummy; - self.func_dirent_dummy_func.call(store, wit_bindgen_wasmer::rt::as_i64(d_next0), wit_bindgen_wasmer::rt::as_i64(d_ino0), wit_bindgen_wasmer::rt::as_i32(d_namlen0), d_type0 as i32, )?; - Ok(()) - } - /// Dummy function to expose type into generated code - pub fn fdstat_dummy_func(&self, store: &mut wasmer::Store,dummy: Fdstat,)-> Result<(), wasmer::RuntimeError> { - let Fdstat{ fs_filetype:fs_filetype0, fs_flags:fs_flags0, fs_rights_base:fs_rights_base0, fs_rights_inheriting:fs_rights_inheriting0, } = dummy; - let flags1 = fs_flags0; - let flags2 = fs_rights_base0; - let flags3 = fs_rights_inheriting0; - self.func_fdstat_dummy_func.call(store, fs_filetype0 as i32, (flags1.bits >> 0) as i32, (flags2.bits >> 0) as i32, (flags2.bits >> 32) as i32, (flags3.bits >> 0) as i32, (flags3.bits >> 32) as i32, )?; - Ok(()) - } - /// Dummy function to expose type into generated code - pub fn subscription_clock_dummy_func(&self, store: &mut wasmer::Store,dummy: SubscriptionClock,)-> Result<(), wasmer::RuntimeError> { - let SubscriptionClock{ identifier:identifier0, id:id0, timeout:timeout0, precision:precision0, flags:flags0, } = dummy; - let flags1 = flags0; - self.func_subscription_clock_dummy_func.call(store, wit_bindgen_wasmer::rt::as_i64(identifier0), id0 as i32, wit_bindgen_wasmer::rt::as_i64(timeout0), wit_bindgen_wasmer::rt::as_i64(precision0), (flags1.bits >> 0) as i32, )?; - Ok(()) - } - } #[allow(unused_imports)] use wasmer::AsStoreMut as _; #[allow(unused_imports)] diff --git a/lib/wasi-types-generated/wit/wasi-io-typenames.wit b/lib/wasi-types-generated/wit/wasi-io-typenames.wit index 720f97019cb..c0eb25ef25a 100644 --- a/lib/wasi-types-generated/wit/wasi-io-typenames.wit +++ b/lib/wasi-types-generated/wit/wasi-io-typenames.wit @@ -1,297 +1,15 @@ // Extracted from https://github.com/WebAssembly/wasi-io/blob/main/standard/io/witx/typenames.witx -/// Dummy function to expose type into generated code -subscription-clock-dummy-func: func(dummy: subscription-clock) -fd-dummy-func: func(dummy: fd) -fdstat-dummy-func: func(dummy: fdstat) -/// 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 -/// Identifiers for clocks. -enum clockid { - // TODO: wit appears to not have support for enum type size - //(@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 type size - //(@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, -} - -/// File descriptor rights, determining which actions may be performed. -flags rights { - // TODO: wit appears to not have support for flags type size - //(@witx repr u64) - - /// The right to invoke `fd_datasync`. - /// - /// If `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 `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 `path_open` is set, the right to invoke `path_open` with `oflags::create`. - 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. - /// If `path_open` is set, includes the right to invoke `path_open` with `oflags::trunc`. - /// Note: there is no function named `path_filestat_set_size`. This follows POSIX design, - /// which only has `ftruncate` and does not provide `ftruncateat`. - /// While such function would be desirable from the API design perspective, there are virtually - /// no use cases for it since no code written for POSIX systems would use it. - /// Moreover, implementing it would require multiple syscalls, leading to inferior performance. - path-filestat-set-size, - /// The right to invoke `path_filestat_set_times`. - path-filestat-set-times, - /// The right to invoke `path_permissions_set`. - path-permissions-set, - /// 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 `fd_permissions_set`. - fd-permissions-set, - /// 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, -} - -/// A file descriptor handle. -// TODO: this is of type `handle` in the witx file -type fd = u32 // ;;; A region of memory for scatter/gather reads. // (typename $iovec @@ -330,149 +48,7 @@ type fd = u32 // $end // ) // ) -// -// ;;; A reference to the offset of a directory entry. -// (typename $dircookie u64) -// -// ;;; In an `fd_readdir` call, this value signifies the start of the directory. -// (@witx const $dircookie $start 0) -// -// ;;; The type for the `dirent::d_namlen` field of `dirent`. -// (typename $dirnamlen u32) -// -// ;;; File serial number that is unique within its file system. -// (typename $inode u64) - -/// The type of a file descriptor or file. -enum filetype { - // TODO: wit appears to not have support for enum type size - //(@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. -// (typename $dirent -// (record -// ;;; The offset of the next directory entry stored in this directory. -// (field $d_next $dircookie) -// ;;; The serial number of the file referred to by this directory entry. -// (field $d_ino $inode) -// ;;; The type of the file referred to by this directory entry. -// (field $d_type $filetype) -// ;;; The length of the name of the directory entry. -// (field $d_namlen $dirnamlen) -// ) -// ) -/// File or memory access pattern advisory information. -enum advice { - // TODO: wit appears to not have support for enum type size - //(@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 type size - //(@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, -} - -// ;;; 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. -// (typename $device u64) -// -// ;;; Which file time attributes to adjust. -// (typename $fstflags -// (flags (@witx repr u16) -// ;;; Adjust the last data access timestamp to the value stored in `filestat::atim`. -// $atim -// ;;; Adjust the last data access timestamp to the time of clock `clockid::realtime`. -// $atim_now -// ;;; Adjust the last data modification timestamp to the value stored in `filestat::mtim`. -// $mtim -// ;;; Adjust the last data modification timestamp to the time of clock `clockid::realtime`. -// $mtim_now -// ) -// ) -// -// ;;; Flags determining the method of how paths are resolved. -// (typename $lookupflags -// (flags (@witx repr u32) -// ;;; As long as the resolved path corresponds to a symbolic link, it is expanded. -// $symlink_follow -// ) -// ) -// -// ;;; Open flags used by `path_open`. -// (typename $oflags -// (flags (@witx repr u16) -// ;;; 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 -// ) -// ) -// // ;;; Number of hard links to an inode. // (typename $linkcount u64) // @@ -531,93 +107,8 @@ record fdstat { // ) // ) // -// ;;; User-provided value that may be attached to objects that is retained when -// ;;; extracted from the implementation. -// (typename $userdata u64) - -/// Type of a subscription to an event or its occurrence. -enum eventtype { - // TODO: wit appears to not have support for enum type size - //(@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, -} - -// ;;; The state of the file descriptor subscribed to with -// ;;; `eventtype::fd_read` or `eventtype::fd_write`. -// (typename $eventrwflags -// (flags (@witx repr u16) -// ;;; The peer of this socket has closed or disconnected. -// $fd_readwrite_hangup -// ) -// ) -// -// ;;; The contents of an `event` when type is `eventtype::fd_read` or -// ;;; `eventtype::fd_write`. -// (typename $event_fd_readwrite -// (record -// ;;; The number of bytes available for reading or writing. -// (field $nbytes $filesize) -// ;;; The state of the file descriptor. -// (field $flags $eventrwflags) -// ) -// ) -// -// ;;; The contents of an `event`. -// (typename $event_u -// (variant (@witx tag $eventtype) -// (case $fd_read $event_fd_readwrite) -// (case $fd_write $event_fd_readwrite) -// (case $clock) -// ) -// ) -// -// ;;; An event that occurred. -// (typename $event -// (record -// ;;; User-provided value that got attached to `subscription::userdata`. -// (field $userdata $userdata) -// ;;; If non-zero, an error that occurred while processing the subscription request. -// (field $error $errno) -// ;;; The type of the event that occurred, and the contents of the event -// (field $u $event_u) -// ) -// ) -/// Flags determining how to interpret the timestamp provided in -/// `subscription_clock::timeout`. -flags subclockflags { - // TODO: wit appears to not have support for enum type size - //(@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 subscription-clock { - /// The clock against which to compare the timestamp. - 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, -} // ;;; The contents of a `subscription` when type is type is // ;;; `eventtype::fd_read` or `eventtype::fd_write`. @@ -693,15 +184,6 @@ record subscription-clock { // ) // ) -/// Identifiers for preopened capabilities. -enum preopentype { - // TODO: wit appears to not have support for enum type size - //(@witx tag u8) - - /// A pre-opened directory. - dir, -} - // ;;; The contents of a `prestat` when its type is `preopentype::dir`. // (typename $prestat_dir // (record diff --git a/lib/wasi-types-generated/wit/wasi-snapshot0.wit b/lib/wasi-types-generated/wit/wasi-snapshot0.wit index f7c487bc500..ddd81089eea 100644 --- a/lib/wasi-types-generated/wit/wasi-snapshot0.wit +++ b/lib/wasi-types-generated/wit/wasi-snapshot0.wit @@ -1,300 +1,11 @@ // Extracted from https://github.com/WebAssembly/WASI/blob/main/phases/old/snapshot_0/witx/typenames.witx -use { eventtype, size, timestamp } from wasi-io-typenames -/// Non-negative file size or length of a region within a file. -type filesize = u64 -/// Identifiers for clocks. -enum clockid { - // TODO: wit appears to not have support for enum type size - //(@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, -} - -/// 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 type size - //enum (@witx tag u16) - - /// No error occurred. System call completed successfully. - success, - /// Argument list too long. - toobig, - /// Permission denied. - acces, - /// 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, -} - -/// 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, but not in wasi-snapshot0 - sock-accept, - /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 - sock-connect, - /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 - sock-listen, - /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 - sock-bind, - /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 - sock-recv, - /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 - sock-send, - /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 - sock-addr-local, - /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 - sock-addr-remote, - /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 - sock-recv-from, - /// TODO: Found in wasmer-wasi-types, but not in wasi-snapshot0 - sock-send-to, -} - -/// A file descriptor handle. -type fd = u32 - // ;;; A region of memory for scatter/gather reads. // (typename $iovec // (record @@ -333,143 +44,6 @@ type fd = u32 // ) // ) -/// A reference to the offset of a directory entry. -type dircookie = u64 - -/// 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 - -/// The type of a file descriptor or file. -enum filetype { - // TODO: wit appears to not have support for enum type size - //enum (@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, -} - -/// 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 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, -} - -/// File or memory access pattern advisory information. -enum advice { - // TODO: wit appears to not have support for enum type size - //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 flag type size - //flags (@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, -} - -// ;;; 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. -// (typename $device u64) -// -// ;;; Which file time attributes to adjust. -// (typename $fstflags -// (flags (@witx repr u16) -// ;;; Adjust the last data access timestamp to the value stored in `filestat::atim`. -// $atim -// ;;; Adjust the last data access timestamp to the time of clock `clockid::realtime`. -// $atim_now -// ;;; Adjust the last data modification timestamp to the value stored in `filestat::mtim`. -// $mtim -// ;;; Adjust the last data modification timestamp to the time of clock `clockid::realtime`. -// $mtim_now -// ) -// ) -// -// ;;; Flags determining the method of how paths are resolved. -// (typename $lookupflags -// (flags (@witx repr u32) -// ;;; As long as the resolved path corresponds to a symbolic link, it is expanded. -// $symlink_follow -// ) -// ) -// -// ;;; Open flags used by `path_open`. -// (typename $oflags -// (flags (@witx repr u16) -// ;;; Create file if it does not exist. -// $creat -// ;;; Fail if not a directory. -// $directory -// ;;; Fail if file already exists. -// $excl -// ;;; Truncate file to size 0. -// $trunc -// ) -// ) -// // ;;; Number of hard links to an inode. // (typename $linkcount u32) // @@ -495,74 +69,6 @@ record fdstat { // ) // ) -/// User-provided value that may be attached to objects that is retained when -/// extracted from the implementation. -type userdata = u64 - - -/// 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 type size - //@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 -// (typename $event_fd_readwrite -// (record -// ;;; The number of bytes available for reading or writing. -// (field $nbytes $filesize) -// ;;; The state of the file descriptor. -// (field $flags $eventrwflags) -// ) -// ) -// -// ;;; An event that occurred. -// (typename $event -// (record -// ;;; User-provided value that got attached to `subscription::userdata`. -// (field $userdata $userdata) -// ;;; If non-zero, an error that occurred while processing the subscription request. -// (field $error $errno) -// ;;; The type of event that occured -// (field $type $eventtype) -// ;;; The contents of the event, if it is an `eventtype::fd_read` or -// ;;; `eventtype::fd_write`. `eventtype::clock` events ignore this field. -// (field $fd_readwrite $event_fd_readwrite) -// ) -// ) - -/// Flags determining how to interpret the timestamp provided in -/// `subscription-clock::timeout`. -flags subclockflags { - // TODO: wit appears to not have support for flags type size - //@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 subscription-clock { - /// The user-defined unique identifier of the clock. - identifier: userdata, - /// The clock against which to compare the timestamp. - 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 -} // ;;; The contents of a `subscription` when the variant is // ;;; `eventtype::fd_read` or `eventtype::fd_write`. @@ -727,14 +233,6 @@ record subscription-clock { // ) // ) -/// Identifiers for preopened capabilities. -enum preopentype { - // TODO: wit appears to not have support for enum type size - // enum (@witx tag u8) - /// A pre-opened directory. - dir, -} - // ;;; The contents of a $prestat when type is `preopentype::dir`. // (typename $prestat_dir // (record @@ -749,12 +247,3 @@ enum preopentype { // $prestat_dir // ) // ) - -/// Dummy function to expose type into generated code -fd-dummy-func: func(dummy: fd) -/// Dummy function to expose type into generated code -dirent-dummy-func: func(dummy: dirent) -/// Dummy function to expose type into generated code -fdstat-dummy-func: func(dummy: fdstat) -/// Dummy function to expose type into generated code -subscription-clock-dummy-func: func(dummy: subscription-clock) diff --git a/lib/wasi-types-generated/wit/wasi.wit b/lib/wasi-types-generated/wit/wasi.wit new file mode 100644 index 00000000000..650aae372ce --- /dev/null +++ b/lib/wasi-types-generated/wit/wasi.wit @@ -0,0 +1,721 @@ +// 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 + + + +/// Dummy function to expose type into generated code +fd-dummy-func: func(dummy: fd) +/// Dummy function to expose type into generated code +dirent-dummy-func: func(dummy: dirent) +/// Dummy function to expose type into generated code +fdstat-dummy-func: func(dummy: fdstat) +/// Dummy function to expose type into generated code +subscription-clock-dummy-func: func(dummy: subscription-clock) + + + +/// 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 + +/// Identifiers for clocks, snapshot0 version. +enum snapshot0-clockid { + // TODO: wit appears to not have support for enum type size + //(@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 type size + //(@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 type size + //(@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, +} + +/// File descriptor rights, determining which actions may be performed, snapshot0 version. +flags snapshot0-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, +} + +/// File descriptor rights, determining which actions may be performed. +flags rights { + // TODO: wit appears to not have support for flags type size + //(@witx repr u64) + + /// The right to invoke `fd_datasync`. + /// + /// If `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 `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 `path_open` is set, the right to invoke `path_open` with `oflags::create`. + 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. + /// If `path_open` is set, includes the right to invoke `path_open` with `oflags::trunc`. + /// Note: there is no function named `path_filestat_set_size`. This follows POSIX design, + /// which only has `ftruncate` and does not provide `ftruncateat`. + /// While such function would be desirable from the API design perspective, there are virtually + /// no use cases for it since no code written for POSIX systems would use it. + /// Moreover, implementing it would require multiple syscalls, leading to inferior performance. + path-filestat-set-size, + /// The right to invoke `path_filestat_set_times`. + path-filestat-set-times, + /// The right to invoke `path_permissions_set`. + path-permissions-set, + /// 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 `fd_permissions_set`. + fd-permissions-set, + /// 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, +} + +/// The type of a file descriptor or file. +enum snapshot0-filetype { + // TODO: wit appears to not have support for enum type size + //enum (@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 type of a file descriptor or file. +enum filetype { + // TODO: wit appears to not have support for enum type size + //(@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 type size + //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 type size + //(@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. +flags fstflags { + // TODO: wit appears to not have support for flags type size + //(@witx repr u16) + + /// Adjust the last data access timestamp to the value stored in `filestat::atim`. + atim, + /// Adjust the last data access timestamp to the time of clock `clockid::realtime`. + atim-now, + /// Adjust the last data modification timestamp to the value stored in `filestat::mtim`. + mtim, + /// Adjust the last data modification timestamp to the time of clock `clockid::realtime`. + mtim-now, +} + +/// Flags determining the method of how paths are resolved. +flags lookup { + // TODO: wit appears to not have support for flags type size + //(@witx repr u32) + + /// As long as the resolved path corresponds to a symbolic link, it is expanded. + symlink-follow, +} + +/// Open flags used by `path_open`. +flags oflags { + // TODO: wit appears to not have support for flags type size + //(@witx repr u16) + + /// 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 type size + //(@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 type size + //@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: 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. + 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 type size + //(@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 type size + //@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 +} + +/// The contents of an `event`. +variant event-u { + // 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, +} From d471def81f2788b8748da1f6ee6cf7ff18dff49e Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Tue, 23 Aug 2022 10:16:50 +0200 Subject: [PATCH 21/84] Builds again --- lib/wasi-types-generated/regenerate.sh | 10 - lib/wasi-types-generated/src/lib.rs | 5 +- lib/wasi-types-generated/src/wasi/bindings.rs | 556 +++++++---- lib/wasi-types-generated/src/wasi/mod.rs | 867 ++++++++++++++++++ .../src/wasi_io_typenames/bindings.rs | 9 - .../src/wasi_io_typenames/mod.rs | 156 ---- .../src/wasi_snapshot0/bindings.rs | 9 - .../src/wasi_snapshot0/mod.rs | 494 ---------- lib/wasi-types-generated/wit/wasi.wit | 179 ++-- lib/wasi-types/src/directory.rs | 16 +- lib/wasi-types/src/event.rs | 29 +- lib/wasi-types/src/file.rs | 79 +- lib/wasi-types/src/subscription.rs | 138 +-- lib/wasi-types/src/versions/snapshot0.rs | 78 +- lib/wasi/src/lib.rs | 18 +- lib/wasi/src/macros.rs | 14 +- lib/wasi/src/runtime.rs | 10 +- lib/wasi/src/state/guard.rs | 2 +- lib/wasi/src/state/mod.rs | 30 +- lib/wasi/src/state/pipe.rs | 13 +- lib/wasi/src/state/socket.rs | 394 ++++---- lib/wasi/src/state/types.rs | 2 +- lib/wasi/src/syscalls/legacy/snapshot0.rs | 20 +- lib/wasi/src/syscalls/mod.rs | 248 ++--- lib/wasi/src/syscalls/unix/mod.rs | 30 +- lib/wasi/src/syscalls/wasi.rs | 185 ++-- lib/wasi/src/syscalls/wasix32.rs | 370 ++++---- lib/wasi/src/syscalls/wasix64.rs | 370 ++++---- lib/wasi/src/syscalls/wasm32.rs | 23 +- lib/wasi/src/utils.rs | 43 +- 30 files changed, 2193 insertions(+), 2204 deletions(-) delete mode 100644 lib/wasi-types-generated/src/wasi_io_typenames/bindings.rs delete mode 100644 lib/wasi-types-generated/src/wasi_io_typenames/mod.rs delete mode 100644 lib/wasi-types-generated/src/wasi_snapshot0/bindings.rs delete mode 100644 lib/wasi-types-generated/src/wasi_snapshot0/mod.rs diff --git a/lib/wasi-types-generated/regenerate.sh b/lib/wasi-types-generated/regenerate.sh index ac5748ec826..fa266c371f8 100755 --- a/lib/wasi-types-generated/regenerate.sh +++ b/lib/wasi-types-generated/regenerate.sh @@ -16,14 +16,4 @@ wit-bindgen wasmer \ "$BASEDIR"/wit/wasi-filesystem.wit \ --out-dir "$BASEDIR"/src/wasi_filesystem -wit-bindgen wasmer \ - --import \ - "$BASEDIR"/wit/wasi-io-typenames.wit \ - --out-dir "$BASEDIR"/src/wasi_io_typenames - -wit-bindgen wasmer \ - --import \ - "$BASEDIR"/wit/wasi-snapshot0.wit \ - --out-dir "$BASEDIR"/src/wasi_snapshot0 - #wit-bindgen rust-wasm --import wit/wasi-snapshot0.wit wit/wasi-filesystem.wit --out-dir . diff --git a/lib/wasi-types-generated/src/lib.rs b/lib/wasi-types-generated/src/lib.rs index 7135f8e6af2..9cdc190a5e1 100644 --- a/lib/wasi-types-generated/src/lib.rs +++ b/lib/wasi-types-generated/src/lib.rs @@ -1,5 +1,6 @@ pub mod wasi; pub mod wasi_filesystem; -pub mod wasi_io_typenames; -pub mod wasi_snapshot0 {} +pub mod wasi_snapshot0 { + pub use super::wasi::{Dircookie, Dirent, Fd}; +} diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index b751a16b61d..2d4afeef0ff 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -2,6 +2,8 @@ pub mod wasi { #[allow(unused_imports)] use wit_bindgen_wasmer::{anyhow, wasmer}; + /// 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. @@ -414,8 +416,8 @@ pub mod wasi { impl std::error::Error for Errno{} wit_bindgen_wasmer::bitflags::bitflags! { - /// File descriptor rights, determining which actions may be performed, snapshot0 version. - pub struct Snapshot0Rights: u64 {/// The right to invoke `fd_datasync`. + /// 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`. @@ -511,103 +513,6 @@ pub mod wasi { } } - impl core::fmt::Display for Snapshot0Rights{ - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("Snapshot0Rights(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(())} - } - - wit_bindgen_wasmer::bitflags::bitflags! { - /// File descriptor rights, determining which actions may be performed. - pub struct Rights: u32 {/// The right to invoke `fd_datasync`. - /// - /// If `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 `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 `path_open` is set, the right to invoke `path_open` with `oflags::create`. - 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. - /// If `path_open` is set, includes the right to invoke `path_open` with `oflags::trunc`. - /// Note: there is no function named `path_filestat_set_size`. This follows POSIX design, - /// which only has `ftruncate` and does not provide `ftruncateat`. - /// While such function would be desirable from the API design perspective, there are virtually - /// no use cases for it since no code written for POSIX systems would use it. - /// Moreover, implementing it would require multiple syscalls, leading to inferior performance. - 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 `path_permissions_set`. - const PATH_PERMISSIONS_SET = 1 << 21; - /// The right to invoke `fd_filestat_get`. - const FD_FILESTAT_GET = 1 << 22; - /// The right to invoke `fd_filestat_set_size`. - const FD_FILESTAT_SET_SIZE = 1 << 23; - /// The right to invoke `fd_filestat_set_times`. - const FD_FILESTAT_SET_TIMES = 1 << 24; - /// The right to invoke `fd_permissions_set`. - const FD_PERMISSIONS_SET = 1 << 25; - /// The right to invoke `path_symlink`. - const PATH_SYMLINK = 1 << 26; - /// The right to invoke `path_remove_directory`. - const PATH_REMOVE_DIRECTORY = 1 << 27; - /// The right to invoke `path_unlink_file`. - const PATH_UNLINK_FILE = 1 << 28; - /// 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 << 29; - /// The right to invoke `sock_shutdown`. - const SOCK_SHUTDOWN = 1 << 30; - } - } - impl core::fmt::Display for Rights{ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.write_str("Rights(")?; @@ -618,57 +523,6 @@ pub mod wasi { Ok(())} } - /// The type of a file descriptor or file. - #[repr(u8)] - #[derive(Clone, Copy, PartialEq, Eq)] - pub enum Snapshot0Filetype { - /// 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, - } - impl core::fmt::Debug for Snapshot0Filetype { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - match self { - Snapshot0Filetype::Unknown => { - f.debug_tuple("Snapshot0Filetype::Unknown").finish() - } - Snapshot0Filetype::BlockDevice => { - f.debug_tuple("Snapshot0Filetype::BlockDevice").finish() - } - Snapshot0Filetype::CharacterDevice => { - f.debug_tuple("Snapshot0Filetype::CharacterDevice").finish() - } - Snapshot0Filetype::Directory => { - f.debug_tuple("Snapshot0Filetype::Directory").finish() - } - Snapshot0Filetype::RegularFile => { - f.debug_tuple("Snapshot0Filetype::RegularFile").finish() - } - Snapshot0Filetype::SocketDgram => { - f.debug_tuple("Snapshot0Filetype::SocketDgram").finish() - } - Snapshot0Filetype::SocketStream => { - f.debug_tuple("Snapshot0Filetype::SocketStream").finish() - } - Snapshot0Filetype::SymbolicLink => { - f.debug_tuple("Snapshot0Filetype::SymbolicLink").finish() - } - } - } - } /// The type of a file descriptor or file. #[repr(u8)] #[derive(Clone, Copy, PartialEq, Eq)] @@ -891,6 +745,9 @@ pub mod wasi { Ok(())} } + /// 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)] @@ -942,12 +799,32 @@ pub mod wasi { Ok(())} } + /// 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 id: Clockid, + pub clock_id: Clockid, /// The absolute or relative timestamp. pub timeout: Timestamp, /// The amount of time that the implementation may wait additionally @@ -958,7 +835,7 @@ pub mod wasi { } impl core::fmt::Debug for SubscriptionClock { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.debug_struct("SubscriptionClock").field("id", &self.id).field("timeout", &self.timeout).field("precision", &self.precision).field("flags", &self.flags).finish()} + 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)] @@ -994,6 +871,146 @@ pub mod wasi { Ok(())} } + /// 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() + } + } + } + } + /// 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()} + } + impl wit_bindgen_wasmer::Endian for SubscriptionFsReadwrite { + fn into_le(self) -> Self { + Self { + file_descriptor: self.file_descriptor.into_le(), + } + } + fn from_le(self) -> Self { + Self { + file_descriptor: self.file_descriptor.from_le(), + } + } + } + unsafe impl wit_bindgen_wasmer::AllBytesValid for SubscriptionFsReadwrite {} + #[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()} + } /// Auxiliary data associated with the wasm exports. #[derive(Default)] @@ -1003,10 +1020,9 @@ pub mod wasi { pub struct Wasi { #[allow(dead_code)] env: wasmer::FunctionEnv, - func_dirent_dummy_func: wasmer::TypedFunction<(i64,i64,i32,i32,), ()>, - func_fd_dummy_func: wasmer::TypedFunction, - func_fdstat_dummy_func: wasmer::TypedFunction<(i32,i32,i32,i32,), ()>, - func_subscription_clock_dummy_func: wasmer::TypedFunction<(i32,i64,i64,i32,), ()>, + func_canonical_abi_realloc: wasmer::TypedFunction<(i32, i32, i32, i32), i32>, + func_expose_types_dummy_func: wasmer::TypedFunction, + memory: wasmer::Memory, } impl Wasi { #[allow(unused_variables)] @@ -1058,43 +1074,204 @@ pub mod wasi { _instance: &wasmer::Instance, env: wasmer::FunctionEnv, ) -> Result { - let func_dirent_dummy_func= _instance.exports.get_typed_function(&store, "dirent-dummy-func")?; - let func_fd_dummy_func= _instance.exports.get_typed_function(&store, "fd-dummy-func")?; - let func_fdstat_dummy_func= _instance.exports.get_typed_function(&store, "fdstat-dummy-func")?; - let func_subscription_clock_dummy_func= _instance.exports.get_typed_function(&store, "subscription-clock-dummy-func")?; + let func_canonical_abi_realloc= _instance.exports.get_typed_function(&store, "canonical_abi_realloc")?; + let func_expose_types_dummy_func= _instance.exports.get_typed_function(&store, "expose-types-dummy-func")?; + let memory= _instance.exports.get_memory("memory")?.clone(); Ok(Wasi{ - func_dirent_dummy_func, - func_fd_dummy_func, - func_fdstat_dummy_func, - func_subscription_clock_dummy_func, + func_canonical_abi_realloc, + func_expose_types_dummy_func, + memory, env, }) } - /// Dummy function to expose type into generated code - pub fn fd_dummy_func(&self, store: &mut wasmer::Store,dummy: Fd,)-> Result<(), wasmer::RuntimeError> { - self.func_fd_dummy_func.call(store, wit_bindgen_wasmer::rt::as_i32(dummy), )?; - Ok(()) - } - /// Dummy function to expose type into generated code - pub fn dirent_dummy_func(&self, store: &mut wasmer::Store,dummy: Dirent,)-> Result<(), wasmer::RuntimeError> { - let Dirent{ d_next:d_next0, d_ino:d_ino0, d_type:d_type0, d_namlen:d_namlen0, } = dummy; - self.func_dirent_dummy_func.call(store, wit_bindgen_wasmer::rt::as_i64(d_next0), wit_bindgen_wasmer::rt::as_i64(d_ino0), d_type0 as i32, wit_bindgen_wasmer::rt::as_i32(d_namlen0), )?; - Ok(()) - } - /// Dummy function to expose type into generated code - pub fn fdstat_dummy_func(&self, store: &mut wasmer::Store,dummy: Fdstat,)-> Result<(), wasmer::RuntimeError> { - let Fdstat{ fs_filetype:fs_filetype0, fs_flags:fs_flags0, fs_rights_base:fs_rights_base0, fs_rights_inheriting:fs_rights_inheriting0, } = dummy; - let flags1 = fs_flags0; - let flags2 = fs_rights_base0; - let flags3 = fs_rights_inheriting0; - self.func_fdstat_dummy_func.call(store, fs_filetype0 as i32, (flags1.bits >> 0) as i32, (flags2.bits >> 0) as i32, (flags3.bits >> 0) as i32, )?; - Ok(()) - } - /// Dummy function to expose type into generated code - pub fn subscription_clock_dummy_func(&self, store: &mut wasmer::Store,dummy: SubscriptionClock,)-> Result<(), wasmer::RuntimeError> { - let SubscriptionClock{ id:id0, timeout:timeout0, precision:precision0, flags:flags0, } = dummy; - let flags1 = flags0; - self.func_subscription_clock_dummy_func.call(store, id0 as i32, wit_bindgen_wasmer::rt::as_i64(timeout0), wit_bindgen_wasmer::rt::as_i64(precision0), (flags1.bits >> 0) as i32, )?; + /// Dummy function to expose types into generated code + pub fn expose_types_dummy_func(&self, store: &mut wasmer::Store,fd: Fd,dirent: Dirent,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,)-> Result<(), wasmer::RuntimeError> { + let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; + let _memory = &self.memory; + let ptr0 = func_canonical_abi_realloc.call(store, 0, 0, 8, 296)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 0, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(fd)))?; + let Dirent{ d_next:d_next1, d_ino:d_ino1, d_type:d_type1, d_namlen:d_namlen1, } = dirent; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 8, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(d_next1)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 16, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(d_ino1)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 24, wit_bindgen_wasmer::rt::as_i32(d_type1 as i32) as u8)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 28, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(d_namlen1)))?; + match event_enum { + EventEnum::FdRead(e) => { + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 32, wit_bindgen_wasmer::rt::as_i32(0i32) as u8)?; + let EventFdReadwrite{ nbytes:nbytes2, flags:flags2, } = e; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 40, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(nbytes2)))?; + let flags3 = flags2; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 48, wit_bindgen_wasmer::rt::as_i32((flags3.bits >> 0) as i32) as u8)?; + }, + EventEnum::FdWrite(e) => { + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 32, wit_bindgen_wasmer::rt::as_i32(1i32) as u8)?; + let EventFdReadwrite{ nbytes:nbytes4, flags:flags4, } = e; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 40, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(nbytes4)))?; + let flags5 = flags4; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 48, wit_bindgen_wasmer::rt::as_i32((flags5.bits >> 0) as i32) as u8)?; + }, + EventEnum::Clock=> { + let e = (); + { + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 32, wit_bindgen_wasmer::rt::as_i32(2i32) as u8)?; + let () = e; + } + } + }; + let Event{ userdata:userdata6, error:error6, data:data6, } = event; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 56, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(userdata6)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 64, wit_bindgen_wasmer::rt::as_i32(error6 as i32) as u8)?; + match data6 { + EventEnum::FdRead(e) => { + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 72, wit_bindgen_wasmer::rt::as_i32(0i32) as u8)?; + let EventFdReadwrite{ nbytes:nbytes7, flags:flags7, } = e; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 80, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(nbytes7)))?; + let flags8 = flags7; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 88, wit_bindgen_wasmer::rt::as_i32((flags8.bits >> 0) as i32) as u8)?; + }, + EventEnum::FdWrite(e) => { + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 72, wit_bindgen_wasmer::rt::as_i32(1i32) as u8)?; + let EventFdReadwrite{ nbytes:nbytes9, flags:flags9, } = e; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 80, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(nbytes9)))?; + let flags10 = flags9; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 88, wit_bindgen_wasmer::rt::as_i32((flags10.bits >> 0) as i32) as u8)?; + }, + EventEnum::Clock=> { + let e = (); + { + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 72, wit_bindgen_wasmer::rt::as_i32(2i32) as u8)?; + let () = e; + } + } + }; + let Fdstat{ fs_filetype:fs_filetype11, fs_flags:fs_flags11, fs_rights_base:fs_rights_base11, fs_rights_inheriting:fs_rights_inheriting11, } = fdstat; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 96, wit_bindgen_wasmer::rt::as_i32(fs_filetype11 as i32) as u8)?; + let flags12 = fs_flags11; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 97, wit_bindgen_wasmer::rt::as_i32((flags12.bits >> 0) as i32) as u8)?; + let flags13 = fs_rights_base11; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 104, wit_bindgen_wasmer::rt::as_i32((flags13.bits >> 32) as i32))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 100, wit_bindgen_wasmer::rt::as_i32((flags13.bits >> 0) as i32))?; + let flags14 = fs_rights_inheriting11; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 112, wit_bindgen_wasmer::rt::as_i32((flags14.bits >> 32) as i32))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 108, wit_bindgen_wasmer::rt::as_i32((flags14.bits >> 0) as i32))?; + let SubscriptionClock{ clock_id:clock_id15, timeout:timeout15, precision:precision15, flags:flags15, } = subscription_clock; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 120, wit_bindgen_wasmer::rt::as_i32(clock_id15 as i32) as u8)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 128, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(timeout15)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 136, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(precision15)))?; + let flags16 = flags15; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 144, wit_bindgen_wasmer::rt::as_i32((flags16.bits >> 0) as i32) as u8)?; + let Snapshot0SubscriptionClock{ identifier:identifier17, id:id17, timeout:timeout17, precision:precision17, flags:flags17, } = snapshot0_subscription_clock; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 152, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(identifier17)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 160, wit_bindgen_wasmer::rt::as_i32(id17 as i32) as u8)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 168, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(timeout17)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 176, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(precision17)))?; + let flags18 = flags17; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 184, wit_bindgen_wasmer::rt::as_i32((flags18.bits >> 0) as i32) as u8)?; + let Subscription{ userdata:userdata19, data:data19, } = subscription; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 192, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(userdata19)))?; + match data19 { + SubscriptionEnum::Clock(e) => { + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 200, wit_bindgen_wasmer::rt::as_i32(0i32) as u8)?; + let SubscriptionClock{ clock_id:clock_id20, timeout:timeout20, precision:precision20, flags:flags20, } = e; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 208, wit_bindgen_wasmer::rt::as_i32(clock_id20 as i32) as u8)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 216, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(timeout20)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 224, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(precision20)))?; + let flags21 = flags20; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 232, wit_bindgen_wasmer::rt::as_i32((flags21.bits >> 0) as i32) as u8)?; + }, + SubscriptionEnum::Read(e) => { + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 200, wit_bindgen_wasmer::rt::as_i32(1i32) as u8)?; + let SubscriptionFsReadwrite{ file_descriptor:file_descriptor22, } = e; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 208, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(file_descriptor22)))?; + }, + SubscriptionEnum::Write(e) => { + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 200, wit_bindgen_wasmer::rt::as_i32(2i32) as u8)?; + let SubscriptionFsReadwrite{ file_descriptor:file_descriptor23, } = e; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 208, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(file_descriptor23)))?; + }, + }; + let Snapshot0Subscription{ userdata:userdata24, data:data24, } = snapshot0_subscription; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 240, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(userdata24)))?; + match data24 { + Snapshot0SubscriptionEnum::Clock(e) => { + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 248, wit_bindgen_wasmer::rt::as_i32(0i32) as u8)?; + let Snapshot0SubscriptionClock{ identifier:identifier25, id:id25, timeout:timeout25, precision:precision25, flags:flags25, } = e; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 256, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(identifier25)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 264, wit_bindgen_wasmer::rt::as_i32(id25 as i32) as u8)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 272, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(timeout25)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 280, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(precision25)))?; + let flags26 = flags25; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 288, wit_bindgen_wasmer::rt::as_i32((flags26.bits >> 0) as i32) as u8)?; + }, + Snapshot0SubscriptionEnum::Read(e) => { + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 248, wit_bindgen_wasmer::rt::as_i32(1i32) as u8)?; + let SubscriptionFsReadwrite{ file_descriptor:file_descriptor27, } = e; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 256, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(file_descriptor27)))?; + }, + Snapshot0SubscriptionEnum::Write(e) => { + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 248, wit_bindgen_wasmer::rt::as_i32(2i32) as u8)?; + let SubscriptionFsReadwrite{ file_descriptor:file_descriptor28, } = e; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 256, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(file_descriptor28)))?; + }, + }; + self.func_expose_types_dummy_func.call(store, ptr0, )?; Ok(()) } } @@ -1102,4 +1279,5 @@ pub mod wasi { use wasmer::AsStoreMut as _; #[allow(unused_imports)] use wasmer::AsStoreRef as _; + use wit_bindgen_wasmer::rt::RawMem; } diff --git a/lib/wasi-types-generated/src/wasi/mod.rs b/lib/wasi-types-generated/src/wasi/mod.rs index e69de29bb2d..e39969f1eb5 100644 --- a/lib/wasi-types-generated/src/wasi/mod.rs +++ b/lib/wasi-types-generated/src/wasi/mod.rs @@ -0,0 +1,867 @@ +mod bindings; +pub use bindings::wasi::*; + +use std::mem::MaybeUninit; +use wasmer_types::ValueType; + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Errno { + #[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]) {} +} + +impl Filetype { + pub fn name(self) -> &'static str { + match self { + Self::Unknown => "Unknown", + Self::BlockDevice => "Block device", + Self::CharacterDevice => "Character device", + Self::Directory => "Directory", + Self::RegularFile => "Regular file", + Self::SocketDgram => "Socket dgram", + Self::SocketStream => "Socket stream", + Self::SymbolicLink => "Symbolic link", + Self::Fifo => "Fifo", + } + } +} + +unsafe impl ValueType for Event { + 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)*) + std::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!(data)); + self.data + .zero_padding_bytes(&mut bytes[field!(data)..field_end!(data)]); + zero!(field_end!(data), std::mem::size_of_val(self)); + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Eventtype { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Rights { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +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, + }) + } +} + +// 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 SubscriptionEnum { + fn zero_padding_bytes(&self, bytes: &mut [MaybeUninit]) { + macro_rules! field { + ($($f:tt)*) => { + &$($f)* as *const _ as usize - self as *const _ as usize + }; + } + macro_rules! field_end { + ($($f:tt)*) => { + field!($($f)*) + std::mem::size_of_val(&$($f)*) + }; + } + macro_rules! zero { + ($start:expr, $end:expr) => { + for i in $start..$end { + bytes[i] = MaybeUninit::new(0); + } + }; + } + + match self { + SubscriptionEnum::Clock(d) => { + d.zero_padding_bytes(&mut bytes[field!(d)..field_end!(d)]); + zero!(field_end!(d), std::mem::size_of_val(self)) + } + SubscriptionEnum::Read(d) => { + d.zero_padding_bytes(&mut bytes[field!(d)..field_end!(d)]); + zero!(field_end!(d), std::mem::size_of_val(self)) + } + SubscriptionEnum::Write(d) => { + d.zero_padding_bytes(&mut bytes[field!(d)..field_end!(d)]); + zero!(field_end!(d), std::mem::size_of_val(self)) + } + } + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for EventEnum { + fn zero_padding_bytes(&self, bytes: &mut [MaybeUninit]) { + macro_rules! field { + ($($f:tt)*) => { + &$($f)* as *const _ as usize - self as *const _ as usize + }; + } + macro_rules! field_end { + ($($f:tt)*) => { + field!($($f)*) + std::mem::size_of_val(&$($f)*) + }; + } + macro_rules! zero { + ($start:expr, $end:expr) => { + for i in $start..$end { + bytes[i] = MaybeUninit::new(0); + } + }; + } + + match self { + Self::Clock => { + zero!(field!(self), std::mem::size_of_val(self)) + } + Self::FdRead(d) => { + d.zero_padding_bytes(&mut bytes[field!(d)..field_end!(d)]); + zero!(field_end!(d), std::mem::size_of_val(self)) + } + Self::FdWrite(d) => { + d.zero_padding_bytes(&mut bytes[field!(d)..field_end!(d)]); + zero!(field_end!(d), std::mem::size_of_val(self)) + } + } + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Snapshot0SubscriptionEnum { + fn zero_padding_bytes(&self, bytes: &mut [MaybeUninit]) { + macro_rules! field { + ($($f:tt)*) => { + &$($f)* as *const _ as usize - self as *const _ as usize + }; + } + macro_rules! field_end { + ($($f:tt)*) => { + field!($($f)*) + std::mem::size_of_val(&$($f)*) + }; + } + macro_rules! zero { + ($start:expr, $end:expr) => { + for i in $start..$end { + bytes[i] = MaybeUninit::new(0); + } + }; + } + + match self { + Snapshot0SubscriptionEnum::Clock(d) => { + d.zero_padding_bytes(&mut bytes[field!(d)..field_end!(d)]); + zero!(field_end!(d), std::mem::size_of_val(self)) + } + Snapshot0SubscriptionEnum::Read(d) => { + d.zero_padding_bytes(&mut bytes[field!(d)..field_end!(d)]); + zero!(field_end!(d), std::mem::size_of_val(self)) + } + Snapshot0SubscriptionEnum::Write(d) => { + d.zero_padding_bytes(&mut bytes[field!(d)..field_end!(d)]); + zero!(field_end!(d), std::mem::size_of_val(self)) + } + } + } +} + +// 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 Clockid { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// 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 Preopentype { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for EventFdReadwrite { + 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)*) + std::mem::size_of_val(&self.$($f)*) + }; + } + macro_rules! zero { + ($start:expr, $end:expr) => { + for i in $start..$end { + bytes[i] = MaybeUninit::new(0); + } + }; + } + + self.nbytes + .zero_padding_bytes(&mut bytes[field!(nbytes)..field_end!(nbytes)]); + zero!(field_end!(nbytes), field!(flags)); + + self.flags + .zero_padding_bytes(&mut bytes[field!(flags)..field_end!(flags)]); + zero!(field_end!(flags), std::mem::size_of_val(self)); + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Fdstat { + 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)*) + std::mem::size_of_val(&self.$($f)*) + }; + } + macro_rules! zero { + ($start:expr, $end:expr) => { + for i in $start..$end { + bytes[i] = MaybeUninit::new(0); + } + }; + } + + self.fs_filetype + .zero_padding_bytes(&mut bytes[field!(fs_filetype)..field_end!(fs_filetype)]); + zero!(field_end!(fs_filetype), field!(fs_flags)); + + self.fs_flags + .zero_padding_bytes(&mut bytes[field!(fs_flags)..field_end!(fs_flags)]); + zero!(field_end!(fs_flags), field!(fs_rights_base)); + + self.fs_rights_base + .zero_padding_bytes(&mut bytes[field!(fs_rights_base)..field_end!(fs_rights_base)]); + zero!( + field_end!(fs_rights_inheriting), + std::mem::size_of_val(self) + ); + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Snapshot0SubscriptionClock { + 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)*) + std::mem::size_of_val(&self.$($f)*) + }; + } + macro_rules! zero { + ($start:expr, $end:expr) => { + for i in $start..$end { + bytes[i] = MaybeUninit::new(0); + } + }; + } + + self.identifier + .zero_padding_bytes(&mut bytes[field!(identifier)..field_end!(identifier)]); + zero!(field_end!(identifier), field!(id)); + + self.id + .zero_padding_bytes(&mut bytes[field!(id)..field_end!(id)]); + zero!(field_end!(id), field!(timeout)); + + self.timeout + .zero_padding_bytes(&mut bytes[field!(timeout)..field_end!(timeout)]); + zero!(field_end!(timeout), field!(precision)); + + self.precision + .zero_padding_bytes(&mut bytes[field!(precision)..field_end!(precision)]); + zero!(field_end!(precision), field!(flags)); + + self.flags + .zero_padding_bytes(&mut bytes[field!(flags)..field_end!(flags)]); + zero!(field_end!(flags), std::mem::size_of_val(self)); + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for SubscriptionFsReadwrite { + 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)*) + std::mem::size_of_val(&self.$($f)*) + }; + } + macro_rules! zero { + ($start:expr, $end:expr) => { + for i in $start..$end { + bytes[i] = MaybeUninit::new(0); + } + }; + } + + self.file_descriptor + .zero_padding_bytes(&mut bytes[field!(file_descriptor)..field_end!(file_descriptor)]); + zero!(field_end!(file_descriptor), std::mem::size_of_val(self)); + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for SubscriptionClock { + 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)*) + std::mem::size_of_val(&self.$($f)*) + }; + } + macro_rules! zero { + ($start:expr, $end:expr) => { + for i in $start..$end { + bytes[i] = MaybeUninit::new(0); + } + }; + } + + self.clock_id + .zero_padding_bytes(&mut bytes[field!(clock_id)..field_end!(clock_id)]); + zero!(field_end!(clock_id), field!(timeout)); + + self.timeout + .zero_padding_bytes(&mut bytes[field!(timeout)..field_end!(timeout)]); + zero!(field_end!(timeout), field!(precision)); + + self.precision + .zero_padding_bytes(&mut bytes[field!(precision)..field_end!(precision)]); + zero!(field_end!(precision), field!(flags)); + + self.flags + .zero_padding_bytes(&mut bytes[field!(flags)..field_end!(flags)]); + zero!(field_end!(flags), std::mem::size_of_val(self)); + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Subscription { + 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)*) + std::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!(data)); + + self.data + .zero_padding_bytes(&mut bytes[field!(data)..field_end!(data)]); + zero!(field_end!(data), std::mem::size_of_val(self)); + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Snapshot0Subscription { + 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)*) + std::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!(data)); + + self.data + .zero_padding_bytes(&mut bytes[field!(data)..field_end!(data)]); + zero!(field_end!(data), std::mem::size_of_val(self)); + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::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, + // TODO: What should we map invalid native values to? + _ => Self::Inval, + } + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::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) + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Eventrwflags { + 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 u8) + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Subclockflags { + 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 u8) + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::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 u8) + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Snapshot0Clockid { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + +impl Eventtype { + pub fn to_str(self) -> &'static str { + match self { + Eventtype::Clock => "Wasi::Eventtype::Clock", + Eventtype::FdRead => "Wasi::Eventtype::FdRead", + Eventtype::FdWrite => "Wasi::Eventtype::FdWrite", + } + } +} + +/// 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), + } + } +} diff --git a/lib/wasi-types-generated/src/wasi_io_typenames/bindings.rs b/lib/wasi-types-generated/src/wasi_io_typenames/bindings.rs deleted file mode 100644 index 5ee86fb0339..00000000000 --- a/lib/wasi-types-generated/src/wasi_io_typenames/bindings.rs +++ /dev/null @@ -1,9 +0,0 @@ -#[allow(clippy::all)] -pub mod wasi_io_typenames { - #[allow(unused_imports)] - use wit_bindgen_wasmer::{anyhow, wasmer}; - #[allow(unused_imports)] - use wasmer::AsStoreMut as _; - #[allow(unused_imports)] - use wasmer::AsStoreRef as _; -} diff --git a/lib/wasi-types-generated/src/wasi_io_typenames/mod.rs b/lib/wasi-types-generated/src/wasi_io_typenames/mod.rs deleted file mode 100644 index 74c90a099ca..00000000000 --- a/lib/wasi-types-generated/src/wasi_io_typenames/mod.rs +++ /dev/null @@ -1,156 +0,0 @@ -mod bindings; -pub use bindings::wasi_io_typenames::*; - -use std::mem::MaybeUninit; -use wasmer_types::ValueType; - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for Eventtype { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -// 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 Clockid { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -impl Eventtype { - pub fn to_str(self) -> &'static str { - match self { - Eventtype::Clock => "Wasi::Eventtype::Clock", - Eventtype::FdRead => "Wasi::Eventtype::FdRead", - Eventtype::FdWrite => "Wasi::Eventtype::FdWrite", - } - } -} - -/// 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 Eventtype { - fn from(other: super::wasi_snapshot0::Eventtype) -> Self { - match other { - super::wasi_snapshot0::Eventtype::Clock => Eventtype::Clock, - super::wasi_snapshot0::Eventtype::FdRead => Eventtype::FdRead, - super::wasi_snapshot0::Eventtype::FdWrite => Eventtype::FdWrite, - } - } -} - -/// 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 Clockid { - fn from(other: super::wasi_snapshot0::Clockid) -> Self { - match other { - super::wasi_snapshot0::Clockid::Realtime => Clockid::Realtime, - super::wasi_snapshot0::Clockid::Monotonic => Clockid::Monotonic, - // TODO: no idea what we should be doing here in the end - _ => panic!("unsupported clock wasi_snapshot0 clockid"), - } - } -} - -/// 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 Subclockflags { - fn from(other: super::wasi_snapshot0::Subclockflags) -> Self { - Subclockflags::from_bits_truncate(other.bits()) - } -} - -/// 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 Errno { - fn from(other: super::wasi_snapshot0::Errno) -> Self { - match other { - super::wasi_snapshot0::Errno::Success => Errno::Success, - super::wasi_snapshot0::Errno::Toobig => Errno::Toobig, - super::wasi_snapshot0::Errno::Acces => Errno::Access, - super::wasi_snapshot0::Errno::Addrinuse => Errno::Addrinuse, - super::wasi_snapshot0::Errno::Addrnotavail => Errno::Addrnotavail, - super::wasi_snapshot0::Errno::Afnosupport => Errno::Afnosupport, - super::wasi_snapshot0::Errno::Again => Errno::Again, - super::wasi_snapshot0::Errno::Already => Errno::Already, - super::wasi_snapshot0::Errno::Badf => Errno::Badf, - super::wasi_snapshot0::Errno::Badmsg => Errno::Badmsg, - super::wasi_snapshot0::Errno::Busy => Errno::Busy, - super::wasi_snapshot0::Errno::Canceled => Errno::Canceled, - super::wasi_snapshot0::Errno::Child => Errno::Child, - super::wasi_snapshot0::Errno::Connaborted => Errno::Connaborted, - super::wasi_snapshot0::Errno::Connrefused => Errno::Connrefused, - super::wasi_snapshot0::Errno::Connreset => Errno::Connreset, - super::wasi_snapshot0::Errno::Deadlk => Errno::Deadlk, - super::wasi_snapshot0::Errno::Destaddrreq => Errno::Destaddrreq, - super::wasi_snapshot0::Errno::Dom => Errno::Dom, - super::wasi_snapshot0::Errno::Dquot => Errno::Dquot, - super::wasi_snapshot0::Errno::Exist => Errno::Exist, - super::wasi_snapshot0::Errno::Fault => Errno::Fault, - super::wasi_snapshot0::Errno::Fbig => Errno::Fbig, - super::wasi_snapshot0::Errno::Hostunreach => Errno::Hostunreach, - super::wasi_snapshot0::Errno::Idrm => Errno::Idrm, - super::wasi_snapshot0::Errno::Ilseq => Errno::Ilseq, - super::wasi_snapshot0::Errno::Inprogress => Errno::Inprogress, - super::wasi_snapshot0::Errno::Intr => Errno::Intr, - super::wasi_snapshot0::Errno::Inval => Errno::Inval, - super::wasi_snapshot0::Errno::Io => Errno::Io, - super::wasi_snapshot0::Errno::Isconn => Errno::Isconn, - super::wasi_snapshot0::Errno::Isdir => Errno::Isdir, - super::wasi_snapshot0::Errno::Loop => Errno::Loop, - super::wasi_snapshot0::Errno::Mfile => Errno::Mfile, - super::wasi_snapshot0::Errno::Mlink => Errno::Mlink, - super::wasi_snapshot0::Errno::Msgsize => Errno::Msgsize, - super::wasi_snapshot0::Errno::Multihop => Errno::Multihop, - super::wasi_snapshot0::Errno::Nametoolong => Errno::Nametoolong, - super::wasi_snapshot0::Errno::Netdown => Errno::Netdown, - super::wasi_snapshot0::Errno::Netreset => Errno::Netreset, - super::wasi_snapshot0::Errno::Netunreach => Errno::Netunreach, - super::wasi_snapshot0::Errno::Nfile => Errno::Nfile, - super::wasi_snapshot0::Errno::Nobufs => Errno::Nobufs, - super::wasi_snapshot0::Errno::Nodev => Errno::Nodev, - super::wasi_snapshot0::Errno::Noent => Errno::Noent, - super::wasi_snapshot0::Errno::Noexec => Errno::Noexec, - super::wasi_snapshot0::Errno::Nolck => Errno::Nolck, - super::wasi_snapshot0::Errno::Nolink => Errno::Nolink, - super::wasi_snapshot0::Errno::Nomem => Errno::Nomem, - super::wasi_snapshot0::Errno::Nomsg => Errno::Nomsg, - super::wasi_snapshot0::Errno::Noprotoopt => Errno::Noprotoopt, - super::wasi_snapshot0::Errno::Nospc => Errno::Nospc, - super::wasi_snapshot0::Errno::Nosys => Errno::Nosys, - super::wasi_snapshot0::Errno::Notconn => Errno::Notconn, - super::wasi_snapshot0::Errno::Notdir => Errno::Notdir, - super::wasi_snapshot0::Errno::Notempty => Errno::Notempty, - super::wasi_snapshot0::Errno::Notrecoverable => Errno::Notrecoverable, - super::wasi_snapshot0::Errno::Notsock => Errno::Notsock, - super::wasi_snapshot0::Errno::Notsup => Errno::Notsup, - super::wasi_snapshot0::Errno::Notty => Errno::Notty, - super::wasi_snapshot0::Errno::Nxio => Errno::Nxio, - super::wasi_snapshot0::Errno::Overflow => Errno::Overflow, - super::wasi_snapshot0::Errno::Ownerdead => Errno::Ownerdead, - super::wasi_snapshot0::Errno::Perm => Errno::Perm, - super::wasi_snapshot0::Errno::Pipe => Errno::Pipe, - super::wasi_snapshot0::Errno::Proto => Errno::Proto, - super::wasi_snapshot0::Errno::Protonosupport => Errno::Protonosupport, - super::wasi_snapshot0::Errno::Prototype => Errno::Prototype, - super::wasi_snapshot0::Errno::Range => Errno::Range, - super::wasi_snapshot0::Errno::Rofs => Errno::Rofs, - super::wasi_snapshot0::Errno::Spipe => Errno::Spipe, - super::wasi_snapshot0::Errno::Srch => Errno::Srch, - super::wasi_snapshot0::Errno::Stale => Errno::Stale, - super::wasi_snapshot0::Errno::Timedout => Errno::Timedout, - super::wasi_snapshot0::Errno::Txtbsy => Errno::Txtbsy, - super::wasi_snapshot0::Errno::Xdev => Errno::Xdev, - super::wasi_snapshot0::Errno::Notcapable => Errno::Notcapable, - } - } -} diff --git a/lib/wasi-types-generated/src/wasi_snapshot0/bindings.rs b/lib/wasi-types-generated/src/wasi_snapshot0/bindings.rs deleted file mode 100644 index 28de26091a2..00000000000 --- a/lib/wasi-types-generated/src/wasi_snapshot0/bindings.rs +++ /dev/null @@ -1,9 +0,0 @@ -#[allow(clippy::all)] -pub mod wasi_snapshot0 { - #[allow(unused_imports)] - use wit_bindgen_wasmer::{anyhow, wasmer}; - #[allow(unused_imports)] - use wasmer::AsStoreMut as _; - #[allow(unused_imports)] - use wasmer::AsStoreRef as _; -} diff --git a/lib/wasi-types-generated/src/wasi_snapshot0/mod.rs b/lib/wasi-types-generated/src/wasi_snapshot0/mod.rs deleted file mode 100644 index 50e78557b1f..00000000000 --- a/lib/wasi-types-generated/src/wasi_snapshot0/mod.rs +++ /dev/null @@ -1,494 +0,0 @@ -mod bindings; -pub use bindings::wasi_snapshot0::*; - -use std::mem::MaybeUninit; -use wasmer_types::ValueType; - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for Errno { - #[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]) {} -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for Eventtype { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -// 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 Eventrwflags { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -// 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 Clockid { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -// 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 Preopentype { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for Fdstat { - 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)*) + std::mem::size_of_val(&self.$($f)*) - }; - } - macro_rules! zero { - ($start:expr, $end:expr) => { - for i in $start..$end { - bytes[i] = MaybeUninit::new(0); - } - }; - } - - self.fs_filetype - .zero_padding_bytes(&mut bytes[field!(fs_filetype)..field_end!(fs_filetype)]); - zero!(field_end!(fs_filetype), field!(fs_flags)); - - self.fs_flags - .zero_padding_bytes(&mut bytes[field!(fs_flags)..field_end!(fs_flags)]); - zero!(field_end!(fs_flags), field!(fs_rights_base)); - - self.fs_rights_base - .zero_padding_bytes(&mut bytes[field!(fs_rights_base)..field_end!(fs_rights_base)]); - zero!( - field_end!(fs_rights_inheriting), - std::mem::size_of_val(self) - ); - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for SubscriptionClock { - 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)*) + std::mem::size_of_val(&self.$($f)*) - }; - } - macro_rules! zero { - ($start:expr, $end:expr) => { - for i in $start..$end { - bytes[i] = MaybeUninit::new(0); - } - }; - } - - self.identifier - .zero_padding_bytes(&mut bytes[field!(identifier)..field_end!(identifier)]); - zero!(field_end!(identifier), field!(id)); - - self.id - .zero_padding_bytes(&mut bytes[field!(id)..field_end!(id)]); - zero!(field_end!(id), field!(timeout)); - - self.timeout - .zero_padding_bytes(&mut bytes[field!(timeout)..field_end!(timeout)]); - zero!(field_end!(timeout), field!(precision)); - - self.precision - .zero_padding_bytes(&mut bytes[field!(precision)..field_end!(precision)]); - zero!(field_end!(precision), field!(flags)); - - self.flags - .zero_padding_bytes(&mut bytes[field!(flags)..field_end!(flags)]); - zero!(field_end!(flags), std::mem::size_of_val(self)); - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::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::Acces, - 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, - // TODO: What should we map invalid native values to? - _ => Self::Inval, - } - } - - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } - - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::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) - } - - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Eventrwflags { - 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 u8) - } - - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Subclockflags { - 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 u8) - } - - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::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, - 2 => Self::ProcessCputimeId, - 3 => Self::ThreadCputimeId, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } - - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::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 u8) - } - - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } - - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} - -impl Eventtype { - pub fn to_str(self) -> &'static str { - match self { - Eventtype::Clock => "Wasi::Eventtype::Clock", - Eventtype::FdRead => "Wasi::Eventtype::FdRead", - Eventtype::FdWrite => "Wasi::Eventtype::FdWrite", - } - } -} - -/// 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 Eventtype { - fn from(other: super::wasi_io_typenames::Eventtype) -> Self { - match other { - super::wasi_io_typenames::Eventtype::Clock => Eventtype::Clock, - super::wasi_io_typenames::Eventtype::FdRead => Eventtype::FdRead, - super::wasi_io_typenames::Eventtype::FdWrite => Eventtype::FdWrite, - } - } -} - -/// 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 Errno { - fn from(other: super::wasi_io_typenames::Errno) -> Self { - match other { - super::wasi_io_typenames::Errno::Success => Errno::Success, - super::wasi_io_typenames::Errno::Toobig => Errno::Toobig, - super::wasi_io_typenames::Errno::Access => Errno::Acces, - super::wasi_io_typenames::Errno::Addrinuse => Errno::Addrinuse, - super::wasi_io_typenames::Errno::Addrnotavail => Errno::Addrnotavail, - super::wasi_io_typenames::Errno::Afnosupport => Errno::Afnosupport, - super::wasi_io_typenames::Errno::Again => Errno::Again, - super::wasi_io_typenames::Errno::Already => Errno::Already, - super::wasi_io_typenames::Errno::Badf => Errno::Badf, - super::wasi_io_typenames::Errno::Badmsg => Errno::Badmsg, - super::wasi_io_typenames::Errno::Busy => Errno::Busy, - super::wasi_io_typenames::Errno::Canceled => Errno::Canceled, - super::wasi_io_typenames::Errno::Child => Errno::Child, - super::wasi_io_typenames::Errno::Connaborted => Errno::Connaborted, - super::wasi_io_typenames::Errno::Connrefused => Errno::Connrefused, - super::wasi_io_typenames::Errno::Connreset => Errno::Connreset, - super::wasi_io_typenames::Errno::Deadlk => Errno::Deadlk, - super::wasi_io_typenames::Errno::Destaddrreq => Errno::Destaddrreq, - super::wasi_io_typenames::Errno::Dom => Errno::Dom, - super::wasi_io_typenames::Errno::Dquot => Errno::Dquot, - super::wasi_io_typenames::Errno::Exist => Errno::Exist, - super::wasi_io_typenames::Errno::Fault => Errno::Fault, - super::wasi_io_typenames::Errno::Fbig => Errno::Fbig, - super::wasi_io_typenames::Errno::Hostunreach => Errno::Hostunreach, - super::wasi_io_typenames::Errno::Idrm => Errno::Idrm, - super::wasi_io_typenames::Errno::Ilseq => Errno::Ilseq, - super::wasi_io_typenames::Errno::Inprogress => Errno::Inprogress, - super::wasi_io_typenames::Errno::Intr => Errno::Intr, - super::wasi_io_typenames::Errno::Inval => Errno::Inval, - super::wasi_io_typenames::Errno::Io => Errno::Io, - super::wasi_io_typenames::Errno::Isconn => Errno::Isconn, - super::wasi_io_typenames::Errno::Isdir => Errno::Isdir, - super::wasi_io_typenames::Errno::Loop => Errno::Loop, - super::wasi_io_typenames::Errno::Mfile => Errno::Mfile, - super::wasi_io_typenames::Errno::Mlink => Errno::Mlink, - super::wasi_io_typenames::Errno::Msgsize => Errno::Msgsize, - super::wasi_io_typenames::Errno::Multihop => Errno::Multihop, - super::wasi_io_typenames::Errno::Nametoolong => Errno::Nametoolong, - super::wasi_io_typenames::Errno::Netdown => Errno::Netdown, - super::wasi_io_typenames::Errno::Netreset => Errno::Netreset, - super::wasi_io_typenames::Errno::Netunreach => Errno::Netunreach, - super::wasi_io_typenames::Errno::Nfile => Errno::Nfile, - super::wasi_io_typenames::Errno::Nobufs => Errno::Nobufs, - super::wasi_io_typenames::Errno::Nodev => Errno::Nodev, - super::wasi_io_typenames::Errno::Noent => Errno::Noent, - super::wasi_io_typenames::Errno::Noexec => Errno::Noexec, - super::wasi_io_typenames::Errno::Nolck => Errno::Nolck, - super::wasi_io_typenames::Errno::Nolink => Errno::Nolink, - super::wasi_io_typenames::Errno::Nomem => Errno::Nomem, - super::wasi_io_typenames::Errno::Nomsg => Errno::Nomsg, - super::wasi_io_typenames::Errno::Noprotoopt => Errno::Noprotoopt, - super::wasi_io_typenames::Errno::Nospc => Errno::Nospc, - super::wasi_io_typenames::Errno::Nosys => Errno::Nosys, - super::wasi_io_typenames::Errno::Notconn => Errno::Notconn, - super::wasi_io_typenames::Errno::Notdir => Errno::Notdir, - super::wasi_io_typenames::Errno::Notempty => Errno::Notempty, - super::wasi_io_typenames::Errno::Notrecoverable => Errno::Notrecoverable, - super::wasi_io_typenames::Errno::Notsock => Errno::Notsock, - super::wasi_io_typenames::Errno::Notsup => Errno::Notsup, - super::wasi_io_typenames::Errno::Notty => Errno::Notty, - super::wasi_io_typenames::Errno::Nxio => Errno::Nxio, - super::wasi_io_typenames::Errno::Overflow => Errno::Overflow, - super::wasi_io_typenames::Errno::Ownerdead => Errno::Ownerdead, - super::wasi_io_typenames::Errno::Perm => Errno::Perm, - super::wasi_io_typenames::Errno::Pipe => Errno::Pipe, - super::wasi_io_typenames::Errno::Proto => Errno::Proto, - super::wasi_io_typenames::Errno::Protonosupport => Errno::Protonosupport, - super::wasi_io_typenames::Errno::Prototype => Errno::Prototype, - super::wasi_io_typenames::Errno::Range => Errno::Range, - super::wasi_io_typenames::Errno::Rofs => Errno::Rofs, - super::wasi_io_typenames::Errno::Spipe => Errno::Spipe, - super::wasi_io_typenames::Errno::Srch => Errno::Srch, - super::wasi_io_typenames::Errno::Stale => Errno::Stale, - super::wasi_io_typenames::Errno::Timedout => Errno::Timedout, - super::wasi_io_typenames::Errno::Txtbsy => Errno::Txtbsy, - super::wasi_io_typenames::Errno::Xdev => Errno::Xdev, - super::wasi_io_typenames::Errno::Notcapable => Errno::Notcapable, - } - } -} diff --git a/lib/wasi-types-generated/wit/wasi.wit b/lib/wasi-types-generated/wit/wasi.wit index 650aae372ce..3fc70c5e057 100644 --- a/lib/wasi-types-generated/wit/wasi.wit +++ b/lib/wasi-types-generated/wit/wasi.wit @@ -4,14 +4,18 @@ -/// Dummy function to expose type into generated code -fd-dummy-func: func(dummy: fd) -/// Dummy function to expose type into generated code -dirent-dummy-func: func(dummy: dirent) -/// Dummy function to expose type into generated code -fdstat-dummy-func: func(dummy: fdstat) -/// Dummy function to expose type into generated code -subscription-clock-dummy-func: func(dummy: subscription-clock) +/// Dummy function to expose types into generated code +expose-types-dummy-func: func( + fd: fd, + dirent: dirent, + event-enum: event-enum, + event: event, + fdstat: fdstat, + subscription-clock: subscription-clock, + snapshot0-subscription-clock: snapshot0-subscription-clock, + subscription: subscription, + snapshot0-subscription: snapshot0-subscription, +) @@ -248,8 +252,8 @@ enum errno { notcapable, } -/// File descriptor rights, determining which actions may be performed, snapshot0 version. -flags snapshot0-rights { +/// File descriptor rights, determining which actions may be performed. +flags rights { // TODO: wit doesnt appear to support repr // flags (@witx repr u64) @@ -349,117 +353,6 @@ flags snapshot0-rights { sock-send-to, } -/// File descriptor rights, determining which actions may be performed. -flags rights { - // TODO: wit appears to not have support for flags type size - //(@witx repr u64) - - /// The right to invoke `fd_datasync`. - /// - /// If `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 `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 `path_open` is set, the right to invoke `path_open` with `oflags::create`. - 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. - /// If `path_open` is set, includes the right to invoke `path_open` with `oflags::trunc`. - /// Note: there is no function named `path_filestat_set_size`. This follows POSIX design, - /// which only has `ftruncate` and does not provide `ftruncateat`. - /// While such function would be desirable from the API design perspective, there are virtually - /// no use cases for it since no code written for POSIX systems would use it. - /// Moreover, implementing it would require multiple syscalls, leading to inferior performance. - path-filestat-set-size, - /// The right to invoke `path_filestat_set_times`. - path-filestat-set-times, - /// The right to invoke `path_permissions_set`. - path-permissions-set, - /// 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 `fd_permissions_set`. - fd-permissions-set, - /// 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, -} - -/// The type of a file descriptor or file. -enum snapshot0-filetype { - // TODO: wit appears to not have support for enum type size - //enum (@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 type of a file descriptor or file. enum filetype { // TODO: wit appears to not have support for enum type size @@ -634,10 +527,10 @@ flags subclockflags { /// The contents of a `subscription` when type is `eventtype::clock`. record snapshot0-subscription-clock { -/// The user-defined unique identifier of the clock. + /// The user-defined unique identifier of the clock. identifier: userdata, /// The clock against which to compare the timestamp. - id: clockid, + id: snapshot0-clockid, /// The absolute or relative timestamp. timeout: timestamp, /// The amount of time that the implementation may wait additionally @@ -650,7 +543,7 @@ record snapshot0-subscription-clock { /// The contents of a `subscription` when type is `eventtype::clock`. record subscription-clock { /// The clock against which to compare the timestamp. - id: clockid, + clock-id: clockid, /// The absolute or relative timestamp. timeout: timestamp, /// The amount of time that the implementation may wait additionally @@ -695,10 +588,11 @@ record event { /// 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-u { +variant event-enum { // TODO: wit appears to not have support for tag type //(@witx tag $eventtype) fd-read(event-fd-readwrite), @@ -719,3 +613,38 @@ record snapshot0-event { /// `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, +} diff --git a/lib/wasi-types/src/directory.rs b/lib/wasi-types/src/directory.rs index 585fcff762a..d7bdbfe231f 100644 --- a/lib/wasi-types/src/directory.rs +++ b/lib/wasi-types/src/directory.rs @@ -1,9 +1,9 @@ use std::mem; -use wasmer_wasi_types_generated::wasi_snapshot0; +use wasmer_wasi_types_generated::wasi; -pub const __WASI_DIRCOOKIE_START: wasi_snapshot0::Dircookie = 0; +pub const __WASI_DIRCOOKIE_START: wasi::Dircookie = 0; -pub fn dirent_to_le_bytes(ent: &wasi_snapshot0::Dirent) -> Vec { +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()) @@ -11,22 +11,22 @@ pub fn dirent_to_le_bytes(ent: &wasi_snapshot0::Dirent) -> Vec { .chain(u32::from(ent.d_type as u8).to_le_bytes()) .collect(); - assert_eq!(out.len(), mem::size_of::()); + assert_eq!(out.len(), mem::size_of::()); out } #[cfg(test)] mod tests { use super::dirent_to_le_bytes; - use wasmer_wasi_types_generated::wasi_snapshot0; + use wasmer_wasi_types_generated::wasi; #[test] fn test_dirent_to_le_bytes() { - let s = wasi_snapshot0::Dirent { + let s = wasi::Dirent { d_next: 0x0123456789abcdef, d_ino: 0xfedcba9876543210, d_namlen: 0xaabbccdd, - d_type: wasi_snapshot0::Filetype::Directory, + d_type: wasi::Filetype::Directory, }; assert_eq!( @@ -59,7 +59,7 @@ mod tests { // // d_type // plus padding - wasi_snapshot0::Filetype::Directory as u8, + wasi::Filetype::Directory as u8, 0x00, 0x00, 0x00, diff --git a/lib/wasi-types/src/event.rs b/lib/wasi-types/src/event.rs index 5c12491605f..ab949202d1d 100644 --- a/lib/wasi-types/src/event.rs +++ b/lib/wasi-types/src/event.rs @@ -1,3 +1,4 @@ +/* TODO: if required, move to generated wasi::Event type use crate::*; use std::{ fmt, @@ -5,13 +6,13 @@ use std::{ }; use wasmer_derive::ValueType; use wasmer_types::ValueType; -use wasmer_wasi_types_generated::wasi_snapshot0; +use wasmer_wasi_types_generated::wasi; #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] #[repr(C)] pub struct __wasi_event_fd_readwrite_t { pub nbytes: __wasi_filesize_t, - pub flags: wasi_snapshot0::Eventrwflags, + pub flags: wasi::Eventrwflags, } #[derive(Copy, Clone)] @@ -33,7 +34,7 @@ impl fmt::Debug for __wasi_event_u { pub enum EventEnum { FdReadWrite { nbytes: __wasi_filesize_t, - flags: wasi_snapshot0::Eventrwflags, + flags: wasi::Eventrwflags, }, } @@ -47,24 +48,13 @@ impl EventEnum { } } -#[derive(Debug, Copy, Clone)] -#[repr(C)] -pub struct __wasi_event_t { - pub userdata: __wasi_userdata_t, - pub error: wasi_snapshot0::Errno, - pub type_: wasi_snapshot0::Eventtype, - pub u: __wasi_event_u, -} - impl __wasi_event_t { pub fn tagged(&self) -> Option { match self.type_ { - wasi_snapshot0::Eventtype::FdRead | wasi_snapshot0::Eventtype::FdWrite => { - Some(EventEnum::FdReadWrite { - nbytes: unsafe { self.u.fd_readwrite.nbytes }, - flags: unsafe { self.u.fd_readwrite.flags }, - }) - } + wasi::Eventtype::FdRead | wasi::Eventtype::FdWrite => Some(EventEnum::FdReadWrite { + nbytes: unsafe { self.u.fd_readwrite.nbytes }, + flags: unsafe { self.u.fd_readwrite.flags }, + }), _ => None, } } @@ -99,7 +89,7 @@ unsafe impl ValueType for __wasi_event_t { .zero_padding_bytes(&mut bytes[field!(type_)..field_end!(type_)]); zero!(field_end!(type_), field!(u)); match self.type_ { - wasi_snapshot0::Eventtype::FdRead | wasi_snapshot0::Eventtype::FdWrite => unsafe { + wasi::Eventtype::FdRead | wasi::Eventtype::FdWrite => unsafe { self.u.fd_readwrite.zero_padding_bytes( &mut bytes[field!(u.fd_readwrite)..field_end!(u.fd_readwrite)], ); @@ -110,3 +100,4 @@ unsafe impl ValueType for __wasi_event_t { zero!(field_end!(u), mem::size_of_val(self)); } } +*/ diff --git a/lib/wasi-types/src/file.rs b/lib/wasi-types/src/file.rs index 89962d40aa8..2325cd982a4 100644 --- a/lib/wasi-types/src/file.rs +++ b/lib/wasi-types/src/file.rs @@ -5,13 +5,13 @@ use std::{ }; use wasmer_derive::ValueType; use wasmer_types::ValueType; -use wasmer_wasi_types_generated::wasi_snapshot0; +use wasmer_wasi_types_generated::wasi::{Fd, Filetype, Preopentype, Rights}; pub type __wasi_device_t = u64; -pub const __WASI_STDIN_FILENO: wasi_snapshot0::Fd = 0; -pub const __WASI_STDOUT_FILENO: wasi_snapshot0::Fd = 1; -pub const __WASI_STDERR_FILENO: wasi_snapshot0::Fd = 2; +pub const __WASI_STDIN_FILENO: Fd = 0; +pub const __WASI_STDOUT_FILENO: Fd = 1; +pub const __WASI_STDERR_FILENO: Fd = 2; pub type __wasi_pid_t = u32; pub type __wasi_tid_t = u32; @@ -40,7 +40,7 @@ impl fmt::Debug for __wasi_prestat_u { #[derive(Debug, Copy, Clone)] #[repr(C)] pub struct __wasi_prestat_t { - pub pr_type: wasi_snapshot0::Preopentype, + pub pr_type: Preopentype, pub u: __wasi_prestat_u, } @@ -63,7 +63,7 @@ impl __wasi_prestat_t { #[allow(clippy::trivially_copy_pass_by_ref)] pub fn tagged(&self) -> Option { match self.pr_type { - wasi_snapshot0::Preopentype::Dir => Some(PrestatEnum::Dir { + Preopentype::Dir => Some(PrestatEnum::Dir { pr_name_len: unsafe { self.u.dir.pr_name_len }, }), } @@ -93,7 +93,7 @@ unsafe impl ValueType for __wasi_prestat_t { .zero_padding_bytes(&mut bytes[field!(pr_type)..field_end!(pr_type)]); zero!(field_end!(pr_type), field!(u)); match self.pr_type { - wasi_snapshot0::Preopentype::Dir => unsafe { + Preopentype::Dir => unsafe { self.u .dir .zero_padding_bytes(&mut bytes[field!(u.dir)..field_end!(u.dir)]); @@ -113,7 +113,7 @@ pub type __wasi_filesize_t = u64; pub struct __wasi_filestat_t { pub st_dev: __wasi_device_t, pub st_ino: __wasi_inode_t, - pub st_filetype: wasi_snapshot0::Filetype, + pub st_filetype: Filetype, pub st_nlink: __wasi_linkcount_t, pub st_size: __wasi_filesize_t, pub st_atim: __wasi_timestamp_t, @@ -126,7 +126,7 @@ impl Default for __wasi_filestat_t { __wasi_filestat_t { st_dev: Default::default(), st_ino: Default::default(), - st_filetype: wasi_snapshot0::Filetype::Unknown, + st_filetype: Filetype::Unknown, st_nlink: 1, st_size: Default::default(), st_atim: Default::default(), @@ -147,11 +147,7 @@ impl fmt::Debug for __wasi_filestat_t { .field("st_ino", &self.st_ino) .field( "st_filetype", - &format!( - "{} ({})", - wasi_filetype_to_name(self.st_filetype), - self.st_filetype as u8, - ), + &format!("{} ({})", self.st_filetype.name(), self.st_filetype as u8,), ) .field("st_nlink", &self.st_nlink) .field("st_size", &self.st_size) @@ -171,19 +167,6 @@ impl fmt::Debug for __wasi_filestat_t { } } -pub fn wasi_filetype_to_name(ft: wasi_snapshot0::Filetype) -> &'static str { - match ft { - wasi_snapshot0::Filetype::Unknown => "Unknown", - wasi_snapshot0::Filetype::BlockDevice => "Block device", - wasi_snapshot0::Filetype::CharacterDevice => "Character device", - wasi_snapshot0::Filetype::Directory => "Directory", - wasi_snapshot0::Filetype::RegularFile => "Regular file", - wasi_snapshot0::Filetype::SocketDgram => "Socket dgram", - wasi_snapshot0::Filetype::SocketStream => "Socket stream", - wasi_snapshot0::Filetype::SymbolicLink => "Symbolic link", - } -} - 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; @@ -205,54 +188,18 @@ pub const __WASI_O_TRUNC: __wasi_oflags_t = 1 << 3; /// function for debugging rights issues #[allow(dead_code)] -pub fn print_right_set(rights: wasi_snapshot0::Rights) { +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 & wasi_snapshot0::Rights::from_bits(1 << i).unwrap(); + let cur_right = rights & Rights::from_bits(1 << i).unwrap(); if !cur_right.is_empty() { - right_set.insert(right_to_string(cur_right).unwrap_or("INVALID RIGHT")); + right_set.insert(cur_right.to_str().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_snapshot0::Rights) -> Option<&'static str> { - Some(match right { - wasi_snapshot0::Rights::FD_DATASYNC => "Rights::_FD_DATASYNC", - wasi_snapshot0::Rights::FD_READ => "Rights::FD_READ", - wasi_snapshot0::Rights::FD_SEEK => "Rights::FD_SEEK", - wasi_snapshot0::Rights::FD_FDSTAT_SET_FLAGS => "Rights::FD_FDSTAT_SET_FLAGS", - wasi_snapshot0::Rights::FD_SYNC => "Rights::FD_SYNC", - wasi_snapshot0::Rights::FD_TELL => "Rights::FD_TELL", - wasi_snapshot0::Rights::FD_WRITE => "Rights::FD_WRITE", - wasi_snapshot0::Rights::FD_ADVISE => "Rights::FD_ADVISE", - wasi_snapshot0::Rights::FD_ALLOCATE => "Rights::FD_ALLOCATE", - wasi_snapshot0::Rights::PATH_CREATE_DIRECTORY => "Rights::PATH_CREATE_DIRECTORY", - wasi_snapshot0::Rights::PATH_CREATE_FILE => "Rights::PATH_CREATE_FILE", - wasi_snapshot0::Rights::PATH_LINK_SOURCE => "Rights::PATH_LINK_SOURCE", - wasi_snapshot0::Rights::PATH_LINK_TARGET => "Rights::PATH_LINK_TARGET", - wasi_snapshot0::Rights::PATH_OPEN => "Rights::PATH_OPEN", - wasi_snapshot0::Rights::FD_READDIR => "Rights::FD_READDIR", - wasi_snapshot0::Rights::PATH_READLINK => "Rights::PATH_READLINK", - wasi_snapshot0::Rights::PATH_RENAME_SOURCE => "Rights::PATH_RENAME_SOURCE", - wasi_snapshot0::Rights::PATH_RENAME_TARGET => "Rights::PATH_RENAME_TARGET", - wasi_snapshot0::Rights::PATH_FILESTAT_GET => "Rights::PATH_FILESTAT_GET", - wasi_snapshot0::Rights::PATH_FILESTAT_SET_SIZE => "Rights::PATH_FILESTAT_SET_SIZE", - wasi_snapshot0::Rights::PATH_FILESTAT_SET_TIMES => "Rights::PATH_FILESTAT_SET_TIMES", - wasi_snapshot0::Rights::FD_FILESTAT_GET => "Rights::FD_FILESTAT_GET", - wasi_snapshot0::Rights::FD_FILESTAT_SET_SIZE => "Rights::FD_FILESTAT_SET_SIZE", - wasi_snapshot0::Rights::FD_FILESTAT_SET_TIMES => "Rights::FD_FILESTAT_SET_TIMES", - wasi_snapshot0::Rights::PATH_SYMLINK => "Rights::PATH_SYMLINK", - wasi_snapshot0::Rights::PATH_UNLINK_FILE => "Rights::PATH_UNLINK_FILE", - wasi_snapshot0::Rights::PATH_REMOVE_DIRECTORY => "Rights::PATH_REMOVE_DIRECTORY", - wasi_snapshot0::Rights::POLL_FD_READWRITE => "Rights::POLL_FD_READWRITE", - wasi_snapshot0::Rights::SOCK_SHUTDOWN => "Rights::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; diff --git a/lib/wasi-types/src/subscription.rs b/lib/wasi-types/src/subscription.rs index 5c8303096a2..b2029df2c88 100644 --- a/lib/wasi-types/src/subscription.rs +++ b/lib/wasi-types/src/subscription.rs @@ -2,128 +2,47 @@ use crate::*; use std::convert::TryFrom; use std::fmt; use std::mem::{self, MaybeUninit}; -use wasmer_derive::ValueType; use wasmer_types::ValueType; -use wasmer_wasi_types_generated::{wasi_io_typenames, wasi_snapshot0}; - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_subscription_clock_t { - pub clock_id: wasi_io_typenames::Clockid, - pub timeout: wasi_io_typenames::Timestamp, - pub precision: wasi_io_typenames::Timestamp, - pub flags: wasi_io_typenames::Subclockflags, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_subscription_fs_readwrite_t { - pub fd: wasi_io_typenames::Fd, -} - -#[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_io_typenames::Eventtype, - pub u: __wasi_subscription_u, -} - -impl From for __wasi_subscription_t { - fn from(orig: super::snapshot0::__wasi_subscription_t) -> Self { - Self { - userdata: orig.userdata, - type_: wasi_io_typenames::Eventtype::from(orig.type_), - u: if orig.type_ == wasi_snapshot0::Eventtype::Clock { - __wasi_subscription_u { - clock: __wasi_subscription_clock_t { - clock_id: wasi_io_typenames::Clockid::from(unsafe { orig.u.clock.id }), - timeout: unsafe { orig.u.clock.timeout }, - precision: unsafe { orig.u.clock.precision }, - flags: wasi_io_typenames::Subclockflags::from(unsafe { - orig.u.clock.flags - }), - }, - } - } else { - __wasi_subscription_u { - fd_readwrite: unsafe { orig.u.fd_readwrite }, - } - }, - } - } -} +use wasmer_wasi_types_generated::wasi::{ + Clockid, Errno, Eventtype, Fd, Subclockflags, Subscription, SubscriptionClock, + SubscriptionEnum, SubscriptionFsReadwrite, Timestamp, Userdata, +}; /// 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), + Clock(SubscriptionClock), + Read(SubscriptionFsReadwrite), + Write(SubscriptionFsReadwrite), } impl EventType { - pub fn raw_tag(&self) -> wasi_io_typenames::Eventtype { + pub fn raw_tag(&self) -> Eventtype { match self { - EventType::Clock(_) => wasi_io_typenames::Eventtype::Clock, - EventType::Read(_) => wasi_io_typenames::Eventtype::FdRead, - EventType::Write(_) => wasi_io_typenames::Eventtype::FdWrite, + EventType::Clock(_) => Eventtype::Clock, + EventType::Read(_) => Eventtype::FdRead, + EventType::Write(_) => Eventtype::FdWrite, } } } -/// 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_io_typenames::Errno; - - fn try_from(ws: __wasi_subscription_t) -> Result { - Ok(Self { - user_data: ws.userdata, - event_type: match ws.type_ { - wasi_io_typenames::Eventtype::Clock => EventType::Clock(unsafe { ws.u.clock }), - wasi_io_typenames::Eventtype::FdRead => { - EventType::Read(unsafe { ws.u.fd_readwrite }) - } - wasi_io_typenames::Eventtype::FdWrite => { - EventType::Write(unsafe { ws.u.fd_readwrite }) - } - }, - }) - } -} - +/* TODO: re-enable and adjust if still required impl TryFrom for __wasi_subscription_t { - type Error = wasi_io_typenames::Errno; + type Error = Errno; fn try_from(ws: WasiSubscription) -> Result { #[allow(unreachable_patterns)] let (type_, u) = match ws.event_type { - EventType::Clock(c) => ( - wasi_io_typenames::Eventtype::Clock, - __wasi_subscription_u { clock: c }, - ), + EventType::Clock(c) => (Eventtype::Clock, __wasi_subscription_u { clock: c }), EventType::Read(rw) => ( - wasi_io_typenames::Eventtype::FdRead, + Eventtype::FdRead, __wasi_subscription_u { fd_readwrite: rw }, ), EventType::Write(rw) => ( - wasi_io_typenames::Eventtype::FdWrite, + Eventtype::FdWrite, __wasi_subscription_u { fd_readwrite: rw }, ), - _ => return Err(wasi_io_typenames::Errno::Inval), + _ => return Err(Errno::Inval), }; Ok(Self { @@ -142,9 +61,8 @@ impl fmt::Debug for __wasi_subscription_t { .field( "u", match self.type_ { - wasi_io_typenames::Eventtype::Clock => unsafe { &self.u.clock }, - wasi_io_typenames::Eventtype::FdRead - | wasi_io_typenames::Eventtype::FdWrite => unsafe { &self.u.fd_readwrite }, + Eventtype::Clock => unsafe { &self.u.clock }, + Eventtype::FdRead | Eventtype::FdWrite => unsafe { &self.u.fd_readwrite }, }, ) .finish() @@ -177,13 +95,13 @@ unsafe impl ValueType for __wasi_subscription_t { .zero_padding_bytes(&mut bytes[field!(type_)..field_end!(type_)]); zero!(field_end!(type_), field!(u)); match self.type_ { - wasi_io_typenames::Eventtype::FdRead | wasi_io_typenames::Eventtype::FdWrite => unsafe { + Eventtype::FdRead | Eventtype::FdWrite => 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_io_typenames::Eventtype::Clock => unsafe { + Eventtype::Clock => unsafe { self.u .clock .zero_padding_bytes(&mut bytes[field!(u.clock)..field_end!(u.clock)]); @@ -202,14 +120,12 @@ pub enum SubscriptionEnum { impl __wasi_subscription_t { pub fn tagged(&self) -> Option { match self.type_ { - wasi_io_typenames::Eventtype::Clock => { - Some(SubscriptionEnum::Clock(unsafe { self.u.clock })) - } - wasi_io_typenames::Eventtype::FdRead | wasi_io_typenames::Eventtype::FdWrite => { - Some(SubscriptionEnum::FdReadWrite(unsafe { - self.u.fd_readwrite - })) - } + Eventtype::Clock => Some(SubscriptionEnum::Clock(unsafe { self.u.clock })), + Eventtype::FdRead | Eventtype::FdWrite => Some(SubscriptionEnum::FdReadWrite(unsafe { + self.u.fd_readwrite + })), } } } + +*/ diff --git a/lib/wasi-types/src/versions/snapshot0.rs b/lib/wasi-types/src/versions/snapshot0.rs index 7b5c41c5f16..1fe9e45e51f 100644 --- a/lib/wasi-types/src/versions/snapshot0.rs +++ b/lib/wasi-types/src/versions/snapshot0.rs @@ -3,68 +3,12 @@ use std::fmt; use std::mem::{self, MaybeUninit}; use wasmer_derive::ValueType; use wasmer_types::ValueType; -use wasmer_wasi_types_generated::wasi_snapshot0; +use wasmer_wasi_types_generated::wasi::{ + Eventtype, Filetype, Snapshot0SubscriptionClock as SubscriptionClock, +}; pub type __wasi_linkcount_t = u32; -#[derive(Copy, Clone)] -#[repr(C)] -pub union __wasi_subscription_u { - pub clock: wasi_snapshot0::SubscriptionClock, - 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_snapshot0::Eventtype, - 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_snapshot0::Eventtype::FdRead | wasi_snapshot0::Eventtype::FdWrite => 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_snapshot0::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_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; @@ -75,7 +19,7 @@ pub const __WASI_WHENCE_SET: u8 = 2; pub struct __wasi_filestat_t { pub st_dev: __wasi_device_t, pub st_ino: __wasi_inode_t, - pub st_filetype: wasi_snapshot0::Filetype, + pub st_filetype: Filetype, pub st_nlink: __wasi_linkcount_t, pub st_size: __wasi_filesize_t, pub st_atim: __wasi_timestamp_t, @@ -94,11 +38,7 @@ impl fmt::Debug for __wasi_filestat_t { .field("st_ino", &self.st_ino) .field( "st_filetype", - &format!( - "{} ({})", - wasi_filetype_to_name(self.st_filetype), - self.st_filetype as u8, - ), + &format!("{} ({})", self.st_filetype.name(), self.st_filetype as u8,), ) .field("st_nlink", &self.st_nlink) .field("st_size", &self.st_size) @@ -118,6 +58,7 @@ impl fmt::Debug for __wasi_filestat_t { } } +/* TODO: re-enable and adjust if required impl fmt::Debug for __wasi_subscription_t { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("__wasi_subscription_t") @@ -126,12 +67,11 @@ impl fmt::Debug for __wasi_subscription_t { .field( "u", match self.type_ { - wasi_snapshot0::Eventtype::Clock => unsafe { &self.u.clock }, - wasi_snapshot0::Eventtype::FdRead | wasi_snapshot0::Eventtype::FdWrite => unsafe { - &self.u.fd_readwrite - }, + Eventtype::Clock => unsafe { &self.u.clock }, + Eventtype::FdRead | Eventtype::FdWrite => unsafe { &self.u.fd_readwrite }, }, ) .finish() } } +*/ diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index 7245e97e27d..f158b050ef2 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -65,7 +65,7 @@ use wasmer::{ imports, namespace, AsStoreMut, AsStoreRef, Exports, Function, FunctionEnv, Imports, Memory, Memory32, MemoryAccessError, MemorySize, MemoryView, Module, TypedFunction, }; -use wasmer_wasi_types_generated::wasi_snapshot0; +use wasmer_wasi_types_generated::wasi::{Errno, Snapshot0Clockid}; pub use runtime::{ PluggableRuntimeImplementation, WasiRuntimeImplementation, WasiThreadError, WasiTtyState, @@ -292,11 +292,11 @@ impl WasiEnv { pub fn sleep(&self, duration: Duration) -> Result<(), WasiError> { let duration = duration.as_nanos(); let start = - platform_clock_time_get(wasi_snapshot0::Clockid::Monotonic, 1_000_000).unwrap() as u128; + platform_clock_time_get(Snapshot0Clockid::Monotonic, 1_000_000).unwrap() as u128; self.yield_now()?; loop { - let now = platform_clock_time_get(wasi_snapshot0::Clockid::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 => { @@ -775,12 +775,12 @@ fn generate_import_object_wasix64_v1( } } -fn mem_error_to_wasi(err: MemoryAccessError) -> types::wasi_snapshot0::Errno { +fn mem_error_to_wasi(err: MemoryAccessError) -> Errno { match err { - MemoryAccessError::HeapOutOfBounds => types::wasi_snapshot0::Errno::Fault, - MemoryAccessError::Overflow => types::wasi_snapshot0::Errno::Overflow, - MemoryAccessError::NonUtf8String => types::wasi_snapshot0::Errno::Inval, - _ => types::wasi_snapshot0::Errno::Inval, + MemoryAccessError::HeapOutOfBounds => Errno::Fault, + MemoryAccessError::Overflow => Errno::Overflow, + MemoryAccessError::NonUtf8String => Errno::Inval, + _ => Errno::Inval, } } diff --git a/lib/wasi/src/macros.rs b/lib/wasi/src/macros.rs index 4e8db8d4c4e..2f3da95588d 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_io_typenames::Errno> = $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_io_typenames::Errno> = $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_io_typenames::Errno> = $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 == crate::syscalls::types::wasi_io_typenames::Errno::Intr { + if err == crate::syscalls::types::wasi::Errno::Intr { $thread.yield_now()?; } tracing::debug!("wasi::wasi_try_ok::err: {:?}", err); @@ -71,21 +71,21 @@ macro_rules! wasi_try_bus { }}; } -/// Like `wasi_try` but converts a `MemoryAccessError` to a wasi_io_typenames::Errno`. +/// 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 `__bus_errno_t`. 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_io_typenames::Errno`. +/// 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 b2c345dcdfc..a931272ec23 100644 --- a/lib/wasi/src/runtime.rs +++ b/lib/wasi/src/runtime.rs @@ -4,7 +4,7 @@ use std::sync::atomic::{AtomicU32, Ordering}; use thiserror::Error; use wasmer_vbus::{UnsupportedVirtualBus, VirtualBus}; use wasmer_vnet::VirtualNetworking; -use wasmer_wasi_types_generated::wasi_snapshot0; +use wasmer_wasi_types_generated::wasi::Errno; use super::WasiError; use super::WasiThreadId; @@ -17,11 +17,11 @@ pub enum WasiThreadError { MethodNotFound, } -impl From for wasi_snapshot0::Errno { - fn from(a: WasiThreadError) -> wasi_snapshot0::Errno { +impl From for Errno { + fn from(a: WasiThreadError) -> Errno { match a { - WasiThreadError::Unsupported => wasi_snapshot0::Errno::Notsup, - WasiThreadError::MethodNotFound => wasi_snapshot0::Errno::Inval, + 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 7b815354006..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_snapshot0::Fd) -> 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 c6fbab7abb1..bb262c2344a 100644 --- a/lib/wasi/src/state/mod.rs +++ b/lib/wasi/src/state/mod.rs @@ -52,8 +52,8 @@ use std::{ }; use tracing::{debug, trace}; use wasmer_vbus::BusSpawnedProcess; -use wasmer_wasi_types_generated::wasi_io_typenames::{ - Errno, Fd as WasiFd, Fdflags, Filetype, Preopentype, Rights, +use wasmer_wasi_types_generated::wasi::{ + Errno, Fd as WasiFd, Fdflags, Fdstat, Filetype, Preopentype, Rights, }; use wasmer_vfs::{FileSystem, FsError, OpenOptions, VirtualFile}; @@ -856,7 +856,7 @@ impl WasiFs { pub fn get_current_dir( &self, inodes: &mut WasiInodes, - base: Fd, + base: WasiFd, ) -> Result<(Inode, String), Errno> { self.get_current_dir_inner(inodes, base, 0) } @@ -1163,11 +1163,11 @@ impl WasiFs { &self, inodes: &WasiInodes, path: &'path Path, - ) -> Result<(Fd, &'path Path), Errno> { + ) -> Result<(WasiFd, &'path Path), Errno> { enum BaseFdAndRelPath<'a> { None, BestMatch { - fd: Fd, + fd: WasiFd, rel_path: &'a Path, max_seen: usize, }, @@ -1221,7 +1221,7 @@ impl WasiFs { pub(crate) fn path_depth_from_fd( &self, inodes: &WasiInodes, - fd: Fd, + fd: WasiFd, inode: Inode, ) -> Result { let mut counter = 0; @@ -1254,7 +1254,7 @@ impl WasiFs { pub(crate) fn get_inode_at_path( &self, inodes: &mut WasiInodes, - base: Fd, + base: WasiFd, path: &str, follow_symlinks: bool, ) -> Result { @@ -1273,7 +1273,7 @@ impl WasiFs { pub(crate) fn get_parent_inode_at_path( &self, inodes: &mut WasiInodes, - base: Fd, + base: WasiFd, path: &Path, follow_symlinks: bool, ) -> Result<(Inode, String), Errno> { @@ -1394,7 +1394,7 @@ impl WasiFs { } } - pub fn flush(&self, inodes: &WasiInodes, fd: Fd) -> Result<(), Errno> { + pub fn flush(&self, inodes: &WasiInodes, fd: WasiFd) -> Result<(), Errno> { match fd { __WASI_STDIN_FILENO => (), __WASI_STDOUT_FILENO => inodes @@ -1412,7 +1412,7 @@ impl WasiFs { _ => { let fd = self.get_fd(fd)?; if !fd.rights.contains(Rights::FD_DATASYNC) { - return Err(Errno::Acces); + return Err(Errno::Access); } let mut guard = inodes.arena[fd.inode].write(); @@ -1498,7 +1498,7 @@ impl WasiFs { Ok(idx) } - pub fn clone_fd(&self, fd: Fd) -> Result { + 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( @@ -1581,7 +1581,7 @@ impl WasiFs { inodes: &mut WasiInodes, handle: Box, name: &'static str, - raw_fd: Fd, + raw_fd: WasiFd, rights: Rights, fd_flags: Fdflags, ) { @@ -1685,7 +1685,7 @@ impl WasiFs { } /// Closes an open FD, handling all details such as FD being preopen - pub(crate) fn close_fd(&self, inodes: &WasiInodes, fd: Fd) -> Result<(), Errno> { + 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; @@ -1750,7 +1750,7 @@ impl WasiFs { } } Kind::EventNotifications { .. } => {} - Kind::Root { .. } => return Err(Errno::Acces), + Kind::Root { .. } => return Err(Errno::Access), Kind::Symlink { .. } | Kind::Buffer { .. } => return Err(Errno::Inval), } @@ -1931,7 +1931,7 @@ impl WasiState { /// Expects one of `__WASI_STDIN_FILENO`, `__WASI_STDOUT_FILENO`, `__WASI_STDERR_FILENO`. fn std_dev_get( &self, - fd: Fd, + fd: WasiFd, ) -> Result>, FsError> { let ret = WasiStateFileGuard::new(self, fd)?.map(|a| { let ret = Box::new(a); diff --git a/lib/wasi/src/state/pipe.rs b/lib/wasi/src/state/pipe.rs index 4cbbe58b564..4ce34e78f72 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_generated::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_snapshot0::Errno::Io)?; + let data = rx.recv().map_err(|_| Errno::Io)?; self.read_buffer.replace(Bytes::from(data)); } } @@ -64,19 +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_snapshot0::Errno::Inval)?; + 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_snapshot0::Errno::Io)?; + 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 bc78d481695..6046694f62b 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_generated::wasi::{Errno, Fdflags, Rights}; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; @@ -162,7 +163,7 @@ impl InodeSocket { &mut self, net: &(dyn VirtualNetworking), set_addr: SocketAddr, - ) -> Result, wasi_snapshot0::Errno> { + ) -> Result, Errno> { match &mut self.kind { InodeSocketKind::PreSocket { family, @@ -175,16 +176,16 @@ impl InodeSocket { match *family { __WASI_ADDRESS_FAMILY_INET4 => { if !set_addr.is_ipv4() { - return Err(wasi_snapshot0::Errno::Inval); + return Err(Errno::Inval); } } __WASI_ADDRESS_FAMILY_INET6 => { if !set_addr.is_ipv6() { - return Err(wasi_snapshot0::Errno::Inval); + return Err(Errno::Inval); } } _ => { - return Err(wasi_snapshot0::Errno::Notsup); + return Err(Errno::Notsup); } } @@ -203,10 +204,10 @@ impl InodeSocket { .map_err(net_error_into_wasi_err)?; Some(InodeSocket::new(InodeSocketKind::UdpSocket(socket))) } - _ => return Err(wasi_snapshot0::Errno::Inval), + _ => return Err(Errno::Inval), }) } - _ => Err(wasi_snapshot0::Errno::Notsup), + _ => Err(Errno::Notsup), } } @@ -214,7 +215,7 @@ impl InodeSocket { &mut self, net: &(dyn VirtualNetworking), _backlog: usize, - ) -> Result, wasi_snapshot0::Errno> { + ) -> Result, Errno> { match &self.kind { InodeSocketKind::PreSocket { ty, @@ -227,7 +228,7 @@ impl InodeSocket { } => Ok(match *ty { __WASI_SOCK_TYPE_STREAM => { if addr.is_none() { - return Err(wasi_snapshot0::Errno::Inval); + return Err(Errno::Inval); } let addr = *addr.as_ref().unwrap(); let mut socket = net @@ -240,38 +241,38 @@ impl InodeSocket { } Some(InodeSocket::new(InodeSocketKind::TcpListener(socket))) } - _ => return Err(wasi_snapshot0::Errno::Notsup), + _ => return Err(Errno::Notsup), }), - InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), - _ => Err(wasi_snapshot0::Errno::Notsup), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } } pub fn accept( &self, - _fd_flags: wasi_snapshot0::Fdflags, - ) -> Result<(Box, SocketAddr), wasi_snapshot0::Errno> { + _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_snapshot0::Errno::Notconn), - InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), - _ => Err(wasi_snapshot0::Errno::Notsup), + InodeSocketKind::PreSocket { .. } => Err(Errno::Notconn), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), }?; Ok((sock, addr)) } pub fn accept_timeout( &self, - _fd_flags: wasi_snapshot0::Fdflags, + _fd_flags: Fdflags, timeout: Duration, - ) -> Result<(Box, SocketAddr), wasi_snapshot0::Errno> { + ) -> 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_snapshot0::Errno::Notconn), - InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), - _ => Err(wasi_snapshot0::Errno::Notsup), + InodeSocketKind::PreSocket { .. } => Err(Errno::Notconn), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), }?; Ok((sock, addr)) } @@ -280,7 +281,7 @@ impl InodeSocket { &mut self, net: &(dyn VirtualNetworking), peer: SocketAddr, - ) -> Result, wasi_snapshot0::Errno> { + ) -> Result, Errno> { match &mut self.kind { InodeSocketKind::PreSocket { ty, @@ -316,19 +317,19 @@ impl InodeSocket { } Some(InodeSocket::new(InodeSocketKind::TcpStream(socket))) } - __WASI_SOCK_TYPE_DGRAM => return Err(wasi_snapshot0::Errno::Inval), - _ => return Err(wasi_snapshot0::Errno::Notsup), + __WASI_SOCK_TYPE_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_snapshot0::Errno::Io), - _ => Err(wasi_snapshot0::Errno::Notsup), + 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 +342,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_snapshot0::Errno::Io)? + .map_err(|_| Errno::Io)? .map_err(net_error_into_wasi_err)?; WasiHttpStatus { ok: true, @@ -357,12 +358,12 @@ impl InodeSocket { size: status.size as u64, } } - InodeSocketKind::Closed => return Err(wasi_snapshot0::Errno::Io), - _ => return Err(wasi_snapshot0::Errno::Notsup), + 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 { @@ -372,7 +373,7 @@ impl InodeSocket { match *family { __WASI_ADDRESS_FAMILY_INET4 => IpAddr::V4(Ipv4Addr::UNSPECIFIED), __WASI_ADDRESS_FAMILY_INET6 => IpAddr::V6(Ipv6Addr::UNSPECIFIED), - _ => return Err(wasi_snapshot0::Errno::Inval), + _ => return Err(Errno::Inval), }, 0, ) @@ -388,18 +389,18 @@ impl InodeSocket { InodeSocketKind::UdpSocket(sock) => { sock.addr_local().map_err(net_error_into_wasi_err)? } - InodeSocketKind::Closed => return Err(wasi_snapshot0::Errno::Io), - _ => return Err(wasi_snapshot0::Errno::Notsup), + 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_snapshot0::Errno::Inval), + _ => return Err(Errno::Inval), }, 0, ), @@ -423,16 +424,12 @@ impl InodeSocket { ) }) })?, - InodeSocketKind::Closed => return Err(wasi_snapshot0::Errno::Io), - _ => return Err(wasi_snapshot0::Errno::Notsup), + InodeSocketKind::Closed => return Err(Errno::Io), + _ => return Err(Errno::Notsup), }) } - pub fn set_opt_flag( - &mut self, - option: WasiSocketOption, - val: bool, - ) -> Result<(), wasi_snapshot0::Errno> { + pub fn set_opt_flag(&mut self, option: WasiSocketOption, val: bool) -> Result<(), Errno> { match &mut self.kind { InodeSocketKind::PreSocket { only_v6, @@ -444,20 +441,20 @@ impl InodeSocket { WasiSocketOption::OnlyV6 => *only_v6 = val, WasiSocketOption::ReusePort => *reuse_port = val, WasiSocketOption::ReuseAddr => *reuse_addr = val, - _ => return Err(wasi_snapshot0::Errno::Inval), + _ => 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_snapshot0::Errno::Inval), + _ => 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_snapshot0::Errno::Inval), + _ => return Err(Errno::Inval), }, InodeSocketKind::UdpSocket(sock) => match option { WasiSocketOption::Broadcast => { @@ -469,15 +466,15 @@ impl InodeSocket { WasiSocketOption::MulticastLoopV6 => sock .set_multicast_loop_v6(val) .map_err(net_error_into_wasi_err)?, - _ => return Err(wasi_snapshot0::Errno::Inval), + _ => return Err(Errno::Inval), }, - InodeSocketKind::Closed => return Err(wasi_snapshot0::Errno::Io), - _ => return Err(wasi_snapshot0::Errno::Notsup), + 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 +485,17 @@ impl InodeSocket { WasiSocketOption::OnlyV6 => *only_v6, WasiSocketOption::ReusePort => *reuse_port, WasiSocketOption::ReuseAddr => *reuse_addr, - _ => return Err(wasi_snapshot0::Errno::Inval), + _ => return Err(Errno::Inval), }, InodeSocketKind::Raw(sock) => match option { WasiSocketOption::Promiscuous => { sock.promiscuous().map_err(net_error_into_wasi_err)? } - _ => return Err(wasi_snapshot0::Errno::Inval), + _ => return Err(Errno::Inval), }, InodeSocketKind::TcpStream(sock) => match option { WasiSocketOption::NoDelay => sock.nodelay().map_err(net_error_into_wasi_err)?, - _ => return Err(wasi_snapshot0::Errno::Inval), + _ => return Err(Errno::Inval), }, InodeSocketKind::UdpSocket(sock) => match option { WasiSocketOption::Broadcast => sock.broadcast().map_err(net_error_into_wasi_err)?, @@ -508,14 +505,14 @@ impl InodeSocket { WasiSocketOption::MulticastLoopV6 => { sock.multicast_loop_v6().map_err(net_error_into_wasi_err)? } - _ => return Err(wasi_snapshot0::Errno::Inval), + _ => return Err(Errno::Inval), }, - InodeSocketKind::Closed => return Err(wasi_snapshot0::Errno::Io), - _ => return Err(wasi_snapshot0::Errno::Notsup), + InodeSocketKind::Closed => return Err(Errno::Io), + _ => return Err(Errno::Notsup), }) } - pub fn set_send_buf_size(&mut self, size: usize) -> Result<(), wasi_snapshot0::Errno> { + 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 +521,13 @@ impl InodeSocket { sock.set_send_buf_size(size) .map_err(net_error_into_wasi_err)?; } - InodeSocketKind::Closed => return Err(wasi_snapshot0::Errno::Io), - _ => return Err(wasi_snapshot0::Errno::Notsup), + 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 +535,12 @@ impl InodeSocket { InodeSocketKind::TcpStream(sock) => { sock.send_buf_size().map_err(net_error_into_wasi_err) } - InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), - _ => Err(wasi_snapshot0::Errno::Notsup), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } } - pub fn set_recv_buf_size(&mut self, size: usize) -> Result<(), wasi_snapshot0::Errno> { + 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 +549,13 @@ impl InodeSocket { sock.set_recv_buf_size(size) .map_err(net_error_into_wasi_err)?; } - InodeSocketKind::Closed => return Err(wasi_snapshot0::Errno::Io), - _ => return Err(wasi_snapshot0::Errno::Notsup), + 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 +563,28 @@ impl InodeSocket { InodeSocketKind::TcpStream(sock) => { sock.recv_buf_size().map_err(net_error_into_wasi_err) } - InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), - _ => Err(wasi_snapshot0::Errno::Notsup), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } } - pub fn set_linger( - &mut self, - linger: Option, - ) -> Result<(), wasi_snapshot0::Errno> { + 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_snapshot0::Errno::Io), - InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), - _ => Err(wasi_snapshot0::Errno::Notsup), + InodeSocketKind::PreSocket { .. } => Err(Errno::Io), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } } - pub fn linger(&self) -> Result, wasi_snapshot0::Errno> { + 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_snapshot0::Errno::Io), - InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), - _ => Err(wasi_snapshot0::Errno::Notsup), + InodeSocketKind::PreSocket { .. } => Err(Errno::Io), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } } @@ -598,7 +592,7 @@ impl InodeSocket { &mut self, ty: TimeType, timeout: Option, - ) -> Result<(), wasi_snapshot0::Errno> { + ) -> Result<(), Errno> { match &mut self.kind { InodeSocketKind::TcpStream(sock) => sock .set_opt_time(ty, timeout) @@ -607,7 +601,7 @@ impl InodeSocket { TimeType::AcceptTimeout => { sock.set_timeout(timeout).map_err(net_error_into_wasi_err) } - _ => Err(wasi_snapshot0::Errno::Inval), + _ => Err(Errno::Inval), }, InodeSocketKind::PreSocket { recv_timeout, @@ -632,22 +626,19 @@ impl InodeSocket { *send_timeout = timeout; Ok(()) } - _ => Err(wasi_snapshot0::Errno::Io), + _ => Err(Errno::Io), }, - InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), - _ => Err(wasi_snapshot0::Errno::Notsup), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } } - pub fn opt_time( - &self, - ty: TimeType, - ) -> Result, wasi_snapshot0::Errno> { + 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_snapshot0::Errno::Inval), + _ => Err(Errno::Inval), }, InodeSocketKind::PreSocket { recv_timeout, @@ -660,67 +651,63 @@ impl InodeSocket { TimeType::AcceptTimeout => Ok(*accept_timeout), TimeType::ReadTimeout => Ok(*recv_timeout), TimeType::WriteTimeout => Ok(*send_timeout), - _ => Err(wasi_snapshot0::Errno::Inval), + _ => Err(Errno::Inval), }, - InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), - _ => Err(wasi_snapshot0::Errno::Notsup), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } } - pub fn set_ttl(&mut self, ttl: u32) -> Result<(), wasi_snapshot0::Errno> { + 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_snapshot0::Errno::Io), - InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), - _ => Err(wasi_snapshot0::Errno::Notsup), + 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_snapshot0::Errno::Io), - InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), - _ => Err(wasi_snapshot0::Errno::Notsup), + 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_snapshot0::Errno> { + 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_snapshot0::Errno::Io), - InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), - _ => Err(wasi_snapshot0::Errno::Notsup), + 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_snapshot0::Errno::Io), - InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), - _ => Err(wasi_snapshot0::Errno::Notsup), + 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_snapshot0::Errno> { + 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_snapshot0::Errno::Io), - InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), - _ => Err(wasi_snapshot0::Errno::Notsup), + InodeSocketKind::PreSocket { .. } => Err(Errno::Io), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } } @@ -728,44 +715,36 @@ impl InodeSocket { &mut self, multiaddr: Ipv4Addr, iface: Ipv4Addr, - ) -> Result<(), wasi_snapshot0::Errno> { + ) -> 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_snapshot0::Errno::Io), - InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), - _ => Err(wasi_snapshot0::Errno::Notsup), + 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_snapshot0::Errno> { + 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_snapshot0::Errno::Io), - InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), - _ => Err(wasi_snapshot0::Errno::Notsup), + 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_snapshot0::Errno> { + 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_snapshot0::Errno::Io), - InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), - _ => Err(wasi_snapshot0::Errno::Notsup), + InodeSocketKind::PreSocket { .. } => Err(Errno::Io), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } } @@ -773,15 +752,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_snapshot0::Errno::Inval)?; + 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 { @@ -790,16 +767,13 @@ impl InodeSocket { match ty { InodeHttpSocketType::Request => { if sock.request.is_none() { - return Err(wasi_snapshot0::Errno::Io); + return Err(Errno::Io); } let request = sock.request.as_ref().unwrap(); - request - .send(buf) - .map(|_| buf_len) - .map_err(|_| wasi_snapshot0::Errno::Io) + request.send(buf).map(|_| buf_len).map_err(|_| Errno::Io) } _ => { - return Err(wasi_snapshot0::Errno::Io); + return Err(Errno::Io); } } } @@ -816,17 +790,14 @@ impl InodeSocket { InodeSocketKind::UdpSocket(sock) => { sock.send(Bytes::from(buf)).map_err(net_error_into_wasi_err) } - InodeSocketKind::PreSocket { .. } => Err(wasi_snapshot0::Errno::Notconn), - InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), - _ => Err(wasi_snapshot0::Errno::Notsup), + 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) => { @@ -834,16 +805,16 @@ impl InodeSocket { match ty { InodeHttpSocketType::Request => { if sock.request.is_none() { - return Err(wasi_snapshot0::Errno::Io); + return Err(Errno::Io); } let request = sock.request.as_ref().unwrap(); request .send(buf.to_vec()) .map(|_| buf_len) - .map_err(|_| wasi_snapshot0::Errno::Io) + .map_err(|_| Errno::Io) } _ => { - return Err(wasi_snapshot0::Errno::Io); + return Err(Errno::Io); } } } @@ -854,9 +825,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_snapshot0::Errno::Notconn), - InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), - _ => Err(wasi_snapshot0::Errno::Notsup), + InodeSocketKind::PreSocket { .. } => Err(Errno::Notconn), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } .map(|_| buf_len) } @@ -866,7 +837,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 @@ -874,9 +845,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_snapshot0::Errno::Inval)?; + 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 { @@ -886,9 +855,9 @@ impl InodeSocket { InodeSocketKind::UdpSocket(sock) => sock .send_to(Bytes::from(buf), addr) .map_err(net_error_into_wasi_err), - InodeSocketKind::PreSocket { .. } => Err(wasi_snapshot0::Errno::Notconn), - InodeSocketKind::Closed => Err(wasi_snapshot0::Errno::Io), - _ => Err(wasi_snapshot0::Errno::Notsup), + InodeSocketKind::PreSocket { .. } => Err(Errno::Notconn), + InodeSocketKind::Closed => Err(Errno::Io), + _ => Err(Errno::Notsup), } .map(|_| buf_len) } @@ -897,7 +866,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(); @@ -918,22 +887,22 @@ impl InodeSocket { match ty { InodeHttpSocketType::Response => { if sock.response.is_none() { - return Err(wasi_snapshot0::Errno::Io); + return Err(Errno::Io); } let response = sock.response.as_ref().unwrap(); - Bytes::from(response.recv().map_err(|_| wasi_snapshot0::Errno::Io)?) + Bytes::from(response.recv().map_err(|_| Errno::Io)?) } InodeHttpSocketType::Headers => { if sock.headers.is_none() { - return Err(wasi_snapshot0::Errno::Io); + return Err(Errno::Io); } let headers = sock.headers.as_ref().unwrap(); - let headers = headers.recv().map_err(|_| wasi_snapshot0::Errno::Io)?; + 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_snapshot0::Errno::Io); + return Err(Errno::Io); } } } @@ -953,9 +922,9 @@ impl InodeSocket { let read = sock.recv().map_err(net_error_into_wasi_err)?; read.data } - InodeSocketKind::PreSocket { .. } => return Err(wasi_snapshot0::Errno::Notconn), - InodeSocketKind::Closed => return Err(wasi_snapshot0::Errno::Io), - _ => return Err(wasi_snapshot0::Errno::Notsup), + 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(); @@ -967,7 +936,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() { @@ -985,16 +954,16 @@ impl InodeSocket { InodeSocketKind::UdpSocket(sock) => { sock.recv_from().map_err(net_error_into_wasi_err)? } - InodeSocketKind::PreSocket { .. } => return Err(wasi_snapshot0::Errno::Notconn), - InodeSocketKind::Closed => return Err(wasi_snapshot0::Errno::Io), - _ => return Err(wasi_snapshot0::Errno::Notsup), + 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_snapshot0::Errno> { + pub fn shutdown(&mut self, how: std::net::Shutdown) -> Result<(), Errno> { use std::net::Shutdown; match &mut self.kind { InodeSocketKind::TcpStream(sock) => { @@ -1017,9 +986,9 @@ impl InodeSocket { } }; } - InodeSocketKind::PreSocket { .. } => return Err(wasi_snapshot0::Errno::Notconn), - InodeSocketKind::Closed => return Err(wasi_snapshot0::Errno::Io), - _ => return Err(wasi_snapshot0::Errno::Notsup), + InodeSocketKind::PreSocket { .. } => return Err(Errno::Notconn), + InodeSocketKind::Closed => return Err(Errno::Io), + _ => return Err(Errno::Notsup), } Ok(()) } @@ -1145,7 +1114,7 @@ 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)?; @@ -1156,14 +1125,14 @@ pub(crate) fn read_ip( 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_snapshot0::Errno::Inval), + _ => 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)?; @@ -1174,7 +1143,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)?; @@ -1186,7 +1155,7 @@ pub(crate) fn write_ip( memory: &MemoryView, ptr: WasmPtr<__wasi_addr_t, M>, ip: IpAddr, -) -> Result<(), wasi_snapshot0::Errno> { +) -> Result<(), Errno> { let ip = match ip { IpAddr::V4(ip) => { let o = ip.octets(); @@ -1215,7 +1184,7 @@ 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)?; @@ -1238,7 +1207,7 @@ pub(crate) fn read_cidr( prefix: o[16], } } - _ => return Err(wasi_snapshot0::Errno::Inval), + _ => return Err(Errno::Inval), }) } @@ -1247,7 +1216,7 @@ pub(crate) fn write_cidr( memory: &MemoryView, ptr: WasmPtr<__wasi_cidr_t, M>, cidr: IpCidr, -) -> Result<(), wasi_snapshot0::Errno> { +) -> Result<(), Errno> { let p = cidr.prefix; let cidr = match cidr.ip { IpAddr::V4(ip) => { @@ -1283,7 +1252,7 @@ pub(crate) fn write_cidr( pub(crate) fn read_ip_port( memory: &MemoryView, ptr: WasmPtr<__wasi_addr_port_t, M>, -) -> Result<(IpAddr, u16), wasi_snapshot0::Errno> { +) -> Result<(IpAddr, u16), Errno> { let addr_ptr = ptr.deref(memory); let addr = addr_ptr.read().map_err(crate::mem_error_to_wasi)?; @@ -1306,7 +1275,7 @@ pub(crate) fn read_ip_port( u16::from_ne_bytes([o[0], o[1]]), ) } - _ => return Err(wasi_snapshot0::Errno::Inval), + _ => return Err(Errno::Inval), }) } @@ -1316,7 +1285,7 @@ pub(crate) fn write_ip_port( ptr: WasmPtr<__wasi_addr_port_t, M>, ip: IpAddr, port: u16, -) -> Result<(), wasi_snapshot0::Errno> { +) -> Result<(), Errno> { let p = port.to_be_bytes(); let ipport = match ip { IpAddr::V4(ip) => { @@ -1353,7 +1322,7 @@ pub(crate) fn write_ip_port( pub(crate) fn read_route( memory: &MemoryView, ptr: WasmPtr<__wasi_route_t, M>, -) -> Result { +) -> Result { let route_ptr = ptr.deref(memory); let route = route_ptr.read().map_err(crate::mem_error_to_wasi)?; @@ -1378,7 +1347,7 @@ pub(crate) fn read_route( prefix: o[16], } } - _ => return Err(wasi_snapshot0::Errno::Inval), + _ => return Err(Errno::Inval), } }, via_router: { @@ -1389,18 +1358,18 @@ pub(crate) fn read_route( 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_snapshot0::Errno::Inval), + _ => 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_snapshot0::Errno::Inval), + _ => return Err(Errno::Inval), }, 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_snapshot0::Errno::Inval), + _ => return Err(Errno::Inval), }, }) } @@ -1409,7 +1378,7 @@ pub(crate) fn write_route( memory: &MemoryView, ptr: WasmPtr<__wasi_route_t, M>, route: IpRoute, -) -> Result<(), wasi_snapshot0::Errno> { +) -> Result<(), Errno> { let cidr = { let p = route.cidr.prefix; match route.cidr.ip { @@ -1488,26 +1457,3 @@ pub(crate) fn write_route( route_ptr.write(route).map_err(crate::mem_error_to_wasi)?; Ok(()) } - -pub(crate) const fn all_socket_rights() -> wasi_snapshot0::Rights { - // This might seem a bit overenineered, but it's the only way I - // discovered for getting the values in a const environment - wasi_snapshot0::Rights::from_bits_truncate( - wasi_snapshot0::Rights::FD_FDSTAT_SET_FLAGS.bits() - | wasi_snapshot0::Rights::FD_FILESTAT_GET.bits() - | wasi_snapshot0::Rights::FD_READ.bits() - | wasi_snapshot0::Rights::FD_WRITE.bits() - | wasi_snapshot0::Rights::POLL_FD_READWRITE.bits() - | wasi_snapshot0::Rights::SOCK_SHUTDOWN.bits() - | wasi_snapshot0::Rights::SOCK_CONNECT.bits() - | wasi_snapshot0::Rights::SOCK_LISTEN.bits() - | wasi_snapshot0::Rights::SOCK_BIND.bits() - | wasi_snapshot0::Rights::SOCK_ACCEPT.bits() - | wasi_snapshot0::Rights::SOCK_RECV.bits() - | wasi_snapshot0::Rights::SOCK_SEND.bits() - | wasi_snapshot0::Rights::SOCK_ADDR_LOCAL.bits() - | wasi_snapshot0::Rights::SOCK_ADDR_REMOTE.bits() - | wasi_snapshot0::Rights::SOCK_RECV_FROM.bits() - | wasi_snapshot0::Rights::SOCK_SEND_TO.bits(), - ) -} diff --git a/lib/wasi/src/state/types.rs b/lib/wasi/src/state/types.rs index f6b8467afde..c91b1526500 100644 --- a/lib/wasi/src/state/types.rs +++ b/lib/wasi/src/state/types.rs @@ -11,7 +11,7 @@ use std::{ time::Duration, }; use wasmer_vbus::BusError; -use wasmer_wasi_types_generated::wasi_io_typenames::Errno; +use wasmer_wasi_types_generated::wasi::Errno; #[cfg(feature = "host-fs")] pub use wasmer_vfs::host_fs::{Stderr, Stdin, Stdout}; diff --git a/lib/wasi/src/syscalls/legacy/snapshot0.rs b/lib/wasi/src/syscalls/legacy/snapshot0.rs index a083a15fc62..9865caeea42 100644 --- a/lib/wasi/src/syscalls/legacy/snapshot0.rs +++ b/lib/wasi/src/syscalls/legacy/snapshot0.rs @@ -1,10 +1,10 @@ use crate::syscalls; -use crate::syscalls::types::{ - self, snapshot0, - wasi_snapshot0::{self, Errno, Fd}, -}; +use crate::syscalls::types::{self, snapshot0}; use crate::{mem_error_to_wasi, Memory32, MemorySize, WasiEnv, WasiError, WasiThread}; use wasmer::{AsStoreMut, FunctionEnvMut, WasmPtr}; +use wasmer_wasi_types_generated::wasi::{ + Errno, Event, Fd, Filetype, Snapshot0Subscription, Subscription, +}; /// Wrapper around `syscalls::fd_filestat_get` with extra logic to handle the size /// difference of `wasi_filestat_t` @@ -19,6 +19,7 @@ pub fn fd_filestat_get( ) -> 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 @@ -71,6 +72,8 @@ pub fn path_filestat_get( path_len: u32, 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); @@ -125,11 +128,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 { + // 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 @@ -141,14 +145,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::from(*orig))); + 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 1b782a625eb..41604fdd1e7 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -2,10 +2,7 @@ pub mod types { pub use wasmer_wasi_types::*; - pub use wasmer_wasi_types_generated::wasi_io_typenames::{ - Advice, Clockid, Errno, Fd, Fdflags, Fdstat, Rights, - }; - pub use wasmer_wasi_types_generated::{wasi_filesystem, wasi_io_typenames, wasi_snapshot0}; + pub use wasmer_wasi_types_generated::wasi; } #[cfg(any( @@ -25,7 +22,14 @@ pub mod legacy; pub mod wasix32; pub mod wasix64; -use self::types::*; +use self::types::{ + wasi::{ + Advice, Clockid, Dircookie, Dirent, Errno, Event, EventEnum, EventFdReadwrite, + Eventrwflags, Eventtype, Fd as WasiFd, Fdflags, Fdstat, Filetype, Rights, Snapshot0Clockid, + Subscription, SubscriptionEnum, SubscriptionFsReadwrite, + }, + *, +}; use crate::state::{bus_error_into_wasi_err, wasi_error_into_bus_err, InodeHttpSocketType}; use crate::utils::map_io_err; use crate::WasiBusProcessId; @@ -36,7 +40,7 @@ use crate::{ 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}; @@ -143,7 +147,7 @@ pub(crate) fn read_bytes( fn __sock_actor( ctx: &FunctionEnvMut<'_, WasiEnv>, - sock: Fd, + sock: WasiFd, rights: Rights, actor: F, ) -> Result @@ -177,7 +181,7 @@ where fn __sock_actor_mut( ctx: &FunctionEnvMut<'_, WasiEnv>, - sock: Fd, + sock: WasiFd, rights: Rights, actor: F, ) -> Result @@ -211,7 +215,7 @@ where fn __sock_upgrade( ctx: &FunctionEnvMut<'_, WasiEnv>, - sock: Fd, + sock: WasiFd, rights: Rights, actor: F, ) -> Result<(), Errno> @@ -369,7 +373,10 @@ pub fn clock_res_get( 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)); + let t_out = wasi_try!(platform_clock_res_get( + Snapshot0Clockid::from(clock_id), + out_addr + )); wasi_try_mem!(resolution.write(&memory, t_out as __wasi_timestamp_t)); Errno::Success } @@ -397,7 +404,10 @@ pub fn clock_time_get( let env = ctx.data(); let memory = env.memory_view(&ctx); - let t_out = wasi_try!(platform_clock_time_get(clock_id, precision)); + let t_out = wasi_try!(platform_clock_time_get( + Snapshot0Clockid::from(clock_id), + precision + )); wasi_try_mem!(time.write(&memory, t_out as __wasi_timestamp_t)); let result = Errno::Success; @@ -481,7 +491,7 @@ pub fn environ_sizes_get( /// The advice to give pub fn fd_advise( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: Fd, + fd: WasiFd, offset: __wasi_filesize_t, len: __wasi_filesize_t, advice: Advice, @@ -504,7 +514,7 @@ pub fn fd_advise( /// The length from the offset marking the end of the allocation pub fn fd_allocate( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: Fd, + fd: WasiFd, offset: __wasi_filesize_t, len: __wasi_filesize_t, ) -> Errno { @@ -555,7 +565,7 @@ pub fn fd_allocate( /// If `fd` is a directory /// - `Errno::Badf` /// If `fd` is invalid or not open -pub fn fd_close(ctx: FunctionEnvMut<'_, WasiEnv>, fd: Fd) -> Errno { +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); @@ -572,7 +582,7 @@ pub fn fd_close(ctx: FunctionEnvMut<'_, WasiEnv>, fd: Fd) -> Errno { /// Inputs: /// - `Fd fd` /// The file descriptor to sync -pub fn fd_datasync(ctx: FunctionEnvMut<'_, WasiEnv>, fd: Fd) -> Errno { +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); @@ -598,7 +608,7 @@ pub fn fd_datasync(ctx: FunctionEnvMut<'_, WasiEnv>, fd: Fd) -> Errno { /// The location where the metadata will be written pub fn fd_fdstat_get( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: Fd, + fd: WasiFd, buf_ptr: WasmPtr, ) -> Errno { debug!( @@ -624,7 +634,7 @@ pub fn fd_fdstat_get( /// The file descriptor to apply the new flags to /// - `Fdflags flags` /// The flags to apply to `fd` -pub fn fd_fdstat_set_flags(ctx: FunctionEnvMut<'_, WasiEnv>, fd: Fd, flags: Fdflags) -> Errno { +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); @@ -650,7 +660,7 @@ pub fn fd_fdstat_set_flags(ctx: FunctionEnvMut<'_, WasiEnv>, fd: Fd, flags: Fdfl /// The inheriting rights to apply to `fd` pub fn fd_fdstat_set_rights( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: Fd, + fd: WasiFd, fs_rights_base: Rights, fs_rights_inheriting: Rights, ) -> Errno { @@ -683,7 +693,7 @@ pub fn fd_fdstat_set_rights( /// Where the metadata from `fd` will be written pub fn fd_filestat_get( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: Fd, + fd: WasiFd, buf: WasmPtr<__wasi_filestat_t, M>, ) -> Errno { debug!("wasi::fd_filestat_get"); @@ -711,7 +721,7 @@ pub fn fd_filestat_get( /// New size that `fd` will be set to pub fn fd_filestat_set_size( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: Fd, + fd: WasiFd, st_size: __wasi_filesize_t, ) -> Errno { debug!("wasi::fd_filestat_set_size"); @@ -761,7 +771,7 @@ pub fn fd_filestat_set_size( /// Bit-vector for controlling which times get set pub fn fd_filestat_set_times( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: Fd, + fd: WasiFd, st_atim: __wasi_timestamp_t, st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, @@ -823,7 +833,7 @@ pub fn fd_filestat_set_times( /// The number of bytes read pub fn fd_pread( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: Fd, + fd: WasiFd, iovs: WasmPtr<__wasi_iovec_t, M>, iovs_len: M::Offset, offset: __wasi_filesize_t, @@ -910,7 +920,7 @@ pub fn fd_pread( /// Where the metadata will be written pub fn fd_prestat_get( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: Fd, + fd: WasiFd, buf: WasmPtr<__wasi_prestat_t, M>, ) -> Errno { trace!("wasi::fd_prestat_get: fd={}", fd); @@ -932,7 +942,7 @@ pub fn fd_prestat_get( pub fn fd_prestat_dir_name( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: Fd, + fd: WasiFd, path: WasmPtr, path_len: M::Offset, ) -> Errno { @@ -995,7 +1005,7 @@ pub fn fd_prestat_dir_name( /// Number of bytes written pub fn fd_pwrite( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: Fd, + fd: WasiFd, iovs: WasmPtr<__wasi_ciovec_t, M>, iovs_len: M::Offset, offset: __wasi_filesize_t, @@ -1105,7 +1115,7 @@ pub fn fd_pwrite( /// pub fn fd_read( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: Fd, + fd: WasiFd, iovs: WasmPtr<__wasi_iovec_t, M>, iovs_len: M::Offset, nread: WasmPtr, @@ -1264,7 +1274,7 @@ pub fn fd_read( /// directory has been read pub fn fd_readdir( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: Fd, + fd: WasiFd, buf: WasmPtr, buf_len: M::Offset, cookie: Dircookie, @@ -1396,7 +1406,7 @@ pub fn fd_readdir( /// File descriptor to copy /// - `Fd to` /// Location to copy file descriptor to -pub fn fd_renumber(ctx: FunctionEnvMut<'_, WasiEnv>, from: Fd, to: Fd) -> Errno { +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); @@ -1425,8 +1435,8 @@ pub fn fd_renumber(ctx: FunctionEnvMut<'_, WasiEnv>, from: Fd, to: Fd) -> Errno /// The new file handle that is a duplicate of the original pub fn fd_dup( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: Fd, - ret_fd: WasmPtr, + fd: WasiFd, + ret_fd: WasmPtr, ) -> Errno { debug!("wasi::fd_dup"); @@ -1445,7 +1455,7 @@ pub fn fd_event( ctx: FunctionEnvMut<'_, WasiEnv>, initial_val: u64, flags: __wasi_eventfdflags, - ret_fd: WasmPtr, + ret_fd: WasmPtr, ) -> Errno { debug!("wasi::fd_event"); @@ -1488,7 +1498,7 @@ pub fn fd_event( /// The new offset relative to the start of the file pub fn fd_seek( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: Fd, + fd: WasiFd, offset: __wasi_filedelta_t, whence: __wasi_whence_t, newoffset: WasmPtr<__wasi_filesize_t, M>, @@ -1571,7 +1581,7 @@ pub fn fd_seek( /// TODO: figure out which errors this should return /// - `Errno::Perm` /// - `Errno::Notcapable` -pub fn fd_sync(ctx: FunctionEnvMut<'_, WasiEnv>, fd: Fd) -> Errno { +pub fn fd_sync(ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd) -> Errno { debug!("wasi::fd_sync"); debug!("=> fd={}", fd); let env = ctx.data(); @@ -1616,7 +1626,7 @@ pub fn fd_sync(ctx: FunctionEnvMut<'_, WasiEnv>, fd: Fd) -> Errno { /// The offset of `fd` relative to the start of the file pub fn fd_tell( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: Fd, + fd: WasiFd, offset: WasmPtr<__wasi_filesize_t, M>, ) -> Errno { debug!("wasi::fd_tell"); @@ -1651,7 +1661,7 @@ pub fn fd_tell( /// pub fn fd_write( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: Fd, + fd: WasiFd, iovs: WasmPtr<__wasi_ciovec_t, M>, iovs_len: M::Offset, nwritten: WasmPtr, @@ -1784,8 +1794,8 @@ pub fn fd_write( /// Second file handle that represents the other end of the pipe pub fn fd_pipe( ctx: FunctionEnvMut<'_, WasiEnv>, - ro_fd1: WasmPtr, - ro_fd2: WasmPtr, + ro_fd1: WasmPtr, + ro_fd2: WasmPtr, ) -> Errno { trace!("wasi::fd_pipe"); @@ -1807,7 +1817,7 @@ pub fn fd_pipe( "pipe".to_string(), ); - let rights = super::state::all_socket_rights(); + let rights = Rights::all_socket(); let fd1 = wasi_try!(state .fs .create_fd(rights, rights, Fdflags::empty(), 0, inode1)); @@ -1836,7 +1846,7 @@ pub fn fd_pipe( /// 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: Fd, + fd: WasiFd, path: WasmPtr, path_len: M::Offset, ) -> Errno { @@ -1965,7 +1975,7 @@ pub fn path_create_directory( /// The location where the metadata will be stored pub fn path_filestat_get( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: Fd, + fd: WasiFd, flags: __wasi_lookupflags_t, path: WasmPtr, path_len: M::Offset, @@ -2009,7 +2019,7 @@ pub fn path_filestat_get_internal( memory: &MemoryView, state: &WasiState, inodes: &mut crate::WasiInodes, - fd: Fd, + fd: WasiFd, flags: __wasi_lookupflags_t, path_string: &str, ) -> Result<__wasi_filestat_t, Errno> { @@ -2053,7 +2063,7 @@ pub fn path_filestat_get_internal( /// A bitmask controlling which attributes are set pub fn path_filestat_set_times( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: Fd, + fd: WasiFd, flags: __wasi_lookupflags_t, path: WasmPtr, path_len: M::Offset, @@ -2131,11 +2141,11 @@ pub fn path_filestat_set_times( /// Length of the `new_path` string pub fn path_link( ctx: FunctionEnvMut<'_, WasiEnv>, - old_fd: Fd, + old_fd: WasiFd, old_flags: __wasi_lookupflags_t, old_path: WasmPtr, old_path_len: M::Offset, - new_fd: Fd, + new_fd: WasiFd, new_path: WasmPtr, new_path_len: M::Offset, ) -> Errno { @@ -2228,7 +2238,7 @@ pub fn path_link( /// - `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: Fd, + dirfd: WasiFd, dirflags: __wasi_lookupflags_t, path: WasmPtr, path_len: M::Offset, @@ -2236,7 +2246,7 @@ pub fn path_open( fs_rights_base: Rights, fs_rights_inheriting: Rights, fs_flags: Fdflags, - fd: WasmPtr, + fd: WasmPtr, ) -> Errno { debug!("wasi::path_open"); if dirflags & __WASI_LOOKUP_SYMLINK_FOLLOW != 0 { @@ -2473,7 +2483,7 @@ pub fn path_open( /// The number of bytes written to `buf` pub fn path_readlink( ctx: FunctionEnvMut<'_, WasiEnv>, - dir_fd: Fd, + dir_fd: WasiFd, path: WasmPtr, path_len: M::Offset, buf: WasmPtr, @@ -2523,7 +2533,7 @@ pub fn path_readlink( /// Returns Errno::Notemtpy if directory is not empty pub fn path_remove_directory( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: Fd, + fd: WasiFd, path: WasmPtr, path_len: M::Offset, ) -> Errno { @@ -2610,10 +2620,10 @@ pub fn path_remove_directory( /// The number of bytes to read from `new_path` pub fn path_rename( ctx: FunctionEnvMut<'_, WasiEnv>, - old_fd: Fd, + old_fd: WasiFd, old_path: WasmPtr, old_path_len: M::Offset, - new_fd: Fd, + new_fd: WasiFd, new_path: WasmPtr, new_path_len: M::Offset, ) -> Errno { @@ -2797,7 +2807,7 @@ pub fn path_symlink( ctx: FunctionEnvMut<'_, WasiEnv>, old_path: WasmPtr, old_path_len: M::Offset, - fd: Fd, + fd: WasiFd, new_path: WasmPtr, new_path_len: M::Offset, ) -> Errno { @@ -2896,7 +2906,7 @@ pub fn path_symlink( /// The number of bytes in the `path` array pub fn path_unlink_file( ctx: FunctionEnvMut<'_, WasiEnv>, - fd: Fd, + fd: WasiFd, path: WasmPtr, path_len: M::Offset, ) -> Errno { @@ -3000,7 +3010,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 @@ -3009,8 +3019,8 @@ 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 { @@ -3030,42 +3040,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); + 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); + 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) => { + 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"); @@ -3147,10 +3157,10 @@ pub fn poll_oneoff( let mut seen_events = vec![Default::default(); in_events.len()]; - let start = platform_clock_time_get(Clockid::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(Clockid::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, @@ -3211,17 +3221,19 @@ pub fn poll_oneoff( } } } - 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)); @@ -3229,18 +3241,10 @@ pub fn poll_oneoff( } if triggered == 0 { for (clock_info, userdata) in clock_subs { - let event = __wasi_event_t { + let event = Event { userdata, error: Errno::Success, - type_: Eventtype::Clock, - u: unsafe { - __wasi_event_u { - fd_readwrite: __wasi_event_fd_readwrite_t { - nbytes: 0, - flags: Eventrwflags::empty(), - }, - } - }, + data: EventEnum::Clock, }; wasi_try_mem_ok!(event_array.index(events_seen as u64).write(event)); events_seen += 1; @@ -4118,7 +4122,7 @@ pub fn ws_connect( ctx: FunctionEnvMut<'_, WasiEnv>, url: WasmPtr, url_len: M::Offset, - ret_sock: WasmPtr, + ret_sock: WasmPtr, ) -> Errno { debug!("wasi::ws_connect"); let env = ctx.data(); @@ -4142,7 +4146,7 @@ pub fn ws_connect( false, "socket".to_string(), ); - let rights = super::state::all_socket_rights(); + let rights = Rights::all_socket(); let fd = wasi_try!(state .fs .create_fd(rights, rights, Fdflags::empty(), 0, inode)); @@ -4254,7 +4258,7 @@ 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 @@ -4283,7 +4287,7 @@ pub fn http_request( /// status of this HTTP request pub fn http_status( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: Fd, + sock: WasiFd, status: WasmPtr<__wasi_http_status_t, M>, ) -> Errno { debug!("wasi::http_status"); @@ -4597,7 +4601,11 @@ pub fn port_route_list( /// ## Parameters /// /// * `how` - Which channels on the socket to shut down. -pub fn sock_shutdown(ctx: FunctionEnvMut<'_, WasiEnv>, sock: Fd, how: __wasi_sdflags_t) -> Errno { +pub fn sock_shutdown( + ctx: FunctionEnvMut<'_, WasiEnv>, + sock: WasiFd, + how: __wasi_sdflags_t, +) -> Errno { debug!("wasi::sock_shutdown"); let both = __WASI_SHUT_RD | __WASI_SHUT_WR; @@ -4622,7 +4630,7 @@ pub fn sock_shutdown(ctx: FunctionEnvMut<'_, WasiEnv>, sock: Fd, how: __wasi_sdf /// Returns the current status of a socket pub fn sock_status( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: Fd, + sock: WasiFd, ret_status: WasmPtr<__wasi_sockstatus_t, M>, ) -> Errno { debug!("wasi::sock_status"); @@ -4659,7 +4667,7 @@ pub fn sock_status( /// * `fd` - Socket that the address is bound to pub fn sock_addr_local( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: Fd, + sock: WasiFd, ret_addr: WasmPtr<__wasi_addr_port_t, M>, ) -> Errno { debug!("wasi::sock_addr_local"); @@ -4690,7 +4698,7 @@ pub fn sock_addr_local( /// * `fd` - Socket that the address is bound to pub fn sock_addr_peer( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: Fd, + sock: WasiFd, ro_addr: WasmPtr<__wasi_addr_port_t, M>, ) -> Errno { debug!("wasi::sock_addr_peer"); @@ -4733,7 +4741,7 @@ pub fn sock_open( af: __wasi_addressfamily_t, ty: __wasi_socktype_t, pt: __wasi_sockproto_t, - ro_sock: WasmPtr, + ro_sock: WasmPtr, ) -> Errno { debug!("wasi::sock_open"); @@ -4767,7 +4775,7 @@ pub fn sock_open( false, "socket".to_string(), ); - let rights = super::state::all_socket_rights(); + let rights = Rights::all_socket(); let fd = wasi_try!(state .fs .create_fd(rights, rights, Fdflags::empty(), 0, inode)); @@ -4788,7 +4796,7 @@ pub fn sock_open( /// * `flag` - Value to set the option to pub fn sock_set_opt_flag( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: Fd, + sock: WasiFd, opt: __wasi_sockoption_t, flag: __wasi_bool_t, ) -> Errno { @@ -4817,7 +4825,7 @@ pub fn sock_set_opt_flag( /// * `sockopt` - Socket option to be retrieved pub fn sock_get_opt_flag( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: Fd, + sock: WasiFd, opt: __wasi_sockoption_t, ret_flag: WasmPtr<__wasi_bool_t, M>, ) -> Errno { @@ -4849,7 +4857,7 @@ pub fn sock_get_opt_flag( /// * `time` - Value to set the time to pub fn sock_set_opt_time( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: Fd, + sock: WasiFd, opt: __wasi_sockoption_t, time: WasmPtr<__wasi_option_timestamp_t, M>, ) -> Errno { @@ -4889,7 +4897,7 @@ pub fn sock_set_opt_time( /// * `sockopt` - Socket option to be retrieved pub fn sock_get_opt_time( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: Fd, + sock: WasiFd, opt: __wasi_sockoption_t, ret_time: WasmPtr<__wasi_option_timestamp_t, M>, ) -> Errno { @@ -4936,7 +4944,7 @@ pub fn sock_get_opt_time( /// * `size` - Buffer size pub fn sock_set_opt_size( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: Fd, + sock: WasiFd, opt: __wasi_sockoption_t, size: __wasi_filesize_t, ) -> Errno { @@ -4974,7 +4982,7 @@ pub fn sock_set_opt_size( /// * `sockopt` - Socket option to be retrieved pub fn sock_get_opt_size( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: Fd, + sock: WasiFd, opt: __wasi_sockoption_t, ret_size: WasmPtr<__wasi_filesize_t, M>, ) -> Errno { @@ -5012,7 +5020,7 @@ pub fn sock_get_opt_size( /// * `interface` - Interface that will join pub fn sock_join_multicast_v4( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: Fd, + sock: WasiFd, multiaddr: WasmPtr<__wasi_addr_ip4_t, M>, iface: WasmPtr<__wasi_addr_ip4_t, M>, ) -> Errno { @@ -5038,7 +5046,7 @@ pub fn sock_join_multicast_v4( /// * `interface` - Interface that will left pub fn sock_leave_multicast_v4( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: Fd, + sock: WasiFd, multiaddr: WasmPtr<__wasi_addr_ip4_t, M>, iface: WasmPtr<__wasi_addr_ip4_t, M>, ) -> Errno { @@ -5064,7 +5072,7 @@ pub fn sock_leave_multicast_v4( /// * `interface` - Interface that will join pub fn sock_join_multicast_v6( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: Fd, + sock: WasiFd, multiaddr: WasmPtr<__wasi_addr_ip6_t, M>, iface: u32, ) -> Errno { @@ -5089,7 +5097,7 @@ pub fn sock_join_multicast_v6( /// * `interface` - Interface that will left pub fn sock_leave_multicast_v6( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: Fd, + sock: WasiFd, multiaddr: WasmPtr<__wasi_addr_ip6_t, M>, iface: u32, ) -> Errno { @@ -5114,7 +5122,7 @@ pub fn sock_leave_multicast_v6( /// * `addr` - Address to bind the socket to pub fn sock_bind( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: Fd, + sock: WasiFd, addr: WasmPtr<__wasi_addr_port_t, M>, ) -> Errno { debug!("wasi::sock_bind"); @@ -5143,7 +5151,7 @@ pub fn sock_bind( /// * `backlog` - Maximum size of the queue for pending connections pub fn sock_listen( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: Fd, + sock: WasiFd, backlog: M::Offset, ) -> Errno { debug!("wasi::sock_listen"); @@ -5170,9 +5178,9 @@ pub fn sock_listen( /// New socket connection pub fn sock_accept( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: Fd, + sock: WasiFd, fd_flags: Fdflags, - ro_fd: WasmPtr, + ro_fd: WasmPtr, ro_addr: WasmPtr<__wasi_addr_port_t, M>, ) -> Result { debug!("wasi::sock_accept"); @@ -5217,7 +5225,7 @@ pub fn sock_accept( "socket".to_string(), ); - let rights = super::state::all_socket_rights(); + let rights = Rights::all_socket(); let fd = wasi_try_ok!(state .fs .create_fd(rights, rights, Fdflags::empty(), 0, inode)); @@ -5247,7 +5255,7 @@ pub fn sock_accept( /// * `addr` - Address of the socket to connect to pub fn sock_connect( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: Fd, + sock: WasiFd, addr: WasmPtr<__wasi_addr_port_t, M>, ) -> Errno { debug!("wasi::sock_connect"); @@ -5277,7 +5285,7 @@ pub fn sock_connect( /// Number of bytes stored in ri_data and message flags. pub fn sock_recv( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: Fd, + sock: WasiFd, ri_data: WasmPtr<__wasi_iovec_t, M>, ri_data_len: M::Offset, _ri_flags: __wasi_riflags_t, @@ -5316,7 +5324,7 @@ pub fn sock_recv( /// Number of bytes stored in ri_data and message flags. pub fn sock_recv_from( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: Fd, + sock: WasiFd, ri_data: WasmPtr<__wasi_iovec_t, M>, ri_data_len: M::Offset, _ri_flags: __wasi_riflags_t, @@ -5359,7 +5367,7 @@ pub fn sock_recv_from( /// Number of bytes transmitted. pub fn sock_send( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: Fd, + sock: WasiFd, si_data: WasmPtr<__wasi_ciovec_t, M>, si_data_len: M::Offset, _si_flags: __wasi_siflags_t, @@ -5398,7 +5406,7 @@ pub fn sock_send( /// Number of bytes transmitted. pub fn sock_send_to( ctx: FunctionEnvMut<'_, WasiEnv>, - sock: Fd, + sock: WasiFd, si_data: WasmPtr<__wasi_ciovec_t, M>, si_data_len: M::Offset, _si_flags: __wasi_siflags_t, @@ -5439,8 +5447,8 @@ pub fn sock_send_to( /// Number of bytes transmitted. pub unsafe fn sock_send_file( mut ctx: FunctionEnvMut<'_, WasiEnv>, - sock: Fd, - in_fd: Fd, + sock: WasiFd, + in_fd: WasiFd, offset: __wasi_filesize_t, mut count: __wasi_filesize_t, ret_sent: WasmPtr<__wasi_filesize_t, M>, diff --git a/lib/wasi/src/syscalls/unix/mod.rs b/lib/wasi/src/syscalls/unix/mod.rs index b2d0f10c464..941bf170154 100644 --- a/lib/wasi/src/syscalls/unix/mod.rs +++ b/lib/wasi/src/syscalls/unix/mod.rs @@ -1,4 +1,3 @@ -use crate::syscalls::types::wasi_snapshot0; use crate::syscalls::types::*; use libc::{ clock_getres, clock_gettime, timespec, CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID, @@ -6,17 +5,18 @@ use libc::{ }; use std::mem; use wasmer::WasmRef; +use wasmer_wasi_types_generated::wasi::{Errno, Snapshot0Clockid}; pub fn platform_clock_res_get( - clock_id: wasi_snapshot0::Clockid, + clock_id: Snapshot0Clockid, resolution: WasmRef<__wasi_timestamp_t>, -) -> Result { +) -> Result { let unix_clock_id = match clock_id { - wasi_snapshot0::Clockid::Monotonic => CLOCK_MONOTONIC, - wasi_snapshot0::Clockid::ProcessCputimeId => CLOCK_PROCESS_CPUTIME_ID, - wasi_snapshot0::Clockid::Realtime => CLOCK_REALTIME, - wasi_snapshot0::Clockid::ThreadCputimeId => CLOCK_THREAD_CPUTIME_ID, - _ => return Err(wasi_snapshot0::Errno::Inval), + 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 { @@ -32,15 +32,15 @@ pub fn platform_clock_res_get( } pub fn platform_clock_time_get( - clock_id: wasi_snapshot0::Clockid, + clock_id: Snapshot0Clockid, precision: __wasi_timestamp_t, -) -> Result { +) -> Result { let unix_clock_id = match clock_id { - wasi_snapshot0::Clockid::Monotonic => CLOCK_MONOTONIC, - wasi_snapshot0::Clockid::ProcessCputimeId => CLOCK_PROCESS_CPUTIME_ID, - wasi_snapshot0::Clockid::Realtime => CLOCK_REALTIME, - wasi_snapshot0::Clockid::ThreadCputimeId => CLOCK_THREAD_CPUTIME_ID, - _ => return Err(wasi_snapshot0::Errno::Inval), + 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 73627b7f75c..8513f4c685f 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::{Memory, Memory32, MemorySize, StoreMut, WasmPtr, WasmSlice}; -use wasmer_wasi_types::*; +use wasmer_wasi_types::{ + wasi::{Errno, Event, Fd as WasiFd}, + *, +}; type MemoryType = Memory32; type MemoryOffset = u32; @@ -10,7 +13,7 @@ pub(crate) fn args_get( ctx: FunctionEnvMut, argv: WasmPtr, MemoryType>, argv_buf: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { super::args_get::(ctx, argv, argv_buf) } @@ -18,7 +21,7 @@ pub(crate) fn args_sizes_get( ctx: FunctionEnvMut, argc: WasmPtr, argv_buf_size: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { super::args_sizes_get::(ctx, argc, argv_buf_size) } @@ -26,7 +29,7 @@ pub(crate) fn clock_res_get( ctx: FunctionEnvMut, clock_id: wasi_snapshot0::Clockid, resolution: WasmPtr<__wasi_timestamp_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::clock_res_get::(ctx, clock_id, resolution) } @@ -35,7 +38,7 @@ pub(crate) fn clock_time_get( clock_id: wasi_snapshot0::Clockid, precision: __wasi_timestamp_t, time: WasmPtr<__wasi_timestamp_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> 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_snapshot0::Errno { +) -> Errno { super::environ_get::(ctx, environ, environ_buf) } @@ -51,227 +54,214 @@ pub(crate) fn environ_sizes_get( ctx: FunctionEnvMut, environ_count: WasmPtr, environ_buf_size: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { super::environ_sizes_get::(ctx, environ_count, environ_buf_size) } pub(crate) fn fd_advise( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: WasiFd, offset: __wasi_filesize_t, len: __wasi_filesize_t, advice: __wasi_advice_t, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_advise(ctx, fd, offset, len, advice) } pub(crate) fn fd_allocate( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: WasiFd, offset: __wasi_filesize_t, len: __wasi_filesize_t, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_allocate(ctx, fd, offset, len) } -pub(crate) fn fd_close( - ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, -) -> wasi_snapshot0::Errno { +pub(crate) fn fd_close(ctx: FunctionEnvMut, fd: WasiFd) -> Errno { super::fd_close(ctx, fd) } -pub(crate) fn fd_datasync( - ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, -) -> wasi_snapshot0::Errno { +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_snapshot0::Fd, - buf_ptr: WasmPtr, -) -> wasi_snapshot0::Errno { + 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_snapshot0::Fd, - flags: wasi_snapshot0::Fdflags, -) -> wasi_snapshot0::Errno { + fd: WasiFd, + flags: WasiFdflags, +) -> Errno { super::fd_fdstat_set_flags(ctx, fd, flags) } pub(crate) fn fd_fdstat_set_rights( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: WasiFd, fs_rights_base: __wasi_rights_t, fs_rights_inheriting: __wasi_rights_t, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_fdstat_set_rights(ctx, fd, fs_rights_base, fs_rights_inheriting) } pub(crate) fn fd_filestat_get( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: WasiFd, buf: WasmPtr<__wasi_filestat_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_filestat_get::(ctx, fd, buf) } pub(crate) fn fd_filestat_set_size( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: WasiFd, st_size: __wasi_filesize_t, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_filestat_set_size(ctx, fd, st_size) } pub(crate) fn fd_filestat_set_times( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: WasiFd, st_atim: __wasi_timestamp_t, st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_filestat_set_times(ctx, fd, st_atim, st_mtim, fst_flags) } pub(crate) fn fd_pread( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: WasiFd, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, offset: __wasi_filesize_t, nread: WasmPtr, -) -> Result { +) -> Result { super::fd_pread::(ctx, fd, iovs, iovs_len, offset, nread) } pub(crate) fn fd_prestat_get( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: WasiFd, buf: WasmPtr<__wasi_prestat_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_prestat_get::(ctx, fd, buf) } pub(crate) fn fd_prestat_dir_name( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: WasiFd, path: WasmPtr, path_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_prestat_dir_name::(ctx, fd, path, path_len) } pub(crate) fn fd_pwrite( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: WasiFd, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, offset: __wasi_filesize_t, nwritten: WasmPtr, -) -> Result { +) -> Result { super::fd_pwrite::(ctx, fd, iovs, iovs_len, offset, nwritten) } pub(crate) fn fd_read( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: WasiFd, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, nread: WasmPtr, -) -> Result { +) -> Result { super::fd_read::(ctx, fd, iovs, iovs_len, nread) } pub(crate) fn fd_readdir( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: WasiFd, buf: WasmPtr, buf_len: MemoryOffset, cookie: __wasi_dircookie_t, bufused: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_readdir::(ctx, fd, buf, buf_len, cookie, bufused) } -pub(crate) fn fd_renumber( - ctx: FunctionEnvMut, - from: wasi_snapshot0::Fd, - to: wasi_snapshot0::Fd, -) -> wasi_snapshot0::Errno { +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_snapshot0::Fd, + fd: WasiFd, offset: __wasi_filedelta_t, whence: __wasi_whence_t, newoffset: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> Result { +) -> Result { super::fd_seek::(ctx, fd, offset, whence, newoffset) } -pub(crate) fn fd_sync( - ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, -) -> wasi_snapshot0::Errno { +pub(crate) fn fd_sync(ctx: FunctionEnvMut, fd: WasiFd) -> Errno { super::fd_sync(ctx, fd) } pub(crate) fn fd_tell( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: WasiFd, offset: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_tell::(ctx, fd, offset) } pub(crate) fn fd_write( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: WasiFd, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, nwritten: WasmPtr, -) -> Result { +) -> Result { super::fd_write::(ctx, fd, iovs, iovs_len, nwritten) } pub(crate) fn path_create_directory( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: WasiFd, path: WasmPtr, path_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> Errno { super::path_create_directory::(ctx, fd, path, path_len) } pub(crate) fn path_filestat_get( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: WasiFd, flags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, buf: WasmPtr<__wasi_filestat_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::path_filestat_get::(ctx, fd, flags, path, path_len, buf) } pub(crate) fn path_filestat_set_times( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: WasiFd, flags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, st_atim: __wasi_timestamp_t, st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, -) -> wasi_snapshot0::Errno { +) -> Errno { super::path_filestat_set_times::( ctx, fd, flags, path, path_len, st_atim, st_mtim, fst_flags, ) @@ -279,14 +269,14 @@ pub(crate) fn path_filestat_set_times( pub(crate) fn path_link( ctx: FunctionEnvMut, - old_fd: wasi_snapshot0::Fd, + old_fd: WasiFd, old_flags: __wasi_lookupflags_t, old_path: WasmPtr, old_path_len: MemoryOffset, - new_fd: wasi_snapshot0::Fd, + new_fd: WasiFd, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> Errno { super::path_link::( ctx, old_fd, @@ -301,16 +291,16 @@ pub(crate) fn path_link( pub(crate) fn path_open( ctx: FunctionEnvMut, - dirfd: wasi_snapshot0::Fd, + dirfd: WasiFd, dirflags: __wasi_lookupflags_t, 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_snapshot0::Fdflags, - fd: WasmPtr, -) -> wasi_snapshot0::Errno { + fs_flags: WasiFdflags, + fd: WasmPtr, +) -> Errno { super::path_open::( ctx, dirfd, @@ -327,34 +317,34 @@ pub(crate) fn path_open( pub(crate) fn path_readlink( ctx: FunctionEnvMut, - dir_fd: wasi_snapshot0::Fd, + dir_fd: WasiFd, path: WasmPtr, path_len: MemoryOffset, buf: WasmPtr, buf_len: MemoryOffset, buf_used: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> 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_snapshot0::Fd, + fd: WasiFd, path: WasmPtr, path_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> Errno { super::path_remove_directory::(ctx, fd, path, path_len) } pub(crate) fn path_rename( ctx: FunctionEnvMut, - old_fd: wasi_snapshot0::Fd, + old_fd: WasiFd, old_path: WasmPtr, old_path_len: MemoryOffset, - new_fd: wasi_snapshot0::Fd, + new_fd: WasiFd, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> Errno { super::path_rename::( ctx, old_fd, @@ -370,29 +360,29 @@ pub(crate) fn path_symlink( ctx: FunctionEnvMut, old_path: WasmPtr, old_path_len: MemoryOffset, - fd: wasi_snapshot0::Fd, + fd: WasiFd, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> 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_snapshot0::Fd, + fd: WasiFd, path: WasmPtr, path_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> 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 { +) -> Result { super::poll_oneoff::(ctx, in_, out_, nsubscriptions, nevents) } @@ -403,10 +393,7 @@ pub(crate) fn proc_exit( super::proc_exit(ctx, code) } -pub(crate) fn proc_raise( - ctx: FunctionEnvMut, - sig: __wasi_signal_t, -) -> wasi_snapshot0::Errno { +pub(crate) fn proc_raise(ctx: FunctionEnvMut, sig: __wasi_signal_t) -> Errno { super::proc_raise(ctx, sig) } @@ -414,25 +401,23 @@ pub(crate) fn random_get( ctx: FunctionEnvMut, buf: WasmPtr, buf_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> Errno { super::random_get::(ctx, buf, buf_len) } -pub(crate) fn sched_yield( - ctx: FunctionEnvMut, -) -> Result { +pub(crate) fn sched_yield(ctx: FunctionEnvMut) -> Result { super::sched_yield(ctx) } pub(crate) fn sock_recv( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: WasiFd, ri_data: WasmPtr<__wasi_iovec_t, MemoryType>, ri_data_len: MemoryOffset, ri_flags: __wasi_riflags_t, ro_data_len: WasmPtr, ro_flags: WasmPtr<__wasi_roflags_t, MemoryType>, -) -> Result { +) -> Result { super::sock_recv::( ctx, sock, @@ -446,19 +431,19 @@ pub(crate) fn sock_recv( pub(crate) fn sock_send( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: WasiFd, si_data: WasmPtr<__wasi_ciovec_t, MemoryType>, si_data_len: MemoryOffset, si_flags: __wasi_siflags_t, ret_data_len: WasmPtr, -) -> Result { +) -> 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_snapshot0::Fd, + sock: WasiFd, how: __wasi_sdflags_t, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_shutdown(ctx, sock, how) } diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index 3a4b86dba39..77220fc7081 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -2,7 +2,9 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{FunctionEnvMut, Memory, Memory32, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; -use wasmer_wasi_types_generated::wasi_snapshot0; +use wasmer_wasi_types_generated::wasi::{ + Advice, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Subscription, +}; type MemoryType = Memory32; type MemoryOffset = u32; @@ -11,7 +13,7 @@ pub(crate) fn args_get( ctx: FunctionEnvMut, argv: WasmPtr, MemoryType>, argv_buf: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { super::args_get::(ctx, argv, argv_buf) } @@ -19,24 +21,24 @@ pub(crate) fn args_sizes_get( ctx: FunctionEnvMut, argc: WasmPtr, argv_buf_size: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { super::args_sizes_get::(ctx, argc, argv_buf_size) } pub(crate) fn clock_res_get( ctx: FunctionEnvMut, - clock_id: wasi_snapshot0::Clockid, + clock_id: Clockid, resolution: WasmPtr<__wasi_timestamp_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::clock_res_get::(ctx, clock_id, resolution) } pub(crate) fn clock_time_get( ctx: FunctionEnvMut, - clock_id: wasi_snapshot0::Clockid, + clock_id: Clockid, precision: __wasi_timestamp_t, time: WasmPtr<__wasi_timestamp_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::clock_time_get::(ctx, clock_id, precision, time) } @@ -44,7 +46,7 @@ pub(crate) fn environ_get( ctx: FunctionEnvMut, environ: WasmPtr, MemoryType>, environ_buf: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { super::environ_get::(ctx, environ, environ_buf) } @@ -52,227 +54,210 @@ pub(crate) fn environ_sizes_get( ctx: FunctionEnvMut, environ_count: WasmPtr, environ_buf_size: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { super::environ_sizes_get::(ctx, environ_count, environ_buf_size) } pub(crate) fn fd_advise( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, offset: __wasi_filesize_t, len: __wasi_filesize_t, - advice: wasi_snapshot0::Advice, -) -> wasi_snapshot0::Errno { + advice: Advice, +) -> Errno { super::fd_advise(ctx, fd, offset, len, advice) } pub(crate) fn fd_allocate( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, offset: __wasi_filesize_t, len: __wasi_filesize_t, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_allocate(ctx, fd, offset, len) } -pub(crate) fn fd_close( - ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, -) -> wasi_snapshot0::Errno { +pub(crate) fn fd_close(ctx: FunctionEnvMut, fd: Fd) -> Errno { super::fd_close(ctx, fd) } -pub(crate) fn fd_datasync( - ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, -) -> wasi_snapshot0::Errno { +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_snapshot0::Fd, - buf_ptr: WasmPtr, -) -> wasi_snapshot0::Errno { + 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_snapshot0::Fd, - flags: wasi_snapshot0::Fdflags, -) -> wasi_snapshot0::Errno { +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_snapshot0::Fd, - fs_rights_base: wasi_snapshot0::Rights, - fs_rights_inheriting: wasi_snapshot0::Rights, -) -> wasi_snapshot0::Errno { + 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_snapshot0::Fd, + fd: Fd, buf: WasmPtr<__wasi_filestat_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_filestat_get::(ctx, fd, buf) } pub(crate) fn fd_filestat_set_size( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, st_size: __wasi_filesize_t, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_filestat_set_size(ctx, fd, st_size) } pub(crate) fn fd_filestat_set_times( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, st_atim: __wasi_timestamp_t, st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_filestat_set_times(ctx, fd, st_atim, st_mtim, fst_flags) } pub(crate) fn fd_pread( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, offset: __wasi_filesize_t, nread: WasmPtr, -) -> Result { +) -> Result { super::fd_pread::(ctx, fd, iovs, iovs_len, offset, nread) } pub(crate) fn fd_prestat_get( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, buf: WasmPtr<__wasi_prestat_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_prestat_get::(ctx, fd, buf) } pub(crate) fn fd_prestat_dir_name( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, path: WasmPtr, path_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_prestat_dir_name::(ctx, fd, path, path_len) } pub(crate) fn fd_pwrite( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, offset: __wasi_filesize_t, nwritten: WasmPtr, -) -> Result { +) -> Result { super::fd_pwrite::(ctx, fd, iovs, iovs_len, offset, nwritten) } pub(crate) fn fd_read( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, nread: WasmPtr, -) -> Result { +) -> Result { super::fd_read::(ctx, fd, iovs, iovs_len, nread) } pub(crate) fn fd_readdir( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, buf: WasmPtr, buf_len: MemoryOffset, - cookie: wasi_snapshot0::Dircookie, + cookie: Dircookie, bufused: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_readdir::(ctx, fd, buf, buf_len, cookie, bufused) } -pub(crate) fn fd_renumber( - ctx: FunctionEnvMut, - from: wasi_snapshot0::Fd, - to: wasi_snapshot0::Fd, -) -> wasi_snapshot0::Errno { +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_snapshot0::Fd, + fd: Fd, offset: __wasi_filedelta_t, whence: __wasi_whence_t, newoffset: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> Result { +) -> Result { super::fd_seek::(ctx, fd, offset, whence, newoffset) } -pub(crate) fn fd_sync( - ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, -) -> wasi_snapshot0::Errno { +pub(crate) fn fd_sync(ctx: FunctionEnvMut, fd: Fd) -> Errno { super::fd_sync(ctx, fd) } pub(crate) fn fd_tell( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, offset: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_tell::(ctx, fd, offset) } pub(crate) fn fd_write( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, nwritten: WasmPtr, -) -> Result { +) -> Result { super::fd_write::(ctx, fd, iovs, iovs_len, nwritten) } pub(crate) fn path_create_directory( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, path: WasmPtr, path_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> Errno { super::path_create_directory::(ctx, fd, path, path_len) } pub(crate) fn path_filestat_get( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, flags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, buf: WasmPtr<__wasi_filestat_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::path_filestat_get::(ctx, fd, flags, path, path_len, buf) } pub(crate) fn path_filestat_set_times( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, flags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, st_atim: __wasi_timestamp_t, st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, -) -> wasi_snapshot0::Errno { +) -> Errno { super::path_filestat_set_times::( ctx, fd, flags, path, path_len, st_atim, st_mtim, fst_flags, ) @@ -280,14 +265,14 @@ pub(crate) fn path_filestat_set_times( pub(crate) fn path_link( ctx: FunctionEnvMut, - old_fd: wasi_snapshot0::Fd, + old_fd: Fd, old_flags: __wasi_lookupflags_t, old_path: WasmPtr, old_path_len: MemoryOffset, - new_fd: wasi_snapshot0::Fd, + new_fd: Fd, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> Errno { super::path_link::( ctx, old_fd, @@ -302,16 +287,16 @@ pub(crate) fn path_link( pub(crate) fn path_open( ctx: FunctionEnvMut, - dirfd: wasi_snapshot0::Fd, + dirfd: Fd, dirflags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, o_flags: __wasi_oflags_t, - fs_rights_base: wasi_snapshot0::Rights, - fs_rights_inheriting: wasi_snapshot0::Rights, - fs_flags: wasi_snapshot0::Fdflags, - fd: WasmPtr, -) -> wasi_snapshot0::Errno { + fs_rights_base: Rights, + fs_rights_inheriting: Rights, + fs_flags: Fdflags, + fd: WasmPtr, +) -> Errno { super::path_open::( ctx, dirfd, @@ -328,34 +313,34 @@ pub(crate) fn path_open( pub(crate) fn path_readlink( ctx: FunctionEnvMut, - dir_fd: wasi_snapshot0::Fd, + dir_fd: Fd, path: WasmPtr, path_len: MemoryOffset, buf: WasmPtr, buf_len: MemoryOffset, buf_used: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> 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_snapshot0::Fd, + fd: Fd, path: WasmPtr, path_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> Errno { super::path_remove_directory::(ctx, fd, path, path_len) } pub(crate) fn path_rename( ctx: FunctionEnvMut, - old_fd: wasi_snapshot0::Fd, + old_fd: Fd, old_path: WasmPtr, old_path_len: MemoryOffset, - new_fd: wasi_snapshot0::Fd, + new_fd: Fd, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> Errno { super::path_rename::( ctx, old_fd, @@ -371,29 +356,29 @@ pub(crate) fn path_symlink( ctx: FunctionEnvMut, old_path: WasmPtr, old_path_len: MemoryOffset, - fd: wasi_snapshot0::Fd, + fd: Fd, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> 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_snapshot0::Fd, + fd: Fd, path: WasmPtr, path_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> 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 { +) -> Result { super::poll_oneoff::(ctx, in_, out_, nsubscriptions, nevents) } @@ -404,10 +389,7 @@ pub(crate) fn proc_exit( super::proc_exit(ctx, code) } -pub(crate) fn proc_raise( - ctx: FunctionEnvMut, - sig: __wasi_signal_t, -) -> wasi_snapshot0::Errno { +pub(crate) fn proc_raise(ctx: FunctionEnvMut, sig: __wasi_signal_t) -> Errno { super::proc_raise(ctx, sig) } @@ -415,15 +397,15 @@ pub(crate) fn random_get( ctx: FunctionEnvMut, buf: WasmPtr, buf_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> Errno { super::random_get::(ctx, buf, buf_len) } pub(crate) fn fd_dup( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, - ret_fd: WasmPtr, -) -> wasi_snapshot0::Errno { + fd: Fd, + ret_fd: WasmPtr, +) -> Errno { super::fd_dup::(ctx, fd, ret_fd) } @@ -431,30 +413,30 @@ pub(crate) fn fd_event( ctx: FunctionEnvMut, initial_val: u64, flags: __wasi_eventfdflags, - ret_fd: WasmPtr, -) -> wasi_snapshot0::Errno { + ret_fd: WasmPtr, +) -> Errno { super::fd_event(ctx, initial_val, flags, ret_fd) } pub(crate) fn fd_pipe( ctx: FunctionEnvMut, - ro_fd1: WasmPtr, - ro_fd2: WasmPtr, -) -> wasi_snapshot0::Errno { + 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_snapshot0::Errno { +) -> Errno { super::tty_get::(ctx, tty_state) } pub(crate) fn tty_set( ctx: FunctionEnvMut, tty_state: WasmPtr<__wasi_tty_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::tty_set::(ctx, tty_state) } @@ -462,7 +444,7 @@ pub(crate) fn getcwd( ctx: FunctionEnvMut, path: WasmPtr, path_len: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { super::getcwd::(ctx, path, path_len) } @@ -470,7 +452,7 @@ pub(crate) fn chdir( ctx: FunctionEnvMut, path: WasmPtr, path_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> Errno { super::chdir::(ctx, path, path_len) } @@ -481,55 +463,53 @@ pub(crate) fn thread_spawn( user_data: u64, reactor: __wasi_bool_t, ret_tid: WasmPtr<__wasi_tid_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> 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 { +) -> Result { super::thread_sleep(ctx, duration) } pub(crate) fn thread_id( ctx: FunctionEnvMut, ret_tid: WasmPtr<__wasi_tid_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::thread_id::(ctx, ret_tid) } pub(crate) fn thread_join( ctx: FunctionEnvMut, tid: __wasi_tid_t, -) -> Result { +) -> Result { super::thread_join(ctx, tid) } pub(crate) fn thread_parallelism( ctx: FunctionEnvMut, ret_parallelism: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { super::thread_parallelism::(ctx, ret_parallelism) } pub(crate) fn thread_exit( ctx: FunctionEnvMut, exitcode: __wasi_exitcode_t, -) -> Result { +) -> Result { super::thread_exit(ctx, exitcode) } -pub(crate) fn sched_yield( - ctx: FunctionEnvMut, -) -> Result { +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_snapshot0::Errno { +) -> Errno { super::getpid::(ctx, ret_pid) } @@ -686,33 +666,33 @@ pub(crate) fn port_bridge( token: WasmPtr, token_len: MemoryOffset, security: __wasi_streamsecurity_t, -) -> wasi_snapshot0::Errno { +) -> Errno { super::port_bridge::(ctx, network, network_len, token, token_len, security) } -pub(crate) fn port_unbridge(ctx: FunctionEnvMut) -> wasi_snapshot0::Errno { +pub(crate) fn port_unbridge(ctx: FunctionEnvMut) -> Errno { super::port_unbridge(ctx) } -pub(crate) fn port_dhcp_acquire(ctx: FunctionEnvMut) -> wasi_snapshot0::Errno { +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_snapshot0::Errno { +) -> Errno { super::port_addr_add::(ctx, addr) } pub(crate) fn port_addr_remove( ctx: FunctionEnvMut, addr: WasmPtr<__wasi_addr_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::port_addr_remove::(ctx, addr) } -pub(crate) fn port_addr_clear(ctx: FunctionEnvMut) -> wasi_snapshot0::Errno { +pub(crate) fn port_addr_clear(ctx: FunctionEnvMut) -> Errno { super::port_addr_clear(ctx) } @@ -720,21 +700,21 @@ pub(crate) fn port_addr_list( ctx: FunctionEnvMut, addrs: WasmPtr<__wasi_cidr_t, MemoryType>, naddrs: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { super::port_addr_list::(ctx, addrs, naddrs) } pub(crate) fn port_mac( ctx: FunctionEnvMut, ret_mac: WasmPtr<__wasi_hardwareaddress_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::port_mac::(ctx, ret_mac) } pub(crate) fn port_gateway_set( ctx: FunctionEnvMut, ip: WasmPtr<__wasi_addr_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::port_gateway_set::(ctx, ip) } @@ -744,18 +724,18 @@ pub(crate) fn port_route_add( via_router: WasmPtr<__wasi_addr_t, MemoryType>, preferred_until: WasmPtr<__wasi_option_timestamp_t, MemoryType>, expires_at: WasmPtr<__wasi_option_timestamp_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> 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_snapshot0::Errno { +) -> Errno { super::port_route_remove::(ctx, ip) } -pub(crate) fn port_route_clear(ctx: FunctionEnvMut) -> wasi_snapshot0::Errno { +pub(crate) fn port_route_clear(ctx: FunctionEnvMut) -> Errno { super::port_route_clear(ctx) } @@ -763,7 +743,7 @@ pub(crate) fn port_route_list( ctx: FunctionEnvMut, routes: WasmPtr<__wasi_route_t, MemoryType>, nroutes: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { super::port_route_list::(ctx, routes, nroutes) } @@ -771,8 +751,8 @@ pub(crate) fn ws_connect( ctx: FunctionEnvMut, url: WasmPtr, url_len: MemoryOffset, - ret_sock: WasmPtr, -) -> wasi_snapshot0::Errno { + ret_sock: WasmPtr, +) -> Errno { super::ws_connect::(ctx, url, url_len, ret_sock) } @@ -786,7 +766,7 @@ pub(crate) fn http_request( headers_len: MemoryOffset, gzip: __wasi_bool_t, ret_handles: WasmPtr<__wasi_http_handles_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::http_request::( ctx, url, @@ -802,37 +782,37 @@ pub(crate) fn http_request( pub(crate) fn http_status( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, status: WasmPtr<__wasi_http_status_t, MemoryType>, status_text: WasmPtr, status_text_len: WasmPtr, headers: WasmPtr, headers_len: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { super::http_status::(ctx, sock, status) } pub(crate) fn sock_status( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, ret_status: WasmPtr<__wasi_sockstatus_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_status::(ctx, sock, ret_status) } pub(crate) fn sock_addr_local( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, ret_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_addr_local::(ctx, sock, ret_addr) } pub(crate) fn sock_addr_peer( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_addr_peer::(ctx, sock, ro_addr) } @@ -841,144 +821,140 @@ pub(crate) fn sock_open( af: __wasi_addressfamily_t, ty: __wasi_socktype_t, pt: __wasi_sockproto_t, - ro_sock: WasmPtr, -) -> wasi_snapshot0::Errno { + ro_sock: WasmPtr, +) -> Errno { super::sock_open::(ctx, af, ty, pt, ro_sock) } pub(crate) fn sock_set_opt_flag( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, opt: __wasi_sockoption_t, flag: __wasi_bool_t, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_set_opt_flag(ctx, sock, opt, flag) } pub(crate) fn sock_get_opt_flag( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, opt: __wasi_sockoption_t, ret_flag: WasmPtr<__wasi_bool_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_get_opt_flag::(ctx, sock, opt, ret_flag) } pub fn sock_set_opt_time( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, opt: __wasi_sockoption_t, time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_set_opt_time(ctx, sock, opt, time) } pub fn sock_get_opt_time( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, opt: __wasi_sockoption_t, ret_time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_get_opt_time(ctx, sock, opt, ret_time) } pub fn sock_set_opt_size( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, opt: __wasi_sockoption_t, size: __wasi_filesize_t, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_set_opt_size(ctx, sock, opt, size) } pub fn sock_get_opt_size( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, opt: __wasi_sockoption_t, ret_size: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_get_opt_size(ctx, sock, opt, ret_size) } pub(crate) fn sock_join_multicast_v4( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, multiaddr: WasmPtr<__wasi_addr_ip4_t, MemoryType>, iface: WasmPtr<__wasi_addr_ip4_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_join_multicast_v4::(ctx, sock, multiaddr, iface) } pub(crate) fn sock_leave_multicast_v4( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, multiaddr: WasmPtr<__wasi_addr_ip4_t, MemoryType>, iface: WasmPtr<__wasi_addr_ip4_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_leave_multicast_v4::(ctx, sock, multiaddr, iface) } pub(crate) fn sock_join_multicast_v6( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, multiaddr: WasmPtr<__wasi_addr_ip6_t, MemoryType>, iface: u32, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_join_multicast_v6::(ctx, sock, multiaddr, iface) } pub(crate) fn sock_leave_multicast_v6( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, multiaddr: WasmPtr<__wasi_addr_ip6_t, MemoryType>, iface: u32, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_leave_multicast_v6::(ctx, sock, multiaddr, iface) } pub(crate) fn sock_bind( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_bind::(ctx, sock, addr) } -pub(crate) fn sock_listen( - ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, - backlog: MemoryOffset, -) -> wasi_snapshot0::Errno { +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_snapshot0::Fd, - fd_flags: wasi_snapshot0::Fdflags, - ro_fd: WasmPtr, + sock: Fd, + fd_flags: Fdflags, + ro_fd: WasmPtr, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> Result { +) -> Result { super::sock_accept::(ctx, sock, fd_flags, ro_fd, ro_addr) } pub(crate) fn sock_connect( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_connect::(ctx, sock, addr) } pub(crate) fn sock_recv( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, ri_data: WasmPtr<__wasi_iovec_t, MemoryType>, ri_data_len: MemoryOffset, ri_flags: __wasi_riflags_t, ro_data_len: WasmPtr, ro_flags: WasmPtr<__wasi_roflags_t, MemoryType>, -) -> Result { +) -> Result { super::sock_recv::( ctx, sock, @@ -992,14 +968,14 @@ pub(crate) fn sock_recv( pub(crate) fn sock_recv_from( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, ri_data: WasmPtr<__wasi_iovec_t, MemoryType>, ri_data_len: MemoryOffset, ri_flags: __wasi_riflags_t, ro_data_len: WasmPtr, ro_flags: WasmPtr<__wasi_roflags_t, MemoryType>, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> Result { +) -> Result { super::sock_recv_from::( ctx, sock, @@ -1014,24 +990,24 @@ pub(crate) fn sock_recv_from( pub(crate) fn sock_send( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, si_data: WasmPtr<__wasi_ciovec_t, MemoryType>, si_data_len: MemoryOffset, si_flags: __wasi_siflags_t, ret_data_len: WasmPtr, -) -> Result { +) -> 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_snapshot0::Fd, + sock: Fd, si_data: WasmPtr<__wasi_ciovec_t, MemoryType>, si_data_len: MemoryOffset, si_flags: __wasi_siflags_t, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ret_data_len: WasmPtr, -) -> Result { +) -> Result { super::sock_send_to::( ctx, sock, @@ -1045,20 +1021,20 @@ pub(crate) fn sock_send_to( pub(crate) fn sock_send_file( ctx: FunctionEnvMut, - out_fd: wasi_snapshot0::Fd, - in_fd: wasi_snapshot0::Fd, + out_fd: Fd, + in_fd: Fd, offset: __wasi_filesize_t, count: __wasi_filesize_t, ret_sent: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> Result { +) -> Result { unsafe { super::sock_send_file::(ctx, out_fd, in_fd, offset, count, ret_sent) } } pub(crate) fn sock_shutdown( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, how: __wasi_sdflags_t, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_shutdown(ctx, sock, how) } @@ -1070,6 +1046,6 @@ pub(crate) fn resolve( ips: WasmPtr<__wasi_addr_t, MemoryType>, nips: MemoryOffset, ret_nips: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> 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 004ab8fcb5e..f2c78c3594d 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -2,7 +2,9 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{FunctionEnvMut, Memory, Memory64, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; -use wasmer_wasi_types_generated::wasi_snapshot0; +use wasmer_wasi_types_generated::wasi::{ + Advice, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Subscription, +}; type MemoryType = Memory64; type MemoryOffset = u64; @@ -11,7 +13,7 @@ pub(crate) fn args_get( ctx: FunctionEnvMut, argv: WasmPtr, MemoryType>, argv_buf: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { super::args_get::(ctx, argv, argv_buf) } @@ -19,24 +21,24 @@ pub(crate) fn args_sizes_get( ctx: FunctionEnvMut, argc: WasmPtr, argv_buf_size: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { super::args_sizes_get::(ctx, argc, argv_buf_size) } pub(crate) fn clock_res_get( ctx: FunctionEnvMut, - clock_id: wasi_snapshot0::Clockid, + clock_id: Clockid, resolution: WasmPtr<__wasi_timestamp_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::clock_res_get::(ctx, clock_id, resolution) } pub(crate) fn clock_time_get( ctx: FunctionEnvMut, - clock_id: wasi_snapshot0::Clockid, + clock_id: Clockid, precision: __wasi_timestamp_t, time: WasmPtr<__wasi_timestamp_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::clock_time_get::(ctx, clock_id, precision, time) } @@ -44,7 +46,7 @@ pub(crate) fn environ_get( ctx: FunctionEnvMut, environ: WasmPtr, MemoryType>, environ_buf: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { super::environ_get::(ctx, environ, environ_buf) } @@ -52,227 +54,210 @@ pub(crate) fn environ_sizes_get( ctx: FunctionEnvMut, environ_count: WasmPtr, environ_buf_size: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { super::environ_sizes_get::(ctx, environ_count, environ_buf_size) } pub(crate) fn fd_advise( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, offset: __wasi_filesize_t, len: __wasi_filesize_t, - advice: wasi_snapshot0::Advice, -) -> wasi_snapshot0::Errno { + advice: Advice, +) -> Errno { super::fd_advise(ctx, fd, offset, len, advice) } pub(crate) fn fd_allocate( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, offset: __wasi_filesize_t, len: __wasi_filesize_t, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_allocate(ctx, fd, offset, len) } -pub(crate) fn fd_close( - ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, -) -> wasi_snapshot0::Errno { +pub(crate) fn fd_close(ctx: FunctionEnvMut, fd: Fd) -> Errno { super::fd_close(ctx, fd) } -pub(crate) fn fd_datasync( - ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, -) -> wasi_snapshot0::Errno { +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_snapshot0::Fd, - buf_ptr: WasmPtr, -) -> wasi_snapshot0::Errno { + 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_snapshot0::Fd, - flags: wasi_snapshot0::Fdflags, -) -> wasi_snapshot0::Errno { +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_snapshot0::Fd, - fs_rights_base: wasi_snapshot0::Rights, - fs_rights_inheriting: wasi_snapshot0::Rights, -) -> wasi_snapshot0::Errno { + 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_snapshot0::Fd, + fd: Fd, buf: WasmPtr<__wasi_filestat_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_filestat_get::(ctx, fd, buf) } pub(crate) fn fd_filestat_set_size( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, st_size: __wasi_filesize_t, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_filestat_set_size(ctx, fd, st_size) } pub(crate) fn fd_filestat_set_times( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, st_atim: __wasi_timestamp_t, st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_filestat_set_times(ctx, fd, st_atim, st_mtim, fst_flags) } pub(crate) fn fd_pread( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, offset: __wasi_filesize_t, nread: WasmPtr, -) -> Result { +) -> Result { super::fd_pread::(ctx, fd, iovs, iovs_len, offset, nread) } pub(crate) fn fd_prestat_get( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, buf: WasmPtr<__wasi_prestat_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_prestat_get::(ctx, fd, buf) } pub(crate) fn fd_prestat_dir_name( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, path: WasmPtr, path_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_prestat_dir_name::(ctx, fd, path, path_len) } pub(crate) fn fd_pwrite( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, offset: __wasi_filesize_t, nwritten: WasmPtr, -) -> Result { +) -> Result { super::fd_pwrite::(ctx, fd, iovs, iovs_len, offset, nwritten) } pub(crate) fn fd_read( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, nread: WasmPtr, -) -> Result { +) -> Result { super::fd_read::(ctx, fd, iovs, iovs_len, nread) } pub(crate) fn fd_readdir( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, buf: WasmPtr, buf_len: MemoryOffset, - cookie: wasi_snapshot0::Dircookie, + cookie: Dircookie, bufused: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_readdir::(ctx, fd, buf, buf_len, cookie, bufused) } -pub(crate) fn fd_renumber( - ctx: FunctionEnvMut, - from: wasi_snapshot0::Fd, - to: wasi_snapshot0::Fd, -) -> wasi_snapshot0::Errno { +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_snapshot0::Fd, + fd: Fd, offset: __wasi_filedelta_t, whence: __wasi_whence_t, newoffset: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> Result { +) -> Result { super::fd_seek::(ctx, fd, offset, whence, newoffset) } -pub(crate) fn fd_sync( - ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, -) -> wasi_snapshot0::Errno { +pub(crate) fn fd_sync(ctx: FunctionEnvMut, fd: Fd) -> Errno { super::fd_sync(ctx, fd) } pub(crate) fn fd_tell( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, offset: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::fd_tell::(ctx, fd, offset) } pub(crate) fn fd_write( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, nwritten: WasmPtr, -) -> Result { +) -> Result { super::fd_write::(ctx, fd, iovs, iovs_len, nwritten) } pub(crate) fn path_create_directory( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, path: WasmPtr, path_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> Errno { super::path_create_directory::(ctx, fd, path, path_len) } pub(crate) fn path_filestat_get( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, flags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, buf: WasmPtr<__wasi_filestat_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::path_filestat_get::(ctx, fd, flags, path, path_len, buf) } pub(crate) fn path_filestat_set_times( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, + fd: Fd, flags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, st_atim: __wasi_timestamp_t, st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, -) -> wasi_snapshot0::Errno { +) -> Errno { super::path_filestat_set_times::( ctx, fd, flags, path, path_len, st_atim, st_mtim, fst_flags, ) @@ -280,14 +265,14 @@ pub(crate) fn path_filestat_set_times( pub(crate) fn path_link( ctx: FunctionEnvMut, - old_fd: wasi_snapshot0::Fd, + old_fd: Fd, old_flags: __wasi_lookupflags_t, old_path: WasmPtr, old_path_len: MemoryOffset, - new_fd: wasi_snapshot0::Fd, + new_fd: Fd, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> Errno { super::path_link::( ctx, old_fd, @@ -302,16 +287,16 @@ pub(crate) fn path_link( pub(crate) fn path_open( ctx: FunctionEnvMut, - dirfd: wasi_snapshot0::Fd, + dirfd: Fd, dirflags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, o_flags: __wasi_oflags_t, - fs_rights_base: wasi_snapshot0::Rights, - fs_rights_inheriting: wasi_snapshot0::Rights, - fs_flags: wasi_snapshot0::Fdflags, - fd: WasmPtr, -) -> wasi_snapshot0::Errno { + fs_rights_base: Rights, + fs_rights_inheriting: Rights, + fs_flags: Fdflags, + fd: WasmPtr, +) -> Errno { super::path_open::( ctx, dirfd, @@ -328,34 +313,34 @@ pub(crate) fn path_open( pub(crate) fn path_readlink( ctx: FunctionEnvMut, - dir_fd: wasi_snapshot0::Fd, + dir_fd: Fd, path: WasmPtr, path_len: MemoryOffset, buf: WasmPtr, buf_len: MemoryOffset, buf_used: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> 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_snapshot0::Fd, + fd: Fd, path: WasmPtr, path_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> Errno { super::path_remove_directory::(ctx, fd, path, path_len) } pub(crate) fn path_rename( ctx: FunctionEnvMut, - old_fd: wasi_snapshot0::Fd, + old_fd: Fd, old_path: WasmPtr, old_path_len: MemoryOffset, - new_fd: wasi_snapshot0::Fd, + new_fd: Fd, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> Errno { super::path_rename::( ctx, old_fd, @@ -371,29 +356,29 @@ pub(crate) fn path_symlink( ctx: FunctionEnvMut, old_path: WasmPtr, old_path_len: MemoryOffset, - fd: wasi_snapshot0::Fd, + fd: Fd, new_path: WasmPtr, new_path_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> 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_snapshot0::Fd, + fd: Fd, path: WasmPtr, path_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> 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 { +) -> Result { super::poll_oneoff::(ctx, in_, out_, nsubscriptions, nevents) } @@ -404,10 +389,7 @@ pub(crate) fn proc_exit( super::proc_exit(ctx, code) } -pub(crate) fn proc_raise( - ctx: FunctionEnvMut, - sig: __wasi_signal_t, -) -> wasi_snapshot0::Errno { +pub(crate) fn proc_raise(ctx: FunctionEnvMut, sig: __wasi_signal_t) -> Errno { super::proc_raise(ctx, sig) } @@ -415,15 +397,15 @@ pub(crate) fn random_get( ctx: FunctionEnvMut, buf: WasmPtr, buf_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> Errno { super::random_get::(ctx, buf, buf_len) } pub(crate) fn fd_dup( ctx: FunctionEnvMut, - fd: wasi_snapshot0::Fd, - ret_fd: WasmPtr, -) -> wasi_snapshot0::Errno { + fd: Fd, + ret_fd: WasmPtr, +) -> Errno { super::fd_dup::(ctx, fd, ret_fd) } @@ -431,30 +413,30 @@ pub(crate) fn fd_event( ctx: FunctionEnvMut, initial_val: u64, flags: __wasi_eventfdflags, - ret_fd: WasmPtr, -) -> wasi_snapshot0::Errno { + ret_fd: WasmPtr, +) -> Errno { super::fd_event(ctx, initial_val, flags, ret_fd) } pub(crate) fn fd_pipe( ctx: FunctionEnvMut, - ro_fd1: WasmPtr, - ro_fd2: WasmPtr, -) -> wasi_snapshot0::Errno { + 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_snapshot0::Errno { +) -> Errno { super::tty_get::(ctx, tty_state) } pub(crate) fn tty_set( ctx: FunctionEnvMut, tty_state: WasmPtr<__wasi_tty_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::tty_set::(ctx, tty_state) } @@ -462,7 +444,7 @@ pub(crate) fn getcwd( ctx: FunctionEnvMut, path: WasmPtr, path_len: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { super::getcwd::(ctx, path, path_len) } @@ -470,7 +452,7 @@ pub(crate) fn chdir( ctx: FunctionEnvMut, path: WasmPtr, path_len: MemoryOffset, -) -> wasi_snapshot0::Errno { +) -> Errno { super::chdir::(ctx, path, path_len) } @@ -481,55 +463,53 @@ pub(crate) fn thread_spawn( user_data: u64, reactor: __wasi_bool_t, ret_tid: WasmPtr<__wasi_tid_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> 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 { +) -> Result { super::thread_sleep(ctx, duration) } pub(crate) fn thread_id( ctx: FunctionEnvMut, ret_tid: WasmPtr<__wasi_tid_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::thread_id::(ctx, ret_tid) } pub(crate) fn thread_join( ctx: FunctionEnvMut, tid: __wasi_tid_t, -) -> Result { +) -> Result { super::thread_join(ctx, tid) } pub(crate) fn thread_parallelism( ctx: FunctionEnvMut, ret_parallelism: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { super::thread_parallelism::(ctx, ret_parallelism) } pub(crate) fn thread_exit( ctx: FunctionEnvMut, exitcode: __wasi_exitcode_t, -) -> Result { +) -> Result { super::thread_exit(ctx, exitcode) } -pub(crate) fn sched_yield( - ctx: FunctionEnvMut, -) -> Result { +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_snapshot0::Errno { +) -> Errno { super::getpid::(ctx, ret_pid) } @@ -686,33 +666,33 @@ pub(crate) fn port_bridge( token: WasmPtr, token_len: MemoryOffset, security: __wasi_streamsecurity_t, -) -> wasi_snapshot0::Errno { +) -> Errno { super::port_bridge::(ctx, network, network_len, token, token_len, security) } -pub(crate) fn port_unbridge(ctx: FunctionEnvMut) -> wasi_snapshot0::Errno { +pub(crate) fn port_unbridge(ctx: FunctionEnvMut) -> Errno { super::port_unbridge(ctx) } -pub(crate) fn port_dhcp_acquire(ctx: FunctionEnvMut) -> wasi_snapshot0::Errno { +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_snapshot0::Errno { +) -> Errno { super::port_addr_add::(ctx, addr) } pub(crate) fn port_addr_remove( ctx: FunctionEnvMut, addr: WasmPtr<__wasi_addr_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::port_addr_remove::(ctx, addr) } -pub(crate) fn port_addr_clear(ctx: FunctionEnvMut) -> wasi_snapshot0::Errno { +pub(crate) fn port_addr_clear(ctx: FunctionEnvMut) -> Errno { super::port_addr_clear(ctx) } @@ -720,21 +700,21 @@ pub(crate) fn port_addr_list( ctx: FunctionEnvMut, addrs: WasmPtr<__wasi_cidr_t, MemoryType>, naddrs: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { super::port_addr_list::(ctx, addrs, naddrs) } pub(crate) fn port_mac( ctx: FunctionEnvMut, ret_mac: WasmPtr<__wasi_hardwareaddress_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::port_mac::(ctx, ret_mac) } pub(crate) fn port_gateway_set( ctx: FunctionEnvMut, ip: WasmPtr<__wasi_addr_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::port_gateway_set::(ctx, ip) } @@ -744,18 +724,18 @@ pub(crate) fn port_route_add( via_router: WasmPtr<__wasi_addr_t, MemoryType>, preferred_until: WasmPtr<__wasi_option_timestamp_t, MemoryType>, expires_at: WasmPtr<__wasi_option_timestamp_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> 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_snapshot0::Errno { +) -> Errno { super::port_route_remove::(ctx, ip) } -pub(crate) fn port_route_clear(ctx: FunctionEnvMut) -> wasi_snapshot0::Errno { +pub(crate) fn port_route_clear(ctx: FunctionEnvMut) -> Errno { super::port_route_clear(ctx) } @@ -763,7 +743,7 @@ pub(crate) fn port_route_list( ctx: FunctionEnvMut, routes: WasmPtr<__wasi_route_t, MemoryType>, nroutes: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { super::port_route_list::(ctx, routes, nroutes) } @@ -771,8 +751,8 @@ pub(crate) fn ws_connect( ctx: FunctionEnvMut, url: WasmPtr, url_len: MemoryOffset, - ret_sock: WasmPtr, -) -> wasi_snapshot0::Errno { + ret_sock: WasmPtr, +) -> Errno { super::ws_connect::(ctx, url, url_len, ret_sock) } @@ -786,7 +766,7 @@ pub(crate) fn http_request( headers_len: MemoryOffset, gzip: __wasi_bool_t, ret_handles: WasmPtr<__wasi_http_handles_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::http_request::( ctx, url, @@ -802,37 +782,37 @@ pub(crate) fn http_request( pub(crate) fn http_status( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, status: WasmPtr<__wasi_http_status_t, MemoryType>, status_text: WasmPtr, status_text_len: WasmPtr, headers: WasmPtr, headers_len: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> Errno { super::http_status::(ctx, sock, status) } pub(crate) fn sock_status( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, ret_status: WasmPtr<__wasi_sockstatus_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_status::(ctx, sock, ret_status) } pub(crate) fn sock_addr_local( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, ret_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_addr_local::(ctx, sock, ret_addr) } pub(crate) fn sock_addr_peer( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_addr_peer::(ctx, sock, ro_addr) } @@ -841,144 +821,140 @@ pub(crate) fn sock_open( af: __wasi_addressfamily_t, ty: __wasi_socktype_t, pt: __wasi_sockproto_t, - ro_sock: WasmPtr, -) -> wasi_snapshot0::Errno { + ro_sock: WasmPtr, +) -> Errno { super::sock_open::(ctx, af, ty, pt, ro_sock) } pub(crate) fn sock_set_opt_flag( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, opt: __wasi_sockoption_t, flag: __wasi_bool_t, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_set_opt_flag(ctx, sock, opt, flag) } pub(crate) fn sock_get_opt_flag( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, opt: __wasi_sockoption_t, ret_flag: WasmPtr<__wasi_bool_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_get_opt_flag::(ctx, sock, opt, ret_flag) } pub fn sock_set_opt_time( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, opt: __wasi_sockoption_t, time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_set_opt_time(ctx, sock, opt, time) } pub fn sock_get_opt_time( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, opt: __wasi_sockoption_t, ret_time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_get_opt_time(ctx, sock, opt, ret_time) } pub fn sock_set_opt_size( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, opt: __wasi_sockoption_t, size: __wasi_filesize_t, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_set_opt_size(ctx, sock, opt, size) } pub fn sock_get_opt_size( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, opt: __wasi_sockoption_t, ret_size: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_get_opt_size(ctx, sock, opt, ret_size) } pub(crate) fn sock_join_multicast_v4( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, multiaddr: WasmPtr<__wasi_addr_ip4_t, MemoryType>, iface: WasmPtr<__wasi_addr_ip4_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_join_multicast_v4::(ctx, sock, multiaddr, iface) } pub(crate) fn sock_leave_multicast_v4( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, multiaddr: WasmPtr<__wasi_addr_ip4_t, MemoryType>, iface: WasmPtr<__wasi_addr_ip4_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_leave_multicast_v4::(ctx, sock, multiaddr, iface) } pub(crate) fn sock_join_multicast_v6( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, multiaddr: WasmPtr<__wasi_addr_ip6_t, MemoryType>, iface: u32, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_join_multicast_v6::(ctx, sock, multiaddr, iface) } pub(crate) fn sock_leave_multicast_v6( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, multiaddr: WasmPtr<__wasi_addr_ip6_t, MemoryType>, iface: u32, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_leave_multicast_v6::(ctx, sock, multiaddr, iface) } pub(crate) fn sock_bind( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_bind::(ctx, sock, addr) } -pub(crate) fn sock_listen( - ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, - backlog: MemoryOffset, -) -> wasi_snapshot0::Errno { +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_snapshot0::Fd, - fd_flags: wasi_snapshot0::Fdflags, - ro_fd: WasmPtr, + sock: Fd, + fd_flags: Fdflags, + ro_fd: WasmPtr, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> Result { +) -> Result { super::sock_accept::(ctx, sock, fd_flags, ro_fd, ro_addr) } pub(crate) fn sock_connect( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_connect::(ctx, sock, addr) } pub(crate) fn sock_recv( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, ri_data: WasmPtr<__wasi_iovec_t, MemoryType>, ri_data_len: MemoryOffset, ri_flags: __wasi_riflags_t, ro_data_len: WasmPtr, ro_flags: WasmPtr<__wasi_roflags_t, MemoryType>, -) -> Result { +) -> Result { super::sock_recv::( ctx, sock, @@ -992,14 +968,14 @@ pub(crate) fn sock_recv( pub(crate) fn sock_recv_from( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, ri_data: WasmPtr<__wasi_iovec_t, MemoryType>, ri_data_len: MemoryOffset, ri_flags: __wasi_riflags_t, ro_data_len: WasmPtr, ro_flags: WasmPtr<__wasi_roflags_t, MemoryType>, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, -) -> Result { +) -> Result { super::sock_recv_from::( ctx, sock, @@ -1014,24 +990,24 @@ pub(crate) fn sock_recv_from( pub(crate) fn sock_send( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, si_data: WasmPtr<__wasi_ciovec_t, MemoryType>, si_data_len: MemoryOffset, si_flags: __wasi_siflags_t, ret_data_len: WasmPtr, -) -> Result { +) -> 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_snapshot0::Fd, + sock: Fd, si_data: WasmPtr<__wasi_ciovec_t, MemoryType>, si_data_len: MemoryOffset, si_flags: __wasi_siflags_t, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ret_data_len: WasmPtr, -) -> Result { +) -> Result { super::sock_send_to::( ctx, sock, @@ -1045,20 +1021,20 @@ pub(crate) fn sock_send_to( pub(crate) fn sock_send_file( ctx: FunctionEnvMut, - out_fd: wasi_snapshot0::Fd, - in_fd: wasi_snapshot0::Fd, + out_fd: Fd, + in_fd: Fd, offset: __wasi_filesize_t, count: __wasi_filesize_t, ret_sent: WasmPtr<__wasi_filesize_t, MemoryType>, -) -> Result { +) -> Result { unsafe { super::sock_send_file::(ctx, out_fd, in_fd, offset, count, ret_sent) } } pub(crate) fn sock_shutdown( ctx: FunctionEnvMut, - sock: wasi_snapshot0::Fd, + sock: Fd, how: __wasi_sdflags_t, -) -> wasi_snapshot0::Errno { +) -> Errno { super::sock_shutdown(ctx, sock, how) } @@ -1070,6 +1046,6 @@ pub(crate) fn resolve( ips: WasmPtr<__wasi_addr_t, MemoryType>, nips: MemoryOffset, ret_nips: WasmPtr, -) -> wasi_snapshot0::Errno { +) -> 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 f05930d0fc7..09e4b66e401 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}, + *, +}; use chrono::prelude::*; use std::mem; use wasmer::WasmRef; pub fn platform_clock_res_get( - clock_id: wasi_snapshot0::Clockid, + clock_id: Snapshot0Clockid, resolution: WasmRef<__wasi_timestamp_t>, -) -> Result { +) -> Result { let t_out = match clock_id { - wasi_snapshot0::Clockid::Monotonic => 10_000_000, - wasi_snapshot0::Clockid::Realtime => 1, - wasi_snapshot0::Clockid::ProcessCputimeId => 1, - wasi_snapshot0::Clockid::ThreadCputimeId => 1, - _ => return Err(wasi_snapshot0::Errno::Inval), + 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_snapshot0::Clockid, + clock_id: Snapshot0Clockid, precision: __wasi_timestamp_t, -) -> Result { +) -> Result { let new_time: DateTime = Local::now(); Ok(new_time.timestamp_nanos() as i64) } diff --git a/lib/wasi/src/utils.rs b/lib/wasi/src/utils.rs index 01e8e7497a4..884b972a9bf 100644 --- a/lib/wasi/src/utils.rs +++ b/lib/wasi/src/utils.rs @@ -1,6 +1,7 @@ use super::types::*; use std::collections::BTreeSet; use wasmer::Module; +use wasmer_wasi_types_generated::wasi::Errno; #[allow(dead_code)] /// Check if a provided module is compiled for some version of WASI. @@ -21,29 +22,29 @@ pub fn is_wasix_module(module: &Module) -> bool { } } -pub fn map_io_err(err: std::io::Error) -> wasi_snapshot0::Errno { +pub fn map_io_err(err: std::io::Error) -> Errno { use std::io::ErrorKind; match err.kind() { - ErrorKind::NotFound => wasi_snapshot0::Errno::Noent, - ErrorKind::PermissionDenied => wasi_snapshot0::Errno::Perm, - ErrorKind::ConnectionRefused => wasi_snapshot0::Errno::Connrefused, - ErrorKind::ConnectionReset => wasi_snapshot0::Errno::Connreset, - ErrorKind::ConnectionAborted => wasi_snapshot0::Errno::Connaborted, - ErrorKind::NotConnected => wasi_snapshot0::Errno::Notconn, - ErrorKind::AddrInUse => wasi_snapshot0::Errno::Addrinuse, - ErrorKind::AddrNotAvailable => wasi_snapshot0::Errno::Addrnotavail, - ErrorKind::BrokenPipe => wasi_snapshot0::Errno::Pipe, - ErrorKind::AlreadyExists => wasi_snapshot0::Errno::Exist, - ErrorKind::WouldBlock => wasi_snapshot0::Errno::Again, - ErrorKind::InvalidInput => wasi_snapshot0::Errno::Io, - ErrorKind::InvalidData => wasi_snapshot0::Errno::Io, - ErrorKind::TimedOut => wasi_snapshot0::Errno::Timedout, - ErrorKind::WriteZero => wasi_snapshot0::Errno::Io, - ErrorKind::Interrupted => wasi_snapshot0::Errno::Intr, - ErrorKind::Other => wasi_snapshot0::Errno::Io, - ErrorKind::UnexpectedEof => wasi_snapshot0::Errno::Io, - ErrorKind::Unsupported => wasi_snapshot0::Errno::Notsup, - _ => wasi_snapshot0::Errno::Io, + 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, } } From 26f42071834ba0f6081aa3df65dcd03fb8bebe75 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Tue, 23 Aug 2022 10:43:16 +0200 Subject: [PATCH 22/84] Timestamp --- lib/wasi-types/src/file.rs | 8 ++--- lib/wasi-types/src/time.rs | 5 ++- lib/wasi-types/src/versions/snapshot0.rs | 8 ++--- lib/wasi/src/syscalls/mod.rs | 44 ++++++++++++------------ lib/wasi/src/syscalls/unix/mod.rs | 6 ++-- lib/wasi/src/syscalls/wasi.rs | 16 ++++----- lib/wasi/src/syscalls/wasix32.rs | 20 +++++------ lib/wasi/src/syscalls/wasix64.rs | 20 +++++------ lib/wasi/src/syscalls/wasm32.rs | 6 ++-- lib/wasi/src/syscalls/windows.rs | 6 ++-- tests/lib/wast/src/wasi_wast.rs | 9 ++--- 11 files changed, 74 insertions(+), 74 deletions(-) diff --git a/lib/wasi-types/src/file.rs b/lib/wasi-types/src/file.rs index 2325cd982a4..16de5a0f5bb 100644 --- a/lib/wasi-types/src/file.rs +++ b/lib/wasi-types/src/file.rs @@ -5,7 +5,7 @@ use std::{ }; use wasmer_derive::ValueType; use wasmer_types::ValueType; -use wasmer_wasi_types_generated::wasi::{Fd, Filetype, Preopentype, Rights}; +use wasmer_wasi_types_generated::wasi::{Fd, Filetype, Preopentype, Rights, Timestamp}; pub type __wasi_device_t = u64; @@ -116,9 +116,9 @@ pub struct __wasi_filestat_t { pub st_filetype: Filetype, 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, + pub st_atim: Timestamp, + pub st_mtim: Timestamp, + pub st_ctim: Timestamp, } impl Default for __wasi_filestat_t { diff --git a/lib/wasi-types/src/time.rs b/lib/wasi-types/src/time.rs index 6c021601ef0..63a19fae493 100644 --- a/lib/wasi-types/src/time.rs +++ b/lib/wasi-types/src/time.rs @@ -1,11 +1,10 @@ use super::io::__wasi_option_t; use wasmer_derive::ValueType; - -pub type __wasi_timestamp_t = u64; +use wasmer_wasi_types_generated::wasi::Timestamp; #[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, + pub u: Timestamp, } diff --git a/lib/wasi-types/src/versions/snapshot0.rs b/lib/wasi-types/src/versions/snapshot0.rs index 1fe9e45e51f..afadcc73dd3 100644 --- a/lib/wasi-types/src/versions/snapshot0.rs +++ b/lib/wasi-types/src/versions/snapshot0.rs @@ -4,7 +4,7 @@ use std::mem::{self, MaybeUninit}; use wasmer_derive::ValueType; use wasmer_types::ValueType; use wasmer_wasi_types_generated::wasi::{ - Eventtype, Filetype, Snapshot0SubscriptionClock as SubscriptionClock, + Eventtype, Filetype, Snapshot0SubscriptionClock as SubscriptionClock, Timestamp, }; pub type __wasi_linkcount_t = u32; @@ -22,9 +22,9 @@ pub struct __wasi_filestat_t { pub st_filetype: Filetype, 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, + pub st_atim: Timestamp, + pub st_mtim: Timestamp, + pub st_ctim: Timestamp, } impl fmt::Debug for __wasi_filestat_t { diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 41604fdd1e7..727160beea8 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -26,7 +26,7 @@ use self::types::{ wasi::{ Advice, Clockid, Dircookie, Dirent, Errno, Event, EventEnum, EventFdReadwrite, Eventrwflags, Eventtype, Fd as WasiFd, Fdflags, Fdstat, Filetype, Rights, Snapshot0Clockid, - Subscription, SubscriptionEnum, SubscriptionFsReadwrite, + Subscription, SubscriptionEnum, SubscriptionFsReadwrite, Timestamp, }, *, }; @@ -282,12 +282,12 @@ fn write_buffer_array( Errno::Success } -fn get_current_time_in_nanos() -> Result<__wasi_timestamp_t, Errno> { +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(|_| Errno::Io)?; - Ok(duration.as_nanos() as __wasi_timestamp_t) + Ok(duration.as_nanos() as Timestamp) } /// ### `args_get()` @@ -361,12 +361,12 @@ pub fn args_sizes_get( /// - `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: Clockid, - resolution: WasmPtr<__wasi_timestamp_t, M>, + resolution: WasmPtr, ) -> Errno { trace!("wasi::clock_res_get"); let env = ctx.data(); @@ -377,7 +377,7 @@ pub fn clock_res_get( Snapshot0Clockid::from(clock_id), out_addr )); - wasi_try_mem!(resolution.write(&memory, t_out as __wasi_timestamp_t)); + wasi_try_mem!(resolution.write(&memory, t_out as Timestamp)); Errno::Success } @@ -386,16 +386,16 @@ pub fn clock_res_get( /// Inputs: /// - `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: Clockid, - precision: __wasi_timestamp_t, - time: WasmPtr<__wasi_timestamp_t, M>, + precision: Timestamp, + time: WasmPtr, ) -> Errno { debug!( "wasi::clock_time_get clock_id: {}, precision: {}", @@ -408,7 +408,7 @@ pub fn clock_time_get( Snapshot0Clockid::from(clock_id), precision )); - wasi_try_mem!(time.write(&memory, t_out as __wasi_timestamp_t)); + wasi_try_mem!(time.write(&memory, t_out as Timestamp)); let result = Errno::Success; trace!( @@ -763,17 +763,17 @@ pub fn fd_filestat_set_size( /// ### `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` /// Bit-vector for controlling which times get set pub fn fd_filestat_set_times( ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd, - st_atim: __wasi_timestamp_t, - st_mtim: __wasi_timestamp_t, + st_atim: Timestamp, + st_mtim: Timestamp, fst_flags: __wasi_fstflags_t, ) -> Errno { debug!("wasi::fd_filestat_set_times"); @@ -2055,9 +2055,9 @@ pub fn path_filestat_get_internal( /// 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` /// A bitmask controlling which attributes are set @@ -2067,8 +2067,8 @@ pub fn path_filestat_set_times( flags: __wasi_lookupflags_t, path: WasmPtr, path_len: M::Offset, - st_atim: __wasi_timestamp_t, - st_mtim: __wasi_timestamp_t, + st_atim: Timestamp, + st_mtim: Timestamp, fst_flags: __wasi_fstflags_t, ) -> Errno { debug!("wasi::path_filestat_set_times"); @@ -3575,7 +3575,7 @@ pub fn thread_spawn( /// * `duration` - Amount of time that the thread should sleep pub fn thread_sleep( ctx: FunctionEnvMut<'_, WasiEnv>, - duration: __wasi_timestamp_t, + duration: Timestamp, ) -> Result { debug!("wasi::thread_sleep"); @@ -4030,7 +4030,7 @@ 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, @@ -4924,7 +4924,7 @@ pub fn sock_get_opt_time( }, Some(timeout) => __wasi_option_timestamp_t { tag: __WASI_OPTION_SOME, - u: timeout.as_nanos() as __wasi_timestamp_t, + u: timeout.as_nanos() as Timestamp, }, }; diff --git a/lib/wasi/src/syscalls/unix/mod.rs b/lib/wasi/src/syscalls/unix/mod.rs index 941bf170154..a079f9c66e8 100644 --- a/lib/wasi/src/syscalls/unix/mod.rs +++ b/lib/wasi/src/syscalls/unix/mod.rs @@ -5,11 +5,11 @@ use libc::{ }; use std::mem; use wasmer::WasmRef; -use wasmer_wasi_types_generated::wasi::{Errno, Snapshot0Clockid}; +use wasmer_wasi_types_generated::wasi::{Errno, Snapshot0Clockid, Timestamp}; pub fn platform_clock_res_get( clock_id: Snapshot0Clockid, - resolution: WasmRef<__wasi_timestamp_t>, + resolution: WasmRef, ) -> Result { let unix_clock_id = match clock_id { Snapshot0Clockid::Monotonic => CLOCK_MONOTONIC, @@ -33,7 +33,7 @@ pub fn platform_clock_res_get( pub fn platform_clock_time_get( clock_id: Snapshot0Clockid, - precision: __wasi_timestamp_t, + precision: Timestamp, ) -> Result { let unix_clock_id = match clock_id { Snapshot0Clockid::Monotonic => CLOCK_MONOTONIC, diff --git a/lib/wasi/src/syscalls/wasi.rs b/lib/wasi/src/syscalls/wasi.rs index 8513f4c685f..ab24ff0b8fa 100644 --- a/lib/wasi/src/syscalls/wasi.rs +++ b/lib/wasi/src/syscalls/wasi.rs @@ -2,7 +2,7 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{Memory, Memory32, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::{ - wasi::{Errno, Event, Fd as WasiFd}, + wasi::{Errno, Event, Fd as WasiFd, Timestamp}, *, }; @@ -28,7 +28,7 @@ pub(crate) fn args_sizes_get( pub(crate) fn clock_res_get( ctx: FunctionEnvMut, clock_id: wasi_snapshot0::Clockid, - resolution: WasmPtr<__wasi_timestamp_t, MemoryType>, + resolution: WasmPtr, ) -> Errno { super::clock_res_get::(ctx, clock_id, resolution) } @@ -36,8 +36,8 @@ pub(crate) fn clock_res_get( pub(crate) fn clock_time_get( ctx: FunctionEnvMut, clock_id: wasi_snapshot0::Clockid, - precision: __wasi_timestamp_t, - time: WasmPtr<__wasi_timestamp_t, MemoryType>, + precision: Timestamp, + time: WasmPtr, ) -> Errno { super::clock_time_get::(ctx, clock_id, precision, time) } @@ -129,8 +129,8 @@ pub(crate) fn fd_filestat_set_size( pub(crate) fn fd_filestat_set_times( ctx: FunctionEnvMut, fd: WasiFd, - st_atim: __wasi_timestamp_t, - st_mtim: __wasi_timestamp_t, + st_atim: Timestamp, + st_mtim: Timestamp, fst_flags: __wasi_fstflags_t, ) -> Errno { super::fd_filestat_set_times(ctx, fd, st_atim, st_mtim, fst_flags) @@ -258,8 +258,8 @@ pub(crate) fn path_filestat_set_times( flags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, - st_atim: __wasi_timestamp_t, - st_mtim: __wasi_timestamp_t, + st_atim: Timestamp, + st_mtim: Timestamp, fst_flags: __wasi_fstflags_t, ) -> Errno { super::path_filestat_set_times::( diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index 77220fc7081..2703ad8455b 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -3,7 +3,7 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{FunctionEnvMut, Memory, Memory32, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ - Advice, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Subscription, + Advice, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Subscription, Timestamp, }; type MemoryType = Memory32; @@ -28,7 +28,7 @@ pub(crate) fn args_sizes_get( pub(crate) fn clock_res_get( ctx: FunctionEnvMut, clock_id: Clockid, - resolution: WasmPtr<__wasi_timestamp_t, MemoryType>, + resolution: WasmPtr, ) -> Errno { super::clock_res_get::(ctx, clock_id, resolution) } @@ -36,8 +36,8 @@ pub(crate) fn clock_res_get( pub(crate) fn clock_time_get( ctx: FunctionEnvMut, clock_id: Clockid, - precision: __wasi_timestamp_t, - time: WasmPtr<__wasi_timestamp_t, MemoryType>, + precision: Timestamp, + time: WasmPtr, ) -> Errno { super::clock_time_get::(ctx, clock_id, precision, time) } @@ -125,8 +125,8 @@ pub(crate) fn fd_filestat_set_size( pub(crate) fn fd_filestat_set_times( ctx: FunctionEnvMut, fd: Fd, - st_atim: __wasi_timestamp_t, - st_mtim: __wasi_timestamp_t, + st_atim: Timestamp, + st_mtim: Timestamp, fst_flags: __wasi_fstflags_t, ) -> Errno { super::fd_filestat_set_times(ctx, fd, st_atim, st_mtim, fst_flags) @@ -254,8 +254,8 @@ pub(crate) fn path_filestat_set_times( flags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, - st_atim: __wasi_timestamp_t, - st_mtim: __wasi_timestamp_t, + st_atim: Timestamp, + st_mtim: Timestamp, fst_flags: __wasi_fstflags_t, ) -> Errno { super::path_filestat_set_times::( @@ -469,7 +469,7 @@ pub(crate) fn thread_spawn( pub(crate) fn thread_sleep( ctx: FunctionEnvMut, - duration: __wasi_timestamp_t, + duration: Timestamp, ) -> Result { super::thread_sleep(ctx, duration) } @@ -619,7 +619,7 @@ pub(crate) fn bus_subcall( pub(crate) fn bus_poll( ctx: FunctionEnvMut, - timeout: __wasi_timestamp_t, + timeout: Timestamp, events: WasmPtr, nevents: MemoryOffset, malloc: WasmPtr, diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index f2c78c3594d..3e4efe228ac 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -3,7 +3,7 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{FunctionEnvMut, Memory, Memory64, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ - Advice, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Subscription, + Advice, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Subscription, Timestamp, }; type MemoryType = Memory64; @@ -28,7 +28,7 @@ pub(crate) fn args_sizes_get( pub(crate) fn clock_res_get( ctx: FunctionEnvMut, clock_id: Clockid, - resolution: WasmPtr<__wasi_timestamp_t, MemoryType>, + resolution: WasmPtr, ) -> Errno { super::clock_res_get::(ctx, clock_id, resolution) } @@ -36,8 +36,8 @@ pub(crate) fn clock_res_get( pub(crate) fn clock_time_get( ctx: FunctionEnvMut, clock_id: Clockid, - precision: __wasi_timestamp_t, - time: WasmPtr<__wasi_timestamp_t, MemoryType>, + precision: Timestamp, + time: WasmPtr, ) -> Errno { super::clock_time_get::(ctx, clock_id, precision, time) } @@ -125,8 +125,8 @@ pub(crate) fn fd_filestat_set_size( pub(crate) fn fd_filestat_set_times( ctx: FunctionEnvMut, fd: Fd, - st_atim: __wasi_timestamp_t, - st_mtim: __wasi_timestamp_t, + st_atim: Timestamp, + st_mtim: Timestamp, fst_flags: __wasi_fstflags_t, ) -> Errno { super::fd_filestat_set_times(ctx, fd, st_atim, st_mtim, fst_flags) @@ -254,8 +254,8 @@ pub(crate) fn path_filestat_set_times( flags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, - st_atim: __wasi_timestamp_t, - st_mtim: __wasi_timestamp_t, + st_atim: Timestamp, + st_mtim: Timestamp, fst_flags: __wasi_fstflags_t, ) -> Errno { super::path_filestat_set_times::( @@ -469,7 +469,7 @@ pub(crate) fn thread_spawn( pub(crate) fn thread_sleep( ctx: FunctionEnvMut, - duration: __wasi_timestamp_t, + duration: Timestamp, ) -> Result { super::thread_sleep(ctx, duration) } @@ -619,7 +619,7 @@ pub(crate) fn bus_subcall( pub(crate) fn bus_poll( ctx: FunctionEnvMut, - timeout: __wasi_timestamp_t, + timeout: Timestamp, events: WasmPtr, nevents: MemoryOffset, malloc: WasmPtr, diff --git a/lib/wasi/src/syscalls/wasm32.rs b/lib/wasi/src/syscalls/wasm32.rs index 09e4b66e401..2796eca5e7d 100644 --- a/lib/wasi/src/syscalls/wasm32.rs +++ b/lib/wasi/src/syscalls/wasm32.rs @@ -1,5 +1,5 @@ use crate::syscalls::types::{ - wasi::{Errno, Snapshot0Clockid}, + wasi::{Errno, Snapshot0Clockid, Timestamp}, *, }; use chrono::prelude::*; @@ -8,7 +8,7 @@ use wasmer::WasmRef; pub fn platform_clock_res_get( clock_id: Snapshot0Clockid, - resolution: WasmRef<__wasi_timestamp_t>, + resolution: WasmRef, ) -> Result { let t_out = match clock_id { Snapshot0Clockid::Monotonic => 10_000_000, @@ -22,7 +22,7 @@ pub fn platform_clock_res_get( pub fn platform_clock_time_get( clock_id: Snapshot0Clockid, - precision: __wasi_timestamp_t, + 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 5da391946e7..35ae6f8f691 100644 --- a/lib/wasi/src/syscalls/windows.rs +++ b/lib/wasi/src/syscalls/windows.rs @@ -1,10 +1,10 @@ -use crate::syscalls::types::*; +use crate::syscalls::types::{wasi::Timestamp, *}; use tracing::debug; use wasmer::WasmRef; pub fn platform_clock_res_get( clock_id: wasi_snapshot0::Clockid, - resolution: WasmRef<__wasi_timestamp_t>, + resolution: WasmRef, ) -> Result { let resolution_val = match clock_id { // resolution of monotonic clock at 10ms, from: @@ -25,7 +25,7 @@ pub fn platform_clock_res_get( pub fn platform_clock_time_get( clock_id: wasi_snapshot0::Clockid, - precision: __wasi_timestamp_t, + precision: Timestamp, ) -> Result { let nanos = match clock_id { wasi_snapshot0::Clockid::MONOTONIC => { diff --git a/tests/lib/wast/src/wasi_wast.rs b/tests/lib/wast/src/wasi_wast.rs index 6b2e13aac4c..f8e1f16631f 100644 --- a/tests/lib/wast/src/wasi_wast.rs +++ b/tests/lib/wast/src/wasi_wast.rs @@ -6,7 +6,8 @@ use std::sync::{mpsc, Arc, Mutex}; use wasmer::FunctionEnv; use wasmer::{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_t; +use wasmer_wasi::types::wasi::Timestamp; use wasmer_wasi::{ generate_import_object_from_env, get_wasi_version, FsError, Pipe, VirtualFile, WasiEnv, WasiFunctionEnv, WasiState, WasiVersion, @@ -614,13 +615,13 @@ 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 { From 8f5a1a6dacc082215111d7eba117e68c90c82a3c Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Tue, 23 Aug 2022 11:32:10 +0200 Subject: [PATCH 23/84] BusErrno --- lib/wasi-types-generated/src/lib.rs | 4 - lib/wasi-types-generated/src/wasi/bindings.rs | 109 ++++++++++++++++++ lib/wasi-types-generated/src/wasi/mod.rs | 47 ++++++++ lib/wasi-types-generated/wit/wasi.wit | 46 ++++++++ lib/wasi-types/src/bus.rs | 6 +- lib/wasi-types/src/error.rs | 21 ---- lib/wasi-types/src/io.rs | 6 +- lib/wasi-types/src/lib.rs | 2 - lib/wasi-types/src/net.rs | 8 +- lib/wasi/src/lib.rs | 12 +- lib/wasi/src/macros.rs | 4 +- lib/wasi/src/state/types.rs | 83 ++++++------- lib/wasi/src/syscalls/mod.rs | 46 ++++---- lib/wasi/src/syscalls/wasix32.rs | 25 ++-- lib/wasi/src/syscalls/wasix64.rs | 25 ++-- 15 files changed, 311 insertions(+), 133 deletions(-) delete mode 100644 lib/wasi-types/src/error.rs diff --git a/lib/wasi-types-generated/src/lib.rs b/lib/wasi-types-generated/src/lib.rs index 9cdc190a5e1..51b9aafb921 100644 --- a/lib/wasi-types-generated/src/lib.rs +++ b/lib/wasi-types-generated/src/lib.rs @@ -1,6 +1,2 @@ pub mod wasi; pub mod wasi_filesystem; - -pub mod wasi_snapshot0 { - pub use super::wasi::{Dircookie, Dirent, Fd}; -} diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index 2d4afeef0ff..062fd9e1339 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -415,6 +415,115 @@ pub mod wasi { } 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_wasmer::bitflags::bitflags! { /// File descriptor rights, determining which actions may be performed. pub struct Rights: u64 {/// The right to invoke `fd_datasync`. diff --git a/lib/wasi-types-generated/src/wasi/mod.rs b/lib/wasi-types-generated/src/wasi/mod.rs index e39969f1eb5..1096452d278 100644 --- a/lib/wasi-types-generated/src/wasi/mod.rs +++ b/lib/wasi-types-generated/src/wasi/mod.rs @@ -10,6 +10,12 @@ unsafe impl ValueType for Errno { fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for BusErrno { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + // TODO: if necessary, must be implemented in wit-bindgen unsafe impl ValueType for Filetype { #[inline] @@ -625,6 +631,47 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Errno { } } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::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, + // TODO: What should we map invalid native values to? + _ => Self::Unknown, + } + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + // TODO: if necessary, must be implemented in wit-bindgen unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Advice { type Native = i32; diff --git a/lib/wasi-types-generated/wit/wasi.wit b/lib/wasi-types-generated/wit/wasi.wit index 3fc70c5e057..64a35ddeeef 100644 --- a/lib/wasi-types-generated/wit/wasi.wit +++ b/lib/wasi-types-generated/wit/wasi.wit @@ -252,6 +252,52 @@ enum errno { notcapable, } +enum bus-errno { + // TODO: wit appears to not have support for enum type size + //(@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 diff --git a/lib/wasi-types/src/bus.rs b/lib/wasi-types/src/bus.rs index 07f587240b8..737db4b0194 100644 --- a/lib/wasi-types/src/bus.rs +++ b/lib/wasi-types/src/bus.rs @@ -1,7 +1,7 @@ use super::*; use wasmer_derive::ValueType; use wasmer_types::MemorySize; -use wasmer_wasi_types_generated::wasi_snapshot0; +use wasmer_wasi_types_generated::wasi::{BusErrno, Fd}; pub type __wasi_busdataformat_t = u8; pub const __WASI_BUS_DATA_FORMAT_RAW: __wasi_busdataformat_t = 0; @@ -35,7 +35,7 @@ pub type __wasi_cid_t = u8; #[repr(C)] pub struct __wasi_option_fd_t { pub tag: __wasi_option_t, - pub fd: wasi_snapshot0::Fd, + pub fd: Fd, } #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] @@ -86,7 +86,7 @@ pub struct __wasi_busevent_result_t { #[repr(C)] pub struct __wasi_busevent_fault_t { pub cid: __wasi_cid_t, - pub err: __bus_errno_t, + pub err: BusErrno, } #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] diff --git a/lib/wasi-types/src/error.rs b/lib/wasi-types/src/error.rs deleted file mode 100644 index 6837314eabd..00000000000 --- a/lib/wasi-types/src/error.rs +++ /dev/null @@ -1,21 +0,0 @@ -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/io.rs b/lib/wasi-types/src/io.rs index 40a72c29207..2c4701e550e 100644 --- a/lib/wasi-types/src/io.rs +++ b/lib/wasi-types/src/io.rs @@ -1,6 +1,6 @@ use wasmer_derive::ValueType; use wasmer_types::MemorySize; -use wasmer_wasi_types_generated::wasi_snapshot0; +use wasmer_wasi_types_generated::wasi::Fd; pub type __wasi_count_t = u32; @@ -43,8 +43,8 @@ pub struct __wasi_tty_t { #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] #[repr(C)] pub struct __wasi_pipe_handles_t { - pub pipe: wasi_snapshot0::Fd, - pub other: wasi_snapshot0::Fd, + pub pipe: Fd, + pub other: Fd, } pub type __wasi_stdiomode_t = u8; diff --git a/lib/wasi-types/src/lib.rs b/lib/wasi-types/src/lib.rs index 06d13658d01..e6053492337 100644 --- a/lib/wasi-types/src/lib.rs +++ b/lib/wasi-types/src/lib.rs @@ -13,7 +13,6 @@ extern crate wasmer_types as wasmer; mod bus; mod directory; -mod error; mod event; mod file; mod io; @@ -26,7 +25,6 @@ mod versions; pub use crate::time::*; pub use bus::*; pub use directory::*; -pub use error::*; pub use event::*; pub use file::*; pub use io::*; diff --git a/lib/wasi-types/src/net.rs b/lib/wasi-types/src/net.rs index 7af15b8da08..0342ba4bcbf 100644 --- a/lib/wasi-types/src/net.rs +++ b/lib/wasi-types/src/net.rs @@ -1,6 +1,6 @@ use super::*; use wasmer_derive::ValueType; -use wasmer_wasi_types_generated::wasi_snapshot0; +use wasmer_wasi_types_generated::wasi::Fd; use crate::__wasi_option_timestamp_t; @@ -460,9 +460,9 @@ pub struct __wasi_route_t { #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] #[repr(C)] pub struct __wasi_http_handles_t { - pub req: wasi_snapshot0::Fd, - pub res: wasi_snapshot0::Fd, - pub hdr: wasi_snapshot0::Fd, + pub req: Fd, + pub res: Fd, + pub hdr: Fd, } #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index f158b050ef2..49c089c92a3 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -65,7 +65,7 @@ use wasmer::{ imports, namespace, AsStoreMut, AsStoreRef, Exports, Function, FunctionEnv, Imports, Memory, Memory32, MemoryAccessError, MemorySize, MemoryView, Module, TypedFunction, }; -use wasmer_wasi_types_generated::wasi::{Errno, Snapshot0Clockid}; +use wasmer_wasi_types_generated::wasi::{BusErrno, Errno, Snapshot0Clockid}; pub use runtime::{ PluggableRuntimeImplementation, WasiRuntimeImplementation, WasiThreadError, WasiTtyState, @@ -784,11 +784,11 @@ fn mem_error_to_wasi(err: MemoryAccessError) -> Errno { } } -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 2f3da95588d..450e88cd637 100644 --- a/lib/wasi/src/macros.rs +++ b/lib/wasi/src/macros.rs @@ -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<_, __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); @@ -78,7 +78,7 @@ macro_rules! wasi_try_mem { }}; } -/// 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)) diff --git a/lib/wasi/src/state/types.rs b/lib/wasi/src/state/types.rs index c91b1526500..c3e33fdade3 100644 --- a/lib/wasi/src/state/types.rs +++ b/lib/wasi/src/state/types.rs @@ -11,7 +11,7 @@ use std::{ time::Duration, }; use wasmer_vbus::BusError; -use wasmer_wasi_types_generated::wasi::Errno; +use wasmer_wasi_types_generated::wasi::{BusErrno, Errno}; #[cfg(feature = "host-fs")] pub use wasmer_vfs::host_fs::{Stderr, Stdin, Stdout}; @@ -103,53 +103,54 @@ pub fn net_error_into_wasi_err(net_error: NetworkError) -> Errno { } } -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, } } diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 727160beea8..18f85fbde48 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -24,7 +24,7 @@ pub mod wasix64; use self::types::{ wasi::{ - Advice, Clockid, Dircookie, Dirent, Errno, Event, EventEnum, EventFdReadwrite, + Advice, BusErrno, Clockid, Dircookie, Dirent, Errno, Event, EventEnum, EventFdReadwrite, Eventrwflags, Eventtype, Fd as WasiFd, Fdflags, Fdstat, Filetype, Rights, Snapshot0Clockid, Subscription, SubscriptionEnum, SubscriptionFsReadwrite, Timestamp, }, @@ -3723,7 +3723,7 @@ pub fn process_spawn( working_dir: WasmPtr, working_dir_len: M::Offset, ret_handles: WasmPtr<__wasi_bus_handles_t, M>, -) -> __bus_errno_t { +) -> BusErrno { let env = ctx.data(); let bus = env.runtime.bus(); let memory = env.memory_view(&ctx); @@ -3794,7 +3794,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 @@ -3815,7 +3815,7 @@ pub fn bus_open_local( name_len: M::Offset, reuse: __wasi_bool_t, ret_bid: WasmPtr<__wasi_bid_t, M>, -) -> __bus_errno_t { +) -> BusErrno { let env = ctx.data(); let bus = env.runtime.bus(); let memory = env.memory_view(&ctx); @@ -3850,7 +3850,7 @@ pub fn bus_open_remote( token: WasmPtr, token_len: M::Offset, ret_bid: WasmPtr<__wasi_bid_t, M>, -) -> __bus_errno_t { +) -> BusErrno { let env = ctx.data(); let bus = env.runtime.bus(); let memory = env.memory_view(&ctx); @@ -3873,7 +3873,7 @@ fn bus_open_local_internal( instance: Option, token: Option, ret_bid: WasmPtr<__wasi_bid_t, M>, -) -> __bus_errno_t { +) -> BusErrno { let env = ctx.data(); let bus = env.runtime.bus(); let memory = env.memory_view(&ctx); @@ -3885,7 +3885,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; } } } @@ -3921,7 +3921,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 @@ -3929,7 +3929,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: __wasi_bid_t) -> BusErrno { trace!("wasi::bus_close (bid={})", bid); let bid: WasiBusProcessId = bid.into(); @@ -3937,7 +3937,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. @@ -3961,7 +3961,7 @@ pub fn bus_call( buf: WasmPtr, buf_len: M::Offset, ret_cid: WasmPtr<__wasi_cid_t, M>, -) -> __bus_errno_t { +) -> BusErrno { let env = ctx.data(); let bus = env.runtime.bus(); let memory = env.memory_view(&ctx); @@ -3974,7 +3974,7 @@ pub fn bus_call( buf_len ); - __BUS_EUNSUPPORTED + BusErrno::Unsupported } /// Invokes a call within the context of another call @@ -3998,7 +3998,7 @@ pub fn bus_subcall( buf: WasmPtr, buf_len: M::Offset, ret_cid: WasmPtr<__wasi_cid_t, M>, -) -> __bus_errno_t { +) -> BusErrno { let env = ctx.data(); let bus = env.runtime.bus(); let memory = env.memory_view(&ctx); @@ -4011,7 +4011,7 @@ pub fn bus_subcall( buf_len ); - __BUS_EUNSUPPORTED + BusErrno::Unsupported } /// Polls for any outstanding events from a particular @@ -4036,14 +4036,14 @@ pub fn bus_poll( 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 @@ -4062,7 +4062,7 @@ pub fn call_reply( format: __wasi_busdataformat_t, buf: WasmPtr, buf_len: M::Offset, -) -> __bus_errno_t { +) -> BusErrno { let env = ctx.data(); let bus = env.runtime.bus(); trace!( @@ -4072,7 +4072,7 @@ pub fn call_reply( buf_len ); - __BUS_EUNSUPPORTED + BusErrno::Unsupported } /// Causes a fault on a particular call that was made @@ -4086,13 +4086,13 @@ pub fn call_reply( pub fn call_fault( ctx: FunctionEnvMut<'_, WasiEnv>, cid: __wasi_cid_t, - fault: __bus_errno_t, -) -> __bus_errno_t { + 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 @@ -4100,12 +4100,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: __wasi_cid_t) -> BusErrno { let env = ctx.data(); let bus = env.runtime.bus(); trace!("wasi::call_close (cid={})", cid); - __BUS_EUNSUPPORTED + BusErrno::Unsupported } /// ### `ws_connect()` diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index 2703ad8455b..166216bf5ab 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -3,7 +3,8 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{FunctionEnvMut, Memory, Memory32, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ - Advice, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Subscription, Timestamp, + Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Subscription, + Timestamp, }; type MemoryType = Memory32; @@ -528,7 +529,7 @@ pub(crate) fn process_spawn( working_dir: WasmPtr, working_dir_len: MemoryOffset, ret_handles: WasmPtr<__wasi_bus_handles_t, MemoryType>, -) -> __bus_errno_t { +) -> BusErrno { super::process_spawn::( ctx, name, @@ -553,7 +554,7 @@ pub(crate) fn bus_open_local( name_len: MemoryOffset, reuse: __wasi_bool_t, ret_bid: WasmPtr<__wasi_bid_t, MemoryType>, -) -> __bus_errno_t { +) -> BusErrno { super::bus_open_local::(ctx, name, name_len, reuse, ret_bid) } @@ -567,7 +568,7 @@ pub(crate) fn bus_open_remote( token: WasmPtr, token_len: MemoryOffset, ret_bid: WasmPtr<__wasi_bid_t, MemoryType>, -) -> __bus_errno_t { +) -> BusErrno { super::bus_open_remote::( ctx, name, @@ -581,7 +582,7 @@ 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: __wasi_bid_t) -> BusErrno { super::bus_close(ctx, bid) } @@ -595,7 +596,7 @@ pub(crate) fn bus_call( buf: WasmPtr, buf_len: MemoryOffset, ret_cid: WasmPtr<__wasi_cid_t, MemoryType>, -) -> __bus_errno_t { +) -> BusErrno { super::bus_call::( ctx, bid, keep_alive, topic, topic_len, format, buf, buf_len, ret_cid, ) @@ -611,7 +612,7 @@ pub(crate) fn bus_subcall( buf: WasmPtr, buf_len: MemoryOffset, ret_cid: WasmPtr<__wasi_cid_t, MemoryType>, -) -> __bus_errno_t { +) -> BusErrno { super::bus_subcall::( ctx, parent, keep_alive, topic, topic_len, format, buf, buf_len, ret_cid, ) @@ -625,7 +626,7 @@ pub(crate) fn bus_poll( malloc: WasmPtr, malloc_len: MemoryOffset, ret_nevents: WasmPtr, -) -> __bus_errno_t { +) -> BusErrno { super::bus_poll::( ctx, timeout, @@ -643,19 +644,19 @@ pub(crate) fn call_reply( format: __wasi_busdataformat_t, 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 { + 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: __wasi_cid_t) -> BusErrno { super::call_close(ctx, cid) } diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index 3e4efe228ac..9d9d2b30257 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -3,7 +3,8 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{FunctionEnvMut, Memory, Memory64, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ - Advice, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Subscription, Timestamp, + Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Subscription, + Timestamp, }; type MemoryType = Memory64; @@ -528,7 +529,7 @@ pub(crate) fn process_spawn( working_dir: WasmPtr, working_dir_len: MemoryOffset, ret_handles: WasmPtr<__wasi_bus_handles_t, MemoryType>, -) -> __bus_errno_t { +) -> BusErrno { super::process_spawn::( ctx, name, @@ -553,7 +554,7 @@ pub(crate) fn bus_open_local( name_len: MemoryOffset, reuse: __wasi_bool_t, ret_bid: WasmPtr<__wasi_bid_t, MemoryType>, -) -> __bus_errno_t { +) -> BusErrno { super::bus_open_local::(ctx, name, name_len, reuse, ret_bid) } @@ -567,7 +568,7 @@ pub(crate) fn bus_open_remote( token: WasmPtr, token_len: MemoryOffset, ret_bid: WasmPtr<__wasi_bid_t, MemoryType>, -) -> __bus_errno_t { +) -> BusErrno { super::bus_open_remote::( ctx, name, @@ -581,7 +582,7 @@ 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: __wasi_bid_t) -> BusErrno { super::bus_close(ctx, bid) } @@ -595,7 +596,7 @@ pub(crate) fn bus_call( buf: WasmPtr, buf_len: MemoryOffset, ret_cid: WasmPtr<__wasi_cid_t, MemoryType>, -) -> __bus_errno_t { +) -> BusErrno { super::bus_call::( ctx, bid, keep_alive, topic, topic_len, format, buf, buf_len, ret_cid, ) @@ -611,7 +612,7 @@ pub(crate) fn bus_subcall( buf: WasmPtr, buf_len: MemoryOffset, ret_cid: WasmPtr<__wasi_cid_t, MemoryType>, -) -> __bus_errno_t { +) -> BusErrno { super::bus_subcall::( ctx, parent, keep_alive, topic, topic_len, format, buf, buf_len, ret_cid, ) @@ -625,7 +626,7 @@ pub(crate) fn bus_poll( malloc: WasmPtr, malloc_len: MemoryOffset, ret_nevents: WasmPtr, -) -> __bus_errno_t { +) -> BusErrno { super::bus_poll::( ctx, timeout, @@ -643,19 +644,19 @@ pub(crate) fn call_reply( format: __wasi_busdataformat_t, 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 { + 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: __wasi_cid_t) -> BusErrno { super::call_close(ctx, cid) } From 60cbd02ff30ff2cd6f98335cc4c6cd838ce7fcf1 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Wed, 24 Aug 2022 10:29:07 +0200 Subject: [PATCH 24/84] Socktype --- lib/wasi-types-generated/src/wasi/bindings.rs | 26 +++++ lib/wasi-types-generated/src/wasi/mod.rs | 31 ++++++ lib/wasi-types-generated/wit/wasi.wit | 7 ++ lib/wasi-types/src/event.rs | 103 ------------------ lib/wasi-types/src/lib.rs | 2 - lib/wasi-types/src/net.rs | 6 - lib/wasi/src/state/socket.rs | 14 +-- lib/wasi/src/syscalls/mod.rs | 6 +- lib/wasi/src/syscalls/wasix32.rs | 6 +- lib/wasi/src/syscalls/wasix64.rs | 6 +- 10 files changed, 80 insertions(+), 127 deletions(-) delete mode 100644 lib/wasi-types/src/event.rs diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index 062fd9e1339..f36af3fc691 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -1120,6 +1120,32 @@ pub mod wasi { 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() + } + } + } + } /// Auxiliary data associated with the wasm exports. #[derive(Default)] diff --git a/lib/wasi-types-generated/src/wasi/mod.rs b/lib/wasi-types-generated/src/wasi/mod.rs index 1096452d278..316d9aea4a5 100644 --- a/lib/wasi-types-generated/src/wasi/mod.rs +++ b/lib/wasi-types-generated/src/wasi/mod.rs @@ -22,6 +22,12 @@ unsafe impl ValueType for Filetype { 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]) {} +} + impl Filetype { pub fn name(self) -> &'static str { match self { @@ -699,6 +705,31 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Advice { } } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + // TODO: if necessary, must be implemented in wit-bindgen unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Rights { type Native = i64; diff --git a/lib/wasi-types-generated/wit/wasi.wit b/lib/wasi-types-generated/wit/wasi.wit index 64a35ddeeef..c247bdde760 100644 --- a/lib/wasi-types-generated/wit/wasi.wit +++ b/lib/wasi-types-generated/wit/wasi.wit @@ -694,3 +694,10 @@ record subscription { userdata: userdata, data: subscription-enum, } + +enum socktype { + dgram, + %stream, + raw, + seqpacket, +} diff --git a/lib/wasi-types/src/event.rs b/lib/wasi-types/src/event.rs deleted file mode 100644 index ab949202d1d..00000000000 --- a/lib/wasi-types/src/event.rs +++ /dev/null @@ -1,103 +0,0 @@ -/* TODO: if required, move to generated wasi::Event type -use crate::*; -use std::{ - fmt, - mem::{self, MaybeUninit}, -}; -use wasmer_derive::ValueType; -use wasmer_types::ValueType; -use wasmer_wasi_types_generated::wasi; - -#[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, -} - -#[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, - }, -} - -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 }, - }, - } - } -} - -impl __wasi_event_t { - pub fn tagged(&self) -> Option { - match self.type_ { - wasi::Eventtype::FdRead | wasi::Eventtype::FdWrite => 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::FdRead | wasi::Eventtype::FdWrite => 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)); - } -} -*/ diff --git a/lib/wasi-types/src/lib.rs b/lib/wasi-types/src/lib.rs index e6053492337..7e5440cc865 100644 --- a/lib/wasi-types/src/lib.rs +++ b/lib/wasi-types/src/lib.rs @@ -13,7 +13,6 @@ extern crate wasmer_types as wasmer; mod bus; mod directory; -mod event; mod file; mod io; mod net; @@ -25,7 +24,6 @@ mod versions; pub use crate::time::*; pub use bus::*; pub use directory::*; -pub use event::*; pub use file::*; pub use io::*; pub use net::*; diff --git a/lib/wasi-types/src/net.rs b/lib/wasi-types/src/net.rs index 0342ba4bcbf..9fe8a126e31 100644 --- a/lib/wasi-types/src/net.rs +++ b/lib/wasi-types/src/net.rs @@ -4,12 +4,6 @@ use wasmer_wasi_types_generated::wasi::Fd; 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; diff --git a/lib/wasi/src/state/socket.rs b/lib/wasi/src/state/socket.rs index 6046694f62b..6bce16173ab 100644 --- a/lib/wasi/src/state/socket.rs +++ b/lib/wasi/src/state/socket.rs @@ -16,7 +16,7 @@ use wasmer_vnet::{ IpCidr, IpRoute, SocketHttpRequest, VirtualIcmpSocket, VirtualNetworking, VirtualRawSocket, VirtualTcpListener, VirtualTcpSocket, VirtualUdpSocket, VirtualWebSocket, }; -use wasmer_wasi_types_generated::wasi::{Errno, Fdflags, Rights}; +use wasmer_wasi_types_generated::wasi::{Errno, Fdflags, Socktype}; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; @@ -37,7 +37,7 @@ pub enum InodeHttpSocketType { pub enum InodeSocketKind { PreSocket { family: __wasi_addressfamily_t, - ty: __wasi_socktype_t, + ty: Socktype, pt: __wasi_sockproto_t, addr: Option, only_v6: bool, @@ -193,12 +193,12 @@ 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)?; @@ -226,7 +226,7 @@ impl InodeSocket { accept_timeout, .. } => Ok(match *ty { - __WASI_SOCK_TYPE_STREAM => { + Socktype::Stream => { if addr.is_none() { return Err(Errno::Inval); } @@ -291,7 +291,7 @@ impl InodeSocket { connect_timeout, .. } => Ok(match *ty { - __WASI_SOCK_TYPE_STREAM => { + Socktype::Stream => { let addr = match addr { Some(a) => *a, None => { @@ -317,7 +317,7 @@ impl InodeSocket { } Some(InodeSocket::new(InodeSocketKind::TcpStream(socket))) } - __WASI_SOCK_TYPE_DGRAM => return Err(Errno::Inval), + Socktype::Dgram => return Err(Errno::Inval), _ => return Err(Errno::Notsup), }), InodeSocketKind::UdpSocket(sock) => { diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 18f85fbde48..063f8c63c55 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -26,7 +26,7 @@ use self::types::{ wasi::{ Advice, BusErrno, Clockid, Dircookie, Dirent, Errno, Event, EventEnum, EventFdReadwrite, Eventrwflags, Eventtype, Fd as WasiFd, Fdflags, Fdstat, Filetype, Rights, Snapshot0Clockid, - Subscription, SubscriptionEnum, SubscriptionFsReadwrite, Timestamp, + Socktype, Subscription, SubscriptionEnum, SubscriptionFsReadwrite, Timestamp, }, *, }; @@ -4739,7 +4739,7 @@ pub fn sock_addr_peer( pub fn sock_open( ctx: FunctionEnvMut<'_, WasiEnv>, af: __wasi_addressfamily_t, - ty: __wasi_socktype_t, + ty: Socktype, pt: __wasi_sockproto_t, ro_sock: WasmPtr, ) -> Errno { @@ -4749,7 +4749,7 @@ pub fn sock_open( 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, diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index 166216bf5ab..0088401d188 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -3,8 +3,8 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{FunctionEnvMut, Memory, Memory32, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ - Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Subscription, - Timestamp, + Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Socktype, + Subscription, Timestamp, }; type MemoryType = Memory32; @@ -820,7 +820,7 @@ pub(crate) fn sock_addr_peer( pub(crate) fn sock_open( ctx: FunctionEnvMut, af: __wasi_addressfamily_t, - ty: __wasi_socktype_t, + ty: Socktype, pt: __wasi_sockproto_t, ro_sock: WasmPtr, ) -> Errno { diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index 9d9d2b30257..e9eaac1825e 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -3,8 +3,8 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{FunctionEnvMut, Memory, Memory64, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ - Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Subscription, - Timestamp, + Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Socktype, + Subscription, Timestamp, }; type MemoryType = Memory64; @@ -820,7 +820,7 @@ pub(crate) fn sock_addr_peer( pub(crate) fn sock_open( ctx: FunctionEnvMut, af: __wasi_addressfamily_t, - ty: __wasi_socktype_t, + ty: Socktype, pt: __wasi_sockproto_t, ro_sock: WasmPtr, ) -> Errno { From 0b86b61ab062a5f6a9d2a1961198cc69d7f1120d Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Wed, 24 Aug 2022 10:54:12 +0200 Subject: [PATCH 25/84] Sockstatus --- lib/wasi-types-generated/src/wasi/bindings.rs | 26 ++++++++++++++++ lib/wasi-types-generated/src/wasi/mod.rs | 31 +++++++++++++++++++ lib/wasi-types-generated/wit/wasi.wit | 7 +++++ lib/wasi-types/src/file.rs | 1 - lib/wasi-types/src/net.rs | 6 ---- lib/wasi-types/src/subscription.rs | 10 +----- lib/wasi-types/src/versions/snapshot0.rs | 6 +--- lib/wasi/src/state/types.rs | 1 - lib/wasi/src/syscalls/mod.rs | 12 +++---- lib/wasi/src/syscalls/wasix32.rs | 6 ++-- lib/wasi/src/syscalls/wasix64.rs | 6 ++-- lib/wasi/src/utils.rs | 1 - 12 files changed, 78 insertions(+), 35 deletions(-) diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index f36af3fc691..5595782b99c 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -1146,6 +1146,32 @@ pub mod wasi { } } } + #[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() + } + } + } + } /// Auxiliary data associated with the wasm exports. #[derive(Default)] diff --git a/lib/wasi-types-generated/src/wasi/mod.rs b/lib/wasi-types-generated/src/wasi/mod.rs index 316d9aea4a5..f3ad7f8ff21 100644 --- a/lib/wasi-types-generated/src/wasi/mod.rs +++ b/lib/wasi-types-generated/src/wasi/mod.rs @@ -28,6 +28,12 @@ unsafe impl ValueType for Socktype { fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Sockstatus { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + impl Filetype { pub fn name(self) -> &'static str { match self { @@ -730,6 +736,31 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Socktype { } } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + // TODO: if necessary, must be implemented in wit-bindgen unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Rights { type Native = i64; diff --git a/lib/wasi-types-generated/wit/wasi.wit b/lib/wasi-types-generated/wit/wasi.wit index c247bdde760..a759ff57b80 100644 --- a/lib/wasi-types-generated/wit/wasi.wit +++ b/lib/wasi-types-generated/wit/wasi.wit @@ -701,3 +701,10 @@ enum socktype { raw, seqpacket, } + +enum sockstatus { + opening, + opened, + closed, + failed, +} diff --git a/lib/wasi-types/src/file.rs b/lib/wasi-types/src/file.rs index 16de5a0f5bb..ccb558e3eda 100644 --- a/lib/wasi-types/src/file.rs +++ b/lib/wasi-types/src/file.rs @@ -1,4 +1,3 @@ -use crate::*; use std::{ fmt, mem::{self, MaybeUninit}, diff --git a/lib/wasi-types/src/net.rs b/lib/wasi-types/src/net.rs index 9fe8a126e31..f8af64dddc8 100644 --- a/lib/wasi-types/src/net.rs +++ b/lib/wasi-types/src/net.rs @@ -4,12 +4,6 @@ use wasmer_wasi_types_generated::wasi::Fd; use crate::__wasi_option_timestamp_t; -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; diff --git a/lib/wasi-types/src/subscription.rs b/lib/wasi-types/src/subscription.rs index b2029df2c88..e47e26eb31c 100644 --- a/lib/wasi-types/src/subscription.rs +++ b/lib/wasi-types/src/subscription.rs @@ -1,12 +1,4 @@ -use crate::*; -use std::convert::TryFrom; -use std::fmt; -use std::mem::{self, MaybeUninit}; -use wasmer_types::ValueType; -use wasmer_wasi_types_generated::wasi::{ - Clockid, Errno, Eventtype, Fd, Subclockflags, Subscription, SubscriptionClock, - SubscriptionEnum, SubscriptionFsReadwrite, Timestamp, Userdata, -}; +use wasmer_wasi_types_generated::wasi::{Eventtype, SubscriptionClock, SubscriptionFsReadwrite}; /// Safe Rust wrapper around `__wasi_subscription_t::type_` and `__wasi_subscription_t::u` #[derive(Debug, Clone)] diff --git a/lib/wasi-types/src/versions/snapshot0.rs b/lib/wasi-types/src/versions/snapshot0.rs index afadcc73dd3..e2277286be1 100644 --- a/lib/wasi-types/src/versions/snapshot0.rs +++ b/lib/wasi-types/src/versions/snapshot0.rs @@ -1,11 +1,7 @@ use crate::*; use std::fmt; -use std::mem::{self, MaybeUninit}; use wasmer_derive::ValueType; -use wasmer_types::ValueType; -use wasmer_wasi_types_generated::wasi::{ - Eventtype, Filetype, Snapshot0SubscriptionClock as SubscriptionClock, Timestamp, -}; +use wasmer_wasi_types_generated::wasi::{Filetype, Timestamp}; pub type __wasi_linkcount_t = u32; diff --git a/lib/wasi/src/state/types.rs b/lib/wasi/src/state/types.rs index c3e33fdade3..662b0819f9b 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"))] diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 063f8c63c55..61fa6664c30 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -26,7 +26,7 @@ use self::types::{ wasi::{ Advice, BusErrno, Clockid, Dircookie, Dirent, Errno, Event, EventEnum, EventFdReadwrite, Eventrwflags, Eventtype, Fd as WasiFd, Fdflags, Fdstat, Filetype, Rights, Snapshot0Clockid, - Socktype, Subscription, SubscriptionEnum, SubscriptionFsReadwrite, Timestamp, + Sockstatus, Socktype, Subscription, SubscriptionEnum, SubscriptionFsReadwrite, Timestamp, }, *, }; @@ -4631,7 +4631,7 @@ pub fn sock_shutdown( pub fn sock_status( ctx: FunctionEnvMut<'_, WasiEnv>, sock: WasiFd, - ret_status: WasmPtr<__wasi_sockstatus_t, M>, + ret_status: WasmPtr, ) -> Errno { debug!("wasi::sock_status"); @@ -4641,10 +4641,10 @@ pub fn sock_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(); diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index 0088401d188..6fd5c1e71cd 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -3,8 +3,8 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{FunctionEnvMut, Memory, Memory32, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ - Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Socktype, - Subscription, Timestamp, + Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Sockstatus, + Socktype, Subscription, Timestamp, }; type MemoryType = Memory32; @@ -796,7 +796,7 @@ pub(crate) fn http_status( pub(crate) fn sock_status( ctx: FunctionEnvMut, sock: Fd, - ret_status: WasmPtr<__wasi_sockstatus_t, MemoryType>, + ret_status: WasmPtr, ) -> Errno { super::sock_status::(ctx, sock, ret_status) } diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index e9eaac1825e..6e5cc33a175 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -3,8 +3,8 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{FunctionEnvMut, Memory, Memory64, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ - Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Socktype, - Subscription, Timestamp, + Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Sockstatus, + Socktype, Subscription, Timestamp, }; type MemoryType = Memory64; @@ -796,7 +796,7 @@ pub(crate) fn http_status( pub(crate) fn sock_status( ctx: FunctionEnvMut, sock: Fd, - ret_status: WasmPtr<__wasi_sockstatus_t, MemoryType>, + ret_status: WasmPtr, ) -> Errno { super::sock_status::(ctx, sock, ret_status) } diff --git a/lib/wasi/src/utils.rs b/lib/wasi/src/utils.rs index 884b972a9bf..668ce684687 100644 --- a/lib/wasi/src/utils.rs +++ b/lib/wasi/src/utils.rs @@ -1,4 +1,3 @@ -use super::types::*; use std::collections::BTreeSet; use wasmer::Module; use wasmer_wasi_types_generated::wasi::Errno; From 7c70dcb1b4c609173efae01af7e4f0221decf072 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Wed, 24 Aug 2022 19:44:44 +0200 Subject: [PATCH 26/84] Sockoption --- lib/wasi-types-generated/src/wasi/bindings.rs | 118 ++++++++++++++++++ lib/wasi-types-generated/src/wasi/mod.rs | 89 +++++++++++++ lib/wasi-types-generated/wit/wasi.wit | 30 +++++ lib/wasi-types/src/net.rs | 29 ----- lib/wasi/src/state/socket.rs | 61 +++++---- lib/wasi/src/syscalls/mod.rs | 67 +++++----- lib/wasi/src/syscalls/wasix32.rs | 16 +-- lib/wasi/src/syscalls/wasix64.rs | 16 +-- 8 files changed, 314 insertions(+), 112 deletions(-) diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index 5595782b99c..1b064a4db1c 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -1172,6 +1172,124 @@ pub mod wasi { } } } + #[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() + } + } + } + } /// Auxiliary data associated with the wasm exports. #[derive(Default)] diff --git a/lib/wasi-types-generated/src/wasi/mod.rs b/lib/wasi-types-generated/src/wasi/mod.rs index f3ad7f8ff21..f80714f6936 100644 --- a/lib/wasi-types-generated/src/wasi/mod.rs +++ b/lib/wasi-types-generated/src/wasi/mod.rs @@ -34,6 +34,12 @@ unsafe impl ValueType for Sockstatus { fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Sockoption { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + impl Filetype { pub fn name(self) -> &'static str { match self { @@ -864,6 +870,89 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Snapshot0Clocki } } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + +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 wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Fdflags { type Native = i32; diff --git a/lib/wasi-types-generated/wit/wasi.wit b/lib/wasi-types-generated/wit/wasi.wit index a759ff57b80..9faac44611e 100644 --- a/lib/wasi-types-generated/wit/wasi.wit +++ b/lib/wasi-types-generated/wit/wasi.wit @@ -708,3 +708,33 @@ enum sockstatus { 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, +} diff --git a/lib/wasi-types/src/net.rs b/lib/wasi-types/src/net.rs index f8af64dddc8..c20c848e058 100644 --- a/lib/wasi-types/src/net.rs +++ b/lib/wasi-types/src/net.rs @@ -4,35 +4,6 @@ use wasmer_wasi_types_generated::wasi::Fd; use crate::__wasi_option_timestamp_t; -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; diff --git a/lib/wasi/src/state/socket.rs b/lib/wasi/src/state/socket.rs index 6bce16173ab..1d8f6264fd8 100644 --- a/lib/wasi/src/state/socket.rs +++ b/lib/wasi/src/state/socket.rs @@ -16,7 +16,7 @@ use wasmer_vnet::{ IpCidr, IpRoute, SocketHttpRequest, VirtualIcmpSocket, VirtualNetworking, VirtualRawSocket, VirtualTcpListener, VirtualTcpSocket, VirtualUdpSocket, VirtualWebSocket, }; -use wasmer_wasi_types_generated::wasi::{Errno, Fdflags, Socktype}; +use wasmer_wasi_types_generated::wasi::{Errno, Fdflags, Sockoption, Socktype}; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; @@ -90,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, } } } diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 61fa6664c30..af16f8ea54d 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -26,7 +26,8 @@ use self::types::{ wasi::{ Advice, BusErrno, Clockid, Dircookie, Dirent, Errno, Event, EventEnum, EventFdReadwrite, Eventrwflags, Eventtype, Fd as WasiFd, Fdflags, Fdstat, Filetype, Rights, Snapshot0Clockid, - Sockstatus, Socktype, Subscription, SubscriptionEnum, SubscriptionFsReadwrite, Timestamp, + Sockoption, Sockstatus, Socktype, Subscription, SubscriptionEnum, SubscriptionFsReadwrite, + Timestamp, }, *, }; @@ -4797,7 +4798,7 @@ pub fn sock_open( pub fn sock_set_opt_flag( ctx: FunctionEnvMut<'_, WasiEnv>, sock: WasiFd, - opt: __wasi_sockoption_t, + opt: Sockoption, flag: __wasi_bool_t, ) -> Errno { debug!("wasi::sock_set_opt_flag(ty={})", opt); @@ -4826,7 +4827,7 @@ pub fn sock_set_opt_flag( pub fn sock_get_opt_flag( ctx: FunctionEnvMut<'_, WasiEnv>, sock: WasiFd, - opt: __wasi_sockoption_t, + opt: Sockoption, ret_flag: WasmPtr<__wasi_bool_t, M>, ) -> Errno { debug!("wasi::sock_get_opt_flag(ty={})", opt); @@ -4858,7 +4859,7 @@ pub fn sock_get_opt_flag( pub fn sock_set_opt_time( ctx: FunctionEnvMut<'_, WasiEnv>, sock: WasiFd, - opt: __wasi_sockoption_t, + opt: Sockoption, time: WasmPtr<__wasi_option_timestamp_t, M>, ) -> Errno { debug!("wasi::sock_set_opt_time(ty={})", opt); @@ -4873,11 +4874,11 @@ pub fn sock_set_opt_time( }; 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, + 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, }; @@ -4898,7 +4899,7 @@ pub fn sock_set_opt_time( pub fn sock_get_opt_time( ctx: FunctionEnvMut<'_, WasiEnv>, sock: WasiFd, - opt: __wasi_sockoption_t, + opt: Sockoption, ret_time: WasmPtr<__wasi_option_timestamp_t, M>, ) -> Errno { debug!("wasi::sock_get_opt_time(ty={})", opt); @@ -4906,11 +4907,11 @@ pub fn sock_get_opt_time( 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, + 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, }; @@ -4945,27 +4946,27 @@ pub fn sock_get_opt_time( pub fn sock_set_opt_size( ctx: FunctionEnvMut<'_, WasiEnv>, sock: WasiFd, - opt: __wasi_sockoption_t, + opt: Sockoption, size: __wasi_filesize_t, ) -> 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, + 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, 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), + 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), } })); @@ -4983,7 +4984,7 @@ pub fn sock_set_opt_size( pub fn sock_get_opt_size( ctx: FunctionEnvMut<'_, WasiEnv>, sock: WasiFd, - opt: __wasi_sockoption_t, + opt: Sockoption, ret_size: WasmPtr<__wasi_filesize_t, M>, ) -> Errno { debug!("wasi::sock_get_opt_size(ty={})", opt); @@ -4992,16 +4993,10 @@ pub fn sock_get_opt_size( 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) - } + Sockoption::RecvBufSize => socket.recv_buf_size().map(|a| a as __wasi_filesize_t), + Sockoption::SendBufSize => socket.send_buf_size().map(|a| a as __wasi_filesize_t), + Sockoption::Ttl => socket.ttl().map(|a| a as __wasi_filesize_t), + Sockoption::MulticastTtlV4 => socket.multicast_ttl_v4().map(|a| a as __wasi_filesize_t), _ => Err(Errno::Inval), } })); diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index 6fd5c1e71cd..ab58a6d5616 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -3,8 +3,8 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{FunctionEnvMut, Memory, Memory32, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ - Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Sockstatus, - Socktype, Subscription, Timestamp, + Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Sockoption, + Sockstatus, Socktype, Subscription, Timestamp, }; type MemoryType = Memory32; @@ -830,7 +830,7 @@ pub(crate) fn sock_open( pub(crate) fn sock_set_opt_flag( ctx: FunctionEnvMut, sock: Fd, - opt: __wasi_sockoption_t, + opt: Sockoption, flag: __wasi_bool_t, ) -> Errno { super::sock_set_opt_flag(ctx, sock, opt, flag) @@ -839,7 +839,7 @@ pub(crate) fn sock_set_opt_flag( pub(crate) fn sock_get_opt_flag( ctx: FunctionEnvMut, sock: Fd, - opt: __wasi_sockoption_t, + opt: Sockoption, ret_flag: WasmPtr<__wasi_bool_t, MemoryType>, ) -> Errno { super::sock_get_opt_flag::(ctx, sock, opt, ret_flag) @@ -848,7 +848,7 @@ pub(crate) fn sock_get_opt_flag( pub fn sock_set_opt_time( ctx: FunctionEnvMut, sock: Fd, - opt: __wasi_sockoption_t, + opt: Sockoption, time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, ) -> Errno { super::sock_set_opt_time(ctx, sock, opt, time) @@ -857,7 +857,7 @@ pub fn sock_set_opt_time( pub fn sock_get_opt_time( ctx: FunctionEnvMut, sock: Fd, - opt: __wasi_sockoption_t, + opt: Sockoption, ret_time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, ) -> Errno { super::sock_get_opt_time(ctx, sock, opt, ret_time) @@ -866,7 +866,7 @@ pub fn sock_get_opt_time( pub fn sock_set_opt_size( ctx: FunctionEnvMut, sock: Fd, - opt: __wasi_sockoption_t, + opt: Sockoption, size: __wasi_filesize_t, ) -> Errno { super::sock_set_opt_size(ctx, sock, opt, size) @@ -875,7 +875,7 @@ pub fn sock_set_opt_size( pub fn sock_get_opt_size( ctx: FunctionEnvMut, sock: Fd, - opt: __wasi_sockoption_t, + opt: Sockoption, ret_size: WasmPtr<__wasi_filesize_t, MemoryType>, ) -> Errno { super::sock_get_opt_size(ctx, sock, opt, ret_size) diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index 6e5cc33a175..76badf38b9d 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -3,8 +3,8 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{FunctionEnvMut, Memory, Memory64, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ - Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Sockstatus, - Socktype, Subscription, Timestamp, + Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Sockoption, + Sockstatus, Socktype, Subscription, Timestamp, }; type MemoryType = Memory64; @@ -830,7 +830,7 @@ pub(crate) fn sock_open( pub(crate) fn sock_set_opt_flag( ctx: FunctionEnvMut, sock: Fd, - opt: __wasi_sockoption_t, + opt: Sockoption, flag: __wasi_bool_t, ) -> Errno { super::sock_set_opt_flag(ctx, sock, opt, flag) @@ -839,7 +839,7 @@ pub(crate) fn sock_set_opt_flag( pub(crate) fn sock_get_opt_flag( ctx: FunctionEnvMut, sock: Fd, - opt: __wasi_sockoption_t, + opt: Sockoption, ret_flag: WasmPtr<__wasi_bool_t, MemoryType>, ) -> Errno { super::sock_get_opt_flag::(ctx, sock, opt, ret_flag) @@ -848,7 +848,7 @@ pub(crate) fn sock_get_opt_flag( pub fn sock_set_opt_time( ctx: FunctionEnvMut, sock: Fd, - opt: __wasi_sockoption_t, + opt: Sockoption, time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, ) -> Errno { super::sock_set_opt_time(ctx, sock, opt, time) @@ -857,7 +857,7 @@ pub fn sock_set_opt_time( pub fn sock_get_opt_time( ctx: FunctionEnvMut, sock: Fd, - opt: __wasi_sockoption_t, + opt: Sockoption, ret_time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, ) -> Errno { super::sock_get_opt_time(ctx, sock, opt, ret_time) @@ -866,7 +866,7 @@ pub fn sock_get_opt_time( pub fn sock_set_opt_size( ctx: FunctionEnvMut, sock: Fd, - opt: __wasi_sockoption_t, + opt: Sockoption, size: __wasi_filesize_t, ) -> Errno { super::sock_set_opt_size(ctx, sock, opt, size) @@ -875,7 +875,7 @@ pub fn sock_set_opt_size( pub fn sock_get_opt_size( ctx: FunctionEnvMut, sock: Fd, - opt: __wasi_sockoption_t, + opt: Sockoption, ret_size: WasmPtr<__wasi_filesize_t, MemoryType>, ) -> Errno { super::sock_get_opt_size(ctx, sock, opt, ret_size) From 4bb761f09b6106e6caa033680041fe1b1adabc07 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Wed, 24 Aug 2022 20:10:45 +0200 Subject: [PATCH 27/84] Streamsecurity --- lib/wasi-types-generated/src/wasi/bindings.rs | 26 ++++++++++++++++ lib/wasi-types-generated/src/wasi/mod.rs | 31 +++++++++++++++++++ lib/wasi-types-generated/wit/wasi.wit | 7 +++++ lib/wasi-types/src/net.rs | 6 ---- lib/wasi/src/syscalls/mod.rs | 14 ++++----- lib/wasi/src/syscalls/wasix32.rs | 4 +-- lib/wasi/src/syscalls/wasix64.rs | 4 +-- 7 files changed, 75 insertions(+), 17 deletions(-) diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index 1b064a4db1c..8726e97a3dc 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -1290,6 +1290,32 @@ pub mod wasi { } } } + #[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() + } + } + } + } /// Auxiliary data associated with the wasm exports. #[derive(Default)] diff --git a/lib/wasi-types-generated/src/wasi/mod.rs b/lib/wasi-types-generated/src/wasi/mod.rs index f80714f6936..d704c81ebc6 100644 --- a/lib/wasi-types-generated/src/wasi/mod.rs +++ b/lib/wasi-types-generated/src/wasi/mod.rs @@ -40,6 +40,12 @@ unsafe impl ValueType for Sockoption { fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Streamsecurity { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + impl Filetype { pub fn name(self) -> &'static str { match self { @@ -767,6 +773,31 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Sockstatus { } } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + // TODO: if necessary, must be implemented in wit-bindgen unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Rights { type Native = i64; diff --git a/lib/wasi-types-generated/wit/wasi.wit b/lib/wasi-types-generated/wit/wasi.wit index 9faac44611e..aa82bf4b86f 100644 --- a/lib/wasi-types-generated/wit/wasi.wit +++ b/lib/wasi-types-generated/wit/wasi.wit @@ -738,3 +738,10 @@ enum sockoption { %type, proto, } + +enum streamsecurity { + unencrypted, + any-encryption, + classic-encryption, + double-encryption, +} diff --git a/lib/wasi-types/src/net.rs b/lib/wasi-types/src/net.rs index c20c848e058..92451878ff6 100644 --- a/lib/wasi-types/src/net.rs +++ b/lib/wasi-types/src/net.rs @@ -4,12 +4,6 @@ use wasmer_wasi_types_generated::wasi::Fd; use crate::__wasi_option_timestamp_t; -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; diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index af16f8ea54d..e33fb8490e2 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -26,8 +26,8 @@ use self::types::{ wasi::{ Advice, BusErrno, Clockid, Dircookie, Dirent, Errno, Event, EventEnum, EventFdReadwrite, Eventrwflags, Eventtype, Fd as WasiFd, Fdflags, Fdstat, Filetype, Rights, Snapshot0Clockid, - Sockoption, Sockstatus, Socktype, Subscription, SubscriptionEnum, SubscriptionFsReadwrite, - Timestamp, + Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, SubscriptionEnum, + SubscriptionFsReadwrite, Timestamp, }, *, }; @@ -4331,7 +4331,7 @@ pub fn port_bridge( network_len: M::Offset, token: WasmPtr, token_len: M::Offset, - security: __wasi_streamsecurity_t, + security: Streamsecurity, ) -> Errno { debug!("wasi::port_bridge"); let env = ctx.data(); @@ -4339,10 +4339,10 @@ pub fn port_bridge( 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, + Streamsecurity::Unencrypted => StreamSecurity::Unencrypted, + Streamsecurity::AnyEncryption => StreamSecurity::AnyEncyption, + Streamsecurity::ClassicEncryption => StreamSecurity::ClassicEncryption, + Streamsecurity::DoubleEncryption => StreamSecurity::DoubleEncryption, _ => return Errno::Inval, }; diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index ab58a6d5616..d19b5b26fa2 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -4,7 +4,7 @@ use wasmer::{FunctionEnvMut, Memory, Memory32, MemorySize, StoreMut, WasmPtr, Wa use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Sockoption, - Sockstatus, Socktype, Subscription, Timestamp, + Sockstatus, Socktype, Streamsecurity, Subscription, Timestamp, }; type MemoryType = Memory32; @@ -666,7 +666,7 @@ pub(crate) fn port_bridge( network_len: MemoryOffset, token: WasmPtr, token_len: MemoryOffset, - security: __wasi_streamsecurity_t, + security: Streamsecurity, ) -> Errno { super::port_bridge::(ctx, network, network_len, token, token_len, security) } diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index 76badf38b9d..4deb60bcf81 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -4,7 +4,7 @@ use wasmer::{FunctionEnvMut, Memory, Memory64, MemorySize, StoreMut, WasmPtr, Wa use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Sockoption, - Sockstatus, Socktype, Subscription, Timestamp, + Sockstatus, Socktype, Streamsecurity, Subscription, Timestamp, }; type MemoryType = Memory64; @@ -666,7 +666,7 @@ pub(crate) fn port_bridge( network_len: MemoryOffset, token: WasmPtr, token_len: MemoryOffset, - security: __wasi_streamsecurity_t, + security: Streamsecurity, ) -> Errno { super::port_bridge::(ctx, network, network_len, token, token_len, security) } From 4abe73c819cecf6785ba670e18006eafc9a34f04 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Wed, 24 Aug 2022 22:36:39 +0200 Subject: [PATCH 28/84] Addressfamily --- lib/wasi-types-generated/src/wasi/bindings.rs | 26 +++++++++ lib/wasi-types-generated/src/wasi/mod.rs | 31 ++++++++++ lib/wasi-types-generated/wit/wasi.wit | 7 +++ lib/wasi-types/src/net.rs | 14 ++--- lib/wasi/src/state/socket.rs | 56 +++++++++---------- lib/wasi/src/syscalls/mod.rs | 10 ++-- lib/wasi/src/syscalls/wasix32.rs | 6 +- lib/wasi/src/syscalls/wasix64.rs | 6 +- 8 files changed, 107 insertions(+), 49 deletions(-) diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index 8726e97a3dc..e77daa164a8 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -1316,6 +1316,32 @@ pub mod wasi { } } } + #[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() + } + } + } + } /// Auxiliary data associated with the wasm exports. #[derive(Default)] diff --git a/lib/wasi-types-generated/src/wasi/mod.rs b/lib/wasi-types-generated/src/wasi/mod.rs index d704c81ebc6..588ca87f274 100644 --- a/lib/wasi-types-generated/src/wasi/mod.rs +++ b/lib/wasi-types-generated/src/wasi/mod.rs @@ -46,6 +46,12 @@ unsafe impl ValueType for Streamsecurity { fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Addressfamily { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + impl Filetype { pub fn name(self) -> &'static str { match self { @@ -1024,6 +1030,31 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Preopentype { } } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + // TODO: if necessary, must be implemented in wit-bindgen unsafe impl ValueType for Snapshot0Clockid { #[inline] diff --git a/lib/wasi-types-generated/wit/wasi.wit b/lib/wasi-types-generated/wit/wasi.wit index aa82bf4b86f..1333144d843 100644 --- a/lib/wasi-types-generated/wit/wasi.wit +++ b/lib/wasi-types-generated/wit/wasi.wit @@ -745,3 +745,10 @@ enum streamsecurity { classic-encryption, double-encryption, } + +enum addressfamily { + unspec, + inet4, + inet6, + unix, +} diff --git a/lib/wasi-types/src/net.rs b/lib/wasi-types/src/net.rs index 92451878ff6..5df39b0fea0 100644 --- a/lib/wasi-types/src/net.rs +++ b/lib/wasi-types/src/net.rs @@ -1,6 +1,6 @@ use super::*; use wasmer_derive::ValueType; -use wasmer_wasi_types_generated::wasi::Fd; +use wasmer_wasi_types_generated::wasi::{Addressfamily, Fd}; use crate::__wasi_option_timestamp_t; @@ -276,12 +276,6 @@ 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 { @@ -371,7 +365,7 @@ pub struct __wasi_addr_u { #[derive(Debug, Copy, Clone, ValueType)] #[repr(C)] pub struct __wasi_addr_t { - pub tag: __wasi_addressfamily_t, + pub tag: Addressfamily, pub u: __wasi_addr_u, } @@ -384,7 +378,7 @@ pub struct __wasi_addr_port_u { #[derive(Debug, Copy, Clone, ValueType)] #[repr(C)] pub struct __wasi_addr_port_t { - pub tag: __wasi_addressfamily_t, + pub tag: Addressfamily, pub u: __wasi_addr_port_u, } @@ -397,7 +391,7 @@ pub struct __wasi_cidr_u { #[derive(Debug, Copy, Clone, ValueType)] #[repr(C)] pub struct __wasi_cidr_t { - pub tag: __wasi_addressfamily_t, + pub tag: Addressfamily, pub u: __wasi_cidr_u, } diff --git a/lib/wasi/src/state/socket.rs b/lib/wasi/src/state/socket.rs index 1d8f6264fd8..c304d6f9c1a 100644 --- a/lib/wasi/src/state/socket.rs +++ b/lib/wasi/src/state/socket.rs @@ -16,7 +16,7 @@ use wasmer_vnet::{ IpCidr, IpRoute, SocketHttpRequest, VirtualIcmpSocket, VirtualNetworking, VirtualRawSocket, VirtualTcpListener, VirtualTcpSocket, VirtualUdpSocket, VirtualWebSocket, }; -use wasmer_wasi_types_generated::wasi::{Errno, Fdflags, Sockoption, Socktype}; +use wasmer_wasi_types_generated::wasi::{Addressfamily, Errno, Fdflags, Sockoption, Socktype}; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; @@ -36,7 +36,7 @@ pub enum InodeHttpSocketType { //#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub enum InodeSocketKind { PreSocket { - family: __wasi_addressfamily_t, + family: Addressfamily, ty: Socktype, pt: __wasi_sockproto_t, addr: Option, @@ -173,12 +173,12 @@ impl InodeSocket { .. } => { match *family { - __WASI_ADDRESS_FAMILY_INET4 => { + Addressfamily::Inet4 => { if !set_addr.is_ipv4() { return Err(Errno::Inval); } } - __WASI_ADDRESS_FAMILY_INET6 => { + Addressfamily::Inet6 => { if !set_addr.is_ipv6() { return Err(Errno::Inval); } @@ -370,8 +370,8 @@ impl InodeSocket { } else { SocketAddr::new( match *family { - __WASI_ADDRESS_FAMILY_INET4 => IpAddr::V4(Ipv4Addr::UNSPECIFIED), - __WASI_ADDRESS_FAMILY_INET6 => IpAddr::V6(Ipv6Addr::UNSPECIFIED), + Addressfamily::Inet4 => IpAddr::V4(Ipv4Addr::UNSPECIFIED), + Addressfamily::Inet6 => IpAddr::V6(Ipv6Addr::UNSPECIFIED), _ => return Err(Errno::Inval), }, 0, @@ -397,8 +397,8 @@ impl InodeSocket { 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), + Addressfamily::Inet4 => IpAddr::V4(Ipv4Addr::UNSPECIFIED), + Addressfamily::Inet6 => IpAddr::V6(Ipv6Addr::UNSPECIFIED), _ => return Err(Errno::Inval), }, 0, @@ -1119,8 +1119,8 @@ pub(crate) fn read_ip( 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)) } @@ -1159,7 +1159,7 @@ pub(crate) fn write_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], }, @@ -1168,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 }, } } @@ -1189,11 +1189,11 @@ pub(crate) fn read_cidr( 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], @@ -1221,7 +1221,7 @@ pub(crate) fn write_cidr( 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, @@ -1232,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], @@ -1257,11 +1257,11 @@ pub(crate) fn read_ip_port( 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], @@ -1290,7 +1290,7 @@ pub(crate) fn write_ip_port( 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, @@ -1301,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], @@ -1329,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], @@ -1352,8 +1352,8 @@ pub(crate) fn read_route( 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)) } @@ -1384,7 +1384,7 @@ pub(crate) fn write_route( 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, @@ -1395,7 +1395,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], @@ -1410,7 +1410,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], }, @@ -1419,7 +1419,7 @@ 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 }, } } diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index e33fb8490e2..e19ce24a828 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -24,10 +24,10 @@ pub mod wasix64; use self::types::{ wasi::{ - Advice, BusErrno, Clockid, Dircookie, Dirent, Errno, Event, EventEnum, EventFdReadwrite, - Eventrwflags, Eventtype, Fd as WasiFd, Fdflags, Fdstat, Filetype, Rights, Snapshot0Clockid, - Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, SubscriptionEnum, - SubscriptionFsReadwrite, Timestamp, + Addressfamily, Advice, BusErrno, Clockid, Dircookie, Dirent, Errno, Event, EventEnum, + EventFdReadwrite, Eventrwflags, Eventtype, Fd as WasiFd, Fdflags, Fdstat, Filetype, Rights, + Snapshot0Clockid, Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, + SubscriptionEnum, SubscriptionFsReadwrite, Timestamp, }, *, }; @@ -4739,7 +4739,7 @@ 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, + af: Addressfamily, ty: Socktype, pt: __wasi_sockproto_t, ro_sock: WasmPtr, diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index d19b5b26fa2..869f57e04fd 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -3,8 +3,8 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{FunctionEnvMut, Memory, Memory32, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ - Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Sockoption, - Sockstatus, Socktype, Streamsecurity, Subscription, Timestamp, + Addressfamily, Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, + Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, Timestamp, }; type MemoryType = Memory32; @@ -819,7 +819,7 @@ pub(crate) fn sock_addr_peer( pub(crate) fn sock_open( ctx: FunctionEnvMut, - af: __wasi_addressfamily_t, + af: Addressfamily, ty: Socktype, pt: __wasi_sockproto_t, ro_sock: WasmPtr, diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index 4deb60bcf81..22beb99c077 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -3,8 +3,8 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{FunctionEnvMut, Memory, Memory64, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ - Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, Sockoption, - Sockstatus, Socktype, Streamsecurity, Subscription, Timestamp, + Addressfamily, Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, + Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, Timestamp, }; type MemoryType = Memory64; @@ -819,7 +819,7 @@ pub(crate) fn sock_addr_peer( pub(crate) fn sock_open( ctx: FunctionEnvMut, - af: __wasi_addressfamily_t, + af: Addressfamily, ty: Socktype, pt: __wasi_sockproto_t, ro_sock: WasmPtr, From 721ece0a949d95472e1d1f3b4cfd9fbbdbd1c393 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Wed, 24 Aug 2022 22:54:44 +0200 Subject: [PATCH 29/84] Filesize --- .../src/link-ext.rs | 7 +- lib/wasi-types/src/file.rs | 6 +- lib/wasi-types/src/net.rs | 4 +- lib/wasi-types/src/versions/snapshot0.rs | 4 +- lib/wasi/src/state/mod.rs | 6 +- lib/wasi/src/syscalls/legacy/snapshot0.rs | 4 +- lib/wasi/src/syscalls/mod.rs | 64 +++++++++---------- lib/wasi/src/syscalls/wasi.rs | 20 +++--- lib/wasi/src/syscalls/wasix32.rs | 32 +++++----- lib/wasi/src/syscalls/wasix64.rs | 32 +++++----- tests/lib/wast/src/wasi_wast.rs | 8 +-- 11 files changed, 93 insertions(+), 94 deletions(-) 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/src/file.rs b/lib/wasi-types/src/file.rs index ccb558e3eda..089b8f0208e 100644 --- a/lib/wasi-types/src/file.rs +++ b/lib/wasi-types/src/file.rs @@ -4,7 +4,7 @@ use std::{ }; use wasmer_derive::ValueType; use wasmer_types::ValueType; -use wasmer_wasi_types_generated::wasi::{Fd, Filetype, Preopentype, Rights, Timestamp}; +use wasmer_wasi_types_generated::wasi::{Fd, Filesize, Filetype, Preopentype, Rights, Timestamp}; pub type __wasi_device_t = u64; @@ -105,8 +105,6 @@ unsafe impl ValueType for __wasi_prestat_t { pub type __wasi_filedelta_t = i64; -pub type __wasi_filesize_t = u64; - #[derive(Copy, Clone, PartialEq, Eq, ValueType)] #[repr(C)] pub struct __wasi_filestat_t { @@ -114,7 +112,7 @@ pub struct __wasi_filestat_t { pub st_ino: __wasi_inode_t, pub st_filetype: Filetype, pub st_nlink: __wasi_linkcount_t, - pub st_size: __wasi_filesize_t, + pub st_size: Filesize, pub st_atim: Timestamp, pub st_mtim: Timestamp, pub st_ctim: Timestamp, diff --git a/lib/wasi-types/src/net.rs b/lib/wasi-types/src/net.rs index 5df39b0fea0..79a11e7d6f0 100644 --- a/lib/wasi-types/src/net.rs +++ b/lib/wasi-types/src/net.rs @@ -1,6 +1,6 @@ use super::*; use wasmer_derive::ValueType; -use wasmer_wasi_types_generated::wasi::{Addressfamily, Fd}; +use wasmer_wasi_types_generated::wasi::{Addressfamily, Fd, Filesize}; use crate::__wasi_option_timestamp_t; @@ -417,7 +417,7 @@ pub struct __wasi_http_handles_t { pub struct __wasi_http_status_t { pub ok: __wasi_bool_t, pub redirect: __wasi_bool_t, - pub size: __wasi_filesize_t, + pub size: Filesize, pub status: u16, } diff --git a/lib/wasi-types/src/versions/snapshot0.rs b/lib/wasi-types/src/versions/snapshot0.rs index e2277286be1..012eb4fa099 100644 --- a/lib/wasi-types/src/versions/snapshot0.rs +++ b/lib/wasi-types/src/versions/snapshot0.rs @@ -1,7 +1,7 @@ use crate::*; use std::fmt; use wasmer_derive::ValueType; -use wasmer_wasi_types_generated::wasi::{Filetype, Timestamp}; +use wasmer_wasi_types_generated::wasi::{Filesize, Filetype, Timestamp}; pub type __wasi_linkcount_t = u32; @@ -17,7 +17,7 @@ pub struct __wasi_filestat_t { pub st_ino: __wasi_inode_t, pub st_filetype: Filetype, pub st_nlink: __wasi_linkcount_t, - pub st_size: __wasi_filesize_t, + pub st_size: Filesize, pub st_atim: Timestamp, pub st_mtim: Timestamp, pub st_ctim: Timestamp, diff --git a/lib/wasi/src/state/mod.rs b/lib/wasi/src/state/mod.rs index bb262c2344a..9cb414d81e1 100644 --- a/lib/wasi/src/state/mod.rs +++ b/lib/wasi/src/state/mod.rs @@ -53,7 +53,7 @@ use std::{ use tracing::{debug, trace}; use wasmer_vbus::BusSpawnedProcess; use wasmer_wasi_types_generated::wasi::{ - Errno, Fd as WasiFd, Fdflags, Fdstat, Filetype, Preopentype, Rights, + Errno, Fd as WasiFd, Fdflags, Fdstat, Filesize, Filetype, Preopentype, Rights, }; use wasmer_vfs::{FileSystem, FsError, OpenOptions, VirtualFile}; @@ -825,7 +825,7 @@ impl WasiFs { &self, inodes: &WasiInodes, fd: WasiFd, - ) -> Result<__wasi_filesize_t, Errno> { + ) -> Result { let inode = self.get_fd_inode(fd)?; let mut guard = inodes.arena[inode].write(); let deref_mut = guard.deref_mut(); @@ -836,7 +836,7 @@ 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(Errno::Badf) } diff --git a/lib/wasi/src/syscalls/legacy/snapshot0.rs b/lib/wasi/src/syscalls/legacy/snapshot0.rs index 9865caeea42..c331404f312 100644 --- a/lib/wasi/src/syscalls/legacy/snapshot0.rs +++ b/lib/wasi/src/syscalls/legacy/snapshot0.rs @@ -3,7 +3,7 @@ use crate::syscalls::types::{self, snapshot0}; use crate::{mem_error_to_wasi, Memory32, MemorySize, WasiEnv, WasiError, WasiThread}; use wasmer::{AsStoreMut, FunctionEnvMut, WasmPtr}; use wasmer_wasi_types_generated::wasi::{ - Errno, Event, Fd, Filetype, Snapshot0Subscription, Subscription, + Errno, Event, Fd, Filesize, Filetype, Snapshot0Subscription, Subscription, }; /// Wrapper around `syscalls::fd_filestat_get` with extra logic to handle the size @@ -112,7 +112,7 @@ pub fn fd_seek( fd: Fd, offset: types::__wasi_filedelta_t, whence: snapshot0::__wasi_whence_t, - newoffset: WasmPtr, + newoffset: WasmPtr, ) -> Result { let new_whence = match whence { snapshot0::__WASI_WHENCE_CUR => types::__WASI_WHENCE_CUR, diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index e19ce24a828..e1a7072fa1c 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -25,9 +25,9 @@ pub mod wasix64; use self::types::{ wasi::{ Addressfamily, Advice, BusErrno, Clockid, Dircookie, Dirent, Errno, Event, EventEnum, - EventFdReadwrite, Eventrwflags, Eventtype, Fd as WasiFd, Fdflags, Fdstat, Filetype, Rights, - Snapshot0Clockid, Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, - SubscriptionEnum, SubscriptionFsReadwrite, Timestamp, + EventFdReadwrite, Eventrwflags, Eventtype, Fd as WasiFd, Fdflags, Fdstat, Filesize, + Filetype, Rights, Snapshot0Clockid, Sockoption, Sockstatus, Socktype, Streamsecurity, + Subscription, SubscriptionEnum, SubscriptionFsReadwrite, Timestamp, }, *, }; @@ -484,17 +484,17 @@ pub fn environ_sizes_get( /// Inputs: /// - `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: WasiFd, - offset: __wasi_filesize_t, - len: __wasi_filesize_t, + offset: Filesize, + len: Filesize, advice: Advice, ) -> Errno { debug!("wasi::fd_advise: fd={}", fd); @@ -509,15 +509,15 @@ pub fn fd_advise( /// Inputs: /// - `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: WasiFd, - offset: __wasi_filesize_t, - len: __wasi_filesize_t, + offset: Filesize, + len: Filesize, ) -> Errno { debug!("wasi::fd_allocate"); let env = ctx.data(); @@ -718,12 +718,12 @@ pub fn fd_filestat_get( /// Inputs: /// - `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: WasiFd, - st_size: __wasi_filesize_t, + st_size: Filesize, ) -> Errno { debug!("wasi::fd_filestat_set_size"); let env = ctx.data(); @@ -827,7 +827,7 @@ pub fn fd_filestat_set_times( /// 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` @@ -837,7 +837,7 @@ pub fn fd_pread( fd: WasiFd, iovs: WasmPtr<__wasi_iovec_t, M>, iovs_len: M::Offset, - offset: __wasi_filesize_t, + offset: Filesize, nread: WasmPtr, ) -> Result { trace!("wasi::fd_pread: fd={}, offset={}", fd, offset); @@ -999,7 +999,7 @@ pub fn fd_prestat_dir_name( /// 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` @@ -1009,7 +1009,7 @@ pub fn fd_pwrite( fd: WasiFd, iovs: WasmPtr<__wasi_ciovec_t, M>, iovs_len: M::Offset, - offset: __wasi_filesize_t, + offset: Filesize, nwritten: WasmPtr, ) -> Result { trace!("wasi::fd_pwrite"); @@ -1495,14 +1495,14 @@ pub fn fd_event( /// - `__wasi_whence_t 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: WasiFd, offset: __wasi_filedelta_t, whence: __wasi_whence_t, - newoffset: WasmPtr<__wasi_filesize_t, M>, + newoffset: WasmPtr, ) -> Result { trace!("wasi::fd_seek: fd={}, offset={}", fd, offset); let env = ctx.data(); @@ -1623,12 +1623,12 @@ pub fn fd_sync(ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd) -> Errno { /// - `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: WasiFd, - offset: WasmPtr<__wasi_filesize_t, M>, + offset: WasmPtr, ) -> Errno { debug!("wasi::fd_tell"); let env = ctx.data(); @@ -4947,7 +4947,7 @@ pub fn sock_set_opt_size( ctx: FunctionEnvMut<'_, WasiEnv>, sock: WasiFd, opt: Sockoption, - size: __wasi_filesize_t, + size: Filesize, ) -> Errno { debug!("wasi::sock_set_opt_size(ty={})", opt); @@ -4985,7 +4985,7 @@ pub fn sock_get_opt_size( ctx: FunctionEnvMut<'_, WasiEnv>, sock: WasiFd, opt: Sockoption, - ret_size: WasmPtr<__wasi_filesize_t, M>, + ret_size: WasmPtr, ) -> Errno { debug!("wasi::sock_get_opt_size(ty={})", opt); let env = ctx.data(); @@ -4993,10 +4993,10 @@ pub fn sock_get_opt_size( let size = wasi_try!(__sock_actor(&ctx, sock, Rights::empty(), |socket| { match opt { - Sockoption::RecvBufSize => socket.recv_buf_size().map(|a| a as __wasi_filesize_t), - Sockoption::SendBufSize => socket.send_buf_size().map(|a| a as __wasi_filesize_t), - Sockoption::Ttl => socket.ttl().map(|a| a as __wasi_filesize_t), - Sockoption::MulticastTtlV4 => socket.multicast_ttl_v4().map(|a| a as __wasi_filesize_t), + 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), } })); @@ -5444,9 +5444,9 @@ pub unsafe fn sock_send_file( mut ctx: FunctionEnvMut<'_, WasiEnv>, sock: WasiFd, in_fd: WasiFd, - offset: __wasi_filesize_t, - mut count: __wasi_filesize_t, - ret_sent: WasmPtr<__wasi_filesize_t, M>, + offset: Filesize, + mut count: Filesize, + ret_sent: WasmPtr, ) -> Result { debug!("wasi::send_file"); let env = ctx.data(); @@ -5460,7 +5460,7 @@ pub unsafe fn sock_send_file( } // 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); @@ -5547,7 +5547,7 @@ pub unsafe fn sock_send_file( 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(Errno::Success) } diff --git a/lib/wasi/src/syscalls/wasi.rs b/lib/wasi/src/syscalls/wasi.rs index ab24ff0b8fa..24fa9ea7c58 100644 --- a/lib/wasi/src/syscalls/wasi.rs +++ b/lib/wasi/src/syscalls/wasi.rs @@ -2,7 +2,7 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{Memory, Memory32, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::{ - wasi::{Errno, Event, Fd as WasiFd, Timestamp}, + wasi::{Errno, Event, Fd as WasiFd, Filesize, Timestamp}, *, }; @@ -61,8 +61,8 @@ pub(crate) fn environ_sizes_get( pub(crate) fn fd_advise( ctx: FunctionEnvMut, fd: WasiFd, - offset: __wasi_filesize_t, - len: __wasi_filesize_t, + offset: Filesize, + len: Filesize, advice: __wasi_advice_t, ) -> Errno { super::fd_advise(ctx, fd, offset, len, advice) @@ -71,8 +71,8 @@ pub(crate) fn fd_advise( pub(crate) fn fd_allocate( ctx: FunctionEnvMut, fd: WasiFd, - offset: __wasi_filesize_t, - len: __wasi_filesize_t, + offset: Filesize, + len: Filesize, ) -> Errno { super::fd_allocate(ctx, fd, offset, len) } @@ -121,7 +121,7 @@ pub(crate) fn fd_filestat_get( pub(crate) fn fd_filestat_set_size( ctx: FunctionEnvMut, fd: WasiFd, - st_size: __wasi_filesize_t, + st_size: Filesize, ) -> Errno { super::fd_filestat_set_size(ctx, fd, st_size) } @@ -141,7 +141,7 @@ pub(crate) fn fd_pread( fd: WasiFd, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, - offset: __wasi_filesize_t, + offset: Filesize, nread: WasmPtr, ) -> Result { super::fd_pread::(ctx, fd, iovs, iovs_len, offset, nread) @@ -169,7 +169,7 @@ pub(crate) fn fd_pwrite( fd: WasiFd, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, - offset: __wasi_filesize_t, + offset: Filesize, nwritten: WasmPtr, ) -> Result { super::fd_pwrite::(ctx, fd, iovs, iovs_len, offset, nwritten) @@ -205,7 +205,7 @@ pub(crate) fn fd_seek( fd: WasiFd, offset: __wasi_filedelta_t, whence: __wasi_whence_t, - newoffset: WasmPtr<__wasi_filesize_t, MemoryType>, + newoffset: WasmPtr, ) -> Result { super::fd_seek::(ctx, fd, offset, whence, newoffset) } @@ -217,7 +217,7 @@ pub(crate) fn fd_sync(ctx: FunctionEnvMut, fd: WasiFd) -> Errno { pub(crate) fn fd_tell( ctx: FunctionEnvMut, fd: WasiFd, - offset: WasmPtr<__wasi_filesize_t, MemoryType>, + offset: WasmPtr, ) -> Errno { super::fd_tell::(ctx, fd, offset) } diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index 869f57e04fd..46d342fe65d 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -3,8 +3,8 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{FunctionEnvMut, Memory, Memory32, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ - Addressfamily, Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, - Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, Timestamp, + Addressfamily, Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, + Filesize, Rights, Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, Timestamp, }; type MemoryType = Memory32; @@ -62,8 +62,8 @@ pub(crate) fn environ_sizes_get( pub(crate) fn fd_advise( ctx: FunctionEnvMut, fd: Fd, - offset: __wasi_filesize_t, - len: __wasi_filesize_t, + offset: Filesize, + len: Filesize, advice: Advice, ) -> Errno { super::fd_advise(ctx, fd, offset, len, advice) @@ -72,8 +72,8 @@ pub(crate) fn fd_advise( pub(crate) fn fd_allocate( ctx: FunctionEnvMut, fd: Fd, - offset: __wasi_filesize_t, - len: __wasi_filesize_t, + offset: Filesize, + len: Filesize, ) -> Errno { super::fd_allocate(ctx, fd, offset, len) } @@ -118,7 +118,7 @@ pub(crate) fn fd_filestat_get( pub(crate) fn fd_filestat_set_size( ctx: FunctionEnvMut, fd: Fd, - st_size: __wasi_filesize_t, + st_size: Filesize, ) -> Errno { super::fd_filestat_set_size(ctx, fd, st_size) } @@ -138,7 +138,7 @@ pub(crate) fn fd_pread( fd: Fd, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, - offset: __wasi_filesize_t, + offset: Filesize, nread: WasmPtr, ) -> Result { super::fd_pread::(ctx, fd, iovs, iovs_len, offset, nread) @@ -166,7 +166,7 @@ pub(crate) fn fd_pwrite( fd: Fd, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, - offset: __wasi_filesize_t, + offset: Filesize, nwritten: WasmPtr, ) -> Result { super::fd_pwrite::(ctx, fd, iovs, iovs_len, offset, nwritten) @@ -202,7 +202,7 @@ pub(crate) fn fd_seek( fd: Fd, offset: __wasi_filedelta_t, whence: __wasi_whence_t, - newoffset: WasmPtr<__wasi_filesize_t, MemoryType>, + newoffset: WasmPtr, ) -> Result { super::fd_seek::(ctx, fd, offset, whence, newoffset) } @@ -214,7 +214,7 @@ pub(crate) fn fd_sync(ctx: FunctionEnvMut, fd: Fd) -> Errno { pub(crate) fn fd_tell( ctx: FunctionEnvMut, fd: Fd, - offset: WasmPtr<__wasi_filesize_t, MemoryType>, + offset: WasmPtr, ) -> Errno { super::fd_tell::(ctx, fd, offset) } @@ -867,7 +867,7 @@ pub fn sock_set_opt_size( ctx: FunctionEnvMut, sock: Fd, opt: Sockoption, - size: __wasi_filesize_t, + size: Filesize, ) -> Errno { super::sock_set_opt_size(ctx, sock, opt, size) } @@ -876,7 +876,7 @@ pub fn sock_get_opt_size( ctx: FunctionEnvMut, sock: Fd, opt: Sockoption, - ret_size: WasmPtr<__wasi_filesize_t, MemoryType>, + ret_size: WasmPtr, ) -> Errno { super::sock_get_opt_size(ctx, sock, opt, ret_size) } @@ -1024,9 +1024,9 @@ pub(crate) fn sock_send_file( ctx: FunctionEnvMut, out_fd: Fd, in_fd: Fd, - offset: __wasi_filesize_t, - count: __wasi_filesize_t, - ret_sent: WasmPtr<__wasi_filesize_t, MemoryType>, + offset: Filesize, + count: Filesize, + ret_sent: WasmPtr, ) -> Result { unsafe { super::sock_send_file::(ctx, out_fd, in_fd, offset, count, ret_sent) } } diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index 22beb99c077..2d98cdd4b42 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -3,8 +3,8 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{FunctionEnvMut, Memory, Memory64, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ - Addressfamily, Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Rights, - Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, Timestamp, + Addressfamily, Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, + Filesize, Rights, Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, Timestamp, }; type MemoryType = Memory64; @@ -62,8 +62,8 @@ pub(crate) fn environ_sizes_get( pub(crate) fn fd_advise( ctx: FunctionEnvMut, fd: Fd, - offset: __wasi_filesize_t, - len: __wasi_filesize_t, + offset: Filesize, + len: Filesize, advice: Advice, ) -> Errno { super::fd_advise(ctx, fd, offset, len, advice) @@ -72,8 +72,8 @@ pub(crate) fn fd_advise( pub(crate) fn fd_allocate( ctx: FunctionEnvMut, fd: Fd, - offset: __wasi_filesize_t, - len: __wasi_filesize_t, + offset: Filesize, + len: Filesize, ) -> Errno { super::fd_allocate(ctx, fd, offset, len) } @@ -118,7 +118,7 @@ pub(crate) fn fd_filestat_get( pub(crate) fn fd_filestat_set_size( ctx: FunctionEnvMut, fd: Fd, - st_size: __wasi_filesize_t, + st_size: Filesize, ) -> Errno { super::fd_filestat_set_size(ctx, fd, st_size) } @@ -138,7 +138,7 @@ pub(crate) fn fd_pread( fd: Fd, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, - offset: __wasi_filesize_t, + offset: Filesize, nread: WasmPtr, ) -> Result { super::fd_pread::(ctx, fd, iovs, iovs_len, offset, nread) @@ -166,7 +166,7 @@ pub(crate) fn fd_pwrite( fd: Fd, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, - offset: __wasi_filesize_t, + offset: Filesize, nwritten: WasmPtr, ) -> Result { super::fd_pwrite::(ctx, fd, iovs, iovs_len, offset, nwritten) @@ -202,7 +202,7 @@ pub(crate) fn fd_seek( fd: Fd, offset: __wasi_filedelta_t, whence: __wasi_whence_t, - newoffset: WasmPtr<__wasi_filesize_t, MemoryType>, + newoffset: WasmPtr, ) -> Result { super::fd_seek::(ctx, fd, offset, whence, newoffset) } @@ -214,7 +214,7 @@ pub(crate) fn fd_sync(ctx: FunctionEnvMut, fd: Fd) -> Errno { pub(crate) fn fd_tell( ctx: FunctionEnvMut, fd: Fd, - offset: WasmPtr<__wasi_filesize_t, MemoryType>, + offset: WasmPtr, ) -> Errno { super::fd_tell::(ctx, fd, offset) } @@ -867,7 +867,7 @@ pub fn sock_set_opt_size( ctx: FunctionEnvMut, sock: Fd, opt: Sockoption, - size: __wasi_filesize_t, + size: Filesize, ) -> Errno { super::sock_set_opt_size(ctx, sock, opt, size) } @@ -876,7 +876,7 @@ pub fn sock_get_opt_size( ctx: FunctionEnvMut, sock: Fd, opt: Sockoption, - ret_size: WasmPtr<__wasi_filesize_t, MemoryType>, + ret_size: WasmPtr, ) -> Errno { super::sock_get_opt_size(ctx, sock, opt, ret_size) } @@ -1024,9 +1024,9 @@ pub(crate) fn sock_send_file( ctx: FunctionEnvMut, out_fd: Fd, in_fd: Fd, - offset: __wasi_filesize_t, - count: __wasi_filesize_t, - ret_sent: WasmPtr<__wasi_filesize_t, MemoryType>, + offset: Filesize, + count: Filesize, + ret_sent: WasmPtr, ) -> Result { unsafe { super::sock_send_file::(ctx, out_fd, in_fd, offset, count, ret_sent) } } diff --git a/tests/lib/wast/src/wasi_wast.rs b/tests/lib/wast/src/wasi_wast.rs index f8e1f16631f..e31993deb0f 100644 --- a/tests/lib/wast/src/wasi_wast.rs +++ b/tests/lib/wast/src/wasi_wast.rs @@ -3,11 +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; -use wasmer_wasi::types::wasi::Timestamp; +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, @@ -627,7 +625,7 @@ impl VirtualFile for OutputCapturerer { 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> { From fdb78509662b282f23aed41d852be723901ba505 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Wed, 24 Aug 2022 22:57:32 +0200 Subject: [PATCH 30/84] Inode --- lib/wasi-types/src/file.rs | 8 ++++---- lib/wasi-types/src/versions/snapshot0.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/wasi-types/src/file.rs b/lib/wasi-types/src/file.rs index 089b8f0208e..8d03c9fe433 100644 --- a/lib/wasi-types/src/file.rs +++ b/lib/wasi-types/src/file.rs @@ -4,7 +4,9 @@ use std::{ }; use wasmer_derive::ValueType; use wasmer_types::ValueType; -use wasmer_wasi_types_generated::wasi::{Fd, Filesize, Filetype, Preopentype, Rights, Timestamp}; +use wasmer_wasi_types_generated::wasi::{ + Fd, Filesize, Filetype, Inode, Preopentype, Rights, Timestamp, +}; pub type __wasi_device_t = u64; @@ -109,7 +111,7 @@ pub type __wasi_filedelta_t = i64; #[repr(C)] pub struct __wasi_filestat_t { pub st_dev: __wasi_device_t, - pub st_ino: __wasi_inode_t, + pub st_ino: Inode, pub st_filetype: Filetype, pub st_nlink: __wasi_linkcount_t, pub st_size: Filesize, @@ -170,8 +172,6 @@ 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; diff --git a/lib/wasi-types/src/versions/snapshot0.rs b/lib/wasi-types/src/versions/snapshot0.rs index 012eb4fa099..79dbe3f6f89 100644 --- a/lib/wasi-types/src/versions/snapshot0.rs +++ b/lib/wasi-types/src/versions/snapshot0.rs @@ -1,7 +1,7 @@ use crate::*; use std::fmt; use wasmer_derive::ValueType; -use wasmer_wasi_types_generated::wasi::{Filesize, Filetype, Timestamp}; +use wasmer_wasi_types_generated::wasi::{Filesize, Filetype, Inode, Timestamp}; pub type __wasi_linkcount_t = u32; @@ -14,7 +14,7 @@ pub const __WASI_WHENCE_SET: u8 = 2; #[repr(C)] pub struct __wasi_filestat_t { pub st_dev: __wasi_device_t, - pub st_ino: __wasi_inode_t, + pub st_ino: Inode, pub st_filetype: Filetype, pub st_nlink: __wasi_linkcount_t, pub st_size: Filesize, From ef8021acac536c1c6ac77594962b317f5cb15cfb Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Wed, 24 Aug 2022 23:09:40 +0200 Subject: [PATCH 31/84] Device --- lib/wasi-types-generated/src/wasi/bindings.rs | 9 +++++++-- lib/wasi-types-generated/wit/wasi.wit | 1 + lib/wasi-types/src/file.rs | 6 ++---- lib/wasi-types/src/versions/snapshot0.rs | 5 ++--- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index e77daa164a8..9f0589df5cb 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -14,6 +14,9 @@ pub mod wasi { 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; /// Identifiers for clocks, snapshot0 version. #[repr(u8)] #[derive(Clone, Copy, PartialEq, Eq)] @@ -1416,10 +1419,10 @@ pub mod wasi { }) } /// Dummy function to expose types into generated code - pub fn expose_types_dummy_func(&self, store: &mut wasmer::Store,fd: Fd,dirent: Dirent,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,)-> Result<(), wasmer::RuntimeError> { + pub fn expose_types_dummy_func(&self, store: &mut wasmer::Store,fd: Fd,dirent: Dirent,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,)-> Result<(), wasmer::RuntimeError> { let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; let _memory = &self.memory; - let ptr0 = func_canonical_abi_realloc.call(store, 0, 0, 8, 296)?; + let ptr0 = func_canonical_abi_realloc.call(store, 0, 0, 8, 304)?; let _memory_view = _memory.view(&store); unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 0, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(fd)))?; let Dirent{ d_next:d_next1, d_ino:d_ino1, d_type:d_type1, d_namlen:d_namlen1, } = dirent; @@ -1602,6 +1605,8 @@ pub mod wasi { unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 256, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(file_descriptor28)))?; }, }; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 296, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(device)))?; self.func_expose_types_dummy_func.call(store, ptr0, )?; Ok(()) } diff --git a/lib/wasi-types-generated/wit/wasi.wit b/lib/wasi-types-generated/wit/wasi.wit index 1333144d843..b006604486b 100644 --- a/lib/wasi-types-generated/wit/wasi.wit +++ b/lib/wasi-types-generated/wit/wasi.wit @@ -15,6 +15,7 @@ expose-types-dummy-func: func( snapshot0-subscription-clock: snapshot0-subscription-clock, subscription: subscription, snapshot0-subscription: snapshot0-subscription, + device: device, ) diff --git a/lib/wasi-types/src/file.rs b/lib/wasi-types/src/file.rs index 8d03c9fe433..f11249930bf 100644 --- a/lib/wasi-types/src/file.rs +++ b/lib/wasi-types/src/file.rs @@ -5,11 +5,9 @@ use std::{ use wasmer_derive::ValueType; use wasmer_types::ValueType; use wasmer_wasi_types_generated::wasi::{ - Fd, Filesize, Filetype, Inode, Preopentype, Rights, Timestamp, + Device, Fd, Filesize, Filetype, Inode, Preopentype, Rights, Timestamp, }; -pub type __wasi_device_t = u64; - pub const __WASI_STDIN_FILENO: Fd = 0; pub const __WASI_STDOUT_FILENO: Fd = 1; pub const __WASI_STDERR_FILENO: Fd = 2; @@ -110,7 +108,7 @@ pub type __wasi_filedelta_t = i64; #[derive(Copy, Clone, PartialEq, Eq, ValueType)] #[repr(C)] pub struct __wasi_filestat_t { - pub st_dev: __wasi_device_t, + pub st_dev: Device, pub st_ino: Inode, pub st_filetype: Filetype, pub st_nlink: __wasi_linkcount_t, diff --git a/lib/wasi-types/src/versions/snapshot0.rs b/lib/wasi-types/src/versions/snapshot0.rs index 79dbe3f6f89..2c65d32c9cd 100644 --- a/lib/wasi-types/src/versions/snapshot0.rs +++ b/lib/wasi-types/src/versions/snapshot0.rs @@ -1,7 +1,6 @@ -use crate::*; use std::fmt; use wasmer_derive::ValueType; -use wasmer_wasi_types_generated::wasi::{Filesize, Filetype, Inode, Timestamp}; +use wasmer_wasi_types_generated::wasi::{Device, Filesize, Filetype, Inode, Timestamp}; pub type __wasi_linkcount_t = u32; @@ -13,7 +12,7 @@ pub const __WASI_WHENCE_SET: u8 = 2; #[derive(Copy, Clone, PartialEq, Eq, ValueType)] #[repr(C)] pub struct __wasi_filestat_t { - pub st_dev: __wasi_device_t, + pub st_dev: Device, pub st_ino: Inode, pub st_filetype: Filetype, pub st_nlink: __wasi_linkcount_t, From 14f1f4291f58b21971b57369c802ec22dc3cf522 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Wed, 24 Aug 2022 23:30:45 +0200 Subject: [PATCH 32/84] Linkcount --- lib/wasi-types-generated/src/wasi/bindings.rs | 10 ++++++++-- lib/wasi-types-generated/wit/wasi.wit | 5 +++++ lib/wasi-types/src/file.rs | 6 ++---- lib/wasi-types/src/versions/snapshot0.rs | 8 ++++---- lib/wasi/src/syscalls/mod.rs | 7 +++---- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index 9f0589df5cb..e8b27b10e77 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -17,6 +17,8 @@ pub mod wasi { /// 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; /// Identifiers for clocks, snapshot0 version. #[repr(u8)] #[derive(Clone, Copy, PartialEq, Eq)] @@ -1419,10 +1421,10 @@ pub mod wasi { }) } /// Dummy function to expose types into generated code - pub fn expose_types_dummy_func(&self, store: &mut wasmer::Store,fd: Fd,dirent: Dirent,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,)-> Result<(), wasmer::RuntimeError> { + pub fn expose_types_dummy_func(&self, store: &mut wasmer::Store,fd: Fd,dirent: Dirent,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,)-> Result<(), wasmer::RuntimeError> { let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; let _memory = &self.memory; - let ptr0 = func_canonical_abi_realloc.call(store, 0, 0, 8, 304)?; + let ptr0 = func_canonical_abi_realloc.call(store, 0, 0, 8, 320)?; let _memory_view = _memory.view(&store); unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 0, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(fd)))?; let Dirent{ d_next:d_next1, d_ino:d_ino1, d_type:d_type1, d_namlen:d_namlen1, } = dirent; @@ -1607,6 +1609,10 @@ pub mod wasi { }; let _memory_view = _memory.view(&store); unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 296, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(device)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 304, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(linkcount)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 312, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(snapshot0_linkcount)))?; self.func_expose_types_dummy_func.call(store, ptr0, )?; Ok(()) } diff --git a/lib/wasi-types-generated/wit/wasi.wit b/lib/wasi-types-generated/wit/wasi.wit index b006604486b..2d65283b10a 100644 --- a/lib/wasi-types-generated/wit/wasi.wit +++ b/lib/wasi-types-generated/wit/wasi.wit @@ -16,6 +16,8 @@ expose-types-dummy-func: func( subscription: subscription, snapshot0-subscription: snapshot0-subscription, device: device, + linkcount: linkcount, + snapshot0-linkcount: snapshot0-linkcount, ) @@ -55,6 +57,9 @@ type inode = u64 /// with `inode` to uniquely identify a file or directory in the filesystem. type device = u64 +type linkcount = u64 +type snapshot0-linkcount = u32 + /// Identifiers for clocks, snapshot0 version. enum snapshot0-clockid { // TODO: wit appears to not have support for enum type size diff --git a/lib/wasi-types/src/file.rs b/lib/wasi-types/src/file.rs index f11249930bf..82531d8b1e3 100644 --- a/lib/wasi-types/src/file.rs +++ b/lib/wasi-types/src/file.rs @@ -5,7 +5,7 @@ use std::{ use wasmer_derive::ValueType; use wasmer_types::ValueType; use wasmer_wasi_types_generated::wasi::{ - Device, Fd, Filesize, Filetype, Inode, Preopentype, Rights, Timestamp, + Device, Fd, Filesize, Filetype, Inode, Linkcount, Preopentype, Rights, Timestamp, }; pub const __WASI_STDIN_FILENO: Fd = 0; @@ -111,7 +111,7 @@ pub struct __wasi_filestat_t { pub st_dev: Device, pub st_ino: Inode, pub st_filetype: Filetype, - pub st_nlink: __wasi_linkcount_t, + pub st_nlink: Linkcount, pub st_size: Filesize, pub st_atim: Timestamp, pub st_mtim: Timestamp, @@ -170,8 +170,6 @@ 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_linkcount_t = u64; - pub type __wasi_lookupflags_t = u32; pub const __WASI_LOOKUP_SYMLINK_FOLLOW: __wasi_lookupflags_t = 1 << 0; diff --git a/lib/wasi-types/src/versions/snapshot0.rs b/lib/wasi-types/src/versions/snapshot0.rs index 2c65d32c9cd..fbb9a03eed3 100644 --- a/lib/wasi-types/src/versions/snapshot0.rs +++ b/lib/wasi-types/src/versions/snapshot0.rs @@ -1,8 +1,8 @@ use std::fmt; use wasmer_derive::ValueType; -use wasmer_wasi_types_generated::wasi::{Device, Filesize, Filetype, Inode, Timestamp}; - -pub type __wasi_linkcount_t = u32; +use wasmer_wasi_types_generated::wasi::{ + Device, Filesize, Filetype, Inode, Snapshot0Linkcount, Timestamp, +}; pub type __wasi_whence_t = u8; pub const __WASI_WHENCE_CUR: u8 = 0; @@ -15,7 +15,7 @@ pub struct __wasi_filestat_t { pub st_dev: Device, pub st_ino: Inode, pub st_filetype: Filetype, - pub st_nlink: __wasi_linkcount_t, + pub st_nlink: Snapshot0Linkcount, pub st_size: Filesize, pub st_atim: Timestamp, pub st_mtim: Timestamp, diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index e1a7072fa1c..adcd6ab30af 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -26,8 +26,8 @@ use self::types::{ wasi::{ Addressfamily, Advice, BusErrno, Clockid, Dircookie, Dirent, Errno, Event, EventEnum, EventFdReadwrite, Eventrwflags, Eventtype, Fd as WasiFd, Fdflags, Fdstat, Filesize, - Filetype, Rights, Snapshot0Clockid, Sockoption, Sockstatus, Socktype, Streamsecurity, - Subscription, SubscriptionEnum, SubscriptionFsReadwrite, Timestamp, + Filetype, Linkcount, Rights, Snapshot0Clockid, Sockoption, Sockstatus, Socktype, + Streamsecurity, Subscription, SubscriptionEnum, SubscriptionFsReadwrite, Timestamp, }, *, }; @@ -2185,8 +2185,7 @@ pub fn path_link( false )); - if inodes.arena[source_inode].stat.write().unwrap().st_nlink == __wasi_linkcount_t::max_value() - { + if inodes.arena[source_inode].stat.write().unwrap().st_nlink == Linkcount::max_value() { return Errno::Mlink; } { From 9fefd2208636ee4a0320e33bcfa2e52cc36970f1 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Thu, 25 Aug 2022 07:44:19 +0200 Subject: [PATCH 33/84] snapshot0 Filestat --- lib/wasi-types-generated/src/wasi/bindings.rs | 70 ++++++++++++++++++- lib/wasi-types-generated/src/wasi/mod.rs | 53 ++++++++++++++ lib/wasi-types-generated/wit/wasi.wit | 24 +++++++ lib/wasi-types/src/versions/snapshot0.rs | 62 ---------------- lib/wasi/src/syscalls/legacy/snapshot0.rs | 10 +-- 5 files changed, 150 insertions(+), 69 deletions(-) diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index e8b27b10e77..3a73b8d4cf2 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -1347,6 +1347,38 @@ pub mod wasi { } } } + #[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()} + } /// Auxiliary data associated with the wasm exports. #[derive(Default)] @@ -1421,10 +1453,10 @@ pub mod wasi { }) } /// Dummy function to expose types into generated code - pub fn expose_types_dummy_func(&self, store: &mut wasmer::Store,fd: Fd,dirent: Dirent,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,)-> Result<(), wasmer::RuntimeError> { + pub fn expose_types_dummy_func(&self, store: &mut wasmer::Store,fd: Fd,dirent: Dirent,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,)-> Result<(), wasmer::RuntimeError> { let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; let _memory = &self.memory; - let ptr0 = func_canonical_abi_realloc.call(store, 0, 0, 8, 320)?; + let ptr0 = func_canonical_abi_realloc.call(store, 0, 0, 8, 440)?; let _memory_view = _memory.view(&store); unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 0, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(fd)))?; let Dirent{ d_next:d_next1, d_ino:d_ino1, d_type:d_type1, d_namlen:d_namlen1, } = dirent; @@ -1613,6 +1645,40 @@ pub mod wasi { unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 304, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(linkcount)))?; let _memory_view = _memory.view(&store); unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 312, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(snapshot0_linkcount)))?; + let Filestat{ st_dev:st_dev29, st_ino:st_ino29, st_filetype:st_filetype29, st_nlink:st_nlink29, st_size:st_size29, st_atim:st_atim29, st_mtim:st_mtim29, st_ctim:st_ctim29, } = filestat; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 320, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_dev29)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 328, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_ino29)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 336, wit_bindgen_wasmer::rt::as_i32(st_filetype29 as i32) as u8)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 344, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_nlink29)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 352, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_size29)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 360, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_atim29)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 368, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_mtim29)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 376, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_ctim29)))?; + let Snapshot0Filestat{ st_dev:st_dev30, st_ino:st_ino30, st_filetype:st_filetype30, st_nlink:st_nlink30, st_size:st_size30, st_atim:st_atim30, st_mtim:st_mtim30, st_ctim:st_ctim30, } = snapshot0_filestat; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 384, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_dev30)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 392, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_ino30)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 400, wit_bindgen_wasmer::rt::as_i32(st_filetype30 as i32) as u8)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 404, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(st_nlink30)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 408, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_size30)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 416, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_atim30)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 424, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_mtim30)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 432, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_ctim30)))?; self.func_expose_types_dummy_func.call(store, ptr0, )?; Ok(()) } diff --git a/lib/wasi-types-generated/src/wasi/mod.rs b/lib/wasi-types-generated/src/wasi/mod.rs index 588ca87f274..9da5c3d2f31 100644 --- a/lib/wasi-types-generated/src/wasi/mod.rs +++ b/lib/wasi-types-generated/src/wasi/mod.rs @@ -563,6 +563,59 @@ unsafe impl ValueType for Snapshot0Subscription { } } +unsafe impl ValueType for Snapshot0Filestat { + 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)*) + std::mem::size_of_val(&self.$($f)*) + }; + } + macro_rules! zero { + ($start:expr, $end:expr) => { + for i in $start..$end { + bytes[i] = MaybeUninit::new(0); + } + }; + } + self.st_dev + .zero_padding_bytes(&mut bytes[field!(st_dev)..field_end!(st_dev)]); + zero!(field_end!(st_dev), field!(st_ino)); + + self.st_ino + .zero_padding_bytes(&mut bytes[field!(st_ino)..field_end!(st_ino)]); + zero!(field_end!(st_ino), field!(st_filetype)); + + self.st_filetype + .zero_padding_bytes(&mut bytes[field!(st_filetype)..field_end!(st_filetype)]); + zero!(field_end!(st_filetype), field!(st_nlink)); + + self.st_nlink + .zero_padding_bytes(&mut bytes[field!(st_nlink)..field_end!(st_nlink)]); + zero!(field_end!(st_nlink), field!(st_size)); + + self.st_size + .zero_padding_bytes(&mut bytes[field!(st_size)..field_end!(st_size)]); + zero!(field_end!(st_size), field!(st_atim)); + + self.st_atim + .zero_padding_bytes(&mut bytes[field!(st_atim)..field_end!(st_atim)]); + zero!(field_end!(st_atim), field!(st_mtim)); + + self.st_mtim + .zero_padding_bytes(&mut bytes[field!(st_mtim)..field_end!(st_mtim)]); + zero!(field_end!(st_mtim), field!(st_ctim)); + + self.st_ctim + .zero_padding_bytes(&mut bytes[field!(st_ctim)..field_end!(st_ctim)]); + zero!(field_end!(st_ctim), std::mem::size_of_val(self)); + } +} + // TODO: if necessary, must be implemented in wit-bindgen unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Errno { type Native = i32; diff --git a/lib/wasi-types-generated/wit/wasi.wit b/lib/wasi-types-generated/wit/wasi.wit index 2d65283b10a..351b97dfed4 100644 --- a/lib/wasi-types-generated/wit/wasi.wit +++ b/lib/wasi-types-generated/wit/wasi.wit @@ -18,6 +18,8 @@ expose-types-dummy-func: func( device: device, linkcount: linkcount, snapshot0-linkcount: snapshot0-linkcount, + filestat: filestat, + snapshot0-filestat: snapshot0-filestat, ) @@ -758,3 +760,25 @@ enum addressfamily { 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, +} diff --git a/lib/wasi-types/src/versions/snapshot0.rs b/lib/wasi-types/src/versions/snapshot0.rs index fbb9a03eed3..46962059ddb 100644 --- a/lib/wasi-types/src/versions/snapshot0.rs +++ b/lib/wasi-types/src/versions/snapshot0.rs @@ -8,65 +8,3 @@ 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)] -#[repr(C)] -pub struct __wasi_filestat_t { - 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 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!("{} ({})", self.st_filetype.name(), self.st_filetype as u8,), - ) - .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() - } -} - -/* TODO: re-enable and adjust if required -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", &self.type_.to_str()) - .field( - "u", - match self.type_ { - Eventtype::Clock => unsafe { &self.u.clock }, - Eventtype::FdRead | Eventtype::FdWrite => unsafe { &self.u.fd_readwrite }, - }, - ) - .finish() - } -} -*/ diff --git a/lib/wasi/src/syscalls/legacy/snapshot0.rs b/lib/wasi/src/syscalls/legacy/snapshot0.rs index c331404f312..83b195ab31b 100644 --- a/lib/wasi/src/syscalls/legacy/snapshot0.rs +++ b/lib/wasi/src/syscalls/legacy/snapshot0.rs @@ -3,7 +3,7 @@ use crate::syscalls::types::{self, snapshot0}; use crate::{mem_error_to_wasi, Memory32, MemorySize, WasiEnv, WasiError, WasiThread}; use wasmer::{AsStoreMut, FunctionEnvMut, WasmPtr}; use wasmer_wasi_types_generated::wasi::{ - Errno, Event, Fd, Filesize, Filetype, Snapshot0Subscription, Subscription, + Errno, Event, Fd, Filesize, Filetype, Snapshot0Filestat, Snapshot0Subscription, Subscription, }; /// Wrapper around `syscalls::fd_filestat_get` with extra logic to handle the size @@ -15,7 +15,7 @@ use wasmer_wasi_types_generated::wasi::{ pub fn fd_filestat_get( mut ctx: FunctionEnvMut, fd: Fd, - buf: WasmPtr, + buf: WasmPtr, ) -> Errno { let env = ctx.data(); let memory = env.memory_view(&ctx); @@ -40,7 +40,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, @@ -70,7 +70,7 @@ pub fn path_filestat_get( flags: types::__wasi_lookupflags_t, path: WasmPtr, path_len: u32, - buf: WasmPtr, + buf: WasmPtr, ) -> Errno { // TODO: understand what's happening inside this function, then do the correct thing @@ -88,7 +88,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, From 19e979c2266bec3248ad46463990cd9ea7a39e24 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Thu, 25 Aug 2022 08:06:24 +0200 Subject: [PATCH 34/84] Filestat --- lib/wasi-types-generated/src/wasi/mod.rs | 68 +++++++++++++++++++++++ lib/wasi-types/src/file.rs | 63 +-------------------- lib/wasi-types/src/versions/snapshot0.rs | 6 -- lib/wasi/src/state/mod.rs | 36 ++++++------ lib/wasi/src/state/types.rs | 4 +- lib/wasi/src/syscalls/legacy/snapshot0.rs | 11 ++-- lib/wasi/src/syscalls/mod.rs | 10 ++-- lib/wasi/src/syscalls/wasi.rs | 4 +- lib/wasi/src/syscalls/wasix32.rs | 7 ++- lib/wasi/src/syscalls/wasix64.rs | 7 ++- 10 files changed, 108 insertions(+), 108 deletions(-) diff --git a/lib/wasi-types-generated/src/wasi/mod.rs b/lib/wasi-types-generated/src/wasi/mod.rs index 9da5c3d2f31..0d4648fbaba 100644 --- a/lib/wasi-types-generated/src/wasi/mod.rs +++ b/lib/wasi-types-generated/src/wasi/mod.rs @@ -616,6 +616,74 @@ unsafe impl ValueType for Snapshot0Filestat { } } +unsafe impl ValueType for Filestat { + 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)*) + std::mem::size_of_val(&self.$($f)*) + }; + } + macro_rules! zero { + ($start:expr, $end:expr) => { + for i in $start..$end { + bytes[i] = MaybeUninit::new(0); + } + }; + } + self.st_dev + .zero_padding_bytes(&mut bytes[field!(st_dev)..field_end!(st_dev)]); + zero!(field_end!(st_dev), field!(st_ino)); + + self.st_ino + .zero_padding_bytes(&mut bytes[field!(st_ino)..field_end!(st_ino)]); + zero!(field_end!(st_ino), field!(st_filetype)); + + self.st_filetype + .zero_padding_bytes(&mut bytes[field!(st_filetype)..field_end!(st_filetype)]); + zero!(field_end!(st_filetype), field!(st_nlink)); + + self.st_nlink + .zero_padding_bytes(&mut bytes[field!(st_nlink)..field_end!(st_nlink)]); + zero!(field_end!(st_nlink), field!(st_size)); + + self.st_size + .zero_padding_bytes(&mut bytes[field!(st_size)..field_end!(st_size)]); + zero!(field_end!(st_size), field!(st_atim)); + + self.st_atim + .zero_padding_bytes(&mut bytes[field!(st_atim)..field_end!(st_atim)]); + zero!(field_end!(st_atim), field!(st_mtim)); + + self.st_mtim + .zero_padding_bytes(&mut bytes[field!(st_mtim)..field_end!(st_mtim)]); + zero!(field_end!(st_mtim), field!(st_ctim)); + + self.st_ctim + .zero_padding_bytes(&mut bytes[field!(st_ctim)..field_end!(st_ctim)]); + zero!(field_end!(st_ctim), std::mem::size_of_val(self)); + } +} + +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(), + } + } +} + // TODO: if necessary, must be implemented in wit-bindgen unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Errno { type Native = i32; diff --git a/lib/wasi-types/src/file.rs b/lib/wasi-types/src/file.rs index 82531d8b1e3..36e55622f2c 100644 --- a/lib/wasi-types/src/file.rs +++ b/lib/wasi-types/src/file.rs @@ -4,9 +4,7 @@ use std::{ }; use wasmer_derive::ValueType; use wasmer_types::ValueType; -use wasmer_wasi_types_generated::wasi::{ - Device, Fd, Filesize, Filetype, Inode, Linkcount, Preopentype, Rights, Timestamp, -}; +use wasmer_wasi_types_generated::wasi::{Fd, Preopentype, Rights}; pub const __WASI_STDIN_FILENO: Fd = 0; pub const __WASI_STDOUT_FILENO: Fd = 1; @@ -105,65 +103,6 @@ unsafe impl ValueType for __wasi_prestat_t { pub type __wasi_filedelta_t = i64; -#[derive(Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_filestat_t { - 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 Default for __wasi_filestat_t { - fn default() -> Self { - __wasi_filestat_t { - 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(), - } - } -} - -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!("{} ({})", self.st_filetype.name(), self.st_filetype as u8,), - ) - .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 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; diff --git a/lib/wasi-types/src/versions/snapshot0.rs b/lib/wasi-types/src/versions/snapshot0.rs index 46962059ddb..6c099849a32 100644 --- a/lib/wasi-types/src/versions/snapshot0.rs +++ b/lib/wasi-types/src/versions/snapshot0.rs @@ -1,9 +1,3 @@ -use std::fmt; -use wasmer_derive::ValueType; -use wasmer_wasi_types_generated::wasi::{ - Device, Filesize, Filetype, Inode, Snapshot0Linkcount, Timestamp, -}; - pub type __wasi_whence_t = u8; pub const __WASI_WHENCE_CUR: u8 = 0; pub const __WASI_WHENCE_END: u8 = 1; diff --git a/lib/wasi/src/state/mod.rs b/lib/wasi/src/state/mod.rs index 9cb414d81e1..c4fafe4a73f 100644 --- a/lib/wasi/src/state/mod.rs +++ b/lib/wasi/src/state/mod.rs @@ -53,7 +53,7 @@ use std::{ use tracing::{debug, trace}; use wasmer_vbus::BusSpawnedProcess; use wasmer_wasi_types_generated::wasi::{ - Errno, Fd as WasiFd, Fdflags, Fdstat, Filesize, Filetype, Preopentype, Rights, + Errno, Fd as WasiFd, Fdflags, Fdstat, Filesize, Filestat, Filetype, Preopentype, Rights, }; use wasmer_vfs::{FileSystem, FsError, OpenOptions, VirtualFile}; @@ -96,7 +96,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, @@ -1024,9 +1024,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() }, ); @@ -1310,7 +1310,7 @@ impl WasiFs { .map(|a| a.inode) } - pub fn filestat_fd(&self, inodes: &WasiInodes, fd: WasiFd) -> Result<__wasi_filestat_t, Errno> { + 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()) } @@ -1452,7 +1452,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) } @@ -1463,7 +1463,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(); @@ -1528,10 +1528,10 @@ impl WasiFs { } fn create_virtual_root(&self, inodes: &mut WasiInodes) -> Inode { - let stat = __wasi_filestat_t { + 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(), @@ -1585,10 +1585,10 @@ impl WasiFs { rights: Rights, fd_flags: Fdflags, ) { - let stat = __wasi_filestat_t { + 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), @@ -1617,22 +1617,18 @@ impl WasiFs { ); } - pub fn get_stat_for_kind( - &self, - inodes: &WasiInodes, - kind: &Kind, - ) -> Result<__wasi_filestat_t, Errno> { + 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 { + 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 @@ -1674,13 +1670,13 @@ impl WasiFs { } _ => 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() }) } diff --git a/lib/wasi/src/state/types.rs b/lib/wasi/src/state/types.rs index 662b0819f9b..5b6f655bc85 100644 --- a/lib/wasi/src/state/types.rs +++ b/lib/wasi/src/state/types.rs @@ -453,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 83b195ab31b..be8c87306a9 100644 --- a/lib/wasi/src/syscalls/legacy/snapshot0.rs +++ b/lib/wasi/src/syscalls/legacy/snapshot0.rs @@ -3,7 +3,8 @@ use crate::syscalls::types::{self, snapshot0}; use crate::{mem_error_to_wasi, Memory32, MemorySize, WasiEnv, WasiError, WasiThread}; use wasmer::{AsStoreMut, FunctionEnvMut, WasmPtr}; use wasmer_wasi_types_generated::wasi::{ - Errno, Event, Fd, Filesize, Filetype, Snapshot0Filestat, Snapshot0Subscription, Subscription, + Errno, Event, Fd, Filesize, Filestat, Filetype, Snapshot0Filestat, Snapshot0Subscription, + Subscription, }; /// Wrapper around `syscalls::fd_filestat_get` with extra logic to handle the size @@ -24,10 +25,10 @@ pub fn fd_filestat_get( // 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. @@ -78,8 +79,8 @@ pub fn path_filestat_get( 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); diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index adcd6ab30af..0d256de712e 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -26,7 +26,7 @@ use self::types::{ wasi::{ Addressfamily, Advice, BusErrno, Clockid, Dircookie, Dirent, Errno, Event, EventEnum, EventFdReadwrite, Eventrwflags, Eventtype, Fd as WasiFd, Fdflags, Fdstat, Filesize, - Filetype, Linkcount, Rights, Snapshot0Clockid, Sockoption, Sockstatus, Socktype, + Filestat, Filetype, Linkcount, Rights, Snapshot0Clockid, Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, SubscriptionEnum, SubscriptionFsReadwrite, Timestamp, }, *, @@ -690,12 +690,12 @@ pub fn fd_fdstat_set_rights( /// - `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: WasiFd, - buf: WasmPtr<__wasi_filestat_t, M>, + buf: WasmPtr, ) -> Errno { debug!("wasi::fd_filestat_get"); let env = ctx.data(); @@ -1980,7 +1980,7 @@ pub fn path_filestat_get( flags: __wasi_lookupflags_t, path: WasmPtr, path_len: M::Offset, - buf: WasmPtr<__wasi_filestat_t, M>, + buf: WasmPtr, ) -> Errno { debug!("wasi::path_filestat_get (fd={})", fd); let env = ctx.data(); @@ -2023,7 +2023,7 @@ pub fn path_filestat_get_internal( fd: WasiFd, flags: __wasi_lookupflags_t, path_string: &str, -) -> Result<__wasi_filestat_t, Errno> { +) -> Result { let root_dir = state.fs.get_fd(fd)?; if !root_dir.rights.contains(Rights::PATH_FILESTAT_GET) { diff --git a/lib/wasi/src/syscalls/wasi.rs b/lib/wasi/src/syscalls/wasi.rs index 24fa9ea7c58..8fdf1dcd67d 100644 --- a/lib/wasi/src/syscalls/wasi.rs +++ b/lib/wasi/src/syscalls/wasi.rs @@ -113,7 +113,7 @@ pub(crate) fn fd_fdstat_set_rights( pub(crate) fn fd_filestat_get( ctx: FunctionEnvMut, fd: WasiFd, - buf: WasmPtr<__wasi_filestat_t, MemoryType>, + buf: WasmPtr, ) -> Errno { super::fd_filestat_get::(ctx, fd, buf) } @@ -247,7 +247,7 @@ pub(crate) fn path_filestat_get( flags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, - buf: WasmPtr<__wasi_filestat_t, MemoryType>, + buf: WasmPtr, ) -> Errno { super::path_filestat_get::(ctx, fd, flags, path, path_len, buf) } diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index 46d342fe65d..a9ddb5cf67f 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -4,7 +4,8 @@ use wasmer::{FunctionEnvMut, Memory, Memory32, MemorySize, StoreMut, WasmPtr, Wa use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ Addressfamily, Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, - Filesize, Rights, Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, Timestamp, + Filesize, Filestat, Rights, Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, + Timestamp, }; type MemoryType = Memory32; @@ -110,7 +111,7 @@ pub(crate) fn fd_fdstat_set_rights( pub(crate) fn fd_filestat_get( ctx: FunctionEnvMut, fd: Fd, - buf: WasmPtr<__wasi_filestat_t, MemoryType>, + buf: WasmPtr, ) -> Errno { super::fd_filestat_get::(ctx, fd, buf) } @@ -244,7 +245,7 @@ pub(crate) fn path_filestat_get( flags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, - buf: WasmPtr<__wasi_filestat_t, MemoryType>, + buf: WasmPtr, ) -> Errno { super::path_filestat_get::(ctx, fd, flags, path, path_len, buf) } diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index 2d98cdd4b42..c0b0f7a5f72 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -4,7 +4,8 @@ use wasmer::{FunctionEnvMut, Memory, Memory64, MemorySize, StoreMut, WasmPtr, Wa use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ Addressfamily, Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, - Filesize, Rights, Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, Timestamp, + Filesize, Filestat, Rights, Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, + Timestamp, }; type MemoryType = Memory64; @@ -110,7 +111,7 @@ pub(crate) fn fd_fdstat_set_rights( pub(crate) fn fd_filestat_get( ctx: FunctionEnvMut, fd: Fd, - buf: WasmPtr<__wasi_filestat_t, MemoryType>, + buf: WasmPtr, ) -> Errno { super::fd_filestat_get::(ctx, fd, buf) } @@ -244,7 +245,7 @@ pub(crate) fn path_filestat_get( flags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, - buf: WasmPtr<__wasi_filestat_t, MemoryType>, + buf: WasmPtr, ) -> Errno { super::path_filestat_get::(ctx, fd, flags, path, path_len, buf) } From 7f2bd8f897971632d1efce49512080a7b5bcf9e8 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Thu, 25 Aug 2022 08:21:38 +0200 Subject: [PATCH 35/84] snapshot0 Whence --- lib/wasi-types-generated/src/wasi/bindings.rs | 44 +++++++++++++++ lib/wasi-types-generated/src/wasi/mod.rs | 54 +++++++++++++++++++ lib/wasi-types-generated/wit/wasi.wit | 12 +++++ lib/wasi-types/src/lib.rs | 2 - lib/wasi-types/src/versions/mod.rs | 1 - lib/wasi-types/src/versions/snapshot0.rs | 4 -- lib/wasi/src/syscalls/legacy/snapshot0.rs | 14 +++-- 7 files changed, 116 insertions(+), 15 deletions(-) delete mode 100644 lib/wasi-types/src/versions/mod.rs delete mode 100644 lib/wasi-types/src/versions/snapshot0.rs diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index 3a73b8d4cf2..bc0e6f5489d 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -1379,6 +1379,50 @@ pub mod wasi { 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() + } + } + } + } /// Auxiliary data associated with the wasm exports. #[derive(Default)] diff --git a/lib/wasi-types-generated/src/wasi/mod.rs b/lib/wasi-types-generated/src/wasi/mod.rs index 0d4648fbaba..f807a9205fe 100644 --- a/lib/wasi-types-generated/src/wasi/mod.rs +++ b/lib/wasi-types-generated/src/wasi/mod.rs @@ -52,6 +52,12 @@ unsafe impl ValueType for Addressfamily { 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]) {} +} + impl Filetype { pub fn name(self) -> &'static str { match self { @@ -1176,6 +1182,54 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Addressfamily { } } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + // TODO: if necessary, must be implemented in wit-bindgen unsafe impl ValueType for Snapshot0Clockid { #[inline] diff --git a/lib/wasi-types-generated/wit/wasi.wit b/lib/wasi-types-generated/wit/wasi.wit index 351b97dfed4..50136027b50 100644 --- a/lib/wasi-types-generated/wit/wasi.wit +++ b/lib/wasi-types-generated/wit/wasi.wit @@ -782,3 +782,15 @@ record filestat { st-mtim: timestamp, st-ctim: timestamp, } + +enum snapshot0-whence { + cur, + end, + set, +} + +enum whence { + set, + cur, + end, +} diff --git a/lib/wasi-types/src/lib.rs b/lib/wasi-types/src/lib.rs index 7e5440cc865..7c85be5aae7 100644 --- a/lib/wasi-types/src/lib.rs +++ b/lib/wasi-types/src/lib.rs @@ -19,7 +19,6 @@ mod net; mod signal; mod subscription; mod time; -mod versions; pub use crate::time::*; pub use bus::*; @@ -29,7 +28,6 @@ pub use io::*; pub use net::*; pub use signal::*; pub use subscription::*; -pub use versions::*; pub type __wasi_exitcode_t = u32; 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 6c099849a32..00000000000 --- a/lib/wasi-types/src/versions/snapshot0.rs +++ /dev/null @@ -1,4 +0,0 @@ -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; diff --git a/lib/wasi/src/syscalls/legacy/snapshot0.rs b/lib/wasi/src/syscalls/legacy/snapshot0.rs index be8c87306a9..f6da8ad1d81 100644 --- a/lib/wasi/src/syscalls/legacy/snapshot0.rs +++ b/lib/wasi/src/syscalls/legacy/snapshot0.rs @@ -1,10 +1,10 @@ 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_generated::wasi::{ Errno, Event, Fd, Filesize, Filestat, Filetype, Snapshot0Filestat, Snapshot0Subscription, - Subscription, + Snapshot0Whence, Subscription, }; /// Wrapper around `syscalls::fd_filestat_get` with extra logic to handle the size @@ -112,15 +112,13 @@ pub fn fd_seek( ctx: FunctionEnvMut, fd: Fd, offset: types::__wasi_filedelta_t, - whence: snapshot0::__wasi_whence_t, + 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 => types::__WASI_WHENCE_CUR, + Snapshot0Whence::End => types::__WASI_WHENCE_END, + Snapshot0Whence::Set => types::__WASI_WHENCE_SET, }; syscalls::fd_seek::(ctx, fd, offset, new_whence, newoffset) } From a9290a547d9c8bb8d3c4d708fe37d93a81b5cb68 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Thu, 25 Aug 2022 08:37:19 +0200 Subject: [PATCH 36/84] Whence --- lib/wasi-types/src/file.rs | 5 ----- lib/wasi/src/syscalls/legacy/snapshot0.rs | 10 +++++----- lib/wasi/src/syscalls/mod.rs | 12 ++++++------ lib/wasi/src/syscalls/wasi.rs | 4 ++-- lib/wasi/src/syscalls/wasix32.rs | 4 ++-- lib/wasi/src/syscalls/wasix64.rs | 4 ++-- 6 files changed, 17 insertions(+), 22 deletions(-) diff --git a/lib/wasi-types/src/file.rs b/lib/wasi-types/src/file.rs index 36e55622f2c..5b6a5b879a4 100644 --- a/lib/wasi-types/src/file.rs +++ b/lib/wasi-types/src/file.rs @@ -131,8 +131,3 @@ pub fn print_right_set(rights: Rights) { } println!("{:#?}", right_set); } - -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/src/syscalls/legacy/snapshot0.rs b/lib/wasi/src/syscalls/legacy/snapshot0.rs index f6da8ad1d81..d5182db9936 100644 --- a/lib/wasi/src/syscalls/legacy/snapshot0.rs +++ b/lib/wasi/src/syscalls/legacy/snapshot0.rs @@ -4,7 +4,7 @@ use crate::{mem_error_to_wasi, Memory32, MemorySize, WasiEnv, WasiError, WasiThr use wasmer::{AsStoreMut, FunctionEnvMut, WasmPtr}; use wasmer_wasi_types_generated::wasi::{ Errno, Event, Fd, Filesize, Filestat, Filetype, Snapshot0Filestat, Snapshot0Subscription, - Snapshot0Whence, Subscription, + Snapshot0Whence, Subscription, Whence, }; /// Wrapper around `syscalls::fd_filestat_get` with extra logic to handle the size @@ -107,7 +107,7 @@ 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: Fd, @@ -116,9 +116,9 @@ pub fn fd_seek( newoffset: WasmPtr, ) -> Result { let new_whence = match whence { - Snapshot0Whence::Cur => types::__WASI_WHENCE_CUR, - Snapshot0Whence::End => types::__WASI_WHENCE_END, - Snapshot0Whence::Set => types::__WASI_WHENCE_SET, + Snapshot0Whence::Cur => Whence::Cur, + Snapshot0Whence::End => Whence::End, + Snapshot0Whence::Set => Whence::Set, }; syscalls::fd_seek::(ctx, fd, offset, new_whence, newoffset) } diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 0d256de712e..bb0f9bf9f3e 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -27,7 +27,7 @@ use self::types::{ Addressfamily, Advice, BusErrno, Clockid, Dircookie, Dirent, Errno, Event, EventEnum, EventFdReadwrite, Eventrwflags, Eventtype, Fd as WasiFd, Fdflags, Fdstat, Filesize, Filestat, Filetype, Linkcount, Rights, Snapshot0Clockid, Sockoption, Sockstatus, Socktype, - Streamsecurity, Subscription, SubscriptionEnum, SubscriptionFsReadwrite, Timestamp, + Streamsecurity, Subscription, SubscriptionEnum, SubscriptionFsReadwrite, Timestamp, Whence, }, *, }; @@ -1492,7 +1492,7 @@ pub fn fd_event( /// File descriptor to mutate /// - `__wasi_filedelta_t offset` /// Number of bytes to adjust offset by -/// - `__wasi_whence_t whence` +/// - `Whence whence` /// What the offset is relative to /// Output: /// - `Filesize *fd` @@ -1501,7 +1501,7 @@ pub fn fd_seek( ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd, offset: __wasi_filedelta_t, - whence: __wasi_whence_t, + whence: Whence, newoffset: WasmPtr, ) -> Result { trace!("wasi::fd_seek: fd={}, offset={}", fd, offset); @@ -1516,12 +1516,12 @@ pub fn fd_seek( // 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(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(); @@ -1559,7 +1559,7 @@ pub fn fd_seek( } } } - __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(Errno::Badf)); fd_entry.offset = offset as u64 diff --git a/lib/wasi/src/syscalls/wasi.rs b/lib/wasi/src/syscalls/wasi.rs index 8fdf1dcd67d..5d0d39a6262 100644 --- a/lib/wasi/src/syscalls/wasi.rs +++ b/lib/wasi/src/syscalls/wasi.rs @@ -2,7 +2,7 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{Memory, Memory32, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::{ - wasi::{Errno, Event, Fd as WasiFd, Filesize, Timestamp}, + wasi::{Errno, Event, Fd as WasiFd, Filesize, Timestamp, Whence}, *, }; @@ -204,7 +204,7 @@ pub(crate) fn fd_seek( ctx: FunctionEnvMut, fd: WasiFd, offset: __wasi_filedelta_t, - whence: __wasi_whence_t, + whence: Whence, newoffset: WasmPtr, ) -> Result { super::fd_seek::(ctx, fd, offset, whence, newoffset) diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index a9ddb5cf67f..b75d3b35b26 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -5,7 +5,7 @@ use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ Addressfamily, Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Filesize, Filestat, Rights, Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, - Timestamp, + Timestamp, Whence, }; type MemoryType = Memory32; @@ -202,7 +202,7 @@ pub(crate) fn fd_seek( ctx: FunctionEnvMut, fd: Fd, offset: __wasi_filedelta_t, - whence: __wasi_whence_t, + whence: Whence, newoffset: WasmPtr, ) -> Result { super::fd_seek::(ctx, fd, offset, whence, newoffset) diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index c0b0f7a5f72..a84873e1084 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -5,7 +5,7 @@ use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ Addressfamily, Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Filesize, Filestat, Rights, Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, - Timestamp, + Timestamp, Whence, }; type MemoryType = Memory64; @@ -202,7 +202,7 @@ pub(crate) fn fd_seek( ctx: FunctionEnvMut, fd: Fd, offset: __wasi_filedelta_t, - whence: __wasi_whence_t, + whence: Whence, newoffset: WasmPtr, ) -> Result { super::fd_seek::(ctx, fd, offset, whence, newoffset) From 7c6164da24b34a412af4dbbc51482040ade98f04 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Thu, 25 Aug 2022 18:20:00 +0200 Subject: [PATCH 37/84] Fstflags --- lib/wasi-types-generated/src/wasi/bindings.rs | 8 ++-- lib/wasi-types-generated/src/wasi/mod.rs | 24 ++++++++++++ lib/wasi-types-generated/wit/wasi.wit | 36 ++++++++--------- lib/wasi-types/src/file.rs | 6 --- lib/wasi/src/syscalls/mod.rs | 39 +++++++++---------- lib/wasi/src/syscalls/wasi.rs | 6 +-- lib/wasi/src/syscalls/wasix32.rs | 8 ++-- lib/wasi/src/syscalls/wasix64.rs | 8 ++-- 8 files changed, 76 insertions(+), 59 deletions(-) diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index bc0e6f5489d..ac82f4027d6 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -799,13 +799,13 @@ pub mod wasi { wit_bindgen_wasmer::bitflags::bitflags! { /// Which file time attributes to adjust. pub struct Fstflags: u8 {/// Adjust the last data access timestamp to the value stored in `filestat::atim`. - const ATIM = 1 << 0; + const SET_ATIM = 1 << 0; /// Adjust the last data access timestamp to the time of clock `clockid::realtime`. - const ATIM_NOW = 1 << 1; + const SET_ATIM_NOW = 1 << 1; /// Adjust the last data modification timestamp to the value stored in `filestat::mtim`. - const MTIM = 1 << 2; + const SET_MTIM = 1 << 2; /// Adjust the last data modification timestamp to the time of clock `clockid::realtime`. - const MTIM_NOW = 1 << 3; + const SET_MTIM_NOW = 1 << 3; } } diff --git a/lib/wasi-types-generated/src/wasi/mod.rs b/lib/wasi-types-generated/src/wasi/mod.rs index f807a9205fe..235e2e15cfb 100644 --- a/lib/wasi-types-generated/src/wasi/mod.rs +++ b/lib/wasi-types-generated/src/wasi/mod.rs @@ -192,6 +192,12 @@ unsafe impl ValueType for Eventrwflags { 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 SubscriptionEnum { fn zero_padding_bytes(&self, bytes: &mut [MaybeUninit]) { @@ -968,6 +974,24 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Eventrwflags { } } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wit_bindgen_wasmer::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 u8) + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} + // TODO: if necessary, must be implemented in wit-bindgen unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Subclockflags { type Native = i32; diff --git a/lib/wasi-types-generated/wit/wasi.wit b/lib/wasi-types-generated/wit/wasi.wit index 50136027b50..97a71f54faa 100644 --- a/lib/wasi-types-generated/wit/wasi.wit +++ b/lib/wasi-types-generated/wit/wasi.wit @@ -64,7 +64,7 @@ type snapshot0-linkcount = u32 /// Identifiers for clocks, snapshot0 version. enum snapshot0-clockid { - // TODO: wit appears to not have support for enum type size + // TODO: wit appears to not have support for enum tag types //(@witx tag u32) /// The clock measuring real time. Time value zero corresponds with @@ -83,7 +83,7 @@ enum snapshot0-clockid { /// Identifiers for clocks. enum clockid { - // TODO: wit appears to not have support for enum type size + // TODO: wit appears to not have support for enum tag types //(@witx tag u32) /// The clock measuring real time. Time value zero corresponds with @@ -101,7 +101,7 @@ enum clockid { /// 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 type size + // TODO: wit appears to not have support for enum tag types //(@witx tag u16) /// No error occurred. System call completed successfully. @@ -261,7 +261,7 @@ enum errno { } enum bus-errno { - // TODO: wit appears to not have support for enum type size + // TODO: wit appears to not have support for enum tag types //(@witx tag u32) /// No error occurred. Call completed successfully. @@ -409,7 +409,7 @@ flags rights { /// The type of a file descriptor or file. enum filetype { - // TODO: wit appears to not have support for enum type size + // 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. @@ -458,7 +458,7 @@ record dirent { /// File or memory access pattern advisory information. enum advice { - // TODO: wit appears to not have support for enum type size + // 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. @@ -477,7 +477,7 @@ enum advice { /// File descriptor flags. flags fdflags { - // TODO: wit appears to not have support for flags type size + // 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. @@ -509,22 +509,22 @@ record fdstat { /// Which file time attributes to adjust. flags fstflags { - // TODO: wit appears to not have support for flags type size + // TODO: wit appears to not have support for flags repr //(@witx repr u16) /// Adjust the last data access timestamp to the value stored in `filestat::atim`. - atim, + set-atim, /// Adjust the last data access timestamp to the time of clock `clockid::realtime`. - atim-now, + set-atim-now, /// Adjust the last data modification timestamp to the value stored in `filestat::mtim`. - mtim, + set-mtim, /// Adjust the last data modification timestamp to the time of clock `clockid::realtime`. - mtim-now, + set-mtim-now, } /// Flags determining the method of how paths are resolved. flags lookup { - // TODO: wit appears to not have support for flags type size + // TODO: wit appears to not have support for flags repr //(@witx repr u32) /// As long as the resolved path corresponds to a symbolic link, it is expanded. @@ -533,7 +533,7 @@ flags lookup { /// Open flags used by `path_open`. flags oflags { - // TODO: wit appears to not have support for flags type size + // TODO: wit appears to not have support for flags repr //(@witx repr u16) /// Create file if it does not exist. @@ -552,7 +552,7 @@ type userdata = u64 /// Type of a subscription to an event or its occurrence. enum eventtype { - // TODO: wit appears to not have support for enum type size + // TODO: wit appears to not have support for enum tag types //(@witx tag u8) /// The time value of clock `subscription_clock::id` has @@ -569,7 +569,7 @@ enum eventtype { /// Flags determining how to interpret the timestamp provided in /// `subscription-clock::timeout`. flags subclockflags { - // TODO: wit appears to not have support for flags type size + // 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 @@ -609,7 +609,7 @@ record subscription-clock { /// Identifiers for preopened capabilities. enum preopentype { - // TODO: wit appears to not have support for enum type size + // TODO: wit appears to not have support for enum tag types //(@witx tag u8) /// A pre-opened directory. @@ -619,7 +619,7 @@ enum preopentype { /// 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 type size + // TODO: wit appears to not have support for flags repr //@witx repr u16) /// The peer of this socket has closed or disconnected. diff --git a/lib/wasi-types/src/file.rs b/lib/wasi-types/src/file.rs index 5b6a5b879a4..16d9fbb05ca 100644 --- a/lib/wasi-types/src/file.rs +++ b/lib/wasi-types/src/file.rs @@ -103,12 +103,6 @@ unsafe impl ValueType for __wasi_prestat_t { pub type __wasi_filedelta_t = i64; -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_lookupflags_t = u32; pub const __WASI_LOOKUP_SYMLINK_FOLLOW: __wasi_lookupflags_t = 1 << 0; diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index bb0f9bf9f3e..23ef9a7ced8 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -26,8 +26,9 @@ use self::types::{ wasi::{ Addressfamily, Advice, BusErrno, Clockid, Dircookie, Dirent, Errno, Event, EventEnum, EventFdReadwrite, Eventrwflags, Eventtype, Fd as WasiFd, Fdflags, Fdstat, Filesize, - Filestat, Filetype, Linkcount, Rights, Snapshot0Clockid, Sockoption, Sockstatus, Socktype, - Streamsecurity, Subscription, SubscriptionEnum, SubscriptionFsReadwrite, Timestamp, Whence, + Filestat, Filetype, Fstflags, Linkcount, Rights, Snapshot0Clockid, Sockoption, Sockstatus, + Socktype, Streamsecurity, Subscription, SubscriptionEnum, SubscriptionFsReadwrite, + Timestamp, Whence, }, *, }; @@ -768,14 +769,14 @@ pub fn fd_filestat_set_size( /// Last accessed time /// - `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: WasiFd, st_atim: Timestamp, st_mtim: Timestamp, - fst_flags: __wasi_fstflags_t, + fst_flags: Fstflags, ) -> Errno { debug!("wasi::fd_filestat_set_times"); let env = ctx.data(); @@ -786,9 +787,8 @@ pub fn 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 Errno::Inval; } @@ -796,8 +796,8 @@ pub fn fd_filestat_set_times( 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()) @@ -805,8 +805,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()) @@ -2060,7 +2060,7 @@ pub fn path_filestat_get_internal( /// The timestamp that the last accessed time attribute is set to /// - `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>, @@ -2070,7 +2070,7 @@ pub fn path_filestat_set_times( path_len: M::Offset, st_atim: Timestamp, st_mtim: Timestamp, - fst_flags: __wasi_fstflags_t, + fst_flags: Fstflags, ) -> Errno { debug!("wasi::path_filestat_set_times"); let env = ctx.data(); @@ -2080,9 +2080,8 @@ pub fn path_filestat_set_times( 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 Errno::Inval; } @@ -2103,16 +2102,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()) diff --git a/lib/wasi/src/syscalls/wasi.rs b/lib/wasi/src/syscalls/wasi.rs index 5d0d39a6262..63109da0baf 100644 --- a/lib/wasi/src/syscalls/wasi.rs +++ b/lib/wasi/src/syscalls/wasi.rs @@ -2,7 +2,7 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{Memory, Memory32, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::{ - wasi::{Errno, Event, Fd as WasiFd, Filesize, Timestamp, Whence}, + wasi::{Errno, Event, Fd as WasiFd, Filesize, Fstflags, Fstflags, Timestamp, Whence}, *, }; @@ -131,7 +131,7 @@ pub(crate) fn fd_filestat_set_times( fd: WasiFd, st_atim: Timestamp, st_mtim: Timestamp, - fst_flags: __wasi_fstflags_t, + fst_flags: Fstflags, ) -> Errno { super::fd_filestat_set_times(ctx, fd, st_atim, st_mtim, fst_flags) } @@ -260,7 +260,7 @@ pub(crate) fn path_filestat_set_times( path_len: MemoryOffset, st_atim: Timestamp, st_mtim: Timestamp, - fst_flags: __wasi_fstflags_t, + fst_flags: Fstflags, ) -> Errno { super::path_filestat_set_times::( ctx, fd, flags, path, path_len, st_atim, st_mtim, fst_flags, diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index b75d3b35b26..7fab2a1c410 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -4,8 +4,8 @@ use wasmer::{FunctionEnvMut, Memory, Memory32, MemorySize, StoreMut, WasmPtr, Wa use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ Addressfamily, Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, - Filesize, Filestat, Rights, Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, - Timestamp, Whence, + Filesize, Filestat, Fstflags, Rights, Sockoption, Sockstatus, Socktype, Streamsecurity, + Subscription, Timestamp, Whence, }; type MemoryType = Memory32; @@ -129,7 +129,7 @@ pub(crate) fn fd_filestat_set_times( fd: Fd, st_atim: Timestamp, st_mtim: Timestamp, - fst_flags: __wasi_fstflags_t, + fst_flags: Fstflags, ) -> Errno { super::fd_filestat_set_times(ctx, fd, st_atim, st_mtim, fst_flags) } @@ -258,7 +258,7 @@ pub(crate) fn path_filestat_set_times( path_len: MemoryOffset, st_atim: Timestamp, st_mtim: Timestamp, - fst_flags: __wasi_fstflags_t, + fst_flags: Fstflags, ) -> Errno { super::path_filestat_set_times::( ctx, fd, flags, path, path_len, st_atim, st_mtim, fst_flags, diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index a84873e1084..51ae191b7e5 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -4,8 +4,8 @@ use wasmer::{FunctionEnvMut, Memory, Memory64, MemorySize, StoreMut, WasmPtr, Wa use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ Addressfamily, Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, - Filesize, Filestat, Rights, Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, - Timestamp, Whence, + Filesize, Filestat, Fstflags, Rights, Sockoption, Sockstatus, Socktype, Streamsecurity, + Subscription, Timestamp, Whence, }; type MemoryType = Memory64; @@ -129,7 +129,7 @@ pub(crate) fn fd_filestat_set_times( fd: Fd, st_atim: Timestamp, st_mtim: Timestamp, - fst_flags: __wasi_fstflags_t, + fst_flags: Fstflags, ) -> Errno { super::fd_filestat_set_times(ctx, fd, st_atim, st_mtim, fst_flags) } @@ -258,7 +258,7 @@ pub(crate) fn path_filestat_set_times( path_len: MemoryOffset, st_atim: Timestamp, st_mtim: Timestamp, - fst_flags: __wasi_fstflags_t, + fst_flags: Fstflags, ) -> Errno { super::path_filestat_set_times::( ctx, fd, flags, path, path_len, st_atim, st_mtim, fst_flags, From aa8d6fa94f4fcb37c55c9875baeb86d43a1563ee Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Thu, 25 Aug 2022 18:43:49 +0200 Subject: [PATCH 38/84] Tty --- lib/types/src/value.rs | 1 + lib/wasi-types-generated/src/wasi/bindings.rs | 40 +++++++++++- lib/wasi-types-generated/src/wasi/mod.rs | 58 +++++++++++++++++ lib/wasi-types-generated/wit/wasi.wit | 13 ++++ lib/wasi-types/src/io.rs | 14 ----- lib/wasi/src/syscalls/mod.rs | 63 +++++-------------- lib/wasi/src/syscalls/wasix32.rs | 12 +--- lib/wasi/src/syscalls/wasix64.rs | 12 +--- 8 files changed, 130 insertions(+), 83 deletions(-) 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-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index ac82f4027d6..88624c9e961 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -1423,6 +1423,23 @@ pub mod wasi { } } } + #[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()} + } /// Auxiliary data associated with the wasm exports. #[derive(Default)] @@ -1497,10 +1514,10 @@ pub mod wasi { }) } /// Dummy function to expose types into generated code - pub fn expose_types_dummy_func(&self, store: &mut wasmer::Store,fd: Fd,dirent: Dirent,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,)-> Result<(), wasmer::RuntimeError> { + pub fn expose_types_dummy_func(&self, store: &mut wasmer::Store,fd: Fd,dirent: Dirent,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,)-> Result<(), wasmer::RuntimeError> { let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; let _memory = &self.memory; - let ptr0 = func_canonical_abi_realloc.call(store, 0, 0, 8, 440)?; + let ptr0 = func_canonical_abi_realloc.call(store, 0, 0, 8, 464)?; let _memory_view = _memory.view(&store); unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 0, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(fd)))?; let Dirent{ d_next:d_next1, d_ino:d_ino1, d_type:d_type1, d_namlen:d_namlen1, } = dirent; @@ -1723,6 +1740,25 @@ pub mod wasi { unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 424, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_mtim30)))?; let _memory_view = _memory.view(&store); unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 432, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_ctim30)))?; + let Tty{ cols:cols31, rows:rows31, width:width31, height:height31, stdin_tty:stdin_tty31, stdout_tty:stdout_tty31, stderr_tty:stderr_tty31, echo:echo31, line_buffered:line_buffered31, } = tty; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 440, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(cols31)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 444, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(rows31)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 448, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(width31)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 452, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(height31)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 456, wit_bindgen_wasmer::rt::as_i32(match stdin_tty31 { true => 1, false => 0 }) as u8)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 457, wit_bindgen_wasmer::rt::as_i32(match stdout_tty31 { true => 1, false => 0 }) as u8)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 458, wit_bindgen_wasmer::rt::as_i32(match stderr_tty31 { true => 1, false => 0 }) as u8)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 459, wit_bindgen_wasmer::rt::as_i32(match echo31 { true => 1, false => 0 }) as u8)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 460, wit_bindgen_wasmer::rt::as_i32(match line_buffered31 { true => 1, false => 0 }) as u8)?; self.func_expose_types_dummy_func.call(store, ptr0, )?; Ok(()) } diff --git a/lib/wasi-types-generated/src/wasi/mod.rs b/lib/wasi-types-generated/src/wasi/mod.rs index 235e2e15cfb..0c4b65f0029 100644 --- a/lib/wasi-types-generated/src/wasi/mod.rs +++ b/lib/wasi-types-generated/src/wasi/mod.rs @@ -105,6 +105,64 @@ unsafe impl ValueType for Event { } } +unsafe impl ValueType for Tty { + 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)*) + std::mem::size_of_val(&self.$($f)*) + }; + } + macro_rules! zero { + ($start:expr, $end:expr) => { + for i in $start..$end { + bytes[i] = MaybeUninit::new(0); + } + }; + } + + self.cols + .zero_padding_bytes(&mut bytes[field!(cols)..field_end!(cols)]); + zero!(field_end!(cols), field!(rows)); + + self.rows + .zero_padding_bytes(&mut bytes[field!(rows)..field_end!(rows)]); + zero!(field_end!(rows), field!(width)); + + self.width + .zero_padding_bytes(&mut bytes[field!(width)..field_end!(width)]); + zero!(field_end!(width), field!(height)); + + self.height + .zero_padding_bytes(&mut bytes[field!(height)..field_end!(height)]); + zero!(field_end!(height), field!(stdin_tty)); + + self.stdin_tty + .zero_padding_bytes(&mut bytes[field!(stdin_tty)..field_end!(stdin_tty)]); + zero!(field_end!(stdin_tty), field!(stdout_tty)); + + self.stdout_tty + .zero_padding_bytes(&mut bytes[field!(stdout_tty)..field_end!(stdout_tty)]); + zero!(field_end!(stdout_tty), field!(stderr_tty)); + + self.stderr_tty + .zero_padding_bytes(&mut bytes[field!(stderr_tty)..field_end!(stderr_tty)]); + zero!(field_end!(stderr_tty), field!(echo)); + + self.echo + .zero_padding_bytes(&mut bytes[field!(echo)..field_end!(echo)]); + zero!(field_end!(echo), field!(line_buffered)); + + self.line_buffered + .zero_padding_bytes(&mut bytes[field!(line_buffered)..field_end!(line_buffered)]); + zero!(field_end!(line_buffered), std::mem::size_of_val(self)); + } +} + // TODO: if necessary, must be implemented in wit-bindgen unsafe impl ValueType for Eventtype { #[inline] diff --git a/lib/wasi-types-generated/wit/wasi.wit b/lib/wasi-types-generated/wit/wasi.wit index 97a71f54faa..28e52050878 100644 --- a/lib/wasi-types-generated/wit/wasi.wit +++ b/lib/wasi-types-generated/wit/wasi.wit @@ -20,6 +20,7 @@ expose-types-dummy-func: func( snapshot0-linkcount: snapshot0-linkcount, filestat: filestat, snapshot0-filestat: snapshot0-filestat, + tty: tty, ) @@ -794,3 +795,15 @@ enum whence { 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, +} diff --git a/lib/wasi-types/src/io.rs b/lib/wasi-types/src/io.rs index 2c4701e550e..9f695073062 100644 --- a/lib/wasi-types/src/io.rs +++ b/lib/wasi-types/src/io.rs @@ -26,20 +26,6 @@ pub struct __wasi_iovec_t { 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 { diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 23ef9a7ced8..6f542bece7b 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -28,7 +28,7 @@ use self::types::{ EventFdReadwrite, Eventrwflags, Eventtype, Fd as WasiFd, Fdflags, Fdstat, Filesize, Filestat, Filetype, Fstflags, Linkcount, Rights, Snapshot0Clockid, Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, SubscriptionEnum, SubscriptionFsReadwrite, - Timestamp, Whence, + Timestamp, Tty, Whence, }, *, }; @@ -3321,37 +3321,22 @@ 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>, + 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); @@ -3364,7 +3349,7 @@ pub fn tty_get( /// Updates the properties of the rect pub fn tty_set( ctx: FunctionEnvMut<'_, WasiEnv>, - tty_state: WasmPtr<__wasi_tty_t, M>, + tty_state: WasmPtr, ) -> Errno { debug!("wasi::tty_set"); @@ -3376,31 +3361,11 @@ 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 Errno::Inval, - }, - stdout_tty: match state.stdout_tty { - __WASI_BOOL_FALSE => false, - __WASI_BOOL_TRUE => true, - _ => return Errno::Inval, - }, - stderr_tty: match state.stderr_tty { - __WASI_BOOL_FALSE => false, - __WASI_BOOL_TRUE => true, - _ => return Errno::Inval, - }, - echo: match state.echo { - __WASI_BOOL_FALSE => false, - __WASI_BOOL_TRUE => true, - _ => return Errno::Inval, - }, - line_buffered: match state.line_buffered { - __WASI_BOOL_FALSE => false, - __WASI_BOOL_TRUE => true, - _ => return Errno::Inval, - }, + 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); diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index 7fab2a1c410..49442e62734 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -5,7 +5,7 @@ use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ Addressfamily, Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Filesize, Filestat, Fstflags, Rights, Sockoption, Sockstatus, Socktype, Streamsecurity, - Subscription, Timestamp, Whence, + Subscription, Timestamp, Tty, Whence, }; type MemoryType = Memory32; @@ -428,17 +428,11 @@ pub(crate) fn fd_pipe( super::fd_pipe::(ctx, ro_fd1, ro_fd2) } -pub(crate) fn tty_get( - ctx: FunctionEnvMut, - tty_state: WasmPtr<__wasi_tty_t, MemoryType>, -) -> Errno { +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>, -) -> Errno { +pub(crate) fn tty_set(ctx: FunctionEnvMut, tty_state: WasmPtr) -> Errno { super::tty_set::(ctx, tty_state) } diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index 51ae191b7e5..183fb25cbd0 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -5,7 +5,7 @@ use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ Addressfamily, Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Filesize, Filestat, Fstflags, Rights, Sockoption, Sockstatus, Socktype, Streamsecurity, - Subscription, Timestamp, Whence, + Subscription, Timestamp, Tty, Whence, }; type MemoryType = Memory64; @@ -428,17 +428,11 @@ pub(crate) fn fd_pipe( super::fd_pipe::(ctx, ro_fd1, ro_fd2) } -pub(crate) fn tty_get( - ctx: FunctionEnvMut, - tty_state: WasmPtr<__wasi_tty_t, MemoryType>, -) -> Errno { +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>, -) -> Errno { +pub(crate) fn tty_set(ctx: FunctionEnvMut, tty_state: WasmPtr) -> Errno { super::tty_set::(ctx, tty_state) } From 7aacc7ab1572fd864ae3eab9411c044db7d81be1 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Thu, 25 Aug 2022 22:07:34 +0200 Subject: [PATCH 39/84] Tid + Pid --- lib/wasi-types-generated/src/wasi/bindings.rs | 10 +++++-- lib/wasi-types-generated/wit/wasi.wit | 5 ++++ lib/wasi-types/src/file.rs | 3 --- lib/wasi/src/syscalls/mod.rs | 26 +++++++------------ lib/wasi/src/syscalls/wasix32.rs | 21 +++++---------- lib/wasi/src/syscalls/wasix64.rs | 21 +++++---------- 6 files changed, 35 insertions(+), 51 deletions(-) diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index 88624c9e961..8ec7e7e9370 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -19,6 +19,8 @@ pub mod wasi { 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)] @@ -1514,10 +1516,10 @@ pub mod wasi { }) } /// Dummy function to expose types into generated code - pub fn expose_types_dummy_func(&self, store: &mut wasmer::Store,fd: Fd,dirent: Dirent,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,)-> Result<(), wasmer::RuntimeError> { + pub fn expose_types_dummy_func(&self, store: &mut wasmer::Store,fd: Fd,dirent: Dirent,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,tid: Tid,pid: Pid,)-> Result<(), wasmer::RuntimeError> { let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; let _memory = &self.memory; - let ptr0 = func_canonical_abi_realloc.call(store, 0, 0, 8, 464)?; + let ptr0 = func_canonical_abi_realloc.call(store, 0, 0, 8, 472)?; let _memory_view = _memory.view(&store); unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 0, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(fd)))?; let Dirent{ d_next:d_next1, d_ino:d_ino1, d_type:d_type1, d_namlen:d_namlen1, } = dirent; @@ -1759,6 +1761,10 @@ pub mod wasi { unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 459, wit_bindgen_wasmer::rt::as_i32(match echo31 { true => 1, false => 0 }) as u8)?; let _memory_view = _memory.view(&store); unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 460, wit_bindgen_wasmer::rt::as_i32(match line_buffered31 { true => 1, false => 0 }) as u8)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 464, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(tid)))?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 468, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(pid)))?; self.func_expose_types_dummy_func.call(store, ptr0, )?; Ok(()) } diff --git a/lib/wasi-types-generated/wit/wasi.wit b/lib/wasi-types-generated/wit/wasi.wit index 28e52050878..019d3bf0184 100644 --- a/lib/wasi-types-generated/wit/wasi.wit +++ b/lib/wasi-types-generated/wit/wasi.wit @@ -21,6 +21,8 @@ expose-types-dummy-func: func( filestat: filestat, snapshot0-filestat: snapshot0-filestat, tty: tty, + tid: tid, + pid: pid, ) @@ -63,6 +65,9 @@ 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 diff --git a/lib/wasi-types/src/file.rs b/lib/wasi-types/src/file.rs index 16d9fbb05ca..f2d75d68062 100644 --- a/lib/wasi-types/src/file.rs +++ b/lib/wasi-types/src/file.rs @@ -10,9 +10,6 @@ pub const __WASI_STDIN_FILENO: Fd = 0; pub const __WASI_STDOUT_FILENO: Fd = 1; pub const __WASI_STDERR_FILENO: Fd = 2; -pub type __wasi_pid_t = u32; -pub type __wasi_tid_t = u32; - pub type __wasi_eventfdflags = u16; pub const __WASI_EVENTFDFLAGS_SEMAPHORE: __wasi_eventfdflags = 1 << 0; diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 6f542bece7b..528569b8b3d 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -26,9 +26,9 @@ use self::types::{ wasi::{ Addressfamily, Advice, BusErrno, Clockid, Dircookie, Dirent, Errno, Event, EventEnum, EventFdReadwrite, Eventrwflags, Eventtype, Fd as WasiFd, Fdflags, Fdstat, Filesize, - Filestat, Filetype, Fstflags, Linkcount, Rights, Snapshot0Clockid, Sockoption, Sockstatus, - Socktype, Streamsecurity, Subscription, SubscriptionEnum, SubscriptionFsReadwrite, - Timestamp, Tty, Whence, + Filestat, Filetype, Fstflags, Linkcount, Pid, Rights, Snapshot0Clockid, Sockoption, + Sockstatus, Socktype, Streamsecurity, Subscription, SubscriptionEnum, + SubscriptionFsReadwrite, Tid, Timestamp, Tty, Whence, }, *, }; @@ -3456,7 +3456,7 @@ pub fn thread_spawn( method_len: M::Offset, user_data: u64, reactor: __wasi_bool_t, - ret_tid: WasmPtr<__wasi_tid_t, M>, + ret_tid: WasmPtr, ) -> Errno { debug!("wasi::thread_spawn"); let env = ctx.data(); @@ -3525,7 +3525,7 @@ pub fn thread_spawn( })); id }; - let child: __wasi_tid_t = child.into(); + let child: Tid = child.into(); wasi_try_mem!(ret_tid.write(&memory, child)); Errno::Success @@ -3554,12 +3554,12 @@ pub fn thread_sleep( /// (threads indices are sequencial from zero) pub fn thread_id( ctx: FunctionEnvMut<'_, WasiEnv>, - ret_tid: WasmPtr<__wasi_tid_t, M>, + 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)); Errno::Success @@ -3572,10 +3572,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 { +pub fn thread_join(ctx: FunctionEnvMut<'_, WasiEnv>, tid: Tid) -> Result { debug!("wasi::thread_join"); let env = ctx.data(); @@ -3619,17 +3616,14 @@ pub fn thread_parallelism( /// ### `getpid()` /// Returns the handle of the current process -pub fn getpid( - ctx: FunctionEnvMut<'_, WasiEnv>, - ret_pid: WasmPtr<__wasi_pid_t, M>, -) -> Errno { +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_try_mem!(ret_pid.write(&memory, pid as Pid)); Errno::Success } else { Errno::Notsup diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index 49442e62734..68ead9c1de2 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -4,8 +4,8 @@ use wasmer::{FunctionEnvMut, Memory, Memory32, MemorySize, StoreMut, WasmPtr, Wa use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ Addressfamily, Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, - Filesize, Filestat, Fstflags, Rights, Sockoption, Sockstatus, Socktype, Streamsecurity, - Subscription, Timestamp, Tty, Whence, + Filesize, Filestat, Fstflags, Pid, Rights, Sockoption, Sockstatus, Socktype, Streamsecurity, + Subscription, Tid, Timestamp, Tty, Whence, }; type MemoryType = Memory32; @@ -458,7 +458,7 @@ pub(crate) fn thread_spawn( method_len: MemoryOffset, user_data: u64, reactor: __wasi_bool_t, - ret_tid: WasmPtr<__wasi_tid_t, MemoryType>, + ret_tid: WasmPtr, ) -> Errno { super::thread_spawn::(ctx, method, method_len, user_data, reactor, ret_tid) } @@ -470,17 +470,11 @@ pub(crate) fn thread_sleep( super::thread_sleep(ctx, duration) } -pub(crate) fn thread_id( - ctx: FunctionEnvMut, - ret_tid: WasmPtr<__wasi_tid_t, MemoryType>, -) -> Errno { +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 { +pub(crate) fn thread_join(ctx: FunctionEnvMut, tid: Tid) -> Result { super::thread_join(ctx, tid) } @@ -502,10 +496,7 @@ pub(crate) fn sched_yield(ctx: FunctionEnvMut) -> Result, - ret_pid: WasmPtr<__wasi_pid_t, MemoryType>, -) -> Errno { +pub(crate) fn getpid(ctx: FunctionEnvMut, ret_pid: WasmPtr) -> Errno { super::getpid::(ctx, ret_pid) } diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index 183fb25cbd0..52ab6a3303d 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -4,8 +4,8 @@ use wasmer::{FunctionEnvMut, Memory, Memory64, MemorySize, StoreMut, WasmPtr, Wa use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ Addressfamily, Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, - Filesize, Filestat, Fstflags, Rights, Sockoption, Sockstatus, Socktype, Streamsecurity, - Subscription, Timestamp, Tty, Whence, + Filesize, Filestat, Fstflags, Pid, Rights, Sockoption, Sockstatus, Socktype, Streamsecurity, + Subscription, Tid, Timestamp, Tty, Whence, }; type MemoryType = Memory64; @@ -458,7 +458,7 @@ pub(crate) fn thread_spawn( method_len: MemoryOffset, user_data: u64, reactor: __wasi_bool_t, - ret_tid: WasmPtr<__wasi_tid_t, MemoryType>, + ret_tid: WasmPtr, ) -> Errno { super::thread_spawn::(ctx, method, method_len, user_data, reactor, ret_tid) } @@ -470,17 +470,11 @@ pub(crate) fn thread_sleep( super::thread_sleep(ctx, duration) } -pub(crate) fn thread_id( - ctx: FunctionEnvMut, - ret_tid: WasmPtr<__wasi_tid_t, MemoryType>, -) -> Errno { +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 { +pub(crate) fn thread_join(ctx: FunctionEnvMut, tid: Tid) -> Result { super::thread_join(ctx, tid) } @@ -502,10 +496,7 @@ pub(crate) fn sched_yield(ctx: FunctionEnvMut) -> Result, - ret_pid: WasmPtr<__wasi_pid_t, MemoryType>, -) -> Errno { +pub(crate) fn getpid(ctx: FunctionEnvMut, ret_pid: WasmPtr) -> Errno { super::getpid::(ctx, ret_pid) } From 5ba7615daf01478731be5234b7bb342783d7359c Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Fri, 26 Aug 2022 10:38:44 +0200 Subject: [PATCH 40/84] WIP, Temporary: reference wit-bindgen silwol/wasi-types-generation git branch --- Cargo.lock | 215 +++++++++++++++++++++------- lib/wasi-types-generated/Cargo.toml | 5 +- 2 files changed, 168 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 67d1c0ddede..f0233359211 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2983,13 +2983,35 @@ dependencies = [ "tracing", "wasm-bindgen", "wasm-bindgen-test", - "wasmer-compiler", - "wasmer-compiler-cranelift", + "wasmer-compiler 3.0.0-beta", + "wasmer-compiler-cranelift 3.0.0-beta", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", - "wasmer-derive", - "wasmer-types", - "wasmer-vm", + "wasmer-derive 3.0.0-beta", + "wasmer-types 3.0.0-beta", + "wasmer-vm 3.0.0-beta", + "wasmparser 0.83.0", + "wat", + "winapi", +] + +[[package]] +name = "wasmer" +version = "3.0.0-beta" +source = "git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation#7aacc7ab1572fd864ae3eab9411c044db7d81be1" +dependencies = [ + "cfg-if 1.0.0", + "indexmap", + "js-sys", + "more-asserts", + "target-lexicon 0.12.4", + "thiserror", + "wasm-bindgen", + "wasmer-compiler 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation)", + "wasmer-compiler-cranelift 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation)", + "wasmer-derive 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation)", + "wasmer-types 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation)", + "wasmer-vm 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation)", "wasmparser 0.83.0", "wat", "winapi", @@ -3002,9 +3024,9 @@ dependencies = [ "anyhow", "libfuzzer-sys", "wasm-smith", - "wasmer", - "wasmer-compiler", - "wasmer-compiler-cranelift", + "wasmer 3.0.0-beta", + "wasmer-compiler 3.0.0-beta", + "wasmer-compiler-cranelift 3.0.0-beta", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-middlewares", @@ -3025,14 +3047,14 @@ dependencies = [ "paste", "thiserror", "typetag", - "wasmer", - "wasmer-compiler", - "wasmer-compiler-cranelift", + "wasmer 3.0.0-beta", + "wasmer-compiler 3.0.0-beta", + "wasmer-compiler-cranelift 3.0.0-beta", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-emscripten", "wasmer-middlewares", - "wasmer-types", + "wasmer-types 3.0.0-beta", "wasmer-wasi", ] @@ -3046,7 +3068,7 @@ dependencies = [ "rand", "tempfile", "thiserror", - "wasmer", + "wasmer 3.0.0-beta", "wasmer-compiler-singlepass", ] @@ -3069,17 +3091,17 @@ dependencies = [ "target-lexicon 0.12.4", "tempfile", "unix_mode", - "wasmer", + "wasmer 3.0.0-beta", "wasmer-cache", - "wasmer-compiler", - "wasmer-compiler-cranelift", + "wasmer-compiler 3.0.0-beta", + "wasmer-compiler-cranelift 3.0.0-beta", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-emscripten", "wasmer-object", - "wasmer-types", + "wasmer-types 3.0.0-beta", "wasmer-vfs", - "wasmer-vm", + "wasmer-vm 3.0.0-beta", "wasmer-wasi", "wasmer-wasi-experimental-io-devices", "wasmer-wast", @@ -3105,8 +3127,31 @@ dependencies = [ "smallvec", "thiserror", "wasmer-object", - "wasmer-types", - "wasmer-vm", + "wasmer-types 3.0.0-beta", + "wasmer-vm 3.0.0-beta", + "wasmparser 0.83.0", + "winapi", +] + +[[package]] +name = "wasmer-compiler" +version = "3.0.0-beta" +source = "git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation#7aacc7ab1572fd864ae3eab9411c044db7d81be1" +dependencies = [ + "backtrace", + "cfg-if 1.0.0", + "enum-iterator", + "enumset", + "lazy_static", + "leb128", + "memmap2", + "more-asserts", + "region", + "rustc-demangle", + "smallvec", + "thiserror", + "wasmer-types 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation)", + "wasmer-vm 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation)", "wasmparser 0.83.0", "winapi", ] @@ -3127,10 +3172,10 @@ dependencies = [ "target-lexicon 0.12.4", "tempfile", "unix_mode", - "wasmer-compiler", - "wasmer-compiler-cranelift", + "wasmer-compiler 3.0.0-beta", + "wasmer-compiler-cranelift 3.0.0-beta", "wasmer-compiler-singlepass", - "wasmer-types", + "wasmer-types 3.0.0-beta", ] [[package]] @@ -3148,8 +3193,26 @@ dependencies = [ "smallvec", "target-lexicon 0.12.4", "tracing", - "wasmer-compiler", - "wasmer-types", + "wasmer-compiler 3.0.0-beta", + "wasmer-types 3.0.0-beta", +] + +[[package]] +name = "wasmer-compiler-cranelift" +version = "3.0.0-beta" +source = "git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation#7aacc7ab1572fd864ae3eab9411c044db7d81be1" +dependencies = [ + "cranelift-codegen", + "cranelift-entity", + "cranelift-frontend", + "gimli", + "more-asserts", + "rayon", + "smallvec", + "target-lexicon 0.12.4", + "tracing", + "wasmer-compiler 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation)", + "wasmer-types 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation)", ] [[package]] @@ -3169,9 +3232,9 @@ dependencies = [ "semver 1.0.13", "smallvec", "target-lexicon 0.12.4", - "wasmer-compiler", - "wasmer-types", - "wasmer-vm", + "wasmer-compiler 3.0.0-beta", + "wasmer-types 3.0.0-beta", + "wasmer-vm 3.0.0-beta", ] [[package]] @@ -3188,8 +3251,8 @@ dependencies = [ "rayon", "smallvec", "target-lexicon 0.12.4", - "wasmer-compiler", - "wasmer-types", + "wasmer-compiler 3.0.0-beta", + "wasmer-types 3.0.0-beta", ] [[package]] @@ -3201,7 +3264,18 @@ dependencies = [ "proc-macro2", "quote", "syn", - "wasmer", + "wasmer 3.0.0-beta", +] + +[[package]] +name = "wasmer-derive" +version = "3.0.0-beta" +source = "git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation#7aacc7ab1572fd864ae3eab9411c044db7d81be1" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -3214,8 +3288,8 @@ dependencies = [ "libc", "log", "time", - "wasmer", - "wasmer-types", + "wasmer 3.0.0-beta", + "wasmer-types 3.0.0-beta", ] [[package]] @@ -3235,9 +3309,9 @@ version = "3.0.0-beta" name = "wasmer-middlewares" version = "3.0.0-beta" dependencies = [ - "wasmer", - "wasmer-types", - "wasmer-vm", + "wasmer 3.0.0-beta", + "wasmer-types 3.0.0-beta", + "wasmer-vm 3.0.0-beta", ] [[package]] @@ -3246,7 +3320,7 @@ version = "3.0.0-beta" dependencies = [ "object 0.28.4", "thiserror", - "wasmer-types", + "wasmer-types 3.0.0-beta", ] [[package]] @@ -3264,6 +3338,20 @@ dependencies = [ "thiserror", ] +[[package]] +name = "wasmer-types" +version = "3.0.0-beta" +source = "git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation#7aacc7ab1572fd864ae3eab9411c044db7d81be1" +dependencies = [ + "enum-iterator", + "enumset", + "indexmap", + "more-asserts", + "rkyv", + "target-lexicon 0.12.4", + "thiserror", +] + [[package]] name = "wasmer-vbus" version = "3.0.0-beta" @@ -3307,7 +3395,30 @@ dependencies = [ "scopeguard", "serde", "thiserror", - "wasmer-types", + "wasmer-types 3.0.0-beta", + "winapi", +] + +[[package]] +name = "wasmer-vm" +version = "3.0.0-beta" +source = "git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation#7aacc7ab1572fd864ae3eab9411c044db7d81be1" +dependencies = [ + "backtrace", + "cc", + "cfg-if 1.0.0", + "corosensei", + "enum-iterator", + "indexmap", + "lazy_static", + "libc", + "mach", + "memoffset", + "more-asserts", + "region", + "scopeguard", + "thiserror", + "wasmer-types 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation)", "winapi", ] @@ -3343,7 +3454,7 @@ dependencies = [ "typetag", "wasm-bindgen", "wasm-bindgen-test", - "wasmer", + "wasmer 3.0.0-beta", "wasmer-vbus", "wasmer-vfs", "wasmer-vnet", @@ -3383,8 +3494,8 @@ dependencies = [ "byteorder", "serde", "time", - "wasmer-derive", - "wasmer-types", + "wasmer-derive 3.0.0-beta", + "wasmer-types 3.0.0-beta", "wasmer-wasi-types-generated", ] @@ -3392,8 +3503,8 @@ dependencies = [ name = "wasmer-wasi-types-generated" version = "3.0.0-beta" dependencies = [ - "wasmer-derive", - "wasmer-types", + "wasmer-derive 3.0.0-beta", + "wasmer-types 3.0.0-beta", "wit-bindgen-wasmer", ] @@ -3405,7 +3516,7 @@ dependencies = [ "serde", "tempfile", "thiserror", - "wasmer", + "wasmer 3.0.0-beta", "wasmer-vfs", "wasmer-wasi", "wast 38.0.1", @@ -3430,15 +3541,15 @@ dependencies = [ "tracing", "tracing-subscriber", "wasi-test-generator", - "wasmer", + "wasmer 3.0.0-beta", "wasmer-cache", - "wasmer-compiler", - "wasmer-compiler-cranelift", + "wasmer-compiler 3.0.0-beta", + "wasmer-compiler-cranelift 3.0.0-beta", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-emscripten", "wasmer-middlewares", - "wasmer-types", + "wasmer-types 3.0.0-beta", "wasmer-wasi", "wasmer-wast", ] @@ -3735,6 +3846,7 @@ checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" [[package]] name = "wit-bindgen-gen-core" version = "0.1.0" +source = "git+https://github.com/wasmerio/wit-bindgen.git?branch=silwol/wasi-types-generation#9c3d3ae54d3db0a24ee473c1c172e1070efbd3d5" dependencies = [ "anyhow", "wit-parser", @@ -3743,6 +3855,7 @@ dependencies = [ [[package]] name = "wit-bindgen-gen-rust" version = "0.1.0" +source = "git+https://github.com/wasmerio/wit-bindgen.git?branch=silwol/wasi-types-generation#9c3d3ae54d3db0a24ee473c1c172e1070efbd3d5" dependencies = [ "heck 0.3.3", "wit-bindgen-gen-core", @@ -3751,6 +3864,7 @@ dependencies = [ [[package]] name = "wit-bindgen-gen-wasmer" version = "0.1.0" +source = "git+https://github.com/wasmerio/wit-bindgen.git?branch=silwol/wasi-types-generation#9c3d3ae54d3db0a24ee473c1c172e1070efbd3d5" dependencies = [ "heck 0.3.3", "wit-bindgen-gen-core", @@ -3760,18 +3874,20 @@ dependencies = [ [[package]] name = "wit-bindgen-wasmer" version = "0.1.0" +source = "git+https://github.com/wasmerio/wit-bindgen.git?branch=silwol/wasi-types-generation#9c3d3ae54d3db0a24ee473c1c172e1070efbd3d5" dependencies = [ "anyhow", "bitflags", "once_cell", "thiserror", - "wasmer", + "wasmer 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation)", "wit-bindgen-wasmer-impl", ] [[package]] name = "wit-bindgen-wasmer-impl" version = "0.1.0" +source = "git+https://github.com/wasmerio/wit-bindgen.git?branch=silwol/wasi-types-generation#9c3d3ae54d3db0a24ee473c1c172e1070efbd3d5" dependencies = [ "proc-macro2", "syn", @@ -3782,6 +3898,7 @@ dependencies = [ [[package]] name = "wit-parser" version = "0.1.0" +source = "git+https://github.com/wasmerio/wit-bindgen.git?branch=silwol/wasi-types-generation#9c3d3ae54d3db0a24ee473c1c172e1070efbd3d5" dependencies = [ "anyhow", "id-arena", diff --git a/lib/wasi-types-generated/Cargo.toml b/lib/wasi-types-generated/Cargo.toml index d776d7ae028..74e0418dd04 100644 --- a/lib/wasi-types-generated/Cargo.toml +++ b/lib/wasi-types-generated/Cargo.toml @@ -10,10 +10,9 @@ wasmer-derive = { path = "../derive", version = "=3.0.0-beta" } wasmer-types = { path = "../types", version = "=3.0.0-beta" } [dependencies.wit-bindgen-wasmer] -path = "/home/silwol/Projects/wasmerio/wit-bindgen/crates/wasmer" default-features = false -#git = "https://github.com/wasmerio/wit-bindgen.git" -#branch = "wasmer" +git = "https://github.com/wasmerio/wit-bindgen.git" +branch = "silwol/wasi-types-generation" [features] js = ["wit-bindgen-wasmer/js"] From 73137f5e26205effcc6a337d8bb618871d9f3f2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 5 Sep 2022 13:56:03 +0200 Subject: [PATCH 41/84] Add wit-clean files --- lib/wasi-types-generated/regenerate.sh | 13 +- .../wit-clean/typenames.wit | 814 ++++++++++++++++++ .../wit-clean/wasi_unstable.wit | 510 +++++++++++ 3 files changed, 1328 insertions(+), 9 deletions(-) create mode 100644 lib/wasi-types-generated/wit-clean/typenames.wit create mode 100644 lib/wasi-types-generated/wit-clean/wasi_unstable.wit diff --git a/lib/wasi-types-generated/regenerate.sh b/lib/wasi-types-generated/regenerate.sh index fa266c371f8..a0fa78e636c 100755 --- a/lib/wasi-types-generated/regenerate.sh +++ b/lib/wasi-types-generated/regenerate.sh @@ -6,14 +6,9 @@ rm -f \ "$BASEDIR"/src/bindings.rs \ "$BASEDIR"/src/*/bindings.rs -wit-bindgen wasmer \ - --import \ - "$BASEDIR"/wit/wasi.wit \ - --out-dir "$BASEDIR"/src/wasi +cat "$BASEDIR"/wit-clean/typenames.wit "$BASEDIR"/wit-clean/wasi_unstable.wit > "$BASEDIR"/wit-clean/output.wit -wit-bindgen wasmer \ +wit-bindgen rust-wasm \ --import \ - "$BASEDIR"/wit/wasi-filesystem.wit \ - --out-dir "$BASEDIR"/src/wasi_filesystem - -#wit-bindgen rust-wasm --import wit/wasi-snapshot0.wit wit/wasi-filesystem.wit --out-dir . + "$BASEDIR"/wit-clean/output.wit \ + --out-dir "$BASEDIR"/src/wasi diff --git a/lib/wasi-types-generated/wit-clean/typenames.wit b/lib/wasi-types-generated/wit-clean/typenames.wit new file mode 100644 index 00000000000..019d3bf0184 --- /dev/null +++ b/lib/wasi-types-generated/wit-clean/typenames.wit @@ -0,0 +1,814 @@ +// 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 + + + +/// Dummy function to expose types into generated code +expose-types-dummy-func: func( + fd: fd, + dirent: dirent, + event-enum: event-enum, + event: event, + fdstat: fdstat, + subscription-clock: subscription-clock, + snapshot0-subscription-clock: snapshot0-subscription-clock, + subscription: subscription, + snapshot0-subscription: snapshot0-subscription, + device: device, + linkcount: linkcount, + snapshot0-linkcount: snapshot0-linkcount, + filestat: filestat, + snapshot0-filestat: snapshot0-filestat, + tty: tty, + tid: tid, + pid: pid, +) + + + +/// 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. +flags fstflags { + // TODO: wit appears to not have support for flags repr + //(@witx repr u16) + + /// 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. +flags lookup { + // TODO: wit appears to not have support for flags repr + //(@witx repr u32) + + /// As long as the resolved path corresponds to a symbolic link, it is expanded. + symlink-follow, +} + +/// Open flags used by `path_open`. +flags oflags { + // TODO: wit appears to not have support for flags repr + //(@witx repr u16) + + /// 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, +} diff --git a/lib/wasi-types-generated/wit-clean/wasi_unstable.wit b/lib/wasi-types-generated/wit-clean/wasi_unstable.wit new file mode 100644 index 00000000000..2330a054ba6 --- /dev/null +++ b/lib/wasi-types-generated/wit-clean/wasi_unstable.wit @@ -0,0 +1,510 @@ +// 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))) + ) +) From a4e7e89f18f65ded6efabbb068d2ff00cae430ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 5 Sep 2022 13:57:16 +0200 Subject: [PATCH 42/84] Update Cargo.lock --- Cargo.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e62aa8d0805..5a22999ce98 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1181,12 +1181,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" -[[package]] -name = "id-arena" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" - [[package]] name = "iana-time-zone" version = "0.1.46" @@ -1200,6 +1194,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" From 00503ad0e1eddc774cd0a2d176d60d5a551f8412 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 5 Sep 2022 14:35:01 +0200 Subject: [PATCH 43/84] Move "wasmer" dependency out of wasi-types-generated crate Previously, this crate would depend on wit_bindgen_wasmer::{$crate}, not $crate directly, which causes import errors when migrating from "wit-bindgen wasmer" to "wit-bindgen rust-wasm". --- Cargo.lock | 653 +++++--------- lib/wasi-experimental-io-devices/Cargo.toml | 4 +- lib/wasi-types-generated/Cargo.toml | 15 +- lib/wasi-types-generated/src/lib.rs | 1 - lib/wasi-types-generated/src/wasi/bindings.rs | 672 +++++++-------- lib/wasi-types-generated/src/wasi/mod.rs | 149 ++-- .../src/wasi_filesystem/bindings.rs | 814 ------------------ .../src/wasi_filesystem/mod.rs | 2 - .../{wit/wasi.wit => wit-clean/output.wit} | 512 +++++++++++ .../wit-clean/wasi_unstable.wit | 2 + .../wit/wasi-filesystem.wit | 626 -------------- .../wit/wasi-io-typenames.wit | 201 ----- .../wit/wasi-snapshot0.wit | 249 ------ 13 files changed, 1117 insertions(+), 2783 deletions(-) delete mode 100644 lib/wasi-types-generated/src/wasi_filesystem/bindings.rs delete mode 100644 lib/wasi-types-generated/src/wasi_filesystem/mod.rs rename lib/wasi-types-generated/{wit/wasi.wit => wit-clean/output.wit} (54%) delete mode 100644 lib/wasi-types-generated/wit/wasi-filesystem.wit delete mode 100644 lib/wasi-types-generated/wit/wasi-io-typenames.wit delete mode 100644 lib/wasi-types-generated/wit/wasi-snapshot0.wit diff --git a/Cargo.lock b/Cargo.lock index 5a22999ce98..98b61e6da43 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -149,34 +149,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 +257,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6358dedf60f4d9b8db43ad187391afe959746101346fe51bb978126bec61dfb" dependencies = [ "clap 3.2.17", - "heck 0.4.0", + "heck", "indexmap", "log", "proc-macro2", @@ -298,15 +275,6 @@ version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" -[[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" @@ -333,30 +301,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]] @@ -371,7 +324,7 @@ dependencies = [ "clap_lex", "indexmap", "once_cell", - "strsim 0.10.0", + "strsim", "termcolor", "textwrap 0.15.0", ] @@ -382,7 +335,7 @@ version = "3.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13547f7012c01ab4a0e8f8967730ada8f9fdf419e8b6c792788f39cf4e46eefa" dependencies = [ - "heck 0.4.0", + "heck", "proc-macro-error", "proc-macro2", "quote", @@ -841,6 +794,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" @@ -926,19 +888,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.22" @@ -1010,6 +959,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" @@ -1133,15 +1171,6 @@ 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" @@ -1175,12 +1204,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.46" @@ -1194,12 +1217,6 @@ 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" @@ -1278,6 +1295,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]] @@ -1326,12 +1346,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" @@ -1441,21 +1455,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]] @@ -1490,25 +1511,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]] @@ -1650,12 +1674,6 @@ version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9423e2b32f7a043629287a536f21951e8c6a82482d0acb1eeebfc90bc2225b22" -[[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.0" @@ -1672,6 +1690,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" @@ -1813,17 +1837,6 @@ 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" @@ -2047,12 +2060,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" @@ -2314,12 +2321,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" @@ -2411,12 +2412,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" @@ -2616,21 +2611,6 @@ 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" @@ -2765,33 +2745,12 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" -[[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.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" - [[package]] name = "unicode-width" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" -[[package]] -name = "unicode-xid" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" - [[package]] name = "unix_mode" version = "0.1.3" @@ -2804,12 +2763,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" @@ -2996,35 +2949,13 @@ dependencies = [ "tracing", "wasm-bindgen", "wasm-bindgen-test", - "wasmer-compiler 3.0.0-beta", - "wasmer-compiler-cranelift 3.0.0-beta", + "wasmer-compiler", + "wasmer-compiler-cranelift", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", - "wasmer-derive 3.0.0-beta", - "wasmer-types 3.0.0-beta", - "wasmer-vm 3.0.0-beta", - "wasmparser 0.83.0", - "wat", - "winapi", -] - -[[package]] -name = "wasmer" -version = "3.0.0-beta" -source = "git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation#7aacc7ab1572fd864ae3eab9411c044db7d81be1" -dependencies = [ - "cfg-if 1.0.0", - "indexmap", - "js-sys", - "more-asserts", - "target-lexicon 0.12.4", - "thiserror", - "wasm-bindgen", - "wasmer-compiler 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation)", - "wasmer-compiler-cranelift 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation)", - "wasmer-derive 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation)", - "wasmer-types 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation)", - "wasmer-vm 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation)", + "wasmer-derive", + "wasmer-types", + "wasmer-vm", "wasmparser 0.83.0", "wat", "winapi", @@ -3037,9 +2968,9 @@ dependencies = [ "anyhow", "libfuzzer-sys", "wasm-smith", - "wasmer 3.0.0-beta", - "wasmer-compiler 3.0.0-beta", - "wasmer-compiler-cranelift 3.0.0-beta", + "wasmer", + "wasmer-compiler", + "wasmer-compiler-cranelift", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-middlewares", @@ -3060,14 +2991,14 @@ dependencies = [ "paste", "thiserror", "typetag", - "wasmer 3.0.0-beta", - "wasmer-compiler 3.0.0-beta", - "wasmer-compiler-cranelift 3.0.0-beta", + "wasmer", + "wasmer-compiler", + "wasmer-compiler-cranelift", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-emscripten", "wasmer-middlewares", - "wasmer-types 3.0.0-beta", + "wasmer-types", "wasmer-wasi", ] @@ -3081,7 +3012,7 @@ dependencies = [ "rand", "tempfile", "thiserror", - "wasmer 3.0.0-beta", + "wasmer", "wasmer-compiler-singlepass", ] @@ -3104,17 +3035,17 @@ dependencies = [ "target-lexicon 0.12.4", "tempfile", "unix_mode", - "wasmer 3.0.0-beta", + "wasmer", "wasmer-cache", - "wasmer-compiler 3.0.0-beta", - "wasmer-compiler-cranelift 3.0.0-beta", + "wasmer-compiler", + "wasmer-compiler-cranelift", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-emscripten", "wasmer-object", - "wasmer-types 3.0.0-beta", + "wasmer-types", "wasmer-vfs", - "wasmer-vm 3.0.0-beta", + "wasmer-vm", "wasmer-wasi", "wasmer-wasi-experimental-io-devices", "wasmer-wast", @@ -3140,31 +3071,8 @@ dependencies = [ "smallvec", "thiserror", "wasmer-object", - "wasmer-types 3.0.0-beta", - "wasmer-vm 3.0.0-beta", - "wasmparser 0.83.0", - "winapi", -] - -[[package]] -name = "wasmer-compiler" -version = "3.0.0-beta" -source = "git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation#7aacc7ab1572fd864ae3eab9411c044db7d81be1" -dependencies = [ - "backtrace", - "cfg-if 1.0.0", - "enum-iterator", - "enumset", - "lazy_static", - "leb128", - "memmap2", - "more-asserts", - "region", - "rustc-demangle", - "smallvec", - "thiserror", - "wasmer-types 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation)", - "wasmer-vm 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation)", + "wasmer-types", + "wasmer-vm", "wasmparser 0.83.0", "winapi", ] @@ -3185,10 +3093,10 @@ dependencies = [ "target-lexicon 0.12.4", "tempfile", "unix_mode", - "wasmer-compiler 3.0.0-beta", - "wasmer-compiler-cranelift 3.0.0-beta", + "wasmer-compiler", + "wasmer-compiler-cranelift", "wasmer-compiler-singlepass", - "wasmer-types 3.0.0-beta", + "wasmer-types", ] [[package]] @@ -3206,26 +3114,8 @@ dependencies = [ "smallvec", "target-lexicon 0.12.4", "tracing", - "wasmer-compiler 3.0.0-beta", - "wasmer-types 3.0.0-beta", -] - -[[package]] -name = "wasmer-compiler-cranelift" -version = "3.0.0-beta" -source = "git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation#7aacc7ab1572fd864ae3eab9411c044db7d81be1" -dependencies = [ - "cranelift-codegen", - "cranelift-entity", - "cranelift-frontend", - "gimli", - "more-asserts", - "rayon", - "smallvec", - "target-lexicon 0.12.4", - "tracing", - "wasmer-compiler 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation)", - "wasmer-types 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation)", + "wasmer-compiler", + "wasmer-types", ] [[package]] @@ -3245,9 +3135,9 @@ dependencies = [ "semver 1.0.13", "smallvec", "target-lexicon 0.12.4", - "wasmer-compiler 3.0.0-beta", - "wasmer-types 3.0.0-beta", - "wasmer-vm 3.0.0-beta", + "wasmer-compiler", + "wasmer-types", + "wasmer-vm", ] [[package]] @@ -3264,8 +3154,8 @@ dependencies = [ "rayon", "smallvec", "target-lexicon 0.12.4", - "wasmer-compiler 3.0.0-beta", - "wasmer-types 3.0.0-beta", + "wasmer-compiler", + "wasmer-types", ] [[package]] @@ -3277,18 +3167,7 @@ dependencies = [ "proc-macro2", "quote", "syn", - "wasmer 3.0.0-beta", -] - -[[package]] -name = "wasmer-derive" -version = "3.0.0-beta" -source = "git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation#7aacc7ab1572fd864ae3eab9411c044db7d81be1" -dependencies = [ - "proc-macro-error", - "proc-macro2", - "quote", - "syn", + "wasmer", ] [[package]] @@ -3301,8 +3180,8 @@ dependencies = [ "libc", "log", "time", - "wasmer 3.0.0-beta", - "wasmer-types 3.0.0-beta", + "wasmer", + "wasmer-types", ] [[package]] @@ -3322,9 +3201,9 @@ version = "3.0.0-beta" name = "wasmer-middlewares" version = "3.0.0-beta" dependencies = [ - "wasmer 3.0.0-beta", - "wasmer-types 3.0.0-beta", - "wasmer-vm 3.0.0-beta", + "wasmer", + "wasmer-types", + "wasmer-vm", ] [[package]] @@ -3333,7 +3212,7 @@ version = "3.0.0-beta" dependencies = [ "object 0.28.4", "thiserror", - "wasmer-types 3.0.0-beta", + "wasmer-types", ] [[package]] @@ -3352,20 +3231,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "wasmer-types" -version = "3.0.0-beta" -source = "git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation#7aacc7ab1572fd864ae3eab9411c044db7d81be1" -dependencies = [ - "enum-iterator", - "enumset", - "indexmap", - "more-asserts", - "rkyv", - "target-lexicon 0.12.4", - "thiserror", -] - [[package]] name = "wasmer-vbus" version = "3.0.0-beta" @@ -3405,30 +3270,7 @@ dependencies = [ "scopeguard", "serde", "thiserror", - "wasmer-types 3.0.0-beta", - "winapi", -] - -[[package]] -name = "wasmer-vm" -version = "3.0.0-beta" -source = "git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation#7aacc7ab1572fd864ae3eab9411c044db7d81be1" -dependencies = [ - "backtrace", - "cc", - "cfg-if 1.0.0", - "corosensei", - "enum-iterator", - "indexmap", - "lazy_static", - "libc", - "mach", - "memoffset", - "more-asserts", - "region", - "scopeguard", - "thiserror", - "wasmer-types 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation)", + "wasmer-types", "winapi", ] @@ -3460,7 +3302,7 @@ dependencies = [ "typetag", "wasm-bindgen", "wasm-bindgen-test", - "wasmer 3.0.0-beta", + "wasmer", "wasmer-vbus", "wasmer-vfs", "wasmer-vnet", @@ -3475,7 +3317,7 @@ name = "wasmer-wasi-experimental-io-devices" version = "3.0.0-beta" dependencies = [ "minifb", - "nix", + "nix 0.25.0", "ref_thread_local", "serde", "tracing", @@ -3500,8 +3342,8 @@ dependencies = [ "byteorder", "serde", "time", - "wasmer-derive 3.0.0-beta", - "wasmer-types 3.0.0-beta", + "wasmer-derive", + "wasmer-types", "wasmer-wasi-types-generated", ] @@ -3509,9 +3351,8 @@ dependencies = [ name = "wasmer-wasi-types-generated" version = "3.0.0-beta" dependencies = [ - "wasmer-derive 3.0.0-beta", - "wasmer-types 3.0.0-beta", - "wit-bindgen-wasmer", + "wasmer", + "wit-bindgen-rust", ] [[package]] @@ -3522,7 +3363,7 @@ dependencies = [ "serde", "tempfile", "thiserror", - "wasmer 3.0.0-beta", + "wasmer", "wasmer-vfs", "wasmer-wasi", "wast 38.0.1", @@ -3547,15 +3388,15 @@ dependencies = [ "tracing", "tracing-subscriber", "wasi-test-generator", - "wasmer 3.0.0-beta", + "wasmer", "wasmer-cache", - "wasmer-compiler 3.0.0-beta", - "wasmer-compiler-cranelift 3.0.0-beta", + "wasmer-compiler", + "wasmer-compiler-cranelift", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-emscripten", "wasmer-middlewares", - "wasmer-types 3.0.0-beta", + "wasmer-types", "wasmer-wasi", "wasmer-wast", ] @@ -3626,14 +3467,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", @@ -3641,11 +3483,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", @@ -3653,20 +3495,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", @@ -3676,9 +3518,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", @@ -3687,10 +3529,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", ] @@ -3723,15 +3567,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" @@ -3850,67 +3685,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" [[package]] -name = "wit-bindgen-gen-core" -version = "0.1.0" -source = "git+https://github.com/wasmerio/wit-bindgen.git?branch=silwol/wasi-types-generation#9c3d3ae54d3db0a24ee473c1c172e1070efbd3d5" -dependencies = [ - "anyhow", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-gen-rust" +name = "wit-bindgen-rust" version = "0.1.0" -source = "git+https://github.com/wasmerio/wit-bindgen.git?branch=silwol/wasi-types-generation#9c3d3ae54d3db0a24ee473c1c172e1070efbd3d5" +source = "git+https://github.com/wasmerio/wit-bindgen?branch=main#005a9e6d5befe4652c0e6e05578b245ab96b3cea" dependencies = [ - "heck 0.3.3", - "wit-bindgen-gen-core", -] - -[[package]] -name = "wit-bindgen-gen-wasmer" -version = "0.1.0" -source = "git+https://github.com/wasmerio/wit-bindgen.git?branch=silwol/wasi-types-generation#9c3d3ae54d3db0a24ee473c1c172e1070efbd3d5" -dependencies = [ - "heck 0.3.3", - "wit-bindgen-gen-core", - "wit-bindgen-gen-rust", -] - -[[package]] -name = "wit-bindgen-wasmer" -version = "0.1.0" -source = "git+https://github.com/wasmerio/wit-bindgen.git?branch=silwol/wasi-types-generation#9c3d3ae54d3db0a24ee473c1c172e1070efbd3d5" -dependencies = [ - "anyhow", "bitflags", - "once_cell", - "thiserror", - "wasmer 3.0.0-beta (git+https://github.com/wasmerio/wasmer.git?branch=silwol/wasi-types-generation)", - "wit-bindgen-wasmer-impl", -] - -[[package]] -name = "wit-bindgen-wasmer-impl" -version = "0.1.0" -source = "git+https://github.com/wasmerio/wit-bindgen.git?branch=silwol/wasi-types-generation#9c3d3ae54d3db0a24ee473c1c172e1070efbd3d5" -dependencies = [ - "proc-macro2", - "syn", - "wit-bindgen-gen-core", - "wit-bindgen-gen-wasmer", -] - -[[package]] -name = "wit-parser" -version = "0.1.0" -source = "git+https://github.com/wasmerio/wit-bindgen.git?branch=silwol/wasi-types-generation#9c3d3ae54d3db0a24ee473c1c172e1070efbd3d5" -dependencies = [ - "anyhow", - "id-arena", - "pulldown-cmark", - "unicode-normalization", - "unicode-xid", ] [[package]] @@ -3930,29 +3709,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/lib/wasi-experimental-io-devices/Cargo.toml b/lib/wasi-experimental-io-devices/Cargo.toml index 6f95a677291..7a5e5bf66e8 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", 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-types-generated/Cargo.toml b/lib/wasi-types-generated/Cargo.toml index 74e0418dd04..9be33fa8d19 100644 --- a/lib/wasi-types-generated/Cargo.toml +++ b/lib/wasi-types-generated/Cargo.toml @@ -6,14 +6,15 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -wasmer-derive = { path = "../derive", version = "=3.0.0-beta" } -wasmer-types = { path = "../types", version = "=3.0.0-beta" } +wasmer = { default-features = false, path = "../api", version = "3.0.0-beta" } -[dependencies.wit-bindgen-wasmer] +# this crate is called "gen-rust" on bytecodealliance/master +[dependencies.wit-bindgen-rust] default-features = false -git = "https://github.com/wasmerio/wit-bindgen.git" -branch = "silwol/wasi-types-generation" +git = "https://github.com/wasmerio/wit-bindgen" +branch = "main" +package = "wit-bindgen-rust" [features] -js = ["wit-bindgen-wasmer/js"] -sys = ["wit-bindgen-wasmer/sys"] +js = [] +sys = [] diff --git a/lib/wasi-types-generated/src/lib.rs b/lib/wasi-types-generated/src/lib.rs index 51b9aafb921..f53466fdb86 100644 --- a/lib/wasi-types-generated/src/lib.rs +++ b/lib/wasi-types-generated/src/lib.rs @@ -1,2 +1 @@ pub mod wasi; -pub mod wasi_filesystem; diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index 8ec7e7e9370..8814f04a38f 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -1,7 +1,5 @@ #[allow(clippy::all)] -pub mod wasi { - #[allow(unused_imports)] - use wit_bindgen_wasmer::{anyhow, wasmer}; +pub mod output { /// Non-negative file size or length of a region within a file. pub type Filesize = u64; /// Timestamp in nanoseconds. @@ -531,9 +529,10 @@ pub mod wasi { } impl std::error::Error for BusErrno{} - wit_bindgen_wasmer::bitflags::bitflags! { + wit_bindgen_rust::bitflags::bitflags! { /// File descriptor rights, determining which actions may be performed. - pub struct Rights: u64 {/// The right to invoke `fd_datasync`. + 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`. @@ -628,17 +627,13 @@ pub mod wasi { const SOCK_SEND_TO = 1 << 38; } } - - impl core::fmt::Display for Rights{ - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("Rights(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(())} + 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)] @@ -753,9 +748,10 @@ pub mod wasi { } } } - wit_bindgen_wasmer::bitflags::bitflags! { + 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. + 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; @@ -769,17 +765,13 @@ pub mod wasi { const SYNC = 1 << 4; } } - - impl core::fmt::Display for Fdflags{ - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("Fdflags(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(())} + 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)] @@ -798,9 +790,10 @@ pub mod wasi { 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_wasmer::bitflags::bitflags! { + wit_bindgen_rust::bitflags::bitflags! { /// Which file time attributes to adjust. - pub struct Fstflags: u8 {/// Adjust the last data access timestamp to the value stored in `filestat::atim`. + 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; @@ -810,37 +803,31 @@ pub mod wasi { const SET_MTIM_NOW = 1 << 3; } } - - impl core::fmt::Display for Fstflags{ - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("Fstflags(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(())} + impl Fstflags { + /// Convert from a raw integer, preserving any unknown bits. See + /// + pub fn from_bits_preserve(bits: u8) -> Self { + Self { bits } + } } - - wit_bindgen_wasmer::bitflags::bitflags! { + wit_bindgen_rust::bitflags::bitflags! { /// Flags determining the method of how paths are resolved. - pub struct Lookup: u8 {/// As long as the resolved path corresponds to a symbolic link, it is expanded. + pub struct Lookup: u8 { + /// As long as the resolved path corresponds to a symbolic link, it is expanded. const SYMLINK_FOLLOW = 1 << 0; } } - - impl core::fmt::Display for Lookup{ - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("Lookup(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(())} + impl Lookup { + /// Convert from a raw integer, preserving any unknown bits. See + /// + pub fn from_bits_preserve(bits: u8) -> Self { + Self { bits } + } } - - wit_bindgen_wasmer::bitflags::bitflags! { + wit_bindgen_rust::bitflags::bitflags! { /// Open flags used by `path_open`. - pub struct Oflags: u8 {/// Create file if it does not exist. + pub struct Oflags: u8 { + /// Create file if it does not exist. const CREATE = 1 << 0; /// Fail if not a directory. const DIRECTORY = 1 << 1; @@ -850,17 +837,13 @@ pub mod wasi { const TRUNC = 1 << 3; } } - - impl core::fmt::Display for Oflags{ - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("Oflags(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(())} + 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; @@ -893,10 +876,11 @@ pub mod wasi { } } } - wit_bindgen_wasmer::bitflags::bitflags! { + 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 + 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 @@ -904,17 +888,13 @@ pub mod wasi { const SUBSCRIPTION_CLOCK_ABSTIME = 1 << 0; } } - - impl core::fmt::Display for Subclockflags{ - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("Subclockflags(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(())} + 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)] @@ -969,24 +949,21 @@ pub mod wasi { } } } - wit_bindgen_wasmer::bitflags::bitflags! { + 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. + pub struct Eventrwflags: u8 { + /// The peer of this socket has closed or disconnected. const FD_READWRITE_HANGUP = 1 << 0; } } - - impl core::fmt::Display for Eventrwflags{ - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("Eventrwflags(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(())} + 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)] @@ -1094,19 +1071,6 @@ pub mod wasi { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("SubscriptionFsReadwrite").field("file-descriptor", &self.file_descriptor).finish()} } - impl wit_bindgen_wasmer::Endian for SubscriptionFsReadwrite { - fn into_le(self) -> Self { - Self { - file_descriptor: self.file_descriptor.into_le(), - } - } - fn from_le(self) -> Self { - Self { - file_descriptor: self.file_descriptor.from_le(), - } - } - } - unsafe impl wit_bindgen_wasmer::AllBytesValid for SubscriptionFsReadwrite {} #[repr(C)] #[derive(Copy, Clone)] pub struct Snapshot0Subscription { @@ -1442,336 +1406,326 @@ pub mod wasi { 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()} } - - /// Auxiliary data associated with the wasm exports. - #[derive(Default)] - pub struct WasiData { - } - - pub struct Wasi { - #[allow(dead_code)] - env: wasmer::FunctionEnv, - func_canonical_abi_realloc: wasmer::TypedFunction<(i32, i32, i32, i32), i32>, - func_expose_types_dummy_func: wasmer::TypedFunction, - memory: wasmer::Memory, - } - impl Wasi { - #[allow(unused_variables)] - - /// Adds any intrinsics, if necessary for this exported wasm - /// functionality to the `ImportObject` provided. - /// - /// This function returns the `WasiData` which needs to be - /// passed through to `Wasi::new`. - fn add_to_imports( - mut store: impl wasmer::AsStoreMut, - imports: &mut wasmer::Imports, - ) -> wasmer::FunctionEnv { - let env = wasmer::FunctionEnv::new(&mut store, WasiData::default()); - env - } - - /// Instantiates the provided `module` using the specified - /// parameters, wrapping up the result in a structure that - /// translates between wasm and the host. - /// - /// The `imports` provided will have intrinsics added to it - /// automatically, so it's not necessary to call - /// `add_to_imports` beforehand. This function will - /// instantiate the `module` otherwise using `imports`, and - /// both an instance of this structure and the underlying - /// `wasmer::Instance` will be returned. - pub fn instantiate( - mut store: impl wasmer::AsStoreMut, - module: &wasmer::Module, - imports: &mut wasmer::Imports, - ) -> anyhow::Result<(Self, wasmer::Instance)> { - let env = Self::add_to_imports(&mut store, imports); - let instance = wasmer::Instance::new( - &mut store, module, &*imports)?; - - Ok((Self::new(store, &instance, env)?, instance)) - } - - /// Low-level creation wrapper for wrapping up the exports - /// of the `instance` provided in this structure of wasm - /// exports. - /// - /// This function will extract exports from the `instance` - /// and wrap them all up in the returned structure which can - /// be used to interact with the wasm module. - pub fn new( - store: impl wasmer::AsStoreMut, - _instance: &wasmer::Instance, - env: wasmer::FunctionEnv, - ) -> Result { - let func_canonical_abi_realloc= _instance.exports.get_typed_function(&store, "canonical_abi_realloc")?; - let func_expose_types_dummy_func= _instance.exports.get_typed_function(&store, "expose-types-dummy-func")?; - let memory= _instance.exports.get_memory("memory")?.clone(); - Ok(Wasi{ - func_canonical_abi_realloc, - func_expose_types_dummy_func, - memory, - env, - }) - } - /// Dummy function to expose types into generated code - pub fn expose_types_dummy_func(&self, store: &mut wasmer::Store,fd: Fd,dirent: Dirent,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,tid: Tid,pid: Pid,)-> Result<(), wasmer::RuntimeError> { - let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; - let _memory = &self.memory; - let ptr0 = func_canonical_abi_realloc.call(store, 0, 0, 8, 472)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 0, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(fd)))?; + /// Dummy function to expose types into generated code + pub fn expose_types_dummy_func(fd: Fd,dirent: Dirent,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,tid: Tid,pid: Pid,) -> (){ + unsafe { + let ptr0 = OUTPUT_RET_AREA.0.as_mut_ptr() as i32; + *((ptr0 + 0) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd); let Dirent{ d_next:d_next1, d_ino:d_ino1, d_type:d_type1, d_namlen:d_namlen1, } = dirent; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 8, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(d_next1)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 16, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(d_ino1)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 24, wit_bindgen_wasmer::rt::as_i32(d_type1 as i32) as u8)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 28, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(d_namlen1)))?; + *((ptr0 + 8) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_next1); + *((ptr0 + 16) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_ino1); + *((ptr0 + 24) as *mut u8) = (match d_type1 { + Filetype::Unknown => 0, + Filetype::BlockDevice => 1, + Filetype::CharacterDevice => 2, + Filetype::Directory => 3, + Filetype::RegularFile => 4, + Filetype::SocketDgram => 5, + Filetype::SocketStream => 6, + Filetype::SymbolicLink => 7, + Filetype::Fifo => 8, + }) as u8; + *((ptr0 + 28) as *mut i32) = wit_bindgen_rust::rt::as_i32(d_namlen1); match event_enum { EventEnum::FdRead(e) => { - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 32, wit_bindgen_wasmer::rt::as_i32(0i32) as u8)?; + *((ptr0 + 32) as *mut u8) = (0i32) as u8; let EventFdReadwrite{ nbytes:nbytes2, flags:flags2, } = e; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 40, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(nbytes2)))?; + *((ptr0 + 40) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes2); let flags3 = flags2; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 48, wit_bindgen_wasmer::rt::as_i32((flags3.bits >> 0) as i32) as u8)?; + *((ptr0 + 48) as *mut u8) = ((flags3.bits() >> 0) as i32) as u8; + }, EventEnum::FdWrite(e) => { - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 32, wit_bindgen_wasmer::rt::as_i32(1i32) as u8)?; + *((ptr0 + 32) as *mut u8) = (1i32) as u8; let EventFdReadwrite{ nbytes:nbytes4, flags:flags4, } = e; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 40, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(nbytes4)))?; + *((ptr0 + 40) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes4); let flags5 = flags4; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 48, wit_bindgen_wasmer::rt::as_i32((flags5.bits >> 0) as i32) as u8)?; + *((ptr0 + 48) as *mut u8) = ((flags5.bits() >> 0) as i32) as u8; + }, EventEnum::Clock=> { let e = (); { - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 32, wit_bindgen_wasmer::rt::as_i32(2i32) as u8)?; + *((ptr0 + 32) as *mut u8) = (2i32) as u8; let () = e; + } } }; let Event{ userdata:userdata6, error:error6, data:data6, } = event; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 56, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(userdata6)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 64, wit_bindgen_wasmer::rt::as_i32(error6 as i32) as u8)?; + *((ptr0 + 56) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata6); + *((ptr0 + 64) as *mut u8) = (match error6 { + Errno::Success => 0, + Errno::Toobig => 1, + Errno::Access => 2, + Errno::Addrinuse => 3, + Errno::Addrnotavail => 4, + Errno::Afnosupport => 5, + Errno::Again => 6, + Errno::Already => 7, + Errno::Badf => 8, + Errno::Badmsg => 9, + Errno::Busy => 10, + Errno::Canceled => 11, + Errno::Child => 12, + Errno::Connaborted => 13, + Errno::Connrefused => 14, + Errno::Connreset => 15, + Errno::Deadlk => 16, + Errno::Destaddrreq => 17, + Errno::Dom => 18, + Errno::Dquot => 19, + Errno::Exist => 20, + Errno::Fault => 21, + Errno::Fbig => 22, + Errno::Hostunreach => 23, + Errno::Idrm => 24, + Errno::Ilseq => 25, + Errno::Inprogress => 26, + Errno::Intr => 27, + Errno::Inval => 28, + Errno::Io => 29, + Errno::Isconn => 30, + Errno::Isdir => 31, + Errno::Loop => 32, + Errno::Mfile => 33, + Errno::Mlink => 34, + Errno::Msgsize => 35, + Errno::Multihop => 36, + Errno::Nametoolong => 37, + Errno::Netdown => 38, + Errno::Netreset => 39, + Errno::Netunreach => 40, + Errno::Nfile => 41, + Errno::Nobufs => 42, + Errno::Nodev => 43, + Errno::Noent => 44, + Errno::Noexec => 45, + Errno::Nolck => 46, + Errno::Nolink => 47, + Errno::Nomem => 48, + Errno::Nomsg => 49, + Errno::Noprotoopt => 50, + Errno::Nospc => 51, + Errno::Nosys => 52, + Errno::Notconn => 53, + Errno::Notdir => 54, + Errno::Notempty => 55, + Errno::Notrecoverable => 56, + Errno::Notsock => 57, + Errno::Notsup => 58, + Errno::Notty => 59, + Errno::Nxio => 60, + Errno::Overflow => 61, + Errno::Ownerdead => 62, + Errno::Perm => 63, + Errno::Pipe => 64, + Errno::Proto => 65, + Errno::Protonosupport => 66, + Errno::Prototype => 67, + Errno::Range => 68, + Errno::Rofs => 69, + Errno::Spipe => 70, + Errno::Srch => 71, + Errno::Stale => 72, + Errno::Timedout => 73, + Errno::Txtbsy => 74, + Errno::Xdev => 75, + Errno::Notcapable => 76, + }) as u8; match data6 { EventEnum::FdRead(e) => { - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 72, wit_bindgen_wasmer::rt::as_i32(0i32) as u8)?; + *((ptr0 + 72) as *mut u8) = (0i32) as u8; let EventFdReadwrite{ nbytes:nbytes7, flags:flags7, } = e; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 80, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(nbytes7)))?; + *((ptr0 + 80) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes7); let flags8 = flags7; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 88, wit_bindgen_wasmer::rt::as_i32((flags8.bits >> 0) as i32) as u8)?; + *((ptr0 + 88) as *mut u8) = ((flags8.bits() >> 0) as i32) as u8; + }, EventEnum::FdWrite(e) => { - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 72, wit_bindgen_wasmer::rt::as_i32(1i32) as u8)?; + *((ptr0 + 72) as *mut u8) = (1i32) as u8; let EventFdReadwrite{ nbytes:nbytes9, flags:flags9, } = e; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 80, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(nbytes9)))?; + *((ptr0 + 80) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes9); let flags10 = flags9; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 88, wit_bindgen_wasmer::rt::as_i32((flags10.bits >> 0) as i32) as u8)?; + *((ptr0 + 88) as *mut u8) = ((flags10.bits() >> 0) as i32) as u8; + }, EventEnum::Clock=> { let e = (); { - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 72, wit_bindgen_wasmer::rt::as_i32(2i32) as u8)?; + *((ptr0 + 72) as *mut u8) = (2i32) as u8; let () = e; + } } }; let Fdstat{ fs_filetype:fs_filetype11, fs_flags:fs_flags11, fs_rights_base:fs_rights_base11, fs_rights_inheriting:fs_rights_inheriting11, } = fdstat; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 96, wit_bindgen_wasmer::rt::as_i32(fs_filetype11 as i32) as u8)?; + *((ptr0 + 96) as *mut u8) = (match fs_filetype11 { + Filetype::Unknown => 0, + Filetype::BlockDevice => 1, + Filetype::CharacterDevice => 2, + Filetype::Directory => 3, + Filetype::RegularFile => 4, + Filetype::SocketDgram => 5, + Filetype::SocketStream => 6, + Filetype::SymbolicLink => 7, + Filetype::Fifo => 8, + }) as u8; let flags12 = fs_flags11; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 97, wit_bindgen_wasmer::rt::as_i32((flags12.bits >> 0) as i32) as u8)?; + *((ptr0 + 97) as *mut u8) = ((flags12.bits() >> 0) as i32) as u8; let flags13 = fs_rights_base11; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 104, wit_bindgen_wasmer::rt::as_i32((flags13.bits >> 32) as i32))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 100, wit_bindgen_wasmer::rt::as_i32((flags13.bits >> 0) as i32))?; + *((ptr0 + 104) as *mut i32) = (flags13.bits() >> 32) as i32; + *((ptr0 + 100) as *mut i32) = (flags13.bits() >> 0) as i32; let flags14 = fs_rights_inheriting11; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 112, wit_bindgen_wasmer::rt::as_i32((flags14.bits >> 32) as i32))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 108, wit_bindgen_wasmer::rt::as_i32((flags14.bits >> 0) as i32))?; + *((ptr0 + 112) as *mut i32) = (flags14.bits() >> 32) as i32; + *((ptr0 + 108) as *mut i32) = (flags14.bits() >> 0) as i32; let SubscriptionClock{ clock_id:clock_id15, timeout:timeout15, precision:precision15, flags:flags15, } = subscription_clock; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 120, wit_bindgen_wasmer::rt::as_i32(clock_id15 as i32) as u8)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 128, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(timeout15)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 136, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(precision15)))?; + *((ptr0 + 120) as *mut u8) = (match clock_id15 { + Clockid::Realtime => 0, + Clockid::Monotonic => 1, + }) as u8; + *((ptr0 + 128) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout15); + *((ptr0 + 136) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision15); let flags16 = flags15; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 144, wit_bindgen_wasmer::rt::as_i32((flags16.bits >> 0) as i32) as u8)?; + *((ptr0 + 144) as *mut u8) = ((flags16.bits() >> 0) as i32) as u8; let Snapshot0SubscriptionClock{ identifier:identifier17, id:id17, timeout:timeout17, precision:precision17, flags:flags17, } = snapshot0_subscription_clock; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 152, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(identifier17)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 160, wit_bindgen_wasmer::rt::as_i32(id17 as i32) as u8)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 168, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(timeout17)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 176, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(precision17)))?; + *((ptr0 + 152) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier17); + *((ptr0 + 160) as *mut u8) = (match id17 { + Snapshot0Clockid::Realtime => 0, + Snapshot0Clockid::Monotonic => 1, + Snapshot0Clockid::ProcessCputimeId => 2, + Snapshot0Clockid::ThreadCputimeId => 3, + }) as u8; + *((ptr0 + 168) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout17); + *((ptr0 + 176) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision17); let flags18 = flags17; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 184, wit_bindgen_wasmer::rt::as_i32((flags18.bits >> 0) as i32) as u8)?; + *((ptr0 + 184) as *mut u8) = ((flags18.bits() >> 0) as i32) as u8; let Subscription{ userdata:userdata19, data:data19, } = subscription; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 192, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(userdata19)))?; + *((ptr0 + 192) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata19); match data19 { SubscriptionEnum::Clock(e) => { - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 200, wit_bindgen_wasmer::rt::as_i32(0i32) as u8)?; + *((ptr0 + 200) as *mut u8) = (0i32) as u8; let SubscriptionClock{ clock_id:clock_id20, timeout:timeout20, precision:precision20, flags:flags20, } = e; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 208, wit_bindgen_wasmer::rt::as_i32(clock_id20 as i32) as u8)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 216, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(timeout20)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 224, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(precision20)))?; + *((ptr0 + 208) as *mut u8) = (match clock_id20 { + Clockid::Realtime => 0, + Clockid::Monotonic => 1, + }) as u8; + *((ptr0 + 216) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout20); + *((ptr0 + 224) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision20); let flags21 = flags20; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 232, wit_bindgen_wasmer::rt::as_i32((flags21.bits >> 0) as i32) as u8)?; + *((ptr0 + 232) as *mut u8) = ((flags21.bits() >> 0) as i32) as u8; + }, SubscriptionEnum::Read(e) => { - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 200, wit_bindgen_wasmer::rt::as_i32(1i32) as u8)?; + *((ptr0 + 200) as *mut u8) = (1i32) as u8; let SubscriptionFsReadwrite{ file_descriptor:file_descriptor22, } = e; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 208, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(file_descriptor22)))?; + *((ptr0 + 208) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor22); + }, SubscriptionEnum::Write(e) => { - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 200, wit_bindgen_wasmer::rt::as_i32(2i32) as u8)?; + *((ptr0 + 200) as *mut u8) = (2i32) as u8; let SubscriptionFsReadwrite{ file_descriptor:file_descriptor23, } = e; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 208, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(file_descriptor23)))?; + *((ptr0 + 208) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor23); + }, }; let Snapshot0Subscription{ userdata:userdata24, data:data24, } = snapshot0_subscription; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 240, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(userdata24)))?; + *((ptr0 + 240) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata24); match data24 { Snapshot0SubscriptionEnum::Clock(e) => { - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 248, wit_bindgen_wasmer::rt::as_i32(0i32) as u8)?; + *((ptr0 + 248) as *mut u8) = (0i32) as u8; let Snapshot0SubscriptionClock{ identifier:identifier25, id:id25, timeout:timeout25, precision:precision25, flags:flags25, } = e; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 256, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(identifier25)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 264, wit_bindgen_wasmer::rt::as_i32(id25 as i32) as u8)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 272, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(timeout25)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 280, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(precision25)))?; + *((ptr0 + 256) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier25); + *((ptr0 + 264) as *mut u8) = (match id25 { + Snapshot0Clockid::Realtime => 0, + Snapshot0Clockid::Monotonic => 1, + Snapshot0Clockid::ProcessCputimeId => 2, + Snapshot0Clockid::ThreadCputimeId => 3, + }) as u8; + *((ptr0 + 272) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout25); + *((ptr0 + 280) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision25); let flags26 = flags25; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 288, wit_bindgen_wasmer::rt::as_i32((flags26.bits >> 0) as i32) as u8)?; + *((ptr0 + 288) as *mut u8) = ((flags26.bits() >> 0) as i32) as u8; + }, Snapshot0SubscriptionEnum::Read(e) => { - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 248, wit_bindgen_wasmer::rt::as_i32(1i32) as u8)?; + *((ptr0 + 248) as *mut u8) = (1i32) as u8; let SubscriptionFsReadwrite{ file_descriptor:file_descriptor27, } = e; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 256, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(file_descriptor27)))?; + *((ptr0 + 256) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor27); + }, Snapshot0SubscriptionEnum::Write(e) => { - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 248, wit_bindgen_wasmer::rt::as_i32(2i32) as u8)?; + *((ptr0 + 248) as *mut u8) = (2i32) as u8; let SubscriptionFsReadwrite{ file_descriptor:file_descriptor28, } = e; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 256, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(file_descriptor28)))?; + *((ptr0 + 256) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor28); + }, }; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 296, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(device)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 304, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(linkcount)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 312, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(snapshot0_linkcount)))?; + *((ptr0 + 296) as *mut i64) = wit_bindgen_rust::rt::as_i64(device); + *((ptr0 + 304) as *mut i64) = wit_bindgen_rust::rt::as_i64(linkcount); + *((ptr0 + 312) as *mut i32) = wit_bindgen_rust::rt::as_i32(snapshot0_linkcount); let Filestat{ st_dev:st_dev29, st_ino:st_ino29, st_filetype:st_filetype29, st_nlink:st_nlink29, st_size:st_size29, st_atim:st_atim29, st_mtim:st_mtim29, st_ctim:st_ctim29, } = filestat; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 320, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_dev29)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 328, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_ino29)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 336, wit_bindgen_wasmer::rt::as_i32(st_filetype29 as i32) as u8)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 344, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_nlink29)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 352, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_size29)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 360, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_atim29)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 368, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_mtim29)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 376, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_ctim29)))?; + *((ptr0 + 320) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev29); + *((ptr0 + 328) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino29); + *((ptr0 + 336) as *mut u8) = (match st_filetype29 { + Filetype::Unknown => 0, + Filetype::BlockDevice => 1, + Filetype::CharacterDevice => 2, + Filetype::Directory => 3, + Filetype::RegularFile => 4, + Filetype::SocketDgram => 5, + Filetype::SocketStream => 6, + Filetype::SymbolicLink => 7, + Filetype::Fifo => 8, + }) as u8; + *((ptr0 + 344) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_nlink29); + *((ptr0 + 352) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size29); + *((ptr0 + 360) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim29); + *((ptr0 + 368) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim29); + *((ptr0 + 376) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim29); let Snapshot0Filestat{ st_dev:st_dev30, st_ino:st_ino30, st_filetype:st_filetype30, st_nlink:st_nlink30, st_size:st_size30, st_atim:st_atim30, st_mtim:st_mtim30, st_ctim:st_ctim30, } = snapshot0_filestat; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 384, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_dev30)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 392, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_ino30)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 400, wit_bindgen_wasmer::rt::as_i32(st_filetype30 as i32) as u8)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 404, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(st_nlink30)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 408, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_size30)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 416, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_atim30)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 424, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_mtim30)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 432, wit_bindgen_wasmer::rt::as_i64(wit_bindgen_wasmer::rt::as_i64(st_ctim30)))?; + *((ptr0 + 384) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev30); + *((ptr0 + 392) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino30); + *((ptr0 + 400) as *mut u8) = (match st_filetype30 { + Filetype::Unknown => 0, + Filetype::BlockDevice => 1, + Filetype::CharacterDevice => 2, + Filetype::Directory => 3, + Filetype::RegularFile => 4, + Filetype::SocketDgram => 5, + Filetype::SocketStream => 6, + Filetype::SymbolicLink => 7, + Filetype::Fifo => 8, + }) as u8; + *((ptr0 + 404) as *mut i32) = wit_bindgen_rust::rt::as_i32(st_nlink30); + *((ptr0 + 408) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size30); + *((ptr0 + 416) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim30); + *((ptr0 + 424) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim30); + *((ptr0 + 432) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim30); let Tty{ cols:cols31, rows:rows31, width:width31, height:height31, stdin_tty:stdin_tty31, stdout_tty:stdout_tty31, stderr_tty:stderr_tty31, echo:echo31, line_buffered:line_buffered31, } = tty; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 440, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(cols31)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 444, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(rows31)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 448, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(width31)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 452, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(height31)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 456, wit_bindgen_wasmer::rt::as_i32(match stdin_tty31 { true => 1, false => 0 }) as u8)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 457, wit_bindgen_wasmer::rt::as_i32(match stdout_tty31 { true => 1, false => 0 }) as u8)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 458, wit_bindgen_wasmer::rt::as_i32(match stderr_tty31 { true => 1, false => 0 }) as u8)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 459, wit_bindgen_wasmer::rt::as_i32(match echo31 { true => 1, false => 0 }) as u8)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 460, wit_bindgen_wasmer::rt::as_i32(match line_buffered31 { true => 1, false => 0 }) as u8)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 464, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(tid)))?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store(ptr0 + 468, wit_bindgen_wasmer::rt::as_i32(wit_bindgen_wasmer::rt::as_i32(pid)))?; - self.func_expose_types_dummy_func.call(store, ptr0, )?; - Ok(()) + *((ptr0 + 440) as *mut i32) = wit_bindgen_rust::rt::as_i32(cols31); + *((ptr0 + 444) as *mut i32) = wit_bindgen_rust::rt::as_i32(rows31); + *((ptr0 + 448) as *mut i32) = wit_bindgen_rust::rt::as_i32(width31); + *((ptr0 + 452) as *mut i32) = wit_bindgen_rust::rt::as_i32(height31); + *((ptr0 + 456) as *mut u8) = (match stdin_tty31 { true => 1, false => 0 }) as u8; + *((ptr0 + 457) as *mut u8) = (match stdout_tty31 { true => 1, false => 0 }) as u8; + *((ptr0 + 458) as *mut u8) = (match stderr_tty31 { true => 1, false => 0 }) as u8; + *((ptr0 + 459) as *mut u8) = (match echo31 { true => 1, false => 0 }) as u8; + *((ptr0 + 460) as *mut u8) = (match line_buffered31 { true => 1, false => 0 }) as u8; + *((ptr0 + 464) as *mut i32) = wit_bindgen_rust::rt::as_i32(tid); + *((ptr0 + 468) as *mut i32) = wit_bindgen_rust::rt::as_i32(pid); + #[link(wasm_import_module = "output")] + extern "C" { + #[cfg_attr(target_arch = "wasm32", link_name = "expose-types-dummy-func")] + #[cfg_attr(not(target_arch = "wasm32"), link_name = "output_expose-types-dummy-func")] + fn wit_import(_: i32, ); + } + wit_import(ptr0); + () } } - #[allow(unused_imports)] - use wasmer::AsStoreMut as _; - #[allow(unused_imports)] - use wasmer::AsStoreRef as _; - use wit_bindgen_wasmer::rt::RawMem; + + #[repr(align(8))] + struct RetArea([u8; 472]); + static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 472]); } diff --git a/lib/wasi-types-generated/src/wasi/mod.rs b/lib/wasi-types-generated/src/wasi/mod.rs index 0c4b65f0029..87ce687a2af 100644 --- a/lib/wasi-types-generated/src/wasi/mod.rs +++ b/lib/wasi-types-generated/src/wasi/mod.rs @@ -1,8 +1,8 @@ mod bindings; -pub use bindings::wasi::*; +pub use bindings::output::*; use std::mem::MaybeUninit; -use wasmer_types::ValueType; +use wasmer::ValueType; // TODO: if necessary, must be implemented in wit-bindgen unsafe impl ValueType for Errno { @@ -754,8 +754,44 @@ impl Default for Filestat { } } +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 wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Errno { +unsafe impl wit_bindgen_rust::FromToNativeWasmType for Errno { type Native = i32; fn to_native(self) -> Self::Native { @@ -846,14 +882,14 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Errno { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { // TODO: find correct implementation false } } // TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for BusErrno { +unsafe impl wit_bindgen_rust::FromToNativeWasmType for BusErrno { type Native = i32; fn to_native(self) -> Self::Native { @@ -887,14 +923,14 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for BusErrno { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { // TODO: find correct implementation false } } // TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Advice { +unsafe impl wit_bindgen_rust::FromToNativeWasmType for Advice { type Native = i32; fn to_native(self) -> Self::Native { @@ -914,14 +950,14 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Advice { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { // TODO: find correct implementation false } } // TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Socktype { +unsafe impl wit_bindgen_rust::FromToNativeWasmType for Socktype { type Native = i32; fn to_native(self) -> Self::Native { @@ -939,14 +975,14 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Socktype { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { // TODO: find correct implementation false } } // TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Sockstatus { +unsafe impl wit_bindgen_rust::FromToNativeWasmType for Sockstatus { type Native = i32; fn to_native(self) -> Self::Native { @@ -964,14 +1000,14 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Sockstatus { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { // TODO: find correct implementation false } } // TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Streamsecurity { +unsafe impl wit_bindgen_rust::FromToNativeWasmType for Streamsecurity { type Native = i32; fn to_native(self) -> Self::Native { @@ -989,14 +1025,14 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Streamsecurity } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { // TODO: find correct implementation false } } // TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Rights { +unsafe impl wit_bindgen_rust::FromToNativeWasmType for Rights { type Native = i64; fn to_native(self) -> Self::Native { @@ -1008,14 +1044,14 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Rights { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { // TODO: find correct implementation false } } // TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Eventrwflags { +unsafe impl wit_bindgen_rust::FromToNativeWasmType for Eventrwflags { type Native = i32; fn to_native(self) -> Self::Native { @@ -1026,14 +1062,14 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Eventrwflags { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { // TODO: find correct implementation false } } // TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Fstflags { +unsafe impl wit_bindgen_rust::FromToNativeWasmType for Fstflags { type Native = i32; fn to_native(self) -> Self::Native { @@ -1044,14 +1080,14 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Fstflags { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { // TODO: find correct implementation false } } // TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Subclockflags { +unsafe impl wit_bindgen_rust::FromToNativeWasmType for Subclockflags { type Native = i32; fn to_native(self) -> Self::Native { @@ -1062,14 +1098,14 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Subclockflags { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { // TODO: find correct implementation false } } // TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Clockid { +unsafe impl wit_bindgen_rust::FromToNativeWasmType for Clockid { type Native = i32; fn to_native(self) -> Self::Native { @@ -1085,14 +1121,14 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Clockid { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { // TODO: find correct implementation false } } // TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Snapshot0Clockid { +unsafe impl wit_bindgen_rust::FromToNativeWasmType for Snapshot0Clockid { type Native = i32; fn to_native(self) -> Self::Native { @@ -1110,14 +1146,14 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Snapshot0Clocki } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { // TODO: find correct implementation false } } // TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Sockoption { +unsafe impl wit_bindgen_rust::FromToNativeWasmType for Sockoption { type Native = i32; fn to_native(self) -> Self::Native { @@ -1158,49 +1194,14 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Sockoption { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { // TODO: find correct implementation false } } -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 wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Fdflags { +unsafe impl wit_bindgen_rust::FromToNativeWasmType for Fdflags { type Native = i32; fn to_native(self) -> Self::Native { @@ -1211,14 +1212,14 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Fdflags { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { // TODO: find correct implementation false } } // TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Preopentype { +unsafe impl wit_bindgen_rust::FromToNativeWasmType for Preopentype { type Native = i32; fn to_native(self) -> Self::Native { @@ -1233,14 +1234,14 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Preopentype { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { // TODO: find correct implementation false } } // TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Addressfamily { +unsafe impl wit_bindgen_rust::FromToNativeWasmType for Addressfamily { type Native = i32; fn to_native(self) -> Self::Native { @@ -1258,14 +1259,14 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Addressfamily { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { // TODO: find correct implementation false } } // TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Snapshot0Whence { +unsafe impl wit_bindgen_rust::FromToNativeWasmType for Snapshot0Whence { type Native = i32; fn to_native(self) -> Self::Native { @@ -1282,14 +1283,14 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Snapshot0Whence } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { // TODO: find correct implementation false } } // TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Whence { +unsafe impl wit_bindgen_rust::FromToNativeWasmType for Whence { type Native = i32; fn to_native(self) -> Self::Native { @@ -1306,12 +1307,12 @@ unsafe impl wit_bindgen_wasmer::wasmer::FromToNativeWasmType for Whence { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_wasmer::wasmer::AsStoreRef) -> bool { + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { // TODO: find correct implementation false } } - +*/ // TODO: if necessary, must be implemented in wit-bindgen unsafe impl ValueType for Snapshot0Clockid { #[inline] diff --git a/lib/wasi-types-generated/src/wasi_filesystem/bindings.rs b/lib/wasi-types-generated/src/wasi_filesystem/bindings.rs deleted file mode 100644 index 7473d7f699e..00000000000 --- a/lib/wasi-types-generated/src/wasi_filesystem/bindings.rs +++ /dev/null @@ -1,814 +0,0 @@ -#[allow(clippy::all)] -pub mod wasi_filesystem { - #[allow(unused_imports)] - use wit_bindgen_wasmer::{anyhow, wasmer}; - /// The type of a filesystem object referenced by a descriptor. - /// - /// Note: This was called `filetype` in earlier versions of WASI. - #[repr(u8)] - #[derive(Clone, Copy, PartialEq, Eq)] - pub enum Type { - /// The type of the descriptor or file is unknown or is different from - /// any of the other types specified. - Unknown, - /// The descriptor refers to a block device inode. - BlockDevice, - /// The descriptor refers to a character device inode. - CharacterDevice, - /// The descriptor refers to a directory inode. - Directory, - /// The descriptor refers to a named pipe. - Fifo, - /// The file refers to a symbolic link inode. - SymbolicLink, - /// The descriptor refers to a regular file inode. - RegularFile, - /// The descriptor refers to a socket. - Socket, - } - impl core::fmt::Debug for Type { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - match self { - Type::Unknown => { - f.debug_tuple("Type::Unknown").finish() - } - Type::BlockDevice => { - f.debug_tuple("Type::BlockDevice").finish() - } - Type::CharacterDevice => { - f.debug_tuple("Type::CharacterDevice").finish() - } - Type::Directory => { - f.debug_tuple("Type::Directory").finish() - } - Type::Fifo => { - f.debug_tuple("Type::Fifo").finish() - } - Type::SymbolicLink => { - f.debug_tuple("Type::SymbolicLink").finish() - } - Type::RegularFile => { - f.debug_tuple("Type::RegularFile").finish() - } - Type::Socket => { - f.debug_tuple("Type::Socket").finish() - } - } - } - } - wit_bindgen_wasmer::bitflags::bitflags! { - /// Descriptor flags. - /// - /// Note: This was called `fd-flags` in earlier versions of WASI. - pub struct Flags: u8 {/// Read mode: Data can be read. - const READ = 1 << 0; - /// Write mode: Data can be written to. - const WRITE = 1 << 1; - /// Append mode: Data written to the file is always appended to the file's - /// end. - const APPEND = 1 << 2; - /// Write according to synchronized I/O data integrity completion. Only the - /// data stored in the file is synchronized. - const DSYNC = 1 << 3; - /// Non-blocking mode. - const NONBLOCK = 1 << 4; - /// Synchronized read I/O operations. - const RSYNC = 1 << 5; - /// 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 << 6; - } - } - - impl core::fmt::Display for Flags{ - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("Flags(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(())} - } - - wit_bindgen_wasmer::bitflags::bitflags! { - /// Flags determining the method of how paths are resolved. - pub struct AtFlags: u8 {/// As long as the resolved path corresponds to a symbolic link, it is expanded. - const SYMLINK_FOLLOW = 1 << 0; - } - } - - impl core::fmt::Display for AtFlags{ - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("AtFlags(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(())} - } - - wit_bindgen_wasmer::bitflags::bitflags! { - /// Open flags used by `open-at`. - 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 core::fmt::Display for OFlags{ - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("OFlags(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(())} - } - - wit_bindgen_wasmer::bitflags::bitflags! { - /// Permissions mode used by `open-at`, `change-permissions-at`, and similar. - pub struct Mode: u8 {/// True if the resource is considered readable by the containing - /// filesystem. - const READABLE = 1 << 0; - /// True if the resource is considered writeable by the containing - /// filesystem. - const WRITEABLE = 1 << 1; - /// True if the resource is considered executable by the containing - /// filesystem. This does not apply to directories. - const EXECUTABLE = 1 << 2; - } - } - - impl core::fmt::Display for Mode{ - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str("Mode(")?; - core::fmt::Debug::fmt(self, f)?; - f.write_str(" (0x")?; - core::fmt::LowerHex::fmt(&self.bits, f)?; - f.write_str("))")?; - Ok(())} - } - - /// 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. This is similar to `E2BIG` in POSIX. - 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 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, - } - 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::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", - } - } - pub fn message(&self) -> &'static str { - match self { - Errno::Success => "No error occurred. System call completed successfully.", - Errno::Toobig => "Argument list too long. This is similar to `E2BIG` in POSIX.", - 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::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.", - } - } - } - 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{} - /// 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() - } - } - } - } - /// A descriptor is a reference to a filesystem object, which may be a file, - /// directory, named pipe, special file, or other object on which filesystem - /// calls may be made. - #[derive(Debug)] - pub struct Descriptor(wit_bindgen_wasmer::rt::ResourceIndex); - - /// Auxiliary data associated with the wasm exports. - #[derive(Default)] - pub struct WasiFilesystemData { - - index_slab0: wit_bindgen_wasmer::rt::IndexSlab, - resource_slab0: wit_bindgen_wasmer::rt::ResourceSlab, - dtor0: OnceCell>, - } - - pub struct WasiFilesystem { - #[allow(dead_code)] - env: wasmer::FunctionEnv, - func_descriptor_fadvise: wasmer::TypedFunction<(i32,i64,i64,i32,), i32>, - memory: wasmer::Memory, - } - impl WasiFilesystem { - - /// Adds any intrinsics, if necessary for this exported wasm - /// functionality to the `ImportObject` provided. - /// - /// This function returns the `WasiFilesystemData` which needs to be - /// passed through to `WasiFilesystem::new`. - fn add_to_imports( - mut store: impl wasmer::AsStoreMut, - imports: &mut wasmer::Imports, - ) -> wasmer::FunctionEnv { - let env = wasmer::FunctionEnv::new(&mut store, WasiFilesystemData::default()); - let mut canonical_abi = imports.get_namespace_exports("canonical_abi").unwrap_or_else(wasmer::Exports::new); - - canonical_abi.insert( - "resource_drop_descriptor", - wasmer::Function::new_typed_with_env( - &mut store, - &env, - move |mut store: wasmer::FunctionEnvMut, idx: u32| -> Result<(), wasmer::RuntimeError> { - let resource_idx = store.data_mut().index_slab0.remove(idx)?; - let wasm = match store.data_mut().resource_slab0.drop(resource_idx) { - Some(wasm) => wasm, - None => return Ok(()), - }; - let dtor = store.data_mut().dtor0.get().unwrap().clone(); - dtor.call(&mut store, wasm)?; - Ok(()) - }, - ) - ); - canonical_abi.insert( - "resource_clone_descriptor", - wasmer::Function::new_typed_with_env( - &mut store, - &env, - move |mut store: wasmer::FunctionEnvMut, idx: u32| -> Result { - let state = &mut *store.data_mut(); - let resource_idx = state.index_slab0.get(idx)?; - state.resource_slab0.clone(resource_idx)?; - Ok(state.index_slab0.insert(resource_idx)) - }, - ) - ); - canonical_abi.insert( - "resource_get_descriptor", - wasmer::Function::new_typed_with_env( - &mut store, - &env, - move |mut store: wasmer::FunctionEnvMut, idx: u32| -> Result { - let state = &mut *store.data_mut(); - let resource_idx = state.index_slab0.get(idx)?; - Ok(state.resource_slab0.get(resource_idx)) - }, - ) - ); - canonical_abi.insert( - "resource_new_descriptor", - wasmer::Function::new_typed_with_env( - &mut store, - &env, - move |mut store: wasmer::FunctionEnvMut, val: i32| -> Result { - let state = &mut *store.data_mut(); - let resource_idx = state.resource_slab0.insert(val); - Ok(state.index_slab0.insert(resource_idx)) - }, - ) - ); - imports.register_namespace("canonical_abi", canonical_abi); - env - } - - /// Instantiates the provided `module` using the specified - /// parameters, wrapping up the result in a structure that - /// translates between wasm and the host. - /// - /// The `imports` provided will have intrinsics added to it - /// automatically, so it's not necessary to call - /// `add_to_imports` beforehand. This function will - /// instantiate the `module` otherwise using `imports`, and - /// both an instance of this structure and the underlying - /// `wasmer::Instance` will be returned. - pub fn instantiate( - mut store: impl wasmer::AsStoreMut, - module: &wasmer::Module, - imports: &mut wasmer::Imports, - ) -> anyhow::Result<(Self, wasmer::Instance)> { - let env = Self::add_to_imports(&mut store, imports); - let instance = wasmer::Instance::new( - &mut store, module, &*imports)?; - { - let dtor0 = instance - .exports - .get_typed_function( - &store, - "canonical_abi_drop_descriptor", - )? - .clone(); - - env - .as_mut(&mut store) - .dtor0 - .set(dtor0) - .map_err(|_e| anyhow::anyhow!("Couldn't set canonical_abi_drop_descriptor"))?; - } - - Ok((Self::new(store, &instance, env)?, instance)) - } - - /// Low-level creation wrapper for wrapping up the exports - /// of the `instance` provided in this structure of wasm - /// exports. - /// - /// This function will extract exports from the `instance` - /// and wrap them all up in the returned structure which can - /// be used to interact with the wasm module. - pub fn new( - store: impl wasmer::AsStoreMut, - _instance: &wasmer::Instance, - env: wasmer::FunctionEnv, - ) -> Result { - let func_descriptor_fadvise= _instance.exports.get_typed_function(&store, "descriptor::fadvise")?; - let memory= _instance.exports.get_memory("memory")?.clone(); - Ok(WasiFilesystem{ - func_descriptor_fadvise, - memory, - env, - }) - } - /// Provide file advisory information on a descriptor. - /// - /// This is similar to `posix_fadvise` in POSIX. - pub fn descriptor_fadvise(&self, store: &mut wasmer::Store,self_: & Descriptor,offset: u64,len: u64,advice: Advice,)-> Result, wasmer::RuntimeError> { - let _memory = &self.memory; - - let obj0 = self_; - let handle0 = { - let state = self.env.as_mut(store); - state.resource_slab0.clone(obj0.0)?; - state.index_slab0.insert(obj0.0) - }; - let result1 = self.func_descriptor_fadvise.call(store, handle0 as i32, wit_bindgen_wasmer::rt::as_i64(offset), wit_bindgen_wasmer::rt::as_i64(len), advice as i32, )?; - let _memory_view = _memory.view(&store); - let load2 = unsafe { _memory_view.data_unchecked_mut() }.load::(result1 + 0)?; - Ok(match i32::from(load2) { - 0 => Ok(()), - 1 => Err({ - let _memory_view = _memory.view(&store); - let load3 = unsafe { _memory_view.data_unchecked_mut() }.load::(result1 + 1)?; - match i32::from(load3) { - 0 => Errno::Success, - 1 => Errno::Toobig, - 2 => Errno::Access, - 3 => Errno::Addrinuse, - 4 => Errno::Addrnotavail, - 5 => Errno::Afnosupport, - 6 => Errno::Again, - 7 => Errno::Already, - 8 => Errno::Badmsg, - 9 => Errno::Busy, - 10 => Errno::Canceled, - 11 => Errno::Child, - 12 => Errno::Connaborted, - 13 => Errno::Connrefused, - 14 => Errno::Connreset, - 15 => Errno::Deadlk, - 16 => Errno::Destaddrreq, - 17 => Errno::Dom, - 18 => Errno::Dquot, - 19 => Errno::Exist, - 20 => Errno::Fault, - 21 => Errno::Fbig, - 22 => Errno::Hostunreach, - 23 => Errno::Idrm, - 24 => Errno::Ilseq, - 25 => Errno::Inprogress, - 26 => Errno::Intr, - 27 => Errno::Inval, - 28 => Errno::Io, - 29 => Errno::Isconn, - 30 => Errno::Isdir, - 31 => Errno::Loop, - 32 => Errno::Mfile, - 33 => Errno::Mlink, - 34 => Errno::Msgsize, - 35 => Errno::Multihop, - 36 => Errno::Nametoolong, - 37 => Errno::Netdown, - 38 => Errno::Netreset, - 39 => Errno::Netunreach, - 40 => Errno::Nfile, - 41 => Errno::Nobufs, - 42 => Errno::Nodev, - 43 => Errno::Noent, - 44 => Errno::Noexec, - 45 => Errno::Nolck, - 46 => Errno::Nolink, - 47 => Errno::Nomem, - 48 => Errno::Nomsg, - 49 => Errno::Noprotoopt, - 50 => Errno::Nospc, - 51 => Errno::Nosys, - 52 => Errno::Notconn, - 53 => Errno::Notdir, - 54 => Errno::Notempty, - 55 => Errno::Notrecoverable, - 56 => Errno::Notsock, - 57 => Errno::Notsup, - 58 => Errno::Notty, - 59 => Errno::Nxio, - 60 => Errno::Overflow, - 61 => Errno::Ownerdead, - 62 => Errno::Perm, - 63 => Errno::Pipe, - 64 => Errno::Proto, - 65 => Errno::Protonosupport, - 66 => Errno::Prototype, - 67 => Errno::Range, - 68 => Errno::Rofs, - 69 => Errno::Spipe, - 70 => Errno::Srch, - 71 => Errno::Stale, - 72 => Errno::Timedout, - 73 => Errno::Txtbsy, - 74 => Errno::Xdev, - _ => return Err(invalid_variant("Errno")), - } - }), - _ => return Err(invalid_variant("expected")), - }) - } - - /// Drops the host-owned handle to the resource - /// specified. - /// - /// Note that this may execute the WebAssembly-defined - /// destructor for this type. This also may not run - /// the destructor if there are still other references - /// to this type. - pub fn drop_descriptor( - &self, - store: &mut wasmer::Store, - val: Descriptor, - ) -> Result<(), wasmer::RuntimeError> { - let state = self.env.as_mut(store); - let wasm = match state.resource_slab0.drop(val.0) { - Some(val) => val, - None => return Ok(()), - }; - let dtor0 = state.dtor0.get().unwrap().clone(); - dtor0.call(store, wasm)?; - Ok(()) - } - } - use wit_bindgen_wasmer::once_cell::unsync::OnceCell; - #[allow(unused_imports)] - use wasmer::AsStoreMut as _; - #[allow(unused_imports)] - use wasmer::AsStoreRef as _; - use wit_bindgen_wasmer::rt::RawMem; - use wit_bindgen_wasmer::rt::invalid_variant; -} diff --git a/lib/wasi-types-generated/src/wasi_filesystem/mod.rs b/lib/wasi-types-generated/src/wasi_filesystem/mod.rs deleted file mode 100644 index 3092f553d6d..00000000000 --- a/lib/wasi-types-generated/src/wasi_filesystem/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod bindings; -pub use bindings::wasi_filesystem::*; diff --git a/lib/wasi-types-generated/wit/wasi.wit b/lib/wasi-types-generated/wit-clean/output.wit similarity index 54% rename from lib/wasi-types-generated/wit/wasi.wit rename to lib/wasi-types-generated/wit-clean/output.wit index 019d3bf0184..8a166fcaf21 100644 --- a/lib/wasi-types-generated/wit/wasi.wit +++ b/lib/wasi-types-generated/wit-clean/output.wit @@ -812,3 +812,515 @@ record tty { echo: bool, line-buffered: bool, } +// 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-generated/wit-clean/wasi_unstable.wit b/lib/wasi-types-generated/wit-clean/wasi_unstable.wit index 2330a054ba6..0e37989f8e8 100644 --- a/lib/wasi-types-generated/wit-clean/wasi_unstable.wit +++ b/lib/wasi-types-generated/wit-clean/wasi_unstable.wit @@ -6,6 +6,7 @@ /// 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)) @@ -508,3 +509,4 @@ (result $error (expected (error $errno))) ) ) +*/ \ No newline at end of file diff --git a/lib/wasi-types-generated/wit/wasi-filesystem.wit b/lib/wasi-types-generated/wit/wasi-filesystem.wit deleted file mode 100644 index c5154f03793..00000000000 --- a/lib/wasi-types-generated/wit/wasi-filesystem.wit +++ /dev/null @@ -1,626 +0,0 @@ -// Extracted from https://github.com/WebAssembly/wasi-filesystem/blob/main/wasi-filesystem.wit.md - -/// Size of a range of bytes in memory. -type size = u32 - -/// Non-negative file size or length of a region within a file. -type filesize = u64 - -/// Relative offset within a file. -type filedelta = s64 - -/// Timestamp in nanoseconds. -/// -/// TODO: wasi-clocks is moving to seconds+nanoseconds. -type timestamp = u64 - -/// Information associated with a descriptor. -/// -/// Note: This was called `fdstat` in earlier versions of WASI. -record info { - /// The type of filesystem object referenced by a descriptor. - %type: %type, - /// Flags associated with a descriptor. - %flags: %flags, -} - -/// The type of a filesystem object referenced by a descriptor. -/// -/// Note: This was called `filetype` in earlier versions of WASI. -enum %type { - /// The type of the descriptor or file is unknown or is different from - /// any of the other types specified. - unknown, - /// The descriptor refers to a block device inode. - block-device, - /// The descriptor refers to a character device inode. - character-device, - /// The descriptor refers to a directory inode. - directory, - /// The descriptor refers to a named pipe. - fifo, - /// The file refers to a symbolic link inode. - symbolic-link, - /// The descriptor refers to a regular file inode. - regular-file, - /// The descriptor refers to a socket. - socket, -} - -/// Descriptor flags. -/// -/// Note: This was called `fd-flags` in earlier versions of WASI. -flags %flags { - /// Read mode: Data can be read. - read, - /// Write mode: Data can be written to. - write, - /// 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 attributes. -/// -/// Note: This was called `filestat` in earlier versions of WASI. -record stat { - /// Device ID of device containing the file. - dev: device, - /// File serial number. - ino: inode, - /// File type. - %type: %type, - /// Number of hard links to the file. - nlink: linkcount, - /// For regular files, the file size in bytes. For symbolic links, the length - /// in bytes of the pathname contained in the symbolic link. - size: filesize, - /// Last data access timestamp. - atim: timestamp, - /// Last data modification timestamp. - mtim: timestamp, - /// Last file status change timestamp. - ctim: timestamp, -} - -/// Flags determining the method of how paths are resolved. -flags at-flags { - /// As long as the resolved path corresponds to a symbolic link, it is expanded. - symlink-follow, -} - -/// Open flags used by `open-at`. -flags o-flags { - /// 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, -} - -/// Permissions mode used by `open-at`, `change-permissions-at`, and similar. -flags mode { - /// True if the resource is considered readable by the containing - /// filesystem. - readable, - /// True if the resource is considered writeable by the containing - /// filesystem. - writeable, - /// True if the resource is considered executable by the containing - /// filesystem. This does not apply to directories. - executable, -} - -/// Number of hard links to an inode. -type linkcount = 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 - -/// Filesystem object serial number that is unique within its file system. -type inode = u64 - -/// When setting a timestamp, this gives the value to set it to. -variant new-timestamp { - /// Leave the timestamp set to its previous value. - no-change, - /// Set the timestamp to the current time of the system clock associated - /// with the filesystem. - now, - /// Set the timestamp to the given value. - timestamp(timestamp), -} - -/// A directory entry. -record dirent { - /// The serial number of the file referred to by this directory entry. - ino: inode, - /// The length of the name of the directory entry. - namelen: size, - /// The type of the file referred to by this directory entry. - %type: %type, -} - -/// 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 { - /// No error occurred. System call completed successfully. - success, - /// Argument list too long. This is similar to `E2BIG` in POSIX. - 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 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, -} - -/// File or memory access pattern advisory information. -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. - will-need, - /// The application expects that it will not access the specified data in the near future. - dont-need, - /// The application expects to access the specified data once and then not reuse it thereafter. - no-reuse, -} - -/// The position relative to which to set the offset of the descriptor. -variant seek-from { - /// Seek relative to start-of-file. - set(filesize), - /// Seek relative to current position. - cur(filedelta), - /// Seek relative to end-of-file. - end(filesize), -} - -/// A descriptor is a reference to a filesystem object, which may be a file, -/// directory, named pipe, special file, or other object on which filesystem -/// calls may be made. -resource descriptor { - /// Provide file advisory information on a descriptor. - /// - /// This is similar to `posix_fadvise` in POSIX. - fadvise: func( - /// The offset within the file to which the advisory applies. - offset: u64, - /// The length of the region to which the advisory applies. - len: u64, - /// The advice. - advice: advice - ) -> expected - -// /// Force the allocation of space in a file. -// /// -// /// Note: This is similar to `posix_fallocate` in POSIX. -// fallocate: func( -// /// The offset at which to start the allocation. -// offset: filesize, -// /// The length of the area that is allocated. -// len: filesize -// ) -> expected -// -// /// Synchronize the data of a file to disk. -// /// -// /// Note: This is similar to `fdatasync` in POSIX. -// datasync: func() -> expected -// -// /// Get information associated with a descriptor. -// /// -// /// Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well -// /// as additional fields. -// /// -// /// Note: This was called `fdstat_get` in earlier versions of WASI. -// info: func() -> expected -// -// /// Adjust the size of an open file. If this increases the file's size, the -// /// extra bytes are filled with zeros. -// /// -// /// Note: This was called `fd_filestat_set_size` in earlier versions of WASI. -// set-size: func(size: filesize) -> expected -// -// /// Adjust the timestamps of an open file or directory. -// /// -// /// Note: This is similar to `futimens` in POSIX. -// /// -// /// Note: This was called `fd_filestat_set_times` in earlier versions of WASI. -// set-times: func( -// /// The desired values of the data access timestamp. -// atim: new-timestamp, -// /// The desired values of the data modification timestamp. -// mtim: new-timestamp, -// ) -> expected -// -// /// Read from a descriptor, without using and updating the descriptor's offset. -// /// -// /// Note: This is similar to `pread` in POSIX. -// pread: func( -// /// The offset within the file at which to read. -// offset: filesize, -// ) -> stream -// -// /// Write to a descriptor, without using and updating the descriptor's offset. -// /// -// /// Note: This is similar to `pwrite` in POSIX. -// pwrite: func( -// /// Data to write -// buf: stream, -// /// The offset within the file at which to write. -// offset: filesize, -// ) -> future> -// -// /// Read from a descriptor. -// /// -// /// The meaning of `read` on a directory is unspecified. -// /// -// /// Note: This is similar to `read` in POSIX. -// read: func() -> stream -// -// /// 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. -// readdir: func( -// /// If true, rewind the current position to the beginning before reading. -// rewind: bool -// ) -> stream -// -// /// Move the offset of a descriptor. -// /// -// /// The meaning of `seek` on a directory is unspecified. -// /// -// /// Returns new offset of the descriptor, relative to the start of the file. -// /// -// /// Note: This is similar to `lseek` in POSIX. -// seek: func( -// /// The method to compute the new offset. -// %from: seek-from, -// ) -> expected -// -// /// Synchronize the data and metadata of a file to disk. -// /// -// /// Note: This is similar to `fsync` in POSIX. -// sync: func() -> expected -// -// /// Return the current offset of a descriptor. -// /// -// /// Returns the current offset of the descriptor, relative to the start of the file. -// /// -// /// Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX. -// tell: func() -> expected -// -// /// Write to a descriptor. -// /// -// /// Note: This is similar to `write` in POSIX. -// write: func( -// /// Data to write -// buf: stream, -// ) -> future> -// -// /// Create a directory. -// /// -// /// Note: This is similar to `mkdirat` in POSIX. -// create-directory-at: func( -// /// The relative path at which to create the directory. -// path: string, -// ) -> expected -// -// /// Return the attributes of a file or directory. -// /// -// /// Note: This is similar to `fstatat` in POSIX. -// /// -// /// Note: This was called `fd_filestat_get` in earlier versions of WASI. -// stat-at: func( -// /// Flags determining the method of how the path is resolved. -// at-flags: at-flags, -// /// The relative path of the file or directory to inspect. -// path: string, -// ) -> expected -// -// /// Adjust the timestamps of a file or directory. -// /// -// /// Note: This is similar to `utimensat` in POSIX. -// /// -// /// Note: This was called `path_filestat_set_times` in earlier versions of WASI. -// set-times-at: func( -// /// Flags determining the method of how the path is resolved. -// at-flags: at-flags, -// /// The relative path of the file or directory to operate on. -// path: string, -// /// The desired values of the data access timestamp. -// atim: new-timestamp, -// /// The desired values of the data modification timestamp. -// mtim: new-timestamp, -// ) -> expected -// -// /// Create a hard link. -// /// -// /// Note: This is similar to `linkat` in POSIX. -// link-at: func( -// /// Flags determining the method of how the path is resolved. -// old-at-flags: at-flags, -// /// The relative source path from which to link. -// old-path: string, -// /// The base directory for `new-path`. -// new-descriptor: handle descriptor, -// /// The relative destination path at which to create the hard link. -// new-path: string, -// ) -> expected -// -// /// Open a file or directory. -// /// -// /// The returned descriptor is not guaranteed to be the lowest-numbered -// /// 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 descriptor is -// /// guaranteed to be less than 2**31. -// /// -// /// Note: This is similar to `openat` in POSIX. -// open-at: func( -// /// Flags determining the method of how the path is resolved. -// at-flags: at-flags, -// /// The relative path of the object to open. -// path: string, -// /// The method by which to open the file. -// o-flags: o-flags, -// /// Flags to use for the resulting descriptor. -// %flags: %flags, -// /// Permissions to use when creating a new file. -// mode: mode -// ) -> expected -// -// /// Read the contents of a symbolic link. -// /// -// /// Note: This is similar to `readlinkat` in POSIX. -// readlink-at: func( -// /// The relative path of the symbolic link from which to read. -// path: string, -// ) -> expected -// -// /// Remove a directory. -// /// -// /// Return `errno::notempty` if the directory is not empty. -// /// -// /// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. -// remove-directory-at: func( -// /// The relative path to a directory to remove. -// path: string, -// ) -> expected -// -// /// Rename a filesystem object. -// /// -// /// Note: This is similar to `renameat` in POSIX. -// rename-at: func( -// /// The relative source path of the file or directory to rename. -// old-path: string, -// /// The base directory for `new-path`. -// new-descriptor: handle descriptor, -// /// The relative destination path to which to rename the file or directory. -// new-path: string, -// ) -> expected -// -// /// Create a symbolic link. -// /// -// /// Note: This is similar to `symlinkat` in POSIX. -// symlink-at: func( -// /// The contents of the symbolic link. -// old-path: string, -// /// The relative destination path at which to create the symbolic link. -// new-path: string, -// ) -> expected -// -// /// Unlink a filesystem object that is not a directory. -// /// -// /// Return `errno::isdir` if the path refers to a directory. -// /// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. -// unlink-file-at: func( -// /// The relative path to a file to unlink. -// path: string, -// ) -> expected -// -// /// Change the permissions of a filesystem object that is not a directory. -// /// -// /// Note that the ultimate meanings of these permissions is -// /// filesystem-specific. -// /// -// /// Note: This is similar to `fchmodat` in POSIX. -// change-file-permissions-at: func( -// /// Flags determining the method of how the path is resolved. -// at-flags: at-flags, -// /// The relative path to operate on. -// path: string, -// /// The new permissions for the filesystem object. -// mode: mode, -// ) -> expected -// -// /// Change the permissions of a directory. -// /// -// /// Note that the ultimate meanings of these permissions is -// /// filesystem-specific. -// /// -// /// Unlike in POSIX, the `executable` flag is not reinterpreted as a "search" -// /// flag. `read` on a directory implies readability and searchability, and -// /// `execute` is not valid for directories. -// /// -// /// Note: This is similar to `fchmodat` in POSIX. -// change-directory-permissions-at: func( -// /// Flags determining the method of how the path is resolved. -// at-flags: at-flags, -// /// The relative path to operate on. -// path: string, -// /// The new permissions for the directory. -// mode: mode, -// ) -> expected -} diff --git a/lib/wasi-types-generated/wit/wasi-io-typenames.wit b/lib/wasi-types-generated/wit/wasi-io-typenames.wit deleted file mode 100644 index c0eb25ef25a..00000000000 --- a/lib/wasi-types-generated/wit/wasi-io-typenames.wit +++ /dev/null @@ -1,201 +0,0 @@ -// Extracted from https://github.com/WebAssembly/wasi-io/blob/main/standard/io/witx/typenames.witx - - - - - - - - - - - - -// ;;; A region of memory for scatter/gather reads. -// (typename $iovec -// (record -// ;;; The address of the buffer to be filled. -// (field $buf (@witx pointer u8)) -// ;;; The length of the buffer to be filled. -// (field $buf_len $size) -// ) -// ) -// -// ;;; A region of memory for scatter/gather writes. -// (typename $ciovec -// (record -// ;;; The address of the buffer to be written. -// (field $buf (@witx const_pointer u8)) -// ;;; The length of the buffer to be written. -// (field $buf_len $size) -// ) -// ) -// -// (typename $iovec_array (list $iovec)) -// (typename $ciovec_array (list $ciovec)) -// -// ;;; Relative offset within a file. -// (typename $filedelta s64) -// -// ;;; The position relative to which to set the offset of the file descriptor. -// (typename $whence -// (enum (@witx tag u8) -// ;;; Seek relative to start-of-file. -// $set -// ;;; Seek relative to current position. -// $cur -// ;;; Seek relative to end-of-file. -// $end -// ) -// ) - -// ;;; Number of hard links to an inode. -// (typename $linkcount u64) -// -// ;;; File permissions. This represents the permissions associated with a -// ;;; file in a filesystem, and don't fully reflect all the conditions -// ;;; which determine whether a given WASI program can access the file. -// (typename $permissions -// (flags (@witx repr u8) -// ;;; For files, permission to read the file. -// ;;; For directories, permission to do `readdir` and access files -// ;;; within the directory. -// ;;; -// ;;; Note: This is similar to the read bit being set on files, and the -// ;;; read *and* execute bits being set on directories, in POSIX. -// $read -// -// ;;; For files, permission to mutate the file. -// ;;; For directories, permission to create, remove, and rename items -// ;;; within the directory. -// $write -// -// ;;; For files, permission to "execute" the file, using whatever -// ;;; concept of "executing" the host filesystem has. -// ;;; This flag is not valid for directories. -// $execute -// -// ;;; For filesystems which have a concept of multiple "users", this flag -// ;;; indicates that the file is only accessible by the effective "user" -// ;;; that the WASI store uses to access the filesystem, and inaccessible -// ;;; to other "users". -// $private -// ) -// ) -// -// ;;; File attributes. -// (typename $filestat -// (record -// ;;; Device ID of device containing the file. -// (field $dev $device) -// ;;; File serial number. -// (field $ino $inode) -// ;;; File type. -// (field $filetype $filetype) -// ;;; File permissions. -// (field $permissions $permissions) -// ;;; Number of hard links to the file. -// (field $nlink $linkcount) -// ;;; For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link. -// (field $size $filesize) -// ;;; Last data access timestamp. -// (field $atim $timestamp) -// ;;; Last data modification timestamp. -// (field $mtim $timestamp) -// ;;; Last file status change timestamp. -// (field $ctim $timestamp) -// ) -// ) -// - - - -// ;;; The contents of a `subscription` when type is type is -// ;;; `eventtype::fd_read` or `eventtype::fd_write`. -// (typename $subscription_fd_readwrite -// (record -// ;;; The file descriptor on which to wait for it to become ready for reading or writing. -// (field $fd $fd) -// ) -// ) -// -// ;;; The contents of a `subscription`. -// (typename $subscription_u -// (union (@witx tag $eventtype) -// $subscription_clock -// $subscription_fd_readwrite -// $subscription_fd_readwrite -// ) -// ) -// -// ;;; Subscription to an event. -// (typename $subscription -// (record -// ;;; User-provided value that is attached to the subscription in the -// ;;; implementation and returned through `event::userdata`. -// (field $userdata $userdata) -// ;;; The type of the event to which to subscribe, and the contents of the subscription. -// (field $u $subscription_u) -// ) -// ) -// -// ;;; Exit code generated by a program when exiting. -// (typename $exitcode u8) -// -// ;;; Indicate the program exited successfully. -// ;;; -// ;;; Note: This is similar to `EXIT_SUCCESS` in POSIX. -// (@witx const $exitcode $success 0) -// -// ;;; Indicate the program exited unsuccessfully. -// ;;; -// ;;; Note: This is similar to `EXIT_FAILURE` in POSIX. -// (@witx const $exitcode $failure 1) -// -// ;;; Flags provided to `sock_recv`. -// (typename $riflags -// (flags (@witx repr u16) -// ;;; Returns the message without removing it from the socket's receive queue. -// $recv_peek -// ;;; On byte-stream sockets, block until the full amount of data can be returned. -// $recv_waitall -// ) -// ) -// -// ;;; Flags returned by `sock_recv`. -// (typename $roflags -// (flags (@witx repr u16) -// ;;; Returned by `sock_recv`: Message data has been truncated. -// $recv_data_truncated -// ) -// ) -// -// ;;; Flags provided to `sock_send`. As there are currently no flags -// ;;; defined, it must be set to zero. -// (typename $siflags u16) -// -// ;;; Which channels on a socket to shut down. -// (typename $sdflags -// (flags (@witx repr u8) -// ;;; Disables further receive operations. -// $rd -// ;;; Disables further send operations. -// $wr -// ) -// ) - -// ;;; The contents of a `prestat` when its type is `preopentype::dir`. -// (typename $prestat_dir -// (record -// ;;; The length of the directory name for use with `fd_prestat_dir_name`. -// (field $pr_name_len $size) -// ) -// ) -// -// ;;; Information about a pre-opened capability. -// (typename $prestat -// (union (@witx tag $preopentype) -// ;;; When type is `preopentype::dir`: -// $prestat_dir -// ) -// ) diff --git a/lib/wasi-types-generated/wit/wasi-snapshot0.wit b/lib/wasi-types-generated/wit/wasi-snapshot0.wit deleted file mode 100644 index ddd81089eea..00000000000 --- a/lib/wasi-types-generated/wit/wasi-snapshot0.wit +++ /dev/null @@ -1,249 +0,0 @@ -// Extracted from https://github.com/WebAssembly/WASI/blob/main/phases/old/snapshot_0/witx/typenames.witx - - - - - - - -// ;;; A region of memory for scatter/gather reads. -// (typename $iovec -// (record -// ;;; The address of the buffer to be filled. -// (field $buf (@witx pointer u8)) -// ;;; The length of the buffer to be filled. -// (field $buf_len $size) -// ) -// ) -// -// ;;; A region of memory for scatter/gather writes. -// (typename $ciovec -// (record -// ;;; The address of the buffer to be written. -// (field $buf (@witx const_pointer u8)) -// ;;; The length of the buffer to be written. -// (field $buf_len $size) -// ) -// ) -// -// (typename $iovec_array (list $iovec)) -// (typename $ciovec_array (list $ciovec)) -// -// ;;; Relative offset within a file. -// (typename $filedelta s64) -// -// ;;; The position relative to which to set the offset of the file descriptor. -// (typename $whence -// (enum (@witx tag u8) -// ;;; Seek relative to current position. -// $cur -// ;;; Seek relative to end-of-file. -// $end -// ;;; Seek relative to start-of-file. -// $set -// ) -// ) - -// ;;; Number of hard links to an inode. -// (typename $linkcount u32) -// -// ;;; File attributes. -// (typename $filestat -// (record -// ;;; Device ID of device containing the file. -// (field $dev $device) -// ;;; File serial number. -// (field $ino $inode) -// ;;; File type. -// (field $filetype $filetype) -// ;;; Number of hard links to the file. -// (field $nlink $linkcount) -// ;;; For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link. -// (field $size $filesize) -// ;;; Last data access timestamp. -// (field $atim $timestamp) -// ;;; Last data modification timestamp. -// (field $mtim $timestamp) -// ;;; Last file status change timestamp. -// (field $ctim $timestamp) -// ) -// ) - - -// ;;; The contents of a `subscription` when the variant is -// ;;; `eventtype::fd_read` or `eventtype::fd_write`. -// (typename $subscription_fd_readwrite -// (record -// ;;; The file descriptor on which to wait for it to become ready for reading or writing. -// (field $file_descriptor $fd) -// ) -// ) -// -// ;;; The contents of a `subscription`. -// (typename $subscription_u -// (union (@witx tag $eventtype) -// $subscription_clock -// $subscription_fd_readwrite -// $subscription_fd_readwrite -// ) -// ) -// -// ;;; Subscription to an event. -// (typename $subscription -// (record -// ;;; User-provided value that is attached to the subscription in the -// ;;; implementation and returned through `event::userdata`. -// (field $userdata $userdata) -// ;;; The type of the event to which to subscribe. -// (field $u $subscription_u) -// ) -// ) -// -// ;;; Exit code generated by a process when exiting. -// (typename $exitcode u32) -// -// ;;; Signal condition. -// (typename $signal -// (enum (@witx tag u8) -// ;;; No signal. Note that POSIX has special semantics for `kill(pid, 0)`, -// ;;; so this value is reserved. -// $none -// ;;; Hangup. -// ;;; Action: Terminates the process. -// $hup -// ;;; Terminate interrupt signal. -// ;;; Action: Terminates the process. -// $int -// ;;; Terminal quit signal. -// ;;; Action: Terminates the process. -// $quit -// ;;; Illegal instruction. -// ;;; Action: Terminates the process. -// $ill -// ;;; Trace/breakpoint trap. -// ;;; Action: Terminates the process. -// $trap -// ;;; Process abort signal. -// ;;; Action: Terminates the process. -// $abrt -// ;;; Access to an undefined portion of a memory object. -// ;;; Action: Terminates the process. -// $bus -// ;;; Erroneous arithmetic operation. -// ;;; Action: Terminates the process. -// $fpe -// ;;; Kill. -// ;;; Action: Terminates the process. -// $kill -// ;;; User-defined signal 1. -// ;;; Action: Terminates the process. -// $usr1 -// ;;; Invalid memory reference. -// ;;; Action: Terminates the process. -// $segv -// ;;; User-defined signal 2. -// ;;; Action: Terminates the process. -// $usr2 -// ;;; Write on a pipe with no one to read it. -// ;;; Action: Ignored. -// $pipe -// ;;; Alarm clock. -// ;;; Action: Terminates the process. -// $alrm -// ;;; Termination signal. -// ;;; Action: Terminates the process. -// $term -// ;;; Child process terminated, stopped, or continued. -// ;;; Action: Ignored. -// $chld -// ;;; Continue executing, if stopped. -// ;;; Action: Continues executing, if stopped. -// $cont -// ;;; Stop executing. -// ;;; Action: Stops executing. -// $stop -// ;;; Terminal stop signal. -// ;;; Action: Stops executing. -// $tstp -// ;;; Background process attempting read. -// ;;; Action: Stops executing. -// $ttin -// ;;; Background process attempting write. -// ;;; Action: Stops executing. -// $ttou -// ;;; High bandwidth data is available at a socket. -// ;;; Action: Ignored. -// $urg -// ;;; CPU time limit exceeded. -// ;;; Action: Terminates the process. -// $xcpu -// ;;; File size limit exceeded. -// ;;; Action: Terminates the process. -// $xfsz -// ;;; Virtual timer expired. -// ;;; Action: Terminates the process. -// $vtalrm -// ;;; Profiling timer expired. -// ;;; Action: Terminates the process. -// $prof -// ;;; Window changed. -// ;;; Action: Ignored. -// $winch -// ;;; I/O possible. -// ;;; Action: Terminates the process. -// $poll -// ;;; Power failure. -// ;;; Action: Terminates the process. -// $pwr -// ;;; Bad system call. -// ;;; Action: Terminates the process. -// $sys -// ) -// ) -// -// ;;; Flags provided to `sock_recv`. -// (typename $riflags -// (flags (@witx repr u16) -// ;;; Returns the message without removing it from the socket's receive queue. -// $recv_peek -// ;;; On byte-stream sockets, block until the full amount of data can be returned. -// $recv_waitall -// ) -// ) -// -// ;;; Flags returned by `sock_recv`. -// (typename $roflags -// (flags (@witx repr u16) -// ;;; Returned by `sock_recv`: Message data has been truncated. -// $recv_data_truncated -// ) -// ) -// -// ;;; Flags provided to `sock_send`. As there are currently no flags -// ;;; defined, it must be set to zero. -// (typename $siflags u16) -// -// ;;; Which channels on a socket to shut down. -// (typename $sdflags -// (flags (@witx repr u8) -// ;;; Disables further receive operations. -// $rd -// ;;; Disables further send operations. -// $wr -// ) -// ) - -// ;;; The contents of a $prestat when type is `preopentype::dir`. -// (typename $prestat_dir -// (record -// ;;; The length of the directory name for use with `fd_prestat_dir_name`. -// (field $pr_name_len $size) -// ) -// ) -// -// ;;; Information about a pre-opened capability. -// (typename $prestat -// (union (@witx tag $preopentype) -// $prestat_dir -// ) -// ) From 69e3114ac0a21fce609facdc0772dc2a51adf121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 7 Sep 2022 10:38:43 +0200 Subject: [PATCH 44/84] Port BusDataFormat --- lib/wasi-types-generated/Cargo.toml | 4 +- lib/wasi-types-generated/regenerate.sh | 2 + lib/wasi-types-generated/src/wasi/bindings.rs | 53 +- lib/wasi-types-generated/src/wasi/mod.rs | 675 +++++++++--------- lib/wasi-types-generated/wit-clean/output.wit | 12 +- .../wit-clean/typenames.wit | 11 + lib/wasi-types/Cargo.toml | 2 + lib/wasi-types/src/bus.rs | 9 +- 8 files changed, 424 insertions(+), 344 deletions(-) diff --git a/lib/wasi-types-generated/Cargo.toml b/lib/wasi-types-generated/Cargo.toml index 9be33fa8d19..86ea43b5936 100644 --- a/lib/wasi-types-generated/Cargo.toml +++ b/lib/wasi-types-generated/Cargo.toml @@ -16,5 +16,5 @@ branch = "main" package = "wit-bindgen-rust" [features] -js = [] -sys = [] +js = ["wasmer/js"] +sys = ["wasmer/sys"] diff --git a/lib/wasi-types-generated/regenerate.sh b/lib/wasi-types-generated/regenerate.sh index a0fa78e636c..97a1ba0b5f0 100755 --- a/lib/wasi-types-generated/regenerate.sh +++ b/lib/wasi-types-generated/regenerate.sh @@ -12,3 +12,5 @@ wit-bindgen rust-wasm \ --import \ "$BASEDIR"/wit-clean/output.wit \ --out-dir "$BASEDIR"/src/wasi + +# sed "mod output" "pub mod output" \ No newline at end of file diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index 8814f04a38f..984d853a9ec 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -1406,8 +1406,46 @@ pub mod output { 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() + } + } + } + } /// Dummy function to expose types into generated code - pub fn expose_types_dummy_func(fd: Fd,dirent: Dirent,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,tid: Tid,pid: Pid,) -> (){ + pub fn expose_types_dummy_func(fd: Fd,dirent: Dirent,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,tid: Tid,pid: Pid,busdataformat: Busdataformat,) -> (){ unsafe { let ptr0 = OUTPUT_RET_AREA.0.as_mut_ptr() as i32; *((ptr0 + 0) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd); @@ -1714,6 +1752,15 @@ pub mod output { *((ptr0 + 460) as *mut u8) = (match line_buffered31 { true => 1, false => 0 }) as u8; *((ptr0 + 464) as *mut i32) = wit_bindgen_rust::rt::as_i32(tid); *((ptr0 + 468) as *mut i32) = wit_bindgen_rust::rt::as_i32(pid); + *((ptr0 + 472) as *mut u8) = (match busdataformat { + Busdataformat::Raw => 0, + Busdataformat::Bincode => 1, + Busdataformat::MessagePack => 2, + Busdataformat::Json => 3, + Busdataformat::Yaml => 4, + Busdataformat::Xml => 5, + Busdataformat::Rkyv => 6, + }) as u8; #[link(wasm_import_module = "output")] extern "C" { #[cfg_attr(target_arch = "wasm32", link_name = "expose-types-dummy-func")] @@ -1726,6 +1773,6 @@ pub mod output { } #[repr(align(8))] - struct RetArea([u8; 472]); - static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 472]); + struct RetArea([u8; 480]); + static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 480]); } diff --git a/lib/wasi-types-generated/src/wasi/mod.rs b/lib/wasi-types-generated/src/wasi/mod.rs index 87ce687a2af..355f4ccdab5 100644 --- a/lib/wasi-types-generated/src/wasi/mod.rs +++ b/lib/wasi-types-generated/src/wasi/mod.rs @@ -4,6 +4,12 @@ pub use bindings::output::*; use std::mem::MaybeUninit; use wasmer::ValueType; +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl ValueType for Busdataformat { + #[inline] + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} +} + // TODO: if necessary, must be implemented in wit-bindgen unsafe impl ValueType for Errno { #[inline] @@ -789,9 +795,8 @@ impl std::fmt::Display for Sockoption { } } -/* // TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_rust::FromToNativeWasmType for Errno { +unsafe impl wasmer::FromToNativeWasmType for Errno { type Native = i32; fn to_native(self) -> Self::Native { @@ -882,415 +887,416 @@ unsafe impl wit_bindgen_rust::FromToNativeWasmType for Errno { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { + 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 wit_bindgen_rust::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, - // TODO: What should we map invalid native values to? - _ => Self::Unknown, +/* + // TODO: if necessary, must be implemented in wit-bindgen + unsafe impl wit_bindgen_rust::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, + // TODO: What should we map invalid native values to? + _ => Self::Unknown, + } } - } - - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_rust::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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { + // TODO: find correct implementation + false } } - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} + // TODO: if necessary, must be implemented in wit-bindgen + unsafe impl wit_bindgen_rust::FromToNativeWasmType for Advice { + type Native = i32; -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_rust::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::Normal, + 1 => Self::Sequential, + 2 => Self::Random, + 3 => Self::Willneed, + 4 => Self::Dontneed, + 5 => Self::Noreuse, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } + } - 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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { + // TODO: find correct implementation + false } } - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} + // TODO: if necessary, must be implemented in wit-bindgen + unsafe impl wit_bindgen_rust::FromToNativeWasmType for Socktype { + type Native = i32; -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_rust::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::Dgram, + 1 => Self::Stream, + 2 => Self::Raw, + 3 => Self::Seqpacket, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } + } - 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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { + // TODO: find correct implementation + false } } - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} + // TODO: if necessary, must be implemented in wit-bindgen + unsafe impl wit_bindgen_rust::FromToNativeWasmType for Sockstatus { + type Native = i32; -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_rust::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::Opening, + 1 => Self::Opened, + 2 => Self::Closed, + 3 => Self::Failed, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } + } - 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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { + // TODO: find correct implementation + false } } - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} + // TODO: if necessary, must be implemented in wit-bindgen + unsafe impl wit_bindgen_rust::FromToNativeWasmType for Streamsecurity { + type Native = i32; -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_rust::FromToNativeWasmType for Rights { - type Native = i64; + 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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } + } - fn to_native(self) -> Self::Native { - self.bits() as i64 + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } } - fn from_native(n: Self::Native) -> Self { - Self::from_bits_truncate(n as u64) - } + // TODO: if necessary, must be implemented in wit-bindgen + unsafe impl wit_bindgen_rust::FromToNativeWasmType for Rights { + type Native = i64; - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} + fn to_native(self) -> Self::Native { + self.bits() as i64 + } -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_rust::FromToNativeWasmType for Eventrwflags { - type Native = i32; + fn from_native(n: Self::Native) -> Self { + Self::from_bits_truncate(n as u64) + } - fn to_native(self) -> Self::Native { - self.bits() as i32 - } - fn from_native(n: Self::Native) -> Self { - Self::from_bits_truncate(n as u8) + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } } - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} + // TODO: if necessary, must be implemented in wit-bindgen + unsafe impl wit_bindgen_rust::FromToNativeWasmType for Eventrwflags { + type Native = i32; -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_rust::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 u8) + } - fn to_native(self) -> Self::Native { - self.bits() as i32 - } - fn from_native(n: Self::Native) -> Self { - Self::from_bits_truncate(n as u8) + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } } - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} + // TODO: if necessary, must be implemented in wit-bindgen + unsafe impl wit_bindgen_rust::FromToNativeWasmType for Fstflags { + type Native = i32; -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_rust::FromToNativeWasmType for Subclockflags { - 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 u8) + } - fn to_native(self) -> Self::Native { - self.bits() as i32 - } - fn from_native(n: Self::Native) -> Self { - Self::from_bits_truncate(n as u8) + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } } - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} + // TODO: if necessary, must be implemented in wit-bindgen + unsafe impl wit_bindgen_rust::FromToNativeWasmType for Subclockflags { + type Native = i32; -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_rust::FromToNativeWasmType for Clockid { - 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 u8) + } - fn to_native(self) -> Self::Native { - self as i32 - } - fn from_native(n: Self::Native) -> Self { - match n { - 0 => Self::Realtime, - 1 => Self::Monotonic, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { + // TODO: find correct implementation + false } } - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} + // TODO: if necessary, must be implemented in wit-bindgen + unsafe impl wit_bindgen_rust::FromToNativeWasmType for Clockid { + type Native = i32; -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_rust::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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } + } - 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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { + // TODO: find correct implementation + false } } - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} + // TODO: if necessary, must be implemented in wit-bindgen + unsafe impl wit_bindgen_rust::FromToNativeWasmType for Snapshot0Clockid { + type Native = i32; -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_rust::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::Realtime, + 1 => Self::Monotonic, + 2 => Self::ProcessCputimeId, + 3 => Self::ThreadCputimeId, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } + } - 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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } + } + + // TODO: if necessary, must be implemented in wit-bindgen + unsafe impl wit_bindgen_rust::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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } } - } - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } } -} -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_rust::FromToNativeWasmType for Fdflags { - type Native = i32; + // TODO: if necessary, must be implemented in wit-bindgen + unsafe impl wit_bindgen_rust::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 u8) - } + fn to_native(self) -> Self::Native { + self.bits() as i32 + } + fn from_native(n: Self::Native) -> Self { + Self::from_bits_truncate(n as u8) + } - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } } -} -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_rust::FromToNativeWasmType for Preopentype { - type Native = i32; + // TODO: if necessary, must be implemented in wit-bindgen + unsafe impl wit_bindgen_rust::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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), + fn to_native(self) -> Self::Native { + self as i32 + } + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::Dir, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } } - } - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } } -} -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_rust::FromToNativeWasmType for Addressfamily { - type Native = i32; + // TODO: if necessary, must be implemented in wit-bindgen + unsafe impl wit_bindgen_rust::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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), + 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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } } - } - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } } -} -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_rust::FromToNativeWasmType for Snapshot0Whence { - type Native = i32; + // TODO: if necessary, must be implemented in wit-bindgen + unsafe impl wit_bindgen_rust::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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), + 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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } } - } - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } } -} -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl wit_bindgen_rust::FromToNativeWasmType for Whence { + // TODO: if necessary, must be implemented in wit-bindgen + unsafe impl wit_bindgen_rust::FromToNativeWasmType for Whence { type Native = i32; fn to_native(self) -> Self::Native { @@ -1313,6 +1319,7 @@ unsafe impl wit_bindgen_rust::FromToNativeWasmType for Whence { } } */ + // TODO: if necessary, must be implemented in wit-bindgen unsafe impl ValueType for Snapshot0Clockid { #[inline] diff --git a/lib/wasi-types-generated/wit-clean/output.wit b/lib/wasi-types-generated/wit-clean/output.wit index 8a166fcaf21..728f023d23a 100644 --- a/lib/wasi-types-generated/wit-clean/output.wit +++ b/lib/wasi-types-generated/wit-clean/output.wit @@ -23,6 +23,7 @@ expose-types-dummy-func: func( tty: tty, tid: tid, pid: pid, + busdataformat: busdataformat, ) @@ -812,7 +813,16 @@ record tty { echo: bool, line-buffered: bool, } -// WASI Preview. This is an evolution of the API that WASI initially + +enum busdataformat { + raw, + bincode, + message-pack, + json, + yaml, + xml, + rkyv, +}// 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). diff --git a/lib/wasi-types-generated/wit-clean/typenames.wit b/lib/wasi-types-generated/wit-clean/typenames.wit index 019d3bf0184..02ffa4e1cb4 100644 --- a/lib/wasi-types-generated/wit-clean/typenames.wit +++ b/lib/wasi-types-generated/wit-clean/typenames.wit @@ -23,6 +23,7 @@ expose-types-dummy-func: func( tty: tty, tid: tid, pid: pid, + busdataformat: busdataformat, ) @@ -812,3 +813,13 @@ record tty { echo: bool, line-buffered: bool, } + +enum busdataformat { + raw, + bincode, + message-pack, + json, + yaml, + xml, + rkyv, +} \ No newline at end of file diff --git a/lib/wasi-types/Cargo.toml b/lib/wasi-types/Cargo.toml index bfcef194396..326d61d4ed2 100644 --- a/lib/wasi-types/Cargo.toml +++ b/lib/wasi-types/Cargo.toml @@ -20,3 +20,5 @@ time = "0.2" [features] enable-serde = ["serde", "wasmer-types/serde"] +sys = ["wasmer-wasi-types-generated/sys"] +js = ["wasmer-wasi-types-generated/js"] \ No newline at end of file diff --git a/lib/wasi-types/src/bus.rs b/lib/wasi-types/src/bus.rs index 737db4b0194..38a0314689a 100644 --- a/lib/wasi-types/src/bus.rs +++ b/lib/wasi-types/src/bus.rs @@ -1,8 +1,9 @@ use super::*; use wasmer_derive::ValueType; use wasmer_types::MemorySize; -use wasmer_wasi_types_generated::wasi::{BusErrno, Fd}; +use wasmer_wasi_types_generated::wasi::{BusErrno, Fd, Busdataformat}; +/* 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; @@ -11,7 +12,7 @@ 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; @@ -66,7 +67,7 @@ pub struct __wasi_busevent_exit_t { pub struct __wasi_busevent_call_t { pub parent: __wasi_option_cid_t, pub cid: __wasi_cid_t, - pub format: __wasi_busdataformat_t, + pub format: Busdataformat, pub topic_ptr: M::Offset, pub topic_len: M::Offset, pub buf_ptr: M::Offset, @@ -76,7 +77,7 @@ pub struct __wasi_busevent_call_t { #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] #[repr(C)] pub struct __wasi_busevent_result_t { - pub format: __wasi_busdataformat_t, + pub format: Busdataformat, pub cid: __wasi_cid_t, pub buf_ptr: M::Offset, pub buf_len: M::Offset, From 8983637d669e85c21b3bf46cf4bacd7052c01538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 7 Sep 2022 13:07:50 +0200 Subject: [PATCH 45/84] Use awk instead of sed to resolve build issues in regenerate.sh --- lib/api/src/sys/module.rs | 10 +++++++--- lib/api/src/sys/store.rs | 6 ++++-- lib/wasi-types-generated/regenerate.sh | 4 +++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/api/src/sys/module.rs b/lib/api/src/sys/module.rs index b730a19b9dd..a8d58ccc5a5 100644 --- a/lib/api/src/sys/module.rs +++ b/lib/api/src/sys/module.rs @@ -193,7 +193,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 /// @@ -210,8 +212,10 @@ impl Module { self.artifact.serialize() } - /// Serializes a module into a file that the `Engine` - /// can later process via [`Module::deserialize_from_file`]. + /// Serializes a module into a file that the `Engine` + /// 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..d9b8a6ba446 100644 --- a/lib/api/src/sys/store.rs +++ b/lib/api/src/sys/store.rs @@ -26,8 +26,10 @@ 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 { pub(crate) inner: Box, diff --git a/lib/wasi-types-generated/regenerate.sh b/lib/wasi-types-generated/regenerate.sh index 97a1ba0b5f0..f21ffbdc4a7 100755 --- a/lib/wasi-types-generated/regenerate.sh +++ b/lib/wasi-types-generated/regenerate.sh @@ -13,4 +13,6 @@ wit-bindgen rust-wasm \ "$BASEDIR"/wit-clean/output.wit \ --out-dir "$BASEDIR"/src/wasi -# sed "mod output" "pub mod output" \ No newline at end of file +awk '{sub(/mod output/,"pub mod output")}1' src/wasi/bindings.rs > src/wasi/bindings2.rs +cp src/wasi/bindings2.rs src/wasi/bindings.rs +rm src/wasi/bindings2.rs \ No newline at end of file From b485e4576b0a93516df43d9c7ad494368fa22976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 7 Sep 2022 13:14:11 +0200 Subject: [PATCH 46/84] Add BusEventType --- lib/wasi-types-generated/src/wasi/bindings.rs | 84 +++++++++++++------ lib/wasi-types-generated/src/wasi/mod.rs | 8 +- lib/wasi-types-generated/wit-clean/output.wit | 16 +++- .../wit-clean/typenames.wit | 15 +++- lib/wasi-types/src/bus.rs | 29 ++----- 5 files changed, 98 insertions(+), 54 deletions(-) diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index 984d853a9ec..0d363c954b2 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -1408,7 +1408,7 @@ pub mod output { } #[repr(u8)] #[derive(Clone, Copy, PartialEq, Eq)] - pub enum Busdataformat { + pub enum BusDataFormat { Raw, Bincode, MessagePack, @@ -1417,35 +1417,69 @@ pub mod output { Xml, Rkyv, } - impl core::fmt::Debug for Busdataformat { + 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::Raw => { + f.debug_tuple("BusDataFormat::Raw").finish() } - Busdataformat::Bincode => { - f.debug_tuple("Busdataformat::Bincode").finish() + BusDataFormat::Bincode => { + f.debug_tuple("BusDataFormat::Bincode").finish() } - Busdataformat::MessagePack => { - f.debug_tuple("Busdataformat::MessagePack").finish() + BusDataFormat::MessagePack => { + f.debug_tuple("BusDataFormat::MessagePack").finish() } - Busdataformat::Json => { - f.debug_tuple("Busdataformat::Json").finish() + BusDataFormat::Json => { + f.debug_tuple("BusDataFormat::Json").finish() } - Busdataformat::Yaml => { - f.debug_tuple("Busdataformat::Yaml").finish() + BusDataFormat::Yaml => { + f.debug_tuple("BusDataFormat::Yaml").finish() } - Busdataformat::Xml => { - f.debug_tuple("Busdataformat::Xml").finish() + BusDataFormat::Xml => { + f.debug_tuple("BusDataFormat::Xml").finish() } - Busdataformat::Rkyv => { - f.debug_tuple("Busdataformat::Rkyv").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() } } } } /// Dummy function to expose types into generated code - pub fn expose_types_dummy_func(fd: Fd,dirent: Dirent,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,tid: Tid,pid: Pid,busdataformat: Busdataformat,) -> (){ + pub fn expose_types_dummy_func(fd: Fd,dirent: Dirent,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,tid: Tid,pid: Pid,bus_data_format: BusDataFormat,) -> (){ unsafe { let ptr0 = OUTPUT_RET_AREA.0.as_mut_ptr() as i32; *((ptr0 + 0) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd); @@ -1752,14 +1786,14 @@ pub mod output { *((ptr0 + 460) as *mut u8) = (match line_buffered31 { true => 1, false => 0 }) as u8; *((ptr0 + 464) as *mut i32) = wit_bindgen_rust::rt::as_i32(tid); *((ptr0 + 468) as *mut i32) = wit_bindgen_rust::rt::as_i32(pid); - *((ptr0 + 472) as *mut u8) = (match busdataformat { - Busdataformat::Raw => 0, - Busdataformat::Bincode => 1, - Busdataformat::MessagePack => 2, - Busdataformat::Json => 3, - Busdataformat::Yaml => 4, - Busdataformat::Xml => 5, - Busdataformat::Rkyv => 6, + *((ptr0 + 472) as *mut u8) = (match bus_data_format { + BusDataFormat::Raw => 0, + BusDataFormat::Bincode => 1, + BusDataFormat::MessagePack => 2, + BusDataFormat::Json => 3, + BusDataFormat::Yaml => 4, + BusDataFormat::Xml => 5, + BusDataFormat::Rkyv => 6, }) as u8; #[link(wasm_import_module = "output")] extern "C" { diff --git a/lib/wasi-types-generated/src/wasi/mod.rs b/lib/wasi-types-generated/src/wasi/mod.rs index 355f4ccdab5..fd62b1c0754 100644 --- a/lib/wasi-types-generated/src/wasi/mod.rs +++ b/lib/wasi-types-generated/src/wasi/mod.rs @@ -5,7 +5,13 @@ use std::mem::MaybeUninit; use wasmer::ValueType; // TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for Busdataformat { +unsafe impl ValueType for BusEventType { + #[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]) {} } diff --git a/lib/wasi-types-generated/wit-clean/output.wit b/lib/wasi-types-generated/wit-clean/output.wit index 728f023d23a..c3d0b3c5ca1 100644 --- a/lib/wasi-types-generated/wit-clean/output.wit +++ b/lib/wasi-types-generated/wit-clean/output.wit @@ -23,7 +23,7 @@ expose-types-dummy-func: func( tty: tty, tid: tid, pid: pid, - busdataformat: busdataformat, + bus-data-format: bus-data-format, ) @@ -814,7 +814,7 @@ record tty { line-buffered: bool, } -enum busdataformat { +enum bus-data-format { raw, bincode, message-pack, @@ -822,7 +822,17 @@ enum busdataformat { yaml, xml, rkyv, -}// WASI Preview. This is an evolution of the API that WASI initially +} + +enum bus-event-type { + noop, + exit, + call, + result, + fault, + close, +} +// 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). diff --git a/lib/wasi-types-generated/wit-clean/typenames.wit b/lib/wasi-types-generated/wit-clean/typenames.wit index 02ffa4e1cb4..9f56860fbba 100644 --- a/lib/wasi-types-generated/wit-clean/typenames.wit +++ b/lib/wasi-types-generated/wit-clean/typenames.wit @@ -23,7 +23,7 @@ expose-types-dummy-func: func( tty: tty, tid: tid, pid: pid, - busdataformat: busdataformat, + bus-data-format: bus-data-format, ) @@ -814,7 +814,7 @@ record tty { line-buffered: bool, } -enum busdataformat { +enum bus-data-format { raw, bincode, message-pack, @@ -822,4 +822,13 @@ enum busdataformat { yaml, xml, rkyv, -} \ No newline at end of file +} + +enum bus-event-type { + noop, + exit, + call, + result, + fault, + close, +} diff --git a/lib/wasi-types/src/bus.rs b/lib/wasi-types/src/bus.rs index 38a0314689a..f301838c252 100644 --- a/lib/wasi-types/src/bus.rs +++ b/lib/wasi-types/src/bus.rs @@ -1,25 +1,10 @@ use super::*; use wasmer_derive::ValueType; use wasmer_types::MemorySize; -use wasmer_wasi_types_generated::wasi::{BusErrno, Fd, Busdataformat}; - -/* -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; +use wasmer_wasi_types_generated::wasi::{ + BusErrno, Fd, BusDataFormat, + BusEventType +}; pub type __wasi_bid_t = u32; @@ -67,7 +52,7 @@ pub struct __wasi_busevent_exit_t { pub struct __wasi_busevent_call_t { pub parent: __wasi_option_cid_t, pub cid: __wasi_cid_t, - pub format: Busdataformat, + pub format: BusDataFormat, pub topic_ptr: M::Offset, pub topic_len: M::Offset, pub buf_ptr: M::Offset, @@ -77,7 +62,7 @@ pub struct __wasi_busevent_call_t { #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] #[repr(C)] pub struct __wasi_busevent_result_t { - pub format: Busdataformat, + pub format: BusDataFormat, pub cid: __wasi_cid_t, pub buf_ptr: M::Offset, pub buf_len: M::Offset, @@ -110,6 +95,6 @@ pub union __wasi_busevent_u { #[derive(Copy, Clone)] #[repr(C)] pub struct __wasi_busevent_t { - pub tag: __wasi_buseventtype_t, + pub tag: BusEventType, pub u: __wasi_busevent_u, } From e7e8e9df8af5d56158aaed636007c1056c870abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 7 Sep 2022 13:53:32 +0200 Subject: [PATCH 47/84] Fix errors in BusDataFormat --- lib/api/src/sys/module.rs | 6 +- lib/api/src/sys/store.rs | 2 +- lib/wasi-types-generated/src/wasi/bindings.rs | 3482 +++++++++-------- lib/wasi-types-generated/src/wasi/mod.rs | 727 ++-- lib/wasi-types/src/bus.rs | 5 +- lib/wasi/src/syscalls/mod.rs | 8 +- lib/wasi/src/syscalls/wasix32.rs | 12 +- lib/wasi/src/syscalls/wasix64.rs | 8 +- 8 files changed, 2171 insertions(+), 2079 deletions(-) diff --git a/lib/api/src/sys/module.rs b/lib/api/src/sys/module.rs index 637bb3f2243..4b6807178ae 100644 --- a/lib/api/src/sys/module.rs +++ b/lib/api/src/sys/module.rs @@ -234,7 +234,7 @@ impl Module { } /// Serializes a module into a binary representation that the `Engine` - /// can later process via + /// can later process via #[cfg_attr(feature = "compiler", doc = "[`Module::deserialize`].")] #[cfg_attr(not(feature = "compiler"), doc = "`Module::deserialize`.")] /// @@ -253,8 +253,8 @@ impl Module { self.artifact.serialize().map(|bytes| bytes.into()) } - /// Serializes a module into a file that the `Engine` - /// can later process via + /// Serializes a module into a file that the `Engine` + /// can later process via #[cfg_attr(feature = "compiler", doc = "[`Module::deserialize_from_file`].")] #[cfg_attr(not(feature = "compiler"), doc = "`Module::deserialize_from_file`.")] /// diff --git a/lib/api/src/sys/store.rs b/lib/api/src/sys/store.rs index d9b8a6ba446..e8d7ea44a37 100644 --- a/lib/api/src/sys/store.rs +++ b/lib/api/src/sys/store.rs @@ -29,7 +29,7 @@ pub(crate) struct StoreInner { #[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 { pub(crate) inner: Box, diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index 0d363c954b2..e641233d782 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -1,1812 +1,1848 @@ #[allow(clippy::all)] pub mod output { - /// 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() + /// 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() + } + } } - Snapshot0Clockid::ProcessCputimeId => { - f.debug_tuple("Snapshot0Clockid::ProcessCputimeId").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(), + } } - Snapshot0Clockid::ThreadCputimeId => { - f.debug_tuple("Snapshot0Clockid::ThreadCputimeId").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.", + } } - } } - } - /// 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() + 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() } - Clockid::Monotonic => { - f.debug_tuple("Clockid::Monotonic").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) } - } } - } - /// 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", - } + + 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, } - 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 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 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", - } + 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) + } } - 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 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 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 { + 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() + Self { bits } } - 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. - #[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() + /// 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(), + } } - Advice::Dontneed => { - f.debug_tuple("Advice::Dontneed").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() } - Advice::Noreuse => { - f.debug_tuple("Advice::Noreuse").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; } } - } - 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 { + impl Fdflags { /// Convert from a raw integer, preserving any unknown bits. See /// pub fn from_bits_preserve(bits: u8) -> Self { - Self { bits } + 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. - 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 } + } + /// 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! { - /// Flags determining the method of how paths are resolved. - 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 { + } + wit_bindgen_rust::bitflags::bitflags! { + /// Which file time attributes to adjust. + 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 } + Self { bits } } - } - wit_bindgen_rust::bitflags::bitflags! { - /// Open flags used by `path_open`. - 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 { + } + wit_bindgen_rust::bitflags::bitflags! { + /// Flags determining the method of how paths are resolved. + 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 } - } - } - /// 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() + Self { bits } } + } + wit_bindgen_rust::bitflags::bitflags! { + /// Open flags used by `path_open`. + 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; } } - } - 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 { + impl Oflags { /// Convert from a raw integer, preserving any unknown bits. See /// pub fn from_bits_preserve(bits: u8) -> Self { - Self { bits } + 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() + } + /// 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! { - /// 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; + 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 Eventrwflags { + impl Subclockflags { /// Convert from a raw integer, preserving any unknown bits. See /// pub fn from_bits_preserve(bits: u8) -> Self { - Self { bits } + 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() - } - } } - } - /// 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` 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, } - } - /// 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() + 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 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() - } - } + /// 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, } - } - #[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() + 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() } - 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() - } - } + /// Identifiers for preopened capabilities. + #[repr(u8)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub enum Preopentype { + /// A pre-opened directory. + Dir, } - } - #[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() + 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; } } - } - #[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() + impl Eventrwflags { + /// Convert from a raw integer, preserving any unknown bits. See + /// + pub fn from_bits_preserve(bits: u8) -> Self { + Self { bits } } - } } - } - #[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() + /// 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() } - Snapshot0Whence::End => { - f.debug_tuple("Snapshot0Whence::End").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() } - Snapshot0Whence::Set => { - f.debug_tuple("Snapshot0Whence::Set").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(), + } } - } } - } - #[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() + /// 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(), + } } - Whence::Cur => { - f.debug_tuple("Whence::Cur").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() + } + } } - Whence::End => { - f.debug_tuple("Whence::End").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 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() + #[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() } - BusDataFormat::Bincode => { - f.debug_tuple("BusDataFormat::Bincode").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() } - BusDataFormat::MessagePack => { - f.debug_tuple("BusDataFormat::MessagePack").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(), + } } - BusDataFormat::Json => { - f.debug_tuple("BusDataFormat::Json").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(), + } } - BusDataFormat::Yaml => { - f.debug_tuple("BusDataFormat::Yaml").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(), + } } - BusDataFormat::Xml => { - f.debug_tuple("BusDataFormat::Xml").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() + } + } } - BusDataFormat::Rkyv => { - f.debug_tuple("BusDataFormat::Rkyv").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(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() + #[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() } - BusEventType::Exit => { - f.debug_tuple("BusEventType::Exit").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() } - BusEventType::Call => { - f.debug_tuple("BusEventType::Call").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(), + } } - BusEventType::Result => { - f.debug_tuple("BusEventType::Result").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(), + } } - BusEventType::Fault => { - f.debug_tuple("BusEventType::Fault").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() } - BusEventType::Close => { - f.debug_tuple("BusEventType::Close").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(), + } } - } } - } - /// Dummy function to expose types into generated code - pub fn expose_types_dummy_func(fd: Fd,dirent: Dirent,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,tid: Tid,pid: Pid,bus_data_format: BusDataFormat,) -> (){ - unsafe { - let ptr0 = OUTPUT_RET_AREA.0.as_mut_ptr() as i32; - *((ptr0 + 0) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd); - let Dirent{ d_next:d_next1, d_ino:d_ino1, d_type:d_type1, d_namlen:d_namlen1, } = dirent; - *((ptr0 + 8) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_next1); - *((ptr0 + 16) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_ino1); - *((ptr0 + 24) as *mut u8) = (match d_type1 { - Filetype::Unknown => 0, - Filetype::BlockDevice => 1, - Filetype::CharacterDevice => 2, - Filetype::Directory => 3, - Filetype::RegularFile => 4, - Filetype::SocketDgram => 5, - Filetype::SocketStream => 6, - Filetype::SymbolicLink => 7, - Filetype::Fifo => 8, - }) as u8; - *((ptr0 + 28) as *mut i32) = wit_bindgen_rust::rt::as_i32(d_namlen1); - match event_enum { - EventEnum::FdRead(e) => { - *((ptr0 + 32) as *mut u8) = (0i32) as u8; - let EventFdReadwrite{ nbytes:nbytes2, flags:flags2, } = e; - *((ptr0 + 40) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes2); - let flags3 = flags2; - *((ptr0 + 48) as *mut u8) = ((flags3.bits() >> 0) as i32) as u8; - - }, - EventEnum::FdWrite(e) => { - *((ptr0 + 32) as *mut u8) = (1i32) as u8; - let EventFdReadwrite{ nbytes:nbytes4, flags:flags4, } = e; - *((ptr0 + 40) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes4); - let flags5 = flags4; - *((ptr0 + 48) as *mut u8) = ((flags5.bits() >> 0) as i32) as u8; - - }, - EventEnum::Clock=> { - let e = (); - { - *((ptr0 + 32) as *mut u8) = (2i32) as u8; - let () = e; - - } + #[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(), + } } - }; - let Event{ userdata:userdata6, error:error6, data:data6, } = event; - *((ptr0 + 56) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata6); - *((ptr0 + 64) as *mut u8) = (match error6 { - Errno::Success => 0, - Errno::Toobig => 1, - Errno::Access => 2, - Errno::Addrinuse => 3, - Errno::Addrnotavail => 4, - Errno::Afnosupport => 5, - Errno::Again => 6, - Errno::Already => 7, - Errno::Badf => 8, - Errno::Badmsg => 9, - Errno::Busy => 10, - Errno::Canceled => 11, - Errno::Child => 12, - Errno::Connaborted => 13, - Errno::Connrefused => 14, - Errno::Connreset => 15, - Errno::Deadlk => 16, - Errno::Destaddrreq => 17, - Errno::Dom => 18, - Errno::Dquot => 19, - Errno::Exist => 20, - Errno::Fault => 21, - Errno::Fbig => 22, - Errno::Hostunreach => 23, - Errno::Idrm => 24, - Errno::Ilseq => 25, - Errno::Inprogress => 26, - Errno::Intr => 27, - Errno::Inval => 28, - Errno::Io => 29, - Errno::Isconn => 30, - Errno::Isdir => 31, - Errno::Loop => 32, - Errno::Mfile => 33, - Errno::Mlink => 34, - Errno::Msgsize => 35, - Errno::Multihop => 36, - Errno::Nametoolong => 37, - Errno::Netdown => 38, - Errno::Netreset => 39, - Errno::Netunreach => 40, - Errno::Nfile => 41, - Errno::Nobufs => 42, - Errno::Nodev => 43, - Errno::Noent => 44, - Errno::Noexec => 45, - Errno::Nolck => 46, - Errno::Nolink => 47, - Errno::Nomem => 48, - Errno::Nomsg => 49, - Errno::Noprotoopt => 50, - Errno::Nospc => 51, - Errno::Nosys => 52, - Errno::Notconn => 53, - Errno::Notdir => 54, - Errno::Notempty => 55, - Errno::Notrecoverable => 56, - Errno::Notsock => 57, - Errno::Notsup => 58, - Errno::Notty => 59, - Errno::Nxio => 60, - Errno::Overflow => 61, - Errno::Ownerdead => 62, - Errno::Perm => 63, - Errno::Pipe => 64, - Errno::Proto => 65, - Errno::Protonosupport => 66, - Errno::Prototype => 67, - Errno::Range => 68, - Errno::Rofs => 69, - Errno::Spipe => 70, - Errno::Srch => 71, - Errno::Stale => 72, - Errno::Timedout => 73, - Errno::Txtbsy => 74, - Errno::Xdev => 75, - Errno::Notcapable => 76, - }) as u8; - match data6 { - EventEnum::FdRead(e) => { - *((ptr0 + 72) as *mut u8) = (0i32) as u8; - let EventFdReadwrite{ nbytes:nbytes7, flags:flags7, } = e; - *((ptr0 + 80) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes7); - let flags8 = flags7; - *((ptr0 + 88) as *mut u8) = ((flags8.bits() >> 0) as i32) as u8; - - }, - EventEnum::FdWrite(e) => { - *((ptr0 + 72) as *mut u8) = (1i32) as u8; - let EventFdReadwrite{ nbytes:nbytes9, flags:flags9, } = e; - *((ptr0 + 80) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes9); - let flags10 = flags9; - *((ptr0 + 88) as *mut u8) = ((flags10.bits() >> 0) as i32) as u8; - - }, - EventEnum::Clock=> { - let e = (); - { - *((ptr0 + 72) as *mut u8) = (2i32) as u8; - let () = e; - - } + } + /// Dummy function to expose types into generated code + pub fn expose_types_dummy_func( + fd: Fd, + dirent: Dirent, + event_enum: EventEnum, + event: Event, + fdstat: Fdstat, + subscription_clock: SubscriptionClock, + snapshot0_subscription_clock: Snapshot0SubscriptionClock, + subscription: Subscription, + snapshot0_subscription: Snapshot0Subscription, + device: Device, + linkcount: Linkcount, + snapshot0_linkcount: Snapshot0Linkcount, + filestat: Filestat, + snapshot0_filestat: Snapshot0Filestat, + tty: Tty, + tid: Tid, + pid: Pid, + bus_data_format: BusDataFormat, + ) -> () { + unsafe { + let ptr0 = OUTPUT_RET_AREA.0.as_mut_ptr() as i32; + *((ptr0 + 0) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd); + let Dirent { + d_next: d_next1, + d_ino: d_ino1, + d_type: d_type1, + d_namlen: d_namlen1, + } = dirent; + *((ptr0 + 8) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_next1); + *((ptr0 + 16) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_ino1); + *((ptr0 + 24) as *mut u8) = (match d_type1 { + Filetype::Unknown => 0, + Filetype::BlockDevice => 1, + Filetype::CharacterDevice => 2, + Filetype::Directory => 3, + Filetype::RegularFile => 4, + Filetype::SocketDgram => 5, + Filetype::SocketStream => 6, + Filetype::SymbolicLink => 7, + Filetype::Fifo => 8, + }) as u8; + *((ptr0 + 28) as *mut i32) = wit_bindgen_rust::rt::as_i32(d_namlen1); + match event_enum { + EventEnum::FdRead(e) => { + *((ptr0 + 32) as *mut u8) = (0i32) as u8; + let EventFdReadwrite { + nbytes: nbytes2, + flags: flags2, + } = e; + *((ptr0 + 40) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes2); + let flags3 = flags2; + *((ptr0 + 48) as *mut u8) = ((flags3.bits() >> 0) as i32) as u8; + } + EventEnum::FdWrite(e) => { + *((ptr0 + 32) as *mut u8) = (1i32) as u8; + let EventFdReadwrite { + nbytes: nbytes4, + flags: flags4, + } = e; + *((ptr0 + 40) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes4); + let flags5 = flags4; + *((ptr0 + 48) as *mut u8) = ((flags5.bits() >> 0) as i32) as u8; + } + EventEnum::Clock => { + let e = (); + { + *((ptr0 + 32) as *mut u8) = (2i32) as u8; + let () = e; + } + } + }; + let Event { + userdata: userdata6, + error: error6, + data: data6, + } = event; + *((ptr0 + 56) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata6); + *((ptr0 + 64) as *mut u8) = (match error6 { + Errno::Success => 0, + Errno::Toobig => 1, + Errno::Access => 2, + Errno::Addrinuse => 3, + Errno::Addrnotavail => 4, + Errno::Afnosupport => 5, + Errno::Again => 6, + Errno::Already => 7, + Errno::Badf => 8, + Errno::Badmsg => 9, + Errno::Busy => 10, + Errno::Canceled => 11, + Errno::Child => 12, + Errno::Connaborted => 13, + Errno::Connrefused => 14, + Errno::Connreset => 15, + Errno::Deadlk => 16, + Errno::Destaddrreq => 17, + Errno::Dom => 18, + Errno::Dquot => 19, + Errno::Exist => 20, + Errno::Fault => 21, + Errno::Fbig => 22, + Errno::Hostunreach => 23, + Errno::Idrm => 24, + Errno::Ilseq => 25, + Errno::Inprogress => 26, + Errno::Intr => 27, + Errno::Inval => 28, + Errno::Io => 29, + Errno::Isconn => 30, + Errno::Isdir => 31, + Errno::Loop => 32, + Errno::Mfile => 33, + Errno::Mlink => 34, + Errno::Msgsize => 35, + Errno::Multihop => 36, + Errno::Nametoolong => 37, + Errno::Netdown => 38, + Errno::Netreset => 39, + Errno::Netunreach => 40, + Errno::Nfile => 41, + Errno::Nobufs => 42, + Errno::Nodev => 43, + Errno::Noent => 44, + Errno::Noexec => 45, + Errno::Nolck => 46, + Errno::Nolink => 47, + Errno::Nomem => 48, + Errno::Nomsg => 49, + Errno::Noprotoopt => 50, + Errno::Nospc => 51, + Errno::Nosys => 52, + Errno::Notconn => 53, + Errno::Notdir => 54, + Errno::Notempty => 55, + Errno::Notrecoverable => 56, + Errno::Notsock => 57, + Errno::Notsup => 58, + Errno::Notty => 59, + Errno::Nxio => 60, + Errno::Overflow => 61, + Errno::Ownerdead => 62, + Errno::Perm => 63, + Errno::Pipe => 64, + Errno::Proto => 65, + Errno::Protonosupport => 66, + Errno::Prototype => 67, + Errno::Range => 68, + Errno::Rofs => 69, + Errno::Spipe => 70, + Errno::Srch => 71, + Errno::Stale => 72, + Errno::Timedout => 73, + Errno::Txtbsy => 74, + Errno::Xdev => 75, + Errno::Notcapable => 76, + }) as u8; + match data6 { + EventEnum::FdRead(e) => { + *((ptr0 + 72) as *mut u8) = (0i32) as u8; + let EventFdReadwrite { + nbytes: nbytes7, + flags: flags7, + } = e; + *((ptr0 + 80) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes7); + let flags8 = flags7; + *((ptr0 + 88) as *mut u8) = ((flags8.bits() >> 0) as i32) as u8; + } + EventEnum::FdWrite(e) => { + *((ptr0 + 72) as *mut u8) = (1i32) as u8; + let EventFdReadwrite { + nbytes: nbytes9, + flags: flags9, + } = e; + *((ptr0 + 80) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes9); + let flags10 = flags9; + *((ptr0 + 88) as *mut u8) = ((flags10.bits() >> 0) as i32) as u8; + } + EventEnum::Clock => { + let e = (); + { + *((ptr0 + 72) as *mut u8) = (2i32) as u8; + let () = e; + } + } + }; + let Fdstat { + fs_filetype: fs_filetype11, + fs_flags: fs_flags11, + fs_rights_base: fs_rights_base11, + fs_rights_inheriting: fs_rights_inheriting11, + } = fdstat; + *((ptr0 + 96) as *mut u8) = (match fs_filetype11 { + Filetype::Unknown => 0, + Filetype::BlockDevice => 1, + Filetype::CharacterDevice => 2, + Filetype::Directory => 3, + Filetype::RegularFile => 4, + Filetype::SocketDgram => 5, + Filetype::SocketStream => 6, + Filetype::SymbolicLink => 7, + Filetype::Fifo => 8, + }) as u8; + let flags12 = fs_flags11; + *((ptr0 + 97) as *mut u8) = ((flags12.bits() >> 0) as i32) as u8; + let flags13 = fs_rights_base11; + *((ptr0 + 104) as *mut i32) = (flags13.bits() >> 32) as i32; + *((ptr0 + 100) as *mut i32) = (flags13.bits() >> 0) as i32; + let flags14 = fs_rights_inheriting11; + *((ptr0 + 112) as *mut i32) = (flags14.bits() >> 32) as i32; + *((ptr0 + 108) as *mut i32) = (flags14.bits() >> 0) as i32; + let SubscriptionClock { + clock_id: clock_id15, + timeout: timeout15, + precision: precision15, + flags: flags15, + } = subscription_clock; + *((ptr0 + 120) as *mut u8) = (match clock_id15 { + Clockid::Realtime => 0, + Clockid::Monotonic => 1, + }) as u8; + *((ptr0 + 128) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout15); + *((ptr0 + 136) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision15); + let flags16 = flags15; + *((ptr0 + 144) as *mut u8) = ((flags16.bits() >> 0) as i32) as u8; + let Snapshot0SubscriptionClock { + identifier: identifier17, + id: id17, + timeout: timeout17, + precision: precision17, + flags: flags17, + } = snapshot0_subscription_clock; + *((ptr0 + 152) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier17); + *((ptr0 + 160) as *mut u8) = (match id17 { + Snapshot0Clockid::Realtime => 0, + Snapshot0Clockid::Monotonic => 1, + Snapshot0Clockid::ProcessCputimeId => 2, + Snapshot0Clockid::ThreadCputimeId => 3, + }) as u8; + *((ptr0 + 168) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout17); + *((ptr0 + 176) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision17); + let flags18 = flags17; + *((ptr0 + 184) as *mut u8) = ((flags18.bits() >> 0) as i32) as u8; + let Subscription { + userdata: userdata19, + data: data19, + } = subscription; + *((ptr0 + 192) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata19); + match data19 { + SubscriptionEnum::Clock(e) => { + *((ptr0 + 200) as *mut u8) = (0i32) as u8; + let SubscriptionClock { + clock_id: clock_id20, + timeout: timeout20, + precision: precision20, + flags: flags20, + } = e; + *((ptr0 + 208) as *mut u8) = (match clock_id20 { + Clockid::Realtime => 0, + Clockid::Monotonic => 1, + }) as u8; + *((ptr0 + 216) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout20); + *((ptr0 + 224) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision20); + let flags21 = flags20; + *((ptr0 + 232) as *mut u8) = ((flags21.bits() >> 0) as i32) as u8; + } + SubscriptionEnum::Read(e) => { + *((ptr0 + 200) as *mut u8) = (1i32) as u8; + let SubscriptionFsReadwrite { + file_descriptor: file_descriptor22, + } = e; + *((ptr0 + 208) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor22); + } + SubscriptionEnum::Write(e) => { + *((ptr0 + 200) as *mut u8) = (2i32) as u8; + let SubscriptionFsReadwrite { + file_descriptor: file_descriptor23, + } = e; + *((ptr0 + 208) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor23); + } + }; + let Snapshot0Subscription { + userdata: userdata24, + data: data24, + } = snapshot0_subscription; + *((ptr0 + 240) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata24); + match data24 { + Snapshot0SubscriptionEnum::Clock(e) => { + *((ptr0 + 248) as *mut u8) = (0i32) as u8; + let Snapshot0SubscriptionClock { + identifier: identifier25, + id: id25, + timeout: timeout25, + precision: precision25, + flags: flags25, + } = e; + *((ptr0 + 256) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier25); + *((ptr0 + 264) as *mut u8) = (match id25 { + Snapshot0Clockid::Realtime => 0, + Snapshot0Clockid::Monotonic => 1, + Snapshot0Clockid::ProcessCputimeId => 2, + Snapshot0Clockid::ThreadCputimeId => 3, + }) as u8; + *((ptr0 + 272) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout25); + *((ptr0 + 280) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision25); + let flags26 = flags25; + *((ptr0 + 288) as *mut u8) = ((flags26.bits() >> 0) as i32) as u8; + } + Snapshot0SubscriptionEnum::Read(e) => { + *((ptr0 + 248) as *mut u8) = (1i32) as u8; + let SubscriptionFsReadwrite { + file_descriptor: file_descriptor27, + } = e; + *((ptr0 + 256) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor27); + } + Snapshot0SubscriptionEnum::Write(e) => { + *((ptr0 + 248) as *mut u8) = (2i32) as u8; + let SubscriptionFsReadwrite { + file_descriptor: file_descriptor28, + } = e; + *((ptr0 + 256) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor28); + } + }; + *((ptr0 + 296) as *mut i64) = wit_bindgen_rust::rt::as_i64(device); + *((ptr0 + 304) as *mut i64) = wit_bindgen_rust::rt::as_i64(linkcount); + *((ptr0 + 312) as *mut i32) = wit_bindgen_rust::rt::as_i32(snapshot0_linkcount); + let Filestat { + st_dev: st_dev29, + st_ino: st_ino29, + st_filetype: st_filetype29, + st_nlink: st_nlink29, + st_size: st_size29, + st_atim: st_atim29, + st_mtim: st_mtim29, + st_ctim: st_ctim29, + } = filestat; + *((ptr0 + 320) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev29); + *((ptr0 + 328) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino29); + *((ptr0 + 336) as *mut u8) = (match st_filetype29 { + Filetype::Unknown => 0, + Filetype::BlockDevice => 1, + Filetype::CharacterDevice => 2, + Filetype::Directory => 3, + Filetype::RegularFile => 4, + Filetype::SocketDgram => 5, + Filetype::SocketStream => 6, + Filetype::SymbolicLink => 7, + Filetype::Fifo => 8, + }) as u8; + *((ptr0 + 344) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_nlink29); + *((ptr0 + 352) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size29); + *((ptr0 + 360) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim29); + *((ptr0 + 368) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim29); + *((ptr0 + 376) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim29); + let Snapshot0Filestat { + st_dev: st_dev30, + st_ino: st_ino30, + st_filetype: st_filetype30, + st_nlink: st_nlink30, + st_size: st_size30, + st_atim: st_atim30, + st_mtim: st_mtim30, + st_ctim: st_ctim30, + } = snapshot0_filestat; + *((ptr0 + 384) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev30); + *((ptr0 + 392) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino30); + *((ptr0 + 400) as *mut u8) = (match st_filetype30 { + Filetype::Unknown => 0, + Filetype::BlockDevice => 1, + Filetype::CharacterDevice => 2, + Filetype::Directory => 3, + Filetype::RegularFile => 4, + Filetype::SocketDgram => 5, + Filetype::SocketStream => 6, + Filetype::SymbolicLink => 7, + Filetype::Fifo => 8, + }) as u8; + *((ptr0 + 404) as *mut i32) = wit_bindgen_rust::rt::as_i32(st_nlink30); + *((ptr0 + 408) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size30); + *((ptr0 + 416) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim30); + *((ptr0 + 424) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim30); + *((ptr0 + 432) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim30); + let Tty { + cols: cols31, + rows: rows31, + width: width31, + height: height31, + stdin_tty: stdin_tty31, + stdout_tty: stdout_tty31, + stderr_tty: stderr_tty31, + echo: echo31, + line_buffered: line_buffered31, + } = tty; + *((ptr0 + 440) as *mut i32) = wit_bindgen_rust::rt::as_i32(cols31); + *((ptr0 + 444) as *mut i32) = wit_bindgen_rust::rt::as_i32(rows31); + *((ptr0 + 448) as *mut i32) = wit_bindgen_rust::rt::as_i32(width31); + *((ptr0 + 452) as *mut i32) = wit_bindgen_rust::rt::as_i32(height31); + *((ptr0 + 456) as *mut u8) = (match stdin_tty31 { + true => 1, + false => 0, + }) as u8; + *((ptr0 + 457) as *mut u8) = (match stdout_tty31 { + true => 1, + false => 0, + }) as u8; + *((ptr0 + 458) as *mut u8) = (match stderr_tty31 { + true => 1, + false => 0, + }) as u8; + *((ptr0 + 459) as *mut u8) = (match echo31 { + true => 1, + false => 0, + }) as u8; + *((ptr0 + 460) as *mut u8) = (match line_buffered31 { + true => 1, + false => 0, + }) as u8; + *((ptr0 + 464) as *mut i32) = wit_bindgen_rust::rt::as_i32(tid); + *((ptr0 + 468) as *mut i32) = wit_bindgen_rust::rt::as_i32(pid); + *((ptr0 + 472) as *mut u8) = (match bus_data_format { + BusDataFormat::Raw => 0, + BusDataFormat::Bincode => 1, + BusDataFormat::MessagePack => 2, + BusDataFormat::Json => 3, + BusDataFormat::Yaml => 4, + BusDataFormat::Xml => 5, + BusDataFormat::Rkyv => 6, + }) as u8; + #[link(wasm_import_module = "output")] + extern "C" { + #[cfg_attr(target_arch = "wasm32", link_name = "expose-types-dummy-func")] + #[cfg_attr( + not(target_arch = "wasm32"), + link_name = "output_expose-types-dummy-func" + )] + fn wit_import(_: i32); + } + wit_import(ptr0); + () } - }; - let Fdstat{ fs_filetype:fs_filetype11, fs_flags:fs_flags11, fs_rights_base:fs_rights_base11, fs_rights_inheriting:fs_rights_inheriting11, } = fdstat; - *((ptr0 + 96) as *mut u8) = (match fs_filetype11 { - Filetype::Unknown => 0, - Filetype::BlockDevice => 1, - Filetype::CharacterDevice => 2, - Filetype::Directory => 3, - Filetype::RegularFile => 4, - Filetype::SocketDgram => 5, - Filetype::SocketStream => 6, - Filetype::SymbolicLink => 7, - Filetype::Fifo => 8, - }) as u8; - let flags12 = fs_flags11; - *((ptr0 + 97) as *mut u8) = ((flags12.bits() >> 0) as i32) as u8; - let flags13 = fs_rights_base11; - *((ptr0 + 104) as *mut i32) = (flags13.bits() >> 32) as i32; - *((ptr0 + 100) as *mut i32) = (flags13.bits() >> 0) as i32; - let flags14 = fs_rights_inheriting11; - *((ptr0 + 112) as *mut i32) = (flags14.bits() >> 32) as i32; - *((ptr0 + 108) as *mut i32) = (flags14.bits() >> 0) as i32; - let SubscriptionClock{ clock_id:clock_id15, timeout:timeout15, precision:precision15, flags:flags15, } = subscription_clock; - *((ptr0 + 120) as *mut u8) = (match clock_id15 { - Clockid::Realtime => 0, - Clockid::Monotonic => 1, - }) as u8; - *((ptr0 + 128) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout15); - *((ptr0 + 136) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision15); - let flags16 = flags15; - *((ptr0 + 144) as *mut u8) = ((flags16.bits() >> 0) as i32) as u8; - let Snapshot0SubscriptionClock{ identifier:identifier17, id:id17, timeout:timeout17, precision:precision17, flags:flags17, } = snapshot0_subscription_clock; - *((ptr0 + 152) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier17); - *((ptr0 + 160) as *mut u8) = (match id17 { - Snapshot0Clockid::Realtime => 0, - Snapshot0Clockid::Monotonic => 1, - Snapshot0Clockid::ProcessCputimeId => 2, - Snapshot0Clockid::ThreadCputimeId => 3, - }) as u8; - *((ptr0 + 168) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout17); - *((ptr0 + 176) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision17); - let flags18 = flags17; - *((ptr0 + 184) as *mut u8) = ((flags18.bits() >> 0) as i32) as u8; - let Subscription{ userdata:userdata19, data:data19, } = subscription; - *((ptr0 + 192) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata19); - match data19 { - SubscriptionEnum::Clock(e) => { - *((ptr0 + 200) as *mut u8) = (0i32) as u8; - let SubscriptionClock{ clock_id:clock_id20, timeout:timeout20, precision:precision20, flags:flags20, } = e; - *((ptr0 + 208) as *mut u8) = (match clock_id20 { - Clockid::Realtime => 0, - Clockid::Monotonic => 1, - }) as u8; - *((ptr0 + 216) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout20); - *((ptr0 + 224) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision20); - let flags21 = flags20; - *((ptr0 + 232) as *mut u8) = ((flags21.bits() >> 0) as i32) as u8; - - }, - SubscriptionEnum::Read(e) => { - *((ptr0 + 200) as *mut u8) = (1i32) as u8; - let SubscriptionFsReadwrite{ file_descriptor:file_descriptor22, } = e; - *((ptr0 + 208) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor22); - - }, - SubscriptionEnum::Write(e) => { - *((ptr0 + 200) as *mut u8) = (2i32) as u8; - let SubscriptionFsReadwrite{ file_descriptor:file_descriptor23, } = e; - *((ptr0 + 208) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor23); - - }, - }; - let Snapshot0Subscription{ userdata:userdata24, data:data24, } = snapshot0_subscription; - *((ptr0 + 240) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata24); - match data24 { - Snapshot0SubscriptionEnum::Clock(e) => { - *((ptr0 + 248) as *mut u8) = (0i32) as u8; - let Snapshot0SubscriptionClock{ identifier:identifier25, id:id25, timeout:timeout25, precision:precision25, flags:flags25, } = e; - *((ptr0 + 256) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier25); - *((ptr0 + 264) as *mut u8) = (match id25 { - Snapshot0Clockid::Realtime => 0, - Snapshot0Clockid::Monotonic => 1, - Snapshot0Clockid::ProcessCputimeId => 2, - Snapshot0Clockid::ThreadCputimeId => 3, - }) as u8; - *((ptr0 + 272) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout25); - *((ptr0 + 280) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision25); - let flags26 = flags25; - *((ptr0 + 288) as *mut u8) = ((flags26.bits() >> 0) as i32) as u8; - - }, - Snapshot0SubscriptionEnum::Read(e) => { - *((ptr0 + 248) as *mut u8) = (1i32) as u8; - let SubscriptionFsReadwrite{ file_descriptor:file_descriptor27, } = e; - *((ptr0 + 256) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor27); - - }, - Snapshot0SubscriptionEnum::Write(e) => { - *((ptr0 + 248) as *mut u8) = (2i32) as u8; - let SubscriptionFsReadwrite{ file_descriptor:file_descriptor28, } = e; - *((ptr0 + 256) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor28); - - }, - }; - *((ptr0 + 296) as *mut i64) = wit_bindgen_rust::rt::as_i64(device); - *((ptr0 + 304) as *mut i64) = wit_bindgen_rust::rt::as_i64(linkcount); - *((ptr0 + 312) as *mut i32) = wit_bindgen_rust::rt::as_i32(snapshot0_linkcount); - let Filestat{ st_dev:st_dev29, st_ino:st_ino29, st_filetype:st_filetype29, st_nlink:st_nlink29, st_size:st_size29, st_atim:st_atim29, st_mtim:st_mtim29, st_ctim:st_ctim29, } = filestat; - *((ptr0 + 320) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev29); - *((ptr0 + 328) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino29); - *((ptr0 + 336) as *mut u8) = (match st_filetype29 { - Filetype::Unknown => 0, - Filetype::BlockDevice => 1, - Filetype::CharacterDevice => 2, - Filetype::Directory => 3, - Filetype::RegularFile => 4, - Filetype::SocketDgram => 5, - Filetype::SocketStream => 6, - Filetype::SymbolicLink => 7, - Filetype::Fifo => 8, - }) as u8; - *((ptr0 + 344) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_nlink29); - *((ptr0 + 352) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size29); - *((ptr0 + 360) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim29); - *((ptr0 + 368) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim29); - *((ptr0 + 376) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim29); - let Snapshot0Filestat{ st_dev:st_dev30, st_ino:st_ino30, st_filetype:st_filetype30, st_nlink:st_nlink30, st_size:st_size30, st_atim:st_atim30, st_mtim:st_mtim30, st_ctim:st_ctim30, } = snapshot0_filestat; - *((ptr0 + 384) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev30); - *((ptr0 + 392) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino30); - *((ptr0 + 400) as *mut u8) = (match st_filetype30 { - Filetype::Unknown => 0, - Filetype::BlockDevice => 1, - Filetype::CharacterDevice => 2, - Filetype::Directory => 3, - Filetype::RegularFile => 4, - Filetype::SocketDgram => 5, - Filetype::SocketStream => 6, - Filetype::SymbolicLink => 7, - Filetype::Fifo => 8, - }) as u8; - *((ptr0 + 404) as *mut i32) = wit_bindgen_rust::rt::as_i32(st_nlink30); - *((ptr0 + 408) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size30); - *((ptr0 + 416) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim30); - *((ptr0 + 424) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim30); - *((ptr0 + 432) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim30); - let Tty{ cols:cols31, rows:rows31, width:width31, height:height31, stdin_tty:stdin_tty31, stdout_tty:stdout_tty31, stderr_tty:stderr_tty31, echo:echo31, line_buffered:line_buffered31, } = tty; - *((ptr0 + 440) as *mut i32) = wit_bindgen_rust::rt::as_i32(cols31); - *((ptr0 + 444) as *mut i32) = wit_bindgen_rust::rt::as_i32(rows31); - *((ptr0 + 448) as *mut i32) = wit_bindgen_rust::rt::as_i32(width31); - *((ptr0 + 452) as *mut i32) = wit_bindgen_rust::rt::as_i32(height31); - *((ptr0 + 456) as *mut u8) = (match stdin_tty31 { true => 1, false => 0 }) as u8; - *((ptr0 + 457) as *mut u8) = (match stdout_tty31 { true => 1, false => 0 }) as u8; - *((ptr0 + 458) as *mut u8) = (match stderr_tty31 { true => 1, false => 0 }) as u8; - *((ptr0 + 459) as *mut u8) = (match echo31 { true => 1, false => 0 }) as u8; - *((ptr0 + 460) as *mut u8) = (match line_buffered31 { true => 1, false => 0 }) as u8; - *((ptr0 + 464) as *mut i32) = wit_bindgen_rust::rt::as_i32(tid); - *((ptr0 + 468) as *mut i32) = wit_bindgen_rust::rt::as_i32(pid); - *((ptr0 + 472) as *mut u8) = (match bus_data_format { - BusDataFormat::Raw => 0, - BusDataFormat::Bincode => 1, - BusDataFormat::MessagePack => 2, - BusDataFormat::Json => 3, - BusDataFormat::Yaml => 4, - BusDataFormat::Xml => 5, - BusDataFormat::Rkyv => 6, - }) as u8; - #[link(wasm_import_module = "output")] - extern "C" { - #[cfg_attr(target_arch = "wasm32", link_name = "expose-types-dummy-func")] - #[cfg_attr(not(target_arch = "wasm32"), link_name = "output_expose-types-dummy-func")] - fn wit_import(_: i32, ); - } - wit_import(ptr0); - () - } - } - - #[repr(align(8))] - struct RetArea([u8; 480]); - static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 480]); + } + + #[repr(align(8))] + struct RetArea([u8; 480]); + static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 480]); } diff --git a/lib/wasi-types-generated/src/wasi/mod.rs b/lib/wasi-types-generated/src/wasi/mod.rs index fd62b1c0754..1b6d5be7e83 100644 --- a/lib/wasi-types-generated/src/wasi/mod.rs +++ b/lib/wasi-types-generated/src/wasi/mod.rs @@ -766,6 +766,12 @@ impl Default for Filestat { } } +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 { @@ -899,410 +905,409 @@ unsafe impl wasmer::FromToNativeWasmType for Errno { } } -/* - // TODO: if necessary, must be implemented in wit-bindgen - unsafe impl wit_bindgen_rust::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, - // TODO: What should we map invalid native values to? - _ => Self::Unknown, - } - } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wasmer::FromToNativeWasmType for BusErrno { + type Native = i32; - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false + 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, + // TODO: What should we map invalid native values to? + _ => Self::Unknown, } } - // TODO: if necessary, must be implemented in wit-bindgen - unsafe impl wit_bindgen_rust::FromToNativeWasmType for Advice { - type Native = i32; + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} - 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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wasmer::FromToNativeWasmType for Advice { + type Native = i32; - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false + 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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), } } - // TODO: if necessary, must be implemented in wit-bindgen - unsafe impl wit_bindgen_rust::FromToNativeWasmType for Socktype { - type Native = i32; + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} - 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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wasmer::FromToNativeWasmType for Socktype { + type Native = i32; - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false + 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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), } } - // TODO: if necessary, must be implemented in wit-bindgen - unsafe impl wit_bindgen_rust::FromToNativeWasmType for Sockstatus { - type Native = i32; + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} - 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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wasmer::FromToNativeWasmType for Sockstatus { + type Native = i32; - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false + 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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), } } - // TODO: if necessary, must be implemented in wit-bindgen - unsafe impl wit_bindgen_rust::FromToNativeWasmType for Streamsecurity { - type Native = i32; + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} - 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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wasmer::FromToNativeWasmType for Streamsecurity { + type Native = i32; - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false + 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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), } } - // TODO: if necessary, must be implemented in wit-bindgen - unsafe impl wit_bindgen_rust::FromToNativeWasmType for Rights { - type Native = i64; + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} - fn to_native(self) -> Self::Native { - self.bits() as i64 - } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wasmer::FromToNativeWasmType for Rights { + type Native = i64; - fn from_native(n: Self::Native) -> Self { - Self::from_bits_truncate(n as u64) - } + fn to_native(self) -> Self::Native { + self.bits() as i64 + } - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } + fn from_native(n: Self::Native) -> Self { + Self::from_bits_truncate(n as u64) } - // TODO: if necessary, must be implemented in wit-bindgen - unsafe impl wit_bindgen_rust::FromToNativeWasmType for Eventrwflags { - type Native = i32; + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} - fn to_native(self) -> Self::Native { - self.bits() as i32 - } - fn from_native(n: Self::Native) -> Self { - Self::from_bits_truncate(n as u8) - } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wasmer::FromToNativeWasmType for Eventrwflags { + type Native = i32; - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } + fn to_native(self) -> Self::Native { + self.bits() as i32 + } + fn from_native(n: Self::Native) -> Self { + Self::from_bits_truncate(n as u8) } - // TODO: if necessary, must be implemented in wit-bindgen - unsafe impl wit_bindgen_rust::FromToNativeWasmType for Fstflags { - type Native = i32; + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} - fn to_native(self) -> Self::Native { - self.bits() as i32 - } - fn from_native(n: Self::Native) -> Self { - Self::from_bits_truncate(n as u8) - } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wasmer::FromToNativeWasmType for Fstflags { + type Native = i32; - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } + fn to_native(self) -> Self::Native { + self.bits() as i32 + } + fn from_native(n: Self::Native) -> Self { + Self::from_bits_truncate(n as u8) } - // TODO: if necessary, must be implemented in wit-bindgen - unsafe impl wit_bindgen_rust::FromToNativeWasmType for Subclockflags { - type Native = i32; + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} - fn to_native(self) -> Self::Native { - self.bits() as i32 - } - fn from_native(n: Self::Native) -> Self { - Self::from_bits_truncate(n as u8) - } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wasmer::FromToNativeWasmType for Subclockflags { + type Native = i32; - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } + fn to_native(self) -> Self::Native { + self.bits() as i32 + } + fn from_native(n: Self::Native) -> Self { + Self::from_bits_truncate(n as u8) } - // TODO: if necessary, must be implemented in wit-bindgen - unsafe impl wit_bindgen_rust::FromToNativeWasmType for Clockid { - type Native = i32; + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} - fn to_native(self) -> Self::Native { - self as i32 - } - fn from_native(n: Self::Native) -> Self { - match n { - 0 => Self::Realtime, - 1 => Self::Monotonic, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wasmer::FromToNativeWasmType for Clockid { + type Native = i32; - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false + fn to_native(self) -> Self::Native { + self as i32 + } + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::Realtime, + 1 => Self::Monotonic, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), } } - // TODO: if necessary, must be implemented in wit-bindgen - unsafe impl wit_bindgen_rust::FromToNativeWasmType for Snapshot0Clockid { - type Native = i32; + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} - 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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wasmer::FromToNativeWasmType for Snapshot0Clockid { + type Native = i32; - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } - } - - // TODO: if necessary, must be implemented in wit-bindgen - unsafe impl wit_bindgen_rust::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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } + 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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), } + } - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } + #[cfg(feature = "sys")] + 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 wit_bindgen_rust::FromToNativeWasmType for Fdflags { - type Native = i32; +// TODO: if necessary, must be implemented in wit-bindgen +unsafe impl wasmer::FromToNativeWasmType for Sockoption { + 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 u8) + 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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), } + } - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } + #[cfg(feature = "sys")] + 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 wit_bindgen_rust::FromToNativeWasmType for Preopentype { - type Native = i32; +// 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 as i32 - } - fn from_native(n: Self::Native) -> Self { - match n { - 0 => Self::Dir, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } + fn to_native(self) -> Self::Native { + self.bits() as i32 + } + fn from_native(n: Self::Native) -> Self { + Self::from_bits_truncate(n as u8) + } - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } + #[cfg(feature = "sys")] + 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 wit_bindgen_rust::FromToNativeWasmType for Addressfamily { - type Native = i32; +// TODO: if necessary, must be implemented in wit-bindgen +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::Unspec, - 1 => Self::Inet4, - 2 => Self::Inet6, - 3 => Self::Unix, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } + fn to_native(self) -> Self::Native { + self as i32 + } + fn from_native(n: Self::Native) -> Self { + match n { + 0 => Self::Dir, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), } + } - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } + #[cfg(feature = "sys")] + 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 wit_bindgen_rust::FromToNativeWasmType for Snapshot0Whence { - type Native = i32; +// TODO: if necessary, must be implemented in wit-bindgen +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::Cur, - 1 => Self::End, - 2 => Self::Set, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } + 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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), } + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { - // TODO: find correct implementation - false +// TODO: if necessary, must be implemented in wit-bindgen +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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), } } - // TODO: if necessary, must be implemented in wit-bindgen - unsafe impl wit_bindgen_rust::FromToNativeWasmType for Whence { + #[cfg(feature = "sys")] + 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 Whence { type Native = i32; fn to_native(self) -> Self::Native { @@ -1319,12 +1324,11 @@ unsafe impl wasmer::FromToNativeWasmType for Errno { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wit_bindgen_rust::AsStoreRef) -> bool { + 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 ValueType for Snapshot0Clockid { @@ -1396,3 +1400,58 @@ impl From for Subscription { } } } + +// TODO: if necessary, must be implemented in wit-bindgen +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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } + } + + #[cfg(feature = "sys")] + 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 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, + // TODO: What should we map invalid native values to? + _ => todo!("Need to decide what to do here…"), + } + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} diff --git a/lib/wasi-types/src/bus.rs b/lib/wasi-types/src/bus.rs index f301838c252..c6e3ec447b9 100644 --- a/lib/wasi-types/src/bus.rs +++ b/lib/wasi-types/src/bus.rs @@ -1,10 +1,7 @@ use super::*; use wasmer_derive::ValueType; use wasmer_types::MemorySize; -use wasmer_wasi_types_generated::wasi::{ - BusErrno, Fd, BusDataFormat, - BusEventType -}; +use wasmer_wasi_types_generated::wasi::{BusDataFormat, BusErrno, BusEventType, Fd}; pub type __wasi_bid_t = u32; diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index d851da5092f..6a78c55fa23 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -30,7 +30,7 @@ use self::types::{ EventFdReadwrite, Eventrwflags, Eventtype, Fd as WasiFd, Fdflags, Fdstat, Filesize, Filestat, Filetype, Fstflags, Linkcount, Pid, Rights, Snapshot0Clockid, Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, SubscriptionEnum, - SubscriptionFsReadwrite, Tid, Timestamp, Tty, Whence, + SubscriptionFsReadwrite, Tid, Timestamp, Tty, Whence, BusDataFormat, }, *, }; @@ -3917,7 +3917,7 @@ pub fn bus_call( keep_alive: __wasi_bool_t, 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>, @@ -3954,7 +3954,7 @@ pub fn bus_subcall( keep_alive: __wasi_bool_t, 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>, @@ -4019,7 +4019,7 @@ pub fn bus_poll( pub fn call_reply( ctx: FunctionEnvMut<'_, WasiEnv>, cid: __wasi_cid_t, - format: __wasi_busdataformat_t, + format: BusDataFormat, buf: WasmPtr, buf_len: M::Offset, ) -> BusErrno { diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index 68ead9c1de2..25410236666 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -3,9 +3,9 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{FunctionEnvMut, Memory, Memory32, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ - Addressfamily, Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, - Filesize, Filestat, Fstflags, Pid, Rights, Sockoption, Sockstatus, Socktype, Streamsecurity, - Subscription, Tid, Timestamp, Tty, Whence, + Addressfamily, Advice, BusDataFormat, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, + Fdstat, Filesize, Filestat, Fstflags, Pid, Rights, Sockoption, Sockstatus, Socktype, + Streamsecurity, Subscription, Tid, Timestamp, Tty, Whence, }; type MemoryType = Memory32; @@ -578,7 +578,7 @@ pub(crate) fn bus_call( keep_alive: __wasi_bool_t, topic: WasmPtr, topic_len: MemoryOffset, - format: __wasi_busdataformat_t, + format: BusDataFormat, buf: WasmPtr, buf_len: MemoryOffset, ret_cid: WasmPtr<__wasi_cid_t, MemoryType>, @@ -594,7 +594,7 @@ pub(crate) fn bus_subcall( keep_alive: __wasi_bool_t, topic: WasmPtr, topic_len: MemoryOffset, - format: __wasi_busdataformat_t, + format: BusDataFormat, buf: WasmPtr, buf_len: MemoryOffset, ret_cid: WasmPtr<__wasi_cid_t, MemoryType>, @@ -627,7 +627,7 @@ pub(crate) fn bus_poll( pub(crate) fn call_reply( ctx: FunctionEnvMut, cid: __wasi_cid_t, - format: __wasi_busdataformat_t, + format: BusDataFormat, buf: WasmPtr, buf_len: MemoryOffset, ) -> BusErrno { diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index 52ab6a3303d..ed734da58e0 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -5,7 +5,7 @@ use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ Addressfamily, Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Filesize, Filestat, Fstflags, Pid, Rights, Sockoption, Sockstatus, Socktype, Streamsecurity, - Subscription, Tid, Timestamp, Tty, Whence, + Subscription, Tid, Timestamp, Tty, Whence, BusDataFormat, }; type MemoryType = Memory64; @@ -578,7 +578,7 @@ pub(crate) fn bus_call( keep_alive: __wasi_bool_t, topic: WasmPtr, topic_len: MemoryOffset, - format: __wasi_busdataformat_t, + format: BusDataFormat, buf: WasmPtr, buf_len: MemoryOffset, ret_cid: WasmPtr<__wasi_cid_t, MemoryType>, @@ -594,7 +594,7 @@ pub(crate) fn bus_subcall( keep_alive: __wasi_bool_t, topic: WasmPtr, topic_len: MemoryOffset, - format: __wasi_busdataformat_t, + format: BusDataFormat, buf: WasmPtr, buf_len: MemoryOffset, ret_cid: WasmPtr<__wasi_cid_t, MemoryType>, @@ -627,7 +627,7 @@ pub(crate) fn bus_poll( pub(crate) fn call_reply( ctx: FunctionEnvMut, cid: __wasi_cid_t, - format: __wasi_busdataformat_t, + format: BusDataFormat, buf: WasmPtr, buf_len: MemoryOffset, ) -> BusErrno { From c1e88970b1e6987e02c410d15515aee5638f3758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 7 Sep 2022 13:54:03 +0200 Subject: [PATCH 48/84] cargo fmt --- lib/wasi/src/syscalls/mod.rs | 10 +++++----- lib/wasi/src/syscalls/wasix64.rs | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 6a78c55fa23..80e870a6b78 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -26,11 +26,11 @@ pub mod wasix64; use self::types::{ wasi::{ - Addressfamily, Advice, BusErrno, Clockid, Dircookie, Dirent, Errno, Event, EventEnum, - EventFdReadwrite, Eventrwflags, Eventtype, Fd as WasiFd, Fdflags, Fdstat, Filesize, - Filestat, Filetype, Fstflags, Linkcount, Pid, Rights, Snapshot0Clockid, Sockoption, - Sockstatus, Socktype, Streamsecurity, Subscription, SubscriptionEnum, - SubscriptionFsReadwrite, Tid, Timestamp, Tty, Whence, BusDataFormat, + Addressfamily, Advice, BusDataFormat, BusErrno, Clockid, Dircookie, Dirent, Errno, Event, + EventEnum, EventFdReadwrite, Eventrwflags, Eventtype, Fd as WasiFd, Fdflags, Fdstat, + Filesize, Filestat, Filetype, Fstflags, Linkcount, Pid, Rights, Snapshot0Clockid, + Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, SubscriptionEnum, + SubscriptionFsReadwrite, Tid, Timestamp, Tty, Whence, }, *, }; diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index ed734da58e0..bbabdf91c28 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -3,9 +3,9 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{FunctionEnvMut, Memory, Memory64, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ - Addressfamily, Advice, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, - Filesize, Filestat, Fstflags, Pid, Rights, Sockoption, Sockstatus, Socktype, Streamsecurity, - Subscription, Tid, Timestamp, Tty, Whence, BusDataFormat, + Addressfamily, Advice, BusDataFormat, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, + Fdstat, Filesize, Filestat, Fstflags, Pid, Rights, Sockoption, Sockstatus, Socktype, + Streamsecurity, Subscription, Tid, Timestamp, Tty, Whence, }; type MemoryType = Memory64; From dec63a416ef5d9b5783c3b3958847e97cc4527e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 7 Sep 2022 16:58:18 +0200 Subject: [PATCH 49/84] Create build.rs script in wasi-types-generated to auto-generate Rust impls --- Cargo.lock | 67 + lib/wasi-types-generated/Cargo.toml | 5 + lib/wasi-types-generated/build.rs | 108 + lib/wasi-types-generated/src/wasi/bindings.rs | 3622 +++++++++-------- lib/wasi-types-generated/src/wasi/extra.rs | 2733 +++++++++++++ .../src/wasi/extra_manual.rs | 181 + lib/wasi-types-generated/src/wasi/mod.rs | 1461 +------ lib/wasi-types-generated/wit-clean/output.wit | 2 + .../wit-clean/typenames.wit | 2 + 9 files changed, 4965 insertions(+), 3216 deletions(-) create mode 100644 lib/wasi-types-generated/build.rs create mode 100644 lib/wasi-types-generated/src/wasi/extra.rs create mode 100644 lib/wasi-types-generated/src/wasi/extra_manual.rs diff --git a/Cargo.lock b/Cargo.lock index e82369ea9e6..ad1374d747e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -437,6 +437,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" @@ -1217,6 +1223,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" @@ -1837,6 +1849,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" @@ -2611,6 +2634,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" @@ -2745,12 +2783,27 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" +[[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-width" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" +[[package]] +name = "unicode-xid" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" + [[package]] name = "unix_mode" version = "0.1.3" @@ -3352,8 +3405,10 @@ dependencies = [ name = "wasmer-wasi-types-generated" version = "3.0.0-beta" dependencies = [ + "convert_case", "wasmer", "wit-bindgen-rust", + "wit-parser", ] [[package]] @@ -3693,6 +3748,18 @@ dependencies = [ "bitflags", ] +[[package]] +name = "wit-parser" +version = "0.2.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=f1682df9adacb515227d061a4601b2b4c997e7a2#f1682df9adacb515227d061a4601b2b4c997e7a2" +dependencies = [ + "anyhow", + "id-arena", + "pulldown-cmark", + "unicode-normalization", + "unicode-xid", +] + [[package]] name = "x11-dl" version = "2.20.0" diff --git a/lib/wasi-types-generated/Cargo.toml b/lib/wasi-types-generated/Cargo.toml index 86ea43b5936..40c823b762e 100644 --- a/lib/wasi-types-generated/Cargo.toml +++ b/lib/wasi-types-generated/Cargo.toml @@ -2,6 +2,7 @@ name = "wasmer-wasi-types-generated" version = "3.0.0-beta" edition = "2018" +build = "build.rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -15,6 +16,10 @@ git = "https://github.com/wasmerio/wit-bindgen" branch = "main" package = "wit-bindgen-rust" +[build-dependencies] +wit-parser = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "f1682df9adacb515227d061a4601b2b4c997e7a2", package = "wit-parser" } +convert_case = "0.5.0" + [features] js = ["wasmer/js"] sys = ["wasmer/sys"] diff --git a/lib/wasi-types-generated/build.rs b/lib/wasi-types-generated/build.rs new file mode 100644 index 00000000000..a683c85acd6 --- /dev/null +++ b/lib/wasi-types-generated/build.rs @@ -0,0 +1,108 @@ +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 main() { + let bindings_rs = BINDINGS_RS + .replace("#[allow(clippy::all)]", "") + .replace("pub mod output {", "") + .replace("mod output {", "") + .replace(" ", ""); + + let mut bindings_rs = bindings_rs.lines().collect::>(); + bindings_rs.pop(); + let bindings_rs = bindings_rs.join("\n"); + + let target_path = std::env::var("CARGO_MANIFEST_DIR").unwrap(); + let path = std::path::Path::new(&target_path) + .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(" ", ""); + 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); + 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); + + match &i.kind { + wit_parser::TypeDefKind::Enum(e) => { + + 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}\"), + }} + }} + + #[cfg(feature = \"sys\")] + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool {{ false }} + }} + " + ) + .replace(" ", ""), + ); + } + _ => {} + } + } + std::fs::write(path, contents).unwrap(); +} diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index e641233d782..507840061bb 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -1,1848 +1,1952 @@ #[allow(clippy::all)] pub mod output { - /// 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() - } - } + /// 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() } - } - /// 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(), - } + Snapshot0Clockid::Monotonic => { + f.debug_tuple("Snapshot0Clockid::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.", - } + Snapshot0Clockid::ProcessCputimeId => { + f.debug_tuple("Snapshot0Clockid::ProcessCputimeId").finish() } - } - 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() + Snapshot0Clockid::ThreadCputimeId => { + f.debug_tuple("Snapshot0Clockid::ThreadCputimeId").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) + } + /// 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() } - } - - 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." - } - } + Clockid::Monotonic => { + f.debug_tuple("Clockid::Monotonic").finish() } + } } - 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() - } + } + /// 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", + } } - 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) - } + 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", + } } - - 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; + 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 Rights { + } + 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 } + 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(), - } + } + /// 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() } - } - /// 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() + Filetype::BlockDevice => { + f.debug_tuple("Filetype::BlockDevice").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(), - } + 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() + } + } } - 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; + } + /// 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() + } } } - impl Fdflags { + } + 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 } + 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() + } + /// 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. + 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! { - /// Which file time attributes to adjust. - 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 { + } + wit_bindgen_rust::bitflags::bitflags! { + /// Flags determining the method of how paths are resolved. + 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 } + Self { bits } } - } - wit_bindgen_rust::bitflags::bitflags! { - /// Flags determining the method of how paths are resolved. - 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 { + } + wit_bindgen_rust::bitflags::bitflags! { + /// Open flags used by `path_open`. + 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 } + 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! { - /// Open flags used by `path_open`. - 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 { + } + 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 } + 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(), - } + } + /// 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! { - /// 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 { + } + 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 } + 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 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() } - } - /// 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() + EventEnum::FdWrite(e) => { + f.debug_tuple("EventEnum::FdWrite").field(e).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(), - } + EventEnum::Clock => { + f.debug_tuple("EventEnum::Clock").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 } + } + /// 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() } - } - /// 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() + Snapshot0SubscriptionEnum::Read(e) => { + f.debug_tuple("Snapshot0SubscriptionEnum::Read").field(e).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() + Snapshot0SubscriptionEnum::Write(e) => { + f.debug_tuple("Snapshot0SubscriptionEnum::Write").field(e).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(), - } + } + /// 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() } - } - /// 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(), - } + SubscriptionEnum::Read(e) => { + f.debug_tuple("SubscriptionEnum::Read").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() - } - } + 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() + } + /// 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() } - } - #[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() + Socktype::Stream => { + f.debug_tuple("Socktype::Stream").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() + Socktype::Raw => { + f.debug_tuple("Socktype::Raw").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(), - } + 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 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() } - } - #[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(), - } + Sockstatus::Opened => { + f.debug_tuple("Sockstatus::Opened").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() - } - } + Sockstatus::Closed => { + f.debug_tuple("Sockstatus::Closed").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(), - } + Sockstatus::Failed => { + f.debug_tuple("Sockstatus::Failed").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(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() } - } - #[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() + Sockoption::ReusePort => { + f.debug_tuple("Sockoption::ReusePort").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(), - } + Sockoption::ReuseAddr => { + f.debug_tuple("Sockoption::ReuseAddr").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(), - } + 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(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 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 BusDataFormat { - Raw, - Bincode, - MessagePack, - Json, - Yaml, - Xml, - Rkyv, + } + #[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() + } + } } - 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(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 BusEventType { - Noop, - Exit, - Call, - Result, - Fault, - Close, + } + #[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() + } + } } - 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(), - } + } + #[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() + } + } } - /// Dummy function to expose types into generated code - pub fn expose_types_dummy_func( - fd: Fd, - dirent: Dirent, - event_enum: EventEnum, - event: Event, - fdstat: Fdstat, - subscription_clock: SubscriptionClock, - snapshot0_subscription_clock: Snapshot0SubscriptionClock, - subscription: Subscription, - snapshot0_subscription: Snapshot0Subscription, - device: Device, - linkcount: Linkcount, - snapshot0_linkcount: Snapshot0Linkcount, - filestat: Filestat, - snapshot0_filestat: Snapshot0Filestat, - tty: Tty, - tid: Tid, - pid: Pid, - bus_data_format: BusDataFormat, - ) -> () { - unsafe { - let ptr0 = OUTPUT_RET_AREA.0.as_mut_ptr() as i32; - *((ptr0 + 0) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd); - let Dirent { - d_next: d_next1, - d_ino: d_ino1, - d_type: d_type1, - d_namlen: d_namlen1, - } = dirent; - *((ptr0 + 8) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_next1); - *((ptr0 + 16) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_ino1); - *((ptr0 + 24) as *mut u8) = (match d_type1 { - Filetype::Unknown => 0, - Filetype::BlockDevice => 1, - Filetype::CharacterDevice => 2, - Filetype::Directory => 3, - Filetype::RegularFile => 4, - Filetype::SocketDgram => 5, - Filetype::SocketStream => 6, - Filetype::SymbolicLink => 7, - Filetype::Fifo => 8, - }) as u8; - *((ptr0 + 28) as *mut i32) = wit_bindgen_rust::rt::as_i32(d_namlen1); - match event_enum { - EventEnum::FdRead(e) => { - *((ptr0 + 32) as *mut u8) = (0i32) as u8; - let EventFdReadwrite { - nbytes: nbytes2, - flags: flags2, - } = e; - *((ptr0 + 40) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes2); - let flags3 = flags2; - *((ptr0 + 48) as *mut u8) = ((flags3.bits() >> 0) as i32) as u8; - } - EventEnum::FdWrite(e) => { - *((ptr0 + 32) as *mut u8) = (1i32) as u8; - let EventFdReadwrite { - nbytes: nbytes4, - flags: flags4, - } = e; - *((ptr0 + 40) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes4); - let flags5 = flags4; - *((ptr0 + 48) as *mut u8) = ((flags5.bits() >> 0) as i32) as u8; - } - EventEnum::Clock => { - let e = (); - { - *((ptr0 + 32) as *mut u8) = (2i32) as u8; - let () = e; - } - } - }; - let Event { - userdata: userdata6, - error: error6, - data: data6, - } = event; - *((ptr0 + 56) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata6); - *((ptr0 + 64) as *mut u8) = (match error6 { - Errno::Success => 0, - Errno::Toobig => 1, - Errno::Access => 2, - Errno::Addrinuse => 3, - Errno::Addrnotavail => 4, - Errno::Afnosupport => 5, - Errno::Again => 6, - Errno::Already => 7, - Errno::Badf => 8, - Errno::Badmsg => 9, - Errno::Busy => 10, - Errno::Canceled => 11, - Errno::Child => 12, - Errno::Connaborted => 13, - Errno::Connrefused => 14, - Errno::Connreset => 15, - Errno::Deadlk => 16, - Errno::Destaddrreq => 17, - Errno::Dom => 18, - Errno::Dquot => 19, - Errno::Exist => 20, - Errno::Fault => 21, - Errno::Fbig => 22, - Errno::Hostunreach => 23, - Errno::Idrm => 24, - Errno::Ilseq => 25, - Errno::Inprogress => 26, - Errno::Intr => 27, - Errno::Inval => 28, - Errno::Io => 29, - Errno::Isconn => 30, - Errno::Isdir => 31, - Errno::Loop => 32, - Errno::Mfile => 33, - Errno::Mlink => 34, - Errno::Msgsize => 35, - Errno::Multihop => 36, - Errno::Nametoolong => 37, - Errno::Netdown => 38, - Errno::Netreset => 39, - Errno::Netunreach => 40, - Errno::Nfile => 41, - Errno::Nobufs => 42, - Errno::Nodev => 43, - Errno::Noent => 44, - Errno::Noexec => 45, - Errno::Nolck => 46, - Errno::Nolink => 47, - Errno::Nomem => 48, - Errno::Nomsg => 49, - Errno::Noprotoopt => 50, - Errno::Nospc => 51, - Errno::Nosys => 52, - Errno::Notconn => 53, - Errno::Notdir => 54, - Errno::Notempty => 55, - Errno::Notrecoverable => 56, - Errno::Notsock => 57, - Errno::Notsup => 58, - Errno::Notty => 59, - Errno::Nxio => 60, - Errno::Overflow => 61, - Errno::Ownerdead => 62, - Errno::Perm => 63, - Errno::Pipe => 64, - Errno::Proto => 65, - Errno::Protonosupport => 66, - Errno::Prototype => 67, - Errno::Range => 68, - Errno::Rofs => 69, - Errno::Spipe => 70, - Errno::Srch => 71, - Errno::Stale => 72, - Errno::Timedout => 73, - Errno::Txtbsy => 74, - Errno::Xdev => 75, - Errno::Notcapable => 76, - }) as u8; - match data6 { - EventEnum::FdRead(e) => { - *((ptr0 + 72) as *mut u8) = (0i32) as u8; - let EventFdReadwrite { - nbytes: nbytes7, - flags: flags7, - } = e; - *((ptr0 + 80) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes7); - let flags8 = flags7; - *((ptr0 + 88) as *mut u8) = ((flags8.bits() >> 0) as i32) as u8; - } - EventEnum::FdWrite(e) => { - *((ptr0 + 72) as *mut u8) = (1i32) as u8; - let EventFdReadwrite { - nbytes: nbytes9, - flags: flags9, - } = e; - *((ptr0 + 80) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes9); - let flags10 = flags9; - *((ptr0 + 88) as *mut u8) = ((flags10.bits() >> 0) as i32) as u8; - } - EventEnum::Clock => { - let e = (); - { - *((ptr0 + 72) as *mut u8) = (2i32) as u8; - let () = e; - } - } - }; - let Fdstat { - fs_filetype: fs_filetype11, - fs_flags: fs_flags11, - fs_rights_base: fs_rights_base11, - fs_rights_inheriting: fs_rights_inheriting11, - } = fdstat; - *((ptr0 + 96) as *mut u8) = (match fs_filetype11 { - Filetype::Unknown => 0, - Filetype::BlockDevice => 1, - Filetype::CharacterDevice => 2, - Filetype::Directory => 3, - Filetype::RegularFile => 4, - Filetype::SocketDgram => 5, - Filetype::SocketStream => 6, - Filetype::SymbolicLink => 7, - Filetype::Fifo => 8, - }) as u8; - let flags12 = fs_flags11; - *((ptr0 + 97) as *mut u8) = ((flags12.bits() >> 0) as i32) as u8; - let flags13 = fs_rights_base11; - *((ptr0 + 104) as *mut i32) = (flags13.bits() >> 32) as i32; - *((ptr0 + 100) as *mut i32) = (flags13.bits() >> 0) as i32; - let flags14 = fs_rights_inheriting11; - *((ptr0 + 112) as *mut i32) = (flags14.bits() >> 32) as i32; - *((ptr0 + 108) as *mut i32) = (flags14.bits() >> 0) as i32; - let SubscriptionClock { - clock_id: clock_id15, - timeout: timeout15, - precision: precision15, - flags: flags15, - } = subscription_clock; - *((ptr0 + 120) as *mut u8) = (match clock_id15 { - Clockid::Realtime => 0, - Clockid::Monotonic => 1, - }) as u8; - *((ptr0 + 128) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout15); - *((ptr0 + 136) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision15); - let flags16 = flags15; - *((ptr0 + 144) as *mut u8) = ((flags16.bits() >> 0) as i32) as u8; - let Snapshot0SubscriptionClock { - identifier: identifier17, - id: id17, - timeout: timeout17, - precision: precision17, - flags: flags17, - } = snapshot0_subscription_clock; - *((ptr0 + 152) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier17); - *((ptr0 + 160) as *mut u8) = (match id17 { - Snapshot0Clockid::Realtime => 0, - Snapshot0Clockid::Monotonic => 1, - Snapshot0Clockid::ProcessCputimeId => 2, - Snapshot0Clockid::ThreadCputimeId => 3, - }) as u8; - *((ptr0 + 168) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout17); - *((ptr0 + 176) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision17); - let flags18 = flags17; - *((ptr0 + 184) as *mut u8) = ((flags18.bits() >> 0) as i32) as u8; - let Subscription { - userdata: userdata19, - data: data19, - } = subscription; - *((ptr0 + 192) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata19); - match data19 { - SubscriptionEnum::Clock(e) => { - *((ptr0 + 200) as *mut u8) = (0i32) as u8; - let SubscriptionClock { - clock_id: clock_id20, - timeout: timeout20, - precision: precision20, - flags: flags20, - } = e; - *((ptr0 + 208) as *mut u8) = (match clock_id20 { - Clockid::Realtime => 0, - Clockid::Monotonic => 1, - }) as u8; - *((ptr0 + 216) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout20); - *((ptr0 + 224) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision20); - let flags21 = flags20; - *((ptr0 + 232) as *mut u8) = ((flags21.bits() >> 0) as i32) as u8; - } - SubscriptionEnum::Read(e) => { - *((ptr0 + 200) as *mut u8) = (1i32) as u8; - let SubscriptionFsReadwrite { - file_descriptor: file_descriptor22, - } = e; - *((ptr0 + 208) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor22); - } - SubscriptionEnum::Write(e) => { - *((ptr0 + 200) as *mut u8) = (2i32) as u8; - let SubscriptionFsReadwrite { - file_descriptor: file_descriptor23, - } = e; - *((ptr0 + 208) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor23); - } - }; - let Snapshot0Subscription { - userdata: userdata24, - data: data24, - } = snapshot0_subscription; - *((ptr0 + 240) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata24); - match data24 { - Snapshot0SubscriptionEnum::Clock(e) => { - *((ptr0 + 248) as *mut u8) = (0i32) as u8; - let Snapshot0SubscriptionClock { - identifier: identifier25, - id: id25, - timeout: timeout25, - precision: precision25, - flags: flags25, - } = e; - *((ptr0 + 256) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier25); - *((ptr0 + 264) as *mut u8) = (match id25 { - Snapshot0Clockid::Realtime => 0, - Snapshot0Clockid::Monotonic => 1, - Snapshot0Clockid::ProcessCputimeId => 2, - Snapshot0Clockid::ThreadCputimeId => 3, - }) as u8; - *((ptr0 + 272) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout25); - *((ptr0 + 280) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision25); - let flags26 = flags25; - *((ptr0 + 288) as *mut u8) = ((flags26.bits() >> 0) as i32) as u8; - } - Snapshot0SubscriptionEnum::Read(e) => { - *((ptr0 + 248) as *mut u8) = (1i32) as u8; - let SubscriptionFsReadwrite { - file_descriptor: file_descriptor27, - } = e; - *((ptr0 + 256) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor27); - } - Snapshot0SubscriptionEnum::Write(e) => { - *((ptr0 + 248) as *mut u8) = (2i32) as u8; - let SubscriptionFsReadwrite { - file_descriptor: file_descriptor28, - } = e; - *((ptr0 + 256) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor28); - } - }; - *((ptr0 + 296) as *mut i64) = wit_bindgen_rust::rt::as_i64(device); - *((ptr0 + 304) as *mut i64) = wit_bindgen_rust::rt::as_i64(linkcount); - *((ptr0 + 312) as *mut i32) = wit_bindgen_rust::rt::as_i32(snapshot0_linkcount); - let Filestat { - st_dev: st_dev29, - st_ino: st_ino29, - st_filetype: st_filetype29, - st_nlink: st_nlink29, - st_size: st_size29, - st_atim: st_atim29, - st_mtim: st_mtim29, - st_ctim: st_ctim29, - } = filestat; - *((ptr0 + 320) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev29); - *((ptr0 + 328) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino29); - *((ptr0 + 336) as *mut u8) = (match st_filetype29 { - Filetype::Unknown => 0, - Filetype::BlockDevice => 1, - Filetype::CharacterDevice => 2, - Filetype::Directory => 3, - Filetype::RegularFile => 4, - Filetype::SocketDgram => 5, - Filetype::SocketStream => 6, - Filetype::SymbolicLink => 7, - Filetype::Fifo => 8, - }) as u8; - *((ptr0 + 344) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_nlink29); - *((ptr0 + 352) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size29); - *((ptr0 + 360) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim29); - *((ptr0 + 368) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim29); - *((ptr0 + 376) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim29); - let Snapshot0Filestat { - st_dev: st_dev30, - st_ino: st_ino30, - st_filetype: st_filetype30, - st_nlink: st_nlink30, - st_size: st_size30, - st_atim: st_atim30, - st_mtim: st_mtim30, - st_ctim: st_ctim30, - } = snapshot0_filestat; - *((ptr0 + 384) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev30); - *((ptr0 + 392) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino30); - *((ptr0 + 400) as *mut u8) = (match st_filetype30 { - Filetype::Unknown => 0, - Filetype::BlockDevice => 1, - Filetype::CharacterDevice => 2, - Filetype::Directory => 3, - Filetype::RegularFile => 4, - Filetype::SocketDgram => 5, - Filetype::SocketStream => 6, - Filetype::SymbolicLink => 7, - Filetype::Fifo => 8, - }) as u8; - *((ptr0 + 404) as *mut i32) = wit_bindgen_rust::rt::as_i32(st_nlink30); - *((ptr0 + 408) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size30); - *((ptr0 + 416) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim30); - *((ptr0 + 424) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim30); - *((ptr0 + 432) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim30); - let Tty { - cols: cols31, - rows: rows31, - width: width31, - height: height31, - stdin_tty: stdin_tty31, - stdout_tty: stdout_tty31, - stderr_tty: stderr_tty31, - echo: echo31, - line_buffered: line_buffered31, - } = tty; - *((ptr0 + 440) as *mut i32) = wit_bindgen_rust::rt::as_i32(cols31); - *((ptr0 + 444) as *mut i32) = wit_bindgen_rust::rt::as_i32(rows31); - *((ptr0 + 448) as *mut i32) = wit_bindgen_rust::rt::as_i32(width31); - *((ptr0 + 452) as *mut i32) = wit_bindgen_rust::rt::as_i32(height31); - *((ptr0 + 456) as *mut u8) = (match stdin_tty31 { - true => 1, - false => 0, - }) as u8; - *((ptr0 + 457) as *mut u8) = (match stdout_tty31 { - true => 1, - false => 0, - }) as u8; - *((ptr0 + 458) as *mut u8) = (match stderr_tty31 { - true => 1, - false => 0, - }) as u8; - *((ptr0 + 459) as *mut u8) = (match echo31 { - true => 1, - false => 0, - }) as u8; - *((ptr0 + 460) as *mut u8) = (match line_buffered31 { - true => 1, - false => 0, - }) as u8; - *((ptr0 + 464) as *mut i32) = wit_bindgen_rust::rt::as_i32(tid); - *((ptr0 + 468) as *mut i32) = wit_bindgen_rust::rt::as_i32(pid); - *((ptr0 + 472) as *mut u8) = (match bus_data_format { - BusDataFormat::Raw => 0, - BusDataFormat::Bincode => 1, - BusDataFormat::MessagePack => 2, - BusDataFormat::Json => 3, - BusDataFormat::Yaml => 4, - BusDataFormat::Xml => 5, - BusDataFormat::Rkyv => 6, - }) as u8; - #[link(wasm_import_module = "output")] - extern "C" { - #[cfg_attr(target_arch = "wasm32", link_name = "expose-types-dummy-func")] - #[cfg_attr( - not(target_arch = "wasm32"), - link_name = "output_expose-types-dummy-func" - )] - fn wit_import(_: i32); - } - wit_import(ptr0); - () + } + #[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() + } + } } - - #[repr(align(8))] - struct RetArea([u8; 480]); - static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 480]); + } + /// Dummy function to expose types into generated code + pub fn expose_types_dummy_func(fd: Fd,dirent: Dirent,snapshot0_dirent: Snapshot0Dirent,snapshot0_event: Snapshot0Event,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,tid: Tid,pid: Pid,bus_data_format: BusDataFormat,) -> (){ + unsafe { + let ptr0 = OUTPUT_RET_AREA.0.as_mut_ptr() as i32; + *((ptr0 + 0) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd); + let Dirent{ d_next:d_next1, d_ino:d_ino1, d_type:d_type1, d_namlen:d_namlen1, } = dirent; + *((ptr0 + 8) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_next1); + *((ptr0 + 16) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_ino1); + *((ptr0 + 24) as *mut u8) = (match d_type1 { + Filetype::Unknown => 0, + Filetype::BlockDevice => 1, + Filetype::CharacterDevice => 2, + Filetype::Directory => 3, + Filetype::RegularFile => 4, + Filetype::SocketDgram => 5, + Filetype::SocketStream => 6, + Filetype::SymbolicLink => 7, + Filetype::Fifo => 8, + }) as u8; + *((ptr0 + 28) as *mut i32) = wit_bindgen_rust::rt::as_i32(d_namlen1); + let Snapshot0Dirent{ d_next:d_next2, d_ino:d_ino2, d_namlen:d_namlen2, d_type:d_type2, } = snapshot0_dirent; + *((ptr0 + 32) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_next2); + *((ptr0 + 40) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_ino2); + *((ptr0 + 48) as *mut i32) = wit_bindgen_rust::rt::as_i32(d_namlen2); + *((ptr0 + 52) as *mut u8) = (match d_type2 { + Filetype::Unknown => 0, + Filetype::BlockDevice => 1, + Filetype::CharacterDevice => 2, + Filetype::Directory => 3, + Filetype::RegularFile => 4, + Filetype::SocketDgram => 5, + Filetype::SocketStream => 6, + Filetype::SymbolicLink => 7, + Filetype::Fifo => 8, + }) as u8; + let Snapshot0Event{ userdata:userdata3, error:error3, type_:type_3, fd_readwrite:fd_readwrite3, } = snapshot0_event; + *((ptr0 + 56) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata3); + *((ptr0 + 64) as *mut u8) = (match error3 { + Errno::Success => 0, + Errno::Toobig => 1, + Errno::Access => 2, + Errno::Addrinuse => 3, + Errno::Addrnotavail => 4, + Errno::Afnosupport => 5, + Errno::Again => 6, + Errno::Already => 7, + Errno::Badf => 8, + Errno::Badmsg => 9, + Errno::Busy => 10, + Errno::Canceled => 11, + Errno::Child => 12, + Errno::Connaborted => 13, + Errno::Connrefused => 14, + Errno::Connreset => 15, + Errno::Deadlk => 16, + Errno::Destaddrreq => 17, + Errno::Dom => 18, + Errno::Dquot => 19, + Errno::Exist => 20, + Errno::Fault => 21, + Errno::Fbig => 22, + Errno::Hostunreach => 23, + Errno::Idrm => 24, + Errno::Ilseq => 25, + Errno::Inprogress => 26, + Errno::Intr => 27, + Errno::Inval => 28, + Errno::Io => 29, + Errno::Isconn => 30, + Errno::Isdir => 31, + Errno::Loop => 32, + Errno::Mfile => 33, + Errno::Mlink => 34, + Errno::Msgsize => 35, + Errno::Multihop => 36, + Errno::Nametoolong => 37, + Errno::Netdown => 38, + Errno::Netreset => 39, + Errno::Netunreach => 40, + Errno::Nfile => 41, + Errno::Nobufs => 42, + Errno::Nodev => 43, + Errno::Noent => 44, + Errno::Noexec => 45, + Errno::Nolck => 46, + Errno::Nolink => 47, + Errno::Nomem => 48, + Errno::Nomsg => 49, + Errno::Noprotoopt => 50, + Errno::Nospc => 51, + Errno::Nosys => 52, + Errno::Notconn => 53, + Errno::Notdir => 54, + Errno::Notempty => 55, + Errno::Notrecoverable => 56, + Errno::Notsock => 57, + Errno::Notsup => 58, + Errno::Notty => 59, + Errno::Nxio => 60, + Errno::Overflow => 61, + Errno::Ownerdead => 62, + Errno::Perm => 63, + Errno::Pipe => 64, + Errno::Proto => 65, + Errno::Protonosupport => 66, + Errno::Prototype => 67, + Errno::Range => 68, + Errno::Rofs => 69, + Errno::Spipe => 70, + Errno::Srch => 71, + Errno::Stale => 72, + Errno::Timedout => 73, + Errno::Txtbsy => 74, + Errno::Xdev => 75, + Errno::Notcapable => 76, + }) as u8; + *((ptr0 + 65) as *mut u8) = (match type_3 { + Eventtype::Clock => 0, + Eventtype::FdRead => 1, + Eventtype::FdWrite => 2, + }) as u8; + let EventFdReadwrite{ nbytes:nbytes4, flags:flags4, } = fd_readwrite3; + *((ptr0 + 72) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes4); + let flags5 = flags4; + *((ptr0 + 80) as *mut u8) = ((flags5.bits() >> 0) as i32) as u8; + match event_enum { + EventEnum::FdRead(e) => { + *((ptr0 + 88) as *mut u8) = (0i32) as u8; + let EventFdReadwrite{ nbytes:nbytes6, flags:flags6, } = e; + *((ptr0 + 96) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes6); + let flags7 = flags6; + *((ptr0 + 104) as *mut u8) = ((flags7.bits() >> 0) as i32) as u8; + + }, + EventEnum::FdWrite(e) => { + *((ptr0 + 88) as *mut u8) = (1i32) as u8; + let EventFdReadwrite{ nbytes:nbytes8, flags:flags8, } = e; + *((ptr0 + 96) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes8); + let flags9 = flags8; + *((ptr0 + 104) as *mut u8) = ((flags9.bits() >> 0) as i32) as u8; + + }, + EventEnum::Clock=> { + let e = (); + { + *((ptr0 + 88) as *mut u8) = (2i32) as u8; + let () = e; + + } + } + }; + let Event{ userdata:userdata10, error:error10, data:data10, } = event; + *((ptr0 + 112) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata10); + *((ptr0 + 120) as *mut u8) = (match error10 { + Errno::Success => 0, + Errno::Toobig => 1, + Errno::Access => 2, + Errno::Addrinuse => 3, + Errno::Addrnotavail => 4, + Errno::Afnosupport => 5, + Errno::Again => 6, + Errno::Already => 7, + Errno::Badf => 8, + Errno::Badmsg => 9, + Errno::Busy => 10, + Errno::Canceled => 11, + Errno::Child => 12, + Errno::Connaborted => 13, + Errno::Connrefused => 14, + Errno::Connreset => 15, + Errno::Deadlk => 16, + Errno::Destaddrreq => 17, + Errno::Dom => 18, + Errno::Dquot => 19, + Errno::Exist => 20, + Errno::Fault => 21, + Errno::Fbig => 22, + Errno::Hostunreach => 23, + Errno::Idrm => 24, + Errno::Ilseq => 25, + Errno::Inprogress => 26, + Errno::Intr => 27, + Errno::Inval => 28, + Errno::Io => 29, + Errno::Isconn => 30, + Errno::Isdir => 31, + Errno::Loop => 32, + Errno::Mfile => 33, + Errno::Mlink => 34, + Errno::Msgsize => 35, + Errno::Multihop => 36, + Errno::Nametoolong => 37, + Errno::Netdown => 38, + Errno::Netreset => 39, + Errno::Netunreach => 40, + Errno::Nfile => 41, + Errno::Nobufs => 42, + Errno::Nodev => 43, + Errno::Noent => 44, + Errno::Noexec => 45, + Errno::Nolck => 46, + Errno::Nolink => 47, + Errno::Nomem => 48, + Errno::Nomsg => 49, + Errno::Noprotoopt => 50, + Errno::Nospc => 51, + Errno::Nosys => 52, + Errno::Notconn => 53, + Errno::Notdir => 54, + Errno::Notempty => 55, + Errno::Notrecoverable => 56, + Errno::Notsock => 57, + Errno::Notsup => 58, + Errno::Notty => 59, + Errno::Nxio => 60, + Errno::Overflow => 61, + Errno::Ownerdead => 62, + Errno::Perm => 63, + Errno::Pipe => 64, + Errno::Proto => 65, + Errno::Protonosupport => 66, + Errno::Prototype => 67, + Errno::Range => 68, + Errno::Rofs => 69, + Errno::Spipe => 70, + Errno::Srch => 71, + Errno::Stale => 72, + Errno::Timedout => 73, + Errno::Txtbsy => 74, + Errno::Xdev => 75, + Errno::Notcapable => 76, + }) as u8; + match data10 { + EventEnum::FdRead(e) => { + *((ptr0 + 128) as *mut u8) = (0i32) as u8; + let EventFdReadwrite{ nbytes:nbytes11, flags:flags11, } = e; + *((ptr0 + 136) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes11); + let flags12 = flags11; + *((ptr0 + 144) as *mut u8) = ((flags12.bits() >> 0) as i32) as u8; + + }, + EventEnum::FdWrite(e) => { + *((ptr0 + 128) as *mut u8) = (1i32) as u8; + let EventFdReadwrite{ nbytes:nbytes13, flags:flags13, } = e; + *((ptr0 + 136) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes13); + let flags14 = flags13; + *((ptr0 + 144) as *mut u8) = ((flags14.bits() >> 0) as i32) as u8; + + }, + EventEnum::Clock=> { + let e = (); + { + *((ptr0 + 128) as *mut u8) = (2i32) as u8; + let () = e; + + } + } + }; + let Fdstat{ fs_filetype:fs_filetype15, fs_flags:fs_flags15, fs_rights_base:fs_rights_base15, fs_rights_inheriting:fs_rights_inheriting15, } = fdstat; + *((ptr0 + 152) as *mut u8) = (match fs_filetype15 { + Filetype::Unknown => 0, + Filetype::BlockDevice => 1, + Filetype::CharacterDevice => 2, + Filetype::Directory => 3, + Filetype::RegularFile => 4, + Filetype::SocketDgram => 5, + Filetype::SocketStream => 6, + Filetype::SymbolicLink => 7, + Filetype::Fifo => 8, + }) as u8; + let flags16 = fs_flags15; + *((ptr0 + 153) as *mut u8) = ((flags16.bits() >> 0) as i32) as u8; + let flags17 = fs_rights_base15; + *((ptr0 + 160) as *mut i32) = (flags17.bits() >> 32) as i32; + *((ptr0 + 156) as *mut i32) = (flags17.bits() >> 0) as i32; + let flags18 = fs_rights_inheriting15; + *((ptr0 + 168) as *mut i32) = (flags18.bits() >> 32) as i32; + *((ptr0 + 164) as *mut i32) = (flags18.bits() >> 0) as i32; + let SubscriptionClock{ clock_id:clock_id19, timeout:timeout19, precision:precision19, flags:flags19, } = subscription_clock; + *((ptr0 + 176) as *mut u8) = (match clock_id19 { + Clockid::Realtime => 0, + Clockid::Monotonic => 1, + }) as u8; + *((ptr0 + 184) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout19); + *((ptr0 + 192) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision19); + let flags20 = flags19; + *((ptr0 + 200) as *mut u8) = ((flags20.bits() >> 0) as i32) as u8; + let Snapshot0SubscriptionClock{ identifier:identifier21, id:id21, timeout:timeout21, precision:precision21, flags:flags21, } = snapshot0_subscription_clock; + *((ptr0 + 208) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier21); + *((ptr0 + 216) as *mut u8) = (match id21 { + Snapshot0Clockid::Realtime => 0, + Snapshot0Clockid::Monotonic => 1, + Snapshot0Clockid::ProcessCputimeId => 2, + Snapshot0Clockid::ThreadCputimeId => 3, + }) as u8; + *((ptr0 + 224) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout21); + *((ptr0 + 232) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision21); + let flags22 = flags21; + *((ptr0 + 240) as *mut u8) = ((flags22.bits() >> 0) as i32) as u8; + let Subscription{ userdata:userdata23, data:data23, } = subscription; + *((ptr0 + 248) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata23); + match data23 { + SubscriptionEnum::Clock(e) => { + *((ptr0 + 256) as *mut u8) = (0i32) as u8; + let SubscriptionClock{ clock_id:clock_id24, timeout:timeout24, precision:precision24, flags:flags24, } = e; + *((ptr0 + 264) as *mut u8) = (match clock_id24 { + Clockid::Realtime => 0, + Clockid::Monotonic => 1, + }) as u8; + *((ptr0 + 272) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout24); + *((ptr0 + 280) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision24); + let flags25 = flags24; + *((ptr0 + 288) as *mut u8) = ((flags25.bits() >> 0) as i32) as u8; + + }, + SubscriptionEnum::Read(e) => { + *((ptr0 + 256) as *mut u8) = (1i32) as u8; + let SubscriptionFsReadwrite{ file_descriptor:file_descriptor26, } = e; + *((ptr0 + 264) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor26); + + }, + SubscriptionEnum::Write(e) => { + *((ptr0 + 256) as *mut u8) = (2i32) as u8; + let SubscriptionFsReadwrite{ file_descriptor:file_descriptor27, } = e; + *((ptr0 + 264) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor27); + + }, + }; + let Snapshot0Subscription{ userdata:userdata28, data:data28, } = snapshot0_subscription; + *((ptr0 + 296) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata28); + match data28 { + Snapshot0SubscriptionEnum::Clock(e) => { + *((ptr0 + 304) as *mut u8) = (0i32) as u8; + let Snapshot0SubscriptionClock{ identifier:identifier29, id:id29, timeout:timeout29, precision:precision29, flags:flags29, } = e; + *((ptr0 + 312) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier29); + *((ptr0 + 320) as *mut u8) = (match id29 { + Snapshot0Clockid::Realtime => 0, + Snapshot0Clockid::Monotonic => 1, + Snapshot0Clockid::ProcessCputimeId => 2, + Snapshot0Clockid::ThreadCputimeId => 3, + }) as u8; + *((ptr0 + 328) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout29); + *((ptr0 + 336) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision29); + let flags30 = flags29; + *((ptr0 + 344) as *mut u8) = ((flags30.bits() >> 0) as i32) as u8; + + }, + Snapshot0SubscriptionEnum::Read(e) => { + *((ptr0 + 304) as *mut u8) = (1i32) as u8; + let SubscriptionFsReadwrite{ file_descriptor:file_descriptor31, } = e; + *((ptr0 + 312) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor31); + + }, + Snapshot0SubscriptionEnum::Write(e) => { + *((ptr0 + 304) as *mut u8) = (2i32) as u8; + let SubscriptionFsReadwrite{ file_descriptor:file_descriptor32, } = e; + *((ptr0 + 312) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor32); + + }, + }; + *((ptr0 + 352) as *mut i64) = wit_bindgen_rust::rt::as_i64(device); + *((ptr0 + 360) as *mut i64) = wit_bindgen_rust::rt::as_i64(linkcount); + *((ptr0 + 368) as *mut i32) = wit_bindgen_rust::rt::as_i32(snapshot0_linkcount); + let Filestat{ st_dev:st_dev33, st_ino:st_ino33, st_filetype:st_filetype33, st_nlink:st_nlink33, st_size:st_size33, st_atim:st_atim33, st_mtim:st_mtim33, st_ctim:st_ctim33, } = filestat; + *((ptr0 + 376) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev33); + *((ptr0 + 384) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino33); + *((ptr0 + 392) as *mut u8) = (match st_filetype33 { + Filetype::Unknown => 0, + Filetype::BlockDevice => 1, + Filetype::CharacterDevice => 2, + Filetype::Directory => 3, + Filetype::RegularFile => 4, + Filetype::SocketDgram => 5, + Filetype::SocketStream => 6, + Filetype::SymbolicLink => 7, + Filetype::Fifo => 8, + }) as u8; + *((ptr0 + 400) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_nlink33); + *((ptr0 + 408) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size33); + *((ptr0 + 416) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim33); + *((ptr0 + 424) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim33); + *((ptr0 + 432) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim33); + let Snapshot0Filestat{ st_dev:st_dev34, st_ino:st_ino34, st_filetype:st_filetype34, st_nlink:st_nlink34, st_size:st_size34, st_atim:st_atim34, st_mtim:st_mtim34, st_ctim:st_ctim34, } = snapshot0_filestat; + *((ptr0 + 440) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev34); + *((ptr0 + 448) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino34); + *((ptr0 + 456) as *mut u8) = (match st_filetype34 { + Filetype::Unknown => 0, + Filetype::BlockDevice => 1, + Filetype::CharacterDevice => 2, + Filetype::Directory => 3, + Filetype::RegularFile => 4, + Filetype::SocketDgram => 5, + Filetype::SocketStream => 6, + Filetype::SymbolicLink => 7, + Filetype::Fifo => 8, + }) as u8; + *((ptr0 + 460) as *mut i32) = wit_bindgen_rust::rt::as_i32(st_nlink34); + *((ptr0 + 464) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size34); + *((ptr0 + 472) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim34); + *((ptr0 + 480) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim34); + *((ptr0 + 488) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim34); + let Tty{ cols:cols35, rows:rows35, width:width35, height:height35, stdin_tty:stdin_tty35, stdout_tty:stdout_tty35, stderr_tty:stderr_tty35, echo:echo35, line_buffered:line_buffered35, } = tty; + *((ptr0 + 496) as *mut i32) = wit_bindgen_rust::rt::as_i32(cols35); + *((ptr0 + 500) as *mut i32) = wit_bindgen_rust::rt::as_i32(rows35); + *((ptr0 + 504) as *mut i32) = wit_bindgen_rust::rt::as_i32(width35); + *((ptr0 + 508) as *mut i32) = wit_bindgen_rust::rt::as_i32(height35); + *((ptr0 + 512) as *mut u8) = (match stdin_tty35 { true => 1, false => 0 }) as u8; + *((ptr0 + 513) as *mut u8) = (match stdout_tty35 { true => 1, false => 0 }) as u8; + *((ptr0 + 514) as *mut u8) = (match stderr_tty35 { true => 1, false => 0 }) as u8; + *((ptr0 + 515) as *mut u8) = (match echo35 { true => 1, false => 0 }) as u8; + *((ptr0 + 516) as *mut u8) = (match line_buffered35 { true => 1, false => 0 }) as u8; + *((ptr0 + 520) as *mut i32) = wit_bindgen_rust::rt::as_i32(tid); + *((ptr0 + 524) as *mut i32) = wit_bindgen_rust::rt::as_i32(pid); + *((ptr0 + 528) as *mut u8) = (match bus_data_format { + BusDataFormat::Raw => 0, + BusDataFormat::Bincode => 1, + BusDataFormat::MessagePack => 2, + BusDataFormat::Json => 3, + BusDataFormat::Yaml => 4, + BusDataFormat::Xml => 5, + BusDataFormat::Rkyv => 6, + }) as u8; + #[link(wasm_import_module = "output")] + extern "C" { + #[cfg_attr(target_arch = "wasm32", link_name = "expose-types-dummy-func")] + #[cfg_attr(not(target_arch = "wasm32"), link_name = "output_expose-types-dummy-func")] + fn wit_import(_: i32, ); + } + wit_import(ptr0); + () + } + } + + #[repr(align(8))] + struct RetArea([u8; 536]); + static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 536]); } diff --git a/lib/wasi-types-generated/src/wasi/extra.rs b/lib/wasi-types-generated/src/wasi/extra.rs new file mode 100644 index 00000000000..fecdb179381 --- /dev/null +++ b/lib/wasi-types-generated/src/wasi/extra.rs @@ -0,0 +1,2733 @@ + +use std::mem::MaybeUninit; +use wasmer::ValueType; + + + + /// 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. +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. +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`. +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() +} + } +} + } + /// Dummy function to expose types into generated code + pub fn expose_types_dummy_func(fd: Fd,dirent: Dirent,snapshot0_dirent: Snapshot0Dirent,snapshot0_event: Snapshot0Event,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,tid: Tid,pid: Pid,bus_data_format: BusDataFormat,) -> (){ +unsafe { + let ptr0 = OUTPUT_RET_AREA.0.as_mut_ptr() as i32; + *((ptr0 + 0) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd); + let Dirent{ d_next:d_next1, d_ino:d_ino1, d_type:d_type1, d_namlen:d_namlen1, } = dirent; + *((ptr0 + 8) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_next1); + *((ptr0 + 16) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_ino1); + *((ptr0 + 24) as *mut u8) = (match d_type1 { +Filetype::Unknown => 0, +Filetype::BlockDevice => 1, +Filetype::CharacterDevice => 2, +Filetype::Directory => 3, +Filetype::RegularFile => 4, +Filetype::SocketDgram => 5, +Filetype::SocketStream => 6, +Filetype::SymbolicLink => 7, +Filetype::Fifo => 8, + }) as u8; + *((ptr0 + 28) as *mut i32) = wit_bindgen_rust::rt::as_i32(d_namlen1); + let Snapshot0Dirent{ d_next:d_next2, d_ino:d_ino2, d_namlen:d_namlen2, d_type:d_type2, } = snapshot0_dirent; + *((ptr0 + 32) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_next2); + *((ptr0 + 40) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_ino2); + *((ptr0 + 48) as *mut i32) = wit_bindgen_rust::rt::as_i32(d_namlen2); + *((ptr0 + 52) as *mut u8) = (match d_type2 { +Filetype::Unknown => 0, +Filetype::BlockDevice => 1, +Filetype::CharacterDevice => 2, +Filetype::Directory => 3, +Filetype::RegularFile => 4, +Filetype::SocketDgram => 5, +Filetype::SocketStream => 6, +Filetype::SymbolicLink => 7, +Filetype::Fifo => 8, + }) as u8; + let Snapshot0Event{ userdata:userdata3, error:error3, type_:type_3, fd_readwrite:fd_readwrite3, } = snapshot0_event; + *((ptr0 + 56) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata3); + *((ptr0 + 64) as *mut u8) = (match error3 { +Errno::Success => 0, +Errno::Toobig => 1, +Errno::Access => 2, +Errno::Addrinuse => 3, +Errno::Addrnotavail => 4, +Errno::Afnosupport => 5, +Errno::Again => 6, +Errno::Already => 7, +Errno::Badf => 8, +Errno::Badmsg => 9, +Errno::Busy => 10, +Errno::Canceled => 11, +Errno::Child => 12, +Errno::Connaborted => 13, +Errno::Connrefused => 14, +Errno::Connreset => 15, +Errno::Deadlk => 16, +Errno::Destaddrreq => 17, +Errno::Dom => 18, +Errno::Dquot => 19, +Errno::Exist => 20, +Errno::Fault => 21, +Errno::Fbig => 22, +Errno::Hostunreach => 23, +Errno::Idrm => 24, +Errno::Ilseq => 25, +Errno::Inprogress => 26, +Errno::Intr => 27, +Errno::Inval => 28, +Errno::Io => 29, +Errno::Isconn => 30, +Errno::Isdir => 31, +Errno::Loop => 32, +Errno::Mfile => 33, +Errno::Mlink => 34, +Errno::Msgsize => 35, +Errno::Multihop => 36, +Errno::Nametoolong => 37, +Errno::Netdown => 38, +Errno::Netreset => 39, +Errno::Netunreach => 40, +Errno::Nfile => 41, +Errno::Nobufs => 42, +Errno::Nodev => 43, +Errno::Noent => 44, +Errno::Noexec => 45, +Errno::Nolck => 46, +Errno::Nolink => 47, +Errno::Nomem => 48, +Errno::Nomsg => 49, +Errno::Noprotoopt => 50, +Errno::Nospc => 51, +Errno::Nosys => 52, +Errno::Notconn => 53, +Errno::Notdir => 54, +Errno::Notempty => 55, +Errno::Notrecoverable => 56, +Errno::Notsock => 57, +Errno::Notsup => 58, +Errno::Notty => 59, +Errno::Nxio => 60, +Errno::Overflow => 61, +Errno::Ownerdead => 62, +Errno::Perm => 63, +Errno::Pipe => 64, +Errno::Proto => 65, +Errno::Protonosupport => 66, +Errno::Prototype => 67, +Errno::Range => 68, +Errno::Rofs => 69, +Errno::Spipe => 70, +Errno::Srch => 71, +Errno::Stale => 72, +Errno::Timedout => 73, +Errno::Txtbsy => 74, +Errno::Xdev => 75, +Errno::Notcapable => 76, + }) as u8; + *((ptr0 + 65) as *mut u8) = (match type_3 { +Eventtype::Clock => 0, +Eventtype::FdRead => 1, +Eventtype::FdWrite => 2, + }) as u8; + let EventFdReadwrite{ nbytes:nbytes4, flags:flags4, } = fd_readwrite3; + *((ptr0 + 72) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes4); + let flags5 = flags4; + *((ptr0 + 80) as *mut u8) = ((flags5.bits() >> 0) as i32) as u8; + match event_enum { +EventEnum::FdRead(e) => { + *((ptr0 + 88) as *mut u8) = (0i32) as u8; + let EventFdReadwrite{ nbytes:nbytes6, flags:flags6, } = e; + *((ptr0 + 96) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes6); + let flags7 = flags6; + *((ptr0 + 104) as *mut u8) = ((flags7.bits() >> 0) as i32) as u8; + +}, +EventEnum::FdWrite(e) => { + *((ptr0 + 88) as *mut u8) = (1i32) as u8; + let EventFdReadwrite{ nbytes:nbytes8, flags:flags8, } = e; + *((ptr0 + 96) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes8); + let flags9 = flags8; + *((ptr0 + 104) as *mut u8) = ((flags9.bits() >> 0) as i32) as u8; + +}, +EventEnum::Clock=> { + let e = (); + { +*((ptr0 + 88) as *mut u8) = (2i32) as u8; +let () = e; + + } +} + }; + let Event{ userdata:userdata10, error:error10, data:data10, } = event; + *((ptr0 + 112) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata10); + *((ptr0 + 120) as *mut u8) = (match error10 { +Errno::Success => 0, +Errno::Toobig => 1, +Errno::Access => 2, +Errno::Addrinuse => 3, +Errno::Addrnotavail => 4, +Errno::Afnosupport => 5, +Errno::Again => 6, +Errno::Already => 7, +Errno::Badf => 8, +Errno::Badmsg => 9, +Errno::Busy => 10, +Errno::Canceled => 11, +Errno::Child => 12, +Errno::Connaborted => 13, +Errno::Connrefused => 14, +Errno::Connreset => 15, +Errno::Deadlk => 16, +Errno::Destaddrreq => 17, +Errno::Dom => 18, +Errno::Dquot => 19, +Errno::Exist => 20, +Errno::Fault => 21, +Errno::Fbig => 22, +Errno::Hostunreach => 23, +Errno::Idrm => 24, +Errno::Ilseq => 25, +Errno::Inprogress => 26, +Errno::Intr => 27, +Errno::Inval => 28, +Errno::Io => 29, +Errno::Isconn => 30, +Errno::Isdir => 31, +Errno::Loop => 32, +Errno::Mfile => 33, +Errno::Mlink => 34, +Errno::Msgsize => 35, +Errno::Multihop => 36, +Errno::Nametoolong => 37, +Errno::Netdown => 38, +Errno::Netreset => 39, +Errno::Netunreach => 40, +Errno::Nfile => 41, +Errno::Nobufs => 42, +Errno::Nodev => 43, +Errno::Noent => 44, +Errno::Noexec => 45, +Errno::Nolck => 46, +Errno::Nolink => 47, +Errno::Nomem => 48, +Errno::Nomsg => 49, +Errno::Noprotoopt => 50, +Errno::Nospc => 51, +Errno::Nosys => 52, +Errno::Notconn => 53, +Errno::Notdir => 54, +Errno::Notempty => 55, +Errno::Notrecoverable => 56, +Errno::Notsock => 57, +Errno::Notsup => 58, +Errno::Notty => 59, +Errno::Nxio => 60, +Errno::Overflow => 61, +Errno::Ownerdead => 62, +Errno::Perm => 63, +Errno::Pipe => 64, +Errno::Proto => 65, +Errno::Protonosupport => 66, +Errno::Prototype => 67, +Errno::Range => 68, +Errno::Rofs => 69, +Errno::Spipe => 70, +Errno::Srch => 71, +Errno::Stale => 72, +Errno::Timedout => 73, +Errno::Txtbsy => 74, +Errno::Xdev => 75, +Errno::Notcapable => 76, + }) as u8; + match data10 { +EventEnum::FdRead(e) => { + *((ptr0 + 128) as *mut u8) = (0i32) as u8; + let EventFdReadwrite{ nbytes:nbytes11, flags:flags11, } = e; + *((ptr0 + 136) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes11); + let flags12 = flags11; + *((ptr0 + 144) as *mut u8) = ((flags12.bits() >> 0) as i32) as u8; + +}, +EventEnum::FdWrite(e) => { + *((ptr0 + 128) as *mut u8) = (1i32) as u8; + let EventFdReadwrite{ nbytes:nbytes13, flags:flags13, } = e; + *((ptr0 + 136) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes13); + let flags14 = flags13; + *((ptr0 + 144) as *mut u8) = ((flags14.bits() >> 0) as i32) as u8; + +}, +EventEnum::Clock=> { + let e = (); + { +*((ptr0 + 128) as *mut u8) = (2i32) as u8; +let () = e; + + } +} + }; + let Fdstat{ fs_filetype:fs_filetype15, fs_flags:fs_flags15, fs_rights_base:fs_rights_base15, fs_rights_inheriting:fs_rights_inheriting15, } = fdstat; + *((ptr0 + 152) as *mut u8) = (match fs_filetype15 { +Filetype::Unknown => 0, +Filetype::BlockDevice => 1, +Filetype::CharacterDevice => 2, +Filetype::Directory => 3, +Filetype::RegularFile => 4, +Filetype::SocketDgram => 5, +Filetype::SocketStream => 6, +Filetype::SymbolicLink => 7, +Filetype::Fifo => 8, + }) as u8; + let flags16 = fs_flags15; + *((ptr0 + 153) as *mut u8) = ((flags16.bits() >> 0) as i32) as u8; + let flags17 = fs_rights_base15; + *((ptr0 + 160) as *mut i32) = (flags17.bits() >> 32) as i32; + *((ptr0 + 156) as *mut i32) = (flags17.bits() >> 0) as i32; + let flags18 = fs_rights_inheriting15; + *((ptr0 + 168) as *mut i32) = (flags18.bits() >> 32) as i32; + *((ptr0 + 164) as *mut i32) = (flags18.bits() >> 0) as i32; + let SubscriptionClock{ clock_id:clock_id19, timeout:timeout19, precision:precision19, flags:flags19, } = subscription_clock; + *((ptr0 + 176) as *mut u8) = (match clock_id19 { +Clockid::Realtime => 0, +Clockid::Monotonic => 1, + }) as u8; + *((ptr0 + 184) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout19); + *((ptr0 + 192) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision19); + let flags20 = flags19; + *((ptr0 + 200) as *mut u8) = ((flags20.bits() >> 0) as i32) as u8; + let Snapshot0SubscriptionClock{ identifier:identifier21, id:id21, timeout:timeout21, precision:precision21, flags:flags21, } = snapshot0_subscription_clock; + *((ptr0 + 208) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier21); + *((ptr0 + 216) as *mut u8) = (match id21 { +Snapshot0Clockid::Realtime => 0, +Snapshot0Clockid::Monotonic => 1, +Snapshot0Clockid::ProcessCputimeId => 2, +Snapshot0Clockid::ThreadCputimeId => 3, + }) as u8; + *((ptr0 + 224) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout21); + *((ptr0 + 232) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision21); + let flags22 = flags21; + *((ptr0 + 240) as *mut u8) = ((flags22.bits() >> 0) as i32) as u8; + let Subscription{ userdata:userdata23, data:data23, } = subscription; + *((ptr0 + 248) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata23); + match data23 { +SubscriptionEnum::Clock(e) => { + *((ptr0 + 256) as *mut u8) = (0i32) as u8; + let SubscriptionClock{ clock_id:clock_id24, timeout:timeout24, precision:precision24, flags:flags24, } = e; + *((ptr0 + 264) as *mut u8) = (match clock_id24 { +Clockid::Realtime => 0, +Clockid::Monotonic => 1, + }) as u8; + *((ptr0 + 272) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout24); + *((ptr0 + 280) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision24); + let flags25 = flags24; + *((ptr0 + 288) as *mut u8) = ((flags25.bits() >> 0) as i32) as u8; + +}, +SubscriptionEnum::Read(e) => { + *((ptr0 + 256) as *mut u8) = (1i32) as u8; + let SubscriptionFsReadwrite{ file_descriptor:file_descriptor26, } = e; + *((ptr0 + 264) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor26); + +}, +SubscriptionEnum::Write(e) => { + *((ptr0 + 256) as *mut u8) = (2i32) as u8; + let SubscriptionFsReadwrite{ file_descriptor:file_descriptor27, } = e; + *((ptr0 + 264) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor27); + +}, + }; + let Snapshot0Subscription{ userdata:userdata28, data:data28, } = snapshot0_subscription; + *((ptr0 + 296) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata28); + match data28 { +Snapshot0SubscriptionEnum::Clock(e) => { + *((ptr0 + 304) as *mut u8) = (0i32) as u8; + let Snapshot0SubscriptionClock{ identifier:identifier29, id:id29, timeout:timeout29, precision:precision29, flags:flags29, } = e; + *((ptr0 + 312) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier29); + *((ptr0 + 320) as *mut u8) = (match id29 { +Snapshot0Clockid::Realtime => 0, +Snapshot0Clockid::Monotonic => 1, +Snapshot0Clockid::ProcessCputimeId => 2, +Snapshot0Clockid::ThreadCputimeId => 3, + }) as u8; + *((ptr0 + 328) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout29); + *((ptr0 + 336) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision29); + let flags30 = flags29; + *((ptr0 + 344) as *mut u8) = ((flags30.bits() >> 0) as i32) as u8; + +}, +Snapshot0SubscriptionEnum::Read(e) => { + *((ptr0 + 304) as *mut u8) = (1i32) as u8; + let SubscriptionFsReadwrite{ file_descriptor:file_descriptor31, } = e; + *((ptr0 + 312) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor31); + +}, +Snapshot0SubscriptionEnum::Write(e) => { + *((ptr0 + 304) as *mut u8) = (2i32) as u8; + let SubscriptionFsReadwrite{ file_descriptor:file_descriptor32, } = e; + *((ptr0 + 312) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor32); + +}, + }; + *((ptr0 + 352) as *mut i64) = wit_bindgen_rust::rt::as_i64(device); + *((ptr0 + 360) as *mut i64) = wit_bindgen_rust::rt::as_i64(linkcount); + *((ptr0 + 368) as *mut i32) = wit_bindgen_rust::rt::as_i32(snapshot0_linkcount); + let Filestat{ st_dev:st_dev33, st_ino:st_ino33, st_filetype:st_filetype33, st_nlink:st_nlink33, st_size:st_size33, st_atim:st_atim33, st_mtim:st_mtim33, st_ctim:st_ctim33, } = filestat; + *((ptr0 + 376) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev33); + *((ptr0 + 384) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino33); + *((ptr0 + 392) as *mut u8) = (match st_filetype33 { +Filetype::Unknown => 0, +Filetype::BlockDevice => 1, +Filetype::CharacterDevice => 2, +Filetype::Directory => 3, +Filetype::RegularFile => 4, +Filetype::SocketDgram => 5, +Filetype::SocketStream => 6, +Filetype::SymbolicLink => 7, +Filetype::Fifo => 8, + }) as u8; + *((ptr0 + 400) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_nlink33); + *((ptr0 + 408) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size33); + *((ptr0 + 416) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim33); + *((ptr0 + 424) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim33); + *((ptr0 + 432) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim33); + let Snapshot0Filestat{ st_dev:st_dev34, st_ino:st_ino34, st_filetype:st_filetype34, st_nlink:st_nlink34, st_size:st_size34, st_atim:st_atim34, st_mtim:st_mtim34, st_ctim:st_ctim34, } = snapshot0_filestat; + *((ptr0 + 440) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev34); + *((ptr0 + 448) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino34); + *((ptr0 + 456) as *mut u8) = (match st_filetype34 { +Filetype::Unknown => 0, +Filetype::BlockDevice => 1, +Filetype::CharacterDevice => 2, +Filetype::Directory => 3, +Filetype::RegularFile => 4, +Filetype::SocketDgram => 5, +Filetype::SocketStream => 6, +Filetype::SymbolicLink => 7, +Filetype::Fifo => 8, + }) as u8; + *((ptr0 + 460) as *mut i32) = wit_bindgen_rust::rt::as_i32(st_nlink34); + *((ptr0 + 464) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size34); + *((ptr0 + 472) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim34); + *((ptr0 + 480) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim34); + *((ptr0 + 488) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim34); + let Tty{ cols:cols35, rows:rows35, width:width35, height:height35, stdin_tty:stdin_tty35, stdout_tty:stdout_tty35, stderr_tty:stderr_tty35, echo:echo35, line_buffered:line_buffered35, } = tty; + *((ptr0 + 496) as *mut i32) = wit_bindgen_rust::rt::as_i32(cols35); + *((ptr0 + 500) as *mut i32) = wit_bindgen_rust::rt::as_i32(rows35); + *((ptr0 + 504) as *mut i32) = wit_bindgen_rust::rt::as_i32(width35); + *((ptr0 + 508) as *mut i32) = wit_bindgen_rust::rt::as_i32(height35); + *((ptr0 + 512) as *mut u8) = (match stdin_tty35 { true => 1, false => 0 }) as u8; + *((ptr0 + 513) as *mut u8) = (match stdout_tty35 { true => 1, false => 0 }) as u8; + *((ptr0 + 514) as *mut u8) = (match stderr_tty35 { true => 1, false => 0 }) as u8; + *((ptr0 + 515) as *mut u8) = (match echo35 { true => 1, false => 0 }) as u8; + *((ptr0 + 516) as *mut u8) = (match line_buffered35 { true => 1, false => 0 }) as u8; + *((ptr0 + 520) as *mut i32) = wit_bindgen_rust::rt::as_i32(tid); + *((ptr0 + 524) as *mut i32) = wit_bindgen_rust::rt::as_i32(pid); + *((ptr0 + 528) as *mut u8) = (match bus_data_format { +BusDataFormat::Raw => 0, +BusDataFormat::Bincode => 1, +BusDataFormat::MessagePack => 2, +BusDataFormat::Json => 3, +BusDataFormat::Yaml => 4, +BusDataFormat::Xml => 5, +BusDataFormat::Rkyv => 6, + }) as u8; + #[link(wasm_import_module = "output")] + extern "C" { +#[cfg_attr(target_arch = "wasm32", link_name = "expose-types-dummy-func")] +#[cfg_attr(not(target_arch = "wasm32"), link_name = "output_expose-types-dummy-func")] +fn wit_import(_: i32, ); + } + wit_import(ptr0); + () +} + } + + #[repr(align(8))] + struct RetArea([u8; 536]); + static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 536]); + + +// 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"), + } + } + + #[cfg(feature = "sys")] + 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"), + } + } + + #[cfg(feature = "sys")] + 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"), + } + } + + #[cfg(feature = "sys")] + 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"), + } + } + + #[cfg(feature = "sys")] + 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"), + } + } + + #[cfg(feature = "sys")] + 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"), + } + } + + #[cfg(feature = "sys")] + 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"), + } + } + + #[cfg(feature = "sys")] + 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"), + } + } + + #[cfg(feature = "sys")] + 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"), + } + } + + #[cfg(feature = "sys")] + 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"), + } + } + + #[cfg(feature = "sys")] + 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"), + } + } + + #[cfg(feature = "sys")] + 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"), + } + } + + #[cfg(feature = "sys")] + 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"), + } + } + + #[cfg(feature = "sys")] + 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"), + } + } + + #[cfg(feature = "sys")] + 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"), + } + } + + #[cfg(feature = "sys")] + 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"), + } + } + + #[cfg(feature = "sys")] + 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"), + } + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } +} diff --git a/lib/wasi-types-generated/src/wasi/extra_manual.rs b/lib/wasi-types-generated/src/wasi/extra_manual.rs new file mode 100644 index 00000000000..df55437bb97 --- /dev/null +++ b/lib/wasi-types-generated/src/wasi/extra_manual.rs @@ -0,0 +1,181 @@ +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) + } +} diff --git a/lib/wasi-types-generated/src/wasi/mod.rs b/lib/wasi-types-generated/src/wasi/mod.rs index 1b6d5be7e83..f0247f05cdf 100644 --- a/lib/wasi-types-generated/src/wasi/mod.rs +++ b/lib/wasi-types-generated/src/wasi/mod.rs @@ -1,1457 +1,4 @@ -mod bindings; -pub use bindings::output::*; - -use std::mem::MaybeUninit; -use wasmer::ValueType; - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for BusEventType { - #[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]) {} -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for Errno { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for BusErrno { - #[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]) {} -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for Socktype { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for Sockstatus { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for Sockoption { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for Streamsecurity { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for Addressfamily { - #[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]) {} -} - -impl Filetype { - pub fn name(self) -> &'static str { - match self { - Self::Unknown => "Unknown", - Self::BlockDevice => "Block device", - Self::CharacterDevice => "Character device", - Self::Directory => "Directory", - Self::RegularFile => "Regular file", - Self::SocketDgram => "Socket dgram", - Self::SocketStream => "Socket stream", - Self::SymbolicLink => "Symbolic link", - Self::Fifo => "Fifo", - } - } -} - -unsafe impl ValueType for Event { - 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)*) + std::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!(data)); - self.data - .zero_padding_bytes(&mut bytes[field!(data)..field_end!(data)]); - zero!(field_end!(data), std::mem::size_of_val(self)); - } -} - -unsafe impl ValueType for Tty { - 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)*) + std::mem::size_of_val(&self.$($f)*) - }; - } - macro_rules! zero { - ($start:expr, $end:expr) => { - for i in $start..$end { - bytes[i] = MaybeUninit::new(0); - } - }; - } - - self.cols - .zero_padding_bytes(&mut bytes[field!(cols)..field_end!(cols)]); - zero!(field_end!(cols), field!(rows)); - - self.rows - .zero_padding_bytes(&mut bytes[field!(rows)..field_end!(rows)]); - zero!(field_end!(rows), field!(width)); - - self.width - .zero_padding_bytes(&mut bytes[field!(width)..field_end!(width)]); - zero!(field_end!(width), field!(height)); - - self.height - .zero_padding_bytes(&mut bytes[field!(height)..field_end!(height)]); - zero!(field_end!(height), field!(stdin_tty)); - - self.stdin_tty - .zero_padding_bytes(&mut bytes[field!(stdin_tty)..field_end!(stdin_tty)]); - zero!(field_end!(stdin_tty), field!(stdout_tty)); - - self.stdout_tty - .zero_padding_bytes(&mut bytes[field!(stdout_tty)..field_end!(stdout_tty)]); - zero!(field_end!(stdout_tty), field!(stderr_tty)); - - self.stderr_tty - .zero_padding_bytes(&mut bytes[field!(stderr_tty)..field_end!(stderr_tty)]); - zero!(field_end!(stderr_tty), field!(echo)); - - self.echo - .zero_padding_bytes(&mut bytes[field!(echo)..field_end!(echo)]); - zero!(field_end!(echo), field!(line_buffered)); - - self.line_buffered - .zero_padding_bytes(&mut bytes[field!(line_buffered)..field_end!(line_buffered)]); - zero!(field_end!(line_buffered), std::mem::size_of_val(self)); - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for Eventtype { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for Rights { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -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, - }) - } -} - -// 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 Fstflags { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for SubscriptionEnum { - fn zero_padding_bytes(&self, bytes: &mut [MaybeUninit]) { - macro_rules! field { - ($($f:tt)*) => { - &$($f)* as *const _ as usize - self as *const _ as usize - }; - } - macro_rules! field_end { - ($($f:tt)*) => { - field!($($f)*) + std::mem::size_of_val(&$($f)*) - }; - } - macro_rules! zero { - ($start:expr, $end:expr) => { - for i in $start..$end { - bytes[i] = MaybeUninit::new(0); - } - }; - } - - match self { - SubscriptionEnum::Clock(d) => { - d.zero_padding_bytes(&mut bytes[field!(d)..field_end!(d)]); - zero!(field_end!(d), std::mem::size_of_val(self)) - } - SubscriptionEnum::Read(d) => { - d.zero_padding_bytes(&mut bytes[field!(d)..field_end!(d)]); - zero!(field_end!(d), std::mem::size_of_val(self)) - } - SubscriptionEnum::Write(d) => { - d.zero_padding_bytes(&mut bytes[field!(d)..field_end!(d)]); - zero!(field_end!(d), std::mem::size_of_val(self)) - } - } - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for EventEnum { - fn zero_padding_bytes(&self, bytes: &mut [MaybeUninit]) { - macro_rules! field { - ($($f:tt)*) => { - &$($f)* as *const _ as usize - self as *const _ as usize - }; - } - macro_rules! field_end { - ($($f:tt)*) => { - field!($($f)*) + std::mem::size_of_val(&$($f)*) - }; - } - macro_rules! zero { - ($start:expr, $end:expr) => { - for i in $start..$end { - bytes[i] = MaybeUninit::new(0); - } - }; - } - - match self { - Self::Clock => { - zero!(field!(self), std::mem::size_of_val(self)) - } - Self::FdRead(d) => { - d.zero_padding_bytes(&mut bytes[field!(d)..field_end!(d)]); - zero!(field_end!(d), std::mem::size_of_val(self)) - } - Self::FdWrite(d) => { - d.zero_padding_bytes(&mut bytes[field!(d)..field_end!(d)]); - zero!(field_end!(d), std::mem::size_of_val(self)) - } - } - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for Snapshot0SubscriptionEnum { - fn zero_padding_bytes(&self, bytes: &mut [MaybeUninit]) { - macro_rules! field { - ($($f:tt)*) => { - &$($f)* as *const _ as usize - self as *const _ as usize - }; - } - macro_rules! field_end { - ($($f:tt)*) => { - field!($($f)*) + std::mem::size_of_val(&$($f)*) - }; - } - macro_rules! zero { - ($start:expr, $end:expr) => { - for i in $start..$end { - bytes[i] = MaybeUninit::new(0); - } - }; - } - - match self { - Snapshot0SubscriptionEnum::Clock(d) => { - d.zero_padding_bytes(&mut bytes[field!(d)..field_end!(d)]); - zero!(field_end!(d), std::mem::size_of_val(self)) - } - Snapshot0SubscriptionEnum::Read(d) => { - d.zero_padding_bytes(&mut bytes[field!(d)..field_end!(d)]); - zero!(field_end!(d), std::mem::size_of_val(self)) - } - Snapshot0SubscriptionEnum::Write(d) => { - d.zero_padding_bytes(&mut bytes[field!(d)..field_end!(d)]); - zero!(field_end!(d), std::mem::size_of_val(self)) - } - } - } -} - -// 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 Clockid { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -// 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 Preopentype { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for EventFdReadwrite { - 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)*) + std::mem::size_of_val(&self.$($f)*) - }; - } - macro_rules! zero { - ($start:expr, $end:expr) => { - for i in $start..$end { - bytes[i] = MaybeUninit::new(0); - } - }; - } - - self.nbytes - .zero_padding_bytes(&mut bytes[field!(nbytes)..field_end!(nbytes)]); - zero!(field_end!(nbytes), field!(flags)); - - self.flags - .zero_padding_bytes(&mut bytes[field!(flags)..field_end!(flags)]); - zero!(field_end!(flags), std::mem::size_of_val(self)); - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for Fdstat { - 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)*) + std::mem::size_of_val(&self.$($f)*) - }; - } - macro_rules! zero { - ($start:expr, $end:expr) => { - for i in $start..$end { - bytes[i] = MaybeUninit::new(0); - } - }; - } - - self.fs_filetype - .zero_padding_bytes(&mut bytes[field!(fs_filetype)..field_end!(fs_filetype)]); - zero!(field_end!(fs_filetype), field!(fs_flags)); - - self.fs_flags - .zero_padding_bytes(&mut bytes[field!(fs_flags)..field_end!(fs_flags)]); - zero!(field_end!(fs_flags), field!(fs_rights_base)); - - self.fs_rights_base - .zero_padding_bytes(&mut bytes[field!(fs_rights_base)..field_end!(fs_rights_base)]); - zero!( - field_end!(fs_rights_inheriting), - std::mem::size_of_val(self) - ); - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for Snapshot0SubscriptionClock { - 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)*) + std::mem::size_of_val(&self.$($f)*) - }; - } - macro_rules! zero { - ($start:expr, $end:expr) => { - for i in $start..$end { - bytes[i] = MaybeUninit::new(0); - } - }; - } - - self.identifier - .zero_padding_bytes(&mut bytes[field!(identifier)..field_end!(identifier)]); - zero!(field_end!(identifier), field!(id)); - - self.id - .zero_padding_bytes(&mut bytes[field!(id)..field_end!(id)]); - zero!(field_end!(id), field!(timeout)); - - self.timeout - .zero_padding_bytes(&mut bytes[field!(timeout)..field_end!(timeout)]); - zero!(field_end!(timeout), field!(precision)); - - self.precision - .zero_padding_bytes(&mut bytes[field!(precision)..field_end!(precision)]); - zero!(field_end!(precision), field!(flags)); - - self.flags - .zero_padding_bytes(&mut bytes[field!(flags)..field_end!(flags)]); - zero!(field_end!(flags), std::mem::size_of_val(self)); - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for SubscriptionFsReadwrite { - 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)*) + std::mem::size_of_val(&self.$($f)*) - }; - } - macro_rules! zero { - ($start:expr, $end:expr) => { - for i in $start..$end { - bytes[i] = MaybeUninit::new(0); - } - }; - } - - self.file_descriptor - .zero_padding_bytes(&mut bytes[field!(file_descriptor)..field_end!(file_descriptor)]); - zero!(field_end!(file_descriptor), std::mem::size_of_val(self)); - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for SubscriptionClock { - 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)*) + std::mem::size_of_val(&self.$($f)*) - }; - } - macro_rules! zero { - ($start:expr, $end:expr) => { - for i in $start..$end { - bytes[i] = MaybeUninit::new(0); - } - }; - } - - self.clock_id - .zero_padding_bytes(&mut bytes[field!(clock_id)..field_end!(clock_id)]); - zero!(field_end!(clock_id), field!(timeout)); - - self.timeout - .zero_padding_bytes(&mut bytes[field!(timeout)..field_end!(timeout)]); - zero!(field_end!(timeout), field!(precision)); - - self.precision - .zero_padding_bytes(&mut bytes[field!(precision)..field_end!(precision)]); - zero!(field_end!(precision), field!(flags)); - - self.flags - .zero_padding_bytes(&mut bytes[field!(flags)..field_end!(flags)]); - zero!(field_end!(flags), std::mem::size_of_val(self)); - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for Subscription { - 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)*) + std::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!(data)); - - self.data - .zero_padding_bytes(&mut bytes[field!(data)..field_end!(data)]); - zero!(field_end!(data), std::mem::size_of_val(self)); - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -unsafe impl ValueType for Snapshot0Subscription { - 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)*) + std::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!(data)); - - self.data - .zero_padding_bytes(&mut bytes[field!(data)..field_end!(data)]); - zero!(field_end!(data), std::mem::size_of_val(self)); - } -} - -unsafe impl ValueType for Snapshot0Filestat { - 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)*) + std::mem::size_of_val(&self.$($f)*) - }; - } - macro_rules! zero { - ($start:expr, $end:expr) => { - for i in $start..$end { - bytes[i] = MaybeUninit::new(0); - } - }; - } - self.st_dev - .zero_padding_bytes(&mut bytes[field!(st_dev)..field_end!(st_dev)]); - zero!(field_end!(st_dev), field!(st_ino)); - - self.st_ino - .zero_padding_bytes(&mut bytes[field!(st_ino)..field_end!(st_ino)]); - zero!(field_end!(st_ino), field!(st_filetype)); - - self.st_filetype - .zero_padding_bytes(&mut bytes[field!(st_filetype)..field_end!(st_filetype)]); - zero!(field_end!(st_filetype), field!(st_nlink)); - - self.st_nlink - .zero_padding_bytes(&mut bytes[field!(st_nlink)..field_end!(st_nlink)]); - zero!(field_end!(st_nlink), field!(st_size)); - - self.st_size - .zero_padding_bytes(&mut bytes[field!(st_size)..field_end!(st_size)]); - zero!(field_end!(st_size), field!(st_atim)); - - self.st_atim - .zero_padding_bytes(&mut bytes[field!(st_atim)..field_end!(st_atim)]); - zero!(field_end!(st_atim), field!(st_mtim)); - - self.st_mtim - .zero_padding_bytes(&mut bytes[field!(st_mtim)..field_end!(st_mtim)]); - zero!(field_end!(st_mtim), field!(st_ctim)); - - self.st_ctim - .zero_padding_bytes(&mut bytes[field!(st_ctim)..field_end!(st_ctim)]); - zero!(field_end!(st_ctim), std::mem::size_of_val(self)); - } -} - -unsafe impl ValueType for Filestat { - 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)*) + std::mem::size_of_val(&self.$($f)*) - }; - } - macro_rules! zero { - ($start:expr, $end:expr) => { - for i in $start..$end { - bytes[i] = MaybeUninit::new(0); - } - }; - } - self.st_dev - .zero_padding_bytes(&mut bytes[field!(st_dev)..field_end!(st_dev)]); - zero!(field_end!(st_dev), field!(st_ino)); - - self.st_ino - .zero_padding_bytes(&mut bytes[field!(st_ino)..field_end!(st_ino)]); - zero!(field_end!(st_ino), field!(st_filetype)); - - self.st_filetype - .zero_padding_bytes(&mut bytes[field!(st_filetype)..field_end!(st_filetype)]); - zero!(field_end!(st_filetype), field!(st_nlink)); - - self.st_nlink - .zero_padding_bytes(&mut bytes[field!(st_nlink)..field_end!(st_nlink)]); - zero!(field_end!(st_nlink), field!(st_size)); - - self.st_size - .zero_padding_bytes(&mut bytes[field!(st_size)..field_end!(st_size)]); - zero!(field_end!(st_size), field!(st_atim)); - - self.st_atim - .zero_padding_bytes(&mut bytes[field!(st_atim)..field_end!(st_atim)]); - zero!(field_end!(st_atim), field!(st_mtim)); - - self.st_mtim - .zero_padding_bytes(&mut bytes[field!(st_mtim)..field_end!(st_mtim)]); - zero!(field_end!(st_mtim), field!(st_ctim)); - - self.st_ctim - .zero_padding_bytes(&mut bytes[field!(st_ctim)..field_end!(st_ctim)]); - zero!(field_end!(st_ctim), std::mem::size_of_val(self)); - } -} - -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(), - } - } -} - -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 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, - // TODO: What should we map invalid native values to? - _ => Self::Inval, - } - } - - #[cfg(feature = "sys")] - 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 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, - // TODO: What should we map invalid native values to? - _ => Self::Unknown, - } - } - - #[cfg(feature = "sys")] - 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 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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } - - #[cfg(feature = "sys")] - 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 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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } - - #[cfg(feature = "sys")] - 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 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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } - - #[cfg(feature = "sys")] - 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 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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } - - #[cfg(feature = "sys")] - 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) - } - - #[cfg(feature = "sys")] - 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 Eventrwflags { - 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 u8) - } - - #[cfg(feature = "sys")] - 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 u8) - } - - #[cfg(feature = "sys")] - 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 Subclockflags { - 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 u8) - } - - #[cfg(feature = "sys")] - 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 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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } - - #[cfg(feature = "sys")] - 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 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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } - - #[cfg(feature = "sys")] - 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 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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } - - #[cfg(feature = "sys")] - 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 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 u8) - } - - #[cfg(feature = "sys")] - 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 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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } - - #[cfg(feature = "sys")] - 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 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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } - - #[cfg(feature = "sys")] - 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 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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } - - #[cfg(feature = "sys")] - 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 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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } - - #[cfg(feature = "sys")] - 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 ValueType for Snapshot0Clockid { - #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} -} - -impl Eventtype { - pub fn to_str(self) -> &'static str { - match self { - Eventtype::Clock => "Wasi::Eventtype::Clock", - Eventtype::FdRead => "Wasi::Eventtype::FdRead", - Eventtype::FdWrite => "Wasi::Eventtype::FdWrite", - } - } -} - -/// 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), - } - } -} - -// TODO: if necessary, must be implemented in wit-bindgen -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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } - - #[cfg(feature = "sys")] - 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 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, - // TODO: What should we map invalid native values to? - _ => todo!("Need to decide what to do here…"), - } - } - - #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { - // TODO: find correct implementation - false - } -} +pub(crate) mod extra; +pub(crate) mod extra_manual; +pub use extra::*; +pub use extra_manual::*; diff --git a/lib/wasi-types-generated/wit-clean/output.wit b/lib/wasi-types-generated/wit-clean/output.wit index c3d0b3c5ca1..c3febd19fc3 100644 --- a/lib/wasi-types-generated/wit-clean/output.wit +++ b/lib/wasi-types-generated/wit-clean/output.wit @@ -8,6 +8,8 @@ expose-types-dummy-func: func( fd: fd, dirent: dirent, + snapshot0-dirent: snapshot0-dirent, + snapshot0-event: snapshot0-event, event-enum: event-enum, event: event, fdstat: fdstat, diff --git a/lib/wasi-types-generated/wit-clean/typenames.wit b/lib/wasi-types-generated/wit-clean/typenames.wit index 9f56860fbba..4d90f429ac0 100644 --- a/lib/wasi-types-generated/wit-clean/typenames.wit +++ b/lib/wasi-types-generated/wit-clean/typenames.wit @@ -8,6 +8,8 @@ expose-types-dummy-func: func( fd: fd, dirent: dirent, + snapshot0-dirent: snapshot0-dirent, + snapshot0-event: snapshot0-event, event-enum: event-enum, event: event, fdstat: fdstat, From ca17477c8b7df510bc8a0ef62b56767832078341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 7 Sep 2022 19:31:34 +0200 Subject: [PATCH 50/84] Finish conversion to autogenerated bindings --- .../src/wasi/extra_manual.rs | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/lib/wasi-types-generated/src/wasi/extra_manual.rs b/lib/wasi-types-generated/src/wasi/extra_manual.rs index df55437bb97..e3cb22b2943 100644 --- a/lib/wasi-types-generated/src/wasi/extra_manual.rs +++ b/lib/wasi-types-generated/src/wasi/extra_manual.rs @@ -179,3 +179,58 @@ impl std::fmt::Display for Sockoption { 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 u8) + } + + #[cfg(feature = "sys")] + 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) + } + + #[cfg(feature = "sys")] + 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 u8) + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + // TODO: find correct implementation + false + } +} From 2c72e6e59eaeb504b149f70c2f7e3c87570b64f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 7 Sep 2022 19:47:51 +0200 Subject: [PATCH 51/84] cargo fmt --- lib/wasi-types-generated/build.rs | 1 - lib/wasi-types-generated/src/wasi/extra.rs | 3740 ++++++++++---------- 2 files changed, 1891 insertions(+), 1850 deletions(-) diff --git a/lib/wasi-types-generated/build.rs b/lib/wasi-types-generated/build.rs index a683c85acd6..358c8790fa6 100644 --- a/lib/wasi-types-generated/build.rs +++ b/lib/wasi-types-generated/build.rs @@ -63,7 +63,6 @@ fn main() { match &i.kind { wit_parser::TypeDefKind::Enum(e) => { - contents.push_str( &format!( " diff --git a/lib/wasi-types-generated/src/wasi/extra.rs b/lib/wasi-types-generated/src/wasi/extra.rs index fecdb179381..3b9be3cd1fd 100644 --- a/lib/wasi-types-generated/src/wasi/extra.rs +++ b/lib/wasi-types-generated/src/wasi/extra.rs @@ -1,548 +1,541 @@ - use std::mem::MaybeUninit; use wasmer::ValueType; - - - /// 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() +/// 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", - } +/// 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.", + } + } } -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::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 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", - } + +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." + } + } + } } -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::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 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! { + +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`. @@ -550,7 +543,7 @@ pub struct Rights: u64 { /// 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; @@ -631,145 +624,127 @@ pub struct Rights: u64 { 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() +impl Rights { + /// Convert from a raw integer, preserving any unknown bits. See + /// + pub fn from_bits_preserve(bits: u64) -> Self { + Self { bits } + } } -Advice::Willneed => { - f.debug_tuple("Advice::Willneed").finish() +/// 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(), + } + } } -Advice::Dontneed => { - f.debug_tuple("Advice::Dontneed").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() + } } -Advice::Noreuse => { - f.debug_tuple("Advice::Noreuse").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! { +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. @@ -786,32 +761,38 @@ pub struct Fdflags: u8 { 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 } +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! { +/// 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. pub struct Fstflags: u8 { /// Adjust the last data access timestamp to the value stored in `filestat::atim`. @@ -824,28 +805,28 @@ pub struct Fstflags: u8 { 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 } +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! { +wit_bindgen_rust::bitflags::bitflags! { /// Flags determining the method of how paths are resolved. 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 } +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! { +wit_bindgen_rust::bitflags::bitflags! { /// Open flags used by `path_open`. pub struct Oflags: u8 { /// Create file if it does not exist. @@ -858,46 +839,40 @@ pub struct Oflags: u8 { 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() +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! { +wit_bindgen_rust::bitflags::bitflags! { /// Flags determining how to interpret the timestamp provided in /// `subscription-clock::timeout`. pub struct Subclockflags: u8 { @@ -909,68 +884,79 @@ pub struct Subclockflags: u8 { 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 } +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() +/// 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() + } } - } - wit_bindgen_rust::bitflags::bitflags! { +/// 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 { @@ -978,990 +964,1052 @@ pub struct Eventrwflags: u8 { 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() +impl Eventrwflags { + /// Convert from a raw integer, preserving any unknown bits. See + /// + pub fn from_bits_preserve(bits: u8) -> Self { + Self { bits } + } } -Snapshot0Whence::Set => { - f.debug_tuple("Snapshot0Whence::Set").finish() +/// 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() + } } - } - #[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() +/// 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(), + } + } } -Whence::Cur => { - f.debug_tuple("Whence::Cur").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() + } } -Whence::End => { - f.debug_tuple("Whence::End").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() + } + } + } } - } - #[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() +/// 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() + } } -BusDataFormat::Bincode => { - f.debug_tuple("BusDataFormat::Bincode").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() + } } -BusDataFormat::MessagePack => { - f.debug_tuple("BusDataFormat::MessagePack").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() + } } -BusDataFormat::Json => { - f.debug_tuple("BusDataFormat::Json").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(), + } + } } -BusDataFormat::Yaml => { - f.debug_tuple("BusDataFormat::Yaml").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(), + } + } } -BusDataFormat::Xml => { - f.debug_tuple("BusDataFormat::Xml").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(), + } + } } -BusDataFormat::Rkyv => { - f.debug_tuple("BusDataFormat::Rkyv").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(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() +#[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() + } } -BusEventType::Exit => { - f.debug_tuple("BusEventType::Exit").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() + } } -BusEventType::Call => { - f.debug_tuple("BusEventType::Call").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(), + } + } } -BusEventType::Result => { - f.debug_tuple("BusEventType::Result").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(), + } + } } -BusEventType::Fault => { - f.debug_tuple("BusEventType::Fault").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() + } } -BusEventType::Close => { - f.debug_tuple("BusEventType::Close").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(), + } + } } - } - /// Dummy function to expose types into generated code - pub fn expose_types_dummy_func(fd: Fd,dirent: Dirent,snapshot0_dirent: Snapshot0Dirent,snapshot0_event: Snapshot0Event,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,tid: Tid,pid: Pid,bus_data_format: BusDataFormat,) -> (){ -unsafe { - let ptr0 = OUTPUT_RET_AREA.0.as_mut_ptr() as i32; - *((ptr0 + 0) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd); - let Dirent{ d_next:d_next1, d_ino:d_ino1, d_type:d_type1, d_namlen:d_namlen1, } = dirent; - *((ptr0 + 8) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_next1); - *((ptr0 + 16) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_ino1); - *((ptr0 + 24) as *mut u8) = (match d_type1 { -Filetype::Unknown => 0, -Filetype::BlockDevice => 1, -Filetype::CharacterDevice => 2, -Filetype::Directory => 3, -Filetype::RegularFile => 4, -Filetype::SocketDgram => 5, -Filetype::SocketStream => 6, -Filetype::SymbolicLink => 7, -Filetype::Fifo => 8, - }) as u8; - *((ptr0 + 28) as *mut i32) = wit_bindgen_rust::rt::as_i32(d_namlen1); - let Snapshot0Dirent{ d_next:d_next2, d_ino:d_ino2, d_namlen:d_namlen2, d_type:d_type2, } = snapshot0_dirent; - *((ptr0 + 32) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_next2); - *((ptr0 + 40) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_ino2); - *((ptr0 + 48) as *mut i32) = wit_bindgen_rust::rt::as_i32(d_namlen2); - *((ptr0 + 52) as *mut u8) = (match d_type2 { -Filetype::Unknown => 0, -Filetype::BlockDevice => 1, -Filetype::CharacterDevice => 2, -Filetype::Directory => 3, -Filetype::RegularFile => 4, -Filetype::SocketDgram => 5, -Filetype::SocketStream => 6, -Filetype::SymbolicLink => 7, -Filetype::Fifo => 8, - }) as u8; - let Snapshot0Event{ userdata:userdata3, error:error3, type_:type_3, fd_readwrite:fd_readwrite3, } = snapshot0_event; - *((ptr0 + 56) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata3); - *((ptr0 + 64) as *mut u8) = (match error3 { -Errno::Success => 0, -Errno::Toobig => 1, -Errno::Access => 2, -Errno::Addrinuse => 3, -Errno::Addrnotavail => 4, -Errno::Afnosupport => 5, -Errno::Again => 6, -Errno::Already => 7, -Errno::Badf => 8, -Errno::Badmsg => 9, -Errno::Busy => 10, -Errno::Canceled => 11, -Errno::Child => 12, -Errno::Connaborted => 13, -Errno::Connrefused => 14, -Errno::Connreset => 15, -Errno::Deadlk => 16, -Errno::Destaddrreq => 17, -Errno::Dom => 18, -Errno::Dquot => 19, -Errno::Exist => 20, -Errno::Fault => 21, -Errno::Fbig => 22, -Errno::Hostunreach => 23, -Errno::Idrm => 24, -Errno::Ilseq => 25, -Errno::Inprogress => 26, -Errno::Intr => 27, -Errno::Inval => 28, -Errno::Io => 29, -Errno::Isconn => 30, -Errno::Isdir => 31, -Errno::Loop => 32, -Errno::Mfile => 33, -Errno::Mlink => 34, -Errno::Msgsize => 35, -Errno::Multihop => 36, -Errno::Nametoolong => 37, -Errno::Netdown => 38, -Errno::Netreset => 39, -Errno::Netunreach => 40, -Errno::Nfile => 41, -Errno::Nobufs => 42, -Errno::Nodev => 43, -Errno::Noent => 44, -Errno::Noexec => 45, -Errno::Nolck => 46, -Errno::Nolink => 47, -Errno::Nomem => 48, -Errno::Nomsg => 49, -Errno::Noprotoopt => 50, -Errno::Nospc => 51, -Errno::Nosys => 52, -Errno::Notconn => 53, -Errno::Notdir => 54, -Errno::Notempty => 55, -Errno::Notrecoverable => 56, -Errno::Notsock => 57, -Errno::Notsup => 58, -Errno::Notty => 59, -Errno::Nxio => 60, -Errno::Overflow => 61, -Errno::Ownerdead => 62, -Errno::Perm => 63, -Errno::Pipe => 64, -Errno::Proto => 65, -Errno::Protonosupport => 66, -Errno::Prototype => 67, -Errno::Range => 68, -Errno::Rofs => 69, -Errno::Spipe => 70, -Errno::Srch => 71, -Errno::Stale => 72, -Errno::Timedout => 73, -Errno::Txtbsy => 74, -Errno::Xdev => 75, -Errno::Notcapable => 76, - }) as u8; - *((ptr0 + 65) as *mut u8) = (match type_3 { -Eventtype::Clock => 0, -Eventtype::FdRead => 1, -Eventtype::FdWrite => 2, - }) as u8; - let EventFdReadwrite{ nbytes:nbytes4, flags:flags4, } = fd_readwrite3; - *((ptr0 + 72) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes4); - let flags5 = flags4; - *((ptr0 + 80) as *mut u8) = ((flags5.bits() >> 0) as i32) as u8; - match event_enum { -EventEnum::FdRead(e) => { - *((ptr0 + 88) as *mut u8) = (0i32) as u8; - let EventFdReadwrite{ nbytes:nbytes6, flags:flags6, } = e; - *((ptr0 + 96) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes6); - let flags7 = flags6; - *((ptr0 + 104) as *mut u8) = ((flags7.bits() >> 0) as i32) as u8; - -}, -EventEnum::FdWrite(e) => { - *((ptr0 + 88) as *mut u8) = (1i32) as u8; - let EventFdReadwrite{ nbytes:nbytes8, flags:flags8, } = e; - *((ptr0 + 96) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes8); - let flags9 = flags8; - *((ptr0 + 104) as *mut u8) = ((flags9.bits() >> 0) as i32) as u8; - -}, -EventEnum::Clock=> { - let e = (); - { -*((ptr0 + 88) as *mut u8) = (2i32) as u8; -let () = e; - - } +/// Dummy function to expose types into generated code +pub fn expose_types_dummy_func( + fd: Fd, + dirent: Dirent, + snapshot0_dirent: Snapshot0Dirent, + snapshot0_event: Snapshot0Event, + event_enum: EventEnum, + event: Event, + fdstat: Fdstat, + subscription_clock: SubscriptionClock, + snapshot0_subscription_clock: Snapshot0SubscriptionClock, + subscription: Subscription, + snapshot0_subscription: Snapshot0Subscription, + device: Device, + linkcount: Linkcount, + snapshot0_linkcount: Snapshot0Linkcount, + filestat: Filestat, + snapshot0_filestat: Snapshot0Filestat, + tty: Tty, + tid: Tid, + pid: Pid, + bus_data_format: BusDataFormat, +) -> () { + unsafe { + let ptr0 = OUTPUT_RET_AREA.0.as_mut_ptr() as i32; + *((ptr0 + 0) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd); + let Dirent { + d_next: d_next1, + d_ino: d_ino1, + d_type: d_type1, + d_namlen: d_namlen1, + } = dirent; + *((ptr0 + 8) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_next1); + *((ptr0 + 16) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_ino1); + *((ptr0 + 24) as *mut u8) = (match d_type1 { + Filetype::Unknown => 0, + Filetype::BlockDevice => 1, + Filetype::CharacterDevice => 2, + Filetype::Directory => 3, + Filetype::RegularFile => 4, + Filetype::SocketDgram => 5, + Filetype::SocketStream => 6, + Filetype::SymbolicLink => 7, + Filetype::Fifo => 8, + }) as u8; + *((ptr0 + 28) as *mut i32) = wit_bindgen_rust::rt::as_i32(d_namlen1); + let Snapshot0Dirent { + d_next: d_next2, + d_ino: d_ino2, + d_namlen: d_namlen2, + d_type: d_type2, + } = snapshot0_dirent; + *((ptr0 + 32) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_next2); + *((ptr0 + 40) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_ino2); + *((ptr0 + 48) as *mut i32) = wit_bindgen_rust::rt::as_i32(d_namlen2); + *((ptr0 + 52) as *mut u8) = (match d_type2 { + Filetype::Unknown => 0, + Filetype::BlockDevice => 1, + Filetype::CharacterDevice => 2, + Filetype::Directory => 3, + Filetype::RegularFile => 4, + Filetype::SocketDgram => 5, + Filetype::SocketStream => 6, + Filetype::SymbolicLink => 7, + Filetype::Fifo => 8, + }) as u8; + let Snapshot0Event { + userdata: userdata3, + error: error3, + type_: type_3, + fd_readwrite: fd_readwrite3, + } = snapshot0_event; + *((ptr0 + 56) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata3); + *((ptr0 + 64) as *mut u8) = (match error3 { + Errno::Success => 0, + Errno::Toobig => 1, + Errno::Access => 2, + Errno::Addrinuse => 3, + Errno::Addrnotavail => 4, + Errno::Afnosupport => 5, + Errno::Again => 6, + Errno::Already => 7, + Errno::Badf => 8, + Errno::Badmsg => 9, + Errno::Busy => 10, + Errno::Canceled => 11, + Errno::Child => 12, + Errno::Connaborted => 13, + Errno::Connrefused => 14, + Errno::Connreset => 15, + Errno::Deadlk => 16, + Errno::Destaddrreq => 17, + Errno::Dom => 18, + Errno::Dquot => 19, + Errno::Exist => 20, + Errno::Fault => 21, + Errno::Fbig => 22, + Errno::Hostunreach => 23, + Errno::Idrm => 24, + Errno::Ilseq => 25, + Errno::Inprogress => 26, + Errno::Intr => 27, + Errno::Inval => 28, + Errno::Io => 29, + Errno::Isconn => 30, + Errno::Isdir => 31, + Errno::Loop => 32, + Errno::Mfile => 33, + Errno::Mlink => 34, + Errno::Msgsize => 35, + Errno::Multihop => 36, + Errno::Nametoolong => 37, + Errno::Netdown => 38, + Errno::Netreset => 39, + Errno::Netunreach => 40, + Errno::Nfile => 41, + Errno::Nobufs => 42, + Errno::Nodev => 43, + Errno::Noent => 44, + Errno::Noexec => 45, + Errno::Nolck => 46, + Errno::Nolink => 47, + Errno::Nomem => 48, + Errno::Nomsg => 49, + Errno::Noprotoopt => 50, + Errno::Nospc => 51, + Errno::Nosys => 52, + Errno::Notconn => 53, + Errno::Notdir => 54, + Errno::Notempty => 55, + Errno::Notrecoverable => 56, + Errno::Notsock => 57, + Errno::Notsup => 58, + Errno::Notty => 59, + Errno::Nxio => 60, + Errno::Overflow => 61, + Errno::Ownerdead => 62, + Errno::Perm => 63, + Errno::Pipe => 64, + Errno::Proto => 65, + Errno::Protonosupport => 66, + Errno::Prototype => 67, + Errno::Range => 68, + Errno::Rofs => 69, + Errno::Spipe => 70, + Errno::Srch => 71, + Errno::Stale => 72, + Errno::Timedout => 73, + Errno::Txtbsy => 74, + Errno::Xdev => 75, + Errno::Notcapable => 76, + }) as u8; + *((ptr0 + 65) as *mut u8) = (match type_3 { + Eventtype::Clock => 0, + Eventtype::FdRead => 1, + Eventtype::FdWrite => 2, + }) as u8; + let EventFdReadwrite { + nbytes: nbytes4, + flags: flags4, + } = fd_readwrite3; + *((ptr0 + 72) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes4); + let flags5 = flags4; + *((ptr0 + 80) as *mut u8) = ((flags5.bits() >> 0) as i32) as u8; + match event_enum { + EventEnum::FdRead(e) => { + *((ptr0 + 88) as *mut u8) = (0i32) as u8; + let EventFdReadwrite { + nbytes: nbytes6, + flags: flags6, + } = e; + *((ptr0 + 96) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes6); + let flags7 = flags6; + *((ptr0 + 104) as *mut u8) = ((flags7.bits() >> 0) as i32) as u8; + } + EventEnum::FdWrite(e) => { + *((ptr0 + 88) as *mut u8) = (1i32) as u8; + let EventFdReadwrite { + nbytes: nbytes8, + flags: flags8, + } = e; + *((ptr0 + 96) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes8); + let flags9 = flags8; + *((ptr0 + 104) as *mut u8) = ((flags9.bits() >> 0) as i32) as u8; + } + EventEnum::Clock => { + let e = (); + { + *((ptr0 + 88) as *mut u8) = (2i32) as u8; + let () = e; + } + } + }; + let Event { + userdata: userdata10, + error: error10, + data: data10, + } = event; + *((ptr0 + 112) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata10); + *((ptr0 + 120) as *mut u8) = (match error10 { + Errno::Success => 0, + Errno::Toobig => 1, + Errno::Access => 2, + Errno::Addrinuse => 3, + Errno::Addrnotavail => 4, + Errno::Afnosupport => 5, + Errno::Again => 6, + Errno::Already => 7, + Errno::Badf => 8, + Errno::Badmsg => 9, + Errno::Busy => 10, + Errno::Canceled => 11, + Errno::Child => 12, + Errno::Connaborted => 13, + Errno::Connrefused => 14, + Errno::Connreset => 15, + Errno::Deadlk => 16, + Errno::Destaddrreq => 17, + Errno::Dom => 18, + Errno::Dquot => 19, + Errno::Exist => 20, + Errno::Fault => 21, + Errno::Fbig => 22, + Errno::Hostunreach => 23, + Errno::Idrm => 24, + Errno::Ilseq => 25, + Errno::Inprogress => 26, + Errno::Intr => 27, + Errno::Inval => 28, + Errno::Io => 29, + Errno::Isconn => 30, + Errno::Isdir => 31, + Errno::Loop => 32, + Errno::Mfile => 33, + Errno::Mlink => 34, + Errno::Msgsize => 35, + Errno::Multihop => 36, + Errno::Nametoolong => 37, + Errno::Netdown => 38, + Errno::Netreset => 39, + Errno::Netunreach => 40, + Errno::Nfile => 41, + Errno::Nobufs => 42, + Errno::Nodev => 43, + Errno::Noent => 44, + Errno::Noexec => 45, + Errno::Nolck => 46, + Errno::Nolink => 47, + Errno::Nomem => 48, + Errno::Nomsg => 49, + Errno::Noprotoopt => 50, + Errno::Nospc => 51, + Errno::Nosys => 52, + Errno::Notconn => 53, + Errno::Notdir => 54, + Errno::Notempty => 55, + Errno::Notrecoverable => 56, + Errno::Notsock => 57, + Errno::Notsup => 58, + Errno::Notty => 59, + Errno::Nxio => 60, + Errno::Overflow => 61, + Errno::Ownerdead => 62, + Errno::Perm => 63, + Errno::Pipe => 64, + Errno::Proto => 65, + Errno::Protonosupport => 66, + Errno::Prototype => 67, + Errno::Range => 68, + Errno::Rofs => 69, + Errno::Spipe => 70, + Errno::Srch => 71, + Errno::Stale => 72, + Errno::Timedout => 73, + Errno::Txtbsy => 74, + Errno::Xdev => 75, + Errno::Notcapable => 76, + }) as u8; + match data10 { + EventEnum::FdRead(e) => { + *((ptr0 + 128) as *mut u8) = (0i32) as u8; + let EventFdReadwrite { + nbytes: nbytes11, + flags: flags11, + } = e; + *((ptr0 + 136) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes11); + let flags12 = flags11; + *((ptr0 + 144) as *mut u8) = ((flags12.bits() >> 0) as i32) as u8; + } + EventEnum::FdWrite(e) => { + *((ptr0 + 128) as *mut u8) = (1i32) as u8; + let EventFdReadwrite { + nbytes: nbytes13, + flags: flags13, + } = e; + *((ptr0 + 136) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes13); + let flags14 = flags13; + *((ptr0 + 144) as *mut u8) = ((flags14.bits() >> 0) as i32) as u8; + } + EventEnum::Clock => { + let e = (); + { + *((ptr0 + 128) as *mut u8) = (2i32) as u8; + let () = e; + } + } + }; + let Fdstat { + fs_filetype: fs_filetype15, + fs_flags: fs_flags15, + fs_rights_base: fs_rights_base15, + fs_rights_inheriting: fs_rights_inheriting15, + } = fdstat; + *((ptr0 + 152) as *mut u8) = (match fs_filetype15 { + Filetype::Unknown => 0, + Filetype::BlockDevice => 1, + Filetype::CharacterDevice => 2, + Filetype::Directory => 3, + Filetype::RegularFile => 4, + Filetype::SocketDgram => 5, + Filetype::SocketStream => 6, + Filetype::SymbolicLink => 7, + Filetype::Fifo => 8, + }) as u8; + let flags16 = fs_flags15; + *((ptr0 + 153) as *mut u8) = ((flags16.bits() >> 0) as i32) as u8; + let flags17 = fs_rights_base15; + *((ptr0 + 160) as *mut i32) = (flags17.bits() >> 32) as i32; + *((ptr0 + 156) as *mut i32) = (flags17.bits() >> 0) as i32; + let flags18 = fs_rights_inheriting15; + *((ptr0 + 168) as *mut i32) = (flags18.bits() >> 32) as i32; + *((ptr0 + 164) as *mut i32) = (flags18.bits() >> 0) as i32; + let SubscriptionClock { + clock_id: clock_id19, + timeout: timeout19, + precision: precision19, + flags: flags19, + } = subscription_clock; + *((ptr0 + 176) as *mut u8) = (match clock_id19 { + Clockid::Realtime => 0, + Clockid::Monotonic => 1, + }) as u8; + *((ptr0 + 184) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout19); + *((ptr0 + 192) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision19); + let flags20 = flags19; + *((ptr0 + 200) as *mut u8) = ((flags20.bits() >> 0) as i32) as u8; + let Snapshot0SubscriptionClock { + identifier: identifier21, + id: id21, + timeout: timeout21, + precision: precision21, + flags: flags21, + } = snapshot0_subscription_clock; + *((ptr0 + 208) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier21); + *((ptr0 + 216) as *mut u8) = (match id21 { + Snapshot0Clockid::Realtime => 0, + Snapshot0Clockid::Monotonic => 1, + Snapshot0Clockid::ProcessCputimeId => 2, + Snapshot0Clockid::ThreadCputimeId => 3, + }) as u8; + *((ptr0 + 224) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout21); + *((ptr0 + 232) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision21); + let flags22 = flags21; + *((ptr0 + 240) as *mut u8) = ((flags22.bits() >> 0) as i32) as u8; + let Subscription { + userdata: userdata23, + data: data23, + } = subscription; + *((ptr0 + 248) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata23); + match data23 { + SubscriptionEnum::Clock(e) => { + *((ptr0 + 256) as *mut u8) = (0i32) as u8; + let SubscriptionClock { + clock_id: clock_id24, + timeout: timeout24, + precision: precision24, + flags: flags24, + } = e; + *((ptr0 + 264) as *mut u8) = (match clock_id24 { + Clockid::Realtime => 0, + Clockid::Monotonic => 1, + }) as u8; + *((ptr0 + 272) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout24); + *((ptr0 + 280) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision24); + let flags25 = flags24; + *((ptr0 + 288) as *mut u8) = ((flags25.bits() >> 0) as i32) as u8; + } + SubscriptionEnum::Read(e) => { + *((ptr0 + 256) as *mut u8) = (1i32) as u8; + let SubscriptionFsReadwrite { + file_descriptor: file_descriptor26, + } = e; + *((ptr0 + 264) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor26); + } + SubscriptionEnum::Write(e) => { + *((ptr0 + 256) as *mut u8) = (2i32) as u8; + let SubscriptionFsReadwrite { + file_descriptor: file_descriptor27, + } = e; + *((ptr0 + 264) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor27); + } + }; + let Snapshot0Subscription { + userdata: userdata28, + data: data28, + } = snapshot0_subscription; + *((ptr0 + 296) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata28); + match data28 { + Snapshot0SubscriptionEnum::Clock(e) => { + *((ptr0 + 304) as *mut u8) = (0i32) as u8; + let Snapshot0SubscriptionClock { + identifier: identifier29, + id: id29, + timeout: timeout29, + precision: precision29, + flags: flags29, + } = e; + *((ptr0 + 312) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier29); + *((ptr0 + 320) as *mut u8) = (match id29 { + Snapshot0Clockid::Realtime => 0, + Snapshot0Clockid::Monotonic => 1, + Snapshot0Clockid::ProcessCputimeId => 2, + Snapshot0Clockid::ThreadCputimeId => 3, + }) as u8; + *((ptr0 + 328) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout29); + *((ptr0 + 336) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision29); + let flags30 = flags29; + *((ptr0 + 344) as *mut u8) = ((flags30.bits() >> 0) as i32) as u8; + } + Snapshot0SubscriptionEnum::Read(e) => { + *((ptr0 + 304) as *mut u8) = (1i32) as u8; + let SubscriptionFsReadwrite { + file_descriptor: file_descriptor31, + } = e; + *((ptr0 + 312) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor31); + } + Snapshot0SubscriptionEnum::Write(e) => { + *((ptr0 + 304) as *mut u8) = (2i32) as u8; + let SubscriptionFsReadwrite { + file_descriptor: file_descriptor32, + } = e; + *((ptr0 + 312) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor32); + } + }; + *((ptr0 + 352) as *mut i64) = wit_bindgen_rust::rt::as_i64(device); + *((ptr0 + 360) as *mut i64) = wit_bindgen_rust::rt::as_i64(linkcount); + *((ptr0 + 368) as *mut i32) = wit_bindgen_rust::rt::as_i32(snapshot0_linkcount); + let Filestat { + st_dev: st_dev33, + st_ino: st_ino33, + st_filetype: st_filetype33, + st_nlink: st_nlink33, + st_size: st_size33, + st_atim: st_atim33, + st_mtim: st_mtim33, + st_ctim: st_ctim33, + } = filestat; + *((ptr0 + 376) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev33); + *((ptr0 + 384) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino33); + *((ptr0 + 392) as *mut u8) = (match st_filetype33 { + Filetype::Unknown => 0, + Filetype::BlockDevice => 1, + Filetype::CharacterDevice => 2, + Filetype::Directory => 3, + Filetype::RegularFile => 4, + Filetype::SocketDgram => 5, + Filetype::SocketStream => 6, + Filetype::SymbolicLink => 7, + Filetype::Fifo => 8, + }) as u8; + *((ptr0 + 400) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_nlink33); + *((ptr0 + 408) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size33); + *((ptr0 + 416) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim33); + *((ptr0 + 424) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim33); + *((ptr0 + 432) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim33); + let Snapshot0Filestat { + st_dev: st_dev34, + st_ino: st_ino34, + st_filetype: st_filetype34, + st_nlink: st_nlink34, + st_size: st_size34, + st_atim: st_atim34, + st_mtim: st_mtim34, + st_ctim: st_ctim34, + } = snapshot0_filestat; + *((ptr0 + 440) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev34); + *((ptr0 + 448) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino34); + *((ptr0 + 456) as *mut u8) = (match st_filetype34 { + Filetype::Unknown => 0, + Filetype::BlockDevice => 1, + Filetype::CharacterDevice => 2, + Filetype::Directory => 3, + Filetype::RegularFile => 4, + Filetype::SocketDgram => 5, + Filetype::SocketStream => 6, + Filetype::SymbolicLink => 7, + Filetype::Fifo => 8, + }) as u8; + *((ptr0 + 460) as *mut i32) = wit_bindgen_rust::rt::as_i32(st_nlink34); + *((ptr0 + 464) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size34); + *((ptr0 + 472) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim34); + *((ptr0 + 480) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim34); + *((ptr0 + 488) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim34); + let Tty { + cols: cols35, + rows: rows35, + width: width35, + height: height35, + stdin_tty: stdin_tty35, + stdout_tty: stdout_tty35, + stderr_tty: stderr_tty35, + echo: echo35, + line_buffered: line_buffered35, + } = tty; + *((ptr0 + 496) as *mut i32) = wit_bindgen_rust::rt::as_i32(cols35); + *((ptr0 + 500) as *mut i32) = wit_bindgen_rust::rt::as_i32(rows35); + *((ptr0 + 504) as *mut i32) = wit_bindgen_rust::rt::as_i32(width35); + *((ptr0 + 508) as *mut i32) = wit_bindgen_rust::rt::as_i32(height35); + *((ptr0 + 512) as *mut u8) = (match stdin_tty35 { + true => 1, + false => 0, + }) as u8; + *((ptr0 + 513) as *mut u8) = (match stdout_tty35 { + true => 1, + false => 0, + }) as u8; + *((ptr0 + 514) as *mut u8) = (match stderr_tty35 { + true => 1, + false => 0, + }) as u8; + *((ptr0 + 515) as *mut u8) = (match echo35 { + true => 1, + false => 0, + }) as u8; + *((ptr0 + 516) as *mut u8) = (match line_buffered35 { + true => 1, + false => 0, + }) as u8; + *((ptr0 + 520) as *mut i32) = wit_bindgen_rust::rt::as_i32(tid); + *((ptr0 + 524) as *mut i32) = wit_bindgen_rust::rt::as_i32(pid); + *((ptr0 + 528) as *mut u8) = (match bus_data_format { + BusDataFormat::Raw => 0, + BusDataFormat::Bincode => 1, + BusDataFormat::MessagePack => 2, + BusDataFormat::Json => 3, + BusDataFormat::Yaml => 4, + BusDataFormat::Xml => 5, + BusDataFormat::Rkyv => 6, + }) as u8; + #[link(wasm_import_module = "output")] + extern "C" { + #[cfg_attr(target_arch = "wasm32", link_name = "expose-types-dummy-func")] + #[cfg_attr( + not(target_arch = "wasm32"), + link_name = "output_expose-types-dummy-func" + )] + fn wit_import(_: i32); + } + wit_import(ptr0); + () + } } - }; - let Event{ userdata:userdata10, error:error10, data:data10, } = event; - *((ptr0 + 112) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata10); - *((ptr0 + 120) as *mut u8) = (match error10 { -Errno::Success => 0, -Errno::Toobig => 1, -Errno::Access => 2, -Errno::Addrinuse => 3, -Errno::Addrnotavail => 4, -Errno::Afnosupport => 5, -Errno::Again => 6, -Errno::Already => 7, -Errno::Badf => 8, -Errno::Badmsg => 9, -Errno::Busy => 10, -Errno::Canceled => 11, -Errno::Child => 12, -Errno::Connaborted => 13, -Errno::Connrefused => 14, -Errno::Connreset => 15, -Errno::Deadlk => 16, -Errno::Destaddrreq => 17, -Errno::Dom => 18, -Errno::Dquot => 19, -Errno::Exist => 20, -Errno::Fault => 21, -Errno::Fbig => 22, -Errno::Hostunreach => 23, -Errno::Idrm => 24, -Errno::Ilseq => 25, -Errno::Inprogress => 26, -Errno::Intr => 27, -Errno::Inval => 28, -Errno::Io => 29, -Errno::Isconn => 30, -Errno::Isdir => 31, -Errno::Loop => 32, -Errno::Mfile => 33, -Errno::Mlink => 34, -Errno::Msgsize => 35, -Errno::Multihop => 36, -Errno::Nametoolong => 37, -Errno::Netdown => 38, -Errno::Netreset => 39, -Errno::Netunreach => 40, -Errno::Nfile => 41, -Errno::Nobufs => 42, -Errno::Nodev => 43, -Errno::Noent => 44, -Errno::Noexec => 45, -Errno::Nolck => 46, -Errno::Nolink => 47, -Errno::Nomem => 48, -Errno::Nomsg => 49, -Errno::Noprotoopt => 50, -Errno::Nospc => 51, -Errno::Nosys => 52, -Errno::Notconn => 53, -Errno::Notdir => 54, -Errno::Notempty => 55, -Errno::Notrecoverable => 56, -Errno::Notsock => 57, -Errno::Notsup => 58, -Errno::Notty => 59, -Errno::Nxio => 60, -Errno::Overflow => 61, -Errno::Ownerdead => 62, -Errno::Perm => 63, -Errno::Pipe => 64, -Errno::Proto => 65, -Errno::Protonosupport => 66, -Errno::Prototype => 67, -Errno::Range => 68, -Errno::Rofs => 69, -Errno::Spipe => 70, -Errno::Srch => 71, -Errno::Stale => 72, -Errno::Timedout => 73, -Errno::Txtbsy => 74, -Errno::Xdev => 75, -Errno::Notcapable => 76, - }) as u8; - match data10 { -EventEnum::FdRead(e) => { - *((ptr0 + 128) as *mut u8) = (0i32) as u8; - let EventFdReadwrite{ nbytes:nbytes11, flags:flags11, } = e; - *((ptr0 + 136) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes11); - let flags12 = flags11; - *((ptr0 + 144) as *mut u8) = ((flags12.bits() >> 0) as i32) as u8; - -}, -EventEnum::FdWrite(e) => { - *((ptr0 + 128) as *mut u8) = (1i32) as u8; - let EventFdReadwrite{ nbytes:nbytes13, flags:flags13, } = e; - *((ptr0 + 136) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes13); - let flags14 = flags13; - *((ptr0 + 144) as *mut u8) = ((flags14.bits() >> 0) as i32) as u8; - -}, -EventEnum::Clock=> { - let e = (); - { -*((ptr0 + 128) as *mut u8) = (2i32) as u8; -let () = e; - } -} - }; - let Fdstat{ fs_filetype:fs_filetype15, fs_flags:fs_flags15, fs_rights_base:fs_rights_base15, fs_rights_inheriting:fs_rights_inheriting15, } = fdstat; - *((ptr0 + 152) as *mut u8) = (match fs_filetype15 { -Filetype::Unknown => 0, -Filetype::BlockDevice => 1, -Filetype::CharacterDevice => 2, -Filetype::Directory => 3, -Filetype::RegularFile => 4, -Filetype::SocketDgram => 5, -Filetype::SocketStream => 6, -Filetype::SymbolicLink => 7, -Filetype::Fifo => 8, - }) as u8; - let flags16 = fs_flags15; - *((ptr0 + 153) as *mut u8) = ((flags16.bits() >> 0) as i32) as u8; - let flags17 = fs_rights_base15; - *((ptr0 + 160) as *mut i32) = (flags17.bits() >> 32) as i32; - *((ptr0 + 156) as *mut i32) = (flags17.bits() >> 0) as i32; - let flags18 = fs_rights_inheriting15; - *((ptr0 + 168) as *mut i32) = (flags18.bits() >> 32) as i32; - *((ptr0 + 164) as *mut i32) = (flags18.bits() >> 0) as i32; - let SubscriptionClock{ clock_id:clock_id19, timeout:timeout19, precision:precision19, flags:flags19, } = subscription_clock; - *((ptr0 + 176) as *mut u8) = (match clock_id19 { -Clockid::Realtime => 0, -Clockid::Monotonic => 1, - }) as u8; - *((ptr0 + 184) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout19); - *((ptr0 + 192) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision19); - let flags20 = flags19; - *((ptr0 + 200) as *mut u8) = ((flags20.bits() >> 0) as i32) as u8; - let Snapshot0SubscriptionClock{ identifier:identifier21, id:id21, timeout:timeout21, precision:precision21, flags:flags21, } = snapshot0_subscription_clock; - *((ptr0 + 208) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier21); - *((ptr0 + 216) as *mut u8) = (match id21 { -Snapshot0Clockid::Realtime => 0, -Snapshot0Clockid::Monotonic => 1, -Snapshot0Clockid::ProcessCputimeId => 2, -Snapshot0Clockid::ThreadCputimeId => 3, - }) as u8; - *((ptr0 + 224) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout21); - *((ptr0 + 232) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision21); - let flags22 = flags21; - *((ptr0 + 240) as *mut u8) = ((flags22.bits() >> 0) as i32) as u8; - let Subscription{ userdata:userdata23, data:data23, } = subscription; - *((ptr0 + 248) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata23); - match data23 { -SubscriptionEnum::Clock(e) => { - *((ptr0 + 256) as *mut u8) = (0i32) as u8; - let SubscriptionClock{ clock_id:clock_id24, timeout:timeout24, precision:precision24, flags:flags24, } = e; - *((ptr0 + 264) as *mut u8) = (match clock_id24 { -Clockid::Realtime => 0, -Clockid::Monotonic => 1, - }) as u8; - *((ptr0 + 272) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout24); - *((ptr0 + 280) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision24); - let flags25 = flags24; - *((ptr0 + 288) as *mut u8) = ((flags25.bits() >> 0) as i32) as u8; - -}, -SubscriptionEnum::Read(e) => { - *((ptr0 + 256) as *mut u8) = (1i32) as u8; - let SubscriptionFsReadwrite{ file_descriptor:file_descriptor26, } = e; - *((ptr0 + 264) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor26); - -}, -SubscriptionEnum::Write(e) => { - *((ptr0 + 256) as *mut u8) = (2i32) as u8; - let SubscriptionFsReadwrite{ file_descriptor:file_descriptor27, } = e; - *((ptr0 + 264) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor27); - -}, - }; - let Snapshot0Subscription{ userdata:userdata28, data:data28, } = snapshot0_subscription; - *((ptr0 + 296) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata28); - match data28 { -Snapshot0SubscriptionEnum::Clock(e) => { - *((ptr0 + 304) as *mut u8) = (0i32) as u8; - let Snapshot0SubscriptionClock{ identifier:identifier29, id:id29, timeout:timeout29, precision:precision29, flags:flags29, } = e; - *((ptr0 + 312) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier29); - *((ptr0 + 320) as *mut u8) = (match id29 { -Snapshot0Clockid::Realtime => 0, -Snapshot0Clockid::Monotonic => 1, -Snapshot0Clockid::ProcessCputimeId => 2, -Snapshot0Clockid::ThreadCputimeId => 3, - }) as u8; - *((ptr0 + 328) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout29); - *((ptr0 + 336) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision29); - let flags30 = flags29; - *((ptr0 + 344) as *mut u8) = ((flags30.bits() >> 0) as i32) as u8; - -}, -Snapshot0SubscriptionEnum::Read(e) => { - *((ptr0 + 304) as *mut u8) = (1i32) as u8; - let SubscriptionFsReadwrite{ file_descriptor:file_descriptor31, } = e; - *((ptr0 + 312) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor31); - -}, -Snapshot0SubscriptionEnum::Write(e) => { - *((ptr0 + 304) as *mut u8) = (2i32) as u8; - let SubscriptionFsReadwrite{ file_descriptor:file_descriptor32, } = e; - *((ptr0 + 312) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor32); - -}, - }; - *((ptr0 + 352) as *mut i64) = wit_bindgen_rust::rt::as_i64(device); - *((ptr0 + 360) as *mut i64) = wit_bindgen_rust::rt::as_i64(linkcount); - *((ptr0 + 368) as *mut i32) = wit_bindgen_rust::rt::as_i32(snapshot0_linkcount); - let Filestat{ st_dev:st_dev33, st_ino:st_ino33, st_filetype:st_filetype33, st_nlink:st_nlink33, st_size:st_size33, st_atim:st_atim33, st_mtim:st_mtim33, st_ctim:st_ctim33, } = filestat; - *((ptr0 + 376) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev33); - *((ptr0 + 384) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino33); - *((ptr0 + 392) as *mut u8) = (match st_filetype33 { -Filetype::Unknown => 0, -Filetype::BlockDevice => 1, -Filetype::CharacterDevice => 2, -Filetype::Directory => 3, -Filetype::RegularFile => 4, -Filetype::SocketDgram => 5, -Filetype::SocketStream => 6, -Filetype::SymbolicLink => 7, -Filetype::Fifo => 8, - }) as u8; - *((ptr0 + 400) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_nlink33); - *((ptr0 + 408) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size33); - *((ptr0 + 416) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim33); - *((ptr0 + 424) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim33); - *((ptr0 + 432) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim33); - let Snapshot0Filestat{ st_dev:st_dev34, st_ino:st_ino34, st_filetype:st_filetype34, st_nlink:st_nlink34, st_size:st_size34, st_atim:st_atim34, st_mtim:st_mtim34, st_ctim:st_ctim34, } = snapshot0_filestat; - *((ptr0 + 440) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev34); - *((ptr0 + 448) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino34); - *((ptr0 + 456) as *mut u8) = (match st_filetype34 { -Filetype::Unknown => 0, -Filetype::BlockDevice => 1, -Filetype::CharacterDevice => 2, -Filetype::Directory => 3, -Filetype::RegularFile => 4, -Filetype::SocketDgram => 5, -Filetype::SocketStream => 6, -Filetype::SymbolicLink => 7, -Filetype::Fifo => 8, - }) as u8; - *((ptr0 + 460) as *mut i32) = wit_bindgen_rust::rt::as_i32(st_nlink34); - *((ptr0 + 464) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size34); - *((ptr0 + 472) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim34); - *((ptr0 + 480) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim34); - *((ptr0 + 488) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim34); - let Tty{ cols:cols35, rows:rows35, width:width35, height:height35, stdin_tty:stdin_tty35, stdout_tty:stdout_tty35, stderr_tty:stderr_tty35, echo:echo35, line_buffered:line_buffered35, } = tty; - *((ptr0 + 496) as *mut i32) = wit_bindgen_rust::rt::as_i32(cols35); - *((ptr0 + 500) as *mut i32) = wit_bindgen_rust::rt::as_i32(rows35); - *((ptr0 + 504) as *mut i32) = wit_bindgen_rust::rt::as_i32(width35); - *((ptr0 + 508) as *mut i32) = wit_bindgen_rust::rt::as_i32(height35); - *((ptr0 + 512) as *mut u8) = (match stdin_tty35 { true => 1, false => 0 }) as u8; - *((ptr0 + 513) as *mut u8) = (match stdout_tty35 { true => 1, false => 0 }) as u8; - *((ptr0 + 514) as *mut u8) = (match stderr_tty35 { true => 1, false => 0 }) as u8; - *((ptr0 + 515) as *mut u8) = (match echo35 { true => 1, false => 0 }) as u8; - *((ptr0 + 516) as *mut u8) = (match line_buffered35 { true => 1, false => 0 }) as u8; - *((ptr0 + 520) as *mut i32) = wit_bindgen_rust::rt::as_i32(tid); - *((ptr0 + 524) as *mut i32) = wit_bindgen_rust::rt::as_i32(pid); - *((ptr0 + 528) as *mut u8) = (match bus_data_format { -BusDataFormat::Raw => 0, -BusDataFormat::Bincode => 1, -BusDataFormat::MessagePack => 2, -BusDataFormat::Json => 3, -BusDataFormat::Yaml => 4, -BusDataFormat::Xml => 5, -BusDataFormat::Rkyv => 6, - }) as u8; - #[link(wasm_import_module = "output")] - extern "C" { -#[cfg_attr(target_arch = "wasm32", link_name = "expose-types-dummy-func")] -#[cfg_attr(not(target_arch = "wasm32"), link_name = "output_expose-types-dummy-func")] -fn wit_import(_: i32, ); - } - wit_import(ptr0); - () -} - } - - #[repr(align(8))] - struct RetArea([u8; 536]); - static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 536]); +#[repr(align(8))] +struct RetArea([u8; 536]); +static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 536]); - // TODO: if necessary, must be implemented in wit-bindgen unsafe impl ValueType for Snapshot0Clockid { #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Snapshot0Clockid { type Native = i32; @@ -1981,16 +2029,17 @@ unsafe impl wasmer::FromToNativeWasmType for Snapshot0Clockid { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Clockid { type Native = i32; @@ -2008,16 +2057,17 @@ unsafe impl wasmer::FromToNativeWasmType for Clockid { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Errno { type Native = i32; @@ -2110,16 +2160,17 @@ unsafe impl wasmer::FromToNativeWasmType for Errno { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for BusErrno { type Native = i32; @@ -2155,23 +2206,23 @@ unsafe impl wasmer::FromToNativeWasmType for BusErrno { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Filetype { type Native = i32; @@ -2196,30 +2247,29 @@ unsafe impl wasmer::FromToNativeWasmType for Filetype { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + 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]) { } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Advice { type Native = i32; @@ -2241,51 +2291,47 @@ unsafe impl wasmer::FromToNativeWasmType for Advice { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Eventtype { type Native = i32; @@ -2304,37 +2350,35 @@ unsafe impl wasmer::FromToNativeWasmType for Eventtype { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Preopentype { type Native = i32; @@ -2351,86 +2395,77 @@ unsafe impl wasmer::FromToNativeWasmType for Preopentype { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Socktype { type Native = i32; @@ -2450,16 +2485,17 @@ unsafe impl wasmer::FromToNativeWasmType for Socktype { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Sockstatus { type Native = i32; @@ -2479,16 +2515,17 @@ unsafe impl wasmer::FromToNativeWasmType for Sockstatus { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Sockoption { type Native = i32; @@ -2531,16 +2568,17 @@ unsafe impl wasmer::FromToNativeWasmType for Sockoption { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Streamsecurity { type Native = i32; @@ -2560,16 +2598,17 @@ unsafe impl wasmer::FromToNativeWasmType for Streamsecurity { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Addressfamily { type Native = i32; @@ -2589,30 +2628,29 @@ unsafe impl wasmer::FromToNativeWasmType for Addressfamily { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + 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]) { } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Snapshot0Whence { type Native = i32; @@ -2631,16 +2669,17 @@ unsafe impl wasmer::FromToNativeWasmType for Snapshot0Whence { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Whence { type Native = i32; @@ -2659,23 +2698,23 @@ unsafe impl wasmer::FromToNativeWasmType for Whence { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for BusDataFormat { type Native = i32; @@ -2698,16 +2737,17 @@ unsafe impl wasmer::FromToNativeWasmType for BusDataFormat { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for BusEventType { type Native = i32; @@ -2729,5 +2769,7 @@ unsafe impl wasmer::FromToNativeWasmType for BusEventType { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } } From cb86205ccaef7ff66c70f8f2eb4abae096a5142b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 7 Sep 2022 20:23:13 +0200 Subject: [PATCH 52/84] Port bus.rs to wasi-types-generated --- lib/wasi-types-generated/src/wasi/bindings.rs | 134 +- lib/wasi-types-generated/src/wasi/extra.rs | 3918 +++++++++-------- .../src/wasi/extra_manual.rs | 9 + lib/wasi-types-generated/wit-clean/output.wit | 57 +- .../wit-clean/typenames.wit | 57 +- lib/wasi-types/src/bus.rs | 89 +- lib/wasi/src/syscalls/mod.rs | 32 +- lib/wasi/src/syscalls/wasix32.rs | 24 +- lib/wasi/src/syscalls/wasix64.rs | 24 +- 9 files changed, 2337 insertions(+), 2007 deletions(-) diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index 507840061bb..255d1d0cdc7 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -1513,8 +1513,84 @@ pub mod output { } } } + pub type Bid = u32; + pub type Cid = u32; + /// __wasi_option_t + pub type OptionTag = u8; + #[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()} + } /// Dummy function to expose types into generated code - pub fn expose_types_dummy_func(fd: Fd,dirent: Dirent,snapshot0_dirent: Snapshot0Dirent,snapshot0_event: Snapshot0Event,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,tid: Tid,pid: Pid,bus_data_format: BusDataFormat,) -> (){ + pub fn expose_types_dummy_func(fd: Fd,dirent: Dirent,snapshot0_dirent: Snapshot0Dirent,snapshot0_event: Snapshot0Event,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,tid: Tid,pid: Pid,bus_data_format: BusDataFormat,bid: Bid,option_bid: OptionBid,cid: Cid,option_cid: OptionCid,option_fd: OptionFd,bus_handles: BusHandles,exit_code: ExitCode,bus_event_exit: BusEventExit,bus_event_fault: BusEventFault,bus_event_close: BusEventClose,) -> (){ unsafe { let ptr0 = OUTPUT_RET_AREA.0.as_mut_ptr() as i32; *((ptr0 + 0) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd); @@ -1935,6 +2011,58 @@ pub mod output { BusDataFormat::Xml => 5, BusDataFormat::Rkyv => 6, }) as u8; + *((ptr0 + 532) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid); + let OptionBid{ tag:tag36, bid:bid36, } = option_bid; + *((ptr0 + 536) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag36)) as u8; + *((ptr0 + 540) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid36); + *((ptr0 + 544) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid); + let OptionCid{ tag:tag37, cid:cid37, } = option_cid; + *((ptr0 + 548) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag37)) as u8; + *((ptr0 + 552) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid37); + let OptionFd{ tag:tag38, fd:fd38, } = option_fd; + *((ptr0 + 556) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag38)) as u8; + *((ptr0 + 560) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd38); + let BusHandles{ bid:bid39, stdin:stdin39, stdout:stdout39, stderr:stderr39, } = bus_handles; + *((ptr0 + 564) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid39); + let OptionFd{ tag:tag40, fd:fd40, } = stdin39; + *((ptr0 + 568) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag40)) as u8; + *((ptr0 + 572) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd40); + let OptionFd{ tag:tag41, fd:fd41, } = stdout39; + *((ptr0 + 576) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag41)) as u8; + *((ptr0 + 580) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd41); + let OptionFd{ tag:tag42, fd:fd42, } = stderr39; + *((ptr0 + 584) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag42)) as u8; + *((ptr0 + 588) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd42); + *((ptr0 + 592) as *mut i32) = wit_bindgen_rust::rt::as_i32(exit_code); + let BusEventExit{ bid:bid43, rval:rval43, } = bus_event_exit; + *((ptr0 + 596) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid43); + *((ptr0 + 600) as *mut i32) = wit_bindgen_rust::rt::as_i32(rval43); + let BusEventFault{ cid:cid44, err:err44, } = bus_event_fault; + *((ptr0 + 604) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid44); + *((ptr0 + 608) as *mut u8) = (match err44 { + BusErrno::Success => 0, + BusErrno::Ser => 1, + BusErrno::Des => 2, + BusErrno::Wapm => 3, + BusErrno::Fetch => 4, + BusErrno::Compile => 5, + BusErrno::Abi => 6, + BusErrno::Aborted => 7, + BusErrno::Badhandle => 8, + BusErrno::Topic => 9, + BusErrno::Badcb => 10, + BusErrno::Unsupported => 11, + BusErrno::Badrequest => 12, + BusErrno::Denied => 13, + BusErrno::Internal => 14, + BusErrno::Alloc => 15, + BusErrno::Invoke => 16, + BusErrno::Consumed => 17, + BusErrno::Memviolation => 18, + BusErrno::Unknown => 19, + }) as u8; + let BusEventClose{ cid:cid45, } = bus_event_close; + *((ptr0 + 612) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid45); #[link(wasm_import_module = "output")] extern "C" { #[cfg_attr(target_arch = "wasm32", link_name = "expose-types-dummy-func")] @@ -1947,6 +2075,6 @@ pub mod output { } #[repr(align(8))] - struct RetArea([u8; 536]); - static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 536]); + struct RetArea([u8; 616]); + static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 616]); } diff --git a/lib/wasi-types-generated/src/wasi/extra.rs b/lib/wasi-types-generated/src/wasi/extra.rs index 3b9be3cd1fd..ba12812d78a 100644 --- a/lib/wasi-types-generated/src/wasi/extra.rs +++ b/lib/wasi-types-generated/src/wasi/extra.rs @@ -1,541 +1,548 @@ + use std::mem::MaybeUninit; use wasmer::ValueType; -/// 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() - } - } - } + + + /// 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() } -/// 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(), - } - } +Snapshot0Clockid::Monotonic => { + f.debug_tuple("Snapshot0Clockid::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.", - } - } +Snapshot0Clockid::ProcessCputimeId => { + f.debug_tuple("Snapshot0Clockid::ProcessCputimeId").finish() } -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() - } +Snapshot0Clockid::ThreadCputimeId => { + f.debug_tuple("Snapshot0Clockid::ThreadCputimeId").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." - } - } - } + } + /// 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() } -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() - } +Clockid::Monotonic => { + f.debug_tuple("Clockid::Monotonic").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! { + } + /// 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`. @@ -543,7 +550,7 @@ pub struct Rights: u64 { /// 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; @@ -624,127 +631,145 @@ pub struct Rights: u64 { 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 } - } + 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(), - } - } + } + /// 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() } -/// 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() - } +Filetype::BlockDevice => { + f.debug_tuple("Filetype::BlockDevice").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() - } +Filetype::CharacterDevice => { + f.debug_tuple("Filetype::CharacterDevice").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(), - } - } +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() } -wit_bindgen_rust::bitflags::bitflags! { +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. @@ -761,38 +786,32 @@ pub struct Fdflags: u8 { 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() - } + impl Fdflags { +/// 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! { + } + /// 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. pub struct Fstflags: u8 { /// Adjust the last data access timestamp to the value stored in `filestat::atim`. @@ -805,28 +824,28 @@ pub struct Fstflags: u8 { 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 } - } + 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! { + } + wit_bindgen_rust::bitflags::bitflags! { /// Flags determining the method of how paths are resolved. 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 } - } + 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! { + } + wit_bindgen_rust::bitflags::bitflags! { /// Open flags used by `path_open`. pub struct Oflags: u8 { /// Create file if it does not exist. @@ -839,40 +858,46 @@ pub struct Oflags: u8 { 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 } - } + 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(), - } - } + } + /// 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! { + } +} + } + wit_bindgen_rust::bitflags::bitflags! { /// Flags determining how to interpret the timestamp provided in /// `subscription-clock::timeout`. pub struct Subclockflags: u8 { @@ -884,79 +909,68 @@ pub struct Subclockflags: u8 { 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() - } + 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 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() - } + } + /// 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() } -/// 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! { + } + 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 { @@ -964,1052 +978,1118 @@ pub struct Eventrwflags: u8 { 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 } - } + 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() - } + } + /// 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() } -/// 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() - } +EventEnum::FdWrite(e) => { + f.debug_tuple("EventEnum::FdWrite").field(e).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(), - } - } +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(), - } - } + } + /// 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() } -/// 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() - } - } - } +Snapshot0SubscriptionEnum::Read(e) => { + f.debug_tuple("Snapshot0SubscriptionEnum::Read").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() - } +Snapshot0SubscriptionEnum::Write(e) => { + f.debug_tuple("Snapshot0SubscriptionEnum::Write").field(e).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() - } + } + /// 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() } -#[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(), - } - } +SubscriptionEnum::Read(e) => { + f.debug_tuple("SubscriptionEnum::Read").field(e).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(), - } - } +SubscriptionEnum::Write(e) => { + f.debug_tuple("SubscriptionEnum::Write").field(e).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() - } - } - } + } + /// 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() } -#[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(), - } - } +Socktype::Stream => { + f.debug_tuple("Socktype::Stream").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() - } +Socktype::Raw => { + f.debug_tuple("Socktype::Raw").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() - } +Socktype::Seqpacket => { + f.debug_tuple("Socktype::Seqpacket").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(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() } -#[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() - } +Sockstatus::Opened => { + f.debug_tuple("Sockstatus::Opened").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(), - } - } +Sockstatus::Closed => { + f.debug_tuple("Sockstatus::Closed").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(), - } - } +Sockstatus::Failed => { + f.debug_tuple("Sockstatus::Failed").finish() } -/// Dummy function to expose types into generated code -pub fn expose_types_dummy_func( - fd: Fd, - dirent: Dirent, - snapshot0_dirent: Snapshot0Dirent, - snapshot0_event: Snapshot0Event, - event_enum: EventEnum, - event: Event, - fdstat: Fdstat, - subscription_clock: SubscriptionClock, - snapshot0_subscription_clock: Snapshot0SubscriptionClock, - subscription: Subscription, - snapshot0_subscription: Snapshot0Subscription, - device: Device, - linkcount: Linkcount, - snapshot0_linkcount: Snapshot0Linkcount, - filestat: Filestat, - snapshot0_filestat: Snapshot0Filestat, - tty: Tty, - tid: Tid, - pid: Pid, - bus_data_format: BusDataFormat, -) -> () { - unsafe { - let ptr0 = OUTPUT_RET_AREA.0.as_mut_ptr() as i32; - *((ptr0 + 0) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd); - let Dirent { - d_next: d_next1, - d_ino: d_ino1, - d_type: d_type1, - d_namlen: d_namlen1, - } = dirent; - *((ptr0 + 8) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_next1); - *((ptr0 + 16) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_ino1); - *((ptr0 + 24) as *mut u8) = (match d_type1 { - Filetype::Unknown => 0, - Filetype::BlockDevice => 1, - Filetype::CharacterDevice => 2, - Filetype::Directory => 3, - Filetype::RegularFile => 4, - Filetype::SocketDgram => 5, - Filetype::SocketStream => 6, - Filetype::SymbolicLink => 7, - Filetype::Fifo => 8, - }) as u8; - *((ptr0 + 28) as *mut i32) = wit_bindgen_rust::rt::as_i32(d_namlen1); - let Snapshot0Dirent { - d_next: d_next2, - d_ino: d_ino2, - d_namlen: d_namlen2, - d_type: d_type2, - } = snapshot0_dirent; - *((ptr0 + 32) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_next2); - *((ptr0 + 40) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_ino2); - *((ptr0 + 48) as *mut i32) = wit_bindgen_rust::rt::as_i32(d_namlen2); - *((ptr0 + 52) as *mut u8) = (match d_type2 { - Filetype::Unknown => 0, - Filetype::BlockDevice => 1, - Filetype::CharacterDevice => 2, - Filetype::Directory => 3, - Filetype::RegularFile => 4, - Filetype::SocketDgram => 5, - Filetype::SocketStream => 6, - Filetype::SymbolicLink => 7, - Filetype::Fifo => 8, - }) as u8; - let Snapshot0Event { - userdata: userdata3, - error: error3, - type_: type_3, - fd_readwrite: fd_readwrite3, - } = snapshot0_event; - *((ptr0 + 56) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata3); - *((ptr0 + 64) as *mut u8) = (match error3 { - Errno::Success => 0, - Errno::Toobig => 1, - Errno::Access => 2, - Errno::Addrinuse => 3, - Errno::Addrnotavail => 4, - Errno::Afnosupport => 5, - Errno::Again => 6, - Errno::Already => 7, - Errno::Badf => 8, - Errno::Badmsg => 9, - Errno::Busy => 10, - Errno::Canceled => 11, - Errno::Child => 12, - Errno::Connaborted => 13, - Errno::Connrefused => 14, - Errno::Connreset => 15, - Errno::Deadlk => 16, - Errno::Destaddrreq => 17, - Errno::Dom => 18, - Errno::Dquot => 19, - Errno::Exist => 20, - Errno::Fault => 21, - Errno::Fbig => 22, - Errno::Hostunreach => 23, - Errno::Idrm => 24, - Errno::Ilseq => 25, - Errno::Inprogress => 26, - Errno::Intr => 27, - Errno::Inval => 28, - Errno::Io => 29, - Errno::Isconn => 30, - Errno::Isdir => 31, - Errno::Loop => 32, - Errno::Mfile => 33, - Errno::Mlink => 34, - Errno::Msgsize => 35, - Errno::Multihop => 36, - Errno::Nametoolong => 37, - Errno::Netdown => 38, - Errno::Netreset => 39, - Errno::Netunreach => 40, - Errno::Nfile => 41, - Errno::Nobufs => 42, - Errno::Nodev => 43, - Errno::Noent => 44, - Errno::Noexec => 45, - Errno::Nolck => 46, - Errno::Nolink => 47, - Errno::Nomem => 48, - Errno::Nomsg => 49, - Errno::Noprotoopt => 50, - Errno::Nospc => 51, - Errno::Nosys => 52, - Errno::Notconn => 53, - Errno::Notdir => 54, - Errno::Notempty => 55, - Errno::Notrecoverable => 56, - Errno::Notsock => 57, - Errno::Notsup => 58, - Errno::Notty => 59, - Errno::Nxio => 60, - Errno::Overflow => 61, - Errno::Ownerdead => 62, - Errno::Perm => 63, - Errno::Pipe => 64, - Errno::Proto => 65, - Errno::Protonosupport => 66, - Errno::Prototype => 67, - Errno::Range => 68, - Errno::Rofs => 69, - Errno::Spipe => 70, - Errno::Srch => 71, - Errno::Stale => 72, - Errno::Timedout => 73, - Errno::Txtbsy => 74, - Errno::Xdev => 75, - Errno::Notcapable => 76, - }) as u8; - *((ptr0 + 65) as *mut u8) = (match type_3 { - Eventtype::Clock => 0, - Eventtype::FdRead => 1, - Eventtype::FdWrite => 2, - }) as u8; - let EventFdReadwrite { - nbytes: nbytes4, - flags: flags4, - } = fd_readwrite3; - *((ptr0 + 72) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes4); - let flags5 = flags4; - *((ptr0 + 80) as *mut u8) = ((flags5.bits() >> 0) as i32) as u8; - match event_enum { - EventEnum::FdRead(e) => { - *((ptr0 + 88) as *mut u8) = (0i32) as u8; - let EventFdReadwrite { - nbytes: nbytes6, - flags: flags6, - } = e; - *((ptr0 + 96) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes6); - let flags7 = flags6; - *((ptr0 + 104) as *mut u8) = ((flags7.bits() >> 0) as i32) as u8; - } - EventEnum::FdWrite(e) => { - *((ptr0 + 88) as *mut u8) = (1i32) as u8; - let EventFdReadwrite { - nbytes: nbytes8, - flags: flags8, - } = e; - *((ptr0 + 96) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes8); - let flags9 = flags8; - *((ptr0 + 104) as *mut u8) = ((flags9.bits() >> 0) as i32) as u8; - } - EventEnum::Clock => { - let e = (); - { - *((ptr0 + 88) as *mut u8) = (2i32) as u8; - let () = e; - } - } - }; - let Event { - userdata: userdata10, - error: error10, - data: data10, - } = event; - *((ptr0 + 112) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata10); - *((ptr0 + 120) as *mut u8) = (match error10 { - Errno::Success => 0, - Errno::Toobig => 1, - Errno::Access => 2, - Errno::Addrinuse => 3, - Errno::Addrnotavail => 4, - Errno::Afnosupport => 5, - Errno::Again => 6, - Errno::Already => 7, - Errno::Badf => 8, - Errno::Badmsg => 9, - Errno::Busy => 10, - Errno::Canceled => 11, - Errno::Child => 12, - Errno::Connaborted => 13, - Errno::Connrefused => 14, - Errno::Connreset => 15, - Errno::Deadlk => 16, - Errno::Destaddrreq => 17, - Errno::Dom => 18, - Errno::Dquot => 19, - Errno::Exist => 20, - Errno::Fault => 21, - Errno::Fbig => 22, - Errno::Hostunreach => 23, - Errno::Idrm => 24, - Errno::Ilseq => 25, - Errno::Inprogress => 26, - Errno::Intr => 27, - Errno::Inval => 28, - Errno::Io => 29, - Errno::Isconn => 30, - Errno::Isdir => 31, - Errno::Loop => 32, - Errno::Mfile => 33, - Errno::Mlink => 34, - Errno::Msgsize => 35, - Errno::Multihop => 36, - Errno::Nametoolong => 37, - Errno::Netdown => 38, - Errno::Netreset => 39, - Errno::Netunreach => 40, - Errno::Nfile => 41, - Errno::Nobufs => 42, - Errno::Nodev => 43, - Errno::Noent => 44, - Errno::Noexec => 45, - Errno::Nolck => 46, - Errno::Nolink => 47, - Errno::Nomem => 48, - Errno::Nomsg => 49, - Errno::Noprotoopt => 50, - Errno::Nospc => 51, - Errno::Nosys => 52, - Errno::Notconn => 53, - Errno::Notdir => 54, - Errno::Notempty => 55, - Errno::Notrecoverable => 56, - Errno::Notsock => 57, - Errno::Notsup => 58, - Errno::Notty => 59, - Errno::Nxio => 60, - Errno::Overflow => 61, - Errno::Ownerdead => 62, - Errno::Perm => 63, - Errno::Pipe => 64, - Errno::Proto => 65, - Errno::Protonosupport => 66, - Errno::Prototype => 67, - Errno::Range => 68, - Errno::Rofs => 69, - Errno::Spipe => 70, - Errno::Srch => 71, - Errno::Stale => 72, - Errno::Timedout => 73, - Errno::Txtbsy => 74, - Errno::Xdev => 75, - Errno::Notcapable => 76, - }) as u8; - match data10 { - EventEnum::FdRead(e) => { - *((ptr0 + 128) as *mut u8) = (0i32) as u8; - let EventFdReadwrite { - nbytes: nbytes11, - flags: flags11, - } = e; - *((ptr0 + 136) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes11); - let flags12 = flags11; - *((ptr0 + 144) as *mut u8) = ((flags12.bits() >> 0) as i32) as u8; - } - EventEnum::FdWrite(e) => { - *((ptr0 + 128) as *mut u8) = (1i32) as u8; - let EventFdReadwrite { - nbytes: nbytes13, - flags: flags13, - } = e; - *((ptr0 + 136) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes13); - let flags14 = flags13; - *((ptr0 + 144) as *mut u8) = ((flags14.bits() >> 0) as i32) as u8; - } - EventEnum::Clock => { - let e = (); - { - *((ptr0 + 128) as *mut u8) = (2i32) as u8; - let () = e; - } - } - }; - let Fdstat { - fs_filetype: fs_filetype15, - fs_flags: fs_flags15, - fs_rights_base: fs_rights_base15, - fs_rights_inheriting: fs_rights_inheriting15, - } = fdstat; - *((ptr0 + 152) as *mut u8) = (match fs_filetype15 { - Filetype::Unknown => 0, - Filetype::BlockDevice => 1, - Filetype::CharacterDevice => 2, - Filetype::Directory => 3, - Filetype::RegularFile => 4, - Filetype::SocketDgram => 5, - Filetype::SocketStream => 6, - Filetype::SymbolicLink => 7, - Filetype::Fifo => 8, - }) as u8; - let flags16 = fs_flags15; - *((ptr0 + 153) as *mut u8) = ((flags16.bits() >> 0) as i32) as u8; - let flags17 = fs_rights_base15; - *((ptr0 + 160) as *mut i32) = (flags17.bits() >> 32) as i32; - *((ptr0 + 156) as *mut i32) = (flags17.bits() >> 0) as i32; - let flags18 = fs_rights_inheriting15; - *((ptr0 + 168) as *mut i32) = (flags18.bits() >> 32) as i32; - *((ptr0 + 164) as *mut i32) = (flags18.bits() >> 0) as i32; - let SubscriptionClock { - clock_id: clock_id19, - timeout: timeout19, - precision: precision19, - flags: flags19, - } = subscription_clock; - *((ptr0 + 176) as *mut u8) = (match clock_id19 { - Clockid::Realtime => 0, - Clockid::Monotonic => 1, - }) as u8; - *((ptr0 + 184) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout19); - *((ptr0 + 192) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision19); - let flags20 = flags19; - *((ptr0 + 200) as *mut u8) = ((flags20.bits() >> 0) as i32) as u8; - let Snapshot0SubscriptionClock { - identifier: identifier21, - id: id21, - timeout: timeout21, - precision: precision21, - flags: flags21, - } = snapshot0_subscription_clock; - *((ptr0 + 208) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier21); - *((ptr0 + 216) as *mut u8) = (match id21 { - Snapshot0Clockid::Realtime => 0, - Snapshot0Clockid::Monotonic => 1, - Snapshot0Clockid::ProcessCputimeId => 2, - Snapshot0Clockid::ThreadCputimeId => 3, - }) as u8; - *((ptr0 + 224) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout21); - *((ptr0 + 232) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision21); - let flags22 = flags21; - *((ptr0 + 240) as *mut u8) = ((flags22.bits() >> 0) as i32) as u8; - let Subscription { - userdata: userdata23, - data: data23, - } = subscription; - *((ptr0 + 248) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata23); - match data23 { - SubscriptionEnum::Clock(e) => { - *((ptr0 + 256) as *mut u8) = (0i32) as u8; - let SubscriptionClock { - clock_id: clock_id24, - timeout: timeout24, - precision: precision24, - flags: flags24, - } = e; - *((ptr0 + 264) as *mut u8) = (match clock_id24 { - Clockid::Realtime => 0, - Clockid::Monotonic => 1, - }) as u8; - *((ptr0 + 272) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout24); - *((ptr0 + 280) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision24); - let flags25 = flags24; - *((ptr0 + 288) as *mut u8) = ((flags25.bits() >> 0) as i32) as u8; - } - SubscriptionEnum::Read(e) => { - *((ptr0 + 256) as *mut u8) = (1i32) as u8; - let SubscriptionFsReadwrite { - file_descriptor: file_descriptor26, - } = e; - *((ptr0 + 264) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor26); - } - SubscriptionEnum::Write(e) => { - *((ptr0 + 256) as *mut u8) = (2i32) as u8; - let SubscriptionFsReadwrite { - file_descriptor: file_descriptor27, - } = e; - *((ptr0 + 264) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor27); - } - }; - let Snapshot0Subscription { - userdata: userdata28, - data: data28, - } = snapshot0_subscription; - *((ptr0 + 296) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata28); - match data28 { - Snapshot0SubscriptionEnum::Clock(e) => { - *((ptr0 + 304) as *mut u8) = (0i32) as u8; - let Snapshot0SubscriptionClock { - identifier: identifier29, - id: id29, - timeout: timeout29, - precision: precision29, - flags: flags29, - } = e; - *((ptr0 + 312) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier29); - *((ptr0 + 320) as *mut u8) = (match id29 { - Snapshot0Clockid::Realtime => 0, - Snapshot0Clockid::Monotonic => 1, - Snapshot0Clockid::ProcessCputimeId => 2, - Snapshot0Clockid::ThreadCputimeId => 3, - }) as u8; - *((ptr0 + 328) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout29); - *((ptr0 + 336) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision29); - let flags30 = flags29; - *((ptr0 + 344) as *mut u8) = ((flags30.bits() >> 0) as i32) as u8; - } - Snapshot0SubscriptionEnum::Read(e) => { - *((ptr0 + 304) as *mut u8) = (1i32) as u8; - let SubscriptionFsReadwrite { - file_descriptor: file_descriptor31, - } = e; - *((ptr0 + 312) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor31); - } - Snapshot0SubscriptionEnum::Write(e) => { - *((ptr0 + 304) as *mut u8) = (2i32) as u8; - let SubscriptionFsReadwrite { - file_descriptor: file_descriptor32, - } = e; - *((ptr0 + 312) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor32); - } - }; - *((ptr0 + 352) as *mut i64) = wit_bindgen_rust::rt::as_i64(device); - *((ptr0 + 360) as *mut i64) = wit_bindgen_rust::rt::as_i64(linkcount); - *((ptr0 + 368) as *mut i32) = wit_bindgen_rust::rt::as_i32(snapshot0_linkcount); - let Filestat { - st_dev: st_dev33, - st_ino: st_ino33, - st_filetype: st_filetype33, - st_nlink: st_nlink33, - st_size: st_size33, - st_atim: st_atim33, - st_mtim: st_mtim33, - st_ctim: st_ctim33, - } = filestat; - *((ptr0 + 376) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev33); - *((ptr0 + 384) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino33); - *((ptr0 + 392) as *mut u8) = (match st_filetype33 { - Filetype::Unknown => 0, - Filetype::BlockDevice => 1, - Filetype::CharacterDevice => 2, - Filetype::Directory => 3, - Filetype::RegularFile => 4, - Filetype::SocketDgram => 5, - Filetype::SocketStream => 6, - Filetype::SymbolicLink => 7, - Filetype::Fifo => 8, - }) as u8; - *((ptr0 + 400) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_nlink33); - *((ptr0 + 408) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size33); - *((ptr0 + 416) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim33); - *((ptr0 + 424) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim33); - *((ptr0 + 432) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim33); - let Snapshot0Filestat { - st_dev: st_dev34, - st_ino: st_ino34, - st_filetype: st_filetype34, - st_nlink: st_nlink34, - st_size: st_size34, - st_atim: st_atim34, - st_mtim: st_mtim34, - st_ctim: st_ctim34, - } = snapshot0_filestat; - *((ptr0 + 440) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev34); - *((ptr0 + 448) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino34); - *((ptr0 + 456) as *mut u8) = (match st_filetype34 { - Filetype::Unknown => 0, - Filetype::BlockDevice => 1, - Filetype::CharacterDevice => 2, - Filetype::Directory => 3, - Filetype::RegularFile => 4, - Filetype::SocketDgram => 5, - Filetype::SocketStream => 6, - Filetype::SymbolicLink => 7, - Filetype::Fifo => 8, - }) as u8; - *((ptr0 + 460) as *mut i32) = wit_bindgen_rust::rt::as_i32(st_nlink34); - *((ptr0 + 464) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size34); - *((ptr0 + 472) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim34); - *((ptr0 + 480) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim34); - *((ptr0 + 488) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim34); - let Tty { - cols: cols35, - rows: rows35, - width: width35, - height: height35, - stdin_tty: stdin_tty35, - stdout_tty: stdout_tty35, - stderr_tty: stderr_tty35, - echo: echo35, - line_buffered: line_buffered35, - } = tty; - *((ptr0 + 496) as *mut i32) = wit_bindgen_rust::rt::as_i32(cols35); - *((ptr0 + 500) as *mut i32) = wit_bindgen_rust::rt::as_i32(rows35); - *((ptr0 + 504) as *mut i32) = wit_bindgen_rust::rt::as_i32(width35); - *((ptr0 + 508) as *mut i32) = wit_bindgen_rust::rt::as_i32(height35); - *((ptr0 + 512) as *mut u8) = (match stdin_tty35 { - true => 1, - false => 0, - }) as u8; - *((ptr0 + 513) as *mut u8) = (match stdout_tty35 { - true => 1, - false => 0, - }) as u8; - *((ptr0 + 514) as *mut u8) = (match stderr_tty35 { - true => 1, - false => 0, - }) as u8; - *((ptr0 + 515) as *mut u8) = (match echo35 { - true => 1, - false => 0, - }) as u8; - *((ptr0 + 516) as *mut u8) = (match line_buffered35 { - true => 1, - false => 0, - }) as u8; - *((ptr0 + 520) as *mut i32) = wit_bindgen_rust::rt::as_i32(tid); - *((ptr0 + 524) as *mut i32) = wit_bindgen_rust::rt::as_i32(pid); - *((ptr0 + 528) as *mut u8) = (match bus_data_format { - BusDataFormat::Raw => 0, - BusDataFormat::Bincode => 1, - BusDataFormat::MessagePack => 2, - BusDataFormat::Json => 3, - BusDataFormat::Yaml => 4, - BusDataFormat::Xml => 5, - BusDataFormat::Rkyv => 6, - }) as u8; - #[link(wasm_import_module = "output")] - extern "C" { - #[cfg_attr(target_arch = "wasm32", link_name = "expose-types-dummy-func")] - #[cfg_attr( - not(target_arch = "wasm32"), - link_name = "output_expose-types-dummy-func" - )] - fn wit_import(_: i32); - } - wit_import(ptr0); - () - } + } +} + } + #[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 + pub type OptionTag = u8; + #[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()} + } + /// Dummy function to expose types into generated code + pub fn expose_types_dummy_func(fd: Fd,dirent: Dirent,snapshot0_dirent: Snapshot0Dirent,snapshot0_event: Snapshot0Event,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,tid: Tid,pid: Pid,bus_data_format: BusDataFormat,bid: Bid,option_bid: OptionBid,cid: Cid,option_cid: OptionCid,option_fd: OptionFd,bus_handles: BusHandles,exit_code: ExitCode,bus_event_exit: BusEventExit,bus_event_fault: BusEventFault,bus_event_close: BusEventClose,) -> (){ +unsafe { + let ptr0 = OUTPUT_RET_AREA.0.as_mut_ptr() as i32; + *((ptr0 + 0) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd); + let Dirent{ d_next:d_next1, d_ino:d_ino1, d_type:d_type1, d_namlen:d_namlen1, } = dirent; + *((ptr0 + 8) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_next1); + *((ptr0 + 16) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_ino1); + *((ptr0 + 24) as *mut u8) = (match d_type1 { +Filetype::Unknown => 0, +Filetype::BlockDevice => 1, +Filetype::CharacterDevice => 2, +Filetype::Directory => 3, +Filetype::RegularFile => 4, +Filetype::SocketDgram => 5, +Filetype::SocketStream => 6, +Filetype::SymbolicLink => 7, +Filetype::Fifo => 8, + }) as u8; + *((ptr0 + 28) as *mut i32) = wit_bindgen_rust::rt::as_i32(d_namlen1); + let Snapshot0Dirent{ d_next:d_next2, d_ino:d_ino2, d_namlen:d_namlen2, d_type:d_type2, } = snapshot0_dirent; + *((ptr0 + 32) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_next2); + *((ptr0 + 40) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_ino2); + *((ptr0 + 48) as *mut i32) = wit_bindgen_rust::rt::as_i32(d_namlen2); + *((ptr0 + 52) as *mut u8) = (match d_type2 { +Filetype::Unknown => 0, +Filetype::BlockDevice => 1, +Filetype::CharacterDevice => 2, +Filetype::Directory => 3, +Filetype::RegularFile => 4, +Filetype::SocketDgram => 5, +Filetype::SocketStream => 6, +Filetype::SymbolicLink => 7, +Filetype::Fifo => 8, + }) as u8; + let Snapshot0Event{ userdata:userdata3, error:error3, type_:type_3, fd_readwrite:fd_readwrite3, } = snapshot0_event; + *((ptr0 + 56) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata3); + *((ptr0 + 64) as *mut u8) = (match error3 { +Errno::Success => 0, +Errno::Toobig => 1, +Errno::Access => 2, +Errno::Addrinuse => 3, +Errno::Addrnotavail => 4, +Errno::Afnosupport => 5, +Errno::Again => 6, +Errno::Already => 7, +Errno::Badf => 8, +Errno::Badmsg => 9, +Errno::Busy => 10, +Errno::Canceled => 11, +Errno::Child => 12, +Errno::Connaborted => 13, +Errno::Connrefused => 14, +Errno::Connreset => 15, +Errno::Deadlk => 16, +Errno::Destaddrreq => 17, +Errno::Dom => 18, +Errno::Dquot => 19, +Errno::Exist => 20, +Errno::Fault => 21, +Errno::Fbig => 22, +Errno::Hostunreach => 23, +Errno::Idrm => 24, +Errno::Ilseq => 25, +Errno::Inprogress => 26, +Errno::Intr => 27, +Errno::Inval => 28, +Errno::Io => 29, +Errno::Isconn => 30, +Errno::Isdir => 31, +Errno::Loop => 32, +Errno::Mfile => 33, +Errno::Mlink => 34, +Errno::Msgsize => 35, +Errno::Multihop => 36, +Errno::Nametoolong => 37, +Errno::Netdown => 38, +Errno::Netreset => 39, +Errno::Netunreach => 40, +Errno::Nfile => 41, +Errno::Nobufs => 42, +Errno::Nodev => 43, +Errno::Noent => 44, +Errno::Noexec => 45, +Errno::Nolck => 46, +Errno::Nolink => 47, +Errno::Nomem => 48, +Errno::Nomsg => 49, +Errno::Noprotoopt => 50, +Errno::Nospc => 51, +Errno::Nosys => 52, +Errno::Notconn => 53, +Errno::Notdir => 54, +Errno::Notempty => 55, +Errno::Notrecoverable => 56, +Errno::Notsock => 57, +Errno::Notsup => 58, +Errno::Notty => 59, +Errno::Nxio => 60, +Errno::Overflow => 61, +Errno::Ownerdead => 62, +Errno::Perm => 63, +Errno::Pipe => 64, +Errno::Proto => 65, +Errno::Protonosupport => 66, +Errno::Prototype => 67, +Errno::Range => 68, +Errno::Rofs => 69, +Errno::Spipe => 70, +Errno::Srch => 71, +Errno::Stale => 72, +Errno::Timedout => 73, +Errno::Txtbsy => 74, +Errno::Xdev => 75, +Errno::Notcapable => 76, + }) as u8; + *((ptr0 + 65) as *mut u8) = (match type_3 { +Eventtype::Clock => 0, +Eventtype::FdRead => 1, +Eventtype::FdWrite => 2, + }) as u8; + let EventFdReadwrite{ nbytes:nbytes4, flags:flags4, } = fd_readwrite3; + *((ptr0 + 72) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes4); + let flags5 = flags4; + *((ptr0 + 80) as *mut u8) = ((flags5.bits() >> 0) as i32) as u8; + match event_enum { +EventEnum::FdRead(e) => { + *((ptr0 + 88) as *mut u8) = (0i32) as u8; + let EventFdReadwrite{ nbytes:nbytes6, flags:flags6, } = e; + *((ptr0 + 96) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes6); + let flags7 = flags6; + *((ptr0 + 104) as *mut u8) = ((flags7.bits() >> 0) as i32) as u8; + +}, +EventEnum::FdWrite(e) => { + *((ptr0 + 88) as *mut u8) = (1i32) as u8; + let EventFdReadwrite{ nbytes:nbytes8, flags:flags8, } = e; + *((ptr0 + 96) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes8); + let flags9 = flags8; + *((ptr0 + 104) as *mut u8) = ((flags9.bits() >> 0) as i32) as u8; + +}, +EventEnum::Clock=> { + let e = (); + { +*((ptr0 + 88) as *mut u8) = (2i32) as u8; +let () = e; -#[repr(align(8))] -struct RetArea([u8; 536]); -static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 536]); + } +} + }; + let Event{ userdata:userdata10, error:error10, data:data10, } = event; + *((ptr0 + 112) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata10); + *((ptr0 + 120) as *mut u8) = (match error10 { +Errno::Success => 0, +Errno::Toobig => 1, +Errno::Access => 2, +Errno::Addrinuse => 3, +Errno::Addrnotavail => 4, +Errno::Afnosupport => 5, +Errno::Again => 6, +Errno::Already => 7, +Errno::Badf => 8, +Errno::Badmsg => 9, +Errno::Busy => 10, +Errno::Canceled => 11, +Errno::Child => 12, +Errno::Connaborted => 13, +Errno::Connrefused => 14, +Errno::Connreset => 15, +Errno::Deadlk => 16, +Errno::Destaddrreq => 17, +Errno::Dom => 18, +Errno::Dquot => 19, +Errno::Exist => 20, +Errno::Fault => 21, +Errno::Fbig => 22, +Errno::Hostunreach => 23, +Errno::Idrm => 24, +Errno::Ilseq => 25, +Errno::Inprogress => 26, +Errno::Intr => 27, +Errno::Inval => 28, +Errno::Io => 29, +Errno::Isconn => 30, +Errno::Isdir => 31, +Errno::Loop => 32, +Errno::Mfile => 33, +Errno::Mlink => 34, +Errno::Msgsize => 35, +Errno::Multihop => 36, +Errno::Nametoolong => 37, +Errno::Netdown => 38, +Errno::Netreset => 39, +Errno::Netunreach => 40, +Errno::Nfile => 41, +Errno::Nobufs => 42, +Errno::Nodev => 43, +Errno::Noent => 44, +Errno::Noexec => 45, +Errno::Nolck => 46, +Errno::Nolink => 47, +Errno::Nomem => 48, +Errno::Nomsg => 49, +Errno::Noprotoopt => 50, +Errno::Nospc => 51, +Errno::Nosys => 52, +Errno::Notconn => 53, +Errno::Notdir => 54, +Errno::Notempty => 55, +Errno::Notrecoverable => 56, +Errno::Notsock => 57, +Errno::Notsup => 58, +Errno::Notty => 59, +Errno::Nxio => 60, +Errno::Overflow => 61, +Errno::Ownerdead => 62, +Errno::Perm => 63, +Errno::Pipe => 64, +Errno::Proto => 65, +Errno::Protonosupport => 66, +Errno::Prototype => 67, +Errno::Range => 68, +Errno::Rofs => 69, +Errno::Spipe => 70, +Errno::Srch => 71, +Errno::Stale => 72, +Errno::Timedout => 73, +Errno::Txtbsy => 74, +Errno::Xdev => 75, +Errno::Notcapable => 76, + }) as u8; + match data10 { +EventEnum::FdRead(e) => { + *((ptr0 + 128) as *mut u8) = (0i32) as u8; + let EventFdReadwrite{ nbytes:nbytes11, flags:flags11, } = e; + *((ptr0 + 136) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes11); + let flags12 = flags11; + *((ptr0 + 144) as *mut u8) = ((flags12.bits() >> 0) as i32) as u8; + +}, +EventEnum::FdWrite(e) => { + *((ptr0 + 128) as *mut u8) = (1i32) as u8; + let EventFdReadwrite{ nbytes:nbytes13, flags:flags13, } = e; + *((ptr0 + 136) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes13); + let flags14 = flags13; + *((ptr0 + 144) as *mut u8) = ((flags14.bits() >> 0) as i32) as u8; + +}, +EventEnum::Clock=> { + let e = (); + { +*((ptr0 + 128) as *mut u8) = (2i32) as u8; +let () = e; + } +} + }; + let Fdstat{ fs_filetype:fs_filetype15, fs_flags:fs_flags15, fs_rights_base:fs_rights_base15, fs_rights_inheriting:fs_rights_inheriting15, } = fdstat; + *((ptr0 + 152) as *mut u8) = (match fs_filetype15 { +Filetype::Unknown => 0, +Filetype::BlockDevice => 1, +Filetype::CharacterDevice => 2, +Filetype::Directory => 3, +Filetype::RegularFile => 4, +Filetype::SocketDgram => 5, +Filetype::SocketStream => 6, +Filetype::SymbolicLink => 7, +Filetype::Fifo => 8, + }) as u8; + let flags16 = fs_flags15; + *((ptr0 + 153) as *mut u8) = ((flags16.bits() >> 0) as i32) as u8; + let flags17 = fs_rights_base15; + *((ptr0 + 160) as *mut i32) = (flags17.bits() >> 32) as i32; + *((ptr0 + 156) as *mut i32) = (flags17.bits() >> 0) as i32; + let flags18 = fs_rights_inheriting15; + *((ptr0 + 168) as *mut i32) = (flags18.bits() >> 32) as i32; + *((ptr0 + 164) as *mut i32) = (flags18.bits() >> 0) as i32; + let SubscriptionClock{ clock_id:clock_id19, timeout:timeout19, precision:precision19, flags:flags19, } = subscription_clock; + *((ptr0 + 176) as *mut u8) = (match clock_id19 { +Clockid::Realtime => 0, +Clockid::Monotonic => 1, + }) as u8; + *((ptr0 + 184) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout19); + *((ptr0 + 192) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision19); + let flags20 = flags19; + *((ptr0 + 200) as *mut u8) = ((flags20.bits() >> 0) as i32) as u8; + let Snapshot0SubscriptionClock{ identifier:identifier21, id:id21, timeout:timeout21, precision:precision21, flags:flags21, } = snapshot0_subscription_clock; + *((ptr0 + 208) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier21); + *((ptr0 + 216) as *mut u8) = (match id21 { +Snapshot0Clockid::Realtime => 0, +Snapshot0Clockid::Monotonic => 1, +Snapshot0Clockid::ProcessCputimeId => 2, +Snapshot0Clockid::ThreadCputimeId => 3, + }) as u8; + *((ptr0 + 224) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout21); + *((ptr0 + 232) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision21); + let flags22 = flags21; + *((ptr0 + 240) as *mut u8) = ((flags22.bits() >> 0) as i32) as u8; + let Subscription{ userdata:userdata23, data:data23, } = subscription; + *((ptr0 + 248) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata23); + match data23 { +SubscriptionEnum::Clock(e) => { + *((ptr0 + 256) as *mut u8) = (0i32) as u8; + let SubscriptionClock{ clock_id:clock_id24, timeout:timeout24, precision:precision24, flags:flags24, } = e; + *((ptr0 + 264) as *mut u8) = (match clock_id24 { +Clockid::Realtime => 0, +Clockid::Monotonic => 1, + }) as u8; + *((ptr0 + 272) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout24); + *((ptr0 + 280) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision24); + let flags25 = flags24; + *((ptr0 + 288) as *mut u8) = ((flags25.bits() >> 0) as i32) as u8; + +}, +SubscriptionEnum::Read(e) => { + *((ptr0 + 256) as *mut u8) = (1i32) as u8; + let SubscriptionFsReadwrite{ file_descriptor:file_descriptor26, } = e; + *((ptr0 + 264) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor26); + +}, +SubscriptionEnum::Write(e) => { + *((ptr0 + 256) as *mut u8) = (2i32) as u8; + let SubscriptionFsReadwrite{ file_descriptor:file_descriptor27, } = e; + *((ptr0 + 264) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor27); + +}, + }; + let Snapshot0Subscription{ userdata:userdata28, data:data28, } = snapshot0_subscription; + *((ptr0 + 296) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata28); + match data28 { +Snapshot0SubscriptionEnum::Clock(e) => { + *((ptr0 + 304) as *mut u8) = (0i32) as u8; + let Snapshot0SubscriptionClock{ identifier:identifier29, id:id29, timeout:timeout29, precision:precision29, flags:flags29, } = e; + *((ptr0 + 312) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier29); + *((ptr0 + 320) as *mut u8) = (match id29 { +Snapshot0Clockid::Realtime => 0, +Snapshot0Clockid::Monotonic => 1, +Snapshot0Clockid::ProcessCputimeId => 2, +Snapshot0Clockid::ThreadCputimeId => 3, + }) as u8; + *((ptr0 + 328) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout29); + *((ptr0 + 336) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision29); + let flags30 = flags29; + *((ptr0 + 344) as *mut u8) = ((flags30.bits() >> 0) as i32) as u8; + +}, +Snapshot0SubscriptionEnum::Read(e) => { + *((ptr0 + 304) as *mut u8) = (1i32) as u8; + let SubscriptionFsReadwrite{ file_descriptor:file_descriptor31, } = e; + *((ptr0 + 312) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor31); + +}, +Snapshot0SubscriptionEnum::Write(e) => { + *((ptr0 + 304) as *mut u8) = (2i32) as u8; + let SubscriptionFsReadwrite{ file_descriptor:file_descriptor32, } = e; + *((ptr0 + 312) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor32); + +}, + }; + *((ptr0 + 352) as *mut i64) = wit_bindgen_rust::rt::as_i64(device); + *((ptr0 + 360) as *mut i64) = wit_bindgen_rust::rt::as_i64(linkcount); + *((ptr0 + 368) as *mut i32) = wit_bindgen_rust::rt::as_i32(snapshot0_linkcount); + let Filestat{ st_dev:st_dev33, st_ino:st_ino33, st_filetype:st_filetype33, st_nlink:st_nlink33, st_size:st_size33, st_atim:st_atim33, st_mtim:st_mtim33, st_ctim:st_ctim33, } = filestat; + *((ptr0 + 376) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev33); + *((ptr0 + 384) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino33); + *((ptr0 + 392) as *mut u8) = (match st_filetype33 { +Filetype::Unknown => 0, +Filetype::BlockDevice => 1, +Filetype::CharacterDevice => 2, +Filetype::Directory => 3, +Filetype::RegularFile => 4, +Filetype::SocketDgram => 5, +Filetype::SocketStream => 6, +Filetype::SymbolicLink => 7, +Filetype::Fifo => 8, + }) as u8; + *((ptr0 + 400) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_nlink33); + *((ptr0 + 408) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size33); + *((ptr0 + 416) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim33); + *((ptr0 + 424) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim33); + *((ptr0 + 432) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim33); + let Snapshot0Filestat{ st_dev:st_dev34, st_ino:st_ino34, st_filetype:st_filetype34, st_nlink:st_nlink34, st_size:st_size34, st_atim:st_atim34, st_mtim:st_mtim34, st_ctim:st_ctim34, } = snapshot0_filestat; + *((ptr0 + 440) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev34); + *((ptr0 + 448) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino34); + *((ptr0 + 456) as *mut u8) = (match st_filetype34 { +Filetype::Unknown => 0, +Filetype::BlockDevice => 1, +Filetype::CharacterDevice => 2, +Filetype::Directory => 3, +Filetype::RegularFile => 4, +Filetype::SocketDgram => 5, +Filetype::SocketStream => 6, +Filetype::SymbolicLink => 7, +Filetype::Fifo => 8, + }) as u8; + *((ptr0 + 460) as *mut i32) = wit_bindgen_rust::rt::as_i32(st_nlink34); + *((ptr0 + 464) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size34); + *((ptr0 + 472) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim34); + *((ptr0 + 480) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim34); + *((ptr0 + 488) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim34); + let Tty{ cols:cols35, rows:rows35, width:width35, height:height35, stdin_tty:stdin_tty35, stdout_tty:stdout_tty35, stderr_tty:stderr_tty35, echo:echo35, line_buffered:line_buffered35, } = tty; + *((ptr0 + 496) as *mut i32) = wit_bindgen_rust::rt::as_i32(cols35); + *((ptr0 + 500) as *mut i32) = wit_bindgen_rust::rt::as_i32(rows35); + *((ptr0 + 504) as *mut i32) = wit_bindgen_rust::rt::as_i32(width35); + *((ptr0 + 508) as *mut i32) = wit_bindgen_rust::rt::as_i32(height35); + *((ptr0 + 512) as *mut u8) = (match stdin_tty35 { true => 1, false => 0 }) as u8; + *((ptr0 + 513) as *mut u8) = (match stdout_tty35 { true => 1, false => 0 }) as u8; + *((ptr0 + 514) as *mut u8) = (match stderr_tty35 { true => 1, false => 0 }) as u8; + *((ptr0 + 515) as *mut u8) = (match echo35 { true => 1, false => 0 }) as u8; + *((ptr0 + 516) as *mut u8) = (match line_buffered35 { true => 1, false => 0 }) as u8; + *((ptr0 + 520) as *mut i32) = wit_bindgen_rust::rt::as_i32(tid); + *((ptr0 + 524) as *mut i32) = wit_bindgen_rust::rt::as_i32(pid); + *((ptr0 + 528) as *mut u8) = (match bus_data_format { +BusDataFormat::Raw => 0, +BusDataFormat::Bincode => 1, +BusDataFormat::MessagePack => 2, +BusDataFormat::Json => 3, +BusDataFormat::Yaml => 4, +BusDataFormat::Xml => 5, +BusDataFormat::Rkyv => 6, + }) as u8; + *((ptr0 + 532) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid); + let OptionBid{ tag:tag36, bid:bid36, } = option_bid; + *((ptr0 + 536) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag36)) as u8; + *((ptr0 + 540) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid36); + *((ptr0 + 544) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid); + let OptionCid{ tag:tag37, cid:cid37, } = option_cid; + *((ptr0 + 548) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag37)) as u8; + *((ptr0 + 552) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid37); + let OptionFd{ tag:tag38, fd:fd38, } = option_fd; + *((ptr0 + 556) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag38)) as u8; + *((ptr0 + 560) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd38); + let BusHandles{ bid:bid39, stdin:stdin39, stdout:stdout39, stderr:stderr39, } = bus_handles; + *((ptr0 + 564) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid39); + let OptionFd{ tag:tag40, fd:fd40, } = stdin39; + *((ptr0 + 568) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag40)) as u8; + *((ptr0 + 572) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd40); + let OptionFd{ tag:tag41, fd:fd41, } = stdout39; + *((ptr0 + 576) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag41)) as u8; + *((ptr0 + 580) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd41); + let OptionFd{ tag:tag42, fd:fd42, } = stderr39; + *((ptr0 + 584) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag42)) as u8; + *((ptr0 + 588) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd42); + *((ptr0 + 592) as *mut i32) = wit_bindgen_rust::rt::as_i32(exit_code); + let BusEventExit{ bid:bid43, rval:rval43, } = bus_event_exit; + *((ptr0 + 596) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid43); + *((ptr0 + 600) as *mut i32) = wit_bindgen_rust::rt::as_i32(rval43); + let BusEventFault{ cid:cid44, err:err44, } = bus_event_fault; + *((ptr0 + 604) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid44); + *((ptr0 + 608) as *mut u8) = (match err44 { +BusErrno::Success => 0, +BusErrno::Ser => 1, +BusErrno::Des => 2, +BusErrno::Wapm => 3, +BusErrno::Fetch => 4, +BusErrno::Compile => 5, +BusErrno::Abi => 6, +BusErrno::Aborted => 7, +BusErrno::Badhandle => 8, +BusErrno::Topic => 9, +BusErrno::Badcb => 10, +BusErrno::Unsupported => 11, +BusErrno::Badrequest => 12, +BusErrno::Denied => 13, +BusErrno::Internal => 14, +BusErrno::Alloc => 15, +BusErrno::Invoke => 16, +BusErrno::Consumed => 17, +BusErrno::Memviolation => 18, +BusErrno::Unknown => 19, + }) as u8; + let BusEventClose{ cid:cid45, } = bus_event_close; + *((ptr0 + 612) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid45); + #[link(wasm_import_module = "output")] + extern "C" { +#[cfg_attr(target_arch = "wasm32", link_name = "expose-types-dummy-func")] +#[cfg_attr(not(target_arch = "wasm32"), link_name = "output_expose-types-dummy-func")] +fn wit_import(_: i32, ); + } + wit_import(ptr0); + () +} + } + + #[repr(align(8))] + struct RetArea([u8; 616]); + static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 616]); + + // TODO: if necessary, must be implemented in wit-bindgen unsafe impl ValueType for Snapshot0Clockid { #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) { } } + unsafe impl wasmer::FromToNativeWasmType for Snapshot0Clockid { type Native = i32; @@ -2029,17 +2109,16 @@ unsafe impl wasmer::FromToNativeWasmType for Snapshot0Clockid { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { - false - } + 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]) {} + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) { } } + unsafe impl wasmer::FromToNativeWasmType for Clockid { type Native = i32; @@ -2057,17 +2136,16 @@ unsafe impl wasmer::FromToNativeWasmType for Clockid { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { - false - } + 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]) {} + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) { } } + unsafe impl wasmer::FromToNativeWasmType for Errno { type Native = i32; @@ -2160,17 +2238,16 @@ unsafe impl wasmer::FromToNativeWasmType for Errno { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { - false - } + 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]) {} + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) { } } + unsafe impl wasmer::FromToNativeWasmType for BusErrno { type Native = i32; @@ -2206,23 +2283,23 @@ unsafe impl wasmer::FromToNativeWasmType for BusErrno { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { - false - } + 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]) {} + 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]) {} + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) { } } + unsafe impl wasmer::FromToNativeWasmType for Filetype { type Native = i32; @@ -2247,29 +2324,30 @@ unsafe impl wasmer::FromToNativeWasmType for Filetype { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { - false - } + 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]) {} + 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]) {} + 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]) {} + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) { } } + unsafe impl wasmer::FromToNativeWasmType for Advice { type Native = i32; @@ -2291,47 +2369,51 @@ unsafe impl wasmer::FromToNativeWasmType for Advice { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { - false - } + 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]) {} + 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]) {} + 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]) {} + 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]) {} + 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]) {} + 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]) {} + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) { } } + unsafe impl wasmer::FromToNativeWasmType for Eventtype { type Native = i32; @@ -2350,35 +2432,37 @@ unsafe impl wasmer::FromToNativeWasmType for Eventtype { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { - false - } + 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]) {} + 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]) {} + 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]) {} + 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]) {} + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) { } } + unsafe impl wasmer::FromToNativeWasmType for Preopentype { type Native = i32; @@ -2395,77 +2479,86 @@ unsafe impl wasmer::FromToNativeWasmType for Preopentype { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { - false - } + 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]) {} + 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]) {} + 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]) {} + 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]) {} + 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]) {} + 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]) {} + 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]) {} + 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]) {} + 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]) {} + 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]) {} + 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]) {} + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) { } } + unsafe impl wasmer::FromToNativeWasmType for Socktype { type Native = i32; @@ -2485,17 +2578,16 @@ unsafe impl wasmer::FromToNativeWasmType for Socktype { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { - false - } + 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]) {} + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) { } } + unsafe impl wasmer::FromToNativeWasmType for Sockstatus { type Native = i32; @@ -2515,17 +2607,16 @@ unsafe impl wasmer::FromToNativeWasmType for Sockstatus { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { - false - } + 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]) {} + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) { } } + unsafe impl wasmer::FromToNativeWasmType for Sockoption { type Native = i32; @@ -2568,17 +2659,16 @@ unsafe impl wasmer::FromToNativeWasmType for Sockoption { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { - false - } + 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]) {} + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) { } } + unsafe impl wasmer::FromToNativeWasmType for Streamsecurity { type Native = i32; @@ -2598,17 +2688,16 @@ unsafe impl wasmer::FromToNativeWasmType for Streamsecurity { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { - false - } + 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]) {} + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) { } } + unsafe impl wasmer::FromToNativeWasmType for Addressfamily { type Native = i32; @@ -2628,29 +2717,30 @@ unsafe impl wasmer::FromToNativeWasmType for Addressfamily { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { - false - } + 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]) {} + 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]) {} + 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]) {} + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) { } } + unsafe impl wasmer::FromToNativeWasmType for Snapshot0Whence { type Native = i32; @@ -2669,17 +2759,16 @@ unsafe impl wasmer::FromToNativeWasmType for Snapshot0Whence { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { - false - } + 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]) {} + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) { } } + unsafe impl wasmer::FromToNativeWasmType for Whence { type Native = i32; @@ -2698,23 +2787,23 @@ unsafe impl wasmer::FromToNativeWasmType for Whence { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { - false - } + 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]) {} + 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]) {} + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) { } } + unsafe impl wasmer::FromToNativeWasmType for BusDataFormat { type Native = i32; @@ -2737,17 +2826,16 @@ unsafe impl wasmer::FromToNativeWasmType for BusDataFormat { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { - false - } + 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]) {} + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) { } } + unsafe impl wasmer::FromToNativeWasmType for BusEventType { type Native = i32; @@ -2769,7 +2857,55 @@ unsafe impl wasmer::FromToNativeWasmType for BusEventType { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { - false - } + 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]) { } +} + + \ No newline at end of file diff --git a/lib/wasi-types-generated/src/wasi/extra_manual.rs b/lib/wasi-types-generated/src/wasi/extra_manual.rs index e3cb22b2943..96ed211d7fa 100644 --- a/lib/wasi-types-generated/src/wasi/extra_manual.rs +++ b/lib/wasi-types-generated/src/wasi/extra_manual.rs @@ -234,3 +234,12 @@ unsafe impl wasmer::FromToNativeWasmType for Fstflags { false } } + +impl PartialEq for OptionCid { + fn eq(&self, other: &Self) -> bool { + self.tag == other.tag && + self.cid == other.cid + } +} + +impl Eq for OptionCid { } \ No newline at end of file diff --git a/lib/wasi-types-generated/wit-clean/output.wit b/lib/wasi-types-generated/wit-clean/output.wit index c3febd19fc3..1bac8dd4fb6 100644 --- a/lib/wasi-types-generated/wit-clean/output.wit +++ b/lib/wasi-types-generated/wit-clean/output.wit @@ -26,10 +26,18 @@ expose-types-dummy-func: func( tid: tid, pid: pid, bus-data-format: bus-data-format, + bid: bid, + option-bid: option-bid, + cid: cid, + option-cid: option-cid, + option-fd: option-fd, + bus-handles: bus-handles, + exit-code: exit-code, + bus-event-exit: bus-event-exit, + bus-event-fault: bus-event-fault, + bus-event-close: bus-event-close, ) - - /// Type names used by low-level WASI interfaces. /// An array size. @@ -834,6 +842,51 @@ enum bus-event-type { fault, close, } + +type bid = u32 + +type cid = u32 + +/// __wasi_option_t +type option-tag = u8 + +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, +} // WASI Preview. This is an evolution of the API that WASI initially // launched with. // diff --git a/lib/wasi-types-generated/wit-clean/typenames.wit b/lib/wasi-types-generated/wit-clean/typenames.wit index 4d90f429ac0..a11166bea0c 100644 --- a/lib/wasi-types-generated/wit-clean/typenames.wit +++ b/lib/wasi-types-generated/wit-clean/typenames.wit @@ -26,10 +26,18 @@ expose-types-dummy-func: func( tid: tid, pid: pid, bus-data-format: bus-data-format, + bid: bid, + option-bid: option-bid, + cid: cid, + option-cid: option-cid, + option-fd: option-fd, + bus-handles: bus-handles, + exit-code: exit-code, + bus-event-exit: bus-event-exit, + bus-event-fault: bus-event-fault, + bus-event-close: bus-event-close, ) - - /// Type names used by low-level WASI interfaces. /// An array size. @@ -834,3 +842,48 @@ enum bus-event-type { fault, close, } + +type bid = u32 + +type cid = u32 + +/// __wasi_option_t +type option-tag = u8 + +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, +} diff --git a/lib/wasi-types/src/bus.rs b/lib/wasi-types/src/bus.rs index c6e3ec447b9..86af94d3955 100644 --- a/lib/wasi-types/src/bus.rs +++ b/lib/wasi-types/src/bus.rs @@ -1,54 +1,18 @@ -use super::*; use wasmer_derive::ValueType; use wasmer_types::MemorySize; -use wasmer_wasi_types_generated::wasi::{BusDataFormat, BusErrno, BusEventType, Fd}; +use wasmer_wasi_types_generated::wasi::{ + BusDataFormat, BusEventType, + BusEventExit, BusEventFault, + BusEventClose, Cid, OptionCid, +}; -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: Fd, -} - -#[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, -} +// 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: __wasi_option_cid_t, - pub cid: __wasi_cid_t, + pub parent: OptionCid, + pub cid: Cid, pub format: BusDataFormat, pub topic_ptr: M::Offset, pub topic_len: M::Offset, @@ -56,37 +20,24 @@ pub struct __wasi_busevent_call_t { pub buf_len: M::Offset, } -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_busevent_result_t { - pub format: BusDataFormat, - 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: BusErrno, -} - -#[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 exit: BusEventExit, pub call: __wasi_busevent_call_t, pub result: __wasi_busevent_result_t, - pub fault: __wasi_busevent_fault_t, - pub close: __wasi_busevent_close_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)] diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 80e870a6b78..dd11841854d 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -30,7 +30,7 @@ use self::types::{ EventEnum, EventFdReadwrite, Eventrwflags, Eventtype, Fd as WasiFd, Fdflags, Fdstat, Filesize, Filestat, Filetype, Fstflags, Linkcount, Pid, Rights, Snapshot0Clockid, Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, SubscriptionEnum, - SubscriptionFsReadwrite, Tid, Timestamp, Tty, Whence, + SubscriptionFsReadwrite, Tid, Timestamp, Tty, Whence, Cid, OptionFd, Bid, BusHandles, }, *, }; @@ -3682,7 +3682,7 @@ pub fn process_spawn( stderr: __wasi_stdiomode_t, working_dir: WasmPtr, working_dir_len: M::Offset, - ret_handles: WasmPtr<__wasi_bus_handles_t, M>, + ret_handles: WasmPtr, ) -> BusErrno { let env = ctx.data(); let bus = env.runtime.bus(); @@ -3721,11 +3721,11 @@ 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 { + Some(fd) => OptionFd { tag: __WASI_OPTION_SOME, fd: fd.into(), }, - None => __wasi_option_fd_t { + None => OptionFd { tag: __WASI_OPTION_NONE, fd: 0, }, @@ -3745,7 +3745,7 @@ pub fn process_spawn( bid }; - let handles = __wasi_bus_handles_t { + let handles = BusHandles { bid, stdin, stdout, @@ -3774,7 +3774,7 @@ pub fn bus_open_local( name: WasmPtr, name_len: M::Offset, reuse: __wasi_bool_t, - ret_bid: WasmPtr<__wasi_bid_t, M>, + ret_bid: WasmPtr, ) -> BusErrno { let env = ctx.data(); let bus = env.runtime.bus(); @@ -3809,7 +3809,7 @@ pub fn bus_open_remote( instance_len: M::Offset, token: WasmPtr, token_len: M::Offset, - ret_bid: WasmPtr<__wasi_bid_t, M>, + ret_bid: WasmPtr, ) -> BusErrno { let env = ctx.data(); let bus = env.runtime.bus(); @@ -3832,7 +3832,7 @@ fn bus_open_local_internal( reuse: bool, instance: Option, token: Option, - ret_bid: WasmPtr<__wasi_bid_t, M>, + ret_bid: WasmPtr, ) -> BusErrno { let env = ctx.data(); let bus = env.runtime.bus(); @@ -3889,7 +3889,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) -> BusErrno { +pub fn bus_close(ctx: FunctionEnvMut<'_, WasiEnv>, bid: Bid) -> BusErrno { trace!("wasi::bus_close (bid={})", bid); let bid: WasiBusProcessId = bid.into(); @@ -3913,14 +3913,14 @@ pub fn bus_close(ctx: FunctionEnvMut<'_, WasiEnv>, bid: __wasi_bid_t) -> BusErrn /// * `buf` - The buffer where data to be transmitted is stored pub fn bus_call( ctx: FunctionEnvMut<'_, WasiEnv>, - bid: __wasi_bid_t, + bid: Bid, keep_alive: __wasi_bool_t, topic: WasmPtr, topic_len: M::Offset, format: BusDataFormat, buf: WasmPtr, buf_len: M::Offset, - ret_cid: WasmPtr<__wasi_cid_t, M>, + ret_cid: WasmPtr, ) -> BusErrno { let env = ctx.data(); let bus = env.runtime.bus(); @@ -3950,14 +3950,14 @@ 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, + parent: Cid, keep_alive: __wasi_bool_t, topic: WasmPtr, topic_len: M::Offset, format: BusDataFormat, buf: WasmPtr, buf_len: M::Offset, - ret_cid: WasmPtr<__wasi_cid_t, M>, + ret_cid: WasmPtr, ) -> BusErrno { let env = ctx.data(); let bus = env.runtime.bus(); @@ -4018,7 +4018,7 @@ 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, + cid: Cid, format: BusDataFormat, buf: WasmPtr, buf_len: M::Offset, @@ -4045,7 +4045,7 @@ pub fn call_reply( /// * `fault` - Fault to be raised on the bus pub fn call_fault( ctx: FunctionEnvMut<'_, WasiEnv>, - cid: __wasi_cid_t, + cid: Cid, fault: BusErrno, ) -> BusErrno { let env = ctx.data(); @@ -4060,7 +4060,7 @@ 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) -> BusErrno { +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); diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index 25410236666..bc792b5304f 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -5,7 +5,7 @@ use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ Addressfamily, Advice, BusDataFormat, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Filesize, Filestat, Fstflags, Pid, Rights, Sockoption, Sockstatus, Socktype, - Streamsecurity, Subscription, Tid, Timestamp, Tty, Whence, + Streamsecurity, Subscription, Tid, Timestamp, Tty, Whence, BusHandles, Bid, Cid }; type MemoryType = Memory32; @@ -514,7 +514,7 @@ pub(crate) fn process_spawn( stderr: __wasi_stdiomode_t, working_dir: WasmPtr, working_dir_len: MemoryOffset, - ret_handles: WasmPtr<__wasi_bus_handles_t, MemoryType>, + ret_handles: WasmPtr, ) -> BusErrno { super::process_spawn::( ctx, @@ -539,7 +539,7 @@ pub(crate) fn bus_open_local( name: WasmPtr, name_len: MemoryOffset, reuse: __wasi_bool_t, - ret_bid: WasmPtr<__wasi_bid_t, MemoryType>, + ret_bid: WasmPtr, ) -> BusErrno { super::bus_open_local::(ctx, name, name_len, reuse, ret_bid) } @@ -553,7 +553,7 @@ pub(crate) fn bus_open_remote( instance_len: MemoryOffset, token: WasmPtr, token_len: MemoryOffset, - ret_bid: WasmPtr<__wasi_bid_t, MemoryType>, + ret_bid: WasmPtr, ) -> BusErrno { super::bus_open_remote::( ctx, @@ -568,20 +568,20 @@ pub(crate) fn bus_open_remote( ) } -pub(crate) fn bus_close(ctx: FunctionEnvMut, bid: __wasi_bid_t) -> BusErrno { +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, + bid: Bid, keep_alive: __wasi_bool_t, topic: WasmPtr, topic_len: MemoryOffset, format: BusDataFormat, buf: WasmPtr, buf_len: MemoryOffset, - ret_cid: WasmPtr<__wasi_cid_t, MemoryType>, + ret_cid: WasmPtr, ) -> BusErrno { super::bus_call::( ctx, bid, keep_alive, topic, topic_len, format, buf, buf_len, ret_cid, @@ -590,14 +590,14 @@ pub(crate) fn bus_call( pub(crate) fn bus_subcall( ctx: FunctionEnvMut, - parent: __wasi_cid_t, + parent: Cid, keep_alive: __wasi_bool_t, topic: WasmPtr, topic_len: MemoryOffset, format: BusDataFormat, buf: WasmPtr, buf_len: MemoryOffset, - ret_cid: WasmPtr<__wasi_cid_t, MemoryType>, + ret_cid: WasmPtr, ) -> BusErrno { super::bus_subcall::( ctx, parent, keep_alive, topic, topic_len, format, buf, buf_len, ret_cid, @@ -626,7 +626,7 @@ pub(crate) fn bus_poll( pub(crate) fn call_reply( ctx: FunctionEnvMut, - cid: __wasi_cid_t, + cid: Cid, format: BusDataFormat, buf: WasmPtr, buf_len: MemoryOffset, @@ -636,13 +636,13 @@ pub(crate) fn call_reply( pub(crate) fn call_fault( ctx: FunctionEnvMut, - cid: __wasi_cid_t, + cid: Cid, fault: BusErrno, ) -> BusErrno { super::call_fault(ctx, cid, fault) } -pub(crate) fn call_close(ctx: FunctionEnvMut, cid: __wasi_cid_t) -> BusErrno { +pub(crate) fn call_close(ctx: FunctionEnvMut, cid: Cid) -> BusErrno { super::call_close(ctx, cid) } diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index bbabdf91c28..3dfe86b8e9a 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -5,7 +5,7 @@ use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ Addressfamily, Advice, BusDataFormat, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, Fdstat, Filesize, Filestat, Fstflags, Pid, Rights, Sockoption, Sockstatus, Socktype, - Streamsecurity, Subscription, Tid, Timestamp, Tty, Whence, + Streamsecurity, Subscription, Tid, Timestamp, Tty, Whence, Bid, Cid, BusHandles, }; type MemoryType = Memory64; @@ -514,7 +514,7 @@ pub(crate) fn process_spawn( stderr: __wasi_stdiomode_t, working_dir: WasmPtr, working_dir_len: MemoryOffset, - ret_handles: WasmPtr<__wasi_bus_handles_t, MemoryType>, + ret_handles: WasmPtr, ) -> BusErrno { super::process_spawn::( ctx, @@ -539,7 +539,7 @@ pub(crate) fn bus_open_local( name: WasmPtr, name_len: MemoryOffset, reuse: __wasi_bool_t, - ret_bid: WasmPtr<__wasi_bid_t, MemoryType>, + ret_bid: WasmPtr, ) -> BusErrno { super::bus_open_local::(ctx, name, name_len, reuse, ret_bid) } @@ -553,7 +553,7 @@ pub(crate) fn bus_open_remote( instance_len: MemoryOffset, token: WasmPtr, token_len: MemoryOffset, - ret_bid: WasmPtr<__wasi_bid_t, MemoryType>, + ret_bid: WasmPtr, ) -> BusErrno { super::bus_open_remote::( ctx, @@ -568,20 +568,20 @@ pub(crate) fn bus_open_remote( ) } -pub(crate) fn bus_close(ctx: FunctionEnvMut, bid: __wasi_bid_t) -> BusErrno { +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, + bid: Bid, keep_alive: __wasi_bool_t, topic: WasmPtr, topic_len: MemoryOffset, format: BusDataFormat, buf: WasmPtr, buf_len: MemoryOffset, - ret_cid: WasmPtr<__wasi_cid_t, MemoryType>, + ret_cid: WasmPtr, ) -> BusErrno { super::bus_call::( ctx, bid, keep_alive, topic, topic_len, format, buf, buf_len, ret_cid, @@ -590,14 +590,14 @@ pub(crate) fn bus_call( pub(crate) fn bus_subcall( ctx: FunctionEnvMut, - parent: __wasi_cid_t, + parent: Cid, keep_alive: __wasi_bool_t, topic: WasmPtr, topic_len: MemoryOffset, format: BusDataFormat, buf: WasmPtr, buf_len: MemoryOffset, - ret_cid: WasmPtr<__wasi_cid_t, MemoryType>, + ret_cid: WasmPtr, ) -> BusErrno { super::bus_subcall::( ctx, parent, keep_alive, topic, topic_len, format, buf, buf_len, ret_cid, @@ -626,7 +626,7 @@ pub(crate) fn bus_poll( pub(crate) fn call_reply( ctx: FunctionEnvMut, - cid: __wasi_cid_t, + cid: Cid, format: BusDataFormat, buf: WasmPtr, buf_len: MemoryOffset, @@ -636,13 +636,13 @@ pub(crate) fn call_reply( pub(crate) fn call_fault( ctx: FunctionEnvMut, - cid: __wasi_cid_t, + cid: Cid, fault: BusErrno, ) -> BusErrno { super::call_fault(ctx, cid, fault) } -pub(crate) fn call_close(ctx: FunctionEnvMut, cid: __wasi_cid_t) -> BusErrno { +pub(crate) fn call_close(ctx: FunctionEnvMut, cid: Cid) -> BusErrno { super::call_close(ctx, cid) } From d09a2ee979142358bcd6666ef18fdb54360a843f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 8 Sep 2022 11:16:45 +0200 Subject: [PATCH 53/84] Serialize all wasi-types into one lib.rs file, adjust Oflags --- lib/wasi-types-generated/build.rs | 6 + lib/wasi-types-generated/regenerate.sh | 1 + lib/wasi-types-generated/src/wasi/bindings.rs | 58 +- lib/wasi-types-generated/src/wasi/extra.rs | 72 +- .../src/wasi/extra_manual.rs | 84 +- lib/wasi-types-generated/wit-clean/output.wit | 40 +- .../wit-clean/typenames.wit | 40 +- lib/wasi-types/src/bus.rs | 48 - lib/wasi-types/src/directory.rs | 70 -- lib/wasi-types/src/file.rs | 124 --- lib/wasi-types/src/io.rs | 40 - lib/wasi-types/src/lib.rs | 831 +++++++++++++++++- lib/wasi-types/src/net.rs | 442 ---------- lib/wasi-types/src/signal.rs | 31 - lib/wasi-types/src/subscription.rs | 123 --- lib/wasi-types/src/time.rs | 10 - lib/wasi/src/state/mod.rs | 7 +- lib/wasi/src/syscalls/legacy/snapshot0.rs | 4 +- lib/wasi/src/syscalls/mod.rs | 66 +- lib/wasi/src/syscalls/wasi.rs | 14 +- lib/wasi/src/syscalls/wasix32.rs | 29 +- lib/wasi/src/syscalls/wasix64.rs | 29 +- 22 files changed, 1165 insertions(+), 1004 deletions(-) delete mode 100644 lib/wasi-types/src/bus.rs delete mode 100644 lib/wasi-types/src/directory.rs delete mode 100644 lib/wasi-types/src/file.rs delete mode 100644 lib/wasi-types/src/io.rs delete mode 100644 lib/wasi-types/src/net.rs delete mode 100644 lib/wasi-types/src/signal.rs delete mode 100644 lib/wasi-types/src/subscription.rs delete mode 100644 lib/wasi-types/src/time.rs diff --git a/lib/wasi-types-generated/build.rs b/lib/wasi-types-generated/build.rs index 358c8790fa6..527ae59e46f 100644 --- a/lib/wasi-types-generated/build.rs +++ b/lib/wasi-types-generated/build.rs @@ -31,6 +31,9 @@ fn main() { " ) .replace(" ", ""); + + let excluded_from_impl_valuetype = ["Prestat"]; + for (_, i) in result.types.iter() { match i.kind { | TypeDefKind::Record(_) @@ -47,6 +50,9 @@ fn main() { // | 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} {{ diff --git a/lib/wasi-types-generated/regenerate.sh b/lib/wasi-types-generated/regenerate.sh index f21ffbdc4a7..9a4fb1f14c3 100755 --- a/lib/wasi-types-generated/regenerate.sh +++ b/lib/wasi-types-generated/regenerate.sh @@ -14,5 +14,6 @@ wit-bindgen rust-wasm \ --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 \ No newline at end of file diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index 255d1d0cdc7..743affac3c1 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -809,6 +809,8 @@ pub mod output { } 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; @@ -829,6 +831,8 @@ pub mod output { } 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; @@ -843,6 +847,8 @@ pub mod output { } 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; @@ -1589,8 +1595,39 @@ pub mod output { 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; /// Dummy function to expose types into generated code - pub fn expose_types_dummy_func(fd: Fd,dirent: Dirent,snapshot0_dirent: Snapshot0Dirent,snapshot0_event: Snapshot0Event,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,tid: Tid,pid: Pid,bus_data_format: BusDataFormat,bid: Bid,option_bid: OptionBid,cid: Cid,option_cid: OptionCid,option_fd: OptionFd,bus_handles: BusHandles,exit_code: ExitCode,bus_event_exit: BusEventExit,bus_event_fault: BusEventFault,bus_event_close: BusEventClose,) -> (){ + pub fn expose_types_dummy_func(fd: Fd,dirent: Dirent,snapshot0_dirent: Snapshot0Dirent,snapshot0_event: Snapshot0Event,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,tid: Tid,pid: Pid,bus_data_format: BusDataFormat,bid: Bid,option_bid: OptionBid,cid: Cid,option_cid: OptionCid,option_fd: OptionFd,bus_handles: BusHandles,exit_code: ExitCode,bus_event_exit: BusEventExit,bus_event_fault: BusEventFault,bus_event_close: BusEventClose,prestat_u_dir: PrestatUDir,prestat_u: PrestatU,event_fd_flags: EventFdFlags,prestat: Prestat,file_delta: FileDelta,lookup_flags: LookupFlags,) -> (){ unsafe { let ptr0 = OUTPUT_RET_AREA.0.as_mut_ptr() as i32; *((ptr0 + 0) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd); @@ -2063,6 +2100,21 @@ pub mod output { }) as u8; let BusEventClose{ cid:cid45, } = bus_event_close; *((ptr0 + 612) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid45); + let PrestatUDir{ pr_name_len:pr_name_len46, } = prestat_u_dir; + *((ptr0 + 616) as *mut i32) = wit_bindgen_rust::rt::as_i32(pr_name_len46); + let PrestatU{ dir:dir47, } = prestat_u; + let PrestatUDir{ pr_name_len:pr_name_len48, } = dir47; + *((ptr0 + 620) as *mut i32) = wit_bindgen_rust::rt::as_i32(pr_name_len48); + *((ptr0 + 624) as *mut u16) = (wit_bindgen_rust::rt::as_i32(event_fd_flags)) as u16; + let Prestat{ pr_type:pr_type49, u:u49, } = prestat; + *((ptr0 + 628) as *mut u8) = (match pr_type49 { + Preopentype::Dir => 0, + }) as u8; + let PrestatU{ dir:dir50, } = u49; + let PrestatUDir{ pr_name_len:pr_name_len51, } = dir50; + *((ptr0 + 632) as *mut i32) = wit_bindgen_rust::rt::as_i32(pr_name_len51); + *((ptr0 + 640) as *mut i64) = wit_bindgen_rust::rt::as_i64(file_delta); + *((ptr0 + 648) as *mut i32) = wit_bindgen_rust::rt::as_i32(lookup_flags); #[link(wasm_import_module = "output")] extern "C" { #[cfg_attr(target_arch = "wasm32", link_name = "expose-types-dummy-func")] @@ -2075,6 +2127,6 @@ pub mod output { } #[repr(align(8))] - struct RetArea([u8; 616]); - static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 616]); + struct RetArea([u8; 656]); + static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 656]); } diff --git a/lib/wasi-types-generated/src/wasi/extra.rs b/lib/wasi-types-generated/src/wasi/extra.rs index ba12812d78a..1aefd18e1ab 100644 --- a/lib/wasi-types-generated/src/wasi/extra.rs +++ b/lib/wasi-types-generated/src/wasi/extra.rs @@ -813,6 +813,8 @@ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { } 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; @@ -833,6 +835,8 @@ pub fn from_bits_preserve(bits: u8) -> Self { } 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; @@ -847,6 +851,8 @@ pub fn from_bits_preserve(bits: u8) -> Self { } 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; @@ -1593,8 +1599,39 @@ pub cid: Cid, 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; /// Dummy function to expose types into generated code - pub fn expose_types_dummy_func(fd: Fd,dirent: Dirent,snapshot0_dirent: Snapshot0Dirent,snapshot0_event: Snapshot0Event,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,tid: Tid,pid: Pid,bus_data_format: BusDataFormat,bid: Bid,option_bid: OptionBid,cid: Cid,option_cid: OptionCid,option_fd: OptionFd,bus_handles: BusHandles,exit_code: ExitCode,bus_event_exit: BusEventExit,bus_event_fault: BusEventFault,bus_event_close: BusEventClose,) -> (){ + pub fn expose_types_dummy_func(fd: Fd,dirent: Dirent,snapshot0_dirent: Snapshot0Dirent,snapshot0_event: Snapshot0Event,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,tid: Tid,pid: Pid,bus_data_format: BusDataFormat,bid: Bid,option_bid: OptionBid,cid: Cid,option_cid: OptionCid,option_fd: OptionFd,bus_handles: BusHandles,exit_code: ExitCode,bus_event_exit: BusEventExit,bus_event_fault: BusEventFault,bus_event_close: BusEventClose,prestat_u_dir: PrestatUDir,prestat_u: PrestatU,event_fd_flags: EventFdFlags,prestat: Prestat,file_delta: FileDelta,lookup_flags: LookupFlags,) -> (){ unsafe { let ptr0 = OUTPUT_RET_AREA.0.as_mut_ptr() as i32; *((ptr0 + 0) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd); @@ -2067,6 +2104,21 @@ BusErrno::Unknown => 19, }) as u8; let BusEventClose{ cid:cid45, } = bus_event_close; *((ptr0 + 612) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid45); + let PrestatUDir{ pr_name_len:pr_name_len46, } = prestat_u_dir; + *((ptr0 + 616) as *mut i32) = wit_bindgen_rust::rt::as_i32(pr_name_len46); + let PrestatU{ dir:dir47, } = prestat_u; + let PrestatUDir{ pr_name_len:pr_name_len48, } = dir47; + *((ptr0 + 620) as *mut i32) = wit_bindgen_rust::rt::as_i32(pr_name_len48); + *((ptr0 + 624) as *mut u16) = (wit_bindgen_rust::rt::as_i32(event_fd_flags)) as u16; + let Prestat{ pr_type:pr_type49, u:u49, } = prestat; + *((ptr0 + 628) as *mut u8) = (match pr_type49 { +Preopentype::Dir => 0, + }) as u8; + let PrestatU{ dir:dir50, } = u49; + let PrestatUDir{ pr_name_len:pr_name_len51, } = dir50; + *((ptr0 + 632) as *mut i32) = wit_bindgen_rust::rt::as_i32(pr_name_len51); + *((ptr0 + 640) as *mut i64) = wit_bindgen_rust::rt::as_i64(file_delta); + *((ptr0 + 648) as *mut i32) = wit_bindgen_rust::rt::as_i32(lookup_flags); #[link(wasm_import_module = "output")] extern "C" { #[cfg_attr(target_arch = "wasm32", link_name = "expose-types-dummy-func")] @@ -2079,8 +2131,8 @@ fn wit_import(_: i32, ); } #[repr(align(8))] - struct RetArea([u8; 616]); - static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 616]); + struct RetArea([u8; 656]); + static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 656]); // TODO: if necessary, must be implemented in wit-bindgen @@ -2908,4 +2960,18 @@ unsafe impl ValueType for BusEventClose { 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]) { } +} + \ No newline at end of file diff --git a/lib/wasi-types-generated/src/wasi/extra_manual.rs b/lib/wasi-types-generated/src/wasi/extra_manual.rs index 96ed211d7fa..f654d98609d 100644 --- a/lib/wasi-types-generated/src/wasi/extra_manual.rs +++ b/lib/wasi-types-generated/src/wasi/extra_manual.rs @@ -235,11 +235,89 @@ unsafe impl wasmer::FromToNativeWasmType for Fstflags { } } +// 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 u8) + } + + #[cfg(feature = "sys")] + 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 + self.tag == other.tag && self.cid == other.cid } } -impl Eq for OptionCid { } \ No newline at end of file +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)); + } +} diff --git a/lib/wasi-types-generated/wit-clean/output.wit b/lib/wasi-types-generated/wit-clean/output.wit index 1bac8dd4fb6..1c99ce569f6 100644 --- a/lib/wasi-types-generated/wit-clean/output.wit +++ b/lib/wasi-types-generated/wit-clean/output.wit @@ -36,6 +36,12 @@ expose-types-dummy-func: func( bus-event-exit: bus-event-exit, bus-event-fault: bus-event-fault, bus-event-close: bus-event-close, + prestat-u-dir: prestat-u-dir, + prestat-u: prestat-u, + event-fd-flags: event-fd-flags, + prestat: prestat, + file-delta: file-delta, + lookup-flags: lookup-flags, ) /// Type names used by low-level WASI interfaces. @@ -525,10 +531,9 @@ record fdstat { } /// Which file time attributes to adjust. +/// TODO: wit appears to not have support for flags repr +/// (@witx repr u16) flags fstflags { - // TODO: wit appears to not have support for flags repr - //(@witx repr u16) - /// 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`. @@ -540,19 +545,17 @@ flags fstflags { } /// Flags determining the method of how paths are resolved. +/// TODO: wit appears to not have support for flags repr +/// (@witx repr u32) flags lookup { - // TODO: wit appears to not have support for flags repr - //(@witx repr u32) - /// 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 { - // TODO: wit appears to not have support for flags repr - //(@witx repr u16) - /// Create file if it does not exist. create, /// Fail if not a directory. @@ -887,6 +890,25 @@ record bus-event-fault { 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 // WASI Preview. This is an evolution of the API that WASI initially // launched with. // diff --git a/lib/wasi-types-generated/wit-clean/typenames.wit b/lib/wasi-types-generated/wit-clean/typenames.wit index a11166bea0c..89cc7ce9c7e 100644 --- a/lib/wasi-types-generated/wit-clean/typenames.wit +++ b/lib/wasi-types-generated/wit-clean/typenames.wit @@ -36,6 +36,12 @@ expose-types-dummy-func: func( bus-event-exit: bus-event-exit, bus-event-fault: bus-event-fault, bus-event-close: bus-event-close, + prestat-u-dir: prestat-u-dir, + prestat-u: prestat-u, + event-fd-flags: event-fd-flags, + prestat: prestat, + file-delta: file-delta, + lookup-flags: lookup-flags, ) /// Type names used by low-level WASI interfaces. @@ -525,10 +531,9 @@ record fdstat { } /// Which file time attributes to adjust. +/// TODO: wit appears to not have support for flags repr +/// (@witx repr u16) flags fstflags { - // TODO: wit appears to not have support for flags repr - //(@witx repr u16) - /// 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`. @@ -540,19 +545,17 @@ flags fstflags { } /// Flags determining the method of how paths are resolved. +/// TODO: wit appears to not have support for flags repr +/// (@witx repr u32) flags lookup { - // TODO: wit appears to not have support for flags repr - //(@witx repr u32) - /// 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 { - // TODO: wit appears to not have support for flags repr - //(@witx repr u16) - /// Create file if it does not exist. create, /// Fail if not a directory. @@ -887,3 +890,22 @@ record bus-event-fault { 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 diff --git a/lib/wasi-types/src/bus.rs b/lib/wasi-types/src/bus.rs deleted file mode 100644 index 86af94d3955..00000000000 --- a/lib/wasi-types/src/bus.rs +++ /dev/null @@ -1,48 +0,0 @@ -use wasmer_derive::ValueType; -use wasmer_types::MemorySize; -use wasmer_wasi_types_generated::wasi::{ - BusDataFormat, BusEventType, - BusEventExit, BusEventFault, - BusEventClose, Cid, OptionCid, -}; - -// 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, -} diff --git a/lib/wasi-types/src/directory.rs b/lib/wasi-types/src/directory.rs deleted file mode 100644 index d7bdbfe231f..00000000000 --- a/lib/wasi-types/src/directory.rs +++ /dev/null @@ -1,70 +0,0 @@ -use std::mem; -use wasmer_wasi_types_generated::wasi; - -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 wasmer_wasi_types_generated::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) - ); - } -} diff --git a/lib/wasi-types/src/file.rs b/lib/wasi-types/src/file.rs deleted file mode 100644 index f2d75d68062..00000000000 --- a/lib/wasi-types/src/file.rs +++ /dev/null @@ -1,124 +0,0 @@ -use std::{ - fmt, - mem::{self, MaybeUninit}, -}; -use wasmer_derive::ValueType; -use wasmer_types::ValueType; -use wasmer_wasi_types_generated::wasi::{Fd, Preopentype, Rights}; - -pub const __WASI_STDIN_FILENO: Fd = 0; -pub const __WASI_STDOUT_FILENO: Fd = 1; -pub const __WASI_STDERR_FILENO: Fd = 2; - -pub type __wasi_eventfdflags = u16; -pub const __WASI_EVENTFDFLAGS_SEMAPHORE: __wasi_eventfdflags = 1 << 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: Preopentype, - 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 { - Preopentype::Dir => Some(PrestatEnum::Dir { - pr_name_len: unsafe { self.u.dir.pr_name_len }, - }), - } - } -} - -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 { - 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_end!(u), mem::size_of_val(self)); - } -} - -pub type __wasi_filedelta_t = i64; - -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; - -/// 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); -} diff --git a/lib/wasi-types/src/io.rs b/lib/wasi-types/src/io.rs deleted file mode 100644 index 9f695073062..00000000000 --- a/lib/wasi-types/src/io.rs +++ /dev/null @@ -1,40 +0,0 @@ -use wasmer_derive::ValueType; -use wasmer_types::MemorySize; -use wasmer_wasi_types_generated::wasi::Fd; - -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_pipe_handles_t { - pub pipe: Fd, - pub other: Fd, -} - -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 7c85be5aae7..32118ed3c98 100644 --- a/lib/wasi-types/src/lib.rs +++ b/lib/wasi-types/src/lib.rs @@ -11,15 +11,6 @@ // Needed for #[derive(ValueType)] extern crate wasmer_types as wasmer; -mod bus; -mod directory; -mod file; -mod io; -mod net; -mod signal; -mod subscription; -mod time; - pub use crate::time::*; pub use bus::*; pub use directory::*; @@ -30,5 +21,825 @@ pub use signal::*; pub use subscription::*; pub type __wasi_exitcode_t = u32; - pub type __wasi_userdata_t = u64; + +pub mod bus { + use wasmer_derive::ValueType; + use wasmer_types::MemorySize; + use wasmer_wasi_types_generated::wasi::{ + BusDataFormat, BusEventClose, BusEventExit, BusEventFault, BusEventType, Cid, OptionCid, + }; + + // 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 std::{ + fmt, + mem::{self, MaybeUninit}, + }; + use wasmer_derive::ValueType; + use wasmer_types::ValueType; + use wasmer_wasi_types_generated::wasi::{Fd, Preopentype, Prestat, Rights}; + + pub use wasmer_wasi_types_generated::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 EventFdFlags_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); + } +} + +// --- not ported + +pub mod directory { + use std::mem; + use wasmer_wasi_types_generated::wasi; + + 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 wasmer_wasi_types_generated::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; + use wasmer_wasi_types_generated::wasi::Fd; + + 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_pipe_handles_t { + pub pipe: Fd, + pub other: Fd, + } + + 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; +} + +pub mod net { + use super::*; + use wasmer_derive::ValueType; + use wasmer_wasi_types_generated::wasi::{Addressfamily, Fd, Filesize}; + + use crate::__wasi_option_timestamp_t; + + 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], + } + + #[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: 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 __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: Fd, + pub res: Fd, + pub hdr: Fd, + } + + #[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: Filesize, + 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; +} + +pub mod signal { + 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; +} + +pub mod subscription { + use wasmer_wasi_types_generated::wasi::{ + Eventtype, SubscriptionClock, SubscriptionFsReadwrite, + }; + + /// Safe Rust wrapper around `__wasi_subscription_t::type_` and `__wasi_subscription_t::u` + #[derive(Debug, Clone)] + pub enum EventType { + Clock(SubscriptionClock), + Read(SubscriptionFsReadwrite), + Write(SubscriptionFsReadwrite), + } + + impl EventType { + pub fn raw_tag(&self) -> Eventtype { + match self { + EventType::Clock(_) => Eventtype::Clock, + EventType::Read(_) => Eventtype::FdRead, + EventType::Write(_) => Eventtype::FdWrite, + } + } + } + + /* TODO: re-enable and adjust if still required + impl TryFrom for __wasi_subscription_t { + type Error = Errno; + + fn try_from(ws: WasiSubscription) -> Result { + #[allow(unreachable_patterns)] + let (type_, u) = match ws.event_type { + EventType::Clock(c) => (Eventtype::Clock, __wasi_subscription_u { clock: c }), + EventType::Read(rw) => ( + Eventtype::FdRead, + __wasi_subscription_u { fd_readwrite: rw }, + ), + EventType::Write(rw) => ( + Eventtype::FdWrite, + __wasi_subscription_u { fd_readwrite: rw }, + ), + _ => return Err(Errno::Inval), + }; + + 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", &self.type_.to_str()) + .field( + "u", + match self.type_ { + Eventtype::Clock => unsafe { &self.u.clock }, + Eventtype::FdRead | Eventtype::FdWrite => unsafe { &self.u.fd_readwrite }, + }, + ) + .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_ { + Eventtype::FdRead | Eventtype::FdWrite => 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)); + }, + 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_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_ { + Eventtype::Clock => Some(SubscriptionEnum::Clock(unsafe { self.u.clock })), + Eventtype::FdRead | Eventtype::FdWrite => Some(SubscriptionEnum::FdReadWrite(unsafe { + self.u.fd_readwrite + })), + } + } + } + + */ +} + +pub mod time { + use super::io::__wasi_option_t; + use wasmer_derive::ValueType; + use wasmer_wasi_types_generated::wasi::Timestamp; + + #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] + #[repr(C)] + pub struct __wasi_option_timestamp_t { + pub tag: __wasi_option_t, + pub u: Timestamp, + } +} diff --git a/lib/wasi-types/src/net.rs b/lib/wasi-types/src/net.rs deleted file mode 100644 index 79a11e7d6f0..00000000000 --- a/lib/wasi-types/src/net.rs +++ /dev/null @@ -1,442 +0,0 @@ -use super::*; -use wasmer_derive::ValueType; -use wasmer_wasi_types_generated::wasi::{Addressfamily, Fd, Filesize}; - -use crate::__wasi_option_timestamp_t; - -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], -} - -#[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: 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 __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: Fd, - pub res: Fd, - pub hdr: Fd, -} - -#[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: Filesize, - 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 e47e26eb31c..00000000000 --- a/lib/wasi-types/src/subscription.rs +++ /dev/null @@ -1,123 +0,0 @@ -use wasmer_wasi_types_generated::wasi::{Eventtype, SubscriptionClock, SubscriptionFsReadwrite}; - -/// Safe Rust wrapper around `__wasi_subscription_t::type_` and `__wasi_subscription_t::u` -#[derive(Debug, Clone)] -pub enum EventType { - Clock(SubscriptionClock), - Read(SubscriptionFsReadwrite), - Write(SubscriptionFsReadwrite), -} - -impl EventType { - pub fn raw_tag(&self) -> Eventtype { - match self { - EventType::Clock(_) => Eventtype::Clock, - EventType::Read(_) => Eventtype::FdRead, - EventType::Write(_) => Eventtype::FdWrite, - } - } -} - -/* TODO: re-enable and adjust if still required -impl TryFrom for __wasi_subscription_t { - type Error = Errno; - - fn try_from(ws: WasiSubscription) -> Result { - #[allow(unreachable_patterns)] - let (type_, u) = match ws.event_type { - EventType::Clock(c) => (Eventtype::Clock, __wasi_subscription_u { clock: c }), - EventType::Read(rw) => ( - Eventtype::FdRead, - __wasi_subscription_u { fd_readwrite: rw }, - ), - EventType::Write(rw) => ( - Eventtype::FdWrite, - __wasi_subscription_u { fd_readwrite: rw }, - ), - _ => return Err(Errno::Inval), - }; - - 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", &self.type_.to_str()) - .field( - "u", - match self.type_ { - Eventtype::Clock => unsafe { &self.u.clock }, - Eventtype::FdRead | Eventtype::FdWrite => unsafe { &self.u.fd_readwrite }, - }, - ) - .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_ { - Eventtype::FdRead | Eventtype::FdWrite => 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)); - }, - 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_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_ { - Eventtype::Clock => Some(SubscriptionEnum::Clock(unsafe { self.u.clock })), - Eventtype::FdRead | Eventtype::FdWrite => Some(SubscriptionEnum::FdReadWrite(unsafe { - self.u.fd_readwrite - })), - } - } -} - -*/ diff --git a/lib/wasi-types/src/time.rs b/lib/wasi-types/src/time.rs deleted file mode 100644 index 63a19fae493..00000000000 --- a/lib/wasi-types/src/time.rs +++ /dev/null @@ -1,10 +0,0 @@ -use super::io::__wasi_option_t; -use wasmer_derive::ValueType; -use wasmer_wasi_types_generated::wasi::Timestamp; - -#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] -#[repr(C)] -pub struct __wasi_option_timestamp_t { - pub tag: __wasi_option_t, - pub u: Timestamp, -} diff --git a/lib/wasi/src/state/mod.rs b/lib/wasi/src/state/mod.rs index c4fafe4a73f..7cc223a5f50 100644 --- a/lib/wasi/src/state/mod.rs +++ b/lib/wasi/src/state/mod.rs @@ -55,6 +55,7 @@ use wasmer_vbus::BusSpawnedProcess; use wasmer_wasi_types_generated::wasi::{ Errno, Fd as WasiFd, Fdflags, Fdstat, Filesize, Filestat, Filetype, Preopentype, Rights, }; +use wasmer_wasi_types_generated::wasi::{Prestat, PrestatEnum}; use wasmer_vfs::{FileSystem, FsError, OpenOptions, VirtualFile}; @@ -1370,7 +1371,7 @@ impl WasiFs { }) } - pub fn prestat_fd(&self, inodes: &WasiInodes, fd: WasiFd) -> Result<__wasi_prestat_t, Errno> { + 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)?); @@ -1383,8 +1384,8 @@ impl WasiFs { } } - pub(crate) fn prestat_fd_inner(&self, inode_val: &InodeVal) -> __wasi_prestat_t { - __wasi_prestat_t { + pub(crate) fn prestat_fd_inner(&self, inode_val: &InodeVal) -> Prestat { + Prestat { pr_type: Preopentype::Dir, u: PrestatEnum::Dir { // REVIEW: diff --git a/lib/wasi/src/syscalls/legacy/snapshot0.rs b/lib/wasi/src/syscalls/legacy/snapshot0.rs index d5182db9936..0ad76d39d1d 100644 --- a/lib/wasi/src/syscalls/legacy/snapshot0.rs +++ b/lib/wasi/src/syscalls/legacy/snapshot0.rs @@ -68,7 +68,7 @@ pub fn fd_filestat_get( pub fn path_filestat_get( mut ctx: FunctionEnvMut, fd: Fd, - flags: types::__wasi_lookupflags_t, + flags: types::LookupFlags, path: WasmPtr, path_len: u32, buf: WasmPtr, @@ -111,7 +111,7 @@ pub fn path_filestat_get( pub fn fd_seek( ctx: FunctionEnvMut, fd: Fd, - offset: types::__wasi_filedelta_t, + offset: types::FileDelta, whence: Snapshot0Whence, newoffset: WasmPtr, ) -> Result { diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index dd11841854d..7ff2d73304c 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -26,11 +26,11 @@ pub mod wasix64; use self::types::{ wasi::{ - Addressfamily, Advice, BusDataFormat, BusErrno, Clockid, Dircookie, Dirent, Errno, Event, - EventEnum, EventFdReadwrite, Eventrwflags, Eventtype, Fd as WasiFd, Fdflags, Fdstat, - Filesize, Filestat, Filetype, Fstflags, Linkcount, Pid, Rights, Snapshot0Clockid, - Sockoption, Sockstatus, Socktype, Streamsecurity, Subscription, SubscriptionEnum, - SubscriptionFsReadwrite, Tid, Timestamp, Tty, Whence, Cid, OptionFd, Bid, BusHandles, + 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, Streamsecurity, Subscription, + SubscriptionEnum, SubscriptionFsReadwrite, Tid, Timestamp, Tty, Whence, }, *, }; @@ -924,7 +924,7 @@ pub fn fd_pread( pub fn fd_prestat_get( ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd, - buf: WasmPtr<__wasi_prestat_t, M>, + buf: WasmPtr, ) -> Errno { trace!("wasi::fd_prestat_get: fd={}", fd); let env = ctx.data(); @@ -1457,7 +1457,7 @@ pub fn fd_dup( pub fn fd_event( ctx: FunctionEnvMut<'_, WasiEnv>, initial_val: u64, - flags: __wasi_eventfdflags, + flags: EventFdFlags, ret_fd: WasmPtr, ) -> Errno { debug!("wasi::fd_event"); @@ -1467,7 +1467,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 & EventFdFlags_SEMAPHORE != 0, wakers: Default::default(), }; @@ -1492,7 +1492,7 @@ pub fn fd_event( /// Inputs: /// - `Fd fd` /// File descriptor to mutate -/// - `__wasi_filedelta_t offset` +/// - `FileDelta offset` /// Number of bytes to adjust offset by /// - `Whence whence` /// What the offset is relative to @@ -1502,7 +1502,7 @@ pub fn fd_event( pub fn fd_seek( ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd, - offset: __wasi_filedelta_t, + offset: FileDelta, whence: Whence, newoffset: WasmPtr, ) -> Result { @@ -1967,7 +1967,7 @@ pub fn path_create_directory( /// Inputs: /// - `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 @@ -1979,7 +1979,7 @@ pub fn path_create_directory( pub fn path_filestat_get( ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd, - flags: __wasi_lookupflags_t, + flags: LookupFlags, path: WasmPtr, path_len: M::Offset, buf: WasmPtr, @@ -2009,7 +2009,7 @@ pub fn path_filestat_get( /// Inputs: /// - `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 @@ -2023,7 +2023,7 @@ pub fn path_filestat_get_internal( state: &WasiState, inodes: &mut crate::WasiInodes, fd: WasiFd, - flags: __wasi_lookupflags_t, + flags: LookupFlags, path_string: &str, ) -> Result { let root_dir = state.fs.get_fd(fd)?; @@ -2052,7 +2052,7 @@ pub fn path_filestat_get_internal( /// Inputs: /// - `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 @@ -2067,7 +2067,7 @@ pub fn path_filestat_get_internal( pub fn path_filestat_set_times( ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd, - flags: __wasi_lookupflags_t, + flags: LookupFlags, path: WasmPtr, path_len: M::Offset, st_atim: Timestamp, @@ -2129,7 +2129,7 @@ pub fn path_filestat_set_times( /// Inputs: /// - `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 @@ -2144,7 +2144,7 @@ pub fn path_filestat_set_times( pub fn path_link( ctx: FunctionEnvMut<'_, WasiEnv>, old_fd: WasiFd, - old_flags: __wasi_lookupflags_t, + old_flags: LookupFlags, old_path: WasmPtr, old_path_len: M::Offset, new_fd: WasiFd, @@ -2218,13 +2218,13 @@ pub fn path_link( /// Inputs: /// - `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 /// - `Rights fs_rights_base` /// The rights of the created file descriptor @@ -2240,10 +2240,10 @@ pub fn path_link( pub fn path_open( ctx: FunctionEnvMut<'_, WasiEnv>, dirfd: WasiFd, - dirflags: __wasi_lookupflags_t, + dirflags: LookupFlags, path: WasmPtr, path_len: M::Offset, - o_flags: __wasi_oflags_t, + o_flags: Oflags, fs_rights_base: Rights, fs_rights_inheriting: Rights, fs_flags: Fdflags, @@ -2310,10 +2310,10 @@ pub fn path_open( wasi_try_mem!(fd_ref.write(*special_fd)); return Errno::Success; } - if o_flags & __WASI_O_DIRECTORY != 0 { + if o_flags.contains(Oflags::DIRECTORY) { return Errno::Notdir; } - if o_flags & __WASI_O_EXCL != 0 { + if o_flags.contains(Oflags::EXCL) { return Errno::Exist; } @@ -2323,8 +2323,8 @@ pub fn path_open( if write_permission { ( fs_flags.contains(Fdflags::APPEND), - o_flags & __WASI_O_TRUNC != 0, - o_flags & __WASI_O_CREAT != 0, + o_flags.contains(Oflags::TRUNC), + o_flags.contains(Oflags::CREATE), ) } else { (false, false, false) @@ -2340,10 +2340,10 @@ pub fn path_open( 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,8 +2370,8 @@ 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 { + if o_flags.contains(Oflags::CREATE) { + if o_flags.contains(Oflags::DIRECTORY) { return Errno::Notdir; } debug!("Creating file"); @@ -4043,11 +4043,7 @@ 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: Cid, - fault: BusErrno, -) -> BusErrno { +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); diff --git a/lib/wasi/src/syscalls/wasi.rs b/lib/wasi/src/syscalls/wasi.rs index 63109da0baf..3ba116a5149 100644 --- a/lib/wasi/src/syscalls/wasi.rs +++ b/lib/wasi/src/syscalls/wasi.rs @@ -150,7 +150,7 @@ pub(crate) fn fd_pread( pub(crate) fn fd_prestat_get( ctx: FunctionEnvMut, fd: WasiFd, - buf: WasmPtr<__wasi_prestat_t, MemoryType>, + buf: WasmPtr, ) -> Errno { super::fd_prestat_get::(ctx, fd, buf) } @@ -203,7 +203,7 @@ pub(crate) fn fd_renumber(ctx: FunctionEnvMut, from: WasiFd, to: WasiFd pub(crate) fn fd_seek( ctx: FunctionEnvMut, fd: WasiFd, - offset: __wasi_filedelta_t, + offset: FileDelta, whence: Whence, newoffset: WasmPtr, ) -> Result { @@ -244,7 +244,7 @@ pub(crate) fn path_create_directory( pub(crate) fn path_filestat_get( ctx: FunctionEnvMut, fd: WasiFd, - flags: __wasi_lookupflags_t, + flags: LookupFlags, path: WasmPtr, path_len: MemoryOffset, buf: WasmPtr, @@ -255,7 +255,7 @@ pub(crate) fn path_filestat_get( pub(crate) fn path_filestat_set_times( ctx: FunctionEnvMut, fd: WasiFd, - flags: __wasi_lookupflags_t, + flags: LookupFlags, path: WasmPtr, path_len: MemoryOffset, st_atim: Timestamp, @@ -270,7 +270,7 @@ pub(crate) fn path_filestat_set_times( pub(crate) fn path_link( ctx: FunctionEnvMut, old_fd: WasiFd, - old_flags: __wasi_lookupflags_t, + old_flags: LookupFlags, old_path: WasmPtr, old_path_len: MemoryOffset, new_fd: WasiFd, @@ -292,10 +292,10 @@ pub(crate) fn path_link( pub(crate) fn path_open( ctx: FunctionEnvMut, dirfd: WasiFd, - dirflags: __wasi_lookupflags_t, + 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: WasiFdflags, diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index bc792b5304f..739b8e19f27 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -3,9 +3,10 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{FunctionEnvMut, Memory, Memory32, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ - Addressfamily, Advice, BusDataFormat, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, - Fdstat, Filesize, Filestat, Fstflags, Pid, Rights, Sockoption, Sockstatus, Socktype, - Streamsecurity, Subscription, Tid, Timestamp, Tty, Whence, BusHandles, Bid, Cid + 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; @@ -148,7 +149,7 @@ pub(crate) fn fd_pread( pub(crate) fn fd_prestat_get( ctx: FunctionEnvMut, fd: Fd, - buf: WasmPtr<__wasi_prestat_t, MemoryType>, + buf: WasmPtr, ) -> Errno { super::fd_prestat_get::(ctx, fd, buf) } @@ -201,7 +202,7 @@ pub(crate) fn fd_renumber(ctx: FunctionEnvMut, from: Fd, to: Fd) -> Err pub(crate) fn fd_seek( ctx: FunctionEnvMut, fd: Fd, - offset: __wasi_filedelta_t, + offset: FileDelta, whence: Whence, newoffset: WasmPtr, ) -> Result { @@ -242,7 +243,7 @@ pub(crate) fn path_create_directory( pub(crate) fn path_filestat_get( ctx: FunctionEnvMut, fd: Fd, - flags: __wasi_lookupflags_t, + flags: LookupFlags, path: WasmPtr, path_len: MemoryOffset, buf: WasmPtr, @@ -253,7 +254,7 @@ pub(crate) fn path_filestat_get( pub(crate) fn path_filestat_set_times( ctx: FunctionEnvMut, fd: Fd, - flags: __wasi_lookupflags_t, + flags: LookupFlags, path: WasmPtr, path_len: MemoryOffset, st_atim: Timestamp, @@ -268,7 +269,7 @@ pub(crate) fn path_filestat_set_times( pub(crate) fn path_link( ctx: FunctionEnvMut, old_fd: Fd, - old_flags: __wasi_lookupflags_t, + old_flags: LookupFlags, old_path: WasmPtr, old_path_len: MemoryOffset, new_fd: Fd, @@ -290,10 +291,10 @@ pub(crate) fn path_link( pub(crate) fn path_open( ctx: FunctionEnvMut, dirfd: Fd, - dirflags: __wasi_lookupflags_t, + dirflags: LookupFlags, path: WasmPtr, path_len: MemoryOffset, - o_flags: __wasi_oflags_t, + o_flags: Oflags, fs_rights_base: Rights, fs_rights_inheriting: Rights, fs_flags: Fdflags, @@ -414,7 +415,7 @@ pub(crate) fn fd_dup( pub(crate) fn fd_event( ctx: FunctionEnvMut, initial_val: u64, - flags: __wasi_eventfdflags, + flags: EventFdFlags, ret_fd: WasmPtr, ) -> Errno { super::fd_event(ctx, initial_val, flags, ret_fd) @@ -634,11 +635,7 @@ pub(crate) fn call_reply( super::call_reply::(ctx, cid, format, buf, buf_len) } -pub(crate) fn call_fault( - ctx: FunctionEnvMut, - cid: Cid, - fault: BusErrno, -) -> BusErrno { +pub(crate) fn call_fault(ctx: FunctionEnvMut, cid: Cid, fault: BusErrno) -> BusErrno { super::call_fault(ctx, cid, fault) } diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index 3dfe86b8e9a..72cfd1488b2 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -3,9 +3,10 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{FunctionEnvMut, Memory, Memory64, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; use wasmer_wasi_types_generated::wasi::{ - Addressfamily, Advice, BusDataFormat, BusErrno, Clockid, Dircookie, Errno, Event, Fd, Fdflags, - Fdstat, Filesize, Filestat, Fstflags, Pid, Rights, Sockoption, Sockstatus, Socktype, - Streamsecurity, Subscription, Tid, Timestamp, Tty, Whence, Bid, Cid, BusHandles, + 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; @@ -148,7 +149,7 @@ pub(crate) fn fd_pread( pub(crate) fn fd_prestat_get( ctx: FunctionEnvMut, fd: Fd, - buf: WasmPtr<__wasi_prestat_t, MemoryType>, + buf: WasmPtr, ) -> Errno { super::fd_prestat_get::(ctx, fd, buf) } @@ -201,7 +202,7 @@ pub(crate) fn fd_renumber(ctx: FunctionEnvMut, from: Fd, to: Fd) -> Err pub(crate) fn fd_seek( ctx: FunctionEnvMut, fd: Fd, - offset: __wasi_filedelta_t, + offset: FileDelta, whence: Whence, newoffset: WasmPtr, ) -> Result { @@ -242,7 +243,7 @@ pub(crate) fn path_create_directory( pub(crate) fn path_filestat_get( ctx: FunctionEnvMut, fd: Fd, - flags: __wasi_lookupflags_t, + flags: LookupFlags, path: WasmPtr, path_len: MemoryOffset, buf: WasmPtr, @@ -253,7 +254,7 @@ pub(crate) fn path_filestat_get( pub(crate) fn path_filestat_set_times( ctx: FunctionEnvMut, fd: Fd, - flags: __wasi_lookupflags_t, + flags: LookupFlags, path: WasmPtr, path_len: MemoryOffset, st_atim: Timestamp, @@ -268,7 +269,7 @@ pub(crate) fn path_filestat_set_times( pub(crate) fn path_link( ctx: FunctionEnvMut, old_fd: Fd, - old_flags: __wasi_lookupflags_t, + old_flags: LookupFlags, old_path: WasmPtr, old_path_len: MemoryOffset, new_fd: Fd, @@ -290,10 +291,10 @@ pub(crate) fn path_link( pub(crate) fn path_open( ctx: FunctionEnvMut, dirfd: Fd, - dirflags: __wasi_lookupflags_t, + dirflags: LookupFlags, path: WasmPtr, path_len: MemoryOffset, - o_flags: __wasi_oflags_t, + o_flags: Oflags, fs_rights_base: Rights, fs_rights_inheriting: Rights, fs_flags: Fdflags, @@ -414,7 +415,7 @@ pub(crate) fn fd_dup( pub(crate) fn fd_event( ctx: FunctionEnvMut, initial_val: u64, - flags: __wasi_eventfdflags, + flags: EventFdFlags, ret_fd: WasmPtr, ) -> Errno { super::fd_event(ctx, initial_val, flags, ret_fd) @@ -634,11 +635,7 @@ pub(crate) fn call_reply( super::call_reply::(ctx, cid, format, buf, buf_len) } -pub(crate) fn call_fault( - ctx: FunctionEnvMut, - cid: Cid, - fault: BusErrno, -) -> BusErrno { +pub(crate) fn call_fault(ctx: FunctionEnvMut, cid: Cid, fault: BusErrno) -> BusErrno { super::call_fault(ctx, cid, fault) } From 1f35d348365f63db10268bda997a9519d546eb87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 8 Sep 2022 11:17:26 +0200 Subject: [PATCH 54/84] cargo fmt --- lib/wasi-types-generated/src/wasi/extra.rs | 4183 +++++++++-------- .../src/wasi/extra_manual.rs | 1 - 2 files changed, 2153 insertions(+), 2031 deletions(-) diff --git a/lib/wasi-types-generated/src/wasi/extra.rs b/lib/wasi-types-generated/src/wasi/extra.rs index 1aefd18e1ab..4889ad1fe08 100644 --- a/lib/wasi-types-generated/src/wasi/extra.rs +++ b/lib/wasi-types-generated/src/wasi/extra.rs @@ -1,548 +1,541 @@ - use std::mem::MaybeUninit; use wasmer::ValueType; - - - /// 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() +/// 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", - } +/// 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.", + } + } } -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::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 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", - } + +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." + } + } + } } -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::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 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! { + +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`. @@ -550,7 +543,7 @@ pub struct Rights: u64 { /// 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; @@ -631,145 +624,127 @@ pub struct Rights: u64 { 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() +impl Rights { + /// Convert from a raw integer, preserving any unknown bits. See + /// + pub fn from_bits_preserve(bits: u64) -> Self { + Self { bits } + } } -Advice::Willneed => { - f.debug_tuple("Advice::Willneed").finish() +/// 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(), + } + } } -Advice::Dontneed => { - f.debug_tuple("Advice::Dontneed").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() + } } -Advice::Noreuse => { - f.debug_tuple("Advice::Noreuse").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! { +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. @@ -786,32 +761,38 @@ pub struct Fdflags: u8 { 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 } +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! { +/// 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) @@ -826,14 +807,14 @@ pub struct Fstflags: u8 { 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 } +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! { +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) @@ -842,14 +823,14 @@ pub struct Lookup: u8 { 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 } +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! { +wit_bindgen_rust::bitflags::bitflags! { /// Open flags used by `path_open`. /// TODO: wit appears to not have support for flags repr /// (@witx repr u16) @@ -864,46 +845,40 @@ pub struct Oflags: u8 { 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() +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! { +wit_bindgen_rust::bitflags::bitflags! { /// Flags determining how to interpret the timestamp provided in /// `subscription-clock::timeout`. pub struct Subclockflags: u8 { @@ -915,68 +890,79 @@ pub struct Subclockflags: u8 { 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 } +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() +/// 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() + } } - } - wit_bindgen_rust::bitflags::bitflags! { +/// 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 { @@ -984,1164 +970,1317 @@ pub struct Eventrwflags: u8 { 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() -} - } +impl Eventrwflags { + /// Convert from a raw integer, preserving any unknown bits. See + /// + pub fn from_bits_preserve(bits: u8) -> Self { + Self { bits } + } } - } - #[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() +/// 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() + } } -Streamsecurity::AnyEncryption => { - f.debug_tuple("Streamsecurity::AnyEncryption").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() + } } -Streamsecurity::ClassicEncryption => { - f.debug_tuple("Streamsecurity::ClassicEncryption").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(), + } + } } -Streamsecurity::DoubleEncryption => { - f.debug_tuple("Streamsecurity::DoubleEncryption").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(), + } + } } - } - #[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() +/// 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() + } + } + } } -Addressfamily::Inet4 => { - f.debug_tuple("Addressfamily::Inet4").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() + } } -Addressfamily::Inet6 => { - f.debug_tuple("Addressfamily::Inet6").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() + } } -Addressfamily::Unix => { - f.debug_tuple("Addressfamily::Unix").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(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() +#[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(), + } + } } -Snapshot0Whence::End => { - f.debug_tuple("Snapshot0Whence::End").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(), + } + } } -Snapshot0Whence::Set => { - f.debug_tuple("Snapshot0Whence::Set").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(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() +#[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() + } } -Whence::Cur => { - f.debug_tuple("Whence::Cur").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() + } } -Whence::End => { - f.debug_tuple("Whence::End").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() +#[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() + } } -BusDataFormat::Bincode => { - f.debug_tuple("BusDataFormat::Bincode").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(), + } + } } -BusDataFormat::MessagePack => { - f.debug_tuple("BusDataFormat::MessagePack").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(), + } + } } -BusDataFormat::Json => { - f.debug_tuple("BusDataFormat::Json").finish() +pub type Bid = u32; +pub type Cid = u32; +/// __wasi_option_t +pub type OptionTag = u8; +#[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() + } } -BusDataFormat::Yaml => { - f.debug_tuple("BusDataFormat::Yaml").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() + } } -BusDataFormat::Xml => { - f.debug_tuple("BusDataFormat::Xml").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() + } } -BusDataFormat::Rkyv => { - f.debug_tuple("BusDataFormat::Rkyv").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(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() +#[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() + } } -BusEventType::Exit => { - f.debug_tuple("BusEventType::Exit").finish() +#[repr(C)] +#[derive(Copy, Clone)] +pub struct BusEventClose { + pub cid: Cid, } -BusEventType::Call => { - f.debug_tuple("BusEventType::Call").finish() +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() + } } -BusEventType::Result => { - f.debug_tuple("BusEventType::Result").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() + } } -BusEventType::Fault => { - f.debug_tuple("BusEventType::Fault").finish() +#[repr(C)] +#[derive(Copy, Clone)] +pub struct PrestatU { + pub dir: PrestatUDir, } -BusEventType::Close => { - f.debug_tuple("BusEventType::Close").finish() +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 Bid = u32; - pub type Cid = u32; - /// __wasi_option_t - pub type OptionTag = u8; - #[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; - /// Dummy function to expose types into generated code - pub fn expose_types_dummy_func(fd: Fd,dirent: Dirent,snapshot0_dirent: Snapshot0Dirent,snapshot0_event: Snapshot0Event,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,tid: Tid,pid: Pid,bus_data_format: BusDataFormat,bid: Bid,option_bid: OptionBid,cid: Cid,option_cid: OptionCid,option_fd: OptionFd,bus_handles: BusHandles,exit_code: ExitCode,bus_event_exit: BusEventExit,bus_event_fault: BusEventFault,bus_event_close: BusEventClose,prestat_u_dir: PrestatUDir,prestat_u: PrestatU,event_fd_flags: EventFdFlags,prestat: Prestat,file_delta: FileDelta,lookup_flags: LookupFlags,) -> (){ -unsafe { - let ptr0 = OUTPUT_RET_AREA.0.as_mut_ptr() as i32; - *((ptr0 + 0) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd); - let Dirent{ d_next:d_next1, d_ino:d_ino1, d_type:d_type1, d_namlen:d_namlen1, } = dirent; - *((ptr0 + 8) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_next1); - *((ptr0 + 16) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_ino1); - *((ptr0 + 24) as *mut u8) = (match d_type1 { -Filetype::Unknown => 0, -Filetype::BlockDevice => 1, -Filetype::CharacterDevice => 2, -Filetype::Directory => 3, -Filetype::RegularFile => 4, -Filetype::SocketDgram => 5, -Filetype::SocketStream => 6, -Filetype::SymbolicLink => 7, -Filetype::Fifo => 8, - }) as u8; - *((ptr0 + 28) as *mut i32) = wit_bindgen_rust::rt::as_i32(d_namlen1); - let Snapshot0Dirent{ d_next:d_next2, d_ino:d_ino2, d_namlen:d_namlen2, d_type:d_type2, } = snapshot0_dirent; - *((ptr0 + 32) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_next2); - *((ptr0 + 40) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_ino2); - *((ptr0 + 48) as *mut i32) = wit_bindgen_rust::rt::as_i32(d_namlen2); - *((ptr0 + 52) as *mut u8) = (match d_type2 { -Filetype::Unknown => 0, -Filetype::BlockDevice => 1, -Filetype::CharacterDevice => 2, -Filetype::Directory => 3, -Filetype::RegularFile => 4, -Filetype::SocketDgram => 5, -Filetype::SocketStream => 6, -Filetype::SymbolicLink => 7, -Filetype::Fifo => 8, - }) as u8; - let Snapshot0Event{ userdata:userdata3, error:error3, type_:type_3, fd_readwrite:fd_readwrite3, } = snapshot0_event; - *((ptr0 + 56) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata3); - *((ptr0 + 64) as *mut u8) = (match error3 { -Errno::Success => 0, -Errno::Toobig => 1, -Errno::Access => 2, -Errno::Addrinuse => 3, -Errno::Addrnotavail => 4, -Errno::Afnosupport => 5, -Errno::Again => 6, -Errno::Already => 7, -Errno::Badf => 8, -Errno::Badmsg => 9, -Errno::Busy => 10, -Errno::Canceled => 11, -Errno::Child => 12, -Errno::Connaborted => 13, -Errno::Connrefused => 14, -Errno::Connreset => 15, -Errno::Deadlk => 16, -Errno::Destaddrreq => 17, -Errno::Dom => 18, -Errno::Dquot => 19, -Errno::Exist => 20, -Errno::Fault => 21, -Errno::Fbig => 22, -Errno::Hostunreach => 23, -Errno::Idrm => 24, -Errno::Ilseq => 25, -Errno::Inprogress => 26, -Errno::Intr => 27, -Errno::Inval => 28, -Errno::Io => 29, -Errno::Isconn => 30, -Errno::Isdir => 31, -Errno::Loop => 32, -Errno::Mfile => 33, -Errno::Mlink => 34, -Errno::Msgsize => 35, -Errno::Multihop => 36, -Errno::Nametoolong => 37, -Errno::Netdown => 38, -Errno::Netreset => 39, -Errno::Netunreach => 40, -Errno::Nfile => 41, -Errno::Nobufs => 42, -Errno::Nodev => 43, -Errno::Noent => 44, -Errno::Noexec => 45, -Errno::Nolck => 46, -Errno::Nolink => 47, -Errno::Nomem => 48, -Errno::Nomsg => 49, -Errno::Noprotoopt => 50, -Errno::Nospc => 51, -Errno::Nosys => 52, -Errno::Notconn => 53, -Errno::Notdir => 54, -Errno::Notempty => 55, -Errno::Notrecoverable => 56, -Errno::Notsock => 57, -Errno::Notsup => 58, -Errno::Notty => 59, -Errno::Nxio => 60, -Errno::Overflow => 61, -Errno::Ownerdead => 62, -Errno::Perm => 63, -Errno::Pipe => 64, -Errno::Proto => 65, -Errno::Protonosupport => 66, -Errno::Prototype => 67, -Errno::Range => 68, -Errno::Rofs => 69, -Errno::Spipe => 70, -Errno::Srch => 71, -Errno::Stale => 72, -Errno::Timedout => 73, -Errno::Txtbsy => 74, -Errno::Xdev => 75, -Errno::Notcapable => 76, - }) as u8; - *((ptr0 + 65) as *mut u8) = (match type_3 { -Eventtype::Clock => 0, -Eventtype::FdRead => 1, -Eventtype::FdWrite => 2, - }) as u8; - let EventFdReadwrite{ nbytes:nbytes4, flags:flags4, } = fd_readwrite3; - *((ptr0 + 72) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes4); - let flags5 = flags4; - *((ptr0 + 80) as *mut u8) = ((flags5.bits() >> 0) as i32) as u8; - match event_enum { -EventEnum::FdRead(e) => { - *((ptr0 + 88) as *mut u8) = (0i32) as u8; - let EventFdReadwrite{ nbytes:nbytes6, flags:flags6, } = e; - *((ptr0 + 96) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes6); - let flags7 = flags6; - *((ptr0 + 104) as *mut u8) = ((flags7.bits() >> 0) as i32) as u8; - -}, -EventEnum::FdWrite(e) => { - *((ptr0 + 88) as *mut u8) = (1i32) as u8; - let EventFdReadwrite{ nbytes:nbytes8, flags:flags8, } = e; - *((ptr0 + 96) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes8); - let flags9 = flags8; - *((ptr0 + 104) as *mut u8) = ((flags9.bits() >> 0) as i32) as u8; - -}, -EventEnum::Clock=> { - let e = (); - { -*((ptr0 + 88) as *mut u8) = (2i32) as u8; -let () = e; - - } +pub type FileDelta = i64; +pub type LookupFlags = u32; +/// Dummy function to expose types into generated code +pub fn expose_types_dummy_func( + fd: Fd, + dirent: Dirent, + snapshot0_dirent: Snapshot0Dirent, + snapshot0_event: Snapshot0Event, + event_enum: EventEnum, + event: Event, + fdstat: Fdstat, + subscription_clock: SubscriptionClock, + snapshot0_subscription_clock: Snapshot0SubscriptionClock, + subscription: Subscription, + snapshot0_subscription: Snapshot0Subscription, + device: Device, + linkcount: Linkcount, + snapshot0_linkcount: Snapshot0Linkcount, + filestat: Filestat, + snapshot0_filestat: Snapshot0Filestat, + tty: Tty, + tid: Tid, + pid: Pid, + bus_data_format: BusDataFormat, + bid: Bid, + option_bid: OptionBid, + cid: Cid, + option_cid: OptionCid, + option_fd: OptionFd, + bus_handles: BusHandles, + exit_code: ExitCode, + bus_event_exit: BusEventExit, + bus_event_fault: BusEventFault, + bus_event_close: BusEventClose, + prestat_u_dir: PrestatUDir, + prestat_u: PrestatU, + event_fd_flags: EventFdFlags, + prestat: Prestat, + file_delta: FileDelta, + lookup_flags: LookupFlags, +) -> () { + unsafe { + let ptr0 = OUTPUT_RET_AREA.0.as_mut_ptr() as i32; + *((ptr0 + 0) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd); + let Dirent { + d_next: d_next1, + d_ino: d_ino1, + d_type: d_type1, + d_namlen: d_namlen1, + } = dirent; + *((ptr0 + 8) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_next1); + *((ptr0 + 16) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_ino1); + *((ptr0 + 24) as *mut u8) = (match d_type1 { + Filetype::Unknown => 0, + Filetype::BlockDevice => 1, + Filetype::CharacterDevice => 2, + Filetype::Directory => 3, + Filetype::RegularFile => 4, + Filetype::SocketDgram => 5, + Filetype::SocketStream => 6, + Filetype::SymbolicLink => 7, + Filetype::Fifo => 8, + }) as u8; + *((ptr0 + 28) as *mut i32) = wit_bindgen_rust::rt::as_i32(d_namlen1); + let Snapshot0Dirent { + d_next: d_next2, + d_ino: d_ino2, + d_namlen: d_namlen2, + d_type: d_type2, + } = snapshot0_dirent; + *((ptr0 + 32) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_next2); + *((ptr0 + 40) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_ino2); + *((ptr0 + 48) as *mut i32) = wit_bindgen_rust::rt::as_i32(d_namlen2); + *((ptr0 + 52) as *mut u8) = (match d_type2 { + Filetype::Unknown => 0, + Filetype::BlockDevice => 1, + Filetype::CharacterDevice => 2, + Filetype::Directory => 3, + Filetype::RegularFile => 4, + Filetype::SocketDgram => 5, + Filetype::SocketStream => 6, + Filetype::SymbolicLink => 7, + Filetype::Fifo => 8, + }) as u8; + let Snapshot0Event { + userdata: userdata3, + error: error3, + type_: type_3, + fd_readwrite: fd_readwrite3, + } = snapshot0_event; + *((ptr0 + 56) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata3); + *((ptr0 + 64) as *mut u8) = (match error3 { + Errno::Success => 0, + Errno::Toobig => 1, + Errno::Access => 2, + Errno::Addrinuse => 3, + Errno::Addrnotavail => 4, + Errno::Afnosupport => 5, + Errno::Again => 6, + Errno::Already => 7, + Errno::Badf => 8, + Errno::Badmsg => 9, + Errno::Busy => 10, + Errno::Canceled => 11, + Errno::Child => 12, + Errno::Connaborted => 13, + Errno::Connrefused => 14, + Errno::Connreset => 15, + Errno::Deadlk => 16, + Errno::Destaddrreq => 17, + Errno::Dom => 18, + Errno::Dquot => 19, + Errno::Exist => 20, + Errno::Fault => 21, + Errno::Fbig => 22, + Errno::Hostunreach => 23, + Errno::Idrm => 24, + Errno::Ilseq => 25, + Errno::Inprogress => 26, + Errno::Intr => 27, + Errno::Inval => 28, + Errno::Io => 29, + Errno::Isconn => 30, + Errno::Isdir => 31, + Errno::Loop => 32, + Errno::Mfile => 33, + Errno::Mlink => 34, + Errno::Msgsize => 35, + Errno::Multihop => 36, + Errno::Nametoolong => 37, + Errno::Netdown => 38, + Errno::Netreset => 39, + Errno::Netunreach => 40, + Errno::Nfile => 41, + Errno::Nobufs => 42, + Errno::Nodev => 43, + Errno::Noent => 44, + Errno::Noexec => 45, + Errno::Nolck => 46, + Errno::Nolink => 47, + Errno::Nomem => 48, + Errno::Nomsg => 49, + Errno::Noprotoopt => 50, + Errno::Nospc => 51, + Errno::Nosys => 52, + Errno::Notconn => 53, + Errno::Notdir => 54, + Errno::Notempty => 55, + Errno::Notrecoverable => 56, + Errno::Notsock => 57, + Errno::Notsup => 58, + Errno::Notty => 59, + Errno::Nxio => 60, + Errno::Overflow => 61, + Errno::Ownerdead => 62, + Errno::Perm => 63, + Errno::Pipe => 64, + Errno::Proto => 65, + Errno::Protonosupport => 66, + Errno::Prototype => 67, + Errno::Range => 68, + Errno::Rofs => 69, + Errno::Spipe => 70, + Errno::Srch => 71, + Errno::Stale => 72, + Errno::Timedout => 73, + Errno::Txtbsy => 74, + Errno::Xdev => 75, + Errno::Notcapable => 76, + }) as u8; + *((ptr0 + 65) as *mut u8) = (match type_3 { + Eventtype::Clock => 0, + Eventtype::FdRead => 1, + Eventtype::FdWrite => 2, + }) as u8; + let EventFdReadwrite { + nbytes: nbytes4, + flags: flags4, + } = fd_readwrite3; + *((ptr0 + 72) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes4); + let flags5 = flags4; + *((ptr0 + 80) as *mut u8) = ((flags5.bits() >> 0) as i32) as u8; + match event_enum { + EventEnum::FdRead(e) => { + *((ptr0 + 88) as *mut u8) = (0i32) as u8; + let EventFdReadwrite { + nbytes: nbytes6, + flags: flags6, + } = e; + *((ptr0 + 96) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes6); + let flags7 = flags6; + *((ptr0 + 104) as *mut u8) = ((flags7.bits() >> 0) as i32) as u8; + } + EventEnum::FdWrite(e) => { + *((ptr0 + 88) as *mut u8) = (1i32) as u8; + let EventFdReadwrite { + nbytes: nbytes8, + flags: flags8, + } = e; + *((ptr0 + 96) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes8); + let flags9 = flags8; + *((ptr0 + 104) as *mut u8) = ((flags9.bits() >> 0) as i32) as u8; + } + EventEnum::Clock => { + let e = (); + { + *((ptr0 + 88) as *mut u8) = (2i32) as u8; + let () = e; + } + } + }; + let Event { + userdata: userdata10, + error: error10, + data: data10, + } = event; + *((ptr0 + 112) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata10); + *((ptr0 + 120) as *mut u8) = (match error10 { + Errno::Success => 0, + Errno::Toobig => 1, + Errno::Access => 2, + Errno::Addrinuse => 3, + Errno::Addrnotavail => 4, + Errno::Afnosupport => 5, + Errno::Again => 6, + Errno::Already => 7, + Errno::Badf => 8, + Errno::Badmsg => 9, + Errno::Busy => 10, + Errno::Canceled => 11, + Errno::Child => 12, + Errno::Connaborted => 13, + Errno::Connrefused => 14, + Errno::Connreset => 15, + Errno::Deadlk => 16, + Errno::Destaddrreq => 17, + Errno::Dom => 18, + Errno::Dquot => 19, + Errno::Exist => 20, + Errno::Fault => 21, + Errno::Fbig => 22, + Errno::Hostunreach => 23, + Errno::Idrm => 24, + Errno::Ilseq => 25, + Errno::Inprogress => 26, + Errno::Intr => 27, + Errno::Inval => 28, + Errno::Io => 29, + Errno::Isconn => 30, + Errno::Isdir => 31, + Errno::Loop => 32, + Errno::Mfile => 33, + Errno::Mlink => 34, + Errno::Msgsize => 35, + Errno::Multihop => 36, + Errno::Nametoolong => 37, + Errno::Netdown => 38, + Errno::Netreset => 39, + Errno::Netunreach => 40, + Errno::Nfile => 41, + Errno::Nobufs => 42, + Errno::Nodev => 43, + Errno::Noent => 44, + Errno::Noexec => 45, + Errno::Nolck => 46, + Errno::Nolink => 47, + Errno::Nomem => 48, + Errno::Nomsg => 49, + Errno::Noprotoopt => 50, + Errno::Nospc => 51, + Errno::Nosys => 52, + Errno::Notconn => 53, + Errno::Notdir => 54, + Errno::Notempty => 55, + Errno::Notrecoverable => 56, + Errno::Notsock => 57, + Errno::Notsup => 58, + Errno::Notty => 59, + Errno::Nxio => 60, + Errno::Overflow => 61, + Errno::Ownerdead => 62, + Errno::Perm => 63, + Errno::Pipe => 64, + Errno::Proto => 65, + Errno::Protonosupport => 66, + Errno::Prototype => 67, + Errno::Range => 68, + Errno::Rofs => 69, + Errno::Spipe => 70, + Errno::Srch => 71, + Errno::Stale => 72, + Errno::Timedout => 73, + Errno::Txtbsy => 74, + Errno::Xdev => 75, + Errno::Notcapable => 76, + }) as u8; + match data10 { + EventEnum::FdRead(e) => { + *((ptr0 + 128) as *mut u8) = (0i32) as u8; + let EventFdReadwrite { + nbytes: nbytes11, + flags: flags11, + } = e; + *((ptr0 + 136) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes11); + let flags12 = flags11; + *((ptr0 + 144) as *mut u8) = ((flags12.bits() >> 0) as i32) as u8; + } + EventEnum::FdWrite(e) => { + *((ptr0 + 128) as *mut u8) = (1i32) as u8; + let EventFdReadwrite { + nbytes: nbytes13, + flags: flags13, + } = e; + *((ptr0 + 136) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes13); + let flags14 = flags13; + *((ptr0 + 144) as *mut u8) = ((flags14.bits() >> 0) as i32) as u8; + } + EventEnum::Clock => { + let e = (); + { + *((ptr0 + 128) as *mut u8) = (2i32) as u8; + let () = e; + } + } + }; + let Fdstat { + fs_filetype: fs_filetype15, + fs_flags: fs_flags15, + fs_rights_base: fs_rights_base15, + fs_rights_inheriting: fs_rights_inheriting15, + } = fdstat; + *((ptr0 + 152) as *mut u8) = (match fs_filetype15 { + Filetype::Unknown => 0, + Filetype::BlockDevice => 1, + Filetype::CharacterDevice => 2, + Filetype::Directory => 3, + Filetype::RegularFile => 4, + Filetype::SocketDgram => 5, + Filetype::SocketStream => 6, + Filetype::SymbolicLink => 7, + Filetype::Fifo => 8, + }) as u8; + let flags16 = fs_flags15; + *((ptr0 + 153) as *mut u8) = ((flags16.bits() >> 0) as i32) as u8; + let flags17 = fs_rights_base15; + *((ptr0 + 160) as *mut i32) = (flags17.bits() >> 32) as i32; + *((ptr0 + 156) as *mut i32) = (flags17.bits() >> 0) as i32; + let flags18 = fs_rights_inheriting15; + *((ptr0 + 168) as *mut i32) = (flags18.bits() >> 32) as i32; + *((ptr0 + 164) as *mut i32) = (flags18.bits() >> 0) as i32; + let SubscriptionClock { + clock_id: clock_id19, + timeout: timeout19, + precision: precision19, + flags: flags19, + } = subscription_clock; + *((ptr0 + 176) as *mut u8) = (match clock_id19 { + Clockid::Realtime => 0, + Clockid::Monotonic => 1, + }) as u8; + *((ptr0 + 184) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout19); + *((ptr0 + 192) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision19); + let flags20 = flags19; + *((ptr0 + 200) as *mut u8) = ((flags20.bits() >> 0) as i32) as u8; + let Snapshot0SubscriptionClock { + identifier: identifier21, + id: id21, + timeout: timeout21, + precision: precision21, + flags: flags21, + } = snapshot0_subscription_clock; + *((ptr0 + 208) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier21); + *((ptr0 + 216) as *mut u8) = (match id21 { + Snapshot0Clockid::Realtime => 0, + Snapshot0Clockid::Monotonic => 1, + Snapshot0Clockid::ProcessCputimeId => 2, + Snapshot0Clockid::ThreadCputimeId => 3, + }) as u8; + *((ptr0 + 224) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout21); + *((ptr0 + 232) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision21); + let flags22 = flags21; + *((ptr0 + 240) as *mut u8) = ((flags22.bits() >> 0) as i32) as u8; + let Subscription { + userdata: userdata23, + data: data23, + } = subscription; + *((ptr0 + 248) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata23); + match data23 { + SubscriptionEnum::Clock(e) => { + *((ptr0 + 256) as *mut u8) = (0i32) as u8; + let SubscriptionClock { + clock_id: clock_id24, + timeout: timeout24, + precision: precision24, + flags: flags24, + } = e; + *((ptr0 + 264) as *mut u8) = (match clock_id24 { + Clockid::Realtime => 0, + Clockid::Monotonic => 1, + }) as u8; + *((ptr0 + 272) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout24); + *((ptr0 + 280) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision24); + let flags25 = flags24; + *((ptr0 + 288) as *mut u8) = ((flags25.bits() >> 0) as i32) as u8; + } + SubscriptionEnum::Read(e) => { + *((ptr0 + 256) as *mut u8) = (1i32) as u8; + let SubscriptionFsReadwrite { + file_descriptor: file_descriptor26, + } = e; + *((ptr0 + 264) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor26); + } + SubscriptionEnum::Write(e) => { + *((ptr0 + 256) as *mut u8) = (2i32) as u8; + let SubscriptionFsReadwrite { + file_descriptor: file_descriptor27, + } = e; + *((ptr0 + 264) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor27); + } + }; + let Snapshot0Subscription { + userdata: userdata28, + data: data28, + } = snapshot0_subscription; + *((ptr0 + 296) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata28); + match data28 { + Snapshot0SubscriptionEnum::Clock(e) => { + *((ptr0 + 304) as *mut u8) = (0i32) as u8; + let Snapshot0SubscriptionClock { + identifier: identifier29, + id: id29, + timeout: timeout29, + precision: precision29, + flags: flags29, + } = e; + *((ptr0 + 312) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier29); + *((ptr0 + 320) as *mut u8) = (match id29 { + Snapshot0Clockid::Realtime => 0, + Snapshot0Clockid::Monotonic => 1, + Snapshot0Clockid::ProcessCputimeId => 2, + Snapshot0Clockid::ThreadCputimeId => 3, + }) as u8; + *((ptr0 + 328) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout29); + *((ptr0 + 336) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision29); + let flags30 = flags29; + *((ptr0 + 344) as *mut u8) = ((flags30.bits() >> 0) as i32) as u8; + } + Snapshot0SubscriptionEnum::Read(e) => { + *((ptr0 + 304) as *mut u8) = (1i32) as u8; + let SubscriptionFsReadwrite { + file_descriptor: file_descriptor31, + } = e; + *((ptr0 + 312) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor31); + } + Snapshot0SubscriptionEnum::Write(e) => { + *((ptr0 + 304) as *mut u8) = (2i32) as u8; + let SubscriptionFsReadwrite { + file_descriptor: file_descriptor32, + } = e; + *((ptr0 + 312) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor32); + } + }; + *((ptr0 + 352) as *mut i64) = wit_bindgen_rust::rt::as_i64(device); + *((ptr0 + 360) as *mut i64) = wit_bindgen_rust::rt::as_i64(linkcount); + *((ptr0 + 368) as *mut i32) = wit_bindgen_rust::rt::as_i32(snapshot0_linkcount); + let Filestat { + st_dev: st_dev33, + st_ino: st_ino33, + st_filetype: st_filetype33, + st_nlink: st_nlink33, + st_size: st_size33, + st_atim: st_atim33, + st_mtim: st_mtim33, + st_ctim: st_ctim33, + } = filestat; + *((ptr0 + 376) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev33); + *((ptr0 + 384) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino33); + *((ptr0 + 392) as *mut u8) = (match st_filetype33 { + Filetype::Unknown => 0, + Filetype::BlockDevice => 1, + Filetype::CharacterDevice => 2, + Filetype::Directory => 3, + Filetype::RegularFile => 4, + Filetype::SocketDgram => 5, + Filetype::SocketStream => 6, + Filetype::SymbolicLink => 7, + Filetype::Fifo => 8, + }) as u8; + *((ptr0 + 400) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_nlink33); + *((ptr0 + 408) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size33); + *((ptr0 + 416) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim33); + *((ptr0 + 424) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim33); + *((ptr0 + 432) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim33); + let Snapshot0Filestat { + st_dev: st_dev34, + st_ino: st_ino34, + st_filetype: st_filetype34, + st_nlink: st_nlink34, + st_size: st_size34, + st_atim: st_atim34, + st_mtim: st_mtim34, + st_ctim: st_ctim34, + } = snapshot0_filestat; + *((ptr0 + 440) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev34); + *((ptr0 + 448) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino34); + *((ptr0 + 456) as *mut u8) = (match st_filetype34 { + Filetype::Unknown => 0, + Filetype::BlockDevice => 1, + Filetype::CharacterDevice => 2, + Filetype::Directory => 3, + Filetype::RegularFile => 4, + Filetype::SocketDgram => 5, + Filetype::SocketStream => 6, + Filetype::SymbolicLink => 7, + Filetype::Fifo => 8, + }) as u8; + *((ptr0 + 460) as *mut i32) = wit_bindgen_rust::rt::as_i32(st_nlink34); + *((ptr0 + 464) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size34); + *((ptr0 + 472) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim34); + *((ptr0 + 480) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim34); + *((ptr0 + 488) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim34); + let Tty { + cols: cols35, + rows: rows35, + width: width35, + height: height35, + stdin_tty: stdin_tty35, + stdout_tty: stdout_tty35, + stderr_tty: stderr_tty35, + echo: echo35, + line_buffered: line_buffered35, + } = tty; + *((ptr0 + 496) as *mut i32) = wit_bindgen_rust::rt::as_i32(cols35); + *((ptr0 + 500) as *mut i32) = wit_bindgen_rust::rt::as_i32(rows35); + *((ptr0 + 504) as *mut i32) = wit_bindgen_rust::rt::as_i32(width35); + *((ptr0 + 508) as *mut i32) = wit_bindgen_rust::rt::as_i32(height35); + *((ptr0 + 512) as *mut u8) = (match stdin_tty35 { + true => 1, + false => 0, + }) as u8; + *((ptr0 + 513) as *mut u8) = (match stdout_tty35 { + true => 1, + false => 0, + }) as u8; + *((ptr0 + 514) as *mut u8) = (match stderr_tty35 { + true => 1, + false => 0, + }) as u8; + *((ptr0 + 515) as *mut u8) = (match echo35 { + true => 1, + false => 0, + }) as u8; + *((ptr0 + 516) as *mut u8) = (match line_buffered35 { + true => 1, + false => 0, + }) as u8; + *((ptr0 + 520) as *mut i32) = wit_bindgen_rust::rt::as_i32(tid); + *((ptr0 + 524) as *mut i32) = wit_bindgen_rust::rt::as_i32(pid); + *((ptr0 + 528) as *mut u8) = (match bus_data_format { + BusDataFormat::Raw => 0, + BusDataFormat::Bincode => 1, + BusDataFormat::MessagePack => 2, + BusDataFormat::Json => 3, + BusDataFormat::Yaml => 4, + BusDataFormat::Xml => 5, + BusDataFormat::Rkyv => 6, + }) as u8; + *((ptr0 + 532) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid); + let OptionBid { + tag: tag36, + bid: bid36, + } = option_bid; + *((ptr0 + 536) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag36)) as u8; + *((ptr0 + 540) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid36); + *((ptr0 + 544) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid); + let OptionCid { + tag: tag37, + cid: cid37, + } = option_cid; + *((ptr0 + 548) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag37)) as u8; + *((ptr0 + 552) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid37); + let OptionFd { + tag: tag38, + fd: fd38, + } = option_fd; + *((ptr0 + 556) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag38)) as u8; + *((ptr0 + 560) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd38); + let BusHandles { + bid: bid39, + stdin: stdin39, + stdout: stdout39, + stderr: stderr39, + } = bus_handles; + *((ptr0 + 564) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid39); + let OptionFd { + tag: tag40, + fd: fd40, + } = stdin39; + *((ptr0 + 568) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag40)) as u8; + *((ptr0 + 572) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd40); + let OptionFd { + tag: tag41, + fd: fd41, + } = stdout39; + *((ptr0 + 576) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag41)) as u8; + *((ptr0 + 580) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd41); + let OptionFd { + tag: tag42, + fd: fd42, + } = stderr39; + *((ptr0 + 584) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag42)) as u8; + *((ptr0 + 588) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd42); + *((ptr0 + 592) as *mut i32) = wit_bindgen_rust::rt::as_i32(exit_code); + let BusEventExit { + bid: bid43, + rval: rval43, + } = bus_event_exit; + *((ptr0 + 596) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid43); + *((ptr0 + 600) as *mut i32) = wit_bindgen_rust::rt::as_i32(rval43); + let BusEventFault { + cid: cid44, + err: err44, + } = bus_event_fault; + *((ptr0 + 604) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid44); + *((ptr0 + 608) as *mut u8) = (match err44 { + BusErrno::Success => 0, + BusErrno::Ser => 1, + BusErrno::Des => 2, + BusErrno::Wapm => 3, + BusErrno::Fetch => 4, + BusErrno::Compile => 5, + BusErrno::Abi => 6, + BusErrno::Aborted => 7, + BusErrno::Badhandle => 8, + BusErrno::Topic => 9, + BusErrno::Badcb => 10, + BusErrno::Unsupported => 11, + BusErrno::Badrequest => 12, + BusErrno::Denied => 13, + BusErrno::Internal => 14, + BusErrno::Alloc => 15, + BusErrno::Invoke => 16, + BusErrno::Consumed => 17, + BusErrno::Memviolation => 18, + BusErrno::Unknown => 19, + }) as u8; + let BusEventClose { cid: cid45 } = bus_event_close; + *((ptr0 + 612) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid45); + let PrestatUDir { + pr_name_len: pr_name_len46, + } = prestat_u_dir; + *((ptr0 + 616) as *mut i32) = wit_bindgen_rust::rt::as_i32(pr_name_len46); + let PrestatU { dir: dir47 } = prestat_u; + let PrestatUDir { + pr_name_len: pr_name_len48, + } = dir47; + *((ptr0 + 620) as *mut i32) = wit_bindgen_rust::rt::as_i32(pr_name_len48); + *((ptr0 + 624) as *mut u16) = (wit_bindgen_rust::rt::as_i32(event_fd_flags)) as u16; + let Prestat { + pr_type: pr_type49, + u: u49, + } = prestat; + *((ptr0 + 628) as *mut u8) = (match pr_type49 { + Preopentype::Dir => 0, + }) as u8; + let PrestatU { dir: dir50 } = u49; + let PrestatUDir { + pr_name_len: pr_name_len51, + } = dir50; + *((ptr0 + 632) as *mut i32) = wit_bindgen_rust::rt::as_i32(pr_name_len51); + *((ptr0 + 640) as *mut i64) = wit_bindgen_rust::rt::as_i64(file_delta); + *((ptr0 + 648) as *mut i32) = wit_bindgen_rust::rt::as_i32(lookup_flags); + #[link(wasm_import_module = "output")] + extern "C" { + #[cfg_attr(target_arch = "wasm32", link_name = "expose-types-dummy-func")] + #[cfg_attr( + not(target_arch = "wasm32"), + link_name = "output_expose-types-dummy-func" + )] + fn wit_import(_: i32); + } + wit_import(ptr0); + () + } } - }; - let Event{ userdata:userdata10, error:error10, data:data10, } = event; - *((ptr0 + 112) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata10); - *((ptr0 + 120) as *mut u8) = (match error10 { -Errno::Success => 0, -Errno::Toobig => 1, -Errno::Access => 2, -Errno::Addrinuse => 3, -Errno::Addrnotavail => 4, -Errno::Afnosupport => 5, -Errno::Again => 6, -Errno::Already => 7, -Errno::Badf => 8, -Errno::Badmsg => 9, -Errno::Busy => 10, -Errno::Canceled => 11, -Errno::Child => 12, -Errno::Connaborted => 13, -Errno::Connrefused => 14, -Errno::Connreset => 15, -Errno::Deadlk => 16, -Errno::Destaddrreq => 17, -Errno::Dom => 18, -Errno::Dquot => 19, -Errno::Exist => 20, -Errno::Fault => 21, -Errno::Fbig => 22, -Errno::Hostunreach => 23, -Errno::Idrm => 24, -Errno::Ilseq => 25, -Errno::Inprogress => 26, -Errno::Intr => 27, -Errno::Inval => 28, -Errno::Io => 29, -Errno::Isconn => 30, -Errno::Isdir => 31, -Errno::Loop => 32, -Errno::Mfile => 33, -Errno::Mlink => 34, -Errno::Msgsize => 35, -Errno::Multihop => 36, -Errno::Nametoolong => 37, -Errno::Netdown => 38, -Errno::Netreset => 39, -Errno::Netunreach => 40, -Errno::Nfile => 41, -Errno::Nobufs => 42, -Errno::Nodev => 43, -Errno::Noent => 44, -Errno::Noexec => 45, -Errno::Nolck => 46, -Errno::Nolink => 47, -Errno::Nomem => 48, -Errno::Nomsg => 49, -Errno::Noprotoopt => 50, -Errno::Nospc => 51, -Errno::Nosys => 52, -Errno::Notconn => 53, -Errno::Notdir => 54, -Errno::Notempty => 55, -Errno::Notrecoverable => 56, -Errno::Notsock => 57, -Errno::Notsup => 58, -Errno::Notty => 59, -Errno::Nxio => 60, -Errno::Overflow => 61, -Errno::Ownerdead => 62, -Errno::Perm => 63, -Errno::Pipe => 64, -Errno::Proto => 65, -Errno::Protonosupport => 66, -Errno::Prototype => 67, -Errno::Range => 68, -Errno::Rofs => 69, -Errno::Spipe => 70, -Errno::Srch => 71, -Errno::Stale => 72, -Errno::Timedout => 73, -Errno::Txtbsy => 74, -Errno::Xdev => 75, -Errno::Notcapable => 76, - }) as u8; - match data10 { -EventEnum::FdRead(e) => { - *((ptr0 + 128) as *mut u8) = (0i32) as u8; - let EventFdReadwrite{ nbytes:nbytes11, flags:flags11, } = e; - *((ptr0 + 136) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes11); - let flags12 = flags11; - *((ptr0 + 144) as *mut u8) = ((flags12.bits() >> 0) as i32) as u8; - -}, -EventEnum::FdWrite(e) => { - *((ptr0 + 128) as *mut u8) = (1i32) as u8; - let EventFdReadwrite{ nbytes:nbytes13, flags:flags13, } = e; - *((ptr0 + 136) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes13); - let flags14 = flags13; - *((ptr0 + 144) as *mut u8) = ((flags14.bits() >> 0) as i32) as u8; - -}, -EventEnum::Clock=> { - let e = (); - { -*((ptr0 + 128) as *mut u8) = (2i32) as u8; -let () = e; - } -} - }; - let Fdstat{ fs_filetype:fs_filetype15, fs_flags:fs_flags15, fs_rights_base:fs_rights_base15, fs_rights_inheriting:fs_rights_inheriting15, } = fdstat; - *((ptr0 + 152) as *mut u8) = (match fs_filetype15 { -Filetype::Unknown => 0, -Filetype::BlockDevice => 1, -Filetype::CharacterDevice => 2, -Filetype::Directory => 3, -Filetype::RegularFile => 4, -Filetype::SocketDgram => 5, -Filetype::SocketStream => 6, -Filetype::SymbolicLink => 7, -Filetype::Fifo => 8, - }) as u8; - let flags16 = fs_flags15; - *((ptr0 + 153) as *mut u8) = ((flags16.bits() >> 0) as i32) as u8; - let flags17 = fs_rights_base15; - *((ptr0 + 160) as *mut i32) = (flags17.bits() >> 32) as i32; - *((ptr0 + 156) as *mut i32) = (flags17.bits() >> 0) as i32; - let flags18 = fs_rights_inheriting15; - *((ptr0 + 168) as *mut i32) = (flags18.bits() >> 32) as i32; - *((ptr0 + 164) as *mut i32) = (flags18.bits() >> 0) as i32; - let SubscriptionClock{ clock_id:clock_id19, timeout:timeout19, precision:precision19, flags:flags19, } = subscription_clock; - *((ptr0 + 176) as *mut u8) = (match clock_id19 { -Clockid::Realtime => 0, -Clockid::Monotonic => 1, - }) as u8; - *((ptr0 + 184) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout19); - *((ptr0 + 192) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision19); - let flags20 = flags19; - *((ptr0 + 200) as *mut u8) = ((flags20.bits() >> 0) as i32) as u8; - let Snapshot0SubscriptionClock{ identifier:identifier21, id:id21, timeout:timeout21, precision:precision21, flags:flags21, } = snapshot0_subscription_clock; - *((ptr0 + 208) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier21); - *((ptr0 + 216) as *mut u8) = (match id21 { -Snapshot0Clockid::Realtime => 0, -Snapshot0Clockid::Monotonic => 1, -Snapshot0Clockid::ProcessCputimeId => 2, -Snapshot0Clockid::ThreadCputimeId => 3, - }) as u8; - *((ptr0 + 224) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout21); - *((ptr0 + 232) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision21); - let flags22 = flags21; - *((ptr0 + 240) as *mut u8) = ((flags22.bits() >> 0) as i32) as u8; - let Subscription{ userdata:userdata23, data:data23, } = subscription; - *((ptr0 + 248) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata23); - match data23 { -SubscriptionEnum::Clock(e) => { - *((ptr0 + 256) as *mut u8) = (0i32) as u8; - let SubscriptionClock{ clock_id:clock_id24, timeout:timeout24, precision:precision24, flags:flags24, } = e; - *((ptr0 + 264) as *mut u8) = (match clock_id24 { -Clockid::Realtime => 0, -Clockid::Monotonic => 1, - }) as u8; - *((ptr0 + 272) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout24); - *((ptr0 + 280) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision24); - let flags25 = flags24; - *((ptr0 + 288) as *mut u8) = ((flags25.bits() >> 0) as i32) as u8; - -}, -SubscriptionEnum::Read(e) => { - *((ptr0 + 256) as *mut u8) = (1i32) as u8; - let SubscriptionFsReadwrite{ file_descriptor:file_descriptor26, } = e; - *((ptr0 + 264) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor26); - -}, -SubscriptionEnum::Write(e) => { - *((ptr0 + 256) as *mut u8) = (2i32) as u8; - let SubscriptionFsReadwrite{ file_descriptor:file_descriptor27, } = e; - *((ptr0 + 264) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor27); - -}, - }; - let Snapshot0Subscription{ userdata:userdata28, data:data28, } = snapshot0_subscription; - *((ptr0 + 296) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata28); - match data28 { -Snapshot0SubscriptionEnum::Clock(e) => { - *((ptr0 + 304) as *mut u8) = (0i32) as u8; - let Snapshot0SubscriptionClock{ identifier:identifier29, id:id29, timeout:timeout29, precision:precision29, flags:flags29, } = e; - *((ptr0 + 312) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier29); - *((ptr0 + 320) as *mut u8) = (match id29 { -Snapshot0Clockid::Realtime => 0, -Snapshot0Clockid::Monotonic => 1, -Snapshot0Clockid::ProcessCputimeId => 2, -Snapshot0Clockid::ThreadCputimeId => 3, - }) as u8; - *((ptr0 + 328) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout29); - *((ptr0 + 336) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision29); - let flags30 = flags29; - *((ptr0 + 344) as *mut u8) = ((flags30.bits() >> 0) as i32) as u8; - -}, -Snapshot0SubscriptionEnum::Read(e) => { - *((ptr0 + 304) as *mut u8) = (1i32) as u8; - let SubscriptionFsReadwrite{ file_descriptor:file_descriptor31, } = e; - *((ptr0 + 312) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor31); - -}, -Snapshot0SubscriptionEnum::Write(e) => { - *((ptr0 + 304) as *mut u8) = (2i32) as u8; - let SubscriptionFsReadwrite{ file_descriptor:file_descriptor32, } = e; - *((ptr0 + 312) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor32); - -}, - }; - *((ptr0 + 352) as *mut i64) = wit_bindgen_rust::rt::as_i64(device); - *((ptr0 + 360) as *mut i64) = wit_bindgen_rust::rt::as_i64(linkcount); - *((ptr0 + 368) as *mut i32) = wit_bindgen_rust::rt::as_i32(snapshot0_linkcount); - let Filestat{ st_dev:st_dev33, st_ino:st_ino33, st_filetype:st_filetype33, st_nlink:st_nlink33, st_size:st_size33, st_atim:st_atim33, st_mtim:st_mtim33, st_ctim:st_ctim33, } = filestat; - *((ptr0 + 376) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev33); - *((ptr0 + 384) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino33); - *((ptr0 + 392) as *mut u8) = (match st_filetype33 { -Filetype::Unknown => 0, -Filetype::BlockDevice => 1, -Filetype::CharacterDevice => 2, -Filetype::Directory => 3, -Filetype::RegularFile => 4, -Filetype::SocketDgram => 5, -Filetype::SocketStream => 6, -Filetype::SymbolicLink => 7, -Filetype::Fifo => 8, - }) as u8; - *((ptr0 + 400) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_nlink33); - *((ptr0 + 408) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size33); - *((ptr0 + 416) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim33); - *((ptr0 + 424) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim33); - *((ptr0 + 432) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim33); - let Snapshot0Filestat{ st_dev:st_dev34, st_ino:st_ino34, st_filetype:st_filetype34, st_nlink:st_nlink34, st_size:st_size34, st_atim:st_atim34, st_mtim:st_mtim34, st_ctim:st_ctim34, } = snapshot0_filestat; - *((ptr0 + 440) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev34); - *((ptr0 + 448) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino34); - *((ptr0 + 456) as *mut u8) = (match st_filetype34 { -Filetype::Unknown => 0, -Filetype::BlockDevice => 1, -Filetype::CharacterDevice => 2, -Filetype::Directory => 3, -Filetype::RegularFile => 4, -Filetype::SocketDgram => 5, -Filetype::SocketStream => 6, -Filetype::SymbolicLink => 7, -Filetype::Fifo => 8, - }) as u8; - *((ptr0 + 460) as *mut i32) = wit_bindgen_rust::rt::as_i32(st_nlink34); - *((ptr0 + 464) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size34); - *((ptr0 + 472) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim34); - *((ptr0 + 480) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim34); - *((ptr0 + 488) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim34); - let Tty{ cols:cols35, rows:rows35, width:width35, height:height35, stdin_tty:stdin_tty35, stdout_tty:stdout_tty35, stderr_tty:stderr_tty35, echo:echo35, line_buffered:line_buffered35, } = tty; - *((ptr0 + 496) as *mut i32) = wit_bindgen_rust::rt::as_i32(cols35); - *((ptr0 + 500) as *mut i32) = wit_bindgen_rust::rt::as_i32(rows35); - *((ptr0 + 504) as *mut i32) = wit_bindgen_rust::rt::as_i32(width35); - *((ptr0 + 508) as *mut i32) = wit_bindgen_rust::rt::as_i32(height35); - *((ptr0 + 512) as *mut u8) = (match stdin_tty35 { true => 1, false => 0 }) as u8; - *((ptr0 + 513) as *mut u8) = (match stdout_tty35 { true => 1, false => 0 }) as u8; - *((ptr0 + 514) as *mut u8) = (match stderr_tty35 { true => 1, false => 0 }) as u8; - *((ptr0 + 515) as *mut u8) = (match echo35 { true => 1, false => 0 }) as u8; - *((ptr0 + 516) as *mut u8) = (match line_buffered35 { true => 1, false => 0 }) as u8; - *((ptr0 + 520) as *mut i32) = wit_bindgen_rust::rt::as_i32(tid); - *((ptr0 + 524) as *mut i32) = wit_bindgen_rust::rt::as_i32(pid); - *((ptr0 + 528) as *mut u8) = (match bus_data_format { -BusDataFormat::Raw => 0, -BusDataFormat::Bincode => 1, -BusDataFormat::MessagePack => 2, -BusDataFormat::Json => 3, -BusDataFormat::Yaml => 4, -BusDataFormat::Xml => 5, -BusDataFormat::Rkyv => 6, - }) as u8; - *((ptr0 + 532) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid); - let OptionBid{ tag:tag36, bid:bid36, } = option_bid; - *((ptr0 + 536) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag36)) as u8; - *((ptr0 + 540) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid36); - *((ptr0 + 544) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid); - let OptionCid{ tag:tag37, cid:cid37, } = option_cid; - *((ptr0 + 548) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag37)) as u8; - *((ptr0 + 552) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid37); - let OptionFd{ tag:tag38, fd:fd38, } = option_fd; - *((ptr0 + 556) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag38)) as u8; - *((ptr0 + 560) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd38); - let BusHandles{ bid:bid39, stdin:stdin39, stdout:stdout39, stderr:stderr39, } = bus_handles; - *((ptr0 + 564) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid39); - let OptionFd{ tag:tag40, fd:fd40, } = stdin39; - *((ptr0 + 568) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag40)) as u8; - *((ptr0 + 572) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd40); - let OptionFd{ tag:tag41, fd:fd41, } = stdout39; - *((ptr0 + 576) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag41)) as u8; - *((ptr0 + 580) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd41); - let OptionFd{ tag:tag42, fd:fd42, } = stderr39; - *((ptr0 + 584) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag42)) as u8; - *((ptr0 + 588) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd42); - *((ptr0 + 592) as *mut i32) = wit_bindgen_rust::rt::as_i32(exit_code); - let BusEventExit{ bid:bid43, rval:rval43, } = bus_event_exit; - *((ptr0 + 596) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid43); - *((ptr0 + 600) as *mut i32) = wit_bindgen_rust::rt::as_i32(rval43); - let BusEventFault{ cid:cid44, err:err44, } = bus_event_fault; - *((ptr0 + 604) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid44); - *((ptr0 + 608) as *mut u8) = (match err44 { -BusErrno::Success => 0, -BusErrno::Ser => 1, -BusErrno::Des => 2, -BusErrno::Wapm => 3, -BusErrno::Fetch => 4, -BusErrno::Compile => 5, -BusErrno::Abi => 6, -BusErrno::Aborted => 7, -BusErrno::Badhandle => 8, -BusErrno::Topic => 9, -BusErrno::Badcb => 10, -BusErrno::Unsupported => 11, -BusErrno::Badrequest => 12, -BusErrno::Denied => 13, -BusErrno::Internal => 14, -BusErrno::Alloc => 15, -BusErrno::Invoke => 16, -BusErrno::Consumed => 17, -BusErrno::Memviolation => 18, -BusErrno::Unknown => 19, - }) as u8; - let BusEventClose{ cid:cid45, } = bus_event_close; - *((ptr0 + 612) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid45); - let PrestatUDir{ pr_name_len:pr_name_len46, } = prestat_u_dir; - *((ptr0 + 616) as *mut i32) = wit_bindgen_rust::rt::as_i32(pr_name_len46); - let PrestatU{ dir:dir47, } = prestat_u; - let PrestatUDir{ pr_name_len:pr_name_len48, } = dir47; - *((ptr0 + 620) as *mut i32) = wit_bindgen_rust::rt::as_i32(pr_name_len48); - *((ptr0 + 624) as *mut u16) = (wit_bindgen_rust::rt::as_i32(event_fd_flags)) as u16; - let Prestat{ pr_type:pr_type49, u:u49, } = prestat; - *((ptr0 + 628) as *mut u8) = (match pr_type49 { -Preopentype::Dir => 0, - }) as u8; - let PrestatU{ dir:dir50, } = u49; - let PrestatUDir{ pr_name_len:pr_name_len51, } = dir50; - *((ptr0 + 632) as *mut i32) = wit_bindgen_rust::rt::as_i32(pr_name_len51); - *((ptr0 + 640) as *mut i64) = wit_bindgen_rust::rt::as_i64(file_delta); - *((ptr0 + 648) as *mut i32) = wit_bindgen_rust::rt::as_i32(lookup_flags); - #[link(wasm_import_module = "output")] - extern "C" { -#[cfg_attr(target_arch = "wasm32", link_name = "expose-types-dummy-func")] -#[cfg_attr(not(target_arch = "wasm32"), link_name = "output_expose-types-dummy-func")] -fn wit_import(_: i32, ); - } - wit_import(ptr0); - () -} - } - - #[repr(align(8))] - struct RetArea([u8; 656]); - static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 656]); +#[repr(align(8))] +struct RetArea([u8; 656]); +static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 656]); - // TODO: if necessary, must be implemented in wit-bindgen unsafe impl ValueType for Snapshot0Clockid { #[inline] - fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Snapshot0Clockid { type Native = i32; @@ -2161,16 +2300,17 @@ unsafe impl wasmer::FromToNativeWasmType for Snapshot0Clockid { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Clockid { type Native = i32; @@ -2188,16 +2328,17 @@ unsafe impl wasmer::FromToNativeWasmType for Clockid { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Errno { type Native = i32; @@ -2290,16 +2431,17 @@ unsafe impl wasmer::FromToNativeWasmType for Errno { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for BusErrno { type Native = i32; @@ -2335,23 +2477,23 @@ unsafe impl wasmer::FromToNativeWasmType for BusErrno { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Filetype { type Native = i32; @@ -2376,30 +2518,29 @@ unsafe impl wasmer::FromToNativeWasmType for Filetype { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + 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]) { } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Advice { type Native = i32; @@ -2421,51 +2562,47 @@ unsafe impl wasmer::FromToNativeWasmType for Advice { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Eventtype { type Native = i32; @@ -2484,37 +2621,35 @@ unsafe impl wasmer::FromToNativeWasmType for Eventtype { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Preopentype { type Native = i32; @@ -2531,86 +2666,77 @@ unsafe impl wasmer::FromToNativeWasmType for Preopentype { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Socktype { type Native = i32; @@ -2630,16 +2756,17 @@ unsafe impl wasmer::FromToNativeWasmType for Socktype { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Sockstatus { type Native = i32; @@ -2659,16 +2786,17 @@ unsafe impl wasmer::FromToNativeWasmType for Sockstatus { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Sockoption { type Native = i32; @@ -2711,16 +2839,17 @@ unsafe impl wasmer::FromToNativeWasmType for Sockoption { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Streamsecurity { type Native = i32; @@ -2740,16 +2869,17 @@ unsafe impl wasmer::FromToNativeWasmType for Streamsecurity { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Addressfamily { type Native = i32; @@ -2769,30 +2899,29 @@ unsafe impl wasmer::FromToNativeWasmType for Addressfamily { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + 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]) { } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Snapshot0Whence { type Native = i32; @@ -2811,16 +2940,17 @@ unsafe impl wasmer::FromToNativeWasmType for Snapshot0Whence { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for Whence { type Native = i32; @@ -2839,23 +2969,23 @@ unsafe impl wasmer::FromToNativeWasmType for Whence { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for BusDataFormat { type Native = i32; @@ -2878,16 +3008,17 @@ unsafe impl wasmer::FromToNativeWasmType for BusDataFormat { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - unsafe impl wasmer::FromToNativeWasmType for BusEventType { type Native = i32; @@ -2909,69 +3040,61 @@ unsafe impl wasmer::FromToNativeWasmType for BusEventType { } #[cfg(feature = "sys")] - fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + 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]) { } + fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit]) {} } - - \ No newline at end of file diff --git a/lib/wasi-types-generated/src/wasi/extra_manual.rs b/lib/wasi-types-generated/src/wasi/extra_manual.rs index f654d98609d..7ab4740e430 100644 --- a/lib/wasi-types-generated/src/wasi/extra_manual.rs +++ b/lib/wasi-types-generated/src/wasi/extra_manual.rs @@ -253,7 +253,6 @@ unsafe impl wasmer::FromToNativeWasmType for Oflags { } } - impl PartialEq for OptionCid { fn eq(&self, other: &Self) -> bool { self.tag == other.tag && self.cid == other.cid From e3188779120d3797ea2e225f5f86289e39223c03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 8 Sep 2022 14:16:44 +0200 Subject: [PATCH 55/84] Start porting "net" to wit --- lib/wasi-types-generated/src/wasi/bindings.rs | 1477 ++++++++++++++- lib/wasi-types-generated/src/wasi/extra.rs | 1639 ++++++++++++++++- lib/wasi-types-generated/wit-clean/output.wit | 304 ++- .../wit-clean/typenames.wit | 303 ++- lib/wasi-types/src/lib.rs | 319 +--- lib/wasi/src/state/socket.rs | 32 +- lib/wasi/src/syscalls/mod.rs | 103 +- lib/wasi/src/syscalls/wasix32.rs | 34 +- lib/wasi/src/syscalls/wasix64.rs | 34 +- 9 files changed, 3818 insertions(+), 427 deletions(-) diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index 743affac3c1..64030825c2e 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -1522,7 +1522,24 @@ pub mod output { pub type Bid = u32; pub type Cid = u32; /// __wasi_option_t - pub type OptionTag = u8; + #[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 { @@ -1626,8 +1643,1143 @@ pub mod output { } 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()} + } /// Dummy function to expose types into generated code - pub fn expose_types_dummy_func(fd: Fd,dirent: Dirent,snapshot0_dirent: Snapshot0Dirent,snapshot0_event: Snapshot0Event,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,tid: Tid,pid: Pid,bus_data_format: BusDataFormat,bid: Bid,option_bid: OptionBid,cid: Cid,option_cid: OptionCid,option_fd: OptionFd,bus_handles: BusHandles,exit_code: ExitCode,bus_event_exit: BusEventExit,bus_event_fault: BusEventFault,bus_event_close: BusEventClose,prestat_u_dir: PrestatUDir,prestat_u: PrestatU,event_fd_flags: EventFdFlags,prestat: Prestat,file_delta: FileDelta,lookup_flags: LookupFlags,) -> (){ + pub fn expose_types_dummy_func(fd: Fd,dirent: Dirent,snapshot0_dirent: Snapshot0Dirent,snapshot0_event: Snapshot0Event,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,tid: Tid,pid: Pid,bus_data_format: BusDataFormat,bid: Bid,option_bid: OptionBid,cid: Cid,option_cid: OptionCid,option_fd: OptionFd,bus_handles: BusHandles,exit_code: ExitCode,bus_event_exit: BusEventExit,bus_event_fault: BusEventFault,bus_event_close: BusEventClose,prestat_u_dir: PrestatUDir,prestat_u: PrestatU,event_fd_flags: EventFdFlags,prestat: Prestat,file_delta: FileDelta,lookup_flags: LookupFlags,count: Count,bool: Bool,pipe_handles: PipeHandles,stdio_mode: StdioMode,sock_proto: SockProto,option_timestamp: OptionTimestamp,) -> (){ unsafe { let ptr0 = OUTPUT_RET_AREA.0.as_mut_ptr() as i32; *((ptr0 + 0) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd); @@ -2050,25 +3202,43 @@ pub mod output { }) as u8; *((ptr0 + 532) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid); let OptionBid{ tag:tag36, bid:bid36, } = option_bid; - *((ptr0 + 536) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag36)) as u8; + *((ptr0 + 536) as *mut u8) = (match tag36 { + OptionTag::None => 0, + OptionTag::Some => 1, + }) as u8; *((ptr0 + 540) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid36); *((ptr0 + 544) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid); let OptionCid{ tag:tag37, cid:cid37, } = option_cid; - *((ptr0 + 548) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag37)) as u8; + *((ptr0 + 548) as *mut u8) = (match tag37 { + OptionTag::None => 0, + OptionTag::Some => 1, + }) as u8; *((ptr0 + 552) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid37); let OptionFd{ tag:tag38, fd:fd38, } = option_fd; - *((ptr0 + 556) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag38)) as u8; + *((ptr0 + 556) as *mut u8) = (match tag38 { + OptionTag::None => 0, + OptionTag::Some => 1, + }) as u8; *((ptr0 + 560) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd38); let BusHandles{ bid:bid39, stdin:stdin39, stdout:stdout39, stderr:stderr39, } = bus_handles; *((ptr0 + 564) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid39); let OptionFd{ tag:tag40, fd:fd40, } = stdin39; - *((ptr0 + 568) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag40)) as u8; + *((ptr0 + 568) as *mut u8) = (match tag40 { + OptionTag::None => 0, + OptionTag::Some => 1, + }) as u8; *((ptr0 + 572) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd40); let OptionFd{ tag:tag41, fd:fd41, } = stdout39; - *((ptr0 + 576) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag41)) as u8; + *((ptr0 + 576) as *mut u8) = (match tag41 { + OptionTag::None => 0, + OptionTag::Some => 1, + }) as u8; *((ptr0 + 580) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd41); let OptionFd{ tag:tag42, fd:fd42, } = stderr39; - *((ptr0 + 584) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag42)) as u8; + *((ptr0 + 584) as *mut u8) = (match tag42 { + OptionTag::None => 0, + OptionTag::Some => 1, + }) as u8; *((ptr0 + 588) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd42); *((ptr0 + 592) as *mut i32) = wit_bindgen_rust::rt::as_i32(exit_code); let BusEventExit{ bid:bid43, rval:rval43, } = bus_event_exit; @@ -2115,6 +3285,293 @@ pub mod output { *((ptr0 + 632) as *mut i32) = wit_bindgen_rust::rt::as_i32(pr_name_len51); *((ptr0 + 640) as *mut i64) = wit_bindgen_rust::rt::as_i64(file_delta); *((ptr0 + 648) as *mut i32) = wit_bindgen_rust::rt::as_i32(lookup_flags); + *((ptr0 + 652) as *mut i32) = wit_bindgen_rust::rt::as_i32(count); + *((ptr0 + 656) as *mut u8) = (match bool { + Bool::False => 0, + Bool::True => 1, + }) as u8; + let PipeHandles{ pipe:pipe52, other:other52, } = pipe_handles; + *((ptr0 + 660) as *mut i32) = wit_bindgen_rust::rt::as_i32(pipe52); + *((ptr0 + 664) as *mut i32) = wit_bindgen_rust::rt::as_i32(other52); + *((ptr0 + 668) as *mut u8) = (match stdio_mode { + StdioMode::Reserved => 0, + StdioMode::Piped => 1, + StdioMode::Inherit => 2, + StdioMode::Null => 3, + StdioMode::Log => 4, + }) as u8; + *((ptr0 + 670) as *mut u16) = (match sock_proto { + SockProto::Ip => 0, + SockProto::Icmp => 1, + SockProto::Igmp => 2, + SockProto::ProtoThree => 3, + SockProto::Ipip => 4, + SockProto::ProtoFive => 5, + SockProto::Tcp => 6, + SockProto::ProtoSeven => 7, + SockProto::Egp => 8, + SockProto::ProtoNine => 9, + SockProto::ProtoTen => 10, + SockProto::ProtoEleven => 11, + SockProto::Pup => 12, + SockProto::ProtoThirteen => 13, + SockProto::ProtoFourteen => 14, + SockProto::ProtoFifteen => 15, + SockProto::ProtoSixteen => 16, + SockProto::Udp => 17, + SockProto::ProtoEighteen => 18, + SockProto::ProtoNineteen => 19, + SockProto::ProtoTwenty => 20, + SockProto::ProtoTwentyone => 21, + SockProto::Idp => 22, + SockProto::ProtoTwentythree => 23, + SockProto::ProtoTwentyfour => 24, + SockProto::ProtoTwentyfive => 25, + SockProto::ProtoTwentysix => 26, + SockProto::ProtoTwentyseven => 27, + SockProto::ProtoTwentyeight => 28, + SockProto::ProtoTp => 29, + SockProto::ProtoThirty => 30, + SockProto::ProtoThirtyone => 31, + SockProto::ProtoThirtytwo => 32, + SockProto::Dccp => 33, + SockProto::ProtoThirtyfour => 34, + SockProto::ProtoThirtyfive => 35, + SockProto::ProtoThirtysix => 36, + SockProto::ProtoThirtyseven => 37, + SockProto::ProtoThirtyeight => 38, + SockProto::ProtoThirtynine => 39, + SockProto::ProtoFourty => 40, + SockProto::Ipv6 => 41, + SockProto::ProtoFourtytwo => 42, + SockProto::Routing => 43, + SockProto::Fragment => 44, + SockProto::ProtoFourtyfive => 45, + SockProto::Rsvp => 46, + SockProto::Gre => 47, + SockProto::ProtoFourtyeight => 48, + SockProto::ProtoFourtynine => 49, + SockProto::Esp => 50, + SockProto::Ah => 51, + SockProto::ProtoFiftytwo => 52, + SockProto::ProtoFiftythree => 53, + SockProto::ProtoFiftyfour => 54, + SockProto::ProtoFiftyfive => 55, + SockProto::ProtoFiftysix => 56, + SockProto::ProtoFiftyseven => 57, + SockProto::Icmpv6 => 58, + SockProto::None => 59, + SockProto::Dstopts => 60, + SockProto::ProtoSixtyone => 61, + SockProto::ProtoSixtytwo => 62, + SockProto::ProtoSixtythree => 63, + SockProto::ProtoSixtyfour => 64, + SockProto::ProtoSixtyfive => 65, + SockProto::ProtoSixtysix => 66, + SockProto::ProtoSixtyseven => 67, + SockProto::ProtoSixtyeight => 68, + SockProto::ProtoSixtynine => 69, + SockProto::ProtoSeventy => 70, + SockProto::ProtoSeventyone => 71, + SockProto::ProtoSeventytwo => 72, + SockProto::ProtoSeventythree => 73, + SockProto::ProtoSeventyfour => 74, + SockProto::ProtoSeventyfive => 75, + SockProto::ProtoSeventysix => 76, + SockProto::ProtoSeventyseven => 77, + SockProto::ProtoSeventyeight => 78, + SockProto::ProtoSeventynine => 79, + SockProto::ProtoEighty => 80, + SockProto::ProtoEightyone => 81, + SockProto::ProtoEightytwo => 82, + SockProto::ProtoEightythree => 83, + SockProto::ProtoEightyfour => 84, + SockProto::ProtoEightyfive => 85, + SockProto::ProtoEightysix => 86, + SockProto::ProtoEightyseven => 87, + SockProto::ProtoEightyeight => 88, + SockProto::ProtoEightynine => 89, + SockProto::ProtoNinety => 90, + SockProto::ProtoNinetyone => 91, + SockProto::Mtp => 92, + SockProto::ProtoNinetythree => 93, + SockProto::Beetph => 94, + SockProto::ProtoNinetyfive => 95, + SockProto::ProtoNinetysix => 96, + SockProto::ProtoNineetyseven => 97, + SockProto::Encap => 98, + SockProto::ProtoNinetynine => 99, + SockProto::ProtoOnehundred => 100, + SockProto::ProtoOnehundredandone => 101, + SockProto::ProtoOnehundredandtwo => 102, + SockProto::Pim => 103, + SockProto::ProtoOnehundredandfour => 104, + SockProto::ProtoOnehundredandfive => 105, + SockProto::ProtoOnehundredandsix => 106, + SockProto::ProtoOnehundredandseven => 107, + SockProto::Comp => 108, + SockProto::ProtoOnehundredandnine => 109, + SockProto::ProtoOnehundredandten => 110, + SockProto::ProtoOnehundredandeleven => 111, + SockProto::ProtoOnehundredandtwelve => 112, + SockProto::ProtoOnehundredandthirteen => 113, + SockProto::ProtoOnehundredandfourteen => 114, + SockProto::ProtoOnehundredandfifteen => 115, + SockProto::ProtoOnehundredandsixteen => 116, + SockProto::ProtoOnehundredandseventeen => 117, + SockProto::ProtoOnehundredandeighteen => 118, + SockProto::ProtoOnehundredandnineteen => 119, + SockProto::ProtoOnehundredandtwenty => 120, + SockProto::ProtoOnehundredandtwentyone => 121, + SockProto::ProtoOnehundredandtwentytwo => 122, + SockProto::ProtoOnehundredandtwentythree => 123, + SockProto::ProtoOnehundredandtwentyfour => 124, + SockProto::ProtoOnehundredandtwentyfive => 125, + SockProto::ProtoOnehundredandtwentysix => 126, + SockProto::ProtoOnehundredandtwentyseven => 127, + SockProto::ProtoOnehundredandtwentyeight => 128, + SockProto::ProtoOnehundredandtwentynine => 129, + SockProto::ProtoOnehundredandthirty => 130, + SockProto::ProtoOnehundredandthirtyone => 131, + SockProto::Sctp => 132, + SockProto::ProtoOnehundredandthirtythree => 133, + SockProto::ProtoOnehundredandthirtyfour => 134, + SockProto::Mh => 135, + SockProto::Udplite => 136, + SockProto::Mpls => 137, + SockProto::ProtoOnehundredandthirtyeight => 138, + SockProto::ProtoOnehundredandthirtynine => 139, + SockProto::ProtoOnehundredandfourty => 140, + SockProto::ProtoOnehundredandfourtyone => 141, + SockProto::ProtoOnehundredandfourtytwo => 142, + SockProto::Ethernet => 143, + SockProto::ProtoOnehundredandfourtyfour => 144, + SockProto::ProtoOnehundredandfourtyfive => 145, + SockProto::ProtoOnehundredandfourtysix => 146, + SockProto::ProtoOnehundredandfourtyseven => 147, + SockProto::ProtoOnehundredandfourtyeight => 148, + SockProto::ProtoOnehundredandfourtynine => 149, + SockProto::ProtoOnehundredandfifty => 150, + SockProto::ProtoOnehundredandfiftyone => 151, + SockProto::ProtoOnehundredandfiftytwo => 152, + SockProto::ProtoOnehundredandfiftythree => 153, + SockProto::ProtoOnehundredandfiftyfour => 154, + SockProto::ProtoOnehundredandfiftyfive => 155, + SockProto::ProtoOnehundredandfiftysix => 156, + SockProto::ProtoOnehundredandfiftyseven => 157, + SockProto::ProtoOnehundredandfiftyeight => 158, + SockProto::ProtoOnehundredandfiftynine => 159, + SockProto::ProtoOnehundredandsixty => 160, + SockProto::ProtoOnehundredandsixtyone => 161, + SockProto::ProtoOnehundredandsixtytwo => 162, + SockProto::ProtoOnehundredandsixtythree => 163, + SockProto::ProtoOnehundredandsixtyfour => 164, + SockProto::ProtoOnehundredandsixtyfive => 165, + SockProto::ProtoOnehundredandsixtysix => 166, + SockProto::ProtoOnehundredandsixtyseven => 167, + SockProto::ProtoOnehundredandsixtyeight => 168, + SockProto::ProtoOnehundredandsixtynine => 169, + SockProto::ProtoOnehundredandseventy => 170, + SockProto::ProtoOnehundredandseventyone => 171, + SockProto::ProtoOnehundredandseventytwo => 172, + SockProto::ProtoOnehundredandseventythree => 173, + SockProto::ProtoOnehundredandseventyfour => 174, + SockProto::ProtoOnehundredandseventyfive => 175, + SockProto::ProtoOnehundredandseventysix => 176, + SockProto::ProtoOnehundredandseventyseven => 177, + SockProto::ProtoOnehundredandseventyeight => 178, + SockProto::ProtoOnehundredandseventynine => 179, + SockProto::ProtoOnehundredandeighty => 180, + SockProto::ProtoOnehundredandeightyone => 181, + SockProto::ProtoOnehundredandeightytwo => 182, + SockProto::ProtoOnehundredandeightythree => 183, + SockProto::ProtoOnehundredandeightyfour => 184, + SockProto::ProtoOnehundredandeightyfive => 185, + SockProto::ProtoOnehundredandeightysix => 186, + SockProto::ProtoOnehundredandeightyseven => 187, + SockProto::ProtoOnehundredandeightyeight => 188, + SockProto::ProtoOnehundredandeightynine => 189, + SockProto::ProtoOnehundredandninety => 190, + SockProto::ProtoOnehundredandninetyone => 191, + SockProto::ProtoOnehundredandninetytwo => 192, + SockProto::ProtoOnehundredandninetythree => 193, + SockProto::ProtoOnehundredandninetyfour => 194, + SockProto::ProtoOnehundredandninetyfive => 195, + SockProto::ProtoOnehundredandninetysix => 196, + SockProto::ProtoOnehundredandninetyseven => 197, + SockProto::ProtoOnehundredandninetyeight => 198, + SockProto::ProtoOnehundredandninetynine => 199, + SockProto::ProtoTwohundred => 200, + SockProto::ProtoTwohundredandone => 201, + SockProto::ProtoTwohundredandtwo => 202, + SockProto::ProtoTwohundredandthree => 203, + SockProto::ProtoTwohundredandfour => 204, + SockProto::ProtoTwohundredandfive => 205, + SockProto::ProtoTwohundredandsix => 206, + SockProto::ProtoTwohundredandseven => 207, + SockProto::ProtoTwohundredandeight => 208, + SockProto::ProtoTwohundredandnine => 209, + SockProto::ProtoTwohundredandten => 210, + SockProto::ProtoTwohundredandeleven => 211, + SockProto::ProtoTwohundredandtwelve => 212, + SockProto::ProtoTwohundredandthirteen => 213, + SockProto::ProtoTwohundredandfourteen => 214, + SockProto::ProtoTwohundredandfifteen => 215, + SockProto::ProtoTwohundredandsixteen => 216, + SockProto::ProtoTwohundredandseventeen => 217, + SockProto::ProtoTwohundredandeighteen => 218, + SockProto::ProtoTwohundredandnineteen => 219, + SockProto::ProtoTwohundredandtwenty => 220, + SockProto::ProtoTwohundredandtwentyone => 221, + SockProto::ProtoTwohundredandtwentytwo => 222, + SockProto::ProtoTwohundredandtwentythree => 223, + SockProto::ProtoTwohundredandtwentyfour => 224, + SockProto::ProtoTwohundredandtwentyfive => 225, + SockProto::ProtoTwohundredandtwentysix => 226, + SockProto::ProtoTwohundredandtwentyseven => 227, + SockProto::ProtoTwohundredandtwentyeight => 228, + SockProto::ProtoTwohundredandtwentynine => 229, + SockProto::ProtoTwohundredandthirty => 230, + SockProto::ProtoTwohundredandthirtyone => 231, + SockProto::ProtoTwohundredandthirtytwo => 232, + SockProto::ProtoTwohundredandthirtythree => 233, + SockProto::ProtoTwohundredandthirtyfour => 234, + SockProto::ProtoTwohundredandthirtyfive => 235, + SockProto::ProtoTwohundredandthirtysix => 236, + SockProto::ProtoTwohundredandthirtyseven => 237, + SockProto::ProtoTwohundredandthirtyeight => 238, + SockProto::ProtoTwohundredandthirtynine => 239, + SockProto::ProtoTwohundredandfourty => 240, + SockProto::ProtoTwohundredandfourtyone => 241, + SockProto::ProtoTwohundredandfourtytwo => 242, + SockProto::ProtoTwohundredandfourtythree => 243, + SockProto::ProtoTwohundredandfourtyfour => 244, + SockProto::ProtoTwohundredandfourtyfive => 245, + SockProto::ProtoTwohundredandfourtysix => 246, + SockProto::ProtoTwohundredandfourtyseven => 247, + SockProto::ProtoTwohundredandfourtyeight => 248, + SockProto::ProtoTwohundredandfourtynine => 249, + SockProto::ProtoTwohundredandfifty => 250, + SockProto::ProtoTwohundredandfiftyone => 251, + SockProto::ProtoTwohundredandfiftytwo => 252, + SockProto::ProtoTwohundredandfiftythree => 253, + SockProto::ProtoTwohundredandfiftyfour => 254, + SockProto::ProtoRaw => 255, + SockProto::ProtoTwohundredandfiftysix => 256, + SockProto::ProtoTwohundredandfiftyseven => 257, + SockProto::ProtoTwohundredandfiftyeight => 258, + SockProto::ProtoTwohundredandfiftynine => 259, + SockProto::ProtoTwohundredandsixty => 260, + SockProto::ProtoTwohundredandsixtyone => 261, + SockProto::Mptcp => 262, + SockProto::Max => 263, + }) as u16; + let OptionTimestamp{ tag:tag53, u:u53, } = option_timestamp; + *((ptr0 + 672) as *mut u8) = (match tag53 { + OptionTag::None => 0, + OptionTag::Some => 1, + }) as u8; + *((ptr0 + 680) as *mut i64) = wit_bindgen_rust::rt::as_i64(u53); #[link(wasm_import_module = "output")] extern "C" { #[cfg_attr(target_arch = "wasm32", link_name = "expose-types-dummy-func")] @@ -2127,6 +3584,6 @@ pub mod output { } #[repr(align(8))] - struct RetArea([u8; 656]); - static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 656]); + struct RetArea([u8; 688]); + static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 688]); } diff --git a/lib/wasi-types-generated/src/wasi/extra.rs b/lib/wasi-types-generated/src/wasi/extra.rs index 4889ad1fe08..241e988ebb2 100644 --- a/lib/wasi-types-generated/src/wasi/extra.rs +++ b/lib/wasi-types-generated/src/wasi/extra.rs @@ -1446,7 +1446,20 @@ impl core::fmt::Debug for BusEventType { pub type Bid = u32; pub type Cid = u32; /// __wasi_option_t -pub type OptionTag = u8; +#[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 { @@ -1587,6 +1600,911 @@ impl core::fmt::Debug for Prestat { } 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() + } +} /// Dummy function to expose types into generated code pub fn expose_types_dummy_func( fd: Fd, @@ -1625,6 +2543,12 @@ pub fn expose_types_dummy_func( prestat: Prestat, file_delta: FileDelta, lookup_flags: LookupFlags, + count: Count, + bool: Bool, + pipe_handles: PipeHandles, + stdio_mode: StdioMode, + sock_proto: SockProto, + option_timestamp: OptionTimestamp, ) -> () { unsafe { let ptr0 = OUTPUT_RET_AREA.0.as_mut_ptr() as i32; @@ -2157,20 +3081,29 @@ pub fn expose_types_dummy_func( tag: tag36, bid: bid36, } = option_bid; - *((ptr0 + 536) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag36)) as u8; + *((ptr0 + 536) as *mut u8) = (match tag36 { + OptionTag::None => 0, + OptionTag::Some => 1, + }) as u8; *((ptr0 + 540) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid36); *((ptr0 + 544) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid); let OptionCid { tag: tag37, cid: cid37, } = option_cid; - *((ptr0 + 548) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag37)) as u8; + *((ptr0 + 548) as *mut u8) = (match tag37 { + OptionTag::None => 0, + OptionTag::Some => 1, + }) as u8; *((ptr0 + 552) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid37); let OptionFd { tag: tag38, fd: fd38, } = option_fd; - *((ptr0 + 556) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag38)) as u8; + *((ptr0 + 556) as *mut u8) = (match tag38 { + OptionTag::None => 0, + OptionTag::Some => 1, + }) as u8; *((ptr0 + 560) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd38); let BusHandles { bid: bid39, @@ -2183,19 +3116,28 @@ pub fn expose_types_dummy_func( tag: tag40, fd: fd40, } = stdin39; - *((ptr0 + 568) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag40)) as u8; + *((ptr0 + 568) as *mut u8) = (match tag40 { + OptionTag::None => 0, + OptionTag::Some => 1, + }) as u8; *((ptr0 + 572) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd40); let OptionFd { tag: tag41, fd: fd41, } = stdout39; - *((ptr0 + 576) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag41)) as u8; + *((ptr0 + 576) as *mut u8) = (match tag41 { + OptionTag::None => 0, + OptionTag::Some => 1, + }) as u8; *((ptr0 + 580) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd41); let OptionFd { tag: tag42, fd: fd42, } = stderr39; - *((ptr0 + 584) as *mut u8) = (wit_bindgen_rust::rt::as_i32(tag42)) as u8; + *((ptr0 + 584) as *mut u8) = (match tag42 { + OptionTag::None => 0, + OptionTag::Some => 1, + }) as u8; *((ptr0 + 588) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd42); *((ptr0 + 592) as *mut i32) = wit_bindgen_rust::rt::as_i32(exit_code); let BusEventExit { @@ -2257,6 +3199,296 @@ pub fn expose_types_dummy_func( *((ptr0 + 632) as *mut i32) = wit_bindgen_rust::rt::as_i32(pr_name_len51); *((ptr0 + 640) as *mut i64) = wit_bindgen_rust::rt::as_i64(file_delta); *((ptr0 + 648) as *mut i32) = wit_bindgen_rust::rt::as_i32(lookup_flags); + *((ptr0 + 652) as *mut i32) = wit_bindgen_rust::rt::as_i32(count); + *((ptr0 + 656) as *mut u8) = (match bool { + Bool::False => 0, + Bool::True => 1, + }) as u8; + let PipeHandles { + pipe: pipe52, + other: other52, + } = pipe_handles; + *((ptr0 + 660) as *mut i32) = wit_bindgen_rust::rt::as_i32(pipe52); + *((ptr0 + 664) as *mut i32) = wit_bindgen_rust::rt::as_i32(other52); + *((ptr0 + 668) as *mut u8) = (match stdio_mode { + StdioMode::Reserved => 0, + StdioMode::Piped => 1, + StdioMode::Inherit => 2, + StdioMode::Null => 3, + StdioMode::Log => 4, + }) as u8; + *((ptr0 + 670) as *mut u16) = (match sock_proto { + SockProto::Ip => 0, + SockProto::Icmp => 1, + SockProto::Igmp => 2, + SockProto::ProtoThree => 3, + SockProto::Ipip => 4, + SockProto::ProtoFive => 5, + SockProto::Tcp => 6, + SockProto::ProtoSeven => 7, + SockProto::Egp => 8, + SockProto::ProtoNine => 9, + SockProto::ProtoTen => 10, + SockProto::ProtoEleven => 11, + SockProto::Pup => 12, + SockProto::ProtoThirteen => 13, + SockProto::ProtoFourteen => 14, + SockProto::ProtoFifteen => 15, + SockProto::ProtoSixteen => 16, + SockProto::Udp => 17, + SockProto::ProtoEighteen => 18, + SockProto::ProtoNineteen => 19, + SockProto::ProtoTwenty => 20, + SockProto::ProtoTwentyone => 21, + SockProto::Idp => 22, + SockProto::ProtoTwentythree => 23, + SockProto::ProtoTwentyfour => 24, + SockProto::ProtoTwentyfive => 25, + SockProto::ProtoTwentysix => 26, + SockProto::ProtoTwentyseven => 27, + SockProto::ProtoTwentyeight => 28, + SockProto::ProtoTp => 29, + SockProto::ProtoThirty => 30, + SockProto::ProtoThirtyone => 31, + SockProto::ProtoThirtytwo => 32, + SockProto::Dccp => 33, + SockProto::ProtoThirtyfour => 34, + SockProto::ProtoThirtyfive => 35, + SockProto::ProtoThirtysix => 36, + SockProto::ProtoThirtyseven => 37, + SockProto::ProtoThirtyeight => 38, + SockProto::ProtoThirtynine => 39, + SockProto::ProtoFourty => 40, + SockProto::Ipv6 => 41, + SockProto::ProtoFourtytwo => 42, + SockProto::Routing => 43, + SockProto::Fragment => 44, + SockProto::ProtoFourtyfive => 45, + SockProto::Rsvp => 46, + SockProto::Gre => 47, + SockProto::ProtoFourtyeight => 48, + SockProto::ProtoFourtynine => 49, + SockProto::Esp => 50, + SockProto::Ah => 51, + SockProto::ProtoFiftytwo => 52, + SockProto::ProtoFiftythree => 53, + SockProto::ProtoFiftyfour => 54, + SockProto::ProtoFiftyfive => 55, + SockProto::ProtoFiftysix => 56, + SockProto::ProtoFiftyseven => 57, + SockProto::Icmpv6 => 58, + SockProto::None => 59, + SockProto::Dstopts => 60, + SockProto::ProtoSixtyone => 61, + SockProto::ProtoSixtytwo => 62, + SockProto::ProtoSixtythree => 63, + SockProto::ProtoSixtyfour => 64, + SockProto::ProtoSixtyfive => 65, + SockProto::ProtoSixtysix => 66, + SockProto::ProtoSixtyseven => 67, + SockProto::ProtoSixtyeight => 68, + SockProto::ProtoSixtynine => 69, + SockProto::ProtoSeventy => 70, + SockProto::ProtoSeventyone => 71, + SockProto::ProtoSeventytwo => 72, + SockProto::ProtoSeventythree => 73, + SockProto::ProtoSeventyfour => 74, + SockProto::ProtoSeventyfive => 75, + SockProto::ProtoSeventysix => 76, + SockProto::ProtoSeventyseven => 77, + SockProto::ProtoSeventyeight => 78, + SockProto::ProtoSeventynine => 79, + SockProto::ProtoEighty => 80, + SockProto::ProtoEightyone => 81, + SockProto::ProtoEightytwo => 82, + SockProto::ProtoEightythree => 83, + SockProto::ProtoEightyfour => 84, + SockProto::ProtoEightyfive => 85, + SockProto::ProtoEightysix => 86, + SockProto::ProtoEightyseven => 87, + SockProto::ProtoEightyeight => 88, + SockProto::ProtoEightynine => 89, + SockProto::ProtoNinety => 90, + SockProto::ProtoNinetyone => 91, + SockProto::Mtp => 92, + SockProto::ProtoNinetythree => 93, + SockProto::Beetph => 94, + SockProto::ProtoNinetyfive => 95, + SockProto::ProtoNinetysix => 96, + SockProto::ProtoNineetyseven => 97, + SockProto::Encap => 98, + SockProto::ProtoNinetynine => 99, + SockProto::ProtoOnehundred => 100, + SockProto::ProtoOnehundredandone => 101, + SockProto::ProtoOnehundredandtwo => 102, + SockProto::Pim => 103, + SockProto::ProtoOnehundredandfour => 104, + SockProto::ProtoOnehundredandfive => 105, + SockProto::ProtoOnehundredandsix => 106, + SockProto::ProtoOnehundredandseven => 107, + SockProto::Comp => 108, + SockProto::ProtoOnehundredandnine => 109, + SockProto::ProtoOnehundredandten => 110, + SockProto::ProtoOnehundredandeleven => 111, + SockProto::ProtoOnehundredandtwelve => 112, + SockProto::ProtoOnehundredandthirteen => 113, + SockProto::ProtoOnehundredandfourteen => 114, + SockProto::ProtoOnehundredandfifteen => 115, + SockProto::ProtoOnehundredandsixteen => 116, + SockProto::ProtoOnehundredandseventeen => 117, + SockProto::ProtoOnehundredandeighteen => 118, + SockProto::ProtoOnehundredandnineteen => 119, + SockProto::ProtoOnehundredandtwenty => 120, + SockProto::ProtoOnehundredandtwentyone => 121, + SockProto::ProtoOnehundredandtwentytwo => 122, + SockProto::ProtoOnehundredandtwentythree => 123, + SockProto::ProtoOnehundredandtwentyfour => 124, + SockProto::ProtoOnehundredandtwentyfive => 125, + SockProto::ProtoOnehundredandtwentysix => 126, + SockProto::ProtoOnehundredandtwentyseven => 127, + SockProto::ProtoOnehundredandtwentyeight => 128, + SockProto::ProtoOnehundredandtwentynine => 129, + SockProto::ProtoOnehundredandthirty => 130, + SockProto::ProtoOnehundredandthirtyone => 131, + SockProto::Sctp => 132, + SockProto::ProtoOnehundredandthirtythree => 133, + SockProto::ProtoOnehundredandthirtyfour => 134, + SockProto::Mh => 135, + SockProto::Udplite => 136, + SockProto::Mpls => 137, + SockProto::ProtoOnehundredandthirtyeight => 138, + SockProto::ProtoOnehundredandthirtynine => 139, + SockProto::ProtoOnehundredandfourty => 140, + SockProto::ProtoOnehundredandfourtyone => 141, + SockProto::ProtoOnehundredandfourtytwo => 142, + SockProto::Ethernet => 143, + SockProto::ProtoOnehundredandfourtyfour => 144, + SockProto::ProtoOnehundredandfourtyfive => 145, + SockProto::ProtoOnehundredandfourtysix => 146, + SockProto::ProtoOnehundredandfourtyseven => 147, + SockProto::ProtoOnehundredandfourtyeight => 148, + SockProto::ProtoOnehundredandfourtynine => 149, + SockProto::ProtoOnehundredandfifty => 150, + SockProto::ProtoOnehundredandfiftyone => 151, + SockProto::ProtoOnehundredandfiftytwo => 152, + SockProto::ProtoOnehundredandfiftythree => 153, + SockProto::ProtoOnehundredandfiftyfour => 154, + SockProto::ProtoOnehundredandfiftyfive => 155, + SockProto::ProtoOnehundredandfiftysix => 156, + SockProto::ProtoOnehundredandfiftyseven => 157, + SockProto::ProtoOnehundredandfiftyeight => 158, + SockProto::ProtoOnehundredandfiftynine => 159, + SockProto::ProtoOnehundredandsixty => 160, + SockProto::ProtoOnehundredandsixtyone => 161, + SockProto::ProtoOnehundredandsixtytwo => 162, + SockProto::ProtoOnehundredandsixtythree => 163, + SockProto::ProtoOnehundredandsixtyfour => 164, + SockProto::ProtoOnehundredandsixtyfive => 165, + SockProto::ProtoOnehundredandsixtysix => 166, + SockProto::ProtoOnehundredandsixtyseven => 167, + SockProto::ProtoOnehundredandsixtyeight => 168, + SockProto::ProtoOnehundredandsixtynine => 169, + SockProto::ProtoOnehundredandseventy => 170, + SockProto::ProtoOnehundredandseventyone => 171, + SockProto::ProtoOnehundredandseventytwo => 172, + SockProto::ProtoOnehundredandseventythree => 173, + SockProto::ProtoOnehundredandseventyfour => 174, + SockProto::ProtoOnehundredandseventyfive => 175, + SockProto::ProtoOnehundredandseventysix => 176, + SockProto::ProtoOnehundredandseventyseven => 177, + SockProto::ProtoOnehundredandseventyeight => 178, + SockProto::ProtoOnehundredandseventynine => 179, + SockProto::ProtoOnehundredandeighty => 180, + SockProto::ProtoOnehundredandeightyone => 181, + SockProto::ProtoOnehundredandeightytwo => 182, + SockProto::ProtoOnehundredandeightythree => 183, + SockProto::ProtoOnehundredandeightyfour => 184, + SockProto::ProtoOnehundredandeightyfive => 185, + SockProto::ProtoOnehundredandeightysix => 186, + SockProto::ProtoOnehundredandeightyseven => 187, + SockProto::ProtoOnehundredandeightyeight => 188, + SockProto::ProtoOnehundredandeightynine => 189, + SockProto::ProtoOnehundredandninety => 190, + SockProto::ProtoOnehundredandninetyone => 191, + SockProto::ProtoOnehundredandninetytwo => 192, + SockProto::ProtoOnehundredandninetythree => 193, + SockProto::ProtoOnehundredandninetyfour => 194, + SockProto::ProtoOnehundredandninetyfive => 195, + SockProto::ProtoOnehundredandninetysix => 196, + SockProto::ProtoOnehundredandninetyseven => 197, + SockProto::ProtoOnehundredandninetyeight => 198, + SockProto::ProtoOnehundredandninetynine => 199, + SockProto::ProtoTwohundred => 200, + SockProto::ProtoTwohundredandone => 201, + SockProto::ProtoTwohundredandtwo => 202, + SockProto::ProtoTwohundredandthree => 203, + SockProto::ProtoTwohundredandfour => 204, + SockProto::ProtoTwohundredandfive => 205, + SockProto::ProtoTwohundredandsix => 206, + SockProto::ProtoTwohundredandseven => 207, + SockProto::ProtoTwohundredandeight => 208, + SockProto::ProtoTwohundredandnine => 209, + SockProto::ProtoTwohundredandten => 210, + SockProto::ProtoTwohundredandeleven => 211, + SockProto::ProtoTwohundredandtwelve => 212, + SockProto::ProtoTwohundredandthirteen => 213, + SockProto::ProtoTwohundredandfourteen => 214, + SockProto::ProtoTwohundredandfifteen => 215, + SockProto::ProtoTwohundredandsixteen => 216, + SockProto::ProtoTwohundredandseventeen => 217, + SockProto::ProtoTwohundredandeighteen => 218, + SockProto::ProtoTwohundredandnineteen => 219, + SockProto::ProtoTwohundredandtwenty => 220, + SockProto::ProtoTwohundredandtwentyone => 221, + SockProto::ProtoTwohundredandtwentytwo => 222, + SockProto::ProtoTwohundredandtwentythree => 223, + SockProto::ProtoTwohundredandtwentyfour => 224, + SockProto::ProtoTwohundredandtwentyfive => 225, + SockProto::ProtoTwohundredandtwentysix => 226, + SockProto::ProtoTwohundredandtwentyseven => 227, + SockProto::ProtoTwohundredandtwentyeight => 228, + SockProto::ProtoTwohundredandtwentynine => 229, + SockProto::ProtoTwohundredandthirty => 230, + SockProto::ProtoTwohundredandthirtyone => 231, + SockProto::ProtoTwohundredandthirtytwo => 232, + SockProto::ProtoTwohundredandthirtythree => 233, + SockProto::ProtoTwohundredandthirtyfour => 234, + SockProto::ProtoTwohundredandthirtyfive => 235, + SockProto::ProtoTwohundredandthirtysix => 236, + SockProto::ProtoTwohundredandthirtyseven => 237, + SockProto::ProtoTwohundredandthirtyeight => 238, + SockProto::ProtoTwohundredandthirtynine => 239, + SockProto::ProtoTwohundredandfourty => 240, + SockProto::ProtoTwohundredandfourtyone => 241, + SockProto::ProtoTwohundredandfourtytwo => 242, + SockProto::ProtoTwohundredandfourtythree => 243, + SockProto::ProtoTwohundredandfourtyfour => 244, + SockProto::ProtoTwohundredandfourtyfive => 245, + SockProto::ProtoTwohundredandfourtysix => 246, + SockProto::ProtoTwohundredandfourtyseven => 247, + SockProto::ProtoTwohundredandfourtyeight => 248, + SockProto::ProtoTwohundredandfourtynine => 249, + SockProto::ProtoTwohundredandfifty => 250, + SockProto::ProtoTwohundredandfiftyone => 251, + SockProto::ProtoTwohundredandfiftytwo => 252, + SockProto::ProtoTwohundredandfiftythree => 253, + SockProto::ProtoTwohundredandfiftyfour => 254, + SockProto::ProtoRaw => 255, + SockProto::ProtoTwohundredandfiftysix => 256, + SockProto::ProtoTwohundredandfiftyseven => 257, + SockProto::ProtoTwohundredandfiftyeight => 258, + SockProto::ProtoTwohundredandfiftynine => 259, + SockProto::ProtoTwohundredandsixty => 260, + SockProto::ProtoTwohundredandsixtyone => 261, + SockProto::Mptcp => 262, + SockProto::Max => 263, + }) as u16; + let OptionTimestamp { tag: tag53, u: u53 } = option_timestamp; + *((ptr0 + 672) as *mut u8) = (match tag53 { + OptionTag::None => 0, + OptionTag::Some => 1, + }) as u8; + *((ptr0 + 680) as *mut i64) = wit_bindgen_rust::rt::as_i64(u53); #[link(wasm_import_module = "output")] extern "C" { #[cfg_attr(target_arch = "wasm32", link_name = "expose-types-dummy-func")] @@ -2272,8 +3504,8 @@ pub fn expose_types_dummy_func( } #[repr(align(8))] -struct RetArea([u8; 656]); -static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 656]); +struct RetArea([u8; 688]); +static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 688]); // TODO: if necessary, must be implemented in wit-bindgen unsafe impl ValueType for Snapshot0Clockid { @@ -3045,6 +4277,34 @@ unsafe impl wasmer::FromToNativeWasmType for BusEventType { } } +// 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"), + } + } + + #[cfg(feature = "sys")] + 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] @@ -3098,3 +4358,364 @@ 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"), + } + } + + #[cfg(feature = "sys")] + 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"), + } + } + + #[cfg(feature = "sys")] + 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"), + } + } + + #[cfg(feature = "sys")] + 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]) {} +} diff --git a/lib/wasi-types-generated/wit-clean/output.wit b/lib/wasi-types-generated/wit-clean/output.wit index 1c99ce569f6..ae95bfed82d 100644 --- a/lib/wasi-types-generated/wit-clean/output.wit +++ b/lib/wasi-types-generated/wit-clean/output.wit @@ -42,6 +42,12 @@ expose-types-dummy-func: func( prestat: prestat, file-delta: file-delta, lookup-flags: lookup-flags, + count: count, + %bool: %bool, + pipe-handles: pipe-handles, + stdio-mode: stdio-mode, + sock-proto: sock-proto, + option-timestamp: option-timestamp, ) /// Type names used by low-level WASI interfaces. @@ -851,7 +857,10 @@ type bid = u32 type cid = u32 /// __wasi_option_t -type option-tag = u8 +enum option-tag { + none, + some, +} record option-bid { tag: option-tag, @@ -909,7 +918,298 @@ record prestat { type file-delta = s64 type lookup-flags = u32 -// WASI Preview. This is an evolution of the API that WASI initially + +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, +}// 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). diff --git a/lib/wasi-types-generated/wit-clean/typenames.wit b/lib/wasi-types-generated/wit-clean/typenames.wit index 89cc7ce9c7e..6f78497175e 100644 --- a/lib/wasi-types-generated/wit-clean/typenames.wit +++ b/lib/wasi-types-generated/wit-clean/typenames.wit @@ -42,6 +42,12 @@ expose-types-dummy-func: func( prestat: prestat, file-delta: file-delta, lookup-flags: lookup-flags, + count: count, + %bool: %bool, + pipe-handles: pipe-handles, + stdio-mode: stdio-mode, + sock-proto: sock-proto, + option-timestamp: option-timestamp, ) /// Type names used by low-level WASI interfaces. @@ -851,7 +857,10 @@ type bid = u32 type cid = u32 /// __wasi_option_t -type option-tag = u8 +enum option-tag { + none, + some, +} record option-bid { tag: option-tag, @@ -909,3 +918,295 @@ record prestat { 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, +} \ No newline at end of file diff --git a/lib/wasi-types/src/lib.rs b/lib/wasi-types/src/lib.rs index 32118ed3c98..b8a6b6f94e1 100644 --- a/lib/wasi-types/src/lib.rs +++ b/lib/wasi-types/src/lib.rs @@ -106,8 +106,6 @@ pub mod file { } } -// --- not ported - pub mod directory { use std::mem; use wasmer_wasi_types_generated::wasi; @@ -186,15 +184,10 @@ pub mod io { use wasmer_types::MemorySize; use wasmer_wasi_types_generated::wasi::Fd; - 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; + pub use wasmer_wasi_types_generated::wasi::Bool; + pub use wasmer_wasi_types_generated::wasi::Count; + pub use wasmer_wasi_types_generated::wasi::OptionTag; + pub use wasmer_wasi_types_generated::wasi::StdioMode; #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] #[repr(C)] @@ -209,293 +202,18 @@ pub mod io { pub buf: M::Offset, pub buf_len: M::Offset, } - - #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] - #[repr(C)] - pub struct __wasi_pipe_handles_t { - pub pipe: Fd, - pub other: Fd, - } - - 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; } +// --- not ported + pub mod net { use super::*; use wasmer_derive::ValueType; use wasmer_wasi_types_generated::wasi::{Addressfamily, Fd, Filesize}; - use crate::__wasi_option_timestamp_t; - - 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; + use crate::OptionTimestamp; + + pub use wasmer_wasi_types_generated::wasi::SockProto; #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] #[repr(C)] @@ -627,8 +345,8 @@ pub mod net { 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, + pub preferred_until: OptionTimestamp, + pub expires_at: OptionTimestamp, } #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] @@ -642,8 +360,8 @@ pub mod net { #[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 ok: Bool, + pub redirect: Bool, pub size: Filesize, pub status: u16, } @@ -832,14 +550,7 @@ pub mod subscription { } pub mod time { - use super::io::__wasi_option_t; use wasmer_derive::ValueType; - use wasmer_wasi_types_generated::wasi::Timestamp; - - #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] - #[repr(C)] - pub struct __wasi_option_timestamp_t { - pub tag: __wasi_option_t, - pub u: Timestamp, - } + pub use wasmer_wasi_types_generated::wasi::OptionTimestamp; + use wasmer_wasi_types_generated::wasi::{OptionTag, Timestamp}; } diff --git a/lib/wasi/src/state/socket.rs b/lib/wasi/src/state/socket.rs index c304d6f9c1a..ee5d07b7bb1 100644 --- a/lib/wasi/src/state/socket.rs +++ b/lib/wasi/src/state/socket.rs @@ -16,7 +16,9 @@ use wasmer_vnet::{ IpCidr, IpRoute, SocketHttpRequest, VirtualIcmpSocket, VirtualNetworking, VirtualRawSocket, VirtualTcpListener, VirtualTcpSocket, VirtualUdpSocket, VirtualWebSocket, }; -use wasmer_wasi_types_generated::wasi::{Addressfamily, Errno, Fdflags, Sockoption, Socktype}; +use wasmer_wasi_types_generated::wasi::{ + Addressfamily, Errno, Fdflags, OptionTag, Sockoption, Socktype, +}; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; @@ -38,7 +40,7 @@ pub enum InodeSocketKind { PreSocket { family: Addressfamily, ty: Socktype, - pt: __wasi_sockproto_t, + pt: SockProto, addr: Option, only_v6: bool, reuse_port: bool, @@ -1361,14 +1363,12 @@ pub(crate) fn read_route( } }, preferred_until: match route.preferred_until.tag { - __WASI_OPTION_NONE => None, - __WASI_OPTION_SOME => Some(Duration::from_nanos(route.preferred_until.u)), - _ => return Err(Errno::Inval), + 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(Errno::Inval), + OptionTag::None => None, + OptionTag::Some => Some(Duration::from_nanos(route.expires_at.u)), }, }) } @@ -1425,22 +1425,22 @@ pub(crate) fn write_route( } }; 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, }, }; diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 7ff2d73304c..b61b920460c 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -29,8 +29,9 @@ use self::types::{ 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, Streamsecurity, Subscription, - SubscriptionEnum, SubscriptionFsReadwrite, Tid, Timestamp, Tty, Whence, + Rights, Snapshot0Clockid, Sockoption, Sockstatus, Socktype, StdioMode as WasiStdioMode, + Streamsecurity, Subscription, SubscriptionEnum, SubscriptionFsReadwrite, Tid, Timestamp, + Tty, Whence, }, *, }; @@ -3457,7 +3458,7 @@ pub fn thread_spawn( method: WasmPtr, method_len: M::Offset, user_data: u64, - reactor: __wasi_bool_t, + reactor: Bool, ret_tid: WasmPtr, ) -> Errno { debug!("wasi::thread_spawn"); @@ -3479,8 +3480,8 @@ pub fn thread_spawn( */ let reactor = match reactor { - __WASI_BOOL_FALSE => false, - __WASI_BOOL_TRUE => true, + Bool::False => false, + Bool::True => true, _ => return Errno::Inval, }; @@ -3672,14 +3673,14 @@ 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, @@ -3691,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(); @@ -3701,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, }; @@ -3722,11 +3723,11 @@ pub fn process_spawn( let conv_stdio_fd = |a: Option| match a { Some(fd) => OptionFd { - tag: __WASI_OPTION_SOME, + tag: OptionTag::Some, fd: fd.into(), }, None => OptionFd { - tag: __WASI_OPTION_NONE, + tag: OptionTag::None, fd: 0, }, }; @@ -3773,14 +3774,14 @@ pub fn bus_open_local( ctx: FunctionEnvMut<'_, WasiEnv>, name: WasmPtr, name_len: M::Offset, - reuse: __wasi_bool_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) @@ -3804,7 +3805,7 @@ 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, @@ -3817,7 +3818,7 @@ pub fn bus_open_remote( 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 @@ -3914,7 +3915,7 @@ pub fn bus_close(ctx: FunctionEnvMut<'_, WasiEnv>, bid: Bid) -> BusErrno { pub fn bus_call( ctx: FunctionEnvMut<'_, WasiEnv>, bid: Bid, - keep_alive: __wasi_bool_t, + keep_alive: Bool, topic: WasmPtr, topic_len: M::Offset, format: BusDataFormat, @@ -3926,7 +3927,7 @@ pub fn bus_call( 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, @@ -3951,7 +3952,7 @@ pub fn bus_call( pub fn bus_subcall( ctx: FunctionEnvMut<'_, WasiEnv>, parent: Cid, - keep_alive: __wasi_bool_t, + keep_alive: Bool, topic: WasmPtr, topic_len: M::Offset, format: BusDataFormat, @@ -3963,7 +3964,7 @@ pub fn bus_subcall( 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, @@ -4136,7 +4137,7 @@ pub fn http_request( method_len: M::Offset, headers: WasmPtr, headers_len: M::Offset, - gzip: __wasi_bool_t, + gzip: Bool, ret_handles: WasmPtr<__wasi_http_handles_t, M>, ) -> Errno { debug!("wasi::http_request"); @@ -4147,8 +4148,8 @@ 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, + Bool::False => false, + Bool::True => true, _ => return Errno::Inval, }; @@ -4258,10 +4259,10 @@ pub fn http_status( // Write everything else and return the status to the caller let status = __wasi_http_status_t { - ok: __WASI_BOOL_TRUE, + 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, @@ -4456,8 +4457,8 @@ 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>, + preferred_until: WasmPtr, + expires_at: WasmPtr, ) -> Errno { debug!("wasi::port_route_add"); let env = ctx.data(); @@ -4466,14 +4467,14 @@ 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)), + 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)), + OptionTag::None => None, + OptionTag::Some => Some(Duration::from_nanos(expires_at.u)), _ => return Errno::Inval, }; @@ -4696,7 +4697,7 @@ pub fn sock_open( ctx: FunctionEnvMut<'_, WasiEnv>, af: Addressfamily, ty: Socktype, - pt: __wasi_sockproto_t, + pt: SockProto, ro_sock: WasmPtr, ) -> Errno { debug!("wasi::sock_open"); @@ -4754,13 +4755,13 @@ pub fn sock_set_opt_flag( ctx: FunctionEnvMut<'_, WasiEnv>, sock: WasiFd, opt: Sockoption, - flag: __wasi_bool_t, + flag: Bool, ) -> Errno { debug!("wasi::sock_set_opt_flag(ty={})", opt); let flag = match flag { - __WASI_BOOL_FALSE => false, - __WASI_BOOL_TRUE => true, + Bool::False => false, + Bool::True => true, _ => return Errno::Inval, }; @@ -4783,7 +4784,7 @@ pub fn sock_get_opt_flag( ctx: FunctionEnvMut<'_, WasiEnv>, sock: WasiFd, opt: Sockoption, - ret_flag: WasmPtr<__wasi_bool_t, M>, + ret_flag: WasmPtr, ) -> Errno { debug!("wasi::sock_get_opt_flag(ty={})", opt); let env = ctx.data(); @@ -4794,8 +4795,8 @@ pub fn sock_get_opt_flag( 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)); @@ -4815,7 +4816,7 @@ pub fn sock_set_opt_time( ctx: FunctionEnvMut<'_, WasiEnv>, sock: WasiFd, opt: Sockoption, - time: WasmPtr<__wasi_option_timestamp_t, M>, + time: WasmPtr, ) -> Errno { debug!("wasi::sock_set_opt_time(ty={})", opt); @@ -4823,8 +4824,8 @@ pub fn sock_set_opt_time( 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)), + OptionTag::None => None, + OptionTag::Some => Some(Duration::from_nanos(time.u)), _ => return Errno::Inval, }; @@ -4855,7 +4856,7 @@ pub fn sock_get_opt_time( ctx: FunctionEnvMut<'_, WasiEnv>, sock: WasiFd, opt: Sockoption, - ret_time: WasmPtr<__wasi_option_timestamp_t, M>, + ret_time: WasmPtr, ) -> Errno { debug!("wasi::sock_get_opt_time(ty={})", opt); let env = ctx.data(); @@ -4874,12 +4875,12 @@ pub fn sock_get_opt_time( 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, + Some(timeout) => OptionTimestamp { + tag: OptionTag::Some, u: timeout.as_nanos() as Timestamp, }, }; diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index 739b8e19f27..d5ec41bb68f 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -458,7 +458,7 @@ pub(crate) fn thread_spawn( method: WasmPtr, method_len: MemoryOffset, user_data: u64, - reactor: __wasi_bool_t, + reactor: Bool, ret_tid: WasmPtr, ) -> Errno { super::thread_spawn::(ctx, method, method_len, user_data, reactor, ret_tid) @@ -505,14 +505,14 @@ 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, @@ -539,7 +539,7 @@ pub(crate) fn bus_open_local( ctx: FunctionEnvMut, name: WasmPtr, name_len: MemoryOffset, - reuse: __wasi_bool_t, + reuse: Bool, ret_bid: WasmPtr, ) -> BusErrno { super::bus_open_local::(ctx, name, name_len, reuse, ret_bid) @@ -549,7 +549,7 @@ 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, @@ -576,7 +576,7 @@ pub(crate) fn bus_close(ctx: FunctionEnvMut, bid: Bid) -> BusErrno { pub(crate) fn bus_call( ctx: FunctionEnvMut, bid: Bid, - keep_alive: __wasi_bool_t, + keep_alive: Bool, topic: WasmPtr, topic_len: MemoryOffset, format: BusDataFormat, @@ -592,7 +592,7 @@ pub(crate) fn bus_call( pub(crate) fn bus_subcall( ctx: FunctionEnvMut, parent: Cid, - keep_alive: __wasi_bool_t, + keep_alive: Bool, topic: WasmPtr, topic_len: MemoryOffset, format: BusDataFormat, @@ -706,8 +706,8 @@ 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>, + preferred_until: WasmPtr, + expires_at: WasmPtr, ) -> Errno { super::port_route_add::(ctx, cidr, via_router, preferred_until, expires_at) } @@ -748,7 +748,7 @@ pub(crate) fn http_request( method_len: MemoryOffset, headers: WasmPtr, headers_len: MemoryOffset, - gzip: __wasi_bool_t, + gzip: Bool, ret_handles: WasmPtr<__wasi_http_handles_t, MemoryType>, ) -> Errno { super::http_request::( @@ -804,7 +804,7 @@ pub(crate) fn sock_open( ctx: FunctionEnvMut, af: Addressfamily, ty: Socktype, - pt: __wasi_sockproto_t, + pt: SockProto, ro_sock: WasmPtr, ) -> Errno { super::sock_open::(ctx, af, ty, pt, ro_sock) @@ -814,7 +814,7 @@ pub(crate) fn sock_set_opt_flag( ctx: FunctionEnvMut, sock: Fd, opt: Sockoption, - flag: __wasi_bool_t, + flag: Bool, ) -> Errno { super::sock_set_opt_flag(ctx, sock, opt, flag) } @@ -823,7 +823,7 @@ pub(crate) fn sock_get_opt_flag( ctx: FunctionEnvMut, sock: Fd, opt: Sockoption, - ret_flag: WasmPtr<__wasi_bool_t, MemoryType>, + ret_flag: WasmPtr, ) -> Errno { super::sock_get_opt_flag::(ctx, sock, opt, ret_flag) } @@ -832,7 +832,7 @@ pub fn sock_set_opt_time( ctx: FunctionEnvMut, sock: Fd, opt: Sockoption, - time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, + time: WasmPtr, ) -> Errno { super::sock_set_opt_time(ctx, sock, opt, time) } @@ -841,7 +841,7 @@ pub fn sock_get_opt_time( ctx: FunctionEnvMut, sock: Fd, opt: Sockoption, - ret_time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, + ret_time: WasmPtr, ) -> Errno { super::sock_get_opt_time(ctx, sock, opt, ret_time) } diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index 72cfd1488b2..43cb55f7af6 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -458,7 +458,7 @@ pub(crate) fn thread_spawn( method: WasmPtr, method_len: MemoryOffset, user_data: u64, - reactor: __wasi_bool_t, + reactor: Bool, ret_tid: WasmPtr, ) -> Errno { super::thread_spawn::(ctx, method, method_len, user_data, reactor, ret_tid) @@ -505,14 +505,14 @@ 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, @@ -539,7 +539,7 @@ pub(crate) fn bus_open_local( ctx: FunctionEnvMut, name: WasmPtr, name_len: MemoryOffset, - reuse: __wasi_bool_t, + reuse: Bool, ret_bid: WasmPtr, ) -> BusErrno { super::bus_open_local::(ctx, name, name_len, reuse, ret_bid) @@ -549,7 +549,7 @@ 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, @@ -576,7 +576,7 @@ pub(crate) fn bus_close(ctx: FunctionEnvMut, bid: Bid) -> BusErrno { pub(crate) fn bus_call( ctx: FunctionEnvMut, bid: Bid, - keep_alive: __wasi_bool_t, + keep_alive: Bool, topic: WasmPtr, topic_len: MemoryOffset, format: BusDataFormat, @@ -592,7 +592,7 @@ pub(crate) fn bus_call( pub(crate) fn bus_subcall( ctx: FunctionEnvMut, parent: Cid, - keep_alive: __wasi_bool_t, + keep_alive: Bool, topic: WasmPtr, topic_len: MemoryOffset, format: BusDataFormat, @@ -706,8 +706,8 @@ 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>, + preferred_until: WasmPtr, + expires_at: WasmPtr, ) -> Errno { super::port_route_add::(ctx, cidr, via_router, preferred_until, expires_at) } @@ -748,7 +748,7 @@ pub(crate) fn http_request( method_len: MemoryOffset, headers: WasmPtr, headers_len: MemoryOffset, - gzip: __wasi_bool_t, + gzip: Bool, ret_handles: WasmPtr<__wasi_http_handles_t, MemoryType>, ) -> Errno { super::http_request::( @@ -804,7 +804,7 @@ pub(crate) fn sock_open( ctx: FunctionEnvMut, af: Addressfamily, ty: Socktype, - pt: __wasi_sockproto_t, + pt: SockProto, ro_sock: WasmPtr, ) -> Errno { super::sock_open::(ctx, af, ty, pt, ro_sock) @@ -814,7 +814,7 @@ pub(crate) fn sock_set_opt_flag( ctx: FunctionEnvMut, sock: Fd, opt: Sockoption, - flag: __wasi_bool_t, + flag: Bool, ) -> Errno { super::sock_set_opt_flag(ctx, sock, opt, flag) } @@ -823,7 +823,7 @@ pub(crate) fn sock_get_opt_flag( ctx: FunctionEnvMut, sock: Fd, opt: Sockoption, - ret_flag: WasmPtr<__wasi_bool_t, MemoryType>, + ret_flag: WasmPtr, ) -> Errno { super::sock_get_opt_flag::(ctx, sock, opt, ret_flag) } @@ -832,7 +832,7 @@ pub fn sock_set_opt_time( ctx: FunctionEnvMut, sock: Fd, opt: Sockoption, - time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, + time: WasmPtr, ) -> Errno { super::sock_set_opt_time(ctx, sock, opt, time) } @@ -841,7 +841,7 @@ pub fn sock_get_opt_time( ctx: FunctionEnvMut, sock: Fd, opt: Sockoption, - ret_time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, + ret_time: WasmPtr, ) -> Errno { super::sock_get_opt_time(ctx, sock, opt, ret_time) } From 4e353352b20a94a32ce288c60471a4865f4e577e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 8 Sep 2022 14:24:03 +0200 Subject: [PATCH 56/84] Port signal::Signal --- lib/wasi-types-generated/src/wasi/bindings.rs | 130 ++++++++++++++++++ lib/wasi-types-generated/src/wasi/extra.rs | 126 +++++++++++++++++ lib/wasi-types-generated/wit-clean/output.wit | 33 +++++ .../wit-clean/typenames.wit | 33 +++++ lib/wasi-types/src/lib.rs | 44 +----- lib/wasi/src/syscalls/mod.rs | 4 +- lib/wasi/src/syscalls/wasi.rs | 2 +- lib/wasi/src/syscalls/wasix32.rs | 2 +- lib/wasi/src/syscalls/wasix64.rs | 2 +- 9 files changed, 334 insertions(+), 42 deletions(-) diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index 64030825c2e..c7f2dd5b482 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -2778,6 +2778,136 @@ pub mod output { 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() + } + } + } + } /// Dummy function to expose types into generated code pub fn expose_types_dummy_func(fd: Fd,dirent: Dirent,snapshot0_dirent: Snapshot0Dirent,snapshot0_event: Snapshot0Event,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,tid: Tid,pid: Pid,bus_data_format: BusDataFormat,bid: Bid,option_bid: OptionBid,cid: Cid,option_cid: OptionCid,option_fd: OptionFd,bus_handles: BusHandles,exit_code: ExitCode,bus_event_exit: BusEventExit,bus_event_fault: BusEventFault,bus_event_close: BusEventClose,prestat_u_dir: PrestatUDir,prestat_u: PrestatU,event_fd_flags: EventFdFlags,prestat: Prestat,file_delta: FileDelta,lookup_flags: LookupFlags,count: Count,bool: Bool,pipe_handles: PipeHandles,stdio_mode: StdioMode,sock_proto: SockProto,option_timestamp: OptionTimestamp,) -> (){ unsafe { diff --git a/lib/wasi-types-generated/src/wasi/extra.rs b/lib/wasi-types-generated/src/wasi/extra.rs index 241e988ebb2..877a211406e 100644 --- a/lib/wasi-types-generated/src/wasi/extra.rs +++ b/lib/wasi-types-generated/src/wasi/extra.rs @@ -2505,6 +2505,76 @@ impl core::fmt::Debug for OptionTimestamp { .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(), + } + } +} /// Dummy function to expose types into generated code pub fn expose_types_dummy_func( fd: Fd, @@ -4719,3 +4789,59 @@ 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"), + } + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } +} diff --git a/lib/wasi-types-generated/wit-clean/output.wit b/lib/wasi-types-generated/wit-clean/output.wit index ae95bfed82d..06cb2965648 100644 --- a/lib/wasi-types-generated/wit-clean/output.wit +++ b/lib/wasi-types-generated/wit-clean/output.wit @@ -1209,6 +1209,39 @@ enum %bool { 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, }// WASI Preview. This is an evolution of the API that WASI initially // launched with. // diff --git a/lib/wasi-types-generated/wit-clean/typenames.wit b/lib/wasi-types-generated/wit-clean/typenames.wit index 6f78497175e..f4373c95bda 100644 --- a/lib/wasi-types-generated/wit-clean/typenames.wit +++ b/lib/wasi-types-generated/wit-clean/typenames.wit @@ -1209,4 +1209,37 @@ enum %bool { 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, } \ No newline at end of file diff --git a/lib/wasi-types/src/lib.rs b/lib/wasi-types/src/lib.rs index b8a6b6f94e1..00a858f7ad6 100644 --- a/lib/wasi-types/src/lib.rs +++ b/lib/wasi-types/src/lib.rs @@ -204,6 +204,12 @@ pub mod io { } } +pub mod time { + use wasmer_derive::ValueType; + pub use wasmer_wasi_types_generated::wasi::OptionTimestamp; + use wasmer_wasi_types_generated::wasi::{OptionTag, Timestamp}; +} + // --- not ported pub mod net { @@ -388,37 +394,7 @@ pub mod net { } pub mod signal { - 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; + pub use wasmer_wasi_types_generated::wasi::Signal; } pub mod subscription { @@ -548,9 +524,3 @@ pub mod subscription { */ } - -pub mod time { - use wasmer_derive::ValueType; - pub use wasmer_wasi_types_generated::wasi::OptionTimestamp; - use wasmer_wasi_types_generated::wasi::{OptionTag, Timestamp}; -} diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index b61b920460c..732831ab65f 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -3276,9 +3276,9 @@ 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) -> Errno { +pub fn proc_raise(ctx: FunctionEnvMut<'_, WasiEnv>, sig: Signal) -> Errno { debug!("wasi::proc_raise"); unimplemented!("wasi::proc_raise") } diff --git a/lib/wasi/src/syscalls/wasi.rs b/lib/wasi/src/syscalls/wasi.rs index 3ba116a5149..15a09df2286 100644 --- a/lib/wasi/src/syscalls/wasi.rs +++ b/lib/wasi/src/syscalls/wasi.rs @@ -393,7 +393,7 @@ pub(crate) fn proc_exit( super::proc_exit(ctx, code) } -pub(crate) fn proc_raise(ctx: FunctionEnvMut, sig: __wasi_signal_t) -> Errno { +pub(crate) fn proc_raise(ctx: FunctionEnvMut, sig: Signal) -> Errno { super::proc_raise(ctx, sig) } diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index d5ec41bb68f..6270d84df34 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -392,7 +392,7 @@ pub(crate) fn proc_exit( super::proc_exit(ctx, code) } -pub(crate) fn proc_raise(ctx: FunctionEnvMut, sig: __wasi_signal_t) -> Errno { +pub(crate) fn proc_raise(ctx: FunctionEnvMut, sig: Signal) -> Errno { super::proc_raise(ctx, sig) } diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index 43cb55f7af6..bddfc9b9aeb 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -392,7 +392,7 @@ pub(crate) fn proc_exit( super::proc_exit(ctx, code) } -pub(crate) fn proc_raise(ctx: FunctionEnvMut, sig: __wasi_signal_t) -> Errno { +pub(crate) fn proc_raise(ctx: FunctionEnvMut, sig: Signal) -> Errno { super::proc_raise(ctx, sig) } From daa20bfe17076c4c0cca411707d5b36aea56cb33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 8 Sep 2022 15:53:11 +0200 Subject: [PATCH 57/84] Port "net" module to .wit (finished porting wasi-types) --- lib/wasi-types-generated/src/wasi/bindings.rs | 123 +++++++++- lib/wasi-types-generated/src/wasi/extra.rs | 218 +++++++++++++++++- lib/wasi-types-generated/wit-clean/output.wit | 52 +++++ .../wit-clean/typenames.wit | 52 +++++ lib/wasi-types/src/lib.rs | 69 +----- lib/wasi/src/state/socket.rs | 6 +- lib/wasi/src/syscalls/mod.rs | 28 +-- lib/wasi/src/syscalls/wasi.rs | 8 +- lib/wasi/src/syscalls/wasix32.rs | 24 +- lib/wasi/src/syscalls/wasix64.rs | 24 +- 10 files changed, 490 insertions(+), 114 deletions(-) diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index c7f2dd5b482..cc6267a34cc 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -2908,8 +2908,90 @@ pub mod output { } } } + #[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() + } + } + } + } /// Dummy function to expose types into generated code - pub fn expose_types_dummy_func(fd: Fd,dirent: Dirent,snapshot0_dirent: Snapshot0Dirent,snapshot0_event: Snapshot0Event,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,tid: Tid,pid: Pid,bus_data_format: BusDataFormat,bid: Bid,option_bid: OptionBid,cid: Cid,option_cid: OptionCid,option_fd: OptionFd,bus_handles: BusHandles,exit_code: ExitCode,bus_event_exit: BusEventExit,bus_event_fault: BusEventFault,bus_event_close: BusEventClose,prestat_u_dir: PrestatUDir,prestat_u: PrestatU,event_fd_flags: EventFdFlags,prestat: Prestat,file_delta: FileDelta,lookup_flags: LookupFlags,count: Count,bool: Bool,pipe_handles: PipeHandles,stdio_mode: StdioMode,sock_proto: SockProto,option_timestamp: OptionTimestamp,) -> (){ + pub fn expose_types_dummy_func(fd: Fd,dirent: Dirent,snapshot0_dirent: Snapshot0Dirent,snapshot0_event: Snapshot0Event,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,tid: Tid,pid: Pid,bus_data_format: BusDataFormat,bid: Bid,option_bid: OptionBid,cid: Cid,option_cid: OptionCid,option_fd: OptionFd,bus_handles: BusHandles,exit_code: ExitCode,bus_event_exit: BusEventExit,bus_event_fault: BusEventFault,bus_event_close: BusEventClose,prestat_u_dir: PrestatUDir,prestat_u: PrestatU,event_fd_flags: EventFdFlags,prestat: Prestat,file_delta: FileDelta,lookup_flags: LookupFlags,count: Count,bool: Bool,pipe_handles: PipeHandles,stdio_mode: StdioMode,sock_proto: SockProto,option_timestamp: OptionTimestamp,addr_unspec: AddrUnspec,addr_unspec_port: AddrUnspecPort,cidr_unspec: CidrUnspec,http_handles: HttpHandles,http_status: HttpStatus,ri_flags: RiFlags,ro_flags: RoFlags,sd_flags: SdFlags,si_flags: SiFlags,timeout: Timeout,) -> (){ unsafe { let ptr0 = OUTPUT_RET_AREA.0.as_mut_ptr() as i32; *((ptr0 + 0) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd); @@ -3702,6 +3784,41 @@ pub mod output { OptionTag::Some => 1, }) as u8; *((ptr0 + 680) as *mut i64) = wit_bindgen_rust::rt::as_i64(u53); + let AddrUnspec{ n0:n054, } = addr_unspec; + *((ptr0 + 688) as *mut u8) = (wit_bindgen_rust::rt::as_i32(n054)) as u8; + let AddrUnspecPort{ port:port55, addr:addr55, } = addr_unspec_port; + *((ptr0 + 690) as *mut u16) = (wit_bindgen_rust::rt::as_i32(port55)) as u16; + let AddrUnspec{ n0:n056, } = addr55; + *((ptr0 + 692) as *mut u8) = (wit_bindgen_rust::rt::as_i32(n056)) as u8; + let CidrUnspec{ addr:addr57, prefix:prefix57, } = cidr_unspec; + let AddrUnspec{ n0:n058, } = addr57; + *((ptr0 + 694) as *mut u8) = (wit_bindgen_rust::rt::as_i32(n058)) as u8; + *((ptr0 + 695) as *mut u8) = (wit_bindgen_rust::rt::as_i32(prefix57)) as u8; + let HttpHandles{ req:req59, res:res59, hdr:hdr59, } = http_handles; + *((ptr0 + 696) as *mut i32) = wit_bindgen_rust::rt::as_i32(req59); + *((ptr0 + 700) as *mut i32) = wit_bindgen_rust::rt::as_i32(res59); + *((ptr0 + 704) as *mut i32) = wit_bindgen_rust::rt::as_i32(hdr59); + let HttpStatus{ ok:ok60, redirect:redirect60, size:size60, status:status60, } = http_status; + *((ptr0 + 712) as *mut u8) = (match ok60 { + Bool::False => 0, + Bool::True => 1, + }) as u8; + *((ptr0 + 713) as *mut u8) = (match redirect60 { + Bool::False => 0, + Bool::True => 1, + }) as u8; + *((ptr0 + 720) as *mut i64) = wit_bindgen_rust::rt::as_i64(size60); + *((ptr0 + 728) as *mut u16) = (wit_bindgen_rust::rt::as_i32(status60)) as u16; + *((ptr0 + 736) as *mut u16) = (wit_bindgen_rust::rt::as_i32(ri_flags)) as u16; + *((ptr0 + 738) as *mut u16) = (wit_bindgen_rust::rt::as_i32(ro_flags)) as u16; + *((ptr0 + 740) as *mut u8) = (wit_bindgen_rust::rt::as_i32(sd_flags)) as u8; + *((ptr0 + 742) as *mut u16) = (wit_bindgen_rust::rt::as_i32(si_flags)) as u16; + *((ptr0 + 744) as *mut u8) = (match timeout { + Timeout::Read => 0, + Timeout::Write => 1, + Timeout::Connect => 2, + Timeout::Accept => 3, + }) as u8; #[link(wasm_import_module = "output")] extern "C" { #[cfg_attr(target_arch = "wasm32", link_name = "expose-types-dummy-func")] @@ -3714,6 +3831,6 @@ pub mod output { } #[repr(align(8))] - struct RetArea([u8; 688]); - static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 688]); + struct RetArea([u8; 752]); + static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 752]); } diff --git a/lib/wasi-types-generated/src/wasi/extra.rs b/lib/wasi-types-generated/src/wasi/extra.rs index 877a211406e..a3643879977 100644 --- a/lib/wasi-types-generated/src/wasi/extra.rs +++ b/lib/wasi-types-generated/src/wasi/extra.rs @@ -2575,6 +2575,100 @@ impl core::fmt::Debug for Signal { } } } +#[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(), + } + } +} /// Dummy function to expose types into generated code pub fn expose_types_dummy_func( fd: Fd, @@ -2619,6 +2713,16 @@ pub fn expose_types_dummy_func( stdio_mode: StdioMode, sock_proto: SockProto, option_timestamp: OptionTimestamp, + addr_unspec: AddrUnspec, + addr_unspec_port: AddrUnspecPort, + cidr_unspec: CidrUnspec, + http_handles: HttpHandles, + http_status: HttpStatus, + ri_flags: RiFlags, + ro_flags: RoFlags, + sd_flags: SdFlags, + si_flags: SiFlags, + timeout: Timeout, ) -> () { unsafe { let ptr0 = OUTPUT_RET_AREA.0.as_mut_ptr() as i32; @@ -3559,6 +3663,56 @@ pub fn expose_types_dummy_func( OptionTag::Some => 1, }) as u8; *((ptr0 + 680) as *mut i64) = wit_bindgen_rust::rt::as_i64(u53); + let AddrUnspec { n0: n054 } = addr_unspec; + *((ptr0 + 688) as *mut u8) = (wit_bindgen_rust::rt::as_i32(n054)) as u8; + let AddrUnspecPort { + port: port55, + addr: addr55, + } = addr_unspec_port; + *((ptr0 + 690) as *mut u16) = (wit_bindgen_rust::rt::as_i32(port55)) as u16; + let AddrUnspec { n0: n056 } = addr55; + *((ptr0 + 692) as *mut u8) = (wit_bindgen_rust::rt::as_i32(n056)) as u8; + let CidrUnspec { + addr: addr57, + prefix: prefix57, + } = cidr_unspec; + let AddrUnspec { n0: n058 } = addr57; + *((ptr0 + 694) as *mut u8) = (wit_bindgen_rust::rt::as_i32(n058)) as u8; + *((ptr0 + 695) as *mut u8) = (wit_bindgen_rust::rt::as_i32(prefix57)) as u8; + let HttpHandles { + req: req59, + res: res59, + hdr: hdr59, + } = http_handles; + *((ptr0 + 696) as *mut i32) = wit_bindgen_rust::rt::as_i32(req59); + *((ptr0 + 700) as *mut i32) = wit_bindgen_rust::rt::as_i32(res59); + *((ptr0 + 704) as *mut i32) = wit_bindgen_rust::rt::as_i32(hdr59); + let HttpStatus { + ok: ok60, + redirect: redirect60, + size: size60, + status: status60, + } = http_status; + *((ptr0 + 712) as *mut u8) = (match ok60 { + Bool::False => 0, + Bool::True => 1, + }) as u8; + *((ptr0 + 713) as *mut u8) = (match redirect60 { + Bool::False => 0, + Bool::True => 1, + }) as u8; + *((ptr0 + 720) as *mut i64) = wit_bindgen_rust::rt::as_i64(size60); + *((ptr0 + 728) as *mut u16) = (wit_bindgen_rust::rt::as_i32(status60)) as u16; + *((ptr0 + 736) as *mut u16) = (wit_bindgen_rust::rt::as_i32(ri_flags)) as u16; + *((ptr0 + 738) as *mut u16) = (wit_bindgen_rust::rt::as_i32(ro_flags)) as u16; + *((ptr0 + 740) as *mut u8) = (wit_bindgen_rust::rt::as_i32(sd_flags)) as u8; + *((ptr0 + 742) as *mut u16) = (wit_bindgen_rust::rt::as_i32(si_flags)) as u16; + *((ptr0 + 744) as *mut u8) = (match timeout { + Timeout::Read => 0, + Timeout::Write => 1, + Timeout::Connect => 2, + Timeout::Accept => 3, + }) as u8; #[link(wasm_import_module = "output")] extern "C" { #[cfg_attr(target_arch = "wasm32", link_name = "expose-types-dummy-func")] @@ -3574,8 +3728,8 @@ pub fn expose_types_dummy_func( } #[repr(align(8))] -struct RetArea([u8; 688]); -static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 688]); +struct RetArea([u8; 752]); +static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 752]); // TODO: if necessary, must be implemented in wit-bindgen unsafe impl ValueType for Snapshot0Clockid { @@ -4845,3 +4999,63 @@ unsafe impl wasmer::FromToNativeWasmType for Signal { 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"), + } + } + + #[cfg(feature = "sys")] + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { + false + } +} diff --git a/lib/wasi-types-generated/wit-clean/output.wit b/lib/wasi-types-generated/wit-clean/output.wit index 06cb2965648..a8645feb1d1 100644 --- a/lib/wasi-types-generated/wit-clean/output.wit +++ b/lib/wasi-types-generated/wit-clean/output.wit @@ -48,6 +48,16 @@ expose-types-dummy-func: func( stdio-mode: stdio-mode, sock-proto: sock-proto, option-timestamp: option-timestamp, + addr-unspec: addr-unspec, + addr-unspec-port: addr-unspec-port, + cidr-unspec: cidr-unspec, + http-handles: http-handles, + http-status: http-status, + ri-flags: ri-flags, + ro-flags: ro-flags, + sd-flags: sd-flags, + si-flags: si-flags, + timeout: timeout, ) /// Type names used by low-level WASI interfaces. @@ -1242,6 +1252,48 @@ enum signal { 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. // diff --git a/lib/wasi-types-generated/wit-clean/typenames.wit b/lib/wasi-types-generated/wit-clean/typenames.wit index f4373c95bda..0385e7c7b72 100644 --- a/lib/wasi-types-generated/wit-clean/typenames.wit +++ b/lib/wasi-types-generated/wit-clean/typenames.wit @@ -48,6 +48,16 @@ expose-types-dummy-func: func( stdio-mode: stdio-mode, sock-proto: sock-proto, option-timestamp: option-timestamp, + addr-unspec: addr-unspec, + addr-unspec-port: addr-unspec-port, + cidr-unspec: cidr-unspec, + http-handles: http-handles, + http-status: http-status, + ri-flags: ri-flags, + ro-flags: ro-flags, + sd-flags: sd-flags, + si-flags: si-flags, + timeout: timeout, ) /// Type names used by low-level WASI interfaces. @@ -1242,4 +1252,46 @@ enum signal { 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/src/lib.rs b/lib/wasi-types/src/lib.rs index 00a858f7ad6..cc7d62d70fd 100644 --- a/lib/wasi-types/src/lib.rs +++ b/lib/wasi-types/src/lib.rs @@ -210,8 +210,6 @@ pub mod time { use wasmer_wasi_types_generated::wasi::{OptionTag, Timestamp}; } -// --- not ported - pub mod net { use super::*; use wasmer_derive::ValueType; @@ -219,7 +217,10 @@ pub mod net { use crate::OptionTimestamp; - pub use wasmer_wasi_types_generated::wasi::SockProto; + pub use wasmer_wasi_types_generated::wasi::{ + AddrUnspec, AddrUnspecPort, CidrUnspec, HttpHandles, HttpStatus, RiFlags, RoFlags, SdFlags, + SiFlags, SockProto, Timeout, + }; #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] #[repr(C)] @@ -227,26 +228,6 @@ pub mod net { pub octs: [u8; 6], } - #[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 { @@ -348,49 +329,21 @@ pub mod net { #[derive(Debug, Copy, Clone, ValueType)] #[repr(C)] - pub struct __wasi_route_t { + pub struct Route { pub cidr: __wasi_cidr_t, pub via_router: __wasi_addr_t, pub preferred_until: OptionTimestamp, pub expires_at: OptionTimestamp, } - #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] - #[repr(C)] - pub struct __wasi_http_handles_t { - pub req: Fd, - pub res: Fd, - pub hdr: Fd, - } - - #[derive(Debug, Copy, Clone, PartialEq, Eq, ValueType)] - #[repr(C)] - pub struct __wasi_http_status_t { - pub ok: Bool, - pub redirect: Bool, - pub size: Filesize, - 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 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 type __wasi_siflags_t = u16; + pub const __WASI_SOCK_RECV_OUTPUT_DATA_TRUNCATED: RoFlags = 1 << 0; - 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; + pub const __WASI_SHUT_RD: SdFlags = 1 << 0; + pub const __WASI_SHUT_WR: SdFlags = 1 << 1; } pub mod signal { diff --git a/lib/wasi/src/state/socket.rs b/lib/wasi/src/state/socket.rs index ee5d07b7bb1..e1f3ce58d75 100644 --- a/lib/wasi/src/state/socket.rs +++ b/lib/wasi/src/state/socket.rs @@ -1322,7 +1322,7 @@ pub(crate) fn write_ip_port( #[allow(dead_code)] pub(crate) fn read_route( memory: &MemoryView, - ptr: WasmPtr<__wasi_route_t, M>, + ptr: WasmPtr, ) -> Result { let route_ptr = ptr.deref(memory); let route = route_ptr.read().map_err(crate::mem_error_to_wasi)?; @@ -1375,7 +1375,7 @@ pub(crate) fn read_route( pub(crate) fn write_route( memory: &MemoryView, - ptr: WasmPtr<__wasi_route_t, M>, + ptr: WasmPtr, route: IpRoute, ) -> Result<(), Errno> { let cidr = { @@ -1445,7 +1445,7 @@ pub(crate) fn write_route( }, }; - let route = __wasi_route_t { + let route = Route { cidr, via_router, preferred_until, diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 732831ab65f..158b4c7fc63 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -4138,7 +4138,7 @@ pub fn http_request( headers: WasmPtr, headers_len: M::Offset, gzip: Bool, - ret_handles: WasmPtr<__wasi_http_handles_t, M>, + ret_handles: WasmPtr, ) -> Errno { debug!("wasi::http_request"); let env = ctx.data(); @@ -4217,7 +4217,7 @@ pub fn http_request( ); let rights = Rights::all_socket(); - let handles = __wasi_http_handles_t { + let handles = HttpHandles { req: wasi_try!(state .fs .create_fd(rights, rights, Fdflags::empty(), 0, inode_req)), @@ -4245,7 +4245,7 @@ pub fn http_request( pub fn http_status( ctx: FunctionEnvMut<'_, WasiEnv>, sock: WasiFd, - status: WasmPtr<__wasi_http_status_t, M>, + status: WasmPtr, ) -> Errno { debug!("wasi::http_status"); @@ -4258,7 +4258,7 @@ pub fn http_status( })); // Write everything else and return the status to the caller - let status = __wasi_http_status_t { + let status = HttpStatus { ok: Bool::True, redirect: match http_status.redirected { true => Bool::True, @@ -4519,7 +4519,7 @@ pub fn port_route_clear(ctx: FunctionEnvMut<'_, WasiEnv>) -> Errno { /// * `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, ) -> Errno { debug!("wasi::port_route_list"); @@ -4558,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: WasiFd, - how: __wasi_sdflags_t, -) -> Errno { +pub fn sock_shutdown(ctx: FunctionEnvMut<'_, WasiEnv>, sock: WasiFd, how: SdFlags) -> Errno { debug!("wasi::sock_shutdown"); let both = __WASI_SHUT_RD | __WASI_SHUT_WR; @@ -5239,9 +5235,9 @@ pub fn sock_recv( 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, ) -> Result { debug!("wasi::sock_recv"); @@ -5278,9 +5274,9 @@ pub fn sock_recv_from( 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 { debug!("wasi::sock_recv_from"); @@ -5321,7 +5317,7 @@ pub fn sock_send( 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 { debug!("wasi::sock_send"); @@ -5360,7 +5356,7 @@ pub fn sock_send_to( 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 { diff --git a/lib/wasi/src/syscalls/wasi.rs b/lib/wasi/src/syscalls/wasi.rs index 15a09df2286..9e8c5d4ba02 100644 --- a/lib/wasi/src/syscalls/wasi.rs +++ b/lib/wasi/src/syscalls/wasi.rs @@ -414,9 +414,9 @@ pub(crate) fn sock_recv( 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>, + ro_flags: WasmPtr, ) -> Result { super::sock_recv::( ctx, @@ -434,7 +434,7 @@ pub(crate) fn sock_send( 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 { super::sock_send::(ctx, sock, si_data, si_data_len, si_flags, ret_data_len) @@ -443,7 +443,7 @@ pub(crate) fn sock_send( pub(crate) fn sock_shutdown( ctx: FunctionEnvMut, sock: WasiFd, - how: __wasi_sdflags_t, + 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 6270d84df34..36d7dafcb2a 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -725,7 +725,7 @@ pub(crate) fn port_route_clear(ctx: FunctionEnvMut) -> Errno { pub(crate) fn port_route_list( ctx: FunctionEnvMut, - routes: WasmPtr<__wasi_route_t, MemoryType>, + routes: WasmPtr, nroutes: WasmPtr, ) -> Errno { super::port_route_list::(ctx, routes, nroutes) @@ -749,7 +749,7 @@ pub(crate) fn http_request( headers: WasmPtr, headers_len: MemoryOffset, gzip: Bool, - ret_handles: WasmPtr<__wasi_http_handles_t, MemoryType>, + ret_handles: WasmPtr, ) -> Errno { super::http_request::( ctx, @@ -767,7 +767,7 @@ pub(crate) fn http_request( pub(crate) fn http_status( ctx: FunctionEnvMut, sock: Fd, - status: WasmPtr<__wasi_http_status_t, MemoryType>, + status: WasmPtr, status_text: WasmPtr, status_text_len: WasmPtr, headers: WasmPtr, @@ -935,9 +935,9 @@ pub(crate) fn sock_recv( 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, ) -> Result { super::sock_recv::( ctx, @@ -955,9 +955,9 @@ pub(crate) fn sock_recv_from( 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 { super::sock_recv_from::( @@ -977,7 +977,7 @@ pub(crate) fn sock_send( 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 { super::sock_send::(ctx, sock, si_data, si_data_len, si_flags, ret_data_len) @@ -988,7 +988,7 @@ pub(crate) fn sock_send_to( 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 { @@ -1014,11 +1014,7 @@ pub(crate) fn sock_send_file( unsafe { super::sock_send_file::(ctx, out_fd, in_fd, offset, count, ret_sent) } } -pub(crate) fn sock_shutdown( - ctx: FunctionEnvMut, - sock: Fd, - how: __wasi_sdflags_t, -) -> Errno { +pub(crate) fn sock_shutdown(ctx: FunctionEnvMut, sock: Fd, how: SdFlags) -> Errno { super::sock_shutdown(ctx, sock, how) } diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index bddfc9b9aeb..e70df788ea7 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -725,7 +725,7 @@ pub(crate) fn port_route_clear(ctx: FunctionEnvMut) -> Errno { pub(crate) fn port_route_list( ctx: FunctionEnvMut, - routes: WasmPtr<__wasi_route_t, MemoryType>, + routes: WasmPtr, nroutes: WasmPtr, ) -> Errno { super::port_route_list::(ctx, routes, nroutes) @@ -749,7 +749,7 @@ pub(crate) fn http_request( headers: WasmPtr, headers_len: MemoryOffset, gzip: Bool, - ret_handles: WasmPtr<__wasi_http_handles_t, MemoryType>, + ret_handles: WasmPtr, ) -> Errno { super::http_request::( ctx, @@ -767,7 +767,7 @@ pub(crate) fn http_request( pub(crate) fn http_status( ctx: FunctionEnvMut, sock: Fd, - status: WasmPtr<__wasi_http_status_t, MemoryType>, + status: WasmPtr, status_text: WasmPtr, status_text_len: WasmPtr, headers: WasmPtr, @@ -935,9 +935,9 @@ pub(crate) fn sock_recv( 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, ) -> Result { super::sock_recv::( ctx, @@ -955,9 +955,9 @@ pub(crate) fn sock_recv_from( 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 { super::sock_recv_from::( @@ -977,7 +977,7 @@ pub(crate) fn sock_send( 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 { super::sock_send::(ctx, sock, si_data, si_data_len, si_flags, ret_data_len) @@ -988,7 +988,7 @@ pub(crate) fn sock_send_to( 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 { @@ -1014,11 +1014,7 @@ pub(crate) fn sock_send_file( unsafe { super::sock_send_file::(ctx, out_fd, in_fd, offset, count, ret_sent) } } -pub(crate) fn sock_shutdown( - ctx: FunctionEnvMut, - sock: Fd, - how: __wasi_sdflags_t, -) -> Errno { +pub(crate) fn sock_shutdown(ctx: FunctionEnvMut, sock: Fd, how: SdFlags) -> Errno { super::sock_shutdown(ctx, sock, how) } From e4d4e8649eb4f95223377381c76cc22f385d5b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 8 Sep 2022 17:58:41 +0200 Subject: [PATCH 58/84] Fix make test-js --- lib/wasi-types-generated/build.rs | 1 - lib/wasi-types-generated/src/wasi/extra.rs | 23 ------------------- .../src/wasi/extra_manual.rs | 4 ---- 3 files changed, 28 deletions(-) diff --git a/lib/wasi-types-generated/build.rs b/lib/wasi-types-generated/build.rs index 527ae59e46f..9bad01d3b28 100644 --- a/lib/wasi-types-generated/build.rs +++ b/lib/wasi-types-generated/build.rs @@ -98,7 +98,6 @@ fn main() { }} }} - #[cfg(feature = \"sys\")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool {{ false }} }} " diff --git a/lib/wasi-types-generated/src/wasi/extra.rs b/lib/wasi-types-generated/src/wasi/extra.rs index a3643879977..b94a04cdf15 100644 --- a/lib/wasi-types-generated/src/wasi/extra.rs +++ b/lib/wasi-types-generated/src/wasi/extra.rs @@ -3755,7 +3755,6 @@ unsafe impl wasmer::FromToNativeWasmType for Snapshot0Clockid { } } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } @@ -3783,7 +3782,6 @@ unsafe impl wasmer::FromToNativeWasmType for Clockid { } } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } @@ -3886,7 +3884,6 @@ unsafe impl wasmer::FromToNativeWasmType for Errno { } } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } @@ -3932,7 +3929,6 @@ unsafe impl wasmer::FromToNativeWasmType for BusErrno { } } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } @@ -3973,7 +3969,6 @@ unsafe impl wasmer::FromToNativeWasmType for Filetype { } } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } @@ -4017,7 +4012,6 @@ unsafe impl wasmer::FromToNativeWasmType for Advice { } } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } @@ -4076,7 +4070,6 @@ unsafe impl wasmer::FromToNativeWasmType for Eventtype { } } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } @@ -4121,7 +4114,6 @@ unsafe impl wasmer::FromToNativeWasmType for Preopentype { } } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } @@ -4211,7 +4203,6 @@ unsafe impl wasmer::FromToNativeWasmType for Socktype { } } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } @@ -4241,7 +4232,6 @@ unsafe impl wasmer::FromToNativeWasmType for Sockstatus { } } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } @@ -4294,7 +4284,6 @@ unsafe impl wasmer::FromToNativeWasmType for Sockoption { } } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } @@ -4324,7 +4313,6 @@ unsafe impl wasmer::FromToNativeWasmType for Streamsecurity { } } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } @@ -4354,7 +4342,6 @@ unsafe impl wasmer::FromToNativeWasmType for Addressfamily { } } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } @@ -4395,7 +4382,6 @@ unsafe impl wasmer::FromToNativeWasmType for Snapshot0Whence { } } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } @@ -4424,7 +4410,6 @@ unsafe impl wasmer::FromToNativeWasmType for Whence { } } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } @@ -4463,7 +4448,6 @@ unsafe impl wasmer::FromToNativeWasmType for BusDataFormat { } } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } @@ -4495,7 +4479,6 @@ unsafe impl wasmer::FromToNativeWasmType for BusEventType { } } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } @@ -4523,7 +4506,6 @@ unsafe impl wasmer::FromToNativeWasmType for OptionTag { } } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } @@ -4614,7 +4596,6 @@ unsafe impl wasmer::FromToNativeWasmType for StdioMode { } } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } @@ -4904,7 +4885,6 @@ unsafe impl wasmer::FromToNativeWasmType for SockProto { } } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } @@ -4932,7 +4912,6 @@ unsafe impl wasmer::FromToNativeWasmType for Bool { } } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } @@ -4994,7 +4973,6 @@ unsafe impl wasmer::FromToNativeWasmType for Signal { } } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } @@ -5054,7 +5032,6 @@ unsafe impl wasmer::FromToNativeWasmType for Timeout { } } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { false } diff --git a/lib/wasi-types-generated/src/wasi/extra_manual.rs b/lib/wasi-types-generated/src/wasi/extra_manual.rs index 7ab4740e430..c568e1a1a69 100644 --- a/lib/wasi-types-generated/src/wasi/extra_manual.rs +++ b/lib/wasi-types-generated/src/wasi/extra_manual.rs @@ -191,7 +191,6 @@ unsafe impl wasmer::FromToNativeWasmType for Fdflags { Self::from_bits_truncate(n as u8) } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { // TODO: find correct implementation false @@ -210,7 +209,6 @@ unsafe impl wasmer::FromToNativeWasmType for Rights { Self::from_bits_truncate(n as u64) } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { // TODO: find correct implementation false @@ -228,7 +226,6 @@ unsafe impl wasmer::FromToNativeWasmType for Fstflags { Self::from_bits_truncate(n as u8) } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { // TODO: find correct implementation false @@ -246,7 +243,6 @@ unsafe impl wasmer::FromToNativeWasmType for Oflags { Self::from_bits_truncate(n as u8) } - #[cfg(feature = "sys")] fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { // TODO: find correct implementation false From 639dc05b3a7d294de604582363adcac75400a404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 8 Sep 2022 18:05:24 +0200 Subject: [PATCH 59/84] License wasi-types-generated MIT, comment out build.rs/main --- lib/wasi-types-generated/Cargo.toml | 2 ++ lib/wasi-types-generated/build.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/wasi-types-generated/Cargo.toml b/lib/wasi-types-generated/Cargo.toml index 40c823b762e..94a96c8b654 100644 --- a/lib/wasi-types-generated/Cargo.toml +++ b/lib/wasi-types-generated/Cargo.toml @@ -3,6 +3,8 @@ name = "wasmer-wasi-types-generated" version = "3.0.0-beta" edition = "2018" build = "build.rs" +license = "MIT" +description = "Autogenerated wasi types, generated from .wit files" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/lib/wasi-types-generated/build.rs b/lib/wasi-types-generated/build.rs index 9bad01d3b28..084863259a3 100644 --- a/lib/wasi-types-generated/build.rs +++ b/lib/wasi-types-generated/build.rs @@ -5,6 +5,7 @@ const WIT_1: &str = include_str!("./wit-clean/output.wit"); const BINDINGS_RS: &str = include_str!("./src/wasi/bindings.rs"); fn main() { + /* let bindings_rs = BINDINGS_RS .replace("#[allow(clippy::all)]", "") .replace("pub mod output {", "") @@ -109,4 +110,5 @@ fn main() { } } std::fs::write(path, contents).unwrap(); + */ } From fbdec22bfc493849e9d194afe7999764f74d3f7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 12 Sep 2022 15:20:02 +0200 Subject: [PATCH 60/84] Added custom bindings test for wit-bindgen --- Cargo.lock | 63 +++++++++++++++---- lib/wasi-types-generated/.gitignore | 1 + lib/wasi-types-generated/Cargo.toml | 28 ++++++++- lib/wasi-types-generated/build.rs | 8 +-- lib/wasi-types-generated/regenerate.sh | 14 +++-- lib/wasi-types-generated/src/lib.rs | 30 +++++++++ lib/wasi-types-generated/src/wasi/bindings.rs | 5 ++ lib/wasi-types-generated/src/wasi/extra.rs | 5 ++ 8 files changed, 131 insertions(+), 23 deletions(-) create mode 100644 lib/wasi-types-generated/.gitignore diff --git a/Cargo.lock b/Cargo.lock index 5893ba7b9e3..13a2fb1bedd 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.63" @@ -257,7 +248,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6358dedf60f4d9b8db43ad187391afe959746101346fe51bb978126bec61dfb" dependencies = [ "clap 3.2.20", - "heck", + "heck 0.4.0", "indexmap", "log", "proc-macro2", @@ -338,7 +329,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", @@ -1180,6 +1171,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" @@ -2839,6 +2839,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-segmentation" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" + [[package]] name = "unicode-width" version = "0.1.9" @@ -3454,7 +3460,10 @@ name = "wasmer-wasi-types-generated" version = "3.0.0-beta" dependencies = [ "convert_case", + "pretty_assertions", "wasmer", + "wit-bindgen-gen-core", + "wit-bindgen-gen-rust-wasm", "wit-bindgen-rust", "wit-parser", ] @@ -3788,6 +3797,34 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +[[package]] +name = "wit-bindgen-gen-core" +version = "0.1.0" +source = "git+https://github.com/wasmerio/wit-bindgen?branch=force-generate-structs#095d295be6392259924e48488af188d3ed3e4102" +dependencies = [ + "anyhow", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-gen-rust" +version = "0.1.0" +source = "git+https://github.com/wasmerio/wit-bindgen?branch=force-generate-structs#095d295be6392259924e48488af188d3ed3e4102" +dependencies = [ + "heck 0.3.3", + "wit-bindgen-gen-core", +] + +[[package]] +name = "wit-bindgen-gen-rust-wasm" +version = "0.1.0" +source = "git+https://github.com/wasmerio/wit-bindgen?branch=force-generate-structs#095d295be6392259924e48488af188d3ed3e4102" +dependencies = [ + "heck 0.3.3", + "wit-bindgen-gen-core", + "wit-bindgen-gen-rust", +] + [[package]] name = "wit-bindgen-rust" version = "0.1.0" @@ -3798,8 +3835,8 @@ dependencies = [ [[package]] name = "wit-parser" -version = "0.2.0" -source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=f1682df9adacb515227d061a4601b2b4c997e7a2#f1682df9adacb515227d061a4601b2b4c997e7a2" +version = "0.1.0" +source = "git+https://github.com/wasmerio/wit-bindgen?branch=force-generate-structs#095d295be6392259924e48488af188d3ed3e4102" dependencies = [ "anyhow", "id-arena", diff --git a/lib/wasi-types-generated/.gitignore b/lib/wasi-types-generated/.gitignore new file mode 100644 index 00000000000..6c8fbf34887 --- /dev/null +++ b/lib/wasi-types-generated/.gitignore @@ -0,0 +1 @@ +wit-bindgen/ \ No newline at end of file diff --git a/lib/wasi-types-generated/Cargo.toml b/lib/wasi-types-generated/Cargo.toml index 94a96c8b654..ad8c26d0fd4 100644 --- a/lib/wasi-types-generated/Cargo.toml +++ b/lib/wasi-types-generated/Cargo.toml @@ -18,8 +18,34 @@ git = "https://github.com/wasmerio/wit-bindgen" branch = "main" package = "wit-bindgen-rust" +[dev-dependencies.wit-bindgen-gen-rust-wasm] +default-features = false +git = "https://github.com/wasmerio/wit-bindgen" +branch = "force-generate-structs" +package = "wit-bindgen-gen-rust-wasm" + +[dev-dependencies.wit-bindgen-core] +default-features = false +git = "https://github.com/wasmerio/wit-bindgen" +branch = "force-generate-structs" +package = "wit-bindgen-gen-core" + +[dev-dependencies.wit-parser] +default-features = false +git = "https://github.com/wasmerio/wit-bindgen" +branch = "force-generate-structs" +package = "wit-parser" + +[dev-dependencies.pretty_assertions] +version = "1.3.0" + +[build-dependencies.wit-parser] +default-features = false +git = "https://github.com/wasmerio/wit-bindgen" +branch = "force-generate-structs" +package = "wit-parser" + [build-dependencies] -wit-parser = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "f1682df9adacb515227d061a4601b2b4c997e7a2", package = "wit-parser" } convert_case = "0.5.0" [features] diff --git a/lib/wasi-types-generated/build.rs b/lib/wasi-types-generated/build.rs index 084863259a3..6f93591f38c 100644 --- a/lib/wasi-types-generated/build.rs +++ b/lib/wasi-types-generated/build.rs @@ -5,7 +5,6 @@ const WIT_1: &str = include_str!("./wit-clean/output.wit"); const BINDINGS_RS: &str = include_str!("./src/wasi/bindings.rs"); fn main() { - /* let bindings_rs = BINDINGS_RS .replace("#[allow(clippy::all)]", "") .replace("pub mod output {", "") @@ -48,7 +47,7 @@ fn main() { | TypeDefKind::List(_) | TypeDefKind::Future(_) | TypeDefKind::Stream(_) - // | TypeDefKind::Type(_) + // | 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()) { @@ -75,7 +74,7 @@ fn main() { " unsafe impl wasmer::FromToNativeWasmType for {name} {{ type Native = i32; - + fn to_native(self) -> Self::Native {{ self as i32 }} @@ -98,7 +97,7 @@ fn main() { q => todo!(\"could not serialize number {{q}} to enum {name}\"), }} }} - + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool {{ false }} }} " @@ -110,5 +109,4 @@ fn main() { } } std::fs::write(path, contents).unwrap(); - */ } diff --git a/lib/wasi-types-generated/regenerate.sh b/lib/wasi-types-generated/regenerate.sh index 9a4fb1f14c3..1a109c07878 100755 --- a/lib/wasi-types-generated/regenerate.sh +++ b/lib/wasi-types-generated/regenerate.sh @@ -8,10 +8,16 @@ rm -f \ cat "$BASEDIR"/wit-clean/typenames.wit "$BASEDIR"/wit-clean/wasi_unstable.wit > "$BASEDIR"/wit-clean/output.wit -wit-bindgen rust-wasm \ - --import \ - "$BASEDIR"/wit-clean/output.wit \ - --out-dir "$BASEDIR"/src/wasi +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 diff --git a/lib/wasi-types-generated/src/lib.rs b/lib/wasi-types-generated/src/lib.rs index f53466fdb86..09b7911ab22 100644 --- a/lib/wasi-types-generated/src/lib.rs +++ b/lib/wasi-types-generated/src/lib.rs @@ -1 +1,31 @@ pub mod 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; + + 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_gen_rust_wasm::Opts { + ..wit_bindgen_gen_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); + pretty_assertions::assert_eq!(generated_str, bindings_target); // output.wit out of date? regenerate bindings.rs +} diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index cc6267a34cc..14dfeaf826c 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -1,5 +1,10 @@ #[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. diff --git a/lib/wasi-types-generated/src/wasi/extra.rs b/lib/wasi-types-generated/src/wasi/extra.rs index b94a04cdf15..5032307702a 100644 --- a/lib/wasi-types-generated/src/wasi/extra.rs +++ b/lib/wasi-types-generated/src/wasi/extra.rs @@ -1,6 +1,11 @@ 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. From 921fac369595e64d7834458e11cce136e8134099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 12 Sep 2022 15:24:45 +0200 Subject: [PATCH 61/84] Remove dummy-func (which prevented proper linking) from .wit --- lib/wasi-types-generated/build.rs | 2 + lib/wasi-types-generated/src/wasi/bindings.rs | 843 ------------- lib/wasi-types-generated/src/wasi/extra.rs | 1061 ----------------- lib/wasi-types-generated/wit-clean/output.wit | 58 - .../wit-clean/typenames.wit | 58 - 5 files changed, 2 insertions(+), 2020 deletions(-) diff --git a/lib/wasi-types-generated/build.rs b/lib/wasi-types-generated/build.rs index 6f93591f38c..70aab7674f5 100644 --- a/lib/wasi-types-generated/build.rs +++ b/lib/wasi-types-generated/build.rs @@ -5,6 +5,7 @@ const WIT_1: &str = include_str!("./wit-clean/output.wit"); const BINDINGS_RS: &str = include_str!("./src/wasi/bindings.rs"); fn main() { + /* let bindings_rs = BINDINGS_RS .replace("#[allow(clippy::all)]", "") .replace("pub mod output {", "") @@ -109,4 +110,5 @@ fn main() { } } std::fs::write(path, contents).unwrap(); + */ } diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index 14dfeaf826c..3d88e9fda80 100644 --- a/lib/wasi-types-generated/src/wasi/bindings.rs +++ b/lib/wasi-types-generated/src/wasi/bindings.rs @@ -2995,847 +2995,4 @@ pub mod output { } } } - /// Dummy function to expose types into generated code - pub fn expose_types_dummy_func(fd: Fd,dirent: Dirent,snapshot0_dirent: Snapshot0Dirent,snapshot0_event: Snapshot0Event,event_enum: EventEnum,event: Event,fdstat: Fdstat,subscription_clock: SubscriptionClock,snapshot0_subscription_clock: Snapshot0SubscriptionClock,subscription: Subscription,snapshot0_subscription: Snapshot0Subscription,device: Device,linkcount: Linkcount,snapshot0_linkcount: Snapshot0Linkcount,filestat: Filestat,snapshot0_filestat: Snapshot0Filestat,tty: Tty,tid: Tid,pid: Pid,bus_data_format: BusDataFormat,bid: Bid,option_bid: OptionBid,cid: Cid,option_cid: OptionCid,option_fd: OptionFd,bus_handles: BusHandles,exit_code: ExitCode,bus_event_exit: BusEventExit,bus_event_fault: BusEventFault,bus_event_close: BusEventClose,prestat_u_dir: PrestatUDir,prestat_u: PrestatU,event_fd_flags: EventFdFlags,prestat: Prestat,file_delta: FileDelta,lookup_flags: LookupFlags,count: Count,bool: Bool,pipe_handles: PipeHandles,stdio_mode: StdioMode,sock_proto: SockProto,option_timestamp: OptionTimestamp,addr_unspec: AddrUnspec,addr_unspec_port: AddrUnspecPort,cidr_unspec: CidrUnspec,http_handles: HttpHandles,http_status: HttpStatus,ri_flags: RiFlags,ro_flags: RoFlags,sd_flags: SdFlags,si_flags: SiFlags,timeout: Timeout,) -> (){ - unsafe { - let ptr0 = OUTPUT_RET_AREA.0.as_mut_ptr() as i32; - *((ptr0 + 0) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd); - let Dirent{ d_next:d_next1, d_ino:d_ino1, d_type:d_type1, d_namlen:d_namlen1, } = dirent; - *((ptr0 + 8) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_next1); - *((ptr0 + 16) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_ino1); - *((ptr0 + 24) as *mut u8) = (match d_type1 { - Filetype::Unknown => 0, - Filetype::BlockDevice => 1, - Filetype::CharacterDevice => 2, - Filetype::Directory => 3, - Filetype::RegularFile => 4, - Filetype::SocketDgram => 5, - Filetype::SocketStream => 6, - Filetype::SymbolicLink => 7, - Filetype::Fifo => 8, - }) as u8; - *((ptr0 + 28) as *mut i32) = wit_bindgen_rust::rt::as_i32(d_namlen1); - let Snapshot0Dirent{ d_next:d_next2, d_ino:d_ino2, d_namlen:d_namlen2, d_type:d_type2, } = snapshot0_dirent; - *((ptr0 + 32) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_next2); - *((ptr0 + 40) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_ino2); - *((ptr0 + 48) as *mut i32) = wit_bindgen_rust::rt::as_i32(d_namlen2); - *((ptr0 + 52) as *mut u8) = (match d_type2 { - Filetype::Unknown => 0, - Filetype::BlockDevice => 1, - Filetype::CharacterDevice => 2, - Filetype::Directory => 3, - Filetype::RegularFile => 4, - Filetype::SocketDgram => 5, - Filetype::SocketStream => 6, - Filetype::SymbolicLink => 7, - Filetype::Fifo => 8, - }) as u8; - let Snapshot0Event{ userdata:userdata3, error:error3, type_:type_3, fd_readwrite:fd_readwrite3, } = snapshot0_event; - *((ptr0 + 56) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata3); - *((ptr0 + 64) as *mut u8) = (match error3 { - Errno::Success => 0, - Errno::Toobig => 1, - Errno::Access => 2, - Errno::Addrinuse => 3, - Errno::Addrnotavail => 4, - Errno::Afnosupport => 5, - Errno::Again => 6, - Errno::Already => 7, - Errno::Badf => 8, - Errno::Badmsg => 9, - Errno::Busy => 10, - Errno::Canceled => 11, - Errno::Child => 12, - Errno::Connaborted => 13, - Errno::Connrefused => 14, - Errno::Connreset => 15, - Errno::Deadlk => 16, - Errno::Destaddrreq => 17, - Errno::Dom => 18, - Errno::Dquot => 19, - Errno::Exist => 20, - Errno::Fault => 21, - Errno::Fbig => 22, - Errno::Hostunreach => 23, - Errno::Idrm => 24, - Errno::Ilseq => 25, - Errno::Inprogress => 26, - Errno::Intr => 27, - Errno::Inval => 28, - Errno::Io => 29, - Errno::Isconn => 30, - Errno::Isdir => 31, - Errno::Loop => 32, - Errno::Mfile => 33, - Errno::Mlink => 34, - Errno::Msgsize => 35, - Errno::Multihop => 36, - Errno::Nametoolong => 37, - Errno::Netdown => 38, - Errno::Netreset => 39, - Errno::Netunreach => 40, - Errno::Nfile => 41, - Errno::Nobufs => 42, - Errno::Nodev => 43, - Errno::Noent => 44, - Errno::Noexec => 45, - Errno::Nolck => 46, - Errno::Nolink => 47, - Errno::Nomem => 48, - Errno::Nomsg => 49, - Errno::Noprotoopt => 50, - Errno::Nospc => 51, - Errno::Nosys => 52, - Errno::Notconn => 53, - Errno::Notdir => 54, - Errno::Notempty => 55, - Errno::Notrecoverable => 56, - Errno::Notsock => 57, - Errno::Notsup => 58, - Errno::Notty => 59, - Errno::Nxio => 60, - Errno::Overflow => 61, - Errno::Ownerdead => 62, - Errno::Perm => 63, - Errno::Pipe => 64, - Errno::Proto => 65, - Errno::Protonosupport => 66, - Errno::Prototype => 67, - Errno::Range => 68, - Errno::Rofs => 69, - Errno::Spipe => 70, - Errno::Srch => 71, - Errno::Stale => 72, - Errno::Timedout => 73, - Errno::Txtbsy => 74, - Errno::Xdev => 75, - Errno::Notcapable => 76, - }) as u8; - *((ptr0 + 65) as *mut u8) = (match type_3 { - Eventtype::Clock => 0, - Eventtype::FdRead => 1, - Eventtype::FdWrite => 2, - }) as u8; - let EventFdReadwrite{ nbytes:nbytes4, flags:flags4, } = fd_readwrite3; - *((ptr0 + 72) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes4); - let flags5 = flags4; - *((ptr0 + 80) as *mut u8) = ((flags5.bits() >> 0) as i32) as u8; - match event_enum { - EventEnum::FdRead(e) => { - *((ptr0 + 88) as *mut u8) = (0i32) as u8; - let EventFdReadwrite{ nbytes:nbytes6, flags:flags6, } = e; - *((ptr0 + 96) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes6); - let flags7 = flags6; - *((ptr0 + 104) as *mut u8) = ((flags7.bits() >> 0) as i32) as u8; - - }, - EventEnum::FdWrite(e) => { - *((ptr0 + 88) as *mut u8) = (1i32) as u8; - let EventFdReadwrite{ nbytes:nbytes8, flags:flags8, } = e; - *((ptr0 + 96) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes8); - let flags9 = flags8; - *((ptr0 + 104) as *mut u8) = ((flags9.bits() >> 0) as i32) as u8; - - }, - EventEnum::Clock=> { - let e = (); - { - *((ptr0 + 88) as *mut u8) = (2i32) as u8; - let () = e; - - } - } - }; - let Event{ userdata:userdata10, error:error10, data:data10, } = event; - *((ptr0 + 112) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata10); - *((ptr0 + 120) as *mut u8) = (match error10 { - Errno::Success => 0, - Errno::Toobig => 1, - Errno::Access => 2, - Errno::Addrinuse => 3, - Errno::Addrnotavail => 4, - Errno::Afnosupport => 5, - Errno::Again => 6, - Errno::Already => 7, - Errno::Badf => 8, - Errno::Badmsg => 9, - Errno::Busy => 10, - Errno::Canceled => 11, - Errno::Child => 12, - Errno::Connaborted => 13, - Errno::Connrefused => 14, - Errno::Connreset => 15, - Errno::Deadlk => 16, - Errno::Destaddrreq => 17, - Errno::Dom => 18, - Errno::Dquot => 19, - Errno::Exist => 20, - Errno::Fault => 21, - Errno::Fbig => 22, - Errno::Hostunreach => 23, - Errno::Idrm => 24, - Errno::Ilseq => 25, - Errno::Inprogress => 26, - Errno::Intr => 27, - Errno::Inval => 28, - Errno::Io => 29, - Errno::Isconn => 30, - Errno::Isdir => 31, - Errno::Loop => 32, - Errno::Mfile => 33, - Errno::Mlink => 34, - Errno::Msgsize => 35, - Errno::Multihop => 36, - Errno::Nametoolong => 37, - Errno::Netdown => 38, - Errno::Netreset => 39, - Errno::Netunreach => 40, - Errno::Nfile => 41, - Errno::Nobufs => 42, - Errno::Nodev => 43, - Errno::Noent => 44, - Errno::Noexec => 45, - Errno::Nolck => 46, - Errno::Nolink => 47, - Errno::Nomem => 48, - Errno::Nomsg => 49, - Errno::Noprotoopt => 50, - Errno::Nospc => 51, - Errno::Nosys => 52, - Errno::Notconn => 53, - Errno::Notdir => 54, - Errno::Notempty => 55, - Errno::Notrecoverable => 56, - Errno::Notsock => 57, - Errno::Notsup => 58, - Errno::Notty => 59, - Errno::Nxio => 60, - Errno::Overflow => 61, - Errno::Ownerdead => 62, - Errno::Perm => 63, - Errno::Pipe => 64, - Errno::Proto => 65, - Errno::Protonosupport => 66, - Errno::Prototype => 67, - Errno::Range => 68, - Errno::Rofs => 69, - Errno::Spipe => 70, - Errno::Srch => 71, - Errno::Stale => 72, - Errno::Timedout => 73, - Errno::Txtbsy => 74, - Errno::Xdev => 75, - Errno::Notcapable => 76, - }) as u8; - match data10 { - EventEnum::FdRead(e) => { - *((ptr0 + 128) as *mut u8) = (0i32) as u8; - let EventFdReadwrite{ nbytes:nbytes11, flags:flags11, } = e; - *((ptr0 + 136) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes11); - let flags12 = flags11; - *((ptr0 + 144) as *mut u8) = ((flags12.bits() >> 0) as i32) as u8; - - }, - EventEnum::FdWrite(e) => { - *((ptr0 + 128) as *mut u8) = (1i32) as u8; - let EventFdReadwrite{ nbytes:nbytes13, flags:flags13, } = e; - *((ptr0 + 136) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes13); - let flags14 = flags13; - *((ptr0 + 144) as *mut u8) = ((flags14.bits() >> 0) as i32) as u8; - - }, - EventEnum::Clock=> { - let e = (); - { - *((ptr0 + 128) as *mut u8) = (2i32) as u8; - let () = e; - - } - } - }; - let Fdstat{ fs_filetype:fs_filetype15, fs_flags:fs_flags15, fs_rights_base:fs_rights_base15, fs_rights_inheriting:fs_rights_inheriting15, } = fdstat; - *((ptr0 + 152) as *mut u8) = (match fs_filetype15 { - Filetype::Unknown => 0, - Filetype::BlockDevice => 1, - Filetype::CharacterDevice => 2, - Filetype::Directory => 3, - Filetype::RegularFile => 4, - Filetype::SocketDgram => 5, - Filetype::SocketStream => 6, - Filetype::SymbolicLink => 7, - Filetype::Fifo => 8, - }) as u8; - let flags16 = fs_flags15; - *((ptr0 + 153) as *mut u8) = ((flags16.bits() >> 0) as i32) as u8; - let flags17 = fs_rights_base15; - *((ptr0 + 160) as *mut i32) = (flags17.bits() >> 32) as i32; - *((ptr0 + 156) as *mut i32) = (flags17.bits() >> 0) as i32; - let flags18 = fs_rights_inheriting15; - *((ptr0 + 168) as *mut i32) = (flags18.bits() >> 32) as i32; - *((ptr0 + 164) as *mut i32) = (flags18.bits() >> 0) as i32; - let SubscriptionClock{ clock_id:clock_id19, timeout:timeout19, precision:precision19, flags:flags19, } = subscription_clock; - *((ptr0 + 176) as *mut u8) = (match clock_id19 { - Clockid::Realtime => 0, - Clockid::Monotonic => 1, - }) as u8; - *((ptr0 + 184) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout19); - *((ptr0 + 192) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision19); - let flags20 = flags19; - *((ptr0 + 200) as *mut u8) = ((flags20.bits() >> 0) as i32) as u8; - let Snapshot0SubscriptionClock{ identifier:identifier21, id:id21, timeout:timeout21, precision:precision21, flags:flags21, } = snapshot0_subscription_clock; - *((ptr0 + 208) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier21); - *((ptr0 + 216) as *mut u8) = (match id21 { - Snapshot0Clockid::Realtime => 0, - Snapshot0Clockid::Monotonic => 1, - Snapshot0Clockid::ProcessCputimeId => 2, - Snapshot0Clockid::ThreadCputimeId => 3, - }) as u8; - *((ptr0 + 224) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout21); - *((ptr0 + 232) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision21); - let flags22 = flags21; - *((ptr0 + 240) as *mut u8) = ((flags22.bits() >> 0) as i32) as u8; - let Subscription{ userdata:userdata23, data:data23, } = subscription; - *((ptr0 + 248) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata23); - match data23 { - SubscriptionEnum::Clock(e) => { - *((ptr0 + 256) as *mut u8) = (0i32) as u8; - let SubscriptionClock{ clock_id:clock_id24, timeout:timeout24, precision:precision24, flags:flags24, } = e; - *((ptr0 + 264) as *mut u8) = (match clock_id24 { - Clockid::Realtime => 0, - Clockid::Monotonic => 1, - }) as u8; - *((ptr0 + 272) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout24); - *((ptr0 + 280) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision24); - let flags25 = flags24; - *((ptr0 + 288) as *mut u8) = ((flags25.bits() >> 0) as i32) as u8; - - }, - SubscriptionEnum::Read(e) => { - *((ptr0 + 256) as *mut u8) = (1i32) as u8; - let SubscriptionFsReadwrite{ file_descriptor:file_descriptor26, } = e; - *((ptr0 + 264) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor26); - - }, - SubscriptionEnum::Write(e) => { - *((ptr0 + 256) as *mut u8) = (2i32) as u8; - let SubscriptionFsReadwrite{ file_descriptor:file_descriptor27, } = e; - *((ptr0 + 264) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor27); - - }, - }; - let Snapshot0Subscription{ userdata:userdata28, data:data28, } = snapshot0_subscription; - *((ptr0 + 296) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata28); - match data28 { - Snapshot0SubscriptionEnum::Clock(e) => { - *((ptr0 + 304) as *mut u8) = (0i32) as u8; - let Snapshot0SubscriptionClock{ identifier:identifier29, id:id29, timeout:timeout29, precision:precision29, flags:flags29, } = e; - *((ptr0 + 312) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier29); - *((ptr0 + 320) as *mut u8) = (match id29 { - Snapshot0Clockid::Realtime => 0, - Snapshot0Clockid::Monotonic => 1, - Snapshot0Clockid::ProcessCputimeId => 2, - Snapshot0Clockid::ThreadCputimeId => 3, - }) as u8; - *((ptr0 + 328) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout29); - *((ptr0 + 336) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision29); - let flags30 = flags29; - *((ptr0 + 344) as *mut u8) = ((flags30.bits() >> 0) as i32) as u8; - - }, - Snapshot0SubscriptionEnum::Read(e) => { - *((ptr0 + 304) as *mut u8) = (1i32) as u8; - let SubscriptionFsReadwrite{ file_descriptor:file_descriptor31, } = e; - *((ptr0 + 312) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor31); - - }, - Snapshot0SubscriptionEnum::Write(e) => { - *((ptr0 + 304) as *mut u8) = (2i32) as u8; - let SubscriptionFsReadwrite{ file_descriptor:file_descriptor32, } = e; - *((ptr0 + 312) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor32); - - }, - }; - *((ptr0 + 352) as *mut i64) = wit_bindgen_rust::rt::as_i64(device); - *((ptr0 + 360) as *mut i64) = wit_bindgen_rust::rt::as_i64(linkcount); - *((ptr0 + 368) as *mut i32) = wit_bindgen_rust::rt::as_i32(snapshot0_linkcount); - let Filestat{ st_dev:st_dev33, st_ino:st_ino33, st_filetype:st_filetype33, st_nlink:st_nlink33, st_size:st_size33, st_atim:st_atim33, st_mtim:st_mtim33, st_ctim:st_ctim33, } = filestat; - *((ptr0 + 376) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev33); - *((ptr0 + 384) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino33); - *((ptr0 + 392) as *mut u8) = (match st_filetype33 { - Filetype::Unknown => 0, - Filetype::BlockDevice => 1, - Filetype::CharacterDevice => 2, - Filetype::Directory => 3, - Filetype::RegularFile => 4, - Filetype::SocketDgram => 5, - Filetype::SocketStream => 6, - Filetype::SymbolicLink => 7, - Filetype::Fifo => 8, - }) as u8; - *((ptr0 + 400) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_nlink33); - *((ptr0 + 408) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size33); - *((ptr0 + 416) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim33); - *((ptr0 + 424) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim33); - *((ptr0 + 432) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim33); - let Snapshot0Filestat{ st_dev:st_dev34, st_ino:st_ino34, st_filetype:st_filetype34, st_nlink:st_nlink34, st_size:st_size34, st_atim:st_atim34, st_mtim:st_mtim34, st_ctim:st_ctim34, } = snapshot0_filestat; - *((ptr0 + 440) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev34); - *((ptr0 + 448) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino34); - *((ptr0 + 456) as *mut u8) = (match st_filetype34 { - Filetype::Unknown => 0, - Filetype::BlockDevice => 1, - Filetype::CharacterDevice => 2, - Filetype::Directory => 3, - Filetype::RegularFile => 4, - Filetype::SocketDgram => 5, - Filetype::SocketStream => 6, - Filetype::SymbolicLink => 7, - Filetype::Fifo => 8, - }) as u8; - *((ptr0 + 460) as *mut i32) = wit_bindgen_rust::rt::as_i32(st_nlink34); - *((ptr0 + 464) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size34); - *((ptr0 + 472) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim34); - *((ptr0 + 480) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim34); - *((ptr0 + 488) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim34); - let Tty{ cols:cols35, rows:rows35, width:width35, height:height35, stdin_tty:stdin_tty35, stdout_tty:stdout_tty35, stderr_tty:stderr_tty35, echo:echo35, line_buffered:line_buffered35, } = tty; - *((ptr0 + 496) as *mut i32) = wit_bindgen_rust::rt::as_i32(cols35); - *((ptr0 + 500) as *mut i32) = wit_bindgen_rust::rt::as_i32(rows35); - *((ptr0 + 504) as *mut i32) = wit_bindgen_rust::rt::as_i32(width35); - *((ptr0 + 508) as *mut i32) = wit_bindgen_rust::rt::as_i32(height35); - *((ptr0 + 512) as *mut u8) = (match stdin_tty35 { true => 1, false => 0 }) as u8; - *((ptr0 + 513) as *mut u8) = (match stdout_tty35 { true => 1, false => 0 }) as u8; - *((ptr0 + 514) as *mut u8) = (match stderr_tty35 { true => 1, false => 0 }) as u8; - *((ptr0 + 515) as *mut u8) = (match echo35 { true => 1, false => 0 }) as u8; - *((ptr0 + 516) as *mut u8) = (match line_buffered35 { true => 1, false => 0 }) as u8; - *((ptr0 + 520) as *mut i32) = wit_bindgen_rust::rt::as_i32(tid); - *((ptr0 + 524) as *mut i32) = wit_bindgen_rust::rt::as_i32(pid); - *((ptr0 + 528) as *mut u8) = (match bus_data_format { - BusDataFormat::Raw => 0, - BusDataFormat::Bincode => 1, - BusDataFormat::MessagePack => 2, - BusDataFormat::Json => 3, - BusDataFormat::Yaml => 4, - BusDataFormat::Xml => 5, - BusDataFormat::Rkyv => 6, - }) as u8; - *((ptr0 + 532) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid); - let OptionBid{ tag:tag36, bid:bid36, } = option_bid; - *((ptr0 + 536) as *mut u8) = (match tag36 { - OptionTag::None => 0, - OptionTag::Some => 1, - }) as u8; - *((ptr0 + 540) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid36); - *((ptr0 + 544) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid); - let OptionCid{ tag:tag37, cid:cid37, } = option_cid; - *((ptr0 + 548) as *mut u8) = (match tag37 { - OptionTag::None => 0, - OptionTag::Some => 1, - }) as u8; - *((ptr0 + 552) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid37); - let OptionFd{ tag:tag38, fd:fd38, } = option_fd; - *((ptr0 + 556) as *mut u8) = (match tag38 { - OptionTag::None => 0, - OptionTag::Some => 1, - }) as u8; - *((ptr0 + 560) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd38); - let BusHandles{ bid:bid39, stdin:stdin39, stdout:stdout39, stderr:stderr39, } = bus_handles; - *((ptr0 + 564) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid39); - let OptionFd{ tag:tag40, fd:fd40, } = stdin39; - *((ptr0 + 568) as *mut u8) = (match tag40 { - OptionTag::None => 0, - OptionTag::Some => 1, - }) as u8; - *((ptr0 + 572) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd40); - let OptionFd{ tag:tag41, fd:fd41, } = stdout39; - *((ptr0 + 576) as *mut u8) = (match tag41 { - OptionTag::None => 0, - OptionTag::Some => 1, - }) as u8; - *((ptr0 + 580) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd41); - let OptionFd{ tag:tag42, fd:fd42, } = stderr39; - *((ptr0 + 584) as *mut u8) = (match tag42 { - OptionTag::None => 0, - OptionTag::Some => 1, - }) as u8; - *((ptr0 + 588) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd42); - *((ptr0 + 592) as *mut i32) = wit_bindgen_rust::rt::as_i32(exit_code); - let BusEventExit{ bid:bid43, rval:rval43, } = bus_event_exit; - *((ptr0 + 596) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid43); - *((ptr0 + 600) as *mut i32) = wit_bindgen_rust::rt::as_i32(rval43); - let BusEventFault{ cid:cid44, err:err44, } = bus_event_fault; - *((ptr0 + 604) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid44); - *((ptr0 + 608) as *mut u8) = (match err44 { - BusErrno::Success => 0, - BusErrno::Ser => 1, - BusErrno::Des => 2, - BusErrno::Wapm => 3, - BusErrno::Fetch => 4, - BusErrno::Compile => 5, - BusErrno::Abi => 6, - BusErrno::Aborted => 7, - BusErrno::Badhandle => 8, - BusErrno::Topic => 9, - BusErrno::Badcb => 10, - BusErrno::Unsupported => 11, - BusErrno::Badrequest => 12, - BusErrno::Denied => 13, - BusErrno::Internal => 14, - BusErrno::Alloc => 15, - BusErrno::Invoke => 16, - BusErrno::Consumed => 17, - BusErrno::Memviolation => 18, - BusErrno::Unknown => 19, - }) as u8; - let BusEventClose{ cid:cid45, } = bus_event_close; - *((ptr0 + 612) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid45); - let PrestatUDir{ pr_name_len:pr_name_len46, } = prestat_u_dir; - *((ptr0 + 616) as *mut i32) = wit_bindgen_rust::rt::as_i32(pr_name_len46); - let PrestatU{ dir:dir47, } = prestat_u; - let PrestatUDir{ pr_name_len:pr_name_len48, } = dir47; - *((ptr0 + 620) as *mut i32) = wit_bindgen_rust::rt::as_i32(pr_name_len48); - *((ptr0 + 624) as *mut u16) = (wit_bindgen_rust::rt::as_i32(event_fd_flags)) as u16; - let Prestat{ pr_type:pr_type49, u:u49, } = prestat; - *((ptr0 + 628) as *mut u8) = (match pr_type49 { - Preopentype::Dir => 0, - }) as u8; - let PrestatU{ dir:dir50, } = u49; - let PrestatUDir{ pr_name_len:pr_name_len51, } = dir50; - *((ptr0 + 632) as *mut i32) = wit_bindgen_rust::rt::as_i32(pr_name_len51); - *((ptr0 + 640) as *mut i64) = wit_bindgen_rust::rt::as_i64(file_delta); - *((ptr0 + 648) as *mut i32) = wit_bindgen_rust::rt::as_i32(lookup_flags); - *((ptr0 + 652) as *mut i32) = wit_bindgen_rust::rt::as_i32(count); - *((ptr0 + 656) as *mut u8) = (match bool { - Bool::False => 0, - Bool::True => 1, - }) as u8; - let PipeHandles{ pipe:pipe52, other:other52, } = pipe_handles; - *((ptr0 + 660) as *mut i32) = wit_bindgen_rust::rt::as_i32(pipe52); - *((ptr0 + 664) as *mut i32) = wit_bindgen_rust::rt::as_i32(other52); - *((ptr0 + 668) as *mut u8) = (match stdio_mode { - StdioMode::Reserved => 0, - StdioMode::Piped => 1, - StdioMode::Inherit => 2, - StdioMode::Null => 3, - StdioMode::Log => 4, - }) as u8; - *((ptr0 + 670) as *mut u16) = (match sock_proto { - SockProto::Ip => 0, - SockProto::Icmp => 1, - SockProto::Igmp => 2, - SockProto::ProtoThree => 3, - SockProto::Ipip => 4, - SockProto::ProtoFive => 5, - SockProto::Tcp => 6, - SockProto::ProtoSeven => 7, - SockProto::Egp => 8, - SockProto::ProtoNine => 9, - SockProto::ProtoTen => 10, - SockProto::ProtoEleven => 11, - SockProto::Pup => 12, - SockProto::ProtoThirteen => 13, - SockProto::ProtoFourteen => 14, - SockProto::ProtoFifteen => 15, - SockProto::ProtoSixteen => 16, - SockProto::Udp => 17, - SockProto::ProtoEighteen => 18, - SockProto::ProtoNineteen => 19, - SockProto::ProtoTwenty => 20, - SockProto::ProtoTwentyone => 21, - SockProto::Idp => 22, - SockProto::ProtoTwentythree => 23, - SockProto::ProtoTwentyfour => 24, - SockProto::ProtoTwentyfive => 25, - SockProto::ProtoTwentysix => 26, - SockProto::ProtoTwentyseven => 27, - SockProto::ProtoTwentyeight => 28, - SockProto::ProtoTp => 29, - SockProto::ProtoThirty => 30, - SockProto::ProtoThirtyone => 31, - SockProto::ProtoThirtytwo => 32, - SockProto::Dccp => 33, - SockProto::ProtoThirtyfour => 34, - SockProto::ProtoThirtyfive => 35, - SockProto::ProtoThirtysix => 36, - SockProto::ProtoThirtyseven => 37, - SockProto::ProtoThirtyeight => 38, - SockProto::ProtoThirtynine => 39, - SockProto::ProtoFourty => 40, - SockProto::Ipv6 => 41, - SockProto::ProtoFourtytwo => 42, - SockProto::Routing => 43, - SockProto::Fragment => 44, - SockProto::ProtoFourtyfive => 45, - SockProto::Rsvp => 46, - SockProto::Gre => 47, - SockProto::ProtoFourtyeight => 48, - SockProto::ProtoFourtynine => 49, - SockProto::Esp => 50, - SockProto::Ah => 51, - SockProto::ProtoFiftytwo => 52, - SockProto::ProtoFiftythree => 53, - SockProto::ProtoFiftyfour => 54, - SockProto::ProtoFiftyfive => 55, - SockProto::ProtoFiftysix => 56, - SockProto::ProtoFiftyseven => 57, - SockProto::Icmpv6 => 58, - SockProto::None => 59, - SockProto::Dstopts => 60, - SockProto::ProtoSixtyone => 61, - SockProto::ProtoSixtytwo => 62, - SockProto::ProtoSixtythree => 63, - SockProto::ProtoSixtyfour => 64, - SockProto::ProtoSixtyfive => 65, - SockProto::ProtoSixtysix => 66, - SockProto::ProtoSixtyseven => 67, - SockProto::ProtoSixtyeight => 68, - SockProto::ProtoSixtynine => 69, - SockProto::ProtoSeventy => 70, - SockProto::ProtoSeventyone => 71, - SockProto::ProtoSeventytwo => 72, - SockProto::ProtoSeventythree => 73, - SockProto::ProtoSeventyfour => 74, - SockProto::ProtoSeventyfive => 75, - SockProto::ProtoSeventysix => 76, - SockProto::ProtoSeventyseven => 77, - SockProto::ProtoSeventyeight => 78, - SockProto::ProtoSeventynine => 79, - SockProto::ProtoEighty => 80, - SockProto::ProtoEightyone => 81, - SockProto::ProtoEightytwo => 82, - SockProto::ProtoEightythree => 83, - SockProto::ProtoEightyfour => 84, - SockProto::ProtoEightyfive => 85, - SockProto::ProtoEightysix => 86, - SockProto::ProtoEightyseven => 87, - SockProto::ProtoEightyeight => 88, - SockProto::ProtoEightynine => 89, - SockProto::ProtoNinety => 90, - SockProto::ProtoNinetyone => 91, - SockProto::Mtp => 92, - SockProto::ProtoNinetythree => 93, - SockProto::Beetph => 94, - SockProto::ProtoNinetyfive => 95, - SockProto::ProtoNinetysix => 96, - SockProto::ProtoNineetyseven => 97, - SockProto::Encap => 98, - SockProto::ProtoNinetynine => 99, - SockProto::ProtoOnehundred => 100, - SockProto::ProtoOnehundredandone => 101, - SockProto::ProtoOnehundredandtwo => 102, - SockProto::Pim => 103, - SockProto::ProtoOnehundredandfour => 104, - SockProto::ProtoOnehundredandfive => 105, - SockProto::ProtoOnehundredandsix => 106, - SockProto::ProtoOnehundredandseven => 107, - SockProto::Comp => 108, - SockProto::ProtoOnehundredandnine => 109, - SockProto::ProtoOnehundredandten => 110, - SockProto::ProtoOnehundredandeleven => 111, - SockProto::ProtoOnehundredandtwelve => 112, - SockProto::ProtoOnehundredandthirteen => 113, - SockProto::ProtoOnehundredandfourteen => 114, - SockProto::ProtoOnehundredandfifteen => 115, - SockProto::ProtoOnehundredandsixteen => 116, - SockProto::ProtoOnehundredandseventeen => 117, - SockProto::ProtoOnehundredandeighteen => 118, - SockProto::ProtoOnehundredandnineteen => 119, - SockProto::ProtoOnehundredandtwenty => 120, - SockProto::ProtoOnehundredandtwentyone => 121, - SockProto::ProtoOnehundredandtwentytwo => 122, - SockProto::ProtoOnehundredandtwentythree => 123, - SockProto::ProtoOnehundredandtwentyfour => 124, - SockProto::ProtoOnehundredandtwentyfive => 125, - SockProto::ProtoOnehundredandtwentysix => 126, - SockProto::ProtoOnehundredandtwentyseven => 127, - SockProto::ProtoOnehundredandtwentyeight => 128, - SockProto::ProtoOnehundredandtwentynine => 129, - SockProto::ProtoOnehundredandthirty => 130, - SockProto::ProtoOnehundredandthirtyone => 131, - SockProto::Sctp => 132, - SockProto::ProtoOnehundredandthirtythree => 133, - SockProto::ProtoOnehundredandthirtyfour => 134, - SockProto::Mh => 135, - SockProto::Udplite => 136, - SockProto::Mpls => 137, - SockProto::ProtoOnehundredandthirtyeight => 138, - SockProto::ProtoOnehundredandthirtynine => 139, - SockProto::ProtoOnehundredandfourty => 140, - SockProto::ProtoOnehundredandfourtyone => 141, - SockProto::ProtoOnehundredandfourtytwo => 142, - SockProto::Ethernet => 143, - SockProto::ProtoOnehundredandfourtyfour => 144, - SockProto::ProtoOnehundredandfourtyfive => 145, - SockProto::ProtoOnehundredandfourtysix => 146, - SockProto::ProtoOnehundredandfourtyseven => 147, - SockProto::ProtoOnehundredandfourtyeight => 148, - SockProto::ProtoOnehundredandfourtynine => 149, - SockProto::ProtoOnehundredandfifty => 150, - SockProto::ProtoOnehundredandfiftyone => 151, - SockProto::ProtoOnehundredandfiftytwo => 152, - SockProto::ProtoOnehundredandfiftythree => 153, - SockProto::ProtoOnehundredandfiftyfour => 154, - SockProto::ProtoOnehundredandfiftyfive => 155, - SockProto::ProtoOnehundredandfiftysix => 156, - SockProto::ProtoOnehundredandfiftyseven => 157, - SockProto::ProtoOnehundredandfiftyeight => 158, - SockProto::ProtoOnehundredandfiftynine => 159, - SockProto::ProtoOnehundredandsixty => 160, - SockProto::ProtoOnehundredandsixtyone => 161, - SockProto::ProtoOnehundredandsixtytwo => 162, - SockProto::ProtoOnehundredandsixtythree => 163, - SockProto::ProtoOnehundredandsixtyfour => 164, - SockProto::ProtoOnehundredandsixtyfive => 165, - SockProto::ProtoOnehundredandsixtysix => 166, - SockProto::ProtoOnehundredandsixtyseven => 167, - SockProto::ProtoOnehundredandsixtyeight => 168, - SockProto::ProtoOnehundredandsixtynine => 169, - SockProto::ProtoOnehundredandseventy => 170, - SockProto::ProtoOnehundredandseventyone => 171, - SockProto::ProtoOnehundredandseventytwo => 172, - SockProto::ProtoOnehundredandseventythree => 173, - SockProto::ProtoOnehundredandseventyfour => 174, - SockProto::ProtoOnehundredandseventyfive => 175, - SockProto::ProtoOnehundredandseventysix => 176, - SockProto::ProtoOnehundredandseventyseven => 177, - SockProto::ProtoOnehundredandseventyeight => 178, - SockProto::ProtoOnehundredandseventynine => 179, - SockProto::ProtoOnehundredandeighty => 180, - SockProto::ProtoOnehundredandeightyone => 181, - SockProto::ProtoOnehundredandeightytwo => 182, - SockProto::ProtoOnehundredandeightythree => 183, - SockProto::ProtoOnehundredandeightyfour => 184, - SockProto::ProtoOnehundredandeightyfive => 185, - SockProto::ProtoOnehundredandeightysix => 186, - SockProto::ProtoOnehundredandeightyseven => 187, - SockProto::ProtoOnehundredandeightyeight => 188, - SockProto::ProtoOnehundredandeightynine => 189, - SockProto::ProtoOnehundredandninety => 190, - SockProto::ProtoOnehundredandninetyone => 191, - SockProto::ProtoOnehundredandninetytwo => 192, - SockProto::ProtoOnehundredandninetythree => 193, - SockProto::ProtoOnehundredandninetyfour => 194, - SockProto::ProtoOnehundredandninetyfive => 195, - SockProto::ProtoOnehundredandninetysix => 196, - SockProto::ProtoOnehundredandninetyseven => 197, - SockProto::ProtoOnehundredandninetyeight => 198, - SockProto::ProtoOnehundredandninetynine => 199, - SockProto::ProtoTwohundred => 200, - SockProto::ProtoTwohundredandone => 201, - SockProto::ProtoTwohundredandtwo => 202, - SockProto::ProtoTwohundredandthree => 203, - SockProto::ProtoTwohundredandfour => 204, - SockProto::ProtoTwohundredandfive => 205, - SockProto::ProtoTwohundredandsix => 206, - SockProto::ProtoTwohundredandseven => 207, - SockProto::ProtoTwohundredandeight => 208, - SockProto::ProtoTwohundredandnine => 209, - SockProto::ProtoTwohundredandten => 210, - SockProto::ProtoTwohundredandeleven => 211, - SockProto::ProtoTwohundredandtwelve => 212, - SockProto::ProtoTwohundredandthirteen => 213, - SockProto::ProtoTwohundredandfourteen => 214, - SockProto::ProtoTwohundredandfifteen => 215, - SockProto::ProtoTwohundredandsixteen => 216, - SockProto::ProtoTwohundredandseventeen => 217, - SockProto::ProtoTwohundredandeighteen => 218, - SockProto::ProtoTwohundredandnineteen => 219, - SockProto::ProtoTwohundredandtwenty => 220, - SockProto::ProtoTwohundredandtwentyone => 221, - SockProto::ProtoTwohundredandtwentytwo => 222, - SockProto::ProtoTwohundredandtwentythree => 223, - SockProto::ProtoTwohundredandtwentyfour => 224, - SockProto::ProtoTwohundredandtwentyfive => 225, - SockProto::ProtoTwohundredandtwentysix => 226, - SockProto::ProtoTwohundredandtwentyseven => 227, - SockProto::ProtoTwohundredandtwentyeight => 228, - SockProto::ProtoTwohundredandtwentynine => 229, - SockProto::ProtoTwohundredandthirty => 230, - SockProto::ProtoTwohundredandthirtyone => 231, - SockProto::ProtoTwohundredandthirtytwo => 232, - SockProto::ProtoTwohundredandthirtythree => 233, - SockProto::ProtoTwohundredandthirtyfour => 234, - SockProto::ProtoTwohundredandthirtyfive => 235, - SockProto::ProtoTwohundredandthirtysix => 236, - SockProto::ProtoTwohundredandthirtyseven => 237, - SockProto::ProtoTwohundredandthirtyeight => 238, - SockProto::ProtoTwohundredandthirtynine => 239, - SockProto::ProtoTwohundredandfourty => 240, - SockProto::ProtoTwohundredandfourtyone => 241, - SockProto::ProtoTwohundredandfourtytwo => 242, - SockProto::ProtoTwohundredandfourtythree => 243, - SockProto::ProtoTwohundredandfourtyfour => 244, - SockProto::ProtoTwohundredandfourtyfive => 245, - SockProto::ProtoTwohundredandfourtysix => 246, - SockProto::ProtoTwohundredandfourtyseven => 247, - SockProto::ProtoTwohundredandfourtyeight => 248, - SockProto::ProtoTwohundredandfourtynine => 249, - SockProto::ProtoTwohundredandfifty => 250, - SockProto::ProtoTwohundredandfiftyone => 251, - SockProto::ProtoTwohundredandfiftytwo => 252, - SockProto::ProtoTwohundredandfiftythree => 253, - SockProto::ProtoTwohundredandfiftyfour => 254, - SockProto::ProtoRaw => 255, - SockProto::ProtoTwohundredandfiftysix => 256, - SockProto::ProtoTwohundredandfiftyseven => 257, - SockProto::ProtoTwohundredandfiftyeight => 258, - SockProto::ProtoTwohundredandfiftynine => 259, - SockProto::ProtoTwohundredandsixty => 260, - SockProto::ProtoTwohundredandsixtyone => 261, - SockProto::Mptcp => 262, - SockProto::Max => 263, - }) as u16; - let OptionTimestamp{ tag:tag53, u:u53, } = option_timestamp; - *((ptr0 + 672) as *mut u8) = (match tag53 { - OptionTag::None => 0, - OptionTag::Some => 1, - }) as u8; - *((ptr0 + 680) as *mut i64) = wit_bindgen_rust::rt::as_i64(u53); - let AddrUnspec{ n0:n054, } = addr_unspec; - *((ptr0 + 688) as *mut u8) = (wit_bindgen_rust::rt::as_i32(n054)) as u8; - let AddrUnspecPort{ port:port55, addr:addr55, } = addr_unspec_port; - *((ptr0 + 690) as *mut u16) = (wit_bindgen_rust::rt::as_i32(port55)) as u16; - let AddrUnspec{ n0:n056, } = addr55; - *((ptr0 + 692) as *mut u8) = (wit_bindgen_rust::rt::as_i32(n056)) as u8; - let CidrUnspec{ addr:addr57, prefix:prefix57, } = cidr_unspec; - let AddrUnspec{ n0:n058, } = addr57; - *((ptr0 + 694) as *mut u8) = (wit_bindgen_rust::rt::as_i32(n058)) as u8; - *((ptr0 + 695) as *mut u8) = (wit_bindgen_rust::rt::as_i32(prefix57)) as u8; - let HttpHandles{ req:req59, res:res59, hdr:hdr59, } = http_handles; - *((ptr0 + 696) as *mut i32) = wit_bindgen_rust::rt::as_i32(req59); - *((ptr0 + 700) as *mut i32) = wit_bindgen_rust::rt::as_i32(res59); - *((ptr0 + 704) as *mut i32) = wit_bindgen_rust::rt::as_i32(hdr59); - let HttpStatus{ ok:ok60, redirect:redirect60, size:size60, status:status60, } = http_status; - *((ptr0 + 712) as *mut u8) = (match ok60 { - Bool::False => 0, - Bool::True => 1, - }) as u8; - *((ptr0 + 713) as *mut u8) = (match redirect60 { - Bool::False => 0, - Bool::True => 1, - }) as u8; - *((ptr0 + 720) as *mut i64) = wit_bindgen_rust::rt::as_i64(size60); - *((ptr0 + 728) as *mut u16) = (wit_bindgen_rust::rt::as_i32(status60)) as u16; - *((ptr0 + 736) as *mut u16) = (wit_bindgen_rust::rt::as_i32(ri_flags)) as u16; - *((ptr0 + 738) as *mut u16) = (wit_bindgen_rust::rt::as_i32(ro_flags)) as u16; - *((ptr0 + 740) as *mut u8) = (wit_bindgen_rust::rt::as_i32(sd_flags)) as u8; - *((ptr0 + 742) as *mut u16) = (wit_bindgen_rust::rt::as_i32(si_flags)) as u16; - *((ptr0 + 744) as *mut u8) = (match timeout { - Timeout::Read => 0, - Timeout::Write => 1, - Timeout::Connect => 2, - Timeout::Accept => 3, - }) as u8; - #[link(wasm_import_module = "output")] - extern "C" { - #[cfg_attr(target_arch = "wasm32", link_name = "expose-types-dummy-func")] - #[cfg_attr(not(target_arch = "wasm32"), link_name = "output_expose-types-dummy-func")] - fn wit_import(_: i32, ); - } - wit_import(ptr0); - () - } - } - - #[repr(align(8))] - struct RetArea([u8; 752]); - static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 752]); } diff --git a/lib/wasi-types-generated/src/wasi/extra.rs b/lib/wasi-types-generated/src/wasi/extra.rs index 5032307702a..dd3c9a3fea9 100644 --- a/lib/wasi-types-generated/src/wasi/extra.rs +++ b/lib/wasi-types-generated/src/wasi/extra.rs @@ -2674,1067 +2674,6 @@ impl core::fmt::Debug for Timeout { } } } -/// Dummy function to expose types into generated code -pub fn expose_types_dummy_func( - fd: Fd, - dirent: Dirent, - snapshot0_dirent: Snapshot0Dirent, - snapshot0_event: Snapshot0Event, - event_enum: EventEnum, - event: Event, - fdstat: Fdstat, - subscription_clock: SubscriptionClock, - snapshot0_subscription_clock: Snapshot0SubscriptionClock, - subscription: Subscription, - snapshot0_subscription: Snapshot0Subscription, - device: Device, - linkcount: Linkcount, - snapshot0_linkcount: Snapshot0Linkcount, - filestat: Filestat, - snapshot0_filestat: Snapshot0Filestat, - tty: Tty, - tid: Tid, - pid: Pid, - bus_data_format: BusDataFormat, - bid: Bid, - option_bid: OptionBid, - cid: Cid, - option_cid: OptionCid, - option_fd: OptionFd, - bus_handles: BusHandles, - exit_code: ExitCode, - bus_event_exit: BusEventExit, - bus_event_fault: BusEventFault, - bus_event_close: BusEventClose, - prestat_u_dir: PrestatUDir, - prestat_u: PrestatU, - event_fd_flags: EventFdFlags, - prestat: Prestat, - file_delta: FileDelta, - lookup_flags: LookupFlags, - count: Count, - bool: Bool, - pipe_handles: PipeHandles, - stdio_mode: StdioMode, - sock_proto: SockProto, - option_timestamp: OptionTimestamp, - addr_unspec: AddrUnspec, - addr_unspec_port: AddrUnspecPort, - cidr_unspec: CidrUnspec, - http_handles: HttpHandles, - http_status: HttpStatus, - ri_flags: RiFlags, - ro_flags: RoFlags, - sd_flags: SdFlags, - si_flags: SiFlags, - timeout: Timeout, -) -> () { - unsafe { - let ptr0 = OUTPUT_RET_AREA.0.as_mut_ptr() as i32; - *((ptr0 + 0) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd); - let Dirent { - d_next: d_next1, - d_ino: d_ino1, - d_type: d_type1, - d_namlen: d_namlen1, - } = dirent; - *((ptr0 + 8) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_next1); - *((ptr0 + 16) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_ino1); - *((ptr0 + 24) as *mut u8) = (match d_type1 { - Filetype::Unknown => 0, - Filetype::BlockDevice => 1, - Filetype::CharacterDevice => 2, - Filetype::Directory => 3, - Filetype::RegularFile => 4, - Filetype::SocketDgram => 5, - Filetype::SocketStream => 6, - Filetype::SymbolicLink => 7, - Filetype::Fifo => 8, - }) as u8; - *((ptr0 + 28) as *mut i32) = wit_bindgen_rust::rt::as_i32(d_namlen1); - let Snapshot0Dirent { - d_next: d_next2, - d_ino: d_ino2, - d_namlen: d_namlen2, - d_type: d_type2, - } = snapshot0_dirent; - *((ptr0 + 32) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_next2); - *((ptr0 + 40) as *mut i64) = wit_bindgen_rust::rt::as_i64(d_ino2); - *((ptr0 + 48) as *mut i32) = wit_bindgen_rust::rt::as_i32(d_namlen2); - *((ptr0 + 52) as *mut u8) = (match d_type2 { - Filetype::Unknown => 0, - Filetype::BlockDevice => 1, - Filetype::CharacterDevice => 2, - Filetype::Directory => 3, - Filetype::RegularFile => 4, - Filetype::SocketDgram => 5, - Filetype::SocketStream => 6, - Filetype::SymbolicLink => 7, - Filetype::Fifo => 8, - }) as u8; - let Snapshot0Event { - userdata: userdata3, - error: error3, - type_: type_3, - fd_readwrite: fd_readwrite3, - } = snapshot0_event; - *((ptr0 + 56) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata3); - *((ptr0 + 64) as *mut u8) = (match error3 { - Errno::Success => 0, - Errno::Toobig => 1, - Errno::Access => 2, - Errno::Addrinuse => 3, - Errno::Addrnotavail => 4, - Errno::Afnosupport => 5, - Errno::Again => 6, - Errno::Already => 7, - Errno::Badf => 8, - Errno::Badmsg => 9, - Errno::Busy => 10, - Errno::Canceled => 11, - Errno::Child => 12, - Errno::Connaborted => 13, - Errno::Connrefused => 14, - Errno::Connreset => 15, - Errno::Deadlk => 16, - Errno::Destaddrreq => 17, - Errno::Dom => 18, - Errno::Dquot => 19, - Errno::Exist => 20, - Errno::Fault => 21, - Errno::Fbig => 22, - Errno::Hostunreach => 23, - Errno::Idrm => 24, - Errno::Ilseq => 25, - Errno::Inprogress => 26, - Errno::Intr => 27, - Errno::Inval => 28, - Errno::Io => 29, - Errno::Isconn => 30, - Errno::Isdir => 31, - Errno::Loop => 32, - Errno::Mfile => 33, - Errno::Mlink => 34, - Errno::Msgsize => 35, - Errno::Multihop => 36, - Errno::Nametoolong => 37, - Errno::Netdown => 38, - Errno::Netreset => 39, - Errno::Netunreach => 40, - Errno::Nfile => 41, - Errno::Nobufs => 42, - Errno::Nodev => 43, - Errno::Noent => 44, - Errno::Noexec => 45, - Errno::Nolck => 46, - Errno::Nolink => 47, - Errno::Nomem => 48, - Errno::Nomsg => 49, - Errno::Noprotoopt => 50, - Errno::Nospc => 51, - Errno::Nosys => 52, - Errno::Notconn => 53, - Errno::Notdir => 54, - Errno::Notempty => 55, - Errno::Notrecoverable => 56, - Errno::Notsock => 57, - Errno::Notsup => 58, - Errno::Notty => 59, - Errno::Nxio => 60, - Errno::Overflow => 61, - Errno::Ownerdead => 62, - Errno::Perm => 63, - Errno::Pipe => 64, - Errno::Proto => 65, - Errno::Protonosupport => 66, - Errno::Prototype => 67, - Errno::Range => 68, - Errno::Rofs => 69, - Errno::Spipe => 70, - Errno::Srch => 71, - Errno::Stale => 72, - Errno::Timedout => 73, - Errno::Txtbsy => 74, - Errno::Xdev => 75, - Errno::Notcapable => 76, - }) as u8; - *((ptr0 + 65) as *mut u8) = (match type_3 { - Eventtype::Clock => 0, - Eventtype::FdRead => 1, - Eventtype::FdWrite => 2, - }) as u8; - let EventFdReadwrite { - nbytes: nbytes4, - flags: flags4, - } = fd_readwrite3; - *((ptr0 + 72) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes4); - let flags5 = flags4; - *((ptr0 + 80) as *mut u8) = ((flags5.bits() >> 0) as i32) as u8; - match event_enum { - EventEnum::FdRead(e) => { - *((ptr0 + 88) as *mut u8) = (0i32) as u8; - let EventFdReadwrite { - nbytes: nbytes6, - flags: flags6, - } = e; - *((ptr0 + 96) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes6); - let flags7 = flags6; - *((ptr0 + 104) as *mut u8) = ((flags7.bits() >> 0) as i32) as u8; - } - EventEnum::FdWrite(e) => { - *((ptr0 + 88) as *mut u8) = (1i32) as u8; - let EventFdReadwrite { - nbytes: nbytes8, - flags: flags8, - } = e; - *((ptr0 + 96) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes8); - let flags9 = flags8; - *((ptr0 + 104) as *mut u8) = ((flags9.bits() >> 0) as i32) as u8; - } - EventEnum::Clock => { - let e = (); - { - *((ptr0 + 88) as *mut u8) = (2i32) as u8; - let () = e; - } - } - }; - let Event { - userdata: userdata10, - error: error10, - data: data10, - } = event; - *((ptr0 + 112) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata10); - *((ptr0 + 120) as *mut u8) = (match error10 { - Errno::Success => 0, - Errno::Toobig => 1, - Errno::Access => 2, - Errno::Addrinuse => 3, - Errno::Addrnotavail => 4, - Errno::Afnosupport => 5, - Errno::Again => 6, - Errno::Already => 7, - Errno::Badf => 8, - Errno::Badmsg => 9, - Errno::Busy => 10, - Errno::Canceled => 11, - Errno::Child => 12, - Errno::Connaborted => 13, - Errno::Connrefused => 14, - Errno::Connreset => 15, - Errno::Deadlk => 16, - Errno::Destaddrreq => 17, - Errno::Dom => 18, - Errno::Dquot => 19, - Errno::Exist => 20, - Errno::Fault => 21, - Errno::Fbig => 22, - Errno::Hostunreach => 23, - Errno::Idrm => 24, - Errno::Ilseq => 25, - Errno::Inprogress => 26, - Errno::Intr => 27, - Errno::Inval => 28, - Errno::Io => 29, - Errno::Isconn => 30, - Errno::Isdir => 31, - Errno::Loop => 32, - Errno::Mfile => 33, - Errno::Mlink => 34, - Errno::Msgsize => 35, - Errno::Multihop => 36, - Errno::Nametoolong => 37, - Errno::Netdown => 38, - Errno::Netreset => 39, - Errno::Netunreach => 40, - Errno::Nfile => 41, - Errno::Nobufs => 42, - Errno::Nodev => 43, - Errno::Noent => 44, - Errno::Noexec => 45, - Errno::Nolck => 46, - Errno::Nolink => 47, - Errno::Nomem => 48, - Errno::Nomsg => 49, - Errno::Noprotoopt => 50, - Errno::Nospc => 51, - Errno::Nosys => 52, - Errno::Notconn => 53, - Errno::Notdir => 54, - Errno::Notempty => 55, - Errno::Notrecoverable => 56, - Errno::Notsock => 57, - Errno::Notsup => 58, - Errno::Notty => 59, - Errno::Nxio => 60, - Errno::Overflow => 61, - Errno::Ownerdead => 62, - Errno::Perm => 63, - Errno::Pipe => 64, - Errno::Proto => 65, - Errno::Protonosupport => 66, - Errno::Prototype => 67, - Errno::Range => 68, - Errno::Rofs => 69, - Errno::Spipe => 70, - Errno::Srch => 71, - Errno::Stale => 72, - Errno::Timedout => 73, - Errno::Txtbsy => 74, - Errno::Xdev => 75, - Errno::Notcapable => 76, - }) as u8; - match data10 { - EventEnum::FdRead(e) => { - *((ptr0 + 128) as *mut u8) = (0i32) as u8; - let EventFdReadwrite { - nbytes: nbytes11, - flags: flags11, - } = e; - *((ptr0 + 136) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes11); - let flags12 = flags11; - *((ptr0 + 144) as *mut u8) = ((flags12.bits() >> 0) as i32) as u8; - } - EventEnum::FdWrite(e) => { - *((ptr0 + 128) as *mut u8) = (1i32) as u8; - let EventFdReadwrite { - nbytes: nbytes13, - flags: flags13, - } = e; - *((ptr0 + 136) as *mut i64) = wit_bindgen_rust::rt::as_i64(nbytes13); - let flags14 = flags13; - *((ptr0 + 144) as *mut u8) = ((flags14.bits() >> 0) as i32) as u8; - } - EventEnum::Clock => { - let e = (); - { - *((ptr0 + 128) as *mut u8) = (2i32) as u8; - let () = e; - } - } - }; - let Fdstat { - fs_filetype: fs_filetype15, - fs_flags: fs_flags15, - fs_rights_base: fs_rights_base15, - fs_rights_inheriting: fs_rights_inheriting15, - } = fdstat; - *((ptr0 + 152) as *mut u8) = (match fs_filetype15 { - Filetype::Unknown => 0, - Filetype::BlockDevice => 1, - Filetype::CharacterDevice => 2, - Filetype::Directory => 3, - Filetype::RegularFile => 4, - Filetype::SocketDgram => 5, - Filetype::SocketStream => 6, - Filetype::SymbolicLink => 7, - Filetype::Fifo => 8, - }) as u8; - let flags16 = fs_flags15; - *((ptr0 + 153) as *mut u8) = ((flags16.bits() >> 0) as i32) as u8; - let flags17 = fs_rights_base15; - *((ptr0 + 160) as *mut i32) = (flags17.bits() >> 32) as i32; - *((ptr0 + 156) as *mut i32) = (flags17.bits() >> 0) as i32; - let flags18 = fs_rights_inheriting15; - *((ptr0 + 168) as *mut i32) = (flags18.bits() >> 32) as i32; - *((ptr0 + 164) as *mut i32) = (flags18.bits() >> 0) as i32; - let SubscriptionClock { - clock_id: clock_id19, - timeout: timeout19, - precision: precision19, - flags: flags19, - } = subscription_clock; - *((ptr0 + 176) as *mut u8) = (match clock_id19 { - Clockid::Realtime => 0, - Clockid::Monotonic => 1, - }) as u8; - *((ptr0 + 184) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout19); - *((ptr0 + 192) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision19); - let flags20 = flags19; - *((ptr0 + 200) as *mut u8) = ((flags20.bits() >> 0) as i32) as u8; - let Snapshot0SubscriptionClock { - identifier: identifier21, - id: id21, - timeout: timeout21, - precision: precision21, - flags: flags21, - } = snapshot0_subscription_clock; - *((ptr0 + 208) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier21); - *((ptr0 + 216) as *mut u8) = (match id21 { - Snapshot0Clockid::Realtime => 0, - Snapshot0Clockid::Monotonic => 1, - Snapshot0Clockid::ProcessCputimeId => 2, - Snapshot0Clockid::ThreadCputimeId => 3, - }) as u8; - *((ptr0 + 224) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout21); - *((ptr0 + 232) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision21); - let flags22 = flags21; - *((ptr0 + 240) as *mut u8) = ((flags22.bits() >> 0) as i32) as u8; - let Subscription { - userdata: userdata23, - data: data23, - } = subscription; - *((ptr0 + 248) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata23); - match data23 { - SubscriptionEnum::Clock(e) => { - *((ptr0 + 256) as *mut u8) = (0i32) as u8; - let SubscriptionClock { - clock_id: clock_id24, - timeout: timeout24, - precision: precision24, - flags: flags24, - } = e; - *((ptr0 + 264) as *mut u8) = (match clock_id24 { - Clockid::Realtime => 0, - Clockid::Monotonic => 1, - }) as u8; - *((ptr0 + 272) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout24); - *((ptr0 + 280) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision24); - let flags25 = flags24; - *((ptr0 + 288) as *mut u8) = ((flags25.bits() >> 0) as i32) as u8; - } - SubscriptionEnum::Read(e) => { - *((ptr0 + 256) as *mut u8) = (1i32) as u8; - let SubscriptionFsReadwrite { - file_descriptor: file_descriptor26, - } = e; - *((ptr0 + 264) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor26); - } - SubscriptionEnum::Write(e) => { - *((ptr0 + 256) as *mut u8) = (2i32) as u8; - let SubscriptionFsReadwrite { - file_descriptor: file_descriptor27, - } = e; - *((ptr0 + 264) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor27); - } - }; - let Snapshot0Subscription { - userdata: userdata28, - data: data28, - } = snapshot0_subscription; - *((ptr0 + 296) as *mut i64) = wit_bindgen_rust::rt::as_i64(userdata28); - match data28 { - Snapshot0SubscriptionEnum::Clock(e) => { - *((ptr0 + 304) as *mut u8) = (0i32) as u8; - let Snapshot0SubscriptionClock { - identifier: identifier29, - id: id29, - timeout: timeout29, - precision: precision29, - flags: flags29, - } = e; - *((ptr0 + 312) as *mut i64) = wit_bindgen_rust::rt::as_i64(identifier29); - *((ptr0 + 320) as *mut u8) = (match id29 { - Snapshot0Clockid::Realtime => 0, - Snapshot0Clockid::Monotonic => 1, - Snapshot0Clockid::ProcessCputimeId => 2, - Snapshot0Clockid::ThreadCputimeId => 3, - }) as u8; - *((ptr0 + 328) as *mut i64) = wit_bindgen_rust::rt::as_i64(timeout29); - *((ptr0 + 336) as *mut i64) = wit_bindgen_rust::rt::as_i64(precision29); - let flags30 = flags29; - *((ptr0 + 344) as *mut u8) = ((flags30.bits() >> 0) as i32) as u8; - } - Snapshot0SubscriptionEnum::Read(e) => { - *((ptr0 + 304) as *mut u8) = (1i32) as u8; - let SubscriptionFsReadwrite { - file_descriptor: file_descriptor31, - } = e; - *((ptr0 + 312) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor31); - } - Snapshot0SubscriptionEnum::Write(e) => { - *((ptr0 + 304) as *mut u8) = (2i32) as u8; - let SubscriptionFsReadwrite { - file_descriptor: file_descriptor32, - } = e; - *((ptr0 + 312) as *mut i32) = wit_bindgen_rust::rt::as_i32(file_descriptor32); - } - }; - *((ptr0 + 352) as *mut i64) = wit_bindgen_rust::rt::as_i64(device); - *((ptr0 + 360) as *mut i64) = wit_bindgen_rust::rt::as_i64(linkcount); - *((ptr0 + 368) as *mut i32) = wit_bindgen_rust::rt::as_i32(snapshot0_linkcount); - let Filestat { - st_dev: st_dev33, - st_ino: st_ino33, - st_filetype: st_filetype33, - st_nlink: st_nlink33, - st_size: st_size33, - st_atim: st_atim33, - st_mtim: st_mtim33, - st_ctim: st_ctim33, - } = filestat; - *((ptr0 + 376) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev33); - *((ptr0 + 384) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino33); - *((ptr0 + 392) as *mut u8) = (match st_filetype33 { - Filetype::Unknown => 0, - Filetype::BlockDevice => 1, - Filetype::CharacterDevice => 2, - Filetype::Directory => 3, - Filetype::RegularFile => 4, - Filetype::SocketDgram => 5, - Filetype::SocketStream => 6, - Filetype::SymbolicLink => 7, - Filetype::Fifo => 8, - }) as u8; - *((ptr0 + 400) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_nlink33); - *((ptr0 + 408) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size33); - *((ptr0 + 416) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim33); - *((ptr0 + 424) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim33); - *((ptr0 + 432) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim33); - let Snapshot0Filestat { - st_dev: st_dev34, - st_ino: st_ino34, - st_filetype: st_filetype34, - st_nlink: st_nlink34, - st_size: st_size34, - st_atim: st_atim34, - st_mtim: st_mtim34, - st_ctim: st_ctim34, - } = snapshot0_filestat; - *((ptr0 + 440) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_dev34); - *((ptr0 + 448) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ino34); - *((ptr0 + 456) as *mut u8) = (match st_filetype34 { - Filetype::Unknown => 0, - Filetype::BlockDevice => 1, - Filetype::CharacterDevice => 2, - Filetype::Directory => 3, - Filetype::RegularFile => 4, - Filetype::SocketDgram => 5, - Filetype::SocketStream => 6, - Filetype::SymbolicLink => 7, - Filetype::Fifo => 8, - }) as u8; - *((ptr0 + 460) as *mut i32) = wit_bindgen_rust::rt::as_i32(st_nlink34); - *((ptr0 + 464) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_size34); - *((ptr0 + 472) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_atim34); - *((ptr0 + 480) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_mtim34); - *((ptr0 + 488) as *mut i64) = wit_bindgen_rust::rt::as_i64(st_ctim34); - let Tty { - cols: cols35, - rows: rows35, - width: width35, - height: height35, - stdin_tty: stdin_tty35, - stdout_tty: stdout_tty35, - stderr_tty: stderr_tty35, - echo: echo35, - line_buffered: line_buffered35, - } = tty; - *((ptr0 + 496) as *mut i32) = wit_bindgen_rust::rt::as_i32(cols35); - *((ptr0 + 500) as *mut i32) = wit_bindgen_rust::rt::as_i32(rows35); - *((ptr0 + 504) as *mut i32) = wit_bindgen_rust::rt::as_i32(width35); - *((ptr0 + 508) as *mut i32) = wit_bindgen_rust::rt::as_i32(height35); - *((ptr0 + 512) as *mut u8) = (match stdin_tty35 { - true => 1, - false => 0, - }) as u8; - *((ptr0 + 513) as *mut u8) = (match stdout_tty35 { - true => 1, - false => 0, - }) as u8; - *((ptr0 + 514) as *mut u8) = (match stderr_tty35 { - true => 1, - false => 0, - }) as u8; - *((ptr0 + 515) as *mut u8) = (match echo35 { - true => 1, - false => 0, - }) as u8; - *((ptr0 + 516) as *mut u8) = (match line_buffered35 { - true => 1, - false => 0, - }) as u8; - *((ptr0 + 520) as *mut i32) = wit_bindgen_rust::rt::as_i32(tid); - *((ptr0 + 524) as *mut i32) = wit_bindgen_rust::rt::as_i32(pid); - *((ptr0 + 528) as *mut u8) = (match bus_data_format { - BusDataFormat::Raw => 0, - BusDataFormat::Bincode => 1, - BusDataFormat::MessagePack => 2, - BusDataFormat::Json => 3, - BusDataFormat::Yaml => 4, - BusDataFormat::Xml => 5, - BusDataFormat::Rkyv => 6, - }) as u8; - *((ptr0 + 532) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid); - let OptionBid { - tag: tag36, - bid: bid36, - } = option_bid; - *((ptr0 + 536) as *mut u8) = (match tag36 { - OptionTag::None => 0, - OptionTag::Some => 1, - }) as u8; - *((ptr0 + 540) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid36); - *((ptr0 + 544) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid); - let OptionCid { - tag: tag37, - cid: cid37, - } = option_cid; - *((ptr0 + 548) as *mut u8) = (match tag37 { - OptionTag::None => 0, - OptionTag::Some => 1, - }) as u8; - *((ptr0 + 552) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid37); - let OptionFd { - tag: tag38, - fd: fd38, - } = option_fd; - *((ptr0 + 556) as *mut u8) = (match tag38 { - OptionTag::None => 0, - OptionTag::Some => 1, - }) as u8; - *((ptr0 + 560) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd38); - let BusHandles { - bid: bid39, - stdin: stdin39, - stdout: stdout39, - stderr: stderr39, - } = bus_handles; - *((ptr0 + 564) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid39); - let OptionFd { - tag: tag40, - fd: fd40, - } = stdin39; - *((ptr0 + 568) as *mut u8) = (match tag40 { - OptionTag::None => 0, - OptionTag::Some => 1, - }) as u8; - *((ptr0 + 572) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd40); - let OptionFd { - tag: tag41, - fd: fd41, - } = stdout39; - *((ptr0 + 576) as *mut u8) = (match tag41 { - OptionTag::None => 0, - OptionTag::Some => 1, - }) as u8; - *((ptr0 + 580) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd41); - let OptionFd { - tag: tag42, - fd: fd42, - } = stderr39; - *((ptr0 + 584) as *mut u8) = (match tag42 { - OptionTag::None => 0, - OptionTag::Some => 1, - }) as u8; - *((ptr0 + 588) as *mut i32) = wit_bindgen_rust::rt::as_i32(fd42); - *((ptr0 + 592) as *mut i32) = wit_bindgen_rust::rt::as_i32(exit_code); - let BusEventExit { - bid: bid43, - rval: rval43, - } = bus_event_exit; - *((ptr0 + 596) as *mut i32) = wit_bindgen_rust::rt::as_i32(bid43); - *((ptr0 + 600) as *mut i32) = wit_bindgen_rust::rt::as_i32(rval43); - let BusEventFault { - cid: cid44, - err: err44, - } = bus_event_fault; - *((ptr0 + 604) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid44); - *((ptr0 + 608) as *mut u8) = (match err44 { - BusErrno::Success => 0, - BusErrno::Ser => 1, - BusErrno::Des => 2, - BusErrno::Wapm => 3, - BusErrno::Fetch => 4, - BusErrno::Compile => 5, - BusErrno::Abi => 6, - BusErrno::Aborted => 7, - BusErrno::Badhandle => 8, - BusErrno::Topic => 9, - BusErrno::Badcb => 10, - BusErrno::Unsupported => 11, - BusErrno::Badrequest => 12, - BusErrno::Denied => 13, - BusErrno::Internal => 14, - BusErrno::Alloc => 15, - BusErrno::Invoke => 16, - BusErrno::Consumed => 17, - BusErrno::Memviolation => 18, - BusErrno::Unknown => 19, - }) as u8; - let BusEventClose { cid: cid45 } = bus_event_close; - *((ptr0 + 612) as *mut i32) = wit_bindgen_rust::rt::as_i32(cid45); - let PrestatUDir { - pr_name_len: pr_name_len46, - } = prestat_u_dir; - *((ptr0 + 616) as *mut i32) = wit_bindgen_rust::rt::as_i32(pr_name_len46); - let PrestatU { dir: dir47 } = prestat_u; - let PrestatUDir { - pr_name_len: pr_name_len48, - } = dir47; - *((ptr0 + 620) as *mut i32) = wit_bindgen_rust::rt::as_i32(pr_name_len48); - *((ptr0 + 624) as *mut u16) = (wit_bindgen_rust::rt::as_i32(event_fd_flags)) as u16; - let Prestat { - pr_type: pr_type49, - u: u49, - } = prestat; - *((ptr0 + 628) as *mut u8) = (match pr_type49 { - Preopentype::Dir => 0, - }) as u8; - let PrestatU { dir: dir50 } = u49; - let PrestatUDir { - pr_name_len: pr_name_len51, - } = dir50; - *((ptr0 + 632) as *mut i32) = wit_bindgen_rust::rt::as_i32(pr_name_len51); - *((ptr0 + 640) as *mut i64) = wit_bindgen_rust::rt::as_i64(file_delta); - *((ptr0 + 648) as *mut i32) = wit_bindgen_rust::rt::as_i32(lookup_flags); - *((ptr0 + 652) as *mut i32) = wit_bindgen_rust::rt::as_i32(count); - *((ptr0 + 656) as *mut u8) = (match bool { - Bool::False => 0, - Bool::True => 1, - }) as u8; - let PipeHandles { - pipe: pipe52, - other: other52, - } = pipe_handles; - *((ptr0 + 660) as *mut i32) = wit_bindgen_rust::rt::as_i32(pipe52); - *((ptr0 + 664) as *mut i32) = wit_bindgen_rust::rt::as_i32(other52); - *((ptr0 + 668) as *mut u8) = (match stdio_mode { - StdioMode::Reserved => 0, - StdioMode::Piped => 1, - StdioMode::Inherit => 2, - StdioMode::Null => 3, - StdioMode::Log => 4, - }) as u8; - *((ptr0 + 670) as *mut u16) = (match sock_proto { - SockProto::Ip => 0, - SockProto::Icmp => 1, - SockProto::Igmp => 2, - SockProto::ProtoThree => 3, - SockProto::Ipip => 4, - SockProto::ProtoFive => 5, - SockProto::Tcp => 6, - SockProto::ProtoSeven => 7, - SockProto::Egp => 8, - SockProto::ProtoNine => 9, - SockProto::ProtoTen => 10, - SockProto::ProtoEleven => 11, - SockProto::Pup => 12, - SockProto::ProtoThirteen => 13, - SockProto::ProtoFourteen => 14, - SockProto::ProtoFifteen => 15, - SockProto::ProtoSixteen => 16, - SockProto::Udp => 17, - SockProto::ProtoEighteen => 18, - SockProto::ProtoNineteen => 19, - SockProto::ProtoTwenty => 20, - SockProto::ProtoTwentyone => 21, - SockProto::Idp => 22, - SockProto::ProtoTwentythree => 23, - SockProto::ProtoTwentyfour => 24, - SockProto::ProtoTwentyfive => 25, - SockProto::ProtoTwentysix => 26, - SockProto::ProtoTwentyseven => 27, - SockProto::ProtoTwentyeight => 28, - SockProto::ProtoTp => 29, - SockProto::ProtoThirty => 30, - SockProto::ProtoThirtyone => 31, - SockProto::ProtoThirtytwo => 32, - SockProto::Dccp => 33, - SockProto::ProtoThirtyfour => 34, - SockProto::ProtoThirtyfive => 35, - SockProto::ProtoThirtysix => 36, - SockProto::ProtoThirtyseven => 37, - SockProto::ProtoThirtyeight => 38, - SockProto::ProtoThirtynine => 39, - SockProto::ProtoFourty => 40, - SockProto::Ipv6 => 41, - SockProto::ProtoFourtytwo => 42, - SockProto::Routing => 43, - SockProto::Fragment => 44, - SockProto::ProtoFourtyfive => 45, - SockProto::Rsvp => 46, - SockProto::Gre => 47, - SockProto::ProtoFourtyeight => 48, - SockProto::ProtoFourtynine => 49, - SockProto::Esp => 50, - SockProto::Ah => 51, - SockProto::ProtoFiftytwo => 52, - SockProto::ProtoFiftythree => 53, - SockProto::ProtoFiftyfour => 54, - SockProto::ProtoFiftyfive => 55, - SockProto::ProtoFiftysix => 56, - SockProto::ProtoFiftyseven => 57, - SockProto::Icmpv6 => 58, - SockProto::None => 59, - SockProto::Dstopts => 60, - SockProto::ProtoSixtyone => 61, - SockProto::ProtoSixtytwo => 62, - SockProto::ProtoSixtythree => 63, - SockProto::ProtoSixtyfour => 64, - SockProto::ProtoSixtyfive => 65, - SockProto::ProtoSixtysix => 66, - SockProto::ProtoSixtyseven => 67, - SockProto::ProtoSixtyeight => 68, - SockProto::ProtoSixtynine => 69, - SockProto::ProtoSeventy => 70, - SockProto::ProtoSeventyone => 71, - SockProto::ProtoSeventytwo => 72, - SockProto::ProtoSeventythree => 73, - SockProto::ProtoSeventyfour => 74, - SockProto::ProtoSeventyfive => 75, - SockProto::ProtoSeventysix => 76, - SockProto::ProtoSeventyseven => 77, - SockProto::ProtoSeventyeight => 78, - SockProto::ProtoSeventynine => 79, - SockProto::ProtoEighty => 80, - SockProto::ProtoEightyone => 81, - SockProto::ProtoEightytwo => 82, - SockProto::ProtoEightythree => 83, - SockProto::ProtoEightyfour => 84, - SockProto::ProtoEightyfive => 85, - SockProto::ProtoEightysix => 86, - SockProto::ProtoEightyseven => 87, - SockProto::ProtoEightyeight => 88, - SockProto::ProtoEightynine => 89, - SockProto::ProtoNinety => 90, - SockProto::ProtoNinetyone => 91, - SockProto::Mtp => 92, - SockProto::ProtoNinetythree => 93, - SockProto::Beetph => 94, - SockProto::ProtoNinetyfive => 95, - SockProto::ProtoNinetysix => 96, - SockProto::ProtoNineetyseven => 97, - SockProto::Encap => 98, - SockProto::ProtoNinetynine => 99, - SockProto::ProtoOnehundred => 100, - SockProto::ProtoOnehundredandone => 101, - SockProto::ProtoOnehundredandtwo => 102, - SockProto::Pim => 103, - SockProto::ProtoOnehundredandfour => 104, - SockProto::ProtoOnehundredandfive => 105, - SockProto::ProtoOnehundredandsix => 106, - SockProto::ProtoOnehundredandseven => 107, - SockProto::Comp => 108, - SockProto::ProtoOnehundredandnine => 109, - SockProto::ProtoOnehundredandten => 110, - SockProto::ProtoOnehundredandeleven => 111, - SockProto::ProtoOnehundredandtwelve => 112, - SockProto::ProtoOnehundredandthirteen => 113, - SockProto::ProtoOnehundredandfourteen => 114, - SockProto::ProtoOnehundredandfifteen => 115, - SockProto::ProtoOnehundredandsixteen => 116, - SockProto::ProtoOnehundredandseventeen => 117, - SockProto::ProtoOnehundredandeighteen => 118, - SockProto::ProtoOnehundredandnineteen => 119, - SockProto::ProtoOnehundredandtwenty => 120, - SockProto::ProtoOnehundredandtwentyone => 121, - SockProto::ProtoOnehundredandtwentytwo => 122, - SockProto::ProtoOnehundredandtwentythree => 123, - SockProto::ProtoOnehundredandtwentyfour => 124, - SockProto::ProtoOnehundredandtwentyfive => 125, - SockProto::ProtoOnehundredandtwentysix => 126, - SockProto::ProtoOnehundredandtwentyseven => 127, - SockProto::ProtoOnehundredandtwentyeight => 128, - SockProto::ProtoOnehundredandtwentynine => 129, - SockProto::ProtoOnehundredandthirty => 130, - SockProto::ProtoOnehundredandthirtyone => 131, - SockProto::Sctp => 132, - SockProto::ProtoOnehundredandthirtythree => 133, - SockProto::ProtoOnehundredandthirtyfour => 134, - SockProto::Mh => 135, - SockProto::Udplite => 136, - SockProto::Mpls => 137, - SockProto::ProtoOnehundredandthirtyeight => 138, - SockProto::ProtoOnehundredandthirtynine => 139, - SockProto::ProtoOnehundredandfourty => 140, - SockProto::ProtoOnehundredandfourtyone => 141, - SockProto::ProtoOnehundredandfourtytwo => 142, - SockProto::Ethernet => 143, - SockProto::ProtoOnehundredandfourtyfour => 144, - SockProto::ProtoOnehundredandfourtyfive => 145, - SockProto::ProtoOnehundredandfourtysix => 146, - SockProto::ProtoOnehundredandfourtyseven => 147, - SockProto::ProtoOnehundredandfourtyeight => 148, - SockProto::ProtoOnehundredandfourtynine => 149, - SockProto::ProtoOnehundredandfifty => 150, - SockProto::ProtoOnehundredandfiftyone => 151, - SockProto::ProtoOnehundredandfiftytwo => 152, - SockProto::ProtoOnehundredandfiftythree => 153, - SockProto::ProtoOnehundredandfiftyfour => 154, - SockProto::ProtoOnehundredandfiftyfive => 155, - SockProto::ProtoOnehundredandfiftysix => 156, - SockProto::ProtoOnehundredandfiftyseven => 157, - SockProto::ProtoOnehundredandfiftyeight => 158, - SockProto::ProtoOnehundredandfiftynine => 159, - SockProto::ProtoOnehundredandsixty => 160, - SockProto::ProtoOnehundredandsixtyone => 161, - SockProto::ProtoOnehundredandsixtytwo => 162, - SockProto::ProtoOnehundredandsixtythree => 163, - SockProto::ProtoOnehundredandsixtyfour => 164, - SockProto::ProtoOnehundredandsixtyfive => 165, - SockProto::ProtoOnehundredandsixtysix => 166, - SockProto::ProtoOnehundredandsixtyseven => 167, - SockProto::ProtoOnehundredandsixtyeight => 168, - SockProto::ProtoOnehundredandsixtynine => 169, - SockProto::ProtoOnehundredandseventy => 170, - SockProto::ProtoOnehundredandseventyone => 171, - SockProto::ProtoOnehundredandseventytwo => 172, - SockProto::ProtoOnehundredandseventythree => 173, - SockProto::ProtoOnehundredandseventyfour => 174, - SockProto::ProtoOnehundredandseventyfive => 175, - SockProto::ProtoOnehundredandseventysix => 176, - SockProto::ProtoOnehundredandseventyseven => 177, - SockProto::ProtoOnehundredandseventyeight => 178, - SockProto::ProtoOnehundredandseventynine => 179, - SockProto::ProtoOnehundredandeighty => 180, - SockProto::ProtoOnehundredandeightyone => 181, - SockProto::ProtoOnehundredandeightytwo => 182, - SockProto::ProtoOnehundredandeightythree => 183, - SockProto::ProtoOnehundredandeightyfour => 184, - SockProto::ProtoOnehundredandeightyfive => 185, - SockProto::ProtoOnehundredandeightysix => 186, - SockProto::ProtoOnehundredandeightyseven => 187, - SockProto::ProtoOnehundredandeightyeight => 188, - SockProto::ProtoOnehundredandeightynine => 189, - SockProto::ProtoOnehundredandninety => 190, - SockProto::ProtoOnehundredandninetyone => 191, - SockProto::ProtoOnehundredandninetytwo => 192, - SockProto::ProtoOnehundredandninetythree => 193, - SockProto::ProtoOnehundredandninetyfour => 194, - SockProto::ProtoOnehundredandninetyfive => 195, - SockProto::ProtoOnehundredandninetysix => 196, - SockProto::ProtoOnehundredandninetyseven => 197, - SockProto::ProtoOnehundredandninetyeight => 198, - SockProto::ProtoOnehundredandninetynine => 199, - SockProto::ProtoTwohundred => 200, - SockProto::ProtoTwohundredandone => 201, - SockProto::ProtoTwohundredandtwo => 202, - SockProto::ProtoTwohundredandthree => 203, - SockProto::ProtoTwohundredandfour => 204, - SockProto::ProtoTwohundredandfive => 205, - SockProto::ProtoTwohundredandsix => 206, - SockProto::ProtoTwohundredandseven => 207, - SockProto::ProtoTwohundredandeight => 208, - SockProto::ProtoTwohundredandnine => 209, - SockProto::ProtoTwohundredandten => 210, - SockProto::ProtoTwohundredandeleven => 211, - SockProto::ProtoTwohundredandtwelve => 212, - SockProto::ProtoTwohundredandthirteen => 213, - SockProto::ProtoTwohundredandfourteen => 214, - SockProto::ProtoTwohundredandfifteen => 215, - SockProto::ProtoTwohundredandsixteen => 216, - SockProto::ProtoTwohundredandseventeen => 217, - SockProto::ProtoTwohundredandeighteen => 218, - SockProto::ProtoTwohundredandnineteen => 219, - SockProto::ProtoTwohundredandtwenty => 220, - SockProto::ProtoTwohundredandtwentyone => 221, - SockProto::ProtoTwohundredandtwentytwo => 222, - SockProto::ProtoTwohundredandtwentythree => 223, - SockProto::ProtoTwohundredandtwentyfour => 224, - SockProto::ProtoTwohundredandtwentyfive => 225, - SockProto::ProtoTwohundredandtwentysix => 226, - SockProto::ProtoTwohundredandtwentyseven => 227, - SockProto::ProtoTwohundredandtwentyeight => 228, - SockProto::ProtoTwohundredandtwentynine => 229, - SockProto::ProtoTwohundredandthirty => 230, - SockProto::ProtoTwohundredandthirtyone => 231, - SockProto::ProtoTwohundredandthirtytwo => 232, - SockProto::ProtoTwohundredandthirtythree => 233, - SockProto::ProtoTwohundredandthirtyfour => 234, - SockProto::ProtoTwohundredandthirtyfive => 235, - SockProto::ProtoTwohundredandthirtysix => 236, - SockProto::ProtoTwohundredandthirtyseven => 237, - SockProto::ProtoTwohundredandthirtyeight => 238, - SockProto::ProtoTwohundredandthirtynine => 239, - SockProto::ProtoTwohundredandfourty => 240, - SockProto::ProtoTwohundredandfourtyone => 241, - SockProto::ProtoTwohundredandfourtytwo => 242, - SockProto::ProtoTwohundredandfourtythree => 243, - SockProto::ProtoTwohundredandfourtyfour => 244, - SockProto::ProtoTwohundredandfourtyfive => 245, - SockProto::ProtoTwohundredandfourtysix => 246, - SockProto::ProtoTwohundredandfourtyseven => 247, - SockProto::ProtoTwohundredandfourtyeight => 248, - SockProto::ProtoTwohundredandfourtynine => 249, - SockProto::ProtoTwohundredandfifty => 250, - SockProto::ProtoTwohundredandfiftyone => 251, - SockProto::ProtoTwohundredandfiftytwo => 252, - SockProto::ProtoTwohundredandfiftythree => 253, - SockProto::ProtoTwohundredandfiftyfour => 254, - SockProto::ProtoRaw => 255, - SockProto::ProtoTwohundredandfiftysix => 256, - SockProto::ProtoTwohundredandfiftyseven => 257, - SockProto::ProtoTwohundredandfiftyeight => 258, - SockProto::ProtoTwohundredandfiftynine => 259, - SockProto::ProtoTwohundredandsixty => 260, - SockProto::ProtoTwohundredandsixtyone => 261, - SockProto::Mptcp => 262, - SockProto::Max => 263, - }) as u16; - let OptionTimestamp { tag: tag53, u: u53 } = option_timestamp; - *((ptr0 + 672) as *mut u8) = (match tag53 { - OptionTag::None => 0, - OptionTag::Some => 1, - }) as u8; - *((ptr0 + 680) as *mut i64) = wit_bindgen_rust::rt::as_i64(u53); - let AddrUnspec { n0: n054 } = addr_unspec; - *((ptr0 + 688) as *mut u8) = (wit_bindgen_rust::rt::as_i32(n054)) as u8; - let AddrUnspecPort { - port: port55, - addr: addr55, - } = addr_unspec_port; - *((ptr0 + 690) as *mut u16) = (wit_bindgen_rust::rt::as_i32(port55)) as u16; - let AddrUnspec { n0: n056 } = addr55; - *((ptr0 + 692) as *mut u8) = (wit_bindgen_rust::rt::as_i32(n056)) as u8; - let CidrUnspec { - addr: addr57, - prefix: prefix57, - } = cidr_unspec; - let AddrUnspec { n0: n058 } = addr57; - *((ptr0 + 694) as *mut u8) = (wit_bindgen_rust::rt::as_i32(n058)) as u8; - *((ptr0 + 695) as *mut u8) = (wit_bindgen_rust::rt::as_i32(prefix57)) as u8; - let HttpHandles { - req: req59, - res: res59, - hdr: hdr59, - } = http_handles; - *((ptr0 + 696) as *mut i32) = wit_bindgen_rust::rt::as_i32(req59); - *((ptr0 + 700) as *mut i32) = wit_bindgen_rust::rt::as_i32(res59); - *((ptr0 + 704) as *mut i32) = wit_bindgen_rust::rt::as_i32(hdr59); - let HttpStatus { - ok: ok60, - redirect: redirect60, - size: size60, - status: status60, - } = http_status; - *((ptr0 + 712) as *mut u8) = (match ok60 { - Bool::False => 0, - Bool::True => 1, - }) as u8; - *((ptr0 + 713) as *mut u8) = (match redirect60 { - Bool::False => 0, - Bool::True => 1, - }) as u8; - *((ptr0 + 720) as *mut i64) = wit_bindgen_rust::rt::as_i64(size60); - *((ptr0 + 728) as *mut u16) = (wit_bindgen_rust::rt::as_i32(status60)) as u16; - *((ptr0 + 736) as *mut u16) = (wit_bindgen_rust::rt::as_i32(ri_flags)) as u16; - *((ptr0 + 738) as *mut u16) = (wit_bindgen_rust::rt::as_i32(ro_flags)) as u16; - *((ptr0 + 740) as *mut u8) = (wit_bindgen_rust::rt::as_i32(sd_flags)) as u8; - *((ptr0 + 742) as *mut u16) = (wit_bindgen_rust::rt::as_i32(si_flags)) as u16; - *((ptr0 + 744) as *mut u8) = (match timeout { - Timeout::Read => 0, - Timeout::Write => 1, - Timeout::Connect => 2, - Timeout::Accept => 3, - }) as u8; - #[link(wasm_import_module = "output")] - extern "C" { - #[cfg_attr(target_arch = "wasm32", link_name = "expose-types-dummy-func")] - #[cfg_attr( - not(target_arch = "wasm32"), - link_name = "output_expose-types-dummy-func" - )] - fn wit_import(_: i32); - } - wit_import(ptr0); - () - } -} - -#[repr(align(8))] -struct RetArea([u8; 752]); -static mut OUTPUT_RET_AREA: RetArea = RetArea([0; 752]); // TODO: if necessary, must be implemented in wit-bindgen unsafe impl ValueType for Snapshot0Clockid { diff --git a/lib/wasi-types-generated/wit-clean/output.wit b/lib/wasi-types-generated/wit-clean/output.wit index a8645feb1d1..33c26abbdbe 100644 --- a/lib/wasi-types-generated/wit-clean/output.wit +++ b/lib/wasi-types-generated/wit-clean/output.wit @@ -2,64 +2,6 @@ // 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 - - -/// Dummy function to expose types into generated code -expose-types-dummy-func: func( - fd: fd, - dirent: dirent, - snapshot0-dirent: snapshot0-dirent, - snapshot0-event: snapshot0-event, - event-enum: event-enum, - event: event, - fdstat: fdstat, - subscription-clock: subscription-clock, - snapshot0-subscription-clock: snapshot0-subscription-clock, - subscription: subscription, - snapshot0-subscription: snapshot0-subscription, - device: device, - linkcount: linkcount, - snapshot0-linkcount: snapshot0-linkcount, - filestat: filestat, - snapshot0-filestat: snapshot0-filestat, - tty: tty, - tid: tid, - pid: pid, - bus-data-format: bus-data-format, - bid: bid, - option-bid: option-bid, - cid: cid, - option-cid: option-cid, - option-fd: option-fd, - bus-handles: bus-handles, - exit-code: exit-code, - bus-event-exit: bus-event-exit, - bus-event-fault: bus-event-fault, - bus-event-close: bus-event-close, - prestat-u-dir: prestat-u-dir, - prestat-u: prestat-u, - event-fd-flags: event-fd-flags, - prestat: prestat, - file-delta: file-delta, - lookup-flags: lookup-flags, - count: count, - %bool: %bool, - pipe-handles: pipe-handles, - stdio-mode: stdio-mode, - sock-proto: sock-proto, - option-timestamp: option-timestamp, - addr-unspec: addr-unspec, - addr-unspec-port: addr-unspec-port, - cidr-unspec: cidr-unspec, - http-handles: http-handles, - http-status: http-status, - ri-flags: ri-flags, - ro-flags: ro-flags, - sd-flags: sd-flags, - si-flags: si-flags, - timeout: timeout, -) - /// Type names used by low-level WASI interfaces. /// An array size. diff --git a/lib/wasi-types-generated/wit-clean/typenames.wit b/lib/wasi-types-generated/wit-clean/typenames.wit index 0385e7c7b72..a4bf2927b39 100644 --- a/lib/wasi-types-generated/wit-clean/typenames.wit +++ b/lib/wasi-types-generated/wit-clean/typenames.wit @@ -2,64 +2,6 @@ // 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 - - -/// Dummy function to expose types into generated code -expose-types-dummy-func: func( - fd: fd, - dirent: dirent, - snapshot0-dirent: snapshot0-dirent, - snapshot0-event: snapshot0-event, - event-enum: event-enum, - event: event, - fdstat: fdstat, - subscription-clock: subscription-clock, - snapshot0-subscription-clock: snapshot0-subscription-clock, - subscription: subscription, - snapshot0-subscription: snapshot0-subscription, - device: device, - linkcount: linkcount, - snapshot0-linkcount: snapshot0-linkcount, - filestat: filestat, - snapshot0-filestat: snapshot0-filestat, - tty: tty, - tid: tid, - pid: pid, - bus-data-format: bus-data-format, - bid: bid, - option-bid: option-bid, - cid: cid, - option-cid: option-cid, - option-fd: option-fd, - bus-handles: bus-handles, - exit-code: exit-code, - bus-event-exit: bus-event-exit, - bus-event-fault: bus-event-fault, - bus-event-close: bus-event-close, - prestat-u-dir: prestat-u-dir, - prestat-u: prestat-u, - event-fd-flags: event-fd-flags, - prestat: prestat, - file-delta: file-delta, - lookup-flags: lookup-flags, - count: count, - %bool: %bool, - pipe-handles: pipe-handles, - stdio-mode: stdio-mode, - sock-proto: sock-proto, - option-timestamp: option-timestamp, - addr-unspec: addr-unspec, - addr-unspec-port: addr-unspec-port, - cidr-unspec: cidr-unspec, - http-handles: http-handles, - http-status: http-status, - ri-flags: ri-flags, - ro-flags: ro-flags, - sd-flags: sd-flags, - si-flags: si-flags, - timeout: timeout, -) - /// Type names used by low-level WASI interfaces. /// An array size. From 17431df647e80f684bdde25c0e75b80e7ed14f80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 12 Sep 2022 15:52:18 +0200 Subject: [PATCH 62/84] Fix "make lint" --- Cargo.lock | 9 ++- Cargo.toml | 1 + lib/wasi-types-generated/Cargo.toml | 10 --- lib/wasi-types-generated/README.md | 5 ++ lib/wasi-types-generated/regenerate.sh | 10 ++- .../wasi-types-generator-extra/.gitignore | 1 + .../wasi-types-generator-extra/Cargo.toml | 15 ++++ .../src/main.rs} | 75 +++++++++---------- 8 files changed, 75 insertions(+), 51 deletions(-) create mode 100644 lib/wasi-types-generated/README.md create mode 100644 lib/wasi-types-generated/wasi-types-generator-extra/.gitignore create mode 100644 lib/wasi-types-generated/wasi-types-generator-extra/Cargo.toml rename lib/wasi-types-generated/{build.rs => wasi-types-generator-extra/src/main.rs} (59%) diff --git a/Cargo.lock b/Cargo.lock index 13a2fb1bedd..6815d546244 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2919,6 +2919,14 @@ dependencies = [ "wast 24.0.0", ] +[[package]] +name = "wasi-types-generator-extra" +version = "0.1.0" +dependencies = [ + "convert_case", + "wit-parser", +] + [[package]] name = "wasm-bindgen" version = "0.2.82" @@ -3459,7 +3467,6 @@ dependencies = [ name = "wasmer-wasi-types-generated" version = "3.0.0-beta" dependencies = [ - "convert_case", "pretty_assertions", "wasmer", "wit-bindgen-gen-core", diff --git a/Cargo.toml b/Cargo.toml index 3cb8f29b56e..548d39299dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,7 @@ members = [ "lib/wasi", "lib/wasi-types", "lib/wasi-types-generated", + "lib/wasi-types-generated/wasi-types-generator-extra", "lib/wasi-experimental-io-devices", "lib/wasi-local-networking", "lib/types", diff --git a/lib/wasi-types-generated/Cargo.toml b/lib/wasi-types-generated/Cargo.toml index ad8c26d0fd4..cef3873b1bc 100644 --- a/lib/wasi-types-generated/Cargo.toml +++ b/lib/wasi-types-generated/Cargo.toml @@ -2,7 +2,6 @@ name = "wasmer-wasi-types-generated" version = "3.0.0-beta" edition = "2018" -build = "build.rs" license = "MIT" description = "Autogenerated wasi types, generated from .wit files" @@ -39,15 +38,6 @@ package = "wit-parser" [dev-dependencies.pretty_assertions] version = "1.3.0" -[build-dependencies.wit-parser] -default-features = false -git = "https://github.com/wasmerio/wit-bindgen" -branch = "force-generate-structs" -package = "wit-parser" - -[build-dependencies] -convert_case = "0.5.0" - [features] js = ["wasmer/js"] sys = ["wasmer/sys"] diff --git a/lib/wasi-types-generated/README.md b/lib/wasi-types-generated/README.md new file mode 100644 index 00000000000..d1050774d82 --- /dev/null +++ b/lib/wasi-types-generated/README.md @@ -0,0 +1,5 @@ +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-generated/regenerate.sh b/lib/wasi-types-generated/regenerate.sh index 1a109c07878..0264c473090 100755 --- a/lib/wasi-types-generated/regenerate.sh +++ b/lib/wasi-types-generated/regenerate.sh @@ -22,4 +22,12 @@ cd .. 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 \ No newline at end of file +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-generated/wasi-types-generator-extra/.gitignore b/lib/wasi-types-generated/wasi-types-generator-extra/.gitignore new file mode 100644 index 00000000000..9f970225adb --- /dev/null +++ b/lib/wasi-types-generated/wasi-types-generator-extra/.gitignore @@ -0,0 +1 @@ +target/ \ No newline at end of file diff --git a/lib/wasi-types-generated/wasi-types-generator-extra/Cargo.toml b/lib/wasi-types-generated/wasi-types-generator-extra/Cargo.toml new file mode 100644 index 00000000000..da32bbeb407 --- /dev/null +++ b/lib/wasi-types-generated/wasi-types-generator-extra/Cargo.toml @@ -0,0 +1,15 @@ +[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 +git = "https://github.com/wasmerio/wit-bindgen" +branch = "force-generate-structs" +package = "wit-parser" diff --git a/lib/wasi-types-generated/build.rs b/lib/wasi-types-generated/wasi-types-generator-extra/src/main.rs similarity index 59% rename from lib/wasi-types-generated/build.rs rename to lib/wasi-types-generated/wasi-types-generator-extra/src/main.rs index 70aab7674f5..d7e1da9a4b5 100644 --- a/lib/wasi-types-generated/build.rs +++ b/lib/wasi-types-generated/wasi-types-generator-extra/src/main.rs @@ -1,11 +1,10 @@ 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"); +const WIT_1: &str = include_str!("../../wit-clean/output.wit"); +const BINDINGS_RS: &str = include_str!("../../src/wasi/bindings.rs"); fn main() { - /* let bindings_rs = BINDINGS_RS .replace("#[allow(clippy::all)]", "") .replace("pub mod output {", "") @@ -16,8 +15,10 @@ fn main() { bindings_rs.pop(); let bindings_rs = bindings_rs.join("\n"); - let target_path = std::env::var("CARGO_MANIFEST_DIR").unwrap(); + let target_path = env!("CARGO_MANIFEST_DIR"); let path = std::path::Path::new(&target_path) + .parent() + .unwrap() .join("src") .join("wasi") .join("extra.rs"); @@ -68,47 +69,43 @@ fn main() { let name = i.name.clone().unwrap_or_default().to_case(Case::Pascal); - match &i.kind { - wit_parser::TypeDefKind::Enum(e) => { - contents.push_str( - &format!( - " - unsafe impl wasmer::FromToNativeWasmType for {name} {{ - type Native = i32; + 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 to_native(self) -> Self::Native {{ + self as i32 + }} - fn from_native(n: Self::Native) -> Self {{ - match n {{\n" - ) - .replace(" ", ""), - ); + 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}\"), - }} + 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(" ", ""), - ); - } - _ => {} + + fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool {{ false }} + }} + " + ) + .replace(" ", ""), + ); } } std::fs::write(path, contents).unwrap(); - */ } From d2edcd74fbcd7e343e9fdc5aaa93cd60b3595755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 12 Sep 2022 17:20:26 +0200 Subject: [PATCH 63/84] Fix "make lint" again --- lib/wasi-types/src/lib.rs | 2 +- lib/wasi/src/syscalls/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/wasi-types/src/lib.rs b/lib/wasi-types/src/lib.rs index cc7d62d70fd..fc5c4d2b768 100644 --- a/lib/wasi-types/src/lib.rs +++ b/lib/wasi-types/src/lib.rs @@ -87,7 +87,7 @@ pub mod file { pub const __WASI_STDOUT_FILENO: Fd = 1; pub const __WASI_STDERR_FILENO: Fd = 2; - pub const EventFdFlags_SEMAPHORE: EventFdFlags = 1; + pub const EVENT_FD_FLAGS_SEMAPHORE: EventFdFlags = 1; pub const __WASI_LOOKUP_SYMLINK_FOLLOW: LookupFlags = 1; diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 158b4c7fc63..668b0ed8c7a 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -1468,7 +1468,7 @@ pub fn fd_event( let kind = Kind::EventNotifications { counter: Arc::new(AtomicU64::new(initial_val)), - is_semaphore: flags & EventFdFlags_SEMAPHORE != 0, + is_semaphore: flags & EVENT_FD_FLAGS_SEMAPHORE != 0, wakers: Default::default(), }; From 8ce1597315ed1b75709853dce17fbbad061679a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 12 Sep 2022 17:33:04 +0200 Subject: [PATCH 64/84] Fix wasi-types-generated unit test --- lib/wasi-types-generated/src/lib.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/wasi-types-generated/src/lib.rs b/lib/wasi-types-generated/src/lib.rs index 09b7911ab22..7528f99b65f 100644 --- a/lib/wasi-types-generated/src/lib.rs +++ b/lib/wasi-types-generated/src/lib.rs @@ -27,5 +27,16 @@ fn fail_if_wit_files_arent_up_to_date() { .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 } From 4e96969df4d72c8daadae5851074580a2ac82257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 12 Sep 2022 17:38:11 +0200 Subject: [PATCH 65/84] Remove wasi_snapshot0 in favor of wasi --- lib/wasi/src/syscalls/wasi.rs | 6 ++--- lib/wasi/src/syscalls/windows.rs | 44 +++++++++++++++----------------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/lib/wasi/src/syscalls/wasi.rs b/lib/wasi/src/syscalls/wasi.rs index 9e8c5d4ba02..6eeaf47886f 100644 --- a/lib/wasi/src/syscalls/wasi.rs +++ b/lib/wasi/src/syscalls/wasi.rs @@ -2,7 +2,7 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; use wasmer::{Memory, Memory32, MemorySize, StoreMut, WasmPtr, WasmSlice}; use wasmer_wasi_types::{ - wasi::{Errno, Event, Fd as WasiFd, Filesize, Fstflags, Fstflags, Timestamp, Whence}, + wasi::{Errno, Event, Fd as WasiFd, Filesize, Fstflags, Fstflags, Timestamp, Whence, Clockid}, *, }; @@ -27,7 +27,7 @@ pub(crate) fn args_sizes_get( pub(crate) fn clock_res_get( ctx: FunctionEnvMut, - clock_id: wasi_snapshot0::Clockid, + clock_id: Clockid, resolution: WasmPtr, ) -> Errno { super::clock_res_get::(ctx, clock_id, resolution) @@ -35,7 +35,7 @@ pub(crate) fn clock_res_get( pub(crate) fn clock_time_get( ctx: FunctionEnvMut, - clock_id: wasi_snapshot0::Clockid, + clock_id: Clockid, precision: Timestamp, time: WasmPtr, ) -> Errno { diff --git a/lib/wasi/src/syscalls/windows.rs b/lib/wasi/src/syscalls/windows.rs index 35ae6f8f691..cb1348075b5 100644 --- a/lib/wasi/src/syscalls/windows.rs +++ b/lib/wasi/src/syscalls/windows.rs @@ -1,57 +1,53 @@ -use crate::syscalls::types::{wasi::Timestamp, *}; +use crate::syscalls::types::wasi::{self, Timestamp}; use tracing::debug; use wasmer::WasmRef; pub fn platform_clock_res_get( - clock_id: wasi_snapshot0::Clockid, + clock_id: wasi::Clockid, resolution: WasmRef, -) -> Result { +) -> 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_snapshot0::Clockid::Monotonic => 10_000_000, + wasi::Clockid::Monotonic => 10_000_000, // TODO: verify or compute this - wasi_snapshot0::Clockid::Realtime => 1, - wasi_snapshot0::Clockid::ProcessCputimeId => { - return Err(wasi_snapshot0::Errno::Inval); + wasi::Clockid::Realtime => 1, + wasi::Clockid::ProcessCputimeId => { + return Err(wasi::Errno::Inval); } - wasi_snapshot0::Clockid::ThreadCputimeId => { - return Err(wasi_snapshot0::Errno::Inval); + wasi::Clockid::ThreadCputimeId => { + return Err(wasi::Errno::Inval); } - _ => return Err(wasi_snapshot0::Errno::Inval), + _ => return Err(wasi::Errno::Inval), }; Ok(resolution_val) } pub fn platform_clock_time_get( - clock_id: wasi_snapshot0::Clockid, + clock_id: wasi::Clockid, precision: Timestamp, -) -> Result { +) -> Result { let nanos = match clock_id { - wasi_snapshot0::Clockid::MONOTONIC => { + wasi::Clockid::MONOTONIC => { let tick_ms = unsafe { winapi::um::sysinfoapi::GetTickCount64() }; tick_ms * 1_000_000 } - wasi_snapshot0::Clockid::REALTIME => { + wasi::Clockid::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_snapshot0::Errno::Io + wasi::Errno::Io })?; duration.as_nanos() as u64 } - wasi_snapshot0::Clockid::ProcessCputimeId => { - unimplemented!( - "wasi::platform_clock_time_get(wasi_snapshot0::Clockid::ProcessCputimeId, ..)" - ) + wasi::Clockid::ProcessCputimeId => { + unimplemented!("wasi::platform_clock_time_get(wasi::Clockid::ProcessCputimeId, ..)") } - wasi_snapshot0::Clockid::ThreadCputimeId => { - unimplemented!( - "wasi::platform_clock_time_get(wasi_snapshot0::Clockid::ThreadCputimeId, ..)" - ) + wasi::Clockid::ThreadCputimeId => { + unimplemented!("wasi::platform_clock_time_get(wasi::Clockid::ThreadCputimeId, ..)") } - _ => return Err(wasi_snapshot0::Errno::Inval), + _ => return Err(wasi::Errno::Inval), }; Ok(nanos as i64) } From b164ea1939c1340fb09def8a96131e9b5164a678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 12 Sep 2022 17:44:14 +0200 Subject: [PATCH 66/84] Remove unused imports --- lib/wasi-types/src/lib.rs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/lib/wasi-types/src/lib.rs b/lib/wasi-types/src/lib.rs index fc5c4d2b768..8dd0766e3a5 100644 --- a/lib/wasi-types/src/lib.rs +++ b/lib/wasi-types/src/lib.rs @@ -73,13 +73,7 @@ pub mod bus { } pub mod file { - use std::{ - fmt, - mem::{self, MaybeUninit}, - }; - use wasmer_derive::ValueType; - use wasmer_types::ValueType; - use wasmer_wasi_types_generated::wasi::{Fd, Preopentype, Prestat, Rights}; + use wasmer_wasi_types_generated::wasi::{Fd, Rights}; pub use wasmer_wasi_types_generated::wasi::{EventFdFlags, FileDelta, LookupFlags, Oflags}; @@ -182,7 +176,6 @@ pub mod directory { pub mod io { use wasmer_derive::ValueType; use wasmer_types::MemorySize; - use wasmer_wasi_types_generated::wasi::Fd; pub use wasmer_wasi_types_generated::wasi::Bool; pub use wasmer_wasi_types_generated::wasi::Count; @@ -205,15 +198,12 @@ pub mod io { } pub mod time { - use wasmer_derive::ValueType; pub use wasmer_wasi_types_generated::wasi::OptionTimestamp; - use wasmer_wasi_types_generated::wasi::{OptionTag, Timestamp}; } pub mod net { - use super::*; use wasmer_derive::ValueType; - use wasmer_wasi_types_generated::wasi::{Addressfamily, Fd, Filesize}; + use wasmer_wasi_types_generated::wasi::Addressfamily; use crate::OptionTimestamp; From bdd5395be5131ef396e824a89e46fb60465eef24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 12 Sep 2022 17:51:17 +0200 Subject: [PATCH 67/84] Fix "make lint" again --- lib/wasi/src/syscalls/legacy/snapshot0.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wasi/src/syscalls/legacy/snapshot0.rs b/lib/wasi/src/syscalls/legacy/snapshot0.rs index 0ad76d39d1d..e18d8a1e0ee 100644 --- a/lib/wasi/src/syscalls/legacy/snapshot0.rs +++ b/lib/wasi/src/syscalls/legacy/snapshot0.rs @@ -60,7 +60,7 @@ pub fn fd_filestat_get( // into memory leaving it as it should be wasi_try_mem!(buf.deref(&memory).write(old_stat)); - Errno::from(result) + result } /// Wrapper around `syscalls::path_filestat_get` with extra logic to handle the size From b98b691a44176265f86550f15a9fae7075182fa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 12 Sep 2022 18:24:42 +0200 Subject: [PATCH 68/84] Fix compilation issues on Windows --- lib/wasi/src/syscalls/windows.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/wasi/src/syscalls/windows.rs b/lib/wasi/src/syscalls/windows.rs index cb1348075b5..656c70a4242 100644 --- a/lib/wasi/src/syscalls/windows.rs +++ b/lib/wasi/src/syscalls/windows.rs @@ -3,19 +3,19 @@ use tracing::debug; use wasmer::WasmRef; pub fn platform_clock_res_get( - clock_id: wasi::Clockid, + 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::Clockid::Monotonic => 10_000_000, + wasi::Snapshot0Clockid::Monotonic => 10_000_000, // TODO: verify or compute this - wasi::Clockid::Realtime => 1, - wasi::Clockid::ProcessCputimeId => { + wasi::Snapshot0Clockid::Realtime => 1, + wasi::Snapshot0Clockid::ProcessCputimeId => { return Err(wasi::Errno::Inval); } - wasi::Clockid::ThreadCputimeId => { + wasi::Snapshot0Clockid::ThreadCputimeId => { return Err(wasi::Errno::Inval); } _ => return Err(wasi::Errno::Inval), @@ -24,15 +24,15 @@ pub fn platform_clock_res_get( } pub fn platform_clock_time_get( - clock_id: wasi::Clockid, + clock_id: wasi::Snapshot0Clockid, precision: Timestamp, ) -> Result { let nanos = match clock_id { - wasi::Clockid::MONOTONIC => { + wasi::Snapshot0Clockid::Monotonic => { let tick_ms = unsafe { winapi::um::sysinfoapi::GetTickCount64() }; tick_ms * 1_000_000 } - wasi::Clockid::REALTIME => { + wasi::Snapshot0Clockid::Realtime => { let duration = std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) .map_err(|e| { @@ -41,10 +41,10 @@ pub fn platform_clock_time_get( })?; duration.as_nanos() as u64 } - wasi::Clockid::ProcessCputimeId => { + wasi::Snapshot0Clockid::ProcessCputimeId => { unimplemented!("wasi::platform_clock_time_get(wasi::Clockid::ProcessCputimeId, ..)") } - wasi::Clockid::ThreadCputimeId => { + wasi::Snapshot0Clockid::ThreadCputimeId => { unimplemented!("wasi::platform_clock_time_get(wasi::Clockid::ThreadCputimeId, ..)") } _ => return Err(wasi::Errno::Inval), From 063c1e751f58e7e491c58f33c6674ce2628dd661 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 14 Sep 2022 15:51:21 +0200 Subject: [PATCH 69/84] Update wit-bindgen --- Cargo.lock | 2 +- lib/wasi-types-generated/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6815d546244..2eb12c32402 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3835,7 +3835,7 @@ dependencies = [ [[package]] name = "wit-bindgen-rust" version = "0.1.0" -source = "git+https://github.com/wasmerio/wit-bindgen?branch=main#005a9e6d5befe4652c0e6e05578b245ab96b3cea" +source = "git+https://github.com/wasmerio/wit-bindgen?branch=force-generate-structs#24f9626a575df6416c35047147a67bc9d9b78afc" dependencies = [ "bitflags", ] diff --git a/lib/wasi-types-generated/Cargo.toml b/lib/wasi-types-generated/Cargo.toml index cef3873b1bc..8b71818c829 100644 --- a/lib/wasi-types-generated/Cargo.toml +++ b/lib/wasi-types-generated/Cargo.toml @@ -14,7 +14,7 @@ wasmer = { default-features = false, path = "../api", version = "3.0.0-beta" } [dependencies.wit-bindgen-rust] default-features = false git = "https://github.com/wasmerio/wit-bindgen" -branch = "main" +branch = "force-generate-structs" package = "wit-bindgen-rust" [dev-dependencies.wit-bindgen-gen-rust-wasm] From d9752a902237c5fec9e9998cbf1200e953d8547d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 13:38:29 +0200 Subject: [PATCH 70/84] Update wit-bindgen again (with rev instead of branch) --- Cargo.lock | 32 ++++++++++++++++++++--------- lib/wasi-types-generated/Cargo.toml | 6 +++--- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2eb12c32402..c9ff1c14cf6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2841,9 +2841,9 @@ dependencies = [ [[package]] name = "unicode-segmentation" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" +checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a" [[package]] name = "unicode-width" @@ -2924,7 +2924,7 @@ name = "wasi-types-generator-extra" version = "0.1.0" dependencies = [ "convert_case", - "wit-parser", + "wit-parser 0.1.0 (git+https://github.com/wasmerio/wit-bindgen?branch=force-generate-structs)", ] [[package]] @@ -3472,7 +3472,7 @@ dependencies = [ "wit-bindgen-gen-core", "wit-bindgen-gen-rust-wasm", "wit-bindgen-rust", - "wit-parser", + "wit-parser 0.1.0 (git+https://github.com/wasmerio/wit-bindgen?branch=force-generate-structs)", ] [[package]] @@ -3807,16 +3807,16 @@ checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" [[package]] name = "wit-bindgen-gen-core" version = "0.1.0" -source = "git+https://github.com/wasmerio/wit-bindgen?branch=force-generate-structs#095d295be6392259924e48488af188d3ed3e4102" +source = "git+https://github.com/wasmerio/wit-bindgen?rev=24f9626a575df6416c35047147a67bc9d9b78afc#24f9626a575df6416c35047147a67bc9d9b78afc" dependencies = [ "anyhow", - "wit-parser", + "wit-parser 0.1.0 (git+https://github.com/wasmerio/wit-bindgen?rev=24f9626a575df6416c35047147a67bc9d9b78afc)", ] [[package]] name = "wit-bindgen-gen-rust" version = "0.1.0" -source = "git+https://github.com/wasmerio/wit-bindgen?branch=force-generate-structs#095d295be6392259924e48488af188d3ed3e4102" +source = "git+https://github.com/wasmerio/wit-bindgen?rev=24f9626a575df6416c35047147a67bc9d9b78afc#24f9626a575df6416c35047147a67bc9d9b78afc" dependencies = [ "heck 0.3.3", "wit-bindgen-gen-core", @@ -3825,7 +3825,7 @@ dependencies = [ [[package]] name = "wit-bindgen-gen-rust-wasm" version = "0.1.0" -source = "git+https://github.com/wasmerio/wit-bindgen?branch=force-generate-structs#095d295be6392259924e48488af188d3ed3e4102" +source = "git+https://github.com/wasmerio/wit-bindgen?rev=24f9626a575df6416c35047147a67bc9d9b78afc#24f9626a575df6416c35047147a67bc9d9b78afc" dependencies = [ "heck 0.3.3", "wit-bindgen-gen-core", @@ -3835,7 +3835,7 @@ dependencies = [ [[package]] name = "wit-bindgen-rust" version = "0.1.0" -source = "git+https://github.com/wasmerio/wit-bindgen?branch=force-generate-structs#24f9626a575df6416c35047147a67bc9d9b78afc" +source = "git+https://github.com/wasmerio/wit-bindgen?rev=24f9626a575df6416c35047147a67bc9d9b78afc#24f9626a575df6416c35047147a67bc9d9b78afc" dependencies = [ "bitflags", ] @@ -3843,7 +3843,19 @@ dependencies = [ [[package]] name = "wit-parser" version = "0.1.0" -source = "git+https://github.com/wasmerio/wit-bindgen?branch=force-generate-structs#095d295be6392259924e48488af188d3ed3e4102" +source = "git+https://github.com/wasmerio/wit-bindgen?branch=force-generate-structs#24f9626a575df6416c35047147a67bc9d9b78afc" +dependencies = [ + "anyhow", + "id-arena", + "pulldown-cmark", + "unicode-normalization", + "unicode-xid", +] + +[[package]] +name = "wit-parser" +version = "0.1.0" +source = "git+https://github.com/wasmerio/wit-bindgen?rev=24f9626a575df6416c35047147a67bc9d9b78afc#24f9626a575df6416c35047147a67bc9d9b78afc" dependencies = [ "anyhow", "id-arena", diff --git a/lib/wasi-types-generated/Cargo.toml b/lib/wasi-types-generated/Cargo.toml index 8b71818c829..80a15afa028 100644 --- a/lib/wasi-types-generated/Cargo.toml +++ b/lib/wasi-types-generated/Cargo.toml @@ -14,19 +14,19 @@ wasmer = { default-features = false, path = "../api", version = "3.0.0-beta" } [dependencies.wit-bindgen-rust] default-features = false git = "https://github.com/wasmerio/wit-bindgen" -branch = "force-generate-structs" +rev = "24f9626a575df6416c35047147a67bc9d9b78afc" package = "wit-bindgen-rust" [dev-dependencies.wit-bindgen-gen-rust-wasm] default-features = false git = "https://github.com/wasmerio/wit-bindgen" -branch = "force-generate-structs" +rev = "24f9626a575df6416c35047147a67bc9d9b78afc" package = "wit-bindgen-gen-rust-wasm" [dev-dependencies.wit-bindgen-core] default-features = false git = "https://github.com/wasmerio/wit-bindgen" -branch = "force-generate-structs" +rev = "24f9626a575df6416c35047147a67bc9d9b78afc" package = "wit-bindgen-gen-core" [dev-dependencies.wit-parser] From a4e1d065c3cb2cce833393a1333487e1d73bdecf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 14:35:01 +0200 Subject: [PATCH 71/84] Update wit-bindgen Now all wit-bindgen libraries are MIT licensed so that cargo deny doesn't complain about invalid licensing --- Cargo.lock | 12 ++++++------ lib/wasi-types-generated/Cargo.toml | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c9ff1c14cf6..243cc9aed3d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3807,16 +3807,16 @@ checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" [[package]] name = "wit-bindgen-gen-core" version = "0.1.0" -source = "git+https://github.com/wasmerio/wit-bindgen?rev=24f9626a575df6416c35047147a67bc9d9b78afc#24f9626a575df6416c35047147a67bc9d9b78afc" +source = "git+https://github.com/wasmerio/wit-bindgen?rev=7fc6c57af548310c21b97d6c5d9dbb648a674f58#7fc6c57af548310c21b97d6c5d9dbb648a674f58" dependencies = [ "anyhow", - "wit-parser 0.1.0 (git+https://github.com/wasmerio/wit-bindgen?rev=24f9626a575df6416c35047147a67bc9d9b78afc)", + "wit-parser 0.1.0 (git+https://github.com/wasmerio/wit-bindgen?rev=7fc6c57af548310c21b97d6c5d9dbb648a674f58)", ] [[package]] name = "wit-bindgen-gen-rust" version = "0.1.0" -source = "git+https://github.com/wasmerio/wit-bindgen?rev=24f9626a575df6416c35047147a67bc9d9b78afc#24f9626a575df6416c35047147a67bc9d9b78afc" +source = "git+https://github.com/wasmerio/wit-bindgen?rev=7fc6c57af548310c21b97d6c5d9dbb648a674f58#7fc6c57af548310c21b97d6c5d9dbb648a674f58" dependencies = [ "heck 0.3.3", "wit-bindgen-gen-core", @@ -3825,7 +3825,7 @@ dependencies = [ [[package]] name = "wit-bindgen-gen-rust-wasm" version = "0.1.0" -source = "git+https://github.com/wasmerio/wit-bindgen?rev=24f9626a575df6416c35047147a67bc9d9b78afc#24f9626a575df6416c35047147a67bc9d9b78afc" +source = "git+https://github.com/wasmerio/wit-bindgen?rev=7fc6c57af548310c21b97d6c5d9dbb648a674f58#7fc6c57af548310c21b97d6c5d9dbb648a674f58" dependencies = [ "heck 0.3.3", "wit-bindgen-gen-core", @@ -3835,7 +3835,7 @@ dependencies = [ [[package]] name = "wit-bindgen-rust" version = "0.1.0" -source = "git+https://github.com/wasmerio/wit-bindgen?rev=24f9626a575df6416c35047147a67bc9d9b78afc#24f9626a575df6416c35047147a67bc9d9b78afc" +source = "git+https://github.com/wasmerio/wit-bindgen?rev=7fc6c57af548310c21b97d6c5d9dbb648a674f58#7fc6c57af548310c21b97d6c5d9dbb648a674f58" dependencies = [ "bitflags", ] @@ -3855,7 +3855,7 @@ dependencies = [ [[package]] name = "wit-parser" version = "0.1.0" -source = "git+https://github.com/wasmerio/wit-bindgen?rev=24f9626a575df6416c35047147a67bc9d9b78afc#24f9626a575df6416c35047147a67bc9d9b78afc" +source = "git+https://github.com/wasmerio/wit-bindgen?rev=7fc6c57af548310c21b97d6c5d9dbb648a674f58#7fc6c57af548310c21b97d6c5d9dbb648a674f58" dependencies = [ "anyhow", "id-arena", diff --git a/lib/wasi-types-generated/Cargo.toml b/lib/wasi-types-generated/Cargo.toml index 80a15afa028..b6cacd09deb 100644 --- a/lib/wasi-types-generated/Cargo.toml +++ b/lib/wasi-types-generated/Cargo.toml @@ -14,19 +14,19 @@ wasmer = { default-features = false, path = "../api", version = "3.0.0-beta" } [dependencies.wit-bindgen-rust] default-features = false git = "https://github.com/wasmerio/wit-bindgen" -rev = "24f9626a575df6416c35047147a67bc9d9b78afc" +rev = "7fc6c57af548310c21b97d6c5d9dbb648a674f58" package = "wit-bindgen-rust" [dev-dependencies.wit-bindgen-gen-rust-wasm] default-features = false git = "https://github.com/wasmerio/wit-bindgen" -rev = "24f9626a575df6416c35047147a67bc9d9b78afc" +rev = "7fc6c57af548310c21b97d6c5d9dbb648a674f58" package = "wit-bindgen-gen-rust-wasm" [dev-dependencies.wit-bindgen-core] default-features = false git = "https://github.com/wasmerio/wit-bindgen" -rev = "24f9626a575df6416c35047147a67bc9d9b78afc" +rev = "7fc6c57af548310c21b97d6c5d9dbb648a674f58" package = "wit-bindgen-gen-core" [dev-dependencies.wit-parser] From 132e7353ef775cee6b582971349ff181a1ce1e65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 15:47:45 +0200 Subject: [PATCH 72/84] Fix dependency issue with wit-bindgen --- Cargo.lock | 18 +++--------------- lib/wasi-types-generated/Cargo.toml | 2 +- .../wasi-types-generator-extra/Cargo.toml | 2 +- 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 243cc9aed3d..13e8cee0ea1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2924,7 +2924,7 @@ name = "wasi-types-generator-extra" version = "0.1.0" dependencies = [ "convert_case", - "wit-parser 0.1.0 (git+https://github.com/wasmerio/wit-bindgen?branch=force-generate-structs)", + "wit-parser", ] [[package]] @@ -3472,7 +3472,7 @@ dependencies = [ "wit-bindgen-gen-core", "wit-bindgen-gen-rust-wasm", "wit-bindgen-rust", - "wit-parser 0.1.0 (git+https://github.com/wasmerio/wit-bindgen?branch=force-generate-structs)", + "wit-parser", ] [[package]] @@ -3810,7 +3810,7 @@ version = "0.1.0" source = "git+https://github.com/wasmerio/wit-bindgen?rev=7fc6c57af548310c21b97d6c5d9dbb648a674f58#7fc6c57af548310c21b97d6c5d9dbb648a674f58" dependencies = [ "anyhow", - "wit-parser 0.1.0 (git+https://github.com/wasmerio/wit-bindgen?rev=7fc6c57af548310c21b97d6c5d9dbb648a674f58)", + "wit-parser", ] [[package]] @@ -3840,18 +3840,6 @@ dependencies = [ "bitflags", ] -[[package]] -name = "wit-parser" -version = "0.1.0" -source = "git+https://github.com/wasmerio/wit-bindgen?branch=force-generate-structs#24f9626a575df6416c35047147a67bc9d9b78afc" -dependencies = [ - "anyhow", - "id-arena", - "pulldown-cmark", - "unicode-normalization", - "unicode-xid", -] - [[package]] name = "wit-parser" version = "0.1.0" diff --git a/lib/wasi-types-generated/Cargo.toml b/lib/wasi-types-generated/Cargo.toml index b6cacd09deb..9444685f898 100644 --- a/lib/wasi-types-generated/Cargo.toml +++ b/lib/wasi-types-generated/Cargo.toml @@ -32,7 +32,7 @@ package = "wit-bindgen-gen-core" [dev-dependencies.wit-parser] default-features = false git = "https://github.com/wasmerio/wit-bindgen" -branch = "force-generate-structs" +rev = "7fc6c57af548310c21b97d6c5d9dbb648a674f58" package = "wit-parser" [dev-dependencies.pretty_assertions] diff --git a/lib/wasi-types-generated/wasi-types-generator-extra/Cargo.toml b/lib/wasi-types-generated/wasi-types-generator-extra/Cargo.toml index da32bbeb407..3fc1a3bc78f 100644 --- a/lib/wasi-types-generated/wasi-types-generator-extra/Cargo.toml +++ b/lib/wasi-types-generated/wasi-types-generator-extra/Cargo.toml @@ -11,5 +11,5 @@ convert_case = "0.5.0" [dependencies.wit-parser] default-features = false git = "https://github.com/wasmerio/wit-bindgen" -branch = "force-generate-structs" +rev = "7fc6c57af548310c21b97d6c5d9dbb648a674f58" package = "wit-parser" From 7e3ca7098ff1f565cb69d1660a21b9a1cb194a4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 18:43:13 +0200 Subject: [PATCH 73/84] Use wit-bindgen dependency from crates.io --- Cargo.lock | 136 +++++++++++------- lib/wasi-types-generated/Cargo.toml | 29 +--- .../wasi-types-generator-extra/Cargo.toml | 5 +- 3 files changed, 89 insertions(+), 81 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 13e8cee0ea1..1ba4a6f051e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -87,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" @@ -2924,7 +2935,7 @@ name = "wasi-types-generator-extra" version = "0.1.0" dependencies = [ "convert_case", - "wit-parser", + "wasmer-wit-parser", ] [[package]] @@ -3469,10 +3480,10 @@ version = "3.0.0-beta" dependencies = [ "pretty_assertions", "wasmer", - "wit-bindgen-gen-core", - "wit-bindgen-gen-rust-wasm", - "wit-bindgen-rust", - "wit-parser", + "wasmer-wit-bindgen-gen-core", + "wasmer-wit-bindgen-gen-rust-wasm", + "wasmer-wit-bindgen-rust", + "wasmer-wit-parser", ] [[package]] @@ -3489,6 +3500,73 @@ dependencies = [ "wast 38.0.1", ] +[[package]] +name = "wasmer-wit-bindgen-gen-core" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4ec8184a86c6617db132eb50cfc20c4c80bfbd0b202d6ec0b7a72dab048c80" +dependencies = [ + "anyhow", + "wasmer-wit-parser", +] + +[[package]] +name = "wasmer-wit-bindgen-gen-rust" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63adda6387873b03418918a991a12ffcfbd4001e56189fede57a29b57d6323ee" +dependencies = [ + "heck 0.3.3", + "wasmer-wit-bindgen-gen-core", +] + +[[package]] +name = "wasmer-wit-bindgen-gen-rust-wasm" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea1c4fe28c7c0e405c137a646ec27aa089ee26292d314710e05fd32aa5cd07b" +dependencies = [ + "heck 0.3.3", + "wasmer-wit-bindgen-gen-core", + "wasmer-wit-bindgen-gen-rust", +] + +[[package]] +name = "wasmer-wit-bindgen-rust" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37a3c6469325eda1d7f9dfe0c36f53d4dc9b33844666f0177f15c56282371407" +dependencies = [ + "async-trait", + "bitflags", + "wasmer-wit-bindgen-rust-impl", +] + +[[package]] +name = "wasmer-wit-bindgen-rust-impl" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d0cb0e77c96a85622cf03cb6cd05501ca4fa4643349fadd96f98aee938a8c6" +dependencies = [ + "proc-macro2", + "syn", + "wasmer-wit-bindgen-gen-core", + "wasmer-wit-bindgen-gen-rust-wasm", +] + +[[package]] +name = "wasmer-wit-parser" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5783fc22d78862b20aec7c87c52eb1dbc7a238706d1207eaa94050af6a5393" +dependencies = [ + "anyhow", + "id-arena", + "pulldown-cmark", + "unicode-normalization", + "unicode-xid", +] + [[package]] name = "wasmer-workspace" version = "3.0.0-beta" @@ -3804,54 +3882,6 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" -[[package]] -name = "wit-bindgen-gen-core" -version = "0.1.0" -source = "git+https://github.com/wasmerio/wit-bindgen?rev=7fc6c57af548310c21b97d6c5d9dbb648a674f58#7fc6c57af548310c21b97d6c5d9dbb648a674f58" -dependencies = [ - "anyhow", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-gen-rust" -version = "0.1.0" -source = "git+https://github.com/wasmerio/wit-bindgen?rev=7fc6c57af548310c21b97d6c5d9dbb648a674f58#7fc6c57af548310c21b97d6c5d9dbb648a674f58" -dependencies = [ - "heck 0.3.3", - "wit-bindgen-gen-core", -] - -[[package]] -name = "wit-bindgen-gen-rust-wasm" -version = "0.1.0" -source = "git+https://github.com/wasmerio/wit-bindgen?rev=7fc6c57af548310c21b97d6c5d9dbb648a674f58#7fc6c57af548310c21b97d6c5d9dbb648a674f58" -dependencies = [ - "heck 0.3.3", - "wit-bindgen-gen-core", - "wit-bindgen-gen-rust", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.1.0" -source = "git+https://github.com/wasmerio/wit-bindgen?rev=7fc6c57af548310c21b97d6c5d9dbb648a674f58#7fc6c57af548310c21b97d6c5d9dbb648a674f58" -dependencies = [ - "bitflags", -] - -[[package]] -name = "wit-parser" -version = "0.1.0" -source = "git+https://github.com/wasmerio/wit-bindgen?rev=7fc6c57af548310c21b97d6c5d9dbb648a674f58#7fc6c57af548310c21b97d6c5d9dbb648a674f58" -dependencies = [ - "anyhow", - "id-arena", - "pulldown-cmark", - "unicode-normalization", - "unicode-xid", -] - [[package]] name = "x11-dl" version = "2.20.0" diff --git a/lib/wasi-types-generated/Cargo.toml b/lib/wasi-types-generated/Cargo.toml index 9444685f898..7719d2b3405 100644 --- a/lib/wasi-types-generated/Cargo.toml +++ b/lib/wasi-types-generated/Cargo.toml @@ -9,31 +9,10 @@ description = "Autogenerated wasi types, generated from .wit files" [dependencies] wasmer = { default-features = false, path = "../api", version = "3.0.0-beta" } - -# this crate is called "gen-rust" on bytecodealliance/master -[dependencies.wit-bindgen-rust] -default-features = false -git = "https://github.com/wasmerio/wit-bindgen" -rev = "7fc6c57af548310c21b97d6c5d9dbb648a674f58" -package = "wit-bindgen-rust" - -[dev-dependencies.wit-bindgen-gen-rust-wasm] -default-features = false -git = "https://github.com/wasmerio/wit-bindgen" -rev = "7fc6c57af548310c21b97d6c5d9dbb648a674f58" -package = "wit-bindgen-gen-rust-wasm" - -[dev-dependencies.wit-bindgen-core] -default-features = false -git = "https://github.com/wasmerio/wit-bindgen" -rev = "7fc6c57af548310c21b97d6c5d9dbb648a674f58" -package = "wit-bindgen-gen-core" - -[dev-dependencies.wit-parser] -default-features = false -git = "https://github.com/wasmerio/wit-bindgen" -rev = "7fc6c57af548310c21b97d6c5d9dbb648a674f58" -package = "wit-parser" +wit-bindgen-rust = { package = "wasmer-wit-bindgen-rust", version = "0.1.0" } +wit-bindgen-rust-wasm = { package = "wasmer-wit-bindgen-gen-rust-wasm", version = "0.1.0" } +wit-bindgen-core = { package = "wasmer-wit-bindgen-gen-core", version = "0.1.0" } +wit-parser = { package = "wasmer-wit-parser", version = "0.1.0" } [dev-dependencies.pretty_assertions] version = "1.3.0" diff --git a/lib/wasi-types-generated/wasi-types-generator-extra/Cargo.toml b/lib/wasi-types-generated/wasi-types-generator-extra/Cargo.toml index 3fc1a3bc78f..252a39507c8 100644 --- a/lib/wasi-types-generated/wasi-types-generator-extra/Cargo.toml +++ b/lib/wasi-types-generated/wasi-types-generator-extra/Cargo.toml @@ -10,6 +10,5 @@ convert_case = "0.5.0" [dependencies.wit-parser] default-features = false -git = "https://github.com/wasmerio/wit-bindgen" -rev = "7fc6c57af548310c21b97d6c5d9dbb648a674f58" -package = "wit-parser" +package = "wasmer-wit-parser" +version = "0.1.0" \ No newline at end of file From 73434490871b178291e1b06fc5d37bc835049ab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 19:11:21 +0200 Subject: [PATCH 74/84] Update wit-bindgen version --- Cargo.lock | 20 +++++++++---------- lib/wasi-types-generated/Cargo.toml | 8 ++++---- .../wasi-types-generator-extra/Cargo.toml | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1ba4a6f051e..7f72decebcc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3502,9 +3502,9 @@ dependencies = [ [[package]] name = "wasmer-wit-bindgen-gen-core" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4ec8184a86c6617db132eb50cfc20c4c80bfbd0b202d6ec0b7a72dab048c80" +checksum = "ff8aa5be5ae5d61f5e151dc2c0e603093fe28395d2083b65ef7a3547844054fe" dependencies = [ "anyhow", "wasmer-wit-parser", @@ -3522,9 +3522,9 @@ dependencies = [ [[package]] name = "wasmer-wit-bindgen-gen-rust-wasm" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea1c4fe28c7c0e405c137a646ec27aa089ee26292d314710e05fd32aa5cd07b" +checksum = "505f5168cfee591840e13e158a5c5e2f95d6df1df710839021564f36bee7bafc" dependencies = [ "heck 0.3.3", "wasmer-wit-bindgen-gen-core", @@ -3533,9 +3533,9 @@ dependencies = [ [[package]] name = "wasmer-wit-bindgen-rust" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37a3c6469325eda1d7f9dfe0c36f53d4dc9b33844666f0177f15c56282371407" +checksum = "968747f1271f74aab9b70d9c5d4921db9bd13b4ec3ba5506506e6e7dc58c918c" dependencies = [ "async-trait", "bitflags", @@ -3544,9 +3544,9 @@ dependencies = [ [[package]] name = "wasmer-wit-bindgen-rust-impl" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d0cb0e77c96a85622cf03cb6cd05501ca4fa4643349fadd96f98aee938a8c6" +checksum = "bd26fe00d08bd2119870b017d13413dfbd51e7750b6634d649fc7a7bbc057b85" dependencies = [ "proc-macro2", "syn", @@ -3556,9 +3556,9 @@ dependencies = [ [[package]] name = "wasmer-wit-parser" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5783fc22d78862b20aec7c87c52eb1dbc7a238706d1207eaa94050af6a5393" +checksum = "f46c9a15086be8a2eb3790613902b9d3a9a687833b17cd021de263a20378585a" dependencies = [ "anyhow", "id-arena", diff --git a/lib/wasi-types-generated/Cargo.toml b/lib/wasi-types-generated/Cargo.toml index 7719d2b3405..21ad9bab8d3 100644 --- a/lib/wasi-types-generated/Cargo.toml +++ b/lib/wasi-types-generated/Cargo.toml @@ -9,10 +9,10 @@ description = "Autogenerated wasi types, generated from .wit files" [dependencies] wasmer = { default-features = false, path = "../api", version = "3.0.0-beta" } -wit-bindgen-rust = { package = "wasmer-wit-bindgen-rust", version = "0.1.0" } -wit-bindgen-rust-wasm = { package = "wasmer-wit-bindgen-gen-rust-wasm", version = "0.1.0" } -wit-bindgen-core = { package = "wasmer-wit-bindgen-gen-core", version = "0.1.0" } -wit-parser = { package = "wasmer-wit-parser", version = "0.1.0" } +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" } [dev-dependencies.pretty_assertions] version = "1.3.0" diff --git a/lib/wasi-types-generated/wasi-types-generator-extra/Cargo.toml b/lib/wasi-types-generated/wasi-types-generator-extra/Cargo.toml index 252a39507c8..fab10cc5c33 100644 --- a/lib/wasi-types-generated/wasi-types-generator-extra/Cargo.toml +++ b/lib/wasi-types-generated/wasi-types-generator-extra/Cargo.toml @@ -11,4 +11,4 @@ convert_case = "0.5.0" [dependencies.wit-parser] default-features = false package = "wasmer-wit-parser" -version = "0.1.0" \ No newline at end of file +version = "0.1.1" \ No newline at end of file From 9f9a0cd8872a050f2ef0ea0c9fb97dc4b9368619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 19:18:56 +0200 Subject: [PATCH 75/84] Regenerate Cargo.lock --- Cargo.lock | 134 ++++++++++++++++++++++++++--------------------------- 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7f72decebcc..bee6df4df14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,9 +30,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.7.18" +version = "0.7.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" dependencies = [ "memchr", ] @@ -48,15 +48,15 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.63" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26fa4d7e3f2eebadf743988fc8aec9fa9a9e82611acafd77c1462ed6262440a" +checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" [[package]] name = "arbitrary" -version = "1.1.4" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8931eb436ab9bf1980c6cb2b9d1ba5390cd6793b2c6e2d2ea8147da3570c2a2e" +checksum = "f44124848854b941eafdb34f05b3bcf59472f643c7e151eba7c2b69daa469ed5" dependencies = [ "derive_arbitrary", ] @@ -173,9 +173,9 @@ dependencies = [ [[package]] name = "block-buffer" -version = "0.10.2" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" +checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" dependencies = [ "generic-array", ] @@ -258,7 +258,7 @@ version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6358dedf60f4d9b8db43ad187391afe959746101346fe51bb978126bec61dfb" dependencies = [ - "clap 3.2.20", + "clap 3.2.21", "heck 0.4.0", "indexmap", "log", @@ -319,9 +319,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.20" +version = "3.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b71c3ce99b7611011217b366d923f1d0a7e07a92bb2dbf1e84508c673ca3bd" +checksum = "1ed5341b2301a26ab80be5cbdced622e80ed808483c52e45e3310a877d3b37d7" dependencies = [ "atty", "bitflags", @@ -720,9 +720,9 @@ dependencies = [ [[package]] name = "derive_arbitrary" -version = "1.1.4" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d749b611838b7e92cba33b8552187059f2dc32f91d4d66bdc4fe5da9526b4e07" +checksum = "226ad66541d865d7a7173ad6a9e691c33fdb910ac723f4bc734b3e5294a1f931" dependencies = [ "proc-macro2", "quote", @@ -1226,9 +1226,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.47" +version = "0.1.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c495f162af0bf17656d0014a0eded5f3cd2f365fdd204548c2869db89359dc7" +checksum = "237a0714f28b1ee39ccec0770ccb544eb02c9ef2c82bb096230eefcffa6468b0" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -1339,9 +1339,9 @@ dependencies = [ [[package]] name = "itertools" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +checksum = "d8bf247779e67a9082a4790b45e71ac7cfd1321331a5c856a74a9faebdab78d0" dependencies = [ "either", ] @@ -1369,9 +1369,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.59" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" dependencies = [ "wasm-bindgen", ] @@ -1533,9 +1533,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.5.3" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc" +checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34" dependencies = [ "adler", ] @@ -1649,9 +1649,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.13.1" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "074864da206b4973b84eb91683020dbefd6a8c3f0f38e054d93954e891935e4e" +checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0" [[package]] name = "oorandom" @@ -1722,9 +1722,9 @@ checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1" [[package]] name = "pest" -version = "2.3.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b0560d531d1febc25a3c9398a62a71256c0178f2e3443baedd9ad4bb8c9deb4" +checksum = "cb779fcf4bb850fbbb0edc96ff6cf34fd90c4b1a112ce042653280d9a7364048" dependencies = [ "thiserror", "ucd-trie", @@ -1750,9 +1750,9 @@ checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" [[package]] name = "plotters" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "716b4eeb6c4a1d3ecc956f75b43ec2e8e8ba80026413e70a3f41fd3313d3492b" +checksum = "2538b639e642295546c50fcd545198c9d64ee2a38620a628724a3b266d5fbf97" dependencies = [ "num-traits", "plotters-backend", @@ -1950,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", ] @@ -2165,7 +2165,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.13", + "semver 1.0.14", ] [[package]] @@ -2287,9 +2287,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93f6841e709003d68bb2deee8c343572bf446003ec20a583e76f7b15cebf3711" +checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" [[package]] name = "semver-parser" @@ -2617,18 +2617,18 @@ checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" [[package]] name = "thiserror" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d0a539a918745651435ac7db7a18761589a94cd7e94cd56999f828bf73c8a57" +checksum = "c53f98874615aea268107765aa1ed8f6116782501d18e53d08b471733bea6c85" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c251e90f708e16c49a16f4917dc2131e75222b72edfa9cb7f7c58ae56aae0c09" +checksum = "f8b463991b4eab2d801e724172285ec4195c650e8ec79b149e6c2a8e6dd3f783" dependencies = [ "proc-macro2", "quote", @@ -2822,9 +2822,9 @@ dependencies = [ [[package]] name = "ucd-trie" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89570599c4fe5585de2b388aab47e99f7fa4e9238a1399f707a02e356058141c" +checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" [[package]] name = "unicase" @@ -2837,9 +2837,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" +checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" [[package]] name = "unicode-normalization" @@ -2858,15 +2858,15 @@ checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a" [[package]] name = "unicode-width" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" [[package]] name = "unicode-xid" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "unix_mode" @@ -2940,9 +2940,9 @@ dependencies = [ [[package]] name = "wasm-bindgen" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -2950,9 +2950,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" dependencies = [ "bumpalo", "log", @@ -2965,9 +2965,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.32" +version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa76fb221a1f8acddf5b54ace85912606980ad661ac7a503b4570ffd3a624dad" +checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -2977,9 +2977,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2987,9 +2987,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" dependencies = [ "proc-macro2", "quote", @@ -3000,15 +3000,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" [[package]] name = "wasm-bindgen-test" -version = "0.3.32" +version = "0.3.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "513df541345bb9fcc07417775f3d51bbb677daf307d8035c0afafd87dc2e6599" +checksum = "09d2fff962180c3fadf677438054b1db62bee4aa32af26a45388af07d1287e1d" dependencies = [ "console_error_panic_hook", "js-sys", @@ -3020,9 +3020,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-macro" -version = "0.3.32" +version = "0.3.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6150d36a03e90a3cf6c12650be10626a9902d70c5270fd47d7a47e5389a10d56" +checksum = "4683da3dfc016f704c9f82cf401520c4f1cb3ee440f7f52b3d6ac29506a49ca7" dependencies = [ "proc-macro2", "quote", @@ -3151,7 +3151,7 @@ dependencies = [ "atty", "bytesize", "cfg-if 1.0.0", - "clap 3.2.20", + "clap 3.2.21", "colored 2.0.0", "dirs", "distance", @@ -3212,7 +3212,7 @@ dependencies = [ "atty", "bytesize", "cfg-if 1.0.0", - "clap 3.2.20", + "clap 3.2.21", "colored 2.0.0", "distance", "fern", @@ -3259,7 +3259,7 @@ dependencies = [ "rayon", "regex", "rustc_version 0.4.0", - "semver 1.0.13", + "semver 1.0.14", "smallvec", "target-lexicon 0.12.4", "wasmer-compiler", @@ -3512,9 +3512,9 @@ dependencies = [ [[package]] name = "wasmer-wit-bindgen-gen-rust" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63adda6387873b03418918a991a12ffcfbd4001e56189fede57a29b57d6323ee" +checksum = "438bce7c4589842bf100cc9b312443a9b5fc6440e58ab0b8c114e460219c3c3b" dependencies = [ "heck 0.3.3", "wasmer-wit-bindgen-gen-core", @@ -3738,9 +3738,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.59" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" dependencies = [ "js-sys", "wasm-bindgen", From ac1e98051128476177a476f7e1f80fa2fb2abefe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 19:24:47 +0200 Subject: [PATCH 76/84] wit_bindgen_gen_rust_wasm -> wit_bindgen_rust_wasm --- lib/wasi-types-generated/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/wasi-types-generated/src/lib.rs b/lib/wasi-types-generated/src/lib.rs index 7528f99b65f..08cf5c9c896 100644 --- a/lib/wasi-types-generated/src/lib.rs +++ b/lib/wasi-types-generated/src/lib.rs @@ -10,8 +10,8 @@ fn fail_if_wit_files_arent_up_to_date() { 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_gen_rust_wasm::Opts { - ..wit_bindgen_gen_rust_wasm::Opts::default() + 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(); From ba2606c7d4b14742fafa545116ea931d0dbf2d60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 22 Sep 2022 18:42:34 +0200 Subject: [PATCH 77/84] Remove unused code, port subscription module --- .../src/wasi/extra_manual.rs | 10 ++ lib/wasi-types/src/lib.rs | 124 +----------------- 2 files changed, 11 insertions(+), 123 deletions(-) diff --git a/lib/wasi-types-generated/src/wasi/extra_manual.rs b/lib/wasi-types-generated/src/wasi/extra_manual.rs index c568e1a1a69..8976880612d 100644 --- a/lib/wasi-types-generated/src/wasi/extra_manual.rs +++ b/lib/wasi-types-generated/src/wasi/extra_manual.rs @@ -316,3 +316,13 @@ unsafe impl wasmer::ValueType for Prestat { 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/lib.rs b/lib/wasi-types/src/lib.rs index 8dd0766e3a5..fe84c8f3a7f 100644 --- a/lib/wasi-types/src/lib.rs +++ b/lib/wasi-types/src/lib.rs @@ -342,128 +342,6 @@ pub mod signal { pub mod subscription { use wasmer_wasi_types_generated::wasi::{ - Eventtype, SubscriptionClock, SubscriptionFsReadwrite, + Eventtype, SubscriptionClock, SubscriptionEnum as EventType, SubscriptionFsReadwrite, }; - - /// Safe Rust wrapper around `__wasi_subscription_t::type_` and `__wasi_subscription_t::u` - #[derive(Debug, Clone)] - pub enum EventType { - Clock(SubscriptionClock), - Read(SubscriptionFsReadwrite), - Write(SubscriptionFsReadwrite), - } - - impl EventType { - pub fn raw_tag(&self) -> Eventtype { - match self { - EventType::Clock(_) => Eventtype::Clock, - EventType::Read(_) => Eventtype::FdRead, - EventType::Write(_) => Eventtype::FdWrite, - } - } - } - - /* TODO: re-enable and adjust if still required - impl TryFrom for __wasi_subscription_t { - type Error = Errno; - - fn try_from(ws: WasiSubscription) -> Result { - #[allow(unreachable_patterns)] - let (type_, u) = match ws.event_type { - EventType::Clock(c) => (Eventtype::Clock, __wasi_subscription_u { clock: c }), - EventType::Read(rw) => ( - Eventtype::FdRead, - __wasi_subscription_u { fd_readwrite: rw }, - ), - EventType::Write(rw) => ( - Eventtype::FdWrite, - __wasi_subscription_u { fd_readwrite: rw }, - ), - _ => return Err(Errno::Inval), - }; - - 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", &self.type_.to_str()) - .field( - "u", - match self.type_ { - Eventtype::Clock => unsafe { &self.u.clock }, - Eventtype::FdRead | Eventtype::FdWrite => unsafe { &self.u.fd_readwrite }, - }, - ) - .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_ { - Eventtype::FdRead | Eventtype::FdWrite => 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)); - }, - 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_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_ { - Eventtype::Clock => Some(SubscriptionEnum::Clock(unsafe { self.u.clock })), - Eventtype::FdRead | Eventtype::FdWrite => Some(SubscriptionEnum::FdReadWrite(unsafe { - self.u.fd_readwrite - })), - } - } - } - - */ } From 4217cf8a827a6e16a099522433c1485a0a3dc7c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 22 Sep 2022 19:08:16 +0200 Subject: [PATCH 78/84] Move wasi-types-generated into wasi-types --- Cargo.lock | 12 +- Cargo.toml | 3 +- lib/wasi-types-generated/Cargo.toml | 22 - lib/wasi-types-generated/README.md | 5 - lib/wasi-types-generated/src/lib.rs | 42 -- .../.gitignore | 0 lib/wasi-types/Cargo.toml | 15 +- lib/wasi-types/README.md | 8 + .../regenerate.sh | 0 lib/wasi-types/src/lib.rs | 388 ++---------------- lib/wasi-types/src/types.rs | 347 ++++++++++++++++ .../src/wasi/bindings.rs | 0 .../src/wasi/extra.rs | 0 .../src/wasi/extra_manual.rs | 0 .../src/wasi/mod.rs | 0 .../wasi-types-generator-extra/.gitignore | 0 .../wasi-types-generator-extra/Cargo.toml | 0 .../wasi-types-generator-extra/src/main.rs | 0 .../wit-clean/output.wit | 0 .../wit-clean/typenames.wit | 0 .../wit-clean/wasi_unstable.wit | 0 lib/wasi/Cargo.toml | 5 +- lib/wasi/src/lib.rs | 2 +- lib/wasi/src/runtime.rs | 2 +- lib/wasi/src/state/mod.rs | 4 +- lib/wasi/src/state/pipe.rs | 2 +- lib/wasi/src/state/socket.rs | 2 +- lib/wasi/src/state/types.rs | 2 +- lib/wasi/src/syscalls/legacy/snapshot0.rs | 2 +- lib/wasi/src/syscalls/mod.rs | 4 +- lib/wasi/src/syscalls/unix/mod.rs | 2 +- lib/wasi/src/syscalls/wasi.rs | 2 +- lib/wasi/src/syscalls/wasix32.rs | 4 +- lib/wasi/src/syscalls/wasix64.rs | 4 +- lib/wasi/src/utils.rs | 2 +- 35 files changed, 431 insertions(+), 450 deletions(-) delete mode 100644 lib/wasi-types-generated/Cargo.toml delete mode 100644 lib/wasi-types-generated/README.md delete mode 100644 lib/wasi-types-generated/src/lib.rs rename lib/{wasi-types-generated => wasi-types}/.gitignore (100%) rename lib/{wasi-types-generated => wasi-types}/regenerate.sh (100%) create mode 100644 lib/wasi-types/src/types.rs rename lib/{wasi-types-generated => wasi-types}/src/wasi/bindings.rs (100%) rename lib/{wasi-types-generated => wasi-types}/src/wasi/extra.rs (100%) rename lib/{wasi-types-generated => wasi-types}/src/wasi/extra_manual.rs (100%) rename lib/{wasi-types-generated => wasi-types}/src/wasi/mod.rs (100%) rename lib/{wasi-types-generated => wasi-types}/wasi-types-generator-extra/.gitignore (100%) rename lib/{wasi-types-generated => wasi-types}/wasi-types-generator-extra/Cargo.toml (100%) rename lib/{wasi-types-generated => wasi-types}/wasi-types-generator-extra/src/main.rs (100%) rename lib/{wasi-types-generated => wasi-types}/wit-clean/output.wit (100%) rename lib/{wasi-types-generated => wasi-types}/wit-clean/typenames.wit (100%) rename lib/{wasi-types-generated => wasi-types}/wit-clean/wasi_unstable.wit (100%) diff --git a/Cargo.lock b/Cargo.lock index bee6df4df14..c8329a91054 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3435,7 +3435,6 @@ dependencies = [ "wasmer-vnet", "wasmer-wasi-local-networking", "wasmer-wasi-types", - "wasmer-wasi-types-generated", "winapi", ] @@ -3467,19 +3466,12 @@ name = "wasmer-wasi-types" version = "3.0.0-beta" dependencies = [ "byteorder", + "pretty_assertions", "serde", "time", + "wasmer", "wasmer-derive", "wasmer-types", - "wasmer-wasi-types-generated", -] - -[[package]] -name = "wasmer-wasi-types-generated" -version = "3.0.0-beta" -dependencies = [ - "pretty_assertions", - "wasmer", "wasmer-wit-bindgen-gen-core", "wasmer-wit-bindgen-gen-rust-wasm", "wasmer-wit-bindgen-rust", diff --git a/Cargo.toml b/Cargo.toml index 548d39299dd..da7f66afa44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,8 +44,7 @@ members = [ "lib/vm", "lib/wasi", "lib/wasi-types", - "lib/wasi-types-generated", - "lib/wasi-types-generated/wasi-types-generator-extra", + "lib/wasi-types/wasi-types-generator-extra", "lib/wasi-experimental-io-devices", "lib/wasi-local-networking", "lib/types", diff --git a/lib/wasi-types-generated/Cargo.toml b/lib/wasi-types-generated/Cargo.toml deleted file mode 100644 index 21ad9bab8d3..00000000000 --- a/lib/wasi-types-generated/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "wasmer-wasi-types-generated" -version = "3.0.0-beta" -edition = "2018" -license = "MIT" -description = "Autogenerated wasi types, generated from .wit files" - -# 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" } - -[dev-dependencies.pretty_assertions] -version = "1.3.0" - -[features] -js = ["wasmer/js"] -sys = ["wasmer/sys"] diff --git a/lib/wasi-types-generated/README.md b/lib/wasi-types-generated/README.md deleted file mode 100644 index d1050774d82..00000000000 --- a/lib/wasi-types-generated/README.md +++ /dev/null @@ -1,5 +0,0 @@ -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-generated/src/lib.rs b/lib/wasi-types-generated/src/lib.rs deleted file mode 100644 index 08cf5c9c896..00000000000 --- a/lib/wasi-types-generated/src/lib.rs +++ /dev/null @@ -1,42 +0,0 @@ -pub mod 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; - - 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-generated/.gitignore b/lib/wasi-types/.gitignore similarity index 100% rename from lib/wasi-types-generated/.gitignore rename to lib/wasi-types/.gitignore diff --git a/lib/wasi-types/Cargo.toml b/lib/wasi-types/Cargo.toml index 326d61d4ed2..ec43629ddd0 100644 --- a/lib/wasi-types/Cargo.toml +++ b/lib/wasi-types/Cargo.toml @@ -10,15 +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" } wasmer-derive = { path = "../derive", version = "=3.0.0-beta" } -wasmer-wasi-types-generated = { path = "../wasi-types-generated", version = "=3.0.0-beta" } 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"] -sys = ["wasmer-wasi-types-generated/sys"] -js = ["wasmer-wasi-types-generated/js"] \ No newline at end of file +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-generated/regenerate.sh b/lib/wasi-types/regenerate.sh similarity index 100% rename from lib/wasi-types-generated/regenerate.sh rename to lib/wasi-types/regenerate.sh diff --git a/lib/wasi-types/src/lib.rs b/lib/wasi-types/src/lib.rs index fe84c8f3a7f..349d6416eb4 100644 --- a/lib/wasi-types/src/lib.rs +++ b/lib/wasi-types/src/lib.rs @@ -1,347 +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)] - -//! 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::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 wasmer_derive::ValueType; - use wasmer_types::MemorySize; - use wasmer_wasi_types_generated::wasi::{ - BusDataFormat, BusEventClose, BusEventExit, BusEventFault, BusEventType, Cid, OptionCid, - }; - - // 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 wasmer_wasi_types_generated::wasi::{Fd, Rights}; - - pub use wasmer_wasi_types_generated::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 std::mem; - use wasmer_wasi_types_generated::wasi; - - 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 wasmer_wasi_types_generated::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 wasmer_wasi_types_generated::wasi::Bool; - pub use wasmer_wasi_types_generated::wasi::Count; - pub use wasmer_wasi_types_generated::wasi::OptionTag; - pub use wasmer_wasi_types_generated::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 wasmer_wasi_types_generated::wasi::OptionTimestamp; -} - -pub mod net { - use wasmer_derive::ValueType; - use wasmer_wasi_types_generated::wasi::Addressfamily; - - use crate::OptionTimestamp; - - pub use wasmer_wasi_types_generated::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 wasmer_wasi_types_generated::wasi::Signal; -} - -pub mod subscription { - use wasmer_wasi_types_generated::wasi::{ - Eventtype, SubscriptionClock, SubscriptionEnum as EventType, SubscriptionFsReadwrite, - }; +pub mod wasi; +pub mod types; + +// 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; + + 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/types.rs b/lib/wasi-types/src/types.rs new file mode 100644 index 00000000000..8bc5a69e079 --- /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 wasmer_derive::ValueType; + use wasmer_types::MemorySize; + use crate::wasi::{ + BusDataFormat, BusEventClose, BusEventExit, BusEventFault, BusEventType, Cid, OptionCid, + }; + + // 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 std::mem; + use crate::wasi; + + 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 wasmer_derive::ValueType; + use crate::wasi::Addressfamily; + + 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 { + use crate::wasi::{ + Eventtype, SubscriptionClock, SubscriptionEnum as EventType, SubscriptionFsReadwrite, + }; +} diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types/src/wasi/bindings.rs similarity index 100% rename from lib/wasi-types-generated/src/wasi/bindings.rs rename to lib/wasi-types/src/wasi/bindings.rs diff --git a/lib/wasi-types-generated/src/wasi/extra.rs b/lib/wasi-types/src/wasi/extra.rs similarity index 100% rename from lib/wasi-types-generated/src/wasi/extra.rs rename to lib/wasi-types/src/wasi/extra.rs diff --git a/lib/wasi-types-generated/src/wasi/extra_manual.rs b/lib/wasi-types/src/wasi/extra_manual.rs similarity index 100% rename from lib/wasi-types-generated/src/wasi/extra_manual.rs rename to lib/wasi-types/src/wasi/extra_manual.rs diff --git a/lib/wasi-types-generated/src/wasi/mod.rs b/lib/wasi-types/src/wasi/mod.rs similarity index 100% rename from lib/wasi-types-generated/src/wasi/mod.rs rename to lib/wasi-types/src/wasi/mod.rs diff --git a/lib/wasi-types-generated/wasi-types-generator-extra/.gitignore b/lib/wasi-types/wasi-types-generator-extra/.gitignore similarity index 100% rename from lib/wasi-types-generated/wasi-types-generator-extra/.gitignore rename to lib/wasi-types/wasi-types-generator-extra/.gitignore diff --git a/lib/wasi-types-generated/wasi-types-generator-extra/Cargo.toml b/lib/wasi-types/wasi-types-generator-extra/Cargo.toml similarity index 100% rename from lib/wasi-types-generated/wasi-types-generator-extra/Cargo.toml rename to lib/wasi-types/wasi-types-generator-extra/Cargo.toml diff --git a/lib/wasi-types-generated/wasi-types-generator-extra/src/main.rs b/lib/wasi-types/wasi-types-generator-extra/src/main.rs similarity index 100% rename from lib/wasi-types-generated/wasi-types-generator-extra/src/main.rs rename to lib/wasi-types/wasi-types-generator-extra/src/main.rs diff --git a/lib/wasi-types-generated/wit-clean/output.wit b/lib/wasi-types/wit-clean/output.wit similarity index 100% rename from lib/wasi-types-generated/wit-clean/output.wit rename to lib/wasi-types/wit-clean/output.wit diff --git a/lib/wasi-types-generated/wit-clean/typenames.wit b/lib/wasi-types/wit-clean/typenames.wit similarity index 100% rename from lib/wasi-types-generated/wit-clean/typenames.wit rename to lib/wasi-types/wit-clean/typenames.wit diff --git a/lib/wasi-types-generated/wit-clean/wasi_unstable.wit b/lib/wasi-types/wit-clean/wasi_unstable.wit similarity index 100% rename from lib/wasi-types-generated/wit-clean/wasi_unstable.wit rename to lib/wasi-types/wit-clean/wasi_unstable.wit diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml index 3819635a42f..8fd6ce8657c 100644 --- a/lib/wasi/Cargo.toml +++ b/lib/wasi/Cargo.toml @@ -22,7 +22,6 @@ wasmer-vfs = { path = "../vfs", version = "=3.0.0-beta", default-features = fals wasmer-vbus = { path = "../vbus", version = "=3.0.0-beta", default-features = false } wasmer-vnet = { path = "../vnet", version = "=3.0.0-beta", default-features = false } wasmer-wasi-local-networking = { path = "../wasi-local-networking", version = "=3.0.0-beta", default-features = false, optional = true } -wasmer-wasi-types-generated = { path = "../wasi-types-generated", version = "=3.0.0-beta", default-features = false } typetag = { version = "0.1", optional = true } serde = { version = "1.0", default-features = false, features = ["derive"], optional = true } bincode = { version = "1.3", optional = true } @@ -47,11 +46,11 @@ tracing-wasm = "0.2" default = ["sys-default"] wasix = [] -sys = ["wasmer/sys", "wasix", "wasmer-wasi-types-generated/sys"] +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", "wasmer-wasi-types-generated/js"] +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 089df8e2408..1d1b76cfa46 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -67,7 +67,7 @@ use wasmer::{ Imports, Instance, Memory, Memory32, MemoryAccessError, MemorySize, MemoryView, Module, TypedFunction, }; -use wasmer_wasi_types_generated::wasi::{BusErrno, Errno, Snapshot0Clockid}; +use wasmer_wasi_types::wasi::{BusErrno, Errno, Snapshot0Clockid}; pub use runtime::{ PluggableRuntimeImplementation, WasiRuntimeImplementation, WasiThreadError, WasiTtyState, diff --git a/lib/wasi/src/runtime.rs b/lib/wasi/src/runtime.rs index a931272ec23..1394e010b8a 100644 --- a/lib/wasi/src/runtime.rs +++ b/lib/wasi/src/runtime.rs @@ -4,7 +4,7 @@ use std::sync::atomic::{AtomicU32, Ordering}; use thiserror::Error; use wasmer_vbus::{UnsupportedVirtualBus, VirtualBus}; use wasmer_vnet::VirtualNetworking; -use wasmer_wasi_types_generated::wasi::Errno; +use wasmer_wasi_types::wasi::Errno; use super::WasiError; use super::WasiThreadId; diff --git a/lib/wasi/src/state/mod.rs b/lib/wasi/src/state/mod.rs index 7cc223a5f50..58f94dcd83a 100644 --- a/lib/wasi/src/state/mod.rs +++ b/lib/wasi/src/state/mod.rs @@ -52,10 +52,10 @@ use std::{ }; use tracing::{debug, trace}; use wasmer_vbus::BusSpawnedProcess; -use wasmer_wasi_types_generated::wasi::{ +use wasmer_wasi_types::wasi::{ Errno, Fd as WasiFd, Fdflags, Fdstat, Filesize, Filestat, Filetype, Preopentype, Rights, }; -use wasmer_wasi_types_generated::wasi::{Prestat, PrestatEnum}; +use wasmer_wasi_types::wasi::{Prestat, PrestatEnum}; use wasmer_vfs::{FileSystem, FsError, OpenOptions, VirtualFile}; diff --git a/lib/wasi/src/state/pipe.rs b/lib/wasi/src/state/pipe.rs index 4ce34e78f72..4781ab0a02f 100644 --- a/lib/wasi/src/state/pipe.rs +++ b/lib/wasi/src/state/pipe.rs @@ -8,7 +8,7 @@ use std::sync::mpsc; use std::sync::Mutex; use wasmer::WasmSlice; use wasmer::{MemorySize, MemoryView}; -use wasmer_wasi_types_generated::wasi::Errno; +use wasmer_wasi_types::wasi::Errno; #[derive(Debug)] pub struct WasiPipe { diff --git a/lib/wasi/src/state/socket.rs b/lib/wasi/src/state/socket.rs index e1f3ce58d75..32171cc959b 100644 --- a/lib/wasi/src/state/socket.rs +++ b/lib/wasi/src/state/socket.rs @@ -16,7 +16,7 @@ use wasmer_vnet::{ IpCidr, IpRoute, SocketHttpRequest, VirtualIcmpSocket, VirtualNetworking, VirtualRawSocket, VirtualTcpListener, VirtualTcpSocket, VirtualUdpSocket, VirtualWebSocket, }; -use wasmer_wasi_types_generated::wasi::{ +use wasmer_wasi_types::wasi::{ Addressfamily, Errno, Fdflags, OptionTag, Sockoption, Socktype, }; diff --git a/lib/wasi/src/state/types.rs b/lib/wasi/src/state/types.rs index 5b6f655bc85..f4aca85ab3f 100644 --- a/lib/wasi/src/state/types.rs +++ b/lib/wasi/src/state/types.rs @@ -10,7 +10,7 @@ use std::{ time::Duration, }; use wasmer_vbus::BusError; -use wasmer_wasi_types_generated::wasi::{BusErrno, Errno}; +use wasmer_wasi_types::wasi::{BusErrno, Errno}; #[cfg(feature = "host-fs")] pub use wasmer_vfs::host_fs::{Stderr, Stdin, Stdout}; diff --git a/lib/wasi/src/syscalls/legacy/snapshot0.rs b/lib/wasi/src/syscalls/legacy/snapshot0.rs index e18d8a1e0ee..176e94a5d6b 100644 --- a/lib/wasi/src/syscalls/legacy/snapshot0.rs +++ b/lib/wasi/src/syscalls/legacy/snapshot0.rs @@ -2,7 +2,7 @@ use crate::syscalls; use crate::syscalls::types; use crate::{mem_error_to_wasi, Memory32, MemorySize, WasiEnv, WasiError, WasiThread}; use wasmer::{AsStoreMut, FunctionEnvMut, WasmPtr}; -use wasmer_wasi_types_generated::wasi::{ +use wasmer_wasi_types::wasi::{ Errno, Event, Fd, Filesize, Filestat, Filetype, Snapshot0Filestat, Snapshot0Subscription, Snapshot0Whence, Subscription, Whence, }; diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 668b0ed8c7a..202fb0b2048 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -1,8 +1,8 @@ #![allow(unused, clippy::too_many_arguments, clippy::cognitive_complexity)] pub mod types { - pub use wasmer_wasi_types::*; - pub use wasmer_wasi_types_generated::wasi; + pub use wasmer_wasi_types::types::*; + pub use wasmer_wasi_types::wasi; } #[cfg(any( diff --git a/lib/wasi/src/syscalls/unix/mod.rs b/lib/wasi/src/syscalls/unix/mod.rs index a079f9c66e8..916b1de0265 100644 --- a/lib/wasi/src/syscalls/unix/mod.rs +++ b/lib/wasi/src/syscalls/unix/mod.rs @@ -5,7 +5,7 @@ use libc::{ }; use std::mem; use wasmer::WasmRef; -use wasmer_wasi_types_generated::wasi::{Errno, Snapshot0Clockid, Timestamp}; +use wasmer_wasi_types::wasi::{Errno, Snapshot0Clockid, Timestamp}; pub fn platform_clock_res_get( clock_id: Snapshot0Clockid, diff --git a/lib/wasi/src/syscalls/wasi.rs b/lib/wasi/src/syscalls/wasi.rs index 6eeaf47886f..f90e5955ba0 100644 --- a/lib/wasi/src/syscalls/wasi.rs +++ b/lib/wasi/src/syscalls/wasi.rs @@ -3,7 +3,7 @@ use crate::{WasiEnv, WasiError, WasiState, WasiThread}; 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; diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index 36d7dafcb2a..53ca959643d 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -1,8 +1,8 @@ #![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_generated::wasi::{ +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, diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index e70df788ea7..df48c26a6ea 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -1,8 +1,8 @@ #![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_generated::wasi::{ +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, diff --git a/lib/wasi/src/utils.rs b/lib/wasi/src/utils.rs index 2c00f329122..571a954fc38 100644 --- a/lib/wasi/src/utils.rs +++ b/lib/wasi/src/utils.rs @@ -1,6 +1,6 @@ use std::collections::BTreeSet; use wasmer::Module; -use wasmer_wasi_types_generated::wasi::Errno; +use wasmer_wasi_types::wasi::Errno; #[allow(dead_code)] /// Check if a provided module is compiled for some version of WASI. From 36db57cab7973c35054f18097e590a6ad5a4d249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 22 Sep 2022 19:28:22 +0200 Subject: [PATCH 79/84] cargo fmt --- lib/wasi-types/src/lib.rs | 2 +- lib/wasi-types/src/types.rs | 8 ++++---- lib/wasi/src/state/socket.rs | 4 +--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/wasi-types/src/lib.rs b/lib/wasi-types/src/lib.rs index 349d6416eb4..2e54b95e5f9 100644 --- a/lib/wasi-types/src/lib.rs +++ b/lib/wasi-types/src/lib.rs @@ -1,5 +1,5 @@ -pub mod wasi; pub mod types; +pub mod wasi; // Prevent the CI from passing if the wasi/bindings.rs is not // up to date with the output.wit file diff --git a/lib/wasi-types/src/types.rs b/lib/wasi-types/src/types.rs index 8bc5a69e079..fd2c14ce6ac 100644 --- a/lib/wasi-types/src/types.rs +++ b/lib/wasi-types/src/types.rs @@ -24,11 +24,11 @@ pub type __wasi_exitcode_t = u32; pub type __wasi_userdata_t = u64; pub mod bus { - use wasmer_derive::ValueType; - use wasmer_types::MemorySize; 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 ... @@ -101,8 +101,8 @@ pub mod file { } pub mod directory { - use std::mem; use crate::wasi; + use std::mem; pub const __WASI_DIRCOOKIE_START: wasi::Dircookie = 0; @@ -202,8 +202,8 @@ pub mod time { } pub mod net { - use wasmer_derive::ValueType; use crate::wasi::Addressfamily; + use wasmer_derive::ValueType; use crate::wasi::OptionTimestamp; diff --git a/lib/wasi/src/state/socket.rs b/lib/wasi/src/state/socket.rs index 32171cc959b..788c0e17827 100644 --- a/lib/wasi/src/state/socket.rs +++ b/lib/wasi/src/state/socket.rs @@ -16,9 +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, -}; +use wasmer_wasi_types::wasi::{Addressfamily, Errno, Fdflags, OptionTag, Sockoption, Socktype}; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; From 3c0386dfcd3cd1dcc55077f4dcb3fd801018f8af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 23 Sep 2022 08:54:33 +0200 Subject: [PATCH 80/84] Fix "make lint" --- lib/wasi-types/src/types.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wasi-types/src/types.rs b/lib/wasi-types/src/types.rs index fd2c14ce6ac..9eee82f3ef1 100644 --- a/lib/wasi-types/src/types.rs +++ b/lib/wasi-types/src/types.rs @@ -341,7 +341,7 @@ pub mod signal { } pub mod subscription { - use crate::wasi::{ + pub use crate::wasi::{ Eventtype, SubscriptionClock, SubscriptionEnum as EventType, SubscriptionFsReadwrite, }; } From 336c4d9c99d96dab469df67190bd87c99f3430ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 26 Sep 2022 15:53:56 +0200 Subject: [PATCH 81/84] Correct bitflags: u8 -> bitflags: u16 / u32 / u64 --- lib/wasi-types/src/wasi/extra.rs | 320 +++++++++--------- .../wasi-types-generator-extra/Cargo.toml | 1 + .../wasi-types-generator-extra/src/main.rs | 56 ++- 3 files changed, 216 insertions(+), 161 deletions(-) diff --git a/lib/wasi-types/src/wasi/extra.rs b/lib/wasi-types/src/wasi/extra.rs index dd3c9a3fea9..a587a806653 100644 --- a/lib/wasi-types/src/wasi/extra.rs +++ b/lib/wasi-types/src/wasi/extra.rs @@ -532,103 +532,103 @@ impl core::fmt::Display for BusErrno { 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; -} + /// 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 /// @@ -750,22 +750,22 @@ impl core::fmt::Debug for Advice { } } 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; -} + /// 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 /// @@ -798,20 +798,20 @@ impl core::fmt::Debug for Fdstat { } } 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; -} + /// 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 /// @@ -820,14 +820,14 @@ impl Fstflags { } } 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; -} + /// 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 /// @@ -836,20 +836,20 @@ impl Lookup { } } 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; -} + /// 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 /// @@ -884,17 +884,17 @@ impl core::fmt::Debug for Eventtype { } } 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; -} + /// 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 /// @@ -968,13 +968,13 @@ impl core::fmt::Debug for Preopentype { } } 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; -} + /// 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 /// diff --git a/lib/wasi-types/wasi-types-generator-extra/Cargo.toml b/lib/wasi-types/wasi-types-generator-extra/Cargo.toml index fab10cc5c33..e0a8dbc160c 100644 --- a/lib/wasi-types/wasi-types-generator-extra/Cargo.toml +++ b/lib/wasi-types/wasi-types-generator-extra/Cargo.toml @@ -7,6 +7,7 @@ description = "Generator for wasi-types" [dependencies] convert_case = "0.5.0" +regex = "1.6.0" [dependencies.wit-parser] default-features = false diff --git a/lib/wasi-types/wasi-types-generator-extra/src/main.rs b/lib/wasi-types/wasi-types-generator-extra/src/main.rs index d7e1da9a4b5..ca9c909841e 100644 --- a/lib/wasi-types/wasi-types-generator-extra/src/main.rs +++ b/lib/wasi-types/wasi-types-generator-extra/src/main.rs @@ -9,7 +9,61 @@ fn main() { .replace("#[allow(clippy::all)]", "") .replace("pub mod output {", "") .replace("mod output {", "") - .replace(" ", ""); + .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 {"); + + let re = regex::Regex::new(r"impl Rights {((.|\n)*)\(bits: u8\)((.|\n)*)").unwrap(); + let bindings_rs = re.replace( + &bindings_rs, + r"impl Rights {((.|\n)*)\(bits: u64\)((.|\n)*)", + ); + + let re = regex::Regex::new(r"impl Lookup {((.|\n)*)\(bits: u8\)((.|\n)*)").unwrap(); + let bindings_rs = re.replace( + &bindings_rs, + r"impl Lookup {((.|\n)*)\(bits: u32\)((.|\n)*)", + ); + + let re = regex::Regex::new(r"impl Oflags {((.|\n)*)\(bits: u8\)((.|\n)*)").unwrap(); + let bindings_rs = re.replace( + &bindings_rs, + r"impl Oflags {((.|\n)*)\(bits: u16\)((.|\n)*)", + ); + + let re = regex::Regex::new(r"impl Subclockflags {((.|\n)*)\(bits: u8\)((.|\n)*)").unwrap(); + let bindings_rs = re.replace( + &bindings_rs, + r"impl Subclockflags {((.|\n)*)\(bits: u16\)((.|\n)*)", + ); + + let re = regex::Regex::new(r"impl Eventrwflags {((.|\n)*)\(bits: u8\)((.|\n)*)").unwrap(); + let bindings_rs = re.replace( + &bindings_rs, + r"impl Eventrwflags {((.|\n)*)\(bits: u16\)((.|\n)*)", + ); + + let re = regex::Regex::new(r"impl Fstflags {((.|\n)*)\(bits: u8\)((.|\n)*)").unwrap(); + let bindings_rs = re.replace( + &bindings_rs, + r"impl Fstflags {((.|\n)*)\(bits: u16\)((.|\n)*)", + ); + + let re = regex::Regex::new(r"impl Fdflags {((.|\n)*)\(bits: u8\)((.|\n)*)").unwrap(); + let bindings_rs = re.replace( + &bindings_rs, + r"impl Fdflags {((.|\n)*)\(bits: u16\)((.|\n)*)", + ); let mut bindings_rs = bindings_rs.lines().collect::>(); bindings_rs.pop(); From c445f1e1d40a971ddd48f1d36ba1b6ed44025dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 26 Sep 2022 17:43:36 +0200 Subject: [PATCH 82/84] Add regex crate --- Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.lock b/Cargo.lock index c8329a91054..c91c1ba459a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2935,6 +2935,7 @@ name = "wasi-types-generator-extra" version = "0.1.0" dependencies = [ "convert_case", + "regex", "wasmer-wit-parser", ] From 43e9d8f0db0a7866e38875c7e5382e97fddb220b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Tue, 27 Sep 2022 11:12:29 +0200 Subject: [PATCH 83/84] Update wasi-types generator to replace repr(u16) types --- Cargo.lock | 1 - lib/wasi-types/src/wasi/extra.rs | 12 ++-- lib/wasi-types/src/wasi/extra_manual.rs | 6 +- .../wasi-types-generator-extra/Cargo.toml | 1 - .../wasi-types-generator-extra/src/main.rs | 65 +++++++------------ 5 files changed, 32 insertions(+), 53 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c91c1ba459a..c8329a91054 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2935,7 +2935,6 @@ name = "wasi-types-generator-extra" version = "0.1.0" dependencies = [ "convert_case", - "regex", "wasmer-wit-parser", ] diff --git a/lib/wasi-types/src/wasi/extra.rs b/lib/wasi-types/src/wasi/extra.rs index a587a806653..4d74ab8d816 100644 --- a/lib/wasi-types/src/wasi/extra.rs +++ b/lib/wasi-types/src/wasi/extra.rs @@ -769,7 +769,7 @@ wit_bindgen_rust::bitflags::bitflags! { impl Fdflags { /// Convert from a raw integer, preserving any unknown bits. See /// - pub fn from_bits_preserve(bits: u8) -> Self { + pub fn from_bits_preserve(bits: u16) -> Self { Self { bits } } } @@ -815,7 +815,7 @@ wit_bindgen_rust::bitflags::bitflags! { impl Fstflags { /// Convert from a raw integer, preserving any unknown bits. See /// - pub fn from_bits_preserve(bits: u8) -> Self { + pub fn from_bits_preserve(bits: u16) -> Self { Self { bits } } } @@ -831,7 +831,7 @@ wit_bindgen_rust::bitflags::bitflags! { impl Lookup { /// Convert from a raw integer, preserving any unknown bits. See /// - pub fn from_bits_preserve(bits: u8) -> Self { + pub fn from_bits_preserve(bits: u32) -> Self { Self { bits } } } @@ -853,7 +853,7 @@ wit_bindgen_rust::bitflags::bitflags! { impl Oflags { /// Convert from a raw integer, preserving any unknown bits. See /// - pub fn from_bits_preserve(bits: u8) -> Self { + pub fn from_bits_preserve(bits: u16) -> Self { Self { bits } } } @@ -898,7 +898,7 @@ wit_bindgen_rust::bitflags::bitflags! { impl Subclockflags { /// Convert from a raw integer, preserving any unknown bits. See /// - pub fn from_bits_preserve(bits: u8) -> Self { + pub fn from_bits_preserve(bits: u16) -> Self { Self { bits } } } @@ -978,7 +978,7 @@ wit_bindgen_rust::bitflags::bitflags! { impl Eventrwflags { /// Convert from a raw integer, preserving any unknown bits. See /// - pub fn from_bits_preserve(bits: u8) -> Self { + pub fn from_bits_preserve(bits: u16) -> Self { Self { bits } } } diff --git a/lib/wasi-types/src/wasi/extra_manual.rs b/lib/wasi-types/src/wasi/extra_manual.rs index 8976880612d..0c6456441a0 100644 --- a/lib/wasi-types/src/wasi/extra_manual.rs +++ b/lib/wasi-types/src/wasi/extra_manual.rs @@ -188,7 +188,7 @@ unsafe impl wasmer::FromToNativeWasmType for Fdflags { self.bits() as i32 } fn from_native(n: Self::Native) -> Self { - Self::from_bits_truncate(n as u8) + Self::from_bits_truncate(n as u16) } fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { @@ -223,7 +223,7 @@ unsafe impl wasmer::FromToNativeWasmType for Fstflags { self.bits() as i32 } fn from_native(n: Self::Native) -> Self { - Self::from_bits_truncate(n as u8) + Self::from_bits_truncate(n as u16) } fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { @@ -240,7 +240,7 @@ unsafe impl wasmer::FromToNativeWasmType for Oflags { self.bits() as i32 } fn from_native(n: Self::Native) -> Self { - Self::from_bits_truncate(n as u8) + Self::from_bits_truncate(n as u16) } fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool { diff --git a/lib/wasi-types/wasi-types-generator-extra/Cargo.toml b/lib/wasi-types/wasi-types-generator-extra/Cargo.toml index e0a8dbc160c..fab10cc5c33 100644 --- a/lib/wasi-types/wasi-types-generator-extra/Cargo.toml +++ b/lib/wasi-types/wasi-types-generator-extra/Cargo.toml @@ -7,7 +7,6 @@ description = "Generator for wasi-types" [dependencies] convert_case = "0.5.0" -regex = "1.6.0" [dependencies.wit-parser] default-features = false diff --git a/lib/wasi-types/wasi-types-generator-extra/src/main.rs b/lib/wasi-types/wasi-types-generator-extra/src/main.rs index ca9c909841e..50104db199b 100644 --- a/lib/wasi-types/wasi-types-generator-extra/src/main.rs +++ b/lib/wasi-types/wasi-types-generator-extra/src/main.rs @@ -4,8 +4,21 @@ 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 bindings_rs = BINDINGS_RS + let mut bindings_rs = BINDINGS_RS .replace("#[allow(clippy::all)]", "") .replace("pub mod output {", "") .replace("mod output {", "") @@ -23,47 +36,13 @@ fn main() { .replace("pub struct Fstflags: u8 {", "pub struct Fstflags: u16 {") .replace("pub struct Fdflags: u8 {", "pub struct Fdflags: u16 {"); - let re = regex::Regex::new(r"impl Rights {((.|\n)*)\(bits: u8\)((.|\n)*)").unwrap(); - let bindings_rs = re.replace( - &bindings_rs, - r"impl Rights {((.|\n)*)\(bits: u64\)((.|\n)*)", - ); - - let re = regex::Regex::new(r"impl Lookup {((.|\n)*)\(bits: u8\)((.|\n)*)").unwrap(); - let bindings_rs = re.replace( - &bindings_rs, - r"impl Lookup {((.|\n)*)\(bits: u32\)((.|\n)*)", - ); - - let re = regex::Regex::new(r"impl Oflags {((.|\n)*)\(bits: u8\)((.|\n)*)").unwrap(); - let bindings_rs = re.replace( - &bindings_rs, - r"impl Oflags {((.|\n)*)\(bits: u16\)((.|\n)*)", - ); - - let re = regex::Regex::new(r"impl Subclockflags {((.|\n)*)\(bits: u8\)((.|\n)*)").unwrap(); - let bindings_rs = re.replace( - &bindings_rs, - r"impl Subclockflags {((.|\n)*)\(bits: u16\)((.|\n)*)", - ); - - let re = regex::Regex::new(r"impl Eventrwflags {((.|\n)*)\(bits: u8\)((.|\n)*)").unwrap(); - let bindings_rs = re.replace( - &bindings_rs, - r"impl Eventrwflags {((.|\n)*)\(bits: u16\)((.|\n)*)", - ); - - let re = regex::Regex::new(r"impl Fstflags {((.|\n)*)\(bits: u8\)((.|\n)*)").unwrap(); - let bindings_rs = re.replace( - &bindings_rs, - r"impl Fstflags {((.|\n)*)\(bits: u16\)((.|\n)*)", - ); - - let re = regex::Regex::new(r"impl Fdflags {((.|\n)*)\(bits: u8\)((.|\n)*)").unwrap(); - let bindings_rs = re.replace( - &bindings_rs, - r"impl Fdflags {((.|\n)*)\(bits: u16\)((.|\n)*)", - ); + 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(); @@ -88,6 +67,8 @@ fn main() { ) .replace(" ", ""); + println!("output to {}", path.display()); + let excluded_from_impl_valuetype = ["Prestat"]; for (_, i) in result.types.iter() { From 5e049b95b6ad51b5fd909fb1aaa647277b641e21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= <12084016+fschutt@users.noreply.github.com> Date: Thu, 29 Sep 2022 20:14:58 +0200 Subject: [PATCH 84/84] Add doc comment to explain wasi-generator-extra --- lib/wasi-types/wasi-types-generator-extra/src/main.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/wasi-types/wasi-types-generator-extra/src/main.rs b/lib/wasi-types/wasi-types-generator-extra/src/main.rs index 50104db199b..70dded6e090 100644 --- a/lib/wasi-types/wasi-types-generator-extra/src/main.rs +++ b/lib/wasi-types/wasi-types-generator-extra/src/main.rs @@ -1,3 +1,9 @@ +//! 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;